~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/sys/gen/string.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)String (eg ``Hello world'') handling.
  2 **/
  3 #include <stdio.h>
  4 #include <sys/param.h>
  5 #include <string.h>
  6 #include <tina/sys.h>
  7 #include <tina/sysfuncs.h>
  8 
  9 #ifndef ANSIFYING
 10 #ifdef __STRICT_ANSI__
 11 
 12 char   *string_append(char *string,...)
 13 {
 14     va_list ap;
 15     char   *substring;
 16 
 17     va_start(ap, string);
 18     (void) strcpy(string, "");
 19     while ((substring = va_arg(ap, char *)) != (char *) 0)
 20         (void) strcat(string, substring);
 21     va_end(ap);
 22 
 23     return (string);
 24 }
 25 
 26 
 27 char   *string_alloc_append(char *substr0,...)
 28 {
 29     int     n = 0;
 30     va_list ap;
 31     char   *str;
 32     char   *substr;
 33 
 34     va_start(ap, substr0);
 35 
 36     for (n = 0, substr = substr0; substr; substr = va_arg(ap, char *))
 37     {
 38         n += strlen(substr);
 39     }
 40 
 41     va_end(ap);
 42 
 43     str = (char *) ralloc((unsigned) (n + 1) * sizeof(char));
 44 
 45     va_start(ap, substr0);
 46 
 47     (void) strcpy(str, "");
 48 
 49     for (substr = substr0; substr; substr = va_arg(ap, char *))
 50     {
 51         (void) strcat(str, substr);
 52     }
 53 
 54     va_end(ap);
 55 
 56     return (str);
 57 }
 58 
 59 #else
 60 
 61 char   *string_append(string, va_alist)
 62 char   *string;
 63 
 64 va_dcl
 65 {
 66     va_list ap;
 67     char   *substring;
 68 
 69     va_start(ap);
 70     (void) strcpy(string, "");
 71     while ((substring = va_arg(ap, char *)) != (char *) 0)
 72         (void) strcat(string, substring);
 73     va_end(ap);
 74 
 75     return (string);
 76 }
 77 
 78 char   *string_alloc_append(va_alist) va_dcl
 79 {
 80     int     n;
 81     va_list ap;
 82     char   *str, *substr;
 83 
 84     n = 0;
 85     va_start(ap);
 86     for (n = 0; (substr = va_arg(ap, char *)) != NULL; n += strlen(substr));
 87     va_end(ap);
 88 
 89     str = (char *) ralloc((unsigned) (n + 1) * sizeof(char));
 90 
 91     va_start(ap);
 92     (void) strcpy(str, "");
 93     while ((substr = va_arg(ap, char *)) != (char *) 0)
 94         (void) strcat(str, substr);
 95     va_end(ap);
 96 
 97     return (str);
 98 }
 99 
100 #endif                          /* __STRICT_ANSI__ */
101 #endif                          /* ANSIFYING */
102 
103 char   *string_copy(char *string)
104 {
105     char   *copy;
106 
107     copy = (char *) ralloc((unsigned) strlen(string) + 1);
108     (void) strcpy(copy, string);
109     return (copy);
110 }
111 
112 static int isspace(int c)
113 {
114     return (c == ' ' || c == '\n');
115 }
116 
117 int     freadline(FILE * fp, char *string)
118 {
119     int     c;
120     int     i = 0;
121 
122     while (isspace(c = getc(fp)));
123 
124     if (c == EOF)
125         return (EOF);
126     do
127     {
128         string[i++] = c;
129     } while ((c = getc(fp)) != '\n' && c != EOF && i<MAXPATHLEN-1);
130     string[i++] = '\0';
131     return (i);
132 }
133 
134 int     read_into_int(int *x, char *string, char *msg)
135 {
136     int     y;
137     char    temps[256];
138 
139     if (sscanf(string, "%d", &y) == 1)
140     {
141         *x = y;
142         message(string_append(temps, msg, string, "\n", 0));
143         return (1);
144     }
145     message("read_into_int: string not an int\n");
146     return (0);
147 }
148 
149 int     read_into_short(short int *x, char *string, char *msg)
150 {
151     short   y;
152     char    temps[256];
153 
154     if (sscanf(string, "%hd", &y) == 1)
155     {
156         *x = y;
157         message(string_append(temps, msg, string, "\n", 0));
158         return (1);
159     }
160     message("read_into_short: string not a short\n");
161     return (0);
162 }
163 
164 int     read_into_float(float *x, char *string, char *msg)
165 {
166     float   y;
167     char    temps[256];
168 
169     if (sscanf(string, "%f", &y) == 1)
170     {
171         *x = y;
172         message(string_append(temps, msg, string, "\n", 0));
173         return (1);
174     }
175     message("read_into_float: string not a float\n");
176     return (0);
177 }
178 
179 int     read_into_double(double *x, char *string, char *msg)
180 {
181     double  y;
182     char    temps[256];
183 
184     if (sscanf(string, "%lf", &y) == 1)
185     {
186         *x = y;
187         message(string_append(temps, msg, string, "\n", 0));
188         return (1);
189     }
190     message("read_into_double: string not a float\n");
191     return (0);
192 }
193 
194 int     read_into_string(char *x, char *string, char *msg)
195 {
196     char    temps[256];
197 
198     (void) strcpy(x, string);
199     message(string_append(temps, msg, string, "\n", 0));
200     return (1);
201 }
202 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.