/// Starts an if void tag_if(parser_status *st, list *l){ int lc=list_count(l); if (lc==2){ function_add_code(st, " {\n" " const char *tmp;\n" ); variable_solve(st, tag_value_arg(l, 1), "tmp", tag_type_arg(l,1)); function_add_code(st, " if (tmp && strcmp(tmp, \"false\")!=0)\n", tag_value_arg(l,1)); } else if (lc==4){ const char *op=tag_value_arg(l, 2); const char *opcmp=NULL; if (strcmp(op,"==")==0) opcmp="==0"; else if (strcmp(op,"<=")==0) opcmp="<=0"; else if (strcmp(op,"<")==0) opcmp="<0"; else if (strcmp(op,">=")==0) opcmp=">=0"; else if (strcmp(op,">")==0) opcmp=">0"; else if (strcmp(op,"!=")==0) opcmp="!=0"; if (opcmp){ function_add_code(st, " {\n" " const char *op1, *op2;\n"); variable_solve(st, tag_value_arg(l, 1), "op1", tag_type_arg(l,1)); variable_solve(st, tag_value_arg(l, 3), "op2", tag_type_arg(l,3)); function_add_code(st, " if (op1==op2 || (op1 && op2 && strcmp(op1, op2)%s))\n",opcmp); } else{ ONION_ERROR("%s:%d Unkonwn operator for if: %s", st->infilename, st->line, op); st->status=1; } } else{ ONION_ERROR("%s:%d If only allows 1 or 3 arguments. TODO. Has %d.", st->infilename, st->line, lc-1); st->status=1; } function_new(st, NULL); }
/** * @short Parses a block variable and writes the code necesary. * * It can go deep inside a dict or list, and apply filters. */ void variable_write(parser_status *st, onion_block *b){ function_add_code(st, " {\n" " const char *tmp;\n"); variable_solve(st, onion_block_data(b), "tmp", STRING); function_add_code(st, " if (tmp)\n" " onion_response_write_html_safe(res, tmp);\n" " }\n"); }