Check for WS_DISABLED parent in WindowFromPoint for un-managed windows.
[wine.git] / programs / winhelp / hlp2sgml.c
blob3bc3ab967fd1affa3839dfbb6abef55e82e9c91c
1 /*
2 * Copyright 1996 Ulrich Schmid
3 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <time.h>
9 #include <ctype.h>
10 #include <fcntl.h>
11 #include "windows.h"
12 #include "hlpfile.h"
14 typedef struct
16 const char *header1;
17 const char *header2;
18 const char *section;
19 const char *first_paragraph;
20 const char *newline;
21 const char *next_paragraph;
22 const char *special_char;
23 const char *begin_italic;
24 const char *end_italic;
25 const char *begin_boldface;
26 const char *end_boldface;
27 const char *begin_typewriter;
28 const char *end_typewriter;
29 const char *tail;
30 } FORMAT;
32 typedef struct
34 const char ch;
35 const char *subst;
36 } CHARMAP[];
39 FORMAT format =
41 "<!doctype linuxdoc system>\n"
42 "<article>\n"
43 "<title>\n",
45 "\n<author>\n%s\n"
46 "<date>\n%s\n",
48 "\n<sect>\n",
49 "\n<p>\n",
50 "\n<newline>\n",
51 "\n\n",
53 "&%s;",
55 "<em>",
56 "</em>",
57 "<bf>",
58 "</bf>",
59 "<tt>",
60 "</tt>",
62 "\n</article>\n"
65 CHARMAP charmap =
66 {{'Æ', "AElig"},
67 {'Á', "Aacute"},
68 {'Â', "Acirc"},
69 {'À', "Agrave"},
70 {'Ã', "Atilde"},
71 {'Ç', "Ccedil"},
72 {'É', "Eacute"},
73 {'È', "Egrave"},
74 {'Ë', "Euml"},
75 {'Í', "Iacute"},
76 {'Î', "Icirc"},
77 {'Ì', "Igrave"},
78 {'Ï', "Iuml"},
79 {'Ñ', "Ntilde"},
80 {'Ó', "Oacute"},
81 {'Ô', "Ocirc"},
82 {'Ò', "Ograve"},
83 {'Ø', "Oslash"},
84 {'Ú', "Uacute"},
85 {'Ù', "Ugrave"},
86 {'Ý', "Yacute"},
87 {'á', "aacute"},
88 {'â', "acirc"},
89 {'æ', "aelig"},
90 {'à', "agrave"},
91 {'å', "aring"},
92 {'ã', "atilde"},
93 {'ç', "ccedil"},
94 {'é', "eacute"},
95 {'ê', "ecirc"},
96 {'è', "egrave"},
97 {'ë', "euml"},
98 {'í', "iacute"},
99 {'î', "icirc"},
100 {'ì', "igrave"},
101 {'ï', "iuml"},
102 {'ñ', "ntilde"},
103 {'ó', "oacute"},
104 {'ÿ', "yuml"},
105 {'ô', "ocirc"},
106 {'ò', "ograve"},
107 {'ø', "oslash"},
108 {'õ', "otilde"},
109 {'ú', "uacute"},
110 {'û', "ucirc"},
111 {'ù', "ugrave"},
112 {'ý', "yacute"},
113 {'<', "lt"},
114 {'&', "amp"},
115 {'"', "dquot"},
116 {'#', "num"},
117 {'%', "percnt"},
118 {'\'', "quot"},
119 #if 0
120 {'(', "lpar"},
121 {')', "rpar"},
122 {'*', "ast"},
123 {'+', "plus"},
124 {',', "comma"},
125 {'-', "hyphen"},
126 {':', "colon"},
127 {';', "semi"},
128 {'=', "equals"},
129 {'@', "commat"},
130 {'[', "lsqb"},
131 {']', "rsqb"},
132 {'^', "circ"},
133 {'_', "lowbar"},
134 {'{', "lcub"},
135 {'|', "verbar"},
136 {'}', "rcub"},
137 {'~', "tilde"},
138 #endif
139 {'\\', "bsol"},
140 {'$', "dollar"},
141 {'Ä', "Auml"},
142 {'ä', "auml"},
143 {'Ö', "Ouml"},
144 {'ö', "ouml"},
145 {'Ü', "Uuml"},
146 {'ü', "uuml"},
147 {'ß', "szlig"},
148 {'>', "gt"},
149 {'§', "sect"},
150 {'¶', "para"},
151 {'©', "copy"},
152 {'¡', "iexcl"},
153 {'¿', "iquest"},
154 {'¢', "cent"},
155 {'£', "pound"},
156 {'×', "times"},
157 {'±', "plusmn"},
158 {'÷', "divide"},
159 {'¬', "not"},
160 {'µ', "mu"},
161 {0,0}};
163 /***********************************************************************
165 * print_text
168 static void print_text(const char *p)
170 int i;
172 for (; *p; p++)
174 for (i = 0; charmap[i].ch; i++)
175 if (*p == charmap[i].ch)
177 printf(format.special_char, charmap[i].subst);
178 break;
180 if (!charmap[i].ch)
181 printf("%c", *p);
185 /***********************************************************************
187 * main
190 int main(int argc, char **argv)
192 HLPFILE *hlpfile;
193 HLPFILE_PAGE *page;
194 HLPFILE_PARAGRAPH *paragraph;
195 time_t t;
196 char date[50];
197 char *filename;
199 hlpfile = HLPFILE_ReadHlpFile(argc > 1 ? argv[1] : "");
201 if (!hlpfile) return(2);
203 time(&t);
204 strftime(date, sizeof(date), "%x", localtime(&t));
205 filename = strrchr(hlpfile->lpszPath, '/');
206 if (filename) filename++;
207 else filename = hlpfile->lpszPath;
209 /* Header */
210 printf(format.header1);
211 print_text(hlpfile->lpszTitle);
212 printf(format.header2, filename, date);
214 for (page = hlpfile->first_page; page; page = page->next)
216 paragraph = page->first_paragraph;
217 if (!paragraph) continue;
219 /* Section */
220 printf(format.section);
221 for (; paragraph && !paragraph->wVSpace; paragraph = paragraph->next)
222 print_text(paragraph->lpszText);
223 printf(format.first_paragraph);
225 for (; paragraph; paragraph = paragraph->next)
227 /* New line; new paragraph */
228 if (paragraph->wVSpace == 1)
229 printf(format.newline);
230 else if (paragraph->wVSpace > 1)
231 printf(format.next_paragraph);
233 if (paragraph->wFont)
234 printf(format.begin_boldface);
236 print_text(paragraph->lpszText);
238 if (paragraph->wFont)
239 printf(format.end_boldface);
243 printf(format.tail);
245 return(0);
248 /***********************************************************************
250 * Substitutions for some WINELIB functions
253 static FILE *file = 0;
255 HFILE WINAPI OpenFile( LPCSTR path, OFSTRUCT *ofs, UINT mode )
257 file = *path ? fopen(path, "r") : stdin;
258 return file ? 1 : HFILE_ERROR;
261 HFILE WINAPI _lclose( HFILE hFile )
263 fclose(file);
264 return 0;
267 LONG WINAPI _hread( HFILE hFile, LPVOID buffer, LONG count )
269 return fread(buffer, 1, count, file);
272 HGLOBAL WINAPI GlobalAlloc( UINT flags, DWORD size )
274 return (HGLOBAL) malloc(size);
277 LPVOID WINAPI GlobalLock( HGLOBAL handle )
279 return (LPVOID) handle;
282 HGLOBAL WINAPI GlobalFree( HGLOBAL handle )
284 free((VOID*) handle);
285 return(0);
289 * String functions
291 * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
294 INT WINAPI lstrcmp(LPCSTR str1,LPCSTR str2)
296 return strcmp( str1, str2 );
299 INT WINAPI lstrcmpi( LPCSTR str1, LPCSTR str2 )
301 INT res;
303 while (*str1)
305 if ((res = toupper(*str1) - toupper(*str2)) != 0) return res;
306 str1++;
307 str2++;
309 return toupper(*str1) - toupper(*str2);
312 INT WINAPI lstrlen(LPCSTR str)
314 return strlen(str);
317 LPSTR WINAPI lstrcpyA( LPSTR dst, LPCSTR src )
319 if (!src || !dst) return NULL;
320 strcpy( dst, src );
321 return dst;
324 void WINAPI hmemcpy16(LPVOID hpvDest, LPCVOID hpvSource, LONG cbCopy)
326 memcpy(hpvDest, hpvSource, cbCopy);
329 /* Local Variables: */
330 /* c-file-style: "GNU" */
331 /* End: */