chiark / gitweb /
Further hacking. Some actual success at runtime now.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 17 May 2008 13:06:32 +0000 (14:06 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 17 May 2008 13:06:32 +0000 (14:06 +0100)
lib/macros.c
server/actions.c
server/macros-disorder.c
server/options.c
templates/choose.tmpl
templates/macros.tmpl
templates/options.labels
templates/playing.tmpl
templates/prefs.tmpl

index 540fc45ee9cc6b81dd80ee441ebaddae25baa0c5..f177ae0e10f9749a12966bcceb841d4ad6edc47f 100644 (file)
@@ -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;
index c0a8cb4b0a169d3c5aa112058a3009e5b1eca5fe..f0b49221d22d4821fe92f0969b3fb39ee034c1c4 100644 (file)
@@ -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");
 }
index 189d51d10cfd65e6fc814ad8ab0d071ff39f66a4..c2ac8b082e89c2dfebbba6a6d3f70fa51aa67d50 100644 (file)
@@ -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);
index 91856104d101e263ce91d4d983f9b23558462746..0453cd7b9268a7dcbb3b336e4d12d75f61a82ff4 100644 (file)
@@ -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 <url.static>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 <url.static>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;
 }
 
index a000cad3e4bd47fe52d386e0010d657118f8ccdc..7e60d55fd48da86056d96e64490dff77ae689d31 100644 (file)
@@ -26,7 +26,7 @@ USA
 @stdmenu{choose}
    <h1>@label:choose.title@</h1>
   
-  @if{@eq{@label{sidebar.choosewhich}}{choosealpha}}
+  @if{@eq{@label{menu.choosewhich}}{choosealpha}}
      {
    <p class=choosealpha>
     <a title="Directories starting with 'a'"
index 11ba25ccf1b1f667bcf670160ed4f2545fd871ed..c3b7ed8deab98a1afd562571b6e507c2e656fe99 100644 (file)
@@ -40,22 +40,23 @@ and then redefines macros as desired.
 
 @# Non-displaying <head> text
 @define {quiethead} {}
-        {<link rel=stylesheet
-      type="text/css"
-      href="@label{url.static}/disorder.css">}
+        {  <link rel=stylesheet
+        type="text/css"
+        href="@label{url.static}/disorder.css">}
 
 @# Standard menu
 @#   @current is the name of the current page, e.g. choosealpha, login
 @define {stdmenu} {current}
-        {<p class=menubar>
+        {  <p class=menubar>
 @menuitem{@current}{playing}{true}
+@menuitem{@current}{recent}{true}
 @menuitem{@current}{choose}{@right{play}}
 @menuitem{@current}{manage}{true}
 @menuitem{@current}{login}{true}
 @menuitem{@current}{help}{true}
 @menuitem{@current}{about}{true}
-</p>
-<hr>
+   </p>
+   <hr>
 }
 
 @# Menu entry
@@ -67,16 +68,15 @@ and then redefines macros as desired.
 @#  
 @define {menuitem} {current name available}  
         {@if{@available}
-            {  <a @if{@eq{@current}{@name}}
-                     {class=activemenu}
-                     {class=inactivemenu}
-                  @if{@eq{name}{playing}}
-                     {href="@url"}
-                     {href="@url?action=@name"}
-                  title="@label{menu.@q{@name}verbose}"
-                 @label{menu.@name}</a>}
-            {  <span class=invaldmenu title="@label{menu.@q{@name}verbose}">
-    @label{menu.@name}</span>}}
+            {   <a @if{@eq{@current}{@name}}
+                     {class=activemenu}
+                     {class=inactivemenu}
+@if{@eq{name}{playing}}
+   {      href="@url"}
+   {      href="@url?action=@name"}
+      title="@label{menu.@q{@name}verbose}">@label{menu.@name}</a>}
+            {   <span class=invalidmenu 
+         title="@label{menu.@q{@name}verbose}">@label{menu.@name}</span>}}
 
 
 @# Standard footer text
@@ -111,9 +111,9 @@ and then redefines macros as desired.
         {@right{play}
                {<a class=directory
                    href="@url?action=choose&amp;directory=@urlquote{@dirname{@dirname{@track}}}"
-                   title="@label{@what.artistverbose}">@part{@track}{short}{artist}</a>}
+                   title="@label{@what.artistverbose}">@part{@track}{artist}{short}</a>}
                {<span class=directory
-                      title="@part{@track}{artist}@">@part{@track}{short}{artist}</span>}}
+                      title="@part{@track}{artist}">@part{@track}{artist}{short}</span>}}
 
 @# Expand to the album for @track
 @#  @what is the section
@@ -122,15 +122,15 @@ and then redefines macros as desired.
         {@right{play}
                {<a class=directory
                    href="@url?action=choose&amp;directory=@urlquote{@dirname{@track}}"
-                   title="@label{@what.albumverbose}">@part{@track}{short}{album}</a>}
+                   title="@label{@what.albumverbose}">@part{@track}{album}{short}</a>}
                {<span class=directory
-                      title="@part{@track}{album}@">@part{@track}{short}{album}</span>}}
+                      title="@part{@track}{album}">@part{@track}{album}{short}</span>}}
 
 @# Expand to the title for @track
 @#  @what is the section
 @#  @track is the track name
 @define {mtitle} {what track}
-        {<span title="@part{@track}{title}">@part{@track}{short}{title}</span>}
+        {<span title="@part{@track}{title}">@part{@track}{title}{short}</span>}
 
 @# Expand to the remove/scratch entry for @id
 @#  @what is the section
index 85e0377216b90f150d52f1e0bdb1c94addd7437d..86586aad4ff2f7d629b2a2f2e85f214ba7dd3fb3 100644 (file)
@@ -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
index 5d369c0eeffbc2f93322eb2da69b595c2d82ba04..5a767e454164e2dd3508cc8cc08ec7674a657952 100644 (file)
@@ -26,7 +26,7 @@ USA
   @#  @state should be the current state
   @define {onoff} {class action state}
           {<a class=button
-              href="@url?action=@action@back"@class}@q{@state
+              href="@url?action=@action@back"
               title="@label{playing.@q{action}verbose}">
              @label{playing.@class}
            </a>
@@ -92,7 +92,7 @@ USA
           <input size=3 name=left type=text value="@volume{left}">
           @label{volume.right}
           <input size=3 name=right type=text value="@volume{right}">
-          <input name=back type=hidden value="@thisurl@?back=manage">
+          <input name=back type=hidden value="@thisurl?back=manage">
           @right{volume}{
             <button class=search name=submit type=submit>
                @label{volume.set}
@@ -146,28 +146,28 @@ USA
         }{}
        </tr>
      }
-     @if{@isqueue@}{
-       <tr class=next>
-        <td colspan=@ifmanage{11}{7}@>@label{playing.next}</td>
-       </tr>
+     @if{@isqueue}{
+      <tr class=next>
+       <td colspan=@ifmanage{11}{7}>@label{playing.next}</td>
+      </tr>
      }
      @queue{
-       <tr class=@parity@>
-        <td class=when>@mwhen{queue}{@id}</td>
-        <td class=who>@mwho{queue}{@id}</td>
-        <td class=artist>@martist{queue}{@track}</td>
-        <td class=album>@malbum{queue}{@track}</td>
-        <td class=title>@mtitle{queue}{@track}</td>
-        <td class=length>@length</td>
-        <td class=imgbutton>@mremove{queue}{@id}</td>
-        @ifmanage{
-          <td class=imgbutton>@mmove{@id}{upall}{2147483647}</td>
-          <td class=imgbutton>@mmove{@id}{up}{1}</td>
-          <td class=imgbutton>@mmove{@id}{down}{-1}</td>
-          <td class=imgbutton>@mmove{@id}{downall}{-2147483647}</td>
-        }
-       </tr>
-     }
+      <tr class=@parity>
+       <td class=when>@mwhen{queue}{@id}</td>
+       <td class=who>@mwho{queue}{@id}</td>
+       <td class=artist>@martist{queue}{@track}</td>
+       <td class=album>@malbum{queue}{@track}</td>
+       <td class=title>@mtitle{queue}{@track}</td>
+       <td class=length>@length{@id}</td>
+       <td class=imgbutton>@mremove{queue}{@id}</td>
+       @ifmanage{
+         <td class=imgbutton>@mmove{@id}{upall}{2147483647}</td>
+         <td class=imgbutton>@mmove{@id}{up}{1}</td>
+         <td class=imgbutton>@mmove{@id}{down}{-1}</td>
+         <td class=imgbutton>@mmove{@id}{downall}{-2147483647}</td>
+       }{}
+      </tr>
+    }
    </table>
 }
 
index e19d4acce1db20273a8a2ba776b6d73588c0bdd7..db03220d33ecaed48be540c2a41d28db7fd754c3 100644 (file)
@@ -40,7 +40,7 @@ USA
       </tr>
       <tr class=even>
        <td class="prefs_name">@label:heading.title@</td>
-       <td class="prefs_value"><input size=40 type=text name="@index@_title" value="@part{display}{title}{@arg{@index@_file}@}@"></td>
+       <td class="prefs_value"><input size=40 type=text name="@index@_title" value="@part{@arg{@index@_file}display}{title}{display}"></td>
       </tr>
       <tr class=odd>
        <td class="prefs_name">@label:heading.album@</td>