Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2010
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. Index: skin_parser.c
  2. ===================================================================
  3. --- skin_parser.c (revision 26458)
  4. +++ skin_parser.c (working copy)
  5. @@ -407,25 +407,27 @@
  6. star = 1;
  7. tag_args++;
  8. }
  9. -
  10. /* If this tag has no arguments, we can bail out now */
  11. if(strlen(tag_args) == 0
  12. - || (tag_args[0] == '|' && *cursor != ARGLISTOPENSYM))
  13. + || (tag_args[0] == '|' && *cursor != ARGLISTOPENSYM)
  14. + || (star && *cursor != ARGLISTOPENSYM))
  15. {
  16. *document = cursor;
  17. return 1;
  18. }
  19. + star = 0;
  20.  
  21. /* Checking the number of arguments and allocating args */
  22. if(*cursor != ARGLISTOPENSYM && tag_args[0] != '|')
  23. {
  24. - skin_error(ARGLIST_EXPECTED);
  25. + skin_error(ARGLIST_EXPECTED, tag_name);
  26. return 0;
  27. }
  28. else
  29. {
  30. cursor++;
  31. }
  32. +
  33.  
  34. for(bookmark = cursor; *cursor != '\n' && *cursor != '\0' &&
  35. *cursor != ARGLISTCLOSESYM; cursor++)
  36. @@ -455,24 +457,10 @@
  37. element->params_count = num_args;
  38. element->params = skin_alloc_params(num_args);
  39.  
  40. - /* Now we have to actually parse each argument */
  41. - for(i = 0; i < num_args; i++)
  42. + i=0; /* found tags */
  43. + while (*tag_args && i<num_args)
  44. {
  45. - /* Making sure we haven't run out of arguments */
  46. - if(*tag_args == '\0')
  47. - {
  48. - skin_error(TOO_MANY_ARGS);
  49. - return 0;
  50. - }
  51. -
  52. - /* Checking for the optional bar */
  53. - if(*tag_args == '|')
  54. - {
  55. - optional = 1;
  56. - req_args = i;
  57. - tag_args++;
  58. - }
  59. -
  60. + int is_default;
  61. /* Scanning the arguments */
  62. skip_whitespace(&cursor);
  63.  
  64. @@ -483,85 +471,99 @@
  65.  
  66. /* Storing the type code */
  67. element->params[i].type_code = *tag_args;
  68. + is_default = (*cursor == DEFAULTSYM);
  69. +
  70. + switch (*tag_args)
  71. + {
  72. + case '|':
  73. + optional = 1;
  74. + tag_args++;
  75. + continue;
  76. + case 'i':
  77. + if (is_default)
  78. + {
  79. + skin_error(DEFAULT_NOT_ALLOWED, "");
  80. + return 0;
  81. + }
  82. + case 'I':
  83. + if (!is_default)
  84. + {
  85. + /* Scanning an int argument */
  86. + if(!isdigit(*cursor))
  87. + {
  88. + skin_error(INT_EXPECTED, "");
  89. + return 0;
  90. + }
  91.  
  92. - /* Checking a nullable argument for null */
  93. - if(*cursor == DEFAULTSYM)
  94. + element->params[i].type = NUMERIC;
  95. + element->params[i].data.numeric = scan_int(&cursor);
  96. + }
  97. + else
  98. + {
  99. + element->params[i].type = DEFAULT;
  100. + }
  101. + break;
  102. + case 's':
  103. + case 'f':
  104. + if (is_default)
  105. + {
  106. + skin_error(DEFAULT_NOT_ALLOWED, "");
  107. + return 0;
  108. + }
  109. + case 'S':
  110. + case 'F':
  111. + /* Scanning a string argument */
  112. + if (!is_default)
  113. + {
  114. + element->params[i].type = STRING;
  115. + element->params[i].data.text = scan_string(&cursor);
  116. + }
  117. + else
  118. + {
  119. + element->params[i].type = DEFAULT;
  120. + }
  121. + break;
  122. + case 'c':
  123. + if (is_default)
  124. + {
  125. + skin_error(DEFAULT_NOT_ALLOWED, "");
  126. + return 0;
  127. + }
  128. + case 'C':
  129. + /* Recursively parsing a code argument */
  130. + element->params[i].type = CODE;
  131. + element->params[i].data.code = skin_parse_code_as_arg(&cursor);
  132. + if(!element->params[i].data.code)
  133. + return 0;
  134. + break;
  135. + } /* switch (*tag_args) */
  136. + tag_args++;
  137. + i++;
  138. +
  139. + if (*cursor == ARGLISTCLOSESYM)
  140. {
  141. - if(islower(*tag_args))
  142. + if (!optional && *tag_args && *tag_args != '|')
  143. {
  144. - element->params[i].type = DEFAULT;
  145. - cursor++;
  146. - }
  147. - else
  148. - {
  149. - skin_error(DEFAULT_NOT_ALLOWED);
  150. + skin_error(INSUFFICIENT_ARGS, tag_name);
  151. return 0;
  152. }
  153. }
  154. - else if(tolower(*tag_args) == 'i')
  155. + else if (*cursor == ARGLISTSEPERATESYM)
  156. {
  157. - /* Scanning an int argument */
  158. - if(!isdigit(*cursor))
  159. + if (!*tag_args)
  160. {
  161. - skin_error(INT_EXPECTED);
  162. + skin_error(TOO_MANY_ARGS, tag_name);
  163. return 0;
  164. }
  165. -
  166. - element->params[i].type = NUMERIC;
  167. - element->params[i].data.numeric = scan_int(&cursor);
  168. }
  169. - else if(tolower(*tag_args) == 's' || tolower(*tag_args) == 'f')
  170. + else
  171. {
  172. - /* Scanning a string argument */
  173. - element->params[i].type = STRING;
  174. - element->params[i].data.text = scan_string(&cursor);
  175. -
  176. - }
  177. - else if(tolower(*tag_args) == 'c')
  178. - {
  179. - /* Recursively parsing a code argument */
  180. - element->params[i].type = CODE;
  181. - element->params[i].data.code = skin_parse_code_as_arg(&cursor);
  182. - if(!element->params[i].data.code)
  183. - return 0;
  184. - }
  185. -
  186. - skip_whitespace(&cursor);
  187. -
  188. - if(*cursor != ARGLISTSEPERATESYM && i < num_args - 1)
  189. - {
  190. - skin_error(SEPERATOR_EXPECTED);
  191. + skin_error(SEPERATOR_EXPECTED, "");
  192. return 0;
  193. }
  194. - else if(*cursor != ARGLISTCLOSESYM && i == num_args - 1)
  195. - {
  196. - skin_error(CLOSE_EXPECTED);
  197. - return 0;
  198. - }
  199. - else
  200. - {
  201. - cursor++;
  202. - }
  203. -
  204. - tag_args++;
  205. -
  206. - /* Checking for the optional bar */
  207. - if(*tag_args == '|')
  208. - {
  209. - optional = 1;
  210. - req_args = i + 1;
  211. - tag_args++;
  212. - }
  213. -
  214. + cursor++;
  215. }
  216.  
  217. - /* Checking for a premature end */
  218. - if(*tag_args != '\0' && !(optional && (!star || num_args == req_args)))
  219. - {
  220. - skin_error(INSUFFICIENT_ARGS);
  221. - return 0;
  222. - }
  223. -
  224. *document = cursor;
  225.  
  226. return 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement