00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include <soi_error.h>
00045 #include "soi_names.h"
00046 #include <stdlib.h>
00047 #include <string.h>
00048
00049 static char *strip_delimiters (char *s) {
00050 char *match;
00051 switch (*s) {
00052 case '{': {
00053 if (match = strchr (s, '}')) *match = 0;
00054 else return NULL;
00055 return s+1;
00056 }
00057 case '[': {
00058 if (match = strchr (s, ']')) *match = 0;
00059 else return NULL;
00060 return s+1;
00061 }
00062 case '(': {
00063 if (match = strchr (s, ')')) *match = 0;
00064 else return NULL;
00065 return s+1;
00066 }
00067 default:
00068 return s;
00069 }
00070 }
00071
00072 int parse_array (KEY **params, char *root, int type) {
00073
00074
00075
00076
00077
00078
00079
00080 double dval;
00081 long ival;
00082 int nvals = 0;
00083 char *endptr;
00084 char *name = getkey_str (*params, root);
00085 char *next, *nptr;
00086 static char key[MAX_STRLEN];
00087
00088 soi_errno = NO_ERROR;
00089 if (!name) return soi_errno = MISSING_DATA_NAME;
00090 str_compress (name);
00091 name = strip_delimiters (name);
00092 if (!name) return soi_errno = MISSING_DATA_NAME;
00093
00094
00095
00096 next = name;
00097 while (next) {
00098 nptr = next;
00099 if (next = (char *)strchr (nptr, ',')) {
00100 *next = 0;
00101 next++;
00102 }
00103 if (!strlen (nptr)) continue;
00104
00105 sprintf (key, "%s_%d_value", root, nvals);
00106 switch (type) {
00107 case KEYTYP_INT:
00108 case KEYTYP_SHORT:
00109 case KEYTYP_USHORT:
00110 case KEYTYP_BYTE:
00111 case KEYTYP_UBYTE:
00112 ival = strtol (nptr, &endptr, 0);
00113 if (endptr == nptr) continue;
00114 setkey_int (params, key, ival);
00115 break;
00116 case KEYTYP_DOUBLE:
00117 case KEYTYP_FLOAT:
00118 dval = strtod (nptr, &endptr);
00119 if (endptr == nptr) continue;
00120 setkey_double (params, key, dval);
00121 break;
00123 default:
00124 soi_errno = KEYTYPE_NOT_IMPLEMENTED;
00125 }
00127 nvals++;
00128 }
00129 sprintf (key, "%s_nvals", root);
00130 setkey_int (params, key, nvals);
00131 return soi_errno;
00132 }
00133
00134 int parse_numerated (char *klist, char ***names) {
00135
00136
00137
00138
00139
00140
00141 int found = 0, maxlen;
00142 char *next, *nptr, *tmp;
00143
00144 if (!klist) return found;
00145 maxlen = strlen (klist);
00146 tmp = malloc (maxlen + 1);
00147 strcpy (tmp, klist);
00148 str_compress (tmp);
00149 next = tmp;
00150
00151 *names = (char **)malloc (maxlen * sizeof (char *));
00152 while (next) {
00153 nptr = next;
00154 if (next = (char *)strchr (nptr, ',')) {
00155 *next = 0;
00156 next++;
00157 }
00158 if (!strlen (nptr)) continue;
00159
00160 (*names)[found] = (char *)malloc (strlen (nptr) + 1);
00161 strcpy ((*names)[found], nptr);
00162 found++;
00163 }
00164 free (tmp);
00165
00166 return found;
00167 }