MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtlib_string_parser

Function gmtlib_string_parser

src/gmt_io.c:10294–10329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10292
10293
10294unsigned 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}

Callers 1

parseFunction · 0.85

Calls 5

GMT_ReportFunction · 0.85
gmt_fgetsFunction · 0.85
gmt_chopFunction · 0.85
gmtio_type_nameFunction · 0.85

Tested by

no test coverage detected