1 /* mswindows.c -- Windows-specific support
2 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 This file is part of Wget.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* #### Someone document these functions! */
35 /* Defined in log.c. */
36 void redirect_output (const char *);
38 static int windows_nt_p;
41 /* Emulation of Unix sleep. */
43 sleep (unsigned seconds)
45 Sleep (1000 * seconds);
46 /* Unix sleep() is interruptible. To make it semi-usable, it
47 returns a value that says how much it "really" slept, or some
48 junk like that. Ignore it. */
53 read_registry (HKEY hkey, char *subkey, char *valuename, char *buf, int *len)
58 if (RegOpenKeyEx (hkey, subkey, NULL, KEY_READ, &result) != ERROR_SUCCESS)
60 if (RegQueryValueEx (result, valuename, NULL, &type, buf, &size) != ERROR_SUCCESS)
68 pwd_cuserid (char *where)
71 int len = sizeof (buf);
72 if (GetUserName (buf, (LPDWORD) &len) == TRUE)
76 else if (!!(ptr = getenv ("USERNAME")))
80 else if (!read_registry (HKEY_LOCAL_MACHINE, "Network\\Logon",
81 "username", buf, &len))
87 strncpy (where, buf, len);
94 windows_main_junk (int *argc, char **argv, char **exec_name)
100 /* Remove .EXE from filename if it has one. */
101 *exec_name = xstrdup (*exec_name);
102 p = strrchr (*exec_name, '.');
118 redirect_output (_("\n\
119 CTRL+Break received, redirecting output to `%s'.\n\
120 Execution continued in background.\n\
121 You may stop Wget by pressing CTRL+ALT+DELETE.\n"));
125 fork_to_background (void)
127 /* Whether we arrange our own version of opt.lfilename here. */
132 opt.lfilename = unique_name (DEFAULT_LOGFILE);
135 printf (_("Continuing in background.\n"));
137 printf (_("Output will be written to `%s'.\n"), opt.lfilename);
145 ws_handler (DWORD dwEvent)
152 #ifdef CTRLBREAK_BACKGND
153 case CTRL_BREAK_EVENT:
155 fork_to_background ();
157 case CTRL_SHUTDOWN_EVENT:
158 case CTRL_CLOSE_EVENT:
159 case CTRL_LOGOFF_EVENT:
168 ws_changetitle (char *url, int nurl)
174 title_buf = (char *)xmalloc (strlen (url) + 20);
175 sprintf (title_buf, "Wget %s%s", url, nurl == 1 ? "" : " ...");
176 /* #### What are the semantics of SetConsoleTitle? Will it free the
177 given memory later? */
178 SetConsoleTitle (title_buf);
184 static char *wspathsave;
193 ptr = strrchr (argv0, '\\');
197 wspathsave = (char*) xmalloc (strlen(argv0)+1);
198 strcpy (wspathsave, argv0);
201 buffer = (char*) xmalloc (256);
202 rrr = SearchPath (NULL, argv0, strchr (argv0, '.') ? NULL : ".EXE",
204 if (rrr && rrr <= 256)
207 wspathsave = (char*) xmalloc (strlen(buffer)+1);
208 strcpy (wspathsave, buffer);
216 ws_help (const char *name)
218 char *mypath = ws_mypath ();
223 char *buf = (char *)alloca (strlen (mypath) + strlen (name) + 4 + 1);
224 sprintf (buf, "%s%s.HLP", mypath, name);
225 if (stat (buf, &sbuf) == 0)
227 printf (_("Starting WinHelp %s\n"), buf);
228 WinHelp (NULL, buf, HELP_INDEX, NULL);
232 printf ("%s: %s\n", buf, strerror (errno));
245 if (GetVersionEx (&os) == TRUE
246 && os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
249 requested = MAKEWORD (1, 1);
250 err = WSAStartup (requested, &data);
254 fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
259 if (LOBYTE (requested) < 1 || (LOBYTE (requested) == 1 &&
260 HIBYTE (requested) < 1))
262 fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
268 SetConsoleCtrlHandler (ws_handler, TRUE);