Changeset 37033
- Timestamp:
- Jul 17, 2014, 10:07:16 AM (12 years ago)
- Location:
- trunk/Ohana/src/libohana
- Files:
-
- 2 edited
-
include/ohana.h (modified) (3 diffs)
-
src/string.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libohana/include/ohana.h
r35754 r37033 71 71 # endif 72 72 73 # define MARKTIME(MSG,...) { \ 74 gettimeofday (&stopTimer, (void *) NULL); \ 75 float dtime = DTIME (stopTimer, startTimer); \ 76 fprintf (stderr, MSG, __VA_ARGS__); } 77 78 # define INITTIME \ 79 struct timeval startTimer, stopTimer; \ 80 gettimeofday (&startTimer, (void *) NULL); 81 73 82 #ifdef __GNUC__ 74 83 #define OHANA_FORMAT(style, fmt, varargs) __attribute__((format(style, fmt, varargs))) … … 252 261 int scan_line PROTO((FILE *f, char *line)); 253 262 int scan_line_maxlen PROTO((FILE *f, char *line, int maxlen)); 263 char *parse_nextword PROTO((char *string)); 264 char *parse_nextword_csv PROTO((char *string)); 254 265 int dparse PROTO((double *X, int NX, char *line)); 255 266 int dparse_csv PROTO((double *X, int NX, char *line)); 256 267 int iparse PROTO((int *X, int NX, char *line)); 257 268 int iparse_csv PROTO((int *X, int NX, char *line)); 269 int charparse_csv PROTO((char *X, int NX, char *line)); 270 char *ptrparse PROTO((int NX, char *line)); 271 char *ptrparse_csv PROTO((int NX, char *line)); 258 272 int charparse_csv PROTO((char *X, int NX, char *line)); 259 273 int charparse PROTO((char *X, int NX, char *line)); … … 266 280 char *strip_version PROTO((char *input)); 267 281 char *strsubs PROTO((char *string, char *match, char *with)); 282 283 char *getword PROTO((char *string)); 284 char *skipword PROTO((char *string)); 268 285 269 286 /* in findexec.c */ -
trunk/Ohana/src/libohana/src/string.c
r34753 r37033 167 167 } 168 168 169 char * _parse_nextword (char *string) {169 char *parse_nextword (char *string) { 170 170 171 171 if (string == (char *) NULL) return ((char *) NULL); … … 182 182 // ,,, : go from , to , to , to 0 183 183 184 char * _parse_nextword_csv (char *string) {184 char *parse_nextword_csv (char *string) { 185 185 186 186 if (string == (char *) NULL) return ((char *) NULL); … … 199 199 word = line; 200 200 for (i = 0; i < NX - 1; i++) 201 word = _parse_nextword (word);201 word = parse_nextword (word); 202 202 203 203 *X = strtod (word, &ptr); … … 215 215 word = line; 216 216 for (i = 0; i < NX - 1; i++) 217 word = _parse_nextword_csv (word);217 word = parse_nextword_csv (word); 218 218 219 219 if (word[0] == '"') word[0] = ' '; … … 237 237 word = line; 238 238 for (i = 0; i < NX - 1; i++) 239 word = _parse_nextword (word);239 word = parse_nextword (word); 240 240 241 241 *X = strtol (word, &ptr, 0); … … 253 253 word = line; 254 254 for (i = 0; i < NX - 1; i++) 255 word = _parse_nextword_csv (word);255 word = parse_nextword_csv (word); 256 256 257 257 if (word[0] == '"') word[0] = ' '; … … 274 274 word = line; 275 275 for (i = 0; i < NX - 1; i++) 276 word = _parse_nextword (word);276 word = parse_nextword (word); 277 277 278 278 *X = word[0]; … … 287 287 word = line; 288 288 for (i = 0; i < NX - 1; i++) 289 word = _parse_nextword_csv (word);289 word = parse_nextword_csv (word); 290 290 291 291 if (word[0] == '"') word[0] = word[1]; … … 299 299 } 300 300 301 // return a pointer to the start of the desired field 302 char *ptrparse (int NX, char *line) { 303 304 int i; 305 char *word; 306 307 word = line; 308 for (i = 0; i < NX - 1; i++) { 309 word = parse_nextword (word); 310 } 311 return word; 312 } 313 314 char *ptrparse_csv (int NX, char *line) { 315 316 int i; 317 char *word; 318 319 word = line; 320 for (i = 0; i < NX - 1; i++) 321 word = parse_nextword_csv (word); 322 323 if (word[0] == '"') word ++; 324 if (word[0] == ',') return NULL; 325 return word; 326 } 327 301 328 int tparse (time_t *X, int NX, char *line) { 302 329 … … 306 333 word = line; 307 334 for (i = 0; i < NX - 1; i++) 308 word = _parse_nextword (word);335 word = parse_nextword (word); 309 336 310 337 status = ohana_str_to_time (word, X); … … 320 347 word = line; 321 348 for (i = 0; i < NX - 1; i++) 322 word = _parse_nextword_csv (word);349 word = parse_nextword_csv (word); 323 350 324 351 if (word[0] == '"') word[0] = ' '; … … 341 368 word = line; 342 369 for (i = 0; i < NX - 1; i++) 343 word = _parse_nextword (word);370 word = parse_nextword (word); 344 371 345 372 *X = strtod (word, &ptr); … … 402 429 return (q); 403 430 } 431 432 // return a newly allocated string containing the first complete set of non-whitespace 433 char *getword (char *string) { 434 435 int i, j; 436 char *word; 437 438 if (!string) return (NULL); 439 440 // find the end of the whitespace (is there any non-whitespace?) 441 for (i = 0; OHANA_WHITESPACE (string[i]); i++); 442 if (!string[i]) return (NULL); 443 444 for (j = i; string[j] && !OHANA_WHITESPACE(string[j]); j++); 445 word = strncreate (&string[i], j - i); 446 return (word); 447 } 448 449 // returns a pointer to the next word, or NULL if there is not a next word 450 char *skipword (char *string) { 451 452 int i; 453 454 if (!string) return (NULL); 455 456 // find the end of the whitespace (is there any non-whitespace?) 457 for (i = 0; OHANA_WHITESPACE (string[i]); i++); 458 if (!string[i]) return (NULL); 459 460 // find the end of the non-whitespace (this word) 461 while (string[i] && !OHANA_WHITESPACE(string[i])) i++; 462 463 // find the end of the following whitespace 464 while (string[i] && OHANA_WHITESPACE(string[i])) i++; 465 if (!string[i]) return (NULL); 466 467 return (&string[i]); 468 } 469
Note:
See TracChangeset
for help on using the changeset viewer.
