fix format not a string literal and no format arguments [-Werror=format-security]
[xcircuit.git] / xcircuit-win32.c
blob737dc6181229cbcf78aef9fbc474fa5c37105961
1 #include <windows.h>
3 #define CMDLINE_SIZE 4096
4 /*
5 #define WISH_EXE L"C:/Software/TclTk/bin/wish84.exe"
6 #define XCLIBDIR L"C:/Software/xcircuit/xcircuit-3.4"
7 */
9 wchar_t *parse_args(LPWSTR *wargv, int argc)
11 int i;
12 static wchar_t buffer[1024];
14 buffer[0] = L'\0';
15 for (i=1; i<argc; i++) {
16 if (_waccess(wargv[i], 0) == 0) {
17 wchar_t *c;
18 while ((c=wcschr(wargv[i], L'\\')) != NULL)
19 *c = L'/';
20 wcscat(buffer, L"\\\"");
21 wcscat(buffer, wargv[i]);
22 wcscat(buffer, L"\\\" ");
23 } else {
24 /*wcscat(buffer, wargv[i]);
25 wcscat(buffer, L" ");*/
29 return buffer;
32 static wchar_t wish_exe[1024] = {0};
33 static wchar_t lib_path[1024] = {0};
35 int look_paths()
37 HKEY hKey;
38 DWORD bufLen = 1024 * sizeof(wchar_t);
39 wchar_t buf[1100];
40 int i;
42 if (RegOpenKeyW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\xcircuit-dev-win32.exe", &hKey))
43 return -1;
44 if (RegQueryValueExW(
45 hKey,
46 L"WishExe",
47 NULL,
48 NULL,
49 (LPBYTE)wish_exe,
50 &bufLen)) {
51 RegCloseKey(hKey);
52 return -1;
54 bufLen = 1024 * sizeof(wchar_t);
55 if (RegQueryValueExW(
56 hKey,
57 L"LibPath",
58 NULL,
59 NULL,
60 (LPBYTE)lib_path,
61 &bufLen)) {
62 RegCloseKey(hKey);
63 return -1;
65 for (i=0; lib_path[i] != 0; i++)
66 if (lib_path[i] == L'\\')
67 lib_path[i] = L'/';
68 _snwprintf(buf, 1100, L"XCIRCUIT_LIB_DIR=%ws", lib_path);
69 _wputenv(buf);
70 RegCloseKey(hKey);
71 return 0;
74 int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int cmdShow)
76 LPWSTR *wargv;
77 wchar_t *cmdLine, *arg_str;
78 int argc, i;
79 STARTUPINFOW si;
80 PROCESS_INFORMATION pi;
82 wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
83 if (wargv != NULL) {
84 cmdLine = (wchar_t*)malloc(sizeof(wchar_t)*CMDLINE_SIZE);
85 arg_str = parse_args(wargv, argc);
86 if (look_paths())
87 goto error;
88 _snwprintf(cmdLine, CMDLINE_SIZE,
89 L"\"%ws\" \"%ws/tkcon.tcl\" -eval \"source \"\"%ws/console.tcl\"\"\" -slave \"package require Tk; set argv [list %ws]; set argc [llength argv]; source \"\"%ws/xcircuit.tcl\"\"\"",
90 wish_exe, lib_path, lib_path, arg_str, lib_path);
91 /*MessageBoxW(NULL, cmdLine, L"Info", MB_OK);*/
92 ZeroMemory(&si, sizeof(STARTUPINFOW));
93 si.cb = sizeof(STARTUPINFOW);
94 if (!CreateProcessW(NULL,
95 cmdLine,
96 NULL,
97 NULL,
98 FALSE,
100 NULL,
101 NULL,
102 &si,
103 &pi)) {
104 goto error;
106 goto success;
108 error:
109 MessageBox(NULL, "Unable to start xcircuit process", "Error", MB_OK);
111 success:
112 LocalFree(wargv);
113 free(cmdLine);
116 return 1;