diff --git a/lib-src/ntlib.h b/lib-src/ntlib.h new file mode 100644 index 00000000000..1598a291e73 --- /dev/null +++ b/lib-src/ntlib.h @@ -0,0 +1,45 @@ +/* Utility and Unix shadow routines for GNU Emacs support programs on NT. + Copyright (C) 1994 Free Software Foundation, Inc. + + This file is part of GNU Emacs. + + GNU Emacs is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any later + version. + + GNU Emacs 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 General Public License for + more details. + + You should have received a copy of the GNU General Public License along + with GNU Emacs; see the file COPYING. If not, write to the Free Software + Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include + +void sleep(int seconds); +int getwd (char *dir); +int getppid(void); +char * getlogin (); +char * cuserid (char * s); +int getuid (); +int setuid (int uid); +struct passwd * getpwuid (int uid); +char * getpass (const char * prompt); +int fchown (int fd, int uid, int gid); + +#ifndef BSTRING +#define bzero(b, l) memset(b, 0, l) +#define bcopy(s, d, l) memcpy(d, s, l) +#define bcmp(a, b, l) memcmp(a, b, l) + +#define index strchr +#define rindex strrchr +#endif + +/* end of ntlib.h */ diff --git a/nt/inc/arpa/inet.h b/nt/inc/arpa/inet.h new file mode 100644 index 00000000000..f5d197c06e1 --- /dev/null +++ b/nt/inc/arpa/inet.h @@ -0,0 +1 @@ +/* null version of - has everything */ diff --git a/nt/inc/netdb.h b/nt/inc/netdb.h new file mode 100644 index 00000000000..5bf232e7f5c --- /dev/null +++ b/nt/inc/netdb.h @@ -0,0 +1 @@ +/* null version of - has everything */ diff --git a/nt/inc/netinet/in.h b/nt/inc/netinet/in.h new file mode 100644 index 00000000000..46fb0faccea --- /dev/null +++ b/nt/inc/netinet/in.h @@ -0,0 +1 @@ +/* null version of - has everything */ diff --git a/nt/inc/sys/socket.h b/nt/inc/sys/socket.h new file mode 100644 index 00000000000..4ea1e44cd12 --- /dev/null +++ b/nt/inc/sys/socket.h @@ -0,0 +1,119 @@ +/* Workable version of based on winsock.h */ + +#ifndef _SOCKET_H_ +#define _SOCKET_H_ + +/* defeat the multiple include protection */ +#ifdef _WINSOCKAPI_ +#undef _WINSOCKAPI_ +#endif + +/* avoid confusion with our version of select */ +#ifdef select +#undef select +#define MUST_REDEF_SELECT +#endif + +/* avoid clashing with our version of FD_SET if already defined */ +#ifdef FD_SET +#undef FD_SET +#undef FD_CLR +#undef FD_ISSET +#undef FD_ZERO +#endif + +/* allow us to provide our own version of fd_set */ +#define fd_set ws_fd_set + +/* avoid duplicate definition of timeval */ +#ifdef HAVE_TIMEVAL +#define timeval ws_timeval +#endif + +#include + +/* redefine select to reference our version */ +#ifdef MUST_REDEF_SELECT +#define select sys_select +#undef MUST_REDEF_SELECT +#endif + +/* revert to our version of FD_SET */ +#undef FD_SET +#undef FD_CLR +#undef FD_ISSET +#undef FD_ZERO +#undef fd_set +#include "nt.h" + +#ifdef HAVE_TIMEVAL +#undef timeval +#endif + +/* shadow functions where we provide our own wrapper */ +#define socket sys_socket +#define bind sys_bind +#define connect sys_connect +#define htons sys_htons +#define ntohs sys_ntohs +#define inet_addr sys_inet_addr +#define gethostname sys_gethostname +#define gethostbyname sys_gethostbyname +#define getservbyname sys_getservbyname + +int sys_socket(int af, int type, int protocol); +int sys_bind (int s, const struct sockaddr *addr, int namelen); +int sys_connect (int s, const struct sockaddr *addr, int namelen); +u_short sys_htons (u_short hostshort); +u_short sys_ntohs (u_short netshort); +unsigned long sys_inet_addr (const char * cp); +int sys_gethostname (char * name, int namelen); +struct hostent * sys_gethostbyname(const char * name); +struct servent * sys_getservbyname(const char * name, const char * proto); + +/* we are providing a real h_errno variable */ +#undef h_errno +extern int h_errno; + +/* map winsock error codes to standard names */ +#define EWOULDBLOCK WSAEWOULDBLOCK +#define EINPROGRESS WSAEINPROGRESS +#define EALREADY WSAEALREADY +#define ENOTSOCK WSAENOTSOCK +#define EDESTADDRREQ WSAEDESTADDRREQ +#define EMSGSIZE WSAEMSGSIZE +#define EPROTOTYPE WSAEPROTOTYPE +#define ENOPROTOOPT WSAENOPROTOOPT +#define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT +#define EOPNOTSUPP WSAEOPNOTSUPP +#define EPFNOSUPPORT WSAEPFNOSUPPORT +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#define EADDRINUSE WSAEADDRINUSE +#define EADDRNOTAVAIL WSAEADDRNOTAVAIL +#define ENETDOWN WSAENETDOWN +#define ENETUNREACH WSAENETUNREACH +#define ENETRESET WSAENETRESET +#define ECONNABORTED WSAECONNABORTED +#define ECONNRESET WSAECONNRESET +#define ENOBUFS WSAENOBUFS +#define EISCONN WSAEISCONN +#define ENOTCONN WSAENOTCONN +#define ESHUTDOWN WSAESHUTDOWN +#define ETOOMANYREFS WSAETOOMANYREFS +#define ETIMEDOUT WSAETIMEDOUT +#define ECONNREFUSED WSAECONNREFUSED +#define ELOOP WSAELOOP +/* #define ENAMETOOLONG WSAENAMETOOLONG */ +#define EHOSTDOWN WSAEHOSTDOWN +#define EHOSTUNREACH WSAEHOSTUNREACH +/* #define ENOTEMPTY WSAENOTEMPTY */ +#define EPROCLIM WSAEPROCLIM +#define EUSERS WSAEUSERS +#define EDQUOT WSAEDQUOT +#define ESTALE WSAESTALE +#define EREMOTE WSAEREMOTE + +#endif /* _SOCKET_H_ */ + +/* end of socket.h */ diff --git a/nt/inc/sys/time.h b/nt/inc/sys/time.h new file mode 100644 index 00000000000..dc270998609 --- /dev/null +++ b/nt/inc/sys/time.h @@ -0,0 +1,18 @@ +/* + * sys/time.h doesn't exist on NT + */ + +struct timeval + { + long tv_sec; /* seconds */ + long tv_usec; /* microseconds */ + }; +struct timezone + { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ + }; + +void gettimeofday (struct timeval *, struct timezone *); + +/* end of sys/time.h */ diff --git a/nt/inc/unistd.h b/nt/inc/unistd.h new file mode 100644 index 00000000000..c1caa77a697 --- /dev/null +++ b/nt/inc/unistd.h @@ -0,0 +1 @@ +/* Fake unistd.h: config.h already provides most of the relevant things. */ diff --git a/nt/runemacs.c b/nt/runemacs.c new file mode 100644 index 00000000000..720c6ca7241 --- /dev/null +++ b/nt/runemacs.c @@ -0,0 +1,80 @@ +/* + Simple program to start Emacs with its console window hidden. + + This program is provided purely for convenience, since most users will + use Emacs in windowing (GUI) mode, and will not want to have an extra + console window lying around. */ + +#define WIN32 + +#include +#include +#include + +int WINAPI +WinMain (HINSTANCE hSelf, HINSTANCE hPrev, LPSTR cmdline, int nShow) +{ + STARTUPINFO start; + SECURITY_ATTRIBUTES sec_attrs; + SECURITY_DESCRIPTOR sec_desc; + PROCESS_INFORMATION child; + int wait_for_child = FALSE; + DWORD ret_code = 0; + char * new_cmdline; + char * p; + char modname[MAX_PATH]; + + if (!GetModuleFileName (NULL, modname, MAX_PATH)) + goto error; + if ((p = strrchr (modname, '\\')) == NULL) + goto error; + *p = 0; + + new_cmdline = alloca (MAX_PATH + strlen (cmdline) + 1); + strcpy (new_cmdline, modname); + strcat (new_cmdline, "\\emacs.exe "); + + /* append original arguments if any; first look for -wait as first + argument, and apply that ourselves */ + if (strncmp (cmdline, "-wait", 5) == 0) + { + wait_for_child = TRUE; + cmdline += 5; + } + strcat (new_cmdline, cmdline); + + /* set emacs_dir variable if runemacs was in "%emacs_dir%\bin" */ + if ((p = strrchr (modname, '\\')) && stricmp (p, "\\bin") == 0) + { + *p = 0; + SetEnvironmentVariable ("emacs_dir", modname); + } + + memset (&start, 0, sizeof (start)); + start.cb = sizeof (start); + start.dwFlags = STARTF_USESHOWWINDOW; + start.wShowWindow = SW_HIDE; + + sec_attrs.nLength = sizeof (sec_attrs); + sec_attrs.lpSecurityDescriptor = NULL; + sec_attrs.bInheritHandle = FALSE; + + if (CreateProcess (NULL, new_cmdline, &sec_attrs, NULL, TRUE, 0, + NULL, NULL, &start, &child)) + { + if (wait_for_child) + { + WaitForSingleObject (child.hProcess, INFINITE); + GetExitCodeProcess (child.hProcess, &ret_code); + } + CloseHandle (child.hThread); + CloseHandle (child.hProcess); + } + else + goto error; + return (int) ret_code; + +error: + MessageBox (NULL, "Could not start Emacs.", "Error", MB_ICONSTOP); + return 1; +}