Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1996 Ulrich Schmid |
| 3 | */ |
| 4 | |
| 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" |
| 13 | |
| 14 | typedef struct |
| 15 | { |
| 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; |
| 31 | |
| 32 | typedef struct |
| 33 | { |
| 34 | const char ch; |
| 35 | const char *subst; |
| 36 | } CHARMAP[]; |
| 37 | |
| 38 | |
| 39 | FORMAT format = |
| 40 | { |
| 41 | "<!doctype linuxdoc system>\n" |
| 42 | "<article>\n" |
| 43 | "<title>\n", |
| 44 | |
| 45 | "\n<author>\n%s\n" |
| 46 | "<date>\n%s\n", |
| 47 | |
| 48 | "\n<sect>\n", |
| 49 | "\n<p>\n", |
| 50 | "\n<newline>\n", |
| 51 | "\n\n", |
| 52 | |
| 53 | "&%s;", |
| 54 | |
| 55 | "<em>", |
| 56 | "</em>", |
| 57 | "<bf>", |
| 58 | "</bf>", |
| 59 | "<tt>", |
| 60 | "</tt>", |
| 61 | |
| 62 | "\n</article>\n" |
| 63 | }; |
| 64 | |
| 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}}; |
| 162 | |
| 163 | /*********************************************************************** |
| 164 | * |
| 165 | * print_text |
| 166 | */ |
| 167 | |
| 168 | static void print_text(const char *p) |
| 169 | { |
| 170 | int i; |
| 171 | |
| 172 | for (; *p; p++) |
| 173 | { |
| 174 | for (i = 0; charmap[i].ch; i++) |
| 175 | if (*p == charmap[i].ch) |
| 176 | { |
| 177 | printf(format.special_char, charmap[i].subst); |
| 178 | break; |
| 179 | } |
| 180 | if (!charmap[i].ch) |
| 181 | printf("%c", *p); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /*********************************************************************** |
| 186 | * |
| 187 | * main |
| 188 | */ |
| 189 | |
| 190 | int main(int argc, char **argv) |
| 191 | { |
| 192 | HLPFILE *hlpfile; |
| 193 | HLPFILE_PAGE *page; |
| 194 | HLPFILE_PARAGRAPH *paragraph; |
| 195 | time_t t; |
| 196 | char date[50]; |
| 197 | char *filename; |
| 198 | |
| 199 | hlpfile = HLPFILE_ReadHlpFile(argc > 1 ? argv[1] : ""); |
| 200 | |
| 201 | if (!hlpfile) return(2); |
| 202 | |
| 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; |
| 208 | |
| 209 | /* Header */ |
| 210 | printf(format.header1); |
| 211 | print_text(hlpfile->lpszTitle); |
| 212 | printf(format.header2, filename, date); |
| 213 | |
| 214 | for (page = hlpfile->first_page; page; page = page->next) |
| 215 | { |
| 216 | paragraph = page->first_paragraph; |
| 217 | if (!paragraph) continue; |
| 218 | |
| 219 | /* Section */ |
| 220 | printf(format.section); |
| 221 | for (; paragraph && !paragraph->wVSpace; paragraph = paragraph->next) |
| 222 | print_text(paragraph->lpszText); |
| 223 | printf(format.first_paragraph); |
| 224 | |
| 225 | for (; paragraph; paragraph = paragraph->next) |
| 226 | { |
| 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); |
| 232 | |
| 233 | if (paragraph->wFont) |
| 234 | printf(format.begin_boldface); |
| 235 | |
| 236 | print_text(paragraph->lpszText); |
| 237 | |
| 238 | if (paragraph->wFont) |
| 239 | printf(format.end_boldface); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | printf(format.tail); |
| 244 | |
| 245 | return(0); |
| 246 | } |
| 247 | |
| 248 | /*********************************************************************** |
| 249 | * |
| 250 | * Substitutions for some WINELIB functions |
| 251 | */ |
| 252 | |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 253 | static FILE *file = 0; |
| 254 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 255 | HFILE WINAPI OpenFile( LPCSTR path, OFSTRUCT *ofs, UINT mode ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 256 | { |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 257 | file = *path ? fopen(path, "r") : stdin; |
Francois Gouget | 56045a5 | 2000-07-23 19:33:42 +0000 | [diff] [blame] | 258 | return file ? (HFILE)1 : HFILE_ERROR; |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 261 | HFILE WINAPI _lclose( HFILE hFile ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 262 | { |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 263 | fclose(file); |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 267 | LONG WINAPI _hread( HFILE hFile, LPVOID buffer, LONG count ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 268 | { |
Alexandre Julliard | 2d93d00 | 1996-05-21 15:01:41 +0000 | [diff] [blame] | 269 | return fread(buffer, 1, count, file); |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Marcus Meissner | 6b5a811 | 1999-01-30 13:06:00 +0000 | [diff] [blame] | 272 | HGLOBAL WINAPI GlobalAlloc( UINT flags, DWORD size ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 273 | { |
| 274 | return (HGLOBAL) malloc(size); |
| 275 | } |
| 276 | |
Marcus Meissner | 6b5a811 | 1999-01-30 13:06:00 +0000 | [diff] [blame] | 277 | LPVOID WINAPI GlobalLock( HGLOBAL handle ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 278 | { |
| 279 | return (LPVOID) handle; |
| 280 | } |
| 281 | |
Marcus Meissner | 6b5a811 | 1999-01-30 13:06:00 +0000 | [diff] [blame] | 282 | HGLOBAL WINAPI GlobalFree( HGLOBAL handle ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 283 | { |
| 284 | free((VOID*) handle); |
| 285 | return(0); |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * String functions |
| 290 | * |
| 291 | * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is) |
| 292 | */ |
| 293 | |
Marcus Meissner | 6b5a811 | 1999-01-30 13:06:00 +0000 | [diff] [blame] | 294 | INT WINAPI lstrcmp(LPCSTR str1,LPCSTR str2) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 295 | { |
| 296 | return strcmp( str1, str2 ); |
| 297 | } |
| 298 | |
Marcus Meissner | 6b5a811 | 1999-01-30 13:06:00 +0000 | [diff] [blame] | 299 | INT WINAPI lstrcmpi( LPCSTR str1, LPCSTR str2 ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 300 | { |
| 301 | INT res; |
| 302 | |
| 303 | while (*str1) |
| 304 | { |
| 305 | if ((res = toupper(*str1) - toupper(*str2)) != 0) return res; |
| 306 | str1++; |
| 307 | str2++; |
| 308 | } |
| 309 | return toupper(*str1) - toupper(*str2); |
| 310 | } |
| 311 | |
Marcus Meissner | 6b5a811 | 1999-01-30 13:06:00 +0000 | [diff] [blame] | 312 | INT WINAPI lstrlen(LPCSTR str) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 313 | { |
| 314 | return strlen(str); |
| 315 | } |
| 316 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 317 | LPSTR WINAPI lstrcpyA( LPSTR dst, LPCSTR src ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 318 | { |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 319 | if (!src || !dst) return NULL; |
| 320 | strcpy( dst, src ); |
| 321 | return dst; |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 324 | void WINAPI hmemcpy16(LPVOID hpvDest, LPCVOID hpvSource, LONG cbCopy) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 325 | { |
| 326 | memcpy(hpvDest, hpvSource, cbCopy); |
| 327 | } |
| 328 | |
| 329 | /* Local Variables: */ |
| 330 | /* c-file-style: "GNU" */ |
| 331 | /* End: */ |