]> git.mdlowis.com Git - proto/rc.git/commitdiff
merged changes from master
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 11 Apr 2017 12:04:13 +0000 (08:04 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 11 Apr 2017 12:04:13 +0000 (08:04 -0400)
1  2 
builtins.c
footobar.c
main.c

diff --cc builtins.c
index f4f6763388e27eb82d051f3d126b75e482838db7,56ff23a04be5d40deffc7ef1e3ded841a192dc9e..1cb825901473c0bb7b10cd8e6e41bc81f5d872d0
  #include "rc.h"
  
  static void b_break(char **), b_cd(char **), b_eval(char **), b_exit(char **),
 -      b_newpgrp(char **), b_return(char **), b_shift(char **), b_umask(char **),
 -      b_wait(char **), b_limit(char **), b_echo(char **);
 +    b_newpgrp(char **), b_return(char **), b_shift(char **), b_umask(char **),
 +    b_wait(char **), b_limit(char **), b_echo(char **);
  
  static struct {
 -      builtin_t *p;
 -      char *name;
 +    builtin_t *p;
 +    char *name;
  } builtins[] = {
-     { 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_newpgrp, "newpgrp" },
-     { b_return,     "return" },
-     { b_shift,     "shift" },
-     { b_umask,     "umask" },
-     { b_wait,     "wait" },
-     { b_dot,     "." },
+       { 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_newpgrp, "newpgrp" },
+       { b_return,      "return"  },
+       { b_shift,       "shift"   },
+       { b_umask,       "umask"   },
+       { b_wait,        "wait"    },
+       { b_dot,         "."       },
  };
  
  extern builtin_t *isbuiltin(char *s) {
diff --cc footobar.c
Simple merge
diff --cc main.c
index 966f003b7cc8debf3e9609c81510824e5eba22fb,cfc31cb966d1bd48bc4b779a262d2439f24bc932..32660fb6ca49623f9776c68fb588e13a83fd4ecb
--- 1/main.c
--- 2/main.c
+++ b/main.c
  #include "rc.h"
  
  char* ARGV0;
- bool dashee, dasheye, dashen, dashpee, interactive;
+ bool interactive;
  pid_t rc_pid;
  
 +static bool dashEYE, dashell, dashoh;
 +
  static void assigndefault(char *,...);
  static void checkfd(int, enum redirtype);
  
  void usage(void) {
 -      printf("Usage: %s [OPTION...] [FILE [ARG...]]\n", ARGV0);
 +    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();
 -      ARGV0 = dollarzero = argv[0];
 -      rc_pid = getpid();
 +    char *dashsee[2], *dollarzero, *null[1];
 +    initprint();
 +    dashsee[0] = dashsee[1] = NULL;
 +    dollarzero = argv[0];
 +    rc_pid = getpid();
 +    dashell = (*argv[0] == '-'); /* login shell, per unix tradition */
 +    
 +    OPTBEGIN {
 +        case 'e': dashee  = true; break;
 +        case 'l': dashell = true; break;
-         case 'n': dashen  = true; break;
 +        case 'o': dashoh  = true; break;
 +        case 'p': dashpee = true; break;
-         case 'i': 
-             dasheye = true;
-             interactive = true; 
-             break;
-         case 'I':
-             dashEYE = true;
-             interactive = false;
-             break;
 +        case 'c':
 +            dashsee[0] = EOPTARG(usage());
 +            break;
 +    } OPTEND;
  
 -      /* use isatty() iff neither -i nor -I is set, and iff the input is not from a script or -c flags */
 -      interactive = isatty(0);
 -      checkfd(0, rFrom);
 -      checkfd(1, rCreate);
 -      checkfd(2, rCreate);
 -      
 -      initsignal();
 -      inithash();
 -      initparse();
 -      assigndefault("ifs", " ", "\t", "\n", (void *)0);
 -      assigndefault("path", DEFAULTPATH, (void *)0);
 -      assigndefault("pid", nprint("%d", rc_pid), (void *)0);
 -      assigndefault("prompt", "; ", "", (void *)0);
 -      assigndefault("version", VERSION, "$Release: @(#)" PACKAGE " " VERSION " " RELDATE " $", (void *)0);
 -      initenv(envp);
 -      initinput();
 -      null[0] = NULL;
 -      starassign(dollarzero, null, false); /* assign $0 to $* */
 -      inithandler();
 +    /* use isatty() iff neither -i nor -I is set, and iff the input is not from a script or -c flags */
-     if (!dasheye && !dashEYE && dashsee[0] == NULL && (*argv == NULL))
-         interactive = isatty(0);
-     if (!dashoh) {
-         checkfd(0, rFrom);
-         checkfd(1, rCreate);
-         checkfd(2, rCreate);
-     }
++    interactive = isatty(0);
++    checkfd(0, rFrom);
++    checkfd(1, rCreate);
++    checkfd(2, rCreate);
 -      pushfd(0); // Read stdin
 -      doit(true);
 -      rc_exit(getstatus());
 -      return 0; /* Never really reached. */
 +    initsignal();
 +    inithash();
 +    initparse();
 +    assigndefault("ifs", " ", "\t", "\n", (void *)0);
- #ifdef DEFAULTPATH
 +    assigndefault("path", DEFAULTPATH, (void *)0);
- #endif
 +    assigndefault("pid", nprint("%d", rc_pid), (void *)0);
 +    assigndefault("prompt", "; ", "", (void *)0);
 +    assigndefault("version", VERSION, "$Release: @(#)" PACKAGE " " VERSION " " RELDATE " $", (void *)0);
 +    initenv(envp);
 +    initinput();
 +    null[0] = NULL;
 +    starassign(dollarzero, null, false); /* assign $0 to $* */
 +    inithandler();
++    
++    pushfd(0); // setup to read stdin
 +
-     if (dashell) {
-         char *rcrc;
-         int fd;
-         rcrc = concat(varlookup("home"), word("/.rcrc", NULL))->w;
-         fd = rc_open(rcrc, rFrom);
-         if (fd == -1) {
-             if (errno != ENOENT)
-                 uerror(rcrc);
-         } else {
-             bool push_interactive;
-             pushfd(fd);
-             push_interactive = interactive;
-             interactive = false;
-             doit(true);
-             interactive = push_interactive;
-             close(fd);
-         }
-     }
-     if (dashsee[0] != NULL) {    /* input from  -c or -s? */
-         if (*argv != NULL)
-             starassign(dollarzero, argv, false);
-         pushstring(dashsee, true);
-     } else if (*argv != NULL) {    /* else from a file? */
-         b_dot(--argv);
-         rc_exit(getstatus());
-     } else {            /* else stdin */
-         pushfd(0);
-     }
-     dasheye = false;
 +    doit(true);
 +    rc_exit(getstatus());
 +    return 0; /* Never really reached. */
  }
  
- static void assigndefault(char *name,...) {
-     va_list ap;
-     List *l;
-     char *v;
-     va_start(ap, name);
-     for (l = NULL; (v = va_arg(ap, char *)) != NULL;)
-         l = append(l, word(v, NULL));
-     varassign(name, l, false);
-     set_exportable(name, false);
-     if (streq(name, "path"))
-         alias(name, l, false);
-     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);
+ static void assigndefault(char *name, ...) {
+       va_list ap;
+       List *l;
+       char *v;
+       va_start(ap, name);
+       for (l = NULL; (v = va_arg(ap, char *)) != NULL;)
+               l = append(l, word(v, NULL));
+       varassign(name, l, false);
+       set_exportable(name, false);
+       if (streq(name, "path"))
+               alias(name, l, false);
+       va_end(ap);
  }
 -