int main(int argc, char *argv[]) { int ch; char *fn; /* Report stack usage at end if compile option is set */ __REPORT_STACK(); /* Parse the command-line options */ while ((ch = getopt(argc, argv, "bc")) != -1) switch (ch) { case 'c': cflag = 1; break; case 'b': bflag = 1; break; case '?': default: usage(); } argc -= optind; argv = argv + optind; if (!*argv) usage(); else { /* Start up the resource manager */ ResourceStartUp(userid()); /* Parse the command-line filenames */ while (*argv) { fn = *argv++; ReadResources(fn); if (*argv && !bflag) (void)printf("\n"); } /* Shut down the resource manager */ /* (which closes open resource files) */ ResourceShutDown(); } exit(rval); }
int main (int argc, char **argv) { char *path; int i, result1, result2; /* make sure GNO is running */ if (needsgno()==0) { errx(1, "Requires GNO\n"); } __REPORT_STACK(); /* initialization */ v_flag = V_flag = M_flag = m_flag = p_flag = err_flag = 0; result1 = result2 = 0; /* parse command line and check usage */ while((i = getopt(argc,argv,"M:m:pVv")) != EOF) { switch(i) { case 'M': if (m_flag) err_flag++; M_flag++; path = optarg; break; case 'm': if (M_flag) err_flag++; m_flag++; path = optarg; break; case 'p': p_flag++; v_flag++; break; case 'V': V_flag++; break; case 'v': v_flag++; break; default: err_flag++; } } if (err_flag || V_flag) { fprintf(stderr,"%s version %s by Devin Reade\n", basename(argv[0]),versionstr); } if (err_flag) { fprintf(stderr,"Usage: %s [-pVv] [-M path] [-m path] [section ...]\n", basename(argv[0])); } if (err_flag || V_flag) return 1; /* translate selected "sections" into something more understandable */ for (i=optind; i<argc; i++) { if (!strcmp(argv[i],"local")) argv[i] = "l"; if (!strcmp(argv[i],"new")) argv[i] = "n"; if (!strcmp(argv[i],"old")) argv[i] = "o"; if (!strcmp(argv[i],"public")) argv[i] = "p"; } /* do the search */ if (M_flag) { manpath = path; } else { manpath = getManpath(); } result1 = catman(argc-optind, &argv[optind]); if (!M_flag) free(manpath); if (m_flag) { manpath = path; result2 = catman(argc-optind, &argv[optind]); } return (result1 || result2); }
int main(int argc, char **argv) { char *p, delimiter = '/'; int ch; #ifdef __GNO__ __REPORT_STACK(); #endif while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { case '?': default: usage(); } argc -= optind; argv += optind; if (argc != 1) usage(); /* * (1) Check for the existence of a colon ':' character for the * delimiter. If a colon is used, it will be used; otherwise * the delimiter will be a backslash '/'. */ # ifdef __GNO__ for (p = *argv;; ++p) { if (*p == ':') { delimiter = ':'; break; } if (!*p) break; } # endif /* * (2) If string consists entirely of slash characters, string * shall be set to a single slash character. In this case, * skip steps (3) through (8). */ for (p = *argv;; ++p) { if (!*p) { if (p > *argv) (void)printf("%c\n", delimiter); else (void)printf(".\n"); exit(0); } if (*p != delimiter) break; } /* * (3) If there are any trailing slash characters in string, they * shall be removed. */ for (; *p; ++p); while (*--p == delimiter) continue; *++p = '\0'; /* * (4) If there are no slash characters remaining in string, * string shall be set to a single period character. In this * case skip steps (5) through (8). * * (5) If there are any trailing nonslash characters in string, * they shall be removed. */ # ifndef __GNO__ while (--p >= *argv) if (*p == delimiter) break; ++p; if (p == *argv) { (void)printf(".\n"); exit(0); } /* * (6) If the remaining string is //, it is implementation defined * whether steps (7) and (8) are skipped or processed. * * This case has already been handled, as part of steps (1) and (2). */ /* * (7) If there are any trailing slash characters in string, they * shall be removed. */ while (--p >= *argv) if (*p == delimiter) break; ++p; /* * (8) If the remaining string is empty, string shall be set to * a single slash character. */ *p = '\0'; (void)printf("%s\n", p == *argv ? delimiter : *argv); # else puts(dirname(*argv)); # endif exit(0); }