main(int argc, char *argv[]) #endif { int ch, secs; #if defined(__GNO__) && defined(__STACK_CHECK__) _beginStackCheck(); atexit(report_stack); #endif while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { case '?': default: usage(); } argc -= optind; #ifndef __ORCAC__ argv += optind; #else /* ORCA/C 2.1 compiler cannot handle += on pointer */ argv = argv + optind; #endif if (argc != 1) usage(); if ((secs = atoi(*argv)) > 0) (void)sleep(secs); exit(0); }
main(int argc, char *argv[]) #endif { int ch, rflag; #if defined(__GNO__) && defined(__STACK_CHECK__) _beginStackCheck(); atexit(report_stack); #endif rflag = 0; while ((ch = getopt(argc, argv, "dfiPRr")) != EOF) switch(ch) { case 'd': dflag = 1; break; case 'f': fflag = 1; iflag = 0; break; case 'i': fflag = 0; iflag = 1; break; case 'P': Pflag = 1; break; case 'R': case 'r': /* Compatibility. */ rflag = 1; break; default: usage(); } argc -= optind; #ifndef __ORCAC__ argv += optind; #else argv = argv + optind; #endif if (argc < 1) usage(); checkdot(argv); if (!*argv) exit (eval); stdin_ok = isatty(STDIN_FILENO); uid = geteuid(); if (rflag) rm_tree(argv); else rm_file(argv); exit (eval); }
main(int argc, char *argv[]) #endif { extern int optind; int ch; #if defined(__GNO__) && defined(__STACK_CHECK__) _beginStackCheck(); atexit(report_stack); #endif #ifndef __GNO__ setlocale(LC_CTYPE, ""); #endif while ((ch = getopt(argc, argv, "benstuv")) != -1) switch (ch) { case 'b': bflag = nflag = 1; /* -b implies -n */ break; case 'e': eflag = vflag = 1; /* -e implies -v */ break; case 'n': nflag = 1; break; case 's': sflag = 1; break; case 't': tflag = vflag = 1; /* -t implies -v */ break; case 'u': setbuf(stdout, (char *)NULL); break; case 'v': vflag = 1; break; default: (void)fprintf(stderr, "usage: cat [-benstuv] [-] [file ...]\n"); exit(1); } #ifndef __ORCAC__ argv += optind; #else argv = argv + optind; #endif if (bflag || eflag || nflag || sflag || tflag || vflag) cook_args(argv); else raw_args(argv); if (fclose(stdout)) err(1, "stdout"); exit(rval); }
int main(int argc, char *argv[]) { int fd; int exit_status=0; int ch; #if defined(__STACK_CHECK__) _beginStackCheck(); atexit(report_stack); #endif /* Get option, if present */ while ((ch = getopt(argc, argv, "d")) != EOF) { switch(ch) { case 'd': decimal_output = TRUE; break; default: usage(); } } argc -= optind; argv = argv + optind; /* Make sure that at least one filename was provided */ if (argc < 1) usage(); /* Print header [v1.1] */ printf( "File Type Size Stack Name\n"); printf( "-------------------- ------------------ -------- ------ ----------------\n"); while (argc-- > 0) { if ((fd = open(*argv, O_RDONLY)) < 0) { exit_status = 1; warn("%s", *argv); } else { scanOMF(fd,*argv); close(fd); } ++argv; } return exit_status; }
main(int argc, char *argv[]) #endif { int ch; char *p; #if defined(__GNO__) && defined(__STACK_CHECK__) _beginStackCheck(); atexit(report_stack); #endif /* * Flags for pwd are a bit strange. The POSIX 1003.2B/D9 document * has an optional -P flag for physical, which is what this program * will produce by default. The logical flag, -L, should fail, as * there's no way to display a logical path after forking. We don't * document either flag, only adding -P for future portability. */ while ((ch = getopt(argc, argv, "P")) != -1) switch (ch) { case 'P': break; case '?': default: usage(); } argc -= optind; #ifndef __ORCAC__ argv += optind; #else /* ORCA/C 2.1 compiler cannot handle += on pointer */ argv = argv + optind; #endif if (argc != 0) usage(); if ((p = getcwd(NULL, 0)) == NULL) err(1, NULL); (void)printf("%s\n", p); exit(0); }
int main(int argc, char **argv) { unsigned i; int ch; const char *path; const char *search_path = 0; static unsigned zero = 0; #ifdef __STACK_CHECK__ _beginStackCheck(); atexit(stackResults); #endif // work around GNO/ME environment bug. PushVariablesGS(&zero); if (_toolErr) { errx(1, "PushVariablesGS: $%04x", _toolErr); } while ((ch = getopt(argc, argv, "-ivP:S:u:x:")) != -1) { switch(ch) { case 'v': _v++; break; case 'i': case '-': reset_env(); break; case 'u': unset_env(optarg); break; case 'x': /* GNO-specific: set prefix */ set_prefix(optarg); break; case 'P': search_path = optarg; break; case 'S': // not a posix flag. errx(1, "-S is not supported"); break; case '?': default: usage(); } } argc -= optind; argv += optind; for( ; argc; ++argv, --argc) { if (!set_env(*argv)) break; } if (!argc) { print_env(); exit(0); } path = find_path(argv[0], search_path); if (_v) { fprintf(stderr, "#env executing:\t%s\n", path); for (i = 0; i < argc; ++i) fprintf(stderr, "#env arg[%d]= '%s'\n", i, argv[i]); } execv(path, argv); exit(errno == ENOENT ? 127 : 126); return 0; }
int main (int argc, char **argv) { FILE *FInPtr, *FOutPtr; long int *record_locs, currLoc, endOfFile; char *buffer; int2 lines, namecount, i, j; nameEntry nameStruct; int c, errflag; char *db_path; /* initialize globals */ Vflag=0; errflag=0; #ifdef __STACK_CHECK__ _beginStackCheck(); #endif assert(sizeof(int2)==2); assert(sizeof(int4)==4); /* Get database path: If DESCDB is set, use it, otherwise use DATABASE */ if (getenv("DESCDB") == 0) { if ((db_path = strdup(DATABASE)) == 0) { fprintf(stderr,"couldn't allocate path variable\n"); exit (-1); } } else { if ((db_path = strdup(getenv("DESCDB"))) == 0) { fprintf(stderr,"couldn't allocate path variable\n"); exit (-1); } } /* parse command line */ while ((c = getopt(argc, argv, "hV")) != EOF) { switch (c) { case 'V': version(basename(argv[0])); break; case 'h': /*FALLTHROUGH*/ default: errflag++; break; } } if (errflag || (argc-optind != 1)) { free (db_path); usage(basename(argv[0])); } /* open input and output files */ if ((buffer = malloc (MAX_LINE_LENGTH)) == NULL) { fprintf(stderr,"couldn't allocate line buffer\n"); free (db_path); exit (-1); } if ((FInPtr = fopen(argv[argc-1],"r")) == NULL) { fprintf(stderr,"Error opening %s; exiting.\n",argv[argc-1]); free (db_path); free(buffer); exit(1); } if ((FOutPtr = fopen(db_path,"wb+")) == NULL) { fprintf(stderr,"Error opening database file %s; exiting.\n",db_path); free (db_path); free(buffer); exit(1); } /* Compile array of names */ lines = 0; namecount = 0; /* space for # of array entries */ fwrite((void *)&namecount,sizeof(namecount),1,FOutPtr); while(mygets(buffer,&lines,FInPtr) != -1) { if (!strncmp(buffer,NAME,FIELD_LEN)) { /* found a match */ strncpy(nameStruct.name,&buffer[FIELD_LEN],NAME_LEN-1); nameStruct.name[NAME_LEN-1] = '\0'; fwrite((void *)&nameStruct,sizeof(nameStruct),1,FOutPtr); namecount++; } } if ((record_locs = malloc (namecount*sizeof(long int)))==NULL) { fprintf(stderr,"malloc of record_locs failed (%ld bytes); exiting\n", (long) namecount*sizeof(long int)); exit(-1); } rewind(FInPtr); buffer[0] = '\0'; lines = 0; fputc('\t',FOutPtr); /* Increment to first field */ while (strncmp(buffer,NAME,FIELD_LEN)) /* found a match! */ mygets(buffer,&lines,FInPtr); { /* BUGBUG 22/10/95 Soenke Behrens */ /* ORCA/C does not advance the file position indicator */ /* correctly after above fputc(). This tries to remedy */ /* the situation. Take out once library has been fixed */ fprintf(FOutPtr,"Junk"); fseek(FOutPtr,-4,SEEK_CUR); } /* Write out records and keep track of their file offsets */ for (i = 0; i < namecount; i++) { record_locs[i] = ftell(FOutPtr); /* print out <Version>, <Shell>, <Author>, <Contact>, <Where>, <FTP> */ for (j = 0; j < FIELD_COUNT-1; j++) { buffer[FIELD_LEN] = '\0'; mygets(buffer,&lines,FInPtr); fprintf(FOutPtr,"%s\n",&buffer[FIELD_LEN]); } /* handle <description> field */ for (;;) { if (mygets(buffer,&lines,FInPtr) == -1) break; if (!strncmp(buffer,NAME,FIELD_LEN)) break; fprintf(FOutPtr,"%s ",buffer); } fputc('\n',FOutPtr); } endOfFile = ftell(FOutPtr); fflush(FOutPtr); /*gdr 1*/ rewind(FOutPtr); fwrite((void *)&namecount,sizeof(namecount),1,FOutPtr); fflush(FOutPtr); /*gdr 1*/ /* time to go through the record_locs array and backpatch in */ /* all the record locations. A little slower than necessary */ /* perhaps, but it gets the job done. */ for (i = 0; i < namecount; i++) { fread(&nameStruct,sizeof(nameStruct),1,FOutPtr); fseek(FOutPtr,-(sizeof(nameStruct)),SEEK_CUR); nameStruct.offset = record_locs[i]; fwrite((void *)&nameStruct,sizeof(nameStruct),(size_t) 1,FOutPtr); fflush(FOutPtr); } fseek(FOutPtr,endOfFile,SEEK_SET); fclose(FOutPtr); #ifdef __GNO__ /* change the filetype of the database to BIN */ changeToBin(db_path); #endif free(db_path); free(record_locs); free(buffer); #ifdef __STACK_CHECK__ fprintf(stderr,"stack usage: %d bytes\n", _endStackCheck()); #endif return 0; }
int main(int argc, char *argv[]) { int i,item; #ifdef __STACK_CHECK__ _beginStackCheck(); atexit(stackResults); #endif ioctl(STDIN_FILENO,TIOCGETP,&sg); ioctl(STDIN_FILENO,TIOCGETC,&tc); ioctl(STDIN_FILENO,TIOCGLTC,<c); ioctl(STDIN_FILENO,TIOCLGET,&localmode); ioctl(STDIN_FILENO,TIOCGWINSZ,&wz); if (argc < 2) { printCurSettings(); exit(0); } for (i = 1; i < argc;) { switch (item = lookup(argv[i])) { case INTR_C: tc.t_intrc = parsechar(argv[i+1]); i++; break; case SUSP_C: ltc.t_suspc = parsechar(argv[i+1]); i++; break; case DSUSP_C: ltc.t_dsuspc = parsechar(argv[i+1]); i++; break; case STOP_C: tc.t_stopc = parsechar(argv[i+1]); i++; break; case START_C: tc.t_startc = parsechar(argv[i+1]); i++; break; case QUIT_C: tc.t_quitc = parsechar(argv[i+1]); i++; break; case ERASE_C: sg.sg_erase = parsechar(argv[i+1]); i++; break; case EOF_C: tc.t_eofc = parsechar(argv[i+1]); i++; break; case WERASE_C: ltc.t_werasc = parsechar(argv[i+1]); i++; break; case FLUSH_C: ltc.t_flushc = parsechar(argv[i+1]); i++; break; case LNEXT_C: ltc.t_lnextc = parsechar(argv[i+1]); i++; break; case RPRNT_C: ltc.t_rprntc = parsechar(argv[i+1]); i++; break; case ECHO_ON: sg.sg_flags |= ECHO; break; case ECHO_OFF: sg.sg_flags &= ~ECHO; break; case RAW_OFF: sg.sg_flags &= ~RAW; break; case RAW_ON: sg.sg_flags |= RAW; break; case CBREAK_OFF: sg.sg_flags &= ~CBREAK; break; case CBREAK_ON: sg.sg_flags |= CBREAK; break; case CRMOD_OFF: sg.sg_flags &= ~CRMOD; break; case CRMOD_ON: sg.sg_flags |= CRMOD; break; case LCTLECH_ON: localmode |= LCTLECH; break; case LCTLECH_OFF: localmode &= ~LCTLECH; break; case LCRTERA_ON: localmode |= LCRTERA; break; case LCRTERA_OFF: localmode &= ~LCRTERA; break; default: if ((item != 0) && (item <= B38400)) { sg.sg_ispeed = item; sg.sg_ospeed = item; } else usage(); break; } i++; } ioctl(STDIN_FILENO,TIOCSETP,&sg); ioctl(STDIN_FILENO,TIOCSETC,&tc); ioctl(STDIN_FILENO,TIOCSLTC,<c); ioctl(STDIN_FILENO,TIOCLSET,&localmode); }
int main (int argc, char **argv) { FILE *FInPtr; char searchName[NAME_LEN]; int2 verbose, numOfEntries, cmp, offset1, offset2, check, i; nameEntry nameStruct; int c, errflag; char *p, *tmp; char *db_path; #ifdef __STACK_CHECK__ _beginStackCheck(); #endif verbose = FALSE; Vflag = FALSE; errflag = FALSE; /* Get database path: If DESCDB is set, use it, otherwise use DATABASE */ if (getenv("DESCDB") == 0) { if ((db_path = strdup(DATABASE)) == 0) { fprintf(stderr,"couldn't allocate path variable\n"); exit (-1); } } else { if ((db_path = strdup(getenv("DESCDB"))) == 0) { fprintf(stderr,"couldn't allocate path variable\n"); exit (-1); } } while ((c = getopt(argc,argv,"hvV")) != EOF) { switch (c) { case 'v': verbose = TRUE; break; case 'V': version(basename(argv[0])); break; case 'h': default: errflag = TRUE; break; } } if (errflag || (argc-optind != 1)) { free (db_path); usage(basename(argv[0])); } if ((FInPtr = fopen(db_path,"rb")) == NULL) { perror("couldn't open database"); free (db_path); exit(-1); } fread(&numOfEntries,2,1,FInPtr); offset1 = 0; offset2 = numOfEntries-1; strcpy(searchName,argv[optind]); i=0; p = searchName; while (*p) { *p = tolower(*p); p++; } if (verbose) printf("Searching...\n"); while (1) { check = ((offset2-offset1)/2) + offset1; fseek(FInPtr,2+(check*sizeof(nameEntry)),SEEK_SET); fread(&nameStruct,sizeof(nameEntry),1,FInPtr); if((tmp = strdup(nameStruct.name)) == 0) { fprintf(stderr,"couldn't copy name string\n"); free (db_path); exit (-1); } p = nameStruct.name; while (*p) { *p = tolower(*p); p++; } cmp = strcmp(nameStruct.name,searchName); if (verbose) printf(" checked %s\n",tmp); if (cmp > 0) { /* name bigger than searchName */ offset2 = check-1; } else if (cmp < 0) { /* name smaller than searchName */ offset1 = check+1; } else { if (verbose) { printf("Found entry %s!\n",tmp); #ifdef __STACK_CHECK__ printf("Stack: %d\n", _endStackCheck()); #endif free (db_path); free (tmp); exit(0); } printf("%s%s\n",NAME,tmp); free (db_path); free (tmp); print_entry(FInPtr,nameStruct.offset); } if (offset1 > offset2) { printf("Entry '%s' not found in describe database.\n",searchName); #ifdef __STACK_CHECK__ printf("Stack: %d\n", _endStackCheck()); #endif free (db_path); free (tmp); exit(1); } } }
int main(int argc, char **argv) { int c, result, pflag; char delim, *path, *root, *p, *q; #ifdef __STACK_CHECK__ _beginStackCheck(); atexit(printStack); #endif pflag = 0; while ((c = getopt (argc, argv, "p")) != EOF) { switch (c) { case 'p': pflag = 1; break; default: usage(); } } if ((argc - optind) == 0) { usage(); } result = 0; /* loop over all filenames */ for (; optind<argc; optind++) { path = argv[optind]; if (pflag == 0) { /* * Just do the last directory component, and * skip the mess below */ if (rmdir(path)!=0) { warn("%s skipped", path); result++; } } else { /* get the full pathname */ if ((path = LC_ExpandPath (path)) == NULL) { warn("couldn't expand %s", argv[optind]); continue; } if ((q = strdup(path)) == NULL) { err(1, nodup, path); } path = q; /* what is the volume component? */ q = (*path == ':') ? path+1 : path; q = strchr(q, ':'); if (q != NULL) { *q = '\0'; } if (*path == ':') { if ((root = strdup(path)) == NULL) { err(1, nodup, path); } } else { root = NULL; } if (q != NULL) { *q = ':'; } for(;;) { if (*path == '\0') { /* deleted all the directories */ break; } if ((root != NULL) && !strcmp(root, path)) { /* don't try to delete the volume */ break; } if (rmdir(path)!=0) { warn("%s skipped", path); result++; break; } p = path + strlen(path) - 1; while (p >= path) { if (*p == ':') { *p = '\0'; break; } else { *p-- = '\0'; } } } } } return result; }
main(int argc, char *argv[]) #endif { struct stat sb1, sb2; off_t skip1, skip2; int ch, fd1, fd2, special; char *file1, *file2; #ifdef __STACK_CHECK__ atexit(cleanup); _beginStackCheck(); #endif #ifdef __GNO__ while ((ch = getopt(argc, argv, "-lsr")) != -1) #else while ((ch = getopt(argc, argv, "-ls")) != -1) #endif switch (ch) { case 'l': /* print all differences */ lflag = 1; break; case 's': /* silent run */ sflag = 1; break; #ifdef __GNO__ case 'r': rflag = 1; /* ignore resource fork */ break; #endif case '-': /* stdin (must be after options) */ --optind; goto endargs; case '?': default: usage(); } endargs: #ifndef __ORCAC__ argv += optind; #else argv = argv + optind; #endif argc -= optind; if (lflag && sflag) errx(ERR_EXIT, "only one of -l and -s may be specified"); if (argc < 2 || argc > 4) usage(); /* Backward compatibility -- handle "-" meaning stdin. */ special = 0; if (strcmp(file1 = argv[0], "-") == 0) { special = 1; fd1 = 0; file1 = "stdin"; } #ifndef __GNO__ else if ((fd1 = open(file1, O_RDONLY, 0)) < 0) { #else /* open() for GNO/ME requires 3rd arg iff creating file */ else if ((fd1 = open(file1, O_RDONLY)) < 0) { #endif if (!sflag) err(ERR_EXIT, "%s", file1); else exit(1); } if (strcmp(file2 = argv[1], "-") == 0) { if (special) errx(ERR_EXIT, "standard input may only be specified once"); special = 1; fd2 = 0; file2 = "stdin"; } #ifndef __GNO__ else if ((fd2 = open(file2, O_RDONLY, 0)) < 0) { #else else if ((fd2 = open(file2, O_RDONLY)) < 0) { #endif if (!sflag) err(ERR_EXIT, "%s", file2); else exit(1); } skip1 = argc > 2 ? strtol(argv[2], NULL, 10) : 0; skip2 = argc == 4 ? strtol(argv[3], NULL, 10) : 0; #ifndef __GNO__ if (!special) { if (fstat(fd1, &sb1)) { if (!sflag) err(ERR_EXIT, "%s", file1); else exit(1); } if (!S_ISREG(sb1.st_mode)) special = 1; else { if (fstat(fd2, &sb2)) { if (!sflag) err(ERR_EXIT, "%s", file2); else exit(1); } if (!S_ISREG(sb2.st_mode)) special = 1; } } #else special = 1; /* GNO doesn't have mmap.h, so treat every file as a special file and process byte by byte */ #endif if (special) #ifdef __GNO__ { #endif c_special(fd1, file1, skip1, fd2, file2, skip2); #ifdef __GNO__ close(fd1); close(fd2); } if (rflag != 1) { rflag = 2; rcmp(&fd1, &fd2, file1, file2); close(fd1); close(fd2); } #else else c_regular(fd1, file1, skip1, sb1.st_size, fd2, file2, skip2, sb2.st_size); #endif /* exit(0); */ } static void #ifndef __STDC__ usage() #else usage(void) #endif { (void)fprintf(stderr, #ifndef __GNO__ "usage: cmp [-l | -s] file1 file2 [skip1 [skip2]]\n"); #else "usage: cmp [-l | -s] [-r] file1 file2 [skip1 [skip2]]\n"); #endif exit(ERR_EXIT); }