1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/************************************************************************
** VODALUTIL.C -- Utility procedures for the DAL interface worker
** procedures.
**
** M. Fitzpatrick, NOAO, July 2007
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include "VOClient.h"
#include "voAppsP.h"
extern int format, iportal;
extern int html_border, html_color, html_header;
void vot_initKML (FILE *fd, svcParams *pars);
void vot_printHTMLRow (FILE *fd, char *line, int isHdr, int rownum);
void vot_closeKML (FILE *fd);
/************************************************************************
** INITHTML -- Initialize the KML output file header.
*/
void
vot_initHTML (FILE *fd, svcParams *pars)
{
if (!fd)
return;
if (html_header)
fprintf (fd, "<html>\n<body>\n");
fprintf (fd, "<table border=\"%d\">\n",
(html_border ? 5 : 0));
}
/************************************************************************
** PRINTHTMLROW -- Write a row in an HTML table.
** file.
*/
void
vot_printHTMLRow (FILE *fd, char *line, int isHdr, int rownum)
{
char *ip, *hp, *sp, *dp, *vp, *tab, *col, delim, val[SZ_LINE];
if (!fd || !line)
return;
for (dp=line; *dp && *dp != '\n'; dp++) /* get the data line */
;
dp++;
hp = line; /* get the header line */
sp = (isHdr ? hp : dp);
tab = (isHdr ? "th" : "td");
if (isHdr)
col = "eec";
else if (html_color)
col = ((rownum % 2) == 0) ? "ccc" : "eee";
else
col = "fff";
delim = ((format == F_CSV) ? ',' :
((format == F_TSV) ? '\t' :
((format == F_ASCII) ? ' ' : ',')));
fprintf (fd, "<tr>");
for (ip=sp; *ip; ) {
bzero (val, SZ_LINE);
for (vp=val; *ip && *ip != '\n' && *ip != delim; ) {
if (*ip == '>') {
strcpy (vp, ">");
vp += 4, ip++;
} else if (*ip == '<') {
strcpy (vp, "<");
vp += 4, ip++;
} else {
*vp++ = *ip++;
}
}
if (strncmp (val, "http://", 7) == 0) {
if (iportal && strstr (val, ".fits") == (char *) NULL) {
fprintf (fd, "<%s style=\"background:#%s\">", tab, col);
fprintf (fd, "<a href=\"javascript:render('%s');\">%s</a></%s>",
val, val, tab);
} else if (!iportal) {
fprintf (fd,
"<%s style=\"background:#%s\"><a href='%s'>%s</a></%s>",
tab, col, val, val, tab);
} else {
fprintf (fd, "<%s style=\"background:#%s\">%s</%s>",
tab, col, val, tab);
}
} else
fprintf (fd, "<%s style=\"background:#%s\">%s</%s>",
tab, col, val, tab);
if (*ip)
ip++;
else
break;
}
fprintf (fd, "</tr>\n");
}
/************************************************************************
** CLOSEHTML -- Close the HTML output file.
*/
void
vot_closeHTML (FILE *fd)
{
if (!fd)
return;
fprintf (fd, "</table>\n");
if (html_header)
fprintf (fd, "</body>\n</html>\n");
fclose (fd);
}
|