1 /*****************************************************************/
2 /* Output of unicode buffers with conversion into target encoding*/
3 /* And application of substitution maps */
5 /* This file is part of catdoc project */
6 /* (c) Victor Wagner 1996-2003, (c) Alex Ott 2003 */
7 /*****************************************************************/
15 /************************************************************************/
16 /* performs paragraph formatting if wrap_margin is non-zero */
17 /* gets character sequence and appends it to buffer. If buffer is long */
18 /* enough, prints its beginning out */
19 /* Input parameter is pointer to the string which represents one unicode*/
20 /* character after character set translation. See convert_char ina */
22 /************************************************************************/
23 static char outputbuffer[LINE_BUF_SIZE]="";
24 void out_char(const char *chunk) {
27 const char *p; char *q;
33 for (q=outputbuffer+bufpos,p=chunk;
35 *(q++)=*(p++),bufpos++) {
36 if (*p=='\n') eol_flag=1;
39 /* This strcat is safe. wrap margin setting
40 code in main.c ensures that wrap_margin is
41 less than LINE_BUF_SIZE-strlen(largest chunk)
44 /* End of paragraph */
45 char *q = map_subst(spec_chars,'\n');
46 fputs(outputbuffer,stdout);
54 } else if (bufpos>wrap_margin) {
55 char *q=outputbuffer,*p=outputbuffer+wrap_margin;
57 while (p>outputbuffer&&!isspace(*p)) p--;
58 if (p==outputbuffer) {
59 /*worst case - nowhere to wrap. Will use brute force */
60 fwrite(outputbuffer,wrap_margin,1,stdout);
62 p=outputbuffer+wrap_margin;
65 fputs(outputbuffer,stdout);
68 for(q=outputbuffer;*p;p++,q++) *q=*p;
69 bufpos=q-outputbuffer;
74 /************************************************************************/
75 /* Main output function.
76 * Programs which read word-processor files should accumulate paragraphs
77 * in the buffer as array of unicode 16-bit codes and pass to this
79 ************************************************************************/
80 void output_paragraph(unsigned short int *buffer) {
81 unsigned short int *p;
83 for (p=buffer;*p;p++) {
84 out_char(convert_char(*p));