void commitall() { char sys[NAMESIZE+5]; char cmfile[NAMESIZE+5]; int i; int n; for (i = 0; i < ncsave; i++) { if (Sgrades) { if ((job_size(&csave[i]) == FAIL) || (fgrade(&csave[i]) == FAIL)) { wfremove(csave[i].file); continue; } } else { Dfileused = TRUE; csave[i].grade = Grade; } /* make new file name for for the job */ if (Sgrades) { n = retseq(csave[i].sys); (void) sprintf(cmfile, "%c.%.*s%c%.4x", *csave[i].file, SYSNSIZE, csave[i].sys, csave[i].grade, n); } else (void) strncpy(cmfile, csave[i].file, NAMESIZE-1); cmfile[NAMESIZE-1] = '\0'; DEBUG(9, "User job queued to %c queue\n", csave[i].grade); (void) sprintf(sys, "/%c", csave[i].grade); (void) strcat(csave[i].sys, sys); if (Dfileused) { putdfiles(csave[i]); Dfileused = FALSE; } wfcommit(csave[i].file, cmfile, csave[i].sys); (void) strncpy(csave[i].file, cmfile, NAMESIZE); } ncsave = 0; /* set real jobid */ (void) strncpy(jobid, BASENAME(csave[0].file, '.'), NAMESIZE); return; }
void prcsreq(int fd) { struct student s; struct course c; struct grade g; int from = -1, to = -1; if ( REQUEST("ADD STUDENT %d %s", &s.index, s.name) == 2 ) { astud(s); sprintf(buff, "OK\n"); } else if ( REQUEST("ADD COURSE %d %s", &c.id, c.name) == 2 ) { acourse(c); sprintf(buff, "OK\n"); } else if ( REQUEST("ADD GRADE %d %d %d", &g.index, &g.id, &g.value) == 3 ) { agrade(g); sprintf(buff, "OK\n"); } else if ( REQUEST("FIND %d %d", &g.index, &g.id) == 2 ) { int grade = fgrade(g); if (grade > 0) { sprintf(buff, "GRADE %d\n", grade); } else { sprintf(buff, "NONE\n"); } } else if ( REQUEST("MATCH OFFSET %s %s %d %d", s.name, c.name, &from, &to) ) { foffset(s.name, c.name, fd, from, to); } else if ( REQUEST("MATCH %s %s", s.name, c.name) == 2 ) { int grade = fgnames(s.name, c.name); if (grade > 0) { sprintf(buff, "GRADE %d\n", grade); } else { sprintf(buff, "NONE\n"); } } else if ( REQUEST("MODIFY %d %d %d", &g.index, &g.id, &g.value) == 3 ) { mgrade(g); sprintf(buff, "OK\n"); } else if ( REQUEST("REMOVE %d %d", &g.index, &g.id) ) { rgrade(g); sprintf(buff, "OK\n"); } else { printf("Invalid request.\n"); } /* Send reply for request. */ if (from == -1 && to == -1) { write(fd, buff, strlen(buff)); } }