OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libnetworking/] [rtems_webserver/] [webcomp.c] - Blame information for rev 507

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.