void backtr(sudoku *S) { sudoku T; int r=0, c=0, i, j, k; printf("<back>"); if (found > 1 || intell(S)) return; if (S->left == 0) { found++; return; } sstat(S); makecand(S); k = -1; for (i = 1; i <= 9; i++) for (j = 1; j <= 9; j++) if (S->a[i][j] == 0 && (k < 0 || nbits[S->c[i][j]] < k)) k = nbits[S->c[r=i][c=j]]; if (k < 0) return; for (k = 1; k <= 9; k++) { if ((S->c[r][c] & (1 << k)) == 0) continue; memcpy(T.a, S->a, sizeof(S->a)); T.c[r][c] = k; backtr(&T); if (found > 1) break; } }
int intell(sudoku *S) { static sudoku_stat st; int k, r, c, u; do { sstat(&st, S); if (st->left == 0) break; makecand(&st, S); /*printf("board:\n"); for(r=1;r<=9;r++){for(c=1;c<=9;c++)printf("%d",S->a[r][c]);printf("\n");} printf("cand:\n"); for(r=1;r<=9;r++){for(c=1;c<=9;c++){ for(k=1;k<=9;k++) if (S->c[r][c] & (1 << k)) printf("%d",k); else printf("."); printf(" "); }printf("\n");} */ u = 0; for (r = 1; r <= 9; r++) { for (c = 1; c <= 9; c++) { if (S->a[r][c] != 0) continue; if (st.c[r][c] == 0) return 1; if (nbits[st.c[r][c]] != 1) continue; S->a[r][c] = sbit[st.c[r][c]]; u++; } } /*printf("[u=%d]", u);*/ } while (u); return 0; }
void srv(Srv *srv) { Req *r; fmtinstall('D', dirfmt); fmtinstall('F', fcallfmt); if(srv->fpool == nil) srv->fpool = allocfidpool(srv->destroyfid); if(srv->rpool == nil) srv->rpool = allocreqpool(srv->destroyreq); if(srv->msize == 0) srv->msize = 8192+IOHDRSZ; changemsize(srv, srv->msize); srv->fpool->srv = srv; srv->rpool->srv = srv; while(r = getreq(srv)){ if(r->error){ respond(r, r->error); continue; } switch(r->ifcall.type){ default: respond(r, "unknown message"); break; case Tversion: sversion(srv, r); break; case Tauth: sauth(srv, r); break; case Tattach: sattach(srv, r); break; case Tflush: sflush(srv, r); break; case Twalk: swalk(srv, r); break; case Topen: sopen(srv, r); break; case Tcreate: screate(srv, r); break; case Tread: sread(srv, r); break; case Twrite: swrite(srv, r); break; case Tclunk: sclunk(srv, r); break; case Tremove: sremove(srv, r); break; case Tstat: sstat(srv, r); break; case Twstat: swstat(srv, r); break; } } free(srv->rbuf); srv->rbuf = nil; free(srv->wbuf); srv->wbuf = nil; srv->msize = 0; freefidpool(srv->fpool); srv->fpool = nil; freereqpool(srv->rpool); srv->rpool = nil; if(srv->end) srv->end(srv); }
int main(int argc, char *argv[]) { int port; char* file_img; int rfd; //Get the arguments get_args(&port, &file_img, argc, argv); int sd = UDP_Open(port); //Creates a new socket and binds to a port to it assert(sd > -1); //Open the file image, if not present call file_create routine disk_fd = open(file_img, O_RDWR); if(disk_fd == -1) { #ifdef DEBUG printf("File image doesn't exist - Creating a new one\n"); #endif rfd = create_img(file_img); if(rfd == -1) { #ifdef DEBUG printf("Error Creating the file - Exiting\n"); #endif return -1; } //disk_fd = rfd; } #ifdef DEBUG printf("File descriptor open: %d\n", disk_fd); #endif //close(ofd); /* CR_t* cr; lseek(ofd, 0, SEEK_SET); int br = read(ofd, (void*)cr, 4); printf("BR: %d\n", br); printf("Log end: %d\n", cr->log_end); printf("Imap_0 addr: %d\n", cr->imap_p[0]); */ printf(" SERVER:: waiting in loop\n"); Stat_t* m =(Stat_t*) malloc(sizeof(Stat_t)); sstat(10, m); printf("file->size=%d\n File->type=%d\n", m->size, m->type); while (1) { struct sockaddr_in s; char buffer[BUFFER_SIZE]; int rc = UDP_Read(sd, &s, buffer, BUFFER_SIZE); if (rc > 0) { printf(" SERVER:: read %d bytes (message: '%s')\n", rc, buffer); char reply[BUFFER_SIZE]; sprintf(reply, "reply"); rc = UDP_Write(sd, &s, reply, BUFFER_SIZE); } } return 0; }
void print_results(int fflag) { long QTP, QFN, QFP, STP, SFN, SFP, VTP, VFN, VTN, VFP; /* Open output files. If line-format output was selected, write column headings only if the files must be created from scratch. */ if (strcmp(ofname, "-")) { if ((ofile = fopen(ofname, "r")) == NULL) { if ((ofile = fopen(ofname, "w")) == NULL) { (void)fprintf(stderr, "%s: can't create %s\n", pname, ofname); exit(0); } if (fflag == 2) { (void)fprintf(ofile, "Record Nn' Vn' Fn' On' Nv Vv Fv' Ov' No'"); (void)fprintf(ofile, " Vo' Fo' Q Se Q +P V Se V +P V FPR\n"); } else if (fflag == 5) { (void)fprintf(ofile, "Record Nn' Sn' Vn' Fn' On' Ns Ss Vs Fs'"); (void)fprintf(ofile, " Os' Nv Sv Vv Fv' Ov' No' So' Vo' Fo'"); (void)fprintf(ofile, " Q Se Q +P V Se V +P S Se S +P RR err\n"); } } else { (void)fclose(ofile); if ((ofile = fopen(ofname, "a")) == NULL) { (void)fprintf(stderr, "%s: can't modify %s\n", pname, ofname); exit(0); } } } else ofile = stdout; if (fflag == 2 || fflag == 5) { if (strcmp(sfname, "-")) { if ((sfile = fopen(sfname, "r")) == NULL) { if ((sfile = fopen(sfname, "w")) == NULL) { (void)fprintf(stderr, "%s: can't create %s\n", pname, sfname); exit(0); } if (fflag == 2) { (void)fprintf(sfile, "Record Nx Vx Fx Qx %% beats %% N "); (void)fprintf(sfile, "%% V %% F Total Shutdown\n"); (void)fprintf(sfile, " missed missed "); (void)fprintf(sfile, "missed missed Time\n"); } else { (void)fprintf(sfile, "Record Nx Sx Vx Fx Qx %% beats %% N "); (void)fprintf(sfile, "%% S %% V %% F Total Shutdown\n"); (void)fprintf(sfile, " missed missed "); (void)fprintf(sfile, "missed missed missed Time\n"); } } else { (void)fclose(sfile); if ((sfile = fopen(sfname, "a")) == NULL) { (void)fprintf(stderr, "%s: can't modify %s\n", pname, sfname); exit(0); } } } else sfile = stdout; } else sfile = stdout; if (fflag == 1 || fflag == 3 || fflag == 4 || fflag == 6) { (void)fprintf(ofile, "Beat-by-beat comparison results for record %s\n", record); (void)fprintf(ofile, "Reference annotator: %s\n", an[0].name); (void)fprintf(ofile, " Test annotator: %s\n\n", an[1].name); } switch (fflag) { case 1: /* print condensed format summary tables */ (void)fprintf(ofile, " Algorithm\n"); (void)fprintf(ofile, " n+f+q v o+x\n"); (void)fprintf(ofile, " ________________\n"); (void)fprintf(ofile, " N | %4ld %4ld %4ld\n", Nn+Ns+Nf+Nq + Sn+Ss+Sf+Sq, Nv + Sv, No+Nx + So+Sx); (void)fprintf(ofile, " V | %4ld %4ld %4ld\n", Vn+Vs+Vf+Vq, Vv, Vo+Vx); (void)fprintf(ofile, " F+Q | %4ld %4ld %4ld\n", Fn+Fs+Ff+Fq + Qn+Qs+Qf+Qq, Fv + Qv, Fo+Fx + Qo+Qx); (void)fprintf(ofile, " O+X | %4ld %4ld\n\n", On+Os+Of+Oq + Xn+Xs+Xf+Xq, Ov+Xv); break; case 2: /* print line-format output */ (void)fprintf(ofile, "%4s %5ld %3ld %3ld %3ld %3ld %4ld %3ld %3ld %3ld %3ld %3ld", record, Nn+Ns+Nf+Nq + Sn+Ss+Sf+Sq, Vn+Vs+Vf+Vq, Fn+Fs+Ff+Fq + Qn+Qs+Qf+Qq, On+Os+Of+Oq + Xn+Xs+Xf+Xq, Nv+Sv, Vv, Fv+Qv, Ov+Xv, No+Nx+So+Sx, Vo+Vx, Fo+Fx+Qo+Qx); (void)fprintf(sfile, "%4s %4ld %4ld %4ld %4ld ", record, Nx+Sx, Vx, Fx, Qx); break; case 3: /* print standard format summary tables */ (void)fprintf(ofile, " Algorithm\n"); (void)fprintf(ofile, " n v f q o x\n"); (void)fprintf(ofile, " _______________________________\n"); (void)fprintf(ofile, " N | %4ld %4ld %4ld %4ld %4ld %4ld\n", Nn+Ns+Sn+Ss, Nv+Sv, Nf+Sf, Nq+Sq, No+So, Nx+Sx); (void)fprintf(ofile, " V | %4ld %4ld %4ld %4ld %4ld %4ld\n", Vn+Vs, Vv, Vf, Vq, Vo, Vx); (void)fprintf(ofile, " F | %4ld %4ld %4ld %4ld %4ld %4ld\n", Fn+Fs, Fv, Ff, Fq, Fo, Fx); (void)fprintf(ofile, " Q | %4ld %4ld %4ld %4ld %4ld %4ld\n", Qn+Qs, Qv, Qf, Qq, Qo, Qx); (void)fprintf(ofile, " O | %4ld %4ld %4ld %4ld\n", On+Os, Ov, Of, Oq); (void)fprintf(ofile, " X | %4ld %4ld %4ld %4ld\n\n", Xn+Xs, Xv, Xf, Xq); break; case 4: /* print condensed format summary tables, with SVEBs */ (void)fprintf(ofile, " Algorithm\n"); (void)fprintf(ofile, " n+f+q s v o+x\n"); (void)fprintf(ofile, " _____________________\n"); (void)fprintf(ofile, " N | %4ld %4ld %4ld %4ld\n", Nn+Nf+Nq, Ns, Nv, No+Nx); (void)fprintf(ofile, " S | %4ld %4ld %4ld %4ld\n", Sn+Sf+Sq, Ss, Sv, So+Sx); (void)fprintf(ofile, " V | %4ld %4ld %4ld %4ld\n", Vn+Vf+Vq, Vs, Vv, Vo+Vx); (void)fprintf(ofile, " F+Q | %4ld %4ld %4ld %4ld\n", Fn+Ff+Fq+Qn+Qf+Qq, Fs+Qs, Fv+Qv, Fo+Fx+Qo+Qx); (void)fprintf(ofile, " O+X | %4ld %4ld %4ld\n\n", On+Of+Oq+Xn+Xf+Xq, Os+Xs, Ov+Xv); break; case 5: /* print line-format output, with SVEBs */ (void)fprintf(ofile, "%4s %5ld %3ld %3ld %3ld %3ld %3ld %3ld %3ld %3ld %3ld", record, Nn+Nf+Nq, Sn+Sf+Sq, Vn+Vf+Vq, Fn+Ff+Fq + Qn+Qf+Qq, On+Of+Oq + Xn+Xf+Xq, Ns, Ss, Vs, Fs+Qs, Os+Xs); (void)fprintf(ofile, " %3ld %3ld %4ld %3ld %3ld %3ld %3ld %3ld %3ld", Nv, Sv, Vv, Fv+Qv, Ov+Xv, No+Nx, So+Sx, Vo+Vx, Fo+Fx+Qo+Qx); (void)fprintf(sfile, "%4s %4ld %4ld %4ld %4ld %4ld ", record, Nx, Sx, Vx, Fx, Qx); break; case 6: /* print standard format summary tables, with SVEBs */ default: (void)fprintf(ofile, " Algorithm\n"); (void)fprintf(ofile, " n s v f q o x\n"); (void)fprintf(ofile, " ____________________________________\n"); (void)fprintf(ofile, " N | %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n", Nn, Ns, Nv, Nf, Nq, No, Nx); (void)fprintf(ofile, " S | %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n", Sn, Ss, Sv, Sf, Sq, So, Sx); (void)fprintf(ofile, " V | %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n", Vn, Vs, Vv, Vf, Vq, Vo, Vx); (void)fprintf(ofile, " F | %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n", Fn, Fs, Fv, Ff, Fq, Fo, Fx); (void)fprintf(ofile, " Q | %4ld %4ld %4ld %4ld %4ld %4ld %4ld\n", Qn, Qs, Qv, Qf, Qq, Qo, Qx); (void)fprintf(ofile, " O | %4ld %4ld %4ld %4ld %4ld\n", On, Os, Ov, Of, Oq); (void)fprintf(ofile, " X | %4ld %4ld %4ld %4ld %4ld\n\n", Xn, Xs, Xv, Xf, Xq); break; } QTP = Nn+Ns+Nv+Nf+Nq + Sn+Ss+Sv+Sf+Sq + Vn+Vs+Vv+Vf+Vq + Fn+Fs+Fv+Ff+Fq + Qn+Qs+Qv+Qf+Qq; QFN = No+Nx + So+Sx + Vo+Vx + Fo+Fx + Qo+Qx; QFP = On+Os+Ov+Of+Oq + Xn+Xs+Xv+Xf+Xq; VTP = Vv; VFN = Vn + Vs + Vf + Vq + Vo + Vx; VTN = Nn+Ns+Nf+Nq + Sn+Ss+Sf+Sq + Fn+Fs+Ff+Fq + Qn+Qs+Qf+Qq + On+Os+Of+Oq + Xn+Xs+Xf+Xq; VFP = Nv + Sv + Ov + Xv; STP = Ss; SFN = Sn + Sv + Sf + Sq + So + Sx; SFP = Ns + Vs + Fs + Os + Xs; pstat(" QRS sensitivity", "%6.2f", QTP, QTP + QFN); pstat(" QRS positive predictivity", "%6.2f", QTP, QTP + QFP); pstat(" VEB sensitivity", "%6.2f", VTP, VTP + VFN); pstat(" VEB positive predictivity", "%6.2f", VTP, VTP + VFP); if (fflag < 4) pstat(" VEB false positive rate", "%6.3f", VFP, VTN + VFP); else { pstat(" SVEB sensitivity", "%6.2f", STP, STP + SFN); pstat("SVEB positive predictivity", "%6.2f", STP, STP + SFP); } if (fflag == 4 || fflag == 6) { (void)fprintf(ofile, " RMS RR interval error: "); if (nrre) (void)fprintf(ofile, "%6.2f ms", sqrt(ssrre/nrre)*1000./strtim("1")); else (void)fprintf(ofile, " -"); } else if (fflag == 5) { if (nrre) (void)fprintf(ofile, " %6.2f", sqrt(ssrre/nrre)*1000./strtim("1")); else (void)fprintf(ofile, " -"); } (void)fprintf(ofile, "\n"); sstat("\n Beats missed in shutdown", "%6.2f", Nx+Vx+Fx+Qx, QTP + QFN); sstat(" N missed in shutdown", "%6.2f", Nx, Nn+Ns+Nv+Nf+Nq+No+Nx); if (fflag >= 4) sstat(" S missed in shutdown", "%6.2f", Sx, Sn+Ss+Sv+Sf+Sq+So+Sx); sstat(" V missed in shutdown", "%6.2f", Vx, Vn+Vs+Vv+Vf+Vq+Vo+Vx); sstat(" F missed in shutdown", "%6.2f", Fx, Fn+Fs+Fv+Ff+Fq+Fo+Fx); if (fflag == 1 || fflag == 3 || fflag == 4 || fflag == 6) (void)fprintf(sfile, " Total shutdown time: "); (void)fprintf(sfile, "%5ld seconds\n", shut_down); if(ofile != NULL) fclose(ofile) ; }