int main(int argn, char **argv) { char buf[1024], sec[100], qry[100], manfile[100]; int retv; strsncpy(buf, getsenv("QUERY_STRING"), sizeof (buf)); if (strchr(buf, '&')) retv = getformarg(buf, sec, qry, 100); else if (strchr(buf, '+')) retv = geturlarg(buf, sec, qry, 100); else retv = -1; if (!retv) retv = testarg(sec, qry); if (!retv) { retv = getmanfile(sec, qry, manfile, sizeof (manfile)); if (retv) { printheader(); printf ("找不到与<font color=red>%s</font>相关的文档<br><br>\n", nohtml(qry)); } } if (retv) { printheader(); printsection(); printform(); return 0; } runman2html(manfile); return 0; }
int gibbsandMHloop(int iter,int thin,gsl_rng *RNG,struct_data *D,struct_para *D_para,struct_priors *D_priors ,struct_MH *D_MH,int print){ int i,j,l,c,ll; /* print=3;*/ if (print==0){printheader(D);} for (i=0;i<iter;i++){ for (j=0;j<thin;j++){ /* printf("%g\n",D_para->sigma_Z);*/ /* printf("%g %g %g\n",D_para->delta_l[2412],D_para->delta_l[3593],D_para->delta_l[4211]);*/ D_para->alpha_c[1]=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_nu,&D_MH->halpha_c,D_para->alpha_c[1],MCMC_alpha_c,-999,-999,-999); D_para->sigma_gamma=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hsigma_gamma,D_para->sigma_gamma,MCMC_sigma_gamma,-999,-999,-999); D_para->sigma_nu=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hsigma_nu,D_para->sigma_nu,MCMC_sigma_nu,-999,-999,-999); D_para->Z_p=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hZ_l,D_para->Z_p,MCMC_Z_p,-999,-999,-999); D_para->sigma_Z=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hsigma_Z,D_para->sigma_Z,MCMC_sigma_Z,-999,-999,-999); D_para->nu_p=gauss_sample(RNG,D,0,2*D->L,D_para->nu_l,exp(D_para->sigma_nu),D_priors->nu_mu,D_priors->eta_nu_p); for (l=0;l<D->L;l++){ D_para->delta_l[l]=aug_delta_l(RNG,D,D_para,D_priors,l); D_para->gamma_cl[l]=MCMC_base_truncate_low(0,RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hgamma_cl,exp(D_para->gamma_cl[l]),MCMC_gamma_cl,-999,l,-999); D_para->gamma_cl[l]=log( D_para->gamma_cl[l]); D_para->Z_l[l]=MCMC_base_truncate_low(0,RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hZ_l,exp(D_para->Z_l[l]),MCMC_Z_l,-999,l,-999); D_para->Z_l[l]=log( D_para->Z_l[l]); for (c=0;c<2;c++){ ll=c*D->L+l; D_para->nu_l[ll]=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_Z,&D_MH->hnu_l,D_para->nu_l[ll],MCMC_nu_l,c,l,-999); } } } if (print==1){printdata(D,D_para,D_MH);} } return 0; }
void close_pat(FILE *fp) { patient p; char yn = 'Y', err[32]; int reg, flag = 0, op, n; FILE *tmp; while(yn == 'Y' || yn == 'y') { system("clear"); printheader(); flag = 0; rewind(fp); tmp = fopen("temporary.txt", "wb+"); w:printf("\n1]Close record\t 2]Return\n"); n = scanf("%d", &op); if(n == 0) { op = 7; readline(err, 32); } if(op == 1) { printf("\n\nEnter Registration number:"); } else if(op == 2) { system("clear"); fclose(fp); pat_info(fp); } else { printf("\n\t***Invalid entry***\n"); goto w; } scanf("%d", ®); while(fread(&p, SIZE, 1, fp) == 1) { if(p.regn != reg) { fseek(tmp, 0, SEEK_END); fwrite(&p, SIZE, 1, tmp); } else flag = 1; } if(flag == 1) { fclose(tmp); fclose(fp); fp = fopen("patient.txt", "wb+"); tmp = fopen("temporary.txt", "rb+"); while(fread(&p, SIZE, 1, tmp) == 1) { fseek(fp, 0, SEEK_END); fwrite(&p, SIZE, 1, fp); } fclose(tmp); fclose(fp); fp = fopen("patient.txt", "rb+"); printf("\n\t\t\t***Successfully closed***\n\n"); } else printf("\t Registration number does not exis\n"); printf("\nDo you want to close any other record(Y/N):\n"); scanf(" %c", &yn); } }
/* dump out a Paragraph in the desired manner */ static Paragraph* display(Paragraph *p, MMIOT *f) { if ( !p ) return 0; switch ( p->typ ) { case STYLE: case WHITESPACE: break; case HTML: printhtml(p->text, f); break; case CODE: printcode(p->text, f); break; case QUOTE: htmlify(p->down, p->ident ? "div" : "blockquote", p->ident, f); break; case UL: case OL: case AL: listdisplay(p->typ, p->down, f); break; #if DL_TAG_EXTENSION case DL: definitionlist(p->down, f); break; #endif case HR: Qstring("<hr />", f); break; case HDR: printheader(p, f); break; case TABLE: printtable(p, f); break; case SOURCE: htmlify(p->down, 0, 0, f); break; default: printblock(p, f); break; } return p->next; }
int main() { system("clear"); system("clear"); printheader(); system("sleep 1"); printf("\n\n\t\t\t\t\t\t\t\t WELCOME\n"); system("sleep 1"); printf("\n\n\n\n\n\t\t\t\t\t\t\tHOSPITAL RECORD MANAGEMENT SYSTEM\n"); system("sleep 1"); printf("\n\n\n\n\n\t\t\t\t\t\t PRACHI PATEL SUMIT SATHE MAYUR MARATHE\n"); system("sleep 2"); system("clear"); printheader(); printmainmenu(); }
int main(int argc, char **argv) { int itmin; /* smallest sample (zero-based) to plot */ int itmax; /* largest sample (zero-based) to plot */ int nt; /* number of samples */ int count; /* number of traces to plot */ register int itr; /* trace counter */ cwp_Bool plotall; /* plot all the traces */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Set number of traces to plot */ plotall = cwp_false; if (!getparint("count", &count)) plotall = cwp_true; /* Loop over traces */ for (itr = 0; (plotall || itr < count) && gettr(&tr); itr++) { nt = (int) tr.ns; /* Cast from unsigned */ if (itr == 0) { /* Awkward to do a gettr outside loop */ if (!getparint("itmin", &itmin)) itmin = 0; if (!getparint("itmax", &itmax)) itmax = nt - 1; if (itmin >= nt - 1 || itmin < 0) { err("itmin=%d, require 0 < itmin < %d", itmin, nt - 1); } if (itmax >= nt) { itmax = nt - 1; } if (itmax < 0) { err("itmax=%d, require itmax > 0", itmax); } if (itmin > itmax) { itmin = itmax; } } printheader(&tr); tabplot(&tr, itmin, itmax); } return(CWP_Exit()); }
/*查询火车信息*/ void searchtrain(Link l) { Node *s[10],*r; int sel,k,i=0 ; char str1[5],str2[10]; if(!l->next) { printf("There is not any record !"); return ; } printf("Choose the way:\n1:according to the number of train;\n2:according to the city:\n"); scanf("%d",&sel);/*输入选择的序号*/ if(sel==1) { printf("Input the the number of train:"); scanf("%s",str1); r=l->next; while(r!=NULL) if(strcmp(r->data.num,str1)==0)/*检索是否有与输入的车号相匹配的*/ { s[i]=r; i++; break; } else r=r->next; } else if(sel==2) { printf("Input the city you want to go:"); scanf("%s",str2); r=l->next; while(r!=NULL) if(strcmp(r->data.reachcity,str2)==0)/*检索是否有与输入的城市相匹配的火车*/ { s[i]=r; i++; r=r->next; } else r=r->next; } if(i==0) printf("can not find!"); else { printheader(); for(k=0;k<i;k++) printdata(s[k]); } }
void showtrain(Link l)/*自定义函数显示列车信息*/ { Node *p; p=l->next; printheader(); if(l->next==NULL) printf("no records!"); else while(p!=NULL) { printdata(p); p=p->next; } }
int main (int argc, char *argv[]) { int rt; rt = _i18n_init (I18N_CAT_MIN); setdefaults (); getoptions (argc, argv); getpids (argc, argv); printheader (); initstats (); processlogfile (); printsummary (); _i18n_end (ls_catd); return (0); }
int dumpat(int y,long startdate, int loc, int num) { static int vh,ap,day,i; static byte putheader; vh=viewheaders && !repeatchooser; ap= -vh; day=0; putheader=!repeatchooser && mainheader; i=putheader; if(!found && !repeatchooser) { printheader(y+0,startdate); if(propfont) #ifndef ITALIAN ozputs(0,y+PROP_FONT_HEIGHT,"No appointments found."); #else /* ITALIAN */ ozputs(0,y+PROP_FONT_HEIGHT,"Non trovo appuntamenti."); #endif /* ITALIAN */ else
int pat_info() { FILE *fp; fp = fopen("patient.txt", "rb+"); if(fp == NULL) { perror(" file cannot be accessed:"); return errno; } int op, n; char err[32]; while(1) { printpatmenu(); b:printf("\n\n\n\tEnter the option number:"); n = scanf("%d", &op); if(n == 0) { op = 7; readline(err, 32); } switch(op) { case 1:system("clear"); printheader(); new_pat(fp); break; case 2:system("clear"); printheader(); edit_pat(fp); break; case 3:system("clear"); printheader(); search_pat(fp); break; case 4:system("clear"); printheader(); list_pat(fp); break; case 5:system("clear"); printheader(); close_pat(fp); break; case 6:system("clear"); fclose(fp); printheader(); printmainmenu(); break; default:printf("\n\n\t***Invalid entry***"); goto b; break; } } return 0; }
/* * List a directory. */ static void listdir(const char *path, int showheader) { int fd; char buf[1024]; char newpath[1024]; int len; if (showheader) { printheader(path); } /* * Open it. */ fd = open(path, O_RDONLY); if (fd<0) { err(1, "%s", path); } /* * List the directory. */ while ((len = getdirentry(fd, buf, sizeof(buf)-1)) > 0) { buf[len] = 0; /* Assemble the full name of the new item */ snprintf(newpath, sizeof(newpath), "%s/%s", path, buf); if (aopt || buf[0]!='.') { /* Print it */ print(newpath); } } if (len<0) { err(1, "%s: getdirentry", path); } /* Done */ close(fd); }
int main(int argc, char *argv[]){ extern char *progname; extern char *filename; FILE *fp; id3v2header *header; id3v2frame *frame; progname = argv[0]; filename = argv[1]; if(argc != 2){ printf("Usage: %s filename\n", progname); exit(EXIT_FAILURE); } if((fp = fopen(filename, "r")) == NULL){ perror(progname); exit(EXIT_FAILURE); } if((header = getheader(fp)) == NULL){ fprintf(stderr, "%s error: not a valid MP3 file.\n", progname); exit(EXIT_FAILURE); } printheader(header); while(((frame = getframe(fp)) != NULL) && frame->body != NULL){ printframe(frame, 1); free(frame->body); frame->body = NULL; } (void) fclose(fp); return 0; }
//main function // This function collects mismatch, InDel and GC contens // from sam files int main(int argc, char *argv[]) { if (argc != 2) { string programname = argv[0]; usage(programname); exit(EXIT_FAILURE); } printheader(); if (strcmp(argv[1],"-") == 0) { cerr << "Taking file from stdin!" << endl; processStdin(); } else { cerr << "Taking file from file: "<< argv[1] << "..." << endl; const char *filename = argv[1]; processFile(filename); } return 0; }
/*订票子模块*/ void Bookticket(Link l,bookLink k) { Node *r[10],*p ; char ch[2],tnum[10],str[10],str1[10],str2[10]; book *q,*h ; int i=0,t=0,flag=0,dnum; q=k ; while(q->next!=NULL) q=q->next ; printf("Input the city you want to go: "); scanf("%s",&str);/*输入要到达的城市*/ p=l->next ; while(p!=NULL) { if(strcmp(p->data.reachcity,str)==0) { r[i]=p ;/*将满足条件的记录存到数组r中*/ i++; } p=p->next ; } printf("\n\nthe number of record have %d\n",i); printheader(); for(t=0;t<i;t++) printdata(r[t]); if(i==0) printf("\nSorry!Can't find the train for you!\n"); else { printf("\ndo you want to book it?<y/n>\n"); scanf("%s",ch); if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判断是否订票*/ { h=(book*)malloc(sizeof(book)); printf("Input your name: "); scanf("%s",&str1); strcpy(h->data.name,str1); printf("Input your id: "); scanf("%s",&str2); strcpy(h->data.num,str2); printf("please input the number of the train:"); scanf("%s",tnum); for(t=0;t<i;t++) if(strcmp(r[t]->data.num,tnum)==0) { if(r[t]->data.ticketnum<1)/*判断剩余的供订票的票数是否为0*/ { printf("sorry,no ticket!"); sleep(2); return; } printf("remain %d tickets\n",r[t]->data.ticketnum); flag=1; break; } if(flag==0) { printf("input error"); sleep(2); return; } printf("Input your bookNum: "); scanf("%d",&dnum); r[t]->data.ticketnum=r[t]->data.ticketnum-dnum;/*定票成功则可供订的票数相应减少*/ h->data.bookNum=dnum ; h->next=NULL ; q->next=h ; q=h ; printf("\nLucky!you have booked a ticket!"); getch(); saveflag=1 ; } } }
int main(int argc, char* argv[]) { const int MAX_LINE_LENGTH = 999999; char tmpbuf[MAX_LINE_LENGTH]; char brch_name[MAX_LINE_LENGTH], frm_name[MAX_LINE_LENGTH], to_name[MAX_LINE_LENGTH]; char *pt; int fnum, eid, up_id, dn_id, lnum, tp; double len, maf, zr, slope, lon, lat, Manning_n; int steady_flag = 0; // ***Revised by Cheng-Wei *** New variables int shape; double wid, SWS; // ***Revised by Cheng-Wei *** New vector for saving x and y coordinates vector<double> xData, yData; vector<double> AAData, PPData, YYData, WWData; //P (perimeter), y(depth) and w(free surface width) all depend on A; FILE *F; tgraph TG; NC runoff; if (argc<3) { printf("Usage: %s <NHD+ connectivity csv file> <netcdf file> [root name] -s(optional)\n", argv[0]); return (1); } if ((argc== 5) && (strcmp(argv[4],"-s") ==0)){ steady_flag= 1; } else if ((argc == 5) && (strcmp(argv[4],"-s") != 0)){ printf("[EE] Please use valid steady state flag -s \n"); printf("Usage: %s <NHD+ connectivity csv file> <netcdf file> [root name] -s(optional)\n", argv[0]); return (1); } //fprintf(stdout,"steady_flag is %i \n", steady_flag); F = fopen(argv[1],"r"); if (!F) { fprintf(stdout,"bummer: unable to open file \"%s\"\n", argv[1]); return (-1); } lnum = 0; while ( (fgets(tmpbuf, MAX_LINE_LENGTH, F)) != NULL ) { if ( tmpbuf[0] == COMMENT_TOKEN ) continue; pt = strtok(tmpbuf, TOKEN_DELIM); fnum = 0; //***Revised by Cheng-Wei*** New variable shape = -1; // ***Revised by Cheng-Wei*** Declare tp as interger tp = 1.0; len = -1.0; maf = -1.0; slope = -1.0; lon = -1.0; lat = -1.0; Manning_n = -1.0; // ***Revised by Cheng-Wei*** New variables SWS = side wall slope; wid = bottom width wid = 1.0; SWS = 1.0; xData.clear(); yData.clear(); AAData.clear(); PPData.clear(); YYData.clear(); WWData.clear(); while ( pt != NULL ) { if (fnum <= 11) { switch (fnum) { case 0: strncpy(brch_name, pt, MAX_LINE_LENGTH-1); // eid = TG.MakeEdge(pt); break; case 1: strncpy(frm_name, pt, MAX_LINE_LENGTH-1); // up_id = TG.MakeVertex(pt); break; case 2: strncpy(to_name, pt, MAX_LINE_LENGTH-1); // dn_id = TG.MakeVertex(pt); break; case 3: tp = atoi(pt); break; case 4: len = atof(pt); break; case 5: maf = atof(pt); break; case 6: slope = atof(pt); break; case 7: zr = atof(pt); break; case 8: Manning_n = atof(pt); break; case 9: lat = atof(pt); break; // ***Revised by Cheng-Wei *** 9th column data is shape case 10: lon = atof(pt); break; case 11: shape = atoi(pt); break; default: break; } } // ***Revised by Cheng-Wei *** For 11th or behind columns, // If shape = 2, read the following AA(Wetarea), PP(perimeter), YY(depth), WW(free surface width) --> instrinsic XS // If shape = 1, read the following x and y coordinates. --> XY data XS // If shape = 0, read only 2 colmuns and save as wid and SWS --> Trapezoidal XS. else if (shape == 0){ if (fnum == 12) {wid = atof(pt);} if (fnum == 13) {SWS = atof(pt);} } else if (shape == 1){ if (fnum % 2 == 0) {xData.push_back(atof(pt));} else {yData.push_back(atof(pt));} } else if (shape == 2){ if (fnum % 4 ==0) {AAData.push_back(atof(pt));} if (fnum % 4 ==1) {PPData.push_back(atof(pt));} if (fnum % 4 ==2) {YYData.push_back(atof(pt));} if (fnum % 4 ==3) {WWData.push_back(atof(pt));} } pt = strtok(NULL, TOKEN_DELIM); fnum++; } if (tp >= 2 ) { // fprintf(stderr,"minor branch %s ignored\n", brch_name); } else { eid = TG.MakeEdge(brch_name); up_id = TG.MakeVertex(frm_name); dn_id = TG.MakeVertex(to_name); TG.AssignLength(eid, len); TG.AssignMAF(eid, maf); TG.AssignZr(eid, zr); TG.AssignSlope(eid, slope); TG.AssignLon(eid, lon); TG.AssignLat(eid, lat); TG.AssignManning(eid, Manning_n); // ***Revised by Cheng-Wei *** New assign fuctions TG.AssignShape(eid, shape); // ***Revised by Cheng-Wei *** If shape = 0, // assign only wid and SWS to TG(class tgraph) if (shape == 0){ TG.AssignWid(eid, wid); TG.AssignSWS(eid, SWS); } // ***Revised by Cheng-Wei *** If shape = 1, // assign the XY vector to TG(class tgraph) if (shape == 1){ for (int i = 0; i < xData.size(); i++){ TG.AssignX(eid, xData[i]); TG.AssignY(eid, yData[i]); } } if (shape ==2){ for (int i= 0; i < AAData.size(); i++){ TG.AssignAA(eid, AAData[i]); TG.AssignPP(eid, PPData[i]); TG.AssignYY(eid, YYData[i]); TG.AssignWW(eid, WWData[i]); } } TG.ConnectEdge(eid, up_id, dn_id); } lnum++; } if (F) fclose(F); TG.QuickCheck(); TG.DFS(); // DFS to look at connectivities printf("Reading runoff data from %s\n", argv[2]); int rc = runoff.Init(argv[2]); if ( rc < 0 ) {//return (-1); printf("control point"); return (-1); } #if 0 printf("Dump:\n"); printf("%d %d\n", runoff.NumComid(), runoff.NumTime()); runoff.Dump(stdout, 3); #endif if ((argc>=4) && (steady_flag==0)) { FILE *fp=fopen(outfile,"w"); printf("[II] Netlist will be saved as %s\n", outfile); if (fp) printheader(fp, argv[1], argv[2],argv[3]); TG.DFSupstream( argv[3], &runoff, fp, steady_flag); printcontrol(fp); fclose(fp); } else if((argc>=4) && (steady_flag==1)) { FILE *fp=fopen(outfile,"w"); printf("[II] Steady State Netlist will be saved as %s\n", outfile); if (fp) printheader(fp, argv[1], argv[2],argv[3]); TG.DFSupstream( argv[3], &runoff, fp, steady_flag); printcontrol(fp); fclose(fp); } return 0; }
void search_pat(FILE *fp) { char n[32], yn = 'Y', err[32]; int reg, op, f1 = 0, n1; patient p; while(yn == 'Y' || yn == 'y') { system("clear"); printheader(); f1 = 0; w:printf("\nSearch by 1]Name 2]Registration number 3]Return:\n\n"); n1 = scanf("%d", &op); if(n1 == 0) { op = 7; readline(err, 32); } if(op == 1) { printf("Enter the name of patient:\n"); readline(err, 32); readline(n, 32); rewind(fp); while(fread(&p, SIZE, 1, fp) == 1) { if(strcmp(p.name, n) == 0) { f1 = 1; break; } } } else if(op == 2) { printf("Enter the registration number:\n"); scanf("%d", ®); rewind(fp); while(fread(&p, SIZE, 1, fp) == 1) { if(p.regn == reg) { f1 = 1; break; } } } else if(op == 3) { fclose(fp); pat_info(fp); } else { printf("\t***Invalid entry***\n"); goto w; } if(f1 == 1) { system("clear"); printf("\n\t\t<<------------- DATA OF PATIENT ------------>>\n\n"); printf("=> Registration number of the patient:""\t%d\n\n", p.regn); printf("=> Name of the patient:""\t%s\n\n", p.name); printf("=> Gender:""\t%s\n\n", p.gender); printf("=> Age:""\t%s years\n\n", p.age); printf("=> Address:\n\n"); printf("\t> City:"" \t%s\n", p.a.city); printf("\t> State:"" \t%s\n\n", p.a.state); printf("=> Contact no.:""\t%s\n\n", p.contact); printf("=> E-mail id:""\t%s\n\n", p.email); printf("=> Type of patient:\t"); if(strcmp(p.type, "G") == 0 || strcmp(p.type, "g") == 0) printf("Government servant\n\n"); else printf("Other\n\n"); printf("=> Blood group:""\t%s\n\n", p.bg); printf("=> Disease/problem:""\t%s\n\n", p.disease); printf("=> Name of the doctor to being referred:""\t%s\n\n", p.doc_name); printf("=> History of patient:""\t%s\n\n", p.history); printf("=> Treatment done:""\t%s\n\n", p.treatment); printf("=> Medicines suggested:""\t%s\n\n", p.med); printf("--------------------------------------------------------------\n"); } else printf("\t Entry not found\n"); printf("\nDo you want to search any other registered entry(Y/N)?\n"); scanf(" %c", &yn); } }
int main(int argc, char *argv[]) { struct kinfo_proc *kp, **kinfo; struct varent *vent; struct winsize ws; struct passwd *pwd; dev_t ttydev; pid_t pid; uid_t uid; int all, ch, flag, i, fmt, lineno, nentries; int prtheader, showthreads, wflag, kflag, what, Uflag, xflg; char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX]; if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 && ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 && ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || ws.ws_col == 0) termwidth = 79; else termwidth = ws.ws_col - 1; if (argc > 1) argv[1] = kludge_oldps_options(argv[1]); all = fmt = prtheader = showthreads = wflag = kflag = Uflag = xflg = 0; pid = -1; uid = 0; ttydev = NODEV; memf = nlistf = swapf = NULL; while ((ch = getopt(argc, argv, "acCegHhjkLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1) switch (ch) { case 'a': all = 1; break; case 'c': commandonly = 1; break; case 'e': /* XXX set ufmt */ needenv = 1; break; case 'C': rawcpu = 1; break; case 'g': break; /* no-op */ case 'H': showthreads = 1; break; case 'h': prtheader = ws.ws_row > 5 ? ws.ws_row : 22; break; case 'j': parsefmt(jfmt); fmt = 1; jfmt[0] = '\0'; break; case 'k': kflag++; break; case 'L': showkey(); exit(0); case 'l': parsefmt(lfmt); fmt = 1; lfmt[0] = '\0'; break; case 'M': memf = optarg; break; case 'm': sortby = SORTMEM; break; case 'N': nlistf = optarg; break; case 'O': parsefmt(o1); parsefmt(optarg); parsefmt(o2); o1[0] = o2[0] = '\0'; fmt = 1; break; case 'o': parsefmt(optarg); fmt = 1; break; case 'p': pid = atol(optarg); xflg = 1; break; case 'r': sortby = SORTCPU; break; case 'S': sumrusage = 1; break; case 'T': if ((optarg = ttyname(STDIN_FILENO)) == NULL) errx(1, "stdin: not a terminal"); /* FALLTHROUGH */ case 't': { struct stat sb; char *ttypath, pathbuf[MAXPATHLEN]; if (strcmp(optarg, "co") == 0) ttypath = _PATH_CONSOLE; else if (*optarg != '/') (void)snprintf(ttypath = pathbuf, sizeof(pathbuf), "%s%s", _PATH_TTY, optarg); else ttypath = optarg; if (stat(ttypath, &sb) == -1) err(1, "%s", ttypath); if (!S_ISCHR(sb.st_mode)) errx(1, "%s: not a terminal", ttypath); ttydev = sb.st_rdev; break; } case 'U': pwd = getpwnam(optarg); if (pwd == NULL) errx(1, "%s: no such user", optarg); uid = pwd->pw_uid; endpwent(); Uflag = xflg = 1; break; case 'u': parsefmt(ufmt); sortby = SORTCPU; fmt = 1; ufmt[0] = '\0'; break; case 'v': parsefmt(vfmt); sortby = SORTMEM; fmt = 1; vfmt[0] = '\0'; break; case 'W': swapf = optarg; break; case 'w': if (wflag) termwidth = UNLIMITED; else if (termwidth < 131) termwidth = 131; wflag++; break; case 'x': xflg = 1; break; default: usage(); } argc -= optind; argv += optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { nlistf = *argv; if (*++argv) { memf = *argv; if (*++argv) swapf = *argv; } } #endif if (nlistf == NULL && memf == NULL && swapf == NULL) { kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf); kvm_sysctl_only = 1; } else { kd = kvm_openfiles(nlistf, memf, swapf, O_RDONLY, errbuf); } if (kd == NULL) errx(1, "%s", errbuf); if (!fmt) { if (showthreads) parsefmt(tfmt); else parsefmt(dfmt); } /* XXX - should be cleaner */ if (!all && ttydev == NODEV && pid == -1 && !Uflag) { uid = getuid(); Uflag = 1; } /* * scan requested variables, noting what structures are needed, * and adjusting header widths as appropriate. */ scanvars(); if (neednlist && !nlistread) (void) donlist(); /* * get proc list */ if (Uflag) { what = KERN_PROC_UID; flag = uid; } else if (ttydev != NODEV) { what = KERN_PROC_TTY; flag = ttydev; } else if (pid != -1) { what = KERN_PROC_PID; flag = pid; } else if (kflag) { what = KERN_PROC_KTHREAD; flag = 0; } else { what = KERN_PROC_ALL; flag = 0; } if (showthreads) what |= KERN_PROC_SHOW_THREADS; /* * select procs */ kp = kvm_getprocs(kd, what, flag, sizeof(*kp), &nentries); if (kp == NULL) errx(1, "%s", kvm_geterr(kd)); /* * print header */ printheader(); if (nentries == 0) exit(1); /* * sort proc list, we convert from an array of structs to an array * of pointers to make the sort cheaper. */ if ((kinfo = calloc(sizeof(*kinfo), nentries)) == NULL) err(1, "failed to allocate memory for proc pointers"); for (i = 0; i < nentries; i++) kinfo[i] = &kp[i]; qsort(kinfo, nentries, sizeof(*kinfo), pscomp); /* * for each proc, call each variable output function. */ for (i = lineno = 0; i < nentries; i++) { if (showthreads == 0 && (kinfo[i]->p_flag & P_THREAD) != 0) continue; if (xflg == 0 && ((int)kinfo[i]->p_tdev == NODEV || (kinfo[i]->p_flag & P_CONTROLT ) == 0)) continue; if (showthreads && kinfo[i]->p_tid == -1) continue; for (vent = vhead; vent; vent = vent->next) { (vent->var->oproc)(kinfo[i], vent); if (vent->next != NULL) (void)putchar(' '); } (void)putchar('\n'); if (prtheader && lineno++ == prtheader - 4) { (void)putchar('\n'); printheader(); lineno = 0; } } exit(eval); }
void edit_pat(FILE *fp) { char yn, err[32]; patient p; int reg, flag = 0, op, n; yn = 'Y'; while(yn == 'Y' || yn == 'y') { system("clear"); printheader(); flag = 0; w:printf("\n1]Edit record\t 2]Return\n"); n = scanf("%d", &op); if(n == 0) { op = 7; readline(err, 32); } if(op == 1) { printf("\n\nEnter Registration number:"); } else if(op == 2) { system("clear"); fclose(fp); pat_info(fp); } else { printf("\n\t***Invalid entry***\n"); goto w; } scanf("%d", ®); rewind(fp); while(fread(&p, SIZE, 1, fp) == 1) { if(p.regn == reg) { flag = 1; break; } } if(flag == 0) { printf("\t The patient is not registered\n"); yn = 'N'; } else { printf("\nName of the patient:"); readline(err, 32); readline(p.name, 32); printf("\nGender(M:Male/F:Female/O:Other):"); readline(p.gender, 8); printf("\nAge:"); readline(p.age, 4); printf("\nAddress:\n"); printf("\n\tCity:"); readline(p.a.city, 32); printf("\n\tState:"); readline(p.a.state, 32); printf("\nContact no.:"); readline(p.contact, 16); printf("\nE-mail id:"); readline(p.email, 32); printf("\nType of patient:\n\tGovernment servant(G)\n\tOther(O)"); readline(p.type, 16); printf("\nBlood group:"); readline(p.bg, 4); printf("\nDisease/problem:"); readline(p.disease, 64); printf("\nName of the doctor to being referred:"); readline(p.doc_name, 32); printf("\nHistory of patient if any:"); readline(p.history, 256); printf("\nTreatment done:"); readline(p.treatment, 32); printf("\nMedicines suggested:"); readline(p.med, 32); fseek(fp, -SIZE, SEEK_CUR); fwrite(&p, SIZE, 1, fp); printf("\n\n\t\t\t***Successfully edited***\n\n"); printf("Do you want edit any other registered entry(Y/N)?\n"); scanf("%c", &yn); } } }
void mesgload(Message *m, char *rootdir, char *file, Window *w) { char *s, *subdir, *name, *dir; Message *mp, *thisone; int n; dir = estrstrdup(rootdir, file); if(strcmp(m->type, "message/rfc822") != 0){ /* suppress headers of envelopes */ if(strlen(m->from) > 0){ Bprint(w->body, "From: %s\n", m->from); mesgline(m, "Date", m->date); mesgline(m, "To", m->to); mesgline(m, "CC", m->cc); mesgline(m, "Subject", m->subject); printheader(dir, w->body, extraheaders); }else{ printheader(dir, w->body, okheaders); printheader(dir, w->body, extraheaders); } Bprint(w->body, "\n"); } if(m->level == 1 && m->recursed == 0){ m->recursed = 1; readmbox(m, rootdir, m->name); } if(m->head == nil){ /* single part message */ if(strcmp(m->type, "text")==0 || strncmp(m->type, "text/", 5)==0){ mimedisplay(m, m->name, rootdir, w, 1); s = readbody(m->type, dir, &n); winwritebody(w, s, n); free(s); }else mimedisplay(m, m->name, rootdir, w, 0); }else{ /* multi-part message, either multipart or message/rfc822 */ thisone = nil; if(strcmp(m->type, "multipart/alternative") == 0){ thisone = bestalt(m, dir); if(thisone == nil){ thisone = m->head; /* in case we can't find a good one */ for(mp=m->head; mp!=nil; mp=mp->next) if(isprintable(mp->type)){ thisone = mp; break; } } } for(mp=m->head; mp!=nil; mp=mp->next){ if(thisone!=nil && mp!=thisone) continue; subdir = estrstrdup(dir, mp->name); name = estrstrdup(file, mp->name); /* skip first element in name because it's already in window name */ if(mp != m->head) Bprint(w->body, "\n===> %s (%s) [%s]\n", strchr(name, '/')+1, mp->type, mp->disposition); if(strcmp(mp->type, "text")==0 || strncmp(mp->type, "text/", 5)==0){ mimedisplay(mp, name, rootdir, w, 1); printheader(subdir, w->body, okheaders); printheader(subdir, w->body, extraheaders); winwritebody(w, "\n", 1); s = readbody(mp->type, subdir, &n); winwritebody(w, s, n); free(s); }else{ if(strncmp(mp->type, "multipart/", 10)==0 || strcmp(mp->type, "message/rfc822")==0){ mp->w = w; mesgload(mp, rootdir, name, w); mp->w = nil; }else mimedisplay(mp, name, rootdir, w, 0); } free(name); free(subdir); } } free(dir); }
void intitest(char *name) { printheader(name); }
void initreference(char *name) { printheader(name); }
static void DoFile(const char *savedir, const char *device) { xo_handle_t *xostdout, *xoinfo; static char infoname[PATH_MAX], corename[PATH_MAX], linkname[PATH_MAX]; static char *buf = NULL, *temp = NULL; struct kerneldumpheader kdhf, kdhl; off_t mediasize, dumpsize, firsthd, lasthd; FILE *info, *fp; mode_t oumask; int fd, fdinfo, error; int bounds, status; u_int sectorsize, xostyle; int istextdump; bounds = getbounds(); mediasize = 0; status = STATUS_UNKNOWN; xostdout = xo_create_to_file(stdout, XO_STYLE_TEXT, 0); if (xostdout == NULL) { syslog(LOG_ERR, "%s: %m", infoname); return; } if (maxdumps > 0 && bounds == maxdumps) bounds = 0; if (buf == NULL) { buf = malloc(BUFFERSIZE); if (buf == NULL) { syslog(LOG_ERR, "%m"); return; } } if (verbose) printf("checking for kernel dump on device %s\n", device); fd = open(device, (checkfor || keep) ? O_RDONLY : O_RDWR); if (fd < 0) { syslog(LOG_ERR, "%s: %m", device); return; } error = ioctl(fd, DIOCGMEDIASIZE, &mediasize); if (!error) error = ioctl(fd, DIOCGSECTORSIZE, §orsize); if (error) { syslog(LOG_ERR, "couldn't find media and/or sector size of %s: %m", device); goto closefd; } if (verbose) { printf("mediasize = %lld\n", (long long)mediasize); printf("sectorsize = %u\n", sectorsize); } if (sectorsize < sizeof(kdhl)) { syslog(LOG_ERR, "Sector size is less the kernel dump header %zu", sizeof(kdhl)); goto closefd; } lasthd = mediasize - sectorsize; if (temp == NULL) { temp = malloc(sectorsize); if (temp == NULL) { syslog(LOG_ERR, "%m"); return; } } if (lseek(fd, lasthd, SEEK_SET) != lasthd || read(fd, temp, sectorsize) != (ssize_t)sectorsize) { syslog(LOG_ERR, "error reading last dump header at offset %lld in %s: %m", (long long)lasthd, device); goto closefd; } memcpy(&kdhl, temp, sizeof(kdhl)); istextdump = 0; if (strncmp(kdhl.magic, TEXTDUMPMAGIC, sizeof kdhl) == 0) { if (verbose) printf("textdump magic on last dump header on %s\n", device); istextdump = 1; if (dtoh32(kdhl.version) != KERNELDUMP_TEXT_VERSION) { syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); status = STATUS_BAD; if (force == 0) goto closefd; } } else if (memcmp(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic) == 0) { if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); status = STATUS_BAD; if (force == 0) goto closefd; } } else { if (verbose) printf("magic mismatch on last dump header on %s\n", device); status = STATUS_BAD; if (force == 0) goto closefd; if (memcmp(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof kdhl.magic) == 0) { if (verbose) printf("forcing magic on %s\n", device); memcpy(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic); } else { syslog(LOG_ERR, "unable to force dump - bad magic"); goto closefd; } if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); status = STATUS_BAD; if (force == 0) goto closefd; } } nfound++; if (clear) goto nuke; if (kerneldump_parity(&kdhl)) { syslog(LOG_ERR, "parity error on last dump header on %s", device); nerr++; status = STATUS_BAD; if (force == 0) goto closefd; } dumpsize = dtoh64(kdhl.dumplength); firsthd = lasthd - dumpsize - sectorsize; if (lseek(fd, firsthd, SEEK_SET) != firsthd || read(fd, temp, sectorsize) != (ssize_t)sectorsize) { syslog(LOG_ERR, "error reading first dump header at offset %lld in %s: %m", (long long)firsthd, device); nerr++; goto closefd; } memcpy(&kdhf, temp, sizeof(kdhf)); if (verbose >= 2) { printf("First dump headers:\n"); printheader(xostdout, &kdhf, device, bounds, -1); printf("\nLast dump headers:\n"); printheader(xostdout, &kdhl, device, bounds, -1); printf("\n"); } if (memcmp(&kdhl, &kdhf, sizeof(kdhl))) { syslog(LOG_ERR, "first and last dump headers disagree on %s", device); nerr++; status = STATUS_BAD; if (force == 0) goto closefd; } else { status = STATUS_GOOD; } if (checkfor) { printf("A dump exists on %s\n", device); close(fd); exit(0); } if (kdhl.panicstring[0] != '\0') syslog(LOG_ALERT, "reboot after panic: %*s", (int)sizeof(kdhl.panicstring), kdhl.panicstring); else syslog(LOG_ALERT, "reboot"); if (verbose) printf("Checking for available free space\n"); if (!check_space(savedir, dumpsize, bounds)) { nerr++; goto closefd; } writebounds(bounds + 1); saved_dump_remove(bounds); snprintf(infoname, sizeof(infoname), "info.%d", bounds); /* * Create or overwrite any existing dump header files. */ fdinfo = open(infoname, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fdinfo < 0) { syslog(LOG_ERR, "%s: %m", infoname); nerr++; goto closefd; } oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file.*/ if (compress) { snprintf(corename, sizeof(corename), "%s.%d.gz", istextdump ? "textdump.tar" : "vmcore", bounds); fp = zopen(corename, "w"); } else { snprintf(corename, sizeof(corename), "%s.%d", istextdump ? "textdump.tar" : "vmcore", bounds); fp = fopen(corename, "w"); } if (fp == NULL) { syslog(LOG_ERR, "%s: %m", corename); close(fdinfo); nerr++; goto closefd; } (void)umask(oumask); info = fdopen(fdinfo, "w"); if (info == NULL) { syslog(LOG_ERR, "fdopen failed: %m"); nerr++; goto closeall; } xostyle = xo_get_style(NULL); xoinfo = xo_create_to_file(info, xostyle, 0); if (xoinfo == NULL) { syslog(LOG_ERR, "%s: %m", infoname); nerr++; goto closeall; } xo_open_container_h(xoinfo, "crashdump"); if (verbose) printheader(xostdout, &kdhl, device, bounds, status); printheader(xoinfo, &kdhl, device, bounds, status); xo_close_container_h(xoinfo, "crashdump"); xo_flush_h(xoinfo); xo_finish_h(xoinfo); fclose(info); syslog(LOG_NOTICE, "writing %score to %s/%s", compress ? "compressed " : "", savedir, corename); if (istextdump) { if (DoTextdumpFile(fd, dumpsize, lasthd, buf, device, corename, fp) < 0) goto closeall; } else { if (DoRegularFile(fd, dumpsize, buf, device, corename, fp) < 0) goto closeall; } if (verbose) printf("\n"); if (fclose(fp) < 0) { syslog(LOG_ERR, "error on %s: %m", corename); nerr++; goto closefd; } symlinks_remove(); if (symlink(infoname, "info.last") == -1) { syslog(LOG_WARNING, "unable to create symlink %s/%s: %m", savedir, "info.last"); } if (compress) { snprintf(linkname, sizeof(linkname), "%s.last.gz", istextdump ? "textdump.tar" : "vmcore"); } else { snprintf(linkname, sizeof(linkname), "%s.last", istextdump ? "textdump.tar" : "vmcore"); } if (symlink(corename, linkname) == -1) { syslog(LOG_WARNING, "unable to create symlink %s/%s: %m", savedir, linkname); } nsaved++; if (verbose) printf("dump saved\n"); nuke: if (!keep) { if (verbose) printf("clearing dump header\n"); memcpy(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof(kdhl.magic)); memcpy(temp, &kdhl, sizeof(kdhl)); if (lseek(fd, lasthd, SEEK_SET) != lasthd || write(fd, temp, sectorsize) != (ssize_t)sectorsize) syslog(LOG_ERR, "error while clearing the dump header: %m"); } xo_close_container_h(xostdout, "crashdump"); xo_finish_h(xostdout); close(fd); return; closeall: fclose(fp); closefd: close(fd); }
static void DoFile(const char *savedir, const char *device) { static char *buf = NULL; struct partinfo dpart; struct kerneldumpheader kdhf, kdhl; off_t mediasize, dumpsize, firsthd, lasthd, dmpcnt; FILE *info, *fp, *fpkern; mode_t oumask; int fd, fdinfo, fdkernin, error, wl; int nr, nw, hs, he = 0; int bounds, status; u_int sectorsize; bounds = getbounds(); dmpcnt = 0; mediasize = 0; status = STATUS_UNKNOWN; if (buf == NULL) { buf = malloc(BUFFERSIZE); if (buf == NULL) { syslog(LOG_ERR, "%m"); return; } } if (verbose) printf("checking for kernel dump on device %s\n", device); fd = open(device, O_RDWR); if (fd < 0) { syslog(LOG_ERR, "%s: %m", device); return; } bzero(&dpart, sizeof(dpart)); error = ioctl(fd, DIOCGPART, &dpart); if (error) { syslog(LOG_ERR, "couldn't find media and/or sector size of %s: %m", device); goto closefd; } mediasize = dpart.media_size; sectorsize = dpart.media_blksize; if (verbose) { printf("mediasize = %lld\n", (long long)mediasize); printf("sectorsize = %u\n", sectorsize); } lasthd = mediasize - sectorsize; lseek(fd, lasthd, SEEK_SET); error = read(fd, &kdhl, sizeof kdhl); if (error != sizeof kdhl) { syslog(LOG_ERR, "error reading last dump header at offset %lld in %s: %m", (long long)lasthd, device); goto closefd; } if (memcmp(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic)) { if (verbose) printf("magic mismatch on last dump header on %s\n", device); status = STATUS_BAD; if (force == 0) goto closefd; if (memcmp(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof kdhl.magic) == 0) { if (verbose) printf("forcing magic on %s\n", device); memcpy(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic); } else { syslog(LOG_ERR, "unable to force dump - bad magic"); goto closefd; } } if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); status = STATUS_BAD; if (force == 0) goto closefd; } nfound++; if (clear) goto nuke; if (kerneldump_parity(&kdhl)) { syslog(LOG_ERR, "parity error on last dump header on %s", device); nerr++; status = STATUS_BAD; if (force == 0) goto closefd; } dumpsize = dtoh64(kdhl.dumplength); firsthd = lasthd - dumpsize - sizeof kdhf; lseek(fd, firsthd, SEEK_SET); error = read(fd, &kdhf, sizeof kdhf); if (error != sizeof kdhf) { syslog(LOG_ERR, "error reading first dump header at offset %lld in %s: %m", (long long)firsthd, device); nerr++; goto closefd; } if (verbose >= 2) { printf("First dump headers:\n"); printheader(stdout, &kdhf, device, bounds, -1); printf("\nLast dump headers:\n"); printheader(stdout, &kdhl, device, bounds, -1); printf("\n"); } if (memcmp(&kdhl, &kdhf, sizeof kdhl)) { syslog(LOG_ERR, "first and last dump headers disagree on %s", device); nerr++; status = STATUS_BAD; if (force == 0) goto closefd; } else { status = STATUS_GOOD; } if (checkfor) { printf("A dump exists on %s\n", device); close(fd); exit(0); } if (kdhl.panicstring[0]) syslog(LOG_ALERT, "reboot after panic: %s", kdhl.panicstring); else syslog(LOG_ALERT, "reboot"); if (verbose) printf("Checking for available free space\n"); if (!check_space(savedir, dumpsize)) { nerr++; goto closefd; } writebounds(bounds + 1); /* * Write kernel file. */ fdkernin = open(getbootfile(), O_RDONLY, 0); if (fdkernin < 0) { syslog(LOG_ERR, "%s: %m", getbootfile()); } if (compress) { sprintf(buf, "kern.%d.gz", bounds); fpkern = zopen(buf, "w"); } else { sprintf(buf, "kern.%d", bounds); fpkern = fopen(buf, "w"); } if (fpkern == NULL) { syslog(LOG_ERR, "%s: %m", buf); close(fdkernin); } syslog(LOG_NOTICE, "writing %skernel to %s", compress ? "compressed " : "", buf); while ((nr = read(fdkernin, buf, sizeof(buf))) > 0) { nw = fwrite(buf, 1, nr, fpkern); if (nw != nr) { syslog(LOG_ERR, "kern.%d: %m", bounds); syslog(LOG_WARNING, "WARNING: kernel may be incomplete"); exit(1); } } if (nr < 0) { syslog(LOG_ERR, "%s: %m", getbootfile()); syslog(LOG_WARNING, "WARNING: kernel may be incomplete"); exit(1); } fclose(fpkern); close(fdkernin); sprintf(buf, "info.%d", bounds); /* * Create or overwrite any existing dump header files. */ fdinfo = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fdinfo < 0) { syslog(LOG_ERR, "%s: %m", buf); nerr++; goto closefd; } oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file.*/ if (compress) { sprintf(buf, "vmcore.%d.gz", bounds); fp = zopen(buf, "w"); } else { sprintf(buf, "vmcore.%d", bounds); fp = fopen(buf, "w"); } if (fp == NULL) { syslog(LOG_ERR, "%s: %m", buf); close(fdinfo); nerr++; goto closefd; } (void)umask(oumask); info = fdopen(fdinfo, "w"); if (info == NULL) { syslog(LOG_ERR, "fdopen failed: %m"); nerr++; goto closefd; } if (verbose) printheader(stdout, &kdhl, device, bounds, status); printheader(info, &kdhl, device, bounds, status); fclose(info); syslog(LOG_NOTICE, "writing %score to %s", compress ? "compressed " : "", buf); while (dumpsize > 0) { wl = BUFFERSIZE; if (wl > dumpsize) wl = dumpsize; nr = read(fd, buf, wl); if (nr != wl) { if (nr == 0) syslog(LOG_WARNING, "WARNING: EOF on dump device"); else syslog(LOG_ERR, "read error on %s: %m", device); nerr++; goto closeall; } if (compress) { nw = fwrite(buf, 1, wl, fp); } else { for (nw = 0; nw < nr; nw = he) { /* find a contiguous block of zeroes */ for (hs = nw; hs < nr; hs += BLOCKSIZE) { for (he = hs; he < nr && buf[he] == 0; ++he) /* nothing */ ; /* is the hole long enough to matter? */ if (he >= hs + BLOCKSIZE) break; } /* back down to a block boundary */ he &= BLOCKMASK; /* * 1) Don't go beyond the end of the buffer. * 2) If the end of the buffer is less than * BLOCKSIZE bytes away, we're at the end * of the file, so just grab what's left. */ if (hs + BLOCKSIZE > nr) hs = he = nr; /* * At this point, we have a partial ordering: * nw <= hs <= he <= nr * If hs > nw, buf[nw..hs] contains non-zero data. * If he > hs, buf[hs..he] is all zeroes. */ if (hs > nw) if (fwrite(buf + nw, hs - nw, 1, fp) != 1) break; if (he > hs) if (fseeko(fp, he - hs, SEEK_CUR) == -1) break; } } if (nw != wl) { syslog(LOG_ERR, "write error on vmcore.%d file: %m", bounds); syslog(LOG_WARNING, "WARNING: vmcore may be incomplete"); nerr++; goto closeall; } if (verbose) { dmpcnt += wl; printf("%llu\r", (unsigned long long)dmpcnt); fflush(stdout); } dumpsize -= wl; } if (verbose) printf("\n"); if (fclose(fp) < 0) { syslog(LOG_ERR, "error on vmcore.%d: %m", bounds); nerr++; goto closeall; } nsaved++; if (verbose) printf("dump saved\n"); nuke: if (clear || !keep) { if (verbose) printf("clearing dump header\n"); memcpy(kdhl.magic, KERNELDUMPMAGIC_CLEARED, sizeof kdhl.magic); lseek(fd, lasthd, SEEK_SET); error = write(fd, &kdhl, sizeof kdhl); if (error != sizeof kdhl) syslog(LOG_ERR, "error while clearing the dump header: %m"); } close(fd); return; closeall: fclose(fp); closefd: close(fd); }
/* Get output stream pointer (open and write header if new and noopen==0) */ STREAMOUT * getostream(const char *ospec, const char *mname, int bn, int noopen) { static STREAMOUT stdos; char info[1024]; int ofl; char oname[1024]; LUENT *lep; STREAMOUT *sop; char *cp; if (ospec == NULL) { /* use stdout? */ if (!noopen & !using_stdout) { if (outfmt != 'a') SET_FILE_BINARY(stdout); if (header) { cp = info; if (yres > 0) { sprintf(cp, "NROWS=%d\n", yres * (xres + !xres) ); while (*cp) ++cp; } if ((xres <= 0) | (stdos.reclen > 1)) sprintf(cp, "NCOLS=%d\n", stdos.reclen); printheader(stdout, info); } if (stdos.reclen == 1) printresolu(stdout, xres, yres); if (waitflush > 0) fflush(stdout); stdos.xr = xres; stdos.yr = yres; #ifdef getc_unlocked flockfile(stdout); /* avoid lock/unlock overhead */ #endif using_stdout = 1; } stdos.ofp = stdout; stdos.reclen += noopen; return(&stdos); } ofl = ofname(oname, ospec, mname, bn); /* get output name */ if (ofl < 0) { sprintf(errmsg, "bad output format '%s'", ospec); error(USER, errmsg); } lep = lu_find(&ofiletab, oname); /* look it up */ if (lep->key == NULL) /* new entry */ lep->key = strcpy((char *)malloc(strlen(oname)+1), oname); sop = (STREAMOUT *)lep->data; if (sop == NULL) { /* allocate stream */ sop = (STREAMOUT *)malloc(sizeof(STREAMOUT)); if (sop == NULL) error(SYSTEM, "out of memory in getostream"); sop->outpipe = oname[0] == '!'; sop->reclen = 0; sop->ofp = NULL; /* open iff noopen==0 */ sop->xr = xres; sop->yr = yres; lep->data = (char *)sop; if (!sop->outpipe & !force_open & !recover && access(oname, F_OK) == 0) { errno = EEXIST; /* file exists */ goto openerr; } } if (!noopen && sop->ofp == NULL) { /* open output stream */ if (oname[0] == '!') /* output to command */ sop->ofp = popen(oname+1, "w"); else /* else open file */ sop->ofp = fopen(oname, "w"); if (sop->ofp == NULL) goto openerr; if (outfmt != 'a') SET_FILE_BINARY(sop->ofp); #ifdef getc_unlocked flockfile(sop->ofp); /* avoid lock/unlock overhead */ #endif if (accumulate > 0) { /* global resolution */ sop->xr = xres; sop->yr = yres; } if (header) { cp = info; if (ofl & OF_MODIFIER || sop->reclen == 1) { sprintf(cp, "MODIFIER=%s\n", mname); while (*cp) ++cp; } if (ofl & OF_BIN) { sprintf(cp, "BIN=%d\n", bn); while (*cp) ++cp; } if (sop->yr > 0) { sprintf(cp, "NROWS=%d\n", sop->yr * (sop->xr + !sop->xr) ); while (*cp) ++cp; } if ((sop->xr <= 0) | (sop->reclen > 1)) sprintf(cp, "NCOLS=%d\n", sop->reclen); printheader(sop->ofp, info); } if (sop->reclen == 1) printresolu(sop->ofp, sop->xr, sop->yr); if (waitflush > 0) fflush(sop->ofp); } sop->reclen += noopen; /* add to length if noopen */ return(sop); /* return output stream */ openerr: sprintf(errmsg, "cannot open '%s' for writing", oname); error(SYSTEM, errmsg); return(NULL); /* pro forma return */ }
/* dump out a Paragraph in the desired manner */ static Paragraph* display(Paragraph *p, MMIOT *f, int easyNewLine) { if ( !p ) return 0; switch ( p->typ ) { case STYLE: case WHITESPACE: break; case HTML: printhtml(p->text, f); break; case CODE: printcode(p->text, f); break; case QUOTE: if (p->down) { p->down->easyNewline = p->easyNewline; } htmlify(p->down, p->ident ? "div" : "blockquote", p->ident, f); break; case UL: case OL: case AL: listdisplay(p->typ, p->down, f); break; case DL: definitionlist(p->down, f); break; case HR: Qstring("<hr />", f); break; case HDR: printheader(p, f); break; case TABLE: printtable(p, f); break; case SOURCE: if (p->down) { p->down->easyNewline = p->easyNewline; } htmlify(p->down, 0, 0, f); break; default: printblock(p, f, easyNewLine); break; } // MK HACK, copy easyNewLine Paragraph *pNext = p->next; if (pNext) { pNext->easyNewline = p->easyNewline; } return pNext; }
int gibbsandMHloop(int iter,int thin,gsl_rng *RNG,struct_data *D,struct_para *D_para,struct_priors *D_priors ,struct_MH *D_MH,int print){ int i,j,l,m,mm,c,ll; if (print==0){ printheader(D); } for (i=0;i<iter;i++){ for (j=0;j<thin;j++){ D_para->P=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_P,&D_MH->hP,D_para->P,MCMC_P,-999,-999,-999); D_MH->hK=0.00003; D_para->alpha_c[1]=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_K,&D_MH->halpha,D_para->alpha_c[1],MCMC_alpha_c,-999,-999,-999); D_para->beta_c[1]=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_K,&D_MH->halpha,D_para->beta_c[1],MCMC_beta_c,-999,-999,-999); D_MH->hK=0.0001; D_para->sigma_gamma=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_K,&D_MH->hK,D_para->sigma_gamma,MCMC_sigma_gamma,-999,-999,-999); D_para->sigma_omega=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_K,&D_MH->hK,D_para->sigma_omega,MCMC_sigma_omega,-999,-999,-999); D_MH->hK=1; D_para->sigma_upsilon=MCMC_base( RNG,D,D_para,D_priors,&D_MH->accept_K,&D_MH->hK,D_para->sigma_upsilon,MCMC_sigma_upsilon,-999,-999,-999); D_MH->hK=0.0001; D_para->sigma_nu=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_K,&D_MH->hP,D_para->sigma_nu,MCMC_sigma_nu,-999,-999,-999); D_MH->hK=0.1; D_para->sigma_K_o=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_K,&D_MH->hK,D_para->sigma_K_o,MCMC_sigma_K_o,-999,-999,-999); D_para->sigma_r_o=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_K,&D_MH->hK,D_para->sigma_r_o,MCMC_sigma_r_o,-999,-999,-999); D_MH->hK=0.0001; D_para->nu_p=gauss_sample(RNG,D,0,D->L,D_para->nu_l,exp(D_para->sigma_nu),D_priors->nu_mu,D_priors->eta_nu); D_para->upsilon_c[1]=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_K,&D_MH->hK,D_para->upsilon_c[1],MCMC_upsilon_c,-999,-999,-999); for (l=0;l<D->L;l++){ D_para->nu_l[l]=MCMC_base(RNG,D,D_para,D_priors,&D_MH->accept_nu,&D_MH->hnu,D_para->nu_l[l],MCMC_nu_l,-999,l,-999); D_para->gamma_cl[l]=MCMC_base( RNG,D,D_para,D_priors,&D_MH->accept_nu,&D_MH->hnu,D_para->gamma_cl[l],MCMC_gamma_cl,-999,l,-999); D_para->omega_cl[l]=MCMC_base( RNG,D,D_para,D_priors,&D_MH->accept_nu,&D_MH->hnu,D_para->omega_cl[l],MCMC_omega_cl,-999,l,-999); D_para->delta_l[l]=aug_delta_l(RNG,D,D_para,D_priors,l); for (c=0;c<2;c++){ ll=c*D->L+l; D_para->tau_K_cl[ll]=gsl_min(7,MCMC_base( RNG,D,D_para,D_priors,&D_MH->accept_nu,&D_MH->hnu,D_para->tau_K_cl[ll],MCMC_tau_K_cl,c,l,-999)); D_para->tau_r_cl[ll]=gsl_min(11,MCMC_base( RNG,D,D_para,D_priors,&D_MH->accept_nu,&D_MH->hnu,D_para->tau_r_cl[ll],MCMC_tau_r_cl,c,l,-999)); for (m=0;m<D->NoORF[l];m++){ mm=D->NoSUM[ll]+m; D_MH->hK=0.1; D_para->K_clm[mm]=gsl_min(0,MCMC_base( RNG,D,D_para,D_priors,&D_MH->accept_K,&D_MH->hK,D_para->K_clm[mm],MCMC_K_clm,c,l,m)); D_MH->hK=0.0001; D_para->r_clm[mm]=gsl_min(3.5,MCMC_base( RNG,D,D_para,D_priors,&D_MH->accept_r,&D_MH->hr,D_para->r_clm[mm],MCMC_r_clm,c,l,m)); } } } update_lik_a(D_para->K_clm,D_para->tau_K_cl,D_para->gamma_cl,D_para->alpha_c,D,D_para,D_para->star_K_lm,D_para->star_tau_K_l); update_lik_b(D_para->star_K_lm,1/exp(D_para->sigma_K_o),D_para->star_tau_K_l,D,D_para,&D_para->star_K_l,&D_para->star_sigma_K_o); D_para->K_p=sim_para(RNG,D_para->star_K_l,D_para->star_sigma_K_o,D_priors->K_mu,1/D_priors->eta_K_p); for (l=0;l<D->L;l++){ D_para->K_o_l[l]=sim_para(RNG,D_para->star_K_lm[l],D_para->star_tau_K_l[l],D_para->K_p,1/exp(D_para->sigma_K_o)); } update_lik_a(D_para->r_clm,D_para->tau_r_cl,D_para->omega_cl,D_para->beta_c,D,D_para,D_para->star_r_lm,D_para->star_tau_r_l); update_lik_b(D_para->star_r_lm,1/exp(D_para->sigma_r_o),D_para->star_tau_r_l,D,D_para,&D_para->star_r_l,&D_para->star_sigma_r_o); D_para->r_p=sim_para(RNG,D_para->star_r_l,D_para->star_sigma_r_o,D_priors->r_mu,1/D_priors->eta_r_p); for (l=0;l<D->L;l++){ D_para->r_o_l[l]=sim_para(RNG,D_para->star_r_lm[l],D_para->star_tau_r_l[l],D_para->r_p,1/exp(D_para->sigma_r_o)); } } if (print==1){ printdata(D,D_para,D_MH); } } return 0; }
void new_pat(FILE *fp) { char yn, err[32]; int flag = 0, reg, op, n; patient p; fseek(fp, 0, SEEK_END); yn = 'Y'; while((yn == 'Y') || (yn == 'y')) { printf("\n--------------------------------------------------------------------------------\n"); system("clear"); printheader(); w: printf("1]Add record\t 2]Return\n"); n = scanf("%d", &op); if(n == 0) { op = 7; readline(err, 32); } if(op == 1) { printf("\n\nEnter Registration number:"); } else if(op == 2) { system("clear"); fclose(fp); pat_info(fp); } else { printf("\n\t***Invalid entry***\n"); goto w; } scanf("%d", ®); rewind(fp); while(fread(&p, SIZE, 1, fp) == 1) { if(p.regn == reg) { printf("\t Registration number already exists; type another one.\n\n"); flag = 1; goto w; } } if((flag == 0) || (fread(&p, SIZE, 1, fp) == 0)) { fseek(fp, 0, SEEK_END); p.regn = reg; printf("\nName of the patient:"); readline(err, 32); readline(p.name, 32); printf("\nGender(M:Male/F:Female/O:Other):"); readline(p.gender, 8); printf("\nAge:"); readline(p.age, 4); printf("\nAddress:\n"); printf("\n\tCity:"); readline(p.a.city, 32); printf("\n\tState:"); readline(p.a.state, 32); printf("\nContact no.:"); readline(p.contact, 16); printf("\nE-mail id:"); readline(p.email, 32); printf("\nType of patient:\n\tGovernment servant(G)\n\tOther(O)\n"); readline(p.type, 16); printf("\nBlood group:"); readline(p.bg, 4); printf("\nDisease/problem:"); readline(p.disease, 64); printf("\nName of the doctor to being referred:"); readline(p.doc_name, 32); printf("\nHistory of patient if any:"); readline(p.history, 256); printf("\n\n\t\t\t***Successfully enrolled***\n\n"); fwrite(&p, SIZE, 1, fp); printf("Do you want to make another new entry(Y/N)?\n"); scanf("%c", &yn); } } }
/* * send the damn thing */ char * data(String *from, Biobuf *b) { char *buf, *cp; int i, n, nbytes, bufsize, eof, r; String *fromline; char errmsg[Errlen]; char id[40]; /* * input the header. */ buf = malloc(1); if(buf == 0){ s_append(s_restart(reply), "out of memory"); return Retry; } n = 0; eof = 0; for(;;){ cp = Brdline(b, '\n'); if(cp == nil){ eof = 1; break; } nbytes = Blinelen(b); buf = realloc(buf, n+nbytes+1); if(buf == 0){ s_append(s_restart(reply), "out of memory"); return Retry; } strncpy(buf+n, cp, nbytes); n += nbytes; if(nbytes == 1) /* end of header */ break; } buf[n] = 0; bufsize = n; /* * parse the header, turn all addresses into @ format */ yyinit(buf, n); yyparse(); /* * print message observing '.' escapes and using \r\n for \n */ alarm(20*alarmscale); if(!filter){ dBprint("DATA\r\n"); switch(getreply()){ case 3: break; case 5: free(buf); return Giveup; default: free(buf); return Retry; } } /* * send header. add a message-id, a sender, and a date if there * isn't one */ nbytes = 0; fromline = convertheader(from); uneaten = buf; srand(truerand()); if(messageid == 0){ for(i=0; i<16; i++){ r = rand()&0xFF; id[2*i] = hex[r&0xF]; id[2*i+1] = hex[(r>>4)&0xF]; } id[2*i] = '\0'; nbytes += Bprint(&bout, "Message-ID: <%s@%s>\r\n", id, hostdomain); if(debug) Bprint(&berr, "Message-ID: <%s@%s>\r\n", id, hostdomain); } if(originator==0){ nbytes += Bprint(&bout, "From: %s\r\n", s_to_c(fromline)); if(debug) Bprint(&berr, "From: %s\r\n", s_to_c(fromline)); } s_free(fromline); if(destination == 0 && toline) if(*s_to_c(toline) == '@'){ /* route addr */ nbytes += Bprint(&bout, "To: <%s>\r\n", s_to_c(toline)); if(debug) Bprint(&berr, "To: <%s>\r\n", s_to_c(toline)); } else { nbytes += Bprint(&bout, "To: %s\r\n", s_to_c(toline)); if(debug) Bprint(&berr, "To: %s\r\n", s_to_c(toline)); } if(date==0 && udate) nbytes += printdate(udate); if (usys) uneaten = usys->end + 1; nbytes += printheader(); if (*uneaten != '\n') putcrnl("\n", 1); /* * send body */ putcrnl(uneaten, buf+n - uneaten); nbytes += buf+n - uneaten; if(eof == 0){ for(;;){ n = Bread(b, buf, bufsize); if(n < 0){ rerrstr(errmsg, sizeof(errmsg)); s_append(s_restart(reply), errmsg); free(buf); return Retry; } if(n == 0) break; alarm(10*alarmscale); putcrnl(buf, n); nbytes += n; } } free(buf); if(!filter){ if(last != '\n') dBprint("\r\n.\r\n"); else dBprint(".\r\n"); alarm(10*alarmscale); switch(getreply()){ case 2: break; case 5: return Giveup; default: return Retry; } syslog(0, "smtp", "%s sent %d bytes to %s", s_to_c(from), nbytes, s_to_c(toline));/**/ } return 0; }
static void cmparena(char *name, vlong len) { ArenaHead head; DigestState s; u64int n, e; u32int bs; int i, j; char buf[20]; fprint(2, "cmp %s\n", name); memset(&s, 0, sizeof s); /* * read a little bit, which will include the header */ if(readblock(fd, data, HeadSize) < 0){ fprint(2, "%s: reading header: %r\n", name); return; } if(unpackarenahead(&head, data) < 0){ fprint(2, "%s: corrupt arena header: %r\n", name); return; } if(head.version != ArenaVersion4 && head.version != ArenaVersion5) fprint(2, "%s: warning: unknown arena version %d\n", name, head.version); if(len != 0 && len != head.size) fprint(2, "%s: warning: unexpected length %lld != %lld\n", name, head.size, len); if(strcmp(name, "<stdin>") != 0 && strcmp(head.name, name) != 0) fprint(2, "%s: warning: unexpected name %s\n", name, head.name); if(readblock(fd1, data1, HeadSize) < 0){ fprint(2, "%s: reading header: %r\n", name); return; } if(unpackarenahead(&head, data) < 0){ fprint(2, "%s: corrupt arena header: %r\n", name); return; } if(head.version != ArenaVersion4 && head.version != ArenaVersion5) fprint(2, "%s: warning: unknown arena version %d\n", name, head.version); if(len != 0 && len != head.size) fprint(2, "%s: warning: unexpected length %lld != %lld\n", name, head.size, len); if(strcmp(name, "<stdin>") != 0 && strcmp(head.name, name) != 0) fprint(2, "%s: warning: unexpected name %s\n", name, head.name); seek(fd, -HeadSize, 1); seek(fd1, -HeadSize, 1); if(printheader(name, &head, fd) < 0) return; /* * now we know how much to read * read everything but the last block, which is special */ e = head.size; bs = blocksize; for(n = 0; n < e; n += bs){ if(n + bs > e) bs = e - n; if(readblock(fd, data, bs) < 0){ fprint(2, "%s: read data: %r\n", name); return; } if(readblock(fd1, data1, bs) < 0){ fprint(2, "%s: read data: %r\n", name); return; } if(memcmp(data, data1, bs) != 0){ print("mismatch at %llx\n", n); for(i=0; i<bs; i+=16){ if(memcmp(data+i, data1+i, 16) != 0){ snprint(buf, sizeof buf, "%llx", n+i); print("%s ", buf); for(j=0; j<16; j++){ print(" %.2ux", data[i+j]); if(j == 7) print(" -"); } print("\n"); print("%*s ", (int)strlen(buf), ""); for(j=0; j<16; j++){ print(" %.2ux", data1[i+j]); if(j == 7) print(" -"); } print("\n"); } } } } }