Fixed installation rules for Wine-specific IDL files.
[wine/testsucceed.git] / programs / winhelp / hlp2sgml.c
blob2df1ec57e016155057ad8b6a1b503c6796b17bb4
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 <string.h>
21 #include <time.h>
22 #include <ctype.h>
23 #include <fcntl.h>
24 #include <assert.h>
25 #include "windows.h"
26 #include "hlpfile.h"
28 typedef struct
30 const char *header1;
31 const char *header2;
32 const char *section;
33 const char *first_paragraph;
34 const char *newline;
35 const char *next_paragraph;
36 const char *special_char;
37 const char *begin_italic;
38 const char *end_italic;
39 const char *begin_boldface;
40 const char *end_boldface;
41 const char *begin_typewriter;
42 const char *end_typewriter;
43 const char *tail;
44 } FORMAT;
46 typedef struct
48 const char ch;
49 const char *subst;
50 } CHARMAP_ENTRY;
53 FORMAT format =
55 "<!doctype linuxdoc system>\n"
56 "<article>\n"
57 "<title>\n",
59 "\n<author>\n%s\n"
60 "<date>\n%s\n",
62 "\n<sect>\n",
63 "\n<p>\n",
64 "\n<newline>\n",
65 "\n\n",
67 "&%s;",
69 "<em>",
70 "</em>",
71 "<bf>",
72 "</bf>",
73 "<tt>",
74 "</tt>",
76 "\n</article>\n"
79 CHARMAP_ENTRY charmap[] =
80 {{'Æ', "AElig"},
81 {'Á', "Aacute"},
82 {'Â', "Acirc"},
83 {'À', "Agrave"},
84 {'Ã', "Atilde"},
85 {'Ç', "Ccedil"},
86 {'É', "Eacute"},
87 {'È', "Egrave"},
88 {'Ë', "Euml"},
89 {'Í', "Iacute"},
90 {'Î', "Icirc"},
91 {'Ì', "Igrave"},
92 {'Ï', "Iuml"},
93 {'Ñ', "Ntilde"},
94 {'Ó', "Oacute"},
95 {'Ô', "Ocirc"},
96 {'Ò', "Ograve"},
97 {'Ø', "Oslash"},
98 {'Ú', "Uacute"},
99 {'Ù', "Ugrave"},
100 {'Ý', "Yacute"},
101 {'á', "aacute"},
102 {'â', "acirc"},
103 {'æ', "aelig"},
104 {'à', "agrave"},
105 {'å', "aring"},
106 {'ã', "atilde"},
107 {'ç', "ccedil"},
108 {'é', "eacute"},
109 {'ê', "ecirc"},
110 {'è', "egrave"},
111 {'ë', "euml"},
112 {'í', "iacute"},
113 {'î', "icirc"},
114 {'ì', "igrave"},
115 {'ï', "iuml"},
116 {'ñ', "ntilde"},
117 {'ó', "oacute"},
118 {'ÿ', "yuml"},
119 {'ô', "ocirc"},
120 {'ò', "ograve"},
121 {'ø', "oslash"},
122 {'õ', "otilde"},
123 {'ú', "uacute"},
124 {'û', "ucirc"},
125 {'ù', "ugrave"},
126 {'ý', "yacute"},
127 {'<', "lt"},
128 {'&', "amp"},
129 {'"', "dquot"},
130 {'#', "num"},
131 {'%', "percnt"},
132 {'\'', "quot"},
133 #if 0
134 {'(', "lpar"},
135 {')', "rpar"},
136 {'*', "ast"},
137 {'+', "plus"},
138 {',', "comma"},
139 {'-', "hyphen"},
140 {':', "colon"},
141 {';', "semi"},
142 {'=', "equals"},
143 {'@', "commat"},
144 {'[', "lsqb"},
145 {']', "rsqb"},
146 {'^', "circ"},
147 {'_', "lowbar"},
148 {'{', "lcub"},
149 {'|', "verbar"},
150 {'}', "rcub"},
151 {'~', "tilde"},
152 #endif
153 {'\\', "bsol"},
154 {'$', "dollar"},
155 {'Ä', "Auml"},
156 {'ä', "auml"},
157 {'Ö', "Ouml"},
158 {'ö', "ouml"},
159 {'Ü', "Uuml"},
160 {'ü', "uuml"},
161 {'ß', "szlig"},
162 {'>', "gt"},
163 {'§', "sect"},
164 {'¶', "para"},
165 {'©', "copy"},
166 {'¡', "iexcl"},
167 {'¿', "iquest"},
168 {'¢', "cent"},
169 {'£', "pound"},
170 {'×', "times"},
171 {'±', "plusmn"},
172 {'÷', "divide"},
173 {'¬', "not"},
174 {'µ', "mu"},
175 {0,0}};
177 /***********************************************************************
179 * print_text
182 static void print_text(const char *p)
184 int i;
186 for (; *p; p++)
188 for (i = 0; charmap[i].ch; i++)
189 if (*p == charmap[i].ch)
191 printf(format.special_char, charmap[i].subst);
192 break;
194 if (!charmap[i].ch)
195 printf("%c", *p);
199 /***********************************************************************
201 * main
204 int main(int argc, char **argv)
206 HLPFILE *hlpfile;
207 HLPFILE_PAGE *page;
208 HLPFILE_PARAGRAPH *paragraph;
209 time_t t;
210 char date[50];
211 char *filename;
213 hlpfile = HLPFILE_ReadHlpFile(argc > 1 ? argv[1] : "");
215 if (!hlpfile) return 2;
217 time(&t);
218 strftime(date, sizeof(date), "%x", localtime(&t));
219 filename = strrchr(hlpfile->lpszPath, '/');
220 if (filename) filename++;
221 else filename = hlpfile->lpszPath;
223 /* Header */
224 printf(format.header1);
225 print_text(hlpfile->lpszTitle);
226 printf(format.header2, filename, date);
228 for (page = hlpfile->first_page; page; page = page->next)
230 paragraph = page->first_paragraph;
231 if (!paragraph) continue;
233 /* Section */
234 printf(format.section);
235 for (; paragraph && !paragraph->u.text.wVSpace; paragraph = paragraph->next)
236 print_text(paragraph->u.text.lpszText);
237 printf(format.first_paragraph);
239 for (; paragraph; paragraph = paragraph->next)
241 switch (paragraph->cookie)
243 case para_normal_text:
244 case para_debug_text:
245 /* New line; new paragraph */
246 if (paragraph->u.text.wVSpace == 1)
247 printf(format.newline);
248 else if (paragraph->u.text.wVSpace > 1)
249 printf(format.next_paragraph);
251 if (paragraph->u.text.wFont)
252 printf(format.begin_boldface);
254 print_text(paragraph->u.text.lpszText);
256 if (paragraph->u.text.wFont)
257 printf(format.end_boldface);
258 break;
259 case para_bitmap:
260 case para_metafile:
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, SIZE_T size )
302 assert(flags == 0);
303 return malloc(size);
306 void* WINAPI HeapReAlloc( HANDLE heap, DWORD flags, void* ptr, SIZE_T 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 int wine_dbg_log( int cls, const char *channel, const char *func, const char *format, ... )
322 return 1;
325 const char *wine_dbgstr_a( const char *s )
327 return NULL;
330 HBITMAP WINAPI CreateDIBitmap(HDC hdc, CONST BITMAPINFOHEADER* bih, DWORD a, CONST void* ptr, CONST BITMAPINFO* bi, UINT c)
332 return 0;
335 HMETAFILE WINAPI SetMetaFileBitsEx(UINT cbBuffer, CONST BYTE *lpbBuffer)
337 return 0;
340 BOOL WINAPI DeleteMetaFile(HMETAFILE h)
342 return 0;
345 HDC WINAPI GetDC(HWND h)
347 return 0;
350 int WINAPI ReleaseDC(HWND h, HDC hdc)
352 return 0;
355 BOOL WINAPI DeleteObject(HGDIOBJ h)
357 return TRUE;
360 * String functions
362 * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
365 INT WINAPI lstrcmp( LPCSTR str1, LPCSTR str2 )
367 return strcmp( str1, str2 );
370 INT WINAPI lstrcmpi( LPCSTR str1, LPCSTR str2 )
372 INT res;
374 while (*str1)
376 if ((res = toupper(*str1) - toupper(*str2)) != 0) return res;
377 str1++;
378 str2++;
380 return toupper(*str1) - toupper(*str2);
383 INT WINAPI lstrlen( LPCSTR str )
385 return strlen(str);
388 LPSTR WINAPI lstrcpyA( LPSTR dst, LPCSTR src )
390 if (!src || !dst) return NULL;
391 strcpy( dst, src );
392 return dst;
395 LPSTR WINAPI lstrcpynA( LPSTR dst, LPCSTR src, INT n )
397 LPSTR d = dst;
398 LPCSTR s = src;
399 UINT count = n;
401 while ((count > 1) && *s)
403 count--;
404 *d++ = *s++;
406 if (count) *d = 0;
407 return dst;