home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / pi1 / string.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  2KB  |  159 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #
  3. /*
  4.  * pi - Pascal interpreter code translator
  5.  *
  6.  * Charles Haley, Bill Joy UCB
  7.  * Version 1.2 January 1979
  8.  *
  9.  * pxp - Pascal execution profiler
  10.  *
  11.  * Bill Joy UCB
  12.  * Version 1.2 January 1979
  13.  */
  14.  
  15. #include "0.h"
  16. #ifndef PI01
  17. #ifndef PXP
  18. #include "send.h"
  19. #endif
  20. #endif
  21.  
  22. /*
  23.  * STRING SPACE DECLARATIONS
  24.  *
  25.  * Strng is the base of the current
  26.  * string space and strngp the
  27.  * base of the free area therein.
  28.  * Strp is the array of descriptors.
  29.  */
  30. #ifndef PI0
  31. static    char strings[STRINC];
  32. static    char *strng strings;
  33. static    char *strngp strings;
  34. #else
  35. char    *strng, *strngp;
  36. #endif
  37. #ifndef PI01
  38. #ifndef PXP
  39. static    char *strp[20];
  40. static    char **stract strp;
  41. int    strmax;
  42. #endif
  43. #endif
  44.  
  45. #ifndef PI01
  46. #ifndef PXP
  47. #ifndef PI0
  48. initstring()
  49. #else
  50. initstring(strings)
  51.     char *strings;
  52. #endif
  53. {
  54.  
  55.     *stract++ = strings;
  56. #ifdef PI0
  57.     strng = strngp = strings;
  58. #endif
  59.     strmax = STRINC * 2;
  60. }
  61. #endif
  62. #endif
  63.  
  64. /*
  65.  * Copy a string into the string area.
  66.  */
  67. savestr(cp)
  68.     register char *cp;
  69. {
  70.     register int i;
  71.  
  72.     i = strlen(cp) + 1;
  73.     if (strngp + i >= strng + STRINC) {
  74.         strngp = alloc(STRINC);
  75.         if (strngp == -1) {
  76.             yerror("Ran out of memory (string)");
  77.             pexit(DIED);
  78.         }
  79. #ifndef PI01
  80. #ifndef PXP
  81.         *stract++ = strngp;
  82.         strmax =+ STRINC;
  83. #endif
  84. #endif
  85.         strng = strngp;
  86.     }
  87.     strcpy(strngp, cp);
  88.     cp = strngp;
  89.     strngp = cp + i;
  90. #ifdef PI0
  91.     send(RSTRING, cp);
  92. #endif
  93.     return (cp);
  94. }
  95.  
  96. #ifndef PI1
  97. #ifndef PXP
  98. esavestr(cp)
  99.     char *cp;
  100. {
  101.  
  102. #ifdef PI0
  103.     send(REVENIT);
  104. #endif
  105.     strngp = (strngp + 1) &~ 1;
  106.     return (savestr(cp));
  107. }
  108. #endif
  109. #endif
  110.  
  111. #ifndef PI01
  112. #ifndef PXP
  113. soffset(cp)
  114.     register char *cp;
  115. {
  116.     register char **sp;
  117.     register int i;
  118.  
  119.     if (cp == NIL || cp == OCT || cp == HEX)
  120.         return (-cp);
  121.     for (i = STRINC, sp = strp; sp < stract; sp++) {
  122.         if (cp >= *sp && cp < (*sp + STRINC))
  123.             return (i + (cp - *sp));
  124.         i =+ STRINC;
  125.     }
  126.     i = nlfund(cp);
  127.     if (i != 0)
  128.         return (i);
  129.     panic("soffset");
  130. }
  131. #ifdef PI1
  132. sreloc(i)
  133.     register int i;
  134. {
  135.  
  136.     if (i == 0 || i == -OCT || i == -HEX)
  137.         return (-i);
  138.     if (i < STRINC) {
  139.         if (i >= INL)
  140.             panic("sreloc INL");
  141.         i = nl[i].symbol;
  142.         if (i == 0)
  143.             panic("sreloc nl[i]");
  144.         return (i);
  145.     }
  146.     if (i > strmax || i < 0)
  147.         panic("sreloc");
  148.     return (strp[(i / STRINC) - 1] + (i % STRINC));
  149. }
  150.  
  151. evenit()
  152. {
  153.  
  154.     strngp = (strngp + 1) &~ 1;
  155. }
  156. #endif
  157. #endif
  158. #endif
  159.