# 2.11BSD#431 - /usr/src/ucb/window/string.c

##### Functions

    str_alloc         X
    str_cat           X
    str_cpy           X
    str_free          X
    str_itoa          X
    str_match         X
    str_ncpy          X

       1: #ifndef lint
       2: static char sccsid[] = "@(#)string.c	3.8 4/24/85";
       3: #endif
       4:
       5: /*
       6:  * Copyright (c) 1983 Regents of the University of California,
       7:  * All rights reserved.  Redistribution permitted subject to
       8:  * the terms of the Berkeley Software License Agreement.
       9:  */
      10:
      11: #include "string.h"
      12:
      13: char *malloc();
      14: char *sprintf();
      15:
      16: char *
      17: str_cpy(s)
      18: register char *s;
      19: {
      20:     char *str;
      21:     register char *p;
      22:
      23:     str = p = str_alloc(strlen(s) + 1);
      24:     if (p == 0)
      25:         return 0;
      26:     while (*p++ = *s++)
      27:         ;
      28:     return str;
      29: }
      30:
      31: char *
      32: str_ncpy(s, n)
      33: register char *s;
      34: register n;
      35: {
      36:     int l = strlen(s);
      37:     char *str;
      38:     register char *p;
      39:
      40:     if (n > l)
      41:         n = l;
      42:     str = p = str_alloc(n + 1);
      43:     if (p == 0)
      44:         return 0;
      45:     while (--n >= 0)
      46:         *p++ = *s++;
      47:     *p = 0;
      48:     return str;
      49: }
      50:
      51: char *
      52: str_itoa(i)
      53: int i;
      54: {
      55:     char buf[30];
      56:
      57:     (void) sprintf(buf, "%d", i);
      58:     return str_cpy(buf);
      59: }
      60:
      61: char *
      62: str_cat(s1, s2)
      63: char *s1, *s2;
      64: {
      65:     char *str;
      66:     register char *p, *q;
      67:
      68:     str = p = str_alloc(strlen(s1) + strlen(s2) + 1);
      69:     if (p == 0)
      70:         return 0;
      71:     for (q = s1; *p++ = *q++;)
      72:         ;
      73:     for (q = s2, p--; *p++ = *q++;)
      74:         ;
      75:     return str;
      76: }
      77:
      78: /*
      79:  * match s against p.
      80:  * s can be a prefix of p with at least min characters.
      81:  */
      82: str_match(s, p, min)
      83: register char *s, *p;
      84: register min;
      85: {
      86:     for (; *s && *p && *s == *p; s++, p++, min--)
      87:         ;
      88:     return *s == *p || *s == 0 && min <= 0;
      89: }
      90:
      91: #ifdef STR_DEBUG
      92: char *
      93: str_alloc(l)
      94: int l;
      95: {
      96:     register struct string *s;
      97:
      98:     s = (struct string *) malloc((unsigned)l + str_offset);
      99:     if (s == 0)
     100:         return 0;
     101:     if (str_head.s_forw == 0)
     102:         str_head.s_forw = str_head.s_back = &str_head;
     103:     s->s_forw = str_head.s_forw;
     104:     s->s_back = &str_head;
     105:     str_head.s_forw = s;
     106:     s->s_forw->s_back = s;
     107:     return s->s_data;
     108: }
     109:
     110: str_free(str)
     111: char *str;
     112: {
     113:     register struct string *s;
     114:
     115:     for (s = str_head.s_forw; s != &str_head && s->s_data != str;
     116:          s = s->s_forw)
     117:         ;
     118:     if (s == &str_head)
     119:         abort();
     120:     s->s_back->s_forw = s->s_forw;
     121:     s->s_forw->s_back = s->s_back;
     122:     free((char *)s);
     123: }
     124: #endif

#### Defined functions

str_alloc defined in line 92; never used
str_cat defined in line 61; used 2 times

- in /usr/src/ucb/window/parser4.c line 244
- in /usr/src/ucb/window/string.h line 15

str_cpy defined in line 16; used 14 times

- in line 58
- in /usr/src/ucb/window/cmd3.c line 63
- in /usr/src/ucb/window/context.c line 57
- in /usr/src/ucb/window/lcmd1.c line 142
- in /usr/src/ucb/window/lcmd2.c line 211, 226, 262
- in /usr/src/ucb/window/main.c line 93
- in /usr/src/ucb/window/parser4.c line 237
- in /usr/src/ucb/window/parser5.c line 95
- in /usr/src/ucb/window/scanner.c line 275
- in /usr/src/ucb/window/string.h line 13
- in /usr/src/ucb/window/var.c line 30, 38

str_free defined in line 110; used 2 times

- in /usr/src/ucb/window/value.h line 25
- in /usr/src/ucb/window/win.c line 105

str_itoa defined in line 51; used 4 times

- in /usr/src/ucb/window/lcmd1.c line 300
- in /usr/src/ucb/window/lcmd2.c line 226
- in /usr/src/ucb/window/parser1.c line 161
- in /usr/src/ucb/window/string.h line 16

str_match defined in line 82; used 10 times

- in /usr/src/ucb/window/lcmd.c line 89
- in /usr/src/ucb/window/lcmd1.c line 263, 342-348(6)
- in /usr/src/ucb/window/lcmd2.c line 79
- in /usr/src/ucb/window/parser2.c line 91

str_ncpy defined in line 31; used 2 times

- in /usr/src/ucb/window/parser4.c line 225
- in /usr/src/ucb/window/string.h line 14

#### Defined variables

sccsid defined in line 2; never used

Last modified: 1987-02-17 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 812 |