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

Linux Cross Reference
Tina6/tina-libs/tina/sys/sysGen_string.c

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

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/sys/sysGen_string.c,v $
 37  * Date    :  $Date: 2003/09/22 16:09:02 $
 38  * Version :  $Revision: 1.8 $
 39  * CVS Id  :  $Id: sysGen_string.c,v 1.8 2003/09/22 16:09:02 tony Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  */
 43 /**
 44  *  @file Basic character string manipulation routines for file name construction.
 45  *
 46  *********
 47 */
 48 
 49 #include "sysGen_string.h"
 50 
 51 #if HAVE_CONFIG_H
 52   #include <config.h>
 53 #endif
 54 
 55 #include <stdio.h>
 56 #include <string.h>
 57 
 58 /* ipoole */
 59 #if HAVE_SYS_PARAM_H
 60 #include <sys/param.h>
 61 #else
 62 #define MAXPATHLEN 255
 63 #endif
 64 
 65 #if HAVE_STDARG_H
 66 #  include <stdarg.h>
 67 #  define VA_START(a, f)                va_start(a, f)
 68 #else
 69 #  if HAVE_VARARGS_H
 70 #    include <varargs.h>
 71 #    define VA_START(a, f)  va_start(a)
 72 #  endif
 73 #endif /* HAVE_STDARG_H */
 74 #ifndef VA_START
 75   error no variadic api available
 76 #endif
 77 
 78 #include <tina/sys/sysMem_ralloc.h>
 79 #include <tina/sys/sysGen_messages.h>
 80 
 81 
 82 char
 83 #if HAVE_STDARG_H
 84 *string_append(char *string, ...)
 85 #else
 86 *string_append(string, va_alist)
 87         char *string;
 88         va_dcl
 89 #endif /* HAVE_STDARG_H */
 90 {
 91         va_list ap;
 92         char *substring;
 93 
 94         VA_START(ap, string);
 95         (void) strcpy(string, "");
 96         while ((substring = va_arg(ap, char *)) != (char *) 0)
 97                  (void) strcat(string, substring);
 98         va_end(ap);
 99 
100         return (string);
101 }
102 
103 
104 char 
105 #if HAVE_STDARG_H
106 *string_alloc_append(char *substr0, ...)
107 #else
108 *string_alloc_append(substr0,va_alist)
109         char *substr0;
110         va_dcl
111 #endif /* HAVE_STDARG_H */
112 {
113         int n = 0;
114         va_list ap;
115         char *str;
116         char *substr;
117 
118         VA_START(ap, substr0);
119 
120         for (n = 0, substr = substr0; substr; substr = va_arg(ap, char *))
121         {
122                 n += strlen(substr);
123         }
124 
125         va_end(ap);
126 
127         str = (char *) ralloc((unsigned) (n + 1) * sizeof(char));
128 
129         VA_START(ap, substr0);
130 
131         (void) strcpy(str, "");
132 
133         for (substr = substr0; substr; substr = va_arg(ap, char *))
134         {
135                 (void) strcat(str, substr);
136         }
137 
138         va_end(ap);
139 
140         return (str);
141 }
142 
143 
144 char *string_copy(char *string)
145 {
146         char *copy;
147 
148         copy = (char *) ralloc((unsigned) strlen(string) + 1);
149         (void) strcpy(copy, string);
150         return (copy);
151 }
152 
153 static int isspace(int c)
154 {
155         return (c == ' ' || c == '\n');
156 }
157 
158 int freadline(FILE * fp, char *string)
159 {
160         int c;
161         int i = 0;
162 
163         while (isspace(c = getc(fp)));
164 
165         if (c == EOF)
166                 return (EOF);
167         do
168         {
169                 string[i++] = (char)c;
170         }
171         while ((c = getc(fp)) != '\n' && c != EOF && i < MAXPATHLEN - 1);
172         string[i++] = '\0';
173         return (i);
174 }
175 
176 int read_into_int(int *x, char *string, char *msg)
177 {
178         int y;
179         char temps[256];
180 
181         if (sscanf(string, "%d", &y) == 1)
182         {
183                 *x = y;
184                 message(string_append(temps, msg, string, "\n", 0));
185                 return (1);
186         }
187         message("read_into_int: string not an int\n");
188         return (0);
189 }
190 
191 int read_into_short(short int *x, char *string, char *msg)
192 {
193         short y;
194         char temps[256];
195 
196         if (sscanf(string, "%hd", &y) == 1)
197         {
198                 *x = y;
199                 message(string_append(temps, msg, string, "\n", 0));
200                 return (1);
201         }
202         message("read_into_short: string not a short\n");
203         return (0);
204 }
205 
206 int read_into_float(float *x, char *string, char *msg)
207 {
208         float y;
209         char temps[256];
210 
211         if (sscanf(string, "%f", &y) == 1)
212         {
213                 *x = y;
214                 message(string_append(temps, msg, string, "\n", 0));
215                 return (1);
216         }
217         message("read_into_float: string not a float\n");
218         return (0);
219 }
220 
221 int read_into_double(double *x, char *string, char *msg)
222 {
223         double y;
224         char temps[256];
225 
226         if (sscanf(string, "%lf", &y) == 1)
227         {
228                 *x = y;
229                 message(string_append(temps, msg, string, "\n", 0));
230                 return (1);
231         }
232         message("read_into_double: string not a float\n");
233         return (0);
234 }
235 
236 int read_into_string(char *x, char *string, char *msg)
237 {
238         char temps[256];
239 
240         (void) strcpy(x, string);
241         message(string_append(temps, msg, string, "\n", 0));
242         return (1);
243 }
244 

~ [ 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.