[79ee183] | 1 | /* editwrap.c |
---|
| 2 | * Run svxedit.tcl from the same directory as this program |
---|
| 3 | * Copyright (C) 2002 Olly Betts |
---|
| 4 | * |
---|
| 5 | * This program is free software; you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU General Public License as published by |
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 8 | * (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with this program; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #ifdef HAVE_CONFIG_H |
---|
| 21 | #include <config.h> |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | #include <stdlib.h> |
---|
| 25 | #include <string.h> |
---|
| 26 | #include <windows.h> |
---|
| 27 | |
---|
| 28 | int APIENTRY |
---|
| 29 | WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) |
---|
| 30 | { |
---|
| 31 | DWORD len = 256; |
---|
| 32 | char *buf = NULL, *p; |
---|
| 33 | hInst = hInst; /* suppress compiler warning */ |
---|
| 34 | hPrevInst = hPrevInst; /* suppress compiler warning */ |
---|
| 35 | while (1) { |
---|
| 36 | DWORD got; |
---|
| 37 | buf = realloc(buf, len); |
---|
| 38 | if (!buf) exit(1); |
---|
| 39 | got = GetModuleFileName(NULL, buf, len); |
---|
| 40 | if (got + 12 < len) break; |
---|
| 41 | len += len; |
---|
| 42 | } |
---|
| 43 | /* Strange Win32 nastiness - strip prefix "\\?\" if present */ |
---|
| 44 | if (strncmp(buf, "\\\\?\\", 4) == 0) buf += 4; |
---|
| 45 | p = strrchr(buf, '\\'); |
---|
| 46 | if (p) ++p; else p = buf; |
---|
| 47 | strcpy(p, "svxedit.tcl"); |
---|
| 48 | /* ShellExecute returns an HINSTANCE for some wacko reason - the docs say |
---|
| 49 | * the only valid operation is to convert it to an int. Marvellous. */ |
---|
| 50 | if ((int)ShellExecute(NULL, NULL, buf, lpCmdLine, NULL, nCmdShow) <= 32) { |
---|
| 51 | ShellExecute(NULL, NULL, "notepad", lpCmdLine, NULL, nCmdShow); |
---|
| 52 | } |
---|
| 53 | return 0; |
---|
| 54 | } |
---|