aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Knudsen <thokn@sdfe.dk>2017-10-10 15:56:42 +0200
committerThomas Knudsen <thokn@sdfe.dk>2017-10-12 14:40:17 +0200
commitf1e12f6bd6c12f08caee2cca15f34aec14f4615b (patch)
tree502c03dbffc87c0fede0f67f0d38aae88b647ea3
parent973c87c5115e34c60d65f702815edee169fcdd1e (diff)
downloadPROJ-f1e12f6bd6c12f08caee2cca15f34aec14f4615b.tar.gz
PROJ-f1e12f6bd6c12f08caee2cca15f34aec14f4615b.zip
remove trailing whitespace
Add missing prototype for opt_strip_path() A bunch of minor oops cleanups Remove unused functiion cloumn() Fighting the good fight trying to be *both* POSIX *and* Windows compatible A few more improvements: 2 missing casts and a potentially uninitialized variable
-rw-r--r--src/gie.c118
-rw-r--r--src/optargpm.h33
-rw-r--r--src/proj_strtod.c14
3 files changed, 78 insertions, 87 deletions
diff --git a/src/gie.c b/src/gie.c
index adfc4e0f..91af00b9 100644
--- a/src/gie.c
+++ b/src/gie.c
@@ -124,15 +124,14 @@ Thomas Knudsen, thokn@sdfe.dk, 2017-10-01/2017-10-08
double proj_strtod(const char *str, char **endptr);
double proj_atof(const char *str);
-static char *column (char *buf, int n);
int main(int argc, char **argv);
-static int process_file (char *fname);
+static int process_file (char *fname);
static int errmsg (int errlev, char *msg, ...);
static int get_inp (FILE *f, char *inp, int size);
static int get_cmnd (char *inp, char *cmnd, int len);
static char *get_args (char *inp);
-static int dispatch (char *cmnd, char *args);
+static int dispatch (char *cmnd, char *args);
@@ -198,14 +197,14 @@ static const char usage[] = {
" gie -vvvv corner-cases.gie\n"
"2. Run all tests in files \"foo\" and \"bar\", providing info on failures only\n"
" gie foo bar\n"
- "--------------------------------------------------------------------------------\n"
+ "--------------------------------------------------------------------------------\n"
};
int main (int argc, char **argv) {
int i;
const char *longflags[] = {"v=verbose", "q=quiet", "h=help", 0};
const char *longkeys[] = {"o=output", 0};
-
+
o = opt_parse (argc, argv, "hvq", "o", longflags, longkeys);
if (0==o)
return 0;
@@ -215,7 +214,7 @@ int main (int argc, char **argv) {
return 0;
}
-
+
T.verbosity = opt_given (o, "q");
if (T.verbosity)
@@ -245,7 +244,7 @@ int main (int argc, char **argv) {
if (T.verbosity > 0) {
if (o->fargc > 1)
fprintf (T.fout, "%sGrand total: %d. Success: %d, Failure: %d\n", delim, T.grand_ok+T.grand_ko, T.grand_ok, T.grand_ko);
- printf (delim);
+ fprintf (T.fout, "%s", delim);
}
else
if (T.grand_ko)
@@ -261,7 +260,7 @@ int main (int argc, char **argv) {
-
+
static int process_file (char *fname) {
FILE *f;
char inp[CMDLEN];
@@ -294,7 +293,7 @@ static int process_file (char *fname) {
proj_destroy (T.P);
T.P = 0;
return 0;
-
+
}
args = get_args (inp);
if (SKIP==dispatch (cmnd, args))
@@ -306,7 +305,7 @@ static int process_file (char *fname) {
T.grand_ko += T.total_ko;
if (T.verbosity > 0)
fprintf (T.fout, "%stotal: %2d tests succeeded, %2d tests %s\n", delim, T.total_ok, T.total_ko, T.total_ko? "FAILED!": "failed.");
-
+
if (level==0)
return errmsg (-3, "File '%s':Missing 'BEGIN' cmnd - bye!\n", fname);
if (level && level%2)
@@ -319,25 +318,6 @@ static int process_file (char *fname) {
-/* return a pointer to the n'th column of buf or a pointer to the terminating 0 if less than n */
-static char *column (char *buf, int n) {
- int i;
- if (n <= 0)
- return buf;
- for (i = 0; i < n; i++) {
- while (isspace(*buf))
- buf++;
- if (i == n - 1)
- break;
- while ((0 != *buf) && !isspace(*buf))
- buf++;
- }
- return buf;
-}
-
-
-
-
static int banner (char *args) {
char dots[] = {"..."}, nodots[] = {""}, *thedots = nodots;
if (T.total_ko > 0 && T.op_ko==0)
@@ -399,7 +379,7 @@ static int direction (char *args) {
T.dir = PJ_INV;
break;
default:
- return 1;
+ return 1;
}
return 0;
}
@@ -407,9 +387,10 @@ static int direction (char *args) {
-static void finish_previous_operation () {
+static void finish_previous_operation (char *args) {
if (T.verbosity > 1 && T.op_id > 1 && T.op_ok+T.op_ko)
fprintf (T.fout, "%s %d tests succeeded, %d tests %s\n", delim, T.op_ok, T.op_ko, T.op_ko? "FAILED!": "failed.");
+ (void) args;
}
static int operation (char *args) {
@@ -423,10 +404,10 @@ static int operation (char *args) {
printf ("%d\n", (int) tol_lineno); */
T.op_ok = 0;
T.op_ko = 0;
-
+
direction ("forward");
tolerance ("0.5");
-
+
if (T.P)
proj_destroy (T.P);
T.P = proj_create (0, args);
@@ -443,11 +424,11 @@ static PJ_COORD torad_if_needed (PJ *P, PJ_DIRECTION dir, PJ_COORD a) {
u = P->right;
if (u==PJ_IO_UNITS_CLASSIC || u==PJ_IO_UNITS_METERS)
return a;
-
- if (u==PJ_IO_UNITS_RADIANS) {
- c.lpz.lam = proj_torad (T.a.lpz.lam);
- c.lpz.phi = proj_torad (T.a.lpz.phi);
- }
+
+ c.lpz.lam = proj_torad (T.a.lpz.lam);
+ c.lpz.phi = proj_torad (T.a.lpz.phi);
+ c.v[2] = T.a.v[2];
+ c.v[3] = T.a.v[3];
return c;
}
@@ -478,15 +459,15 @@ static int roundtrip (char *args) {
double d, r, ans;
char *endp;
ans = proj_strtod (args, &endp);
- ntrips = ans==HUGE_VAL? 100: fabs(ans);
+ ntrips = (int) (ans==HUGE_VAL? 100: fabs(ans));
d = proj_strtod (endp, &endp);
d = d==HUGE_VAL? T.tolerance: d / 1000;
r = proj_roundtrip (T.P, PJ_FWD, ntrips, T.a);
if (r > d) {
if (T.verbosity > -1) {
if (0==T.op_ko && T.verbosity < 2)
- banner (T.operation);
- fprintf (T.fout, T.op_ko? " -----\n": delim);
+ banner (T.operation);
+ fprintf (T.fout, "%s", T.op_ko? " -----\n": delim);
fprintf (T.fout, " FAILURE in %s(%d):\n", opt_strip_path (T.curr_file), (int) lineno);
fprintf (T.fout, " roundtrip deivation: %.3f mm, expected: %.3f mm\n", 1000*r, 1000*d);
}
@@ -513,17 +494,17 @@ static int expect (char *args) {
}
}
T.e = torad_if_needed (T.P, T.dir==PJ_FWD? PJ_INV:PJ_FWD, T.e);
-
+
T.b = proj_trans_coord (T.P, T.dir, T.a);
T.b = torad_if_needed (T.P, T.dir==PJ_FWD? PJ_INV:PJ_FWD, T.b);
-
+
if (T.nargs < 2) {
T.op_ko++;
T.total_ko++;
if (T.verbosity > -1) {
if (0==T.op_ko && T.verbosity < 2)
- banner (T.operation);
- fprintf (T.fout, T.op_ko? " -----\n": delim);
+ banner (T.operation);
+ fprintf (T.fout, "%s", T.op_ko? " -----\n": delim);
fprintf (T.fout, " FAILURE in %s(%d):\n Too few args: %s\n", opt_strip_path (T.curr_file), (int) lineno, args);
}
return 1;
@@ -544,8 +525,8 @@ static int expect (char *args) {
if (T.verbosity > -1) {
if (0==T.op_ko && T.verbosity < 2)
banner (T.operation);
- fprintf (T.fout, T.op_ko? " -----\n": delim);
-
+ fprintf (T.fout, "%s", T.op_ko? " -----\n": delim);
+
fprintf (T.fout, " FAILURE in %s(%d):\n", opt_strip_path (T.curr_file), (int) lineno);
fprintf (T.fout, " expected: %s\n", args);
fprintf (T.fout, " got: %.9f %.9f", T.b.xy.x, T.b.xy.y);
@@ -572,7 +553,7 @@ static int expect (char *args) {
static int verbose (char *args) {
- int i = proj_atof (args);
+ int i = (int) proj_atof (args);
/* if -q/--quiet flag has been given, we do nothing */
if (T.verbosity < 0)
@@ -604,17 +585,26 @@ static int dispatch (char *cmnd, char *args) {
level++;
return 0;
}
- if (0==stricmp (cmnd, "OPERATION")) return operation (args);
- if (0==stricmp (cmnd, "ACCEPT")) return accept (args);
- if (0==stricmp (cmnd, "EXPECT")) return expect (args);
- if (0==stricmp (cmnd, "ROUNDTRIP")) return roundtrip (args);
- if (0==stricmp (cmnd, "BANNER")) return banner (args);
- if (0==stricmp (cmnd, "VERBOSE")) return verbose (args);
- if (0==stricmp (cmnd, "DIRECTION")) return direction (args);
- if (0==stricmp (cmnd, "TOLERANCE")) return tolerance (args);
- if (0==stricmp (cmnd, "ECHO")) return echo (args);
- if (0==strcmp (cmnd, "END")) return finish_previous_operation (args), level++, 0;
- if ('#'==cmnd[0]) return comment (args);
+ if (0==strcmp (cmnd, "OPERATION")) return operation (args);
+ if (0==strcmp (cmnd, "operation")) return operation (args);
+ if (0==strcmp (cmnd, "ACCEPT")) return accept (args);
+ if (0==strcmp (cmnd, "accept")) return accept (args);
+ if (0==strcmp (cmnd, "EXPECT")) return expect (args);
+ if (0==strcmp (cmnd, "expect")) return expect (args);
+ if (0==strcmp (cmnd, "ROUNDTRIP")) return roundtrip (args);
+ if (0==strcmp (cmnd, "roundtrip")) return roundtrip (args);
+ if (0==strcmp (cmnd, "BANNER")) return banner (args);
+ if (0==strcmp (cmnd, "banner")) return banner (args);
+ if (0==strcmp (cmnd, "VERBOSE")) return verbose (args);
+ if (0==strcmp (cmnd, "verbose")) return verbose (args);
+ if (0==strcmp (cmnd, "DIRECTION")) return direction (args);
+ if (0==strcmp (cmnd, "direction")) return direction (args);
+ if (0==strcmp (cmnd, "TOLERANCE")) return tolerance (args);
+ if (0==strcmp (cmnd, "tolerance")) return tolerance (args);
+ if (0==strcmp (cmnd, "ECHO")) return echo (args);
+ if (0==strcmp (cmnd, "echo")) return echo (args);
+ if (0==strcmp (cmnd, "END")) return finish_previous_operation (args), level++, 0;
+ if ('#'==cmnd[0]) return comment (args);
return 0;
}
@@ -661,10 +651,10 @@ static int errmsg (int errlev, char *msg, ...) {
next--; \
while (isspace (c=fgetc(f)) && !feof(f)); \
}
-
+
static int get_inp (FILE *f, char *inp, int size) {
char *next;
- int c, esc;
+ int c = 0, esc;
char *endp = inp + size - 2;
skipspace (f, c);
@@ -686,15 +676,15 @@ static int get_inp (FILE *f, char *inp, int size) {
lineno++;
break;
}
-
- *next++ = c;
+
+ *next++ = (char) c;
if ('\\'==c)
esc = 1;
if (feof(f) || (next==endp))
break;
}
*(next) = 0;
- return strlen(inp);
+ return (int) strlen(inp);
}
static int get_cmnd (char *inp, char *cmnd, int len) {
diff --git a/src/optargpm.h b/src/optargpm.h
index 4933cd2d..c47dfec1 100644
--- a/src/optargpm.h
+++ b/src/optargpm.h
@@ -1,6 +1,6 @@
/***********************************************************************
- OPTARGPM - a header-only library for decoding
+ OPTARGPM - a header-only library for decoding
PROJ.4 style command line options
Thomas Knudsen, 2017-09-10
@@ -18,7 +18,7 @@ this is an attempt to catch up and chop the ketchup.
Since optargpm (for "optarg plus minus") does not belong, in any
obvious way, in any systems development library, it is provided as
-a "header only" library.
+a "header only" library.
While this is conventional in C++, it is frowned at in plain C.
But frown away - "header only" has its places, and this is one of
@@ -56,7 +56,7 @@ Supporting a wide range of option syntax, the getoptpm API is somewhat
quirky, but also compact, consisting of one data type, 3(+2) functions,
and one enumeration:
-OPTARGS
+OPTARGS
Housekeeping data type. An instance of OPTARGS is conventionally
called o or opt
opt_parse (opt, argc, argv ...):
@@ -105,7 +105,7 @@ int main(int argc, char **argv) {
FILE *out = stdout;
char *longflags[] = {"v=verbose", "h=help", 0};
char *longkeys[] = {"o=output", "hello", 0};
-
+
o = opt_parse (argc, argv, "hv", "o", longflags, longkeys);
if (0==o)
return 0;
@@ -116,7 +116,7 @@ int main(int argc, char **argv) {
exit (0);
}
- if (opt_given (o, "v"))
+ if (opt_given (o, "v"))
puts ("Feeling chatty today?");
if (opt_given (o, "hello")) {
@@ -126,8 +126,8 @@ int main(int argc, char **argv) {
if (opt_given (o, "o"))
out = fopen (opt_arg (o, "output"), "rt"); // Note: "output" translates to "o" internally
-
- // Setup transformation
+
+ // Setup transformation
P = proj_create_argv (0, o->pargc, o->pargv);
// Loop over all lines of all input files
@@ -207,6 +207,7 @@ static int opt_raise_flag (OPTARGS *opt, int ordinal);
static int opt_ordinal (OPTARGS *opt, char *option);
int opt_given (OPTARGS *opt, char *option);
char *opt_arg (OPTARGS *opt, char *option);
+char *opt_strip_path (char *full_name);
OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys, const char **longflags, const char **longkeys);
#define opt_eof_handler(opt) if (opt_eof (opt)) {continue;} else {;}
@@ -223,7 +224,7 @@ struct OPTARGS {
char *optarg[256]; /* optarg[(int) 'f'] holds a pointer to the argument of option "-f" */
char *flags; /* a list of flag style options supported, e.g. "hv" (help and verbose) */
char *keys; /* a list of key/value style options supported, e.g. "o" (output) */
- const char **longflags; /* long flags, {"help", "verbose"}, or {"h=help", "v=verbose"}, to indicate homologous short options */
+ const char **longflags; /* long flags, {"help", "verbose"}, or {"h=help", "v=verbose"}, to indicate homologous short options */
const char **longkeys; /* e.g. {"output"} or {o=output"} to support --output=/path/to/output-file. In the latter case, */
/* all operations on "--output" gets redirected to "-o", so user code need handle arguments to "-o" only */
};
@@ -264,7 +265,7 @@ int opt_input_loop (OPTARGS *opt, int binary) {
}
opt->record_index = 0;
-
+
/* no input files specified - read from stdin */
if ((0==opt->fargc) && (0==opt->input)) {
opt->input = stdin;
@@ -415,7 +416,7 @@ char *opt_strip_path (char *full_name) {
OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys, const char **longflags, const char **longkeys) {
int i, j;
OPTARGS *o;
-
+
o = (OPTARGS *) calloc (1, sizeof(OPTARGS));
if (0==o)
return 0;
@@ -430,7 +431,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
last_path_delim = strrchr (argv[0], '/');
if (last_path_delim > o->progname)
o->progname = last_path_delim;
-*/
+*/
/* Reset all flags */
for (i = 0; i < (int) strlen (flags); i++)
@@ -439,7 +440,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
/* Flag args for all argument taking options as "unset" */
for (i = 0; i < (int) strlen (keys); i++)
o->optarg[(int) keys[i]] = argv[0];
-
+
/* Hence, undefined/illegal options have an argument of 0 */
/* long opts are handled similarly, but are mapped to the high bit character range (above 128) */
@@ -457,7 +458,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if (0==strchr (flags, longflags[i][0])) {
fprintf (stderr, "%s: Invalid alias - '%s'. Valid short flags are '%s'\n", o->progname, longflags[i], flags);
free (o);
- return 0;
+ return 0;
}
}
for (i = 0; longkeys && longkeys[i]; i++) {
@@ -469,7 +470,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if (0==strchr (keys, longkeys[i][0])) {
fprintf (stderr, "%s: Invalid alias - '%s'. Valid short flags are '%s'\n", o->progname, longkeys[i], keys);
free (o);
- return 0;
+ return 0;
}
}
@@ -514,7 +515,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
char cstring[2], *crepr = cstring;
cstring[0] = (char) c;
cstring[1] = 0;
-
+
/* Long style flags and options (--long_opt_name, --long_opt_namr arg, --long_opt_name=arg) */
if (c== (int)'-') {
@@ -537,7 +538,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
o->optarg[c] = equals + 1;
break;
}
-
+
/* "outline" --foo bar style arg */
if (!opt_is_flag (o, c)) {
if ((argc==i + 1) || ('+'==argv[i+1][0]) || ('-'==argv[i+1][0]))
diff --git a/src/proj_strtod.c b/src/proj_strtod.c
index c771f2a6..aa2211f5 100644
--- a/src/proj_strtod.c
+++ b/src/proj_strtod.c
@@ -94,7 +94,7 @@ Thomas Knudsen, thokn@sdfe.dk, 2017-01-17/2017-09-18
double proj_strtod(const char *str, char **endptr);
double proj_atof(const char *str);
-
+
double proj_strtod(const char *str, char **endptr) {
double number = 0, integral_part = 0;
@@ -106,7 +106,7 @@ double proj_strtod(const char *str, char **endptr) {
int num_digits_total = 0;
int num_digits_after_comma = 0;
int num_prefixed_zeros = 0;
-
+
if (0==str) {
errno = EFAULT;
if (endptr)
@@ -140,11 +140,11 @@ double proj_strtod(const char *str, char **endptr) {
errno = EINVAL;
return HUGE_VAL;
}
-
+
/* skip prefixed zeros */
while ('0'==*p || '_'==*p)
p++;
-
+
/* Now expect a (potentially zero-length) string of digits */
while (isdigit(*p) || ('_'==*p)) {
if ('_'==*p) {
@@ -156,11 +156,11 @@ double proj_strtod(const char *str, char **endptr) {
num_digits_total++;
}
integral_part = number;
-
+
/* Do we have a fractional part? */
if ('.'==*p) {
p++;
-
+
/* keep on skipping prefixed zeros (i.e. allow writing 1e-20 */
/* as 0.00000000000000000001 without losing precision) */
if (0==integral_part)
@@ -173,7 +173,7 @@ double proj_strtod(const char *str, char **endptr) {
/* if the next character is nonnumeric, we have reached the end */
if (0==strchr ("0123456789eE+-", *p))
return integral_part;
-
+
while (isdigit(*p) || '_'==*p) {
/* Don't let pathologically long fractions destroy precision */
if ('_'==*p || num_digits_total > 17) {