main() { int i, fd; struct record rec; /* * Open the data file for writing. */ if ((fd = open("datafile", O_WRONLY | O_CREAT, 0644)) < 0) { perror("datafile"); exit(1); } /* * For each user, going backwards... */ for (i = 4; i >= 0; i--) { /* * Create the record. */ rec.uid = i; strcpy(rec.login, logins[i]); /* * Output the record. Notice we pass the * address of the structure. */ putrec(fd, i, &rec); } close(fd); exit(0); }
void main(void) { struct employee temp; getrec(&temp); putrec(&temp); }
static void global(int sense, int query) { register char* s; register int c; register Line_t* a1; if (ed.global) error(2, "recursive global not allowed"); setwide(); squeeze(ed.dol > ed.zero); compile(); if (query) newline(); else { s = getrec(ed.buffer.global, '\n', REC_SPLICE|REC_TERMINATE); if (s[0] == '\n' && !s[1]) sfputr(ed.buffer.global, "p\n", 0); } for (a1 = ed.zero; a1 <= ed.dol; a1++) { a1->offset &= ~LINE_GLOBAL; if (a1 >= ed.addr1 && a1 <= ed.addr2 && execute(a1, 0) == sense) a1->offset |= LINE_GLOBAL; } /* special case: g/.../d (avoid n^2 algorithm) */ if (!query && s[0] == 'd' && s[1] == '\n' && !s[2]) gdelete(); else { for (a1 = ed.zero; a1 <= ed.dol; a1++) { if (a1->offset & LINE_GLOBAL) { a1->offset &= ~LINE_GLOBAL; ed.dot = a1; if (query) { putrec(lineget(a1->offset)); if ((c = getchr()) == EOF) break; else if (c == '\n') continue; else if (c == '&') { newline(); if (!*(ed.global = sfstrbase(ed.buffer.query))) error(2, "no saved command"); } else { ed.peekc = c; ed.global = getrec(ed.buffer.query, '\n', REC_TERMINATE); } } else ed.global = s; commands(); a1 = ed.zero; } } } }
void main(void) { char c = 'n'; char b, sname[15]; int a = 0; static int x; do { b = '\0'; switch(c) { case 'a': getrec(&worker[x++]); c = 'n'; break; case 's': printf("\nEnter the name to search for: "); scanf("%s", sname); while(b!='\n') b = getchar(); b = '\0'; a = searchrec(worker, sname, x); if (a == -1) printf("\nRecord not found.\n"); if(a != -1) putrec(&worker[a]); c = 'n'; break; default: printf("\n\n\ta -- Add a record\n"); printf("\ts -- Search for a record\n"); printf("\tq -- Quit\n"); printf("\nEnter your selection: "); scanf("%c",&c); while(b!='\n') b = getchar(); break; } /* end of switch */ }while(c != 'q'); }
static void print(void) { register Line_t* a1; nonzero(); a1 = ed.addr1; do { if (ed.print & REG_SUB_NUMBER) sfprintf(ed.msg, "%d\t", a1 - ed.zero); putrec(lineget((a1++)->offset)); } while (a1 <= ed.addr2); ed.dot = ed.addr2; ed.print = 0; }
static void putout(void) /* produce an output record */ { colpos = 0; if (outfmt != NULL) putrec(); else if (otype == 'a') chanout(chanset); else chanout(bchanset); if (colpos && otype == 'a') putchar('\n'); if (unbuff) fflush(stdout); }
void onepass(u_char **a, int depth, long n, long sizes[], u_char *tr, FILE *fp) { size_t tsizes[NBINS+1]; u_char **bin[257], **top[256], ***bp, ***bpmax, ***tp; static int histo[256]; int *hp; int c; u_char **an, *t, **aj; u_char **ak, *r; memset(tsizes, 0, sizeof(tsizes)); depth += sizeof(TRECHEADER); an = &a[n]; for (ak = a; ak < an; ak++) { histo[c = tr[**ak]]++; tsizes[c] += ((RECHEADER *) (*ak -= depth))->length; } bin[0] = a; bpmax = bin + 256; tp = top, hp = histo; for (bp = bin; bp < bpmax; bp++) { *tp++ = *(bp + 1) = *bp + (c = *hp); *hp++ = 0; if (c <= 1) continue; } for (aj = a; aj < an; *aj = r, aj = bin[c + 1]) for (r = *aj; aj < (ak = --top[c = tr[r[depth]]]); ) swap(*ak, r, t); for (ak = a, c = 0; c < 256; c++) { an = bin[c + 1]; n = an - ak; tsizes[c] += n * sizeof(TRECHEADER); /* tell getnext how many elements in this bin, this segment. */ EWRITE(&tsizes[c], sizeof(size_t), 1, fp); sizes[c] += tsizes[c]; for (; ak < an; ++ak) putrec((RECHEADER *) *ak, fp); } }
void sbbs_t::openfile(file_t* f) { char str1[256],str2[4],str3[4],ch; int file; /************************************/ /* Increment open count in dat file */ /************************************/ sprintf(str1,"%s%s.dat",cfg.dir[f->dir]->data_dir,cfg.dir[f->dir]->code); if((file=nopen(str1,O_RDWR))==-1) { errormsg(WHERE,ERR_OPEN,str1,O_RDWR); return; } lseek(file,f->datoffset+F_OPENCOUNT,SEEK_SET); if(read(file,str2,3)!=3) { close(file); errormsg(WHERE,ERR_READ,str1,3); return; } str2[3]=0; ultoa(atoi(str2)+1,str3,10); putrec(str2,0,3,str3); lseek(file,f->datoffset+F_OPENCOUNT,SEEK_SET); if(write(file,str2,3)!=3) { close(file); errormsg(WHERE,ERR_WRITE,str1,3); return; } close(file); /**********************************/ /* Add transaction to BACKOUT.DAB */ /**********************************/ sprintf(str1,"%sbackout.dab",cfg.node_dir); if((file=nopen(str1,O_WRONLY|O_APPEND|O_CREAT))==-1) { errormsg(WHERE,ERR_OPEN,str1,O_WRONLY|O_APPEND|O_CREAT); return; } ch=BO_OPENFILE; write(file,&ch,1); /* backout type */ write(file,cfg.dir[f->dir]->code,8); /* directory code */ write(file,&f->datoffset,4); /* offset into .dat file */ write(file,&ch,BO_LEN-(1+8+4)); /* pad it */ close(file); }
//#pragma argsused short PD_style _ASK_CalRec( OpndType *lpOpnd, short ParaNum, short *OpndTop, \ short *CurState ) { dFIELDWHENACTION *p; dFILE *tdf; int i; extern WSToMT FromToStru fFrTo; if( *CurState == 0 ) { int freeMark = 0; for(i = 0; i < ParaNum; i++ ) { if( lpOpnd[i].type == STRING_TYPE && \ lpOpnd[i].length >= MAX_OPND_LENGTH ) { free((char *)*(long *)lpOpnd[i].values); freeMark = 1; } } *OpndTop -= ParaNum; if( freeMark ) return 1; return 0; } if( *CurState > 0 ) { if( xIsOpndField(&lpOpnd[0]) == 0 ) { i = xGetOpndLong(&lpOpnd[0]) - 1; if( i < 0 || i >= fFrTo.cSouDbfNum ) { ErrorSet.xERROR = iRefTabelErr; sprintf(ErrorSet.string, "calrec(%d)", i+1); return 1; } tdf = fFrTo.cSouFName[i]; if( tdf->rec_p <= 0 ) { *OpndTop -= ParaNum; return 0; } if( fFrTo.phuf != NULL ) { fseek(fFrTo.phuf, -4, SEEK_CUR); if( ( i = checkRecValid(tdf) ) != 0 ) { ErrorSet.xERROR = iFailFunCall; sprintf(ErrorSet.string, "calrec(%d),Field:%s", tdf->error, tdf->field[i-1].field); return 1; } if( toLockRec(tdf, tdf->rec_p) != 0 ) { ErrorSet.xERROR = iFailToLock; sprintf(ErrorSet.string, "calrec(%d)", -1); return 1; } fwrite(&tdf, sizeof(dFILE *), 1, fFrTo.phuf); fwrite(&(tdf->rec_p), sizeof(long), 1, fFrTo.phuf); fwrite(tdf->rec_buf, tdf->rec_len, 1, fFrTo.phuf); fwrite("\0\0\0\0", sizeof(dFILE *), 1, fFrTo.phuf); } else { if( put1rec( tdf ) == NULL ) { ErrorSet.xERROR = iFailFunCall; sprintf(ErrorSet.string, "calrec(err_fldid:%d)", \ fFrTo.cSouFName[i]->error); return 1; } } *OpndTop -= ParaNum; return 0; } ////////////////////////////////////////////////////////////////// if( fFrTo.phuf != NULL ) { tdf = ((dFIELDWHENACTION *)lpOpnd[0].oval)->pSourceDfile; if( tdf->rec_p <= 0 ) { *OpndTop -= ParaNum; return 0; } if( ( i = checkRecValid(tdf) ) != 0 ) { ErrorSet.xERROR = iFailFunCall; sprintf(ErrorSet.string, "calrec(%d),Field:%s", tdf->error, tdf->field[i-1].field); return 1; } if( toLockRec(tdf, tdf->rec_p) != 0 ) { ErrorSet.xERROR = iFailFunCall; sprintf(ErrorSet.string, "calrec(%d)", -1); return 1; } fseek(fFrTo.phuf, -4, SEEK_CUR); fwrite(&tdf, sizeof(dFILE *), 1, fFrTo.phuf); fwrite(&(tdf->rec_p), sizeof(long), 1, fFrTo.phuf); fwrite(tdf->rec_buf, tdf->rec_len, 1, fFrTo.phuf); fwrite("\0\0\0\0", sizeof(dFILE *), 1, fFrTo.phuf); } else { p = (dFIELDWHENACTION *)lpOpnd[0].oval; if( (tdf = p->pTargetDfile) == NULL ) return( 1 ); if( tdf->rec_p <= 0 ) { *OpndTop -= ParaNum; return 0; } if( tdf != p->pSourceDfile ) { /*1998.5.28 short i; unsigned short j; dFILE *sdf = p->pSourceDfile; char buf[512]; for( i = tdf->field_num-1; i >= 0; i-- ) { get_fld(tdf, i, buf); if( ltrim(buf)[0] != '\0' ) continue; if( (j = GetFldid(sdf, tdf->field[i].field)) != 0xFFFF ) { if( tdf->field[i].fieldtype == 'M' ) { sprintf(buf, "ILDIODBT.%03X", intOfThread); //read the dbt into file dbtToFile(sdf, j, buf); //put_fld from file dbtFromFile(tdf, i, buf); } else { GetField(sdf, j, buf); PutField(tdf, i, buf); } } }*/ tdf->rec_buf[0] = ' '; putrec( tdf ); } else { if( put1rec( tdf ) == NULL ) { ErrorSet.xERROR = iFailFunCall; sprintf(ErrorSet.string, "calrec(%d)", tdf->error); return 1; } } } } /* end of if */ *OpndTop -= ParaNum; /* maintain the opnd stack */ return( 0 ); } /* end of function _ASK_CalRec() */
void sbbs_t::closefile(file_t* f) { char str1[256],str2[4],str3[4],ch,*buf; int file; long length,l,offset; /************************************/ /* Decrement open count in dat file */ /************************************/ sprintf(str1,"%s%s.dat",cfg.dir[f->dir]->data_dir,cfg.dir[f->dir]->code); if((file=nopen(str1,O_RDWR))==-1) { errormsg(WHERE,ERR_OPEN,str1,O_RDWR); return; } lseek(file,f->datoffset+F_OPENCOUNT,SEEK_SET); if(read(file,str2,3)!=3) { close(file); errormsg(WHERE,ERR_READ,str1,3); return; } str2[3]=0; ch=atoi(str2); if(ch) ch--; ultoa(ch,str3,10); putrec(str2,0,3,str3); lseek(file,f->datoffset+F_OPENCOUNT,SEEK_SET); if(write(file,str2,3)!=3) { close(file); errormsg(WHERE,ERR_WRITE,str1,3); return; } close(file); /*****************************************/ /* Removing transaction from BACKOUT.DAB */ /*****************************************/ sprintf(str1,"%sbackout.dab",cfg.node_dir); if(flength(str1)<1L) /* file is not there or empty */ return; if((file=nopen(str1,O_RDONLY))==-1) { errormsg(WHERE,ERR_OPEN,str1,O_RDONLY); return; } length=filelength(file); if((buf=(char *)malloc(length))==NULL) { close(file); errormsg(WHERE,ERR_ALLOC,str1,length); return; } if(read(file,buf,length)!=length) { close(file); free(buf); errormsg(WHERE,ERR_READ,str1,length); return; } close(file); if((file=nopen(str1,O_WRONLY|O_TRUNC))==-1) { errormsg(WHERE,ERR_OPEN,str1,O_WRONLY|O_TRUNC); return; } ch=0; /* 'ch' is a 'file already removed' flag */ for(l=0;l<length;l+=BO_LEN) { /* in case file is in backout.dab > 1 */ if(!ch && buf[l]==BO_OPENFILE) { memcpy(str1,buf+l+1,8); str1[8]=0; memcpy(&offset,buf+l+9,4); if(!stricmp(str1,cfg.dir[f->dir]->code) && offset==f->datoffset) { ch=1; continue; } } write(file,buf+l,BO_LEN); } free(buf); close(file); }
uLong oz_sys_recio_write (OZ_Recio_chnex *recio_chnex, OZ_Recio_filex *recio_filex, OZ_IO_fs_writerec *writerec) { uLong atbyt, efbyt, ewbyt, sts, wlen; OZ_Dbn atblk, efblk, ewblk; /* If append mode, position to the eof point */ atblk = writerec -> atblock; atbyt = writerec -> atbyte; if (writerec -> append) { atblk = recio_filex -> efblk; atbyt = recio_filex -> efbyt; } /* If explicit position given, position there */ if (atblk != 0) { recio_chnex -> cur_vbn = atblk; recio_chnex -> cur_ofs = atbyt; } /* Extend the file if necessary to accomodate the record to be written */ ewblk = recio_chnex -> cur_vbn; /* calculate where the end-of-write will be */ ewbyt = recio_chnex -> cur_ofs + writerec -> size + writerec -> trmsize; ewblk += ewbyt / recio_filex -> diskblksize; /* normalize to disk block size for extend routine */ ewbyt %= recio_filex -> diskblksize; if (ewbyt == 0) ewblk --; ewblk = (((ewblk + recio_filex -> blockfact - 2) / recio_filex -> blockfact) * recio_filex -> blockfact) + 1; /* round up to blockfact boundary */ sts = (*(recio_filex -> call -> extend)) (recio_chnex -> chnex, recio_filex -> filex, ewblk); if (sts != OZ_SUCCESS) return (sts); /* Copy record followed by terminator to block buffer */ wlen = 0; sts = putrec (recio_chnex, recio_filex, writerec -> size, writerec -> buff, &wlen); if (sts == OZ_SUCCESS) sts = putrec (recio_chnex, recio_filex, writerec -> trmsize, writerec -> trmbuff, NULL); /* Return the actual length written */ if (writerec -> wlen != NULL) *(writerec -> wlen) = wlen; /* Set the new eof position if truncate mode or if end-of-write went past current end-of-file */ efblk = recio_filex -> efblk; efbyt = recio_filex -> efbyt; ewblk = recio_chnex -> cur_vbn; ewbyt = recio_chnex -> cur_ofs; ewblk += ewbyt / recio_filex -> diskblksize; ewbyt %= recio_filex -> diskblksize; if (writerec -> truncate || (ewblk > efblk) || ((ewblk == efblk) && (ewbyt > efbyt))) { recio_filex -> efblk = ewblk; recio_filex -> efbyt = ewbyt; (*(recio_filex -> call -> seteof)) (recio_chnex -> chnex, recio_filex -> filex, ewblk, ewbyt); } return (sts); }
static void commands(void) { register Line_t* a1; register int c; register int n; char* s; int lastsep; for (;;) { trap(); if (ed.print & (REG_SUB_LIST|REG_SUB_NUMBER|REG_SUB_PRINT)) { ed.addr1 = ed.addr2 = ed.dot; print(); } if (!ed.global) { ed.evented = 0; if (ed.prompt > 0) sfputr(ed.msg, sfstrbase(ed.buffer.prompt), -1); } if ((c = getchr()) == ',' || c == ';') { ed.given = 1; ed.addr1 = (lastsep = c) == ',' ? ed.zero + 1 : ed.dot; a1 = ed.dol; c = getchr(); } else { ed.addr1 = 0; ed.peekc = c; c = '\n'; for (;;) { lastsep = c; a1 = address(); c = getchr(); if (c != ',' && c != ';') break; if (lastsep == ',') error(2, "invalid address"); if (!a1) { a1 = ed.zero + 1; if (a1 > ed.dol) a1--; } ed.addr1 = a1; if (c == ';') ed.dot = a1; } if (lastsep != '\n' && !a1) a1 = ed.dol; } if (!(ed.addr2 = a1)) { ed.given = 0; ed.addr2 = ed.dot; } else ed.given = 1; if (!ed.addr1) ed.addr1 = ed.addr2; switch (c) { case 'a': add(0); continue; case 'c': nonzero(); newline(); rdelete(ed.addr1, ed.addr2); append(getline, ed.addr1 - 1, NiL); continue; case 'd': nonzero(); newline(); rdelete(ed.addr1, ed.addr2); continue; case 'E': ed.modified = 0; c = 'e'; /*FALLTHROUGH*/ case 'e': setnoaddr(); if (ed.verbose && ed.modified) { ed.modified = 0; error(2, "modified data not written"); } /*FALLTHROUGH*/ case 'r': filename(c); setwide(); squeeze(0); c = ed.zero != ed.dol; append(getfile, ed.addr2, NiL); ed.modified = c; exfile(); continue; case 'f': setnoaddr(); filename(c); putrec(sfstrbase(ed.buffer.file)); continue; case 'G': global(1, 1); continue; case 'g': global(1, 0); continue; case 'H': ed.help = !ed.help; /*FALLTHROUGH*/ case 'h': setnoaddr(); newline(); if (ed.help || c == 'h') sfputr(ed.msg, sfstrbase(ed.buffer.help), '\n'); continue; case 'i': add(-1); continue; case 'j': if (!ed.given) ed.addr2++; newline(); join(); continue; case 'k': nonzero(); if ((c = getchr()) == EOF || (c -= MARK_MIN) < 0 || c >= elementsof(ed.marks)) error(2, "invalid mark"); newline(); ed.addr2->offset |= LINE_MARKED; ed.marks[c] = ed.addr2->offset & ~LINE_GLOBAL; ed.marked = 1; continue; case 'm': move(0); continue; case 'n': ed.print |= REG_SUB_NUMBER; newline(); print(); continue; case '\n': if (!a1) { a1 = ed.dot + 1; ed.addr2 = a1; ed.addr1 = a1; } if (lastsep == ';') ed.addr1 = a1; print(); continue; case 'l': ed.print |= REG_SUB_LIST; /*FALLTHROUGH*/ case 'p': newline(); print(); continue; case 'P': setnoaddr(); s = getrec(ed.buffer.line, '\n', 0); if (*s || !(ed.prompt = -ed.prompt) && (s = "*")) { sfstrseek(ed.buffer.prompt, 0, SEEK_SET); sfputr(ed.buffer.prompt, s, 0); ed.prompt = 1; } continue; case 'Q': ed.modified = 0; /*FALLTHROUGH*/ case 'q': setnoaddr(); newline(); quit(0); continue; case 'S': setnoaddr(); newline(); s = strchr(usage, '\n') + 5; sfprintf(ed.msg, "file=\"%s\"%s%s%s prompt=\"%s\" tmp=%lu%s event=%lu version=\"%-.*s\"\n", sfstrbase(ed.buffer.file), ed.modified ? " modified" : "", ed.help ? " help" : "", ed.verbose ? " verbose" : "", sfstrbase(ed.buffer.prompt), ed.tmpoff, ed.tmpoff > BLOCK_TMP ? "[file]" : "", ed.event, strchr(s, '\n') - s, s); continue; case 's': nonzero(); substitute(ed.global != 0); continue; case 't': move(1); continue; case 'u': setnoaddr(); newline(); undo(); continue; case 'V': global(0, 1); continue; case 'v': global(0, 0); continue; case 'W': case 'w': setwide(); squeeze(ed.dol > ed.zero); if ((n = getchr()) != 'q' && n != 'Q') { ed.peekc = n; n = 0; } filename(c); if (ed.dol > ed.zero) putfile(); exfile(); if (n == 'Q' || ed.addr1 <= ed.zero + 1 && ed.addr2 == ed.dol) ed.modified = 0; if (n) quit(0); continue; case 'z': nonzero(); page(); continue; case '=': setwide(); squeeze(0); newline(); sfprintf(ed.msg, "%d\n", ed.addr2 - ed.zero); continue; case '!': if (ed.restricted) error(2, "%c: restricted command", c); shell(); continue; case '#': setnoaddr(); getrec(ed.buffer.line, '\n', REC_IGNORE); continue; case EOF: return; } error(2, "unknown command"); } }
static void shell(void) { register char* s; register char* f = 0; register int c; if (ed.given) squeeze(ed.dol > ed.zero); s = getrec(ed.buffer.line, '\n', 0); if (s[0] == '!' && !s[1]) { if (!*sfstrbase(ed.buffer.shell)) error(2, "no saved shell command"); f = sfstrbase(ed.buffer.file); } else if (!s[0]) error(2, "empty shell command"); else SWP(ed.buffer.shell, ed.buffer.line); s = sfstrbase(ed.buffer.shell); sfstrseek(ed.buffer.line, 0, SEEK_SET); sfputc(ed.buffer.line, '!'); while (c = *s++) { if (c == '\\') { if (*s != '%') sfputc(ed.buffer.line, c); sfputc(ed.buffer.line, *s++); } else if (c == '%') sfputr(ed.buffer.line, f = sfstrbase(ed.buffer.file), -1); else sfputc(ed.buffer.line, c); } if (ed.given) { if (!ed.tmpfile && !(ed.tmpfile = pathtemp(NiL, 0, NiL, error_info.id, NiL))) error(ERROR_SYSTEM|2, "cannot generate temp file name"); if (!(ed.iop = sfopen(NiL, ed.tmpfile, "w"))) error(ERROR_SYSTEM|2, "%s: cannot create temp file", ed.tmpfile); error_info.file = ed.tmpfile; if (ed.dol > ed.zero) putfile(); exfile(); ed.bytes = 0; ed.lines = 0; sfprintf(ed.buffer.line, " < %s", ed.tmpfile); if (!(s = sfstruse(ed.buffer.line))) error(ERROR_SYSTEM|3, "out of space"); if (!(ed.iop = sfpopen(NiL, s + 1, "r"))) error(ERROR_SYSTEM|2, "%s: cannot execute shell command", s); error_info.file = s; rdelete(ed.addr1, ed.addr2); append(getfile, ed.dot, NiL); exfile(); remove(ed.tmpfile); } else { if (!(s = sfstruse(ed.buffer.line))) error(ERROR_SYSTEM|3, "out of space"); s++; if (f) putrec(s); if (!(ed.iop = sfpopen(NiL, s, ""))) error(ERROR_SYSTEM|2, "%s: cannot execute shell command", s); if (sfclose(ed.iop)) { ed.iop = 0; error(ERROR_SYSTEM|2, "%s: shell command exit error", s); } if (ed.verbose) putrec("!"); } }
void sbbs_t::sif(char *fname, char *answers, long len) { char str[256],tmplt[256],*buf; uint t,max,min,mode,cr; int file; long length,l=0,m,top,a=0; sprintf(str,"%s%s.sif",cfg.text_dir,fname); if((file=nopen(str,O_RDONLY))==-1) { errormsg(WHERE,ERR_OPEN,str,O_RDONLY); answers[0]=0; return; } length=filelength(file); if((buf=(char *)malloc(length))==0) { close(file); errormsg(WHERE,ERR_ALLOC,str,length); answers[0]=0; return; } if(lread(file,buf,length)!=length) { close(file); errormsg(WHERE,ERR_READ,str,length); answers[0]=0; return; } close(file); while(l<length && online) { mode=min=max=t=cr=0; top=l; while(l<length && buf[l++]!=STX); for(m=l;m<length;m++) if(buf[m]==ETX || !buf[m]) { buf[m]=0; break; } if(l>=length) break; if(online==ON_REMOTE) { rioctl(IOCM|ABORT); rioctl(IOCS|ABORT); } putmsg(buf+l,P_SAVEATR); m++; if(toupper(buf[m])!='C' && toupper(buf[m])!='S') continue; SYNC; if(online==ON_REMOTE) rioctl(IOSM|ABORT); if(a>=len) { errormsg(WHERE,ERR_LEN,fname,len); break; } if((buf[m]&0xdf)=='C') { if((buf[m+1]&0xdf)=='U') { /* Uppercase only */ mode|=K_UPPER; m++; } else if((buf[m+1]&0xdf)=='N') { /* Numbers only */ mode|=K_NUMBER; m++; } if((buf[m+1]&0xdf)=='L') { /* Draw line */ if(term_supports(COLOR)) attr(cfg.color[clr_inputline]); else attr(BLACK|BG_LIGHTGRAY); bputs(" \b"); m++; } if((buf[m+1]&0xdf)=='R') { /* Add CRLF */ cr=1; m++; } if(buf[m+1]=='"') { m+=2; for(l=m;l<length;l++) if(buf[l]=='"') { buf[l]=0; break; } answers[a++]=(char)getkeys((char *)buf+m,0); } else { answers[a]=getkey(mode); outchar(answers[a++]); attr(LIGHTGRAY); CRLF; } if(cr) { answers[a++]=CR; answers[a++]=LF; } } else if((buf[m]&0xdf)=='S') { /* String */ if((buf[m+1]&0xdf)=='U') { /* Uppercase only */ mode|=K_UPPER; m++; } else if((buf[m+1]&0xdf)=='F') { /* Force Upper/Lowr case */ mode|=K_UPRLWR; m++; } else if((buf[m+1]&0xdf)=='N') { /* Numbers only */ mode|=K_NUMBER; m++; } if((buf[m+1]&0xdf)=='L') { /* Draw line */ mode|=K_LINE; m++; } if((buf[m+1]&0xdf)=='R') { /* Add CRLF */ cr=1; m++; } if(isdigit(buf[m+1])) { max=buf[++m]&0xf; if(isdigit(buf[m+1])) max=max*10+(buf[++m]&0xf); } if(buf[m+1]=='.' && isdigit(buf[m+2])) { m++; min=buf[++m]&0xf; if(isdigit(buf[m+1])) min=min*10+(buf[++m]&0xf); } if(buf[m+1]=='"') { m++; mode&=~K_NUMBER; while(buf[++m]!='"' && t<80) tmplt[t++]=buf[m]; tmplt[t]=0; max=strlen(tmplt); } if(t) { if(gettmplt(str,tmplt,mode)<min) { l=top; continue; } } else { if(!max) continue; if(getstr(str,max,mode)<min) { l=top; continue; } } if(!cr) { for(cr=0;str[cr];cr++) answers[a+cr]=str[cr]; while(cr<max) answers[a+cr++]=ETX; a+=max; } else { putrec(answers,a,max,str); putrec(answers,a+max,2,crlf); a+=max+2; } } } answers[a]=0; free((char *)buf); }
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); }
BOOL DLLCALL putfiledat(scfg_t* cfg, file_t* f) { char buf[F_LEN+1],str[MAX_PATH+1],tmp[128]; int file; long length; putrec(buf,F_CDT,LEN_FCDT,ultoa(f->cdt,tmp,10)); putrec(buf,F_DESC,LEN_FDESC,f->desc); putrec(buf,F_DESC+LEN_FDESC,2,crlf); putrec(buf,F_ULER,LEN_ALIAS+5,f->uler); putrec(buf,F_ULER+LEN_ALIAS+5,2,crlf); putrec(buf,F_TIMESDLED,5,ultoa(f->timesdled,tmp,10)); putrec(buf,F_TIMESDLED+5,2,crlf); putrec(buf,F_OPENCOUNT,3,ultoa(f->opencount,tmp,10)); putrec(buf,F_OPENCOUNT+3,2,crlf); buf[F_MISC]=(char)f->misc+' '; putrec(buf,F_ALTPATH,2,hexplus(f->altpath,tmp)); putrec(buf,F_ALTPATH+2,2,crlf); 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); } length=(long)filelength(file); if(length%F_LEN) { close(file); return(FALSE); } if(f->datoffset>length) { close(file); return(FALSE); } lseek(file,f->datoffset,SEEK_SET); if(write(file,buf,F_LEN)!=F_LEN) { close(file); return(FALSE); } length=(long)filelength(file); close(file); if(length%F_LEN) { return(FALSE); } return(TRUE); }