home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 128_01 / roff44.c < prev    next >
Text File  |  1985-03-10  |  6KB  |  211 lines

  1. /********************************************************/
  2. /*                            */
  3. /*            ROFF4, Version 1.60            */
  4. /*                            */
  5. /*(C) 1983,4 by Ernest E. Bergmann            */
  6. /*        Physics, Building #16            */
  7. /*        Lehigh Univerisity            */
  8. /*        Bethlehem, Pa. 18015            */
  9. /*                            */
  10. /* Permission is hereby granted for all commercial and    */
  11. /* non-commercial reproduction and distribution of this    */
  12. /* material provided this notice is included.        */
  13. /*                            */
  14. /********************************************************/
  15. /*FEB 18, 1984*/
  16. /*JAN 15, 1984*/
  17. #include "roff4.h"
  18.  
  19. /**************************************************
  20. handles case of leading blanks or tabs; empty lines 
  21. ***************************************************/
  22. leadbl (line)
  23. char *line;
  24. {int i, j, white;
  25. brk();
  26. /* figure out white space Nov 13*/
  27. for (white=0, i=0; line[i] == ' ' || line[i] == '\t'; i++ )
  28.     {if(line[i]==' ') white++;
  29.     else white=min(RMVAL,TABSIZ*(1+white/TABSIZ));
  30.     }
  31. if ( line[i] != NEWLINE ) TIVAL += white;
  32. /* move line to left */
  33. for(j=0;(line[j]=line[i])!='\0';j++,i++);
  34. }
  35. /*****************************************
  36.         puts out page header
  37. ******************************************/
  38. phead()
  39. {exchange();
  40. UF=XF=FALSE;
  41. MCNT=1;
  42. CURPAG = NEWPAG++;
  43. if((CURPAG<FIRSTPAGE)||(CURPAG>LASTPAGE)) SUPPRESS=TRUE;
  44. else SUPPRESS=FALSE;
  45. OLDLN=-1;
  46. if(PAGESTOP)
  47.     {bdos(2,7);    /*ring bell*/
  48.     bdos(1);    /*wait til char typed at console*/
  49.     }
  50. PLINENO=0;FPLINENO=0;
  51. if (M1VAL > 0 )
  52.       { VLINENO = M1VAL-1;
  53.     if (CURPAG % 2) puttl3 ( OHEAD, OH2, OH3, CURPAG );
  54.     else puttl3 ( EHEAD, EH2, EH3, CURPAG );
  55.       }
  56. VLINENO = M1VAL+M2VAL; FVLINENO=0;
  57. exchange();
  58. }
  59. /**************************************
  60.         puts out page footer
  61. ***************************************/
  62. pfoot()
  63. {exchange();
  64. UF=XF=FALSE;
  65. MCNT=1;
  66. VLINENO = BOTTOM+M3VAL; FVLINENO=0;
  67. if ( M4VAL > 0 )
  68.       { if(CURPAG % 2)puttl3 ( OFOOT,OF2,OF3, CURPAG );
  69.     else puttl3(EFOOT,EF2,EF3,CURPAG);
  70.       }
  71. VLINENO = PLVAL;FVLINENO=0;
  72. if (FFEED) putchar(FORMF);
  73. else padv();
  74. whole();
  75. OLDBOT=PLINENO=FPLINENO=0;/*printer at start of newpage*/
  76. OLDLN=-1;
  77. exchange();
  78. }
  79. /**********************************************
  80.     space n lines or to bottom of the page
  81. ***********************************************/
  82. space (n)
  83. int n;
  84. {brk();    /* flush out last unfilled line */
  85. if (VLINENO >= BOTTOM)    return;    /* end of page */
  86. if (VLINENO<0) phead();    /* top of page */
  87. VLINENO += n;
  88. if (VLINENO >= BOTTOM) pfoot(); /* print footer if bottom */
  89. }
  90. /*******************************************************/
  91. text (line)
  92. char *line;
  93. {char wrdbuf [LSZ];
  94. int i, j, k;
  95. char *p1, *p2;
  96. if DEBUG fprintf(STDERR,"\n\nTEXT:<%s>", line);
  97. if (line[0] == BLANK || line[0]==NEWLINE || line[0] == TAB)
  98.     leadbl (line);
  99. if (CEVAL > 0)
  100.       { center(line);
  101.     put(line);
  102.     CEVAL--;
  103.       }
  104. else if(line[0]==NEWLINE) space(LSVAL);
  105. else if(!FILL) put(line);
  106. else while (WE_HAVE_A_WORD == getwrd (line, wrdbuf))
  107.     putwrd (wrdbuf);
  108. }
  109. /******************************************************
  110.     put out a line of text with correct indentation
  111.     underlining if specified
  112. *******************************************************/
  113. put (line)
  114. char *line;
  115. {int i,fs,minfs;
  116. if ((VLINENO < 0)||(VLINENO >= BOTTOM)) phead();
  117. fs=(VLINENO-OLDLN)*FRVAL;
  118. minfs=OLDBOT-OUTTOP; if(!(OLDBOT&&OUTTOP)) minfs++;
  119. while(fs<minfs) {fs+=FRVAL; VLINENO++;}
  120. need(0);
  121. putline(line);
  122. TIVAL = INVAL;
  123. VLINENO += LSVAL;
  124. if (VLINENO >= BOTTOM) pfoot();
  125. }
  126. /***********************************************************
  127. concatenates the word onto the end of OUTBUF for filled text
  128. ************************************************************/
  129. putwrd (wrdbuf)    /*Nov 22: SENTENCE*/
  130. char *wrdbuf;
  131. {int i, j, k;
  132. char s[MAXLINE], ch;
  133. int line_len, new_out_width, wid;
  134. int nextra;
  135. skip_blanks (wrdbuf); trunc_bl (wrdbuf);
  136. wid =1+SENTENCE+strln3(wrdbuf,TRUE,1);/*sets WTOP,WBOT*/
  137. line_len = RMVAL - TIVAL;
  138. new_out_width = OUTW+wid;
  139. if (new_out_width > min (line_len, MAXLINE-1))
  140.       { nextra = min(line_len, MAXLINE-1)-OUTW+1;
  141.     if(OUTBUF[OUTPOS-2]==BLANK) nextra++;
  142.     if(JUSTIFY) spread(OUTBUF,nextra,OUTWRDS);
  143.     brk();
  144.       }
  145. OUTW += wid;
  146. OUTcat(wrdbuf);
  147. OUTSP(); if(SENTENCE) OUTSP();
  148. OUTWRDS++;
  149. if(WTOP<OUTTOP) OUTTOP=WTOP;
  150. if(WBOT>OUTBOT) OUTBOT=WBOT;
  151. }
  152. /**********************************************************
  153.     a new putline routine; sends line to  OUTPUT2
  154. ***********************************************************/
  155. putline (line)
  156. char *line;
  157. {char c;
  158. blanks(TIVAL);
  159. for(;c=*line;line++) putout(c);
  160. putout('\0');
  161. printout();
  162. }
  163. /****************************************/
  164. OUTcat(str)    /*appends string to OUTBUF*/
  165. char *str;
  166. {while(OUTBUF[OUTPOS]=*(str++))
  167.     OUTPOS++;
  168. }
  169. /****************************************/
  170. OUTSP()        /*appends BLANK to OUTBUF*/
  171. {OUTBUF[OUTPOS++]=BLANK;
  172. OUTBUF[OUTPOS]='\0';
  173. }
  174. /****************************************/
  175. gloss()    /*prints on STDOUT a glossary of .tr chars*/
  176. {int i;
  177. char line[20],tcs;
  178. put("GLOSSARY:");
  179. put("USE     <GET>");
  180. tcs=TCVAL;
  181. TCVAL |= 128; /*set most significant bit*/
  182. for(i=1;i<19;i++) line[i]=' ';
  183. line[0]=tcs;
  184. line[8]='<';
  185. line[9]=TCVAL;
  186. line[11]='>';
  187. line[12]='\0';
  188. for(i=' ';i<127;i++)
  189.     {if(TPTR[i-' '])
  190.         {line[1]=line[10]=i;
  191.         put(line);
  192.         }
  193.     }
  194. TCVAL=tcs;
  195. SPACE(HUGE);
  196. }
  197. /***************************************/
  198. exchange() /*maintain separate environment for headers and
  199.         footers*/
  200. {int i;
  201. i=MCNT2; MCNT2=MCNT; MCNT=i;
  202. i=XF2; XF2=XF; XF=i;
  203. i=UF2; UF2=UF; UF=i;
  204. }
  205. ;
  206. {char c;
  207. blanks(TIVAL);
  208. for(;c=*line;line++) putout(c);
  209. putout('\0');
  210. printout();
  211. }