string & DosTextEditer::edcommand(string prompt,ostream &out,LinkList<string> &tmpfile) // pre: string is == to the prompt you wont and ostream == to the stream you wont to output too tmpfile == the file you have opend { string tmpstr; unsigned __int8 changed=0; do { cout<<prompt; MSF::getline(cin,tmpstr); if(tmpstr[0]!='Q') { tmpstr=MSF::tolower(tmpstr); } if(do_range(tmpstr,tmpfile,changed,out)); else if(do_double(tmpstr,tmpfile,changed,out)); else if(do_single(tmpstr,tmpfile,changed,out)); else { cout<<"Bad command."<<endl; } }while(tmpstr[0]!='Q'); return filename; }
int main(int argc, char *argv[]) { int ch, options = 0, action = CCD_CONFIG; while ((ch = getopt(argc, argv, "cCf:guUv")) != -1) { switch (ch) { case 'c': action = CCD_CONFIG; ++options; break; case 'C': action = CCD_CONFIGALL; ++options; break; case 'f': ccdconf = optarg; break; case 'g': action = CCD_DUMP; break; case 'u': action = CCD_UNCONFIG; ++options; break; case 'U': action = CCD_UNCONFIGALL; ++options; break; case 'v': verbose = 1; break; default: usage(); } } argc -= optind; argv += optind; if (options > 1) usage(); if (modfind("g_ccd") < 0) { /* Not present in kernel, try loading it */ if (kldload("geom_ccd") < 0 || modfind("g_ccd") < 0) warn("geom_ccd module not available!"); } switch (action) { case CCD_CONFIG: case CCD_UNCONFIG: exit(do_single(argc, argv, action)); /* NOTREACHED */ case CCD_CONFIGALL: case CCD_UNCONFIGALL: exit(do_all(action)); /* NOTREACHED */ case CCD_DUMP: exit(dump_ccd(argc, argv)); /* NOTREACHED */ } /* NOTREACHED */ return (0); }
static int do_all(int action) { FILE *f; char line[_POSIX2_LINE_MAX]; char *cp, **argv; int argc, rval; gid_t egid; rval = 0; egid = getegid(); if (setegid(getgid()) != 0) err(1, "setegid failed"); if ((f = fopen(ccdconf, "r")) == NULL) { if (setegid(egid) != 0) err(1, "setegid failed"); warn("fopen: %s", ccdconf); return (1); } if (setegid(egid) != 0) err(1, "setegid failed"); while (fgets(line, sizeof(line), f) != NULL) { argc = 0; argv = NULL; ++lineno; if ((cp = strrchr(line, '\n')) != NULL) *cp = '\0'; /* Break up the line and pass it's contents to do_single(). */ if (line[0] == '\0') goto end_of_line; for (cp = line; (cp = strtok(cp, " \t")) != NULL; cp = NULL) { if (*cp == '#') break; if ((argv = realloc(argv, sizeof(char *) * ++argc)) == NULL) { warnx("no memory to configure ccds"); return (1); } argv[argc - 1] = cp; /* * If our action is to unconfigure all, then pass * just the first token to do_single() and ignore * the rest. Since this will be encountered on * our first pass through the line, the Right * Thing will happen. */ if (action == CCD_UNCONFIGALL) { if (do_single(argc, argv, action)) rval = 1; goto end_of_line; } } if (argc != 0) if (do_single(argc, argv, action)) rval = 1; end_of_line: if (argv != NULL) free(argv); } (void)fclose(f); return (rval); }