STATIC void read_profile(const char *name) { int fd; int xflag_set = 0; int vflag_set = 0; if (*name == '\0') return; INTOFF; if ((fd = open(name, O_RDONLY)) >= 0) setinputfd(fd, 1); INTON; if (fd < 0) return; /* -q turns off -x and -v just when executing init files */ if (qflag) { if (xflag) xflag = 0, xflag_set = 1; if (vflag) vflag = 0, vflag_set = 1; } (void)set_dot_funcnest(1); /* allow profile to "return" */ cmdloop(0); (void)set_dot_funcnest(0); if (qflag) { if (xflag_set) xflag = 1; if (vflag_set) vflag = 1; } popfile(); }
STATIC void read_profile(const char *name) { int fd; int xflag_set = 0; int vflag_set = 0; INTOFF; if ((fd = open(name, O_RDONLY)) >= 0) setinputfd(fd, 1); INTON; if (fd < 0) return; /* -q turns off -x and -v just when executing init files */ if (qflag) { if (xflag) xflag = 0, xflag_set = 1; if (vflag) vflag = 0, vflag_set = 1; } cmdloop(0); if (qflag) { if (xflag_set) xflag = 1; if (vflag_set) vflag = 1; } popfile(); }
void readcmdfile(char *name) { setinputfile(name, INPUT_PUSH_FILE); cmdloop(0); popfile(); }
/* * We suck in lots of fsck code, and just pick & choose the stuff we want. * * fsreadfd is set up to read from the file system, fswritefd to write to * the file system. */ int main(int argc, char *argv[]) { int ch, rval; char *fsys = NULL; while (-1 != (ch = getopt(argc, argv, "f:d"))) { switch (ch) { case 'f': fsys = optarg; break; case 'd': debug++; break; default: usage(); } } if (fsys == NULL) usage(); if (!setup(fsys)) errx(1, "cannot set up file system `%s'", fsys); printf("Editing file system `%s'\nLast Mounted on %s\n", fsys, sblock.fs_fsmnt); rval = cmdloop(); sblock.fs_clean = 0; /* mark it dirty */ sbdirty(); ckfini(0); printf("*** FILE SYSTEM MARKED DIRTY\n"); printf("*** BE SURE TO RUN FSCK TO CLEAN UP ANY DAMAGE\n"); printf("*** IF IT WAS MOUNTED, RE-MOUNT WITH -u -o reload\n"); exit(rval); }
int dotcmd(int argc, char **argv) { exitstatus = 0; if (argc >= 2) { /* That's what SVR2 does */ char *fullname; /* * dot_funcnest needs to be 0 when not in a dotcmd, so it * cannot be restored with (funcnest + 1). */ int dot_funcnest_old; struct stackmark smark; setstackmark(&smark); fullname = find_dot_file(argv[1]); setinputfile(fullname, 1); commandname = fullname; dot_funcnest_old = dot_funcnest; dot_funcnest = funcnest + 1; cmdloop(0); dot_funcnest = dot_funcnest_old; popfile(); popstackmark(&smark); } return exitstatus; }
void readcmdfile(const char *name) { setinputfile(name, 1); cmdloop(0); popfile(); }
STATIC void read_profile(struct shinstance *psh, const char *name) { int fd; int xflag_set = 0; int vflag_set = 0; INTOFF; if ((fd = shfile_open(&psh->fdtab, name, O_RDONLY, 0)) >= 0) setinputfd(psh, fd, 1); INTON; if (fd < 0) return; /* -q turns off -x and -v just when executing init files */ if (qflag(psh)) { if (xflag(psh)) xflag(psh) = 0, xflag_set = 1; if (vflag(psh)) vflag(psh) = 0, vflag_set = 1; } cmdloop(psh, 0); if (qflag(psh)) { if (xflag_set) xflag(psh) = 1; if (vflag_set) vflag(psh) = 1; } popfile(psh); }
STATIC void read_profile(const char *name) { name = expandstr(name); if (setinputfile(name, INPUT_PUSH_FILE | INPUT_NOFILE_OK) < 0) return; cmdloop(0); popfile(); }
void readcmdfile(struct shinstance *psh, char *name) { int fd; INTOFF; if ((fd = shfile_open(&psh->fdtab, name, O_RDONLY, 0)) >= 0) setinputfd(psh, fd, 1); else error(psh, "Can't open %s", name); INTON; cmdloop(psh, 0); popfile(psh); }
void readcmdfile(char *name) { int fd; INTOFF; if ((fd = open(name, O_RDONLY)) >= 0) setinputfd(fd, 1); else error("Can't open %s", name); INTON; cmdloop(0); popfile(); }
static void read_profile(const char *name) { int fd; INTOFF; if ((fd = open(name, O_RDONLY)) >= 0) setinputfd(fd, 1); INTON; if (fd < 0) return; cmdloop(0); popfile(); }
void readcmdfile(const char *name) { int fd; INTOFF; if ((fd = open(name, O_RDONLY)) >= 0) setinputfd(fd, 1); else error("cannot open %s: %s", name, strerror(errno)); INTON; cmdloop(0); popfile(); }
/* * We suck in lots of fsck code, and just pick & choose the stuff we want. * * fsreadfd is set up to read from the file system, fswritefd to write to * the file system. */ int main(int argc, char *argv[]) { int ch, rval; char *fsys = NULL; forceimage = 0; debug = 0; isappleufs = 0; while ((ch = getopt(argc, argv, "dFf:n")) != -1) { switch (ch) { case 'd': debug++; break; case 'F': forceimage = 1; break; case 'f': fsys = optarg; break; case 'n': nflag++; break; default: usage(); } } if (fsys == NULL) usage(); endian = 0; if (setup(fsys, fsys) <= 0) errx(1, "cannot set up file system `%s'", fsys); printf("Editing file system `%s'\nLast Mounted on %s\n", fsys, sblock->fs_fsmnt); rval = cmdloop(); if (nflag) exit(rval); sblock->fs_clean = 0; /* mark it dirty */ sbdirty(); markclean = 0; ckfini(1); printf("*** FILE SYSTEM MARKED DIRTY\n"); printf("*** BE SURE TO RUN FSCK TO CLEAN UP ANY DAMAGE\n"); printf("*** IF IT WAS MOUNTED, RE-MOUNT WITH -u -o reload\n"); exit(rval); }
/* * We suck in lots of fsck code, and just pick & choose the stuff we want. * * fsreadfd is set up to read from the file system, fswritefd to write to * the file system. */ int main(int argc, char *argv[]) { int ch, rval; char *fsys = NULL; while (-1 != (ch = getopt(argc, argv, "fdr"))) { switch (ch) { case 'f': /* The -f option is left for historical * reasons and has no meaning. */ break; case 'd': check_debug++; break; case 'r': nflag++; /* "no" in fsck, readonly for us */ break; default: usage(); } } argc -= optind; argv += optind; if (argc != 1) usage(); else fsys = argv[0]; check_sblock_init(); if (!check_setup(fsys, 0)) errx(1, "cannot set up file system `%s'", fsys); printf("%s file system `%s'\nLast Mounted on %s\n", nflag? "Examining": "Editing", fsys, check_sblk.b_un.b_fs->fs_fsmnt); rval = cmdloop(); if (!nflag) { check_sblk.b_un.b_fs->fs_clean = 0; /* mark it dirty */ dirty(&check_sblk); check_finish(0); printf("*** FILE SYSTEM MARKED DIRTY\n"); printf("*** BE SURE TO RUN FSCK TO CLEAN UP ANY DAMAGE\n"); printf("*** IF IT WAS MOUNTED, RE-MOUNT WITH -u -o reload\n"); } exit(rval); }
static void read_profile(char *name) { int fd; const char *expandedname; expandedname = expandstr(name); if (expandedname == NULL) return; INTOFF; if ((fd = open(expandedname, O_RDONLY)) >= 0) setinputfd(fd, 1); INTON; if (fd < 0) return; cmdloop(0); popfile(); }
int dotcmd(struct shinstance *psh, int argc, char **argv) { psh->exitstatus = 0; if (argc >= 2) { /* That's what SVR2 does */ char *fullname; struct stackmark smark; setstackmark(psh, &smark); fullname = find_dot_file(psh, argv[1]); setinputfile(psh, fullname, 1); psh->commandname = fullname; cmdloop(psh, 0); popfile(psh); popstackmark(psh, &smark); } return psh->exitstatus; }
int dotcmd(int argc, char **argv) { exitstatus = 0; if (argc >= 2) { /* That's what SVR2 does */ char *fullname; struct stackmark smark; setstackmark(&smark); fullname = find_dot_file(argv[1]); setinputfile(fullname, 1); commandname = fullname; cmdloop(0); popfile(); popstackmark(&smark); } return exitstatus; }
int dotcmd(int argc, char **argv) { int status = 0; nextopt(nullstr); argv = argptr; if (*argv) { char *fullname; fullname = find_dot_file(*argv); setinputfile(fullname, INPUT_PUSH_FILE); commandname = fullname; status = cmdloop(0); popfile(); } return status; }
int main(int argc, char **argv) { /* Argument processing - see comments for hw3_opt_proc */ struct fuse_args args = FUSE_ARGS_INIT(argc, argv); if (fuse_opt_parse(&args, &hw3_data, hw3_opts, hw3_opt_proc) == -1) exit(1); hw3_ops.destroy = hw3_destroy; if (hw3_data.cmd_mode) { hw3_ops.init(NULL); _blksiz(1000); cmdloop(); hw3_destroy(NULL); return 0; } else return fuse_main(args.argc, args.argv, &hw3_ops, NULL); }
/* * === FUNCTION ====================================================================== * Name: main * Description: 主函数,处理命令行参数后,尝试连接并进入主循环 * ===================================================================================== */ int main( int argc, char *argv[] ) { char *cp; argc--, argv++; while(argc > 0 && **argv == '-'){ for(cp = *argv + 1; *cp; cp++){ switch (*cp){ case 'a': automatic = 1; break; case 'p': passivemode = 1; break; case 'h': usage(); exit(0); default: printf("ftp: %c: unknown option\n", *cp); usage(); exit(1); } } argc--, argv++; } ftpport = getftpport(); /* 有主机名,试图建立连接 */ if (argc > 0) setpeer(*argv); signal(SIGINT, SIG_IGN); signal(SIGPIPE, lostpeer); while (1) { cmdloop(); } return EXIT_SUCCESS; } /* ---------- end of function main ---------- */
static void read_profile(const char *name) { int fd; const char *expandedname; expandedname = expandstr(__DECONST(char *, name)); if (expandedname == NULL) return; INTOFF; #ifndef O_CLOEXEC if ((fd = open(expandedname, O_RDONLY)) >= 0) #else if ((fd = open(expandedname, O_RDONLY | O_CLOEXEC)) >= 0) #endif setinputfd(fd, 1); INTON; if (fd < 0) return; cmdloop(0); popfile(); }
int dotcmd(int argc, char **argv) { char *filename, *fullname; if (argc < 2) error("missing filename"); exitstatus = 0; /* * Because we have historically not supported any options, * only treat "--" specially. */ filename = argc > 2 && strcmp(argv[1], "--") == 0 ? argv[2] : argv[1]; fullname = find_dot_file(filename); setinputfile(fullname, 1); commandname = fullname; cmdloop(0); popfile(); return exitstatus; }
void main(int argc, char *argv[]) { int i; String *t; char *termargs[10], **ap; ap = termargs; *ap++ = "samterm"; ARGBEGIN{ case 'd': dflag++; break; case 'r': machine = EARGF(usage()); break; case 'R': Rflag++; break; case 't': samterm = EARGF(usage()); break; case 's': rsamname = EARGF(usage()); break; default: dprint("sam: unknown flag %c\n", ARGC()); usage(); /* options for samterm */ case 'a': *ap++ = "-a"; break; } ARGEND *ap = nil; Strinit(&cmdstr); Strinit0(&lastpat); Strinit0(&lastregexp); Strinit0(&genstr); Strinit0(&rhs); Strinit0(&curwd); Strinit0(&plan9cmd); home = getenv(HOME); disk = diskinit(); if(home == 0) home = "/"; if(!dflag) startup(machine, Rflag, termargs, argv); notify(notifyf); getcurwd(); if(argc>0) { for(i=0; i<argc; i++) { if(!setjmp(mainloop)) { t = tmpcstr(argv[i]); Straddc(t, '\0'); Strduplstr(&genstr, t); freetmpstr(t); fixname(&genstr); logsetname(newfile(), &genstr); } } } else if(!downloaded) newfile(); seq++; if(file.nused) current(file.filepptr[0]); setjmp(mainloop); cmdloop(); trytoquit(); /* if we already q'ed, quitok will be TRUE */ exits(0); }
int main(int argc, char *argv[]) { int i, o; String *t; char *arg[argc + 1], **ap; int targc = 1; ap = &arg[argc]; arg[0] = "samterm"; setlocale(LC_ALL, ""); while ((o = getopt(argc, argv, "efdRr:t:s:")) != -1) { switch (o) { case 'e': arg[targc++] = "-e"; break; case 'f': arg[targc++] = "-f"; break; case 'd': dflag = true; break; case 'r': machine = optarg; rsamname = "rsam"; arg[targc++] = "-r"; arg[targc++] = optarg; break; case 'R': Rflag = true; break; case 't': samterm = optarg; break; case 's': rsamname = optarg; break; default: usage(); } } argv += optind; argc -= optind; arg[targc] = NULL; Strinit(&cmdstr); Strinit0(&lastpat); Strinit0(&lastregexp); Strinit0(&genstr); Strinit0(&rhs); Strinit0(&wd); Strinit0(&plan9cmd); tempfile.listptr = emalloc(0); home = getenv("HOME") ? getenv("HOME") : "/"; shpath = getenv("SHELL") ? getenv("SHELL") : shpath; sh = basename(shpath); if(!dflag) startup(machine, Rflag, arg, ap); Fstart(); signal(SIGINT, SIG_IGN); signal(SIGHUP, hup); signal(SIGPIPE, SIG_IGN); if(argc > 0) { for(i=0; i<argc; i++) if(!setjmp(mainloop)) { t = tmpcstr(argv[i]); Straddc(t, '\0'); Strduplstr(&genstr, t); freetmpstr(t); Fsetname(newfile(), &genstr); } } else if(!downloaded) newfile()->state = Clean; modnum++; if(file.nused) current(file.filepptr[0]); atexit(shutdown); setjmp(mainloop); cmdloop(); trytoquit(); /* if we already q'ed, quitok will be true */ exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { struct stackmark smark, smark2; volatile int state; char *shinit; (void) setlocale(LC_ALL, ""); initcharset(); state = 0; if (setjmp(main_handler.loc)) { switch (exception) { case EXEXEC: exitstatus = exerrno; break; case EXERROR: exitstatus = 2; break; default: break; } if (state == 0 || iflag == 0 || ! rootshell || exception == EXEXIT) exitshell(exitstatus); reset(); if (exception == EXINT) out2fmt_flush("\n"); popstackmark(&smark); FORCEINTON; /* enable interrupts */ if (state == 1) goto state1; else if (state == 2) goto state2; else if (state == 3) goto state3; else goto state4; } handler = &main_handler; #ifdef DEBUG opentrace(); trputs("Shell args: "); trargs(argv); #endif rootpid = getpid(); rootshell = 1; init(); setstackmark(&smark); setstackmark(&smark2); procargs(argc, argv); pwd_init(iflag); if (iflag) chkmail(1); if (argv[0] && argv[0][0] == '-') { state = 1; read_profile("/etc/profile"); state1: state = 2; if (privileged == 0) read_profile("${HOME-}/.profile"); else read_profile("/etc/suid_profile"); } state2: state = 3; if (!privileged && iflag) { if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') { state = 3; read_profile(shinit); } } state3: state = 4; popstackmark(&smark2); if (minusc) { evalstring(minusc, sflag ? 0 : EV_EXIT); } if (sflag || minusc == NULL) { state4: /* XXX ??? - why isn't this before the "if" statement */ cmdloop(1); } exitshell(exitstatus); /*NOTREACHED*/ return 0; }
int sammain(int argc, char *argv[]) { bool trylock = true; int i, o; String *t; char *arg[argc + 1], **ap; ap = &arg[argc]; arg[0] = "samterm"; setlocale(LC_ALL, ""); while ((o = getopt(argc, argv, "SedR:r:t:s:")) != -1){ switch (o){ case 'd': dflag = true; break; case 'r': machine = optarg; break; case 'R': rmsocketname = optarg; atexit(rmsocket); break; case 't': samterm = optarg; break; case 's': rsamname = optarg; break; case 'S': trylock = false; break; default: usage(); } } if (trylock && !canlocksocket(machine) && !dflag) return bmain(argc, argv); argv += optind; argc -= optind; Strinit(&cmdstr); Strinit0(&lastpat); Strinit0(&lastregexp); Strinit0(&genstr); Strinit0(&rhs); Strinit0(&wd); Strinit0(&plan9cmd); tempfile.listptr = emalloc(0); home = getenv("HOME") ? getenv("HOME") : "/"; shpath = getenv("SHELL") ? getenv("SHELL") : shpath; sh = basename(shpath); if(!dflag) startup(machine, rmsocketname != NULL, trylock); Fstart(); signal(SIGINT, SIG_IGN); signal(SIGHUP, hup); signal(SIGPIPE, SIG_IGN); if(argc > 0){ for(i=0; i<argc; i++) if(!setjmp(mainloop)){ t = tmpcstr(argv[i]); Straddc(t, '\0'); Strduplstr(&genstr, t); freetmpstr(t); Fsetname(newfile(), &genstr); } }else if(!downloaded) newfile()->state = Clean; modnum++; if(file.nused) current(file.filepptr[0]); atexit(scram); setjmp(mainloop); cmdloop(); trytoquit(); /* if we already q'ed, quitok will be true */ exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { cmdloop(); return 0; }
int main(int argc, char **argv) { char *shinit; volatile int state; struct jmploc jmploc; struct stackmark smark; int login; int i; for (i = 1; i < argc; i++) { if (0 == strcmp(argv[i], "--help") || 0 == strcmp(argv[i], "-h")) { sxsh_print_usage(); return (0); } if (0 == strcmp(argv[i], "--version") || 0 == strcmp(argv[i], "-v")) { sxsh_print_version(); return (0); } } #ifdef __GLIBC__ dash_errno = __errno_location(); #endif #if PROFILE monitor(4, etext, profile_buf, sizeof profile_buf, 50); #endif state = 0; if (unlikely(setjmp(jmploc.loc))) { int e; int s; reset(); e = exception; s = state; if (e == EXEXIT || s == 0 || iflag == 0 || shlvl) exitshell(); if (e == EXINT #if ATTY && (! attyset() || equal(termval(), "emacs")) #endif ) { out2c('\n'); #ifdef FLUSHERR flushout(out2); #endif } popstackmark(&smark); FORCEINTON; /* enable interrupts */ if (s == 1) goto state1; else if (s == 2) goto state2; else if (s == 3) goto state3; else goto state4; } handler = &jmploc; #ifdef DEBUG opentrace(); trputs("Shell args: "); trargs(argv); #endif rootpid = getpid(); init(); setstackmark(&smark); login = procargs(argc, argv); if (login) { state = 1; read_profile("/etc/profile"); state1: state = 2; read_profile("$HOME/.profile"); } state2: state = 3; if ( #ifndef linux getuid() == geteuid() && getgid() == getegid() && #endif iflag ) { if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') { read_profile(shinit); } } popstackmark(&smark); state3: state = 4; if (minusc) evalstring(minusc, sflag ? 0 : EV_EXIT); if (sflag || minusc == NULL) { state4: /* XXX ??? - why isn't this before the "if" statement */ cmdloop(1); } #if PROFILE monitor(0); #endif #if GPROF { extern void _mcleanup(void); _mcleanup(); } #endif exitshell(); /* NOTREACHED */ }
int main(int argc, char **argv) { struct jmploc jmploc; struct stackmark smark; volatile int state; char *shinit; setlocale(LC_ALL, ""); /* Just a --version for show. */ if (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-') { if (!strcmp(&argv[1][2], "version")) { printf("kmk_ash - kBuild version %d.%d.%d\n", KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR, KBUILD_VERSION_PATCH); return 0; } if (!strcmp(&argv[1][2], "help")) { printf("usage: kmk_ash [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n" " [+o option_name] [command_file [argument ...]]\n" " or: kmk_ash -c [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n" " [+o option_name] command_string [command_name [argument ...]]\n" " or: kmk_ash -s [-aCefnuvxIimqVEb] [+aCefnuvxIimqVEb] [-o option_name]\n" " [+o option_name] [argument ...]\n" " or: kmk_ash --help\n" " or: kmk_ash --version\n", argv[0], argv[0], argv[0], argv[0], argv[0]); return 0; } } #if PROFILE monitor(4, etext, profile_buf, sizeof profile_buf, 50); #endif state = 0; if (setjmp(jmploc.loc)) { /* * When a shell procedure is executed, we raise the * exception EXSHELLPROC to clean up before executing * the shell procedure. */ switch (exception) { case EXSHELLPROC: rootpid = getpid(); rootshell = 1; minusc = NULL; state = 3; break; case EXEXEC: exitstatus = exerrno; break; case EXERROR: exitstatus = 2; break; default: break; } if (exception != EXSHELLPROC) { if (state == 0 || iflag == 0 || ! rootshell) exitshell(exitstatus); } reset(); if (exception == EXINT #if ATTY && (! attyset() || equal(termval(), "emacs")) #endif ) { out2c('\n'); flushout(&errout); } popstackmark(&smark); FORCEINTON; /* enable interrupts */ if (state == 1) goto state1; else if (state == 2) goto state2; else if (state == 3) goto state3; else goto state4; } handler = &jmploc; #ifdef DEBUG #if DEBUG == 2 debug = 1; #endif opentrace(); trputs("Shell args: "); trargs(argv); #endif rootpid = getpid(); rootshell = 1; #ifdef _MSC_VER { extern void init_syntax(void); init_syntax(); } #endif init(); setstackmark(&smark); procargs(argc, argv); if (argv[0] && argv[0][0] == '-') { state = 1; #ifndef KMK read_profile("/etc/profile"); #endif state1: state = 2; #ifndef KMK read_profile(".profile"); #endif } state2: state = 3; #ifndef KMK if (getuid() == geteuid() && getgid() == getegid()) { if ((shinit = lookupvar("ENV")) != NULL && *shinit != '\0') { state = 3; read_profile(shinit); } } #endif state3: state = 4; if (sflag == 0 || minusc) { static int sigs[] = { SIGINT, SIGQUIT, SIGHUP, #ifdef SIGTSTP SIGTSTP, #endif SIGPIPE }; #define SIGSSIZE (sizeof(sigs)/sizeof(sigs[0])) int i; for (i = 0; i < SIGSSIZE; i++) setsignal(sigs[i], 0); } if (minusc) evalstring(minusc, 0); if (sflag || minusc == NULL) { state4: /* XXX ??? - why isn't this before the "if" statement */ cmdloop(1); } #if PROFILE monitor(0); #endif exitshell(exitstatus); /* NOTREACHED */ }
static DWORD WINAPI DbgCommandLoopThread(void* a) { cmdloop(command_list, cbBadCmd, cbCommandProvider, cmdfindmain, false); return 0; }