martin 98/04/03 06:55:46
Modified: src/main buff.c Log: Integrate EBCDIC conversion into new bprintf() and friends. Fix an old bug with EBCDIC translation (sometimes, a necessary conversion was forgotten). Revision Changes Path 1.72 +30 -2 apache-1.3/src/main/buff.c Index: buff.c =================================================================== RCS file: /home/cvs/apache-1.3/src/main/buff.c,v retrieving revision 1.71 retrieving revision 1.72 diff -u -u -r1.71 -r1.72 --- buff.c 1998/04/01 01:31:12 1.71 +++ buff.c 1998/04/03 14:55:45 1.72 @@ -630,6 +630,9 @@ * Read up to nbyte bytes into buf. * If fewer than byte bytes are currently available, then return those. * Returns 0 for EOF, -1 for error. + * NOTE EBCDIC: The readahead buffer _always_ contains *unconverted* data. + * Only when the caller retrieves data from the buffer (calls bread) + * is a conversion done, if the conversion flag is set at that time. */ API_EXPORT(int) bread(BUFF *fb, void *buf, int nbyte) { @@ -656,6 +659,10 @@ return i; } i = read_with_errors(fb, buf, nbyte); +#ifdef CHARSET_EBCDIC + if (i > 0 && bgetflag(fb, B_ASCII2EBCDIC)) + ascii2ebcdic(buf, buf, i); +#endif /*CHARSET_EBCDIC*/ return i; } @@ -689,11 +696,11 @@ /* do a single read */ if (nbyte >= fb->bufsiz) { -/* read directly into buffer */ +/* read directly into caller's buffer */ i = read_with_errors(fb, buf, nbyte); #ifdef CHARSET_EBCDIC if (i > 0 && bgetflag(fb, B_ASCII2EBCDIC)) - ascii2ebcdic(buf, buf, nbyte); + ascii2ebcdic(buf, buf, i); #endif /*CHARSET_EBCDIC*/ if (i == -1) { return nrd ? nrd : -1; @@ -1459,6 +1466,13 @@ struct bprintf_data *b = (struct bprintf_data *)vbuff; BUFF *fb = b->fb; +#ifdef CHARSET_EBCDIC + /* Characters were pushed into the buffer without conversion. Do it now */ + if (fb->flags & B_EBCDIC2ASCII) + ebcdic2ascii(&fb->outbase[fb->outcnt], + &fb->outbase[fb->outcnt], + b->vbuff.curpos - (char *)&fb->outbase[fb->outcnt]); +#endif /*CHARSET_EBCDIC*/ fb->outcnt += b->vbuff.curpos - (char *)&fb->outbase[fb->outcnt]; if (fb->outcnt == fb->bufsiz) { if (bflush(fb)) { @@ -1483,6 +1497,13 @@ res = ap_vformatter(bprintf_flush, &b.vbuff, fmt, ap); va_end(ap); if (res != -1) { +#ifdef CHARSET_EBCDIC + /* Characters were pushed into the buffer without conversion. Do it now */ + if (fb->flags & B_EBCDIC2ASCII) + ebcdic2ascii(&fb->outbase[fb->outcnt], + &fb->outbase[fb->outcnt], + b.vbuff.curpos - (char *)&fb->outbase[fb->outcnt]); +#endif /*CHARSET_EBCDIC*/ fb->outcnt += b.vbuff.curpos - (char *)&fb->outbase[fb->outcnt]; } return res; @@ -1498,6 +1519,13 @@ b.fb = fb; res = ap_vformatter(bprintf_flush, &b.vbuff, fmt, ap); if (res != -1) { +#ifdef CHARSET_EBCDIC + /* Characters were pushed into the buffer without conversion. Do it now */ + if (fb->flags & B_EBCDIC2ASCII) + ebcdic2ascii(&fb->outbase[fb->outcnt], + &fb->outbase[fb->outcnt], + b.vbuff.curpos - (char *)&fb->outbase[fb->outcnt]); +#endif /*CHARSET_EBCDIC*/ fb->outcnt += b.vbuff.curpos - (char *)&fb->outbase[fb->outcnt]; } return res;