Mercurial > hg > xemacs-beta
annotate src/termcap.c @ 5353:38e24b8be4ea
Improve the lexical scoping in #'block, #'return-from.
lisp/ChangeLog addition:
2011-02-07 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el:
* bytecomp.el (byte-compile-initial-macro-environment):
Shadow `block', `return-from' here, we implement them differently
when byte-compiling.
* bytecomp.el (byte-compile-active-blocks): New.
* bytecomp.el (byte-compile-block-1): New.
* bytecomp.el (byte-compile-return-from-1): New.
* bytecomp.el (return-from-1): New.
* bytecomp.el (block-1): New.
These are two aliases that exist to have their own associated
byte-compile functions, which functions implement `block' and
`return-from'.
* cl-extra.el (cl-macroexpand-all):
Fix a bug here when macros in the environment have been compiled.
* cl-macs.el (block):
* cl-macs.el (return):
* cl-macs.el (return-from):
Be more careful about lexical scope in these macros.
* cl.el:
* cl.el ('cl-block-wrapper): Removed.
* cl.el ('cl-block-throw): Removed.
These aren't needed in code generated by this XEmacs. They
shouldn't be needed in code generated by XEmacs 21.4, but if it
turns out the packages do need them, we can put them back.
2011-01-30 Mike Sperber <mike@xemacs.org>
* font-lock.el (font-lock-fontify-pending-extents): Don't fail if
`font-lock-mode' is unset, which can happen in the middle of
`revert-buffer'.
2011-01-23 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (delete):
* cl-macs.el (delq):
* cl-macs.el (remove):
* cl-macs.el (remq):
Don't use the compiler macro if these functions were given the
wrong number of arguments, as happens in lisp-tests.el.
* cl-seq.el (remove, remq): Removed.
I added these to subr.el, and forgot to remove them from here.
2011-01-22 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-setq, byte-compile-set):
Remove kludge allowing keywords' values to be set, all the code
that does that is gone.
* cl-compat.el (elt-satisfies-test-p):
* faces.el (set-face-parent):
* faces.el (face-doc-string):
* gtk-font-menu.el:
* gtk-font-menu.el (gtk-reset-device-font-menus):
* msw-font-menu.el:
* msw-font-menu.el (mswindows-reset-device-font-menus):
* package-get.el (package-get-installedp):
* select.el (select-convert-from-image-data):
* sound.el:
* sound.el (load-sound-file):
* x-font-menu.el (x-reset-device-font-menus-core):
Don't quote keywords, they're self-quoting, and the
win from backward-compatibility is sufficiently small now that the
style problem overrides it.
2011-01-22 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (block, return-from): Require that NAME be a symbol
in these macros, as always documented in the #'block docstring and
as required by Common Lisp.
* descr-text.el (unidata-initialize-unihan-database):
Correct the use of non-symbols in #'block and #'return-from in
this function.
2011-01-15 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (concatenate): Accept more complicated TYPEs in this
function, handing the sequences over to #'coerce if we don't
understand them here.
* cl-macs.el (inline): Don't proclaim #'concatenate as inline, its
compiler macro is more useful than doing that.
2011-01-11 Aidan Kehoe <kehoea@parhasard.net>
* subr.el (delete, delq, remove, remq): Move #'remove, #'remq
here, they don't belong in cl-seq.el; move #'delete, #'delq here
from fns.c, implement them in terms of #'delete*, allowing support
for sequences generally.
* update-elc.el (do-autoload-commands): Use #'delete*, not #'delq
here, now the latter's no longer dumped.
* cl-macs.el (delete, delq): Add compiler macros transforming
#'delete and #'delq to #'delete* calls.
2011-01-10 Aidan Kehoe <kehoea@parhasard.net>
* dialog.el (make-dialog-box): Correct a misplaced parenthesis
here, thank you Mats Lidell in 87zkr9gqrh.fsf@mail.contactor.se !
2011-01-02 Aidan Kehoe <kehoea@parhasard.net>
* dialog.el (make-dialog-box):
* list-mode.el (display-completion-list):
These functions used to use cl-parsing-keywords; change them to
use defun* instead, fixing the build. (Not sure what led to me
not including this change in d1b17a33450b!)
2011-01-02 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (define-star-compiler-macros):
Make sure the form has ITEM and LIST specified before attempting
to change to calls with explicit tests; necessary for some tests
in lisp-tests.el to compile correctly.
(stable-union, stable-intersection): Add compiler macros for these
functions, in the same way we do for most of the other functions
in cl-seq.el.
2011-01-01 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (dolist, dotimes, do-symbols, macrolet)
(symbol-macrolet):
Define these macros with defmacro* instead of parsing the argument
list by hand, for the sake of style and readability; use backquote
where appropriate, instead of calling #'list and and friends, for
the same reason.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* x-misc.el (device-x-display):
Provide this function, documented in the Lispref for years, but
not existing previously. Thank you Julian Bradfield, thank you
Jeff Mincy.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* cl-seq.el:
Move the heavy lifting from this file to C. Dump the
cl-parsing-keywords macro, but don't use defun* for the functions
we define that do take keywords, dynamic scope lossage makes that
not practical.
* subr.el (sort, fillarray): Move these aliases here.
(map-plist): #'nsublis is now built-in, but at this point #'eql
isn't necessarily available as a test; use #'eq.
* obsolete.el (cl-delete-duplicates): Make this available for old
compiler macros and old code.
(memql): Document that this is equivalent to #'member*, and worse.
* cl.el (adjoin, subst): Removed. These are in C.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* simple.el (assoc-ignore-case): Remove a duplicate definition of
this function (it's already in subr.el).
* iso8859-1.el (char-width):
On non-Mule, make this function equivalent to that produced by
(constantly 1), but preserve its docstring.
* subr.el (subst-char-in-string): Define this in terms of
#'substitute, #'nsubstitute.
(string-width): Define this using #'reduce and #'char-width.
(char-width): Give this a simpler definition, it makes far more
sense to check for mule at load time and redefine, as we do in
iso8859-1.el.
(store-substring): Implement this in terms of #'replace, now
#'replace is cheap.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* update-elc.el (lisp-files-needed-for-byte-compilation)
(lisp-files-needing-early-byte-compilation):
cl-macs belongs in the former, not the latter, it is as
fundamental as bytecomp.el.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* cl.el:
Provde the Common Lisp program-error, type-error as error
symbols. This doesn't nearly go far enough for anyone using the
Common Lisp errors.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (delete-duplicates):
If the form has an incorrect number of arguments, don't attempt a
compiler macroexpansion.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (cl-safe-expr-p):
Forms that start with the symbol lambda are also safe.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (= < > <= >=):
For these functions' compiler macros, the optimisation is safe
even if the first and the last arguments have side effects, since
they're only used the once.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (inline-side-effect-free-compiler-macros):
Unroll a loop here at macro-expansion time, so these compiler
macros are compiled. Use #'eql instead of #'eq in a couple of
places for better style.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (notany, notevery): Avoid some dynamic scope
stupidity with local variable names in these functions, when they
weren't prefixed with cl-; go into some more detail in the doc
strings.
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (side-effect-free-fns): #'remove, #'remq are
free of side-effects.
(side-effect-and-error-free-fns):
Drop dot, dot-marker from the list.
2010-11-17 Aidan Kehoe <kehoea@parhasard.net>
* cl-extra.el (coerce):
In the argument list, name the first argument OBJECT, not X; the
former name was always used in the doc string and is clearer.
Handle vector type specifications which include the length of the
target sequence, error if there's a mismatch.
* cl-macs.el (cl-make-type-test): Handle type specifications
starting with the symbol 'eql.
2010-11-14 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (eql): Don't remove the byte-compile property of this
symbol. That was necessary to override a bug in bytecomp.el where
#'eql was confused with #'eq, which bug we no longer have.
If neither expression is constant, don't attempt to handle the
expression in this compiler macro, leave it to byte-compile-eql,
which produces better code anyway.
* bytecomp.el (eq): #'eql is not the function associated with the
byte-eq byte code.
(byte-compile-eql): Add an explicit compile method for this
function, for cases where the cl-macs compiler macro hasn't
reduced it to #'eq or #'equal.
2010-10-25 Aidan Kehoe <kehoea@parhasard.net>
Add compiler macros and compilation sanity-checking for various
functions that take keywords.
* byte-optimize.el (side-effect-free-fns): #'symbol-value is
side-effect free and not error free.
* bytecomp.el (byte-compile-normal-call): Check keyword argument
lists for sanity; store information about the positions where
keyword arguments start using the new byte-compile-keyword-start
property.
* cl-macs.el (cl-const-expr-val): Take a new optional argument,
cl-not-constant, defaulting to nil, in this function; return it if
the expression is not constant.
(cl-non-fixnum-number-p): Make this into a separate function, we
want to pass it to #'every.
(eql): Use it.
(define-star-compiler-macros): Use the same code to generate the
member*, assoc* and rassoc* compiler macros; special-case some
code in #'add-to-list in subr.el.
(remove, remq): Add compiler macros for these two functions, in
preparation for #'remove being in C.
(define-foo-if-compiler-macros): Transform (remove-if-not ...) calls to
(remove ... :if-not) at compile time, which will be a real win
once the latter is in C.
(define-substitute-if-compiler-macros)
(define-subst-if-compiler-macros): Similarly for these functions.
(delete-duplicates): Change this compiler macro to use
#'plists-equal; if we don't have information about the type of
SEQUENCE at compile time, don't bother attempting to inline the
call, the function will be in C soon enough.
(equalp): Remove an old commented-out compiler macro for this, if
we want to see it it's in version control.
(subst-char-in-string): Transform this to a call to nsubstitute or
nsubstitute, if that is appropriate.
* cl.el (ldiff): Don't call setf here, this makes for a load-time
dependency problem in cl-macs.el
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* term/vt100.el:
Refer to XEmacs, not GNU Emacs, in permissions.
* term/bg-mouse.el:
* term/sup-mouse.el:
Put copyright notice in canonical "Copyright DATE AUTHOR" form.
Refer to XEmacs, not GNU Emacs, in permissions.
* site-load.el:
Add permission boilerplate.
* mule/canna-leim.el:
* alist.el:
Refer to XEmacs, not APEL/this program, in permissions.
* mule/canna-leim.el:
Remove my copyright, I've assigned it to the FSF.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* gtk.el:
* gtk-widget-accessors.el:
* gtk-package.el:
* gtk-marshal.el:
* gtk-compose.el:
* gnome.el:
Add copyright notice based on internal evidence.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* easymenu.el: Add reference to COPYING to permission notice.
* gutter.el:
* gutter-items.el:
* menubar-items.el:
Fix typo "Xmacs" in permissions notice.
2010-06-14 Stephen J. Turnbull <stephen@xemacs.org>
* auto-save.el:
* font.el:
* fontconfig.el:
* mule/kinsoku.el:
Add "part of XEmacs" text to permission notice.
2010-10-14 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (side-effect-free-fns):
* cl-macs.el (remf, getf):
* cl-extra.el (tailp, cl-set-getf, cl-do-remf):
* cl.el (ldiff, endp):
Tighten up Common Lisp compatibility for #'ldiff, #'endp, #'tailp;
add circularity checking for the first two.
#'cl-set-getf and #'cl-do-remf were Lisp implementations of
#'plist-put and #'plist-remprop; change the names to aliases,
changes the macros that use them to using #'plist-put and
#'plist-remprop directly.
2010-10-12 Aidan Kehoe <kehoea@parhasard.net>
* abbrev.el (fundamental-mode-abbrev-table, global-abbrev-table):
Create both these abbrev tables using the usual
#'define-abbrev-table calls, rather than attempting to
special-case them.
* cl-extra.el: Force cl-macs to be loaded here, if cl-extra.el is
being loaded interpreted. Previously other, later files would
redundantly call (load "cl-macs") when interpreted, it's more
reasonable to do it here, once.
* cmdloop.el (read-quoted-char-radix): Use defcustom here, we
don't have any dump-order dependencies that would prevent that.
* custom.el (eval-when-compile): Don't load cl-macs when
interpreted or when byte-compiling, rely on cl-extra.el in the
former case and the appropriate entry in bytecomp-load-hook in the
latter. Get rid of custom-declare-variable-list, we have no
dump-time dependencies that would require it.
* faces.el (eval-when-compile): Don't load cl-macs when
interpreted or when byte-compiling.
* packages.el: Remove some inaccurate comments.
* post-gc.el (cleanup-simple-finalizers): Use #'delete-if-not
here, now the order of preloaded-file-list has been changed to
make it available.
* subr.el (custom-declare-variable-list): Remove. No need for it.
Also remove a stub define-abbrev-table from this file, given the
current order of preloaded-file-list there's no need for it.
2010-10-10 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-constp) Forms quoted with FUNCTION are
also constant.
(byte-compile-initial-macro-environment): In #'the, if FORM is
constant and does not match TYPE, warn at byte-compile time.
2010-10-10 Aidan Kehoe <kehoea@parhasard.net>
* backquote.el (bq-vector-contents, bq-list*): Remove; the former
is equivalent to (append VECTOR nil), the latter to (list* ...).
(bq-process-2): Use (append VECTOR nil) instead of using
#'bq-vector-contents to convert to a list.
(bq-process-1): Now we use list* instead of bq-list
* subr.el (list*): Moved from cl.el, since it is now required to
be available the first time a backquoted form is encountered.
* cl.el (list*): Move to subr.el.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* test-harness.el (Check-Message):
Add an omitted comma here, thank you the buildbot.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* hash-table.el (hash-table-key-list, hash-table-value-list)
(hash-table-key-value-alist, hash-table-key-value-plist):
Remove some useless #'nreverse calls in these files; our hash
tables have no order, it's not helpful to pretend they do.
* behavior.el (read-behavior):
Do the same in this file, in some code evidently copied from
hash-table.el.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* info.el (Info-insert-dir):
* format.el (format-deannotate-region):
* files.el (cd, save-buffers-kill-emacs):
Use #'some, #'every and related functions for applying boolean
operations to lists, instead of rolling our own ones that cons and
don't short-circuit.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-initial-macro-environment):
* cl-macs.el (the):
Rephrase the docstring, make its implementation when compiling
files a little nicer.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* descr-text.el (unidata-initialize-unicodedata-database)
(unidata-initialize-unihan-database, describe-char-unicode-data)
(describe-char-unicode-data):
Wrap calls to the database functions with (with-fboundp ...),
avoiding byte compile warnings on builds without support for the
database functions.
(describe-char): (reduce #'max ...), not (apply #'max ...), no
need to cons needlessly.
(describe-char): Remove a redundant lambda wrapping
#'extent-properties.
(describe-char-unicode-data): Call #'nsubst when replacing "" with
nil in the result of #'split-string, instead of consing inside
mapcar.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* x-faces.el (x-available-font-sizes):
* specifier.el (let-specifier):
* package-ui.el (pui-add-required-packages):
* msw-faces.el (mswindows-available-font-sizes):
* modeline.el (modeline-minor-mode-menu):
* minibuf.el (minibuf-directory-files):
Replace the O2N (delq nil (mapcar (lambda (W) (and X Y)) Z)) with
the ON (mapcan (lambda (W) (and X (list Y))) Z) in these files.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (= < > <= >=):
When these functions are handed more than two arguments, and those
arguments have no side effects, transform to a series of two
argument calls, avoiding funcall in the byte-compiled code.
* mule/mule-cmds.el (finish-set-language-environment):
Take advantage of this change in a function called 256 times at
startup.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el (byte-compile-function-form, byte-compile-quote)
(byte-compile-quote-form):
Warn at compile time, and error at runtime, if a (quote ...) or a
(function ...) form attempts to quote more than one object.
2010-09-16 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (byte-optimize-apply): Transform (apply 'nconc
(mapcar ...)) to (mapcan ...); warn about use of the first idiom.
* update-elc.el (do-autoload-commands):
* packages.el (packages-find-package-library-path):
* frame.el (frame-list):
* extents.el (extent-descendants):
* etags.el (buffer-tag-table-files):
* dumped-lisp.el (preloaded-file-list):
* device.el (device-list):
* bytecomp-runtime.el (proclaim-inline, proclaim-notinline)
Use #'mapcan, not (apply #'nconc (mapcar ...) in all these files.
* bytecomp-runtime.el (eval-when-compile, eval-and-compile):
In passing, mention that these macros also evaluate the body when
interpreted.
tests/ChangeLog addition:
2011-02-07 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el:
Test lexical scope for `block', `return-from'; add a
Known-Bug-Expect-Failure for a contorted example that fails when
byte-compiled.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Mon, 07 Feb 2011 12:01:24 +0000 |
parents | dd2976af8783 |
children | 308d34e9f07d |
rev | line source |
---|---|
428 | 1 /* Work-alike for termcap, plus extra features. |
2 Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc. | |
771 | 3 Copyright (C) 2001 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: Not synched with FSF. */ | |
23 | |
24 /* config.h may rename various library functions such as malloc. */ | |
25 #ifdef emacs | |
26 #include <config.h> | |
27 #include "lisp.h" /* For encapsulated open, close, read */ | |
5276
dd2976af8783
Add some missing #includes, termcap.c, hopefully fixing Adam Sjoegren's build.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
28 #include "device.h" |
dd2976af8783
Add some missing #includes, termcap.c, hopefully fixing Adam Sjoegren's build.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
29 #include "device-impl.h" /* For DEVICE_BAUD_RATE */ |
dd2976af8783
Add some missing #includes, termcap.c, hopefully fixing Adam Sjoegren's build.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
30 #include "sysfile.h" |
dd2976af8783
Add some missing #includes, termcap.c, hopefully fixing Adam Sjoegren's build.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4976
diff
changeset
|
31 #include "process.h" |
428 | 32 #else /* not emacs */ |
33 | |
34 #include <stdlib.h> | |
35 #include <string.h> | |
36 | |
37 #ifdef HAVE_UNISTD_H | |
38 #include <unistd.h> | |
39 #endif | |
40 #ifdef _POSIX_VERSION | |
41 #include <fcntl.h> | |
42 #endif | |
43 | |
44 #endif /* not emacs */ | |
45 | |
46 /* BUFSIZE is the initial size allocated for the buffer | |
47 for reading the termcap file. | |
48 It is not a limit. | |
49 Make it large normally for speed. | |
50 Make it variable when debugging, so can exercise | |
51 increasing the space dynamically. */ | |
52 | |
53 #ifndef BUFSIZE | |
54 #ifdef DEBUG | |
55 #define BUFSIZE bufsize | |
56 | |
57 int bufsize = 128; | |
58 #else | |
59 #define BUFSIZE 2048 | |
60 #endif | |
61 #endif | |
62 | |
63 #ifndef emacs | |
64 static void | |
65 memory_out () | |
66 { | |
771 | 67 retry_write (2, "virtual memory exhausted\n", 25); |
428 | 68 exit (1); |
69 } | |
70 | |
71 static char * | |
72 xmalloc (size) | |
73 unsigned int size; | |
74 { | |
75 char *tem = malloc (size); | |
76 | |
77 if (!tem) | |
78 memory_out (); | |
79 return tem; | |
80 } | |
81 | |
82 static char * | |
83 xrealloc (ptr, size) | |
84 char *ptr; | |
85 unsigned size; | |
86 { | |
87 char *tem = realloc (ptr, size); | |
88 | |
89 if (!tem) | |
90 memory_out (); | |
91 return tem; | |
92 } | |
93 #endif /* not emacs */ | |
94 | |
95 /* Looking up capabilities in the entry already found. */ | |
96 | |
97 /* The pointer to the data made by tgetent is left here | |
98 for tgetnum, tgetflag and tgetstr to find. */ | |
99 static char *term_entry; | |
100 | |
442 | 101 static const char *tgetst1 (const char *ptr, char **area); |
428 | 102 |
103 /* Search entry BP for capability CAP. | |
104 Return a pointer to the capability (in BP) if found, | |
105 0 if not found. */ | |
106 | |
442 | 107 static const char * |
428 | 108 find_capability (bp, cap) |
442 | 109 const char *bp; |
110 const char *cap; | |
428 | 111 { |
112 for (; *bp; bp++) | |
113 if (bp[0] == ':' | |
114 && bp[1] == cap[0] | |
115 && bp[2] == cap[1]) | |
116 return &bp[4]; | |
117 return 0; | |
118 } | |
119 | |
120 int | |
121 tgetnum (cap) | |
442 | 122 const char *cap; |
428 | 123 { |
442 | 124 const char *ptr = find_capability (term_entry, cap); |
428 | 125 if (!ptr || ptr[-1] != '#') |
126 return -1; | |
127 return atoi (ptr); | |
128 } | |
129 | |
130 int | |
131 tgetflag (cap) | |
442 | 132 const char *cap; |
428 | 133 { |
442 | 134 const char *ptr = find_capability (term_entry, cap); |
428 | 135 return 0 != ptr && ptr[-1] == ':'; |
136 } | |
137 | |
138 /* Look up a string-valued capability CAP. | |
139 If AREA is nonzero, it points to a pointer to a block in which | |
140 to store the string. That pointer is advanced over the space used. | |
141 If AREA is zero, space is allocated with `malloc'. */ | |
142 | |
442 | 143 const char * |
428 | 144 tgetstr (cap, area) |
442 | 145 const char *cap; |
428 | 146 char **area; |
147 { | |
442 | 148 const char *ptr = find_capability (term_entry, cap); |
428 | 149 if (!ptr || (ptr[-1] != '=' && ptr[-1] != '~')) |
150 return 0; | |
151 return tgetst1 (ptr, area); | |
152 } | |
153 | |
154 /* Table, indexed by a character in range 0100 to 0140 with 0100 subtracted, | |
155 gives meaning of character following \, or a space if no special meaning. | |
156 Eight characters per line within the string. */ | |
157 | |
158 static char esctab[] | |
159 = " \007\010 \033\014 " | |
160 " \012 " | |
161 " \015 \011 \013 " | |
162 " "; | |
163 | |
164 /* PTR points to a string value inside a termcap entry. | |
165 Copy that value, processing \ and ^ abbreviations, | |
166 into the block that *AREA points to, | |
167 or to newly allocated storage if AREA is 0. */ | |
168 | |
442 | 169 static const char * |
428 | 170 tgetst1 (ptr, area) |
442 | 171 const char *ptr; |
428 | 172 char **area; |
173 { | |
442 | 174 const char *p; |
428 | 175 char *r; |
176 int c; | |
177 int size; | |
178 char *ret; | |
179 int c1; | |
180 | |
181 if (!ptr) | |
182 return 0; | |
183 | |
184 /* `ret' gets address of where to store the string. */ | |
185 if (!area) | |
186 { | |
187 /* Compute size of block needed (may overestimate). */ | |
188 p = ptr; | |
189 while ((c = *p++) && c != ':' && c != '\n') | |
190 ; | |
191 ret = (char *) xmalloc (p - ptr + 1); | |
192 } | |
193 else | |
194 ret = *area; | |
195 | |
196 /* Copy the string value, stopping at null or colon. | |
197 Also process ^ and \ abbreviations. */ | |
198 p = ptr; | |
199 r = ret; | |
200 while ((c = *p++) && c != ':' && c != '\n') | |
201 { | |
202 if (c == '^') | |
203 c = *p++ & 037; | |
204 else if (c == '\\') | |
205 { | |
206 c = *p++; | |
207 if (c >= '0' && c <= '7') | |
208 { | |
209 c -= '0'; | |
210 size = 0; | |
211 | |
212 while (++size < 3 && (c1 = *p) >= '0' && c1 <= '7') | |
213 { | |
214 c *= 8; | |
215 c += c1 - '0'; | |
216 p++; | |
217 } | |
218 } | |
219 else if (c >= 0100 && c < 0200) | |
220 { | |
221 c1 = esctab[(c & ~040) - 0100]; | |
222 if (c1 != ' ') | |
223 c = c1; | |
224 } | |
225 } | |
226 *r++ = c; | |
227 } | |
228 *r = 0; | |
229 /* Update *AREA. */ | |
230 if (area) | |
231 *area = r + 1; | |
232 return ret; | |
233 } | |
234 | |
235 /* Outputting a string with padding. */ | |
236 | |
237 #ifdef LINUX | |
238 speed_t ospeed; | |
239 #else | |
240 short ospeed; | |
241 #endif | |
242 /* If `ospeed' is 0, we use `tputs_baud_rate' as the actual baud rate. */ | |
243 int tputs_baud_rate; | |
244 char PC; | |
245 | |
246 /* Actual baud rate if positive; | |
247 - baud rate / 100 if negative. */ | |
248 | |
249 static short speeds[] = | |
250 { | |
251 0, 50, 75, 110, 135, 150, -2, -3, -6, -12, | |
252 -18, -24, -48, -96, -192, -288, -384, -576, -1152 | |
253 }; | |
254 | |
255 void | |
256 tputs (string, nlines, outfun) | |
442 | 257 const char *string; |
428 | 258 int nlines; |
259 void (*outfun) (int); | |
260 { | |
261 int padcount = 0; | |
262 int speed; | |
263 | |
264 #ifdef emacs | |
265 speed = DEVICE_BAUD_RATE (XDEVICE (Fselected_device (Qnil))); | |
266 #else | |
267 if (ospeed == 0) | |
268 speed = tputs_baud_rate; | |
269 else | |
270 speed = speeds[ospeed]; | |
271 #endif | |
272 | |
273 if (string == (char *) 0) | |
274 return; | |
275 | |
442 | 276 while (isdigit (* (const unsigned char *) string)) |
428 | 277 { |
278 padcount += *string++ - '0'; | |
279 padcount *= 10; | |
280 } | |
281 if (*string == '.') | |
282 { | |
283 string++; | |
284 padcount += *string++ - '0'; | |
285 } | |
286 if (*string == '*') | |
287 { | |
288 string++; | |
289 padcount *= nlines; | |
290 } | |
291 while (*string) | |
292 (*outfun) (*string++); | |
293 | |
294 /* padcount is now in units of tenths of msec. */ | |
295 padcount *= speeds[ospeed]; | |
296 padcount += 500; | |
297 padcount /= 1000; | |
298 if (speeds[ospeed] < 0) | |
299 padcount = -padcount; | |
300 else | |
301 { | |
302 padcount += 50; | |
303 padcount /= 100; | |
304 } | |
305 | |
306 while (padcount-- > 0) | |
307 (*outfun) (PC); | |
308 } | |
309 | |
310 /* Finding the termcap entry in the termcap data base. */ | |
311 | |
312 struct buffer | |
313 { | |
314 char *beg; | |
315 int size; | |
316 char *ptr; | |
317 int ateof; | |
318 int full; | |
319 }; | |
320 | |
321 /* Forward declarations of static functions. */ | |
322 | |
323 static int scan_file (); | |
324 static char *gobble_line (); | |
325 static int compare_contin (); | |
326 static int name_match (); | |
327 | |
328 | |
329 /* Find the termcap entry data for terminal type NAME | |
330 and store it in the block that BP points to. | |
331 Record its address for future use. | |
332 | |
333 If BP is zero, space is dynamically allocated. */ | |
334 | |
335 int | |
336 tgetent (bp, name) | |
337 char *bp; | |
442 | 338 const char *name; |
428 | 339 { |
340 char *tem; | |
341 int fd; | |
342 struct buffer buf; | |
343 char *bp1; | |
344 char *bp2; | |
442 | 345 const char *term; |
428 | 346 int malloc_size = 0; |
347 int c; | |
442 | 348 char *tcenv; /* TERMCAP value, if it contains :tc=. */ |
349 const char *indirect = 0; /* Terminal type in :tc= in TERMCAP value. */ | |
428 | 350 |
771 | 351 tem = egetenv ("TERMCAP"); |
428 | 352 if (tem && *tem == 0) tem = 0; |
353 | |
354 | |
355 /* If tem is non-null and starts with / (in the un*x case, that is), | |
356 it is a file name to use instead of /etc/termcap. | |
357 If it is non-null and does not start with /, | |
358 it is the entry itself, but only if | |
359 the name the caller requested matches the TERM variable. */ | |
360 | |
771 | 361 if (tem && !IS_DIRECTORY_SEP (*tem) && !strcmp (name, egetenv ("TERM"))) |
428 | 362 { |
363 indirect = tgetst1 (find_capability (tem, "tc"), 0); | |
364 if (!indirect) | |
365 { | |
366 if (!bp) | |
367 bp = tem; | |
368 else | |
369 strcpy (bp, tem); | |
370 goto ret; | |
371 } | |
372 else | |
373 { /* We will need to read /etc/termcap. */ | |
374 tcenv = tem; | |
375 tem = 0; | |
376 } | |
377 } | |
378 else | |
379 indirect = (char *) 0; | |
380 | |
381 if (!tem) | |
382 tem = "/etc/termcap"; | |
383 | |
384 /* Here we know we must search a file and tem has its name. */ | |
385 | |
867 | 386 fd = qxe_open ((Ibyte *) tem, 0, 0); |
428 | 387 if (fd < 0) |
388 return -1; | |
389 | |
390 buf.size = BUFSIZE; | |
391 /* Add 1 to size to ensure room for terminating null. */ | |
392 buf.beg = (char *) xmalloc (buf.size + 1); | |
393 term = indirect ? indirect : name; | |
394 | |
395 if (!bp) | |
396 { | |
397 malloc_size = indirect ? strlen (tcenv) + 1 : buf.size; | |
398 bp = (char *) xmalloc (malloc_size); | |
399 } | |
400 bp1 = bp; | |
401 | |
402 if (indirect) | |
403 /* Copy the data from the environment variable. */ | |
404 { | |
405 strcpy (bp, tcenv); | |
406 bp1 += strlen (tcenv); | |
407 } | |
408 | |
409 while (term) | |
410 { | |
411 /* Scan the file, reading it via buf, till find start of main entry. */ | |
412 if (scan_file (term, fd, &buf) == 0) | |
413 return 0; | |
414 | |
415 /* Free old `term' if appropriate. */ | |
416 if (term != name) | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
1726
diff
changeset
|
417 xfree (term); |
428 | 418 |
419 /* If BP is malloc'd by us, make sure it is big enough. */ | |
420 if (malloc_size) | |
421 { | |
422 malloc_size = bp1 - bp + buf.size; | |
423 tem = (char *) xrealloc (bp, malloc_size); | |
424 bp1 += tem - bp; | |
425 bp = tem; | |
426 } | |
427 | |
428 bp2 = bp1; | |
429 | |
430 /* Copy the line of the entry from buf into bp. */ | |
431 tem = buf.ptr; | |
432 while ((*bp1++ = c = *tem++) && c != '\n') | |
433 /* Drop out any \ newline sequence. */ | |
434 if (c == '\\' && *tem == '\n') | |
435 { | |
436 bp1--; | |
437 tem++; | |
438 } | |
439 *bp1 = 0; | |
440 | |
441 /* Does this entry refer to another terminal type's entry? | |
442 If something is found, copy it into heap and null-terminate it. */ | |
443 term = tgetst1 (find_capability (bp2, "tc"), 0); | |
444 } | |
445 | |
771 | 446 retry_close (fd); |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
1726
diff
changeset
|
447 xfree (buf.beg); |
428 | 448 |
449 if (malloc_size) | |
450 { | |
451 bp = (char *) xrealloc (bp, bp1 - bp + 1); | |
452 } | |
453 | |
454 ret: | |
455 term_entry = bp; | |
456 if (malloc_size) | |
457 /* #### yuck, why the hell are we casting a pointer to an int? */ | |
458 return (int) (long) bp; | |
459 return 1; | |
460 } | |
461 | |
462 /* Given file open on FD and buffer BUFP, | |
463 scan the file from the beginning until a line is found | |
464 that starts the entry for terminal type STRING. | |
465 Returns 1 if successful, with that line in BUFP, | |
466 or returns 0 if no entry found in the file. */ | |
467 | |
468 static int | |
469 scan_file (string, fd, bufp) | |
470 char *string; | |
471 int fd; | |
472 struct buffer *bufp; | |
473 { | |
474 char *end; | |
475 | |
476 bufp->ptr = bufp->beg; | |
477 bufp->full = 0; | |
478 bufp->ateof = 0; | |
479 *bufp->ptr = 0; | |
480 | |
481 lseek (fd, 0L, 0); | |
482 | |
483 while (!bufp->ateof) | |
484 { | |
485 /* Read a line into the buffer. */ | |
486 end = 0; | |
487 do | |
488 { | |
489 /* if it is continued, append another line to it, | |
490 until a non-continued line ends. */ | |
491 end = gobble_line (fd, bufp, end); | |
492 } | |
493 while (!bufp->ateof && end[-2] == '\\'); | |
494 | |
495 if (*bufp->ptr != '#' | |
496 && name_match (bufp->ptr, string)) | |
497 return 1; | |
498 | |
499 /* Discard the line just processed. */ | |
500 bufp->ptr = end; | |
501 } | |
502 return 0; | |
503 } | |
504 | |
505 /* Return nonzero if NAME is one of the names specified | |
506 by termcap entry LINE. */ | |
507 | |
508 static int | |
509 name_match (line, name) | |
510 char *line, *name; | |
511 { | |
512 char *tem; | |
513 | |
514 if (!compare_contin (line, name)) | |
515 return 1; | |
516 /* This line starts an entry. Is it the right one? */ | |
517 for (tem = line; *tem && *tem != '\n' && *tem != ':'; tem++) | |
518 if (*tem == '|' && !compare_contin (tem + 1, name)) | |
519 return 1; | |
520 | |
521 return 0; | |
522 } | |
523 | |
524 static int | |
525 compare_contin (str1, str2) | |
526 char *str1, *str2; | |
527 { | |
528 int c1, c2; | |
529 while (1) | |
530 { | |
531 c1 = *str1++; | |
532 c2 = *str2++; | |
533 while (c1 == '\\' && *str1 == '\n') | |
534 { | |
535 str1++; | |
536 while ((c1 = *str1++) == ' ' || c1 == '\t'); | |
537 } | |
538 if (c2 == '\0') | |
539 { | |
540 /* End of type being looked up. */ | |
541 if (c1 == '|' || c1 == ':') | |
542 /* If end of name in data base, we win. */ | |
543 return 0; | |
544 else | |
545 return 1; | |
546 } | |
547 else if (c1 != c2) | |
548 return 1; | |
549 } | |
550 } | |
551 | |
552 /* Make sure that the buffer <- BUFP contains a full line | |
553 of the file open on FD, starting at the place BUFP->ptr | |
554 points to. Can read more of the file, discard stuff before | |
555 BUFP->ptr, or make the buffer bigger. | |
556 | |
557 Returns the pointer to after the newline ending the line, | |
558 or to the end of the file, if there is no newline to end it. | |
559 | |
560 Can also merge on continuation lines. If APPEND_END is | |
561 nonzero, it points past the newline of a line that is | |
562 continued; we add another line onto it and regard the whole | |
563 thing as one line. The caller decides when a line is continued. */ | |
564 | |
565 static char * | |
566 gobble_line (fd, bufp, append_end) | |
567 int fd; | |
568 struct buffer *bufp; | |
569 char *append_end; | |
570 { | |
571 char *end; | |
572 int nread; | |
573 char *buf = bufp->beg; | |
574 char *tem; | |
575 | |
576 if (append_end == 0) | |
577 append_end = bufp->ptr; | |
578 | |
579 while (1) | |
580 { | |
581 end = append_end; | |
582 while (*end && *end != '\n') end++; | |
583 if (*end) | |
584 break; | |
585 if (bufp->ateof) | |
586 return buf + bufp->full; | |
587 if (bufp->ptr == buf) | |
588 { | |
589 if (bufp->full == bufp->size) | |
590 { | |
591 bufp->size *= 2; | |
592 /* Add 1 to size to ensure room for terminating null. */ | |
593 tem = (char *) xrealloc (buf, bufp->size + 1); | |
594 bufp->ptr = (bufp->ptr - buf) + tem; | |
595 append_end = (append_end - buf) + tem; | |
596 bufp->beg = buf = tem; | |
597 } | |
598 } | |
599 else | |
600 { | |
601 append_end -= bufp->ptr - buf; | |
602 memcpy (buf, bufp->ptr, bufp->full -= bufp->ptr - buf); | |
603 bufp->ptr = buf; | |
604 } | |
771 | 605 if (!(nread = retry_read (fd, buf + bufp->full, bufp->size - bufp->full))) |
428 | 606 bufp->ateof = 1; |
607 bufp->full += nread; | |
608 buf[bufp->full] = 0; | |
609 } | |
610 return end + 1; | |
611 } | |
612 | |
613 #ifdef TEST | |
614 | |
615 #include <stdio.h> | |
616 | |
617 main (argc, argv) | |
618 int argc; | |
619 char **argv; | |
620 { | |
621 char *term; | |
622 char *buf; | |
623 | |
624 term = argv[1]; | |
625 printf ("TERM: %s\n", term); | |
626 | |
627 buf = (char *) tgetent (0, term); | |
628 if ((int) buf <= 0) | |
629 { | |
630 printf ("No entry.\n"); | |
631 return 0; | |
632 } | |
633 | |
634 printf ("Entry: %s\n", buf); | |
635 | |
636 tprint ("cm"); | |
637 tprint ("AL"); | |
638 | |
639 printf ("co: %d\n", tgetnum ("co")); | |
640 printf ("am: %d\n", tgetflag ("am")); | |
641 } | |
642 | |
643 tprint (cap) | |
442 | 644 const char *cap; |
428 | 645 { |
646 char *x = tgetstr (cap, 0); | |
647 char *y; | |
648 | |
649 printf ("%s: ", cap); | |
650 if (x) | |
651 { | |
652 for (y = x; *y; y++) | |
653 if (*y <= ' ' || *y == 0177) | |
654 printf ("\\%0o", *y); | |
655 else | |
656 putchar (*y); | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
1726
diff
changeset
|
657 xfree (x); |
428 | 658 } |
659 else | |
660 printf ("none"); | |
661 putchar ('\n'); | |
662 } | |
663 | |
664 #endif /* TEST */ | |
665 |