view nt/runemacs.c @ 31385:b1e1a94dfc0a

(vc-sccs-latest-on-branch-p): Always return t; we don't support anything else under SCCS yet. (vc-sccs-update-changelog): Dummy implementation that simply signals an error. (vc-sccs-state-heuristic): Use file-ownership-preserved-p. (vc-sccs-workfile-unchanged-p): Fix call to vc-do-command. (vc-sccs-state-heuristic): Don't use file-writable-p. (vc-sccs-workfile-unchanged-p): Fix parenthesis. (vc-sccs-print-log, vc-sccs-diff): Insert in the current buffer. (vc-sccs-workfile-unchanged-p): Rewritten. (vc-sccs-diff): Remove optional arg CMP. (vc-sccs-state): Call vc-workfile-unchanged-p, not the SCCS-specific function. (vc-sccs-state): Fix obviously wrong parenthesis. (vc-sccs-state-heuristic): Use file-writable-p instead of comparing userids. (vc-sccs-checkout): Use `unless'. (vc-sccs-state): Use with-temp-buffer. (vc-sccs-workfile-version): Use with-temp-buffer and new vc-parse-buffer and don't bother setting the property. (vc-sccs-add-triple): Use with-current-buffer and find-file-noselect. (vc-sccs-lookup-triple): New vc-parse-buffer and turn cond -> if. Merge in code from vc-sccs-hooks.el. (vc-sccs-release, vc-sccs-system-release): Remove. Don't require 'vc anymore. (vc-sccs-responsible-p): Use expand-file-name instead of concat and file-directory-p instead of file-exists-p. (vc-sccs-check-headers): Simplify the regexp. (vc-sccs-responsible-p, vc-sccs-register): Use `vc-sccs-search-project-dir' instead of `vc-sccs-project-dir'. (vc-sccs-header): New var. (vc-sccs-rename-file): Renamed from vc-sccs-record-rename. Use `find-file-noselect' rather than `find-file' and call `vc-rename-master' to do the actual move. (vc-sccs-diff): Remove unused `backend' variable. (tail): Provide vc-sccs. (vc-sccs-checkout): Removed call to vc-file-clear-masterprops. If writable, set vc-state to 'edited rather than user login name. Require 'vc and 'vc-sccs-hooks. (vc-sccs-register-switches): New var, copied off of vc-rcs-hooks. (vc-sccs-latest-on-branch-p): Add a `FIXME' for a call to the unknown `vc-latest-version' function. It should probably refer to vc-workfile-version or somesuch, but it's very unclear to me and I don't have SCCS to test things. (vc-sccs-steal-lock): Renamed from `vc-sccs-steal'. (vc-BACKEND-responsible-p): New functions. (vc-BACKEND-register): Renamed from `vc-BACKEND-admin'. Removed query option. Redocumented. (vc-sccs-diff): Function changed name from `vc-backend-diff'. This makes `vc-diff' work. (vc-sccs-release): Doc fix. (vc-sccs-admin): Added the query-only option as required by the vc.el file. (vc-sccs-latest-on-branch-p): Function added. (vc-sccs-diff): Function added. (vc-sccs-checkout): Added function `vc-sccs-checkout'. Require vc when compiling. (vc-sccs-print-log, vc-sccs-assign-name, vc-sccs-merge) (vc-sccs-check-headers, vc-sccs-steal, vc-sccs-uncheck) (vc-sccs-revert) (vc-sccs-checkin, vc-sccs-logentry-check): New functions (code from vc.el). (vc-sccs-add-triple, vc-sccs-record-rename) (vc-sccs-lookup-triple): Moved from vc.el and renamed. (vc-sccs-admin): Doc fix. (vc-admin-sccs): Added from vc.el (vc-sccs-system-release): Renamed from vc-sccs-backend-release. (vc-sccs-release): Moved from vc.el. (vc-sccs-backend-release): New function.
author Gerd Moellmann <gerd@gnu.org>
date Mon, 04 Sep 2000 19:48:23 +0000
parents 6d99fe7bc313
children b2e0c0638bf2
line wrap: on
line source

/*
  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.  */

/*
   You may want to define this if you want to be able to install updated
   emacs binaries even when other users are using the current version.
   The problem with some file servers (notably Novell) is that an open
   file cannot be overwritten, deleted, or even renamed.  So if someone
   is running emacs.exe already, you cannot install a newer version.
   By defining CHOOSE_NEWEST_EXE, you can name your new emacs.exe
   something else which matches "emacs*.exe", and runemacs will
   automatically select the newest emacs executeable in the bin directory.
   (So you'll probably be able to delete the old version some hours/days
   later).
*/

/* #define CHOOSE_NEWEST_EXE */

#include <windows.h>
#include <string.h>
#include <malloc.h>

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 priority_class = NORMAL_PRIORITY_CLASS;
  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);

#ifdef CHOOSE_NEWEST_EXE
  {
    /* Silly hack to allow new versions to be installed on
       server even when current version is in use. */

    char * best_name = alloca (MAX_PATH + 1);
    FILETIME best_time = {0,0};
    WIN32_FIND_DATA wfd;
    HANDLE fh;
    p = new_cmdline + strlen (new_cmdline);
    strcpy (p, "\\emacs*.exe ");
    fh = FindFirstFile (new_cmdline, &wfd);
    if (fh == INVALID_HANDLE_VALUE)
      goto error;
    do
      {
        if (wfd.ftLastWriteTime.dwHighDateTime > best_time.dwHighDateTime
            || (wfd.ftLastWriteTime.dwHighDateTime == best_time.dwHighDateTime
                && wfd.ftLastWriteTime.dwLowDateTime > best_time.dwLowDateTime))
          {
            best_time = wfd.ftLastWriteTime;
            strcpy (best_name, wfd.cFileName);
          }
      }
    while (FindNextFile (fh, &wfd));
    FindClose (fh);
    *p++ = '\\';
    strcpy (p, best_name);
    strcat (p, " ");
  }
#else
  strcat (new_cmdline, "\\emacs.exe ");
#endif

  /* Append original arguments if any; first look for arguments we
     recognise (-wait, -high, and -low), and apply them ourselves.  */
  while (cmdline[0] == '-' || cmdline[0] == '/')
    {
      if (strncmp (cmdline+1, "wait", 4) == 0)
	{
      wait_for_child = TRUE;
      cmdline += 5;
    }
      else if (strncmp (cmdline+1, "high", 4) == 0)
	{
	  priority_class = HIGH_PRIORITY_CLASS;
	  cmdline += 5;
	}
      else if (strncmp (cmdline+1, "low", 3) == 0)
	{
	  priority_class = IDLE_PRIORITY_CLASS;
	  cmdline += 4;
	}
      else
	break;
    }
  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;
      for (p = modname; *p; p++)
	if (*p == '\\') *p = '/';
      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, priority_class,
		     GetEnvironmentStrings (), 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;
}