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

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