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
str_free defined in line 110; used 2 times
str_ncpy defined in line 31; used 2 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1985-04-25
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1088
Valid CSS Valid XHTML 1.0 Strict