X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/59cf25c47fbda22f3f4e14399f0436cc6ed2c56f..224cac449a246bd7432fd5fb4e15f942547185d3:/cgi/macros-disorder.c diff --git a/cgi/macros-disorder.c b/cgi/macros-disorder.c index 6348f47..1ef1ee1 100644 --- a/cgi/macros-disorder.c +++ b/cgi/macros-disorder.c @@ -159,10 +159,11 @@ static int exp_part(int nargs, return 0; } if(dcgi_client - && !disorder_part(dcgi_client, (char **)&s, + && !disorder_part(dcgi_client, track, !strcmp(context, "short") ? "display" : context, - part)) { + part, + (char **)&s)) { if(!strcmp(context, "short")) s = truncate_for_display(s, config->short_display); return sink_writes(output, cgi_sgmlquote(s)) < 0 ? -1 : 0; @@ -457,7 +458,7 @@ static int exp_volume(int attribute((unused)) nargs, struct sink *output, void attribute((unused)) *u) { dcgi_lookup(DCGI_VOLUME); - return sink_printf(output, "%d", + return sink_printf(output, "%ld", !strcmp(args[0], "left") ? dcgi_volume_left : dcgi_volume_right) < 0 ? -1 : 0; } @@ -486,7 +487,7 @@ static int exp_isqueue(int attribute((unused)) nargs, return mx_bool_result(output, !!dcgi_queue); } -/*$ @isrecent@ +/*$ @isrecent * * Expands to "true" if there the recently played list is nonempty, otherwise * "false". @@ -581,7 +582,7 @@ static int exp_transform(int nargs, return sink_writes(output, cgi_sgmlquote(t)) < 0 ? -1 : 0; } -/*$ @enabled@ +/*$ @enabled * * Expands to "true" if playing is enabled, otherwise "false". */ @@ -625,7 +626,7 @@ static int exp_trackstate(int attribute((unused)) nargs, if(!dcgi_client) return 0; - if(disorder_resolve(dcgi_client, &track, args[0])) + if(disorder_resolve(dcgi_client, args[0], &track)) return 0; dcgi_lookup(DCGI_PLAYING); if(dcgi_playing && !strcmp(track, dcgi_playing->track)) @@ -661,7 +662,7 @@ static int exp_resolve(int attribute((unused)) nargs, void attribute((unused)) *u) { char *r; - if(dcgi_client && !disorder_resolve(dcgi_client, &r, args[0])) + if(dcgi_client && !disorder_resolve(dcgi_client, args[0], &r)) return sink_writes(output, r) < 0 ? -1 : 0; return 0; } @@ -680,7 +681,7 @@ static int exp_paused(int attribute((unused)) nargs, && dcgi_playing->state == playing_paused)); } -/*$ @state{ID}@ +/*$ @state{ID} * * Expands to the current state of track ID. */ @@ -695,7 +696,22 @@ static int exp_state(int attribute((unused)) nargs, return 0; } -/*$ @right{RIGHT}{WITH-RIGHT}{WITHOUT-RIGHT}@ +/*$ @origin{ID} + * + * Expands to the current origin of track ID. + */ +static int exp_origin(int attribute((unused)) nargs, + char **args, + struct sink *output, + void attribute((unused)) *u) { + struct queue_entry *q = dcgi_findtrack(args[0]); + + if(q) + return sink_writes(output, track_origins[q->origin]) < 0 ? -1 : 0; + return 0; +} + +/*$ @right{RIGHT}{WITH-RIGHT}{WITHOUT-RIGHT} * * Expands to WITH-RIGHT if the current user has right RIGHT, otherwise to * WITHOUT-RIGHT. The WITHOUT-RIGHT argument may be left out. @@ -844,24 +860,36 @@ static int exp__files_dirs(int nargs, /* Get the list */ if(fn(dcgi_client, dir, re, &tracks, &ntracks)) return 0; - /* Sort it. NB trackname_transform() does not go to the server. */ - tsd = tracksort_init(ntracks, tracks, type); - /* Expand the subsiduary templates. We chuck in @sort and @display because - * it is particularly easy to do so. */ - for(n = 0; n < ntracks; ++n) - if((rc = mx_expand(mx_rewritel(m, - "index", make_index(n), - "parity", n % 2 ? "odd" : "even", - "track", tsd[n].track, - "first", n == 0 ? "true" : "false", - "last", n + 1 == ntracks ? "false" : "true", - "sort", tsd[n].sort, - "display", tsd[n].display, - (char *)0), - output, u))) - return rc; + if(type) { + /* Sort it. NB trackname_transform() does not go to the server. */ + tsd = tracksort_init(ntracks, tracks, type); + /* Expand the subsiduary templates. We chuck in @sort and @display because + * it is particularly easy to do so. */ + for(n = 0; n < ntracks; ++n) + if((rc = mx_expand(mx_rewritel(m, + "index", make_index(n), + "parity", n % 2 ? "odd" : "even", + "track", tsd[n].track, + "first", n == 0 ? "true" : "false", + "last", n + 1 == ntracks ? "false" : "true", + "sort", tsd[n].sort, + "display", tsd[n].display, + (char *)0), + output, u))) + return rc; + } else { + for(n = 0; n < ntracks; ++n) + if((rc = mx_expand(mx_rewritel(m, + "index", make_index(n), + "parity", n % 2 ? "odd" : "even", + "track", tracks[n], + "first", n == 0 ? "true" : "false", + "last", n + 1 == ntracks ? "false" : "true", + (char *)0), + output, u))) + return rc; + } return 0; - } /*$ @tracks{DIR}{RE}{TEMPLATE} @@ -903,7 +931,7 @@ static int exp_dirs(int nargs, const struct mx_node **args, struct sink *output, void *u) { - return exp__files_dirs(nargs, args, output, u, "dir", disorder_directories); + return exp__files_dirs(nargs, args, output, u, "dir", disorder_dirs); } static int exp__search_shim(disorder_client *c, const char *terms, @@ -921,14 +949,12 @@ static int exp__search_shim(disorder_client *c, const char *terms, * - @parity: "even" or "odd" alternately * - @first: "true" on the first directory and "false" otherwise * - @last: "true" on the last directory and "false" otherwise - * - @sort: the sort key for this track - * - @display: the UNQUOTED display string for this track */ static int exp_search(int nargs, const struct mx_node **args, struct sink *output, void *u) { - return exp__files_dirs(nargs, args, output, u, "track", exp__search_shim); + return exp__files_dirs(nargs, args, output, u, NULL, exp__search_shim); } /*$ @label{NAME} @@ -963,7 +989,7 @@ static int exp_breadcrumbs(int attribute((unused)) nargs, return rc; /* Reject relative paths */ if(dir[0] != '/') { - error(0, "breadcrumbs: '%s' is a relative path", dir); + disorder_error(0, "breadcrumbs: '%s' is a relative path", dir); return 0; } /* Skip the root */ @@ -999,6 +1025,7 @@ void dcgi_expansions(void) { mx_register("label", 1, 1, exp_label); mx_register("length", 1, 1, exp_length); mx_register("movable", 1, 2, exp_movable); + mx_register("origin", 1, 1, exp_origin); mx_register("part", 2, 3, exp_part); mx_register("paused", 0, 0, exp_paused); mx_register("pref", 2, 2, exp_pref);