| 10292 | |
| 10293 | |
| 10294 | unsigned int gmtlib_string_parser (struct GMT_CTRL *GMT, char *file) |
| 10295 | { /* Debug function for testing string parser gmtlib_determine_datatype on input list. |
| 10296 | * Expects input records to be <whateverarg>|NAME, e.g. |
| 10297 | * 2001-12-24T20:01:02.333|ABSTIME |
| 10298 | * and it will then echo out that and the name it detected examining <wateverarg> */ |
| 10299 | int k, c; |
| 10300 | unsigned int kind; |
| 10301 | FILE *fp = fopen (file, "r"); |
| 10302 | char line[GMT_LEN256] = {""}; |
| 10303 | if (fp == NULL) { /* Not good, wrong filename? */ |
| 10304 | GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -/: File %s not found\n", file); |
| 10305 | return (GMT_RUNTIME_ERROR); |
| 10306 | } |
| 10307 | while (gmt_fgets (GMT, line, GMT_LEN256, fp)) { |
| 10308 | if (line[0] == '#') { /* Just a header; echo it out */ |
| 10309 | printf ("%s", line); |
| 10310 | continue; |
| 10311 | } |
| 10312 | if (strchr (line, '|') == NULL) { |
| 10313 | GMT_Report (GMT->parent, GMT_MSG_ERROR, "Data file for -/ testing does not have format <string>|<NAME>\n"); |
| 10314 | return (GMT_RUNTIME_ERROR); |
| 10315 | } |
| 10316 | gmt_chop (line); /* Remove trailing newline/CR */ |
| 10317 | k = strlen (line) - 1; /* Last position in line */ |
| 10318 | while (line[k] != '|') k--; /* Search backwards to the vertical bar */ |
| 10319 | c = k + 1; k--; /* c is start of data type (e.g., STRING) */ |
| 10320 | while (line[k] == ' ' || line[k] == '\t') k--; /* Skip past spaces before the bar */ |
| 10321 | k++; line[k] = '\0'; /* Truncate at first space */ |
| 10322 | printf ("%30s", line); /* Print the input string to be classified */ |
| 10323 | printf ("%14s\t", &line[c]); /* Print what we expect (from input file) */ |
| 10324 | kind = gmtlib_determine_datatype (GMT, line); /* Analyze what we got */ |
| 10325 | printf ("%14s\n", gmtio_type_name(kind)); /* Print data type detected */ |
| 10326 | } |
| 10327 | fclose (fp); |
| 10328 | return (GMT_NOERROR); |
| 10329 | } |
no test coverage detected