diff options
author | Thomas White <taw@bitwiz.me.uk> | 2018-10-27 18:05:27 +0200 |
---|---|---|
committer | Thomas White <taw@bitwiz.me.uk> | 2018-10-27 18:05:27 +0200 |
commit | 662ea0cffbda947f363f9f734309066cd93e917f (patch) | |
tree | 58a380ba5284fd2bfd004174559b03c9448ef4a5 /src/sc_interp.c | |
parent | d5f7ae9d6a28781051d7649a656dd2f93b6ea96d (diff) |
Avoid copious strcatting for stylesheet lookups
Diffstat (limited to 'src/sc_interp.c')
-rw-r--r-- | src/sc_interp.c | 52 |
1 files changed, 9 insertions, 43 deletions
diff --git a/src/sc_interp.c b/src/sc_interp.c index ef3c7df..73fc263 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -935,64 +935,40 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl, static void apply_style(SCInterpreter *scin, Stylesheet *ss, const char *path) { - char fullpath[256]; - size_t len; char *result; - len = strlen(path); - if ( len > 160 ) { - fprintf(stderr, "Can't apply style: path too long.\n"); - return; - } - if ( ss == NULL ) return; /* Font */ - strcpy(fullpath, path); - strcat(fullpath, ".font"); - result = stylesheet_lookup(ss, fullpath); + result = stylesheet_lookup(ss, path, "font"); if ( result != NULL ) set_font(scin, result); /* Foreground colour */ - strcpy(fullpath, path); - strcat(fullpath, ".fgcol"); - result = stylesheet_lookup(ss, fullpath); + result = stylesheet_lookup(ss, path, "fgcol"); if ( result != NULL ) set_colour(scin, result); /* Background (vertical gradient) */ - strcpy(fullpath, path); - strcat(fullpath, ".bggradv"); - result = stylesheet_lookup(ss, fullpath); + result = stylesheet_lookup(ss, path, "bggradv"); if ( result != NULL ) set_bggrad(scin, result, GRAD_VERT); /* Background (horizontal gradient) */ - strcpy(fullpath, path); - strcat(fullpath, ".bggradh"); - result = stylesheet_lookup(ss, fullpath); + result = stylesheet_lookup(ss, path, "bggradh"); if ( result != NULL ) set_bggrad(scin, result, GRAD_HORIZ); /* Background (solid colour) */ - strcpy(fullpath, path); - strcat(fullpath, ".bgcol"); - result = stylesheet_lookup(ss, fullpath); + result = stylesheet_lookup(ss, path, "bgcol"); if ( result != NULL ) set_bgcol(scin, result); /* Padding */ - strcpy(fullpath, path); - strcat(fullpath, ".pad"); - result = stylesheet_lookup(ss, fullpath); + result = stylesheet_lookup(ss, path, "pad"); if ( result != NULL ) set_padding(sc_interp_get_frame(scin), result); /* Paragraph spacing */ - strcpy(fullpath, path); - strcat(fullpath, ".paraspace"); - result = stylesheet_lookup(ss, fullpath); + result = stylesheet_lookup(ss, path, "paraspace"); if ( result != NULL ) set_paraspace(scin, result); /* Alignment */ - strcpy(fullpath, path); - strcat(fullpath, ".alignment"); - result = stylesheet_lookup(ss, fullpath); + result = stylesheet_lookup(ss, path, "alignment"); if ( result != NULL ) { if ( strcmp(result, "center") == 0 ) { set_alignment(scin, PANGO_ALIGN_CENTER); @@ -1015,16 +991,8 @@ static void output_frame(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss, struct frame *fr; SCBlock *child = sc_block_child(bl); const char *options = sc_block_options(bl); - char fullpath[256]; - size_t len; char *result; - len = strlen(stylename); - if ( len > 160 ) { - fprintf(stderr, "Can't apply style: path too long.\n"); - return; - } - fr = add_subframe(sc_interp_get_frame(scin)); fr->scblocks = bl; fr->resizable = 1; @@ -1037,9 +1005,7 @@ static void output_frame(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss, set_frame_default_style(fr, scin); /* Next priority: geometry from stylesheet */ - strcpy(fullpath, stylename); - strcat(fullpath, ".geometry"); - result = stylesheet_lookup(ss, fullpath); + result = stylesheet_lookup(ss, stylename, "geometry"); if ( result != NULL ) { parse_frame_options(fr, sc_interp_get_frame(scin), result); } |