X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/1e97629da2ea6c1ae328912ba82d4595eb08b700..04aa2c4f1affbc96f5de4ad492e9dce89f6209e1:/server/macros-disorder.c diff --git a/server/macros-disorder.c b/server/macros-disorder.c index bb920f4..2dc8098 100644 --- a/server/macros-disorder.c +++ b/server/macros-disorder.c @@ -1,3 +1,4 @@ + /* * This file is part of DisOrder. * Copyright (C) 2004-2008 Richard Kettlewell @@ -24,25 +25,10 @@ #include "disorder-cgi.h" /** @brief For error template */ -char *dcgi_error_string; - -/** @brief Locate a track by ID */ -static struct queue_entry *findtrack(const char *id) { - struct queue_entry *q; +const char *dcgi_error_string; - dcgi_lookup(DCGI_PLAYING); - if(dcgi_playing && !strcmp(dcgi_playing->id, id)) - return dcgi_playing; - dcgi_lookup(DCGI_QUEUE); - for(q = dcgi_queue; q; q = q->next) - if(!strcmp(q->id, id)) - return q; - dcgi_lookup(DCGI_RECENT); - for(q = dcgi_recent; q; q = q->next) - if(!strcmp(q->id, id)) - return q; - return NULL; -} +/** @brief For login template */ +const char *dcgi_status_string; /** @brief Return @p i as a string */ static const char *make_index(int i) { @@ -52,7 +38,7 @@ static const char *make_index(int i) { return s; } -/* @server-version +/*! @server-version * * Expands to the server's version string, or a (safe to use) error * value if the server is unavailable or broken. @@ -71,7 +57,7 @@ static int exp_server_version(int attribute((unused)) nargs, return sink_writes(output, cgi_sgmlquote(v)) < 0 ? -1 : 0; } -/* @version +/*! @version * * Expands to the local version string. */ @@ -83,7 +69,7 @@ static int exp_version(int attribute((unused)) nargs, cgi_sgmlquote(disorder_short_version_string)) < 0 ? -1 : 0; } -/* @url +/*! @url * * Expands to the base URL of the web interface. */ @@ -95,24 +81,41 @@ static int exp_url(int attribute((unused)) nargs, cgi_sgmlquote(config->url)) < 0 ? -1 : 0; } -/* @arg{NAME} +/*! @arg{NAME} * - * Expands to the CGI argument NAME, or the empty string if there is - * no such argument. + * Expands to the UNQUOTED form of CGI argument NAME, or the empty string if + * there is no such argument. Use @argq for a quick way to quote the argument. */ static int exp_arg(int attribute((unused)) nargs, char **args, struct sink *output, void attribute((unused)) *u) { const char *s = cgi_get(args[0]); + if(s) - return sink_writes(output, - cgi_sgmlquote(s)) < 0 ? -1 : 0; + return sink_writes(output, s) < 0 ? -1 : 0; else return 0; } -/* @user +/*! @argq{NAME} + * + * Expands to the (quoted) form of CGI argument NAME, or the empty string if + * there is no such argument. Use @arg for the unquoted argument. + */ +static int exp_argq(int attribute((unused)) nargs, + char **args, + struct sink *output, + void attribute((unused)) *u) { + const char *s = cgi_get(args[0]); + + if(s) + return sink_writes(output, cgi_sgmlquote(s)) < 0 ? -1 : 0; + else + return 0; +} + +/*! @user * * Expands to the logged-in username (which might be "guest"), or to * the empty string if not connected. @@ -128,7 +131,7 @@ static int exp_user(int attribute((unused)) nargs, return 0; } -/* @part{TRACK|ID}{PART}{CONTEXT} +/*! @part{TRACK|ID}{PART}{CONTEXT} * * Expands to a track name part. * @@ -149,7 +152,7 @@ static int exp_part(int nargs, char *s; if(track[0] != '/') { - struct queue_entry *q = findtrack(track); + struct queue_entry *q = dcgi_findtrack(track); if(q) track = q->track; @@ -165,7 +168,7 @@ static int exp_part(int nargs, return 0; } -/* @quote{STRING} +/*! @quote{STRING} * * SGML-quotes STRING. Note that most expansion results are already suitable * quoted, so this expansion is usually not required. @@ -177,7 +180,7 @@ static int exp_quote(int attribute((unused)) nargs, return sink_writes(output, cgi_sgmlquote(args[0])) < 0 ? -1 : 0; } -/* @who{ID} +/*! @who{ID} * * Expands to the name of the submitter of track ID, which must be a playing * track, in the queue, or in the recent list. @@ -186,14 +189,14 @@ static int exp_who(int attribute((unused)) nargs, char **args, struct sink *output, void attribute((unused)) *u) { - struct queue_entry *q = findtrack(args[0]); + struct queue_entry *q = dcgi_findtrack(args[0]); if(q && q->submitter) return sink_writes(output, cgi_sgmlquote(q->submitter)) < 0 ? -1 : 0; return 0; } -/* @when{ID} +/*! @when{ID} * * Expands to the time a track started or is expected to start. The track must * be a playing track, in the queue, or in the recent list. @@ -202,7 +205,7 @@ static int exp_when(int attribute((unused)) nargs, char **args, struct sink *output, void attribute((unused)) *u) { - struct queue_entry *q = findtrack(args[0]); + struct queue_entry *q = dcgi_findtrack(args[0]); const struct tm *w = 0; if(q) { @@ -230,7 +233,7 @@ static int exp_when(int attribute((unused)) nargs, return sink_writes(output, " ") < 0 ? -1 : 0; } -/* @length{ID|TRACK} +/*! @length{ID|TRACK} * * Expands to the length of a track, identified by its queue ID or its name. * If it is the playing track (identified by ID) then the amount played so far @@ -249,7 +252,7 @@ static int exp_length(int attribute((unused)) nargs, name = args[0]; else { /* Track identified by queue ID */ - if(!(q = findtrack(args[0]))) + if(!(q = dcgi_findtrack(args[0]))) return 0; if(q->state == playing_started || q->state == playing_paused) if(sink_printf(output, "%ld:%02ld/", q->sofar / 60, q->sofar % 60) < 0) @@ -262,7 +265,7 @@ static int exp_length(int attribute((unused)) nargs, return sink_writes(output, " ") < 0 ? -1 : 0; } -/* @removable{ID} +/*! @removable{ID} * * Expands to "true" if track ID is removable (or scratchable, if it is the * playing track) and "false" otherwise. @@ -271,7 +274,7 @@ static int exp_removable(int attribute((unused)) nargs, char **args, struct sink *output, void attribute((unused)) *u) { - struct queue_entry *q = findtrack(args[0]); + struct queue_entry *q = dcgi_findtrack(args[0]); /* TODO would be better to reject recent */ if(!q || !dcgi_client) @@ -282,29 +285,45 @@ static int exp_removable(int attribute((unused)) nargs, (dcgi_rights, disorder_user(dcgi_client), q)); } -/* @movable{ID} +/*! @movable{ID}{DIR} * * Expands to "true" if track ID is movable and "false" otherwise. + * + * DIR (which is optional) should be a non-zero integer. If it is negative + * then the intended move is down (later in the queue), if it is positive then + * the intended move is up (earlier in the queue). The first track is not + * movable up and the last track not movable down. */ -static int exp_movable(int attribute((unused)) nargs, +static int exp_movable(int nargs, char **args, struct sink *output, void attribute((unused)) *u) { - struct queue_entry *q = findtrack(args[0]); + struct queue_entry *q = dcgi_findtrack(args[0]); /* TODO would be better to recent playing/recent */ if(!q || !dcgi_client) return mx_bool_result(output, 0); + if(nargs > 1) { + const long dir = atoi(args[1]); + + if(dir > 0 && q == dcgi_queue) + return mx_bool_result(output, 0); + if(dir < 0 && q->next == 0) + return mx_bool_result(output, 0); + } dcgi_lookup(DCGI_RIGHTS); return mx_bool_result(output, - right_movable(dcgi_rights, disorder_user(dcgi_client), q)); + right_movable(dcgi_rights, + disorder_user(dcgi_client), + q)); } -/* @playing{TEMPLATE} +/*! @playing{TEMPLATE} * - * Expands to TEMPLATE, with: - * - @id@ expanded to the queue ID of the playing track - * - @track@ expanded to its UNQUOTED name + * Expands to TEMPLATE, with the following expansions: + * - @id: the queue ID of the playing track + * - @track: the playing track's + UNQUOTED name * * If no track is playing expands to nothing. * @@ -327,15 +346,15 @@ static int exp_playing(int nargs, output, u); } -/* @queue{TEMPLATE} +/*! @queue{TEMPLATE} * * For each track in the queue, expands TEMPLATE with the following expansions: - * - @id@ to the queue ID of the track - * - @track@ to the UNQUOTED track name - * - @index@ to the track number from 0 - * - @parity@ to "even" or "odd" alternately - * - @first@ to "true" on the first track and "false" otherwise - * - @last@ to "true" on the last track and "false" otherwise + * - @id: the queue ID of the track + * - @track: the UNQUOTED track name + * - @index: the track number from 0 + * - @parity: "even" or "odd" alternately + * - @first: "true" on the first track and "false" otherwise + * - @last: "true" on the last track and "false" otherwise */ static int exp_queue(int attribute((unused)) nargs, const struct mx_node **args, @@ -359,16 +378,16 @@ static int exp_queue(int attribute((unused)) nargs, return 0; } -/* @recent{TEMPLATE} +/*! @recent{TEMPLATE} * * For each track in the recently played list, expands TEMPLATE with the * following expansions: - * - @id@ to the queue ID of the track - * - @track@ to the UNQUOTED track name - * - @index@ to the track number from 0 - * - @parity@ to "even" or "odd" alternately - * - @first@ to "true" on the first track and "false" otherwise - * - @last@ to "true" on the last track and "false" otherwise + * - @id: the queue ID of the track + * - @track: the UNQUOTED track name + * - @index: the track number from 0 + * - @parity: "even" or "odd" alternately + * - @first: "true" on the first track and "false" otherwise + * - @last: "true" on the last track and "false" otherwise */ static int exp_recent(int attribute((unused)) nargs, const struct mx_node **args, @@ -392,18 +411,18 @@ static int exp_recent(int attribute((unused)) nargs, return 0; } -/* @new{TEMPLATE} +/*! @new{TEMPLATE} * * For each track in the newly added list, expands TEMPLATE wit the following * expansions: - * - @track@ to the UNQUOTED track name - * - @index@ to the track number from 0 - * - @parity@ to "even" or "odd" alternately - * - @first@ to "true" on the first track and "false" otherwise - * - @last@ to "true" on the last track and "false" otherwise + * - @track: the UNQUOTED track name + * - @index: the track number from 0 + * - @parity: "even" or "odd" alternately + * - @first: "true" on the first track and "false" otherwise + * - @last: "true" on the last track and "false" otherwise * - * Note that unlike @playing@, @queue@ and @recent@ which are otherwise - * superficially similar, there is no @id@ sub-expansion here. + * Note that unlike @playing, @queue and @recent which are otherwise + * superficially similar, there is no @id sub-expansion here. */ static int exp_new(int attribute((unused)) nargs, const struct mx_node **args, @@ -426,7 +445,7 @@ static int exp_new(int attribute((unused)) nargs, return 0; } -/* @volume{CHANNEL} +/*! @volume{CHANNEL} * * Expands to the volume in a given channel. CHANNEL must be "left" or * "right". @@ -441,7 +460,7 @@ static int exp_volume(int attribute((unused)) nargs, ? dcgi_volume_left : dcgi_volume_right) < 0 ? -1 : 0; } -/* @isplaying +/*! @isplaying * * Expands to "true" if there is a playing track, otherwise "false". */ @@ -453,7 +472,7 @@ static int exp_isplaying(int attribute((unused)) nargs, return mx_bool_result(output, !!dcgi_playing); } -/* @isqueue +/*! @isqueue * * Expands to "true" if there the queue is nonempty, otherwise "false". */ @@ -465,7 +484,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". @@ -478,7 +497,7 @@ static int exp_isrecent(int attribute((unused)) nargs, return mx_bool_result(output, !!dcgi_recent); } -/* @isnew +/*! @isnew * * Expands to "true" if there the newly added track list is nonempty, otherwise * "false". @@ -491,7 +510,7 @@ static int exp_isnew(int attribute((unused)) nargs, return mx_bool_result(output, !!dcgi_nnew); } -/* @pref{TRACK}{KEY} +/*! @pref{TRACK}{KEY} * * Expands to a track preference. */ @@ -506,18 +525,18 @@ static int exp_pref(int attribute((unused)) nargs, return 0; } -/* @prefs{TRACK}{TEMPLATE} +/*! @prefs{TRACK}{TEMPLATE} * * For each track preference of track TRACK, expands TEMPLATE with the * following expansions: - * - @name@ to the UNQUOTED preference name - * - @index@ to the preference number from 0 - * - @value@ to the UNQUOTED preference value - * - @parity@ to "even" or "odd" alternately - * - @first@ to "true" on the first preference and "false" otherwise - * - @last@ to "true" on the last preference and "false" otherwise + * - @name: the UNQUOTED preference name + * - @index: the preference number from 0 + * - @value: the UNQUOTED preference value + * - @parity: "even" or "odd" alternately + * - @first: "true" on the first preference and "false" otherwise + * - @last: "true" on the last preference and "false" otherwise * - * Use @quote@ to quote preference names and values where necessary; see below. + * Use @quote to quote preference names and values where necessary; see below. */ static int exp_prefs(int attribute((unused)) nargs, const struct mx_node **args, @@ -545,7 +564,7 @@ static int exp_prefs(int attribute((unused)) nargs, return 0; } -/* @transform{TRACK}{TYPE}{CONTEXT} +/*! @transform{TRACK}{TYPE}{CONTEXT} * * Transforms a track name (if TYPE is "track") or directory name (if type is * "dir"). CONTEXT should be the context, if it is left out then "display" is @@ -560,7 +579,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". */ @@ -575,7 +594,7 @@ static int exp_enabled(int attribute((unused)) nargs, return mx_bool_result(output, e); } -/* @random-enabled +/*! @random-enabled * * Expands to "true" if random play is enabled, otherwise "false". */ @@ -590,7 +609,7 @@ static int exp_random_enabled(int attribute((unused)) nargs, return mx_bool_result(output, e); } -/* @trackstate{TRACK} +/*! @trackstate{TRACK} * * Expands to "playing" if TRACK is currently playing, or "queue" if it is in * the queue, otherwise to nothing. @@ -616,7 +635,7 @@ static int exp_trackstate(int attribute((unused)) nargs, return 0; } -/* @thisurl +/*! @thisurl * * Expands to an UNQUOTED URL which points back to the current page. (NB it * might not be byte for byte identical - for instance, CGI arguments might be @@ -629,7 +648,7 @@ static int exp_thisurl(int attribute((unused)) nargs, return sink_writes(output, cgi_thisurl(config->url)) < 0 ? -1 : 0; } -/* @resolve{TRACK} +/*! @resolve{TRACK} * * Expands to an UNQUOTED name for the TRACK that is not an alias, or to * nothing if it is not a valid track. @@ -645,7 +664,7 @@ static int exp_resolve(int attribute((unused)) nargs, return 0; } -/* @paused +/*! @paused * * Expands to "true" if the playing track is paused, to "false" if it is * playing (or if there is no playing track at all). @@ -653,13 +672,13 @@ static int exp_resolve(int attribute((unused)) nargs, static int exp_paused(int attribute((unused)) nargs, char attribute((unused)) **args, struct sink *output, - void attribute((unused)) *u) { + void attribute((unused)) *u) { dcgi_lookup(DCGI_PLAYING); return mx_bool_result(output, (dcgi_playing && dcgi_playing->state == playing_paused)); } -/* @state{ID}@ +/*! @state{ID}@ * * Expands to the current state of track ID. */ @@ -667,14 +686,14 @@ static int exp_state(int attribute((unused)) nargs, char **args, struct sink *output, void attribute((unused)) *u) { - struct queue_entry *q = findtrack(args[0]); + struct queue_entry *q = dcgi_findtrack(args[0]); if(q) return sink_writes(output, playing_states[q->state]) < 0 ? -1 : 0; return 0; } -/* @right{RIGHT}{WITH-RIGHT}{WITHOUT-RIGHT}@ +/*! @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. @@ -711,7 +730,7 @@ static int exp_right(int nargs, return 0; } -/* @userinfo{PROPERTY} +/*! @userinfo{PROPERTY} * * Expands to the named property of the current user. */ @@ -728,7 +747,7 @@ static int exp_userinfo(int attribute((unused)) nargs, return 0; } -/* @error +/*! @error * * Expands to the latest error string. */ @@ -736,20 +755,264 @@ static int exp_error(int attribute((unused)) nargs, char attribute((unused)) **args, struct sink *output, void attribute((unused)) *u) { - return sink_writes(output, cgi_sgmlquote(dcgi_error_string)) < 0 ? -1 : 0; + return sink_writes(output, dcgi_error_string ? dcgi_error_string : "") + < 0 ? -1 : 0; +} + +/*! @status + * + * Expands to the latest status string. + */ +static int exp_status(int attribute((unused)) nargs, + char attribute((unused)) **args, + struct sink *output, + void attribute((unused)) *u) { + return sink_writes(output, dcgi_status_string ? dcgi_status_string : "") + < 0 ? -1 : 0; +} + +/*! @image{NAME} + * + * Expands to the URL of the image called NAME. + * + * Firstly if there is a label called images.NAME then the image stem will be + * the value of that label. Otherwise the stem will be NAME.png. + * + * If the label url.static exists then it will give the base URL for images. + * Otherwise the base url will be /disorder/. + */ +static int exp_image(int attribute((unused)) nargs, + char **args, + struct sink *output, + void attribute((unused)) *u) { + const char *url, *stem; + char *labelname; + + /* Compute the stem */ + byte_xasprintf(&labelname, "images.%s", args[0]); + if(option_label_exists(labelname)) + stem = option_label(labelname); + else + byte_xasprintf((char **)&stem, "%s.png", args[0]); + /* If the stem looks like it's reasonalby complete, use that */ + if(stem[0] == '/' + || !strncmp(stem, "http:", 5) + || !strncmp(stem, "https:", 6)) + url = stem; + else { + /* Compute the URL */ + if(option_label_exists("url.static")) + byte_xasprintf((char **)&url, "%s/%s", + option_label("url.static"), stem); + else + /* Default base is /disorder */ + byte_xasprintf((char **)&url, "/disorder/%s", stem); + } + return sink_writes(output, cgi_sgmlquote(url)) < 0 ? -1 : 0; +} + +/** @brief Compare two @ref entry objects */ +int dcgi_compare_entry(const void *a, const void *b) { + const struct dcgi_entry *ea = a, *eb = b; + + return compare_tracks(ea->sort, eb->sort, + ea->display, eb->display, + ea->track, eb->track); } +/** @brief Implementation of exp_tracks() and exp_dirs() */ +static int exp__files_dirs(int nargs, + const struct mx_node **args, + struct sink *output, + void *u, + const char *type, + int (*fn)(disorder_client *client, + const char *name, + const char *re, + char ***vecp, + int *nvecp)) { + char **tracks, *dir, *re; + int n, ntracks, rc; + const struct mx_node *m; + struct dcgi_entry *e; + + if((rc = mx_expandstr(args[0], &dir, u, "argument #0 (DIR)"))) + return rc; + if(nargs == 3) { + if((rc = mx_expandstr(args[1], &re, u, "argument #1 (RE)"))) + return rc; + m = args[2]; + } else { + re = 0; + m = args[1]; + } + if(!dcgi_client) + return 0; + /* Get the list */ + if(fn(dcgi_client, dir, re, &tracks, &ntracks)) + return 0; + /* Sort it. NB trackname_transform() does not go to the server. */ + e = xcalloc(ntracks, sizeof *e); + for(n = 0; n < ntracks; ++n) { + e->track = tracks[n]; + e[n].track = tracks[n]; + e[n].sort = trackname_transform(type, tracks[n], "sort"); + e[n].display = trackname_transform(type, tracks[n], "display"); + } + qsort(e, ntracks, sizeof (struct dcgi_entry), dcgi_compare_entry); + /* 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", tracks[n], + "first", n == 0 ? "true" : "false", + "last", n + 1 == ntracks ? "false" : "true", + "sort", e[n].sort, + "display", e[n].display, + (char *)0), + output, u))) + return rc; + return 0; + +} + +/*! @tracks{DIR}{RE}{TEMPLATE} + * + * For each track below DIR, expands TEMPLATE with the + * following expansions: + * - @track: the UNQUOTED track name + * - @index: the track number from 0 + * - @parity: "even" or "odd" alternately + * - @first: "true" on the first track and "false" otherwise + * - @last: "true" on the last track and "false" otherwise + * - @sort: the sort key for this track + * - @display: the UNQUOTED display string for this track + * + * RE is optional and if present is the regexp to match against. + */ +static int exp_tracks(int nargs, + const struct mx_node **args, + struct sink *output, + void *u) { + return exp__files_dirs(nargs, args, output, u, "track", disorder_files); +} + +/*! @dirs{DIR}{RE}{TEMPLATE} + * + * For each directory below DIR, expands TEMPLATE with the + * following expansions: + * - @track: the UNQUOTED directory name + * - @index: the directory number from 0 + * - @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 directory + * - @display: the UNQUOTED display string for this directory + * + * RE is optional and if present is the regexp to match against. + */ +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); +} + +static int exp__search_shim(disorder_client *c, const char *terms, + const char attribute((unused)) *re, + char ***vecp, int *nvecp) { + return disorder_search(c, terms, vecp, nvecp); +} + +/*! @search{KEYWORDS}{TEMPLATE} + * + * For each track matching KEYWORDS, expands TEMPLATE with the + * following expansions: + * - @track: the UNQUOTED directory name + * - @index: the directory number from 0 + * - @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); +} + +/*! @label{NAME} + * + * Expands to label NAME from options.labels. Undefined lables expand to the + * last dot-separated component, e.g. X.Y.Z to Z. + */ +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; +} + +/*! @breadcrumbs{DIR}{TEMPLATE} + * + * Expands TEMPLATE for each directory in the path up to DIR, excluding the root + * but including DIR itself, with the following expansions: + * - @dir: the directory + * - @last: "true" if this is the last directory, otherwise "false" + * + * DIR must be an absolute path. + */ +static int exp_breadcrumbs(int attribute((unused)) nargs, + const struct mx_node **args, + struct sink *output, + void attribute((unused)) *u) { + int rc; + char *dir, *parent, *ptr; + + if((rc = mx_expandstr(args[0], &dir, u, "argument #0 (DIR)"))) + return rc; + /* Reject relative paths */ + if(dir[0] != '/') { + error(0, "breadcrumbs: '%s' is a relative path", dir); + return 0; + } + /* Skip the root */ + ptr = dir + 1; + while(*ptr) { + /* Find the end of this directory */ + while(*ptr && *ptr != '/') + ++ptr; + parent = xstrndup(dir, ptr - dir); + if((rc = mx_expand(mx_rewritel(args[1], + "dir", parent, + "last", *ptr ? "false" : "true", + (char *)0), + output, u))) + return rc; + if(*ptr) + ++ptr; + } + return 0; +} + /** @brief Register DisOrder-specific expansions */ void dcgi_expansions(void) { mx_register("arg", 1, 1, exp_arg); + mx_register("argq", 1, 1, exp_argq); mx_register("enabled", 0, 0, exp_enabled); mx_register("error", 0, 0, exp_error); + 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); @@ -759,6 +1022,7 @@ void dcgi_expansions(void) { mx_register("resolve", 1, 1, exp_resolve); mx_register("server-version", 0, 0, exp_server_version); mx_register("state", 1, 1, exp_state); + mx_register("status", 0, 0, exp_status); mx_register("thisurl", 0, 0, exp_thisurl); mx_register("trackstate", 1, 1, exp_trackstate); mx_register("transform", 2, 3, exp_transform); @@ -769,12 +1033,16 @@ void dcgi_expansions(void) { mx_register("volume", 1, 1, exp_volume); mx_register("when", 1, 1, exp_when); mx_register("who", 1, 1, exp_who); + mx_register_magic("breadcrumbs", 2, 2, exp_breadcrumbs); + mx_register_magic("dirs", 2, 3, exp_dirs); mx_register_magic("new", 1, 1, exp_new); mx_register_magic("playing", 0, 1, exp_playing); mx_register_magic("prefs", 2, 2, exp_prefs); mx_register_magic("queue", 1, 1, exp_queue); mx_register_magic("recent", 1, 1, exp_recent); mx_register_magic("right", 1, 3, exp_right); + mx_register_magic("search", 2, 2, exp_search); + mx_register_magic("tracks", 2, 3, exp_tracks); } /*