void Connection::request( const char* method, const char* url, const char* headers[], const unsigned char* body, int bodysize ) { bool gotcontentlength = false; // already in headers? // check headers for content-length // TODO: check for "Host" and "Accept-Encoding" too // and avoid adding them ourselves in putrequest() if( headers ) { const char** h = headers; while( *h ) { const char* name = *h++; const char* value = *h++; assert( value != 0 ); // name with no value! if( 0==_stricmp( name, "content-length" ) ) gotcontentlength = true; } } putrequest( method, url ); if( body && !gotcontentlength ) putheader( "Content-Length", bodysize ); if( headers ) { const char** h = headers; while( *h ) { const char* name = *h++; const char* value = *h++; putheader( name, value ); } } endheaders(); if( body ) send( body, bodysize ); }
void Connection::putrequest( const char* method, const char* url ) { if( m_State != IDLE ) throw Wobbly( "Request already issued" ); m_State = REQ_STARTED; char req[ 512 ]; sprintf( req, "%s %s HTTP/1.1", method, url ); m_Buffer.push_back( req ); putheader( "Host", m_Host.c_str() ); // required for HTTP1.1 // don't want any fancy encodings please putheader("Accept-Encoding", "identity"); // Push a new response onto the queue Response *r = new Response( method, *this ); m_Outstanding.push_back( r ); }
static void WAV_Exit(void) { VC_Exit(); /* write in the actual sizes now */ if(wavout) { putheader(); _mm_delete_file_writer(wavout); fclose(wavfile); wavfile=NULL;wavout=NULL; } MikMod_free(audiobuffer); audiobuffer=NULL; }
static int WAV_Init(void) { #if (MIKMOD_UNIX) if (!MD_Access(filename?filename:FILENAME)) { _mm_errno=MMERR_OPENING_FILE; return 1; } #endif if(!(wavfile=fopen(filename?filename:FILENAME,"wb"))) { _mm_errno=MMERR_OPENING_FILE; return 1; } if(!(wavout=_mm_new_file_writer (wavfile))) { fclose(wavfile);unlink(filename?filename:FILENAME); wavfile=NULL; return 1; } if(!(audiobuffer=(SBYTE*)MikMod_malloc(BUFFERSIZE))) { _mm_delete_file_writer(wavout); fclose(wavfile);unlink(filename?filename:FILENAME); wavfile=NULL;wavout=NULL; return 1; } md_mode|=DMODE_SOFT_MUSIC|DMODE_SOFT_SNDFX; if (VC_Init()) { _mm_delete_file_writer(wavout); fclose(wavfile);unlink(filename?filename:FILENAME); wavfile=NULL;wavout=NULL; return 1; } dumpsize=0; putheader(); return 0; }
/* * Do the function */ MAINENT main(int argc, uchar * *argv) { /* Parse arguments */ parseargs(argc, argv); /* Open and check input file */ openpfm(); /* Make output file name and open */ openafm(); /* Put out header information */ putheader(); /* Put out character table */ putchartab(); /* Put out kerning table */ if (pfm->kernpairs) { putkerntab((KERN *)(buffer+pfm->kernpairs+2), *(ushort *)(buffer+pfm->kernpairs)); } if (pfm->kerntrack) { /* rjl */ fprintf(stderr, "Ignoring track kern table\n"); } /* Put out trailer line */ puttrailer(); /* Cleanup */ if (buffer) free(buffer); fclose(inf); fclose(outf); return 0; }
/* -------------------------------------------------------------------- */ BOOL getText(void) { char *buf; if (!gl_user.expert) { nextblurb("entry", &(cfg.cnt.ecount), 1); outFlag = OUTOK; doCR(); mPrintf(" You may enter up to %d characters.", cfg.maxtext); mPrintf("\n Please enter message. Use an empty line to end."); } outFlag = IMPERVIOUS; doCR(); putheader(); doCR(); outFlag = OUTOK; buf = msgBuf->mbtext; /* do text entry */ return (BOOL) editBuf(buf,cfg.maxtext-1); }
void Connection::putheader( const char* header, int numericvalue ) { char buf[32]; sprintf( buf, "%d", numericvalue ); putheader( header, buf ); }
/* * cleandic(): Passe en revue toutes les lignes du dictionnaire, et * elimine les lignes de commentaires ainsi que les retour- * charriot eventuels provenant de DOS, pour gagner de la * place entre autres sous ce systeme. */ cleandic() { char fname[127]; char tmpfile[127]; char buf[90]; char ch, letter ; FILE *fp,*ftmp ; sprintf(tmpfile,"%s/cleantmp.%d", TMPPATH, getpid() ); for( letter = 'a' ; letter <= 'z' ; letter++ ) { sprintf(fname, "%s%s%c%s",dict_path, sep, letter, DICT_EXT ); if(( fp = fopen(fname,READ_TEXT)) == NULL ) { fprintf(stderr,"Impossible de lire fichier %s\n",fname ); file_usage(); return ERROR; } #ifdef MUST_HAVE_BUF setvbuf( fp, NULL, _IOFBF, MYVBUF ); #endif if(( ftmp = fopen(tmpfile,WRITE_BINARY)) == NULL ) /* BINARY for DOS!*/ { fprintf(stderr,"Fichier temporaire %s impossible !\n",fname ); return ERROR; } #ifdef MUST_HAVE_BUF setvbuf( ftmp, NULL, _IOFBF, MYVBUF ); #endif printf("Traite la lettre %c...\n", letter ); putheader( letter, ftmp); while( fgets(buf,88,fp) ) { nocrlf( buf ); if((byte) *buf == COMMENT_CHAR || *buf == '\0' ) continue; fprintf(ftmp,"%s\n",buf); } putfooter( letter, ftmp); fclose( fp ); fclose( ftmp); /* ensuite, on recopie. C'est tres lent mais */ /* ca marche a coup sur sous DOS avec des */ /* drives differents, ce serait mieux avec */ /* un link ou un rename... Pas me casser :-) */ if(( ftmp = fopen(tmpfile,READ_BINARY)) == NULL ) /* BINARY for DOS!*/ { fprintf(stderr,"Fichier temporaire %s inacessible !\n",fname ); return ERROR; } #ifdef MUST_HAVE_BUF setvbuf( ftmp, NULL, _IOFBF, MYVBUF ); #endif if(( fp = fopen(fname,WRITE_BINARY)) == NULL ) { fprintf(stderr,"Impossible de reecrire fichier %s\n",fname ); return ERROR; } #ifdef MUST_HAVE_BUF setvbuf( fp, NULL, _IOFBF, MYVBUF ); #endif while( fread( &ch, 1, 1, ftmp ) ) fwrite( &ch, 1,1, fp ) ; fclose( fp ); fclose( ftmp); } unlink( tmpfile ); printf("Hop, j'ai fini.\n"); return OK ; }
void fileout(register Archive_t* ap, register File_t* f) { register size_t m; register ssize_t n; register off_t c; int err; Buffer_t* bp; if (f->delta.op == DELTA_verify) ap->selected--; else if (putheader(ap, f)) { if (!ap->format->putdata || !(*ap->format->putdata)(&state, ap, f, f->fd)) { err = 0; c = f->st->st_size; while (c > 0) { n = m = c > state.buffersize ? state.buffersize : c; if (!err) { if (f->fd >= 0) { if ((n = read(f->fd, ap->io->next, m)) < 0 && errno == EIO) { static char* buf; if (!buf) { n = 1024 * 8; error(1, "EIO read error -- falling back to aligned reads"); if (!(buf = malloc(state.buffersize + n))) nospace(); buf += n - (((ssize_t)buf) & (n - 1)); } if ((n = read(f->fd, buf, m)) > 0) memcpy(ap->io->next, buf, n); } } else if (bp = getbuffer(f->fd)) { memcpy(ap->io->next, bp->next, m); if (f->extended && ap->convert[SECTION_CONTROL].f2a) ccmapstr(ap->convert[SECTION_CONTROL].f2a, ap->io->next, m); bp->next += m; } else if (bread(f->ap, ap->io->next, (off_t)0, (off_t)n, 1) <= 0) n = -1; } if (n <= 0) { if (n) error(ERROR_SYSTEM|2, "%s: read error", f->path); else error(2, "%s: file size changed", f->path); memzero(ap->io->next, state.buffersize); err = 1; } else { c -= n; bput(ap, n); } } } puttrailer(ap, f); } if (f->fd >= 0) closein(ap, f, f->fd); }
/* -------------------------------------------------------------------- */ int editText(char *buf, int lim) { char ch, x; FILE *fd; int eom; dowhat = PROMPT; do { outFlag = IMPERVIOUS; while (MIReady()) /* flush modem input buffer */ getMod(); doCR(); strcpy(gprompt,"Entry command:"); /* in case of ^A? */ mtPrintf(TERM_REVERSE,gprompt); mPrintf(" "); switch (ch = (char) toupper(iChar())) { case 'A': mPrintf("\bAbort\n "); if (strblank(buf)) return FALSE; else if (getYesNo(confirm, 0)) { heldMessage = TRUE; memcpy(msgBuf2, msgBuf, sizeof(struct msgB)); dowhat = DUNO; return FALSE; } break; case 'C': mPrintf("\bContinue"); /* dump message to display */ outFlag = IMPERVIOUS; doCR(); putheader(); doCR(); outFlag = OUTOK; mFormat(buf); doBS(); eom = strlen(buf); if (eom > 0) buf[eom - 1] = '\0'; /* zap last character ('\n') */ outFlag = IMPERVIOUS; return ERROR; /* to return to this routine */ case 'F': mPrintf("\bFind & Replace text\n "); replaceString(buf, lim, TRUE); break; case 'P': mPrintf("\bPrint formatted\n "); doCR(); outFlag = IMPERVIOUS; putheader(); doCR(); outFlag = OUTOK; mFormat(buf); termCap(TERM_NORMAL); doCR(); break; case 'R': mPrintf("\bReplace text\n "); replaceString(buf, lim, FALSE); break; case 'S': mPrintf("\bSave buffer\n "); entered++; /* increment # messages entered */ dowhat = DUNO; return TRUE; case 'W': mPrintf("\bWord count\n "); wordcount(buf); break; case '?': nextmenu("edit", &(cfg.cnt.edittut), 1); break; default: if ((x = (char) strpos((char) tolower(ch), editcmd)) != 0) { x--; mPrintf("\b%s", edit[x].ed_name); doCR(); if (edit[x].ed_local && !onConsole) { mPrintf("\n Local editor only!\n "); } else { changedir(cfg.aplpath); if ((fd = fopen("message.apl", "wb")) != NULL) { xPutStr(fd, msgBuf->mbtext); fclose(fd); } readMessage = FALSE; extFmtRun(edit[x].ed_cmd, "message.apl"); changedir(cfg.aplpath); if ((fd = fopen("message.apl", "rb")) != NULL) { GetStr(fd, msgBuf->mbtext, cfg.maxtext); fclose(fd); unlink("message.apl"); } } break; } if (!gl_user.expert) nextmenu("edit", &(cfg.cnt.edittut), 1); else mPrintf("\n '?' for menu.\n \n"); break; } } while (!ExitToMsdos && (haveCarrier || onConsole)); dowhat = DUNO; return FALSE; }
static void build(void) { int i; FILE *oldrefs; /* old cross-reference file */ time_t reftime; /* old crossref modification time */ char *file; /* current file */ char *oldfile; /* file in old cross-reference */ char newdir[PATHLEN + 1]; /* directory in new cross-reference */ char olddir[PATHLEN + 1]; /* directory in old cross-reference */ char oldname[PATHLEN + 1]; /* name in old cross-reference */ int oldnum; /* number in old cross-ref */ struct stat statstruct; /* file status */ int firstfile; /* first source file in pass */ int lastfile; /* last source file in pass */ int built = 0; /* built crossref for these files */ int copied = 0; /* copied crossref for these files */ BOOL interactive = YES; /* output progress messages */ /* * normalize the current directory relative to the home directory so * the cross-reference is not rebuilt when the user's login is moved */ (void) strcpy(newdir, currentdir); if (strcmp(currentdir, home) == 0) { (void) strcpy(newdir, "$HOME"); } else if (strncmp(currentdir, home, strlen(home)) == 0) { (void) sprintf(newdir, "$HOME%s", currentdir + strlen(home)); } /* sort the source file names (needed for rebuilding) */ qsort((char *)srcfiles, (unsigned)nsrcfiles, sizeof (char *), compare); /* * if there is an old cross-reference and its current directory * matches or this is an unconditional build */ if ((oldrefs = vpfopen(reffile, "r")) != NULL && unconditional == NO && fscanf(oldrefs, "cscope %d %s", &fileversion, olddir) == 2 && (strcmp(olddir, currentdir) == 0 || /* remain compatible */ strcmp(olddir, newdir) == 0)) { /* get the cross-reference file's modification time */ (void) fstat(fileno(oldrefs), &statstruct); reftime = statstruct.st_mtime; if (fileversion >= 8) { BOOL oldcompress = YES; BOOL oldinvertedindex = NO; BOOL oldtruncatesyms = NO; int c; /* see if there are options in the database */ for (;;) { while ((c = getc(oldrefs)) == ' ') { } if (c != '-') { (void) ungetc(c, oldrefs); break; } switch (c = getc(oldrefs)) { case 'c': /* ASCII characters only */ oldcompress = NO; break; case 'q': /* quick search */ oldinvertedindex = YES; (void) fscanf(oldrefs, "%ld", &totalterms); break; case 'T': /* truncate symbols to 8 characters */ oldtruncatesyms = YES; break; } } /* check the old and new option settings */ if (oldcompress != compress || oldtruncatesyms != truncatesyms) { (void) fprintf(stderr, "cscope: -c or -T option mismatch between " "command line and old symbol database\n"); goto force; } if (oldinvertedindex != invertedindex) { (void) fprintf(stderr, "cscope: -q option mismatch between " "command line and old symbol database\n"); if (invertedindex == NO) { removeindex(); } goto outofdate; } /* seek to the trailer */ if (fscanf(oldrefs, "%ld", &traileroffset) != 1 || fseek(oldrefs, traileroffset, 0) == -1) { (void) fprintf(stderr, "cscope: incorrect symbol database file " "format\n"); goto force; } } /* if assuming that some files have changed */ if (fileschanged == YES) { goto outofdate; } /* see if the view path is the same */ if (fileversion >= 13 && samelist(oldrefs, vpdirs, vpndirs) == NO) { goto outofdate; } /* see if the directory lists are the same */ if (samelist(oldrefs, srcdirs, nsrcdirs) == NO || samelist(oldrefs, incdirs, nincdirs) == NO || fscanf(oldrefs, "%d", &oldnum) != 1 || fileversion >= 9 && fscanf(oldrefs, "%*s") != 0) { /* skip the string space size */ goto outofdate; } /* * see if the list of source files is the same and * none have been changed up to the included files */ for (i = 0; i < nsrcfiles; ++i) { if (fscanf(oldrefs, "%s", oldname) != 1 || strnotequal(oldname, srcfiles[i]) || vpstat(srcfiles[i], &statstruct) != 0 || statstruct.st_mtime > reftime) { goto outofdate; } } /* the old cross-reference is up-to-date */ /* so get the list of included files */ while (i++ < oldnum && fscanf(oldrefs, "%s", oldname) == 1) { addsrcfile(oldname); } (void) fclose(oldrefs); return; outofdate: /* if the database format has changed, rebuild it all */ if (fileversion != FILEVERSION) { (void) fprintf(stderr, "cscope: converting to new symbol database file " "format\n"); goto force; } /* reopen the old cross-reference file for fast scanning */ if ((symrefs = vpopen(reffile, O_RDONLY)) == -1) { cannotopen(reffile); myexit(1); } /* get the first file name in the old cross-reference */ blocknumber = -1; (void) readblock(); /* read the first cross-ref block */ (void) scanpast('\t'); /* skip the header */ oldfile = getoldfile(); } else { /* force cross-referencing of all the source files */ force: reftime = 0; oldfile = NULL; } /* open the new cross-reference file */ if ((newrefs = fopen(newreffile, "w")) == NULL) { cannotopen(newreffile); myexit(1); } if (invertedindex == YES && (postings = fopen(temp1, "w")) == NULL) { cannotopen(temp1); cannotindex(); } (void) fprintf(stderr, "cscope: building symbol database\n"); putheader(newdir); fileversion = FILEVERSION; if (buildonly == YES && !isatty(0)) { interactive = NO; } else { initprogress(); } /* output the leading tab expected by crossref() */ dbputc('\t'); /* * make passes through the source file list until the last level of * included files is processed */ firstfile = 0; lastfile = nsrcfiles; if (invertedindex == YES) { srcoffset = mymalloc((nsrcfiles + 1) * sizeof (long)); } for (;;) { /* get the next source file name */ for (fileindex = firstfile; fileindex < lastfile; ++fileindex) { /* display the progress about every three seconds */ if (interactive == YES && fileindex % 10 == 0) { if (copied == 0) { progress("%ld files built", (long)built, 0L); } else { progress("%ld files built, %ld " "files copied", (long)built, (long)copied); } } /* if the old file has been deleted get the next one */ file = srcfiles[fileindex]; while (oldfile != NULL && strcmp(file, oldfile) > 0) { oldfile = getoldfile(); } /* * if there isn't an old database or this is * a new file */ if (oldfile == NULL || strcmp(file, oldfile) < 0) { crossref(file); ++built; } else if (vpstat(file, &statstruct) == 0 && statstruct.st_mtime > reftime) { /* if this file was modified */ crossref(file); ++built; /* * skip its old crossref so modifying the last * source file does not cause all included files * to be built. Unfortunately a new file that * is alphabetically last will cause all * included files to be built, but this is * less likely */ oldfile = getoldfile(); } else { /* copy its cross-reference */ putfilename(file); if (invertedindex == YES) { copyinverted(); } else { copydata(); } ++copied; oldfile = getoldfile(); } } /* see if any included files were found */ if (lastfile == nsrcfiles) { break; } firstfile = lastfile; lastfile = nsrcfiles; if (invertedindex == YES) { srcoffset = myrealloc(srcoffset, (nsrcfiles + 1) * sizeof (long)); } /* sort the included file names */ qsort((char *)&srcfiles[firstfile], (unsigned)(lastfile - firstfile), sizeof (char *), compare); } /* add a null file name to the trailing tab */ putfilename(""); dbputc('\n'); /* get the file trailer offset */ traileroffset = dboffset; /* * output the view path and source and include directory and * file lists */ putlist(vpdirs, vpndirs); putlist(srcdirs, nsrcdirs); putlist(incdirs, nincdirs); putlist(srcfiles, nsrcfiles); if (fflush(newrefs) == EOF) { /* rewind doesn't check for write failure */ cannotwrite(newreffile); /* NOTREACHED */ } /* create the inverted index if requested */ if (invertedindex == YES) { char sortcommand[PATHLEN + 1]; if (fflush(postings) == EOF) { cannotwrite(temp1); /* NOTREACHED */ } (void) fstat(fileno(postings), &statstruct); (void) fprintf(stderr, "cscope: building symbol index: temporary file size is " "%ld bytes\n", statstruct.st_size); (void) fclose(postings); /* * sort -T is broken until it is fixed we don't have too much choice */ /* * (void) sprintf(sortcommand, "sort -y -T %s %s", tmpdir, temp1); */ (void) sprintf(sortcommand, "LC_ALL=C sort %s", temp1); if ((postings = popen(sortcommand, "r")) == NULL) { (void) fprintf(stderr, "cscope: cannot open pipe to sort command\n"); cannotindex(); } else { if ((totalterms = invmake(newinvname, newinvpost, postings)) > 0) { movefile(newinvname, invname); movefile(newinvpost, invpost); } else { cannotindex(); } (void) pclose(postings); } (void) unlink(temp1); (void) free(srcoffset); (void) fprintf(stderr, "cscope: index has %ld references to %ld symbols\n", npostings, totalterms); } /* rewrite the header with the trailer offset and final option list */ rewind(newrefs); putheader(newdir); (void) fclose(newrefs); /* close the old database file */ if (symrefs >= 0) { (void) close(symrefs); } if (oldrefs != NULL) { (void) fclose(oldrefs); } /* replace it with the new database file */ movefile(newreffile, reffile); }