Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cct: forward comments to output #1111

Merged
merged 1 commit into from Sep 7, 2018
Merged

Conversation

kbevers
Copy link
Member

@kbevers kbevers commented Sep 6, 2018

Any text written after the coordinate input will automatically be
forwarded to the output stream. Text in columns before the coordinate
input is discarded in the output. This works for any combination of -c, -t
and -z parameters:

$ echo 12 56 100 2018.0 comment comment | cct +proj=merc
 1335833.8895   7522963.2411      100.0000     2018.0000 comment commen

$ echo text 12 56 100 2018.0 comment | cct -c 2,3,4,5 +proj=merc
 1335833.8895   7522963.2411      100.0000     2018.0000 comment

$ echo text 12 56 comment | cct -c 2,3 -t0 -z0 +proj=merc
 1335833.8895   7522963.2411        0.0000        0.0000 comment

$ echo 12 56 comment | cct -t0 -z0 +proj=merc
 1335833.8895   7522963.2411        0.0000        0.0000 comment

Closes #918

@kbevers kbevers added this to the 5.2.0 milestone Sep 6, 2018
src/cct.c Outdated
@@ -206,8 +206,8 @@ int main(int argc, char **argv) {
PJ_COORD point;
PJ_PROJ_INFO info;
OPTARGS *o;
char *buf;
int nfields = 4, direction = 1, skip_lines = 0, verbose;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can simplify the control flow somewhat by doing something like

char blank_comment[] = {""};
char *comment = blank_comment;

here

src/cct.c Outdated
}

if (opt_given (o, "s")) {
skip_lines = atoi (opt_arg(o, "s"));
}

if (opt_given (o, "c")) {
/* reset colum numbers to ease comment output later on */
for (i=0; i<4; i++) columns_xyzt[i] = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For style coherency this should be

for (i=0; i<4; i++)
    columns_xyzt[i] = 0;

src/cct.c Outdated
for (i=0; i<4; i++)
colmax = MAX(colmax, columns_xyzt[i]);
comment = column(buf, colmax+1);
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else block can be left out if introducing the "blank_comment" initialization above

src/cct.c Outdated
/* Time to print the result */
if (proj_angular_output (P, direction)) {
point.lpzt.lam = proj_todeg (point.lpzt.lam);
point.lpzt.phi = proj_todeg (point.lpzt.phi);
print (PJ_LOG_NONE, "%14.*f %14.*f %12.*f %12.4f\n", decimals_angles, point.xyzt.x, decimals_angles, point.xyzt.y, decimals_distances, point.xyzt.z, point.xyzt.t);
print (PJ_LOG_NONE, "%14.*f %14.*f %12.*f %12.4f %s\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppressing unwanted whitespace, cont'd: Replace by

print (PJ_LOG_NONE, "%14.*f  %14.*f  %12.*f  %12.4f%s%s\n",

src/cct.c Outdated
decimals_angles, point.xyzt.x,
decimals_angles, point.xyzt.y,
decimals_distances, point.xyzt.z,
point.xyzt.t, comment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And finally:

point.xyzt.t, comment_delimiter, comment

@busstoptaktik
Copy link
Member

Sorry - some of my inline comments seem to have been dropped.

Missing elements:

char *comment_delimiter = blank_comment;
char whitespace[] = " ";

And later:

comment = column(buf, colmax+1);
comment_delimiter = (comment || *comment)? whitespace: blank_comment;

@rouault
Copy link
Member

rouault commented Sep 7, 2018

comment_delimiter = (comment || *comment)? whitespace: blank_comment;

The above suggestiong looks wrong. If comment is NULL, then *comment will be evaluated and segfault

@busstoptaktik
Copy link
Member

@rouault said:

The above suggestiong looks wrong. If comment is NULL, then *comment will be evaluated and segfault

It not only looks wrong - it is wrong. I think I mounted the brain on the wrong mount-point this morning. What I meant was:

comment_delimiter = (comment && *comment)? whitespace: blank_comment

i.e. if there is a comment, and the comment is not blank (i.e. it is not pointing to a nul-terminator), add a whitespace to output, otherwise add "a nothing"

@kbevers kbevers force-pushed the cct-forward-comments branch 3 times, most recently from 060701e to e442ef7 Compare September 7, 2018 12:17
Any text written after the coordinate input will automatically be
forwarded to the output stream. Text in columns before the coordinate
input is discarded in the output. This works for any combination of -c, -t
and -z parameters:

$ echo 12 56 100 2018.0 comment comment | cct +proj=merc
 1335833.8895   7522963.2411      100.0000     2018.0000 comment commen

$ echo text 12 56 100 2018.0 comment | cct -c 2,3,4,5 +proj=merc
 1335833.8895   7522963.2411      100.0000     2018.0000 comment

$ echo text 12 56 comment | cct -c 2,3 -t0 -z0 +proj=merc
 1335833.8895   7522963.2411        0.0000        0.0000 comment

$ echo 12 56 comment | cct -t0 -z0 +proj=merc
 1335833.8895   7522963.2411        0.0000        0.0000 comment

Closes OSGeo#918
@kbevers kbevers merged commit 46e96ad into OSGeo:master Sep 7, 2018
@kbevers kbevers deleted the cct-forward-comments branch February 6, 2019 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants