Skip to content

Commit

Permalink
Merge branch 'master' into psconvert-no-file-dup
Browse files Browse the repository at this point in the history
  • Loading branch information
joa-quim committed Nov 14, 2024
2 parents 330e078 + 184cc55 commit cdd0a17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
29 changes: 16 additions & 13 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2527,43 +2527,46 @@ int gmt_parse_model (struct GMT_CTRL *GMT, char option, char *in_arg, unsigned i
#define is_text(item,k) (item[k] == 't' && item[k+1]) /* Modifier t followed by random text */

/*! Parse the -U option. Full syntax: -U[<label>][+c][+j<just>][+o<dx>[/<dy>]][+t<string>] Old syntax was -U[[<just>]/<dx>/<dy>/][c|<label>] */
GMT_LOCAL int gmtinit_parse_U_option (struct GMT_CTRL *GMT, char *item) {
GMT_LOCAL int gmtinit_parse_U_option(struct GMT_CTRL *GMT, char *item) {
int just = 1, error = 0;

GMT->current.setting.map_logo = true;
gmt_M_memset (GMT->common.U.string, GMT_LEN64, char); /* Initialize to nothing */
gmt_M_memset(GMT->common.U.string, GMT_LEN64, char); /* Initialize to nothing */
if (!item || !item[0]) return (GMT_NOERROR); /* Just basic -U with no args */

if (gmt_found_modifier (GMT, item, "cjot")) { /* New syntax */
unsigned int pos = 0, uerr = 0;
int k = 1, len = (int)strlen (item);
int k = 1, len = (int)strlen(item);
char word[GMT_LEN256] = {""}, *c = NULL;
/* Find the first +c|j|o|t that looks like it may be a modifier and not random text */
while (k < len && !(is_plus(item,k) && (is_label(item,k) || is_just(item,k) || is_off(item,k) || is_text(item,k)))) k++;
if (k == len) /* Modifiers were just random text */
strncpy (GMT->current.ps.map_logo_label, item, GMT_LEN256-1); /* Got a label */
if (k == len && item[len-2] != '+' && item[len-1] != 't') /* Modifiers were just random text (but not if it ends in "+t")*/
strncpy(GMT->current.ps.map_logo_label, item, GMT_LEN256-1); /* Got a label */
else { /* Appears to have gotten a valid modifier or more */
c = &item[k-1]; /* Start of the modifier */
c = (k != len) ? &item[k-1] : &item[k-2]; /* Start of the modifier. The ternary is for the ending "+t" case */
c[0] = '\0'; /* Chop off the + so we can parse the label, if any */
if (item[0]) strncpy (GMT->current.ps.map_logo_label, item, GMT_LEN256-1); /* Got a label */
if (item[0]) strncpy(GMT->current.ps.map_logo_label, item, GMT_LEN256-1); /* Got a label */
c[0] = '+'; /* Restore modifiers */
while (gmt_getmodopt (GMT, 'U', c, "cjot", &pos, word, &uerr) && uerr == 0) {
while (gmt_getmodopt(GMT, 'U', c, "cjot", &pos, word, &uerr) && uerr == 0) {
switch (word[0]) {
case 'c': /* Maybe +c but only if at end of followed by another modifier */
if (word[1] == '+' || word[1] == '\0') /* Use command string */
GMT->current.ps.logo_cmd = true;
break;
case 'j': /* Maybe +j if the next two letters are from LCRBMT */
if (strchr ("LCRBMT", word[1]) && strchr ("LCRBMT", word[2]))
just = gmt_just_decode (GMT, &word[1], GMT->current.setting.map_logo_justify);
if (strchr("LCRBMT", word[1]) && strchr("LCRBMT", word[2]))
just = gmt_just_decode(GMT, &word[1], GMT->current.setting.map_logo_justify);
break;
case 'o': /* Maybe +o if next letter could be part of a number */
if (strchr ("-+.0123456789", word[1])) { /* Seems to be a number */
if ((k = gmt_get_pair (GMT, &word[1], GMT_PAIR_DIM_DUP, GMT->current.setting.map_logo_pos)) < 1) error++;
if (strchr("-+.0123456789", word[1])) { /* Seems to be a number */
if ((k = gmt_get_pair(GMT, &word[1], GMT_PAIR_DIM_DUP, GMT->current.setting.map_logo_pos)) < 1) error++;
}
break;
case 't': /* Short text to replace dateclock string */
strncpy (GMT->common.U.string, &word[1], GMT_LEN64);
if (word[1])
strncpy(GMT->common.U.string, &word[1], GMT_LEN64);
else
GMT->common.U.string[0] = ' ';
break;
default: break; /* These are caught in gmt_getmodopt so break is just for Coverity */
}
Expand Down
9 changes: 5 additions & 4 deletions src/gmt_plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -3181,7 +3181,7 @@ GMT_LOCAL void gmtplot_cube_box (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, int
PSL_plotline (PSL, xx, yy, 4, PSL_MOVE|PSL_STROKE);
}

GMT_LOCAL void gmtplot_timestamp (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x, double y, unsigned int justify, char *U_label) {
GMT_LOCAL void gmtplot_timestamp(struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x, double y, unsigned int justify, char *U_label) {
/* x, y = location of the time stamp box
* justify indicates the corner of the box that (x,y) refers to, see below
* U_label = label to be plotted to the right of the box
Expand All @@ -3199,9 +3199,10 @@ GMT_LOCAL void gmtplot_timestamp (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, do

/* Plot time string in format defined by format_time_stamp */

if (GMT->common.U.string[0]) /* Override UNIX time stamp with custom short string */
snprintf (label, GMT_LEN256, " %s ", GMT->common.U.string);
else { /* Build UNIX time stamp based on current time */
if (GMT->common.U.string[0]) { /* Override time stamp with custom short string. But write nothing if only one char and == ' ' */
if (GMT->common.U.string[0] != ' ' || GMT->common.U.string[1]) snprintf(label, GMT_LEN256, " %s ", GMT->common.U.string);
}
else { /* Build time stamp based on current time */
time_t right_now = time ((time_t *)0);
char text[GMT_LEN256] = {""};
strftime (text, sizeof(text), GMT->current.setting.format_time_stamp, localtime (&right_now));
Expand Down

0 comments on commit cdd0a17

Please sign in to comment.