Mercurial > hg > xemacs-beta
annotate lib-src/getopt1.c @ 5652:cc6f0266bc36
Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
lisp/ChangeLog addition:
2012-05-01 Aidan Kehoe <kehoea@parhasard.net>
Avoid #'delq in core code, for the sake of style and a (very
slightly) smaller binary.
* behavior.el (disable-behavior):
* behavior.el (compute-behavior-group-children):
* buff-menu.el (buffers-tab-items):
* byte-optimize.el (byte-optimize-delay-constants-math):
* byte-optimize.el (byte-optimize-logmumble):
* byte-optimize.el (byte-decompile-bytecode-1):
* byte-optimize.el (byte-optimize-lapcode):
* bytecomp.el:
* bytecomp.el (byte-compile-arglist-warn):
* bytecomp.el (byte-compile-warn-about-unresolved-functions):
* bytecomp.el (byte-compile-lambda):
* bytecomp.el (byte-compile-out-toplevel):
* bytecomp.el (byte-compile-insert):
* bytecomp.el (byte-compile-defalias-warn):
* cl-macs.el (cl-upcase-arg):
* cl-macs.el (cl-transform-lambda):
* cl-macs.el (cl-do-proclaim):
* cl-macs.el (defstruct):
* cl-macs.el (cl-make-type-test):
* cl-macs.el (define-compiler-macro):
* cl-macs.el (delete-duplicates):
* cus-edit.el (widget-face-value-delete):
* cus-edit.el (face-history):
* easymenu.el (easy-menu-remove):
* files.el (files-fetch-hook-value):
* files.el (file-expand-wildcards):
* font-lock.el (font-lock-update-removed-keyword-alist):
* font-lock.el (font-lock-remove-keywords):
* frame.el (frame-initialize):
* frame.el (frame-notice-user-settings):
* frame.el (set-frame-font):
* frame.el (delete-other-frames):
* frame.el (get-frame-for-buffer-noselect):
* gnuserv.el (gnuserv-kill-buffer-function):
* gnuserv.el (gnuserv-check-device):
* gnuserv.el (gnuserv-kill-client):
* gnuserv.el (gnuserv-buffer-done-1):
* gtk-font-menu.el (gtk-reset-device-font-menus):
* gutter-items.el (buffers-tab-items):
* gutter.el (set-gutter-element-visible-p):
* info.el (Info-find-file-node):
* info.el (Info-history-add):
* info.el (Info-build-annotation-completions):
* info.el (Info-index):
* info.el (Info-reannotate-node):
* itimer.el (delete-itimer):
* itimer.el (start-itimer):
* lib-complete.el (lib-complete:cache-completions):
* loadhist.el (unload-feature):
* menubar-items.el (build-buffers-menu-internal):
* menubar.el (delete-menu-item):
* menubar.el (relabel-menu-item):
* msw-font-menu.el (mswindows-reset-device-font-menus):
* mule/make-coding-system.el (fixed-width-generate-helper):
* next-error.el (next-error-find-buffer):
* obsolete.el:
* obsolete.el (find-non-ascii-charset-string):
* obsolete.el (find-non-ascii-charset-region):
* occur.el (multi-occur-by-filename-regexp):
* occur.el (occur-1):
* packages.el (packages-package-hierarchy-directory-names):
* packages.el (package-get-key-1):
* process.el (setenv):
* simple.el (undo):
* simple.el (handle-pre-motion-command-current-command-is-motion):
* sound.el (load-sound-file):
* wid-edit.el (widget-field-value-delete):
* wid-edit.el (widget-checklist-match-inline):
* wid-edit.el (widget-checklist-match-find):
* wid-edit.el (widget-editable-list-delete-at):
* wid-edit.el (widget-editable-list-entry-create):
* window.el (quit-window):
* x-font-menu.el (x-reset-device-font-menus-core):
1. Replace (delq nil (mapcar ....)) with analogous (mapcan ...)
forms; this is in non-dumped files, it was done previously in
dumped files.
2. Replace (delq FOO (copy-sequence BAR)) with (remove* FOO BAR),
where #'eq and #'eql are equivalent
3. Replace (delq FOO BAR) with (delete* FOO BAR), where FOO is not
a non-fixnum number. Saves a little space in the dumped file
(since the compiler macro adds :test #'eq to the delete* call if
it's not clear that FOO is not a non-fixnum number).
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Tue, 01 May 2012 16:17:42 +0100 |
parents | 061f4f90f874 |
children |
rev | line source |
---|---|
428 | 1 /* getopt_long and getopt_long_only entry points for GNU getopt. |
2 Copyright (C) 1987,88,89,90,91,92,93,94,96,97 Free Software Foundation, Inc. | |
3 | |
4 NOTE: The canonical source of this file is maintained with the GNU C Library. | |
5 Bugs can be reported to bug-glibc@prep.ai.mit.edu. | |
6 | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
438
diff
changeset
|
7 This program is free software: you can redistribute it and/or modify it |
428 | 8 under the terms of the GNU General Public License as published by the |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
438
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
438
diff
changeset
|
10 option) any later version. |
428 | 11 |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
438
diff
changeset
|
12 This program is distributed in the hope that it will be useful, but WITHOUT |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
438
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
438
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
438
diff
changeset
|
15 for more details. |
428 | 16 |
17 You should have received a copy of the GNU General Public License | |
5406
061f4f90f874
Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
438
diff
changeset
|
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 19 |
20 #ifdef HAVE_CONFIG_H | |
438 | 21 #include <config.h> |
428 | 22 #endif |
23 | |
24 #include "getopt.h" | |
25 | |
26 #include <stdio.h> | |
27 | |
28 /* Comment out all this code if we are using the GNU C Library, and are not | |
29 actually compiling the library itself. This code is part of the GNU C | |
30 Library, but also included in many other GNU distributions. Compiling | |
31 and linking in this code is a waste when using the GNU C library | |
32 (especially if it is a shared library). Rather than having every GNU | |
33 program understand `configure --with-gnu-libc' and omit the object files, | |
34 it is simpler to just do this in the source for each such file. */ | |
35 | |
36 #define GETOPT_INTERFACE_VERSION 2 | |
37 #if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2 | |
38 #include <gnu-versions.h> | |
39 #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION | |
40 #define ELIDE_CODE | |
41 #endif | |
42 #endif | |
43 | |
44 #ifndef ELIDE_CODE | |
45 | |
46 | |
47 /* This needs to come after some library #include | |
48 to get __GNU_LIBRARY__ defined. */ | |
49 #ifdef __GNU_LIBRARY__ | |
50 #include <stdlib.h> | |
51 #endif | |
52 | |
53 #ifndef NULL | |
54 #define NULL 0 | |
55 #endif | |
56 | |
57 int | |
58 getopt_long (int argc, char *const *argv, const char *options, | |
59 const struct option *long_options, int *opt_index) | |
60 { | |
61 return _getopt_internal (argc, argv, options, long_options, opt_index, 0); | |
62 } | |
63 | |
64 /* Like getopt_long, but '-' as well as '--' can indicate a long option. | |
65 If an option that starts with '-' (not '--') doesn't match a long option, | |
66 but does match a short option, it is parsed as a short option | |
67 instead. */ | |
68 | |
69 int | |
70 getopt_long_only (int argc, char *const *argv, const char *options, | |
71 const struct option *long_options, int *opt_index) | |
72 { | |
73 return _getopt_internal (argc, argv, options, long_options, opt_index, 1); | |
74 } | |
75 | |
76 | |
77 #endif /* Not ELIDE_CODE. */ | |
78 | |
79 #ifdef TEST | |
80 | |
81 #include <stdio.h> | |
82 | |
83 int | |
84 main (int argc, char **argv) | |
85 { | |
86 int c; | |
87 int digit_optind = 0; | |
88 | |
89 while (1) | |
90 { | |
91 int this_option_optind = optind ? optind : 1; | |
92 int option_index = 0; | |
93 static struct option long_options[] = | |
94 { | |
95 {"add", 1, 0, 0}, | |
96 {"append", 0, 0, 0}, | |
97 {"delete", 1, 0, 0}, | |
98 {"verbose", 0, 0, 0}, | |
99 {"create", 0, 0, 0}, | |
100 {"file", 1, 0, 0}, | |
101 {0, 0, 0, 0} | |
102 }; | |
103 | |
104 c = getopt_long (argc, argv, "abc:d:0123456789", | |
105 long_options, &option_index); | |
106 if (c == -1) | |
107 break; | |
108 | |
109 switch (c) | |
110 { | |
111 case 0: | |
112 printf ("option %s", long_options[option_index].name); | |
113 if (optarg) | |
114 printf (" with arg %s", optarg); | |
115 printf ("\n"); | |
116 break; | |
117 | |
118 case '0': | |
119 case '1': | |
120 case '2': | |
121 case '3': | |
122 case '4': | |
123 case '5': | |
124 case '6': | |
125 case '7': | |
126 case '8': | |
127 case '9': | |
128 if (digit_optind != 0 && digit_optind != this_option_optind) | |
129 printf ("digits occur in two different argv-elements.\n"); | |
130 digit_optind = this_option_optind; | |
131 printf ("option %c\n", c); | |
132 break; | |
133 | |
134 case 'a': | |
135 printf ("option a\n"); | |
136 break; | |
137 | |
138 case 'b': | |
139 printf ("option b\n"); | |
140 break; | |
141 | |
142 case 'c': | |
143 printf ("option c with value `%s'\n", optarg); | |
144 break; | |
145 | |
146 case 'd': | |
147 printf ("option d with value `%s'\n", optarg); | |
148 break; | |
149 | |
150 case '?': | |
151 break; | |
152 | |
153 default: | |
154 printf ("?? getopt returned character code 0%o ??\n", c); | |
155 } | |
156 } | |
157 | |
158 if (optind < argc) | |
159 { | |
160 printf ("non-option ARGV-elements: "); | |
161 while (optind < argc) | |
162 printf ("%s ", argv[optind++]); | |
163 printf ("\n"); | |
164 } | |
165 | |
166 exit (0); | |
167 } | |
168 | |
169 #endif /* TEST */ |