source: rtems/cpukit/httpd/webcomp.c @ f26145b

4.104.114.84.95
Last change on this file since f26145b was ee3afa2, checked in by Joel Sherrill <joel.sherrill@…>, on 04/11/03 at 14:46:55

2002-04-10 Mike Siers <mikes@…>

  • rtems_webserver/NOTES, rtems_webserver/asp.c, rtems_webserver/balloc.c, rtems_webserver/default.c, rtems_webserver/ej.h, rtems_webserver/ejIntrn.h, rtems_webserver/ejlex.c, rtems_webserver/ejparse.c, rtems_webserver/emfdb.c, rtems_webserver/emfdb.h, rtems_webserver/form.c, rtems_webserver/h.c, rtems_webserver/handler.c, rtems_webserver/license.txt, rtems_webserver/md5.h, rtems_webserver/md5c.c, rtems_webserver/mime.c, rtems_webserver/misc.c, rtems_webserver/ringq.c, rtems_webserver/rom.c, rtems_webserver/security.c, rtems_webserver/sock.c, rtems_webserver/sym.c, rtems_webserver/uemf.c, rtems_webserver/uemf.h, rtems_webserver/um.c, rtems_webserver/um.h, rtems_webserver/url.c, rtems_webserver/value.c, rtems_webserver/wbase64.c, rtems_webserver/webcomp.c, rtems_webserver/webpage.c, rtems_webserver/webrom.c, rtems_webserver/webs.c, rtems_webserver/webs.h, rtems_webserver/websuemf.c, rtems_webserver/wsIntrn.h: Update to GoAhead? Webserver 2.1.4. The following URL is the release notes from GoAhead?.

http://data.goahead.com/Software/Webserver/2.1.4/release.htm

I have only done a minimal amount of testing (i.e. the network
demo program works fine). Please try this out and let me know
if it works. The patch needs to be applied on the
c/src/libnetworking/rtems_webserver directory.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/*
2 * webcomp -- Compile web pages into C source
3 *
4 * Copyright (c) GoAhead Software Inc., 1995-2000. All Rights Reserved.
5 *
6 * See the file "license.txt" for usage and redistribution license requirements
7 *
8 * $Id$
9 */
10
11/******************************** Description *********************************/
12
13/*
14 *      Usage: webcomp prefix filelist >webrom.c
15 *
16 *      filelist is a file containing the pathnames of all web pages
17 *      prefix is a path prefix to remove from all the web page pathnames
18 *      webrom.c is the resulting C source file to compile and link.
19 */
20
21/********************************* Includes ***********************************/
22
23#include        "wsIntrn.h"
24
25/**************************** Forward Declarations ****************************/
26
27static int      compile(char_t *fileList, char_t *prefix);
28static void usage();
29
30/*********************************** Code *************************************/
31/*
32 *      Main program for webpack test harness
33 */
34
35int gmain(int argc, char_t* argv[])
36{
37        char_t          *fileList, *prefix;
38
39        fileList = NULL;
40
41        if (argc != 3) {
42                usage();
43        }
44
45        prefix = argv[1];
46        fileList = argv[2];
47
48        if (compile(fileList, prefix) < 0) {
49                return -1;
50        }
51        return 0;
52}
53
54/******************************************************************************/
55/*
56 *      Output usage message
57 */
58
59static void usage()
60{
61        fprintf(stderr, "usage: webcomp prefix filelist >output.c\n");
62        exit(2);
63}
64
65/******************************************************************************/
66/*
67 *      Compile the web pages
68 */
69
70static int compile(char_t *fileList, char_t *prefix)
71{
72        gstat_t                 sbuf;
73        FILE                    *lp;
74        time_t                  now;
75        char_t                  file[FNAMESIZE];
76        char_t                  *cp, *sl;
77        char                    buf[512];
78        unsigned char   *p;
79        int                             j, i, len, fd, nFile;
80
81/*
82 *      Open list of files
83 */
84        if ((lp = fopen(fileList, "r")) == NULL) {
85                fprintf(stderr, "Can't open file list %s\n", fileList);
86                return -1;
87        }
88
89        time(&now);
90        fprintf(stdout, "/*\n * webrom.c -- Compiled Web Pages\n *\n");
91        fprintf(stdout, " * Compiled by GoAhead WebCompile: %s */\n\n",
92                gctime(&now));
93        fprintf(stdout, "#include \"wsIntrn.h\"\n\n");
94        fprintf(stdout, "#ifndef WEBS_PAGE_ROM\n");
95        fprintf(stdout, "websRomPageIndexType websRomPageIndex[] = {\n");
96        fprintf(stdout, "    { 0, 0, 0 },\n};\n");
97        fprintf(stdout, "#else\n");
98
99/*
100 *      Open each input file and compile each web page
101 */
102        nFile = 0;
103        while (fgets(file, sizeof(file), lp) != NULL) {
104                if ((p = strchr(file, '\n')) || (p = strchr(file, '\r'))) {
105                        *p = '\0';
106                }
107                if (*file == '\0') {
108                        continue;
109                }
110                if (gstat(file, &sbuf) == 0 && sbuf.st_mode & S_IFDIR) {
111                        continue;
112                }
113                if ((fd = gopen(file, O_RDONLY | O_BINARY)) < 0) {
114                        fprintf(stderr, "Can't open file %s\n", file);
115                        return -1;
116                }
117                fprintf(stdout, "static unsigned char page_%d[] = {\n", nFile);
118
119                while ((len = read(fd, buf, sizeof(buf))) > 0) {
120                        p = buf;
121                        for (i = 0; i < len; ) {
122                                fprintf(stdout, "    ");
123                                for (j = 0; p < &buf[len] && j < 16; j++, p++) {
124                                        fprintf(stdout, "%3d,", *p);
125                                }
126                                i += j;
127                                fprintf(stdout, "\n");
128                        }
129                }
130                fprintf(stdout, "    0 };\n\n");
131
132                close(fd);
133                nFile++;
134        }
135        fclose(lp);
136
137/*
138 *      Now output the page index
139 */
140        fprintf(stdout, "websRomPageIndexType websRomPageIndex[] = {\n");
141
142        if ((lp = fopen(fileList, "r")) == NULL) {
143                fprintf(stderr, "Can't open file list %s\n", fileList);
144                return -1;
145        }
146        nFile = 0;
147        while (fgets(file, sizeof(file), lp) != NULL) {
148                if ((p = strchr(file, '\n')) || (p = strchr(file, '\r'))) {
149                        *p = '\0';
150                }
151                if (*file == '\0') {
152                        continue;
153                }
154/*
155 *              Remove the prefix and add a leading "/" when we print the path
156 */
157                if (strncmp(file, prefix, gstrlen(prefix)) == 0) {
158                        cp = &file[gstrlen(prefix)];
159                } else {
160                        cp = file;
161                }
162                while((sl = strchr(file, '\\')) != NULL) {
163                        *sl = '/';
164                }
165                if (*cp == '/') {
166                        cp++;
167                }
168
169                if (gstat(file, &sbuf) == 0 && sbuf.st_mode & S_IFDIR) {
170                        fprintf(stdout, "    { T(\"/%s\"), 0, 0 },\n", cp);
171                        continue;
172                }
173                fprintf(stdout, "    { T(\"/%s\"), page_%d, %d },\n", cp, nFile,
174                        sbuf.st_size);
175                nFile++;
176        }
177        fclose(lp);
178       
179        fprintf(stdout, "    { 0, 0, 0 },\n");
180        fprintf(stdout, "};\n");
181        fprintf(stdout, "#endif /* WEBS_PAGE_ROM */\n");
182
183        fclose(lp);
184        fflush(stdout);
185        return 0;
186}
187
188/******************************************************************************/
Note: See TracBrowser for help on using the repository browser.