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
@kbevers kbevers force-pushed the kbevers:cct-forward-comments branch from d85129e to 18adfea 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;

This comment has been minimized.

@busstoptaktik

busstoptaktik Sep 7, 2018
Member

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;

This comment has been minimized.

@busstoptaktik

busstoptaktik Sep 7, 2018
Member

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 {

This comment has been minimized.

@busstoptaktik

busstoptaktik Sep 7, 2018
Member

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",

This comment has been minimized.

@busstoptaktik

busstoptaktik Sep 7, 2018
Member

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

This comment has been minimized.

@busstoptaktik

busstoptaktik Sep 7, 2018
Member

And finally:

point.xyzt.t, comment_delimiter, comment
@busstoptaktik
Copy link
Member

@busstoptaktik busstoptaktik commented Sep 7, 2018

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 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

@busstoptaktik busstoptaktik commented Sep 7, 2018

@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 kbevers:cct-forward-comments branch 3 times, most recently from 060701e to e442ef7 Sep 7, 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 force-pushed the kbevers:cct-forward-comments branch from e442ef7 to 4f961f5 Sep 7, 2018
@kbevers kbevers merged commit 46e96ad into OSGeo:master Sep 7, 2018
4 checks passed
4 checks passed
Travis CI - Pull Request Build Passed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 77.83%
Details
@kbevers kbevers deleted the kbevers:cct-forward-comments branch Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.