static int pump_chunk(FILE *fh, int ofd) { int chunk_started = 0; do { char line[1024]; char *rval; rval = fgets(line, 1024, fh); if ( rval == NULL ) { if ( feof(fh) ) { /* Whoops, connection lost */ if ( chunk_started ) { ERROR("EOF during chunk!\n"); lwrite(ofd, "Unfinished chunk!\n"); lwrite(ofd, CHUNK_END_MARKER"\n"); } /* else normal end of output */ return 1; } ERROR("fgets() failed: %s\n", strerror(errno)); return 1; } if ( strcmp(line, "FLUSH\n") == 0 ) break; lwrite(ofd, line); if ( strcmp(line, CHUNK_END_MARKER"\n") == 0 ) break; } while ( 1 ); return 0; }
/* * writeboard() Function to write the scoreboard from readboard()'s buffer * * returns -1 if unable to write the scoreboard, returns 0 if all is OK */ writeboard() { set_score_output(); if (lcreat(scorefile)<0) { lprcat("Can't write scoreboard\n"); lflush(); return(-1); } lwrite((char*)sco,sizeof(sco)); lwrite((char*)winr,sizeof(winr)); lwclose(); lcreat((char*)0); return(0); }
int main() { Value *result; init(); // List manipulation. defnative(mksym("CONS"), native_cons); defnative(mksym("CAR"), native_car); defnative(mksym("CDR"), native_cdr); // Arithmetic. defnative(mksym("PLUS"), native_plus); defnative(mksym("MINUS"), native_minus); defnative(mksym("MUL"), native_mul); defnative(mksym("DIV"), native_div); // Miscellaneous. defnative(mksym("EVAL"), native_eval); defglobal(mksym("NIL"), LISP_NIL); while (!feof(stdin)) { setjmp(toplevel_escape); printf("> "); result = eval(lread(), global_env); printf("\n"); lwrite(result); printf("\n"); } return 0; }
BOOL DLLCALL removefiledat(scfg_t* cfg, file_t* f) { char c,str[MAX_PATH+1],ixbname[12],*ixbbuf,fname[13]; int i,file; long l,length; SAFECOPY(fname,f->name); for(i=8;i<12;i++) /* Turn FILENAME.EXT into FILENAMEEXT */ fname[i]=fname[i+1]; SAFEPRINTF2(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) { return(FALSE); } length=(long)filelength(file); if(!length) { close(file); return(FALSE); } if((ixbbuf=(char *)malloc(length))==0) { close(file); return(FALSE); } if(lread(file,ixbbuf,length)!=length) { close(file); free((char *)ixbbuf); return(FALSE); } close(file); if((file=sopen(str,O_WRONLY|O_TRUNC|O_BINARY,SH_DENYRW))==-1) { return(FALSE); } for(l=0;l<length;l+=F_IXBSIZE) { for(i=0;i<11;i++) ixbname[i]=ixbbuf[l+i]; ixbname[i]=0; if(stricmp(ixbname,fname)) if(lwrite(file,&ixbbuf[l],F_IXBSIZE)!=F_IXBSIZE) { close(file); free((char *)ixbbuf); return(FALSE); } } free((char *)ixbbuf); close(file); SAFEPRINTF2(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=sopen(str,O_WRONLY|O_BINARY,SH_DENYRW))==-1) { return(FALSE); } lseek(file,f->datoffset,SEEK_SET); c=ETX; /* If first char of record is ETX, record is unused */ if(write(file,&c,1)!=1) { /* So write a D_T on the first byte of the record */ close(file); return(FALSE); } close(file); if(f->dir==cfg->user_dir) /* remove file from index */ rmuserxfers(cfg,0,0,f->name); return(TRUE); }
void lwritepair(Value *pair) { printf("("); for (; !LISP_NILP(pair); pair = CDR(pair)) { lwrite(CAR(pair)); if (!LISP_NILP(CDR(pair))) { if (gettype(CDR(pair)) == T_PAIR) { printf(" "); } else { // Handle improper lists printf(" . "); lwrite(CDR(pair)); break; } } } printf(")"); }
/* * writeboard() Function to write the scoreboard from readboard()'s buffer * * returns -1 if unable to write the scoreboard, returns 0 if all is OK */ static int writeboard(void) { int i; set_score_output(); if (gid != egid) setegid(egid); i = lcreat(scorefile); if (gid != egid) setegid(gid); if (i < 0) { lprcat("Can't write scoreboard\n"); lflush(); return (-1); } lwrite((char *) sco, sizeof(sco)); lwrite((char *) winr, sizeof(winr)); lwclose(); lcreat((char *) 0); return (0); }
void died(int x) { int f, win; char ch; const char *mod; time_t zzz; if (c[LIFEPROT] > 0) { /* if life protection */ switch ((x > 0) ? x : -x) { case 256: case 257: case 262: case 263: case 265: case 266: case 267: case 268: case 269: case 271: case 282: case 284: case 285: case 300: goto invalid; /* can't be saved */ }; --c[LIFEPROT]; c[HP] = 1; --c[CONSTITUTION]; cursors(); lprcat("\nYou feel wiiieeeeerrrrrd all over! "); emit_beep(); lflush(); sleep(4); return; /* only case where died() returns */ } invalid: clearvt100(); lflush(); f = 0; if (ckpflag) unlink(ckpfile);/* remove checkpoint file if used */ if (x < 0) { f++; x = -x; } /* if we are not to display the scores */ if ((x == 300) || (x == 257)) exit(0); /* for quick exit or saved game */ if (x == 263) win = 1; else win = 0; c[GOLD] += c[BANKACCOUNT]; c[BANKACCOUNT] = 0; /* now enter the player at the end of the scoreboard */ newscore(c[GOLD], logname, x, win); diedsub(x); /* print out the score line */ lflush(); set_score_output(); if ((wizard == 0) && (c[GOLD] > 0)) { /* wizards can't score */ #ifndef NOLOG if (gid != egid) setegid(egid); if (lappend(logfile) < 0) { /* append to file */ if (lcreat(logfile) < 0) { /* and can't create new * log file */ lcreat((char *) 0); lprcat("\nCan't open record file: I can't post your score.\n"); sncbr(); resetscroll(); lflush(); exit(0); } if (gid != egid) setegid(egid); chmod(logfile, 0660); if (gid != egid) setegid(gid); } if (gid != egid) setegid(gid); strcpy(logg.who, loginname); logg.score = c[GOLD]; logg.diff = c[HARDGAME]; if (x < 256) { ch = *monster[x].name; if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') mod = "an"; else mod = "a"; snprintf(logg.what, sizeof(logg.what), "killed by %s %s", mod, monster[x].name); } else snprintf(logg.what, sizeof(logg.what), "%s", whydead[x - 256]); logg.cavelev = level; time(&zzz); /* get CPU time -- write out score info */ logg.diedtime = zzz; #ifdef EXTRA times(&cputime);/* get CPU time -- write out score info */ logg.cputime = i = (cputime.tms_utime + cputime.tms_stime) / 60 + c[CPUTIME]; logg.lev = c[LEVEL]; logg.ac = c[AC]; logg.hpmax = c[HPMAX]; logg.hp = c[HP]; logg.elapsedtime = (zzz - initialtime + 59) / 60; logg.usage = (10000 * i) / (zzz - initialtime); logg.bytin = c[BYTESIN]; logg.bytout = c[BYTESOUT]; logg.moves = c[MOVESMADE]; logg.spused = c[SPELLSCAST]; logg.killed = c[MONSTKILLED]; #endif lwrite((char *) &logg, sizeof(struct log_fmt)); lwclose(); #endif /* NOLOG */ /* * now for the scoreboard maintenance -- not for a suspended * game */ if (x != 257) { if (sortboard()) { set_score_output(); scorerror = writeboard(); } } } if ((x == 256) || (x == 257) || (f != 0)) exit(0); if (scorerror == 0) showscores(); /* if we updated the scoreboard */ if (x == 263) mailbill(); exit(0); }
void sbbs_t::resort(uint dirnum) { char str[25],ixbfname[128],datfname[128],exbfname[128],txbfname[128] ,ext[512],nulbuf[512]; char tmp[512]; uchar* ixbbuf, *datbuf; uchar* ixbptr[MAX_FILES]; int ixbfile,datfile,exbfile,txbfile,i,j; long ixblen,datlen,offset,newoffset,l; memset(nulbuf,0,512); bprintf(text[ResortLineFmt],cfg.lib[cfg.dir[dirnum]->lib]->sname,cfg.dir[dirnum]->sname); sprintf(ixbfname,"%s%s.ixb",cfg.dir[dirnum]->data_dir,cfg.dir[dirnum]->code); sprintf(datfname,"%s%s.dat",cfg.dir[dirnum]->data_dir,cfg.dir[dirnum]->code); sprintf(exbfname,"%s%s.exb",cfg.dir[dirnum]->data_dir,cfg.dir[dirnum]->code); sprintf(txbfname,"%s%s.txb",cfg.dir[dirnum]->data_dir,cfg.dir[dirnum]->code); if(flength(ixbfname)<1L || flength(datfname)<1L) { remove(exbfname); remove(txbfname); remove(ixbfname); remove(datfname); bputs(text[ResortEmptyDir]); return; } bputs(text[Sorting]); if((ixbfile=nopen(ixbfname,O_RDONLY))==-1) { errormsg(WHERE,ERR_OPEN,ixbfname,O_RDONLY); return; } if((datfile=nopen(datfname,O_RDONLY))==-1) { close(ixbfile); errormsg(WHERE,ERR_OPEN,datfname,O_RDONLY); return; } ixblen=(long)filelength(ixbfile); datlen=(long)filelength(datfile); if((ixbbuf=(uchar *)malloc(ixblen))==NULL) { close(ixbfile); close(datfile); errormsg(WHERE,ERR_ALLOC,ixbfname,ixblen); return; } if((datbuf=(uchar *)malloc(datlen))==NULL) { close(ixbfile); close(datfile); free((char *)ixbbuf); errormsg(WHERE,ERR_ALLOC,datfname,datlen); return; } if(lread(ixbfile,ixbbuf,ixblen)!=ixblen) { close(ixbfile); close(datfile); free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_READ,ixbfname,ixblen); return; } if(lread(datfile,datbuf,datlen)!=datlen) { close(ixbfile); close(datfile); free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_READ,datfname,datlen); return; } close(ixbfile); close(datfile); if((ixbfile=nopen(ixbfname,O_WRONLY|O_TRUNC))==-1) { free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_OPEN,ixbfname,O_WRONLY|O_TRUNC); return; } if((datfile=nopen(datfname,O_WRONLY|O_TRUNC))==-1) { close(ixbfile); free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_OPEN,datfname,O_WRONLY|O_TRUNC); return; } for(l=0,i=0;l<ixblen && i<MAX_FILES;l+=F_IXBSIZE,i++) ixbptr[i]=ixbbuf+l; switch(cfg.dir[dirnum]->sort) { case SORT_NAME_A: qsort((void *)ixbptr,ixblen/F_IXBSIZE,sizeof(ixbptr[0]) ,(int(*)(const void*, const void*))fnamecmp_a); break; case SORT_NAME_D: qsort((void *)ixbptr,ixblen/F_IXBSIZE,sizeof(ixbptr[0]) ,(int(*)(const void*, const void*))fnamecmp_d); break; case SORT_DATE_A: qsort((void *)ixbptr,ixblen/F_IXBSIZE,sizeof(ixbptr[0]) ,(int(*)(const void*, const void*))fdatecmp_a); break; case SORT_DATE_D: qsort((void *)ixbptr,ixblen/F_IXBSIZE,sizeof(ixbptr[0]) ,(int(*)(const void*, const void*))fdatecmp_d); break; } if((exbfile=nopen(exbfname,O_RDWR|O_CREAT))==-1) { close(ixbfile); close(datfile); free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_OPEN,exbfname,O_RDWR|O_CREAT); return; } if((txbfile=nopen(txbfname,O_RDWR|O_CREAT))==-1) { close(exbfile); close(datfile); close(exbfile); free((char *)ixbbuf); free((char *)datbuf); errormsg(WHERE,ERR_OPEN,txbfname,O_RDWR|O_CREAT); return; } for(i=0;i<ixblen/F_IXBSIZE;i++) { offset=ixbptr[i][11]|((long)ixbptr[i][12]<<8)|((long)ixbptr[i][13]<<16); lwrite(datfile,&datbuf[offset],F_LEN); newoffset=(ulong)i*(ulong)F_LEN; j=datbuf[offset+F_MISC]; /* misc bits */ if(j!=ETX) j-=' '; if(j&FM_EXTDESC) { /* extended description */ lseek(exbfile,(offset/F_LEN)*512L,SEEK_SET); memset(ext,0,512); read(exbfile,ext,512); while(filelength(txbfile)<(newoffset/F_LEN)*512L) { // lseek(txbfile,0L,SEEK_END); write(txbfile,nulbuf,512); } lseek(txbfile,(newoffset/F_LEN)*512L,SEEK_SET); write(txbfile,ext,512); } str[0]=newoffset&0xff; /* Get offset within DAT file for IXB file */ str[1]=(newoffset>>8)&0xff; str[2]=(newoffset>>16)&0xff; lwrite(ixbfile,ixbptr[i],11); /* filename */ lwrite(ixbfile,str,3); /* offset */ lwrite(ixbfile,ixbptr[i]+14,8); } /* upload and download times */ close(exbfile); close(txbfile); close(ixbfile); close(datfile); remove(exbfname); rename(txbfname,exbfname); if(!flength(exbfname)) remove(exbfname); free((char *)ixbbuf); free((char *)datbuf); if(ixblen/F_IXBSIZE==datlen/F_LEN) bputs(text[Sorted]); else bprintf(text[Compressed] ,(uint)((datlen/F_LEN)-(ixblen/F_IXBSIZE)) ,ultoac(((datlen/F_LEN)-(ixblen/F_IXBSIZE))*F_LEN,tmp)); }
void writeln(FILE* file, int indentLevel, const char* str) { writeIndent(file, indentLevel); lwrite(file, str); lwrite(file, "\n"); }
xtrysend() { int i; dem_open(dfname); /*open spider connection.*/ if((dfb = fopen(dfname, "r")) == NULL){ if(LDIRNAM < (i = sizeof(baddf)-1)){ strncpy(baddf, dfname, i); baddf[i] = '\0'; baddf[LDIRNAM] = 'b'; link(dfname, baddf); } unlink(dfname); retcode = 0; trouble("Can't read %s.", dfname); } getowner(dfname); /*RBB*/ mesp = message; *mesp = 0; while (getline()) switch (line[0]) { case 'S': get_snumb(); /*get snumb for GCOS.*/ continue; case 'B': if(sascii(0)) trouble("Can't send %s.", &line[1]); continue; case 'F': if(sascii(1)) trouble("Can't send %s.", &line[1]); continue; case 'I': /*mail back $IDENT card. MRW*/ mesp = copline(&line[1], linel-1, mesp); case 'L': lwrite(); /*write a literal line.*/ continue; case 'M': continue; case 'N': /*mail back file name. MRW*/ copline(&line[1], linel-1, mailfname); continue; case 'Q': /*additional text to mail back*/ if(mesp+linel <= message+MXMESS) mesp = copline(&line[1], linel-1, mesp); case 'U': continue; } /* * Second pass. * Unlink files and send mail. */ alarm(0); fseek(dfb, (long)0, 0); while (getline()) switch (line[0]) { default: continue; case 'U': unlink(&line[1]); continue; case 'M': sendmail(); continue; } FCLOSE(dfb); dem_close(); /*close connection to spider.*/ unlink(dfname); retcode = 0; trouble("OK: %-5s %-7s %-8s", snumb, fowner, dfname+LDIRNAM); /*RBB*/ }
BOOL DLLCALL addfiledat(scfg_t* cfg, file_t* f) { char str[MAX_PATH+1],fname[13],c,fdat[F_LEN+1]; char tmp[128]; uchar *ixbbuf,idx[3]; int i,file; long l,length; time_t now; time_t uldate; /************************/ /* Add data to DAT File */ /************************/ SAFEPRINTF2(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=sopen(str,O_RDWR|O_BINARY|O_CREAT,SH_DENYRW,DEFFILEMODE))==-1) { return(FALSE); } length=(long)filelength(file); if(length==0L) l=0L; else { if(length%F_LEN) { close(file); return(FALSE); } for(l=0;l<length;l+=F_LEN) { /* Find empty slot */ lseek(file,l,SEEK_SET); read(file,&c,1); if(c==ETX) break; } if(l/F_LEN>=MAX_FILES) { close(file); return(FALSE); } } putrec(fdat,F_CDT,LEN_FCDT,ultoa(f->cdt,tmp,10)); putrec(fdat,F_DESC,LEN_FDESC,f->desc); putrec(fdat,F_DESC+LEN_FDESC,2,crlf); putrec(fdat,F_ULER,LEN_ALIAS+5,f->uler); putrec(fdat,F_ULER+LEN_ALIAS+5,2,crlf); putrec(fdat,F_TIMESDLED,5,ultoa(f->timesdled,tmp,10)); putrec(fdat,F_TIMESDLED+5,2,crlf); putrec(fdat,F_OPENCOUNT,3,ultoa(f->opencount,tmp,10)); putrec(fdat,F_OPENCOUNT+3,2,crlf); fdat[F_MISC]=(char)f->misc+' '; putrec(fdat,F_ALTPATH,2,hexplus(f->altpath,tmp)); putrec(fdat,F_ALTPATH+2,2,crlf); f->datoffset=l; idx[0]=(uchar)(l&0xff); /* Get offset within DAT file for IXB file */ idx[1]=(uchar)((l>>8)&0xff); idx[2]=(uchar)((l>>16)&0xff); lseek(file,l,SEEK_SET); if(write(file,fdat,F_LEN)!=F_LEN) { close(file); return(FALSE); } length=(long)filelength(file); close(file); if(length%F_LEN) { return(FALSE); } /*******************************************/ /* Update last upload date/time stamp file */ /*******************************************/ SAFEPRINTF2(str,"%s%s.dab",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=sopen(str,O_WRONLY|O_CREAT|O_BINARY,SH_DENYRW,DEFFILEMODE))!=-1) { now=time(NULL); /* TODO: 32-bit *or* LE required */ write(file,&now,4); close(file); } /************************/ /* Add data to IXB File */ /************************/ SAFECOPY(fname,f->name); for(i=8;i<12;i++) /* Turn FILENAME.EXT into FILENAMEEXT */ fname[i]=fname[i+1]; SAFEPRINTF2(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code); if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYRW,DEFFILEMODE))==-1) { return(FALSE); } length=(long)filelength(file); if(length) { /* IXB file isn't empty */ if(length%F_IXBSIZE) { close(file); return(FALSE); } if((ixbbuf=(uchar *)malloc(length))==NULL) { close(file); return(FALSE); } if(lread(file,ixbbuf,length)!=length) { close(file); free((char *)ixbbuf); return(FALSE); } /************************************************/ /* Sort by Name or Date, Assending or Decending */ /************************************************/ if(cfg->dir[f->dir]->sort==SORT_NAME_A || cfg->dir[f->dir]->sort==SORT_NAME_D) { for(l=0;l<length;l+=F_IXBSIZE) { for(i=0;i<12 && toupper(fname[i])==toupper(ixbbuf[l+i]);i++); if(i==12) { /* file already in directory index */ close(file); free((char *)ixbbuf); return(FALSE); } if(cfg->dir[f->dir]->sort==SORT_NAME_A && toupper(fname[i])<toupper(ixbbuf[l+i])) break; if(cfg->dir[f->dir]->sort==SORT_NAME_D && toupper(fname[i])>toupper(ixbbuf[l+i])) break; } } else { /* sort by date */ for(l=0;l<length;l+=F_IXBSIZE) { uldate=(ixbbuf[l+14]|((long)ixbbuf[l+15]<<8) |((long)ixbbuf[l+16]<<16)|((long)ixbbuf[l+17]<<24)); if(cfg->dir[f->dir]->sort==SORT_DATE_A && f->dateuled<uldate) break; if(cfg->dir[f->dir]->sort==SORT_DATE_D && f->dateuled>uldate) break; } } lseek(file,l,SEEK_SET); if(write(file,fname,11)!=11) { /* Write filename to IXB file */ close(file); free((char *)ixbbuf); return(FALSE); } if(write(file,idx,3)!=3) { /* Write DAT offset into IXB file */ close(file); free((char *)ixbbuf); return(FALSE); } write(file,&f->dateuled,4); write(file,&f->datedled,4); /* Write 0 for datedled */ if(lwrite(file,&ixbbuf[l],length-l)!=length-l) { /* Write rest of IXB */ close(file); free((char *)ixbbuf); return(FALSE); } free((char *)ixbbuf); } else { /* IXB file is empty... No files */ if(write(file,fname,11)!=11) { /* Write filename it IXB file */ close(file); return(FALSE); } if(write(file,idx,3)!=3) { /* Write DAT offset into IXB file */ close(file); return(FALSE); } write(file,&f->dateuled,4); write(file,&f->datedled,4); } length=(long)filelength(file); close(file); return(TRUE); }
void writer::lwriteLine() { std::string l( 80, 0x5F ); // horizontal line lwrite( l.c_str() ); }