Mercurial > emacs
annotate msdos/is_exec.c @ 72917:17942cb3949e
(allout-regexp, allout-line-boundary-regexp)
(allout-bob-regexp): Correct grouping and boundaries to fix backwards traversal.
(allout-depth-specific-regexp, allout-depth-one-regexp): New versions that
exploit \\{M\\} regexp syntax, to avoid geometric or worse time in
allout-ascend.
(allout-doublecheck-at-and-shallower): Identify depth threshold below which
topics are checked for and disqualified by containment discontinuities.
(allout-hotspot-key-handler): Correctly handle multiple-key strokes. Remove
some unused variables.
(allout-mode-leaders): Clarify that mode-specific comment-start will be used
(set-allout-regexp): Correctly regexp-quote allout regexps to properly accept
alternative header-leads and primary bullets with regexp-specific characters
(eg, C "/*", mathematica "(*").
Include new regular expressions among those configured.
(allout-infer-header-lead-and-primary-bullet): Rename allout-infer-header-lead.
(allout-recent-depth): Manifest as a variable as well as a function.
(allout-prefix-data): Simplify into an inline instead of a macro, assuming
current match data rather than being explicitly passed it. Establish
allout-recent-depth value as well as allout-recent-prefix-beginning and
allout-recent-prefix-end.
(allout-aberrant-container-p): True when an item's immediate offspring
discontinuously contained. Useful for disqualifying unintended topic prefixes,
likely at low depths.
(allout-goto-prefix-doublechecked): Elaborated version of allout-goto-prefix
which disqualifies aberrant pseudo-items.
(allout-pre-next-prefix): Layer on top of lower-level routines, to get
disqualification of aberrant containers.
(allout-end-of-prefix, allout-end-of-subtree): Disqualify aberrant containers.
(allout-beginning-of-current-entry): Position at start of buffer when in
container (depth 0) entry.
(nullify-allout-prefix-data): Invalidate allout-recent-* prefix data.
(allout-current-bullet): Strip text properties.
(allout-get-prefix-bullet): Use right match groups.
(allout-beginning-of-line, allout-next-heading): Disqualify aberrant containers.
(allout-previous-heading): Disqualify aberrant containers, and change to
regular (rather than inline) function, to allow self-recursion.
(allout-get-invisibility-overlay): Increment so progress is made when the first
overlay is not the sought one.
(allout-end-of-prefix): Disqualify aberrant containers.
(allout-end-of-line): Cycle something like allout-beginning-of-line.
(allout-mode): Make allout-old-style-prefixes (ie, enabling use with outline.el
outlines) functional again. Change the primary bullet along with the
header-lead - level 1 new-style bullets now work.
Engage allout-before-change-handler in mainline emacs, not just xemacs, to do
undo handling.
(allout-before-change-handler): Expose undo changes occurring in hidden
regions. Use allout-get-invisibility-overlay instead of reimplementing it
inline.
(allout-chart-subtree): Use start rather than end of prefix in charts. Use
allout-recent-depth variable.
(allout-chart-siblings): Disqualify aberrant topics.
(allout-beginning-of-current-entry): Position correctly.
(allout-ascend): Use new allout-depth-specific-regexp and
allout-depth-one-regexp for linear instead of O(N^2) or worse behavior.
(allout-ascend-to-depth): Depend on allout-ascend, rather than reimplementing
an algorithm.
(allout-up-current-level): Depend on allout-ascend, rather than reimplementing
an algorithm. Return to start-point if we fail.
(allout-descend-to-depth): Use allout-recent-depth variable instead of function.
(allout-next-sibling): On traversal of numerous intervening topics, resort to
economical allout-next-sibling-leap.
(allout-next-sibling-leap): Specialized version of allout-next-sibling that
uses allout-ascend cleverly, to depend on a regexp search to leap large numbers
of contained topics, rather than arbitrarily many one-by-one traversals.
(allout-next-visible-heading): Disqualify aberrant topics.
(allout-previous-visible-heading): Position consistently when interactive.
(allout-forward-current-level): Base on allout-previous-sibling rather than
(differently) reimplmenting the algorithm. Remove some unused variables.
(allout-solicit-alternate-bullet): Present default choice stripped of text
properties.
(allout-rebullet-heading): Use bullet stripped of text properties.
Register changes using allout-exposure-change-hook. Disregard aberrant topics.
(allout-shift-in): With universal-argument, make topic a peer of it's former
offspring. Simplify the code by separating out allout-shift-out functionality.
(allout-shift-out): With universal-argument, make offspring peers of their
former container, and its siblings. Implement the functionality here, rather
than inappropriately muddling the implementation of allout-shift-in.
(allout-rebullet-topic): Respect additional argument for new parent-child
separation function.
(allout-yank-processing): Use allout-ascend directly.
(allout-show-entry): Disqualify aberrant topics.
(allout-show-children): Handle discontinuous children gracefully, extending the
depth being revealed to expose them and posting a message indicating the
situation.
(allout-show-to-offshoot): Remove obsolete and incorrect comment. Leave cursor
in correct position.
(allout-hide-current-subtree): Use allout-ascend directly. Disqualify aberrant
topics.
(allout-kill-line, allout-kill-topic): Preserve exposure layout in a way that
the yanks can restore it, as used to happen.
(allout-yank-processing): Restore exposure layout as recorded by allout-kill-*,
as used to happen.
(allout-annotate-hidden, allout-hide-by-annotation): New routines for preseving
and restoring exposure layout across kills.
(allout-toggle-subtree-encryption): Run allout-exposure-change-hook.
(allout-encrypt-string): Strip text properties. Rearranged order and
outline-headings for some of the miscellaneous functions.
(allout-resolve-xref): No need to quote the error name in the condition-case
handler section.
(allout-flatten): Classic recursive (and recursively intensive, without
tail-recursion) list-flattener, needed by allout-shift-out when confronted with
discontinuous children.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 16 Sep 2006 10:24:24 +0000 |
parents | 695cf19ef79e |
children | 0f8b60808af2 375f2633d815 |
rev | line source |
---|---|
25856 | 1 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ |
2 /* IS_EXEC.C | |
3 * | |
4 * Given a filename or a file handle, and the extension of the file, | |
5 * determine if the file is executable. | |
6 * First, the file extension is checked in case it uniquely identifies | |
7 * the file as either an executable or not. Failing this, the first | |
8 * two bytes of the file are tested for known signatures of executable | |
9 * files. | |
10 * | |
11 * Copyright (c) 1994 Eli Zaretskii <eliz@is.elta.co.il> | |
12 * | |
13 * This software may be used freely so long as this copyright notice is | |
14 * left intact. There is no warranty on this software. | |
15 * | |
16 */ | |
17 | |
18 #include <libc/stubs.h> | |
19 #include <stdio.h> | |
20 #include <string.h> | |
21 #include <ctype.h> | |
22 #include <errno.h> | |
23 #include <dpmi.h> | |
24 #include <go32.h> | |
25 #include <io.h> | |
26 #include <libc/farptrgs.h> | |
27 #include <libc/dosio.h> | |
28 | |
29 extern unsigned short _djstat_flags; | |
30 unsigned short _get_magic(const char *, int); | |
31 int _is_executable(const char *, int, const char *); | |
32 | |
33 /* | |
34 * Read a MAGIC NUMBER from a given file. These are the first | |
35 * two bytes of the file, if we look at them as an unsigned short. */ | |
36 | |
37 #define _STAT_EXEC_EXT 2 /* get execute bits from file extension? */ | |
38 #define _STAT_EXEC_MAGIC 4 /* get execute bits from magic signature? */ | |
39 | |
40 unsigned short | |
41 _get_magic(const char *s, int fh) | |
42 { | |
43 __dpmi_regs regs; | |
44 unsigned short retval; | |
45 unsigned short fpos_high = 0, fpos_low = 0; | |
46 int read_fail = 0; | |
47 | |
48 /* If given a pathname, open the file. */ | |
49 if (s) | |
50 { | |
51 int handle; | |
52 if((handle = _open(s,0)) == -1) | |
53 return 0; | |
54 regs.x.bx = handle; | |
55 } | |
56 /* Else file already open. Remember its current file position | |
57 and move to beginning of file. */ | |
58 else | |
59 { | |
60 regs.x.ax = 0x4201; /* set pointer from current position */ | |
61 regs.x.bx = fh; | |
62 regs.x.cx = regs.x.dx = 0; /* move 0 bytes (i.e., stay put) */ | |
63 __dpmi_int(0x21, ®s); | |
64 if (regs.x.flags & 1) | |
65 { | |
66 errno = __doserr_to_errno(regs.x.ax); | |
67 return 0; | |
68 } | |
69 fpos_high = regs.x.dx; /* got current position */ | |
70 fpos_low = regs.x.ax; | |
71 | |
72 regs.x.ax = 0x4200; /* set pointer from the beginning of file */ | |
73 regs.x.cx = regs.x.dx = 0; /* move to beginning of file */ | |
74 __dpmi_int(0x21, ®s); | |
75 if (regs.x.flags & 1) | |
76 { | |
77 errno = __doserr_to_errno(regs.x.ax); | |
78 return 0; | |
79 } | |
80 } | |
81 regs.x.ds = __tb_segment; | |
82 regs.x.dx = __tb_offset; | |
83 | |
84 /* Read 2 bytes from the file. */ | |
85 regs.x.ax = 0x3f00; | |
86 regs.x.cx = 2; | |
87 __dpmi_int(0x21, ®s); | |
88 | |
89 /* We can either (1) succeed, (2) read less than 2 bytes, | |
90 or (3) fail to read at all. */ | |
91 if (regs.x.ax != 2) | |
92 read_fail = (regs.x.flags & 1) ? regs.x.ax : -1; | |
93 | |
94 /* If called with filename, close the file. */ | |
95 if (s) | |
96 { | |
97 regs.x.ax = 0x3e00; | |
98 __dpmi_int(0x21, ®s); | |
99 if (regs.x.flags & 1) | |
100 errno = __doserr_to_errno(regs.x.ax); | |
101 } | |
102 /* Else leave file pointer where we found it. */ | |
103 else | |
104 { | |
105 regs.x.ax = 0x4200; /* set pointer from the beginning of file */ | |
106 regs.x.bx = fh; | |
107 regs.x.cx = fpos_high; | |
108 regs.x.dx = fpos_low; | |
109 __dpmi_int(0x21, ®s); | |
110 if (regs.x.flags & 1) | |
111 { | |
112 errno = __doserr_to_errno(regs.x.ax); | |
113 return 0; | |
114 } | |
115 } | |
116 | |
117 if (read_fail == 0) | |
118 retval = _farpeekw(_dos_ds, __tb); | |
119 else | |
120 { | |
121 /* The file couldn't be read: assume non-executable. If the file | |
122 *is* executable, but was passed as a file-handle, and the user | |
123 opened it in write-only mode, they lose... */ | |
124 retval = 0; | |
125 if (read_fail != -1) | |
126 errno = __doserr_to_errno(read_fail); | |
127 } | |
128 | |
129 return retval; | |
130 } | |
131 | |
132 /* A list of extensions which designate executable files. These | |
133 are NOT tested for the magic number. */ | |
134 static char executables[] = "|EXE|COM|BAT|BTM|DLL|VXD|"; | |
135 | |
136 /* A list of extensions which belong to files known to NEVER be | |
137 executables. These exist to minimize read()'ing files while | |
138 detecting executables by magic number. You are welcome to | |
139 add to this list, but remember: only extensions which could | |
140 NEVER be present in executables should go here. */ | |
141 static char non_executables[] = "\ | |
142 |A|A01|A02|A03|A04|A05|ADL|ARC|ARJ|ASC|ASM|AUX|AWK\ | |
143 |BAS|BIB|BGI|BMP\ | |
144 |C|CC|CFG|CGZ|CH3|CHR|CI|CLP|CMF|CPI|CPP|CXX\ | |
145 |DAT|DBF|DIZ|DOC|DVI\ | |
146 |E|EL|ELC\ | |
147 |F77|FN3\ | |
148 |GIF|GZ\ | |
149 |H|HLP|HPP|HXX\ | |
150 |ICO|IN|INC|INF|INI\ | |
151 |JPG\ | |
152 |L|LEX|LF|LIB|LOG|LST|LZH\ | |
153 |M|MAK|MAP|MF|MID|MPG\ | |
154 |O|OBJ\ | |
155 |PAK|PAS|PBM|PCD|PCX|PDS|PIC|PIF|PN3|PRJ|PS\ | |
156 |RAS|RGB|RLE\ | |
157 |S|SND|SY3\ | |
158 |TAR|TAZ|TEX|TGA|TGZ|TIF|TXH|TXI|TXT\ | |
159 |VOC\ | |
160 |WAV|WK1|WK3|WKB|WQ1|WQ3|WQ4|WQ5|WQ6|WQ!\ | |
161 |XBM\ | |
162 |Y\ | |
163 |ZIP|ZOO|"; | |
164 | |
165 int | |
166 _is_executable(const char *filename, int fhandle, const char *extension) | |
167 { | |
168 if (!extension && filename) | |
169 { | |
170 const char *cp, *ep=0; | |
171 for (cp=filename; *cp; cp++) | |
172 { | |
173 if (*cp == '.') | |
174 ep = cp; | |
175 if (*cp == '/' || *cp == '\\' || *cp == ':') | |
176 ep = 0; | |
177 } | |
178 extension = ep; | |
179 } | |
180 if ((_djstat_flags & _STAT_EXEC_EXT) == 0 | |
181 && extension | |
182 && *extension | |
183 && strlen(extension) <= ((extension[0]=='.') ? 4 : 3)) | |
184 { | |
185 /* Search the list of extensions in executables[]. */ | |
186 char tmp_buf[6], *tp = tmp_buf; | |
187 | |
188 *tp++ = '|'; | |
189 if (*extension == '.') | |
190 extension++; | |
191 while (*extension) | |
192 *tp++ = toupper (*extension++); | |
193 *tp++ = '|'; | |
194 *tp = '\0'; | |
195 if (strstr(non_executables, tmp_buf)) | |
196 return 0; | |
197 else if (strstr(executables, tmp_buf)) | |
198 return 1; | |
199 } | |
200 | |
201 /* No extension, or extension doesn't define execute | |
202 bits unambiguously. We are in for some dirty work. | |
203 Read the first two bytes of the file and see if they | |
204 are any of the known magic numbers which designate | |
205 executable files. | |
206 Unix-like shells, which have executable shell scripts | |
207 without extensions and DON'T have "#!" as their FIRST | |
208 TWO CHARACTERS, lose here. Sorry, folks. */ | |
209 if ( (_djstat_flags & _STAT_EXEC_MAGIC) == 0 ) | |
210 { | |
211 switch (_get_magic(filename, fhandle)) | |
212 { | |
213 case 0x5a4d: /* "MZ" */ | |
214 case 0x010b: | |
215 case 0x014c: | |
216 case 0x2123: /* "#!" */ | |
217 return 1; | |
218 } | |
219 } | |
220 | |
221 return 0; | |
222 } | |
52401 | 223 |
224 /* arch-tag: b0965811-8c3e-4bc4-8d81-4447a3594785 | |
225 (do not change this comment) */ |