Annotation of 41BSD/cmd/cifplot/string.c, revision 1.1.1.1

1.1       root        1: /*******************************************************************
                      2: *                                                                  *
                      3: *    File: CIFPLOT/string.c                                        *
                      4: *    Written by Dan Fitzpatrick                                    *
                      5: *    copyright 1980 -- Regents of the University of California     *
                      6: *                                                                  *
                      7: ********************************************************************/
                      8: 
                      9: 
                     10: #include <stdio.h>
                     11: #include "defs.h"
                     12: #include "globals.h"
                     13: 
                     14: IMPORT alloc();
                     15: 
                     16: string
                     17: CatString(s1,s2)
                     18: string s1,s2;
                     19: /* Concatenate 's1' & 's2' */
                     20: {
                     21:     string p;
                     22:     int i,j;
                     23:     p = (char *) alloc(LengthString(s1)+LengthString(s2)-1);
                     24:     for (i=0; '\0' != (p[i] = s1[i]);) i++;
                     25:     for (j=0; '\0' != (p[i++] = s2[j++]););
                     26:     return(p);
                     27:     }
                     28: 
                     29: string
                     30: Concat(args)
                     31: /* Concatenate an arbitrary number of arguments terminated by a 0 */
                     32: {
                     33:     string s,t;
                     34:     union {
                     35:        string *p;
                     36:        int *a;
                     37:        } x;
                     38: 
                     39:     s = CatString("","");
                     40:     x.a = &args;
                     41: 
                     42:     while (*(x.p) != 0) {
                     43:        t = CatString(s,*(x.p++));
                     44:        Free(s);
                     45:        s = t;
                     46:        }
                     47:     return(s);
                     48:     }
                     49: 
                     50: LengthString(s)
                     51: string s;
                     52: /* Return the length of the string 's' */
                     53: {
                     54:     int i;
                     55:     for (i=0; '\0' != s[i++];);
                     56:     return(i+1);
                     57:     }
                     58: 
                     59: string 
                     60: MakeString(c)
                     61: char c;
                     62: /* Return a string that contains only the character in 'c' */
                     63: {
                     64:     char s[2];
                     65:     s[0] = c;
                     66:     s[1] = '\0';
                     67:     return(Concat(s,0));
                     68:     }
                     69: 
                     70: char *
                     71: strip(s)
                     72: char *s;
                     73: /* Returns a pointer to the string of characters in 's'
                     74:  * without leading or trailing white spaces */
                     75: {
                     76:    char *t;
                     77:    while (*s == ' ' || *s == '\t' || *s == '\n') s++;
                     78:    t = s;
                     79:    while (*t != ' ' && *t != '\t' && *t != '\n' && *t != 0) t++;
                     80:    *t = 0;
                     81:    return(s);
                     82:    }
                     83: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.