Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Someone
Sunday, May 29th, 2011 at 7:33:31pm UTC 

  1. Index: apps/tagtree.c
  2. ===================================================================
  3. --- apps/tagtree.c      (revision 29930)
  4. +++ apps/tagtree.c      (arbetskopia)
  5. @@ -156,6 +156,12 @@
  6.      struct menu_entry *items[TAGMENU_MAX_ITEMS];
  7.  };
  8.  
  9. +struct match
  10. +{
  11. +    const char* str;
  12. +    int symbol;
  13. +};
  14. +
  15.  /* Statusbar text of the current view. */
  16.  static char current_title[MAX_TAGS][128];
  17.  
  18. @@ -193,16 +199,48 @@
  19.      return 0;
  20.  }
  21.  
  22. -#define MATCH(tag,str1,str2,settag) \
  23. -    if (!strcasecmp(str1, str2)) { \
  24. -        *tag = settag; \
  25. -        return 1; \
  26. -    }
  27. -
  28.  static int get_tag(int *tag)
  29.  {
  30. +    static const struct match get_tag_match[] =
  31. +    {
  32. +        {"album", tag_album},
  33. +        {"artist", tag_artist},
  34. +        {"bitrate", tag_bitrate},
  35. +        {"composer", tag_composer},
  36. +        {"comment", tag_comment},
  37. +        {"albumartist", tag_albumartist},
  38. +        {"ensemble", tag_albumartist},
  39. +        {"grouping", tag_grouping},
  40. +        {"genre", tag_genre},
  41. +        {"length", tag_length},
  42. +        {"Lm", tag_virt_length_min},
  43. +        {"Ls", tag_virt_length_sec},
  44. +        {"Pm", tag_virt_playtime_min},
  45. +        {"Ps", tag_virt_playtime_sec},
  46. +        {"title", tag_title},
  47. +        {"filename", tag_filename},
  48. +        {"tracknum", tag_tracknumber},
  49. +        {"discnum", tag_discnumber},
  50. +        {"year", tag_year},
  51. +        {"playcount", tag_playcount},
  52. +        {"rating", tag_rating},
  53. +        {"lastplayed", tag_lastplayed},
  54. +        {"lastoffset", tag_lastoffset},
  55. +        {"commitid", tag_commitid},
  56. +        {"entryage", tag_virt_entryage},
  57. +        {"autoscore", tag_virt_autoscore},
  58. +        {"%sort", var_sorttype},
  59. +        {"%limit", var_limit},
  60. +        {"%strip", var_strip},
  61. +        {"%menu_start", var_menu_start},
  62. +        {"%include", var_include},
  63. +        {"%root_menu", var_rootmenu},
  64. +        {"%format", var_format},
  65. +        {"->", menu_next},
  66. +        {"==>", menu_load}
  67. +    };
  68.      char buf[128];
  69. -    int i;
  70. +    unsigned int i;
  71.      
  72.      /* Find the start. */
  73.      while ((*strp == ' ' || *strp == '>') && *strp != '\0')
  74. @@ -210,8 +248,8 @@
  75.      
  76.      if (*strp == '\0' || *strp == '?')
  77.          return 0;
  78. -   
  79. -    for (i = 0; i < (int)sizeof(buf)-1; i++)
  80. +
  81. +    for (i = 0; i < sizeof(buf)-1; i++)
  82.      {
  83.          if (*strp == '\0' || *strp == ' ')
  84.              break ;
  85. @@ -219,63 +257,54 @@
  86.          strp++;
  87.      }
  88.      buf[i] = '\0';
  89. -   
  90. -    MATCH(tag, buf, "album", tag_album);
  91. -    MATCH(tag, buf, "artist", tag_artist);
  92. -    MATCH(tag, buf, "bitrate", tag_bitrate);
  93. -    MATCH(tag, buf, "composer", tag_composer);
  94. -    MATCH(tag, buf, "comment", tag_comment);
  95. -    MATCH(tag, buf, "albumartist", tag_albumartist);
  96. -    MATCH(tag, buf, "ensemble", tag_albumartist);
  97. -    MATCH(tag, buf, "grouping", tag_grouping);
  98. -    MATCH(tag, buf, "genre", tag_genre);
  99. -    MATCH(tag, buf, "length", tag_length);
  100. -    MATCH(tag, buf, "Lm", tag_virt_length_min);
  101. -    MATCH(tag, buf, "Ls", tag_virt_length_sec);
  102. -    MATCH(tag, buf, "Pm", tag_virt_playtime_min);
  103. -    MATCH(tag, buf, "Ps", tag_virt_playtime_sec);
  104. -    MATCH(tag, buf, "title", tag_title);
  105. -    MATCH(tag, buf, "filename", tag_filename);
  106. -    MATCH(tag, buf, "tracknum", tag_tracknumber);
  107. -    MATCH(tag, buf, "discnum", tag_discnumber);
  108. -    MATCH(tag, buf, "year", tag_year);
  109. -    MATCH(tag, buf, "playcount", tag_playcount);
  110. -    MATCH(tag, buf, "rating", tag_rating);
  111. -    MATCH(tag, buf, "lastplayed", tag_lastplayed);
  112. -    MATCH(tag, buf, "lastoffset", tag_lastoffset);
  113. -    MATCH(tag, buf, "commitid", tag_commitid);
  114. -    MATCH(tag, buf, "entryage", tag_virt_entryage);
  115. -    MATCH(tag, buf, "autoscore", tag_virt_autoscore);
  116. -    MATCH(tag, buf, "%sort", var_sorttype);
  117. -    MATCH(tag, buf, "%limit", var_limit);
  118. -    MATCH(tag, buf, "%strip", var_strip);
  119. -    MATCH(tag, buf, "%menu_start", var_menu_start);
  120. -    MATCH(tag, buf, "%include", var_include);
  121. -    MATCH(tag, buf, "%root_menu", var_rootmenu);
  122. -    MATCH(tag, buf, "%format", var_format);
  123. -    MATCH(tag, buf, "->", menu_next);
  124. -    MATCH(tag, buf, "==>", menu_load);
  125. -   
  126. +
  127. +    for (i = 0; i < ARRAYLEN(get_tag_match); i++)
  128. +    {
  129. +        if (!strcasecmp(buf, get_tag_match[i].str))
  130. +        {
  131. +            *tag = get_tag_match[i].symbol;
  132. +            return 1;
  133. +        }
  134. +    }
  135. +
  136.      logf("NO MATCH: %s\n", buf);
  137.      if (buf[0] == '?')
  138.          return 0;
  139. -   
  140. +
  141.      return -1;
  142.  }
  143.  
  144.  static int get_clause(int *condition)
  145.  {
  146. +    static const struct match get_clause_match[] =
  147. +    {
  148. +        {"=", clause_is},
  149. +        {"==", clause_is},
  150. +        {"!=", clause_is_not},
  151. +        {">", clause_gt},
  152. +        {">=", clause_gteq},
  153. +        {"<", clause_lt},
  154. +        {"<=", clause_lteq},
  155. +        {"~", clause_contains},
  156. +        {"!~", clause_not_contains},
  157. +        {"^", clause_begins_with},
  158. +        {"!^", clause_not_begins_with},
  159. +        {"$", clause_ends_with},
  160. +        {"!$", clause_not_ends_with},
  161. +        {"@", clause_oneof}
  162. +    };
  163. +
  164.      char buf[4];
  165. -    int i;
  166. -   
  167. +    unsigned int i;
  168. +
  169.      /* Find the start. */
  170.      while (*strp == ' ' && *strp != '\0')
  171.          strp++;
  172. -   
  173. +
  174.      if (*strp == '\0')
  175.          return 0;
  176. -   
  177. -    for (i = 0; i < (int)sizeof(buf)-1; i++)
  178. +
  179. +    for (i = 0; i < sizeof(buf)-1; i++)
  180.      {
  181.          if (*strp == '\0' || *strp == ' ')
  182.              break ;
  183. @@ -283,22 +312,16 @@
  184.          strp++;
  185.      }
  186.      buf[i] = '\0';
  187. -   
  188. -    MATCH(condition, buf, "=", clause_is);
  189. -    MATCH(condition, buf, "==", clause_is);
  190. -    MATCH(condition, buf, "!=", clause_is_not);
  191. -    MATCH(condition, buf, ">", clause_gt);
  192. -    MATCH(condition, buf, ">=", clause_gteq);
  193. -    MATCH(condition, buf, "<", clause_lt);
  194. -    MATCH(condition, buf, "<=", clause_lteq);
  195. -    MATCH(condition, buf, "~", clause_contains);
  196. -    MATCH(condition, buf, "!~", clause_not_contains);
  197. -    MATCH(condition, buf, "^", clause_begins_with);
  198. -    MATCH(condition, buf, "!^", clause_not_begins_with);
  199. -    MATCH(condition, buf, "$", clause_ends_with);
  200. -    MATCH(condition, buf, "!$", clause_not_ends_with);
  201. -    MATCH(condition, buf, "@", clause_oneof);
  202. -   
  203. +
  204. +    for (i = 0; i < ARRAYLEN(get_clause_match); i++)
  205. +    {
  206. +        if (!strcasecmp(buf, get_clause_match[i].str))
  207. +        {
  208. +            *condition = get_clause_match[i].symbol;
  209. +            return 1;
  210. +        }
  211. +    }
  212. +
  213.      return 0;
  214.  }
  215.  

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right worth-right