From 99955407d05eb81a81b410cd4b6d182f64e1ff57 Mon Sep 17 00:00:00 2001 Message-Id: <99955407d05eb81a81b410cd4b6d182f64e1ff57.1714511372.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 17 May 2008 14:06:32 +0100 Subject: [PATCH] Further hacking. Some actual success at runtime now. Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/macros.c | 13 +++++++--- server/actions.c | 9 ++++--- server/macros-disorder.c | 23 +++++++++++++---- server/options.c | 34 ++++++++++++++------------ templates/choose.tmpl | 2 +- templates/macros.tmpl | 42 +++++++++++++++---------------- templates/options.labels | 53 +++++++++++++++++++++------------------- templates/playing.tmpl | 44 ++++++++++++++++----------------- templates/prefs.tmpl | 2 +- 9 files changed, 124 insertions(+), 98 deletions(-) diff --git a/lib/macros.c b/lib/macros.c index 540fc45..f177ae0 100644 --- a/lib/macros.c +++ b/lib/macros.c @@ -202,8 +202,12 @@ const struct mx_node *mx_parse(const char *filename, * consist of alnums and '-'. We don't permit whitespace between the '@' * and the name. */ dynstr_init(d); - if(input == end || !isalnum((unsigned char)*input)) - fatal(0, "%s:%d: invalid expansion", filename, e->line); + if(input == end) + fatal(0, "%s:%d: invalid expansion syntax (truncated)", + filename, e->line); + if(!isalnum((unsigned char)*input)) + fatal(0, "%s:%d: invalid expansion syntax (unexpected %#x)", + filename, e->line, (unsigned char)*input); while(input < end && (isalnum((unsigned char)*input) || *input == '-')) dynstr_append(d, *input++); dynstr_terminate(d); @@ -611,7 +615,7 @@ const struct mx_node *mx_rewritel(const struct mx_node *m, */ const struct mx_node *mx_rewrite(const struct mx_node *definition, hash *h) { - const struct mx_node *head = 0, **tailp = &head, *argvalue, *m, *mm; + const struct mx_node *head = 0, **tailp = &head, *argvalue, *m, *mm, **ap; struct mx_node *nm; int n; @@ -626,7 +630,7 @@ const struct mx_node *mx_rewrite(const struct mx_node *definition, break; case MX_EXPANSION: if(m->nargs == 0 - && (argvalue = *(const struct mx_node **)hash_find(h, m->name))) { + && (ap = hash_find(h, m->name))) { /* This expansion has no arguments and its name matches one of the * macro arguments. (Even if it's a valid expansion name we override * it.) We insert its value at this point. We do NOT recursively @@ -636,6 +640,7 @@ const struct mx_node *mx_rewrite(const struct mx_node *definition, * We need to recreate the list structure but a shallow copy will * suffice here. */ + argvalue = *ap; for(mm = argvalue; mm; mm = mm->next) { nm = xmalloc(sizeof *nm); *nm = *mm; diff --git a/server/actions.c b/server/actions.c index c0a8cb4..f0b4922 100644 --- a/server/actions.c +++ b/server/actions.c @@ -170,17 +170,20 @@ static const struct action { * @param name Base name of template, or NULL to consult CGI args */ void dcgi_expand(const char *name) { - const char *p; + const char *p, *found; /* Parse macros first */ - mx_expand_file("macros.tmpl", sink_discard(), 0); + if((found = mx_find("macros.tmpl"))) + mx_expand_file(found, sink_discard(), 0); /* For unknown actions check that they aren't evil */ for(p = name; *p && isalnum((unsigned char)*p); ++p) ; if(*p) fatal(0, "invalid action name '%s'", name); byte_xasprintf((char **)&p, "%s.tmpl", name); - if(mx_expand_file(p, sink_stdio("stdout", stdout), 0) == -1 + if(!(found = mx_find(p))) + fatal(errno, "cannot find %s", p); + if(mx_expand_file(found, sink_stdio("stdout", stdout), 0) == -1 || fflush(stdout) < 0) fatal(errno, "error writing to stdout"); } diff --git a/server/macros-disorder.c b/server/macros-disorder.c index 189d51d..c2ac8b0 100644 --- a/server/macros-disorder.c +++ b/server/macros-disorder.c @@ -155,6 +155,11 @@ static int exp_part(int nargs, else return 0; } + fprintf(stderr, "track=[%s] part=[%s] context=[%s] dcgi_client=[%p]\n", + track, + part, + !strcmp(context, "short") ? "display" : context, + dcgi_client); if(dcgi_client && !disorder_part(dcgi_client, &s, track, @@ -931,12 +936,19 @@ static int exp__search_shim(disorder_client *c, const char *terms, * - @display to the UNQUOTED display string for this track */ static int exp_search(int nargs, - const struct mx_node **args, - struct sink *output, - void *u) { + const struct mx_node **args, + struct sink *output, + void *u) { return exp__files_dirs(nargs, args, output, u, "track", exp__search_shim); } +static int exp_label(int attribute((unused)) nargs, + char **args, + struct sink *output, + void attribute((unused)) *u) { + return sink_writes(output, option_label(args[0])) < 0 ? -1 : 0; +} + /** @brief Register DisOrder-specific expansions */ void dcgi_expansions(void) { mx_register("arg", 1, 1, exp_arg); @@ -946,10 +958,11 @@ void dcgi_expansions(void) { mx_register("image", 1, 1, exp_image); mx_register("isnew", 0, 0, exp_isnew); mx_register("isplaying", 0, 0, exp_isplaying); - mx_register("isplaying", 0, 0, exp_isqueue); + mx_register("isqueue", 0, 0, exp_isqueue); mx_register("isrecent", 0, 0, exp_isrecent); + mx_register("label", 1, 1, exp_label); mx_register("length", 1, 1, exp_length); - mx_register("movable", 1, 1, exp_movable); + mx_register("movable", 1, 2, exp_movable); mx_register("part", 2, 3, exp_part); mx_register("paused", 0, 0, exp_paused); mx_register("pref", 2, 2, exp_pref); diff --git a/server/options.c b/server/options.c index 9185610..0453cd7 100644 --- a/server/options.c +++ b/server/options.c @@ -153,24 +153,26 @@ void option_set(const char *name, const char *value) { */ const char *option_label(const char *key) { const char *label; + char **lptr; option__init(); - if(!(label = *(char **)hash_find(labels, key))) { - /* No label found */ - if(!strncmp(key, "images.", 7)) { - static const char *url_static; - /* images.X defaults to X.png */ - - if(!url_static) - url_static = option_label("url.static"); - byte_xasprintf((char **)&label, "%s%s.png", url_static, key + 7); - } else if((label = strrchr(key, '.'))) - /* X.Y defaults to Y */ - ++label; - else - /* otherwise default to label name */ - label = key; - } + lptr = hash_find(labels, key); + if(lptr) + return *lptr; + /* No label found */ + if(!strncmp(key, "images.", 7)) { + static const char *url_static; + /* images.X defaults to X.png */ + + if(!url_static) + url_static = option_label("url.static"); + byte_xasprintf((char **)&label, "%s%s.png", url_static, key + 7); + } else if((label = strrchr(key, '.'))) + /* X.Y defaults to Y */ + ++label; + else + /* otherwise default to label name */ + label = key; return label; } diff --git a/templates/choose.tmpl b/templates/choose.tmpl index a000cad..7e60d55 100644 --- a/templates/choose.tmpl +++ b/templates/choose.tmpl @@ -26,7 +26,7 @@ USA @stdmenu{choose}

@label:choose.title@

- @if{@eq{@label{sidebar.choosewhich}}{choosealpha}} + @if{@eq{@label{menu.choosewhich}}{choosealpha}} {

text @define {quiethead} {} - {} + { } @# Standard menu @# @current is the name of the current page, e.g. choosealpha, login @define {stdmenu} {current} - {

-
+

+
} @# Menu entry @@ -67,16 +68,15 @@ and then redefines macros as desired. @# @define {menuitem} {current name available} {@if{@available} - {
} - { - @label{menu.@name}}} + { @label{menu.@name}} + { @label{menu.@name}}} @# Standard footer text @@ -111,9 +111,9 @@ and then redefines macros as desired. {@right{play} {@part{@track}{short}{artist}} + title="@label{@what.artistverbose}">@part{@track}{artist}{short}} {@part{@track}{short}{artist}}} + title="@part{@track}{artist}">@part{@track}{artist}{short}}} @# Expand to the album for @track @# @what is the section @@ -122,15 +122,15 @@ and then redefines macros as desired. {@right{play} {@part{@track}{short}{album}} + title="@label{@what.albumverbose}">@part{@track}{album}{short}} {@part{@track}{short}{album}}} + title="@part{@track}{album}">@part{@track}{album}{short}}} @# Expand to the title for @track @# @what is the section @# @track is the track name @define {mtitle} {what track} - {@part{@track}{short}{title}} + {@part{@track}{title}{short}} @# Expand to the remove/scratch entry for @id @# @what is the section diff --git a/templates/options.labels b/templates/options.labels index 85e0377..86586aa 100644 --- a/templates/options.labels +++ b/templates/options.labels @@ -198,35 +198,35 @@ label error.reminderfailed "Cannot send a reminder." # Text appended to all error pages label error.generic "" -# Displayed text for links in the sidebar (or other menu) -label sidebar.playing Playing -label sidebar.choose Choose -label sidebar.random Random -label sidebar.search Search -label sidebar.recent Recent -label sidebar.new New -label sidebar.about About -label sidebar.volume Volume -label sidebar.login Login -label sidebar.help Help -label sidebar.manage Manage - -# Long (i.e. TITLE=) text for sidebar links -label sidebar.playingverbose "Current and queued tracks" -label sidebar.chooseverbose "Choose tracks" -label sidebar.searchverbose "Word search among track names" -label sidebar.recentverbose "Recently played tracks" -label sidebar.newverbose "Newly added tracks" -label sidebar.aboutverbose "About DisOrder" -label sidebar.volumeverbose "Volume control" -label sidebar.loginverbose "Log in to DisOrder" -label sidebar.helpverbose "Basic user guide" -label sidebar.manageverbose "Queue management and volume control" +# Displayed text for links in the menu +label menu.playing Playing +label menu.choose Choose +label menu.random Random +label menu.search Search +label menu.recent Recent +label menu.new New +label menu.about About +label menu.volume Volume +label menu.login Login +label menu.help Help +label menu.manage Manage + +# Long (i.e. TITLE=) text for menu links +label menu.playingverbose "Current and queued tracks" +label menu.chooseverbose "Choose tracks" +label menu.searchverbose "Word search among track names" +label menu.recentverbose "Recently played tracks" +label menu.newverbose "Newly added tracks" +label menu.aboutverbose "About DisOrder" +label menu.volumeverbose "Volume control" +label menu.loginverbose "Log in to DisOrder" +label menu.helpverbose "Basic user guide" +label menu.manageverbose "Queue management and volume control" # This should be 'choose' or 'choosealpha'. If 'choose' then all artists # appear on the same page, otherwise they are broken up by initial letter # (which can be more convenient if you have huge numbers). -label sidebar.choosewhich choose +label menu.choosewhich choose # Column headings for tables of tracks (playing, queue, recent) label heading.when When @@ -246,3 +246,6 @@ label images.upall upup.png label images.noupall noupup.png label images.downall downdown.png label images.nodownall nodowndown.png + +# Where to find images etc +label url.static /disorder diff --git a/templates/playing.tmpl b/templates/playing.tmpl index 5d369c0..5a767e4 100644 --- a/templates/playing.tmpl +++ b/templates/playing.tmpl @@ -26,7 +26,7 @@ USA @# @state should be the current state @define {onoff} {class action state} { @label{playing.@class} @@ -92,7 +92,7 @@ USA @label{volume.right} - + @right{volume}{