static void genkeys(void) { long seedspace[numprocs]; int i; /* Create the file. */ docreate(PATH_KEYS); /* Generate random seeds for each subprocess. */ srandom(randomseed); for (i=0; i<numprocs; i++) { seedspace[i] = random(); } /* Do it. */ seeds = seedspace; doforkall("Initialization", genkeys_sub); seeds = NULL; /* Cross-check the size of the output. */ if (getsize(PATH_KEYS) != correctsize) { complainx("%s: file is wrong size", PATH_KEYS); exit(1); } /* Checksum the output. */ checksum = checksum_file(PATH_KEYS); complainx("Checksum of unsorted keys: %ld", checksum); }
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; }
static void sort(void) { unsigned long sortedsum; int i, j; /* Step 1. Toss into bins. */ doforkall("Tossing", bin); checksize_bins(); complainx("Done tossing into bins."); /* Step 2: Sort the bins. */ doforkall("Sorting", sortbins); checksize_bins(); complainx("Done sorting the bins."); /* Step 3: Merge corresponding bins. */ doforkall("Merging", mergebins); checksize_merge(); complainx("Done merging the bins."); /* Step 3a: delete the bins */ for (i=0; i<numprocs; i++) { for (j=0; j<numprocs; j++) { doremove(binname(i, j)); } } /* Step 4: assemble output file */ docreate(PATH_SORTED); doforkall("Final assembly", assemble); if (getsize(PATH_SORTED) != correctsize) { complainx("%s: file is wrong size", PATH_SORTED); exit(1); } /* Step 4a: delete the merged bins */ for (i=0; i<numprocs; i++) { doremove(mergedname(i)); } /* Step 5: Checksum the result. */ sortedsum = checksum_file(PATH_SORTED); complainx("Checksum of sorted keys: %ld", sortedsum); if (sortedsum != checksum) { complainx("Sums do not match"); exit(1); } }
/*this is the main routine*/ void doshell() { char line[80]; /*run forever - the shell shouldn't end*/ while(1==1) { /*read in a line*/ printstring("SHELL>\0"); readstring(line); /*match it against each possible command*/ /*if the user presses return, ignore it*/ if (line[0]==0xd) continue; else if (iscommand(line,"CLS\0")==1) doclear(); else if (iscommand(line,"cls\0")==1) doclear(); else if (iscommand(line,"COPY\0")==1) docopy(); else if (iscommand(line,"copy\0")==1) docopy(); else if (iscommand(line,"CREATE \0")==1) docreate(line); else if (iscommand(line,"create \0")==1) docreate(line); else if (iscommand(line,"DELETE \0")==1) dodelete(line); else if (iscommand(line,"delete \0")==1) dodelete(line); else if (iscommand(line,"DIR\0")==1) dodir(); else if (iscommand(line,"dir\0")==1) dodir(); else if (iscommand(line,"EXEC \0")==1) doexecute(line,1); else if (iscommand(line,"exec \0")==1) doexecute(line,1); else if (iscommand(line,"EXECBACK \0")==1) doexecute(line,0); else if (iscommand(line,"execback \0")==1) doexecute(line,0); else if (iscommand(line,"HELP\0")==1) dohelp(); else if (iscommand(line,"help\0")==1) dohelp(); else if (line[0]=='?') dohelp(); else if (iscommand(line,"TYPE \0")==1) dotype(line); else if (iscommand(line,"type \0")==1) dotype(line); else if (iscommand(line,"KILL \0")==1) dokill(line); else if (iscommand(line,"kill \0")==1) dokill(line); else if (iscommand(line,"mkdir \0")==1) domkdir(line); else if (iscommand(line,"MKDIR\0")==1) domkdir(line); else if (iscommand(line,"FORMAT\0")==1) doFormat(); else if (iscommand(line,"format\0")==1) doFormat(); else if (iscommand(line,"remove\0")==1) doRemove(line); else if (iscommand(line,"REMOVE\0")==1) doRemove(line); else if (iscommand(line,"list\0")==1) doList(); else if (iscommand(line,"LIST\0")==1) doList(); else if (iscommand(line,"count\0")==1) doCount(line); else if (iscommand(line,"WRITE\0")==1) doCreateFile(line); else if (iscommand(line,"write\0")==1) doCreateFile(line); else if (iscommand(line,"READ\0")==1) doEcho(line); else if (iscommand(line,"read\0")==1) doEcho(line); else printstring("Command not found\r\n\0"); printstring("\r\n\0"); } }