annotate src/win32.c @ 665:fdefd0186b75

[xemacs-hg @ 2001-09-20 06:28:42 by ben] The great integral types renaming. The purpose of this is to rationalize the names used for various integral types, so that they match their intended uses and follow consist conventions, and eliminate types that were not semantically different from each other. The conventions are: -- All integral types that measure quantities of anything are signed. Some people disagree vociferously with this, but their arguments are mostly theoretical, and are vastly outweighed by the practical headaches of mixing signed and unsigned values, and more importantly by the far increased likelihood of inadvertent bugs: Because of the broken "viral" nature of unsigned quantities in C (operations involving mixed signed/unsigned are done unsigned, when exactly the opposite is nearly always wanted), even a single error in declaring a quantity unsigned that should be signed, or even the even more subtle error of comparing signed and unsigned values and forgetting the necessary cast, can be catastrophic, as comparisons will yield wrong results. -Wsign-compare is turned on specifically to catch this, but this tends to result in a great number of warnings when mixing signed and unsigned, and the casts are annoying. More has been written on this elsewhere. -- All such quantity types just mentioned boil down to EMACS_INT, which is 32 bits on 32-bit machines and 64 bits on 64-bit machines. This is guaranteed to be the same size as Lisp objects of type `int', and (as far as I can tell) of size_t (unsigned!) and ssize_t. The only type below that is not an EMACS_INT is Hashcode, which is an unsigned value of the same size as EMACS_INT. -- Type names should be relatively short (no more than 10 characters or so), with the first letter capitalized and no underscores if they can at all be avoided. -- "count" == a zero-based measurement of some quantity. Includes sizes, offsets, and indexes. -- "bpos" == a one-based measurement of a position in a buffer. "Charbpos" and "Bytebpos" count text in the buffer, rather than bytes in memory; thus Bytebpos does not directly correspond to the memory representation. Use "Membpos" for this. -- "Char" refers to internal-format characters, not to the C type "char", which is really a byte. -- For the actual name changes, see the script below. I ran the following script to do the conversion. (NOTE: This script is idempotent. You can safely run it multiple times and it will not screw up previous results -- in fact, it will do nothing if nothing has changed. Thus, it can be run repeatedly as necessary to handle patches coming in from old workspaces, or old branches.) There are two tags, just before and just after the change: `pre-integral-type-rename' and `post-integral-type-rename'. When merging code from the main trunk into a branch, the best thing to do is first merge up to `pre-integral-type-rename', then apply the script and associated changes, then merge from `post-integral-type-change' to the present. (Alternatively, just do the merging in one operation; but you may then have a lot of conflicts needing to be resolved by hand.) Script `fixtypes.sh' follows: ----------------------------------- cut ------------------------------------ files="*.[ch] s/*.h m/*.h config.h.in ../configure.in Makefile.in.in ../lib-src/*.[ch] ../lwlib/*.[ch]" gr Memory_Count Bytecount $files gr Lstream_Data_Count Bytecount $files gr Element_Count Elemcount $files gr Hash_Code Hashcode $files gr extcount bytecount $files gr bufpos charbpos $files gr bytind bytebpos $files gr memind membpos $files gr bufbyte intbyte $files gr Extcount Bytecount $files gr Bufpos Charbpos $files gr Bytind Bytebpos $files gr Memind Membpos $files gr Bufbyte Intbyte $files gr EXTCOUNT BYTECOUNT $files gr BUFPOS CHARBPOS $files gr BYTIND BYTEBPOS $files gr MEMIND MEMBPOS $files gr BUFBYTE INTBYTE $files gr MEMORY_COUNT BYTECOUNT $files gr LSTREAM_DATA_COUNT BYTECOUNT $files gr ELEMENT_COUNT ELEMCOUNT $files gr HASH_CODE HASHCODE $files ----------------------------------- cut ------------------------------------ `fixtypes.sh' is a Bourne-shell script; it uses 'gr': ----------------------------------- cut ------------------------------------ #!/bin/sh # Usage is like this: # gr FROM TO FILES ... # globally replace FROM with TO in FILES. FROM and TO are regular expressions. # backup files are stored in the `backup' directory. from="$1" to="$2" shift 2 echo ${1+"$@"} | xargs global-replace "s/$from/$to/g" ----------------------------------- cut ------------------------------------ `gr' in turn uses a Perl script to do its real work, `global-replace', which follows: ----------------------------------- cut ------------------------------------ : #-*- Perl -*- ### global-modify --- modify the contents of a file by a Perl expression ## Copyright (C) 1999 Martin Buchholz. ## Copyright (C) 2001 Ben Wing. ## Authors: Martin Buchholz <martin@xemacs.org>, Ben Wing <ben@xemacs.org> ## Maintainer: Ben Wing <ben@xemacs.org> ## Current Version: 1.0, May 5, 2001 # This program 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. # # This program 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 XEmacs; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. eval 'exec perl -w -S $0 ${1+"$@"}' if 0; use strict; use FileHandle; use Carp; use Getopt::Long; use File::Basename; (my $myName = $0) =~ s@.*/@@; my $usage=" Usage: $myName [--help] [--backup-dir=DIR] [--line-mode] [--hunk-mode] PERLEXPR FILE ... Globally modify a file, either line by line or in one big hunk. Typical usage is like this: [with GNU print, GNU xargs: guaranteed to handle spaces, quotes, etc. in file names] find . -name '*.[ch]' -print0 | xargs -0 $0 's/\bCONST\b/const/g'\n [with non-GNU print, xargs] find . -name '*.[ch]' -print | xargs $0 's/\bCONST\b/const/g'\n The file is read in, either line by line (with --line-mode specified) or in one big hunk (with --hunk-mode specified; it's the default), and the Perl expression is then evalled with \$_ set to the line or hunk of text, including the terminating newline if there is one. It should destructively modify the value there, storing the changed result in \$_. Files in which any modifications are made are backed up to the directory specified using --backup-dir, or to `backup' by default. To disable this, use --backup-dir= with no argument. Hunk mode is the default because it is MUCH MUCH faster than line-by-line. Use line-by-line only when it matters, e.g. you want to do a replacement only once per line (the default without the `g' argument). Conversely, when using hunk mode, *ALWAYS* use `g'; otherwise, you will only make one replacement in the entire file! "; my %options = (); $Getopt::Long::ignorecase = 0; &GetOptions ( \%options, 'help', 'backup-dir=s', 'line-mode', 'hunk-mode', ); die $usage if $options{"help"} or @ARGV <= 1; my $code = shift; die $usage if grep (-d || ! -w, @ARGV); sub SafeOpen { open ((my $fh = new FileHandle), $_[0]); confess "Can't open $_[0]: $!" if ! defined $fh; return $fh; } sub SafeClose { close $_[0] or confess "Can't close $_[0]: $!"; } sub FileContents { my $fh = SafeOpen ("< $_[0]"); my $olddollarslash = $/; local $/ = undef; my $contents = <$fh>; $/ = $olddollarslash; return $contents; } sub WriteStringToFile { my $fh = SafeOpen ("> $_[0]"); binmode $fh; print $fh $_[1] or confess "$_[0]: $!\n"; SafeClose $fh; } foreach my $file (@ARGV) { my $changed_p = 0; my $new_contents = ""; if ($options{"line-mode"}) { my $fh = SafeOpen $file; while (<$fh>) { my $save_line = $_; eval $code; $changed_p = 1 if $save_line ne $_; $new_contents .= $_; } } else { my $orig_contents = $_ = FileContents $file; eval $code; if ($_ ne $orig_contents) { $changed_p = 1; $new_contents = $_; } } if ($changed_p) { my $backdir = $options{"backup-dir"}; $backdir = "backup" if !defined ($backdir); if ($backdir) { my ($name, $path, $suffix) = fileparse ($file, ""); my $backfulldir = $path . $backdir; my $backfile = "$backfulldir/$name"; mkdir $backfulldir, 0755 unless -d $backfulldir; print "modifying $file (original saved in $backfile)\n"; rename $file, $backfile; } WriteStringToFile ($file, $new_contents); } } ----------------------------------- cut ------------------------------------ In addition to those programs, I needed to fix up a few other things, particularly relating to the duplicate definitions of types, now that some types merged with others. Specifically: 1. in lisp.h, removed duplicate declarations of Bytecount. The changed code should now look like this: (In each code snippet below, the first and last lines are the same as the original, as are all lines outside of those lines. That allows you to locate the section to be replaced, and replace the stuff in that section, verifying that there isn't anything new added that would need to be kept.) --------------------------------- snip ------------------------------------- /* Counts of bytes or chars */ typedef EMACS_INT Bytecount; typedef EMACS_INT Charcount; /* Counts of elements */ typedef EMACS_INT Elemcount; /* Hash codes */ typedef unsigned long Hashcode; /* ------------------------ dynamic arrays ------------------- */ --------------------------------- snip ------------------------------------- 2. in lstream.h, removed duplicate declaration of Bytecount. Rewrote the comment about this type. The changed code should now look like this: --------------------------------- snip ------------------------------------- #endif /* The have been some arguments over the what the type should be that specifies a count of bytes in a data block to be written out or read in, using Lstream_read(), Lstream_write(), and related functions. Originally it was long, which worked fine; Martin "corrected" these to size_t and ssize_t on the grounds that this is theoretically cleaner and is in keeping with the C standards. Unfortunately, this practice is horribly error-prone due to design flaws in the way that mixed signed/unsigned arithmetic happens. In fact, by doing this change, Martin introduced a subtle but fatal error that caused the operation of sending large mail messages to the SMTP server under Windows to fail. By putting all values back to be signed, avoiding any signed/unsigned mixing, the bug immediately went away. The type then in use was Lstream_Data_Count, so that it be reverted cleanly if a vote came to that. Now it is Bytecount. Some earlier comments about why the type must be signed: This MUST BE SIGNED, since it also is used in functions that return the number of bytes actually read to or written from in an operation, and these functions can return -1 to signal error. Note that the standard Unix read() and write() functions define the count going in as a size_t, which is UNSIGNED, and the count going out as an ssize_t, which is SIGNED. This is a horrible design flaw. Not only is it highly likely to lead to logic errors when a -1 gets interpreted as a large positive number, but operations are bound to fail in all sorts of horrible ways when a number in the upper-half of the size_t range is passed in -- this number is unrepresentable as an ssize_t, so code that checks to see how many bytes are actually written (which is mandatory if you are dealing with certain types of devices) will get completely screwed up. --ben */ typedef enum lstream_buffering --------------------------------- snip ------------------------------------- 3. in dumper.c, there are four places, all inside of switch() statements, where XD_BYTECOUNT appears twice as a case tag. In each case, the two case blocks contain identical code, and you should *REMOVE THE SECOND* and leave the first.
author ben
date Thu, 20 Sep 2001 06:31:11 +0000
parents 023b83f4e54b
children 685b588e92d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
1 /* Utility routines for XEmacs on Windows 9x, NT and Cygwin.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
2 Copyright (C) 2000 Ben Wing.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
3
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
4 This file is part of XEmacs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
5
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
9 later version.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
10
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
14 for more details.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
15
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to the Free
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
19 02111-1307, USA. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
20
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
21 #include <config.h>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
22 #include "lisp.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
23
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
24 #include "buffer.h"
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
25
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
26 #include "syssignal.h"
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
27 #include "systime.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
28 #include "syswindows.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
29
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
30 typedef BOOL (WINAPI *pfSwitchToThread_t) (VOID);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
31 pfSwitchToThread_t xSwitchToThread;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
32
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
33 typedef HKL (WINAPI *pfGetKeyboardLayout_t) (DWORD);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
34 pfGetKeyboardLayout_t xGetKeyboardLayout;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
35 typedef BOOL (WINAPI *pfSetMenuDefaultItem_t) (HMENU, UINT, UINT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
36 pfSetMenuDefaultItem_t xSetMenuDefaultItem;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
37 typedef BOOL (WINAPI *pfInsertMenuItemA_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
38 (HMENU, UINT, BOOL, LPCMENUITEMINFOA);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
39 pfInsertMenuItemA_t xInsertMenuItemA;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
40 typedef BOOL (WINAPI *pfInsertMenuItemW_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
41 (HMENU, UINT, BOOL, LPCMENUITEMINFOW);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
42 pfInsertMenuItemW_t xInsertMenuItemW;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
43 typedef HANDLE (WINAPI *pfLoadImageA_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
44 (HINSTANCE, LPCSTR, UINT, int, int, UINT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
45 pfLoadImageA_t xLoadImageA;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
46 typedef HANDLE (WINAPI *pfLoadImageW_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
47 (HINSTANCE, LPCWSTR, UINT, int, int, UINT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
48 pfLoadImageW_t xLoadImageW;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
49 typedef ATOM (WINAPI *pfRegisterClassExA_t) (CONST WNDCLASSEXA *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
50 pfRegisterClassExA_t xRegisterClassExA;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
51 typedef ATOM (WINAPI *pfRegisterClassExW_t) (CONST WNDCLASSEXW *);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
52 pfRegisterClassExW_t xRegisterClassExW;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
53
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
54 typedef int (WINAPI *pfEnumFontFamiliesExA_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
55 (HDC, LPLOGFONTA, FONTENUMPROCA, LPARAM, DWORD);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
56 pfEnumFontFamiliesExA_t xEnumFontFamiliesExA;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
57 typedef int (WINAPI *pfEnumFontFamiliesExW_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
58 (HDC, LPLOGFONTW, FONTENUMPROCW, LPARAM, DWORD);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
59 pfEnumFontFamiliesExW_t xEnumFontFamiliesExW;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
60
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
61 typedef DWORD (WINAPI *pfSHGetFileInfoA_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
62 (LPCSTR, DWORD, SHFILEINFOA FAR *, UINT, UINT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
63 pfSHGetFileInfoA_t xSHGetFileInfoA;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
64 typedef DWORD (WINAPI *pfSHGetFileInfoW_t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
65 (LPCWSTR, DWORD, SHFILEINFOW FAR *, UINT, UINT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
66 pfSHGetFileInfoW_t xSHGetFileInfoW;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
67
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
68 typedef NET_API_STATUS (NET_API_FUNCTION *pfNetUserEnum_t)
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
69 (
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
70 IN LPCWSTR servername OPTIONAL,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
71 IN DWORD level,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
72 IN DWORD filter,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
73 OUT LPBYTE *bufptr,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
74 IN DWORD prefmaxlen,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
75 OUT LPDWORD entriesread,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
76 OUT LPDWORD totalentries,
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
77 IN OUT LPDWORD resume_handle OPTIONAL
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
78 );
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
79 pfNetUserEnum_t xNetUserEnum;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
80
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
81 typedef NET_API_STATUS (NET_API_FUNCTION *pfNetApiBufferFree_t)
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
82 (
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
83 IN LPVOID Buffer
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
84 );
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
85 pfNetApiBufferFree_t xNetApiBufferFree;
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
86
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
87 Lisp_Object
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
88 tstr_to_local_file_format (Extbyte *pathout)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
89 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 613
diff changeset
90 Intbyte *ttlff;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
91 Lisp_Object in;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
92
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
93 EXTERNAL_TO_C_STRING (pathout, ttlff, Qmswindows_tstr);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
94 WIN32_TO_LOCAL_FILE_FORMAT (ttlff, in);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
95
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
96 return in;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
97 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
98
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
99 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
100 init_potentially_nonexistent_functions (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
101 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
102 HMODULE h_kernel = GetModuleHandle ("kernel32");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
103 HMODULE h_user = GetModuleHandle ("user32");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
104 HMODULE h_gdi = GetModuleHandle ("gdi32");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
105 HMODULE h_shell = GetModuleHandle ("shell32");
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
106 /* the following does not seem to get mapped in automatically */
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
107 HMODULE h_netapi = LoadLibrary ("netapi32.dll");
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
108
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
109 if (h_kernel)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
110 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
111 xSwitchToThread =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
112 (pfSwitchToThread_t) GetProcAddress (h_kernel, "SwitchToThread");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
113 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
114
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
115 if (h_user)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
116 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
117 xGetKeyboardLayout =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
118 (pfGetKeyboardLayout_t) GetProcAddress (h_user, "GetKeyboardLayout");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
119 xSetMenuDefaultItem =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
120 (pfSetMenuDefaultItem_t) GetProcAddress (h_user, "SetMenuDefaultItem");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
121 xInsertMenuItemA =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
122 (pfInsertMenuItemA_t) GetProcAddress (h_user, "InsertMenuItemA");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
123 xInsertMenuItemW =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
124 (pfInsertMenuItemW_t) GetProcAddress (h_user, "InsertMenuItemW");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
125 xLoadImageA =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
126 (pfLoadImageA_t) GetProcAddress (h_user, "LoadImageA");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
127 xLoadImageW =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
128 (pfLoadImageW_t) GetProcAddress (h_user, "LoadImageW");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
129 xRegisterClassExA =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
130 (pfRegisterClassExA_t) GetProcAddress (h_user, "RegisterClassExA");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
131 xRegisterClassExW =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
132 (pfRegisterClassExW_t) GetProcAddress (h_user, "RegisterClassExW");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
133 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
134
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
135 if (h_gdi)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
136 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
137 xEnumFontFamiliesExA =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
138 (pfEnumFontFamiliesExA_t) GetProcAddress (h_gdi, "EnumFontFamiliesExA");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
139 xEnumFontFamiliesExW =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
140 (pfEnumFontFamiliesExW_t) GetProcAddress (h_gdi, "EnumFontFamiliesExW");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
141 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
142
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
143 if (h_shell)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
144 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
145 xSHGetFileInfoA =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
146 (pfSHGetFileInfoA_t) GetProcAddress (h_shell, "SHGetFileInfoA");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
147 xSHGetFileInfoW =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
148 (pfSHGetFileInfoW_t) GetProcAddress (h_shell, "SHGetFileInfoW");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
149 }
531
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
150
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
151 if (h_netapi)
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
152 {
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
153 xNetUserEnum =
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
154 (pfNetUserEnum_t) GetProcAddress (h_netapi, "NetUserEnum");
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
155 xNetApiBufferFree =
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
156 (pfNetApiBufferFree_t) GetProcAddress (h_netapi, "NetApiBufferFree");
0493e9f3c27f [xemacs-hg @ 2001-05-12 11:16:12 by ben]
ben
parents: 442
diff changeset
157 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
158 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
159
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
160 DEFUN ("mswindows-shell-execute", Fmswindows_shell_execute, 2, 4, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
161 Get Windows to perform OPERATION on DOCUMENT.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
162 This is a wrapper around the ShellExecute system function, which
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
163 invokes the application registered to handle OPERATION for DOCUMENT.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
164 OPERATION is typically \"open\", \"print\" or \"explore\" (but can be
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
165 nil for the default action), and DOCUMENT is typically the name of a
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
166 document file or URL, but can also be a program executable to run or
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
167 a directory to open in the Windows Explorer.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
168
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
169 If DOCUMENT is a program executable, PARAMETERS can be a string
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
170 containing command line parameters, but otherwise should be nil.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
171
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
172 SHOW-FLAG can be used to control whether the invoked application is hidden
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
173 or minimized. If SHOW-FLAG is nil, the application is displayed normally,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
174 otherwise it is an integer representing a ShowWindow flag:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
175
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
176 0 - start hidden
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
177 1 - start normally
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
178 3 - start maximized
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
179 6 - start minimized
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
180 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
181 (operation, document, parameters, show_flag))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
182 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
183 /* Encode filename and current directory. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
184 Lisp_Object current_dir = Ffile_name_directory (document);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
185 char* path = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
186 char* doc = NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
187 Extbyte* f=0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
188 int ret;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
189 struct gcpro gcpro1, gcpro2;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
190
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
191 CHECK_STRING (document);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
192
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
193 if (NILP (current_dir))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
194 current_dir = current_buffer->directory;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
195
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
196 GCPRO2 (current_dir, document);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
197
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
198 /* Use mule and cygwin-safe APIs top get at file data. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
199 if (STRINGP (current_dir))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
200 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
201 TO_EXTERNAL_FORMAT (LISP_STRING, current_dir,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
202 C_STRING_ALLOCA, f,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
203 Qfile_name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
204 #ifdef CYGWIN
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
205 CYGWIN_WIN32_PATH (f, path);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
206 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
207 path = f;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
208 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
209 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
210
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
211 if (STRINGP (document))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
212 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
213 TO_EXTERNAL_FORMAT (LISP_STRING, document,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
214 C_STRING_ALLOCA, f,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
215 Qfile_name);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
216 #ifdef CYGWIN
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
217 CYGWIN_WIN32_PATH (f, doc);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
218 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
219 doc = f;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
220 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
221 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
222
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
223 UNGCPRO;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
224
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
225 ret = (int) ShellExecute (NULL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
226 (STRINGP (operation) ?
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 578
diff changeset
227 /* !!#### more mule bogosity */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 578
diff changeset
228 (char *) XSTRING_DATA (operation) : NULL),
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
229 doc,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
230 (STRINGP (parameters) ?
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 578
diff changeset
231 /* !!#### more mule bogosity */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 578
diff changeset
232 (char *) XSTRING_DATA (parameters) : NULL),
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
233 path,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
234 (INTP (show_flag) ?
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
235 XINT (show_flag) : SW_SHOWDEFAULT));
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
236
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
237 if (ret > 32)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
238 return Qt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
239
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
240 if (ret == ERROR_FILE_NOT_FOUND)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 531
diff changeset
241 signal_error (Qfile_error, "file not found", document);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
242 else if (ret == ERROR_PATH_NOT_FOUND)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 531
diff changeset
243 signal_error (Qfile_error, "path not found", current_dir);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
244 else if (ret == ERROR_BAD_FORMAT)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 531
diff changeset
245 signal_error (Qfile_error, "bad executable format", document);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
246 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 531
diff changeset
247 signal_error (Qinternal_error, "internal error", Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
248
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
249 return Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
250 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
251
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
252 #if defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
253
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
254 /* setitimer() does not exist on native MS Windows, and appears broken
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
255 on Cygwin (random lockups when BROKEN_SIGIO is defined), so we
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
256 emulate in both cases by using multimedia timers. Furthermore,
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
257 the lockups still occur on Cygwin even when we do nothing but
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
258 use the standard signalling mechanism -- so we have to emulate
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
259 that, too. (But only for timeouts -- we have to use the standard
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
260 mechanism for SIGCHLD. Yuck.)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
261 */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
262
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
263
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
264 /*--------------------------------------------------------------------*/
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
265 /* Signal support */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
266 /*--------------------------------------------------------------------*/
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
267
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
268 #define sigmask(nsig) (1U << nsig)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
269
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
270 /* We can support as many signals as fit into word */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
271 #define SIG_MAX 32
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
272
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
273 /* Signal handlers. Initial value = 0 = SIG_DFL */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
274 static mswindows_sighandler signal_handlers[SIG_MAX] = {0};
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
275
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
276 /* Signal block mask: bit set to 1 means blocked */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
277 unsigned signal_block_mask = 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
278
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
279 /* Signal pending mask: bit set to 1 means sig is pending */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
280 unsigned signal_pending_mask = 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
281
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
282 mswindows_sighandler
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
283 mswindows_sigset (int nsig, mswindows_sighandler handler)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
284 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
285 /* We delegate some signals to the system function */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
286 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
287 return signal (nsig, handler);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
288
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
289 if (nsig < 0 || nsig > SIG_MAX)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
290 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
291 errno = EINVAL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
292 return NULL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
293 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
294
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
295 /* Store handler ptr */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
296 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
297 mswindows_sighandler old_handler = signal_handlers[nsig];
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
298 signal_handlers[nsig] = handler;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
299 return old_handler;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
300 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
301 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
302
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
303 int
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
304 mswindows_sighold (int nsig)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
305 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
306 if (nsig < 0 || nsig > SIG_MAX)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
307 return errno = EINVAL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
308
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
309 signal_block_mask |= sigmask (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
310 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
311 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
312
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
313 int
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
314 mswindows_sigrelse (int nsig)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
315 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
316 if (nsig < 0 || nsig > SIG_MAX)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
317 return errno = EINVAL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
318
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
319 signal_block_mask &= ~sigmask (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
320
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
321 if (signal_pending_mask & sigmask (nsig))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
322 mswindows_raise (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
323
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
324 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
325 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
326
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
327 int
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
328 mswindows_sigpause (int nsig)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
329 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
330 /* This is currently not called, because the only call to sigpause
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
331 inside XEmacs is with SIGCHLD parameter. Just in case, we put an
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
332 assert here, so anyone adds a call to sigpause will be surprised
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
333 (or surprise someone else...) */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
334 assert (0);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
335 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
336 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
337
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
338 int
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
339 mswindows_raise (int nsig)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
340 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
341 /* We delegate some raises to the system routine */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
342 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
343 return raise (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
344
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
345 if (nsig < 0 || nsig > SIG_MAX)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
346 return errno = EINVAL;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
347
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
348 /* If the signal is blocked, remember to issue later */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
349 if (signal_block_mask & sigmask (nsig))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
350 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
351 signal_pending_mask |= sigmask (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
352 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
353 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
354
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
355 if (signal_handlers[nsig] == SIG_IGN)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
356 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
357
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
358 if (signal_handlers[nsig] != SIG_DFL)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
359 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
360 (*signal_handlers[nsig]) (nsig);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
361 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
362 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
363
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
364 /* Default signal actions */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
365 if (nsig == SIGALRM || nsig == SIGPROF)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
366 exit (3);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
367
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
368 /* Other signals are ignored by default */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
369 return 0;
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
370 }
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
371
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
372
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
373 /*--------------------------------------------------------------------*/
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
374 /* Async timers */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
375 /*--------------------------------------------------------------------*/
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
376
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
377 /* We emulate two timers, one for SIGALRM, another for SIGPROF.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
378
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
379 itimerproc() function has an implementation limitation: it does
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
380 not allow to set *both* interval and period. If an attempt is
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
381 made to set both, and then they are unequal, the function
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
382 asserts.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
383
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
384 Minimum timer resolution on Win32 systems varies, and is greater
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
385 than or equal than 1 ms. The resolution is always wrapped not to
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
386 attempt to get below the system defined limit.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
387 */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
388
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
389 /* Timer precision, denominator of one fraction: for 100 ms
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
390 interval, request 10 ms precision
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
391 */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
392 const int setitimer_helper_timer_prec = 10;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
393
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
394 /* Last itimervals, as set by calls to setitimer */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
395 static struct itimerval it_alarm;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
396 static struct itimerval it_prof;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
397
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
398 /* Timer IDs as returned by MM */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
399 MMRESULT tid_alarm = 0;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
400 MMRESULT tid_prof = 0;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
401
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
402 static void CALLBACK
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
403 setitimer_helper_proc (UINT uID, UINT uMsg, DWORD dwUser,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
404 DWORD dw1, DWORD dw2)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
405 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
406 /* Just raise the signal indicated by the dwUser parameter */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
407 mswindows_raise (dwUser);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
408 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
409
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
410 /* Divide time in ms specified by IT by DENOM. Return 1 ms
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
411 if division results in zero */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
412 static UINT
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
413 setitimer_helper_period (const struct itimerval* it, UINT denom)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
414 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
415 static TIMECAPS time_caps;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
416
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
417 UINT res;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
418 const struct timeval* tv =
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
419 (it->it_value.tv_sec == 0 && it->it_value.tv_usec == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
420 ? &it->it_interval : &it->it_value;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
421
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
422 /* Zero means stop timer */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
423 if (tv->tv_sec == 0 && tv->tv_usec == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
424 return 0;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
425
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
426 /* Convert to ms and divide by denom */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
427 res = (tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000) / denom;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
428
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
429 /* Converge to minimum timer resolution */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
430 if (time_caps.wPeriodMin == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
431 timeGetDevCaps (&time_caps, sizeof(time_caps));
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
432
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
433 if (res < time_caps.wPeriodMin)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
434 res = time_caps.wPeriodMin;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
435
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
436 return res;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
437 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
438
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
439 static int
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
440 setitimer_helper (const struct itimerval* itnew,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
441 struct itimerval* itold, struct itimerval* itcurrent,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
442 MMRESULT* tid, DWORD sigkind)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
443 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
444 UINT delay, resolution, event_type;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
445
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
446 /* First stop the old timer */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
447 if (*tid)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
448 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
449 timeKillEvent (*tid);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
450 timeEndPeriod (setitimer_helper_period (itcurrent,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
451 setitimer_helper_timer_prec));
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
452 *tid = 0;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
453 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
454
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
455 /* Return old itimerval if requested */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
456 if (itold)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
457 *itold = *itcurrent;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
458
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
459 *itcurrent = *itnew;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
460
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
461 /* Determine if to start new timer */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
462 delay = setitimer_helper_period (itnew, 1);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
463 if (delay)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
464 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
465 resolution = setitimer_helper_period (itnew,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
466 setitimer_helper_timer_prec);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
467 event_type = (itnew->it_value.tv_sec == 0 &&
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
468 itnew->it_value.tv_usec == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
469 ? TIME_ONESHOT : TIME_PERIODIC;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
470 timeBeginPeriod (resolution);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
471 *tid = timeSetEvent (delay, resolution, setitimer_helper_proc, sigkind,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
472 event_type);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
473 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
474
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
475 return !delay || *tid;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
476 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
477
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
478 int
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
479 mswindows_setitimer (int kind, const struct itimerval *itnew,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
480 struct itimerval *itold)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
481 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
482 /* In this version, both interval and value are allowed
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
483 only if they are equal. */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
484 assert ((itnew->it_value.tv_sec == 0 && itnew->it_value.tv_usec == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
485 || (itnew->it_interval.tv_sec == 0 &&
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
486 itnew->it_interval.tv_usec == 0)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
487 || (itnew->it_value.tv_sec == itnew->it_interval.tv_sec &&
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
488 itnew->it_value.tv_usec == itnew->it_interval.tv_usec));
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
489
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
490 if (kind == ITIMER_REAL)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
491 return setitimer_helper (itnew, itold, &it_alarm, &tid_alarm, SIGALRM);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
492 else if (kind == ITIMER_PROF)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
493 return setitimer_helper (itnew, itold, &it_prof, &tid_prof, SIGPROF);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
494 else
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
495 return errno = EINVAL;
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
496 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
497
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
498 #endif /* defined (WIN32_NATIVE) || defined (CYGWIN_BROKEN_SIGNALS) */
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
499
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
500
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
501 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
502 syms_of_win32 (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
503 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
504 DEFSUBR (Fmswindows_shell_execute);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
505 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
506
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
507 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
508 init_win32 (void)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
509 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
510 init_potentially_nonexistent_functions ();
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents:
diff changeset
511 }