int main(int argc, char *argv[]) { const char *command; int doforce = 0; int ch; int i; if (argc < 2) { usage(); } command = argv[1]; argv++; argc--; while ((ch = getopt(argc, argv, "f"))!=-1) { switch (ch) { case 'f': doforce = 1; break; default: usage(); } } if (!strcmp(command, "create")) { if (optind + 2 != argc) { usage(); } docreate(argv[optind], argv[optind+1], doforce); } else if (!strcmp(command, "info") || !strcmp(command, "stat") || !strcmp(command, "stats") || !strcmp(command, "status")) { if (doforce) { usage(); } for (i=optind; i<argc; i++) { doinfo(argv[i]); } } else if (!strcmp(command, "resize") || !strcmp(command, "setsize")) { if (optind + 2 != argc) { usage(); } if (doforce) { usage(); } doresize(argv[optind], argv[optind+1]); } else if (!strcmp(command, "help")) { usage(); } else { fprintf(stderr, "disk161: Unknown command %s\n", command); usage(); } return 0; }
/* list list 10-50 list -50 list 10- list 10 */ void dolist(bc *bc, char *text) { char aline[1024]; char *p; int i; int min, max; int v1, v2; int wantinfo=1; min=0; max=0x7fffffff; if(sscanf(text, "%d-%d", &v1, &v2) == 2) { min=v1; max=v2; wantinfo=0; } else if(*text=='-' && text[1]>='0' && text[1]<='9') { max=atoi(text+1); wantinfo=0; } else if(sscanf(text, "%d", &v1) == 1) { min=v1; while(*text>='0' && *text<='9') ++text; if(*text != '-') max=v1; wantinfo=0; } if(wantinfo) doinfo(bc,""); p=bc->program; while(*p) { i=0; while(*p) { aline[i] = *p; if(i<sizeof(aline)-1) ++i; if(*p++ == '\n') break; } aline[i]=0; i=atoi(aline); if(min<=i && i<=max) tprintf(bc, "%s", aline); } }