1 /* notes-to-html.c - written by Alexis Wilke for Made to Order Software Corp. (c) 2002-2009 */
2
3 /*
4
5 Copyright (c) 2002-2009 Made to Order Software Corp.
6
7 Permission is hereby granted, free of charge, to any
8 person obtaining a copy of this software and
9 associated documentation files (the "Software"), to
10 deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify,
12 merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom
14 the Software is furnished to do so, subject to the
15 following conditions:
16
17 The above copyright notice and this permission notice
18 shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
22 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
23 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31
32 */
33
34
35
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <ctype.h>
39 #include <string.h>
40
main(int argc,char * argv[])41 int main(int argc, char *argv[])
42 {
43 char buf[256], *start, *s, *end;
44 int empty, indent;
45 FILE *f;
46
47 if(argc <= 1) {
48 fprintf(stderr, "Notes to HTML -- Copyright Made to Order Software Corp. (c) 2002-2009\n");
49 fprintf(stderr, "Written by Alexis Wilke\n\n");
50 fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
51 exit(1);
52 }
53
54 empty = 1;
55 indent = 0;
56 f = fopen(argv[1], "rb");
57 while(fgets(buf, sizeof(buf), f) != NULL) {
58 s = buf;
59 while(isspace(*s) && *s != '\n' && *s != '\r' && *s != '\0') {
60 /* keep this space in the output */
61 printf("%c", *s);
62 s++;
63 }
64 if(*s == '\n' || *s == '\r' || *s == '\0') {
65 empty = 1;
66 if(indent != 0) {
67 indent = 0;
68 printf("</ul></ul>");
69 }
70 printf("\n");
71 continue;
72 }
73 start = s;
74 if(*start == '*' || (start[0] == 'o' && isspace(start[1]))) {
75 start = "<br/><br/><center><hr noshade size=\"2\" width=\"80%\"/></center><br/><font color=\"#ff000\" style=\"font-size: 20px\">";
76 end = "</font>";
77
78 if(indent != 0) {
79 indent = 0;
80 printf("</ul></ul>");
81 }
82 }
83 else if(*start == '.') {
84 start = "<ul><b>";
85 end = "</b></ul>";
86
87 if(indent != 0) {
88 indent = 0;
89 printf("</ul></ul>");
90 }
91 }
92 else {
93 if(isspace(buf[0]) && indent == 0) {
94 indent = 1;
95 printf("<ul><ul>");
96 }
97 if(empty) {
98 empty = 0;
99 start = "<p>";
100 end = "";
101 }
102 else {
103 start = "";
104 end = "";
105 }
106 }
107
108 printf("%s", start);
109
110 while(*s != '\0') {
111 if(strncasecmp(s, "ft2sswf", 7) == 0) {
112 printf("<i>ft2sswf</i>");
113 s += 7;
114 }
115 else if(strncasecmp(s, "sswf", 4) == 0) {
116 printf("<i>sswf</i>");
117 s += 4;
118 }
119 else if(strncasecmp(s, "swf_dump", 8) == 0) {
120 printf("<i>swf_dump</i>");
121 s += 8;
122 }
123 else {
124 switch(*s) {
125 case '<':
126 printf("<");
127 break;
128
129 case '>':
130 printf(">");
131 break;
132
133 case '&':
134 printf("&");
135 break;
136
137 case '"':
138 printf(""");
139 break;
140
141 case '\r':
142 case '\n':
143 *s-- = '\0';
144 break;
145
146 default:
147 printf("%c", *s);
148 break;
149
150 }
151 s++;
152 }
153 }
154
155 printf("%s\n", end);
156 }
157 fclose(f);
158
159 return 0;
160 }
161
162