X-Git-Url: http://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=src%2Fwriter.c;h=75daa46ac34425fe105756a6c7e4abfa95085df7;hb=35d0d9bcbb33b64c3cfd83548fc9fc1cbdb5295e;hp=5448d6c0b805d1e5b26e7e9f10081663eec42be3;hpb=51f0f8ed69b065cd2577a27c2a2911cdda243b99;p=oss%2Fcatdoc.git diff --git a/src/writer.c b/src/writer.c index 5448d6c..75daa46 100644 --- a/src/writer.c +++ b/src/writer.c @@ -21,6 +21,9 @@ /* charset.c */ /************************************************************************/ static char outputbuffer[LINE_BUF_SIZE]=""; + +int para_double_newline = 1; + void out_char(const char *chunk) { static int bufpos=0; int eol_flag=0; @@ -34,7 +37,7 @@ void out_char(const char *chunk) { *p; *(q++)=*(p++),bufpos++) { if (*p=='\n') eol_flag=1; - } + } *q=0; /* This strcat is safe. wrap margin setting code in main.c ensures that wrap_margin is @@ -46,20 +49,29 @@ void out_char(const char *chunk) { fputs(outputbuffer,stdout); *outputbuffer=0; bufpos=0; - if (q) { - fputs(q,stdout); - } else { - fputc('\n',stdout); - } + if (para_double_newline) { + if (q) { + fputs(q,stdout); + } else { + fputc('\n',stdout); + } + } } else if (bufpos>wrap_margin) { char *q=outputbuffer,*p=outputbuffer+wrap_margin; - while (p>outputbuffer&&!isspace(*p)) p--; + while (p>outputbuffer&&*p!=' '&& *p!='\t') p--; if (p==outputbuffer) { /*worst case - nowhere to wrap. Will use brute force */ - fwrite(outputbuffer,wrap_margin,1,stdout); + int i = wrap_margin; + if (target_charset == NULL) { + /* NULL target_charest means UTF-8 */ + /* go back to start of nearest utf-8 character */ + while(i>0 && (outputbuffer[i] & 0xC0) == 0x80) i--; + } + fwrite(outputbuffer,i,1,stdout); + fputc('\n',stdout); - p=outputbuffer+wrap_margin; + p=outputbuffer+i; } else { *p=0;p++; fputs(outputbuffer,stdout);