Mercurial > hg > xemacs-beta
annotate lisp/win32-native.el @ 5820:b3824b7f5627
Some changes to eliminate warnings with Apple clang version 1.7.
src/ChangeLog addition:
2014-10-18 Aidan Kehoe <kehoea@parhasard.net>
Some changes to eliminate warnings with Apple clang version 1.7.
* cm.c (send_string_to_tty_console):
* doprnt.c (doprnt_2):
* doprnt.c (parse_off_posnum):
* event-stream.c (dribble_out_event):
Cast various calls to Lstream_putc() to void when the result isn't
being used, for the sake of clang.
* lisp.h:
Declare #'replace here too, it's used in event-stream.c.
* lisp.h (ALLOCA):
* lisp.h (MALLOC_OR_ALLOCA):
Cast a couple of zeros in the context of the ternary operator to
void to prevent unused value warnings with clang.
* sysdep.c (child_setup_tty):
* text.h (ASSERT_ASCTEXT_ASCII_LEN):
Use DO_NOTHING in these files to quieten the compiler.
lib-src/ChangeLog addition:
2014-10-18 Aidan Kehoe <kehoea@parhasard.net>
* ootags.c (substitute):
Cast the result of strlen to int before comparing it with a signed
value, for the sake of compiler warnings.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Sat, 18 Oct 2014 21:48:10 +0100 |
| parents | 308d34e9f07d |
| children |
| rev | line source |
|---|---|
| 611 | 1 ;;; win32-native.el --- Lisp routines when running on native MS Windows. |
| 442 | 2 |
| 3 ;; Copyright (C) 1994 Free Software Foundation, Inc. | |
| 2367 | 4 ;; Copyright (C) 2000, 2004 Ben Wing. |
| 442 | 5 |
| 6 ;; Maintainer: XEmacs Development Team | |
| 7 ;; Keywords: mouse, dumped | |
| 8 | |
| 9 ;; This file is part of XEmacs. | |
| 10 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
11 ;; XEmacs is free software: you can redistribute it and/or modify it |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
12 ;; under the terms of the GNU General Public License as published by the |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
13 ;; Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
14 ;; option) any later version. |
| 442 | 15 |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
16 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
18 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
19 ;; for more details. |
| 442 | 20 |
| 21 ;; You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2367
diff
changeset
|
22 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
| 442 | 23 |
| 611 | 24 ;;; Synched up with: Not in FSF. |
| 442 | 25 ;;; (FSF has stuff in w32-fns.el and term/w32-win.el.) |
| 26 | |
| 27 ;;; Commentary: | |
| 28 | |
| 29 ;; This file is dumped with XEmacs for MS Windows (without cygwin). | |
| 611 | 30 ;; It is for stuff that is used specifically when `system-type' eq |
| 31 ;; `windows-nt' (i.e. also applies to MinGW), and has nothing to do | |
| 32 ;; with the `mswindows' device type. Thus, it probably applies in | |
| 33 ;; non-interactive mode as well, and it DOES NOT APPLY to Cygwin. | |
| 442 | 34 |
| 611 | 35 ;; Based (originally) on NT Emacs version by Geoff Voelker |
| 36 ;; (voelker@cs.washington.edu) | |
| 442 | 37 ;; Ported to XEmacs by Marc Paquette <marcpa@cam.org> |
| 38 ;; Largely modified by Kirill M. Katsnelson <kkm@kis.ru> | |
| 611 | 39 ;; Rewritten from scratch by Ben Wing <ben@xemacs.org>. No code in common |
| 40 ;; with FSF. | |
| 442 | 41 |
| 42 ;;; Code: | |
| 43 | |
| 44 ;; For appending suffixes to directories and files in shell | |
| 45 ;; completions. This screws up cygwin users so we leave it out for | |
| 46 ;; now. Uncomment this if you only ever want to use cmd. | |
| 47 | |
| 48 ;(defun nt-shell-mode-hook () | |
| 49 ; (setq comint-completion-addsuffix '("\\" . " ") | |
| 50 ; comint-process-echoes t)) | |
| 51 ;(add-hook 'shell-mode-hook 'nt-shell-mode-hook) | |
| 52 | |
| 53 ;; Use ";" instead of ":" as a path separator (from files.el). | |
| 54 (setq path-separator ";") | |
| 55 | |
| 56 ;; Set the grep regexp to match entries with drive letters. | |
| 776 | 57 (defvar grep-regexp-alist) |
| 442 | 58 (setq grep-regexp-alist |
| 59 '(("^\\(\\([a-zA-Z]:\\)?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 3))) | |
| 60 | |
| 611 | 61 (defvar mswindows-system-shells '("cmd" "cmd.exe" "command" "command.com" |
| 62 "4nt" "4nt.exe" "4dos" "4dos.exe" | |
| 63 "ndos" "ndos.exe") | |
| 64 "List of strings recognized as Windows NT/9X system shells. | |
| 65 These are shells with native semantics, e.g. they use `/c', not '-c', | |
| 66 to pass a command in.") | |
| 67 | |
| 68 (defun mswindows-system-shell-p (shell-name) | |
| 69 (member (downcase (file-name-nondirectory shell-name)) | |
| 70 mswindows-system-shells)) | |
| 71 | |
| 72 (defun init-mswindows-at-startup () | |
| 73 ;; shell-file-name is initialized in the C code (callproc.c) from | |
| 74 ;; SHELL or COMSPEC. | |
| 75 ;; #### If only shell-command-switch could be a function. But there | |
| 76 ;; is code littered around that uses it. | |
| 77 ;; #### Maybe we should set a symbol-value handler on `shell-file-name' | |
| 78 ;; that automatically sets shell-command-switch? | |
| 79 (if (mswindows-system-shell-p shell-file-name) | |
| 80 (setq shell-command-switch "/c"))) | |
| 81 | |
| 2367 | 82 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 83 ;; ;; | |
| 84 ;; Quoting process args ;; | |
| 85 ;; ;; | |
| 86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 87 | |
| 88 ;; Converting a bunch of args into a single command line or vice-versa is | |
| 89 ;; extremely hairy due to the quoting conventions needed. There is in fact | |
| 90 ;; code that does this in the CRT, and perhaps we should look at it and | |
| 91 ;; follow the logic. | |
| 92 | |
| 93 ;; Here is some further info from MSDN, discovered *AFTER* the actual code | |
| 94 ;; below was written, and hence the code may not follow what it should. | |
| 95 ;; !!#### But this is definitely something to be fixed up. The article is | |
| 96 ;; called "Parsing C++ Command-Line Arguments", Visual Tools and Langs -> | |
| 97 ;; Visual Studio -> Visual C++ -> Reference -> C/C++ Lang and ... -> C++ | |
| 98 ;; Lang Ref -> Basic Concepts -> Startup and Termination -> Program | |
| 99 ;; Startup: the main Function. | |
| 100 | |
| 101 ;; Microsoft Specific | |
| 102 ;; | |
| 103 ;; Microsoft C/C++ startup code uses the following rules when interpreting | |
| 104 ;; arguments given on the operating system command line: | |
| 105 ;; | |
| 106 ;; Arguments are delimited by white space, which is either a space or a tab. | |
| 107 ;; | |
| 108 ;; The caret character (^) is not recognized as an escape character or | |
| 109 ;; delimiter. The character is handled completely by the command-line parser | |
| 110 ;; in the operating system before being passed to the argv array in the | |
| 111 ;; program. | |
| 112 ;; | |
| 113 ;; A string surrounded by double quotation marks ("string") is interpreted as | |
| 114 ;; a single argument, regardless of white space contained within. A quoted | |
| 115 ;; string can be embedded in an argument. | |
| 116 ;; | |
| 117 ;; A double quotation mark preceded by a backslash ( \") is interpreted as a | |
| 118 ;; literal double quotation mark character ("). | |
| 119 ;; | |
| 120 ;; Backslashes are interpreted literally, unless they immediately precede a | |
| 121 ;; double quotation mark. | |
| 122 ;; | |
| 123 ;; If an even number of backslashes is followed by a double quotation mark, | |
| 124 ;; one backslash is placed in the argv array for every pair of backslashes, | |
| 125 ;; and the double quotation mark is interpreted as a string delimiter. | |
| 126 ;; | |
| 127 ;; If an odd number of backslashes is followed by a double quotation mark, one | |
| 128 ;; backslash is placed in the argv array for every pair of backslashes, and | |
| 129 ;; the double quotation mark is "escaped" by the remaining backslash, | |
| 130 ;; causing a literal double quotation mark (") to be placed in argv. | |
| 131 ;; | |
| 132 ;; The following program demonstrates how command-line arguments are passed: | |
| 133 ;; | |
| 134 ;; include <iostream.h> | |
| 135 ;; | |
| 136 ;; void main( int argc, // Number of strings in array argv | |
| 137 ;; char *argv[], // Array of command-line argument strings | |
| 138 ;; char *envp[] ) // Array of environment variable strings | |
| 139 ;; { | |
| 140 ;; int count; | |
| 141 ;; | |
| 142 ;; // Display each command-line argument. | |
| 143 ;; cout << "\nCommand-line arguments:\n"; | |
| 144 ;; for( count = 0; count < argc; count++ ) | |
| 145 ;; cout << " argv[" << count << "] " | |
| 146 ;; << argv[count] << "\n"; | |
| 147 ;; } | |
| 148 ;; | |
| 149 ;; Table 2.2 shows example input and expected output, demonstrating the rules | |
| 150 ;; in the preceding list. | |
| 151 ;; | |
| 152 ;; Table 2.2 | |
| 153 ;; | |
| 154 ;; Command-Line Input argv[1] argv[2] argv[3] | |
| 155 ;; ------------------------------------------ | |
| 156 ;; "abc" d e abc d e | |
| 157 ;; | |
| 158 ;; a\\\b d"e f"g h a\\\b de fg h | |
| 159 ;; | |
| 160 ;; a\\\"b c d a\"b c d | |
| 161 ;; | |
| 162 ;; a\\\\"b c" d e a\\b c d e | |
| 163 ;; | |
| 164 ;; END Microsoft Specific | |
| 165 ;; | |
| 166 ;; note: for pulling apart an arg: | |
| 167 ;; each arg consists of either | |
| 168 | |
| 169 ;; something surrounded by single quotes | |
| 170 | |
| 171 ;; or | |
| 172 | |
| 173 ;; one or more of | |
| 174 | |
| 175 ;; 1. a non-ws, non-" char | |
| 176 ;; 2. a section of double-quoted text | |
| 177 ;; 3. a section of double-quoted text with end-of-string instead of the final | |
| 178 ;; quote. | |
| 179 | |
| 180 ;; 2 and 3 get handled together. | |
| 181 | |
| 182 ;; quoted text is one of | |
| 183 ;; | |
| 184 ;; 1. quote + even number of backslashes + quote, or | |
| 185 ;; 2. quote + non-greedy anything + non-backslash + even number of | |
| 186 ;; backslashes + quote. | |
| 187 | |
| 188 ;; we need to separate the two because we unfortunately have no non-greedy | |
| 189 ;; ? operator. (urk! we actually do, but it wasn't documented.) --ben | |
| 190 | |
| 191 ;; if you want to mess around, keep this test case in mind: | |
| 192 | |
| 193 ;; this string | |
| 194 | |
| 195 ;; " as'f 'FOO BAR' '' \"\" \"asdf \\ \\\" \\\\\\\" asdfasdf\\\\\" foo\" " | |
| 196 | |
| 197 ;; should tokenize into this: | |
| 198 | |
| 199 ;; (" " "as'f" " " "'FOO BAR' " "'' " "\"\"" " " "\"asdf \\ \\\" \\\\\\\" asdfasdf\\\\\"" " " "foo" "\" ") | |
| 200 | |
| 442 | 201 |
| 202 (defvar debug-mswindows-process-command-lines nil | |
| 203 "If non-nil, output debug information about the command lines constructed. | |
| 204 This can be useful if you are getting process errors where the arguments | |
| 205 to the process appear to be getting passed incorrectly.") | |
| 206 | |
| 207 ;; properly quotify one arg for the vc runtime argv constructor. | |
| 208 (defun mswindows-quote-one-vc-runtime-arg (arg &optional quote-shell) | |
| 209 ;; we mess with any arg with whitespace, quotes, or globbing chars in it. | |
| 210 ;; we also include shell metachars if asked. | |
| 211 ;; note that \ is NOT included! it's perfectly OK to include an | |
| 212 ;; arg like c:\ or c:\foo. | |
| 611 | 213 (cond ((equal arg "") "\"\"") |
| 214 ((string-match | |
| 215 (if quote-shell "[ \t\n\r\f*?\"<>|&^%]" "[ \t\n\r\f*?\"]") | |
| 216 arg) | |
| 217 ;; handle nested quotes, possibly preceded by backslashes | |
| 218 (setq arg (replace-in-string arg "\\([\\]*\\)\"" "\\1\\1\\\\\"")) | |
| 219 ;; handle trailing backslashes | |
| 220 (setq arg (replace-in-string arg "\\([\\]+\\)$" "\\1\\1")) | |
| 221 (concat "\"" arg "\"")) | |
| 222 (t arg))) | |
| 442 | 223 |
| 224 (defun mswindows-quote-one-simple-arg (arg &optional quote-shell) | |
| 225 ;; just put double quotes around args with spaces (and maybe shell | |
| 226 ;; metachars). | |
| 611 | 227 (cond ((equal arg "") "\"\"") |
| 228 ((string-match | |
| 229 (if quote-shell "[ \t\n\r\f*?\"<>|&^%]" "[ \t\n\r\f*?]") | |
| 230 arg) | |
| 231 (concat "\"" arg "\"")) | |
| 232 (t arg))) | |
| 442 | 233 |
| 234 (defun mswindows-quote-one-command-arg (arg) | |
| 235 ;; quote an arg to get it past COMMAND.COM/CMD.EXE: need to quote shell | |
| 236 ;; metachars with ^. | |
| 611 | 237 (cond ((equal arg "") "\"\"") |
| 238 (t (replace-in-string "[<>|&^%]" "^\\1" arg)))) | |
| 442 | 239 |
| 240 (defun mswindows-construct-verbatim-command-line (program args) | |
| 241 (mapconcat #'identity args " ")) | |
| 242 | |
| 243 ;; for use with either standard VC++ compiled programs or Cygwin programs, | |
| 244 ;; which emulate the same behavior. | |
| 245 (defun mswindows-construct-vc-runtime-command-line (program args) | |
| 246 (mapconcat #'mswindows-quote-one-vc-runtime-arg args " ")) | |
| 247 | |
| 248 ;; this regexp actually separates the arg into individual args, like a | |
| 249 ;; shell (such as sh) does, but using vc-runtime rules. it's easy to | |
| 250 ;; derive the tokenizing regexp from it, and that's exactly what i did. | |
| 251 ;; but oh was it hard to get this first regexp right. --ben | |
| 252 ;(defvar mswindows-match-one-cmd-exe-arg-regexp | |
| 253 ; (concat | |
| 254 ; "^\\(" | |
| 255 ; "'\\([\\]*\\)\\2'" "\\|" | |
| 256 ; "'.*?[^\\]\\(\\([\\]*\\)\\4'\\)" "\\|" | |
| 257 ; "\\(" | |
| 258 ; "[^ \t\n\r\f\v\"]" "\\|" | |
| 259 ; "\"\\([\\]*\\)\\6\"" "\\|" | |
| 260 ; "\".*?[^\\]\\(\\([\\]*\\)\\8\"\\|$\\)" | |
| 261 ; "\\)+" | |
| 262 ; "\\)" | |
| 263 ; "\\([ \t\n\r\f\v]+\\|$\\)")) | |
| 264 | |
| 265 (defvar mswindows-match-one-cmd-exe-token-regexp | |
| 266 (concat | |
| 267 "^\\(" | |
| 268 "[ \t\n\r\f\v]+" "\\|" | |
| 269 "'\\([\\]*\\)\\2'" "\\([ \t\n\r\f\v]+\\|$\\)" "\\|" | |
| 270 "'.*?[^\\]\\(\\([\\]*\\)\\5'\\)" "\\([ \t\n\r\f\v]+\\|$\\)" "\\|" | |
| 271 "[^ \t\n\r\f\v\"]+" "\\|" | |
| 272 "\"\\([\\]*\\)\\7\"" "\\|" | |
| 273 "\".*?[^\\]\\(\\([\\]*\\)\\9\"\\|$\\)" | |
| 274 "\\)")) | |
| 275 | |
| 276 (defun mswindows-construct-command-command-line (program args) | |
| 277 ;; for use with COMMAND.COM and CMD.EXE: | |
| 278 ;; for each arg, tokenize it into quoted and non-quoted sections; | |
| 279 ;; then quote all the shell meta-chars with ^; then put everything | |
| 280 ;; back together. the truly hard part is the tokenizing -- typically | |
| 281 ;; we get a single argument (the command to execute) and we have to | |
| 282 ;; worry about quotes that are backslash-quoted and such. | |
| 283 (mapconcat | |
| 284 #'(lambda (arg) | |
| 285 (mapconcat | |
| 286 #'(lambda (part) | |
| 287 (if (string-match "^'" part) | |
| 288 (replace-in-string part "\\([<>|^&%]\\)" "^\\1") | |
| 289 part)) | |
| 290 (let (parts) | |
| 291 (while (and (> (length arg) 0) | |
| 292 (string-match | |
| 293 mswindows-match-one-cmd-exe-token-regexp | |
| 294 arg)) | |
| 295 (push (match-string 0 arg) parts) | |
| 296 (setq arg (substring arg (match-end 0)))) | |
| 297 (if (> (length arg) 0) | |
| 298 (push arg parts)) | |
| 299 (nreverse parts)) | |
| 300 "")) | |
| 301 args " ")) | |
| 302 | |
| 303 (defvar mswindows-construct-process-command-line-alist | |
| 611 | 304 '( |
| 305 ;; at one point (pre-1.0), this was required for Cygwin bash. | |
| 306 ;; evidently, Cygwin changed its arg handling to work just like | |
| 307 ;; any standard VC program, so we no longer need it. | |
| 308 ;;("[\\/].?.?sh\\." . mswindows-construct-verbatim-command-line) | |
| 442 | 309 ("[\\/]command\\.com$" . mswindows-construct-command-command-line) |
| 310 ("[\\/]cmd\\.exe$" . mswindows-construct-command-command-line) | |
| 311 ("" . mswindows-construct-vc-runtime-command-line)) | |
| 312 "An alist for determining proper argument quoting given executable | |
| 313 file name. Car of each cons should be a string, a regexp against | |
| 314 which the file name is matched. Matching is case-insensitive but does | |
| 315 include the directory, so you should begin your regexp with [\\\\/] if | |
| 316 you don't want the directory to matter. Alternatively, the car can be | |
| 317 a function of one arg, which is called with the executable's name and | |
| 318 should return t if this entry should be processed. Cdr is a function | |
| 319 symbol, which is called with two args, the executable name and a list | |
| 320 of the args passed to it. It should return a string, which includes | |
| 321 the executable's args (but not the executable name itself) properly | |
| 322 quoted and pasted together. The list is matched in order, and the | |
| 323 first matching entry specifies how the processing will happen.") | |
| 324 | |
| 325 (defun mswindows-construct-process-command-line (args) | |
| 326 ;;Properly quote process ARGS for executing (car ARGS). | |
| 327 ;;Called from the C code. | |
| 328 (let ((fname (car args)) | |
| 329 (alist mswindows-construct-process-command-line-alist) | |
| 330 (case-fold-search t) | |
| 331 (return-me nil) | |
| 332 (assoc nil)) | |
| 333 (while (and alist | |
| 334 (null return-me)) | |
| 335 (setq assoc (pop alist)) | |
| 336 (if (if (stringp (car assoc)) | |
| 337 (string-match (car assoc) fname) | |
| 338 (funcall (car assoc) fname)) | |
| 339 (setq return-me (cdr assoc)))) | |
| 340 (let* ((called-fun (or return-me | |
| 341 #'mswindows-construct-vc-runtime-command-line)) | |
| 342 (retval | |
| 343 (let ((str (funcall called-fun fname (cdr args))) | |
| 344 (quoted-fname (mswindows-quote-one-simple-arg fname))) | |
| 345 (if (and str (> (length str) 0)) | |
| 346 (concat quoted-fname " " str) | |
| 347 quoted-fname)))) | |
| 348 (when debug-mswindows-process-command-lines | |
| 349 (debug-print "mswindows-construct-process-command-line called:\n") | |
| 350 (debug-print "received args: \n%s" | |
| 351 (let ((n -1)) | |
| 352 (mapconcat #'(lambda (arg) | |
| 353 (incf n) | |
| 354 (format " %d %s\n" n arg)) | |
| 355 args | |
| 356 ""))) | |
| 357 (debug-print "called fun %s\n" called-fun) | |
| 358 (debug-print "resulting command line: %s\n" retval)) | |
| 359 retval))) | |
| 360 | |
| 361 ;;; win32-native.el ends here |
