Convert the wininet HTTP functions to Unicode.
[wine.git] / programs / winhelp / hlp2sgml.c
blob3d0ed4bf51599ef0ca7b03e363dacb1ae1c6e714
1 /*
2 * Copyright 1996 Ulrich Schmid
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <time.h>
23 #include <ctype.h>
24 #include <fcntl.h>
25 #include <assert.h>
26 #include "windows.h"
27 #include "hlpfile.h"
29 typedef struct
31 const char *header1;
32 const char *header2;
33 const char *section;
34 const char *first_paragraph;
35 const char *newline;
36 const char *next_paragraph;
37 const char *special_char;
38 const char *begin_italic;
39 const char *end_italic;
40 const char *begin_boldface;
41 const char *end_boldface;
42 const char *begin_typewriter;
43 const char *end_typewriter;
44 const char *tail;
45 } FORMAT;
47 typedef struct
49 const char ch;
50 const char *subst;
51 } CHARMAP_ENTRY;
54 FORMAT format =
56 "<!doctype linuxdoc system>\n"
57 "<article>\n"
58 "<title>\n",
60 "\n<author>\n%s\n"
61 "<date>\n%s\n",
63 "\n<sect>\n",
64 "\n<p>\n",
65 "\n<newline>\n",
66 "\n\n",
68 "&%s;",
70 "<em>",
71 "</em>",
72 "<bf>",
73 "</bf>",
74 "<tt>",
75 "</tt>",
77 "\n</article>\n"
80 CHARMAP_ENTRY charmap[] =
81 {{'Æ', "AElig"},
82 {'Á', "Aacute"},
83 {'Â', "Acirc"},
84 {'À', "Agrave"},
85 {'Ã', "Atilde"},
86 {'Ç', "Ccedil"},
87 {'É', "Eacute"},
88 {'È', "Egrave"},
89 {'Ë', "Euml"},
90 {'Í', "Iacute"},
91 {'Î', "Icirc"},
92 {'Ì', "Igrave"},
93 {'Ï', "Iuml"},
94 {'Ñ', "Ntilde"},
95 {'Ó', "Oacute"},
96 {'Ô', "Ocirc"},
97 {'Ò', "Ograve"},
98 {'Ø', "Oslash"},
99 {'Ú', "Uacute"},
100 {'Ù', "Ugrave"},
101 {'Ý', "Yacute"},
102 {'á', "aacute"},
103 {'â', "acirc"},
104 {'æ', "aelig"},
105 {'à', "agrave"},
106 {'å', "aring"},
107 {'ã', "atilde"},
108 {'ç', "ccedil"},
109 {'é', "eacute"},
110 {'ê', "ecirc"},
111 {'è', "egrave"},
112 {'ë', "euml"},
113 {'í', "iacute"},
114 {'î', "icirc"},
115 {'ì', "igrave"},
116 {'ï', "iuml"},
117 {'ñ', "ntilde"},
118 {'ó', "oacute"},
119 {'ÿ', "yuml"},
120 {'ô', "ocirc"},
121 {'ò', "ograve"},
122 {'ø', "oslash"},
123 {'õ', "otilde"},
124 {'ú', "uacute"},
125 {'û', "ucirc"},
126 {'ù', "ugrave"},
127 {'ý', "yacute"},
128 {'<', "lt"},
129 {'&', "amp"},
130 {'"', "dquot"},
131 {'#', "num"},
132 {'%', "percnt"},
133 {'\'', "quot"},
134 #if 0
135 {'(', "lpar"},
136 {')', "rpar"},
137 {'*', "ast"},
138 {'+', "plus"},
139 {',', "comma"},
140 {'-', "hyphen"},
141 {':', "colon"},
142 {';', "semi"},
143 {'=', "equals"},
144 {'@', "commat"},
145 {'[', "lsqb"},
146 {']', "rsqb"},
147 {'^', "circ"},
148 {'_', "lowbar"},
149 {'{', "lcub"},
150 {'|', "verbar"},
151 {'}', "rcub"},
152 {'~', "tilde"},
153 #endif
154 {'\\', "bsol"},
155 {'$', "dollar"},
156 {'Ä', "Auml"},
157 {'ä', "auml"},
158 {'Ö', "Ouml"},
159 {'ö', "ouml"},
160 {'Ü', "Uuml"},
161 {'ü', "uuml"},
162 {'ß', "szlig"},
163 {'>', "gt"},
164 {'§', "sect"},
165 {'¶', "para"},
166 {'©', "copy"},
167 {'¡', "iexcl"},
168 {'¿', "iquest"},
169 {'¢', "cent"},
170 {'£', "pound"},
171 {'×', "times"},
172 {'±', "plusmn"},
173 {'÷', "divide"},
174 {'¬', "not"},
175 {'µ', "mu"},
176 {0,0}};
178 /***********************************************************************
180 * print_text
183 static void print_text(const char *p)
185 int i;
187 for (; *p; p++)
189 for (i = 0; charmap[i].ch; i++)
190 if (*p == charmap[i].ch)
192 printf(format.special_char, charmap[i].subst);
193 break;
195 if (!charmap[i].ch)
196 printf("%c", *p);
200 /***********************************************************************
202 * main
205 int main(int argc, char **argv)
207 HLPFILE *hlpfile;
208 HLPFILE_PAGE *page;
209 HLPFILE_PARAGRAPH *paragraph;
210 time_t t;
211 char date[50];
212 char *filename;
214 hlpfile = HLPFILE_ReadHlpFile(argc > 1 ? argv[1] : "");
216 if (!hlpfile) return 2;
218 time(&t);
219 strftime(date, sizeof(date), "%x", localtime(&t));
220 filename = strrchr(hlpfile->lpszPath, '/');
221 if (filename) filename++;
222 else filename = hlpfile->lpszPath;
224 /* Header */
225 printf(format.header1);
226 print_text(hlpfile->lpszTitle);
227 printf(format.header2, filename, date);
229 for (page = hlpfile->first_page; page; page = page->next)
231 paragraph = page->first_paragraph;
232 if (!paragraph) continue;
234 /* Section */
235 printf(format.section);
236 for (; paragraph && !paragraph->u.text.wVSpace; paragraph = paragraph->next)
237 print_text(paragraph->u.text.lpszText);
238 printf(format.first_paragraph);
240 for (; paragraph; paragraph = paragraph->next)
242 switch (paragraph->cookie)
244 case para_normal_text:
245 case para_debug_text:
246 /* New line; new paragraph */
247 if (paragraph->u.text.wVSpace == 1)
248 printf(format.newline);
249 else if (paragraph->u.text.wVSpace > 1)
250 printf(format.next_paragraph);
252 if (paragraph->u.text.wFont)
253 printf(format.begin_boldface);
255 print_text(paragraph->u.text.lpszText);
257 if (paragraph->u.text.wFont)
258 printf(format.end_boldface);
259 break;
260 case para_bitmap:
261 case para_metafile:
262 break;
267 printf(format.tail);
269 return 0;
272 /***********************************************************************
274 * Substitutions for some WINELIB functions
277 static FILE *file = 0;
279 HFILE WINAPI OpenFile( LPCSTR path, OFSTRUCT *ofs, UINT mode )
281 file = *path ? fopen(path, "r") : stdin;
282 return file ? (HFILE)1 : HFILE_ERROR;
285 HFILE WINAPI _lclose( HFILE hFile )
287 fclose(file);
288 return 0;
291 LONG WINAPI _hread( HFILE hFile, LPVOID buffer, LONG count )
293 return fread(buffer, 1, count, file);
296 HANDLE WINAPI GetProcessHeap(void)
298 return 0;
301 void* WINAPI HeapAlloc( HANDLE heap, DWORD flags, DWORD size )
303 assert(flags == 0);
304 return malloc(size);
307 void* WINAPI HeapReAlloc( HANDLE heap, DWORD flags, void* ptr, DWORD size)
309 assert(flags == 0);
310 return realloc(ptr, size);
313 BOOL WINAPI HeapFree( HGLOBAL handle, DWORD flags, void* ptr )
315 free(ptr);
316 return TRUE;
319 char __wine_dbch_winhelp[] = "\003winhelp";
321 int wine_dbg_log( int cls, const char *channel, const char *func, const char *format, ... )
323 return 1;
326 HBITMAP WINAPI CreateDIBitmap(HDC hdc, CONST BITMAPINFOHEADER* bih, DWORD a, CONST void* ptr, CONST BITMAPINFO* bi, UINT c)
328 return 0;
331 HMETAFILE WINAPI SetMetaFileBitsEx(UINT cbBuffer, CONST BYTE *lpbBuffer)
333 return 0;
336 BOOL WINAPI DeleteMetaFile(HMETAFILE h)
338 return 0;
341 HDC WINAPI GetDC(HWND h)
343 return 0;
346 int WINAPI ReleaseDC(HWND h, HDC hdc)
348 return 0;
351 BOOL WINAPI DeleteObject(HGDIOBJ h)
353 return TRUE;
356 * String functions
358 * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
361 INT WINAPI lstrcmp( LPCSTR str1, LPCSTR str2 )
363 return strcmp( str1, str2 );
366 INT WINAPI lstrcmpi( LPCSTR str1, LPCSTR str2 )
368 INT res;
370 while (*str1)
372 if ((res = toupper(*str1) - toupper(*str2)) != 0) return res;
373 str1++;
374 str2++;
376 return toupper(*str1) - toupper(*str2);
379 INT WINAPI lstrlen( LPCSTR str )
381 return strlen(str);
384 LPSTR WINAPI lstrcpyA( LPSTR dst, LPCSTR src )
386 if (!src || !dst) return NULL;
387 strcpy( dst, src );
388 return dst;