Skip to content

Commit be76d9c

Browse files
authored
Improve parsing of modifier text with plus-symbols (#577)
Since quotes are not passed into GMT, it can be difficult to know if any combination of +letter is a modifier or not. To eliminate as many cases as we can, we do this: For argument to an option that takes modifiers, replace any + symbol that is not followed by one of the allowed modifier letters with ASCII 1. New: THe second time we find a + followed by a valid modifier we know it cannot be a modifer since a modifier can only be given once. So +tTitle+test will now handle the second +t sequence as plain text. Bug: If a string ended in a plus then it got removed. With these improvements we are less vulnerable to this problem and a few tests could be simplified and a few actually had text ending in double-pus-symbols to compensate for the loss of the last. Ultimately, the only foolproof way to not have a +letter be interpreted as a modifier is to use the octal code for the plus: \053.
1 parent fe0454c commit be76d9c

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

doc/scripts/func_F_iso+.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $AWK -f tt.awk tt.txt > tt.d
7171
gmt set PS_CHAR_ENCODING ISOLatin1+
7272

7373
# First the uncoded ones
74-
gmt psxy -R0/9/2/32 -Jx0.345i/-0.21i -BN+tISOLatin1++ -P -K -Glightred -Y0.0 << EOF
74+
gmt psxy -R0/9/2/32 -Jx0.345i/-0.21i -BN+tISOLatin1+ -P -K -Glightred -Y0.0 << EOF
7575
>
7676
1 4
7777
2 4

doc/scripts/func_F_stand+.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ $AWK -f tt.awk tt.txt > tt.d
7171
gmt set PS_CHAR_ENCODING Standard+
7272

7373
# First mark uncoded entries
74-
gmt psxy -R0/9/2/32 -Jx0.345i/-0.21i -BN+tStandard++ -P -K -Glightred -Y0.0 << EOF
74+
gmt psxy -R0/9/2/32 -Jx0.345i/-0.21i -BN+tStandard+ -P -K -Glightred -Y0.0 << EOF
7575
>
7676
1 4
7777
2 4

src/gmt_init.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,11 +3436,14 @@ GMT_LOCAL int gmtinit_parse4_B_option (struct GMT_CTRL *GMT, char *in) {
34363436
/*! . */
34373437
void gmt_handle5_plussign (struct GMT_CTRL *GMT, char *in, char *mods, unsigned way) {
34383438
/* Way = 0: replace any +<letter> with <letter> NOT in <mods> with ASCII 1<letter>
3439+
* We only skip +<letter> the first time it is found (if in <mods>).
34393440
* Way = 1: Replace ASCII 1 with + */
34403441
gmt_M_unused(GMT);
34413442
if (in == NULL || in[0] == '\0') return; /* No string to check */
34423443
if (way == 0) { /* Replace any +<letter> with <letter> NOT in <mods> with ASCII 1<letter> */
3443-
char *c = in;
3444+
size_t n = strlen (mods);
3445+
char *c = in, *p = NULL;
3446+
unsigned int *used = gmt_M_memory (GMT, NULL, n, unsigned int);
34443447
for ( ;; ) { /* Replace super-script escape sequence @+ with @1 */
34453448
c = strstr (c, "@+");
34463449
if (c == NULL) break;
@@ -3451,10 +3454,17 @@ void gmt_handle5_plussign (struct GMT_CTRL *GMT, char *in, char *mods, unsigned
34513454
for ( ;; ) { /* Now look for +<letter> */
34523455
c = strchr (c, '+'); /* Find next '+' */
34533456
if (c == NULL) break; /* No more + found */
3454-
if (!strchr (mods, c[1])) /* Not one of the +<mods> cases so we can replace the + by 1 */
3457+
p = NULL;
3458+
if (c[1] && (p = strchr (mods, c[1]))) { /* Any of ours */
3459+
unsigned int k = (p - mods);
3460+
if (used[k]) p = NULL;
3461+
else used[k]++;
3462+
}
3463+
if (!p) /* Not one of the +<mods> cases (or already fixed) so we can replace the + by 1 */
34553464
*c = 1;
34563465
++c;
34573466
}
3467+
gmt_M_free (GMT, used);
34583468
}
34593469
else /* way != 0: Replace single ASCII 1 with + */
34603470
gmt_strrepc (in, 1, '+');

test/psimage/transparent_gif.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ ps=transparent_gif.ps
1010
gmt psbasemap -R0/1/0/1 -JX7c -Y19c -B+glightblue+t"no option" -K -P > $ps
1111
gmt psimage @warning.gif -Dx0.5c/0.5c+jBL+w6c -O -K >> $ps
1212

13-
gmt psbasemap -Y-9c -R -J -B+glightblue+t"-Gblack\053t" -O -K >> $ps
13+
gmt psbasemap -Y-9c -R -J -B+glightblue+t"-Gblack+t" -O -K >> $ps
1414
gmt psimage @warning.gif -Gblack+t -Dx0.5c/0.5c+jBL+w6c -O -K >> $ps
1515

16-
gmt psbasemap -X8c -R -J -B+glightblue+t"-Gwhite\053t" -O -K >> $ps
16+
gmt psbasemap -X8c -R -J -B+glightblue+t"-Gwhite+t" -O -K >> $ps
1717
gmt psimage @warning.gif -Gwhite+t -D0.5c/0.5c+jBL+w6c -O -K >> $ps
1818

19-
gmt psbasemap -X-8c -Y-9c -R -J -B+glightblue+t"-Gred\053t" -O -K >> $ps
19+
gmt psbasemap -X-8c -Y-9c -R -J -B+glightblue+t"-Gred+t" -O -K >> $ps
2020
gmt psimage @warning.gif -Gred+t -Dx0.5c/0.5c+jBL+w6c -O -K >> $ps
2121

22-
gmt psbasemap -X8c -R -J -B+glightblue+t"-Gblue\053t" -O -K >> $ps
22+
gmt psbasemap -X8c -R -J -B+glightblue+t"-Gblue+t" -O -K >> $ps
2323
gmt psimage @warning.gif -Gblue+t -Dx0.5c/0.5c+jBL+w6c -O >> $ps

test/psimage/transparent_png.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ ps=transparent_png.ps
99
gmt psbasemap -R0/1/0/1 -JX7c -Y19c -B+glightblue+t"no option" -K -P > $ps
1010
gmt psimage @warning.png -Dx0.5c/0.5c+jBL+w6c -O -K >> $ps
1111

12-
gmt psbasemap -Y-9c -R -J -B+glightblue+t"-Gblack\053t" -O -K >> $ps
12+
gmt psbasemap -Y-9c -R -J -B+glightblue+t"-Gblack+t" -O -K >> $ps
1313
gmt psimage @warning.png -Gblack+t -Dx0.5c/0.5c+jBL+w6c -O -K >> $ps
1414

15-
gmt psbasemap -X8c -R -J -B+glightblue+t"-Gwhite\053t" -O -K >> $ps
15+
gmt psbasemap -X8c -R -J -B+glightblue+t"-Gwhite+t" -O -K >> $ps
1616
gmt psimage @warning.png -Gwhite+t -Dx0.5c/0.5c+jBL+w6c -O -K >> $ps
1717

18-
gmt psbasemap -X-8c -Y-9c -R -J -B+glightblue+t"-Gred\053t" -O -K >> $ps
18+
gmt psbasemap -X-8c -Y-9c -R -J -B+glightblue+t"-Gred+t" -O -K >> $ps
1919
gmt psimage @warning.png -Gred+t -Dx0.5c/0.5c+jBL+w6c -O -K >> $ps
2020

21-
gmt psbasemap -X8c -R -J -B+glightblue+t"-Gblue\053t" -O -K >> $ps
21+
gmt psbasemap -X8c -R -J -B+glightblue+t"-Gblue+t" -O -K >> $ps
2222
gmt psimage @warning.png -Gblue+t -Dx0.5c/0.5c+jBL+w6c -O >> $ps

test/pstext/utf8.ps

-256 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)