4 Copyright (C) 2006-2009 Jonathan Zarate
14 <% ident(arg, "arg", 'arg'); %>
16 Syntax checking is very relaxed and all arguments are considered a
17 string. Example, the following are the same:
23 int parse_asp(const char *path
)
39 if (!nvram_match("debug_npages", "0")) {
40 if (((a
= strrchr(path
, '.')) != NULL
) && ((n
= a
- path
) > 3) && (strncmp(a
- 2, "-n", 2) != 0)) {
41 memcpy(npath
, path
, n
);
42 memcpy(npath
+ n
, "-n", 2);
43 strcpy(npath
+ n
+ 2, a
);
44 if (f_exists(npath
)) {
51 if (f_read_alloc_string(path
, &buffer
, 128 * 1024) < 0) {
53 if (!header_sent
) send_error(500, NULL
, "Read error");
57 if (!header_sent
) send_header(200, NULL
, mime_html
, 0);
59 // <% id(arg, arg); %>
62 if ((b
= strstr(cp
, "%>")) == NULL
) {
72 while ((c
= strstr(a
, "<%")) != NULL
) {
79 web_write(cp
, b
- cp
);
84 web_write(cp
, (a
- cp
) - 2);
88 while (*a
== ' ') ++a
;
90 while (((*a
>= 'a') && (*a
<= 'z')) || ((*a
>= 'A') && (*a
<= 'Z')) || ((*a
>= '0') && (*a
<= '9')) || (*a
== '_')) {
95 syslog(LOG_WARNING
, "Identifier not found in %s @%u", path
, a
- buffer
);
100 while (*a
== ' ') ++a
;
103 syslog(LOG_WARNING
, "Expecting ( in %s @%u", path
, a
- buffer
);
109 // <% foo(123, "arg"); %>
110 // a -----^ ^--- null
112 // printf("\n[[['%s'\n", ident);
116 while (*a
== ' ') ++a
;
120 while ((*a
== ' ') || (*a
== ';')) ++a
;
123 for (api
= aspapi
; api
->name
; ++api
) {
124 if (strcmp(api
->name
, ident
) == 0) {
125 api
->exec(argc
, argv
);
133 for (z = 0; z < argc; ++z) {
134 printf(" %d '%s'\n", z, argv[z]);
142 syslog(LOG_WARNING
, "Error while parsing arguments in %s @%u", path
, a
- buffer
);
147 if ((*a
== '"') || (*a
== '\'')) {
149 argv
[argc
++] = a
+ 1;
150 while ((*++a
!= x
) && (*a
!= 0)) {
152 if (*++a
== 0) break;
161 while ((*a
!= ',') && (*a
!= ')') && (*a
!= ' ') && (*a
!= 0)) ++a
;
163 while (*a
== ' ') ++a
;
168 if (*a
!= ',') break;
173 if (a
!= NULL
) syslog(LOG_WARNING
, "Error while parsing arguments in %s @%u", path
, a
- buffer
);
176 // printf("argc=%d]]]\n", argc);
184 void wo_asp(char *path
)