From: Michael D. Lowis Date: Mon, 10 Apr 2017 20:22:50 +0000 (-0400) Subject: cleanup X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=cee5f9a2c344cf1e636af0309a71b9d93e4eca80;p=proto%2Frc.git cleanup --- diff --git a/builtins.c b/builtins.c index 8d338a1..56ff23a 100644 --- a/builtins.c +++ b/builtins.c @@ -17,20 +17,20 @@ static struct { builtin_t *p; char *name; } builtins[] = { - { b_break, "break" }, + { b_break, "break" }, { b_builtin, "builtin" }, - { b_cd, "cd" }, - { b_echo, "echo" }, - { b_eval, "eval" }, - { b_exec, "exec" }, - { b_exit, "exit" }, - { b_limit, "limit" }, + { b_cd, "cd" }, + { b_echo, "echo" }, + { b_eval, "eval" }, + { b_exec, "exec" }, + { b_exit, "exit" }, + { b_limit, "limit" }, { b_newpgrp, "newpgrp" }, - { b_return, "return" }, - { b_shift, "shift" }, - { b_umask, "umask" }, - { b_wait, "wait" }, - { b_dot, "." }, + { b_return, "return" }, + { b_shift, "shift" }, + { b_umask, "umask" }, + { b_wait, "wait" }, + { b_dot, "." }, }; extern builtin_t *isbuiltin(char *s) { diff --git a/footobar.c b/footobar.c index 0cf1efd..0d5f7d2 100644 --- a/footobar.c +++ b/footobar.c @@ -1,3 +1,4 @@ + /* footobar.c: a collection of functions to convert internal representations of variables and functions to external representations, and vice versa diff --git a/main.c b/main.c index c188efa..cfc31cb 100644 --- a/main.c +++ b/main.c @@ -13,6 +13,14 @@ void usage(void) { printf("Usage: %s [OPTION...] [FILE [ARG...]]\n", ARGV0); } +/* open an fd on /dev/null if it is inherited closed */ + +static void checkfd(int fd, enum redirtype r) { + int new = rc_open("/dev/null", r); + if (new != fd && new != -1) + close(new); +} + extern int main(int argc, char *argv[], char *envp[]) { char *dollarzero, *null[1]; initprint(); @@ -45,7 +53,7 @@ extern int main(int argc, char *argv[], char *envp[]) { return 0; /* Never really reached. */ } -static void assigndefault(char *name,...) { +static void assigndefault(char *name, ...) { va_list ap; List *l; char *v; @@ -59,10 +67,3 @@ static void assigndefault(char *name,...) { va_end(ap); } -/* open an fd on /dev/null if it is inherited closed */ - -static void checkfd(int fd, enum redirtype r) { - int new = rc_open("/dev/null", r); - if (new != fd && new != -1) - close(new); -} diff --git a/mksignal.c b/mksignal.c deleted file mode 100644 index c66ad49..0000000 --- a/mksignal.c +++ /dev/null @@ -1,239 +0,0 @@ -#include -#include -#include - -#ifdef NSIG -#define NUMSIG NSIG -#else -#define NUMSIG 1 -#endif - -struct signaming { - int signo; - const char *signame; - const char *sigmsg; -}; - -static struct signaming signamings[] = { -#ifdef SIGABRT - { SIGABRT, "sigabrt", "abort"}, -#endif -#ifdef SIGALRM - { SIGALRM, "sigalrm", "alarm clock"}, -#endif -#ifdef SIGBREAK - { SIGBREAK, "sigbreak", "break"}, -#endif -#ifdef SIGBUS - { SIGBUS, "sigbus", "bus error"}, -#endif -#ifdef SIGCANCEL - { SIGCANCEL, "sigcancel", "thread cancellation"}, -#endif -#ifdef SIGCHLD - { SIGCHLD, "sigchld", "child stop or exit"}, -#endif -#ifdef SIGCLD - { SIGCLD, "sigcld", "child stop or exit"}, -#endif -#ifdef SIGCONT - { SIGCONT, "sigcont", "continue"}, -#endif -#ifdef SIGDIL - { SIGDIL, "sigdil", "dil signal"}, -#endif -#ifdef SIGEMT - { SIGEMT, "sigemt", "emt instruction"}, -#endif -#ifdef SIGFPE - { SIGFPE, "sigfpe", "floating point error"}, -#endif -#ifdef SIGFREEZE - { SIGFREEZE, "sigfreeze", "cpr freeze"}, -#endif -#ifdef SIGHUP - { SIGHUP, "sighup", "hangup"}, -#endif -#ifdef SIGILL - { SIGILL, "sigill", "illegal instruction"}, -#endif - -/* We don't want a default message for SIGINT. */ -#ifdef SIGINT - { SIGINT, "sigint", ""}, -#endif - -#ifdef SIGIO - { SIGIO, "sigio", "socket i/o possible"}, -#endif -#ifdef SIGIOT - { SIGIOT, "sigiot", "iot instruction"}, -#endif -#ifdef SIGKILL - { SIGKILL, "sigkill", "killed"}, -#endif -#ifdef SIGLOST - { SIGLOST, "siglost", "resource lost"}, -#endif -#ifdef SIGLWP - { SIGLWP, "siglwp", "thread library signal"}, -#endif - -/* By default, SIGPIPEs are silent. */ -#ifdef SIGPIPE - { SIGPIPE, "sigpipe", ""}, -#endif - -#ifdef SIGPOLL - { SIGPOLL, "sigpoll", "pollable event occurred"}, -#endif -#ifdef SIGPROF - { SIGPROF, "sigprof", "profiling timer alarm"}, -#endif -#ifdef SIGPWR - { SIGPWR, "sigpwr", "power-fail restart"}, -#endif -#ifdef SIGQUIT - { SIGQUIT, "sigquit", "quit"}, -#endif -#ifdef SIGSEGV - { SIGSEGV, "sigsegv", "segmentation violation"}, -#endif -#ifdef SIGSTKFLT - { SIGSTKFLT, "sigstkflt", "stack fault"}, -#endif -#ifdef SIGSTOP - { SIGSTOP, "sigstop", "stopped by program"}, -#endif -#ifdef SIGSYS - { SIGSYS, "sigsys", "invalid argument to system call"}, -#endif -#ifdef SIGTERM - { SIGTERM, "sigterm", "terminated"}, -#endif -#ifdef SIGTHAW - { SIGTHAW, "sigthaw", "cpr thaw"}, -#endif -#ifdef SIGTRAP - { SIGTRAP, "sigtrap", "trace trap"}, -#endif -#ifdef SIGTSTP - { SIGTSTP, "sigtstp", "stopped"}, -#endif -#ifdef SIGTTIN - { SIGTTIN, "sigttin", "background tty read"}, -#endif -#ifdef SIGTTOU - { SIGTTOU, "sigttou", "background tty write"}, -#endif -#ifdef SIGURG - { SIGURG, "sigurg", "urgent condition on i/o channel"}, -#endif -#ifdef SIGUSR1 - { SIGUSR1, "sigusr1", "user defined signal 1"}, -#endif -#ifdef SIGUSR2 - { SIGUSR2, "sigusr2", "user defined signal 2"}, -#endif -#ifdef SIGVTALRM - { SIGVTALRM, "sigvtalrm", "virtual timer alarm"}, -#endif -#ifdef SIGWAITING - { SIGWAITING, "sigwaiting", "lwps blocked"}, -#endif -#ifdef SIGWINCH - { SIGWINCH, "sigwinch", "window size change"}, -#endif -#ifdef SIGWINDOW - { SIGWINDOW, "sigwindow", "window size change"}, -#endif -#ifdef SIGXCPU - { SIGXCPU, "sigxcpu", "exceeded cpu time limit"}, -#endif -#ifdef SIGXFSZ - { SIGXFSZ, "sigxfsz", "exceeded file size limit"}, -#endif -#ifdef SIGSAK - { SIGSAK, "sigsak", "secure attention key"}, -#endif -#ifdef SIGSOUND - { SIGSOUND, "sigsound", "hft sound sequence completed"}, -#endif -#ifdef SIGRETRACT - { SIGRETRACT, "sigretract", "hft monitor mode retracted"}, -#endif -#ifdef SIGKAP - { SIGKAP, "sigkap", "keep alive poll"}, -#endif -#ifdef SIGGRANT - { SIGGRANT, "siggrant", "hft monitor mode granted"}, -#endif -#ifdef SIGALRM1 - { SIGALRM1, "sigalrm1", "m:n condition alarm"}, -#endif -#ifdef SIGVIRT - { SIGVIRT, "sigvirt", "virtual time alarm"}, -#endif -#ifdef SIGPRE - { SIGPRE, "sigpre", "programming error"}, -#endif -#ifdef SIGMIGRATE - { SIGMIGRATE, "sigmigrate", "migrate process"}, -#endif -#ifdef SIGDANGER - { SIGDANGER, "sigdanger", "system crash imminent"}, -#endif -#ifdef SIGMSG - { SIGMSG, "sigmsg", "hft input data pending"}, -#endif -#ifdef SIGINFO - { SIGINFO, "siginfo", "information request"}, -#endif - { 0, 0, 0} -}; - -static void barf(const char *msg) { - fprintf(stderr, "mksignals: %s\n", msg); - exit(1); -} - -int main(void) { - int maxsig = NUMSIG-1; - int s; - struct signaming *snp; - FILE *outf; - - for (snp = signamings; snp->signo; ++snp) - if (snp->signo > maxsig) - maxsig = snp->signo; - - outf = fopen("sigmsgs.h", "w"); - if (!outf) barf("could not open sigmsgs.h for writing"); - fprintf(outf, "typedef struct {\n"); - fprintf(outf, "\tchar *name, *msg;\n"); - fprintf(outf, "} Sigmsgs;\n"); - fprintf(outf, "extern Sigmsgs signals[];\n"); - fprintf(outf, "#define NUMOFSIGNALS %d\n", maxsig+1); - if (fclose(outf) == EOF) barf("could not fclose sigmsgs.h after writing"); - - outf = fopen("sigmsgs.c", "w"); - if (!outf) barf("could not open sigmsgs.c for writing"); - fprintf(outf, "#include \"sigmsgs.h\"\n\n"); - fprintf(outf, "Sigmsgs signals[] = {\n"); - fprintf(outf, "\t{\"\",\t\"\"},\n"); - - /* yes, we could avoid the quadratic searching with an aux array. fap. */ - for (s = 1; s <= maxsig; ++s) { - for (snp = signamings; snp->signo && snp->signo != s; ++snp) - /* */; - if (snp->signo) - fprintf(outf, "\t{\"%s\",\t\"%s\"},\n", - snp->signame, snp->sigmsg); - else - fprintf(outf, "\t{\"sigunknown%d\",\t\"unknown signal %d\"},\n", - s, s); - } - fprintf(outf, "};\n"); - if (fclose(outf) == EOF) barf("could not fclose sigmsgs.c after writing"); - return 0; -} diff --git a/mkstatval.c b/mkstatval.c deleted file mode 100644 index c74ac46..0000000 --- a/mkstatval.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include -#include - -int main(void) { - int cstatus, pstatus; - pid_t pid; - - for (cstatus = 0; cstatus < 2; ++cstatus) { - switch (pid = fork()) { - case -1: - perror("fork"); - return 1; - case 0: - _exit(cstatus); - default: - if (wait(&pstatus) != pid) { - perror("wait"); - return 1; - } - printf("#define STATUS%d %d\n", cstatus, pstatus); - } - } - return 0; -}