00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "eg_io.h"
00021 void EGmvar (char *str,
00022 int nind,
00023 const char *header,
00024 ...)
00025 {
00026
00027
00028 char lstr[4096];
00029 va_list largs;
00030
00031
00032 str[0] = '\0';
00033 strcat (str, header);
00034 strcat (str, "(");
00035
00036
00037 va_start (largs, nind);
00038 while (--nind)
00039 {
00040 snprintf (lstr, (size_t)4095, "%d", va_arg (largs, int));
00041 strncat (str, lstr, (size_t)4095);
00042 strncat (str, ",", (size_t)4095);
00043 }
00044 snprintf (lstr, (size_t)4095, "%d", va_arg (largs, int));
00045 strncat (str, lstr, (size_t)4095);
00046 strncat (str, ")", (size_t)4095);
00047
00048
00049
00050 va_end (largs);
00051 return;
00052 }
00053
00054
00055
00056
00057 void EGioNParse (char *input,
00058 int max_argc,
00059 const char *delim,
00060 const char *comment,
00061 int *argc,
00062 char **argv)
00063 {
00064
00065 char *next;
00066
00067 for ((*argc) = 0, next = input; ((*argc) < max_argc) && next; (*argc)++)
00068 {
00069 EGioParse (&next, &input, delim, comment);
00070 if (next == 0)
00071 break;
00072 argv[(*argc)] = next;
00073 }
00074
00075 return;
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 void EGioParse (char **next,
00089 char **current,
00090 const char *delim,
00091 const char *comment)
00092 {
00093
00094
00095 int i;
00096 char *ctmp;
00097 char *curchar = *current;
00098
00099
00100 if (*current == 0)
00101 {
00102 *next = 0;
00103 return;
00104 }
00105
00106
00107 while ((((*curchar < 32) || (*curchar > 126))) && (*curchar != '\0'))
00108 curchar++;
00109
00110
00111 while (index (delim, *curchar) && (*curchar != '\0'))
00112 curchar++;
00113
00114
00115 if ((*curchar) == '\0')
00116 {
00117 *next = *current = 0;
00118 return;
00119 }
00120
00121
00122 if (index (comment, *curchar))
00123 {
00124 *next = *current = 0;
00125 return;
00126 }
00127
00128
00129
00130 *next = curchar;
00131
00132 *current = index (curchar, 0);
00133 i = strlen (delim);
00134 while (i)
00135 {
00136 i--;
00137 ctmp = index (curchar, delim[i]);
00138 if (ctmp && (ctmp < *current) && (ctmp > *next))
00139 *current = ctmp;
00140 }
00141
00142
00143 i = 32;
00144 while (i)
00145 {
00146 i--;
00147 ctmp = index (curchar, i);
00148 if (ctmp && (ctmp < *current) && (ctmp > *next))
00149 *current = ctmp;
00150 }
00151
00152
00153
00154 if (index (curchar, 0) == *current)
00155 {
00156 *current = 0;
00157 return;
00158 }
00159
00160
00161
00162 **current = 0;
00163 (*current)++;
00164
00165
00166 return;
00167 }
00168
00169
00170
00171
00172
00173 void EGioDisCom (char **next,
00174 char **current,
00175 const char *delim,
00176 const char *comment,
00177 char *store,
00178 unsigned int storeSize,
00179 FILE * in)
00180 {
00181
00182
00183 int status = 1;
00184
00185
00186 if (!(*current))
00187 {
00188 status = (store == fgets (store, (int) storeSize, in));
00189 *current = store;
00190 }
00191
00192
00193 EGioParse (next, current, delim, comment);
00194 while (!(*next) && status)
00195 {
00196 status = (store == fgets (store, (int) storeSize, in));
00197 *current = store;
00198 EGioParse (next, current, delim, comment);
00199 }
00200
00201 return;
00202 }
00203
00204
00205 void EGdisplayString (void *str,
00206 FILE * file)
00207 {
00208 fprintf (file, "%s", (char *) str);
00209 }
00210
00211
00212 int EGioReadLine(char*const str,size_t const max_len, FILE*file)
00213 {
00214 char c=0;
00215 size_t len = max_len ;
00216 while(((c=getc(file))!=EOF) && (c!='\n') && --len)
00217 {
00218 str[max_len-1-len] = c;
00219 }
00220 str[max_len-len] = '\0';
00221 TEST((max_len - len)==0 && c!= '\n',"Nothing to be read");
00222 return 0;
00223 }