home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 145_01 / roff41.c < prev    next >
Text File  |  1979-12-31  |  7KB  |  214 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. /*Jan 8, 1984*/
  16. #include "roff4.h"
  17. /**********************************************************
  18. Removes white-space characters at start of string.
  19. ***********************************************************/
  20. skip_blanks ( string )
  21. char *string;    /* cursor to original string */
  22. {char *p;    /* cursor to 'final' string */
  23. for(p=string;*string==BLANK||*string==TAB||*string==NEWLINE;
  24.     string++);
  25. while(*(p++) = *(string++));
  26. }
  27. /*************************************************************/
  28. int comtyp (line)
  29. char *line;
  30. {char let1, let2;
  31. let1 = toupper( line[1] );
  32. let2 = toupper( line[2] );
  33.  
  34. if ( let1==COMMAND )        return( IG );
  35. if ( let1=='I' && let2=='G')    return( IG );
  36. if ( let1=='F' && let2=='I')    return( FI );
  37. if ( let1=='F' && let2=='O')    return( FO );
  38. if ( let1=='T' && let2=='I')    return( TI );
  39. if ( let1=='B' && let2=='P')    return( BP );
  40. if ( let1=='B' && let2=='R')    return( BR );
  41. if ( let1=='C' && let2=='E')    return( CE );
  42. if ( let1=='H' && let2=='E')    return( HE );
  43. if ( let1=='I' && let2=='N')    return( IN );
  44. if ( let1=='L' && let2=='S')    return( LS );
  45. if ( let1=='N' && let2=='F')    return( NF );
  46. if ( let1=='P' && let2=='L')    return( PL );
  47. if ( let1=='R' && let2=='M')    return( RM );
  48. if ( let1=='S' && let2=='P')    return( SP );
  49. if ( let1=='S' && let2=='T')    return( ST );
  50. if ( let1=='N' && let2=='E')    return( NE );
  51. if ( let1=='F' && let2=='F')    return( FF );
  52. if ( let1=='S' && let2=='C')    return( SC );
  53. if ( let1=='O' && let2=='W')    return( OW );
  54. if ( let1=='T' && let2=='S')    return( TS );
  55. if ( let1=='O' && let2=='H')    return( OH );
  56. if ( let1=='O' && let2=='F')    return( OF );
  57. if ( let1=='E' && let2=='H')    return( EH );
  58. if ( let1=='E' && let2=='F')    return( EF );
  59. if ( let1=='A' && let2=='B')    return( AB );
  60. if ( let1=='D' && let2=='B')    return( DB );
  61. if ( let1=='T' && let2=='C')    return( TC );
  62. if ( let1=='T' && let2=='R')    return( TR );
  63. if ( let1=='C' && let2=='F')    return( CF );
  64. if ( let1=='I' && let2=='C')    return( IC );
  65. if ( let1=='O' && let2=='U')    return( OU );
  66. if ( let1=='J' && let2=='U')    return( JU );
  67. if ( let1=='N' && let2=='J')    return( NJ );
  68. if ( let1=='F' && let2=='R')    return( FR );
  69. if ( let1=='W' && let2=='H')    return( WH );
  70. if ( let1=='E' && let2=='M')    return( EM );
  71. if ( let1=='D' && let2=='M')    return( DM );
  72. if ( let1=='D' && let2=='S')    return( DS );
  73. if ( let1=='R' && let2=='G')    return( RG );
  74. if ( let1=='D' && let2=='I')    return( DI );
  75. if ( let1=='E' && let2=='D')    return( ED );
  76. if ( let1=='S' && let2=='O')    return( SO );
  77. if ( let1=='P' && let2=='C')    return( PC );
  78. if ( let1=='S' && let2=='A')    return( SA );
  79. if ( let1=='B' && let2=='J')    return( BJ );
  80.  
  81. if ( let1=='M')
  82.       { if (let2=='1')        return( M1 );
  83.     if (let2=='2')        return( M2 );
  84.     if (let2=='3')        return( M3 );
  85.     if (let2=='4')        return( M4 );
  86.       }
  87. return( UNKNOWN );        /* no match */
  88. }
  89. /*************************************************************
  90. gets the number ( if any ) associated with any command 
  91. *************************************************************/
  92. int get_val ( line, typ )
  93. char *line, *typ;
  94. {int i;
  95. char local[ MAXLINE ];
  96. strcpy (local, line);    /* local copy */
  97. /* skip over the command line */
  98. for(i=1; local[i]!=' '&&local[i]!='\t'&&local[i]!='\n' ;i++);
  99.  
  100. skip_blanks (&local[i]);    /* find the number */
  101. *typ = local[i];    /* relative or absolute */
  102. if ( *typ=='+' || *typ=='-' )    i++;
  103. else if ( !isdigit( *typ ) )    return( NO_VAL );
  104. return ( atoi( &local[i] ));
  105. }
  106. /*************************************************************
  107.  sets a global parameter like SPVAL, PAGESTOP, etc.
  108.  Also checks that the new value is within the range of that 
  109.  parameter.  Assigns the default for that parameter if no value
  110.   is specified.
  111. *************************************************************/
  112. set ( param, val, arg_typ, defval, minval, maxval )
  113. int *param, val, defval, minval, maxval;
  114. char arg_typ;
  115. {if(val==NO_VAL) *param = defval;    /* defaulted */
  116. else if(arg_typ == '+') *param += val;    /* relative + */
  117. else if(arg_typ == '-')    *param -= val;    /* relative - */
  118. else    *param = val;            /* absolute */
  119. *param = min (*param,maxval);
  120. *param = max (*param, minval);
  121. if DEBUG fprintf(STDERR,"\tSET *param = %d\n", *param);
  122. }
  123. /*************************************************************
  124.     end current filled line 
  125. **************************************************************/
  126. brk()
  127. {int l;
  128. if DEBUG fprintf(STDERR,"brk: OUTBUF=<%s>\n", OUTBUF);
  129. if (OUTPOS) put(OUTBUF);
  130. OUTW=OUTPOS=OUTTOP=OUTBOT=OUTWRDS = 0;
  131. OUTBUF[0] = '\0';
  132. }
  133.  
  134. /**************************************************/
  135. initxu()    /*initialize underline,overstrike variables*/
  136. {    XCOL=UCOL=-1;
  137. #if BDS
  138.     setmem(&XBUF,LSZ,' ');
  139.     setmem(&UBUF,LSZ,' ');
  140. #else
  141.     setmem(XBUF,LSZ,' ');
  142.     setmem(UBUF,LSZ,' ');
  143. #endif
  144. }
  145. /****************************************/
  146. need(n)    /*test for space before footer*/
  147. int n;    /*whole lines*/
  148. {if (( VLINENO>=(BOTTOM-n) ) && (BOTTOM>=VLINENO) )
  149.     {space(HUGE); NEWPAG= ++CURPAG;
  150.     }
  151. }
  152. /****************************************/
  153. #if BDS
  154. /*from stdlib1.c, with minor mods*/
  155.  
  156. free(ap)
  157. struct _header *ap;
  158. {
  159.     struct _header *p, *q;
  160.     p = ap - 1;    /* No need for the cast when "ap" is a struct ptr */
  161.  
  162.     for (q = _allocp; !(p > q && p < q -> _ptr); q = q -> _ptr)
  163.         if (q >= q -> _ptr && (p > q || p < q -> _ptr))
  164.             break;
  165.     if (p + p -> _size == q -> _ptr) {
  166.         p -> _size += q -> _ptr -> _size;
  167.         p -> _ptr = q -> _ptr -> _ptr;
  168.      }
  169.     else p -> _ptr = q -> _ptr;
  170.  
  171.     if (q + q -> _size == p) {
  172.         q -> _size += p -> _size;
  173.         q -> _ptr = p -> _ptr;
  174.      }
  175.     else q -> _ptr = p;
  176.  
  177.     _allocp = q;
  178. }
  179. /******************************************/
  180. char *alloc(nbytes)
  181. unsigned nbytes;
  182. {
  183.     struct _header *p, *q, *cp;
  184.     int nunits; 
  185.     nunits = 1 + (nbytes + (sizeof (_base) - 1)) / sizeof (_base);
  186.     if ((q = _allocp) == NULL) {
  187.         _base._ptr = _allocp = q = &_base;
  188.         _base._size = 0;
  189.      }
  190.     for (p = q -> _ptr; ; q = p, p = p -> _ptr) {
  191.         if (p -> _size >= nunits) {
  192.             if (p -> _size == nunits)
  193.                 q -> _ptr = p -> _ptr;
  194.             else {
  195.                 p -> _size -= nunits;
  196.                 p += p -> _size;
  197.                 p -> _size = nunits;
  198.              }
  199.             _allocp = q;
  200.             return p + 1;
  201.          }
  202.         if (p == _allocp) {
  203.             if ((cp = sbrk(nunits * sizeof (_base))) == ERROR)
  204.                 {fprintf(STDERR,"\nCan't Allocate more buffer space.");
  205.                 return NULL;
  206.                 }
  207.             cp -> _size = nunits; 
  208.             free(cp+1);    /* remember: pointer arithmetic! */
  209.             p = _allocp;
  210.         }
  211.      }
  212. }
  213. #endif
  214.