1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 2010-2011 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Eclipse Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.eclipse.org/org/documents/epl-v10.html *
11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <glenn.s.fowler@gmail.com> *
18 * *
19 ***********************************************************************/
20 #pragma prototyped
21 /*
22 * dss html type library
23 *
24 * Glenn Fowler
25 * AT&T Research
26 */
27
28 #include <dsslib.h>
29
30 static int
html_ref_F(Cx_t * cx,Cxvariable_t * var,Cxoperand_t * ret,Cxoperand_t * arg,int n,void * data,Cxdisc_t * disc)31 html_ref_F(Cx_t* cx, Cxvariable_t* var, Cxoperand_t* ret, Cxoperand_t* arg, int n, void* data, Cxdisc_t* disc)
32 {
33 register char* s;
34 register char* t;
35 register char* v;
36 register int i;
37 register int c;
38 register int k;
39 register int q;
40 char* b;
41
42 if (!(t = vmnewof(cx->em, 0, char, arg->value.string.size, 1)))
43 {
44 if (disc->errorf)
45 (*disc->errorf)(NiL, disc, ERROR_SYSTEM|2, "out of space");
46 return -1;
47 }
48 b = t;
49 i = 0;
50 k = 0;
51 q = 0;
52 v = 0;
53 s = arg->value.string.data;
54 while (c = *s++)
55 {
56 if (!i)
57 {
58 if (c == '<')
59 i = 1;
60 }
61 else if (c == '"')
62 {
63 if (!(q = !q))
64 k = 0;
65 else if (k && t > b)
66 *t++ = ' ';
67 }
68 else if (!q)
69 {
70 if (c == '>')
71 i = 0;
72 else if (isspace(c))
73 v = 0;
74 else if (c == '=')
75 {
76 if (v)
77 {
78 n = s - v - 1;
79 if (n == 4 && !strncasecmp(v, "href", 4) || n == 3 && !strncasecmp(v, "src", 3))
80 k = 1;
81 }
82 }
83 else if (!v)
84 v = s - 1;
85 }
86 else if (k)
87 *t++ = c;
88 }
89 if (t > b)
90 {
91 *t = 0;
92 ret->value.string.size = t - b;
93 ret->value.string.data = b;
94 }
95 else
96 ret->value = arg->value;
97 return 0;
98 }
99
100 static Cxvariable_t dss_functions[] =
101 {
102 CXF("html::ref", "string", html_ref_F, "string",
103 "Return a space separated list of referenced resources from the HTML tags in the string argument.")
104 0
105 };
106
107 Dsslib_t dss_lib_html =
108 {
109 "html",
110 "html function support"
111 "[-?\n@(#)$Id: dss html function library (AT&T Research) 2010-04-22 $\n]"
112 USAGE_LICENSE,
113 CXH,
114 0,
115 0,
116 0,
117 0,
118 0,
119 0,
120 0,
121 0,
122 0,
123 &dss_functions[0]
124 };
125