hlp2sgml.c 7.68 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2
/*
 * Copyright 1996 Ulrich Schmid
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Alexandre Julliard's avatar
Alexandre Julliard committed
17 18 19 20 21 22 23 24
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <fcntl.h>
25
#include <assert.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
26 27 28 29 30
#include "windows.h"
#include "hlpfile.h"

typedef struct
{
31 32 33 34 35 36 37 38 39 40 41 42 43 44
    const char *header1;
    const char *header2;
    const char *section;
    const char *first_paragraph;
    const char *newline;
    const char *next_paragraph;
    const char *special_char;
    const char *begin_italic;
    const char *end_italic;
    const char *begin_boldface;
    const char *end_boldface;
    const char *begin_typewriter;
    const char *end_typewriter;
    const char *tail;
Alexandre Julliard's avatar
Alexandre Julliard committed
45 46 47 48
} FORMAT;

typedef struct
{
49 50
    const char ch;
    const char *subst;
51
} CHARMAP_ENTRY;
Alexandre Julliard's avatar
Alexandre Julliard committed
52 53 54 55


FORMAT format =
{
56 57 58
    "<!doctype linuxdoc system>\n"
    "<article>\n"
    "<title>\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
59

60 61
    "\n<author>\n%s\n"
    "<date>\n%s\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
62

63 64 65 66
    "\n<sect>\n",
    "\n<p>\n",
    "\n<newline>\n",
    "\n\n",
Alexandre Julliard's avatar
Alexandre Julliard committed
67

68
    "&%s;",
Alexandre Julliard's avatar
Alexandre Julliard committed
69

70 71 72 73 74 75
    "<em>",
    "</em>",
    "<bf>",
    "</bf>",
    "<tt>",
    "</tt>",
Alexandre Julliard's avatar
Alexandre Julliard committed
76

77
    "\n</article>\n"
Alexandre Julliard's avatar
Alexandre Julliard committed
78 79
};

80
CHARMAP_ENTRY charmap[] =
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
{{'', "AElig"},
 {'', "Aacute"},
 {'', "Acirc"},
 {'', "Agrave"},
 {'', "Atilde"},
 {'', "Ccedil"},
 {'', "Eacute"},
 {'', "Egrave"},
 {'', "Euml"},
 {'', "Iacute"},
 {'', "Icirc"},
 {'', "Igrave"},
 {'', "Iuml"},
 {'', "Ntilde"},
 {'', "Oacute"},
 {'', "Ocirc"},
 {'', "Ograve"},
 {'', "Oslash"},
 {'', "Uacute"},
 {'', "Ugrave"},
 {'', "Yacute"},
 {'', "aacute"},
 {'', "acirc"},
 {'', "aelig"},
 {'', "agrave"},
 {'', "aring"},
 {'', "atilde"},
 {'', "ccedil"},
 {'', "eacute"},
 {'', "ecirc"},
 {'', "egrave"},
 {'', "euml"},
 {'', "iacute"},
 {'', "icirc"},
 {'', "igrave"},
 {'', "iuml"},
 {'', "ntilde"},
 {'', "oacute"},
 {'', "yuml"},
 {'', "ocirc"},
 {'', "ograve"},
 {'', "oslash"},
 {'', "otilde"},
 {'', "uacute"},
 {'', "ucirc"},
 {'', "ugrave"},
 {'', "yacute"},
 {'<', "lt"},
 {'&', "amp"},
 {'"', "dquot"},
 {'#', "num"},
 {'%', "percnt"},
 {'\'', "quot"},
Alexandre Julliard's avatar
Alexandre Julliard committed
134
#if 0
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
 {'(', "lpar"},
 {')', "rpar"},
 {'*', "ast"},
 {'+', "plus"},
 {',', "comma"},
 {'-', "hyphen"},
 {':', "colon"},
 {';', "semi"},
 {'=', "equals"},
 {'@', "commat"},
 {'[', "lsqb"},
 {']', "rsqb"},
 {'^', "circ"},
 {'_', "lowbar"},
 {'{', "lcub"},
 {'|', "verbar"},
 {'}', "rcub"},
 {'~', "tilde"},
Alexandre Julliard's avatar
Alexandre Julliard committed
153
#endif
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
 {'\\', "bsol"},
 {'$', "dollar"},
 {'', "Auml"},
 {'', "auml"},
 {'', "Ouml"},
 {'', "ouml"},
 {'', "Uuml"},
 {'', "uuml"},
 {'', "szlig"},
 {'>', "gt"},
 {'', "sect"},
 {'', "para"},
 {'', "copy"},
 {'', "iexcl"},
 {'', "iquest"},
 {'', "cent"},
 {'', "pound"},
 {'', "times"},
 {'', "plusmn"},
 {'', "divide"},
 {'', "not"},
 {'', "mu"},
 {0,0}};
Alexandre Julliard's avatar
Alexandre Julliard committed
177 178 179 180 181 182 183 184

/***********************************************************************
 *
 *           print_text
 */

static void print_text(const char *p)
{
185
    int i;
Alexandre Julliard's avatar
Alexandre Julliard committed
186

187
    for (; *p; p++)
Alexandre Julliard's avatar
Alexandre Julliard committed
188
    {
189 190 191 192 193 194 195 196
        for (i = 0; charmap[i].ch; i++)
            if (*p == charmap[i].ch)
            {
                printf(format.special_char, charmap[i].subst);
                break;
            }
        if (!charmap[i].ch)
            printf("%c", *p);
Alexandre Julliard's avatar
Alexandre Julliard committed
197 198 199 200 201 202 203 204 205 206
    }
}

/***********************************************************************
 *
 *           main
 */

int main(int argc, char **argv)
{
207 208 209 210 211 212
    HLPFILE   *hlpfile;
    HLPFILE_PAGE *page;
    HLPFILE_PARAGRAPH *paragraph;
    time_t t;
    char date[50];
    char *filename;
Alexandre Julliard's avatar
Alexandre Julliard committed
213

214
    hlpfile = HLPFILE_ReadHlpFile(argc > 1 ? argv[1] : "");
Alexandre Julliard's avatar
Alexandre Julliard committed
215

216
    if (!hlpfile) return 2;
Alexandre Julliard's avatar
Alexandre Julliard committed
217

218 219 220 221 222
    time(&t);
    strftime(date, sizeof(date), "%x", localtime(&t));
    filename = strrchr(hlpfile->lpszPath, '/');
    if (filename) filename++;
    else filename = hlpfile->lpszPath;
Alexandre Julliard's avatar
Alexandre Julliard committed
223

224 225 226 227
    /* Header */
    printf(format.header1);
    print_text(hlpfile->lpszTitle);
    printf(format.header2, filename, date);
Alexandre Julliard's avatar
Alexandre Julliard committed
228

229
    for (page = hlpfile->first_page; page; page = page->next)
Alexandre Julliard's avatar
Alexandre Julliard committed
230
    {
231 232
        paragraph = page->first_paragraph;
        if (!paragraph) continue;
Alexandre Julliard's avatar
Alexandre Julliard committed
233

234 235 236 237 238
        /* Section */
        printf(format.section);
        for (; paragraph && !paragraph->u.text.wVSpace; paragraph = paragraph->next)
            print_text(paragraph->u.text.lpszText);
        printf(format.first_paragraph);
Alexandre Julliard's avatar
Alexandre Julliard committed
239

240
        for (; paragraph; paragraph = paragraph->next)
Alexandre Julliard's avatar
Alexandre Julliard committed
241
	{
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
            switch (paragraph->cookie)
            {
            case para_normal_text:
            case para_debug_text:
                /* New line; new paragraph */
                if (paragraph->u.text.wVSpace == 1)
                    printf(format.newline);
                else if (paragraph->u.text.wVSpace > 1)
                    printf(format.next_paragraph);

                if (paragraph->u.text.wFont)
                    printf(format.begin_boldface);

                print_text(paragraph->u.text.lpszText);

                if (paragraph->u.text.wFont)
                    printf(format.end_boldface);
                break;
260 261
            case para_bitmap:
            case para_metafile:
262 263
                break;
            }
Alexandre Julliard's avatar
Alexandre Julliard committed
264 265 266
	}
    }

267
    printf(format.tail);
Alexandre Julliard's avatar
Alexandre Julliard committed
268

269
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
270 271 272 273 274 275 276
}

/***********************************************************************
 *
 *           Substitutions for some WINELIB functions
 */

Alexandre Julliard's avatar
Alexandre Julliard committed
277 278
static FILE *file = 0;

279
HFILE WINAPI OpenFile( LPCSTR path, OFSTRUCT *ofs, UINT mode )
Alexandre Julliard's avatar
Alexandre Julliard committed
280
{
281 282
    file = *path ? fopen(path, "r") : stdin;
    return file ? (HFILE)1 : HFILE_ERROR;
Alexandre Julliard's avatar
Alexandre Julliard committed
283 284
}

285
HFILE WINAPI _lclose( HFILE hFile )
Alexandre Julliard's avatar
Alexandre Julliard committed
286
{
287 288
    fclose(file);
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
289 290
}

291
LONG WINAPI _hread( HFILE hFile, LPVOID buffer, LONG count )
Alexandre Julliard's avatar
Alexandre Julliard committed
292
{
293 294 295
    return fread(buffer, 1, count, file);
}

296 297 298 299 300
HANDLE WINAPI GetProcessHeap(void)
{
    return 0;
}

301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
void* WINAPI HeapAlloc( HANDLE heap, DWORD flags, DWORD size )
{
    assert(flags == 0);
    return malloc(size);
}

void* WINAPI HeapReAlloc( HANDLE heap, DWORD flags, void* ptr, DWORD size)
{
    assert(flags == 0);
    return realloc(ptr, size);
}

BOOL WINAPI HeapFree( HGLOBAL handle, DWORD flags, void* ptr )
{
    free(ptr);
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
317 318
}

319 320 321
char __wine_dbch_winhelp[] = "\003winhelp";

int wine_dbg_log( int cls, const char *channel, const char *func, const char *format, ... )
Alexandre Julliard's avatar
Alexandre Julliard committed
322
{
323
    return 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
324 325
}

326
HBITMAP WINAPI CreateDIBitmap(HDC hdc, CONST BITMAPINFOHEADER* bih, DWORD a, CONST void* ptr, CONST BITMAPINFO* bi, UINT c)
Alexandre Julliard's avatar
Alexandre Julliard committed
327
{
328
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
329 330
}

331 332 333 334 335 336 337 338 339 340
HMETAFILE WINAPI SetMetaFileBitsEx(UINT cbBuffer, CONST BYTE *lpbBuffer)
{
    return 0;
}

BOOL WINAPI DeleteMetaFile(HMETAFILE h)
{
    return 0;
}

341
HDC WINAPI GetDC(HWND h)
Alexandre Julliard's avatar
Alexandre Julliard committed
342
{
343
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
344 345
}

346 347 348 349 350
int WINAPI ReleaseDC(HWND h, HDC hdc)
{
    return 0;
}

351 352 353 354
BOOL WINAPI DeleteObject(HGDIOBJ h)
{
    return TRUE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
355 356 357 358 359 360
/*
 * String functions
 *
 * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is)
 */

361
INT WINAPI lstrcmp( LPCSTR str1, LPCSTR str2 )
Alexandre Julliard's avatar
Alexandre Julliard committed
362
{
363
    return strcmp( str1, str2 );
Alexandre Julliard's avatar
Alexandre Julliard committed
364 365
}

366
INT WINAPI lstrcmpi( LPCSTR str1, LPCSTR str2 )
Alexandre Julliard's avatar
Alexandre Julliard committed
367
{
368
    INT res;
Alexandre Julliard's avatar
Alexandre Julliard committed
369

370
    while (*str1)
Alexandre Julliard's avatar
Alexandre Julliard committed
371
    {
372 373 374
        if ((res = toupper(*str1) - toupper(*str2)) != 0) return res;
        str1++;
        str2++;
Alexandre Julliard's avatar
Alexandre Julliard committed
375
    }
376
    return toupper(*str1) - toupper(*str2);
Alexandre Julliard's avatar
Alexandre Julliard committed
377 378
}

379
INT WINAPI lstrlen( LPCSTR str )
Alexandre Julliard's avatar
Alexandre Julliard committed
380
{
381
    return strlen(str);
Alexandre Julliard's avatar
Alexandre Julliard committed
382 383
}

384
LPSTR WINAPI lstrcpyA( LPSTR dst, LPCSTR src )
Alexandre Julliard's avatar
Alexandre Julliard committed
385
{
Alexandre Julliard's avatar
Alexandre Julliard committed
386 387 388
    if (!src || !dst) return NULL;
    strcpy( dst, src );
    return dst;
Alexandre Julliard's avatar
Alexandre Julliard committed
389
}