Intial commit
[profile/ivi/w3m.git] / parsetag.c
1 /* $Id: parsetag.c,v 1.4 2001/11/20 17:49:23 ukai Exp $ */
2 #include "myctype.h"
3 #include "indep.h"
4 #include "Str.h"
5 #include "parsetag.h"
6
7 char *
8 tag_get_value(struct parsed_tagarg *t, char *arg)
9 {
10     for (; t; t = t->next) {
11         if (!strcasecmp(t->arg, arg))
12             return t->value;
13     }
14     return NULL;
15 }
16
17 int
18 tag_exists(struct parsed_tagarg *t, char *arg)
19 {
20     for (; t; t = t->next) {
21         if (!strcasecmp(t->arg, arg))
22             return 1;
23     }
24     return 0;
25 }
26
27 struct parsed_tagarg *
28 cgistr2tagarg(char *cgistr)
29 {
30     Str tag;
31     Str value;
32     struct parsed_tagarg *t0, *t;
33
34     t = t0 = NULL;
35     do {
36         t = New(struct parsed_tagarg);
37         t->next = t0;
38         t0 = t;
39         tag = Strnew();
40         while (*cgistr && *cgistr != '=' && *cgistr != '&')
41             Strcat_char(tag, *cgistr++);
42         t->arg = Str_form_unquote(tag)->ptr;
43         t->value = NULL;
44         if (*cgistr == '\0')
45             return t;
46         else if (*cgistr == '=') {
47             cgistr++;
48             value = Strnew();
49             while (*cgistr && *cgistr != '&')
50                 Strcat_char(value, *cgistr++);
51             t->value = Str_form_unquote(value)->ptr;
52         }
53         else if (*cgistr == '&')
54             cgistr++;
55     } while (*cgistr);
56     return t;
57 }