/* * test program * pgm runs regression * pgm sep splits stdin lines by sep * pgm str sep splits str by sep * pgm str sep n splits str by sep n times */ int main(int argc, char *argv[]) { char buf[512]; int n; # define MNF 10 char *fields[MNF]; if (argc > 4) for (n = atoi(argv[3]); n > 0; n--) { (void) strcpy(buf, argv[1]); } else if (argc > 3) for (n = atoi(argv[3]); n > 0; n--) { (void) strcpy(buf, argv[1]); (void) split(buf, fields, MNF, argv[2]); } else if (argc > 2) dosplit(argv[1], argv[2]); else if (argc > 1) while (fgets(buf, sizeof(buf), stdin) != NULL) { buf[strlen(buf)-1] = '\0'; /* stomp newline */ dosplit(buf, argv[1]); } else regress(); exit(0); }
int main(int argc, char **argv) { struct stat statbuf; char fontbuf[4096]; int fd; char *p, *q; int from, to; if (argc != 3) { fprintf(stderr, "call: splitfont fontfile 17,23-30,...\n"); exit(1); } if (stat(argv[1], &statbuf)) { perror("splitfont"); fprintf(stderr, "cannot stat fontfile %s", argv[1]); exit(1); } if (statbuf.st_size > 4096) { fprintf(stderr, "splitfont: file unexpectedly large\n"); exit(1); } if (statbuf.st_size % 256) { fprintf(stderr, "splitfont: file size not a multiple of 256\n"); exit(1); } if ((fd = open(argv[1], O_RDONLY)) < 0) { perror("splitfont"); fprintf(stderr, "cannot open fontfile %s", argv[1]); exit(1); } if (read(fd, fontbuf, statbuf.st_size) != statbuf.st_size) { perror("splitfont"); fprintf(stderr, "error reading fontfile %s", argv[1]); exit(1); } p = argv[2]; while (1) { to = from = strtoul(p, &q, 0); if (*q == '-') { p = q + 1; to = strtoul(p, &q, 0); } if (*q && *q != ',') { fprintf(stderr, "splitfont: garbage in %s\n", p); exit(1); } dosplit(from, to, fontbuf, statbuf.st_size, argv[1]); if (!*q) break; p = q + 1; } return 0; }
int main(int argc, char **argv) { params.debug = 0; params.writing = 1; params.winsize = 31; params.minsize = 4096; params.modulus = 10*1024*1024; { int opt; while((opt = getopt(argc, argv, "hm:no:vw:z:")) != -1) { switch(opt) { case 'h': help(); break; case 'm': params.minsize = safe_strtoul(optarg, "minsize"); break; case 'n': params.writing = 0; break; case 'o': params.outpfx = optarg; break; case 'v': params.debug++; break; case 'w': params.winsize = safe_strtoul(optarg, "window size"); break; case 'z': params.modulus = safe_strtoul(optarg, "modulus"); break; default: fprintf(stderr, "Unrecognized option: '%c'\n", opt); help(); break; } } } { int bsize = params.winsize * sizeof(*ss.wind_head); ss.wind_head = alloca(bsize); ss.wind_end = ss.wind_head + params.winsize; ss.wind_cur = ss.wind_head; ss.wind_sum = 0; for (int i = 0; i < params.winsize; i++) { ss.wind_head[i] = 0; } ss.chunkcount = 0; ss.chunksize = 0; ss.totalsize = 0; ss.outfile = NULL; } build_shiftout(params.shiftout); dosplit(); // Get the party started int ci; while((ci = fgetc(stdin)) >= 0) { procbyte((uint8_t) ci); } }
void procbyte(uint8_t in) { ss.chunksize++; ss.totalsize++; ss.wind_sum *= mulprime; ss.wind_sum += in + win_data_offset; ss.wind_sum -= *ss.wind_cur; ss.wind_sum %= params.modulus; *ss.wind_cur = params.shiftout[in]; if(++ss.wind_cur == ss.wind_end) { ss.wind_cur = ss.wind_head; } if(ss.outfile) { fputc(in,ss.outfile); } if((ss.wind_sum == params.modulus - 1) && ss.chunksize >= params.minsize) { dosplit(); } }
static int ftpparse_int(struct ftpparse *fp,char *buf,int len) { unsigned int count; char *p[MAXWORDS]; int l[MAXWORDS] = { 0,0,0,0,0,0,0,0,0,0 }; SETUP(); if (len < 2) /* an empty name in EPLF, with no info, could be 2 chars */ return 0; /* cheap cases first */ switch (*buf) { case '+': if (parse_eplf(fp,buf,len)) return 1; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (parse_msdos(fp,buf,len)) return 1; break; } count=dosplit(buf, len, p,l); switch(*buf) { case 'b': case 'c': case 'd': case 'l': case 'p': case 's': case '-': if (parse_unix(fp,buf,len,p,l,count)) return 1; break; } if (*buf==' ') { switch(p[0][0]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (parse_os2(fp,p,l,count)) return 1; break; } } if (parse_multinet(fp,p,l,count)) return 1; if (parse_supertcp(fp,p,l,count)) return 1; return 0; }