# 2.11BSD#431 - /usr/src/new/PORT/perl.1.0.0/x2p/str.c

##### Functions

    str_2num          X
    str_2ptr          X
    str_append_till   X
    str_cat           X
    str_chop          X
    str_dec           X
    str_free          X
    str_gets          X
    str_grow          X
    str_inc           X
    str_len           X
    str_make          X
    str_ncat          X
    str_new           X
    str_nmake         X
    str_nset          X
    str_numset        X
    str_replace       X
    str_scat          X
    str_set           X
    str_sset          X
    str_static        X

       1: /* $Header: str.c,v 1.0 87/12/18 13:07:26 root Exp $
       2:  *
       3:  * $Log:	str.c,v $
       4:  * Revision 1.0  87/12/18  13:07:26  root
       5:  * Initial revision
       6:  *
       7:  */
       8:
       9: #include "handy.h"
      10: #include "EXTERN.h"
      11: #include "util.h"
      12: #include "a2p.h"
      13:
      14: str_numset(str,num)
      15: register STR *str;
      16: double num;
      17: {
      18:     str->str_nval = num;
      19:     str->str_pok = 0;       /* invalidate pointer */
      20:     str->str_nok = 1;       /* validate number */
      21: }
      22:
      23: char *
      24: str_2ptr(str)
      25: register STR *str;
      26: {
      27:     register char *s;
      28:
      29:     if (!str)
      30:     return "";
      31:     GROWSTR(&(str->str_ptr), &(str->str_len), 24);
      32:     s = str->str_ptr;
      33:     if (str->str_nok) {
      34:     sprintf(s,"%.20g",str->str_nval);
      35:     while (*s) s++;
      36:     }
      37:     *s = '\0';
      38:     str->str_cur = s - str->str_ptr;
      39:     str->str_pok = 1;
      40: #ifdef DEBUGGING
      41:     if (debug & 32)
      42:     fprintf(stderr,"0x%lx ptr(%s)\n",str,str->str_ptr);
      43: #endif
      44:     return str->str_ptr;
      45: }
      46:
      47: double
      48: str_2num(str)
      49: register STR *str;
      50: {
      51:     if (!str)
      52:     return 0.0;
      53:     if (str->str_len && str->str_pok)
      54:     str->str_nval = atof(str->str_ptr);
      55:     else
      56:     str->str_nval = 0.0;
      57:     str->str_nok = 1;
      58: #ifdef DEBUGGING
      59:     if (debug & 32)
      60:     fprintf(stderr,"0x%lx num(%g)\n",str,str->str_nval);
      61: #endif
      62:     return str->str_nval;
      63: }
      64:
      65: str_sset(dstr,sstr)
      66: STR *dstr;
      67: register STR *sstr;
      68: {
      69:     if (!sstr)
      70:     str_nset(dstr,No,0);
      71:     else if (sstr->str_nok)
      72:     str_numset(dstr,sstr->str_nval);
      73:     else if (sstr->str_pok)
      74:     str_nset(dstr,sstr->str_ptr,sstr->str_cur);
      75:     else
      76:     str_nset(dstr,"",0);
      77: }
      78:
      79: str_nset(str,ptr,len)
      80: register STR *str;
      81: register char *ptr;
      82: register int len;
      83: {
      84:     GROWSTR(&(str->str_ptr), &(str->str_len), len + 1);
      85:     bcopy(ptr,str->str_ptr,len);
      86:     str->str_cur = len;
      87:     *(str->str_ptr+str->str_cur) = '\0';
      88:     str->str_nok = 0;       /* invalidate number */
      89:     str->str_pok = 1;       /* validate pointer */
      90: }
      91:
      92: str_set(str,ptr)
      93: register STR *str;
      94: register char *ptr;
      95: {
      96:     register int len;
      97:
      98:     if (!ptr)
      99:     ptr = "";
     100:     len = strlen(ptr);
     101:     GROWSTR(&(str->str_ptr), &(str->str_len), len + 1);
     102:     bcopy(ptr,str->str_ptr,len+1);
     103:     str->str_cur = len;
     104:     str->str_nok = 0;       /* invalidate number */
     105:     str->str_pok = 1;       /* validate pointer */
     106: }
     107:
     108: str_chop(str,ptr)   /* like set but assuming ptr is in str */
     109: register STR *str;
     110: register char *ptr;
     111: {
     112:     if (!(str->str_pok))
     113:     str_2ptr(str);
     114:     str->str_cur -= (ptr - str->str_ptr);
     115:     bcopy(ptr,str->str_ptr, str->str_cur + 1);
     116:     str->str_nok = 0;       /* invalidate number */
     117:     str->str_pok = 1;       /* validate pointer */
     118: }
     119:
     120: str_ncat(str,ptr,len)
     121: register STR *str;
     122: register char *ptr;
     123: register int len;
     124: {
     125:     if (!(str->str_pok))
     126:     str_2ptr(str);
     127:     GROWSTR(&(str->str_ptr), &(str->str_len), str->str_cur + len + 1);
     128:     bcopy(ptr,str->str_ptr+str->str_cur,len);
     129:     str->str_cur += len;
     130:     *(str->str_ptr+str->str_cur) = '\0';
     131:     str->str_nok = 0;       /* invalidate number */
     132:     str->str_pok = 1;       /* validate pointer */
     133: }
     134:
     135: str_scat(dstr,sstr)
     136: STR *dstr;
     137: register STR *sstr;
     138: {
     139:     if (!(sstr->str_pok))
     140:     str_2ptr(sstr);
     141:     if (sstr)
     142:     str_ncat(dstr,sstr->str_ptr,sstr->str_cur);
     143: }
     144:
     145: str_cat(str,ptr)
     146: register STR *str;
     147: register char *ptr;
     148: {
     149:     register int len;
     150:
     151:     if (!ptr)
     152:     return;
     153:     if (!(str->str_pok))
     154:     str_2ptr(str);
     155:     len = strlen(ptr);
     156:     GROWSTR(&(str->str_ptr), &(str->str_len), str->str_cur + len + 1);
     157:     bcopy(ptr,str->str_ptr+str->str_cur,len+1);
     158:     str->str_cur += len;
     159:     str->str_nok = 0;       /* invalidate number */
     160:     str->str_pok = 1;       /* validate pointer */
     161: }
     162:
     163: char *
     164: str_append_till(str,from,delim,keeplist)
     165: register STR *str;
     166: register char *from;
     167: register int delim;
     168: char *keeplist;
     169: {
     170:     register char *to;
     171:     register int len;
     172:
     173:     if (!from)
     174:     return Nullch;
     175:     len = strlen(from);
     176:     GROWSTR(&(str->str_ptr), &(str->str_len), str->str_cur + len + 1);
     177:     str->str_nok = 0;       /* invalidate number */
     178:     str->str_pok = 1;       /* validate pointer */
     179:     to = str->str_ptr+str->str_cur;
     180:     for (; *from; from++,to++) {
     181:     if (*from == '\\' && from[1] && delim != '\\') {
     182:         if (!keeplist) {
     183:         if (from[1] == delim || from[1] == '\\')
     184:             from++;
     185:         else
     186:             *to++ = *from++;
     187:         }
     188:         else if (index(keeplist,from[1]))
     189:         *to++ = *from++;
     190:         else
     191:         from++;
     192:     }
     193:     else if (*from == delim)
     194:         break;
     195:     *to = *from;
     196:     }
     197:     *to = '\0';
     198:     str->str_cur = to - str->str_ptr;
     199:     return from;
     200: }
     201:
     202: STR *
     203: str_new(len)
     204: int len;
     205: {
     206:     register STR *str;
     207:
     208:     if (freestrroot) {
     209:     str = freestrroot;
     210:     freestrroot = str->str_link.str_next;
     211:     }
     212:     else {
     213:     str = (STR *) safemalloc(sizeof(STR));
     214:     bzero((char*)str,sizeof(STR));
     215:     }
     216:     if (len)
     217:     GROWSTR(&(str->str_ptr), &(str->str_len), len + 1);
     218:     return str;
     219: }
     220:
     221: void
     222: str_grow(str,len)
     223: register STR *str;
     224: int len;
     225: {
     226:     if (len && str)
     227:     GROWSTR(&(str->str_ptr), &(str->str_len), len + 1);
     228: }
     229:
     230: /* make str point to what nstr did */
     231:
     232: void
     233: str_replace(str,nstr)
     234: register STR *str;
     235: register STR *nstr;
     236: {
     237:     safefree(str->str_ptr);
     238:     str->str_ptr = nstr->str_ptr;
     239:     str->str_len = nstr->str_len;
     240:     str->str_cur = nstr->str_cur;
     241:     str->str_pok = nstr->str_pok;
     242:     if (str->str_nok = nstr->str_nok)
     243:     str->str_nval = nstr->str_nval;
     244:     safefree((char*)nstr);
     245: }
     246:
     247: void
     248: str_free(str)
     249: register STR *str;
     250: {
     251:     if (!str)
     252:     return;
     253:     if (str->str_len)
     254:     str->str_ptr[0] = '\0';
     255:     str->str_cur = 0;
     256:     str->str_nok = 0;
     257:     str->str_pok = 0;
     258:     str->str_link.str_next = freestrroot;
     259:     freestrroot = str;
     260: }
     261:
     262: str_len(str)
     263: register STR *str;
     264: {
     265:     if (!str)
     266:     return 0;
     267:     if (!(str->str_pok))
     268:     str_2ptr(str);
     269:     if (str->str_len)
     270:     return str->str_cur;
     271:     else
     272:     return 0;
     273: }
     274:
     275: char *
     276: str_gets(str,fp)
     277: register STR *str;
     278: register FILE *fp;
     279: {
     280: #ifdef STDSTDIO     /* Here is some breathtakingly efficient cheating */
     281:
     282:     register char *bp;      /* we're going to steal some values */
     283:     register int cnt;       /*  from the stdio struct and put EVERYTHING */
     284:     register char *ptr;     /*   in the innermost loop into registers */
     285:     register char newline = '\n';   /* (assuming at least 6 registers) */
     286:     int i;
     287:     int bpx;
     288:
     289:     cnt = fp->_cnt;         /* get count into register */
     290:     str->str_nok = 0;           /* invalidate number */
     291:     str->str_pok = 1;           /* validate pointer */
     292:     if (str->str_len <= cnt)        /* make sure we have the room */
     293:     GROWSTR(&(str->str_ptr), &(str->str_len), cnt+1);
     294:     bp = str->str_ptr;          /* move these two too to registers */
     295:     ptr = fp->_ptr;
     296:     for (;;) {
     297:     while (--cnt >= 0) {            /* this */  /* eat */
     298:         if ((*bp++ = *ptr++) == newline)    /* really */    /* dust */
     299:         goto thats_all_folks;       /* screams */   /* sed :-) */
     300:     }
     301:
     302:     fp->_cnt = cnt;         /* deregisterize cnt and ptr */
     303:     fp->_ptr = ptr;
     304:     i = _filbuf(fp);        /* get more characters */
     305:     cnt = fp->_cnt;
     306:     ptr = fp->_ptr;         /* reregisterize cnt and ptr */
     307:
     308:     bpx = bp - str->str_ptr;    /* prepare for possible relocation */
     309:     GROWSTR(&(str->str_ptr), &(str->str_len), str->str_cur + cnt + 1);
     310:     bp = str->str_ptr + bpx;    /* reconstitute our pointer */
     311:
     312:     if (i == newline) {     /* all done for now? */
     313:         *bp++ = i;
     314:         goto thats_all_folks;
     315:     }
     316:     else if (i == EOF)      /* all done for ever? */
     317:         goto thats_all_folks;
     318:     *bp++ = i;          /* now go back to screaming loop */
     319:     }
     320:
     321: thats_all_folks:
     322:     fp->_cnt = cnt;         /* put these back or we're in trouble */
     323:     fp->_ptr = ptr;
     324:     *bp = '\0';
     325:     str->str_cur = bp - str->str_ptr;   /* set length */
     326:
     327: #else /* !STDSTDIO */   /* The big, slow, and stupid way */
     328:
     329:     static char buf[4192];
     330:
     331:     if (fgets(buf, sizeof buf, fp) != Nullch)
     332:     str_set(str, buf);
     333:     else
     334:     str_set(str, No);
     335:
     336: #endif /* STDSTDIO */
     337:
     338:     return str->str_cur ? str->str_ptr : Nullch;
     339: }
     340:
     341: void
     342: str_inc(str)
     343: register STR *str;
     344: {
     345:     register char *d;
     346:
     347:     if (!str)
     348:     return;
     349:     if (str->str_nok) {
     350:     str->str_nval += 1.0;
     351:     str->str_pok = 0;
     352:     return;
     353:     }
     354:     if (!str->str_pok) {
     355:     str->str_nval = 1.0;
     356:     str->str_nok = 1;
     357:     return;
     358:     }
     359:     for (d = str->str_ptr; *d && *d != '.'; d++) ;
     360:     d--;
     361:     if (!isdigit(*str->str_ptr) || !isdigit(*d) ) {
     362:         str_numset(str,atof(str->str_ptr) + 1.0);  /* punt */
     363:     return;
     364:     }
     365:     while (d >= str->str_ptr) {
     366:     if (++*d <= '9')
     367:         return;
     368:     *(d--) = '0';
     369:     }
     370:     /* oh,oh, the number grew */
     371:     GROWSTR(&(str->str_ptr), &(str->str_len), str->str_cur + 2);
     372:     str->str_cur++;
     373:     for (d = str->str_ptr + str->str_cur; d > str->str_ptr; d--)
     374:     *d = d[-1];
     375:     *d = '1';
     376: }
     377:
     378: void
     379: str_dec(str)
     380: register STR *str;
     381: {
     382:     register char *d;
     383:
     384:     if (!str)
     385:     return;
     386:     if (str->str_nok) {
     387:     str->str_nval -= 1.0;
     388:     str->str_pok = 0;
     389:     return;
     390:     }
     391:     if (!str->str_pok) {
     392:     str->str_nval = -1.0;
     393:     str->str_nok = 1;
     394:     return;
     395:     }
     396:     for (d = str->str_ptr; *d && *d != '.'; d++) ;
     397:     d--;
     398:     if (!isdigit(*str->str_ptr) || !isdigit(*d) || (*d == '0' && d == str->str_ptr)) {
     399:         str_numset(str,atof(str->str_ptr) - 1.0);  /* punt */
     400:     return;
     401:     }
     402:     while (d >= str->str_ptr) {
     403:     if (--*d >= '0')
     404:         return;
     405:     *(d--) = '9';
     406:     }
     407: }
     408:
     409: /* make a string that will exist for the duration of the expression eval */
     410:
     411: STR *
     412: str_static(oldstr)
     413: STR *oldstr;
     414: {
     415:     register STR *str = str_new(0);
     416:     static long tmps_size = -1;
     417:
     418:     str_sset(str,oldstr);
     419:     if (++tmps_max > tmps_size) {
     420:     tmps_size = tmps_max;
     421:     if (!(tmps_size & 127)) {
     422:         if (tmps_size)
     423:         tmps_list = (STR**)saferealloc((char*)tmps_list,
     424:             (tmps_size + 128) * sizeof(STR*) );
     425:         else
     426:         tmps_list = (STR**)safemalloc(128 * sizeof(char*));
     427:     }
     428:     }
     429:     tmps_list[tmps_max] = str;
     430:     return str;
     431: }
     432:
     433: STR *
     434: str_make(s)
     435: char *s;
     436: {
     437:     register STR *str = str_new(0);
     438:
     439:     str_set(str,s);
     440:     return str;
     441: }
     442:
     443: STR *
     444: str_nmake(n)
     445: double n;
     446: {
     447:     register STR *str = str_new(0);
     448:
     449:     str_numset(str,n);
     450:     return str;
     451: }

#### Defined functions

str_2num defined in line 47; used 2 times

- in /usr/src/new/PORT/perl.1.0.0/x2p/a2p.h line 192
- in /usr/src/new/PORT/perl.1.0.0/x2p/str.h line 31

str_2ptr defined in line 23; used 7 times

- in line 113, 126, 140, 154, 268
- in /usr/src/new/PORT/perl.1.0.0/x2p/a2p.h line 191
- in /usr/src/new/PORT/perl.1.0.0/x2p/str.h line 30

str_append_till defined in line 163; never used
str_cat defined in line 145; used 132 times

- in /usr/src/new/PORT/perl.1.0.0/x2p/a2py.c line 120, 854
- in /usr/src/new/PORT/perl.1.0.0/x2p/walk.c line 54, 63-93(12), 115-127(5), 162, 186-188(2), 194-197(2), 205-210(2), 223-227(2), 233, 249-254(2), 261, 298-307(4), 318-330(4), 341-345(2), 351, 357, 366, 373, 380, 387, 394, 401-406(2), 438, 446, 457, 464-467(2), 473-474(2), 489, 498, 506-517(6), 526-529(2), 548, 570-575(3), 583, 591-594(2), 614, 649, 671, 698-714(11), 723, 733-739(4), 746, 754, 760-768(3), 797-801(2), 807, 813-827(4), 842, 854-856(2), 870, 887-892(2), 903, 920, 929-932(2), 940, 964-966(2), 984, 1027-1031(2), 1048, 1062, 1072-1074(2), 1080, 1086-1095(4)

str_chop defined in line 108; never used
str_dec defined in line 378; never used
str_free defined in line 247; used 85 times

- in /usr/src/new/PORT/perl.1.0.0/x2p/a2p.h line 202
- in /usr/src/new/PORT/perl.1.0.0/x2p/a2py.c line 119-123(2), 856
- in /usr/src/new/PORT/perl.1.0.0/x2p/walk.c line 83, 113, 121, 152-155(2), 164, 187, 196, 208, 222, 229, 235, 241, 247, 256, 263, 269, 306-309(2), 316, 328-332(2), 339, 347, 356-359(2), 368, 375, 382, 389, 396, 413, 420, 427, 437, 456, 463-470(3), 502, 514-519(2), 525-528(2), 547, 577, 585, 593, 613, 635, 644, 651, 660, 666, 673, 715-716(2), 726-727(2), 770, 826, 845, 853, 869-872(2), 889-894(2), 902-905(2), 927-934(4), 956-970(5), 977-981(2), 995

str_gets defined in line 275; used 2 times

- in /usr/src/new/PORT/perl.1.0.0/x2p/a2py.c line 164
- in /usr/src/new/PORT/perl.1.0.0/x2p/str.h line 35

str_grow defined in line 221; never used
str_inc defined in line 341; never used
str_len defined in line 262; used 19 times

- in line 31, 53, 84, 101, 127, 156, 176, 217, 227, 239(2), 253, 269, 292-293(2), 309, 371
- in /usr/src/new/PORT/perl.1.0.0/x2p/walk.c line 354, 492

str_make defined in line 433; used 11 times

- in /usr/src/new/PORT/perl.1.0.0/x2p/a2py.c line 116, 855
- in /usr/src/new/PORT/perl.1.0.0/x2p/str.h line 33
- in /usr/src/new/PORT/perl.1.0.0/x2p/walk.c line 40, 773-785(5), 821, 1461

str_ncat defined in line 120; used 1 times

- in line 142

str_new defined in line 202; used 48 times

- in line 415, 437, 447
- in /usr/src/new/PORT/perl.1.0.0/x2p/a2p.h line 197
- in /usr/src/new/PORT/perl.1.0.0/x2p/a2py.c line 25-26(2)
- in /usr/src/new/PORT/perl.1.0.0/x2p/walk.c line 48, 169, 192, 202, 219, 238, 244, 266, 313, 336, 410, 417, 424, 434, 442, 453, 460, 477-481(2), 522, 544, 551, 588, 606, 619-629(3), 639, 654, 663, 679, 791, 830-838(3), 860, 866, 899, 908, 938, 973, 1004

str_nmake defined in line 443; used 1 times

- in /usr/src/new/PORT/perl.1.0.0/x2p/str.h line 34

str_nset defined in line 79; used 3 times

- in line 70-76(3)

str_numset defined in line 14; used 4 times

- in line 72, 362, 399, 449

str_replace defined in line 232; never used
str_scat defined in line 135; used 78 times

- in /usr/src/new/PORT/perl.1.0.0/x2p/a2py.c line 118-122(2)
- in /usr/src/new/PORT/perl.1.0.0/x2p/walk.c line 82, 112, 120, 151-154(2), 163, 195, 204-207(2), 221, 228, 234, 240, 246, 255, 262, 268, 305-308(2), 315, 327-331(2), 338, 346, 353-358(2), 367, 374, 381, 388, 395, 412, 419, 426, 436, 455, 462-469(3), 488, 501, 513, 524-527(2), 546, 553, 576, 592, 612, 634, 643, 650, 659, 665, 703, 765, 825, 844, 852, 868-871(2), 888-893(2), 901-904(2), 910, 926-933(3), 957-967(4), 976-980(2), 994

str_set defined in line 92; used 52 times

- in line 332-334(2), 439
- in /usr/src/new/PORT/perl.1.0.0/x2p/walk.c line 170, 203, 220, 239, 245, 267, 281-291(6), 314, 337, 362, 411, 418, 425, 435, 443, 454, 461, 478, 485-487(2), 523, 545, 552, 560-567(3), 590, 602-607(2), 620-630(3), 655, 831-840(3), 850, 861, 867, 900, 909, 955, 961, 974

str_sset defined in line 65; used 2 times

- in line 418
- in /usr/src/new/PORT/perl.1.0.0/x2p/walk.c line 939

str_static defined in line 411; used 1 times

- in /usr/src/new/PORT/perl.1.0.0/x2p/str.h line 32

Last modified: 1988-01-31 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 2063 |