All MCI functions are now cleanly separated.
[wine/multimedia.git] / programs / winhelp / hlp2sgml.c
blob92dc4d5895da817ee4f52ff5a2fe182154b40c0d
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_image:
261 break;
266 printf(format.tail);
268 return 0;
271 /***********************************************************************
273 * Substitutions for some WINELIB functions
276 static FILE *file = 0;
278 HFILE WINAPI OpenFile( LPCSTR path, OFSTRUCT *ofs, UINT mode )
280 file = *path ? fopen(path, "r") : stdin;
281 return file ? (HFILE)1 : HFILE_ERROR;
284 HFILE WINAPI _lclose( HFILE hFile )
286 fclose(file);
287 return 0;
290 LONG WINAPI _hread( HFILE hFile, LPVOID buffer, LONG count )
292 return fread(buffer, 1, count, file);
295 HANDLE WINAPI GetProcessHeap(void)
297 return 0;
300 void* WINAPI HeapAlloc( HANDLE heap, DWORD flags, DWORD size )
302 assert(flags == 0);
303 return malloc(size);
306 void* WINAPI HeapReAlloc( HANDLE heap, DWORD flags, void* ptr, DWORD size)
308 assert(flags == 0);
309 return realloc(ptr, size);
312 BOOL WINAPI HeapFree( HGLOBAL handle, DWORD flags, void* ptr )
314 free(ptr);
315 return TRUE;
318 char __wine_dbch_winhelp[] = "\003winhelp";
320 static char * const debug_channels[1] =
322 __wine_dbch_winhelp
325 int wine_dbg_log( int cls, const char *channel, const char *func, const char *format, ... )
327 return 1;
330 HBITMAP WINAPI CreateDIBitmap(HDC hdc, CONST BITMAPINFOHEADER* bih, DWORD a, CONST void* ptr, CONST BITMAPINFO* bi, UINT c)
332 return 0;
335 HDC WINAPI GetDC(HWND h)
337 return 0;
340 BOOL WINAPI DeleteObject(HGDIOBJ h)
342 return TRUE;
345 * String functions
347 * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
350 INT WINAPI lstrcmp( LPCSTR str1, LPCSTR str2 )
352 return strcmp( str1, str2 );
355 INT WINAPI lstrcmpi( LPCSTR str1, LPCSTR str2 )
357 INT res;
359 while (*str1)
361 if ((res = toupper(*str1) - toupper(*str2)) != 0) return res;
362 str1++;
363 str2++;
365 return toupper(*str1) - toupper(*str2);
368 INT WINAPI lstrlen( LPCSTR str )
370 return strlen(str);
373 LPSTR WINAPI lstrcpyA( LPSTR dst, LPCSTR src )
375 if (!src || !dst) return NULL;
376 strcpy( dst, src );
377 return dst;