/src/PROJ/src/pr_list.cpp
Line | Count | Source |
1 | | /* print projection's list of parameters */ |
2 | | |
3 | | #include <stddef.h> |
4 | | #include <stdio.h> |
5 | | #include <string.h> |
6 | | |
7 | | #include "proj.h" |
8 | | #include "proj_internal.h" |
9 | | |
10 | 0 | #define LINE_LEN 72 |
11 | 0 | static int pr_list(PJ *P, int not_used) { |
12 | 0 | paralist *t; |
13 | 0 | int l, n = 1, flag = 0; |
14 | |
|
15 | 0 | (void)putchar('#'); |
16 | 0 | for (t = P->params; t; t = t->next) |
17 | 0 | if ((!not_used && t->used) || (not_used && !t->used)) { |
18 | 0 | l = (int)strlen(t->param) + 1; |
19 | 0 | if (n + l > LINE_LEN) { |
20 | 0 | (void)fputs("\n#", stdout); |
21 | 0 | n = 2; |
22 | 0 | } |
23 | 0 | (void)putchar(' '); |
24 | 0 | if (*(t->param) != '+') |
25 | 0 | (void)putchar('+'); |
26 | 0 | (void)fputs(t->param, stdout); |
27 | 0 | n += l; |
28 | 0 | } else |
29 | 0 | flag = 1; |
30 | 0 | if (n > 1) |
31 | 0 | (void)putchar('\n'); |
32 | 0 | return flag; |
33 | 0 | } |
34 | | void /* print link list of projection parameters */ |
35 | 0 | pj_pr_list(PJ *P) { |
36 | 0 | char const *s; |
37 | |
|
38 | 0 | (void)putchar('#'); |
39 | 0 | for (s = P->descr; *s; ++s) { |
40 | 0 | (void)putchar(*s); |
41 | 0 | if (*s == '\n') |
42 | 0 | (void)putchar('#'); |
43 | 0 | } |
44 | 0 | (void)putchar('\n'); |
45 | 0 | if (pr_list(P, 0)) { |
46 | 0 | (void)fputs("#--- following specified but NOT used\n", stdout); |
47 | 0 | (void)pr_list(P, 1); |
48 | 0 | } |
49 | 0 | } |
50 | | |
51 | | /************************************************************************/ |
52 | | /* pj_get_def() */ |
53 | | /* */ |
54 | | /* Returns the PROJ.4 command string that would produce this */ |
55 | | /* definition expanded as much as possible. For instance, */ |
56 | | /* +init= calls and +datum= definitions would be expanded. */ |
57 | | /************************************************************************/ |
58 | | |
59 | | char *pj_get_def(const PJ *P, int options) |
60 | | |
61 | 0 | { |
62 | 0 | paralist *t; |
63 | 0 | int l; |
64 | 0 | char *definition; |
65 | 0 | size_t def_max = 10; |
66 | 0 | (void)options; |
67 | |
|
68 | 0 | definition = (char *)malloc(def_max); |
69 | 0 | if (!definition) |
70 | 0 | return nullptr; |
71 | 0 | definition[0] = '\0'; |
72 | |
|
73 | 0 | for (t = P->params; t; t = t->next) { |
74 | | /* skip unused parameters ... mostly appended defaults and stuff */ |
75 | 0 | if (!t->used) |
76 | 0 | continue; |
77 | | |
78 | | /* grow the resulting string if needed */ |
79 | 0 | l = (int)strlen(t->param) + 1; |
80 | 0 | if (strlen(definition) + l + 5 > def_max) { |
81 | 0 | char *def2; |
82 | |
|
83 | 0 | def_max = def_max * 2 + l + 5; |
84 | 0 | def2 = (char *)malloc(def_max); |
85 | 0 | if (def2) { |
86 | 0 | strcpy(def2, definition); |
87 | 0 | free(definition); |
88 | 0 | definition = def2; |
89 | 0 | } else { |
90 | 0 | free(definition); |
91 | 0 | return nullptr; |
92 | 0 | } |
93 | 0 | } |
94 | | |
95 | | /* append this parameter */ |
96 | 0 | strcat(definition, " +"); |
97 | 0 | strcat(definition, t->param); |
98 | 0 | } |
99 | | |
100 | 0 | return definition; |
101 | 0 | } |