From ab124e78b0271ddb904b761b31e5c9a0cf24e070 Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 30 Dec 1995 19:02:48 +0000 Subject: recording cvs-1.6 file death --- gnu/Makefile.inc | 4 - gnu/games/Makefile | 5 - gnu/games/Makefile.inc | 9 - gnu/games/chess/Makefile | 15 - gnu/games/chess/Xchess/Makefile | 136 - gnu/games/chess/Xchess/XCircle.c | 162 - gnu/games/chess/Xchess/board.c | 179 - gnu/games/chess/Xchess/button.c | 337 -- gnu/games/chess/Xchess/clock.c | 291 - gnu/games/chess/Xchess/control.c | 515 -- gnu/games/chess/Xchess/jail.c | 327 -- gnu/games/chess/Xchess/message.c | 101 - gnu/games/chess/Xchess/parse.c | 386 -- gnu/games/chess/Xchess/popup.c | 112 - gnu/games/chess/Xchess/program.c | 204 - gnu/games/chess/Xchess/record.c | 315 -- gnu/games/chess/Xchess/scrollText.c | 1877 ------- gnu/games/chess/Xchess/scrollText/scrollText.c | 1858 ------- gnu/games/chess/Xchess/std.c | 427 -- gnu/games/chess/Xchess/std.h | 105 - gnu/games/chess/Xchess/valid.c | 264 - gnu/games/chess/Xchess/window.c | 952 ---- gnu/games/chess/Xchess/xchess.c | 205 - gnu/games/chess/chess.6 | 161 - gnu/games/chess/gnuchess.c | 2307 -------- gnu/games/chess/gnuchess.h | 97 - gnu/games/chess/move.c | 357 -- gnu/games/chess/move.h | 81 - gnu/games/chess/nondsp.c | 791 --- gnu/games/chess/uxdsp.c | 933 ---- gnu/lib/libg++/libg++/regex.cc | 2757 ---------- gnu/lib/libmalloc/free.c | 210 - gnu/lib/libmalloc/realloc.c | 146 - gnu/lib/libreadline/README.FreeBSD | 21 - gnu/lib/libreadline/doc/ChangeLog | 8 - gnu/lib/libreadline/doc/hist.texinfo | 113 - gnu/lib/libreadline/doc/history.info | 744 --- gnu/lib/libreadline/doc/inc-hist.texi | 155 - gnu/lib/libreadline/doc/readline.info | 74 - gnu/lib/libreadline/doc/readline.info-1 | 1322 ----- gnu/lib/libreadline/doc/readline.info-2 | 978 ---- gnu/lib/libreadline/doc/rlman.texinfo | 111 - gnu/lib/libreadline/doc/texindex.c | 1666 ------ gnu/lib/libreadline/readline/chardefs.h | 89 - gnu/lib/libreadline/readline/history.h | 149 - gnu/lib/libreadline/readline/keymaps.h | 91 - gnu/lib/libreadline/readline/readline.h | 267 - gnu/lib/libreadline/readline/tilde.h | 38 - gnu/lib/libreadline/sysdep.h | 37 - gnu/lib/libreadline/tcsh_hack.readme | 27 - gnu/lib/libregex/doc/Makefile.in | 92 - gnu/lib/libregex/doc/regex.aux | 136 - gnu/lib/libregex/doc/regex.cps | 152 - gnu/lib/libregex/doc/regex.info | 2836 ---------- gnu/lib/libregex/doc/regex.texi | 3138 ----------- gnu/lib/libregex/test/TAGS | 373 -- gnu/libexec/uucp/common_sources/conf.h | 444 -- gnu/libexec/uucp/common_sources/tcp.c | 477 -- gnu/libexec/uucp/common_sources/tli.c | 582 -- gnu/libexec/uucp/contrib/uureroute | 91 - gnu/libexec/uucp/sample/call | 20 - gnu/libexec/uucp/sample/config | 88 - gnu/libexec/uucp/sample/dial | 35 - gnu/libexec/uucp/sample/dialcode | 19 - gnu/libexec/uucp/sample/passwd | 18 - gnu/libexec/uucp/sample/port | 41 - gnu/libexec/uucp/sample/sys1 | 44 - gnu/libexec/uucp/sample/sys2 | 51 - gnu/usr.bin/as/Makefile.gnu | 356 -- gnu/usr.bin/as/README.gnu | 133 - gnu/usr.bin/as/append.c | 37 - gnu/usr.bin/as/config/a.out.gnu.h | 261 - gnu/usr.bin/as/config/i386-opcode.h | 806 --- gnu/usr.bin/as/config/i386.c | 1946 ------- gnu/usr.bin/as/config/i386.h | 296 -- gnu/usr.bin/as/doc/Makefile.in | 172 - gnu/usr.bin/as/doc/a29k-coff.m4 | 14 - gnu/usr.bin/as/doc/a29k.m4 | 9 - gnu/usr.bin/as/doc/all.m4 | 20 - gnu/usr.bin/as/doc/as.texinfo | 6730 ------------------------ gnu/usr.bin/as/doc/config.status | 5 - gnu/usr.bin/as/doc/configure.in | 34 - gnu/usr.bin/as/doc/gen.m4 | 14 - gnu/usr.bin/as/doc/h8.m4 | 15 - gnu/usr.bin/as/doc/i80386.m4 | 12 - gnu/usr.bin/as/doc/i960.m4 | 16 - gnu/usr.bin/as/doc/m680x0.m4 | 8 - gnu/usr.bin/as/doc/none.m4 | 57 - gnu/usr.bin/as/doc/pretex.m4 | 268 - gnu/usr.bin/as/doc/sparc.m4 | 8 - gnu/usr.bin/as/doc/vax.m4 | 7 - gnu/usr.bin/as/doc/vintage.m4 | 11 - gnu/usr.bin/as/flonum-const.c | 157 - gnu/usr.bin/as/flonum-copy.c | 76 - gnu/usr.bin/as/md.h | 57 - gnu/usr.bin/as/objrecdef.h | 255 - gnu/usr.bin/awk/regex.c | 5070 ------------------ gnu/usr.bin/awk/regex.h | 505 -- gnu/usr.bin/cpio/mt.1 | 107 - gnu/usr.bin/cpio/rmt.c | 281 - gnu/usr.bin/cvs/lib/regex.h | 479 -- gnu/usr.bin/dialog/inputbox.c | 279 - gnu/usr.bin/diff/regex.c | 5171 ------------------ gnu/usr.bin/diff/regex.h | 490 -- gnu/usr.bin/gdb/ChangeLog | 4887 ----------------- gnu/usr.bin/gdb/Gdbinit | 15 - gnu/usr.bin/gdb/Makefile.dist | 371 -- gnu/usr.bin/gdb/Projects | 114 - gnu/usr.bin/gdb/README.gnu | 142 - gnu/usr.bin/gdb/XGdbinit.samp | 15 - gnu/usr.bin/gdb/Xgdb.ad | 8 - gnu/usr.bin/gdb/bfd/seclet.c | 185 - gnu/usr.bin/gdb/bfd/seclet.h | 55 - gnu/usr.bin/gdb/blockframe.c | 622 --- gnu/usr.bin/gdb/breakpoint.c | 1383 ----- gnu/usr.bin/gdb/command.c | 856 --- gnu/usr.bin/gdb/command.h | 77 - gnu/usr.bin/gdb/config/Makefile.i386 | 6 - gnu/usr.bin/gdb/config/default-dep.c | 585 -- gnu/usr.bin/gdb/config/i386-dep.c | 1275 ----- gnu/usr.bin/gdb/config/i386-pinsn.c | 1812 ------- gnu/usr.bin/gdb/config/i386bsd-dep.c | 1889 ------- gnu/usr.bin/gdb/config/m-i386-sv32.h | 28 - gnu/usr.bin/gdb/config/m-i386.h | 394 -- gnu/usr.bin/gdb/config/m-i386bsd.h | 375 -- gnu/usr.bin/gdb/config/m-i386g-sv32.h | 28 - gnu/usr.bin/gdb/config/m-i386gas.h | 37 - gnu/usr.bin/gdb/copying.c | 215 - gnu/usr.bin/gdb/core.c | 581 -- gnu/usr.bin/gdb/cplus-dem.c | 996 ---- gnu/usr.bin/gdb/dbxread.c | 5727 -------------------- gnu/usr.bin/gdb/defs.h | 122 - gnu/usr.bin/gdb/doc/ChangeLog | 783 --- gnu/usr.bin/gdb/doc/Makefile.in | 327 -- gnu/usr.bin/gdb/doc/a4rc.sed | 11 - gnu/usr.bin/gdb/doc/config.status | 5 - gnu/usr.bin/gdb/doc/configure.in | 7 - gnu/usr.bin/gdb/doc/gdb.info | 213 - gnu/usr.bin/gdb/doc/gdb.info-1 | 1304 ----- gnu/usr.bin/gdb/doc/gdb.info-2 | 1165 ---- gnu/usr.bin/gdb/doc/gdb.info-3 | 1264 ----- gnu/usr.bin/gdb/doc/gdb.info-4 | 1349 ----- gnu/usr.bin/gdb/doc/gdb.info-5 | 1215 ----- gnu/usr.bin/gdb/doc/gdb.info-6 | 1220 ----- gnu/usr.bin/gdb/doc/gdb.info-7 | 1233 ----- gnu/usr.bin/gdb/doc/gdb.info-8 | 657 --- gnu/usr.bin/gdb/doc/libgdb.texinfo | 1471 ------ gnu/usr.bin/gdb/doc/lpsrc.sed | 13 - gnu/usr.bin/gdb/doc/psrc.sed | 13 - gnu/usr.bin/gdb/doc/refcard.ps | 798 --- gnu/usr.bin/gdb/doc/refcard.tex | 646 --- gnu/usr.bin/gdb/environ.c | 185 - gnu/usr.bin/gdb/environ.h | 39 - gnu/usr.bin/gdb/eval.c | 1065 ---- gnu/usr.bin/gdb/expprint.c | 324 -- gnu/usr.bin/gdb/expread.y | 1782 ------- gnu/usr.bin/gdb/expression.h | 191 - gnu/usr.bin/gdb/findvar.c | 579 -- gnu/usr.bin/gdb/frame.h | 115 - gnu/usr.bin/gdb/gdb.1 | 3 - gnu/usr.bin/gdb/gdb/c-exp.tab.c | 2648 ---------- gnu/usr.bin/gdb/gdb/ch-exp.tab.c | 2854 ---------- gnu/usr.bin/gdb/gdb/freebsd-solib.c | 1469 ------ gnu/usr.bin/gdb/gdb/m2-exp.tab.c | 1991 ------- gnu/usr.bin/gdb/gdb/putenv.c | 111 - gnu/usr.bin/gdb/gdb/regex.c | 1744 ------ gnu/usr.bin/gdb/gdb/regex.h | 181 - gnu/usr.bin/gdb/gdb/y.tab.h | 65 - gnu/usr.bin/gdb/getpagesize.h | 25 - gnu/usr.bin/gdb/infcmd.c | 1204 ----- gnu/usr.bin/gdb/inferior.h | 142 - gnu/usr.bin/gdb/inflow.c | 569 -- gnu/usr.bin/gdb/infrun.c | 1459 ----- gnu/usr.bin/gdb/kgdb_proto.h | 63 - gnu/usr.bin/gdb/main.c | 2241 -------- gnu/usr.bin/gdb/ngdb.i386/Makefile | 27 - gnu/usr.bin/gdb/obstack.c | 313 -- gnu/usr.bin/gdb/obstack.h | 372 -- gnu/usr.bin/gdb/printcmd.c | 1867 ------- gnu/usr.bin/gdb/readline/ChangeLog | 98 - gnu/usr.bin/gdb/readline/Makefile.gnu | 114 - gnu/usr.bin/gdb/readline/chardefs.h | 50 - gnu/usr.bin/gdb/readline/emacs_keymap.c | 472 -- gnu/usr.bin/gdb/readline/funmap.c | 217 - gnu/usr.bin/gdb/readline/history.c | 1462 ----- gnu/usr.bin/gdb/readline/history.h | 108 - gnu/usr.bin/gdb/readline/keymaps.c | 172 - gnu/usr.bin/gdb/readline/keymaps.h | 53 - gnu/usr.bin/gdb/readline/readline.c | 5557 ------------------- gnu/usr.bin/gdb/readline/readline.h | 161 - gnu/usr.bin/gdb/readline/vi_keymap.c | 484 -- gnu/usr.bin/gdb/readline/vi_mode.c | 875 --- gnu/usr.bin/gdb/regex.c | 1738 ------ gnu/usr.bin/gdb/regex.h | 185 - gnu/usr.bin/gdb/remote-sl.c | 10 - gnu/usr.bin/gdb/remote.c | 626 --- gnu/usr.bin/gdb/source.c | 1166 ---- gnu/usr.bin/gdb/stab.def | 115 - gnu/usr.bin/gdb/stack.c | 960 ---- gnu/usr.bin/gdb/symmisc.c | 584 -- gnu/usr.bin/gdb/symseg.h | 523 -- gnu/usr.bin/gdb/symtab.c | 2473 --------- gnu/usr.bin/gdb/symtab.h | 384 -- gnu/usr.bin/gdb/utils.c | 1096 ---- gnu/usr.bin/gdb/valarith.c | 690 --- gnu/usr.bin/gdb/valops.c | 1418 ----- gnu/usr.bin/gdb/valprint.c | 1430 ----- gnu/usr.bin/gdb/value.h | 212 - gnu/usr.bin/gdb/values.c | 1059 ---- gnu/usr.bin/gdb/version.c | 20 - gnu/usr.bin/gdb/wait.h | 81 - gnu/usr.bin/gdb/xgdb/Makefile | 33 - gnu/usr.bin/gdb/xgdb/xgdb.c | 700 --- gnu/usr.bin/grep/regex.c | 4987 ------------------ gnu/usr.bin/grep/regex.h | 490 -- gnu/usr.bin/gzip/gzexe.in | 151 - gnu/usr.bin/ld/TODO | 4 - gnu/usr.bin/man/catman/catman | 36 - gnu/usr.bin/man/catman/catman.sh | 43 - gnu/usr.bin/man/makewhatis/makewhatis.sh | 120 - gnu/usr.bin/perl/perl/usub/Makefile | 16 - gnu/usr.bin/pr/Makefile | 11 - gnu/usr.bin/pr/error.c | 117 - gnu/usr.bin/pr/getopt.c | 757 --- gnu/usr.bin/pr/getopt1.c | 187 - gnu/usr.bin/pr/pr.1 | 103 - gnu/usr.bin/pr/pr.c | 1920 ------- gnu/usr.bin/pr/system.h | 200 - gnu/usr.bin/pr/version.c | 13 - gnu/usr.bin/pr/xmalloc.c | 88 - gnu/usr.bin/ptx/regex.h | 490 -- gnu/usr.bin/send-pr/send-pr.info | 1604 ------ gnu/usr.bin/send-pr/send-pr.texi | 657 --- gnu/usr.bin/tar/regex.c | 4923 ----------------- gnu/usr.bin/yppush/yp.h | 292 - gnu/usr.bin/yppush/yp_clnt.c | 216 - gnu/usr.bin/yppush/yp_xdr.c | 477 -- gnu/usr.bin/yppush/ypclnt.c | 128 - gnu/usr.bin/yppush/yppush_s.c | 156 - gnu/usr.sbin/yppasswdd/yppasswd_xdr.c | 57 - gnu/usr.sbin/ypserv/Makefile | 20 - gnu/usr.sbin/ypserv/Makefile.yp | 394 -- gnu/usr.sbin/ypserv/dnslookup.c | 112 - gnu/usr.sbin/ypserv/mknetid | 36 - gnu/usr.sbin/ypserv/server.c | 1384 ----- gnu/usr.sbin/ypserv/svc_run.c | 85 - gnu/usr.sbin/ypserv/system.h | 67 - gnu/usr.sbin/ypserv/yp.h | 611 --- gnu/usr.sbin/ypserv/yp_svc.c | 430 -- gnu/usr.sbin/ypserv/yp_xdr.c | 415 -- gnu/usr.sbin/ypserv/ypserv.8 | 293 -- 251 files changed, 162853 deletions(-) delete mode 100644 gnu/Makefile.inc delete mode 100644 gnu/games/Makefile delete mode 100644 gnu/games/Makefile.inc delete mode 100644 gnu/games/chess/Makefile delete mode 100644 gnu/games/chess/Xchess/Makefile delete mode 100644 gnu/games/chess/Xchess/XCircle.c delete mode 100644 gnu/games/chess/Xchess/board.c delete mode 100644 gnu/games/chess/Xchess/button.c delete mode 100644 gnu/games/chess/Xchess/clock.c delete mode 100644 gnu/games/chess/Xchess/control.c delete mode 100644 gnu/games/chess/Xchess/jail.c delete mode 100644 gnu/games/chess/Xchess/message.c delete mode 100644 gnu/games/chess/Xchess/parse.c delete mode 100644 gnu/games/chess/Xchess/popup.c delete mode 100644 gnu/games/chess/Xchess/program.c delete mode 100644 gnu/games/chess/Xchess/record.c delete mode 100644 gnu/games/chess/Xchess/scrollText.c delete mode 100644 gnu/games/chess/Xchess/scrollText/scrollText.c delete mode 100644 gnu/games/chess/Xchess/std.c delete mode 100644 gnu/games/chess/Xchess/std.h delete mode 100644 gnu/games/chess/Xchess/valid.c delete mode 100644 gnu/games/chess/Xchess/window.c delete mode 100644 gnu/games/chess/Xchess/xchess.c delete mode 100644 gnu/games/chess/chess.6 delete mode 100644 gnu/games/chess/gnuchess.c delete mode 100644 gnu/games/chess/gnuchess.h delete mode 100644 gnu/games/chess/move.c delete mode 100644 gnu/games/chess/move.h delete mode 100644 gnu/games/chess/nondsp.c delete mode 100644 gnu/games/chess/uxdsp.c delete mode 100644 gnu/lib/libg++/libg++/regex.cc delete mode 100644 gnu/lib/libmalloc/free.c delete mode 100644 gnu/lib/libmalloc/realloc.c delete mode 100644 gnu/lib/libreadline/README.FreeBSD delete mode 100644 gnu/lib/libreadline/doc/ChangeLog delete mode 100644 gnu/lib/libreadline/doc/hist.texinfo delete mode 100644 gnu/lib/libreadline/doc/history.info delete mode 100644 gnu/lib/libreadline/doc/inc-hist.texi delete mode 100644 gnu/lib/libreadline/doc/readline.info delete mode 100644 gnu/lib/libreadline/doc/readline.info-1 delete mode 100644 gnu/lib/libreadline/doc/readline.info-2 delete mode 100644 gnu/lib/libreadline/doc/rlman.texinfo delete mode 100644 gnu/lib/libreadline/doc/texindex.c delete mode 100644 gnu/lib/libreadline/readline/chardefs.h delete mode 100644 gnu/lib/libreadline/readline/history.h delete mode 100644 gnu/lib/libreadline/readline/keymaps.h delete mode 100644 gnu/lib/libreadline/readline/readline.h delete mode 100644 gnu/lib/libreadline/readline/tilde.h delete mode 100644 gnu/lib/libreadline/sysdep.h delete mode 100644 gnu/lib/libreadline/tcsh_hack.readme delete mode 100644 gnu/lib/libregex/doc/Makefile.in delete mode 100644 gnu/lib/libregex/doc/regex.aux delete mode 100644 gnu/lib/libregex/doc/regex.cps delete mode 100644 gnu/lib/libregex/doc/regex.info delete mode 100644 gnu/lib/libregex/doc/regex.texi delete mode 100644 gnu/lib/libregex/test/TAGS delete mode 100644 gnu/libexec/uucp/common_sources/conf.h delete mode 100644 gnu/libexec/uucp/common_sources/tcp.c delete mode 100644 gnu/libexec/uucp/common_sources/tli.c delete mode 100755 gnu/libexec/uucp/contrib/uureroute delete mode 100644 gnu/libexec/uucp/sample/call delete mode 100644 gnu/libexec/uucp/sample/config delete mode 100644 gnu/libexec/uucp/sample/dial delete mode 100644 gnu/libexec/uucp/sample/dialcode delete mode 100644 gnu/libexec/uucp/sample/passwd delete mode 100644 gnu/libexec/uucp/sample/port delete mode 100644 gnu/libexec/uucp/sample/sys1 delete mode 100644 gnu/libexec/uucp/sample/sys2 delete mode 100644 gnu/usr.bin/as/Makefile.gnu delete mode 100644 gnu/usr.bin/as/README.gnu delete mode 100644 gnu/usr.bin/as/append.c delete mode 100644 gnu/usr.bin/as/config/a.out.gnu.h delete mode 100644 gnu/usr.bin/as/config/i386-opcode.h delete mode 100644 gnu/usr.bin/as/config/i386.c delete mode 100644 gnu/usr.bin/as/config/i386.h delete mode 100644 gnu/usr.bin/as/doc/Makefile.in delete mode 100644 gnu/usr.bin/as/doc/a29k-coff.m4 delete mode 100644 gnu/usr.bin/as/doc/a29k.m4 delete mode 100644 gnu/usr.bin/as/doc/all.m4 delete mode 100644 gnu/usr.bin/as/doc/as.texinfo delete mode 100644 gnu/usr.bin/as/doc/config.status delete mode 100644 gnu/usr.bin/as/doc/configure.in delete mode 100644 gnu/usr.bin/as/doc/gen.m4 delete mode 100644 gnu/usr.bin/as/doc/h8.m4 delete mode 100644 gnu/usr.bin/as/doc/i80386.m4 delete mode 100644 gnu/usr.bin/as/doc/i960.m4 delete mode 100644 gnu/usr.bin/as/doc/m680x0.m4 delete mode 100644 gnu/usr.bin/as/doc/none.m4 delete mode 100644 gnu/usr.bin/as/doc/pretex.m4 delete mode 100644 gnu/usr.bin/as/doc/sparc.m4 delete mode 100644 gnu/usr.bin/as/doc/vax.m4 delete mode 100644 gnu/usr.bin/as/doc/vintage.m4 delete mode 100644 gnu/usr.bin/as/flonum-const.c delete mode 100644 gnu/usr.bin/as/flonum-copy.c delete mode 100644 gnu/usr.bin/as/md.h delete mode 100644 gnu/usr.bin/as/objrecdef.h delete mode 100644 gnu/usr.bin/awk/regex.c delete mode 100644 gnu/usr.bin/awk/regex.h delete mode 100644 gnu/usr.bin/cpio/mt.1 delete mode 100644 gnu/usr.bin/cpio/rmt.c delete mode 100644 gnu/usr.bin/cvs/lib/regex.h delete mode 100644 gnu/usr.bin/dialog/inputbox.c delete mode 100644 gnu/usr.bin/diff/regex.c delete mode 100644 gnu/usr.bin/diff/regex.h delete mode 100644 gnu/usr.bin/gdb/ChangeLog delete mode 100644 gnu/usr.bin/gdb/Gdbinit delete mode 100644 gnu/usr.bin/gdb/Makefile.dist delete mode 100644 gnu/usr.bin/gdb/Projects delete mode 100644 gnu/usr.bin/gdb/README.gnu delete mode 100644 gnu/usr.bin/gdb/XGdbinit.samp delete mode 100644 gnu/usr.bin/gdb/Xgdb.ad delete mode 100644 gnu/usr.bin/gdb/bfd/seclet.c delete mode 100644 gnu/usr.bin/gdb/bfd/seclet.h delete mode 100644 gnu/usr.bin/gdb/blockframe.c delete mode 100644 gnu/usr.bin/gdb/breakpoint.c delete mode 100644 gnu/usr.bin/gdb/command.c delete mode 100644 gnu/usr.bin/gdb/command.h delete mode 100644 gnu/usr.bin/gdb/config/Makefile.i386 delete mode 100644 gnu/usr.bin/gdb/config/default-dep.c delete mode 100644 gnu/usr.bin/gdb/config/i386-dep.c delete mode 100644 gnu/usr.bin/gdb/config/i386-pinsn.c delete mode 100644 gnu/usr.bin/gdb/config/i386bsd-dep.c delete mode 100644 gnu/usr.bin/gdb/config/m-i386-sv32.h delete mode 100644 gnu/usr.bin/gdb/config/m-i386.h delete mode 100644 gnu/usr.bin/gdb/config/m-i386bsd.h delete mode 100644 gnu/usr.bin/gdb/config/m-i386g-sv32.h delete mode 100644 gnu/usr.bin/gdb/config/m-i386gas.h delete mode 100644 gnu/usr.bin/gdb/copying.c delete mode 100644 gnu/usr.bin/gdb/core.c delete mode 100644 gnu/usr.bin/gdb/cplus-dem.c delete mode 100644 gnu/usr.bin/gdb/dbxread.c delete mode 100644 gnu/usr.bin/gdb/defs.h delete mode 100644 gnu/usr.bin/gdb/doc/ChangeLog delete mode 100644 gnu/usr.bin/gdb/doc/Makefile.in delete mode 100644 gnu/usr.bin/gdb/doc/a4rc.sed delete mode 100755 gnu/usr.bin/gdb/doc/config.status delete mode 100644 gnu/usr.bin/gdb/doc/configure.in delete mode 100644 gnu/usr.bin/gdb/doc/gdb.info delete mode 100644 gnu/usr.bin/gdb/doc/gdb.info-1 delete mode 100644 gnu/usr.bin/gdb/doc/gdb.info-2 delete mode 100644 gnu/usr.bin/gdb/doc/gdb.info-3 delete mode 100644 gnu/usr.bin/gdb/doc/gdb.info-4 delete mode 100644 gnu/usr.bin/gdb/doc/gdb.info-5 delete mode 100644 gnu/usr.bin/gdb/doc/gdb.info-6 delete mode 100644 gnu/usr.bin/gdb/doc/gdb.info-7 delete mode 100644 gnu/usr.bin/gdb/doc/gdb.info-8 delete mode 100644 gnu/usr.bin/gdb/doc/libgdb.texinfo delete mode 100644 gnu/usr.bin/gdb/doc/lpsrc.sed delete mode 100644 gnu/usr.bin/gdb/doc/psrc.sed delete mode 100644 gnu/usr.bin/gdb/doc/refcard.ps delete mode 100644 gnu/usr.bin/gdb/doc/refcard.tex delete mode 100644 gnu/usr.bin/gdb/environ.c delete mode 100644 gnu/usr.bin/gdb/environ.h delete mode 100644 gnu/usr.bin/gdb/eval.c delete mode 100644 gnu/usr.bin/gdb/expprint.c delete mode 100644 gnu/usr.bin/gdb/expread.y delete mode 100644 gnu/usr.bin/gdb/expression.h delete mode 100644 gnu/usr.bin/gdb/findvar.c delete mode 100644 gnu/usr.bin/gdb/frame.h delete mode 100644 gnu/usr.bin/gdb/gdb.1 delete mode 100644 gnu/usr.bin/gdb/gdb/c-exp.tab.c delete mode 100644 gnu/usr.bin/gdb/gdb/ch-exp.tab.c delete mode 100644 gnu/usr.bin/gdb/gdb/freebsd-solib.c delete mode 100644 gnu/usr.bin/gdb/gdb/m2-exp.tab.c delete mode 100644 gnu/usr.bin/gdb/gdb/putenv.c delete mode 100644 gnu/usr.bin/gdb/gdb/regex.c delete mode 100644 gnu/usr.bin/gdb/gdb/regex.h delete mode 100644 gnu/usr.bin/gdb/gdb/y.tab.h delete mode 100644 gnu/usr.bin/gdb/getpagesize.h delete mode 100644 gnu/usr.bin/gdb/infcmd.c delete mode 100644 gnu/usr.bin/gdb/inferior.h delete mode 100644 gnu/usr.bin/gdb/inflow.c delete mode 100644 gnu/usr.bin/gdb/infrun.c delete mode 100644 gnu/usr.bin/gdb/kgdb_proto.h delete mode 100644 gnu/usr.bin/gdb/main.c delete mode 100644 gnu/usr.bin/gdb/ngdb.i386/Makefile delete mode 100644 gnu/usr.bin/gdb/obstack.c delete mode 100644 gnu/usr.bin/gdb/obstack.h delete mode 100644 gnu/usr.bin/gdb/printcmd.c delete mode 100644 gnu/usr.bin/gdb/readline/ChangeLog delete mode 100644 gnu/usr.bin/gdb/readline/Makefile.gnu delete mode 100644 gnu/usr.bin/gdb/readline/chardefs.h delete mode 100644 gnu/usr.bin/gdb/readline/emacs_keymap.c delete mode 100644 gnu/usr.bin/gdb/readline/funmap.c delete mode 100644 gnu/usr.bin/gdb/readline/history.c delete mode 100644 gnu/usr.bin/gdb/readline/history.h delete mode 100644 gnu/usr.bin/gdb/readline/keymaps.c delete mode 100644 gnu/usr.bin/gdb/readline/keymaps.h delete mode 100644 gnu/usr.bin/gdb/readline/readline.c delete mode 100644 gnu/usr.bin/gdb/readline/readline.h delete mode 100644 gnu/usr.bin/gdb/readline/vi_keymap.c delete mode 100644 gnu/usr.bin/gdb/readline/vi_mode.c delete mode 100644 gnu/usr.bin/gdb/regex.c delete mode 100644 gnu/usr.bin/gdb/regex.h delete mode 100644 gnu/usr.bin/gdb/remote-sl.c delete mode 100644 gnu/usr.bin/gdb/remote.c delete mode 100644 gnu/usr.bin/gdb/source.c delete mode 100644 gnu/usr.bin/gdb/stab.def delete mode 100644 gnu/usr.bin/gdb/stack.c delete mode 100644 gnu/usr.bin/gdb/symmisc.c delete mode 100644 gnu/usr.bin/gdb/symseg.h delete mode 100644 gnu/usr.bin/gdb/symtab.c delete mode 100644 gnu/usr.bin/gdb/symtab.h delete mode 100644 gnu/usr.bin/gdb/utils.c delete mode 100644 gnu/usr.bin/gdb/valarith.c delete mode 100644 gnu/usr.bin/gdb/valops.c delete mode 100644 gnu/usr.bin/gdb/valprint.c delete mode 100644 gnu/usr.bin/gdb/value.h delete mode 100644 gnu/usr.bin/gdb/values.c delete mode 100644 gnu/usr.bin/gdb/version.c delete mode 100644 gnu/usr.bin/gdb/wait.h delete mode 100644 gnu/usr.bin/gdb/xgdb/Makefile delete mode 100644 gnu/usr.bin/gdb/xgdb/xgdb.c delete mode 100644 gnu/usr.bin/grep/regex.c delete mode 100644 gnu/usr.bin/grep/regex.h delete mode 100644 gnu/usr.bin/gzip/gzexe.in delete mode 100644 gnu/usr.bin/ld/TODO delete mode 100644 gnu/usr.bin/man/catman/catman delete mode 100644 gnu/usr.bin/man/catman/catman.sh delete mode 100644 gnu/usr.bin/man/makewhatis/makewhatis.sh delete mode 100644 gnu/usr.bin/perl/perl/usub/Makefile delete mode 100644 gnu/usr.bin/pr/Makefile delete mode 100644 gnu/usr.bin/pr/error.c delete mode 100644 gnu/usr.bin/pr/getopt.c delete mode 100644 gnu/usr.bin/pr/getopt1.c delete mode 100644 gnu/usr.bin/pr/pr.1 delete mode 100644 gnu/usr.bin/pr/pr.c delete mode 100644 gnu/usr.bin/pr/system.h delete mode 100644 gnu/usr.bin/pr/version.c delete mode 100644 gnu/usr.bin/pr/xmalloc.c delete mode 100644 gnu/usr.bin/ptx/regex.h delete mode 100644 gnu/usr.bin/send-pr/send-pr.info delete mode 100644 gnu/usr.bin/send-pr/send-pr.texi delete mode 100644 gnu/usr.bin/tar/regex.c delete mode 100644 gnu/usr.bin/yppush/yp.h delete mode 100644 gnu/usr.bin/yppush/yp_clnt.c delete mode 100644 gnu/usr.bin/yppush/yp_xdr.c delete mode 100644 gnu/usr.bin/yppush/ypclnt.c delete mode 100644 gnu/usr.bin/yppush/yppush_s.c delete mode 100644 gnu/usr.sbin/yppasswdd/yppasswd_xdr.c delete mode 100644 gnu/usr.sbin/ypserv/Makefile delete mode 100644 gnu/usr.sbin/ypserv/Makefile.yp delete mode 100644 gnu/usr.sbin/ypserv/dnslookup.c delete mode 100644 gnu/usr.sbin/ypserv/mknetid delete mode 100644 gnu/usr.sbin/ypserv/server.c delete mode 100644 gnu/usr.sbin/ypserv/svc_run.c delete mode 100644 gnu/usr.sbin/ypserv/system.h delete mode 100644 gnu/usr.sbin/ypserv/yp.h delete mode 100644 gnu/usr.sbin/ypserv/yp_svc.c delete mode 100644 gnu/usr.sbin/ypserv/yp_xdr.c delete mode 100644 gnu/usr.sbin/ypserv/ypserv.8 (limited to 'gnu') diff --git a/gnu/Makefile.inc b/gnu/Makefile.inc deleted file mode 100644 index 8eb90e8..0000000 --- a/gnu/Makefile.inc +++ /dev/null @@ -1,4 +0,0 @@ -# @(#)Makefile.inc 5.1 (Berkeley) 5/11/90 - -BINDIR?= /usr/bin -LIBDIR?= /usr/lib diff --git a/gnu/games/Makefile b/gnu/games/Makefile deleted file mode 100644 index 4a7577e..0000000 --- a/gnu/games/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# $Id$ - -SUBDIR= chess - -.include diff --git a/gnu/games/Makefile.inc b/gnu/games/Makefile.inc deleted file mode 100644 index 4437a84..0000000 --- a/gnu/games/Makefile.inc +++ /dev/null @@ -1,9 +0,0 @@ -# $Id$ - -BINOWN?= games -.if defined(HIDEGAME) -BINDIR?= /usr/games/hide -BINMODE?= 4700 -.else -BINDIR?= /usr/games -.endif diff --git a/gnu/games/chess/Makefile b/gnu/games/chess/Makefile deleted file mode 100644 index a40e597..0000000 --- a/gnu/games/chess/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# @(#)Makefile 5.4 (Berkeley) 5/11/90 - -PROG= chess -SRCS= gnuchess.c uxdsp.c move.c -CFLAGS+=-DNEWMOVE=12 -MAN6= chess.6 -DPADD= ${LIBCURSES} ${LIBTERMCAP} -LDADD= -lcurses -ltermcap -HIDEGAME=hidegame - -beforeinstall: - ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 \ - ${.CURDIR}/gnuchess.book ${DESTDIR}/usr/share/games - -.include diff --git a/gnu/games/chess/Xchess/Makefile b/gnu/games/chess/Xchess/Makefile deleted file mode 100644 index c4d0d78..0000000 --- a/gnu/games/chess/Xchess/Makefile +++ /dev/null @@ -1,136 +0,0 @@ -# RCS Info: $Revision: 1.3 $ on $Date: 1995/05/30 04:41:16 $ -# $Source: /home/ncvs/src/gnu/games/chess/Xchess/Makefile,v $ -# Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group -# -# Makefile for xchess. - -#CC = cc -O -m68010 -L/pub.MC68010/lib -L/usr.MC68010/lib -CC = cc -O - -CFILES =\ - board.c\ - button.c\ - clock.c\ - control.c\ - jail.c\ - message.c\ - parse.c\ - popup.c\ - program.c\ - record.c\ - std.c\ - valid.c\ - window.c\ - XCircle.c - -COBJS =\ - board.o\ - button.o\ - clock.o\ - control.o\ - jail.o\ - message.o\ - parse.o\ - popup.o\ - program.o\ - record.o\ - std.o\ - valid.o\ - window.o\ - XCircle.o - -HFILES =\ - std.h\ - xchess.h - -SOURCE = $(CFILES) - -ALLFILES = $(SOURCE) $(HFILES) - -INCLUDE = -I. -I${X11BASE}/include - -DEFINES = -DDEF_PROGRAM=\"/usr/games/chess\" - -CFLAGS = $(DEFINES) $(INCLUDE) -LINTFLAGS = -u -z -lc -DLINT $(DEFINES) $(INCLUDE) -LINTLIB = ../lib/llib-lX.ln -#LDFLAGS = -L/usr2/X/lib -z -lX -lm -LDFLAGS = -L${X11BASE}/lib -loldX -lX11 -z -lm -GPLDFLAGS = -z -loldX -lX11 -lXMenu_p -lX -lm_p -g -pg - -.c.o: $*.c - $(CC) $(CFLAGS) -c $*.c -.s.o: $*.s - $(CC) $(CFLAGS) -c $*.s - -all: xchess scrollText.o - @echo "All done." - -everything: all tags depend lint wc - @echo "All done." - -xchess: xchess.o $(COBJS) scrollText.o - $(CC) -o xchess xchess.o $(COBJS) scrollText.o \ - $(LDFLAGS) - -scrollText.o: scrollText.h scrollText.c - -gpxchess: xchess.o $(COBJS) - $(CC) -o gpxchess xchess.o $(COBJS) scrollText/libScroll.a \ - $(GPLDFLAGS) - -lint: $(SOURCE) - lint $(LINTFLAGS) $(SOURCE) $(LINTLIB) | \ - grep -v "multiply declared" - -qgrind: $(ALLFILES) - qgrind -lc $(ALLFILES) - -vgrind: $(ALLFILES) - vgrind -lc $(ALLFILES) - -opt: all - -reopt: all - -install: all - -source: $(SOURCE) - -tags: $(ALLFILES) - ctags -w -t *.c *.h > /dev/null 2>&1 - -wc: $(ALLFILES) - @wc $(ALLFILES) - -print: $(ALLFILES) - @pr $(ALLFILES) - -clean: - rm -f *.o *.a *.out xchess tags foo tmp - -tar: - tar -cf xchess.tar Makefile *.h *.c *.bitmap *.icon *.cur *.1\ - scrollText/Makefile scrollText/*.h scrollText/*.c scrollText/*.1\ - scrollText/*.3 - -$(ALLFILES): - co $@ - -depend: $(SOURCE) - cc -M $(CFLAGS) $(CFILES) > makedep - echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep - echo '$$r makedep' >>eddep - echo 'w' >>eddep - ed - Makefile < eddep - rm eddep makedep - echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile - echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile - echo '# see make depend above' >> Makefile - -#----------------------------------------------------------------- -# DO NOT DELETE THIS LINE -- make depend uses it -# DEPENDENCIES MUST END AT END OF FILE - -xchess.o $(COBJS): $(HFILES) - diff --git a/gnu/games/chess/Xchess/XCircle.c b/gnu/games/chess/Xchess/XCircle.c deleted file mode 100644 index 5514855..0000000 --- a/gnu/games/chess/Xchess/XCircle.c +++ /dev/null @@ -1,162 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.2 $ on $Date: 1995/05/30 04:41:18 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/XCircle.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - */ - -#include -#include -#include -#include - -#define PI 3.1415926535897932384 - -#define MAXVERTS 1000 - -void -XCircle(win, x, y, rad, start, end, width, height, pixel, func, planes) - Window win; - int x, y, rad; - double start, end; - int pixel; - int width, height; - int func, planes; -{ - Vertex verts[MAXVERTS]; - double xp, yp, ang; - int lx, ly, xpt, ypt, i; - double gradincr = 2 / (double) rad; - int bk = 0; - - while (end >= PI * 2) - end -= PI * 2; - while (start >= PI * 2) - start -= PI * 2; - while (end < 0) - end += PI * 2; - while (start < 0) - start += PI * 2; - if (end == start) { - if (end < gradincr) - end = end + PI * 2 - gradincr / 2; - else - end -= gradincr / 2; - } - for (ang = start, i = 0; i < MAXVERTS; ) { - - xp = x + rad * cos(ang); - yp = y + rad * sin(ang); - - xpt = xp; - ypt = yp; - - if (!i || (lx != xpt) || (ly != ypt)) { - verts[i].x = xpt; - verts[i].y = ypt; - verts[i].flags = 0; - i++; - } - lx = xpt; - ly = ypt; - if (bk) - break; - if (((ang < end) && (ang + gradincr > end)) || ((end < start) - && (ang + gradincr > 2 * PI) - && (ang + gradincr - 2 * PI > end))) { - ang = end; - bk = 1; - } else if (ang == end) { - break; - } else { - ang += gradincr; - } - if (ang >= PI * 2) - ang -= PI * 2; - } - - /* Now draw the thing.. */ - XDraw(win, verts, i, width, height, pixel, func, planes); - - return; -} - -#ifdef notdef /* VertexCurved is screwed up */ - -void -XCircle(win, x, y, rad, start, end, width, height, pixel, func, planes) - Window win; - int x, y, rad; - double start, end; - int pixel; - int width, height; - int func, planes; -{ - Vertex verts[7]; - int i, j, sv, ev; - int dp = 0; - - for (i = j = 0 ; i < 4; i++) { - verts[j].x = x + rad * cos((double) (PI * i / 2)); - verts[j].y = y + rad * sin((double) (PI * i / 2)); - verts[j].flags = VertexCurved; - if ((start >= PI * i / 2) && (start < PI * (i + 1) / 2) && - (start != end)) { - j++; - verts[j].x = x + rad * cos(start); - verts[j].y = y + rad * sin(start); - verts[j].flags = VertexCurved; - sv = j; - } else if ((end >= PI * i / 2) && (end < PI * (i + 1) / 2) - && (start != end)) { - j++; - verts[j].x = x + rad * cos(end); - verts[j].y = y + rad * sin(end); - verts[j].flags = VertexCurved; - ev = j; - } - j++; - } - verts[0].flags |= VertexStartClosed; - verts[j].x = verts[0].x; - verts[j].y = verts[0].y; - verts[j].flags = (verts[0].flags & ~VertexStartClosed) | - VertexEndClosed; - for (i = 0; i < 15; i++) { - if (dp) - verts[i % 7].flags |= VertexDontDraw; - if (i % 7 == ev) - dp = 1; - else if (i % 7 == sv) - dp = 0; - } - XDraw(win, verts, j + 1, width, height, pixel, func, planes); - - return; -} - -#endif notdef - diff --git a/gnu/games/chess/Xchess/board.c b/gnu/games/chess/Xchess/board.c deleted file mode 100644 index fab97d8..0000000 --- a/gnu/games/chess/Xchess/board.c +++ /dev/null @@ -1,179 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/board.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - * Stuff to deal with the board. - */ - -#include "xchess.h" - -board *chessboard; - -void -board_setup() -{ - chessboard = alloc(board); - board_init(chessboard); - return; -} - -void -board_init(b) - board *b; -{ - int i, j; - - for (i = 0; i < 2; i++) - for (j = 0; j < SIZE; j++) - b->square[i][j].color = BLACK; - for (i = 2; i < 6; i++) - for (j = 0; j < SIZE; j++) - b->square[i][j].color = NONE; - for (i = 6; i < 8; i++) - for (j = 0; j < SIZE; j++) - b->square[i][j].color = WHITE; - for (i = 0; i < SIZE; i++) - b->square[1][i].type = b->square[6][i].type = - PAWN; - b->square[0][0].type = b->square[7][0].type = ROOK; - b->square[0][1].type = b->square[7][1].type = KNIGHT; - b->square[0][2].type = b->square[7][2].type = BISHOP; - b->square[0][3].type = b->square[7][3].type = QUEEN; - b->square[0][4].type = b->square[7][4].type = KING; - b->square[0][5].type = b->square[7][5].type = BISHOP; - b->square[0][6].type = b->square[7][6].type = KNIGHT; - b->square[0][7].type = b->square[7][7].type = ROOK; - b->black_cant_castle_k = false; - b->black_cant_castle_q = false; - b->white_cant_castle_k = false; - b->white_cant_castle_q = false; - - return; -} - -void -board_drawall() -{ - int i, j; - - for (i = 0; i < SIZE; i++) - for (j = 0; j < SIZE; j++) - if (chessboard->square[i][j].color != NONE) { - win_drawpiece(&chessboard->square[i][j], i, - j, WHITE); - if (!oneboard) - win_drawpiece(&chessboard->square[i][j], - i, j, BLACK); - } - return; -} - -void -board_move(b, m) - board *b; - move *m; -{ - switch (m->type) { - - case MOVE: - case CAPTURE: - b->square[m->fromy][m->fromx].color = NONE; - b->square[m->toy][m->tox].color = m->piece.color; - b->square[m->toy][m->tox].type = m->piece.type; - if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) && - (m->toy == 7)) || ((m->piece.color == WHITE) && - (m->toy == 0)))) - b->square[m->toy][m->tox].type = QUEEN; - if (m->enpassant) - b->square[m->toy + ((m->piece.color == WHITE) ? 1 : - -1)][m->tox].color = NONE; - break; - - case KCASTLE: - if (m->piece.color == WHITE) { - b->square[7][5].color = m->piece.color; - b->square[7][5].type = ROOK; - b->square[7][6].color = m->piece.color; - b->square[7][6].type = KING; - b->square[7][4].color = NONE; - b->square[7][7].color = NONE; - } else { - b->square[0][5].color = m->piece.color; - b->square[0][5].type = ROOK; - b->square[0][6].color = m->piece.color; - b->square[0][6].type = KING; - b->square[0][4].color = NONE; - b->square[0][7].color = NONE; - } - break; - - case QCASTLE: - if (m->piece.color == WHITE) { - b->square[7][3].color = m->piece.color; - b->square[7][3].type = ROOK; - b->square[7][2].color = m->piece.color; - b->square[7][2].type = KING; - b->square[7][4].color = NONE; - b->square[7][0].color = NONE; - } else { - b->square[0][3].color = m->piece.color; - b->square[0][3].type = ROOK; - b->square[0][2].color = m->piece.color; - b->square[0][2].type = KING; - b->square[0][4].color = NONE; - b->square[0][0].color = NONE; - } - break; - - default: - fprintf(stderr, "Bad move type %d\n", m->type); - } - - if (m->piece.type == KING) { - if (m->piece.color == WHITE) - b->white_cant_castle_q = - b->white_cant_castle_k= true; - else - b->black_cant_castle_q = - b->black_cant_castle_k= true; - } else if (m->piece.type == ROOK) { - if (m->piece.color == WHITE) { - if (m->fromx == 0) - b->white_cant_castle_q = true; - else if (m->fromx == 7) - b->white_cant_castle_k = true; - } else { - if (m->fromx == 0) - b->black_cant_castle_q = true; - else if (m->fromx == 7) - b->black_cant_castle_k = true; - } - } - - return; -} - diff --git a/gnu/games/chess/Xchess/button.c b/gnu/games/chess/Xchess/button.c deleted file mode 100644 index d91005d..0000000 --- a/gnu/games/chess/Xchess/button.c +++ /dev/null @@ -1,337 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:15 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/button.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - * Do stuff with the buttons. - * The configuration we're using is: Draw Back Pause - * Resign Fwd Flip - * Reset Save Easy (Switch) - */ - -#include "xchess.h" - -typedef enum choice { NOCHOICE, DRAW, RESIGN, REPLAY, SWITCH, FORE, SAVE, - STOP, FLIP, RESTART, EASY } choice; - -static struct but { - char *label; - int x, y; - int width, height; - choice which; -} buts[] = { - { "Draw", 0, 20, 108, 29, DRAW } , - { "Back", 109, 20, 108, 29, REPLAY } , - { "Pause", 219, 20, 108, 29, STOP } , - { "Resign", 0, 50, 108, 29, RESIGN } , - { "Fwd", 109, 50, 108, 29, FORE } , - { "Flip", 219, 50, 108, 29, FLIP } , - { "Reset", 0, 80, 108, 29, RESTART } , - { "Save", 109, 80, 108, 29, SAVE } , -#define EASY_OFFSET 8 - { "Switch", 219, 80, 108, 29, SWITCH } -/* { "NoEasy", 219, 80, 108, 29, EASY }*/ -} ; -static int easy = 1; - -void -button_draw(win) - windata *win; -{ - int i, x, numbuts = sizeof (buts) / sizeof (struct but); - - XSetState(win->display, DefaultGC(win->display, 0), - win->border.pixel, WhitePixel(win->display, 0), - GXcopy, AllPlanes); - XSetLineAttributes(win->display, DefaultGC(win->display, 0), - BORDER_WIDTH, LineSolid, CapButt, - JoinMiter); - - XDrawLine(win->display, win->buttonwin, - DefaultGC(win->display, 0), - 0, 29, BUTTON_WIDTH, 29); - XDrawLine(win->display, win->buttonwin, - DefaultGC(win->display, 0), - 0, 60, BUTTON_WIDTH, 60); - XDrawLine(win->display, win->buttonwin, - DefaultGC(win->display, 0), - 108, 0, 108, BUTTON_HEIGHT); - XDrawLine(win->display, win->buttonwin, - DefaultGC(win->display, 0), - 219, 0, 219, BUTTON_HEIGHT); - - XSetFont(win->display, DefaultGC(win->display, 0), win->large->fid); - XSetForeground(win->display, DefaultGC(win->display, 0), - win->textcolor.pixel); - XSetBackground(win->display, DefaultGC(win->display, 0), - win->textback.pixel); - - for (i = 0; i < numbuts; i++) { - x = (buts[i].width - - XTextWidth(win->large, buts[i].label, - strlen(buts[i].label))) / 2; - - XDrawImageString(win->display, win->buttonwin, - DefaultGC(win->display, 0), - buts[i].x + x, buts[i].y, buts[i].label, - strlen(buts[i].label)); - } - return; -} - -void -button_service(win, event) - windata *win; - XEvent *event; -{ - XKeyEvent *ev = &event->xkey; - choice c; - int i, numbuts = sizeof (buts) / sizeof (struct but); - char *s; - - ev->y += 15; - for (i = 0; i < numbuts; i++) - if ((ev->x >= buts[i].x) && (ev->x <= buts[i].x + - buts[i].width) && (ev->y >= buts[i].y) && - (ev->y <= buts[i].y + buts[i].height)) { - c = buts[i].which; - break; - } - if ((i == numbuts) || (c == NOCHOICE)) { - message_add(win, "Bad choice.\n", true); - return; - } - - if (loading_flag && (c != STOP)) { - message_add(win, "You can only use PAUSE now\n", true); - return; - } - - switch (c) { - case DRAW: - if (!oneboard) { - message_add(win, "Just a sec...\n", false); - if (!pop_question(((win == win1) ? win2 : win1), -"The other player wants\nto call the game a draw.\nDo you agree?\n")) { - message_add(win, - "The other player declines the draw\n", false); - return; - } - } - message_add(win1, "Draw agreed.\n", false); - if (!oneboard) - message_add(win2, "Draw agreed.\n", false); - cleanup("Draw agreed."); - break; - - case RESIGN: - if (!pop_question(win, "Are you sure\nyou want to resign?")) - return; - if ((oneboard && !progflag) || (nexttomove == win->color)) { - if (nexttomove == WHITE) - s = "White resigns."; - else - s = "Black resigns."; - if (oneboard) { - message_add(win, s, false); - message_add(win, "\n", false); - } else { - message_add(win1, s, false); - message_add(win, "\n", false); - message_add(win2, s, false); - message_add(win, "\n", false); - } - sleep(5); - cleanup(s); - } else { - message_add(win, "It's not your turn.\n", true); - } - break; - - case REPLAY: - if (!oneboard) { - message_add(win, "Just a sec...\n", false); - if (!pop_question(((win == win1) ? win2 : win1), -"The other player wants\nto take back his last move.\nDo you let him?\n")) { - message_add(win, - "The other player refuses...\n", false); - return; - } - } - if (!moves) { - message_add(win, "Can't back up...\n", true); - break; - } - message_add(win1, "Replaying...\n", false); - if (!oneboard) - message_add(win2, "Replaying...\n", false); - replay(); - if (progflag) - replay(); - break; - - case FORE: - if (!oneboard) { - message_add(win, "Just a sec...\n", false); - if (!pop_question(((win == win1) ? win2 : win1), -"The other player wants\nto do a 'fore'.\nIs that ok with you?\n")) { - message_add(win, - "The other player refuses...\n", false); - return; - } - } - if (!foremoves) { - message_add(win, "Can't go forward...\n", true); - break; - } - message_add(win1, "Moving forward...\n", false); - if (!oneboard) - message_add(win2, "Moving forward...\n", false); - forward(); - break; - - case SWITCH: - message_add(win, "You can't switch yet.\n", false); - break; - - case SAVE: - if (saveflag) { - message_add(win, - "Game is already being logged in file '", true); - message_add(win, record_file, true); - message_add(win, "'.\n", true); - } else { - message_add(win, "Saving game to file '", false); - message_add(win, record_file, false); - message_add(win, "'.\n", false); - record_save(); - } - break; - - case STOP: - if (loading_flag) { - loading_paused = (loading_paused ? false : true); - message_add(win, loading_paused ? - "Stopped.\nHit 'Pause' again to restart.\n" : - "Restarted.\n", false); - } else if (clock_started) { - if (!oneboard) { - message_add(win, "Just a sec...\n", false); - if (!pop_question(((win == win1) ? win2 : win1), -"The other player wants\nto stop the clock.\nDo you let him?\n")) { - message_add(win, - "The other player refuses to pause.\n", - false); - return; - } - } - message_add(win1, - "Clock stopped.\nHit 'Pause' again to restart.\n", - false); - if (!oneboard) - message_add(win2, - "Clock stopped.\nHit 'Pause' again to restart.\n", - false); - clock_started = false; - } else { - if (!oneboard) { - message_add(win, "Just a sec...\n", false); - if (!pop_question(((win == win1) ? win2 : win1), -"The other player wants\nto start the clock again.\nIs that ok?\n")) { - message_add(win, - "The other player refuses to resume.\n", - false); - return; - } - } - message_add(win1, "Clock restarted.\n", false); - if (!oneboard) - message_add(win2, "Clock restarted.\n", false); - clock_started = true; - } - break; - - case FLIP: - message_add(win, "Flipping window...\n", false); - win->flipped = win->flipped ? false : true; - win_redraw(win, (XEvent *) NULL); - break; - - case RESTART: - if (!oneboard) { - message_add(win, "Just a sec...\n", false); - if (!pop_question(((win == win1) ? win2 : win1), -"The other player wants\nto restart the game.\nDo you agree?\n")) { - message_add(win, - "The other player refuses to reset\n", false); - return; - } - } - message_add(win, "Restarting game.\n", false); - restart(); - break; - case EASY: - if (oneboard) { - int x; - if (easy) - easy = 0; - else - easy = 1; - - if (easy) - buts[EASY_OFFSET].label = " Easy "; - else - buts[EASY_OFFSET].label = "NoEasy"; - - program_easy(easy); - - x = (buts[EASY_OFFSET].width - - XTextWidth(win->large, - buts[EASY_OFFSET].label, - strlen(buts[EASY_OFFSET].label))) / 2; - - XSetFont(win->display, DefaultGC(win->display, - 0), win->large->fid); - XSetForeground(win->display, - DefaultGC(win->display, 0), - win->textcolor.pixel); - XSetBackground(win->display, - DefaultGC(win->display, 0), - win->textback.pixel); - - XDrawImageString(win->display, - win->buttonwin, - DefaultGC(win->display, 0), - buts[EASY_OFFSET].x + x, - buts[EASY_OFFSET].y, - buts[EASY_OFFSET].label, - strlen(buts[EASY_OFFSET].label)); - } - break; - } - return; -} - diff --git a/gnu/games/chess/Xchess/clock.c b/gnu/games/chess/Xchess/clock.c deleted file mode 100644 index 88228b0..0000000 --- a/gnu/games/chess/Xchess/clock.c +++ /dev/null @@ -1,291 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/clock.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - * Do stuff with the clocks. The way things work is as follows. We call - * clock_init to draw the clocks initially, but they don't actually start - * running until we call clock_switch for the first time. - */ - -#include "xchess.h" - -int movesperunit = 0; -int timeunit = 0; -bool clock_started = false; -int whiteseconds, blackseconds; - -static bool white_running = true; -static long lastwhite, lastblack; -static bool firstmove = true; - -extern void dohands(), hilight(); - -#define PI 3.1415926535897932384 - -void -clock_draw(win, col) - windata *win; - color col; -{ - int i; - char buf[BSIZE]; - int x = CLOCK_WIDTH / 2, y = CLOCK_WIDTH / 2; - int xp, yp; - int rad = CLOCK_WIDTH / 2 - 10; - Window w = ((col == WHITE) ? win->wclockwin : win->bclockwin); - - /* Draw a clock face and the hands. */ - XCircle(w, x, y, rad, 0.0, 0.0, 1, 1, win->textcolor.pixel, GXcopy, - AllPlanes); - rad -= 8; - - XSetFont(win->display, DefaultGC(win->display, 0), - win->small->fid); - XSetForeground(win->display, DefaultGC(win->display, 0), - win->textcolor.pixel); - XSetBackground(win->display, DefaultGC(win->display, 0), - win->textback.pixel); - for (i = 1; i <= 12; i++) { - xp = x + rad * cos(PI * 3 / 2 + i * PI / 6) - 4; - yp = y + rad * sin(PI * 3 / 2 + i * PI / 6) - 5; - sprintf(buf, "%d", i); - XDrawString(win->display, w, DefaultGC(win->display, 0), - xp, yp, buf, strlen(buf)); - } - - dohands(win, col); - - if (white_running) { - hilight(win, WHITE, true); - hilight(win, BLACK, false); - } else { - hilight(win, WHITE, false); - hilight(win, BLACK, true); - } - return; -} - -void -clock_init(win, col) - windata *win; - color col; -{ - whiteseconds = blackseconds = 0; - clock_started = false; - firstmove = true; - clock_draw(win, col); - - return; -} - -void -clock_update() -{ - int now = time((long *) NULL); - int i; - - if (!clock_started) { - lastwhite = lastblack = now; - return; - } - - if (white_running) { - whiteseconds += now - lastwhite; - lastwhite = now; - dohands(win1, WHITE); - if (!oneboard) - dohands(win2, WHITE); - if (timeunit) { - i = whiteseconds / timeunit; - if ((i > 0) && (whiteseconds > i * timeunit) && - (whiteseconds < i * timeunit + 10) && - (movesperunit * i > movenum)) { - message_add(win1, - "White has exceeded his time limit\n", - true); - if (!oneboard) { - message_add(win2, - "White has exceeded his time limit\n", - true); - } - timeunit = 0; - } - } - } else { - blackseconds += now - lastblack; - lastblack = now; - dohands(win1, BLACK); - if (!oneboard) - dohands(win2, BLACK); - if (timeunit) { - i = blackseconds / timeunit; - if ((i > 0) && (blackseconds > i * timeunit) && - (blackseconds < i * timeunit + 10) && - (movesperunit * i > movenum)) { - message_add(win1, - "Black has exceeded his time limit\n", - true); - if (!oneboard) { - message_add(win2, - "Black has exceeded his time limit\n", - true); - } - timeunit = 0; - } - } - } - return; -} - -void -clock_switch() -{ - if (firstmove) { - clock_started = true; - firstmove = false; - lastwhite = lastblack = time((long *) NULL); - } - if (white_running) { - white_running = false; - lastblack = time((long *) NULL); - hilight(win1, WHITE, false); - hilight(win1, BLACK, true); - if (!oneboard) { - hilight(win2, WHITE, false); - hilight(win2, BLACK, true); - } - } else { - white_running = true; - lastwhite = time((long *) NULL); - hilight(win1, WHITE, true); - hilight(win1, BLACK, false); - if (!oneboard) { - hilight(win2, WHITE, true); - hilight(win2, BLACK, false); - } - } - return; -} - -static void -dohands(win, col) - windata *win; - color col; -{ - int cx = CLOCK_WIDTH / 2, cy = CLOCK_WIDTH / 2; - double *h = (col == WHITE) ? win->whitehands : win->blackhands; - Window w = (col == WHITE) ? win->wclockwin : win->bclockwin; - long secs = (col == WHITE) ? whiteseconds : blackseconds; - int rad, x, y, i; - - /* First erase the old hands. */ - XSetState(win->display, DefaultGC(win->display, 0), - win->textback.pixel, win->textback.pixel, - GXcopy, AllPlanes); - - rad = CLOCK_WIDTH / 2 - 30; - for (i = 0; i < 3; i++) { - x = cx + rad * sin(PI - h[i]); - y = cy + rad * cos(PI - h[i]); - XSetLineAttributes(win->display, - DefaultGC(win->display, 0), - i, LineSolid, 0, 0); - XDrawLine(win->display, w, DefaultGC(win->display, 0), - cx, cy, x, y); - rad -= 8; - } - - h[0] = (secs % 60) * 2 * PI / 60; - h[1] = ((secs / 60) % 60) * 2 * PI / 60; - h[2] = ((secs / 3600) % 12) * 2 * PI / 12; - - /* Now draw the new ones. */ - - XSetState(win->display, DefaultGC(win->display, 0), - win->textcolor.pixel, win->textback.pixel, - GXcopy, AllPlanes); - - rad = CLOCK_WIDTH / 2 - 30; - for (i = 0; i < 3; i++) { - x = cx + rad * sin(PI - h[i]); - y = cy + rad * cos(PI - h[i]); - XSetLineAttributes(win->display, - DefaultGC(win->display, 0), - i, LineSolid, 0, 0); - XDrawLine(win->display, w, DefaultGC(win->display, 0), - cx, cy, x, y); - rad -= 8; - } - XFlush(win->display); - return; -} - -static void -hilight(win, col, on) - windata *win; - color col; - bool on; -{ - Window w = (col == WHITE) ? win->wclockwin : win->bclockwin; - char *s = (col == WHITE) ? " WHITE " : " BLACK "; - int x; - - - x = XTextWidth(win->large, s, strlen(s)); - if (on) - XSetState(win->display, DefaultGC(win->display, 0), - win->textback.pixel, - win->textcolor.pixel, - GXcopy, - AllPlanes); - else - XSetState(win->display, DefaultGC(win->display, 0), - win->textcolor.pixel, - win->textback.pixel, - GXcopy, AllPlanes); - - XSetLineAttributes(win->display, DefaultGC(win->display, 0), - BORDER_WIDTH, LineSolid, CapButt, JoinMiter); - XSetFont(win->display, DefaultGC(win->display, 0), - win->large->fid); - - XDrawLine(win->display, w, DefaultGC(win->display, 0), - 0, CLOCK_HEIGHT - 26, - CLOCK_WIDTH, CLOCK_HEIGHT - 26); - - XDrawImageString(win->display, w, DefaultGC(win->display, 0), - (CLOCK_WIDTH - x) / 2, CLOCK_HEIGHT, - s, strlen(s)); - - if (on) - XSetState(win->display, DefaultGC(win->display, 0), - win->textcolor.pixel, - win->textback.pixel, - GXcopy, AllPlanes); - return; -} - diff --git a/gnu/games/chess/Xchess/control.c b/gnu/games/chess/Xchess/control.c deleted file mode 100644 index 7d23a76..0000000 --- a/gnu/games/chess/Xchess/control.c +++ /dev/null @@ -1,515 +0,0 @@ -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:11 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/control.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - * Deal with input from the user. - */ - -#include "xchess.h" - -move *moves; -move *foremoves; -color nexttomove = WHITE; -bool noisyflag = false; - -move *lastmove; -static move *thismove; - -static void screen_move(); - -void -button_pressed(event, win) - XEvent *event; - windata *win; -{ - int x, y; - XKeyEvent *ev = (XKeyEvent *) event; - - if (!oneboard && (win->color != nexttomove)) { - message_add(win, "Wrong player!\n", true); - return; - } - if (progflag && (nexttomove == (blackflag ? WHITE : BLACK))) { - message_add(win, "Wait for the computer...\n", true); - return; - } - if (loading_flag) { - message_add(win, "You'd better not do that now...\n", true); - return; - } - - /* Figure out what piece he is pointing at. */ - x = ev->x / (SQUARE_WIDTH + BORDER_WIDTH); - y = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH); - - if (win->flipped) { - y = SIZE - y - 1; - x = SIZE - x - 1; - } - - if ((x < 0) || (x >= SIZE) || (y < 0) || (y >= SIZE)) { - fprintf(stderr, "Bad coords (%d, %d)\n", x, y); - return; - } - - if (oneboard && (chessboard->square[y][x].color != nexttomove)) { - message_add(win, "Wrong player!\n", true); - return; - } else if (!oneboard && (chessboard->square[y][x].color != - win->color)) { - message_add(win, "Can't move that\n", true); - return; - } - - thismove = alloc(move); - thismove->fromx = x; - thismove->fromy = y; - thismove->piece.color = chessboard->square[y][x].color; - thismove->piece.type = chessboard->square[y][x].type; - - if (debug) - fprintf(stderr, "%s selected his %s at (%d, %d)...\n", - colornames[(int) thismove->piece.color], - piecenames[(int) thismove->piece.type], - thismove->fromy, thismove->fromx); - return; -} - -void -button_released(event, win) - XEvent *event; - windata *win; -{ - int x, y; - XKeyEvent *ev = (XKeyEvent *) event; - - if (!thismove) { - /* fprintf(stderr, "Error: button hasn't been pressed\n"); */ - return; - } - if (loading_flag) - return; - - /* Figure out what piece he is pointing at. */ - x = ev->x / (SQUARE_WIDTH + BORDER_WIDTH); - y = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH); - - if (win->flipped) { - y = SIZE - y - 1; - x = SIZE - x - 1; - } - - if ((x < 0) || (x >= SIZE) || (y < 0) || (y >= SIZE)) { - fprintf(stderr, "Bad coords (%d, %d)\n", x, y); - return; - } - - if ((thismove->fromx == x) && (thismove->fromy == y)) { - message_add(win, "Hey, you touch it, you move it, buddy.\n", - true); - return; - } - if (chessboard->square[y][x].color == thismove->piece.color) { - message_add(win, "Can't put one piece on top of another\n", - true); - return; - } - - thismove->tox = x; - thismove->toy = y; - thismove->taken.color = chessboard->square[y][x].color; - thismove->taken.type = chessboard->square[y][x].type; - if (thismove->taken.color != NONE) - thismove->type = CAPTURE; - else if ((thismove->piece.type == KING) && (thismove->fromx == 4) && - (thismove->tox == 6) && - (thismove->toy == thismove->fromy)) - thismove->type = KCASTLE; - else if ((thismove->piece.type == KING) && (thismove->tox == 2) && - (thismove->fromx == 4) && - (thismove->toy == thismove->fromy)) - thismove->type = QCASTLE; - else - thismove->type = MOVE; - - /* Now check the en-passant case... */ - if ((thismove->type == MOVE) && ((thismove->tox == thismove->fromx + 1) - || (thismove->tox == thismove->fromx - 1)) && - (thismove->piece.type == PAWN) && lastmove && - (lastmove->tox == lastmove->fromx) && (lastmove->fromx - == thismove->tox) && ((lastmove->fromy + lastmove->toy) - / 2 == thismove->toy)) { - thismove->type = CAPTURE; - thismove->enpassant = true; - thismove->taken = lastmove->piece; - } - - if (!valid_move(thismove, chessboard)) { - message_add(win, "Invalid move.\n", true); - return; - } - - if (debug) - fprintf(stderr, "\t... and moved it to (%d, %d), type %s\n", - thismove->toy, thismove->tox, - movetypenames[(int) thismove->type]); - move_piece(thismove); - - if (thismove->check) { - message_add(win1, "Check.\n", true); - if (!oneboard) { - message_add(win2, "Check.\n", true); - } - } - - if (!moves) - moves = lastmove = thismove; - else - lastmove = lastmove->next = thismove; - - if (progflag) - program_send(thismove); - - thismove = NULL; - nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE); - clock_switch(); - - return; -} - -void -prog_move(m) - move *m; -{ - if (debug) - fprintf(stderr, "program moves from (%d, %d) to (%d, %d)\n", - m->fromy, m->fromx, m->toy, m->tox); - move_piece(m); - - if (!moves) - moves = lastmove = m; - else - lastmove = lastmove->next = m; - - nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE); - clock_switch(); - - return; -} - -void -move_piece(m) - move *m; -{ - /* Update the screen... */ - screen_move(m); - - /* Move the piece on the board... */ - board_move(chessboard, m); - - /* And record it... */ - record_move(m); - - if (noisyflag) { - XBell(win1->display, 50); - XBell(win2->display, 50); - } - return; -} - -static void -screen_move(m) - move *m; -{ - piece pp; - - switch (m->type) { - case CAPTURE: - jail_add(&m->taken); - /* FALLTHRU */ - - case MOVE: - win_erasepiece(m->fromy, m->fromx, WHITE); - if (win_flashmove) - win_flash(m, WHITE); - win_drawpiece(&m->piece, m->toy, m->tox, WHITE); - if (m->enpassant) - win_erasepiece(m->toy + ((m->piece.color == WHITE) ? - 1 : -1), m->tox, WHITE); - if (!oneboard) { - win_erasepiece(m->fromy, m->fromx, BLACK); - if (win_flashmove) - win_flash(m, BLACK); - win_drawpiece(&m->piece, m->toy, m->tox, BLACK); - if (m->enpassant) - win_erasepiece(m->toy + ((m->piece.color == - WHITE) ? 1 : -1), m->tox, WHITE); - } - if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) && - (m->toy == 7)) || ((m->piece.color == WHITE) && - (m->toy == 0)))) { - pp.color = m->piece.color; - pp.type = QUEEN; - win_drawpiece(&pp, m->toy, m->tox, WHITE); - if (!oneboard) - win_drawpiece(&m->piece, m->toy, m->tox, BLACK); - } - break; - - case KCASTLE: - if (m->piece.color == WHITE) { - win_erasepiece(7, 4, WHITE); - win_erasepiece(7, 7, WHITE); - if (win_flashmove) - win_flash(m, WHITE); - win_drawpiece(&m->piece, 7, 6, WHITE); - win_drawpiece(&chessboard->square[7][7], 7, 5, WHITE); - if (!oneboard) { - win_erasepiece(7, 4, BLACK); - win_erasepiece(7, 7, BLACK); - if (win_flashmove) - win_flash(m, BLACK); - win_drawpiece(&m->piece, 7, 6, BLACK); - win_drawpiece(&chessboard->square[7][7], 7, 5, - BLACK); - } - } else { - win_erasepiece(0, 4, WHITE); - win_erasepiece(0, 7, WHITE); - if (win_flashmove) - win_flash(m, WHITE); - win_drawpiece(&m->piece, 0, 6, WHITE); - win_drawpiece(&chessboard->square[0][7], 0, 5, WHITE); - if (!oneboard) { - win_erasepiece(0, 4, BLACK); - win_erasepiece(0, 7, BLACK); - if (win_flashmove) - win_flash(m, BLACK); - win_drawpiece(&m->piece, 0, 6, BLACK); - win_drawpiece(&chessboard->square[0][7], 0, 5, - BLACK); - } - } - break; - - case QCASTLE: - if (m->piece.color == WHITE) { - win_erasepiece(7, 4, WHITE); - win_erasepiece(7, 0, WHITE); - if (win_flashmove) - win_flash(m, WHITE); - win_drawpiece(&m->piece, 7, 2, WHITE); - win_drawpiece(&chessboard->square[7][0], 7, 3, WHITE); - if (!oneboard) { - win_erasepiece(7, 4, BLACK); - win_erasepiece(7, 0, BLACK); - if (win_flashmove) - win_flash(m, BLACK); - win_drawpiece(&m->piece, 7, 2, BLACK); - win_drawpiece(&chessboard->square[7][7], 7, 3, - BLACK); - } - } else { - win_erasepiece(0, 4, WHITE); - win_erasepiece(0, 0, WHITE); - if (win_flashmove) - win_flash(m, WHITE); - win_drawpiece(&m->piece, 0, 2, WHITE); - win_drawpiece(&chessboard->square[0][0], 0, 3, WHITE); - if (!oneboard) { - win_erasepiece(0, 4, BLACK); - win_erasepiece(0, 0, BLACK); - if (win_flashmove) - win_flash(m, BLACK); - win_drawpiece(&m->piece, 0, 2, BLACK); - win_drawpiece(&chessboard->square[0][7], 0, 3, - BLACK); - } - } - break; - - default: - fprintf(stderr, "Bad move type %d\n", m->type); - } - return; -} - -/* Retract the last move made... */ - -void -replay() -{ - move *m = lastmove, bm; - - memset(&bm, 0, sizeof(bm)); - switch (m->type) { - case MOVE: - bm.type = MOVE; - bm.piece = m->piece; - bm.fromx = m->tox; - bm.fromy = m->toy; - bm.tox = m->fromx; - bm.toy = m->fromy; - board_move(chessboard, &bm); - screen_move(&bm); - break; - - case CAPTURE: - bm.type = MOVE; - bm.piece = m->piece; - bm.fromx = m->tox; - bm.fromy = m->toy; - bm.tox = m->fromx; - bm.toy = m->fromy; - board_move(chessboard, &bm); - screen_move(&bm); - chessboard->square[m->toy][m->tox] = m->taken; - bm.piece = m->taken; - bm.fromx = bm.tox = m->tox; - bm.fromy = bm.toy = m->toy; - screen_move(&bm); - jail_remove(&m->taken); - break; - - case KCASTLE: - bm.type = MOVE; - bm.piece.type = KING; - bm.piece.color = m->piece.color; - bm.fromx = 6; - bm.tox = 4; - bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; - board_move(chessboard, &bm); - screen_move(&bm); - bm.type = MOVE; - bm.piece.type = ROOK; - bm.piece.color = m->piece.color; - bm.fromx = 5; - bm.tox = 7; - bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; - board_move(chessboard, &bm); - screen_move(&bm); - if (m->piece.color == WHITE) - chessboard->white_cant_castle_k = false; - else - chessboard->black_cant_castle_k = false; - break; - - case QCASTLE: - bm.type = MOVE; - bm.piece.type = KING; - bm.piece.color = m->piece.color; - bm.fromx = 2; - bm.tox = 4; - bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; - board_move(chessboard, &bm); - screen_move(&bm); - bm.type = MOVE; - bm.piece.type = ROOK; - bm.piece.color = m->piece.color; - bm.fromx = 3; - bm.tox = 0; - bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; - board_move(chessboard, &bm); - screen_move(&bm); - if (m->piece.color == WHITE) - chessboard->white_cant_castle_q = false; - else - chessboard->black_cant_castle_q = false; - break; - } - record_back(); - - nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE); - clock_switch(); - - if (!moves->next) { - moves->next = foremoves; - foremoves = moves; - moves = lastmove = NULL; - } else { - for (m = moves; m->next; m = m->next) - lastmove = m; - lastmove->next->next = foremoves; - foremoves = lastmove->next; - lastmove->next = NULL; - } - - if (progflag) - program_undo(); - - return; -} - -/* Put back the last move undone. */ - -void -forward() -{ - prog_move(foremoves); - foremoves = foremoves->next; - return; -} - -/* End the game. */ - -void -cleanup(s) - char *s; -{ - if (progflag) - program_end(); - record_end(s); - XSync(win1->display, 0); - if (!oneboard) { - XSync(win2->display, 0); - } - exit(0); -} - -void -restart() -{ - moves = lastmove = thismove = NULL; - nexttomove = WHITE; - - clock_init(win1, WHITE); - clock_init(win1, BLACK); - jail_init(win1); - if (!oneboard) { - clock_init(win2, WHITE); - clock_init(win2, BLACK); - jail_init(win2); - } - board_init(chessboard); - win_restart(); - record_reset(); - if (progflag) { - program_end(); - program_init(progname); - } - return; -} - diff --git a/gnu/games/chess/Xchess/jail.c b/gnu/games/chess/Xchess/jail.c deleted file mode 100644 index b3ed391..0000000 --- a/gnu/games/chess/Xchess/jail.c +++ /dev/null @@ -1,327 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:12 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/jail.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - */ - -#include "xchess.h" - -#include "pawn_small.bitmap" -#include "rook_small.bitmap" -#include "knight_small.bitmap" -#include "bishop_small.bitmap" -#include "queen_small.bitmap" -#include "king_small.bitmap" - -#include "pawn_small_outline.bitmap" -#include "rook_small_outline.bitmap" -#include "knight_small_outline.bitmap" -#include "bishop_small_outline.bitmap" -#include "queen_small_outline.bitmap" -#include "king_small_outline.bitmap" - -static bool pos[32]; - -static piecetype pcs[] = { KING, QUEEN, ROOK, ROOK, BISHOP, BISHOP, KNIGHT, - KNIGHT, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN } ; - -extern int piecepos(); -extern char *bitsget(); - -void -jail_init(win) - windata *win; -{ - int i; - - for (i = 0; i < 32; i++) - pos[i] = false; - jail_draw(win); - return; -} - -#define JAIL_HEADER "Captured Pieces" - -void -jail_draw(win) - windata *win; -{ - int i; - char *bits; - Pixmap tmpPM; - piece p; - - i = XTextWidth(win->large, JAIL_HEADER, strlen(JAIL_HEADER)); - XSetFont(win->display, DefaultGC(win->display, 0), - win->large->fid); - XSetForeground(win->display, DefaultGC(win->display, 0), - win->textcolor.pixel); - XSetBackground(win->display, DefaultGC(win->display, 0), - win->textback.pixel); - - XDrawImageString(win->display, win->jailwin, - DefaultGC(win->display, 0), - (JAIL_WIDTH - i) / 2, 20, JAIL_HEADER, - strlen(JAIL_HEADER)); - - XSetForeground(win->display, DefaultGC(win->display, 0), - win->blackpiece.pixel); - XSetBackground(win->display, DefaultGC(win->display, 0), - win->textback.pixel); - XSetFillStyle(win->display, DefaultGC(win->display, 0), - FillSolid); - XSetFunction(win->display, DefaultGC(win->display, 0), - GXcopy); - - for (i = 0; i < 16; i++) - if (pos[i]) { - p.color = WHITE; - p.type = pcs[i]; - bits = bitsget(&p); - tmpPM = XCreateBitmapFromData(win->display, - win->jailwin, bits, - 32, 32); - - XCopyPlane(win->display, tmpPM, win->jailwin, - DefaultGC(win->display, 0), - 0, 0, 32, 32, - 5 + (i % 8) * 32, 25 + (i / 8) * 32, - 1); - XFreePixmap(win->display, tmpPM); - } else { - XFillRectangle(win->display, win->jailwin, - DefaultGC(win->display, 0), - 5 + (i % 8) * 32, - 25 + (i / 8) * 32, - 32, 32); - } - for (i = 0; i < 16; i++) - if (pos[i + 16]) { - p.color = BLACK; - p.type = pcs[i]; - bits = bitsget(&p); - tmpPM = XCreateBitmapFromData(win->display, - win->jailwin, bits, - 32, 32); - - XCopyPlane(win->display, tmpPM, win->jailwin, - DefaultGC(win->display, 0), - 0, 0, 32, 32, - 5 + (i % 8) * 32, 94 + (i / 8) * 32, - 1); - XFreePixmap(win->display, tmpPM); - } else { - XFillRectangle(win->display, win->jailwin, - DefaultGC(win->display, 0), - 5 + (i % 8) * 32, 94 + (i / 8) * 32, - 32, 32); - } - - return; -} - -void -jail_add(p) - piece *p; -{ - int i = piecepos(p, false); - char *bits; - Pixmap tmpPM; - - pos[i] = true; - - bits = bitsget(p); - - XSetState(win1->display, DefaultGC(win1->display, 0), - win1->blackpiece.pixel, - win1->textback.pixel, - GXcopy, - AllPlanes); - - tmpPM = XCreateBitmapFromData(win1->display, - win1->jailwin, bits, - 32, 32); - - XCopyPlane(win1->display, tmpPM, win1->jailwin, - DefaultGC(win1->display, 0), - 0, 0, 32, 32, - 5 + (i % 8) * 32, ((i >= 16) ? 30 : 25) + (i / 8) * 32, - 1); - XFreePixmap(win1->display, tmpPM); - - if (!oneboard) { - XSetState(win2->display, DefaultGC(win2->display, 0), - win2->blackpiece.pixel, - win2->textback.pixel, - GXcopy, - AllPlanes); - - - tmpPM = XCreateBitmapFromData(win2->display, - win2->jailwin, bits, - 32, 32); - - XCopyPlane(win2->display, tmpPM, win2->jailwin, - DefaultGC(win2->display, 0), - 0, 0, 32, 32, - 5 + (i % 8) * 32, ((i >= 16) ? 30 : 25) + (i / 8) * 32, - 1); - XFreePixmap(win2->display, tmpPM); - } - - return; -} - -void -jail_remove(p) - piece *p; -{ - int i = piecepos(p, true); - - pos[i] = false; - - - XSetForeground(win1->display, - DefaultGC(win1->display, 0), - win1->blackpiece.pixel); - XSetBackground(win1->display, - DefaultGC(win1->display, 0), - win1->textback.pixel); - XSetFillStyle(win1->display, - DefaultGC(win1->display, 0), - FillSolid); - - XFillRectangle(win1->display, win1->jailwin, - DefaultGC(win1->display, 0), - 5 + (i % 8) * 32, - ((i >= 16) ? 30 : 25) + (i / 8) * 32, - 32, 32); - - if (!oneboard) { - XSetForeground(win2->display, - DefaultGC(win2->display, 0), - win2->blackpiece.pixel); - XSetBackground(win2->display, - DefaultGC(win2->display, 0), - win2->textback.pixel); - XSetFillStyle(win2->display, - DefaultGC(win2->display, 0), - FillSolid); - - XFillRectangle(win2->display, win2->jailwin, - DefaultGC(win2->display, 0), - 5 + (i % 8) * 32, - ((i >= 16) ? 30 : 25) + (i / 8) * 32, - 32, 32); - } - - return; -} - -static char *bitsget(p) - piece *p; -{ - char *bits; - - switch (p->type) { - case PAWN: - bits = (p->color == WHITE) ? pawn_small_outline_bits : - pawn_small_bits; - break; - - case ROOK: - bits = (p->color == WHITE) ? rook_small_outline_bits : - rook_small_bits; - break; - - case KNIGHT: - bits = (p->color == WHITE) ? knight_small_outline_bits : - knight_small_bits; - break; - - case BISHOP: - bits = (p->color == WHITE) ? bishop_small_outline_bits : - bishop_small_bits; - break; - - case QUEEN: - bits = (p->color == WHITE) ? queen_small_outline_bits : - queen_small_bits; - break; - - case KING: - bits = (p->color == WHITE) ? king_small_outline_bits : - king_small_bits; - break; - } - return (bits); -} - -static int -piecepos(p, there) - piece *p; - bool there; -{ - int i, base = (p->color == WHITE) ? 0 : 16; - - switch (p->type) { - case PAWN: - for (i = base + 8; (i < base + 15) && pos[i]; i++) - ; - if (there && !pos[i]) - i--; - break; - - case KING: - /* Hmm... */ - i = base; - break; - - case QUEEN: - i = base + 1; - break; - - case ROOK: - i = base + 2; - if ((there && pos[i + 1]) || (!there && pos[i])) - i++; - break; - - case BISHOP: - i = base + 4; - if ((there && pos[i + 1]) || (!there && pos[i])) - i++; - break; - - case KNIGHT: - i = base + 6; - if ((there && pos[i + 1]) || (!there && pos[i])) - i++; - break; - } - return (i); -} diff --git a/gnu/games/chess/Xchess/message.c b/gnu/games/chess/Xchess/message.c deleted file mode 100644 index 26df739..0000000 --- a/gnu/games/chess/Xchess/message.c +++ /dev/null @@ -1,101 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:14 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/message.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - * Do stuff with the message window. Font 0 is the normal font, font 1 - * is large, and font 2 is normal red. - */ - -#include "xchess.h" - -#define MESSAGE_HEADER "\n1 XChess Messages0\n" - -void -message_init(win) - windata *win; -{ - TxtGrab(win->display, win->messagewin, "xchess", win->medium, - win->textback.pixel, win->textcolor.pixel, - win->cursorcolor.pixel); - TxtAddFont(win->display, win->messagewin, 1, win->large, win->textcolor.pixel); - TxtAddFont(win->display, win->messagewin, 2, win->medium, win->errortext.pixel); - TxtAddFont(win->display, win->messagewin, 3, win->medium, win->playertext.pixel); - - TxtWriteStr(win->display, win->messagewin, MESSAGE_HEADER); - return; -} - -void -message_add(win, string, err) - windata *win; - char *string; - bool err; -{ - if (err) { - TxtWriteStr(win->display, win->messagewin, "2"); - TxtWriteStr(win->display, win->messagewin, string); - TxtWriteStr(win->display, win->messagewin, "0"); - XBell(win->display, 50); - } else - TxtWriteStr(win->display, win->messagewin, string); - - XSync(win->display, 0); - return; -} - -void -message_send(win, event) - windata *win; - XEvent *event; -{ - XKeyEvent *ev = &event->xkey; - KeySym keysym; - windata *ow = (win == win1) ? win2 : win1; - char buf[BSIZE], *s; - int i; - - i = XLookupString(ev, buf, sizeof(buf) - 1, &keysym, &s); - buf[i] = '\0'; - for (s = buf; *s; s++) - if (*s == '\r') - *s = '\n'; - else if (*s == '\177') - *s = ''; - - TxtWriteStr(win->display, win->messagewin, "3"); - TxtWriteStr(win->display, win->messagewin, buf); - TxtWriteStr(win->display, win->messagewin, "0"); - XSync(win->display, 0); - if (ow) { - TxtWriteStr(ow->display, ow->messagewin, "3"); - TxtWriteStr(ow->display, ow->messagewin, buf); - TxtWriteStr(ow->display, ow->messagewin, "0"); - XSync(ow->display, 0); - } - return; -} - diff --git a/gnu/games/chess/Xchess/parse.c b/gnu/games/chess/Xchess/parse.c deleted file mode 100644 index 2dd94ed..0000000 --- a/gnu/games/chess/Xchess/parse.c +++ /dev/null @@ -1,386 +0,0 @@ -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:06 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/parse.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - * Parse a sequence of chess moves... - */ - -#include "xchess.h" - -bool loading_flag = false; -bool loading_paused = false; - -static char *line; - -/* Load a record file in. This returns a number of things -- the board, the - * list of moves, and whose turn it is. - */ - -void -load_game(file) - char *file; -{ - FILE *fp; - char buf[BSIZE]; - bool eflag; - move *m; - board *tmpboard = alloc(board); - - if (eq(file, "xchess.game") && saveflag) { - message_add(win1, - "Oops, I just overwrote the\nfile xchess.game...\n", - true); - message_add(win1, "I hope you had another copy.\n", true); - return; - } - if (!(fp = fopen(file, "r"))) { - perror(file); - return; - } - - /* Get a few lines... */ - fgets(buf, BSIZE, fp); - message_add(win1, buf, false); - if (!oneboard) - message_add(win2, buf, false); - - fgets(buf, BSIZE, fp); - message_add(win1, buf, false); - if (!oneboard) - message_add(win2, buf, false); - - fgets(buf, BSIZE, fp); - if (eq(buf, "\tenglish\n")) - eflag = true; - else if (eq(buf, "\talgebraic\n")) - eflag = false; - else { - fprintf(stderr, "Can't decide whether this is english...\n"); - return; - } - - board_init(tmpboard); - line = NULL; - m = parse_file(fp, tmpboard, eflag); - tfree(tmpboard); - - /* Now apply these moves to the board we were given... */ - loading_flag = true; - while (m) { - if (!quickflag) - XSync(win1->display, 0); - win_process(true); - if (!quickflag) - sleep(1); - if (!loading_paused) { - prog_move(m); - m = m->next; - } - } - loading_flag = false; - if (line) - message_add(win1, line, false); - - while (fgets(buf, BSIZE, fp)) - message_add(win1, buf, false); - - fclose(fp); - - return; -} - -/* Given a starting position (usually the beginning board configuration), - * read in a file of moves. - */ - -move * -parse_file(fp, b, english) - FILE *fp; - board *b; - bool english; -{ - move *mvs = NULL, *end = NULL; - char buf[BSIZE], *s, *t; - - while (fgets(buf, BSIZE, fp)) { - if (*buf == '#') - continue; - s = buf; - - /* The move number... */ - if (!(t = gettok(&s))) - break; - if (!isdigit(*t)) { - line = copy(buf); - break; - } - - if (!(t = gettok(&s))) - break; - if (end) - end = end->next = (english ? parse_move(b, t, WHITE) : - parse_imove(b, t, WHITE)); - else - mvs = end = (english ? parse_move(b, t, WHITE) : - parse_imove(b, t, WHITE)); - if (!end) { - fprintf(stderr, "Can't parse %s\n", buf); - return (NULL); - } - board_move(b, end); - - if (!(t = gettok(&s))) - break; - if (end) - end = end->next = (english ? parse_move(b, t, BLACK) : - parse_imove(b, t, BLACK)); - else - mvs = end = (english ? parse_move(b, t, BLACK) : - parse_imove(b, t, BLACK)); - if (!end) { - fprintf(stderr, "Can't parse %s\n", buf); - return (NULL); - } - board_move(b, end); - } - - return (mvs); -} - -/* Parse a move. The move format accepted is as follows - - * move: spec-spec - * capture: specxspec - * kcastle: 2 o's - * qcastle: 3 o's - * A spec is either piece/pos, piece, or just pos. A pos consists of a column - * name followed by a row number. If the column name is kr, kn, kb, k, q, - * qb, qn, or qr, then the row number is according to the english system, - * or if it is a-h then it is according to the international system. - * - *** As of now the spec must include the position. - */ - -move * -parse_move(b, str, w) - board *b; - char *str; - color w; -{ - move *m = alloc(move); - char *s; - char spec1[16], spec2[16]; - int i, j; - -if (debug) fprintf(stderr, "parsing %s\n", str); - - /* Check for castles. */ - for (s = str, i = 0; *s; s++) - if ((*s == 'o') || (*s == 'O')) - i++; - if (i == 2) { - m->type = KCASTLE; - m->piece.type = KING; - m->piece.color = w; - return (m); - } else if (i == 3) { - m->type = QCASTLE; - m->piece.type = KING; - m->piece.color = w; - return (m); - } - if (index(str, '-')) - m->type = MOVE; - else if (index(str, 'x')) - m->type = CAPTURE; - else - return (NULL); - for (i = 0; str[i]; i++) - if ((str[i] == 'x') || (str[i] == '-')) - break; - else - spec1[i] = str[i]; - spec1[i] = '\0'; - for (i++, j = 0; str[i]; i++, j++) - if ((str[i] == 'x') || (str[i] == '-')) - break; - else - spec2[j] = str[i]; - spec2[j] = '\0'; - - /* Now decode the specifications. */ - s = spec1; - switch (*s) { - case 'p': case 'P': - m->piece.type = PAWN; break; - case 'r': case 'R': - m->piece.type = ROOK; break; - case 'n': case 'N': - m->piece.type = KNIGHT; break; - case 'b': case 'B': - m->piece.type = BISHOP; break; - case 'q': case 'Q': - m->piece.type = QUEEN; break; - case 'k': case 'K': - m->piece.type = KING; break; - default: - return (NULL); - } - m->piece.color = w; - s += 2; - - /* Now get the {q,k}{,b,n,r}n string... */ - if ((s[0] == 'q') && (s[1] == 'r')) - m->fromx = 0, s += 2; - else if ((s[0] == 'q') && (s[1] == 'n')) - m->fromx = 1, s += 2; - else if ((s[0] == 'q') && (s[1] == 'b')) - m->fromx = 2, s += 2; - else if ((s[0] == 'q') && isdigit(s[1])) - m->fromx = 3, s += 1; - else if ((s[0] == 'k') && isdigit(s[1])) - m->fromx = 4, s += 1; - else if ((s[0] == 'k') && (s[1] == 'b')) - m->fromx = 5, s += 2; - else if ((s[0] == 'k') && (s[1] == 'n')) - m->fromx = 6, s += 2; - else if ((s[0] == 'k') && (s[1] == 'r')) - m->fromx = 7, s += 2; - m->fromy = ((w == WHITE) ? (SIZE - atoi(s)) : (atoi(s) - 1)); - - if ((b->square[m->fromy][m->fromx].color != w) || - (b->square[m->fromy][m->fromx].type != m->piece.type)) { - fprintf(stderr, "Error: bad stuff\n"); - return (NULL); - } - - s = spec2; - if (m->type == CAPTURE) { - switch (*s) { - case 'p': case 'P': - m->taken.type = PAWN; break; - case 'r': case 'R': - m->taken.type = ROOK; break; - case 'n': case 'N': - m->taken.type = KNIGHT; break; - case 'b': case 'B': - m->taken.type = BISHOP; break; - case 'q': case 'Q': - m->taken.type = QUEEN; break; - case 'k': case 'K': - m->taken.type = KING; break; - default: - return (NULL); - } - m->taken.color = ((w == WHITE) ? BLACK : WHITE); - s += 2; - } - - /* Now get the {q,k}{,b,n,r}n string... */ - if ((s[0] == 'q') && (s[1] == 'r')) - m->tox = 0, s += 2; - else if ((s[0] == 'q') && (s[1] == 'n')) - m->tox = 1, s += 2; - else if ((s[0] == 'q') && (s[1] == 'b')) - m->tox = 2, s += 2; - else if ((s[0] == 'q') && isdigit(s[1])) - m->tox = 3, s += 1; - else if ((s[0] == 'k') && isdigit(s[1])) - m->tox = 4, s += 1; - else if ((s[0] == 'k') && (s[1] == 'b')) - m->tox = 5, s += 2; - else if ((s[0] == 'k') && (s[1] == 'n')) - m->tox = 6, s += 2; - else if ((s[0] == 'k') && (s[1] == 'r')) - m->tox = 7, s += 2; - m->toy = ((w == WHITE) ? (SIZE - atoi(s)) : (atoi(s) - 1)); - - if ((m->type == CAPTURE) && ((b->square[m->toy][m->tox].color != - m->taken.color) || (b->square[m->toy][m->tox].type != - m->taken.type))) { - fprintf(stderr, "Error: bad stuff\n"); - return (NULL); - } - - return (m); -} - -/* Parse an algebraic notation move. This is a lot easier... */ - -move * -parse_imove(b, buf, w) - board *b; - char *buf; - color w; -{ - char *s; - move *m = alloc(move); - int n; - -if (debug) fprintf(stderr, "(alg) parsing %s\n", buf); - - for (s = buf, n = 0; *s; s++) - if ((*s == 'o') || (*s == 'O')) - n++; - s = buf; - - if (n == 2) - m->type = KCASTLE; - else if (n == 3) - m->type = QCASTLE; - else { - m->fromx = *s++ - 'a'; - m->fromy = SIZE - (*s++ - '0'); - m->tox = *s++ - 'a'; - m->toy = SIZE - (*s++ - '0'); - m->piece = b->square[m->fromy][m->fromx]; - m->taken = b->square[m->toy][m->tox]; - if (m->taken.color == NONE) - m->type = MOVE; - else - m->type = CAPTURE; - /* for pawns we must account for en passant */ - if (m->piece.type == PAWN) { - if (m->type == MOVE && m->fromx != m->tox) { - m->enpassant = 1; - m->type = CAPTURE; - } - } - } - - if (m->piece.color != w) { - fprintf(stderr, "Error: parse_imove: piece of wrong color!\n"); - return (NULL); - } - if ((m->piece.type == KING) && (m->fromy == m->toy) && (m->fromx == 4) - && (m->tox == 6)) - m->type = KCASTLE; - else if ((m->piece.type == KING) && (m->fromy == m->toy) && - (m->fromx == 4) && (m->tox == 2)) - m->type = QCASTLE; - - return (m); -} - diff --git a/gnu/games/chess/Xchess/popup.c b/gnu/games/chess/Xchess/popup.c deleted file mode 100644 index 0995638..0000000 --- a/gnu/games/chess/Xchess/popup.c +++ /dev/null @@ -1,112 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:13 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/popup.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * faustus@cad.berkeley.edu, ucbvax!faustus - * Permission is granted to modify and re-distribute this code in any manner - * as long as this notice is preserved. All standard disclaimers apply. - * - * A simple pop-up menu system. - */ - -#include "xchess.h" - -/* Open a small window with some text in it and two buttons -- yes and no. - * Use black and white pixel, and the medium font. - */ - -bool -pop_question(win, text) - windata *win; - char *text; -{ - char *s, *t; - int nlines = 1, ncols = 0, i = 0, j; - int x, y; - Window w; - bool ch; - XEvent ev; - - for (s = text; *s; s++) { - if ((*s == '\n') && s[1]) - nlines++; - if ((*s == '\n') || !s[1]) { - if (i > ncols) - ncols = i; - i = 0; - } else - i++; - } - - if (ncols < 12) - ncols = 12; - nlines += 4; - ncols += 4; - - x = (BASE_WIDTH - ncols * win->medium->max_bounds.width) / 2; - y = (BASE_HEIGHT - nlines * win->medium->max_bounds.ascent) / 2; - - w = XCreateSimpleWindow(win->display, win->basewin, - x, y, ncols * win->medium->max_bounds.width, - nlines * win->medium->ascent, - BORDER_WIDTH, win->border.pixel, - win->textback.pixel); - XMapRaised(win->display, w); - XSetFont(win->display, DefaultGC(win->display, 0), - win->medium->fid); - - for (i = 0, s = text; i < nlines - 4; i++) { - for (t = s, j = 0; *t && (*t != '\n'); t++, j++) - ; - XDrawString(win->display, w, DefaultGC(win->display, 0), - (ncols - j) / 2 * win->medium->max_bounds.width, - (i + 1) * win->medium->ascent, - s, j); - s = t + 1; - } - XDrawString(win->display, w, DefaultGC(win->display, 0), - (ncols - 8) * win->medium->max_bounds.width / 4, - (nlines - 2) * win->medium->ascent, - "YES", 3); - XDrawString(win->display, w, DefaultGC(win->display, 0), - (ncols - 4) * win->medium->max_bounds.width * 3 / 4, - (nlines - 2) * win->medium->ascent, - "NO", 2); - - XSync(win->display, 0); - XSelectInput(win->display, w, ButtonPressMask); - XWindowEvent(win->display, w, ButtonPressMask, &ev); - x = ev.xkey.x; - y = ev.xkey.y; - - if (x > ncols * win->medium->max_bounds.width / 2) - ch = false; - else - ch = true; - - XDestroyWindow(win->display, w); - XSync(win->display, 0); - return (ch); -} - diff --git a/gnu/games/chess/Xchess/program.c b/gnu/games/chess/Xchess/program.c deleted file mode 100644 index e2eb186..0000000 --- a/gnu/games/chess/Xchess/program.c +++ /dev/null @@ -1,204 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.3 $ on $Date: 1994/11/04 02:11:30 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/program.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - * The interface to whichever chess playing program we are using... - */ - -#include "xchess.h" -#include -#include - -static int pid; -static FILE *from; -static FILE *to; -static bool easy = 1; - -bool -program_init(name) - char *name; -{ - int toprog[2], fromprog[2]; - char buf[BSIZE]; - char time[10]; - char moves[10]; - - pipe(toprog); - pipe(fromprog); - - if (!(pid = fork())) { - /* Start up the program. */ - dup2(toprog[0], 0); - dup2(fromprog[1], 1); - close(toprog[0]); - close(toprog[1]); - close(fromprog[0]); - close(fromprog[1]); - sprintf (time, "%d", timeunit/60); - sprintf (moves, "%d", movesperunit); - if (proghost) - execl("/usr/ucb/rsh", "rsh", proghost, name, - moves, time, - (char *) NULL); - else - execl(name, name, moves, time, (char *) NULL); - perror(name); - exit(1); - } - - close(toprog[0]); - close(fromprog[1]); - - from = fdopen(fromprog[0], "r"); - setbuf(from, NULL); - to = fdopen(toprog[1], "w"); - setbuf(to, NULL); - - /* Get the first line... */ - fgets(buf, BSIZE, from); - if (debug) - fprintf(stderr, "program says %s", buf); - if (blackflag) { - fputs("switch\n", to); - fflush(to); - fgets(buf, BSIZE, from); - if (debug) - fprintf(stderr, "program says %s", buf); - message_add(win1, "GNU Chess playing white\n", false); - } else - message_add(win1, "GNU Chess playing black\n", false); - - return (true); -} - -void -program_end() -{ - fclose(from); - fclose(to); - kill(pid, SIGTERM); - return; -} - -void -program_send(m) - move *m; -{ - char buf[BSIZE]; - - if ((m->type == MOVE) || (m->type == CAPTURE)) - sprintf(buf, "%c%d%c%d\n", 'a' + m->fromx, SIZE - m->fromy, - 'a' + m->tox, SIZE - m->toy); - else if (m->type == KCASTLE) - strcpy(buf, (m->piece.color == WHITE) ? "e1g1\n" : "e8g8\n"); - else if (m->type == QCASTLE) - strcpy(buf, (m->piece.color == WHITE) ? "e1c1\n" : "e8c8\n"); - - if (debug) - fprintf(stderr, "sending program %s", buf); - if (!easy) - kill (pid, SIGINT); - - fputs(buf, to); - fflush(to); - - /* One junk line... */ - fgets(buf, BSIZE, from); - if (debug) - fprintf(stderr, "program says %s", buf); - return; -} - -move * -program_get() -{ - int rfd = (1 << fileno(from)), wfd = 0, xfd = 0; - static struct timeval notime = { 0, 0 }; - char buf[BSIZE], *s; - move *m; - int i; - - /* Do a poll... */ - -#ifdef __FreeBSD__ - if (!(i = select(32, &rfd, &wfd, &xfd, ¬ime))) { -#else - if (!(i = select(32, &rfd, &wfd, &xfd, ¬ime)) && - !from->_cnt) { /* Bad stuff... */ -#endif - if (debug) - fprintf(stderr, "poll: nothing\n"); - return (NULL); - } - if (i == -1) { - perror("select"); - return (NULL); - } - - fgets(buf, BSIZE, from); - if (*buf == '\n' || *buf == '\0') { - message_add(win1, "program died", false); - return (NULL); - } - - if (debug) - fprintf(stderr, "got from program %s", buf); - - for (s = buf; !isalpha(*s); s++) - ; - m = parse_imove(chessboard, s, nexttomove); - if (m == NULL) - return (NULL); - - if (!valid_move(m, chessboard)) { - fprintf(stderr, "Error: move %s is invalid!!\n", buf); - return (NULL); - } - - /* - fgets(buf, BSIZE, from); - if (debug) - fprintf(stderr, "program says %s", buf); - */ - message_add(win1, buf, false); - return (m); -} - -void -program_undo() -{ - fputs("undo\n", to); - return; -} -void -program_easy (mode) - bool mode; - -{ - fputs("easy\n", to); - easy = mode; -} diff --git a/gnu/games/chess/Xchess/record.c b/gnu/games/chess/Xchess/record.c deleted file mode 100644 index b2fcea1..0000000 --- a/gnu/games/chess/Xchess/record.c +++ /dev/null @@ -1,315 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:09 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/record.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - * Deal with recording moves. - */ - -#include "xchess.h" - -#undef smartass - -bool record_english = true; -char *record_file = DEF_RECORD_FILE; -int movenum = 0; -bool saveflag = false; - -static char *colnames[] = { "qr", "qn", "qb", "q", "k", "kb", "kn", "kr" } ; -static char *pcnames[] = { "P", "R", "N", "B", "Q", "K" } ; - -static char *movestring(); -static char *tstring(); -static FILE *backup; - -#define RECORD_HEADER "\n1 XChess Game Record0\n" - -void -record_init(win) - windata *win; -{ - int i; - - i = XTextWidth(win->medium, RECORD_HEADER, - sizeof(RECORD_HEADER) - 1); - i = (40 * win->small->max_bounds.width - i * - win->medium->max_bounds.width) / - win->medium->max_bounds.width / 2; - TxtGrab(win->display, win->recwin, "xchess", win->small, win->textback.pixel, - win->textcolor.pixel, win->cursorcolor.pixel); - TxtAddFont(win->display, win->recwin, 1, win->medium, win->textcolor.pixel); - for (; i > 0; i++) - TxtWriteStr(win->display, win->recwin, " "); - TxtWriteStr(win->display, win->recwin, RECORD_HEADER); - - if (saveflag) { - if (!(backup = fopen(record_file, "w"))) { - perror(record_file); - saveflag = false; - } else { - fprintf(backup, "X Chess -- %s\n", datestring()); - if (dispname2) - fprintf(backup, "\tWhite on %s, black on %s\n", - dispname1, dispname2); - else - fprintf(backup, "\tGame played on %s\n", - dispname1); - fprintf(backup, "\t%s\n", record_english ? "english" : - "algebraic"); - fflush(backup); - } - } - - movenum = 0; - return; -} - -void -record_reset() -{ - TxtWriteStr(win1->display, win1->recwin, "\n\n1 New Game0\n\n"); - if (!oneboard) { - TxtWriteStr(win2->display, win2->recwin, "\n\n1 New Game0\n\n"); - } - movenum = 0; - if (saveflag) { - fprintf(backup, "\n\nNew Game\n\n"); - fflush(backup); - } - return; -} - -void -record_end(s) - char *s; -{ - char buf[BSIZE]; - - sprintf(buf, "\n%s\n", s); - TxtWriteStr(win1->display, win1->recwin, s); - if (!oneboard) { - TxtWriteStr(win2->display, win2->recwin, s); - } - if (saveflag) { - fprintf(backup, "\n%s\n", s); - fprintf(backup, "Time: white: %s, ", tstring(whiteseconds)); - fprintf(backup, "black: %s\n", tstring(blackseconds)); - fclose(backup); - } - return; -} - -void -record_save() -{ - move *m; - FILE *fp; - int i; - char *s; - - if (!(fp = fopen(record_file, "w"))) { - perror(record_file); - return; - } - fprintf(fp, "X Chess -- %s\n", datestring()); - if (dispname2) - fprintf(fp, "\tWhite on %s, black on %s\n", - dispname1, dispname2); - else - fprintf(fp, "\tGame played on %s\n", dispname1); - fprintf(fp, "\t%s\n", record_english ? "english" : "algebraic"); - - for (m = moves, i = 1; m; i++) { - s = movestring(m); - fprintf(fp, "%2d. %-16s ", i, s); - m = m->next; - if (m) - s = movestring(m); - else - s = ""; - fprintf(fp, "%s\n", s); - if (m) - m = m->next; - } - fclose(fp); - return; -} - -void -record_move(m) - move *m; -{ - char *s, buf[BSIZE]; - - s = movestring(m); - - if (m->piece.color == WHITE) { - movenum++; - sprintf(buf, "%2d. %-16s ", movenum, s); - } else { - sprintf(buf, "%s\n", s); - } - TxtWriteStr(win1->display, win1->recwin, buf); - if (!oneboard) { - TxtWriteStr(win2->display, win2->recwin, buf); - } - if (saveflag) { - fprintf(backup, "%s", buf); - fflush(backup); - } - - return; -} - -void -record_back() -{ - extern move *lastmove; - move *m = lastmove; - char *s = movestring(m); - char buf[BSIZE]; - long i; - - if (m->piece.color == WHITE) { - sprintf(buf, "%2d. %-16s ", movenum, s); - } else { - sprintf(buf, "%s\n", s); - } - s = buf; - for (i = 0; *s != '\0'; i++) - *s++ = ''; /* control H, backspace */ - - TxtWriteStr(win1->display, win1->recwin, buf); - if (!oneboard) { - TxtWriteStr(win2->display, win2->recwin, buf); - } - - if (nexttomove == BLACK) - movenum--; - if (saveflag) { - fseek(backup, -i, 1); - fflush(backup); - } - - return; -} - -static char * -movestring(m) - move *m; -{ - int fy, ty; - static char buf[BSIZE]; - - if (!record_english || (m->piece.color == WHITE)) { - fy = SIZE - m->fromy; - ty = SIZE - m->toy; - } else { - fy = m->fromy + 1; - ty = m->toy + 1; - } - - switch (m->type) { - case MOVE: - if (record_english) - sprintf(buf, "%s/%s%d-%s%d%s", pcnames[(int) m->piece. - type], colnames[m->fromx], fy, - colnames[m->tox], ty, m->check ? "+" : - ""); - else - sprintf(buf, "%c%d%c%d", 'a' + m->fromx, fy, 'a' + - m->tox, ty); - break; - case CAPTURE: - if (record_english) - sprintf(buf, "%s/%s%dx%s/%s%d%s%s", - pcnames[(int) m->piece.type], - colnames[m->fromx], fy, - pcnames[(int) m->taken.type], - colnames[m->tox], ty, - m->enpassant ? "e.p." : "", - m->check ? "+" : ""); - else - sprintf(buf, "%c%d%c%d", 'a' + m->fromx, fy, 'a' + - m->tox, ty); - break; - - case KCASTLE: - if (record_english) - sprintf(buf, "O-O%s", m->check ? "ch" : ""); - else if (m->piece.color == WHITE) - strcpy(buf, "e1g1"); - else - strcpy(buf, "e8g8"); - break; - - case QCASTLE: - if (record_english) - sprintf(buf, "O-O-O%s", m->check ? "ch" : ""); - else if (m->piece.color == WHITE) - strcpy(buf, "e1c1"); - else - strcpy(buf, "e8c8"); - break; - - default: - sprintf(buf, "something strange"); - break; - } - if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) && - (m->toy == 7)) || ((m->piece.color == WHITE) && - (m->toy == 0)))) - strcat(buf, "(Q)"); - -#ifdef smartass - if (!(random() % 50)) - strcat(buf, "?"); - else if (!(random() % 50)) - strcat(buf, "!"); - else if (!(random() % 500)) - strcat(buf, "???"); - else if (!(random() % 500)) - strcat(buf, "!!!"); -#endif smartass - - return (buf); -} - -static char * -tstring(s) - int s; -{ - static char buf[64]; - - if (s > 3600) - sprintf(buf, "%dh %dm %ds", s / 3600, (s % 3600) / 60, s % 60); - else if (s > 60) - sprintf(buf, "%dm %ds", (s % 3600) / 60, s % 60); - else - sprintf(buf, "%ds", s); - return (buf); -} - diff --git a/gnu/games/chess/Xchess/scrollText.c b/gnu/games/chess/Xchess/scrollText.c deleted file mode 100644 index b8484dd..0000000 --- a/gnu/games/chess/Xchess/scrollText.c +++ /dev/null @@ -1,1877 +0,0 @@ -/* - * A Scrollable Text Output Window - * - * David Harrison - * University of California, Berkeley - * 1986 - * - * The following is an implementation for a scrollable text output - * system. It handles exposure events only (other interactions are - * under user control). For scrolling, a always present scroll bar - * is implemented. It detects size changes and compensates accordingly. - */ - -#include -#include -#include -#include -#include "scrollText.h" - -extern char *malloc(); -extern char *realloc(); -#define alloc(type) (type *) malloc(sizeof(type)) -#define numalloc(type, num) (type *) malloc((unsigned) (num * sizeof(type))) -#define MAXINT 2147483647 - -extern XAssocTable *XCreateAssocTable(); -extern caddr_t XLookUpAssoc(); - -static XAssocTable *textWindows = (XAssocTable *) 0; - -#define NOOPTION -1 /* Option hasn't been set yet */ -#define NORMSCROLL 0 /* Smooth scroll on LineToTop and TopToHere */ -#define JUMPSCROLL 1 /* Jump scrolling on LineToTop and TopToHere */ - -static int ScrollOption = NOOPTION; - -typedef char *Generic; - -#define DEFAULT_GC textInfo->fontGC[textInfo->curFont] - -#define BARSIZE 15 -#define BARBORDER 1 -#define MAXFONTS 8 -#define INITBUFSIZE 1024 -#define INITLINES 50 -#define INITEXPARY 50 -#define XPADDING 2 -#define YPADDING 2 -#define INTERLINE 5 -#define INTERSPACE 1 -#define CURSORWIDTH 2 -#define EXPANDPERCENT 40 -#define BUFSIZE 1024 -#define CUROFFSET 1 -#define MAXFOREIGN 250 -#define NOINDEX -1 - -/* The wrap line indicator */ -#define WRAPINDSIZE 7 -#define STEMOFFSET 5 -#define arrow_width 7 -#define arrow_height 5 -static char arrow_bits[] = { - 0x24, 0x26, 0x3f, 0x06, 0x04}; - -#define NEWLINE '\n' -#define BACKSPACE '\010' -#define NEWFONT '\006' -#define LOWCHAR '\040' -#define HIGHCHAR '\176' - -#define CHARMASK 0x00ff /* Character mask */ -#define FONTMASK 0x0700 /* Character font */ -#define FONTSHIFT 8 /* Shift amount */ - -#define WRAPFLAG 0x01 /* Line wrap flag */ - -/* - * Lines are represented by a pointer into the overall array of - * 16-bit characters. The lower eight bits is used to indicate the character - * (in ASCII), and the next two bits are used to indicate the font - * the character should be drawn in. - */ - -typedef struct txtLine { - int lineLength; /* Current line length */ - int lineHeight; /* Full height of line in pixels */ - int lineBaseLine; /* Current baseline of the line */ - int lineWidth; /* Drawing position at end of line */ - int lineText; /* Offset into master buffer */ - int lineFlags; /* Line wrap flag is here */ -}; - - -/* - * For ExposeCopy events, we queue up the redraw requests collapsing - * them into line redraw requests until the CopyExpose event arrives. - * The queue is represented as a dynamic array of the following - * structure: - */ - -typedef struct expEvent { - int lineIndex; /* Index of line to redraw */ - int ypos; /* Drawing position of line */ -}; - - -/* - * The text buffer is represented using a dynamic counted array - * of 16-bit quantities. This array expands as needed. - * For the screen representation, a dynamic counted array - * of line structures is used. This array points into the - * text buffer to denote the start of each line and its parameters. - * The windows are configured as one overall window which contains - * the scroll bar as a sub-window along its right edge. Thus, - * the text drawing space is actually w-BARSIZE. - */ - -#define NOTATBOTTOM 0x01 /* Need to scroll to bottom before appending */ -#define FONTNUMWAIT 0x02 /* Waiting for font number */ -#define COPYEXPOSE 0x04 /* Need to process a copy expose event */ -#define SCREENWRONG 0x08 /* TxtJamStr has invalidated screen contents */ - -typedef struct txtWin { - /* Basic text buffer */ - int bufAlloc; /* Allocated size of buffer */ - int bufSpot; /* Current writing position in buffer */ - short *mainBuffer; /* Main buffer of text */ - - /* Line information */ - int numLines; /* Number of display lines in buffer */ - int allocLines; /* Number of lines allocated */ - struct txtLine **txtBuffer; /* Dynamic array of lines */ - - /* Current Window display information */ - Window mainWindow; /* Text display window */ - Window scrollBar; /* Subwindow for scroll bar */ - Pixmap arrowMap; /* line wrap indicator */ - int bgPix, fgPix; /* Background and cursor */ - GC CursorGC; /* gc for the cursor */ - GC bgGC; /* gc for erasing things */ - GC fontGC[MAXFONTS]; /* gc for doing fonts */ - XFontStruct theFonts[MAXFONTS];/* Display fonts */ - int theColors[MAXFONTS]; /* foregrounds of the fonts */ - int curFont; /* current font for tracking */ - int w, h; /* Current size */ - int startLine; /* Top line in display */ - int endLine; /* Bottom line in display */ - int bottomSpace; /* Space at bottom of screen */ - int flagWord; /* If non-zero, not at end */ - - /* For handling ExposeCopy events */ - int exposeSize; /* Current size of array */ - int exposeAlloc; /* Allocated size */ - struct expEvent **exposeAry;/* Array of line indices */ - - /* Drawing position information */ - int curLine; /* Current line in buffer */ - int curX; /* Current horizontal positi */ - int curY; /* Current vertical drawing */ -}; - -/* Flags for the various basic character handling functions */ - -#define DODISP 0x01 /* Update the display */ -#define NONEWLINE 0x02 /* Dont append newline */ - - - -static int InitLine(newLine) -struct txtLine *newLine; /* Newly created line structure */ -/* - * This routine initializes a newly created line structure. - */ -{ - newLine->lineLength = 0; - newLine->lineHeight = 0; - newLine->lineBaseLine = 0; - newLine->lineWidth = XPADDING; - newLine->lineText = NOINDEX; - newLine->lineFlags = 0; - return 1; -} - - - - -int TxtGrab(display, txtWin, program, mainFont, bg, fg, cur) -Display *display; /* display window is on */ -Window txtWin; /* Window to take over as scrollable text */ -char *program; /* Program name for Xdefaults */ -XFontStruct *mainFont; /* Primary text font */ -int bg, fg, cur; /* Background, foreground, and cursor colors */ -/* - * This routine takes control of 'txtWin' and makes it into a scrollable - * text output window. It will create a sub-window for the scroll bar - * with a background of 'bg' and an bar with color 'fg'. Both fixed width - * and variable width fonts are supported. Additional fonts can be loaded - * using 'TxtAddFont'. Returns 0 if there were problems, non-zero if - * everything went ok. - */ -{ - struct txtWin *newWin; /* Text package specific information */ - XWindowAttributes winInfo; /* Window information */ - int index; - XGCValues gc_val; - - if (textWindows == (XAssocTable *) 0) { - textWindows = XCreateAssocTable(32); - if (textWindows == (XAssocTable *) 0) return(0); - } - if (XGetWindowAttributes(display, txtWin, &winInfo) == 0) return 0; - - if (ScrollOption == NOOPTION) { - /* Read to see if the user wants jump scrolling or not */ - if (XGetDefault(display, program, "JumpScroll")) { - ScrollOption = JUMPSCROLL; - } else { - ScrollOption = NORMSCROLL; - } - } - - /* Initialize local structure */ - newWin = alloc(struct txtWin); - - /* Initialize arrow pixmap */ - newWin->arrowMap = XCreatePixmapFromBitmapData(display, txtWin, - arrow_bits, - arrow_width, arrow_height, - cur, bg, - DisplayPlanes(display, 0)); - - newWin->bufAlloc = INITBUFSIZE; - newWin->bufSpot = 0; - newWin->mainBuffer = numalloc(short, INITBUFSIZE); - - newWin->numLines = 1; - newWin->allocLines = INITLINES; - newWin->txtBuffer = numalloc(struct txtLine *, INITLINES); - for (index = 0; index < INITLINES; index++) { - newWin->txtBuffer[index] = alloc(struct txtLine); - InitLine(newWin->txtBuffer[index]); - } - - /* Window display information */ - newWin->mainWindow = txtWin; - newWin->w = winInfo.width; - newWin->h = winInfo.height; - newWin->startLine = 0; - newWin->endLine = 0; - newWin->bottomSpace = winInfo.height - - YPADDING - mainFont->ascent - mainFont->descent - INTERLINE; - newWin->flagWord = 0; - newWin->bgPix = bg; - newWin->fgPix = fg; - - /* Scroll Bar Creation */ - newWin->scrollBar = XCreateSimpleWindow(display, txtWin, - winInfo.width - BARSIZE, - 0, BARSIZE - (2*BARBORDER), - winInfo.height - (2*BARBORDER), - BARBORDER, - fg, bg); - XSelectInput(display, newWin->scrollBar, ExposureMask|ButtonReleaseMask); - XMapRaised(display, newWin->scrollBar); - - /* Font and Color Initialization */ - newWin->theFonts[0] = *mainFont; - newWin->theColors[0] = fg; - gc_val.function = GXcopy; - gc_val.plane_mask = AllPlanes; - gc_val.foreground = fg; - gc_val.background = bg; - gc_val.graphics_exposures = 1; - gc_val.font = mainFont->fid; - gc_val.line_width = 1; - gc_val.line_style = LineSolid; - - newWin->fontGC[0] = XCreateGC(display, txtWin, - GCFunction | GCPlaneMask | - GCForeground | GCBackground | - GCGraphicsExposures | GCFont, - &gc_val); - - gc_val.foreground = cur; - newWin->CursorGC = XCreateGC(display, txtWin, - GCFunction | GCPlaneMask | - GCForeground | GCBackground | - GCLineStyle | GCLineWidth, - &gc_val); - - gc_val.foreground = bg; - newWin->bgGC = XCreateGC(display, txtWin, - GCFunction | GCPlaneMask | - GCForeground | GCBackground | - GCGraphicsExposures | GCFont, - &gc_val); - - - for (index = 1; index < MAXFONTS; index++) { - newWin->theFonts[index].fid = 0; - newWin->fontGC[index] = 0; - } - - - /* Initialize size of first line */ - newWin->txtBuffer[0]->lineHeight = newWin->theFonts[0].ascent + - newWin->theFonts[0].descent; - newWin->txtBuffer[0]->lineText = 0; - - /* ExposeCopy array initialization */ - newWin->exposeSize = 0; - newWin->exposeAlloc = INITEXPARY; - newWin->exposeAry = numalloc(struct expEvent *, INITEXPARY); - for (index = 0; index < newWin->exposeAlloc; index++) - newWin->exposeAry[index] = alloc(struct expEvent); - /* Put plus infinity in last slot for sorting purposes */ - newWin->exposeAry[0]->lineIndex = MAXINT; - - /* Drawing Position Information */ - newWin->curLine = 0; - newWin->curX = 0; - newWin->curY = YPADDING + mainFont->ascent + mainFont->descent; - - /* Attach it to both windows */ - XMakeAssoc(display, textWindows, (XID) txtWin, (caddr_t) newWin); - XMakeAssoc(display, textWindows, (XID) newWin->scrollBar, (caddr_t) newWin); - return 1; -} - - -int TxtRelease(display, w) -Display *display; -Window w; /* Window to release */ -/* - * This routine releases all resources associated with the - * specified window which are consumed by the text - * window package. This includes the entire text buffer, line start - * array, and the scroll bar window. However, the window - * itself is NOT destroyed. The routine will return zero if - * the window is not owned by the text window package. - */ -{ - struct txtWin *textInfo; - int index; - - if ((textInfo = (struct txtWin *) XLookUpAssoc(display, - textWindows, (XID) w)) == 0) - return 0; - - for (index = 0; index < MAXFONTS; index++) - if (textInfo->fontGC[index] != 0) - XFreeGC(display, textInfo->fontGC[index]); - - free((Generic) textInfo->mainBuffer); - for (index = 0; index < textInfo->numLines; index++) { - free((Generic) textInfo->txtBuffer[index]); - } - free((Generic) textInfo->txtBuffer); - XDestroyWindow(display, textInfo->scrollBar); - for (index = 0; index < textInfo->exposeSize; index++) { - free((Generic) textInfo->exposeAry[index]); - } - free((Generic) textInfo->exposeAry); - XDeleteAssoc(display, textWindows, (XID) w); - free((Generic) textInfo); - return 1; -} - - - -static int RecompBuffer(textInfo) -struct txtWin *textInfo; /* Text window information */ -/* - * This routine recomputes all line breaks in a buffer after - * a change in window size or font. This is done by throwing - * away the old line start array and recomputing it. Although - * a lot of this work is also done elsewhere, it has been included - * inline here for efficiency. - */ -{ - int startPos, endSize, linenum; - register int index, chsize, curfont; - register short *bufptr; - register XFontStruct *fontptr; - register struct txtLine *lineptr; - char theChar; - - /* Record the old position so we can come back to it */ - for (startPos = textInfo->txtBuffer[textInfo->startLine]->lineText; - (startPos > 0) && (textInfo->mainBuffer[startPos] != '\n'); - startPos--) - /* null loop body */; - - /* Clear out the old line start array */ - for (index = 0; index < textInfo->numLines; index++) { - InitLine(textInfo->txtBuffer[index]); - } - - /* Initialize first line */ - textInfo->txtBuffer[0]->lineHeight = - textInfo->theFonts[0].ascent + textInfo->theFonts[0].descent; - textInfo->txtBuffer[0]->lineText = 0; - - /* Process the text back into lines */ - endSize = textInfo->w - BARSIZE - WRAPINDSIZE; - bufptr = textInfo->mainBuffer; - lineptr = textInfo->txtBuffer[0]; - linenum = 0; - fontptr = &(textInfo->theFonts[0]); - curfont = 0; - for (index = 0; index < textInfo->bufSpot; index++) { - theChar = bufptr[index] & CHARMASK; - - if ((bufptr[index] & FONTMASK) != curfont) { - int newFontNum, heightDiff; - - /* Switch fonts */ - newFontNum = (bufptr[index] & FONTMASK) >> FONTSHIFT; - if (textInfo->theFonts[newFontNum].fid != 0) { - /* Valid font */ - curfont = bufptr[index] & FONTMASK; - fontptr = &(textInfo->theFonts[newFontNum]); - heightDiff = (fontptr->ascent + fontptr->descent) - - lineptr->lineHeight; - if (heightDiff < 0) heightDiff = 0; - lineptr->lineHeight += heightDiff; - } - } - if (theChar == '\n') { - /* Handle new line */ - if (linenum >= textInfo->allocLines-1) - /* Expand number of lines */ - ExpandLines(textInfo); - linenum++; - lineptr = textInfo->txtBuffer[linenum]; - /* Initialize next line */ - lineptr->lineHeight = fontptr->ascent + fontptr->descent; - lineptr->lineText = index+1; - /* Check to see if its the starting line */ - if (index == startPos) textInfo->startLine = linenum; - } else { - /* Handle normal character */ - chsize = CharSize(textInfo, linenum, index); - if (lineptr->lineWidth + chsize > endSize) { - /* Handle line wrap */ - lineptr->lineFlags |= WRAPFLAG; - if (linenum >= textInfo->allocLines-1) - /* Expand number of lines */ - ExpandLines(textInfo); - linenum++; - lineptr = textInfo->txtBuffer[linenum]; - /* Initialize next line */ - lineptr->lineHeight = fontptr->ascent + fontptr->descent; - lineptr->lineText = index; - lineptr->lineLength = 1; - lineptr->lineWidth += chsize; - } else { - /* Handle normal addition of character */ - lineptr->lineLength += 1; - lineptr->lineWidth += chsize; - } - } - } - /* We now have a valid line array. Let's clean up some other fields. */ - textInfo->numLines = linenum+1; - if (startPos == 0) { - textInfo->startLine = 0; - } - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - textInfo->curLine = linenum; - /* Check to see if we are at the bottom */ - if (textInfo->endLine >= textInfo->numLines-1) { - textInfo->curY = textInfo->h - textInfo->bottomSpace - - lineptr->lineHeight; - textInfo->flagWord &= (~NOTATBOTTOM); - } else { - textInfo->flagWord |= NOTATBOTTOM; - } - return 1; -} - - - - -int TxtAddFont(display, textWin, fontNumber, newFont, newColor) -Display *display; -Window textWin; /* Scrollable text window */ -int fontNumber; /* Place to add font (0-7) */ -XFontStruct *newFont; /* Font to add */ -int newColor; /* Color of font */ -/* - * This routine loads a new font so that it can be used in a previously - * created text window. There are eight font slots numbered 0 through 7. - * If there is already a font in the specified slot, it will be replaced - * and an automatic redraw of the window will take place. See TxtWriteStr - * for details on using alternate fonts. The color specifies the foreground - * color of the text. The default foreground color is used if this - * parameter is TXT_NO_COLOR. Returns a non-zero value if - * everything went well. - */ -{ - struct txtWin *textInfo; - int redrawFlag; - XGCValues gc_val; - - if ((fontNumber < 0) || (fontNumber >= MAXFONTS)) return 0; - if ((textInfo = (struct txtWin *) - XLookUpAssoc(display, textWindows, (XID) textWin)) == 0) - return 0; - if (newColor == TXT_NO_COLOR) { - newColor = textInfo->fgPix; - } - - gc_val.font = newFont->fid; - gc_val.foreground = newColor; - gc_val.background = textInfo->bgPix; - gc_val.plane_mask = AllPlanes; - gc_val.graphics_exposures = 1; - gc_val.function = GXcopy; - - if (textInfo->fontGC[fontNumber] != 0) - { - XChangeGC(display, textInfo->fontGC[fontNumber], - GCFont | GCForeground, &gc_val); - } - else - textInfo->fontGC[fontNumber] = XCreateGC(display, textWin, - GCFont | - GCForeground | - GCBackground | - GCFunction | - GCPlaneMask | - GCGraphicsExposures, - &gc_val); - - - redrawFlag = (textInfo->theFonts[fontNumber].fid != 0) && - (((newFont) && (newFont->fid != textInfo->theFonts[fontNumber].fid)) || - (newColor != textInfo->theColors[fontNumber])); - if (newFont) { - textInfo->theFonts[fontNumber] = *newFont; - } - textInfo->theColors[fontNumber] = newColor; - - if (redrawFlag) { - RecompBuffer(textInfo); - XClearWindow(display, textWin); - TxtRepaint(display, textWin); - } - return 1; -} - - - -int TxtWinP(display, w) -Display *display; -Window w; -/* - * Returns a non-zero value if the window has been previously grabbed - * using TxtGrab and 0 if it has not. - */ -{ - if (XLookUpAssoc(display, textWindows, (XID) w)) - return(1); - else return(0); -} - - - -static int FindEndLine(textInfo, botSpace) -struct txtWin *textInfo; -int *botSpace; -/* - * Given the starting line in 'textInfo->startLine', this routine - * determines the index of the last line that can be drawn given the - * current size of the screen. If there are not enough lines to - * fill the screen, the index of the last line will be returned. - * The amount of empty bottom space is returned in 'botSpace'. - */ -{ - int index, height, lineHeight; - - height = YPADDING; - index = textInfo->startLine; - while (index < textInfo->numLines) { - lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE; - if (height + lineHeight > textInfo->h) break; - height += lineHeight; - index++; - } - if (botSpace) { - *botSpace = textInfo->h - height; - } - return index - 1; -} - - - -static int UpdateScroll(display, textInfo) -Display *display; -struct txtWin *textInfo; /* Text window information */ -/* - * This routine computes the current extent of the scroll bar - * indicator and repaints the bar with the correct information. - */ -{ - int top, bottom; - - if (textInfo->numLines > 1) { - top = textInfo->startLine * (textInfo->h - 2*BARBORDER) / - (textInfo->numLines - 1); - bottom = textInfo->endLine * (textInfo->h - 2*BARBORDER) / - (textInfo->numLines - 1); - } else { - top = 0; - bottom = textInfo->h - (2*BARBORDER); - } - - /* Draw it - make sure there is a little padding */ - if (top == 0) top++; - if (bottom == textInfo->h-(2*BARBORDER)) bottom--; - - XFillRectangle(display, textInfo->scrollBar, - textInfo->bgGC, - 0, 0, BARSIZE, top-1); -#ifdef __FreeBSD__ - XFillRectangle(display, textInfo->scrollBar, - DEFAULT_GC, top, BARSIZE - (2*BARBORDER) - 2, - BARSIZE, bottom - top); -#else - XFillRectangle(display, textInfo->scrollBar, - DEFAULT_GC, top, BARSIZE - (2*BARBORDER) - 2, - bottom - top); -#endif - XFillRectangle(display, textInfo->scrollBar, DEFAULT_GC, - 0, bottom+1, BARSIZE, - textInfo->h - (2 * BARBORDER) - bottom); - - return 1; -} - - - - -int TxtClear(display, w) -Display *display; -Window w; -/* - * This routine clears a scrollable text window. It resets the current - * writing position to the upper left hand corner of the screen. - * NOTE: THIS ALSO CLEARS THE CONTENTS OF THE TEXT WINDOW BUFFER AND - * RESETS THE SCROLL BAR. Returns 0 if the window is not a text window. - * This should be used *instead* of XClear. - */ -{ - struct txtWin *textInfo; - int index; - - if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0) - return 0; - - /* Zero out the arrays */ - textInfo->bufSpot = 0; - for (index = 0; index < textInfo->numLines; index++) { - InitLine(textInfo->txtBuffer[index]); - } - textInfo->txtBuffer[0]->lineHeight = - textInfo->theFonts[textInfo->curFont].ascent + - textInfo->theFonts[textInfo->curFont].descent; - - textInfo->numLines = 1; - textInfo->startLine = 0; - textInfo->endLine = 0; - textInfo->curLine = 0; - textInfo->curX = 0; - textInfo->curY = YPADDING + textInfo->theFonts[textInfo->curFont].ascent - + textInfo->theFonts[textInfo->curFont].descent; - - textInfo->bottomSpace = textInfo->h - YPADDING - - textInfo->theFonts[textInfo->curFont].ascent - INTERLINE - - textInfo->theFonts[textInfo->curFont].descent; - /* Actually clear the window */ - XClearWindow(display, w); - - /* Draw the current cursor */ - XFillRectangle(display, w, textInfo->CursorGC, - XPADDING + CUROFFSET, textInfo->curY, - CURSORWIDTH, - textInfo->theFonts[textInfo->curFont].ascent + - textInfo->theFonts[textInfo->curFont].descent); - - /* Update the scroll bar */ - UpdateScroll(display, textInfo); - return 1; -} - - -static int WarpToBottom(display, textInfo) -Display *display; -struct txtWin *textInfo; /* Text Information */ -/* - * This routine causes the specified text window to display its - * last screen of information. It updates the scroll bar - * to the appropriate spot. The implementation scans backward - * through the buffer to find an appropriate starting spot for - * the window. - */ -{ - int index, height, lineHeight; - - index = textInfo->numLines-1; - height = 0; - while (index >= 0) { - lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE; - if (height + lineHeight > textInfo->h) break; - height += lineHeight; - index--; - } - textInfo->startLine = index + 1; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - textInfo->curY = textInfo->h - textInfo->bottomSpace - - textInfo->txtBuffer[textInfo->endLine]->lineHeight; - XClearWindow(display, textInfo->mainWindow); - TxtRepaint(display, textInfo->mainWindow); - return 1; -} - - - -static int UpdateExposures(display, textInfo) -Display *display; -struct txtWin *textInfo; /* Text window information */ -/* - * Before a new scrolling action occurs, the text window package - * must handle all COPYEXPOSE events generated by the last scrolling - * action. This routine is called to do this. Foreign events (those - * not handled by TxtFilter) are queued up and replaced on the queue - * after the processing of the exposure events is complete. - */ -{ -#if 0 - XEvent foreignQueue[MAXFOREIGN]; - int index, lastItem = 0; - - while (textInfo->flagWord & COPYEXPOSE) { - XNextEvent(display, &(foreignQueue[lastItem])); - if (!TxtFilter(display, &(foreignQueue[lastItem]))) - lastItem++; - if (lastItem >= MAXFOREIGN) { - printf("Too many foreign events to queue!\n"); - textInfo->flagWord &= (~COPYEXPOSE); - } - } - for (index = 0; index < lastItem; index++) { - XPutBackEvent(display, &(foreignQueue[index])); - } -#endif - return 1; -} - - -static int ScrollDown(display,textInfo) -Display *display; -struct txtWin *textInfo; /* Text window information */ -/* - * This routine scrolls the indicated text window down by one - * line. The line below the current line must exist. The window - * is scrolled so that the line below the last line is fully - * displayed. This may cause many lines to scroll off the top. - * Scrolling is done using XCopyArea. The exposure events should - * be caught using ExposeCopy. - */ -{ - int lineSum, index, targetSpace, freeSpace, updateFlag; - - lineSum = 0; - if (textInfo->endLine + 1 >= textInfo->numLines) return 0; - targetSpace = textInfo->txtBuffer[textInfo->endLine+1]->lineHeight + - INTERLINE; - if (textInfo->bottomSpace < targetSpace) { - index = textInfo->startLine; - while (index < textInfo->endLine) { - lineSum += (textInfo->txtBuffer[index]->lineHeight + INTERLINE); - if (textInfo->bottomSpace + lineSum >= targetSpace) break; - index++; - } - - /* Must move upward by 'lineSum' pixels */ - XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow, - DEFAULT_GC, 0, lineSum, - textInfo->w - BARSIZE, textInfo->h, - 0, 0); - - textInfo->flagWord |= COPYEXPOSE; - /* Repair the damage to the structures */ - textInfo->startLine = index + 1; - updateFlag = 1; - } else { - updateFlag = 0; - } - /* More lines might be able to fit. Let's check. */ - freeSpace = textInfo->bottomSpace + lineSum - targetSpace; - index = textInfo->endLine + 1; - while (index < textInfo->numLines-1) { - if (freeSpace - textInfo->txtBuffer[index+1]->lineHeight - INTERLINE < 0) - break; - freeSpace -= (textInfo->txtBuffer[index+1]->lineHeight + INTERLINE); - index++; - } - textInfo->endLine = index; - textInfo->bottomSpace = freeSpace; - if (updateFlag) { - UpdateExposures(display, textInfo); - } - UpdateScroll(display, textInfo); - return 1; -} - - - - -static int ExpandLines(textInfo) -struct txtWin *textInfo; /* Text Information */ -/* - * This routine allocates and initializes additional space in - * the line start array (txtBuffer). The new space - * is allocated using realloc. The expansion factor is a percentage - * given by EXPANDPERCENT. - */ -{ - int newSize, index; - - newSize = textInfo->allocLines; - newSize += (newSize * EXPANDPERCENT) / 100; - - textInfo->txtBuffer = (struct txtLine **) - realloc((char *) textInfo->txtBuffer, - (unsigned) (newSize * sizeof(struct txtLine *))); - for (index = textInfo->allocLines; index < newSize; index++) { - textInfo->txtBuffer[index] = alloc(struct txtLine); - InitLine(textInfo->txtBuffer[index]); - } - textInfo->allocLines = newSize; - return 1; -} - -static int ExpandBuffer(textInfo) -struct txtWin *textInfo; /* Text information */ -/* - * Expands the basic character buffer using realloc. The expansion - * factor is a percentage given by EXPANDPERCENT. - */ -{ - int newSize; - - newSize = textInfo->bufAlloc + (textInfo->bufAlloc * EXPANDPERCENT) / 100; - textInfo->mainBuffer = (short *) - realloc((char *) textInfo->mainBuffer, (unsigned) newSize * sizeof(short)); - textInfo->bufAlloc = newSize; - return 1; -} - - - -static int HandleNewLine(display, textInfo, flagWord) -Display *display; -struct txtWin *textInfo; /* Text Information */ -int flagWord; /* DODISP or NONEWLINE or both */ -/* - * This routine initializes the next line for drawing by setting - * its height to the current font height, scrolls the screen down - * one line, and updates the current drawing position to the - * left edge of the newly cleared line. If DODISP is specified, - * the screen will be updated (otherwise not). If NONEWLINE is - * specified, no newline character will be added to the text buffer - * (this is for line wrap). - */ -{ - struct txtLine *curLine, *nextLine; - - /* Check to see if a new line must be allocated */ - if (textInfo->curLine >= textInfo->allocLines-1) - /* Expand the number of lines */ - ExpandLines(textInfo); - textInfo->numLines += 1; - - /* Then we initialize the next line */ - nextLine = textInfo->txtBuffer[textInfo->numLines-1]; - nextLine->lineHeight = - textInfo->theFonts[textInfo->curFont].ascent + - textInfo->theFonts[textInfo->curFont].descent; - - curLine = textInfo->txtBuffer[textInfo->curLine]; - if (flagWord & DODISP) { - /* Scroll down a line if required */ - if ((textInfo->curY + curLine->lineHeight + - nextLine->lineHeight + (INTERLINE * 2)) > textInfo->h) - { - ScrollDown(display, textInfo); - } - else - { - /* Update the bottom space appropriately */ - textInfo->bottomSpace -= (nextLine->lineHeight + INTERLINE); - textInfo->endLine += 1; - } - /* Update drawing position */ - textInfo->curY = textInfo->h - - (textInfo->bottomSpace + nextLine->lineHeight); - } - - /* Move down a line */ - textInfo->curLine += 1; - if (!(flagWord & NONEWLINE)) { - /* Append end-of-line to text buffer */ - if (textInfo->bufSpot >= textInfo->bufAlloc) { - /* Allocate more space in main text buffer */ - ExpandBuffer(textInfo); - } - textInfo->mainBuffer[(textInfo->bufSpot)++] = - (textInfo->curFont << FONTSHIFT) | '\n'; - } - nextLine->lineText = textInfo->bufSpot; - textInfo->curX = 0; - return 1; -} - - - -static int CharSize(textInfo, lineNum, charNum) -struct txtWin *textInfo; /* Current Text Information */ -int lineNum; /* Line in buffer */ -int charNum; /* Character in line */ -/* - * This routine determines the size of the specified character. - * It takes in account the font of the character and whether its - * fixed or variable. The size includes INTERSPACE spacing between - * the characters. - */ -{ - register XFontStruct *charFont; - register short *theLine; - register short theChar; - - theLine = &(textInfo->mainBuffer[textInfo->txtBuffer[lineNum]->lineText]); - theChar = theLine[charNum] & CHARMASK; - charFont = &(textInfo->theFonts[(theChar & FONTMASK) >> FONTSHIFT]); - if (theChar <= charFont->min_char_or_byte2 || - theChar >= charFont->max_char_or_byte2 || - charFont->per_char == 0) - return charFont->max_bounds.width + 1; - else - return charFont->per_char[theChar].width + 1; -} - - - - - -static int HandleBackspace(display, textInfo, flagWord) -Display *display; -struct txtWin *textInfo; /* Text Information */ -int flagWord; /* DODISP or nothing */ -/* - * This routine handles a backspace found in the input stream. The - * character before the current writing position will be erased and - * the drawing position will move back one character. If the writing - * position is at the left margin, the drawing position will move - * up to the previous line. If it is a line that has been wrapped, - * the character at the end of the previous line will be erased. - */ -{ - struct txtLine *thisLine, *prevLine; - int chSize; - - thisLine = textInfo->txtBuffer[textInfo->curLine]; - /* First, determine whether we need to go back a line */ - if (thisLine->lineLength == 0) { - /* Bleep if at top of buffer */ - if (textInfo->curLine == 0) { - XBell(display, 50); - return 0; - } - - /* See if we have to scroll in the other direction */ - if ((flagWord & DODISP) && (textInfo->curY <= YPADDING)) { - /* This will display the last lines of the buffer */ - WarpToBottom(display, textInfo); - } - - /* Set drawing position at end of previous line */ - textInfo->curLine -= 1; - prevLine = textInfo->txtBuffer[textInfo->curLine]; - textInfo->numLines -= 1; - if (flagWord & DODISP) { - textInfo->curY -= (prevLine->lineHeight + INTERLINE); - textInfo->bottomSpace += (thisLine->lineHeight + INTERLINE); - textInfo->endLine -= 1; - } - - /* We are unlinewrapping if the previous line has flag set */ - if (prevLine->lineFlags & WRAPFLAG) { - /* Get rid of line wrap indicator */ - if (flagWord & DODISP) { - XFillRectangle(display, textInfo->mainWindow, - textInfo->bgGC, - textInfo->w - BARSIZE - WRAPINDSIZE, - textInfo->curY, WRAPINDSIZE, - prevLine->lineHeight); - } - prevLine->lineFlags &= (~WRAPFLAG); - /* Call recursively to wipe out the ending character */ - HandleBackspace(display, textInfo, flagWord); - } else { - /* Delete the end-of-line in the primary buffer */ - textInfo->bufSpot -= 1; - } - } else { - /* Normal deletion of character */ - chSize = - CharSize(textInfo, textInfo->curLine, - textInfo->txtBuffer[textInfo->curLine]->lineLength - 1); - /* Move back appropriate amount and wipe it out */ - thisLine->lineWidth -= chSize; - if (flagWord & DODISP) { - XFillRectangle(display, textInfo->mainWindow, - textInfo->bgGC, - thisLine->lineWidth, textInfo->curY, - chSize, thisLine->lineHeight); - } - /* Delete from buffer */ - textInfo->txtBuffer[textInfo->curLine]->lineLength -= 1; - textInfo->bufSpot -= 1; - } - return 1; -} - - - -static int DrawLineWrap(display, win, x, y, h, col) -Display *display; -Window win; /* What window to draw it in */ -int x, y; /* Position of upper left corner */ -int h; /* Height of indicator */ -int col; /* Color of indicator */ -/* - * This routine draws a line wrap indicator at the end of a line. - * Visually, it is an arrow of the specified height directly against - * the scroll bar border. The bitmap used for the arrow is stored - * in 'arrowMap' with size 'arrow_width' and 'arrow_height'. - */ -{ - struct txtWin *textInfo; - - textInfo = (struct txtWin *)XLookUpAssoc(display, textWindows, - (XID) win); - - /* First, draw the arrow */ -#ifdef __FreeBSD__ - XCopyArea(display, textInfo->arrowMap, textInfo->mainWindow, - textInfo->CursorGC, - 0, 0, arrow_width, arrow_height, - x, y + h - arrow_height); -#else - XCopyArea(display, textInfo->arrowMap, textInfo->mainWindow, - textInfo->CursorGC, - 0, 0, arrow_width, arrow_height, - x, y + h - arrow_height, 1); -#endif - - /* Then draw the stem */ - XDrawLine(display, textInfo->mainWindow, textInfo->CursorGC, - x + STEMOFFSET, y, - x + STEMOFFSET, y + h - arrow_height); - return 1; -} - - - - -static int DrawLine(display, textInfo, lineIndex, ypos) -Display *display; -struct txtWin *textInfo; /* Text window information */ -int lineIndex; /* Index of line to draw */ -int ypos; /* Y position for line */ -/* - * This routine destructively draws the indicated line in the - * indicated window at the indicated position. It does not - * clear to end of line however. It draws a line wrap indicator - * if needed but does not draw a cursor. - */ -{ - int index, startPos, curFont, theColor, curX, saveX, fontIndex; - struct txtLine *someLine; - char lineBuffer[BUFSIZE], *glyph; - short *linePointer; - XFontStruct *theFont; - XGCValues gc; - - /* First, we draw the text */ - index = 0; - curX = XPADDING; - someLine = textInfo->txtBuffer[lineIndex]; - linePointer = &(textInfo->mainBuffer[someLine->lineText]); - while (index < someLine->lineLength) { - startPos = index; - saveX = curX; - curFont = linePointer[index] & FONTMASK; - fontIndex = curFont >> FONTSHIFT; - theFont = &(textInfo->theFonts[fontIndex]); - theColor = textInfo->theColors[fontIndex]; - glyph = &(lineBuffer[0]); - while ((index < someLine->lineLength) && - ((linePointer[index] & FONTMASK) == curFont)) - { - *glyph = linePointer[index] & CHARMASK; - index++; - curX += CharSize(textInfo, lineIndex, index); - glyph++; - } - - /* Flush out the glyphs */ - XFillRectangle(display, textInfo->mainWindow, - textInfo->bgGC, - saveX, ypos, - textInfo->w - BARSIZE, - someLine->lineHeight + YPADDING + INTERLINE); - - XDrawString(display, textInfo->mainWindow, - textInfo->fontGC[fontIndex], - saveX, ypos, - lineBuffer, someLine->lineLength); - } - /* Then the line wrap indicator (if needed) */ - if (someLine->lineFlags & WRAPFLAG) { - DrawLineWrap(display, textInfo->mainWindow, - textInfo->w - BARSIZE - WRAPINDSIZE, - ypos, someLine->lineHeight, - textInfo->fgPix); - } - return 1; -} - - - - -static int HandleNewFont(display, fontNum, textInfo, flagWord) -Display *display; -int fontNum; /* Font number */ -struct txtWin *textInfo; /* Text information */ -int flagWord; /* DODISP or nothing */ -/* - * This routine handles a new font request. These requests take - * the form "^F". The parsing is done in TxtWriteStr. - * This routine is called only if the form is valid. It may return - * a failure (0 status) if the requested font is not loaded. - * If the new font is larger than any of the current - * fonts on the line, it will change the line height and redisplay - * the line. - */ -{ - struct txtLine *thisLine; - int heightDiff, baseDiff, redrawFlag; - - if (textInfo->theFonts[fontNum].fid == 0) { - return 0; - } else { - thisLine = textInfo->txtBuffer[textInfo->curLine]; - textInfo->curFont = fontNum; - redrawFlag = 0; - heightDiff = textInfo->theFonts[fontNum].ascent + - textInfo->theFonts[fontNum].descent - - thisLine->lineHeight; - - if (heightDiff > 0) { - redrawFlag = 1; - } else { - heightDiff = 0; - } - - if (redrawFlag) { - if (flagWord & DODISP) { - /* Clear current line */ - XFillRectangle(display, textInfo->mainWindow, - textInfo->bgGC, - 0, textInfo->curY, textInfo->w, - thisLine->lineHeight); - - /* Check to see if it requires scrolling */ - if ((textInfo->curY + thisLine->lineHeight + heightDiff + - INTERLINE) > textInfo->h) - { - /* - * General approach: "unscroll" the last line up - * and then call ScrollDown to do the right thing. - */ - textInfo->endLine -= 1; - textInfo->bottomSpace += thisLine->lineHeight + - INTERLINE; - - XFillRectangle(display, textInfo->mainWindow, - textInfo->bgGC, - 0, textInfo->h - textInfo->bottomSpace, - textInfo->w, textInfo->bottomSpace); - - thisLine->lineHeight += heightDiff; - ScrollDown(display, textInfo); - textInfo->curY = textInfo->h - - (textInfo->bottomSpace + INTERLINE + - thisLine->lineHeight); - } - else - { - /* Just update bottom space */ - textInfo->bottomSpace -= heightDiff; - thisLine->lineHeight += heightDiff; - } - /* Redraw the current line */ - DrawLine(display, textInfo, textInfo->curLine, textInfo->curY); - } else { - /* Just update line height */ - thisLine->lineHeight += heightDiff; - } - } - return 1; - } -} - - - -int TxtWriteStr(display, w, str) -Display *display; -Window w; /* Text window */ -register char *str; /* 0 terminated string */ -/* - * This routine writes a string to the specified text window. - * The following notes apply: - * - Text is always appended to the end of the text buffer. - * - If the scroll bar is positioned such that the end of the - * text is not visible, an automatic scroll to the bottom - * will be done before the appending of text. - * - Non-printable ASCII characters are not displayed. - * - The '\n' character causes the current text position to - * advance one line and start at the left. - * - Tabs are not supported. - * - Lines too long for the screen will be wrapped and a line wrap - * indication will be drawn. - * - Backspace clears the previous character. It will do the right - * thing if asked to backspace past a wrapped line. - * - A new font can be chosen using the sequence '^F' where - * is 0-7. The directive will be ignored if - * there is no font in the specified slot. - * Returns 0 if something went wrong. - */ -{ - register int fontIndex; - register struct txtWin *textInfo; - register struct txtLine *thisLine; - - if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0) - return 0; - - /* See if screen needs to be updated */ - if (textInfo->flagWord & SCREENWRONG) { - TxtRepaint(display, textInfo->mainWindow); - } - - /* See if we have to scroll down to the bottom */ - if (textInfo->flagWord & NOTATBOTTOM) { - WarpToBottom(display, textInfo); - textInfo->flagWord &= (~NOTATBOTTOM); - } - - /* Undraw the current cursor */ - thisLine = textInfo->txtBuffer[textInfo->curLine]; - - XFillRectangle(display, w, textInfo->bgGC, - thisLine->lineWidth + CUROFFSET, - textInfo->curY, - CURSORWIDTH, - thisLine->lineHeight); - - for ( /* str is ok */ ; (*str != 0) ; str++) { - /* Check to see if we are waiting on a font */ - if (textInfo->flagWord & FONTNUMWAIT) { - textInfo->flagWord &= (~FONTNUMWAIT); - fontIndex = *str - '0'; - if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) { - /* Handle font -- go get next character */ - if (HandleNewFont(display, fontIndex, textInfo, DODISP)) - continue; - } - } - - /* Inline code for handling normal character case */ - if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) { - register XFontStruct *thisFont; - register struct txtLine *thisLine; - register int charWidth; - int thisColor; - - /* Determine size of character */ - thisFont = &(textInfo->theFonts[textInfo->curFont]); - thisColor = textInfo->theColors[textInfo->curFont]; - if (*str <= thisFont->min_char_or_byte2 || - *str >= thisFont->max_char_or_byte2 || - thisFont->per_char == 0) - charWidth = thisFont->max_bounds.width + 1; - else - charWidth = thisFont->per_char[*str].width + 1; - - /* Check to see if line wrap is required */ - thisLine = textInfo->txtBuffer[textInfo->curLine]; - if (thisLine->lineWidth + charWidth > - (textInfo->w-BARSIZE-WRAPINDSIZE)) - { - DrawLineWrap(display, textInfo->mainWindow, - textInfo->w-BARSIZE-WRAPINDSIZE, - textInfo->curY, thisLine->lineHeight, - textInfo->fgPix); - thisLine->lineFlags |= WRAPFLAG; - /* Handle the spacing problem the same way as a newline */ - HandleNewLine(display, textInfo, DODISP | NONEWLINE); - thisLine = textInfo->txtBuffer[textInfo->curLine]; - } - - /* Ready to draw character */ - XDrawString(display, textInfo->mainWindow, - DEFAULT_GC, - textInfo->curX += charWidth, - textInfo->curY + thisLine->lineHeight, - str, 1); - - /* Append character onto main buffer */ - if (textInfo->bufSpot >= textInfo->bufAlloc) - /* Make room for more characters */ - ExpandBuffer(textInfo); - textInfo->mainBuffer[(textInfo->bufSpot)++] = - (textInfo->curFont << FONTSHIFT) | (*str); - - /* Update the line start array */ - thisLine->lineLength += 1; - thisLine->lineWidth += charWidth; - } else if (*str == NEWLINE) { - HandleNewLine(display, textInfo, DODISP); - } else if (*str == NEWFONT) { - /* Go into waiting for font number mode */ - textInfo->flagWord |= FONTNUMWAIT; - } else if (*str == BACKSPACE) { - HandleBackspace(display, textInfo, DODISP); - } else { - /* Ignore all others */ - } - } - /* Draw the cursor in its new position */ - thisLine = textInfo->txtBuffer[textInfo->curLine]; - - XFillRectangle(display, w, textInfo->CursorGC, - thisLine->lineWidth + CUROFFSET, - textInfo->curY /* + thisLine->lineHeight */, - CURSORWIDTH, thisLine->lineHeight); - - return 1; -} - - - -int TxtJamStr(display, w, str) -Display *display; -Window w; /* Text window */ -register char *str; /* NULL terminated string */ -/* - * This is the same as TxtWriteStr except the screen is NOT updated. - * After a call to this routine, TxtRepaint should be called to - * update the screen. This routine is meant to be used to load - * a text buffer with information and then allow the user to - * scroll through it at will. - */ -{ - register int fontIndex; - register struct txtWin *textInfo; - - if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w) - ) == 0) - return 0; - - for ( /* str is ok */ ; (*str != 0) ; str++) { - /* Check to see if we are waiting on a font */ - if (textInfo->flagWord & FONTNUMWAIT) { - textInfo->flagWord &= (~FONTNUMWAIT); - fontIndex = *str - '0'; - if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) { - if (HandleNewFont(display, fontIndex, textInfo, 0)) { - /* Handled font -- go get next character */ - continue; - } - } - } - /* Inline code for handling normal character case */ - if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) { - register XFontStruct *thisFont; - register struct txtLine *thisLine; - register int charWidth; - - /* Determine size of character */ - thisFont = &(textInfo->theFonts[textInfo->curFont]); - - if (*str <= thisFont->min_char_or_byte2 || - *str >= thisFont->max_char_or_byte2 || - thisFont->per_char == 0) - charWidth = thisFont->max_bounds.width + 1; - else - charWidth = thisFont->per_char[*str].width + 1; - - /* Check to see if line wrap is required */ - thisLine = textInfo->txtBuffer[textInfo->curLine]; - if (thisLine->lineWidth + charWidth > - (textInfo->w-BARSIZE-WRAPINDSIZE)) - { - thisLine->lineFlags |= WRAPFLAG; - /* Handle the spacing problem the same way as a newline */ - HandleNewLine(display, textInfo, NONEWLINE); - thisLine = textInfo->txtBuffer[textInfo->curLine]; - } - /* Append character onto main buffer */ - if (textInfo->bufSpot >= textInfo->bufAlloc) - /* Make room for more characters */ - ExpandBuffer(textInfo); - textInfo->mainBuffer[(textInfo->bufSpot)++] = - (textInfo->curFont << FONTSHIFT) | (*str); - - /* Update the line start array */ - thisLine->lineLength += 1; - thisLine->lineWidth += charWidth; - } else if (*str == NEWLINE) { - HandleNewLine(display, textInfo, 0); - } else if (*str == NEWFONT) { - /* Go into waiting for font number mode */ - textInfo->flagWord |= FONTNUMWAIT; - } else if (*str == BACKSPACE) { - HandleBackspace(display, textInfo, 0); - } else { - /* Ignore all others */ - } - } - textInfo->flagWord |= SCREENWRONG; - return 1; -} - - - -int TxtRepaint(display,w) -Display *display; -Window w; -/* - * Repaints the given scrollable text window. The routine repaints - * the entire window. For handling exposure events, the TxtFilter - * routine should be used. - */ -{ - struct txtWin *textInfo; - int index, ypos; - - if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w) - ) == 0) - return 0; - - /* Check to see if the screen is up to date */ - if (textInfo->flagWord & SCREENWRONG) { - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - textInfo->flagWord &= (~SCREENWRONG); - } - - ypos = YPADDING; - index = textInfo->startLine; - for (;;) { - DrawLine(display, textInfo, index, ypos); - if (index >= textInfo->endLine) break; - ypos += (textInfo->txtBuffer[index]->lineHeight + INTERLINE); - index++; - } - /* Draw the cursor (if on screen) */ - if (textInfo->endLine == textInfo->curLine) { - XFillRectangle(display, w, textInfo->CursorGC, - textInfo->txtBuffer[index]->lineWidth + CUROFFSET, - ypos /* + textInfo->txtBuffer[index]->lineHeight */, - CURSORWIDTH, textInfo->txtBuffer[index]->lineHeight); - - } - /* Update the scroll bar */ - UpdateScroll(display, textInfo); - return 1; -} - - - -static int InsertIndex(textInfo, thisIndex, ypos) -struct txtWin *textInfo; /* Text Window Information */ -int thisIndex; /* Line index of exposed line */ -int ypos; /* Drawing position of line */ -/* - * This routine inserts the supplied line index into the copy - * exposure array for 'textInfo'. The array is kept sorted - * from lowest to highest using insertion sort. The array - * is dynamically expanded if needed. - */ -{ - struct expEvent *newItem; - int newSize, index, downIndex; - - /* Check to see if we need to expand it */ - if ((textInfo->exposeSize + 3) >= textInfo->exposeAlloc) { - newSize = textInfo->exposeAlloc + - (textInfo->exposeAlloc * EXPANDPERCENT / 100); - textInfo->exposeAry = (struct expEvent **) - realloc((char *) textInfo->exposeAry, - (unsigned) (newSize * sizeof(struct expEvent *))); - for (index = textInfo->exposeAlloc; index < newSize; index++) - textInfo->exposeAry[index] = alloc(struct expEvent); - textInfo->exposeAlloc = newSize; - } - /* Find spot for insertion. NOTE: last spot has big number */ - for (index = 0; index <= textInfo->exposeSize; index++) { - if (textInfo->exposeAry[index]->lineIndex >= thisIndex) { - if (textInfo->exposeAry[index]->lineIndex > thisIndex) { - /* Insert before this entry */ - newItem = textInfo->exposeAry[textInfo->exposeSize+1]; - for (downIndex = textInfo->exposeSize; - downIndex >= index; - downIndex--) - { - textInfo->exposeAry[downIndex+1] = - textInfo->exposeAry[downIndex]; - } - /* Put a free structure at this spot */ - textInfo->exposeAry[index] = newItem; - /* Fill it in */ - textInfo->exposeAry[index]->lineIndex = thisIndex; - textInfo->exposeAry[index]->ypos = ypos; - /* Break out of loop */ - textInfo->exposeSize += 1; - } - break; - } - } - return 1; -} - - - -static int ScrollUp(display, textInfo) -Display *display; -struct txtWin *textInfo; /* Text window information */ -/* - * This routine scrolls the indicated text window up by one - * line. The line above the current line must exist. The - * window is scrolled so that the line above the start line - * is displayed at the top of the screen. This may cause - * many lines to scroll off the bottom. The scrolling is - * done using XCopyArea. The exposure events should be caught - * by ExposeCopy. - */ -{ - int targetSpace; - - /* Make sure all exposures have been handled by now */ - if (textInfo->startLine == 0) return 0; - targetSpace = textInfo->txtBuffer[textInfo->startLine-1]->lineHeight + - INTERLINE; - /* Move the area downward by the target amount */ - XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow, - DEFAULT_GC, - 0, YPADDING, textInfo->w - BARSIZE, - textInfo->h, 0, targetSpace); - - textInfo->flagWord |= COPYEXPOSE; - /* Update the text window parameters */ - textInfo->startLine -= 1; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - - /* Clear out bottom space region */ -#ifdef __FreeBSD__ - XClearArea(display, textInfo->mainWindow, - 0, textInfo->h - textInfo->bottomSpace, - textInfo->w, textInfo->bottomSpace, 1); -#else - XClearArea(display, textInfo->mainWindow, - 0, textInfo->h - textInfo->bottomSpace, - textInfo->w, textInfo->bottomSpace); -#endif - - UpdateExposures(display, textInfo); - UpdateScroll(display, textInfo); - - return 1; -} - - -static int ScrollToSpot(display, textInfo, ySpot) -Display *display; -struct txtWin *textInfo; /* Text window information */ -int ySpot; /* Button position in scroll window */ -/* - * This routine scrolls the specified text window relative to the - * position of the mouse in the scroll bar. The center of the screen - * will be positioned to correspond to the mouse position. - */ -{ - int targetLine, aboveLines; - - targetLine = textInfo->numLines * ySpot / textInfo->h; - textInfo->startLine = targetLine; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - aboveLines = 0; - /* Make the target line the *center* of the window */ - while ((textInfo->startLine > 0) && - (aboveLines < textInfo->endLine - targetLine)) - { - textInfo->startLine -= 1; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - aboveLines++; - } - if (textInfo->endLine == textInfo->numLines-1) { - WarpToBottom(display, textInfo); - } else { - XClearWindow(display, textInfo->mainWindow); - TxtRepaint(display, textInfo->mainWindow); - } - return 1; -} - - - -static int LineToTop(display, textInfo, pos) -Display *display; -struct txtWin *textInfo; /* Text window information */ -int pos; /* Y position of mouse */ -/* - * This routine scrolls the screen down until the line at the - * mouse position is at the top of the screen. It stops - * if it can't scroll the buffer down that far. If the - * global 'ScrollOption' is NORMSCROLL, a smooth scroll - * is used. Otherwise, it jumps to the right position - * and repaints the screen. - */ -{ - int index, sum; - - /* First, we find the current line */ - sum = 0; - for (index = textInfo->startLine; index <= textInfo->endLine; index++) { - if (sum + textInfo->txtBuffer[index]->lineHeight + INTERLINE> pos) break; - sum += textInfo->txtBuffer[index]->lineHeight + INTERLINE; - } - /* We always want to scroll down at least one line */ - if (index == textInfo->startLine) index++; - if (ScrollOption == NORMSCROLL) { - /* Scroll down until 'index' is the starting line */ - while ((textInfo->startLine < index) && ScrollDown(display, textInfo)) - { - /* Empty Loop Body */ - } - } else { - /* Immediately jump to correct spot */ - textInfo->startLine = index; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - if (textInfo->endLine == textInfo->numLines-1) { - WarpToBottom(display, textInfo); - } else { - XClearWindow(display, textInfo->mainWindow); - TxtRepaint(display, textInfo->mainWindow); - } - } - /* Check to see if at end of buffer */ - if (textInfo->endLine >= textInfo->numLines-1) { - textInfo->flagWord &= (~NOTATBOTTOM); - } - return 1; -} - - - -static int TopToHere(display, textInfo, pos) -Display *display; -struct txtWin *textInfo; /* Text window information */ -int pos; /* Y position of mouse */ -/* - * This routine scrolls the screen up until the top line of - * the screen is at the current Y position of the mouse. Again, - * it will stop if it can't scroll that far. If the global - * 'ScrollOption' is NORMSCROLL, a smooth scroll is used. - * If it's not, it will simply redraw the screen at the - * correct spot. - */ -{ - int sum, target, linesup, index; - - target = pos - textInfo->txtBuffer[textInfo->startLine]->lineHeight; - /* We always want to scroll up at least one line */ - if (target <= 0) target = 1; - sum = 0; - linesup = 0; - /* Check to see if we are at the top anyway */ - if (textInfo->startLine == 0) return 0; - if (ScrollOption == NORMSCROLL) { - /* Scroll up until sum of new top lines greater than target */ - while ((sum < target) && ScrollUp(display, textInfo)) { - sum += textInfo->txtBuffer[textInfo->startLine]->lineHeight; - linesup++; - } - } else { - /* Search backward to find index */ - index = textInfo->startLine - 1; - while ((index > 0) && (sum < target)) { - sum += textInfo->txtBuffer[index]->lineHeight; - linesup++; - index--; - } - /* Go directly to the index */ - textInfo->startLine = index; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - XClearWindow(display, textInfo->mainWindow); - TxtRepaint(display, textInfo->mainWindow); - } - /* If we scrolled, assert we are not at bottom of buffer */ - if (linesup > 0) { - textInfo->flagWord |= NOTATBOTTOM; - } - return 1; -} - - - -int TxtFilter(display, evt) -Display *display; -XEvent *evt; -/* - * This routine handles events associated with scrollable text windows. - * It will handle all exposure events and any button released events - * in the scroll bar of a text window. It does NOT handle any other - * events. If it cannot handle the event, it will return 0. - */ -{ - XExposeEvent *expose = &evt->xexpose; - XButtonEvent *btEvt = &evt->xbutton; - XGraphicsExposeEvent *gexpose = &evt->xgraphicsexpose; - XNoExposeEvent *noexpose = &evt->xnoexpose; - struct txtWin *textInfo; - int index, ypos; - Window w, sw; - - if (textWindows == (XAssocTable *) 0) { - textWindows = XCreateAssocTable(32); - if (textWindows == (XAssocTable *) 0) return(0); - } - if (evt->type == Expose) { - w = expose->window; - sw = 0; - } - else if (evt->type == GraphicsExpose) { - w = gexpose->drawable; - sw = 0; - } - else if (evt->type == NoExpose) { - w = noexpose->drawable; - sw = 0; - } - else if (evt->type == ButtonRelease) { - w = btEvt->window; - sw = btEvt->subwindow; - } - else - return 0; - - if ((textInfo = (struct txtWin *) - XLookUpAssoc(display, textWindows, (XID) w)) == 0) - return 0; - - /* Determine whether it's main window or not */ - if ((w == textInfo->mainWindow) && (sw == 0)) { - /* Main Window - handle exposures */ - switch (evt->type) { - case Expose: - ypos = 0 /*YPADDING*/; - for (index = textInfo->startLine; - index <= textInfo->endLine; - index++) - { - int lh = textInfo->txtBuffer[index]->lineHeight; - - if (((ypos + lh) >= expose->y) && - (ypos <= (expose->y + expose->height))) - { - /* Intersection region */ - /* Draw line immediately */ - DrawLine(display, textInfo, index, ypos); - /* And possibly draw cursor */ - if (textInfo->curLine == index) { - XFillRectangle(display, w, textInfo->CursorGC, - textInfo->txtBuffer[index]->lineWidth + - CUROFFSET, - ypos, - CURSORWIDTH, - lh); - } - } - ypos += lh + INTERLINE; - } - break; - case GraphicsExpose: - ypos = 0 /*YPADDING*/; - for (index = textInfo->startLine; - index <= textInfo->endLine; - index++) - { - int lh = textInfo->txtBuffer[index]->lineHeight; - - if (((ypos + lh) >= gexpose->y) && - (ypos <= (gexpose->y + gexpose->height))) - { - /* Intersection region */ - /* Draw line immediately */ - DrawLine(display, textInfo, index, ypos); - /* And possibly draw cursor */ - if (textInfo->curLine == index) { - XFillRectangle(display, w, textInfo->CursorGC, - textInfo->txtBuffer[index]->lineWidth + - CUROFFSET, - ypos, - CURSORWIDTH, - lh); - } - } - ypos += lh + INTERLINE; - } - break; - case NoExpose: - break; - default: - /* Not one of our events */ - return 0; - } - } else { - switch (evt->type) { - case Expose: - UpdateScroll(display, textInfo); - break; - case ButtonRelease: - /* Find out which button */ - switch (btEvt->button) { - case Button1: - /* Scroll up until top line is at mouse position */ - TopToHere(display, textInfo, btEvt->y); - break; - case Button2: - /* Scroll to spot relative to position */ - ScrollToSpot(display, textInfo, btEvt->y); - if (textInfo->endLine >= textInfo->numLines-1) { - textInfo->flagWord &= (~NOTATBOTTOM); - } else { - textInfo->flagWord |= NOTATBOTTOM; - } - break; - case Button3: - /* Scroll down until pointed line is at top */ - LineToTop(display, textInfo, btEvt->y); - break; - } - break; - default: - /* Not one of our events */ - return 0; - } - } - return 1; -} diff --git a/gnu/games/chess/Xchess/scrollText/scrollText.c b/gnu/games/chess/Xchess/scrollText/scrollText.c deleted file mode 100644 index aefb599..0000000 --- a/gnu/games/chess/Xchess/scrollText/scrollText.c +++ /dev/null @@ -1,1858 +0,0 @@ -/* - * A Scrollable Text Output Window - * - * David Harrison - * University of California, Berkeley - * 1986 - * - * The following is an implementation for a scrollable text output - * system. It handles exposure events only (other interactions are - * under user control). For scrolling, a always present scroll bar - * is implemented. It detects size changes and compensates accordingly. - */ - -#include -#include -#include -#include -#include "scrollText.h" - -extern char *malloc(); -extern char *realloc(); -#define alloc(type) (type *) malloc(sizeof(type)) -#define numalloc(type, num) (type *) malloc((unsigned) (num * sizeof(type))) -#define MAXINT 2147483647 - -extern XAssocTable *XCreateAssocTable(); -extern caddr_t XLookUpAssoc(); - -static XAssocTable *textWindows = (XAssocTable *) 0; - -#define NOOPTION -1 /* Option hasn't been set yet */ -#define NORMSCROLL 0 /* Smooth scroll on LineToTop and TopToHere */ -#define JUMPSCROLL 1 /* Jump scrolling on LineToTop and TopToHere */ - -static int ScrollOption = NOOPTION; - -typedef char *Generic; - -#define DEFAULT_GC textInfo->fontGC[textInfo->curFont] - -#define BARSIZE 15 -#define BARBORDER 1 -#define MAXFONTS 8 -#define INITBUFSIZE 1024 -#define INITLINES 50 -#define INITEXPARY 50 -#define XPADDING 2 -#define YPADDING 2 -#define INTERLINE 5 -#define INTERSPACE 1 -#define CURSORWIDTH 2 -#define EXPANDPERCENT 40 -#define BUFSIZE 1024 -#define CUROFFSET 1 -#define MAXFOREIGN 250 -#define NOINDEX -1 - -/* The wrap line indicator */ -#define WRAPINDSIZE 7 -#define STEMOFFSET 5 -#define arrow_width 7 -#define arrow_height 5 -static char arrow_bits[] = { - 0x24, 0x26, 0x3f, 0x06, 0x04}; - -#define NEWLINE '\n' -#define BACKSPACE '\010' -#define NEWFONT '\006' -#define LOWCHAR '\040' -#define HIGHCHAR '\176' - -#define CHARMASK 0x00ff /* Character mask */ -#define FONTMASK 0x0700 /* Character font */ -#define FONTSHIFT 8 /* Shift amount */ - -#define WRAPFLAG 0x01 /* Line wrap flag */ - -/* - * Lines are represented by a pointer into the overall array of - * 16-bit characters. The lower eight bits is used to indicate the character - * (in ASCII), and the next two bits are used to indicate the font - * the character should be drawn in. - */ - -typedef struct txtLine { - int lineLength; /* Current line length */ - int lineHeight; /* Full height of line in pixels */ - int lineBaseLine; /* Current baseline of the line */ - int lineWidth; /* Drawing position at end of line */ - int lineText; /* Offset into master buffer */ - int lineFlags; /* Line wrap flag is here */ -}; - - -/* - * For ExposeCopy events, we queue up the redraw requests collapsing - * them into line redraw requests until the CopyExpose event arrives. - * The queue is represented as a dynamic array of the following - * structure: - */ - -typedef struct expEvent { - int lineIndex; /* Index of line to redraw */ - int ypos; /* Drawing position of line */ -}; - - -/* - * The text buffer is represented using a dynamic counted array - * of 16-bit quantities. This array expands as needed. - * For the screen representation, a dynamic counted array - * of line structures is used. This array points into the - * text buffer to denote the start of each line and its parameters. - * The windows are configured as one overall window which contains - * the scroll bar as a sub-window along its right edge. Thus, - * the text drawing space is actually w-BARSIZE. - */ - -#define NOTATBOTTOM 0x01 /* Need to scroll to bottom before appending */ -#define FONTNUMWAIT 0x02 /* Waiting for font number */ -#define COPYEXPOSE 0x04 /* Need to process a copy expose event */ -#define SCREENWRONG 0x08 /* TxtJamStr has invalidated screen contents */ - -typedef struct txtWin { - /* Basic text buffer */ - int bufAlloc; /* Allocated size of buffer */ - int bufSpot; /* Current writing position in buffer */ - short *mainBuffer; /* Main buffer of text */ - - /* Line information */ - int numLines; /* Number of display lines in buffer */ - int allocLines; /* Number of lines allocated */ - struct txtLine **txtBuffer; /* Dynamic array of lines */ - - /* Current Window display information */ - Window mainWindow; /* Text display window */ - Window scrollBar; /* Subwindow for scroll bar */ - Pixmap arrowMap; /* line wrap indicator */ - int bgPix, fgPix; /* Background and cursor */ - GC CursorGC; /* gc for the cursor */ - GC bgGC; /* gc for erasing things */ - GC fontGC[MAXFONTS]; /* gc for doing fonts */ - XFontStruct theFonts[MAXFONTS];/* Display fonts */ - int theColors[MAXFONTS]; /* foregrounds of the fonts */ - int curFont; /* current font for tracking */ - int w, h; /* Current size */ - int startLine; /* Top line in display */ - int endLine; /* Bottom line in display */ - int bottomSpace; /* Space at bottom of screen */ - int flagWord; /* If non-zero, not at end */ - - /* For handling ExposeCopy events */ - int exposeSize; /* Current size of array */ - int exposeAlloc; /* Allocated size */ - struct expEvent **exposeAry;/* Array of line indices */ - - /* Drawing position information */ - int curLine; /* Current line in buffer */ - int curX; /* Current horizontal positi */ - int curY; /* Current vertical drawing */ -}; - -/* Flags for the various basic character handling functions */ - -#define DODISP 0x01 /* Update the display */ -#define NONEWLINE 0x02 /* Dont append newline */ - - - -static int InitLine(newLine) -struct txtLine *newLine; /* Newly created line structure */ -/* - * This routine initializes a newly created line structure. - */ -{ - newLine->lineLength = 0; - newLine->lineHeight = 0; - newLine->lineBaseLine = 0; - newLine->lineWidth = XPADDING; - newLine->lineText = NOINDEX; - newLine->lineFlags = 0; - return 1; -} - - - - -int TxtGrab(display, txtWin, program, mainFont, bg, fg, cur) -Display *display; /* display window is on */ -Window txtWin; /* Window to take over as scrollable text */ -char *program; /* Program name for Xdefaults */ -XFontStruct *mainFont; /* Primary text font */ -int bg, fg, cur; /* Background, foreground, and cursor colors */ -/* - * This routine takes control of 'txtWin' and makes it into a scrollable - * text output window. It will create a sub-window for the scroll bar - * with a background of 'bg' and an bar with color 'fg'. Both fixed width - * and variable width fonts are supported. Additional fonts can be loaded - * using 'TxtAddFont'. Returns 0 if there were problems, non-zero if - * everything went ok. - */ -{ - struct txtWin *newWin; /* Text package specific information */ - XWindowAttributes winInfo; /* Window information */ - int index; - XGCValues gc_val; - - if (textWindows == (XAssocTable *) 0) { - textWindows = XCreateAssocTable(32); - if (textWindows == (XAssocTable *) 0) return(0); - } - if (XGetWindowAttributes(display, txtWin, &winInfo) == 0) return 0; - - if (ScrollOption == NOOPTION) { - /* Read to see if the user wants jump scrolling or not */ - if (XGetDefault(display, program, "JumpScroll")) { - ScrollOption = JUMPSCROLL; - } else { - ScrollOption = NORMSCROLL; - } - } - - /* Initialize local structure */ - newWin = alloc(struct txtWin); - - /* Initialize arrow pixmap */ - newWin->arrowMap = XCreatePixmapFromBitmapData(display, txtWin, - arrow_bits, - arrow_width, arrow_height, - cur, bg, - DisplayPlanes(display, 0)); - - newWin->bufAlloc = INITBUFSIZE; - newWin->bufSpot = 0; - newWin->mainBuffer = numalloc(short, INITBUFSIZE); - - newWin->numLines = 1; - newWin->allocLines = INITLINES; - newWin->txtBuffer = numalloc(struct txtLine *, INITLINES); - for (index = 0; index < INITLINES; index++) { - newWin->txtBuffer[index] = alloc(struct txtLine); - InitLine(newWin->txtBuffer[index]); - } - - /* Window display information */ - newWin->mainWindow = txtWin; - newWin->w = winInfo.width; - newWin->h = winInfo.height; - newWin->startLine = 0; - newWin->endLine = 0; - newWin->bottomSpace = winInfo.height - - YPADDING - mainFont->ascent - mainFont->descent - INTERLINE; - newWin->flagWord = 0; - newWin->bgPix = bg; - newWin->fgPix = fg; - - /* Scroll Bar Creation */ - newWin->scrollBar = XCreateSimpleWindow(display, txtWin, - winInfo.width - BARSIZE, - 0, BARSIZE - (2*BARBORDER), - winInfo.height - (2*BARBORDER), - BARBORDER, - fg, bg); - XSelectInput(display, newWin->scrollBar, ExposureMask|ButtonReleaseMask); - XMapRaised(display, newWin->scrollBar); - - /* Font and Color Initialization */ - newWin->theFonts[0] = *mainFont; - newWin->theColors[0] = fg; - gc_val.function = GXcopy; - gc_val.plane_mask = AllPlanes; - gc_val.foreground = fg; - gc_val.background = bg; - gc_val.graphics_exposures = 1; - gc_val.font = mainFont->fid; - gc_val.line_width = 1; - gc_val.line_style = LineSolid; - - newWin->fontGC[0] = XCreateGC(display, txtWin, - GCFunction | GCPlaneMask | - GCForeground | GCBackground | - GCGraphicsExposures | GCFont, - &gc_val); - - gc_val.foreground = cur; - newWin->CursorGC = XCreateGC(display, txtWin, - GCFunction | GCPlaneMask | - GCForeground | GCBackground | - GCLineStyle | GCLineWidth, - &gc_val); - - gc_val.foreground = bg; - newWin->bgGC = XCreateGC(display, txtWin, - GCFunction | GCPlaneMask | - GCForeground | GCBackground | - GCGraphicsExposures | GCFont, - &gc_val); - - - for (index = 1; index < MAXFONTS; index++) { - newWin->theFonts[index].fid = 0; - newWin->fontGC[index] = 0; - } - - - /* Initialize size of first line */ - newWin->txtBuffer[0]->lineHeight = newWin->theFonts[0].ascent + - newWin->theFonts[0].descent; - newWin->txtBuffer[0]->lineText = 0; - - /* ExposeCopy array initialization */ - newWin->exposeSize = 0; - newWin->exposeAlloc = INITEXPARY; - newWin->exposeAry = numalloc(struct expEvent *, INITEXPARY); - for (index = 0; index < newWin->exposeAlloc; index++) - newWin->exposeAry[index] = alloc(struct expEvent); - /* Put plus infinity in last slot for sorting purposes */ - newWin->exposeAry[0]->lineIndex = MAXINT; - - /* Drawing Position Information */ - newWin->curLine = 0; - newWin->curX = 0; - newWin->curY = YPADDING + mainFont->ascent + mainFont->descent; - - /* Attach it to both windows */ - XMakeAssoc(display, textWindows, (XID) txtWin, (caddr_t) newWin); - XMakeAssoc(display, textWindows, (XID) newWin->scrollBar, (caddr_t) newWin); - return 1; -} - - -int TxtRelease(display, w) -Display *display; -Window w; /* Window to release */ -/* - * This routine releases all resources associated with the - * specified window which are consumed by the text - * window package. This includes the entire text buffer, line start - * array, and the scroll bar window. However, the window - * itself is NOT destroyed. The routine will return zero if - * the window is not owned by the text window package. - */ -{ - struct txtWin *textInfo; - int index; - - if ((textInfo = (struct txtWin *) XLookUpAssoc(display, - textWindows, (XID) w)) == 0) - return 0; - - for (index = 0; index < MAXFONTS; index++) - if (textInfo->fontGC[index] != 0) - XFreeGC(display, textInfo->fontGC[index]); - - free((Generic) textInfo->mainBuffer); - for (index = 0; index < textInfo->numLines; index++) { - free((Generic) textInfo->txtBuffer[index]); - } - free((Generic) textInfo->txtBuffer); - XDestroyWindow(display, textInfo->scrollBar); - for (index = 0; index < textInfo->exposeSize; index++) { - free((Generic) textInfo->exposeAry[index]); - } - free((Generic) textInfo->exposeAry); - XDeleteAssoc(display, textWindows, (XID) w); - free((Generic) textInfo); - return 1; -} - - - -static int RecompBuffer(textInfo) -struct txtWin *textInfo; /* Text window information */ -/* - * This routine recomputes all line breaks in a buffer after - * a change in window size or font. This is done by throwing - * away the old line start array and recomputing it. Although - * a lot of this work is also done elsewhere, it has been included - * inline here for efficiency. - */ -{ - int startPos, endSize, linenum; - register int index, chsize, curfont; - register short *bufptr; - register XFontStruct *fontptr; - register struct txtLine *lineptr; - char theChar; - - /* Record the old position so we can come back to it */ - for (startPos = textInfo->txtBuffer[textInfo->startLine]->lineText; - (startPos > 0) && (textInfo->mainBuffer[startPos] != '\n'); - startPos--) - /* null loop body */; - - /* Clear out the old line start array */ - for (index = 0; index < textInfo->numLines; index++) { - InitLine(textInfo->txtBuffer[index]); - } - - /* Initialize first line */ - textInfo->txtBuffer[0]->lineHeight = - textInfo->theFonts[0].ascent + textInfo->theFonts[0].descent; - textInfo->txtBuffer[0]->lineText = 0; - - /* Process the text back into lines */ - endSize = textInfo->w - BARSIZE - WRAPINDSIZE; - bufptr = textInfo->mainBuffer; - lineptr = textInfo->txtBuffer[0]; - linenum = 0; - fontptr = &(textInfo->theFonts[0]); - curfont = 0; - for (index = 0; index < textInfo->bufSpot; index++) { - theChar = bufptr[index] & CHARMASK; - - if ((bufptr[index] & FONTMASK) != curfont) { - int newFontNum, heightDiff; - - /* Switch fonts */ - newFontNum = (bufptr[index] & FONTMASK) >> FONTSHIFT; - if (textInfo->theFonts[newFontNum].fid != 0) { - /* Valid font */ - curfont = bufptr[index] & FONTMASK; - fontptr = &(textInfo->theFonts[newFontNum]); - heightDiff = (fontptr->ascent + fontptr->descent) - - lineptr->lineHeight; - if (heightDiff < 0) heightDiff = 0; - lineptr->lineHeight += heightDiff; - } - } - if (theChar == '\n') { - /* Handle new line */ - if (linenum >= textInfo->allocLines-1) - /* Expand number of lines */ - ExpandLines(textInfo); - linenum++; - lineptr = textInfo->txtBuffer[linenum]; - /* Initialize next line */ - lineptr->lineHeight = fontptr->ascent + fontptr->descent; - lineptr->lineText = index+1; - /* Check to see if its the starting line */ - if (index == startPos) textInfo->startLine = linenum; - } else { - /* Handle normal character */ - chsize = CharSize(textInfo, linenum, index); - if (lineptr->lineWidth + chsize > endSize) { - /* Handle line wrap */ - lineptr->lineFlags |= WRAPFLAG; - if (linenum >= textInfo->allocLines-1) - /* Expand number of lines */ - ExpandLines(textInfo); - linenum++; - lineptr = textInfo->txtBuffer[linenum]; - /* Initialize next line */ - lineptr->lineHeight = fontptr->ascent + fontptr->descent; - lineptr->lineText = index; - lineptr->lineLength = 1; - lineptr->lineWidth += chsize; - } else { - /* Handle normal addition of character */ - lineptr->lineLength += 1; - lineptr->lineWidth += chsize; - } - } - } - /* We now have a valid line array. Let's clean up some other fields. */ - textInfo->numLines = linenum+1; - if (startPos == 0) { - textInfo->startLine = 0; - } - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - textInfo->curLine = linenum; - /* Check to see if we are at the bottom */ - if (textInfo->endLine >= textInfo->numLines-1) { - textInfo->curY = textInfo->h - textInfo->bottomSpace - - lineptr->lineHeight; - textInfo->flagWord &= (~NOTATBOTTOM); - } else { - textInfo->flagWord |= NOTATBOTTOM; - } - return 1; -} - - - - -int TxtAddFont(display, textWin, fontNumber, newFont, newColor) -Display *display; -Window textWin; /* Scrollable text window */ -int fontNumber; /* Place to add font (0-7) */ -XFontStruct *newFont; /* Font to add */ -int newColor; /* Color of font */ -/* - * This routine loads a new font so that it can be used in a previously - * created text window. There are eight font slots numbered 0 through 7. - * If there is already a font in the specified slot, it will be replaced - * and an automatic redraw of the window will take place. See TxtWriteStr - * for details on using alternate fonts. The color specifies the foreground - * color of the text. The default foreground color is used if this - * parameter is TXT_NO_COLOR. Returns a non-zero value if - * everything went well. - */ -{ - struct txtWin *textInfo; - int redrawFlag; - XGCValues gc_val; - - if ((fontNumber < 0) || (fontNumber >= MAXFONTS)) return 0; - if ((textInfo = (struct txtWin *) - XLookUpAssoc(display, textWindows, (XID) textWin)) == 0) - return 0; - if (newColor == TXT_NO_COLOR) { - newColor = textInfo->fgPix; - } - - gc_val.font = newFont->fid; - gc_val.foreground = newColor; - gc_val.background = textInfo->bgPix; - gc_val.plane_mask = AllPlanes; - gc_val.graphics_exposures = 1; - gc_val.function = GXcopy; - - if (textInfo->fontGC[fontNumber] != 0) - { - XChangeGC(display, textInfo->fontGC[fontNumber], - GCFont | GCForeground, &gc_val); - } - else - textInfo->fontGC[fontNumber] = XCreateGC(display, textWin, - GCFont | - GCForeground | - GCBackground | - GCFunction | - GCPlaneMask | - GCGraphicsExposures, - &gc_val); - - - redrawFlag = (textInfo->theFonts[fontNumber].fid != 0) && - (((newFont) && (newFont->fid != textInfo->theFonts[fontNumber].fid)) || - (newColor != textInfo->theColors[fontNumber])); - if (newFont) { - textInfo->theFonts[fontNumber] = *newFont; - } - textInfo->theColors[fontNumber] = newColor; - - if (redrawFlag) { - RecompBuffer(textInfo); - XClearWindow(display, textWin); - TxtRepaint(display, textWin); - } - return 1; -} - - - -int TxtWinP(display, w) -Display *display; -Window w; -/* - * Returns a non-zero value if the window has been previously grabbed - * using TxtGrab and 0 if it has not. - */ -{ - if (XLookUpAssoc(display, textWindows, (XID) w)) - return(1); - else return(0); -} - - - -static int FindEndLine(textInfo, botSpace) -struct txtWin *textInfo; -int *botSpace; -/* - * Given the starting line in 'textInfo->startLine', this routine - * determines the index of the last line that can be drawn given the - * current size of the screen. If there are not enough lines to - * fill the screen, the index of the last line will be returned. - * The amount of empty bottom space is returned in 'botSpace'. - */ -{ - int index, height, lineHeight; - - height = YPADDING; - index = textInfo->startLine; - while (index < textInfo->numLines) { - lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE; - if (height + lineHeight > textInfo->h) break; - height += lineHeight; - index++; - } - if (botSpace) { - *botSpace = textInfo->h - height; - } - return index - 1; -} - - - -static int UpdateScroll(display, textInfo) -Display *display; -struct txtWin *textInfo; /* Text window information */ -/* - * This routine computes the current extent of the scroll bar - * indicator and repaints the bar with the correct information. - */ -{ - int top, bottom; - - if (textInfo->numLines > 1) { - top = textInfo->startLine * (textInfo->h - 2*BARBORDER) / - (textInfo->numLines - 1); - bottom = textInfo->endLine * (textInfo->h - 2*BARBORDER) / - (textInfo->numLines - 1); - } else { - top = 0; - bottom = textInfo->h - (2*BARBORDER); - } - - /* Draw it - make sure there is a little padding */ - if (top == 0) top++; - if (bottom == textInfo->h-(2*BARBORDER)) bottom--; - - XFillRectangle(display, textInfo->scrollBar, - textInfo->bgGC, - 0, 0, BARSIZE, top-1); - XFillRectangle(display, textInfo->scrollBar, - DEFAULT_GC, top, BARSIZE - (2*BARBORDER) - 2, - bottom - top); - XFillRectangle(display, textInfo->scrollBar, DEFAULT_GC, - 0, bottom+1, BARSIZE, - textInfo->h - (2 * BARBORDER) - bottom); - - return 1; -} - - - - -int TxtClear(display, w) -Display *display; -Window w; -/* - * This routine clears a scrollable text window. It resets the current - * writing position to the upper left hand corner of the screen. - * NOTE: THIS ALSO CLEARS THE CONTENTS OF THE TEXT WINDOW BUFFER AND - * RESETS THE SCROLL BAR. Returns 0 if the window is not a text window. - * This should be used *instead* of XClear. - */ -{ - struct txtWin *textInfo; - int index; - - if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0) - return 0; - - /* Zero out the arrays */ - textInfo->bufSpot = 0; - for (index = 0; index < textInfo->numLines; index++) { - InitLine(textInfo->txtBuffer[index]); - } - textInfo->txtBuffer[0]->lineHeight = - textInfo->theFonts[textInfo->curFont].ascent + - textInfo->theFonts[textInfo->curFont].descent; - - textInfo->numLines = 1; - textInfo->startLine = 0; - textInfo->endLine = 0; - textInfo->curLine = 0; - textInfo->curX = 0; - textInfo->curY = YPADDING + textInfo->theFonts[textInfo->curFont].ascent - + textInfo->theFonts[textInfo->curFont].descent; - - textInfo->bottomSpace = textInfo->h - YPADDING - - textInfo->theFonts[textInfo->curFont].ascent - INTERLINE - - textInfo->theFonts[textInfo->curFont].descent; - /* Actually clear the window */ - XClearWindow(display, w); - - /* Draw the current cursor */ - XFillRectangle(display, w, textInfo->CursorGC, - XPADDING + CUROFFSET, textInfo->curY, - CURSORWIDTH, - textInfo->theFonts[textInfo->curFont].ascent + - textInfo->theFonts[textInfo->curFont].descent); - - /* Update the scroll bar */ - UpdateScroll(display, textInfo); - return 1; -} - - -static int WarpToBottom(display, textInfo) -Display *display; -struct txtWin *textInfo; /* Text Information */ -/* - * This routine causes the specified text window to display its - * last screen of information. It updates the scroll bar - * to the appropriate spot. The implementation scans backward - * through the buffer to find an appropriate starting spot for - * the window. - */ -{ - int index, height, lineHeight; - - index = textInfo->numLines-1; - height = 0; - while (index >= 0) { - lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE; - if (height + lineHeight > textInfo->h) break; - height += lineHeight; - index--; - } - textInfo->startLine = index + 1; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - textInfo->curY = textInfo->h - textInfo->bottomSpace - - textInfo->txtBuffer[textInfo->endLine]->lineHeight; - XClearWindow(display, textInfo->mainWindow); - TxtRepaint(display, textInfo->mainWindow); - return 1; -} - - - -static int UpdateExposures(display, textInfo) -Display *display; -struct txtWin *textInfo; /* Text window information */ -/* - * Before a new scrolling action occurs, the text window package - * must handle all COPYEXPOSE events generated by the last scrolling - * action. This routine is called to do this. Foreign events (those - * not handled by TxtFilter) are queued up and replaced on the queue - * after the processing of the exposure events is complete. - */ -{ -#if 0 - XEvent foreignQueue[MAXFOREIGN]; - int index, lastItem = 0; - - while (textInfo->flagWord & COPYEXPOSE) { - XNextEvent(display, &(foreignQueue[lastItem])); - if (!TxtFilter(display, &(foreignQueue[lastItem]))) - lastItem++; - if (lastItem >= MAXFOREIGN) { - printf("Too many foreign events to queue!\n"); - textInfo->flagWord &= (~COPYEXPOSE); - } - } - for (index = 0; index < lastItem; index++) { - XPutBackEvent(display, &(foreignQueue[index])); - } -#endif - return 1; -} - - -static int ScrollDown(display,textInfo) -Display *display; -struct txtWin *textInfo; /* Text window information */ -/* - * This routine scrolls the indicated text window down by one - * line. The line below the current line must exist. The window - * is scrolled so that the line below the last line is fully - * displayed. This may cause many lines to scroll off the top. - * Scrolling is done using XCopyArea. The exposure events should - * be caught using ExposeCopy. - */ -{ - int lineSum, index, targetSpace, freeSpace, updateFlag; - - lineSum = 0; - if (textInfo->endLine + 1 >= textInfo->numLines) return 0; - targetSpace = textInfo->txtBuffer[textInfo->endLine+1]->lineHeight + - INTERLINE; - if (textInfo->bottomSpace < targetSpace) { - index = textInfo->startLine; - while (index < textInfo->endLine) { - lineSum += (textInfo->txtBuffer[index]->lineHeight + INTERLINE); - if (textInfo->bottomSpace + lineSum >= targetSpace) break; - index++; - } - - /* Must move upward by 'lineSum' pixels */ - XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow, - DEFAULT_GC, 0, lineSum, - textInfo->w - BARSIZE, textInfo->h, - 0, 0); - - textInfo->flagWord |= COPYEXPOSE; - /* Repair the damage to the structures */ - textInfo->startLine = index + 1; - updateFlag = 1; - } else { - updateFlag = 0; - } - /* More lines might be able to fit. Let's check. */ - freeSpace = textInfo->bottomSpace + lineSum - targetSpace; - index = textInfo->endLine + 1; - while (index < textInfo->numLines-1) { - if (freeSpace - textInfo->txtBuffer[index+1]->lineHeight - INTERLINE < 0) - break; - freeSpace -= (textInfo->txtBuffer[index+1]->lineHeight + INTERLINE); - index++; - } - textInfo->endLine = index; - textInfo->bottomSpace = freeSpace; - if (updateFlag) { - UpdateExposures(display, textInfo); - } - UpdateScroll(display, textInfo); - return 1; -} - - - - -static int ExpandLines(textInfo) -struct txtWin *textInfo; /* Text Information */ -/* - * This routine allocates and initializes additional space in - * the line start array (txtBuffer). The new space - * is allocated using realloc. The expansion factor is a percentage - * given by EXPANDPERCENT. - */ -{ - int newSize, index; - - newSize = textInfo->allocLines; - newSize += (newSize * EXPANDPERCENT) / 100; - - textInfo->txtBuffer = (struct txtLine **) - realloc((char *) textInfo->txtBuffer, - (unsigned) (newSize * sizeof(struct txtLine *))); - for (index = textInfo->allocLines; index < newSize; index++) { - textInfo->txtBuffer[index] = alloc(struct txtLine); - InitLine(textInfo->txtBuffer[index]); - } - textInfo->allocLines = newSize; - return 1; -} - -static int ExpandBuffer(textInfo) -struct txtWin *textInfo; /* Text information */ -/* - * Expands the basic character buffer using realloc. The expansion - * factor is a percentage given by EXPANDPERCENT. - */ -{ - int newSize; - - newSize = textInfo->bufAlloc + (textInfo->bufAlloc * EXPANDPERCENT) / 100; - textInfo->mainBuffer = (short *) - realloc((char *) textInfo->mainBuffer, (unsigned) newSize * sizeof(short)); - textInfo->bufAlloc = newSize; - return 1; -} - - - -static int HandleNewLine(display, textInfo, flagWord) -Display *display; -struct txtWin *textInfo; /* Text Information */ -int flagWord; /* DODISP or NONEWLINE or both */ -/* - * This routine initializes the next line for drawing by setting - * its height to the current font height, scrolls the screen down - * one line, and updates the current drawing position to the - * left edge of the newly cleared line. If DODISP is specified, - * the screen will be updated (otherwise not). If NONEWLINE is - * specified, no newline character will be added to the text buffer - * (this is for line wrap). - */ -{ - struct txtLine *curLine, *nextLine; - - /* Check to see if a new line must be allocated */ - if (textInfo->curLine >= textInfo->allocLines-1) - /* Expand the number of lines */ - ExpandLines(textInfo); - textInfo->numLines += 1; - - /* Then we initialize the next line */ - nextLine = textInfo->txtBuffer[textInfo->numLines-1]; - nextLine->lineHeight = - textInfo->theFonts[textInfo->curFont].ascent + - textInfo->theFonts[textInfo->curFont].descent; - - curLine = textInfo->txtBuffer[textInfo->curLine]; - if (flagWord & DODISP) { - /* Scroll down a line if required */ - if ((textInfo->curY + curLine->lineHeight + - nextLine->lineHeight + (INTERLINE * 2)) > textInfo->h) - { - ScrollDown(display, textInfo); - } - else - { - /* Update the bottom space appropriately */ - textInfo->bottomSpace -= (nextLine->lineHeight + INTERLINE); - textInfo->endLine += 1; - } - /* Update drawing position */ - textInfo->curY = textInfo->h - - (textInfo->bottomSpace + nextLine->lineHeight); - } - - /* Move down a line */ - textInfo->curLine += 1; - if (!(flagWord & NONEWLINE)) { - /* Append end-of-line to text buffer */ - if (textInfo->bufSpot >= textInfo->bufAlloc) { - /* Allocate more space in main text buffer */ - ExpandBuffer(textInfo); - } - textInfo->mainBuffer[(textInfo->bufSpot)++] = - (textInfo->curFont << FONTSHIFT) | '\n'; - } - nextLine->lineText = textInfo->bufSpot; - textInfo->curX = 0; - return 1; -} - - - -static int CharSize(textInfo, lineNum, charNum) -struct txtWin *textInfo; /* Current Text Information */ -int lineNum; /* Line in buffer */ -int charNum; /* Character in line */ -/* - * This routine determines the size of the specified character. - * It takes in account the font of the character and whether its - * fixed or variable. The size includes INTERSPACE spacing between - * the characters. - */ -{ - register XFontStruct *charFont; - register short *theLine; - register short theChar; - - theLine = &(textInfo->mainBuffer[textInfo->txtBuffer[lineNum]->lineText]); - theChar = theLine[charNum] & CHARMASK; - charFont = &(textInfo->theFonts[(theChar & FONTMASK) >> FONTSHIFT]); - if (theChar <= charFont->min_char_or_byte2 || - theChar >= charFont->max_char_or_byte2 || - charFont->per_char == 0) - return charFont->max_bounds.width + 1; - else - return charFont->per_char[theChar].width + 1; -} - - - - - -static int HandleBackspace(display, textInfo, flagWord) -Display *display; -struct txtWin *textInfo; /* Text Information */ -int flagWord; /* DODISP or nothing */ -/* - * This routine handles a backspace found in the input stream. The - * character before the current writing position will be erased and - * the drawing position will move back one character. If the writing - * position is at the left margin, the drawing position will move - * up to the previous line. If it is a line that has been wrapped, - * the character at the end of the previous line will be erased. - */ -{ - struct txtLine *thisLine, *prevLine; - int chSize; - - thisLine = textInfo->txtBuffer[textInfo->curLine]; - /* First, determine whether we need to go back a line */ - if (thisLine->lineLength == 0) { - /* Bleep if at top of buffer */ - if (textInfo->curLine == 0) { - XBell(display, 50); - return 0; - } - - /* See if we have to scroll in the other direction */ - if ((flagWord & DODISP) && (textInfo->curY <= YPADDING)) { - /* This will display the last lines of the buffer */ - WarpToBottom(display, textInfo); - } - - /* Set drawing position at end of previous line */ - textInfo->curLine -= 1; - prevLine = textInfo->txtBuffer[textInfo->curLine]; - textInfo->numLines -= 1; - if (flagWord & DODISP) { - textInfo->curY -= (prevLine->lineHeight + INTERLINE); - textInfo->bottomSpace += (thisLine->lineHeight + INTERLINE); - textInfo->endLine -= 1; - } - - /* We are unlinewrapping if the previous line has flag set */ - if (prevLine->lineFlags & WRAPFLAG) { - /* Get rid of line wrap indicator */ - if (flagWord & DODISP) { - XFillRectangle(display, textInfo->mainWindow, - textInfo->bgGC, - textInfo->w - BARSIZE - WRAPINDSIZE, - textInfo->curY, WRAPINDSIZE, - prevLine->lineHeight); - } - prevLine->lineFlags &= (~WRAPFLAG); - /* Call recursively to wipe out the ending character */ - HandleBackspace(display, textInfo, flagWord); - } else { - /* Delete the end-of-line in the primary buffer */ - textInfo->bufSpot -= 1; - } - } else { - /* Normal deletion of character */ - chSize = - CharSize(textInfo, textInfo->curLine, - textInfo->txtBuffer[textInfo->curLine]->lineLength - 1); - /* Move back appropriate amount and wipe it out */ - thisLine->lineWidth -= chSize; - if (flagWord & DODISP) { - XFillRectangle(display, textInfo->mainWindow, - textInfo->bgGC, - thisLine->lineWidth, textInfo->curY, - chSize, thisLine->lineHeight); - } - /* Delete from buffer */ - textInfo->txtBuffer[textInfo->curLine]->lineLength -= 1; - textInfo->bufSpot -= 1; - } - return 1; -} - - - -static int DrawLineWrap(display, win, x, y, h, col) -Display *display; -Window win; /* What window to draw it in */ -int x, y; /* Position of upper left corner */ -int h; /* Height of indicator */ -int col; /* Color of indicator */ -/* - * This routine draws a line wrap indicator at the end of a line. - * Visually, it is an arrow of the specified height directly against - * the scroll bar border. The bitmap used for the arrow is stored - * in 'arrowMap' with size 'arrow_width' and 'arrow_height'. - */ -{ - struct txtWin *textInfo; - - textInfo = (struct txtWin *)XLookUpAssoc(display, textWindows, - (XID) win); - - /* First, draw the arrow */ - XCopyArea(display, textInfo->arrowMap, textInfo->mainWindow, - textInfo->CursorGC, - 0, 0, arrow_width, arrow_height, - x, y + h - arrow_height, 1); - - /* Then draw the stem */ - XDrawLine(display, textInfo->mainWindow, textInfo->CursorGC, - x + STEMOFFSET, y, - x + STEMOFFSET, y + h - arrow_height); - return 1; -} - - - - -static int DrawLine(display, textInfo, lineIndex, ypos) -Display *display; -struct txtWin *textInfo; /* Text window information */ -int lineIndex; /* Index of line to draw */ -int ypos; /* Y position for line */ -/* - * This routine destructively draws the indicated line in the - * indicated window at the indicated position. It does not - * clear to end of line however. It draws a line wrap indicator - * if needed but does not draw a cursor. - */ -{ - int index, startPos, curFont, theColor, curX, saveX, fontIndex; - struct txtLine *someLine; - char lineBuffer[BUFSIZE], *glyph; - short *linePointer; - XFontStruct *theFont; - XGCValues gc; - - /* First, we draw the text */ - index = 0; - curX = XPADDING; - someLine = textInfo->txtBuffer[lineIndex]; - linePointer = &(textInfo->mainBuffer[someLine->lineText]); - while (index < someLine->lineLength) { - startPos = index; - saveX = curX; - curFont = linePointer[index] & FONTMASK; - fontIndex = curFont >> FONTSHIFT; - theFont = &(textInfo->theFonts[fontIndex]); - theColor = textInfo->theColors[fontIndex]; - glyph = &(lineBuffer[0]); - while ((index < someLine->lineLength) && - ((linePointer[index] & FONTMASK) == curFont)) - { - *glyph = linePointer[index] & CHARMASK; - index++; - curX += CharSize(textInfo, lineIndex, index); - glyph++; - } - - /* Flush out the glyphs */ - XFillRectangle(display, textInfo->mainWindow, - textInfo->bgGC, - saveX, ypos, - textInfo->w - BARSIZE, - someLine->lineHeight + YPADDING + INTERLINE); - - XDrawString(display, textInfo->mainWindow, - textInfo->fontGC[fontIndex], - saveX, ypos, - lineBuffer, someLine->lineLength); - } - /* Then the line wrap indicator (if needed) */ - if (someLine->lineFlags & WRAPFLAG) { - DrawLineWrap(display, textInfo->mainWindow, - textInfo->w - BARSIZE - WRAPINDSIZE, - ypos, someLine->lineHeight, - textInfo->fgPix); - } - return 1; -} - - - - -static int HandleNewFont(display, fontNum, textInfo, flagWord) -Display *display; -int fontNum; /* Font number */ -struct txtWin *textInfo; /* Text information */ -int flagWord; /* DODISP or nothing */ -/* - * This routine handles a new font request. These requests take - * the form "^F". The parsing is done in TxtWriteStr. - * This routine is called only if the form is valid. It may return - * a failure (0 status) if the requested font is not loaded. - * If the new font is larger than any of the current - * fonts on the line, it will change the line height and redisplay - * the line. - */ -{ - struct txtLine *thisLine; - int heightDiff, baseDiff, redrawFlag; - - if (textInfo->theFonts[fontNum].fid == 0) { - return 0; - } else { - thisLine = textInfo->txtBuffer[textInfo->curLine]; - textInfo->curFont = fontNum; - redrawFlag = 0; - heightDiff = textInfo->theFonts[fontNum].ascent + - textInfo->theFonts[fontNum].descent - - thisLine->lineHeight; - - if (heightDiff > 0) { - redrawFlag = 1; - } else { - heightDiff = 0; - } - - if (redrawFlag) { - if (flagWord & DODISP) { - /* Clear current line */ - XFillRectangle(display, textInfo->mainWindow, - textInfo->bgGC, - 0, textInfo->curY, textInfo->w, - thisLine->lineHeight); - - /* Check to see if it requires scrolling */ - if ((textInfo->curY + thisLine->lineHeight + heightDiff + - INTERLINE) > textInfo->h) - { - /* - * General approach: "unscroll" the last line up - * and then call ScrollDown to do the right thing. - */ - textInfo->endLine -= 1; - textInfo->bottomSpace += thisLine->lineHeight + - INTERLINE; - - XFillRectangle(display, textInfo->mainWindow, - textInfo->bgGC, - 0, textInfo->h - textInfo->bottomSpace, - textInfo->w, textInfo->bottomSpace); - - thisLine->lineHeight += heightDiff; - ScrollDown(display, textInfo); - textInfo->curY = textInfo->h - - (textInfo->bottomSpace + INTERLINE + - thisLine->lineHeight); - } - else - { - /* Just update bottom space */ - textInfo->bottomSpace -= heightDiff; - thisLine->lineHeight += heightDiff; - } - /* Redraw the current line */ - DrawLine(display, textInfo, textInfo->curLine, textInfo->curY); - } else { - /* Just update line height */ - thisLine->lineHeight += heightDiff; - } - } - return 1; - } -} - - - -int TxtWriteStr(display, w, str) -Display *display; -Window w; /* Text window */ -register char *str; /* 0 terminated string */ -/* - * This routine writes a string to the specified text window. - * The following notes apply: - * - Text is always appended to the end of the text buffer. - * - If the scroll bar is positioned such that the end of the - * text is not visible, an automatic scroll to the bottom - * will be done before the appending of text. - * - Non-printable ASCII characters are not displayed. - * - The '\n' character causes the current text position to - * advance one line and start at the left. - * - Tabs are not supported. - * - Lines too long for the screen will be wrapped and a line wrap - * indication will be drawn. - * - Backspace clears the previous character. It will do the right - * thing if asked to backspace past a wrapped line. - * - A new font can be chosen using the sequence '^F' where - * is 0-7. The directive will be ignored if - * there is no font in the specified slot. - * Returns 0 if something went wrong. - */ -{ - register int fontIndex; - register struct txtWin *textInfo; - register struct txtLine *thisLine; - - if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0) - return 0; - - /* See if screen needs to be updated */ - if (textInfo->flagWord & SCREENWRONG) { - TxtRepaint(display, textInfo->mainWindow); - } - - /* See if we have to scroll down to the bottom */ - if (textInfo->flagWord & NOTATBOTTOM) { - WarpToBottom(display, textInfo); - textInfo->flagWord &= (~NOTATBOTTOM); - } - - /* Undraw the current cursor */ - thisLine = textInfo->txtBuffer[textInfo->curLine]; - - XFillRectangle(display, w, textInfo->bgGC, - thisLine->lineWidth + CUROFFSET, - textInfo->curY, - CURSORWIDTH, - thisLine->lineHeight); - - for ( /* str is ok */ ; (*str != 0) ; str++) { - /* Check to see if we are waiting on a font */ - if (textInfo->flagWord & FONTNUMWAIT) { - textInfo->flagWord &= (~FONTNUMWAIT); - fontIndex = *str - '0'; - if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) { - /* Handle font -- go get next character */ - if (HandleNewFont(display, fontIndex, textInfo, DODISP)) - continue; - } - } - - /* Inline code for handling normal character case */ - if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) { - register XFontStruct *thisFont; - register struct txtLine *thisLine; - register int charWidth; - int thisColor; - - /* Determine size of character */ - thisFont = &(textInfo->theFonts[textInfo->curFont]); - thisColor = textInfo->theColors[textInfo->curFont]; - if (*str <= thisFont->min_char_or_byte2 || - *str >= thisFont->max_char_or_byte2 || - thisFont->per_char == 0) - charWidth = thisFont->max_bounds.width + 1; - else - charWidth = thisFont->per_char[*str].width + 1; - - /* Check to see if line wrap is required */ - thisLine = textInfo->txtBuffer[textInfo->curLine]; - if (thisLine->lineWidth + charWidth > - (textInfo->w-BARSIZE-WRAPINDSIZE)) - { - DrawLineWrap(display, textInfo->mainWindow, - textInfo->w-BARSIZE-WRAPINDSIZE, - textInfo->curY, thisLine->lineHeight, - textInfo->fgPix); - thisLine->lineFlags |= WRAPFLAG; - /* Handle the spacing problem the same way as a newline */ - HandleNewLine(display, textInfo, DODISP | NONEWLINE); - thisLine = textInfo->txtBuffer[textInfo->curLine]; - } - - /* Ready to draw character */ - XDrawString(display, textInfo->mainWindow, - DEFAULT_GC, - textInfo->curX += charWidth, - textInfo->curY + thisLine->lineHeight, - str, 1); - - /* Append character onto main buffer */ - if (textInfo->bufSpot >= textInfo->bufAlloc) - /* Make room for more characters */ - ExpandBuffer(textInfo); - textInfo->mainBuffer[(textInfo->bufSpot)++] = - (textInfo->curFont << FONTSHIFT) | (*str); - - /* Update the line start array */ - thisLine->lineLength += 1; - thisLine->lineWidth += charWidth; - } else if (*str == NEWLINE) { - HandleNewLine(display, textInfo, DODISP); - } else if (*str == NEWFONT) { - /* Go into waiting for font number mode */ - textInfo->flagWord |= FONTNUMWAIT; - } else if (*str == BACKSPACE) { - HandleBackspace(display, textInfo, DODISP); - } else { - /* Ignore all others */ - } - } - /* Draw the cursor in its new position */ - thisLine = textInfo->txtBuffer[textInfo->curLine]; - - XFillRectangle(display, w, textInfo->CursorGC, - thisLine->lineWidth + CUROFFSET, - textInfo->curY /* + thisLine->lineHeight */, - CURSORWIDTH, thisLine->lineHeight); - - return 1; -} - - - -int TxtJamStr(display, w, str) -Display *display; -Window w; /* Text window */ -register char *str; /* NULL terminated string */ -/* - * This is the same as TxtWriteStr except the screen is NOT updated. - * After a call to this routine, TxtRepaint should be called to - * update the screen. This routine is meant to be used to load - * a text buffer with information and then allow the user to - * scroll through it at will. - */ -{ - register int fontIndex; - register struct txtWin *textInfo; - - if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w) - ) == 0) - return 0; - - for ( /* str is ok */ ; (*str != 0) ; str++) { - /* Check to see if we are waiting on a font */ - if (textInfo->flagWord & FONTNUMWAIT) { - textInfo->flagWord &= (~FONTNUMWAIT); - fontIndex = *str - '0'; - if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) { - if (HandleNewFont(display, fontIndex, textInfo, 0)) { - /* Handled font -- go get next character */ - continue; - } - } - } - /* Inline code for handling normal character case */ - if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) { - register XFontStruct *thisFont; - register struct txtLine *thisLine; - register int charWidth; - - /* Determine size of character */ - thisFont = &(textInfo->theFonts[textInfo->curFont]); - - if (*str <= thisFont->min_char_or_byte2 || - *str >= thisFont->max_char_or_byte2 || - thisFont->per_char == 0) - charWidth = thisFont->max_bounds.width + 1; - else - charWidth = thisFont->per_char[*str].width + 1; - - /* Check to see if line wrap is required */ - thisLine = textInfo->txtBuffer[textInfo->curLine]; - if (thisLine->lineWidth + charWidth > - (textInfo->w-BARSIZE-WRAPINDSIZE)) - { - thisLine->lineFlags |= WRAPFLAG; - /* Handle the spacing problem the same way as a newline */ - HandleNewLine(display, textInfo, NONEWLINE); - thisLine = textInfo->txtBuffer[textInfo->curLine]; - } - /* Append character onto main buffer */ - if (textInfo->bufSpot >= textInfo->bufAlloc) - /* Make room for more characters */ - ExpandBuffer(textInfo); - textInfo->mainBuffer[(textInfo->bufSpot)++] = - (textInfo->curFont << FONTSHIFT) | (*str); - - /* Update the line start array */ - thisLine->lineLength += 1; - thisLine->lineWidth += charWidth; - } else if (*str == NEWLINE) { - HandleNewLine(display, textInfo, 0); - } else if (*str == NEWFONT) { - /* Go into waiting for font number mode */ - textInfo->flagWord |= FONTNUMWAIT; - } else if (*str == BACKSPACE) { - HandleBackspace(display, textInfo, 0); - } else { - /* Ignore all others */ - } - } - textInfo->flagWord |= SCREENWRONG; - return 1; -} - - - -int TxtRepaint(display,w) -Display *display; -Window w; -/* - * Repaints the given scrollable text window. The routine repaints - * the entire window. For handling exposure events, the TxtFilter - * routine should be used. - */ -{ - struct txtWin *textInfo; - int index, ypos; - - if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w) - ) == 0) - return 0; - - /* Check to see if the screen is up to date */ - if (textInfo->flagWord & SCREENWRONG) { - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - textInfo->flagWord &= (~SCREENWRONG); - } - - ypos = YPADDING; - index = textInfo->startLine; - for (;;) { - DrawLine(display, textInfo, index, ypos); - if (index >= textInfo->endLine) break; - ypos += (textInfo->txtBuffer[index]->lineHeight + INTERLINE); - index++; - } - /* Draw the cursor (if on screen) */ - if (textInfo->endLine == textInfo->curLine) { - XFillRectangle(display, w, textInfo->CursorGC, - textInfo->txtBuffer[index]->lineWidth + CUROFFSET, - ypos /* + textInfo->txtBuffer[index]->lineHeight */, - CURSORWIDTH, textInfo->txtBuffer[index]->lineHeight); - - } - /* Update the scroll bar */ - UpdateScroll(display, textInfo); - return 1; -} - - - -static int InsertIndex(textInfo, thisIndex, ypos) -struct txtWin *textInfo; /* Text Window Information */ -int thisIndex; /* Line index of exposed line */ -int ypos; /* Drawing position of line */ -/* - * This routine inserts the supplied line index into the copy - * exposure array for 'textInfo'. The array is kept sorted - * from lowest to highest using insertion sort. The array - * is dynamically expanded if needed. - */ -{ - struct expEvent *newItem; - int newSize, index, downIndex; - - /* Check to see if we need to expand it */ - if ((textInfo->exposeSize + 3) >= textInfo->exposeAlloc) { - newSize = textInfo->exposeAlloc + - (textInfo->exposeAlloc * EXPANDPERCENT / 100); - textInfo->exposeAry = (struct expEvent **) - realloc((char *) textInfo->exposeAry, - (unsigned) (newSize * sizeof(struct expEvent *))); - for (index = textInfo->exposeAlloc; index < newSize; index++) - textInfo->exposeAry[index] = alloc(struct expEvent); - textInfo->exposeAlloc = newSize; - } - /* Find spot for insertion. NOTE: last spot has big number */ - for (index = 0; index <= textInfo->exposeSize; index++) { - if (textInfo->exposeAry[index]->lineIndex >= thisIndex) { - if (textInfo->exposeAry[index]->lineIndex > thisIndex) { - /* Insert before this entry */ - newItem = textInfo->exposeAry[textInfo->exposeSize+1]; - for (downIndex = textInfo->exposeSize; - downIndex >= index; - downIndex--) - { - textInfo->exposeAry[downIndex+1] = - textInfo->exposeAry[downIndex]; - } - /* Put a free structure at this spot */ - textInfo->exposeAry[index] = newItem; - /* Fill it in */ - textInfo->exposeAry[index]->lineIndex = thisIndex; - textInfo->exposeAry[index]->ypos = ypos; - /* Break out of loop */ - textInfo->exposeSize += 1; - } - break; - } - } - return 1; -} - - - -static int ScrollUp(display, textInfo) -Display *display; -struct txtWin *textInfo; /* Text window information */ -/* - * This routine scrolls the indicated text window up by one - * line. The line above the current line must exist. The - * window is scrolled so that the line above the start line - * is displayed at the top of the screen. This may cause - * many lines to scroll off the bottom. The scrolling is - * done using XCopyArea. The exposure events should be caught - * by ExposeCopy. - */ -{ - int targetSpace; - - /* Make sure all exposures have been handled by now */ - if (textInfo->startLine == 0) return 0; - targetSpace = textInfo->txtBuffer[textInfo->startLine-1]->lineHeight + - INTERLINE; - /* Move the area downward by the target amount */ - XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow, - DEFAULT_GC, - 0, YPADDING, textInfo->w - BARSIZE, - textInfo->h, 0, targetSpace); - - textInfo->flagWord |= COPYEXPOSE; - /* Update the text window parameters */ - textInfo->startLine -= 1; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - - /* Clear out bottom space region */ - XClearArea(display, textInfo->mainWindow, - 0, textInfo->h - textInfo->bottomSpace, - textInfo->w, textInfo->bottomSpace); - - UpdateExposures(display, textInfo); - UpdateScroll(display, textInfo); - - return 1; -} - - -static int ScrollToSpot(display, textInfo, ySpot) -Display *display; -struct txtWin *textInfo; /* Text window information */ -int ySpot; /* Button position in scroll window */ -/* - * This routine scrolls the specified text window relative to the - * position of the mouse in the scroll bar. The center of the screen - * will be positioned to correspond to the mouse position. - */ -{ - int targetLine, aboveLines; - - targetLine = textInfo->numLines * ySpot / textInfo->h; - textInfo->startLine = targetLine; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - aboveLines = 0; - /* Make the target line the *center* of the window */ - while ((textInfo->startLine > 0) && - (aboveLines < textInfo->endLine - targetLine)) - { - textInfo->startLine -= 1; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - aboveLines++; - } - if (textInfo->endLine == textInfo->numLines-1) { - WarpToBottom(display, textInfo); - } else { - XClearWindow(display, textInfo->mainWindow); - TxtRepaint(display, textInfo->mainWindow); - } - return 1; -} - - - -static int LineToTop(display, textInfo, pos) -Display *display; -struct txtWin *textInfo; /* Text window information */ -int pos; /* Y position of mouse */ -/* - * This routine scrolls the screen down until the line at the - * mouse position is at the top of the screen. It stops - * if it can't scroll the buffer down that far. If the - * global 'ScrollOption' is NORMSCROLL, a smooth scroll - * is used. Otherwise, it jumps to the right position - * and repaints the screen. - */ -{ - int index, sum; - - /* First, we find the current line */ - sum = 0; - for (index = textInfo->startLine; index <= textInfo->endLine; index++) { - if (sum + textInfo->txtBuffer[index]->lineHeight + INTERLINE> pos) break; - sum += textInfo->txtBuffer[index]->lineHeight + INTERLINE; - } - /* We always want to scroll down at least one line */ - if (index == textInfo->startLine) index++; - if (ScrollOption == NORMSCROLL) { - /* Scroll down until 'index' is the starting line */ - while ((textInfo->startLine < index) && ScrollDown(display, textInfo)) - { - /* Empty Loop Body */ - } - } else { - /* Immediately jump to correct spot */ - textInfo->startLine = index; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - if (textInfo->endLine == textInfo->numLines-1) { - WarpToBottom(display, textInfo); - } else { - XClearWindow(display, textInfo->mainWindow); - TxtRepaint(display, textInfo->mainWindow); - } - } - /* Check to see if at end of buffer */ - if (textInfo->endLine >= textInfo->numLines-1) { - textInfo->flagWord &= (~NOTATBOTTOM); - } - return 1; -} - - - -static int TopToHere(display, textInfo, pos) -Display *display; -struct txtWin *textInfo; /* Text window information */ -int pos; /* Y position of mouse */ -/* - * This routine scrolls the screen up until the top line of - * the screen is at the current Y position of the mouse. Again, - * it will stop if it can't scroll that far. If the global - * 'ScrollOption' is NORMSCROLL, a smooth scroll is used. - * If it's not, it will simply redraw the screen at the - * correct spot. - */ -{ - int sum, target, linesup, index; - - target = pos - textInfo->txtBuffer[textInfo->startLine]->lineHeight; - /* We always want to scroll up at least one line */ - if (target <= 0) target = 1; - sum = 0; - linesup = 0; - /* Check to see if we are at the top anyway */ - if (textInfo->startLine == 0) return 0; - if (ScrollOption == NORMSCROLL) { - /* Scroll up until sum of new top lines greater than target */ - while ((sum < target) && ScrollUp(display, textInfo)) { - sum += textInfo->txtBuffer[textInfo->startLine]->lineHeight; - linesup++; - } - } else { - /* Search backward to find index */ - index = textInfo->startLine - 1; - while ((index > 0) && (sum < target)) { - sum += textInfo->txtBuffer[index]->lineHeight; - linesup++; - index--; - } - /* Go directly to the index */ - textInfo->startLine = index; - textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); - XClearWindow(display, textInfo->mainWindow); - TxtRepaint(display, textInfo->mainWindow); - } - /* If we scrolled, assert we are not at bottom of buffer */ - if (linesup > 0) { - textInfo->flagWord |= NOTATBOTTOM; - } - return 1; -} - - - -int TxtFilter(display, evt) -Display *display; -XEvent *evt; -/* - * This routine handles events associated with scrollable text windows. - * It will handle all exposure events and any button released events - * in the scroll bar of a text window. It does NOT handle any other - * events. If it cannot handle the event, it will return 0. - */ -{ - XExposeEvent *expose = &evt->xexpose; - XButtonEvent *btEvt = &evt->xbutton; - XGraphicsExposeEvent *gexpose = &evt->xgraphicsexpose; - XNoExposeEvent *noexpose = &evt->xnoexpose; - struct txtWin *textInfo; - int index, ypos; - Window w, sw; - - if (textWindows == (XAssocTable *) 0) { - textWindows = XCreateAssocTable(32); - if (textWindows == (XAssocTable *) 0) return(0); - } - if (evt->type == Expose) { - w = expose->window; - sw = 0; - } - else if (evt->type == GraphicsExpose) { - w = gexpose->drawable; - sw = 0; - } - else if (evt->type == NoExpose) { - w = noexpose->drawable; - sw = 0; - } - else if (evt->type == ButtonRelease) { - w = btEvt->window; - sw = btEvt->subwindow; - } - else - return 0; - - if ((textInfo = (struct txtWin *) - XLookUpAssoc(display, textWindows, (XID) w)) == 0) - return 0; - - /* Determine whether it's main window or not */ - if ((w == textInfo->mainWindow) && (sw == 0)) { - /* Main Window - handle exposures */ - switch (evt->type) { - case Expose: - ypos = 0 /*YPADDING*/; - for (index = textInfo->startLine; - index <= textInfo->endLine; - index++) - { - int lh = textInfo->txtBuffer[index]->lineHeight; - - if (((ypos + lh) >= expose->y) && - (ypos <= (expose->y + expose->height))) - { - /* Intersection region */ - /* Draw line immediately */ - DrawLine(display, textInfo, index, ypos); - /* And possibly draw cursor */ - if (textInfo->curLine == index) { - XFillRectangle(display, w, textInfo->CursorGC, - textInfo->txtBuffer[index]->lineWidth + - CUROFFSET, - ypos, - CURSORWIDTH, - lh); - } - } - ypos += lh + INTERLINE; - } - break; - case GraphicsExpose: - ypos = 0 /*YPADDING*/; - for (index = textInfo->startLine; - index <= textInfo->endLine; - index++) - { - int lh = textInfo->txtBuffer[index]->lineHeight; - - if (((ypos + lh) >= gexpose->y) && - (ypos <= (gexpose->y + gexpose->height))) - { - /* Intersection region */ - /* Draw line immediately */ - DrawLine(display, textInfo, index, ypos); - /* And possibly draw cursor */ - if (textInfo->curLine == index) { - XFillRectangle(display, w, textInfo->CursorGC, - textInfo->txtBuffer[index]->lineWidth + - CUROFFSET, - ypos, - CURSORWIDTH, - lh); - } - } - ypos += lh + INTERLINE; - } - break; - case NoExpose: - break; - default: - /* Not one of our events */ - return 0; - } - } else { - switch (evt->type) { - case Expose: - UpdateScroll(display, textInfo); - break; - case ButtonRelease: - /* Find out which button */ - switch (btEvt->button) { - case Button1: - /* Scroll up until top line is at mouse position */ - TopToHere(display, textInfo, btEvt->y); - break; - case Button2: - /* Scroll to spot relative to position */ - ScrollToSpot(display, textInfo, btEvt->y); - if (textInfo->endLine >= textInfo->numLines-1) { - textInfo->flagWord &= (~NOTATBOTTOM); - } else { - textInfo->flagWord |= NOTATBOTTOM; - } - break; - case Button3: - /* Scroll down until pointed line is at top */ - LineToTop(display, textInfo, btEvt->y); - break; - } - break; - default: - /* Not one of our events */ - return 0; - } - } - return 1; -} diff --git a/gnu/games/chess/Xchess/std.c b/gnu/games/chess/Xchess/std.c deleted file mode 100644 index 2bbd113..0000000 --- a/gnu/games/chess/Xchess/std.c +++ /dev/null @@ -1,427 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.3 $ on $Date: 1994/11/04 02:11:33 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/std.c,v $ - * Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group - * - * Utility routines. - */ - -#include "std.h" - -#ifndef IBMPC -#include -#endif not IBMPC -#ifdef UNIX -#include -#include -#endif UNIX -#ifdef BSD -#include -#include -#endif BSD - -extern char **environ; - -bool -prefix(p, s) - register char *p, *s; -{ - while (*p && (*p == *s)) - p++, s++; - if (!*p) - return (true); - else - return (false); -} - -/* Create a copy of a string. */ - -char * -copy(str) - char *str; -{ - char *p, *tmalloc(); - - p = tmalloc(strlen(str) + 1); - strcpy(p, str); - return(p); -} - -/* Determine whether sub is a substring of str. */ - -bool -substring(sub, str) - register char *str, *sub; -{ - register char *s; - - while(*str) { - if(*str == *sub) { - for(s = sub; *s; s++) - if(*s != *str++) - break; - if(*s == '\0') - return (true); - } - str++; - } - return (false); -} - -/* Malloc num bytes and initialize to zero. Fatal error if the space can't - * be malloc'd. - */ - -char * -tmalloc(num) - register int num; -{ - register char *s; - char *malloc(); - - s = malloc((unsigned) num); - if (!s) { - fatal("malloc: can't allocate %d bytes", num); - } - bzero(s, num); - return(s); -} - -char * -trealloc(ptr, num) - char *ptr; - int num; -{ - register char *s; - char *realloc(); - - s = realloc(ptr, (unsigned) num); - if (!s) { - fatal("realloc: can't allocate %d bytes", num); - } - /* Well, this won't be zeroed... Too bad... */ - return(s); -} - -/* Append one character to a string. Don't check for overflow. */ - -void -appendc(s, c) - char *s, c; -{ - while (*s) - s++; - *s++ = c; - *s = '\0'; - return; -} - -int -scannum(str) - char *str; -{ - int i = 0; - - while(isdigit(*str)) - i = i * 10 + *(str++) - '0'; - return(i); -} - -/* Case insensitive prefix. */ - -bool -ciprefix(p, s) - register char *p, *s; -{ - while (*p) { - if ((isupper(*p) ? tolower(*p) : *p) != - (isupper(*s) ? tolower(*s) : *s)) - return(false); - p++; - s++; - } - return (true); -} - -/* Case insensitive strcmp... */ - -bool -cieq(p, s) - register char *p, *s; -{ - while (*p) { - if ((isupper(*p) ? tolower(*p) : *p) != - (isupper(*s) ? tolower(*s) : *s)) - return(false); - p++; - s++; - } - return (!*s); -} - -#ifdef BSD - -/* Return the date. Return value is static data. */ - -char * -datestring() -{ - register char *tzn; - struct tm *tp; - static char tbuf[40]; - char *ap; - struct timeval tv; - struct timezone tz; - char *timezone(), *asctime(); - int i; - struct tm *localtime(); - - (void) gettimeofday(&tv, &tz); - tp = localtime((time_t *) &tv.tv_sec); - ap = asctime(tp); - tzn = timezone(tz.tz_minuteswest, tp->tm_isdst); - sprintf(tbuf, "%.20s", ap); - if (tzn) - strcat(tbuf, tzn); - strcat(tbuf, ap + 19); - i = strlen(tbuf); - tbuf[i - 1] = '\0'; - return (tbuf); -} - -#else BSD - -/* Give it a try... */ - -char * -datestring() -{ - long i; - static char buf[64]; - - i = time(0); - strcpy(buf, ctime(&i)); - buf[strlen(buf) - 1] = '\0'; /* Kill the nl. */ - return (buf); -} - -#endif - -/* How many seconds have elapsed in running time. */ - -int -seconds() -{ -#ifdef BSD - struct rusage ruse; - - getrusage(RUSAGE_SELF, &ruse); - return (ruse.ru_utime.tv_sec); -#else BSD -#endif BSD -} - -/* A few things that may not exist on non-unix systems. */ - -#ifndef BSD - -#ifndef index - -char * -index(s, c) - register char *s; - register char c; -{ - while ((*s != c) && (*s != '\0')) - s++; - if (*s == '\0') - return ((char *) 0); - else - return (s); -} - -#endif not index - -#ifndef rindex - -char * -rindex(s, c) - register char *s; - register char c; -{ - register char *t; - - for (t = s; *t != '\0'; t++); - while ((*t != c) && (t != s)) - t--; - if (t == s) - return ((char *) 0); - else - return (t); -} - -#endif not rindex - -#ifndef bcopy - -void -bcopy(from, to, num) - register char *from, *to; - register int num; -{ - while (num-- > 0) - *to++ = *from++; - return; -} - -#endif not bcopy - -#ifndef bzero - -void -bzero(ptr, num) - register char *ptr; - register int num; -{ - while (num-- > 0) - *ptr++ = '\0'; - return; -} - -#endif not bzero - -/* This might not be around... If not then forget about sorting... */ - -void qsort() {} - -#endif BSD - -char * -gettok(s) - char **s; -{ - char buf[BSIZE]; - int i = 0; - - while (isspace(**s)) - (*s)++; - if (!**s) - return (NULL); - while (**s && !isspace(**s)) - buf[i++] = *(*s)++; - buf[i] = '\0'; - while (isspace(**s)) - (*s)++; - return (copy(buf)); -} - -/* Die horribly. */ - -/* VARARGS1 */ -void -fatal(s, args) - char *s; -{ - fputs("Internal Error: ", stderr); -#ifndef __FreeBSD__ - _doprnt(s, &args, stderr); -#endif - putc('\n', stderr); - - kill(getpid(), SIGIOT); - /* NOTREACHED */ -} - -void -setenv(name, value) - char *name, *value; -{ - int i; - char **xx, *s; - - s = tmalloc(strlen(name) + 2); - sprintf(s, "%s=", name); - - /* Copy the old environment... */ - for (i = 0; environ[i]; i++) - if (prefix(s, environ[i])) - break; - if (!environ[i]) { - xx = (char **) tmalloc((i + 2) * sizeof (char *)); - for (i = 0; environ[i]; i++) - xx[i] = environ[i]; - xx[i + 1] = NULL; - environ = xx; - } else - xx = environ; - - xx[i] = tmalloc(strlen(name) + strlen(value) + 2); - sprintf(xx[i], "%s=%s", name, value); - return; -} - -char * -getusername() -{ - int i = getuid(); - struct passwd *pw = getpwuid(i); - - return (pw ? pw->pw_name : NULL); -} - -char * -gethome() -{ - int i = getuid(); - struct passwd *pw = getpwuid(i); - - return (pw ? pw->pw_dir : "/strange"); -} - -char * -tildexpand(s) - char *s; -{ - struct passwd *pw; - char *n, buf[64]; - int i; - - if (*s != '~') - return (copy(s)); - - for (s++, i = 0; *s != '/'; s++, i++) - buf[i] = *s; - buf[i] = '\0'; - if (!i) - pw = getpwuid(getuid()); - else - pw = getpwnam(buf); - if (!pw) - return (s); - n = tmalloc(strlen(s) + strlen(pw->pw_dir) + 1); - strcpy(n, pw->pw_dir); - strcat(n, s); - return (n); -} - diff --git a/gnu/games/chess/Xchess/std.h b/gnu/games/chess/Xchess/std.h deleted file mode 100644 index 19cb1da..0000000 --- a/gnu/games/chess/Xchess/std.h +++ /dev/null @@ -1,105 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:06 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/std.h,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * - * Standard definitions. - */ - -#define UNIX -#define BSD - -#ifndef FILE -#include -#endif -#ifndef isalpha -#include -#endif -#ifndef HUGE -#include -#endif -#include - -typedef int bool; - -#define false 0 -#define true 1 - -/* Externs defined in std.c */ - -extern char *tmalloc(); -extern char *trealloc(); -extern char *copy(); -extern char *datestring(); -extern char *getusername(); -extern char *gethome(); -extern char *gettok(); -extern char *tildexpand(); -extern void fatal(); -extern void setenv(); -extern void appendc(); -extern int scannum(); -extern int seconds(); -extern bool prefix(); -extern bool ciprefix(); -extern bool cieq(); -extern bool substring(); - -/* Externs from libc */ - -extern char *getenv(); -extern int errno; -/* extern char *sys_errlist[]; */ - -/* Should use BSIZE instead of BUFSIZ... */ - -#define BSIZE 512 - -/* Some standard macros. */ - -#define eq(a,b) (!strcmp((a), (b))) -#define isalphanum(c) (isalpha(c) || isdigit(c)) -#define alloc(strname) ((struct strname *) tmalloc(sizeof(struct strname))) -#define tfree(ptr) { if (ptr) free((char *) ptr); ptr = 0; } -#define hexnum(c) ((((c) >= '0') && ((c) <= '9')) ? ((c) - '0') : ((((c) >= \ - 'a') && ((c) <= 'f')) ? ((c) - 'a' + 10) : ((((c) >= 'A') && \ - ((c) <= 'F')) ? ((c) - 'A' + 10) : 0))) - -#ifndef BSD -#define random rand -#define srandom srand -#endif BSD - -#ifdef VMS - -#define EXIT_NORMAL 1 -#define EXIT_BAD 0 - -#else VMS - -#define EXIT_NORMAL 0 -#define EXIT_BAD 1 - -#endif VMS - diff --git a/gnu/games/chess/Xchess/valid.c b/gnu/games/chess/Xchess/valid.c deleted file mode 100644 index 06d1f29..0000000 --- a/gnu/games/chess/Xchess/valid.c +++ /dev/null @@ -1,264 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/valid.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - * Validate a move. - */ - -#include "xchess.h" - -extern bool ischeck(), couldmove(); - -bool -valid_move(m, b) - move *m; - board *b; -{ - board tb; - - /* First check that the piece can make the move at all... */ - if (!couldmove(m, b)) - return (false); - - /* Now see if the king is in check now. */ - bcopy((char *) b, (char *) &tb, sizeof (board)); - board_move(&tb, m); - if (ischeck(&tb, m->piece.color)) - return (false); - - if (ischeck(&tb, ((m->piece.color == WHITE) ? BLACK : WHITE))) - m->check = true; - - return (true); -} - -static bool -couldmove(m, b) - move *m; - board *b; -{ - int x, y; - - switch (m->type) { - case KCASTLE: - if ((m->piece.color == WHITE) && (b->white_cant_castle_k) || - (m->piece.color == BLACK) && - (b->black_cant_castle_k)) - return (false); - if ((b->square[m->fromy][5].color != NONE) || - (b->square[m->fromy][6].color != NONE)) - return (false); - if (ischeck(b, m->piece.color)) - return (false); - break; - - case QCASTLE: - if ((m->piece.color == WHITE) && (b->white_cant_castle_q) || - (m->piece.color == BLACK) && - (b->black_cant_castle_q)) - return (false); - if ((b->square[m->fromy][1].color != NONE) || - (b->square[m->fromy][2].color != NONE) || - (b->square[m->fromy][3].color != NONE)) - return (false); - if (ischeck(b, m->piece.color)) - return (false); - break; - - case MOVE: - case CAPTURE: - /* There is one special case here, that of taking a pawn - * en passant. In this case we change the move field to - * CAPTURE if it's ok. - */ - switch (m->piece.type) { - case PAWN: - if ((m->type == MOVE) && (m->fromx == m->tox)) { - /* A normal move. */ - if ((m->piece.color == WHITE) && (m->fromy == - m->toy + 1)) - break; - if ((m->piece.color == WHITE) && (m->fromy == - 6) && (m->toy == 4) && - (b->square[5][m->fromx].color - == NONE)) - break; - if ((m->piece.color == BLACK) && (m->fromy == - m->toy - 1)) - break; - if ((m->piece.color == BLACK) && (m->fromy == - 1) && (m->toy == 3) && - (b->square[2][m->fromx].color - == NONE)) - break; - return (false); - } else if (m->type == CAPTURE) { - if ((((m->piece.color == WHITE) && (m->fromy == - m->toy + 1)) || ((m->piece.color == - BLACK) && (m->fromy == m->toy - - 1))) && ((m->fromx == m->tox + 1) || - (m->fromx == m->tox - 1))) - break; - /* Now maybe it's enpassant... We've already - * checked for some of these things in the - * calling routine. - */ - if (m->enpassant) { - if (b->square[(m->piece.color == WHITE) - ? 3 : 4][m->tox].color == - ((m->piece.color == WHITE) ? - BLACK : WHITE)) - break; - } - return (false); - } - return (false); - - case ROOK: - if (m->fromx == m->tox) { - for (y = m->fromy + ((m->fromy > m->toy) ? -1 : - 1); y != m->toy; y += ((m->fromy - > m->toy) ? -1 : 1)) - if (b->square[y][m->tox].color != NONE) - return (false); - break; - } - if (m->fromy == m->toy) { - for (x = m->fromx + ((m->fromx > m->tox) ? -1 : - 1); x != m->tox; x += ((m->fromx - > m->tox) ? -1 : 1)) - if (b->square[m->toy][x].color != NONE) - return (false); - break; - } - return (false); - - case KNIGHT: - x = m->fromx - m->tox; - y = m->fromy - m->toy; - if ((((x == 2) || (x == -2)) && - ((y == 1) || (y == -1))) || - (((x == 1) || (x == -1)) && - ((y == 2) || (y == -2)))) - break; - return (false); - - case BISHOP: - x = m->fromx - m->tox; - y = m->fromy - m->toy; - if ((x != y) && (x != - y)) - return (false); - for (x = m->fromx + ((m->fromx > m->tox) ? -1 : 1), y = - m->fromy + ((m->fromy > m->toy) ? -1 : - 1); x != m->tox; - x += ((m->fromx > m->tox) ? -1 : 1), - y += ((m->fromy > m->toy) ? -1 : 1)) - if (b->square[y][x].color != NONE) - return (false); - break; - - case QUEEN: - if (m->fromx == m->tox) { - for (y = m->fromy + ((m->fromy > m->toy) ? -1 : - 1); y != m->toy; y += ((m->fromy - > m->toy) ? -1 : 1)) - if (b->square[y][m->tox].color != NONE) - return (false); - break; - } - if (m->fromy == m->toy) { - for (x = m->fromx + ((m->fromx > m->tox) ? -1 : - 1); x != m->tox; x += ((m->fromx - > m->tox) ? -1 : 1)) - if (b->square[m->toy][x].color != NONE) - return (false); - break; - } - x = m->fromx - m->tox; - y = m->fromy - m->toy; - if ((x != y) && (x != - y)) - return (false); - for (x = m->fromx + ((m->fromx > m->tox) ? -1 : 1), y = - m->fromy + ((m->fromy > m->toy) ? -1 : - 1); x != m->tox; - x += ((m->fromx > m->tox) ? -1 : 1), - y += ((m->fromy > m->toy) ? -1 : 1)) - if (b->square[y][x].color != NONE) - return (false); - break; - - case KING: - x = m->fromx - m->tox; - y = m->fromy - m->toy; - if ((x >= -1) && (x <= 1) && (y >= -1) && (y <= 1)) - break; - return (false); - } - break; - } - return (true); -} - -/* Say whether either king is in check... If move is non-NULL, say whether he - * in in check after the move takes place. We do this in a rather stupid way. - */ - -static bool -ischeck(b, col) - board *b; - color col; -{ - int x, y, kx, ky; - move ch; - - for (x = 0; x < SIZE; x++) - for (y = 0; y < SIZE; y++) - if ((b->square[y][x].color == col) && - (b->square[y][x].type == KING)) { - kx = x; - ky = y; - } - - for (x = 0; x < SIZE; x++) - for (y = 0; y < SIZE; y++) - if (b->square[y][x].color == ((col == WHITE) ? - BLACK : WHITE)) { - ch.type = CAPTURE; - ch.piece.color = b->square[y][x].color; - ch.piece.type = b->square[y][x].type; - ch.fromx = x; - ch.fromy = y; - ch.tox = kx; - ch.toy = ky; - ch.enpassant = false; - if (couldmove(&ch, b)) - return (true); - } - - return (false); -} - diff --git a/gnu/games/chess/Xchess/window.c b/gnu/games/chess/Xchess/window.c deleted file mode 100644 index c33ef81..0000000 --- a/gnu/games/chess/Xchess/window.c +++ /dev/null @@ -1,952 +0,0 @@ -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/window.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - * - * Deal with the two (or one) windows. - */ - -#include "xchess.h" -#include -#include - -#include "pawn.bitmap" -#include "rook.bitmap" -#include "knight.bitmap" -#include "bishop.bitmap" -#include "queen.bitmap" -#include "king.bitmap" - -#include "pawn_outline.bitmap" -#include "rook_outline.bitmap" -#include "knight_outline.bitmap" -#include "bishop_outline.bitmap" -#include "queen_outline.bitmap" -#include "king_outline.bitmap" - -#include "pawn_mask.bitmap" -#include "rook_mask.bitmap" -#include "knight_mask.bitmap" -#include "bishop_mask.bitmap" -#include "queen_mask.bitmap" -#include "king_mask.bitmap" - -#include "shade.bitmap" - -#include "xchess.cur" -#include "xchess_mask.cur" - -#include "xchess.icon" - -windata *win1, *win2; -bool win_flashmove = false; - -extern bool setup(); -extern void service(), drawgrid(), icon_refresh(); - -bool -win_setup(disp1, disp2) - char *disp1, *disp2; -{ - win1 = alloc(windata); - if (!oneboard) - win2 = alloc(windata); - - if (!setup(disp1, win1) || (!oneboard && !setup(disp2, win2))) - return (false); - - if (blackflag) { - win1->color = BLACK; - win1->flipped = true; - } else - win1->color = WHITE; - win_drawboard(win1); - - if (!oneboard) { - win2->color = BLACK; - win2->flipped = true; - win_drawboard(win2); - } - - return(true); -} - -/* Draw the chess board... */ - -void -win_drawboard(win) - windata *win; -{ - int i, j; - - drawgrid(win); - - /* Now toss on the squares... */ - for (i = 0; i < SIZE; i++) - for (j = 0; j < SIZE; j++) - win_erasepiece(j, i, win->color); - - return; -} - -/* Draw one piece. */ - -void -win_drawpiece(p, y, x, wnum) - piece *p; - int y, x; - color wnum; -{ - char *bits, *maskbits, *outline; - windata *win; - char buf[BSIZE]; - XImage *tmpImage; - Pixmap tmpPM, maskPM; - XGCValues gc; - - if (oneboard || (wnum == win1->color)) - win = win1; - else - win = win2; - - if (win->flipped) { - y = SIZE - y - 1; - x = SIZE - x - 1; - } - - /* - if (debug) - fprintf(stderr, "draw a %s at (%d, %d) on board %d\n", - piecenames[(int) p->type], y, x, wnum); - */ - - if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1); - - switch (p->type) { - case PAWN: - bits = pawn_bits; - maskbits = pawn_mask_bits; - outline = pawn_outline_bits; - break; - - case ROOK: - bits = rook_bits; - maskbits = rook_mask_bits; - outline = rook_outline_bits; - break; - - case KNIGHT: - bits = knight_bits; - maskbits = knight_mask_bits; - outline = knight_outline_bits; - break; - - case BISHOP: - bits = bishop_bits; - maskbits = bishop_mask_bits; - outline = bishop_outline_bits; - break; - - case QUEEN: - bits = queen_bits; - maskbits = queen_mask_bits; - outline = queen_outline_bits; - break; - - case KING: - bits = king_bits; - maskbits = king_mask_bits; - outline = king_outline_bits; - break; - - default: - fprintf(stderr, - "Internal Error: win_drawpiece: bad piece type %d\n", - p->type); - } - - /* There are two things we can do... If this is a black and white - * display, we have to shade the square and use an outline if the piece - * is white. We also have to use a mask... Since we don't want - * to use up too many bitmaps, create the mask bitmap, put the bits, - * and then destroy it. - */ - if (win->bnw && (p->color == WHITE)) - bits = outline; - if (win->bnw && !iswhite(win, x, y)) { - XSetState(win->display, DefaultGC(win->display, 0), - BlackPixel(win->display, 0), - WhitePixel(win->display, 0), GXcopy, AllPlanes); - - tmpPM = XCreateBitmapFromData(win->display, win->boardwin, - shade_bits, SQUARE_WIDTH, SQUARE_HEIGHT); - - XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), - 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, - x * (SQUARE_WIDTH + BORDER_WIDTH), - y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); - - XFreePixmap(win->display, tmpPM); - - XSetFunction(win->display, DefaultGC(win->display, 0), - GXandInverted); - maskPM = XCreateBitmapFromData(win->display, win->boardwin, - maskbits, SQUARE_WIDTH, SQUARE_HEIGHT); - XCopyPlane(win->display, maskPM, win->boardwin, DefaultGC(win->display, 0), - 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, - x * (SQUARE_WIDTH + BORDER_WIDTH), - y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); - XFreePixmap(win->display, maskPM); - - XSetFunction(win->display, DefaultGC(win->display, 0), - GXor); - tmpPM = XCreateBitmapFromData(win->display, win->boardwin, - bits, SQUARE_WIDTH, SQUARE_HEIGHT); - XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), - 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, - x * (SQUARE_WIDTH + BORDER_WIDTH), - y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); - XFreePixmap(win->display, tmpPM); - - XSetFunction(win->display, DefaultGC(win->display, 0), GXcopy); - - } else if (win->bnw){ - XSetState(win->display, DefaultGC(win->display, 0), - BlackPixel(win->display, 0), - WhitePixel(win->display, 0), GXcopy, AllPlanes); - - tmpPM = XCreateBitmapFromData(win->display, win->boardwin, - bits, SQUARE_WIDTH, SQUARE_HEIGHT); - XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), - 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, - x * (SQUARE_WIDTH + BORDER_WIDTH), - y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); - XFreePixmap(win->display, tmpPM); - } else { - XSetState(win->display, DefaultGC(win->display, 0), - ((p->color == WHITE) ? win->whitepiece.pixel : - win->blackpiece.pixel), - (iswhite(win, x, y) ? win->whitesquare.pixel : - win->blacksquare.pixel), - GXcopy, AllPlanes); - tmpPM = XCreateBitmapFromData(win->display, win->boardwin, - bits, SQUARE_WIDTH, SQUARE_HEIGHT); - XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), - 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, - x * (SQUARE_WIDTH + BORDER_WIDTH), - y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); - XFreePixmap(win->display, tmpPM); - } - - if (!record_english) { - gc.foreground = win->textcolor.pixel; - if (iswhite(win, x, y) || win->bnw) - gc.background = win->whitesquare.pixel; - else - gc.background = win->blacksquare.pixel; - - gc.font = win->small->fid; - - XChangeGC(win->display, DefaultGC(win->display, 0), - GCForeground | GCBackground | GCFont, &gc); - - if (!x) { - sprintf(buf, " %d", SIZE - y); - XDrawImageString(win->display, win->boardwin, - DefaultGC(win->display, 0), - 1, (y + 1) * (SQUARE_HEIGHT + - BORDER_WIDTH) - BORDER_WIDTH + - win->small->max_bounds.ascent - 1, buf, 2); - } - if (y == SIZE - 1) { - sprintf(buf, "%c", 'A' + x); - XDrawImageString(win->display, win->boardwin, - DefaultGC(win->display, 0), - x * (SQUARE_WIDTH + BORDER_WIDTH) + 1, - SIZE * (SQUARE_HEIGHT + BORDER_WIDTH) - BORDER_WIDTH + - win->small->max_bounds.ascent - 1, buf, 1); - } - } - return; -} - -void -win_erasepiece(y, x, wnum) - int y, x; - color wnum; -{ - windata *win; - char buf[BSIZE]; - XGCValues gc; - Pixmap tmpPM; - - if (oneboard || (wnum == win1->color)) - win = win1; - else - win = win2; - - if (win->flipped) { - y = SIZE - y - 1; - x = SIZE - x - 1; - } - - /* - if (debug) - fprintf(stderr, "erase square (%d, %d) on board %d\n", y, x, - wnum); - */ - - if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1); - - if (win->bnw && !iswhite(win, x, y)) { - XSetState(win->display, DefaultGC(win->display, 0), - BlackPixel(win->display, 0), - WhitePixel(win->display, 0), GXcopy, AllPlanes); - tmpPM = XCreateBitmapFromData(win->display, win->boardwin, - shade_bits, SQUARE_WIDTH, SQUARE_HEIGHT); - - XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), - 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, - x * (SQUARE_WIDTH + BORDER_WIDTH), - y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); - - XFreePixmap(win->display, tmpPM); - } else { - XSetFillStyle(win->display, DefaultGC(win->display, 0), - FillSolid); - XSetForeground(win->display, DefaultGC(win->display, 0), - iswhite(win, x, y) ? win->whitesquare.pixel : - win->blacksquare.pixel); - XFillRectangle(win->display, win->boardwin, - DefaultGC(win->display, 0), - x * (SQUARE_WIDTH + BORDER_WIDTH), - y * (SQUARE_HEIGHT + BORDER_WIDTH), - SQUARE_WIDTH, SQUARE_HEIGHT); - } - - if (!record_english) { - gc.foreground = win->textcolor.pixel; - if (iswhite(win, x, y) || win->bnw) - gc.background = win->whitesquare.pixel; - else - gc.background = win->blacksquare.pixel; - - gc.font = win->small->fid; - - XChangeGC(win->display, DefaultGC(win->display, 0), - GCForeground | GCBackground | GCFont, &gc); - - if (!x) { - sprintf(buf, " %d", SIZE - y); - XDrawImageString(win->display, win->boardwin, - DefaultGC(win->display, 0), - 1, (y + 1) * (SQUARE_HEIGHT + - BORDER_WIDTH) - BORDER_WIDTH + - win->small->max_bounds.ascent - 1, buf, 2); - } - if (y == SIZE - 1) { - sprintf(buf, "%c", 'A' + x); - XDrawImageString(win->display, win->boardwin, - DefaultGC(win->display, 0), - x * (SQUARE_WIDTH + BORDER_WIDTH) + 1, - SIZE * (SQUARE_HEIGHT + BORDER_WIDTH) - BORDER_WIDTH + - win->small->max_bounds.ascent - 1, buf, 1); - } - } - - - return; -} - -void -win_flash(m, wnum) - move *m; - color wnum; -{ - windata *win; - int sx, sy, ex, ey, i; - - if (oneboard || (wnum == win1->color)) - win = win1; - else - win = win2; - - if (win->flipped) { - sx = SIZE - m->fromx - 1; - sy = SIZE - m->fromy - 1; - ex = SIZE - m->tox - 1; - ey = SIZE - m->toy - 1; - } else { - sx = m->fromx; - sy = m->fromy; - ex = m->tox; - ey = m->toy; - } - sx = sx * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2; - sy = sy * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2; - ex = ex * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2; - ey = ey * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2; - - XSetFunction(win->display, DefaultGC(win->display, 0), GXinvert); - XSetLineAttributes(win->display, DefaultGC(win->display, 0), - 0, LineSolid, 0, 0); - for (i = 0; i < num_flashes * 2; i++) { - XDrawLine(win->display,win->boardwin, - DefaultGC(win->display, 0), - sx, sy, ex, ey); - } - - XSetFunction(win->display, DefaultGC(win->display, 0), GXcopy); - return; -} - -/* Handle input from the players. */ - -void -win_process(quick) - bool quick; -{ - int i, rfd = 0, wfd = 0, xfd = 0; - struct timeval timeout; - - timeout.tv_sec = 0; - timeout.tv_usec = (quick ? 0 : 500000); - - if (XPending(win1->display)) - service(win1); - if (!oneboard) { - if (XPending(win1->display)) - service(win2); - } - - if (oneboard) - rfd = 1 << win1->display->fd; - else - rfd = (1 << win1->display->fd) | (1 << win2->display->fd); - if (!(i = select(32, &rfd, &wfd, &xfd, &timeout))) - return; - if (i == -1) { - perror("select"); - exit(1); - } - if (rfd & (1 << win1->display->fd)) - service(win1); - if (!oneboard && (rfd & (1 << win2->display->fd))) - service(win2); - - return; -} - -static void -service(win) - windata *win; -{ - XEvent ev; - - while(XPending(win->display)) { - XNextEvent(win->display, &ev); - if (TxtFilter(win->display, &ev)) - continue; - - if (ev.xany.window == win->boardwin) { - switch (ev.type) { - case ButtonPress: - button_pressed(&ev, win); - break; - - case ButtonRelease: - button_released(&ev, win); - break; - - case Expose: - /* Redraw... */ - win_redraw(win, &ev); - break; - - case 0: - case NoExpose: - break; - default: - fprintf(stderr, "Bad event type %d\n", ev.type); - exit(1); - } - } else if (ev.xany.window == win->wclockwin) { - switch (ev.type) { - case Expose: - clock_draw(win, WHITE); - break; - - case 0: - case NoExpose: - break; - default: - fprintf(stderr, "Bad event type %d\n", ev.type); - exit(1); - } - } else if (ev.xany.window == win->bclockwin) { - switch (ev.type) { - case Expose: - clock_draw(win, BLACK); - break; - - case 0: - case NoExpose: - break; - default: - fprintf(stderr, "Bad event type %d\n", ev.type); - exit(1); - } - } else if (ev.xany.window == win->jailwin) { - switch (ev.type) { - case Expose: - jail_draw(win); - break; - - case 0: - case NoExpose: - break; - default: - fprintf(stderr, "Bad event type %d\n", ev.type); - exit(1); - } - } else if (ev.xany.window == win->buttonwin) { - switch (ev.type) { - case ButtonPress: - button_service(win, &ev); - break; - - case Expose: - button_draw(win); - break; - - case 0: - case NoExpose: - break; - default: - fprintf(stderr, "Bad event type %d\n", ev.type); - exit(1); - } - } else if (ev.xany.window == win->icon) { - icon_refresh(win); - } else if (ev.xany.window == win->basewin) { - message_send(win, &ev); - } else { - fprintf(stderr, "Internal Error: service: bad win\n"); - fprintf(stderr, "window = %d, event = %d\n", ev.xany.window, - ev.type); - } - } - return; -} - -void -win_redraw(win, event) - windata *win; - XEvent *event; -{ - XExposeEvent *ev = &event->xexpose; - int x1, y1, x2, y2, i, j; - - drawgrid(win); - if (ev) { - x1 = ev->x / (SQUARE_WIDTH + BORDER_WIDTH); - y1 = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH); - x2 = (ev->x + ev->width) / (SQUARE_WIDTH + BORDER_WIDTH); - y2 = (ev->y + ev->height) / (SQUARE_HEIGHT + BORDER_WIDTH); - } else { - x1 = 0; - y1 = 0; - x2 = SIZE - 1; - y2 = SIZE - 1; - } - - if (x1 < 0) x1 = 0; - if (y1 < 0) y1 = 0; - if (x2 < 0) x2 = 0; - if (y2 < 0) y2 = 0; - if (x1 > SIZE - 1) x1 = SIZE - 1; - if (y1 > SIZE - 1) y1 = SIZE - 1; - if (x2 > SIZE - 1) x2 = SIZE - 1; - if (y2 > SIZE - 1) y2 = SIZE - 1; - - if (win->flipped) { - y1 = SIZE - y2 - 1; - y2 = SIZE - y1 - 1; - x1 = SIZE - x2 - 1; - x2 = SIZE - x1 - 1; - } - - for (i = x1; i <= x2; i++) - for (j = y1; j <= y2; j++) { - if (chessboard->square[j][i].color == NONE) - win_erasepiece(j, i, WHITE); - else - win_drawpiece(&chessboard->square[j][i], j, i, - WHITE); - if (!oneboard) { - if (chessboard->square[j][i].color == NONE) - win_erasepiece(j, i, BLACK); - else - win_drawpiece(&chessboard->square[j][i], - j, i, BLACK); - } - } - - return; -} - -static bool -setup(dispname, win) - char *dispname; - windata *win; -{ - char buf[BSIZE], *s; - Pixmap bm, bmask; - Cursor cur; - extern char *program, *recfile; - XSizeHints xsizes; - - - if (!(win->display = XOpenDisplay(dispname))) - return (false); - - - /* Now get boolean defaults... */ - if ((s = XGetDefault(win->display, program, "noisy")) && eq(s, "on")) - noisyflag = true; - if ((s = XGetDefault(win->display, program, "savemoves")) && eq(s, "on")) - saveflag = true; - if ((s = XGetDefault(win->display, program, "algebraic")) && eq(s, "on")) - record_english = false; - if ((s = XGetDefault(win->display, program, "blackandwhite")) && eq(s, "on")) - bnwflag = true; - if ((s = XGetDefault(win->display, program, "quickrestore")) && eq(s, "on")) - quickflag = true; - if ((s = XGetDefault(win->display, program, "flash")) && eq(s, "on")) - win_flashmove = true; - - /* ... numeric variables ... */ - if (s = XGetDefault(win->display, program, "numflashes")) - num_flashes = atoi(s); - if (s = XGetDefault(win->display, program, "flashsize")) - flash_size = atoi(s); - - /* ... and strings. */ - if (s = XGetDefault(win->display, program, "progname")) - progname = s; - if (s = XGetDefault(win->display, program, "proghost")) - proghost = s; - if (s = XGetDefault(win->display, program, "recordfile")) - recfile = s; - if (s = XGetDefault(win->display, program, "blackpiece")) - black_piece_color = s; - if (s = XGetDefault(win->display, program, "whitepiece")) - white_piece_color = s; - if (s = XGetDefault(win->display, program, "blacksquare")) - black_square_color = s; - if (s = XGetDefault(win->display, program, "whitesquare")) - white_square_color = s; - if (s = XGetDefault(win->display, program, "bordercolor")) - border_color = s; - if (s = XGetDefault(win->display, program, "textcolor")) - text_color = s; - if (s = XGetDefault(win->display, program, "textback")) - text_back = s; - if (s = XGetDefault(win->display, program, "errortext")) - error_text = s; - if (s = XGetDefault(win->display, program, "playertext")) - player_text = s; - if (s = XGetDefault(win->display, program, "cursorcolor")) - cursor_color = s; - - if ((DisplayPlanes(win->display, 0) == 1) || bnwflag) - win->bnw = true; - - /* Allocate colors... */ - if (win->bnw) { - win->blackpiece.pixel = BlackPixel (win->display, 0); - win->whitepiece.pixel = WhitePixel (win->display, 0); - win->blacksquare.pixel = BlackPixel (win->display, 0); - win->whitesquare.pixel = WhitePixel (win->display, 0); - win->border.pixel = BlackPixel (win->display, 0); - win->textcolor.pixel = BlackPixel (win->display, 0); - win->textback.pixel = WhitePixel (win->display, 0); - win->playertext.pixel = BlackPixel (win->display, 0); - win->errortext.pixel = BlackPixel (win->display, 0); - win->cursorcolor.pixel = BlackPixel (win->display, 0) ; - } else { - if (!XParseColor(win->display, - DefaultColormap(win->display, 0), - black_piece_color, &win->blackpiece) || - !XParseColor(win->display, - DefaultColormap(win->display, 0), - white_piece_color, &win->whitepiece) || - !XParseColor(win->display, - DefaultColormap(win->display, 0), - black_square_color, &win->blacksquare) || - !XParseColor(win->display, - DefaultColormap(win->display, 0), - white_square_color, &win->whitesquare) || - !XParseColor(win->display, - DefaultColormap(win->display, 0), - border_color, &win->border) || - !XParseColor(win->display, - DefaultColormap(win->display, 0), - text_color, &win->textcolor) || - !XParseColor(win->display, - DefaultColormap(win->display, 0), - text_back, &win->textback) || - !XParseColor(win->display, - DefaultColormap(win->display, 0), - error_text, &win->errortext) || - !XParseColor(win->display, - DefaultColormap(win->display, 0), - player_text, &win->playertext) || - !XParseColor(win->display, - DefaultColormap(win->display, 0), - cursor_color, &win->cursorcolor) || - !XAllocColor(win->display, - DefaultColormap(win->display, 0), - &win->blackpiece) || - !XAllocColor(win->display, - DefaultColormap(win->display, 0), - &win->whitepiece) || - !XAllocColor(win->display, - DefaultColormap(win->display, 0), - &win->blacksquare) || - !XAllocColor(win->display, - DefaultColormap(win->display, 0), - &win->whitesquare) || - !XAllocColor(win->display, - DefaultColormap(win->display, 0), - &win->border) || - !XAllocColor(win->display, - DefaultColormap(win->display, 0), - &win->textcolor) || - !XAllocColor(win->display, - DefaultColormap(win->display, 0), - &win->textback) || - !XAllocColor(win->display, - DefaultColormap(win->display, 0), - &win->errortext) || - !XAllocColor(win->display, - DefaultColormap(win->display, 0), - &win->playertext) || - !XAllocColor(win->display, - DefaultColormap(win->display, 0), - &win->cursorcolor)) - fprintf(stderr, "Can't get colors...\n"); - } - - /* Get fonts... */ - if ((win->small = XLoadQueryFont(win->display,SMALL_FONT)) == - NULL) - fprintf(stderr, "Can't get small font...\n"); - - if ((win->medium = XLoadQueryFont(win->display,MEDIUM_FONT)) - == NULL) - fprintf(stderr, "Can't get medium font...\n"); - - if ((win->large = XLoadQueryFont(win->display,LARGE_FONT)) == - NULL) - fprintf(stderr, "Can't get large font...\n"); - - - /* Create the windows... */ - - win->basewin = - XCreateSimpleWindow(win->display,DefaultRootWindow(win->display), - BASE_XPOS, BASE_YPOS, - BASE_WIDTH, BASE_HEIGHT, 0, - BlackPixel(win->display, 0), - WhitePixel(win->display, 0)); - win->boardwin = XCreateSimpleWindow(win->display,win->basewin, - BOARD_XPOS, BOARD_YPOS, - BOARD_WIDTH, BOARD_HEIGHT, - BORDER_WIDTH, - win->border.pixel, - WhitePixel(win->display, 0)); - win->recwin = XCreateSimpleWindow(win->display,win->basewin, - RECORD_XPOS, RECORD_YPOS, - RECORD_WIDTH, RECORD_HEIGHT, - BORDER_WIDTH, win->border.pixel, - win->textback.pixel); - win->jailwin = XCreateSimpleWindow(win->display,win->basewin, - JAIL_XPOS, JAIL_YPOS, - JAIL_WIDTH, JAIL_HEIGHT, - BORDER_WIDTH, - win->border.pixel, - win->textback.pixel); - win->wclockwin = XCreateSimpleWindow(win->display,win->basewin, - WCLOCK_XPOS, WCLOCK_YPOS, - CLOCK_WIDTH, CLOCK_HEIGHT, - BORDER_WIDTH, win->border.pixel, - win->textback.pixel); - win->bclockwin = XCreateSimpleWindow(win->display,win->basewin, - BCLOCK_XPOS, BCLOCK_YPOS, - CLOCK_WIDTH, CLOCK_HEIGHT, - BORDER_WIDTH, win->border.pixel, - win->textback.pixel); - win->messagewin = XCreateSimpleWindow(win->display,win->basewin, - MESS_XPOS, MESS_YPOS, - MESS_WIDTH, MESS_HEIGHT, - BORDER_WIDTH, win->border.pixel, - win->textback.pixel); - win->buttonwin = XCreateSimpleWindow(win->display,win->basewin, - BUTTON_XPOS, BUTTON_YPOS, - BUTTON_WIDTH, BUTTON_HEIGHT, - BORDER_WIDTH, win->border.pixel, - win->textback.pixel); - - /* Let's define an icon... */ - win->iconpixmap = XCreatePixmapFromBitmapData(win->display, - win->basewin, icon_bits, - icon_width, icon_height, - win->blacksquare.pixel, - win->whitesquare.pixel, - 1); - xsizes.flags = PSize | PMinSize | PPosition; - xsizes.min_width = BASE_WIDTH; - xsizes.min_height = BASE_HEIGHT; - xsizes.x = BASE_XPOS; - xsizes.y = BASE_YPOS; - XSetStandardProperties(win->display, win->basewin, - program, program, win->iconpixmap, - 0, NULL, &xsizes); - - bm = XCreateBitmapFromData(win->display, - win->basewin, xchess_bits, - xchess_width, xchess_height); - bmask = XCreateBitmapFromData(win->display, - win->basewin, xchess_mask_bits, - xchess_width, xchess_height); - cur = XCreatePixmapCursor(win->display, bm, bmask, - &win->cursorcolor, - &WhitePixel(win->display, 0), - xchess_x_hot, xchess_y_hot); - XFreePixmap(win->display, bm); - XFreePixmap(win->display, bmask); - - XDefineCursor(win->display,win->basewin, cur); - - XMapSubwindows(win->display,win->basewin); - XMapRaised(win->display,win->basewin); - - XSelectInput(win->display,win->basewin, KeyPressMask); - XSelectInput(win->display,win->boardwin, - ButtonPressMask | ButtonReleaseMask | ExposureMask); - XSelectInput(win->display,win->recwin, - ButtonReleaseMask | ExposureMask); - XSelectInput(win->display,win->jailwin, ExposureMask); - XSelectInput(win->display,win->wclockwin, ExposureMask); - XSelectInput(win->display,win->bclockwin, ExposureMask); - XSelectInput(win->display,win->messagewin, - ButtonReleaseMask | ExposureMask); - XSelectInput(win->display,win->buttonwin, - ButtonPressMask | ExposureMask); - - message_init(win); - record_init(win); - button_draw(win); - jail_init(win); - clock_init(win, WHITE); - clock_init(win, BLACK); - if (timeunit) { - if (timeunit > 1800) - sprintf(buf, "%d moves every %.2lg hours.\n", - movesperunit, ((double) timeunit) / 3600); - else if (timeunit > 30) - sprintf(buf, "%d moves every %.2lg minutes.\n", - movesperunit, ((double) timeunit) / 60); - else - sprintf(buf, "%d moves every %d seconds.\n", - movesperunit, timeunit); - message_add(win, buf, false); - } - return (true); -} - -static void -drawgrid(win) - windata *win; -{ - int i; - XGCValues gc; - - gc.function = GXcopy; - gc.plane_mask = AllPlanes; - gc.foreground = win->border.pixel; - gc.line_width = 0; - gc.line_style = LineSolid; - - XChangeGC(win->display, - DefaultGC(win->display, 0), - GCFunction | GCPlaneMask | GCForeground | - GCLineWidth | GCLineStyle, &gc); - - /* Draw the lines... horizontal, */ - for (i = 1; i < SIZE; i++) - XDrawLine(win->display, win->boardwin, - DefaultGC(win->display, 0), 0, - i * (SQUARE_WIDTH + BORDER_WIDTH) - - BORDER_WIDTH / 2, - SIZE * (SQUARE_WIDTH + BORDER_WIDTH), - i * (SQUARE_WIDTH + BORDER_WIDTH) - - BORDER_WIDTH / 2); - - /* and vertical... */ - for (i = 1; i < SIZE; i++) - XDrawLine(win->display, win->boardwin, - DefaultGC(win->display, 0), - i * (SQUARE_WIDTH + BORDER_WIDTH) - - BORDER_WIDTH / 2, 0, - i * (SQUARE_WIDTH + BORDER_WIDTH) - - BORDER_WIDTH / 2, - SIZE * (SQUARE_WIDTH + BORDER_WIDTH)); - return; -} - -void -win_restart() -{ - win1->flipped = false; - win_redraw(win1, (XEvent *) NULL); - if (!oneboard) { - win2->flipped = true; - win_redraw(win2, (XEvent *) NULL); - } - return; -} - -static void -icon_refresh(win) - windata *win; -{ - XCopyArea(win->display, win->iconpixmap, win->icon, - DefaultGC(win->display, 0), - 0, 0, icon_width, icon_height, 0, 0); - return; -} - diff --git a/gnu/games/chess/Xchess/xchess.c b/gnu/games/chess/Xchess/xchess.c deleted file mode 100644 index 74d010f..0000000 --- a/gnu/games/chess/Xchess/xchess.c +++ /dev/null @@ -1,205 +0,0 @@ - -/* This file contains code for X-CHESS. - Copyright (C) 1986 Free Software Foundation, Inc. - -This file is part of X-CHESS. - -X-CHESS is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the X-CHESS General Public -License for full details. - -Everyone is granted permission to copy, modify and redistribute -X-CHESS, but only under the conditions described in the -X-CHESS General Public License. A copy of this license is -supposed to have been given to you along with X-CHESS so you -can know your rights and responsibilities. It should be in a -file named COPYING. Among other things, the copyright notice -and this notice must be preserved on all copies. */ - - -/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:09 $ - * $Source: /home/ncvs/src/gnu/games/chess/Xchess/xchess.c,v $ - * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group - * Permission is granted to do anything with this code except sell it - * or remove this message. - */ - -#define USAGE "xchess [ -d ] [ -f recordfile ] [ -r savedfile ] [ -i ]\n\ -\t[ -t moves/timeunit ] [ -c ] [ -p program ] [ -b ] [ -bnw ] [ -s ]\n\ -\t[ -n ] [ -h host ] [ -v ] [ -R ] [ whitedisplay ] [ blackdisplay ]" - -#include -#include "xchess.h" - -bool debug = false; -bool oneboard = false; -bool bnwflag = false; -bool progflag = false; -bool blackflag = false; -bool quickflag = false; - -char *progname = DEF_PROGRAM; -char *proghost = NULL; -char *piecenames[] = { "pawn", "rook", "knight", "bishop", "queen", "king" } ; -char *colornames[] = { "white", "black", "none" } ; -char *movetypenames[] = { "move", "qcastle", "kcastle", "capture" } ; -char *dispname1 = NULL, *dispname2 = NULL; - -char *black_piece_color = BLACK_PIECE_COLOR; -char *white_piece_color = WHITE_PIECE_COLOR; -char *black_square_color = BLACK_SQUARE_COLOR; -char *white_square_color = WHITE_SQUARE_COLOR; -char *border_color = BORDER_COLOR; -char *text_color = TEXT_COLOR; -char *text_back = TEXT_BACK; -char *error_text = ERROR_TEXT; -char *player_text = PLAYER_TEXT; -char *cursor_color = CURSOR_COLOR; - -int num_flashes = NUM_FLASHES; -int flash_size = FLASH_SIZE; -char *program; -char *recfile = NULL; - -#ifdef notdef -/* - * Serves no purpose. - */ -die () { -fprintf(stderr, "child proc changed status?!\n"); -} -#endif - -void -main(ac, av) - char **av; -{ - bool randflag = false; - move *m; - char *s; - - program = av[0]; - -#ifdef notdef - signal(SIGCHLD, die); -#endif - - /* Process args. */ - av++; ac--; - while (ac > 0 && **av == '-') { - if (eq(*av, "-d")) { - debug = true; - } else if (eq(*av, "-f")) { - av++; ac--; - if (*av) - record_file = *av; - else - goto usage; - } else if (eq(*av, "-r")) { - av++; ac--; - if (*av) - recfile = *av; - else - goto usage; - } else if (eq(*av, "-i")) { - record_english = false; - } else if (eq(*av, "-R")) { - randflag = true; - } else if (eq(*av, "-v")) { - win_flashmove = true; - } else if (eq(*av, "-q")) { - quickflag = true; - } else if (eq(*av, "-t")) { - av++; ac--; - if (*av) { - movesperunit = atoi(*av); - if (s = index(*av, '/')) - timeunit = atoi(s + 1) * 60; - else - timeunit = 60; - } else - goto usage; - } else if (eq(*av, "-p")) { - av++; ac--; - if (*av) - progname = *av; - else - goto usage; - } else if (eq(*av, "-h")) { - av++; ac--; - if (*av) - proghost = *av; - else - goto usage; - } else if (eq(*av, "-b")) { - blackflag = true; - } else if (eq(*av, "-c")) { - progflag = true; - } else if (eq(*av, "-bnw")) { - bnwflag = true; - } else if (eq(*av, "-s")) { - saveflag = true; - } else if (eq(*av, "-n")) { - noisyflag = true; - } else - goto usage; - av++; ac--; - } - if (ac > 0) - dispname1 = av[0]; - if (ac > 1) - dispname2 = av[1]; - if (ac > 2) - goto usage; - - if (!dispname2) - oneboard = true; - - srandom(getpid()); - - if (!oneboard && randflag && (random() % 2)) { - s = dispname1; - dispname1 = dispname2; - dispname2 = s; - } - - if (!dispname1) - dispname1 = getenv("DISPLAY"); - - /* Set up the board. */ - board_setup(); - - /* Create the windows. */ - win_setup(dispname1, dispname2); - - board_drawall(); - - /* Start the program if necessary. */ - if (progflag) - if (!program_init(progname)) - exit(1); - - if (recfile) - load_game(recfile); - - /* Go into a loop of prompting players alternately for moves, checking - * them, and updating things. - */ - for (;;) { - win_process(false); - clock_update(); - if (progflag && ((!blackflag && (nexttomove == BLACK)) || - (blackflag && (nexttomove == WHITE)))) { - m = program_get(); - if (m) - prog_move(m); - } - } - -usage: fprintf(stderr, "Usage: %s\n", USAGE); - exit(1); -} - diff --git a/gnu/games/chess/chess.6 b/gnu/games/chess/chess.6 deleted file mode 100644 index bbf0aa4..0000000 --- a/gnu/games/chess/chess.6 +++ /dev/null @@ -1,161 +0,0 @@ -.TH Chess GNU -.SH NAME -Chess \- GNU Chess -.SH SYNOPSIS -.B Chess -[ -.B arg1 arg2 -] -.SH DESCRIPTION -.I Chess -plays a game of chess against the user or it plays against itself. -.PP -.I Chess -has a simple alpha-numeric board display or it can be compiled for -use with the CHESSTOOL program on a SUN workstation. -The program gets its opening moves from the file gnuchess.book which -should be located in the same directory as gnuchess. -To invoke the prgram, type 'gnuchess' or type 'chesstool gnuchess' -on a SUN workstation where 'CHESSTOOL' is installed. -The 'gnuchess' command can be followed by up to 2 command line arguments. -If one argument is given it determines the programs search time in -seconds. If two arguments are given, they will be used to set tournament -time controls with the first argument being the number of moves and the second -being the total clock time in minutes. Thus, entering 'chess 60 5' will set -the clocks for 5 minutes (300 seconds) for the first 60 moves. -If no argument is given the program will prompt the user for level of -play. -For use with CHESSTOOL, see the documentation on that program. -.PP -Once -.I Chess -is invoked, the program will display the board and prompt the user -for a move. To enter a move, use the notation 'e2e4' where the first -letter-number pair indicates the origination square -and the second letter-number pair indicates the destination square. -An alternative is to use the notation 'nf3' where -the first letter indicates the piece type (p,n,b,r,q,k). -To castle, type the origin and destination squares -of the king just as you would do for a regular move, or type -"o-o" for kingside castling and "o-o-o" for queenside. -.SH COMMANDS -.PP -In addition to legal moves, the following commands are available as responses. -.PP -.I beep --- causes the program to beep after each move. -.PP -.I bd --- updates the current board position on the display. -.PP -.I book --- turns off use of the opening library. -.PP -.I both --- causes the computer to play both sides of a chess game. -.PP -.I black --- causes the computer to take the black pieces with the move -and begin searching. -.PP -.I level --- allows the user to set time controls such as -60 moves in 5 minutes etc. In tournament mode, the program will -vary the time it takes for each -move depending on the situation. If easy mode is disabled (using -the 'easy' command), the program -will often respond with its move immediately, saving time on -its clock for use later on. -.PP -.I depth --- allows the user to change the -search depth of the program. The maximum depth is 29 ply. -Normally the depth is set to 29 and the computer terminates -its search based on elapsed time rather than depth. -Using the depth command allows setting depth to say -4 ply and setting response time to a large number such as -9999 seconds. The program will then search until all moves -have been examined to a depth of 4 ply (with extensions up -to 11 additional ply for sequences of checks and captures). -.PP -.I easy --- toggles easy mode (thinking on opponents time) -on and off. The default is easy mode ON. If easy mode is disabled, -the user must enter a 'break' or '^C' to get the programs -attention before entering each move. -.PP -.I edit --- allows the user to set up a board position. -In this mode, the '#' command will clear the board, the 'c' -command will toggle piece color, and the '.' command will exit -setup mode. Pieces are entered by typing a letter (p,n,b,r,q,k) for -the piece followed by the coordinate. For example "pb3" would -place a pawn on square b3. -.PP -.I force --- allows the user to enter moves for both -sides. To get the program to play after a sequence of moves -has been entered use the 'white' or 'black' commands. -.PP -.I get --- retrieves a game from disk. The program will -prompt the user for a file name. -.PP -.I help --- displays a short description of the commands. -.PP -.I hint --- causes the program to supply the user with -its predicted move. -.PP -.I list --- writes the game moves and some statistics -on search depth, nodes, and time to the file 'chess.lst'. -.PP -.I new --- starts a new game. -.PP -.I post --- causes the program to display the principle -variation and the score during the search. A score of -100 is equivalent to a 1 pawn advantage for the computer. -.PP -.I random --- causes the program to randomize its move -selection slightly. -.PP -.I reverse --- causes the board display to be reversed. That -is, the white pieces will now appear at the top of the board. -.PP -.I quit --- exits the game. -.PP -.I save --- saves a game to disk. The program will prompt -the user for a file name. -.PP -.I switch --- causes the program to switch places with -the opponent and begin searching. -.PP -.I undo --- undoes the last move whether it was the computer's -or the human's. You may also type "remove". This is equivalent -to two "undo's" (e.g. retract one move for each side). -.PP -.I white --- causes the computer to take the white pieces -with the move and begin searching. -.SH BUGS -.PP -Pawn promotion to pieces other than a queen is not allowed. -En-Passant does not work properly with CHESSTOOOL. -The transposition table may not work properly in some -positions so the default is to turn this off. -.fi -.SH SEE ALSO -.nf -chesstool(6) -.fi - diff --git a/gnu/games/chess/gnuchess.c b/gnu/games/chess/gnuchess.c deleted file mode 100644 index 20b32c4..0000000 --- a/gnu/games/chess/gnuchess.c +++ /dev/null @@ -1,2307 +0,0 @@ -/* - C source for CHESS - - Revision: 4-25-88 - - Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc. - Copyright (c) 1988 John Stanback - - This file is part of CHESS. - - CHESS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY. No author or distributor - accepts responsibility to anyone for the consequences of using it - or for whether it serves any particular purpose or works at all, - unless he says so in writing. Refer to the CHESS General Public - License for full details. - - Everyone is granted permission to copy, modify and redistribute - CHESS, but only under the conditions described in the - CHESS General Public License. A copy of this license is - supposed to have been given to you along with CHESS so you - can know your rights and responsibilities. It should be in a - file named COPYING. Among other things, the copyright notice - and this notice must be preserved on all copies. -*/ - - -#include -#include - -#ifdef MSDOS -#include -#include -#include -#define ttblsz 4096 -#else -#include -#include -#define ttblsz 16384 -#define huge -#endif MSDOS - -#include "move.h" - -#define neutral 2 -#define white 0 -#define black 1 -#define no_piece 0 -#define pawn 1 -#define knight 2 -#define bishop 3 -#define rook 4 -#define queen 5 -#define king 6 -#define valueP 100 -#define valueN 350 -#define valueB 355 -#define valueR 550 -#define valueQ 1100 -#define valueK 1200 -#define ctlP 0x4000 -#define ctlN 0x2800 -#define ctlB 0x1800 -#define ctlR 0x0400 -#define ctlQ 0x0200 -#define ctlK 0x0100 -#define ctlBQ 0x1200 -#define ctlRQ 0x0600 -#define ctlNN 0x2000 -#define pxx " PNBRQK" -#define qxx " pnbrqk" -#define rxx "12345678" -#define cxx "abcdefgh" -#define check 0x0001 -#define capture 0x0002 -#define draw 0x0004 -#define promote 0x0008 -#define cstlmask 0x0010 -#define epmask 0x0020 -#define exact 0x0040 -#define pwnthrt 0x0080 -#define truescore 0x0001 -#define lowerbound 0x0002 -#define upperbound 0x0004 -#define maxdepth 30 -#define true 1 -#define false 0 -#define absv(x) ((x) < 0 ? -(x) : (x)) -#if (NEWMOVE < 1) -#define taxicab(a,b) (abs(column[a]-column[b]) + abs(row[a]-row[b])) -#endif -struct leaf - { - short f,t,score,reply; - unsigned short flags; - }; -struct GameRec - { - unsigned short gmove; - short score,depth,time,piece,color; - long nodes; - }; -struct TimeControlRec - { - short moves[2]; - long clock[2]; - }; -struct BookEntry - { - struct BookEntry *next; - unsigned short *mv; - }; -struct hashval - { - unsigned long bd; - unsigned short key; - }; -struct hashentry - { - unsigned long hashbd; - unsigned short mv,flags; - short score,depth; - }; - -char mvstr1[5],mvstr2[5]; -struct leaf Tree[2000],*root; -short TrPnt[maxdepth],board[64],color[64]; -short row[64],column[64],locn[8][8],Pindex[64],svalue[64]; -short PieceList[2][16],PieceCnt[2],atak[2][64],PawnCnt[2][8]; -short castld[2],kingmoved[2],mtl[2],pmtl[2],emtl[2],hung[2]; -short c1,c2,*atk1,*atk2,*PC1,*PC2,EnemyKing; -short mate,post,opponent,computer,Sdepth,Awindow,Bwindow,dither; -long ResponseTime,ExtraTime,Level,et,et0,time0,cputimer,ft; -long NodeCnt,evrate,ETnodes,EvalNodes,HashCnt; -short quit,reverse,bothsides,hashflag,InChk,player,force,easy,beep; -short wking,bking,FROMsquare,TOsquare,timeout,Zscore,zwndw,xwndw,slk; -short INCscore; -short HasPawn[2],HasKnight[2],HasBishop[2],HasRook[2],HasQueen[2]; -short ChkFlag[maxdepth],CptrFlag[maxdepth],PawnThreat[maxdepth]; -short Pscore[maxdepth],Tscore[maxdepth],Threat[maxdepth]; -struct GameRec GameList[240]; -short GameCnt,Game50,epsquare,lpost,rcptr,contempt; -short MaxSearchDepth; -struct BookEntry *Book; -struct TimeControlRec TimeControl; -short TCflag,TCmoves,TCminutes,OperatorTime; -short otherside[3]={1,0,2}; -short rank7[3]={6,1,0}; -short map[64]= - {0,1,2,3,4,5,6,7, - 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, - 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27, - 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, - 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47, - 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57, - 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67, - 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77}; -short unmap[120]= - {0,1,2,3,4,5,6,7,-1,-1,-1,-1,-1,-1,-1,-1, - 8,9,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1, - 16,17,18,19,20,21,22,23,-1,-1,-1,-1,-1,-1,-1,-1, - 24,25,26,27,28,29,30,31,-1,-1,-1,-1,-1,-1,-1,-1, - 32,33,34,35,36,37,38,39,-1,-1,-1,-1,-1,-1,-1,-1, - 40,41,42,43,44,45,46,47,-1,-1,-1,-1,-1,-1,-1,-1, - 48,49,50,51,52,53,54,55,-1,-1,-1,-1,-1,-1,-1,-1, - 56,57,58,59,60,61,62,63}; -short Dcode[120]= - {0,1,1,1,1,1,1,1,0,0,0,0,0,0,0x0E,0x0F, - 0x10,0x11,0x12,0,0,0,0,0,0,0,0,0,0,0,0x0F,0x1F, - 0x10,0x21,0x11,0,0,0,0,0,0,0,0,0,0,0x0F,0,0, - 0x10,0,0,0x11,0,0,0,0,0,0,0,0,0x0F,0,0,0, - 0x10,0,0,0,0x11,0,0,0,0,0,0,0x0F,0,0,0,0, - 0x10,0,0,0,0,0x11,0,0,0,0,0x0F,0,0,0,0,0, - 0x10,0,0,0,0,0,0x11,0,0,0x0F,0,0,0,0,0,0, - 0x10,0,0,0,0,0,0,0x11}; -short Stboard[64]= - {rook,knight,bishop,queen,king,bishop,knight,rook, - pawn,pawn,pawn,pawn,pawn,pawn,pawn,pawn, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - pawn,pawn,pawn,pawn,pawn,pawn,pawn,pawn, - rook,knight,bishop,queen,king,bishop,knight,rook}; -short Stcolor[64]= - {white,white,white,white,white,white,white,white, - white,white,white,white,white,white,white,white, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - black,black,black,black,black,black,black,black, - black,black,black,black,black,black,black,black}; -short sweep[7]= {false,false,false,true,true,true,false}; -short Dpwn[3]={4,6,0}; -short Dstart[7]={6,4,8,4,0,0,0}; -short Dstop[7]={7,5,15,7,3,7,7}; -short Dir[16]={1,0x10,-1,-0x10,0x0F,0x11,-0x0F,-0x11, - 0x0E,-0x0E,0x12,-0x12,0x1F,-0x1F,0x21,-0x21}; -short Pdir[34]={0,0x38,0,0,0,0,0,0,0,0,0,0,0,0,0x02,0x35, - 0x38,0x35,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0x02, - 0,0x02}; -short pbit[7]={0,0x01,0x02,0x04,0x08,0x10,0x20}; -unsigned short killr0[maxdepth],killr1[maxdepth],killr2[maxdepth]; -unsigned short killr3[maxdepth],PrVar[maxdepth]; -unsigned short PV,hint,Swag0,Swag1,Swag2,Swag3,Swag4; -unsigned short hashkey; -unsigned long hashbd; -struct hashval hashcode[2][7][64]; -struct hashentry huge *ttable,*ptbl; -unsigned char history[8192]; - -short Mwpawn[64],Mbpawn[64],Mknight[2][64],Mbishop[2][64]; -short Mking[2][64],Kfield[2][64]; -short value[7]={0,valueP,valueN,valueB,valueR,valueQ,valueK}; -short control[7]={0,ctlP,ctlN,ctlB,ctlR,ctlQ,ctlK}; -short PassedPawn0[8]={0,60,80,120,200,360,600,800}; -short PassedPawn1[8]={0,30,40,60,100,180,300,800}; -short PassedPawn2[8]={0,15,25,35,50,90,140,800}; -short PassedPawn3[8]={0,5,10,15,20,30,140,800}; -short ISOLANI[8] = {-12,-16,-20,-24,-24,-20,-16,-12}; -short BACKWARD[8] = {-6,-10,-15,-21,-28,-28,-28,-28}; -short BMBLTY[14] = {-2,0,2,4,6,8,10,12,13,14,15,16,16,16}; -short RMBLTY[14] = {0,2,4,6,8,10,11,12,13,14,14,14,14,14}; -short Kthreat[16] = {0,-8,-20,-36,-52,-68,-80,-80,-80,-80,-80,-80, - -80,-80,-80,-80}; -short KNIGHTPOST,KNIGHTSTRONG,BISHOPSTRONG,KATAK,KBNKsq; -short PEDRNK2B,PWEAKH,PADVNCM,PADVNCI,PAWNSHIELD,PDOUBLED,PBLOK; -short RHOPN,RHOPNX,KHOPN,KHOPNX,KSFTY; -short ATAKD,HUNGP,HUNGX,KCASTLD,KMOVD,XRAY,PINVAL; -short stage,stage2,Zwmtl,Zbmtl,Developed[2],PawnStorm; -short PawnBonus,BishopBonus,RookBonus; -short KingOpening[64]= - { 0, 0, -4,-10,-10, -4, 0, 0, - -4, -4, -8,-12,-12, -8, -4, -4, - -12,-16,-20,-20,-20,-20,-16,-12, - -16,-20,-24,-24,-24,-24,-20,-16, - -16,-20,-24,-24,-24,-24,-20,-16, - -12,-16,-20,-20,-20,-20,-16,-12, - -4, -4, -8,-12,-12, -8, -4, -4, - 0, 0, -4,-10,-10, -4, 0, 0}; -short KingEnding[64]= - { 0, 6,12,18,18,12, 6, 0, - 6,12,18,24,24,18,12, 6, - 12,18,24,30,30,24,18,12, - 18,24,30,36,36,30,24,18, - 18,24,30,36,36,30,24,18, - 12,18,24,30,30,24,18,12, - 6,12,18,24,24,18,12, 6, - 0, 6,12,18,18,12, 6, 0}; -short DyingKing[64]= - { 0, 8,16,24,24,16, 8, 0, - 8,32,40,48,48,40,32, 8, - 16,40,56,64,64,56,40,16, - 24,48,64,72,72,64,48,24, - 24,48,64,72,72,64,48,24, - 16,40,56,64,64,56,40,16, - 8,32,40,48,48,40,32, 8, - 0, 8,16,24,24,16, 8, 0}; -short KBNK[64]= - {99,90,80,70,60,50,40,40, - 90,80,60,50,40,30,20,40, - 80,60,40,30,20,10,30,50, - 70,50,30,10, 0,20,40,60, - 60,40,20, 0,10,30,50,70, - 50,30,10,20,30,40,60,80, - 40,20,30,40,50,60,80,90, - 40,40,50,60,70,80,90,99}; -short pknight[64]= - { 0, 4, 8,10,10, 8, 4, 0, - 4, 8,16,20,20,16, 8, 4, - 8,16,24,28,28,24,16, 8, - 10,20,28,32,32,28,20,10, - 10,20,28,32,32,28,20,10, - 8,16,24,28,28,24,16, 8, - 4, 8,16,20,20,16, 8, 4, - 0, 4, 8,10,10, 8, 4, 0}; -short pbishop[64]= - {14,14,14,14,14,14,14,14, - 14,22,18,18,18,18,22,14, - 14,18,22,22,22,22,18,14, - 14,18,22,22,22,22,18,14, - 14,18,22,22,22,22,18,14, - 14,18,22,22,22,22,18,14, - 14,22,18,18,18,18,22,14, - 14,14,14,14,14,14,14,14}; -short PawnAdvance[64]= - { 0, 0, 0, 0, 0, 0, 0, 0, - 4, 4, 4, 0, 0, 4, 4, 4, - 6, 8, 2,10,10, 2, 8, 6, - 6, 8,12,16,16,12, 8, 6, - 8,12,16,24,24,16,12, 8, - 12,16,24,32,32,24,16,12, - 12,16,24,32,32,24,16,12, - 0, 0, 0, 0, 0, 0, 0, 0}; - - -main(argc,argv) -int argc; char *argv[]; -{ -#ifdef MSDOS - ttable = (struct hashentry huge *)farmalloc(ttblsz * - (unsigned long)sizeof(struct hashentry)); -#else - ttable = (struct hashentry *)malloc(ttblsz * - (unsigned long)sizeof(struct hashentry)); -#endif - Level = 0; TCflag = false; OperatorTime = 0; - if (argc == 2) Level = atoi(argv[1]); - if (argc == 3) - { - TCmoves = atoi(argv[1]); TCminutes = atoi(argv[2]); TCflag = true; - } - Initialize(); - NewGame(); -#if (NEWMOVE > 0) - Initialize_dist(); -#if (NEWMOVE > 1) - Initialize_moves(); -#endif -#endif - while (!(quit)) - { - if (bothsides && !mate) SelectMove(opponent,1); else InputCommand(); - if (!(quit || mate || force)) SelectMove(computer,1); - } - ExitChess(); -} - - - -/* ............ INTERFACE ROUTINES ........................... */ - -int VerifyMove(s,iop,mv) -char s[]; -short iop; -unsigned short *mv; - -/* - Compare the string 's' to the list of legal moves available for the - opponent. If a match is found, make the move on the board. -*/ - -{ -static short pnt,tempb,tempc,tempsf,tempst,cnt; -static struct leaf xnode; -struct leaf *node; - - *mv = 0; - if (iop == 2) - { - UnmakeMove(opponent,&xnode,&tempb,&tempc,&tempsf,&tempst); - return(false); - } - cnt = 0; - MoveList(opponent,2); - pnt = TrPnt[2]; - while (pnt < TrPnt[3]) - { - node = &Tree[pnt++]; - algbr(node->f,node->t,(short) node->flags & cstlmask); - if (strcmp(s,mvstr1) == 0 || strcmp(s,mvstr2) == 0) - { - cnt++; xnode = *node; - } - } - if (cnt == 1) - { - MakeMove(opponent,&xnode,&tempb,&tempc,&tempsf,&tempst); - if (SqAtakd(PieceList[opponent][0],computer)) - { - UnmakeMove(opponent,&xnode,&tempb,&tempc,&tempsf,&tempst); - ShowMessage("Illegal Move!!"); - return(false); - } - else - { - if (iop == 1) return(true); - if (xnode.flags & epmask) UpdateDisplay(0,0,1,0); - else UpdateDisplay(xnode.f,xnode.t,0,xnode.flags & cstlmask); - if (xnode.flags & cstlmask) Game50 = GameCnt; - else if (board[xnode.t] == pawn || (xnode.flags & capture)) - Game50 = GameCnt; - GameList[GameCnt].depth = GameList[GameCnt].score = 0; - GameList[GameCnt].nodes = 0; - ElapsedTime(1); - GameList[GameCnt].time = (short)et; - TimeControl.clock[opponent] -= et; - --TimeControl.moves[opponent]; - *mv = (xnode.f << 8) + xnode.t; - algbr(xnode.f,xnode.t,false); - return(true); - } - } - if (cnt > 1) ShowMessage("Ambiguous Move!"); - return(false); -} - - -NewGame() - -/* - Reset the board and other variables to start a new game. -*/ - -{ -short l,r,c,p; - - mate = quit = reverse = bothsides = post = false; - hashflag = force = PawnStorm = false; - beep = rcptr = easy = true; - lpost = NodeCnt = epsquare = et0 = 0; - dither = 0; - Awindow = 90; - Bwindow = 90; - xwndw = 90; - MaxSearchDepth = 29; - contempt = 0; - GameCnt = -1; Game50 = 0; - Zwmtl = Zbmtl = 0; - Developed[white] = Developed[black] = false; - castld[white] = castld[black] = false; - kingmoved[white] = kingmoved[black] = 0; - PawnThreat[0] = CptrFlag[0] = Threat[0] = false; - Pscore[0] = 12000; Tscore[0] = 12000; - opponent = white; computer = black; - for (r = 0; r < 8; r++) - for (c = 0; c < 8; c++) - { - l = 8*r+c; locn[r][c] = l; - row[l] = r; column[l] = c; - board[l] = Stboard[l]; color[l] = Stcolor[l]; - } - for (c = white; c <= black; c++) - for (p = pawn; p <= king; p++) - for (l = 0; l < 64; l++) - { - hashcode[c][p][l].key = (unsigned short)rand(); - hashcode[c][p][l].bd = ((unsigned long)rand() << 16) + - (unsigned long)rand(); - } - ClrScreen(); - if (TCflag) SetTimeControl(); - else if (Level == 0) SelectLevel(); - UpdateDisplay(0,0,1,0); - InitializeStats(); - time0 = time((long *)0); - ElapsedTime(1); - GetOpenings(); -} - - -algbr(f,t,iscastle) -short f,t,iscastle; -{ - mvstr1[0] = cxx[column[f]]; mvstr1[1] = rxx[row[f]]; - mvstr1[2] = cxx[column[t]]; mvstr1[3] = rxx[row[t]]; - mvstr2[0] = qxx[board[f]]; - mvstr2[1] = mvstr1[2]; mvstr2[2] = mvstr1[3]; - mvstr1[4] = '\0'; mvstr2[3] = '\0'; - if (iscastle) - if (t > f) strcpy(mvstr2,"o-o"); - else strcpy(mvstr2,"o-o-o"); -} - - -/* ............ MOVE GENERATION & SEARCH ROUTINES .............. */ - -SelectMove(side,iop) -short side,iop; - -/* - Select a move by calling function search() at progressively deeper - ply until time is up or a mate or draw is reached. An alpha-beta - window of -90 to +90 points is set around the score returned from the - previous iteration. If Sdepth != 0 then the program has correctly - predicted the opponents move and the search will start at a depth of - Sdepth+1 rather than a depth of 1. -*/ - -{ -static short i,alpha,beta,score,tempb,tempc,tempsf,tempst,xside,rpt; - - timeout = false; - xside = otherside[side]; - if (iop != 2) player = side; - if (TCflag) - { - if (((TimeControl.moves[side] + 3) - OperatorTime) != 0) - ResponseTime = (TimeControl.clock[side]) / - (TimeControl.moves[side] + 3) - - OperatorTime; - else ResponseTime = 0; - ResponseTime += (ResponseTime*TimeControl.moves[side])/(2*TCmoves+1); - } - else ResponseTime = Level; - if (iop == 2) ResponseTime = 999; - if (Sdepth > 0 && root->score > Zscore-zwndw) ResponseTime -= ft; - else if (ResponseTime < 1) ResponseTime = 1; - ExtraTime = 0; - ExaminePosition(); - ScorePosition(side,&score); - ShowSidetomove(); - - if (Sdepth == 0) - { - ZeroTTable(); - SearchStartStuff(side); - for (i = 0; i < 8192; i++) history[i] = 0; - FROMsquare = TOsquare = -1; - PV = 0; - if (iop != 2) hint = 0; - for (i = 0; i < maxdepth; i++) - PrVar[i] = killr0[i] = killr1[i] = killr2[i] = killr3[i] = 0; - alpha = score-90; beta = score+90; - rpt = 0; - TrPnt[1] = 0; root = &Tree[0]; - MoveList(side,1); - for (i = TrPnt[1]; i < TrPnt[2]; i++) pick(i,TrPnt[2]-1); - if (Book != NULL) OpeningBook(); - if (Book != NULL) timeout = true; - NodeCnt = ETnodes = EvalNodes = HashCnt = 0; - Zscore = 0; zwndw = 20; - } - - while (!timeout && Sdepth < MaxSearchDepth) - { - Sdepth++; - ShowDepth(' '); - score = search(side,1,Sdepth,alpha,beta,PrVar,&rpt); - for (i = 1; i <= Sdepth; i++) killr0[i] = PrVar[i]; - if (score < alpha) - { - ShowDepth('-'); - ExtraTime = 10*ResponseTime; - ZeroTTable(); - score = search(side,1,Sdepth,-9000,beta,PrVar,&rpt); - } - if (score > beta && !(root->flags & exact)) - { - ShowDepth('+'); - ExtraTime = 0; - ZeroTTable(); - score = search(side,1,Sdepth,alpha,9000,PrVar,&rpt); - } - score = root->score; - if (!timeout) - for (i = TrPnt[1]+1; i < TrPnt[2]; i++) pick(i,TrPnt[2]-1); - ShowResults(score,PrVar,'.'); - for (i = 1; i <= Sdepth; i++) killr0[i] = PrVar[i]; - if (score > Zscore-zwndw && score > Tree[1].score+250) ExtraTime = 0; - else if (score > Zscore-3*zwndw) ExtraTime = ResponseTime; - else ExtraTime = 3*ResponseTime; - if (root->flags & exact) timeout = true; - if (Tree[1].score < -9000) timeout = true; - if (4*et > 2*ResponseTime + ExtraTime) timeout = true; - if (!timeout) - { - Tscore[0] = score; - if (Zscore == 0) Zscore = score; - else Zscore = (Zscore+score)/2; - } - zwndw = 20+abs(Zscore/12); - beta = score + Bwindow; - if (Zscore < score) alpha = Zscore - Awindow - zwndw; - else alpha = score - Awindow - zwndw; - } - - score = root->score; - if (rpt >= 2 || score < -12000) root->flags |= draw; - if (iop == 2) return(0); - if (Book == NULL) hint = PrVar[2]; - ElapsedTime(1); - - if (score > -9999 && rpt <= 2) - { - MakeMove(side,root,&tempb,&tempc,&tempsf,&tempst); - algbr(root->f,root->t,(short) root->flags & cstlmask); - } - else mvstr1[0] = '\0'; - OutputMove(); - if (score == -9999 || score == 9998) mate = true; - if (mate) hint = 0; - if (root->flags & cstlmask) Game50 = GameCnt; - else if (board[root->t] == pawn || (root->flags & capture)) - Game50 = GameCnt; - GameList[GameCnt].score = score; - GameList[GameCnt].nodes = NodeCnt; - GameList[GameCnt].time = (short)et; - GameList[GameCnt].depth = Sdepth; - if (TCflag) - { - TimeControl.clock[side] -= (et + OperatorTime); - if (--TimeControl.moves[side] == 0) SetTimeControl(); - } - if ((root->flags & draw) && bothsides) quit = true; - if (GameCnt > 238) quit = true; - player = xside; - Sdepth = 0; - fflush(stdin); - return(0); -} - - -OpeningBook() - -/* - Go thru each of the opening lines of play and check for a match with - the current game listing. If a match occurs, generate a random number. - If this number is the largest generated so far then the next move in - this line becomes the current "candidate". After all lines are - checked, the candidate move is put at the top of the Tree[] array and - will be played by the program. Note that the program does not handle - book transpositions. -*/ - -{ -short j,pnt; -unsigned short m,*mp; -unsigned r,r0; -struct BookEntry *p; - - srand((unsigned)time0); - r0 = m = 0; - p = Book; - while (p != NULL) - { - mp = p->mv; - for (j = 0; j <= GameCnt; j++) - if (GameList[j].gmove != *(mp++)) break; - if (j > GameCnt) - if ((r=rand()) > r0) - { - r0 = r; m = *mp; - hint = *(++mp); - } - p = p->next; - } - - for (pnt = TrPnt[1]; pnt < TrPnt[2]; pnt++) - if ((Tree[pnt].f<<8) + Tree[pnt].t == m) Tree[pnt].score = 0; - pick(TrPnt[1],TrPnt[2]-1); - if (Tree[TrPnt[1]].score < 0) Book = NULL; -} - - -#define UpdateSearchStatus \ -{\ - if (post) ShowCurrentMove(pnt,node->f,node->t);\ - if (pnt > TrPnt[1])\ - {\ - d = best-Zscore; e = best-node->score;\ - if (best < alpha) ExtraTime = 10*ResponseTime;\ - else if (d > -zwndw && e > 4*zwndw) ExtraTime = -ResponseTime/3;\ - else if (d > -zwndw) ExtraTime = 0;\ - else if (d > -3*zwndw) ExtraTime = ResponseTime;\ - else if (d > -9*zwndw) ExtraTime = 3*ResponseTime;\ - else ExtraTime = 5*ResponseTime;\ - }\ -} - -int search(side,ply,depth,alpha,beta,bstline,rpt) -short side,ply,depth,alpha,beta,*rpt; -unsigned short bstline[]; - -/* - Perform an alpha-beta search to determine the score for the current - board position. If depth <= 0 only capturing moves, pawn promotions - and responses to check are generated and searched, otherwise all - moves are processed. The search depth is modified for check evasions, - certain re-captures and threats. Extensions may continue for up to 11 - ply beyond the nominal search depth. -*/ - -#define prune (cf && score+node->score < alpha) -#define ReCapture (rcptr && score > alpha && score < beta &&\ - ply > 2 && CptrFlag[ply-1] && CptrFlag[ply-2]) -#define MateThreat (ply < Sdepth+4 && ply > 4 &&\ - ChkFlag[ply-2] && ChkFlag[ply-4] &&\ - ChkFlag[ply-2] != ChkFlag[ply-4]) - -{ -register short j,pnt; -short best,tempb,tempc,tempsf,tempst; -short xside,pbst,d,e,cf,score,rcnt; -unsigned short mv,nxtline[maxdepth]; -struct leaf *node,tmp; - - NodeCnt++; - xside = otherside[side]; - if (depth < 0) depth = 0; - - if (ply <= Sdepth+3) repetition(rpt); else *rpt = 0; - if (*rpt >= 2) return(0); - - score = evaluate(side,xside,ply,alpha,beta); - if (score > 9000) - { - bstline[ply] = 0; - return(score); - } - - if (depth > 0) - { - if (InChk || PawnThreat[ply-1] || ReCapture) ++depth; - } - else - { - if (score >= alpha && - (InChk || PawnThreat[ply-1] || Threat[ply-1])) ++depth; - else if (score <= beta && MateThreat) ++depth; - } - - if (depth > 0 && hashflag && ply > 1) - { - ProbeTTable(side,depth,&alpha,&beta,&score); - bstline[ply] = PV; - bstline[ply+1] = 0; - if (beta == -20000) return(score); - if (alpha > beta) return(alpha); - } - - if (Sdepth == 1) d = 7; else d = 11; - if (ply > Sdepth+d || (depth < 1 && score > beta)) return(score); - - if (ply > 1) - if (depth > 0) MoveList(side,ply); - else CaptureList(side,xside,ply); - - if (TrPnt[ply] == TrPnt[ply+1]) return(score); - - cf = (depth < 1 && ply > Sdepth+1 && !ChkFlag[ply-2] && !slk); - - if (depth > 0) best = -12000; else best = score; - if (best > alpha) alpha = best; - - for (pnt = pbst = TrPnt[ply]; - pnt < TrPnt[ply+1] && best <= beta; - pnt++) - { - if (ply > 1) pick(pnt,TrPnt[ply+1]-1); - node = &Tree[pnt]; - mv = (node->f << 8) + node->t; - nxtline[ply+1] = 0; - - if (prune) break; - if (ply == 1) UpdateSearchStatus; - - if (!(node->flags & exact)) - { - MakeMove(side,node,&tempb,&tempc,&tempsf,&tempst); - CptrFlag[ply] = (node->flags & capture); - PawnThreat[ply] = (node->flags & pwnthrt); - Tscore[ply] = node->score; - PV = node->reply; - node->score = -search(xside,ply+1,depth-1,-beta,-alpha, - nxtline,&rcnt); - if (abs(node->score) > 9000) node->flags |= exact; - else if (rcnt == 1) node->score /= 2; - if (rcnt >= 2 || GameCnt-Game50 > 99 || - (node->score == 9999-ply && !ChkFlag[ply])) - { - node->flags |= draw; node->flags |= exact; - if (side == computer) node->score = contempt; - else node->score = -contempt; - } - node->reply = nxtline[ply+1]; - UnmakeMove(side,node,&tempb,&tempc,&tempsf,&tempst); - } - if (node->score > best && !timeout) - { - if (depth > 0) - if (node->score > alpha && !(node->flags & exact)) - node->score += depth; - best = node->score; pbst = pnt; - if (best > alpha) alpha = best; - for (j = ply+1; nxtline[j] > 0; j++) bstline[j] = nxtline[j]; - bstline[j] = 0; - bstline[ply] = mv; - if (ply == 1) - { - if (best == alpha) - { - tmp = Tree[pnt]; - for (j = pnt-1; j >= 0; j--) Tree[j+1] = Tree[j]; - Tree[0] = tmp; - pbst = 0; - } - if (Sdepth > 2) - if (best > beta) ShowResults(best,bstline,'+'); - else if (best < alpha) ShowResults(best,bstline,'-'); - else ShowResults(best,bstline,'&'); - } - } - if (NodeCnt > ETnodes) ElapsedTime(0); - if (timeout) return(-Tscore[ply-1]); - } - - node = &Tree[pbst]; - mv = (node->f<<8) + node->t; - if (hashflag && ply <= Sdepth && *rpt == 0 && best == alpha) - PutInTTable(side,best,depth,alpha,beta,mv); - if (depth > 0) - { - j = (node->f<<6) + node->t; if (side == black) j |= 0x1000; - if (history[j] < 150) history[j] += 2*depth; - if (node->t != (GameList[GameCnt].gmove & 0xFF)) - if (best <= beta) killr3[ply] = mv; - else if (mv != killr1[ply]) - { - killr2[ply] = killr1[ply]; - killr1[ply] = mv; - } - if (best > 9000) killr0[ply] = mv; else killr0[ply] = 0; - } - return(best); -} - - -evaluate(side,xside,ply,alpha,beta) -short side,xside,ply,alpha,beta; - -/* - Compute an estimate of the score by adding the positional score from - the previous ply to the material difference. If this score falls - inside a window which is 180 points wider than the alpha-beta window - (or within a 50 point window during quiescence search) call - ScorePosition() to determine a score, otherwise return the estimated - score. If one side has only a king and the other either has no pawns - or no pieces then the function ScoreLoneKing() is called. -*/ - -{ -short s,evflag; - - hung[white] = hung[black] = 0; - slk = ((mtl[white] == valueK && (pmtl[black] == 0 || emtl[black] == 0)) || - (mtl[black] == valueK && (pmtl[white] == 0 || emtl[white] == 0))); - s = -Pscore[ply-1] + mtl[side] - mtl[xside]; - s -= INCscore; - - if (slk) evflag = false; - else evflag = - (ply == 1 || ply < Sdepth || - ((ply == Sdepth+1 || ply == Sdepth+2) && - (s > alpha-xwndw && s < beta+xwndw)) || - (ply > Sdepth+2 && s >= alpha-25 && s <= beta+25)); - - if (evflag) - { - EvalNodes++; - ataks(side,atak[side]); - if (atak[side][PieceList[xside][0]] > 0) return(10001-ply); - ataks(xside,atak[xside]); - InChk = (atak[xside][PieceList[side][0]] > 0); - ScorePosition(side,&s); - } - else - { - if (SqAtakd(PieceList[xside][0],side)) return(10001-ply); - InChk = SqAtakd(PieceList[side][0],xside); - if (slk) ScoreLoneKing(side,&s); - } - - Pscore[ply] = s - mtl[side] + mtl[xside]; - if (InChk) ChkFlag[ply-1] = Pindex[TOsquare]; - else ChkFlag[ply-1] = 0; - Threat[ply-1] = (hung[side] > 1 && ply == Sdepth+1); - return(s); -} - - -ProbeTTable(side,depth,alpha,beta,score) -short side,depth,*alpha,*beta,*score; - -/* - Look for the current board position in the transposition table. -*/ - -{ -short hindx; - if (side == white) hashkey |= 1; else hashkey &= 0xFFFE; - hindx = (hashkey & (ttblsz-1)); - ptbl = (ttable + hindx); - if (ptbl->depth >= depth && ptbl->hashbd == hashbd) - { - HashCnt++; - PV = ptbl->mv; - if (ptbl->flags & truescore) - { - *score = ptbl->score; - *beta = -20000; - return(true); - } -/* - else if (ptbl->flags & upperbound) - { - if (ptbl->score < *beta) *beta = ptbl->score+1; - } -*/ - else if (ptbl->flags & lowerbound) - { - if (ptbl->score > *alpha) *alpha = ptbl->score-1; - } - } - return(false); -} - - -PutInTTable(side,score,depth,alpha,beta,mv) -short side,score,depth,alpha,beta; -unsigned short mv; - -/* - Store the current board position in the transposition table. -*/ - -{ -short hindx; - if (side == white) hashkey |= 1; else hashkey &= 0xFFFE; - hindx = (hashkey & (ttblsz-1)); - ptbl = (ttable + hindx); - ptbl->hashbd = hashbd; - ptbl->depth = depth; - ptbl->score = score; - ptbl->mv = mv; - ptbl->flags = 0; - if (score < alpha) ptbl->flags |= upperbound; - else if (score > beta) ptbl->flags |= lowerbound; - else ptbl->flags |= truescore; -} - - -ZeroTTable() -{ -int i; - if (hashflag) - for (i = 0; i < ttblsz; i++) - { - ptbl = (ttable + i); - ptbl->depth = 0; - } -} - - -MoveList(side,ply) -short side,ply; - -/* - Fill the array Tree[] with all available moves for side to play. Array - TrPnt[ply] contains the index into Tree[] of the first move at a ply. -*/ - -{ -register short i; -short xside,f; - - xside = otherside[side]; - if (PV == 0) Swag0 = killr0[ply]; else Swag0 = PV; - Swag1 = killr1[ply]; Swag2 = killr2[ply]; - Swag3 = killr3[ply]; Swag4 = 0; - if (ply > 2) Swag4 = killr1[ply-2]; - TrPnt[ply+1] = TrPnt[ply]; - Dstart[pawn] = Dpwn[side]; Dstop[pawn] = Dstart[pawn] + 1; - for (i = PieceCnt[side]; i >= 0; i--) - GenMoves(ply,PieceList[side][i],side,xside); - if (kingmoved[side] == 0 && !castld[side]) - { - f = PieceList[side][0]; - if (castle(side,f,f+2,0)) - { - LinkMove(ply,f,f+2,xside); - Tree[TrPnt[ply+1]-1].flags |= cstlmask; - } - if (castle(side,f,f-2,0)) - { - LinkMove(ply,f,f-2,xside); - Tree[TrPnt[ply+1]-1].flags |= cstlmask; - } - } -} - -#if (NEWMOVE < 11) -GenMoves(ply,sq,side,xside) -short ply,sq,side,xside; - -/* - Generate moves for a piece. The from square is mapped onto a special - board and offsets (taken from array Dir[]) are added to the mapped - location. The newly generated square is tested to see if it falls off - the board by ANDing the square with 88 HEX. Legal moves are linked - into the tree. -*/ - -{ -register short m,u,d; -short i,m0,piece; - - piece = board[sq]; m0 = map[sq]; - if (sweep[piece]) - for (i = Dstart[piece]; i <= Dstop[piece]; i++) - { - d = Dir[i]; m = m0+d; - while (!(m & 0x88)) - { - u = unmap[m]; - if (color[u] == neutral) - { - LinkMove(ply,sq,u,xside); - m += d; - } - else if (color[u] == xside) - { - LinkMove(ply,sq,u,xside); - break; - } - else break; - } - } - else if (piece == pawn) - { - if (side == white && color[sq+8] == neutral) - { - LinkMove(ply,sq,sq+8,xside); - if (row[sq] == 1) - if (color[sq+16] == neutral) - LinkMove(ply,sq,sq+16,xside); - } - else if (side == black && color[sq-8] == neutral) - { - LinkMove(ply,sq,sq-8,xside); - if (row[sq] == 6) - if (color[sq-16] == neutral) - LinkMove(ply,sq,sq-16,xside); - } - for (i = Dstart[piece]; i <= Dstop[piece]; i++) - if (!((m = m0+Dir[i]) & 0x88)) - { - u = unmap[m]; - if (color[u] == xside || u == epsquare) - LinkMove(ply,sq,u,xside); - } - } - else - { - for (i = Dstart[piece]; i <= Dstop[piece]; i++) - if (!((m = m0+Dir[i]) & 0x88)) - { - u = unmap[m]; - if (color[u] != side) LinkMove(ply,sq,u,xside); - } - } -} -#endif - -LinkMove(ply,f,t,xside) -short ply,f,t,xside; - -/* - Add a move to the tree. Assign a bonus to order the moves - as follows: - 1. Principle variation - 2. Capture of last moved piece - 3. Other captures (major pieces first) - 4. Killer moves - 5. "history" killers -*/ - -{ -register short s,z; -unsigned short mv; -struct leaf *node; - - node = &Tree[TrPnt[ply+1]]; - ++TrPnt[ply+1]; - node->flags = node->reply = 0; - node->f = f; node->t = t; - mv = (f<<8) + t; - s = 0; - if (mv == Swag0) s = 2000; - else if (mv == Swag1) s = 60; - else if (mv == Swag2) s = 50; - else if (mv == Swag3) s = 40; - else if (mv == Swag4) s = 30; - if (color[t] != neutral) - { - node->flags |= capture; - if (t == TOsquare) s += 500; - s += value[board[t]] - board[f]; - } - if (board[f] == pawn) - if (row[t] == 0 || row[t] == 7) - { - node->flags |= promote; - s += 800; - } - else if (row[t] == 1 || row[t] == 6) - { - node->flags |= pwnthrt; - s += 600; - } - else if (t == epsquare) node->flags |= epmask; - z = (f<<6) + t; if (xside == white) z |= 0x1000; - s += history[z]; - node->score = s - 20000; -} - -#if (NEWMOVE < 10) -CaptureList(side,xside,ply) -short side,xside,ply; - -/* - Generate captures and Pawn promotions only. -*/ - -#define LinkCapture\ -{\ - node->f = sq; node->t = u;\ - node->reply = 0;\ - node->flags = capture;\ - node->score = value[board[u]] + svalue[board[u]] - piece;\ - if (piece == pawn && (u < 8 || u > 55))\ - {\ - node->flags |= promote;\ - node->score = valueQ;\ - }\ - ++node;\ - ++TrPnt[ply+1];\ -} - -{ -register short m,u; -short d,sq,i,j,j1,j2,m0,r7,d0,piece,*PL; -struct leaf *node; - - TrPnt[ply+1] = TrPnt[ply]; - node = &Tree[TrPnt[ply]]; - Dstart[pawn] = Dpwn[side]; Dstop[pawn] = Dstart[pawn] + 1; - if (side == white) - { - r7 = 6; d0 = 8; - } - else - { - r7 = 1; d0 = -8; - } - PL = PieceList[side]; - for (i = 0; i <= PieceCnt[side]; i++) - { - sq = PL[i]; - m0 = map[sq]; piece = board[sq]; - j1 = Dstart[piece]; j2 = Dstop[piece]; - if (sweep[piece]) - for (j = j1; j <= j2; j++) - { - d = Dir[j]; m = m0+d; - while (!(m & 0x88)) - { - u = unmap[m]; - if (color[u] == neutral) m += d; - else - { - if (color[u] == xside) LinkCapture; - break; - } - } - } - else - { - for (j = j1; j <= j2; j++) - if (!((m = m0+Dir[j]) & 0x88)) - { - u = unmap[m]; - if (color[u] == xside) LinkCapture; - } - if (piece == pawn && row[sq] == r7) - { - u = sq+d0; - if (color[u] == neutral) LinkCapture; - } - } - } -} -#endif - -int castle(side,kf,kt,iop) -short side,kf,kt,iop; - -/* - Make or Unmake a castling move. -*/ - -{ -short rf,rt,d,t0,xside; - - xside = otherside[side]; - if (kt > kf) - { - rf = kf+3; rt = kt-1; d = 1; - } - else - { - rf = kf-4; rt = kt+1; d = -1; - } - if (iop == 0) - { - if (board[kf] != king || board[rf] != rook || color[rf] != side) - return(false); - if (color[kt] != neutral || color[rt] != neutral) return(false); - if (d == -1 && color[kt+d] != neutral) return(false); - if (SqAtakd(kf,xside)) return(false); - if (SqAtakd(kt,xside)) return(false); - if (SqAtakd(kf+d,xside)) return(false); - } - else - { - if (iop == 1) castld[side] = true; else castld[side] = false; - if (iop == 2) - { - t0 = kt; kt = kf; kf = t0; - t0 = rt; rt = rf; rf = t0; - } - board[kt] = king; color[kt] = side; Pindex[kt] = 0; - board[kf] = no_piece; color[kf] = neutral; - board[rt] = rook; color[rt] = side; Pindex[rt] = Pindex[rf]; - board[rf] = no_piece; color[rf] = neutral; - PieceList[side][Pindex[kt]] = kt; - PieceList[side][Pindex[rt]] = rt; - if (hashflag) - { - UpdateHashbd(side,king,kf,kt); - UpdateHashbd(side,rook,rf,rt); - } - } - return(true); -} - - -EnPassant(xside,f,t,iop) -short xside,f,t,iop; - -/* - Make or unmake an en passant move. -*/ - -{ -short l; - if (t > f) l = t-8; else l = t+8; - if (iop == 1) - { - board[l] = no_piece; color[l] = neutral; - } - else - { - board[l] = pawn; color[l] = xside; - } - InitializeStats(); -} - - -MakeMove(side,node,tempb,tempc,tempsf,tempst) -short side,*tempc,*tempb,*tempsf,*tempst; -struct leaf *node; - -/* - Update Arrays board[], color[], and Pindex[] to reflect the new board - position obtained after making the move pointed to by node. Also - update miscellaneous stuff that changes when a move is made. -*/ - -{ -register short f,t; -short xside,ct,cf; - - xside = otherside[side]; - f = node->f; t = node->t; epsquare = -1; - FROMsquare = f; TOsquare = t; - INCscore = 0; - GameList[++GameCnt].gmove = (f<<8) + t; - if (node->flags & cstlmask) - { - GameList[GameCnt].piece = no_piece; - GameList[GameCnt].color = side; - castle(side,f,t,1); - } - else - { - *tempc = color[t]; *tempb = board[t]; - *tempsf = svalue[f]; *tempst = svalue[t]; - GameList[GameCnt].piece = *tempb; - GameList[GameCnt].color = *tempc; - if (*tempc != neutral) - { - UpdatePieceList(*tempc,t,1); - if (*tempb == pawn) --PawnCnt[*tempc][column[t]]; - if (board[f] == pawn) - { - --PawnCnt[side][column[f]]; - ++PawnCnt[side][column[t]]; - cf = column[f]; ct = column[t]; - if (PawnCnt[side][ct] > 1+PawnCnt[side][cf]) - INCscore -= 15; - else if (PawnCnt[side][ct] < 1+PawnCnt[side][cf]) - INCscore += 15; - else if (ct == 0 || ct == 7 || PawnCnt[side][ct+ct-cf] == 0) - INCscore -= 15; - } - mtl[xside] -= value[*tempb]; - if (*tempb == pawn) pmtl[xside] -= valueP; - if (hashflag) UpdateHashbd(xside,*tempb,-1,t); - INCscore += *tempst; - } - color[t] = color[f]; board[t] = board[f]; svalue[t] = svalue[f]; - Pindex[t] = Pindex[f]; PieceList[side][Pindex[t]] = t; - color[f] = neutral; board[f] = no_piece; - if (board[t] == pawn) - if (t-f == 16) epsquare = f+8; - else if (f-t == 16) epsquare = f-8; - if (node->flags & promote) - { - board[t] = queen; - --PawnCnt[side][column[t]]; - mtl[side] += valueQ - valueP; - pmtl[side] -= valueP; - HasQueen[side] = true; - if (hashflag) - { - UpdateHashbd(side,pawn,f,-1); - UpdateHashbd(side,queen,f,-1); - } - INCscore -= *tempsf; - } - if (board[t] == king) ++kingmoved[side]; - if (node->flags & epmask) EnPassant(xside,f,t,1); - else if (hashflag) UpdateHashbd(side,board[t],f,t); - } -} - - -UnmakeMove(side,node,tempb,tempc,tempsf,tempst) -short side,*tempc,*tempb,*tempsf,*tempst; -struct leaf *node; - -/* - Take back a move. -*/ - -{ -register short f,t; -short xside; - - xside = otherside[side]; - f = node->f; t = node->t; epsquare = -1; - GameCnt--; - if (node->flags & cstlmask) castle(side,f,t,2); - else - { - color[f] = color[t]; board[f] = board[t]; svalue[f] = *tempsf; - Pindex[f] = Pindex[t]; PieceList[side][Pindex[f]] = f; - color[t] = *tempc; board[t] = *tempb; svalue[t] = *tempst; - if (node->flags & promote) - { - board[f] = pawn; - ++PawnCnt[side][column[t]]; - mtl[side] += valueP - valueQ; - pmtl[side] += valueP; - if (hashflag) - { - UpdateHashbd(side,queen,-1,t); - UpdateHashbd(side,pawn,-1,t); - } - } - if (*tempc != neutral) - { - UpdatePieceList(*tempc,t,2); - if (*tempb == pawn) ++PawnCnt[*tempc][column[t]]; - if (board[f] == pawn) - { - --PawnCnt[side][column[t]]; - ++PawnCnt[side][column[f]]; - } - mtl[xside] += value[*tempb]; - if (*tempb == pawn) pmtl[xside] += valueP; - if (hashflag) UpdateHashbd(xside,*tempb,-1,t); - } - if (board[f] == king) --kingmoved[side]; - if (node->flags & epmask) EnPassant(xside,f,t,2); - else if (hashflag) UpdateHashbd(side,board[f],f,t); - } -} - - -UpdateHashbd(side,piece,f,t) -short side,piece,f,t; - -/* - hashbd contains a 32 bit "signature" of the board position. hashkey - contains a 16 bit code used to address the hash table. When a move is - made, XOR'ing the hashcode of moved piece on the from and to squares - with the hashbd and hashkey values keeps things current. -*/ - -{ - if (f >= 0) - { - hashbd ^= hashcode[side][piece][f].bd; - hashkey ^= hashcode[side][piece][f].key; - } - if (t >= 0) - { - hashbd ^= hashcode[side][piece][t].bd; - hashkey ^= hashcode[side][piece][t].key; - } -} - - -UpdatePieceList(side,sq,iop) -short side,sq,iop; - -/* - Update the PieceList and Pindex arrays when a piece is captured or - when a capture is unmade. -*/ - -{ -register short i; - if (iop == 1) - { - PieceCnt[side]--; - for (i = Pindex[sq]; i <= PieceCnt[side]; i++) - { - PieceList[side][i] = PieceList[side][i+1]; - Pindex[PieceList[side][i]] = i; - } - } - else - { - PieceCnt[side]++; - PieceList[side][PieceCnt[side]] = sq; - Pindex[sq] = PieceCnt[side]; - } -} - - -InitializeStats() - -/* - Scan thru the board seeing what's on each square. If a piece is found, - update the variables PieceCnt, PawnCnt, Pindex and PieceList. Also - determine the material for each side and set the hashkey and hashbd - variables to represent the current board position. Array - PieceList[side][indx] contains the location of all the pieces of - either side. Array Pindex[sq] contains the indx into PieceList for a - given square. -*/ - -{ -register short i,sq; - epsquare = -1; - for (i = 0; i < 8; i++) - PawnCnt[white][i] = PawnCnt[black][i] = 0; - mtl[white] = mtl[black] = pmtl[white] = pmtl[black] = 0; - PieceCnt[white] = PieceCnt[black] = 0; - hashbd = hashkey = 0; - for (sq = 0; sq < 64; sq++) - if (color[sq] != neutral) - { - mtl[color[sq]] += value[board[sq]]; - if (board[sq] == pawn) - { - pmtl[color[sq]] += valueP; - ++PawnCnt[color[sq]][column[sq]]; - } - if (board[sq] == king) Pindex[sq] = 0; - else Pindex[sq] = ++PieceCnt[color[sq]]; - PieceList[color[sq]][Pindex[sq]] = sq; - hashbd ^= hashcode[color[sq]][board[sq]][sq].bd; - hashkey ^= hashcode[color[sq]][board[sq]][sq].key; - } -} - - -pick(p1,p2) -short p1,p2; - -/* - Find the best move in the tree between indexes p1 and p2. Swap the - best move into the p1 element. -*/ - -{ -register short p,s; -short p0,s0; -struct leaf temp; - - s0 = Tree[p1].score; p0 = p1; - for (p = p1+1; p <= p2; p++) - if ((s = Tree[p].score) > s0) - { - s0 = s; p0 = p; - } - if (p0 != p1) - { - temp = Tree[p1]; Tree[p1] = Tree[p0]; Tree[p0] = temp; - } -} - - -repetition(cnt) -short *cnt; - -/* - Check for draw by threefold repetition. -*/ - -{ -register short i,c; -short f,t,b[64]; -unsigned short m; - *cnt = c = 0; - if (GameCnt > Game50+3) - { -/* - memset((char *)b,0,64*sizeof(short)); -*/ - for (i = 0; i < 64; b[i++] = 0); - for (i = GameCnt; i > Game50; i--) - { - m = GameList[i].gmove; f = m>>8; t = m & 0xFF; - if (++b[f] == 0) c--; else c++; - if (--b[t] == 0) c--; else c++; - if (c == 0) (*cnt)++; - } - } -} - -#if (NEWMOVE < 3) -int SqAtakd(sq,side) -short sq,side; - -/* - See if any piece with color 'side' ataks sq. First check for pawns - or king, then try other pieces. Array Dcode is used to check for - knight attacks or R,B,Q co-linearity. -*/ - -{ -register short m,d; -short i,m0,m1,loc,piece,*PL; - - m1 = map[sq]; - if (side == white) m = m1-0x0F; else m = m1+0x0F; - if (!(m & 0x88)) - if (board[unmap[m]] == pawn && color[unmap[m]] == side) return(true); - if (side == white) m = m1-0x11; else m = m1+0x11; - if (!(m & 0x88)) - if (board[unmap[m]] == pawn && color[unmap[m]] == side) return(true); - if (distance(sq,PieceList[side][0]) == 1) return(true); - - PL = PieceList[side]; - for (i = 1; i <= PieceCnt[side]; i++) - { - loc = PL[i]; piece = board[loc]; - if (piece == pawn) continue; - m0 = map[loc]; d = Dcode[abs(m1-m0)]; - if (d == 0 || (Pdir[d] & pbit[piece]) == 0) continue; - if (piece == knight) return(true); - else - { - if (m1 < m0) d = -d; - for (m = m0+d; m != m1; m += d) - if (color[unmap[m]] != neutral) break; - if (m == m1) return(true); - } - } - return(false); -} -#endif - -#if (NEWMOVE < 2) -ataks(side,a) -short side,*a; - -/* - Fill array atak[][] with info about ataks to a square. Bits 8-15 - are set if the piece (king..pawn) ataks the square. Bits 0-7 - contain a count of total ataks to the square. -*/ - -{ -register short u,m; -short d,c,j,j1,j2,piece,i,m0,sq,*PL; - -/* - memset((char *)a,0,64*sizeof(short)); -*/ - for (u = 0; u < 64; a[u++] = 0); - Dstart[pawn] = Dpwn[side]; Dstop[pawn] = Dstart[pawn] + 1; - PL = PieceList[side]; - for (i = 0; i <= PieceCnt[side]; i++) - { - sq = PL[i]; - m0 = map[sq]; - piece = board[sq]; - c = control[piece]; j1 = Dstart[piece]; j2 = Dstop[piece]; - if (sweep[piece]) - for (j = j1; j <= j2; j++) - { - d = Dir[j]; m = m0+d; - while (!(m & 0x88)) - { - u = unmap[m]; - a[u] = ++a[u] | c; - if (color[u] == neutral) m += d; - else break; - } - } - else - for (j = j1; j <= j2; j++) - if (!((m = m0+Dir[j]) & 0x88)) - { - u = unmap[m]; - a[u] = ++a[u] | c; - } - } -} -#endif - -/* ............ POSITIONAL EVALUATION ROUTINES ............ */ - -ScorePosition(side,score) -short side,*score; - -/* - Perform normal static evaluation of board position. A score is - generated for each piece and these are summed to get a score for each - side. -*/ - -{ -register short sq,s; -short i,xside,pscore[3]; - - wking = PieceList[white][0]; bking = PieceList[black][0]; - UpdateWeights(); - xside = otherside[side]; - pscore[white] = pscore[black] = 0; - - for (c1 = white; c1 <= black; c1++) - { - c2 = otherside[c1]; - if (c1 == white) EnemyKing = bking; else EnemyKing = wking; - atk1 = atak[c1]; atk2 = atak[c2]; - PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2]; - for (i = 0; i <= PieceCnt[c1]; i++) - { - sq = PieceList[c1][i]; - s = SqValue(sq,side); - pscore[c1] += s; - svalue[sq] = s; - } - } - if (hung[side] > 1) pscore[side] += HUNGX; - if (hung[xside] > 1) pscore[xside] += HUNGX; - - *score = mtl[side] - mtl[xside] + pscore[side] - pscore[xside] + 10; - if (dither) *score += rand() % dither; - - if (*score > 0 && pmtl[side] == 0) - if (emtl[side] < valueR) *score = 0; - else if (*score < valueR) *score /= 2; - if (*score < 0 && pmtl[xside] == 0) - if (emtl[xside] < valueR) *score = 0; - else if (-*score < valueR) *score /= 2; - - if (mtl[xside] == valueK && emtl[side] > valueB) *score += 200; - if (mtl[side] == valueK && emtl[xside] > valueB) *score -= 200; -} - - -ScoreLoneKing(side,score) -short side,*score; - -/* - Static evaluation when loser has only a king and winner has no pawns - or no pieces. -*/ - -{ -short winner,loser,king1,king2,s,i; - - UpdateWeights(); - if (mtl[white] > mtl[black]) winner = white; else winner = black; - loser = otherside[winner]; - king1 = PieceList[winner][0]; king2 = PieceList[loser][0]; - - s = 0; - - if (pmtl[winner] > 0) - for (i = 1; i <= PieceCnt[winner]; i++) - s += ScoreKPK(side,winner,loser,king1,king2,PieceList[winner][i]); - - else if (emtl[winner] == valueB+valueN) - s = ScoreKBNK(winner,king1,king2); - - else if (emtl[winner] > valueB) - s = 500 + emtl[winner] - DyingKing[king2] - 2*distance(king1,king2); - - if (side == winner) *score = s; else *score = -s; -} - - -int ScoreKPK(side,winner,loser,king1,king2,sq) -short side,winner,loser,king1,king2,sq; - -/* - Score King and Pawns versus King endings. -*/ - -{ -short s,r; - - if (PieceCnt[winner] == 1) s = 50; else s = 120; - if (winner == white) - { - if (side == loser) r = row[sq]-1; else r = row[sq]; - if (row[king2] >= r && distance(sq,king2) < 8-r) s += 10*row[sq]; - else s = 500+50*row[sq]; - if (row[sq] < 6) sq += 16; else sq += 8; - } - else - { - if (side == loser) r = row[sq]+1; else r = row[sq]; - if (row[king2] <= r && distance(sq,king2) < r+1) s += 10*(7-row[sq]); - else s = 500+50*(7-row[sq]); - if (row[sq] > 1) sq -= 16; else sq -= 8; - } - s += 8*(taxicab(king2,sq) - taxicab(king1,sq)); - return(s); -} - - -int ScoreKBNK(winner,king1,king2) -short winner,king1,king2; - -/* - Score King+Bishop+Knight versus King endings. - This doesn't work all that well but it's better than nothing. -*/ - -{ -short s; - s = emtl[winner] - 300; - if (KBNKsq == 0) s += KBNK[king2]; - else s += KBNK[locn[row[king2]][7-column[king2]]]; - s -= taxicab(king1,king2); - s -= distance(PieceList[winner][1],king2); - s -= distance(PieceList[winner][2],king2); - return(s); -} - - -SqValue(sq,side) -short sq,side; - -/* - Calculate the positional value for the piece on 'sq'. -*/ - -{ -register short j,fyle,rank; -short s,piece,a1,a2,in_square,r,mob,e,c; - - piece = board[sq]; - a1 = (atk1[sq] & 0x4FFF); a2 = (atk2[sq] & 0x4FFF); - rank = row[sq]; fyle = column[sq]; - s = 0; - if (piece == pawn && c1 == white) - { - s = Mwpawn[sq]; - if (sq == 11 || sq == 12) - if (color[sq+8] != neutral) s += PEDRNK2B; - if ((fyle == 0 || PC1[fyle-1] == 0) && - (fyle == 7 || PC1[fyle+1] == 0)) - s += ISOLANI[fyle]; - else if (PC1[fyle] > 1) s += PDOUBLED; - if (a1 < ctlP && atk1[sq+8] < ctlP) - { - s += BACKWARD[a2 & 0xFF]; - if (PC2[fyle] == 0) s += PWEAKH; - if (color[sq+8] != neutral) s += PBLOK; - } - if (PC2[fyle] == 0) - { - if (side == black) r = rank-1; else r = rank; - in_square = (row[bking] >= r && distance(sq,bking) < 8-r); - if (a2 == 0 || side == white) e = 0; else e = 1; - for (j = sq+8; j < 64; j += 8) - if (atk2[j] >= ctlP) { e = 2; break; } - else if (atk2[j] > 0 || color[j] != neutral) e = 1; - if (e == 2) s += (stage*PassedPawn3[rank]) / 10; - else if (in_square || e == 1) s += (stage*PassedPawn2[rank]) / 10; - else if (emtl[black] > 0) s += (stage*PassedPawn1[rank]) / 10; - else s += PassedPawn0[rank]; - } - } - else if (piece == pawn && c1 == black) - { - s = Mbpawn[sq]; - if (sq == 51 || sq == 52) - if (color[sq-8] != neutral) s += PEDRNK2B; - if ((fyle == 0 || PC1[fyle-1] == 0) && - (fyle == 7 || PC1[fyle+1] == 0)) - s += ISOLANI[fyle]; - else if (PC1[fyle] > 1) s += PDOUBLED; - if (a1 < ctlP && atk1[sq-8] < ctlP) - { - s += BACKWARD[a2 & 0xFF]; - if (PC2[fyle] == 0) s += PWEAKH; - if (color[sq-8] != neutral) s += PBLOK; - } - if (PC2[fyle] == 0) - { - if (side == white) r = rank+1; else r = rank; - in_square = (row[wking] <= r && distance(sq,wking) < r+1); - if (a2 == 0 || side == black) e = 0; else e = 1; - for (j = sq-8; j >= 0; j -= 8) - if (atk2[j] >= ctlP) { e = 2; break; } - else if (atk2[j] > 0 || color[j] != neutral) e = 1; - if (e == 2) s += (stage*PassedPawn3[7-rank]) / 10; - else if (in_square || e == 1) s += (stage*PassedPawn2[7-rank]) / 10; - else if (emtl[white] > 0) s += (stage*PassedPawn1[7-rank]) / 10; - else s += PassedPawn0[7-rank]; - } - } - else if (piece == knight) - { - s = Mknight[c1][sq]; - } - else if (piece == bishop) - { - s = Mbishop[c1][sq]; - BRscan(sq,&s,&mob); - s += BMBLTY[mob]; - } - else if (piece == rook) - { - s += RookBonus; - BRscan(sq,&s,&mob); - s += RMBLTY[mob]; - if (PC1[fyle] == 0) s += RHOPN; - if (PC2[fyle] == 0) s += RHOPNX; - if (rank == rank7[c1] && pmtl[c2] > 100) s += 10; - if (stage > 2) s += 14 - taxicab(sq,EnemyKing); - } - else if (piece == queen) - { - if (stage > 2) s += 14 - taxicab(sq,EnemyKing); - if (distance(sq,EnemyKing) < 3) s += 12; - } - else if (piece == king) - { - s = Mking[c1][sq]; - if (KSFTY > 0) - if (Developed[c2] || stage > 0) KingScan(sq,&s); - if (castld[c1]) s += KCASTLD; - else if (kingmoved[c1]) s += KMOVD; - - if (PC1[fyle] == 0) s += KHOPN; - if (PC2[fyle] == 0) s += KHOPNX; - if (fyle == 1 || fyle == 2 || fyle == 3 || fyle == 7) - { - if (PC1[fyle-1] == 0) s += KHOPN; - if (PC2[fyle-1] == 0) s += KHOPNX; - } - if (fyle == 4 || fyle == 5 || fyle == 6 || fyle == 0) - { - if (PC1[fyle+1] == 0) s += KHOPN; - if (PC2[fyle+1] == 0) s += KHOPNX; - } - if (fyle == 2) - { - if (PC1[0] == 0) s += KHOPN; - if (PC2[0] == 0) s += KHOPNX; - } - if (fyle == 5) - { - if (PC1[7] == 0) s += KHOPN; - if (PC2[7] == 0) s += KHOPNX; - } - } - - if (a2 > 0) - { - c = (control[piece] & 0x4FFF); - if (a1 == 0 || a2 > c+1) - { - s += HUNGP; - ++hung[c1]; - if (piece != king && trapped(sq,piece)) ++hung[c1]; - } - else if (piece != pawn || a2 > a1) - if (a2 >= c || a1 < ctlP) s += ATAKD; - } - return(s); -} - -#if (NEWMOVE > 6) -KingScan(sq,s) -short sq,*s; - -/* - Assign penalties if king can be threatened by checks, if squares - near the king are controlled by the enemy (especially the queen), - or if there are no pawns near the king. -*/ - -#define ScoreThreat\ - if (color[u] != c2)\ - if (atk1[u] == 0 || (atk2[u] & 0xFF) > 1) ++cnt;\ - else *s -= 3 - -{ -register short m,u; -short d,i,m0,cnt,ok; - - cnt = 0; - m0 = map[sq]; - if (HasBishop[c2] || HasQueen[c2]) - for (i = Dstart[bishop]; i <= Dstop[bishop]; i++) - { - d = Dir[i]; m = m0+d; - while (!(m & 0x88)) - { - u = unmap[m]; - if (atk2[u] & ctlBQ) ScoreThreat; - if (color[u] != neutral) break; - m += d; - } - } - if (HasRook[c2] || HasQueen[c2]) - for (i = Dstart[rook]; i <= Dstop[rook]; i++) - { - d = Dir[i]; m = m0+d; - while (!(m & 0x88)) - { - u = unmap[m]; - if (atk2[u] & ctlRQ) ScoreThreat; - if (color[u] != neutral) break; - m += d; - } - } - if (HasKnight[c2]) - for (i = Dstart[knight]; i <= Dstop[knight]; i++) - if (!((m = m0+Dir[i]) & 0x88)) - { - u = unmap[m]; - if (atk2[u] & ctlNN) ScoreThreat; - } - *s += (KSFTY*Kthreat[cnt]) / 16; - - cnt = 0; ok = false; - m0 = map[sq]; - for (i = Dstart[king]; i <= Dstop[king]; i++) - if (!((m = m0+Dir[i]) & 0x88)) - { - u = unmap[m]; - if (board[u] == pawn) ok = true; - if (atk2[u] > atk1[u]) - { - ++cnt; - if (atk2[u] & ctlQ) - if (atk2[u] > ctlQ+1 && atk1[u] < ctlQ) *s -= 4*KSFTY; - } - } - if (!ok) *s -= KSFTY; - if (cnt > 1) *s -= KSFTY; -} -#endif - -#if (NEWMOVE < 4) -BRscan(sq,s,mob) -short sq,*s,*mob; - -/* - Find Bishop and Rook mobility, XRAY attacks, and pins. Increment the - hung[] array if a pin is found. -*/ - -{ -register short m,u; -short d,j,m0,piece,pin,*Kf; - - Kf = Kfield[c1]; - *mob = 0; - m0 = map[sq]; piece = board[sq]; - for (j = Dstart[piece]; j <= Dstop[piece]; j++) - { - pin = -1; - d = Dir[j]; m = m0+d; - while (!(m & 0x88)) - { - u = unmap[m]; *s += Kf[u]; - if (color[u] == neutral) - { - (*mob)++; - m += d; - } - else if (pin < 0) - { - if (board[u] == pawn || board[u] == king) break; - pin = u; - m += d; - } - else if (color[u] == c2 && (board[u] > piece || atk2[u] == 0)) - { - if (color[pin] == c2) - { - *s += PINVAL; - if (atk2[pin] == 0 || - atk1[pin] > control[board[pin]]+1) - ++hung[c2]; - } - else *s += XRAY; - break; - } - else break; - } - } -} -#endif - -#if (NEWMOVE > 5) -int trapped(sq,piece) -short sq,piece; - -/* - See if the attacked piece has unattacked squares to move to. -*/ - -{ -register short u,m,d; -short i,m0; - - m0 = map[sq]; - if (sweep[piece]) - for (i = Dstart[piece]; i <= Dstop[piece]; i++) - { - d = Dir[i]; m = m0+d; - while (!(m & 0x88)) - { - u = unmap[m]; - if (color[u] == c1) break; - if (atk2[u] == 0 || board[u] >= piece) return(false); - if (color[u] == c2) break; - m += d; - } - } - else if (piece == pawn) - { - if (c1 == white) u = sq+8; else u = sq-8; - if (color[u] == neutral && atk1[u] >= atk2[u]) - return(false); - if (!((m = m0+Dir[Dpwn[c1]]) & 0x88)) - if (color[unmap[m]] == c2) return(false); - if (!((m = m0+Dir[Dpwn[c1]+1]) & 0x88)) - if (color[unmap[m]] == c2) return(false); - } - else - { - for (i = Dstart[piece]; i <= Dstop[piece]; i++) - if (!((m = m0+Dir[i]) & 0x88)) - { - u = unmap[m]; - if (color[u] != c1) - if (atk2[u] == 0 || board[u] >= piece) return(false); - } - } - return(true); -} -#endif - -ExaminePosition() - -/* - This is done one time before the search is started. Set up arrays - Mwpawn, Mbpawn, Mknight, Mbishop, Mking which are used in the - SqValue() function to determine the positional value of each piece. -*/ - -{ -register short i,sq; -short wpadv,bpadv,wstrong,bstrong,z,side,pp,j,val,Pd,fyle,rank; - - wking = PieceList[white][0]; bking = PieceList[black][0]; - ataks(white,atak[white]); ataks(black,atak[black]); - Zwmtl = Zbmtl = 0; - UpdateWeights(); - HasPawn[white] = HasPawn[black] = 0; - HasKnight[white] = HasKnight[black] = 0; - HasBishop[white] = HasBishop[black] = 0; - HasRook[white] = HasRook[black] = 0; - HasQueen[white] = HasQueen[black] = 0; - for (side = white; side <= black; side++) - for (i = 0; i <= PieceCnt[side]; i++) - switch (board[PieceList[side][i]]) - { - case pawn : ++HasPawn[side]; break; - case knight : ++HasKnight[side]; break; - case bishop : ++HasBishop[side]; break; - case rook : ++HasRook[side]; break; - case queen : ++HasQueen[side]; break; - } - if (!Developed[white]) - Developed[white] = (board[1] != knight && board[2] != bishop && - board[5] != bishop && board[6] != knight); - if (!Developed[black]) - Developed[black] = (board[57] != knight && board[58] != bishop && - board[61] != bishop && board[62] != knight); - if (!PawnStorm && stage < 5) - PawnStorm = ((column[wking] < 3 && column[bking] > 4) || - (column[wking] > 4 && column[bking] < 3)); - - CopyBoard(pknight,Mknight[white]); - CopyBoard(pknight,Mknight[black]); - CopyBoard(pbishop,Mbishop[white]); - CopyBoard(pbishop,Mbishop[black]); - BlendBoard(KingOpening,KingEnding,Mking[white]); - BlendBoard(KingOpening,KingEnding,Mking[black]); - - for (sq = 0; sq < 64; sq++) - { - fyle = column[sq]; rank = row[sq]; - wstrong = bstrong = true; - for (i = sq; i < 64; i += 8) - if (atak[black][i] >= ctlP) wstrong = false; - for (i = sq; i >= 0; i -= 8) - if (atak[white][i] >= ctlP) bstrong = false; - wpadv = bpadv = PADVNCM; - if ((fyle == 0 || PawnCnt[white][fyle-1] == 0) && - (fyle == 7 || PawnCnt[white][fyle+1] == 0)) wpadv = PADVNCI; - if ((fyle == 0 || PawnCnt[black][fyle-1] == 0) && - (fyle == 7 || PawnCnt[black][fyle+1] == 0)) bpadv = PADVNCI; - Mwpawn[sq] = (wpadv*PawnAdvance[sq]) / 10; - Mbpawn[sq] = (bpadv*PawnAdvance[63-sq]) / 10; - Mwpawn[sq] += PawnBonus; Mbpawn[sq] += PawnBonus; - if (castld[white] || kingmoved[white]) - { - if ((fyle < 3 || fyle > 4) && distance(sq,wking) < 3) - Mwpawn[sq] += PAWNSHIELD; - } - else if (rank < 3 && (fyle < 2 || fyle > 5)) - Mwpawn[sq] += PAWNSHIELD / 2; - if (castld[black] || kingmoved[black]) - { - if ((fyle < 3 || fyle > 4) && distance(sq,bking) < 3) - Mbpawn[sq] += PAWNSHIELD; - } - else if (rank > 4 && (fyle < 2 || fyle > 5)) - Mbpawn[sq] += PAWNSHIELD / 2; - if (PawnStorm) - { - if ((column[wking] < 4 && fyle > 4) || - (column[wking] > 3 && fyle < 3)) Mwpawn[sq] += 3*rank - 21; - if ((column[bking] < 4 && fyle > 4) || - (column[bking] > 3 && fyle < 3)) Mbpawn[sq] -= 3*rank; - } - - Mknight[white][sq] += 5 - distance(sq,bking); - Mknight[white][sq] += 5 - distance(sq,wking); - Mknight[black][sq] += 5 - distance(sq,wking); - Mknight[black][sq] += 5 - distance(sq,bking); - Mbishop[white][sq] += BishopBonus; - Mbishop[black][sq] += BishopBonus; - for (i = 0; i <= PieceCnt[black]; i++) - if (distance(sq,PieceList[black][i]) < 3) - Mknight[white][sq] += KNIGHTPOST; - for (i = 0; i <= PieceCnt[white]; i++) - if (distance(sq,PieceList[white][i]) < 3) - Mknight[black][sq] += KNIGHTPOST; - if (wstrong) Mknight[white][sq] += KNIGHTSTRONG; - if (bstrong) Mknight[black][sq] += KNIGHTSTRONG; - if (wstrong) Mbishop[white][sq] += BISHOPSTRONG; - if (bstrong) Mbishop[black][sq] += BISHOPSTRONG; - - if (HasBishop[white] == 2) Mbishop[white][sq] += 8; - if (HasBishop[black] == 2) Mbishop[black][sq] += 8; - if (HasKnight[white] == 2) Mknight[white][sq] += 5; - if (HasKnight[black] == 2) Mknight[black][sq] += 5; - - if (board[sq] == bishop) - if (rank % 2 == fyle % 2) KBNKsq = 0; else KBNKsq = 7; - - Kfield[white][sq] = Kfield[black][sq] = 0; - if (distance(sq,wking) == 1) Kfield[black][sq] = KATAK; - if (distance(sq,bking) == 1) Kfield[white][sq] = KATAK; - - Pd = 0; - for (i = 0; i < 64; i++) - if (board[i] == pawn) - { - if (color[i] == white) - { - pp = true; - if (row[i] == 6) z = i+8; else z = i+16; - for (j = i+8; j < 64; j += 8) - if (atak[black][j] > ctlP || board[j] == pawn) pp = false; - } - else - { - pp = true; - if (row[i] == 1) z = i-8; else z = i-16; - for (j = i-8; j >= 0; j -= 8) - if (atak[white][j] > ctlP || board[j] == pawn) pp = false; - } - if (pp) Pd += 5*taxicab(sq,z); else Pd += taxicab(sq,z); - } - if (Pd != 0) - { - val = (Pd*stage2) / 10; - Mking[white][sq] -= val; - Mking[black][sq] -= val; - } - } -} - - -UpdateWeights() - -/* - If material balance has changed, determine the values for the - positional evaluation terms. -*/ - -{ -short tmtl; - - if (mtl[white] != Zwmtl || mtl[black] != Zbmtl) - { - Zwmtl = mtl[white]; Zbmtl = mtl[black]; - emtl[white] = Zwmtl - pmtl[white] - valueK; - emtl[black] = Zbmtl - pmtl[black] - valueK; - tmtl = emtl[white] + emtl[black]; - if (tmtl > 6600) stage = 0; - else if (tmtl < 1400) stage = 10; - else stage = (6600-tmtl) / 520; - if (tmtl > 3600) stage2 = 0; - else if (tmtl < 1400) stage2 = 10; - else stage2 = (3600-tmtl) / 220; - - PEDRNK2B = -15; /* centre pawn on 2nd rank & blocked */ - PBLOK = -4; /* blocked backward pawn */ - PDOUBLED = -14; /* doubled pawn */ - PWEAKH = -4; /* weak pawn on half open file */ - PAWNSHIELD = 10-stage; /* pawn near friendly king */ - PADVNCM = 10; /* advanced pawn multiplier */ - PADVNCI = 7; /* muliplier for isolated pawn */ - PawnBonus = stage; - - KNIGHTPOST = (stage+2)/3; /* knight near enemy pieces */ - KNIGHTSTRONG = (stage+6)/2; /* occupies pawn hole */ - - BISHOPSTRONG = (stage+6)/2; /* occupies pawn hole */ - BishopBonus = 2*stage; - - RHOPN = 10; /* rook on half open file */ - RHOPNX = 4; - RookBonus = 6*stage; - - XRAY = 8; /* Xray attack on piece */ - PINVAL = 10; /* Pin */ - - KHOPN = (3*stage-30) / 2; /* king on half open file */ - KHOPNX = KHOPN / 2; - KCASTLD = 10 - stage; - KMOVD = -40 / (stage+1); /* king moved before castling */ - KATAK = (10-stage) / 2; /* B,R attacks near enemy king */ - if (stage < 8) KSFTY = 16-2*stage; else KSFTY = 0; - - ATAKD = -6; /* defender > attacker */ - HUNGP = -8; /* each hung piece */ - HUNGX = -12; /* extra for >1 hung piece */ - } -} - -#if (NEWMOVE < 1) -int distance(a,b) -short a,b; -{ -register short d1,d2; - - d1 = abs(column[a]-column[b]); - d2 = abs(row[a]-row[b]); - return(d1 > d2 ? d1 : d2); -} -#endif - -BlendBoard(a,b,c) -short a[64],b[64],c[64]; -{ -register int sq; - for (sq = 0; sq < 64; sq++) - c[sq] = (a[sq]*(10-stage) + b[sq]*stage) / 10; -} - - -CopyBoard(a,b) -short a[64],b[64]; -{ -register int sq; - for (sq = 0; sq < 64; sq++) - b[sq] = a[sq]; -} diff --git a/gnu/games/chess/gnuchess.h b/gnu/games/chess/gnuchess.h deleted file mode 100644 index ee6442e..0000000 --- a/gnu/games/chess/gnuchess.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - This file contains code for CHESS. - Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc. - - This file is part of CHESS. - - CHESS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY. No author or distributor - accepts responsibility to anyone for the consequences of using it - or for whether it serves any particular purpose or works at all, - unless he says so in writing. Refer to the CHESS General Public - License for full details. - - Everyone is granted permission to copy, modify and redistribute - CHESS, but only under the conditions described in the - CHESS General Public License. A copy of this license is - supposed to have been given to you along with CHESS so you - can know your rights and responsibilities. It should be in a - file named COPYING. Among other things, the copyright notice - and this notice must be preserved on all copies. -*/ - - -/* Header file for GNU CHESS */ - -#define neutral 2 -#define white 0 -#define black 1 -#define no_piece 0 -#define pawn 1 -#define knight 2 -#define bishop 3 -#define rook 4 -#define queen 5 -#define king 6 -#define pxx " PNBRQK" -#define qxx " pnbrqk" -#define rxx "12345678" -#define cxx "abcdefgh" -#define check 0x0001 -#define capture 0x0002 -#define draw 0x0004 -#define promote 0x0008 -#define cstlmask 0x0010 -#define epmask 0x0020 -#define exact 0x0040 -#define pwnthrt 0x0080 -#define maxdepth 30 -#define true 1 -#define false 0 - -struct leaf - { - short f,t,score,reply; - unsigned short flags; - }; -struct GameRec - { - unsigned short gmove; - short score,depth,time,piece,color; - long nodes; - }; -struct TimeControlRec - { - short moves[2]; - long clock[2]; - }; -struct BookEntry - { - struct BookEntry *next; - unsigned short *mv; - }; - -extern char mvstr1[5],mvstr2[5]; -extern struct leaf Tree[2000],*root; -extern short TrPnt[maxdepth],board[64],color[64]; -extern short row[64],column[64],locn[8][8]; -extern short atak[2][64],PawnCnt[2][8]; -extern short castld[2],kingmoved[2]; -extern short c1,c2,*atk1,*atk2,*PC1,*PC2; -extern short mate,post,opponent,computer,Sdepth,Awindow,Bwindow,dither; -extern long ResponseTime,ExtraTime,Level,et,et0,time0,cputimer,ft; -extern long NodeCnt,evrate,ETnodes,EvalNodes,HashCnt; -extern short quit,reverse,bothsides,hashflag,InChk,player,force,easy,beep,meter; -extern short timeout,xwndw; -extern struct GameRec GameList[240]; -extern short GameCnt,Game50,epsquare,lpost,rcptr,contempt; -extern short MaxSearchDepth; -extern struct BookEntry *Book; -extern struct TimeControlRec TimeControl; -extern short TCflag,TCmoves,TCminutes,OperatorTime; -extern short otherside[3]; -extern short Stboard[64]; -extern short Stcolor[64]; -extern unsigned short hint,PrVar[maxdepth]; - -#define HZ 60 diff --git a/gnu/games/chess/move.c b/gnu/games/chess/move.c deleted file mode 100644 index b4b0d42..0000000 --- a/gnu/games/chess/move.c +++ /dev/null @@ -1,357 +0,0 @@ -/* move generator hes@log-sv.se 890318 - Modified: 890606 NEWMOVE Levels 1-6 for easier debugging */ -#include "move.h" -#include "gnuchess.h" - -short distdata[64][64]; -short taxidata[64][64]; - -void Initialize_dist() { -register short a,b,d,di; - - /* init taxi and dist data */ - for(a=0;a<64;a++) - for(b=0;b<64;b++) { - d = abs(column[a]-column[b]); - di = abs(row[a]-row[b]); - taxidata[a][b] = d + di; - distdata[a][b] = (d > di ? d : di); - }; -} - -#if (NEWMOVE > 1) -struct sqdata posdata[3][8][64][64]; - -static short direc[8][8] = { - 0, 0, 0, 0, 0, 0, 0, 0, /* no_piece = 0 */ - -10,-11, -9, 0, 0, 0, 0, 0, /* wpawn = 1 */ - -21,-19,-12, -8, 21, 19, 12, 8, /* knight = 2 */ - -11, -9, 11, 9, 0, 0, 0, 0, /* bishop = 3 */ - -10, -1, 10, 1, 0, 0, 0, 0, /* rook = 4 */ - -11, -9,-10, -1, 11, 9, 10, 1, /* queen = 5 */ - -11, -9,-10, -1, 11, 9, 10, 1, /* king = 6 */ - 0, 0, 0, 0, 0, 0, 0, 0};/* no_piece = 7 */ - -static short dc[3] = {-1,1,0}; - -static short max_steps [8] = {0,2,1,7,7,7,1,0}; - -static short unmap[120] = { - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1, 0, 1, 2, 3, 4, 5, 6, 7,-1, - -1, 8, 9,10,11,12,13,14,15,-1, - -1,16,17,18,19,20,21,22,23,-1, - -1,24,25,26,27,28,29,30,31,-1, - -1,32,33,34,35,36,37,38,39,-1, - -1,40,41,42,43,44,45,46,47,-1, - -1,48,49,50,51,52,53,54,55,-1, - -1,56,57,58,59,60,61,62,63,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; - -void Initialize_moves() { - short c,ptyp,po,p0,d,di,s; - struct sqdata *p; - short dest[8][8]; - short steps[8]; - short sorted[8]; - - /* init posdata */ - for(c=0;c<3;c++) - for(ptyp=0;ptyp<8;ptyp++) - for(po=0;po<64;po++) - for(p0=0;p0<64;p0++) { - posdata[c][ptyp][po][p0].nextpos = po; - posdata[c][ptyp][po][p0].nextdir = po; - }; - /* dest is a function of dir and step */ - for(c=0;c<2;c++) - for(ptyp=1;ptyp<7;ptyp++) - for(po=21;po<99;po++) - if (unmap[po] >= 0) { - p = posdata[c][ptyp][unmap[po]]; - for(d=0;d<8;d++) { - dest[d][0] = unmap[po]; - if (dc[c]*direc[ptyp][d] != 0) { - p0=po; - for(s=0;s0 && (d>0 || Stboard[unmap[po]] != ptyp))) - break; - else - dest[d][s] = unmap[p0]; - } - } - else s=0; - /* sort dest in number of steps order */ - steps[d] = s; - for(di=d;di>0;di--) - if (steps[sorted[di-1]] < s) - sorted[di] = sorted[di-1]; - else - break; - sorted[di] = d; - } - /* update posdata, pawns have two threads (capture and no capture) */ - p0=unmap[po]; - if (ptyp == pawn) { - for(s=0;s 2) -int SqAtakd(sq,side) -short sq,side; - -/* - See if any piece with color 'side' ataks sq. First check pawns - Then Queen, Bishop, Rook and King and last Knight. -*/ - -{ - register short u; - register struct sqdata *p; - - p = posdata[1-side][pawn][sq]; - u = p[sq].nextdir; /* follow captures thread */ - while (u != sq) { - if (board[u] == pawn && color[u] == side) return(true); - u = p[u].nextdir; - } - /* king capture */ - if (distance(sq,PieceList[side][0]) == 1) return(true); - /* try a queen bishop capture */ - p = posdata[side][bishop][sq]; - u = p[sq].nextpos; - while (u != sq) { - if (color[u] == neutral) { - u = p[u].nextpos; - } - else { - if (color[u] == side && - (board[u] == queen || board[u] == bishop)) - return(true); - u = p[u].nextdir; - } - } - /* try a queen rook capture */ - p = posdata[side][rook][sq]; - u = p[sq].nextpos; - while (u != sq) { - if (color[u] == neutral) { - u = p[u].nextpos; - } - else { - if (color[u] == side && - (board[u] == queen || board[u] == rook)) - return(true); - u = p[u].nextdir; - } - } - /* try a knight capture */ - p = posdata[side][knight][sq]; - u = p[sq].nextpos; - while (u != sq) { - if (color[u] == neutral) { - u = p[u].nextpos; - } - else { - if (color[u] == side && board[u] == knight) return(true); - u = p[u].nextdir; - } - } - return(false); -} -#endif - -#if (NEWMOVE > 3) -BRscan(sq,s,mob) -short sq,*s,*mob; -/* - Find Bishop and Rook mobility, XRAY attacks, and pins. Increment the - hung[] array if a pin is found. -*/ -{ - register short u,piece,pin; - register struct sqdata *p; - short *Kf; - - Kf = Kfield[c1]; - *mob = 0; - piece = board[sq]; - p = posdata[color[sq]][piece][sq]; - u = p[sq].nextpos; - pin = -1; /* start new direction */ - while (u != sq) { - *s += Kf[u]; - if (color[u] == neutral) { - (*mob)++; - if (p[u].nextpos == p[u].nextdir) pin = -1; /* oops new direction */ - u = p[u].nextpos; - } - else if (pin < 0) { - if (board[u] == pawn || board[u] == king) - u = p[u].nextdir; - else { - if (p[u].nextpos != p[u].nextdir) - pin = u; /* not on the edge and on to find a pin */ - u = p[u].nextpos; - } - } - else if (color[u] == c2 && (board[u] > piece || atk2[u] == 0)) - { - if (color[pin] == c2) - { - *s += PINVAL; - if (atk2[pin] == 0 || - atk1[pin] > control[board[pin]]+1) - ++hung[c2]; - } - else *s += XRAY; - pin = -1; /* new direction */ - u = p[u].nextdir; - } - else { - pin = -1; /* new direction */ - u = p[u].nextdir; - } - } -} -#endif - -#if (NEWMOVE >= 5) -CaptureList(side,xside,ply) -short side,xside,ply; -{ - register short u,sq; - register struct sqdata *p; - short i,piece,*PL; - struct leaf *node; - - TrPnt[ply+1] = TrPnt[ply]; - node = &Tree[TrPnt[ply]]; - PL = PieceList[side]; - for (i = 0; i <= PieceCnt[side]; i++) - { - sq = PL[i]; - piece = board[sq]; - p = posdata[side][piece][sq]; - if (piece == pawn) { - u = p[sq].nextdir; /* follow captures thread */ - while (u != sq) { - if (color[u] == xside) { - node->f = sq; node->t = u; - node->flags = capture; - if (u < 8 || u > 55) - { - node->flags |= promote; - node->score = valueQ; - } - else - node->score = value[board[u]] + svalue[board[u]] - piece; - ++node; - ++TrPnt[ply+1]; - } - u = p[u].nextdir; - } - } - else { - u = p[sq].nextpos; - while (u != sq) { - if (color[u] == neutral) - u = p[u].nextpos; - else { - if (color[u] == xside) { - node->f = sq; node->t = u; - node->flags = capture; - node->score = value[board[u]] + svalue[board[u]] - piece; - ++node; - ++TrPnt[ply+1]; - } - u = p[u].nextdir; - } - } - } - } -} -#endif - -#if (NEWMOVE > 5) -GenMoves(ply,sq,side,xside) - short ply,sq,side,xside; - -/* - Generate moves for a piece. The moves are taken from the - precalulated array posdata. If the board is free, next move - is choosen from nextpos else from nextdir. -*/ - -{ - register short u,piece; - register struct sqdata *p; - - piece = board[sq]; - p = posdata[side][piece][sq]; - if (piece == pawn) { - u = p[sq].nextdir; /* follow captures thread */ - while (u != sq) { - if (color[u] == xside) LinkMove(ply,sq,u,xside); - u = p[u].nextdir; - } - u = p[sq].nextpos; /* and follow no captures thread */ - while (u != sq) { - if (color[u] == neutral && (u != sq+16 || color[u-8] == neutral) - && (u != sq-16 || color[u+8] == neutral)) { - LinkMove(ply,sq,u,xside); - } - u = p[u].nextpos; - } - } - else { - u = p[sq].nextpos; - while (u != sq) { - if (color[u] == neutral) { - LinkMove(ply,sq,u,xside); - u = p[u].nextpos; - } - else { - if (color[u] == xside) LinkMove(ply,sq,u,xside); - u = p[u].nextdir; - } - } - } -} -#endif diff --git a/gnu/games/chess/move.h b/gnu/games/chess/move.h deleted file mode 100644 index 3294e4a..0000000 --- a/gnu/games/chess/move.h +++ /dev/null @@ -1,81 +0,0 @@ -/* header file for move generator hes 890318 - Modified: 890510 minor bug fixed in Newataks - 890606 NEWMOVE levels 1-6 */ - -#if (NEWMOVE >= 1) -extern short distdata[64][64]; -extern short taxidata[64][64]; - -#define taxicab(a,b) taxidata[a][b] -#define distance(a,b) distdata[a][b] - -extern void Initialize_dist(); -#endif - -#if (NEWMOVE >= 2) -struct sqdata { - short nextpos; - short nextdir; -}; -extern struct sqdata posdata[3][8][64][64]; - -extern void Initialize_moves(); - -#define ataks(side,a)\ -{\ - register short u,c,sq;\ - register struct sqdata *p;\ - short i,piece,*PL;\ - \ - for (u = 64; u; a[--u] = 0); \ - PL = PieceList[side];\ - for (i = 0; i <= PieceCnt[side]; i++)\ - {\ - sq = PL[i];\ - piece = board[sq];\ - c = control[piece];\ - p = posdata[side][piece][sq];\ - if (piece == pawn) {\ - u = p[sq].nextdir; /* follow captures thread */\ - while (u != sq) {\ - a[u] = ++a[u] | c;\ - u = p[u].nextdir;\ - }\ - }\ - else {\ - u = p[sq].nextpos;\ - while (u != sq) {\ - a[u] = ++a[u] | c;\ - if (color[u] == neutral)\ - u = p[u].nextpos;\ - else\ - u = p[u].nextdir;\ - }\ - }\ - }\ -} -#endif - -#if (NEWMOVE >= 3) -extern short PieceList[2][16]; - -extern int Sqatakd(); -#endif - -#if (NEWMOVE > 3) -extern short Kfield[2][64],PINVAL,control[7],hung[2],XRAY; - -extern BRscan(); -#endif - -#if (NEWMOVE > 4) -#define valueQ 1100 - -extern short PieceCnt[2],value[7],svalue[64]; - -extern CaptureList(); -#endif - -#if (NEWMOVE > 5) -extern GenMoves(); -#endif diff --git a/gnu/games/chess/nondsp.c b/gnu/games/chess/nondsp.c deleted file mode 100644 index bec36d3..0000000 --- a/gnu/games/chess/nondsp.c +++ /dev/null @@ -1,791 +0,0 @@ -/* - UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL interface for Chess - - Revision: 4-25-88 - - Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc. - Copyright (c) 1988 John Stanback - - This file is part of CHESS. - - CHESS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY. No author or distributor - accepts responsibility to anyone for the consequences of using it - or for whether it serves any particular purpose or works at all, - unless he says so in writing. Refer to the CHESS General Public - License for full details. - - Everyone is granted permission to copy, modify and redistribute - CHESS, but only under the conditions described in the - CHESS General Public License. A copy of this license is - supposed to have been given to you along with CHESS so you - can know your rights and responsibilities. It should be in a - file named COPYING. Among other things, the copyright notice - and this notice must be preserved on all copies. -*/ - - -#include -#include -#ifdef MSDOS -#include -#include -#include -#else -#include -#include -#include -struct tms tmbuf1,tmbuf2; -int TerminateSearch(),Die(); -#endif MSDOS - -#include "gnuchess.h" -#ifdef NEWMOVE -#include "move.h" -#endif - -#define printz printf -#define scanz scanf -int mycnt1,mycnt2; - - -Initialize() -{ - mycnt1 = mycnt2 = 0; -#ifndef MSDOS -#endif -#ifdef CHESSTOOL - setlinebuf(stdout); -/* - setvbuf(stdout,NULL,_IOLBF,BUFSIZ); -*/ - printf("Chess\n"); - if (Level == 0 && !TCflag) Level = 15; -#endif CHESSTOOL -} - -ExitChess() -{ - ListGame(); - exit(0); -} - -#ifndef MSDOS -Die() -{ -char s[80]; - printz("Abort? "); - scanz("%s",s); - if (strcmp(s,"yes") == 0) ExitChess(); -} - -TerminateSearch() -{ - timeout = true; - bothsides = false; -} -#endif MSDOS - - -InputCommand() - -/* - Process the users command. If easy mode is OFF (the computer is - thinking on opponents time) and the program is out of book, then make - the 'hint' move on the board and call SelectMove() to find a response. - The user terminates the search by entering ^C (quit siqnal) before - entering a command. If the opponent does not make the hint move, then - set Sdepth to zero. -*/ - -{ -int i; -short ok,tmp; -long cnt,rate,t1,t2; -unsigned short mv; -char s[80]; - - ok = quit = false; - player = opponent; - ft = 0; - if (hint > 0 && !easy && Book == NULL) - { - fflush(stdout); - time0 = time((long *)0); - algbr(hint>>8,hint & 0xFF,false); - strcpy(s,mvstr1); - tmp = epsquare; - if (VerifyMove(s,1,&mv)) - { - SelectMove(computer,2); - VerifyMove(mvstr1,2,&mv); - if (Sdepth > 0) Sdepth--; - } - ft = time((long *)0) - time0; - epsquare = tmp; - } - -#ifndef MSDOS -#endif - while (!(ok || quit)) - { - PromptForMove(); - i = scanz("%s",s); - if (i == EOF || s[0] == 0) ExitChess(); - player = opponent; - ok = VerifyMove(s,0,&mv); - if (ok && mv != hint) - { - Sdepth = 0; - ft = 0; - } - - if (strcmp(s,"bd") == 0) - { - ClrScreen(); - UpdateDisplay(0,0,1,0); - } - if (strcmp(s,"quit") == 0) quit = true; - if (strcmp(s,"post") == 0) post = !post; - if (strcmp(s,"set") == 0) EditBoard(); - if (strcmp(s,"go") == 0) ok = true; - if (strcmp(s,"help") == 0) help(); - if (strcmp(s,"force") == 0) force = !force; - if (strcmp(s,"book") == 0) Book = NULL; - if (strcmp(s,"new") == 0) NewGame(); - if (strcmp(s,"list") == 0) ListGame(); - if (strcmp(s,"level") == 0) SelectLevel(); - if (strcmp(s,"hash") == 0) hashflag = !hashflag; - if (strcmp(s,"beep") == 0) beep = !beep; - if (strcmp(s,"Awindow") == 0) ChangeAlphaWindow(); - if (strcmp(s,"Bwindow") == 0) ChangeBetaWindow(); - if (strcmp(s,"rcptr") == 0) rcptr = !rcptr; - if (strcmp(s,"hint") == 0) GiveHint(); - if (strcmp(s,"zero") == 0) ZeroTTable(); - if (strcmp(s,"both") == 0) - { - bothsides = !bothsides; - Sdepth = 0; - SelectMove(opponent,1); - ok = true; - } - if (strcmp(s,"reverse") == 0) - { - reverse = !reverse; - ClrScreen(); - UpdateDisplay(0,0,1,0); - } - if (strcmp(s,"switch") == 0) - { - computer = otherside[computer]; - opponent = otherside[opponent]; - force = false; - Sdepth = 0; - ok = true; - } - if (strcmp(s,"white") == 0) - { - computer = white; opponent = black; - ok = true; force = false; - Sdepth = 0; - } - if (strcmp(s,"black") == 0) - { - computer = black; opponent = white; - ok = true; force = false; - Sdepth = 0; - } - if (strcmp(s,"undo") == 0 && GameCnt >= 0) Undo(); - if (strcmp(s,"remove") == 0 && GameCnt >= 1) - { - Undo(); Undo(); - } - if (strcmp(s,"get") == 0) GetGame(); - if (strcmp(s,"save") == 0) SaveGame(); - if (strcmp(s,"depth") == 0) ChangeSearchDepth(); - if (strcmp(s,"random") == 0) dither = 6; - if (strcmp(s,"easy") == 0) easy = !easy; - if (strcmp(s,"contempt") == 0) SetContempt(); - if (strcmp(s,"xwndw") == 0) ChangeXwindow(); - if (strcmp(s,"test") == 0) - { - t1 = time(0); - cnt = 0; - for (i = 0; i < 10000; i++) - { - MoveList(opponent,2); - cnt += TrPnt[3] - TrPnt[2]; - } - t2 = time(0); - rate = cnt / (t2-t1); - printz("cnt= %ld rate= %ld\n",cnt,rate); - } - } - - ElapsedTime(1); - if (force) - { - computer = opponent; opponent = otherside[computer]; - } -#ifndef MSDOS - (void) times(&tmbuf1); -#ifdef CHESSTOOL - printf("%d. %s\n",++mycnt2,s); -#endif CHESSTOOL -#endif MSDOS -} - - -help() -{ - ClrScreen(); - printz("CHESS command summary\n"); - printz("g1f3 move from g1 to f3\n"); - printz("nf3 move knight to f3\n"); - printz("o-o castle king side\n"); - printz("o-o-o castle queen side\n"); - printz("set edit board\n"); - printz("switch sides with computer\n"); - printz("white computer plays white\n"); - printz("black computer plays black\n"); - printz("reverse board display\n"); - printz("both computer match\n"); - printz("random randomize play\n"); - printz("undo undo last move\n"); - printz("time change level\n"); - printz("depth set search depth\n"); - printz("post principle variation\n"); - printz("hint suggest a move\n"); - printz("bd redraw board\n"); - printz("clock set time control\n"); - printz("force enter game moves\n"); - printz("list game to chess.lst\n"); - printz("save game to file\n"); - printz("get game from file\n"); - printz("new start new game\n"); - printz("quit exit CHESS\n"); - printz("Computer: "); - if (computer == white) printz("WHITE\n"); else printz("BLACK\n"); - printz("Opponent: "); - if (opponent == white) printz("WHITE\n"); else printz("BLACK\n"); - printz("Response time: %ld",Level," sec.\n"); - printz("Easy mode: "); - if (easy) printz("ON\n"); else printz("OFF\n"); - printz("Depth: %d\n",MaxSearchDepth); - printz("Random: "); - if (dither) printz("ON\n"); else printz("OFF\n"); - printz("Transposition table: "); - if (hashflag) printz("ON\n"); else printz("OFF\n"); - UpdateDisplay(0,0,1,0); -} - - -EditBoard() - -/* - Set up a board position. Pieces are entered by typing the piece - followed by the location. For example, Nf3 will place a knight on - square f3. -*/ - -{ -short a,r,c,sq; -char s[80]; - - ClrScreen(); - UpdateDisplay(0,0,1,0); - printz(". exit to main\n"); - printz("# clear board\n"); - printz("enter piece & location: \n"); - - a = white; - do - { - scanz("%s",s); - if (s[0] == '#') - { - for (sq = 0; sq < 64; sq++) - { - board[sq] = no_piece; color[sq] = neutral; - } - UpdateDisplay(0,0,1,0); - } - if (s[0] == 'c' || s[0] == 'C') a = otherside[a]; - c = s[1]-'a'; r = s[2]-'1'; - if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8)) - { - sq = locn[r][c]; - color[sq] = a; - if (s[0] == 'p') board[sq] = pawn; - else if (s[0] == 'n') board[sq] = knight; - else if (s[0] == 'b') board[sq] = bishop; - else if (s[0] == 'r') board[sq] = rook; - else if (s[0] == 'q') board[sq] = queen; - else if (s[0] == 'k') board[sq] = king; - else { board[sq] = no_piece; color[sq] = neutral; } - } - } - while (s[0] != '.'); - if (board[4] != king) kingmoved[white] = 10; - if (board[60] != king) kingmoved[black] = 10; - GameCnt = -1; Game50 = 0; Sdepth = 0; - InitializeStats(); - ClrScreen(); - UpdateDisplay(0,0,1,0); -} - - -ShowDepth(ch) -char ch; -{ -} - -ShowResults(score,bstline,ch) -short score; -unsigned short bstline[]; -char ch; -{ -#ifndef CHESSTOOL -register int i; - printz("%2d%c %5d %4ld %7ld ",Sdepth,ch,score,et,NodeCnt); - for (i = 1; bstline[i] > 0; i++) - { - algbr((short)(bstline[i] >> 8),(short)(bstline[i] & 0xFF),false); - if (i == 9 || i == 17) printz("\n "); - printz("%5s ",mvstr1); - } - printz("\n"); -#endif -} - - -SearchStartStuff(side) -short side; -{ -#ifndef MSDOS -#endif -#ifndef CHESSTOOL - printz("\nMove# %d Target= %ld Clock: %ld\n", - TCmoves-TimeControl.moves[side]+1, - ResponseTime,TimeControl.clock[side]); -#endif -} - - -OutputMove() -{ -#ifdef CHESSTOOL - printz("%d. ... %s\n",++mycnt1,mvstr1); - if (root->flags & draw) - { - printz("Draw\n"); - ListGame(); - exit(0); - } - if (root->score == -9999) - { - if (opponent == white) printz("White\n"); else printz("Black\n"); - ListGame(); - exit(0); - } - if (root->score == 9998) - { - if (computer == white) printz("White\n"); else printz("Black\n"); - ListGame(); - exit(0); - } -#else - printz("Nodes= %ld Eval= %ld Hash= %ld Rate= %ld ", - NodeCnt,EvalNodes,HashCnt,evrate); - printz("CPU= %.2ld:%.2ld.%.2ld\n\n", - cputimer/6000,(cputimer % 6000)/100,cputimer % 100); - - if (root->flags & epmask) UpdateDisplay(0,0,1,0); - else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask); - printz("My move is: %s\n\n",mvstr1); - if (beep) printz("%c",7); - - if (root->flags & draw) printz("Draw game!\n"); - else if (root->score == -9999) printz("opponent mates!\n"); - else if (root->score == 9998) printz("computer mates!\n"); - else if (root->score < -9000) printz("opponent will soon mate!\n"); - else if (root->score > 9000) printz("computer will soon mate!\n"); -#endif CHESSTOOL -} - - -ElapsedTime(iop) -short iop; - -/* - Determine the time that has passed since the search was started. If - the elapsed time exceeds the target (ResponseTime+ExtraTime) then set - timeout to true which will terminate the search. -*/ - -{ - et = time((long *)0) - time0; - if (et < 0) et = 0; - ETnodes += 50; - if (et > et0 || iop == 1) - { - if (et > ResponseTime+ExtraTime && Sdepth > 1) timeout = true; - et0 = et; - if (iop == 1) - { - time0 = time((long *)0); et0 = 0; - } -#ifdef MSDOS - cputimer = 100*et; - if (et > 0) evrate = NodeCnt/(et+ft); else evrate = 0; - if (kbhit() && Sdepth > 1) - { - timeout = true; - bothsides = false; - } -#else - (void) times(&tmbuf2); - cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ; - if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft); - else evrate = 0; -#endif MSDOS - ETnodes = NodeCnt + 50; - } -} - - -SetTimeControl() -{ - if (TCflag) - { - TimeControl.moves[white] = TimeControl.moves[black] = TCmoves; - TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes; - } - else - { - TimeControl.moves[white] = TimeControl.moves[black] = 0; - TimeControl.clock[white] = TimeControl.clock[black] = 0; - Level = 60*(long)TCminutes; - } - et = 0; - ElapsedTime(1); -} - - -ClrScreen() -{ -#ifndef CHESSTOOL - printz("\n"); -#endif -} - - -UpdateDisplay(f,t,flag,iscastle) -short f,t,flag,iscastle; -{ -#ifndef CHESSTOOL -short r,c,l; - if (flag) - { - printz("\n"); - for (r = 7; r >= 0; r--) - { - for (c = 0; c <= 7; c++) - { - if (reverse) l = locn[7-r][7-c]; else l = locn[r][c]; - if (color[l] == neutral) printz(" -"); - else if (color[l] == white) printz(" %c",qxx[board[l]]); - else printz(" %c",pxx[board[l]]); - } - printz("\n"); - } - printz("\n"); - } -#endif CHESSTOOL -} - - -GetOpenings() - -/* - Read in the Opening Book file and parse the algebraic notation for a - move into an unsigned integer format indicating the from and to - square. Create a linked list of opening lines of play, with - entry->next pointing to the next line and entry->move pointing to a - chunk of memory containing the moves. More Opening lines of up to 256 - half moves may be added to gnuchess.book. -*/ - -{ -FILE *fd; -int c,i,j,side; -char buffr[2048]; -struct BookEntry *entry; -unsigned short mv,*mp,tmp[100]; - - if ((fd = fopen("gnuchess.book","r")) != NULL) - { -/* - setvbuf(fd,buffr,_IOFBF,2048); -*/ - Book = NULL; - i = 0; side = white; - while ((c = parse(fd,&mv,side)) >= 0) - if (c == 1) - { - tmp[++i] = mv; - side = otherside[side]; - } - else if (c == 0 && i > 0) - { - entry = (struct BookEntry *)malloc(sizeof(struct BookEntry)); - mp = (unsigned short *)malloc((i+1)*sizeof(unsigned short)); - entry->mv = mp; - entry->next = Book; - Book = entry; - for (j = 1; j <= i; j++) *(mp++) = tmp[j]; - *mp = 0; - i = 0; side = white; - } - fclose(fd); - } -} - - -int parse(fd,mv,side) -FILE *fd; -unsigned short *mv; -short side; -{ -int c,i,r1,r2,c1,c2; -char s[100]; - while ((c = getc(fd)) == ' '); - i = 0; s[0] = c; - while (c != ' ' && c != '\n' && c != EOF) s[++i] = c = getc(fd); - s[++i] = '\0'; - if (c == EOF) return(-1); - if (s[0] == '!' || i < 3) - { - while (c != '\n' && c != EOF) c = getc(fd); - return(0); - } - if (s[4] == 'o') - if (side == black) *mv = 0x3C3A; else *mv = 0x0402; - else if (s[0] == 'o') - if (side == black) *mv = 0x3C3E; else *mv = 0x0406; - else - { - c1 = s[0] - 'a'; r1 = s[1] - '1'; - c2 = s[2] - 'a'; r2 = s[3] - '1'; - *mv = (locn[r1][c1]<<8) + locn[r2][c2]; - } - return(1); -} - - -GetGame() -{ -FILE *fd; -char fname[40]; -int c; -short sq; -unsigned short m; - - printz("Enter file name: "); - scanz("%s",fname); - if (fname[0] == '\0') strcpy(fname,"chess.000"); - if ((fd = fopen(fname,"r")) != NULL) - { - fscanf(fd,"%hd%hd%hd",&computer,&opponent,&Game50); - fscanf(fd,"%hd%hd%hd%hd", - &castld[white],&castld[black], - &kingmoved[white],&kingmoved[black]); - fscanf(fd,"%hd%hd",&TCflag,&OperatorTime); - fscanf(fd,"%ld%ld%hd%hd", - &TimeControl.clock[white],&TimeControl.clock[black], - &TimeControl.moves[white],&TimeControl.moves[black]); - for (sq = 0; sq < 64; sq++) - { - fscanf(fd,"%hd",&m); - board[sq] = (m >> 8); color[sq] = (m & 0xFF); - if (color[sq] == 0) color[sq] = neutral; else --color[sq]; - } - GameCnt = -1; c = '?'; - while (c != EOF) - { - ++GameCnt; - c = fscanf(fd,"%hd%hd%hd%ld%hd%hd%hd",&GameList[GameCnt].gmove, - &GameList[GameCnt].score,&GameList[GameCnt].depth, - &GameList[GameCnt].nodes,&GameList[GameCnt].time, - &GameList[GameCnt].piece,&GameList[GameCnt].color); - if (GameList[GameCnt].color == 0) GameList[GameCnt].color = neutral; - else --GameList[GameCnt].color; - } - GameCnt--; - if (TimeControl.clock[white] > 0) TCflag = true; - computer--; opponent--; - } - fclose(fd); - InitializeStats(); - UpdateDisplay(0,0,1,0); - Sdepth = 0; -} - - -SaveGame() -{ -FILE *fd; -char fname[40]; -short sq,i,c; - - printz("Enter file name: "); - scanz("%s",fname); - - if (fname[0] == '\0' || access(fname,W_OK) == -1) strcpy(fname,"chess.000"); - fd = fopen(fname,"w"); - fprintf(fd,"%d %d %d\n",computer+1,opponent+1,Game50); - fprintf(fd,"%d %d %d %d\n", - castld[white],castld[black],kingmoved[white],kingmoved[black]); - fprintf(fd,"%d %d\n",TCflag,OperatorTime); - fprintf(fd,"%ld %ld %d %d\n", - TimeControl.clock[white],TimeControl.clock[black], - TimeControl.moves[white],TimeControl.moves[black]); - for (sq = 0; sq < 64; sq++) - { - if (color[sq] == neutral) c = 0; else c = color[sq]+1; - fprintf(fd,"%d\n",256*board[sq] + c); - } - for (i = 0; i <= GameCnt; i++) - { - if (GameList[i].color == neutral) c = 0; - else c = GameList[i].color + 1; - fprintf(fd,"%d %d %d %ld %d %d %d\n", - GameList[i].gmove,GameList[i].score,GameList[i].depth, - GameList[i].nodes,GameList[i].time, - GameList[i].piece,c); - } - fclose(fd); -} - - -ListGame() -{ -FILE *fd; -short i,f,t; - fd = fopen("chess.lst","w"); - fprintf(fd,"\n"); - fprintf(fd," score depth nodes time "); - fprintf(fd," score depth nodes time\n"); - for (i = 0; i <= GameCnt; i++) - { - f = GameList[i].gmove>>8; t = (GameList[i].gmove & 0xFF); - algbr(f,t,false); - if ((i % 2) == 0) fprintf(fd,"\n"); else fprintf(fd," "); - fprintf(fd,"%5s %5d %2d %6ld %5d",mvstr1, - GameList[i].score,GameList[i].depth, - GameList[i].nodes,GameList[i].time); - } - fprintf(fd,"\n\n"); - fclose(fd); -} - - -Undo() - -/* - Undo the most recent half-move. -*/ - -{ -short f,t; - f = GameList[GameCnt].gmove>>8; - t = GameList[GameCnt].gmove & 0xFF; - if (board[t] == king && distance(t,f) > 1) - castle(GameList[GameCnt].color,f,t,2); - else - { - board[f] = board[t]; color[f] = color[t]; - board[t] = GameList[GameCnt].piece; - color[t] = GameList[GameCnt].color; - if (board[f] == king) --kingmoved[color[f]]; - } - if (TCflag) ++TimeControl.moves[color[f]]; - GameCnt--; mate = false; Sdepth = 0; - UpdateDisplay(0,0,1,0); - InitializeStats(); -} - - -ShowMessage(s) -char *s; -{ -#ifndef CHESSTOOL - printz("%s\n"); -#endif CHESSTOOL -} - -ShowSidetomove() -{ -} - -PromptForMove() -{ -#ifndef CHESSTOOL - printz("\nYour move is? "); -#endif CHESSTOOL -} - - -ShowCurrentMove(pnt,f,t) -short pnt,f,t; -{ -} - -ChangeAlphaWindow() -{ - printz("window: "); - scanz("%hd",&Awindow); -} - -ChangeBetaWindow() -{ - printz("window: "); - scanz("%hd",&Bwindow); -} - -GiveHint() -{ - algbr((short)(hint>>8),(short)(hint & 0xFF),false); - printz("try %s\n",mvstr1); -} - - -SelectLevel() -{ - OperatorTime = 30000; - printz("Enter #moves #minutes: "); - scanz("%hd %hd",&TCmoves,&TCminutes); - printz("Operator time= "); - scanz("%hd",&OperatorTime); - TCflag = (TCmoves > 1); - SetTimeControl(); -} - - -ChangeSearchDepth() -{ - printz("depth= "); - scanz("%hd",&MaxSearchDepth); -} - -SetContempt() -{ - printz("contempt= "); - scanz("%hd",&contempt); -} - -ChangeXwindow() -{ - printz("xwndw= "); - scanz("%hd",&xwndw); -} diff --git a/gnu/games/chess/uxdsp.c b/gnu/games/chess/uxdsp.c deleted file mode 100644 index 84034bc..0000000 --- a/gnu/games/chess/uxdsp.c +++ /dev/null @@ -1,933 +0,0 @@ -/* - ALPHA interface for CHESS - - Revision: 4-25-88 - - Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc. - Copyright (c) 1988 John Stanback - - This file is part of CHESS. - - CHESS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY. No author or distributor - accepts responsibility to anyone for the consequences of using it - or for whether it serves any particular purpose or works at all, - unless he says so in writing. Refer to the CHESS General Public - License for full details. - - Everyone is granted permission to copy, modify and redistribute - CHESS, but only under the conditions described in the - CHESS General Public License. A copy of this license is - supposed to have been given to you along with CHESS so you - can know your rights and responsibilities. It should be in a - file named COPYING. Among other things, the copyright notice - and this notice must be preserved on all copies. -*/ - - -#include -#include -#include -#include -#include -#include -#include -#include "gnuchess.h" -#ifdef NEWMOVE -#include "move.h" -#endif -#include "pathnames.h" - -struct tms tmbuf1,tmbuf2; -void TerminateSearch(),Die(); - -#define scanz fflush(stdout),scanw -#define printz printw - - -Initialize() -{ - signal(SIGINT,Die); signal(SIGQUIT,Die); - initscr(); - crmode(); -} - - -ExitChess() -{ - nocrmode(); - endwin(); - exit(0); -} - - -void -Die() -{ -char s[80]; - signal(SIGINT,SIG_IGN); - signal(SIGQUIT,SIG_IGN); - ShowMessage("Abort? "); - scanz("%s",s); - if (strcmp(s,"yes") == 0) ExitChess(); - signal(SIGINT,Die); signal(SIGQUIT,Die); -} - - -void -TerminateSearch() -{ - signal(SIGINT,SIG_IGN); - signal(SIGQUIT,SIG_IGN); - timeout = true; - bothsides = false; - signal(SIGINT,Die); signal(SIGQUIT,Die); -} - - -InputCommand() - -/* - Process the users command. If easy mode is OFF (the computer is - thinking on opponents time) and the program is out of book, then make - the 'hint' move on the board and call SelectMove() to find a response. - The user terminates the search by entering ^C (quit siqnal) before - entering a command. If the opponent does not make the hint move, then - set Sdepth to zero. -*/ - -{ -short ok,i,tmp; -long cnt,rate,t1,t2; -unsigned short mv; -char s[80]; - - ok = quit = false; - player = opponent; - ShowSidetomove(); - ft = 0; - if (hint > 0 && !easy && Book == NULL) - { - fflush(stdout); - time0 = time((long *)0); - algbr(hint>>8,hint & 0xFF,false); - strcpy(s,mvstr1); - tmp = epsquare; - if (VerifyMove(s,1,&mv)) - { - PromptForMove(); - SelectMove(computer,2); - VerifyMove(mvstr1,2,&mv); - if (Sdepth > 0) Sdepth--; - } - ft = time((time_t *)0) - time0; - epsquare = tmp; - } - - signal(SIGINT,Die); signal(SIGQUIT,Die); - while (!(ok || quit)) - { - PromptForMove(); - scanz("%s",s); - player = opponent; - ok = VerifyMove(s,0,&mv); - if (ok && mv != hint) - { - Sdepth = 0; - ft = 0; - } - - if (strcmp(s,"bd") == 0) - { - ClrScreen(); - UpdateDisplay(0,0,1,0); - } - if (strcmp(s,"quit") == 0) quit = true; - if (strcmp(s,"post") == 0) post = !post; - if (strcmp(s,"edit") == 0) EditBoard(); - if (strcmp(s,"go") == 0) ok = true; - if (strcmp(s,"help") == 0) help(); - if (strcmp(s,"force") == 0) force = !force; - if (strcmp(s,"book") == 0) Book = NULL; - if (strcmp(s,"undo") == 0 && GameCnt >= 0) Undo(); - if (strcmp(s,"new") == 0) NewGame(); - if (strcmp(s,"list") == 0) ListGame(); - if (strcmp(s,"level") == 0) SelectLevel(); - if (strcmp(s,"hash") == 0) hashflag = !hashflag; - if (strcmp(s,"beep") == 0) beep = !beep; - if (strcmp(s,"Awindow") == 0) ChangeAlphaWindow(); - if (strcmp(s,"Bwindow") == 0) ChangeBetaWindow(); - if (strcmp(s,"hint") == 0) GiveHint(); - if (strcmp(s,"both") == 0) - { - bothsides = !bothsides; - Sdepth = 0; - SelectMove(opponent,1); - ok = true; - } - if (strcmp(s,"reverse") == 0) - { - reverse = !reverse; - ClrScreen(); - UpdateDisplay(0,0,1,0); - } - if (strcmp(s,"switch") == 0) - { - computer = otherside[computer]; - opponent = otherside[opponent]; - force = false; - Sdepth = 0; - ok = true; - } - if (strcmp(s,"white") == 0) - { - computer = white; opponent = black; - ok = true; force = false; - Sdepth = 0; - } - if (strcmp(s,"black") == 0) - { - computer = black; opponent = white; - ok = true; force = false; - Sdepth = 0; - } - if (strcmp(s,"remove") == 0 && GameCnt >= 1) - { - Undo(); Undo(); - } - if (strcmp(s,"get") == 0) GetGame(); - if (strcmp(s,"save") == 0) SaveGame(); - if (strcmp(s,"depth") == 0) ChangeSearchDepth(); - if (strcmp(s,"random") == 0) dither = 6; - if (strcmp(s,"easy") == 0) easy = !easy; - if (strcmp(s,"contempt") == 0) SetContempt(); - if (strcmp(s,"xwndw") == 0) ChangeXwindow(); - if (strcmp(s,"test") == 0) - { - t1 = time(0); - cnt = 0; - for (i = 0; i < 10000; i++) - { - MoveList(opponent,2); - cnt += TrPnt[3] - TrPnt[2]; - } - t2 = time(0); - rate = cnt / (t2-t1); - gotoXY(50,24); - printz("cnt= %ld rate= %ld",cnt,rate); - ClrEoln(); - } - if (strcmp(s,"p") == 0) ShowPostnValues(); - if (strcmp(s,"debug") == 0) DoDebug(); - } - - ClearMessage(); - ElapsedTime(1); - if (force) - { - computer = opponent; opponent = otherside[computer]; - } - (void) times(&tmbuf1); - signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch); -} - - -EditBoard() - -/* - Set up a board position. Pieces are entered by typing the piece - followed by the location. For example, Nf3 will place a knight on - square f3. -*/ - -{ -short a,r,c,sq; -char s[80]; - - ClrScreen(); - UpdateDisplay(0,0,1,0); - gotoXY(50,2); printz(". Exit to main"); - gotoXY(50,3); printz("# Clear board"); - gotoXY(49,5); printz("Enter piece & location: "); - a = white; - do - { - gotoXY(73,5); ClrEoln(); scanz("%s",s); - if (s[0] == '#') - { - for (sq = 0; sq < 64; sq++) - { - board[sq] = no_piece; color[sq] = neutral; - } - UpdateDisplay(0,0,1,0); - } - if (s[0] == 'c' || s[0] == 'C') a = otherside[a]; - c = s[1]-'a'; r = s[2]-'1'; - if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8)) - { - sq = locn[r][c]; - color[sq] = a; - if (s[0] == 'p') board[sq] = pawn; - else if (s[0] == 'n') board[sq] = knight; - else if (s[0] == 'b') board[sq] = bishop; - else if (s[0] == 'r') board[sq] = rook; - else if (s[0] == 'q') board[sq] = queen; - else if (s[0] == 'k') board[sq] = king; - else { board[sq] = no_piece; color[sq] = neutral; } - DrawPiece(sq); - } - } - while (s[0] != '.'); - if (board[4] != king) kingmoved[white] = 10; - if (board[60] != king) kingmoved[black] = 10; - GameCnt = -1; Game50 = 0; Sdepth = 0; - InitializeStats(); - ClrScreen(); - UpdateDisplay(0,0,1,0); -} - - -help() -{ - ClrScreen(); - gotoXY(28,1); printz("CHESS command summary"); - gotoXY(1,3); printz("g1f3 move from g1 to f3"); - gotoXY(1,4); printz("nf3 move knight to f3"); - gotoXY(1,5); printz("o-o castle king side"); - gotoXY(1,6); printz("o-o-o castle queen side"); - gotoXY(1,7); printz("edit edit board"); - gotoXY(1,8); printz("switch sides with computer"); - gotoXY(1,9); printz("white computer plays white"); - gotoXY(1,10); printz("black computer plays black"); - gotoXY(1,11); printz("reverse board display"); - gotoXY(1,12); printz("both computer match"); - gotoXY(1,13); printz("random randomize play"); - gotoXY(1,14); printz("undo undo last move"); - gotoXY(42,3); printz("level change level"); - gotoXY(42,4); printz("depth set search depth"); - gotoXY(42,5); printz("post principle variation"); - gotoXY(42,6); printz("hint suggest a move"); - gotoXY(42,7); printz("bd redraw board"); - gotoXY(42,8); printz("force enter game moves"); - gotoXY(42,9); printz("list game to chess.lst"); - gotoXY(42,10); printz("save game to file"); - gotoXY(42,11); printz("get game from file"); - gotoXY(42,12); printz("new start new game"); - gotoXY(42,13); printz("quit exit CHESS"); - gotoXY(10,21); printz("Computer: "); - if (computer == white) printz("WHITE"); else printz("BLACK"); - gotoXY(10,22); printz("Opponent: "); - if (opponent == white) printz("WHITE"); else printz("BLACK"); - gotoXY(10,23); printz("Level: %ld",Level," sec."); - gotoXY(10,24); printz("Easy mode: "); - if (easy) printz("ON"); else printz("OFF"); - gotoXY(40,21); printz("Depth: %d",MaxSearchDepth); - gotoXY(40,22); printz("Random: "); - if (dither) printz("ON"); else printz("OFF"); - gotoXY(40,23); printz("Transposition table: "); - if (hashflag) printz("ON"); else printz("OFF"); - refresh(); - while (getchar() != 27); - ClrScreen(); - UpdateDisplay(0,0,1,0); -} - - -ShowDepth(ch) -char ch; -{ - gotoXY(50,4); printz("Depth= %d%c ",Sdepth,ch); ClrEoln(); -} - - -ShowResults(score,bstline,ch) -short score; -unsigned short bstline[]; -char ch; -{ -short d,e,ply; - if (post && player == computer) - { - e = lpost; - gotoXY(50,5); printz("Score= %d",score); ClrEoln(); - d = 8; gotoXY(50,d); ClrEoln(); - for (ply = 1; bstline[ply] > 0; ply++) - { - algbr(bstline[ply] >> 8,bstline[ply] & 0xFF,false); - if (ply == 5 || ply == 9 || ply == 13 || ply == 17) - { - gotoXY(50,++d); ClrEoln(); - } - printz("%5s ",mvstr1); - } - ClrEoln(); - lpost = d; - while (++d <= e) - { - gotoXY(50,d); ClrEoln(); - } - } -} - - -SearchStartStuff(side) -short side; -{ -short i; - signal(SIGINT,TerminateSearch); signal(SIGQUIT,TerminateSearch); - if (player == computer) - for (i = 5; i < 14; i++) - { - gotoXY(50,i); ClrEoln(); - } -} - - -OutputMove() -{ - if (root->flags & epmask) UpdateDisplay(0,0,1,0); - else UpdateDisplay(root->f,root->t,0,root->flags & cstlmask); - gotoXY(50,17); printz("My move is: %s",mvstr1); - if (beep) putchar(7); - ClrEoln(); - - gotoXY(50,24); - if (root->flags & draw) printz("Draw game!"); - else if (root->score == -9999) printz("opponent mates!"); - else if (root->score == 9998) printz("computer mates!"); - else if (root->score < -9000) printz("opponent will soon mate!"); - else if (root->score > 9000) printz("computer will soon mate!"); - ClrEoln(); - - if (post) - { - gotoXY(50,22); printz("Nodes= %6ld",NodeCnt); ClrEoln(); - gotoXY(50,23); printz("Nodes/Sec= %4ld",evrate); ClrEoln(); - } -} - - -ElapsedTime(iop) - -/* - Determine the time that has passed since the search was started. If - the elapsed time exceeds the target (ResponseTime+ExtraTime) then set - timeout to true which will terminate the search. -*/ - -short iop; -{ - et = time((time_t *)0) - time0; - if (et < 0) et = 0; - ETnodes += 50; - if (et > et0 || iop == 1) - { - if (et > ResponseTime+ExtraTime && Sdepth > 1) timeout = true; - et0 = et; - if (iop == 1) - { - time0 = time((time_t *)0); et0 = 0; - } - (void) times(&tmbuf2); - cputimer = 100*(tmbuf2.tms_utime - tmbuf1.tms_utime) / HZ; - if (cputimer > 0) evrate = (100*NodeCnt)/(cputimer+100*ft); - else evrate = 0; - ETnodes = NodeCnt + 50; - UpdateClocks(); - } -} - - -UpdateClocks() -{ -short m,s; - m = et/60; s = (et - 60*m); - if (TCflag) - { - m = (TimeControl.clock[player] - et) / 60; - s = TimeControl.clock[player] - et - 60*m; - } - if (m < 0) m = 0; - if (s < 0) s = 0; - if (player == white) - if (reverse) gotoXY(20,2); else gotoXY(20,23); - else - if (reverse) gotoXY(20,23); else gotoXY(20,2); - printz("%d:%2d ",m,s); - if (post) - { - gotoXY(50,22); printz("Nodes= %6ld",NodeCnt); - gotoXY(50,23); printz("Nodes/Sec= %4ld",evrate); - } - refresh(); -} - - - -SetTimeControl() -{ - if (TCflag) - { - TimeControl.moves[white] = TimeControl.moves[black] = TCmoves; - TimeControl.clock[white] = TimeControl.clock[black] = 60*(long)TCminutes; - } - else - { - TimeControl.moves[white] = TimeControl.moves[black] = 0; - TimeControl.clock[white] = TimeControl.clock[black] = 0; - Level = 60*(long)TCminutes; - } - et = 0; - ElapsedTime(1); -} - - -gotoXY(x,y) -short x,y; -{ - move(y-1,x-1); -} - - -ClrScreen() -{ - clear(); refresh(); -} - - -ClrEoln() -{ - clrtoeol(); refresh(); -} - - -DrawPiece(sq) -short sq; -{ -short r,c; char x; - if (reverse) r = 7-row[sq]; else r = row[sq]; - if (reverse) c = 7-column[sq]; else c = column[sq]; - if (color[sq] == black) x = '*'; else x = ' '; - gotoXY(5+5*c,5+2*(7-r)); printz("%c%c ",x,pxx[board[sq]]); -} - - -UpdateDisplay(f,t,flag,iscastle) -short f,t,flag,iscastle; -{ -short i,l,z; - if (flag) - { - gotoXY(56,2); printz("CHESS"); - i = 3; - gotoXY(3,++i); - printz("|----|----|----|----|----|----|----|----|"); - while (i<19) - { - gotoXY(1,++i); - if (reverse) z = (i/2)-1; else z = 10-(i/2); - printz("%d | | | | | | | | |",z); - gotoXY(3,++i); - if (i < 19) - printz("+----+----+----+----+----+----+----+----+"); - } - printz("|----|----|----|----|----|----|----|----|"); - gotoXY(3,21); - if (reverse) printz(" h g f e d c b a"); - else printz(" a b c d e f g h"); - if (reverse) gotoXY(5,23); else gotoXY(5,2); - if (computer == black) printz("Computer"); else printz("Human "); - if (reverse) gotoXY(5,2); else gotoXY(5,23); - if (computer == white) printz("Computer"); else printz("Human "); - for (l = 0; l < 64; l++) DrawPiece(l); - } - else - { - DrawPiece(f); DrawPiece(t); - if (iscastle) - if (t > f) - { DrawPiece(f+3); DrawPiece(t-1); } - else - { DrawPiece(f-4); DrawPiece(t+1); } - } - refresh(); -} - - -GetOpenings() - -/* - Read in the Opening Book file and parse the algebraic notation for a - move into an unsigned integer format indicating the from and to - square. Create a linked list of opening lines of play, with - entry->next pointing to the next line and entry->move pointing to a - chunk of memory containing the moves. More Opening lines of up to 256 - half moves may be added to gnuchess.book. -*/ - -{ -FILE *fd; -int c,i,j,side; -struct BookEntry *entry; -unsigned short mv,*mp,tmp[100]; - - if ((fd = fopen(_PATH_CHESSBOOK,"r")) != NULL) - { - Book = NULL; - i = 0; side = white; - while ((c = parse(fd,&mv,side)) >= 0) - if (c == 1) - { - tmp[++i] = mv; - side = otherside[side]; - } - else if (c == 0 && i > 0) - { - entry = (struct BookEntry *)malloc(sizeof(struct BookEntry)); - mp = (unsigned short *)malloc((i+1)*sizeof(unsigned short)); - entry->mv = mp; - entry->next = Book; - Book = entry; - for (j = 1; j <= i; j++) *(mp++) = tmp[j]; - *mp = 0; - i = 0; side = white; - } - fclose(fd); - } - else - { - fprintf(stderr, "\nchess: can't read %s.\n", _PATH_CHESSBOOK); - exit(1); - } -} - - -int parse(fd,mv,side) -FILE *fd; -unsigned short *mv; -short side; -{ -int c,i,r1,r2,c1,c2; -char s[100]; - while ((c = getc(fd)) == ' '); - i = 0; s[0] = c; - while (c != ' ' && c != '\n' && c != EOF) s[++i] = c = getc(fd); - s[++i] = '\0'; - if (c == EOF) return(-1); - if (s[0] == '!' || i < 3) - { - while (c != '\n' && c != EOF) c = getc(fd); - return(0); - } - if (s[4] == 'o') - if (side == black) *mv = 0x3C3A; else *mv = 0x0402; - else if (s[0] == 'o') - if (side == black) *mv = 0x3C3E; else *mv = 0x0406; - else - { - c1 = s[0] - 'a'; r1 = s[1] - '1'; - c2 = s[2] - 'a'; r2 = s[3] - '1'; - *mv = (locn[r1][c1]<<8) + locn[r2][c2]; - } - return(1); -} - - -GetGame() -{ -FILE *fd; -char fname[40]; -int c; -short sq; -unsigned short m; - - ShowMessage("File name: "); - scanz("%s",fname); - if (fname[0] == '\0') strcpy(fname,"chess.000"); - if ((fd = fopen(fname,"r")) != NULL) - { - fscanf(fd,"%hd%hd%hd",&computer,&opponent,&Game50); - fscanf(fd,"%hd%hd%hd%hd", - &castld[white],&castld[black], - &kingmoved[white],&kingmoved[black]); - fscanf(fd,"%hd%hd",&TCflag,&OperatorTime); - fscanf(fd,"%ld%ld%hd%hd", - &TimeControl.clock[white],&TimeControl.clock[black], - &TimeControl.moves[white],&TimeControl.moves[black]); - for (sq = 0; sq < 64; sq++) - { - fscanf(fd,"%hd",&m); - board[sq] = (m >> 8); color[sq] = (m & 0xFF); - if (color[sq] == 0) color[sq] = neutral; else --color[sq]; - } - GameCnt = -1; c = '?'; - while (c != EOF) - { - ++GameCnt; - c = fscanf(fd,"%hd%hd%hd%ld%hd%hd%hd",&GameList[GameCnt].gmove, - &GameList[GameCnt].score,&GameList[GameCnt].depth, - &GameList[GameCnt].nodes,&GameList[GameCnt].time, - &GameList[GameCnt].piece,&GameList[GameCnt].color); - if (GameList[GameCnt].color == 0) GameList[GameCnt].color = neutral; - else --GameList[GameCnt].color; - } - GameCnt--; - if (TimeControl.clock[white] > 0) TCflag = true; - computer--; opponent--; - } - fclose(fd); - InitializeStats(); - UpdateDisplay(0,0,1,0); - Sdepth = 0; -} - - -SaveGame() -{ -FILE *fd; -char fname[40]; -short sq,i,c; - - ShowMessage("File name: "); - scanz("%s",fname); - - if (fname[0] == '\0' || access(fname,W_OK) == -1) strcpy(fname,"chess.000"); - fd = fopen(fname,"w"); - fprintf(fd,"%d %d %d\n",computer+1,opponent+1,Game50); - fprintf(fd,"%d %d %d %d\n", - castld[white],castld[black],kingmoved[white],kingmoved[black]); - fprintf(fd,"%d %d\n",TCflag,OperatorTime); - fprintf(fd,"%ld %ld %d %d\n", - TimeControl.clock[white],TimeControl.clock[black], - TimeControl.moves[white],TimeControl.moves[black]); - for (sq = 0; sq < 64; sq++) - { - if (color[sq] == neutral) c = 0; else c = color[sq]+1; - fprintf(fd,"%d\n",256*board[sq] + c); - } - for (i = 0; i <= GameCnt; i++) - { - if (GameList[i].color == neutral) c = 0; - else c = GameList[i].color + 1; - fprintf(fd,"%d %d %d %ld %d %d %d\n", - GameList[i].gmove,GameList[i].score,GameList[i].depth, - GameList[i].nodes,GameList[i].time, - GameList[i].piece,c); - } - fclose(fd); -} - - -ListGame() -{ -FILE *fd; -short i,f,t; - fd = fopen("chess.lst","w"); - fprintf(fd,"\n"); - fprintf(fd," score depth nodes time "); - fprintf(fd," score depth nodes time\n"); - for (i = 0; i <= GameCnt; i++) - { - f = GameList[i].gmove>>8; t = (GameList[i].gmove & 0xFF); - algbr(f,t,false); - if ((i % 2) == 0) fprintf(fd,"\n"); else fprintf(fd," "); - fprintf(fd,"%5s %5d %2d %6ld %5d",mvstr1, - GameList[i].score,GameList[i].depth, - GameList[i].nodes,GameList[i].time); - } - fprintf(fd,"\n\n"); - fclose(fd); -} - - -Undo() - -/* - Undo the most recent half-move. -*/ - -{ -short f,t; - f = GameList[GameCnt].gmove>>8; - t = GameList[GameCnt].gmove & 0xFF; - if (board[t] == king && distance(t,f) > 1) - castle(GameList[GameCnt].color,f,t,2); - else - { - board[f] = board[t]; color[f] = color[t]; - board[t] = GameList[GameCnt].piece; - color[t] = GameList[GameCnt].color; - if (board[f] == king) --kingmoved[color[f]]; - } - if (TCflag) ++TimeControl.moves[color[f]]; - GameCnt--; mate = false; Sdepth = 0; - UpdateDisplay(0,0,1,0); - InitializeStats(); -} - - -ShowMessage(s) -char *s; -{ - gotoXY(50,24); printz("%s",s); ClrEoln(); -} - -ClearMessage() -{ - gotoXY(50,24); ClrEoln(); -} - -ShowSidetomove() -{ - gotoXY(50,14); - if (player == white) printz("%2d: WHITE",1+(GameCnt+1)/2); - else printz("%2d: BLACK",1+(GameCnt+1)/2); - ClrEoln(); -} - -PromptForMove() -{ - gotoXY(50,19); printz("Your move is? "); ClrEoln(); -} - -ShowCurrentMove(pnt,f,t) -short pnt,f,t; -{ - algbr(f,t,false); - gotoXY(50,7); printz("(%2d) %4s",pnt,mvstr1); -} - -ChangeAlphaWindow() -{ - ShowMessage("window: "); - scanz("%hd",&Awindow); -} - -ChangeBetaWindow() -{ - ShowMessage("window: "); - scanz("%hd",&Bwindow); -} - -GiveHint() -{ -char s[40]; - algbr((short)(hint>>8),(short)(hint & 0xFF),false); - strcpy(s,"try "); - strcat(s,mvstr1); - ShowMessage(s); -} - -ChangeSearchDepth() -{ - ShowMessage("depth= "); - scanz("%hd",&MaxSearchDepth); -} - -SetContempt() -{ - ShowMessage("contempt= "); - scanz("%hd",&contempt); -} - -ChangeXwindow() -{ - ShowMessage("xwndw= "); - scanz("%hd",&xwndw); -} - - -SelectLevel() -{ - ClrScreen(); - gotoXY(32,2); printz("CHESS"); - gotoXY(20,4); printz(" 1. 60 moves in 5 minutes"); - gotoXY(20,5); printz(" 2. 60 moves in 15 minutes"); - gotoXY(20,6); printz(" 3. 60 moves in 30 minutes"); - gotoXY(20,7); printz(" 4. 40 moves in 30 minutes"); - gotoXY(20,8); printz(" 5. 40 moves in 60 minutes"); - gotoXY(20,9); printz(" 6. 40 moves in 120 minutes"); - gotoXY(20,10); printz(" 7. 40 moves in 240 minutes"); - gotoXY(20,11); printz(" 8. 1 move in 15 minutes"); - gotoXY(20,12); printz(" 9. 1 move in 60 minutes"); - gotoXY(20,13); printz("10. 1 move in 600 minutes"); - - OperatorTime = 0; TCmoves = 60; TCminutes = 5; - - gotoXY(20,17); printz("Enter Level: "); - refresh(); - scanz("%ld",&Level); - switch (Level) - { - case 1 : TCmoves = 60; TCminutes = 5; break; - case 2 : TCmoves = 60; TCminutes = 15; break; - case 3 : TCmoves = 60; TCminutes = 30; break; - case 4 : TCmoves = 40; TCminutes = 30; break; - case 5 : TCmoves = 40; TCminutes = 60; break; - case 6 : TCmoves = 40; TCminutes = 120; break; - case 7 : TCmoves = 40; TCminutes = 240; break; - case 8 : TCmoves = 1; TCminutes = 15; break; - case 9 : TCmoves = 1; TCminutes = 60; break; - case 10 : TCmoves = 1; TCminutes = 600; break; - } - - TCflag = (TCmoves > 1); - SetTimeControl(); - ClrScreen(); - UpdateDisplay(0,0,1,0); -} - - -ShowPostnValues() -{ -short i,r,c; - ExaminePosition(); - for (i = 0; i < 64; i++) - { - if (reverse) r = 7-row[i]; else r = row[i]; - if (reverse) c = 7-column[i]; else c = column[i]; - gotoXY(4+5*c,5+2*(7-r)); - c1 = color[i]; c2 = otherside[c1]; - PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2]; - atk1 = atak[c1]; atk2 = atak[c2]; - if (color[i] == neutral) printz(" "); - else printz("%3d ",SqValue(i,opponent)); - } - ScorePosition(opponent,&i); - gotoXY(50,24); - printz("Score= %d",i); ClrEoln(); -} - - -DoDebug() -{ -short k,p,i,r,c,tp,tc; -char s[40]; - ExaminePosition(); - ShowMessage("Enter piece: "); - scanz("%s",s); - if (s[0] == 'w') k = white; else k = black; - if (s[1] == 'p') p = pawn; - else if (s[1] == 'n') p = knight; - else if (s[1] == 'b') p = bishop; - else if (s[1] == 'r') p = rook; - else if (s[1] == 'q') p = queen; - else if (s[1] == 'k') p = king; - else p = no_piece; - for (i = 0; i < 64; i++) - { - if (reverse) r = 7-row[i]; else r = row[i]; - if (reverse) c = 7-column[i]; else c = column[i]; - gotoXY(4+5*c,5+2*(7-r)); - tp = board[i]; tc = color[i]; - board[i] = p; color[i] = k; - c1 = k; c2 = otherside[c1]; - PC1 = PawnCnt[c1]; PC2 = PawnCnt[c2]; - atk1 = atak[c1]; atk2 = atak[c2]; - printz("%3d ",SqValue(i,opponent)); - board[i] = tp; color[i] = tc; - } - ScorePosition(opponent,&i); - gotoXY(50,24); - printz("Score= %d",i); ClrEoln(); -} diff --git a/gnu/lib/libg++/libg++/regex.cc b/gnu/lib/libg++/libg++/regex.cc deleted file mode 100644 index 40b8498..0000000 --- a/gnu/lib/libg++/libg++/regex.cc +++ /dev/null @@ -1,2757 +0,0 @@ -/* Extended regular expression matching and search library. - Copyright (C) 1985, 1989-90 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - - -// This is a translation into C++ of regex.c, the GNU regexp package. - -/* To test, compile with -Dtest. This Dtestable feature turns this into - a self-contained program which reads a pattern, describes how it - compiles, then reads a string and searches for it. - - On the other hand, if you compile with both -Dtest and -Dcanned you - can run some tests we've already thought of. */ - -/* AIX requires the alloca decl to be the first thing in the file. */ -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else -#ifdef sparc -#include -extern "C" void *__builtin_alloca(...); -#else -#ifdef _AIX -#pragma alloca -#else -char *alloca (); -#endif -#endif -#endif - -#ifdef emacs - -/* The `emacs' switch turns on certain special matching commands - that make sense only in emacs. */ - -#include "config.h" -#include "lisp.h" -#include "buffer.h" -#include "syntax.h" - -#else /* not emacs */ - -#include <_G_config.h> -#include -#include - -/* Define the syntax stuff, so we can do the \<, \>, etc. */ - -/* This must be nonzero for the wordchar and notwordchar pattern - commands in re_match_2. */ -#ifndef Sword -#define Sword 1 -#endif - -#define SYNTAX(c) re_syntax_table[c] - - -#ifdef SYNTAX_TABLE - -char *re_syntax_table; - -#else /* not SYNTAX_TABLE */ - -static char re_syntax_table[256]; - - -static void -init_syntax_once () -{ - register int c; - static int done = 0; - - if (done) - return; - - memset (re_syntax_table, 0, sizeof re_syntax_table); - - for (c = 'a'; c <= 'z'; c++) - re_syntax_table[c] = Sword; - - for (c = 'A'; c <= 'Z'; c++) - re_syntax_table[c] = Sword; - - for (c = '0'; c <= '9'; c++) - re_syntax_table[c] = Sword; - - done = 1; -} - -#endif /* SYNTAX_TABLE */ -#endif /* emacs */ - -/* We write fatal error messages on standard error. */ -#include - -/* isalpha(3) etc. are used for the character classes. */ -#include -/* Sequents are missing isgraph. */ -#ifndef isgraph -#define isgraph(c) (isprint((c)) && !isspace((c))) -#endif - -/* Get the interface, including the syntax bits. */ -#include - - -/* These are the command codes that appear in compiled regular - expressions, one per byte. Some command codes are followed by - argument bytes. A command code can specify any interpretation - whatsoever for its arguments. Zero-bytes may appear in the compiled - regular expression. - - The value of `exactn' is needed in search.c (search_buffer) in emacs. - So regex.h defines a symbol `RE_EXACTN_VALUE' to be 1; the value of - `exactn' we use here must also be 1. */ - -enum regexpcode - { - unused=0, - exactn=1, /* Followed by one byte giving n, then by n literal bytes. */ - begline, /* Fail unless at beginning of line. */ - endline, /* Fail unless at end of line. */ - jump, /* Followed by two bytes giving relative address to jump to. */ - on_failure_jump, /* Followed by two bytes giving relative address of - place to resume at in case of failure. */ - finalize_jump, /* Throw away latest failure point and then jump to - address. */ - maybe_finalize_jump, /* Like jump but finalize if safe to do so. - This is used to jump back to the beginning - of a repeat. If the command that follows - this jump is clearly incompatible with the - one at the beginning of the repeat, such that - we can be sure that there is no use backtracking - out of repetitions already completed, - then we finalize. */ - dummy_failure_jump, /* Jump, and push a dummy failure point. This - failure point will be thrown away if an attempt - is made to use it for a failure. A + construct - makes this before the first repeat. Also - use it as an intermediary kind of jump when - compiling an or construct. */ - succeed_n, /* Used like on_failure_jump except has to succeed n times; - then gets turned into an on_failure_jump. The relative - address following it is useless until then. The - address is followed by two bytes containing n. */ - jump_n, /* Similar to jump, but jump n times only; also the relative - address following is in turn followed by yet two more bytes - containing n. */ - set_number_at, /* Set the following relative location to the - subsequent number. */ - anychar, /* Matches any (more or less) one character. */ - charset, /* Matches any one char belonging to specified set. - First following byte is number of bitmap bytes. - Then come bytes for a bitmap saying which chars are in. - Bits in each byte are ordered low-bit-first. - A character is in the set if its bit is 1. - A character too large to have a bit in the map - is automatically not in the set. */ - charset_not, /* Same parameters as charset, but match any character - that is not one of those specified. */ - start_memory, /* Start remembering the text that is matched, for - storing in a memory register. Followed by one - byte containing the register number. Register numbers - must be in the range 0 through RE_NREGS. */ - stop_memory, /* Stop remembering the text that is matched - and store it in a memory register. Followed by - one byte containing the register number. Register - numbers must be in the range 0 through RE_NREGS. */ - duplicate, /* Match a duplicate of something remembered. - Followed by one byte containing the index of the memory - register. */ -#ifdef emacs - before_dot, /* Succeeds if before point. */ - at_dot, /* Succeeds if at point. */ - after_dot, /* Succeeds if after point. */ -#endif - begbuf, /* Succeeds if at beginning of buffer. */ - endbuf, /* Succeeds if at end of buffer. */ - wordchar, /* Matches any word-constituent character. */ - notwordchar, /* Matches any char that is not a word-constituent. */ - wordbeg, /* Succeeds if at word beginning. */ - wordend, /* Succeeds if at word end. */ - wordbound, /* Succeeds if at a word boundary. */ - notwordbound /* Succeeds if not at a word boundary. */ -#ifdef emacs - ,syntaxspec, /* Matches any character whose syntax is specified. - followed by a byte which contains a syntax code, - e.g., Sword. */ - notsyntaxspec /* Matches any character whose syntax differs from - that specified. */ -#endif - }; - - -/* Number of failure points to allocate space for initially, - when matching. If this number is exceeded, more space is allocated, - so it is not a hard limit. */ - -#ifndef NFAILURES -#define NFAILURES 80 -#endif - - -#ifndef SIGN_EXTEND_CHAR -#ifdef __STDC__ -#define SIGN_EXTEND_CHAR(c) ((signed char)(c)) -#else -#define SIGN_EXTEND_CHAR(c) (((c)^128) - 128) /* As in Harbison and Steele. */ -#endif -#endif /* not SIGN_EXTEND_CHAR */ - -/* Store NUMBER in two contiguous bytes starting at DESTINATION. */ -#define STORE_NUMBER(destination, number) \ - { (destination)[0] = (char)((number) & 0377); \ - (destination)[1] = (number) >> 8; } - -/* Same as STORE_NUMBER, except increment the destination pointer to - the byte after where the number is stored. Watch out that values for - DESTINATION such as p + 1 won't work, whereas p will. */ -#define STORE_NUMBER_AND_INCR(destination, number) \ - { STORE_NUMBER(destination, number); \ - (destination) += 2; } - - -/* Put into DESTINATION a number stored in two contingous bytes starting - at SOURCE. */ -#define EXTRACT_NUMBER(destination, source) \ - { (destination) = *(source) & 0377; \ - (destination) += SIGN_EXTEND_CHAR (*(char *)((source) + 1)) << 8; } - -/* Same as EXTRACT_NUMBER, except increment the pointer for source to - point to second byte of SOURCE. Note that SOURCE has to be a value - such as p, not, e.g., p + 1. */ -#define EXTRACT_NUMBER_AND_INCR(destination, source) \ - { EXTRACT_NUMBER (destination, source); \ - (source) += 2; } - - -/* Specify the precise syntax of regexps for compilation. This provides - for compatibility for various utilities which historically have - different, incompatible syntaxes. - - The argument SYNTAX is a bit-mask comprised of the various bits - defined in regex.h. */ - -int -re_set_syntax (int syntax) -{ - int ret; - - ret = obscure_syntax; - obscure_syntax = syntax; - return ret; -} - -/* Set by re_set_syntax to the current regexp syntax to recognize. */ -int obscure_syntax = 0; - - - -/* Macros for re_compile_pattern, which is found below these definitions. */ - -#define CHAR_CLASS_MAX_LENGTH 6 - -/* Fetch the next character in the uncompiled pattern, translating it if - necessary. */ -#define PATFETCH(c) \ - {if (p == pend) goto end_of_pattern; \ - c = * (const unsigned char *) p++; \ - if (translate) c = translate[c]; } - -/* Fetch the next character in the uncompiled pattern, with no - translation. */ -#define PATFETCH_RAW(c) \ - {if (p == pend) goto end_of_pattern; \ - c = * (const unsigned char *) p++; } - -#define PATUNFETCH p-- - - -/* If the buffer isn't allocated when it comes in, use this. */ -#define INIT_BUF_SIZE 28 - -/* Make sure we have at least N more bytes of space in buffer. */ -#define GET_BUFFER_SPACE(n) \ - { \ - while (b - bufp->buffer + (n) >= bufp->allocated) \ - EXTEND_BUFFER; \ - } - -/* Make sure we have one more byte of buffer space and then add CH to it. */ -#define BUFPUSH(ch) \ - { \ - GET_BUFFER_SPACE (1); \ - *b++ = (char) (ch); \ - } - -/* Extend the buffer by twice its current size via reallociation and - reset the pointers that pointed into the old allocation to point to - the correct places in the new allocation. If extending the buffer - results in it being larger than 1 << 16, then flag memory exhausted. */ -#define EXTEND_BUFFER \ - { char *old_buffer = bufp->buffer; \ - if (bufp->allocated == (1L<<16)) goto too_big; \ - bufp->allocated *= 2; \ - if (bufp->allocated > (1L<<16)) bufp->allocated = (1L<<16); \ - bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated); \ - if (bufp->buffer == 0) \ - goto memory_exhausted; \ - b = (b - old_buffer) + bufp->buffer; \ - if (fixup_jump) \ - fixup_jump = (fixup_jump - old_buffer) + bufp->buffer; \ - if (laststart) \ - laststart = (laststart - old_buffer) + bufp->buffer; \ - begalt = (begalt - old_buffer) + bufp->buffer; \ - if (pending_exact) \ - pending_exact = (pending_exact - old_buffer) + bufp->buffer; \ - } - -/* Set the bit for character C in a character set list. */ -#define SET_LIST_BIT(c) (b[(c) / BYTEWIDTH] |= 1 << ((c) % BYTEWIDTH)) - -/* Get the next unsigned number in the uncompiled pattern. */ -#define GET_UNSIGNED_NUMBER(num) \ - { if (p != pend) \ - { \ - PATFETCH (c); \ - while (isdigit (c)) \ - { \ - if (num < 0) \ - num = 0; \ - num = num * 10 + c - '0'; \ - if (p == pend) \ - break; \ - PATFETCH (c); \ - } \ - } \ - } - -/* Subroutines for re_compile_pattern. */ -static void store_jump (char *from, char opcode, char *to); -static void insert_jump (char op, char *from, char *to, char *current_end); -static void store_jump_n (char *from, char opcode, char *to, unsigned n); -static void insert_jump_n (char, char *, char *, char *, unsigned); -static void insert_op_2 (char, char *, char *_end, int, int); - - -/* re_compile_pattern takes a regular-expression string - and converts it into a buffer full of byte commands for matching. - - PATTERN is the address of the pattern string - SIZE is the length of it. - BUFP is a struct re_pattern_buffer * which points to the info - on where to store the byte commands. - This structure contains a char * which points to the - actual space, which should have been obtained with malloc. - re_compile_pattern may use realloc to grow the buffer space. - - The number of bytes of commands can be found out by looking in - the `struct re_pattern_buffer' that bufp pointed to, after - re_compile_pattern returns. */ - -char * -re_compile_pattern (const char *pattern, int size, struct re_pattern_buffer *bufp) -{ - register char *b = bufp->buffer; - register const char *p = pattern; - const char *pend = pattern + size; - register unsigned c, c1; - const char *p1; - unsigned char *translate = (unsigned char *) bufp->translate; - - /* Address of the count-byte of the most recently inserted `exactn' - command. This makes it possible to tell whether a new exact-match - character can be added to that command or requires a new `exactn' - command. */ - - char *pending_exact = 0; - - /* Address of the place where a forward-jump should go to the end of - the containing expression. Each alternative of an `or', except the - last, ends with a forward-jump of this sort. */ - - char *fixup_jump = 0; - - /* Address of start of the most recently finished expression. - This tells postfix * where to find the start of its operand. */ - - char *laststart = 0; - - /* In processing a repeat, 1 means zero matches is allowed. */ - - char zero_times_ok; - - /* In processing a repeat, 1 means many matches is allowed. */ - - char many_times_ok; - - /* Address of beginning of regexp, or inside of last \(. */ - - char *begalt = b; - - /* In processing an interval, at least this many matches must be made. */ - int lower_bound; - - /* In processing an interval, at most this many matches can be made. */ - int upper_bound; - - /* Place in pattern (i.e., the {) to which to go back if the interval - is invalid. */ - const char *beg_interval = 0; - - /* Stack of information saved by \( and restored by \). - Four stack elements are pushed by each \(: - First, the value of b. - Second, the value of fixup_jump. - Third, the value of regnum. - Fourth, the value of begalt. */ - - int stackb[40]; - int *stackp = stackb; - int *stacke = stackb + 40; - int *stackt; - - /* Counts \('s as they are encountered. Remembered for the matching \), - where it becomes the register number to put in the stop_memory - command. */ - - unsigned regnum = 1; - - bufp->fastmap_accurate = 0; - -#ifndef emacs -#ifndef SYNTAX_TABLE - /* Initialize the syntax table. */ - init_syntax_once(); -#endif -#endif - - if (bufp->allocated == 0) - { - bufp->allocated = INIT_BUF_SIZE; - if (bufp->buffer) - /* EXTEND_BUFFER loses when bufp->allocated is 0. */ - bufp->buffer = (char *) realloc (bufp->buffer, INIT_BUF_SIZE); - else - /* Caller did not allocate a buffer. Do it for them. */ - bufp->buffer = (char *) malloc (INIT_BUF_SIZE); - if (!bufp->buffer) goto memory_exhausted; - begalt = b = bufp->buffer; - } - - while (p != pend) - { - PATFETCH (c); - - switch (c) - { - case '$': - { - const char *p1 = p; - /* When testing what follows the $, - look past the \-constructs that don't consume anything. */ - if (! (obscure_syntax & RE_CONTEXT_INDEP_OPS)) - while (p1 != pend) - { - if (*p1 == '\\' && p1 + 1 != pend - && (p1[1] == '<' || p1[1] == '>' - || p1[1] == '`' || p1[1] == '\'' -#ifdef emacs - || p1[1] == '=' -#endif - || p1[1] == 'b' || p1[1] == 'B')) - p1 += 2; - else - break; - } - if (obscure_syntax & RE_TIGHT_VBAR) - { - if (! (obscure_syntax & RE_CONTEXT_INDEP_OPS) && p1 != pend) - goto normal_char; - /* Make operand of last vbar end before this `$'. */ - if (fixup_jump) - store_jump (fixup_jump, jump, b); - fixup_jump = 0; - BUFPUSH (endline); - break; - } - /* $ means succeed if at end of line, but only in special contexts. - If validly in the middle of a pattern, it is a normal character. */ - - if ((obscure_syntax & RE_CONTEXTUAL_INVALID_OPS) && p1 != pend) - goto invalid_pattern; - if (p1 == pend || *p1 == '\n' - || (obscure_syntax & RE_CONTEXT_INDEP_OPS) - || (obscure_syntax & RE_NO_BK_PARENS - ? *p1 == ')' - : *p1 == '\\' && p1[1] == ')') - || (obscure_syntax & RE_NO_BK_VBAR - ? *p1 == '|' - : *p1 == '\\' && p1[1] == '|')) - { - BUFPUSH (endline); - break; - } - goto normal_char; - } - case '^': - /* ^ means succeed if at beg of line, but only if no preceding - pattern. */ - - if ((obscure_syntax & RE_CONTEXTUAL_INVALID_OPS) && laststart) - goto invalid_pattern; - if (laststart && p - 2 >= pattern && p[-2] != '\n' - && !(obscure_syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - if (obscure_syntax & RE_TIGHT_VBAR) - { - if (p != pattern + 1 - && ! (obscure_syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - BUFPUSH (begline); - begalt = b; - } - else - BUFPUSH (begline); - break; - - case '+': - case '?': - if ((obscure_syntax & RE_BK_PLUS_QM) - || (obscure_syntax & RE_LIMITED_OPS)) - goto normal_char; - handle_plus: - case '*': - /* If there is no previous pattern, char not special. */ - if (!laststart) - { - if (obscure_syntax & RE_CONTEXTUAL_INVALID_OPS) - goto invalid_pattern; - else if (! (obscure_syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - } - /* If there is a sequence of repetition chars, - collapse it down to just one. */ - zero_times_ok = 0; - many_times_ok = 0; - while (1) - { - zero_times_ok |= c != '+'; - many_times_ok |= c != '?'; - if (p == pend) - break; - PATFETCH (c); - if (c == '*') - ; - else if (!(obscure_syntax & RE_BK_PLUS_QM) - && (c == '+' || c == '?')) - ; - else if ((obscure_syntax & RE_BK_PLUS_QM) - && c == '\\') - { - int c1; - PATFETCH (c1); - if (!(c1 == '+' || c1 == '?')) - { - PATUNFETCH; - PATUNFETCH; - break; - } - c = c1; - } - else - { - PATUNFETCH; - break; - } - } - - /* Star, etc. applied to an empty pattern is equivalent - to an empty pattern. */ - if (!laststart) - break; - - /* Now we know whether or not zero matches is allowed - and also whether or not two or more matches is allowed. */ - if (many_times_ok) - { - /* If more than one repetition is allowed, put in at the - end a backward relative jump from b to before the next - jump we're going to put in below (which jumps from - laststart to after this jump). */ - GET_BUFFER_SPACE (3); - store_jump (b, maybe_finalize_jump, laststart - 3); - b += 3; /* Because store_jump put stuff here. */ - } - /* On failure, jump from laststart to b + 3, which will be the - end of the buffer after this jump is inserted. */ - GET_BUFFER_SPACE (3); - insert_jump (on_failure_jump, laststart, b + 3, b); - pending_exact = 0; - b += 3; - if (!zero_times_ok) - { - /* At least one repetition is required, so insert a - dummy-failure before the initial on-failure-jump - instruction of the loop. This effects a skip over that - instruction the first time we hit that loop. */ - GET_BUFFER_SPACE (6); - insert_jump (dummy_failure_jump, laststart, laststart + 6, b); - b += 3; - } - break; - - case '.': - laststart = b; - BUFPUSH (anychar); - break; - - case '[': - if (p == pend) - goto invalid_pattern; - while (b - bufp->buffer - > bufp->allocated - 3 - (1 << BYTEWIDTH) / BYTEWIDTH) - EXTEND_BUFFER; - - laststart = b; - if (*p == '^') - { - BUFPUSH (charset_not); - p++; - } - else - BUFPUSH (charset); - p1 = p; - - BUFPUSH ((1 << BYTEWIDTH) / BYTEWIDTH); - /* Clear the whole map */ - memset (b, 0, (1 << BYTEWIDTH) / BYTEWIDTH); - - if ((obscure_syntax & RE_HAT_NOT_NEWLINE) && b[-2] == charset_not) - SET_LIST_BIT ('\n'); - - - /* Read in characters and ranges, setting map bits. */ - while (1) - { - /* Don't translate while fetching, in case it's a range bound. - When we set the bit for the character, we translate it. */ - PATFETCH_RAW (c); - - /* If set, \ escapes characters when inside [...]. */ - if ((obscure_syntax & RE_AWK_CLASS_HACK) && c == '\\') - { - PATFETCH(c1); - SET_LIST_BIT (c1); - continue; - } - if (c == ']') - { - if (p == p1 + 1) - { - /* If this is an empty bracket expression. */ - if ((obscure_syntax & RE_NO_EMPTY_BRACKETS) - && p == pend) - goto invalid_pattern; - } - else - /* Stop if this isn't merely a ] inside a bracket - expression, but rather the end of a bracket - expression. */ - break; - } - /* Get a range. */ - if (p[0] == '-' && p[1] != ']') - { - PATFETCH (c1); - /* Don't translate the range bounds while fetching them. */ - PATFETCH_RAW (c1); - - if ((obscure_syntax & RE_NO_EMPTY_RANGES) && c > c1) - goto invalid_pattern; - - if ((obscure_syntax & RE_NO_HYPHEN_RANGE_END) - && c1 == '-' && *p != ']') - goto invalid_pattern; - - while (c <= c1) - { - /* Translate each char that's in the range. */ - if (translate) - SET_LIST_BIT (translate[c]); - else - SET_LIST_BIT (c); - c++; - } - } - else if ((obscure_syntax & RE_CHAR_CLASSES) - && c == '[' && p[0] == ':') - { - /* Longest valid character class word has six characters. */ - char str[CHAR_CLASS_MAX_LENGTH]; - PATFETCH (c); - c1 = 0; - /* If no ] at end. */ - if (p == pend) - goto invalid_pattern; - while (1) - { - /* Don't translate the ``character class'' characters. */ - PATFETCH_RAW (c); - if (c == ':' || c == ']' || p == pend - || c1 == CHAR_CLASS_MAX_LENGTH) - break; - str[c1++] = c; - } - str[c1] = '\0'; - if (p == pend - || c == ']' /* End of the bracket expression. */ - || p[0] != ']' - || p + 1 == pend - || (strcmp (str, "alpha") != 0 - && strcmp (str, "upper") != 0 - && strcmp (str, "lower") != 0 - && strcmp (str, "digit") != 0 - && strcmp (str, "alnum") != 0 - && strcmp (str, "xdigit") != 0 - && strcmp (str, "space") != 0 - && strcmp (str, "print") != 0 - && strcmp (str, "punct") != 0 - && strcmp (str, "graph") != 0 - && strcmp (str, "cntrl") != 0)) - { - /* Undo the ending character, the letters, and leave - the leading : and [ (but set bits for them). */ - c1++; - while (c1--) - PATUNFETCH; - SET_LIST_BIT ('['); - SET_LIST_BIT (':'); - } - else - { - /* The ] at the end of the character class. */ - PATFETCH (c); - if (c != ']') - goto invalid_pattern; - for (c = 0; c < (1 << BYTEWIDTH); c++) - { - if ((strcmp (str, "alpha") == 0 && isalpha (c)) - || (strcmp (str, "upper") == 0 && isupper (c)) - || (strcmp (str, "lower") == 0 && islower (c)) - || (strcmp (str, "digit") == 0 && isdigit (c)) - || (strcmp (str, "alnum") == 0 && isalnum (c)) - || (strcmp (str, "xdigit") == 0 && isxdigit (c)) - || (strcmp (str, "space") == 0 && isspace (c)) - || (strcmp (str, "print") == 0 && isprint (c)) - || (strcmp (str, "punct") == 0 && ispunct (c)) - || (strcmp (str, "graph") == 0 && isgraph (c)) - || (strcmp (str, "cntrl") == 0 && iscntrl (c))) - SET_LIST_BIT (c); - } - } - } - else if (translate) - SET_LIST_BIT (translate[c]); - else - SET_LIST_BIT (c); - } - - /* Discard any character set/class bitmap bytes that are all - 0 at the end of the map. Decrement the map-length byte too. */ - while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) - b[-1]--; - b += b[-1]; - break; - - case '(': - if (! (obscure_syntax & RE_NO_BK_PARENS)) - goto normal_char; - else - goto handle_open; - - case ')': - if (! (obscure_syntax & RE_NO_BK_PARENS)) - goto normal_char; - else - goto handle_close; - - case '\n': - if (! (obscure_syntax & RE_NEWLINE_OR)) - goto normal_char; - else - goto handle_bar; - - case '|': - if ((obscure_syntax & RE_CONTEXTUAL_INVALID_OPS) - && (! laststart || p == pend)) - goto invalid_pattern; - else if (! (obscure_syntax & RE_NO_BK_VBAR)) - goto normal_char; - else - goto handle_bar; - - case '{': - if (! ((obscure_syntax & RE_NO_BK_CURLY_BRACES) - && (obscure_syntax & RE_INTERVALS))) - goto normal_char; - else - goto handle_interval; - - case '\\': - if (p == pend) goto invalid_pattern; - PATFETCH_RAW (c); - switch (c) - { - case '(': - if (obscure_syntax & RE_NO_BK_PARENS) - goto normal_backsl; - handle_open: - if (stackp == stacke) goto nesting_too_deep; - - /* Laststart should point to the start_memory that we are about - to push (unless the pattern has RE_NREGS or more ('s). */ - *stackp++ = b - bufp->buffer; - if (regnum < RE_NREGS) - { - BUFPUSH (start_memory); - BUFPUSH (regnum); - } - *stackp++ = fixup_jump ? fixup_jump - bufp->buffer + 1 : 0; - *stackp++ = regnum++; - *stackp++ = begalt - bufp->buffer; - fixup_jump = 0; - laststart = 0; - begalt = b; - break; - - case ')': - if (obscure_syntax & RE_NO_BK_PARENS) - goto normal_backsl; - handle_close: - if (stackp == stackb) goto unmatched_close; - begalt = *--stackp + bufp->buffer; - if (fixup_jump) - store_jump (fixup_jump, jump, b); - if (stackp[-1] < RE_NREGS) - { - BUFPUSH (stop_memory); - BUFPUSH (stackp[-1]); - } - stackp -= 2; - fixup_jump = *stackp ? *stackp + bufp->buffer - 1 : 0; - laststart = *--stackp + bufp->buffer; - break; - - case '|': - if ((obscure_syntax & RE_LIMITED_OPS) - || (obscure_syntax & RE_NO_BK_VBAR)) - goto normal_backsl; - handle_bar: - if (obscure_syntax & RE_LIMITED_OPS) - goto normal_char; - /* Insert before the previous alternative a jump which - jumps to this alternative if the former fails. */ - GET_BUFFER_SPACE (6); - insert_jump (on_failure_jump, begalt, b + 6, b); - pending_exact = 0; - b += 3; - /* The alternative before the previous alternative has a - jump after it which gets executed if it gets matched. - Adjust that jump so it will jump to the previous - alternative's analogous jump (put in below, which in - turn will jump to the next (if any) alternative's such - jump, etc.). The last such jump jumps to the correct - final destination. */ - if (fixup_jump) - store_jump (fixup_jump, jump, b); - - /* Leave space for a jump after previous alternative---to be - filled in later. */ - fixup_jump = b; - b += 3; - - laststart = 0; - begalt = b; - break; - - case '{': - if (! (obscure_syntax & RE_INTERVALS) - /* Let \{ be a literal. */ - || ((obscure_syntax & RE_INTERVALS) - && (obscure_syntax & RE_NO_BK_CURLY_BRACES)) - /* If it's the string "\{". */ - || (p - 2 == pattern && p == pend)) - goto normal_backsl; - handle_interval: - beg_interval = p - 1; /* The {. */ - /* If there is no previous pattern, this isn't an interval. */ - if (!laststart) - { - if (obscure_syntax & RE_CONTEXTUAL_INVALID_OPS) - goto invalid_pattern; - else - goto normal_backsl; - } - /* It also isn't an interval if not preceded by an re - matching a single character or subexpression, or if - the current type of intervals can't handle back - references and the previous thing is a back reference. */ - if (! (*laststart == anychar - || *laststart == charset - || *laststart == charset_not - || *laststart == start_memory - || (*laststart == exactn && laststart[1] == 1) - || (! (obscure_syntax & RE_NO_BK_REFS) - && *laststart == duplicate))) - { - if (obscure_syntax & RE_NO_BK_CURLY_BRACES) - goto normal_char; - - /* Posix extended syntax is handled in previous - statement; this is for Posix basic syntax. */ - if (obscure_syntax & RE_INTERVALS) - goto invalid_pattern; - - goto normal_backsl; - } - lower_bound = -1; /* So can see if are set. */ - upper_bound = -1; - GET_UNSIGNED_NUMBER (lower_bound); - if (c == ',') - { - GET_UNSIGNED_NUMBER (upper_bound); - if (upper_bound < 0) - upper_bound = RE_DUP_MAX; - } - if (upper_bound < 0) - upper_bound = lower_bound; - if (! (obscure_syntax & RE_NO_BK_CURLY_BRACES)) - { - if (c != '\\') - goto invalid_pattern; - PATFETCH (c); - } - if (c != '}' || lower_bound < 0 || upper_bound > RE_DUP_MAX - || lower_bound > upper_bound - || ((obscure_syntax & RE_NO_BK_CURLY_BRACES) - && p != pend && *p == '{')) - { - if (obscure_syntax & RE_NO_BK_CURLY_BRACES) - goto unfetch_interval; - else - goto invalid_pattern; - } - - /* If upper_bound is zero, don't want to succeed at all; - jump from laststart to b + 3, which will be the end of - the buffer after this jump is inserted. */ - - if (upper_bound == 0) - { - GET_BUFFER_SPACE (3); - insert_jump (jump, laststart, b + 3, b); - b += 3; - } - - /* Otherwise, after lower_bound number of succeeds, jump - to after the jump_n which will be inserted at the end - of the buffer, and insert that jump_n. */ - else - { /* Set to 5 if only one repetition is allowed and - hence no jump_n is inserted at the current end of - the buffer; then only space for the succeed_n is - needed. Otherwise, need space for both the - succeed_n and the jump_n. */ - - unsigned slots_needed = upper_bound == 1 ? 5 : 10; - - GET_BUFFER_SPACE ((int) slots_needed); - /* Initialize the succeed_n to n, even though it will - be set by its attendant set_number_at, because - re_compile_fastmap will need to know it. Jump to - what the end of buffer will be after inserting - this succeed_n and possibly appending a jump_n. */ - insert_jump_n (succeed_n, laststart, b + slots_needed, - b, lower_bound); - b += 5; /* Just increment for the succeed_n here. */ - - /* More than one repetition is allowed, so put in at - the end of the buffer a backward jump from b to the - succeed_n we put in above. By the time we've gotten - to this jump when matching, we'll have matched once - already, so jump back only upper_bound - 1 times. */ - - if (upper_bound > 1) - { - store_jump_n (b, jump_n, laststart, upper_bound - 1); - b += 5; - /* When hit this when matching, reset the - preceding jump_n's n to upper_bound - 1. */ - BUFPUSH (set_number_at); - GET_BUFFER_SPACE (2); - STORE_NUMBER_AND_INCR (b, -5); - STORE_NUMBER_AND_INCR (b, upper_bound - 1); - } - /* When hit this when matching, set the succeed_n's n. */ - GET_BUFFER_SPACE (5); - insert_op_2 (set_number_at, laststart, b, 5, lower_bound); - b += 5; - } - pending_exact = 0; - beg_interval = 0; - break; - - - unfetch_interval: - /* If an invalid interval, match the characters as literals. */ - if (beg_interval) - p = beg_interval; - else - { - fprintf (stderr, - "regex: no interval beginning to which to backtrack.\n"); - exit (1); - } - - beg_interval = 0; - PATFETCH (c); /* normal_char expects char in `c'. */ - goto normal_char; - break; - -#ifdef emacs - case '=': - BUFPUSH (at_dot); - break; - - case 's': - laststart = b; - BUFPUSH (syntaxspec); - PATFETCH (c); - BUFPUSH (syntax_spec_code[c]); - break; - - case 'S': - laststart = b; - BUFPUSH (notsyntaxspec); - PATFETCH (c); - BUFPUSH (syntax_spec_code[c]); - break; -#endif /* emacs */ - - case 'w': - laststart = b; - BUFPUSH (wordchar); - break; - - case 'W': - laststart = b; - BUFPUSH (notwordchar); - break; - - case '<': - BUFPUSH (wordbeg); - break; - - case '>': - BUFPUSH (wordend); - break; - - case 'b': - BUFPUSH (wordbound); - break; - - case 'B': - BUFPUSH (notwordbound); - break; - - case '`': - BUFPUSH (begbuf); - break; - - case '\'': - BUFPUSH (endbuf); - break; - - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (obscure_syntax & RE_NO_BK_REFS) - goto normal_char; - c1 = c - '0'; - if (c1 >= regnum) - { - if (obscure_syntax & RE_NO_EMPTY_BK_REF) - goto invalid_pattern; - else - goto normal_char; - } - /* Can't back reference to a subexpression if inside of it. */ - for (stackt = stackp - 2; stackt > stackb; stackt -= 4) - if (*stackt == c1) - goto normal_char; - laststart = b; - BUFPUSH (duplicate); - BUFPUSH (c1); - break; - - case '+': - case '?': - if (obscure_syntax & RE_BK_PLUS_QM) - goto handle_plus; - else - goto normal_backsl; - break; - - default: - normal_backsl: - /* You might think it would be useful for \ to mean - not to translate; but if we don't translate it - it will never match anything. */ - if (translate) c = translate[c]; - goto normal_char; - } - break; - - default: - normal_char: /* Expects the character in `c'. */ - if (!pending_exact || pending_exact + *pending_exact + 1 != b - || *pending_exact == 0177 || *p == '*' || *p == '^' - || ((obscure_syntax & RE_BK_PLUS_QM) - ? *p == '\\' && (p[1] == '+' || p[1] == '?') - : (*p == '+' || *p == '?')) - || ((obscure_syntax & RE_INTERVALS) - && ((obscure_syntax & RE_NO_BK_CURLY_BRACES) - ? *p == '{' - : (p[0] == '\\' && p[1] == '{')))) - { - laststart = b; - BUFPUSH (exactn); - pending_exact = b; - BUFPUSH (0); - } - BUFPUSH (c); - (*pending_exact)++; - } - } - - if (fixup_jump) - store_jump (fixup_jump, jump, b); - - if (stackp != stackb) goto unmatched_open; - - bufp->used = b - bufp->buffer; - return 0; - - invalid_pattern: - return "Invalid regular expression"; - - unmatched_open: - return "Unmatched \\("; - - unmatched_close: - return "Unmatched \\)"; - - end_of_pattern: - return "Premature end of regular expression"; - - nesting_too_deep: - return "Nesting too deep"; - - too_big: - return "Regular expression too big"; - - memory_exhausted: - return "Memory exhausted"; -} - - -/* Store a jump of the form . - Store in the location FROM a jump operation to jump to relative - address FROM - TO. OPCODE is the opcode to store. */ - -static void -store_jump (char *from, char opcode, char *to) -{ - from[0] = opcode; - STORE_NUMBER(from + 1, to - (from + 3)); -} - - -/* Open up space before char FROM, and insert there a jump to TO. - CURRENT_END gives the end of the storage not in use, so we know - how much data to copy up. OP is the opcode of the jump to insert. - - If you call this function, you must zero out pending_exact. */ - -static void -insert_jump (char op, char *from, char *to, char *current_end) -{ - register char *pfrom = current_end; /* Copy from here... */ - register char *pto = current_end + 3; /* ...to here. */ - - while (pfrom != from) - *--pto = *--pfrom; - store_jump (from, op, to); -} - - -/* Store a jump of the form . - - Store in the location FROM a jump operation to jump to relative - address FROM - TO. OPCODE is the opcode to store, N is a number the - jump uses, say, to decide how many times to jump. - - If you call this function, you must zero out pending_exact. */ - -static void -store_jump_n (char *from, char opcode, char *to, unsigned n) -{ - from[0] = opcode; - STORE_NUMBER (from + 1, to - (from + 3)); - STORE_NUMBER (from + 3, n); -} - - -/* Similar to insert_jump, but handles a jump which needs an extra - number to handle minimum and maximum cases. Open up space at - location FROM, and insert there a jump to TO. CURRENT_END gives the - end of the storage in use, so we know how much data to copy up. OP is - the opcode of the jump to insert. - - If you call this function, you must zero out pending_exact. */ - -static void -insert_jump_n (char op, char *from, char *to, char *current_end, unsigned n) -{ - register char *pfrom = current_end; /* Copy from here... */ - register char *pto = current_end + 5; /* ...to here. */ - - while (pfrom != from) - *--pto = *--pfrom; - store_jump_n (from, op, to, n); -} - - -/* Open up space at location THERE, and insert operation OP followed by - NUM_1 and NUM_2. CURRENT_END gives the end of the storage in use, so - we know how much data to copy up. - - If you call this function, you must zero out pending_exact. */ - -static void -insert_op_2 (char op, char *there, char *current_end, int num_1, int num_2) -{ - register char *pfrom = current_end; /* Copy from here... */ - register char *pto = current_end + 5; /* ...to here. */ - - while (pfrom != there) - *--pto = *--pfrom; - - there[0] = op; - STORE_NUMBER (there + 1, num_1); - STORE_NUMBER (there + 3, num_2); -} - - - -/* Given a pattern, compute a fastmap from it. The fastmap records - which of the (1 << BYTEWIDTH) possible characters can start a string - that matches the pattern. This fastmap is used by re_search to skip - quickly over totally implausible text. - - The caller must supply the address of a (1 << BYTEWIDTH)-byte data - area as bufp->fastmap. - The other components of bufp describe the pattern to be used. */ - -void -re_compile_fastmap (struct re_pattern_buffer *bufp) -{ - unsigned char *pattern = (unsigned char *) bufp->buffer; - int size = bufp->used; - register char *fastmap = bufp->fastmap; - register unsigned char *p = pattern; - register unsigned char *pend = pattern + size; - register int j, k; - unsigned char *translate = (unsigned char *) bufp->translate; - - unsigned char *stackb[NFAILURES]; - unsigned char **stackp = stackb; - - unsigned is_a_succeed_n; - - memset (fastmap, 0, (1 << BYTEWIDTH)); - bufp->fastmap_accurate = 1; - bufp->can_be_null = 0; - - while (p) - { - is_a_succeed_n = 0; - if (p == pend) - { - bufp->can_be_null = 1; - break; - } -#ifdef SWITCH_ENUM_BUG - switch ((int) ((enum regexpcode) *p++)) -#else - switch ((enum regexpcode) *p++) -#endif - { - case exactn: - if (translate) - fastmap[translate[p[1]]] = 1; - else - fastmap[p[1]] = 1; - break; - - case unused: - case begline: -#ifdef emacs - case before_dot: - case at_dot: - case after_dot: -#endif - case begbuf: - case endbuf: - case wordbound: - case notwordbound: - case wordbeg: - case wordend: - continue; - - case endline: - if (translate) - fastmap[translate['\n']] = 1; - else - fastmap['\n'] = 1; - - if (bufp->can_be_null != 1) - bufp->can_be_null = 2; - break; - - case jump_n: - case finalize_jump: - case maybe_finalize_jump: - case jump: - case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); - p += j; - if (j > 0) - continue; - /* Jump backward reached implies we just went through - the body of a loop and matched nothing. - Opcode jumped to should be an on_failure_jump. - Just treat it like an ordinary jump. - For a * loop, it has pushed its failure point already; - If so, discard that as redundant. */ - - if ((enum regexpcode) *p != on_failure_jump - && (enum regexpcode) *p != succeed_n) - continue; - p++; - EXTRACT_NUMBER_AND_INCR (j, p); - p += j; - if (stackp != stackb && *stackp == p) - stackp--; - continue; - - case on_failure_jump: - handle_on_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); - *++stackp = p + j; - if (is_a_succeed_n) - EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */ - continue; - - case succeed_n: - is_a_succeed_n = 1; - /* Get to the number of times to succeed. */ - p += 2; - /* Increment p past the n for when k != 0. */ - EXTRACT_NUMBER_AND_INCR (k, p); - if (k == 0) - { - p -= 4; - goto handle_on_failure_jump; - } - continue; - - case set_number_at: - p += 4; - continue; - - case start_memory: - case stop_memory: - p++; - continue; - - case duplicate: - bufp->can_be_null = 1; - fastmap['\n'] = 1; - case anychar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (j != '\n') - fastmap[j] = 1; - if (bufp->can_be_null) - return; - /* Don't return; check the alternative paths - so we can set can_be_null if appropriate. */ - break; - - case wordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == Sword) - fastmap[j] = 1; - break; - - case notwordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != Sword) - fastmap[j] = 1; - break; - -#ifdef emacs - case syntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == (enum syntaxcode) k) - fastmap[j] = 1; - break; - - case notsyntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != (enum syntaxcode) k) - fastmap[j] = 1; - break; -#endif /* not emacs */ - - case charset: - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) - { - if (translate) - fastmap[translate[j]] = 1; - else - fastmap[j] = 1; - } - break; - - case charset_not: - /* Chars beyond end of map must be allowed */ - for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) - if (translate) - fastmap[translate[j]] = 1; - else - fastmap[j] = 1; - - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) - { - if (translate) - fastmap[translate[j]] = 1; - else - fastmap[j] = 1; - } - break; - } - - /* Get here means we have successfully found the possible starting - characters of one path of the pattern. We need not follow this - path any farther. Instead, look at the next alternative - remembered in the stack. */ - if (stackp != stackb) - p = *stackp--; - else - break; - } -} - - - -/* Like re_search_2, below, but only one string is specified, and - doesn't let you say where to stop matching. */ - -int -re_search (struct re_pattern_buffer *pbufp, - char *string, - int size, - int startpos, - int range, - struct re_registers *regs) -{ - return re_search_2 (pbufp, (char *) 0, 0, string, size, startpos, range, - regs, size); -} - - -/* Using the compiled pattern in PBUFP->buffer, first tries to match the - virtual concatenation of STRING1 and STRING2, starting first at index - STARTPOS, then at STARTPOS + 1, and so on. RANGE is the number of - places to try before giving up. If RANGE is negative, it searches - backwards, i.e., the starting positions tried are STARTPOS, STARTPOS - - 1, etc. STRING1 and STRING2 are of SIZE1 and SIZE2, respectively. - In REGS, return the indices of the virtual concatenation of STRING1 - and STRING2 that matched the entire PBUFP->buffer and its contained - subexpressions. Do not consider matching one past the index MSTOP in - the virtual concatenation of STRING1 and STRING2. - - The value returned is the position in the strings at which the match - was found, or -1 if no match was found, or -2 if error (such as - failure stack overflow). */ - -int -re_search_2 (struct re_pattern_buffer *pbufp, - char *string1, int size1, - char *string2, int size2, - int startpos, - register int range, - struct re_registers *regs, - int mstop) -{ - register char *fastmap = pbufp->fastmap; - register unsigned char *translate = (unsigned char *) pbufp->translate; - int total_size = size1 + size2; - int endpos = startpos + range; - int val; - - /* Check for out-of-range starting position. */ - if (startpos < 0 || startpos > total_size) - return -1; - - /* Fix up range if it would eventually take startpos outside of the - virtual concatenation of string1 and string2. */ - if (endpos < -1) - range = -1 - startpos; - else if (endpos > total_size) - range = total_size - startpos; - - /* Update the fastmap now if not correct already. */ - if (fastmap && !pbufp->fastmap_accurate) - re_compile_fastmap (pbufp); - - /* If the search isn't to be a backwards one, don't waste time in a - long search for a pattern that says it is anchored. */ - if (pbufp->used > 0 && (enum regexpcode) pbufp->buffer[0] == begbuf - && range > 0) - { - if (startpos > 0) - return -1; - else - range = 1; - } - - while (1) - { - /* If a fastmap is supplied, skip quickly over characters that - cannot possibly be the start of a match. Note, however, that - if the pattern can possibly match the null string, we must - test it at each starting point so that we take the first null - string we get. */ - - if (fastmap && startpos < total_size && pbufp->can_be_null != 1) - { - if (range > 0) /* Searching forwards. */ - { - register int lim = 0; - register unsigned char *p; - int irange = range; - if (startpos < size1 && startpos + range >= size1) - lim = range - (size1 - startpos); - - p = ((unsigned char *) - &(startpos >= size1 ? string2 - size1 : string1)[startpos]); - - while (range > lim && !fastmap[translate - ? translate[*p++] - : *p++]) - range--; - startpos += irange - range; - } - else /* Searching backwards. */ - { - register unsigned char c; - - if (string1 == 0 || startpos >= size1) - c = string2[startpos - size1]; - else - c = string1[startpos]; - - c &= 0xff; - if (translate ? !fastmap[translate[c]] : !fastmap[c]) - goto advance; - } - } - - if (range >= 0 && startpos == total_size - && fastmap && pbufp->can_be_null == 0) - return -1; - - val = re_match_2 (pbufp, string1, size1, string2, size2, startpos, - regs, mstop); - if (val >= 0) - return startpos; - if (val == -2) - return -2; - -#ifdef C_ALLOCA - alloca (0); -#endif /* C_ALLOCA */ - - advance: - if (!range) - break; - else if (range > 0) - { - range--; - startpos++; - } - else - { - range++; - startpos--; - } - } - return -1; -} - - - -#ifndef emacs /* emacs never uses this. */ -int -re_match (struct re_pattern_buffer *pbufp, - char *string, - int size, - int pos, - struct re_registers *regs) -{ - return re_match_2 (pbufp, (char *) 0, 0, string, size, pos, regs, size); -} -#endif /* not emacs */ - - -/* The following are used for re_match_2, defined below: */ - -/* Roughly the maximum number of failure points on the stack. Would be - exactly that if always pushed MAX_NUM_FAILURE_ITEMS each time we failed. */ - -int re_max_failures = 2000; - -/* Routine used by re_match_2. */ -static int bcmp_translate (char *, char *, int, unsigned char *); - - -/* Structure and accessing macros used in re_match_2: */ - -struct register_info -{ - unsigned is_active : 1; - unsigned matched_something : 1; -}; - -#define IS_ACTIVE(R) ((R).is_active) -#define MATCHED_SOMETHING(R) ((R).matched_something) - - -/* Macros used by re_match_2: */ - - -/* I.e., regstart, regend, and reg_info. */ - -#define NUM_REG_ITEMS 3 - -/* We push at most this many things on the stack whenever we - fail. The `+ 2' refers to PATTERN_PLACE and STRING_PLACE, which are - arguments to the PUSH_FAILURE_POINT macro. */ - -#define MAX_NUM_FAILURE_ITEMS (RE_NREGS * NUM_REG_ITEMS + 2) - - -/* We push this many things on the stack whenever we fail. */ - -#define NUM_FAILURE_ITEMS (last_used_reg * NUM_REG_ITEMS + 2) - - -/* This pushes most of the information about the current state we will want - if we ever fail back to it. */ - -#define PUSH_FAILURE_POINT(pattern_place, string_place) \ - { \ - short last_used_reg, this_reg; \ - \ - /* Find out how many registers are active or have been matched. \ - (Aside from register zero, which is only set at the end.) */ \ - for (last_used_reg = RE_NREGS - 1; last_used_reg > 0; last_used_reg--)\ - if (regstart[last_used_reg] != (unsigned char *) -1) \ - break; \ - \ - if (stacke - stackp < NUM_FAILURE_ITEMS) \ - { \ - unsigned char **stackx; \ - int len = stacke - stackb; \ - if (len > re_max_failures * MAX_NUM_FAILURE_ITEMS) \ - return -2; \ - \ - /* Roughly double the size of the stack. */ \ - stackx = (unsigned char **) alloca (2 * len \ - * sizeof (unsigned char *));\ - /* Only copy what is in use. */ \ - memcpy (stackx, stackb, len * sizeof (char *)); \ - stackp = stackx + (stackp - stackb); \ - stackb = stackx; \ - stacke = stackb + 2 * len; \ - } \ - \ - /* Now push the info for each of those registers. */ \ - for (this_reg = 1; this_reg <= last_used_reg; this_reg++) \ - { \ - *stackp++ = regstart[this_reg]; \ - *stackp++ = regend[this_reg]; \ - *stackp++ = (unsigned char *) ®_info[this_reg]; \ - } \ - \ - /* Push how many registers we saved. */ \ - *stackp++ = (unsigned char *) last_used_reg; \ - \ - *stackp++ = pattern_place; \ - *stackp++ = string_place; \ - } - - -/* This pops what PUSH_FAILURE_POINT pushes. */ - -#define POP_FAILURE_POINT() \ - { \ - int temp; \ - stackp -= 2; /* Remove failure points. */ \ - temp = (int) *--stackp; /* How many regs pushed. */ \ - temp *= NUM_REG_ITEMS; /* How much to take off the stack. */ \ - stackp -= temp; /* Remove the register info. */ \ - } - - -#define MATCHING_IN_FIRST_STRING (dend == end_match_1) - -/* Is true if there is a first string and if PTR is pointing anywhere - inside it or just past the end. */ - -#define IS_IN_FIRST_STRING(ptr) \ - (size1 && string1 <= (ptr) && (ptr) <= string1 + size1) - -/* Call before fetching a character with *d. This switches over to - string2 if necessary. */ - -#define PREFETCH \ - while (d == dend) \ - { \ - /* end of string2 => fail. */ \ - if (dend == end_match_2) \ - goto fail; \ - /* end of string1 => advance to string2. */ \ - d = string2; \ - dend = end_match_2; \ - } - - -/* Call this when have matched something; it sets `matched' flags for the - registers corresponding to the subexpressions of which we currently - are inside. */ -#define SET_REGS_MATCHED \ - { unsigned this_reg; \ - for (this_reg = 0; this_reg < RE_NREGS; this_reg++) \ - { \ - if (IS_ACTIVE(reg_info[this_reg])) \ - MATCHED_SOMETHING(reg_info[this_reg]) = 1; \ - else \ - MATCHED_SOMETHING(reg_info[this_reg]) = 0; \ - } \ - } - -/* Test if at very beginning or at very end of the virtual concatenation - of string1 and string2. If there is only one string, we've put it in - string2. */ - -#define AT_STRINGS_BEG (d == (size1 ? string1 : string2) || !size2) -#define AT_STRINGS_END (d == end2) - -#define AT_WORD_BOUNDARY \ - (AT_STRINGS_BEG || AT_STRINGS_END || IS_A_LETTER (d - 1) != IS_A_LETTER (d)) - -/* We have two special cases to check for: - 1) if we're past the end of string1, we have to look at the first - character in string2; - 2) if we're before the beginning of string2, we have to look at the - last character in string1; we assume there is a string1, so use - this in conjunction with AT_STRINGS_BEG. */ -#define IS_A_LETTER(d) \ - (SYNTAX ((d) == end1 ? *string2 : (d) == string2 - 1 ? *(end1 - 1) : *(d))\ - == Sword) - - -/* Match the pattern described by PBUFP against the virtual - concatenation of STRING1 and STRING2, which are of SIZE1 and SIZE2, - respectively. Start the match at index POS in the virtual - concatenation of STRING1 and STRING2. In REGS, return the indices of - the virtual concatenation of STRING1 and STRING2 that matched the - entire PBUFP->buffer and its contained subexpressions. Do not - consider matching one past the index MSTOP in the virtual - concatenation of STRING1 and STRING2. - - If pbufp->fastmap is nonzero, then it had better be up to date. - - The reason that the data to match are specified as two components - which are to be regarded as concatenated is so this function can be - used directly on the contents of an Emacs buffer. - - -1 is returned if there is no match. -2 is returned if there is an - error (such as match stack overflow). Otherwise the value is the - length of the substring which was matched. */ - -int -re_match_2 (struct re_pattern_buffer *pbufp, - char *string1_arg, int size1, - char *string2_arg, int size2, - int pos, - struct re_registers *regs, - int mstop) -{ - register unsigned char *p = (unsigned char *) pbufp->buffer; - - /* Pointer to beyond end of buffer. */ - register unsigned char *pend = p + pbufp->used; - - unsigned char *string1 = (unsigned char *) string1_arg; - unsigned char *string2 = (unsigned char *) string2_arg; - unsigned char *end1; /* Just past end of first string. */ - unsigned char *end2; /* Just past end of second string. */ - - /* Pointers into string1 and string2, just past the last characters in - each to consider matching. */ - unsigned char *end_match_1, *end_match_2; - - register unsigned char *d, *dend; - register int mcnt; /* Multipurpose. */ - unsigned char *translate = (unsigned char *) pbufp->translate; - unsigned is_a_jump_n = 0; - - /* Failure point stack. Each place that can handle a failure further - down the line pushes a failure point on this stack. It consists of - restart, regend, and reg_info for all registers corresponding to the - subexpressions we're currently inside, plus the number of such - registers, and, finally, two char *'s. The first char * is where to - resume scanning the pattern; the second one is where to resume - scanning the strings. If the latter is zero, the failure point is a - ``dummy''; if a failure happens and the failure point is a dummy, it - gets discarded and the next next one is tried. */ - - unsigned char *initial_stack[MAX_NUM_FAILURE_ITEMS * NFAILURES]; - unsigned char **stackb = initial_stack; - unsigned char **stackp = stackb; - unsigned char **stacke = &stackb[MAX_NUM_FAILURE_ITEMS * NFAILURES]; - - - /* Information on the contents of registers. These are pointers into - the input strings; they record just what was matched (on this - attempt) by a subexpression part of the pattern, that is, the - regnum-th regstart pointer points to where in the pattern we began - matching and the regnum-th regend points to right after where we - stopped matching the regnum-th subexpression. (The zeroth register - keeps track of what the whole pattern matches.) */ - - unsigned char *regstart[RE_NREGS]; - unsigned char *regend[RE_NREGS]; - - /* The is_active field of reg_info helps us keep track of which (possibly - nested) subexpressions we are currently in. The matched_something - field of reg_info[reg_num] helps us tell whether or not we have - matched any of the pattern so far this time through the reg_num-th - subexpression. These two fields get reset each time through any - loop their register is in. */ - - struct register_info reg_info[RE_NREGS]; - - - /* The following record the register info as found in the above - variables when we find a match better than any we've seen before. - This happens as we backtrack through the failure points, which in - turn happens only if we have not yet matched the entire string. */ - - unsigned best_regs_set = 0; - unsigned char *best_regstart[RE_NREGS]; - unsigned char *best_regend[RE_NREGS]; - - /* Initialize subexpression text positions to -1 to mark ones that no - \( or ( and \) or ) has been seen for. Also set all registers to - inactive and mark them as not having matched anything or ever - failed. */ - for (mcnt = 0; mcnt < RE_NREGS; mcnt++) - { - regstart[mcnt] = regend[mcnt] = (unsigned char *) -1; - IS_ACTIVE (reg_info[mcnt]) = 0; - MATCHED_SOMETHING (reg_info[mcnt]) = 0; - } - - if (regs) - for (mcnt = 0; mcnt < RE_NREGS; mcnt++) - regs->start[mcnt] = regs->end[mcnt] = -1; - - /* Set up pointers to ends of strings. - Don't allow the second string to be empty unless both are empty. */ - if (size2 == 0) - { - string2 = string1; - size2 = size1; - string1 = 0; - size1 = 0; - } - end1 = string1 + size1; - end2 = string2 + size2; - - /* Compute where to stop matching, within the two strings. */ - if (mstop <= size1) - { - end_match_1 = string1 + mstop; - end_match_2 = string2; - } - else - { - end_match_1 = end1; - end_match_2 = string2 + mstop - size1; - } - - /* `p' scans through the pattern as `d' scans through the data. `dend' - is the end of the input string that `d' points within. `d' is - advanced into the following input string whenever necessary, but - this happens before fetching; therefore, at the beginning of the - loop, `d' can be pointing at the end of a string, but it cannot - equal string2. */ - - if (size1 != 0 && pos <= size1) - d = string1 + pos, dend = end_match_1; - else - d = string2 + pos - size1, dend = end_match_2; - - - /* This loops over pattern commands. It exits by returning from the - function if match is complete, or it drops through if match fails - at this starting point in the input data. */ - - while (1) - { - is_a_jump_n = 0; - /* End of pattern means we might have succeeded. */ - if (p == pend) - { - /* If not end of string, try backtracking. Otherwise done. */ - if (d != end_match_2) - { - if (stackp != stackb) - { - /* More failure points to try. */ - - unsigned in_same_string = - IS_IN_FIRST_STRING (best_regend[0]) - == MATCHING_IN_FIRST_STRING; - - /* If exceeds best match so far, save it. */ - if (! best_regs_set - || (in_same_string && d > best_regend[0]) - || (! in_same_string && ! MATCHING_IN_FIRST_STRING)) - { - best_regs_set = 1; - best_regend[0] = d; /* Never use regstart[0]. */ - - for (mcnt = 1; mcnt < RE_NREGS; mcnt++) - { - best_regstart[mcnt] = regstart[mcnt]; - best_regend[mcnt] = regend[mcnt]; - } - } - goto fail; - } - /* If no failure points, don't restore garbage. */ - else if (best_regs_set) - { - restore_best_regs: - /* Restore best match. */ - d = best_regend[0]; - - for (mcnt = 0; mcnt < RE_NREGS; mcnt++) - { - regstart[mcnt] = best_regstart[mcnt]; - regend[mcnt] = best_regend[mcnt]; - } - } - } - - /* If caller wants register contents data back, convert it - to indices. */ - if (regs) - { - regs->start[0] = pos; - if (MATCHING_IN_FIRST_STRING) - regs->end[0] = d - string1; - else - regs->end[0] = d - string2 + size1; - for (mcnt = 1; mcnt < RE_NREGS; mcnt++) - { - if (regend[mcnt] == (unsigned char *) -1) - { - regs->start[mcnt] = -1; - regs->end[mcnt] = -1; - continue; - } - if (IS_IN_FIRST_STRING (regstart[mcnt])) - regs->start[mcnt] = regstart[mcnt] - string1; - else - regs->start[mcnt] = regstart[mcnt] - string2 + size1; - - if (IS_IN_FIRST_STRING (regend[mcnt])) - regs->end[mcnt] = regend[mcnt] - string1; - else - regs->end[mcnt] = regend[mcnt] - string2 + size1; - } - } - return d - pos - (MATCHING_IN_FIRST_STRING - ? string1 - : string2 - size1); - } - - /* Otherwise match next pattern command. */ -#ifdef SWITCH_ENUM_BUG - switch ((int) ((enum regexpcode) *p++)) -#else - switch ((enum regexpcode) *p++) -#endif - { - - /* \( [or `(', as appropriate] is represented by start_memory, - \) by stop_memory. Both of those commands are followed by - a register number in the next byte. The text matched - within the \( and \) is recorded under that number. */ - case start_memory: - regstart[*p] = d; - IS_ACTIVE (reg_info[*p]) = 1; - MATCHED_SOMETHING (reg_info[*p]) = 0; - p++; - break; - - case stop_memory: - regend[*p] = d; - IS_ACTIVE (reg_info[*p]) = 0; - - /* If just failed to match something this time around with a sub- - expression that's in a loop, try to force exit from the loop. */ - if ((! MATCHED_SOMETHING (reg_info[*p]) - || (enum regexpcode) p[-3] == start_memory) - && (p + 1) != pend) - { - register unsigned char *p2 = p + 1; - mcnt = 0; - switch (*p2++) - { - case jump_n: - is_a_jump_n = 1; - case finalize_jump: - case maybe_finalize_jump: - case jump: - case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p2); - if (is_a_jump_n) - p2 += 2; - break; - } - p2 += mcnt; - - /* If the next operation is a jump backwards in the pattern - to an on_failure_jump, exit from the loop by forcing a - failure after pushing on the stack the on_failure_jump's - jump in the pattern, and d. */ - if (mcnt < 0 && (enum regexpcode) *p2++ == on_failure_jump) - { - EXTRACT_NUMBER_AND_INCR (mcnt, p2); - PUSH_FAILURE_POINT (p2 + mcnt, d); - goto fail; - } - } - p++; - break; - - /* \ has been turned into a `duplicate' command which is - followed by the numeric value of as the register number. */ - case duplicate: - { - int regno = *p++; /* Get which register to match against */ - register unsigned char *d2, *dend2; - - /* Where in input to try to start matching. */ - d2 = regstart[regno]; - - /* Where to stop matching; if both the place to start and - the place to stop matching are in the same string, then - set to the place to stop, otherwise, for now have to use - the end of the first string. */ - - dend2 = ((IS_IN_FIRST_STRING (regstart[regno]) - == IS_IN_FIRST_STRING (regend[regno])) - ? regend[regno] : end_match_1); - while (1) - { - /* If necessary, advance to next segment in register - contents. */ - while (d2 == dend2) - { - if (dend2 == end_match_2) break; - if (dend2 == regend[regno]) break; - d2 = string2, dend2 = regend[regno]; /* end of string1 => advance to string2. */ - } - /* At end of register contents => success */ - if (d2 == dend2) break; - - /* If necessary, advance to next segment in data. */ - PREFETCH; - - /* How many characters left in this segment to match. */ - mcnt = dend - d; - - /* Want how many consecutive characters we can match in - one shot, so, if necessary, adjust the count. */ - if (mcnt > dend2 - d2) - mcnt = dend2 - d2; - - /* Compare that many; failure if mismatch, else move - past them. */ - if (translate - ? bcmp_translate ((char*)d, (char*)d2, mcnt, translate) - : memcmp (d, d2, mcnt)) - goto fail; - d += mcnt, d2 += mcnt; - } - } - break; - - case anychar: - PREFETCH; /* Fetch a data character. */ - /* Match anything but a newline, maybe even a null. */ - if ((translate ? translate[*d] : *d) == '\n' - || ((obscure_syntax & RE_DOT_NOT_NULL) - && (translate ? translate[*d] : *d) == '\000')) - goto fail; - SET_REGS_MATCHED; - d++; - break; - - case charset: - case charset_not: - { - int not = 0; /* Nonzero for charset_not. */ - register int c; - if (*(p - 1) == (unsigned char) charset_not) - not = 1; - - PREFETCH; /* Fetch a data character. */ - - if (translate) - c = translate[*d]; - else - c = *d; - - if (c < *p * BYTEWIDTH - && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - p += 1 + *p; - - if (!not) goto fail; - SET_REGS_MATCHED; - d++; - break; - } - - case begline: - if ((size1 != 0 && d == string1) - || (size1 == 0 && size2 != 0 && d == string2) - || (d && d[-1] == '\n') - || (size1 == 0 && size2 == 0)) - break; - else - goto fail; - - case endline: - if (d == end2 - || (d == end1 ? (size2 == 0 || *string2 == '\n') : *d == '\n')) - break; - goto fail; - - /* `or' constructs are handled by starting each alternative with - an on_failure_jump that points to the start of the next - alternative. Each alternative except the last ends with a - jump to the joining point. (Actually, each jump except for - the last one really jumps to the following jump, because - tensioning the jumps is a hassle.) */ - - /* The start of a stupid repeat has an on_failure_jump that points - past the end of the repeat text. This makes a failure point so - that on failure to match a repetition, matching restarts past - as many repetitions have been found with no way to fail and - look for another one. */ - - /* A smart repeat is similar but loops back to the on_failure_jump - so that each repetition makes another failure point. */ - - case on_failure_jump: - on_failure: - EXTRACT_NUMBER_AND_INCR (mcnt, p); - PUSH_FAILURE_POINT (p + mcnt, d); - break; - - /* The end of a smart repeat has a maybe_finalize_jump back. - Change it either to a finalize_jump or an ordinary jump. */ - case maybe_finalize_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p); - { - register unsigned char *p2 = p; - /* Compare what follows with the beginning of the repeat. - If we can establish that there is nothing that they would - both match, we can change to finalize_jump. */ - while (p2 + 1 != pend - && (*p2 == (unsigned char) stop_memory - || *p2 == (unsigned char) start_memory)) - p2 += 2; /* Skip over reg number. */ - if (p2 == pend) - p[-3] = (unsigned char) finalize_jump; - else if (*p2 == (unsigned char) exactn - || *p2 == (unsigned char) endline) - { - register int c = *p2 == (unsigned char) endline ? '\n' : p2[2]; - register unsigned char *p1 = p + mcnt; - /* p1[0] ... p1[2] are an on_failure_jump. - Examine what follows that. */ - if (p1[3] == (unsigned char) exactn && p1[5] != c) - p[-3] = (unsigned char) finalize_jump; - else if (p1[3] == (unsigned char) charset - || p1[3] == (unsigned char) charset_not) - { - int not = p1[3] == (unsigned char) charset_not; - if (c < p1[4] * BYTEWIDTH - && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - /* `not' is 1 if c would match. */ - /* That means it is not safe to finalize. */ - if (!not) - p[-3] = (unsigned char) finalize_jump; - } - } - } - p -= 2; /* Point at relative address again. */ - if (p[-1] != (unsigned char) finalize_jump) - { - p[-1] = (unsigned char) jump; - goto nofinalize; - } - /* Note fall through. */ - - /* The end of a stupid repeat has a finalize_jump back to the - start, where another failure point will be made which will - point to after all the repetitions found so far. */ - - /* Take off failure points put on by matching on_failure_jump - because didn't fail. Also remove the register information - put on by the on_failure_jump. */ - case finalize_jump: - POP_FAILURE_POINT (); - /* Note fall through. */ - - /* Jump without taking off any failure points. */ - case jump: - nofinalize: - EXTRACT_NUMBER_AND_INCR (mcnt, p); - p += mcnt; - break; - - case dummy_failure_jump: - /* Normally, the on_failure_jump pushes a failure point, which - then gets popped at finalize_jump. We will end up at - finalize_jump, also, and with a pattern of, say, `a+', we - are skipping over the on_failure_jump, so we have to push - something meaningless for finalize_jump to pop. */ - PUSH_FAILURE_POINT (0, 0); - goto nofinalize; - - - /* Have to succeed matching what follows at least n times. Then - just handle like an on_failure_jump. */ - case succeed_n: - EXTRACT_NUMBER (mcnt, p + 2); - /* Originally, this is how many times we HAVE to succeed. */ - if (mcnt) - { - mcnt--; - p += 2; - STORE_NUMBER_AND_INCR (p, mcnt); - } - else if (mcnt == 0) - { - p[2] = unused; - p[3] = unused; - goto on_failure; - } - else - { - fprintf (stderr, "regex: the succeed_n's n is not set.\n"); - exit (1); - } - break; - - case jump_n: - EXTRACT_NUMBER (mcnt, p + 2); - /* Originally, this is how many times we CAN jump. */ - if (mcnt) - { - mcnt--; - STORE_NUMBER(p + 2, mcnt); - goto nofinalize; /* Do the jump without taking off - any failure points. */ - } - /* If don't have to jump any more, skip over the rest of command. */ - else - p += 4; - break; - - case set_number_at: - { - register unsigned char *p1; - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - p1 = p + mcnt; - EXTRACT_NUMBER_AND_INCR (mcnt, p); - STORE_NUMBER (p1, mcnt); - break; - } - - /* Ignore these. Used to ignore the n of succeed_n's which - currently have n == 0. */ - case unused: - break; - - case wordbound: - if (AT_WORD_BOUNDARY) - break; - goto fail; - - case notwordbound: - if (AT_WORD_BOUNDARY) - goto fail; - break; - - case wordbeg: - /* Have to check if AT_STRINGS_BEG before looking at d - 1. */ - if (IS_A_LETTER (d) && (AT_STRINGS_BEG || !IS_A_LETTER (d - 1))) - break; - goto fail; - - case wordend: - /* Have to check if AT_STRINGS_BEG before looking at d - 1. */ - if (!AT_STRINGS_BEG && IS_A_LETTER (d - 1) - && (!IS_A_LETTER (d) || AT_STRINGS_END)) - break; - goto fail; - -#ifdef emacs - case before_dot: - if (PTR_CHAR_POS (d) >= point) - goto fail; - break; - - case at_dot: - if (PTR_CHAR_POS (d) != point) - goto fail; - break; - - case after_dot: - if (PTR_CHAR_POS (d) <= point) - goto fail; - break; - - case wordchar: - mcnt = (int) Sword; - goto matchsyntax; - - case syntaxspec: - mcnt = *p++; - matchsyntax: - PREFETCH; - if (SYNTAX (*d++) != (enum syntaxcode) mcnt) goto fail; - SET_REGS_MATCHED; - break; - - case notwordchar: - mcnt = (int) Sword; - goto matchnotsyntax; - - case notsyntaxspec: - mcnt = *p++; - matchnotsyntax: - PREFETCH; - if (SYNTAX (*d++) == (enum syntaxcode) mcnt) goto fail; - SET_REGS_MATCHED; - break; - -#else /* not emacs */ - - case wordchar: - PREFETCH; - if (!IS_A_LETTER (d)) - goto fail; - SET_REGS_MATCHED; - break; - - case notwordchar: - PREFETCH; - if (IS_A_LETTER (d)) - goto fail; - SET_REGS_MATCHED; - break; - -#endif /* not emacs */ - - case begbuf: - if (AT_STRINGS_BEG) - break; - goto fail; - - case endbuf: - if (AT_STRINGS_END) - break; - goto fail; - - case exactn: - /* Match the next few pattern characters exactly. - mcnt is how many characters to match. */ - mcnt = *p++; - /* This is written out as an if-else so we don't waste time - testing `translate' inside the loop. */ - if (translate) - { - do - { - PREFETCH; - if (translate[*d++] != *p++) goto fail; - } - while (--mcnt); - } - else - { - do - { - PREFETCH; - if (*d++ != *p++) goto fail; - } - while (--mcnt); - } - SET_REGS_MATCHED; - break; - } - continue; /* Successfully executed one pattern command; keep going. */ - - /* Jump here if any matching operation fails. */ - fail: - if (stackp != stackb) - /* A restart point is known. Restart there and pop it. */ - { - short last_used_reg, this_reg; - - /* If this failure point is from a dummy_failure_point, just - skip it. */ - if (!stackp[-2]) - { - POP_FAILURE_POINT (); - goto fail; - } - - d = *--stackp; - p = *--stackp; - if (d >= string1 && d <= end1) - dend = end_match_1; - /* Restore register info. */ - last_used_reg = (short) (int) *--stackp; - - /* Make the ones that weren't saved -1 or 0 again. */ - for (this_reg = RE_NREGS - 1; this_reg > last_used_reg; this_reg--) - { - regend[this_reg] = (unsigned char *) -1; - regstart[this_reg] = (unsigned char *) -1; - IS_ACTIVE (reg_info[this_reg]) = 0; - MATCHED_SOMETHING (reg_info[this_reg]) = 0; - } - - /* And restore the rest from the stack. */ - for ( ; this_reg > 0; this_reg--) - { - reg_info[this_reg] = *(struct register_info *) *--stackp; - regend[this_reg] = *--stackp; - regstart[this_reg] = *--stackp; - } - } - else - break; /* Matching at this starting point really fails. */ - } - - if (best_regs_set) - goto restore_best_regs; - return -1; /* Failure to match. */ -} - - -static int -bcmp_translate (char *s1, char *s2, int len, unsigned char *translate) -{ - register unsigned char *p1 = (unsigned char*)s1; - register unsigned char *p2 = (unsigned char*)s2; - while (len) - { - if (translate [*p1++] != translate [*p2++]) return 1; - len--; - } - return 0; -} - - - -/* Entry points compatible with 4.2 BSD regex library. */ - -#if 0 - -static struct re_pattern_buffer re_comp_buf; - -char * -re_comp (char *s) -{ - if (!s) - { - if (!re_comp_buf.buffer) - return "No previous regular expression"; - return 0; - } - - if (!re_comp_buf.buffer) - { - if (!(re_comp_buf.buffer = (char *) malloc (200))) - return "Memory exhausted"; - re_comp_buf.allocated = 200; - if (!(re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH))) - return "Memory exhausted"; - } - return re_compile_pattern (s, strlen (s), &re_comp_buf); -} - -int -re_exec (char *s) -{ - int len = strlen (s); - return 0 <= re_search (&re_comp_buf, s, len, 0, len, - (struct re_registers *) 0); -} -#endif /* not emacs */ - - - -#ifdef test - -#include - -/* Indexed by a character, gives the upper case equivalent of the - character. */ - -char upcase[0400] = - { 000, 001, 002, 003, 004, 005, 006, 007, - 010, 011, 012, 013, 014, 015, 016, 017, - 020, 021, 022, 023, 024, 025, 026, 027, - 030, 031, 032, 033, 034, 035, 036, 037, - 040, 041, 042, 043, 044, 045, 046, 047, - 050, 051, 052, 053, 054, 055, 056, 057, - 060, 061, 062, 063, 064, 065, 066, 067, - 070, 071, 072, 073, 074, 075, 076, 077, - 0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107, - 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, - 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, - 0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137, - 0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107, - 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, - 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, - 0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177, - 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207, - 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217, - 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227, - 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237, - 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247, - 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257, - 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, - 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, - 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307, - 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317, - 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327, - 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, - 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347, - 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357, - 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, - 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377 - }; - -#ifdef canned - -#include "tests.h" - -typedef enum { extended_test, basic_test } test_type; - -/* Use this to run the tests we've thought of. */ - -void -main () -{ - test_type t = extended_test; - - if (t == basic_test) - { - printf ("Running basic tests:\n\n"); - test_posix_basic (); - } - else if (t == extended_test) - { - printf ("Running extended tests:\n\n"); - test_posix_extended (); - } -} - -#else /* not canned */ - -/* Use this to run interactive tests. */ - -void -main (int argc, char **argv) -{ - char pat[80]; - struct re_pattern_buffer buf; - int i; - char c; - char fastmap[(1 << BYTEWIDTH)]; - - /* Allow a command argument to specify the style of syntax. */ - if (argc > 1) - obscure_syntax = atoi (argv[1]); - - buf.allocated = 40; - buf.buffer = (char *) malloc (buf.allocated); - buf.fastmap = fastmap; - buf.translate = upcase; - - while (1) - { - gets (pat); - - if (*pat) - { - re_compile_pattern (pat, strlen(pat), &buf); - - for (i = 0; i < buf.used; i++) - printchar (buf.buffer[i]); - - putchar ('\n'); - - printf ("%d allocated, %d used.\n", buf.allocated, buf.used); - - re_compile_fastmap (&buf); - printf ("Allowed by fastmap: "); - for (i = 0; i < (1 << BYTEWIDTH); i++) - if (fastmap[i]) printchar (i); - putchar ('\n'); - } - - gets (pat); /* Now read the string to match against */ - - i = re_match (&buf, pat, strlen (pat), 0, 0); - printf ("Match value %d.\n", i); - } -} - -#endif - - -#ifdef NOTDEF -void -print_buf (struct re_pattern_buffer *bufpbufp) -{ - int i; - - printf ("buf is :\n----------------\n"); - for (i = 0; i < bufp->used; i++) - printchar (bufp->buffer[i]); - - printf ("\n%d allocated, %d used.\n", bufp->allocated, bufp->used); - - printf ("Allowed by fastmap: "); - for (i = 0; i < (1 << BYTEWIDTH); i++) - if (bufp->fastmap[i]) - printchar (i); - printf ("\nAllowed by translate: "); - if (bufp->translate) - for (i = 0; i < (1 << BYTEWIDTH); i++) - if (bufp->translate[i]) - printchar (i); - printf ("\nfastmap is%s accurate\n", bufp->fastmap_accurate ? "" : "n't"); - printf ("can %s be null\n----------", bufp->can_be_null ? "" : "not"); -} -#endif /* NOTDEF */ - -void -printchar (char c) -{ - if (c < 040 || c >= 0177) - { - putchar ('\\'); - putchar (((c >> 6) & 3) + '0'); - putchar (((c >> 3) & 7) + '0'); - putchar ((c & 7) + '0'); - } - else - putchar (c); -} - -void -error (char *string) -{ - puts (string); - exit (1); -} -#endif /* test */ diff --git a/gnu/lib/libmalloc/free.c b/gnu/lib/libmalloc/free.c deleted file mode 100644 index 7d2a77c..0000000 --- a/gnu/lib/libmalloc/free.c +++ /dev/null @@ -1,210 +0,0 @@ -/* Free a block of memory allocated by `malloc'. - Copyright 1990, 1991, 1992 Free Software Foundation - Written May 1989 by Mike Haertel. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -This library 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 -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with this library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. - - The author may be reached (Email) at the address mike@ai.mit.edu, - or (US mail) as Mike Haertel c/o Free Software Foundation. */ - -#ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include -#endif - -/* Debugging hook for free. */ -void (*__free_hook) __P ((__ptr_t __ptr)); - -/* List of blocks allocated by memalign. */ -struct alignlist *_aligned_blocks = NULL; - -/* Return memory to the heap. - Like `free' but don't call a __free_hook if there is one. */ -void -_free_internal (ptr) - __ptr_t ptr; -{ - int type; - size_t block, blocks; - register size_t i; - struct list *prev, *next; - - block = BLOCK (ptr); - - type = _heapinfo[block].busy.type; - switch (type) - { - case 0: - /* Get as many statistics as early as we can. */ - --_chunks_used; - _bytes_used -= _heapinfo[block].busy.info.size * BLOCKSIZE; - _bytes_free += _heapinfo[block].busy.info.size * BLOCKSIZE; - - /* Find the free cluster previous to this one in the free list. - Start searching at the last block referenced; this may benefit - programs with locality of allocation. */ - i = _heapindex; - if (i > block) - while (i > block) - i = _heapinfo[i].free.prev; - else - { - do - i = _heapinfo[i].free.next; - while (i > 0 && i < block); - i = _heapinfo[i].free.prev; - } - - /* Determine how to link this block into the free list. */ - if (block == i + _heapinfo[i].free.size) - { - /* Coalesce this block with its predecessor. */ - _heapinfo[i].free.size += _heapinfo[block].busy.info.size; - block = i; - } - else - { - /* Really link this block back into the free list. */ - _heapinfo[block].free.size = _heapinfo[block].busy.info.size; - _heapinfo[block].free.next = _heapinfo[i].free.next; - _heapinfo[block].free.prev = i; - _heapinfo[i].free.next = block; - _heapinfo[_heapinfo[block].free.next].free.prev = block; - ++_chunks_free; - } - - /* Now that the block is linked in, see if we can coalesce it - with its successor (by deleting its successor from the list - and adding in its size). */ - if (block + _heapinfo[block].free.size == _heapinfo[block].free.next) - { - _heapinfo[block].free.size - += _heapinfo[_heapinfo[block].free.next].free.size; - _heapinfo[block].free.next - = _heapinfo[_heapinfo[block].free.next].free.next; - _heapinfo[_heapinfo[block].free.next].free.prev = block; - --_chunks_free; - } - - /* Now see if we can return stuff to the system. */ - blocks = _heapinfo[block].free.size; - if (blocks >= FINAL_FREE_BLOCKS && block + blocks == _heaplimit - && (*__morecore) (0) == ADDRESS (block + blocks)) - { - register size_t bytes = blocks * BLOCKSIZE; - _heaplimit -= blocks; - (*__morecore) (-bytes); - _heapinfo[_heapinfo[block].free.prev].free.next - = _heapinfo[block].free.next; - _heapinfo[_heapinfo[block].free.next].free.prev - = _heapinfo[block].free.prev; - block = _heapinfo[block].free.prev; - --_chunks_free; - _bytes_free -= bytes; - } - - /* Set the next search to begin at this block. */ - _heapindex = block; - break; - - default: - /* Do some of the statistics. */ - --_chunks_used; - _bytes_used -= 1 << type; - ++_chunks_free; - _bytes_free += 1 << type; - - /* Get the address of the first free fragment in this block. */ - prev = (struct list *) ((char *) ADDRESS (block) + - (_heapinfo[block].busy.info.frag.first << type)); - - if (_heapinfo[block].busy.info.frag.nfree == (BLOCKSIZE >> type) - 1) - { - /* If all fragments of this block are free, remove them - from the fragment list and free the whole block. */ - next = prev; - for (i = 1; i < (size_t) (BLOCKSIZE >> type); ++i) - next = next->next; - prev->prev->next = next; - if (next != NULL) - next->prev = prev->prev; - _heapinfo[block].busy.type = 0; - _heapinfo[block].busy.info.size = 1; - - /* Keep the statistics accurate. */ - ++_chunks_used; - _bytes_used += BLOCKSIZE; - _chunks_free -= BLOCKSIZE >> type; - _bytes_free -= BLOCKSIZE; - - free (ADDRESS (block)); - } - else if (_heapinfo[block].busy.info.frag.nfree != 0) - { - /* If some fragments of this block are free, link this - fragment into the fragment list after the first free - fragment of this block. */ - next = (struct list *) ptr; - next->next = prev->next; - next->prev = prev; - prev->next = next; - if (next->next != NULL) - next->next->prev = next; - ++_heapinfo[block].busy.info.frag.nfree; - } - else - { - /* No fragments of this block are free, so link this - fragment into the fragment list and announce that - it is the first free fragment of this block. */ - prev = (struct list *) ptr; - _heapinfo[block].busy.info.frag.nfree = 1; - _heapinfo[block].busy.info.frag.first = (unsigned long int) - ((unsigned long int) ((char *) ptr - (char *) NULL) - % BLOCKSIZE >> type); - prev->next = _fraghead[type].next; - prev->prev = &_fraghead[type]; - prev->prev->next = prev; - if (prev->next != NULL) - prev->next->prev = prev; - } - break; - } -} - -/* Return memory to the heap. */ -void -free (ptr) - __ptr_t ptr; -{ - register struct alignlist *l; - - if (ptr == NULL) - return; - - for (l = _aligned_blocks; l != NULL; l = l->next) - if (l->aligned == ptr) - { - l->aligned = NULL; /* Mark the slot in the list as free. */ - ptr = l->exact; - break; - } - - if (__free_hook != NULL) - (*__free_hook) (ptr); - else - _free_internal (ptr); -} diff --git a/gnu/lib/libmalloc/realloc.c b/gnu/lib/libmalloc/realloc.c deleted file mode 100644 index 2d31766..0000000 --- a/gnu/lib/libmalloc/realloc.c +++ /dev/null @@ -1,146 +0,0 @@ -/* Change the size of a block allocated by `malloc'. - Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc. - Written May 1989 by Mike Haertel. - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -This library 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 -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with this library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. - - The author may be reached (Email) at the address mike@ai.mit.edu, - or (US mail) as Mike Haertel c/o Free Software Foundation. */ - -#ifndef _MALLOC_INTERNAL -#define _MALLOC_INTERNAL -#include -#endif - -#define min(A, B) ((A) < (B) ? (A) : (B)) - -/* Debugging hook for realloc. */ -__ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, size_t __size)); - -/* Resize the given region to the new size, returning a pointer - to the (possibly moved) region. This is optimized for speed; - some benchmarks seem to indicate that greater compactness is - achieved by unconditionally allocating and copying to a - new region. This module has incestuous knowledge of the - internals of both free and malloc. */ -__ptr_t -realloc (ptr, size) - __ptr_t ptr; - size_t size; -{ - __ptr_t result; - int type; - size_t block, blocks, oldlimit; - - if (size == 0) - { - free (ptr); - return malloc (0); - } - else if (ptr == NULL) - return malloc (size); - - if (__realloc_hook != NULL) - return (*__realloc_hook) (ptr, size); - - block = BLOCK (ptr); - - type = _heapinfo[block].busy.type; - switch (type) - { - case 0: - /* Maybe reallocate a large block to a small fragment. */ - if (size <= BLOCKSIZE / 2) - { - result = malloc (size); - if (result != NULL) - { - memcpy (result, ptr, size); - free (ptr); - return result; - } - } - - /* The new size is a large allocation as well; - see if we can hold it in place. */ - blocks = BLOCKIFY (size); - if (blocks < _heapinfo[block].busy.info.size) - { - /* The new size is smaller; return - excess memory to the free list. */ - _heapinfo[block + blocks].busy.type = 0; - _heapinfo[block + blocks].busy.info.size - = _heapinfo[block].busy.info.size - blocks; - _heapinfo[block].busy.info.size = blocks; - free (ADDRESS (block + blocks)); - result = ptr; - } - else if (blocks == _heapinfo[block].busy.info.size) - /* No size change necessary. */ - result = ptr; - else - { - /* Won't fit, so allocate a new region that will. - Free the old region first in case there is sufficient - adjacent free space to grow without moving. */ - blocks = _heapinfo[block].busy.info.size; - /* Prevent free from actually returning memory to the system. */ - oldlimit = _heaplimit; - _heaplimit = 0; - free (ptr); - _heaplimit = oldlimit; - result = malloc (size); - if (result == NULL) - { - /* Now we're really in trouble. We have to unfree - the thing we just freed. Unfortunately it might - have been coalesced with its neighbors. */ - if (_heapindex == block) - (void) malloc (blocks * BLOCKSIZE); - else - { - __ptr_t previous = malloc ((block - _heapindex) * BLOCKSIZE); - (void) malloc (blocks * BLOCKSIZE); - free (previous); - } - return NULL; - } - if (ptr != result) - memmove (result, ptr, blocks * BLOCKSIZE); - } - break; - - default: - /* Old size is a fragment; type is logarithm - to base two of the fragment size. */ - if (size > (size_t) (1 << (type - 1)) && size <= (size_t) (1 << type)) - /* The new size is the same kind of fragment. */ - result = ptr; - else - { - /* The new size is different; allocate a new space, - and copy the lesser of the new size and the old. */ - result = malloc (size); - if (result == NULL) - return NULL; - memcpy (result, ptr, min (size, (size_t) 1 << type)); - free (ptr); - } - break; - } - - return result; -} diff --git a/gnu/lib/libreadline/README.FreeBSD b/gnu/lib/libreadline/README.FreeBSD deleted file mode 100644 index 6af2775..0000000 --- a/gnu/lib/libreadline/README.FreeBSD +++ /dev/null @@ -1,21 +0,0 @@ -The GNU Readline library is a programming tool that provides a -consistent user interface for recalling lines of previously typed -input and performing editing tasks on input lines. - -paul@freefall.cdrom.com - -There was a bug with tcsh: when readline attempt to get tty -modes from background, it got no-echo editing tcsh mode. - -Workaround for this implemented via TIOCGWINSZ/TIOCSWINSZ -with same winsize structure: it does nothing expect polling -process from background. Look tcsh_hack.readme for details. - -This version is more ctype-oriented than original bash version. - -If you want 8-bit clean version, put - set convert-meta off - set output-meta on -in your ~/.inputrc file - -ache@astral.msk.su diff --git a/gnu/lib/libreadline/doc/ChangeLog b/gnu/lib/libreadline/doc/ChangeLog deleted file mode 100644 index 5f1f5061..0000000 --- a/gnu/lib/libreadline/doc/ChangeLog +++ /dev/null @@ -1,8 +0,0 @@ -Tue Feb 2 11:40:04 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * Makefile.in: configurable (and useable) Makefile template - * Makefile: removed, replaced with configurable Makefile.in - * texindex.c texinfo.tex: remove, replacing w/refs to tools - elsewhere in distribution tree - * configure.in: pro forma configure stub - * ChangeLog: new file diff --git a/gnu/lib/libreadline/doc/hist.texinfo b/gnu/lib/libreadline/doc/hist.texinfo deleted file mode 100644 index cc80efa..0000000 --- a/gnu/lib/libreadline/doc/hist.texinfo +++ /dev/null @@ -1,113 +0,0 @@ -\input texinfo @c -*-texinfo-*- -@c %**start of header (This is for running Texinfo on a region.) -@setfilename history.info -@settitle GNU History Library -@c %**end of header (This is for running Texinfo on a region.) - -@setchapternewpage odd - -@ignore -last change: Wed Jul 20 09:57:17 EDT 1994 -@end ignore - -@set EDITION 2.0 -@set VERSION 2.0 -@set UPDATED 20 July 1994 -@set UPDATE-MONTH July 1994 - -@ifinfo -This document describes the GNU History library, a programming tool that -provides a consistent user interface for recalling lines of previously -typed input. - -Copyright (C) 1988, 1991 Free Software Foundation, Inc. - -Permission is granted to make and distribute verbatim copies of -this manual provided the copyright notice and this permission notice -pare preserved on all copies. - -@ignore -Permission is granted to process this file through TeX and print the -results, provided the printed document carries copying permission -notice identical to this one except for the removal of this paragraph -(this paragraph not being relevant to the printed manual). -@end ignore - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided that the entire -resulting derived work is distributed under the terms of a permission -notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that this permission notice may be stated in a translation approved -by the Foundation. -@end ifinfo - -@titlepage -@sp 10 -@title GNU History Library -@subtitle Edition @value{EDITION}, for @code{History Library} Version @value{VERSION}. -@subtitle @value{UPDATE-MONTH} -@author Brian Fox, Free Software Foundation -@author Chet Ramey, Case Western Reserve University - -@page -This document describes the GNU History library, a programming tool that -provides a consistent user interface for recalling lines of previously -typed input. - -Published by the Free Software Foundation @* -675 Massachusetts Avenue, @* -Cambridge, MA 02139 USA - -Permission is granted to make and distribute verbatim copies of -this manual provided the copyright notice and this permission notice -are preserved on all copies. - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided that the entire -resulting derived work is distributed under the terms of a permission -notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that this permission notice may be stated in a translation approved -by the Foundation. - -@vskip 0pt plus 1filll -Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. -@end titlepage - -@ifinfo -@node Top -@top GNU History Library - -This document describes the GNU History library, a programming tool that -provides a consistent user interface for recalling lines of previously -typed input. - -@menu -* Using History Interactively:: GNU History User's Manual. -* Programming with GNU History:: GNU History Programmer's Manual. -* Concept Index:: Index of concepts described in this manual. -* Function and Variable Index:: Index of externally visible functions - and variables. -@end menu -@end ifinfo - -@syncodeindex fn vr - -@include hsuser.texinfo -@include hstech.texinfo - -@node Concept Index -@appendix Concept Index -@printindex cp - -@node Function and Variable Index -@appendix Function and Variable Index -@printindex vr - -@contents -@bye diff --git a/gnu/lib/libreadline/doc/history.info b/gnu/lib/libreadline/doc/history.info deleted file mode 100644 index 6df0bd9..0000000 --- a/gnu/lib/libreadline/doc/history.info +++ /dev/null @@ -1,744 +0,0 @@ -This is Info file history.info, produced by Makeinfo-1.55 from the -input file hist.texinfo. - - This document describes the GNU History library, a programming tool -that provides a consistent user interface for recalling lines of -previously typed input. - - Copyright (C) 1988, 1991 Free Software Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice pare -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided that -the entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions, except that this permission notice may be stated in a -translation approved by the Foundation. - - -File: history.info, Node: Top, Next: Using History Interactively, Prev: (DIR), Up: (DIR) - -GNU History Library -******************* - - This document describes the GNU History library, a programming tool -that provides a consistent user interface for recalling lines of -previously typed input. - -* Menu: - -* Using History Interactively:: GNU History User's Manual. -* Programming with GNU History:: GNU History Programmer's Manual. -* Concept Index:: Index of concepts described in this manual. -* Function and Variable Index:: Index of externally visible functions - and variables. - - -File: history.info, Node: Using History Interactively, Next: Programming with GNU History, Prev: Top, Up: Top - -Using History Interactively -*************************** - - This chapter describes how to use the GNU History Library -interactively, from a user's standpoint. It should be considered a -user's guide. For information on using the GNU History Library in your -own programs, *note Programming with GNU History::.. - -* Menu: - -* History Interaction:: What it feels like using History as a user. - - -File: history.info, Node: History Interaction, Up: Using History Interactively - -History Interaction -=================== - - The History library provides a history expansion feature that is -similar to the history expansion provided by `csh'. The following text -describes the syntax used to manipulate the history information. - - History expansion takes place in two parts. The first is to -determine which line from the previous history should be used during -substitution. The second is to select portions of that line for -inclusion into the current one. The line selected from the previous -history is called the "event", and the portions of that line that are -acted upon are called "words". The line is broken into words in the -same fashion that Bash does, so that several English (or Unix) words -surrounded by quotes are considered as one word. - -* Menu: - -* Event Designators:: How to specify which history line to use. -* Word Designators:: Specifying which words are of interest. -* Modifiers:: Modifying the results of substitution. - - -File: history.info, Node: Event Designators, Next: Word Designators, Up: History Interaction - -Event Designators ------------------ - - An event designator is a reference to a command line entry in the -history list. - -`!' - Start a history substitution, except when followed by a space, tab, - the end of the line, = or (. - -`!!' - Refer to the previous command. This is a synonym for `!-1'. - -`!n' - Refer to command line N. - -`!-n' - Refer to the command N lines back. - -`!string' - Refer to the most recent command starting with STRING. - -`!?string'[`?'] - Refer to the most recent command containing STRING. - -`!#' - The entire command line typed so far. - -`^string1^string2^' - Quick Substitution. Repeat the last command, replacing STRING1 - with STRING2. Equivalent to `!!:s/string1/string2/'. - - -File: history.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction - -Word Designators ----------------- - - A : separates the event specification from the word designator. It -can be omitted if the word designator begins with a ^, $, * or %. -Words are numbered from the beginning of the line, with the first word -being denoted by a 0 (zero). - -`0 (zero)' - The `0'th word. For many applications, this is the command word. - -`n' - The Nth word. - -`^' - The first argument; that is, word 1. - -`$' - The last argument. - -`%' - The word matched by the most recent `?string?' search. - -`x-y' - A range of words; `-Y' abbreviates `0-Y'. - -`*' - All of the words, except the `0'th. This is a synonym for `1-$'. - It is not an error to use * if there is just one word in the event; - the empty string is returned in that case. - -`x*' - Abbreviates `x-$' - -`x-' - Abbreviates `x-$' like `x*', but omits the last word. - - -File: history.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction - -Modifiers ---------- - - After the optional word designator, you can add a sequence of one or -more of the following modifiers, each preceded by a :. - -`h' - Remove a trailing pathname component, leaving only the head. - -`r' - Remove a trailing suffix of the form `.'SUFFIX, leaving the - basename. - -`e' - Remove all but the trailing suffix. - -`t' - Remove all leading pathname components, leaving the tail. - -`p' - Print the new command but do not execute it. - -`s/old/new/' - Substitute NEW for the first occurrence of OLD in the event line. - Any delimiter may be used in place of /. The delimiter may be - quoted in OLD and NEW with a single backslash. If & appears in - NEW, it is replaced by OLD. A single backslash will quote the &. - The final delimiter is optional if it is the last character on the - input line. - -`&' - Repeat the previous substitution. - -`g' - Cause changes to be applied over the entire event line. Used in - conjunction with `s', as in `gs/old/new/', or with `&'. - - -File: history.info, Node: Programming with GNU History, Next: Concept Index, Prev: Using History Interactively, Up: Top - -Programming with GNU History -**************************** - - This chapter describes how to interface programs that you write with -the GNU History Library. It should be considered a technical guide. -For information on the interactive use of GNU History, *note Using -History Interactively::.. - -* Menu: - -* Introduction to History:: What is the GNU History library for? -* History Storage:: How information is stored. -* History Functions:: Functions that you can use. -* History Variables:: Variables that control behaviour. -* History Programming Example:: Example of using the GNU History Library. - - -File: history.info, Node: Introduction to History, Next: History Storage, Up: Programming with GNU History - -Introduction to History -======================= - - Many programs read input from the user a line at a time. The GNU -History library is able to keep track of those lines, associate -arbitrary data with each line, and utilize information from previous -lines in composing new ones. - - The programmer using the History library has available functions for -remembering lines on a history list, associating arbitrary data with a -line, removing lines from the list, searching through the list for a -line containing an arbitrary text string, and referencing any line in -the list directly. In addition, a history "expansion" function is -available which provides for a consistent user interface across -different programs. - - The user using programs written with the History library has the -benefit of a consistent user interface with a set of well-known -commands for manipulating the text of previous lines and using that text -in new commands. The basic history manipulation commands are similar to -the history substitution provided by `csh'. - - If the programmer desires, he can use the Readline library, which -includes some history manipulation by default, and has the added -advantage of command line editing. - - -File: history.info, Node: History Storage, Next: History Functions, Prev: Introduction to History, Up: Programming with GNU History - -History Storage -=============== - - The history list is an array of history entries. A history entry is -declared as follows: - - typedef struct _hist_entry { - char *line; - char *data; - } HIST_ENTRY; - - The history list itself might therefore be declared as - - HIST_ENTRY **the_history_list; - - The state of the History library is encapsulated into a single -structure: - - /* A structure used to pass the current state of the history stuff around. */ - typedef struct _hist_state { - HIST_ENTRY **entries; /* Pointer to the entries themselves. */ - int offset; /* The location pointer within this array. */ - int length; /* Number of elements within this array. */ - int size; /* Number of slots allocated to this array. */ - int flags; - } HISTORY_STATE; - - If the flags member includes `HS_STIFLED', the history has been -stifled. - - -File: history.info, Node: History Functions, Next: History Variables, Prev: History Storage, Up: Programming with GNU History - -History Functions -================= - - This section describes the calling sequence for the various functions -present in GNU History. - -* Menu: - -* Initializing History and State Management:: Functions to call when you - want to use history in a - program. -* History List Management:: Functions used to manage the list - of history entries. -* Information About the History List:: Functions returning information about - the history list. -* Moving Around the History List:: Functions used to change the position - in the history list. -* Searching the History List:: Functions to search the history list - for entries containing a string. -* Managing the History File:: Functions that read and write a file - containing the history list. -* History Expansion:: Functions to perform csh-like history - expansion. - - -File: history.info, Node: Initializing History and State Management, Next: History List Management, Up: History Functions - -Initializing History and State Management ------------------------------------------ - - This section describes functions used to initialize and manage the -state of the History library when you want to use the history functions -in your program. - - - Function: void using_history () - Begin a session in which the history functions might be used. This - initializes the interactive variables. - - - Function: HISTORY_STATE * history_get_history_state () - Return a structure describing the current state of the input - history. - - - Function: void history_set_history_state (HISTORY_STATE *state) - Set the state of the history list according to STATE. - - -File: history.info, Node: History List Management, Next: Information About the History List, Prev: Initializing History and State Management, Up: History Functions - -History List Management ------------------------ - - These functions manage individual entries on the history list, or set -parameters managing the list itself. - - - Function: void add_history (char *string) - Place STRING at the end of the history list. The associated data - field (if any) is set to `NULL'. - - - Function: HIST_ENTRY * remove_history (int which) - Remove history entry at offset WHICH from the history. The - removed element is returned so you can free the line, data, and - containing structure. - - - Function: HIST_ENTRY * replace_history_entry (int which, char *line, - char *data) - Make the history entry at offset WHICH have LINE and DATA. This - returns the old entry so you can dispose of the data. In the case - of an invalid WHICH, a `NULL' pointer is returned. - - - Function: void stifle_history (int max) - Stifle the history list, remembering only the last MAX entries. - - - Function: int unstifle_history () - Stop stifling the history. This returns the previous amount the - history was stifled. The value is positive if the history was - stifled, negative if it wasn't. - - - Function: int history_is_stifled () - Returns non-zero if the history is stifled, zero if it is not. - - -File: history.info, Node: Information About the History List, Next: Moving Around the History List, Prev: History List Management, Up: History Functions - -Information About the History List ----------------------------------- - - These functions return information about the entire history list or -individual list entries. - - - Function: HIST_ENTRY ** history_list () - Return a `NULL' terminated array of `HIST_ENTRY' which is the - current input history. Element 0 of this list is the beginning of - time. If there is no history, return `NULL'. - - - Function: int where_history () - Returns the offset of the current history element. - - - Function: HIST_ENTRY * current_history () - Return the history entry at the current position, as determined by - `where_history ()'. If there is no entry there, return a `NULL' - pointer. - - - Function: HIST_ENTRY * history_get (int offset) - Return the history entry at position OFFSET, starting from - `history_base'. If there is no entry there, or if OFFSET is - greater than the history length, return a `NULL' pointer. - - - Function: int history_total_bytes () - Return the number of bytes that the primary history entries are - using. This function returns the sum of the lengths of all the - lines in the history. - - -File: history.info, Node: Moving Around the History List, Next: Searching the History List, Prev: Information About the History List, Up: History Functions - -Moving Around the History List ------------------------------- - - These functions allow the current index into the history list to be -set or changed. - - - Function: int history_set_pos (int pos) - Set the position in the history list to POS, an absolute index - into the list. - - - Function: HIST_ENTRY * previous_history () - Back up the current history offset to the previous history entry, - and return a pointer to that entry. If there is no previous - entry, return a `NULL' pointer. - - - Function: HIST_ENTRY * next_history () - Move the current history offset forward to the next history entry, - and return the a pointer to that entry. If there is no next - entry, return a `NULL' pointer. - - -File: history.info, Node: Searching the History List, Next: Managing the History File, Prev: Moving Around the History List, Up: History Functions - -Searching the History List --------------------------- - - These functions allow searching of the history list for entries -containing a specific string. Searching may be performed both forward -and backward from the current history position. The search may be -"anchored", meaning that the string must match at the beginning of the -history entry. - - - Function: int history_search (char *string, int direction) - Search the history for STRING, starting at the current history - offset. If DIRECTION < 0, then the search is through previous - entries, else through subsequent. If STRING is found, then the - current history index is set to that history entry, and the value - returned is the offset in the line of the entry where STRING was - found. Otherwise, nothing is changed, and a -1 is returned. - - - Function: int history_search_prefix (char *string, int direction) - Search the history for STRING, starting at the current history - offset. The search is anchored: matching lines must begin with - STRING. If DIRECTION < 0, then the search is through previous - entries, else through subsequent. If STRING is found, then the - current history index is set to that entry, and the return value - is 0. Otherwise, nothing is changed, and a -1 is returned. - - - Function: int history_search_pos (char *string, int direction, int - pos) - Search for STRING in the history list, starting at POS, an - absolute index into the list. If DIRECTION is negative, the search - proceeds backward from POS, otherwise forward. Returns the - absolute index of the history element where STRING was found, or - -1 otherwise. - - -File: history.info, Node: Managing the History File, Next: History Expansion, Prev: Searching the History List, Up: History Functions - -Managing the History File -------------------------- - - The History library can read the history from and write it to a file. -This section documents the functions for managing a history file. - - - Function: int read_history (char *filename) - Add the contents of FILENAME to the history list, a line at a - time. If FILENAME is `NULL', then read from `~/.history'. - Returns 0 if successful, or errno if not. - - - Function: int read_history_range (char *filename, int from, int to) - Read a range of lines from FILENAME, adding them to the history - list. Start reading at line FROM and end at TO. If FROM is zero, - start at the beginning. If TO is less than FROM, then read until - the end of the file. If FILENAME is `NULL', then read from - `~/.history'. Returns 0 if successful, or `errno' if not. - - - Function: int write_history (char *filename) - Write the current history to FILENAME, overwriting FILENAME if - necessary. If FILENAME is `NULL', then write the history list to - `~/.history'. Values returned are as in `read_history ()'. - - - Function: int append_history (int nelements, char *filename) - Append the last NELEMENTS of the history list to FILENAME. - - - Function: int history_truncate_file (char *filename, int nlines) - Truncate the history file FILENAME, leaving only the last NLINES - lines. - - -File: history.info, Node: History Expansion, Prev: Managing the History File, Up: History Functions - -History Expansion ------------------ - - These functions implement `csh'-like history expansion. - - - Function: int history_expand (char *string, char **output) - Expand STRING, placing the result into OUTPUT, a pointer to a - string (*note History Interaction::.). Returns: - `0' - If no expansions took place (or, if the only change in the - text was the de-slashifying of the history expansion - character); - - `1' - if expansions did take place; - - `-1' - if there was an error in expansion; - - `2' - if the returned line should only be displayed, but not - executed, as with the `:p' modifier (*note Modifiers::.). - - If an error ocurred in expansion, then OUTPUT contains a - descriptive error message. - - - Function: char * history_arg_extract (int first, int last, char - *string) - Extract a string segment consisting of the FIRST through LAST - arguments present in STRING. Arguments are broken up as in Bash. - - - Function: char * get_history_event (char *string, int *cindex, int - qchar) - Returns the text of the history event beginning at STRING + - *CINDEX. *CINDEX is modified to point to after the event - specifier. At function entry, CINDEX points to the index into - STRING where the history event specification begins. QCHAR is a - character that is allowed to end the event specification in - addition to the "normal" terminating characters. - - - Function: char ** history_tokenize (char *string) - Return an array of tokens parsed out of STRING, much as the shell - might. The tokens are split on white space and on the characters - `()<>;&|$', and shell quoting conventions are obeyed. - - -File: history.info, Node: History Variables, Next: History Programming Example, Prev: History Functions, Up: Programming with GNU History - -History Variables -================= - - This section describes the externally visible variables exported by -the GNU History Library. - - - Variable: int history_base - The logical offset of the first entry in the history list. - - - Variable: int history_length - The number of entries currently stored in the history list. - - - Variable: int max_input_history - The maximum number of history entries. This must be changed using - `stifle_history ()'. - - - Variable: char history_expansion_char - The character that starts a history event. The default is `!'. - - - Variable: char history_subst_char - The character that invokes word substitution if found at the start - of a line. The default is `^'. - - - Variable: char history_comment_char - During tokenization, if this character is seen as the first - character of a word, then it and all subsequent characters up to a - newline are ignored, suppressing history expansion for the - remainder of the line. This is disabled by default. - - - Variable: char * history_no_expand_chars - The list of characters which inhibit history expansion if found - immediately following HISTORY_EXPANSION_CHAR. The default is - whitespace and `='. - - -File: history.info, Node: History Programming Example, Prev: History Variables, Up: Programming with GNU History - -History Programming Example -=========================== - - The following program demonstrates simple use of the GNU History -Library. - - main () - { - char line[1024], *t; - int len, done = 0; - - line[0] = 0; - - using_history (); - while (!done) - { - printf ("history$ "); - fflush (stdout); - t = fgets (line, sizeof (line) - 1, stdin); - if (t && *t) - { - len = strlen (t); - if (t[len - 1] == '\n') - t[len - 1] = '\0'; - } - - if (!t) - strcpy (line, "quit"); - - if (line[0]) - { - char *expansion; - int result; - - result = history_expand (line, &expansion); - if (result) - fprintf (stderr, "%s\n", expansion); - - if (result < 0 || result == 2) - { - free (expansion); - continue; - } - - add_history (expansion); - strncpy (line, expansion, sizeof (line) - 1); - free (expansion); - } - - if (strcmp (line, "quit") == 0) - done = 1; - else if (strcmp (line, "save") == 0) - write_history ("history_file"); - else if (strcmp (line, "read") == 0) - read_history ("history_file"); - else if (strcmp (line, "list") == 0) - { - register HIST_ENTRY **the_list; - register int i; - - the_list = history_list (); - if (the_list) - for (i = 0; the_list[i]; i++) - printf ("%d: %s\n", i + history_base, the_list[i]->line); - } - else if (strncmp (line, "delete", 6) == 0) - { - int which; - if ((sscanf (line + 6, "%d", &which)) == 1) - { - HIST_ENTRY *entry = remove_history (which); - if (!entry) - fprintf (stderr, "No such entry %d\n", which); - else - { - free (entry->line); - free (entry); - } - } - else - { - fprintf (stderr, "non-numeric arg given to `delete'\n"); - } - } - } - } - - -File: history.info, Node: Concept Index, Next: Function and Variable Index, Prev: Programming with GNU History, Up: Top - -Concept Index -************* - -* Menu: - -* anchored search: Searching the History List. -* event designators: Event Designators. -* expansion: History Interaction. -* history events: Event Designators. -* History Searching: Searching the History List. - - -File: history.info, Node: Function and Variable Index, Prev: Concept Index, Up: Top - -Function and Variable Index -*************************** - -* Menu: - -* add_history: History List Management. -* append_history: Managing the History File. -* current_history: Information About the History List. -* get_history_event: History Expansion. -* history_arg_extract: History Expansion. -* history_base: History Variables. -* history_comment_char: History Variables. -* history_expand: History Expansion. -* history_expansion_char: History Variables. -* history_get: Information About the History List. -* history_get_history_state: Initializing History and State Management. -* history_is_stifled: History List Management. -* history_length: History Variables. -* history_list: Information About the History List. -* history_no_expand_chars: History Variables. -* history_search: Searching the History List. -* history_search_pos: Searching the History List. -* history_search_prefix: Searching the History List. -* history_set_history_state: Initializing History and State Management. -* history_set_pos: Moving Around the History List. -* history_subst_char: History Variables. -* history_tokenize: History Expansion. -* history_total_bytes: Information About the History List. -* history_truncate_file: Managing the History File. -* max_input_history: History Variables. -* next_history: Moving Around the History List. -* previous_history: Moving Around the History List. -* read_history: Managing the History File. -* read_history_range: Managing the History File. -* remove_history: History List Management. -* replace_history_entry: History List Management. -* stifle_history: History List Management. -* unstifle_history: History List Management. -* using_history: Initializing History and State Management. -* where_history: Information About the History List. -* write_history: Managing the History File. - - - -Tag Table: -Node: Top975 -Node: Using History Interactively1569 -Node: History Interaction2077 -Node: Event Designators3122 -Node: Word Designators3952 -Node: Modifiers4936 -Node: Programming with GNU History6065 -Node: Introduction to History6791 -Node: History Storage8112 -Node: History Functions9205 -Node: Initializing History and State Management10176 -Node: History List Management10968 -Node: Information About the History List12396 -Node: Moving Around the History List13702 -Node: Searching the History List14587 -Node: Managing the History File16419 -Node: History Expansion17925 -Node: History Variables19769 -Node: History Programming Example21138 -Node: Concept Index23742 -Node: Function and Variable Index24223 - -End Tag Table diff --git a/gnu/lib/libreadline/doc/inc-hist.texi b/gnu/lib/libreadline/doc/inc-hist.texi deleted file mode 100644 index 539e372..0000000 --- a/gnu/lib/libreadline/doc/inc-hist.texi +++ /dev/null @@ -1,155 +0,0 @@ -@ignore -This file is completely identical to hsuser.texinfo, except that it has the -reference to the programming manual removed. There are definately better ways -to do this! - -This file documents the user interface to the GNU History library. - -Copyright (C) 1988, 1991 Free Software Foundation, Inc. -Authored by Brian Fox. - -Permission is granted to make and distribute verbatim copies of this manual -provided the copyright notice and this permission notice are preserved on -all copies. - -Permission is granted to process this file through Tex and print the -results, provided the printed document carries copying permission notice -identical to this one except for the removal of this paragraph (this -paragraph not being relevant to the printed manual). - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that the -GNU Copyright statement is available to the distributee, and provided that -the entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions. -@end ignore - -@node Using History Interactively -@appendix Using History Interactively - -This chapter describes how to use the GNU History Library interactively, -from a user's standpoint. - -@menu -* History Interaction:: What it feels like using History as a user. -@end menu - -@node History Interaction -@section History Interaction -@cindex expansion - -The History library provides a history expansion feature that is similar -to the history expansion in Csh. The following text describes the sytax -that you use to manipulate the history information. - -History expansion takes place in two parts. The first is to determine -which line from the previous history should be used during substitution. -The second is to select portions of that line for inclusion into the -current one. The line selected from the previous history is called the -@dfn{event}, and the portions of that line that are acted upon are -called @dfn{words}. The line is broken into words in the same fashion -that the Bash shell does, so that several English (or Unix) words -surrounded by quotes are considered as one word. - -@menu -* Event Designators:: How to specify which history line to use. -* Word Designators:: Specifying which words are of interest. -* Modifiers:: Modifying the results of susbstitution. -@end menu - -@node Event Designators -@subsection Event Designators -@cindex event designators - -An event designator is a reference to a command line entry in the -history list. - -@table @asis - -@item @code{!} -Start a history subsititution, except when followed by a space, tab, or -the end of the line... @key{=} or @key{(}. - -@item @code{!!} -Refer to the previous command. This is a synonym for @code{!-1}. - -@item @code{!n} -Refer to command line @var{n}. - -@item @code{!-n} -Refer to the command line @var{n} lines back. - -@item @code{!string} -Refer to the most recent command starting with @var{string}. - -@item @code{!?string}[@code{?}] -Refer to the most recent command containing @var{string}. - -@end table - -@node Word Designators -@subsection Word Designators - -A @key{:} separates the event specification from the word designator. It -can be omitted if the word designator begins with a @key{^}, @key{$}, -@key{*} or @key{%}. Words are numbered from the beginning of the line, -with the first word being denoted by a 0 (zero). - -@table @code - -@item 0 (zero) -The zero'th word. For many applications, this is the command word. - -@item n -The @var{n}'th word. - -@item ^ -The first argument. that is, word 1. - -@item $ -The last argument. - -@item % -The word matched by the most recent @code{?string?} search. - -@item x-y -A range of words; @code{-@var{y}} Abbreviates @code{0-@var{y}}. - -@item * -All of the words, excepting the zero'th. This is a synonym for @code{1-$}. -It is not an error to use @key{*} if there is just one word in the event. -The empty string is returned in that case. - -@end table - -@node Modifiers -@subsection Modifiers - -After the optional word designator, you can add a sequence of one or more -of the following modifiers, each preceded by a @key{:}. - -@table @code - -@item # -The entire command line typed so far. This means the current command, -not the previous command, so it really isn't a word designator, and doesn't -belong in this section. - -@item h -Remove a trailing pathname component, leaving only the head. - -@item r -Remove a trailing suffix of the form @samp{.}@var{suffix}, leaving the basename. - -@item e -Remove all but the suffix. - -@item t -Remove all leading pathname components, leaving the tail. - -@item p -Print the new command but do not execute it. -@end table diff --git a/gnu/lib/libreadline/doc/readline.info b/gnu/lib/libreadline/doc/readline.info deleted file mode 100644 index f4882e9..0000000 --- a/gnu/lib/libreadline/doc/readline.info +++ /dev/null @@ -1,74 +0,0 @@ -This is Info file readline.info, produced by Makeinfo-1.55 from the -input file rlman.texinfo. - - This document describes the GNU Readline Library, a utility which -aids in the consistency of user interface across discrete programs that -need to provide a command line interface. - - Copyright (C) 1988, 1991 Free Software Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice pare -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided that -the entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions, except that this permission notice may be stated in a -translation approved by the Foundation. - - -Indirect: -readline.info-1: 1000 -readline.info-2: 50467 - -Tag Table: -(Indirect) -Node: Top1000 -Node: Command Line Editing1613 -Node: Introduction and Notation2264 -Node: Readline Interaction3284 -Node: Readline Bare Essentials4423 -Node: Readline Movement Commands5953 -Node: Readline Killing Commands6844 -Node: Readline Arguments8547 -Node: Readline Init File9498 -Node: Readline Init Syntax10502 -Node: Conditional Init Constructs17435 -Node: Bindable Readline Commands19681 -Node: Commands For Moving20351 -Node: Commands For History21199 -Node: Commands For Text23783 -Node: Commands For Killing25522 -Node: Numeric Arguments26971 -Node: Commands For Completion27598 -Node: Keyboard Macros28525 -Node: Miscellaneous Commands29084 -Node: Readline vi Mode30372 -Node: Programming with GNU Readline32122 -Node: Basic Behavior32919 -Node: Custom Functions36232 -Node: The Function Type36845 -Node: Function Writing37690 -Node: Readline Convenience Functions40453 -Node: Function Naming41118 -Node: Keymaps42345 -Node: Binding Keys43856 -Node: Associating Function Names and Bindings45650 -Node: Allowing Undoing46812 -Node: Redisplay49397 -Node: Modifying Text50467 -Node: Utility Functions51378 -Node: Custom Completers54444 -Node: How Completing Works55165 -Node: Completion Functions58156 -Node: Completion Variables61171 -Node: A Short Completion Example64996 -Node: Concept Index77230 -Node: Function and Variable Index77717 - -End Tag Table diff --git a/gnu/lib/libreadline/doc/readline.info-1 b/gnu/lib/libreadline/doc/readline.info-1 deleted file mode 100644 index 78bbd05..0000000 --- a/gnu/lib/libreadline/doc/readline.info-1 +++ /dev/null @@ -1,1322 +0,0 @@ -This is Info file readline.info, produced by Makeinfo-1.55 from the -input file rlman.texinfo. - - This document describes the GNU Readline Library, a utility which -aids in the consistency of user interface across discrete programs that -need to provide a command line interface. - - Copyright (C) 1988, 1991 Free Software Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice pare -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided that -the entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions, except that this permission notice may be stated in a -translation approved by the Foundation. - - -File: readline.info, Node: Top, Next: Command Line Editing, Prev: (DIR), Up: (DIR) - -GNU Readline Library -******************** - - This document describes the GNU Readline Library, a utility which -aids in the consistency of user interface across discrete programs that -need to provide a command line interface. - -* Menu: - -* Command Line Editing:: GNU Readline User's Manual. -* Programming with GNU Readline:: GNU Readline Programmer's Manual. -* Concept Index:: Index of concepts described in this manual. -* Function and Variable Index:: Index of externally visible functions - and variables. - - -File: readline.info, Node: Command Line Editing, Next: Programming with GNU Readline, Prev: Top, Up: Top - -Command Line Editing -******************** - - This chapter describes the basic features of the GNU command line -editing interface. - -* Menu: - -* Introduction and Notation:: Notation used in this text. -* Readline Interaction:: The minimum set of commands for editing a line. -* Readline Init File:: Customizing Readline from a user's view. -* Bindable Readline Commands:: A description of most of the Readline commands - available for binding -* Readline vi Mode:: A short description of how to make Readline - behave like the vi editor. - - -File: readline.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing - -Introduction to Line Editing -============================ - - The following paragraphs describe the notation used to represent -keystrokes. - - The text C-k is read as `Control-K' and describes the character -produced when the Control key is depressed and the k key is struck. - - The text M-k is read as `Meta-K' and describes the character -produced when the meta key (if you have one) is depressed, and the k -key is struck. If you do not have a meta key, the identical keystroke -can be generated by typing ESC first, and then typing k. Either -process is known as "metafying" the k key. - - The text M-C-k is read as `Meta-Control-k' and describes the -character produced by "metafying" C-k. - - In addition, several keys have their own names. Specifically, DEL, -ESC, LFD, SPC, RET, and TAB all stand for themselves when seen in this -text, or in an init file (*note Readline Init File::., for more info). - - -File: readline.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing - -Readline Interaction -==================== - - Often during an interactive session you type in a long line of text, -only to notice that the first word on the line is misspelled. The -Readline library gives you a set of commands for manipulating the text -as you type it in, allowing you to just fix your typo, and not forcing -you to retype the majority of the line. Using these editing commands, -you move the cursor to the place that needs correction, and delete or -insert the text of the corrections. Then, when you are satisfied with -the line, you simply press RETURN. You do not have to be at the end of -the line to press RETURN; the entire line is accepted regardless of the -location of the cursor within the line. - -* Menu: - -* Readline Bare Essentials:: The least you need to know about Readline. -* Readline Movement Commands:: Moving about the input line. -* Readline Killing Commands:: How to delete text, and how to get it back! -* Readline Arguments:: Giving numeric arguments to commands. - - -File: readline.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction - -Readline Bare Essentials ------------------------- - - In order to enter characters into the line, simply type them. The -typed character appears where the cursor was, and then the cursor moves -one space to the right. If you mistype a character, you can use your -erase character to back up and delete the mistyped character. - - Sometimes you may miss typing a character that you wanted to type, -and not notice your error until you have typed several other -characters. In that case, you can type C-b to move the cursor to the -left, and then correct your mistake. Afterwards, you can move the -cursor to the right with C-f. - - When you add text in the middle of a line, you will notice that -characters to the right of the cursor are `pushed over' to make room -for the text that you have inserted. Likewise, when you delete text -behind the cursor, characters to the right of the cursor are `pulled -back' to fill in the blank space created by the removal of the text. A -list of the basic bare essentials for editing the text of an input line -follows. - -C-b - Move back one character. - -C-f - Move forward one character. - -DEL - Delete the character to the left of the cursor. - -C-d - Delete the character underneath the cursor. - -Printing characters - Insert the character into the line at the cursor. - -C-_ - Undo the last thing that you did. You can undo all the way back - to an empty line. - - -File: readline.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction - -Readline Movement Commands --------------------------- - - The above table describes the most basic possible keystrokes that -you need in order to do editing of the input line. For your -convenience, many other commands have been added in addition to C-b, -C-f, C-d, and DEL. Here are some commands for moving more rapidly -about the line. - -C-a - Move to the start of the line. - -C-e - Move to the end of the line. - -M-f - Move forward a word. - -M-b - Move backward a word. - -C-l - Clear the screen, reprinting the current line at the top. - - Notice how C-f moves forward a character, while M-f moves forward a -word. It is a loose convention that control keystrokes operate on -characters while meta keystrokes operate on words. - - -File: readline.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction - -Readline Killing Commands -------------------------- - - "Killing" text means to delete the text from the line, but to save -it away for later use, usually by "yanking" (re-inserting) it back into -the line. If the description for a command says that it `kills' text, -then you can be sure that you can get the text back in a different (or -the same) place later. - - When you use a kill command, the text is saved in a "kill-ring". -Any number of consecutive kills save all of the killed text together, so -that when you yank it back, you get it all. The kill ring is not line -specific; the text that you killed on a previously typed line is -available to be yanked back later, when you are typing another line. - - Here is the list of commands for killing text. - -C-k - Kill the text from the current cursor position to the end of the - line. - -M-d - Kill from the cursor to the end of the current word, or if between - words, to the end of the next word. - -M-DEL - Kill from the cursor the start of the previous word, or if between - words, to the start of the previous word. - -C-w - Kill from the cursor to the previous whitespace. This is - different than M-DEL because the word boundaries differ. - - And, here is how to "yank" the text back into the line. Yanking -means to copy the most-recently-killed text from the kill buffer. - -C-y - Yank the most recently killed text back into the buffer at the - cursor. - -M-y - Rotate the kill-ring, and yank the new top. You can only do this - if the prior command is C-y or M-y. - - -File: readline.info, Node: Readline Arguments, Prev: Readline Killing Commands, Up: Readline Interaction - -Readline Arguments ------------------- - - You can pass numeric arguments to Readline commands. Sometimes the -argument acts as a repeat count, other times it is the sign of the -argument that is significant. If you pass a negative argument to a -command which normally acts in a forward direction, that command will -act in a backward direction. For example, to kill text back to the -start of the line, you might type M- C-k. - - The general way to pass numeric arguments to a command is to type -meta digits before the command. If the first `digit' you type is a -minus sign (-), then the sign of the argument will be negative. Once -you have typed one meta digit to get the argument started, you can type -the remainder of the digits, and then the command. For example, to give -the C-d command an argument of 10, you could type M-1 0 C-d. - - -File: readline.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing - -Readline Init File -================== - - Although the Readline library comes with a set of Emacs-like -keybindings installed by default, it is possible that you would like to -use a different set of keybindings. You can customize programs that -use Readline by putting commands in an "init" file in your home -directory. The name of this file is taken from the value of the -environment variable `INPUTRC'. If that variable is unset, the default -is `~/.inputrc'. - - When a program which uses the Readline library starts up, the init -file is read, and the key bindings are set. - - In addition, the `C-x C-r' command re-reads this init file, thus -incorporating any changes that you might have made to it. - -* Menu: - -* Readline Init Syntax:: Syntax for the commands in the inputrc file. -* Conditional Init Constructs:: Conditional key bindings in the inputrc file. - - -File: readline.info, Node: Readline Init Syntax, Next: Conditional Init Constructs, Up: Readline Init File - -Readline Init Syntax --------------------- - - There are only a few basic constructs allowed in the Readline init -file. Blank lines are ignored. Lines beginning with a # are comments. -Lines beginning with a $ indicate conditional constructs (*note -Conditional Init Constructs::.). Other lines denote variable settings -and key bindings. - -Variable Settings - You can change the state of a few variables in Readline by using - the `set' command within the init file. Here is how you would - specify that you wish to use `vi' line editing commands: - - set editing-mode vi - - Right now, there are only a few variables which can be set; so - few, in fact, that we just list them here: - - `editing-mode' - The `editing-mode' variable controls which editing mode you - are using. By default, Readline starts up in Emacs editing - mode, where the keystrokes are most similar to Emacs. This - variable can be set to either `emacs' or `vi'. - - `horizontal-scroll-mode' - This variable can be set to either `On' or `Off'. Setting it - to `On' means that the text of the lines that you edit will - scroll horizontally on a single screen line when they are - longer than the width of the screen, instead of wrapping onto - a new screen line. By default, this variable is set to `Off'. - - `mark-modified-lines' - This variable, when set to `On', says to display an asterisk - (`*') at the start of history lines which have been modified. - This variable is `off' by default. - - `bell-style' - Controls what happens when Readline wants to ring the - terminal bell. If set to `none', Readline never rings the - bell. If set to `visible', Readline uses a visible bell if - one is available. If set to `audible' (the default), - Readline attempts to ring the terminal's bell. - - `comment-begin' - The string to insert at the beginning of the line when the - `vi-comment' command is executed. The default value is `"#"'. - - `meta-flag' - If set to `on', Readline will enable eight-bit input (it will - not strip the eighth bit from the characters it reads), - regardless of what the terminal claims it can support. The - default value is `off'. - - `convert-meta' - If set to `on', Readline will convert characters with the - eigth bit set to an ASCII key sequence by stripping the eigth - bit and prepending an ESC character, converting them to a - meta-prefixed key sequence. The default value is `on'. - - `output-meta' - If set to `on', Readline will display characters with the - eighth bit set directly rather than as a meta-prefixed escape - sequence. The default is `off'. - - `completion-query-items' - The number of possible completions that determines when the - user is asked whether he wants to see the list of - possibilities. If the number of possible completions is - greater than this value, Readline will ask the user whether - or not he wishes to view them; otherwise, they are simply - listed. The default limit is `100'. - - `keymap' - Sets Readline's idea of the current keymap for key binding - commands. Acceptable `keymap' names are `emacs', - `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move', - `vi-command', and `vi-insert'. `vi' is equivalent to - `vi-command'; `emacs' is equivalent to `emacs-standard'. The - default value is `emacs'. The value of the `editing-mode' - variable also affects the default keymap. - - `show-all-if-ambiguous' - This alters the default behavior of the completion functions. - If set to `on', words which have more than one possible - completion cause the matches to be listed immediately instead - of ringing the bell. The default value is `off'. - - `expand-tilde' - If set to `on', tilde expansion is performed when Readline - attempts word completion. The default is `off'. - -Key Bindings - The syntax for controlling key bindings in the init file is - simple. First you have to know the name of the command that you - want to change. The following pages contain tables of the command - name, the default keybinding, and a short description of what the - command does. - - Once you know the name of the command, simply place the name of - the key you wish to bind the command to, a colon, and then the - name of the command on a line in the init file. The name of the - key can be expressed in different ways, depending on which is most - comfortable for you. - - KEYNAME: FUNCTION-NAME or MACRO - KEYNAME is the name of a key spelled out in English. For - example: - Control-u: universal-argument - Meta-Rubout: backward-kill-word - Control-o: ">&output" - - In the above example, `C-u' is bound to the function - `universal-argument', and `C-o' is bound to run the macro - expressed on the right hand side (that is, to insert the text - `>&output' into the line). - - "KEYSEQ": FUNCTION-NAME or MACRO - KEYSEQ differs from KEYNAME above in that strings denoting an - entire key sequence can be specified, by placing the key - sequence in double quotes. Some GNU Emacs style key escapes - can be used, as in the following example, but the special - character names are not recognized. - - "\C-u": universal-argument - "\C-x\C-r": re-read-init-file - "\e[11~": "Function Key 1" - - In the above example, `C-u' is bound to the function - `universal-argument' (just as it was in the first example), - `C-x C-r' is bound to the function `re-read-init-file', and - `ESC [ 1 1 ~' is bound to insert the text `Function Key 1'. - The following escape sequences are available when specifying - key sequences: - - ``\C-'' - control prefix - - ``\M-'' - meta prefix - - ``\e'' - an escape character - - ``\\'' - backslash - - ``\"'' - " - - ``\''' - ' - - When entering the text of a macro, single or double quotes - should be used to indicate a macro definition. Unquoted text - is assumed to be a function name. Backslash will quote any - character in the macro text, including " and '. For example, - the following binding will make `C-x \' insert a single \ - into the line: - "\C-x\\": "\\" - - -File: readline.info, Node: Conditional Init Constructs, Prev: Readline Init Syntax, Up: Readline Init File - -Conditional Init Constructs ---------------------------- - - Readline implements a facility similar in spirit to the conditional -compilation features of the C preprocessor which allows key bindings -and variable settings to be performed as the result of tests. There -are three parser directives used. - -`$if' - The `$if' construct allows bindings to be made based on the - editing mode, the terminal being used, or the application using - Readline. The text of the test extends to the end of the line; no - characters are required to isolate it. - - `mode' - The `mode=' form of the `$if' directive is used to test - whether Readline is in `emacs' or `vi' mode. This may be - used in conjunction with the `set keymap' command, for - instance, to set bindings in the `emacs-standard' and - `emacs-ctlx' keymaps only if Readline is starting out in - `emacs' mode. - - `term' - The `term=' form may be used to include terminal-specific key - bindings, perhaps to bind the key sequences output by the - terminal's function keys. The word on the right side of the - `=' is tested against the full name of the terminal and the - portion of the terminal name before the first `-'. This - allows SUN to match both SUN and SUN-CMD, for instance. - - `application' - The APPLICATION construct is used to include - application-specific settings. Each program using the - Readline library sets the APPLICATION NAME, and you can test - for it. This could be used to bind key sequences to - functions useful for a specific program. For instance, the - following command adds a key sequence that quotes the current - or previous word in Bash: - $if bash - # Quote the current or previous word - "\C-xq": "\eb\"\ef\"" - $endif - -`$endif' - This command, as you saw in the previous example, terminates an - `$if' command. - -`$else' - Commands in this branch of the `$if' directive are executed if the - test fails. - - -File: readline.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing - -Bindable Readline Commands -========================== - -* Menu: - -* Commands For Moving:: Moving about the line. -* Commands For History:: Getting at previous lines. -* Commands For Text:: Commands for changing text. -* Commands For Killing:: Commands for killing and yanking. -* Numeric Arguments:: Specifying numeric arguments, repeat counts. -* Commands For Completion:: Getting Readline to do the typing for you. -* Keyboard Macros:: Saving and re-executing typed characters -* Miscellaneous Commands:: Other miscellaneous commands. - - -File: readline.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands - -Commands For Moving -------------------- - -`beginning-of-line (C-a)' - Move to the start of the current line. - -`end-of-line (C-e)' - Move to the end of the line. - -`forward-char (C-f)' - Move forward a character. - -`backward-char (C-b)' - Move back a character. - -`forward-word (M-f)' - Move forward to the end of the next word. Words are composed of - letters and digits. - -`backward-word (M-b)' - Move back to the start of this, or the previous, word. Words are - composed of letters and digits. - -`clear-screen (C-l)' - Clear the screen and redraw the current line, leaving the current - line at the top of the screen. - -`redraw-current-line ()' - Refresh the current line. By default, this is unbound. - - -File: readline.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands - -Commands For Manipulating The History -------------------------------------- - -`accept-line (Newline, Return)' - Accept the line regardless of where the cursor is. If this line is - non-empty, add it to the history list. If this line was a history - line, then restore the history line to its original state. - -`previous-history (C-p)' - Move `up' through the history list. - -`next-history (C-n)' - Move `down' through the history list. - -`beginning-of-history (M-<)' - Move to the first line in the history. - -`end-of-history (M->)' - Move to the end of the input history, i.e., the line you are - entering. - -`reverse-search-history (C-r)' - Search backward starting at the current line and moving `up' - through the history as necessary. This is an incremental search. - -`forward-search-history (C-s)' - Search forward starting at the current line and moving `down' - through the the history as necessary. This is an incremental - search. - -`non-incremental-reverse-search-history (M-p)' - Search backward starting at the current line and moving `up' - through the history as necessary using a non-incremental search - for a string supplied by the user. - -`non-incremental-forward-search-history (M-n)' - Search forward starting at the current line and moving `down' - through the the history as necessary using a non-incremental search - for a string supplied by the user. - -`history-search-forward ()' - Search forward through the history for the string of characters - between the start of the current line and the current point. This - is a non-incremental search. By default, this command is unbound. - -`history-search-backward ()' - Search backward through the history for the string of characters - between the start of the current line and the current point. This - is a non-incremental search. By default, this command is unbound. - -`yank-nth-arg (M-C-y)' - Insert the first argument to the previous command (usually the - second word on the previous line). With an argument N, insert the - Nth word from the previous command (the words in the previous - command begin with word 0). A negative argument inserts the Nth - word from the end of the previous command. - -`yank-last-arg (M-., M-_)' - Insert last argument to the previous command (the last word on the - previous line). With an argument, behave exactly like - `yank-nth-arg'. - - -File: readline.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands - -Commands For Changing Text --------------------------- - -`delete-char (C-d)' - Delete the character under the cursor. If the cursor is at the - beginning of the line, there are no characters in the line, and - the last character typed was not C-d, then return EOF. - -`backward-delete-char (Rubout)' - Delete the character behind the cursor. A numeric arg says to kill - the characters instead of deleting them. - -`quoted-insert (C-q, C-v)' - Add the next character that you type to the line verbatim. This is - how to insert key sequences like C-q, for example. - -`tab-insert (M-TAB)' - Insert a tab character. - -`self-insert (a, b, A, 1, !, ...)' - Insert yourself. - -`transpose-chars (C-t)' - Drag the character before the cursor forward over the character at - the cursor, moving the cursor forward as well. If the insertion - point is at the end of the line, then this transposes the last two - characters of the line. Negative argumentss don't work. - -`transpose-words (M-t)' - Drag the word behind the cursor past the word in front of the - cursor moving the cursor over that word as well. - -`upcase-word (M-u)' - Uppercase the current (or following) word. With a negative - argument, do the previous word, but do not move the cursor. - -`downcase-word (M-l)' - Lowercase the current (or following) word. With a negative - argument, do the previous word, but do not move the cursor. - -`capitalize-word (M-c)' - Capitalize the current (or following) word. With a negative - argument, do the previous word, but do not move the cursor. - - -File: readline.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands - -Killing And Yanking -------------------- - -`kill-line (C-k)' - Kill the text from the current cursor position to the end of the - line. - -`backward-kill-line (C-x Rubout)' - Kill backward to the beginning of the line. - -`unix-line-discard (C-u)' - Kill backward from the cursor to the beginning of the current line. - Save the killed text on the kill-ring. - -`kill-whole-line ()' - Kill all characters on the current line, no matter where the - cursor is. By default, this is unbound. - -`kill-word (M-d)' - Kill from the cursor to the end of the current word, or if between - words, to the end of the next word. Word boundaries are the same - as `forward-word'. - -`backward-kill-word (M-DEL)' - Kill the word behind the cursor. Word boundaries are the same as - `backward-word'. - -`unix-word-rubout (C-w)' - Kill the word behind the cursor, using white space as a word - boundary. The killed text is saved on the kill-ring. - -`delete-horizontal-space ()' - Delete all spaces and tabs around point. By default, this is - unbound. - -`yank (C-y)' - Yank the top of the kill ring into the buffer at the current - cursor position. - -`yank-pop (M-y)' - Rotate the kill-ring, and yank the new top. You can only do this - if the prior command is yank or yank-pop. - - -File: readline.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands - -Specifying Numeric Arguments ----------------------------- - -`digit-argument (M-0, M-1, ... M--)' - Add this digit to the argument already accumulating, or start a new - argument. M- starts a negative argument. - -`universal-argument ()' - Each time this is executed, the argument count is multiplied by - four. The argument count is initially one, so executing this - function the first time makes the argument count four. By - default, this is not bound to a key. - - -File: readline.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands - -Letting Readline Type For You ------------------------------ - -`complete (TAB)' - Attempt to do completion on the text before the cursor. This is - application-specific. Generally, if you are typing a filename - argument, you can do filename completion; if you are typing a - command, you can do command completion, if you are typing in a - symbol to GDB, you can do symbol name completion, if you are - typing in a variable to Bash, you can do variable name completion, - and so on. - -`possible-completions (M-?)' - List the possible completions of the text before the cursor. - -`insert-completions ()' - Insert all completions of the text before point that would have - been generated by `possible-completions'. By default, this is not - bound to a key. - - -File: readline.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands - -Keyboard Macros ---------------- - -`start-kbd-macro (C-x ()' - Begin saving the characters typed into the current keyboard macro. - -`end-kbd-macro (C-x ))' - Stop saving the characters typed into the current keyboard macro - and save the definition. - -`call-last-kbd-macro (C-x e)' - Re-execute the last keyboard macro defined, by making the - characters in the macro appear as if typed at the keyboard. - - -File: readline.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands - -Some Miscellaneous Commands ---------------------------- - -`re-read-init-file (C-x C-r)' - Read in the contents of your init file, and incorporate any - bindings or variable assignments found there. - -`abort (C-g)' - Abort the current editing command and ring the terminal's bell - (subject to the setting of `bell-style'). - -`do-uppercase-version (M-a, M-b, ...)' - Run the command that is bound to the corresoponding uppercase - character. - -`prefix-meta (ESC)' - Make the next character that you type be metafied. This is for - people without a meta key. Typing `ESC f' is equivalent to typing - `M-f'. - -`undo (C-_, C-x C-u)' - Incremental undo, separately remembered for each line. - -`revert-line (M-r)' - Undo all changes made to this line. This is like typing the `undo' - command enough times to get back to the beginning. - -`tilde-expand (M-~)' - Perform tilde expansion on the current word. - -`dump-functions ()' - Print all of the functions and their key bindings to the readline - output stream. If a numeric argument is supplied, the output is - formatted in such a way that it can be made part of an INPUTRC - file. - - -File: readline.info, Node: Readline vi Mode, Prev: Bindable Readline Commands, Up: Command Line Editing - -Readline vi Mode -================ - - While the Readline library does not have a full set of `vi' editing -functions, it does contain enough to allow simple editing of the line. -The Readline `vi' mode behaves as specified in the Posix 1003.2 -standard. - - In order to switch interactively between `Emacs' and `Vi' editing -modes, use the command M-C-j (toggle-editing-mode). The Readline -default is `emacs' mode. - - When you enter a line in `vi' mode, you are already placed in -`insertion' mode, as if you had typed an `i'. Pressing ESC switches -you into `command' mode, where you can edit the text of the line with -the standard `vi' movement keys, move to previous history lines with -`k', and following lines with `j', and so forth. - - This document describes the GNU Readline Library, a utility for -aiding in the consitency of user interface across discrete programs -that need to provide a command line interface. - - Copyright (C) 1988, 1994 Free Software Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice pare -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided that -the entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions, except that this permission notice may be stated in a -translation approved by the Foundation. - - -File: readline.info, Node: Programming with GNU Readline, Next: Concept Index, Prev: Command Line Editing, Up: Top - -Programming with GNU Readline -***************************** - - This chapter describes the interface between the GNU Readline -Library and other programs. If you are a programmer, and you wish to -include the features found in GNU Readline such as completion, line -editing, and interactive history manipulation in your own programs, -this section is for you. - -* Menu: - -* Basic Behavior:: Using the default behavior of Readline. -* Custom Functions:: Adding your own functions to Readline. -* Readline Convenience Functions:: Functions which Readline supplies to - aid in writing your own -* Custom Completers:: Supplanting or supplementing Readline's - completion functions. - - -File: readline.info, Node: Basic Behavior, Next: Custom Functions, Up: Programming with GNU Readline - -Basic Behavior -============== - - Many programs provide a command line interface, such as `mail', -`ftp', and `sh'. For such programs, the default behaviour of Readline -is sufficient. This section describes how to use Readline in the -simplest way possible, perhaps to replace calls in your code to -`gets()' or `fgets ()'. - - The function `readline ()' prints a prompt and then reads and returns -a single line of text from the user. The line `readline' returns is -allocated with `malloc ()'; you should `free ()' the line when you are -done with it. The declaration for `readline' in ANSI C is - - `char *readline (char *PROMPT);' - -So, one might say - `char *line = readline ("Enter a line: ");' - -in order to read a line of text from the user. The line returned has -the final newline removed, so only the text remains. - - If `readline' encounters an `EOF' while reading the line, and the -line is empty at that point, then `(char *)NULL' is returned. -Otherwise, the line is ended just as if a newline had been typed. - - If you want the user to be able to get at the line later, (with C-p -for example), you must call `add_history ()' to save the line away in a -"history" list of such lines. - - `add_history (line)'; - -For full details on the GNU History Library, see the associated manual. - - It is preferable to avoid saving empty lines on the history list, -since users rarely have a burning need to reuse a blank line. Here is -a function which usefully replaces the standard `gets ()' library -function, and has the advantage of no static buffer to overflow: - - /* A static variable for holding the line. */ - static char *line_read = (char *)NULL; - - /* Read a string, and return a pointer to it. Returns NULL on EOF. */ - char * - rl_gets () - { - /* If the buffer has already been allocated, return the memory - to the free pool. */ - if (line_read) - { - free (line_read); - line_read = (char *)NULL; - } - - /* Get a line from the user. */ - line_read = readline (""); - - /* If the line has any text in it, save it on the history. */ - if (line_read && *line_read) - add_history (line_read); - - return (line_read); - } - - This function gives the user the default behaviour of TAB -completion: completion on file names. If you do not want Readline to -complete on filenames, you can change the binding of the TAB key with -`rl_bind_key ()'. - - `int rl_bind_key (int KEY, int (*FUNCTION)());' - - `rl_bind_key ()' takes two arguments: KEY is the character that you -want to bind, and FUNCTION is the address of the function to call when -KEY is pressed. Binding TAB to `rl_insert ()' makes TAB insert itself. -`rl_bind_key ()' returns non-zero if KEY is not a valid ASCII character -code (between 0 and 255). - - Thus, to disable the default TAB behavior, the following suffices: - `rl_bind_key ('\t', rl_insert);' - - This code should be executed once at the start of your program; you -might write a function called `initialize_readline ()' which performs -this and other desired initializations, such as installing custom -completers (*note Custom Completers::.). - - -File: readline.info, Node: Custom Functions, Next: Readline Convenience Functions, Prev: Basic Behavior, Up: Programming with GNU Readline - -Custom Functions -================ - - Readline provides many functions for manipulating the text of the -line, but it isn't possible to anticipate the needs of all programs. -This section describes the various functions and variables defined -within the Readline library which allow a user program to add -customized functionality to Readline. - -* Menu: - -* The Function Type:: C declarations to make code readable. -* Function Writing:: Variables and calling conventions. - - -File: readline.info, Node: The Function Type, Next: Function Writing, Up: Custom Functions - -The Function Type ------------------ - - For readabilty, we declare a new type of object, called "Function". -A `Function' is a C function which returns an `int'. The type -declaration for `Function' is: - -`typedef int Function ();' - - The reason for declaring this new type is to make it easier to write -code describing pointers to C functions. Let us say we had a variable -called FUNC which was a pointer to a function. Instead of the classic -C declaration - - `int (*)()func;' - -we may write - - `Function *func;' - -Similarly, there are - - typedef void VFunction (); - typedef char *CPFunction (); and - typedef char **CPPFunction (); - -for functions returning no value, `pointer to char', and `pointer to -pointer to char', respectively. - - -File: readline.info, Node: Function Writing, Prev: The Function Type, Up: Custom Functions - -Writing a New Function ----------------------- - - In order to write new functions for Readline, you need to know the -calling conventions for keyboard-invoked functions, and the names of the -variables that describe the current state of the line read so far. - - The calling sequence for a command `foo' looks like - - `foo (int count, int key)' - -where COUNT is the numeric argument (or 1 if defaulted) and KEY is the -key that invoked this function. - - It is completely up to the function as to what should be done with -the numeric argument. Some functions use it as a repeat count, some as -a flag, and others to choose alternate behavior (refreshing the current -line as opposed to refreshing the screen, for example). Some choose to -ignore it. In general, if a function uses the numeric argument as a -repeat count, it should be able to do something useful with both -negative and positive arguments. At the very least, it should be aware -that it can be passed a negative argument. - - - Variable: char * rl_line_buffer - This is the line gathered so far. You are welcome to modify the - contents of the line, but see *Note Allowing Undoing::. - - - Variable: int rl_point - The offset of the current cursor position in `rl_line_buffer' (the - *point*). - - - Variable: int rl_end - The number of characters present in `rl_line_buffer'. When - `rl_point' is at the end of the line, `rl_point' and `rl_end' are - equal. - - - Variable: int rl_mark - The mark (saved position) in the current line. If set, the mark - and point define a *region*. - - - Variable: int rl_done - Setting this to a non-zero value causes Readline to return the - current line immediately. - - - Variable: int rl_pending_input - Setting this to a value makes it the next keystroke read. This is - a way to stuff a single character into the input stream. - - - Variable: char * rl_prompt - The prompt Readline uses. This is set from the argument to - `readline ()', and should not be assigned to directly. - - - Variable: char * rl_terminal_name - The terminal type, used for initialization. - - - Variable: char * rl_readline_name - This variable is set to a unique name by each application using - Readline. The value allows conditional parsing of the inputrc file - (*note Conditional Init Constructs::.). - - - Variable: FILE * rl_instream - The stdio stream from which Readline reads input. - - - Variable: FILE * rl_outstream - The stdio stream to which Readline performs output. - - - Variable: Function * rl_startup_hook - If non-zero, this is the address of a function to call just before - `readline' prints the first prompt. - - -File: readline.info, Node: Readline Convenience Functions, Next: Custom Completers, Prev: Custom Functions, Up: Programming with GNU Readline - -Readline Convenience Functions -============================== - -* Menu: - -* Function Naming:: How to give a function you write a name. -* Keymaps:: Making keymaps. -* Binding Keys:: Changing Keymaps. -* Associating Function Names and Bindings:: Translate function names to - key sequences. -* Allowing Undoing:: How to make your functions undoable. -* Redisplay:: Functions to control line display. -* Modifying Text:: Functions to modify `rl_line_buffer'. -* Utility Functions:: Generally useful functions and hooks. - - -File: readline.info, Node: Function Naming, Next: Keymaps, Up: Readline Convenience Functions - -Naming a Function ------------------ - - The user can dynamically change the bindings of keys while using -Readline. This is done by representing the function with a descriptive -name. The user is able to type the descriptive name when referring to -the function. Thus, in an init file, one might find - - Meta-Rubout: backward-kill-word - - This binds the keystroke Meta-Rubout to the function *descriptively* -named `backward-kill-word'. You, as the programmer, should bind the -functions you write to descriptive names as well. Readline provides a -function for doing that: - - - Function: int rl_add_defun (char *name, Function *function, int key) - Add NAME to the list of named functions. Make FUNCTION be the - function that gets called. If KEY is not -1, then bind it to - FUNCTION using `rl_bind_key ()'. - - Using this function alone is sufficient for most applications. It is -the recommended way to add a few functions to the default functions that -Readline has built in. If you need to do something other than adding a -function to Readline, you may need to use the underlying functions -described below. - - -File: readline.info, Node: Keymaps, Next: Binding Keys, Prev: Function Naming, Up: Readline Convenience Functions - -Selecting a Keymap ------------------- - - Key bindings take place on a "keymap". The keymap is the -association between the keys that the user types and the functions that -get run. You can make your own keymaps, copy existing keymaps, and tell -Readline which keymap to use. - - - Function: Keymap rl_make_bare_keymap () - Returns a new, empty keymap. The space for the keymap is - allocated with `malloc ()'; you should `free ()' it when you are - done. - - - Function: Keymap rl_copy_keymap (Keymap map) - Return a new keymap which is a copy of MAP. - - - Function: Keymap rl_make_keymap () - Return a new keymap with the printing characters bound to - rl_insert, the lowercase Meta characters bound to run their - equivalents, and the Meta digits bound to produce numeric - arguments. - - - Function: void rl_discard_keymap (Keymap keymap) - Free the storage associated with KEYMAP. - - Readline has several internal keymaps. These functions allow you to -change which keymap is active. - - - Function: Keymap rl_get_keymap () - Returns the currently active keymap. - - - Function: void rl_set_keymap (Keymap keymap) - Makes KEYMAP the currently active keymap. - - - Function: Keymap rl_get_keymap_by_name (char *name) - Return the keymap matching NAME. NAME is one which would be - supplied in a `set keymap' inputrc line (*note Readline Init - File::.). - - -File: readline.info, Node: Binding Keys, Next: Associating Function Names and Bindings, Prev: Keymaps, Up: Readline Convenience Functions - -Binding Keys ------------- - - You associate keys with functions through the keymap. Readline has -several internal keymaps: `emacs_standard_keymap', `emacs_meta_keymap', -`emacs_ctlx_keymap', `vi_movement_keymap', and `vi_insertion_keymap'. -`emacs_standard_keymap' is the default, and the examples in this manual -assume that. - - These functions manage key bindings. - - - Function: int rl_bind_key (int key, Function *function) - Binds KEY to FUNCTION in the currently active keymap. Returns - non-zero in the case of an invalid KEY. - - - Function: int rl_bind_key_in_map (int key, Function *function, - Keymap map) - Bind KEY to FUNCTION in MAP. Returns non-zero in the case of an - invalid KEY. - - - Function: int rl_unbind_key (int key) - Bind KEY to the null function in the currently active keymap. - Returns non-zero in case of error. - - - Function: int rl_unbind_key_in_map (int key, Keymap map) - Bind KEY to the null function in MAP. Returns non-zero in case of - error. - - - Function: int rl_generic_bind (int type, char *keyseq, char *data, - Keymap map) - Bind the key sequence represented by the string KEYSEQ to the - arbitrary pointer DATA. TYPE says what kind of data is pointed to - by DATA; this can be a function (`ISFUNC'), a macro (`ISMACR'), or - a keymap (`ISKMAP'). This makes new keymaps as necessary. The - initial keymap in which to do bindings is MAP. - - - Function: int rl_parse_and_bind (char *line) - Parse LINE as if it had been read from the `inputrc' file and - perform any key bindings and variable assignments found (*note - Readline Init File::.). - - -File: readline.info, Node: Associating Function Names and Bindings, Next: Allowing Undoing, Prev: Binding Keys, Up: Readline Convenience Functions - -Associating Function Names and Bindings ---------------------------------------- - - These functions allow you to find out what keys invoke named -functions and the functions invoked by a particular key sequence. - - - Function: Function * rl_named_function (char *name) - Return the function with name NAME. - - - Function: Function * rl_function_of_keyseq (char *keyseq, Keymap - map, int *type) - Return the function invoked by KEYSEQ in keymap MAP. If MAP is - NULL, the current keymap is used. If TYPE is not NULL, the type - of the object is returned in it (one of `ISFUNC', `ISKMAP', or - `ISMACR'). - - - Function: char ** rl_invoking_keyseqs (Function *function) - Return an array of strings representing the key sequences used to - invoke FUNCTION in the current keymap. - - - Function: char ** rl_invoking_keyseqs_in_map (Function *function, - Keymap map) - Return an array of strings representing the key sequences used to - invoke FUNCTION in the keymap MAP. - - -File: readline.info, Node: Allowing Undoing, Next: Redisplay, Prev: Associating Function Names and Bindings, Up: Readline Convenience Functions - -Allowing Undoing ----------------- - - Supporting the undo command is a painless thing, and makes your -functions much more useful. It is certainly easy to try something if -you know you can undo it. I could use an undo function for the stock -market. - - If your function simply inserts text once, or deletes text once, and -uses `rl_insert_text ()' or `rl_delete_text ()' to do it, then undoing -is already done for you automatically. - - If you do multiple insertions or multiple deletions, or any -combination of these operations, you should group them together into -one operation. This is done with `rl_begin_undo_group ()' and -`rl_end_undo_group ()'. - - The types of events that can be undone are: - - enum undo_code { UNDO_DELETE, UNDO_INSERT, UNDO_BEGIN, UNDO_END }; - - Notice that `UNDO_DELETE' means to insert some text, and -`UNDO_INSERT' means to delete some text. That is, the undo code tells -undo what to undo, not how to undo it. `UNDO_BEGIN' and `UNDO_END' are -tags added by `rl_begin_undo_group ()' and `rl_end_undo_group ()'. - - - Function: int rl_begin_undo_group () - Begins saving undo information in a group construct. The undo - information usually comes from calls to `rl_insert_text ()' and - `rl_delete_text ()', but could be the result of calls to - `rl_add_undo ()'. - - - Function: int rl_end_undo_group () - Closes the current undo group started with `rl_begin_undo_group - ()'. There should be one call to `rl_end_undo_group ()' for each - call to `rl_begin_undo_group ()'. - - - Function: void rl_add_undo (enum undo_code what, int start, int end, - char *text) - Remember how to undo an event (according to WHAT). The affected - text runs from START to END, and encompasses TEXT. - - - Function: void free_undo_list () - Free the existing undo list. - - - Function: int rl_do_undo () - Undo the first thing on the undo list. Returns `0' if there was - nothing to undo, non-zero if something was undone. - - Finally, if you neither insert nor delete text, but directly modify -the existing text (e.g., change its case), call `rl_modifying ()' once, -just before you modify the text. You must supply the indices of the -text range that you are going to modify. - - - Function: int rl_modifying (int start, int end) - Tell Readline to save the text between START and END as a single - undo unit. It is assumed that you will subsequently modify that - text. - - -File: readline.info, Node: Redisplay, Next: Modifying Text, Prev: Allowing Undoing, Up: Readline Convenience Functions - -Redisplay ---------- - - - Function: int rl_redisplay () - Change what's displayed on the screen to reflect the current - contents of `rl_line_buffer'. - - - Function: int rl_forced_update_display () - Force the line to be updated and redisplayed, whether or not - Readline thinks the screen display is correct. - - - Function: int rl_on_new_line () - Tell the update routines that we have moved onto a new (empty) - line, usually after ouputting a newline. - - - Function: int rl_reset_line_state () - Reset the display state to a clean state and redisplay the current - line starting on a new line. - - - Function: int rl_message (va_alist) - The arguments are a string as would be supplied to `printf'. The - resulting string is displayed in the "echo area". The echo area - is also used to display numeric arguments and search strings. - - - Function: int rl_clear_message () - Clear the message in the echo area. - diff --git a/gnu/lib/libreadline/doc/readline.info-2 b/gnu/lib/libreadline/doc/readline.info-2 deleted file mode 100644 index 35681aa..0000000 --- a/gnu/lib/libreadline/doc/readline.info-2 +++ /dev/null @@ -1,978 +0,0 @@ -This is Info file readline.info, produced by Makeinfo-1.55 from the -input file rlman.texinfo. - - This document describes the GNU Readline Library, a utility which -aids in the consistency of user interface across discrete programs that -need to provide a command line interface. - - Copyright (C) 1988, 1991 Free Software Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice pare -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided that -the entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions, except that this permission notice may be stated in a -translation approved by the Foundation. - - -File: readline.info, Node: Modifying Text, Next: Utility Functions, Prev: Redisplay, Up: Readline Convenience Functions - -Modifying Text --------------- - - - Function: int rl_insert_text (char *text) - Insert TEXT into the line at the current cursor position. - - - Function: int rl_delete_text (int start, int end) - Delete the text between START and END in the current line. - - - Function: char * rl_copy_text (int start, int end) - Return a copy of the text between START and END in the current - line. - - - Function: int rl_kill_text (int start, int end) - Copy the text between START and END in the current line to the - kill ring, appending or prepending to the last kill if the last - command was a kill command. The text is deleted. If START is - less than END, the text is appended, otherwise prepended. If the - last command was not a kill, a new kill ring slot is used. - - -File: readline.info, Node: Utility Functions, Prev: Modifying Text, Up: Readline Convenience Functions - -Utility Functions ------------------ - - - Function: int rl_reset_terminal (char *terminal_name) - Reinitialize Readline's idea of the terminal settings using - TERMINAL_NAME as the terminal type (e.g., `vt100'). - - - Function: int alphabetic (int c) - Return 1 if C is an alphabetic character. - - - Function: int numeric (int c) - Return 1 if C is a numeric character. - - - Function: int ding () - Ring the terminal bell, obeying the setting of `bell-style'. - - The following are implemented as macros, defined in `chartypes.h'. - - - Function: int uppercase_p (int c) - Return 1 if C is an uppercase alphabetic character. - - - Function: int lowercase_p (int c) - Return 1 if C is a lowercase alphabetic character. - - - Function: int digit_p (int c) - Return 1 if C is a numeric character. - - - Function: int to_upper (int c) - If C is a lowercase alphabetic character, return the corresponding - uppercase character. - - - Function: int to_lower (int c) - If C is an uppercase alphabetic character, return the corresponding - lowercase character. - - - Function: int digit_value (int c) - If C is a number, return the value it represents. - -An Example ----------- - - Here is a function which changes lowercase characters to their -uppercase equivalents, and uppercase characters to lowercase. If this -function was bound to `M-c', then typing `M-c' would change the case of -the character under point. Typing `M-1 0 M-c' would change the case of -the following 10 characters, leaving the cursor on the last character -changed. - - /* Invert the case of the COUNT following characters. */ - int - invert_case_line (count, key) - int count, key; - { - register int start, end, i; - - start = rl_point; - - if (rl_point >= rl_end) - return (0); - - if (count < 0) - { - direction = -1; - count = -count; - } - else - direction = 1; - - /* Find the end of the range to modify. */ - end = start + (count * direction); - - /* Force it to be within range. */ - if (end > rl_end) - end = rl_end; - else if (end < 0) - end = 0; - - if (start == end) - return (0); - - if (start > end) - { - int temp = start; - start = end; - end = temp; - } - - /* Tell readline that we are modifying the line, so it will save - the undo information. */ - rl_modifying (start, end); - - for (i = start; i != end; i++) - { - if (uppercase_p (rl_line_buffer[i])) - rl_line_buffer[i] = to_lower (rl_line_buffer[i]); - else if (lowercase_p (rl_line_buffer[i])) - rl_line_buffer[i] = to_upper (rl_line_buffer[i]); - } - /* Move point to on top of the last character changed. */ - rl_point = (direction == 1) ? end - 1 : start; - return (0); - } - - -File: readline.info, Node: Custom Completers, Prev: Readline Convenience Functions, Up: Programming with GNU Readline - -Custom Completers -================= - - Typically, a program that reads commands from the user has a way of -disambiguating commands and data. If your program is one of these, then -it can provide completion for commands, data, or both. The following -sections describe how your program and Readline cooperate to provide -this service. - -* Menu: - -* How Completing Works:: The logic used to do completion. -* Completion Functions:: Functions provided by Readline. -* Completion Variables:: Variables which control completion. -* A Short Completion Example:: An example of writing completer subroutines. - - -File: readline.info, Node: How Completing Works, Next: Completion Functions, Up: Custom Completers - -How Completing Works --------------------- - - In order to complete some text, the full list of possible completions -must be available. That is, it is not possible to accurately expand a -partial word without knowing all of the possible words which make sense -in that context. The Readline library provides the user interface to -completion, and two of the most common completion functions: filename -and username. For completing other types of text, you must write your -own completion function. This section describes exactly what such -functions must do, and provides an example. - - There are three major functions used to perform completion: - - 1. The user-interface function `rl_complete ()'. This function is - called with the same arguments as other Readline functions - intended for interactive use: COUNT and INVOKING_KEY. It - isolates the word to be completed and calls `completion_matches - ()' to generate a list of possible completions. It then either - lists the possible completions, inserts the possible completions, - or actually performs the completion, depending on which behavior - is desired. - - 2. The internal function `completion_matches ()' uses your - "generator" function to generate the list of possible matches, and - then returns the array of these matches. You should place the - address of your generator function in - `rl_completion_entry_function'. - - 3. The generator function is called repeatedly from - `completion_matches ()', returning a string each time. The - arguments to the generator function are TEXT and STATE. TEXT is - the partial word to be completed. STATE is zero the first time - the function is called, allowing the generator to perform any - necessary initialization, and a positive non-zero integer for each - subsequent call. When the generator function returns `(char - *)NULL' this signals `completion_matches ()' that there are no - more possibilities left. Usually the generator function computes - the list of possible completions when STATE is zero, and returns - them one at a time on subsequent calls. Each string the generator - function returns as a match must be allocated with `malloc()'; - Readline frees the strings when it has finished with them. - - - - Function: int rl_complete (int ignore, int invoking_key) - Complete the word at or before point. You have supplied the - function that does the initial simple matching selection algorithm - (see `completion_matches ()'). The default is to do filename - completion. - - - Variable: Function * rl_completion_entry_function - This is a pointer to the generator function for `completion_matches - ()'. If the value of `rl_completion_entry_function' is `(Function - *)NULL' then the default filename generator function, - `filename_entry_function ()', is used. - - -File: readline.info, Node: Completion Functions, Next: Completion Variables, Prev: How Completing Works, Up: Custom Completers - -Completion Functions --------------------- - - Here is the complete list of callable completion functions present in -Readline. - - - Function: int rl_complete_internal (int what_to_do) - Complete the word at or before point. WHAT_TO_DO says what to do - with the completion. A value of `?' means list the possible - completions. `TAB' means do standard completion. `*' means - insert all of the possible completions. `!' means to display all - of the possible completions, if there is more than one, as well as - performing partial completion. - - - Function: int rl_complete (int ignore, int invoking_key) - Complete the word at or before point. You have supplied the - function that does the initial simple matching selection algorithm - (see `completion_matches ()' and `rl_completion_entry_function'). - The default is to do filename completion. This calls - `rl_complete_internal ()' with an argument depending on - INVOKING_KEY. - - - Function: int rl_possible_completions (int count, int invoking_key)) - List the possible completions. See description of `rl_complete - ()'. This calls `rl_complete_internal ()' with an argument of `?'. - - - Function: int rl_insert_completions (int count, int invoking_key)) - Insert the list of possible completions into the line, deleting the - partially-completed word. See description of `rl_complete ()'. - This calls `rl_complete_internal ()' with an argument of `*'. - - - Function: char ** completion_matches (char *text, CPFunction - *entry_func) - Returns an array of `(char *)' which is a list of completions for - TEXT. If there are no completions, returns `(char **)NULL'. The - first entry in the returned array is the substitution for TEXT. - The remaining entries are the possible completions. The array is - terminated with a `NULL' pointer. - - ENTRY_FUNC is a function of two args, and returns a `(char *)'. - The first argument is TEXT. The second is a state argument; it is - zero on the first call, and non-zero on subsequent calls. - eNTRY_FUNC returns a `NULL' pointer to the caller when there are - no more matches. - - - Function: char * filename_completion_function (char *text, int state) - A generator function for filename completion in the general case. - Note that completion in Bash is a little different because of all - the pathnames that must be followed when looking up completions - for a command. The Bash source is a useful reference for writing - custom completion functions. - - - Function: char * username_completion_function (char *text, int state) - A completion generator for usernames. TEXT contains a partial - username preceded by a random character (usually `~'). As with all - completion generators, STATE is zero on the first call and non-zero - for subsequent calls. - - -File: readline.info, Node: Completion Variables, Next: A Short Completion Example, Prev: Completion Functions, Up: Custom Completers - -Completion Variables --------------------- - - - Variable: Function * rl_completion_entry_function - A pointer to the generator function for `completion_matches ()'. - `NULL' means to use `filename_entry_function ()', the default - filename completer. - - - Variable: CPPFunction * rl_attempted_completion_function - A pointer to an alternative function to create matches. The - function is called with TEXT, START, and END. START and END are - indices in `rl_line_buffer' saying what the boundaries of TEXT - are. If this function exists and returns `NULL', or if this - variable is set to `NULL', then `rl_complete ()' will call the - value of `rl_completion_entry_function' to generate matches, - otherwise the array of strings returned will be used. - - - Variable: int rl_completion_query_items - Up to this many items will be displayed in response to a - possible-completions call. After that, we ask the user if she is - sure she wants to see them all. The default value is 100. - - - Variable: char * rl_basic_word_break_characters - The basic list of characters that signal a break between words for - the completer routine. The default value of this variable is the - characters which break words for completion in Bash, i.e., `" - \t\n\"\\'`@$><=;|&{("'. - - - Variable: char * rl_completer_word_break_characters - The list of characters that signal a break between words for - `rl_complete_internal ()'. The default list is the value of - `rl_basic_word_break_characters'. - - - Variable: char * rl_special_prefixes - The list of characters that are word break characters, but should - be left in TEXT when it is passed to the completion function. - Programs can use this to help determine what kind of completing to - do. For instance, Bash sets this variable to "$@" so that it can - complete shell variables and hostnames. - - - Variable: int rl_ignore_completion_duplicates - If non-zero, then disallow duplicates in the matches. Default is - 1. - - - Variable: int rl_filename_completion_desired - Non-zero means that the results of the matches are to be treated as - filenames. This is *always* zero on entry, and can only be changed - within a completion entry generator function. If it is set to a - non-zero value, directory names have a slash appended and Readline - attempts to quote completed filenames if they contain any embedded - word break characters. - - - Variable: int rl_filename_quoting_desired - Non-zero means that the results of the matches are to be quoted - using double quotes (or an application-specific quoting mechanism) - if the completed filename contains any characters in - `rl_completer_word_break_chars'. This is *always* non-zero on - entry, and can only be changed within a completion entry generator - function. - - - Variable: Function * rl_ignore_some_completions_function - This function, if defined, is called by the completer when real - filename completion is done, after all the matching names have - been generated. It is passed a `NULL' terminated array of matches. - The first element (`matches[0]') is the maximal substring common - to all matches. This function can re-arrange the list of matches - as required, but each element deleted from the array must be freed. - - - Variable: char * rl_completer_quote_characters - List of characters which can be used to quote a substring of the - line. Completion occurs on the entire substring, and within the - substring `rl_completer_word_break_characters' are treated as any - other character, unless they also appear within this list. - - -File: readline.info, Node: A Short Completion Example, Prev: Completion Variables, Up: Custom Completers - -A Short Completion Example --------------------------- - - Here is a small application demonstrating the use of the GNU Readline -library. It is called `fileman', and the source code resides in -`examples/fileman.c'. This sample application provides completion of -command names, line editing features, and access to the history list. - - /* fileman.c -- A tiny application which demonstrates how to use the - GNU Readline library. This application interactively allows users - to manipulate files and their modes. */ - - #include - #include - #include - #include - #include - - #include - #include - - extern char *getwd (); - extern char *xmalloc (); - - /* The names of functions that actually do the manipulation. */ - int com_list (), com_view (), com_rename (), com_stat (), com_pwd (); - int com_delete (), com_help (), com_cd (), com_quit (); - - /* A structure which contains information on the commands this program - can understand. */ - - typedef struct { - char *name; /* User printable name of the function. */ - Function *func; /* Function to call to do the job. */ - char *doc; /* Documentation for this function. */ - } COMMAND; - - COMMAND commands[] = { - { "cd", com_cd, "Change to directory DIR" }, - { "delete", com_delete, "Delete FILE" }, - { "help", com_help, "Display this text" }, - { "?", com_help, "Synonym for `help'" }, - { "list", com_list, "List files in DIR" }, - { "ls", com_list, "Synonym for `list'" }, - { "pwd", com_pwd, "Print the current working directory" }, - { "quit", com_quit, "Quit using Fileman" }, - { "rename", com_rename, "Rename FILE to NEWNAME" }, - { "stat", com_stat, "Print out statistics on FILE" }, - { "view", com_view, "View the contents of FILE" }, - { (char *)NULL, (Function *)NULL, (char *)NULL } - }; - - /* Forward declarations. */ - char *stripwhite (); - COMMAND *find_command (); - - /* The name of this program, as taken from argv[0]. */ - char *progname; - - /* When non-zero, this global means the user is done using this program. */ - int done; - - char * - dupstr (s) - int s; - { - char *r; - - r = xmalloc (strlen (s) + 1); - strcpy (r, s); - return (r); - } - - main (argc, argv) - int argc; - char **argv; - { - char *line, *s; - - progname = argv[0]; - - initialize_readline (); /* Bind our completer. */ - - /* Loop reading and executing lines until the user quits. */ - for ( ; done == 0; ) - { - line = readline ("FileMan: "); - - if (!line) - break; - - /* Remove leading and trailing whitespace from the line. - Then, if there is anything left, add it to the history list - and execute it. */ - s = stripwhite (line); - - if (*s) - { - add_history (s); - execute_line (s); - } - - free (line); - } - exit (0); - } - - /* Execute a command line. */ - int - execute_line (line) - char *line; - { - register int i; - COMMAND *command; - char *word; - - /* Isolate the command word. */ - i = 0; - while (line[i] && whitespace (line[i])) - i++; - word = line + i; - - while (line[i] && !whitespace (line[i])) - i++; - - if (line[i]) - line[i++] = '\0'; - - command = find_command (word); - - if (!command) - { - fprintf (stderr, "%s: No such command for FileMan.\n", word); - return (-1); - } - - /* Get argument to command, if any. */ - while (whitespace (line[i])) - i++; - - word = line + i; - - /* Call the function. */ - return ((*(command->func)) (word)); - } - - /* Look up NAME as the name of a command, and return a pointer to that - command. Return a NULL pointer if NAME isn't a command name. */ - COMMAND * - find_command (name) - char *name; - { - register int i; - - for (i = 0; commands[i].name; i++) - if (strcmp (name, commands[i].name) == 0) - return (&commands[i]); - - return ((COMMAND *)NULL); - } - - /* Strip whitespace from the start and end of STRING. Return a pointer - into STRING. */ - char * - stripwhite (string) - char *string; - { - register char *s, *t; - - for (s = string; whitespace (*s); s++) - ; - - if (*s == 0) - return (s); - - t = s + strlen (s) - 1; - while (t > s && whitespace (*t)) - t--; - *++t = '\0'; - - return s; - } - - /* **************************************************************** */ - /* */ - /* Interface to Readline Completion */ - /* */ - /* **************************************************************** */ - - char *command_generator (); - char **fileman_completion (); - - /* Tell the GNU Readline library how to complete. We want to try to complete - on command names if this is the first word in the line, or on filenames - if not. */ - initialize_readline () - { - /* Allow conditional parsing of the ~/.inputrc file. */ - rl_readline_name = "FileMan"; - - /* Tell the completer that we want a crack first. */ - rl_attempted_completion_function = (CPPFunction *)fileman_completion; - } - - /* Attempt to complete on the contents of TEXT. START and END show the - region of TEXT that contains the word to complete. We can use the - entire line in case we want to do some simple parsing. Return the - array of matches, or NULL if there aren't any. */ - char ** - fileman_completion (text, start, end) - char *text; - int start, end; - { - char **matches; - - matches = (char **)NULL; - - /* If this word is at the start of the line, then it is a command - to complete. Otherwise it is the name of a file in the current - directory. */ - if (start == 0) - matches = completion_matches (text, command_generator); - - return (matches); - } - - /* Generator function for command completion. STATE lets us know whether - to start from scratch; without any state (i.e. STATE == 0), then we - start at the top of the list. */ - char * - command_generator (text, state) - char *text; - int state; - { - static int list_index, len; - char *name; - - /* If this is a new word to complete, initialize now. This includes - saving the length of TEXT for efficiency, and initializing the index - variable to 0. */ - if (!state) - { - list_index = 0; - len = strlen (text); - } - - /* Return the next name which partially matches from the command list. */ - while (name = commands[list_index].name) - { - list_index++; - - if (strncmp (name, text, len) == 0) - return (dupstr(name)); - } - - /* If no names matched, then return NULL. */ - return ((char *)NULL); - } - - /* **************************************************************** */ - /* */ - /* FileMan Commands */ - /* */ - /* **************************************************************** */ - - /* String to pass to system (). This is for the LIST, VIEW and RENAME - commands. */ - static char syscom[1024]; - - /* List the file(s) named in arg. */ - com_list (arg) - char *arg; - { - if (!arg) - arg = ""; - - sprintf (syscom, "ls -FClg %s", arg); - return (system (syscom)); - } - - com_view (arg) - char *arg; - { - if (!valid_argument ("view", arg)) - return 1; - - sprintf (syscom, "more %s", arg); - return (system (syscom)); - } - - com_rename (arg) - char *arg; - { - too_dangerous ("rename"); - return (1); - } - - com_stat (arg) - char *arg; - { - struct stat finfo; - - if (!valid_argument ("stat", arg)) - return (1); - - if (stat (arg, &finfo) == -1) - { - perror (arg); - return (1); - } - - printf ("Statistics for `%s':\n", arg); - - printf ("%s has %d link%s, and is %d byte%s in length.\n", arg, - finfo.st_nlink, - (finfo.st_nlink == 1) ? "" : "s", - finfo.st_size, - (finfo.st_size == 1) ? "" : "s"); - printf ("Inode Last Change at: %s", ctime (&finfo.st_ctime)); - printf (" Last access at: %s", ctime (&finfo.st_atime)); - printf (" Last modified at: %s", ctime (&finfo.st_mtime)); - return (0); - } - - com_delete (arg) - char *arg; - { - too_dangerous ("delete"); - return (1); - } - - /* Print out help for ARG, or for all of the commands if ARG is - not present. */ - com_help (arg) - char *arg; - { - register int i; - int printed = 0; - - for (i = 0; commands[i].name; i++) - { - if (!*arg || (strcmp (arg, commands[i].name) == 0)) - { - printf ("%s\t\t%s.\n", commands[i].name, commands[i].doc); - printed++; - } - } - - if (!printed) - { - printf ("No commands match `%s'. Possibilties are:\n", arg); - - for (i = 0; commands[i].name; i++) - { - /* Print in six columns. */ - if (printed == 6) - { - printed = 0; - printf ("\n"); - } - - printf ("%s\t", commands[i].name); - printed++; - } - - if (printed) - printf ("\n"); - } - return (0); - } - - /* Change to the directory ARG. */ - com_cd (arg) - char *arg; - { - if (chdir (arg) == -1) - { - perror (arg); - return 1; - } - - com_pwd (""); - return (0); - } - - /* Print out the current working directory. */ - com_pwd (ignore) - char *ignore; - { - char dir[1024], *s; - - s = getwd (dir); - if (s == 0) - { - printf ("Error getting pwd: %s\n", dir); - return 1; - } - - printf ("Current directory is %s\n", dir); - return 0; - } - - /* The user wishes to quit using this program. Just set DONE non-zero. */ - com_quit (arg) - char *arg; - { - done = 1; - return (0); - } - - /* Function which tells you that you can't do this. */ - too_dangerous (caller) - char *caller; - { - fprintf (stderr, - "%s: Too dangerous for me to distribute. Write it yourself.\n", - caller); - } - - /* Return non-zero if ARG is a valid argument for CALLER, else print - an error message and return zero. */ - int - valid_argument (caller, arg) - char *caller, *arg; - { - if (!arg || !*arg) - { - fprintf (stderr, "%s: Argument required.\n", caller); - return (0); - } - - return (1); - } - - -File: readline.info, Node: Concept Index, Next: Function and Variable Index, Prev: Programming with GNU Readline, Up: Top - -Concept Index -************* - -* Menu: - -* interaction, readline: Readline Interaction. -* Kill ring: Readline Killing Commands. -* Killing text: Readline Killing Commands. -* readline, function: Basic Behavior. -* Yanking text: Readline Killing Commands. - - -File: readline.info, Node: Function and Variable Index, Prev: Concept Index, Up: Top - -Function and Variable Index -*************************** - -* Menu: - -* $else: Conditional Init Constructs. -* $endif: Conditional Init Constructs. -* $if: Conditional Init Constructs. -* abort (C-g): Miscellaneous Commands. -* accept-line (Newline, Return): Commands For History. -* alphabetic: Utility Functions. -* backward-char (C-b): Commands For Moving. -* backward-delete-char (Rubout): Commands For Text. -* backward-kill-line (C-x Rubout): Commands For Killing. -* backward-kill-word (M-DEL): Commands For Killing. -* backward-word (M-b): Commands For Moving. -* beginning-of-history (M-<): Commands For History. -* beginning-of-line (C-a): Commands For Moving. -* bell-style: Readline Init Syntax. -* call-last-kbd-macro (C-x e): Keyboard Macros. -* capitalize-word (M-c): Commands For Text. -* clear-screen (C-l): Commands For Moving. -* comment-begin: Readline Init Syntax. -* complete (TAB): Commands For Completion. -* completion-query-items: Readline Init Syntax. -* completion_matches: Completion Functions. -* convert-meta: Readline Init Syntax. -* delete-char (C-d): Commands For Text. -* delete-horizontal-space (): Commands For Killing. -* digit-argument (M-0, M-1, ... M-): Numeric Arguments. -* digit_p: Utility Functions. -* digit_value: Utility Functions. -* ding: Utility Functions. -* do-uppercase-version (M-a, M-b, ...): Miscellaneous Commands. -* downcase-word (M-l): Commands For Text. -* dump-functions (): Miscellaneous Commands. -* editing-mode: Readline Init Syntax. -* end-kbd-macro (C-x )): Keyboard Macros. -* end-of-history (M->): Commands For History. -* end-of-line (C-e): Commands For Moving. -* expand-tilde: Readline Init Syntax. -* filename_completion_function: Completion Functions. -* forward-char (C-f): Commands For Moving. -* forward-search-history (C-s): Commands For History. -* forward-word (M-f): Commands For Moving. -* free_undo_list: Allowing Undoing. -* history-search-backward (): Commands For History. -* history-search-forward (): Commands For History. -* horizontal-scroll-mode: Readline Init Syntax. -* insert-completions (): Commands For Completion. -* keymap: Readline Init Syntax. -* kill-line (C-k): Commands For Killing. -* kill-whole-line (): Commands For Killing. -* kill-word (M-d): Commands For Killing. -* lowercase_p: Utility Functions. -* mark-modified-lines: Readline Init Syntax. -* meta-flag: Readline Init Syntax. -* next-history (C-n): Commands For History. -* non-incremental-forward-search-history (M-n): Commands For History. -* non-incremental-reverse-search-history (M-p): Commands For History. -* numeric: Utility Functions. -* output-meta: Readline Init Syntax. -* possible-completions (M-?): Commands For Completion. -* prefix-meta (ESC): Miscellaneous Commands. -* previous-history (C-p): Commands For History. -* quoted-insert (C-q, C-v): Commands For Text. -* re-read-init-file (C-x C-r): Miscellaneous Commands. -* readline: Basic Behavior. -* redraw-current-line (): Commands For Moving. -* reverse-search-history (C-r): Commands For History. -* revert-line (M-r): Miscellaneous Commands. -* rl_add_defun: Function Naming. -* rl_add_undo: Allowing Undoing. -* rl_attempted_completion_function: Completion Variables. -* rl_basic_word_break_characters: Completion Variables. -* rl_begin_undo_group: Allowing Undoing. -* rl_bind_key: Binding Keys. -* rl_bind_key_in_map: Binding Keys. -* rl_clear_message: Redisplay. -* rl_complete: How Completing Works. -* rl_complete: Completion Functions. -* rl_completer_quote_characters: Completion Variables. -* rl_completer_word_break_characters: Completion Variables. -* rl_complete_internal: Completion Functions. -* rl_completion_entry_function: Completion Variables. -* rl_completion_entry_function: How Completing Works. -* rl_completion_query_items: Completion Variables. -* rl_copy_keymap: Keymaps. -* rl_copy_text: Modifying Text. -* rl_delete_text: Modifying Text. -* rl_discard_keymap: Keymaps. -* rl_done: Function Writing. -* rl_do_undo: Allowing Undoing. -* rl_end: Function Writing. -* rl_end_undo_group: Allowing Undoing. -* rl_filename_completion_desired: Completion Variables. -* rl_filename_quoting_desired: Completion Variables. -* rl_forced_update_display: Redisplay. -* rl_function_of_keyseq: Associating Function Names and Bindings. -* rl_generic_bind: Binding Keys. -* rl_get_keymap: Keymaps. -* rl_get_keymap_by_name: Keymaps. -* rl_ignore_completion_duplicates: Completion Variables. -* rl_ignore_some_completions_function: Completion Variables. -* rl_insert_completions: Completion Functions. -* rl_insert_text: Modifying Text. -* rl_instream: Function Writing. -* rl_invoking_keyseqs: Associating Function Names and Bindings. -* rl_invoking_keyseqs_in_map: Associating Function Names and Bindings. -* rl_kill_text: Modifying Text. -* rl_line_buffer: Function Writing. -* rl_make_bare_keymap: Keymaps. -* rl_make_keymap: Keymaps. -* rl_mark: Function Writing. -* rl_message: Redisplay. -* rl_modifying: Allowing Undoing. -* rl_named_function: Associating Function Names and Bindings. -* rl_on_new_line: Redisplay. -* rl_outstream: Function Writing. -* rl_parse_and_bind: Binding Keys. -* rl_pending_input: Function Writing. -* rl_point: Function Writing. -* rl_possible_completions: Completion Functions. -* rl_prompt: Function Writing. -* rl_readline_name: Function Writing. -* rl_redisplay: Redisplay. -* rl_reset_line_state: Redisplay. -* rl_reset_terminal: Utility Functions. -* rl_set_keymap: Keymaps. -* rl_special_prefixes: Completion Variables. -* rl_startup_hook: Function Writing. -* rl_terminal_name: Function Writing. -* rl_unbind_key: Binding Keys. -* rl_unbind_key_in_map: Binding Keys. -* self-insert (a, b, A, 1, !, ...): Commands For Text. -* show-all-if-ambiguous: Readline Init Syntax. -* start-kbd-macro (C-x (): Keyboard Macros. -* tab-insert (M-TAB): Commands For Text. -* tilde-expand (M-~): Miscellaneous Commands. -* to_lower: Utility Functions. -* to_upper: Utility Functions. -* transpose-chars (C-t): Commands For Text. -* transpose-words (M-t): Commands For Text. -* undo (C-_, C-x C-u): Miscellaneous Commands. -* universal-argument (): Numeric Arguments. -* unix-line-discard (C-u): Commands For Killing. -* unix-word-rubout (C-w): Commands For Killing. -* upcase-word (M-u): Commands For Text. -* uppercase_p: Utility Functions. -* username_completion_function: Completion Functions. -* yank (C-y): Commands For Killing. -* yank-last-arg (M-., M-_): Commands For History. -* yank-nth-arg (M-C-y): Commands For History. -* yank-pop (M-y): Commands For Killing. - - diff --git a/gnu/lib/libreadline/doc/rlman.texinfo b/gnu/lib/libreadline/doc/rlman.texinfo deleted file mode 100644 index ec14066..0000000 --- a/gnu/lib/libreadline/doc/rlman.texinfo +++ /dev/null @@ -1,111 +0,0 @@ -\input texinfo @c -*-texinfo-*- -@comment %**start of header (This is for running Texinfo on a region.) -@setfilename readline.info -@settitle GNU Readline Library -@comment %**end of header (This is for running Texinfo on a region.) -@synindex vr fn -@setchapternewpage odd - -@ignore -last change: Thu Jul 21 16:02:40 EDT 1994 -@end ignore - -@set EDITION 2.0 -@set VERSION 2.0 -@set UPDATED 21 July 1994 -@set UPDATE-MONTH July 1994 - -@ifinfo -This document describes the GNU Readline Library, a utility which aids -in the consistency of user interface across discrete programs that need -to provide a command line interface. - -Copyright (C) 1988, 1991 Free Software Foundation, Inc. - -Permission is granted to make and distribute verbatim copies of -this manual provided the copyright notice and this permission notice -pare preserved on all copies. - -@ignore -Permission is granted to process this file through TeX and print the -results, provided the printed document carries copying permission -notice identical to this one except for the removal of this paragraph -(this paragraph not being relevant to the printed manual). -@end ignore - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided that the entire -resulting derived work is distributed under the terms of a permission -notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that this permission notice may be stated in a translation approved -by the Foundation. -@end ifinfo - -@titlepage -@sp 10 -@title GNU Readline Library -@subtitle Edition @value{EDITION}, for @code{Readline Library} Version @value{VERSION}. -@subtitle @value{UPDATE-MONTH} -@author Brian Fox, Free Software Foundation -@author Chet Ramey, Case Western Reserve University - -@page -This document describes the GNU Readline Library, a utility which aids -in the consistency of user interface across discrete programs that need -to provide a command line interface. - -Published by the Free Software Foundation @* -675 Massachusetts Avenue, @* -Cambridge, MA 02139 USA - -Permission is granted to make and distribute verbatim copies of -this manual provided the copyright notice and this permission notice -are preserved on all copies. - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided that the entire -resulting derived work is distributed under the terms of a permission -notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that this permission notice may be stated in a translation approved -by the Foundation. - -@vskip 0pt plus 1filll -Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. -@end titlepage - -@ifinfo -@node Top -@top GNU Readline Library - -This document describes the GNU Readline Library, a utility which aids -in the consistency of user interface across discrete programs that need -to provide a command line interface. - -@menu -* Command Line Editing:: GNU Readline User's Manual. -* Programming with GNU Readline:: GNU Readline Programmer's Manual. -* Concept Index:: Index of concepts described in this manual. -* Function and Variable Index:: Index of externally visible functions - and variables. -@end menu -@end ifinfo - -@include rluser.texinfo -@include rltech.texinfo - -@node Concept Index -@unnumbered Concept Index -@printindex cp - -@node Function and Variable Index -@unnumbered Function and Variable Index -@printindex fn - -@contents -@bye diff --git a/gnu/lib/libreadline/doc/texindex.c b/gnu/lib/libreadline/doc/texindex.c deleted file mode 100644 index 9233bab..0000000 --- a/gnu/lib/libreadline/doc/texindex.c +++ /dev/null @@ -1,1666 +0,0 @@ -/* Prepare TeX index dribble output into an actual index. - - Version 1.45 - - Copyright (C) 1987, 1991, 1992 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - - -#include -#include -#include -#include "getopt.h" -#include "bashansi.h" - -#if !defined (errno) -extern int errno; -#endif - -#if defined (HAVE_UNISTD_H) -# include -#else /* !HAVE_UNISTD_H */ -extern long lseek (); -#endif /* !HAVE_UNISTD_H */ - -extern char *mktemp (); - -#if !defined (HAVE_STRERROR) -extern int sys_nerr; -extern char *sys_errlist[]; -#endif - -#include - -#if defined (_AIX) || !defined (_POSIX_VERSION) -# include -#endif - -#include - -#define TI_NO_ERROR 0 -#define TI_FATAL_ERROR 1 - -#if !defined (SEEK_SET) -# define SEEK_SET 0 -# define SEEK_CUR 1 -# define SEEK_END 2 -#endif /* !SEEK_SET */ - -/* When sorting in core, this structure describes one line - and the position and length of its first keyfield. */ -struct lineinfo -{ - char *text; /* The actual text of the line. */ - union { - char *text; /* The start of the key (for textual comparison). */ - long number; /* The numeric value (for numeric comparison). */ - } key; - long keylen; /* Length of KEY field. */ -}; - -/* This structure describes a field to use as a sort key. */ -struct keyfield -{ - int startwords; /* Number of words to skip. */ - int startchars; /* Number of additional chars to skip. */ - int endwords; /* Number of words to ignore at end. */ - int endchars; /* Ditto for characters of last word. */ - char ignore_blanks; /* Non-zero means ignore spaces and tabs. */ - char fold_case; /* Non-zero means case doesn't matter. */ - char reverse; /* Non-zero means compare in reverse order. */ - char numeric; /* Non-zeros means field is ASCII numeric. */ - char positional; /* Sort according to file position. */ - char braced; /* Count balanced-braced groupings as fields. */ -}; - -/* Vector of keyfields to use. */ -struct keyfield keyfields[3]; - -/* Number of keyfields stored in that vector. */ -int num_keyfields = 3; - -/* Vector of input file names, terminated with a null pointer. */ -char **infiles; - -/* Vector of corresponding output file names, or NULL, meaning default it - (add an `s' to the end). */ -char **outfiles; - -/* Length of `infiles'. */ -int num_infiles; - -/* Pointer to the array of pointers to lines being sorted. */ -char **linearray; - -/* The allocated length of `linearray'. */ -long nlines; - -/* Directory to use for temporary files. On Unix, it ends with a slash. */ -char *tempdir; - -/* Start of filename to use for temporary files. */ -char *tempbase; - -/* Number of last temporary file. */ -int tempcount; - -/* Number of last temporary file already deleted. - Temporary files are deleted by `flush_tempfiles' in order of creation. */ -int last_deleted_tempcount; - -/* During in-core sort, this points to the base of the data block - which contains all the lines of data. */ -char *text_base; - -/* Additional command switches .*/ - -/* Nonzero means do not delete tempfiles -- for debugging. */ -int keep_tempfiles; - -/* The name this program was run with. */ -char *program_name; - -/* Forward declarations of functions in this file. */ - -void decode_command (); -void sort_in_core (); -void sort_offline (); -char **parsefile (); -char *find_field (); -char *find_pos (); -long find_value (); -char *find_braced_pos (); -char *find_braced_end (); -void writelines (); -int compare_field (); -int compare_full (); -long readline (); -int merge_files (); -int merge_direct (); -void pfatal_with_name (); -void fatal (); -void error (); -void *xmalloc (), *xrealloc (); -char *concat (); -char *maketempname (); -void flush_tempfiles (); -char *tempcopy (); - -#define MAX_IN_CORE_SORT 500000 - -void -main (argc, argv) - int argc; - char **argv; -{ - int i; - - tempcount = 0; - last_deleted_tempcount = 0; - program_name = argv[0]; - - /* Describe the kind of sorting to do. */ - /* The first keyfield uses the first braced field and folds case. */ - keyfields[0].braced = 1; - keyfields[0].fold_case = 1; - keyfields[0].endwords = -1; - keyfields[0].endchars = -1; - - /* The second keyfield uses the second braced field, numerically. */ - keyfields[1].braced = 1; - keyfields[1].numeric = 1; - keyfields[1].startwords = 1; - keyfields[1].endwords = -1; - keyfields[1].endchars = -1; - - /* The third keyfield (which is ignored while discarding duplicates) - compares the whole line. */ - keyfields[2].endwords = -1; - keyfields[2].endchars = -1; - - decode_command (argc, argv); - - tempbase = mktemp (concat ("txiXXXXXX", "", "")); - - /* Process input files completely, one by one. */ - - for (i = 0; i < num_infiles; i++) - { - int desc; - long ptr; - char *outfile; - - desc = open (infiles[i], O_RDONLY, 0); - if (desc < 0) - pfatal_with_name (infiles[i]); - lseek (desc, 0L, SEEK_END); - ptr = lseek (desc, 0L, SEEK_CUR); - - close (desc); - - outfile = outfiles[i]; - if (!outfile) - { - outfile = concat (infiles[i], "s", ""); - } - - if (ptr < MAX_IN_CORE_SORT) - /* Sort a small amount of data. */ - sort_in_core (infiles[i], ptr, outfile); - else - sort_offline (infiles[i], ptr, outfile); - } - - flush_tempfiles (tempcount); - exit (TI_NO_ERROR); -} - -void -usage () -{ - fprintf (stderr, "\ -Usage: %s [-k] infile [-o outfile] ...\n", program_name); - exit (1); -} - -/* Decode the command line arguments to set the parameter variables - and set up the vector of keyfields and the vector of input files. */ - -void -decode_command (argc, argv) - int argc; - char **argv; -{ - int optc; - char **ip; - char **op; - - /* Store default values into parameter variables. */ - - tempdir = getenv ("TMPDIR"); - if (tempdir == NULL) - tempdir = "/tmp/"; - else - tempdir = concat (tempdir, "/", ""); - - keep_tempfiles = 0; - - /* Allocate ARGC input files, which must be enough. */ - - infiles = (char **) xmalloc (argc * sizeof (char *)); - outfiles = (char **) xmalloc (argc * sizeof (char *)); - ip = infiles; - op = outfiles; - - while ((optc = getopt (argc, argv, "-ko:")) != EOF) - { - switch (optc) - { - case 1: /* Non-option filename. */ - *ip++ = optarg; - *op++ = NULL; - break; - - case 'k': - keep_tempfiles = 1; - break; - - case 'o': - if (op > outfiles) - *(op - 1) = optarg; - break; - - default: - usage (); - } - } - - /* Record number of keyfields and terminate list of filenames. */ - num_infiles = ip - infiles; - *ip = 0; - if (num_infiles == 0) - usage (); -} - -/* Return a name for a temporary file. */ - -char * -maketempname (count) - int count; -{ - char tempsuffix[10]; - sprintf (tempsuffix, "%d", count); - return concat (tempdir, tempbase, tempsuffix); -} - -/* Delete all temporary files up to TO_COUNT. */ - -void -flush_tempfiles (to_count) - int to_count; -{ - if (keep_tempfiles) - return; - while (last_deleted_tempcount < to_count) - unlink (maketempname (++last_deleted_tempcount)); -} - -/* Copy the input file open on IDESC into a temporary file - and return the temporary file name. */ - -#define BUFSIZE 1024 - -char * -tempcopy (idesc) - int idesc; -{ - char *outfile = maketempname (++tempcount); - int odesc; - char buffer[BUFSIZE]; - - odesc = open (outfile, O_WRONLY | O_CREAT, 0666); - - if (odesc < 0) - pfatal_with_name (outfile); - - while (1) - { - int nread = read (idesc, buffer, BUFSIZE); - write (odesc, buffer, nread); - if (!nread) - break; - } - - close (odesc); - - return outfile; -} - -/* Compare LINE1 and LINE2 according to the specified set of keyfields. */ - -int -compare_full (line1, line2) - char **line1, **line2; -{ - int i; - - /* Compare using the first keyfield; - if that does not distinguish the lines, try the second keyfield; - and so on. */ - - for (i = 0; i < num_keyfields; i++) - { - long length1, length2; - char *start1 = find_field (&keyfields[i], *line1, &length1); - char *start2 = find_field (&keyfields[i], *line2, &length2); - int tem = compare_field (&keyfields[i], start1, length1, *line1 - text_base, - start2, length2, *line2 - text_base); - if (tem) - { - if (keyfields[i].reverse) - return -tem; - return tem; - } - } - - return 0; /* Lines match exactly. */ -} - -/* Compare LINE1 and LINE2, described by structures - in which the first keyfield is identified in advance. - For positional sorting, assumes that the order of the lines in core - reflects their nominal order. */ - -int -compare_prepared (line1, line2) - struct lineinfo *line1, *line2; -{ - int i; - int tem; - char *text1, *text2; - - /* Compare using the first keyfield, which has been found for us already. */ - if (keyfields->positional) - { - if (line1->text - text_base > line2->text - text_base) - tem = 1; - else - tem = -1; - } - else if (keyfields->numeric) - tem = line1->key.number - line2->key.number; - else - tem = compare_field (keyfields, line1->key.text, line1->keylen, 0, - line2->key.text, line2->keylen, 0); - if (tem) - { - if (keyfields->reverse) - return -tem; - return tem; - } - - text1 = line1->text; - text2 = line2->text; - - /* Compare using the second keyfield; - if that does not distinguish the lines, try the third keyfield; - and so on. */ - - for (i = 1; i < num_keyfields; i++) - { - long length1, length2; - char *start1 = find_field (&keyfields[i], text1, &length1); - char *start2 = find_field (&keyfields[i], text2, &length2); - int tem = compare_field (&keyfields[i], start1, length1, text1 - text_base, - start2, length2, text2 - text_base); - if (tem) - { - if (keyfields[i].reverse) - return -tem; - return tem; - } - } - - return 0; /* Lines match exactly. */ -} - -/* Like compare_full but more general. - You can pass any strings, and you can say how many keyfields to use. - POS1 and POS2 should indicate the nominal positional ordering of - the two lines in the input. */ - -int -compare_general (str1, str2, pos1, pos2, use_keyfields) - char *str1, *str2; - long pos1, pos2; - int use_keyfields; -{ - int i; - - /* Compare using the first keyfield; - if that does not distinguish the lines, try the second keyfield; - and so on. */ - - for (i = 0; i < use_keyfields; i++) - { - long length1, length2; - char *start1 = find_field (&keyfields[i], str1, &length1); - char *start2 = find_field (&keyfields[i], str2, &length2); - int tem = compare_field (&keyfields[i], start1, length1, pos1, - start2, length2, pos2); - if (tem) - { - if (keyfields[i].reverse) - return -tem; - return tem; - } - } - - return 0; /* Lines match exactly. */ -} - -/* Find the start and length of a field in STR according to KEYFIELD. - A pointer to the starting character is returned, and the length - is stored into the int that LENGTHPTR points to. */ - -char * -find_field (keyfield, str, lengthptr) - struct keyfield *keyfield; - char *str; - long *lengthptr; -{ - char *start; - char *end; - char *(*fun) (); - - if (keyfield->braced) - fun = find_braced_pos; - else - fun = find_pos; - - start = (*fun) (str, keyfield->startwords, keyfield->startchars, - keyfield->ignore_blanks); - if (keyfield->endwords < 0) - { - if (keyfield->braced) - end = find_braced_end (start); - else - { - end = start; - while (*end && *end != '\n') - end++; - } - } - else - { - end = (*fun) (str, keyfield->endwords, keyfield->endchars, 0); - if (end - str < start - str) - end = start; - } - *lengthptr = end - start; - return start; -} - -/* Return a pointer to a specified place within STR, - skipping (from the beginning) WORDS words and then CHARS chars. - If IGNORE_BLANKS is nonzero, we skip all blanks - after finding the specified word. */ - -char * -find_pos (str, words, chars, ignore_blanks) - char *str; - int words, chars; - int ignore_blanks; -{ - int i; - char *p = str; - - for (i = 0; i < words; i++) - { - char c; - /* Find next bunch of nonblanks and skip them. */ - while ((c = *p) == ' ' || c == '\t') - p++; - while ((c = *p) && c != '\n' && !(c == ' ' || c == '\t')) - p++; - if (!*p || *p == '\n') - return p; - } - - while (*p == ' ' || *p == '\t') - p++; - - for (i = 0; i < chars; i++) - { - if (!*p || *p == '\n') - break; - p++; - } - return p; -} - -/* Like find_pos but assumes that each field is surrounded by braces - and that braces within fields are balanced. */ - -char * -find_braced_pos (str, words, chars, ignore_blanks) - char *str; - int words, chars; - int ignore_blanks; -{ - int i; - int bracelevel; - char *p = str; - char c; - - for (i = 0; i < words; i++) - { - bracelevel = 1; - while ((c = *p++) != '{' && c != '\n' && c) - /* Do nothing. */ ; - if (c != '{') - return p - 1; - while (bracelevel) - { - c = *p++; - if (c == '{') - bracelevel++; - if (c == '}') - bracelevel--; - if (c == 0 || c == '\n') - return p - 1; - } - } - - while ((c = *p++) != '{' && c != '\n' && c) - /* Do nothing. */ ; - - if (c != '{') - return p - 1; - - if (ignore_blanks) - while ((c = *p) == ' ' || c == '\t') - p++; - - for (i = 0; i < chars; i++) - { - if (!*p || *p == '\n') - break; - p++; - } - return p; -} - -/* Find the end of the balanced-brace field which starts at STR. - The position returned is just before the closing brace. */ - -char * -find_braced_end (str) - char *str; -{ - int bracelevel; - char *p = str; - char c; - - bracelevel = 1; - while (bracelevel) - { - c = *p++; - if (c == '{') - bracelevel++; - if (c == '}') - bracelevel--; - if (c == 0 || c == '\n') - return p - 1; - } - return p - 1; -} - -long -find_value (start, length) - char *start; - long length; -{ - while (length != 0L) - { - if (isdigit (*start)) - return atol (start); - length--; - start++; - } - return 0l; -} - -/* Vector used to translate characters for comparison. - This is how we make all alphanumerics follow all else, - and ignore case in the first sorting. */ -int char_order[256]; - -void -init_char_order () -{ - int i; - for (i = 1; i < 256; i++) - char_order[i] = i; - - for (i = '0'; i <= '9'; i++) - char_order[i] += 512; - - for (i = 'a'; i <= 'z'; i++) - { - char_order[i] = 512 + i; - char_order[i + 'A' - 'a'] = 512 + i; - } -} - -/* Compare two fields (each specified as a start pointer and a character count) - according to KEYFIELD. - The sign of the value reports the relation between the fields. */ - -int -compare_field (keyfield, start1, length1, pos1, start2, length2, pos2) - struct keyfield *keyfield; - char *start1; - long length1; - long pos1; - char *start2; - long length2; - long pos2; -{ - if (keyfields->positional) - { - if (pos1 > pos2) - return 1; - else - return -1; - } - if (keyfield->numeric) - { - long value = find_value (start1, length1) - find_value (start2, length2); - if (value > 0) - return 1; - if (value < 0) - return -1; - return 0; - } - else - { - char *p1 = start1; - char *p2 = start2; - char *e1 = start1 + length1; - char *e2 = start2 + length2; - - while (1) - { - int c1, c2; - - if (p1 == e1) - c1 = 0; - else - c1 = *p1++; - if (p2 == e2) - c2 = 0; - else - c2 = *p2++; - - if (char_order[c1] != char_order[c2]) - return char_order[c1] - char_order[c2]; - if (!c1) - break; - } - - /* Strings are equal except possibly for case. */ - p1 = start1; - p2 = start2; - while (1) - { - int c1, c2; - - if (p1 == e1) - c1 = 0; - else - c1 = *p1++; - if (p2 == e2) - c2 = 0; - else - c2 = *p2++; - - if (c1 != c2) - /* Reverse sign here so upper case comes out last. */ - return c2 - c1; - if (!c1) - break; - } - - return 0; - } -} - -/* A `struct linebuffer' is a structure which holds a line of text. - `readline' reads a line from a stream into a linebuffer - and works regardless of the length of the line. */ - -struct linebuffer -{ - long size; - char *buffer; -}; - -/* Initialize LINEBUFFER for use. */ - -void -initbuffer (linebuffer) - struct linebuffer *linebuffer; -{ - linebuffer->size = 200; - linebuffer->buffer = (char *) xmalloc (200); -} - -/* Read a line of text from STREAM into LINEBUFFER. - Return the length of the line. */ - -long -readline (linebuffer, stream) - struct linebuffer *linebuffer; - FILE *stream; -{ - char *buffer = linebuffer->buffer; - char *p = linebuffer->buffer; - char *end = p + linebuffer->size; - - while (1) - { - int c = getc (stream); - if (p == end) - { - buffer = (char *) xrealloc (buffer, linebuffer->size *= 2); - p += buffer - linebuffer->buffer; - end += buffer - linebuffer->buffer; - linebuffer->buffer = buffer; - } - if (c < 0 || c == '\n') - { - *p = 0; - break; - } - *p++ = c; - } - - return p - buffer; -} - -/* Sort an input file too big to sort in core. */ - -void -sort_offline (infile, nfiles, total, outfile) - char *infile; - int nfiles; - long total; - char *outfile; -{ - /* More than enough. */ - int ntemps = 2 * (total + MAX_IN_CORE_SORT - 1) / MAX_IN_CORE_SORT; - char **tempfiles = (char **) xmalloc (ntemps * sizeof (char *)); - FILE *istream = fopen (infile, "r"); - int i; - struct linebuffer lb; - long linelength; - int failure = 0; - - initbuffer (&lb); - - /* Read in one line of input data. */ - - linelength = readline (&lb, istream); - - if (lb.buffer[0] != '\\' && lb.buffer[0] != '@') - { - error ("%s: not a texinfo index file", infile); - return; - } - - /* Split up the input into `ntemps' temporary files, or maybe fewer, - and put the new files' names into `tempfiles' */ - - for (i = 0; i < ntemps; i++) - { - char *outname = maketempname (++tempcount); - FILE *ostream = fopen (outname, "w"); - long tempsize = 0; - - if (!ostream) - pfatal_with_name (outname); - tempfiles[i] = outname; - - /* Copy lines into this temp file as long as it does not make file - "too big" or until there are no more lines. */ - - while (tempsize + linelength + 1 <= MAX_IN_CORE_SORT) - { - tempsize += linelength + 1; - fputs (lb.buffer, ostream); - putc ('\n', ostream); - - /* Read another line of input data. */ - - linelength = readline (&lb, istream); - if (!linelength && feof (istream)) - break; - - if (lb.buffer[0] != '\\' && lb.buffer[0] != '@') - { - error ("%s: not a texinfo index file", infile); - failure = 1; - goto fail; - } - } - fclose (ostream); - if (feof (istream)) - break; - } - - free (lb.buffer); - -fail: - /* Record number of temp files we actually needed. */ - - ntemps = i; - - /* Sort each tempfile into another tempfile. - Delete the first set of tempfiles and put the names of the second - into `tempfiles'. */ - - for (i = 0; i < ntemps; i++) - { - char *newtemp = maketempname (++tempcount); - sort_in_core (&tempfiles[i], MAX_IN_CORE_SORT, newtemp); - if (!keep_tempfiles) - unlink (tempfiles[i]); - tempfiles[i] = newtemp; - } - - if (failure) - return; - - /* Merge the tempfiles together and indexify. */ - - merge_files (tempfiles, ntemps, outfile); -} - -/* Sort INFILE, whose size is TOTAL, - assuming that is small enough to be done in-core, - then indexify it and send the output to OUTFILE (or to stdout). */ - -void -sort_in_core (infile, total, outfile) - char *infile; - long total; - char *outfile; -{ - char **nextline; - char *data = (char *) xmalloc (total + 1); - char *file_data; - long file_size; - int i; - FILE *ostream = stdout; - struct lineinfo *lineinfo; - - /* Read the contents of the file into the moby array `data'. */ - - int desc = open (infile, O_RDONLY, 0); - - if (desc < 0) - fatal ("failure reopening %s", infile); - for (file_size = 0;;) - { - i = read (desc, data + file_size, total - file_size); - if (i <= 0) - break; - file_size += i; - } - file_data = data; - data[file_size] = 0; - - close (desc); - - if (file_size > 0 && data[0] != '\\' && data[0] != '@') - { - error ("%s: not a texinfo index file", infile); - return; - } - - init_char_order (); - - /* Sort routines want to know this address. */ - - text_base = data; - - /* Create the array of pointers to lines, with a default size - frequently enough. */ - - nlines = total / 50; - if (!nlines) - nlines = 2; - linearray = (char **) xmalloc (nlines * sizeof (char *)); - - /* `nextline' points to the next free slot in this array. - `nlines' is the allocated size. */ - - nextline = linearray; - - /* Parse the input file's data, and make entries for the lines. */ - - nextline = parsefile (infile, nextline, file_data, file_size); - if (nextline == 0) - { - error ("%s: not a texinfo index file", infile); - return; - } - - /* Sort the lines. */ - - /* If we have enough space, find the first keyfield of each line in advance. - Make a `struct lineinfo' for each line, which records the keyfield - as well as the line, and sort them. */ - - lineinfo = (struct lineinfo *) malloc ((nextline - linearray) * sizeof (struct lineinfo)); - - if (lineinfo) - { - struct lineinfo *lp; - char **p; - - for (lp = lineinfo, p = linearray; p != nextline; lp++, p++) - { - lp->text = *p; - lp->key.text = find_field (keyfields, *p, &lp->keylen); - if (keyfields->numeric) - lp->key.number = find_value (lp->key.text, lp->keylen); - } - - qsort (lineinfo, nextline - linearray, sizeof (struct lineinfo), compare_prepared); - - for (lp = lineinfo, p = linearray; p != nextline; lp++, p++) - *p = lp->text; - - free (lineinfo); - } - else - qsort (linearray, nextline - linearray, sizeof (char *), compare_full); - - /* Open the output file. */ - - if (outfile) - { - ostream = fopen (outfile, "w"); - if (!ostream) - pfatal_with_name (outfile); - } - - writelines (linearray, nextline - linearray, ostream); - if (outfile) - fclose (ostream); - - free (linearray); - free (data); -} - -/* Parse an input string in core into lines. - DATA is the input string, and SIZE is its length. - Data goes in LINEARRAY starting at NEXTLINE. - The value returned is the first entry in LINEARRAY still unused. - Value 0 means input file contents are invalid. */ - -char ** -parsefile (filename, nextline, data, size) - char *filename; - char **nextline; - char *data; - long size; -{ - char *p, *end; - char **line = nextline; - - p = data; - end = p + size; - *end = 0; - - while (p != end) - { - if (p[0] != '\\' && p[0] != '@') - return 0; - - *line = p; - while (*p && *p != '\n') - p++; - if (p != end) - p++; - - line++; - if (line == linearray + nlines) - { - char **old = linearray; - linearray = (char **) xrealloc (linearray, sizeof (char *) * (nlines *= 4)); - line += linearray - old; - } - } - - return line; -} - -/* Indexification is a filter applied to the sorted lines - as they are being written to the output file. - Multiple entries for the same name, with different page numbers, - get combined into a single entry with multiple page numbers. - The first braced field, which is used for sorting, is discarded. - However, its first character is examined, folded to lower case, - and if it is different from that in the previous line fed to us - a \initial line is written with one argument, the new initial. - - If an entry has four braced fields, then the second and third - constitute primary and secondary names. - In this case, each change of primary name - generates a \primary line which contains only the primary name, - and in between these are \secondary lines which contain - just a secondary name and page numbers. */ - -/* The last primary name we wrote a \primary entry for. - If only one level of indexing is being done, this is the last name seen. */ -char *lastprimary; -/* Length of storage allocated for lastprimary. */ -int lastprimarylength; - -/* Similar, for the secondary name. */ -char *lastsecondary; -int lastsecondarylength; - -/* Zero if we are not in the middle of writing an entry. - One if we have written the beginning of an entry but have not - yet written any page numbers into it. - Greater than one if we have written the beginning of an entry - plus at least one page number. */ -int pending; - -/* The initial (for sorting purposes) of the last primary entry written. - When this changes, a \initial {c} line is written */ - -char *lastinitial; - -int lastinitiallength; - -/* When we need a string of length 1 for the value of lastinitial, - store it here. */ - -char lastinitial1[2]; - -/* Initialize static storage for writing an index. */ - -static void -xbzero(s, n) - char *s; - int n; -{ - register char *p; - for (p = s; n--; ) - *p++ = '\0'; -} - -void -init_index () -{ - pending = 0; - lastinitial = lastinitial1; - lastinitial1[0] = 0; - lastinitial1[1] = 0; - lastinitiallength = 0; - lastprimarylength = 100; - lastprimary = (char *) xmalloc (lastprimarylength + 1); - xbzero (lastprimary, lastprimarylength + 1); - lastsecondarylength = 100; - lastsecondary = (char *) xmalloc (lastsecondarylength + 1); - xbzero (lastsecondary, lastsecondarylength + 1); -} - -/* Indexify. Merge entries for the same name, - insert headers for each initial character, etc. */ - -void -indexify (line, ostream) - char *line; - FILE *ostream; -{ - char *primary, *secondary, *pagenumber; - int primarylength, secondarylength = 0, pagelength; - int nosecondary; - int initiallength; - char *initial; - char initial1[2]; - register char *p; - - /* First, analyze the parts of the entry fed to us this time. */ - - p = find_braced_pos (line, 0, 0, 0); - if (*p == '{') - { - initial = p; - /* Get length of inner pair of braces starting at `p', - including that inner pair of braces. */ - initiallength = find_braced_end (p + 1) + 1 - p; - } - else - { - initial = initial1; - initial1[0] = *p; - initial1[1] = 0; - initiallength = 1; - - if (initial1[0] >= 'a' && initial1[0] <= 'z') - initial1[0] -= 040; - } - - pagenumber = find_braced_pos (line, 1, 0, 0); - pagelength = find_braced_end (pagenumber) - pagenumber; - if (pagelength == 0) - abort (); - - primary = find_braced_pos (line, 2, 0, 0); - primarylength = find_braced_end (primary) - primary; - - secondary = find_braced_pos (line, 3, 0, 0); - nosecondary = !*secondary; - if (!nosecondary) - secondarylength = find_braced_end (secondary) - secondary; - - /* If the primary is different from before, make a new primary entry. */ - if (strncmp (primary, lastprimary, primarylength)) - { - /* Close off current secondary entry first, if one is open. */ - if (pending) - { - fputs ("}\n", ostream); - pending = 0; - } - - /* If this primary has a different initial, include an entry for - the initial. */ - if (initiallength != lastinitiallength || - strncmp (initial, lastinitial, initiallength)) - { - fprintf (ostream, "\\initial {"); - fwrite (initial, 1, initiallength, ostream); - fprintf (ostream, "}\n", initial); - if (initial == initial1) - { - lastinitial = lastinitial1; - *lastinitial1 = *initial1; - } - else - { - lastinitial = initial; - } - lastinitiallength = initiallength; - } - - /* Make the entry for the primary. */ - if (nosecondary) - fputs ("\\entry {", ostream); - else - fputs ("\\primary {", ostream); - fwrite (primary, primarylength, 1, ostream); - if (nosecondary) - { - fputs ("}{", ostream); - pending = 1; - } - else - fputs ("}\n", ostream); - - /* Record name of most recent primary. */ - if (lastprimarylength < primarylength) - { - lastprimarylength = primarylength + 100; - lastprimary = (char *) xrealloc (lastprimary, - 1 + lastprimarylength); - } - strncpy (lastprimary, primary, primarylength); - lastprimary[primarylength] = 0; - - /* There is no current secondary within this primary, now. */ - lastsecondary[0] = 0; - } - - /* Should not have an entry with no subtopic following one with a subtopic. */ - - if (nosecondary && *lastsecondary) - error ("entry %s follows an entry with a secondary name", line); - - /* Start a new secondary entry if necessary. */ - if (!nosecondary && strncmp (secondary, lastsecondary, secondarylength)) - { - if (pending) - { - fputs ("}\n", ostream); - pending = 0; - } - - /* Write the entry for the secondary. */ - fputs ("\\secondary {", ostream); - fwrite (secondary, secondarylength, 1, ostream); - fputs ("}{", ostream); - pending = 1; - - /* Record name of most recent secondary. */ - if (lastsecondarylength < secondarylength) - { - lastsecondarylength = secondarylength + 100; - lastsecondary = (char *) xrealloc (lastsecondary, - 1 + lastsecondarylength); - } - strncpy (lastsecondary, secondary, secondarylength); - lastsecondary[secondarylength] = 0; - } - - /* Here to add one more page number to the current entry. */ - if (pending++ != 1) - fputs (", ", ostream); /* Punctuate first, if this is not the first. */ - fwrite (pagenumber, pagelength, 1, ostream); -} - -/* Close out any unfinished output entry. */ - -void -finish_index (ostream) - FILE *ostream; -{ - if (pending) - fputs ("}\n", ostream); - free (lastprimary); - free (lastsecondary); -} - -/* Copy the lines in the sorted order. - Each line is copied out of the input file it was found in. */ - -void -writelines (linearray, nlines, ostream) - char **linearray; - int nlines; - FILE *ostream; -{ - char **stop_line = linearray + nlines; - char **next_line; - - init_index (); - - /* Output the text of the lines, and free the buffer space. */ - - for (next_line = linearray; next_line != stop_line; next_line++) - { - /* If -u was specified, output the line only if distinct from previous one. */ - if (next_line == linearray - /* Compare previous line with this one, using only the - explicitly specd keyfields. */ - || compare_general (*(next_line - 1), *next_line, 0L, 0L, num_keyfields - 1)) - { - char *p = *next_line; - char c; - - while ((c = *p++) && c != '\n') - /* Do nothing. */ ; - *(p - 1) = 0; - indexify (*next_line, ostream); - } - } - - finish_index (ostream); -} - -/* Assume (and optionally verify) that each input file is sorted; - merge them and output the result. - Returns nonzero if any input file fails to be sorted. - - This is the high-level interface that can handle an unlimited - number of files. */ - -#define MAX_DIRECT_MERGE 10 - -int -merge_files (infiles, nfiles, outfile) - char **infiles; - int nfiles; - char *outfile; -{ - char **tempfiles; - int ntemps; - int i; - int value = 0; - int start_tempcount = tempcount; - - if (nfiles <= MAX_DIRECT_MERGE) - return merge_direct (infiles, nfiles, outfile); - - /* Merge groups of MAX_DIRECT_MERGE input files at a time, - making a temporary file to hold each group's result. */ - - ntemps = (nfiles + MAX_DIRECT_MERGE - 1) / MAX_DIRECT_MERGE; - tempfiles = (char **) xmalloc (ntemps * sizeof (char *)); - for (i = 0; i < ntemps; i++) - { - int nf = MAX_DIRECT_MERGE; - if (i + 1 == ntemps) - nf = nfiles - i * MAX_DIRECT_MERGE; - tempfiles[i] = maketempname (++tempcount); - value |= merge_direct (&infiles[i * MAX_DIRECT_MERGE], nf, tempfiles[i]); - } - - /* All temporary files that existed before are no longer needed - since their contents have been merged into our new tempfiles. - So delete them. */ - flush_tempfiles (start_tempcount); - - /* Now merge the temporary files we created. */ - - merge_files (tempfiles, ntemps, outfile); - - free (tempfiles); - - return value; -} - -/* Assume (and optionally verify) that each input file is sorted; - merge them and output the result. - Returns nonzero if any input file fails to be sorted. - - This version of merging will not work if the number of - input files gets too high. Higher level functions - use it only with a bounded number of input files. */ - -int -merge_direct (infiles, nfiles, outfile) - char **infiles; - int nfiles; - char *outfile; -{ - struct linebuffer *lb1, *lb2; - struct linebuffer **thisline, **prevline; - FILE **streams; - int i; - int nleft; - int lossage = 0; - int *file_lossage; - struct linebuffer *prev_out = 0; - FILE *ostream = stdout; - - if (outfile) - { - ostream = fopen (outfile, "w"); - } - if (!ostream) - pfatal_with_name (outfile); - - init_index (); - - if (nfiles == 0) - { - if (outfile) - fclose (ostream); - return 0; - } - - /* For each file, make two line buffers. - Also, for each file, there is an element of `thisline' - which points at any time to one of the file's two buffers, - and an element of `prevline' which points to the other buffer. - `thisline' is supposed to point to the next available line from the file, - while `prevline' holds the last file line used, - which is remembered so that we can verify that the file is properly sorted. */ - - /* lb1 and lb2 contain one buffer each per file. */ - lb1 = (struct linebuffer *) xmalloc (nfiles * sizeof (struct linebuffer)); - lb2 = (struct linebuffer *) xmalloc (nfiles * sizeof (struct linebuffer)); - - /* thisline[i] points to the linebuffer holding the next available line in file i, - or is zero if there are no lines left in that file. */ - thisline = (struct linebuffer **) - xmalloc (nfiles * sizeof (struct linebuffer *)); - /* prevline[i] points to the linebuffer holding the last used line - from file i. This is just for verifying that file i is properly - sorted. */ - prevline = (struct linebuffer **) - xmalloc (nfiles * sizeof (struct linebuffer *)); - /* streams[i] holds the input stream for file i. */ - streams = (FILE **) xmalloc (nfiles * sizeof (FILE *)); - /* file_lossage[i] is nonzero if we already know file i is not - properly sorted. */ - file_lossage = (int *) xmalloc (nfiles * sizeof (int)); - - /* Allocate and initialize all that storage. */ - - for (i = 0; i < nfiles; i++) - { - initbuffer (&lb1[i]); - initbuffer (&lb2[i]); - thisline[i] = &lb1[i]; - prevline[i] = &lb2[i]; - file_lossage[i] = 0; - streams[i] = fopen (infiles[i], "r"); - if (!streams[i]) - pfatal_with_name (infiles[i]); - - readline (thisline[i], streams[i]); - } - - /* Keep count of number of files not at eof. */ - nleft = nfiles; - - while (nleft) - { - struct linebuffer *best = 0; - struct linebuffer *exch; - int bestfile = -1; - int i; - - /* Look at the next avail line of each file; choose the least one. */ - - for (i = 0; i < nfiles; i++) - { - if (thisline[i] && - (!best || - 0 < compare_general (best->buffer, thisline[i]->buffer, - (long) bestfile, (long) i, num_keyfields))) - { - best = thisline[i]; - bestfile = i; - } - } - - /* Output that line, unless it matches the previous one and we - don't want duplicates. */ - - if (!(prev_out && - !compare_general (prev_out->buffer, - best->buffer, 0L, 1L, num_keyfields - 1))) - indexify (best->buffer, ostream); - prev_out = best; - - /* Now make the line the previous of its file, and fetch a new - line from that file. */ - - exch = prevline[bestfile]; - prevline[bestfile] = thisline[bestfile]; - thisline[bestfile] = exch; - - while (1) - { - /* If the file has no more, mark it empty. */ - - if (feof (streams[bestfile])) - { - thisline[bestfile] = 0; - /* Update the number of files still not empty. */ - nleft--; - break; - } - readline (thisline[bestfile], streams[bestfile]); - if (thisline[bestfile]->buffer[0] || !feof (streams[bestfile])) - break; - } - } - - finish_index (ostream); - - /* Free all storage and close all input streams. */ - - for (i = 0; i < nfiles; i++) - { - fclose (streams[i]); - free (lb1[i].buffer); - free (lb2[i].buffer); - } - free (file_lossage); - free (lb1); - free (lb2); - free (thisline); - free (prevline); - free (streams); - - if (outfile) - fclose (ostream); - - return lossage; -} - -/* Print error message and exit. */ - -void -fatal (s1, s2) - char *s1, *s2; -{ - error (s1, s2); - exit (TI_FATAL_ERROR); -} - -/* Print error message. S1 is printf control string, S2 is arg for it. */ - -void -error (s1, s2) - char *s1, *s2; -{ - printf ("%s: ", program_name); - printf (s1, s2); - printf ("\n"); -} - -#if !defined (HAVE_STRERROR) -static char * -strerror (n) - int n; -{ - static char ebuf[40]; - - if (n < sys_nerr) - return sys_errlist[n]; - else - { - sprintf (ebuf, "Unknown error %d", n); - return ebuf; - } -} -#endif - -void -perror_with_name (name) - char *name; -{ - char *s; - - s = concat ("", strerror (errno), " for %s"); - error (s, name); -} - -void -pfatal_with_name (name) - char *name; -{ - char *s; - - s = concat ("", strerror (errno), " for %s"); - fatal (s, name); -} - -/* Return a newly-allocated string whose contents concatenate those of - S1, S2, S3. */ - -char * -concat (s1, s2, s3) - char *s1, *s2, *s3; -{ - int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); - char *result = (char *) xmalloc (len1 + len2 + len3 + 1); - - strcpy (result, s1); - strcpy (result + len1, s2); - strcpy (result + len1 + len2, s3); - *(result + len1 + len2 + len3) = 0; - - return result; -} - -/* Just like malloc, but kills the program in case of fatal error. */ -void * -xmalloc (nbytes) - int nbytes; -{ - void *temp = (void *) malloc (nbytes); - - if (nbytes && temp == (void *)NULL) - memory_error ("xmalloc", nbytes); - - return (temp); -} - -/* Like realloc (), but barfs if there isn't enough memory. */ -void * -xrealloc (pointer, nbytes) - void *pointer; - int nbytes; -{ - void *temp; - - if (!pointer) - temp = (void *)xmalloc (nbytes); - else - temp = (void *)realloc (pointer, nbytes); - - if (nbytes && !temp) - memory_error ("xrealloc", nbytes); - - return (temp); -} - -memory_error (callers_name, bytes_wanted) - char *callers_name; - int bytes_wanted; -{ - char printable_string[80]; - - sprintf (printable_string, - "Virtual memory exhausted in %s ()! Needed %d bytes.", - callers_name, bytes_wanted); - - error (printable_string, ""); - abort (); -} diff --git a/gnu/lib/libreadline/readline/chardefs.h b/gnu/lib/libreadline/readline/chardefs.h deleted file mode 100644 index aa63da6..0000000 --- a/gnu/lib/libreadline/readline/chardefs.h +++ /dev/null @@ -1,89 +0,0 @@ -/* chardefs.h -- Character definitions for readline. */ -#ifndef _CHARDEFS_ -#define _CHARDEFS_ - -#include -#include - -#ifndef savestring -extern char *xmalloc (); -#define savestring(x) strcpy (xmalloc (1 + strlen (x)), (x)) -#endif - -#ifndef whitespace -#define whitespace(c) (((c) == ' ') || ((c) == '\t')) -#endif - -#ifdef CTRL -#undef CTRL -#endif - -/* Some character stuff. */ -#define control_character_threshold 0x020 /* Smaller than this is control. */ -#define meta_character_threshold 0x07f /* Larger than this is Meta. */ -#define control_character_bit 0x40 /* 0x000000, must be off. */ -#define meta_character_bit 0x080 /* x0000000, must be on. */ -#define largest_char 255 /* Largest character value. */ - -#define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char) -#define CTRL(c) ((c) & (~control_character_bit)) -#define META(c) ((c) | meta_character_bit) - -#define UNMETA(c) ((c) & (~meta_character_bit)) -#define UNCTRL(c) to_upper(((c)|control_character_bit)) - -#define lowercase_p(c) islower(c) -#define uppercase_p(c) isupper(c) - -#define pure_alphabetic(c) isalpha(c) - -#ifndef to_upper -#define to_upper(c) toupper(c) -#define to_lower(c) tolower(c) -#endif - -#define CTRL_P(c) ((c) < control_character_threshold) -#define META_P(c) ((c) > meta_character_threshold) - -#ifndef digit_value -#define digit_value(x) ((x) - '0') -#endif - -#ifndef NEWLINE -#define NEWLINE '\n' -#endif - -#ifndef RETURN -#define RETURN CTRL('M') -#endif - -#ifndef RUBOUT -#define RUBOUT 0x7f -#endif - -#ifndef TAB -#define TAB '\t' -#endif - -#ifdef ABORT_CHAR -#undef ABORT_CHAR -#endif -#define ABORT_CHAR CTRL('G') - -#ifdef PAGE -#undef PAGE -#endif -#define PAGE CTRL('L') - -#ifdef SPACE -#undef SPACE -#endif -#define SPACE 0x20 - -#ifdef ESC -#undef ESC -#endif - -#define ESC CTRL('[') - -#endif /* _CHARDEFS_ */ diff --git a/gnu/lib/libreadline/readline/history.h b/gnu/lib/libreadline/readline/history.h deleted file mode 100644 index 2ef5424..0000000 --- a/gnu/lib/libreadline/readline/history.h +++ /dev/null @@ -1,149 +0,0 @@ -/* History.h -- the names of functions that you can call in history. */ - -/* The structure used to store a history entry. */ -typedef struct _hist_entry { - char *line; - char *data; -} HIST_ENTRY; - -/* A structure used to pass the current state of the history stuff around. */ -typedef struct _hist_state { - HIST_ENTRY **entries; /* Pointer to the entries themselves. */ - int offset; /* The location pointer within this array. */ - int length; /* Number of elements within this array. */ - int size; /* Number of slots allocated to this array. */ -} HISTORY_STATE; - -/* For convenience only. You set this when interpreting history commands. - It is the logical offset of the first history element. */ -extern int history_base; - -/* Begin a session in which the history functions might be used. This - just initializes the interactive variables. */ -extern void using_history (); - -/* Return the current HISTORY_STATE of the history. */ -extern HISTORY_STATE *history_get_history_state (); - -/* Set the state of the current history array to STATE. */ -extern void history_set_history_state (); - -/* Place STRING at the end of the history list. - The associated data field (if any) is set to NULL. */ -extern void add_history (); - -/* Returns the number which says what history element we are now - looking at. */ -extern int where_history (); - -/* Set the position in the history list to POS. */ -int history_set_pos (); - -/* Search for STRING in the history list, starting at POS, an - absolute index into the list. DIR, if negative, says to search - backwards from POS, else forwards. - Returns the absolute index of the history element where STRING - was found, or -1 otherwise. */ -extern int history_search_pos (); - -/* A reasonably useless function, only here for completeness. WHICH - is the magic number that tells us which element to delete. The - elements are numbered from 0. */ -extern HIST_ENTRY *remove_history (); - -/* Stifle the history list, remembering only MAX number of entries. */ -extern void stifle_history (); - -/* Stop stifling the history. This returns the previous amount the - history was stifled by. The value is positive if the history was - stifled, negative if it wasn't. */ -extern int unstifle_history (); - -/* Add the contents of FILENAME to the history list, a line at a time. - If FILENAME is NULL, then read from ~/.history. Returns 0 if - successful, or errno if not. */ -extern int read_history (); - -/* Read a range of lines from FILENAME, adding them to the history list. - Start reading at the FROM'th line and end at the TO'th. If FROM - is zero, start at the beginning. If TO is less than FROM, read - until the end of the file. If FILENAME is NULL, then read from - ~/.history. Returns 0 if successful, or errno if not. */ -extern int read_history_range (); - -/* Append the current history to FILENAME. If FILENAME is NULL, - then append the history list to ~/.history. Values returned - are as in read_history (). */ -extern int write_history (); - -/* Append NELEMENT entries to FILENAME. The entries appended are from - the end of the list minus NELEMENTs up to the end of the list. */ -int append_history (); - -/* Make the history entry at WHICH have LINE and DATA. This returns - the old entry so you can dispose of the data. In the case of an - invalid WHICH, a NULL pointer is returned. */ -extern HIST_ENTRY *replace_history_entry (); - -/* Return the history entry at the current position, as determined by - history_offset. If there is no entry there, return a NULL pointer. */ -HIST_ENTRY *current_history (); - -/* Back up history_offset to the previous history entry, and return - a pointer to that entry. If there is no previous entry, return - a NULL pointer. */ -extern HIST_ENTRY *previous_history (); - -/* Move history_offset forward to the next item in the input_history, - and return the a pointer to that entry. If there is no next entry, - return a NULL pointer. */ -extern HIST_ENTRY *next_history (); - -/* Return a NULL terminated array of HIST_ENTRY which is the current input - history. Element 0 of this list is the beginning of time. If there - is no history, return NULL. */ -extern HIST_ENTRY **history_list (); - -/* Search the history for STRING, starting at history_offset. - If DIRECTION < 0, then the search is through previous entries, - else through subsequent. If the string is found, then - current_history () is the history entry, and the value of this function - is the offset in the line of that history entry that the string was - found in. Otherwise, nothing is changed, and a -1 is returned. */ -extern int history_search (); - -/* Expand the string STRING, placing the result into OUTPUT, a pointer - to a string. Returns: - - 0) If no expansions took place (or, if the only change in - the text was the de-slashifying of the history expansion - character) - 1) If expansions did take place - -1) If there was an error in expansion. - - If an error ocurred in expansion, then OUTPUT contains a descriptive - error message. */ -extern int history_expand (); - -/* Return an array of tokens, much as the shell might. The tokens are - parsed out of STRING. */ -extern char **history_tokenize (); - -/* Extract a string segment consisting of the FIRST through LAST - arguments present in STRING. Arguments are broken up as in - the shell. */ -extern char *history_arg_extract (); - -/* Return the number of bytes that the primary history entries are using. - This just adds up the lengths of the_history->lines. */ -extern int history_total_bytes (); - -/* Exported history variables. */ -extern int history_stifled; -extern int history_length; -extern int max_input_history; -extern char history_expansion_char; -extern char history_subst_char; -extern char history_comment_char; -extern char *history_no_expand_chars; -extern int history_base; diff --git a/gnu/lib/libreadline/readline/keymaps.h b/gnu/lib/libreadline/readline/keymaps.h deleted file mode 100644 index f7e9f6f..0000000 --- a/gnu/lib/libreadline/readline/keymaps.h +++ /dev/null @@ -1,91 +0,0 @@ -/* keymaps.h -- Manipulation of readline keymaps. */ - -/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library, a library for - reading lines of text with interactive input and history editing. - - The GNU Readline Library 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 1, or - (at your option) any later version. - - The GNU Readline Library 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. - - The GNU General Public License is often shipped with GNU software, and - is generally kept in a file called COPYING or LICENSE. If you do not - have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef _KEYMAPS_H_ -#define _KEYMAPS_H_ - -#include - -#if !defined (__FUNCTION_DEF) -# define __FUNCTION_DEF -typedef int Function (); -typedef void VFunction (); -typedef char *CPFunction (); -typedef char **CPPFunction (); -#endif - -/* A keymap contains one entry for each key in the ASCII set. - Each entry consists of a type and a pointer. - POINTER is the address of a function to run, or the - address of a keymap to indirect through. - TYPE says which kind of thing POINTER is. */ -typedef struct _keymap_entry { - char type; - Function *function; -} KEYMAP_ENTRY; - -/* This must be large enough to hold bindings for all of the characters - in a desired character set (e.g, 128 for ASCII, 256 for ISO Latin-x, - and so on). */ -#define KEYMAP_SIZE 256 - -/* I wanted to make the above structure contain a union of: - union { Function *function; struct _keymap_entry *keymap; } value; - but this made it impossible for me to create a static array. - Maybe I need C lessons. */ - -typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE]; -typedef KEYMAP_ENTRY *Keymap; - -/* The values that TYPE can have in a keymap entry. */ -#define ISFUNC 0 -#define ISKMAP 1 -#define ISMACR 2 - -extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap, emacs_meta_keymap, emacs_ctlx_keymap; -extern KEYMAP_ENTRY_ARRAY vi_insertion_keymap, vi_movement_keymap; - -/* Return a new, empty keymap. - Free it with free() when you are done. */ -extern Keymap rl_make_bare_keymap (); - -/* Return a new keymap which is a copy of MAP. */ -extern Keymap rl_copy_keymap (); - -/* Return a new keymap with the printing characters bound to rl_insert, - the lowercase Meta characters bound to run their equivalents, and - the Meta digits bound to produce numeric arguments. */ -extern Keymap rl_make_keymap (); - -extern void rl_discard_keymap (); - -/* Return the keymap corresponding to a given name. Names look like - `emacs' or `emacs-meta' or `vi-insert'. */ -extern Keymap rl_get_keymap_by_name (); - -/* Return the current keymap. */ -extern Keymap rl_get_keymap (); - -/* Set the current keymap to MAP. */ -extern void rl_set_keymap (); - -#endif /* _KEYMAPS_H_ */ diff --git a/gnu/lib/libreadline/readline/readline.h b/gnu/lib/libreadline/readline/readline.h deleted file mode 100644 index bbc8a0f..0000000 --- a/gnu/lib/libreadline/readline/readline.h +++ /dev/null @@ -1,267 +0,0 @@ -/* Readline.h -- the names of functions callable from within readline. */ - -/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. - - This file is part of the GNU Readline Library, a library for - reading lines of text with interactive input and history editing. - - The GNU Readline Library 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 1, or - (at your option) any later version. - - The GNU Readline Library 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. - - The GNU General Public License is often shipped with GNU software, and - is generally kept in a file called COPYING or LICENSE. If you do not - have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#if !defined (_READLINE_H_) -#define _READLINE_H_ - -#include -#include - -/* The functions for manipulating the text of the line within readline. -Most of these functions are bound to keys by default. */ -extern int - rl_tilde_expand (), - rl_beg_of_line (), rl_backward (), rl_delete (), rl_end_of_line (), - rl_forward (), ding (), rl_backward (), rl_newline (), rl_kill_line (), - rl_clear_screen (), rl_get_next_history (), rl_get_previous_history (), - rl_quoted_insert (), rl_reverse_search_history (), rl_transpose_chars (), - rl_unix_line_discard (), rl_quoted_insert (), rl_unix_word_rubout (), - rl_yank (), rl_rubout (), rl_backward_word (), rl_kill_word (), - rl_forward_word (), rl_tab_insert (), rl_yank_pop (), rl_yank_nth_arg (), - rl_backward_kill_word (), rl_backward_kill_line (), rl_transpose_words (), - rl_complete (), rl_possible_completions (), rl_insert_completions (), - rl_do_lowercase_version (), rl_kill_full_line (), - rl_digit_argument (), rl_universal_argument (), rl_abort (), - rl_undo_command (), rl_revert_line (), rl_beginning_of_history (), - rl_end_of_history (), rl_forward_search_history (), rl_insert (), - rl_upcase_word (), rl_downcase_word (), rl_capitalize_word (), - rl_restart_output (), rl_re_read_init_file (), rl_dump_functions (), - rl_delete_horizontal_space (), rl_history_search_forward (), - rl_history_search_backward (); - -/* `Public' utility functions. */ -extern int rl_insert_text (), rl_delete_text (), rl_kill_text (); -extern int rl_complete_internal (); -extern int rl_expand_prompt (); -extern int rl_initialize (); -extern int rl_set_signals (), rl_clear_signals (); -extern int rl_init_argument (), rl_digit_argument (); -extern int rl_read_key (), rl_getc (), rl_stuff_char (); -extern int maybe_save_line (), maybe_unsave_line (), maybe_replace_line (); -extern int rl_modifying (); - -extern int rl_begin_undo_group (), rl_end_undo_group (); -extern void rl_add_undo (), free_undo_list (); -extern int rl_do_undo (); - -extern int rl_insert_close (); - -/* These are *both* defined even when VI_MODE is not. */ -extern int rl_vi_editing_mode (), rl_emacs_editing_mode (); - -/* Non incremental history searching. */ -extern int - rl_noninc_forward_search (), rl_noninc_reverse_search (), - rl_noninc_forward_search_again (), rl_noninc_reverse_search_again (); - -/* Things for vi mode. */ -extern int rl_vi_check (), rl_vi_textmod_command (); -extern int - rl_vi_redo (), rl_vi_tilde_expand (), - rl_vi_movement_mode (), rl_vi_insertion_mode (), rl_vi_arg_digit (), - rl_vi_prev_word (), rl_vi_next_word (), rl_vi_char_search (), - rl_vi_eof_maybe (), rl_vi_append_mode (), rl_vi_put (), - rl_vi_append_eol (), rl_vi_insert_beg (), rl_vi_delete (), rl_vi_comment (), - rl_vi_first_print (), rl_vi_fword (), rl_vi_fWord (), rl_vi_bword (), - rl_vi_bWord (), rl_vi_eword (), rl_vi_eWord (), rl_vi_end_word (), - rl_vi_change_case (), rl_vi_match (), rl_vi_bracktype (), - rl_vi_change_char (), rl_vi_yank_arg (), rl_vi_search (), - rl_vi_search_again (), rl_vi_subst (), rl_vi_overstrike (), - rl_vi_overstrike_delete (), rl_vi_replace(), rl_vi_column (), - rl_vi_delete_to (), rl_vi_change_to (), rl_vi_yank_to (), - rl_vi_complete (), rl_vi_fetch_history (); - -/* Keyboard macro commands. */ -extern int rl_start_kbd_macro (), rl_end_kbd_macro (); -extern int rl_call_last_kbd_macro (); - -extern int rl_arrow_keys(), rl_refresh_line (); - -/* Maintaining the state of undo. We remember individual deletes and inserts - on a chain of things to do. */ - -/* The actions that undo knows how to undo. Notice that UNDO_DELETE means - to insert some text, and UNDO_INSERT means to delete some text. I.e., - the code tells undo what to undo, not how to undo it. */ -enum undo_code { UNDO_DELETE, UNDO_INSERT, UNDO_BEGIN, UNDO_END }; - -/* What an element of THE_UNDO_LIST looks like. */ -typedef struct undo_list { - struct undo_list *next; - int start, end; /* Where the change took place. */ - char *text; /* The text to insert, if undoing a delete. */ - enum undo_code what; /* Delete, Insert, Begin, End. */ -} UNDO_LIST; - -/* The current undo list for RL_LINE_BUFFER. */ -extern UNDO_LIST *rl_undo_list; - -/* The data structure for mapping textual names to code addresses. */ -typedef struct { - char *name; - Function *function; -} FUNMAP; - -extern FUNMAP **funmap; - -/* **************************************************************** */ -/* */ -/* Well Published Variables */ -/* */ -/* **************************************************************** */ - -/* The name of the calling program. You should initialize this to - whatever was in argv[0]. It is used when parsing conditionals. */ -extern char *rl_readline_name; - -/* The line buffer that is in use. */ -extern char *rl_line_buffer; - -/* The location of point, and end. */ -extern int rl_point, rl_end; - -/* The name of the terminal to use. */ -extern char *rl_terminal_name; - -/* The input and output streams. */ -extern FILE *rl_instream, *rl_outstream; - -/* The basic list of characters that signal a break between words for the - completer routine. The initial contents of this variable is what - breaks words in the shell, i.e. "n\"\\'`@$>". */ -extern char *rl_basic_word_break_characters; - -/* The list of characters that signal a break between words for - rl_complete_internal. The default list is the contents of - rl_basic_word_break_characters. */ -extern char *rl_completer_word_break_characters; - -/* List of characters which can be used to quote a substring of the line. - Completion occurs on the entire substring, and within the substring - rl_completer_word_break_characters are treated as any other character, - unless they also appear within this list. */ -extern char *rl_completer_quote_characters; - -/* List of characters that are word break characters, but should be left - in TEXT when it is passed to the completion function. The shell uses - this to help determine what kind of completing to do. */ -extern char *rl_special_prefixes; - -/* Pointer to the generator function for completion_matches (). - NULL means to use filename_entry_function (), the default filename - completer. */ -extern Function *rl_completion_entry_function; - -/* If rl_ignore_some_completions_function is non-NULL it is the address - of a function to call after all of the possible matches have been - generated, but before the actual completion is done to the input line. - The function is called with one argument; a NULL terminated array - of (char *). If your function removes any of the elements, they - must be free()'ed. */ -extern Function *rl_ignore_some_completions_function; - -/* Pointer to alternative function to create matches. - Function is called with TEXT, START, and END. - START and END are indices in RL_LINE_BUFFER saying what the boundaries - of TEXT are. - If this function exists and returns NULL then call the value of - rl_completion_entry_function to try to match, otherwise use the - array of strings returned. */ -extern CPPFunction *rl_attempted_completion_function; - -/* If non-zero, then this is the address of a function to call just - before readline_internal () prints the first prompt. */ -extern Function *rl_startup_hook; - -/* If non-zero, then this is the address of a function to call when - completing on a directory name. The function is called with - the address of a string (the current directory name) as an arg. */ -extern Function *rl_directory_completion_hook; - -/* Backwards compatibility with previous versions of readline. */ -#define rl_symbolic_link_hook rl_directory_completion_hook - -/* The address of a function to call periodically while Readline is - awaiting character input, or NULL, for no event handling. */ -extern Function *rl_event_hook; - -/* Non-zero means that modified history lines are preceded - with an asterisk. */ -extern int rl_show_star; - -/* Non-zero means to suppress normal filename completion after the - user-specified completion function has been called. */ -extern int rl_attempted_completion_over; - -/* **************************************************************** */ -/* */ -/* Well Published Functions */ -/* */ -/* **************************************************************** */ - -/* Read a line of input. Prompt with PROMPT. A NULL PROMPT means none. */ -extern char *readline (); - -/* These functions are from complete.c. */ -/* Return an array of strings which are the result of repeatadly calling - FUNC with TEXT. */ -extern char **completion_matches (); -extern char *username_completion_function (); -extern char *filename_completion_function (); - -/* These functions are from bind.c. */ -/* rl_add_defun (char *name, Function *function, int key) - Add NAME to the list of named functions. Make FUNCTION - be the function that gets called. - If KEY is not -1, then bind it. */ -extern int rl_add_defun (); -extern int rl_bind_key (), rl_bind_key_in_map (); -extern int rl_unbind_key (), rl_unbind_key_in_map (); -extern int rl_set_key (); -extern int rl_macro_bind (), rl_generic_bind (), rl_variable_bind (); -extern int rl_translate_keyseq (); -extern Function *rl_named_function (), *rl_function_of_keyseq (); -extern int rl_parse_and_bind (); -extern Keymap rl_get_keymap (), rl_get_keymap_by_name (); -extern void rl_set_keymap (); -extern char **rl_invoking_keyseqs (), **rl_invoking_keyseqs_in_map (); -extern void rl_function_dumper (); -extern int rl_read_init_file (); - -/* Functions in funmap.c */ -extern void rl_list_funmap_names (); -extern void rl_initialize_funmap (); - -/* Functions in display.c */ -extern void rl_redisplay (); -extern int rl_message (), rl_clear_message (); -extern int rl_reset_line_state (); -extern int rl_character_len (); -extern int rl_show_char (); -extern int crlf (), rl_on_new_line (); -extern int rl_forced_update_display (); - -/* Definitions available for use by readline clients. */ -#define RL_PROMPT_START_IGNORE '\001' -#define RL_PROMPT_END_IGNORE '\002' - -#endif /* _READLINE_H_ */ diff --git a/gnu/lib/libreadline/readline/tilde.h b/gnu/lib/libreadline/readline/tilde.h deleted file mode 100644 index 726d081..0000000 --- a/gnu/lib/libreadline/readline/tilde.h +++ /dev/null @@ -1,38 +0,0 @@ -/* tilde.h: Externally available variables and function in libtilde.a. */ - -#if !defined (__TILDE_H__) -# define __TILDE_H__ - -/* Function pointers can be declared as (Function *)foo. */ -#if !defined (__FUNCTION_DEF) -# define __FUNCTION_DEF -typedef int Function (); -typedef void VFunction (); -typedef char *CPFunction (); -typedef char **CPPFunction (); -#endif /* _FUNCTION_DEF */ - -/* If non-null, this contains the address of a function to call if the - standard meaning for expanding a tilde fails. The function is called - with the text (sans tilde, as in "foo"), and returns a malloc()'ed string - which is the expansion, or a NULL pointer if there is no expansion. */ -extern CPFunction *tilde_expansion_failure_hook; - -/* When non-null, this is a NULL terminated array of strings which - are duplicates for a tilde prefix. Bash uses this to expand - `=~' and `:~'. */ -extern char **tilde_additional_prefixes; - -/* When non-null, this is a NULL terminated array of strings which match - the end of a username, instead of just "/". Bash sets this to - `:' and `=~'. */ -extern char **tilde_additional_suffixes; - -/* Return a new string which is the result of tilde expanding STRING. */ -extern char *tilde_expand (); - -/* Do the work of tilde expansion on FILENAME. FILENAME starts with a - tilde. If there is no expansion, call tilde_expansion_failure_hook. */ -extern char *tilde_expand_word (); - -#endif /* __TILDE_H__ */ diff --git a/gnu/lib/libreadline/sysdep.h b/gnu/lib/libreadline/sysdep.h deleted file mode 100644 index 007a561..0000000 --- a/gnu/lib/libreadline/sysdep.h +++ /dev/null @@ -1,37 +0,0 @@ -/* System-dependent stuff, for ``normal'' systems */ -/* If you think you need to change this file, then you are wrong. In order to - avoid a huge ugly mass of nested #ifdefs, you should create a new file just - for your system, which contains exactly those #includes and definitions that - your system needs, AND NOTHING MORE! Then, add that file to the appropriate - place in configure.in, and viola, you are done. sysdep-sunos4.h is a good - example of how to do this. */ - -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else -#if defined (sparc) && defined (sun) -#include -#endif -#ifndef alloca /* May be a macro, with args. */ -extern char *alloca (); -#endif -#endif - -#include /* Needed by dirent.h */ -#include /* Needed for TIOC?WINSZ */ - -#if defined (USG) && defined (TIOCGWINSZ) -#include -#if defined (USGr4) || defined (USGr3) -#include -#endif /* USGr4 */ -#endif /* USG && TIOCGWINSZ */ - -#include -typedef struct dirent dirent; - -/* SVR4 systems should use rather than . */ - -#if defined (USGr4) -#define _POSIX_VERSION -#endif diff --git a/gnu/lib/libreadline/tcsh_hack.readme b/gnu/lib/libreadline/tcsh_hack.readme deleted file mode 100644 index 6fd5da1..0000000 --- a/gnu/lib/libreadline/tcsh_hack.readme +++ /dev/null @@ -1,27 +0,0 @@ -*** rltty.c.orig Thu May 12 19:02:50 1994 ---- rltty.c Thu May 12 19:03:06 1994 -*************** -*** 21,26 **** ---- 21,27 ---- - have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ - #include -+ #include - #include - #include - #include -*************** -*** 359,364 **** ---- 360,371 ---- - int tty; - TIOTYPE *tiop; - { -+ /* XXX this prevents to got editing mode from tcsh. Ache */ -+ struct winsize w; -+ -+ if (ioctl (tty, TIOCGWINSZ, &w) == 0) -+ (void) ioctl (tty, TIOCSWINSZ, &w); -+ - while (GETATTR (tty, tiop) < 0) - { - if (errno != EINTR) diff --git a/gnu/lib/libregex/doc/Makefile.in b/gnu/lib/libregex/doc/Makefile.in deleted file mode 100644 index 2f5d382..0000000 --- a/gnu/lib/libregex/doc/Makefile.in +++ /dev/null @@ -1,92 +0,0 @@ -# Makefile for regex documentation. -# -# Copyright (C) 1992 Free Software Foundation, Inc. -# -# 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 this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -# Installation directories. -prefix = /usr/local -infodir = $(prefix)/info - -srcdir = @srcdir@ -VPATH = @srcdir@:../@srcdir@ - -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ - -MAKEINFO = makeinfo --no-split -SHELL = /bin/sh -TEX = tex -TEXINDEX = texindex - -default all: regex.info regex.dvi -.PHONY: default all - -# We need to include some code from regex.h. -regex.texi: xregex.texi - rm -f $@ - gawk -f include.awk -vsource=../$(srcdir)/regex.h \ - <../$(srcdir)/doc/xregex.texi \ - | expand >$@ - chmod a-w $@ - -regex.dvi: regex.cps - $(TEX) regex.texi -regex.cps: regex.cp - $(TEXINDEX) regex.?? -regex.cp: regex.texi - $(TEX) ../$(srcdir)/doc/regex.texi - -regex.info: regex.texi - $(MAKEINFO) ../$(srcdir)/doc/regex.texi - -# I know of no way to make a good TAGS file from Texinfo source. -TAGS: - -check: -.PHONY: check - -install: regex.info - -mkdir $(prefix) $(infodir) - for i in *.info*; do $(INSTALL_DATA) $$i $(infodir)/$$i; done -.PHONY: install - -clean mostlyclean: - rm -f regex.?? *.dvi *.log *.toc - -distclean: clean - rm -f Makefile - for f in regex.??s; do if test -z "`cat $$f`"; then rm -f $$f; fi; done - -realclean: distclean - rm -f *.info* regex.??? regex.texi TAGS - -extraclean: distclean - rm -f patch* *~* *\#* *.orig *.rej *.bak core a.out -.PHONY: mostlyclean clean distclean realclean extraclean - -Makefile: Makefile.in ../config.status - (cd ..; sh config.status) - -# Prevent GNU make 3 from overflowing arg limit on system V. -.NOEXPORT: - -# Assumes $(distdir) is the place to put our files. -distfiles = Makefile.in *.texi texinfo.tex include.awk \ - regex.info* regex.aux regex.cps -dist: Makefile regex.info regex.cps - mkdir $(distdir) - ln $(distfiles) $(distdir) -.PHONY: dist diff --git a/gnu/lib/libregex/doc/regex.aux b/gnu/lib/libregex/doc/regex.aux deleted file mode 100644 index fd6a245..0000000 --- a/gnu/lib/libregex/doc/regex.aux +++ /dev/null @@ -1,136 +0,0 @@ -'xrdef {Overview-pg}{1} -'xrdef {Overview-snt}{Chapter'tie1} -'xrdef {Regular Expression Syntax-pg}{2} -'xrdef {Regular Expression Syntax-snt}{Chapter'tie2} -'xrdef {Syntax Bits-pg}{2} -'xrdef {Syntax Bits-snt}{Section'tie2.1} -'xrdef {Predefined Syntaxes-pg}{5} -'xrdef {Predefined Syntaxes-snt}{Section'tie2.2} -'xrdef {Collating Elements vs. Characters-pg}{6} -'xrdef {Collating Elements vs. Characters-snt}{Section'tie2.3} -'xrdef {The Backslash Character-pg}{7} -'xrdef {The Backslash Character-snt}{Section'tie2.4} -'xrdef {Common Operators-pg}{9} -'xrdef {Common Operators-snt}{Chapter'tie3} -'xrdef {Match-self Operator-pg}{9} -'xrdef {Match-self Operator-snt}{Section'tie3.1} -'xrdef {Match-any-character Operator-pg}{9} -'xrdef {Match-any-character Operator-snt}{Section'tie3.2} -'xrdef {Concatenation Operator-pg}{10} -'xrdef {Concatenation Operator-snt}{Section'tie3.3} -'xrdef {Repetition Operators-pg}{10} -'xrdef {Repetition Operators-snt}{Section'tie3.4} -'xrdef {Match-zero-or-more Operator-pg}{10} -'xrdef {Match-zero-or-more Operator-snt}{Section'tie3.4.1} -'xrdef {Match-one-or-more Operator-pg}{11} -'xrdef {Match-one-or-more Operator-snt}{Section'tie3.4.2} -'xrdef {Match-zero-or-one Operator-pg}{11} -'xrdef {Match-zero-or-one Operator-snt}{Section'tie3.4.3} -'xrdef {Interval Operators-pg}{12} -'xrdef {Interval Operators-snt}{Section'tie3.4.4} -'xrdef {Alternation Operator-pg}{13} -'xrdef {Alternation Operator-snt}{Section'tie3.5} -'xrdef {List Operators-pg}{13} -'xrdef {List Operators-snt}{Section'tie3.6} -'xrdef {Character Class Operators-pg}{14} -'xrdef {Character Class Operators-snt}{Section'tie3.6.1} -'xrdef {Range Operator-pg}{15} -'xrdef {Range Operator-snt}{Section'tie3.6.2} -'xrdef {Grouping Operators-pg}{16} -'xrdef {Grouping Operators-snt}{Section'tie3.7} -'xrdef {Back-reference Operator-pg}{17} -'xrdef {Back-reference Operator-snt}{Section'tie3.8} -'xrdef {Anchoring Operators-pg}{18} -'xrdef {Anchoring Operators-snt}{Section'tie3.9} -'xrdef {Match-beginning-of-line Operator-pg}{18} -'xrdef {Match-beginning-of-line Operator-snt}{Section'tie3.9.1} -'xrdef {Match-end-of-line Operator-pg}{18} -'xrdef {Match-end-of-line Operator-snt}{Section'tie3.9.2} -'xrdef {GNU Operators-pg}{20} -'xrdef {GNU Operators-snt}{Chapter'tie4} -'xrdef {Word Operators-pg}{20} -'xrdef {Word Operators-snt}{Section'tie4.1} -'xrdef {Non-Emacs Syntax Tables-pg}{20} -'xrdef {Non-Emacs Syntax Tables-snt}{Section'tie4.1.1} -'xrdef {Match-word-boundary Operator-pg}{20} -'xrdef {Match-word-boundary Operator-snt}{Section'tie4.1.2} -'xrdef {Match-within-word Operator-pg}{20} -'xrdef {Match-within-word Operator-snt}{Section'tie4.1.3} -'xrdef {Match-beginning-of-word Operator-pg}{21} -'xrdef {Match-beginning-of-word Operator-snt}{Section'tie4.1.4} -'xrdef {Match-end-of-word Operator-pg}{21} -'xrdef {Match-end-of-word Operator-snt}{Section'tie4.1.5} -'xrdef {Match-word-constituent Operator-pg}{21} -'xrdef {Match-word-constituent Operator-snt}{Section'tie4.1.6} -'xrdef {Match-non-word-constituent Operator-pg}{21} -'xrdef {Match-non-word-constituent Operator-snt}{Section'tie4.1.7} -'xrdef {Buffer Operators-pg}{21} -'xrdef {Buffer Operators-snt}{Section'tie4.2} -'xrdef {Match-beginning-of-buffer Operator-pg}{21} -'xrdef {Match-beginning-of-buffer Operator-snt}{Section'tie4.2.1} -'xrdef {Match-end-of-buffer Operator-pg}{21} -'xrdef {Match-end-of-buffer Operator-snt}{Section'tie4.2.2} -'xrdef {GNU Emacs Operators-pg}{22} -'xrdef {GNU Emacs Operators-snt}{Chapter'tie5} -'xrdef {Syntactic Class Operators-pg}{22} -'xrdef {Syntactic Class Operators-snt}{Section'tie5.1} -'xrdef {Emacs Syntax Tables-pg}{22} -'xrdef {Emacs Syntax Tables-snt}{Section'tie5.1.1} -'xrdef {Match-syntactic-class Operator-pg}{22} -'xrdef {Match-syntactic-class Operator-snt}{Section'tie5.1.2} -'xrdef {Match-not-syntactic-class Operator-pg}{22} -'xrdef {Match-not-syntactic-class Operator-snt}{Section'tie5.1.3} -'xrdef {What Gets Matched?-pg}{23} -'xrdef {What Gets Matched?-snt}{Chapter'tie6} -'xrdef {Programming with Regex-pg}{24} -'xrdef {Programming with Regex-snt}{Chapter'tie7} -'xrdef {GNU Regex Functions-pg}{24} -'xrdef {GNU Regex Functions-snt}{Section'tie7.1} -'xrdef {GNU Pattern Buffers-pg}{24} -'xrdef {GNU Pattern Buffers-snt}{Section'tie7.1.1} -'xrdef {GNU Regular Expression Compiling-pg}{26} -'xrdef {GNU Regular Expression Compiling-snt}{Section'tie7.1.2} -'xrdef {GNU Matching-pg}{27} -'xrdef {GNU Matching-snt}{Section'tie7.1.3} -'xrdef {GNU Searching-pg}{28} -'xrdef {GNU Searching-snt}{Section'tie7.1.4} -'xrdef {Matching/Searching with Split Data-pg}{29} -'xrdef {Matching/Searching with Split Data-snt}{Section'tie7.1.5} -'xrdef {Searching with Fastmaps-pg}{30} -'xrdef {Searching with Fastmaps-snt}{Section'tie7.1.6} -'xrdef {GNU Translate Tables-pg}{31} -'xrdef {GNU Translate Tables-snt}{Section'tie7.1.7} -'xrdef {Using Registers-pg}{32} -'xrdef {Using Registers-snt}{Section'tie7.1.8} -'xrdef {Freeing GNU Pattern Buffers-pg}{34} -'xrdef {Freeing GNU Pattern Buffers-snt}{Section'tie7.1.9} -'xrdef {POSIX Regex Functions-pg}{35} -'xrdef {POSIX Regex Functions-snt}{Section'tie7.2} -'xrdef {POSIX Pattern Buffers-pg}{35} -'xrdef {POSIX Pattern Buffers-snt}{Section'tie7.2.1} -'xrdef {POSIX Regular Expression Compiling-pg}{35} -'xrdef {POSIX Regular Expression Compiling-snt}{Section'tie7.2.2} -'xrdef {POSIX Matching-pg}{37} -'xrdef {POSIX Matching-snt}{Section'tie7.2.3} -'xrdef {Reporting Errors-pg}{38} -'xrdef {Reporting Errors-snt}{Section'tie7.2.4} -'xrdef {Using Byte Offsets-pg}{39} -'xrdef {Using Byte Offsets-snt}{Section'tie7.2.5} -'xrdef {Freeing POSIX Pattern Buffers-pg}{39} -'xrdef {Freeing POSIX Pattern Buffers-snt}{Section'tie7.2.6} -'xrdef {BSD Regex Functions-pg}{40} -'xrdef {BSD Regex Functions-snt}{Section'tie7.3} -'xrdef {BSD Regular Expression Compiling-pg}{40} -'xrdef {BSD Regular Expression Compiling-snt}{Section'tie7.3.1} -'xrdef {BSD Searching-pg}{40} -'xrdef {BSD Searching-snt}{Section'tie7.3.2} -'xrdef {Copying-pg}{42} -'xrdef {Copying-snt}{Appendix'tie'char65{}} -'xrdef {Copying-pg}{42} -'xrdef {Copying-snt}{} -'xrdef {Copying-pg}{43} -'xrdef {Copying-snt}{} -'xrdef {Copying-pg}{48} -'xrdef {Copying-snt}{} -'xrdef {Index-pg}{50} -'xrdef {Index-snt}{} diff --git a/gnu/lib/libregex/doc/regex.cps b/gnu/lib/libregex/doc/regex.cps deleted file mode 100644 index 8b2e57c..0000000 --- a/gnu/lib/libregex/doc/regex.cps +++ /dev/null @@ -1,152 +0,0 @@ -\initial {$} -\entry {\code {$}}{18} -\initial {(} -\entry {\code {(}}{16} -\initial {)} -\entry {\code {)}}{16} -\initial {*} -\entry {\samp {*}}{10} -\initial {-} -\entry {\samp {-}}{13} -\initial {.} -\entry {\samp {.}}{9} -\initial {:} -\entry {\samp {:]} in regex}{14} -\initial {?} -\entry {\samp {?}}{11} -\initial {[} -\entry {\samp {[}}{13} -\entry {\samp {[:} in regex}{14} -\entry {\samp {[{\tt\hat}}}{13} -\initial {]} -\entry {\samp {]}}{13} -\initial {{\tt\char'173}} -\entry {\samp {{\tt\char'173}}}{12} -\initial {{\tt\char'174}} -\entry {\code {{\tt\char'174}}}{13} -\initial {{\tt\char'175}} -\entry {\samp {{\tt\char'175}}}{12} -\initial {{\tt\char43}} -\entry {\samp {{\tt\char43}}}{11} -\initial {{\tt\hat}} -\entry {\samp {{\tt\hat}}}{13} -\entry {\code {{\tt\hat}}}{18} -\initial {{\tt\indexbackslash }} -\entry {{\tt\indexbackslash }}{7} -\entry {\samp {{\tt\indexbackslash }}}{13} -\entry {\samp {{\tt\indexbackslash }'}}{21} -\entry {\code {{\tt\indexbackslash }(}}{16} -\entry {\code {{\tt\indexbackslash })}}{16} -\entry {\samp {{\tt\indexbackslash }`}}{21} -\entry {\samp {{\tt\indexbackslash }{\tt\char'173}}}{12} -\entry {\code {{\tt\indexbackslash }{\tt\char'174}}}{13} -\entry {\samp {{\tt\indexbackslash }{\tt\char'175}}}{12} -\entry {\samp {{\tt\indexbackslash }{\tt\gtr}}}{21} -\entry {\samp {{\tt\indexbackslash }{\tt\less}}}{21} -\entry {\samp {{\tt\indexbackslash }b}}{20} -\entry {\samp {{\tt\indexbackslash }B}}{20} -\entry {\samp {{\tt\indexbackslash }s}}{22} -\entry {\samp {{\tt\indexbackslash }S}}{22} -\entry {\samp {{\tt\indexbackslash }w}}{21} -\entry {\samp {{\tt\indexbackslash }W}}{21} -\initial {A} -\entry {\code {allocated \r {initialization}}}{26} -\entry {alternation operator}{13} -\entry {alternation operator and \samp {{\tt\hat}}}{18} -\entry {anchoring}{18} -\entry {anchors}{18} -\entry {Awk}{5} -\initial {B} -\entry {back references}{17} -\entry {backtracking}{10, 13} -\entry {beginning-of-line operator}{18} -\entry {bracket expression}{13} -\entry {\code {buffer \r {field, set by \code {re{\_}compile{\_}pattern}}}}{27} -\entry {\code {buffer \r {initialization}}}{26} -\initial {C} -\entry {character classes}{14} -\initial {E} -\entry {Egrep}{5} -\entry {Emacs}{5} -\entry {end-of-line operator}{18} -\entry {\code {end\penalty 10000{\spaceskip = 0pt{} }\r {in\penalty 10000{\spaceskip = 0pt{} }\code {struct\penalty 10000{\spaceskip = 0pt{} }re_registers}}}}{32} -\initial {F} -\entry {\code {fastmap \r {initialization}}}{26} -\entry {\code {fastmap{\_}accurate \r {field, set by \code {re{\_}compile{\_}pattern}}}}{27} -\entry {fastmaps}{30} -\initial {G} -\entry {Grep}{5} -\entry {grouping}{16} -\initial {I} -\entry {ignoring case}{35} -\entry {interval expression}{12} -\initial {M} -\entry {matching list}{13} -\entry {matching newline}{13} -\entry {matching with GNU functions}{27} -\initial {N} -\entry {\code {newline{\_}anchor \r {field in pattern buffer}}}{18} -\entry {nonmatching list}{13} -\entry {\code {not{\_}bol \r {field in pattern buffer}}}{18} -\entry {\code {num_regs\penalty 10000{\spaceskip = 0pt{} }\r {in\penalty 10000{\spaceskip = 0pt{} }\code {struct\penalty 10000{\spaceskip = 0pt{} }re_registers}}}}{32} -\initial {O} -\entry {open-group operator and \samp {{\tt\hat}}}{18} -\entry {or operator}{13} -\initial {P} -\entry {parenthesizing}{16} -\entry {pattern buffer initialization}{26} -\entry {pattern buffer, definition of}{24} -\entry {POSIX Awk}{5} -\initial {R} -\entry {\code {range \r {argument to \code {re{\_}search}}}}{28} -\entry {\code {re_registers}}{32} -\entry {\code {RE{\_}BACKSLASH{\_}ESCAPE{\_}IN{\_}LIST}}{3} -\entry {\code {RE{\_}BK{\_}PLUS{\_}QM}}{3} -\entry {\code {RE{\_}CHAR{\_}CLASSES}}{3} -\entry {\code {RE{\_}CONTEXT{\_}INDEP{\_}ANCHORS}}{3} -\entry {\code {RE{\_}CONTEXT{\_}INDEP{\_}ANCHORS \r {(and \samp {{\tt\hat}})}}}{18} -\entry {\code {RE{\_}CONTEXT{\_}INDEP{\_}OPS}}{3} -\entry {\code {RE{\_}CONTEXT{\_}INVALID{\_}OPS}}{3} -\entry {\code {RE{\_}DOT{\_}NEWLINE}}{3} -\entry {\code {RE{\_}DOT{\_}NOT{\_}NULL}}{4} -\entry {\code {RE{\_}INTERVALS}}{4} -\entry {\code {RE{\_}LIMITED{\_}OPS}}{4} -\entry {\code {RE{\_}NEWLINE{\_}ALT}}{4} -\entry {\code {RE{\_}NO{\_}BK{\_}BRACES}}{4} -\entry {\code {RE{\_}NO{\_}BK{\_}PARENS}}{4} -\entry {\code {RE{\_}NO{\_}BK{\_}REFS}}{4} -\entry {\code {RE{\_}NO{\_}BK{\_}VBAR}}{4} -\entry {\code {RE{\_}NO{\_}EMPTY{\_}RANGES}}{4} -\entry {\code {re{\_}nsub \r {field, set by \code {re{\_}compile{\_}pattern}}}}{27} -\entry {\code {re{\_}pattern{\_}buffer \r {definition}}}{24} -\entry {\code {re{\_}syntax{\_}options \r {initialization}}}{26} -\entry {\code {RE{\_}UNMATCHED{\_}RIGHT{\_}PAREN{\_}ORD}}{4} -\entry {\code {REG{\_}EXTENDED}}{35} -\entry {\code {REG{\_}ICASE}}{35} -\entry {\code {REG{\_}NEWLINE}}{36} -\entry {\code {REG{\_}NOSUB}}{35} -\entry {\code {regex.c}}{1} -\entry {\code {regex.h}}{1} -\entry {regexp anchoring}{18} -\entry {\code {regmatch{\_}t}}{39} -\entry {\code {regs{\_}allocated}}{32} -\entry {\code {REGS{\_}FIXED}}{33} -\entry {\code {REGS{\_}REALLOCATE}}{32} -\entry {\code {REGS{\_}UNALLOCATED}}{32} -\entry {regular expressions, syntax of}{2} -\initial {S} -\entry {searching with GNU functions}{28} -\entry {\code {start \r {argument to \code {re{\_}search}}}}{28} -\entry {\code {start\penalty 10000{\spaceskip = 0pt{} }\r {in\penalty 10000{\spaceskip = 0pt{} }\code {struct\penalty 10000{\spaceskip = 0pt{} }re_registers}}}}{32} -\entry {\code {struct re{\_}pattern{\_}buffer \r {definition}}}{24} -\entry {subexpressions}{16} -\entry {syntax bits}{2} -\entry {\code {syntax \r {field, set by \code {re{\_}compile{\_}pattern}}}}{27} -\entry {syntax initialization}{26} -\entry {syntax of regular expressions}{2} -\initial {T} -\entry {\code {translate \r {initialization}}}{26} -\initial {U} -\entry {\code {used \r {field, set by \code {re{\_}compile{\_}pattern}}}}{27} -\initial {W} -\entry {word boundaries, matching}{20} diff --git a/gnu/lib/libregex/doc/regex.info b/gnu/lib/libregex/doc/regex.info deleted file mode 100644 index 90deede..0000000 --- a/gnu/lib/libregex/doc/regex.info +++ /dev/null @@ -1,2836 +0,0 @@ -This is Info file regex.info, produced by Makeinfo-1.52 from the input -file .././doc/regex.texi. - - This file documents the GNU regular expression library. - - Copyright (C) 1992, 1993 Free Software Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that the -section entitled "GNU General Public License" is included exactly as in -the original, and provided that the entire resulting derived work is -distributed under the terms of a permission notice identical to this -one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions, except that the section entitled "GNU General Public License" -may be included in a translation approved by the Free Software -Foundation instead of in the original English. - - -File: regex.info, Node: Top, Next: Overview, Prev: (dir), Up: (dir) - -Regular Expression Library -************************** - - This manual documents how to program with the GNU regular expression -library. This is edition 0.12a of the manual, 19 September 1992. - - The first part of this master menu lists the major nodes in this Info -document, including the index. The rest of the menu lists all the -lower level nodes in the document. - -* Menu: - -* Overview:: -* Regular Expression Syntax:: -* Common Operators:: -* GNU Operators:: -* GNU Emacs Operators:: -* What Gets Matched?:: -* Programming with Regex:: -* Copying:: Copying and sharing Regex. -* Index:: General index. - -- The Detailed Node Listing -- - -Regular Expression Syntax - -* Syntax Bits:: -* Predefined Syntaxes:: -* Collating Elements vs. Characters:: -* The Backslash Character:: - -Common Operators - -* Match-self Operator:: Ordinary characters. -* Match-any-character Operator:: . -* Concatenation Operator:: Juxtaposition. -* Repetition Operators:: * + ? {} -* Alternation Operator:: | -* List Operators:: [...] [^...] -* Grouping Operators:: (...) -* Back-reference Operator:: \digit -* Anchoring Operators:: ^ $ - -Repetition Operators - -* Match-zero-or-more Operator:: * -* Match-one-or-more Operator:: + -* Match-zero-or-one Operator:: ? -* Interval Operators:: {} - -List Operators (`[' ... `]' and `[^' ... `]') - -* Character Class Operators:: [:class:] -* Range Operator:: start-end - -Anchoring Operators - -* Match-beginning-of-line Operator:: ^ -* Match-end-of-line Operator:: $ - -GNU Operators - -* Word Operators:: -* Buffer Operators:: - -Word Operators - -* Non-Emacs Syntax Tables:: -* Match-word-boundary Operator:: \b -* Match-within-word Operator:: \B -* Match-beginning-of-word Operator:: \< -* Match-end-of-word Operator:: \> -* Match-word-constituent Operator:: \w -* Match-non-word-constituent Operator:: \W - -Buffer Operators - -* Match-beginning-of-buffer Operator:: \` -* Match-end-of-buffer Operator:: \' - -GNU Emacs Operators - -* Syntactic Class Operators:: - -Syntactic Class Operators - -* Emacs Syntax Tables:: -* Match-syntactic-class Operator:: \sCLASS -* Match-not-syntactic-class Operator:: \SCLASS - -Programming with Regex - -* GNU Regex Functions:: -* POSIX Regex Functions:: -* BSD Regex Functions:: - -GNU Regex Functions - -* GNU Pattern Buffers:: The re_pattern_buffer type. -* GNU Regular Expression Compiling:: re_compile_pattern () -* GNU Matching:: re_match () -* GNU Searching:: re_search () -* Matching/Searching with Split Data:: re_match_2 (), re_search_2 () -* Searching with Fastmaps:: re_compile_fastmap () -* GNU Translate Tables:: The `translate' field. -* Using Registers:: The re_registers type and related fns. -* Freeing GNU Pattern Buffers:: regfree () - -POSIX Regex Functions - -* POSIX Pattern Buffers:: The regex_t type. -* POSIX Regular Expression Compiling:: regcomp () -* POSIX Matching:: regexec () -* Reporting Errors:: regerror () -* Using Byte Offsets:: The regmatch_t type. -* Freeing POSIX Pattern Buffers:: regfree () - -BSD Regex Functions - -* BSD Regular Expression Compiling:: re_comp () -* BSD Searching:: re_exec () - - -File: regex.info, Node: Overview, Next: Regular Expression Syntax, Prev: Top, Up: Top - -Overview -******** - - A "regular expression" (or "regexp", or "pattern") is a text string -that describes some (mathematical) set of strings. A regexp R -"matches" a string S if S is in the set of strings described by R. - - Using the Regex library, you can: - - * see if a string matches a specified pattern as a whole, and - - * search within a string for a substring matching a specified - pattern. - - Some regular expressions match only one string, i.e., the set they -describe has only one member. For example, the regular expression -`foo' matches the string `foo' and no others. Other regular -expressions match more than one string, i.e., the set they describe has -more than one member. For example, the regular expression `f*' matches -the set of strings made up of any number (including zero) of `f's. As -you can see, some characters in regular expressions match themselves -(such as `f') and some don't (such as `*'); the ones that don't match -themselves instead let you specify patterns that describe many -different strings. - - To either match or search for a regular expression with the Regex -library functions, you must first compile it with a Regex pattern -compiling function. A "compiled pattern" is a regular expression -converted to the internal format used by the library functions. Once -you've compiled a pattern, you can use it for matching or searching any -number of times. - - The Regex library consists of two source files: `regex.h' and -`regex.c'. Regex provides three groups of functions with which you can -operate on regular expressions. One group--the GNU group--is more -powerful but not completely compatible with the other two, namely the -POSIX and Berkeley UNIX groups; its interface was designed specifically -for GNU. The other groups have the same interfaces as do the regular -expression functions in POSIX and Berkeley UNIX. - - We wrote this chapter with programmers in mind, not users of -programs--such as Emacs--that use Regex. We describe the Regex library -in its entirety, not how to write regular expressions that a particular -program understands. - - -File: regex.info, Node: Regular Expression Syntax, Next: Common Operators, Prev: Overview, Up: Top - -Regular Expression Syntax -************************* - - "Characters" are things you can type. "Operators" are things in a -regular expression that match one or more characters. You compose -regular expressions from operators, which in turn you specify using one -or more characters. - - Most characters represent what we call the match-self operator, i.e., -they match themselves; we call these characters "ordinary". Other -characters represent either all or parts of fancier operators; e.g., -`.' represents what we call the match-any-character operator (which, no -surprise, matches (almost) any character); we call these characters -"special". Two different things determine what characters represent -what operators: - - 1. the regular expression syntax your program has told the Regex - library to recognize, and - - 2. the context of the character in the regular expression. - - In the following sections, we describe these things in more detail. - -* Menu: - -* Syntax Bits:: -* Predefined Syntaxes:: -* Collating Elements vs. Characters:: -* The Backslash Character:: - - -File: regex.info, Node: Syntax Bits, Next: Predefined Syntaxes, Up: Regular Expression Syntax - -Syntax Bits -=========== - - In any particular syntax for regular expressions, some characters are -always special, others are sometimes special, and others are never -special. The particular syntax that Regex recognizes for a given -regular expression depends on the value in the `syntax' field of the -pattern buffer of that regular expression. - - You get a pattern buffer by compiling a regular expression. *Note -GNU Pattern Buffers::, and *Note POSIX Pattern Buffers::, for more -information on pattern buffers. *Note GNU Regular Expression -Compiling::, *Note POSIX Regular Expression Compiling::, and *Note BSD -Regular Expression Compiling::, for more information on compiling. - - Regex considers the value of the `syntax' field to be a collection of -bits; we refer to these bits as "syntax bits". In most cases, they -affect what characters represent what operators. We describe the -meanings of the operators to which we refer in *Note Common Operators::, -*Note GNU Operators::, and *Note GNU Emacs Operators::. - - For reference, here is the complete list of syntax bits, in -alphabetical order: - -`RE_BACKSLASH_ESCAPE_IN_LISTS' - If this bit is set, then `\' inside a list (*note List Operators::. - quotes (makes ordinary, if it's special) the following character; - if this bit isn't set, then `\' is an ordinary character inside - lists. (*Note The Backslash Character::, for what `\' does - outside of lists.) - -`RE_BK_PLUS_QM' - If this bit is set, then `\+' represents the match-one-or-more - operator and `\?' represents the match-zero-or-more operator; if - this bit isn't set, then `+' represents the match-one-or-more - operator and `?' represents the match-zero-or-one operator. This - bit is irrelevant if `RE_LIMITED_OPS' is set. - -`RE_CHAR_CLASSES' - If this bit is set, then you can use character classes in lists; - if this bit isn't set, then you can't. - -`RE_CONTEXT_INDEP_ANCHORS' - If this bit is set, then `^' and `$' are special anywhere outside - a list; if this bit isn't set, then these characters are special - only in certain contexts. *Note Match-beginning-of-line - Operator::, and *Note Match-end-of-line Operator::. - -`RE_CONTEXT_INDEP_OPS' - If this bit is set, then certain characters are special anywhere - outside a list; if this bit isn't set, then those characters are - special only in some contexts and are ordinary elsewhere. - Specifically, if this bit isn't set then `*', and (if the syntax - bit `RE_LIMITED_OPS' isn't set) `+' and `?' (or `\+' and `\?', - depending on the syntax bit `RE_BK_PLUS_QM') represent repetition - operators only if they're not first in a regular expression or - just after an open-group or alternation operator. The same holds - for `{' (or `\{', depending on the syntax bit `RE_NO_BK_BRACES') if - it is the beginning of a valid interval and the syntax bit - `RE_INTERVALS' is set. - -`RE_CONTEXT_INVALID_OPS' - If this bit is set, then repetition and alternation operators - can't be in certain positions within a regular expression. - Specifically, the regular expression is invalid if it has: - - * a repetition operator first in the regular expression or just - after a match-beginning-of-line, open-group, or alternation - operator; or - - * an alternation operator first or last in the regular - expression, just before a match-end-of-line operator, or just - after an alternation or open-group operator. - - If this bit isn't set, then you can put the characters - representing the repetition and alternation characters anywhere in - a regular expression. Whether or not they will in fact be - operators in certain positions depends on other syntax bits. - -`RE_DOT_NEWLINE' - If this bit is set, then the match-any-character operator matches - a newline; if this bit isn't set, then it doesn't. - -`RE_DOT_NOT_NULL' - If this bit is set, then the match-any-character operator doesn't - match a null character; if this bit isn't set, then it does. - -`RE_INTERVALS' - If this bit is set, then Regex recognizes interval operators; if - this bit isn't set, then it doesn't. - -`RE_LIMITED_OPS' - If this bit is set, then Regex doesn't recognize the - match-one-or-more, match-zero-or-one or alternation operators; if - this bit isn't set, then it does. - -`RE_NEWLINE_ALT' - If this bit is set, then newline represents the alternation - operator; if this bit isn't set, then newline is ordinary. - -`RE_NO_BK_BRACES' - If this bit is set, then `{' represents the open-interval operator - and `}' represents the close-interval operator; if this bit isn't - set, then `\{' represents the open-interval operator and `\}' - represents the close-interval operator. This bit is relevant only - if `RE_INTERVALS' is set. - -`RE_NO_BK_PARENS' - If this bit is set, then `(' represents the open-group operator and - `)' represents the close-group operator; if this bit isn't set, - then `\(' represents the open-group operator and `\)' represents - the close-group operator. - -`RE_NO_BK_REFS' - If this bit is set, then Regex doesn't recognize `\'DIGIT as the - back reference operator; if this bit isn't set, then it does. - -`RE_NO_BK_VBAR' - If this bit is set, then `|' represents the alternation operator; - if this bit isn't set, then `\|' represents the alternation - operator. This bit is irrelevant if `RE_LIMITED_OPS' is set. - -`RE_NO_EMPTY_RANGES' - If this bit is set, then a regular expression with a range whose - ending point collates lower than its starting point is invalid; if - this bit isn't set, then Regex considers such a range to be empty. - -`RE_UNMATCHED_RIGHT_PAREN_ORD' - If this bit is set and the regular expression has no matching - open-group operator, then Regex considers what would otherwise be - a close-group operator (based on how `RE_NO_BK_PARENS' is set) to - match `)'. - - -File: regex.info, Node: Predefined Syntaxes, Next: Collating Elements vs. Characters, Prev: Syntax Bits, Up: Regular Expression Syntax - -Predefined Syntaxes -=================== - - If you're programming with Regex, you can set a pattern buffer's -(*note GNU Pattern Buffers::., and *Note POSIX Pattern Buffers::) -`syntax' field either to an arbitrary combination of syntax bits (*note -Syntax Bits::.) or else to the configurations defined by Regex. These -configurations define the syntaxes used by certain programs--GNU Emacs, -POSIX Awk, traditional Awk, Grep, Egrep--in addition to syntaxes for -POSIX basic and extended regular expressions. - - The predefined syntaxes-taken directly from `regex.h'--are: - - #define RE_SYNTAX_EMACS 0 - - #define RE_SYNTAX_AWK \ - (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - - #define RE_SYNTAX_POSIX_AWK \ - (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS) - - #define RE_SYNTAX_GREP \ - (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ - | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ - | RE_NEWLINE_ALT) - - #define RE_SYNTAX_EGREP \ - (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ - | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ - | RE_NO_BK_VBAR) - - #define RE_SYNTAX_POSIX_EGREP \ - (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES) - - /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ - #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC - - #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC - - /* Syntax bits common to both basic and extended POSIX regex syntax. */ - #define _RE_SYNTAX_POSIX_COMMON \ - (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ - | RE_INTERVALS | RE_NO_EMPTY_RANGES) - - #define RE_SYNTAX_POSIX_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) - - /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes - RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this - isn't minimal, since other operators, such as \`, aren't disabled. */ - #define RE_SYNTAX_POSIX_MINIMAL_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) - - #define RE_SYNTAX_POSIX_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - - /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS - replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */ - #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) - - -File: regex.info, Node: Collating Elements vs. Characters, Next: The Backslash Character, Prev: Predefined Syntaxes, Up: Regular Expression Syntax - -Collating Elements vs. Characters -================================= - - POSIX generalizes the notion of a character to that of a collating -element. It defines a "collating element" to be "a sequence of one or -more bytes defined in the current collating sequence as a unit of -collation." - - This generalizes the notion of a character in two ways. First, a -single character can map into two or more collating elements. For -example, the German "es-zet" collates as the collating element `s' -followed by another collating element `s'. Second, two or more -characters can map into one collating element. For example, the -Spanish `ll' collates after `l' and before `m'. - - Since POSIX's "collating element" preserves the essential idea of a -"character," we use the latter, more familiar, term in this document. - - -File: regex.info, Node: The Backslash Character, Prev: Collating Elements vs. Characters, Up: Regular Expression Syntax - -The Backslash Character -======================= - - The `\' character has one of four different meanings, depending on -the context in which you use it and what syntax bits are set (*note -Syntax Bits::.). It can: 1) stand for itself, 2) quote the next -character, 3) introduce an operator, or 4) do nothing. - - 1. It stands for itself inside a list (*note List Operators::.) if - the syntax bit `RE_BACKSLASH_ESCAPE_IN_LISTS' is not set. For - example, `[\]' would match `\'. - - 2. It quotes (makes ordinary, if it's special) the next character - when you use it either: - - * outside a list,(1) or - - * inside a list and the syntax bit - `RE_BACKSLASH_ESCAPE_IN_LISTS' is set. - - 3. It introduces an operator when followed by certain ordinary - characters--sometimes only when certain syntax bits are set. See - the cases `RE_BK_PLUS_QM', `RE_NO_BK_BRACES', `RE_NO_BK_VAR', - `RE_NO_BK_PARENS', `RE_NO_BK_REF' in *Note Syntax Bits::. Also: - - * `\b' represents the match-word-boundary operator (*note - Match-word-boundary Operator::.). - - * `\B' represents the match-within-word operator (*note - Match-within-word Operator::.). - - * `\<' represents the match-beginning-of-word operator - (*note Match-beginning-of-word Operator::.). - - * `\>' represents the match-end-of-word operator (*note - Match-end-of-word Operator::.). - - * `\w' represents the match-word-constituent operator (*note - Match-word-constituent Operator::.). - - * `\W' represents the match-non-word-constituent operator - (*note Match-non-word-constituent Operator::.). - - * `\`' represents the match-beginning-of-buffer operator and - `\'' represents the match-end-of-buffer operator (*note - Buffer Operators::.). - - * If Regex was compiled with the C preprocessor symbol `emacs' - defined, then `\sCLASS' represents the match-syntactic-class - operator and `\SCLASS' represents the - match-not-syntactic-class operator (*note Syntactic Class - Operators::.). - - 4. In all other cases, Regex ignores `\'. For example, `\n' matches - `n'. - - - ---------- Footnotes ---------- - - (1) Sometimes you don't have to explicitly quote special characters -to make them ordinary. For instance, most characters lose any special -meaning inside a list (*note List Operators::.). In addition, if the -syntax bits `RE_CONTEXT_INVALID_OPS' and `RE_CONTEXT_INDEP_OPS' aren't -set, then (for historical reasons) the matcher considers special -characters ordinary if they are in contexts where the operations they -represent make no sense; for example, then the match-zero-or-more -operator (represented by `*') matches itself in the regular expression -`*foo' because there is no preceding expression on which it can -operate. It is poor practice, however, to depend on this behavior; if -you want a special character to be ordinary outside a list, it's better -to always quote it, regardless. - - -File: regex.info, Node: Common Operators, Next: GNU Operators, Prev: Regular Expression Syntax, Up: Top - -Common Operators -**************** - - You compose regular expressions from operators. In the following -sections, we describe the regular expression operators specified by -POSIX; GNU also uses these. Most operators have more than one -representation as characters. *Note Regular Expression Syntax::, for -what characters represent what operators under what circumstances. - - For most operators that can be represented in two ways, one -representation is a single character and the other is that character -preceded by `\'. For example, either `(' or `\(' represents the -open-group operator. Which one does depends on the setting of a syntax -bit, in this case `RE_NO_BK_PARENS'. Why is this so? Historical -reasons dictate some of the varying representations, while POSIX -dictates others. - - Finally, almost all characters lose any special meaning inside a list -(*note List Operators::.). - -* Menu: - -* Match-self Operator:: Ordinary characters. -* Match-any-character Operator:: . -* Concatenation Operator:: Juxtaposition. -* Repetition Operators:: * + ? {} -* Alternation Operator:: | -* List Operators:: [...] [^...] -* Grouping Operators:: (...) -* Back-reference Operator:: \digit -* Anchoring Operators:: ^ $ - - -File: regex.info, Node: Match-self Operator, Next: Match-any-character Operator, Up: Common Operators - -The Match-self Operator (ORDINARY CHARACTER) -============================================ - - This operator matches the character itself. All ordinary characters -(*note Regular Expression Syntax::.) represent this operator. For -example, `f' is always an ordinary character, so the regular expression -`f' matches only the string `f'. In particular, it does *not* match -the string `ff'. - - -File: regex.info, Node: Match-any-character Operator, Next: Concatenation Operator, Prev: Match-self Operator, Up: Common Operators - -The Match-any-character Operator (`.') -====================================== - - This operator matches any single printing or nonprinting character -except it won't match a: - -newline - if the syntax bit `RE_DOT_NEWLINE' isn't set. - -null - if the syntax bit `RE_DOT_NOT_NULL' is set. - - The `.' (period) character represents this operator. For example, -`a.b' matches any three-character string beginning with `a' and ending -with `b'. - - -File: regex.info, Node: Concatenation Operator, Next: Repetition Operators, Prev: Match-any-character Operator, Up: Common Operators - -The Concatenation Operator -========================== - - This operator concatenates two regular expressions A and B. No -character represents this operator; you simply put B after A. The -result is a regular expression that will match a string if A matches -its first part and B matches the rest. For example, `xy' (two -match-self operators) matches `xy'. - - -File: regex.info, Node: Repetition Operators, Next: Alternation Operator, Prev: Concatenation Operator, Up: Common Operators - -Repetition Operators -==================== - - Repetition operators repeat the preceding regular expression a -specified number of times. - -* Menu: - -* Match-zero-or-more Operator:: * -* Match-one-or-more Operator:: + -* Match-zero-or-one Operator:: ? -* Interval Operators:: {} - - -File: regex.info, Node: Match-zero-or-more Operator, Next: Match-one-or-more Operator, Up: Repetition Operators - -The Match-zero-or-more Operator (`*') -------------------------------------- - - This operator repeats the smallest possible preceding regular -expression as many times as necessary (including zero) to match the -pattern. `*' represents this operator. For example, `o*' matches any -string made up of zero or more `o's. Since this operator operates on -the smallest preceding regular expression, `fo*' has a repeating `o', -not a repeating `fo'. So, `fo*' matches `f', `fo', `foo', and so on. - - Since the match-zero-or-more operator is a suffix operator, it may be -useless as such when no regular expression precedes it. This is the -case when it: - - * is first in a regular expression, or - - * follows a match-beginning-of-line, open-group, or alternation - operator. - -Three different things can happen in these cases: - - 1. If the syntax bit `RE_CONTEXT_INVALID_OPS' is set, then the - regular expression is invalid. - - 2. If `RE_CONTEXT_INVALID_OPS' isn't set, but `RE_CONTEXT_INDEP_OPS' - is, then `*' represents the match-zero-or-more operator (which - then operates on the empty string). - - 3. Otherwise, `*' is ordinary. - - - The matcher processes a match-zero-or-more operator by first matching -as many repetitions of the smallest preceding regular expression as it -can. Then it continues to match the rest of the pattern. - - If it can't match the rest of the pattern, it backtracks (as many -times as necessary), each time discarding one of the matches until it -can either match the entire pattern or be certain that it cannot get a -match. For example, when matching `ca*ar' against `caaar', the matcher -first matches all three `a's of the string with the `a*' of the regular -expression. However, it cannot then match the final `ar' of the -regular expression against the final `r' of the string. So it -backtracks, discarding the match of the last `a' in the string. It can -then match the remaining `ar'. - - -File: regex.info, Node: Match-one-or-more Operator, Next: Match-zero-or-one Operator, Prev: Match-zero-or-more Operator, Up: Repetition Operators - -The Match-one-or-more Operator (`+' or `\+') --------------------------------------------- - - If the syntax bit `RE_LIMITED_OPS' is set, then Regex doesn't -recognize this operator. Otherwise, if the syntax bit `RE_BK_PLUS_QM' -isn't set, then `+' represents this operator; if it is, then `\+' does. - - This operator is similar to the match-zero-or-more operator except -that it repeats the preceding regular expression at least once; *note -Match-zero-or-more Operator::., for what it operates on, how some -syntax bits affect it, and how Regex backtracks to match it. - - For example, supposing that `+' represents the match-one-or-more -operator; then `ca+r' matches, e.g., `car' and `caaaar', but not `cr'. - - -File: regex.info, Node: Match-zero-or-one Operator, Next: Interval Operators, Prev: Match-one-or-more Operator, Up: Repetition Operators - -The Match-zero-or-one Operator (`?' or `\?') --------------------------------------------- - - If the syntax bit `RE_LIMITED_OPS' is set, then Regex doesn't -recognize this operator. Otherwise, if the syntax bit `RE_BK_PLUS_QM' -isn't set, then `?' represents this operator; if it is, then `\?' does. - - This operator is similar to the match-zero-or-more operator except -that it repeats the preceding regular expression once or not at all; -*note Match-zero-or-more Operator::., to see what it operates on, how -some syntax bits affect it, and how Regex backtracks to match it. - - For example, supposing that `?' represents the match-zero-or-one -operator; then `ca?r' matches both `car' and `cr', but nothing else. - - -File: regex.info, Node: Interval Operators, Prev: Match-zero-or-one Operator, Up: Repetition Operators - -Interval Operators (`{' ... `}' or `\{' ... `\}') -------------------------------------------------- - - If the syntax bit `RE_INTERVALS' is set, then Regex recognizes -"interval expressions". They repeat the smallest possible preceding -regular expression a specified number of times. - - If the syntax bit `RE_NO_BK_BRACES' is set, `{' represents the -"open-interval operator" and `}' represents the "close-interval -operator" ; otherwise, `\{' and `\}' do. - - Specifically, supposing that `{' and `}' represent the open-interval -and close-interval operators; then: - -`{COUNT}' - matches exactly COUNT occurrences of the preceding regular - expression. - -`{MIN,}' - matches MIN or more occurrences of the preceding regular - expression. - -`{MIN, MAX}' - matches at least MIN but no more than MAX occurrences of the - preceding regular expression. - - The interval expression (but not necessarily the regular expression -that contains it) is invalid if: - - * MIN is greater than MAX, or - - * any of COUNT, MIN, or MAX are outside the range zero to - `RE_DUP_MAX' (which symbol `regex.h' defines). - - If the interval expression is invalid and the syntax bit -`RE_NO_BK_BRACES' is set, then Regex considers all the characters in -the would-be interval to be ordinary. If that bit isn't set, then the -regular expression is invalid. - - If the interval expression is valid but there is no preceding regular -expression on which to operate, then if the syntax bit -`RE_CONTEXT_INVALID_OPS' is set, the regular expression is invalid. If -that bit isn't set, then Regex considers all the characters--other than -backslashes, which it ignores--in the would-be interval to be ordinary. - - -File: regex.info, Node: Alternation Operator, Next: List Operators, Prev: Repetition Operators, Up: Common Operators - -The Alternation Operator (`|' or `\|') -====================================== - - If the syntax bit `RE_LIMITED_OPS' is set, then Regex doesn't -recognize this operator. Otherwise, if the syntax bit `RE_NO_BK_VBAR' -is set, then `|' represents this operator; otherwise, `\|' does. - - Alternatives match one of a choice of regular expressions: if you put -the character(s) representing the alternation operator between any two -regular expressions A and B, the result matches the union of the -strings that A and B match. For example, supposing that `|' is the -alternation operator, then `foo|bar|quux' would match any of `foo', -`bar' or `quux'. - - The alternation operator operates on the *largest* possible -surrounding regular expressions. (Put another way, it has the lowest -precedence of any regular expression operator.) Thus, the only way you -can delimit its arguments is to use grouping. For example, if `(' and -`)' are the open and close-group operators, then `fo(o|b)ar' would -match either `fooar' or `fobar'. (`foo|bar' would match `foo' or -`bar'.) - - The matcher usually tries all combinations of alternatives so as to -match the longest possible string. For example, when matching -`(fooq|foo)*(qbarquux|bar)' against `fooqbarquux', it cannot take, say, -the first ("depth-first") combination it could match, since then it -would be content to match just `fooqbar'. - - -File: regex.info, Node: List Operators, Next: Grouping Operators, Prev: Alternation Operator, Up: Common Operators - -List Operators (`[' ... `]' and `[^' ... `]') -============================================= - - "Lists", also called "bracket expressions", are a set of one or more -items. An "item" is a character, a character class expression, or a -range expression. The syntax bits affect which kinds of items you can -put in a list. We explain the last two items in subsections below. -Empty lists are invalid. - - A "matching list" matches a single character represented by one of -the list items. You form a matching list by enclosing one or more items -within an "open-matching-list operator" (represented by `[') and a -"close-list operator" (represented by `]'). - - For example, `[ab]' matches either `a' or `b'. `[ad]*' matches the -empty string and any string composed of just `a's and `d's in any -order. Regex considers invalid a regular expression with a `[' but no -matching `]'. - - "Nonmatching lists" are similar to matching lists except that they -match a single character *not* represented by one of the list items. -You use an "open-nonmatching-list operator" (represented by `[^'(1)) -instead of an open-matching-list operator to start a nonmatching list. - - For example, `[^ab]' matches any character except `a' or `b'. - - If the `posix_newline' field in the pattern buffer (*note GNU Pattern -Buffers::. is set, then nonmatching lists do not match a newline. - - Most characters lose any special meaning inside a list. The special -characters inside a list follow. - -`]' - ends the list if it's not the first list item. So, if you want to - make the `]' character a list item, you must put it first. - -`\' - quotes the next character if the syntax bit - `RE_BACKSLASH_ESCAPE_IN_LISTS' is set. - -`[:' - represents the open-character-class operator (*note Character - Class Operators::.) if the syntax bit `RE_CHAR_CLASSES' is set and - what follows is a valid character class expression. - -`:]' - represents the close-character-class operator if the syntax bit - `RE_CHAR_CLASSES' is set and what precedes it is an - open-character-class operator followed by a valid character class - name. - -`-' - represents the range operator (*note Range Operator::.) if it's - not first or last in a list or the ending point of a range. - -All other characters are ordinary. For example, `[.*]' matches `.' and -`*'. - -* Menu: - -* Character Class Operators:: [:class:] -* Range Operator:: start-end - - ---------- Footnotes ---------- - - (1) Regex therefore doesn't consider the `^' to be the first -character in the list. If you put a `^' character first in (what you -think is) a matching list, you'll turn it into a nonmatching list. - - -File: regex.info, Node: Character Class Operators, Next: Range Operator, Up: List Operators - -Character Class Operators (`[:' ... `:]') ------------------------------------------ - - If the syntax bit `RE_CHARACTER_CLASSES' is set, then Regex -recognizes character class expressions inside lists. A "character -class expression" matches one character from a given class. You form a -character class expression by putting a character class name between an -"open-character-class operator" (represented by `[:') and a -"close-character-class operator" (represented by `:]'). The character -class names and their meanings are: - -`alnum' - letters and digits - -`alpha' - letters - -`blank' - system-dependent; for GNU, a space or tab - -`cntrl' - control characters (in the ASCII encoding, code 0177 and codes - less than 040) - -`digit' - digits - -`graph' - same as `print' except omits space - -`lower' - lowercase letters - -`print' - printable characters (in the ASCII encoding, space tilde--codes - 040 through 0176) - -`punct' - neither control nor alphanumeric characters - -`space' - space, carriage return, newline, vertical tab, and form feed - -`upper' - uppercase letters - -`xdigit' - hexadecimal digits: `0'-`9', `a'-`f', `A'-`F' - -These correspond to the definitions in the C library's `' -facility. For example, `[:alpha:]' corresponds to the standard -facility `isalpha'. Regex recognizes character class expressions only -inside of lists; so `[[:alpha:]]' matches any letter, but `[:alpha:]' -outside of a bracket expression and not followed by a repetition -operator matches just itself. - - -File: regex.info, Node: Range Operator, Prev: Character Class Operators, Up: List Operators - -The Range Operator (`-') ------------------------- - - Regex recognizes "range expressions" inside a list. They represent -those characters that fall between two elements in the current -collating sequence. You form a range expression by putting a "range -operator" between two characters.(1) `-' represents the range operator. -For example, `a-f' within a list represents all the characters from `a' -through `f' inclusively. - - If the syntax bit `RE_NO_EMPTY_RANGES' is set, then if the range's -ending point collates less than its starting point, the range (and the -regular expression containing it) is invalid. For example, the regular -expression `[z-a]' would be invalid. If this bit isn't set, then Regex -considers such a range to be empty. - - Since `-' represents the range operator, if you want to make a `-' -character itself a list item, you must do one of the following: - - * Put the `-' either first or last in the list. - - * Include a range whose starting point collates strictly lower than - `-' and whose ending point collates equal or higher. Unless a - range is the first item in a list, a `-' can't be its starting - point, but *can* be its ending point. That is because Regex - considers `-' to be the range operator unless it is preceded by - another `-'. For example, in the ASCII encoding, `)', `*', `+', - `,', `-', `.', and `/' are contiguous characters in the collating - sequence. You might think that `[)-+--/]' has two ranges: `)-+' - and `--/'. Rather, it has the ranges `)-+' and `+--', plus the - character `/', so it matches, e.g., `,', not `.'. - - * Put a range whose starting point is `-' first in the list. - - For example, `[-a-z]' matches a lowercase letter or a hyphen (in -English, in ASCII). - - ---------- Footnotes ---------- - - (1) You can't use a character class for the starting or ending point -of a range, since a character class is not a single character. - - -File: regex.info, Node: Grouping Operators, Next: Back-reference Operator, Prev: List Operators, Up: Common Operators - -Grouping Operators (`(' ... `)' or `\(' ... `\)') -================================================= - - A "group", also known as a "subexpression", consists of an -"open-group operator", any number of other operators, and a -"close-group operator". Regex treats this sequence as a unit, just as -mathematics and programming languages treat a parenthesized expression -as a unit. - - Therefore, using "groups", you can: - - * delimit the argument(s) to an alternation operator (*note - Alternation Operator::.) or a repetition operator (*note - Repetition Operators::.). - - * keep track of the indices of the substring that matched a given - group. *Note Using Registers::, for a precise explanation. This - lets you: - - * use the back-reference operator (*note Back-reference - Operator::.). - - * use registers (*note Using Registers::.). - - If the syntax bit `RE_NO_BK_PARENS' is set, then `(' represents the -open-group operator and `)' represents the close-group operator; -otherwise, `\(' and `\)' do. - - If the syntax bit `RE_UNMATCHED_RIGHT_PAREN_ORD' is set and a -close-group operator has no matching open-group operator, then Regex -considers it to match `)'. - - -File: regex.info, Node: Back-reference Operator, Next: Anchoring Operators, Prev: Grouping Operators, Up: Common Operators - -The Back-reference Operator ("\"DIGIT) -====================================== - - If the syntax bit `RE_NO_BK_REF' isn't set, then Regex recognizes -back references. A back reference matches a specified preceding group. -The back reference operator is represented by `\DIGIT' anywhere after -the end of a regular expression's DIGIT-th group (*note Grouping -Operators::.). - - DIGIT must be between `1' and `9'. The matcher assigns numbers 1 -through 9 to the first nine groups it encounters. By using one of `\1' -through `\9' after the corresponding group's close-group operator, you -can match a substring identical to the one that the group does. - - Back references match according to the following (in all examples -below, `(' represents the open-group, `)' the close-group, `{' the -open-interval and `}' the close-interval operator): - - * If the group matches a substring, the back reference matches an - identical substring. For example, `(a)\1' matches `aa' and - `(bana)na\1bo\1' matches `bananabanabobana'. Likewise, `(.*)\1' - matches any (newline-free if the syntax bit `RE_DOT_NEWLINE' isn't - set) string that is composed of two identical halves; the `(.*)' - matches the first half and the `\1' matches the second half. - - * If the group matches more than once (as it might if followed by, - e.g., a repetition operator), then the back reference matches the - substring the group *last* matched. For example, `((a*)b)*\1\2' - matches `aabababa'; first group 1 (the outer one) matches `aab' - and group 2 (the inner one) matches `aa'. Then group 1 matches - `ab' and group 2 matches `a'. So, `\1' matches `ab' and `\2' - matches `a'. - - * If the group doesn't participate in a match, i.e., it is part of an - alternative not taken or a repetition operator allows zero - repetitions of it, then the back reference makes the whole match - fail. For example, `(one()|two())-and-(three\2|four\3)' matches - `one-and-three' and `two-and-four', but not `one-and-four' or - `two-and-three'. For example, if the pattern matches `one-and-', - then its group 2 matches the empty string and its group 3 doesn't - participate in the match. So, if it then matches `four', then - when it tries to back reference group 3--which it will attempt to - do because `\3' follows the `four'--the match will fail because - group 3 didn't participate in the match. - - You can use a back reference as an argument to a repetition operator. -For example, `(a(b))\2*' matches `a' followed by two or more `b's. -Similarly, `(a(b))\2{3}' matches `abbbb'. - - If there is no preceding DIGIT-th subexpression, the regular -expression is invalid. - - -File: regex.info, Node: Anchoring Operators, Prev: Back-reference Operator, Up: Common Operators - -Anchoring Operators -=================== - - These operators can constrain a pattern to match only at the -beginning or end of the entire string or at the beginning or end of a -line. - -* Menu: - -* Match-beginning-of-line Operator:: ^ -* Match-end-of-line Operator:: $ - - -File: regex.info, Node: Match-beginning-of-line Operator, Next: Match-end-of-line Operator, Up: Anchoring Operators - -The Match-beginning-of-line Operator (`^') ------------------------------------------- - - This operator can match the empty string either at the beginning of -the string or after a newline character. Thus, it is said to "anchor" -the pattern to the beginning of a line. - - In the cases following, `^' represents this operator. (Otherwise, -`^' is ordinary.) - - * It (the `^') is first in the pattern, as in `^foo'. - - * The syntax bit `RE_CONTEXT_INDEP_ANCHORS' is set, and it is outside - a bracket expression. - - * It follows an open-group or alternation operator, as in `a\(^b\)' - and `a\|^b'. *Note Grouping Operators::, and *Note Alternation - Operator::. - - These rules imply that some valid patterns containing `^' cannot be -matched; for example, `foo^bar' if `RE_CONTEXT_INDEP_ANCHORS' is set. - - If the `not_bol' field is set in the pattern buffer (*note GNU -Pattern Buffers::.), then `^' fails to match at the beginning of the -string. *Note POSIX Matching::, for when you might find this useful. - - If the `newline_anchor' field is set in the pattern buffer, then `^' -fails to match after a newline. This is useful when you do not regard -the string to be matched as broken into lines. - - -File: regex.info, Node: Match-end-of-line Operator, Prev: Match-beginning-of-line Operator, Up: Anchoring Operators - -The Match-end-of-line Operator (`$') ------------------------------------- - - This operator can match the empty string either at the end of the -string or before a newline character in the string. Thus, it is said -to "anchor" the pattern to the end of a line. - - It is always represented by `$'. For example, `foo$' usually -matches, e.g., `foo' and, e.g., the first three characters of -`foo\nbar'. - - Its interaction with the syntax bits and pattern buffer fields is -exactly the dual of `^''s; see the previous section. (That is, -"beginning" becomes "end", "next" becomes "previous", and "after" -becomes "before".) - - -File: regex.info, Node: GNU Operators, Next: GNU Emacs Operators, Prev: Common Operators, Up: Top - -GNU Operators -************* - - Following are operators that GNU defines (and POSIX doesn't). - -* Menu: - -* Word Operators:: -* Buffer Operators:: - - -File: regex.info, Node: Word Operators, Next: Buffer Operators, Up: GNU Operators - -Word Operators -============== - - The operators in this section require Regex to recognize parts of -words. Regex uses a syntax table to determine whether or not a -character is part of a word, i.e., whether or not it is -"word-constituent". - -* Menu: - -* Non-Emacs Syntax Tables:: -* Match-word-boundary Operator:: \b -* Match-within-word Operator:: \B -* Match-beginning-of-word Operator:: \< -* Match-end-of-word Operator:: \> -* Match-word-constituent Operator:: \w -* Match-non-word-constituent Operator:: \W - - -File: regex.info, Node: Non-Emacs Syntax Tables, Next: Match-word-boundary Operator, Up: Word Operators - -Non-Emacs Syntax Tables ------------------------ - - A "syntax table" is an array indexed by the characters in your -character set. In the ASCII encoding, therefore, a syntax table has -256 elements. Regex always uses a `char *' variable `re_syntax_table' -as its syntax table. In some cases, it initializes this variable and -in others it expects you to initialize it. - - * If Regex is compiled with the preprocessor symbols `emacs' and - `SYNTAX_TABLE' both undefined, then Regex allocates - `re_syntax_table' and initializes an element I either to `Sword' - (which it defines) if I is a letter, number, or `_', or to zero if - it's not. - - * If Regex is compiled with `emacs' undefined but `SYNTAX_TABLE' - defined, then Regex expects you to define a `char *' variable - `re_syntax_table' to be a valid syntax table. - - * *Note Emacs Syntax Tables::, for what happens when Regex is - compiled with the preprocessor symbol `emacs' defined. - - -File: regex.info, Node: Match-word-boundary Operator, Next: Match-within-word Operator, Prev: Non-Emacs Syntax Tables, Up: Word Operators - -The Match-word-boundary Operator (`\b') ---------------------------------------- - - This operator (represented by `\b') matches the empty string at -either the beginning or the end of a word. For example, `\brat\b' -matches the separate word `rat'. - - -File: regex.info, Node: Match-within-word Operator, Next: Match-beginning-of-word Operator, Prev: Match-word-boundary Operator, Up: Word Operators - -The Match-within-word Operator (`\B') -------------------------------------- - - This operator (represented by `\B') matches the empty string within a -word. For example, `c\Brat\Be' matches `crate', but `dirty \Brat' -doesn't match `dirty rat'. - - -File: regex.info, Node: Match-beginning-of-word Operator, Next: Match-end-of-word Operator, Prev: Match-within-word Operator, Up: Word Operators - -The Match-beginning-of-word Operator (`\<') -------------------------------------------- - - This operator (represented by `\<') matches the empty string at the -beginning of a word. - - -File: regex.info, Node: Match-end-of-word Operator, Next: Match-word-constituent Operator, Prev: Match-beginning-of-word Operator, Up: Word Operators - -The Match-end-of-word Operator (`\>') -------------------------------------- - - This operator (represented by `\>') matches the empty string at the -end of a word. - - -File: regex.info, Node: Match-word-constituent Operator, Next: Match-non-word-constituent Operator, Prev: Match-end-of-word Operator, Up: Word Operators - -The Match-word-constituent Operator (`\w') ------------------------------------------- - - This operator (represented by `\w') matches any word-constituent -character. - - -File: regex.info, Node: Match-non-word-constituent Operator, Prev: Match-word-constituent Operator, Up: Word Operators - -The Match-non-word-constituent Operator (`\W') ----------------------------------------------- - - This operator (represented by `\W') matches any character that is not -word-constituent. - - -File: regex.info, Node: Buffer Operators, Prev: Word Operators, Up: GNU Operators - -Buffer Operators -================ - - Following are operators which work on buffers. In Emacs, a "buffer" -is, naturally, an Emacs buffer. For other programs, Regex considers the -entire string to be matched as the buffer. - -* Menu: - -* Match-beginning-of-buffer Operator:: \` -* Match-end-of-buffer Operator:: \' - - -File: regex.info, Node: Match-beginning-of-buffer Operator, Next: Match-end-of-buffer Operator, Up: Buffer Operators - -The Match-beginning-of-buffer Operator (`\`') ---------------------------------------------- - - This operator (represented by `\`') matches the empty string at the -beginning of the buffer. - - -File: regex.info, Node: Match-end-of-buffer Operator, Prev: Match-beginning-of-buffer Operator, Up: Buffer Operators - -The Match-end-of-buffer Operator (`\'') ---------------------------------------- - - This operator (represented by `\'') matches the empty string at the -end of the buffer. - - -File: regex.info, Node: GNU Emacs Operators, Next: What Gets Matched?, Prev: GNU Operators, Up: Top - -GNU Emacs Operators -******************* - - Following are operators that GNU defines (and POSIX doesn't) that you -can use only when Regex is compiled with the preprocessor symbol -`emacs' defined. - -* Menu: - -* Syntactic Class Operators:: - - -File: regex.info, Node: Syntactic Class Operators, Up: GNU Emacs Operators - -Syntactic Class Operators -========================= - - The operators in this section require Regex to recognize the syntactic -classes of characters. Regex uses a syntax table to determine this. - -* Menu: - -* Emacs Syntax Tables:: -* Match-syntactic-class Operator:: \sCLASS -* Match-not-syntactic-class Operator:: \SCLASS - - -File: regex.info, Node: Emacs Syntax Tables, Next: Match-syntactic-class Operator, Up: Syntactic Class Operators - -Emacs Syntax Tables -------------------- - - A "syntax table" is an array indexed by the characters in your -character set. In the ASCII encoding, therefore, a syntax table has -256 elements. - - If Regex is compiled with the preprocessor symbol `emacs' defined, -then Regex expects you to define and initialize the variable -`re_syntax_table' to be an Emacs syntax table. Emacs' syntax tables -are more complicated than Regex's own (*note Non-Emacs Syntax -Tables::.). *Note Syntax: (emacs)Syntax, for a description of Emacs' -syntax tables. - - -File: regex.info, Node: Match-syntactic-class Operator, Next: Match-not-syntactic-class Operator, Prev: Emacs Syntax Tables, Up: Syntactic Class Operators - -The Match-syntactic-class Operator (`\s'CLASS) ----------------------------------------------- - - This operator matches any character whose syntactic class is -represented by a specified character. `\sCLASS' represents this -operator where CLASS is the character representing the syntactic class -you want. For example, `w' represents the syntactic class of -word-constituent characters, so `\sw' matches any word-constituent -character. - - -File: regex.info, Node: Match-not-syntactic-class Operator, Prev: Match-syntactic-class Operator, Up: Syntactic Class Operators - -The Match-not-syntactic-class Operator (`\S'CLASS) --------------------------------------------------- - - This operator is similar to the match-syntactic-class operator except -that it matches any character whose syntactic class is *not* -represented by the specified character. `\SCLASS' represents this -operator. For example, `w' represents the syntactic class of -word-constituent characters, so `\Sw' matches any character that is not -word-constituent. - - -File: regex.info, Node: What Gets Matched?, Next: Programming with Regex, Prev: GNU Emacs Operators, Up: Top - -What Gets Matched? -****************** - - Regex usually matches strings according to the "leftmost longest" -rule; that is, it chooses the longest of the leftmost matches. This -does not mean that for a regular expression containing subexpressions -that it simply chooses the longest match for each subexpression, left to -right; the overall match must also be the longest possible one. - - For example, `(ac*)(c*d[ac]*)\1' matches `acdacaaa', not `acdac', as -it would if it were to choose the longest match for the first -subexpression. - - -File: regex.info, Node: Programming with Regex, Next: Copying, Prev: What Gets Matched?, Up: Top - -Programming with Regex -********************** - - Here we describe how you use the Regex data structures and functions -in C programs. Regex has three interfaces: one designed for GNU, one -compatible with POSIX and one compatible with Berkeley UNIX. - -* Menu: - -* GNU Regex Functions:: -* POSIX Regex Functions:: -* BSD Regex Functions:: - - -File: regex.info, Node: GNU Regex Functions, Next: POSIX Regex Functions, Up: Programming with Regex - -GNU Regex Functions -=================== - - If you're writing code that doesn't need to be compatible with either -POSIX or Berkeley UNIX, you can use these functions. They provide more -options than the other interfaces. - -* Menu: - -* GNU Pattern Buffers:: The re_pattern_buffer type. -* GNU Regular Expression Compiling:: re_compile_pattern () -* GNU Matching:: re_match () -* GNU Searching:: re_search () -* Matching/Searching with Split Data:: re_match_2 (), re_search_2 () -* Searching with Fastmaps:: re_compile_fastmap () -* GNU Translate Tables:: The `translate' field. -* Using Registers:: The re_registers type and related fns. -* Freeing GNU Pattern Buffers:: regfree () - - -File: regex.info, Node: GNU Pattern Buffers, Next: GNU Regular Expression Compiling, Up: GNU Regex Functions - -GNU Pattern Buffers -------------------- - - To compile, match, or search for a given regular expression, you must -supply a pattern buffer. A "pattern buffer" holds one compiled regular -expression.(1) - - You can have several different pattern buffers simultaneously, each -holding a compiled pattern for a different regular expression. - - `regex.h' defines the pattern buffer `struct' as follows: - - /* Space that holds the compiled pattern. It is declared as - `unsigned char *' because its elements are - sometimes used as array indexes. */ - unsigned char *buffer; - - /* Number of bytes to which `buffer' points. */ - unsigned long allocated; - - /* Number of bytes actually used in `buffer'. */ - unsigned long used; - - /* Syntax setting with which the pattern was compiled. */ - reg_syntax_t syntax; - - /* Pointer to a fastmap, if any, otherwise zero. re_search uses - the fastmap, if there is one, to skip over impossible - starting points for matches. */ - char *fastmap; - - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation - is applied to a pattern when it is compiled and to a string - when it is matched. */ - char *translate; - - /* Number of subexpressions found by the compiler. */ - size_t re_nsub; - - /* Zero if this pattern cannot match the empty string, one else. - Well, in truth it's used only in `re_search_2', to see - whether or not we should use the fastmap, so we don't set - this absolutely perfectly; see `re_compile_fastmap' (the - `duplicate' case). */ - unsigned can_be_null : 1; - - /* If REGS_UNALLOCATED, allocate space in the `regs' structure - for `max (RE_NREGS, re_nsub + 1)' groups. - If REGS_REALLOCATE, reallocate space if necessary. - If REGS_FIXED, use what's there. */ - #define REGS_UNALLOCATED 0 - #define REGS_REALLOCATE 1 - #define REGS_FIXED 2 - unsigned regs_allocated : 2; - - /* Set to zero when `regex_compile' compiles a pattern; set to one - by `re_compile_fastmap' if it updates the fastmap. */ - unsigned fastmap_accurate : 1; - - /* If set, `re_match_2' does not return information about - subexpressions. */ - unsigned no_sub : 1; - - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ - unsigned not_bol : 1; - - /* Similarly for an end-of-line anchor. */ - unsigned not_eol : 1; - - /* If true, an anchor at a newline matches. */ - unsigned newline_anchor : 1; - - ---------- Footnotes ---------- - - (1) Regular expressions are also referred to as "patterns," hence -the name "pattern buffer." - - -File: regex.info, Node: GNU Regular Expression Compiling, Next: GNU Matching, Prev: GNU Pattern Buffers, Up: GNU Regex Functions - -GNU Regular Expression Compiling --------------------------------- - - In GNU, you can both match and search for a given regular expression. -To do either, you must first compile it in a pattern buffer (*note GNU -Pattern Buffers::.). - - Regular expressions match according to the syntax with which they were -compiled; with GNU, you indicate what syntax you want by setting the -variable `re_syntax_options' (declared in `regex.h' and defined in -`regex.c') before calling the compiling function, `re_compile_pattern' -(see below). *Note Syntax Bits::, and *Note Predefined Syntaxes::. - - You can change the value of `re_syntax_options' at any time. -Usually, however, you set its value once and then never change it. - - `re_compile_pattern' takes a pattern buffer as an argument. You must -initialize the following fields: - -`translate initialization' -`translate' - Initialize this to point to a translate table if you want one, or - to zero if you don't. We explain translate tables in *Note GNU - Translate Tables::. - -`fastmap' - Initialize this to nonzero if you want a fastmap, or to zero if you - don't. - -`buffer' -`allocated' - If you want `re_compile_pattern' to allocate memory for the - compiled pattern, set both of these to zero. If you have an - existing block of memory (allocated with `malloc') you want Regex - to use, set `buffer' to its address and `allocated' to its size (in - bytes). - - `re_compile_pattern' uses `realloc' to extend the space for the - compiled pattern as necessary. - - To compile a pattern buffer, use: - - char * - re_compile_pattern (const char *REGEX, const int REGEX_SIZE, - struct re_pattern_buffer *PATTERN_BUFFER) - -REGEX is the regular expression's address, REGEX_SIZE is its length, -and PATTERN_BUFFER is the pattern buffer's address. - - If `re_compile_pattern' successfully compiles the regular expression, -it returns zero and sets `*PATTERN_BUFFER' to the compiled pattern. It -sets the pattern buffer's fields as follows: - -`buffer' - to the compiled pattern. - -`used' - to the number of bytes the compiled pattern in `buffer' occupies. - -`syntax' - to the current value of `re_syntax_options'. - -`re_nsub' - to the number of subexpressions in REGEX. - -`fastmap_accurate' - to zero on the theory that the pattern you're compiling is - different than the one previously compiled into `buffer'; in that - case (since you can't make a fastmap without a compiled pattern), - `fastmap' would either contain an incompatible fastmap, or nothing - at all. - - If `re_compile_pattern' can't compile REGEX, it returns an error -string corresponding to one of the errors listed in *Note POSIX Regular -Expression Compiling::. - - -File: regex.info, Node: GNU Matching, Next: GNU Searching, Prev: GNU Regular Expression Compiling, Up: GNU Regex Functions - -GNU Matching ------------- - - Matching the GNU way means trying to match as much of a string as -possible starting at a position within it you specify. Once you've -compiled a pattern into a pattern buffer (*note GNU Regular Expression -Compiling::.), you can ask the matcher to match that pattern against a -string using: - - int - re_match (struct re_pattern_buffer *PATTERN_BUFFER, - const char *STRING, const int SIZE, - const int START, struct re_registers *REGS) - -PATTERN_BUFFER is the address of a pattern buffer containing a compiled -pattern. STRING is the string you want to match; it can contain -newline and null characters. SIZE is the length of that string. START -is the string index at which you want to begin matching; the first -character of STRING is at index zero. *Note Using Registers::, for a -explanation of REGS; you can safely pass zero. - - `re_match' matches the regular expression in PATTERN_BUFFER against -the string STRING according to the syntax in PATTERN_BUFFERS's `syntax' -field. (*Note GNU Regular Expression Compiling::, for how to set it.) -The function returns -1 if the compiled pattern does not match any part -of STRING and -2 if an internal error happens; otherwise, it returns -how many (possibly zero) characters of STRING the pattern matched. - - An example: suppose PATTERN_BUFFER points to a pattern buffer -containing the compiled pattern for `a*', and STRING points to `aaaaab' -(whereupon SIZE should be 6). Then if START is 2, `re_match' returns 3, -i.e., `a*' would have matched the last three `a's in STRING. If START -is 0, `re_match' returns 5, i.e., `a*' would have matched all the `a's -in STRING. If START is either 5 or 6, it returns zero. - - If START is not between zero and SIZE, then `re_match' returns -1. - - -File: regex.info, Node: GNU Searching, Next: Matching/Searching with Split Data, Prev: GNU Matching, Up: GNU Regex Functions - -GNU Searching -------------- - - "Searching" means trying to match starting at successive positions -within a string. The function `re_search' does this. - - Before calling `re_search', you must compile your regular expression. -*Note GNU Regular Expression Compiling::. - - Here is the function declaration: - - int - re_search (struct re_pattern_buffer *PATTERN_BUFFER, - const char *STRING, const int SIZE, - const int START, const int RANGE, - struct re_registers *REGS) - -whose arguments are the same as those to `re_match' (*note GNU -Matching::.) except that the two arguments START and RANGE replace -`re_match''s argument START. - - If RANGE is positive, then `re_search' attempts a match starting -first at index START, then at START + 1 if that fails, and so on, up to -START + RANGE; if RANGE is negative, then it attempts a match starting -first at index START, then at START -1 if that fails, and so on. - - If START is not between zero and SIZE, then `re_search' returns -1. -When RANGE is positive, `re_search' adjusts RANGE so that START + RANGE -- 1 is between zero and SIZE, if necessary; that way it won't search -outside of STRING. Similarly, when RANGE is negative, `re_search' -adjusts RANGE so that START + RANGE + 1 is between zero and SIZE, if -necessary. - - If the `fastmap' field of PATTERN_BUFFER is zero, `re_search' matches -starting at consecutive positions; otherwise, it uses `fastmap' to make -the search more efficient. *Note Searching with Fastmaps::. - - If no match is found, `re_search' returns -1. If a match is found, -it returns the index where the match began. If an internal error -happens, it returns -2. - - -File: regex.info, Node: Matching/Searching with Split Data, Next: Searching with Fastmaps, Prev: GNU Searching, Up: GNU Regex Functions - -Matching and Searching with Split Data --------------------------------------- - - Using the functions `re_match_2' and `re_search_2', you can match or -search in data that is divided into two strings. - - The function: - - int - re_match_2 (struct re_pattern_buffer *BUFFER, - const char *STRING1, const int SIZE1, - const char *STRING2, const int SIZE2, - const int START, - struct re_registers *REGS, - const int STOP) - -is similar to `re_match' (*note GNU Matching::.) except that you pass -*two* data strings and sizes, and an index STOP beyond which you don't -want the matcher to try matching. As with `re_match', if it succeeds, -`re_match_2' returns how many characters of STRING it matched. Regard -STRING1 and STRING2 as concatenated when you set the arguments START and -STOP and use the contents of REGS; `re_match_2' never returns a value -larger than SIZE1 + SIZE2. - - The function: - - int - re_search_2 (struct re_pattern_buffer *BUFFER, - const char *STRING1, const int SIZE1, - const char *STRING2, const int SIZE2, - const int START, const int RANGE, - struct re_registers *REGS, - const int STOP) - -is similarly related to `re_search'. - - -File: regex.info, Node: Searching with Fastmaps, Next: GNU Translate Tables, Prev: Matching/Searching with Split Data, Up: GNU Regex Functions - -Searching with Fastmaps ------------------------ - - If you're searching through a long string, you should use a fastmap. -Without one, the searcher tries to match at consecutive positions in the -string. Generally, most of the characters in the string could not start -a match. It takes much longer to try matching at a given position in -the string than it does to check in a table whether or not the -character at that position could start a match. A "fastmap" is such a -table. - - More specifically, a fastmap is an array indexed by the characters in -your character set. Under the ASCII encoding, therefore, a fastmap has -256 elements. If you want the searcher to use a fastmap with a given -pattern buffer, you must allocate the array and assign the array's -address to the pattern buffer's `fastmap' field. You either can -compile the fastmap yourself or have `re_search' do it for you; when -`fastmap' is nonzero, it automatically compiles a fastmap the first -time you search using a particular compiled pattern. - - To compile a fastmap yourself, use: - - int - re_compile_fastmap (struct re_pattern_buffer *PATTERN_BUFFER) - -PATTERN_BUFFER is the address of a pattern buffer. If the character C -could start a match for the pattern, `re_compile_fastmap' makes -`PATTERN_BUFFER->fastmap[C]' nonzero. It returns 0 if it can compile a -fastmap and -2 if there is an internal error. For example, if `|' is -the alternation operator and PATTERN_BUFFER holds the compiled pattern -for `a|b', then `re_compile_fastmap' sets `fastmap['a']' and -`fastmap['b']' (and no others). - - `re_search' uses a fastmap as it moves along in the string: it checks -the string's characters until it finds one that's in the fastmap. Then -it tries matching at that character. If the match fails, it repeats -the process. So, by using a fastmap, `re_search' doesn't waste time -trying to match at positions in the string that couldn't start a match. - - If you don't want `re_search' to use a fastmap, store zero in the -`fastmap' field of the pattern buffer before calling `re_search'. - - Once you've initialized a pattern buffer's `fastmap' field, you need -never do so again--even if you compile a new pattern in it--provided -the way the field is set still reflects whether or not you want a -fastmap. `re_search' will still either do nothing if `fastmap' is null -or, if it isn't, compile a new fastmap for the new pattern. - - -File: regex.info, Node: GNU Translate Tables, Next: Using Registers, Prev: Searching with Fastmaps, Up: GNU Regex Functions - -GNU Translate Tables --------------------- - - If you set the `translate' field of a pattern buffer to a translate -table, then the GNU Regex functions to which you've passed that pattern -buffer use it to apply a simple transformation to all the regular -expression and string characters at which they look. - - A "translate table" is an array indexed by the characters in your -character set. Under the ASCII encoding, therefore, a translate table -has 256 elements. The array's elements are also characters in your -character set. When the Regex functions see a character C, they use -`translate[C]' in its place, with one exception: the character after a -`\' is not translated. (This ensures that, the operators, e.g., `\B' -and `\b', are always distinguishable.) - - For example, a table that maps all lowercase letters to the -corresponding uppercase ones would cause the matcher to ignore -differences in case.(1) Such a table would map all characters except -lowercase letters to themselves, and lowercase letters to the -corresponding uppercase ones. Under the ASCII encoding, here's how you -could initialize such a table (we'll call it `case_fold'): - - for (i = 0; i < 256; i++) - case_fold[i] = i; - for (i = 'a'; i <= 'z'; i++) - case_fold[i] = i - ('a' - 'A'); - - You tell Regex to use a translate table on a given pattern buffer by -assigning that table's address to the `translate' field of that buffer. -If you don't want Regex to do any translation, put zero into this -field. You'll get weird results if you change the table's contents -anytime between compiling the pattern buffer, compiling its fastmap, and -matching or searching with the pattern buffer. - - ---------- Footnotes ---------- - - (1) A table that maps all uppercase letters to the corresponding -lowercase ones would work just as well for this purpose. - - -File: regex.info, Node: Using Registers, Next: Freeing GNU Pattern Buffers, Prev: GNU Translate Tables, Up: GNU Regex Functions - -Using Registers ---------------- - - A group in a regular expression can match a (posssibly empty) -substring of the string that regular expression as a whole matched. -The matcher remembers the beginning and end of the substring matched by -each group. - - To find out what they matched, pass a nonzero REGS argument to a GNU -matching or searching function (*note GNU Matching::. and *Note GNU -Searching::), i.e., the address of a structure of this type, as defined -in `regex.h': - - struct re_registers - { - unsigned num_regs; - regoff_t *start; - regoff_t *end; - }; - - Except for (possibly) the NUM_REGS'th element (see below), the Ith -element of the `start' and `end' arrays records information about the -Ith group in the pattern. (They're declared as C pointers, but this is -only because not all C compilers accept zero-length arrays; -conceptually, it is simplest to think of them as arrays.) - - The `start' and `end' arrays are allocated in various ways, depending -on the value of the `regs_allocated' field in the pattern buffer passed -to the matcher. - - The simplest and perhaps most useful is to let the matcher -(re)allocate enough space to record information for all the groups in -the regular expression. If `regs_allocated' is `REGS_UNALLOCATED', the -matcher allocates 1 + RE_NSUB (another field in the pattern buffer; -*note GNU Pattern Buffers::.). The extra element is set to -1, and -sets `regs_allocated' to `REGS_REALLOCATE'. Then on subsequent calls -with the same pattern buffer and REGS arguments, the matcher -reallocates more space if necessary. - - It would perhaps be more logical to make the `regs_allocated' field -part of the `re_registers' structure, instead of part of the pattern -buffer. But in that case the caller would be forced to initialize the -structure before passing it. Much existing code doesn't do this -initialization, and it's arguably better to avoid it anyway. - - `re_compile_pattern' sets `regs_allocated' to `REGS_UNALLOCATED', so -if you use the GNU regular expression functions, you get this behavior -by default. - - xx document re_set_registers - - POSIX, on the other hand, requires a different interface: the caller -is supposed to pass in a fixed-length array which the matcher fills. -Therefore, if `regs_allocated' is `REGS_FIXED' the matcher simply fills -that array. - - The following examples illustrate the information recorded in the -`re_registers' structure. (In all of them, `(' represents the -open-group and `)' the close-group operator. The first character in -the string STRING is at index 0.) - - * If the regular expression has an I-th group not contained within - another group that matches a substring of STRING, then the - function sets `REGS->start[I]' to the index in STRING where the - substring matched by the I-th group begins, and `REGS->end[I]' to - the index just beyond that substring's end. The function sets - `REGS->start[0]' and `REGS->end[0]' to analogous information about - the entire pattern. - - For example, when you match `((a)(b))' against `ab', you get: - - * 0 in `REGS->start[0]' and 2 in `REGS->end[0]' - - * 0 in `REGS->start[1]' and 2 in `REGS->end[1]' - - * 0 in `REGS->start[2]' and 1 in `REGS->end[2]' - - * 1 in `REGS->start[3]' and 2 in `REGS->end[3]' - - * If a group matches more than once (as it might if followed by, - e.g., a repetition operator), then the function reports the - information about what the group *last* matched. - - For example, when you match the pattern `(a)*' against the string - `aa', you get: - - * 0 in `REGS->start[0]' and 2 in `REGS->end[0]' - - * 1 in `REGS->start[1]' and 2 in `REGS->end[1]' - - * If the I-th group does not participate in a successful match, - e.g., it is an alternative not taken or a repetition operator - allows zero repetitions of it, then the function sets - `REGS->start[I]' and `REGS->end[I]' to -1. - - For example, when you match the pattern `(a)*b' against the string - `b', you get: - - * 0 in `REGS->start[0]' and 1 in `REGS->end[0]' - - * -1 in `REGS->start[1]' and -1 in `REGS->end[1]' - - * If the I-th group matches a zero-length string, then the function - sets `REGS->start[I]' and `REGS->end[I]' to the index just beyond - that zero-length string. - - For example, when you match the pattern `(a*)b' against the string - `b', you get: - - * 0 in `REGS->start[0]' and 1 in `REGS->end[0]' - - * 0 in `REGS->start[1]' and 0 in `REGS->end[1]' - - * If an I-th group contains a J-th group in turn not contained - within any other group within group I and the function reports a - match of the I-th group, then it records in `REGS->start[J]' and - `REGS->end[J]' the last match (if it matched) of the J-th group. - - For example, when you match the pattern `((a*)b)*' against the - string `abb', group 2 last matches the empty string, so you get - what it previously matched: - - * 0 in `REGS->start[0]' and 3 in `REGS->end[0]' - - * 2 in `REGS->start[1]' and 3 in `REGS->end[1]' - - * 2 in `REGS->start[2]' and 2 in `REGS->end[2]' - - When you match the pattern `((a)*b)*' against the string `abb', - group 2 doesn't participate in the last match, so you get: - - * 0 in `REGS->start[0]' and 3 in `REGS->end[0]' - - * 2 in `REGS->start[1]' and 3 in `REGS->end[1]' - - * 0 in `REGS->start[2]' and 1 in `REGS->end[2]' - - * If an I-th group contains a J-th group in turn not contained - within any other group within group I and the function sets - `REGS->start[I]' and `REGS->end[I]' to -1, then it also sets - `REGS->start[J]' and `REGS->end[J]' to -1. - - For example, when you match the pattern `((a)*b)*c' against the - string `c', you get: - - * 0 in `REGS->start[0]' and 1 in `REGS->end[0]' - - * -1 in `REGS->start[1]' and -1 in `REGS->end[1]' - - * -1 in `REGS->start[2]' and -1 in `REGS->end[2]' - - -File: regex.info, Node: Freeing GNU Pattern Buffers, Prev: Using Registers, Up: GNU Regex Functions - -Freeing GNU Pattern Buffers ---------------------------- - - To free any allocated fields of a pattern buffer, you can use the -POSIX function described in *Note Freeing POSIX Pattern Buffers::, -since the type `regex_t'--the type for POSIX pattern buffers--is -equivalent to the type `re_pattern_buffer'. After freeing a pattern -buffer, you need to again compile a regular expression in it (*note GNU -Regular Expression Compiling::.) before passing it to a matching or -searching function. - - -File: regex.info, Node: POSIX Regex Functions, Next: BSD Regex Functions, Prev: GNU Regex Functions, Up: Programming with Regex - -POSIX Regex Functions -===================== - - If you're writing code that has to be POSIX compatible, you'll need -to use these functions. Their interfaces are as specified by POSIX, -draft 1003.2/D11.2. - -* Menu: - -* POSIX Pattern Buffers:: The regex_t type. -* POSIX Regular Expression Compiling:: regcomp () -* POSIX Matching:: regexec () -* Reporting Errors:: regerror () -* Using Byte Offsets:: The regmatch_t type. -* Freeing POSIX Pattern Buffers:: regfree () - - -File: regex.info, Node: POSIX Pattern Buffers, Next: POSIX Regular Expression Compiling, Up: POSIX Regex Functions - -POSIX Pattern Buffers ---------------------- - - To compile or match a given regular expression the POSIX way, you -must supply a pattern buffer exactly the way you do for GNU (*note GNU -Pattern Buffers::.). POSIX pattern buffers have type `regex_t', which -is equivalent to the GNU pattern buffer type `re_pattern_buffer'. - - -File: regex.info, Node: POSIX Regular Expression Compiling, Next: POSIX Matching, Prev: POSIX Pattern Buffers, Up: POSIX Regex Functions - -POSIX Regular Expression Compiling ----------------------------------- - - With POSIX, you can only search for a given regular expression; you -can't match it. To do this, you must first compile it in a pattern -buffer, using `regcomp'. - - To compile a pattern buffer, use: - - int - regcomp (regex_t *PREG, const char *REGEX, int CFLAGS) - -PREG is the initialized pattern buffer's address, REGEX is the regular -expression's address, and CFLAGS is the compilation flags, which Regex -considers as a collection of bits. Here are the valid bits, as defined -in `regex.h': - -`REG_EXTENDED' - says to use POSIX Extended Regular Expression syntax; if this isn't - set, then says to use POSIX Basic Regular Expression syntax. - `regcomp' sets PREG's `syntax' field accordingly. - -`REG_ICASE' - says to ignore case; `regcomp' sets PREG's `translate' field to a - translate table which ignores case, replacing anything you've put - there before. - -`REG_NOSUB' - says to set PREG's `no_sub' field; *note POSIX Matching::., for - what this means. - -`REG_NEWLINE' - says that a: - - * match-any-character operator (*note Match-any-character - Operator::.) doesn't match a newline. - - * nonmatching list not containing a newline (*note List - Operators::.) matches a newline. - - * match-beginning-of-line operator (*note - Match-beginning-of-line Operator::.) matches the empty string - immediately after a newline, regardless of how `REG_NOTBOL' - is set (*note POSIX Matching::., for an explanation of - `REG_NOTBOL'). - - * match-end-of-line operator (*note Match-beginning-of-line - Operator::.) matches the empty string immediately before a - newline, regardless of how `REG_NOTEOL' is set (*note POSIX - Matching::., for an explanation of `REG_NOTEOL'). - - If `regcomp' successfully compiles the regular expression, it returns -zero and sets `*PATTERN_BUFFER' to the compiled pattern. Except for -`syntax' (which it sets as explained above), it also sets the same -fields the same way as does the GNU compiling function (*note GNU -Regular Expression Compiling::.). - - If `regcomp' can't compile the regular expression, it returns one of -the error codes listed here. (Except when noted differently, the -syntax of in all examples below is basic regular expression syntax.) - -`REG_BADRPT' - For example, the consecutive repetition operators `**' in `a**' - are invalid. As another example, if the syntax is extended - regular expression syntax, then the repetition operator `*' with - nothing on which to operate in `*' is invalid. - -`REG_BADBR' - For example, the COUNT `-1' in `a\{-1' is invalid. - -`REG_EBRACE' - For example, `a\{1' is missing a close-interval operator. - -`REG_EBRACK' - For example, `[a' is missing a close-list operator. - -`REG_ERANGE' - For example, the range ending point `z' that collates lower than - does its starting point `a' in `[z-a]' is invalid. Also, the - range with the character class `[:alpha:]' as its starting point in - `[[:alpha:]-|]'. - -`REG_ECTYPE' - For example, the character class name `foo' in `[[:foo:]' is - invalid. - -`REG_EPAREN' - For example, `a\)' is missing an open-group operator and `\(a' is - missing a close-group operator. - -`REG_ESUBREG' - For example, the back reference `\2' that refers to a nonexistent - subexpression in `\(a\)\2' is invalid. - -`REG_EEND' - Returned when a regular expression causes no other more specific - error. - -`REG_EESCAPE' - For example, the trailing backslash `\' in `a\' is invalid, as is - the one in `\'. - -`REG_BADPAT' - For example, in the extended regular expression syntax, the empty - group `()' in `a()b' is invalid. - -`REG_ESIZE' - Returned when a regular expression needs a pattern buffer larger - than 65536 bytes. - -`REG_ESPACE' - Returned when a regular expression makes Regex to run out of - memory. - - -File: regex.info, Node: POSIX Matching, Next: Reporting Errors, Prev: POSIX Regular Expression Compiling, Up: POSIX Regex Functions - -POSIX Matching --------------- - - Matching the POSIX way means trying to match a null-terminated string -starting at its first character. Once you've compiled a pattern into a -pattern buffer (*note POSIX Regular Expression Compiling::.), you can -ask the matcher to match that pattern against a string using: - - int - regexec (const regex_t *PREG, const char *STRING, - size_t NMATCH, regmatch_t PMATCH[], int EFLAGS) - -PREG is the address of a pattern buffer for a compiled pattern. STRING -is the string you want to match. - - *Note Using Byte Offsets::, for an explanation of PMATCH. If you -pass zero for NMATCH or you compiled PREG with the compilation flag -`REG_NOSUB' set, then `regexec' will ignore PMATCH; otherwise, you must -allocate it to have at least NMATCH elements. `regexec' will record -NMATCH byte offsets in PMATCH, and set to -1 any unused elements up to -PMATCH`[NMATCH]' - 1. - - EFLAGS specifies "execution flags"--namely, the two bits `REG_NOTBOL' -and `REG_NOTEOL' (defined in `regex.h'). If you set `REG_NOTBOL', then -the match-beginning-of-line operator (*note Match-beginning-of-line -Operator::.) always fails to match. This lets you match against pieces -of a line, as you would need to if, say, searching for repeated -instances of a given pattern in a line; it would work correctly for -patterns both with and without match-beginning-of-line operators. -`REG_NOTEOL' works analogously for the match-end-of-line operator -(*note Match-end-of-line Operator::.); it exists for symmetry. - - `regexec' tries to find a match for PREG in STRING according to the -syntax in PREG's `syntax' field. (*Note POSIX Regular Expression -Compiling::, for how to set it.) The function returns zero if the -compiled pattern matches STRING and `REG_NOMATCH' (defined in -`regex.h') if it doesn't. - - -File: regex.info, Node: Reporting Errors, Next: Using Byte Offsets, Prev: POSIX Matching, Up: POSIX Regex Functions - -Reporting Errors ----------------- - - If either `regcomp' or `regexec' fail, they return a nonzero error -code, the possibilities for which are defined in `regex.h'. *Note -POSIX Regular Expression Compiling::, and *Note POSIX Matching::, for -what these codes mean. To get an error string corresponding to these -codes, you can use: - - size_t - regerror (int ERRCODE, - const regex_t *PREG, - char *ERRBUF, - size_t ERRBUF_SIZE) - -ERRCODE is an error code, PREG is the address of the pattern buffer -which provoked the error, ERRBUF is the error buffer, and ERRBUF_SIZE -is ERRBUF's size. - - `regerror' returns the size in bytes of the error string -corresponding to ERRCODE (including its terminating null). If ERRBUF -and ERRBUF_SIZE are nonzero, it also returns in ERRBUF the first -ERRBUF_SIZE - 1 characters of the error string, followed by a null. -eRRBUF_SIZE must be a nonnegative number less than or equal to the size -in bytes of ERRBUF. - - You can call `regerror' with a null ERRBUF and a zero ERRBUF_SIZE to -determine how large ERRBUF need be to accommodate `regerror''s error -string. - - -File: regex.info, Node: Using Byte Offsets, Next: Freeing POSIX Pattern Buffers, Prev: Reporting Errors, Up: POSIX Regex Functions - -Using Byte Offsets ------------------- - - In POSIX, variables of type `regmatch_t' hold analogous information, -but are not identical to, GNU's registers (*note Using Registers::.). -To get information about registers in POSIX, pass to `regexec' a -nonzero PMATCH of type `regmatch_t', i.e., the address of a structure -of this type, defined in `regex.h': - - typedef struct - { - regoff_t rm_so; - regoff_t rm_eo; - } regmatch_t; - - When reading in *Note Using Registers::, about how the matching -function stores the information into the registers, substitute PMATCH -for REGS, `PMATCH[I]->rm_so' for `REGS->start[I]' and -`PMATCH[I]->rm_eo' for `REGS->end[I]'. - - -File: regex.info, Node: Freeing POSIX Pattern Buffers, Prev: Using Byte Offsets, Up: POSIX Regex Functions - -Freeing POSIX Pattern Buffers ------------------------------ - - To free any allocated fields of a pattern buffer, use: - - void - regfree (regex_t *PREG) - -PREG is the pattern buffer whose allocated fields you want freed. -`regfree' also sets PREG's `allocated' and `used' fields to zero. -After freeing a pattern buffer, you need to again compile a regular -expression in it (*note POSIX Regular Expression Compiling::.) before -passing it to the matching function (*note POSIX Matching::.). - - -File: regex.info, Node: BSD Regex Functions, Prev: POSIX Regex Functions, Up: Programming with Regex - -BSD Regex Functions -=================== - - If you're writing code that has to be Berkeley UNIX compatible, -you'll need to use these functions whose interfaces are the same as -those in Berkeley UNIX. - -* Menu: - -* BSD Regular Expression Compiling:: re_comp () -* BSD Searching:: re_exec () - - -File: regex.info, Node: BSD Regular Expression Compiling, Next: BSD Searching, Up: BSD Regex Functions - -BSD Regular Expression Compiling --------------------------------- - - With Berkeley UNIX, you can only search for a given regular -expression; you can't match one. To search for it, you must first -compile it. Before you compile it, you must indicate the regular -expression syntax you want it compiled according to by setting the -variable `re_syntax_options' (declared in `regex.h' to some syntax -(*note Regular Expression Syntax::.). - - To compile a regular expression use: - - char * - re_comp (char *REGEX) - -REGEX is the address of a null-terminated regular expression. -`re_comp' uses an internal pattern buffer, so you can use only the most -recently compiled pattern buffer. This means that if you want to use a -given regular expression that you've already compiled--but it isn't the -latest one you've compiled--you'll have to recompile it. If you call -`re_comp' with the null string (*not* the empty string) as the -argument, it doesn't change the contents of the pattern buffer. - - If `re_comp' successfully compiles the regular expression, it returns -zero. If it can't compile the regular expression, it returns an error -string. `re_comp''s error messages are identical to those of -`re_compile_pattern' (*note GNU Regular Expression Compiling::.). - - -File: regex.info, Node: BSD Searching, Prev: BSD Regular Expression Compiling, Up: BSD Regex Functions - -BSD Searching -------------- - - Searching the Berkeley UNIX way means searching in a string starting -at its first character and trying successive positions within it to -find a match. Once you've compiled a pattern using `re_comp' (*note -BSD Regular Expression Compiling::.), you can ask Regex to search for -that pattern in a string using: - - int - re_exec (char *STRING) - -STRING is the address of the null-terminated string in which you want -to search. - - `re_exec' returns either 1 for success or 0 for failure. It -automatically uses a GNU fastmap (*note Searching with Fastmaps::.). - - -File: regex.info, Node: Copying, Next: Index, Prev: Programming with Regex, Up: Top - -GNU GENERAL PUBLIC LICENSE -************************** - - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 675 Mass Ave, Cambridge, MA 02139, USA - - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -Preamble -======== - - The licenses for most software are designed to take away your freedom -to share and change it. By contrast, the GNU General Public License is -intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it in -new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 1. This License applies to any program or other work which contains a - notice placed by the copyright holder saying it may be distributed - under the terms of this General Public License. The "Program", - below, refers to any such program or work, and a "work based on - the Program" means either the Program or any derivative work under - copyright law: that is to say, a work containing the Program or a - portion of it, either verbatim or with modifications and/or - translated into another language. (Hereinafter, translation is - included without limitation in the term "modification".) Each - licensee is addressed as "you". - - Activities other than copying, distribution and modification are - not covered by this License; they are outside its scope. The act - of running the Program is not restricted, and the output from the - Program is covered only if its contents constitute a work based on - the Program (independent of having been made by running the - Program). Whether that is true depends on what the Program does. - - 2. You may copy and distribute verbatim copies of the Program's - source code as you receive it, in any medium, provided that you - conspicuously and appropriately publish on each copy an appropriate - copyright notice and disclaimer of warranty; keep intact all the - notices that refer to this License and to the absence of any - warranty; and give any other recipients of the Program a copy of - this License along with the Program. - - You may charge a fee for the physical act of transferring a copy, - and you may at your option offer warranty protection in exchange - for a fee. - - 3. You may modify your copy or copies of the Program or any portion - of it, thus forming a work based on the Program, and copy and - distribute such modifications or work under the terms of Section 1 - above, provided that you also meet all of these conditions: - - a. You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b. You must cause any work that you distribute or publish, that - in whole or in part contains or is derived from the Program - or any part thereof, to be licensed as a whole at no charge - to all third parties under the terms of this License. - - c. If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display - an announcement including an appropriate copyright notice and - a notice that there is no warranty (or else, saying that you - provide a warranty) and that users may redistribute the - program under these conditions, and telling the user how to - view a copy of this License. (Exception: if the Program - itself is interactive but does not normally print such an - announcement, your work based on the Program is not required - to print an announcement.) - - These requirements apply to the modified work as a whole. If - identifiable sections of that work are not derived from the - Program, and can be reasonably considered independent and separate - works in themselves, then this License, and its terms, do not - apply to those sections when you distribute them as separate - works. But when you distribute the same sections as part of a - whole which is a work based on the Program, the distribution of - the whole must be on the terms of this License, whose permissions - for other licensees extend to the entire whole, and thus to each - and every part regardless of who wrote it. - - Thus, it is not the intent of this section to claim rights or - contest your rights to work written entirely by you; rather, the - intent is to exercise the right to control the distribution of - derivative or collective works based on the Program. - - In addition, mere aggregation of another work not based on the - Program with the Program (or with a work based on the Program) on - a volume of a storage or distribution medium does not bring the - other work under the scope of this License. - - 4. You may copy and distribute the Program (or a work based on it, - under Section 2) in object code or executable form under the terms - of Sections 1 and 2 above provided that you also do one of the - following: - - a. Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of - Sections 1 and 2 above on a medium customarily used for - software interchange; or, - - b. Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a - medium customarily used for software interchange; or, - - c. Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with - such an offer, in accord with Subsection b above.) - - The source code for a work means the preferred form of the work for - making modifications to it. For an executable work, complete - source code means all the source code for all modules it contains, - plus any associated interface definition files, plus the scripts - used to control compilation and installation of the executable. - However, as a special exception, the source code distributed need - not include anything that is normally distributed (in either - source or binary form) with the major components (compiler, - kernel, and so on) of the operating system on which the executable - runs, unless that component itself accompanies the executable. - - If distribution of executable or object code is made by offering - access to copy from a designated place, then offering equivalent - access to copy the source code from the same place counts as - distribution of the source code, even though third parties are not - compelled to copy the source along with the object code. - - 5. You may not copy, modify, sublicense, or distribute the Program - except as expressly provided under this License. Any attempt - otherwise to copy, modify, sublicense or distribute the Program is - void, and will automatically terminate your rights under this - License. However, parties who have received copies, or rights, - from you under this License will not have their licenses - terminated so long as such parties remain in full compliance. - - 6. You are not required to accept this License, since you have not - signed it. However, nothing else grants you permission to modify - or distribute the Program or its derivative works. These actions - are prohibited by law if you do not accept this License. - Therefore, by modifying or distributing the Program (or any work - based on the Program), you indicate your acceptance of this - License to do so, and all its terms and conditions for copying, - distributing or modifying the Program or works based on it. - - 7. Each time you redistribute the Program (or any work based on the - Program), the recipient automatically receives a license from the - original licensor to copy, distribute or modify the Program - subject to these terms and conditions. You may not impose any - further restrictions on the recipients' exercise of the rights - granted herein. You are not responsible for enforcing compliance - by third parties to this License. - - 8. If, as a consequence of a court judgment or allegation of patent - infringement or for any other reason (not limited to patent - issues), conditions are imposed on you (whether by court order, - agreement or otherwise) that contradict the conditions of this - License, they do not excuse you from the conditions of this - License. If you cannot distribute so as to satisfy simultaneously - your obligations under this License and any other pertinent - obligations, then as a consequence you may not distribute the - Program at all. For example, if a patent license would not permit - royalty-free redistribution of the Program by all those who - receive copies directly or indirectly through you, then the only - way you could satisfy both it and this License would be to refrain - entirely from distribution of the Program. - - If any portion of this section is held invalid or unenforceable - under any particular circumstance, the balance of the section is - intended to apply and the section as a whole is intended to apply - in other circumstances. - - It is not the purpose of this section to induce you to infringe any - patents or other property right claims or to contest validity of - any such claims; this section has the sole purpose of protecting - the integrity of the free software distribution system, which is - implemented by public license practices. Many people have made - generous contributions to the wide range of software distributed - through that system in reliance on consistent application of that - system; it is up to the author/donor to decide if he or she is - willing to distribute software through any other system and a - licensee cannot impose that choice. - - This section is intended to make thoroughly clear what is believed - to be a consequence of the rest of this License. - - 9. If the distribution and/or use of the Program is restricted in - certain countries either by patents or by copyrighted interfaces, - the original copyright holder who places the Program under this - License may add an explicit geographical distribution limitation - excluding those countries, so that distribution is permitted only - in or among countries not thus excluded. In such case, this - License incorporates the limitation as if written in the body of - this License. - - 10. The Free Software Foundation may publish revised and/or new - versions of the General Public License from time to time. Such - new versions will be similar in spirit to the present version, but - may differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the - Program specifies a version number of this License which applies - to it and "any later version", you have the option of following - the terms and conditions either of that version or of any later - version published by the Free Software Foundation. If the Program - does not specify a version number of this License, you may choose - any version ever published by the Free Software Foundation. - - 11. If you wish to incorporate parts of the Program into other free - programs whose distribution conditions are different, write to the - author to ask for permission. For software which is copyrighted - by the Free Software Foundation, write to the Free Software - Foundation; we sometimes make exceptions for this. Our decision - will be guided by the two goals of preserving the free status of - all derivatives of our free software and of promoting the sharing - and reuse of software generally. - - NO WARRANTY - - 12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO - WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE - LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT - HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT - WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT - NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE - QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE - PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY - SERVICING, REPAIR OR CORRECTION. - - 13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN - WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY - MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE - LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, - INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR - INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF - DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU - OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY - OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN - ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - -Appendix: How to Apply These Terms to Your New Programs -======================================================= - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these -terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES. - Copyright (C) 19YY NAME OF AUTHOR - - 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 of the License, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - Also add information on how to contact you by electronic and paper -mail. - - If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - - The hypothetical commands `show w' and `show c' should show the -appropriate parts of the General Public License. Of course, the -commands you use may be called something other than `show w' and `show -c'; they could even be mouse-clicks or menu items--whatever suits your -program. - - You should also get your employer (if you work as a programmer) or -your school, if any, to sign a "copyright disclaimer" for the program, -if necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - SIGNATURE OF TY COON, 1 April 1989 - Ty Coon, President of Vice - - This General Public License does not permit incorporating your -program into proprietary programs. If your program is a subroutine -library, you may consider it more useful to permit linking proprietary -applications with the library. If this is what you want to do, use the -GNU Library General Public License instead of this License. - - -File: regex.info, Node: Index, Prev: Copying, Up: Top - -Index -***** - -* Menu: - -* $: Match-end-of-line Operator. -* (: Grouping Operators. -* ): Grouping Operators. -* *: Match-zero-or-more Operator. -* +: Match-one-or-more Operator. -* -: List Operators. -* .: Match-any-character Operator. -* :] in regex: Character Class Operators. -* ?: Match-zero-or-one Operator. -* {: Interval Operators. -* }: Interval Operators. -* [: in regex: Character Class Operators. -* [^: List Operators. -* [: List Operators. -* \': Match-end-of-buffer Operator. -* \<: Match-beginning-of-word Operator. -* \>: Match-end-of-word Operator. -* \{: Interval Operators. -* \}: Interval Operators. -* \b: Match-word-boundary Operator. -* \B: Match-within-word Operator. -* \s: Match-syntactic-class Operator. -* \S: Match-not-syntactic-class Operator. -* \w: Match-word-constituent Operator. -* \W: Match-non-word-constituent Operator. -* \`: Match-beginning-of-buffer Operator. -* \: List Operators. -* ]: List Operators. -* ^: List Operators. -* allocated initialization: GNU Regular Expression Compiling. -* alternation operator: Alternation Operator. -* alternation operator and ^: Match-beginning-of-line Operator. -* anchoring: Anchoring Operators. -* anchors: Match-end-of-line Operator. -* anchors: Match-beginning-of-line Operator. -* Awk: Predefined Syntaxes. -* back references: Back-reference Operator. -* backtracking: Match-zero-or-more Operator. -* backtracking: Alternation Operator. -* beginning-of-line operator: Match-beginning-of-line Operator. -* bracket expression: List Operators. -* buffer field, set by re_compile_pattern: GNU Regular Expression Compiling. -* buffer initialization: GNU Regular Expression Compiling. -* character classes: Character Class Operators. -* Egrep: Predefined Syntaxes. -* Emacs: Predefined Syntaxes. -* end in struct re_registers: Using Registers. -* end-of-line operator: Match-end-of-line Operator. -* fastmap initialization: GNU Regular Expression Compiling. -* fastmaps: Searching with Fastmaps. -* fastmap_accurate field, set by re_compile_pattern: GNU Regular Expression Compiling. -* Grep: Predefined Syntaxes. -* grouping: Grouping Operators. -* ignoring case: POSIX Regular Expression Compiling. -* interval expression: Interval Operators. -* matching list: List Operators. -* matching newline: List Operators. -* matching with GNU functions: GNU Matching. -* newline_anchor field in pattern buffer: Match-beginning-of-line Operator. -* nonmatching list: List Operators. -* not_bol field in pattern buffer: Match-beginning-of-line Operator. -* num_regs in struct re_registers: Using Registers. -* open-group operator and ^: Match-beginning-of-line Operator. -* or operator: Alternation Operator. -* parenthesizing: Grouping Operators. -* pattern buffer initialization: GNU Regular Expression Compiling. -* pattern buffer, definition of: GNU Pattern Buffers. -* POSIX Awk: Predefined Syntaxes. -* range argument to re_search: GNU Searching. -* regex.c: Overview. -* regex.h: Overview. -* regexp anchoring: Anchoring Operators. -* regmatch_t: Using Byte Offsets. -* regs_allocated: Using Registers. -* REGS_FIXED: Using Registers. -* REGS_REALLOCATE: Using Registers. -* REGS_UNALLOCATED: Using Registers. -* regular expressions, syntax of: Regular Expression Syntax. -* REG_EXTENDED: POSIX Regular Expression Compiling. -* REG_ICASE: POSIX Regular Expression Compiling. -* REG_NEWLINE: POSIX Regular Expression Compiling. -* REG_NOSUB: POSIX Regular Expression Compiling. -* RE_BACKSLASH_ESCAPE_IN_LIST: Syntax Bits. -* RE_BK_PLUS_QM: Syntax Bits. -* RE_CHAR_CLASSES: Syntax Bits. -* RE_CONTEXT_INDEP_ANCHORS: Syntax Bits. -* RE_CONTEXT_INDEP_ANCHORS (and ^): Match-beginning-of-line Operator. -* RE_CONTEXT_INDEP_OPS: Syntax Bits. -* RE_CONTEXT_INVALID_OPS: Syntax Bits. -* RE_DOT_NEWLINE: Syntax Bits. -* RE_DOT_NOT_NULL: Syntax Bits. -* RE_INTERVALS: Syntax Bits. -* RE_LIMITED_OPS: Syntax Bits. -* RE_NEWLINE_ALT: Syntax Bits. -* RE_NO_BK_BRACES: Syntax Bits. -* RE_NO_BK_PARENS: Syntax Bits. -* RE_NO_BK_REFS: Syntax Bits. -* RE_NO_BK_VBAR: Syntax Bits. -* RE_NO_EMPTY_RANGES: Syntax Bits. -* re_nsub field, set by re_compile_pattern: GNU Regular Expression Compiling. -* re_pattern_buffer definition: GNU Pattern Buffers. -* re_registers: Using Registers. -* re_syntax_options initialization: GNU Regular Expression Compiling. -* RE_UNMATCHED_RIGHT_PAREN_ORD: Syntax Bits. -* searching with GNU functions: GNU Searching. -* start argument to re_search: GNU Searching. -* start in struct re_registers: Using Registers. -* struct re_pattern_buffer definition: GNU Pattern Buffers. -* subexpressions: Grouping Operators. -* syntax field, set by re_compile_pattern: GNU Regular Expression Compiling. -* syntax bits: Syntax Bits. -* syntax initialization: GNU Regular Expression Compiling. -* syntax of regular expressions: Regular Expression Syntax. -* translate initialization: GNU Regular Expression Compiling. -* used field, set by re_compile_pattern: GNU Regular Expression Compiling. -* word boundaries, matching: Match-word-boundary Operator. -* \: The Backslash Character. -* \(: Grouping Operators. -* \): Grouping Operators. -* \|: Alternation Operator. -* ^: Match-beginning-of-line Operator. -* |: Alternation Operator. - - - -Tag Table: -Node: Top1064 -Node: Overview4562 -Node: Regular Expression Syntax6746 -Node: Syntax Bits7916 -Node: Predefined Syntaxes14018 -Node: Collating Elements vs. Characters17872 -Node: The Backslash Character18835 -Node: Common Operators21992 -Node: Match-self Operator23445 -Node: Match-any-character Operator23941 -Node: Concatenation Operator24520 -Node: Repetition Operators25017 -Node: Match-zero-or-more Operator25436 -Node: Match-one-or-more Operator27483 -Node: Match-zero-or-one Operator28341 -Node: Interval Operators29196 -Node: Alternation Operator30991 -Node: List Operators32489 -Node: Character Class Operators35272 -Node: Range Operator36901 -Node: Grouping Operators38930 -Node: Back-reference Operator40251 -Node: Anchoring Operators43073 -Node: Match-beginning-of-line Operator43447 -Node: Match-end-of-line Operator44779 -Node: GNU Operators45518 -Node: Word Operators45767 -Node: Non-Emacs Syntax Tables46391 -Node: Match-word-boundary Operator47465 -Node: Match-within-word Operator47858 -Node: Match-beginning-of-word Operator48255 -Node: Match-end-of-word Operator48588 -Node: Match-word-constituent Operator48908 -Node: Match-non-word-constituent Operator49234 -Node: Buffer Operators49545 -Node: Match-beginning-of-buffer Operator49952 -Node: Match-end-of-buffer Operator50264 -Node: GNU Emacs Operators50558 -Node: Syntactic Class Operators50901 -Node: Emacs Syntax Tables51307 -Node: Match-syntactic-class Operator51963 -Node: Match-not-syntactic-class Operator52560 -Node: What Gets Matched?53150 -Node: Programming with Regex53799 -Node: GNU Regex Functions54237 -Node: GNU Pattern Buffers55078 -Node: GNU Regular Expression Compiling58303 -Node: GNU Matching61181 -Node: GNU Searching63101 -Node: Matching/Searching with Split Data64913 -Node: Searching with Fastmaps66369 -Node: GNU Translate Tables68921 -Node: Using Registers70892 -Node: Freeing GNU Pattern Buffers77000 -Node: POSIX Regex Functions77593 -Node: POSIX Pattern Buffers78266 -Node: POSIX Regular Expression Compiling78709 -Node: POSIX Matching82836 -Node: Reporting Errors84791 -Node: Using Byte Offsets86048 -Node: Freeing POSIX Pattern Buffers86861 -Node: BSD Regex Functions87467 -Node: BSD Regular Expression Compiling87886 -Node: BSD Searching89258 -Node: Copying89960 -Node: Index109122 - -End Tag Table diff --git a/gnu/lib/libregex/doc/regex.texi b/gnu/lib/libregex/doc/regex.texi deleted file mode 100644 index d93953e..0000000 --- a/gnu/lib/libregex/doc/regex.texi +++ /dev/null @@ -1,3138 +0,0 @@ -\input texinfo -@c %**start of header -@setfilename regex.info -@settitle Regex -@c %**end of header - -@c \\{fill-paragraph} works better (for me, anyway) if the text in the -@c source file isn't indented. -@paragraphindent 2 - -@c Define a new index for our magic constants. -@defcodeindex cn - -@c Put everything in one index (arbitrarily chosen to be the concept index). -@syncodeindex cn cp -@syncodeindex ky cp -@syncodeindex pg cp -@syncodeindex tp cp -@syncodeindex vr cp - -@c Here is what we use in the Info `dir' file: -@c * Regex: (regex). Regular expression library. - - -@ifinfo -This file documents the GNU regular expression library. - -Copyright (C) 1992, 1993 Free Software Foundation, Inc. - -Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - -@ignore -Permission is granted to process this file through TeX and print the -results, provided the printed document carries a copying permission -notice identical to this one except for the removal of this paragraph -(this paragraph not being relevant to the printed manual). -@end ignore - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that the -section entitled ``GNU General Public License'' is included exactly as -in the original, and provided that the entire resulting derived work is -distributed under the terms of a permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that the section entitled ``GNU General Public License'' may be -included in a translation approved by the Free Software Foundation -instead of in the original English. -@end ifinfo - - -@titlepage - -@title Regex -@subtitle edition 0.12a -@subtitle 19 September 1992 -@author Kathryn A. Hargreaves -@author Karl Berry - -@page - -@vskip 0pt plus 1filll -Copyright @copyright{} 1992 Free Software Foundation. - -Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that the -section entitled ``GNU General Public License'' is included exactly as -in the original, and provided that the entire resulting derived work is -distributed under the terms of a permission notice identical to this -one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that the section entitled ``GNU General Public License'' may be -included in a translation approved by the Free Software Foundation -instead of in the original English. - -@end titlepage - - -@ifinfo -@node Top, Overview, (dir), (dir) -@top Regular Expression Library - -This manual documents how to program with the GNU regular expression -library. This is edition 0.12a of the manual, 19 September 1992. - -The first part of this master menu lists the major nodes in this Info -document, including the index. The rest of the menu lists all the -lower level nodes in the document. - -@menu -* Overview:: -* Regular Expression Syntax:: -* Common Operators:: -* GNU Operators:: -* GNU Emacs Operators:: -* What Gets Matched?:: -* Programming with Regex:: -* Copying:: Copying and sharing Regex. -* Index:: General index. - --- The Detailed Node Listing --- - -Regular Expression Syntax - -* Syntax Bits:: -* Predefined Syntaxes:: -* Collating Elements vs. Characters:: -* The Backslash Character:: - -Common Operators - -* Match-self Operator:: Ordinary characters. -* Match-any-character Operator:: . -* Concatenation Operator:: Juxtaposition. -* Repetition Operators:: * + ? @{@} -* Alternation Operator:: | -* List Operators:: [...] [^...] -* Grouping Operators:: (...) -* Back-reference Operator:: \digit -* Anchoring Operators:: ^ $ - -Repetition Operators - -* Match-zero-or-more Operator:: * -* Match-one-or-more Operator:: + -* Match-zero-or-one Operator:: ? -* Interval Operators:: @{@} - -List Operators (@code{[} @dots{} @code{]} and @code{[^} @dots{} @code{]}) - -* Character Class Operators:: [:class:] -* Range Operator:: start-end - -Anchoring Operators - -* Match-beginning-of-line Operator:: ^ -* Match-end-of-line Operator:: $ - -GNU Operators - -* Word Operators:: -* Buffer Operators:: - -Word Operators - -* Non-Emacs Syntax Tables:: -* Match-word-boundary Operator:: \b -* Match-within-word Operator:: \B -* Match-beginning-of-word Operator:: \< -* Match-end-of-word Operator:: \> -* Match-word-constituent Operator:: \w -* Match-non-word-constituent Operator:: \W - -Buffer Operators - -* Match-beginning-of-buffer Operator:: \` -* Match-end-of-buffer Operator:: \' - -GNU Emacs Operators - -* Syntactic Class Operators:: - -Syntactic Class Operators - -* Emacs Syntax Tables:: -* Match-syntactic-class Operator:: \sCLASS -* Match-not-syntactic-class Operator:: \SCLASS - -Programming with Regex - -* GNU Regex Functions:: -* POSIX Regex Functions:: -* BSD Regex Functions:: - -GNU Regex Functions - -* GNU Pattern Buffers:: The re_pattern_buffer type. -* GNU Regular Expression Compiling:: re_compile_pattern () -* GNU Matching:: re_match () -* GNU Searching:: re_search () -* Matching/Searching with Split Data:: re_match_2 (), re_search_2 () -* Searching with Fastmaps:: re_compile_fastmap () -* GNU Translate Tables:: The `translate' field. -* Using Registers:: The re_registers type and related fns. -* Freeing GNU Pattern Buffers:: regfree () - -POSIX Regex Functions - -* POSIX Pattern Buffers:: The regex_t type. -* POSIX Regular Expression Compiling:: regcomp () -* POSIX Matching:: regexec () -* Reporting Errors:: regerror () -* Using Byte Offsets:: The regmatch_t type. -* Freeing POSIX Pattern Buffers:: regfree () - -BSD Regex Functions - -* BSD Regular Expression Compiling:: re_comp () -* BSD Searching:: re_exec () -@end menu -@end ifinfo -@node Overview, Regular Expression Syntax, Top, Top -@chapter Overview - -A @dfn{regular expression} (or @dfn{regexp}, or @dfn{pattern}) is a text -string that describes some (mathematical) set of strings. A regexp -@var{r} @dfn{matches} a string @var{s} if @var{s} is in the set of -strings described by @var{r}. - -Using the Regex library, you can: - -@itemize @bullet - -@item -see if a string matches a specified pattern as a whole, and - -@item -search within a string for a substring matching a specified pattern. - -@end itemize - -Some regular expressions match only one string, i.e., the set they -describe has only one member. For example, the regular expression -@samp{foo} matches the string @samp{foo} and no others. Other regular -expressions match more than one string, i.e., the set they describe has -more than one member. For example, the regular expression @samp{f*} -matches the set of strings made up of any number (including zero) of -@samp{f}s. As you can see, some characters in regular expressions match -themselves (such as @samp{f}) and some don't (such as @samp{*}); the -ones that don't match themselves instead let you specify patterns that -describe many different strings. - -To either match or search for a regular expression with the Regex -library functions, you must first compile it with a Regex pattern -compiling function. A @dfn{compiled pattern} is a regular expression -converted to the internal format used by the library functions. Once -you've compiled a pattern, you can use it for matching or searching any -number of times. - -The Regex library consists of two source files: @file{regex.h} and -@file{regex.c}. -@pindex regex.h -@pindex regex.c -Regex provides three groups of functions with which you can operate on -regular expressions. One group---the @sc{gnu} group---is more powerful -but not completely compatible with the other two, namely the @sc{posix} -and Berkeley @sc{unix} groups; its interface was designed specifically -for @sc{gnu}. The other groups have the same interfaces as do the -regular expression functions in @sc{posix} and Berkeley -@sc{unix}. - -We wrote this chapter with programmers in mind, not users of -programs---such as Emacs---that use Regex. We describe the Regex -library in its entirety, not how to write regular expressions that a -particular program understands. - - -@node Regular Expression Syntax, Common Operators, Overview, Top -@chapter Regular Expression Syntax - -@cindex regular expressions, syntax of -@cindex syntax of regular expressions - -@dfn{Characters} are things you can type. @dfn{Operators} are things in -a regular expression that match one or more characters. You compose -regular expressions from operators, which in turn you specify using one -or more characters. - -Most characters represent what we call the match-self operator, i.e., -they match themselves; we call these characters @dfn{ordinary}. Other -characters represent either all or parts of fancier operators; e.g., -@samp{.} represents what we call the match-any-character operator -(which, no surprise, matches (almost) any character); we call these -characters @dfn{special}. Two different things determine what -characters represent what operators: - -@enumerate -@item -the regular expression syntax your program has told the Regex library to -recognize, and - -@item -the context of the character in the regular expression. -@end enumerate - -In the following sections, we describe these things in more detail. - -@menu -* Syntax Bits:: -* Predefined Syntaxes:: -* Collating Elements vs. Characters:: -* The Backslash Character:: -@end menu - - -@node Syntax Bits, Predefined Syntaxes, , Regular Expression Syntax -@section Syntax Bits - -@cindex syntax bits - -In any particular syntax for regular expressions, some characters are -always special, others are sometimes special, and others are never -special. The particular syntax that Regex recognizes for a given -regular expression depends on the value in the @code{syntax} field of -the pattern buffer of that regular expression. - -You get a pattern buffer by compiling a regular expression. @xref{GNU -Pattern Buffers}, and @ref{POSIX Pattern Buffers}, for more information -on pattern buffers. @xref{GNU Regular Expression Compiling}, @ref{POSIX -Regular Expression Compiling}, and @ref{BSD Regular Expression -Compiling}, for more information on compiling. - -Regex considers the value of the @code{syntax} field to be a collection -of bits; we refer to these bits as @dfn{syntax bits}. In most cases, -they affect what characters represent what operators. We describe the -meanings of the operators to which we refer in @ref{Common Operators}, -@ref{GNU Operators}, and @ref{GNU Emacs Operators}. - -For reference, here is the complete list of syntax bits, in alphabetical -order: - -@table @code - -@cnindex RE_BACKSLASH_ESCAPE_IN_LIST -@item RE_BACKSLASH_ESCAPE_IN_LISTS -If this bit is set, then @samp{\} inside a list (@pxref{List Operators} -quotes (makes ordinary, if it's special) the following character; if -this bit isn't set, then @samp{\} is an ordinary character inside lists. -(@xref{The Backslash Character}, for what `\' does outside of lists.) - -@cnindex RE_BK_PLUS_QM -@item RE_BK_PLUS_QM -If this bit is set, then @samp{\+} represents the match-one-or-more -operator and @samp{\?} represents the match-zero-or-more operator; if -this bit isn't set, then @samp{+} represents the match-one-or-more -operator and @samp{?} represents the match-zero-or-one operator. This -bit is irrelevant if @code{RE_LIMITED_OPS} is set. - -@cnindex RE_CHAR_CLASSES -@item RE_CHAR_CLASSES -If this bit is set, then you can use character classes in lists; if this -bit isn't set, then you can't. - -@cnindex RE_CONTEXT_INDEP_ANCHORS -@item RE_CONTEXT_INDEP_ANCHORS -If this bit is set, then @samp{^} and @samp{$} are special anywhere outside -a list; if this bit isn't set, then these characters are special only in -certain contexts. @xref{Match-beginning-of-line Operator}, and -@ref{Match-end-of-line Operator}. - -@cnindex RE_CONTEXT_INDEP_OPS -@item RE_CONTEXT_INDEP_OPS -If this bit is set, then certain characters are special anywhere outside -a list; if this bit isn't set, then those characters are special only in -some contexts and are ordinary elsewhere. Specifically, if this bit -isn't set then @samp{*}, and (if the syntax bit @code{RE_LIMITED_OPS} -isn't set) @samp{+} and @samp{?} (or @samp{\+} and @samp{\?}, depending -on the syntax bit @code{RE_BK_PLUS_QM}) represent repetition operators -only if they're not first in a regular expression or just after an -open-group or alternation operator. The same holds for @samp{@{} (or -@samp{\@{}, depending on the syntax bit @code{RE_NO_BK_BRACES}) if -it is the beginning of a valid interval and the syntax bit -@code{RE_INTERVALS} is set. - -@cnindex RE_CONTEXT_INVALID_OPS -@item RE_CONTEXT_INVALID_OPS -If this bit is set, then repetition and alternation operators can't be -in certain positions within a regular expression. Specifically, the -regular expression is invalid if it has: - -@itemize @bullet - -@item -a repetition operator first in the regular expression or just after a -match-beginning-of-line, open-group, or alternation operator; or - -@item -an alternation operator first or last in the regular expression, just -before a match-end-of-line operator, or just after an alternation or -open-group operator. - -@end itemize - -If this bit isn't set, then you can put the characters representing the -repetition and alternation characters anywhere in a regular expression. -Whether or not they will in fact be operators in certain positions -depends on other syntax bits. - -@cnindex RE_DOT_NEWLINE -@item RE_DOT_NEWLINE -If this bit is set, then the match-any-character operator matches -a newline; if this bit isn't set, then it doesn't. - -@cnindex RE_DOT_NOT_NULL -@item RE_DOT_NOT_NULL -If this bit is set, then the match-any-character operator doesn't match -a null character; if this bit isn't set, then it does. - -@cnindex RE_INTERVALS -@item RE_INTERVALS -If this bit is set, then Regex recognizes interval operators; if this bit -isn't set, then it doesn't. - -@cnindex RE_LIMITED_OPS -@item RE_LIMITED_OPS -If this bit is set, then Regex doesn't recognize the match-one-or-more, -match-zero-or-one or alternation operators; if this bit isn't set, then -it does. - -@cnindex RE_NEWLINE_ALT -@item RE_NEWLINE_ALT -If this bit is set, then newline represents the alternation operator; if -this bit isn't set, then newline is ordinary. - -@cnindex RE_NO_BK_BRACES -@item RE_NO_BK_BRACES -If this bit is set, then @samp{@{} represents the open-interval operator -and @samp{@}} represents the close-interval operator; if this bit isn't -set, then @samp{\@{} represents the open-interval operator and -@samp{\@}} represents the close-interval operator. This bit is relevant -only if @code{RE_INTERVALS} is set. - -@cnindex RE_NO_BK_PARENS -@item RE_NO_BK_PARENS -If this bit is set, then @samp{(} represents the open-group operator and -@samp{)} represents the close-group operator; if this bit isn't set, then -@samp{\(} represents the open-group operator and @samp{\)} represents -the close-group operator. - -@cnindex RE_NO_BK_REFS -@item RE_NO_BK_REFS -If this bit is set, then Regex doesn't recognize @samp{\}@var{digit} as -the back reference operator; if this bit isn't set, then it does. - -@cnindex RE_NO_BK_VBAR -@item RE_NO_BK_VBAR -If this bit is set, then @samp{|} represents the alternation operator; -if this bit isn't set, then @samp{\|} represents the alternation -operator. This bit is irrelevant if @code{RE_LIMITED_OPS} is set. - -@cnindex RE_NO_EMPTY_RANGES -@item RE_NO_EMPTY_RANGES -If this bit is set, then a regular expression with a range whose ending -point collates lower than its starting point is invalid; if this bit -isn't set, then Regex considers such a range to be empty. - -@cnindex RE_UNMATCHED_RIGHT_PAREN_ORD -@item RE_UNMATCHED_RIGHT_PAREN_ORD -If this bit is set and the regular expression has no matching open-group -operator, then Regex considers what would otherwise be a close-group -operator (based on how @code{RE_NO_BK_PARENS} is set) to match @samp{)}. - -@end table - - -@node Predefined Syntaxes, Collating Elements vs. Characters, Syntax Bits, Regular Expression Syntax -@section Predefined Syntaxes - -If you're programming with Regex, you can set a pattern buffer's -(@pxref{GNU Pattern Buffers}, and @ref{POSIX Pattern Buffers}) -@code{syntax} field either to an arbitrary combination of syntax bits -(@pxref{Syntax Bits}) or else to the configurations defined by Regex. -These configurations define the syntaxes used by certain -programs---@sc{gnu} Emacs, -@cindex Emacs -@sc{posix} Awk, -@cindex POSIX Awk -traditional Awk, -@cindex Awk -Grep, -@cindex Grep -@cindex Egrep -Egrep---in addition to syntaxes for @sc{posix} basic and extended -regular expressions. - -The predefined syntaxes--taken directly from @file{regex.h}---are: - -@example -#define RE_SYNTAX_EMACS 0 - -#define RE_SYNTAX_AWK \ - (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - -#define RE_SYNTAX_POSIX_AWK \ - (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS) - -#define RE_SYNTAX_GREP \ - (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ - | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ - | RE_NEWLINE_ALT) - -#define RE_SYNTAX_EGREP \ - (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ - | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ - | RE_NO_BK_VBAR) - -#define RE_SYNTAX_POSIX_EGREP \ - (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES) - -/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ -#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC - -#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC - -/* Syntax bits common to both basic and extended POSIX regex syntax. */ -#define _RE_SYNTAX_POSIX_COMMON \ - (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ - | RE_INTERVALS | RE_NO_EMPTY_RANGES) - -#define RE_SYNTAX_POSIX_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) - -/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes - RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this - isn't minimal, since other operators, such as \`, aren't disabled. */ -#define RE_SYNTAX_POSIX_MINIMAL_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) - -#define RE_SYNTAX_POSIX_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - -/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS - replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */ -#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) -@end example - -@node Collating Elements vs. Characters, The Backslash Character, Predefined Syntaxes, Regular Expression Syntax -@section Collating Elements vs.@: Characters - -@sc{posix} generalizes the notion of a character to that of a -collating element. It defines a @dfn{collating element} to be ``a -sequence of one or more bytes defined in the current collating sequence -as a unit of collation.'' - -This generalizes the notion of a character in -two ways. First, a single character can map into two or more collating -elements. For example, the German -@tex -`\ss' -@end tex -@ifinfo -``es-zet'' -@end ifinfo -collates as the collating element @samp{s} followed by another collating -element @samp{s}. Second, two or more characters can map into one -collating element. For example, the Spanish @samp{ll} collates after -@samp{l} and before @samp{m}. - -Since @sc{posix}'s ``collating element'' preserves the essential idea of -a ``character,'' we use the latter, more familiar, term in this document. - -@node The Backslash Character, , Collating Elements vs. Characters, Regular Expression Syntax -@section The Backslash Character - -@cindex \ -The @samp{\} character has one of four different meanings, depending on -the context in which you use it and what syntax bits are set -(@pxref{Syntax Bits}). It can: 1) stand for itself, 2) quote the next -character, 3) introduce an operator, or 4) do nothing. - -@enumerate -@item -It stands for itself inside a list -(@pxref{List Operators}) if the syntax bit -@code{RE_BACKSLASH_ESCAPE_IN_LISTS} is not set. For example, @samp{[\]} -would match @samp{\}. - -@item -It quotes (makes ordinary, if it's special) the next character when you -use it either: - -@itemize @bullet -@item -outside a list,@footnote{Sometimes -you don't have to explicitly quote special characters to make -them ordinary. For instance, most characters lose any special meaning -inside a list (@pxref{List Operators}). In addition, if the syntax bits -@code{RE_CONTEXT_INVALID_OPS} and @code{RE_CONTEXT_INDEP_OPS} -aren't set, then (for historical reasons) the matcher considers special -characters ordinary if they are in contexts where the operations they -represent make no sense; for example, then the match-zero-or-more -operator (represented by @samp{*}) matches itself in the regular -expression @samp{*foo} because there is no preceding expression on which -it can operate. It is poor practice, however, to depend on this -behavior; if you want a special character to be ordinary outside a list, -it's better to always quote it, regardless.} or - -@item -inside a list and the syntax bit @code{RE_BACKSLASH_ESCAPE_IN_LISTS} is set. - -@end itemize - -@item -It introduces an operator when followed by certain ordinary -characters---sometimes only when certain syntax bits are set. See the -cases @code{RE_BK_PLUS_QM}, @code{RE_NO_BK_BRACES}, @code{RE_NO_BK_VAR}, -@code{RE_NO_BK_PARENS}, @code{RE_NO_BK_REF} in @ref{Syntax Bits}. Also: - -@itemize @bullet -@item -@samp{\b} represents the match-word-boundary operator -(@pxref{Match-word-boundary Operator}). - -@item -@samp{\B} represents the match-within-word operator -(@pxref{Match-within-word Operator}). - -@item -@samp{\<} represents the match-beginning-of-word operator @* -(@pxref{Match-beginning-of-word Operator}). - -@item -@samp{\>} represents the match-end-of-word operator -(@pxref{Match-end-of-word Operator}). - -@item -@samp{\w} represents the match-word-constituent operator -(@pxref{Match-word-constituent Operator}). - -@item -@samp{\W} represents the match-non-word-constituent operator -(@pxref{Match-non-word-constituent Operator}). - -@item -@samp{\`} represents the match-beginning-of-buffer -operator and @samp{\'} represents the match-end-of-buffer operator -(@pxref{Buffer Operators}). - -@item -If Regex was compiled with the C preprocessor symbol @code{emacs} -defined, then @samp{\s@var{class}} represents the match-syntactic-class -operator and @samp{\S@var{class}} represents the -match-not-syntactic-class operator (@pxref{Syntactic Class Operators}). - -@end itemize - -@item -In all other cases, Regex ignores @samp{\}. For example, -@samp{\n} matches @samp{n}. - -@end enumerate - -@node Common Operators, GNU Operators, Regular Expression Syntax, Top -@chapter Common Operators - -You compose regular expressions from operators. In the following -sections, we describe the regular expression operators specified by -@sc{posix}; @sc{gnu} also uses these. Most operators have more than one -representation as characters. @xref{Regular Expression Syntax}, for -what characters represent what operators under what circumstances. - -For most operators that can be represented in two ways, one -representation is a single character and the other is that character -preceded by @samp{\}. For example, either @samp{(} or @samp{\(} -represents the open-group operator. Which one does depends on the -setting of a syntax bit, in this case @code{RE_NO_BK_PARENS}. Why is -this so? Historical reasons dictate some of the varying -representations, while @sc{posix} dictates others. - -Finally, almost all characters lose any special meaning inside a list -(@pxref{List Operators}). - -@menu -* Match-self Operator:: Ordinary characters. -* Match-any-character Operator:: . -* Concatenation Operator:: Juxtaposition. -* Repetition Operators:: * + ? @{@} -* Alternation Operator:: | -* List Operators:: [...] [^...] -* Grouping Operators:: (...) -* Back-reference Operator:: \digit -* Anchoring Operators:: ^ $ -@end menu - -@node Match-self Operator, Match-any-character Operator, , Common Operators -@section The Match-self Operator (@var{ordinary character}) - -This operator matches the character itself. All ordinary characters -(@pxref{Regular Expression Syntax}) represent this operator. For -example, @samp{f} is always an ordinary character, so the regular -expression @samp{f} matches only the string @samp{f}. In -particular, it does @emph{not} match the string @samp{ff}. - -@node Match-any-character Operator, Concatenation Operator, Match-self Operator, Common Operators -@section The Match-any-character Operator (@code{.}) - -@cindex @samp{.} - -This operator matches any single printing or nonprinting character -except it won't match a: - -@table @asis -@item newline -if the syntax bit @code{RE_DOT_NEWLINE} isn't set. - -@item null -if the syntax bit @code{RE_DOT_NOT_NULL} is set. - -@end table - -The @samp{.} (period) character represents this operator. For example, -@samp{a.b} matches any three-character string beginning with @samp{a} -and ending with @samp{b}. - -@node Concatenation Operator, Repetition Operators, Match-any-character Operator, Common Operators -@section The Concatenation Operator - -This operator concatenates two regular expressions @var{a} and @var{b}. -No character represents this operator; you simply put @var{b} after -@var{a}. The result is a regular expression that will match a string if -@var{a} matches its first part and @var{b} matches the rest. For -example, @samp{xy} (two match-self operators) matches @samp{xy}. - -@node Repetition Operators, Alternation Operator, Concatenation Operator, Common Operators -@section Repetition Operators - -Repetition operators repeat the preceding regular expression a specified -number of times. - -@menu -* Match-zero-or-more Operator:: * -* Match-one-or-more Operator:: + -* Match-zero-or-one Operator:: ? -* Interval Operators:: @{@} -@end menu - -@node Match-zero-or-more Operator, Match-one-or-more Operator, , Repetition Operators -@subsection The Match-zero-or-more Operator (@code{*}) - -@cindex @samp{*} - -This operator repeats the smallest possible preceding regular expression -as many times as necessary (including zero) to match the pattern. -@samp{*} represents this operator. For example, @samp{o*} -matches any string made up of zero or more @samp{o}s. Since this -operator operates on the smallest preceding regular expression, -@samp{fo*} has a repeating @samp{o}, not a repeating @samp{fo}. So, -@samp{fo*} matches @samp{f}, @samp{fo}, @samp{foo}, and so on. - -Since the match-zero-or-more operator is a suffix operator, it may be -useless as such when no regular expression precedes it. This is the -case when it: - -@itemize @bullet -@item -is first in a regular expression, or - -@item -follows a match-beginning-of-line, open-group, or alternation -operator. - -@end itemize - -@noindent -Three different things can happen in these cases: - -@enumerate -@item -If the syntax bit @code{RE_CONTEXT_INVALID_OPS} is set, then the -regular expression is invalid. - -@item -If @code{RE_CONTEXT_INVALID_OPS} isn't set, but -@code{RE_CONTEXT_INDEP_OPS} is, then @samp{*} represents the -match-zero-or-more operator (which then operates on the empty string). - -@item -Otherwise, @samp{*} is ordinary. - -@end enumerate - -@cindex backtracking -The matcher processes a match-zero-or-more operator by first matching as -many repetitions of the smallest preceding regular expression as it can. -Then it continues to match the rest of the pattern. - -If it can't match the rest of the pattern, it backtracks (as many times -as necessary), each time discarding one of the matches until it can -either match the entire pattern or be certain that it cannot get a -match. For example, when matching @samp{ca*ar} against @samp{caaar}, -the matcher first matches all three @samp{a}s of the string with the -@samp{a*} of the regular expression. However, it cannot then match the -final @samp{ar} of the regular expression against the final @samp{r} of -the string. So it backtracks, discarding the match of the last @samp{a} -in the string. It can then match the remaining @samp{ar}. - - -@node Match-one-or-more Operator, Match-zero-or-one Operator, Match-zero-or-more Operator, Repetition Operators -@subsection The Match-one-or-more Operator (@code{+} or @code{\+}) - -@cindex @samp{+} - -If the syntax bit @code{RE_LIMITED_OPS} is set, then Regex doesn't recognize -this operator. Otherwise, if the syntax bit @code{RE_BK_PLUS_QM} isn't -set, then @samp{+} represents this operator; if it is, then @samp{\+} -does. - -This operator is similar to the match-zero-or-more operator except that -it repeats the preceding regular expression at least once; -@pxref{Match-zero-or-more Operator}, for what it operates on, how some -syntax bits affect it, and how Regex backtracks to match it. - -For example, supposing that @samp{+} represents the match-one-or-more -operator; then @samp{ca+r} matches, e.g., @samp{car} and -@samp{caaaar}, but not @samp{cr}. - -@node Match-zero-or-one Operator, Interval Operators, Match-one-or-more Operator, Repetition Operators -@subsection The Match-zero-or-one Operator (@code{?} or @code{\?}) -@cindex @samp{?} - -If the syntax bit @code{RE_LIMITED_OPS} is set, then Regex doesn't -recognize this operator. Otherwise, if the syntax bit -@code{RE_BK_PLUS_QM} isn't set, then @samp{?} represents this operator; -if it is, then @samp{\?} does. - -This operator is similar to the match-zero-or-more operator except that -it repeats the preceding regular expression once or not at all; -@pxref{Match-zero-or-more Operator}, to see what it operates on, how -some syntax bits affect it, and how Regex backtracks to match it. - -For example, supposing that @samp{?} represents the match-zero-or-one -operator; then @samp{ca?r} matches both @samp{car} and @samp{cr}, but -nothing else. - -@node Interval Operators, , Match-zero-or-one Operator, Repetition Operators -@subsection Interval Operators (@code{@{} @dots{} @code{@}} or @code{\@{} @dots{} @code{\@}}) - -@cindex interval expression -@cindex @samp{@{} -@cindex @samp{@}} -@cindex @samp{\@{} -@cindex @samp{\@}} - -If the syntax bit @code{RE_INTERVALS} is set, then Regex recognizes -@dfn{interval expressions}. They repeat the smallest possible preceding -regular expression a specified number of times. - -If the syntax bit @code{RE_NO_BK_BRACES} is set, @samp{@{} represents -the @dfn{open-interval operator} and @samp{@}} represents the -@dfn{close-interval operator} ; otherwise, @samp{\@{} and @samp{\@}} do. - -Specifically, supposing that @samp{@{} and @samp{@}} represent the -open-interval and close-interval operators; then: - -@table @code -@item @{@var{count}@} -matches exactly @var{count} occurrences of the preceding regular -expression. - -@item @{@var{min,}@} -matches @var{min} or more occurrences of the preceding regular -expression. - -@item @{@var{min, max}@} -matches at least @var{min} but no more than @var{max} occurrences of -the preceding regular expression. - -@end table - -The interval expression (but not necessarily the regular expression that -contains it) is invalid if: - -@itemize @bullet -@item -@var{min} is greater than @var{max}, or - -@item -any of @var{count}, @var{min}, or @var{max} are outside the range -zero to @code{RE_DUP_MAX} (which symbol @file{regex.h} -defines). - -@end itemize - -If the interval expression is invalid and the syntax bit -@code{RE_NO_BK_BRACES} is set, then Regex considers all the -characters in the would-be interval to be ordinary. If that bit -isn't set, then the regular expression is invalid. - -If the interval expression is valid but there is no preceding regular -expression on which to operate, then if the syntax bit -@code{RE_CONTEXT_INVALID_OPS} is set, the regular expression is invalid. -If that bit isn't set, then Regex considers all the characters---other -than backslashes, which it ignores---in the would-be interval to be -ordinary. - - -@node Alternation Operator, List Operators, Repetition Operators, Common Operators -@section The Alternation Operator (@code{|} or @code{\|}) - -@kindex | -@kindex \| -@cindex alternation operator -@cindex or operator - -If the syntax bit @code{RE_LIMITED_OPS} is set, then Regex doesn't -recognize this operator. Otherwise, if the syntax bit -@code{RE_NO_BK_VBAR} is set, then @samp{|} represents this operator; -otherwise, @samp{\|} does. - -Alternatives match one of a choice of regular expressions: -if you put the character(s) representing the alternation operator between -any two regular expressions @var{a} and @var{b}, the result matches -the union of the strings that @var{a} and @var{b} match. For -example, supposing that @samp{|} is the alternation operator, then -@samp{foo|bar|quux} would match any of @samp{foo}, @samp{bar} or -@samp{quux}. - -@ignore -@c Nobody needs to disallow empty alternatives any more. -If the syntax bit @code{RE_NO_EMPTY_ALTS} is set, then if either of the regular -expressions @var{a} or @var{b} is empty, the -regular expression is invalid. More precisely, if this syntax bit is -set, then the alternation operator can't: - -@itemize @bullet -@item -be first or last in a regular expression; - -@item -follow either another alternation operator or an open-group operator -(@pxref{Grouping Operators}); or - -@item -precede a close-group operator. - -@end itemize - -@noindent -For example, supposing @samp{(} and @samp{)} represent the open and -close-group operators, then @samp{|foo}, @samp{foo|}, @samp{foo||bar}, -@samp{foo(|bar)}, and @samp{(foo|)bar} would all be invalid. -@end ignore - -The alternation operator operates on the @emph{largest} possible -surrounding regular expressions. (Put another way, it has the lowest -precedence of any regular expression operator.) -Thus, the only way you can -delimit its arguments is to use grouping. For example, if @samp{(} and -@samp{)} are the open and close-group operators, then @samp{fo(o|b)ar} -would match either @samp{fooar} or @samp{fobar}. (@samp{foo|bar} would -match @samp{foo} or @samp{bar}.) - -@cindex backtracking -The matcher usually tries all combinations of alternatives so as to -match the longest possible string. For example, when matching -@samp{(fooq|foo)*(qbarquux|bar)} against @samp{fooqbarquux}, it cannot -take, say, the first (``depth-first'') combination it could match, since -then it would be content to match just @samp{fooqbar}. - -@comment xx something about leftmost-longest - - -@node List Operators, Grouping Operators, Alternation Operator, Common Operators -@section List Operators (@code{[} @dots{} @code{]} and @code{[^} @dots{} @code{]}) - -@cindex matching list -@cindex @samp{[} -@cindex @samp{]} -@cindex @samp{^} -@cindex @samp{-} -@cindex @samp{\} -@cindex @samp{[^} -@cindex nonmatching list -@cindex matching newline -@cindex bracket expression - -@dfn{Lists}, also called @dfn{bracket expressions}, are a set of one or -more items. An @dfn{item} is a character, -@ignore -(These get added when they get implemented.) -a collating symbol, an equivalence class expression, -@end ignore -a character class expression, or a range expression. The syntax bits -affect which kinds of items you can put in a list. We explain the last -two items in subsections below. Empty lists are invalid. - -A @dfn{matching list} matches a single character represented by one of -the list items. You form a matching list by enclosing one or more items -within an @dfn{open-matching-list operator} (represented by @samp{[}) -and a @dfn{close-list operator} (represented by @samp{]}). - -For example, @samp{[ab]} matches either @samp{a} or @samp{b}. -@samp{[ad]*} matches the empty string and any string composed of just -@samp{a}s and @samp{d}s in any order. Regex considers invalid a regular -expression with a @samp{[} but no matching -@samp{]}. - -@dfn{Nonmatching lists} are similar to matching lists except that they -match a single character @emph{not} represented by one of the list -items. You use an @dfn{open-nonmatching-list operator} (represented by -@samp{[^}@footnote{Regex therefore doesn't consider the @samp{^} to be -the first character in the list. If you put a @samp{^} character first -in (what you think is) a matching list, you'll turn it into a -nonmatching list.}) instead of an open-matching-list operator to start a -nonmatching list. - -For example, @samp{[^ab]} matches any character except @samp{a} or -@samp{b}. - -If the @code{posix_newline} field in the pattern buffer (@pxref{GNU -Pattern Buffers} is set, then nonmatching lists do not match a newline. - -Most characters lose any special meaning inside a list. The special -characters inside a list follow. - -@table @samp -@item ] -ends the list if it's not the first list item. So, if you want to make -the @samp{]} character a list item, you must put it first. - -@item \ -quotes the next character if the syntax bit @code{RE_BACKSLASH_ESCAPE_IN_LISTS} is -set. - -@ignore -Put these in if they get implemented. - -@item [. -represents the open-collating-symbol operator (@pxref{Collating Symbol -Operators}). - -@item .] -represents the close-collating-symbol operator. - -@item [= -represents the open-equivalence-class operator (@pxref{Equivalence Class -Operators}). - -@item =] -represents the close-equivalence-class operator. - -@end ignore - -@item [: -represents the open-character-class operator (@pxref{Character Class -Operators}) if the syntax bit @code{RE_CHAR_CLASSES} is set and what -follows is a valid character class expression. - -@item :] -represents the close-character-class operator if the syntax bit -@code{RE_CHAR_CLASSES} is set and what precedes it is an -open-character-class operator followed by a valid character class name. - -@item - -represents the range operator (@pxref{Range Operator}) if it's -not first or last in a list or the ending point of a range. - -@end table - -@noindent -All other characters are ordinary. For example, @samp{[.*]} matches -@samp{.} and @samp{*}. - -@menu -* Character Class Operators:: [:class:] -* Range Operator:: start-end -@end menu - -@ignore -(If collating symbols and equivalence class expressions get implemented, -then add this.) - -node Collating Symbol Operators -subsubsection Collating Symbol Operators (@code{[.} @dots{} @code{.]}) - -If the syntax bit @code{XX} is set, then you can represent -collating symbols inside lists. You form a @dfn{collating symbol} by -putting a collating element between an @dfn{open-collating-symbol -operator} and an @dfn{close-collating-symbol operator}. @samp{[.} -represents the open-collating-symbol operator and @samp{.]} represents -the close-collating-symbol operator. For example, if @samp{ll} is a -collating element, then @samp{[[.ll.]]} would match @samp{ll}. - -node Equivalence Class Operators -subsubsection Equivalence Class Operators (@code{[=} @dots{} @code{=]}) -@cindex equivalence class expression in regex -@cindex @samp{[=} in regex -@cindex @samp{=]} in regex - -If the syntax bit @code{XX} is set, then Regex recognizes equivalence class -expressions inside lists. A @dfn{equivalence class expression} is a set -of collating elements which all belong to the same equivalence class. -You form an equivalence class expression by putting a collating -element between an @dfn{open-equivalence-class operator} and a -@dfn{close-equivalence-class operator}. @samp{[=} represents the -open-equivalence-class operator and @samp{=]} represents the -close-equivalence-class operator. For example, if @samp{a} and @samp{A} -were an equivalence class, then both @samp{[[=a=]]} and @samp{[[=A=]]} -would match both @samp{a} and @samp{A}. If the collating element in an -equivalence class expression isn't part of an equivalence class, then -the matcher considers the equivalence class expression to be a collating -symbol. - -@end ignore - -@node Character Class Operators, Range Operator, , List Operators -@subsection Character Class Operators (@code{[:} @dots{} @code{:]}) - -@cindex character classes -@cindex @samp{[:} in regex -@cindex @samp{:]} in regex - -If the syntax bit @code{RE_CHARACTER_CLASSES} is set, then Regex -recognizes character class expressions inside lists. A @dfn{character -class expression} matches one character from a given class. You form a -character class expression by putting a character class name between an -@dfn{open-character-class operator} (represented by @samp{[:}) and a -@dfn{close-character-class operator} (represented by @samp{:]}). The -character class names and their meanings are: - -@table @code - -@item alnum -letters and digits - -@item alpha -letters - -@item blank -system-dependent; for @sc{gnu}, a space or tab - -@item cntrl -control characters (in the @sc{ascii} encoding, code 0177 and codes -less than 040) - -@item digit -digits - -@item graph -same as @code{print} except omits space - -@item lower -lowercase letters - -@item print -printable characters (in the @sc{ascii} encoding, space -tilde---codes 040 through 0176) - -@item punct -neither control nor alphanumeric characters - -@item space -space, carriage return, newline, vertical tab, and form feed - -@item upper -uppercase letters - -@item xdigit -hexadecimal digits: @code{0}--@code{9}, @code{a}--@code{f}, @code{A}--@code{F} - -@end table - -@noindent -These correspond to the definitions in the C library's @file{} -facility. For example, @samp{[:alpha:]} corresponds to the standard -facility @code{isalpha}. Regex recognizes character class expressions -only inside of lists; so @samp{[[:alpha:]]} matches any letter, but -@samp{[:alpha:]} outside of a bracket expression and not followed by a -repetition operator matches just itself. - -@node Range Operator, , Character Class Operators, List Operators -@subsection The Range Operator (@code{-}) - -Regex recognizes @dfn{range expressions} inside a list. They represent -those characters -that fall between two elements in the current collating sequence. You -form a range expression by putting a @dfn{range operator} between two -@ignore -(If these get implemented, then substitute this for ``characters.'') -of any of the following: characters, collating elements, collating symbols, -and equivalence class expressions. The starting point of the range and -the ending point of the range don't have to be the same kind of item, -e.g., the starting point could be a collating element and the ending -point could be an equivalence class expression. If a range's ending -point is an equivalence class, then all the collating elements in that -class will be in the range. -@end ignore -characters.@footnote{You can't use a character class for the starting -or ending point of a range, since a character class is not a single -character.} @samp{-} represents the range operator. For example, -@samp{a-f} within a list represents all the characters from @samp{a} -through @samp{f} -inclusively. - -If the syntax bit @code{RE_NO_EMPTY_RANGES} is set, then if the range's -ending point collates less than its starting point, the range (and the -regular expression containing it) is invalid. For example, the regular -expression @samp{[z-a]} would be invalid. If this bit isn't set, then -Regex considers such a range to be empty. - -Since @samp{-} represents the range operator, if you want to make a -@samp{-} character itself -a list item, you must do one of the following: - -@itemize @bullet -@item -Put the @samp{-} either first or last in the list. - -@item -Include a range whose starting point collates strictly lower than -@samp{-} and whose ending point collates equal or higher. Unless a -range is the first item in a list, a @samp{-} can't be its starting -point, but @emph{can} be its ending point. That is because Regex -considers @samp{-} to be the range operator unless it is preceded by -another @samp{-}. For example, in the @sc{ascii} encoding, @samp{)}, -@samp{*}, @samp{+}, @samp{,}, @samp{-}, @samp{.}, and @samp{/} are -contiguous characters in the collating sequence. You might think that -@samp{[)-+--/]} has two ranges: @samp{)-+} and @samp{--/}. Rather, it -has the ranges @samp{)-+} and @samp{+--}, plus the character @samp{/}, so -it matches, e.g., @samp{,}, not @samp{.}. - -@item -Put a range whose starting point is @samp{-} first in the list. - -@end itemize - -For example, @samp{[-a-z]} matches a lowercase letter or a hyphen (in -English, in @sc{ascii}). - - -@node Grouping Operators, Back-reference Operator, List Operators, Common Operators -@section Grouping Operators (@code{(} @dots{} @code{)} or @code{\(} @dots{} @code{\)}) - -@kindex ( -@kindex ) -@kindex \( -@kindex \) -@cindex grouping -@cindex subexpressions -@cindex parenthesizing - -A @dfn{group}, also known as a @dfn{subexpression}, consists of an -@dfn{open-group operator}, any number of other operators, and a -@dfn{close-group operator}. Regex treats this sequence as a unit, just -as mathematics and programming languages treat a parenthesized -expression as a unit. - -Therefore, using @dfn{groups}, you can: - -@itemize @bullet -@item -delimit the argument(s) to an alternation operator (@pxref{Alternation -Operator}) or a repetition operator (@pxref{Repetition -Operators}). - -@item -keep track of the indices of the substring that matched a given group. -@xref{Using Registers}, for a precise explanation. -This lets you: - -@itemize @bullet -@item -use the back-reference operator (@pxref{Back-reference Operator}). - -@item -use registers (@pxref{Using Registers}). - -@end itemize - -@end itemize - -If the syntax bit @code{RE_NO_BK_PARENS} is set, then @samp{(} represents -the open-group operator and @samp{)} represents the -close-group operator; otherwise, @samp{\(} and @samp{\)} do. - -If the syntax bit @code{RE_UNMATCHED_RIGHT_PAREN_ORD} is set and a -close-group operator has no matching open-group operator, then Regex -considers it to match @samp{)}. - - -@node Back-reference Operator, Anchoring Operators, Grouping Operators, Common Operators -@section The Back-reference Operator (@dfn{\}@var{digit}) - -@cindex back references - -If the syntax bit @code{RE_NO_BK_REF} isn't set, then Regex recognizes -back references. A back reference matches a specified preceding group. -The back reference operator is represented by @samp{\@var{digit}} -anywhere after the end of a regular expression's @w{@var{digit}-th} -group (@pxref{Grouping Operators}). - -@var{digit} must be between @samp{1} and @samp{9}. The matcher assigns -numbers 1 through 9 to the first nine groups it encounters. By using -one of @samp{\1} through @samp{\9} after the corresponding group's -close-group operator, you can match a substring identical to the -one that the group does. - -Back references match according to the following (in all examples below, -@samp{(} represents the open-group, @samp{)} the close-group, @samp{@{} -the open-interval and @samp{@}} the close-interval operator): - -@itemize @bullet -@item -If the group matches a substring, the back reference matches an -identical substring. For example, @samp{(a)\1} matches @samp{aa} and -@samp{(bana)na\1bo\1} matches @samp{bananabanabobana}. Likewise, -@samp{(.*)\1} matches any (newline-free if the syntax bit -@code{RE_DOT_NEWLINE} isn't set) string that is composed of two -identical halves; the @samp{(.*)} matches the first half and the -@samp{\1} matches the second half. - -@item -If the group matches more than once (as it might if followed -by, e.g., a repetition operator), then the back reference matches the -substring the group @emph{last} matched. For example, -@samp{((a*)b)*\1\2} matches @samp{aabababa}; first @w{group 1} (the -outer one) matches @samp{aab} and @w{group 2} (the inner one) matches -@samp{aa}. Then @w{group 1} matches @samp{ab} and @w{group 2} matches -@samp{a}. So, @samp{\1} matches @samp{ab} and @samp{\2} matches -@samp{a}. - -@item -If the group doesn't participate in a match, i.e., it is part of an -alternative not taken or a repetition operator allows zero repetitions -of it, then the back reference makes the whole match fail. For example, -@samp{(one()|two())-and-(three\2|four\3)} matches @samp{one-and-three} -and @samp{two-and-four}, but not @samp{one-and-four} or -@samp{two-and-three}. For example, if the pattern matches -@samp{one-and-}, then its @w{group 2} matches the empty string and its -@w{group 3} doesn't participate in the match. So, if it then matches -@samp{four}, then when it tries to back reference @w{group 3}---which it -will attempt to do because @samp{\3} follows the @samp{four}---the match -will fail because @w{group 3} didn't participate in the match. - -@end itemize - -You can use a back reference as an argument to a repetition operator. For -example, @samp{(a(b))\2*} matches @samp{a} followed by two or more -@samp{b}s. Similarly, @samp{(a(b))\2@{3@}} matches @samp{abbbb}. - -If there is no preceding @w{@var{digit}-th} subexpression, the regular -expression is invalid. - - -@node Anchoring Operators, , Back-reference Operator, Common Operators -@section Anchoring Operators - -@cindex anchoring -@cindex regexp anchoring - -These operators can constrain a pattern to match only at the beginning or -end of the entire string or at the beginning or end of a line. - -@menu -* Match-beginning-of-line Operator:: ^ -* Match-end-of-line Operator:: $ -@end menu - - -@node Match-beginning-of-line Operator, Match-end-of-line Operator, , Anchoring Operators -@subsection The Match-beginning-of-line Operator (@code{^}) - -@kindex ^ -@cindex beginning-of-line operator -@cindex anchors - -This operator can match the empty string either at the beginning of the -string or after a newline character. Thus, it is said to @dfn{anchor} -the pattern to the beginning of a line. - -In the cases following, @samp{^} represents this operator. (Otherwise, -@samp{^} is ordinary.) - -@itemize @bullet - -@item -It (the @samp{^}) is first in the pattern, as in @samp{^foo}. - -@cnindex RE_CONTEXT_INDEP_ANCHORS @r{(and @samp{^})} -@item -The syntax bit @code{RE_CONTEXT_INDEP_ANCHORS} is set, and it is outside -a bracket expression. - -@cindex open-group operator and @samp{^} -@cindex alternation operator and @samp{^} -@item -It follows an open-group or alternation operator, as in @samp{a\(^b\)} -and @samp{a\|^b}. @xref{Grouping Operators}, and @ref{Alternation -Operator}. - -@end itemize - -These rules imply that some valid patterns containing @samp{^} cannot be -matched; for example, @samp{foo^bar} if @code{RE_CONTEXT_INDEP_ANCHORS} -is set. - -@vindex not_bol @r{field in pattern buffer} -If the @code{not_bol} field is set in the pattern buffer (@pxref{GNU -Pattern Buffers}), then @samp{^} fails to match at the beginning of the -string. @xref{POSIX Matching}, for when you might find this useful. - -@vindex newline_anchor @r{field in pattern buffer} -If the @code{newline_anchor} field is set in the pattern buffer, then -@samp{^} fails to match after a newline. This is useful when you do not -regard the string to be matched as broken into lines. - - -@node Match-end-of-line Operator, , Match-beginning-of-line Operator, Anchoring Operators -@subsection The Match-end-of-line Operator (@code{$}) - -@kindex $ -@cindex end-of-line operator -@cindex anchors - -This operator can match the empty string either at the end of -the string or before a newline character in the string. Thus, it is -said to @dfn{anchor} the pattern to the end of a line. - -It is always represented by @samp{$}. For example, @samp{foo$} usually -matches, e.g., @samp{foo} and, e.g., the first three characters of -@samp{foo\nbar}. - -Its interaction with the syntax bits and pattern buffer fields is -exactly the dual of @samp{^}'s; see the previous section. (That is, -``beginning'' becomes ``end'', ``next'' becomes ``previous'', and -``after'' becomes ``before''.) - - -@node GNU Operators, GNU Emacs Operators, Common Operators, Top -@chapter GNU Operators - -Following are operators that @sc{gnu} defines (and @sc{posix} doesn't). - -@menu -* Word Operators:: -* Buffer Operators:: -@end menu - -@node Word Operators, Buffer Operators, , GNU Operators -@section Word Operators - -The operators in this section require Regex to recognize parts of words. -Regex uses a syntax table to determine whether or not a character is -part of a word, i.e., whether or not it is @dfn{word-constituent}. - -@menu -* Non-Emacs Syntax Tables:: -* Match-word-boundary Operator:: \b -* Match-within-word Operator:: \B -* Match-beginning-of-word Operator:: \< -* Match-end-of-word Operator:: \> -* Match-word-constituent Operator:: \w -* Match-non-word-constituent Operator:: \W -@end menu - -@node Non-Emacs Syntax Tables, Match-word-boundary Operator, , Word Operators -@subsection Non-Emacs Syntax Tables - -A @dfn{syntax table} is an array indexed by the characters in your -character set. In the @sc{ascii} encoding, therefore, a syntax table -has 256 elements. Regex always uses a @code{char *} variable -@code{re_syntax_table} as its syntax table. In some cases, it -initializes this variable and in others it expects you to initialize it. - -@itemize @bullet -@item -If Regex is compiled with the preprocessor symbols @code{emacs} and -@code{SYNTAX_TABLE} both undefined, then Regex allocates -@code{re_syntax_table} and initializes an element @var{i} either to -@code{Sword} (which it defines) if @var{i} is a letter, number, or -@samp{_}, or to zero if it's not. - -@item -If Regex is compiled with @code{emacs} undefined but @code{SYNTAX_TABLE} -defined, then Regex expects you to define a @code{char *} variable -@code{re_syntax_table} to be a valid syntax table. - -@item -@xref{Emacs Syntax Tables}, for what happens when Regex is compiled with -the preprocessor symbol @code{emacs} defined. - -@end itemize - -@node Match-word-boundary Operator, Match-within-word Operator, Non-Emacs Syntax Tables, Word Operators -@subsection The Match-word-boundary Operator (@code{\b}) - -@cindex @samp{\b} -@cindex word boundaries, matching - -This operator (represented by @samp{\b}) matches the empty string at -either the beginning or the end of a word. For example, @samp{\brat\b} -matches the separate word @samp{rat}. - -@node Match-within-word Operator, Match-beginning-of-word Operator, Match-word-boundary Operator, Word Operators -@subsection The Match-within-word Operator (@code{\B}) - -@cindex @samp{\B} - -This operator (represented by @samp{\B}) matches the empty string within -a word. For example, @samp{c\Brat\Be} matches @samp{crate}, but -@samp{dirty \Brat} doesn't match @samp{dirty rat}. - -@node Match-beginning-of-word Operator, Match-end-of-word Operator, Match-within-word Operator, Word Operators -@subsection The Match-beginning-of-word Operator (@code{\<}) - -@cindex @samp{\<} - -This operator (represented by @samp{\<}) matches the empty string at the -beginning of a word. - -@node Match-end-of-word Operator, Match-word-constituent Operator, Match-beginning-of-word Operator, Word Operators -@subsection The Match-end-of-word Operator (@code{\>}) - -@cindex @samp{\>} - -This operator (represented by @samp{\>}) matches the empty string at the -end of a word. - -@node Match-word-constituent Operator, Match-non-word-constituent Operator, Match-end-of-word Operator, Word Operators -@subsection The Match-word-constituent Operator (@code{\w}) - -@cindex @samp{\w} - -This operator (represented by @samp{\w}) matches any word-constituent -character. - -@node Match-non-word-constituent Operator, , Match-word-constituent Operator, Word Operators -@subsection The Match-non-word-constituent Operator (@code{\W}) - -@cindex @samp{\W} - -This operator (represented by @samp{\W}) matches any character that is -not word-constituent. - - -@node Buffer Operators, , Word Operators, GNU Operators -@section Buffer Operators - -Following are operators which work on buffers. In Emacs, a @dfn{buffer} -is, naturally, an Emacs buffer. For other programs, Regex considers the -entire string to be matched as the buffer. - -@menu -* Match-beginning-of-buffer Operator:: \` -* Match-end-of-buffer Operator:: \' -@end menu - - -@node Match-beginning-of-buffer Operator, Match-end-of-buffer Operator, , Buffer Operators -@subsection The Match-beginning-of-buffer Operator (@code{\`}) - -@cindex @samp{\`} - -This operator (represented by @samp{\`}) matches the empty string at the -beginning of the buffer. - -@node Match-end-of-buffer Operator, , Match-beginning-of-buffer Operator, Buffer Operators -@subsection The Match-end-of-buffer Operator (@code{\'}) - -@cindex @samp{\'} - -This operator (represented by @samp{\'}) matches the empty string at the -end of the buffer. - - -@node GNU Emacs Operators, What Gets Matched?, GNU Operators, Top -@chapter GNU Emacs Operators - -Following are operators that @sc{gnu} defines (and @sc{posix} doesn't) -that you can use only when Regex is compiled with the preprocessor -symbol @code{emacs} defined. - -@menu -* Syntactic Class Operators:: -@end menu - - -@node Syntactic Class Operators, , , GNU Emacs Operators -@section Syntactic Class Operators - -The operators in this section require Regex to recognize the syntactic -classes of characters. Regex uses a syntax table to determine this. - -@menu -* Emacs Syntax Tables:: -* Match-syntactic-class Operator:: \sCLASS -* Match-not-syntactic-class Operator:: \SCLASS -@end menu - -@node Emacs Syntax Tables, Match-syntactic-class Operator, , Syntactic Class Operators -@subsection Emacs Syntax Tables - -A @dfn{syntax table} is an array indexed by the characters in your -character set. In the @sc{ascii} encoding, therefore, a syntax table -has 256 elements. - -If Regex is compiled with the preprocessor symbol @code{emacs} defined, -then Regex expects you to define and initialize the variable -@code{re_syntax_table} to be an Emacs syntax table. Emacs' syntax -tables are more complicated than Regex's own (@pxref{Non-Emacs Syntax -Tables}). @xref{Syntax, , Syntax, emacs, The GNU Emacs User's Manual}, -for a description of Emacs' syntax tables. - -@node Match-syntactic-class Operator, Match-not-syntactic-class Operator, Emacs Syntax Tables, Syntactic Class Operators -@subsection The Match-syntactic-class Operator (@code{\s}@var{class}) - -@cindex @samp{\s} - -This operator matches any character whose syntactic class is represented -by a specified character. @samp{\s@var{class}} represents this operator -where @var{class} is the character representing the syntactic class you -want. For example, @samp{w} represents the syntactic -class of word-constituent characters, so @samp{\sw} matches any -word-constituent character. - -@node Match-not-syntactic-class Operator, , Match-syntactic-class Operator, Syntactic Class Operators -@subsection The Match-not-syntactic-class Operator (@code{\S}@var{class}) - -@cindex @samp{\S} - -This operator is similar to the match-syntactic-class operator except -that it matches any character whose syntactic class is @emph{not} -represented by the specified character. @samp{\S@var{class}} represents -this operator. For example, @samp{w} represents the syntactic class of -word-constituent characters, so @samp{\Sw} matches any character that is -not word-constituent. - - -@node What Gets Matched?, Programming with Regex, GNU Emacs Operators, Top -@chapter What Gets Matched? - -Regex usually matches strings according to the ``leftmost longest'' -rule; that is, it chooses the longest of the leftmost matches. This -does not mean that for a regular expression containing subexpressions -that it simply chooses the longest match for each subexpression, left to -right; the overall match must also be the longest possible one. - -For example, @samp{(ac*)(c*d[ac]*)\1} matches @samp{acdacaaa}, not -@samp{acdac}, as it would if it were to choose the longest match for the -first subexpression. - - -@node Programming with Regex, Copying, What Gets Matched?, Top -@chapter Programming with Regex - -Here we describe how you use the Regex data structures and functions in -C programs. Regex has three interfaces: one designed for @sc{gnu}, one -compatible with @sc{posix} and one compatible with Berkeley @sc{unix}. - -@menu -* GNU Regex Functions:: -* POSIX Regex Functions:: -* BSD Regex Functions:: -@end menu - - -@node GNU Regex Functions, POSIX Regex Functions, , Programming with Regex -@section GNU Regex Functions - -If you're writing code that doesn't need to be compatible with either -@sc{posix} or Berkeley @sc{unix}, you can use these functions. They -provide more options than the other interfaces. - -@menu -* GNU Pattern Buffers:: The re_pattern_buffer type. -* GNU Regular Expression Compiling:: re_compile_pattern () -* GNU Matching:: re_match () -* GNU Searching:: re_search () -* Matching/Searching with Split Data:: re_match_2 (), re_search_2 () -* Searching with Fastmaps:: re_compile_fastmap () -* GNU Translate Tables:: The `translate' field. -* Using Registers:: The re_registers type and related fns. -* Freeing GNU Pattern Buffers:: regfree () -@end menu - - -@node GNU Pattern Buffers, GNU Regular Expression Compiling, , GNU Regex Functions -@subsection GNU Pattern Buffers - -@cindex pattern buffer, definition of -@tindex re_pattern_buffer @r{definition} -@tindex struct re_pattern_buffer @r{definition} - -To compile, match, or search for a given regular expression, you must -supply a pattern buffer. A @dfn{pattern buffer} holds one compiled -regular expression.@footnote{Regular expressions are also referred to as -``patterns,'' hence the name ``pattern buffer.''} - -You can have several different pattern buffers simultaneously, each -holding a compiled pattern for a different regular expression. - -@file{regex.h} defines the pattern buffer @code{struct} as follows: - -@example - /* Space that holds the compiled pattern. It is declared as - `unsigned char *' because its elements are - sometimes used as array indexes. */ - unsigned char *buffer; - - /* Number of bytes to which `buffer' points. */ - unsigned long allocated; - - /* Number of bytes actually used in `buffer'. */ - unsigned long used; - - /* Syntax setting with which the pattern was compiled. */ - reg_syntax_t syntax; - - /* Pointer to a fastmap, if any, otherwise zero. re_search uses - the fastmap, if there is one, to skip over impossible - starting points for matches. */ - char *fastmap; - - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation - is applied to a pattern when it is compiled and to a string - when it is matched. */ - char *translate; - - /* Number of subexpressions found by the compiler. */ - size_t re_nsub; - - /* Zero if this pattern cannot match the empty string, one else. - Well, in truth it's used only in `re_search_2', to see - whether or not we should use the fastmap, so we don't set - this absolutely perfectly; see `re_compile_fastmap' (the - `duplicate' case). */ - unsigned can_be_null : 1; - - /* If REGS_UNALLOCATED, allocate space in the `regs' structure - for `max (RE_NREGS, re_nsub + 1)' groups. - If REGS_REALLOCATE, reallocate space if necessary. - If REGS_FIXED, use what's there. */ -#define REGS_UNALLOCATED 0 -#define REGS_REALLOCATE 1 -#define REGS_FIXED 2 - unsigned regs_allocated : 2; - - /* Set to zero when `regex_compile' compiles a pattern; set to one - by `re_compile_fastmap' if it updates the fastmap. */ - unsigned fastmap_accurate : 1; - - /* If set, `re_match_2' does not return information about - subexpressions. */ - unsigned no_sub : 1; - - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ - unsigned not_bol : 1; - - /* Similarly for an end-of-line anchor. */ - unsigned not_eol : 1; - - /* If true, an anchor at a newline matches. */ - unsigned newline_anchor : 1; - -@end example - - -@node GNU Regular Expression Compiling, GNU Matching, GNU Pattern Buffers, GNU Regex Functions -@subsection GNU Regular Expression Compiling - -In @sc{gnu}, you can both match and search for a given regular -expression. To do either, you must first compile it in a pattern buffer -(@pxref{GNU Pattern Buffers}). - -@cindex syntax initialization -@vindex re_syntax_options @r{initialization} -Regular expressions match according to the syntax with which they were -compiled; with @sc{gnu}, you indicate what syntax you want by setting -the variable @code{re_syntax_options} (declared in @file{regex.h} and -defined in @file{regex.c}) before calling the compiling function, -@code{re_compile_pattern} (see below). @xref{Syntax Bits}, and -@ref{Predefined Syntaxes}. - -You can change the value of @code{re_syntax_options} at any time. -Usually, however, you set its value once and then never change it. - -@cindex pattern buffer initialization -@code{re_compile_pattern} takes a pattern buffer as an argument. You -must initialize the following fields: - -@table @code - -@item translate @r{initialization} - -@item translate -@vindex translate @r{initialization} -Initialize this to point to a translate table if you want one, or to -zero if you don't. We explain translate tables in @ref{GNU Translate -Tables}. - -@item fastmap -@vindex fastmap @r{initialization} -Initialize this to nonzero if you want a fastmap, or to zero if you -don't. - -@item buffer -@itemx allocated -@vindex buffer @r{initialization} -@vindex allocated @r{initialization} -@findex malloc -If you want @code{re_compile_pattern} to allocate memory for the -compiled pattern, set both of these to zero. If you have an existing -block of memory (allocated with @code{malloc}) you want Regex to use, -set @code{buffer} to its address and @code{allocated} to its size (in -bytes). - -@code{re_compile_pattern} uses @code{realloc} to extend the space for -the compiled pattern as necessary. - -@end table - -To compile a pattern buffer, use: - -@findex re_compile_pattern -@example -char * -re_compile_pattern (const char *@var{regex}, const int @var{regex_size}, - struct re_pattern_buffer *@var{pattern_buffer}) -@end example - -@noindent -@var{regex} is the regular expression's address, @var{regex_size} is its -length, and @var{pattern_buffer} is the pattern buffer's address. - -If @code{re_compile_pattern} successfully compiles the regular -expression, it returns zero and sets @code{*@var{pattern_buffer}} to the -compiled pattern. It sets the pattern buffer's fields as follows: - -@table @code -@item buffer -@vindex buffer @r{field, set by @code{re_compile_pattern}} -to the compiled pattern. - -@item used -@vindex used @r{field, set by @code{re_compile_pattern}} -to the number of bytes the compiled pattern in @code{buffer} occupies. - -@item syntax -@vindex syntax @r{field, set by @code{re_compile_pattern}} -to the current value of @code{re_syntax_options}. - -@item re_nsub -@vindex re_nsub @r{field, set by @code{re_compile_pattern}} -to the number of subexpressions in @var{regex}. - -@item fastmap_accurate -@vindex fastmap_accurate @r{field, set by @code{re_compile_pattern}} -to zero on the theory that the pattern you're compiling is different -than the one previously compiled into @code{buffer}; in that case (since -you can't make a fastmap without a compiled pattern), -@code{fastmap} would either contain an incompatible fastmap, or nothing -at all. - -@c xx what else? -@end table - -If @code{re_compile_pattern} can't compile @var{regex}, it returns an -error string corresponding to one of the errors listed in @ref{POSIX -Regular Expression Compiling}. - - -@node GNU Matching, GNU Searching, GNU Regular Expression Compiling, GNU Regex Functions -@subsection GNU Matching - -@cindex matching with GNU functions - -Matching the @sc{gnu} way means trying to match as much of a string as -possible starting at a position within it you specify. Once you've compiled -a pattern into a pattern buffer (@pxref{GNU Regular Expression -Compiling}), you can ask the matcher to match that pattern against a -string using: - -@findex re_match -@example -int -re_match (struct re_pattern_buffer *@var{pattern_buffer}, - const char *@var{string}, const int @var{size}, - const int @var{start}, struct re_registers *@var{regs}) -@end example - -@noindent -@var{pattern_buffer} is the address of a pattern buffer containing a -compiled pattern. @var{string} is the string you want to match; it can -contain newline and null characters. @var{size} is the length of that -string. @var{start} is the string index at which you want to -begin matching; the first character of @var{string} is at index zero. -@xref{Using Registers}, for a explanation of @var{regs}; you can safely -pass zero. - -@code{re_match} matches the regular expression in @var{pattern_buffer} -against the string @var{string} according to the syntax in -@var{pattern_buffers}'s @code{syntax} field. (@xref{GNU Regular -Expression Compiling}, for how to set it.) The function returns -@math{-1} if the compiled pattern does not match any part of -@var{string} and @math{-2} if an internal error happens; otherwise, it -returns how many (possibly zero) characters of @var{string} the pattern -matched. - -An example: suppose @var{pattern_buffer} points to a pattern buffer -containing the compiled pattern for @samp{a*}, and @var{string} points -to @samp{aaaaab} (whereupon @var{size} should be 6). Then if @var{start} -is 2, @code{re_match} returns 3, i.e., @samp{a*} would have matched the -last three @samp{a}s in @var{string}. If @var{start} is 0, -@code{re_match} returns 5, i.e., @samp{a*} would have matched all the -@samp{a}s in @var{string}. If @var{start} is either 5 or 6, it returns -zero. - -If @var{start} is not between zero and @var{size}, then -@code{re_match} returns @math{-1}. - - -@node GNU Searching, Matching/Searching with Split Data, GNU Matching, GNU Regex Functions -@subsection GNU Searching - -@cindex searching with GNU functions - -@dfn{Searching} means trying to match starting at successive positions -within a string. The function @code{re_search} does this. - -Before calling @code{re_search}, you must compile your regular -expression. @xref{GNU Regular Expression Compiling}. - -Here is the function declaration: - -@findex re_search -@example -int -re_search (struct re_pattern_buffer *@var{pattern_buffer}, - const char *@var{string}, const int @var{size}, - const int @var{start}, const int @var{range}, - struct re_registers *@var{regs}) -@end example - -@noindent -@vindex start @r{argument to @code{re_search}} -@vindex range @r{argument to @code{re_search}} -whose arguments are the same as those to @code{re_match} (@pxref{GNU -Matching}) except that the two arguments @var{start} and @var{range} -replace @code{re_match}'s argument @var{start}. - -If @var{range} is positive, then @code{re_search} attempts a match -starting first at index @var{start}, then at @math{@var{start} + 1} if -that fails, and so on, up to @math{@var{start} + @var{range}}; if -@var{range} is negative, then it attempts a match starting first at -index @var{start}, then at @math{@var{start} -1} if that fails, and so -on. - -If @var{start} is not between zero and @var{size}, then @code{re_search} -returns @math{-1}. When @var{range} is positive, @code{re_search} -adjusts @var{range} so that @math{@var{start} + @var{range} - 1} is -between zero and @var{size}, if necessary; that way it won't search -outside of @var{string}. Similarly, when @var{range} is negative, -@code{re_search} adjusts @var{range} so that @math{@var{start} + -@var{range} + 1} is between zero and @var{size}, if necessary. - -If the @code{fastmap} field of @var{pattern_buffer} is zero, -@code{re_search} matches starting at consecutive positions; otherwise, -it uses @code{fastmap} to make the search more efficient. -@xref{Searching with Fastmaps}. - -If no match is found, @code{re_search} returns @math{-1}. If -a match is found, it returns the index where the match began. If an -internal error happens, it returns @math{-2}. - - -@node Matching/Searching with Split Data, Searching with Fastmaps, GNU Searching, GNU Regex Functions -@subsection Matching and Searching with Split Data - -Using the functions @code{re_match_2} and @code{re_search_2}, you can -match or search in data that is divided into two strings. - -The function: - -@findex re_match_2 -@example -int -re_match_2 (struct re_pattern_buffer *@var{buffer}, - const char *@var{string1}, const int @var{size1}, - const char *@var{string2}, const int @var{size2}, - const int @var{start}, - struct re_registers *@var{regs}, - const int @var{stop}) -@end example - -@noindent -is similar to @code{re_match} (@pxref{GNU Matching}) except that you -pass @emph{two} data strings and sizes, and an index @var{stop} beyond -which you don't want the matcher to try matching. As with -@code{re_match}, if it succeeds, @code{re_match_2} returns how many -characters of @var{string} it matched. Regard @var{string1} and -@var{string2} as concatenated when you set the arguments @var{start} and -@var{stop} and use the contents of @var{regs}; @code{re_match_2} never -returns a value larger than @math{@var{size1} + @var{size2}}. - -The function: - -@findex re_search_2 -@example -int -re_search_2 (struct re_pattern_buffer *@var{buffer}, - const char *@var{string1}, const int @var{size1}, - const char *@var{string2}, const int @var{size2}, - const int @var{start}, const int @var{range}, - struct re_registers *@var{regs}, - const int @var{stop}) -@end example - -@noindent -is similarly related to @code{re_search}. - - -@node Searching with Fastmaps, GNU Translate Tables, Matching/Searching with Split Data, GNU Regex Functions -@subsection Searching with Fastmaps - -@cindex fastmaps -If you're searching through a long string, you should use a fastmap. -Without one, the searcher tries to match at consecutive positions in the -string. Generally, most of the characters in the string could not start -a match. It takes much longer to try matching at a given position in the -string than it does to check in a table whether or not the character at -that position could start a match. A @dfn{fastmap} is such a table. - -More specifically, a fastmap is an array indexed by the characters in -your character set. Under the @sc{ascii} encoding, therefore, a fastmap -has 256 elements. If you want the searcher to use a fastmap with a -given pattern buffer, you must allocate the array and assign the array's -address to the pattern buffer's @code{fastmap} field. You either can -compile the fastmap yourself or have @code{re_search} do it for you; -when @code{fastmap} is nonzero, it automatically compiles a fastmap the -first time you search using a particular compiled pattern. - -To compile a fastmap yourself, use: - -@findex re_compile_fastmap -@example -int -re_compile_fastmap (struct re_pattern_buffer *@var{pattern_buffer}) -@end example - -@noindent -@var{pattern_buffer} is the address of a pattern buffer. If the -character @var{c} could start a match for the pattern, -@code{re_compile_fastmap} makes -@code{@var{pattern_buffer}->fastmap[@var{c}]} nonzero. It returns -@math{0} if it can compile a fastmap and @math{-2} if there is an -internal error. For example, if @samp{|} is the alternation operator -and @var{pattern_buffer} holds the compiled pattern for @samp{a|b}, then -@code{re_compile_fastmap} sets @code{fastmap['a']} and -@code{fastmap['b']} (and no others). - -@code{re_search} uses a fastmap as it moves along in the string: it -checks the string's characters until it finds one that's in the fastmap. -Then it tries matching at that character. If the match fails, it -repeats the process. So, by using a fastmap, @code{re_search} doesn't -waste time trying to match at positions in the string that couldn't -start a match. - -If you don't want @code{re_search} to use a fastmap, -store zero in the @code{fastmap} field of the pattern buffer before -calling @code{re_search}. - -Once you've initialized a pattern buffer's @code{fastmap} field, you -need never do so again---even if you compile a new pattern in -it---provided the way the field is set still reflects whether or not you -want a fastmap. @code{re_search} will still either do nothing if -@code{fastmap} is null or, if it isn't, compile a new fastmap for the -new pattern. - -@node GNU Translate Tables, Using Registers, Searching with Fastmaps, GNU Regex Functions -@subsection GNU Translate Tables - -If you set the @code{translate} field of a pattern buffer to a translate -table, then the @sc{gnu} Regex functions to which you've passed that -pattern buffer use it to apply a simple transformation -to all the regular expression and string characters at which they look. - -A @dfn{translate table} is an array indexed by the characters in your -character set. Under the @sc{ascii} encoding, therefore, a translate -table has 256 elements. The array's elements are also characters in -your character set. When the Regex functions see a character @var{c}, -they use @code{translate[@var{c}]} in its place, with one exception: the -character after a @samp{\} is not translated. (This ensures that, the -operators, e.g., @samp{\B} and @samp{\b}, are always distinguishable.) - -For example, a table that maps all lowercase letters to the -corresponding uppercase ones would cause the matcher to ignore -differences in case.@footnote{A table that maps all uppercase letters to -the corresponding lowercase ones would work just as well for this -purpose.} Such a table would map all characters except lowercase letters -to themselves, and lowercase letters to the corresponding uppercase -ones. Under the @sc{ascii} encoding, here's how you could initialize -such a table (we'll call it @code{case_fold}): - -@example -for (i = 0; i < 256; i++) - case_fold[i] = i; -for (i = 'a'; i <= 'z'; i++) - case_fold[i] = i - ('a' - 'A'); -@end example - -You tell Regex to use a translate table on a given pattern buffer by -assigning that table's address to the @code{translate} field of that -buffer. If you don't want Regex to do any translation, put zero into -this field. You'll get weird results if you change the table's contents -anytime between compiling the pattern buffer, compiling its fastmap, and -matching or searching with the pattern buffer. - -@node Using Registers, Freeing GNU Pattern Buffers, GNU Translate Tables, GNU Regex Functions -@subsection Using Registers - -A group in a regular expression can match a (posssibly empty) substring -of the string that regular expression as a whole matched. The matcher -remembers the beginning and end of the substring matched by -each group. - -To find out what they matched, pass a nonzero @var{regs} argument to a -@sc{gnu} matching or searching function (@pxref{GNU Matching} and -@ref{GNU Searching}), i.e., the address of a structure of this type, as -defined in @file{regex.h}: - -@c We don't bother to include this directly from regex.h, -@c since it changes so rarely. -@example -@tindex re_registers -@vindex num_regs @r{in @code{struct re_registers}} -@vindex start @r{in @code{struct re_registers}} -@vindex end @r{in @code{struct re_registers}} -struct re_registers -@{ - unsigned num_regs; - regoff_t *start; - regoff_t *end; -@}; -@end example - -Except for (possibly) the @var{num_regs}'th element (see below), the -@var{i}th element of the @code{start} and @code{end} arrays records -information about the @var{i}th group in the pattern. (They're declared -as C pointers, but this is only because not all C compilers accept -zero-length arrays; conceptually, it is simplest to think of them as -arrays.) - -The @code{start} and @code{end} arrays are allocated in various ways, -depending on the value of the @code{regs_allocated} -@vindex regs_allocated -field in the pattern buffer passed to the matcher. - -The simplest and perhaps most useful is to let the matcher (re)allocate -enough space to record information for all the groups in the regular -expression. If @code{regs_allocated} is @code{REGS_UNALLOCATED}, -@vindex REGS_UNALLOCATED -the matcher allocates @math{1 + @var{re_nsub}} (another field in the -pattern buffer; @pxref{GNU Pattern Buffers}). The extra element is set -to @math{-1}, and sets @code{regs_allocated} to @code{REGS_REALLOCATE}. -@vindex REGS_REALLOCATE -Then on subsequent calls with the same pattern buffer and @var{regs} -arguments, the matcher reallocates more space if necessary. - -It would perhaps be more logical to make the @code{regs_allocated} field -part of the @code{re_registers} structure, instead of part of the -pattern buffer. But in that case the caller would be forced to -initialize the structure before passing it. Much existing code doesn't -do this initialization, and it's arguably better to avoid it anyway. - -@code{re_compile_pattern} sets @code{regs_allocated} to -@code{REGS_UNALLOCATED}, -so if you use the GNU regular expression -functions, you get this behavior by default. - -xx document re_set_registers - -@sc{posix}, on the other hand, requires a different interface: the -caller is supposed to pass in a fixed-length array which the matcher -fills. Therefore, if @code{regs_allocated} is @code{REGS_FIXED} -@vindex REGS_FIXED -the matcher simply fills that array. - -The following examples illustrate the information recorded in the -@code{re_registers} structure. (In all of them, @samp{(} represents the -open-group and @samp{)} the close-group operator. The first character -in the string @var{string} is at index 0.) - -@c xx i'm not sure this is all true anymore. - -@itemize @bullet - -@item -If the regular expression has an @w{@var{i}-th} -group not contained within another group that matches a -substring of @var{string}, then the function sets -@code{@w{@var{regs}->}start[@var{i}]} to the index in @var{string} where -the substring matched by the @w{@var{i}-th} group begins, and -@code{@w{@var{regs}->}end[@var{i}]} to the index just beyond that -substring's end. The function sets @code{@w{@var{regs}->}start[0]} and -@code{@w{@var{regs}->}end[0]} to analogous information about the entire -pattern. - -For example, when you match @samp{((a)(b))} against @samp{ab}, you get: - -@itemize -@item -0 in @code{@w{@var{regs}->}start[0]} and 2 in @code{@w{@var{regs}->}end[0]} - -@item -0 in @code{@w{@var{regs}->}start[1]} and 2 in @code{@w{@var{regs}->}end[1]} - -@item -0 in @code{@w{@var{regs}->}start[2]} and 1 in @code{@w{@var{regs}->}end[2]} - -@item -1 in @code{@w{@var{regs}->}start[3]} and 2 in @code{@w{@var{regs}->}end[3]} -@end itemize - -@item -If a group matches more than once (as it might if followed by, -e.g., a repetition operator), then the function reports the information -about what the group @emph{last} matched. - -For example, when you match the pattern @samp{(a)*} against the string -@samp{aa}, you get: - -@itemize -@item -0 in @code{@w{@var{regs}->}start[0]} and 2 in @code{@w{@var{regs}->}end[0]} - -@item -1 in @code{@w{@var{regs}->}start[1]} and 2 in @code{@w{@var{regs}->}end[1]} -@end itemize - -@item -If the @w{@var{i}-th} group does not participate in a -successful match, e.g., it is an alternative not taken or a -repetition operator allows zero repetitions of it, then the function -sets @code{@w{@var{regs}->}start[@var{i}]} and -@code{@w{@var{regs}->}end[@var{i}]} to @math{-1}. - -For example, when you match the pattern @samp{(a)*b} against -the string @samp{b}, you get: - -@itemize -@item -0 in @code{@w{@var{regs}->}start[0]} and 1 in @code{@w{@var{regs}->}end[0]} - -@item -@math{-1} in @code{@w{@var{regs}->}start[1]} and @math{-1} in @code{@w{@var{regs}->}end[1]} -@end itemize - -@item -If the @w{@var{i}-th} group matches a zero-length string, then the -function sets @code{@w{@var{regs}->}start[@var{i}]} and -@code{@w{@var{regs}->}end[@var{i}]} to the index just beyond that -zero-length string. - -For example, when you match the pattern @samp{(a*)b} against the string -@samp{b}, you get: - -@itemize -@item -0 in @code{@w{@var{regs}->}start[0]} and 1 in @code{@w{@var{regs}->}end[0]} - -@item -0 in @code{@w{@var{regs}->}start[1]} and 0 in @code{@w{@var{regs}->}end[1]} -@end itemize - -@ignore -The function sets @code{@w{@var{regs}->}start[0]} and -@code{@w{@var{regs}->}end[0]} to analogous information about the entire -pattern. - -For example, when you match the pattern @samp{(a*)} against the empty -string, you get: - -@itemize -@item -0 in @code{@w{@var{regs}->}start[0]} and 0 in @code{@w{@var{regs}->}end[0]} - -@item -0 in @code{@w{@var{regs}->}start[1]} and 0 in @code{@w{@var{regs}->}end[1]} -@end itemize -@end ignore - -@item -If an @w{@var{i}-th} group contains a @w{@var{j}-th} group -in turn not contained within any other group within group @var{i} and -the function reports a match of the @w{@var{i}-th} group, then it -records in @code{@w{@var{regs}->}start[@var{j}]} and -@code{@w{@var{regs}->}end[@var{j}]} the last match (if it matched) of -the @w{@var{j}-th} group. - -For example, when you match the pattern @samp{((a*)b)*} against the -string @samp{abb}, @w{group 2} last matches the empty string, so you -get what it previously matched: - -@itemize -@item -0 in @code{@w{@var{regs}->}start[0]} and 3 in @code{@w{@var{regs}->}end[0]} - -@item -2 in @code{@w{@var{regs}->}start[1]} and 3 in @code{@w{@var{regs}->}end[1]} - -@item -2 in @code{@w{@var{regs}->}start[2]} and 2 in @code{@w{@var{regs}->}end[2]} -@end itemize - -When you match the pattern @samp{((a)*b)*} against the string -@samp{abb}, @w{group 2} doesn't participate in the last match, so you -get: - -@itemize -@item -0 in @code{@w{@var{regs}->}start[0]} and 3 in @code{@w{@var{regs}->}end[0]} - -@item -2 in @code{@w{@var{regs}->}start[1]} and 3 in @code{@w{@var{regs}->}end[1]} - -@item -0 in @code{@w{@var{regs}->}start[2]} and 1 in @code{@w{@var{regs}->}end[2]} -@end itemize - -@item -If an @w{@var{i}-th} group contains a @w{@var{j}-th} group -in turn not contained within any other group within group @var{i} -and the function sets -@code{@w{@var{regs}->}start[@var{i}]} and -@code{@w{@var{regs}->}end[@var{i}]} to @math{-1}, then it also sets -@code{@w{@var{regs}->}start[@var{j}]} and -@code{@w{@var{regs}->}end[@var{j}]} to @math{-1}. - -For example, when you match the pattern @samp{((a)*b)*c} against the -string @samp{c}, you get: - -@itemize -@item -0 in @code{@w{@var{regs}->}start[0]} and 1 in @code{@w{@var{regs}->}end[0]} - -@item -@math{-1} in @code{@w{@var{regs}->}start[1]} and @math{-1} in @code{@w{@var{regs}->}end[1]} - -@item -@math{-1} in @code{@w{@var{regs}->}start[2]} and @math{-1} in @code{@w{@var{regs}->}end[2]} -@end itemize - -@end itemize - -@node Freeing GNU Pattern Buffers, , Using Registers, GNU Regex Functions -@subsection Freeing GNU Pattern Buffers - -To free any allocated fields of a pattern buffer, you can use the -@sc{posix} function described in @ref{Freeing POSIX Pattern Buffers}, -since the type @code{regex_t}---the type for @sc{posix} pattern -buffers---is equivalent to the type @code{re_pattern_buffer}. After -freeing a pattern buffer, you need to again compile a regular expression -in it (@pxref{GNU Regular Expression Compiling}) before passing it to -a matching or searching function. - - -@node POSIX Regex Functions, BSD Regex Functions, GNU Regex Functions, Programming with Regex -@section POSIX Regex Functions - -If you're writing code that has to be @sc{posix} compatible, you'll need -to use these functions. Their interfaces are as specified by @sc{posix}, -draft 1003.2/D11.2. - -@menu -* POSIX Pattern Buffers:: The regex_t type. -* POSIX Regular Expression Compiling:: regcomp () -* POSIX Matching:: regexec () -* Reporting Errors:: regerror () -* Using Byte Offsets:: The regmatch_t type. -* Freeing POSIX Pattern Buffers:: regfree () -@end menu - - -@node POSIX Pattern Buffers, POSIX Regular Expression Compiling, , POSIX Regex Functions -@subsection POSIX Pattern Buffers - -To compile or match a given regular expression the @sc{posix} way, you -must supply a pattern buffer exactly the way you do for @sc{gnu} -(@pxref{GNU Pattern Buffers}). @sc{posix} pattern buffers have type -@code{regex_t}, which is equivalent to the @sc{gnu} pattern buffer -type @code{re_pattern_buffer}. - - -@node POSIX Regular Expression Compiling, POSIX Matching, POSIX Pattern Buffers, POSIX Regex Functions -@subsection POSIX Regular Expression Compiling - -With @sc{posix}, you can only search for a given regular expression; you -can't match it. To do this, you must first compile it in a -pattern buffer, using @code{regcomp}. - -@ignore -Before calling @code{regcomp}, you must initialize this pattern buffer -as you do for @sc{gnu} (@pxref{GNU Regular Expression Compiling}). See -below, however, for how to choose a syntax with which to compile. -@end ignore - -To compile a pattern buffer, use: - -@findex regcomp -@example -int -regcomp (regex_t *@var{preg}, const char *@var{regex}, int @var{cflags}) -@end example - -@noindent -@var{preg} is the initialized pattern buffer's address, @var{regex} is -the regular expression's address, and @var{cflags} is the compilation -flags, which Regex considers as a collection of bits. Here are the -valid bits, as defined in @file{regex.h}: - -@table @code - -@item REG_EXTENDED -@vindex REG_EXTENDED -says to use @sc{posix} Extended Regular Expression syntax; if this isn't -set, then says to use @sc{posix} Basic Regular Expression syntax. -@code{regcomp} sets @var{preg}'s @code{syntax} field accordingly. - -@item REG_ICASE -@vindex REG_ICASE -@cindex ignoring case -says to ignore case; @code{regcomp} sets @var{preg}'s @code{translate} -field to a translate table which ignores case, replacing anything you've -put there before. - -@item REG_NOSUB -@vindex REG_NOSUB -says to set @var{preg}'s @code{no_sub} field; @pxref{POSIX Matching}, -for what this means. - -@item REG_NEWLINE -@vindex REG_NEWLINE -says that a: - -@itemize @bullet - -@item -match-any-character operator (@pxref{Match-any-character -Operator}) doesn't match a newline. - -@item -nonmatching list not containing a newline (@pxref{List -Operators}) matches a newline. - -@item -match-beginning-of-line operator (@pxref{Match-beginning-of-line -Operator}) matches the empty string immediately after a newline, -regardless of how @code{REG_NOTBOL} is set (@pxref{POSIX Matching}, for -an explanation of @code{REG_NOTBOL}). - -@item -match-end-of-line operator (@pxref{Match-beginning-of-line -Operator}) matches the empty string immediately before a newline, -regardless of how @code{REG_NOTEOL} is set (@pxref{POSIX Matching}, -for an explanation of @code{REG_NOTEOL}). - -@end itemize - -@end table - -If @code{regcomp} successfully compiles the regular expression, it -returns zero and sets @code{*@var{pattern_buffer}} to the compiled -pattern. Except for @code{syntax} (which it sets as explained above), it -also sets the same fields the same way as does the @sc{gnu} compiling -function (@pxref{GNU Regular Expression Compiling}). - -If @code{regcomp} can't compile the regular expression, it returns one -of the error codes listed here. (Except when noted differently, the -syntax of in all examples below is basic regular expression syntax.) - -@table @code - -@comment repetitions -@item REG_BADRPT -For example, the consecutive repetition operators @samp{**} in -@samp{a**} are invalid. As another example, if the syntax is extended -regular expression syntax, then the repetition operator @samp{*} with -nothing on which to operate in @samp{*} is invalid. - -@item REG_BADBR -For example, the @var{count} @samp{-1} in @samp{a\@{-1} is invalid. - -@item REG_EBRACE -For example, @samp{a\@{1} is missing a close-interval operator. - -@comment lists -@item REG_EBRACK -For example, @samp{[a} is missing a close-list operator. - -@item REG_ERANGE -For example, the range ending point @samp{z} that collates lower than -does its starting point @samp{a} in @samp{[z-a]} is invalid. Also, the -range with the character class @samp{[:alpha:]} as its starting point in -@samp{[[:alpha:]-|]}. - -@item REG_ECTYPE -For example, the character class name @samp{foo} in @samp{[[:foo:]} is -invalid. - -@comment groups -@item REG_EPAREN -For example, @samp{a\)} is missing an open-group operator and @samp{\(a} -is missing a close-group operator. - -@item REG_ESUBREG -For example, the back reference @samp{\2} that refers to a nonexistent -subexpression in @samp{\(a\)\2} is invalid. - -@comment unfinished business - -@item REG_EEND -Returned when a regular expression causes no other more specific error. - -@item REG_EESCAPE -For example, the trailing backslash @samp{\} in @samp{a\} is invalid, as is the -one in @samp{\}. - -@comment kitchen sink -@item REG_BADPAT -For example, in the extended regular expression syntax, the empty group -@samp{()} in @samp{a()b} is invalid. - -@comment internal -@item REG_ESIZE -Returned when a regular expression needs a pattern buffer larger than -65536 bytes. - -@item REG_ESPACE -Returned when a regular expression makes Regex to run out of memory. - -@end table - - -@node POSIX Matching, Reporting Errors, POSIX Regular Expression Compiling, POSIX Regex Functions -@subsection POSIX Matching - -Matching the @sc{posix} way means trying to match a null-terminated -string starting at its first character. Once you've compiled a pattern -into a pattern buffer (@pxref{POSIX Regular Expression Compiling}), you -can ask the matcher to match that pattern against a string using: - -@findex regexec -@example -int -regexec (const regex_t *@var{preg}, const char *@var{string}, - size_t @var{nmatch}, regmatch_t @var{pmatch}[], int @var{eflags}) -@end example - -@noindent -@var{preg} is the address of a pattern buffer for a compiled pattern. -@var{string} is the string you want to match. - -@xref{Using Byte Offsets}, for an explanation of @var{pmatch}. If you -pass zero for @var{nmatch} or you compiled @var{preg} with the -compilation flag @code{REG_NOSUB} set, then @code{regexec} will ignore -@var{pmatch}; otherwise, you must allocate it to have at least -@var{nmatch} elements. @code{regexec} will record @var{nmatch} byte -offsets in @var{pmatch}, and set to @math{-1} any unused elements up to -@math{@var{pmatch}@code{[@var{nmatch}]} - 1}. - -@var{eflags} specifies @dfn{execution flags}---namely, the two bits -@code{REG_NOTBOL} and @code{REG_NOTEOL} (defined in @file{regex.h}). If -you set @code{REG_NOTBOL}, then the match-beginning-of-line operator -(@pxref{Match-beginning-of-line Operator}) always fails to match. -This lets you match against pieces of a line, as you would need to if, -say, searching for repeated instances of a given pattern in a line; it -would work correctly for patterns both with and without -match-beginning-of-line operators. @code{REG_NOTEOL} works analogously -for the match-end-of-line operator (@pxref{Match-end-of-line -Operator}); it exists for symmetry. - -@code{regexec} tries to find a match for @var{preg} in @var{string} -according to the syntax in @var{preg}'s @code{syntax} field. -(@xref{POSIX Regular Expression Compiling}, for how to set it.) The -function returns zero if the compiled pattern matches @var{string} and -@code{REG_NOMATCH} (defined in @file{regex.h}) if it doesn't. - -@node Reporting Errors, Using Byte Offsets, POSIX Matching, POSIX Regex Functions -@subsection Reporting Errors - -If either @code{regcomp} or @code{regexec} fail, they return a nonzero -error code, the possibilities for which are defined in @file{regex.h}. -@xref{POSIX Regular Expression Compiling}, and @ref{POSIX Matching}, for -what these codes mean. To get an error string corresponding to these -codes, you can use: - -@findex regerror -@example -size_t -regerror (int @var{errcode}, - const regex_t *@var{preg}, - char *@var{errbuf}, - size_t @var{errbuf_size}) -@end example - -@noindent -@var{errcode} is an error code, @var{preg} is the address of the pattern -buffer which provoked the error, @var{errbuf} is the error buffer, and -@var{errbuf_size} is @var{errbuf}'s size. - -@code{regerror} returns the size in bytes of the error string -corresponding to @var{errcode} (including its terminating null). If -@var{errbuf} and @var{errbuf_size} are nonzero, it also returns in -@var{errbuf} the first @math{@var{errbuf_size} - 1} characters of the -error string, followed by a null. -@var{errbuf_size} must be a nonnegative number less than or equal to the -size in bytes of @var{errbuf}. - -You can call @code{regerror} with a null @var{errbuf} and a zero -@var{errbuf_size} to determine how large @var{errbuf} need be to -accommodate @code{regerror}'s error string. - -@node Using Byte Offsets, Freeing POSIX Pattern Buffers, Reporting Errors, POSIX Regex Functions -@subsection Using Byte Offsets - -In @sc{posix}, variables of type @code{regmatch_t} hold analogous -information, but are not identical to, @sc{gnu}'s registers (@pxref{Using -Registers}). To get information about registers in @sc{posix}, pass to -@code{regexec} a nonzero @var{pmatch} of type @code{regmatch_t}, i.e., -the address of a structure of this type, defined in -@file{regex.h}: - -@tindex regmatch_t -@example -typedef struct -@{ - regoff_t rm_so; - regoff_t rm_eo; -@} regmatch_t; -@end example - -When reading in @ref{Using Registers}, about how the matching function -stores the information into the registers, substitute @var{pmatch} for -@var{regs}, @code{@w{@var{pmatch}[@var{i}]->}rm_so} for -@code{@w{@var{regs}->}start[@var{i}]} and -@code{@w{@var{pmatch}[@var{i}]->}rm_eo} for -@code{@w{@var{regs}->}end[@var{i}]}. - -@node Freeing POSIX Pattern Buffers, , Using Byte Offsets, POSIX Regex Functions -@subsection Freeing POSIX Pattern Buffers - -To free any allocated fields of a pattern buffer, use: - -@findex regfree -@example -void -regfree (regex_t *@var{preg}) -@end example - -@noindent -@var{preg} is the pattern buffer whose allocated fields you want freed. -@code{regfree} also sets @var{preg}'s @code{allocated} and @code{used} -fields to zero. After freeing a pattern buffer, you need to again -compile a regular expression in it (@pxref{POSIX Regular Expression -Compiling}) before passing it to the matching function (@pxref{POSIX -Matching}). - - -@node BSD Regex Functions, , POSIX Regex Functions, Programming with Regex -@section BSD Regex Functions - -If you're writing code that has to be Berkeley @sc{unix} compatible, -you'll need to use these functions whose interfaces are the same as those -in Berkeley @sc{unix}. - -@menu -* BSD Regular Expression Compiling:: re_comp () -* BSD Searching:: re_exec () -@end menu - -@node BSD Regular Expression Compiling, BSD Searching, , BSD Regex Functions -@subsection BSD Regular Expression Compiling - -With Berkeley @sc{unix}, you can only search for a given regular -expression; you can't match one. To search for it, you must first -compile it. Before you compile it, you must indicate the regular -expression syntax you want it compiled according to by setting the -variable @code{re_syntax_options} (declared in @file{regex.h} to some -syntax (@pxref{Regular Expression Syntax}). - -To compile a regular expression use: - -@findex re_comp -@example -char * -re_comp (char *@var{regex}) -@end example - -@noindent -@var{regex} is the address of a null-terminated regular expression. -@code{re_comp} uses an internal pattern buffer, so you can use only the -most recently compiled pattern buffer. This means that if you want to -use a given regular expression that you've already compiled---but it -isn't the latest one you've compiled---you'll have to recompile it. If -you call @code{re_comp} with the null string (@emph{not} the empty -string) as the argument, it doesn't change the contents of the pattern -buffer. - -If @code{re_comp} successfully compiles the regular expression, it -returns zero. If it can't compile the regular expression, it returns -an error string. @code{re_comp}'s error messages are identical to those -of @code{re_compile_pattern} (@pxref{GNU Regular Expression -Compiling}). - -@node BSD Searching, , BSD Regular Expression Compiling, BSD Regex Functions -@subsection BSD Searching - -Searching the Berkeley @sc{unix} way means searching in a string -starting at its first character and trying successive positions within -it to find a match. Once you've compiled a pattern using @code{re_comp} -(@pxref{BSD Regular Expression Compiling}), you can ask Regex -to search for that pattern in a string using: - -@findex re_exec -@example -int -re_exec (char *@var{string}) -@end example - -@noindent -@var{string} is the address of the null-terminated string in which you -want to search. - -@code{re_exec} returns either 1 for success or 0 for failure. It -automatically uses a @sc{gnu} fastmap (@pxref{Searching with Fastmaps}). - - -@node Copying, Index, Programming with Regex, Top -@appendix GNU GENERAL PUBLIC LICENSE -@center Version 2, June 1991 - -@display -Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. -675 Mass Ave, Cambridge, MA 02139, USA - -Everyone is permitted to copy and distribute verbatim copies -of this license document, but changing it is not allowed. -@end display - -@unnumberedsec Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software---to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - -@iftex -@unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -@end iftex -@ifinfo -@center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -@end ifinfo - -@enumerate -@item -This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The ``Program'', below, -refers to any such program or work, and a ``work based on the Program'' -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term ``modification''.) Each licensee is addressed as ``you''. - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - -@item -You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - -@item -You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - -@enumerate a -@item -You must cause the modified files to carry prominent notices -stating that you changed the files and the date of any change. - -@item -You must cause any work that you distribute or publish, that in -whole or in part contains or is derived from the Program or any -part thereof, to be licensed as a whole at no charge to all third -parties under the terms of this License. - -@item -If the modified program normally reads commands interactively -when run, you must cause it, when started running for such -interactive use in the most ordinary way, to print or display an -announcement including an appropriate copyright notice and a -notice that there is no warranty (or else, saying that you provide -a warranty) and that users may redistribute the program under -these conditions, and telling the user how to view a copy of this -License. (Exception: if the Program itself is interactive but -does not normally print such an announcement, your work based on -the Program is not required to print an announcement.) -@end enumerate - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - -@item -You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - -@enumerate a -@item -Accompany it with the complete corresponding machine-readable -source code, which must be distributed under the terms of Sections -1 and 2 above on a medium customarily used for software interchange; or, - -@item -Accompany it with a written offer, valid for at least three -years, to give any third party, for a charge no more than your -cost of physically performing source distribution, a complete -machine-readable copy of the corresponding source code, to be -distributed under the terms of Sections 1 and 2 above on a medium -customarily used for software interchange; or, - -@item -Accompany it with the information you received as to the offer -to distribute corresponding source code. (This alternative is -allowed only for noncommercial distribution and only if you -received the program in object code or executable form with such -an offer, in accord with Subsection b above.) -@end enumerate - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - -@item -You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - -@item -You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - -@item -Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - -@item -If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - -@item -If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - -@item -The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and ``any -later version'', you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - -@item -If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - -@iftex -@heading NO WARRANTY -@end iftex -@ifinfo -@center NO WARRANTY -@end ifinfo - -@item -BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - -@item -IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. -@end enumerate - -@iftex -@heading END OF TERMS AND CONDITIONS -@end iftex -@ifinfo -@center END OF TERMS AND CONDITIONS -@end ifinfo - -@page -@unnumberedsec Appendix: How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the ``copyright'' line and a pointer to where the full notice is found. - -@smallexample -@var{one line to give the program's name and a brief idea of what it does.} -Copyright (C) 19@var{yy} @var{name of author} - -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 of the License, 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 this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -@end smallexample - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - -@smallexample -Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} -Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. -This is free software, and you are welcome to redistribute it -under certain conditions; type `show c' for details. -@end smallexample - -The hypothetical commands @samp{show w} and @samp{show c} should show -the appropriate parts of the General Public License. Of course, the -commands you use may be called something other than @samp{show w} and -@samp{show c}; they could even be mouse-clicks or menu items---whatever -suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a ``copyright disclaimer'' for the program, if -necessary. Here is a sample; alter the names: - -@example -Yoyodyne, Inc., hereby disclaims all copyright interest in the program -`Gnomovision' (which makes passes at compilers) written by James Hacker. - -@var{signature of Ty Coon}, 1 April 1989 -Ty Coon, President of Vice -@end example - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. - - -@node Index, , Copying, Top -@unnumbered Index - -@printindex cp - -@contents - -@bye diff --git a/gnu/lib/libregex/test/TAGS b/gnu/lib/libregex/test/TAGS deleted file mode 100644 index d3aad75..0000000 --- a/gnu/lib/libregex/test/TAGS +++ /dev/null @@ -1,373 +0,0 @@ - -.././regex.c,4137 -#define AT_STRINGS_BEG(3078,98376 -#define AT_STRINGS_END(3079,98449 -#define AT_WORD_BOUNDARY(3093,99002 -#define BUF_PUSH(887,24995 -#define BUF_PUSH_2(895,25208 -#define BUF_PUSH_3(904,25437 -#define DEBUG_POP(2336,74614 -#define DEBUG_PRINT1(471,14296 -#define DEBUG_PRINT1(785,21263 -#define DEBUG_PRINT2(472,14342 -#define DEBUG_PRINT3(473,14398 -#define DEBUG_PRINT3(787,21316 -#define DEBUG_PRINT4(474,14462 -#define DEBUG_PRINT_COMPILED_PATTERN(475,14534 -#define DEBUG_PRINT_COMPILED_PATTERN(789,21386 -#define DEBUG_PRINT_DOUBLE_STRING(477,14637 -#define DEBUG_PUSH(2338,74684 -#define DEBUG_STATEMENT(470,14267 -#define DOUBLE_FAIL_STACK(2299,73230 -#define EVER_MATCHED_SOMETHING(3028,96680 -#define EXTEND_BUFFER(941,26834 -#define EXTRACT_NUMBER(403,12499 -#define EXTRACT_NUMBER(422,12960 -#define EXTRACT_NUMBER_AND_INCR(430,13181 -#define EXTRACT_NUMBER_AND_INCR(448,13583 -#define FAIL_STACK_EMPTY(2271,72289 -#define FAIL_STACK_FULL(2273,72404 -#define FAIL_STACK_PTR_EMPTY(2272,72344 -#define FAIL_STACK_TOP(2274,72473 -#define FIRST_STRING_P(221,5848 -#define FREE_VAR(3100,99186 -#define FREE_VARIABLES(3101,99240 -#define FREE_VARIABLES(3116,99751 -#define GET_BUFFER_SPACE(882,24802 -#define GET_UNSIGNED_NUMBER(1017,29312 -#define INIT_FAIL_STACK(2279,72612 -#define INSERT_JUMP(923,26079 -#define INSERT_JUMP2(927,26236 -#define ISALNUM(147,3407 -#define ISALPHA(148,3455 -#define ISBLANK(135,3062 -#define ISBLANK(137,3116 -#define ISCNTRL(149,3503 -#define ISDIGIT(146,3359 -#define ISGRAPH(140,3185 -#define ISGRAPH(142,3239 -#define ISLOWER(150,3551 -#define ISPRINT(145,3311 -#define ISPUNCT(151,3599 -#define ISSPACE(152,3647 -#define ISUPPER(153,3695 -#define ISXDIGIT(154,3743 -#define IS_ACTIVE(3026,96578 -#define IS_CHAR_CLASS(1035,29793 -#define MATCHED_SOMETHING(3027,96621 -#define MAX(233,6292 -#define MIN(234,6334 -#define PATFETCH(852,23769 -#define PATFETCH_RAW(860,24020 -#define POINTER_TO_OFFSET(3050,97433 -#define POP_FAILURE_ITEM(2331,74426 -#define POP_FAILURE_POINT(2461,79538 -#define PREFETCH(3064,97916 -#define PUSH_FAILURE_ITEM(2327,74253 -#define PUSH_FAILURE_POINT(2352,75048 -#define PUSH_PATTERN_OP(2317,73841 -#define REGEX_REALLOCATE(185,4875 -#define REGEX_REALLOCATE(210,5495 -#define REGEX_TALLOC(227,6137 -#define REG_MATCH_NULL_STRING_P(3025,96511 -#define REG_UNSET(3055,97649 -#define RETALLOC(226,6058 -#define SET_LIST_BIT(1011,29089 -#define SET_REGS_MATCHED(3034,96936 -#define SIGN_EXTEND_CHAR(166,4109 -#define SIGN_EXTEND_CHAR(169,4217 -#define STORE_JUMP(915,25800 -#define STORE_JUMP2(919,25917 -#define STORE_NUMBER(384,11919 -#define STORE_NUMBER_AND_INCR(394,12242 -#define STREQ(231,6244 -#define SYNTAX(120,2790 -#define TALLOC(225,6003 -#define TRANSLATE(873,24503 -#define WORDCHAR_P(3086,98755 -alt_match_null_string_p 4466,149039 -#define assert(782,21217 -at_begline_loc_p 2131,67979 -at_endline_loc_p 2150,68557 -#define bcmp(54,1656 -bcmp_translate 4591,151831 -#define bcopy(57,1726 -typedef char boolean;236,6377 -#define bzero(60,1793 -common_op_match_null_string_p 4503,149895 -compile_range 2200,69997 -} compile_stack_elt_t;990,28602 -} compile_stack_type;998,28748 -extract_number 411,12714 -extract_number_and_incr 438,13370 -} fail_stack_type;2269,72269 -group_in_compile_stack 2172,69174 -group_match_null_string_p 4357,145267 -init_syntax_once 94,2365 -insert_op1 2091,67107 -insert_op2 2110,67475 -#define isascii(131,3018 -typedef int pattern_offset_t;981,28388 -print_compiled_pattern 726,19792 -print_double_string 753,20605 -print_fastmap 486,14835 -print_partial_compiled_pattern 518,15475 -re_comp 4650,153479 -re_compile_fastmap 2532,82428 -re_compile_pattern 4617,152520 -re_exec 4688,154373 -re_match 3136,100557 -re_match_2 3161,101399 -} re_opcode_t;378,11781 -re_search 2844,90872 -re_search_2 2877,91998 -re_set_registers 2817,90247 -re_set_syntax 808,22087 -regcomp 4736,155972 -regerror 4876,160188 -regex_compile 1062,30922 -regexec 4811,158371 -regfree 4920,161247 -} register_info_type;3023,96488 -typedef unsigned regnum_t;974,28172 -store_op1 2063,66535 -store_op2 2076,66768 -typedef const unsigned 2262,72103 - -.././regex.h,230 -#define _RE_ARGS(394,14981 -#define _RE_ARGS(398,15036 -} reg_errcode_t;270,10874 -typedef unsigned reg_syntax_t;38,1503 -typedef struct re_pattern_buffer regex_t;346,13556 -} regmatch_t;382,14634 -typedef int regoff_t;354,13814 - -getpagesize.h,84 -#define getpagesize(12,137 -#define getpagesize(15,191 -#define getpagesize(20,302 - -test.h,436 -#define BRACES_TO_OPS(107,3169 -#define INVALID_PATTERN(110,3328 -#define MATCH_SELF(114,3429 -#define PARENS_TO_OPS(108,3248 -#define SAFE_STRLEN(14,201 -#define TEST_POSITIONED_MATCH(116,3470 -#define TEST_REGISTERS(104,3011 -#define TEST_REGISTERS_2(97,2703 -#define TEST_SEARCH(127,3875 -#define TEST_SEARCH_2(123,3720 -#define TEST_TRUNCATED_MATCH(120,3608 -typedef enum { false = 0, true = 1 } boolean;16,255 -} test_type;33,572 - -alloca.c,128 -alloca 141,3996 -find_stack_direction 85,2553 -} header;127,3538 -typedef void *pointer;51,1721 -typedef char *pointer;53,1778 - -bsd-interf.c,51 -test_berk_search 8,106 -test_bsd_interface 33,738 - -debugmalloc.c,395 -#define TRACE(8,143 -#define TRACE1(9,197 -#define TRACE2(10,254 -#define TRACE3(11,319 -#define TRACE4(12,392 -#define USER_ALLOC(61,1440 -typedef char *address;15,480 -} *chunk;54,1225 -chunk_delete 115,2778 -chunk_insert 96,2294 -chunk_to_mem 79,1916 -free 261,5604 -free_list_available 175,3947 -malloc 203,4343 -mem_to_chunk 68,1703 -realloc 242,5309 -validate_list 153,3478 -xsbrk 21,545 - -emacsmalloc.c,574 -#define ASSERT(178,5884 -#define ASSERT(181,5985 -#define CHAIN(166,5430 -#define bcmp(73,2821 -#define bcopy(72,2777 -#define bzero(74,2868 -calloc 603,15983 -free 484,13255 -get_lim_data 736,18517 -get_lim_data 752,18767 -get_lim_data 759,18860 -getpool 374,10263 -malloc 413,11133 -malloc_init 218,6863 -malloc_mem_free 707,17940 -malloc_mem_used 688,17683 -malloc_stats 663,17320 -malloc_usable_size 233,7147 -memalign 618,16164 -morecore 244,7380 -realloc 541,14424 -#define start_of_data(110,3486 -#define start_of_data(115,3546 -sys_sbrk 815,20804 -valloc 645,17031 - -fileregex.c,13 -main 11,156 - -g++malloc.c,1543 -#define UPDATE_STATS(33,1090 -#define UPDATE_STATS(35,1131 -static inline int aligned_OK(343,11189 -void* calloc(1039,28692 -void cfree(1048,28894 -static inline void* chunk2mem(619,19336 -#define clear_inuse(592,18767 -static inline void consollink(716,21398 -static void do_free_stats(544,18016 -static void do_malloc_stats(534,17741 -766,22304 -extern 762,22235 - for 1260,34165 -void free(1028,28553 -static inline void frontlink(732,21717 -static unsigned int gcd(557,18251 - if 1212,32427 - if 1216,32582 - if 1220,32737 - if 1224,32880 - if 1229,33094 - if 1233,33251 - if 1238,33463 - if 1242,33609 - if 1247,33739 -#define inuse(590,18680 -static inline unsigned int lcm(580,18540 -void* malloc(939,26370 -static mchunkptr malloc_find_space(858,24561 -void malloc_stats(1201,32256 -unsigned int malloc_usable_size(1054,28936 -static volatile void malloc_user_error(286,9757 -static void malloc_user_error(288,9804 -typedef struct malloc_bin* mbinptr;320,10636 -typedef struct malloc_chunk* mchunkptr;309,10247 -static inline mchunkptr mem2chunk(643,19759 -void* memalign(1118,30363 -#define next_chunk(600,18910 -#define prev_chunk(604,19023 -void* realloc(1071,29263 -static inline unsigned int request2size(335,10993 -mchunkptr sanity_check(628,19486 -#define set_inuse(591,18723 -static inline void set_size(609,19149 -static inline mbinptr size2bin(499,16914 -static inline void split(685,20463 -static 768,22312 -static inline void unlink(671,20263 -void* valloc(1194,32107 -typedef volatile void 760,22184 -764,22271 - -iregex.c,54 -main 20,390 -print_regs 141,2638 -scanstring 87,1839 - -main.c,13 -main 12,242 - -malloc-test.c,112 -#define BITS_BLOCK(12,168 -#define BITS_MASK(13,228 -} bits_list_type;6,56 -init_bits_list 16,311 -main(32,621 - -other.c,18 -test_others 6,96 - -printchar.c,15 -printchar 2,5 - -psx-basic.c,23 -test_posix_basic 7,84 - -psx-extend.c,26 -test_posix_extended 7,88 - -psx-generic.c,26 -test_posix_generic 8,117 - -psx-group.c,20 -test_grouping 7,92 - -psx-interf.c,416 -fill_pmatch 174,4802 -get_error_string 18,260 -init_pattern_buffer 49,1434 -test_compile 67,1925 -test_eflags 245,6876 -test_error_code_allocation 562,16619 -test_error_code_message 524,15247 -test_ignore_case 303,8525 -test_newline 330,9199 -test_nsub 117,3319 -test_pmatch 188,5121 -test_posix_interface 614,18719 -test_posix_match 359,9938 -test_regcomp 138,3725 -test_regerror 592,17621 -test_regexec 394,10783 - -psx-interv.c,21 -test_intervals 6,93 - -test.c,607 -#define SET_FASTMAP(447,13999 -#define bcmp(18,362 -#define bcopy(19,415 -#define bzero(20,473 -compile_and_print_pattern 666,19653 -concat 97,2673 -delimiters_to_ops 571,17477 -general_test 115,2996 -invalid_pattern 542,16821 -#define memcmp(26,611 -#define memcpy(27,660 -print_pattern_info 635,18998 -set_all_registers 58,1390 -test_all_registers 506,15567 -test_case_fold 682,19993 -test_fastmap 460,14363 -test_fastmap_search 474,14668 -test_match 776,22235 -test_match_2 766,22040 -test_match_n_times 715,20798 -test_search_return 408,13011 -valid_nonposix_pattern 646,19239 -valid_pattern 557,17182 - -tregress.c,208 -#define SIMPLE_MATCH(74,1463 -#define SIMPLE_NONMATCH(75,1528 -do_match 78,1599 -itoa 10,199 -simple_compile 44,882 -simple_fail 21,353 -simple_fastmap 55,1115 -simple_search 100,2020 -test_regress 124,2513 - -upcase.c,0 - -xmalloc.c,14 -xmalloc 9,87 diff --git a/gnu/libexec/uucp/common_sources/conf.h b/gnu/libexec/uucp/common_sources/conf.h deleted file mode 100644 index 9053c44..0000000 --- a/gnu/libexec/uucp/common_sources/conf.h +++ /dev/null @@ -1,444 +0,0 @@ -/* conf.h. Generated automatically by configure. */ -/* Configuration header file for Taylor UUCP. -*- C -*- */ - -/* Set MAIL_PROGRAM to a program which takes a mail address as an - argument and accepts a mail message to send to that address on - stdin (e.g. "/bin/mail"). */ -#define MAIL_PROGRAM "/usr/bin/mail" - -/* Set ECHO_PROGRAM to a program which echoes its arguments; if echo - is a shell builtin you can just use "echo". */ -#define ECHO_PROGRAM "echo" - -/* The following macros indicate what header files you have. Set the - macro to 1 if you have the corresponding header file, or 0 if you - do not. */ -#define HAVE_STDDEF_H 1 /* */ -#define HAVE_STRING_H 1 /* */ -#define HAVE_STRINGS_H 1 /* */ -#define HAVE_UNISTD_H 1 /* */ -#define HAVE_STDLIB_H 1 /* */ -#define HAVE_LIMITS_H 1 /* */ -#define HAVE_TIME_H 1 /* */ -#define HAVE_SYS_WAIT_H 1 /* */ -#define HAVE_SYS_IOCTL_H 1 /* */ -#define HAVE_DIRENT_H 1 /* */ -#define HAVE_MEMORY_H 1 /* */ -#define HAVE_SYS_PARAM_H 1 /* */ -#define HAVE_UTIME_H 1 /* */ -#define HAVE_FCNTL_H 1 /* */ -#define HAVE_SYS_FILE_H 1 /* */ -#define HAVE_SYS_TIMES_H 1 /* */ -#define HAVE_LIBC_H 0 /* */ -#define HAVE_SYSEXITS_H 1 /* */ -#define HAVE_POLL_H 0 /* */ -#define HAVE_TIUSER_H 0 /* */ -#define HAVE_XTI_H 0 /* */ -#define HAVE_SYS_TLI_H 0 /* */ -#define HAVE_STROPTS_H 0 /* */ -#define HAVE_FTW_H 0 /* */ -#define HAVE_GLOB_H 1 /* */ -#define HAVE_SYS_SELECT_H 0 /* */ -#define HAVE_SYS_TYPES_TCP_H 0 /* */ - -/* If major and minor are not defined in , but are in - , set MAJOR_IN_MKDEV to 1. If they are in - , set MAJOR_IN_SYSMACROS to 1. */ -#define MAJOR_IN_MKDEV 0 -#define MAJOR_IN_SYSMACROS 0 - -/* If the macro offsetof is not defined in , you may give it - a definition here. If you do not, the code will use a definition - (in uucp.h) that should be fairly portable. */ -/* #define offsetof */ - -/* Set RETSIGTYPE to the return type of a signal handler. On newer - systems this will be void; some older systems use int. */ -#define RETSIGTYPE void - -/* Set HAVE_SYS_TIME_AND_TIME_H to 1 if and can both - be included in a single source file; if you don't have either or both of - them, it doesn't matter what you set this to. */ -#define HAVE_SYS_TIME_AND_TIME_H 1 - -/* Set HAVE_TERMIOS_AND_SYS_IOCTL_H to 1 if and - can both be included in a single source file; if you don't have either - or both of them, it doesn't matter what you set this to. */ -#define HAVE_TERMIOS_AND_SYS_IOCTL_H 1 - -/* If you are configuring by hand, you should set one of the terminal - driver options in policy.h. If you are autoconfiguring, the script - will check whether your system defines CBREAK, which is a terminal - setting; if your system supports CBREAK, and you don't set a terminal - driver in policy.h, the code will assume that you have a BSD style - terminal driver. */ -#define HAVE_CBREAK 1 - -/* The package needs several standard types. If you are using the - configure script, it will look in standard places for these types, - and give default definitions for them here if it doesn't find them. - The default definitions should work on most systems, but you may - want to check them. If you are configuring by hand, you will have - to figure out whether the types are defined on your system, and - what they should be defined to. - - Any type that is not defined on your system should get a macro - definition. The definition should be of the name of the type in - all capital letters. For example, #define PID_T int. If the type - is defined in a standard header file, the macro name should not be - defined. */ - -/* The type pid_t is used to hold a process ID number. It is normally - defined in . This is the type returned by the - functions fork or getpid. Usually int will work fine. */ -#undef PID_T - -/* The type uid_t is used to hold a user ID number. It is normally - defined in . This is the type returned by the getuid - function. Usually int will work fine. */ -#undef UID_T - -/* The type gid_t is used to hold a group ID number. It is sometimes - defined in . This is the type returned by the getgid - function. Usually int will work fine. */ -#undef GID_T - -/* The type off_t is used to hold an offset in a file. It is sometimes - defined in . This is the type of the second argument to - the lseek function. Usually long will work fine. */ -#undef OFF_T - -/* Set HAVE_SIG_ATOMIC_T_IN_SIGNAL_H if the type sig_atomic_t is defined - in as required by ANSI C. */ -#define HAVE_SIG_ATOMIC_T_IN_SIGNAL_H 0 - -/* Set HAVE_SIG_ATOMIC_T_IN_TYPES_H if the type sig_atomic_t is defined - in . This is ignored if HAVE_SIG_ATOMIC_T_IN_SIGNAL_H is - set to 1. */ -#define HAVE_SIG_ATOMIC_T_IN_TYPES_H 0 - -/* The type sig_atomic_t is used to hold a value which may be - referenced in a single atomic operation. If it is not defined in - either or , you may want to give it a - definition here. If you don't, the code will use char. If your - compiler does not support sig_atomic_t, there is no type which is - really correct; fortunately, for this package it does not really - matter very much. */ -#undef SIG_ATOMIC_T - -/* Set HAVE_SIZE_T_IN_STDDEF_H to 1 if the type size_t is defined in - as required by ANSI C. */ -#define HAVE_SIZE_T_IN_STDDEF_H 1 - -/* Set HAVE_SIZE_T_IN_TYPES_H to 1 if the type size_t is defined in - . This is ignored if HAVE_SIZE_T_IN_STDDEF_H is set - to 1. */ -#define HAVE_SIZE_T_IN_TYPES_H 1 - -/* The type size_t is used to hold the size of an object. In - particular, an argument of this type is passed as the size argument - to the malloc and realloc functions. If size_t is not defined in - either or , you may want to give it a - definition here. If you don't, the code will use unsigned. */ -#undef SIZE_T - -/* Set HAVE_TIME_T_IN_TIME_H to 1 if the type time_t is defined in - , as required by the ANSI C standard. */ -#define HAVE_TIME_T_IN_TIME_H 1 - -/* Set HAVE_TIME_T_IN_TYPES_H to 1 if the type time_t is defined in - . This is ignored if HAVE_TIME_T_IN_TIME_H is set to - 1. */ -#define HAVE_TIME_T_IN_TYPES_H 1 - -/* When Taylor UUCP is talking to another instance of itself, it will - tell the other side the size of a file before it is transferred. - If the package can determine how much disk space is available, it - will use this information to avoid filling up the disk. Define one - of the following macros to tell the code how to determine the - amount of available disk space. It is possible that none of these - are appropriate; it will do no harm to use none of them, but, of - course, nothing will then prevent the package from filling up the - disk. Note that this space check is only useful when talking to - another instance of Taylor UUCP. - - STAT_STATVFS statvfs function - STAT_STATFS2_BSIZE two argument statfs function with f_bsize field - STAT_STATFS2_FSIZE two argument statfs function with f_fsize field - STAT_STATFS2_FS_DATA two argument statfs function with fd_req field - STAT_STATFS4 four argument statfs function - STAT_USTAT the ustat function with 512 byte blocks. */ -#define STAT_STATVFS 0 -#define STAT_STATFS2_BSIZE 0 -#define STAT_STATFS2_FSIZE 1 -#define STAT_STATFS2_FS_DATA 0 -#define STAT_STATFS4 0 -#define STAT_USTAT 0 - -/* Set HAVE_VOID to 1 if the compiler supports declaring functions with - a return type of void and casting values to void. */ -#define HAVE_VOID 1 - -/* Set HAVE_UNSIGNED_CHAR to 1 if the compiler supports the type unsigned - char. */ -#define HAVE_UNSIGNED_CHAR 1 - -/* Set HAVE_ERRNO_DECLARATION to 1 if errno is declared in . */ -#define HAVE_ERRNO_DECLARATION 1 - -/* There are now a number of functions to check for. For each of - these, the macro HAVE_FUNC should be set to 1 if your system has - FUNC. For example, HAVE_VFPRINTF should be set to 1 if your system - has vfprintf, 0 otherwise. */ - -/* Taylor UUCP will take advantage of the following functions if they - are available, but knows how to deal with their absence. */ -#define HAVE_VFPRINTF 1 -#define HAVE_FTRUNCATE 1 -#define HAVE_LTRUNC 0 -#define HAVE_WAITPID 1 -#define HAVE_WAIT4 1 -#define HAVE_GLOB 1 -#define HAVE_SETREUID 1 - -/* There are several functions which are replaced in the subdirectory - lib. If they are missing, the configure script will automatically - add them to lib/Makefile to force them to be recompiled. If you - are configuring by hand, you will have to do this yourself. The - string @LIBOBJS@ in lib/Makefile.in should be replaced by a list of - object files in lib/Makefile. The following comments tell you - which object file names to add (they are generally fairly obvious, - given that the file names have no more than six characters before - the period). */ - -/* For each of these functions, if it does not exist, the indicated - object file should be added to lib/Makefile. */ -#define HAVE_BSEARCH 1 /* bsrch.o */ -#define HAVE_GETLINE 0 /* getlin.o */ -#define HAVE_MEMCHR 1 /* memchr.o */ -#define HAVE_STRDUP 1 /* strdup.o */ -#define HAVE_STRSTR 1 /* strstr.o */ -#define HAVE_STRTOL 1 /* strtol.o */ - -/* If neither of these functions exists, you should add bzero.o to - lib/Makefile. */ -#define HAVE_BZERO 1 -#define HAVE_MEMSET 1 - -/* If neither of these functions exists, you should add memcmp.o to - lib/Makefile. */ -#define HAVE_MEMCMP 1 -#define HAVE_BCMP 1 - -/* If neither of these functions exists, you should add memcpy.o to - lib/Makefile. */ -#define HAVE_MEMCPY 1 -#define HAVE_BCOPY 1 - -/* If neither of these functions exists, you should add strcas.o to - lib/Makefile. */ -#define HAVE_STRCASECMP 1 -#define HAVE_STRICMP 0 - -/* If neither of these functions exists, you should add strncs.o to - lib/Makefile. */ -#define HAVE_STRNCASECMP 1 -#define HAVE_STRNICMP 0 - -/* If neither of these functions exists, you should add strchr.o to - lib/Makefile. */ -#define HAVE_STRCHR 1 -#define HAVE_INDEX 1 - -/* If neither of these functions exists, you should add strrch.o to - lib/Makefile. */ -#define HAVE_STRRCHR 1 -#define HAVE_RINDEX 1 - -/* There are also Unix specific functions which are replaced in the - subdirectory unix. If they are missing, the configure script will - automatically add them to unix/Makefile to force them to be - recompiled. If you are configuring by hand, you will have to do - this yourself. The string @UNIXOBJS@ in unix/Makefile.in should be - replaced by a list of object files in unix/Makefile. The following - comments tell you which object file names to add. */ - -/* For each of these functions, if it does not exist, the indicated - object file should be added to unix/Makefile. */ -#define HAVE_OPENDIR 1 /* dirent.o */ -#define HAVE_DUP2 1 /* dup2.o */ -#define HAVE_FTW 0 /* ftw.o */ -#define HAVE_REMOVE 1 /* remove.o */ -#define HAVE_RENAME 1 /* rename.o */ -#define HAVE_STRERROR 1 /* strerr.o */ - -/* The code needs to know how to create directories. If you have the - mkdir function, set HAVE_MKDIR to 1 and replace @UUDIR@ in - Makefile.in with '# ' (the configure script will set @UUDIR@ - according to the variable UUDIR). Otherwise, set HAVE_MKDIR to 0, - remove @UUDIR@ from Makefile.in, set MKDIR_PROGRAM to the name of - the program which will create a directory named on the command line - (e.g., "/bin/mkdir"), and add mkdir.o to the @UNIXOBJS@ string in - unix/Makefile.in. */ -#define HAVE_MKDIR 1 -#define MKDIR_PROGRAM unused - -/* The code also needs to know how to remove directories. If you have - the rmdir function, set HAVE_RMDIR to 1. Otherwise, set - RMDIR_PROGRAM to the name of the program which will remove a - directory named on the command line (e.g., "/bin/rmdir") and add - rmdir.o to the @UNIXOBJS@ string in unix/Makefile.in. */ -#define HAVE_RMDIR 1 -#define RMDIR_PROGRAM unused - -/* The code needs to know to how to get the name of the current - directory. If getcwd is available it will be used, otherwise if - getwd is available it will be used. Otherwise, set PWD_PROGRAM to - the name of the program which will print the name of the current - working directory (e.g., "/bin/pwd") and add getcwd.o to the - @UNIXOBJS@ string in unix/Makefile.in. */ -#define HAVE_GETCWD 1 -#define HAVE_GETWD 1 -#define PWD_PROGRAM unused - -/* If you have either sigsetjmp or setret, it will be used instead of - setjmp. These functions will only be used if your system restarts - system calls after interrupts (see HAVE_RESTARTABLE_SYSCALLS, - below). */ -#define HAVE_SIGSETJMP 0 -#define HAVE_SETRET 0 - -/* The code needs to know what function to use to set a signal - handler. If will try to use each of the following functions in - turn. If none are available, it will use signal, which is assumed - to always exist. */ -#define HAVE_SIGACTION 1 -#define HAVE_SIGVEC 1 -#define HAVE_SIGSET 0 - -/* If the code is going to use sigvec (HAVE_SIGACTION is 0 and - HAVE_SIGVEC is 1), then HAVE_SIGVEC_SV_FLAGS must be set to 1 if - the sigvec structure contains the sv_flags field, or 0 if the - sigvec structure contains the sv_onstack field. If the code is not - going to use sigvec, it doesn't matter what this is set to. */ -#define HAVE_SIGVEC_SV_FLAGS 1 - -/* The code will try to use each of the following functions in turn - when blocking signals from delivery. If none are available, a - relatively unimportant race condition will exist. */ -#define HAVE_SIGPROCMASK 1 -#define HAVE_SIGBLOCK 1 -#define HAVE_SIGHOLD 0 - -/* If you have either of the following functions, it will be used to - determine the number of file descriptors which may be open. - Otherwise, the code will use OPEN_MAX if defined, then NOFILE if - defined, then 20. */ -#define HAVE_GETDTABLESIZE 1 -#define HAVE_SYSCONF 0 - -/* The code will use one of the following functions when detaching - from a terminal. One of these must exist. */ -#define HAVE_SETPGRP 0 -#define HAVE_SETSID 1 - -/* If you do not specify the local node name in the main configuration - file, Taylor UUCP will try to use each of the following functions - in turn. If neither is available, you must specify the local node - name in the configuration file. */ -#define HAVE_GETHOSTNAME 1 -#define HAVE_UNAME 0 - -/* The code will try to use each of the following functions in turn to - determine the current time. If none are available, it will use - time, which is assumed to always exist. */ -#define HAVE_GETTIMEOFDAY 1 -#define HAVE_FTIME 0 - -/* If neither gettimeofday nor ftime is available, the code will use - times (if available) to measure a span of time. See also the - discussion of TIMES_TICK in policy.h. */ -#define HAVE_TIMES 1 - -/* When a chat script requests a pause of less than a second with \p, - Taylor UUCP will try to use each of the following functions in - turn. If none are available, it will sleep for a full second. - Also, the (non-portable) tstuu program requires either select or - poll. */ -#define HAVE_NAPMS 0 -#define HAVE_NAP 0 -#define HAVE_USLEEP 1 -#define HAVE_POLL 0 -#define HAVE_SELECT 1 - -/* If the getgrent function is available, it will be used to determine - all the groups a user belongs to when checking file access - permissions. */ -#define HAVE_GETGRENT 1 - -/* If the socket function is available, TCP support code will be - compiled in. */ -#define HAVE_SOCKET 1 - -/* If the t_open function is available, TLI support code will be - compiled in. This may require adding a library, such as -lnsl or - -lxti, to the Makefile variables LIBS. */ -#define HAVE_T_OPEN 0 - -/* That's the end of the list of the functions. Now there are a few - last miscellaneous items. */ - -/* On some systems the following functions are declared in such a way - that the code cannot make a simple extern. On other systems, these - functions are not declared at all, and the extern is required. If - a declaration of the function, as shown, compiles on your system, - set the value to 1. Not all functions declared externally are - listed here, only the ones with which I have had trouble. */ -/* extern long times (); */ -#define TIMES_DECLARATION_OK 0 -/* extern struct passwd *getpwnam (); */ -#define GETPWNAM_DECLARATION_OK 1 -/* extern struct passwd *getpwuid (); */ -#define GETPWUID_DECLARATION_OK 0 -/* extern struct group *getgrent (); */ -#define GETGRENT_DECLARATION_OK 1 - -/* Set HAVE_BSD_PGRP to 1 if your getpgrp call takes 1 argument and - your setpgrp calls takes 2 arguments (on System V they generally - take no arguments). You can safely set this to 1 on System V, - provided the call will compile without any errors. */ -#define HAVE_BSD_PGRP 0 - -/* Set HAVE_UNION_WAIT to 1 if union wait is defined in the header - file . */ -#define HAVE_UNION_WAIT 1 - -/* Set HAVE_LONG_FILE_NAMES to 1 if the system supports file names - longer than 14 characters. */ -#define HAVE_LONG_FILE_NAMES 1 - -/* If slow system calls are restarted after interrupts, set - HAVE_RESTARTABLE_SYSCALLS to 1. This is ignored if HAVE_SIGACTION - is 1 or if HAVE_SIGVEC is 1 and HAVE_SIGVEC_SV_FLAGS is 1 and - SV_INTERRUPT is defined in . In both of these cases - system calls can be prevented from restarting. */ -#define HAVE_RESTARTABLE_SYSCALLS 1 - -/* Some systems supposedly need the following macros to be defined. - These are handled by the configure script (it will turn #undef into - #define when appropriate, which is why the peculiar #ifndef #undef - construction is used). If you are configuring by hand, you may add - appropriate definitions here, or just add them to CFLAGS when - running make. */ -#ifndef _ALL_SOURCE -#undef _ALL_SOURCE -#endif -#ifndef _POSIX_SOURCE -#undef _POSIX_SOURCE -#endif -#ifndef _MINIX -#undef _MINIX -#endif -#ifndef _POSIX_1_SOURCE -#undef _POSIX_1_SOURCE -#endif diff --git a/gnu/libexec/uucp/common_sources/tcp.c b/gnu/libexec/uucp/common_sources/tcp.c deleted file mode 100644 index 161e5f9e..0000000 --- a/gnu/libexec/uucp/common_sources/tcp.c +++ /dev/null @@ -1,477 +0,0 @@ -/* tcp.c - Code to handle TCP connections. - - Copyright (C) 1991, 1992, 1993 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - 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 of the - License, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, Building 200, 1 Kendall Square, Cambridge, MA 02139. - */ - -#include "uucp.h" - -#if USE_RCS_ID -const char tcp_rcsid[] = "$Id: tcp.c,v 1.2 1994/05/07 18:09:01 ache Exp $"; -#endif - -#if HAVE_TCP - -#include "uudefs.h" -#include "uuconf.h" -#include "sysdep.h" -#include "conn.h" -#include "system.h" - -#include - -#if HAVE_SYS_TYPES_TCP_H -#include -#endif -#include -#include -#include - -#if HAVE_FCNTL_H -#include -#else -#if HAVE_SYS_FILE_H -#include -#endif -#endif - -#ifndef FD_CLOEXEC -#define FD_CLOEXEC 1 -#endif - -/* This code handles TCP connections. It assumes a Berkeley socket - interface. */ - -/* The normal "uucp" port number. */ -#define IUUCP_PORT (540) - -/* Local functions. */ -static void utcp_free P((struct sconnection *qconn)); -static boolean ftcp_open P((struct sconnection *qconn, long ibaud, - boolean fwait)); -static boolean ftcp_close P((struct sconnection *qconn, - pointer puuconf, - struct uuconf_dialer *qdialer, - boolean fsuccess)); -static boolean ftcp_dial P((struct sconnection *qconn, pointer puuconf, - const struct uuconf_system *qsys, - const char *zphone, - struct uuconf_dialer *qdialer, - enum tdialerfound *ptdialer)); -static int itcp_port_number P((const char *zport)); - -/* The command table for a TCP connection. */ -static const struct sconncmds stcpcmds = -{ - utcp_free, - NULL, /* pflock */ - NULL, /* pfunlock */ - ftcp_open, - ftcp_close, - ftcp_dial, - fsysdep_conn_read, - fsysdep_conn_write, - fsysdep_conn_io, - NULL, /* pfbreak */ - NULL, /* pfset */ - NULL, /* pfcarrier */ - fsysdep_conn_chat, - NULL /* pibaud */ -}; - -/* Initialize a TCP connection. */ - -boolean -fsysdep_tcp_init (qconn) - struct sconnection *qconn; -{ - struct ssysdep_conn *q; - - q = (struct ssysdep_conn *) xmalloc (sizeof (struct ssysdep_conn)); - q->o = -1; - q->ord = -1; - q->owr = -1; - q->zdevice = NULL; - q->iflags = -1; - q->iwr_flags = -1; - q->fterminal = FALSE; - q->ftli = FALSE; - q->ibaud = 0; - - qconn->psysdep = (pointer) q; - qconn->qcmds = &stcpcmds; - return TRUE; -} - -/* Free a TCP connection. */ - -static void -utcp_free (qconn) - struct sconnection *qconn; -{ - xfree (qconn->psysdep); -} - -/* Open a TCP connection. If the fwait argument is TRUE, we are - running as a server. Otherwise we are just trying to reach another - system. */ - -static boolean -ftcp_open (qconn, ibaud, fwait) - struct sconnection *qconn; - long ibaud; - boolean fwait; -{ - struct ssysdep_conn *qsysdep; - struct sockaddr_in s; - const char *zport; - uid_t iuid, ieuid; - - ulog_device ("TCP"); - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - - qsysdep->o = socket (AF_INET, SOCK_STREAM, 0); - if (qsysdep->o < 0) - { - ulog (LOG_ERROR, "socket: %s", strerror (errno)); - return FALSE; - } - - if (fcntl (qsysdep->o, F_SETFD, - fcntl (qsysdep->o, F_GETFD, 0) | FD_CLOEXEC) < 0) - { - ulog (LOG_ERROR, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - (void) close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } - - qsysdep->iflags = fcntl (qsysdep->o, F_GETFL, 0); - if (qsysdep->iflags < 0) - { - ulog (LOG_ERROR, "fcntl: %s", strerror (errno)); - (void) close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } - - /* We save our process ID in the qconn structure. This is checked - in ftcp_close. */ - qsysdep->ipid = getpid (); - - /* If we aren't waiting for a connection, we're done. */ - if (! fwait) - return TRUE; - - /* Run as a server and wait for a new connection. The code in - uucico.c has already detached us from our controlling terminal. - From this point on if the server gets an error we exit; we only - return if we have received a connection. It would be more robust - to respawn the server if it fails; someday. */ - bzero ((pointer) &s, sizeof s); - s.sin_family = AF_INET; - zport = qconn->qport->uuconf_u.uuconf_stcp.uuconf_zport; - s.sin_port = itcp_port_number (zport); - s.sin_addr.s_addr = htonl (INADDR_ANY); - - /* Swap to our real user ID when doing the bind call. This will - permit the server to use privileged TCP ports when invoked by - root. We only swap if our effective user ID is not root, so that - the program can also be made suid root in order to get privileged - ports when invoked by anybody. */ - iuid = getuid (); - ieuid = geteuid (); - if (ieuid != 0) - { -#if HAVE_SETREUID - /* Swap the effective user id and the real user id. We can then - swap them back again when we want to return to the uucp - user's permissions. */ - if (setreuid (ieuid, iuid) < 0) - { - ulog (LOG_ERROR, "setreuid (%ld, %ld): %s", - (long) ieuid, (long) iuid, strerror (errno)); - (void) close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } -#else /* ! HAVE_SETREUID */ -#if HAVE_SAVED_SETUID - /* Set the effective user id to the real user id. Since the - effective user id is the saved setuid we will able to set - back to it later. If the real user id is root we will not be - able to switch back and forth, but that doesn't matter since - we only want to switch once. */ - if (setuid (iuid) < 0) - { - ulog (LOG_ERROR, "setuid (%ld): %s", (long) iuid, - strerror (errno)); - (void) close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } -#else /* ! HAVE_SAVED_SETUID */ - /* There's no way to switch between real permissions and - effective permissions. Just try the bind with the uucp - permissions. */ -#endif /* ! HAVE_SAVED_SETUID */ -#endif /* ! HAVE_SETREUID */ - } - - if (bind (qsysdep->o, (struct sockaddr *) &s, sizeof s) < 0) - ulog (LOG_FATAL, "bind: %s", strerror (errno)); - - /* Now swap back to the uucp user ID. */ - if (ieuid != 0) - { -#if HAVE_SETREUID - if (setreuid (iuid, ieuid) < 0) - { - ulog (LOG_ERROR, "setreuid (%ld, %ld): %s", - (long) iuid, (long) ieuid, strerror (errno)); - (void) close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } -#else /* ! HAVE_SETREUID */ -#if HAVE_SAVED_SETUID - /* Set ourselves back to our original effective user id. */ - if (setuid ((uid_t) ieuid) < 0) - { - ulog (LOG_ERROR, "setuid (%ld): %s", (long) ieuid, - strerror (errno)); - (void) close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } -#else /* ! HAVE_SAVED_SETUID */ - /* We didn't switch, no need to switch back. */ -#endif /* ! HAVE_SAVED_SETUID */ -#endif /* ! HAVE_SETREUID */ - } - - if (listen (qsysdep->o, 5) < 0) - ulog (LOG_FATAL, "listen: %s", strerror (errno)); - - while (! FGOT_SIGNAL ()) - { - size_t clen; - int onew; - pid_t ipid; - - DEBUG_MESSAGE0 (DEBUG_PORT, - "ftcp_open: Waiting for connections"); - - clen = sizeof s; - onew = accept (qsysdep->o, (struct sockaddr *) &s, &clen); - if (onew < 0) - ulog (LOG_FATAL, "accept: %s", strerror (errno)); - - DEBUG_MESSAGE0 (DEBUG_PORT, - "ftcp_open: Got connection; forking"); - - ipid = ixsfork (); - if (ipid < 0) - ulog (LOG_FATAL, "fork: %s", strerror (errno)); - if (ipid == 0) - { - (void) close (qsysdep->o); - qsysdep->o = onew; - - /* Now we fork and let our parent die, so that we become - a child of init. This lets the main server code wait - for its child and then continue without accumulating - zombie children. */ - ipid = ixsfork (); - if (ipid < 0) - { - ulog (LOG_ERROR, "fork: %s", strerror (errno)); - _exit (EXIT_FAILURE); - } - - if (ipid != 0) - _exit (EXIT_SUCCESS); - - ulog_id (getpid ()); - - return TRUE; - } - - (void) close (onew); - - /* Now wait for the child. */ - (void) ixswait ((unsigned long) ipid, (const char *) NULL); - } - - /* We got a signal. */ - usysdep_exit (FALSE); - - /* Avoid compiler warnings. */ - return FALSE; -} - -/* Close the port. */ - -/*ARGSUSED*/ -static boolean -ftcp_close (qconn, puuconf, qdialer, fsuccess) - struct sconnection *qconn; - pointer puuconf; - struct uuconf_dialer *qdialer; - boolean fsuccess; -{ - struct ssysdep_conn *qsysdep; - boolean fret; - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - fret = TRUE; - if (qsysdep->o >= 0 && close (qsysdep->o) < 0) - { - ulog (LOG_ERROR, "close: %s", strerror (errno)); - fret = FALSE; - } - qsysdep->o = -1; - - /* If the current pid is not the one we used to open the port, then - we must have forked up above and we are now the child. In this - case, we are being called from within the fendless loop in - uucico.c. We return FALSE to force the loop to end and the child - to exit. This should be handled in a cleaner fashion. */ - if (qsysdep->ipid != getpid ()) - fret = FALSE; - - return fret; -} - -/* Dial out on a TCP port, so to speak: connect to a remote computer. */ - -/*ARGSUSED*/ -static boolean -ftcp_dial (qconn, puuconf, qsys, zphone, qdialer, ptdialer) - struct sconnection *qconn; - pointer puuconf; - const struct uuconf_system *qsys; - const char *zphone; - struct uuconf_dialer *qdialer; - enum tdialerfound *ptdialer; -{ - struct ssysdep_conn *qsysdep; - const char *zhost; - struct hostent *q; - struct sockaddr_in s; - const char *zport; - char **pzdialer; - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - - *ptdialer = DIALERFOUND_FALSE; - - zhost = zphone; - if (zhost == NULL) - { - if (qsys == NULL) - { - ulog (LOG_ERROR, "No address for TCP connection"); - return FALSE; - } - zhost = qsys->uuconf_zname; - } - - errno = 0; - q = gethostbyname ((char *) zhost); - if (q == NULL) - { - if (errno == 0) - ulog (LOG_ERROR, "%s: unknown host name", zhost); - else - ulog (LOG_ERROR, "gethostbyname (%s): %s", zhost, strerror (errno)); - return FALSE; - } - - s.sin_family = q->h_addrtype; - memcpy (&s.sin_addr.s_addr, q->h_addr, (size_t) q->h_length); - zport = qconn->qport->uuconf_u.uuconf_stcp.uuconf_zport; - s.sin_port = itcp_port_number (zport); - - if (connect (qsysdep->o, (struct sockaddr *) &s, sizeof s) < 0) - { - ulog (LOG_ERROR, "connect: %s", strerror (errno)); - return FALSE; - } - - /* Handle the dialer sequence, if any. */ - pzdialer = qconn->qport->uuconf_u.uuconf_stcp.uuconf_pzdialer; - if (pzdialer != NULL && *pzdialer != NULL) - { - if (! fconn_dial_sequence (qconn, puuconf, pzdialer, qsys, zphone, - qdialer, ptdialer)) - return FALSE; - } - - return TRUE; -} - -/* Get the port number given a name. The argument will almost always - be "uucp" so we cache that value. The return value is always in - network byte order. This returns -1 on error. */ - -static int -itcp_port_number (zname) - const char *zname; -{ - boolean fuucp; - static int iuucp; - int i; - char *zend; - struct servent *q; - - fuucp = strcmp (zname, "uucp") == 0; - if (fuucp && iuucp != 0) - return iuucp; - - /* Try it as a number first. */ - i = strtol ((char *) zname, &zend, 10); - if (i != 0 && *zend == '\0') - return htons (i); - - q = getservbyname ((char *) zname, (char *) "tcp"); - if (q == NULL) - { - /* We know that the "uucp" service should be 540, even if isn't - in /etc/services. */ - if (fuucp) - { - iuucp = htons (IUUCP_PORT); - return iuucp; - } - ulog (LOG_ERROR, "getservbyname (%s): %s", zname, strerror (errno)); - return -1; - } - - if (fuucp) - iuucp = q->s_port; - - return q->s_port; -} - -#endif /* HAVE_TCP */ diff --git a/gnu/libexec/uucp/common_sources/tli.c b/gnu/libexec/uucp/common_sources/tli.c deleted file mode 100644 index db3491a..0000000 --- a/gnu/libexec/uucp/common_sources/tli.c +++ /dev/null @@ -1,582 +0,0 @@ -/* tli.c - Code to handle TLI connections. - - Copyright (C) 1992, 1993, 1994 Ian Lance Taylor - - This file is part of the Taylor UUCP package. - - 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 of the - License, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The author of the program may be contacted at ian@airs.com or - c/o Cygnus Support, Building 200, 1 Kendall Square, Cambridge, MA 02139. - */ - -#include "uucp.h" - -#if USE_RCS_ID -const char tli_rcsid[] = "$Id: tli.c,v 1.2 1994/05/07 18:09:03 ache Exp $"; -#endif - -#if HAVE_TLI - -#include "sysdep.h" -#include "uudefs.h" -#include "uuconf.h" -#include "conn.h" -#include "system.h" - -#include - -#if HAVE_SYS_IOCTL_H -#include -#endif - -#if HAVE_TIUSER_H -#include -#else -#if HAVE_XTI_H -#include -#else -#if HAVE_SYS_TLI_H -#include -#endif -#endif -#endif - -#if HAVE_STROPTS_H -#include -#endif - -#if HAVE_FCNTL_H -#include -#else -#if HAVE_SYS_FILE_H -#include -#endif -#endif - -#ifndef O_RDONLY -#define O_RDONLY 0 -#define O_WRONLY 1 -#define O_RDWR 2 -#endif - -#ifndef FD_CLOEXEC -#define FD_CLOEXEC 1 -#endif - -/* The arguments to t_alloca have two different names. I want the - SVID ones, not the XPG3 ones. */ -#ifndef T_BIND -#define T_BIND T_BIND_STR -#endif -#ifndef T_CALL -#define T_CALL T_CALL_STR -#endif - -/* Hopefully these externs will not cause any trouble. This is how - they are shown in the SVID. */ -extern int t_errno; -extern char *t_errlist[]; -extern int t_nerr; - -#ifndef HAVE_TIUSER_H -#ifndef t_alloc -extern pointer t_alloc (); -#endif -#endif - -/* This code handles TLI connections. It's Unix specific. It's - largely based on code from Unix Network Programming, by W. Richard - Stevens. */ - -/* Local functions. */ -static const char *ztlierror P((void)); -static void utli_free P((struct sconnection *qconn)); -static boolean ftli_push P((struct sconnection *qconn)); -static boolean ftli_open P((struct sconnection *qconn, long ibaud, - boolean fwait)); -static boolean ftli_close P((struct sconnection *qconn, - pointer puuconf, - struct uuconf_dialer *qdialer, - boolean fsuccess)); -static boolean ftli_dial P((struct sconnection *qconn, pointer puuconf, - const struct uuconf_system *qsys, - const char *zphone, - struct uuconf_dialer *qdialer, - enum tdialerfound *ptdialer)); - -/* The command table for a TLI connection. */ -static const struct sconncmds stlicmds = -{ - utli_free, - NULL, /* pflock */ - NULL, /* pfunlock */ - ftli_open, - ftli_close, - ftli_dial, - fsysdep_conn_read, - fsysdep_conn_write, - fsysdep_conn_io, - NULL, /* pfbreak */ - NULL, /* pfset */ - NULL, /* pfcarrier */ - fsysdep_conn_chat, - NULL /* pibaud */ -}; - -/* Get a TLI error string. */ - -static const char * -ztlierror () -{ - if (t_errno == TSYSERR) - return strerror (errno); - if (t_errno < 0 || t_errno >= t_nerr) - return "Unknown TLI error"; - return t_errlist[t_errno]; -} - -/* Initialize a TLI connection. This may be called with qconn->qport - NULL, when opening standard input as a TLI connection. */ - -boolean -fsysdep_tli_init (qconn) - struct sconnection *qconn; -{ - struct ssysdep_conn *q; - - q = (struct ssysdep_conn *) xmalloc (sizeof (struct ssysdep_conn)); - q->o = -1; - q->ord = -1; - q->owr = -1; - q->zdevice = NULL; - q->iflags = -1; - q->iwr_flags = -1; - q->fterminal = FALSE; - q->ftli = TRUE; - q->ibaud = 0; - - qconn->psysdep = (pointer) q; - qconn->qcmds = &stlicmds; - return TRUE; -} - -/* Free a TLI connection. */ - -static void -utli_free (qconn) - struct sconnection *qconn; -{ - xfree (qconn->psysdep); -} - -/* Push all desired modules onto a TLI stream. If the user requests a - STREAMS connection without giving a list of modules, we just push - tirdwr. If the I_PUSH ioctl is not defined on this system, we just - ignore any list of modules. */ - -static boolean -ftli_push (qconn) - struct sconnection *qconn; -{ -#ifdef I_PUSH - - struct ssysdep_conn *qsysdep; - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - - if (qconn->qport->uuconf_u.uuconf_stli.uuconf_pzpush != NULL) - { - char **pz; - - for (pz = qconn->qport->uuconf_u.uuconf_stli.uuconf_pzpush; - *pz != NULL; - pz++) - { - if (ioctl (qsysdep->o, I_PUSH, *pz) < 0) - { - ulog (LOG_ERROR, "ioctl (I_PUSH, %s): %s", *pz, - strerror (errno)); - return FALSE; - } - } - } - else if (qconn->qport->uuconf_u.uuconf_stli.uuconf_fstream) - { - if (ioctl (qsysdep->o, I_PUSH, "tirdwr") < 0) - { - ulog (LOG_ERROR, "ioctl (I_PUSH, tirdwr): %s", - strerror (errno)); - return FALSE; - } - } - - /* If we have just put the connection into stream mode, we must turn - off the TLI flag to avoid using TLI calls on it. */ - if (qconn->qport->uuconf_u.uuconf_stli.uuconf_fstream) - qsysdep->ftli = FALSE; - -#endif /* defined (I_PUSH) */ - - return TRUE; -} - -/* Open a TLI connection. If the fwait argument is TRUE, we are - running as a server. Otherwise we are just trying to reach another - system. */ - -static boolean -ftli_open (qconn, ibaud, fwait) - struct sconnection *qconn; - long ibaud; - boolean fwait; -{ - struct ssysdep_conn *qsysdep; - const char *zdevice; - char *zfreedev; - const char *zservaddr; - char *zfreeaddr; - struct t_bind *qtbind; - struct t_call *qtcall; - - /* Unlike most other device types, we don't bother to call - ulog_device here, because fconn_open calls it with the name of - the port anyhow. */ - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - - zdevice = qconn->qport->uuconf_u.uuconf_stli.uuconf_zdevice; - if (zdevice == NULL) - zdevice = qconn->qport->uuconf_zname; - - zfreedev = NULL; - if (*zdevice != '/') - { - zfreedev = zbufalc (sizeof "/dev/" + strlen (zdevice)); - sprintf (zfreedev, "/dev/%s", zdevice); - zdevice = zfreedev; - } - - qsysdep->o = t_open (zdevice, O_RDWR, (struct t_info *) NULL); - if (qsysdep->o < 0) - { - ulog (LOG_ERROR, "t_open (%s): %s", zdevice, ztlierror ()); - ubuffree (zfreedev); - return FALSE; - } - - if (fcntl (qsysdep->o, F_SETFD, - fcntl (qsysdep->o, F_GETFD, 0) | FD_CLOEXEC) < 0) - { - ulog (LOG_ERROR, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - ubuffree (zfreedev); - (void) t_close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } - - qsysdep->iflags = fcntl (qsysdep->o, F_GETFL, 0); - if (qsysdep->iflags < 0) - { - ulog (LOG_ERROR, "fcntl: %s", strerror (errno)); - ubuffree (zfreedev); - (void) t_close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } - - /* We save our process ID in the qconn structure. This is checked - in ftli_close. */ - qsysdep->ipid = getpid (); - - /* If we aren't waiting for a connection, we can bind to any local - address, and then we're finished. */ - if (! fwait) - { - ubuffree (zfreedev); - if (t_bind (qsysdep->o, (struct t_bind *) NULL, - (struct t_bind *) NULL) < 0) - { - ulog (LOG_ERROR, "t_bind: %s", ztlierror ()); - (void) t_close (qsysdep->o); - qsysdep->o = -1; - return FALSE; - } - return TRUE; - } - - /* Run as a server and wait for a new connection. The code in - uucico.c has already detached us from our controlling terminal. - From this point on if the server gets an error we exit; we only - return if we have received a connection. It would be more robust - to respawn the server if it fails; someday. */ - qtbind = (struct t_bind *) t_alloc (qsysdep->o, T_BIND, T_ALL); - if (qtbind == NULL) - ulog (LOG_FATAL, "t_alloc (T_BIND): %s", ztlierror ()); - - zservaddr = qconn->qport->uuconf_u.uuconf_stli.uuconf_zservaddr; - if (zservaddr == NULL) - ulog (LOG_FATAL, "Can't run as TLI server; no server address"); - - zfreeaddr = zbufcpy (zservaddr); - qtbind->addr.len = cescape (zfreeaddr); - if (qtbind->addr.len > qtbind->addr.maxlen) - ulog (LOG_FATAL, "%s: TLI server address too long (max %d)", - zservaddr, qtbind->addr.maxlen); - memcpy (qtbind->addr.buf, zfreeaddr, qtbind->addr.len); - ubuffree (zfreeaddr); - - qtbind->qlen = 5; - - if (t_bind (qsysdep->o, qtbind, (struct t_bind *) NULL) < 0) - ulog (LOG_FATAL, "t_bind (%s): %s", zservaddr, ztlierror ()); - - (void) t_free ((pointer) qtbind, T_BIND); - - qtcall = (struct t_call *) t_alloc (qsysdep->o, T_CALL, T_ALL); - if (qtcall == NULL) - ulog (LOG_FATAL, "t_alloc (T_CALL): %s", ztlierror ()); - - while (! FGOT_SIGNAL ()) - { - int onew; - pid_t ipid; - - DEBUG_MESSAGE0 (DEBUG_PORT, - "ftli_open: Waiting for connections"); - - if (t_listen (qsysdep->o, qtcall) < 0) - ulog (LOG_FATAL, "t_listen: %s", ztlierror ()); - - onew = t_open (zdevice, O_RDWR, (struct t_info *) NULL); - if (onew < 0) - ulog (LOG_FATAL, "t_open (%s): %s", zdevice, ztlierror ()); - - if (fcntl (onew, F_SETFD, - fcntl (onew, F_GETFD, 0) | FD_CLOEXEC) < 0) - ulog (LOG_FATAL, "fcntl (FD_CLOEXEC): %s", strerror (errno)); - - if (t_bind (onew, (struct t_bind *) NULL, (struct t_bind *) NULL) < 0) - ulog (LOG_FATAL, "t_bind: %s", ztlierror ()); - - if (t_accept (qsysdep->o, onew, qtcall) < 0) - { - /* We may have received a disconnect. */ - if (t_errno != TLOOK) - ulog (LOG_FATAL, "t_accept: %s", ztlierror ()); - if (t_rcvdis (qsysdep->o, (struct t_discon *) NULL) < 0) - ulog (LOG_FATAL, "t_rcvdis: %s", ztlierror ()); - (void) t_close (onew); - continue; - } - - DEBUG_MESSAGE0 (DEBUG_PORT, - "ftli_open: Got connection; forking"); - - ipid = ixsfork (); - if (ipid < 0) - ulog (LOG_FATAL, "fork: %s", strerror (errno)); - if (ipid == 0) - { - ulog_close (); - - (void) t_close (qsysdep->o); - qsysdep->o = onew; - - /* Push any desired modules. */ - if (! ftli_push (qconn)) - _exit (EXIT_FAILURE); - - /* Now we fork and let our parent die, so that we become - a child of init. This lets the main server code wait - for its child and then continue without accumulating - zombie children. */ - ipid = ixsfork (); - if (ipid < 0) - { - ulog (LOG_ERROR, "fork: %s", strerror (errno)); - _exit (EXIT_FAILURE); - } - - if (ipid != 0) - _exit (EXIT_SUCCESS); - - ulog_id (getpid ()); - - return TRUE; - } - - (void) t_close (onew); - - /* Now wait for the child. */ - (void) ixswait ((unsigned long) ipid, (const char *) NULL); - } - - /* We got a signal. */ - usysdep_exit (FALSE); - - /* Avoid compiler warnings. */ - return FALSE; -} - -/* Close the port. */ - -/*ARGSUSED*/ -static boolean -ftli_close (qconn, puuconf, qdialer, fsuccess) - struct sconnection *qconn; - pointer puuconf; - struct uuconf_dialer *qdialer; - boolean fsuccess; -{ - struct ssysdep_conn *qsysdep; - boolean fret; - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - - fret = TRUE; - if (qsysdep->o >= 0) - { - if (qsysdep->ftli) - { - if (t_close (qsysdep->o) < 0) - { - ulog (LOG_ERROR, "t_close: %s", ztlierror ()); - fret = FALSE; - } - } - else - { - if (close (qsysdep->o) < 0) - { - ulog (LOG_ERROR, "close: %s", strerror (errno)); - fret = FALSE; - } - } - - qsysdep->o = -1; - } - - /* If the current pid is not the one we used to open the port, then - we must have forked up above and we are now the child. In this - case, we are being called from within the fendless loop in - uucico.c. We return FALSE to force the loop to end and the child - to exit. This should be handled in a cleaner fashion. */ - if (qsysdep->ipid != getpid ()) - fret = FALSE; - - return fret; -} - -/* Dial out on a TLI port, so to speak: connect to a remote computer. */ - -/*ARGSUSED*/ -static boolean -ftli_dial (qconn, puuconf, qsys, zphone, qdialer, ptdialerfound) - struct sconnection *qconn; - pointer puuconf; - const struct uuconf_system *qsys; - const char *zphone; - struct uuconf_dialer *qdialer; - enum tdialerfound *ptdialerfound; -{ - struct ssysdep_conn *qsysdep; - char **pzdialer; - const char *zaddr; - struct t_call *qtcall; - char *zescape; - - qsysdep = (struct ssysdep_conn *) qconn->psysdep; - - *ptdialerfound = DIALERFOUND_FALSE; - - pzdialer = qconn->qport->uuconf_u.uuconf_stli.uuconf_pzdialer; - if (*pzdialer == NULL) - pzdialer = NULL; - - /* If the first dialer is "TLI" or "TLIS", we use the first token - (pzdialer[1]) as the address to connect to. */ - zaddr = zphone; - if (pzdialer != NULL - && (strcmp (pzdialer[0], "TLI") == 0 - || strcmp (pzdialer[0], "TLIS") == 0)) - { - if (pzdialer[1] == NULL) - ++pzdialer; - else - { - if (strcmp (pzdialer[1], "\\D") != 0 - && strcmp (pzdialer[1], "\\T") != 0) - zaddr = pzdialer[1]; - pzdialer += 2; - } - } - - if (zaddr == NULL) - { - ulog (LOG_ERROR, "No address for TLI connection"); - return FALSE; - } - - qtcall = (struct t_call *) t_alloc (qsysdep->o, T_CALL, T_ADDR); - if (qtcall == NULL) - { - ulog (LOG_ERROR, "t_alloc (T_CALL): %s", ztlierror ()); - return FALSE; - } - - zescape = zbufcpy (zaddr); - qtcall->addr.len = cescape (zescape); - if (qtcall->addr.len > qtcall->addr.maxlen) - { - ulog (LOG_ERROR, "%s: TLI address too long (max %d)", zaddr, - qtcall->addr.maxlen); - ubuffree (zescape); - return FALSE; - } - memcpy (qtcall->addr.buf, zescape, qtcall->addr.len); - ubuffree (zescape); - - if (t_connect (qsysdep->o, qtcall, (struct t_call *) NULL) < 0) - { - if (t_errno != TLOOK) - ulog (LOG_ERROR, "t_connect: %s", ztlierror ()); - else - { - if (t_rcvdis (qsysdep->o, (struct t_discon *) NULL) < 0) - ulog (LOG_ERROR, "t_rcvdis: %s", ztlierror ()); - else - ulog (LOG_ERROR, "Connection refused"); - } - return FALSE; - } - - /* We've connected to the remote. Push any desired modules. */ - if (! ftli_push (qconn)) - return FALSE; - - /* Handle the rest of the dialer sequence. */ - if (pzdialer != NULL && *pzdialer != NULL) - { - if (! fconn_dial_sequence (qconn, puuconf, pzdialer, qsys, zphone, - qdialer, ptdialerfound)) - return FALSE; - } - - return TRUE; -} - -#endif /* HAVE_TLI */ diff --git a/gnu/libexec/uucp/contrib/uureroute b/gnu/libexec/uucp/contrib/uureroute deleted file mode 100755 index 3eeb654..0000000 --- a/gnu/libexec/uucp/contrib/uureroute +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/local/bin/perl -eval ' exec /usr/local/bin/perl $0 "$@" ' - if $running_under_some_shell; - -# From a script by -# Newsgroups: comp.sources.misc -# Subject: v28i073: uureroute - Reroute HDB queued mail, Part01/01 -# Date: 26 Feb 92 02:28:37 GMT -# -# This is a Honey DanBer specific routine written in perl to reroute all -# mail queued up for a specific host. It needs to be run as "root" since -# uucp will not allow itself to remove others requests. -# -# Revision *** 92/21/09: Francois Pinard -# 1. adapted for Taylor UUCP -# -# Revision 1.3 91/10/08 09:01:21 src -# 1. Rewritten in perl -# 2. Add -v option for debugging. -# -# Revision 1.2 91/10/07 23:57:42 root -# 1. Fix mail program path. -# 2. Truncate directory name to 7 characters - -($progname = $0) =~ s!.*/!!; # save this very early - -$USAGE = " -# Reroute uucp mail -# -# Usage: $progname [-v] host [host...] -# -# Options Argument Description -# -v Verbose (doesn't execute /bin/sh) -# -"; - -$UUSTAT = "/usr/local/bin/uustat"; -$SHELL = "/bin/sh"; -$SMAIL = "/bin/smail"; - -sub usage -{ - die join ("\n", @_) . "\n$USAGE\n"; -} - -do "getopts.pl"; - -&usage ("Invalid Option") unless do Getopts ("vV"); - -$verbose = ($opt_v ? '-v' : ()); -$suffix = ($verbose ? '' : $$); - -&usage ("No system specified") if $#ARGV < 0; - -if (!$verbose) -{ - open (SHELL, "| $SHELL"); - select SHELL; -} - -while ($system = shift) -{ - $sysprefix = substr ($system, 0, 7); - $directory = "/usr/spool/uucp/$sysprefix"; - open (UUSTAT, "$UUSTAT -s $system -c rmail |"); - print "set -ex\n"; - while () - { - ($jobid, ) = split; - ($cfile) = substr ($jobid, length ($jobid) - 5); - $cfilename = "$directory/C./C.$cfile"; - open (CFILE, $cfilename) || die "Cannot open $cfilename\n"; - $_ = ; - close CFILE; - if (/^E D\.(....) [^ ]+ [^ ]+ -CR D\.\1 0666 [^ ]+ 0 rmail (.*)/) - { - $datafile = "$directory/D./D.$1"; - $address = $2; - } - else - { - print STDERR; - die "Cannot parse previous line from $cfilename\n"; - } - print "$SMAIL -R $system!$address < $datafile && $UUSTAT -k $jobid\n"; - } - close UUSTAT; -} -close SHELL unless $verbose; - -exit 0; diff --git a/gnu/libexec/uucp/sample/call b/gnu/libexec/uucp/sample/call deleted file mode 100644 index de4190c..0000000 --- a/gnu/libexec/uucp/sample/call +++ /dev/null @@ -1,20 +0,0 @@ -# This is an example of call, the call out password file for Taylor -# UUCP. To use it, you must compile the package with -# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy -# this file to newconfigdir as set in Makefile.in (the default is -# /usr/local/conf/uucp), and edit it as appropriate for your system. - -# Everything after a '#' character is a comment. To uncomment any of -# the sample lines below, just delete the '#'. - -# This file is used when the ``call-login'' or ``call-password'' -# commands are used in the sys file with a "*" argument (e.g., -# ``call-login *''). The system name is looked up in this file, and -# the login name and password are used. - -# The point of this is that the sys file may then be publically -# readable, while still concealing the login names and passwords used -# to connect to the remote system. - -# The format is just system-name login-name password. -uunet Uairs foobar diff --git a/gnu/libexec/uucp/sample/config b/gnu/libexec/uucp/sample/config deleted file mode 100644 index e7d683b..0000000 --- a/gnu/libexec/uucp/sample/config +++ /dev/null @@ -1,88 +0,0 @@ -# This is an example of config, the main configuration file for Taylor -# UUCP. To use it, you must compile the package with -# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy -# this file to newconfigdir as set in Makefile.in (the default is -# /usr/local/conf/uucp), and edit it as appropriate for your system. - -# You need not use this file at all; all the important commands have -# defaults which will be used if this file can not be found. - -# Everything after a '#' character is a comment. To uncomment any of -# the sample lines below, just delete the '#'. - -# You must choose a UUCP name. If your system is going to be -# communicating with other systems outside your organization, the name -# must be unique in the entire world. The usual method is to pick a -# name, and then search the UUCP maps (in the newsgroup -# comp.mail.maps) to see whether it has already been taken. See the -# README posting in comp.mail.maps for more information. If the name -# of your system as returned by "uuname -n" or "hostname" is the name -# you want to use, you do not need to set the name in this file. -# Otherwise uncomment and edit the following line. -# nodename uucp # The UUCP name of this system - -# The default spool directory is set in policy.h (the default is -# /usr/spool/uucp). All UUCP jobs and status information are kept in -# the spool directory. If you wish to change it, use the spool -# command. -# spool /usr/spool/uucp # The UUCP spool directory - -# The default public directory is set in policy.h (the default is -# /usr/spool/uucppublic). Remote systems may refer to a file in this -# directory using "~/FILE". By default, the public directory is the -# only directory which remote systems may transfer files in and out -# of. If you wish to change the public directory, use the pubdir -# command. -# pubdir /usr/spool/uucppublic # The UUCP public directory - -# The names of the UUCP log files are set in policy.h. The default -# names depend on the logging option you have chosen. If -# HAVE_TAYLOR_LOGGING is set in policy.h, the default log file name is -# /usr/spool/uucp/Log, the default statistics file name is -# /usr/spool/uucp/Stats, and the default debugging file name is -# /usr/spool/uucp/Debug. These file names may be set by the following -# commands. -# logfile /usr/spool/uucp/Log # The UUCP log file -# statfile /usr/spool/uucp/Stats # The UUCP statistics file -# debugfile /usr/spool/uucp/Debug # The UUCP debugging file - -# uuxqt is the program which executes UUCP requests from other -# systems. Normally one is started after each run of uucico, the -# communications daemon. You may control the maximum number of uuxqt -# programs run at the same time with the following command. The -# default is to have no maximum. -# max-uuxqts 1 # The maximum number of uuxqts - -# There are several files that uucico uses. By default it looks for -# them in newconfigdir, as set in Makefile.in. You may name one or -# more of each type of file using the following commands. -# sysfile FILES # Default "sys" -# portfile FILES # Default "port" -# dialfile FILES # Default "dial" -# dialcodefile FILES # Default "dialcode" -# callfile FILES # Default "call" -# passwdfile FILES # Default "passwd" - -# The ``timetable'' command may be used to declare timetables. These -# may then be referred to in time strings in the other files. -# timetable Day Wk0905-1655 - -# The ``unknown'' command is followed by any command which may appear -# in a sys file. These commands are taken together to describe what -# is permitted to a system which is not listed in any sys file. If -# the ``unknown'' command, then unknown systems are not permitted to -# connect. - -# Here is an example which permits unknown systems to download files -# from /usr/spool/anonymous, and to upload them to -# /usr/spool/anonymous/upload. -# -# No commands may be executed (the list of permitted commands is empty) -# unknown commands -# The public directory is /usr/spool/anonymous -# unknown pubdir /usr/spool/anonymous -# Only files in the public directory may be sent; users may not download -# files from the upload directory -# unknown remote-send ~ !~/upload -# May only upload files into /usr/spool/anonymous/upload -# unknown remote-receive ~/upload diff --git a/gnu/libexec/uucp/sample/dial b/gnu/libexec/uucp/sample/dial deleted file mode 100644 index f0d4bdd..0000000 --- a/gnu/libexec/uucp/sample/dial +++ /dev/null @@ -1,35 +0,0 @@ -# This is an example of dial, the dialer configuration file for Taylor -# UUCP. To use it, you must compile the package with -# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy -# this file to newconfigdir as set in Makefile.in (the default is -# /usr/local/conf/uucp), and edit it as appropriate for your system. - -# Everything after a '#' character is a comment. To uncomment any of -# the sample lines below, just delete the '#'. - -# All dialers named in the port (or sys) file must be described in the -# dial file. It is also possible to describe a dialer directly in the -# port (or sys) file. - -# This is a typical Hayes modem definition. -dialer hayes - -# The chat script used to dial the phone. -# This means: -# 1) expect nothing (i.e., continue with step 2) -# 2) send "ATZ", then a carriage return, then sleep for 1 to 2 -# seconds. The \c means to not send a final carriage return. -# 3) wait until the modem echoes "OK" -# 4) send "ATDT", then the telephone number (after translating any -# dialcodes). -# 5) wait until the modem echoes "CONNECT" -chat "" ATZ\r\d\c OK ATDT\T CONNECT - -# If we get "BUSY" or "NO CARRIER" during the dial chat script we -# abort the dial immediately. -chat-fail BUSY -chat-fail NO\sCARRIER - -# When the call is over, we make sure we hangup the modem. -complete \d\d+++\d\dATH\r\c -abort \d\d+++\d\dATH\r\c diff --git a/gnu/libexec/uucp/sample/dialcode b/gnu/libexec/uucp/sample/dialcode deleted file mode 100644 index 710a07b..0000000 --- a/gnu/libexec/uucp/sample/dialcode +++ /dev/null @@ -1,19 +0,0 @@ -# This is an example of dialcode, the dialcode configuration file for -# Taylor UUCP. To use it, you must compile the package with -# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy -# this file to newconfigdir as set in Makefile.in (the default is -# /usr/local/conf/uucp), and edit it as appropriate for your system. - -# Everything after a '#' character is a comment. To uncomment any of -# the sample lines below, just delete the '#'. - -# The dialcode file is used if \T is used in the dialer chat script -# and the telephone number begins with alphabetic characters. The -# alphabetic characters are looked up and translated in dialcode. - -# Here are a couple of sample dialcodes. -MA 617 -CA 415 - -# For example, if the phone number (from the sys file) is MA7389449, -# then the string sent to the modem will be 6177389449. diff --git a/gnu/libexec/uucp/sample/passwd b/gnu/libexec/uucp/sample/passwd deleted file mode 100644 index 2b04e13..0000000 --- a/gnu/libexec/uucp/sample/passwd +++ /dev/null @@ -1,18 +0,0 @@ -# This is an example of passwd, the call in password file for Taylor -# UUCP. To use it, you must compile the package with -# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy -# this file to newconfigdir as set in Makefile.in (the default is -# /usr/local/conf/uucp), and edit it as appropriate for your system. - -# Everything after a '#' character is a comment. To uncomment any of -# the sample lines below, just delete the '#'. - -# This file is used when uucico is invoked with the -l or -e argument. -# uucico will then prompt for a login name and password. The login -# name is looked up in this file to check the password (the system -# password file, /etc/passwd, is not checked). This permits uucico to -# completely take over a port, allowing UUCP access to remote systems -# but not permitting remote users to actually log in to the system. - -# The format is just login-name password. -Uairs foobar diff --git a/gnu/libexec/uucp/sample/port b/gnu/libexec/uucp/sample/port deleted file mode 100644 index 8e48186..0000000 --- a/gnu/libexec/uucp/sample/port +++ /dev/null @@ -1,41 +0,0 @@ -# This is an example of port, the port configuration file for Taylor -# UUCP. To use it, you must compile the package with -# HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), copy -# this file to newconfigdir as set in Makefile.in (the default is -# /usr/local/conf/uucp), and edit it as appropriate for your system. - -# Everything after a '#' character is a comment. To uncomment any of -# the sample lines below, just delete the '#'. - -# All ports named in the sys file must be described in a port file. -# It is also possible to describe the port directly in the sys file. - -# Commands that appears before the first ``port'' command are defaults -# for all ports that appear later in the file. In this case all ports -# will default to being modems (other possible types are direct, tcp -# and tli). -type modem - -# Now we describe two ports. - -# This is the name of the port. This name may be used in the sys file -# to select the port, or the sys file may just specify a baud rate in -# which case the first matching unlocked port will be used. -port port1 - -# This is the device name to open to dial out. -device /dev/ttyd0 - -# This is the dialer to use, as described in the dialer file. -dialer hayes - -# This is the baud rate to dial out at. -speed 2400 - -# Here is a second port. This is like the first, except that it uses -# a different device. It also permits a range of speeds, which is -# mainly useful if the system specifies a particular baud rate. -port port2 -device /dev/ttyd1 -dialer hayes -speed-range 2400 9600 diff --git a/gnu/libexec/uucp/sample/sys1 b/gnu/libexec/uucp/sample/sys1 deleted file mode 100644 index fa9e770..0000000 --- a/gnu/libexec/uucp/sample/sys1 +++ /dev/null @@ -1,44 +0,0 @@ -# This is an example of a sys file, the file(s) which describe remote -# systems for Taylor UUCP. To use it, you must compile the package -# with HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), -# copy this file to newconfigdir as set in Makefile.in (the default is -# /usr/local/conf/uucp), and edit it as appropriate for your system. - -# If you do not use the ``unknown'' command in the config file, then -# each system that you communicate with must be listed in a sys file. - -# Everything after a '#' character is a comment. To uncomment any of -# the sample lines below, just delete the '#'. - -# This is a sample sys file that might be used in a leaf system. A -# leaf system is one that only contacts one other system. sys2 -# provides another example. - -# The name of the remote system that we call. -system uunet - -# The login name and password are kept in the callout password file -# (by default this is the file "call" in newconfigdir). -call-login * -call-password * - -# We can send anything at any time. -time any - -# During the day we only accept grade 'Z' or above; at other times -# (not mentioned here) we accept all grades. uunet queues up news -# at grade 'd', which is lower than 'Z'. -call-timegrade Z Wk0755-2305,Su1655-2305 - -# The phone number to call. -phone 7389449 - -# uunet tends to be slow, so we increase the timeout -chat-timeout 120 - -# The port we use to dial out. -port serial - -# Increase the timeout and the number of retries. -protocol-parameter g timeout 20 -protocol-parameter g retries 10 diff --git a/gnu/libexec/uucp/sample/sys2 b/gnu/libexec/uucp/sample/sys2 deleted file mode 100644 index 856529a..0000000 --- a/gnu/libexec/uucp/sample/sys2 +++ /dev/null @@ -1,51 +0,0 @@ -# This is an example of a sys file, the file(s) which describe remote -# systems for Taylor UUCP. To use it, you must compile the package -# with HAVE_TAYLOR_CONFIG set to 1 in policy.h (that is the default), -# copy this file to newconfigdir as set in Makefile.in (the default is -# /usr/local/conf/uucp), and edit it as appropriate for your system. - -# If you do not use the ``unknown'' command in the config file, then -# each system that you communicate with must be listed in a sys file. - -# Everything after a '#' character is a comment. To uncomment any of -# the sample lines below, just delete the '#'. - -# This is a sample sys file that might be used by a system that -# contacts a couple of other systems, both of which are treated the -# same. sys1 provides another example. - -# Commands that appear before the first ``system'' commands are -# defaults for all systems listed in the file. - -# Get the login name and password to use from the call-out file. By -# default this is the file "call" in newconfigdir. -call-login * -call-password * - -# The systems must use a particular login -called-login Ulocal - -# Permit local users to send any world readable file -local-send / - -# Permit local uses to request into any world writable directory -local-receive / - -# Call at any time -time any - -# Use port1, then port2 -port port1 - -alternate - -port port2 - -# Now define the systems themselves. Because of all the defaults we -# used, there is very little to specify for the systems themselves. - -system comton -phone 5551212 - -system bugs -phone 5552424 diff --git a/gnu/usr.bin/as/Makefile.gnu b/gnu/usr.bin/as/Makefile.gnu deleted file mode 100644 index 4b81b0c..0000000 --- a/gnu/usr.bin/as/Makefile.gnu +++ /dev/null @@ -1,356 +0,0 @@ -# Makefile for GAS. -# Copyright (C) 1989, Free Software Foundation -# -# This file is part of GAS, the GNU Assembler. -# -# GAS 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 1, or (at your option) -# any later version. -# -# GAS 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 GAS; see the file COPYING. If not, write to -# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - -# This makefile may be used to make the VAX, 68020, 80386, -# SPARC, ns32k, or i860 assembler(s). - -BINDIR = /usr/local/bin -#CC=gcc - -# If you are on a BSD system, un-comment the next two lines, and comment out -# the lines for SystemV and HPUX below -G0 = -g -I. #-O -Wall -LDFLAGS = $(CFLAGS) -# -# To compile gas on a System Five machine, comment out the two lines above -# and un-comment out the next three lines -# Comment out the -lPW on the LOADLIBES line if you are using GCC. -# G0 = -g -I. -DUSG -# LDFLAGS = $(CFLAGS) -# LOADLIBES = -lmalloc -lPW -# -# To compile gas for HPUX, link m-hpux.h to m68k.h , and un-comment the -# next two lines. (If you are using GCC, comment out the alloca.o part) -# (Get alloca from the emacs distribution, or use GCC.) -# HPUX 7.0 may have a bug in setvbuf. gas gives an error message like -# 1:"Unknown operator" -- Statement 'NO_APP' ignored -# if setvbuf is broken. Re-compile input-file.c (and only input-file.c -# with -DVMS and the problem should go away. -# -# G0 = -g -I. -DUSG -# LOADLIBES = alloca.o -# -# To compile gas for a Sequent Symmetry, comment out all the above lines, -# and un-comment the next two lines. -# G0 = -g -I. -DUSE_SYSTEM_HDR -DEXEC_VERSION=1 -# LOADLIBES = -lc /usr/att/lib/libc.a - -# If you just want to compile the vax assembler, type 'make avax' - -# If you just want to compile the i386 assembler, type 'make a386' - -# If you just want to compile the ns32k assembler, type 'make a32k' - -# If you just want to compile the sparc assembler, type 'make asparc' - -# If you just want to compile the mc68020 assembler, make sure m68k.h -# is correctly set up, and type type 'make a68' (Except on HPUX machines, -# where you will have to make the changes marked below before typing -# 'make a68' -# m68k.h should be a symbolic or hard-link to one of -# m-sun3.h , m-hpux.h or m-generic.h -# depending on which machine you want to compile the 68020 assembler for. -# -# If you want the 68k assembler to be completely compatable with the the -# SUN one, un-comment the -DSUN_ASM_SYNTAX line below. -# -# If you machine does not have vfprintf, but does have _doprnt(), -# remove the # from the -DNO_VARARGS line below. -# -# If the return-type of a signal-hander is void (instead of int), -# remove the # from the -DSIGTY line below. -# -# To include the mc68851 mmu coprocessor instructions in the 68020 assembler, -# remove the # from the -Dm68851 line below. -# -# If you want the 68020 assembler use a register prefix character, un-comment -# the REGISTER_PREFIX line, and (maybe) change the '%' to the appropriate -# character. -# -# If you want the assembler to treat .L* or ..* symbols as local, instead of -# the usual L* symbols, un-comment the DOT_LABEL_PREFIX line. -# -# If you want the 80386 assembler to correctly handle fsub/fsubr and fdiv/fdivr -# opcodes (unlike most 80386 assemblers), remove the # from -# the -DNON_BROKEN_WORDS line below. -# -# To compile 80386 Gas for the Sequent Symmetry, un-comment the -DEXEC_VERSION -# and the -DUSE_SYSTEM_HDR lines below. -# -# To compile gas for the HP 9000/300 un-comment the -DUSE_HP_HDR line below. -# -# For the ns32k, the options are 32532 or 32032 CPU and 32381 or 32081 FPU. -# To select the NS32532, remove the # from the -DNS32532 line below. -# To compile in tne NS32381 opcodes in addition to the NS32081 opcodes -# (the 32381 is a superset of the 32081), remove the # from the -DNS32381 -# line below. -# -# For the ns32k on a Sequent, uncomment the SEQUENT_COMPATABILITY line below. -# -# If you want the .align N directive to align to the next N byte boundry, -# instead of the next 1< .fname - mkdir `cat .fname` - - ln COPYING README ChangeLog $A $H $Z $Y $X $W $V $U Makefile `cat .fname` - tar cvhZf `cat .fname`.tar.Z `cat .fname` - -rm -r `cat .fname` - -rm .fname - -clean: - rm -f a avax a68 a386 a32k asparc $a $v $w $x $y $z a core gmon.out bugs a.out - -install: a - cp a $(BINDIR)/gas - - -# General .o-->.h dependencies - -app.o: as.h -as.o: a.out.gnu.h as.h read.h struc-symbol.h write.h -atof-generic.o: flonum.h -bignum-copy.o: bignum.h -expr.o: a.out.gnu.h as.h expr.h flonum.h obstack.h read.h struc-symbol.h -expr.o: symbols.h -flonum-const.o: flonum.h -flonum-copy.o: flonum.h -flonum-mult.o: flonum.h -flonum-normal.o:flonum.h -flonum-print.o: flonum.h -frags.o: a.out.gnu.h as.h frags.h obstack.h struc-symbol.h subsegs.h -#gdb.o: as.h -#gdb-blocks.o: as.h -#gdb-lines.o: as.h frags.h obstack.h -#gdb-symbols.o: a.out.gnu.h as.h struc-symbol.h -hash.o: hash.h -input-file.o: input-file.h -input-scrub.o: as.h input-file.h read.h -messages.o: as.h -obstack.o: obstack.h -read.o: a.out.gnu.h as.h expr.h flonum.h frags.h hash.h md.h obstack.h -read.o: read.h struc-symbol.h symbols.h -subsegs.o: a.out.gnu.h as.h frags.h obstack.h struc-symbol.h subsegs.h write.h -symbols.o: a.out.gnu.h as.h frags.h hash.h obstack.h struc-symbol.h symbols.h -write.o: a.out.gnu.h as.h md.h obstack.h struc-symbol.h subsegs.h -write.o: symbols.h write.h - -flonum.h: bignum.h - diff --git a/gnu/usr.bin/as/README.gnu b/gnu/usr.bin/as/README.gnu deleted file mode 100644 index 46f135fc..0000000 --- a/gnu/usr.bin/as/README.gnu +++ /dev/null @@ -1,133 +0,0 @@ -This is the beta-test version of the GNU assembler. (Probably -around Version 1.35, but check version.c which gets updated more -often than this readme.) - -The assembler has been modified to support a feature that is -potentially useful when assembling compiler output, but which may -confuse assembly language programmers. If assembler encounters a -.word pseudo-op of the form symbol1-symbol2 (the difference of two -symbols), and the difference of those two symbols will not fit in 16 -bits, the assembler will create a branch around a long jump to -symbol1, and insert this into the output directly before the next -label: The .word will (instead of containing garbage, or giving an -error message) contain (the address of the long jump)-symbol2. This -allows the assembler to assemble jump tables that jump to locations -very far away into code that works properly. If the next label is -more than 32K away from the .word, you lose (silently) RMS claims -this will never happen. If the -k option is given, you will get a -warning message when this happens. - -These files are currently set up to allow you to compile all of the -versions of the assembler (68020, VAX, ns32k, and i386) on the same -machine. To compile the 68020 version, type 'make a68'. To compile -the VAX version, type 'make avax'. To compile the ns32k version, -type 'make a32k'. To compile the Intel 80386 version, type 'make -a386'. The Makefile contains instructions on how to make one of the -assemblers compile as the default. - -Before you can compile the 68020 version of the assembler, you must -make m68k.h be a link to m-sun3.h , m-hpux.h or m-generic.h . If -you are on a SUN-3 (or other machine that uses a magic number of -(2 << 16) | OMAGIC type 'ln -s m-sun3.h m68k.h' else if you are on a -machine running HP-UX, type 'ln m-hpux.h m689k.h' else type -'ln -s m-generic.h m68k.h' If your machine does not support symbolic -links, omit the '-s'. - -See the instructions in the Makefile for compiling gas for the Sequent -Symmetry (dynix 3.0.12 + others?) or for the HP 9000/300 - -If your machine does not have both varargs.h and vfprintf(), but does have -_doprnt() add -DNO_VARARGS to the CFLAGS line in the makefile. If your -machine has neither vfprintf() or _doprnt(), you will have to change -messages.c in order to get readable error messages from the assembler. - - - REPORTING BUGS IN GAS - -Bugs in gas should be reported to bug-gnu-utils@prep.ai.mit.edu If you can't -get through to prep, try hack@gnu.ai.mit.edu or hack@media-lab.media.mit.edu - -If you report a bug in GAS, please remember to include: - -A description of exactly what went wrong. - -The type of machine GAS was running on (VAX, 68020, etc), - -The Operating System GAS was running under. - -The options given to GAS. - -The actual input file that caused the problem. - -It is silly to report a bug in GAS without including an input file for -GAS. Don't ask us to generate the file just because you made it from -files you think we have access to. - -1. You might be mistaken. -2. It might take us a lot of time to install things to regenerate that file. -3. We might get a different file from the one you got, and might not see any -bug. - -To save us these delays and uncertainties, always send the input file -for the program that failed. - -If the input file is very large, and you are on the internet, you may -want to make it avaliable for anonymous FTP instead of mailing it. If you -do, include instructions for FTP'ing it in your bug report. - ------------------------------- README.APOLLO --------------------------------- - -The changes required to get the GNU C compiler running on -Apollo 68K platforms are available via anonymous ftp from -labrea.stanford.edu (36.8.0.47) in the form of a compressed -tar file named "/pub/gnu/apollo-gcc-1.37.tar.Z". -The size of the file is 84145 bytes. - -To build GCC for the Apollo you'll need the virgin FSF -distributions of bison-1.03, gas-1.34, and gcc-1.37. They -are also on labrea.stanford.edu as well as prep.ai.mit.edu. -My changes are to enable gas to produce Apollo COFF object -files and allow gcc to parse some of the syntax extensions -which appear in Apollo C header files. Note that the -COFF encapsulation technique cannot be used on the Apollo. - -The tar file should be unpacked in the directory containing -the gas-1.34 and gcc-1.37 directories; a few files will be overlaid, -and an APOLLO-GCC-README file will appear in the top directory. -This file contains detailed instructions on how to proceed. - -These changes will only work for SR10.1 or later systems, using -the 6.6 or later version of the Apollo C compiler. - -If you do not have ftp access, I can mail you the changes in the -form of diffs; they are approximately 40K in length. If you request -them, be sure to give me a voice phone number so I can contact you -in case I can't send you mail; I've had several requests in the -past from people I can't contact. - -By the way, I'm working on getting the GNU C++ compiler running; -there are a couple problems to solve. I hope to be able to announce -the Apollo version shortly after the 1.37 version is released. - -John Vasta Hewlett-Packard Apollo Systems Division -vasta@apollo.hp.com M.S. CHA-01-LT -(508) 256-6600 x6362 300 Apollo Drive, Chelmsford, MA 01824 -UUCP: {decwrl!decvax, mit-eddie, attunix}!apollo!vasta - ------------------------------------- - -You might refer others who are interested in a similar thing. - -Kevin Buchs buchs@mayo.edu - - ------------------------------- README.COFF ----------------------------------- - -If you have a COFF system, you may wish to aquire - - UUCP: osu-cis!~/gnu/coff/gnu-coff.tar.Z - or - FTP: tut.cis.ohio-state.edu:/pub/gnu/coff/gnu-coff.tar.Z - -These contain patches for gas that will make it produce COFF output. -I have never seen these patches, so I don't know how well they work. diff --git a/gnu/usr.bin/as/append.c b/gnu/usr.bin/as/append.c deleted file mode 100644 index d51a27f..0000000 --- a/gnu/usr.bin/as/append.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Append a string ontp another string - Copyright (C) 1987 Free Software Foundation, Inc. - -This file is part of GAS, the GNU Assembler. - -GAS 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 1, or (at your option) -any later version. - -GAS 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 GAS; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* JF: This is silly. Why not stuff this in some other file? */ -#ifdef USG -#define bcopy(from,to,n) memcpy(to,from,n) -#endif - -void -append (charPP, fromP, length) -char **charPP; -char *fromP; -unsigned long length; -{ - if (length) { /* Don't trust bcopy() of 0 chars. */ - bcopy (fromP, * charPP,(int) length); - *charPP += length; - } -} - -/* end: append.c */ diff --git a/gnu/usr.bin/as/config/a.out.gnu.h b/gnu/usr.bin/as/config/a.out.gnu.h deleted file mode 100644 index 71b09a0..0000000 --- a/gnu/usr.bin/as/config/a.out.gnu.h +++ /dev/null @@ -1,261 +0,0 @@ -#ifndef __A_OUT_GNU_H__ -#define __A_OUT_GNU_H__ - -#define __GNU_EXEC_MACROS__ - -#ifndef __STRUCT_EXEC_OVERRIDE__ - -struct exec -{ - unsigned long a_info; /* Use macros N_MAGIC, etc for access */ - unsigned a_text; /* length of text, in bytes */ - unsigned a_data; /* length of data, in bytes */ - unsigned a_bss; /* length of uninitialized data area for file, in bytes */ - unsigned a_syms; /* length of symbol table data in file, in bytes */ - unsigned a_entry; /* start address */ - unsigned a_trsize; /* length of relocation info for text, in bytes */ - unsigned a_drsize; /* length of relocation info for data, in bytes */ -}; - -#endif /* __STRUCT_EXEC_OVERRIDE__ */ - -/* these go in the N_MACHTYPE field */ -enum machine_type { -#if defined (M_OLDSUN2) - M__OLDSUN2 = M_OLDSUN2, -#else - M_OLDSUN2 = 0, -#endif -#if defined (M_68010) - M__68010 = M_68010, -#else - M_68010 = 1, -#endif -#if defined (M_68020) - M__68020 = M_68020, -#else - M_68020 = 2, -#endif -#if defined (M_SPARC) - M__SPARC = M_SPARC, -#else - M_SPARC = 3, -#endif - /* skip a bunch so we don't run into any of sun's numbers */ - M_386 = 100, -}; - -#if !defined (N_MAGIC) -#define N_MAGIC(exec) ((exec).a_info & 0xffff) -#endif -#define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff)) -#define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff) -#define N_SET_INFO(exec, magic, type, flags) \ - ((exec).a_info = ((magic) & 0xffff) \ - | (((int)(type) & 0xff) << 16) \ - | (((flags) & 0xff) << 24)) -#define N_SET_MAGIC(exec, magic) \ - ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff))) - -#define N_SET_MACHTYPE(exec, machtype) \ - ((exec).a_info = \ - ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16)) - -#define N_SET_FLAGS(exec, flags) \ - ((exec).a_info = \ - ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24)) - -/* Code indicating object file or impure executable. */ -#define OMAGIC 0407 -/* Code indicating pure executable. */ -#define NMAGIC 0410 -/* Code indicating demand-paged executable. */ -#define ZMAGIC 0413 - -#if !defined (N_BADMAG) -#define N_BADMAG(x) \ - (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \ - && N_MAGIC(x) != ZMAGIC) -#endif - -#define _N_BADMAG(x) \ - (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \ - && N_MAGIC(x) != ZMAGIC) - -#define _N_HDROFF(x) (1024 - sizeof (struct exec)) - -#if !defined (N_TXTOFF) -#define N_TXTOFF(x) \ - (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : sizeof (struct exec)) -#endif - -#if !defined (N_DATOFF) -#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text) -#endif - -#if !defined (N_TRELOFF) -#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data) -#endif - -#if !defined (N_DRELOFF) -#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize) -#endif - -#if !defined (N_SYMOFF) -#define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize) -#endif - -#if !defined (N_STROFF) -#define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms) -#endif - -/* Address of text segment in memory after it is loaded. */ -#if !defined (N_TXTADDR) -#define N_TXTADDR(x) 0 -#endif - -/* Address of data segment in memory after it is loaded. - Note that it is up to you to define SEGMENT_SIZE - on machines not listed here. */ -#if defined(vax) || defined(hp300) || defined(pyr) -#define SEGMENT_SIZE page_size -#endif -#ifdef sony -#define SEGMENT_SIZE 0x2000 -#endif /* Sony. */ -#ifdef is68k -#define SEGMENT_SIZE 0x20000 -#endif -#if defined(m68k) && defined(PORTAR) -#define PAGE_SIZE 0x400 -#define SEGMENT_SIZE PAGE_SIZE -#endif - -#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1)) - -#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text) - -#ifndef N_DATADDR -#define N_DATADDR(x) \ - (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \ - : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x)))) -#endif - -/* Address of bss segment in memory after it is loaded. */ -#if !defined (N_BSSADDR) -#define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data) -#endif - -#if !defined (N_NLIST_DECLARED) -struct nlist { - union { - char *n_name; - struct nlist *n_next; - long n_strx; - } n_un; - unsigned char n_type; - char n_other; - short n_desc; - unsigned long n_value; -}; -#endif /* no N_NLIST_DECLARED. */ - -#if !defined (N_UNDF) -#define N_UNDF 0 -#endif -#if !defined (N_ABS) -#define N_ABS 2 -#endif -#if !defined (N_TEXT) -#define N_TEXT 4 -#endif -#if !defined (N_DATA) -#define N_DATA 6 -#endif -#if !defined (N_BSS) -#define N_BSS 8 -#endif -#if !defined (N_FN) -#define N_FN 15 -#endif - -#if !defined (N_EXT) -#define N_EXT 1 -#endif -#if !defined (N_TYPE) -#define N_TYPE 036 -#endif -#if !defined (N_STAB) -#define N_STAB 0340 -#endif - -/* The following type indicates the definition of a symbol as being - an indirect reference to another symbol. The other symbol - appears as an undefined reference, immediately following this symbol. - - Indirection is asymmetrical. The other symbol's value will be used - to satisfy requests for the indirect symbol, but not vice versa. - If the other symbol does not have a definition, libraries will - be searched to find a definition. */ -#define N_INDR 0xa - -/* The following symbols refer to set elements. - All the N_SET[ATDB] symbols with the same name form one set. - Space is allocated for the set in the text section, and each set - element's value is stored into one word of the space. - The first word of the space is the length of the set (number of elements). - - The address of the set is made into an N_SETV symbol - whose name is the same as the name of the set. - This symbol acts like a N_DATA global symbol - in that it can satisfy undefined external references. */ - -/* These appear as input to LD, in a .o file. */ -#define N_SETA 0x14 /* Absolute set element symbol */ -#define N_SETT 0x16 /* Text set element symbol */ -#define N_SETD 0x18 /* Data set element symbol */ -#define N_SETB 0x1A /* Bss set element symbol */ - -/* This is output from LD. */ -#define N_SETV 0x1C /* Pointer to set vector in data area. */ - -#if !defined (N_RELOCATION_INFO_DECLARED) -/* This structure describes a single relocation to be performed. - The text-relocation section of the file is a vector of these structures, - all of which apply to the text section. - Likewise, the data-relocation section applies to the data section. */ - -struct relocation_info -{ - /* Address (within segment) to be relocated. */ - int r_address; - /* The meaning of r_symbolnum depends on r_extern. */ - unsigned int r_symbolnum:24; - /* Nonzero means value is a pc-relative offset - and it should be relocated for changes in its own address - as well as for changes in the symbol or section specified. */ - unsigned int r_pcrel:1; - /* Length (as exponent of 2) of the field to be relocated. - Thus, a value of 2 indicates 1<<2 bytes. */ - unsigned int r_length:2; - /* 1 => relocate with value of symbol. - r_symbolnum is the index of the symbol - in file's the symbol table. - 0 => relocate with the address of a segment. - r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS - (the N_EXT bit may be set also, but signifies nothing). */ - unsigned int r_extern:1; - /* Four bits that aren't used, but when writing an object file - it is desirable to clear them. */ -#ifdef NS32K - unsigned r_bsr:1; - unsigned r_disp:1; - unsigned r_pad:2; -#else - unsigned int r_pad:4; -#endif -}; -#endif /* no N_RELOCATION_INFO_DECLARED. */ - - -#endif /* __A_OUT_GNU_H__ */ diff --git a/gnu/usr.bin/as/config/i386-opcode.h b/gnu/usr.bin/as/config/i386-opcode.h deleted file mode 100644 index cace0c3..0000000 --- a/gnu/usr.bin/as/config/i386-opcode.h +++ /dev/null @@ -1,806 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * - * @(#)i386-opcode.h 6.3 (Berkeley) 5/8/91 - */ - -/* i386-opcode.h -- Intel 80386 opcode table - Copyright (C) 1989, Free Software Foundation. - -This file is part of GAS, the GNU Assembler. - -GAS 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 1, or (at your option) -any later version. - -GAS 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 GAS; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -template i386_optab[] = { - -#define _ None -/* move instructions */ -{ "mov", 2, 0xa0, _, DW|NoModrm, Disp32, Acc, 0 }, -{ "mov", 2, 0x88, _, DW|Modrm, Reg, Reg|Mem, 0 }, -{ "mov", 2, 0xb0, _, ShortFormW, Imm, Reg, 0 }, -{ "mov", 2, 0xc6, _, W|Modrm, Imm, Reg|Mem, 0 }, -{ "mov", 2, 0x8c, _, D|Modrm, SReg3|SReg2, Reg16|Mem16, 0 }, -/* move to/from control debug registers */ -{ "mov", 2, 0x0f20, _, D|Modrm, Control, Reg32, 0}, -{ "mov", 2, 0x0f21, _, D|Modrm, Debug, Reg32, 0}, -{ "mov", 2, 0x0f24, _, D|Modrm, Test, Reg32, 0}, - -/* move with sign extend */ -/* "movsbl" & "movsbw" must not be unified into "movsb" to avoid - conflict with the "movs" string move instruction. Thus, - {"movsb", 2, 0x0fbe, _, ReverseRegRegmem|Modrm, Reg8|Mem, Reg16|Reg32, 0}, - is not kosher; we must seperate the two instructions. */ -{"movsbl", 2, 0x0fbe, _, ReverseRegRegmem|Modrm, Reg8|Mem, Reg32, 0}, -{"movsbw", 2, 0x660fbe, _, ReverseRegRegmem|Modrm, Reg8|Mem, Reg16, 0}, -{"movswl", 2, 0x0fbf, _, ReverseRegRegmem|Modrm, Reg16|Mem, Reg32, 0}, - -/* move with zero extend */ -{"movzb", 2, 0x0fb6, _, ReverseRegRegmem|Modrm, Reg8|Mem, Reg16|Reg32, 0}, -{"movzwl", 2, 0x0fb7, _, ReverseRegRegmem|Modrm, Reg16|Mem, Reg32, 0}, - -/* push instructions */ -{"push", 1, 0x50, _, ShortForm, WordReg,0,0 }, -{"push", 1, 0xff, 0x6, Modrm, WordReg|WordMem, 0, 0 }, -{"push", 1, 0x6a, _, NoModrm, Imm8S, 0, 0}, -{"push", 1, 0x68, _, NoModrm, Imm16|Imm32, 0, 0}, -{"push", 1, 0x06, _, Seg2ShortForm, SReg2,0,0 }, -{"push", 1, 0x0fa0, _, Seg3ShortForm, SReg3,0,0 }, -/* push all */ -{"pusha", 0, 0x60, _, NoModrm, 0, 0, 0 }, - -/* pop instructions */ -{"pop", 1, 0x58, _, ShortForm, WordReg,0,0 }, -{"pop", 1, 0x8f, 0x0, Modrm, WordReg|WordMem, 0, 0 }, -#define POP_SEG_SHORT 0x7 -{"pop", 1, 0x07, _, Seg2ShortForm, SReg2,0,0 }, -{"pop", 1, 0x0fa1, _, Seg3ShortForm, SReg3,0,0 }, -/* pop all */ -{"popa", 0, 0x61, _, NoModrm, 0, 0, 0 }, - -/* xchg exchange instructions - xchg commutes: we allow both operand orders */ -{"xchg", 2, 0x90, _, ShortForm, WordReg, Acc, 0 }, -{"xchg", 2, 0x90, _, ShortForm, Acc, WordReg, 0 }, -{"xchg", 2, 0x86, _, W|Modrm, Reg, Reg|Mem, 0 }, -{"xchg", 2, 0x86, _, W|Modrm, Reg|Mem, Reg, 0 }, - -/* in/out from ports */ -{"in", 2, 0xe4, _, W|NoModrm, Imm8, Acc, 0 }, -{"in", 2, 0xec, _, W|NoModrm, InOutPortReg, Acc, 0 }, -{"out", 2, 0xe6, _, W|NoModrm, Acc, Imm8, 0 }, -{"out", 2, 0xee, _, W|NoModrm, Acc, InOutPortReg, 0 }, - -/* load effective address */ -{"lea", 2, 0x8d, _, Modrm, WordMem, WordReg, 0 }, - -/* load segment registers from memory */ -{"lds", 2, 0xc5, _, Modrm, Mem, Reg32, 0}, -{"les", 2, 0xc4, _, Modrm, Mem, Reg32, 0}, -{"lfs", 2, 0x0fb4, _, Modrm, Mem, Reg32, 0}, -{"lgs", 2, 0x0fb5, _, Modrm, Mem, Reg32, 0}, -{"lss", 2, 0x0fb2, _, Modrm, Mem, Reg32, 0}, - -/* flags register instructions */ -{"clc", 0, 0xf8, _, NoModrm, 0, 0, 0}, -{"cld", 0, 0xfc, _, NoModrm, 0, 0, 0}, -{"cli", 0, 0xfa, _, NoModrm, 0, 0, 0}, -{"clts", 0, 0x0f06, _, NoModrm, 0, 0, 0}, -{"cmc", 0, 0xf5, _, NoModrm, 0, 0, 0}, -{"lahf", 0, 0x9f, _, NoModrm, 0, 0, 0}, -{"sahf", 0, 0x9e, _, NoModrm, 0, 0, 0}, -{"pushf", 0, 0x9c, _, NoModrm, 0, 0, 0}, -{"popf", 0, 0x9d, _, NoModrm, 0, 0, 0}, -{"stc", 0, 0xf9, _, NoModrm, 0, 0, 0}, -{"std", 0, 0xfd, _, NoModrm, 0, 0, 0}, -{"sti", 0, 0xfb, _, NoModrm, 0, 0, 0}, - -{"add", 2, 0x0, _, DW|Modrm, Reg, Reg|Mem, 0}, -{"add", 2, 0x83, 0, Modrm, Imm8S, WordReg|WordMem, 0}, -{"add", 2, 0x4, _, W|NoModrm, Imm, Acc, 0}, -{"add", 2, 0x80, 0, W|Modrm, Imm, Reg|Mem, 0}, - -{"inc", 1, 0x40, _, ShortForm, WordReg, 0, 0}, -{"inc", 1, 0xfe, 0, W|Modrm, Reg|Mem, 0, 0}, - -{"sub", 2, 0x28, _, DW|Modrm, Reg, Reg|Mem, 0}, -{"sub", 2, 0x83, 5, Modrm, Imm8S, WordReg|WordMem, 0}, -{"sub", 2, 0x2c, _, W|NoModrm, Imm, Acc, 0}, -{"sub", 2, 0x80, 5, W|Modrm, Imm, Reg|Mem, 0}, - -{"dec", 1, 0x48, _, ShortForm, WordReg, 0, 0}, -{"dec", 1, 0xfe, 1, W|Modrm, Reg|Mem, 0, 0}, - -{"sbb", 2, 0x18, _, DW|Modrm, Reg, Reg|Mem, 0}, -{"sbb", 2, 0x83, 3, Modrm, Imm8S, WordReg|WordMem, 0}, -{"sbb", 2, 0x1c, _, W|NoModrm, Imm, Acc, 0}, -{"sbb", 2, 0x80, 3, W|Modrm, Imm, Reg|Mem, 0}, - -{"cmp", 2, 0x38, _, DW|Modrm, Reg, Reg|Mem, 0}, -{"cmp", 2, 0x83, 7, Modrm, Imm8S, WordReg|WordMem, 0}, -{"cmp", 2, 0x3c, _, W|NoModrm, Imm, Acc, 0}, -{"cmp", 2, 0x80, 7, W|Modrm, Imm, Reg|Mem, 0}, - -{"test", 2, 0x84, _, W|Modrm, Reg|Mem, Reg, 0}, -{"test", 2, 0x84, _, W|Modrm, Reg, Reg|Mem, 0}, -{"test", 2, 0xa8, _, W|NoModrm, Imm, Acc, 0}, -{"test", 2, 0xf6, 0, W|Modrm, Imm, Reg|Mem, 0}, - -{"and", 2, 0x20, _, DW|Modrm, Reg, Reg|Mem, 0}, -{"and", 2, 0x83, 4, Modrm, Imm8S, WordReg|WordMem, 0}, -{"and", 2, 0x24, _, W|NoModrm, Imm, Acc, 0}, -{"and", 2, 0x80, 4, W|Modrm, Imm, Reg|Mem, 0}, - -{"or", 2, 0x08, _, DW|Modrm, Reg, Reg|Mem, 0}, -{"or", 2, 0x83, 1, Modrm, Imm8S, WordReg|WordMem, 0}, -{"or", 2, 0x0c, _, W|NoModrm, Imm, Acc, 0}, -{"or", 2, 0x80, 1, W|Modrm, Imm, Reg|Mem, 0}, - -{"xor", 2, 0x30, _, DW|Modrm, Reg, Reg|Mem, 0}, -{"xor", 2, 0x83, 6, Modrm, Imm8S, WordReg|WordMem, 0}, -{"xor", 2, 0x34, _, W|NoModrm, Imm, Acc, 0}, -{"xor", 2, 0x80, 6, W|Modrm, Imm, Reg|Mem, 0}, - -{"adc", 2, 0x10, _, DW|Modrm, Reg, Reg|Mem, 0}, -{"adc", 2, 0x83, 2, Modrm, Imm8S, WordReg|WordMem, 0}, -{"adc", 2, 0x14, _, W|NoModrm, Imm, Acc, 0}, -{"adc", 2, 0x80, 2, W|Modrm, Imm, Reg|Mem, 0}, - -{"neg", 1, 0xf6, 3, W|Modrm, Reg|Mem, 0, 0}, -{"not", 1, 0xf6, 2, W|Modrm, Reg|Mem, 0, 0}, - -{"aaa", 0, 0x37, _, NoModrm, 0, 0, 0}, -{"aas", 0, 0x3f, _, NoModrm, 0, 0, 0}, -{"daa", 0, 0x27, _, NoModrm, 0, 0, 0}, -{"das", 0, 0x2f, _, NoModrm, 0, 0, 0}, -{"aad", 0, 0xd50a, _, NoModrm, 0, 0, 0}, -{"aam", 0, 0xd40a, _, NoModrm, 0, 0, 0}, - -/* conversion insns */ -/* conversion: intel naming */ -{"cbw", 0, 0x6698, _, NoModrm, 0, 0, 0}, -{"cwd", 0, 0x6699, _, NoModrm, 0, 0, 0}, -{"cwde", 0, 0x98, _, NoModrm, 0, 0, 0}, -{"cdq", 0, 0x99, _, NoModrm, 0, 0, 0}, -/* att naming */ -{"cbtw", 0, 0x6698, _, NoModrm, 0, 0, 0}, -{"cwtl", 0, 0x98, _, NoModrm, 0, 0, 0}, -{"cwtd", 0, 0x6699, _, NoModrm, 0, 0, 0}, -{"cltd", 0, 0x99, _, NoModrm, 0, 0, 0}, - -/* Warning! the mul/imul (opcode 0xf6) must only have 1 operand! They are - expanding 64-bit multiplies, and *cannot* be selected to accomplish - 'imul %ebx, %eax' (opcode 0x0faf must be used in this case) - These multiplies can only be selected with single opearnd forms. */ -{"mul", 1, 0xf6, 4, W|Modrm, Reg|Mem, 0, 0}, -{"imul", 1, 0xf6, 5, W|Modrm, Reg|Mem, 0, 0}, - - - - -/* imulKludge here is needed to reverse the i.rm.reg & i.rm.regmem fields. - These instructions are exceptions: 'imul $2, %eax, %ecx' would put - '%eax' in the reg field and '%ecx' in the regmem field if we did not - switch them. */ -{"imul", 2, 0x0faf, _, Modrm|ReverseRegRegmem, WordReg|Mem, WordReg, 0}, -{"imul", 3, 0x6b, _, Modrm|ReverseRegRegmem, Imm8S, WordReg|Mem, WordReg}, -{"imul", 3, 0x69, _, Modrm|ReverseRegRegmem, Imm16|Imm32, WordReg|Mem, WordReg}, -/* - imul with 2 operands mimicks imul with 3 by puting register both - in i.rm.reg & i.rm.regmem fields -*/ -{"imul", 2, 0x6b, _, Modrm|imulKludge, Imm8S, WordReg, 0}, -{"imul", 2, 0x69, _, Modrm|imulKludge, Imm16|Imm32, WordReg, 0}, -{"div", 1, 0xf6, 6, W|Modrm, Reg|Mem, 0, 0}, -{"div", 2, 0xf6, 6, W|Modrm, Reg|Mem, Acc, 0}, -{"idiv", 1, 0xf6, 7, W|Modrm, Reg|Mem, 0, 0}, -{"idiv", 2, 0xf6, 7, W|Modrm, Reg|Mem, Acc, 0}, - -{"rol", 2, 0xd0, 0, W|Modrm, Imm1, Reg|Mem, 0}, -{"rol", 2, 0xc0, 0, W|Modrm, Imm8, Reg|Mem, 0}, -{"rol", 2, 0xd2, 0, W|Modrm, ShiftCount, Reg|Mem, 0}, -{"rol", 1, 0xd0, 0, W|Modrm, Reg|Mem, 0, 0}, - -{"ror", 2, 0xd0, 1, W|Modrm, Imm1, Reg|Mem, 0}, -{"ror", 2, 0xc0, 1, W|Modrm, Imm8, Reg|Mem, 0}, -{"ror", 2, 0xd2, 1, W|Modrm, ShiftCount, Reg|Mem, 0}, -{"ror", 1, 0xd0, 1, W|Modrm, Reg|Mem, 0, 0}, - -{"rcl", 2, 0xd0, 2, W|Modrm, Imm1, Reg|Mem, 0}, -{"rcl", 2, 0xc0, 2, W|Modrm, Imm8, Reg|Mem, 0}, -{"rcl", 2, 0xd2, 2, W|Modrm, ShiftCount, Reg|Mem, 0}, -{"rcl", 1, 0xd0, 2, W|Modrm, Reg|Mem, 0, 0}, - -{"rcr", 2, 0xd0, 3, W|Modrm, Imm1, Reg|Mem, 0}, -{"rcr", 2, 0xc0, 3, W|Modrm, Imm8, Reg|Mem, 0}, -{"rcr", 2, 0xd2, 3, W|Modrm, ShiftCount, Reg|Mem, 0}, -{"rcr", 1, 0xd0, 3, W|Modrm, Reg|Mem, 0, 0}, - -{"sal", 2, 0xd0, 4, W|Modrm, Imm1, Reg|Mem, 0}, -{"sal", 2, 0xc0, 4, W|Modrm, Imm8, Reg|Mem, 0}, -{"sal", 2, 0xd2, 4, W|Modrm, ShiftCount, Reg|Mem, 0}, -{"sal", 1, 0xd0, 4, W|Modrm, Reg|Mem, 0, 0}, -{"shl", 2, 0xd0, 4, W|Modrm, Imm1, Reg|Mem, 0}, -{"shl", 2, 0xc0, 4, W|Modrm, Imm8, Reg|Mem, 0}, -{"shl", 2, 0xd2, 4, W|Modrm, ShiftCount, Reg|Mem, 0}, -{"shl", 1, 0xd0, 4, W|Modrm, Reg|Mem, 0, 0}, - -{"shld", 3, 0x0fa4, _, Modrm, Imm8, WordReg, WordReg|Mem}, -{"shld", 3, 0x0fa5, _, Modrm, ShiftCount, WordReg, WordReg|Mem}, - -{"shr", 2, 0xd0, 5, W|Modrm, Imm1, Reg|Mem, 0}, -{"shr", 2, 0xc0, 5, W|Modrm, Imm8, Reg|Mem, 0}, -{"shr", 2, 0xd2, 5, W|Modrm, ShiftCount, Reg|Mem, 0}, -{"shr", 1, 0xd0, 5, W|Modrm, Reg|Mem, 0, 0}, - -{"shrd", 3, 0x0fac, _, Modrm, Imm8, WordReg, WordReg|Mem}, -{"shrd", 3, 0x0fad, _, Modrm, ShiftCount, WordReg, WordReg|Mem}, - -{"sar", 2, 0xd0, 7, W|Modrm, Imm1, Reg|Mem, 0}, -{"sar", 2, 0xc0, 7, W|Modrm, Imm8, Reg|Mem, 0}, -{"sar", 2, 0xd2, 7, W|Modrm, ShiftCount, Reg|Mem, 0}, -{"sar", 1, 0xd0, 7, W|Modrm, Reg|Mem, 0, 0}, - -/* control transfer instructions */ -#define CALL_PC_RELATIVE 0xe8 -{"call", 1, 0xe8, _, JumpDword, Disp32, 0, 0}, -{"call", 1, 0xff, 2, Modrm, Reg|Mem|JumpAbsolute, 0, 0}, -#define CALL_FAR_IMMEDIATE 0x9a -{"lcall", 2, 0x9a, _, JumpInterSegment, Imm16, Imm32, 0}, -{"lcall", 1, 0xff, 3, Modrm, Mem, 0, 0}, - -#define JUMP_PC_RELATIVE 0xeb -{"jmp", 1, 0xeb, _, Jump, Disp, 0, 0}, -{"jmp", 1, 0xff, 4, Modrm, Reg32|Mem|JumpAbsolute, 0, 0}, -#define JUMP_FAR_IMMEDIATE 0xea -{"ljmp", 2, 0xea, _, JumpInterSegment, Imm16, Imm32, 0}, -{"ljmp", 1, 0xff, 5, Modrm, Mem, 0, 0}, - -{"ret", 0, 0xc3, _, NoModrm, 0, 0, 0}, -{"ret", 1, 0xc2, _, NoModrm, Imm16, 0, 0}, -{"lret", 0, 0xcb, _, NoModrm, 0, 0, 0}, -{"lret", 1, 0xca, _, NoModrm, Imm16, 0, 0}, -{"enter", 2, 0xc8, _, NoModrm, Imm16, Imm8, 0}, -{"leave", 0, 0xc9, _, NoModrm, 0, 0, 0}, - -/* conditional jumps */ -{"jo", 1, 0x70, _, Jump, Disp, 0, 0}, - -{"jno", 1, 0x71, _, Jump, Disp, 0, 0}, - -{"jb", 1, 0x72, _, Jump, Disp, 0, 0}, -{"jc", 1, 0x72, _, Jump, Disp, 0, 0}, -{"jnae", 1, 0x72, _, Jump, Disp, 0, 0}, - -{"jnb", 1, 0x73, _, Jump, Disp, 0, 0}, -{"jnc", 1, 0x73, _, Jump, Disp, 0, 0}, -{"jae", 1, 0x73, _, Jump, Disp, 0, 0}, - -{"je", 1, 0x74, _, Jump, Disp, 0, 0}, -{"jz", 1, 0x74, _, Jump, Disp, 0, 0}, - -{"jne", 1, 0x75, _, Jump, Disp, 0, 0}, -{"jnz", 1, 0x75, _, Jump, Disp, 0, 0}, - -{"jbe", 1, 0x76, _, Jump, Disp, 0, 0}, -{"jna", 1, 0x76, _, Jump, Disp, 0, 0}, - -{"jnbe", 1, 0x77, _, Jump, Disp, 0, 0}, -{"ja", 1, 0x77, _, Jump, Disp, 0, 0}, - -{"js", 1, 0x78, _, Jump, Disp, 0, 0}, - -{"jns", 1, 0x79, _, Jump, Disp, 0, 0}, - -{"jp", 1, 0x7a, _, Jump, Disp, 0, 0}, -{"jpe", 1, 0x7a, _, Jump, Disp, 0, 0}, - -{"jnp", 1, 0x7b, _, Jump, Disp, 0, 0}, -{"jpo", 1, 0x7b, _, Jump, Disp, 0, 0}, - -{"jl", 1, 0x7c, _, Jump, Disp, 0, 0}, -{"jnge", 1, 0x7c, _, Jump, Disp, 0, 0}, - -{"jnl", 1, 0x7d, _, Jump, Disp, 0, 0}, -{"jge", 1, 0x7d, _, Jump, Disp, 0, 0}, - -{"jle", 1, 0x7e, _, Jump, Disp, 0, 0}, -{"jng", 1, 0x7e, _, Jump, Disp, 0, 0}, - -{"jnle", 1, 0x7f, _, Jump, Disp, 0, 0}, -{"jg", 1, 0x7f, _, Jump, Disp, 0, 0}, - -/* these turn into pseudo operations when disp is larger than 8 bits */ -#define IS_JUMP_ON_CX_ZERO(o) \ - (o == 0x67e3) -#define IS_JUMP_ON_ECX_ZERO(o) \ - (o == 0xe3) - -{"jcxz", 1, 0x67e3, _, JumpByte, Disp, 0, 0}, -{"jecxz", 1, 0xe3, _, JumpByte, Disp, 0, 0}, - -#define IS_LOOP_ECX_TIMES(o) \ - (o == 0xe2 || o == 0xe1 || o == 0xe0) - -{"loop", 1, 0xe2, _, JumpByte, Disp, 0, 0}, - -{"loopz", 1, 0xe1, _, JumpByte, Disp, 0, 0}, -{"loope", 1, 0xe1, _, JumpByte, Disp, 0, 0}, - -{"loopnz", 1, 0xe0, _, JumpByte, Disp, 0, 0}, -{"loopne", 1, 0xe0, _, JumpByte, Disp, 0, 0}, - -/* set byte on flag instructions */ -{"seto", 1, 0x0f90, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setno", 1, 0x0f91, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setb", 1, 0x0f92, 0, Modrm, Reg8|Mem, 0, 0}, -{"setnae", 1, 0x0f92, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setnb", 1, 0x0f93, 0, Modrm, Reg8|Mem, 0, 0}, -{"setae", 1, 0x0f93, 0, Modrm, Reg8|Mem, 0, 0}, - -{"sete", 1, 0x0f94, 0, Modrm, Reg8|Mem, 0, 0}, -{"setz", 1, 0x0f94, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setne", 1, 0x0f95, 0, Modrm, Reg8|Mem, 0, 0}, -{"setnz", 1, 0x0f95, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setbe", 1, 0x0f96, 0, Modrm, Reg8|Mem, 0, 0}, -{"setna", 1, 0x0f96, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setnbe", 1, 0x0f97, 0, Modrm, Reg8|Mem, 0, 0}, -{"seta", 1, 0x0f97, 0, Modrm, Reg8|Mem, 0, 0}, - -{"sets", 1, 0x0f98, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setns", 1, 0x0f99, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setp", 1, 0x0f9a, 0, Modrm, Reg8|Mem, 0, 0}, -{"setpe", 1, 0x0f9a, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setnp", 1, 0x0f9b, 0, Modrm, Reg8|Mem, 0, 0}, -{"setpo", 1, 0x0f9b, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setl", 1, 0x0f9c, 0, Modrm, Reg8|Mem, 0, 0}, -{"setnge", 1, 0x0f9c, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setnl", 1, 0x0f9d, 0, Modrm, Reg8|Mem, 0, 0}, -{"setge", 1, 0x0f9d, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setle", 1, 0x0f9e, 0, Modrm, Reg8|Mem, 0, 0}, -{"setng", 1, 0x0f9e, 0, Modrm, Reg8|Mem, 0, 0}, - -{"setnle", 1, 0x0f9f, 0, Modrm, Reg8|Mem, 0, 0}, -{"setg", 1, 0x0f9f, 0, Modrm, Reg8|Mem, 0, 0}, - -#define IS_STRING_INSTRUCTION(o) \ - ((o) == 0xa6 || (o) == 0x6c || (o) == 0x6e || (o) == 0x6e || \ - (o) == 0xac || (o) == 0xa4 || (o) == 0xae || (o) == 0xaa || \ - (o) == 0xd7) - -/* string manipulation */ -{"cmps", 0, 0xa6, _, W|NoModrm, 0, 0, 0}, -{"ins", 0, 0x6c, _, W|NoModrm, 0, 0, 0}, -{"outs", 0, 0x6e, _, W|NoModrm, 0, 0, 0}, -{"lods", 0, 0xac, _, W|NoModrm, 0, 0, 0}, -{"movs", 0, 0xa4, _, W|NoModrm, 0, 0, 0}, -{"scas", 0, 0xae, _, W|NoModrm, 0, 0, 0}, -{"stos", 0, 0xaa, _, W|NoModrm, 0, 0, 0}, -{"xlat", 0, 0xd7, _, NoModrm, 0, 0, 0}, - -/* bit manipulation */ -{"bsf", 2, 0x0fbc, _, Modrm|ReverseRegRegmem, Reg|Mem, Reg, 0}, -{"bsr", 2, 0x0fbd, _, Modrm|ReverseRegRegmem, Reg|Mem, Reg, 0}, -{"bt", 2, 0x0fa3, _, Modrm, Reg, Reg|Mem, 0}, -{"bt", 2, 0x0fba, 4, Modrm, Imm8, Reg|Mem, 0}, -{"btc", 2, 0x0fbb, _, Modrm, Reg, Reg|Mem, 0}, -{"btc", 2, 0x0fba, 7, Modrm, Imm8, Reg|Mem, 0}, -{"btr", 2, 0x0fb3, _, Modrm, Reg, Reg|Mem, 0}, -{"btr", 2, 0x0fba, 6, Modrm, Imm8, Reg|Mem, 0}, -{"bts", 2, 0x0fab, _, Modrm, Reg, Reg|Mem, 0}, -{"bts", 2, 0x0fba, 5, Modrm, Imm8, Reg|Mem, 0}, - -/* interrupts & op. sys insns */ -/* See i386.c for conversion of 'int $3' into the special int 3 insn. */ -#define INT_OPCODE 0xcd -#define INT3_OPCODE 0xcc -{"int", 1, 0xcd, _, NoModrm, Imm8, 0, 0}, -{"int3", 0, 0xcc, _, NoModrm, 0, 0, 0}, -{"into", 0, 0xce, _, NoModrm, 0, 0, 0}, -{"iret", 0, 0xcf, _, NoModrm, 0, 0, 0}, - -{"boundl", 2, 0x62, _, Modrm, Reg32, Mem, 0}, -{"boundw", 2, 0x6662, _, Modrm, Reg16, Mem, 0}, - -{"hlt", 0, 0xf4, _, NoModrm, 0, 0, 0}, -{"wait", 0, 0x9b, _, NoModrm, 0, 0, 0}, -/* nop is actually 'xchgl %eax, %eax' */ -{"nop", 0, 0x90, _, NoModrm, 0, 0, 0}, - -/* protection control */ -{"arpl", 2, 0x63, _, Modrm, Reg16, Reg16|Mem, 0}, -{"lar", 2, 0x0f02, _, Modrm|ReverseRegRegmem, WordReg|Mem, WordReg, 0}, -{"lgdt", 1, 0x0f01, 2, Modrm, Mem, 0, 0}, -{"lidt", 1, 0x0f01, 3, Modrm, Mem, 0, 0}, -{"lldt", 1, 0x0f00, 2, Modrm, WordReg|Mem, 0, 0}, -{"lmsw", 1, 0x0f01, 6, Modrm, WordReg|Mem, 0, 0}, -{"lsl", 2, 0x0f03, _, Modrm|ReverseRegRegmem, WordReg|Mem, WordReg, 0}, -{"ltr", 1, 0x0f00, 3, Modrm, WordReg|Mem, 0, 0}, - -{"sgdt", 1, 0x0f01, 0, Modrm, Mem, 0, 0}, -{"sidt", 1, 0x0f01, 1, Modrm, Mem, 0, 0}, -{"sldt", 1, 0x0f00, 0, Modrm, WordReg|Mem, 0, 0}, -{"smsw", 1, 0x0f01, 4, Modrm, WordReg|Mem, 0, 0}, -{"str", 1, 0x0f00, 1, Modrm, Reg16|Mem, 0, 0}, - -{"verr", 1, 0x0f00, 4, Modrm, WordReg|Mem, 0, 0}, -{"verw", 1, 0x0f00, 5, Modrm, WordReg|Mem, 0, 0}, - -/* floating point instructions */ - -/* load */ -{"fld", 1, 0xd9c0, _, ShortForm, FloatReg, 0, 0}, /* register */ -{"flds", 1, 0xd9, 0, Modrm, Mem, 0, 0}, /* %st0 <-- mem float */ -{"fildl", 1, 0xdb, 0, Modrm, Mem, 0, 0}, /* %st0 <-- mem word */ -{"fldl", 1, 0xdd, 0, Modrm, Mem, 0, 0}, /* %st0 <-- mem double */ -{"fldl", 1, 0xd9c0, _, ShortForm, FloatReg, 0, 0}, /* register */ -{"filds", 1, 0xdf, 0, Modrm, Mem, 0, 0}, /* %st0 <-- mem dword */ -{"fildq", 1, 0xdf, 5, Modrm, Mem, 0, 0}, /* %st0 <-- mem qword */ -{"fldt", 1, 0xdb, 5, Modrm, Mem, 0, 0}, /* %st0 <-- mem efloat */ -{"fbld", 1, 0xdf, 4, Modrm, Mem, 0, 0}, /* %st0 <-- mem bcd */ - -/* store (no pop) */ -{"fst", 1, 0xddd0, _, ShortForm, FloatReg, 0, 0}, /* register */ -{"fsts", 1, 0xd9, 2, Modrm, Mem, 0, 0}, /* %st0 --> mem float */ -{"fistl", 1, 0xdb, 2, Modrm, Mem, 0, 0}, /* %st0 --> mem dword */ -{"fstl", 1, 0xdd, 2, Modrm, Mem, 0, 0}, /* %st0 --> mem double */ -{"fstl", 1, 0xddd0, _, ShortForm, FloatReg, 0, 0}, /* register */ -{"fists", 1, 0xdf, 2, Modrm, Mem, 0, 0}, /* %st0 --> mem word */ - -/* store (with pop) */ -{"fstp", 1, 0xddd8, _, ShortForm, FloatReg, 0, 0}, /* register */ -{"fstps", 1, 0xd9, 3, Modrm, Mem, 0, 0}, /* %st0 --> mem float */ -{"fistpl", 1, 0xdb, 3, Modrm, Mem, 0, 0}, /* %st0 --> mem word */ -{"fstpl", 1, 0xdd, 3, Modrm, Mem, 0, 0}, /* %st0 --> mem double */ -{"fstpl", 1, 0xddd8, _, ShortForm, FloatReg, 0, 0}, /* register */ -{"fistps", 1, 0xdf, 3, Modrm, Mem, 0, 0}, /* %st0 --> mem dword */ -{"fistpq", 1, 0xdf, 7, Modrm, Mem, 0, 0}, /* %st0 --> mem qword */ -{"fstpt", 1, 0xdb, 7, Modrm, Mem, 0, 0}, /* %st0 --> mem efloat */ -{"fbstp", 1, 0xdf, 6, Modrm, Mem, 0, 0}, /* %st0 --> mem bcd */ - -/* exchange %st with %st0 */ -{"fxch", 1, 0xd9c8, _, ShortForm, FloatReg, 0, 0}, - -/* comparison (without pop) */ -{"fcom", 1, 0xd8d0, _, ShortForm, FloatReg, 0, 0}, -{"fcoms", 1, 0xd8, 2, Modrm, Mem, 0, 0}, /* compare %st0, mem float */ -{"ficoml", 1, 0xda, 2, Modrm, Mem, 0, 0}, /* compare %st0, mem word */ -{"fcoml", 1, 0xdc, 2, Modrm, Mem, 0, 0}, /* compare %st0, mem double */ -{"fcoml", 1, 0xd8d0, _, ShortForm, FloatReg, 0, 0}, -{"ficoms", 1, 0xde, 2, Modrm, Mem, 0, 0}, /* compare %st0, mem dword */ - -/* comparison (with pop) */ -{"fcomp", 1, 0xd8d8, _, ShortForm, FloatReg, 0, 0}, -{"fcomps", 1, 0xd8, 3, Modrm, Mem, 0, 0}, /* compare %st0, mem float */ -{"ficompl", 1, 0xda, 3, Modrm, Mem, 0, 0}, /* compare %st0, mem word */ -{"fcompl", 1, 0xdc, 3, Modrm, Mem, 0, 0}, /* compare %st0, mem double */ -{"fcompl", 1, 0xd8d8, _, ShortForm, FloatReg, 0, 0}, -{"ficomps", 1, 0xde, 3, Modrm, Mem, 0, 0}, /* compare %st0, mem dword */ -{"fcompp", 0, 0xded9, _, NoModrm, 0, 0, 0}, /* compare %st0, %st1 & pop twice */ - -/* unordered comparison (with pop) */ -{"fucom", 1, 0xdde0, _, ShortForm, FloatReg, 0, 0}, -{"fucomp", 1, 0xdde8, _, ShortForm, FloatReg, 0, 0}, -{"fucompp", 0, 0xdae9, _, NoModrm, 0, 0, 0}, /* ucompare %st0, %st1 & pop twice */ - -{"ftst", 0, 0xd9e4, _, NoModrm, 0, 0, 0}, /* test %st0 */ -{"fxam", 0, 0xd9e5, _, NoModrm, 0, 0, 0}, /* examine %st0 */ - -/* load constants into %st0 */ -{"fld1", 0, 0xd9e8, _, NoModrm, 0, 0, 0}, /* %st0 <-- 1.0 */ -{"fldl2t", 0, 0xd9e9, _, NoModrm, 0, 0, 0}, /* %st0 <-- log2(10) */ -{"fldl2e", 0, 0xd9ea, _, NoModrm, 0, 0, 0}, /* %st0 <-- log2(e) */ -{"fldpi", 0, 0xd9eb, _, NoModrm, 0, 0, 0}, /* %st0 <-- pi */ -{"fldlg2", 0, 0xd9ec, _, NoModrm, 0, 0, 0}, /* %st0 <-- log10(2) */ -{"fldln2", 0, 0xd9ed, _, NoModrm, 0, 0, 0}, /* %st0 <-- ln(2) */ -{"fldz", 0, 0xd9ee, _, NoModrm, 0, 0, 0}, /* %st0 <-- 0.0 */ - -/* arithmetic */ - -/* add */ -{"fadd", 1, 0xd8c0, _, ShortForm, FloatReg, 0, 0}, -{"fadd", 2, 0xd8c0, _, ShortForm|FloatD, FloatReg, FloatAcc, 0}, -{"fadd", 0, 0xdcc1, _, NoModrm, 0, 0, 0}, /* alias for fadd %st, %st(1) */ -{"faddp", 1, 0xdac0, _, ShortForm, FloatReg, 0, 0}, -{"faddp", 2, 0xdac0, _, ShortForm|FloatD, FloatReg, FloatAcc, 0}, -{"faddp", 0, 0xdec1, _, NoModrm, 0, 0, 0}, /* alias for faddp %st, %st(1) */ -{"fadds", 1, 0xd8, 0, Modrm, Mem, 0, 0}, -{"fiaddl", 1, 0xda, 0, Modrm, Mem, 0, 0}, -{"faddl", 1, 0xdc, 0, Modrm, Mem, 0, 0}, -{"fiadds", 1, 0xde, 0, Modrm, Mem, 0, 0}, - -/* sub */ -/* Note: intel has decided that certain of these operations are reversed - in assembler syntax. */ -{"fsub", 1, 0xd8e0, _, ShortForm, FloatReg, 0, 0}, -{"fsub", 2, 0xd8e0, _, ShortForm, FloatReg, FloatAcc, 0}, -#ifdef NON_BROKEN_OPCODES -{"fsub", 2, 0xdce8, _, ShortForm, FloatAcc, FloatReg, 0}, -#else -{"fsub", 2, 0xdce0, _, ShortForm, FloatAcc, FloatReg, 0}, -#endif -{"fsub", 0, 0xdce1, _, NoModrm, 0, 0, 0}, -{"fsubp", 1, 0xdae0, _, ShortForm, FloatReg, 0, 0}, -{"fsubp", 2, 0xdae0, _, ShortForm, FloatReg, FloatAcc, 0}, -#ifdef NON_BROKEN_OPCODES -{"fsubp", 2, 0xdee8, _, ShortForm, FloatAcc, FloatReg, 0}, -#else -{"fsubp", 2, 0xdee0, _, ShortForm, FloatAcc, FloatReg, 0}, -#endif -{"fsubp", 0, 0xdee1, _, NoModrm, 0, 0, 0}, -{"fsubs", 1, 0xd8, 4, Modrm, Mem, 0, 0}, -{"fisubl", 1, 0xda, 4, Modrm, Mem, 0, 0}, -{"fsubl", 1, 0xdc, 4, Modrm, Mem, 0, 0}, -{"fisubs", 1, 0xde, 4, Modrm, Mem, 0, 0}, - -/* sub reverse */ -{"fsubr", 1, 0xd8e8, _, ShortForm, FloatReg, 0, 0}, -{"fsubr", 2, 0xd8e8, _, ShortForm, FloatReg, FloatAcc, 0}, -#ifdef NON_BROKEN_OPCODES -{"fsubr", 2, 0xdce0, _, ShortForm, FloatAcc, FloatReg, 0}, -#else -{"fsubr", 2, 0xdce8, _, ShortForm, FloatAcc, FloatReg, 0}, -#endif -{"fsubr", 0, 0xdce9, _, NoModrm, 0, 0, 0}, -{"fsubrp", 1, 0xdae8, _, ShortForm, FloatReg, 0, 0}, -{"fsubrp", 2, 0xdae8, _, ShortForm, FloatReg, FloatAcc, 0}, -#ifdef NON_BROKEN_OPCODES -{"fsubrp", 2, 0xdee0, _, ShortForm, FloatAcc, FloatReg, 0}, -#else -{"fsubrp", 2, 0xdee8, _, ShortForm, FloatAcc, FloatReg, 0}, -#endif -{"fsubrp", 0, 0xdee9, _, NoModrm, 0, 0, 0}, -{"fsubrs", 1, 0xd8, 5, Modrm, Mem, 0, 0}, -{"fisubrl", 1, 0xda, 5, Modrm, Mem, 0, 0}, -{"fsubrl", 1, 0xdc, 5, Modrm, Mem, 0, 0}, -{"fisubrs", 1, 0xde, 5, Modrm, Mem, 0, 0}, - -/* mul */ -{"fmul", 1, 0xd8c8, _, ShortForm, FloatReg, 0, 0}, -{"fmul", 2, 0xd8c8, _, ShortForm|FloatD, FloatReg, FloatAcc, 0}, -{"fmul", 0, 0xdcc9, _, NoModrm, 0, 0, 0}, -{"fmulp", 1, 0xdac8, _, ShortForm, FloatReg, 0, 0}, -{"fmulp", 2, 0xdac8, _, ShortForm|FloatD, FloatReg, FloatAcc, 0}, -{"fmulp", 0, 0xdec9, _, NoModrm, 0, 0, 0}, -{"fmuls", 1, 0xd8, 1, Modrm, Mem, 0, 0}, -{"fimull", 1, 0xda, 1, Modrm, Mem, 0, 0}, -{"fmull", 1, 0xdc, 1, Modrm, Mem, 0, 0}, -{"fimuls", 1, 0xde, 1, Modrm, Mem, 0, 0}, - -/* div */ -/* Note: intel has decided that certain of these operations are reversed - in assembler syntax. */ -{"fdiv", 1, 0xd8f0, _, ShortForm, FloatReg, 0, 0}, -{"fdiv", 2, 0xd8f0, _, ShortForm, FloatReg, FloatAcc, 0}, -#ifdef NON_BROKEN_OPCODES -{"fdiv", 2, 0xdcf8, _, ShortForm, FloatAcc, FloatReg, 0}, -#else -{"fdiv", 2, 0xdcf0, _, ShortForm, FloatAcc, FloatReg, 0}, -#endif -{"fdiv", 0, 0xdcf1, _, NoModrm, 0, 0, 0}, -{"fdivp", 1, 0xdaf0, _, ShortForm, FloatReg, 0, 0}, -{"fdivp", 2, 0xdaf0, _, ShortForm, FloatReg, FloatAcc, 0}, -#ifdef NON_BROKEN_OPCODES -{"fdivp", 2, 0xdef8, _, ShortForm, FloatAcc, FloatReg, 0}, -#else -{"fdivp", 2, 0xdef0, _, ShortForm, FloatAcc, FloatReg, 0}, -#endif -{"fdivp", 0, 0xdef1, _, NoModrm, 0, 0, 0}, -{"fdivs", 1, 0xd8, 6, Modrm, Mem, 0, 0}, -{"fidivl", 1, 0xda, 6, Modrm, Mem, 0, 0}, -{"fdivl", 1, 0xdc, 6, Modrm, Mem, 0, 0}, -{"fidivs", 1, 0xde, 6, Modrm, Mem, 0, 0}, - -/* div reverse */ -{"fdivr", 1, 0xd8f8, _, ShortForm, FloatReg, 0, 0}, -{"fdivr", 2, 0xd8f8, _, ShortForm, FloatReg, FloatAcc, 0}, -#ifdef NON_BROKEN_OPCODES -{"fdivr", 2, 0xdcf0, _, ShortForm, FloatAcc, FloatReg, 0}, -#else -{"fdivr", 2, 0xdcf8, _, ShortForm, FloatAcc, FloatReg, 0}, -#endif -{"fdivr", 0, 0xdcf9, _, NoModrm, 0, 0, 0}, -{"fdivrp", 1, 0xdaf8, _, ShortForm, FloatReg, 0, 0}, -{"fdivrp", 2, 0xdaf8, _, ShortForm, FloatReg, FloatAcc, 0}, -#ifdef NON_BROKEN_OPCODES -{"fdivrp", 2, 0xdef0, _, ShortForm, FloatAcc, FloatReg, 0}, -#else -{"fdivrp", 2, 0xdef8, _, ShortForm, FloatAcc, FloatReg, 0}, -#endif -{"fdivrp", 0, 0xdef9, _, NoModrm, 0, 0, 0}, -{"fdivrs", 1, 0xd8, 7, Modrm, Mem, 0, 0}, -{"fidivrl", 1, 0xda, 7, Modrm, Mem, 0, 0}, -{"fdivrl", 1, 0xdc, 7, Modrm, Mem, 0, 0}, -{"fidivrs", 1, 0xde, 7, Modrm, Mem, 0, 0}, - -{"f2xm1", 0, 0xd9f0, _, NoModrm, 0, 0, 0}, -{"fyl2x", 0, 0xd9f1, _, NoModrm, 0, 0, 0}, -{"fptan", 0, 0xd9f2, _, NoModrm, 0, 0, 0}, -{"fpatan", 0, 0xd9f3, _, NoModrm, 0, 0, 0}, -{"fxtract", 0, 0xd9f4, _, NoModrm, 0, 0, 0}, -{"fprem1", 0, 0xd9f5, _, NoModrm, 0, 0, 0}, -{"fdecstp", 0, 0xd9f6, _, NoModrm, 0, 0, 0}, -{"fincstp", 0, 0xd9f7, _, NoModrm, 0, 0, 0}, -{"fprem", 0, 0xd9f8, _, NoModrm, 0, 0, 0}, -{"fyl2xp1", 0, 0xd9f9, _, NoModrm, 0, 0, 0}, -{"fsqrt", 0, 0xd9fa, _, NoModrm, 0, 0, 0}, -{"fsincos", 0, 0xd9fb, _, NoModrm, 0, 0, 0}, -{"frndint", 0, 0xd9fc, _, NoModrm, 0, 0, 0}, -{"fscale", 0, 0xd9fd, _, NoModrm, 0, 0, 0}, -{"fsin", 0, 0xd9fe, _, NoModrm, 0, 0, 0}, -{"fcos", 0, 0xd9ff, _, NoModrm, 0, 0, 0}, - -{"fchs", 0, 0xd9e0, _, NoModrm, 0, 0, 0}, -{"fabs", 0, 0xd9e1, _, NoModrm, 0, 0, 0}, - -/* processor control */ -{"fninit", 0, 0xdbe3, _, NoModrm, 0, 0, 0}, -{"finit", 0, 0xdbe3, _, NoModrm, 0, 0, 0}, -{"fldcw", 1, 0xd9, 5, Modrm, Mem, 0, 0}, -{"fnstcw", 1, 0xd9, 7, Modrm, Mem, 0, 0}, -{"fstcw", 1, 0xd9, 7, Modrm, Mem, 0, 0}, -{"fnstsw", 1, 0xdfe0, _, NoModrm, Acc, 0, 0}, -{"fnstsw", 1, 0xdd, 7, Modrm, Mem, 0, 0}, -{"fnstsw", 0, 0xdfe0, _, NoModrm, 0, 0, 0}, -{"fstsw", 1, 0xdfe0, _, NoModrm, Acc, 0, 0}, -{"fstsw", 1, 0xdd, 7, Modrm, Mem, 0, 0}, -{"fstsw", 0, 0xdfe0, _, NoModrm, 0, 0, 0}, -{"fnclex", 0, 0xdbe2, _, NoModrm, 0, 0, 0}, -{"fclex", 0, 0xdbe2, _, NoModrm, 0, 0, 0}, -/* - We ignore the short format (287) versions of fstenv/fldenv & fsave/frstor - instructions; i'm not sure how to add them or how they are different. - My 386/387 book offers no details about this. -*/ -{"fnstenv", 1, 0xd9, 6, Modrm, Mem, 0, 0}, -{"fstenv", 1, 0xd9, 6, Modrm, Mem, 0, 0}, -{"fldenv", 1, 0xd9, 4, Modrm, Mem, 0, 0}, -{"fnsave", 1, 0xdd, 6, Modrm, Mem, 0, 0}, -{"fsave", 1, 0xdd, 6, Modrm, Mem, 0, 0}, -{"frstor", 1, 0xdd, 4, Modrm, Mem, 0, 0}, - -{"ffree", 1, 0xddc0, _, ShortForm, FloatReg, 0, 0}, -{"fnop", 0, 0xd9d0, _, NoModrm, 0, 0, 0}, -{"fwait", 0, 0x9b, _, NoModrm, 0, 0, 0}, - -/* - opcode prefixes; we allow them as seperate insns too - (see prefix table below) -*/ -{"aword", 0, 0x67, _, NoModrm, 0, 0, 0}, -{"word", 0, 0x66, _, NoModrm, 0, 0, 0}, -{"lock", 0, 0xf0, _, NoModrm, 0, 0, 0}, -{"cs", 0, 0x2e, _, NoModrm, 0, 0, 0}, -{"ds", 0, 0x3e, _, NoModrm, 0, 0, 0}, -{"es", 0, 0x26, _, NoModrm, 0, 0, 0}, -{"fs", 0, 0x64, _, NoModrm, 0, 0, 0}, -{"gs", 0, 0x65, _, NoModrm, 0, 0, 0}, -{"ss", 0, 0x36, _, NoModrm, 0, 0, 0}, -{"rep", 0, 0xf3, _, NoModrm, 0, 0, 0}, -{"repe", 0, 0xf3, _, NoModrm, 0, 0, 0}, -{ "repne", 0, 0xf2, _, NoModrm, 0, 0, 0}, - -{"", 0, 0, 0, 0, 0, 0, 0} /* sentinal */ -}; -#undef _ - -template *i386_optab_end - = i386_optab + sizeof (i386_optab)/sizeof(i386_optab[0]); - -/* 386 register table */ - -reg_entry i386_regtab[] = { - /* 8 bit regs */ - {"al", Reg8|Acc, 0}, {"cl", Reg8|ShiftCount, 1}, {"dl", Reg8, 2}, - {"bl", Reg8, 3}, - {"ah", Reg8, 4}, {"ch", Reg8, 5}, {"dh", Reg8, 6}, {"bh", Reg8, 7}, - /* 16 bit regs */ - {"ax", Reg16|Acc, 0}, {"cx", Reg16, 1}, {"dx", Reg16|InOutPortReg, 2}, {"bx", Reg16, 3}, - {"sp", Reg16, 4}, {"bp", Reg16, 5}, {"si", Reg16, 6}, {"di", Reg16, 7}, - /* 32 bit regs */ - {"eax", Reg32|Acc, 0}, {"ecx", Reg32, 1}, {"edx", Reg32, 2}, {"ebx", Reg32, 3}, - {"esp", Reg32, 4}, {"ebp", Reg32, 5}, {"esi", Reg32, 6}, {"edi", Reg32, 7}, - /* segment registers */ - {"es", SReg2, 0}, {"cs", SReg2, 1}, {"ss", SReg2, 2}, - {"ds", SReg2, 3}, {"fs", SReg3, 4}, {"gs", SReg3, 5}, - /* control registers */ - {"cr0", Control, 0}, {"cr2", Control, 2}, {"cr3", Control, 3}, - /* debug registers */ - {"db0", Debug, 0}, {"db1", Debug, 1}, {"db2", Debug, 2}, - {"db3", Debug, 3}, {"db6", Debug, 6}, {"db7", Debug, 7}, - /* test registers */ - {"tr6", Test, 6}, {"tr7", Test, 7}, - /* float registers */ - {"st(0)", FloatReg|FloatAcc, 0}, - {"st", FloatReg|FloatAcc, 0}, - {"st(1)", FloatReg, 1}, {"st(2)", FloatReg, 2}, - {"st(3)", FloatReg, 3}, {"st(4)", FloatReg, 4}, {"st(5)", FloatReg, 5}, - {"st(6)", FloatReg, 6}, {"st(7)", FloatReg, 7} -}; - -#define MAX_REG_NAME_SIZE 8 /* for parsing register names from input */ - -reg_entry *i386_regtab_end - = i386_regtab + sizeof(i386_regtab)/sizeof(i386_regtab[0]); - -/* segment stuff */ -seg_entry cs = { "cs", 0x2e }; -seg_entry ds = { "ds", 0x3e }; -seg_entry ss = { "ss", 0x36 }; -seg_entry es = { "es", 0x26 }; -seg_entry fs = { "fs", 0x64 }; -seg_entry gs = { "gs", 0x65 }; -seg_entry null = { "", 0x0 }; - -/* - This table is used to store the default segment register implied by all - possible memory addressing modes. - It is indexed by the mode & modrm entries of the modrm byte as follows: - index = (mode<<3) | modrm; -*/ -seg_entry *one_byte_segment_defaults[] = { - /* mode 0 */ - &ds, &ds, &ds, &ds, &null, &ds, &ds, &ds, - /* mode 1 */ - &ds, &ds, &ds, &ds, &null, &ss, &ds, &ds, - /* mode 2 */ - &ds, &ds, &ds, &ds, &null, &ss, &ds, &ds, - /* mode 3 --- not a memory reference; never referenced */ -}; - -seg_entry *two_byte_segment_defaults[] = { - /* mode 0 */ - &ds, &ds, &ds, &ds, &ss, &ds, &ds, &ds, - /* mode 1 */ - &ds, &ds, &ds, &ds, &ss, &ds, &ds, &ds, - /* mode 2 */ - &ds, &ds, &ds, &ds, &ss, &ds, &ds, &ds, - /* mode 3 --- not a memory reference; never referenced */ -}; - -prefix_entry i386_prefixtab[] = { - { "addr16", 0x67 }, /* address size prefix ==> 16bit addressing - * (How is this useful?) */ -#define WORD_PREFIX_OPCODE 0x66 - { "data16", 0x66 }, /* operand size prefix */ - { "lock", 0xf0 }, /* bus lock prefix */ - { "wait", 0x9b }, /* wait for coprocessor */ - { "cs", 0x2e }, { "ds", 0x3e }, /* segment overrides ... */ - { "es", 0x26 }, { "fs", 0x64 }, - { "gs", 0x65 }, { "ss", 0x36 }, -/* REPE & REPNE used to detect rep/repne with a non-string instruction */ -#define REPNE 0xf2 -#define REPE 0xf3 - { "rep", 0xf3 }, { "repe", 0xf3 }, /* repeat string instructions */ - { "repne", 0xf2 } -}; - -prefix_entry *i386_prefixtab_end - = i386_prefixtab + sizeof(i386_prefixtab)/sizeof(i386_prefixtab[0]); - diff --git a/gnu/usr.bin/as/config/i386.c b/gnu/usr.bin/as/config/i386.c deleted file mode 100644 index 2281acd..0000000 --- a/gnu/usr.bin/as/config/i386.c +++ /dev/null @@ -1,1946 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - */ - -#ifndef lint -static char sccsid[] = "@(#)i386.c 6.4 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* i386.c -- Assemble code for the Intel 80386 - Copyright (C) 1989, Free Software Foundation. - -This file is part of GAS, the GNU Assembler. - -GAS 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 1, or (at your option) -any later version. - -GAS 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 GAS; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* - Intel 80386 machine specific gas. - Written by Eliot Dresselhaus (eliot@mgm.mit.edu). - Bugs & suggestions are completely welcome. This is free software. - Please help us make it better. -*/ - -#include -#include -#include - -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else -extern char *alloca(); -#endif -#ifdef USG -#define index strchr -#endif - -#include "as.h" -#include "read.h" -#include "flonum.h" -#include "obstack.h" -#include "frags.h" -#include "struc-symbol.h" -#include "expr.h" -#include "symbols.h" -#include "hash.h" -#include "md.h" -#include "i386.h" -#include "i386-opcode.h" - -long omagic = OMAGIC; -char FLT_CHARS[] = "fFdDxX"; -char EXP_CHARS[] = "eE"; -char line_comment_chars[] = "#"; -char comment_chars[] = "#"; - -/* tables for lexical analysis */ -static char opcode_chars[256]; -static char register_chars[256]; -static char operand_chars[256]; -static char space_chars[256]; -static char identifier_chars[256]; -static char digit_chars[256]; - -/* lexical macros */ -#define is_opcode_char(x) (opcode_chars[(unsigned char) x]) -#define is_operand_char(x) (operand_chars[(unsigned char) x]) -#define is_register_char(x) (register_chars[(unsigned char) x]) -#define is_space_char(x) (space_chars[(unsigned char) x]) -#define is_identifier_char(x) (identifier_chars[(unsigned char) x]) -#define is_digit_char(x) (digit_chars[(unsigned char) x]) - -/* put here all non-digit non-letter charcters that may occur in an operand */ -static char operand_special_chars[] = "%$-+(,)*._~/<>|&^!:"; - -static char *ordinal_names[] = { "first", "second", "third" }; /* for printfs */ - -/* md_assemble() always leaves the strings it's passed unaltered. To - effect this we maintain a stack of saved characters that we've smashed - with '\0's (indicating end of strings for various sub-fields of the - assembler instruction). */ -static char save_stack[32]; -static char *save_stack_p; /* stack pointer */ -#define END_STRING_AND_SAVE(s) *save_stack_p++ = *s; *s = '\0' -#define RESTORE_END_STRING(s) *s = *--save_stack_p - -/* The instruction we're assembling. */ -static i386_insn i; - -/* Per instruction expressionS buffers: 2 displacements & 2 immediate max. */ -static expressionS disp_expressions[2], im_expressions[2]; - -/* pointers to ebp & esp entries in reg_hash hash table */ -static reg_entry *ebp, *esp; - -static int this_operand; /* current operand we are working on */ - -/* -Interface to relax_segment. -There are 2 relax states for 386 jump insns: one for conditional & one -for unconditional jumps. This is because the these two types of jumps -add different sizes to frags when we're figuring out what sort of jump -to choose to reach a given label. */ - -/* types */ -#define COND_JUMP 1 /* conditional jump */ -#define UNCOND_JUMP 2 /* unconditional jump */ -/* sizes */ -#define BYTE 0 -#define WORD 1 -#define DWORD 2 -#define UNKNOWN_SIZE 3 - -#define ENCODE_RELAX_STATE(type,size) ((type<<2) | (size)) -#define SIZE_FROM_RELAX_STATE(s) \ - ( (((s) & 0x3) == BYTE ? 1 : (((s) & 0x3) == WORD ? 2 : 4)) ) - -const relax_typeS md_relax_table[] = { -/* - The fields are: - 1) most positive reach of this state, - 2) most negative reach of this state, - 3) how many bytes this mode will add to the size of the current frag - 4) which index into the table to try if we can't fit into this one. -*/ - {1, 1, 0, 0}, - {1, 1, 0, 0}, - {1, 1, 0, 0}, - {1, 1, 0, 0}, - - /* For now we don't use word displacement jumps: they may be - untrustworthy. */ - {127+1, -128+1, 0, ENCODE_RELAX_STATE(COND_JUMP,DWORD) }, - /* word conditionals add 3 bytes to frag: - 2 opcode prefix; 1 displacement bytes */ - {32767+2, -32768+2, 3, ENCODE_RELAX_STATE(COND_JUMP,DWORD) }, - /* dword conditionals adds 4 bytes to frag: - 1 opcode prefix; 3 displacement bytes */ - {0, 0, 4, 0}, - {1, 1, 0, 0}, - - {127+1, -128+1, 0, ENCODE_RELAX_STATE(UNCOND_JUMP,DWORD) }, - /* word jmp adds 2 bytes to frag: - 1 opcode prefix; 1 displacement bytes */ - {32767+2, -32768+2, 2, ENCODE_RELAX_STATE(UNCOND_JUMP,DWORD) }, - /* dword jmp adds 3 bytes to frag: - 0 opcode prefix; 3 displacement bytes */ - {0, 0, 3, 0}, - {1, 1, 0, 0}, - -}; - -void float_cons (), cons (); - -/* Ignore certain directives generated by gcc. This probably should - not be here. */ -void dummy () -{ - while (*input_line_pointer && *input_line_pointer != '\n') - input_line_pointer++; -} - -const pseudo_typeS md_pseudo_table[] = { - { "ffloat", float_cons, 'f' }, - { "dfloat", float_cons, 'd' }, - { "tfloat", float_cons, 'x' }, - { "value", cons, 2 }, - { "ident", dummy, 0 }, /* ignore these directives */ - { "def", dummy, 0 }, - { "optim", dummy, 0 }, /* For sun386i cc */ - { "version", dummy, 0 }, - { "ln", dummy, 0 }, - { 0, 0, 0 } -}; - -/* for interface with expression () */ -extern char * input_line_pointer; -char * index (); - -char * output_invalid (); -reg_entry * parse_register (); - -/* obstack for constructing various things in md_begin */ -struct obstack o; - -/* hash table for opcode lookup */ -static struct hash_control *op_hash = (struct hash_control *) 0; -/* hash table for register lookup */ -static struct hash_control *reg_hash = (struct hash_control *) 0; -/* hash table for prefix lookup */ -static struct hash_control *prefix_hash = (struct hash_control *) 0; - - -void md_begin () -{ - char * hash_err; - - obstack_begin (&o,4096); - - /* initialize op_hash hash table */ - op_hash = hash_new(); /* xmalloc handles error */ - - { - register template *optab; - register templates *core_optab; - char *prev_name; - - optab = i386_optab; /* setup for loop */ - prev_name = optab->name; - obstack_grow (&o, optab, sizeof(template)); - core_optab = (templates *) xmalloc (sizeof (templates)); - - for (optab++; optab < i386_optab_end; optab++) { - if (! strcmp (optab->name, prev_name)) { - /* same name as before --> append to current template list */ - obstack_grow (&o, optab, sizeof(template)); - } else { - /* different name --> ship out current template list; - add to hash table; & begin anew */ - /* Note: end must be set before start! since obstack_next_free changes - upon opstack_finish */ - core_optab->end = (template *) obstack_next_free(&o); - core_optab->start = (template *) obstack_finish(&o); - hash_err = hash_insert (op_hash, prev_name, (char *) core_optab); - if (hash_err && *hash_err) { - hash_error: - as_fatal("Internal Error: Can't hash %s: %s",prev_name, hash_err); - } - prev_name = optab->name; - core_optab = (templates *) xmalloc (sizeof(templates)); - obstack_grow (&o, optab, sizeof(template)); - } - } - } - - /* initialize reg_hash hash table */ - reg_hash = hash_new(); - { - register reg_entry *regtab; - - for (regtab = i386_regtab; regtab < i386_regtab_end; regtab++) { - hash_err = hash_insert (reg_hash, regtab->reg_name, regtab); - if (hash_err && *hash_err) goto hash_error; - } - } - - esp = (reg_entry *) hash_find (reg_hash, "esp"); - ebp = (reg_entry *) hash_find (reg_hash, "ebp"); - - /* initialize reg_hash hash table */ - prefix_hash = hash_new(); - { - register prefix_entry *prefixtab; - - for (prefixtab = i386_prefixtab; - prefixtab < i386_prefixtab_end; prefixtab++) { - hash_err = hash_insert (prefix_hash, prefixtab->prefix_name, prefixtab); - if (hash_err && *hash_err) goto hash_error; - } - } - - /* fill in lexical tables: opcode_chars, operand_chars, space_chars */ - { - register unsigned int c; - - bzero (opcode_chars, sizeof(opcode_chars)); - bzero (operand_chars, sizeof(operand_chars)); - bzero (space_chars, sizeof(space_chars)); - bzero (identifier_chars, sizeof(identifier_chars)); - bzero (digit_chars, sizeof(digit_chars)); - - for (c = 0; c < 256; c++) { - if (islower(c) || isdigit(c)) { - opcode_chars[c] = c; - register_chars[c] = c; - } else if (isupper(c)) { - opcode_chars[c] = tolower(c); - register_chars[c] = opcode_chars[c]; - } else if (c == PREFIX_SEPERATOR) { - opcode_chars[c] = c; - } else if (c == ')' || c == '(') { - register_chars[c] = c; - } - - if (isupper(c) || islower(c) || isdigit(c)) - operand_chars[c] = c; - else if (c && index(operand_special_chars, c)) - operand_chars[c] = c; - - if (isdigit(c) || c == '-') digit_chars[c] = c; - - if (isalpha(c) || c == '_' || c == '.' || isdigit(c)) - identifier_chars[c] = c; - - if (c == ' ' || c == '\t') space_chars[c] = c; - } - } -} - -void md_end() {} /* not much to do here. */ - - -#ifdef DEBUG386 - -/* debugging routines for md_assemble */ -static void pi (), pte (), pt (), pe (), ps (); - -static void pi (line, x) - char * line; - i386_insn *x; -{ - register template *p; - int i; - - fprintf (stdout, "%s: template ", line); - pte (&x->tm); - fprintf (stdout, " modrm: mode %x reg %x reg/mem %x", - x->rm.mode, x->rm.reg, x->rm.regmem); - fprintf (stdout, " base %x index %x scale %x\n", - x->bi.base, x->bi.index, x->bi.scale); - for (i = 0; i < x->operands; i++) { - fprintf (stdout, " #%d: ", i+1); - pt (x->types[i]); - fprintf (stdout, "\n"); - if (x->types[i] & Reg) fprintf (stdout, "%s\n", x->regs[i]->reg_name); - if (x->types[i] & Imm) pe (x->imms[i]); - if (x->types[i] & (Disp|Abs)) pe (x->disps[i]); - } -} - -static void pte (t) - template *t; -{ - int i; - fprintf (stdout, " %d operands ", t->operands); - fprintf (stdout, "opcode %x ", - t->base_opcode); - if (t->extension_opcode != None) - fprintf (stdout, "ext %x ", t->extension_opcode); - if (t->opcode_modifier&D) - fprintf (stdout, "D"); - if (t->opcode_modifier&W) - fprintf (stdout, "W"); - fprintf (stdout, "\n"); - for (i = 0; i < t->operands; i++) { - fprintf (stdout, " #%d type ", i+1); - pt (t->operand_types[i]); - fprintf (stdout, "\n"); - } -} - -char *seg_names[] = { -"SEG_ABSOLUTE", "SEG_TEXT", "SEG_DATA", "SEG_BSS", "SEG_UNKNOWN", -"SEG_NONE", "SEG_PASS1", "SEG_GOOF", "SEG_BIG", "SEG_DIFFERENCE" }; - -static void pe (e) - expressionS *e; -{ - fprintf (stdout, " segment %s\n", seg_names[(int) e->X_seg]); - fprintf (stdout, " add_number %d (%x)\n", - e->X_add_number, e->X_add_number); - if (e->X_add_symbol) { - fprintf (stdout, " add_symbol "); - ps (e->X_add_symbol); - fprintf (stdout, "\n"); - } - if (e->X_subtract_symbol) { - fprintf (stdout, " sub_symbol "); - ps (e->X_subtract_symbol); - fprintf (stdout, "\n"); - } -} - -#define SYMBOL_TYPE(t) \ - (((t&N_TYPE) == N_UNDF) ? "UNDEFINED" : \ - (((t&N_TYPE) == N_ABS) ? "ABSOLUTE" : \ - (((t&N_TYPE) == N_TEXT) ? "TEXT" : \ - (((t&N_TYPE) == N_DATA) ? "DATA" : \ - (((t&N_TYPE) == N_BSS) ? "BSS" : "Bad n_type!"))))) - -static void ps (s) - symbolS *s; -{ - fprintf (stdout, "%s type %s%s", - s->sy_nlist.n_un.n_name, - (s->sy_nlist.n_type&N_EXT) ? "EXTERNAL " : "", - SYMBOL_TYPE (s->sy_nlist.n_type)); -} - -struct type_name { - uint mask; - char *tname; -} type_names[] = { - { Reg8, "r8" }, { Reg16, "r16" }, { Reg32, "r32" }, { Imm8, "i8" }, - { Imm8S, "i8s" }, - { Imm16, "i16" }, { Imm32, "i32" }, { Mem8, "Mem8"}, { Mem16, "Mem16"}, - { Mem32, "Mem32"}, { BaseIndex, "BaseIndex" }, - { Abs8, "Abs8" }, { Abs16, "Abs16" }, { Abs32, "Abs32" }, - { Disp8, "d8" }, { Disp16, "d16" }, - { Disp32, "d32" }, { SReg2, "SReg2" }, { SReg3, "SReg3" }, { Acc, "Acc" }, - { InOutPortReg, "InOutPortReg" }, { ShiftCount, "ShiftCount" }, - { Imm1, "i1" }, { Control, "control reg" }, {Test, "test reg"}, - { FloatReg, "FReg"}, {FloatAcc, "FAcc"}, - { JumpAbsolute, "Jump Absolute"}, - { 0, "" } -}; - -static void pt (t) - uint t; -{ - register struct type_name *ty; - - if (t == Unknown) { - fprintf (stdout, "Unknown"); - } else { - for (ty = type_names; ty->mask; ty++) - if (t & ty->mask) fprintf (stdout, "%s, ", ty->tname); - } - fflush (stdout); -} - -#endif /* DEBUG386 */ - -/* - This is the guts of the machine-dependent assembler. LINE points to a - machine dependent instruction. This funciton is supposed to emit - the frags/bytes it assembles to. - */ -void md_assemble (line) - char *line; -{ - /* Holds temlate once we've found it. */ - register template * t; - - /* Possible templates for current insn */ - templates *current_templates = (templates *) 0; - - /* Initialize globals. */ - bzero (&i, sizeof(i)); - bzero (disp_expressions, sizeof(disp_expressions)); - bzero (im_expressions, sizeof(im_expressions)); - save_stack_p = save_stack; /* reset stack pointer */ - - /* Fist parse an opcode & call i386_operand for the operands. - We assume that the scrubber has arranged it so that line[0] is the valid - start of a (possibly prefixed) opcode. */ - { - register char *l = line; /* Fast place to put LINE. */ - - /* TRUE if operand is pending after ','. */ - uint expecting_operand = 0; - /* TRUE if we found a prefix only acceptable with string insns. */ - uint expecting_string_instruction = 0; - /* Non-zero if operand parens not balenced. */ - uint paren_not_balenced; - char * token_start = l; - - while (! is_space_char(*l) && *l != END_OF_INSN) { - if (! is_opcode_char(*l)) { - as_bad ("invalid character %s in opcode", output_invalid(*l)); - return; - } else if (*l != PREFIX_SEPERATOR) { - *l = opcode_chars[(unsigned char) *l]; /* fold case of opcodes */ - l++; - } else { /* this opcode's got a prefix */ - register int q; - register prefix_entry * prefix; - - if (l == token_start) { - as_bad ("expecting prefix; got nothing"); - return; - } - END_STRING_AND_SAVE (l); - prefix = (prefix_entry *) hash_find (prefix_hash, token_start); - if (! prefix) { - as_bad ("no such opcode prefix ('%s')", token_start); - return; - } - RESTORE_END_STRING (l); - /* check for repeated prefix */ - for (q = 0; q < i.prefixes; q++) - if (i.prefix[q] == prefix->prefix_code) { - as_bad ("same prefix used twice; you don't really want this!"); - return; - } - if (i.prefixes == MAX_PREFIXES) { - as_bad ("too many opcode prefixes"); - return; - } - i.prefix[i.prefixes++] = prefix->prefix_code; - if (prefix->prefix_code == REPE || prefix->prefix_code == REPNE) - expecting_string_instruction = TRUE; - /* skip past PREFIX_SEPERATOR and reset token_start */ - token_start = ++l; - } - } - END_STRING_AND_SAVE (l); - if (token_start == l) { - as_bad ("expecting opcode; got nothing"); - return; - } - - /* Lookup insn in hash; try intel & att naming conventions if appropriate; - that is: we only use the opcode suffix 'b' 'w' or 'l' if we need to. */ - current_templates = (templates *) hash_find (op_hash, token_start); - if (! current_templates) { - int last_index = strlen(token_start) - 1; - char last_char = token_start[last_index]; - switch (last_char) { - case DWORD_OPCODE_SUFFIX: - case WORD_OPCODE_SUFFIX: - case BYTE_OPCODE_SUFFIX: - token_start[last_index] = '\0'; - current_templates = (templates *) hash_find (op_hash, token_start); - token_start[last_index] = last_char; - i.suffix = last_char; - } - if (!current_templates) { - as_bad ("no such 386 instruction: `%s'", token_start); return; - } - } - RESTORE_END_STRING (l); - - /* check for rep/repne without a string instruction */ - if (expecting_string_instruction && - ! IS_STRING_INSTRUCTION (current_templates-> - start->base_opcode)) { - as_bad ("expecting string instruction after rep/repne"); - return; - } - - /* There may be operands to parse. */ - if (*l != END_OF_INSN && - /* For string instructions, we ignore any operands if given. This - kludges, for example, 'rep/movsb %ds:(%esi), %es:(%edi)' where - the operands are always going to be the same, and are not really - encoded in machine code. */ - ! IS_STRING_INSTRUCTION (current_templates-> - start->base_opcode)) { - /* parse operands */ - do { - /* skip optional white space before operand */ - while (! is_operand_char(*l) && *l != END_OF_INSN) { - if (! is_space_char(*l)) { - as_bad ("invalid character %s before %s operand", - output_invalid(*l), - ordinal_names[i.operands]); - return; - } - l++; - } - token_start = l; /* after white space */ - paren_not_balenced = 0; - while (paren_not_balenced || *l != ',') { - if (*l == END_OF_INSN) { - if (paren_not_balenced) { - as_bad ("unbalenced parenthesis in %s operand.", - ordinal_names[i.operands]); - return; - } else break; /* we are done */ - } else if (! is_operand_char(*l)) { - as_bad ("invalid character %s in %s operand", - output_invalid(*l), - ordinal_names[i.operands]); - return; - } - if (*l == '(') ++paren_not_balenced; - if (*l == ')') --paren_not_balenced; - l++; - } - if (l != token_start) { /* yes, we've read in another operand */ - uint operand_ok; - this_operand = i.operands++; - if (i.operands > MAX_OPERANDS) { - as_bad ("spurious operands; (%d operands/instruction max)", - MAX_OPERANDS); - return; - } - /* now parse operand adding info to 'i' as we go along */ - END_STRING_AND_SAVE (l); - operand_ok = i386_operand (token_start); - RESTORE_END_STRING (l); /* restore old contents */ - if (!operand_ok) return; - } else { - if (expecting_operand) { - expecting_operand_after_comma: - as_bad ("expecting operand after ','; got nothing"); - return; - } - if (*l == ',') { - as_bad ("expecting operand before ','; got nothing"); - return; - } - } - - /* now *l must be either ',' or END_OF_INSN */ - if (*l == ',') { - if (*++l == END_OF_INSN) { /* just skip it, if it's \n complain */ - goto expecting_operand_after_comma; - } - expecting_operand = TRUE; - } - } while (*l != END_OF_INSN); /* until we get end of insn */ - } - } - - /* Now we've parsed the opcode into a set of templates, and have the - operands at hand. - Next, we find a template that matches the given insn, - making sure the overlap of the given operands types is consistent - with the template operand types. */ - -#define MATCH(overlap,given_type) \ - (overlap && \ - (overlap & (JumpAbsolute|BaseIndex|Mem8)) \ - == (given_type & (JumpAbsolute|BaseIndex|Mem8))) - - /* If m0 and m1 are register matches they must be consistent - with the expected operand types t0 and t1. - That is, if both m0 & m1 are register matches - i.e. ( ((m0 & (Reg)) && (m1 & (Reg)) ) ? - then, either 1. or 2. must be true: - 1. the expected operand type register overlap is null: - (t0 & t1 & Reg) == 0 - AND - the given register overlap is null: - (m0 & m1 & Reg) == 0 - 2. the expected operand type register overlap == the given - operand type overlap: (t0 & t1 & m0 & m1 & Reg). - */ -#define CONSISTENT_REGISTER_MATCH(m0, m1, t0, t1) \ - ( ((m0 & (Reg)) && (m1 & (Reg))) ? \ - ( ((t0 & t1 & (Reg)) == 0 && (m0 & m1 & (Reg)) == 0) || \ - ((t0 & t1) & (m0 & m1) & (Reg)) \ - ) : 1) - { - register uint overlap0, overlap1; - expressionS * exp; - uint overlap2; - uint found_reverse_match; - - overlap0 = overlap1 = overlap2 = found_reverse_match = 0; - for (t = current_templates->start; - t < current_templates->end; - t++) { - - /* must have right number of operands */ - if (i.operands != t->operands) continue; - else if (!t->operands) break; /* 0 operands always matches */ - - overlap0 = i.types[0] & t->operand_types[0]; - switch (t->operands) { - case 1: - if (! MATCH (overlap0,i.types[0])) continue; - break; - case 2: case 3: - overlap1 = i.types[1] & t->operand_types[1]; - if (! MATCH (overlap0,i.types[0]) || - ! MATCH (overlap1,i.types[1]) || - ! CONSISTENT_REGISTER_MATCH(overlap0, overlap1, - t->operand_types[0], - t->operand_types[1])) { - - /* check if other direction is valid ... */ - if (! (t->opcode_modifier & COMES_IN_BOTH_DIRECTIONS)) - continue; - - /* try reversing direction of operands */ - overlap0 = i.types[0] & t->operand_types[1]; - overlap1 = i.types[1] & t->operand_types[0]; - if (! MATCH (overlap0,i.types[0]) || - ! MATCH (overlap1,i.types[1]) || - ! CONSISTENT_REGISTER_MATCH (overlap0, overlap1, - t->operand_types[0], - t->operand_types[1])) { - /* does not match either direction */ - continue; - } - /* found a reverse match here -- slip through */ - /* found_reverse_match holds which of D or FloatD we've found */ - found_reverse_match = t->opcode_modifier & COMES_IN_BOTH_DIRECTIONS; - } /* endif: not forward match */ - /* found either forward/reverse 2 operand match here */ - if (t->operands == 3) { - overlap2 = i.types[2] & t->operand_types[2]; - if (! MATCH (overlap2,i.types[2]) || - ! CONSISTENT_REGISTER_MATCH (overlap0, overlap2, - t->operand_types[0], - t->operand_types[2]) || - ! CONSISTENT_REGISTER_MATCH (overlap1, overlap2, - t->operand_types[1], - t->operand_types[2])) - continue; - } - /* found either forward/reverse 2 or 3 operand match here: - slip through to break */ - } - break; /* we've found a match; break out of loop */ - } /* for (t = ... */ - if (t == current_templates->end) { /* we found no match */ - as_bad ("operands given don't match any known 386 instruction"); - return; - } - - /* Copy the template we found (we may change it!). */ - bcopy (t, &i.tm, sizeof (template)); - t = &i.tm; /* alter new copy of template */ - - /* If there's no opcode suffix we try to invent one based on register - operands. */ - if (! i.suffix && i.reg_operands) { - /* We take i.suffix from the LAST register operand specified. This - assumes that the last register operands is the destination register - operand. */ - int o; - for (o = 0; o < MAX_OPERANDS; o++) - if (i.types[o] & Reg) { - i.suffix = (i.types[o] == Reg8) ? BYTE_OPCODE_SUFFIX : - (i.types[o] == Reg16) ? WORD_OPCODE_SUFFIX : - DWORD_OPCODE_SUFFIX; - } - } - - /* Make still unresolved immediate matches conform to size of immediate - given in i.suffix. Note: overlap2 cannot be an immediate! - We assume this. */ - if ((overlap0 & (Imm8|Imm8S|Imm16|Imm32)) - && overlap0 != Imm8 && overlap0 != Imm8S - && overlap0 != Imm16 && overlap0 != Imm32) { - if (! i.suffix) { - as_bad ("no opcode suffix given; can't determine immediate size"); - return; - } - overlap0 &= (i.suffix == BYTE_OPCODE_SUFFIX ? (Imm8|Imm8S) : - (i.suffix == WORD_OPCODE_SUFFIX ? Imm16 : Imm32)); - } - if ((overlap1 & (Imm8|Imm8S|Imm16|Imm32)) - && overlap1 != Imm8 && overlap1 != Imm8S - && overlap1 != Imm16 && overlap1 != Imm32) { - if (! i.suffix) { - as_bad ("no opcode suffix given; can't determine immediate size"); - return; - } - overlap1 &= (i.suffix == BYTE_OPCODE_SUFFIX ? (Imm8|Imm8S) : - (i.suffix == WORD_OPCODE_SUFFIX ? Imm16 : Imm32)); - } - - i.types[0] = overlap0; - i.types[1] = overlap1; - i.types[2] = overlap2; - - if (overlap0 & ImplicitRegister) i.reg_operands--; - if (overlap1 & ImplicitRegister) i.reg_operands--; - if (overlap2 & ImplicitRegister) i.reg_operands--; - if (overlap0 & Imm1) i.imm_operands = 0; /* kludge for shift insns */ - - if (found_reverse_match) { - uint save; - save = t->operand_types[0]; - t->operand_types[0] = t->operand_types[1]; - t->operand_types[1] = save; - } - - /* Finalize opcode. First, we change the opcode based on the operand - size given by i.suffix: we never have to change things for byte insns, - or when no opcode suffix is need to size the operands. */ - - if (! i.suffix && (t->opcode_modifier & W)) { - as_bad ("no opcode suffix given and no register operands; can't size instruction"); - return; - } - - if (i.suffix && i.suffix != BYTE_OPCODE_SUFFIX) { - /* Select between byte and word/dword operations. */ - if (t->opcode_modifier & W) - t->base_opcode |= W; - /* Now select between word & dword operations via the - operand size prefix. */ - if (i.suffix == WORD_OPCODE_SUFFIX) { - if (i.prefixes == MAX_PREFIXES) { - as_bad ("%d prefixes given and 'w' opcode suffix gives too many prefixes", - MAX_PREFIXES); - return; - } - i.prefix[i.prefixes++] = WORD_PREFIX_OPCODE; - } - } - - /* For insns with operands there are more diddles to do to the opcode. */ - if (i.operands) { - /* If we found a reverse match we must alter the opcode direction bit - found_reverse_match holds bit to set (different for int & - float insns). */ - - if (found_reverse_match) { - t->base_opcode |= found_reverse_match; - } - - /* - The imul $imm, %reg instruction is converted into - imul $imm, %reg, %reg. */ - if (t->opcode_modifier & imulKludge) { - i.regs[2] = i.regs[1]; /* Pretend we saw the 3 operand case. */ - i.reg_operands = 2; - } - - /* Certain instructions expect the destination to be in the i.rm.reg - field. This is by far the exceptional case. For these instructions, - if the source operand is a register, we must reverse the i.rm.reg - and i.rm.regmem fields. We accomplish this by faking that the - two register operands were given in the reverse order. */ - if ((t->opcode_modifier & ReverseRegRegmem) && i.reg_operands == 2) { - uint first_reg_operand = (i.types[0] & Reg) ? 0 : 1; - uint second_reg_operand = first_reg_operand + 1; - reg_entry *tmp = i.regs[first_reg_operand]; - i.regs[first_reg_operand] = i.regs[second_reg_operand]; - i.regs[second_reg_operand] = tmp; - } - - if (t->opcode_modifier & ShortForm) { - /* The register or float register operand is in operand 0 or 1. */ - uint o = (i.types[0] & (Reg|FloatReg)) ? 0 : 1; - /* Register goes in low 3 bits of opcode. */ - t->base_opcode |= i.regs[o]->reg_num; - } else if (t->opcode_modifier & ShortFormW) { - /* Short form with 0x8 width bit. Register is always dest. operand */ - t->base_opcode |= i.regs[1]->reg_num; - if (i.suffix == WORD_OPCODE_SUFFIX || - i.suffix == DWORD_OPCODE_SUFFIX) - t->base_opcode |= 0x8; - } else if (t->opcode_modifier & Seg2ShortForm) { - if (t->base_opcode == POP_SEG_SHORT && i.regs[0]->reg_num == 1) { - as_bad ("you can't 'pop cs' on the 386."); - return; - } - t->base_opcode |= (i.regs[0]->reg_num << 3); - } else if (t->opcode_modifier & Seg3ShortForm) { - /* 'push %fs' is 0x0fa0; 'pop %fs' is 0x0fa1. - 'push %gs' is 0x0fa8; 'pop %fs' is 0x0fa9. - So, only if i.regs[0]->reg_num == 5 (%gs) do we need - to change the opcode. */ - if (i.regs[0]->reg_num == 5) - t->base_opcode |= 0x08; - } else if (t->opcode_modifier & Modrm) { - /* The opcode is completed (modulo t->extension_opcode which must - be put into the modrm byte. - Now, we make the modrm & index base bytes based on all the info - we've collected. */ - - /* i.reg_operands MUST be the number of real register operands; - implicit registers do not count. */ - if (i.reg_operands == 2) { - uint source, dest; - source = (i.types[0] & (Reg|SReg2|SReg3|Control|Debug|Test)) ? 0 : 1; - dest = source + 1; - i.rm.mode = 3; - /* We must be careful to make sure that all segment/control/test/ - debug registers go into the i.rm.reg field (despite the whether - they are source or destination operands). */ - if (i.regs[dest]->reg_type & (SReg2|SReg3|Control|Debug|Test)) { - i.rm.reg = i.regs[dest]->reg_num; - i.rm.regmem = i.regs[source]->reg_num; - } else { - i.rm.reg = i.regs[source]->reg_num; - i.rm.regmem = i.regs[dest]->reg_num; - } - } else { /* if it's not 2 reg operands... */ - if (i.mem_operands) { - uint fake_zero_displacement = FALSE; - uint o = (i.types[0] & Mem) ? 0 : ((i.types[1] & Mem) ? 1 : 2); - - /* Encode memory operand into modrm byte and base index byte. */ - - if (i.base_reg == esp && ! i.index_reg) { - /* (%esp) becomes two byte modrm with no index register. */ - i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; - i.rm.mode = MODE_FROM_DISP_SIZE (i.types[o]); - i.bi.base = ESP_REG_NUM; - i.bi.index = NO_INDEX_REGISTER; - i.bi.scale = 0; /* Must be zero! */ - } else if (i.base_reg == ebp && !i.index_reg) { - if (! (i.types[o] & Disp)) { - /* Must fake a zero byte displacement. - There is no direct way to code '(%ebp)' directly. */ - fake_zero_displacement = TRUE; - /* fake_zero_displacement code does not set this. */ - i.types[o] |= Disp8; - } - i.rm.mode = MODE_FROM_DISP_SIZE (i.types[o]); - i.rm.regmem = EBP_REG_NUM; - } else if (! i.base_reg && (i.types[o] & BaseIndex)) { - /* There are three cases here. - Case 1: '<32bit disp>(,1)' -- indirect absolute. - (Same as cases 2 & 3 with NO index register) - Case 2: <32bit disp> (,) -- no base register with disp - Case 3: (, ) --- no base register; - no disp (must add 32bit 0 disp). */ - i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; - i.rm.mode = 0; /* 32bit mode */ - i.bi.base = NO_BASE_REGISTER; - i.types[o] &= ~Disp; - i.types[o] |= Disp32; /* Must be 32bit! */ - if (i.index_reg) { /* case 2 or case 3 */ - i.bi.index = i.index_reg->reg_num; - i.bi.scale = i.log2_scale_factor; - if (i.disp_operands == 0) - fake_zero_displacement = TRUE; /* case 3 */ - } else { - i.bi.index = NO_INDEX_REGISTER; - i.bi.scale = 0; - } - } else if (i.disp_operands && !i.base_reg && !i.index_reg) { - /* Operand is just <32bit disp> */ - i.rm.regmem = EBP_REG_NUM; - i.rm.mode = 0; - i.types[o] &= ~Disp; - i.types[o] |= Disp32; - } else { - /* It's not a special case; rev'em up. */ - i.rm.regmem = i.base_reg->reg_num; - i.rm.mode = MODE_FROM_DISP_SIZE (i.types[o]); - if (i.index_reg) { - i.rm.regmem = ESCAPE_TO_TWO_BYTE_ADDRESSING; - i.bi.base = i.base_reg->reg_num; - i.bi.index = i.index_reg->reg_num; - i.bi.scale = i.log2_scale_factor; - if (i.base_reg == ebp && i.disp_operands == 0) { /* pace */ - fake_zero_displacement = TRUE; - i.types[o] |= Disp8; - i.rm.mode = MODE_FROM_DISP_SIZE (i.types[o]); - } - } - } - if (fake_zero_displacement) { - /* Fakes a zero displacement assuming that i.types[o] holds - the correct displacement size. */ - exp = &disp_expressions[i.disp_operands++]; - i.disps[o] = exp; - exp->X_seg = SEG_ABSOLUTE; - exp->X_add_number = 0; - exp->X_add_symbol = (symbolS *) 0; - exp->X_subtract_symbol = (symbolS *) 0; - } - - /* Select the correct segment for the memory operand. */ - if (i.seg) { - uint seg_index; - seg_entry * default_seg; - - if (i.rm.regmem == ESCAPE_TO_TWO_BYTE_ADDRESSING) { - seg_index = (i.rm.mode<<3) | i.bi.base; - default_seg = two_byte_segment_defaults [seg_index]; - } else { - seg_index = (i.rm.mode<<3) | i.rm.regmem; - default_seg = one_byte_segment_defaults [seg_index]; - } - /* If the specified segment is not the default, use an - opcode prefix to select it */ - if (i.seg != default_seg) { - if (i.prefixes == MAX_PREFIXES) { - as_bad ("%d prefixes given and %s segment override gives too many prefixes", - MAX_PREFIXES, i.seg->seg_name); - return; - } - i.prefix[i.prefixes++] = i.seg->seg_prefix; - } - } - } - - /* Fill in i.rm.reg or i.rm.regmem field with register operand - (if any) based on t->extension_opcode. Again, we must be careful - to make sure that segment/control/debug/test registers are coded - into the i.rm.reg field. */ - if (i.reg_operands) { - uint o = - (i.types[0] & (Reg|SReg2|SReg3|Control|Debug|Test)) ? 0 : - (i.types[1] & (Reg|SReg2|SReg3|Control|Debug|Test)) ? 1 : 2; - /* If there is an extension opcode to put here, the register number - must be put into the regmem field. */ - if (t->extension_opcode != None) - i.rm.regmem = i.regs[o]->reg_num; - else i.rm.reg = i.regs[o]->reg_num; - - /* Now, if no memory operand has set i.rm.mode = 0, 1, 2 - we must set it to 3 to indicate this is a register operand - int the regmem field */ - if (! i.mem_operands) i.rm.mode = 3; - } - - /* Fill in i.rm.reg field with extension opcode (if any). */ - if (t->extension_opcode != None) - i.rm.reg = t->extension_opcode; - } - } - } - } - - /* Handle conversion of 'int $3' --> special int3 insn. */ - if (t->base_opcode == INT_OPCODE && i.imms[0]->X_add_number == 3) { - t->base_opcode = INT3_OPCODE; - i.imm_operands = 0; - } - - /* We are ready to output the insn. */ - { - register char * p; - - /* Output jumps. */ - if (t->opcode_modifier & Jump) { - int n = i.disps[0]->X_add_number; - - switch (i.disps[0]->X_seg) { - case SEG_ABSOLUTE: - if (FITS_IN_SIGNED_BYTE (n)) { - p = frag_more (2); - p[0] = t->base_opcode; - p[1] = n; -#if 0 /* leave out 16 bit jumps - pace */ - } else if (FITS_IN_SIGNED_WORD (n)) { - p = frag_more (4); - p[0] = WORD_PREFIX_OPCODE; - p[1] = t->base_opcode; - md_number_to_chars (&p[2], n, 2); -#endif - } else { /* It's an absolute dword displacement. */ - if (t->base_opcode == JUMP_PC_RELATIVE) { /* pace */ - /* unconditional jump */ - p = frag_more (5); - p[0] = 0xe9; - md_number_to_chars (&p[1], n, 4); - } else { - /* conditional jump */ - p = frag_more (6); - p[0] = TWO_BYTE_OPCODE_ESCAPE; - p[1] = t->base_opcode + 0x10; - md_number_to_chars (&p[2], n, 4); - } - } - break; - default: - /* It's a symbol; end frag & setup for relax. - Make sure there are 6 chars left in the current frag; if not - we'll have to start a new one. */ - /* I caught it failing with obstack_room == 6, - so I changed to <= pace */ - if (obstack_room (&frags) <= 6) { - frag_wane(frag_now); - frag_new (0); - } - p = frag_more (1); - p[0] = t->base_opcode; - frag_var (rs_machine_dependent, - 6, /* 2 opcode/prefix + 4 displacement */ - 1, - ((uchar) *p == JUMP_PC_RELATIVE - ? ENCODE_RELAX_STATE (UNCOND_JUMP, BYTE) - : ENCODE_RELAX_STATE (COND_JUMP, BYTE)), - i.disps[0]->X_add_symbol, - n, p); - break; - } - } else if (t->opcode_modifier & (JumpByte|JumpDword)) { - int size = (t->opcode_modifier & JumpByte) ? 1 : 4; - int n = i.disps[0]->X_add_number; - - if (FITS_IN_UNSIGNED_BYTE(t->base_opcode)) { - FRAG_APPEND_1_CHAR (t->base_opcode); - } else { - p = frag_more (2); /* opcode can be at most two bytes */ - /* put out high byte first: can't use md_number_to_chars! */ - *p++ = (t->base_opcode >> 8) & 0xff; - *p = t->base_opcode & 0xff; - } - - p = frag_more (size); - switch (i.disps[0]->X_seg) { - case SEG_ABSOLUTE: - md_number_to_chars (p, n, size); - if (size == 1 && ! FITS_IN_SIGNED_BYTE (n)) { - as_bad ("loop/jecx only takes byte displacement; %d shortened to %d", - n, *p); - } - break; - default: - fix_new (frag_now, p - frag_now->fr_literal, size, - i.disps[0]->X_add_symbol, i.disps[0]->X_subtract_symbol, - i.disps[0]->X_add_number, 1); - break; - } - } else if (t->opcode_modifier & JumpInterSegment) { - p = frag_more (1 + 2 + 4); /* 1 opcode; 2 segment; 4 offset */ - p[0] = t->base_opcode; - if (i.imms[1]->X_seg == SEG_ABSOLUTE) - md_number_to_chars (p + 1, i.imms[1]->X_add_number, 4); - else - fix_new (frag_now, p + 1 - frag_now->fr_literal, 4, - i.imms[1]->X_add_symbol, - i.imms[1]->X_subtract_symbol, - i.imms[1]->X_add_number, 0); - if (i.imms[0]->X_seg != SEG_ABSOLUTE) - as_bad ("can't handle non absolute segment in long call/jmp"); - md_number_to_chars (p + 5, i.imms[0]->X_add_number, 2); - } else { - /* Output normal instructions here. */ - register char *q; - - /* First the prefix bytes. */ - for (q = i.prefix; q < i.prefix + i.prefixes; q++) { - p = frag_more (1); - md_number_to_chars (p, (uint) *q, 1); - } - - /* Now the opcode; be careful about word order here! */ - if (FITS_IN_UNSIGNED_BYTE(t->base_opcode)) { - FRAG_APPEND_1_CHAR (t->base_opcode); - } else if (FITS_IN_UNSIGNED_WORD(t->base_opcode)) { - p = frag_more (2); - /* put out high byte first: can't use md_number_to_chars! */ - *p++ = (t->base_opcode >> 8) & 0xff; - *p = t->base_opcode & 0xff; - } else { /* opcode is either 3 or 4 bytes */ - if (t->base_opcode & 0xff000000) { - p = frag_more (4); - *p++ = (t->base_opcode >> 24) & 0xff; - } else p = frag_more (3); - *p++ = (t->base_opcode >> 16) & 0xff; - *p++ = (t->base_opcode >> 8) & 0xff; - *p = (t->base_opcode ) & 0xff; - } - - /* Now the modrm byte and base index byte (if present). */ - if (t->opcode_modifier & Modrm) { - p = frag_more (1); - /* md_number_to_chars (p, i.rm, 1); */ - md_number_to_chars (p, (i.rm.regmem<<0 | i.rm.reg<<3 | i.rm.mode<<6), 1); - /* If i.rm.regmem == ESP (4) && i.rm.mode != Mode 3 (Register mode) - ==> need second modrm byte. */ - if (i.rm.regmem == ESCAPE_TO_TWO_BYTE_ADDRESSING && i.rm.mode != 3) { - p = frag_more (1); - /* md_number_to_chars (p, i.bi, 1); */ - md_number_to_chars (p,(i.bi.base<<0 | i.bi.index<<3 | i.bi.scale<<6), 1); - } - } - - if (i.disp_operands) { - register int n; - - for (n = 0; n < i.operands; n++) { - if (i.disps[n]) { - if (i.disps[n]->X_seg == SEG_ABSOLUTE) { - if (i.types[n] & (Disp8|Abs8)) { - p = frag_more (1); - md_number_to_chars (p, i.disps[n]->X_add_number, 1); - } else if (i.types[n] & (Disp16|Abs16)) { - p = frag_more (2); - md_number_to_chars (p, i.disps[n]->X_add_number, 2); - } else { /* Disp32|Abs32 */ - p = frag_more (4); - md_number_to_chars (p, i.disps[n]->X_add_number, 4); - } - } else { /* not SEG_ABSOLUTE */ - /* need a 32-bit fixup (don't support 8bit non-absolute disps) */ - p = frag_more (4); - fix_new (frag_now, p - frag_now->fr_literal, 4, - i.disps[n]->X_add_symbol, i.disps[n]->X_subtract_symbol, - i.disps[n]->X_add_number, 0); - } - } - } - } /* end displacement output */ - - /* output immediate */ - if (i.imm_operands) { - register int n; - - for (n = 0; n < i.operands; n++) { - if (i.imms[n]) { - if (i.imms[n]->X_seg == SEG_ABSOLUTE) { - if (i.types[n] & (Imm8|Imm8S)) { - p = frag_more (1); - md_number_to_chars (p, i.imms[n]->X_add_number, 1); - } else if (i.types[n] & Imm16) { - p = frag_more (2); - md_number_to_chars (p, i.imms[n]->X_add_number, 2); - } else { - p = frag_more (4); - md_number_to_chars (p, i.imms[n]->X_add_number, 4); - } - } else { /* not SEG_ABSOLUTE */ - /* need a 32-bit fixup (don't support 8bit non-absolute ims) */ - /* try to support other sizes ... */ - int size; - if (i.types[n] & (Imm8|Imm8S)) - size = 1; - else if (i.types[n] & Imm16) - size = 2; - else - size = 4; - p = frag_more (size); - fix_new (frag_now, p - frag_now->fr_literal, size, - i.imms[n]->X_add_symbol, i.imms[n]->X_subtract_symbol, - i.imms[n]->X_add_number, 0); - } - } - } - } /* end immediate output */ - } - -#ifdef DEBUG386 - if (flagseen ['D']) { - pi (line, &i); - } -#endif /* DEBUG386 */ - - } - return; -} - -/* Parse OPERAND_STRING into the i386_insn structure I. Returns non-zero - on error. */ - -int i386_operand (operand_string) - char *operand_string; -{ - register char *op_string = operand_string; - - /* Address of '\0' at end of operand_string. */ - char * end_of_operand_string = operand_string + strlen(operand_string); - - /* Start and end of displacement string expression (if found). */ - char * displacement_string_start = 0; - char * displacement_string_end; - - /* We check for an absolute prefix (differentiating, - for example, 'jmp pc_relative_label' from 'jmp *absolute_label'. */ - if (*op_string == ABSOLUTE_PREFIX) { - op_string++; - i.types[this_operand] |= JumpAbsolute; - } - - /* Check if operand is a register. */ - if (*op_string == REGISTER_PREFIX) { - register reg_entry * r; - if (! (r = parse_register (op_string))) { - as_bad ("bad register name ('%s')", op_string); - return 0; - } - /* Check for segment override, rather than segment register by - searching for ':' after %s where = s, c, d, e, f, g. */ - if ((r->reg_type & (SReg2|SReg3)) && op_string[3] == ':') { - switch (r->reg_num) { - case 0: - i.seg = &es; break; - case 1: - i.seg = &cs; break; - case 2: - i.seg = &ss; break; - case 3: - i.seg = &ds; break; - case 4: - i.seg = &fs; break; - case 5: - i.seg = &gs; break; - } - op_string += 4; /* skip % s : */ - operand_string = op_string; /* Pretend given string starts here. */ - if (!is_digit_char(*op_string) && !is_identifier_char(*op_string) - && *op_string != '(' && *op_string != ABSOLUTE_PREFIX) { - as_bad ("bad memory operand after segment override"); - return 0; - } - /* Handle case of %es:*foo. */ - if (*op_string == ABSOLUTE_PREFIX) { - op_string++; - i.types[this_operand] |= JumpAbsolute; - } - goto do_memory_reference; - } - i.types[this_operand] |= r->reg_type; - i.regs[this_operand] = r; - i.reg_operands++; - } else if (*op_string == IMMEDIATE_PREFIX) { /* ... or an immediate */ - char * save_input_line_pointer; - register expressionS *exp; - segT exp_seg; - if (i.imm_operands == MAX_IMMEDIATE_OPERANDS) { - as_bad ("only 1 or 2 immediate operands are allowed"); - return 0; - } - exp = &im_expressions[i.imm_operands++]; - i.imms [this_operand] = exp; - save_input_line_pointer = input_line_pointer; - input_line_pointer = ++op_string; /* must advance op_string! */ - exp_seg = expression (exp); - input_line_pointer = save_input_line_pointer; - switch (exp_seg) { - case SEG_NONE: /* missing or bad expr becomes absolute 0 */ - as_bad ("missing or invalid immediate expression '%s' taken as 0", - operand_string); - exp->X_seg = SEG_ABSOLUTE; - exp->X_add_number = 0; - exp->X_add_symbol = (symbolS *) 0; - exp->X_subtract_symbol = (symbolS *) 0; - i.types[this_operand] |= Imm; - break; - case SEG_ABSOLUTE: - i.types[this_operand] |= SMALLEST_IMM_TYPE (exp->X_add_number); - break; - case SEG_TEXT: case SEG_DATA: case SEG_BSS: case SEG_UNKNOWN: - i.types[this_operand] |= Imm32; /* this is an address ==> 32bit */ - break; - default: -seg_unimplemented: - as_bad ("Unimplemented segment type %d in parse_operand", exp_seg); - return 0; - } - /* shorten this type of this operand if the instruction wants - * fewer bits than are present in the immediate. The bit field - * code can put out 'andb $0xffffff, %al', for example. pace - * also 'movw $foo,(%eax)' - */ - switch (i.suffix) { - case WORD_OPCODE_SUFFIX: - i.types[this_operand] |= Imm16; - break; - case BYTE_OPCODE_SUFFIX: - i.types[this_operand] |= Imm16 | Imm8 | Imm8S; - break; - } - } else if (is_digit_char(*op_string) || is_identifier_char(*op_string) - || *op_string == '(') { - /* This is a memory reference of some sort. */ - register char * base_string; - uint found_base_index_form; - - do_memory_reference: - if (i.mem_operands == MAX_MEMORY_OPERANDS) { - as_bad ("more than 1 memory reference in instruction"); - return 0; - } - i.mem_operands++; - - /* Determine type of memory operand from opcode_suffix; - no opcode suffix implies general memory references. */ - switch (i.suffix) { - case BYTE_OPCODE_SUFFIX: - i.types[this_operand] |= Mem8; - break; - case WORD_OPCODE_SUFFIX: - i.types[this_operand] |= Mem16; - break; - case DWORD_OPCODE_SUFFIX: - default: - i.types[this_operand] |= Mem32; - } - - /* Check for base index form. We detect the base index form by - looking for an ')' at the end of the operand, searching - for the '(' matching it, and finding a REGISTER_PREFIX or ',' - after it. */ - base_string = end_of_operand_string - 1; - found_base_index_form = FALSE; - if (*base_string == ')') { - uint parens_balenced = 1; - /* We've already checked that the number of left & right ()'s are equal, - so this loop will not be infinite. */ - do { - base_string--; - if (*base_string == ')') parens_balenced++; - if (*base_string == '(') parens_balenced--; - } while (parens_balenced); - base_string++; /* Skip past '('. */ - if (*base_string == REGISTER_PREFIX || *base_string == ',') - found_base_index_form = TRUE; - } - - /* If we can't parse a base index register expression, we've found - a pure displacement expression. We set up displacement_string_start - and displacement_string_end for the code below. */ - if (! found_base_index_form) { - displacement_string_start = op_string; - displacement_string_end = end_of_operand_string; - } else { - char *base_reg_name, *index_reg_name, *num_string; - int num; - - i.types[this_operand] |= BaseIndex; - - /* If there is a displacement set-up for it to be parsed later. */ - if (base_string != op_string + 1) { - displacement_string_start = op_string; - displacement_string_end = base_string - 1; - } - - /* Find base register (if any). */ - if (*base_string != ',') { - base_reg_name = base_string++; - /* skip past register name & parse it */ - while (isalpha(*base_string)) base_string++; - if (base_string == base_reg_name+1) { - as_bad ("can't find base register name after '(%c'", - REGISTER_PREFIX); - return 0; - } - END_STRING_AND_SAVE (base_string); - if (! (i.base_reg = parse_register (base_reg_name))) { - as_bad ("bad base register name ('%s')", base_reg_name); - return 0; - } - RESTORE_END_STRING (base_string); - } - - /* Now check seperator; must be ',' ==> index reg - OR num ==> no index reg. just scale factor - OR ')' ==> end. (scale factor = 1) */ - if (*base_string != ',' && *base_string != ')') { - as_bad ("expecting ',' or ')' after base register in `%s'", - operand_string); - return 0; - } - - /* There may index reg here; and there may be a scale factor. */ - if (*base_string == ',' && *(base_string+1) == REGISTER_PREFIX) { - index_reg_name = ++base_string; - while (isalpha(*++base_string)); - END_STRING_AND_SAVE (base_string); - if (! (i.index_reg = parse_register(index_reg_name))) { - as_bad ("bad index register name ('%s')", index_reg_name); - return 0; - } - RESTORE_END_STRING (base_string); - } - - /* Check for scale factor. */ - if (*base_string == ',' && isdigit(*(base_string+1))) { - num_string = ++base_string; - while (is_digit_char(*base_string)) base_string++; - if (base_string == num_string) { - as_bad ("can't find a scale factor after ','"); - return 0; - } - END_STRING_AND_SAVE (base_string); - /* We've got a scale factor. */ - if (! sscanf (num_string, "%d", &num)) { - as_bad ("can't parse scale factor from '%s'", num_string); - return 0; - } - RESTORE_END_STRING (base_string); - switch (num) { /* must be 1 digit scale */ - case 1: i.log2_scale_factor = 0; break; - case 2: i.log2_scale_factor = 1; break; - case 4: i.log2_scale_factor = 2; break; - case 8: i.log2_scale_factor = 3; break; - default: - as_bad ("expecting scale factor of 1, 2, 4, 8; got %d", num); - return 0; - } - } else { - if (! i.index_reg && *base_string == ',') { - as_bad ("expecting index register or scale factor after ','; got '%c'", - *(base_string+1)); - return 0; - } - } - } - - /* If there's an expression begining the operand, parse it, - assuming displacement_string_start and displacement_string_end - are meaningful. */ - if (displacement_string_start) { - register expressionS * exp; - segT exp_seg; - char * save_input_line_pointer; - exp = &disp_expressions[i.disp_operands]; - i.disps [this_operand] = exp; - i.disp_operands++; - save_input_line_pointer = input_line_pointer; - input_line_pointer = displacement_string_start; - END_STRING_AND_SAVE (displacement_string_end); - exp_seg = expression (exp); - if(*input_line_pointer) - as_bad("Ignoring junk '%s' after expression",input_line_pointer); - RESTORE_END_STRING (displacement_string_end); - input_line_pointer = save_input_line_pointer; - switch (exp_seg) { - case SEG_NONE: - /* missing expr becomes absolute 0 */ - as_bad ("missing or invalid displacement '%s' taken as 0", - operand_string); - i.types[this_operand] |= (Disp|Abs); - exp->X_seg = SEG_ABSOLUTE; - exp->X_add_number = 0; - exp->X_add_symbol = (symbolS *) 0; - exp->X_subtract_symbol = (symbolS *) 0; - break; - case SEG_ABSOLUTE: - i.types[this_operand] |= SMALLEST_DISP_TYPE (exp->X_add_number); - break; - case SEG_TEXT: case SEG_DATA: case SEG_BSS: - case SEG_UNKNOWN: /* must be 32 bit displacement (i.e. address) */ - i.types[this_operand] |= Disp32; - break; - default: - goto seg_unimplemented; - } - } - - /* Make sure the memory operand we've been dealt is valid. */ - if (i.base_reg && i.index_reg && - ! (i.base_reg->reg_type & i.index_reg->reg_type & Reg)) { - as_bad ("register size mismatch in (base,index,scale) expression"); - return 0; - } - if ((i.base_reg && (i.base_reg->reg_type & Reg32) == 0) || - (i.index_reg && (i.index_reg->reg_type & Reg32) == 0)) { - as_bad ("base/index register must be 32 bit register"); - return 0; - } - if (i.index_reg && i.index_reg == esp) { - as_bad ("%s may not be used as an index register", esp->reg_name); - return 0; - } - } else { /* it's not a memory operand; argh! */ - as_bad ("invalid char %s begining %s operand '%s'", - output_invalid(*op_string), ordinal_names[this_operand], - op_string); - return 0; - } - return 1; /* normal return */ -} - -/* - * md_estimate_size_before_relax() - * - * Called just before relax(). - * Any symbol that is now undefined will not become defined. - * Return the correct fr_subtype in the frag. - * Return the initial "guess for fr_var" to caller. - * The guess for fr_var is ACTUALLY the growth beyond fr_fix. - * Whatever we do to grow fr_fix or fr_var contributes to our returned value. - * Although it may not be explicit in the frag, pretend fr_var starts with a - * 0 value. - */ -int -md_estimate_size_before_relax (fragP, segment_type) - register fragS * fragP; - register int segment_type; /* N_DATA or N_TEXT. */ -{ - register uchar * opcode; - register int old_fr_fix; - - old_fr_fix = fragP -> fr_fix; - opcode = (uchar *) fragP -> fr_opcode; - /* We've already got fragP->fr_subtype right; all we have to do is check - for un-relaxable symbols. */ - if ((fragP -> fr_symbol -> sy_type & N_TYPE) != segment_type) { - /* symbol is undefined in this segment */ - switch (opcode[0]) { - case JUMP_PC_RELATIVE: /* make jmp (0xeb) a dword displacement jump */ - opcode[0] = 0xe9; /* dword disp jmp */ - fragP -> fr_fix += 4; - fix_new (fragP, old_fr_fix, 4, - fragP -> fr_symbol, - (symbolS *) 0, - fragP -> fr_offset, 1); - break; - - default: - /* This changes the byte-displacement jump 0x7N --> - the dword-displacement jump 0x0f8N */ - opcode[1] = opcode[0] + 0x10; - opcode[0] = TWO_BYTE_OPCODE_ESCAPE; /* two-byte escape */ - fragP -> fr_fix += 1 + 4; /* we've added an opcode byte */ - fix_new (fragP, old_fr_fix + 1, 4, - fragP -> fr_symbol, - (symbolS *) 0, - fragP -> fr_offset, 1); - break; - } - frag_wane (fragP); - } - return (fragP -> fr_var + fragP -> fr_fix - old_fr_fix); -} /* md_estimate_size_before_relax() */ - -/* - * md_convert_frag(); - * - * Called after relax() is finished. - * In: Address of frag. - * fr_type == rs_machine_dependent. - * fr_subtype is what the address relaxed to. - * - * Out: Any fixSs and constants are set up. - * Caller will turn frag into a ".space 0". - */ -void -md_convert_frag (fragP) - register fragS * fragP; -{ - register uchar * opcode; - uchar * where_to_put_displacement; - uint target_address, opcode_address; - uint extension; - int displacement_from_opcode_start; - - opcode = (uchar *) fragP -> fr_opcode; - - /* Address we want to reach in file space. */ - target_address = fragP->fr_symbol->sy_value + fragP->fr_offset; - - /* Address opcode resides at in file space. */ - opcode_address = fragP->fr_address + fragP->fr_fix; - - /* Displacement from opcode start to fill into instruction. */ - displacement_from_opcode_start = target_address - opcode_address; - - switch (fragP->fr_subtype) { - case ENCODE_RELAX_STATE (COND_JUMP, BYTE): - case ENCODE_RELAX_STATE (UNCOND_JUMP, BYTE): - /* don't have to change opcode */ - extension = 1; /* 1 opcode + 1 displacement */ - where_to_put_displacement = &opcode[1]; - break; - - case ENCODE_RELAX_STATE (COND_JUMP, WORD): - opcode[1] = TWO_BYTE_OPCODE_ESCAPE; - opcode[2] = opcode[0] + 0x10; - opcode[0] = WORD_PREFIX_OPCODE; - extension = 4; /* 3 opcode + 2 displacement */ - where_to_put_displacement = &opcode[3]; - break; - - case ENCODE_RELAX_STATE (UNCOND_JUMP, WORD): - opcode[1] = 0xe9; - opcode[0] = WORD_PREFIX_OPCODE; - extension = 3; /* 2 opcode + 2 displacement */ - where_to_put_displacement = &opcode[2]; - break; - - case ENCODE_RELAX_STATE (COND_JUMP, DWORD): - opcode[1] = opcode[0] + 0x10; - opcode[0] = TWO_BYTE_OPCODE_ESCAPE; - extension = 5; /* 2 opcode + 4 displacement */ - where_to_put_displacement = &opcode[2]; - break; - - case ENCODE_RELAX_STATE (UNCOND_JUMP, DWORD): - opcode[0] = 0xe9; - extension = 4; /* 1 opcode + 4 displacement */ - where_to_put_displacement = &opcode[1]; - break; - - default: - BAD_CASE(fragP -> fr_subtype); - break; - } - /* now put displacement after opcode */ - md_number_to_chars (where_to_put_displacement, - displacement_from_opcode_start - extension, - SIZE_FROM_RELAX_STATE (fragP->fr_subtype)); - fragP -> fr_fix += extension; -} - - -int md_short_jump_size = 2; /* size of byte displacement jmp */ -int md_long_jump_size = 5; /* size of dword displacement jmp */ - -void md_create_short_jump(ptr, from_addr, to_addr) - char *ptr; - long from_addr, to_addr; -{ - long offset; - - offset = to_addr - (from_addr + 2); - md_number_to_chars (ptr, (long) 0xeb, 1); /* opcode for byte-disp jump */ - md_number_to_chars (ptr + 1, offset, 1); -} - -void md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol) - char *ptr; - long from_addr, to_addr; - fragS *frag; - symbolS *to_symbol; -{ - long offset; - - if (flagseen['m']) { - offset = to_addr - to_symbol->sy_value; - md_number_to_chars (ptr, 0xe9, 1); /* opcode for long jmp */ - md_number_to_chars (ptr + 1, offset, 4); - fix_new (frag, (ptr+1) - frag->fr_literal, 4, - to_symbol, (symbolS *) 0, (long int) 0, 0); - } else { - offset = to_addr - (from_addr + 5); - md_number_to_chars(ptr, (long) 0xe9, 1); - md_number_to_chars(ptr + 1, offset, 4); - } -} - -int -md_parse_option(argP,cntP,vecP) -char **argP; -int *cntP; -char ***vecP; -{ - return 1; -} - -void /* Knows about order of bytes in address. */ -md_number_to_chars (con, value, nbytes) - char con []; /* Return 'nbytes' of chars here. */ - long int value; /* The value of the bits. */ - int nbytes; /* Number of bytes in the output. */ -{ - register char * p = con; - - switch (nbytes) { - case 1: - p[0] = value & 0xff; - break; - case 2: - p[0] = value & 0xff; - p[1] = (value >> 8) & 0xff; - break; - case 4: - p[0] = value & 0xff; - p[1] = (value>>8) & 0xff; - p[2] = (value>>16) & 0xff; - p[3] = (value>>24) & 0xff; - break; - default: - BAD_CASE (nbytes); - } -} - -void /* Knows about order of bytes in address. */ -md_number_to_disp (con, value, nbytes) - char con []; /* Return 'nbytes' of chars here. */ - long int value; /* The value of the bits. */ - int nbytes; /* Number of bytes in the output. */ -{ - char * answer = alloca (nbytes); - register char * p = answer; - - switch (nbytes) { - case 1: - *p = value; - break; - case 2: - *p++ = value; - *p = (value>>8); - break; - case 4: - *p++ = value; - *p++ = (value>>8); - *p++ = (value>>16); - *p = (value>>24); - break; - default: - BAD_CASE (nbytes); - } - bcopy (answer, con, nbytes); -} - -void /* Knows about order of bytes in address. */ -md_number_to_imm (con, value, nbytes) - char con []; /* Return 'nbytes' of chars here. */ - long int value; /* The value of the bits. */ - int nbytes; /* Number of bytes in the output. */ -{ - char * answer = alloca (nbytes); - register char * p = answer; - - switch (nbytes) { - case 1: - *p = value; - break; - case 2: - *p++ = value; - *p = (value>>8); - break; - case 4: - *p++ = value; - *p++ = (value>>8); - *p++ = (value>>16); - *p = (value>>24); - break; - default: - BAD_CASE (nbytes); - } - bcopy (answer, con, nbytes); -} - -void /* Knows about order of bytes in address. */ -md_number_to_field (con, value, nbytes) - char con []; /* Return 'nbytes' of chars here. */ - long int value; /* The value of the bits. */ - int nbytes; /* Number of bytes in the output. */ -{ - char * answer = alloca (nbytes); - register char * p = answer; - - switch (nbytes) { - case 1: - *p = value; - break; - case 2: - *p++ = value; - *p = (value>>8); - break; - case 4: - *p++ = value; - *p++ = (value>>8); - *p++ = (value>>16); - *p = (value>>24); - break; - default: - BAD_CASE (nbytes); - } - bcopy (answer, con, nbytes); -} - -long int /* Knows about the byte order in a word. */ -md_chars_to_number (con, nbytes) -unsigned char con[]; /* Low order byte 1st. */ - int nbytes; /* Number of bytes in the input. */ -{ - long int retval; - for (retval=0, con+=nbytes-1; nbytes--; con--) - { - retval <<= BITS_PER_CHAR; - retval |= *con; - } - return retval; -} - -void md_ri_to_chars(ri_p, ri) - struct relocation_info *ri_p, ri; -{ - unsigned char the_bytes[8]; - - /* this is easy */ - md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address)); - /* now the fun stuff */ - the_bytes[6] = (ri.r_symbolnum >> 16) & 0x0ff; - the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff; - the_bytes[4] = ri.r_symbolnum & 0x0ff; - the_bytes[7] = (((ri.r_extern << 3) & 0x08) | ((ri.r_length << 1) & 0x06) | - ((ri.r_pcrel << 0) & 0x01)) & 0x0F; - /* now put it back where you found it */ - bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info)); -} - - -#define MAX_LITTLENUMS 6 - -/* Turn the string pointed to by litP into a floating point constant of type - type, and emit the appropriate bytes. The number of LITTLENUMS emitted - is stored in *sizeP . An error message is returned, or NULL on OK. - */ -char * -md_atof(type,litP,sizeP) - char type; - char *litP; - int *sizeP; -{ - int prec; - LITTLENUM_TYPE words[MAX_LITTLENUMS]; - LITTLENUM_TYPE *wordP; - char *t; - char *atof_ieee(); - - switch(type) { - case 'f': - case 'F': - prec = 2; - break; - - case 'd': - case 'D': - prec = 4; - break; - - case 'x': - case 'X': - prec = 5; - break; - - default: - *sizeP=0; - return "Bad call to md_atof ()"; - } - t = atof_ieee (input_line_pointer,type,words); - if(t) - input_line_pointer=t; - - *sizeP = prec * sizeof(LITTLENUM_TYPE); - /* this loops outputs the LITTLENUMs in REVERSE order; in accord with - the bigendian 386 */ - for(wordP = words + prec - 1;prec--;) { - md_number_to_chars (litP, (long) (*wordP--), sizeof(LITTLENUM_TYPE)); - litP += sizeof(LITTLENUM_TYPE); - } - return ""; /* Someone should teach Dean about null pointers */ -} - -char output_invalid_buf[8]; - -char * output_invalid (c) - char c; -{ - if (isprint(c)) sprintf (output_invalid_buf, "'%c'", c); - else sprintf (output_invalid_buf, "(0x%x)", c); - return output_invalid_buf; -} - -reg_entry *parse_register (reg_string) - char *reg_string; /* reg_string starts *before* REGISTER_PREFIX */ -{ - register char *s = reg_string; - register char *p; - char reg_name_given[MAX_REG_NAME_SIZE]; - - s++; /* skip REGISTER_PREFIX */ - for (p = reg_name_given; is_register_char (*s); p++, s++) { - *p = register_chars [*s]; - if (p >= reg_name_given + MAX_REG_NAME_SIZE) - return (reg_entry *) 0; - } - *p = '\0'; - return (reg_entry *) hash_find (reg_hash, reg_name_given); -} - diff --git a/gnu/usr.bin/as/config/i386.h b/gnu/usr.bin/as/config/i386.h deleted file mode 100644 index c569c1c..0000000 --- a/gnu/usr.bin/as/config/i386.h +++ /dev/null @@ -1,296 +0,0 @@ -/* i386.h -- Header file for i386.c - Copyright (C) 1989, Free Software Foundation. - -This file is part of GAS, the GNU Assembler. - -GAS 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 1, or (at your option) -any later version. - -GAS 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 GAS; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#define MAX_OPERANDS 3 /* max operands per insn */ -#define MAX_PREFIXES 4 /* max prefixes per opcode */ -#define MAX_IMMEDIATE_OPERANDS 2 /* max immediates per insn */ -#define MAX_MEMORY_OPERANDS 2 /* max memory ref per insn - * lcall uses 2 - */ -/* we define the syntax here (modulo base,index,scale syntax) */ -#define REGISTER_PREFIX '%' -#define IMMEDIATE_PREFIX '$' -#define ABSOLUTE_PREFIX '*' -#define PREFIX_SEPERATOR '/' - -#define TWO_BYTE_OPCODE_ESCAPE 0x0f - -/* register numbers */ -#define EBP_REG_NUM 5 -#define ESP_REG_NUM 4 - -/* modrm_byte.regmem for twobyte escape */ -#define ESCAPE_TO_TWO_BYTE_ADDRESSING ESP_REG_NUM -/* index_base_byte.index for no index register addressing */ -#define NO_INDEX_REGISTER ESP_REG_NUM -/* index_base_byte.base for no base register addressing */ -#define NO_BASE_REGISTER EBP_REG_NUM - -/* these are the att as opcode suffixes, making movl --> mov, for example */ -#define DWORD_OPCODE_SUFFIX 'l' -#define WORD_OPCODE_SUFFIX 'w' -#define BYTE_OPCODE_SUFFIX 'b' - -/* modrm.mode = REGMEM_FIELD_HAS_REG when a register is in there */ -#define REGMEM_FIELD_HAS_REG 0x3 /* always = 0x3 */ -#define REGMEM_FIELD_HAS_MEM (~REGMEM_FIELD_HAS_REG) - -#define END_OF_INSN '\0' - -/* -When an operand is read in it is classified by its type. This type includes -all the possible ways an operand can be used. Thus, '%eax' is both 'register -# 0' and 'The Accumulator'. In our language this is expressed by OR'ing -'Reg32' (any 32 bit register) and 'Acc' (the accumulator). -Operands are classified so that we can match given operand types with -the opcode table in i386-opcode.h. - */ -#define Unknown 0x0 -/* register */ -#define Reg8 0x1 /* 8 bit reg */ -#define Reg16 0x2 /* 16 bit reg */ -#define Reg32 0x4 /* 32 bit reg */ -#define Reg (Reg8|Reg16|Reg32) /* gen'l register */ -#define WordReg (Reg16|Reg32) /* for push/pop operands */ -/* immediate */ -#define Imm8 0x8 /* 8 bit immediate */ -#define Imm8S 0x10 /* 8 bit immediate sign extended */ -#define Imm16 0x20 /* 16 bit immediate */ -#define Imm32 0x40 /* 32 bit immediate */ -#define Imm1 0x80 /* 1 bit immediate */ -#define ImmUnknown Imm32 /* for unknown expressions */ -#define Imm (Imm8|Imm8S|Imm16|Imm32) /* gen'l immediate */ -/* memory */ -#define Disp8 0x200 /* 8 bit displacement (for jumps) */ -#define Disp16 0x400 /* 16 bit displacement */ -#define Disp32 0x800 /* 32 bit displacement */ -#define Disp (Disp8|Disp16|Disp32) /* General displacement */ -#define DispUnknown Disp32 /* for unknown size displacements */ -#define Mem8 0x1000 -#define Mem16 0x2000 -#define Mem32 0x4000 -#define BaseIndex 0x8000 -#define Mem (Disp|Mem8|Mem16|Mem32|BaseIndex) /* General memory */ -#define WordMem (Mem16|Mem32|Disp|BaseIndex) -#define ByteMem (Mem8|Disp|BaseIndex) -/* specials */ -#define InOutPortReg 0x10000 /* register to hold in/out port addr = dx */ -#define ShiftCount 0x20000 /* register to hold shift cound = cl */ -#define Control 0x40000 /* Control register */ -#define Debug 0x80000 /* Debug register */ -#define Test 0x100000 /* Test register */ -#define FloatReg 0x200000 /* Float register */ -#define FloatAcc 0x400000 /* Float stack top %st(0) */ -#define SReg2 0x800000 /* 2 bit segment register */ -#define SReg3 0x1000000 /* 3 bit segment register */ -#define Acc 0x2000000 /* Accumulator %al or %ax or %eax */ -#define ImplicitRegister (InOutPortReg|ShiftCount|Acc|FloatAcc) -#define JumpAbsolute 0x4000000 -#define Abs8 0x08000000 -#define Abs16 0x10000000 -#define Abs32 0x20000000 -#define Abs (Abs8|Abs16|Abs32) - -#define MODE_FROM_DISP_SIZE(t) \ - ((t&(Disp8)) ? 1 : \ - ((t&(Disp32)) ? 2 : 0)) - -#define Byte (Reg8|Imm8|Imm8S) -#define Word (Reg16|Imm16) -#define DWord (Reg32|Imm32) - -/* convert opcode suffix ('b' 'w' 'l' typically) into type specifyer */ -#define OPCODE_SUFFIX_TO_TYPE(s) \ - (s == BYTE_OPCODE_SUFFIX ? Byte : \ - (s == WORD_OPCODE_SUFFIX ? Word : DWord)) - -#define FITS_IN_SIGNED_BYTE(num) ((num) >= -128 && (num) <= 127) -#define FITS_IN_UNSIGNED_BYTE(num) ((num) >= 0 && (num) <= 255) -#define FITS_IN_UNSIGNED_WORD(num) ((num) >= 0 && (num) <= 65535) -#define FITS_IN_SIGNED_WORD(num) ((num) >= -32768 && (num) <= 32767) - -#define SMALLEST_DISP_TYPE(num) \ - FITS_IN_SIGNED_BYTE(num) ? (Disp8|Disp32|Abs8|Abs32) : (Disp32|Abs32) - -#define SMALLEST_IMM_TYPE(num) \ - (num == 1) ? (Imm1|Imm8|Imm8S|Imm16|Imm32): \ - FITS_IN_SIGNED_BYTE(num) ? (Imm8S|Imm8|Imm16|Imm32) : \ - FITS_IN_UNSIGNED_BYTE(num) ? (Imm8|Imm16|Imm32): \ - (FITS_IN_SIGNED_WORD(num)||FITS_IN_UNSIGNED_WORD(num)) ? (Imm16|Imm32) : \ - (Imm32) - -typedef unsigned char uchar; -typedef unsigned int uint; - -typedef struct { - /* instruction name sans width suffix ("mov" for movl insns) */ - char *name; - - /* how many operands */ - uint operands; - - /* base_opcode is the fundamental opcode byte with a optional prefix(es). */ - uint base_opcode; - - /* extension_opcode is the 3 bit extension for group insns. - If this template has no extension opcode (the usual case) use None */ - uchar extension_opcode; -#define None 0xff /* If no extension_opcode is possible. */ - - /* the bits in opcode_modifier are used to generate the final opcode from - the base_opcode. These bits also are used to detect alternate forms of - the same instruction */ - uint opcode_modifier; - -/* opcode_modifier bits: */ -#define W 0x1 /* set if operands are words or dwords */ -#define D 0x2 /* D = 0 if Reg --> Regmem; D = 1 if Regmem --> Reg */ -/* direction flag for floating insns: MUST BE 0x400 */ -#define FloatD 0x400 -/* shorthand */ -#define DW (D|W) -#define ShortForm 0x10 /* register is in low 3 bits of opcode */ -#define ShortFormW 0x20 /* ShortForm and W bit is 0x8 */ -#define Seg2ShortForm 0x40 /* encoding of load segment reg insns */ -#define Seg3ShortForm 0x80 /* fs/gs segment register insns. */ -#define Jump 0x100 /* special case for jump insns. */ -#define JumpInterSegment 0x200 /* special case for intersegment leaps/calls */ -/* 0x400 CANNOT BE USED since it's already used by FloatD above */ -#define DONT_USE 0x400 -#define NoModrm 0x800 -#define Modrm 0x1000 -#define imulKludge 0x2000 -#define JumpByte 0x4000 -#define JumpDword 0x8000 -#define ReverseRegRegmem 0x10000 - - /* (opcode_modifier & COMES_IN_ALL_SIZES) is true if the - instuction comes in byte, word, and dword sizes and is encoded into - machine code in the canonical way. */ -#define COMES_IN_ALL_SIZES (W) - - /* (opcode_modifier & COMES_IN_BOTH_DIRECTIONS) indicates that the - source and destination operands can be reversed by setting either - the D (for integer insns) or the FloatD (for floating insns) bit - in base_opcode. */ -#define COMES_IN_BOTH_DIRECTIONS (D|FloatD) - - /* operand_types[i] describes the type of operand i. This is made - by OR'ing together all of the possible type masks. (e.g. - 'operand_types[i] = Reg|Imm' specifies that operand i can be - either a register or an immediate operand */ - uint operand_types[3]; -} template; - -/* - 'templates' is for grouping together 'template' structures for opcodes - of the same name. This is only used for storing the insns in the grand - ole hash table of insns. - The templates themselves start at START and range up to (but not including) - END. -*/ -typedef struct { - template *start; - template *end; -} templates; - -/* these are for register name --> number & type hash lookup */ -typedef struct { - char * reg_name; - uint reg_type; - uint reg_num; -} reg_entry; - -typedef struct { - char * seg_name; - uint seg_prefix; -} seg_entry; - -/* these are for prefix name --> prefix code hash lookup */ -typedef struct { - char * prefix_name; - uchar prefix_code; -} prefix_entry; - -/* 386 operand encoding bytes: see 386 book for details of this. */ -typedef struct { - unsigned regmem:3; /* codes register or memory operand */ - unsigned reg:3; /* codes register operand (or extended opcode) */ - unsigned mode:2; /* how to interpret regmem & reg */ -} modrm_byte; - -/* 386 opcode byte to code indirect addressing. */ -typedef struct { - unsigned base:3; - unsigned index:3; - unsigned scale:2; -} base_index_byte; - -/* 'md_assemble ()' gathers together information and puts it into a - i386_insn. */ - -typedef struct { - /* TM holds the template for the insn were currently assembling. */ - template tm; - /* SUFFIX holds the opcode suffix (e.g. 'l' for 'movl') if given. */ - char suffix; - /* Operands are coded with OPERANDS, TYPES, DISPS, IMMS, and REGS. */ - - /* OPERANDS gives the number of given operands. */ - uint operands; - - /* REG_OPERANDS, DISP_OPERANDS, MEM_OPERANDS, IMM_OPERANDS give the number of - given register, displacement, memory operands and immediate operands. */ - uint reg_operands, disp_operands, mem_operands, imm_operands; - - /* TYPES [i] is the type (see above #defines) which tells us how to - search through DISPS [i] & IMMS [i] & REGS [i] for the required - operand. */ - uint types [MAX_OPERANDS]; - - /* Displacements (if given) for each operand. */ - expressionS * disps [MAX_OPERANDS]; - - /* Immediate operands (if given) for each operand. */ - expressionS * imms [MAX_OPERANDS]; - - /* Register operands (if given) for each operand. */ - reg_entry * regs [MAX_OPERANDS]; - - /* BASE_REG, INDEX_REG, and LOG2_SCALE_FACTOR are used to encode - the base index byte below. */ - reg_entry * base_reg; - reg_entry * index_reg; - uint log2_scale_factor; - - /* SEG gives the seg_entry of this insn. It is equal to zero unless - an explicit segment override is given. */ - seg_entry * seg; /* segment for memory operands (if given) */ - - /* PREFIX holds all the given prefix opcodes (usually null). - PREFIXES is the size of PREFIX. */ - char prefix [MAX_PREFIXES]; - uint prefixes; - - /* RM and IB are the modrm byte and the base index byte where the addressing - modes of this insn are encoded. */ - - modrm_byte rm; - base_index_byte bi; -} i386_insn; diff --git a/gnu/usr.bin/as/doc/Makefile.in b/gnu/usr.bin/as/doc/Makefile.in deleted file mode 100644 index fdae0b2..0000000 --- a/gnu/usr.bin/as/doc/Makefile.in +++ /dev/null @@ -1,172 +0,0 @@ -# Makefile for GNU Assembler documentation -# - see pretex.m4 for discussion of preprocessor definitions -# Copyright (C) 1987-1992 Free Software Foundation, Inc. - -#This file is part of GNU GAS. - -#GNU GAS 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. - -#GNU GAS 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 GNU GAS; see the file COPYING. If not, write to -#the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - -# The targets for external use include: -# all, doc, proto, install, uninstall, includes, TAGS, -# clean, cleanconfig, realclean, stage1, stage2, stage3, stage4. - -# Variables that exist for you to override. -# See below for how to change them for certain systems. - -srcdir = . - -prefix = /usr/local - -bindir = $(prefix)/bin -datadir = $(prefix)/lib -libdir = $(prefix)/lib -mandir = $(datadir)/man -man1dir = $(mandir)/man1 -man2dir = $(mandir)/man2 -man3dir = $(mandir)/man3 -man4dir = $(mandir)/man4 -man5dir = $(mandir)/man5 -man6dir = $(mandir)/man6 -man7dir = $(mandir)/man7 -man8dir = $(mandir)/man8 -man9dir = $(mandir)/man9 -infodir = $(datadir)/info -includedir = $(prefix)/include -docdir = $(datadir)/doc - -SHELL = /bin/sh - -INSTALL = install -c -INSTALL_PROGRAM = $(INSTALL) -INSTALL_DATA = $(INSTALL) - -AR = ar -AR_FLAGS = qv -BISON = bison -MAKEINFO = makeinfo -RANLIB = ranlib - -# What version of the manual you want (see *.m4); "all" includes everything -CONFIG=all - -# Sun/Berkeley m4 doesn't have all the things we need; use GNU or sV -M4=gm4 -#M4=/usr/5bin/m4 - -# Directory for gas source -srcdir=.. - -# Where to find texinfo.tex to format docn with TeX -TEXIDIR = $(srcdir)/../texinfo/fsf - -#### host, target, and site specific Makefile frags come in here. -## - -all: -clean: -install: - $(INSTALL_DATA) $(srcdir)/as.1 $(man1dir)/as.1 - -info: as.info - -as.info: as-${CONFIG}.texinfo - makeinfo -o as.info as-${CONFIG}.texinfo - -install-info: as.info - [ -d $(infodir) ] || mkdir $(infodir) - for i in as.info* ; do \ - $(INSTALL_DATA) $$i $(infodir)/$$i ; \ - done - -as.dvi: as-${CONFIG}.texinfo - TEXINPUTS=${TEXIDIR}:.:$$TEXINPUTS tex as-${CONFIG}.texinfo - texindex as-${CONFIG}.?? - TEXINPUTS=${TEXIDIR}:.:$$TEXINPUTS tex as-${CONFIG}.texinfo - mv as-${CONFIG}.dvi as.dvi - rm as-${CONFIG}.?? as-${CONFIG}.??? - -# ROFF doc targets as.ms, as.mm, as.me -# (we don't use a variable because we don't trust all makes to handle -# a var in the target name right). -# roff output (-ms) -as.ms: as-${CONFIG}.texinfo - sed -e '/\\input texinfo/d' \ - -e '/@c TEXI2ROFF-KILL/,/@c END TEXI2ROFF-KILL/d' \ - -e 's/{.*,,/{/' \ - as-${CONFIG}.texinfo | \ - texi2roff -ms >as.ms - -# roff output (-mm) -as.mm: as-${CONFIG}.texinfo - sed -e '/\\input texinfo/d' \ - -e '/@c TEXI2ROFF-KILL/,/@c END TEXI2ROFF-KILL/d' \ - -e 's/{.*,,/{/' \ - -e '/@noindent/d' \ - as-${CONFIG}.texinfo | \ - texi2roff -mm | \ - sed -e 's/---/\\(em/g' \ - >as.mm - -# roff output (-me) -as.me: as-${CONFIG}.texinfo - sed -e '/\\input texinfo/d' \ - -e '/@c TEXI2ROFF-KILL/,/@c END TEXI2ROFF-KILL/d' \ - -e 's/{.*,,/{/' \ - as-${CONFIG}.texinfo | \ - texi2roff -me >as.me - - - -as-all.texinfo: as.texinfo pretex.m4 none.m4 all.m4 - ${M4} $(srcdir)/pretex.m4 $(srcdir)/none.m4 $(srcdir)/all.m4 $(srcdir)/as.texinfo >as-all.texinfo - -as-a29k.texinfo: as.texinfo pretex.m4 none.m4 a29k.m4 - ${M4} pretex.m4 none.m4 a29k.m4 as.texinfo >as-a29k.texinfo - -as-a29k-coff.texinfo: as.texinfo pretex.m4 none.m4 a29k-coff.m4 - ${M4} pretex.m4 none.m4 a29k-coff.m4 as.texinfo >as-a29k-coff.texinfo - -as-gen.texinfo: as.texinfo pretex.m4 none.m4 gen.m4 - ${M4} pretex.m4 none.m4 gen.m4 as.texinfo >as-gen.texinfo - -as-h8.texinfo: as.texinfo pretex.m4 none.m4 h8.m4 - ${M4} pretex.m4 none.m4 h8.m4 as.texinfo >as-h8.texinfo - -as-i80386.texinfo: as.texinfo pretex.m4 none.m4 i80386.m4 - ${M4} pretex.m4 none.m4 i80386.m4 as.texinfo >as-i80386.texinfo - -as-i960.texinfo: as.texinfo pretex.m4 none.m4 i960.m4 - ${M4} pretex.m4 none.m4 i960.m4 as.texinfo >as-i960.texinfo - -as-m680x0.texinfo: as.texinfo pretex.m4 none.m4 m680x0.m4 - ${M4} pretex.m4 none.m4 m680x0.m4 as.texinfo >as-m680x0.texinfo - -as-sparc.texinfo: as.texinfo pretex.m4 none.m4 sparc.m4 - ${M4} pretex.m4 none.m4 sparc.m4 as.texinfo >as-sparc.texinfo - -as-vax.texinfo: as.texinfo pretex.m4 none.m4 vax.m4 - ${M4} pretex.m4 none.m4 vax.m4 as.texinfo >as-vax.texinfo - -as-vintage.texinfo: as.texinfo pretex.m4 none.m4 vintage.m4 - ${M4} pretex.m4 none.m4 vintage.m4 as.texinfo >as-vintage.texinfo - -clean-info: - rm -f as-${CONFIG}.* as.dvi as.info* - -force: - -Makefile: $(srcdir)/Makefile.in $(host_makefile_frag) $(target_makefile_frag) - $(SHELL) ./config.status - diff --git a/gnu/usr.bin/as/doc/a29k-coff.m4 b/gnu/usr.bin/as/doc/a29k-coff.m4 deleted file mode 100644 index c3b04e1..0000000 --- a/gnu/usr.bin/as/doc/a29k-coff.m4 +++ /dev/null @@ -1,14 +0,0 @@ -_divert__(-1) -_define__(<_A29K__>,<1>) -_define__(<_GENERIC__>,<0>) -_define__(<_HOST__>,) -_define__(<_MACH_DEP__>,) -_define__(<_AOUT__>,<0>) -_define__(<_BOUT__>,<0>) -_define__(<_COFF__>,<1>) -_define__(<_ELF__>,<0>) -_define__(<_DIFFTABKLUG__>,0) NO difference-table kluge -_define__(<_IEEEFLOAT__>,1) IEEE floating point -_define__(<_W32__>,1) 32-bit words -_define__(<_W16__>,0) -_divert__<> diff --git a/gnu/usr.bin/as/doc/a29k.m4 b/gnu/usr.bin/as/doc/a29k.m4 deleted file mode 100644 index 9564387..0000000 --- a/gnu/usr.bin/as/doc/a29k.m4 +++ /dev/null @@ -1,9 +0,0 @@ -_divert__(-1) -_define__(<_A29K__>,<1>) -_define__(<_HOST__>,) -_define__(<_MACH_DEP__>,) -_define__(<_DIFFTABKLUG__>,0) NO difference-table kluge -_define__(<_IEEEFLOAT__>,1) IEEE floating point -_define__(<_W32__>,1) 32-bit words -_define__(<_W16__>,0) -_divert__<> diff --git a/gnu/usr.bin/as/doc/all.m4 b/gnu/usr.bin/as/doc/all.m4 deleted file mode 100644 index 3d4e7fd..0000000 --- a/gnu/usr.bin/as/doc/all.m4 +++ /dev/null @@ -1,20 +0,0 @@ -_divert__(-1) -<$Id: all.m4,v 1.1 1993/10/02 21:00:13 pk Exp $> -_define__(<_ALL_ARCH__>,<1>) -_define__(<_GENERIC__>,<1>) In case none.m4 changes its mind abt default - -_define__(<_AOUT__>,<1>) -_define__(<_BOUT__>,<1>) -_define__(<_COFF__>,<1>) -_define__(<_ELF__>,<1>) - -_define__(<_A29K__>,<1>) -_define__(<_H8__>,<1>) -_define__(<_I80386__>,<1>) -_define__(<_I960__>,<1>) -_define__(<_M680X0__>,<1>) -_define__(<_SPARC__>,<1>) -_define__(<_VAX__>,<1>) -_define__(<_VXWORKS__>,<1>) - -_divert__<> diff --git a/gnu/usr.bin/as/doc/as.texinfo b/gnu/usr.bin/as/doc/as.texinfo deleted file mode 100644 index c9e0f57..0000000 --- a/gnu/usr.bin/as/doc/as.texinfo +++ /dev/null @@ -1,6730 +0,0 @@ -_dnl__ -*-Texinfo-*- -_dnl__ Copyright (c) 1991 1992 Free Software Foundation, Inc. -_dnl__ $Id: as.texinfo,v 1.1 1993/10/02 21:00:15 pk Exp $ -\input texinfo @c -*-Texinfo-*- -@c Copyright (c) 1991 1992 Free Software Foundation, Inc. -@c %**start of header -@setfilename _AS__.info -_if__(_GENERIC__) -@settitle Using _AS__ -_fi__(_GENERIC__) -_if__(!_GENERIC__) -@settitle Using _AS__ (_HOST__) -_fi__(!_GENERIC__) -@setchapternewpage odd -@c @smallbook -@c @cropmarks -@c %**end of header - -@finalout -@syncodeindex ky cp - -_if__(0) - -NOTE: this manual is marked up for preprocessing with a collection -of m4 macros called "pretex.m4". - -THIS IS THE FULL SOURCE. The full source needs to be run through m4 -before either tex- or info- formatting: for example, - m4 pretex.m4 none.m4 m680x0.m4 as.texinfo >as-680x0.texinfo -will produce (assuming your path finds either GNU or SysV m4; Berkeley -won't do) a file, configured for the M680x0 version of GAS, suitable for -formatting. See the text in "pretex.m4" for a fuller explanation (and -the macro definitions). - -_fi__(0) -@c -@ifinfo -This file documents the GNU Assembler "_AS__". - -Copyright (C) 1991 Free Software Foundation, Inc. - -Permission is granted to make and distribute verbatim copies of -this manual provided the copyright notice and this permission notice -are preserved on all copies. - -@ignore -Permission is granted to process this file through Tex and print the -results, provided the printed document carries copying permission -notice identical to this one except for the removal of this paragraph -(this paragraph not being relevant to the printed manual). - -@end ignore -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that the -section entitled ``GNU General Public License'' is included exactly as -in the original, and provided that the entire resulting derived work is -distributed under the terms of a permission notice identical to this -one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that the section entitled ``GNU General Public License'' may be -included in a translation approved by the Free Software Foundation -instead of in the original English. -@end ifinfo - -@titlepage -@title Using _AS__ -@subtitle The GNU Assembler -_if__(!_GENERIC__) -@subtitle for the _HOST__ family -_fi__(!_GENERIC__) -@sp 1 -@subtitle January 1992 -@sp 1 -@sp 13 -The Free Software Foundation Inc. thanks The Nice Computer -Company of Australia for loaning Dean Elsner to write the -first (Vax) version of @code{as} for Project GNU. -The proprietors, management and staff of TNCCA thank FSF for -distracting the boss while they got some work -done. -@sp 3 -@author Dean Elsner, Jay Fenlason & friends -@c edited by: pesch@cygnus.com -@page -@tex -\def\$#1${{#1}} % Kluge: collect RCS revision info without $...$ -\xdef\manvers{\$Revision: 1.1 $} % For use in headers, footers too -{\parskip=0pt -\hfill \manvers\par -\hfill \TeX{}info \texinfoversion\par -} -%"boxit" macro for figures: -%Modified from Knuth's ``boxit'' macro from TeXbook (answer to exercise 21.3) -\gdef\boxit#1#2{\vbox{\hrule\hbox{\vrule\kern3pt - \vbox{\parindent=0pt\parskip=0pt\hsize=#1\kern3pt\strut\hfil -#2\hfil\strut\kern3pt}\kern3pt\vrule}\hrule}}%box with visible outline -\gdef\ibox#1#2{\hbox to #1{#2\hfil}\kern8pt}% invisible box -@end tex - -Edited by Roland Pesch for Cygnus Support. - -@vskip 0pt plus 1filll -Copyright @copyright{} 1991 Free Software Foundation, Inc. - -Permission is granted to make and distribute verbatim copies of -this manual provided the copyright notice and this permission notice -are preserved on all copies. - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that the -section entitled ``GNU General Public License'' is included exactly as -in the original, and provided that the entire resulting derived work is -distributed under the terms of a permission notice identical to this -one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions, -except that the section entitled ``GNU General Public License'' may be -included in a translation approved by the Free Software Foundation -instead of in the original English. -@end titlepage -@page -@node Top, Overview, (dir), (dir) -@ifinfo -This file is a user guide to the GNU assembler @code{_AS__}. -_if__(!_GENERIC__) -This version of the file describes @code{_AS__} configured to generate -code for _HOST__ architectures. -_fi__(!_GENERIC__) -@end ifinfo -@menu -* Overview:: Overview -* Invoking:: Command-Line Options -* Syntax:: Syntax -* Sections:: Sections and Relocation -* Symbols:: Symbols -* Expressions:: Expressions -* Pseudo Ops:: Assembler Directives -* _MACH_DEP__:: Machine Dependent Features -* Copying:: GNU GENERAL PUBLIC LICENSE -* Index:: Index -@end menu - -@node Overview, Invoking, Top, Top -@chapter Overview -@iftex -This manual is a user guide to the GNU assembler @code{_AS__}. -_if__(!_GENERIC__) -This version of the manual describes @code{_AS__} configured to generate -code for _HOST__ architectures. -_fi__(!_GENERIC__) -@end iftex - -@cindex invocation summary -@cindex option summary -@cindex summary of options -Here is a brief summary of how to invoke @code{_AS__}. For details, -@pxref{Invoking,,Comand-Line Options}. - -@c We don't use deffn and friends for the following because they seem -@c to be limited to one line for the header. -@smallexample - _AS__ [ -a | -al | -as ] [ -D ] [ -f ] - [ -I @var{path} ] [ -k ] [ -L ] - [ -o @var{objfile} ] [ -R ] [ -v ] [ -w ] -_if__(_A29K__) -@c am29k has no machine-dependent assembler options -_fi__(_A29K__) -_if__(_H8__) -@c h8/300 has no machine-dependent assembler options -_fi__(_H8__) -_if__(_I960__) -@c see md_parse_option in i960.c - [ -ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC ] - [ -b ] [ -norelax ] -_fi__(_I960__) -_if__(_M680X0__) - [ -l ] [ -mc68000 | -mc68010 | -mc68020 ] -_fi__(_M680X0__) - [ -- | @var{files} @dots{} ] -@end smallexample - -@table @code -@item -a | -al | -as -Turn on assembly listings; @samp{-al}, listing only, @samp{-as}, symbols -only, @samp{-a}, everything. - -@item -D -This option is accepted only for script compatibility with calls to -other assemblers; it has no effect on @code{_AS__}. - -@item -f -``fast''---skip preprocessing (assume source is compiler output) - -@item -I @var{path} -Add @var{path} to the search list for @code{.include} directives - -@item -k -_if__((!_GENERIC__) && !_DIFFTABKLUG__) -This option is accepted but has no effect on the _HOST__ family. -_fi__((!_GENERIC__) && !_DIFFTABKLUG__) -_if__(_GENERIC__ || _DIFFTABKLUG__) -Issue warnings when difference tables altered for long displacements. -_fi__(_GENERIC__ || _DIFFTABKLUG__) - -@item -L -Keep (in symbol table) local symbols, starting with @samp{L} - -@item -o @var{objfile} -Name the object-file output from @code{_AS__} - -@item -R -Fold data section into text section - -@item -v -Announce @code{as} version - -@item -W -Suppress warning messages - -_if__(_I960__) -@item -ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC -_if__(_GENERIC__) -(When configured for Intel 960). -_fi__(_GENERIC__) -Specify which variant of the 960 architecture is the target. - -@item -b -_if__(_GENERIC__) -(When configured for Intel 960). -_fi__(_GENERIC__) -Add code to collect statistics about branches taken. - -@item -norelax -_if__(_GENERIC__) -(When configured for Intel 960). -_fi__(_GENERIC__) -Do not alter compare-and-branch instructions for long displacements; -error if necessary. -_fi__(_I960__) - -_if__(_M680X0__) -@item -l -_if__(_GENERIC__) -(When configured for Motorola 68000). -_fi__(_GENERIC__) -Shorten references to undefined symbols, to one word instead of two - -@item -mc68000 | -mc68010 | -mc68020 -_if__(_GENERIC__) -(When configured for Motorola 68000). -_fi__(_GENERIC__) -Specify what processor in the 68000 family is the target (default 68020) -_fi__(_M680X0__) - -@item -- | @var{files} @dots{} -Standard input, or source files to assemble -@end table - -@menu -* Manual:: Structure of this Manual -* GNU Assembler:: _AS__, the GNU Assembler -* Object Formats:: Object File Formats -* Command Line:: Command Line -* Input Files:: Input Files -* Object:: Output (Object) File -* Errors:: Error and Warning Messages -@end menu - -@node Manual, GNU Assembler, Overview, Overview -@section Structure of this Manual - -@cindex manual, structure and purpose -This manual is intended to describe what you need to know to use -@sc{gnu} @code{_AS__}. We cover the syntax expected in source files, including -notation for symbols, constants, and expressions; the directives that -@code{_AS__} understands; and of course how to invoke @code{_AS__}. - -_if__(!_GENERIC__) -We also cover special features in the _HOST__ -configuration of @code{_AS__}, including assembler directives. -_fi__(!_GENERIC__) -_if__(_GENERIC__) -This manual also describes some of the machine-dependent features of -various flavors of the assembler. -_fi__(_GENERIC__) -_if__(_INTERNALS__) -This manual also describes how the assembler works internally, and -provides some information that may be useful to people attempting to -port the assembler to another machine. -_fi__(_INTERNALS__) -@refill - -@cindex machine instructions (not covered) -On the other hand, this manual is @emph{not} intended as an introduction -to programming in assembly language---let alone programming in general! -In a similar vein, we make no attempt to introduce the machine -architecture; we do @emph{not} describe the instruction set, standard -mnemonics, registers or addressing modes that are standard to a -particular architecture. -_if__(_GENERIC__) -You may want to consult the manufacturer's -machine architecture manual for this information. -_fi__(_GENERIC__) -_if__(_H8__&&!_GENERIC__) -For information on the H8/300 machine instruction set, see @cite{H8/300 -Series Programming Manual} (Hitachi ADE--602--025). -_fi__(_H8__&&!_GENERIC__) - - -@c I think this is premature---pesch@cygnus.com, 17jan1991 -@ignore -Throughout this manual, we assume that you are running @dfn{GNU}, -the portable operating system from the @dfn{Free Software -Foundation, Inc.}. This restricts our attention to certain kinds of -computer (in particular, the kinds of computers that GNU can run on); -once this assumption is granted examples and definitions need less -qualification. - -@code{_AS__} is part of a team of programs that turn a high-level -human-readable series of instructions into a low-level -computer-readable series of instructions. Different versions of -@code{_AS__} are used for different kinds of computer. -@end ignore - -@c There used to be a section "Terminology" here, which defined -@c "contents", "byte", "word", and "long". Defining "word" to any -@c particular size is confusing when the .word directive may generate 16 -@c bits on one machine and 32 bits on another; in general, for the user -@c version of this manual, none of these terms seem essential to define. -@c They were used very little even in the former draft of the manual; -@c this draft makes an effort to avoid them (except in names of -@c directives). - -@node GNU Assembler, Object Formats, Manual, Overview -@section _AS__, the GNU Assembler - -GNU @code{as} is really a family of assemblers. -_if__(!_GENERIC__) -This manual describes @code{_AS__}, a member of that family which is -configured for the _HOST__ architectures. -_fi__(!_GENERIC__) -If you use (or have used) the GNU assembler on one architecture, you -should find a fairly similar environment when you use it on another -architecture. Each version has much in common with the others, -including object file formats, most assembler directives (often called -@dfn{pseudo-ops)} and assembler syntax.@refill - -_if__(_GENERIC__||!_H8__) -@cindex purpose of @sc{gnu} @code{_AS__} -@code{_AS__} is primarily intended to assemble the output of the GNU C -compiler @code{_GCC__} for use by the linker @code{_LD__}. Nevertheless, -we've tried to make @code{_AS__} assemble correctly everything that the native -assembler would. -_fi__(_GENERIC__||!_H8__) -_if__(_VAX__) -Any exceptions are documented explicitly (@pxref{_MACH_DEP__}). -_fi__(_VAX__) -_if__(_GENERIC__||_M680X0__) -This doesn't mean @code{_AS__} always uses the same syntax as another -assembler for the same architecture; for example, we know of several -incompatible versions of 680x0 assembly language syntax. -_fi__(_GENERIC__||_M680X0__) - -Unlike older assemblers, @code{_AS__} is designed to assemble a source -program in one pass of the source file. This has a subtle impact on the -@kbd{.org} directive (@pxref{Org,,@code{.org}}). - -@node Object Formats, Command Line, GNU Assembler, Overview -@section Object File Formats - -@cindex object file format -The GNU assembler can be configured to produce several alternative -object file formats. For the most part, this does not affect how you -write assembly language programs; but directives for debugging symbols -are typically different in different file formats. @xref{Symbol -Attributes,,Symbol Attributes}. -_if__(!_GENERIC__) -_if__(!(_I960__||_A29K__)) -_if__(_AOUT__ && (!_COFF__) && (!_ELF__)) -On the _HOST__, @code{_AS__} is configured to produce @code{a.out} format object -files.@refill -_fi__(_AOUT__ && (!_COFF__) && (!_ELF__)) -_if__((!_AOUT__) && _COFF__ && (!_ELF__)) -On the _HOST__, @code{_AS__} is configured to produce COFF format object -files.@refill -_fi__((!_AOUT__) && _COFF__ && (!_ELF__)) -_fi__(!(_I960__||_A29K__)) -_if__(_A29K__) -On the _HOST__, @code{_AS__} can be configured to produce either -@code{a.out} or COFF format object files. -_fi__(_A29K__) -_if__(_I960__) -On the _HOST__, @code{_AS__} can be configured to produce either @code{b.out} or COFF -format object files. -_fi__(_I960__) -_fi__(!_GENERIC__) - -@node Command Line, Input Files, Object Formats, Overview -@section Command Line - -@cindex command line conventions -After the program name @code{_AS__}, the command line may contain -options and file names. Options may appear in any order, and may be -before, after, or between file names. The order of file names is -significant. - -@cindex standard input, as input file -@kindex -- -@file{--} (two hyphens) by itself names the standard input file -explicitly, as one of the files for @code{_AS__} to assemble. - -@cindex options, command line -Except for @samp{--} any command line argument that begins with a -hyphen (@samp{-}) is an option. Each option changes the behavior of -@code{_AS__}. No option changes the way another option works. An -option is a @samp{-} followed by one or more letters; the case of -the letter is important. All options are optional. - -Some options expect exactly one file name to follow them. The file -name may either immediately follow the option's letter (compatible -with older assemblers) or it may be the next command argument (GNU -standard). These two command lines are equivalent: - -@smallexample -_AS__ -o my-object-file.o mumble.s -_AS__ -omy-object-file.o mumble.s -@end smallexample - -@node Input Files, Object, Command Line, Overview -@section Input Files - -@cindex input -@cindex source program -@cindex files, input -We use the phrase @dfn{source program}, abbreviated @dfn{source}, to -describe the program input to one run of @code{_AS__}. The program may -be in one or more files; how the source is partitioned into files -doesn't change the meaning of the source. - -@c I added "con" prefix to "catenation" just to prove I can overcome my -@c APL training... pesch@cygnus.com -The source program is a concatenation of the text in all the files, in the -order specified. - -Each time you run @code{_AS__} it assembles exactly one source -program. The source program is made up of one or more files. -(The standard input is also a file.) - -You give @code{_AS__} a command line that has zero or more input file -names. The input files are read (from left file name to right). A -command line argument (in any position) that has no special meaning -is taken to be an input file name. - -If you give @code{_AS__} no file names it attempts to read one input file -from the @code{_AS__} standard input, which is normally your terminal. You -may have to type @key{ctl-D} to tell @code{_AS__} there is no more program -to assemble. - -Use @samp{--} if you need to explicitly name the standard input file -in your command line. - -If the source is empty, @code{_AS__} will produce a small, empty object -file. - -@subheading Filenames and Line-numbers - -@cindex input file linenumbers -@cindex line numbers, in input files -There are two ways of locating a line in the input file (or files) and -either may be used in reporting error messages. One way refers to a line -number in a physical file; the other refers to a line number in a -``logical'' file. @xref{Errors, ,Error and Warning Messages}. - -@dfn{Physical files} are those files named in the command line given -to @code{_AS__}. - -@dfn{Logical files} are simply names declared explicitly by assembler -directives; they bear no relation to physical files. Logical file names -help error messages reflect the original source file, when @code{_AS__} -source is itself synthesized from other files. -@xref{App-File,,@code{.app-file}}. - -@node Object, Errors, Input Files, Overview -@section Output (Object) File - -@cindex object file -@cindex output file -@kindex a.out -@kindex .o -Every time you run @code{_AS__} it produces an output file, which is -your assembly language program translated into numbers. This file -is the object file, named @code{a.out} unless you tell @code{_AS__} to -give it another name by using the @code{-o} option. Conventionally, -object file names end with @file{.o}. The default name of -@file{a.out} is used for historical reasons: older assemblers were -capable of assembling self-contained programs directly into a -runnable program. -@c This may still work, but hasn't been tested. - -@cindex linker -@kindex ld -The object file is meant for input to the linker @code{_LD__}. It contains -assembled program code, information to help @code{_LD__} integrate -the assembled program into a runnable file, and (optionally) symbolic -information for the debugger. - -@c link above to some info file(s) like the description of a.out. -@c don't forget to describe GNU info as well as Unix lossage. - -@node Errors, , Object, Overview -@section Error and Warning Messages - -@cindex error messsages -@cindex warning messages -@cindex messages from @code{_AS__} -@code{_AS__} may write warnings and error messages to the standard error -file (usually your terminal). This should not happen when a compiler -runs @code{_AS__} automatically. Warnings report an assumption made so -that @code{_AS__} could keep assembling a flawed program; errors report a -grave problem that stops the assembly. - -@cindex format of warning messages -Warning messages have the format - -@smallexample -file_name:@b{NNN}:Warning Message Text -@end smallexample - -@noindent -@cindex line numbers, in warnings/errors -(where @b{NNN} is a line number). If a logical file name has -been given (@pxref{App-File,,@code{.app-file}}) it is used for the filename, otherwise the -name of the current input file is used. If a logical line number was -given -_if__(!_A29K__) -(@pxref{Line,,@code{.line}}) -_fi__(!_A29K__) -_if__(_A29K__) -(@pxref{Ln,,@code{.ln}}) -_fi__(_A29K__) -then it is used to calculate the number printed, -otherwise the actual line in the current source file is printed. The -message text is intended to be self explanatory (in the grand Unix -tradition). @refill - -@cindex format of error messages -Error messages have the format -@smallexample -file_name:@b{NNN}:FATAL:Error Message Text -@end smallexample -The file name and line number are derived as for warning -messages. The actual message text may be rather less explanatory -because many of them aren't supposed to happen. - -@node Invoking, Syntax, Overview, Top -@chapter Command-Line Options - -@cindex options, all versions of @code{_AS__} -This chapter describes command-line options available in @emph{all} -versions of the GNU assembler; @pxref{_MACH_DEP__}, for options specific -_if__(!_GENERIC__) -to the _HOST__. -_fi__(!_GENERIC__) -_if__(_GENERIC__) -to particular machine architectures. -_fi__(_GENERIC__) - -@section Enable Listings: @code{-a}, @code{-al}, @code{-as} - -@kindex -a -@kindex -al -@kindex -as -@cindex listings, enabling -@cindex assembly listings, enabling -These options enable listing output from the assembler. @samp{-a} by -itself requests all listing output; @samp{-al} requests only the -output-program listing, and @samp{-as} requests only a symbol table -listing. - -Once you have specified one of these options, you can further control -listing output and its appearance using the directives @code{.list}, -@code{.nolist}, @code{.psize}, @code{.eject}, @code{.title}, and -@code{.sbttl}. - -If you do not request listing output with one of the @samp{-a} options, the -listing-control directives have no effect. - -@section @code{-D} - -@kindex -D -This option has no effect whatsoever, but it is accepted to make it more -likely that scripts written for other assemblers will also work with -@code{_AS__}. - -@section Work Faster: @code{-f} - -@kindex -f -@cindex trusted compiler -@cindex faster processing (@code{-f}) -@samp{-f} should only be used when assembling programs written by a -(trusted) compiler. @samp{-f} stops the assembler from pre-processing -the input file(s) before assembling them. @xref{Pre-processing, -,Pre-processing}. - -@quotation -@emph{Warning:} if the files actually need to be pre-processed (if they -contain comments, for example), @code{_AS__} will not work correctly if -@samp{-f} is used. -@end quotation - -@section @code{.include} search path: @code{-I} @var{path} - -@kindex -I @var{path} -@cindex paths for @code{.include} -@cindex search path for @code{.include} -@cindex @code{include} directive search path -Use this option to add a @var{path} to the list of directories -@code{_AS__} will search for files specified in @code{.include} -directives (@pxref{Include,,@code{.include}}). You may use @code{-I} as -many times as necessary to include a variety of paths. The current -working directory is always searched first; after that, @code{_AS__} -searches any @samp{-I} directories in the same order as they were -specified (left to right) on the command line. - -@section Difference Tables: @code{-k} - -@kindex -k -_if__((!_GENERIC__) && (!_DIFFTABKLUG__)) -On the _HOST__ family, this option is allowed, but has no effect. It is -permitted for compatibility with the GNU assembler on other platforms, -where it can be used to warn when the assembler alters the machine code -generated for @samp{.word} directives in difference tables. The _HOST__ -family does not have the addressing limitations that sometimes lead to this -alteration on other platforms. -_fi__((!_GENERIC__) && (!_DIFFTABKLUG__)) - -_if__(_GENERIC__ || _DIFFTABKLUG__ ) -@cindex difference tables, warning -@cindex warning for altered difference tables -@code{_AS__} sometimes alters the code emitted for directives of the form -@samp{.word @var{sym1}-@var{sym2}}; @pxref{Word,,@code{.word}}. -You can use the @samp{-k} option if you want a warning issued when this -is done. -_fi__(_GENERIC__ || _DIFFTABKLUG__ ) - -@section Include Local Labels: @code{-L} - -@kindex -L -@cindex local labels, retaining in output -Labels beginning with @samp{L} (upper case only) are called @dfn{local -labels}. @xref{Symbol Names}. Normally you don't see such labels when -debugging, because they are intended for the use of programs (like -compilers) that compose assembler programs, not for your notice. -Normally both @code{_AS__} and @code{_LD__} discard such labels, so you don't -normally debug with them. - -This option tells @code{_AS__} to retain those @samp{L@dots{}} symbols -in the object file. Usually if you do this you also tell the linker -@code{_LD__} to preserve symbols whose names begin with @samp{L}. - -@section Name the Object File: @code{-o} - -@kindex -o -@cindex naming object file -@cindex object file name -There is always one object file output when you run @code{_AS__}. By -default it has the name @file{a.out}. You use this option (which -takes exactly one filename) to give the object file a different name. - -Whatever the object file is called, @code{_AS__} will overwrite any -existing file of the same name. - -@section Join Data and Text Sections: @code{-R} - -@kindex -R -@cindex data and text sections, joining -@cindex text and data sections, joining -@cindex joining text and data sections -@cindex merging text and data sections -@code{-R} tells @code{_AS__} to write the object file as if all -data-section data lives in the text section. This is only done at -the very last moment: your binary data are the same, but data -section parts are relocated differently. The data section part of -your object file is zero bytes long because all it bytes are -appended to the text section. (@xref{Sections,,Sections and Relocation}.) - -When you specify @code{-R} it would be possible to generate shorter -address displacements (because we don't have to cross between text and -data section). We refrain from doing this simply for compatibility with -older versions of @code{_AS__}. In future, @code{-R} may work this way. - -_if__(_COFF__) -When @code{_AS__} is configured for COFF output, -this option is only useful if you use sections named @samp{.text} and -@samp{.data}. -_fi__(_COFF__) - -@section Announce Version: @code{-v} - -@kindex -v -@kindex -version -@cindex @code{_AS__} version -@cindex version of @code{_AS__} -You can find out what version of as is running by including the -option @samp{-v} (which you can also spell as @samp{-version}) on the -command line. - -@section Suppress Warnings: @code{-W} - -@kindex -W -@cindex suppressing warnings -@cindex warnings, suppressing -@code{_AS__} should never give a warning or error message when -assembling compiler output. But programs written by people often -cause @code{_AS__} to give a warning that a particular assumption was -made. All such warnings are directed to the standard error file. -If you use this option, no warnings are issued. This option only -affects the warning messages: it does not change any particular of how -@code{_AS__} assembles your file. Errors, which stop the assembly, are -still reported. - -@node Syntax, Sections, Invoking, Top -@chapter Syntax - -@cindex machine-independent syntax -@cindex syntax, machine-independent -This chapter describes the machine-independent syntax allowed in a -source file. @code{_AS__} syntax is similar to what many other assemblers -use; it is inspired in BSD 4.2 -_if__(!_VAX__) -assembler. @refill -_fi__(!_VAX__) -_if__(_VAX__) -assembler, except that @code{_AS__} does not assemble Vax bit-fields. -_fi__(_VAX__) - -@menu -* Pre-processing:: Pre-processing -* Whitespace:: Whitespace -* Comments:: Comments -* Symbol Intro:: Symbols -* Statements:: Statements -* Constants:: Constants -@end menu - -@node Pre-processing, Whitespace, Syntax, Syntax -@section Pre-Processing - -@cindex preprocessing -The pre-processor: -@itemize @bullet -@cindex whitespace, removed by preprocessor -@item -adjusts and removes extra whitespace. It leaves one space or tab before -the keywords on a line, and turns any other whitespace on the line into -a single space. - -@cindex comments, removed by preprocessor -@item -removes all comments, replacing them with a single space, or an -appropriate number of newlines. - -@cindex constants, converted by preprocessor -@item -converts character constants into the appropriate numeric values. -@end itemize - -Excess whitespace, comments, and character constants -cannot be used in the portions of the input text that are not -pre-processed. - -@cindex turning preprocessing on and off -@cindex preprocessing, turning on and off -@kindex #NO_APP -@kindex #APP -If the first line of an input file is @code{#NO_APP} or the @samp{-f} -option is given, the input file will not be pre-processed. Within such -an input file, parts of the file can be pre-processed by putting a line -that says @code{#APP} before the text that should be pre-processed, and -putting a line that says @code{#NO_APP} after them. This feature is -mainly intend to support @code{asm} statements in compilers whose output -normally does not need to be pre-processed. - -@node Whitespace, Comments, Pre-processing, Syntax -@section Whitespace - -@cindex whitespace -@dfn{Whitespace} is one or more blanks or tabs, in any order. -Whitespace is used to separate symbols, and to make programs neater for -people to read. Unless within character constants -(@pxref{Characters,,Character Constants}), any whitespace means the same -as exactly one space. - -@node Comments, Symbol Intro, Whitespace, Syntax -@section Comments - -@cindex comments -There are two ways of rendering comments to @code{_AS__}. In both -cases the comment is equivalent to one space. - -Anything from @samp{/*} through the next @samp{*/} is a comment. -This means you may not nest these comments. - -@smallexample -/* - The only way to include a newline ('\n') in a comment - is to use this sort of comment. -*/ - -/* This sort of comment does not nest. */ -@end smallexample - -@cindex line comment character -Anything from the @dfn{line comment} character to the next newline -is considered a comment and is ignored. The line comment character is -_if__(_VAX__) -@samp{#} on the Vax; -_fi__(_VAX__) -_if__(_I960__) -@samp{#} on the i960; -_fi__(_I960__) -_if__(_M680X0__) -@samp{|} on the 680x0; -_fi__(_M680X0__) -_if__(_A29K__) -@samp{;} for the AMD 29K family; -_fi__(_A29K__) -_if__(_H8__) -@samp{;} for the _HOST__ family; -_fi__(_H8__) -@pxref{_MACH_DEP__}. @refill -@c FIXME: fill in SPARC line comment char - -_if__(_GENERIC__) -On some machines there are two different line comment characters. One -will only begin a comment if it is the first non-whitespace character on -a line, while the other will always begin a comment. -_fi__(_GENERIC__) - -@kindex # -@cindex lines starting with @code{#} -@cindex logical line numbers -To be compatible with past assemblers, a special interpretation is -given to lines that begin with @samp{#}. Following the @samp{#} an -absolute expression (@pxref{Expressions}) is expected: this will be -the logical line number of the @b{next} line. Then a string -(@xref{Strings}.) is allowed: if present it is a new logical file -name. The rest of the line, if any, should be whitespace. - -If the first non-whitespace characters on the line are not numeric, -the line is ignored. (Just like a comment.) -@smallexample - # This is an ordinary comment. -# 42-6 "new_file_name" # New logical file name - # This is logical line # 36. -@end smallexample -This feature is deprecated, and may disappear from future versions -of @code{_AS__}. - -@node Symbol Intro, Statements, Comments, Syntax -@section Symbols - -@cindex symbols -@cindex characters used in symbols -A @dfn{symbol} is one or more characters chosen from the set of all -letters (both upper and lower case), digits and -_if__(!_H8__) -the three characters @samp{_.$} -_fi__(!_H8__) -_if__(_H8__) -the two characters @samp{_.} -_if__(_GENERIC__) -On most machines, you can also use @code{$} in symbol names; exceptions -are noted in @ref{_MACH_DEP__}. -_fi__(_GENERIC__) -_fi__(_H8__) -No symbol may begin with a digit. Case is significant. -There is no length limit: all characters are significant. Symbols are -delimited by characters not in that set, or by the beginning of a file -(since the source program must end with a newline, the end of a file is -not a possible symbol delimiter). @xref{Symbols}. -@cindex length of symbols - -@node Statements, Constants, Symbol Intro, Syntax -@section Statements - -@cindex statements, structure of -@cindex line separator character -@cindex statement separator character -_if__(!_GENERIC__) -_if__(!(_A29K__||_H8__)) -A @dfn{statement} ends at a newline character (@samp{\n}) or at a -semicolon (@samp{;}). The newline or semicolon is considered part of -the preceding statement. Newlines and semicolons within character -constants are an exception: they don't end statements. -_fi__(!(_A29K__||_H8__)) -_if__(_A29K__) -A @dfn{statement} ends at a newline character (@samp{\n}) or an ``at'' -sign (@samp{@@}). The newline or at sign is considered part of the -preceding statement. Newlines and at signs within character constants -are an exception: they don't end statements. -_fi__(_A29K__) -_if__(_H8__) -A @dfn{statement} ends at a newline character (@samp{\n}) or a dollar -sign (@samp{$}). The newline or dollar sign is considered part of the -preceding statement. Newlines and dollar signs within character constants -are an exception: they don't end statements. -_fi__(_H8__) -_fi__(!_GENERIC__) -_if__(_GENERIC__) -A @dfn{statement} ends at a newline character (@samp{\n}) or line -separator character. (The line separator is usually @samp{;}, unless -this conflicts with the comment character; @pxref{_MACH_DEP__}.) The -newline or separator character is considered part of the preceding -statement. Newlines and separators within character constants are an -exception: they don't end statements. -_fi__(_GENERIC__) - -@cindex newline, required at file end -@cindex EOF, newline must precede -It is an error to end any statement with end-of-file: the last -character of any input file should be a newline.@refill - -@cindex continuing statements -@cindex multi-line statements -@cindex statement on multiple lines -You may write a statement on more than one line if you put a -backslash (@kbd{\}) immediately in front of any newlines within the -statement. When @code{_AS__} reads a backslashed newline both -characters are ignored. You can even put backslashed newlines in -the middle of symbol names without changing the meaning of your -source program. - -An empty statement is allowed, and may include whitespace. It is ignored. - -@cindex instructions and directives -@cindex directives and instructions -@c "key symbol" is not used elsewhere in the document; seems pedantic to -@c @defn{} it in that case, as was done previously... pesch@cygnus.com, -@c 13feb91. -A statement begins with zero or more labels, optionally followed by a -key symbol which determines what kind of statement it is. The key -symbol determines the syntax of the rest of the statement. If the -symbol begins with a dot @samp{.} then the statement is an assembler -directive: typically valid for any computer. If the symbol begins with -a letter the statement is an assembly language @dfn{instruction}: it -will assemble into a machine language instruction. -_if__(_GENERIC__) -Different versions of @code{_AS__} for different computers will -recognize different instructions. In fact, the same symbol may -represent a different instruction in a different computer's assembly -language.@refill -_fi__(_GENERIC__) - -@cindex @code{:} (label) -@cindex label (@code{:}) -A label is a symbol immediately followed by a colon (@code{:}). -Whitespace before a label or after a colon is permitted, but you may not -have whitespace between a label's symbol and its colon. @xref{Labels}. - -@smallexample -label: .directive followed by something -another_label: # This is an empty statement. - instruction operand_1, operand_2, @dots{} -@end smallexample - -@node Constants, , Statements, Syntax -@section Constants - -@cindex constants -A constant is a number, written so that its value is known by -inspection, without knowing any context. Like this: -@smallexample -.byte 74, 0112, 092, 0x4A, 0X4a, 'J, '\J # All the same value. -.ascii "Ring the bell\7" # A string constant. -.octa 0x123456789abcdef0123456789ABCDEF0 # A bignum. -.float 0f-314159265358979323846264338327\ -95028841971.693993751E-40 # - pi, a flonum. -@end smallexample - -@menu -* Characters:: Character Constants -* Numbers:: Number Constants -@end menu - -@node Characters, Numbers, Constants, Constants -@subsection Character Constants - -@cindex character constants -@cindex constants, character -There are two kinds of character constants. A @dfn{character} stands -for one character in one byte and its value may be used in -numeric expressions. String constants (properly called string -@emph{literals}) are potentially many bytes and their values may not be -used in arithmetic expressions. - -@menu -* Strings:: Strings -* Chars:: Characters -@end menu - -@node Strings, Chars, Characters, Characters -@subsubsection Strings - -@cindex string constants -@cindex constants, string -A @dfn{string} is written between double-quotes. It may contain -double-quotes or null characters. The way to get special characters -into a string is to @dfn{escape} these characters: precede them with -a backslash @samp{\} character. For example @samp{\\} represents -one backslash: the first @code{\} is an escape which tells -@code{_AS__} to interpret the second character literally as a backslash -(which prevents @code{_AS__} from recognizing the second @code{\} as an -escape character). The complete list of escapes follows. - -@cindex escape codes, character -@cindex character escape codes -@table @kbd -@c @item \a -@c Mnemonic for ACKnowledge; for ASCII this is octal code 007. -@c -@item \b -@cindex @code{\b} (backspace character) -@cindex backspace (@code{\b}) -Mnemonic for backspace; for ASCII this is octal code 010. - -@c @item \e -@c Mnemonic for EOText; for ASCII this is octal code 004. -@c -@item \f -@cindex @code{\f} (formfeed character) -@cindex formfeed (@code{\f}) -Mnemonic for FormFeed; for ASCII this is octal code 014. - -@item \n -@cindex @code{\n} (newline character) -@cindex newline (@code{\n}) -Mnemonic for newline; for ASCII this is octal code 012. - -@c @item \p -@c Mnemonic for prefix; for ASCII this is octal code 033, usually known as @code{escape}. -@c -@item \r -@cindex @code{\r} (carriage return character) -@cindex carriage return (@code{\r}) -Mnemonic for carriage-Return; for ASCII this is octal code 015. - -@c @item \s -@c Mnemonic for space; for ASCII this is octal code 040. Included for compliance with -@c other assemblers. -@c -@item \t -@cindex @code{\t} (tab) -@cindex tab (@code{\t}) -Mnemonic for horizontal Tab; for ASCII this is octal code 011. - -@c @item \v -@c Mnemonic for Vertical tab; for ASCII this is octal code 013. -@c @item \x @var{digit} @var{digit} @var{digit} -@c A hexadecimal character code. The numeric code is 3 hexadecimal digits. -@c -@item \ @var{digit} @var{digit} @var{digit} -@cindex @code{\@var{ddd}} (octal character code) -@cindex octal character code (@code{\@var{ddd}}) -An octal character code. The numeric code is 3 octal digits. -For compatibility with other Unix systems, 8 and 9 are accepted as digits: -for example, @code{\008} has the value 010, and @code{\009} the value 011. - -@item \\ -@cindex @code{\\} (@samp{\} character) -@cindex backslash (@code{\\}) -Represents one @samp{\} character. - -@c @item \' -@c Represents one @samp{'} (accent acute) character. -@c This is needed in single character literals -@c (@xref{Characters,,Character Constants}.) to represent -@c a @samp{'}. -@c -@item \" -@cindex @code{\"} (doublequote character) -@cindex doublequote (@code{\"}) -Represents one @samp{"} character. Needed in strings to represent -this character, because an unescaped @samp{"} would end the string. - -@item \ @var{anything-else} -Any other character when escaped by @kbd{\} will give a warning, but -assemble as if the @samp{\} was not present. The idea is that if -you used an escape sequence you clearly didn't want the literal -interpretation of the following character. However @code{_AS__} has no -other interpretation, so @code{_AS__} knows it is giving you the wrong -code and warns you of the fact. -@end table - -Which characters are escapable, and what those escapes represent, -varies widely among assemblers. The current set is what we think -the BSD 4.2 assembler recognizes, and is a subset of what most C -compilers recognize. If you are in doubt, don't use an escape -sequence. - -@node Chars, , Strings, Characters -@subsubsection Characters - -@cindex single character constant -@cindex character, single -@cindex constant, single character -A single character may be written as a single quote immediately -followed by that character. The same escapes apply to characters as -to strings. So if you want to write the character backslash, you -must write @kbd{'\\} where the first @code{\} escapes the second -@code{\}. As you can see, the quote is an acute accent, not a -grave accent. A newline -_if__(!_GENERIC__) -_if__(!(_A29K__||_H8__)) -(or semicolon @samp{;}) -_fi__(!(_A29K__||_H8__)) -_if__(_A29K__) -(or at sign @samp{@@}) -_fi__(_A29K__) -_if__(_H8__) -(or dollar sign @samp{$}) -_fi__(_H8__) -_fi__(!_GENERIC__) -immediately following an acute accent is taken as a literal character -and does not count as the end of a statement. The value of a character -constant in a numeric expression is the machine's byte-wide code for -that character. @code{_AS__} assumes your character code is ASCII: -@kbd{'A} means 65, @kbd{'B} means 66, and so on. @refill - -@node Numbers, , Characters, Constants -@subsection Number Constants - -@cindex constants, number -@cindex number constants -@code{_AS__} distinguishes three kinds of numbers according to how they -are stored in the target machine. @emph{Integers} are numbers that -would fit into an @code{int} in the C language. @emph{Bignums} are -integers, but they are stored in more than 32 bits. @emph{Flonums} -are floating point numbers, described below. - -@menu -* Integers:: Integers -* Bignums:: Bignums -* Flonums:: Flonums -_if__(_I960__&&!_GENERIC__) -* Bit Fields:: Bit Fields -_fi__(_I960__&&!_GENERIC__) -@end menu - -@node Integers, Bignums, Numbers, Numbers -@subsubsection Integers -@cindex integers -@cindex constants, integer - -@cindex binary integers -@cindex integers, binary -A binary integer is @samp{0b} or @samp{0B} followed by zero or more of -the binary digits @samp{01}. - -@cindex octal integers -@cindex integers, octal -An octal integer is @samp{0} followed by zero or more of the octal -digits (@samp{01234567}). - -@cindex decimal integers -@cindex integers, decimal -A decimal integer starts with a non-zero digit followed by zero or -more digits (@samp{0123456789}). - -@cindex hexadecimal integers -@cindex integers, hexadecimal -A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or -more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}. - -Integers have the usual values. To denote a negative integer, use -the prefix operator @samp{-} discussed under expressions -(@pxref{Prefix Ops,,Prefix Operators}). - -@node Bignums, Flonums, Integers, Numbers -@subsubsection Bignums - -@cindex bignums -@cindex constants, bignum -A @dfn{bignum} has the same syntax and semantics as an integer -except that the number (or its negative) takes more than 32 bits to -represent in binary. The distinction is made because in some places -integers are permitted while bignums are not. - -_if__(_I960__&&!_GENERIC__) -@node Flonums, Bit Fields, Bignums, Numbers -_fi__(_I960__&&!_GENERIC__) -_if__(_GENERIC__||!_I960__) -@node Flonums, , Bignums, Numbers -_fi__(_GENERIC__||!_I960__) -@subsubsection Flonums -@cindex flonums -@cindex floating point numbers -@cindex constants, floating point - -@cindex precision, floating point -A @dfn{flonum} represents a floating point number. The translation is -indirect: a decimal floating point number from the text is converted by -@code{_AS__} to a generic binary floating point number of more than -sufficient precision. This generic floating point number is converted -to a particular computer's floating point format (or formats) by a -portion of @code{_AS__} specialized to that computer. - -A flonum is written by writing (in order) -@itemize @bullet -@item -The digit @samp{0}. -@item -A letter, to tell @code{_AS__} the rest of the number is a flonum. -_if__(_GENERIC__) -@kbd{e} is recommended. Case is not important. -@ignore -@c FIXME: verify if flonum syntax really this vague for most cases - (Any otherwise illegal letter -will work here, but that might be changed. Vax BSD 4.2 assembler seems -to allow any of @samp{defghDEFGH}.) -@end ignore -_fi__(_GENERIC__) -_if__(_A29K__||_H8__) -_if__(_GENERIC__) -On the AMD 29K and H8/300 architectures, the letter must be: -_fi__(_GENERIC__) -One of the letters @samp{DFPRSX} (in upper or lower case). -_fi__(_A29K__||_H8__) -_if__(_I960__) -_if__(_GENERIC__) -On the Intel 960 architecture, the letter must be: -_fi__(_GENERIC__) -One of the letters @samp{DFT} (in upper or lower case). -_fi__(_I960__) -@item -An optional sign: either @samp{+} or @samp{-}. -@item -An optional @dfn{integer part}: zero or more decimal digits. -@item -An optional @dfn{fractional part}: @samp{.} followed by zero -or more decimal digits. -@item -An optional exponent, consisting of: -@itemize @bullet -@item -An @samp{E} or @samp{e}. -@c I can't find a config where "EXP_CHARS" is other than 'eE', but in -@c principle this can perfectly well be different on different targets. -@item -Optional sign: either @samp{+} or @samp{-}. -@item -One or more decimal digits. -@end itemize -@end itemize - -At least one of the integer part or the fractional part must be -present. The floating point number has the usual base-10 value. - -@code{_AS__} does all processing using integers. Flonums are computed -independently of any floating point hardware in the computer running -@code{_AS__}. - -_if__(_I960__&&!_GENERIC__) -@c Bit fields are written as a general facility but are also controlled -@c by a conditional-compilation flag---which is as of now (21mar91) -@c turned on only by the i960 config of GAS. -@node Bit Fields, , Flonums, Numbers -@subsubsection Bit Fields - -@cindex bit fields -@cindex constants, bit field -You can also define numeric constants as @dfn{bit fields}. -specify two numbers separated by a colon--- -@example -@var{mask}:@var{value} -@end example -@noindent -the first will act as a mask; @code{_AS__} will bitwise-and it with the -second value. - -The resulting number is then packed -_if__(_GENERIC__) -@c this conditional paren in case bit fields turned on elsewhere than 960 -(in host-dependent byte order) -_fi__(_GENERIC__) -into a field whose width depends on which assembler directive has the -bit-field as its argument. Overflow (a result from the bitwise and -requiring more binary digits to represent) is not an error; instead, -more constants are generated, of the specified width, beginning with the -least significant digits.@refill - -The directives @code{.byte}, @code{.hword}, @code{.int}, @code{.long}, -@code{.short}, and @code{.word} accept bit-field arguments. -_fi__(_I960__&&!_GENERIC__) - -@node Sections, Symbols, Syntax, Top -@chapter Sections and Relocation -@cindex sections -@cindex relocation - -@menu -* Secs Background:: Background -* _LD__ Sections:: _LD__ Sections -* _AS__ Sections:: _AS__ Internal Sections -* Sub-Sections:: Sub-Sections -* bss:: bss Section -@end menu - -@node Secs Background, _LD__ Sections, Sections, Sections -@section Background - -Roughly, a section is a range of addresses, with no gaps; all data -``in'' those addresses is treated the same for some particular purpose. -For example there may be a ``read only'' section. - -@cindex linker, and assembler -@cindex assembler, and linker -The linker @code{_LD__} reads many object files (partial programs) and -combines their contents to form a runnable program. When @code{_AS__} -emits an object file, the partial program is assumed to start at address -0. @code{_LD__} will assign the final addresses the partial program -occupies, so that different partial programs don't overlap. This is -actually an over-simplification, but it will suffice to explain how -@code{_AS__} uses sections. - -@code{_LD__} moves blocks of bytes of your program to their run-time -addresses. These blocks slide to their run-time addresses as rigid -units; their length does not change and neither does the order of bytes -within them. Such a rigid unit is called a @emph{section}. Assigning -run-time addresses to sections is called @dfn{relocation}. It includes -the task of adjusting mentions of object-file addresses so they refer to -the proper run-time addresses. -_if__(_H8__) -For the H8/300, @code{_AS__} pads sections if needed to ensure they end -on a word (sixteen bit) boundary. -_fi__(_H8__) - -@cindex standard @code{_AS__} sections -An object file written by @code{_AS__} has at least three sections, any -of which may be empty. These are named @dfn{text}, @dfn{data} and -@dfn{bss} sections. - -_if__(_COFF__) -_if__(_GENERIC__) -When it generates COFF output, -_fi__(_GENERIC__) -@code{_AS__} can also generate whatever other named sections you specify -using the @samp{.section} directive (@pxref{Section,,@code{.section}}). -If you don't use any directives that place output in the @samp{.text} -or @samp{.data} sections, these sections will still exist, but will be empty. -_fi__(_COFF__) - -Within the object file, the text section starts at address @code{0}, the -data section follows, and the bss section follows the data section. - -To let @code{_LD__} know which data will change when the sections are -relocated, and how to change that data, @code{_AS__} also writes to the -object file details of the relocation needed. To perform relocation -@code{_LD__} must know, each time an address in the object -file is mentioned: -@itemize @bullet -@item -Where in the object file is the beginning of this reference to -an address? -@item -How long (in bytes) is this reference? -@item -Which section does the address refer to? What is the numeric value of -@display -(@var{address}) @minus{} (@var{start-address of section})? -@end display -@item -Is the reference to an address ``Program-Counter relative''? -@end itemize - -@cindex addresses, format of -@cindex section-relative addressing -In fact, every address @code{_AS__} ever uses is expressed as -@display -(@var{section}) + (@var{offset into section}) -@end display -@noindent -Further, every expression @code{_AS__} computes is of this section-relative -nature. @dfn{Absolute expression} means an expression with section -``absolute'' (@pxref{_LD__ Sections}). A @dfn{pass1 expression} means -an expression with section ``pass1'' (@pxref{_AS__ Sections,,_AS__ -Internal Sections}). In this manual we use the notation @{@var{secname} -@var{N}@} to mean ``offset @var{N} into section @var{secname}''. - -Apart from text, data and bss sections you need to know about the -@dfn{absolute} section. When @code{_LD__} mixes partial programs, -addresses in the absolute section remain unchanged. For example, address -@code{@{absolute 0@}} is ``relocated'' to run-time address 0 by @code{_LD__}. -Although two partial programs' data sections will not overlap addresses -after linking, @emph{by definition} their absolute sections will overlap. -Address @code{@{absolute@ 239@}} in one partial program will always be the same -address when the program is running as address @code{@{absolute@ 239@}} in any -other partial program. - -The idea of sections is extended to the @dfn{undefined} section. Any -address whose section is unknown at assembly time is by definition -rendered @{undefined @var{U}@}---where @var{U} will be filled in later. -Since numbers are always defined, the only way to generate an undefined -address is to mention an undefined symbol. A reference to a named -common block would be such a symbol: its value is unknown at assembly -time so it has section @emph{undefined}. - -By analogy the word @emph{section} is used to describe groups of sections in -the linked program. @code{_LD__} puts all partial programs' text -sections in contiguous addresses in the linked program. It is -customary to refer to the @emph{text section} of a program, meaning all -the addresses of all partial program's text sections. Likewise for -data and bss sections. - -Some sections are manipulated by @code{_LD__}; others are invented for -use of @code{_AS__} and have no meaning except during assembly. - -@node _LD__ Sections, _AS__ Sections, Secs Background, Sections -@section _LD__ Sections -@code{_LD__} deals with just four kinds of sections, summarized below. - -@table @strong - -_if__(_GENERIC__||_COFF__) -@cindex named sections -@cindex sections, named -@item named sections -_fi__(_GENERIC__||_COFF__) -_if__(_AOUT__||_BOUT__) -@cindex text section -@cindex data section -@item text section -@itemx data section -_fi__(_AOUT__||_BOUT__) -These sections hold your program. @code{_AS__} and @code{_LD__} treat them as -separate but equal sections. Anything you can say of one section is -true another. -_if__(_AOUT__||_BOUT__) -When the program is running, however, it is -customary for the text section to be unalterable. The -text section is often shared among processes: it will contain -instructions, constants and the like. The data section of a running -program is usually alterable: for example, C variables would be stored -in the data section. -_fi__(_AOUT__||_BOUT__) - -@cindex bss section -@item bss section -This section contains zeroed bytes when your program begins running. It -is used to hold unitialized variables or common storage. The length of -each partial program's bss section is important, but because it starts -out containing zeroed bytes there is no need to store explicit zero -bytes in the object file. The bss section was invented to eliminate -those explicit zeros from object files. - -@cindex absolute section -@item absolute section -Address 0 of this section is always ``relocated'' to runtime address 0. -This is useful if you want to refer to an address that @code{_LD__} must -not change when relocating. In this sense we speak of absolute -addresses being ``unrelocatable'': they don't change during relocation. - -@cindex undefined section -@item undefined section -This ``section'' is a catch-all for address references to objects not in -the preceding sections. -@c FIXME: ref to some other doc on obj-file formats could go here. -@end table - -@cindex relocation example -An idealized example of three relocatable sections follows. -_if__(_COFF__) -The example uses the traditional section names @samp{.text} and @samp{.data}. -_fi__(_COFF__) -Memory addresses are on the horizontal axis. - -@c TEXI2ROFF-KILL -@ifinfo -@c END TEXI2ROFF-KILL -@smallexample - +-----+----+--+ -partial program # 1: |ttttt|dddd|00| - +-----+----+--+ - - text data bss - seg. seg. seg. - - +---+---+---+ -partial program # 2: |TTT|DDD|000| - +---+---+---+ - - +--+---+-----+--+----+---+-----+~~ -linked program: | |TTT|ttttt| |dddd|DDD|00000| - +--+---+-----+--+----+---+-----+~~ - - addresses: 0 @dots{} -@end smallexample -@c TEXI2ROFF-KILL -@end ifinfo -@c FIXME make sure no page breaks inside figure!! -@tex - -\line{\it Partial program \#1: \hfil} -\line{\ibox{2.5cm}{\tt text}\ibox{2cm}{\tt data}\ibox{1cm}{\tt bss}\hfil} -\line{\boxit{2.5cm}{\tt ttttt}\boxit{2cm}{\tt dddd}\boxit{1cm}{\tt 00}\hfil} - -\line{\it Partial program \#2: \hfil} -\line{\ibox{1cm}{\tt text}\ibox{1.5cm}{\tt data}\ibox{1cm}{\tt bss}\hfil} -\line{\boxit{1cm}{\tt TTT}\boxit{1.5cm}{\tt DDDD}\boxit{1cm}{\tt 000}\hfil} - -\line{\it linked program: \hfil} -\line{\ibox{.5cm}{}\ibox{1cm}{\tt text}\ibox{2.5cm}{}\ibox{.75cm}{}\ibox{2cm}{\tt data}\ibox{1.5cm}{}\ibox{2cm}{\tt bss}\hfil} -\line{\boxit{.5cm}{}\boxit{1cm}{\tt TTT}\boxit{2.5cm}{\tt -ttttt}\boxit{.75cm}{}\boxit{2cm}{\tt dddd}\boxit{1.5cm}{\tt -DDDD}\boxit{2cm}{\tt 00000}\ \dots\hfil} - -\line{\it addresses: \hfil} -\line{0\dots\hfil} - -@end tex -@c END TEXI2ROFF-KILL - -@node _AS__ Sections, Sub-Sections, _LD__ Sections, Sections -@section _AS__ Internal Sections - -@cindex internal @code{_AS__} sections -@cindex sections in messages, internal -These sections are meant only for the internal use of @code{_AS__}. They -have no meaning at run-time. You don't really need to know about these -sections for most purposes; but they can be mentioned in @code{_AS__} -warning messages, so it might be helpful to have an idea of their -meanings to @code{_AS__}. These sections are used to permit the -value of every expression in your assembly language program to be a -section-relative address. - -@table @b -@item absent -@cindex absent (internal section) -An expression was expected and none was found. - -@item ASSEMBLER-INTERNAL-LOGIC-ERROR! -@cindex assembler internal logic error -An internal assembler logic error has been found. This means there is a -bug in the assembler. - -@item bignum/flonum -@cindex bignum/flonum (internal section) -If a number can't be written as a C @code{int} constant (a bignum or a -flonum, but not an integer), it is recorded as belonging to this -``section''. @code{_AS__} has to remember that a flonum or a bignum -does not fit into 32 bits, and cannot be an argument (@pxref{Arguments}) -in an expression: this is done by making a flonum or bignum be in a -separate internal section. This is purely for internal @code{_AS__} -convenience; bignum/flonum section behaves similarly to absolute -section. - -@item pass1 section -@cindex pass1 (internal section) -The expression was impossible to evaluate in the first pass. The -assembler will attempt a second pass (second reading of the source) to -evaluate the expression. Your expression mentioned an undefined symbol -in a way that defies the one-pass (section + offset in section) assembly -process. No compiler need emit such an expression. - -@quotation -@emph{Warning:} the second pass is currently not implemented. @code{_AS__} -will abort with an error message if one is required. -@end quotation - -@item difference section -@cindex difference (internal section) -As an assist to the C compiler, expressions of the forms -@display - (@var{undefined symbol}) @minus{} (@var{expression}) - @var{something} @minus{} (@var{undefined symbol}) - (@var{undefined symbol}) @minus{} (@var{undefined symbol}) -@end display - -are permitted, and belong to the difference section. @code{_AS__} -re-evaluates such expressions after the source file has been read and -the symbol table built. If by that time there are no undefined symbols -in the expression then the expression assumes a new section. The -intention is to permit statements like -@samp{.word label - base_of_table} -to be assembled in one pass where both @code{label} and -@code{base_of_table} are undefined. This is useful for compiling C and -Algol switch statements, Pascal case statements, FORTRAN computed goto -statements and the like. -@c FIXME item debug -@c FIXME item transfer[t] vector preload -@c FIXME item transfer[t] vector postload -@c FIXME item register -@end table - -@node Sub-Sections, bss, _AS__ Sections, Sections -@section Sub-Sections - -@cindex numbered subsections -@cindex grouping data -_if__(_AOUT__||_BOUT__) -Assembled bytes -_if__(_COFF__) -conventionally -_fi__(_COFF__) -fall into two sections: text and data. -_fi__(_AOUT__||_BOUT__) -You may have separate groups of -_if__(_COFF__||_GENERIC__) -data in named sections -_fi__(_COFF__||_GENERIC__) -_if__((_AOUT__||_BOUT__)&&!_GENERIC__) -text or data -_fi__((_AOUT__||_BOUT__)&&!_GENERIC__) -that you want to end up near to each other in the object -file, even though they are not contiguous in the assembler source. -@code{_AS__} allows you to use @dfn{subsections} for this purpose. -Within each section, there can be numbered subsections with -values from 0 to 8192. Objects assembled into the same subsection will -be grouped with other objects in the same subsection when they are all -put into the object file. For example, a compiler might want to store -constants in the text section, but might not want to have them -interspersed with the program being assembled. In this case, the -compiler could issue a @samp{.text 0} before each section of code being -output, and a @samp{.text 1} before each group of constants being output. - -Subsections are optional. If you don't use subsections, everything -will be stored in subsection number zero. - -_if__(_GENERIC__) -Each subsection is zero-padded up to a multiple of four bytes. -(Subsections may be padded a different amount on different flavors -of @code{_AS__}.) -_fi__(_GENERIC__) -_if__(!_GENERIC__) -_if__(_H8__) -On the H8/300 platform, each subsection is zero-padded to a word -boundary (two bytes). -_fi__(_H8__) -_if__(_I960__) -@c FIXME section padding (alignment)? -@c Rich Pixley says padding here depends on target obj code format; that -@c doesn't seem particularly useful to say without further elaboration, -@c so for now I say nothing about it. If this is a generic BFD issue, -@c these paragraphs might need to vanish from this manual, and be -@c discussed in BFD chapter of binutils (or some such). -_fi__(_I960__) -_if__(_A29K__) -On the AMD 29K family, no particular padding is added to section or -subsection sizes; _AS__ forces no alignment on this platform. -_fi__(_A29K__) -_fi__(!_GENERIC__) - -Subsections appear in your object file in numeric order, lowest numbered -to highest. (All this to be compatible with other people's assemblers.) -The object file contains no representation of subsections; @code{_LD__} and -other programs that manipulate object files will see no trace of them. -They just see all your text subsections as a text section, and all your -data subsections as a data section. - -To specify which subsection you want subsequent statements assembled -into, use a numeric argument to specify it, in a @samp{.text -@var{expression}} or a @samp{.data @var{expression}} statement. -_if__(_COFF__) -_if__(_GENERIC__) -When generating COFF output, you -_fi__(_GENERIC__) -_if__(!_GENERIC__) -You -_fi__(!_GENERIC__) -can also use an extra subsection -argument with arbitrary named sections: @samp{.section @var{name}, -@var{expression}}. -_fi__(_COFF__) -@var{Expression} should be an absolute expression. -(@xref{Expressions}.) If you just say @samp{.text} then @samp{.text 0} -is assumed. Likewise @samp{.data} means @samp{.data 0}. Assembly -begins in @code{text 0}. For instance: -@smallexample -.text 0 # The default subsection is text 0 anyway. -.ascii "This lives in the first text subsection. *" -.text 1 -.ascii "But this lives in the second text subsection." -.data 0 -.ascii "This lives in the data section," -.ascii "in the first data subsection." -.text 0 -.ascii "This lives in the first text section," -.ascii "immediately following the asterisk (*)." -@end smallexample - -Each section has a @dfn{location counter} incremented by one for every -byte assembled into that section. Because subsections are merely a -convenience restricted to @code{_AS__} there is no concept of a subsection -location counter. There is no way to directly manipulate a location -counter---but the @code{.align} directive will change it, and any label -definition will capture its current value. The location counter of the -section that statements are being assembled into is said to be the -@dfn{active} location counter. - -@node bss, , Sub-Sections, Sections -@section bss Section - -@cindex bss section -@cindex common variable storage -The bss section is used for local common variable storage. -You may allocate address space in the bss section, but you may -not dictate data to load into it before your program executes. When -your program starts running, all the contents of the bss -section are zeroed bytes. - -Addresses in the bss section are allocated with special directives; you -may not assemble anything directly into the bss section. Hence there -are no bss subsections. @xref{Comm,,@code{.comm}}, -@pxref{Lcomm,,@code{.lcomm}}. - -@node Symbols, Expressions, Sections, Top -@chapter Symbols - -@cindex symbols -Symbols are a central concept: the programmer uses symbols to name -things, the linker uses symbols to link, and the debugger uses symbols -to debug. - -@quotation -@cindex debuggers, and symbol order -@emph{Warning:} @code{_AS__} does not place symbols in the object file in -the same order they were declared. This may break some debuggers. -@end quotation - -@menu -* Labels:: Labels -* Setting Symbols:: Giving Symbols Other Values -* Symbol Names:: Symbol Names -* Dot:: The Special Dot Symbol -* Symbol Attributes:: Symbol Attributes -@end menu - -@node Labels, Setting Symbols, Symbols, Symbols -@section Labels - -@cindex labels -A @dfn{label} is written as a symbol immediately followed by a colon -@samp{:}. The symbol then represents the current value of the -active location counter, and is, for example, a suitable instruction -operand. You are warned if you use the same symbol to represent two -different locations: the first definition overrides any other -definitions. - -@node Setting Symbols, Symbol Names, Labels, Symbols -@section Giving Symbols Other Values - -@cindex assigning values to symbols -@cindex symbol values, assigning -A symbol can be given an arbitrary value by writing a symbol, followed -by an equals sign @samp{=}, followed by an expression -(@pxref{Expressions}). This is equivalent to using the @code{.set} -directive. @xref{Set,,@code{.set}}. - -@node Symbol Names, Dot, Setting Symbols, Symbols -@section Symbol Names - -@cindex symbol names -@cindex names, symbol -Symbol names begin with a letter or with one of -_if__(!_H8__) -@samp{_.$} -_fi__(!_H8__) -_if__(_H8__) -@samp{_.} -_if__(_GENERIC__) -(On most machines, you can also use @code{$} in symbol names; exceptions -are noted in @ref{_MACH_DEP__}.) -_fi__(_GENERIC__) -_fi__(_H8__) -That character may be followed by any string of digits, letters, -_if__(!_H8__) -underscores and dollar signs. -_fi__(!_H8__) -_if__(_H8__) -_if__(_GENERIC__) -dollar signs (unless otherwise noted in @ref{_MACH_DEP__}), -_fi__(_GENERIC__) -and underscores. -_fi__(_H8__) -Case of letters is significant: -@code{foo} is a different symbol name than @code{Foo}. - -_if__(_A29K__) -For the AMD 29K family, @samp{?} is also allowed in the -body of a symbol name, though not at its beginning. -_fi__(_A29K__) - -Each symbol has exactly one name. Each name in an assembly language -program refers to exactly one symbol. You may use that symbol name any -number of times in a program. - -@subheading Local Symbol Names - -@cindex local symbol names -@cindex symbol names, local -@cindex temporary symbol names -@cindex symbol names, temporary -Local symbols help compilers and programmers use names temporarily. -There are ten local symbol names, which are re-used throughout the -program. You may refer to them using the names @samp{0} @samp{1} -@dots{} @samp{9}. To define a local symbol, write a label of the form -@samp{@b{N}:} (where @b{N} represents any digit). To refer to the most -recent previous definition of that symbol write @samp{@b{N}b}, using the -same digit as when you defined the label. To refer to the next -definition of a local label, write @samp{@b{N}f}---where @b{N} gives you -a choice of 10 forward references. The @samp{b} stands for -``backwards'' and the @samp{f} stands for ``forwards''. - -Local symbols are not emitted by the current GNU C compiler. - -There is no restriction on how you can use these labels, but -remember that at any point in the assembly you can refer to at most -10 prior local labels and to at most 10 forward local labels. - -Local symbol names are only a notation device. They are immediately -transformed into more conventional symbol names before the assembler -uses them. The symbol names stored in the symbol table, appearing in -error messages and optionally emitted to the object file have these -parts: - -@table @code -@item L -All local labels begin with @samp{L}. Normally both @code{_AS__} and -@code{_LD__} forget symbols that start with @samp{L}. These labels are -used for symbols you are never intended to see. If you give the -@samp{-L} option then @code{_AS__} will retain these symbols in the -object file. If you also instruct @code{_LD__} to retain these symbols, -you may use them in debugging. - -@item @var{digit} -If the label is written @samp{0:} then the digit is @samp{0}. -If the label is written @samp{1:} then the digit is @samp{1}. -And so on up through @samp{9:}. - -@item @ctrl{A} -This unusual character is included so you don't accidentally invent -a symbol of the same name. The character has ASCII value -@samp{\001}. - -@item @emph{ordinal number} -This is a serial number to keep the labels distinct. The first -@samp{0:} gets the number @samp{1}; The 15th @samp{0:} gets the -number @samp{15}; @emph{etc.}. Likewise for the other labels @samp{1:} -through @samp{9:}. -@end table - -For instance, the first @code{1:} is named @code{L1@ctrl{A}1}, the 44th -@code{3:} is named @code{L3@ctrl{A}44}. - -@node Dot, Symbol Attributes, Symbol Names, Symbols -@section The Special Dot Symbol - -@cindex dot (symbol) -@cindex @code{.} (symbol) -@cindex current address -@cindex location counter -The special symbol @samp{.} refers to the current address that -@code{_AS__} is assembling into. Thus, the expression @samp{melvin: -.long .} will cause @code{melvin} to contain its own address. -Assigning a value to @code{.} is treated the same as a @code{.org} -directive. Thus, the expression @samp{.=.+4} is the same as saying -_if__(!_A29K__) -@samp{.space 4}. -_fi__(!_A29K__) -_if__(_A29K__) -@samp{.block 4}. -_fi__(_A29K__) - -@node Symbol Attributes, , Dot, Symbols -@section Symbol Attributes - -@cindex symbol attributes -@cindex attributes, symbol -Every symbol has, as well as its name, the attributes ``Value'' and -``Type''. Depending on output format, symbols can also have auxiliary -attributes. -_if__(_INTERNALS__) -The detailed definitions are in _0___1__. -_fi__(_INTERNALS__) - -If you use a symbol without defining it, @code{_AS__} assumes zero for -all these attributes, and probably won't warn you. This makes the -symbol an externally defined symbol, which is generally what you -would want. - -@menu -* Symbol Value:: Value -* Symbol Type:: Type -_if__(_AOUT__||_BOUT__) -_if__(_GENERIC__||!_BOUT__) -* a.out Symbols:: Symbol Attributes: @code{a.out} -_fi__(_GENERIC__||!_BOUT__) -_if__(_BOUT__&&!_GENERIC__) -* a.out Symbols:: Symbol Attributes: @code{a.out}, @code{b.out} -_fi__(_BOUT__&&!_GENERIC__) -_fi__(_AOUT__||_BOUT__) -_if__(_COFF__) -* COFF Symbols:: Symbol Attributes for COFF -_fi__(_COFF__) -@end menu - -@node Symbol Value, Symbol Type, Symbol Attributes, Symbol Attributes -@subsection Value - -@cindex value of a symbol -@cindex symbol value -The value of a symbol is (usually) 32 bits. For a symbol which labels a -location in the text, data, bss or absolute sections the value is the -number of addresses from the start of that section to the label. -Naturally for text, data and bss sections the value of a symbol changes -as @code{_LD__} changes section base addresses during linking. Absolute -symbols' values do not change during linking: that is why they are -called absolute. - -The value of an undefined symbol is treated in a special way. If it is -0 then the symbol is not defined in this assembler source program, and -@code{_LD__} will try to determine its value from other programs it is -linked with. You make this kind of symbol simply by mentioning a symbol -name without defining it. A non-zero value represents a @code{.comm} -common declaration. The value is how much common storage to reserve, in -bytes (addresses). The symbol refers to the first address of the -allocated storage. - -_if__(!(_AOUT__||_BOUT__)) -@node Symbol Type, COFF Symbols, Symbol Value, Symbol Attributes -_fi__(!(_AOUT__||_BOUT__)) -_if__((_AOUT__||_BOUT__)) -@node Symbol Type, a.out Symbols, Symbol Value, Symbol Attributes -_fi__((_AOUT__||_BOUT__)) -@subsection Type - -@cindex type of a symbol -@cindex symbol type -The type attribute of a symbol contains relocation (section) -information, any flag settings indicating that a symbol is external, and -(optionally), other information for linkers and debuggers. The exact -format depends on the object-code output format in use. - -_if__(_AOUT__||_BOUT__) -_if__(_COFF__) -@node a.out Symbols, COFF Symbols, Symbol Type, Symbol Attributes -_fi__(_COFF__) -_if__(!_COFF__) -@node a.out Symbols, , Symbol Type, Symbol Attributes -_fi__(!_COFF__) -_if__(_BOUT__&&!_GENERIC__) -@subsection Symbol Attributes: @code{a.out}, @code{b.out} - -@cindex @code{b.out} symbol attributes -@cindex symbol attributes, @code{b.out} -These symbol attributes appear only when @code{_AS__} is configured for -one of the Berkeley-descended object output formats. -_fi__(_BOUT__&&!_GENERIC__) -_if__(_GENERIC__||!_BOUT__) -@subsection Symbol Attributes: @code{a.out} -_fi__(_GENERIC__||!_BOUT__) - -@cindex @code{a.out} symbol attributes -@cindex symbol attributes, @code{a.out} - -@menu -* Symbol Desc:: Descriptor -* Symbol Other:: Other -@end menu - -@node Symbol Desc, Symbol Other, a.out Symbols, a.out Symbols -@subsubsection Descriptor - -@cindex descriptor, of @code{a.out} symbol -This is an arbitrary 16-bit value. You may establish a symbol's -descriptor value by using a @code{.desc} statement -(@pxref{Desc,,@code{.desc}}). A descriptor value means nothing to -@code{_AS__}. - -@node Symbol Other, , Symbol Desc, a.out Symbols -@subsubsection Other - -@cindex other attribute, of @code{a.out} symbol -This is an arbitrary 8-bit value. It means nothing to @code{_AS__}. -_fi__(_AOUT__||_BOUT__) - -_if__(_COFF__) -_if__(!(_AOUT__||_BOUT__)) -@node COFF Symbols, , Symbol Type, Symbol Attributes -_fi__(!(_AOUT__||_BOUT__)) -_if__(_AOUT__||_BOUT__) -@node COFF Symbols, , a.out Symbols, Symbol Attributes -_fi__(_AOUT__||_BOUT__) -@subsection Symbol Attributes for COFF - -@cindex COFF symbol attributes -@cindex symbol attributes, COFF - -The COFF format supports a multitude of auxiliary symbol attributes; -like the primary symbol attributes, they are set between @code{.def} and -@code{.endef} directives. - -@subsubsection Primary Attributes - -@cindex primary attributes, COFF symbols -The symbol name is set with @code{.def}; the value and type, -respectively, with @code{.val} and @code{.type}. - -@subsubsection Auxiliary Attributes - -@cindex auxiliary attributes, COFF symbols -The @code{_AS__} directives @code{.dim}, @code{.line}, @code{.scl}, -@code{.size}, and @code{.tag} can generate auxiliary symbol table -information for COFF. -_fi__(_COFF__) - -@node Expressions, Pseudo Ops, Symbols, Top -@chapter Expressions - -@cindex expressions -@cindex addresses -@cindex numeric values -An @dfn{expression} specifies an address or numeric value. -Whitespace may precede and/or follow an expression. - -@menu -* Empty Exprs:: Empty Expressions -* Integer Exprs:: Integer Expressions -@end menu - -@node Empty Exprs, Integer Exprs, Expressions, Expressions -@section Empty Expressions - -@cindex empty expressions -@cindex expressions, empty -An empty expression has no value: it is just whitespace or null. -Wherever an absolute expression is required, you may omit the -expression and @code{_AS__} will assume a value of (absolute) 0. This -is compatible with other assemblers. - -@node Integer Exprs, , Empty Exprs, Expressions -@section Integer Expressions - -@cindex integer expressions -@cindex expressions, integer -An @dfn{integer expression} is one or more @emph{arguments} delimited -by @emph{operators}. - -@menu -* Arguments:: Arguments -* Operators:: Operators -* Prefix Ops:: Prefix Operators -* Infix Ops:: Infix Operators -@end menu - -@node Arguments, Operators, Integer Exprs, Integer Exprs -@subsection Arguments - -@cindex expression arguments -@cindex arguments in expressions -@cindex operands in expressions -@cindex arithmetic operands -@dfn{Arguments} are symbols, numbers or subexpressions. In other -contexts arguments are sometimes called ``arithmetic operands''. In -this manual, to avoid confusing them with the ``instruction operands'' of -the machine language, we use the term ``argument'' to refer to parts of -expressions only, reserving the word ``operand'' to refer only to machine -instruction operands. - -Symbols are evaluated to yield @{@var{section} @var{NNN}@} where -@var{section} is one of text, data, bss, absolute, -or undefined. @var{NNN} is a signed, 2's complement 32 bit -integer. - -Numbers are usually integers. - -A number can be a flonum or bignum. In this case, you are warned -that only the low order 32 bits are used, and @code{_AS__} pretends -these 32 bits are an integer. You may write integer-manipulating -instructions that act on exotic constants, compatible with other -assemblers. - -@cindex subexpressions -Subexpressions are a left parenthesis @samp{(} followed by an integer -expression, followed by a right parenthesis @samp{)}; or a prefix -operator followed by an argument. - -@node Operators, Prefix Ops, Arguments, Integer Exprs -@subsection Operators - -@cindex operators, in expressions -@cindex arithmetic functions -@cindex functions, in expressions -@dfn{Operators} are arithmetic functions, like @code{+} or @code{%}. Prefix -operators are followed by an argument. Infix operators appear -between their arguments. Operators may be preceded and/or followed by -whitespace. - -@node Prefix Ops, Infix Ops, Operators, Integer Exprs -@subsection Prefix Operator - -@cindex prefix operators -@code{_AS__} has the following @dfn{prefix operators}. They each take -one argument, which must be absolute. - -@c the tex/end tex stuff surrounding this small table is meant to make -@c it align, on the printed page, with the similar table in the next -@c section (which is inside an enumerate). -@tex -\global\advance\leftskip by \itemindent -@end tex - -@table @code -@item - -@dfn{Negation}. Two's complement negation. -@item ~ -@dfn{Complementation}. Bitwise not. -@end table - -@tex -\global\advance\leftskip by -\itemindent -@end tex - -@node Infix Ops, , Prefix Ops, Integer Exprs -@subsection Infix Operators - -@cindex infix operators -@cindex operators, permitted arguments -@dfn{Infix operators} take two arguments, one on either side. Operators -have precedence, but operations with equal precedence are performed left -to right. Apart from @code{+} or @code{-}, both arguments must be -absolute, and the result is absolute. - -@enumerate -@cindex operator precedence -@cindex precedence of operators - -@item -Highest Precedence - -@table @code -@item * -@dfn{Multiplication}. - -@item / -@dfn{Division}. Truncation is the same as the C operator @samp{/} - -@item % -@dfn{Remainder}. - -@item _0__<_1__ -@itemx _0__<<_1__ -@dfn{Shift Left}. Same as the C operator @samp{_0__<<_1__} - -@item _0__>_1__ -@itemx _0__>>_1__ -@dfn{Shift Right}. Same as the C operator @samp{_0__>>_1__} -@end table - -@item -Intermediate precedence - -@table @code -@item | - -@dfn{Bitwise Inclusive Or}. - -@item & -@dfn{Bitwise And}. - -@item ^ -@dfn{Bitwise Exclusive Or}. - -@item ! -@dfn{Bitwise Or Not}. -@end table - -@item -Lowest Precedence - -@table @code -@item + -@cindex addition, permitted arguments -@cindex plus, permitted arguments -@cindex arguments for addition -@dfn{Addition}. If either argument is absolute, the result -has the section of the other argument. -If either argument is pass1 or undefined, the result is pass1. -Otherwise @code{+} is illegal. - -@item - -@cindex subtraction, permitted arguments -@cindex minus, permitted arguments -@cindex arguments for subtraction -@dfn{Subtraction}. If the right argument is absolute, the -result has the section of the left argument. -If either argument is pass1 the result is pass1. -If either argument is undefined the result is difference section. -If both arguments are in the same section, the result is absolute---provided -that section is one of text, data or bss. -Otherwise subtraction is illegal. -@end table -@end enumerate - -The sense of the rule for addition is that it's only meaningful to add -the @emph{offsets} in an address; you can only have a defined section in -one of the two arguments. - -Similarly, you can't subtract quantities from two different sections. - -@node Pseudo Ops, _MACH_DEP__, Expressions, Top -@chapter Assembler Directives - -@cindex directives, machine independent -@cindex pseudo-ops, machine independent -@cindex machine independent directives -All assembler directives have names that begin with a period (@samp{.}). -The rest of the name is letters, usually in lower case. - -This chapter discusses directives present regardless of the target -machine configuration for the GNU assembler. -_if__(!_H8__) -@xref{_MACH_DEP__} for additional directives. -_fi__(!_H8__) - -@menu -* Abort:: @code{.abort} -_if__(_COFF__) -* coff-ABORT:: @code{.ABORT} -_fi__(_COFF__) -_if__(_BOUT__&&!_COFF__) -* bout-ABORT:: @code{.ABORT} -_fi__(_BOUT__&&!_COFF__) -* Align:: @code{.align @var{abs-expr} , @var{abs-expr}} -* App-File:: @code{.app-file @var{string}} -* Ascii:: @code{.ascii "@var{string}"}@dots{} -* Asciz:: @code{.asciz "@var{string}"}@dots{} -* Byte:: @code{.byte @var{expressions}} -* Comm:: @code{.comm @var{symbol} , @var{length} } -* Data:: @code{.data @var{subsection}} -_if__(_COFF__||_BOUT__) -* Def:: @code{.def @var{name}} -_fi__(_COFF__||_BOUT__) -_if__(_AOUT__||_BOUT__) -* Desc:: @code{.desc @var{symbol}, @var{abs-expression}} -_fi__(_AOUT__||_BOUT__) -_if__(_COFF__||_BOUT__) -* Dim:: @code{.dim} -_fi__(_COFF__||_BOUT__) -* Double:: @code{.double @var{flonums}} -* Eject:: @code{.eject} -* Else:: @code{.else} -_if__(_COFF__||_BOUT__) -* Endef:: @code{.endef} -_fi__(_COFF__||_BOUT__) -* Endif:: @code{.endif} -* Equ:: @code{.equ @var{symbol}, @var{expression}} -* Extern:: @code{.extern} -_if__(_GENERIC__||!_A29K__) -* File:: @code{.file @var{string}} -_fi__(_GENERIC__||!_A29K__) -* Fill:: @code{.fill @var{repeat} , @var{size} , @var{value}} -* Float:: @code{.float @var{flonums}} -* Global:: @code{.global @var{symbol}}, @code{.globl @var{symbol}} -* hword:: @code{.hword @var{expressions}} -* Ident:: @code{.ident} -* If:: @code{.if @var{absolute expression}} -* Include:: @code{.include "@var{file}"} -* Int:: @code{.int @var{expressions}} -* Lcomm:: @code{.lcomm @var{symbol} , @var{length}} -* Lflags:: @code{.lflags} -_if__(_GENERIC__||!_A29K__) -* Line:: @code{.line @var{line-number}} -_fi__(_GENERIC__||!_A29K__) -* Ln:: @code{.ln @var{line-number}} -* List:: @code{.list} -* Long:: @code{.long @var{expressions}} -* Lsym:: @code{.lsym @var{symbol}, @var{expression}} -* Nolist:: @code{.nolist} -* Octa:: @code{.octa @var{bignums}} -* Org:: @code{.org @var{new-lc} , @var{fill}} -* Psize:: @code{.psize @var{lines}, @var{columns}} -* Quad:: @code{.quad @var{bignums}} -* Sbttl:: @code{.sbttl "@var{subheading}"} -_if__(_COFF__||_BOUT__) -* Scl:: @code{.scl @var{class}} -_fi__(_COFF__||_BOUT__) -_if__(_COFF__) -* Section:: @code{.section @var{name}, @var{subsection}} -_fi__(_COFF__) -* Set:: @code{.set @var{symbol}, @var{expression}} -* Short:: @code{.short @var{expressions}} -* Single:: @code{.single @var{flonums}} -_if__(_COFF__||_BOUT__) -* Size:: @code{.size} -_fi__(_COFF__||_BOUT__) -* Space:: @code{.space @var{size} , @var{fill}} -_if__(_GENERIC__||!_H8__) -* Stab:: @code{.stabd, .stabn, .stabs} -_fi__(_GENERIC__||!_H8__) -_if__(_COFF__||_BOUT__) -* Tag:: @code{.tag @var{structname}} -_fi__(_COFF__||_BOUT__) -* Text:: @code{.text @var{subsection}} -* Title:: @code{.title "@var{heading}"} -_if__(_COFF__||_BOUT__) -* Type:: @code{.type @var{int}} -* Val:: @code{.val @var{addr}} -_fi__(_COFF__||_BOUT__) -* Word:: @code{.word @var{expressions}} -* Deprecated:: Deprecated Directives -@end menu - -_if__(_COFF__) -@node Abort, coff-ABORT, Pseudo Ops, Pseudo Ops -_fi__(_COFF__) -_if__((!_COFF__) && _BOUT__) -@node Abort, bout-ABORT, Pseudo Ops, Pseudo Ops -_fi__((!_COFF__) && _BOUT__) -_if__(! (_BOUT__ || _COFF__) ) -@node Abort, Align, Pseudo Ops, Pseudo Ops -_fi__(! (_BOUT__ || _COFF__) ) -@section @code{.abort} - -@cindex @code{abort} directive -@cindex stopping the assembly -This directive stops the assembly immediately. It is for -compatibility with other assemblers. The original idea was that the -assembly language source would be piped into the assembler. If the sender -of the source quit, it could use this directive tells @code{_AS__} to -quit also. One day @code{.abort} will not be supported. - -_if__(_COFF__) -@node coff-ABORT, Align, Abort, Pseudo Ops -@section @code{.ABORT} - -@cindex @code{ABORT} directive -When producing COFF output, @code{_AS__} accepts this directive as a -synonym for @samp{.abort}. -_fi__(_COFF__) - -_if__(_BOUT__) -_if__(!_COFF__) -@node bout-ABORT, Align, Abort, Pseudo Ops -@section @code{.ABORT} - -@cindex @code{ABORT} directive -_fi__(!_COFF__) - -When producing @code{b.out} output, @code{_AS__} accepts this directive, -but ignores it. -_fi__(_BOUT__) - -_if__( ! (_COFF__ || _BOUT__) ) -@node Align, App-File, Abort, Pseudo Ops -_fi__( ! (_COFF__ || _BOUT__) ) -_if__( _COFF__) -@node Align, App-File, coff-ABORT, Pseudo Ops -_fi__( _COFF__) -_if__( _BOUT__ && (! _COFF__)) -@node Align, App-File, bout-ABORT, Pseudo Ops -_fi__( _BOUT__ && (! _COFF__)) -@section @code{.align @var{abs-expr} , @var{abs-expr}} - -@cindex padding the location counter -@cindex advancing location counter -@cindex location counter, advancing -@cindex @code{align} directive -Pad the location counter (in the current subsection) to a particular -storage boundary. The first expression (which must be absolute) is the -number of low-order zero bits the location counter will have after -advancement. For example @samp{.align 3} will advance the location -counter until it a multiple of 8. If the location counter is already a -multiple of 8, no change is needed. - -The second expression (also absolute) gives the value to be stored in -the padding bytes. It (and the comma) may be omitted. If it is -omitted, the padding bytes are zero. - -@node App-File, Ascii, Align, Pseudo Ops -@section @code{.app-file @var{string}} - -@cindex logical file name -@cindex file name, logical -@cindex @code{app-file} directive -@code{.app-file} -_if__(!_A29K__) -(which may also be spelled @samp{.file}) -_fi__(!_A29K__) -tells @code{_AS__} that we are about to start a new -logical file. @var{string} is the new file name. In general, the -filename is recognized whether or not it is surrounded by quotes @samp{"}; -but if you wish to specify an empty file name is permitted, -you must give the quotes--@code{""}. This statement may go away in -future: it is only recognized to be compatible with old @code{_AS__} -programs.@refill - -@node Ascii, Asciz, App-File, Pseudo Ops -@section @code{.ascii "@var{string}"}@dots{} - -@cindex @code{ascii} directive -@cindex string literals -@code{.ascii} expects zero or more string literals (@pxref{Strings}) -separated by commas. It assembles each string (with no automatic -trailing zero byte) into consecutive addresses. - -@node Asciz, Byte, Ascii, Pseudo Ops -@section @code{.asciz "@var{string}"}@dots{} - -@cindex @code{asciz} directive -@cindex zero-terminated strings -@cindex null-terminated strings -@code{.asciz} is just like @code{.ascii}, but each string is followed by -a zero byte. The ``z'' in @samp{.asciz} stands for ``zero''. - -@node Byte, Comm, Asciz, Pseudo Ops -@section @code{.byte @var{expressions}} - -@cindex @code{byte} directive -@cindex integers, one byte -@code{.byte} expects zero or more expressions, separated by commas. -Each expression is assembled into the next byte. - -@node Comm, Data, Byte, Pseudo Ops -@section @code{.comm @var{symbol} , @var{length} } - -@cindex @code{comm} directive -@cindex symbol, common -@code{.comm} declares a named common area in the bss section. Normally -@code{_LD__} reserves memory addresses for it during linking, so no partial -program defines the location of the symbol. Use @code{.comm} to tell -@code{_LD__} that it must be at least @var{length} bytes long. @code{_LD__} -will allocate space for each @code{.comm} symbol that is at least as -long as the longest @code{.comm} request in any of the partial programs -linked. @var{length} is an absolute expression. - -_if__(_COFF__ || _BOUT__) -@node Data, Def, Comm, Pseudo Ops -_fi__(_COFF__ || _BOUT__) -_if__(!(_COFF__ || _BOUT__) && _AOUT__) -@node Data, Desc, Comm, Pseudo Ops -_fi__(!(_COFF__ || _BOUT__) && _AOUT__) -_if__(! (_COFF__ || _BOUT__ || _AOUT__) ) -@c Well, this *might* happen... -@node Data, Double, Comm, Pseudo Ops -_fi__(! (_COFF__ || _BOUT__ || _AOUT__) ) -@section @code{.data @var{subsection}} - -@cindex @code{data} directive -@code{.data} tells @code{_AS__} to assemble the following statements onto the -end of the data subsection numbered @var{subsection} (which is an -absolute expression). If @var{subsection} is omitted, it defaults -to zero. - -_if__(_COFF__ || _BOUT__) -_if__(_AOUT__ || _BOUT__) -@node Def, Desc, Data, Pseudo Ops -_fi__(_AOUT__ || _BOUT__) -_if__(!(_AOUT__ || _BOUT__)) -@node Def, Dim, Data, Pseudo Ops -_fi__(!(_AOUT__ || _BOUT__)) -@section @code{.def @var{name}} - -@cindex @code{def} directive -@cindex COFF symbols, debugging -@cindex debugging COFF symbols -Begin defining debugging information for a symbol @var{name}; the -definition extends until the @code{.endef} directive is encountered. -_if__(_BOUT__) - -This directive is only observed when @code{_AS__} is configured for COFF -format output; when producing @code{b.out}, @samp{.def} is recognized, -but ignored. -_fi__(_BOUT__) -_fi__(_COFF__ || _BOUT__) - -_if__(_AOUT__||_BOUT__) -_if__(_COFF__||_BOUT__) -@node Desc, Dim, Def, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Desc, Double, Data, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.desc @var{symbol}, @var{abs-expression}} - -@cindex @code{desc} directive -@cindex COFF symbol descriptor -@cindex symbol descriptor, COFF -This directive sets the descriptor of the symbol (@pxref{Symbol Attributes}) -to the low 16 bits of an absolute expression. - -_if__(_COFF__) -The @samp{.desc} directive is not available when @code{_AS__} is -configured for COFF output; it is only for @code{a.out} or @code{b.out} -object format. For the sake of compatibility, @code{_AS__} will accept -it, but produce no output, when configured for COFF. -_fi__(_COFF__) -_fi__(_AOUT__||_BOUT__) - -_if__(_COFF__ || _BOUT__) -_if__(_AOUT__ || _BOUT__) -@node Dim, Double, Desc, Pseudo Ops -_fi__(_AOUT__ || _BOUT__) -_if__(!(_AOUT__ || _BOUT__)) -@node Dim, Double, Def, Pseudo Ops -_fi__(!(_AOUT__ || _BOUT__)) -@section @code{.dim} - -@cindex @code{dim} directive -@cindex COFF auxiliary symbol information -@cindex auxiliary symbol information, COFF -This directive is generated by compilers to include auxiliary debugging -information in the symbol table. It is only permitted inside -@code{.def}/@code{.endef} pairs. -_if__(_BOUT__) - -@samp{.dim} is only meaningful when generating COFF format output; when -@code{_AS__} is generating @code{b.out}, it accepts this directive but -ignores it. -_fi__(_BOUT__) -_fi__(_COFF__ || _BOUT__) - -_if__(_COFF__||_BOUT__) -@node Double, Eject, Dim, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Double, Eject, Desc, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.double @var{flonums}} - -@cindex @code{double} directive -@cindex floating point numbers (double) -@code{.double} expects zero or more flonums, separated by commas. It -assembles floating point numbers. -_if__(_GENERIC__) -The exact kind of floating point numbers emitted depends on how -@code{_AS__} is configured. @xref{_MACH_DEP__}. -_fi__(_GENERIC__) -_if__((!_GENERIC__) && _IEEEFLOAT__) -On the _HOST__ family @samp{.double} emits 64-bit floating-point numbers -in @sc{ieee} format. -_fi__((!_GENERIC__) && _IEEEFLOAT__) - -@node Eject, Else, Double, Pseudo Ops -@section @code{.eject} - -@cindex @code{eject} directive -@cindex new page, in listings -@cindex page, in listings -@cindex listing control: new page -Force a page break at this point, when generating assembly listings. - -_if__(_COFF__||_BOUT__) -@node Else, Endef, Eject, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Else, Endif, Eject, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.else} - -@cindex @code{else} directive -@code{.else} is part of the @code{_AS__} support for conditional -assembly; @pxref{If,,@code{.if}}. It marks the beginning of a section -of code to be assembled if the condition for the preceding @code{.if} -was false. - -_if__(0) -@node End, Endef, Else, Pseudo Ops -@section @code{.end} - -@cindex @code{end} directive -This doesn't do anything---but isn't an s_ignore, so I suspect it's -meant to do something eventually (which is why it isn't documented here -as "for compatibility with blah"). -_fi__(0) - -_if__(_COFF__||_BOUT__) -@node Endef, Endif, Else, Pseudo Ops -@section @code{.endef} - -@cindex @code{endef} directive -This directive flags the end of a symbol definition begun with -@code{.def}. -_if__(_BOUT__) - -@samp{.endef} is only meaningful when generating COFF format output; if -@code{_AS__} is configured to generate @code{b.out}, it accepts this -directive but ignores it. -_fi__(_BOUT__) -_fi__(_COFF__||_BOUT__) - -_if__(_COFF__||_BOUT__) -@node Endif, Equ, Endef, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Endif, Equ, Else, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.endif} - -@cindex @code{endif} directive -@code{.endif} is part of the @code{_AS__} support for conditional assembly; -it marks the end of a block of code that is only assembled -conditionally. @xref{If,,@code{.if}}. - -@node Equ, Extern, Endif, Pseudo Ops -@section @code{.equ @var{symbol}, @var{expression}} - -@cindex @code{equ} directive -@cindex assigning values to symbols -@cindex symbols, assigning values to -This directive sets the value of @var{symbol} to @var{expression}. -It is synonymous with @samp{.set}; @pxref{Set,,@code{.set}}. - -_if__(_GENERIC__||!_A29K__) -@node Extern, File, Equ, Pseudo Ops -_fi__(_GENERIC__||!_A29K__) -_if__(_A29K__&&!_GENERIC__) -@node Extern, Fill, Equ, Pseudo Ops -_fi__(_A29K__&&!_GENERIC__) -@section @code{.extern} - -@cindex @code{extern} directive -@code{.extern} is accepted in the source program---for compatibility -with other assemblers---but it is ignored. @code{_AS__} treats -all undefined symbols as external. - -_if__(_GENERIC__||!_A29K__) -@node File, Fill, Extern, Pseudo Ops -@section @code{.file @var{string}} - -@cindex @code{file} directive -@cindex logical file name -@cindex file name, logical -@code{.file} (which may also be spelled @samp{.app-file}) tells -@code{_AS__} that we are about to start a new logical file. -@var{string} is the new file name. In general, the filename is -recognized whether or not it is surrounded by quotes @samp{"}; but if -you wish to specify an empty file name, you must give the -quotes--@code{""}. This statement may go away in future: it is only -recognized to be compatible with old @code{_AS__} programs. -_if__(_A29K__) -In some configurations of @code{_AS__}, @code{.file} has already been -removed to avoid conflicts with other assemblers. @xref{_MACH_DEP__}. -_fi__(_A29K__) -_fi__(_GENERIC__||!_A29K__) - -_if__(_GENERIC__||!_A29K__) -@node Fill, Float, File, Pseudo Ops -_fi__(_GENERIC__||!_A29K__) -_if__(_A29K__&&!_GENERIC__) -@node Fill, Float, Extern, Pseudo Ops -_fi__(_A29K__&&!_GENERIC__) -@section @code{.fill @var{repeat} , @var{size} , @var{value}} - -@cindex @code{fill} directive -@cindex writing patterns in memory -@cindex patterns, writing in memory -@var{result}, @var{size} and @var{value} are absolute expressions. -This emits @var{repeat} copies of @var{size} bytes. @var{Repeat} -may be zero or more. @var{Size} may be zero or more, but if it is -more than 8, then it is deemed to have the value 8, compatible with -other people's assemblers. The contents of each @var{repeat} bytes -is taken from an 8-byte number. The highest order 4 bytes are -zero. The lowest order 4 bytes are @var{value} rendered in the -byte-order of an integer on the computer @code{_AS__} is assembling for. -Each @var{size} bytes in a repetition is taken from the lowest order -@var{size} bytes of this number. Again, this bizarre behavior is -compatible with other people's assemblers. - -@var{size} and @var{value} are optional. -If the second comma and @var{value} are absent, @var{value} is -assumed zero. If the first comma and following tokens are absent, -@var{size} is assumed to be 1. - -@node Float, Global, Fill, Pseudo Ops -@section @code{.float @var{flonums}} - -@cindex floating point numbers (single) -@cindex @code{float} directive -This directive assembles zero or more flonums, separated by commas. It -has the same effect as @code{.single}. -_if__(_GENERIC__) -The exact kind of floating point numbers emitted depends on how -@code{_AS__} is configured. -@xref{_MACH_DEP__}. -_fi__(_GENERIC__) -_if__((!_GENERIC__) && _IEEEFLOAT__) -On the _HOST__ family, @code{.float} emits 32-bit floating point numbers -in @sc{ieee} format. -_fi__((!_GENERIC__) && _IEEEFLOAT__) - -@node Global, hword, Float, Pseudo Ops -@section @code{.global @var{symbol}}, @code{.globl @var{symbol}} - -@cindex @code{global} directive -@cindex symbol, making visible to linker -@code{.global} makes the symbol visible to @code{_LD__}. If you define -@var{symbol} in your partial program, its value is made available to -other partial programs that are linked with it. Otherwise, -@var{symbol} will take its attributes from a symbol of the same name -from another partial program it is linked with. - -Both spellings (@samp{.globl} and @samp{.global}) are accepted, for -compatibility with other assemblers. - -_if__(_AOUT__||_BOUT__||_COFF__) -@node hword, Ident, Global, Pseudo Ops -_fi__(_AOUT__||_BOUT__||_COFF__) -_if__(!(_AOUT__||_BOUT__||_COFF__)) -@node hword, If, Global, Pseudo Ops -_fi__(!(_AOUT__||_BOUT__||_COFF__)) -@section @code{.hword @var{expressions}} - -@cindex @code{hword} directive -@cindex integers, 16-bit -@cindex numbers, 16-bit -@cindex sixteen bit integers -This expects zero or more @var{expressions}, and emits -a 16 bit number for each. - -_if__(_GENERIC__) -This directive is a synonym for @samp{.short}; depending on the target -architecture, it may also be a synonym for @samp{.word}. -_fi__(_GENERIC__) -_if__( _W32__ && !_GENERIC__ ) -This directive is a synonym for @samp{.short}. -_fi__( _W32__ && !_GENERIC__ ) -_if__(_W16__ && !_GENERIC__ ) -This directive is a synonym for both @samp{.short} and @samp{.word}. -_fi__(_W16__ && !_GENERIC__ ) - -_if__(_AOUT__||_BOUT__||_COFF__) -@node Ident, If, hword, Pseudo Ops -@section @code{.ident} - -@cindex @code{ident} directive -This directive is used by some assemblers to place tags in object files. -@code{_AS__} simply accepts the directive for source-file -compatibility with such assemblers, but does not actually emit anything -for it. -_fi__(_AOUT__||_BOUT__||_COFF__) - -_if__(_AOUT__||_BOUT__||_COFF__) -@node If, Include, Ident, Pseudo Ops -_fi__(_AOUT__||_BOUT__||_COFF__) -_if__(!(_AOUT__||_BOUT__||_COFF__)) -@node If, Include, hword, Pseudo Ops -_fi__(!(_AOUT__||_BOUT__||_COFF__)) -@section @code{.if @var{absolute expression}} - -@cindex conditional assembly -@cindex @code{if} directive -@code{.if} marks the beginning of a section of code which is only -considered part of the source program being assembled if the argument -(which must be an @var{absolute expression}) is non-zero. The end of -the conditional section of code must be marked by @code{.endif} -(@pxref{Endif,,@code{.endif}}); optionally, you may include code for the -alternative condition, flagged by @code{.else} (@pxref{Else,,@code{.else}}. - -The following variants of @code{.if} are also supported: -@table @code -@item .ifdef @var{symbol} -@cindex @code{ifdef} directive -Assembles the following section of code if the specified @var{symbol} -has been defined. - -_if__(0) -@item .ifeqs -@cindex @code{ifeqs} directive -Not yet implemented. -_fi__(0) - -@item .ifndef @var{symbol} -@itemx ifnotdef @var{symbol} -@cindex @code{ifndef} directive -@cindex @code{ifnotdef} directive -Assembles the following section of code if the specified @var{symbol} -has not been defined. Both spelling variants are equivalent. - -_if__(0) -@item ifnes -Not yet implemented. -_fi__(0) -@end table - -@node Include, Int, If, Pseudo Ops -@section @code{.include "@var{file}"} - -@cindex @code{include} directive -@cindex supporting files, including -@cindex files, including -This directive provides a way to include supporting files at specified -points in your source program. The code from @var{file} is assembled as -if it followed the point of the @code{.include}; when the end of the -included file is reached, assembly of the original file continues. You -can control the search paths used with the @samp{-I} command-line option -(@pxref{Invoking,,Command-Line Options}). Quotation marks are required -around @var{file}. - -@node Int, Lcomm, Include, Pseudo Ops -@section @code{.int @var{expressions}} - -@cindex @code{int} directive -_if__(_GENERIC__||!_H8__) -@cindex integers, 32-bit -_fi__(_GENERIC__||!_H8__) -Expect zero or more @var{expressions}, of any section, separated by -commas. For each expression, emit a -_if__(_GENERIC__||!_H8__) -32-bit -_fi__(_GENERIC__||!_H8__) -_if__(_H8__&&!_GENERIC__) -16-bit -_fi__(_H8__&&!_GENERIC__) -number that will, at run -time, be the value of that expression. The byte order of the -expression depends on what kind of computer will run the program. - -@node Lcomm, Lflags, Int, Pseudo Ops -@section @code{.lcomm @var{symbol} , @var{length}} - -@cindex @code{lcomm} directive -@cindex local common symbols -@cindex symbols, local common -Reserve @var{length} (an absolute expression) bytes for a local common -denoted by @var{symbol}. The section and value of @var{symbol} are -those of the new local common. The addresses are allocated in the bss -section, so at run-time the bytes will start off zeroed. @var{Symbol} -is not declared global (@pxref{Global,,@code{.global}}), so is normally -not visible to @code{_LD__}. - -_if__(_GENERIC__||(!_A29K__)) -@node Lflags, Line, Lcomm, Pseudo Ops -_fi__(_GENERIC__||(!_A29K__)) -_if__((!_GENERIC__)&& _A29K__) -@node Lflags, Ln, Lcomm, Pseudo Ops -_fi__((!_GENERIC__)&& _A29K__) -@section @code{.lflags} - -@cindex @code{lflags} directive (ignored) -@code{_AS__} accepts this directive, for compatibility with other -assemblers, but ignores it. - -_if__(_GENERIC__ || !_A29K__) -@node Line, Ln, Lflags, Pseudo Ops -@section @code{.line @var{line-number}} - -@cindex @code{line} directive -_fi__(_GENERIC__ || (!_A29K__)) -_if__(_A29K__ && (!_GENERIC__)) -@node Ln, List, Lflags, Pseudo Ops -@section @code{.ln @var{line-number}} - -@cindex @code{ln} directive -_fi__(_A29K__ && (!_GENERIC__)) -@cindex logical line number -_if__(_AOUT__||_BOUT__) -Tell @code{_AS__} to change the logical line number. @var{line-number} must be -an absolute expression. The next line will have that logical line -number. So any other statements on the current line (after a statement -separator -_if__(_GENERIC__) -character) -_fi__(_GENERIC__) -_if__(!_GENERIC__) -_if__(! (_A29K__||_H8__) ) -character @code{;}) -_fi__(! (_A29K__||_H8__) ) -_if__(_A29K__) -character @samp{@@}) -_fi__(_A29K__) -_if__(_H8__) -character @samp{$}) -_fi__(_H8__) -_fi__(!_GENERIC__) -will be reported as on logical line number -@var{line-number} @minus{} 1. -One day this directive will be unsupported: it is used only -for compatibility with existing assembler programs. @refill - -_if__(_GENERIC__ && _A29K__) -@emph{Warning:} In the AMD29K configuration of _AS__, this command is -only available with the name @code{.ln}, rather than as either -@code{.line} or @code{.ln}. -_fi__(_GENERIC__ && _A29K__) -_fi__(_AOUT__||_BOUT__) -_if__(_COFF__) - -Even though this is a directive associated with the @code{a.out} or -@code{b.out} object-code formats, @code{_AS__} will still recognize it -when producing COFF output, and will treat @samp{.line} as though it -were the COFF @samp{.ln} @emph{if} it is found outside a -@code{.def}/@code{.endef} pair. - -Inside a @code{.def}, @samp{.line} is, instead, one of the directives -used by compilers to generate auxiliary symbol information for -debugging. -_fi__(_COFF__) - -_if__(_AOUT__&&(_GENERIC__||!_A29K__)) -@node Ln, List, Line, Pseudo Ops -@section @code{.ln @var{line-number}} - -@cindex @code{ln} directive -@samp{.ln} is a synonym for @samp{.line}. -_fi__(_AOUT__&&(_GENERIC__||!_A29K__)) -_if__(_COFF__&&!_AOUT__) -@node Ln, List, Line, Pseudo Ops -@section @code{.ln @var{line-number}} - -@cindex @code{ln} directive -Tell @code{_AS__} to change the logical line number. @var{line-number} -must be an absolute expression. The next line will have that logical -line number, so any other statements on the current line (after a -statement separator character @code{;}) will be reported as on logical -line number @var{line-number} @minus{} 1. -_if__(_BOUT__) - -This directive is accepted, but ignored, when @code{_AS__} is configured for -@code{b.out}; its effect is only associated with COFF output format. -_fi__(_BOUT__) -_fi__(_COFF__&&!_AOUT__) - -@node List, Long, Ln, Pseudo Ops -@section @code{.list} - -@cindex @code{list} directive -@cindex listing control, turning on -Control (in conjunction with the @code{.nolist} directive) whether or -not assembly listings are generated. These two directives maintain an -internal counter (which is zero initially). @code{.list} increments the -counter, and @code{.nolist} decrements it. Assembly listings are -generated whenever the counter is greater than zero. - -By default, listings are disabled. When you enable them (with the -@samp{-a} command line option; @pxref{Invoking,,Command-Line Options}), -the initial value of the listing counter is one. - -@node Long, Lsym, List, Pseudo Ops -@section @code{.long @var{expressions}} - -@cindex @code{long} directive -@code{.long} is the same as @samp{.int}, @pxref{Int,,@code{.int}}. - -@node Lsym, Nolist, Long, Pseudo Ops -@section @code{.lsym @var{symbol}, @var{expression}} - -@cindex @code{lsym} directive -@cindex symbol, not referenced in assembly -@code{.lsym} creates a new symbol named @var{symbol}, but does not put it in -the hash table, ensuring it cannot be referenced by name during the -rest of the assembly. This sets the attributes of the symbol to be -the same as the expression value: -@smallexample -@var{other} = @var{descriptor} = 0 -@var{type} = @r{(section of @var{expression})} -@var{value} = @var{expression} -@end smallexample -@noindent -The new symbol is not flagged as external. - -@node Nolist, Octa, Lsym, Pseudo Ops -@section @code{.nolist} - -@cindex @code{nolist} directive -@cindex listing control, turning off -Control (in conjunction with the @code{.list} directive) whether or -not assembly listings are generated. These two directives maintain an -internal counter (which is zero initially). @code{.list} increments the -counter, and @code{.nolist} decrements it. Assembly listings are -generated whenever the counter is greater than zero. - -@node Octa, Org, Nolist, Pseudo Ops -@section @code{.octa @var{bignums}} - -@c FIXME: double size emitted for "octa" on i960, others? Or warn? -@cindex @code{octa} directive -@cindex integer, 16-byte -@cindex sixteen byte integer -This directive expects zero or more bignums, separated by commas. For each -bignum, it emits a 16-byte integer. - -The term ``octa'' comes from contexts in which a ``word'' is two bytes; -hence @emph{octa}-word for 16 bytes. - -@node Org, Psize, Octa, Pseudo Ops -@section @code{.org @var{new-lc} , @var{fill}} - -@cindex @code{org} directive -@cindex location counter, advancing -@cindex advancing location counter -@cindex current address, advancing -@code{.org} will advance the location counter of the current section to -@var{new-lc}. @var{new-lc} is either an absolute expression or an -expression with the same section as the current subsection. That is, -you can't use @code{.org} to cross sections: if @var{new-lc} has the -wrong section, the @code{.org} directive is ignored. To be compatible -with former assemblers, if the section of @var{new-lc} is absolute, -@code{_AS__} will issue a warning, then pretend the section of @var{new-lc} -is the same as the current subsection. - -@code{.org} may only increase the location counter, or leave it -unchanged; you cannot use @code{.org} to move the location counter -backwards. - -@c double negative used below "not undefined" because this is a specific -@c reference to "undefined" (as SEG_UNKNOWN is called in this manual) -@c section. pesch@cygnus.com 18feb91 -Because @code{_AS__} tries to assemble programs in one pass @var{new-lc} -may not be undefined. If you really detest this restriction we eagerly await -a chance to share your improved assembler. - -Beware that the origin is relative to the start of the section, not -to the start of the subsection. This is compatible with other -people's assemblers. - -When the location counter (of the current subsection) is advanced, the -intervening bytes are filled with @var{fill} which should be an -absolute expression. If the comma and @var{fill} are omitted, -@var{fill} defaults to zero. - -@node Psize, Quad, Org, Pseudo Ops -@section @code{.psize @var{lines} , @var{columns}} - -@cindex @code{psize} directive -@cindex listing control: paper size -@cindex paper size, for listings -Use this directive to declare the number of lines---and, optionally, the -number of columns---to use for each page, when generating listings. - -If you don't use @code{.psize}, listings will use a default line-count -of 60. You may omit the comma and @var{columns} specification; the -default width is 200 columns. - -@code{_AS__} will generate formfeeds whenever the specified number of -lines is exceeded (or whenever you explicitly request one, using -@code{.eject}). - -If you specify @var{lines} as @code{0}, no formfeeds are generated save -those explicitly specified with @code{.eject}. - -@node Quad, Sbttl, Psize, Pseudo Ops -@section @code{.quad @var{bignums}} - -@cindex @code{quad} directive -@code{.quad} expects zero or more bignums, separated by commas. For -each bignum, it emits -_if__(_GENERIC__||(!_I960__)) -an 8-byte integer. If the bignum won't fit in 8 -bytes, it prints a warning message; and just takes the lowest order 8 -bytes of the bignum.@refill -@cindex eight-byte integer -@cindex integer, 8-byte - -The term ``quad'' comes from contexts in which a ``word'' is two bytes; -hence @emph{quad}-word for 8 bytes. -_fi__(_GENERIC__||(!_I960__)) -_if__(_I960__&&(!_GENERIC__)) -a 16-byte integer. If the bignum won't fit in 16 bytes, it prints a -warning message; and just takes the lowest order 16 bytes of the -bignum.@refill -@cindex sixteen-byte integer -@cindex integer, 16-byte -_fi__(_I960__&&(!_GENERIC__)) - -_if__(_COFF__||_BOUT__) -@node Sbttl, Scl, Quad, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Sbttl, Set, Quad, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.sbttl "@var{subheading}"} - -@cindex @code{sbttl} directive -@cindex subtitles for listings -@cindex listing control: subtitle -Use @var{subheading} as the title (third line, immediately after the -title line) when generating assembly listings. - -This directive affects subsequent pages, as well as the current page if -it appears within ten lines of the top of a page. - -_if__(_COFF__||_BOUT__) -_if__(!_COFF__) -@node Scl, Set, Sbttl, Pseudo Ops -_fi__(!_COFF__) -_if__(_COFF__) -@node Scl, Section, Sbttl, Pseudo Ops -_fi__(_COFF__) -@section @code{.scl @var{class}} - -@cindex @code{scl} directive -@cindex symbol storage class (COFF) -@cindex COFF symbol storage class -Set the storage-class value for a symbol. This directive may only be -used inside a @code{.def}/@code{.endef} pair. Storage class may flag -whether a symbol is static or external, or it may record further -symbolic debugging information. -_if__(_BOUT__) - -The @samp{.scl} directive is primarily associated with COFF output; when -configured to generate @code{b.out} output format, @code{_AS__} will -accept this directive but ignore it. -_fi__(_BOUT__) -_fi__(_COFF__||_BOUT__) - -_if__(_COFF__) -@node Section, Set, Scl, Pseudo Ops -@section @code{.section @var{name}, @var{subsection}} - -@cindex @code{section} directive -@cindex named section (COFF) -@cindex COFF named section -Assemble the following code into end of subsection numbered -@var{subsection} in the COFF named section @var{name}. If you omit -@var{subsection}, @code{_AS__} uses subsection number zero. -@samp{.section .text} is equivalent to the @code{.text} directive; -@samp{.section .data} is equivalent to the @code{.data} directive. - -@node Set, Short, Section, Pseudo Ops -_fi__(_COFF__) -_if__(_BOUT__&&!_COFF__) -@node Set, Short, Scl, Pseudo Ops -_fi__(_BOUT__&&!_COFF__) -_if__(!(_COFF__||_BOUT__)) -@node Set, Short, Quad, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.set @var{symbol}, @var{expression}} - -@cindex @code{set} directive -@cindex symbol value, setting -This directive sets the value of @var{symbol} to @var{expression}. This -will change @var{symbol}'s value and type to conform to -@var{expression}. If @var{symbol} was flagged as external, it remains -flagged. (@xref{Symbol Attributes}.) - -You may @code{.set} a symbol many times in the same assembly. -If the expression's section is unknowable during pass 1, a second -pass over the source program will be forced. The second pass is -currently not implemented. @code{_AS__} will abort with an error -message if one is required. - -If you @code{.set} a global symbol, the value stored in the object -file is the last value stored into it. - -@node Short, Single, Set, Pseudo Ops -@section @code{.short @var{expressions}} - -@cindex @code{short} directive -_if__(_GENERIC__ || _W16__) -@code{.short} is the same as @samp{.word}. @xref{Word,,@code{.word}}. -_if__(_W32__) -In some configurations, however, @code{.short} and @code{.word} generate -numbers of different lengths; @pxref{_MACH_DEP__}. -_fi__(_W32__) -_fi__(_GENERIC__|| _W16__) -_if__((!_GENERIC__) && _W32__) -This expects zero or more @var{expressions}, and emits -a 16 bit number for each. -_fi__((!_GENERIC__) && _W32__) -_if__(_COFF__||_BOUT__) -@node Single, Size, Short, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Single, Space, Short, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.single @var{flonums}} - -@cindex @code{single} directive -@cindex floating point numbers (single) -This directive assembles zero or more flonums, separated by commas. It -has the same effect as @code{.float}. -_if__(_GENERIC__) -The exact kind of floating point numbers emitted depends on how -@code{_AS__} is configured. @xref{_MACH_DEP__}. -_fi__(_GENERIC__) -_if__((!_GENERIC__) && _IEEEFLOAT__) -On the _HOST__ family, @code{.single} emits 32-bit floating point -numbers in @sc{ieee} format. -_fi__((!_GENERIC__) && _IEEEFLOAT__) - -_if__(_COFF__||_BOUT__) -@node Size, Space, Single, Pseudo Ops -@section @code{.size} - -@cindex @code{size} directive -This directive is generated by compilers to include auxiliary debugging -information in the symbol table. It is only permitted inside -@code{.def}/@code{.endef} pairs. -_if__(_BOUT__) - -@samp{.size} is only meaningful when generating COFF format output; when -@code{_AS__} is generating @code{b.out}, it accepts this directive but -ignores it. -_fi__(_BOUT__) -_fi__(_COFF__||_BOUT__) - -_if__(_H8__&&!_GENERIC__) -@node Space, Tag, Size, Pseudo Ops -_fi__(_H8__&&!_GENERIC__) -_if__(_GENERIC__||!_H8__) -_if__(_COFF__||_BOUT__) -@node Space, Stab, Size, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Space, Stab, Single, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -_fi__(_GENERIC__||!_H8__) -_if__(_GENERIC__ || !_A29K__) -@section @code{.space @var{size} , @var{fill}} - -@cindex @code{space} directive -@cindex filling memory -This directive emits @var{size} bytes, each of value @var{fill}. Both -@var{size} and @var{fill} are absolute expressions. If the comma -and @var{fill} are omitted, @var{fill} is assumed to be zero. -_fi__(_GENERIC__ || !_A29K__) - -_if__(_A29K__) -@section @code{.space} - -@cindex @code{space} directive -On the AMD 29K, this directive is ignored; it is accepted for -compatibility with other AMD 29K assemblers. - -@quotation -@emph{Warning:} In other versions of the GNU assembler, the directive -@code{.space} has the effect of @code{.block} @xref{_MACH_DEP__}. -@end quotation -_fi__(_A29K__) - -_if__(_GENERIC__||!_H8__) -_if__(_AOUT__||_BOUT__||_COFF__) -_if__(_COFF__||_BOUT__) -@node Stab, Tag, Space, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Stab, Text, Space, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.stabd, .stabn, .stabs} - -@cindex symbolic debuggers, information for -@cindex @code{stab@var{x}} directives -There are three directives that begin @samp{.stab}. -All emit symbols (@pxref{Symbols}), for use by symbolic debuggers. -The symbols are not entered in the @code{_AS__} hash table: they -cannot be referenced elsewhere in the source file. -Up to five fields are required: -@table @var -@item string -This is the symbol's name. It may contain any character except @samp{\000}, -so is more general than ordinary symbol names. Some debuggers used to -code arbitrarily complex structures into symbol names using this field. -@item type -An absolute expression. The symbol's type is set to the low 8 -bits of this expression. -Any bit pattern is permitted, but @code{_LD__} and debuggers will choke on -silly bit patterns. -@item other -An absolute expression. -The symbol's ``other'' attribute is set to the low 8 bits of this expression. -@item desc -An absolute expression. -The symbol's descriptor is set to the low 16 bits of this expression. -@item value -An absolute expression which becomes the symbol's value. -@end table - -If a warning is detected while reading a @code{.stabd}, @code{.stabn}, -or @code{.stabs} statement, the symbol has probably already been created -and you will get a half-formed symbol in your object file. This is -compatible with earlier assemblers! - -@table @code -@cindex @code{stabd} directive -@item .stabd @var{type} , @var{other} , @var{desc} - -The ``name'' of the symbol generated is not even an empty string. -It is a null pointer, for compatibility. Older assemblers used a -null pointer so they didn't waste space in object files with empty -strings. - -The symbol's value is set to the location counter, -relocatably. When your program is linked, the value of this symbol -will be where the location counter was when the @code{.stabd} was -assembled. - -@item .stabn @var{type} , @var{other} , @var{desc} , @var{value} -@cindex @code{stabn} directive -The name of the symbol is set to the empty string @code{""}. - -@item .stabs @var{string} , @var{type} , @var{other} , @var{desc} , @var{value} -@cindex @code{stabs} directive -All five fields are specified. -@end table -_fi__(_AOUT__||_BOUT__||_COFF__) -_fi__(_GENERIC__||!_H8__) - -_if__(_COFF__||_BOUT__) -_if__(_GENERIC__||!_H8__) -@node Tag, Text, Stab, Pseudo Ops -_fi__(_GENERIC__||!_H8__) -_if__(_H8__&&!_GENERIC__) -@node Tag, Text, Space, Pseudo Ops -_fi__(_H8__&&!_GENERIC__) -@section @code{.tag @var{structname}} - -@cindex COFF structure debugging -@cindex structure debugging, COFF -@cindex @code{tag} directive -This directive is generated by compilers to include auxiliary debugging -information in the symbol table. It is only permitted inside -@code{.def}/@code{.endef} pairs. Tags are used to link structure -definitions in the symbol table with instances of those structures. -_if__(_BOUT__) - -@samp{.tag} is only used when generating COFF format output; when -@code{_AS__} is generating @code{b.out}, it accepts this directive but -ignores it. -_fi__(_BOUT__) -_fi__(_COFF__||_BOUT__) - -_if__(_COFF__||_BOUT__) -@node Text, Title, Tag, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Text, Title, Stab, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.text @var{subsection}} - -@cindex @code{text} directive -Tells @code{_AS__} to assemble the following statements onto the end of -the text subsection numbered @var{subsection}, which is an absolute -expression. If @var{subsection} is omitted, subsection number zero -is used. - -_if__(_COFF__||_BOUT__) -@node Title, Type, Text, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Title, Word, Text, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.title "@var{heading}"} - -@cindex @code{title} directive -@cindex listing control: title line -Use @var{heading} as the title (second line, immediately after the -source file name and pagenumber) when generating assembly listings. - -This directive affects subsequent pages, as well as the current page if -it appears within ten lines of the top of a page. - -_if__(_COFF__||_BOUT__) -@node Type, Val, Title, Pseudo Ops -@section @code{.type @var{int}} - -@cindex COFF symbol type -@cindex symbol type, COFF -@cindex @code{type} directive -This directive, permitted only within @code{.def}/@code{.endef} pairs, -records the integer @var{int} as the type attribute of a symbol table entry. -_if__(_BOUT__) - -@samp{.type} is associated only with COFF format output; when -@code{_AS__} is configured for @code{b.out} output, it accepts this -directive but ignores it. -_fi__(_BOUT__) -_fi__(_COFF__||_BOUT__) - -_if__(_COFF__||_BOUT__) -@node Val, Word, Type, Pseudo Ops -@section @code{.val @var{addr}} - -@cindex @code{val} directive -@cindex COFF value attribute -@cindex value attribute, COFF -This directive, permitted only within @code{.def}/@code{.endef} pairs, -records the address @var{addr} as the value attribute of a symbol table -entry. -_if__(_BOUT__) - -@samp{.val} is used only for COFF output; when @code{_AS__} is -configured for @code{b.out}, it accepts this directive but ignores it. -_fi__(_BOUT__) -_fi__(_COFF__||_BOUT__) - -_if__(_COFF__||_BOUT__) -@node Word, Deprecated, Val, Pseudo Ops -_fi__(_COFF__||_BOUT__) -_if__(!(_COFF__||_BOUT__)) -@node Word, Deprecated, Text, Pseudo Ops -_fi__(!(_COFF__||_BOUT__)) -@section @code{.word @var{expressions}} - -@cindex @code{word} directive -This directive expects zero or more @var{expressions}, of any section, -separated by commas. -_if__((!_GENERIC__) && _W32__) -For each expression, @code{_AS__} emits a 32-bit number. -_fi__((!_GENERIC__) && _W32__) -_if__((!_GENERIC__) && _W16__) -For each expression, @code{_AS__} emits a 16-bit number. -_fi__((!_GENERIC__) && _W16__) - -_if__(_GENERIC__) -The size of the number emitted, and its byte order, -depends on what kind of computer will run the program. -_fi__(_GENERIC__) - -@c on amd29k, i960, sparc the "special treatment to support compilers" doesn't -@c happen---32-bit addressability, period; no long/short jumps. -_if__(_GENERIC__ || _DIFFTABKLUG__) -@cindex difference tables altered -@cindex altered difference tables -@quotation -@emph{Warning: Special Treatment to support Compilers} -@end quotation - -_if__(_GENERIC__) -Machines with a 32-bit address space, but that do less than 32-bit -addressing, require the following special treatment. If the machine of -interest to you does 32-bit addressing (or doesn't require it; -@pxref{_MACH_DEP__}), you can ignore this issue. - -_fi__(_GENERIC__) -In order to assemble compiler output into something that will work, -@code{_AS__} will occasionlly do strange things to @samp{.word} directives. -Directives of the form @samp{.word sym1-sym2} are often emitted by -compilers as part of jump tables. Therefore, when @code{_AS__} assembles a -directive of the form @samp{.word sym1-sym2}, and the difference between -@code{sym1} and @code{sym2} does not fit in 16 bits, @code{_AS__} will -create a @dfn{secondary jump table}, immediately before the next label. -This secondary jump table will be preceded by a short-jump to the -first byte after the secondary table. This short-jump prevents the flow -of control from accidentally falling into the new table. Inside the -table will be a long-jump to @code{sym2}. The original @samp{.word} -will contain @code{sym1} minus the address of the long-jump to -@code{sym2}. - -If there were several occurrences of @samp{.word sym1-sym2} before the -secondary jump table, all of them will be adjusted. If there was a -@samp{.word sym3-sym4}, that also did not fit in sixteen bits, a -long-jump to @code{sym4} will be included in the secondary jump table, -and the @code{.word} directives will be adjusted to contain @code{sym3} -minus the address of the long-jump to @code{sym4}; and so on, for as many -entries in the original jump table as necessary. - -_if__(_INTERNALS__) -@emph{This feature may be disabled by compiling @code{_AS__} with the -@samp{-DWORKING_DOT_WORD} option.} This feature is likely to confuse -assembly language programmers. -_fi__(_INTERNALS__) -_fi__(_GENERIC__ || _DIFFTABKLUG__) - -@node Deprecated, , Word, Pseudo Ops -@section Deprecated Directives - -@cindex deprecated directives -@cindex obsolescent directives -One day these directives won't work. -They are included for compatibility with older assemblers. -@table @t -@item .abort -@item .app-file -@item .line -@end table - -@node _MACH_DEP__, Copying, Pseudo Ops, Top -_if__(_GENERIC__) -@chapter Machine Dependent Features - -@cindex machine dependencies -The machine instruction sets are (almost by definition) different on -each machine where @code{_AS__} runs. Floating point representations -vary as well, and @code{_AS__} often supports a few additional -directives or command-line options for compatibility with other -assemblers on a particular platform. Finally, some versions of -@code{_AS__} support special pseudo-instructions for branch -optimization. - -This chapter discusses most of these differences, though it does not -include details on any machine's instruction set. For details on that -subject, see the hardware manufacturer's manual. - -@menu -_if__(_VAX__) -* Vax-Dependent:: VAX Dependent Features -_fi__(_VAX__) -_if__(_A29K__) -* AMD29K-Dependent:: AMD 29K Dependent Features -_fi__(_A29K__) -_if__(_H8__) -* H8/300-Dependent:: AMD 29K Dependent Features -_fi__(_H8__) -_if__(_I960__) -* i960-Dependent:: Intel 80960 Dependent Features -_fi__(_I960__) -_if__(_M680X0__) -* M68K-Dependent:: M680x0 Dependent Features -_fi__(_M680X0__) -_if__(_SPARC__) -* Sparc-Dependent:: SPARC Dependent Features -_fi__(_SPARC__) -_if__(_I80386__) -* i386-Dependent:: 80386 Dependent Features -_fi__(_I80386__) -@end menu - -_fi__(_GENERIC__) -_if__(_VAX__) -_if__(_GENERIC__) -@node Vax-Dependent, AMD29K-Dependent, Machine Dependent, Machine Dependent -_fi__(_GENERIC__) -_CHAPSEC__(0+_GENERIC__) VAX Dependent Features - -@cindex VAX support -@menu -* Vax-Opts:: VAX Command-Line Options -* VAX-float:: VAX Floating Point -* VAX-directives:: Vax Machine Directives -* VAX-opcodes:: VAX Opcodes -* VAX-branch:: VAX Branch Improvement -* VAX-operands:: VAX Operands -* VAX-no:: Not Supported on VAX -@end menu - -@node Vax-Opts, VAX-float, Vax-Dependent, Vax-Dependent -_CHAPSEC__(1+_GENERIC__) VAX Command-Line Options - -@cindex command-line options ignored, VAX -@cindex VAX command-line options ignored -The Vax version of @code{_AS__} accepts any of the following options, -gives a warning message that the option was ignored and proceeds. -These options are for compatibility with scripts designed for other -people's assemblers. - -@table @asis -@item @kbd{-D} (Debug) -@itemx @kbd{-S} (Symbol Table) -@itemx @kbd{-T} (Token Trace) -@cindex @code{-D}, ignored on VAX -@cindex @code{-S}, ignored on VAX -@cindex @code{-T}, ignored on VAX -These are obsolete options used to debug old assemblers. - -@item @kbd{-d} (Displacement size for JUMPs) -@cindex @code{-d}, VAX option -This option expects a number following the @kbd{-d}. Like options -that expect filenames, the number may immediately follow the -@kbd{-d} (old standard) or constitute the whole of the command line -argument that follows @kbd{-d} (GNU standard). - -@item @kbd{-V} (Virtualize Interpass Temporary File) -@cindex @code{-V}, redundant on VAX -Some other assemblers use a temporary file. This option -commanded them to keep the information in active memory rather -than in a disk file. @code{_AS__} always does this, so this -option is redundant. - -@item @kbd{-J} (JUMPify Longer Branches) -@cindex @code{-J}, ignored on VAX -Many 32-bit computers permit a variety of branch instructions -to do the same job. Some of these instructions are short (and -fast) but have a limited range; others are long (and slow) but -can branch anywhere in virtual memory. Often there are 3 -flavors of branch: short, medium and long. Some other -assemblers would emit short and medium branches, unless told by -this option to emit short and long branches. - -@item @kbd{-t} (Temporary File Directory) -@cindex @code{-t}, ignored on VAX -Some other assemblers may use a temporary file, and this option -takes a filename being the directory to site the temporary -file. @code{_AS__} does not use a temporary disk file, so this -option makes no difference. @kbd{-t} needs exactly one -filename. -@end table - -@cindex VMS (VAX) options -@cindex options for VAX/VMS -@cindex VAX/VMS options -@cindex @code{-h} option, VAX/VMS -@cindex @code{-+} option, VAX/VMS -@cindex Vax-11 C compatibility -@cindex symbols with lowercase, VAX/VMS -@c FIXME! look into "I think" below, correct if needed, delete. -The Vax version of the assembler accepts two options when -compiled for VMS. They are @kbd{-h}, and @kbd{-+}. The -@kbd{-h} option prevents @code{_AS__} from modifying the -symbol-table entries for symbols that contain lowercase -characters (I think). The @kbd{-+} option causes @code{_AS__} to -print warning messages if the FILENAME part of the object file, -or any symbol name is larger than 31 characters. The @kbd{-+} -option also insertes some code following the @samp{_main} -symbol so that the object file will be compatible with Vax-11 -"C". - -@node VAX-float, VAX-directives, Vax-Opts, Vax-Dependent -_CHAPSEC__(1+_GENERIC__) VAX Floating Point - -@cindex VAX floating point -@cindex floating point, VAX -Conversion of flonums to floating point is correct, and -compatible with previous assemblers. Rounding is -towards zero if the remainder is exactly half the least significant bit. - -@code{D}, @code{F}, @code{G} and @code{H} floating point formats -are understood. - -Immediate floating literals (@emph{e.g.} @samp{S`$6.9}) -are rendered correctly. Again, rounding is towards zero in the -boundary case. - -@cindex @code{float} directive, VAX -@cindex @code{double} directive, VAX -The @code{.float} directive produces @code{f} format numbers. -The @code{.double} directive produces @code{d} format numbers. - -@node VAX-directives, VAX-opcodes, VAX-float, Vax-Dependent -_CHAPSEC__(1+_GENERIC__) Vax Machine Directives - -@cindex machine directives, VAX -@cindex VAX machine directives -The Vax version of the assembler supports four directives for -generating Vax floating point constants. They are described in the -table below. - -@cindex wide floating point directives, VAX -@table @code -@item .dfloat -@cindex @code{dfloat} directive, VAX -This expects zero or more flonums, separated by commas, and -assembles Vax @code{d} format 64-bit floating point constants. - -@item .ffloat -@cindex @code{ffloat} directive, VAX -This expects zero or more flonums, separated by commas, and -assembles Vax @code{f} format 32-bit floating point constants. - -@item .gfloat -@cindex @code{gfloat} directive, VAX -This expects zero or more flonums, separated by commas, and -assembles Vax @code{g} format 64-bit floating point constants. - -@item .hfloat -@cindex @code{hfloat} directive, VAX -This expects zero or more flonums, separated by commas, and -assembles Vax @code{h} format 128-bit floating point constants. - -@end table - -@node VAX-opcodes, VAX-branch, VAX-directives, Vax-Dependent -_CHAPSEC__(1+_GENERIC__) VAX Opcodes - -@cindex VAX opcode mnemonics -@cindex opcode mnemonics, VAX -@cindex mnemonics for opcodes, VAX -All DEC mnemonics are supported. Beware that @code{case@dots{}} -instructions have exactly 3 operands. The dispatch table that -follows the @code{case@dots{}} instruction should be made with -@code{.word} statements. This is compatible with all unix -assemblers we know of. - -@node VAX-branch, VAX-operands, VAX-opcodes, Vax-Dependent -_CHAPSEC__(1+_GENERIC__) VAX Branch Improvement - -@cindex VAX branch improvement -@cindex branch improvement, VAX -@cindex pseudo-ops for branch, VAX -Certain pseudo opcodes are permitted. They are for branch -instructions. They expand to the shortest branch instruction that -will reach the target. Generally these mnemonics are made by -substituting @samp{j} for @samp{b} at the start of a DEC mnemonic. -This feature is included both for compatibility and to help -compilers. If you don't need this feature, don't use these -opcodes. Here are the mnemonics, and the code they can expand into. - -@table @code -@item jbsb -@samp{Jsb} is already an instruction mnemonic, so we chose @samp{jbsb}. -@table @asis -@item (byte displacement) -@kbd{bsbb @dots{}} -@item (word displacement) -@kbd{bsbw @dots{}} -@item (long displacement) -@kbd{jsb @dots{}} -@end table -@item jbr -@itemx jr -Unconditional branch. -@table @asis -@item (byte displacement) -@kbd{brb @dots{}} -@item (word displacement) -@kbd{brw @dots{}} -@item (long displacement) -@kbd{jmp @dots{}} -@end table -@item j@var{COND} -@var{COND} may be any one of the conditional branches -@code{neq nequ eql eqlu gtr geq lss gtru lequ vc vs gequ cc lssu cs}. -@var{COND} may also be one of the bit tests -@code{bs bc bss bcs bsc bcc bssi bcci lbs lbc}. -@var{NOTCOND} is the opposite condition to @var{COND}. -@table @asis -@item (byte displacement) -@kbd{b@var{COND} @dots{}} -@item (word displacement) -@kbd{b@var{NOTCOND} foo ; brw @dots{} ; foo:} -@item (long displacement) -@kbd{b@var{NOTCOND} foo ; jmp @dots{} ; foo:} -@end table -@item jacb@var{X} -@var{X} may be one of @code{b d f g h l w}. -@table @asis -@item (word displacement) -@kbd{@var{OPCODE} @dots{}} -@item (long displacement) -@example -@var{OPCODE} @dots{}, foo ; -brb bar ; -foo: jmp @dots{} ; -bar: -@end example -@end table -@item jaob@var{YYY} -@var{YYY} may be one of @code{lss leq}. -@item jsob@var{ZZZ} -@var{ZZZ} may be one of @code{geq gtr}. -@table @asis -@item (byte displacement) -@kbd{@var{OPCODE} @dots{}} -@item (word displacement) -@example -@var{OPCODE} @dots{}, foo ; -brb bar ; -foo: brw @var{destination} ; -bar: -@end example -@item (long displacement) -@example -@var{OPCODE} @dots{}, foo ; -brb bar ; -foo: jmp @var{destination} ; -bar: -@end example -@end table -@item aobleq -@itemx aoblss -@itemx sobgeq -@itemx sobgtr -@table @asis -@item (byte displacement) -@kbd{@var{OPCODE} @dots{}} -@item (word displacement) -@example -@var{OPCODE} @dots{}, foo ; -brb bar ; -foo: brw @var{destination} ; -bar: -@end example -@item (long displacement) -@example -@var{OPCODE} @dots{}, foo ; -brb bar ; -foo: jmp @var{destination} ; -bar: -@end example -@end table -@end table - -@node VAX-operands, VAX-no, VAX-branch, Vax-Dependent -_CHAPSEC__(1+_GENERIC__) VAX Operands - -@cindex VAX operand notation -@cindex operand notation, VAX -@cindex immediate character, VAX -@cindex VAX immediate character -The immediate character is @samp{$} for Unix compatibility, not -@samp{#} as DEC writes it. - -@cindex indirect character, VAX -@cindex VAX indirect character -The indirect character is @samp{*} for Unix compatibility, not -@samp{@@} as DEC writes it. - -@cindex displacement sizing character, VAX -@cindex VAX displacement sizing character -The displacement sizing character is @samp{`} (an accent grave) for -Unix compatibility, not @samp{^} as DEC writes it. The letter -preceding @samp{`} may have either case. @samp{G} is not -understood, but all other letters (@code{b i l s w}) are understood. - -@cindex register names, VAX -@cindex VAX register names -Register names understood are @code{r0 r1 r2 @dots{} r15 ap fp sp -pc}. Any case of letters will do. - -For instance -@smallexample -tstb *w`$4(r5) -@end smallexample - -Any expression is permitted in an operand. Operands are comma -separated. - -@c There is some bug to do with recognizing expressions -@c in operands, but I forget what it is. It is -@c a syntax clash because () is used as an address mode -@c and to encapsulate sub-expressions. - -@node VAX-no, , VAX-operands, Vax-Dependent -_CHAPSEC__(1+_GENERIC__) Not Supported on VAX - -@cindex VAX bitfields not supported -@cindex bitfields, not supported on VAX -Vax bit fields can not be assembled with @code{_AS__}. Someone -can add the required code if they really need it. - -_fi__(_VAX__) -_if__(_A29K__) -_if__(_GENERIC__) -@node AMD29K-Dependent, H8/300-Dependent, Vax-Dependent, Machine Dependent -_fi__(_GENERIC__) -_CHAPSEC__(0+_GENERIC__) AMD 29K Dependent Features - -@cindex AMD 29K support -@cindex 29K support -@menu -* AMD29K Options:: Options -* AMD29K Syntax:: Syntax -* AMD29K Floating Point:: Floating Point -* AMD29K Directives:: AMD 29K Machine Directives -* AMD29K Opcodes:: Opcodes -@end menu - -@node AMD29K Options, AMD29K Syntax, AMD29K-Dependent, AMD29K-Dependent -_CHAPSEC__(1+_GENERIC__) Options -@cindex AMD 29K options (none) -@cindex options for AMD29K (none) -@code{_AS__} has no additional command-line options for the AMD -29K family. - -@node AMD29K Syntax, AMD29K Floating Point, AMD29K Options, AMD29K-Dependent -_CHAPSEC__(1+_GENERIC__) Syntax -@menu -* AMD29K-Chars:: Special Characters -* AMD29K-Regs:: Register Names -@end menu - -@node AMD29K-Chars, AMD29K-Regs, AMD29K Syntax, AMD29K Syntax -_CHAPSEC__(2+_GENERIC__) Special Characters - -@cindex line comment character, AMD 29K -@cindex AMD 29K line comment character -@samp{;} is the line comment character. - -@cindex line separator, AMD 29K -@cindex AMD 29K line separator -@cindex statement separator, AMD 29K -@cindex AMD 29K statement separator -@samp{@@} can be used instead of a newline to separate statements. - -@cindex identifiers, AMD 29K -@cindex AMD 29K identifiers -The character @samp{?} is permitted in identifiers (but may not begin -an identifier). - -@node AMD29K-Regs, , AMD29K-Chars, AMD29K Syntax -_CHAPSEC__(2+_GENERIC__) Register Names - -@cindex AMD 29K register names -@cindex register names, AMD 29K -General-purpose registers are represented by predefined symbols of the -form @samp{GR@var{nnn}} (for global registers) or @samp{LR@var{nnn}} -(for local registers), where @var{nnn} represents a number between -@code{0} and @code{127}, written with no leading zeros. The leading -letters may be in either upper or lower case; for example, @samp{gr13} -and @samp{LR7} are both valid register names. - -You may also refer to general-purpose registers by specifying the -register number as the result of an expression (prefixed with @samp{%%} -to flag the expression as a register number): -@smallexample -%%@var{expression} -@end smallexample -@noindent ----where @var{expression} must be an absolute expression evaluating to a -number between @code{0} and @code{255}. The range [0, 127] refers to -global registers, and the range [128, 255] to local registers. - -@cindex special purpose registers, AMD 29K -@cindex AMD 29K special purpose registers -@cindex protected registers, AMD 29K -@cindex AMD 29K protected registers -In addition, @code{_AS__} understands the following protected -special-purpose register names for the AMD 29K family: - -@smallexample - vab chd pc0 - ops chc pc1 - cps rbp pc2 - cfg tmc mmu - cha tmr lru -@end smallexample - -These unprotected special-purpose register names are also recognized: -@smallexample - ipc alu fpe - ipa bp inte - ipb fc fps - q cr exop -@end smallexample - -@node AMD29K Floating Point, AMD29K Directives, AMD29K Syntax, AMD29K-Dependent -_CHAPSEC__(1+_GENERIC__) Floating Point - -@cindex floating point, AMD 29K (@sc{ieee}) -@cindex AMD 29K floating point (@sc{ieee}) -The AMD 29K family uses @sc{ieee} floating-point numbers. - -@node AMD29K Directives, AMD29K Opcodes, AMD29K Floating Point, AMD29K-Dependent -_CHAPSEC__(1+_GENERIC__) AMD 29K Machine Directives - -@cindex machine directives, AMD 29K -@cindex AMD 29K machine directives -@table @code -@item .block @var{size} , @var{fill} -@cindex @code{block} directive, AMD 29K -This directive emits @var{size} bytes, each of value @var{fill}. Both -@var{size} and @var{fill} are absolute expressions. If the comma -and @var{fill} are omitted, @var{fill} is assumed to be zero. - -In other versions of the GNU assembler, this directive is called -@samp{.space}. -@end table - -@table @code -@item .cputype -@cindex @code{cputype} directive, AMD 29K -This directive is ignored; it is accepted for compatibility with other -AMD 29K assemblers. - -@item .file -@cindex @code{file} directive, AMD 29K -This directive is ignored; it is accepted for compatibility with other -AMD 29K assemblers. - -@quotation -@emph{Warning:} in other versions of the GNU assembler, @code{.file} is -used for the directive called @code{.app-file} in the AMD 29K support. -@end quotation - -@item .line -@cindex @code{line} directive, AMD 29K -This directive is ignored; it is accepted for compatibility with other -AMD 29K assemblers. - -@item .reg @var{symbol}, @var{expression} -@cindex @code{reg} directive, AMD 29K -@code{.reg} has the same effect as @code{.lsym}; @pxref{Lsym,,@code{.lsym}}. - -@item .sect -@cindex @code{sect} directive, AMD 29K -This directive is ignored; it is accepted for compatibility with other -AMD 29K assemblers. - -@item .use @var{section name} -@cindex @code{use} directive, AMD 29K -Establishes the section and subsection for the following code; -@var{section name} may be one of @code{.text}, @code{.data}, -@code{.data1}, or @code{.lit}. With one of the first three @var{section -name} options, @samp{.use} is equivalent to the machine directive -@var{section name}; the remaining case, @samp{.use .lit}, is the same as -@samp{.data 200}. -@end table - -@node AMD29K Opcodes, , AMD29K Directives, AMD29K-Dependent -_CHAPSEC__(1+_GENERIC__) Opcodes - -@cindex AMD 29K opcodes -@cindex opcodes for AMD 29K -@code{_AS__} implements all the standard AMD 29K opcodes. No -additional pseudo-instructions are needed on this family. - -For information on the 29K machine instruction set, see @cite{Am29000 -User's Manual}, Advanced Micro Devices, Inc. - -_fi__(_A29K__) -_if__(_H8__) -_if__(_GENERIC__) -@node H8/300-Dependent, i960-Dependent, AMD29K-Dependent, Machine Dependent -_fi__(_GENERIC__) -_CHAPSEC__(0+_GENERIC__) H8/300 Dependent Features - -@cindex H8/300 support -@menu -* H8/300 Options:: Options -* H8/300 Syntax:: Syntax -* H8/300 Floating Point:: Floating Point -* H8/300 Directives:: H8/300 Machine Directives -* H8/300 Opcodes:: Opcodes -@end menu - -@node H8/300 Options, H8/300 Syntax, H8/300-Dependent, H8/300-Dependent -_CHAPSEC__(1+_GENERIC__) Options - -@cindex H8/300 options (none) -@cindex options, H8/300 (none) -@code{_AS__} has no additional command-line options for the Hitachi -H8/300 family. - -@node H8/300 Syntax, H8/300 Floating Point, H8/300 Options, H8/300-Dependent -_CHAPSEC__(1+_GENERIC__) Syntax -@menu -* H8/300-Chars:: Special Characters -* H8/300-Regs:: Register Names -* H8/300-Addressing:: Addressing Modes -@end menu - -@node H8/300-Chars, H8/300-Regs, H8/300 Syntax, H8/300 Syntax -_CHAPSEC__(2+_GENERIC__) Special Characters - -@cindex line comment character, H8/300 -@cindex H8/300 line comment character -@samp{;} is the line comment character. - -@cindex line separator, H8/300 -@cindex statement separator, H8/300 -@cindex H8/300 line separator -@samp{$} can be used instead of a newline to separate statements. -Therefore @emph{you may not use @samp{$} in symbol names} on the H8/300. - -@node H8/300-Regs, H8/300-Addressing, H8/300-Chars, H8/300 Syntax -_CHAPSEC__(2+_GENERIC__) Register Names - -@cindex H8/300 registers -@cindex registers, H8/300 -You can use predefined symbols of the form @samp{r@var{n}h} and -@samp{r@var{n}l} to refer to the H8/300 registers as sixteen 8-bit -general-purpose registers. @var{n} is a digit from @samp{0} to -@samp{7}); for instance, both @samp{r0h} and @samp{r7l} are valid -register names. - -You can also use the eight predefined symbols @samp{r@var{n}} to refer -to the H8/300 registers as 16-bit registers (you must use this form for -addressing). - -The two control registers are called @code{pc} (program counter; a -16-bit register) and @code{ccr} (condition code register; an 8-bit -register). @code{r7} is used as the stack pointer, and can also be -called @code{sp}. - -@node H8/300-Addressing, , H8/300-Regs, H8/300 Syntax -_CHAPSEC__(2+_GENERIC__) Addressing Modes - -@cindex addressing modes, H8/300 -@cindex H8/300 addressing modes -_AS__ understands the following addressing modes for the H8/300: -@table @code -@item r@var{n} -Register direct - -@item @@r@var{n} -Register indirect - -@item @@(@var{d}, r@var{n}) -@itemx @@(@var{d}:16, r@var{n}) -Register indirect: 16-bit displacement @var{d} from register @var{n}. -(You may specify the @samp{:16} for clarity if you wish, but it is not -required and has no effect.) - -@item @@r@var{n}+ -Register indirect with post-increment - -@item @@-r@var{n} -Register indirect with pre-decrement - -@item @code{@@}@var{aa} -@itemx @code{@@}@var{aa}:8 -@itemx @code{@@}@var{aa}:16 -Absolute address @code{aa}. You may specify the @samp{:8} or @samp{:16} -for clarity, if you wish; but @code{_AS__} neither requires this nor -uses it---the address size required is taken from context. - -@item #@var{xx} -@itemx #@var{xx}:8 -@itemx #@var{xx}:16 -Immediate data @var{xx}. You may specify the @samp{:8} or @samp{:16} -for clarity, if you wish; but @code{_AS__} neither requires this nor -uses it---the data size required is taken from context. - -@item @code{@@}@code{@@}@var{aa} -@itemx @code{@@}@code{@@}@var{aa}:8 -Memory indirect. You may specify the @samp{:8} for clarity, if you -wish; but @code{_AS__} neither requires this nor uses it. -@end table - -@node H8/300 Floating Point, H8/300 Directives, H8/300 Syntax, H8/300-Dependent -_CHAPSEC__(1+_GENERIC__) Floating Point - -@cindex floating point, H8/300 (@sc{ieee}) -@cindex H8/300 floating point (@sc{ieee}) -The H8/300 family uses @sc{ieee} floating-point numbers. - -@node H8/300 Directives, H8/300 Opcodes, H8/300 Floating Point, H8/300-Dependent -_CHAPSEC__(1+_GENERIC__) H8/300 Machine Directives - -@cindex H8/300 machine directives (none) -@cindex machine directives, H8/300 (none) -@cindex @code{word} directive, H8/300 -@cindex @code{int} directive, H8/300 -@code{_AS__} has no machine-dependent directives for the H8/300. -However, on this platform the @samp{.int} and @samp{.word} directives -generate 16-bit numbers. - -@node H8/300 Opcodes, , H8/300 Directives, H8/300-Dependent -_CHAPSEC__(1+_GENERIC__) Opcodes - -@cindex H8/300 opcode summary -@cindex opcode summary, H8/300 -@cindex mnemonics, H8/300 -@cindex instruction summary, H8/300 -For detailed information on the H8/300 machine instruction set, see -@cite{H8/300 Series Programming Manual} (Hitachi ADE--602--025). - -@code{_AS__} implements all the standard H8/300 opcodes. No additional -pseudo-instructions are needed on this family. - -The following table summarizes the opcodes and their arguments: -@c kluge due to lack of group outside example -@page -@smallexample -@group - Rs @r{source register} - Rd @r{destination register} - imm @r{immediate data} - x:3 @r{a bit (as a number between 0 and 7)} - d:8 @r{eight bit displacement from @code{pc}} - d:16 @r{sixteen bit displacement from @code{Rs}} - -add.b Rs,Rd biand #x:3,Rd -add.b #imm:8,Rd biand #x:3,@@Rd -add.w Rs,Rd biand #x:3,@@aa:8 -adds #1,Rd bild #x:3,Rd -adds #2,Rd bild #x:3,@@Rd -addx #imm:8,Rd bild #x:3,@@aa:8 -addx Rs,Rd bior #x:3,Rd -and #imm:8,Rd bior #x:3,@@Rd -and Rs,Rd bior #x:3,@@aa:8 -andc #imm:8,ccr bist #x:3,Rd -band #x:3,Rd bist #x:3,@@Rd -band #x:3,@@Rd bist #x:3,@@aa:8 -bra d:8 bixor #x:3,Rd -bt d:8 bixor #x:3,@@Rd -brn d:8 bixor #x:3,@@aa:8 -bf d:8 bld #x:3,Rd -bhi d:8 bld #x:3,@@Rd -bls d:8 bld #x:3,@@aa:8 -bcc d:8 bnot #x:3,Rd -bhs d:8 bnot #x:3,@@Rd -bcs d:8 bnot #x:3,@@aa:8 -blo d:8 bnot Rs,Rd -bne d:8 bnot Rs,@@Rd -beq d:8 bnot Rs,@@aa:8 -bvc d:8 bor #x:3,Rd -bvs d:8 bor #x:3,@@Rd -bpl d:8 bor #x:3,@@aa:8 -bmi d:8 bset #x:3,@@Rd -bge d:8 bset #x:3,@@aa:8 -blt d:8 bset Rs,Rd -bgt d:8 bset Rs,@@Rd -ble d:8 bset Rs,@@aa:8 -bclr #x:3,Rd bsr d:8 -bclr #x:3,@@Rd bst #x:3,Rd -bclr #x:3,@@aa:8 bst #x:3,@@Rd -bclr Rs,Rd bst #x:3,@@aa:8 -bclr Rs,@@Rd btst #x:3,Rd -@end group -@group -btst #x:3,@@Rd mov.w @@(d:16, Rs),Rd -btst #x:3,@@aa:8 mov.w @@Rs+,Rd -btst Rs,Rd mov.w @@aa:16,Rd -btst Rs,@@Rd mov.w Rs,@@Rd -btst Rs,@@aa:8 mov.w Rs,@@(d:16, Rd) -bxor #x:3,Rd mov.w Rs,@@-Rd -bxor #x:3,@@Rd mov.w Rs,@@aa:16 -bxor #x:3,@@aa:8 movfpe @@aa:16,Rd -cmp.b #imm:8,Rd movtpe Rs,@@aa:16 -cmp.b Rs,Rd mulxu Rs,Rd -cmp.w Rs,Rd neg Rs -daa Rs nop -das Rs not Rs -dec Rs or #imm:8,Rd -divxu Rs,Rd or Rs,Rd -eepmov orc #imm:8,ccr -inc Rs pop Rs -jmp @@Rs push Rs -jmp @@aa:16 rotl Rs -jmp @@@@aa rotr Rs -jsr @@Rs rotxl Rs -jsr @@aa:16 rotxr Rs -jsr @@@@aa:8 rte -ldc #imm:8,ccr rts -ldc Rs,ccr shal Rs -mov.b Rs,Rd shar Rs -mov.b #imm:8,Rd shll Rs -mov.b @@Rs,Rd shlr Rs -mov.b @@(d:16, Rs),Rd sleep -mov.b @@Rs+,Rd stc ccr,Rd -mov.b @@aa:16,Rd sub.b Rs,Rd -mov.b @@aa:8,Rd sub.w Rs,Rd -mov.b Rs,@@Rd subs #1,Rd -mov.b Rs,@@(d:16, Rd) subs #2,Rd -mov.b Rs,@@-Rd subx #imm:8,Rd -mov.b Rs,@@aa:16 subx Rs,Rd -mov.b Rs,@@aa:8 xor #imm:8,Rd -mov.w Rs,Rd xor Rs,Rd -mov.w #imm:16,Rd xorc #imm:8,ccr -mov.w @@Rs,Rd -@end group -@end smallexample - -@cindex size suffixes, H8/300 -@cindex H8/300 size suffixes -Four H8/300 instructions (@code{add}, @code{cmp}, @code{mov}, -@code{sub}) are defined with variants using the suffixes @samp{.b} and -@samp{.w} to specify the size of a memory operand. @code{_AS__} -supports these suffixes, but does not require them; since one of the -operands is always a register, @code{_AS__} can deduce the correct size. - -For example, since @code{r0} refers to a 16-bit register, -@example -mov r0,@@foo -@exdent is equivalent to -mov.w r0,@@foo -@end example - -If you use the size suffixes, @code{_AS__} will issue a warning if -there's a mismatch between the suffix and the register size. - -_fi__(_H8__) -_if__(_I960__) -_if__(_GENERIC__) -@node i960-Dependent, M68K-Dependent, H8/300-Dependent, Machine Dependent -_fi__(_GENERIC__) -_CHAPSEC__(0+_GENERIC__) Intel 80960 Dependent Features - -@cindex i960 support -@menu -* Options-i960:: i960 Command-line Options -* Floating Point-i960:: Floating Point -* Directives-i960:: i960 Machine Directives -* Opcodes for i960:: i960 Opcodes -@end menu - -@c FIXME! Add Syntax sec with discussion of bitfields here, at least so -@c long as they're not turned on for other machines than 960. -@node Options-i960, Floating Point-i960, i960-Dependent, i960-Dependent - -_CHAPSEC__(1+_GENERIC__) i960 Command-line Options - -@cindex i960 options -@cindex options, i960 -@table @code - -@item -ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC -@cindex i960 architecture options -@cindex architecture options, i960 -@cindex @code{-A} options, i960 -Select the 80960 architecture. Instructions or features not supported -by the selected architecture cause fatal errors. - -@samp{-ACA} is equivalent to @samp{-ACA_A}; @samp{-AKC} is equivalent to -@samp{-AMC}. Synonyms are provided for compatibility with other tools. - -If none of these options is specified, @code{_AS__} will generate code for any -instruction or feature that is supported by @emph{some} version of the -960 (even if this means mixing architectures!). In principle, -@code{_AS__} will attempt to deduce the minimal sufficient processor -type if none is specified; depending on the object code format, the -processor type may be recorded in the object file. If it is critical -that the @code{_AS__} output match a specific architecture, specify that -architecture explicitly. - -@item -b -@cindex @code{-b} option, i960 -@cindex branch recording, i960 -@cindex i960 branch recording -Add code to collect information about conditional branches taken, for -later optimization using branch prediction bits. (The conditional branch -instructions have branch prediction bits in the CA, CB, and CC -architectures.) If @var{BR} represents a conditional branch instruction, -the following represents the code generated by the assembler when -@samp{-b} is specified: - -@smallexample - call @var{increment routine} - .word 0 # pre-counter -Label: @var{BR} - call @var{increment routine} - .word 0 # post-counter -@end smallexample - -The counter following a branch records the number of times that branch -was @emph{not} taken; the differenc between the two counters is the -number of times the branch @emph{was} taken. - -@cindex @code{gbr960}, i960 postprocessor -@cindex branch statistics table, i960 -A table of every such @code{Label} is also generated, so that the -external postprocessor @code{gbr960} (supplied by Intel) can locate all -the counters. This table is always labelled @samp{__BRANCH_TABLE__}; -this is a local symbol to permit collecting statistics for many separate -object files. The table is word aligned, and begins with a two-word -header. The first word, initialized to 0, is used in maintaining linked -lists of branch tables. The second word is a count of the number of -entries in the table, which follow immediately: each is a word, pointing -to one of the labels illustrated above. - -@c TEXI2ROFF-KILL -@ifinfo -@c END TEXI2ROFF-KILL -@example - +------------+------------+------------+ ... +------------+ - | | | | | | - | *NEXT | COUNT: N | *BRLAB 1 | | *BRLAB N | - | | | | | | - +------------+------------+------------+ ... +------------+ - - __BRANCH_TABLE__ layout -@end example -@c TEXI2ROFF-KILL -@end ifinfo -@tex -\vskip 1pc -\line{\leftskip=0pt\hskip\tableindent -\boxit{2cm}{\tt *NEXT}\boxit{2cm}{\tt COUNT: \it N}\boxit{2cm}{\tt -*BRLAB 1}\ibox{1cm}{\quad\dots}\boxit{2cm}{\tt *BRLAB \it N}\hfil} -\centerline{\it {\tt \_\_BRANCH\_TABLE\_\_} layout} -@end tex -@c END TEXI2ROFF-KILL - -The first word of the header is used to locate multiple branch tables, -since each object file may contain one. Normally the links are -maintained with a call to an initialization routine, placed at the -beginning of each function in the file. The GNU C compiler will -generate these calls automatically when you give it a @samp{-b} option. -For further details, see the documentation of @samp{gbr960}. - -@item -norelax -@cindex @code{-norelax} option, i960 -Normally, Compare-and-Branch instructions with targets that require -displacements greater than 13 bits (or that have external targets) are -replaced with the corresponding compare (or @samp{chkbit}) and branch -instructions. You can use the @samp{-norelax} option to specify that -@code{_AS__} should generate errors instead, if the target displacement -is larger than 13 bits. - -This option does not affect the Compare-and-Jump instructions; the code -emitted for them is @emph{always} adjusted when necessary (depending on -displacement size), regardless of whether you use @samp{-norelax}. -@end table - -@node Floating Point-i960, Directives-i960, Options-i960, i960-Dependent -_CHAPSEC__(1+_GENERIC__) Floating Point - -@cindex floating point, i960 (@sc{ieee}) -@cindex i960 floating point (@sc{ieee}) -@code{_AS__} generates @sc{ieee} floating-point numbers for the directives -@samp{.float}, @samp{.double}, @samp{.extended}, and @samp{.single}. - -@node Directives-i960, Opcodes for i960, Floating Point-i960, i960-Dependent -_CHAPSEC__(1+_GENERIC__) i960 Machine Directives - -@cindex machine directives, i960 -@cindex i960 machine directives - -@table @code -@cindex @code{bss} directive, i960 -@item .bss @var{symbol}, @var{length}, @var{align} -Reserve @var{length} bytes in the bss section for a local @var{symbol}, -aligned to the power of two specified by @var{align}. @var{length} and -@var{align} must be positive absolute expressions. This directive -differs from @samp{.lcomm} only in that it permits you to specify -an alignment. @xref{Lcomm,,@code{.lcomm}}. -@end table - -@table @code -@item .extended @var{flonums} -@cindex @code{extended} directive, i960 -@code{.extended} expects zero or more flonums, separated by commas; for -each flonum, @samp{.extended} emits an @sc{ieee} extended-format (80-bit) -floating-point number. - -@item .leafproc @var{call-lab}, @var{bal-lab} -@cindex @code{leafproc} directive, i960 -You can use the @samp{.leafproc} directive in conjunction with the -optimized @code{callj} instruction to enable faster calls of leaf -procedures. If a procedure is known to call no other procedures, you -may define an entry point that skips procedure prolog code (and that does -not depend on system-supplied saved context), and declare it as the -@var{bal-lab} using @samp{.leafproc}. If the procedure also has an -entry point that goes through the normal prolog, you can specify that -entry point as @var{call-lab}. - -A @samp{.leafproc} declaration is meant for use in conjunction with the -optimized call instruction @samp{callj}; the directive records the data -needed later to choose between converting the @samp{callj} into a -@code{bal} or a @code{call}. - -@var{call-lab} is optional; if only one argument is present, or if the -two arguments are identical, the single argument is assumed to be the -@code{bal} entry point. - -@item .sysproc @var{name}, @var{index} -@cindex @code{sysproc} directive, i960 -The @samp{.sysproc} directive defines a name for a system procedure. -After you define it using @samp{.sysproc}, you can use @var{name} to -refer to the system procedure identified by @var{index} when calling -procedures with the optimized call instruction @samp{callj}. - -Both arguments are required; @var{index} must be between 0 and 31 -(inclusive). -@end table - -@node Opcodes for i960, , Directives-i960, i960-Dependent -_CHAPSEC__(1+_GENERIC__) i960 Opcodes - -@cindex opcodes, i960 -@cindex i960 opcodes -All Intel 960 machine instructions are supported; -@pxref{Options-i960,,i960 Command-line Options} for a discussion of -selecting the instruction subset for a particular 960 -architecture.@refill - -Some opcodes are processed beyond simply emitting a single corresponding -instruction: @samp{callj}, and Compare-and-Branch or Compare-and-Jump -instructions with target displacements larger than 13 bits. - -@menu -* callj-i960:: @code{callj} -* Compare-and-branch-i960:: Compare-and-Branch -@end menu - -@node callj-i960, Compare-and-branch-i960, Opcodes for i960, Opcodes for i960 -_CHAPSEC__(2+_GENERIC__) @code{callj} - -@cindex @code{callj}, i960 pseudo-opcode -@cindex i960 @code{callj} pseudo-opcode -You can write @code{callj} to have the assembler or the linker determine -the most appropriate form of subroutine call: @samp{call}, -@samp{bal}, or @samp{calls}. If the assembly source contains -enough information---a @samp{.leafproc} or @samp{.sysproc} directive -defining the operand---then @code{_AS__} will translate the -@code{callj}; if not, it will simply emit the @code{callj}, leaving it -for the linker to resolve. - -@node Compare-and-branch-i960, , callj-i960, Opcodes for i960 -_CHAPSEC__(2+_GENERIC__) Compare-and-Branch - -@cindex i960 compare and branch instructions -@cindex compare and branch instructions, i960 -The 960 architectures provide combined Compare-and-Branch instructions -that permit you to store the branch target in the lower 13 bits of the -instruction word itself. However, if you specify a branch target far -enough away that its address won't fit in 13 bits, the assembler can -either issue an error, or convert your Compare-and-Branch instruction -into separate instructions to do the compare and the branch. - -@cindex compare and jump expansions, i960 -@cindex i960 compare and jump expansions -Whether @code{_AS__} gives an error or expands the instruction depends -on two choices you can make: whether you use the @samp{-norelax} option, -and whether you use a ``Compare and Branch'' instruction or a ``Compare -and Jump'' instruction. The ``Jump'' instructions are @emph{always} -expanded if necessary; the ``Branch'' instructions are expanded when -necessary @emph{unless} you specify @code{-norelax}---in which case -@code{_AS__} gives an error instead. - -These are the Compare-and-Branch instructions, their ``Jump'' variants, -and the instruction pairs they may expand into: - -@c TEXI2ROFF-KILL -@ifinfo -@c END TEXI2ROFF-KILL -@example - Compare and - Branch Jump Expanded to - ------ ------ ------------ - bbc chkbit; bno - bbs chkbit; bo - cmpibe cmpije cmpi; be - cmpibg cmpijg cmpi; bg - cmpibge cmpijge cmpi; bge - cmpibl cmpijl cmpi; bl - cmpible cmpijle cmpi; ble - cmpibno cmpijno cmpi; bno - cmpibne cmpijne cmpi; bne - cmpibo cmpijo cmpi; bo - cmpobe cmpoje cmpo; be - cmpobg cmpojg cmpo; bg - cmpobge cmpojge cmpo; bge - cmpobl cmpojl cmpo; bl - cmpoble cmpojle cmpo; ble - cmpobne cmpojne cmpo; bne -@end example -@c TEXI2ROFF-KILL -@end ifinfo -@tex -\hskip\tableindent -\halign{\hfil {\tt #}\quad&\hfil {\tt #}\qquad&{\tt #}\hfil\cr -\omit{\hfil\it Compare and\hfil}\span\omit&\cr -{\it Branch}&{\it Jump}&{\it Expanded to}\cr - bbc& & chkbit; bno\cr - bbs& & chkbit; bo\cr - cmpibe& cmpije& cmpi; be\cr - cmpibg& cmpijg& cmpi; bg\cr - cmpibge& cmpijge& cmpi; bge\cr - cmpibl& cmpijl& cmpi; bl\cr - cmpible& cmpijle& cmpi; ble\cr - cmpibno& cmpijno& cmpi; bno\cr - cmpibne& cmpijne& cmpi; bne\cr - cmpibo& cmpijo& cmpi; bo\cr - cmpobe& cmpoje& cmpo; be\cr - cmpobg& cmpojg& cmpo; bg\cr - cmpobge& cmpojge& cmpo; bge\cr - cmpobl& cmpojl& cmpo; bl\cr - cmpoble& cmpojle& cmpo; ble\cr - cmpobne& cmpojne& cmpo; bne\cr} -@end tex -@c END TEXI2ROFF-KILL -_fi__(_I960__) - -_if__(_M680X0__) -_if__(_GENERIC__) -@c FIXME! node conds are only sufficient for m68k alone, all, and vintage -_if__(_I960__) -@node M68K-Dependent, Sparc-Dependent, i960-Dependent, Machine Dependent -_fi__(_I960__) -_if__(!_I960__) -@node M68K-Dependent, Sparc-Dependent, Machine Dependent, Machine Dependent -_fi__(!_I960__) -_fi__(_GENERIC__) -_CHAPSEC__(0+_GENERIC__) M680x0 Dependent Features - -@cindex M680x0 support -@menu -* M68K-Opts:: M680x0 Options -* M68K-Syntax:: Syntax -* M68K-Float:: Floating Point -* M68K-Directives:: 680x0 Machine Directives -* M68K-opcodes:: Opcodes -@end menu - -@node M68K-Opts, M68K-Syntax, M68K-Dependent, M68K-Dependent -_CHAPSEC__(1+_GENERIC__) M680x0 Options - -@cindex options, M680x0 -@cindex M680x0 options -The Motorola 680x0 version of @code{_AS__} has two machine dependent options. -One shortens undefined references from 32 to 16 bits, while the -other is used to tell @code{_AS__} what kind of machine it is -assembling for. - -@cindex @code{-l} option, M680x0 -You can use the @kbd{-l} option to shorten the size of references to -undefined symbols. If the @kbd{-l} option is not given, references to -undefined symbols will be a full long (32 bits) wide. (Since @code{_AS__} -cannot know where these symbols will end up, @code{_AS__} can only allocate -space for the linker to fill in later. Since @code{_AS__} doesn't know how -far away these symbols will be, it allocates as much space as it can.) -If this option is given, the references will only be one word wide (16 -bits). This may be useful if you want the object file to be as small as -possible, and you know that the relevant symbols will be less than 17 -bits away. - -@cindex @code{-m68000} and related options, M680x0 -@cindex architecture options, M680x0 -@cindex M680x0 architecture options -The 680x0 version of @code{_AS__} is most frequently used to assemble -programs for the Motorola MC68020 microprocessor. Occasionally it is -used to assemble programs for the mostly similar, but slightly different -MC68000 or MC68010 microprocessors. You can give @code{_AS__} the options -@samp{-m68000}, @samp{-mc68000}, @samp{-m68010}, @samp{-mc68010}, -@samp{-m68020}, and @samp{-mc68020} to tell it what processor is the -target. - -@node M68K-Syntax, M68K-Float, M68K-Opts, M68K-Dependent -_CHAPSEC__(1+_GENERIC__) Syntax - -@cindex M680x0 syntax -@cindex syntax, M680x0 -@cindex M680x0 size modifiers -@cindex size modifiers, M680x0 -The 680x0 version of @code{_AS__} uses syntax similar to the Sun assembler. -Size modifiers are appended directly to the end of the opcode without an -intervening period. For example, write @samp{movl} rather than -@samp{move.l}. - -_if__(_INTERNALS__) -If @code{_AS__} is compiled with SUN_ASM_SYNTAX defined, it will also allow -Sun-style local labels of the form @samp{1$} through @samp{$9}. -_fi__(_INTERNALS__) - -In the following table @dfn{apc} stands for any of the address -registers (@samp{a0} through @samp{a7}), nothing, (@samp{}), the -Program Counter (@samp{pc}), or the zero-address relative to the -program counter (@samp{zpc}). - -@cindex M680x0 addressing modes -@cindex addressing modes, M680x0 -The following addressing modes are understood: -@table @dfn -@item Immediate -@samp{#@var{digits}} - -@item Data Register -@samp{d0} through @samp{d7} - -@item Address Register -@samp{a0} through @samp{a7} - -@item Address Register Indirect -@samp{a0@@} through @samp{a7@@} - -@item Address Register Postincrement -@samp{a0@@+} through @samp{a7@@+} - -@item Address Register Predecrement -@samp{a0@@-} through @samp{a7@@-} - -@item Indirect Plus Offset -@samp{@var{apc}@@(@var{digits})} - -@item Index -@samp{@var{apc}@@(@var{digits},@var{register}:@var{size}:@var{scale})} - -or @samp{@var{apc}@@(@var{register}:@var{size}:@var{scale})} - -@item Postindex -@samp{@var{apc}@@(@var{digits})@@(@var{digits},@var{register}:@var{size}:@var{scale})} - -or @samp{@var{apc}@@(@var{digits})@@(@var{register}:@var{size}:@var{scale})} - -@item Preindex -@samp{@var{apc}@@(@var{digits},@var{register}:@var{size}:@var{scale})@@(@var{digits})} - -or @samp{@var{apc}@@(@var{register}:@var{size}:@var{scale})@@(@var{digits})} - -@item Memory Indirect -@samp{@var{apc}@@(@var{digits})@@(@var{digits})} - -@item Absolute -@samp{@var{symbol}}, or @samp{@var{digits}} -@ignore -@c pesch@cygnus.com: gnu, rich concur the following needs careful -@c research before documenting. - , or either of the above followed -by @samp{:b}, @samp{:w}, or @samp{:l}. -@end ignore -@end table - -@node M68K-Float, M68K-Directives, M68K-Syntax, M68K-Dependent -_CHAPSEC__(1+_GENERIC__) Floating Point - -@cindex floating point, M680x0 -@cindex M680x0 floating point -@c FIXME is this "not too well tested" crud STILL true? -The floating point code is not too well tested, and may have -subtle bugs in it. - -Packed decimal (P) format floating literals are not supported. -Feel free to add the code! - -The floating point formats generated by directives are these. - -@table @code -@item .float -@cindex @code{float} directive, M680x0 -@code{Single} precision floating point constants. - -@item .double -@cindex @code{double} directive, M680x0 -@code{Double} precision floating point constants. -@end table - -There is no directive to produce regions of memory holding -extended precision numbers, however they can be used as -immediate operands to floating-point instructions. Adding a -directive to create extended precision numbers would not be -hard, but it has not yet seemed necessary. - -@node M68K-Directives, M68K-opcodes, M68K-Float, M68K-Dependent -_CHAPSEC__(1+_GENERIC__) 680x0 Machine Directives - -@cindex M680x0 directives -@cindex directives, M680x0 -In order to be compatible with the Sun assembler the 680x0 assembler -understands the following directives. - -@table @code -@item .data1 -@cindex @code{data1} directive, M680x0 -This directive is identical to a @code{.data 1} directive. - -@item .data2 -@cindex @code{data2} directive, M680x0 -This directive is identical to a @code{.data 2} directive. - -@item .even -@cindex @code{even} directive, M680x0 -This directive is identical to a @code{.align 1} directive. -@c Is this true? does it work??? - -@item .skip -@cindex @code{skip} directive, M680x0 -This directive is identical to a @code{.space} directive. -@end table - -@node M68K-opcodes, , M68K-Directives, M68K-Dependent -_CHAPSEC__(1+_GENERIC__) Opcodes - -@cindex M680x0 opcodes -@cindex opcodes, M680x0 -@cindex instruction set, M680x0 -@c pesch@cygnus.com: I don't see any point in the following -@c paragraph. Bugs are bugs; how does saying this -@c help anyone? -@ignore -Danger: Several bugs have been found in the opcode table (and -fixed). More bugs may exist. Be careful when using obscure -instructions. -@end ignore - -@menu -* M68K-Branch:: Branch Improvement -* M68K-Chars:: Special Characters -@end menu - -@node M68K-Branch, M68K-Chars, M68K-opcodes, M68K-opcodes -_CHAPSEC__(2+_GENERIC__) Branch Improvement - -@cindex pseudo-opcodes, M680x0 -@cindex M680x0 pseudo-opcodes -@cindex branch improvement, M680x0 -@cindex M680x0 branch improvement -Certain pseudo opcodes are permitted for branch instructions. -They expand to the shortest branch instruction that will reach the -target. Generally these mnemonics are made by substituting @samp{j} for -@samp{b} at the start of a Motorola mnemonic. - -The following table summarizes the pseudo-operations. A @code{*} flags -cases that are more fully described after the table: - -@smallexample - Displacement - +--------------------------------------------------------- - | 68020 68000/10 -Pseudo-Op |BYTE WORD LONG LONG non-PC relative - +--------------------------------------------------------- - jbsr |bsrs bsr bsrl jsr jsr - jra |bras bra bral jmp jmp -* jXX |bXXs bXX bXXl bNXs;jmpl bNXs;jmp -* dbXX |dbXX dbXX dbXX; bra; jmpl -* fjXX |fbXXw fbXXw fbXXl fbNXw;jmp - -XX: condition -NX: negative of condition XX - -@end smallexample -@center @code{*}---see full description below - -@table @code -@item jbsr -@itemx jra -These are the simplest jump pseudo-operations; they always map to one -particular machine instruction, depending on the displacement to the -branch target. - -@item j@var{XX} -Here, @samp{j@var{XX}} stands for an entire family of pseudo-operations, -where @var{XX} is a conditional branch or condition-code test. The full -list of pseudo-ops in this family is: -@smallexample - jhi jls jcc jcs jne jeq jvc - jvs jpl jmi jge jlt jgt jle -@end smallexample - -For the cases of non-PC relative displacements and long displacements on -the 68000 or 68010, @code{_AS__} will issue a longer code fragment in terms of -@var{NX}, the opposite condition to @var{XX}: -@smallexample - j@var{XX} foo -@end smallexample -gives -@smallexample - b@var{NX}s oof - jmp foo - oof: -@end smallexample - -@item db@var{XX} -The full family of pseudo-operations covered here is -@smallexample - dbhi dbls dbcc dbcs dbne dbeq dbvc - dbvs dbpl dbmi dbge dblt dbgt dble - dbf dbra dbt -@end smallexample - -Other than for word and byte displacements, when the source reads -@samp{db@var{XX} foo}, @code{_AS__} will emit -@smallexample - db@var{XX} oo1 - bra oo2 - oo1:jmpl foo - oo2: -@end smallexample - -@item fj@var{XX} -This family includes -@smallexample - fjne fjeq fjge fjlt fjgt fjle fjf - fjt fjgl fjgle fjnge fjngl fjngle fjngt - fjnle fjnlt fjoge fjogl fjogt fjole fjolt - fjor fjseq fjsf fjsne fjst fjueq fjuge - fjugt fjule fjult fjun -@end smallexample - -For branch targets that are not PC relative, @code{_AS__} emits -@smallexample - fb@var{NX} oof - jmp foo - oof: -@end smallexample -when it encounters @samp{fj@var{XX} foo}. - -@end table - -@node M68K-Chars, , M68K-Branch, M68K-opcodes -_CHAPSEC__(2+_GENERIC__) Special Characters - -@cindex special characters, M680x0 -@cindex M680x0 immediate character -@cindex immediate character, M680x0 -@cindex M680x0 line comment character -@cindex line comment character, M680x0 -@cindex comments, M680x0 -The immediate character is @samp{#} for Sun compatibility. The -line-comment character is @samp{|}. If a @samp{#} appears at the -beginning of a line, it is treated as a comment unless it looks like -@samp{# line file}, in which case it is treated normally. - -_fi__(_M680X0__) -_if__(0) -@c pesch@cygnus.com: conditionalize on something other than 0 when filled in. -@section 32x32 -@section Options -The 32x32 version of @code{_AS__} accepts a @kbd{-m32032} option to -specify thiat it is compiling for a 32032 processor, or a -@kbd{-m32532} to specify that it is compiling for a 32532 option. -The default (if neither is specified) is chosen when the assembler -is compiled. - -@subsection Syntax -I don't know anything about the 32x32 syntax assembled by -@code{_AS__}. Someone who undersands the processor (I've never seen -one) and the possible syntaxes should write this section. - -@subsection Floating Point -The 32x32 uses @sc{ieee} floating point numbers, but @code{_AS__} will only -create single or double precision values. I don't know if the 32x32 -understands extended precision numbers. - -@subsection 32x32 Machine Directives -The 32x32 has no machine dependent directives. - -_fi__(0) -_if__(_SPARC__) -_if__(_GENERIC__) -_if__(_I80386__&&_M680X0__) -@node Sparc-Dependent, i386-Dependent, M68K-Dependent, Machine Dependent -_fi__(_I80386__&&_M680X0__) -_if__(_I80386__&&_I960__&&!_M680X0__) -@node Sparc-Dependent, i386-Dependent, i960-Dependent, Machine Dependent -_fi__(_I80386__&&_I960__&&!_M680X0__) -_if__(_I80386__&&_A29K__&&(!_I960__)&&!_M680X0__) -@node Sparc-Dependent, i386-Dependent, AMD29K-Dependent, Machine Dependent -_fi__(_I80386__&&_A29K__&&(!_I960__)&&!_M680X0__) -_if__(_I80386__&&_VAX__&&(!_A29K__)&&(!_I960__)&&!_M680X0__) -@node Sparc-Dependent, i386-Dependent, Vax-Dependent, Machine Dependent -_fi__(_I80386__&&_VAX__&&(!_A29K__)&&(!_I960__)&&!_M680X0__) -_if__(_I80386__&&(!_VAX__)&&(!_A29K__)&&(!_I960__)&&!_M680X0__) -@node Sparc-Dependent, i386-Dependent, Machine Dependent, Machine Dependent -_fi__(_I80386__&&(!_VAX__)&&(!_A29K__)&&(!_I960__)&&!_M680X0__) -_if__((!_I80386__)&&_M680X0__) -@node Sparc-Dependent, , M68K-Dependent, Machine Dependent -_fi__((!_I80386__)&&_M680X0__) -_if__((!_I80386__)&&_I960__&&!_M680X0__) -@node Sparc-Dependent, , i960-Dependent, Machine Dependent -_fi__((!_I80386__)&&_I960__&&!_M680X0__) -_if__((!_I80386__)&&_A29K__&&(!_I960__)&&!_M680X0__) -@node Sparc-Dependent, , AMD29K-Dependent, Machine Dependent -_fi__((!_I80386__)&&_A29K__&&(!_I960__)&&!_M680X0__) -_if__((!_I80386__)&&_VAX__&&(!_A29K__)&&(!_I960__)&&!_M680X0__) -@node Sparc-Dependent, , Vax-Dependent, Machine Dependent -_fi__((!_I80386__)&&_VAX__&&(!_A29K__)&&(!_I960__)&&!_M680X0__) -_if__((!_I80386__)&&(!_VAX__)&&(!_A29K__)&&(!_I960__)&&!_M680X0__) -@node Sparc-Dependent, , Machine Dependent, Machine Dependent -_fi__((!_I80386__)&&(!_VAX__)&&(!_A29K__)&&(!_I960__)&&!_M680X0__) -_fi__(_GENERIC__) -_CHAPSEC__(0+_GENERIC__) SPARC Dependent Features - -@cindex SPARC support -@menu -* Sparc-Opts:: Options -* Sparc-Float:: Floating Point -* Sparc-Directives:: Sparc Machine Directives -@end menu - -@node Sparc-Opts, Sparc-Float, Sparc-Dependent, Sparc-Dependent -_CHAPSEC__(1+_GENERIC__) Options - -@cindex options for SPARC (none) -@cindex SPARC options (none) -The Sparc has no machine dependent options. - -@ignore -@c FIXME: (sparc) Fill in "syntax" section! -@c subsection syntax -I don't know anything about Sparc syntax. Someone who does -will have to write this section. -@end ignore - -@node Sparc-Float, Sparc-Directives, Sparc-Opts, Sparc-Dependent -_CHAPSEC__(1+_GENERIC__) Floating Point - -@cindex floating point, SPARC (@sc{ieee}) -@cindex SPARC floating point (@sc{ieee}) -The Sparc uses @sc{ieee} floating-point numbers. - -@node Sparc-Directives, , Sparc-Float, Sparc-Dependent -_CHAPSEC__(1+_GENERIC__) Sparc Machine Directives - -@cindex SPARC machine directives -@cindex machine directives, SPARC -The Sparc version of @code{_AS__} supports the following additional -machine directives: - -@table @code -@item .common -@cindex @code{common} directive, SPARC -This must be followed by a symbol name, a positive number, and -@code{"bss"}. This behaves somewhat like @code{.comm}, but the -syntax is different. - -@item .half -@cindex @code{half} directive, SPARC -This is functionally identical to @code{.short}. - -@item .proc -@cindex @code{proc} directive, SPARC -This directive is ignored. Any text following it on the same -line is also ignored. - -@item .reserve -@cindex @code{reserve} directive, SPARC -This must be followed by a symbol name, a positive number, and -@code{"bss"}. This behaves somewhat like @code{.lcomm}, but the -syntax is different. - -@item .seg -@cindex @code{seg} directive, SPARC -This must be followed by @code{"text"}, @code{"data"}, or -@code{"data1"}. It behaves like @code{.text}, @code{.data}, or -@code{.data 1}. - -@item .skip -@cindex @code{skip} directive, SPARC -This is functionally identical to the @code{.space} directive. - -@item .word -@cindex @code{word} directive, SPARC -On the Sparc, the .word directive produces 32 bit values, -instead of the 16 bit values it produces on many other machines. -@end table - -_fi__(_SPARC__) -_if__(_I80386__) -_if__(_GENERIC__) -@c FIXME! Conditionalize for all combinations in this section -@node i386-Dependent, , Sparc-Dependent, Machine Dependent -_fi__(_GENERIC__) -_CHAPSEC__(0+_GENERIC__) 80386 Dependent Features - -@cindex i386 support -@cindex i80306 support -@menu -* i386-Options:: Options -* i386-Syntax:: AT&T Syntax versus Intel Syntax -* i386-Opcodes:: Opcode Naming -* i386-Regs:: Register Naming -* i386-prefixes:: Opcode Prefixes -* i386-Memory:: Memory References -* i386-jumps:: Handling of Jump Instructions -* i386-Float:: Floating Point -* i386-Notes:: Notes -@end menu - -@node i386-Options, i386-Syntax, i386-Dependent, i386-Dependent -_CHAPSEC__(1+_GENERIC__) Options - -@cindex options for i386 (none) -@cindex i386 options (none) -The 80386 has no machine dependent options. - -@node i386-Syntax, i386-Opcodes, i386-Options, i386-Dependent -_CHAPSEC__(1+_GENERIC__) AT&T Syntax versus Intel Syntax - -@cindex i386 syntax compatibility -@cindex syntax compatibility, i386 -In order to maintain compatibility with the output of @code{_GCC__}, -@code{_AS__} supports AT&T System V/386 assembler syntax. This is quite -different from Intel syntax. We mention these differences because -almost all 80386 documents used only Intel syntax. Notable differences -between the two syntaxes are: - -@itemize @bullet -@item -@cindex immediate operands, i386 -@cindex i386 immediate operands -@cindex register operands, i386 -@cindex i386 register operands -@cindex jump/call operands, i386 -@cindex i386 jump/call operands -@cindex operand delimiters, i386 -AT&T immediate operands are preceded by @samp{$}; Intel immediate -operands are undelimited (Intel @samp{push 4} is AT&T @samp{pushl $4}). -AT&T register operands are preceded by @samp{%}; Intel register operands -are undelimited. AT&T absolute (as opposed to PC relative) jump/call -operands are prefixed by @samp{*}; they are undelimited in Intel syntax. - -@item -@cindex i386 source, destination operands -@cindex source, destination operands; i386 -AT&T and Intel syntax use the opposite order for source and destination -operands. Intel @samp{add eax, 4} is @samp{addl $4, %eax}. The -@samp{source, dest} convention is maintained for compatibility with -previous Unix assemblers. - -@item -@cindex opcode suffixes, i386 -@cindex sizes operands, i386 -@cindex i386 size suffixes -In AT&T syntax the size of memory operands is determined from the last -character of the opcode name. Opcode suffixes of @samp{b}, @samp{w}, -and @samp{l} specify byte (8-bit), word (16-bit), and long (32-bit) -memory references. Intel syntax accomplishes this by prefixes memory -operands (@emph{not} the opcodes themselves) with @samp{byte ptr}, -@samp{word ptr}, and @samp{dword ptr}. Thus, Intel @samp{mov al, byte -ptr @var{foo}} is @samp{movb @var{foo}, %al} in AT&T syntax. - -@item -@cindex return instructions, i386 -@cindex i386 jump, call, return -Immediate form long jumps and calls are -@samp{lcall/ljmp $@var{section}, $@var{offset}} in AT&T syntax; the -Intel syntax is -@samp{call/jmp far @var{section}:@var{offset}}. Also, the far return -instruction -is @samp{lret $@var{stack-adjust}} in AT&T syntax; Intel syntax is -@samp{ret far @var{stack-adjust}}. - -@item -@cindex sections, i386 -@cindex i386 sections -The AT&T assembler does not provide support for multiple section -programs. Unix style systems expect all programs to be single sections. -@end itemize - -@node i386-Opcodes, i386-Regs, i386-Syntax, i386-Dependent -_CHAPSEC__(1+_GENERIC__) Opcode Naming - -@cindex i386 opcode naming -@cindex opcode naming, i386 -Opcode names are suffixed with one character modifiers which specify the -size of operands. The letters @samp{b}, @samp{w}, and @samp{l} specify -byte, word, and long operands. If no suffix is specified by an -instruction and it contains no memory operands then @code{_AS__} tries to -fill in the missing suffix based on the destination register operand -(the last one by convention). Thus, @samp{mov %ax, %bx} is equivalent -to @samp{movw %ax, %bx}; also, @samp{mov $1, %bx} is equivalent to -@samp{movw $1, %bx}. Note that this is incompatible with the AT&T Unix -assembler which assumes that a missing opcode suffix implies long -operand size. (This incompatibility does not affect compiler output -since compilers always explicitly specify the opcode suffix.) - -Almost all opcodes have the same names in AT&T and Intel format. There -are a few exceptions. The sign extend and zero extend instructions need -two sizes to specify them. They need a size to sign/zero extend -@emph{from} and a size to zero extend @emph{to}. This is accomplished -by using two opcode suffixes in AT&T syntax. Base names for sign extend -and zero extend are @samp{movs@dots{}} and @samp{movz@dots{}} in AT&T -syntax (@samp{movsx} and @samp{movzx} in Intel syntax). The opcode -suffixes are tacked on to this base name, the @emph{from} suffix before -the @emph{to} suffix. Thus, @samp{movsbl %al, %edx} is AT&T syntax for -``move sign extend @emph{from} %al @emph{to} %edx.'' Possible suffixes, -thus, are @samp{bl} (from byte to long), @samp{bw} (from byte to word), -and @samp{wl} (from word to long). - -@cindex conversion instructions, i386 -@cindex i386 conversion instructions -The Intel-syntax conversion instructions - -@itemize @bullet -@item -@samp{cbw} --- sign-extend byte in @samp{%al} to word in @samp{%ax}, - -@item -@samp{cwde} --- sign-extend word in @samp{%ax} to long in @samp{%eax}, - -@item -@samp{cwd} --- sign-extend word in @samp{%ax} to long in @samp{%dx:%ax}, - -@item -@samp{cdq} --- sign-extend dword in @samp{%eax} to quad in @samp{%edx:%eax}, -@end itemize - -@noindent -are called @samp{cbtw}, @samp{cwtl}, @samp{cwtd}, and @samp{cltd} in -AT&T naming. @code{_AS__} accepts either naming for these instructions. - -@cindex jump instructions, i386 -@cindex call instructions, i386 -Far call/jump instructions are @samp{lcall} and @samp{ljmp} in -AT&T syntax, but are @samp{call far} and @samp{jump far} in Intel -convention. - -@node i386-Regs, i386-prefixes, i386-Opcodes, i386-Dependent -_CHAPSEC__(1+_GENERIC__) Register Naming - -@cindex i386 registers -@cindex registers, i386 -Register operands are always prefixes with @samp{%}. The 80386 registers -consist of - -@itemize @bullet -@item -the 8 32-bit registers @samp{%eax} (the accumulator), @samp{%ebx}, -@samp{%ecx}, @samp{%edx}, @samp{%edi}, @samp{%esi}, @samp{%ebp} (the -frame pointer), and @samp{%esp} (the stack pointer). - -@item -the 8 16-bit low-ends of these: @samp{%ax}, @samp{%bx}, @samp{%cx}, -@samp{%dx}, @samp{%di}, @samp{%si}, @samp{%bp}, and @samp{%sp}. - -@item -the 8 8-bit registers: @samp{%ah}, @samp{%al}, @samp{%bh}, -@samp{%bl}, @samp{%ch}, @samp{%cl}, @samp{%dh}, and @samp{%dl} (These -are the high-bytes and low-bytes of @samp{%ax}, @samp{%bx}, -@samp{%cx}, and @samp{%dx}) - -@item -the 6 section registers @samp{%cs} (code section), @samp{%ds} -(data section), @samp{%ss} (stack section), @samp{%es}, @samp{%fs}, -and @samp{%gs}. - -@item -the 3 processor control registers @samp{%cr0}, @samp{%cr2}, and -@samp{%cr3}. - -@item -the 6 debug registers @samp{%db0}, @samp{%db1}, @samp{%db2}, -@samp{%db3}, @samp{%db6}, and @samp{%db7}. - -@item -the 2 test registers @samp{%tr6} and @samp{%tr7}. - -@item -the 8 floating point register stack @samp{%st} or equivalently -@samp{%st(0)}, @samp{%st(1)}, @samp{%st(2)}, @samp{%st(3)}, -@samp{%st(4)}, @samp{%st(5)}, @samp{%st(6)}, and @samp{%st(7)}. -@end itemize - -@node i386-prefixes, i386-Memory, i386-Regs, i386-Dependent -_CHAPSEC__(1+_GENERIC__) Opcode Prefixes - -@cindex i386 opcode prefixes -@cindex opcode prefixes, i386 -@cindex prefixes, i386 -Opcode prefixes are used to modify the following opcode. They are used -to repeat string instructions, to provide section overrides, to perform -bus lock operations, and to give operand and address size (16-bit -operands are specified in an instruction by prefixing what would -normally be 32-bit operands with a ``operand size'' opcode prefix). -Opcode prefixes are usually given as single-line instructions with no -operands, and must directly precede the instruction they act upon. For -example, the @samp{scas} (scan string) instruction is repeated with: -@smallexample - repne - scas -@end smallexample - -Here is a list of opcode prefixes: - -@itemize @bullet -@item -@cindex section override prefixes, i386 -Section override prefixes @samp{cs}, @samp{ds}, @samp{ss}, @samp{es}, -@samp{fs}, @samp{gs}. These are automatically added by specifying -using the @var{section}:@var{memory-operand} form for memory references. - -@item -@cindex size prefixes, i386 -Operand/Address size prefixes @samp{data16} and @samp{addr16} -change 32-bit operands/addresses into 16-bit operands/addresses. Note -that 16-bit addressing modes (i.e. 8086 and 80286 addressing modes) -are not supported (yet). - -@item -@cindex bus lock prefixes, i386 -@cindex inhibiting interrupts, i386 -The bus lock prefix @samp{lock} inhibits interrupts during -execution of the instruction it precedes. (This is only valid with -certain instructions; see a 80386 manual for details). - -@item -@cindex coprocessor wait, i386 -The wait for coprocessor prefix @samp{wait} waits for the -coprocessor to complete the current instruction. This should never be -needed for the 80386/80387 combination. - -@item -@cindex repeat prefixes, i386 -The @samp{rep}, @samp{repe}, and @samp{repne} prefixes are added -to string instructions to make them repeat @samp{%ecx} times. -@end itemize - -@node i386-Memory, i386-jumps, i386-prefixes, i386-Dependent -_CHAPSEC__(1+_GENERIC__) Memory References - -@cindex i386 memory references -@cindex memory references, i386 -An Intel syntax indirect memory reference of the form - -@smallexample -@var{section}:[@var{base} + @var{index}*@var{scale} + @var{disp}] -@end smallexample - -@noindent -is translated into the AT&T syntax - -@smallexample -@var{section}:@var{disp}(@var{base}, @var{index}, @var{scale}) -@end smallexample - -@noindent -where @var{base} and @var{index} are the optional 32-bit base and -index registers, @var{disp} is the optional displacement, and -@var{scale}, taking the values 1, 2, 4, and 8, multiplies @var{index} -to calculate the address of the operand. If no @var{scale} is -specified, @var{scale} is taken to be 1. @var{section} specifies the -optional section register for the memory operand, and may override the -default section register (see a 80386 manual for section register -defaults). Note that section overrides in AT&T syntax @emph{must} have -be preceded by a @samp{%}. If you specify a section override which -coincides with the default section register, @code{_AS__} will @emph{not} -output any section register override prefixes to assemble the given -instruction. Thus, section overrides can be specified to emphasize which -section register is used for a given memory operand. - -Here are some examples of Intel and AT&T style memory references: - -@table @asis -@item AT&T: @samp{-4(%ebp)}, Intel: @samp{[ebp - 4]} -@var{base} is @samp{%ebp}; @var{disp} is @samp{-4}. @var{section} is -missing, and the default section is used (@samp{%ss} for addressing with -@samp{%ebp} as the base register). @var{index}, @var{scale} are both missing. - -@item AT&T: @samp{foo(,%eax,4)}, Intel: @samp{[foo + eax*4]} -@var{index} is @samp{%eax} (scaled by a @var{scale} 4); @var{disp} is -@samp{foo}. All other fields are missing. The section register here -defaults to @samp{%ds}. - -@item AT&T: @samp{foo(,1)}; Intel @samp{[foo]} -This uses the value pointed to by @samp{foo} as a memory operand. -Note that @var{base} and @var{index} are both missing, but there is only -@emph{one} @samp{,}. This is a syntactic exception. - -@item AT&T: @samp{%gs:foo}; Intel @samp{gs:foo} -This selects the contents of the variable @samp{foo} with section -register @var{section} being @samp{%gs}. -@end table - -Absolute (as opposed to PC relative) call and jump operands must be -prefixed with @samp{*}. If no @samp{*} is specified, @code{_AS__} will -always choose PC relative addressing for jump/call labels. - -Any instruction that has a memory operand @emph{must} specify its size (byte, -word, or long) with an opcode suffix (@samp{b}, @samp{w}, or @samp{l}, -respectively). - -@node i386-jumps, i386-Float, i386-Memory, i386-Dependent -_CHAPSEC__(1+_GENERIC__) Handling of Jump Instructions - -@cindex jump optimization, i386 -@cindex i386 jump optimization -Jump instructions are always optimized to use the smallest possible -displacements. This is accomplished by using byte (8-bit) displacement -jumps whenever the target is sufficiently close. If a byte displacement -is insufficient a long (32-bit) displacement is used. We do not support -word (16-bit) displacement jumps (i.e. prefixing the jump instruction -with the @samp{addr16} opcode prefix), since the 80386 insists upon masking -@samp{%eip} to 16 bits after the word displacement is added. - -Note that the @samp{jcxz}, @samp{jecxz}, @samp{loop}, @samp{loopz}, -@samp{loope}, @samp{loopnz} and @samp{loopne} instructions only come in -byte displacements, so that it is possible that use of these -instructions (@code{_GCC__} does not use them) will cause the assembler to -print an error message (and generate incorrect code). The AT&T 80386 -assembler tries to get around this problem by expanding @samp{jcxz foo} to -@smallexample - jcxz cx_zero - jmp cx_nonzero -cx_zero: jmp foo -cx_nonzero: -@end smallexample - -@node i386-Float, i386-Notes, i386-jumps, i386-Dependent -_CHAPSEC__(1+_GENERIC__) Floating Point - -@cindex i386 floating point -@cindex floating point, i386 -All 80387 floating point types except packed BCD are supported. -(BCD support may be added without much difficulty). These data -types are 16-, 32-, and 64- bit integers, and single (32-bit), -double (64-bit), and extended (80-bit) precision floating point. -Each supported type has an opcode suffix and a constructor -associated with it. Opcode suffixes specify operand's data -types. Constructors build these data types into memory. - -@itemize @bullet -@item -@cindex @code{float} directive, i386 -@cindex @code{single} directive, i386 -@cindex @code{double} directive, i386 -@cindex @code{tfloat} directive, i386 -Floating point constructors are @samp{.float} or @samp{.single}, -@samp{.double}, and @samp{.tfloat} for 32-, 64-, and 80-bit formats. -These correspond to opcode suffixes @samp{s}, @samp{l}, and @samp{t}. -@samp{t} stands for temporary real, and that the 80387 only supports -this format via the @samp{fldt} (load temporary real to stack top) and -@samp{fstpt} (store temporary real and pop stack) instructions. - -@item -@cindex @code{word} directive, i386 -@cindex @code{long} directive, i386 -@cindex @code{int} directive, i386 -@cindex @code{quad} directive, i386 -Integer constructors are @samp{.word}, @samp{.long} or @samp{.int}, and -@samp{.quad} for the 16-, 32-, and 64-bit integer formats. The corresponding -opcode suffixes are @samp{s} (single), @samp{l} (long), and @samp{q} -(quad). As with the temporary real format the 64-bit @samp{q} format is -only present in the @samp{fildq} (load quad integer to stack top) and -@samp{fistpq} (store quad integer and pop stack) instructions. -@end itemize - -Register to register operations do not require opcode suffixes, -so that @samp{fst %st, %st(1)} is equivalent to @samp{fstl %st, %st(1)}. - -@cindex i386 @code{fwait} instruction -@cindex @code{fwait instruction}, i386 -Since the 80387 automatically synchronizes with the 80386 @samp{fwait} -instructions are almost never needed (this is not the case for the -80286/80287 and 8086/8087 combinations). Therefore, @code{_AS__} suppresses -the @samp{fwait} instruction whenever it is implicitly selected by one -of the @samp{fn@dots{}} instructions. For example, @samp{fsave} and -@samp{fnsave} are treated identically. In general, all the @samp{fn@dots{}} -instructions are made equivalent to @samp{f@dots{}} instructions. If -@samp{fwait} is desired it must be explicitly coded. - -@node i386-Notes, , i386-Float, i386-Dependent -_CHAPSEC__(1+_GENERIC__) Notes - -@cindex i386 @code{mul}, @code{imul} instructions -@cindex @code{mul} instruction, i386 -@cindex @code{imul} instruction, i386 -There is some trickery concerning the @samp{mul} and @samp{imul} -instructions that deserves mention. The 16-, 32-, and 64-bit expanding -multiplies (base opcode @samp{0xf6}; extension 4 for @samp{mul} and 5 -for @samp{imul}) can be output only in the one operand form. Thus, -@samp{imul %ebx, %eax} does @emph{not} select the expanding multiply; -the expanding multiply would clobber the @samp{%edx} register, and this -would confuse @code{_GCC__} output. Use @samp{imul %ebx} to get the -64-bit product in @samp{%edx:%eax}. - -We have added a two operand form of @samp{imul} when the first operand -is an immediate mode expression and the second operand is a register. -This is just a shorthand, so that, multiplying @samp{%eax} by 69, for -example, can be done with @samp{imul $69, %eax} rather than @samp{imul -$69, %eax, %eax}. - -_fi__(_I80386__) -_if__(0) -@c pesch@cygnus.com: we ignore the following chapters, since internals are -@c changing rapidly. These may need to be moved to another -@c book anyhow, if we adopt the model of user/modifier -@c books. -@node Maintenance, Retargeting, _MACH_DEP__, Top -@chapter Maintaining the Assembler -[[this chapter is still being built]] - -@section Design -We had these goals, in descending priority: -@table @b -@item Accuracy. -For every program composed by a compiler, @code{_AS__} should emit -``correct'' code. This leaves some latitude in choosing addressing -modes, order of @code{relocation_info} structures in the object -file, @emph{etc}. - -@item Speed, for usual case. -By far the most common use of @code{_AS__} will be assembling compiler -emissions. - -@item Upward compatibility for existing assembler code. -Well @dots{} we don't support Vax bit fields but everything else -seems to be upward compatible. - -@item Readability. -The code should be maintainable with few surprises. (JF: ha!) - -@end table - -We assumed that disk I/O was slow and expensive while memory was -fast and access to memory was cheap. We expect the in-memory data -structures to be less than 10 times the size of the emitted object -file. (Contrast this with the C compiler where in-memory structures -might be 100 times object file size!) -This suggests: -@itemize @bullet -@item -Try to read the source file from disk only one time. For other -reasons, we keep large chunks of the source file in memory during -assembly so this is not a problem. Also the assembly algorithm -should only scan the source text once if the compiler composed the -text according to a few simple rules. -@item -Emit the object code bytes only once. Don't store values and then -backpatch later. -@item -Build the object file in memory and do direct writes to disk of -large buffers. -@end itemize - -RMS suggested a one-pass algorithm which seems to work well. By not -parsing text during a second pass considerable time is saved on -large programs (@emph{e.g.} the sort of C program @code{yacc} would -emit). - -It happened that the data structures needed to emit relocation -information to the object file were neatly subsumed into the data -structures that do backpatching of addresses after pass 1. - -Many of the functions began life as re-usable modules, loosely -connected. RMS changed this to gain speed. For example, input -parsing routines which used to work on pre-sanitized strings now -must parse raw data. Hence they have to import knowledge of the -assemblers' comment conventions @emph{etc}. - -@section Deprecated Feature(?)s -We have stopped supporting some features: -@itemize @bullet -@item -@code{.org} statements must have @b{defined} expressions. -@item -Vax Bit fields (@kbd{:} operator) are entirely unsupported. -@end itemize - -It might be a good idea to not support these features in a future release: -@itemize @bullet -@item -@kbd{#} should begin a comment, even in column 1. -@item -Why support the logical line & file concept any more? -@item -Subsections are a good candidate for flushing. -Depends on which compilers need them I guess. -@end itemize - -@section Bugs, Ideas, Further Work -Clearly the major improvement is DON'T USE A TEXT-READING -ASSEMBLER for the back end of a compiler. It is much faster to -interpret binary gobbledygook from a compiler's tables than to -ask the compiler to write out human-readable code just so the -assembler can parse it back to binary. - -Assuming you use @code{_AS__} for human written programs: here are -some ideas: -@itemize @bullet -@item -Document (here) @code{APP}. -@item -Take advantage of knowing no spaces except after opcode -to speed up @code{_AS__}. (Modify @code{app.c} to flush useless spaces: -only keep space/tabs at begin of line or between 2 -symbols.) -@item -Put pointers in this documentation to @file{a.out} documentation. -@item -Split the assembler into parts so it can gobble direct binary -from @emph{e.g.} @code{cc}. It is silly for@code{cc} to compose text -just so @code{_AS__} can parse it back to binary. -@item -Rewrite hash functions: I want a more modular, faster library. -@item -Clean up LOTS of code. -@item -Include all the non-@file{.c} files in the maintenance chapter. -@item -Document flonums. -@item -Implement flonum short literals. -@item -Change all talk of expression operands to expression quantities, -or perhaps to expression arguments. -@item -Implement pass 2. -@item -Whenever a @code{.text} or @code{.data} statement is seen, we close -of the current frag with an imaginary @code{.fill 0}. This is -because we only have one obstack for frags, and we can't grow new -frags for a new subsection, then go back to the old subsection and -append bytes to the old frag. All this nonsense goes away if we -give each subsection its own obstack. It makes code simpler in -about 10 places, but nobody has bothered to do it because C compiler -output rarely changes subsections (compared to ending frags with -relaxable addresses, which is common). -@end itemize - -@section Sources -@c The following files in the @file{_AS__} directory -@c are symbolic links to other files, of -@c the same name, in a different directory. -@c @itemize @bullet -@c @item -@c @file{atof_generic.c} -@c @item -@c @file{atof_vax.c} -@c @item -@c @file{flonum_const.c} -@c @item -@c @file{flonum_copy.c} -@c @item -@c @file{flonum_get.c} -@c @item -@c @file{flonum_multip.c} -@c @item -@c @file{flonum_normal.c} -@c @item -@c @file{flonum_print.c} -@c @end itemize - -Here is a list of the source files in the @file{_AS__} directory. - -@table @file -@item app.c -This contains the pre-processing phase, which deletes comments, -handles whitespace, etc. This was recently re-written, since app -used to be a separate program, but RMS wanted it to be inline. - -@item append.c -This is a subroutine to append a string to another string returning a -pointer just after the last @code{char} appended. (JF: All these -little routines should probably all be put in one file.) - -@item as.c -Here you will find the main program of the assembler @code{_AS__}. - -@item expr.c -This is a branch office of @file{read.c}. This understands -expressions, arguments. Inside @code{_AS__}, arguments are called -(expression) @emph{operands}. This is confusing, because we also talk -(elsewhere) about instruction @emph{operands}. Also, expression -operands are called @emph{quantities} explicitly to avoid confusion -with instruction operands. What a mess. - -@item frags.c -This implements the @b{frag} concept. Without frags, finding the -right size for branch instructions would be a lot harder. - -@item hash.c -This contains the symbol table, opcode table @emph{etc.} hashing -functions. - -@item hex_value.c -This is a table of values of digits, for use in atoi() type -functions. Could probably be flushed by using calls to strtol(), or -something similar. - -@item input-file.c -This contains Operating system dependent source file reading -routines. Since error messages often say where we are in reading -the source file, they live here too. Since @code{_AS__} is intended to -run under GNU and Unix only, this might be worth flushing. Anyway, -almost all C compilers support stdio. - -@item input-scrub.c -This deals with calling the pre-processor (if needed) and feeding the -chunks back to the rest of the assembler the right way. - -@item messages.c -This contains operating system independent parts of fatal and -warning message reporting. See @file{append.c} above. - -@item output-file.c -This contains operating system dependent functions that write an -object file for @code{_AS__}. See @file{input-file.c} above. - -@item read.c -This implements all the directives of @code{_AS__}. This also deals -with passing input lines to the machine dependent part of the -assembler. - -@item strstr.c -This is a C library function that isn't in most C libraries yet. -See @file{append.c} above. - -@item subsegs.c -This implements subsections. - -@item symbols.c -This implements symbols. - -@item write.c -This contains the code to perform relaxation, and to write out -the object file. It is mostly operating system independent, but -different OSes have different object file formats in any case. - -@item xmalloc.c -This implements @code{malloc()} or bust. See @file{append.c} above. - -@item xrealloc.c -This implements @code{realloc()} or bust. See @file{append.c} above. - -@item atof-generic.c -The following files were taken from a machine-independent subroutine -library for manipulating floating point numbers and very large -integers. - -@file{atof-generic.c} turns a string into a flonum internal format -floating-point number. - -@item flonum-const.c -This contains some potentially useful floating point numbers in -flonum format. - -@item flonum-copy.c -This copies a flonum. - -@item flonum-multip.c -This multiplies two flonums together. - -@item bignum-copy.c -This copies a bignum. - -@end table - -Here is a table of all the machine-specific files (this includes -both source and header files). Typically, there is a -@var{machine}.c file, a @var{machine}-opcode.h file, and an -atof-@var{machine}.c file. The @var{machine}-opcode.h file should -be identical to the one used by GDB (which uses it for disassembly.) - -@table @file - -@item atof-ieee.c -This contains code to turn a flonum into a ieee literal constant. -This is used by tye 680x0, 32x32, sparc, and i386 versions of @code{_AS__}. - -@item i386-opcode.h -This is the opcode-table for the i386 version of the assembler. - -@item i386.c -This contains all the code for the i386 version of the assembler. - -@item i386.h -This defines constants and macros used by the i386 version of the assembler. - -@item m-generic.h -generic 68020 header file. To be linked to m68k.h on a -non-sun3, non-hpux system. - -@item m-sun2.h -68010 header file for Sun2 workstations. Not well tested. To be linked -to m68k.h on a sun2. (See also @samp{-DSUN_ASM_SYNTAX} in the -@file{Makefile}.) - -@item m-sun3.h -68020 header file for Sun3 workstations. To be linked to m68k.h before -compiling on a Sun3 system. (See also @samp{-DSUN_ASM_SYNTAX} in the -@file{Makefile}.) - -@item m-hpux.h -68020 header file for a HPUX (system 5?) box. Which box, which -version of HPUX, etc? I don't know. - -@item m68k.h -A hard- or symbolic- link to one of @file{m-generic.h}, -@file{m-hpux.h} or @file{m-sun3.h} depending on which kind of -680x0 you are assembling for. (See also @samp{-DSUN_ASM_SYNTAX} in the -@file{Makefile}.) - -@item m68k-opcode.h -Opcode table for 68020. This is now a link to the opcode table -in the @code{GDB} source directory. - -@item m68k.c -All the mc680x0 code, in one huge, slow-to-compile file. - -@item ns32k.c -This contains the code for the ns32032/ns32532 version of the -assembler. - -@item ns32k-opcode.h -This contains the opcode table for the ns32032/ns32532 version -of the assembler. - -@item vax-inst.h -Vax specific file for describing Vax operands and other Vax-ish things. - -@item vax-opcode.h -Vax opcode table. - -@item vax.c -Vax specific parts of @code{_AS__}. Also includes the former files -@file{vax-ins-parse.c}, @file{vax-reg-parse.c} and @file{vip-op.c}. - -@item atof-vax.c -Turns a flonum into a Vax constant. - -@item vms.c -This file contains the special code needed to put out a VMS -style object file for the Vax. - -@end table - -Here is a list of the header files in the source directory. -(Warning: This section may not be very accurate. I didn't -write the header files; I just report them.) Also note that I -think many of these header files could be cleaned up or -eliminated. - -@table @file - -@item a.out.h -This describes the structures used to create the binary header data -inside the object file. Perhaps we should use the one in -@file{/usr/include}? - -@item as.h -This defines all the globally useful things, and pulls in _0___1__ -and _0___1__. - -@item bignum.h -This defines macros useful for dealing with bignums. - -@item expr.h -Structure and macros for dealing with expression() - -@item flonum.h -This defines the structure for dealing with floating point -numbers. It #includes @file{bignum.h}. - -@item frags.h -This contains macro for appending a byte to the current frag. - -@item hash.h -Structures and function definitions for the hashing functions. - -@item input-file.h -Function headers for the input-file.c functions. - -@item md.h -structures and function headers for things defined in the -machine dependent part of the assembler. - -@item obstack.h -This is the GNU systemwide include file for manipulating obstacks. -Since nobody is running under real GNU yet, we include this file. - -@item read.h -Macros and function headers for reading in source files. - -@item struct-symbol.h -Structure definition and macros for dealing with the _AS__ -internal form of a symbol. - -@item subsegs.h -structure definition for dealing with the numbered subsections -of the text and data sections. - -@item symbols.h -Macros and function headers for dealing with symbols. - -@item write.h -Structure for doing section fixups. -@end table - -@comment ~subsection Test Directory -@comment (Note: The test directory seems to have disappeared somewhere -@comment along the line. If you want it, you'll probably have to find a -@comment REALLY OLD dump tape~dots{}) -@comment -@comment The ~file{test/} directory is used for regression testing. -@comment After you modify ~@code{_AS__}, you can get a quick go/nogo -@comment confidence test by running the new ~@code{_AS__} over the source -@comment files in this directory. You use a shell script ~file{test/do}. -@comment -@comment The tests in this suite are evolving. They are not comprehensive. -@comment They have, however, caught hundreds of bugs early in the debugging -@comment cycle of ~@code{_AS__}. Most test statements in this suite were naturally -@comment selected: they were used to demonstrate actual ~@code{_AS__} bugs rather -@comment than being written ~i{a prioi}. -@comment -@comment Another testing suggestion: over 30 bugs have been found simply by -@comment running examples from this manual through ~@code{_AS__}. -@comment Some examples in this manual are selected -@comment to distinguish boundary conditions; they are good for testing ~@code{_AS__}. -@comment -@comment ~subsubsection Regression Testing -@comment Each regression test involves assembling a file and comparing the -@comment actual output of ~@code{_AS__} to ``known good'' output files. Both -@comment the object file and the error/warning message file (stderr) are -@comment inspected. Optionally the ~@code{_AS__} exit status may be checked. -@comment Discrepencies are reported. Each discrepency means either that -@comment you broke some part of ~@code{_AS__} or that the ``known good'' files -@comment are now out of date and should be changed to reflect the new -@comment definition of ``good''. -@comment -@comment Each regression test lives in its own directory, in a tree -@comment rooted in the directory ~file{test/}. Each such directory -@comment has a name ending in ~file{.ret}, where `ret' stands for -@comment REgression Test. The ~file{.ret} ending allows ~code{find -@comment (1)} to find all regression tests in the tree, without -@comment needing to list them explicitly. -@comment -@comment Any ~file{.ret} directory must contain a file called -@comment ~file{input} which is the source file to assemble. During -@comment testing an object file ~file{output} is created, as well as -@comment a file ~file{stdouterr} which contains the output to both -@comment stderr and stderr. If there is a file ~file{output.good} in -@comment the directory, and if ~file{output} contains exactly the -@comment same data as ~file{output.good}, the file ~file{output} is -@comment deleted. Likewise ~file{stdouterr} is removed if it exactly -@comment matches a file ~file{stdouterr.good}. If file -@comment ~file{status.good} is present, containing a decimal number -@comment before a newline, the exit status of ~@code{_AS__} is compared -@comment to this number. If the status numbers are not equal, a file -@comment ~file{status} is written to the directory, containing the -@comment actual status as a decimal number followed by newline. -@comment -@comment Should any of the ~file{*.good} files fail to match their corresponding -@comment actual files, this is noted by a 1-line message on the screen during -@comment the regression test, and you can use ~@code{find (1)} to find any -@comment files named ~file{status}, ~file {output} or ~file{stdouterr}. -@comment -@node Retargeting, Copying, Maintenance, Top -@chapter Teaching the Assembler about a New Machine - -This chapter describes the steps required in order to make the -assembler work with another machine's assembly language. This -chapter is not complete, and only describes the steps in the -broadest terms. You should look at the source for the -currently supported machine in order to discover some of the -details that aren't mentioned here. - -You should create a new file called @file{@var{machine}.c}, and -add the appropriate lines to the file @file{Makefile} so that -you can compile your new version of the assembler. This should -be straighforward; simply add lines similar to the ones there -for the four current versions of the assembler. - -If you want to be compatible with GDB, (and the current -machine-dependent versions of the assembler), you should create -a file called @file{@var{machine}-opcode.h} which should -contain all the information about the names of the machine -instructions, their opcodes, and what addressing modes they -support. If you do this right, the assembler and GDB can share -this file, and you'll only have to write it once. Note that -while you're writing @code{_AS__}, you may want to use an -independent program (if you have access to one), to make sure -that @code{_AS__} is emitting the correct bytes. Since @code{_AS__} -and @code{GDB} share the opcode table, an incorrect opcode -table entry may make invalid bytes look OK when you disassemble -them with @code{GDB}. - -@section Functions You will Have to Write - -Your file @file{@var{machine}.c} should contain definitions for -the following functions and variables. It will need to include -some header files in order to use some of the structures -defined in the machine-independent part of the assembler. The -needed header files are mentioned in the descriptions of the -functions that will need them. - -@table @code - -@item long omagic; -This long integer holds the value to place at the beginning of -the @file{a.out} file. It is usually @samp{OMAGIC}, except on -machines that store additional information in the magic-number. - -@item char comment_chars[]; -This character array holds the values of the characters that -start a comment anywhere in a line. Comments are stripped off -automatically by the machine independent part of the -assembler. Note that the @samp{/*} will always start a -comment, and that only @samp{*/} will end a comment started by -@samp{*/}. - -@item char line_comment_chars[]; -This character array holds the values of the chars that start a -comment only if they are the first (non-whitespace) character -on a line. If the character @samp{#} does not appear in this -list, you may get unexpected results. (Various -machine-independent parts of the assembler treat the comments -@samp{#APP} and @samp{#NO_APP} specially, and assume that lines -that start with @samp{#} are comments.) - -@item char EXP_CHARS[]; -This character array holds the letters that can separate the -mantissa and the exponent of a floating point number. Typical -values are @samp{e} and @samp{E}. - -@item char FLT_CHARS[]; -This character array holds the letters that--when they appear -immediately after a leading zero--indicate that a number is a -floating-point number. (Sort of how 0x indicates that a -hexadecimal number follows.) - -@item pseudo_typeS md_pseudo_table[]; -(@var{pseudo_typeS} is defined in @file{md.h}) -This array contains a list of the machine_dependent directives -the assembler must support. It contains the name of each -pseudo op (Without the leading @samp{.}), a pointer to a -function to be called when that directive is encountered, and -an integer argument to be passed to that function. - -@item void md_begin(void) -This function is called as part of the assembler's -initialization. It should do any initialization required by -any of your other routines. - -@item int md_parse_option(char **optionPTR, int *argcPTR, char ***argvPTR) -This routine is called once for each option on the command line -that the machine-independent part of @code{_AS__} does not -understand. This function should return non-zero if the option -pointed to by @var{optionPTR} is a valid option. If it is not -a valid option, this routine should return zero. The variables -@var{argcPTR} and @var{argvPTR} are provided in case the option -requires a filename or something similar as an argument. If -the option is multi-character, @var{optionPTR} should be -advanced past the end of the option, otherwise every letter in -the option will be treated as a separate single-character -option. - -@item void md_assemble(char *string) -This routine is called for every machine-dependent -non-directive line in the source file. It does all the real -work involved in reading the opcode, parsing the operands, -etc. @var{string} is a pointer to a null-terminated string, -that comprises the input line, with all excess whitespace and -comments removed. - -@item void md_number_to_chars(char *outputPTR,long value,int nbytes) -This routine is called to turn a C long int, short int, or char -into the series of bytes that represents that number on the -target machine. @var{outputPTR} points to an array where the -result should be stored; @var{value} is the value to store; and -@var{nbytes} is the number of bytes in 'value' that should be -stored. - -@item void md_number_to_imm(char *outputPTR,long value,int nbytes) -This routine is called to turn a C long int, short int, or char -into the series of bytes that represent an immediate value on -the target machine. It is identical to the function @code{md_number_to_chars}, -except on NS32K machines.@refill - -@item void md_number_to_disp(char *outputPTR,long value,int nbytes) -This routine is called to turn a C long int, short int, or char -into the series of bytes that represent an displacement value on -the target machine. It is identical to the function @code{md_number_to_chars}, -except on NS32K machines.@refill - -@item void md_number_to_field(char *outputPTR,long value,int nbytes) -This routine is identical to @code{md_number_to_chars}, -except on NS32K machines. - -@item void md_ri_to_chars(struct relocation_info *riPTR,ri) -(@code{struct relocation_info} is defined in @file{a.out.h}) -This routine emits the relocation info in @var{ri} -in the appropriate bit-pattern for the target machine. -The result should be stored in the location pointed -to by @var{riPTR}. This routine may be a no-op unless you are -attempting to do cross-assembly. - -@item char *md_atof(char type,char *outputPTR,int *sizePTR) -This routine turns a series of digits into the appropriate -internal representation for a floating-point number. -@var{type} is a character from @var{FLT_CHARS[]} that describes -what kind of floating point number is wanted; @var{outputPTR} -is a pointer to an array that the result should be stored in; -and @var{sizePTR} is a pointer to an integer where the size (in -bytes) of the result should be stored. This routine should -return an error message, or an empty string (not (char *)0) for -success. - -@item int md_short_jump_size; -This variable holds the (maximum) size in bytes of a short (16 -bit or so) jump created by @code{md_create_short_jump()}. This -variable is used as part of the broken-word feature, and isn't -needed if the assembler is compiled with -@samp{-DWORKING_DOT_WORD}. - -@item int md_long_jump_size; -This variable holds the (maximum) size in bytes of a long (32 -bit or so) jump created by @code{md_create_long_jump()}. This -variable is used as part of the broken-word feature, and isn't -needed if the assembler is compiled with -@samp{-DWORKING_DOT_WORD}. - -@item void md_create_short_jump(char *resultPTR,long from_addr, -@code{long to_addr,fragS *frag,symbolS *to_symbol)} -This function emits a jump from @var{from_addr} to @var{to_addr} in -the array of bytes pointed to by @var{resultPTR}. If this creates a -type of jump that must be relocated, this function should call -@code{fix_new()} with @var{frag} and @var{to_symbol}. The jump -emitted by this function may be smaller than @var{md_short_jump_size}, -but it must never create a larger one. -(If it creates a smaller jump, the extra bytes of memory will not be -used.) This function is used as part of the broken-word feature, -and isn't needed if the assembler is compiled with -@samp{-DWORKING_DOT_WORD}.@refill - -@item void md_create_long_jump(char *ptr,long from_addr, -@code{long to_addr,fragS *frag,symbolS *to_symbol)} -This function is similar to the previous function, -@code{md_create_short_jump()}, except that it creates a long -jump instead of a short one. This function is used as part of -the broken-word feature, and isn't needed if the assembler is -compiled with @samp{-DWORKING_DOT_WORD}. - -@item int md_estimate_size_before_relax(fragS *fragPTR,int segment_type) -This function does the initial setting up for relaxation. This -includes forcing references to still-undefined symbols to the -appropriate addressing modes. - -@item relax_typeS md_relax_table[]; -(relax_typeS is defined in md.h) -This array describes the various machine dependent states a -frag may be in before relaxation. You will need one group of -entries for each type of addressing mode you intend to relax. - -@item void md_convert_frag(fragS *fragPTR) -(@var{fragS} is defined in @file{as.h}) -This routine does the required cleanup after relaxation. -Relaxation has changed the type of the frag to a type that can -reach its destination. This function should adjust the opcode -of the frag to use the appropriate addressing mode. -@var{fragPTR} points to the frag to clean up. - -@item void md_end(void) -This function is called just before the assembler exits. It -need not free up memory unless the operating system doesn't do -it automatically on exit. (In which case you'll also have to -track down all the other places where the assembler allocates -space but never frees it.) - -@end table - -@section External Variables You will Need to Use - -You will need to refer to or change the following external variables -from within the machine-dependent part of the assembler. - -@table @code -@item extern char flagseen[]; -This array holds non-zero values in locations corresponding to -the options that were on the command line. Thus, if the -assembler was called with @samp{-W}, @var{flagseen['W']} would -be non-zero. - -@item extern fragS *frag_now; -This pointer points to the current frag--the frag that bytes -are currently being added to. If nothing else, you will need -to pass it as an argument to various machine-independent -functions. It is maintained automatically by the -frag-manipulating functions; you should never have to change it -yourself. - -@item extern LITTLENUM_TYPE generic_bignum[]; -(@var{LITTLENUM_TYPE} is defined in @file{bignum.h}. -This is where @dfn{bignums}--numbers larger than 32 bits--are -returned when they are encountered in an expression. You will -need to use this if you need to implement directives (or -anything else) that must deal with these large numbers. -@code{Bignums} are of @code{segT} @code{SEG_BIG} (defined in -@file{as.h}, and have a positive @code{X_add_number}. The -@code{X_add_number} of a @code{bignum} is the number of -@code{LITTLENUMS} in @var{generic_bignum} that the number takes -up. - -@item extern FLONUM_TYPE generic_floating_point_number; -(@var{FLONUM_TYPE} is defined in @file{flonum.h}. -The is where @dfn{flonums}--floating-point numbers within -expressions--are returned. @code{Flonums} are of @code{segT} -@code{SEG_BIG}, and have a negative @code{X_add_number}. -@code{Flonums} are returned in a generic format. You will have -to write a routine to turn this generic format into the -appropriate floating-point format for your machine. - -@item extern int need_pass_2; -If this variable is non-zero, the assembler has encountered an -expression that cannot be assembled in a single pass. Since -the second pass isn't implemented, this flag means that the -assembler is punting, and is only looking for additional syntax -errors. (Or something like that.) - -@item extern segT now_seg; -This variable holds the value of the section the assembler is -currently assembling into. - -@end table - -@section External functions will you need - -You will find the following external functions useful (or -indispensable) when you're writing the machine-dependent part -of the assembler. - -@table @code - -@item char *frag_more(int bytes) -This function allocates @var{bytes} more bytes in the current -frag (or starts a new frag, if it can't expand the current frag -any more.) for you to store some object-file bytes in. It -returns a pointer to the bytes, ready for you to store data in. - -@item void fix_new(fragS *frag, int where, short size, symbolS *add_symbol, symbolS *sub_symbol, long offset, int pcrel) -This function stores a relocation fixup to be acted on later. -@var{frag} points to the frag the relocation belongs in; -@var{where} is the location within the frag where the relocation begins; -@var{size} is the size of the relocation, and is usually 1 (a single byte), - 2 (sixteen bits), or 4 (a longword). -The value @var{add_symbol} @minus{} @var{sub_symbol} + @var{offset}, is added to the byte(s) -at _0__@var{frag->literal[where]}_1__. If @var{pcrel} is non-zero, the address of the -location is subtracted from the result. A relocation entry is also added -to the @file{a.out} file. @var{add_symbol}, @var{sub_symbol}, and/or -@var{offset} may be NULL.@refill - -@item char *frag_var(relax_stateT type, int max_chars, int var, -@code{relax_substateT subtype, symbolS *symbol, char *opcode)} -This function creates a machine-dependent frag of type @var{type} -(usually @code{rs_machine_dependent}). -@var{max_chars} is the maximum size in bytes that the frag may grow by; -@var{var} is the current size of the variable end of the frag; -@var{subtype} is the sub-type of the frag. The sub-type is used to index into -@var{md_relax_table[]} during @code{relaxation}. -@var{symbol} is the symbol whose value should be used to when relax-ing this frag. -@var{opcode} points into a byte whose value may have to be modified if the -addressing mode used by this frag changes. It typically points into the -@var{fr_literal[]} of the previous frag, and is used to point to a location -that @code{md_convert_frag()}, may have to change.@refill - -@item void frag_wane(fragS *fragPTR) -This function is useful from within @code{md_convert_frag}. It -changes a frag to type rs_fill, and sets the variable-sized -piece of the frag to zero. The frag will never change in size -again. - -@item segT expression(expressionS *retval) -(@var{segT} is defined in @file{as.h}; @var{expressionS} is defined in @file{expr.h}) -This function parses the string pointed to by the external char -pointer @var{input_line_pointer}, and returns the section-type -of the expression. It also stores the results in the -@var{expressionS} pointed to by @var{retval}. -@var{input_line_pointer} is advanced to point past the end of -the expression. (@var{input_line_pointer} is used by other -parts of the assembler. If you modify it, be sure to restore -it to its original value.) - -@item as_warn(char *message,@dots{}) -If warning messages are disabled, this function does nothing. -Otherwise, it prints out the current file name, and the current -line number, then uses @code{fprintf} to print the -@var{message} and any arguments it was passed. - -@item as_bad(char *message,@dots{}) -This function should be called when @code{_AS__} encounters -conditions that are bad enough that @code{_AS__} should not -produce an object file, but should continue reading input and -printing warning and bad error messages. - -@item as_fatal(char *message,@dots{}) -This function prints out the current file name and line number, -prints the word @samp{FATAL:}, then uses @code{fprintf} to -print the @var{message} and any arguments it was passed. Then -the assembler exits. This function should only be used for -serious, unrecoverable errors. - -@item void float_const(int float_type) -This function reads floating-point constants from the current -input line, and calls @code{md_atof} to assemble them. It is -useful as the function to call for the directives -@samp{.single}, @samp{.double}, @samp{.float}, etc. -@var{float_type} must be a character from @var{FLT_CHARS}. - -@item void demand_empty_rest_of_line(void); -This function can be used by machine-dependent directives to -make sure the rest of the input line is empty. It prints a -warning message if there are additional characters on the line. - -@item long int get_absolute_expression(void) -This function can be used by machine-dependent directives to -read an absolute number from the current input line. It -returns the result. If it isn't given an absolute expression, -it prints a warning message and returns zero. - -@end table - - -@section The concept of Frags - -This assembler works to optimize the size of certain addressing -modes. (e.g. branch instructions) This means the size of many -pieces of object code cannot be determined until after assembly -is finished. (This means that the addresses of symbols cannot be -determined until assembly is finished.) In order to do this, -@code{_AS__} stores the output bytes as @dfn{frags}. - -Here is the definition of a frag (from @file{as.h}) -@smallexample -struct frag -@{ - long int fr_fix; - long int fr_var; - relax_stateT fr_type; - relax_substateT fr_substate; - unsigned long fr_address; - long int fr_offset; - struct symbol *fr_symbol; - char *fr_opcode; - struct frag *fr_next; - char fr_literal[]; -@} -@end smallexample - -@table @var -@item fr_fix -is the size of the fixed-size piece of the frag. - -@item fr_var -is the maximum (?) size of the variable-sized piece of the frag. - -@item fr_type -is the type of the frag. -Current types are: -rs_fill -rs_align -rs_org -rs_machine_dependent - -@item fr_substate -This stores the type of machine-dependent frag this is. (what -kind of addressing mode is being used, and what size is being -tried/will fit/etc. - -@item fr_address -@var{fr_address} is only valid after relaxation is finished. -Before relaxation, the only way to store an address is (pointer -to frag containing the address) plus (offset into the frag). - -@item fr_offset -This contains a number, whose meaning depends on the type of -the frag. -for machine_dependent frags, this contains the offset from -fr_symbol that the frag wants to go to. Thus, for branch -instructions it is usually zero. (unless the instruction was -@samp{jba foo+12} or something like that.) - -@item fr_symbol -for machine_dependent frags, this points to the symbol the frag -needs to reach. - -@item fr_opcode -This points to the location in the frag (or in a previous frag) -of the opcode for the instruction that caused this to be a frag. -@var{fr_opcode} is needed if the actual opcode must be changed -in order to use a different form of the addressing mode. -(For example, if a conditional branch only comes in size tiny, -a large-size branch could be implemented by reversing the sense -of the test, and turning it into a tiny branch over a large jump. -This would require changing the opcode.) - -@var{fr_literal} is a variable-size array that contains the -actual object bytes. A frag consists of a fixed size piece of -object data, (which may be zero bytes long), followed by a -piece of object data whose size may not have been determined -yet. Other information includes the type of the frag (which -controls how it is relaxed), - -@item fr_next -This is the next frag in the singly-linked list. This is -usually only needed by the machine-independent part of -@code{_AS__}. - -@end table -_fi__(0) - -@node Copying, Index, _MACH_DEP__, Top -@unnumbered GNU GENERAL PUBLIC LICENSE - -@cindex license -@cindex GPL -@cindex copying @code{_AS__} -@center Version 2, June 1991 - -@display -Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. -675 Mass Ave, Cambridge, MA 02139, USA - -Everyone is permitted to copy and distribute verbatim copies -of this license document, but changing it is not allowed. -@end display - -@unnumberedsec Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software---to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - -@iftex -@unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -@end iftex -@ifinfo -@center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -@end ifinfo - -@enumerate -@item -This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The ``Program'', below, -refers to any such program or work, and a ``work based on the Program'' -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term ``modification''.) Each licensee is addressed as ``you''. - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - -@item -You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - -@item -You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - -@enumerate a -@item -You must cause the modified files to carry prominent notices -stating that you changed the files and the date of any change. - -@item -You must cause any work that you distribute or publish, that in -whole or in part contains or is derived from the Program or any -part thereof, to be licensed as a whole at no charge to all third -parties under the terms of this License. - -@item -If the modified program normally reads commands interactively -when run, you must cause it, when started running for such -interactive use in the most ordinary way, to print or display an -announcement including an appropriate copyright notice and a -notice that there is no warranty (or else, saying that you provide -a warranty) and that users may redistribute the program under -these conditions, and telling the user how to view a copy of this -License. (Exception: if the Program itself is interactive but -does not normally print such an announcement, your work based on -the Program is not required to print an announcement.) -@end enumerate - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - -@item -You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - -@enumerate a -@item -Accompany it with the complete corresponding machine-readable -source code, which must be distributed under the terms of Sections -1 and 2 above on a medium customarily used for software interchange; or, - -@item -Accompany it with a written offer, valid for at least three -years, to give any third party, for a charge no more than your -cost of physically performing source distribution, a complete -machine-readable copy of the corresponding source code, to be -distributed under the terms of Sections 1 and 2 above on a medium -customarily used for software interchange; or, - -@item -Accompany it with the information you received as to the offer -to distribute corresponding source code. (This alternative is -allowed only for noncommercial distribution and only if you -received the program in object code or executable form with such -an offer, in accord with Subsection b above.) -@end enumerate - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - -@item -You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - -@item -You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - -@item -Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - -@item -If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - -@item -If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - -@item -The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and ``any -later version'', you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - -@item -If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - -@iftex -@heading NO WARRANTY -@end iftex -@ifinfo -@center NO WARRANTY -@end ifinfo - -@item -BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - -@item -IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. -@end enumerate - -@iftex -@heading END OF TERMS AND CONDITIONS -@end iftex -@ifinfo -@center END OF TERMS AND CONDITIONS -@end ifinfo - -@page -@unnumberedsec Applying These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the ``copyright'' line and a pointer to where the full notice is found. - -@smallexample -@var{one line to give the program's name and an idea of what it does.} -Copyright (C) 19@var{yy} @var{name of author} - -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 -of the License, 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 this program; if not, write to the -Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. -@end smallexample - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - -@smallexample -Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author} -Gnomovision comes with ABSOLUTELY NO WARRANTY; for details -type `show w'. This is free software, and you are welcome -to redistribute it under certain conditions; type `show c' -for details. -@end smallexample - -The hypothetical commands @samp{show w} and @samp{show c} should show -the appropriate parts of the General Public License. Of course, the -commands you use may be called something other than @samp{show w} and -@samp{show c}; they could even be mouse-clicks or menu items---whatever -suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a ``copyright disclaimer'' for the program, if -necessary. Here is a sample; alter the names: - -@smallexample -Yoyodyne, Inc., hereby disclaims all copyright interest in -the program `Gnomovision' (which makes passes at compilers) -written by James Hacker. - -@var{signature of Ty Coon}, 1 April 1989 -Ty Coon, President of Vice -@end smallexample - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. - -@node Index, , Copying, Top -@unnumbered Index - -@printindex cp - -@summarycontents -@contents -@bye diff --git a/gnu/usr.bin/as/doc/config.status b/gnu/usr.bin/as/doc/config.status deleted file mode 100644 index f1e7f63..0000000 --- a/gnu/usr.bin/as/doc/config.status +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# This file was generated automatically by configure. Do not edit. -# /d/users/pk/src/gnu/usr.bin/gas.1.93/gas/doc was configured as follows: -/d/users/pk/src/gnu/usr.bin/gas.1.93/./configure i386 -target=i386 -norecursion -# diff --git a/gnu/usr.bin/as/doc/configure.in b/gnu/usr.bin/as/doc/configure.in deleted file mode 100644 index f9820ea..0000000 --- a/gnu/usr.bin/as/doc/configure.in +++ /dev/null @@ -1,34 +0,0 @@ -# This file is configure.in -# -# Copyright (C) 1987-1992 Free Software Foundation, Inc. -# -# This file is part of GAS, the GNU Assembler. -# -# GAS 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. -# -# GAS 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 GAS; see the file COPYING. If not, write to -# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ -# - -# This file is a shell script that supplies the information necessary -# to tailor a template configure script into the configure script -# appropriate for this directory. For more information, check any -# existing configure script. - -srctrigger=all.m4 -srcname="gas doc" - -# per-host: - -# per-target: - -# end of gas/doc/configure.in diff --git a/gnu/usr.bin/as/doc/gen.m4 b/gnu/usr.bin/as/doc/gen.m4 deleted file mode 100644 index bf444a6..0000000 --- a/gnu/usr.bin/as/doc/gen.m4 +++ /dev/null @@ -1,14 +0,0 @@ -_divert__(-1) -<$Id: gen.m4,v 1.1 1993/10/02 21:00:19 pk Exp $> -_define__(<_GENERIC__>,<1>) In case none.m4 changes its mind abt default - -_define__(<_AOUT__>,<1>) -_define__(<_COFF__>,<1>) -_define__(<_ELF__>,<1>) - -_define__(<_I80386__>,<1>) -_define__(<_M680X0__>,<1>) -_define__(<_SPARC__>,<1>) -_define__(<_VAX__>,<1>) - -_divert__<> diff --git a/gnu/usr.bin/as/doc/h8.m4 b/gnu/usr.bin/as/doc/h8.m4 deleted file mode 100644 index ed52c85..0000000 --- a/gnu/usr.bin/as/doc/h8.m4 +++ /dev/null @@ -1,15 +0,0 @@ -_divert__(-1) -_define__(<_H8__>,<1>) -_define__(<_AS__>,) -_define__(<_GENERIC__>,<0>) -_define__(<_HOST__>,) -_define__(<_MACH_DEP__>,) -_define__(<_AOUT__>,<0>) -_define__(<_BOUT__>,<0>) -_define__(<_COFF__>,<1>) -_define__(<_ELF__>,<0>) -_define__(<_DIFFTABKLUG__>,0) NO difference-table kluge -_define__(<_IEEEFLOAT__>,1) IEEE floating point -_define__(<_W32__>,0) -_define__(<_W16__>,1) 16-bit words -_divert__<> diff --git a/gnu/usr.bin/as/doc/i80386.m4 b/gnu/usr.bin/as/doc/i80386.m4 deleted file mode 100644 index e8718aa..0000000 --- a/gnu/usr.bin/as/doc/i80386.m4 +++ /dev/null @@ -1,12 +0,0 @@ -_divert__(-1) -_define__(<_I80386__>,<1>) -_define__(<_GENERIC__>,<0>) -_define__(<_HOST__>,) -_define__(<_MACH_DEP__>,) -_define__(<_AOUT__>,<1>) -_define__(<_BOUT__>,<0>) -_define__(<_COFF__>,<0>) -_define__(<_ELF__>,<0>) -_define__(<_W32__>,0) -_define__(<_W16__>,1) 16-bit words -_divert__<> diff --git a/gnu/usr.bin/as/doc/i960.m4 b/gnu/usr.bin/as/doc/i960.m4 deleted file mode 100644 index 1fca147..0000000 --- a/gnu/usr.bin/as/doc/i960.m4 +++ /dev/null @@ -1,16 +0,0 @@ -_divert__(-1) -_define__(<_I960__>,<1>) -_define__(<_AOUT__>,<0>) -_define__(<_BOUT__>,<1>) -_define__(<_COFF__>,<1>) -_define__(<_AS__>,) -_define__(<_GCC__>,) -_define__(<_LD__>,) -_define__(<_GDB__>,) -_define__(<_HOST__>,) -_define__(<_MACH_DEP__>,) -_define__(<_DIFFTABKLUG__>,0) NO difference-table kluge -_define__(<_IEEEFLOAT__>,1) IEEE floating point -_define__(<_W32__>,1) 32-bit words -_define__(<_W16__>,0) -_divert__<> diff --git a/gnu/usr.bin/as/doc/m680x0.m4 b/gnu/usr.bin/as/doc/m680x0.m4 deleted file mode 100644 index 4013e72..0000000 --- a/gnu/usr.bin/as/doc/m680x0.m4 +++ /dev/null @@ -1,8 +0,0 @@ -_divert__(-1) -_define__(<_GENERIC__>,<0>) -_define__(<_M680X0__>,<1>) -_define__(<_HOST__>,) -_define__(<_MACH_DEP__>,) -_define__(<_W32__>,0) -_define__(<_W16__>,1) 16-bit words -_divert__<> diff --git a/gnu/usr.bin/as/doc/none.m4 b/gnu/usr.bin/as/doc/none.m4 deleted file mode 100644 index dfa17d3..0000000 --- a/gnu/usr.bin/as/doc/none.m4 +++ /dev/null @@ -1,57 +0,0 @@ -_divert__(-1) -<$Id: none.m4,v 1.1 1993/10/02 21:00:24 pk Exp $> - -Switches: - -_define__(<_ALL_ARCH__>,<0>) (Meant as most inclusive; file turning - it on is expected to also turn on - all arch-related switches including - "_GENERIC__") -_define__(<_GENERIC__>,<1>) (may not be quite all configs; - meant for "most vanilla" manual) -_define__(<_INTERNALS__>,<0>) - -_define__(<_AOUT__>,<1>) Object formats. Note we turn on one. -_define__(<_BOUT__>,<0>) -_define__(<_COFF__>,<0>) -_define__(<_ELF__>,<0>) - - Properties of the assembler -_define__(<_DIFFTABKLUG__>,1) Do we use the difference-table kluge? -_define__(<_IEEEFLOAT__>,0) IEEE floating-point? -_define__(<_W32__>,0) word is 32 bits -_define__(<_W16__>,1) word is 16 bits - -_define__(<_A29K__>,<0>) Specific architectures. Note none -_define__(<_H8__>,<0>) starts out on. -_define__(<_I80386__>,<0>) -_define__(<_I960__>,<0>) -_define__(<_M680X0__>,<0>) -_define__(<_SPARC__>,<0>) -_define__(<_VAX__>,<0>) -_define__(<_VXWORKS__>,<0>) - -Text: - -Default names; individual configs may override -Assembler: -_define__(<_AS__>,) -C Compiler: -_define__(<_GCC__>,) -Linker: -_define__(<_LD__>,) -Debugger name: -_define__(<_GDBN__>,) -Debugger program: -_define__(<_GDBP__>,) -Debugger init file: -_define__(<_GDBINIT__>,<.gdbinit>) - -Text for host; individual configs *should* override, but this may -catch some flubs -_define__(<_HOST__>,) - -"Machine Dependent" nodename -_define__(<_MACH_DEP__>,) - -_divert__<> diff --git a/gnu/usr.bin/as/doc/pretex.m4 b/gnu/usr.bin/as/doc/pretex.m4 deleted file mode 100644 index 9a9696f..0000000 --- a/gnu/usr.bin/as/doc/pretex.m4 +++ /dev/null @@ -1,268 +0,0 @@ -divert(-1) -*-Text-*- -` Copyright (c) 1991 Free Software Foundation, Inc.' -` This file defines and documents the M4 macros used ' -` to preprocess some GNU manuals' -` $Id: pretex.m4,v 1.1 1993/10/02 21:00:25 pk Exp $' - -I. INTRODUCTION - -This collection of M4 macros is meant to help in pre-processing texinfo -files to allow configuring them by hosts; for example, the reader of an -as manual who only has access to a 386 may not really want to see crud about -VAXen. - -A preprocessor is used, rather than extending texinfo, because this -way we can hack the conditionals in only one place; otherwise we would -have to write TeX macros, update makeinfo, and update the Emacs -info-formatting functions. - -II. COMPATIBILITY - -These macros should work with GNU m4 and System V m4; they do not work -with Sun or Berkeley M4. - -III. USAGE - -A. M4 INVOCATION -Assume this file is called "pretex.m4". Then, to preprocess a -document "mybook.texinfo" you might do something like the following: - - m4 pretex.m4 none.m4 PARTIC.m4 mybook.texinfo >mybook-PARTIC.texinfo - ----where your path is set to find GNU or SysV "m4", and the other m4 -files mentioned are as follows: - - none.m4: A file that defines, as 0, all the options you might - want to turn on using the conditionals defined below. - Unlike the C preprocessor, m4 does not default - undefined macros to 0. For example, here is a "none.m4" - I have been using: - _divert__(-1) - - _define__(<_ALL_ARCH__>,<0>) - _define__(<_INTERNALS__>,<0>) - - _define__(<_AMD29K__>,<0>) - _define__(<_I80386__>,<0>) - _define__(<_I960__>,<0>) - _define__(<_M680X0__>,<0>) - _define__(<_SPARC__>,<0>) - _define__(<_VAX__>,<0>) - - _divert__<> - - PARTIC.m4: A file that turns on whichever options you actually - want the manual configured for, in this particular - instance. Its contents are similar to one or more of - the lines in "none.m4", but of course the second - argument to _define__ is <1> rather than <0>. - - This is also a convenient place to _define__ any macros - that you want to expand to different text for - different configurations---for example, the name of - the program being described. - -Naturally, these are just suggested conventions; you could put your macro -definitions in any files or combinations of files you like. - -These macros use the characters < and > as m4 quotes; if you need -these characters in your text, you will also want to use the macros -_0__ and _1__ from this package---see the description of "Quote -Handling" in the "Implementation" section below. - -B. WHAT GOES IN THE PRE-TEXINFO SOURCE - -For the most part, the text of your book. In addition, you can -have text that is included only conditionally, using the macros -_if__ and _fi__ defined below. They BOTH take an argument! This is -primarily meant for readability (so a human can more easily see what -conditional end matches what conditional beginning), but the argument -is actually used in the _fi__ as well as the _if__ implementation. -You should always give a _fi__ the same argument as its matching -_if__. Other arguments may appear to work for a while, but are almost -certain to produce the wrong output for some configurations. - -For example, here is an excerpt from the very beginning of the -documentation for GNU as, to name the info file appropriately for -different configurations: - _if__(_ALL_ARCH__) - @setfilename as.info - _fi__(_ALL_ARCH__) - _if__(_M680X0__ && !_ALL_ARCH__) - @setfilename as-m680x0.info - _fi__(_M680X0__ && !_ALL_ARCH__) - _if__(_AMD29K__ && !_ALL_ARCH__) - @setfilename as-29k.info - _fi__(_AMD29K__ && !_ALL_ARCH__) - -Note that you can use Boolean expressions in the arguments; the -expression language is that of the built-in m4 macro `eval', described -in the m4 manual. - -IV. IMPLEMENTATION - -A.PRIMITIVE RENAMING -First, we redefine m4's built-ins to avoid conflict with plain text. -The naming convention used is that our macros all begin with a single -underbar and end with two underbars. The asymmetry is meant to avoid -conflict with some other conventions (which we may want to document) that -are intended to avoid conflict, like ANSI C predefined macros. - -define(`_undefine__',defn(`undefine')) -define(`_define__',defn(`define')) -define(`_defn__',defn(`defn')) -define(`_ppf__',`_define__(`_$1__',_defn__(`$1'))_undefine__(`$1')') -_ppf__(`builtin') -_ppf__(`changecom') -_ppf__(`changequote') -_ppf__(`decr') -_ppf__(`define') -_ppf__(`defn') -_ppf__(`divert') -_ppf__(`divnum') -_ppf__(`dnl') -_ppf__(`dumpdef') -_ppf__(`errprint') -_ppf__(`esyscmd') -_ppf__(`eval') -_ppf__(`format') -_ppf__(`ifdef') -_ppf__(`ifelse') -_ppf__(`include') -_ppf__(`incr') -_ppf__(`index') -_ppf__(`len') -_ppf__(`m4exit') -_ppf__(`m4wrap') -_ppf__(`maketemp') -_ppf__(`patsubst') -_ppf__(`popdef') -_ppf__(`pushdef') -_ppf__(`regexp') -_ppf__(`shift') -_ppf__(`sinclude') -_ppf__(`substr') -_ppf__(`syscmd') -_ppf__(`sysval') -_ppf__(`traceoff') -_ppf__(`traceon') -_ppf__(`translit') -_ppf__(`undefine') -_ppf__(`undivert') -_ppf__(`unix') - -B. QUOTE HANDLING. - -The characters used as quotes by M4, by default, are unfortunately -quite likely to occur in ordinary text. To avoid surprises, we will -use the characters <> ---which are just as suggestive (more so to -Francophones, perhaps) but a little less common in text (save for -those poor Francophones. You win some, you lose some). Still, we -expect also to have to set < and > occasionally in text; to do that, -we define a macro to turn off quote handling (_0__) and a macro to -turn it back on (_1__), according to our convention. - - BEWARE: This seems to make < and > unusable as relational operations - in calls to the builtin "eval". So far I've gotten - along without; but a better choice may be possible. - -Note that we postponed this for a while, for convenience in discussing -the issue and in the primitive renaming---not to mention in defining -_0__ and _1__ themselves! However, the quote redefinitions MUST -precede the _if__ / _fi__ definitions, because M4 will expand the text -as given---if we use the wrong quotes here, we will get the wrong -quotes when we use the conditionals. - -_define__(_0__,`_changequote__(,)')_define__(_1__,`_changequote__(<,>)') -_1__ - -C. CONDITIONALS - -We define two macros, _if__ and _fi__. BOTH take arguments! This is -meant both to help the human reader match up a _fi__ with its -corresponding _if__ and to aid in the implementation. You may use the -full expression syntax supported by M4 (see docn of `eval' builtin in -the m4 manual). - -The conditional macros are carefully defined to avoid introducing -extra whitespace (i.e., blank lines or blank characters). One side -effect exists--- - - BEWARE: text following an `_if__' on the same line is - DISCARDED even if the condition is true; text - following a `_fi__' on the same line is also - always discarded. - -The recommended convention is to always place _if__ and _fi__ on a -line by themselves. This will also aid the human reader. TeX won't -care about the line breaks; as for info, you may want to insert calls -to `@refill' at the end of paragraphs containing conditionalized text, -where you don't want line breaks separating unconditional from -conditional text. info formatting will then give you nice looking -paragraphs in the info file. - -Nesting: conditionals are designed to nest, in the following way: -*nothing* is output between an outer pair of false conditionals, even -if there are true conditionals inside. A false conditional "defeats" -all conditionals within it. The counter _IF_FS__ is used to -implement this; kindly avoid redefining it directly. - -_define__(<_IF_FS__>,<0>) - -NOTE: The definitions for our "pushf" and "popf" macros use eval -rather than incr and decr, because GNU m4 (0.75) tries to call eval -for us when we say "incr" or "decr"---but doesn't notice we've changed -eval's name. - -_define__( - <_pushf__>, - <_define__(<_IF_FS__>, - _eval__((_IF_FS__)+1))>) -_define__( - <_popf__>, - <_ifelse__(0,_IF_FS__, - <<>_dnl__<>>, - <_define__(<_IF_FS__>,_eval__((_IF_FS__)-1))>)>) - -_define__( - <_if__>, - <_ifelse__(1,_eval__( ($1) ), - <<>_dnl__<>>, - <_pushf__<>_divert__(-1)>)>) -_define__( - <_fi__>, - <_ifelse__(1,_eval__( ($1) ), - <<>_dnl__<>>, - <_popf__<>_ifelse__(0,_IF_FS__, - <_divert__<>_dnl__<>>,<>)>)>) - -D. CHAPTER/SECTION MACRO -In a parametrized manual, the heading level may need to be calculated; -for example, a manual that has a chapter on machine dependencies -should be conditionally structured as follows: - - IF the manual is configured for a SINGLE machine type, use -the chapter heading for that machine type, and run headings down -from there (top level for a particular machine is chapter, then within -that we have section, subsection etc); - - ELSE, if MANY machine types are described in the chapter, -use a generic chapter heading such as "@chapter Machine Dependencies", -use "section" for the top level description of EACH machine, and run -headings down from there (top level for a particular machine is -section, then within that we have subsection, subsubsection etc). - -The macro <_CHAPSEC__> is for this purpose: its argument is evaluated (so -you can construct expressions to express choices such as above), then -expands as follows: - 0: @chapter - 1: @section - 2: @subsection - 3: @subsubsection - ...and so on. - -_define__(<_CHAPSEC__>,<@_cs__(_eval__($1))>) -_define__(<_cs__>,<_ifelse__( - 0, $1, , - 1, $1,
, - _cs__(_eval__($1 - 1))>)>) - -_divert__<>_dnl__<> diff --git a/gnu/usr.bin/as/doc/sparc.m4 b/gnu/usr.bin/as/doc/sparc.m4 deleted file mode 100644 index 121855a..0000000 --- a/gnu/usr.bin/as/doc/sparc.m4 +++ /dev/null @@ -1,8 +0,0 @@ -_divert__(-1) -_define__(<_SPARC__>,<1>) -_define__(<_HOST__>,) -_define__(<_MACH_DEP__>,) -_define__(<_IEEEFLOAT__>,1) IEEE floating point -_define__(<_W32__>,1) 32-bit words -_define__(<_W16__>,0) -_divert__<> diff --git a/gnu/usr.bin/as/doc/vax.m4 b/gnu/usr.bin/as/doc/vax.m4 deleted file mode 100644 index 009e334..0000000 --- a/gnu/usr.bin/as/doc/vax.m4 +++ /dev/null @@ -1,7 +0,0 @@ -_divert__(-1) -_define__(<_VAX__>,<1>) -_define__(<_HOST__>,) -_define__(<_MACH_DEP__>,) -_define__(<_W32__>,0) -_define__(<_W16__>,1) 16-bit words -_divert__<> diff --git a/gnu/usr.bin/as/doc/vintage.m4 b/gnu/usr.bin/as/doc/vintage.m4 deleted file mode 100644 index d5913be..0000000 --- a/gnu/usr.bin/as/doc/vintage.m4 +++ /dev/null @@ -1,11 +0,0 @@ -_divert__(-1) -<$Id: vintage.m4,v 1.1 1993/10/02 21:00:29 pk Exp $> -_define__(<_ALL_ARCH__>,<1>) -_define__(<_GENERIC__>,<1>) In case none.m4 changes its mind abt default - -_define__(<_AOUT__>,<1>) - -_define__(<_M680X0__>,<1>) -_define__(<_SPARC__>,<1>) - -_divert__<> diff --git a/gnu/usr.bin/as/flonum-const.c b/gnu/usr.bin/as/flonum-const.c deleted file mode 100644 index 617e585..0000000 --- a/gnu/usr.bin/as/flonum-const.c +++ /dev/null @@ -1,157 +0,0 @@ -/* flonum_const.c - Useful Flonum constants - Copyright (C) 1987 Free Software Foundation, Inc. - -This file is part of GAS, the GNU Assembler. - -GAS 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 1, or (at your option) -any later version. - -GAS 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 GAS; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "flonum.h" -/* JF: I added the last entry to this table, and I'm not - sure if its right or not. Could go either way. I wish - I really understood this stuff. */ - - -const int table_size_of_flonum_powers_of_ten = 11; - -static const LITTLENUM_TYPE zero[] = { 1 }; - -/***********************************************************************\ -* * -* Warning: the low order bits may be WRONG here. * -* I took this from a suspect bc(1) script. * -* "minus_X"[] is supposed to be 10^(2^-X) expressed in base 2^16. * -* The radix point is just AFTER the highest element of the [] * -* * -* Because bc rounds DOWN for printing (I think), the lowest * -* significance littlenums should probably have 1 added to them. * -* * -\***********************************************************************/ - -/* JF: If this equals 6553/(2^16)+39321/(2^32)+... it approaches .1 */ -static const LITTLENUM_TYPE minus_1 [] = { - 39321, 39321, 39321, 39321, 39321, 39321, 39321, 39321, 39321, 39321, - 39321, 39321, 39321, 39321, 39321, 39321, 39321, 39321, 39321, 6553 }; -static const LITTLENUM_TYPE plus_1 [] = { 10 }; - -/* JF: If this equals 655/(2^16) + 23592/(2^32) + ... it approaches .01 */ -static const LITTLENUM_TYPE minus_2 [] = { - 10485, 36700, 62914, 23592, 49807, 10485, 36700, 62914, 23592, 49807, - 10485, 36700, 62914, 23592, 49807, 10485, 36700, 62914, 23592, 655 }; -static const LITTLENUM_TYPE plus_2 [] = { 100 }; - -/* This approaches .0001 */ -static const LITTLENUM_TYPE minus_3 [] = { - 52533, 20027, 37329, 65116, 64067, 60397, 14784, 18979, 33659, 19503, - 2726, 9542, 629, 2202, 40475, 10590, 4299, 47815, 36280, 6 }; -static const LITTLENUM_TYPE plus_3 [] = { 10000 }; - -/* JF: this approaches 1e-8 */ -static const LITTLENUM_TYPE minus_4 [] = { - 22516, 49501, 54293, 19424, 60699, 6716, 24348, 22618, 23904, 21327, - 3919, 44703, 19149, 28803, 48959, 6259, 50273, 62237, 42 }; -/* This equals 1525 * 2^16 + 57600 */ -static const LITTLENUM_TYPE plus_4 [] = { 57600, 1525 }; - -/* This approaches 1e-16 */ -static const LITTLENUM_TYPE minus_5 [] = { - 22199, 45957, 17005, 26266, 10526, 16260, 55017, 35680, 40443, 19789, - 17356, 30195, 55905, 28426, 63010, 44197, 1844 }; -static const LITTLENUM_TYPE plus_5 [] = { 28609, 34546, 35 }; - -static const LITTLENUM_TYPE minus_6 [] = { - 30926, 26518, 13110, 43018, 54982, 48258, 24658, 15209, 63366, 11929, - 20069, 43857, 60487, 51 }; -static const LITTLENUM_TYPE plus_6 [] = { 61313, 34220, 16731, 11629, 1262 }; - -static const LITTLENUM_TYPE minus_7 [] = { - 29819, 14733, 21490, 40602, 31315, 65186, 2695 }; -static const LITTLENUM_TYPE plus_7 [] = { - 7937, 49002, 60772, 28216, 38893, 55975, 63988, 59711, 20227, 24 }; - -static const LITTLENUM_TYPE minus_8 [] = { - 45849, 19069, 18068, 36324, 37948, 48745, 10873, 64360, 15961, 20566, - 24178, 15922, 59427, 110 }; -static const LITTLENUM_TYPE plus_8 [] = { - 15873, 11925, 39177, 991, 14589, 19735, 25347, 65086, 53853, 938, - 37209, 47086, 33626, 23253, 32586, 42547, 9731, 59679, 590 }; - -static const LITTLENUM_TYPE minus_9 [] = { - 63601, 55221, 43562, 33661, 29067, 28203, 65417, 64352, 22462, 41110, - 12570, 28635, 23199, 50572, 28471, 27074, 46375, 64028, 13106, 63700, - 32698, 17493, 32420, 34382, 22750, 20681, 12300 }; -static const LITTLENUM_TYPE plus_9 [] = { - 63564, 61556, 29377, 54467, 18621, 28141, 36415, 61241, 47119, 30026, - 19740, 46002, 13541, 61413, 30480, 38664, 32205, 50593, 51112, 48904, - 48263, 43814, 286, 30826, 52813, 62575, 61390, 24540, 21495, 5 }; - -static const LITTLENUM_TYPE minus_10 [] = { - 50313, 34681, 1464, 25889, 19575, 41125, 17635, 4598, 49708, 13427, - 17287, 56115, 53783, 38255, 32415, 17778, 31596, 7557, 20951, 18477, - 40353, 1178, 44405, 11837, 11571, 50963, 15649, 11698, 40675, 2308, }; -static const LITTLENUM_TYPE plus_10[] = { -18520, 53764, 54535, 61910, 61962, 59843, 46270, 58053, 12473, 63785, - 2449, 43230, 50044, 47595, 10403, 35766, 32607, 1124, 24966, 35044, -25524, 23631, 18826, 14518, 58448, 14562, 49618, 5588, 25396, 28 }; - -static const LITTLENUM_TYPE minus_11 [] = { - 6223, 59909, 62437, 59960, 14652, 45336, 48800, 7647, 51962, 37982, - 60436, 58176, 26767, 8440, 9831, 48556, 20994, 14148, 6757, 17221, - 60624, 46129, 53210, 44085, 54016, 24259, 11232, 21229, 21313, 81, }; -static const LITTLENUM_TYPE plus_11 [] = { - 36159, 2055, 33615, 61362, 23581, 62454, 9748, 15275, 39284, 58636, - 16269, 42793, 47240, 45774, 50861, 48400, 9413, 40281, 4030, 9572, - 7984, 33038, 59522, 19450, 40593, 24486, 54320, 6661, 55766, 805, }; - -/* Shut up complaints about differing pointer types. They only differ - in the const attribute, but there isn't any easy way to do this - */ -#define X (LITTLENUM_TYPE *) - -const FLONUM_TYPE flonum_negative_powers_of_ten [] = { - {X zero, X zero, X zero, 0, '+'}, - {X minus_1, X minus_1 +19, X minus_1 + 19, -20, '+'}, - {X minus_2, X minus_2 +19, X minus_2 + 19, -20, '+'}, - {X minus_3, X minus_3 +19, X minus_3 + 19, -20, '+'}, - {X minus_4, X minus_4 +18, X minus_4 + 18, -20, '+'}, - {X minus_5, X minus_5 +16, X minus_5 + 16, -20, '+'}, - {X minus_6, X minus_6 +13, X minus_6 + 13, -20, '+'}, - {X minus_7, X minus_7 + 6, X minus_7 + 6, -20, '+'}, - {X minus_8, X minus_8 +13, X minus_8 + 13, -40, '+'}, - {X minus_9, X minus_9 +26, X minus_9 + 26, -80, '+'}, - {X minus_10, X minus_10+29, X minus_10 + 29,-136, '+'}, - {X minus_11, X minus_11+29, X minus_11 + 29,-242, '+'}, -}; - -const FLONUM_TYPE flonum_positive_powers_of_ten [] = { - {X zero, X zero, X zero, 0, '+'}, - {X plus_1, X plus_1 + 0, X plus_1 + 0, 0, '+'}, - {X plus_2, X plus_2 + 0, X plus_2 + 0, 0, '+'}, - {X plus_3, X plus_3 + 0, X plus_3 + 0, 0, '+'}, - {X plus_4, X plus_4 + 1, X plus_4 + 1, 0, '+'}, - {X plus_5, X plus_5 + 2, X plus_5 + 2, 1, '+'}, - {X plus_6, X plus_6 + 4, X plus_6 + 4, 2, '+'}, - {X plus_7, X plus_7 + 9, X plus_7 + 9, 4, '+'}, - {X plus_8, X plus_8 + 18, X plus_8 + 18, 8, '+'}, - {X plus_9, X plus_9 + 29, X plus_9 + 29, 24, '+'}, - {X plus_10, X plus_10 + 29, X plus_10 + 29, 77, '+'}, - {X plus_11, X plus_11 + 29, X plus_11 + 29, 183, '+'}, -}; - -#ifdef VMS -dummy1() -{ -} -#endif -/* end: flonum_const.c */ diff --git a/gnu/usr.bin/as/flonum-copy.c b/gnu/usr.bin/as/flonum-copy.c deleted file mode 100644 index 3a51f06..0000000 --- a/gnu/usr.bin/as/flonum-copy.c +++ /dev/null @@ -1,76 +0,0 @@ -/* flonum_copy.c - copy a flonum - Copyright (C) 1987 Free Software Foundation, Inc. - -This file is part of GAS, the GNU Assembler. - -GAS 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 1, or (at your option) -any later version. - -GAS 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 GAS; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "flonum.h" -#ifdef USG -#define bzero(s,n) memset(s,0,n) -#define bcopy(from,to,n) memcpy(to,from,n) -#endif - -void -flonum_copy (in, out) - FLONUM_TYPE * in; - FLONUM_TYPE * out; -{ - int in_length; /* 0 origin */ - int out_length; /* 0 origin */ - - out -> sign = in -> sign; - in_length = in -> leader - in -> low; - if (in_length < 0) - { - out -> leader = out -> low - 1; /* 0.0 case */ - } - else - { - out_length = out -> high - out -> low; - /* - * Assume no GAPS in packing of littlenums. - * I.e. sizeof(array) == sizeof(element) * number_of_elements. - */ - if (in_length <= out_length) - { - { - /* - * For defensive programming, zero any high-order littlenums we don't need. - * This is destroying evidence and wasting time, so why bother??? - */ - if (in_length < out_length) - { - bzero ((char *)(out->low + in_length + 1), out_length - in_length); - } - } - bcopy ((char *)(in->low), (char *)(out->low), (int)((in_length + 1) * sizeof(LITTLENUM_TYPE))); - out -> exponent = in -> exponent; - out -> leader = in -> leader - in -> low + out -> low; - } - else - { - int shorten; /* 1-origin. Number of littlenums we drop. */ - - shorten = in_length - out_length; - /* Assume out_length >= 0 ! */ - bcopy ((char *)(in->low + shorten),(char *)( out->low), (int)((out_length + 1) * sizeof(LITTLENUM_TYPE))); - out -> leader = out -> high; - out -> exponent = in -> exponent + shorten; - } - } /* if any significant bits */ -} - -/* end: flonum_copy.c */ diff --git a/gnu/usr.bin/as/md.h b/gnu/usr.bin/as/md.h deleted file mode 100644 index 681d027..0000000 --- a/gnu/usr.bin/as/md.h +++ /dev/null @@ -1,57 +0,0 @@ -/* md.h -machine dependent- */ - -/* Copyright (C) 1987 Free Software Foundation, Inc. - -This file is part of Gas, the GNU Assembler. - -The GNU assembler is distributed in the hope that it will be -useful, but WITHOUT ANY WARRANTY. No author or distributor -accepts responsibility to anyone for the consequences of using it -or for whether it serves any particular purpose or works at all, -unless he says so in writing. Refer to the GNU Assembler General -Public License for full details. - -Everyone is granted permission to copy, modify and redistribute -the GNU Assembler, but only under the conditions described in the -GNU Assembler General Public License. A copy of this license is -supposed to have been given to you along with the GNU Assembler -so you can know your rights and responsibilities. It should be -in a file named COPYING. Among other things, the copyright -notice and this notice must be preserved on all copies. */ - -/* In theory (mine, at least!) the machine dependent part of the assembler - should only have to include one file. This one. -- JF */ - -/* JF added this here */ -typedef struct { - char * poc_name; /* assembler mnemonic, lower case, no '.' */ - void (*poc_handler)(); /* Do the work */ - int poc_val; /* Value to pass to handler */ -} -pseudo_typeS; -extern const pseudo_typeS md_pseudo_table[]; - -/* JF moved this here from as.h under the theory that nobody except MACHINE.c - and write.c care about it anyway. */ - -typedef struct -{ - long rlx_forward; /* Forward reach. Signed number. > 0. */ - long rlx_backward; /* Backward reach. Signed number. < 0. */ - unsigned char rlx_length; /* Bytes length of this address. */ - relax_substateT rlx_more; /* Next longer relax-state. */ - /* 0 means there is no 'next' relax-state. */ -} -relax_typeS; - -extern const relax_typeS md_relax_table[]; /* Define it in MACHINE.c */ - -char * md_atof(); -void md_assemble(); -void md_begin(); -void md_convert_frag(); -void md_end(); -int md_estimate_size_before_relax(); -void md_number_to_chars(); - -/* end: md.h */ diff --git a/gnu/usr.bin/as/objrecdef.h b/gnu/usr.bin/as/objrecdef.h deleted file mode 100644 index fca8af4..0000000 --- a/gnu/usr.bin/as/objrecdef.h +++ /dev/null @@ -1,255 +0,0 @@ -/* - * - * $OBJRECDEF - * Generated automatically by "vms_struct Version 1.00" - * Created from VMS definition file "objrecdef.mar" - * Mon Oct 14 14:01:29 1985 - * - */ -struct OBJREC { - unsigned char obj$b_rectyp; - unsigned char obj$b_subtyp; - unsigned char obj$b_mhd_strlv; - unsigned char obj$b_mhd_recsz[2]; - unsigned char obj$t_mhd_name[1]; - }; - -#define OBJ$C_HDR 0 -#define OBJ$C_HDR_MHD 0 -#define OBJ$C_HDR_LNM 1 -#define OBJ$C_HDR_SRC 2 -#define OBJ$C_HDR_TTL 3 -#define OBJ$C_HDR_CPR 4 -#define OBJ$C_HDR_MTC 5 -#define OBJ$C_HDR_GTX 6 -#define OBJ$C_GSD 1 -#define OBJ$C_GSD_PSC 0 -#define OBJ$C_GSD_SYM 1 -#define OBJ$C_GSD_EPM 2 -#define OBJ$C_GSD_PRO 3 -#define OBJ$C_GSD_SYMW 4 -#define OBJ$C_GSD_EPMW 5 -#define OBJ$C_GSD_PROW 6 -#define OBJ$C_GSD_IDC 7 -#define OBJ$C_GSD_ENV 8 -#define OBJ$C_GSD_LSY 9 -#define OBJ$C_GSD_LEPM 10 -#define OBJ$C_GSD_LPRO 11 -#define OBJ$C_GSD_SPSC 12 -#define OBJ$C_TIR 2 -#define OBJ$C_EOM 3 -#define OBJ$C_DBG 4 -#define OBJ$C_TBT 5 -#define OBJ$C_LNK 6 -#define OBJ$C_EOMW 7 -#define OBJ$C_MAXRECTYP 7 -#define OBJ$K_SUBTYP 1 -#define OBJ$C_SUBTYP 1 -#define OBJ$C_MAXRECSIZ 2048 -#define OBJ$C_STRLVL 0 -#define OBJ$C_SYMSIZ 31 -#define OBJ$C_STOREPLIM -1 -#define OBJ$C_PSCALILIM 9 - -#define MHD$C_MHD 0 -#define MHD$C_LNM 1 -#define MHD$C_SRC 2 -#define MHD$C_TTL 3 -#define MHD$C_CPR 4 -#define MHD$C_MTC 5 -#define MHD$C_GTX 6 -#define MHD$C_MAXHDRTYP 6 - -#define GSD$K_ENTRIES 1 -#define GSD$C_ENTRIES 1 -#define GSD$C_PSC 0 -#define GSD$C_SYM 1 -#define GSD$C_EPM 2 -#define GSD$C_PRO 3 -#define GSD$C_SYMW 4 -#define GSD$C_EPMW 5 -#define GSD$C_PROW 6 -#define GSD$C_IDC 7 -#define GSD$C_ENV 8 -#define GSD$C_LSY 9 -#define GSD$C_LEPM 10 -#define GSD$C_LPRO 11 -#define GSD$C_SPSC 12 -#define GSD$C_SYMV 13 -#define GSD$C_EPMV 14 -#define GSD$C_PROV 15 -#define GSD$C_MAXRECTYP 15 - -#define GSY$M_WEAK 1 -#define GSY$M_DEF 2 -#define GSY$M_UNI 4 -#define GSY$M_REL 8 - -#define GPS$M_PIC 1 -#define GPS$M_LIB 2 -#define GPS$M_OVR 4 -#define GPS$M_REL 8 -#define GPS$M_GBL 16 -#define GPS$M_SHR 32 -#define GPS$M_EXE 64 -#define GPS$M_RD 128 -#define GPS$M_WRT 256 -#define GPS$M_VEC 512 -#define GPS$K_NAME 9 -#define GPS$C_NAME 9 - -#define TIR$C_STA_GBL 0 -#define TIR$C_STA_SB 1 -#define TIR$C_STA_SW 2 -#define TIR$C_STA_LW 3 -#define TIR$C_STA_PB 4 -#define TIR$C_STA_PW 5 -#define TIR$C_STA_PL 6 -#define TIR$C_STA_UB 7 -#define TIR$C_STA_UW 8 -#define TIR$C_STA_BFI 9 -#define TIR$C_STA_WFI 10 -#define TIR$C_STA_LFI 11 -#define TIR$C_STA_EPM 12 -#define TIR$C_STA_CKARG 13 -#define TIR$C_STA_WPB 14 -#define TIR$C_STA_WPW 15 -#define TIR$C_STA_WPL 16 -#define TIR$C_STA_LSY 17 -#define TIR$C_STA_LIT 18 -#define TIR$C_STA_LEPM 19 -#define TIR$C_MAXSTACOD 19 -#define TIR$C_MINSTOCOD 20 -#define TIR$C_STO_SB 20 -#define TIR$C_STO_SW 21 -#define TIR$C_STO_L 22 -#define TIR$C_STO_BD 23 -#define TIR$C_STO_WD 24 -#define TIR$C_STO_LD 25 -#define TIR$C_STO_LI 26 -#define TIR$C_STO_PIDR 27 -#define TIR$C_STO_PICR 28 -#define TIR$C_STO_RSB 29 -#define TIR$C_STO_RSW 30 -#define TIR$C_STO_RL 31 -#define TIR$C_STO_VPS 32 -#define TIR$C_STO_USB 33 -#define TIR$C_STO_USW 34 -#define TIR$C_STO_RUB 35 -#define TIR$C_STO_RUW 36 -#define TIR$C_STO_B 37 -#define TIR$C_STO_W 38 -#define TIR$C_STO_RB 39 -#define TIR$C_STO_RW 40 -#define TIR$C_STO_RIVB 41 -#define TIR$C_STO_PIRR 42 -#define TIR$C_MAXSTOCOD 42 -#define TIR$C_MINOPRCOD 50 -#define TIR$C_OPR_NOP 50 -#define TIR$C_OPR_ADD 51 -#define TIR$C_OPR_SUB 52 -#define TIR$C_OPR_MUL 53 -#define TIR$C_OPR_DIV 54 -#define TIR$C_OPR_AND 55 -#define TIR$C_OPR_IOR 56 -#define TIR$C_OPR_EOR 57 -#define TIR$C_OPR_NEG 58 -#define TIR$C_OPR_COM 59 -#define TIR$C_OPR_INSV 60 -#define TIR$C_OPR_ASH 61 -#define TIR$C_OPR_USH 62 -#define TIR$C_OPR_ROT 63 -#define TIR$C_OPR_SEL 64 -#define TIR$C_OPR_REDEF 65 -#define TIR$C_OPR_DFLIT 66 -#define TIR$C_MAXOPRCOD 66 -#define TIR$C_MINCTLCOD 80 -#define TIR$C_CTL_SETRB 80 -#define TIR$C_CTL_AUGRB 81 -#define TIR$C_CTL_DFLOC 82 -#define TIR$C_CTL_STLOC 83 -#define TIR$C_CTL_STKDL 84 -#define TIR$C_MAXCTLCOD 84 - -/* - * Debugger symbol definitions: These are done by hand, as no - * machine-readable version seems - * to be available. - */ -#define DST$C_C 7 /* Language == "C" */ -#define DST$C_VERSION 153 -#define DST$C_SOURCE 155 /* Source file */ -#define DST$C_PROLOG 162 -#define DST$C_BLKBEG 176 /* Beginning of block */ -#define DST$C_BLKEND 177 /* End of block */ -#define DST$C_ENTRY 181 -#define DST$C_PSECT 184 -#define DST$C_LINE_NUM 185 /* Line Number */ -#define DST$C_LBLORLIT 186 -#define DST$C_LABEL 187 -#define DST$C_MODBEG 188 /* Beginning of module */ -#define DST$C_MODEND 189 /* End of module */ -#define DST$C_RTNBEG 190 /* Beginning of routine */ -#define DST$C_RTNEND 191 /* End of routine */ -#define DST$C_DELTA_PC_W 1 /* Incr PC */ -#define DST$C_INCR_LINUM 2 /* Incr Line # */ -#define DST$C_INCR_LINUM_W 3 /* Incr Line # */ -#define DST$C_SET_LINUM_INCR 4 -#define DST$C_SET_LINUM_INCR_W 5 -#define DST$C_RESET_LINUM_INCR 6 -#define DST$C_BEG_STMT_MODE 7 -#define DST$C_END_STMT_MODE 8 -#define DST$C_SET_LINE_NUM 9 /* Set Line # */ -#define DST$C_SET_PC 10 -#define DST$C_SET_PC_W 11 -#define DST$C_SET_PC_L 12 -#define DST$C_SET_STMTNUM 13 -#define DST$C_TERM 14 /* End of lines */ -#define DST$C_TERM_W 15 /* End of lines */ -#define DST$C_SET_ABS_PC 16 /* Set PC */ -#define DST$C_DELTA_PC_L 17 /* Incr PC */ -#define DST$C_INCR_LINUM_L 18 /* Incr Line # */ -#define DST$C_SET_LINUM_B 19 /* Set Line # */ -#define DST$C_SET_LINUM_L 20 /* Set Line # */ -#define DST$C_TERM_L 21 /* End of lines */ -/* these are used with DST$C_SOURCE */ -#define DST$C_SRC_FORMFEED 16 /* ^L counts */ -#define DST$C_SRC_DECLFILE 1 /* Declare file */ -#define DST$C_SRC_SETFILE 2 /* Set file */ -#define DST$C_SRC_SETREC_L 3 /* Set record */ -#define DST$C_SRC_DEFLINES_W 10 /* # of line */ -/* the following are the codes for the various data types. Anything not on - * the list is included under 'advanced_type' - */ -#define DBG$C_UCHAR 0x02 -#define DBG$C_USINT 0x03 -#define DBG$C_ULINT 0x04 -#define DBG$C_SCHAR 0x06 -#define DBG$C_SSINT 0x07 -#define DBG$C_SLINT 0x08 -#define DBG$C_REAL4 0x0a -#define DBG$C_REAL8 0x0b -#define DBG$C_FUNCTION_ADDR 0x17 -#define DBG$C_ADVANCED_TYPE 0xa3 -/* These are the codes that are used to generate the definitions of struct - * union and enum records - */ -#define DBG$C_ENUM_ITEM 0xa4 -#define DBG$C_ENUM_START 0xa5 -#define DBG$C_ENUM_END 0xa6 -#define DBG$C_STRUCT_START 0xab -#define DBG$C_STRUCT_ITEM 0xff -#define DBG$C_STRUCT_END 0xac -/* These are the codes that are used in the suffix records to determine the - * actual data type - */ -#define DBG$C_BASIC 0x01 -#define DBG$C_BASIC_ARRAY 0x02 -#define DBG$C_STRUCT 0x03 -#define DBG$C_POINTER 0x04 -#define DBG$C_VOID 0x05 -#define DBG$C_COMPLEX_ARRAY 0x07 -/* These codes are used in the generation of the symbol definition records - */ -#define DBG$C_FUNCTION_PARAMETER 0xc9 -#define DBG$C_LOCAL_SYM 0xd9 diff --git a/gnu/usr.bin/awk/regex.c b/gnu/usr.bin/awk/regex.c deleted file mode 100644 index 6a36f3d..0000000 --- a/gnu/usr.bin/awk/regex.c +++ /dev/null @@ -1,5070 +0,0 @@ -/* Extended regular expression matching and search library, - version 0.12. - (Implements POSIX draft P10003.2/D11.2, except for - internationalization features.) - - Copyright (C) 1993 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* AIX requires this to be the first thing in the file. */ -#if defined (_AIX) && !defined (REGEX_MALLOC) - #pragma alloca -#endif - -#define _GNU_SOURCE - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#if defined(STDC_HEADERS) && !defined(emacs) -#include -#else -/* We need this for `regex.h', and perhaps for the Emacs include files. */ -#include -#endif - -/* The `emacs' switch turns on certain matching commands - that make sense only in Emacs. */ -#ifdef emacs - -#include "lisp.h" -#include "buffer.h" -#include "syntax.h" - -/* Emacs uses `NULL' as a predicate. */ -#undef NULL - -#else /* not emacs */ - -/* We used to test for `BSTRING' here, but only GCC and Emacs define - `BSTRING', as far as I know, and neither of them use this code. */ -#if HAVE_STRING_H || STDC_HEADERS -#include -#ifndef bcmp -#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) -#endif -#ifndef bcopy -#define bcopy(s, d, n) memcpy ((d), (s), (n)) -#endif -#ifndef bzero -#define bzero(s, n) memset ((s), 0, (n)) -#endif -#else -#include -#endif - -#ifdef STDC_HEADERS -#include -#else -char *malloc (); -char *realloc (); -#endif - - -/* Define the syntax stuff for \<, \>, etc. */ - -/* This must be nonzero for the wordchar and notwordchar pattern - commands in re_match_2. */ -#ifndef Sword -#define Sword 1 -#endif - -#ifdef SYNTAX_TABLE - -extern char *re_syntax_table; - -#else /* not SYNTAX_TABLE */ - -/* How many characters in the character set. */ -#define CHAR_SET_SIZE 256 - -static char re_syntax_table[CHAR_SET_SIZE]; - -static void -init_syntax_once () -{ - register int c; - static int done = 0; - - if (done) - return; - - bzero (re_syntax_table, sizeof re_syntax_table); - - for (c = 'a'; c <= 'z'; c++) - re_syntax_table[c] = Sword; - - for (c = 'A'; c <= 'Z'; c++) - re_syntax_table[c] = Sword; - - for (c = '0'; c <= '9'; c++) - re_syntax_table[c] = Sword; - - re_syntax_table['_'] = Sword; - - done = 1; -} - -#endif /* not SYNTAX_TABLE */ - -#define SYNTAX(c) re_syntax_table[c] - -#endif /* not emacs */ - -/* Get the interface, including the syntax bits. */ -#include "regex.h" - -/* isalpha etc. are used for the character classes. */ -#include - -/* Jim Meyering writes: - - "... Some ctype macros are valid only for character codes that - isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when - using /bin/cc or gcc but without giving an ansi option). So, all - ctype uses should be through macros like ISPRINT... If - STDC_HEADERS is defined, then autoconf has verified that the ctype - macros don't need to be guarded with references to isascii. ... - Defining isascii to 1 should let any compiler worth its salt - eliminate the && through constant folding." */ -#if ! defined (isascii) || defined (STDC_HEADERS) -#undef isascii -#define isascii(c) 1 -#endif - -#ifdef isblank -#define ISBLANK(c) (isascii (c) && isblank (c)) -#else -#define ISBLANK(c) ((c) == ' ' || (c) == '\t') -#endif -#ifdef isgraph -#define ISGRAPH(c) (isascii (c) && isgraph (c)) -#else -#define ISGRAPH(c) (isascii (c) && isprint (c) && !isspace (c)) -#endif - -#define ISPRINT(c) (isascii (c) && isprint (c)) -#define ISDIGIT(c) (isascii (c) && isdigit (c)) -#define ISALNUM(c) (isascii (c) && isalnum (c)) -#define ISALPHA(c) (isascii (c) && isalpha (c)) -#define ISCNTRL(c) (isascii (c) && iscntrl (c)) -#define ISLOWER(c) (isascii (c) && islower (c)) -#define ISPUNCT(c) (isascii (c) && ispunct (c)) -#define ISSPACE(c) (isascii (c) && isspace (c)) -#define ISUPPER(c) (isascii (c) && isupper (c)) -#define ISXDIGIT(c) (isascii (c) && isxdigit (c)) - -#ifndef NULL -#define NULL 0 -#endif - -/* We remove any previous definition of `SIGN_EXTEND_CHAR', - since ours (we hope) works properly with all combinations of - machines, compilers, `char' and `unsigned char' argument types. - (Per Bothner suggested the basic approach.) */ -#undef SIGN_EXTEND_CHAR -#if __STDC__ -#define SIGN_EXTEND_CHAR(c) ((signed char) (c)) -#else /* not __STDC__ */ -/* As in Harbison and Steele. */ -#define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128) -#endif - -/* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we - use `alloca' instead of `malloc'. This is because using malloc in - re_search* or re_match* could cause memory leaks when C-g is used in - Emacs; also, malloc is slower and causes storage fragmentation. On - the other hand, malloc is more portable, and easier to debug. - - Because we sometimes use alloca, some routines have to be macros, - not functions -- `alloca'-allocated space disappears at the end of the - function it is called in. */ - -#ifdef REGEX_MALLOC - -#define REGEX_ALLOCATE malloc -#define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize) - -#else /* not REGEX_MALLOC */ - -/* Emacs already defines alloca, sometimes. */ -#ifndef alloca - -/* Make alloca work the best possible way. */ -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else /* not __GNUC__ */ -#if HAVE_ALLOCA_H -#include -#else /* not __GNUC__ or HAVE_ALLOCA_H */ -#ifndef _AIX /* Already did AIX, up at the top. */ -char *alloca (); -#endif /* not _AIX */ -#endif /* not HAVE_ALLOCA_H */ -#endif /* not __GNUC__ */ - -#endif /* not alloca */ - -#define REGEX_ALLOCATE alloca - -/* Assumes a `char *destination' variable. */ -#define REGEX_REALLOCATE(source, osize, nsize) \ - (destination = (char *) alloca (nsize), \ - bcopy (source, destination, osize), \ - destination) - -#endif /* not REGEX_MALLOC */ - - -/* True if `size1' is non-NULL and PTR is pointing anywhere inside - `string1' or just past its end. This works if PTR is NULL, which is - a good thing. */ -#define FIRST_STRING_P(ptr) \ - (size1 && string1 <= (ptr) && (ptr) <= string1 + size1) - -/* (Re)Allocate N items of type T using malloc, or fail. */ -#define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t))) -#define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t))) -#define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t))) - -#define BYTEWIDTH 8 /* In bits. */ - -#define STREQ(s1, s2) ((strcmp (s1, s2) == 0)) - -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -typedef char boolean; -#define false 0 -#define true 1 - -/* These are the command codes that appear in compiled regular - expressions. Some opcodes are followed by argument bytes. A - command code can specify any interpretation whatsoever for its - arguments. Zero bytes may appear in the compiled regular expression. - - The value of `exactn' is needed in search.c (search_buffer) in Emacs. - So regex.h defines a symbol `RE_EXACTN_VALUE' to be 1; the value of - `exactn' we use here must also be 1. */ - -typedef enum -{ - no_op = 0, - - /* Followed by one byte giving n, then by n literal bytes. */ - exactn = 1, - - /* Matches any (more or less) character. */ - anychar, - - /* Matches any one char belonging to specified set. First - following byte is number of bitmap bytes. Then come bytes - for a bitmap saying which chars are in. Bits in each byte - are ordered low-bit-first. A character is in the set if its - bit is 1. A character too large to have a bit in the map is - automatically not in the set. */ - charset, - - /* Same parameters as charset, but match any character that is - not one of those specified. */ - charset_not, - - /* Start remembering the text that is matched, for storing in a - register. Followed by one byte with the register number, in - the range 0 to one less than the pattern buffer's re_nsub - field. Then followed by one byte with the number of groups - inner to this one. (This last has to be part of the - start_memory only because we need it in the on_failure_jump - of re_match_2.) */ - start_memory, - - /* Stop remembering the text that is matched and store it in a - memory register. Followed by one byte with the register - number, in the range 0 to one less than `re_nsub' in the - pattern buffer, and one byte with the number of inner groups, - just like `start_memory'. (We need the number of inner - groups here because we don't have any easy way of finding the - corresponding start_memory when we're at a stop_memory.) */ - stop_memory, - - /* Match a duplicate of something remembered. Followed by one - byte containing the register number. */ - duplicate, - - /* Fail unless at beginning of line. */ - begline, - - /* Fail unless at end of line. */ - endline, - - /* Succeeds if at beginning of buffer (if emacs) or at beginning - of string to be matched (if not). */ - begbuf, - - /* Analogously, for end of buffer/string. */ - endbuf, - - /* Followed by two byte relative address to which to jump. */ - jump, - - /* Same as jump, but marks the end of an alternative. */ - jump_past_alt, - - /* Followed by two-byte relative address of place to resume at - in case of failure. */ - on_failure_jump, - - /* Like on_failure_jump, but pushes a placeholder instead of the - current string position when executed. */ - on_failure_keep_string_jump, - - /* Throw away latest failure point and then jump to following - two-byte relative address. */ - pop_failure_jump, - - /* Change to pop_failure_jump if know won't have to backtrack to - match; otherwise change to jump. This is used to jump - back to the beginning of a repeat. If what follows this jump - clearly won't match what the repeat does, such that we can be - sure that there is no use backtracking out of repetitions - already matched, then we change it to a pop_failure_jump. - Followed by two-byte address. */ - maybe_pop_jump, - - /* Jump to following two-byte address, and push a dummy failure - point. This failure point will be thrown away if an attempt - is made to use it for a failure. A `+' construct makes this - before the first repeat. Also used as an intermediary kind - of jump when compiling an alternative. */ - dummy_failure_jump, - - /* Push a dummy failure point and continue. Used at the end of - alternatives. */ - push_dummy_failure, - - /* Followed by two-byte relative address and two-byte number n. - After matching N times, jump to the address upon failure. */ - succeed_n, - - /* Followed by two-byte relative address, and two-byte number n. - Jump to the address N times, then fail. */ - jump_n, - - /* Set the following two-byte relative address to the - subsequent two-byte number. The address *includes* the two - bytes of number. */ - set_number_at, - - wordchar, /* Matches any word-constituent character. */ - notwordchar, /* Matches any char that is not a word-constituent. */ - - wordbeg, /* Succeeds if at word beginning. */ - wordend, /* Succeeds if at word end. */ - - wordbound, /* Succeeds if at a word boundary. */ - notwordbound /* Succeeds if not at a word boundary. */ - -#ifdef emacs - ,before_dot, /* Succeeds if before point. */ - at_dot, /* Succeeds if at point. */ - after_dot, /* Succeeds if after point. */ - - /* Matches any character whose syntax is specified. Followed by - a byte which contains a syntax code, e.g., Sword. */ - syntaxspec, - - /* Matches any character whose syntax is not that specified. */ - notsyntaxspec -#endif /* emacs */ -} re_opcode_t; - -/* Common operations on the compiled pattern. */ - -/* Store NUMBER in two contiguous bytes starting at DESTINATION. */ - -#define STORE_NUMBER(destination, number) \ - do { \ - (destination)[0] = (number) & 0377; \ - (destination)[1] = (number) >> 8; \ - } while (0) - -/* Same as STORE_NUMBER, except increment DESTINATION to - the byte after where the number is stored. Therefore, DESTINATION - must be an lvalue. */ - -#define STORE_NUMBER_AND_INCR(destination, number) \ - do { \ - STORE_NUMBER (destination, number); \ - (destination) += 2; \ - } while (0) - -/* Put into DESTINATION a number stored in two contiguous bytes starting - at SOURCE. */ - -#define EXTRACT_NUMBER(destination, source) \ - do { \ - (destination) = *(source) & 0377; \ - (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \ - } while (0) - -#ifdef DEBUG -static void extract_number _RE_ARGS((int *dest, unsigned char *source)); -static void -extract_number (dest, source) - int *dest; - unsigned char *source; -{ - int temp = SIGN_EXTEND_CHAR (*(source + 1)); - *dest = *source & 0377; - *dest += temp << 8; -} - -#ifndef EXTRACT_MACROS /* To debug the macros. */ -#undef EXTRACT_NUMBER -#define EXTRACT_NUMBER(dest, src) extract_number (&dest, src) -#endif /* not EXTRACT_MACROS */ - -#endif /* DEBUG */ - -/* Same as EXTRACT_NUMBER, except increment SOURCE to after the number. - SOURCE must be an lvalue. */ - -#define EXTRACT_NUMBER_AND_INCR(destination, source) \ - do { \ - EXTRACT_NUMBER (destination, source); \ - (source) += 2; \ - } while (0) - -#ifdef DEBUG -static void extract_number_and_incr _RE_ARGS((int *destination, - unsigned char **source)); -static void -extract_number_and_incr (destination, source) - int *destination; - unsigned char **source; -{ - extract_number (destination, *source); - *source += 2; -} - -#ifndef EXTRACT_MACROS -#undef EXTRACT_NUMBER_AND_INCR -#define EXTRACT_NUMBER_AND_INCR(dest, src) \ - extract_number_and_incr (&dest, &src) -#endif /* not EXTRACT_MACROS */ - -#endif /* DEBUG */ - -/* If DEBUG is defined, Regex prints many voluminous messages about what - it is doing (if the variable `debug' is nonzero). If linked with the - main program in `iregex.c', you can enter patterns and strings - interactively. And if linked with the main program in `main.c' and - the other test files, you can run the already-written tests. */ - -#ifdef DEBUG - -/* We use standard I/O for debugging. */ -#include - -/* It is useful to test things that ``must'' be true when debugging. */ -#include - -static int debug = 0; - -#define DEBUG_STATEMENT(e) e -#define DEBUG_PRINT1(x) if (debug) printf (x) -#define DEBUG_PRINT2(x1, x2) if (debug) printf (x1, x2) -#define DEBUG_PRINT3(x1, x2, x3) if (debug) printf (x1, x2, x3) -#define DEBUG_PRINT4(x1, x2, x3, x4) if (debug) printf (x1, x2, x3, x4) -#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ - if (debug) print_partial_compiled_pattern (s, e) -#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ - if (debug) print_double_string (w, s1, sz1, s2, sz2) - - -extern void printchar (); - -/* Print the fastmap in human-readable form. */ - -void -print_fastmap (fastmap) - char *fastmap; -{ - unsigned was_a_range = 0; - unsigned i = 0; - - while (i < (1 << BYTEWIDTH)) - { - if (fastmap[i++]) - { - was_a_range = 0; - printchar (i - 1); - while (i < (1 << BYTEWIDTH) && fastmap[i]) - { - was_a_range = 1; - i++; - } - if (was_a_range) - { - printf ("-"); - printchar (i - 1); - } - } - } - putchar ('\n'); -} - - -/* Print a compiled pattern string in human-readable form, starting at - the START pointer into it and ending just before the pointer END. */ - -void -print_partial_compiled_pattern (start, end) - unsigned char *start; - unsigned char *end; -{ - int mcnt, mcnt2; - unsigned char *p = start; - unsigned char *pend = end; - - if (start == NULL) - { - printf ("(null)\n"); - return; - } - - /* Loop over pattern commands. */ - while (p < pend) - { - printf ("%d:\t", p - start); - - switch ((re_opcode_t) *p++) - { - case no_op: - printf ("/no_op"); - break; - - case exactn: - mcnt = *p++; - printf ("/exactn/%d", mcnt); - do - { - putchar ('/'); - printchar (*p++); - } - while (--mcnt); - break; - - case start_memory: - mcnt = *p++; - printf ("/start_memory/%d/%d", mcnt, *p++); - break; - - case stop_memory: - mcnt = *p++; - printf ("/stop_memory/%d/%d", mcnt, *p++); - break; - - case duplicate: - printf ("/duplicate/%d", *p++); - break; - - case anychar: - printf ("/anychar"); - break; - - case charset: - case charset_not: - { - register int c, last = -100; - register int in_range = 0; - - printf ("/charset [%s", - (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); - - assert (p + *p < pend); - - for (c = 0; c < 256; c++) - if (c / 8 < *p - && (p[1 + (c/8)] & (1 << (c % 8)))) - { - /* Are we starting a range? */ - if (last + 1 == c && ! in_range) - { - putchar ('-'); - in_range = 1; - } - /* Have we broken a range? */ - else if (last + 1 != c && in_range) - { - printchar (last); - in_range = 0; - } - - if (! in_range) - printchar (c); - - last = c; - } - - if (in_range) - printchar (last); - - putchar (']'); - - p += 1 + *p; - } - break; - - case begline: - printf ("/begline"); - break; - - case endline: - printf ("/endline"); - break; - - case on_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/on_failure_jump to %d", p + mcnt - start); - break; - - case on_failure_keep_string_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/on_failure_keep_string_jump to %d", p + mcnt - start); - break; - - case dummy_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/dummy_failure_jump to %d", p + mcnt - start); - break; - - case push_dummy_failure: - printf ("/push_dummy_failure"); - break; - - case maybe_pop_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/maybe_pop_jump to %d", p + mcnt - start); - break; - - case pop_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/pop_failure_jump to %d", p + mcnt - start); - break; - - case jump_past_alt: - extract_number_and_incr (&mcnt, &p); - printf ("/jump_past_alt to %d", p + mcnt - start); - break; - - case jump: - extract_number_and_incr (&mcnt, &p); - printf ("/jump to %d", p + mcnt - start); - break; - - case succeed_n: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/succeed_n to %d, %d times", p + mcnt - start, mcnt2); - break; - - case jump_n: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/jump_n to %d, %d times", p + mcnt - start, mcnt2); - break; - - case set_number_at: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/set_number_at location %d to %d", p + mcnt - start, mcnt2); - break; - - case wordbound: - printf ("/wordbound"); - break; - - case notwordbound: - printf ("/notwordbound"); - break; - - case wordbeg: - printf ("/wordbeg"); - break; - - case wordend: - printf ("/wordend"); - -#ifdef emacs - case before_dot: - printf ("/before_dot"); - break; - - case at_dot: - printf ("/at_dot"); - break; - - case after_dot: - printf ("/after_dot"); - break; - - case syntaxspec: - printf ("/syntaxspec"); - mcnt = *p++; - printf ("/%d", mcnt); - break; - - case notsyntaxspec: - printf ("/notsyntaxspec"); - mcnt = *p++; - printf ("/%d", mcnt); - break; -#endif /* emacs */ - - case wordchar: - printf ("/wordchar"); - break; - - case notwordchar: - printf ("/notwordchar"); - break; - - case begbuf: - printf ("/begbuf"); - break; - - case endbuf: - printf ("/endbuf"); - break; - - default: - printf ("?%d", *(p-1)); - } - - putchar ('\n'); - } - - printf ("%d:\tend of pattern.\n", p - start); -} - - -void -print_compiled_pattern (bufp) - struct re_pattern_buffer *bufp; -{ - unsigned char *buffer = bufp->buffer; - - print_partial_compiled_pattern (buffer, buffer + bufp->used); - printf ("%d bytes used/%d bytes allocated.\n", bufp->used, bufp->allocated); - - if (bufp->fastmap_accurate && bufp->fastmap) - { - printf ("fastmap: "); - print_fastmap (bufp->fastmap); - } - - printf ("re_nsub: %d\t", bufp->re_nsub); - printf ("regs_alloc: %d\t", bufp->regs_allocated); - printf ("can_be_null: %d\t", bufp->can_be_null); - printf ("newline_anchor: %d\n", bufp->newline_anchor); - printf ("no_sub: %d\t", bufp->no_sub); - printf ("not_bol: %d\t", bufp->not_bol); - printf ("not_eol: %d\t", bufp->not_eol); - printf ("syntax: %d\n", bufp->syntax); - /* Perhaps we should print the translate table? */ -} - - -void -print_double_string (where, string1, size1, string2, size2) - const char *where; - const char *string1; - const char *string2; - int size1; - int size2; -{ - unsigned this_char; - - if (where == NULL) - printf ("(null)"); - else - { - if (FIRST_STRING_P (where)) - { - for (this_char = where - string1; this_char < size1; this_char++) - printchar (string1[this_char]); - - where = string2; - } - - for (this_char = where - string2; this_char < size2; this_char++) - printchar (string2[this_char]); - } -} - -#else /* not DEBUG */ - -#undef assert -#define assert(e) - -#define DEBUG_STATEMENT(e) -#define DEBUG_PRINT1(x) -#define DEBUG_PRINT2(x1, x2) -#define DEBUG_PRINT3(x1, x2, x3) -#define DEBUG_PRINT4(x1, x2, x3, x4) -#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) -#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) - -#endif /* not DEBUG */ - -/* Set by `re_set_syntax' to the current regexp syntax to recognize. Can - also be assigned to arbitrarily: each pattern buffer stores its own - syntax, so it can be changed between regex compilations. */ -reg_syntax_t re_syntax_options = RE_SYNTAX_EMACS; - - -/* Specify the precise syntax of regexps for compilation. This provides - for compatibility for various utilities which historically have - different, incompatible syntaxes. - - The argument SYNTAX is a bit mask comprised of the various bits - defined in regex.h. We return the old syntax. */ - -reg_syntax_t -re_set_syntax (syntax) - reg_syntax_t syntax; -{ - reg_syntax_t ret = re_syntax_options; - - re_syntax_options = syntax; - return ret; -} - -/* This table gives an error message for each of the error codes listed - in regex.h. Obviously the order here has to be same as there. */ - -static const char *re_error_msg[] = - { NULL, /* REG_NOERROR */ - "No match", /* REG_NOMATCH */ - "Invalid regular expression", /* REG_BADPAT */ - "Invalid collation character", /* REG_ECOLLATE */ - "Invalid character class name", /* REG_ECTYPE */ - "Trailing backslash", /* REG_EESCAPE */ - "Invalid back reference", /* REG_ESUBREG */ - "Unmatched [ or [^", /* REG_EBRACK */ - "Unmatched ( or \\(", /* REG_EPAREN */ - "Unmatched \\{", /* REG_EBRACE */ - "Invalid content of \\{\\}", /* REG_BADBR */ - "Invalid range end", /* REG_ERANGE */ - "Memory exhausted", /* REG_ESPACE */ - "Invalid preceding regular expression", /* REG_BADRPT */ - "Premature end of regular expression", /* REG_EEND */ - "Regular expression too big", /* REG_ESIZE */ - "Unmatched ) or \\)", /* REG_ERPAREN */ - }; - -/* Subroutine declarations and macros for regex_compile. */ - -static reg_errcode_t regex_compile _RE_ARGS((const char *pattern, size_t size, - reg_syntax_t syntax, - struct re_pattern_buffer *bufp)); -static void store_op1 _RE_ARGS((re_opcode_t op, unsigned char *loc, int arg)); -static void store_op2 _RE_ARGS((re_opcode_t op, unsigned char *loc, - int arg1, int arg2)); -static void insert_op1 _RE_ARGS((re_opcode_t op, unsigned char *loc, - int arg, unsigned char *end)); -static void insert_op2 _RE_ARGS((re_opcode_t op, unsigned char *loc, - int arg1, int arg2, unsigned char *end)); -static boolean at_begline_loc_p _RE_ARGS((const char *pattern, const char *p, - reg_syntax_t syntax)); -static boolean at_endline_loc_p _RE_ARGS((const char *p, const char *pend, - reg_syntax_t syntax)); -static reg_errcode_t compile_range _RE_ARGS((const char **p_ptr, - const char *pend, - char *translate, - reg_syntax_t syntax, - unsigned char *b)); - -/* Fetch the next character in the uncompiled pattern---translating it - if necessary. Also cast from a signed character in the constant - string passed to us by the user to an unsigned char that we can use - as an array index (in, e.g., `translate'). */ -#define PATFETCH(c) \ - do {if (p == pend) return REG_EEND; \ - c = (unsigned char) *p++; \ - if (translate) c = translate[c]; \ - } while (0) - -/* Fetch the next character in the uncompiled pattern, with no - translation. */ -#define PATFETCH_RAW(c) \ - do {if (p == pend) return REG_EEND; \ - c = (unsigned char) *p++; \ - } while (0) - -/* Go backwards one character in the pattern. */ -#define PATUNFETCH p-- - - -/* If `translate' is non-null, return translate[D], else just D. We - cast the subscript to translate because some data is declared as - `char *', to avoid warnings when a string constant is passed. But - when we use a character as a subscript we must make it unsigned. */ -#define TRANSLATE(d) (translate ? translate[(unsigned char) (d)] : (d)) - - -/* Macros for outputting the compiled pattern into `buffer'. */ - -/* If the buffer isn't allocated when it comes in, use this. */ -#define INIT_BUF_SIZE 32 - -/* Make sure we have at least N more bytes of space in buffer. */ -#define GET_BUFFER_SPACE(n) \ - while (b - bufp->buffer + (n) > bufp->allocated) \ - EXTEND_BUFFER () - -/* Make sure we have one more byte of buffer space and then add C to it. */ -#define BUF_PUSH(c) \ - do { \ - GET_BUFFER_SPACE (1); \ - *b++ = (unsigned char) (c); \ - } while (0) - - -/* Ensure we have two more bytes of buffer space and then append C1 and C2. */ -#define BUF_PUSH_2(c1, c2) \ - do { \ - GET_BUFFER_SPACE (2); \ - *b++ = (unsigned char) (c1); \ - *b++ = (unsigned char) (c2); \ - } while (0) - - -/* As with BUF_PUSH_2, except for three bytes. */ -#define BUF_PUSH_3(c1, c2, c3) \ - do { \ - GET_BUFFER_SPACE (3); \ - *b++ = (unsigned char) (c1); \ - *b++ = (unsigned char) (c2); \ - *b++ = (unsigned char) (c3); \ - } while (0) - - -/* Store a jump with opcode OP at LOC to location TO. We store a - relative address offset by the three bytes the jump itself occupies. */ -#define STORE_JUMP(op, loc, to) \ - store_op1 (op, loc, (int)((to) - (loc) - 3)) - -/* Likewise, for a two-argument jump. */ -#define STORE_JUMP2(op, loc, to, arg) \ - store_op2 (op, loc, (int)((to) - (loc) - 3), arg) - -/* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */ -#define INSERT_JUMP(op, loc, to) \ - insert_op1 (op, loc, (int)((to) - (loc) - 3), b) - -/* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */ -#define INSERT_JUMP2(op, loc, to, arg) \ - insert_op2 (op, loc, (int)((to) - (loc) - 3), arg, b) - - -/* This is not an arbitrary limit: the arguments which represent offsets - into the pattern are two bytes long. So if 2^16 bytes turns out to - be too small, many things would have to change. */ -/* Any other compiler which, like MSC, has allocation limit below 2^16 - bytes will have to use approach similar to what was done below for - MSC and drop MAX_BUF_SIZE a bit. Otherwise you may end up - reallocating to 0 bytes. Such thing is not going to work too well. - You have been warned!! */ -#ifdef _MSC_VER -/* Microsoft C 16-bit versions limit malloc to approx 65512 bytes. - The REALLOC define eliminates a flurry of conversion warnings, - but is not required. */ -#define MAX_BUF_SIZE 65500L -#define REALLOC(p,s) realloc((p), (size_t) (s)) -#else -#define MAX_BUF_SIZE (1L << 16) -#define REALLOC realloc -#endif - -/* Extend the buffer by twice its current size via realloc and - reset the pointers that pointed into the old block to point to the - correct places in the new one. If extending the buffer results in it - being larger than MAX_BUF_SIZE, then flag memory exhausted. */ -#define EXTEND_BUFFER() \ - do { \ - unsigned char *old_buffer = bufp->buffer; \ - if (bufp->allocated == MAX_BUF_SIZE) \ - return REG_ESIZE; \ - bufp->allocated <<= 1; \ - if (bufp->allocated > MAX_BUF_SIZE) \ - bufp->allocated = MAX_BUF_SIZE; \ - bufp->buffer = (unsigned char *) REALLOC(bufp->buffer, bufp->allocated);\ - if (bufp->buffer == NULL) \ - return REG_ESPACE; \ - /* If the buffer moved, move all the pointers into it. */ \ - if (old_buffer != bufp->buffer) \ - { \ - b = (b - old_buffer) + bufp->buffer; \ - begalt = (begalt - old_buffer) + bufp->buffer; \ - if (fixup_alt_jump) \ - fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\ - if (laststart) \ - laststart = (laststart - old_buffer) + bufp->buffer; \ - if (pending_exact) \ - pending_exact = (pending_exact - old_buffer) + bufp->buffer; \ - } \ - } while (0) - - -/* Since we have one byte reserved for the register number argument to - {start,stop}_memory, the maximum number of groups we can report - things about is what fits in that byte. */ -#define MAX_REGNUM 255 - -/* But patterns can have more than `MAX_REGNUM' registers. We just - ignore the excess. */ -typedef unsigned regnum_t; - - -/* Macros for the compile stack. */ - -/* Since offsets can go either forwards or backwards, this type needs to - be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ -/* int may be not enough when sizeof(int) == 2 */ -typedef long pattern_offset_t; - -typedef struct -{ - pattern_offset_t begalt_offset; - pattern_offset_t fixup_alt_jump; - pattern_offset_t inner_group_offset; - pattern_offset_t laststart_offset; - regnum_t regnum; -} compile_stack_elt_t; - - -typedef struct -{ - compile_stack_elt_t *stack; - unsigned size; - unsigned avail; /* Offset of next open position. */ -} compile_stack_type; - - -#define INIT_COMPILE_STACK_SIZE 32 - -#define COMPILE_STACK_EMPTY (compile_stack.avail == 0) -#define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size) - -/* The next available element. */ -#define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail]) - - -/* Set the bit for character C in a list. */ -#define SET_LIST_BIT(c) \ - (b[((unsigned char) (c)) / BYTEWIDTH] \ - |= 1 << (((unsigned char) c) % BYTEWIDTH)) - - -/* Get the next unsigned number in the uncompiled pattern. */ -#define GET_UNSIGNED_NUMBER(num) \ - { if (p != pend) \ - { \ - PATFETCH (c); \ - while (ISDIGIT (c)) \ - { \ - if (num < 0) \ - num = 0; \ - num = num * 10 + c - '0'; \ - if (p == pend) \ - break; \ - PATFETCH (c); \ - } \ - } \ - } - -#define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ - -#define IS_CHAR_CLASS(string) \ - (STREQ (string, "alpha") || STREQ (string, "upper") \ - || STREQ (string, "lower") || STREQ (string, "digit") \ - || STREQ (string, "alnum") || STREQ (string, "xdigit") \ - || STREQ (string, "space") || STREQ (string, "print") \ - || STREQ (string, "punct") || STREQ (string, "graph") \ - || STREQ (string, "cntrl") || STREQ (string, "blank")) - -static boolean group_in_compile_stack _RE_ARGS((compile_stack_type - compile_stack, - regnum_t regnum)); - -/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. - Returns one of error codes defined in `regex.h', or zero for success. - - Assumes the `allocated' (and perhaps `buffer') and `translate' - fields are set in BUFP on entry. - - If it succeeds, results are put in BUFP (if it returns an error, the - contents of BUFP are undefined): - `buffer' is the compiled pattern; - `syntax' is set to SYNTAX; - `used' is set to the length of the compiled pattern; - `fastmap_accurate' is zero; - `re_nsub' is the number of subexpressions in PATTERN; - `not_bol' and `not_eol' are zero; - - The `fastmap' and `newline_anchor' fields are neither - examined nor set. */ - -static reg_errcode_t -regex_compile (pattern, size, syntax, bufp) - const char *pattern; - size_t size; - reg_syntax_t syntax; - struct re_pattern_buffer *bufp; -{ - /* We fetch characters from PATTERN here. Even though PATTERN is - `char *' (i.e., signed), we declare these variables as unsigned, so - they can be reliably used as array indices. */ - register unsigned char c, c1; - - /* A random tempory spot in PATTERN. */ - const char *p1; - - /* Points to the end of the buffer, where we should append. */ - register unsigned char *b; - - /* Keeps track of unclosed groups. */ - compile_stack_type compile_stack; - - /* Points to the current (ending) position in the pattern. */ - const char *p = pattern; - const char *pend = pattern + size; - - /* How to translate the characters in the pattern. */ - char *translate = bufp->translate; - - /* Address of the count-byte of the most recently inserted `exactn' - command. This makes it possible to tell if a new exact-match - character can be added to that command or if the character requires - a new `exactn' command. */ - unsigned char *pending_exact = 0; - - /* Address of start of the most recently finished expression. - This tells, e.g., postfix * where to find the start of its - operand. Reset at the beginning of groups and alternatives. */ - unsigned char *laststart = 0; - - /* Address of beginning of regexp, or inside of last group. */ - unsigned char *begalt; - - /* Place in the uncompiled pattern (i.e., the {) to - which to go back if the interval is invalid. */ - const char *beg_interval; - - /* Address of the place where a forward jump should go to the end of - the containing expression. Each alternative of an `or' -- except the - last -- ends with a forward jump of this sort. */ - unsigned char *fixup_alt_jump = 0; - - /* Counts open-groups as they are encountered. Remembered for the - matching close-group on the compile stack, so the same register - number is put in the stop_memory as the start_memory. */ - regnum_t regnum = 0; - -#ifdef DEBUG - DEBUG_PRINT1 ("\nCompiling pattern: "); - if (debug) - { - unsigned debug_count; - - for (debug_count = 0; debug_count < size; debug_count++) - printchar (pattern[debug_count]); - putchar ('\n'); - } -#endif /* DEBUG */ - - /* Initialize the compile stack. */ - compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t); - if (compile_stack.stack == NULL) - return REG_ESPACE; - - compile_stack.size = INIT_COMPILE_STACK_SIZE; - compile_stack.avail = 0; - - /* Initialize the pattern buffer. */ - bufp->syntax = syntax; - bufp->fastmap_accurate = 0; - bufp->not_bol = bufp->not_eol = 0; - - /* Set `used' to zero, so that if we return an error, the pattern - printer (for debugging) will think there's no pattern. We reset it - at the end. */ - bufp->used = 0; - - /* Always count groups, whether or not bufp->no_sub is set. */ - bufp->re_nsub = 0; - -#if !defined (emacs) && !defined (SYNTAX_TABLE) - /* Initialize the syntax table. */ - init_syntax_once (); -#endif - - if (bufp->allocated == 0) - { - if (bufp->buffer) - { /* If zero allocated, but buffer is non-null, try to realloc - enough space. This loses if buffer's address is bogus, but - that is the user's responsibility. */ - RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char); - } - else - { /* Caller did not allocate a buffer. Do it for them. */ - bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char); - } - if (!bufp->buffer) return REG_ESPACE; - - bufp->allocated = INIT_BUF_SIZE; - } - - begalt = b = bufp->buffer; - - /* Loop through the uncompiled pattern until we're at the end. */ - while (p != pend) - { - PATFETCH (c); - - switch (c) - { - case '^': - { - if ( /* If at start of pattern, it's an operator. */ - p == pattern + 1 - /* If context independent, it's an operator. */ - || syntax & RE_CONTEXT_INDEP_ANCHORS - /* Otherwise, depends on what's come before. */ - || at_begline_loc_p (pattern, p, syntax)) - BUF_PUSH (begline); - else - goto normal_char; - } - break; - - - case '$': - { - if ( /* If at end of pattern, it's an operator. */ - p == pend - /* If context independent, it's an operator. */ - || syntax & RE_CONTEXT_INDEP_ANCHORS - /* Otherwise, depends on what's next. */ - || at_endline_loc_p (p, pend, syntax)) - BUF_PUSH (endline); - else - goto normal_char; - } - break; - - - case '+': - case '?': - if ((syntax & RE_BK_PLUS_QM) - || (syntax & RE_LIMITED_OPS)) - goto normal_char; - handle_plus: - case '*': - /* If there is no previous pattern... */ - if (!laststart) - { - if (syntax & RE_CONTEXT_INVALID_OPS) - return REG_BADRPT; - else if (!(syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - } - - { - /* Are we optimizing this jump? */ - boolean keep_string_p = false; - - /* 1 means zero (many) matches is allowed. */ - char zero_times_ok = 0, many_times_ok = 0; - - /* If there is a sequence of repetition chars, collapse it - down to just one (the right one). We can't combine - interval operators with these because of, e.g., `a{2}*', - which should only match an even number of `a's. */ - - for (;;) - { - zero_times_ok |= c != '+'; - many_times_ok |= c != '?'; - - if (p == pend) - break; - - PATFETCH (c); - - if (c == '*' - || (!(syntax & RE_BK_PLUS_QM) && (c == '+' || c == '?'))) - ; - - else if (syntax & RE_BK_PLUS_QM && c == '\\') - { - if (p == pend) return REG_EESCAPE; - - PATFETCH (c1); - if (!(c1 == '+' || c1 == '?')) - { - PATUNFETCH; - PATUNFETCH; - break; - } - - c = c1; - } - else - { - PATUNFETCH; - break; - } - - /* If we get here, we found another repeat character. */ - } - - /* Star, etc. applied to an empty pattern is equivalent - to an empty pattern. */ - if (!laststart) - break; - - /* Now we know whether or not zero matches is allowed - and also whether or not two or more matches is allowed. */ - if (many_times_ok) - { /* More than one repetition is allowed, so put in at the - end a backward relative jump from `b' to before the next - jump we're going to put in below (which jumps from - laststart to after this jump). - - But if we are at the `*' in the exact sequence `.*\n', - insert an unconditional jump backwards to the ., - instead of the beginning of the loop. This way we only - push a failure point once, instead of every time - through the loop. */ - assert (p - 1 > pattern); - - /* Allocate the space for the jump. */ - GET_BUFFER_SPACE (3); - - /* We know we are not at the first character of the pattern, - because laststart was nonzero. And we've already - incremented `p', by the way, to be the character after - the `*'. Do we have to do something analogous here - for null bytes, because of RE_DOT_NOT_NULL? */ - if (TRANSLATE (*(p - 2)) == TRANSLATE ('.') - && zero_times_ok - && p < pend && TRANSLATE (*p) == TRANSLATE ('\n') - && !(syntax & RE_DOT_NEWLINE)) - { /* We have .*\n. */ - STORE_JUMP (jump, b, laststart); - keep_string_p = true; - } - else - /* Anything else. */ - STORE_JUMP (maybe_pop_jump, b, laststart - 3); - - /* We've added more stuff to the buffer. */ - b += 3; - } - - /* On failure, jump from laststart to b + 3, which will be the - end of the buffer after this jump is inserted. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump - : on_failure_jump, - laststart, b + 3); - pending_exact = 0; - b += 3; - - if (!zero_times_ok) - { - /* At least one repetition is required, so insert a - `dummy_failure_jump' before the initial - `on_failure_jump' instruction of the loop. This - effects a skip over that instruction the first time - we hit that loop. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6); - b += 3; - } - } - break; - - - case '.': - laststart = b; - BUF_PUSH (anychar); - break; - - - case '[': - { - boolean had_char_class = false; - - if (p == pend) return REG_EBRACK; - - /* Ensure that we have enough space to push a charset: the - opcode, the length count, and the bitset; 34 bytes in all. */ - GET_BUFFER_SPACE (34); - - laststart = b; - - /* We test `*p == '^' twice, instead of using an if - statement, so we only need one BUF_PUSH. */ - BUF_PUSH (*p == '^' ? charset_not : charset); - if (*p == '^') - p++; - - /* Remember the first position in the bracket expression. */ - p1 = p; - - /* Push the number of bytes in the bitmap. */ - BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH); - - /* Clear the whole map. */ - bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH); - - /* charset_not matches newline according to a syntax bit. */ - if ((re_opcode_t) b[-2] == charset_not - && (syntax & RE_HAT_LISTS_NOT_NEWLINE)) - SET_LIST_BIT ('\n'); - - /* Read in characters and ranges, setting map bits. */ - for (;;) - { - if (p == pend) return REG_EBRACK; - - PATFETCH (c); - - /* \ might escape characters inside [...] and [^...]. */ - if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\') - { - if (p == pend) return REG_EESCAPE; - - PATFETCH (c1); - SET_LIST_BIT (c1); - continue; - } - - /* Could be the end of the bracket expression. If it's - not (i.e., when the bracket expression is `[]' so - far), the ']' character bit gets set way below. */ - if (c == ']' && p != p1 + 1) - break; - - /* Look ahead to see if it's a range when the last thing - was a character class. */ - if (had_char_class && c == '-' && *p != ']') - return REG_ERANGE; - - /* Look ahead to see if it's a range when the last thing - was a character: if this is a hyphen not at the - beginning or the end of a list, then it's the range - operator. */ - if (c == '-' - && !(p - 2 >= pattern && p[-2] == '[') - && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^') - && *p != ']') - { - reg_errcode_t ret - = compile_range (&p, pend, translate, syntax, b); - if (ret != REG_NOERROR) return ret; - } - - else if (p[0] == '-' && p[1] != ']') - { /* This handles ranges made up of characters only. */ - reg_errcode_t ret; - - /* Move past the `-'. */ - PATFETCH (c1); - - ret = compile_range (&p, pend, translate, syntax, b); - if (ret != REG_NOERROR) return ret; - } - - /* See if we're at the beginning of a possible character - class. */ - - else if (syntax & RE_CHAR_CLASSES && c == '[' && *p == ':') - { /* Leave room for the null. */ - char str[CHAR_CLASS_MAX_LENGTH + 1]; - - PATFETCH (c); - c1 = 0; - - /* If pattern is `[[:'. */ - if (p == pend) return REG_EBRACK; - - for (;;) - { - PATFETCH (c); - if (c == ':' || c == ']' || p == pend - || c1 == CHAR_CLASS_MAX_LENGTH) - break; - str[c1++] = c; - } - str[c1] = '\0'; - - /* If isn't a word bracketed by `[:' and:`]': - undo the ending character, the letters, and leave - the leading `:' and `[' (but set bits for them). */ - if (c == ':' && *p == ']') - { - int ch; - boolean is_alnum = STREQ (str, "alnum"); - boolean is_alpha = STREQ (str, "alpha"); - boolean is_blank = STREQ (str, "blank"); - boolean is_cntrl = STREQ (str, "cntrl"); - boolean is_digit = STREQ (str, "digit"); - boolean is_graph = STREQ (str, "graph"); - boolean is_lower = STREQ (str, "lower"); - boolean is_print = STREQ (str, "print"); - boolean is_punct = STREQ (str, "punct"); - boolean is_space = STREQ (str, "space"); - boolean is_upper = STREQ (str, "upper"); - boolean is_xdigit = STREQ (str, "xdigit"); - - if (!IS_CHAR_CLASS (str)) return REG_ECTYPE; - - /* Throw away the ] at the end of the character - class. */ - PATFETCH (c); - - if (p == pend) return REG_EBRACK; - - for (ch = 0; ch < 1 << BYTEWIDTH; ch++) - { - if ( (is_alnum && ISALNUM (ch)) - || (is_alpha && ISALPHA (ch)) - || (is_blank && ISBLANK (ch)) - || (is_cntrl && ISCNTRL (ch)) - || (is_digit && ISDIGIT (ch)) - || (is_graph && ISGRAPH (ch)) - || (is_lower && ISLOWER (ch)) - || (is_print && ISPRINT (ch)) - || (is_punct && ISPUNCT (ch)) - || (is_space && ISSPACE (ch)) - || (is_upper && ISUPPER (ch)) - || (is_xdigit && ISXDIGIT (ch))) - SET_LIST_BIT (ch); - } - had_char_class = true; - } - else - { - c1++; - while (c1--) - PATUNFETCH; - SET_LIST_BIT ('['); - SET_LIST_BIT (':'); - had_char_class = false; - } - } - else - { - had_char_class = false; - SET_LIST_BIT (c); - } - } - - /* Discard any (non)matching list bytes that are all 0 at the - end of the map. Decrease the map-length byte too. */ - while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) - b[-1]--; - b += b[-1]; - } - break; - - - case '(': - if (syntax & RE_NO_BK_PARENS) - goto handle_open; - else - goto normal_char; - - - case ')': - if (syntax & RE_NO_BK_PARENS) - goto handle_close; - else - goto normal_char; - - - case '\n': - if (syntax & RE_NEWLINE_ALT) - goto handle_alt; - else - goto normal_char; - - - case '|': - if (syntax & RE_NO_BK_VBAR) - goto handle_alt; - else - goto normal_char; - - - case '{': - if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES) - goto handle_interval; - else - goto normal_char; - - - case '\\': - if (p == pend) return REG_EESCAPE; - - /* Do not translate the character after the \, so that we can - distinguish, e.g., \B from \b, even if we normally would - translate, e.g., B to b. */ - PATFETCH_RAW (c); - - switch (c) - { - case '(': - if (syntax & RE_NO_BK_PARENS) - goto normal_backslash; - - handle_open: - bufp->re_nsub++; - regnum++; - - if (COMPILE_STACK_FULL) - { - RETALLOC (compile_stack.stack, compile_stack.size << 1, - compile_stack_elt_t); - if (compile_stack.stack == NULL) return REG_ESPACE; - - compile_stack.size <<= 1; - } - - /* These are the values to restore when we hit end of this - group. They are all relative offsets, so that if the - whole pattern moves because of realloc, they will still - be valid. */ - COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer; - COMPILE_STACK_TOP.fixup_alt_jump - = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0; - COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer; - COMPILE_STACK_TOP.regnum = regnum; - - /* We will eventually replace the 0 with the number of - groups inner to this one. But do not push a - start_memory for groups beyond the last one we can - represent in the compiled pattern. */ - if (regnum <= MAX_REGNUM) - { - COMPILE_STACK_TOP.inner_group_offset = b - bufp->buffer + 2; - BUF_PUSH_3 (start_memory, regnum, 0); - } - - compile_stack.avail++; - - fixup_alt_jump = 0; - laststart = 0; - begalt = b; - /* If we've reached MAX_REGNUM groups, then this open - won't actually generate any code, so we'll have to - clear pending_exact explicitly. */ - pending_exact = 0; - break; - - - case ')': - if (syntax & RE_NO_BK_PARENS) goto normal_backslash; - - if (COMPILE_STACK_EMPTY) - if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) - goto normal_backslash; - else - return REG_ERPAREN; - - handle_close: - if (fixup_alt_jump) - { /* Push a dummy failure point at the end of the - alternative for a possible future - `pop_failure_jump' to pop. See comments at - `push_dummy_failure' in `re_match_2'. */ - BUF_PUSH (push_dummy_failure); - - /* We allocated space for this jump when we assigned - to `fixup_alt_jump', in the `handle_alt' case below. */ - STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1); - } - - /* See similar code for backslashed left paren above. */ - if (COMPILE_STACK_EMPTY) - if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) - goto normal_char; - else - return REG_ERPAREN; - - /* Since we just checked for an empty stack above, this - ``can't happen''. */ - assert (compile_stack.avail != 0); - { - /* We don't just want to restore into `regnum', because - later groups should continue to be numbered higher, - as in `(ab)c(de)' -- the second group is #2. */ - regnum_t this_group_regnum; - - compile_stack.avail--; - begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset; - fixup_alt_jump - = COMPILE_STACK_TOP.fixup_alt_jump - ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 - : 0; - laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; - this_group_regnum = COMPILE_STACK_TOP.regnum; - /* If we've reached MAX_REGNUM groups, then this open - won't actually generate any code, so we'll have to - clear pending_exact explicitly. */ - pending_exact = 0; - - /* We're at the end of the group, so now we know how many - groups were inside this one. */ - if (this_group_regnum <= MAX_REGNUM) - { - unsigned char *inner_group_loc - = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset; - - *inner_group_loc = regnum - this_group_regnum; - BUF_PUSH_3 (stop_memory, this_group_regnum, - regnum - this_group_regnum); - } - } - break; - - - case '|': /* `\|'. */ - if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR) - goto normal_backslash; - handle_alt: - if (syntax & RE_LIMITED_OPS) - goto normal_char; - - /* Insert before the previous alternative a jump which - jumps to this alternative if the former fails. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (on_failure_jump, begalt, b + 6); - pending_exact = 0; - b += 3; - - /* The alternative before this one has a jump after it - which gets executed if it gets matched. Adjust that - jump so it will jump to this alternative's analogous - jump (put in below, which in turn will jump to the next - (if any) alternative's such jump, etc.). The last such - jump jumps to the correct final destination. A picture: - _____ _____ - | | | | - | v | v - a | b | c - - If we are at `b', then fixup_alt_jump right now points to a - three-byte space after `a'. We'll put in the jump, set - fixup_alt_jump to right after `b', and leave behind three - bytes which we'll fill in when we get to after `c'. */ - - if (fixup_alt_jump) - STORE_JUMP (jump_past_alt, fixup_alt_jump, b); - - /* Mark and leave space for a jump after this alternative, - to be filled in later either by next alternative or - when know we're at the end of a series of alternatives. */ - fixup_alt_jump = b; - GET_BUFFER_SPACE (3); - b += 3; - - laststart = 0; - begalt = b; - break; - - - case '{': - /* If \{ is a literal. */ - if (!(syntax & RE_INTERVALS) - /* If we're at `\{' and it's not the open-interval - operator. */ - || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) - || (p - 2 == pattern && p == pend)) - goto normal_backslash; - - handle_interval: - { - /* If got here, then the syntax allows intervals. */ - - /* At least (most) this many matches must be made. */ - int lower_bound = -1, upper_bound = -1; - - beg_interval = p - 1; - - if (p == pend) - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_EBRACE; - } - - GET_UNSIGNED_NUMBER (lower_bound); - - if (c == ',') - { - GET_UNSIGNED_NUMBER (upper_bound); - if (upper_bound < 0) upper_bound = RE_DUP_MAX; - } - else - /* Interval such as `{1}' => match exactly once. */ - upper_bound = lower_bound; - - if (lower_bound < 0 || upper_bound > RE_DUP_MAX - || lower_bound > upper_bound) - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_BADBR; - } - - if (!(syntax & RE_NO_BK_BRACES)) - { - if (c != '\\') return REG_EBRACE; - - PATFETCH (c); - } - - if (c != '}') - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_BADBR; - } - - /* We just parsed a valid interval. */ - - /* If it's invalid to have no preceding re. */ - if (!laststart) - { - if (syntax & RE_CONTEXT_INVALID_OPS) - return REG_BADRPT; - else if (syntax & RE_CONTEXT_INDEP_OPS) - laststart = b; - else - goto unfetch_interval; - } - - /* If the upper bound is zero, don't want to succeed at - all; jump from `laststart' to `b + 3', which will be - the end of the buffer after we insert the jump. */ - if (upper_bound == 0) - { - GET_BUFFER_SPACE (3); - INSERT_JUMP (jump, laststart, b + 3); - b += 3; - } - - /* Otherwise, we have a nontrivial interval. When - we're all done, the pattern will look like: - set_number_at - set_number_at - succeed_n - - jump_n - (The upper bound and `jump_n' are omitted if - `upper_bound' is 1, though.) */ - else - { /* If the upper bound is > 1, we need to insert - more at the end of the loop. */ - unsigned nbytes = 10 + (upper_bound > 1) * 10; - - GET_BUFFER_SPACE (nbytes); - - /* Initialize lower bound of the `succeed_n', even - though it will be set during matching by its - attendant `set_number_at' (inserted next), - because `re_compile_fastmap' needs to know. - Jump to the `jump_n' we might insert below. */ - INSERT_JUMP2 (succeed_n, laststart, - b + 5 + (upper_bound > 1) * 5, - lower_bound); - b += 5; - - /* Code to initialize the lower bound. Insert - before the `succeed_n'. The `5' is the last two - bytes of this `set_number_at', plus 3 bytes of - the following `succeed_n'. */ - insert_op2 (set_number_at, laststart, 5, lower_bound, b); - b += 5; - - if (upper_bound > 1) - { /* More than one repetition is allowed, so - append a backward jump to the `succeed_n' - that starts this interval. - - When we've reached this during matching, - we'll have matched the interval once, so - jump back only `upper_bound - 1' times. */ - STORE_JUMP2 (jump_n, b, laststart + 5, - upper_bound - 1); - b += 5; - - /* The location we want to set is the second - parameter of the `jump_n'; that is `b-2' as - an absolute address. `laststart' will be - the `set_number_at' we're about to insert; - `laststart+3' the number to set, the source - for the relative address. But we are - inserting into the middle of the pattern -- - so everything is getting moved up by 5. - Conclusion: (b - 2) - (laststart + 3) + 5, - i.e., b - laststart. - - We insert this at the beginning of the loop - so that if we fail during matching, we'll - reinitialize the bounds. */ - insert_op2 (set_number_at, laststart, b - laststart, - upper_bound - 1, b); - b += 5; - } - } - pending_exact = 0; - beg_interval = NULL; - } - break; - - unfetch_interval: - /* If an invalid interval, match the characters as literals. */ - assert (beg_interval); - p = beg_interval; - beg_interval = NULL; - - /* normal_char and normal_backslash need `c'. */ - PATFETCH (c); - - if (!(syntax & RE_NO_BK_BRACES)) - { - if (p > pattern && p[-1] == '\\') - goto normal_backslash; - } - goto normal_char; - -#ifdef emacs - /* There is no way to specify the before_dot and after_dot - operators. rms says this is ok. --karl */ - case '=': - BUF_PUSH (at_dot); - break; - - case 's': - laststart = b; - PATFETCH (c); - BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]); - break; - - case 'S': - laststart = b; - PATFETCH (c); - BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]); - break; -#endif /* emacs */ - - - case 'w': - if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; - laststart = b; - BUF_PUSH (wordchar); - break; - - - case 'W': - if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; - laststart = b; - BUF_PUSH (notwordchar); - break; - - - case '<': - if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; - BUF_PUSH (wordbeg); - break; - - case '>': - if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; - BUF_PUSH (wordend); - break; - - case 'b': - if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; - BUF_PUSH (wordbound); - break; - - case 'B': - if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; - BUF_PUSH (notwordbound); - break; - - case '`': - if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; - BUF_PUSH (begbuf); - break; - - case '\'': - if (re_syntax_options & RE_NO_GNU_OPS) - goto normal_char; - BUF_PUSH (endbuf); - break; - - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - if (syntax & RE_NO_BK_REFS) - goto normal_char; - - c1 = c - '0'; - - if (c1 > regnum) - return REG_ESUBREG; - - /* Can't back reference to a subexpression if inside of it. */ - if (group_in_compile_stack (compile_stack, (regnum_t)c1)) - goto normal_char; - - laststart = b; - BUF_PUSH_2 (duplicate, c1); - break; - - - case '+': - case '?': - if (syntax & RE_BK_PLUS_QM) - goto handle_plus; - else - goto normal_backslash; - - default: - normal_backslash: - /* You might think it would be useful for \ to mean - not to translate; but if we don't translate it - it will never match anything. */ - c = TRANSLATE (c); - goto normal_char; - } - break; - - - default: - /* Expects the character in `c'. */ - normal_char: - /* If no exactn currently being built. */ - if (!pending_exact - - /* If last exactn not at current position. */ - || pending_exact + *pending_exact + 1 != b - - /* We have only one byte following the exactn for the count. */ - || *pending_exact == (1 << BYTEWIDTH) - 1 - - /* If followed by a repetition operator. */ - || *p == '*' || *p == '^' - || ((syntax & RE_BK_PLUS_QM) - ? *p == '\\' && (p[1] == '+' || p[1] == '?') - : (*p == '+' || *p == '?')) - || ((syntax & RE_INTERVALS) - && ((syntax & RE_NO_BK_BRACES) - ? *p == '{' - : (p[0] == '\\' && p[1] == '{')))) - { - /* Start building a new exactn. */ - - laststart = b; - - BUF_PUSH_2 (exactn, 0); - pending_exact = b - 1; - } - - BUF_PUSH (c); - (*pending_exact)++; - break; - } /* switch (c) */ - } /* while p != pend */ - - - /* Through the pattern now. */ - - if (fixup_alt_jump) - STORE_JUMP (jump_past_alt, fixup_alt_jump, b); - - if (!COMPILE_STACK_EMPTY) - return REG_EPAREN; - - free (compile_stack.stack); - - /* We have succeeded; set the length of the buffer. */ - bufp->used = b - bufp->buffer; - -#ifdef DEBUG - if (debug) - { - DEBUG_PRINT1 ("\nCompiled pattern: \n"); - print_compiled_pattern (bufp); - } -#endif /* DEBUG */ - - return REG_NOERROR; -} /* regex_compile */ - -/* Subroutines for `regex_compile'. */ - -/* Store OP at LOC followed by two-byte integer parameter ARG. */ - -static void -store_op1 (op, loc, arg) - re_opcode_t op; - unsigned char *loc; - int arg; -{ - *loc = (unsigned char) op; - STORE_NUMBER (loc + 1, arg); -} - - -/* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */ - -static void -store_op2 (op, loc, arg1, arg2) - re_opcode_t op; - unsigned char *loc; - int arg1, arg2; -{ - *loc = (unsigned char) op; - STORE_NUMBER (loc + 1, arg1); - STORE_NUMBER (loc + 3, arg2); -} - - -/* Copy the bytes from LOC to END to open up three bytes of space at LOC - for OP followed by two-byte integer parameter ARG. */ - -static void -insert_op1 (op, loc, arg, end) - re_opcode_t op; - unsigned char *loc; - int arg; - unsigned char *end; -{ - register unsigned char *pfrom = end; - register unsigned char *pto = end + 3; - - while (pfrom != loc) - *--pto = *--pfrom; - - store_op1 (op, loc, arg); -} - - -/* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */ - -static void -insert_op2 (op, loc, arg1, arg2, end) - re_opcode_t op; - unsigned char *loc; - int arg1, arg2; - unsigned char *end; -{ - register unsigned char *pfrom = end; - register unsigned char *pto = end + 5; - - while (pfrom != loc) - *--pto = *--pfrom; - - store_op2 (op, loc, arg1, arg2); -} - - -/* P points to just after a ^ in PATTERN. Return true if that ^ comes - after an alternative or a begin-subexpression. We assume there is at - least one character before the ^. */ - -static boolean -at_begline_loc_p (pattern, p, syntax) - const char *pattern, *p; - reg_syntax_t syntax; -{ - const char *prev = p - 2; - boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; - - return - /* After a subexpression? */ - (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) - /* After an alternative? */ - || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash)); -} - - -/* The dual of at_begline_loc_p. This one is for $. We assume there is - at least one character after the $, i.e., `P < PEND'. */ - -static boolean -at_endline_loc_p (p, pend, syntax) - const char *p, *pend; - reg_syntax_t syntax; -{ - const char *next = p; - boolean next_backslash = *next == '\\'; - const char *next_next = p + 1 < pend ? p + 1 : NULL; - - return - /* Before a subexpression? */ - (syntax & RE_NO_BK_PARENS ? *next == ')' - : next_backslash && next_next && *next_next == ')') - /* Before an alternative? */ - || (syntax & RE_NO_BK_VBAR ? *next == '|' - : next_backslash && next_next && *next_next == '|'); -} - - -/* Returns true if REGNUM is in one of COMPILE_STACK's elements and - false if it's not. */ - -static boolean -group_in_compile_stack (compile_stack, regnum) - compile_stack_type compile_stack; - regnum_t regnum; -{ - int this_element; - - for (this_element = compile_stack.avail - 1; - this_element >= 0; - this_element--) - if (compile_stack.stack[this_element].regnum == regnum) - return true; - - return false; -} - - -/* Read the ending character of a range (in a bracket expression) from the - uncompiled pattern *P_PTR (which ends at PEND). We assume the - starting character is in `P[-2]'. (`P[-1]' is the character `-'.) - Then we set the translation of all bits between the starting and - ending characters (inclusive) in the compiled pattern B. - - Return an error code. - - We use these short variable names so we can use the same macros as - `regex_compile' itself. */ - -static reg_errcode_t -compile_range (p_ptr, pend, translate, syntax, b) - const char **p_ptr, *pend; - char *translate; - reg_syntax_t syntax; - unsigned char *b; -{ - unsigned this_char; - - const char *p = *p_ptr; - int range_start, range_end; - - if (p == pend) - return REG_ERANGE; - - /* Even though the pattern is a signed `char *', we need to fetch - with unsigned char *'s; if the high bit of the pattern character - is set, the range endpoints will be negative if we fetch using a - signed char *. - - We also want to fetch the endpoints without translating them; the - appropriate translation is done in the bit-setting loop below. */ - range_start = ((unsigned char *) p)[-2]; - range_end = ((unsigned char *) p)[0]; - - /* Have to increment the pointer into the pattern string, so the - caller isn't still at the ending character. */ - (*p_ptr)++; - - /* If the start is after the end, the range is empty. */ - if (range_start > range_end) - return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR; - - /* Here we see why `this_char' has to be larger than an `unsigned - char' -- the range is inclusive, so if `range_end' == 0xff - (assuming 8-bit characters), we would otherwise go into an infinite - loop, since all characters <= 0xff. */ - for (this_char = range_start; this_char <= range_end; this_char++) - { - SET_LIST_BIT (TRANSLATE (this_char)); - } - - return REG_NOERROR; -} - -/* Failure stack declarations and macros; both re_compile_fastmap and - re_match_2 use a failure stack. These have to be macros because of - REGEX_ALLOCATE. */ - - -/* Number of failure points for which to initially allocate space - when matching. If this number is exceeded, we allocate more - space, so it is not a hard limit. */ -#ifndef INIT_FAILURE_ALLOC -#define INIT_FAILURE_ALLOC 5 -#endif - -/* Roughly the maximum number of failure points on the stack. Would be - exactly that if always used MAX_FAILURE_SPACE each time we failed. - This is a variable only so users of regex can assign to it; we never - change it ourselves. */ -int re_max_failures = 2000; - -typedef const unsigned char *fail_stack_elt_t; - -typedef struct -{ - fail_stack_elt_t *stack; - unsigned size; - unsigned avail; /* Offset of next open position. */ -} fail_stack_type; - -#define FAIL_STACK_EMPTY() (fail_stack.avail == 0) -#define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0) -#define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size) -#define FAIL_STACK_TOP() (fail_stack.stack[fail_stack.avail]) - - -/* Initialize `fail_stack'. Do `return -2' if the alloc fails. */ - -#define INIT_FAIL_STACK() \ - do { \ - fail_stack.stack = (fail_stack_elt_t *) \ - REGEX_ALLOCATE (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \ - \ - if (fail_stack.stack == NULL) \ - return -2; \ - \ - fail_stack.size = INIT_FAILURE_ALLOC; \ - fail_stack.avail = 0; \ - } while (0) - - -/* Double the size of FAIL_STACK, up to approximately `re_max_failures' items. - - Return 1 if succeeds, and 0 if either ran out of memory - allocating space for it or it was already too large. - - REGEX_REALLOCATE requires `destination' be declared. */ - -#define DOUBLE_FAIL_STACK(fail_stack) \ - ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \ - ? 0 \ - : ((fail_stack).stack = (fail_stack_elt_t *) \ - REGEX_REALLOCATE ((fail_stack).stack, \ - (fail_stack).size * sizeof (fail_stack_elt_t), \ - ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \ - \ - (fail_stack).stack == NULL \ - ? 0 \ - : ((fail_stack).size <<= 1, \ - 1))) - - -/* Push PATTERN_OP on FAIL_STACK. - - Return 1 if was able to do so and 0 if ran out of memory allocating - space to do so. */ -#define PUSH_PATTERN_OP(pattern_op, fail_stack) \ - ((FAIL_STACK_FULL () \ - && !DOUBLE_FAIL_STACK (fail_stack)) \ - ? 0 \ - : ((fail_stack).stack[(fail_stack).avail++] = pattern_op, \ - 1)) - -/* This pushes an item onto the failure stack. Must be a four-byte - value. Assumes the variable `fail_stack'. Probably should only - be called from within `PUSH_FAILURE_POINT'. */ -#define PUSH_FAILURE_ITEM(item) \ - fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) item - -/* The complement operation. Assumes `fail_stack' is nonempty. */ -#define POP_FAILURE_ITEM() fail_stack.stack[--fail_stack.avail] - -/* Used to omit pushing failure point id's when we're not debugging. */ -#ifdef DEBUG -#define DEBUG_PUSH PUSH_FAILURE_ITEM -#define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_ITEM () -#else -#define DEBUG_PUSH(item) -#define DEBUG_POP(item_addr) -#endif - - -/* Push the information about the state we will need - if we ever fail back to it. - - Requires variables fail_stack, regstart, regend, reg_info, and - num_regs be declared. DOUBLE_FAIL_STACK requires `destination' be - declared. - - Does `return FAILURE_CODE' if runs out of memory. */ - -#define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \ - do { \ - char *destination; \ - /* Must be int, so when we don't save any registers, the arithmetic \ - of 0 + -1 isn't done as unsigned. */ \ - /* Can't be int, since there is not a shred of a guarantee that int \ - is wide enough to hold a value of something to which pointer can \ - be assigned */ \ - s_reg_t this_reg; \ - \ - DEBUG_STATEMENT (failure_id++); \ - DEBUG_STATEMENT (nfailure_points_pushed++); \ - DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \ - DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\ - DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\ - \ - DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \ - DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \ - \ - /* Ensure we have enough space allocated for what we will push. */ \ - while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \ - { \ - if (!DOUBLE_FAIL_STACK (fail_stack)) \ - return failure_code; \ - \ - DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \ - (fail_stack).size); \ - DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\ - } - -#define PUSH_FAILURE_POINT2(pattern_place, string_place, failure_code) \ - /* Push the info, starting with the registers. */ \ - DEBUG_PRINT1 ("\n"); \ - \ - PUSH_FAILURE_POINT_LOOP (); \ - \ - DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\ - PUSH_FAILURE_ITEM (lowest_active_reg); \ - \ - DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\ - PUSH_FAILURE_ITEM (highest_active_reg); \ - \ - DEBUG_PRINT2 (" Pushing pattern 0x%x: ", pattern_place); \ - DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \ - PUSH_FAILURE_ITEM (pattern_place); \ - \ - DEBUG_PRINT2 (" Pushing string 0x%x: `", string_place); \ - DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \ - size2); \ - DEBUG_PRINT1 ("'\n"); \ - PUSH_FAILURE_ITEM (string_place); \ - \ - DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \ - DEBUG_PUSH (failure_id); \ - } while (0) - -/* Pulled out of PUSH_FAILURE_POINT() to shorten the definition - of that macro. (for VAX C) */ -#define PUSH_FAILURE_POINT_LOOP() \ - for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \ - this_reg++) \ - { \ - DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \ - DEBUG_STATEMENT (num_regs_pushed++); \ - \ - DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \ - PUSH_FAILURE_ITEM (regstart[this_reg]); \ - \ - DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ - PUSH_FAILURE_ITEM (regend[this_reg]); \ - \ - DEBUG_PRINT2 (" info: 0x%x\n ", reg_info[this_reg]); \ - DEBUG_PRINT2 (" match_null=%d", \ - REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \ - DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \ - DEBUG_PRINT2 (" matched_something=%d", \ - MATCHED_SOMETHING (reg_info[this_reg])); \ - DEBUG_PRINT2 (" ever_matched=%d", \ - EVER_MATCHED_SOMETHING (reg_info[this_reg])); \ - DEBUG_PRINT1 ("\n"); \ - PUSH_FAILURE_ITEM (reg_info[this_reg].word); \ - } - -/* This is the number of items that are pushed and popped on the stack - for each register. */ -#define NUM_REG_ITEMS 3 - -/* Individual items aside from the registers. */ -#ifdef DEBUG -#define NUM_NONREG_ITEMS 5 /* Includes failure point id. */ -#else -#define NUM_NONREG_ITEMS 4 -#endif - -/* We push at most this many items on the stack. */ -#define MAX_FAILURE_ITEMS ((num_regs - 1) * NUM_REG_ITEMS + NUM_NONREG_ITEMS) - -/* We actually push this many items. */ -#define NUM_FAILURE_ITEMS \ - ((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS \ - + NUM_NONREG_ITEMS) - -/* How many items can still be added to the stack without overflowing it. */ -#define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail) - - -/* Pops what PUSH_FAIL_STACK pushes. - - We restore into the parameters, all of which should be lvalues: - STR -- the saved data position. - PAT -- the saved pattern position. - LOW_REG, HIGH_REG -- the highest and lowest active registers. - REGSTART, REGEND -- arrays of string positions. - REG_INFO -- array of information about each subexpression. - - Also assumes the variables `fail_stack' and (if debugging), `bufp', - `pend', `string1', `size1', `string2', and `size2'. */ - -#define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\ -{ \ - DEBUG_STATEMENT (fail_stack_elt_t failure_id;) \ - s_reg_t this_reg; \ - const unsigned char *string_temp; \ - \ - assert (!FAIL_STACK_EMPTY ()); \ - \ - /* Remove failure points and point to how many regs pushed. */ \ - DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \ - DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \ - DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \ - \ - assert (fail_stack.avail >= NUM_NONREG_ITEMS); \ - \ - DEBUG_POP (&failure_id); \ - DEBUG_PRINT2 (" Popping failure id: %u\n", failure_id); \ - \ - /* If the saved string location is NULL, it came from an \ - on_failure_keep_string_jump opcode, and we want to throw away the \ - saved NULL, thus retaining our current position in the string. */ \ - string_temp = POP_FAILURE_ITEM (); \ - if (string_temp != NULL) \ - str = (const char *) string_temp; \ - \ - DEBUG_PRINT2 (" Popping string 0x%x: `", str); \ - DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ - DEBUG_PRINT1 ("'\n"); \ - \ - pat = (unsigned char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping pattern 0x%x: ", pat); \ - DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ - \ - POP_FAILURE_POINT2 (low_reg, high_reg, regstart, regend, reg_info); - -/* Pulled out of POP_FAILURE_POINT() to shorten the definition - of that macro. (for MSC 5.1) */ -#define POP_FAILURE_POINT2(low_reg, high_reg, regstart, regend, reg_info) \ - \ - /* Restore register info. */ \ - high_reg = (active_reg_t) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \ - \ - low_reg = (active_reg_t) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping low active reg: %d\n", low_reg); \ - \ - for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \ - { \ - DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \ - \ - reg_info[this_reg].word = POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" info: 0x%x\n", reg_info[this_reg]); \ - \ - regend[this_reg] = (const char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ - \ - regstart[this_reg] = (const char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \ - } \ - \ - DEBUG_STATEMENT (nfailure_points_popped++); \ -} /* POP_FAILURE_POINT */ - - -/* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in - BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible - characters can start a string that matches the pattern. This fastmap - is used by re_search to skip quickly over impossible starting points. - - The caller must supply the address of a (1 << BYTEWIDTH)-byte data - area as BUFP->fastmap. - - We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in - the pattern buffer. - - Returns 0 if we succeed, -2 if an internal error. */ - -int -re_compile_fastmap (bufp) - struct re_pattern_buffer *bufp; -{ - int j, k; - fail_stack_type fail_stack; -#ifndef REGEX_MALLOC - char *destination; -#endif - /* We don't push any register information onto the failure stack. */ - unsigned num_regs = 0; - - register char *fastmap = bufp->fastmap; - unsigned char *pattern = bufp->buffer; - const unsigned char *p = pattern; - register unsigned char *pend = pattern + bufp->used; - - /* Assume that each path through the pattern can be null until - proven otherwise. We set this false at the bottom of switch - statement, to which we get only if a particular path doesn't - match the empty string. */ - boolean path_can_be_null = true; - - /* We aren't doing a `succeed_n' to begin with. */ - boolean succeed_n_p = false; - - assert (fastmap != NULL && p != NULL); - - INIT_FAIL_STACK (); - bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */ - bufp->fastmap_accurate = 1; /* It will be when we're done. */ - bufp->can_be_null = 0; - - while (p != pend || !FAIL_STACK_EMPTY ()) - { - if (p == pend) - { - bufp->can_be_null |= path_can_be_null; - - /* Reset for next path. */ - path_can_be_null = true; - - p = fail_stack.stack[--fail_stack.avail]; - } - - /* We should never be about to go beyond the end of the pattern. */ - assert (p < pend); - -#ifdef SWITCH_ENUM_BUG - switch ((int) ((re_opcode_t) *p++)) -#else - switch ((re_opcode_t) *p++) -#endif - { - - /* I guess the idea here is to simply not bother with a fastmap - if a backreference is used, since it's too hard to figure out - the fastmap for the corresponding group. Setting - `can_be_null' stops `re_search_2' from using the fastmap, so - that is all we do. */ - case duplicate: - bufp->can_be_null = 1; - return 0; - - - /* Following are the cases which match a character. These end - with `break'. */ - - case exactn: - fastmap[p[1]] = 1; - break; - - - case charset: - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) - fastmap[j] = 1; - break; - - - case charset_not: - /* Chars beyond end of map must be allowed. */ - for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) - fastmap[j] = 1; - - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) - fastmap[j] = 1; - break; - - - case wordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == Sword) - fastmap[j] = 1; - break; - - - case notwordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != Sword) - fastmap[j] = 1; - break; - - - case anychar: - /* `.' matches anything ... */ - for (j = 0; j < (1 << BYTEWIDTH); j++) - fastmap[j] = 1; - - /* ... except perhaps newline. */ - if (!(bufp->syntax & RE_DOT_NEWLINE)) - fastmap['\n'] = 0; - - /* Return if we have already set `can_be_null'; if we have, - then the fastmap is irrelevant. Something's wrong here. */ - else if (bufp->can_be_null) - return 0; - - /* Otherwise, have to check alternative paths. */ - break; - - -#ifdef emacs - case syntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == (enum syntaxcode) k) - fastmap[j] = 1; - break; - - - case notsyntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != (enum syntaxcode) k) - fastmap[j] = 1; - break; - - - /* All cases after this match the empty string. These end with - `continue'. */ - - - case before_dot: - case at_dot: - case after_dot: - continue; -#endif /* not emacs */ - - - case no_op: - case begline: - case endline: - case begbuf: - case endbuf: - case wordbound: - case notwordbound: - case wordbeg: - case wordend: - case push_dummy_failure: - continue; - - - case jump_n: - case pop_failure_jump: - case maybe_pop_jump: - case jump: - case jump_past_alt: - case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); - p += j; - if (j > 0) - continue; - - /* Jump backward implies we just went through the body of a - loop and matched nothing. Opcode jumped to should be - `on_failure_jump' or `succeed_n'. Just treat it like an - ordinary jump. For a * loop, it has pushed its failure - point already; if so, discard that as redundant. */ - if ((re_opcode_t) *p != on_failure_jump - && (re_opcode_t) *p != succeed_n) - continue; - - p++; - EXTRACT_NUMBER_AND_INCR (j, p); - p += j; - - /* If what's on the stack is where we are now, pop it. */ - if (!FAIL_STACK_EMPTY () - && fail_stack.stack[fail_stack.avail - 1] == p) - fail_stack.avail--; - - continue; - - - case on_failure_jump: - case on_failure_keep_string_jump: - handle_on_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); - - /* For some patterns, e.g., `(a?)?', `p+j' here points to the - end of the pattern. We don't want to push such a point, - since when we restore it above, entering the switch will - increment `p' past the end of the pattern. We don't need - to push such a point since we obviously won't find any more - fastmap entries beyond `pend'. Such a pattern can match - the null string, though. */ - if (p + j < pend) - { - if (!PUSH_PATTERN_OP (p + j, fail_stack)) - return -2; - } - else - bufp->can_be_null = 1; - - if (succeed_n_p) - { - EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */ - succeed_n_p = false; - } - - continue; - - - case succeed_n: - /* Get to the number of times to succeed. */ - p += 2; - - /* Increment p past the n for when k != 0. */ - EXTRACT_NUMBER_AND_INCR (k, p); - if (k == 0) - { - p -= 4; - succeed_n_p = true; /* Spaghetti code alert. */ - goto handle_on_failure_jump; - } - continue; - - - case set_number_at: - p += 4; - continue; - - - case start_memory: - case stop_memory: - p += 2; - continue; - - - default: - abort (); /* We have listed all the cases. */ - } /* switch *p++ */ - - /* Getting here means we have found the possible starting - characters for one path of the pattern -- and that the empty - string does not match. We need not follow this path further. - Instead, look at the next alternative (remembered on the - stack), or quit if no more. The test at the top of the loop - does these things. */ - path_can_be_null = false; - p = pend; - } /* while p */ - - /* Set `can_be_null' for the last path (also the first path, if the - pattern is empty). */ - bufp->can_be_null |= path_can_be_null; - return 0; -} /* re_compile_fastmap */ - -/* Set REGS to hold NUM_REGS registers, storing them in STARTS and - ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use - this memory for recording register information. STARTS and ENDS - must be allocated using the malloc library routine, and must each - be at least NUM_REGS * sizeof (regoff_t) bytes long. - - If NUM_REGS == 0, then subsequent matches should allocate their own - register data. - - Unless this function is called, the first search or match using - PATTERN_BUFFER will allocate its own register data, without - freeing the old data. */ - -void -re_set_registers (bufp, regs, num_regs, starts, ends) - struct re_pattern_buffer *bufp; - struct re_registers *regs; - unsigned num_regs; - regoff_t *starts, *ends; -{ - if (num_regs) - { - bufp->regs_allocated = REGS_REALLOCATE; - regs->num_regs = num_regs; - regs->start = starts; - regs->end = ends; - } - else - { - bufp->regs_allocated = REGS_UNALLOCATED; - regs->num_regs = 0; - regs->start = regs->end = 0; - } -} - -/* Searching routines. */ - -/* Like re_search_2, below, but only one string is specified, and - doesn't let you say where to stop matching. */ - -int -re_search (bufp, string, size, startpos, range, regs) - struct re_pattern_buffer *bufp; - const char *string; - int size, startpos, range; - struct re_registers *regs; -{ - return re_search_2 (bufp, NULL, 0, string, size, startpos, range, - regs, size); -} - - -/* Using the compiled pattern in BUFP->buffer, first tries to match the - virtual concatenation of STRING1 and STRING2, starting first at index - STARTPOS, then at STARTPOS + 1, and so on. - - STRING1 and STRING2 have length SIZE1 and SIZE2, respectively. - - RANGE is how far to scan while trying to match. RANGE = 0 means try - only at STARTPOS; in general, the last start tried is STARTPOS + - RANGE. - - In REGS, return the indices of the virtual concatenation of STRING1 - and STRING2 that matched the entire BUFP->buffer and its contained - subexpressions. - - Do not consider matching one past the index STOP in the virtual - concatenation of STRING1 and STRING2. - - We return either the position in the strings at which the match was - found, -1 if no match, or -2 if error (such as failure - stack overflow). */ - -int -re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int startpos; - int range; - struct re_registers *regs; - int stop; -{ - int val; - register char *fastmap = bufp->fastmap; - register char *translate = bufp->translate; - int total_size = size1 + size2; - int endpos = startpos + range; - - /* Check for out-of-range STARTPOS. */ - if (startpos < 0 || startpos > total_size) - return -1; - - /* Fix up RANGE if it might eventually take us outside - the virtual concatenation of STRING1 and STRING2. */ - if (endpos < -1) - range = -1 - startpos; - else if (endpos > total_size) - range = total_size - startpos; - - /* If the search isn't to be a backwards one, don't waste time in a - search for a pattern that must be anchored. */ - if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0) - { - if (startpos > 0) - return -1; - else - range = 1; - } - - /* Update the fastmap now if not correct already. */ - if (fastmap && !bufp->fastmap_accurate) - if (re_compile_fastmap (bufp) == -2) - return -2; - - /* Loop through the string, looking for a place to start matching. */ - for (;;) - { - /* If a fastmap is supplied, skip quickly over characters that - cannot be the start of a match. If the pattern can match the - null string, however, we don't need to skip characters; we want - the first null string. */ - if (fastmap && startpos < total_size && !bufp->can_be_null) - { - if (range > 0) /* Searching forwards. */ - { - register const char *d; - register int lim = 0; - int irange = range; - - if (startpos < size1 && startpos + range >= size1) - lim = range - (size1 - startpos); - - d = (startpos >= size1 ? string2 - size1 : string1) + startpos; - - /* Written out as an if-else to avoid testing `translate' - inside the loop. */ - if (translate) - while (range > lim - && !fastmap[(unsigned char) - translate[(unsigned char) *d++]]) - range--; - else - while (range > lim && !fastmap[(unsigned char) *d++]) - range--; - - startpos += irange - range; - } - else /* Searching backwards. */ - { - register char c = (size1 == 0 || startpos >= size1 - ? string2[startpos - size1] - : string1[startpos]); - - if (!fastmap[(unsigned char) TRANSLATE (c)]) - goto advance; - } - } - - /* If can't match the null string, and that's all we have left, fail. */ - if (range >= 0 && startpos == total_size && fastmap - && !bufp->can_be_null) - return -1; - - val = re_match_2 (bufp, string1, size1, string2, size2, - startpos, regs, stop); - if (val >= 0) - return startpos; - - if (val == -2) - return -2; - - advance: - if (!range) - break; - else if (range > 0) - { - range--; - startpos++; - } - else - { - range++; - startpos--; - } - } - return -1; -} /* re_search_2 */ - -/* Structure for per-register (a.k.a. per-group) information. - This must not be longer than one word, because we push this value - onto the failure stack. Other register information, such as the - starting and ending positions (which are addresses), and the list of - inner groups (which is a bits list) are maintained in separate - variables. - - We are making a (strictly speaking) nonportable assumption here: that - the compiler will pack our bit fields into something that fits into - the type of `word', i.e., is something that fits into one item on the - failure stack. */ - -/* Declarations and macros for re_match_2. */ - -typedef union -{ - fail_stack_elt_t word; - struct - { - /* This field is one if this group can match the empty string, - zero if not. If not yet determined, `MATCH_NULL_UNSET_VALUE'. */ -#define MATCH_NULL_UNSET_VALUE 3 - unsigned match_null_string_p : 2; - unsigned is_active : 1; - unsigned matched_something : 1; - unsigned ever_matched_something : 1; - } bits; -} register_info_type; - -#define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p) -#define IS_ACTIVE(R) ((R).bits.is_active) -#define MATCHED_SOMETHING(R) ((R).bits.matched_something) -#define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something) - -static boolean group_match_null_string_p _RE_ARGS((unsigned char **p, - unsigned char *end, - register_info_type *reg_info)); -static boolean alt_match_null_string_p _RE_ARGS((unsigned char *p, - unsigned char *end, - register_info_type *reg_info)); -static boolean common_op_match_null_string_p _RE_ARGS((unsigned char **p, - unsigned char *end, - register_info_type *reg_info)); -static int bcmp_translate _RE_ARGS((const char *s1, const char *s2, - int len, char *translate)); - -/* Call this when have matched a real character; it sets `matched' flags - for the subexpressions which we are currently inside. Also records - that those subexprs have matched. */ -#define SET_REGS_MATCHED() \ - do \ - { \ - active_reg_t r; \ - for (r = lowest_active_reg; r <= highest_active_reg; r++) \ - { \ - MATCHED_SOMETHING (reg_info[r]) \ - = EVER_MATCHED_SOMETHING (reg_info[r]) \ - = 1; \ - } \ - } \ - while (0) - - -/* This converts PTR, a pointer into one of the search strings `string1' - and `string2' into an offset from the beginning of that string. */ -#define POINTER_TO_OFFSET(ptr) \ - (FIRST_STRING_P (ptr) ? (ptr) - string1 : (ptr) - string2 + size1) - -/* Registers are set to a sentinel when they haven't yet matched. */ -#define REG_UNSET_VALUE ((char *) -1) -#define REG_UNSET(e) ((e) == REG_UNSET_VALUE) - - -/* Macros for dealing with the split strings in re_match_2. */ - -#define MATCHING_IN_FIRST_STRING (dend == end_match_1) - -/* Call before fetching a character with *d. This switches over to - string2 if necessary. */ -#define PREFETCH() \ - while (d == dend) \ - { \ - /* End of string2 => fail. */ \ - if (dend == end_match_2) \ - goto fail; \ - /* End of string1 => advance to string2. */ \ - d = string2; \ - dend = end_match_2; \ - } - - -/* Test if at very beginning or at very end of the virtual concatenation - of `string1' and `string2'. If only one string, it's `string2'. */ -#define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2) -#define AT_STRINGS_END(d) ((d) == end2) - - -/* Test if D points to a character which is word-constituent. We have - two special cases to check for: if past the end of string1, look at - the first character in string2; and if before the beginning of - string2, look at the last character in string1. */ -#define WORDCHAR_P(d) \ - (SYNTAX ((d) == end1 ? *string2 \ - : (d) == string2 - 1 ? *(end1 - 1) : *(d)) \ - == Sword) - -/* Test if the character before D and the one at D differ with respect - to being word-constituent. */ -#define AT_WORD_BOUNDARY(d) \ - (AT_STRINGS_BEG (d) || AT_STRINGS_END (d) \ - || WORDCHAR_P (d - 1) != WORDCHAR_P (d)) - - -/* Free everything we malloc. */ -#ifdef REGEX_MALLOC -#define FREE_VAR(var) if (var) free (var); var = NULL -#define FREE_VARIABLES() \ - do { \ - FREE_VAR (fail_stack.stack); \ - FREE_VAR (regstart); \ - FREE_VAR (regend); \ - FREE_VAR (old_regstart); \ - FREE_VAR (old_regend); \ - FREE_VAR (best_regstart); \ - FREE_VAR (best_regend); \ - FREE_VAR (reg_info); \ - FREE_VAR (reg_dummy); \ - FREE_VAR (reg_info_dummy); \ - } while (0) -#else /* not REGEX_MALLOC */ -/* Some MIPS systems (at least) want this to free alloca'd storage. */ -#define FREE_VARIABLES() alloca (0) -#endif /* not REGEX_MALLOC */ - - -/* These values must meet several constraints. They must not be valid - register values; since we have a limit of 255 registers (because - we use only one byte in the pattern for the register number), we can - use numbers larger than 255. They must differ by 1, because of - NUM_FAILURE_ITEMS above. And the value for the lowest register must - be larger than the value for the highest register, so we do not try - to actually save any registers when none are active. */ -#define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH) -#define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1) - -/* Matching routines. */ - -#ifndef emacs /* Emacs never uses this. */ -/* re_match is like re_match_2 except it takes only a single string. */ - -int -re_match (bufp, string, size, pos, regs) - struct re_pattern_buffer *bufp; - const char *string; - int size, pos; - struct re_registers *regs; - { - return re_match_2 (bufp, NULL, 0, string, size, pos, regs, size); -} -#endif /* not emacs */ - - -/* re_match_2 matches the compiled pattern in BUFP against the - the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 - and SIZE2, respectively). We start matching at POS, and stop - matching at STOP. - - If REGS is non-null and the `no_sub' field of BUFP is nonzero, we - store offsets for the substring each group matched in REGS. See the - documentation for exactly how many groups we fill. - - We return -1 if no match, -2 if an internal error (such as the - failure stack overflowing). Otherwise, we return the length of the - matched substring. */ - -int -re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int pos; - struct re_registers *regs; - int stop; -{ - /* General temporaries. */ - int mcnt; - unsigned char *p1; - - /* Just past the end of the corresponding string. */ - const char *end1, *end2; - - /* Pointers into string1 and string2, just past the last characters in - each to consider matching. */ - const char *end_match_1, *end_match_2; - - /* Where we are in the data, and the end of the current string. */ - const char *d, *dend; - - /* Where we are in the pattern, and the end of the pattern. */ - unsigned char *p = bufp->buffer; - register unsigned char *pend = p + bufp->used; - - /* We use this to map every character in the string. */ - char *translate = bufp->translate; - - /* Failure point stack. Each place that can handle a failure further - down the line pushes a failure point on this stack. It consists of - restart, regend, and reg_info for all registers corresponding to - the subexpressions we're currently inside, plus the number of such - registers, and, finally, two char *'s. The first char * is where - to resume scanning the pattern; the second one is where to resume - scanning the strings. If the latter is zero, the failure point is - a ``dummy''; if a failure happens and the failure point is a dummy, - it gets discarded and the next next one is tried. */ - fail_stack_type fail_stack; -#ifdef DEBUG - static unsigned failure_id = 0; - unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; -#endif - - /* We fill all the registers internally, independent of what we - return, for use in backreferences. The number here includes - an element for register zero. */ - size_t num_regs = bufp->re_nsub + 1; - - /* The currently active registers. */ - active_reg_t lowest_active_reg = NO_LOWEST_ACTIVE_REG; - active_reg_t highest_active_reg = NO_HIGHEST_ACTIVE_REG; - - /* Information on the contents of registers. These are pointers into - the input strings; they record just what was matched (on this - attempt) by a subexpression part of the pattern, that is, the - regnum-th regstart pointer points to where in the pattern we began - matching and the regnum-th regend points to right after where we - stopped matching the regnum-th subexpression. (The zeroth register - keeps track of what the whole pattern matches.) */ - const char **regstart = 0, **regend = 0; - - /* If a group that's operated upon by a repetition operator fails to - match anything, then the register for its start will need to be - restored because it will have been set to wherever in the string we - are when we last see its open-group operator. Similarly for a - register's end. */ - const char **old_regstart = 0, **old_regend = 0; - - /* The is_active field of reg_info helps us keep track of which (possibly - nested) subexpressions we are currently in. The matched_something - field of reg_info[reg_num] helps us tell whether or not we have - matched any of the pattern so far this time through the reg_num-th - subexpression. These two fields get reset each time through any - loop their register is in. */ - register_info_type *reg_info = 0; - - /* The following record the register info as found in the above - variables when we find a match better than any we've seen before. - This happens as we backtrack through the failure points, which in - turn happens only if we have not yet matched the entire string. */ - unsigned best_regs_set = false; - const char **best_regstart = 0, **best_regend = 0; - - /* Logically, this is `best_regend[0]'. But we don't want to have to - allocate space for that if we're not allocating space for anything - else (see below). Also, we never need info about register 0 for - any of the other register vectors, and it seems rather a kludge to - treat `best_regend' differently than the rest. So we keep track of - the end of the best match so far in a separate variable. We - initialize this to NULL so that when we backtrack the first time - and need to test it, it's not garbage. */ - const char *match_end = NULL; - - /* Used when we pop values we don't care about. */ - const char **reg_dummy = 0; - register_info_type *reg_info_dummy = 0; - -#ifdef DEBUG - /* Counts the total number of registers pushed. */ - unsigned num_regs_pushed = 0; -#endif - - DEBUG_PRINT1 ("\n\nEntering re_match_2.\n"); - - INIT_FAIL_STACK (); - - /* Do not bother to initialize all the register variables if there are - no groups in the pattern, as it takes a fair amount of time. If - there are groups, we include space for register 0 (the whole - pattern), even though we never use it, since it simplifies the - array indexing. We should fix this. */ - if (bufp->re_nsub) - { - regstart = REGEX_TALLOC (num_regs, const char *); - regend = REGEX_TALLOC (num_regs, const char *); - old_regstart = REGEX_TALLOC (num_regs, const char *); - old_regend = REGEX_TALLOC (num_regs, const char *); - best_regstart = REGEX_TALLOC (num_regs, const char *); - best_regend = REGEX_TALLOC (num_regs, const char *); - reg_info = REGEX_TALLOC (num_regs, register_info_type); - reg_dummy = REGEX_TALLOC (num_regs, const char *); - reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type); - - if (!(regstart && regend && old_regstart && old_regend && reg_info - && best_regstart && best_regend && reg_dummy && reg_info_dummy)) - { - FREE_VARIABLES (); - return -2; - } - } -#ifdef REGEX_MALLOC - else - { - /* We must initialize all our variables to NULL, so that - `FREE_VARIABLES' doesn't try to free them. */ - regstart = regend = old_regstart = old_regend = best_regstart - = best_regend = reg_dummy = NULL; - reg_info = reg_info_dummy = (register_info_type *) NULL; - } -#endif /* REGEX_MALLOC */ - - /* The starting position is bogus. */ - if (pos < 0 || pos > size1 + size2) - { - FREE_VARIABLES (); - return -1; - } - - /* Initialize subexpression text positions to -1 to mark ones that no - start_memory/stop_memory has been seen for. Also initialize the - register information struct. */ - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - regstart[mcnt] = regend[mcnt] - = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE; - - REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE; - IS_ACTIVE (reg_info[mcnt]) = 0; - MATCHED_SOMETHING (reg_info[mcnt]) = 0; - EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0; - } - - /* We move `string1' into `string2' if the latter's empty -- but not if - `string1' is null. */ - if (size2 == 0 && string1 != NULL) - { - string2 = string1; - size2 = size1; - string1 = 0; - size1 = 0; - } - end1 = string1 + size1; - end2 = string2 + size2; - - /* Compute where to stop matching, within the two strings. */ - if (stop <= size1) - { - end_match_1 = string1 + stop; - end_match_2 = string2; - } - else - { - end_match_1 = end1; - end_match_2 = string2 + stop - size1; - } - - /* `p' scans through the pattern as `d' scans through the data. - `dend' is the end of the input string that `d' points within. `d' - is advanced into the following input string whenever necessary, but - this happens before fetching; therefore, at the beginning of the - loop, `d' can be pointing at the end of a string, but it cannot - equal `string2'. */ - if (size1 > 0 && pos <= size1) - { - d = string1 + pos; - dend = end_match_1; - } - else - { - d = string2 + pos - size1; - dend = end_match_2; - } - - DEBUG_PRINT1 ("The compiled pattern is: "); - DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); - DEBUG_PRINT1 ("The string to match is: `"); - DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); - DEBUG_PRINT1 ("'\n"); - - /* This loops over pattern commands. It exits by returning from the - function if the match is complete, or it drops through if the match - fails at this starting point in the input data. */ - for (;;) - { - DEBUG_PRINT2 ("\n0x%x: ", p); - - if (p == pend) - { /* End of pattern means we might have succeeded. */ - DEBUG_PRINT1 ("end of pattern ... "); - - /* If we haven't matched the entire string, and we want the - longest match, try backtracking. */ - if (d != end_match_2) - { - DEBUG_PRINT1 ("backtracking.\n"); - - if (!FAIL_STACK_EMPTY ()) - { /* More failure points to try. */ - boolean same_str_p = (FIRST_STRING_P (match_end) - == MATCHING_IN_FIRST_STRING); - - /* If exceeds best match so far, save it. */ - if (!best_regs_set - || (same_str_p && d > match_end) - || (!same_str_p && !MATCHING_IN_FIRST_STRING)) - { - best_regs_set = true; - match_end = d; - - DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); - - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - best_regstart[mcnt] = regstart[mcnt]; - best_regend[mcnt] = regend[mcnt]; - } - } - goto fail; - } - - /* If no failure points, don't restore garbage. */ - else if (best_regs_set) - { - restore_best_regs: - /* Restore best match. It may happen that `dend == - end_match_1' while the restored d is in string2. - For example, the pattern `x.*y.*z' against the - strings `x-' and `y-z-', if the two strings are - not consecutive in memory. */ - DEBUG_PRINT1 ("Restoring best registers.\n"); - - d = match_end; - dend = ((d >= string1 && d <= end1) - ? end_match_1 : end_match_2); - - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - regstart[mcnt] = best_regstart[mcnt]; - regend[mcnt] = best_regend[mcnt]; - } - } - } /* d != end_match_2 */ - - DEBUG_PRINT1 ("Accepting match.\n"); - - /* If caller wants register contents data back, do it. */ - if (regs && !bufp->no_sub) - { - /* Have the register data arrays been allocated? */ - if (bufp->regs_allocated == REGS_UNALLOCATED) - { /* No. So allocate them with malloc. We need one - extra element beyond `num_regs' for the `-1' marker - GNU code uses. */ - regs->num_regs = MAX (RE_NREGS, num_regs + 1); - regs->start = TALLOC (regs->num_regs, regoff_t); - regs->end = TALLOC (regs->num_regs, regoff_t); - if (regs->start == NULL || regs->end == NULL) - return -2; - bufp->regs_allocated = REGS_REALLOCATE; - } - else if (bufp->regs_allocated == REGS_REALLOCATE) - { /* Yes. If we need more elements than were already - allocated, reallocate them. If we need fewer, just - leave it alone. */ - if (regs->num_regs < num_regs + 1) - { - regs->num_regs = num_regs + 1; - RETALLOC (regs->start, regs->num_regs, regoff_t); - RETALLOC (regs->end, regs->num_regs, regoff_t); - if (regs->start == NULL || regs->end == NULL) - return -2; - } - } - else - { - /* These braces fend off a "empty body in an else-statement" - warning under GCC when assert expands to nothing. */ - assert (bufp->regs_allocated == REGS_FIXED); - } - - /* Convert the pointer data in `regstart' and `regend' to - indices. Register zero has to be set differently, - since we haven't kept track of any info for it. */ - if (regs->num_regs > 0) - { - regs->start[0] = pos; - regs->end[0] = (MATCHING_IN_FIRST_STRING ? d - string1 - : d - string2 + size1); - } - - /* Go through the first `min (num_regs, regs->num_regs)' - registers, since that is all we initialized. */ - for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++) - { - if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt])) - regs->start[mcnt] = regs->end[mcnt] = -1; - else - { - regs->start[mcnt] = POINTER_TO_OFFSET (regstart[mcnt]); - regs->end[mcnt] = POINTER_TO_OFFSET (regend[mcnt]); - } - } - - /* If the regs structure we return has more elements than - were in the pattern, set the extra elements to -1. If - we (re)allocated the registers, this is the case, - because we always allocate enough to have at least one - -1 at the end. */ - for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++) - regs->start[mcnt] = regs->end[mcnt] = -1; - } /* regs && !bufp->no_sub */ - - FREE_VARIABLES (); - DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", - nfailure_points_pushed, nfailure_points_popped, - nfailure_points_pushed - nfailure_points_popped); - DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); - - mcnt = d - pos - (MATCHING_IN_FIRST_STRING - ? string1 - : string2 - size1); - - DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); - - return mcnt; - } - - /* Otherwise match next pattern command. */ -#ifdef SWITCH_ENUM_BUG - switch ((int) ((re_opcode_t) *p++)) -#else - switch ((re_opcode_t) *p++) -#endif - { - /* Ignore these. Used to ignore the n of succeed_n's which - currently have n == 0. */ - case no_op: - DEBUG_PRINT1 ("EXECUTING no_op.\n"); - break; - - - /* Match the next n pattern characters exactly. The following - byte in the pattern defines n, and the n bytes after that - are the characters to match. */ - case exactn: - mcnt = *p++; - DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt); - - /* This is written out as an if-else so we don't waste time - testing `translate' inside the loop. */ - if (translate) - { - do - { - PREFETCH (); - if (translate[(unsigned char) *d++] != (char) *p++) - goto fail; - } - while (--mcnt); - } - else - { - do - { - PREFETCH (); - if (*d++ != (char) *p++) goto fail; - } - while (--mcnt); - } - SET_REGS_MATCHED (); - break; - - - /* Match any character except possibly a newline or a null. */ - case anychar: - DEBUG_PRINT1 ("EXECUTING anychar.\n"); - - PREFETCH (); - - if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n') - || (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000')) - goto fail; - - SET_REGS_MATCHED (); - DEBUG_PRINT2 (" Matched `%d'.\n", *d); - d++; - break; - - - case charset: - case charset_not: - { - register unsigned char c; - boolean not = (re_opcode_t) *(p - 1) == charset_not; - - DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); - - PREFETCH (); - c = TRANSLATE (*d); /* The character to match. */ - - /* Cast to `unsigned' instead of `unsigned char' in case the - bit list is a full 32 bytes long. */ - if (c < (unsigned) (*p * BYTEWIDTH) - && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - p += 1 + *p; - - if (!not) goto fail; - - SET_REGS_MATCHED (); - d++; - break; - } - - - /* The beginning of a group is represented by start_memory. - The arguments are the register number in the next byte, and the - number of groups inner to this one in the next. The text - matched within the group is recorded (in the internal - registers data structure) under the register number. */ - case start_memory: - DEBUG_PRINT3 ("EXECUTING start_memory %d (%d):\n", *p, p[1]); - - /* Find out if this group can match the empty string. */ - p1 = p; /* To send to group_match_null_string_p. */ - - if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE) - REG_MATCH_NULL_STRING_P (reg_info[*p]) - = group_match_null_string_p (&p1, pend, reg_info); - - /* Save the position in the string where we were the last time - we were at this open-group operator in case the group is - operated upon by a repetition operator, e.g., with `(a*)*b' - against `ab'; then we want to ignore where we are now in - the string in case this attempt to match fails. */ - old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) - ? REG_UNSET (regstart[*p]) ? d : regstart[*p] - : regstart[*p]; - DEBUG_PRINT2 (" old_regstart: %d\n", - POINTER_TO_OFFSET (old_regstart[*p])); - - regstart[*p] = d; - DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p])); - - IS_ACTIVE (reg_info[*p]) = 1; - MATCHED_SOMETHING (reg_info[*p]) = 0; - - /* This is the new highest active register. */ - highest_active_reg = *p; - - /* If nothing was active before, this is the new lowest active - register. */ - if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) - lowest_active_reg = *p; - - /* Move past the register number and inner group count. */ - p += 2; - break; - - - /* The stop_memory opcode represents the end of a group. Its - arguments are the same as start_memory's: the register - number, and the number of inner groups. */ - case stop_memory: - DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]); - - /* We need to save the string position the last time we were at - this close-group operator in case the group is operated - upon by a repetition operator, e.g., with `((a*)*(b*)*)*' - against `aba'; then we want to ignore where we are now in - the string in case this attempt to match fails. */ - old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) - ? REG_UNSET (regend[*p]) ? d : regend[*p] - : regend[*p]; - DEBUG_PRINT2 (" old_regend: %d\n", - POINTER_TO_OFFSET (old_regend[*p])); - - regend[*p] = d; - DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p])); - - /* This register isn't active anymore. */ - IS_ACTIVE (reg_info[*p]) = 0; - - /* If this was the only register active, nothing is active - anymore. */ - if (lowest_active_reg == highest_active_reg) - { - lowest_active_reg = NO_LOWEST_ACTIVE_REG; - highest_active_reg = NO_HIGHEST_ACTIVE_REG; - } - else - { /* We must scan for the new highest active register, since - it isn't necessarily one less than now: consider - (a(b)c(d(e)f)g). When group 3 ends, after the f), the - new highest active register is 1. */ - unsigned char r = *p - 1; - while (r > 0 && !IS_ACTIVE (reg_info[r])) - r--; - - /* If we end up at register zero, that means that we saved - the registers as the result of an `on_failure_jump', not - a `start_memory', and we jumped to past the innermost - `stop_memory'. For example, in ((.)*) we save - registers 1 and 2 as a result of the *, but when we pop - back to the second ), we are at the stop_memory 1. - Thus, nothing is active. */ - if (r == 0) - { - lowest_active_reg = NO_LOWEST_ACTIVE_REG; - highest_active_reg = NO_HIGHEST_ACTIVE_REG; - } - else - highest_active_reg = r; - } - - /* If just failed to match something this time around with a - group that's operated on by a repetition operator, try to - force exit from the ``loop'', and restore the register - information for this group that we had before trying this - last match. */ - if ((!MATCHED_SOMETHING (reg_info[*p]) - || (re_opcode_t) p[-3] == start_memory) - && (p + 2) < pend) - { - boolean is_a_jump_n = false; - - p1 = p + 2; - mcnt = 0; - switch ((re_opcode_t) *p1++) - { - case jump_n: - is_a_jump_n = true; - case pop_failure_jump: - case maybe_pop_jump: - case jump: - case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if (is_a_jump_n) - p1 += 2; - break; - - default: - /* do nothing */ ; - } - p1 += mcnt; - - /* If the next operation is a jump backwards in the pattern - to an on_failure_jump right before the start_memory - corresponding to this stop_memory, exit from the loop - by forcing a failure after pushing on the stack the - on_failure_jump's jump in the pattern, and d. */ - if (mcnt < 0 && (re_opcode_t) *p1 == on_failure_jump - && (re_opcode_t) p1[3] == start_memory && p1[4] == *p) - { - /* If this group ever matched anything, then restore - what its registers were before trying this last - failed match, e.g., with `(a*)*b' against `ab' for - regstart[1], and, e.g., with `((a*)*(b*)*)*' - against `aba' for regend[3]. - - Also restore the registers for inner groups for, - e.g., `((a*)(b*))*' against `aba' (register 3 would - otherwise get trashed). */ - - if (EVER_MATCHED_SOMETHING (reg_info[*p])) - { - unsigned r; - - EVER_MATCHED_SOMETHING (reg_info[*p]) = 0; - - /* Restore this and inner groups' (if any) registers. */ - for (r = *p; r < *p + *(p + 1); r++) - { - regstart[r] = old_regstart[r]; - - /* xx why this test? */ - if ((s_reg_t) old_regend[r] >= (s_reg_t) regstart[r]) - regend[r] = old_regend[r]; - } - } - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - PUSH_FAILURE_POINT (p1 + mcnt, d, -2); - PUSH_FAILURE_POINT2(p1 + mcnt, d, -2); - - goto fail; - } - } - - /* Move past the register number and the inner group count. */ - p += 2; - break; - - - /* \ has been turned into a `duplicate' command which is - followed by the numeric value of as the register number. */ - case duplicate: - { - register const char *d2, *dend2; - int regno = *p++; /* Get which register to match against. */ - DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); - - /* Can't back reference a group which we've never matched. */ - if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) - goto fail; - - /* Where in input to try to start matching. */ - d2 = regstart[regno]; - - /* Where to stop matching; if both the place to start and - the place to stop matching are in the same string, then - set to the place to stop, otherwise, for now have to use - the end of the first string. */ - - dend2 = ((FIRST_STRING_P (regstart[regno]) - == FIRST_STRING_P (regend[regno])) - ? regend[regno] : end_match_1); - for (;;) - { - /* If necessary, advance to next segment in register - contents. */ - while (d2 == dend2) - { - if (dend2 == end_match_2) break; - if (dend2 == regend[regno]) break; - - /* End of string1 => advance to string2. */ - d2 = string2; - dend2 = regend[regno]; - } - /* At end of register contents => success */ - if (d2 == dend2) break; - - /* If necessary, advance to next segment in data. */ - PREFETCH (); - - /* How many characters left in this segment to match. */ - mcnt = dend - d; - - /* Want how many consecutive characters we can match in - one shot, so, if necessary, adjust the count. */ - if (mcnt > dend2 - d2) - mcnt = dend2 - d2; - - /* Compare that many; failure if mismatch, else move - past them. */ - if (translate - ? bcmp_translate (d, d2, mcnt, translate) - : bcmp (d, d2, mcnt)) - goto fail; - d += mcnt, d2 += mcnt; - } - } - break; - - - /* begline matches the empty string at the beginning of the string - (unless `not_bol' is set in `bufp'), and, if - `newline_anchor' is set, after newlines. */ - case begline: - DEBUG_PRINT1 ("EXECUTING begline.\n"); - - if (AT_STRINGS_BEG (d)) - { - if (!bufp->not_bol) break; - } - else if (d[-1] == '\n' && bufp->newline_anchor) - { - break; - } - /* In all other cases, we fail. */ - goto fail; - - - /* endline is the dual of begline. */ - case endline: - DEBUG_PRINT1 ("EXECUTING endline.\n"); - - if (AT_STRINGS_END (d)) - { - if (!bufp->not_eol) break; - } - - /* We have to ``prefetch'' the next character. */ - else if ((d == end1 ? *string2 : *d) == '\n' - && bufp->newline_anchor) - { - break; - } - goto fail; - - - /* Match at the very beginning of the data. */ - case begbuf: - DEBUG_PRINT1 ("EXECUTING begbuf.\n"); - if (AT_STRINGS_BEG (d)) - break; - goto fail; - - - /* Match at the very end of the data. */ - case endbuf: - DEBUG_PRINT1 ("EXECUTING endbuf.\n"); - if (AT_STRINGS_END (d)) - break; - goto fail; - - - /* on_failure_keep_string_jump is used to optimize `.*\n'. It - pushes NULL as the value for the string on the stack. Then - `pop_failure_point' will keep the current value for the - string, instead of restoring it. To see why, consider - matching `foo\nbar' against `.*\n'. The .* matches the foo; - then the . fails against the \n. But the next thing we want - to do is match the \n against the \n; if we restored the - string value, we would be back at the foo. - - Because this is used only in specific cases, we don't need to - check all the things that `on_failure_jump' does, to make - sure the right things get saved on the stack. Hence we don't - share its code. The only reason to push anything on the - stack at all is that otherwise we would have to change - `anychar's code to do something besides goto fail in this - case; that seems worse than this. */ - case on_failure_keep_string_jump: - DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" %d (to 0x%x):\n", mcnt, p + mcnt); - - PUSH_FAILURE_POINT (p + mcnt, NULL, -2); - PUSH_FAILURE_POINT2(p + mcnt, NULL, -2); - break; - - - /* Uses of on_failure_jump: - - Each alternative starts with an on_failure_jump that points - to the beginning of the next alternative. Each alternative - except the last ends with a jump that in effect jumps past - the rest of the alternatives. (They really jump to the - ending jump of the following alternative, because tensioning - these jumps is a hassle.) - - Repeats start with an on_failure_jump that points past both - the repetition text and either the following jump or - pop_failure_jump back to this on_failure_jump. */ - case on_failure_jump: - on_failure: - DEBUG_PRINT1 ("EXECUTING on_failure_jump"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" %d (to 0x%x)", mcnt, p + mcnt); - - /* If this on_failure_jump comes right before a group (i.e., - the original * applied to a group), save the information - for that group and all inner ones, so that if we fail back - to this point, the group's information will be correct. - For example, in \(a*\)*\1, we need the preceding group, - and in \(\(a*\)b*\)\2, we need the inner group. */ - - /* We can't use `p' to check ahead because we push - a failure point to `p + mcnt' after we do this. */ - p1 = p; - - /* We need to skip no_op's before we look for the - start_memory in case this on_failure_jump is happening as - the result of a completed succeed_n, as in \(a\)\{1,3\}b\1 - against aba. */ - while (p1 < pend && (re_opcode_t) *p1 == no_op) - p1++; - - if (p1 < pend && (re_opcode_t) *p1 == start_memory) - { - /* We have a new highest active register now. This will - get reset at the start_memory we are about to get to, - but we will have saved all the registers relevant to - this repetition op, as described above. */ - highest_active_reg = *(p1 + 1) + *(p1 + 2); - if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) - lowest_active_reg = *(p1 + 1); - } - - DEBUG_PRINT1 (":\n"); - PUSH_FAILURE_POINT (p + mcnt, d, -2); - PUSH_FAILURE_POINT2(p + mcnt, d, -2); - break; - - - /* A smart repeat ends with `maybe_pop_jump'. - We change it to either `pop_failure_jump' or `jump'. */ - case maybe_pop_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT2 ("EXECUTING maybe_pop_jump %d.\n", mcnt); - { - register unsigned char *p2 = p; - - /* Compare the beginning of the repeat with what in the - pattern follows its end. If we can establish that there - is nothing that they would both match, i.e., that we - would have to backtrack because of (as in, e.g., `a*a') - then we can change to pop_failure_jump, because we'll - never have to backtrack. - - This is not true in the case of alternatives: in - `(a|ab)*' we do need to backtrack to the `ab' alternative - (e.g., if the string was `ab'). But instead of trying to - detect that here, the alternative has put on a dummy - failure point which is what we will end up popping. */ - - /* Skip over open/close-group commands. */ - while (p2 + 2 < pend - && ((re_opcode_t) *p2 == stop_memory - || (re_opcode_t) *p2 == start_memory)) - p2 += 3; /* Skip over args, too. */ - - /* If we're at the end of the pattern, we can change. */ - if (p2 == pend) - { - /* Consider what happens when matching ":\(.*\)" - against ":/". I don't really understand this code - yet. */ - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 - (" End of pattern: change to `pop_failure_jump'.\n"); - } - - else if ((re_opcode_t) *p2 == exactn - || (bufp->newline_anchor && (re_opcode_t) *p2 == endline)) - { - register unsigned char c - = *p2 == (unsigned char) endline ? '\n' : p2[2]; - p1 = p + mcnt; - - /* p1[0] ... p1[2] are the `on_failure_jump' corresponding - to the `maybe_finalize_jump' of this case. Examine what - follows. */ - if ((re_opcode_t) p1[3] == exactn && p1[5] != c) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", - c, p1[5]); - } - - else if ((re_opcode_t) p1[3] == charset - || (re_opcode_t) p1[3] == charset_not) - { - int not = (re_opcode_t) p1[3] == charset_not; - - if (c < (unsigned char) (p1[4] * BYTEWIDTH) - && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - /* `not' is equal to 1 if c would match, which means - that we can't change to pop_failure_jump. */ - if (!not) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 (" No match => pop_failure_jump.\n"); - } - } - } - } - p -= 2; /* Point at relative address again. */ - if ((re_opcode_t) p[-1] != pop_failure_jump) - { - p[-1] = (unsigned char) jump; - DEBUG_PRINT1 (" Match => jump.\n"); - goto unconditional_jump; - } - /* Note fall through. */ - - - /* The end of a simple repeat has a pop_failure_jump back to - its matching on_failure_jump, where the latter will push a - failure point. The pop_failure_jump takes off failure - points put on by this pop_failure_jump's matching - on_failure_jump; we got through the pattern to here from the - matching on_failure_jump, so didn't fail. */ - case pop_failure_jump: - { - /* We need to pass separate storage for the lowest and - highest registers, even though we don't care about the - actual values. Otherwise, we will restore only one - register from the stack, since lowest will == highest in - `pop_failure_point'. */ - active_reg_t dummy_low_reg, dummy_high_reg; - unsigned char *pdummy; - const char *sdummy; - - DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); - POP_FAILURE_POINT (sdummy, pdummy, - dummy_low_reg, dummy_high_reg, - reg_dummy, reg_dummy, reg_info_dummy); - } - /* Note fall through. */ - - - /* Unconditionally jump (without popping any failure points). */ - case jump: - unconditional_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */ - DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt); - p += mcnt; /* Do the jump. */ - DEBUG_PRINT2 ("(to 0x%x).\n", p); - break; - - - /* We need this opcode so we can detect where alternatives end - in `group_match_null_string_p' et al. */ - case jump_past_alt: - DEBUG_PRINT1 ("EXECUTING jump_past_alt.\n"); - goto unconditional_jump; - - - /* Normally, the on_failure_jump pushes a failure point, which - then gets popped at pop_failure_jump. We will end up at - pop_failure_jump, also, and with a pattern of, say, `a+', we - are skipping over the on_failure_jump, so we have to push - something meaningless for pop_failure_jump to pop. */ - case dummy_failure_jump: - DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n"); - /* It doesn't matter what we push for the string here. What - the code at `fail' tests is the value for the pattern. */ - PUSH_FAILURE_POINT (0, 0, -2); - PUSH_FAILURE_POINT2(0, 0, -2); - goto unconditional_jump; - - - /* At the end of an alternative, we need to push a dummy failure - point in case we are followed by a `pop_failure_jump', because - we don't want the failure point for the alternative to be - popped. For example, matching `(a|ab)*' against `aab' - requires that we match the `ab' alternative. */ - case push_dummy_failure: - DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n"); - /* See comments just above at `dummy_failure_jump' about the - two zeroes. */ - PUSH_FAILURE_POINT (0, 0, -2); - PUSH_FAILURE_POINT2(0, 0, -2); - break; - - /* Have to succeed matching what follows at least n times. - After that, handle like `on_failure_jump'. */ - case succeed_n: - EXTRACT_NUMBER (mcnt, p + 2); - DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt); - - assert (mcnt >= 0); - /* Originally, this is how many times we HAVE to succeed. */ - if (mcnt > 0) - { - mcnt--; - p += 2; - STORE_NUMBER_AND_INCR (p, mcnt); - DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p, mcnt); - } - else if (mcnt == 0) - { - DEBUG_PRINT2 (" Setting two bytes from 0x%x to no_op.\n", p+2); - p[2] = (unsigned char) no_op; - p[3] = (unsigned char) no_op; - goto on_failure; - } - break; - - case jump_n: - EXTRACT_NUMBER (mcnt, p + 2); - DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt); - - /* Originally, this is how many times we CAN jump. */ - if (mcnt) - { - mcnt--; - STORE_NUMBER (p + 2, mcnt); - goto unconditional_jump; - } - /* If don't have to jump any more, skip over the rest of command. */ - else - p += 4; - break; - - case set_number_at: - { - DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - p1 = p + mcnt; - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p1, mcnt); - STORE_NUMBER (p1, mcnt); - break; - } - - case wordbound: - DEBUG_PRINT1 ("EXECUTING wordbound.\n"); - if (AT_WORD_BOUNDARY (d)) - break; - goto fail; - - case notwordbound: - DEBUG_PRINT1 ("EXECUTING notwordbound.\n"); - if (AT_WORD_BOUNDARY (d)) - goto fail; - break; - - case wordbeg: - DEBUG_PRINT1 ("EXECUTING wordbeg.\n"); - if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1))) - break; - goto fail; - - case wordend: - DEBUG_PRINT1 ("EXECUTING wordend.\n"); - if (!AT_STRINGS_BEG (d) && WORDCHAR_P (d - 1) - && (!WORDCHAR_P (d) || AT_STRINGS_END (d))) - break; - goto fail; - -#ifdef emacs -#ifdef emacs19 - case before_dot: - DEBUG_PRINT1 ("EXECUTING before_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) >= point) - goto fail; - break; - - case at_dot: - DEBUG_PRINT1 ("EXECUTING at_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) != point) - goto fail; - break; - - case after_dot: - DEBUG_PRINT1 ("EXECUTING after_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) <= point) - goto fail; - break; -#else /* not emacs19 */ - case at_dot: - DEBUG_PRINT1 ("EXECUTING at_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) + 1 != point) - goto fail; - break; -#endif /* not emacs19 */ - - case syntaxspec: - DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt); - mcnt = *p++; - goto matchsyntax; - - case wordchar: - DEBUG_PRINT1 ("EXECUTING Emacs wordchar.\n"); - mcnt = (int) Sword; - matchsyntax: - PREFETCH (); - if (SYNTAX (*d++) != (enum syntaxcode) mcnt) - goto fail; - SET_REGS_MATCHED (); - break; - - case notsyntaxspec: - DEBUG_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt); - mcnt = *p++; - goto matchnotsyntax; - - case notwordchar: - DEBUG_PRINT1 ("EXECUTING Emacs notwordchar.\n"); - mcnt = (int) Sword; - matchnotsyntax: - PREFETCH (); - if (SYNTAX (*d++) == (enum syntaxcode) mcnt) - goto fail; - SET_REGS_MATCHED (); - break; - -#else /* not emacs */ - case wordchar: - DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n"); - PREFETCH (); - if (!WORDCHAR_P (d)) - goto fail; - SET_REGS_MATCHED (); - d++; - break; - - case notwordchar: - DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n"); - PREFETCH (); - if (WORDCHAR_P (d)) - goto fail; - SET_REGS_MATCHED (); - d++; - break; -#endif /* not emacs */ - - default: - abort (); - } - continue; /* Successfully executed one pattern command; keep going. */ - - - /* We goto here if a matching operation fails. */ - fail: - if (!FAIL_STACK_EMPTY ()) - { /* A restart point is known. Restore to that state. */ - DEBUG_PRINT1 ("\nFAIL:\n"); - POP_FAILURE_POINT (d, p, - lowest_active_reg, highest_active_reg, - regstart, regend, reg_info); - - /* If this failure point is a dummy, try the next one. */ - if (!p) - goto fail; - - /* If we failed to the end of the pattern, don't examine *p. */ - assert (p <= pend); - if (p < pend) - { - boolean is_a_jump_n = false; - - /* If failed to a backwards jump that's part of a repetition - loop, need to pop this failure point and use the next one. */ - switch ((re_opcode_t) *p) - { - case jump_n: - is_a_jump_n = true; - case maybe_pop_jump: - case pop_failure_jump: - case jump: - p1 = p + 1; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - - if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n) - || (!is_a_jump_n - && (re_opcode_t) *p1 == on_failure_jump)) - goto fail; - break; - default: - /* do nothing */ ; - } - } - - if (d >= string1 && d <= end1) - dend = end_match_1; - } - else - break; /* Matching at this starting point really fails. */ - } /* for (;;) */ - - if (best_regs_set) - goto restore_best_regs; - - FREE_VARIABLES (); - - return -1; /* Failure to match. */ -} /* re_match_2 */ - -/* Subroutine definitions for re_match_2. */ - - -/* We are passed P pointing to a register number after a start_memory. - - Return true if the pattern up to the corresponding stop_memory can - match the empty string, and false otherwise. - - If we find the matching stop_memory, sets P to point to one past its number. - Otherwise, sets P to an undefined byte less than or equal to END. - - We don't handle duplicates properly (yet). */ - -static boolean -group_match_null_string_p (p, end, reg_info) - unsigned char **p, *end; - register_info_type *reg_info; -{ - int mcnt; - /* Point to after the args to the start_memory. */ - unsigned char *p1 = *p + 2; - - while (p1 < end) - { - /* Skip over opcodes that can match nothing, and return true or - false, as appropriate, when we get to one that can't, or to the - matching stop_memory. */ - - switch ((re_opcode_t) *p1) - { - /* Could be either a loop or a series of alternatives. */ - case on_failure_jump: - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - - /* If the next operation is not a jump backwards in the - pattern. */ - - if (mcnt >= 0) - { - /* Go through the on_failure_jumps of the alternatives, - seeing if any of the alternatives cannot match nothing. - The last alternative starts with only a jump, - whereas the rest start with on_failure_jump and end - with a jump, e.g., here is the pattern for `a|b|c': - - /on_failure_jump/0/6/exactn/1/a/jump_past_alt/0/6 - /on_failure_jump/0/6/exactn/1/b/jump_past_alt/0/3 - /exactn/1/c - - So, we have to first go through the first (n-1) - alternatives and then deal with the last one separately. */ - - - /* Deal with the first (n-1) alternatives, which start - with an on_failure_jump (see above) that jumps to right - past a jump_past_alt. */ - - while ((re_opcode_t) p1[mcnt-3] == jump_past_alt) - { - /* `mcnt' holds how many bytes long the alternative - is, including the ending `jump_past_alt' and - its number. */ - - if (!alt_match_null_string_p (p1, p1 + mcnt - 3, - reg_info)) - return false; - - /* Move to right after this alternative, including the - jump_past_alt. */ - p1 += mcnt; - - /* Break if it's the beginning of an n-th alternative - that doesn't begin with an on_failure_jump. */ - if ((re_opcode_t) *p1 != on_failure_jump) - break; - - /* Still have to check that it's not an n-th - alternative that starts with an on_failure_jump. */ - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if ((re_opcode_t) p1[mcnt-3] != jump_past_alt) - { - /* Get to the beginning of the n-th alternative. */ - p1 -= 3; - break; - } - } - - /* Deal with the last alternative: go back and get number - of the `jump_past_alt' just before it. `mcnt' contains - the length of the alternative. */ - EXTRACT_NUMBER (mcnt, p1 - 2); - - if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info)) - return false; - - p1 += mcnt; /* Get past the n-th alternative. */ - } /* if mcnt > 0 */ - break; - - - case stop_memory: - assert (p1[1] == **p); - *p = p1 + 2; - return true; - - - default: - if (!common_op_match_null_string_p (&p1, end, reg_info)) - return false; - } - } /* while p1 < end */ - - return false; -} /* group_match_null_string_p */ - - -/* Similar to group_match_null_string_p, but doesn't deal with alternatives: - It expects P to be the first byte of a single alternative and END one - byte past the last. The alternative can contain groups. */ - -static boolean -alt_match_null_string_p (p, end, reg_info) - unsigned char *p, *end; - register_info_type *reg_info; -{ - int mcnt; - unsigned char *p1 = p; - - while (p1 < end) - { - /* Skip over opcodes that can match nothing, and break when we get - to one that can't. */ - - switch ((re_opcode_t) *p1) - { - /* It's a loop. */ - case on_failure_jump: - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - break; - - default: - if (!common_op_match_null_string_p (&p1, end, reg_info)) - return false; - } - } /* while p1 < end */ - - return true; -} /* alt_match_null_string_p */ - - -/* Deals with the ops common to group_match_null_string_p and - alt_match_null_string_p. - - Sets P to one after the op and its arguments, if any. */ - -static boolean -common_op_match_null_string_p (p, end, reg_info) - unsigned char **p, *end; - register_info_type *reg_info; -{ - int mcnt; - boolean ret; - int reg_no; - unsigned char *p1 = *p; - - switch ((re_opcode_t) *p1++) - { - case no_op: - case begline: - case endline: - case begbuf: - case endbuf: - case wordbeg: - case wordend: - case wordbound: - case notwordbound: -#ifdef emacs - case before_dot: - case at_dot: - case after_dot: -#endif - break; - - case start_memory: - reg_no = *p1; - assert (reg_no > 0 && reg_no <= MAX_REGNUM); - ret = group_match_null_string_p (&p1, end, reg_info); - - /* Have to set this here in case we're checking a group which - contains a group and a back reference to it. */ - - if (REG_MATCH_NULL_STRING_P (reg_info[reg_no]) == MATCH_NULL_UNSET_VALUE) - REG_MATCH_NULL_STRING_P (reg_info[reg_no]) = ret; - - if (!ret) - return false; - break; - - /* If this is an optimized succeed_n for zero times, make the jump. */ - case jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if (mcnt >= 0) - p1 += mcnt; - else - return false; - break; - - case succeed_n: - /* Get to the number of times to succeed. */ - p1 += 2; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - - if (mcnt == 0) - { - p1 -= 4; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - } - else - return false; - break; - - case duplicate: - if (!REG_MATCH_NULL_STRING_P (reg_info[*p1])) - return false; - break; - - case set_number_at: - p1 += 4; - - default: - /* All other opcodes mean we cannot match the empty string. */ - return false; - } - - *p = p1; - return true; -} /* common_op_match_null_string_p */ - - -/* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN - bytes; nonzero otherwise. */ - -static int -bcmp_translate (s1, s2, len, translate) - const char *s1, *s2; - register int len; - char *translate; -{ - register const unsigned char *p1 = (const unsigned char *) s1, - *p2 = (const unsigned char *) s2; - while (len) - { - if (translate[*p1++] != translate[*p2++]) return 1; - len--; - } - return 0; -} - -/* Entry points for GNU code. */ - -/* re_compile_pattern is the GNU regular expression compiler: it - compiles PATTERN (of length SIZE) and puts the result in BUFP. - Returns 0 if the pattern was valid, otherwise an error string. - - Assumes the `allocated' (and perhaps `buffer') and `translate' fields - are set in BUFP on entry. - - We call regex_compile to do the actual compilation. */ - -const char * -re_compile_pattern (pattern, length, bufp) - const char *pattern; - size_t length; - struct re_pattern_buffer *bufp; -{ - reg_errcode_t ret; - - /* GNU code is written to assume at least RE_NREGS registers will be set - (and at least one extra will be -1). */ - bufp->regs_allocated = REGS_UNALLOCATED; - - /* And GNU code determines whether or not to get register information - by passing null for the REGS argument to re_match, etc., not by - setting no_sub. */ - bufp->no_sub = 0; - - /* Match anchors at newline. */ - bufp->newline_anchor = 1; - - ret = regex_compile (pattern, length, re_syntax_options, bufp); - - return re_error_msg[(int) ret]; -} - -/* Entry points compatible with 4.2 BSD regex library. We don't define - them if this is an Emacs or POSIX compilation. */ - -#if !defined (emacs) && !defined (_POSIX_SOURCE) - -/* BSD has one and only one pattern buffer. */ -static struct re_pattern_buffer re_comp_buf; - -char * -re_comp (s) - const char *s; -{ - reg_errcode_t ret; - - if (!s) - { - if (!re_comp_buf.buffer) - return "No previous regular expression"; - return 0; - } - - if (!re_comp_buf.buffer) - { - re_comp_buf.buffer = (unsigned char *) malloc (200); - if (re_comp_buf.buffer == NULL) - return "Memory exhausted"; - re_comp_buf.allocated = 200; - - re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); - if (re_comp_buf.fastmap == NULL) - return "Memory exhausted"; - } - - /* Since `re_exec' always passes NULL for the `regs' argument, we - don't need to initialize the pattern buffer fields which affect it. */ - - /* Match anchors at newlines. */ - re_comp_buf.newline_anchor = 1; - - ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); - - /* Yes, we're discarding `const' here. */ - return (char *) re_error_msg[(int) ret]; -} - - -int -re_exec (s) - const char *s; -{ - const int len = strlen (s); - return - 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0); -} -#endif /* not emacs and not _POSIX_SOURCE */ - -/* POSIX.2 functions. Don't define these for Emacs. */ - -#ifndef emacs - -/* regcomp takes a regular expression as a string and compiles it. - - PREG is a regex_t *. We do not expect any fields to be initialized, - since POSIX says we shouldn't. Thus, we set - - `buffer' to the compiled pattern; - `used' to the length of the compiled pattern; - `syntax' to RE_SYNTAX_POSIX_EXTENDED if the - REG_EXTENDED bit in CFLAGS is set; otherwise, to - RE_SYNTAX_POSIX_BASIC; - `newline_anchor' to REG_NEWLINE being set in CFLAGS; - `fastmap' and `fastmap_accurate' to zero; - `re_nsub' to the number of subexpressions in PATTERN. - - PATTERN is the address of the pattern string. - - CFLAGS is a series of bits which affect compilation. - - If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we - use POSIX basic syntax. - - If REG_NEWLINE is set, then . and [^...] don't match newline. - Also, regexec will try a match beginning after every newline. - - If REG_ICASE is set, then we considers upper- and lowercase - versions of letters to be equivalent when matching. - - If REG_NOSUB is set, then when PREG is passed to regexec, that - routine will report only success or failure, and nothing about the - registers. - - It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for - the return codes and their meanings.) */ - -int -regcomp (preg, pattern, cflags) - regex_t *preg; - const char *pattern; - int cflags; -{ - reg_errcode_t ret; - reg_syntax_t syntax - = (cflags & REG_EXTENDED) ? - RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC; - - /* regex_compile will allocate the space for the compiled pattern. */ - preg->buffer = 0; - preg->allocated = 0; - preg->used = 0; - - /* Don't bother to use a fastmap when searching. This simplifies the - REG_NEWLINE case: if we used a fastmap, we'd have to put all the - characters after newlines into the fastmap. This way, we just try - every character. */ - preg->fastmap = 0; - - if (cflags & REG_ICASE) - { - unsigned i; - - preg->translate = (char *) malloc (CHAR_SET_SIZE); - if (preg->translate == NULL) - return (int) REG_ESPACE; - - /* Map uppercase characters to corresponding lowercase ones. */ - for (i = 0; i < CHAR_SET_SIZE; i++) - preg->translate[i] = ISUPPER (i) ? tolower (i) : i; - } - else - preg->translate = NULL; - - /* If REG_NEWLINE is set, newlines are treated differently. */ - if (cflags & REG_NEWLINE) - { /* REG_NEWLINE implies neither . nor [^...] match newline. */ - syntax &= ~RE_DOT_NEWLINE; - syntax |= RE_HAT_LISTS_NOT_NEWLINE; - /* It also changes the matching behavior. */ - preg->newline_anchor = 1; - } - else - preg->newline_anchor = 0; - - preg->no_sub = !!(cflags & REG_NOSUB); - - /* POSIX says a null character in the pattern terminates it, so we - can use strlen here in compiling the pattern. */ - ret = regex_compile (pattern, strlen (pattern), syntax, preg); - - /* POSIX doesn't distinguish between an unmatched open-group and an - unmatched close-group: both are REG_EPAREN. */ - if (ret == REG_ERPAREN) ret = REG_EPAREN; - - return (int) ret; -} - - -/* regexec searches for a given pattern, specified by PREG, in the - string STRING. - - If NMATCH is zero or REG_NOSUB was set in the cflags argument to - `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at - least NMATCH elements, and we set them to the offsets of the - corresponding matched substrings. - - EFLAGS specifies `execution flags' which affect matching: if - REG_NOTBOL is set, then ^ does not match at the beginning of the - string; if REG_NOTEOL is set, then $ does not match at the end. - - We return 0 if we find a match and REG_NOMATCH if not. */ - -int -regexec (preg, string, nmatch, pmatch, eflags) - const regex_t *preg; - const char *string; - size_t nmatch; - regmatch_t pmatch[]; - int eflags; -{ - int ret; - struct re_registers regs; - regex_t private_preg; - int len = strlen (string); - boolean want_reg_info = !preg->no_sub && nmatch > 0; - - private_preg = *preg; - - private_preg.not_bol = !!(eflags & REG_NOTBOL); - private_preg.not_eol = !!(eflags & REG_NOTEOL); - - /* The user has told us exactly how many registers to return - information about, via `nmatch'. We have to pass that on to the - matching routines. */ - private_preg.regs_allocated = REGS_FIXED; - - if (want_reg_info) - { - regs.num_regs = nmatch; - regs.start = TALLOC (nmatch, regoff_t); - regs.end = TALLOC (nmatch, regoff_t); - if (regs.start == NULL || regs.end == NULL) - return (int) REG_NOMATCH; - } - - /* Perform the searching operation. */ - ret = re_search (&private_preg, string, len, - /* start: */ 0, /* range: */ len, - want_reg_info ? ®s : (struct re_registers *) 0); - - /* Copy the register information to the POSIX structure. */ - if (want_reg_info) - { - if (ret >= 0) - { - unsigned r; - - for (r = 0; r < nmatch; r++) - { - pmatch[r].rm_so = regs.start[r]; - pmatch[r].rm_eo = regs.end[r]; - } - } - - /* If we needed the temporary register info, free the space now. */ - free (regs.start); - free (regs.end); - } - - /* We want zero return to mean success, unlike `re_search'. */ - return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH; -} - - -/* Returns a message corresponding to an error code, ERRCODE, returned - from either regcomp or regexec. We don't use PREG here. */ - -size_t -regerror (errcode, preg, errbuf, errbuf_size) - int errcode; - const regex_t *preg; - char *errbuf; - size_t errbuf_size; -{ - const char *msg; - size_t msg_size; - - if (errcode < 0 - || errcode >= (sizeof (re_error_msg) / sizeof (re_error_msg[0]))) - /* Only error codes returned by the rest of the code should be passed - to this routine. If we are given anything else, or if other regex - code generates an invalid error code, then the program has a bug. - Dump core so we can fix it. */ - abort (); - - msg = re_error_msg[errcode]; - - /* POSIX doesn't require that we do anything in this case, but why - not be nice. */ - if (! msg) - msg = "Success"; - - msg_size = strlen (msg) + 1; /* Includes the null. */ - - if (errbuf_size != 0) - { - if (msg_size > errbuf_size) - { - strncpy (errbuf, msg, errbuf_size - 1); - errbuf[errbuf_size - 1] = 0; - } - else - strcpy (errbuf, msg); - } - - return msg_size; -} - - -/* Free dynamically allocated space used by PREG. */ - -void -regfree (preg) - regex_t *preg; -{ - if (preg->buffer != NULL) - free (preg->buffer); - preg->buffer = NULL; - - preg->allocated = 0; - preg->used = 0; - - if (preg->fastmap != NULL) - free (preg->fastmap); - preg->fastmap = NULL; - preg->fastmap_accurate = 0; - - if (preg->translate != NULL) - free (preg->translate); - preg->translate = NULL; -} - -#endif /* not emacs */ - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/gnu/usr.bin/awk/regex.h b/gnu/usr.bin/awk/regex.h deleted file mode 100644 index 757dbac..0000000 --- a/gnu/usr.bin/awk/regex.h +++ /dev/null @@ -1,505 +0,0 @@ -/* Definitions for data structures and routines for the regular - expression library, version 0.12. - - Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __REGEXP_LIBRARY_H__ -#define __REGEXP_LIBRARY_H__ - -/* POSIX says that must be included (by the caller) before - . */ - -#ifdef VMS -/* VMS doesn't have `size_t' in , even though POSIX says it - should be there. */ -#include -#endif - - -/* The following two types have to be signed and unsigned integer type - wide enough to hold a value of a pointer. For most ANSI compilers - ptrdiff_t and size_t should be likely OK. Still size of these two - types is 2 for Microsoft C. Ugh... */ -typedef long s_reg_t; -typedef unsigned long active_reg_t; - -/* The following bits are used to determine the regexp syntax we - recognize. The set/not-set meanings are chosen so that Emacs syntax - remains the value 0. The bits are given in alphabetical order, and - the definitions shifted by one from the previous bit; thus, when we - add or remove a bit, only one other definition need change. */ -typedef unsigned long reg_syntax_t; - -/* If this bit is not set, then \ inside a bracket expression is literal. - If set, then such a \ quotes the following character. */ -#define RE_BACKSLASH_ESCAPE_IN_LISTS (1L) - -/* If this bit is not set, then + and ? are operators, and \+ and \? are - literals. - If set, then \+ and \? are operators and + and ? are literals. */ -#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) - -/* If this bit is set, then character classes are supported. They are: - [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], - [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. - If not set, then character classes are not supported. */ -#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) - -/* If this bit is set, then ^ and $ are always anchors (outside bracket - expressions, of course). - If this bit is not set, then it depends: - ^ is an anchor if it is at the beginning of a regular - expression or after an open-group or an alternation operator; - $ is an anchor if it is at the end of a regular expression, or - before a close-group or an alternation operator. - - This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because - POSIX draft 11.2 says that * etc. in leading positions is undefined. - We already implemented a previous draft which made those constructs - invalid, though, so we haven't changed the code back. */ -#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) - -/* If this bit is set, then special characters are always special - regardless of where they are in the pattern. - If this bit is not set, then special characters are special only in - some contexts; otherwise they are ordinary. Specifically, - * + ? and intervals are only special when not after the beginning, - open-group, or alternation operator. */ -#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) - -/* If this bit is set, then *, +, ?, and { cannot be first in an re or - immediately after an alternation or begin-group operator. */ -#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) - -/* If this bit is set, then . matches newline. - If not set, then it doesn't. */ -#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) - -/* If this bit is set, then . doesn't match NUL. - If not set, then it does. */ -#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) - -/* If this bit is set, nonmatching lists [^...] do not match newline. - If not set, they do. */ -#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) - -/* If this bit is set, either \{...\} or {...} defines an - interval, depending on RE_NO_BK_BRACES. - If not set, \{, \}, {, and } are literals. */ -#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) - -/* If this bit is set, +, ? and | aren't recognized as operators. - If not set, they are. */ -#define RE_LIMITED_OPS (RE_INTERVALS << 1) - -/* If this bit is set, newline is an alternation operator. - If not set, newline is literal. */ -#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) - -/* If this bit is set, then `{...}' defines an interval, and \{ and \} - are literals. - If not set, then `\{...\}' defines an interval. */ -#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) - -/* If this bit is set, (...) defines a group, and \( and \) are literals. - If not set, \(...\) defines a group, and ( and ) are literals. */ -#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) - -/* If this bit is set, then \ matches . - If not set, then \ is a back-reference. */ -#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) - -/* If this bit is set, then | is an alternation operator, and \| is literal. - If not set, then \| is an alternation operator, and | is literal. */ -#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) - -/* If this bit is set, then an ending range point collating higher - than the starting range point, as in [z-a], is invalid. - If not set, then when ending range point collates higher than the - starting range point, the range is ignored. */ -#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) - -/* If this bit is set, then an unmatched ) is ordinary. - If not set, then an unmatched ) is invalid. */ -#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) - -/* If this bit is set, do not process the GNU regex operators. - IF not set, then the GNU regex operators are recognized. */ -#define RE_NO_GNU_OPS (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) - -/* This global variable defines the particular regexp syntax to use (for - some interfaces). When a regexp is compiled, the syntax used is - stored in the pattern buffer, so changing this does not affect - already-compiled regexps. */ -extern reg_syntax_t re_syntax_options; - -/* Define combinations of the above bits for the standard possibilities. - (The [[[ comments delimit what gets put into the Texinfo file, so - don't delete them!) */ -/* [[[begin syntaxes]]] */ -#define RE_SYNTAX_EMACS 0 - -#define RE_SYNTAX_AWK \ - (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ - | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) - -#define RE_SYNTAX_GNU_AWK \ - (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS) - -#define RE_SYNTAX_POSIX_AWK \ - (RE_SYNTAX_GNU_AWK | RE_NO_GNU_OPS) - -#define RE_SYNTAX_GREP \ - (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ - | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ - | RE_NEWLINE_ALT) - -#define RE_SYNTAX_EGREP \ - (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ - | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ - | RE_NO_BK_VBAR) - -#define RE_SYNTAX_POSIX_EGREP \ - (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES) - -/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ -#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC - -#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC - -/* Syntax bits common to both basic and extended POSIX regex syntax. */ -#define _RE_SYNTAX_POSIX_COMMON \ - (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ - | RE_INTERVALS | RE_NO_EMPTY_RANGES) - -#define RE_SYNTAX_POSIX_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) - -/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes - RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this - isn't minimal, since other operators, such as \`, aren't disabled. */ -#define RE_SYNTAX_POSIX_MINIMAL_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) - -#define RE_SYNTAX_POSIX_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - -/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS - replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */ -#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) -/* [[[end syntaxes]]] */ - -/* Maximum number of duplicates an interval can allow. Some systems - (erroneously) define this in other header files, but we want our - value, so remove any previous define. */ -#ifdef RE_DUP_MAX -#undef RE_DUP_MAX -#endif -/* if sizeof(int) == 2, then ((1 << 15) - 1) overflows */ -#define RE_DUP_MAX (0x7fff) - - -/* POSIX `cflags' bits (i.e., information for `regcomp'). */ - -/* If this bit is set, then use extended regular expression syntax. - If not set, then use basic regular expression syntax. */ -#define REG_EXTENDED 1 - -/* If this bit is set, then ignore case when matching. - If not set, then case is significant. */ -#define REG_ICASE (REG_EXTENDED << 1) - -/* If this bit is set, then anchors do not match at newline - characters in the string. - If not set, then anchors do match at newlines. */ -#define REG_NEWLINE (REG_ICASE << 1) - -/* If this bit is set, then report only success or fail in regexec. - If not set, then returns differ between not matching and errors. */ -#define REG_NOSUB (REG_NEWLINE << 1) - - -/* POSIX `eflags' bits (i.e., information for regexec). */ - -/* If this bit is set, then the beginning-of-line operator doesn't match - the beginning of the string (presumably because it's not the - beginning of a line). - If not set, then the beginning-of-line operator does match the - beginning of the string. */ -#define REG_NOTBOL 1 - -/* Like REG_NOTBOL, except for the end-of-line. */ -#define REG_NOTEOL (1 << 1) - - -/* If any error codes are removed, changed, or added, update the - `re_error_msg' table in regex.c. */ -typedef enum -{ - REG_NOERROR = 0, /* Success. */ - REG_NOMATCH, /* Didn't find a match (for regexec). */ - - /* POSIX regcomp return error codes. (In the order listed in the - standard.) */ - REG_BADPAT, /* Invalid pattern. */ - REG_ECOLLATE, /* Not implemented. */ - REG_ECTYPE, /* Invalid character class name. */ - REG_EESCAPE, /* Trailing backslash. */ - REG_ESUBREG, /* Invalid back reference. */ - REG_EBRACK, /* Unmatched left bracket. */ - REG_EPAREN, /* Parenthesis imbalance. */ - REG_EBRACE, /* Unmatched \{. */ - REG_BADBR, /* Invalid contents of \{\}. */ - REG_ERANGE, /* Invalid range end. */ - REG_ESPACE, /* Ran out of memory. */ - REG_BADRPT, /* No preceding re for repetition op. */ - - /* Error codes we've added. */ - REG_EEND, /* Premature end. */ - REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ - REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ -} reg_errcode_t; - -/* This data structure represents a compiled pattern. Before calling - the pattern compiler, the fields `buffer', `allocated', `fastmap', - `translate', and `no_sub' can be set. After the pattern has been - compiled, the `re_nsub' field is available. All other fields are - private to the regex routines. */ - -struct re_pattern_buffer -{ -/* [[[begin pattern_buffer]]] */ - /* Space that holds the compiled pattern. It is declared as - `unsigned char *' because its elements are - sometimes used as array indexes. */ - unsigned char *buffer; - - /* Number of bytes to which `buffer' points. */ - unsigned long allocated; - - /* Number of bytes actually used in `buffer'. */ - unsigned long used; - - /* Syntax setting with which the pattern was compiled. */ - reg_syntax_t syntax; - - /* Pointer to a fastmap, if any, otherwise zero. re_search uses - the fastmap, if there is one, to skip over impossible - starting points for matches. */ - char *fastmap; - - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation - is applied to a pattern when it is compiled and to a string - when it is matched. */ - char *translate; - - /* Number of subexpressions found by the compiler. */ - size_t re_nsub; - - /* Zero if this pattern cannot match the empty string, one else. - Well, in truth it's used only in `re_search_2', to see - whether or not we should use the fastmap, so we don't set - this absolutely perfectly; see `re_compile_fastmap' (the - `duplicate' case). */ - unsigned can_be_null : 1; - - /* If REGS_UNALLOCATED, allocate space in the `regs' structure - for `max (RE_NREGS, re_nsub + 1)' groups. - If REGS_REALLOCATE, reallocate space if necessary. - If REGS_FIXED, use what's there. */ -#define REGS_UNALLOCATED 0 -#define REGS_REALLOCATE 1 -#define REGS_FIXED 2 - unsigned regs_allocated : 2; - - /* Set to zero when `regex_compile' compiles a pattern; set to one - by `re_compile_fastmap' if it updates the fastmap. */ - unsigned fastmap_accurate : 1; - - /* If set, `re_match_2' does not return information about - subexpressions. */ - unsigned no_sub : 1; - - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ - unsigned not_bol : 1; - - /* Similarly for an end-of-line anchor. */ - unsigned not_eol : 1; - - /* If true, an anchor at a newline matches. */ - unsigned newline_anchor : 1; - -/* [[[end pattern_buffer]]] */ -}; - -typedef struct re_pattern_buffer regex_t; - - -/* search.c (search_buffer) in Emacs needs this one opcode value. It is - defined both in `regex.c' and here. */ -#define RE_EXACTN_VALUE 1 - -/* Type for byte offsets within the string. POSIX mandates this. */ -typedef int regoff_t; - - -/* This is the structure we store register match data in. See - regex.texinfo for a full description of what registers match. */ -struct re_registers -{ - unsigned num_regs; - regoff_t *start; - regoff_t *end; -}; - - -/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, - `re_match_2' returns information about at least this many registers - the first time a `regs' structure is passed. */ -#ifndef RE_NREGS -#define RE_NREGS 30 -#endif - - -/* POSIX specification for registers. Aside from the different names than - `re_registers', POSIX uses an array of structures, instead of a - structure of arrays. */ -typedef struct -{ - regoff_t rm_so; /* Byte offset from string's start to substring's start. */ - regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ -} regmatch_t; - -/* Declarations for routines. */ - -/* To avoid duplicating every routine declaration -- once with a - prototype (if we are ANSI), and once without (if we aren't) -- we - use the following macro to declare argument types. This - unfortunately clutters up the declarations a bit, but I think it's - worth it. */ - -#ifdef __STDC__ - -#define _RE_ARGS(args) args - -#else /* not __STDC__ */ - -#define _RE_ARGS(args) () - -#endif /* not __STDC__ */ - -/* Sets the current default syntax to SYNTAX, and return the old syntax. - You can also simply assign to the `re_syntax_options' variable. */ -extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); - -/* Compile the regular expression PATTERN, with length LENGTH - and syntax given by the global `re_syntax_options', into the buffer - BUFFER. Return NULL if successful, and an error string if not. */ -extern const char *re_compile_pattern - _RE_ARGS ((const char *pattern, size_t length, - struct re_pattern_buffer *buffer)); - - -/* Compile a fastmap for the compiled pattern in BUFFER; used to - accelerate searches. Return 0 if successful and -2 if was an - internal error. */ -extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); - - -/* Search in the string STRING (with length LENGTH) for the pattern - compiled into BUFFER. Start searching at position START, for RANGE - characters. Return the starting position of the match, -1 for no - match, or -2 for an internal error. Also return register - information in REGS (if REGS and BUFFER->no_sub are nonzero). */ -extern int re_search - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, int range, struct re_registers *regs)); - - -/* Like `re_search', but search in the concatenation of STRING1 and - STRING2. Also, stop searching at index START + STOP. */ -extern int re_search_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, int range, struct re_registers *regs, int stop)); - - -/* Like `re_search', but return how many characters in STRING the regexp - in BUFFER matched, starting at position START. */ -extern int re_match - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, struct re_registers *regs)); - - -/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ -extern int re_match_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, struct re_registers *regs, int stop)); - - -/* Set REGS to hold NUM_REGS registers, storing them in STARTS and - ENDS. Subsequent matches using BUFFER and REGS will use this memory - for recording register information. STARTS and ENDS must be - allocated with malloc, and must each be at least `NUM_REGS * sizeof - (regoff_t)' bytes long. - - If NUM_REGS == 0, then subsequent matches should allocate their own - register data. - - Unless this function is called, the first search or match using - PATTERN_BUFFER will allocate its own register data, without - freeing the old data. */ -extern void re_set_registers - _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, - unsigned num_regs, regoff_t *starts, regoff_t *ends)); - -/* 4.2 bsd compatibility. */ -extern char *re_comp _RE_ARGS ((const char *)); -extern int re_exec _RE_ARGS ((const char *)); - -/* POSIX compatibility. */ -extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags)); -extern int regexec - _RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch, - regmatch_t pmatch[], int eflags)); -extern size_t regerror - _RE_ARGS ((int errcode, const regex_t *preg, char *errbuf, - size_t errbuf_size)); -extern void regfree _RE_ARGS ((regex_t *preg)); - -#endif /* not __REGEXP_LIBRARY_H__ */ - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/gnu/usr.bin/cpio/mt.1 b/gnu/usr.bin/cpio/mt.1 deleted file mode 100644 index fc9cb64..0000000 --- a/gnu/usr.bin/cpio/mt.1 +++ /dev/null @@ -1,107 +0,0 @@ -.TH MT 1L \" -*- nroff -*- -.SH NAME -mt \- control magnetic tape drive operation -.SH SYNOPSIS -.B mt -[\-V] [\-f device] [\-\-file=device] [\-\-version] -operation [count] -.SH DESCRIPTION -This manual page -documents the GNU version of -.BR mt . -.B mt -performs the given -.IR operation , -which must be one of the tape operations listed below, on a tape -drive. -.PP -The default tape device to operate on is taken from the file -.I /usr/include/sys/mtio.h -when -.B mt -is compiled. It can be overridden by giving a device file name in -the environment variable -.BR TAPE -or by a command line option (see below), which also overrides the -environment variable. -.PP -The device must be either a character special file or a -remote tape drive. To use a tape drive on another machine as the -archive, use a filename that starts with `HOSTNAME:'. The -hostname can be preceded by a username and an `@' to access the remote -tape drive as that user, if you have permission to do so (typically an -entry in that user's `~/.rhosts' file). -.PP -The available operations are listed below. Unique abbreviations are -accepted. Not all operations are available on all systems, or work on -all types of tape drives. -Some operations optionally take a repeat count, which can be given -after the operation name and defaults to 1. -.IP "eof, weof" -Write -.I count -EOF marks at current position. -.IP fsf -Forward space -.I count -files. -The tape is positioned on the first block of the next file. -.IP bsf -Backward space -.I count -files. -The tape is positioned on the first block of the next file. -.IP fsr -Forward space -.I count -records. -.IP bsr -Backward space -.I count -records. -.IP bsfm -Backward space -.I count -file marks. -The tape is positioned on the beginning-of-the-tape side of -the file mark. -.IP asf -Absolute space to file number -.IR count . -Equivalent to rewind followed by fsf -.IR count . -.IP eom -Space to the end of the recorded media on the tape -(for appending files onto tapes). -.IP rewind -Rewind the tape. -.IP "offline, rewoffl" -Rewind the tape and, if applicable, unload the tape. -.IP status -Print status information about the tape unit. -.IP retension -Rewind the tape, then wind it to the end of the reel, -then rewind it again. -.IP erase -Erase the tape. -.PP -.B mt -exits with a status of 0 if the operation succeeded, 1 if the -operation or device name given was invalid, or 2 if the operation -failed. -.SS OPTIONS -.TP -.I "\-f, \-\-file=device" -Use -.I device -as the file name of the tape drive to operate on. -To use a -tape drive on another machine, use a filename that -starts with `HOSTNAME:'. The hostname can be preceded by a -username and an `@' to access the remote tape drive as that user, if -you have permission to do so (typically an entry in that user's -`~/.rhosts' file). -.TP -.I "\-V, \-\-version" -Print the version number of -.BR mt . diff --git a/gnu/usr.bin/cpio/rmt.c b/gnu/usr.bin/cpio/rmt.c deleted file mode 100644 index 442a831..0000000 --- a/gnu/usr.bin/cpio/rmt.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ - -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1983 Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -/* - * rmt - */ -#include -#include -#include -#include -#ifdef HAVE_SYS_GENTAPE_H /* e.g., ISC UNIX */ -#include -#else -#include -#endif -#include - -#if defined (_I386) && defined (_AIX) -#include -#endif - -#ifdef HAVE_UNISTD_H -#include -#else -long lseek (); -#endif - -#ifdef STDC_HEADERS -#include -#include -#else -extern char *malloc (); -#endif - -int tape = -1; - -char *record; -int maxrecsize = -1; -char *checkbuf (); -void getstring (); -void error (); - -#define SSIZE 64 -char device[SSIZE]; -char count[SSIZE], mode[SSIZE], pos[SSIZE], op[SSIZE]; - -extern errno; -extern char *sys_errlist[]; -char resp[BUFSIZ]; - -FILE *debug; -#define DEBUG(f) if (debug) fprintf(debug, f) -#define DEBUG1(f,a) if (debug) fprintf(debug, f, a) -#define DEBUG2(f,a1,a2) if (debug) fprintf(debug, f, a1, a2) - -int -main (argc, argv) - int argc; - char **argv; -{ - int rval; - char c; - int n, i, cc; - - argc--, argv++; - if (argc > 0) - { - debug = fopen (*argv, "w"); - if (debug == 0) - exit (1); - (void) setbuf (debug, (char *) 0); - } -top: - errno = 0; - rval = 0; - if (read (0, &c, 1) != 1) - exit (0); - switch (c) - { - - case 'O': - if (tape >= 0) - (void) close (tape); - getstring (device); - getstring (mode); - DEBUG2 ("rmtd: O %s %s\n", device, mode); -#if defined (i386) && defined (AIX) - /* This is alleged to fix a byte ordering problem. */ - /* I'm quite suspicious if it's right. -- mib */ - { - int oflag = atoi (mode); - int nflag = 0; - if ((oflag & 3) == 0) - nflag |= O_RDONLY; - if (oflag & 1) - nflag |= O_WRONLY; - if (oflag & 2) - nflag |= O_RDWR; - if (oflag & 0x0008) - nflag |= O_APPEND; - if (oflag & 0x0200) - nflag |= O_CREAT; - if (oflag & 0x0400) - nflag |= O_TRUNC; - if (oflag & 0x0800) - nflag |= O_EXCL; - tape = open (device, nflag, 0666); - } -#else - tape = open (device, atoi (mode), 0666); -#endif - if (tape < 0) - goto ioerror; - goto respond; - - case 'C': - DEBUG ("rmtd: C\n"); - getstring (device); /* discard */ - if (close (tape) < 0) - goto ioerror; - tape = -1; - goto respond; - - case 'L': - getstring (count); - getstring (pos); - DEBUG2 ("rmtd: L %s %s\n", count, pos); - rval = lseek (tape, (long) atoi (count), atoi (pos)); - if (rval < 0) - goto ioerror; - goto respond; - - case 'W': - getstring (count); - n = atoi (count); - DEBUG1 ("rmtd: W %s\n", count); - record = checkbuf (record, n); - for (i = 0; i < n; i += cc) - { - cc = read (0, &record[i], n - i); - if (cc <= 0) - { - DEBUG ("rmtd: premature eof\n"); - exit (2); - } - } - rval = write (tape, record, n); - if (rval < 0) - goto ioerror; - goto respond; - - case 'R': - getstring (count); - DEBUG1 ("rmtd: R %s\n", count); - n = atoi (count); - record = checkbuf (record, n); - rval = read (tape, record, n); - if (rval < 0) - goto ioerror; - (void) sprintf (resp, "A%d\n", rval); - (void) write (1, resp, strlen (resp)); - (void) write (1, record, rval); - goto top; - - case 'I': - getstring (op); - getstring (count); - DEBUG2 ("rmtd: I %s %s\n", op, count); -#ifdef MTIOCTOP - { - struct mtop mtop; - mtop.mt_op = atoi (op); - mtop.mt_count = atoi (count); - if (ioctl (tape, MTIOCTOP, (char *) &mtop) < 0) - goto ioerror; - rval = mtop.mt_count; - } -#endif - goto respond; - - case 'S': /* status */ - DEBUG ("rmtd: S\n"); - { -#ifdef MTIOCGET - struct mtget mtget; - if (ioctl (tape, MTIOCGET, (char *) &mtget) < 0) - goto ioerror; - rval = sizeof (mtget); - (void) sprintf (resp, "A%d\n", rval); - (void) write (1, resp, strlen (resp)); - (void) write (1, (char *) &mtget, sizeof (mtget)); -#endif - goto top; - } - - default: - DEBUG1 ("rmtd: garbage command %c\n", c); - exit (3); - } -respond: - DEBUG1 ("rmtd: A %d\n", rval); - (void) sprintf (resp, "A%d\n", rval); - (void) write (1, resp, strlen (resp)); - goto top; -ioerror: - error (errno); - goto top; -} - -void -getstring (bp) - char *bp; -{ - int i; - char *cp = bp; - - for (i = 0; i < SSIZE; i++) - { - if (read (0, cp + i, 1) != 1) - exit (0); - if (cp[i] == '\n') - break; - } - cp[i] = '\0'; -} - -char * -checkbuf (record, size) - char *record; - int size; -{ - if (size <= maxrecsize) - return (record); - if (record != 0) - free (record); - record = malloc (size); - if (record == 0) - { - DEBUG ("rmtd: cannot allocate buffer space\n"); - exit (4); - } - maxrecsize = size; -#ifdef SO_RCVBUF - while (size > 1024 && - setsockopt (0, SOL_SOCKET, SO_RCVBUF, (char *) &size, sizeof (size)) < 0) - size -= 1024; -#else - size = 1 + ((size - 1) % 1024); -#endif - return (record); -} - -void -error (num) - int num; -{ - - DEBUG2 ("rmtd: E %d (%s)\n", num, sys_errlist[num]); - (void) sprintf (resp, "E%d\n%s\n", num, sys_errlist[num]); - (void) write (1, resp, strlen (resp)); -} diff --git a/gnu/usr.bin/cvs/lib/regex.h b/gnu/usr.bin/cvs/lib/regex.h deleted file mode 100644 index 546b8a9..0000000 --- a/gnu/usr.bin/cvs/lib/regex.h +++ /dev/null @@ -1,479 +0,0 @@ -/* Definitions for data structures and routines for the regular - expression library, version REPLACE-WITH-VERSION. - - Copyright (C) 1985, 1989, 1990, 1991, 1992 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __REGEXP_LIBRARY_H__ -#define __REGEXP_LIBRARY_H__ - -/* POSIX says that must be included before . */ - -/* The following bits are used to determine the regexp syntax we - recognize. The set/not-set meanings are chosen so that Emacs syntax - remains the value 0. The bits are given in alphabetical order, and - the definitions shifted by one from the previous bit; thus, when we - add or remove a bit, only one other definition need change. */ -typedef unsigned reg_syntax_t; - -/* If this bit is not set, then \ inside a bracket expression is literal. - If set, then such a \ quotes the following character. */ -#define RE_BACKSLASH_ESCAPE_IN_LISTS (1) - -/* If this bit is not set, then + and ? are operators, and \+ and \? are - literals. - If set, then \+ and \? are operators and + and ? are literals. */ -#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) - -/* If this bit is set, then character classes are supported. They are: - [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], - [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. - If not set, then character classes are not supported. */ -#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) - -/* If this bit is set, then ^ and $ are always anchors (outside bracket - expressions). - If this bit is not set, then it depends: - ^ is an anchor if it is at the beginning of a regular - expression or after an open-group or an alternation operator; - $ is an anchor if it is at the end of a regular expression, or - before a close-group or an alternation operator. - This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because - POSIX now says that the behavior of * etc. in leading positions is - undefined. We have already implemented a previous draft which - made those constructs invalid, so we may as well not change the code - back. */ -#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) - -/* If this bit is set, then special characters are always special - regardless of where they are in the pattern. - If this bit is not set, then special characters are special only in - some contexts; otherwise they are ordinary. Specifically, - * + ? and intervals are only special when not after the beginning, - open-group, or alternation operator. */ -#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) - -/* If this bit is set, then *, +, ?, and { cannot be first in an re or - immediately after an alternation or begin-group operator. - Furthermore, alternation cannot be first or last in an re, or - immediately follow another alternation or begin-group. */ -#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) - -/* If this bit is set, then . matches a newline. - If not set, then it doesn't. */ -#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) - -/* If this bit is set, then period doesn't match a null. - If not set, then it does. */ -#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) - -/* If this bit is set, nonmatching lists [^...] do not match newline. - If not set, they do. */ -#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) - -/* If this bit is set, either \{...\} or {...} defines an - interval, depending on RE_NO_BK_BRACES. - If not set, \{, \}, {, and } are literals. */ -#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) - -/* If this bit is set, +, ? and | aren't recognized as operators. - If not set, they are. */ -#define RE_LIMITED_OPS (RE_INTERVALS << 1) - -/* If this bit is set, newline is an alternation operator. - If not set, newline is literal. */ -#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) - -/* If this bit is set, newline in the pattern is an ordinary character. - If not set, newline before ^ or after $ allows the ^ or $ to be an - anchor. */ -#define RE_NEWLINE_ORDINARY (RE_NEWLINE_ALT << 1) - -/* If this bit is not set, then \{ and \} defines an interval, - and { and } are literals. - If set, then { and } defines an interval, and \{ and \} are literals. */ -#define RE_NO_BK_BRACES (RE_NEWLINE_ORDINARY << 1) - -/* If this bit is set, (...) defines a group, and \( and \) are literals. - If not set, \(...\) defines a group, and ( and ) are literals. */ -#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) - -/* If this bit is set, then back references (i.e., \) are not - recognized. - If not set, then they are. */ -#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) - -/* If this bit is set, then | is an alternation operator, and \| is literal. - If not set, then \| is an alternation operator, and | is literal. */ -#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) - -/* If this bit is set, then you can't have empty alternatives. - If not set, then you can. */ -#define RE_NO_EMPTY_ALTS (RE_NO_BK_VBAR << 1) - -/* If this bit is set, then you can't have empty groups. - If not set, then you can. */ -#define RE_NO_EMPTY_GROUPS (RE_NO_EMPTY_ALTS << 1) - -/* If this bit is set, then an ending range point has to collate higher - than or equal to the starting range point. - If not set, then when the ending range point collates higher than the - starting range point, we consider such a range to be empty. */ -#define RE_NO_EMPTY_RANGES (RE_NO_EMPTY_GROUPS << 1) - -/* If this bit is set, then all back references must refer to a preceding - subexpression. - If not set, then a back reference to a nonexistent subexpression is - treated as literal characters. */ -#define RE_NO_MISSING_BK_REF (RE_NO_EMPTY_RANGES << 1) - -/* If this bit is set, then Regex considers an unmatched close-group - operator to be the ordinary character parenthesis. - If not set, then an unmatched close-group operator is invalid. */ -#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_MISSING_BK_REF << 1) - -/* This global variable defines the particular regexp syntax to use (for - some interfaces). When a regexp is compiled, the syntax used is - stored in the pattern buffer, so changing this does not affect - already-compiled regexps. */ -extern reg_syntax_t obscure_syntax; - - - -/* Define combinations of the above bits for the standard possibilities. - (The [[[ comments delimit what gets put into the Texinfo file.) */ -/* [[[begin syntaxes]]] */ -#define RE_SYNTAX_EMACS 0 - -#define RE_SYNTAX_POSIX_AWK \ - (RE_CONTEXT_INDEP_ANCHORS | RE_CONTEXT_INDEP_OPS | RE_NO_BK_PARENS \ - | RE_NO_BK_VBAR) - -#define RE_SYNTAX_AWK \ - (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_SYNTAX_POSIX_AWK) - -#define RE_SYNTAX_GREP \ - (RE_BK_PLUS_QM | RE_NEWLINE_ALT) - -#define RE_SYNTAX_EGREP \ - (RE_CONTEXT_INDEP_ANCHORS | RE_CONTEXT_INDEP_OPS \ - | RE_NEWLINE_ALT | RE_NO_BK_PARENS | RE_NO_BK_VBAR) - -#define RE_SYNTAX_POSIX_BASIC \ - (RE_CHAR_CLASSES | RE_DOT_NEWLINE \ - | RE_DOT_NOT_NULL | RE_INTERVALS | RE_LIMITED_OPS \ - | RE_NEWLINE_ORDINARY | RE_NO_EMPTY_RANGES | RE_NO_MISSING_BK_REF) - -#define RE_SYNTAX_POSIX_EXTENDED \ - (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INVALID_OPS | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ - | RE_INTERVALS | RE_NEWLINE_ORDINARY | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS | RE_NO_BK_VBAR \ - | RE_NO_EMPTY_ALTS | RE_NO_EMPTY_GROUPS | RE_NO_EMPTY_RANGES \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) -/* [[[end syntaxes]]] */ - - - - -/* Maximum number of duplicates an interval can allow. */ -#undef RE_DUP_MAX -#define RE_DUP_MAX ((1 << 15) - 1) - - -/* POSIX `cflags' bits (i.e., information for regcomp). */ - -/* If this bit is set, then use extended regular expression syntax. - If not set, then use basic regular expression syntax. */ -#define REG_EXTENDED 1 - -/* If this bit is set, then ignore case when matching. - If not set, then case is significant. */ -#define REG_ICASE (REG_EXTENDED << 1) - -/* If this bit is set, then anchors do not match at newline - characters in the string. - If not set, then anchors do match at newlines. */ -#define REG_NEWLINE (REG_ICASE << 1) - -/* If this bit is set, then report only success or fail in regexec. - If not set, then returns differ between not matching and errors. */ -#define REG_NOSUB (REG_NEWLINE << 1) - - -/* POSIX `eflags' bits (i.e., information for regexec). */ - -/* If this bit is set, then the beginning-of-line operator doesn't match - the beginning of the string (presumably because it's not the - beginning of a line). - If not set, then the beginning-of-line operator does match the - beginning of the string. */ -#define REG_NOTBOL 1 - -/* Like REG_NOTBOL, except for the end-of-line. */ -#define REG_NOTEOL (1 << 1) - - -/* If any error codes are removed, changed, or added, update the - `re_error_msg' table in regex.c. */ -typedef enum -{ - REG_NOERROR = 0, /* Success. */ - REG_NOMATCH, /* Didn't find a match (for regexec). */ - - /* POSIX regcomp return error codes. (In the order listed in the - standard.) */ - REG_BADPAT, /* Invalid pattern. */ - REG_ECOLLATE, /* Not implemented. */ - REG_ECTYPE, /* Invalid character class name. */ - REG_EESCAPE, /* Trailing backslash. */ - REG_ESUBREG, /* Invalid back reference. */ - REG_EBRACK, /* Unmatched left bracket. */ - REG_EPAREN, /* Parenthesis imbalance. */ - REG_EBRACE, /* Unmatched \{. */ - REG_BADBR, /* Invalid contents of \{\}. */ - REG_ERANGE, /* Invalid range end. */ - REG_ESPACE, /* Ran out of memory. */ - REG_BADRPT, /* No preceding re for repetition op. */ - - /* Error codes we've added. */ - REG_EEND, /* Premature end. */ - REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ - REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ -} reg_errcode_t; - - - - -/* This data structure represents a compiled pattern. Before calling - the pattern compiler, the fields `buffer', `allocated', `fastmap', - `translate', and `no_sub' can be set. After the pattern has been - compiled, the `re_nsub' field is available. All other fields are - private to the regex routines. */ - -struct re_pattern_buffer -{ -/* [[[begin pattern_buffer]]] */ - /* Space that holds the compiled pattern. It is declared as - `unsigned char *' because its elements are - sometimes used as array indexes. */ - unsigned char *buffer; - - /* Number of bytes to which `buffer' points. */ - unsigned long allocated; - - /* Number of bytes actually used in `buffer'. */ - unsigned long used; - - /* Syntax setting with which the pattern was compiled. */ - reg_syntax_t syntax; - - /* Pointer to a fastmap, if any, otherwise zero. re_search uses - the fastmap, if there is one, to skip over impossible - starting points for matches. */ - char *fastmap; - - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation - is applied to a pattern when it is compiled and to a string - when it is matched. */ - char *translate; - - /* Number of subexpressions found by the compiler. */ - size_t re_nsub; - - /* Set to 1 by re_compile_fastmap if this pattern can match the - null string; 0 prevents the searcher from matching it with - the null string. Set to 2 if it might match the null string - either at the end of a search range or just before a - character listed in the fastmap. */ - unsigned can_be_null : 2; - - /* Set to zero when regex_compile compiles a pattern; set to one - by re_compile_fastmap when it updates the fastmap, if any. */ - unsigned fastmap_accurate : 1; - - /* If set, regexec reports only success or failure and does not - return anything in pmatch. */ - unsigned no_sub : 1; - - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ - unsigned not_bol : 1; - - /* Similarly for an end-of-line anchor. */ - unsigned not_eol : 1; - - /* If true, an anchor at a newline matches. */ - unsigned newline_anchor : 1; - - /* If set, re_match_2 assumes a non-null REGS argument is - initialized. If not set, REGS is initialized to the max of - RE_NREGS and re_nsub + 1 registers. */ - unsigned caller_allocated_regs : 1; -/* [[[end pattern_buffer]]] */ -}; - -typedef struct re_pattern_buffer regex_t; - - -/* search.c (search_buffer) in Emacs needs this one opcode value. It is - defined both in `regex.c' and here. */ -#define RE_EXACTN_VALUE 1 - - - - -/* Type for byte offsets within the string. POSIX mandates us defining - this. */ -typedef int regoff_t; - - -/* This is the structure we store register match data in. See - regex.texinfo for a full description of what registers match. */ -struct re_registers -{ - unsigned num_regs; - regoff_t *start; - regoff_t *end; -}; - - -/* If `caller_allocated_regs' is zero in the pattern buffer, re_match_2 - returns information about this many registers. */ -#ifndef RE_NREGS -#define RE_NREGS 30 -#endif - - -/* POSIX specification for registers. Aside from the different names than - `re_registers', POSIX uses an array of structures, instead of a - structure of arrays. */ -typedef struct -{ - regoff_t rm_so; /* Byte offset from string's start to substring's start. */ - regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ -} regmatch_t; - - - - -/* Declarations for routines. */ - -#if __STDC__ - -/* Sets the current syntax to SYNTAX. You can also simply assign to the - `obscure_syntax' variable. */ -extern reg_syntax_t re_set_syntax (reg_syntax_t syntax); - -/* Compile the regular expression PATTERN, with length LENGTH - and syntax given by the global `obscure_syntax', into the buffer - BUFFER. Return NULL if successful, and an error string if not. */ -extern const char *re_compile_pattern (const char *pattern, int length, - struct re_pattern_buffer *buffer); - - -/* Compile a fastmap for the compiled pattern in BUFFER; used to - accelerate searches. Return 0 if successful and -2 if was an - internal error. */ -extern int re_compile_fastmap (struct re_pattern_buffer *buffer); - - -/* Search in the string STRING (with length LENGTH) for the pattern - compiled into BUFFER. Start searching at position START, for RANGE - characters. Return the starting position of the match, -1 for no - match, or -2 for an internal error. Also return register - information in REGS (if REGS and BUFFER->no_sub are nonzero). */ -extern int re_search (struct re_pattern_buffer *buffer, - const char *string, int length, - int start, int range, - struct re_registers *regs); - - -/* Like `re_search', but search in the concatenation of STRING1 and - STRING2. Also, stop searching at index START + STOP. */ -extern int re_search_2 (struct re_pattern_buffer *buffer, - const char *string1, int length1, - const char *string2, int length2, - int start, int range, - struct re_registers *regs, - int stop); - - -/* Like `re_search', but return how many characters in STRING the regexp - in BUFFER matched, starting at position START. */ -extern int re_match (const struct re_pattern_buffer *buffer, - const char *string, int length, - int start, struct re_registers *regs); - - -/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ -extern int re_match_2 (const struct re_pattern_buffer *buffer, - const char *string1, int length1, - const char *string2, int length2, - int start, - struct re_registers *regs, - int stop); - - -#ifndef __FreeBSD__ -/* 4.2 bsd compatibility. */ -#ifndef bsdi -extern const char *re_comp (const char *); -#endif -extern int re_exec (const char *); -#endif - -/* POSIX compatibility. */ -extern int regcomp (regex_t *preg, const char *pattern, int cflags); -extern int regexec (const regex_t *preg, const char *string, size_t nmatch, - regmatch_t pmatch[], int eflags); -extern size_t regerror (int errcode, const regex_t *preg, char *errbuf, - size_t errbuf_size); -extern void regfree (regex_t *preg); - -#else /* not __STDC__ */ - -/* Support old C compilers. */ -#define const - -extern reg_syntax_t re_set_syntax (); -extern char *re_compile_pattern (); -extern int re_search (), re_search_2 (); -extern int re_match (), re_match_2 (); - -/* 4.2 BSD compatibility. */ -extern char *re_comp (); -extern int re_exec (); - -/* POSIX compatibility. */ -extern int regcomp (); -extern int regexec (); -extern size_t regerror (); -extern void regfree (); - -#endif /* not __STDC__ */ -#endif /* not __REGEXP_LIBRARY_H__ */ - - - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/gnu/usr.bin/dialog/inputbox.c b/gnu/usr.bin/dialog/inputbox.c deleted file mode 100644 index 4c51a1c..0000000 --- a/gnu/usr.bin/dialog/inputbox.c +++ /dev/null @@ -1,279 +0,0 @@ -/* - * inputbox.c -- implements the input box - * - * AUTHOR: Savio Lam (lam836@cs.cuhk.hk) - * - * 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 - * of the License, 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 this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - - -#include "dialog.h" - - -/* - * Display a dialog box for inputing a string - */ -int dialog_inputbox(unsigned char *title, unsigned char *prompt, int height, int width) -{ - int i, x, y, box_y, box_x, box_width, - input_x = 0, scroll = 0, key = 0, button = -1; - unsigned char instr[MAX_LEN+1]; - WINDOW *dialog; - - /* center dialog box on screen */ - x = (COLS - width)/2; - y = (LINES - height)/2; - - memset(instr, 0, sizeof(instr)); - -#ifdef HAVE_NCURSES - if (use_shadow) - draw_shadow(stdscr, y, x, height, width); -#endif - dialog = newwin(height, width, y, x); - keypad(dialog, TRUE); - - draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); - wattrset(dialog, border_attr); - wmove(dialog, height-3, 0); - waddch(dialog, ACS_LTEE); - for (i = 0; i < width-2; i++) - waddch(dialog, ACS_HLINE); - wattrset(dialog, dialog_attr); - waddch(dialog, ACS_RTEE); - wmove(dialog, height-2, 1); - for (i = 0; i < width-2; i++) - waddch(dialog, ' '); - - if (title != NULL) { - wattrset(dialog, title_attr); - wmove(dialog, 0, (width - strlen(title))/2 - 1); - waddch(dialog, ' '); - waddstr(dialog, title); - waddch(dialog, ' '); - } - wattrset(dialog, dialog_attr); - print_autowrap(dialog, prompt, width, 1, 3); - - /* Draw the input field box */ - box_width = width-6; - getyx(dialog, y, x); - box_y = y + 2; - box_x = (width - box_width)/2; - draw_box(dialog, y+1, box_x-1, 3, box_width+2, border_attr, dialog_attr); - - x = width/2-11; - y = height-2; - print_button(dialog, "Cancel", y, x+14, FALSE); - print_button(dialog, " OK ", y, x, TRUE); - - wmove(dialog, box_y, box_x); - wrefresh(dialog); - while (key != ESC) { - key = wgetch(dialog); - - if (button == -1) { /* Input box selected */ - switch (key) { - case TAB: - case KEY_BTAB: - case KEY_UP: - case KEY_DOWN: - break; - case KEY_HOME: - input_x = scroll = 0; - wmove(dialog, box_y, box_x); - for (i = 0; i < box_width; i++) - waddch(dialog, instr[i] ? instr[i] : ' '); - wmove(dialog, box_y, box_x); - wrefresh(dialog); - continue; - case KEY_END: - for (i = strlen(instr) - 1; i >= scroll + input_x && instr[i] == ' '; i--) - instr[i] = '\0'; - i++; - input_x = i % box_width; - scroll = i - input_x; - wmove(dialog, box_y, box_x); - for (i = 0; i < box_width; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wmove(dialog, box_y, input_x + box_x); - wrefresh(dialog); - continue; - case KEY_LEFT: - if (input_x || scroll) { - wattrset(dialog, inputbox_attr); - if (!input_x) { - int oldscroll = scroll; - scroll = scroll < box_width-1 ? 0 : scroll-(box_width-1); - wmove(dialog, box_y, box_x); - for (i = 0; i < box_width; i++) - waddch(dialog, instr[scroll+input_x+i] ? instr[scroll+input_x+i] : ' '); - input_x = oldscroll - 1 - scroll; - } - else - input_x--; - wmove(dialog, box_y, input_x + box_x); - wrefresh(dialog); - } - continue; - case KEY_RIGHT: - if (scroll+input_x < MAX_LEN) { - wattrset(dialog, inputbox_attr); - if (!instr[scroll+input_x]) - instr[scroll+input_x] = ' '; - if (input_x == box_width-1) { - scroll++; - wmove(dialog, box_y, box_x); - for (i = 0; i < box_width; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wmove(dialog, box_y, box_x + box_width - 1); - } - else { - wmove(dialog, box_y, input_x + box_x); - waddch(dialog, instr[scroll+input_x]); - input_x++; - } - wrefresh(dialog); - } else - flash(); /* Alarm user about overflow */ - continue; - case KEY_BACKSPACE: - case KEY_DC: - if (input_x || scroll) { - i = strlen(instr); - memmove(instr+scroll+input_x-1, instr+scroll+input_x, i-scroll+input_x+1); - wattrset(dialog, inputbox_attr); - if (!input_x) { - int oldscroll = scroll; - scroll = scroll < box_width-1 ? 0 : scroll-(box_width-1); - wmove(dialog, box_y, box_x); - for (i = 0; i < box_width; i++) - waddch(dialog, instr[scroll+input_x+i] ? instr[scroll+input_x+i] : ' '); - input_x = oldscroll - 1 - scroll; - } - else - input_x--; - wmove(dialog, box_y, input_x + box_x); - for (i = input_x; i < box_width; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wmove(dialog, box_y, input_x + box_x); - wrefresh(dialog); - } - continue; - default: - if (key < 0x100 && isprint(key)) { - for (i = strlen(instr) - 1; i >= scroll + input_x && instr[i] == ' '; i--) - instr[i] = '\0'; - i++; - if (i < MAX_LEN) { - memmove(instr+scroll+input_x+1, instr+scroll+input_x, i-scroll+input_x); - wattrset(dialog, inputbox_attr); - instr[scroll+input_x] = key; - if (input_x == box_width-1) { - scroll++; - wmove(dialog, box_y, box_x); - for (i = 0; i < box_width-1; i++) - waddch(dialog, instr[scroll+i]); - } - else { - wmove(dialog, box_y, input_x + box_x); - for (i = input_x; i < box_width; i++) - waddch(dialog, instr[scroll+i] ? instr[scroll+i] : ' '); - wmove(dialog, box_y, ++input_x + box_x); - } - wrefresh(dialog); - } else - flash(); /* Alarm user about overflow */ - continue; - } - } - } - - switch (key) { - case 'O': - case 'o': - delwin(dialog); - fprintf(stderr, instr); - return 0; - case 'C': - case 'c': - delwin(dialog); - return 1; - case KEY_UP: - case KEY_LEFT: - case KEY_BTAB: - switch (button) { - case -1: - button = 1; /* Indicates "Cancel" button is selected */ - print_button(dialog, " OK ", y, x, FALSE); - print_button(dialog, "Cancel", y, x+14, TRUE); - wrefresh(dialog); - break; - case 0: - button = -1; /* Indicates input box is selected */ - print_button(dialog, "Cancel", y, x+14, FALSE); - print_button(dialog, " OK ", y, x, TRUE); - wmove(dialog, box_y, box_x + input_x); - wrefresh(dialog); - break; - case 1: - button = 0; /* Indicates "OK" button is selected */ - print_button(dialog, "Cancel", y, x+14, FALSE); - print_button(dialog, " OK ", y, x, TRUE); - wrefresh(dialog); - break; - } - break; - case TAB: - case KEY_DOWN: - case KEY_RIGHT: - switch (button) { - case -1: - button = 0; /* Indicates "OK" button is selected */ - print_button(dialog, "Cancel", y, x+14, FALSE); - print_button(dialog, " OK ", y, x, TRUE); - wrefresh(dialog); - break; - case 0: - button = 1; /* Indicates "Cancel" button is selected */ - print_button(dialog, " OK ", y, x, FALSE); - print_button(dialog, "Cancel", y, x+14, TRUE); - wrefresh(dialog); - break; - case 1: - button = -1; /* Indicates input box is selected */ - print_button(dialog, "Cancel", y, x+14, FALSE); - print_button(dialog, " OK ", y, x, TRUE); - wmove(dialog, box_y, box_x + input_x); - wrefresh(dialog); - break; - } - break; - case ' ': - case '\n': - delwin(dialog); - for (i = strlen(instr) - 1; i >= scroll + input_x && instr[i] == ' '; i--) - instr[i] = '\0'; - fprintf(stderr, instr); - return (button == -1 ? 0 : button); - case ESC: - break; - } - } - - delwin(dialog); - return -1; /* ESC pressed */ -} -/* End of dialog_inputbox() */ diff --git a/gnu/usr.bin/diff/regex.c b/gnu/usr.bin/diff/regex.c deleted file mode 100644 index 81b06ff..0000000 --- a/gnu/usr.bin/diff/regex.c +++ /dev/null @@ -1,5171 +0,0 @@ -/* Extended regular expression matching and search library, - version 0.12. - (Implements POSIX draft P10003.2/D11.2, except for - internationalization features.) - - Copyright (C) 1993 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* AIX requires this to be the first thing in the file. */ -#if defined (_AIX) && !defined (REGEX_MALLOC) - #pragma alloca -#endif - -#define _GNU_SOURCE - -#ifdef HAVE_CONFIG_H -#if defined (CONFIG_BROKETS) -/* We use instead of "config.h" so that a compilation - using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h - (which it would do because it found this file in $srcdir). */ -#include -#else -#include "config.h" -#endif -#endif - -/* We need this for `regex.h', and perhaps for the Emacs include files. */ -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -/* The `emacs' switch turns on certain matching commands - that make sense only in Emacs. */ -#ifdef emacs - -#include "lisp.h" -#include "buffer.h" -#include "syntax.h" - -/* Emacs uses `NULL' as a predicate. */ -#undef NULL - -#else /* not emacs */ - -#ifdef STDC_HEADERS -#include -#else -char *malloc (); -char *realloc (); -#endif - - -/* We used to test for `BSTRING' here, but only GCC and Emacs define - `BSTRING', as far as I know, and neither of them use this code. */ -#if HAVE_STRING_H || STDC_HEADERS -#include -#ifndef bcmp -#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) -#endif -#ifndef bcopy -#define bcopy(s, d, n) memcpy ((d), (s), (n)) -#endif -#ifndef bzero -#define bzero(s, n) memset ((s), 0, (n)) -#endif -#else -#include -#endif - -/* Define the syntax stuff for \<, \>, etc. */ - -/* This must be nonzero for the wordchar and notwordchar pattern - commands in re_match_2. */ -#ifndef Sword -#define Sword 1 -#endif - -#ifdef SYNTAX_TABLE - -extern char *re_syntax_table; - -#else /* not SYNTAX_TABLE */ - -/* How many characters in the character set. */ -#define CHAR_SET_SIZE 256 - -static char re_syntax_table[CHAR_SET_SIZE]; - -static void -init_syntax_once () -{ - register int c; - static int done = 0; - - if (done) - return; - - bzero (re_syntax_table, sizeof re_syntax_table); - - for (c = 'a'; c <= 'z'; c++) - re_syntax_table[c] = Sword; - - for (c = 'A'; c <= 'Z'; c++) - re_syntax_table[c] = Sword; - - for (c = '0'; c <= '9'; c++) - re_syntax_table[c] = Sword; - - re_syntax_table['_'] = Sword; - - done = 1; -} - -#endif /* not SYNTAX_TABLE */ - -#define SYNTAX(c) re_syntax_table[c] - -#endif /* not emacs */ - -/* Get the interface, including the syntax bits. */ -#include "regex.h" - -/* isalpha etc. are used for the character classes. */ -#include - -/* Jim Meyering writes: - - "... Some ctype macros are valid only for character codes that - isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when - using /bin/cc or gcc but without giving an ansi option). So, all - ctype uses should be through macros like ISPRINT... If - STDC_HEADERS is defined, then autoconf has verified that the ctype - macros don't need to be guarded with references to isascii. ... - Defining isascii to 1 should let any compiler worth its salt - eliminate the && through constant folding." */ -#if ! defined (isascii) || defined (STDC_HEADERS) -#undef isascii -#define isascii(c) 1 -#endif - -#ifdef isblank -#define ISBLANK(c) (isascii (c) && isblank (c)) -#else -#define ISBLANK(c) ((c) == ' ' || (c) == '\t') -#endif -#ifdef isgraph -#define ISGRAPH(c) (isascii (c) && isgraph (c)) -#else -#define ISGRAPH(c) (isascii (c) && isprint (c) && !isspace (c)) -#endif - -#define ISPRINT(c) (isascii (c) && isprint (c)) -#define ISDIGIT(c) (isascii (c) && isdigit (c)) -#define ISALNUM(c) (isascii (c) && isalnum (c)) -#define ISALPHA(c) (isascii (c) && isalpha (c)) -#define ISCNTRL(c) (isascii (c) && iscntrl (c)) -#define ISLOWER(c) (isascii (c) && islower (c)) -#define ISPUNCT(c) (isascii (c) && ispunct (c)) -#define ISSPACE(c) (isascii (c) && isspace (c)) -#define ISUPPER(c) (isascii (c) && isupper (c)) -#define ISXDIGIT(c) (isascii (c) && isxdigit (c)) - -#ifndef NULL -#define NULL 0 -#endif - -/* We remove any previous definition of `SIGN_EXTEND_CHAR', - since ours (we hope) works properly with all combinations of - machines, compilers, `char' and `unsigned char' argument types. - (Per Bothner suggested the basic approach.) */ -#undef SIGN_EXTEND_CHAR -#if __STDC__ -#define SIGN_EXTEND_CHAR(c) ((signed char) (c)) -#else /* not __STDC__ */ -/* As in Harbison and Steele. */ -#define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128) -#endif - -/* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we - use `alloca' instead of `malloc'. This is because using malloc in - re_search* or re_match* could cause memory leaks when C-g is used in - Emacs; also, malloc is slower and causes storage fragmentation. On - the other hand, malloc is more portable, and easier to debug. - - Because we sometimes use alloca, some routines have to be macros, - not functions -- `alloca'-allocated space disappears at the end of the - function it is called in. */ - -#ifdef REGEX_MALLOC - -#define REGEX_ALLOCATE malloc -#define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize) - -#else /* not REGEX_MALLOC */ - -/* Emacs already defines alloca, sometimes. */ -#ifndef alloca - -/* Make alloca work the best possible way. */ -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else /* not __GNUC__ */ -#if HAVE_ALLOCA_H -#include -#else /* not __GNUC__ or HAVE_ALLOCA_H */ -#ifndef _AIX /* Already did AIX, up at the top. */ -char *alloca (); -#endif /* not _AIX */ -#endif /* not HAVE_ALLOCA_H */ -#endif /* not __GNUC__ */ - -#endif /* not alloca */ - -#define REGEX_ALLOCATE alloca - -/* Assumes a `char *destination' variable. */ -#define REGEX_REALLOCATE(source, osize, nsize) \ - (destination = (char *) alloca (nsize), \ - bcopy (source, destination, osize), \ - destination) - -#endif /* not REGEX_MALLOC */ - - -/* True if `size1' is non-NULL and PTR is pointing anywhere inside - `string1' or just past its end. This works if PTR is NULL, which is - a good thing. */ -#define FIRST_STRING_P(ptr) \ - (size1 && string1 <= (ptr) && (ptr) <= string1 + size1) - -/* (Re)Allocate N items of type T using malloc, or fail. */ -#define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t))) -#define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t))) -#define RETALLOC_IF(addr, n, t) \ - if (addr) RETALLOC((addr), (n), t); else (addr) = TALLOC ((n), t) -#define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t))) - -#define BYTEWIDTH 8 /* In bits. */ - -#define STREQ(s1, s2) ((strcmp (s1, s2) == 0)) - -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -typedef char boolean; -#define false 0 -#define true 1 - -/* These are the command codes that appear in compiled regular - expressions. Some opcodes are followed by argument bytes. A - command code can specify any interpretation whatsoever for its - arguments. Zero bytes may appear in the compiled regular expression. - - The value of `exactn' is needed in search.c (search_buffer) in Emacs. - So regex.h defines a symbol `RE_EXACTN_VALUE' to be 1; the value of - `exactn' we use here must also be 1. */ - -typedef enum -{ - no_op = 0, - - /* Followed by one byte giving n, then by n literal bytes. */ - exactn = 1, - - /* Matches any (more or less) character. */ - anychar, - - /* Matches any one char belonging to specified set. First - following byte is number of bitmap bytes. Then come bytes - for a bitmap saying which chars are in. Bits in each byte - are ordered low-bit-first. A character is in the set if its - bit is 1. A character too large to have a bit in the map is - automatically not in the set. */ - charset, - - /* Same parameters as charset, but match any character that is - not one of those specified. */ - charset_not, - - /* Start remembering the text that is matched, for storing in a - register. Followed by one byte with the register number, in - the range 0 to one less than the pattern buffer's re_nsub - field. Then followed by one byte with the number of groups - inner to this one. (This last has to be part of the - start_memory only because we need it in the on_failure_jump - of re_match_2.) */ - start_memory, - - /* Stop remembering the text that is matched and store it in a - memory register. Followed by one byte with the register - number, in the range 0 to one less than `re_nsub' in the - pattern buffer, and one byte with the number of inner groups, - just like `start_memory'. (We need the number of inner - groups here because we don't have any easy way of finding the - corresponding start_memory when we're at a stop_memory.) */ - stop_memory, - - /* Match a duplicate of something remembered. Followed by one - byte containing the register number. */ - duplicate, - - /* Fail unless at beginning of line. */ - begline, - - /* Fail unless at end of line. */ - endline, - - /* Succeeds if at beginning of buffer (if emacs) or at beginning - of string to be matched (if not). */ - begbuf, - - /* Analogously, for end of buffer/string. */ - endbuf, - - /* Followed by two byte relative address to which to jump. */ - jump, - - /* Same as jump, but marks the end of an alternative. */ - jump_past_alt, - - /* Followed by two-byte relative address of place to resume at - in case of failure. */ - on_failure_jump, - - /* Like on_failure_jump, but pushes a placeholder instead of the - current string position when executed. */ - on_failure_keep_string_jump, - - /* Throw away latest failure point and then jump to following - two-byte relative address. */ - pop_failure_jump, - - /* Change to pop_failure_jump if know won't have to backtrack to - match; otherwise change to jump. This is used to jump - back to the beginning of a repeat. If what follows this jump - clearly won't match what the repeat does, such that we can be - sure that there is no use backtracking out of repetitions - already matched, then we change it to a pop_failure_jump. - Followed by two-byte address. */ - maybe_pop_jump, - - /* Jump to following two-byte address, and push a dummy failure - point. This failure point will be thrown away if an attempt - is made to use it for a failure. A `+' construct makes this - before the first repeat. Also used as an intermediary kind - of jump when compiling an alternative. */ - dummy_failure_jump, - - /* Push a dummy failure point and continue. Used at the end of - alternatives. */ - push_dummy_failure, - - /* Followed by two-byte relative address and two-byte number n. - After matching N times, jump to the address upon failure. */ - succeed_n, - - /* Followed by two-byte relative address, and two-byte number n. - Jump to the address N times, then fail. */ - jump_n, - - /* Set the following two-byte relative address to the - subsequent two-byte number. The address *includes* the two - bytes of number. */ - set_number_at, - - wordchar, /* Matches any word-constituent character. */ - notwordchar, /* Matches any char that is not a word-constituent. */ - - wordbeg, /* Succeeds if at word beginning. */ - wordend, /* Succeeds if at word end. */ - - wordbound, /* Succeeds if at a word boundary. */ - notwordbound /* Succeeds if not at a word boundary. */ - -#ifdef emacs - ,before_dot, /* Succeeds if before point. */ - at_dot, /* Succeeds if at point. */ - after_dot, /* Succeeds if after point. */ - - /* Matches any character whose syntax is specified. Followed by - a byte which contains a syntax code, e.g., Sword. */ - syntaxspec, - - /* Matches any character whose syntax is not that specified. */ - notsyntaxspec -#endif /* emacs */ -} re_opcode_t; - -/* Common operations on the compiled pattern. */ - -/* Store NUMBER in two contiguous bytes starting at DESTINATION. */ - -#define STORE_NUMBER(destination, number) \ - do { \ - (destination)[0] = (number) & 0377; \ - (destination)[1] = (number) >> 8; \ - } while (0) - -/* Same as STORE_NUMBER, except increment DESTINATION to - the byte after where the number is stored. Therefore, DESTINATION - must be an lvalue. */ - -#define STORE_NUMBER_AND_INCR(destination, number) \ - do { \ - STORE_NUMBER (destination, number); \ - (destination) += 2; \ - } while (0) - -/* Put into DESTINATION a number stored in two contiguous bytes starting - at SOURCE. */ - -#define EXTRACT_NUMBER(destination, source) \ - do { \ - (destination) = *(source) & 0377; \ - (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \ - } while (0) - -#ifdef DEBUG -static void -extract_number (dest, source) - int *dest; - unsigned char *source; -{ - int temp = SIGN_EXTEND_CHAR (*(source + 1)); - *dest = *source & 0377; - *dest += temp << 8; -} - -#ifndef EXTRACT_MACROS /* To debug the macros. */ -#undef EXTRACT_NUMBER -#define EXTRACT_NUMBER(dest, src) extract_number (&dest, src) -#endif /* not EXTRACT_MACROS */ - -#endif /* DEBUG */ - -/* Same as EXTRACT_NUMBER, except increment SOURCE to after the number. - SOURCE must be an lvalue. */ - -#define EXTRACT_NUMBER_AND_INCR(destination, source) \ - do { \ - EXTRACT_NUMBER (destination, source); \ - (source) += 2; \ - } while (0) - -#ifdef DEBUG -static void -extract_number_and_incr (destination, source) - int *destination; - unsigned char **source; -{ - extract_number (destination, *source); - *source += 2; -} - -#ifndef EXTRACT_MACROS -#undef EXTRACT_NUMBER_AND_INCR -#define EXTRACT_NUMBER_AND_INCR(dest, src) \ - extract_number_and_incr (&dest, &src) -#endif /* not EXTRACT_MACROS */ - -#endif /* DEBUG */ - -/* If DEBUG is defined, Regex prints many voluminous messages about what - it is doing (if the variable `debug' is nonzero). If linked with the - main program in `iregex.c', you can enter patterns and strings - interactively. And if linked with the main program in `main.c' and - the other test files, you can run the already-written tests. */ - -#ifdef DEBUG - -/* We use standard I/O for debugging. */ -#include - -/* It is useful to test things that ``must'' be true when debugging. */ -#include - -static int debug = 0; - -#define DEBUG_STATEMENT(e) e -#define DEBUG_PRINT1(x) if (debug) printf (x) -#define DEBUG_PRINT2(x1, x2) if (debug) printf (x1, x2) -#define DEBUG_PRINT3(x1, x2, x3) if (debug) printf (x1, x2, x3) -#define DEBUG_PRINT4(x1, x2, x3, x4) if (debug) printf (x1, x2, x3, x4) -#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ - if (debug) print_partial_compiled_pattern (s, e) -#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ - if (debug) print_double_string (w, s1, sz1, s2, sz2) - - -extern void printchar (); - -/* Print the fastmap in human-readable form. */ - -void -print_fastmap (fastmap) - char *fastmap; -{ - unsigned was_a_range = 0; - unsigned i = 0; - - while (i < (1 << BYTEWIDTH)) - { - if (fastmap[i++]) - { - was_a_range = 0; - printchar (i - 1); - while (i < (1 << BYTEWIDTH) && fastmap[i]) - { - was_a_range = 1; - i++; - } - if (was_a_range) - { - printf ("-"); - printchar (i - 1); - } - } - } - putchar ('\n'); -} - - -/* Print a compiled pattern string in human-readable form, starting at - the START pointer into it and ending just before the pointer END. */ - -void -print_partial_compiled_pattern (start, end) - unsigned char *start; - unsigned char *end; -{ - int mcnt, mcnt2; - unsigned char *p = start; - unsigned char *pend = end; - - if (start == NULL) - { - printf ("(null)\n"); - return; - } - - /* Loop over pattern commands. */ - while (p < pend) - { - printf ("%d:\t", p - start); - - switch ((re_opcode_t) *p++) - { - case no_op: - printf ("/no_op"); - break; - - case exactn: - mcnt = *p++; - printf ("/exactn/%d", mcnt); - do - { - putchar ('/'); - printchar (*p++); - } - while (--mcnt); - break; - - case start_memory: - mcnt = *p++; - printf ("/start_memory/%d/%d", mcnt, *p++); - break; - - case stop_memory: - mcnt = *p++; - printf ("/stop_memory/%d/%d", mcnt, *p++); - break; - - case duplicate: - printf ("/duplicate/%d", *p++); - break; - - case anychar: - printf ("/anychar"); - break; - - case charset: - case charset_not: - { - register int c, last = -100; - register int in_range = 0; - - printf ("/charset [%s", - (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); - - assert (p + *p < pend); - - for (c = 0; c < 256; c++) - if (c / 8 < *p - && (p[1 + (c/8)] & (1 << (c % 8)))) - { - /* Are we starting a range? */ - if (last + 1 == c && ! in_range) - { - putchar ('-'); - in_range = 1; - } - /* Have we broken a range? */ - else if (last + 1 != c && in_range) - { - printchar (last); - in_range = 0; - } - - if (! in_range) - printchar (c); - - last = c; - } - - if (in_range) - printchar (last); - - putchar (']'); - - p += 1 + *p; - } - break; - - case begline: - printf ("/begline"); - break; - - case endline: - printf ("/endline"); - break; - - case on_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/on_failure_jump to %d", p + mcnt - start); - break; - - case on_failure_keep_string_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/on_failure_keep_string_jump to %d", p + mcnt - start); - break; - - case dummy_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/dummy_failure_jump to %d", p + mcnt - start); - break; - - case push_dummy_failure: - printf ("/push_dummy_failure"); - break; - - case maybe_pop_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/maybe_pop_jump to %d", p + mcnt - start); - break; - - case pop_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/pop_failure_jump to %d", p + mcnt - start); - break; - - case jump_past_alt: - extract_number_and_incr (&mcnt, &p); - printf ("/jump_past_alt to %d", p + mcnt - start); - break; - - case jump: - extract_number_and_incr (&mcnt, &p); - printf ("/jump to %d", p + mcnt - start); - break; - - case succeed_n: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/succeed_n to %d, %d times", p + mcnt - start, mcnt2); - break; - - case jump_n: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/jump_n to %d, %d times", p + mcnt - start, mcnt2); - break; - - case set_number_at: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/set_number_at location %d to %d", p + mcnt - start, mcnt2); - break; - - case wordbound: - printf ("/wordbound"); - break; - - case notwordbound: - printf ("/notwordbound"); - break; - - case wordbeg: - printf ("/wordbeg"); - break; - - case wordend: - printf ("/wordend"); - -#ifdef emacs - case before_dot: - printf ("/before_dot"); - break; - - case at_dot: - printf ("/at_dot"); - break; - - case after_dot: - printf ("/after_dot"); - break; - - case syntaxspec: - printf ("/syntaxspec"); - mcnt = *p++; - printf ("/%d", mcnt); - break; - - case notsyntaxspec: - printf ("/notsyntaxspec"); - mcnt = *p++; - printf ("/%d", mcnt); - break; -#endif /* emacs */ - - case wordchar: - printf ("/wordchar"); - break; - - case notwordchar: - printf ("/notwordchar"); - break; - - case begbuf: - printf ("/begbuf"); - break; - - case endbuf: - printf ("/endbuf"); - break; - - default: - printf ("?%d", *(p-1)); - } - - putchar ('\n'); - } - - printf ("%d:\tend of pattern.\n", p - start); -} - - -void -print_compiled_pattern (bufp) - struct re_pattern_buffer *bufp; -{ - unsigned char *buffer = bufp->buffer; - - print_partial_compiled_pattern (buffer, buffer + bufp->used); - printf ("%d bytes used/%d bytes allocated.\n", bufp->used, bufp->allocated); - - if (bufp->fastmap_accurate && bufp->fastmap) - { - printf ("fastmap: "); - print_fastmap (bufp->fastmap); - } - - printf ("re_nsub: %d\t", bufp->re_nsub); - printf ("regs_alloc: %d\t", bufp->regs_allocated); - printf ("can_be_null: %d\t", bufp->can_be_null); - printf ("newline_anchor: %d\n", bufp->newline_anchor); - printf ("no_sub: %d\t", bufp->no_sub); - printf ("not_bol: %d\t", bufp->not_bol); - printf ("not_eol: %d\t", bufp->not_eol); - printf ("syntax: %d\n", bufp->syntax); - /* Perhaps we should print the translate table? */ -} - - -void -print_double_string (where, string1, size1, string2, size2) - const char *where; - const char *string1; - const char *string2; - int size1; - int size2; -{ - unsigned this_char; - - if (where == NULL) - printf ("(null)"); - else - { - if (FIRST_STRING_P (where)) - { - for (this_char = where - string1; this_char < size1; this_char++) - printchar (string1[this_char]); - - where = string2; - } - - for (this_char = where - string2; this_char < size2; this_char++) - printchar (string2[this_char]); - } -} - -#else /* not DEBUG */ - -#undef assert -#define assert(e) - -#define DEBUG_STATEMENT(e) -#define DEBUG_PRINT1(x) -#define DEBUG_PRINT2(x1, x2) -#define DEBUG_PRINT3(x1, x2, x3) -#define DEBUG_PRINT4(x1, x2, x3, x4) -#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) -#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) - -#endif /* not DEBUG */ - -/* Set by `re_set_syntax' to the current regexp syntax to recognize. Can - also be assigned to arbitrarily: each pattern buffer stores its own - syntax, so it can be changed between regex compilations. */ -reg_syntax_t re_syntax_options = RE_SYNTAX_EMACS; - - -/* Specify the precise syntax of regexps for compilation. This provides - for compatibility for various utilities which historically have - different, incompatible syntaxes. - - The argument SYNTAX is a bit mask comprised of the various bits - defined in regex.h. We return the old syntax. */ - -reg_syntax_t -re_set_syntax (syntax) - reg_syntax_t syntax; -{ - reg_syntax_t ret = re_syntax_options; - - re_syntax_options = syntax; - return ret; -} - -/* This table gives an error message for each of the error codes listed - in regex.h. Obviously the order here has to be same as there. */ - -static const char *re_error_msg[] = - { NULL, /* REG_NOERROR */ - "No match", /* REG_NOMATCH */ - "Invalid regular expression", /* REG_BADPAT */ - "Invalid collation character", /* REG_ECOLLATE */ - "Invalid character class name", /* REG_ECTYPE */ - "Trailing backslash", /* REG_EESCAPE */ - "Invalid back reference", /* REG_ESUBREG */ - "Unmatched [ or [^", /* REG_EBRACK */ - "Unmatched ( or \\(", /* REG_EPAREN */ - "Unmatched \\{", /* REG_EBRACE */ - "Invalid content of \\{\\}", /* REG_BADBR */ - "Invalid range end", /* REG_ERANGE */ - "Memory exhausted", /* REG_ESPACE */ - "Invalid preceding regular expression", /* REG_BADRPT */ - "Premature end of regular expression", /* REG_EEND */ - "Regular expression too big", /* REG_ESIZE */ - "Unmatched ) or \\)", /* REG_ERPAREN */ - }; - -/* Avoiding alloca during matching, to placate r_alloc. */ - -/* Define MATCH_MAY_ALLOCATE if we need to make sure that the - searching and matching functions should not call alloca. On some - systems, alloca is implemented in terms of malloc, and if we're - using the relocating allocator routines, then malloc could cause a - relocation, which might (if the strings being searched are in the - ralloc heap) shift the data out from underneath the regexp - routines. - - Here's another reason to avoid allocation: Emacs insists on - processing input from X in a signal handler; processing X input may - call malloc; if input arrives while a matching routine is calling - malloc, then we're scrod. But Emacs can't just block input while - calling matching routines; then we don't notice interrupts when - they come in. So, Emacs blocks input around all regexp calls - except the matching calls, which it leaves unprotected, in the - faith that they will not malloc. */ - -/* Normally, this is fine. */ -#define MATCH_MAY_ALLOCATE - -/* But under some circumstances, it's not. */ -#if defined (emacs) || (defined (REL_ALLOC) && defined (C_ALLOCA)) -#undef MATCH_MAY_ALLOCATE -#endif - - -/* Failure stack declarations and macros; both re_compile_fastmap and - re_match_2 use a failure stack. These have to be macros because of - REGEX_ALLOCATE. */ - - -/* Number of failure points for which to initially allocate space - when matching. If this number is exceeded, we allocate more - space, so it is not a hard limit. */ -#ifndef INIT_FAILURE_ALLOC -#define INIT_FAILURE_ALLOC 5 -#endif - -/* Roughly the maximum number of failure points on the stack. Would be - exactly that if always used MAX_FAILURE_SPACE each time we failed. - This is a variable only so users of regex can assign to it; we never - change it ourselves. */ -int re_max_failures = 2000; - -typedef unsigned char *fail_stack_elt_t; - -typedef struct -{ - fail_stack_elt_t *stack; - unsigned size; - unsigned avail; /* Offset of next open position. */ -} fail_stack_type; - -#define FAIL_STACK_EMPTY() (fail_stack.avail == 0) -#define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0) -#define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size) -#define FAIL_STACK_TOP() (fail_stack.stack[fail_stack.avail]) - - -/* Initialize `fail_stack'. Do `return -2' if the alloc fails. */ - -#ifdef MATCH_MAY_ALLOCATE -#define INIT_FAIL_STACK() \ - do { \ - fail_stack.stack = (fail_stack_elt_t *) \ - REGEX_ALLOCATE (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \ - \ - if (fail_stack.stack == NULL) \ - return -2; \ - \ - fail_stack.size = INIT_FAILURE_ALLOC; \ - fail_stack.avail = 0; \ - } while (0) -#else -#define INIT_FAIL_STACK() \ - do { \ - fail_stack.avail = 0; \ - } while (0) -#endif - - -/* Double the size of FAIL_STACK, up to approximately `re_max_failures' items. - - Return 1 if succeeds, and 0 if either ran out of memory - allocating space for it or it was already too large. - - REGEX_REALLOCATE requires `destination' be declared. */ - -#define DOUBLE_FAIL_STACK(fail_stack) \ - ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \ - ? 0 \ - : ((fail_stack).stack = (fail_stack_elt_t *) \ - REGEX_REALLOCATE ((fail_stack).stack, \ - (fail_stack).size * sizeof (fail_stack_elt_t), \ - ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \ - \ - (fail_stack).stack == NULL \ - ? 0 \ - : ((fail_stack).size <<= 1, \ - 1))) - - -/* Push PATTERN_OP on FAIL_STACK. - - Return 1 if was able to do so and 0 if ran out of memory allocating - space to do so. */ -#define PUSH_PATTERN_OP(pattern_op, fail_stack) \ - ((FAIL_STACK_FULL () \ - && !DOUBLE_FAIL_STACK (fail_stack)) \ - ? 0 \ - : ((fail_stack).stack[(fail_stack).avail++] = pattern_op, \ - 1)) - -/* This pushes an item onto the failure stack. Must be a four-byte - value. Assumes the variable `fail_stack'. Probably should only - be called from within `PUSH_FAILURE_POINT'. */ -#define PUSH_FAILURE_ITEM(item) \ - fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) item - -/* The complement operation. Assumes `fail_stack' is nonempty. */ -#define POP_FAILURE_ITEM() fail_stack.stack[--fail_stack.avail] - -/* Used to omit pushing failure point id's when we're not debugging. */ -#ifdef DEBUG -#define DEBUG_PUSH PUSH_FAILURE_ITEM -#define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_ITEM () -#else -#define DEBUG_PUSH(item) -#define DEBUG_POP(item_addr) -#endif - - -/* Push the information about the state we will need - if we ever fail back to it. - - Requires variables fail_stack, regstart, regend, reg_info, and - num_regs be declared. DOUBLE_FAIL_STACK requires `destination' be - declared. - - Does `return FAILURE_CODE' if runs out of memory. */ - -#define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \ - do { \ - char *destination; \ - /* Must be int, so when we don't save any registers, the arithmetic \ - of 0 + -1 isn't done as unsigned. */ \ - int this_reg; \ - \ - DEBUG_STATEMENT (failure_id++); \ - DEBUG_STATEMENT (nfailure_points_pushed++); \ - DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \ - DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\ - DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\ - \ - DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \ - DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \ - \ - /* Ensure we have enough space allocated for what we will push. */ \ - while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \ - { \ - if (!DOUBLE_FAIL_STACK (fail_stack)) \ - return failure_code; \ - \ - DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \ - (fail_stack).size); \ - DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\ - } \ - \ - /* Push the info, starting with the registers. */ \ - DEBUG_PRINT1 ("\n"); \ - \ - for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \ - this_reg++) \ - { \ - DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \ - DEBUG_STATEMENT (num_regs_pushed++); \ - \ - DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \ - PUSH_FAILURE_ITEM (regstart[this_reg]); \ - \ - DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ - PUSH_FAILURE_ITEM (regend[this_reg]); \ - \ - DEBUG_PRINT2 (" info: 0x%x\n ", reg_info[this_reg]); \ - DEBUG_PRINT2 (" match_null=%d", \ - REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \ - DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \ - DEBUG_PRINT2 (" matched_something=%d", \ - MATCHED_SOMETHING (reg_info[this_reg])); \ - DEBUG_PRINT2 (" ever_matched=%d", \ - EVER_MATCHED_SOMETHING (reg_info[this_reg])); \ - DEBUG_PRINT1 ("\n"); \ - PUSH_FAILURE_ITEM (reg_info[this_reg].word); \ - } \ - \ - DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\ - PUSH_FAILURE_ITEM (lowest_active_reg); \ - \ - DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\ - PUSH_FAILURE_ITEM (highest_active_reg); \ - \ - DEBUG_PRINT2 (" Pushing pattern 0x%x: ", pattern_place); \ - DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \ - PUSH_FAILURE_ITEM (pattern_place); \ - \ - DEBUG_PRINT2 (" Pushing string 0x%x: `", string_place); \ - DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \ - size2); \ - DEBUG_PRINT1 ("'\n"); \ - PUSH_FAILURE_ITEM (string_place); \ - \ - DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \ - DEBUG_PUSH (failure_id); \ - } while (0) - -/* This is the number of items that are pushed and popped on the stack - for each register. */ -#define NUM_REG_ITEMS 3 - -/* Individual items aside from the registers. */ -#ifdef DEBUG -#define NUM_NONREG_ITEMS 5 /* Includes failure point id. */ -#else -#define NUM_NONREG_ITEMS 4 -#endif - -/* We push at most this many items on the stack. */ -#define MAX_FAILURE_ITEMS ((num_regs - 1) * NUM_REG_ITEMS + NUM_NONREG_ITEMS) - -/* We actually push this many items. */ -#define NUM_FAILURE_ITEMS \ - ((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS \ - + NUM_NONREG_ITEMS) - -/* How many items can still be added to the stack without overflowing it. */ -#define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail) - - -/* Pops what PUSH_FAIL_STACK pushes. - - We restore into the parameters, all of which should be lvalues: - STR -- the saved data position. - PAT -- the saved pattern position. - LOW_REG, HIGH_REG -- the highest and lowest active registers. - REGSTART, REGEND -- arrays of string positions. - REG_INFO -- array of information about each subexpression. - - Also assumes the variables `fail_stack' and (if debugging), `bufp', - `pend', `string1', `size1', `string2', and `size2'. */ - -#define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\ -{ \ - DEBUG_STATEMENT (fail_stack_elt_t failure_id;) \ - int this_reg; \ - const unsigned char *string_temp; \ - \ - assert (!FAIL_STACK_EMPTY ()); \ - \ - /* Remove failure points and point to how many regs pushed. */ \ - DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \ - DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \ - DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \ - \ - assert (fail_stack.avail >= NUM_NONREG_ITEMS); \ - \ - DEBUG_POP (&failure_id); \ - DEBUG_PRINT2 (" Popping failure id: %u\n", failure_id); \ - \ - /* If the saved string location is NULL, it came from an \ - on_failure_keep_string_jump opcode, and we want to throw away the \ - saved NULL, thus retaining our current position in the string. */ \ - string_temp = POP_FAILURE_ITEM (); \ - if (string_temp != NULL) \ - str = (const char *) string_temp; \ - \ - DEBUG_PRINT2 (" Popping string 0x%x: `", str); \ - DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ - DEBUG_PRINT1 ("'\n"); \ - \ - pat = (unsigned char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping pattern 0x%x: ", pat); \ - DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ - \ - /* Restore register info. */ \ - high_reg = (unsigned) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \ - \ - low_reg = (unsigned) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping low active reg: %d\n", low_reg); \ - \ - for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \ - { \ - DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \ - \ - reg_info[this_reg].word = POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" info: 0x%x\n", reg_info[this_reg]); \ - \ - regend[this_reg] = (const char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ - \ - regstart[this_reg] = (const char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \ - } \ - \ - DEBUG_STATEMENT (nfailure_points_popped++); \ -} /* POP_FAILURE_POINT */ - - - -/* Structure for per-register (a.k.a. per-group) information. - This must not be longer than one word, because we push this value - onto the failure stack. Other register information, such as the - starting and ending positions (which are addresses), and the list of - inner groups (which is a bits list) are maintained in separate - variables. - - We are making a (strictly speaking) nonportable assumption here: that - the compiler will pack our bit fields into something that fits into - the type of `word', i.e., is something that fits into one item on the - failure stack. */ -typedef union -{ - fail_stack_elt_t word; - struct - { - /* This field is one if this group can match the empty string, - zero if not. If not yet determined, `MATCH_NULL_UNSET_VALUE'. */ -#define MATCH_NULL_UNSET_VALUE 3 - unsigned match_null_string_p : 2; - unsigned is_active : 1; - unsigned matched_something : 1; - unsigned ever_matched_something : 1; - } bits; -} register_info_type; - -#define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p) -#define IS_ACTIVE(R) ((R).bits.is_active) -#define MATCHED_SOMETHING(R) ((R).bits.matched_something) -#define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something) - - -/* Call this when have matched a real character; it sets `matched' flags - for the subexpressions which we are currently inside. Also records - that those subexprs have matched. */ -#define SET_REGS_MATCHED() \ - do \ - { \ - unsigned r; \ - for (r = lowest_active_reg; r <= highest_active_reg; r++) \ - { \ - MATCHED_SOMETHING (reg_info[r]) \ - = EVER_MATCHED_SOMETHING (reg_info[r]) \ - = 1; \ - } \ - } \ - while (0) - - -/* Registers are set to a sentinel when they haven't yet matched. */ -#define REG_UNSET_VALUE ((char *) -1) -#define REG_UNSET(e) ((e) == REG_UNSET_VALUE) - - - -/* How do we implement a missing MATCH_MAY_ALLOCATE? - We make the fail stack a global thing, and then grow it to - re_max_failures when we compile. */ -#ifndef MATCH_MAY_ALLOCATE -static fail_stack_type fail_stack; - -static const char ** regstart, ** regend; -static const char ** old_regstart, ** old_regend; -static const char **best_regstart, **best_regend; -static register_info_type *reg_info; -static const char **reg_dummy; -static register_info_type *reg_info_dummy; -#endif - - -/* Subroutine declarations and macros for regex_compile. */ - -static void store_op1 (), store_op2 (); -static void insert_op1 (), insert_op2 (); -static boolean at_begline_loc_p (), at_endline_loc_p (); -static boolean group_in_compile_stack (); -static reg_errcode_t compile_range (); - -/* Fetch the next character in the uncompiled pattern---translating it - if necessary. Also cast from a signed character in the constant - string passed to us by the user to an unsigned char that we can use - as an array index (in, e.g., `translate'). */ -#define PATFETCH(c) \ - do {if (p == pend) return REG_EEND; \ - c = (unsigned char) *p++; \ - if (translate) c = translate[c]; \ - } while (0) - -/* Fetch the next character in the uncompiled pattern, with no - translation. */ -#define PATFETCH_RAW(c) \ - do {if (p == pend) return REG_EEND; \ - c = (unsigned char) *p++; \ - } while (0) - -/* Go backwards one character in the pattern. */ -#define PATUNFETCH p-- - - -/* If `translate' is non-null, return translate[D], else just D. We - cast the subscript to translate because some data is declared as - `char *', to avoid warnings when a string constant is passed. But - when we use a character as a subscript we must make it unsigned. */ -#define TRANSLATE(d) (translate ? translate[(unsigned char) (d)] : (d)) - - -/* Macros for outputting the compiled pattern into `buffer'. */ - -/* If the buffer isn't allocated when it comes in, use this. */ -#define INIT_BUF_SIZE 32 - -/* Make sure we have at least N more bytes of space in buffer. */ -#define GET_BUFFER_SPACE(n) \ - while (b - bufp->buffer + (n) > bufp->allocated) \ - EXTEND_BUFFER () - -/* Make sure we have one more byte of buffer space and then add C to it. */ -#define BUF_PUSH(c) \ - do { \ - GET_BUFFER_SPACE (1); \ - *b++ = (unsigned char) (c); \ - } while (0) - - -/* Ensure we have two more bytes of buffer space and then append C1 and C2. */ -#define BUF_PUSH_2(c1, c2) \ - do { \ - GET_BUFFER_SPACE (2); \ - *b++ = (unsigned char) (c1); \ - *b++ = (unsigned char) (c2); \ - } while (0) - - -/* As with BUF_PUSH_2, except for three bytes. */ -#define BUF_PUSH_3(c1, c2, c3) \ - do { \ - GET_BUFFER_SPACE (3); \ - *b++ = (unsigned char) (c1); \ - *b++ = (unsigned char) (c2); \ - *b++ = (unsigned char) (c3); \ - } while (0) - - -/* Store a jump with opcode OP at LOC to location TO. We store a - relative address offset by the three bytes the jump itself occupies. */ -#define STORE_JUMP(op, loc, to) \ - store_op1 (op, loc, (to) - (loc) - 3) - -/* Likewise, for a two-argument jump. */ -#define STORE_JUMP2(op, loc, to, arg) \ - store_op2 (op, loc, (to) - (loc) - 3, arg) - -/* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */ -#define INSERT_JUMP(op, loc, to) \ - insert_op1 (op, loc, (to) - (loc) - 3, b) - -/* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */ -#define INSERT_JUMP2(op, loc, to, arg) \ - insert_op2 (op, loc, (to) - (loc) - 3, arg, b) - - -/* This is not an arbitrary limit: the arguments which represent offsets - into the pattern are two bytes long. So if 2^16 bytes turns out to - be too small, many things would have to change. */ -#define MAX_BUF_SIZE (1L << 16) - - -/* Extend the buffer by twice its current size via realloc and - reset the pointers that pointed into the old block to point to the - correct places in the new one. If extending the buffer results in it - being larger than MAX_BUF_SIZE, then flag memory exhausted. */ -#define EXTEND_BUFFER() \ - do { \ - unsigned char *old_buffer = bufp->buffer; \ - if (bufp->allocated == MAX_BUF_SIZE) \ - return REG_ESIZE; \ - bufp->allocated <<= 1; \ - if (bufp->allocated > MAX_BUF_SIZE) \ - bufp->allocated = MAX_BUF_SIZE; \ - bufp->buffer = (unsigned char *) realloc (bufp->buffer, bufp->allocated);\ - if (bufp->buffer == NULL) \ - return REG_ESPACE; \ - /* If the buffer moved, move all the pointers into it. */ \ - if (old_buffer != bufp->buffer) \ - { \ - b = (b - old_buffer) + bufp->buffer; \ - begalt = (begalt - old_buffer) + bufp->buffer; \ - if (fixup_alt_jump) \ - fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\ - if (laststart) \ - laststart = (laststart - old_buffer) + bufp->buffer; \ - if (pending_exact) \ - pending_exact = (pending_exact - old_buffer) + bufp->buffer; \ - } \ - } while (0) - - -/* Since we have one byte reserved for the register number argument to - {start,stop}_memory, the maximum number of groups we can report - things about is what fits in that byte. */ -#define MAX_REGNUM 255 - -/* But patterns can have more than `MAX_REGNUM' registers. We just - ignore the excess. */ -typedef unsigned regnum_t; - - -/* Macros for the compile stack. */ - -/* Since offsets can go either forwards or backwards, this type needs to - be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ -typedef int pattern_offset_t; - -typedef struct -{ - pattern_offset_t begalt_offset; - pattern_offset_t fixup_alt_jump; - pattern_offset_t inner_group_offset; - pattern_offset_t laststart_offset; - regnum_t regnum; -} compile_stack_elt_t; - - -typedef struct -{ - compile_stack_elt_t *stack; - unsigned size; - unsigned avail; /* Offset of next open position. */ -} compile_stack_type; - - -#define INIT_COMPILE_STACK_SIZE 32 - -#define COMPILE_STACK_EMPTY (compile_stack.avail == 0) -#define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size) - -/* The next available element. */ -#define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail]) - - -/* Set the bit for character C in a list. */ -#define SET_LIST_BIT(c) \ - (b[((unsigned char) (c)) / BYTEWIDTH] \ - |= 1 << (((unsigned char) c) % BYTEWIDTH)) - - -/* Get the next unsigned number in the uncompiled pattern. */ -#define GET_UNSIGNED_NUMBER(num) \ - { if (p != pend) \ - { \ - PATFETCH (c); \ - while (ISDIGIT (c)) \ - { \ - if (num < 0) \ - num = 0; \ - num = num * 10 + c - '0'; \ - if (p == pend) \ - break; \ - PATFETCH (c); \ - } \ - } \ - } - -#define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ - -#define IS_CHAR_CLASS(string) \ - (STREQ (string, "alpha") || STREQ (string, "upper") \ - || STREQ (string, "lower") || STREQ (string, "digit") \ - || STREQ (string, "alnum") || STREQ (string, "xdigit") \ - || STREQ (string, "space") || STREQ (string, "print") \ - || STREQ (string, "punct") || STREQ (string, "graph") \ - || STREQ (string, "cntrl") || STREQ (string, "blank")) - -/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. - Returns one of error codes defined in `regex.h', or zero for success. - - Assumes the `allocated' (and perhaps `buffer') and `translate' - fields are set in BUFP on entry. - - If it succeeds, results are put in BUFP (if it returns an error, the - contents of BUFP are undefined): - `buffer' is the compiled pattern; - `syntax' is set to SYNTAX; - `used' is set to the length of the compiled pattern; - `fastmap_accurate' is zero; - `re_nsub' is the number of subexpressions in PATTERN; - `not_bol' and `not_eol' are zero; - - The `fastmap' and `newline_anchor' fields are neither - examined nor set. */ - -static reg_errcode_t -regex_compile (pattern, size, syntax, bufp) - const char *pattern; - int size; - reg_syntax_t syntax; - struct re_pattern_buffer *bufp; -{ - /* We fetch characters from PATTERN here. Even though PATTERN is - `char *' (i.e., signed), we declare these variables as unsigned, so - they can be reliably used as array indices. */ - register unsigned char c, c1; - - /* A random tempory spot in PATTERN. */ - const char *p1; - - /* Points to the end of the buffer, where we should append. */ - register unsigned char *b; - - /* Keeps track of unclosed groups. */ - compile_stack_type compile_stack; - - /* Points to the current (ending) position in the pattern. */ - const char *p = pattern; - const char *pend = pattern + size; - - /* How to translate the characters in the pattern. */ - char *translate = bufp->translate; - - /* Address of the count-byte of the most recently inserted `exactn' - command. This makes it possible to tell if a new exact-match - character can be added to that command or if the character requires - a new `exactn' command. */ - unsigned char *pending_exact = 0; - - /* Address of start of the most recently finished expression. - This tells, e.g., postfix * where to find the start of its - operand. Reset at the beginning of groups and alternatives. */ - unsigned char *laststart = 0; - - /* Address of beginning of regexp, or inside of last group. */ - unsigned char *begalt; - - /* Place in the uncompiled pattern (i.e., the {) to - which to go back if the interval is invalid. */ - const char *beg_interval; - - /* Address of the place where a forward jump should go to the end of - the containing expression. Each alternative of an `or' -- except the - last -- ends with a forward jump of this sort. */ - unsigned char *fixup_alt_jump = 0; - - /* Counts open-groups as they are encountered. Remembered for the - matching close-group on the compile stack, so the same register - number is put in the stop_memory as the start_memory. */ - regnum_t regnum = 0; - -#ifdef DEBUG - DEBUG_PRINT1 ("\nCompiling pattern: "); - if (debug) - { - unsigned debug_count; - - for (debug_count = 0; debug_count < size; debug_count++) - printchar (pattern[debug_count]); - putchar ('\n'); - } -#endif /* DEBUG */ - - /* Initialize the compile stack. */ - compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t); - if (compile_stack.stack == NULL) - return REG_ESPACE; - - compile_stack.size = INIT_COMPILE_STACK_SIZE; - compile_stack.avail = 0; - - /* Initialize the pattern buffer. */ - bufp->syntax = syntax; - bufp->fastmap_accurate = 0; - bufp->not_bol = bufp->not_eol = 0; - - /* Set `used' to zero, so that if we return an error, the pattern - printer (for debugging) will think there's no pattern. We reset it - at the end. */ - bufp->used = 0; - - /* Always count groups, whether or not bufp->no_sub is set. */ - bufp->re_nsub = 0; - -#if !defined (emacs) && !defined (SYNTAX_TABLE) - /* Initialize the syntax table. */ - init_syntax_once (); -#endif - - if (bufp->allocated == 0) - { - if (bufp->buffer) - { /* If zero allocated, but buffer is non-null, try to realloc - enough space. This loses if buffer's address is bogus, but - that is the user's responsibility. */ - RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char); - } - else - { /* Caller did not allocate a buffer. Do it for them. */ - bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char); - } - if (!bufp->buffer) return REG_ESPACE; - - bufp->allocated = INIT_BUF_SIZE; - } - - begalt = b = bufp->buffer; - - /* Loop through the uncompiled pattern until we're at the end. */ - while (p != pend) - { - PATFETCH (c); - - switch (c) - { - case '^': - { - if ( /* If at start of pattern, it's an operator. */ - p == pattern + 1 - /* If context independent, it's an operator. */ - || syntax & RE_CONTEXT_INDEP_ANCHORS - /* Otherwise, depends on what's come before. */ - || at_begline_loc_p (pattern, p, syntax)) - BUF_PUSH (begline); - else - goto normal_char; - } - break; - - - case '$': - { - if ( /* If at end of pattern, it's an operator. */ - p == pend - /* If context independent, it's an operator. */ - || syntax & RE_CONTEXT_INDEP_ANCHORS - /* Otherwise, depends on what's next. */ - || at_endline_loc_p (p, pend, syntax)) - BUF_PUSH (endline); - else - goto normal_char; - } - break; - - - case '+': - case '?': - if ((syntax & RE_BK_PLUS_QM) - || (syntax & RE_LIMITED_OPS)) - goto normal_char; - handle_plus: - case '*': - /* If there is no previous pattern... */ - if (!laststart) - { - if (syntax & RE_CONTEXT_INVALID_OPS) - return REG_BADRPT; - else if (!(syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - } - - { - /* Are we optimizing this jump? */ - boolean keep_string_p = false; - - /* 1 means zero (many) matches is allowed. */ - char zero_times_ok = 0, many_times_ok = 0; - - /* If there is a sequence of repetition chars, collapse it - down to just one (the right one). We can't combine - interval operators with these because of, e.g., `a{2}*', - which should only match an even number of `a's. */ - - for (;;) - { - zero_times_ok |= c != '+'; - many_times_ok |= c != '?'; - - if (p == pend) - break; - - PATFETCH (c); - - if (c == '*' - || (!(syntax & RE_BK_PLUS_QM) && (c == '+' || c == '?'))) - ; - - else if (syntax & RE_BK_PLUS_QM && c == '\\') - { - if (p == pend) return REG_EESCAPE; - - PATFETCH (c1); - if (!(c1 == '+' || c1 == '?')) - { - PATUNFETCH; - PATUNFETCH; - break; - } - - c = c1; - } - else - { - PATUNFETCH; - break; - } - - /* If we get here, we found another repeat character. */ - } - - /* Star, etc. applied to an empty pattern is equivalent - to an empty pattern. */ - if (!laststart) - break; - - /* Now we know whether or not zero matches is allowed - and also whether or not two or more matches is allowed. */ - if (many_times_ok) - { /* More than one repetition is allowed, so put in at the - end a backward relative jump from `b' to before the next - jump we're going to put in below (which jumps from - laststart to after this jump). - - But if we are at the `*' in the exact sequence `.*\n', - insert an unconditional jump backwards to the ., - instead of the beginning of the loop. This way we only - push a failure point once, instead of every time - through the loop. */ - assert (p - 1 > pattern); - - /* Allocate the space for the jump. */ - GET_BUFFER_SPACE (3); - - /* We know we are not at the first character of the pattern, - because laststart was nonzero. And we've already - incremented `p', by the way, to be the character after - the `*'. Do we have to do something analogous here - for null bytes, because of RE_DOT_NOT_NULL? */ - if (TRANSLATE (*(p - 2)) == TRANSLATE ('.') - && zero_times_ok - && p < pend && TRANSLATE (*p) == TRANSLATE ('\n') - && !(syntax & RE_DOT_NEWLINE)) - { /* We have .*\n. */ - STORE_JUMP (jump, b, laststart); - keep_string_p = true; - } - else - /* Anything else. */ - STORE_JUMP (maybe_pop_jump, b, laststart - 3); - - /* We've added more stuff to the buffer. */ - b += 3; - } - - /* On failure, jump from laststart to b + 3, which will be the - end of the buffer after this jump is inserted. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump - : on_failure_jump, - laststart, b + 3); - pending_exact = 0; - b += 3; - - if (!zero_times_ok) - { - /* At least one repetition is required, so insert a - `dummy_failure_jump' before the initial - `on_failure_jump' instruction of the loop. This - effects a skip over that instruction the first time - we hit that loop. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6); - b += 3; - } - } - break; - - - case '.': - laststart = b; - BUF_PUSH (anychar); - break; - - - case '[': - { - boolean had_char_class = false; - - if (p == pend) return REG_EBRACK; - - /* Ensure that we have enough space to push a charset: the - opcode, the length count, and the bitset; 34 bytes in all. */ - GET_BUFFER_SPACE (34); - - laststart = b; - - /* We test `*p == '^' twice, instead of using an if - statement, so we only need one BUF_PUSH. */ - BUF_PUSH (*p == '^' ? charset_not : charset); - if (*p == '^') - p++; - - /* Remember the first position in the bracket expression. */ - p1 = p; - - /* Push the number of bytes in the bitmap. */ - BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH); - - /* Clear the whole map. */ - bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH); - - /* charset_not matches newline according to a syntax bit. */ - if ((re_opcode_t) b[-2] == charset_not - && (syntax & RE_HAT_LISTS_NOT_NEWLINE)) - SET_LIST_BIT ('\n'); - - /* Read in characters and ranges, setting map bits. */ - for (;;) - { - if (p == pend) return REG_EBRACK; - - PATFETCH (c); - - /* \ might escape characters inside [...] and [^...]. */ - if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\') - { - if (p == pend) return REG_EESCAPE; - - PATFETCH (c1); - SET_LIST_BIT (c1); - continue; - } - - /* Could be the end of the bracket expression. If it's - not (i.e., when the bracket expression is `[]' so - far), the ']' character bit gets set way below. */ - if (c == ']' && p != p1 + 1) - break; - - /* Look ahead to see if it's a range when the last thing - was a character class. */ - if (had_char_class && c == '-' && *p != ']') - return REG_ERANGE; - - /* Look ahead to see if it's a range when the last thing - was a character: if this is a hyphen not at the - beginning or the end of a list, then it's the range - operator. */ - if (c == '-' - && !(p - 2 >= pattern && p[-2] == '[') - && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^') - && *p != ']') - { - reg_errcode_t ret - = compile_range (&p, pend, translate, syntax, b); - if (ret != REG_NOERROR) return ret; - } - - else if (p[0] == '-' && p[1] != ']') - { /* This handles ranges made up of characters only. */ - reg_errcode_t ret; - - /* Move past the `-'. */ - PATFETCH (c1); - - ret = compile_range (&p, pend, translate, syntax, b); - if (ret != REG_NOERROR) return ret; - } - - /* See if we're at the beginning of a possible character - class. */ - - else if (syntax & RE_CHAR_CLASSES && c == '[' && *p == ':') - { /* Leave room for the null. */ - char str[CHAR_CLASS_MAX_LENGTH + 1]; - - PATFETCH (c); - c1 = 0; - - /* If pattern is `[[:'. */ - if (p == pend) return REG_EBRACK; - - for (;;) - { - PATFETCH (c); - if (c == ':' || c == ']' || p == pend - || c1 == CHAR_CLASS_MAX_LENGTH) - break; - str[c1++] = c; - } - str[c1] = '\0'; - - /* If isn't a word bracketed by `[:' and:`]': - undo the ending character, the letters, and leave - the leading `:' and `[' (but set bits for them). */ - if (c == ':' && *p == ']') - { - int ch; - boolean is_alnum = STREQ (str, "alnum"); - boolean is_alpha = STREQ (str, "alpha"); - boolean is_blank = STREQ (str, "blank"); - boolean is_cntrl = STREQ (str, "cntrl"); - boolean is_digit = STREQ (str, "digit"); - boolean is_graph = STREQ (str, "graph"); - boolean is_lower = STREQ (str, "lower"); - boolean is_print = STREQ (str, "print"); - boolean is_punct = STREQ (str, "punct"); - boolean is_space = STREQ (str, "space"); - boolean is_upper = STREQ (str, "upper"); - boolean is_xdigit = STREQ (str, "xdigit"); - - if (!IS_CHAR_CLASS (str)) return REG_ECTYPE; - - /* Throw away the ] at the end of the character - class. */ - PATFETCH (c); - - if (p == pend) return REG_EBRACK; - - for (ch = 0; ch < 1 << BYTEWIDTH; ch++) - { - if ( (is_alnum && ISALNUM (ch)) - || (is_alpha && ISALPHA (ch)) - || (is_blank && ISBLANK (ch)) - || (is_cntrl && ISCNTRL (ch)) - || (is_digit && ISDIGIT (ch)) - || (is_graph && ISGRAPH (ch)) - || (is_lower && ISLOWER (ch)) - || (is_print && ISPRINT (ch)) - || (is_punct && ISPUNCT (ch)) - || (is_space && ISSPACE (ch)) - || (is_upper && ISUPPER (ch)) - || (is_xdigit && ISXDIGIT (ch))) - SET_LIST_BIT (ch); - } - had_char_class = true; - } - else - { - c1++; - while (c1--) - PATUNFETCH; - SET_LIST_BIT ('['); - SET_LIST_BIT (':'); - had_char_class = false; - } - } - else - { - had_char_class = false; - SET_LIST_BIT (c); - } - } - - /* Discard any (non)matching list bytes that are all 0 at the - end of the map. Decrease the map-length byte too. */ - while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) - b[-1]--; - b += b[-1]; - } - break; - - - case '(': - if (syntax & RE_NO_BK_PARENS) - goto handle_open; - else - goto normal_char; - - - case ')': - if (syntax & RE_NO_BK_PARENS) - goto handle_close; - else - goto normal_char; - - - case '\n': - if (syntax & RE_NEWLINE_ALT) - goto handle_alt; - else - goto normal_char; - - - case '|': - if (syntax & RE_NO_BK_VBAR) - goto handle_alt; - else - goto normal_char; - - - case '{': - if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES) - goto handle_interval; - else - goto normal_char; - - - case '\\': - if (p == pend) return REG_EESCAPE; - - /* Do not translate the character after the \, so that we can - distinguish, e.g., \B from \b, even if we normally would - translate, e.g., B to b. */ - PATFETCH_RAW (c); - - switch (c) - { - case '(': - if (syntax & RE_NO_BK_PARENS) - goto normal_backslash; - - handle_open: - bufp->re_nsub++; - regnum++; - - if (COMPILE_STACK_FULL) - { - RETALLOC (compile_stack.stack, compile_stack.size << 1, - compile_stack_elt_t); - if (compile_stack.stack == NULL) return REG_ESPACE; - - compile_stack.size <<= 1; - } - - /* These are the values to restore when we hit end of this - group. They are all relative offsets, so that if the - whole pattern moves because of realloc, they will still - be valid. */ - COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer; - COMPILE_STACK_TOP.fixup_alt_jump - = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0; - COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer; - COMPILE_STACK_TOP.regnum = regnum; - - /* We will eventually replace the 0 with the number of - groups inner to this one. But do not push a - start_memory for groups beyond the last one we can - represent in the compiled pattern. */ - if (regnum <= MAX_REGNUM) - { - COMPILE_STACK_TOP.inner_group_offset = b - bufp->buffer + 2; - BUF_PUSH_3 (start_memory, regnum, 0); - } - - compile_stack.avail++; - - fixup_alt_jump = 0; - laststart = 0; - begalt = b; - /* If we've reached MAX_REGNUM groups, then this open - won't actually generate any code, so we'll have to - clear pending_exact explicitly. */ - pending_exact = 0; - break; - - - case ')': - if (syntax & RE_NO_BK_PARENS) goto normal_backslash; - - if (COMPILE_STACK_EMPTY) - if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) - goto normal_backslash; - else - return REG_ERPAREN; - - handle_close: - if (fixup_alt_jump) - { /* Push a dummy failure point at the end of the - alternative for a possible future - `pop_failure_jump' to pop. See comments at - `push_dummy_failure' in `re_match_2'. */ - BUF_PUSH (push_dummy_failure); - - /* We allocated space for this jump when we assigned - to `fixup_alt_jump', in the `handle_alt' case below. */ - STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1); - } - - /* See similar code for backslashed left paren above. */ - if (COMPILE_STACK_EMPTY) - if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) - goto normal_char; - else - return REG_ERPAREN; - - /* Since we just checked for an empty stack above, this - ``can't happen''. */ - assert (compile_stack.avail != 0); - { - /* We don't just want to restore into `regnum', because - later groups should continue to be numbered higher, - as in `(ab)c(de)' -- the second group is #2. */ - regnum_t this_group_regnum; - - compile_stack.avail--; - begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset; - fixup_alt_jump - = COMPILE_STACK_TOP.fixup_alt_jump - ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 - : 0; - laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; - this_group_regnum = COMPILE_STACK_TOP.regnum; - /* If we've reached MAX_REGNUM groups, then this open - won't actually generate any code, so we'll have to - clear pending_exact explicitly. */ - pending_exact = 0; - - /* We're at the end of the group, so now we know how many - groups were inside this one. */ - if (this_group_regnum <= MAX_REGNUM) - { - unsigned char *inner_group_loc - = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset; - - *inner_group_loc = regnum - this_group_regnum; - BUF_PUSH_3 (stop_memory, this_group_regnum, - regnum - this_group_regnum); - } - } - break; - - - case '|': /* `\|'. */ - if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR) - goto normal_backslash; - handle_alt: - if (syntax & RE_LIMITED_OPS) - goto normal_char; - - /* Insert before the previous alternative a jump which - jumps to this alternative if the former fails. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (on_failure_jump, begalt, b + 6); - pending_exact = 0; - b += 3; - - /* The alternative before this one has a jump after it - which gets executed if it gets matched. Adjust that - jump so it will jump to this alternative's analogous - jump (put in below, which in turn will jump to the next - (if any) alternative's such jump, etc.). The last such - jump jumps to the correct final destination. A picture: - _____ _____ - | | | | - | v | v - a | b | c - - If we are at `b', then fixup_alt_jump right now points to a - three-byte space after `a'. We'll put in the jump, set - fixup_alt_jump to right after `b', and leave behind three - bytes which we'll fill in when we get to after `c'. */ - - if (fixup_alt_jump) - STORE_JUMP (jump_past_alt, fixup_alt_jump, b); - - /* Mark and leave space for a jump after this alternative, - to be filled in later either by next alternative or - when know we're at the end of a series of alternatives. */ - fixup_alt_jump = b; - GET_BUFFER_SPACE (3); - b += 3; - - laststart = 0; - begalt = b; - break; - - - case '{': - /* If \{ is a literal. */ - if (!(syntax & RE_INTERVALS) - /* If we're at `\{' and it's not the open-interval - operator. */ - || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) - || (p - 2 == pattern && p == pend)) - goto normal_backslash; - - handle_interval: - { - /* If got here, then the syntax allows intervals. */ - - /* At least (most) this many matches must be made. */ - int lower_bound = -1, upper_bound = -1; - - beg_interval = p - 1; - - if (p == pend) - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_EBRACE; - } - - GET_UNSIGNED_NUMBER (lower_bound); - - if (c == ',') - { - GET_UNSIGNED_NUMBER (upper_bound); - if (upper_bound < 0) upper_bound = RE_DUP_MAX; - } - else - /* Interval such as `{1}' => match exactly once. */ - upper_bound = lower_bound; - - if (lower_bound < 0 || upper_bound > RE_DUP_MAX - || lower_bound > upper_bound) - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_BADBR; - } - - if (!(syntax & RE_NO_BK_BRACES)) - { - if (c != '\\') return REG_EBRACE; - - PATFETCH (c); - } - - if (c != '}') - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_BADBR; - } - - /* We just parsed a valid interval. */ - - /* If it's invalid to have no preceding re. */ - if (!laststart) - { - if (syntax & RE_CONTEXT_INVALID_OPS) - return REG_BADRPT; - else if (syntax & RE_CONTEXT_INDEP_OPS) - laststart = b; - else - goto unfetch_interval; - } - - /* If the upper bound is zero, don't want to succeed at - all; jump from `laststart' to `b + 3', which will be - the end of the buffer after we insert the jump. */ - if (upper_bound == 0) - { - GET_BUFFER_SPACE (3); - INSERT_JUMP (jump, laststart, b + 3); - b += 3; - } - - /* Otherwise, we have a nontrivial interval. When - we're all done, the pattern will look like: - set_number_at - set_number_at - succeed_n - - jump_n - (The upper bound and `jump_n' are omitted if - `upper_bound' is 1, though.) */ - else - { /* If the upper bound is > 1, we need to insert - more at the end of the loop. */ - unsigned nbytes = 10 + (upper_bound > 1) * 10; - - GET_BUFFER_SPACE (nbytes); - - /* Initialize lower bound of the `succeed_n', even - though it will be set during matching by its - attendant `set_number_at' (inserted next), - because `re_compile_fastmap' needs to know. - Jump to the `jump_n' we might insert below. */ - INSERT_JUMP2 (succeed_n, laststart, - b + 5 + (upper_bound > 1) * 5, - lower_bound); - b += 5; - - /* Code to initialize the lower bound. Insert - before the `succeed_n'. The `5' is the last two - bytes of this `set_number_at', plus 3 bytes of - the following `succeed_n'. */ - insert_op2 (set_number_at, laststart, 5, lower_bound, b); - b += 5; - - if (upper_bound > 1) - { /* More than one repetition is allowed, so - append a backward jump to the `succeed_n' - that starts this interval. - - When we've reached this during matching, - we'll have matched the interval once, so - jump back only `upper_bound - 1' times. */ - STORE_JUMP2 (jump_n, b, laststart + 5, - upper_bound - 1); - b += 5; - - /* The location we want to set is the second - parameter of the `jump_n'; that is `b-2' as - an absolute address. `laststart' will be - the `set_number_at' we're about to insert; - `laststart+3' the number to set, the source - for the relative address. But we are - inserting into the middle of the pattern -- - so everything is getting moved up by 5. - Conclusion: (b - 2) - (laststart + 3) + 5, - i.e., b - laststart. - - We insert this at the beginning of the loop - so that if we fail during matching, we'll - reinitialize the bounds. */ - insert_op2 (set_number_at, laststart, b - laststart, - upper_bound - 1, b); - b += 5; - } - } - pending_exact = 0; - beg_interval = NULL; - } - break; - - unfetch_interval: - /* If an invalid interval, match the characters as literals. */ - assert (beg_interval); - p = beg_interval; - beg_interval = NULL; - - /* normal_char and normal_backslash need `c'. */ - PATFETCH (c); - - if (!(syntax & RE_NO_BK_BRACES)) - { - if (p > pattern && p[-1] == '\\') - goto normal_backslash; - } - goto normal_char; - -#ifdef emacs - /* There is no way to specify the before_dot and after_dot - operators. rms says this is ok. --karl */ - case '=': - BUF_PUSH (at_dot); - break; - - case 's': - laststart = b; - PATFETCH (c); - BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]); - break; - - case 'S': - laststart = b; - PATFETCH (c); - BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]); - break; -#endif /* emacs */ - - - case 'w': - laststart = b; - BUF_PUSH (wordchar); - break; - - - case 'W': - laststart = b; - BUF_PUSH (notwordchar); - break; - - - case '<': - BUF_PUSH (wordbeg); - break; - - case '>': - BUF_PUSH (wordend); - break; - - case 'b': - BUF_PUSH (wordbound); - break; - - case 'B': - BUF_PUSH (notwordbound); - break; - - case '`': - BUF_PUSH (begbuf); - break; - - case '\'': - BUF_PUSH (endbuf); - break; - - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - if (syntax & RE_NO_BK_REFS) - goto normal_char; - - c1 = c - '0'; - - if (c1 > regnum) - return REG_ESUBREG; - - /* Can't back reference to a subexpression if inside of it. */ - if (group_in_compile_stack (compile_stack, c1)) - goto normal_char; - - laststart = b; - BUF_PUSH_2 (duplicate, c1); - break; - - - case '+': - case '?': - if (syntax & RE_BK_PLUS_QM) - goto handle_plus; - else - goto normal_backslash; - - default: - normal_backslash: - /* You might think it would be useful for \ to mean - not to translate; but if we don't translate it - it will never match anything. */ - c = TRANSLATE (c); - goto normal_char; - } - break; - - - default: - /* Expects the character in `c'. */ - normal_char: - /* If no exactn currently being built. */ - if (!pending_exact - - /* If last exactn not at current position. */ - || pending_exact + *pending_exact + 1 != b - - /* We have only one byte following the exactn for the count. */ - || *pending_exact == (1 << BYTEWIDTH) - 1 - - /* If followed by a repetition operator. */ - || *p == '*' || *p == '^' - || ((syntax & RE_BK_PLUS_QM) - ? *p == '\\' && (p[1] == '+' || p[1] == '?') - : (*p == '+' || *p == '?')) - || ((syntax & RE_INTERVALS) - && ((syntax & RE_NO_BK_BRACES) - ? *p == '{' - : (p[0] == '\\' && p[1] == '{')))) - { - /* Start building a new exactn. */ - - laststart = b; - - BUF_PUSH_2 (exactn, 0); - pending_exact = b - 1; - } - - BUF_PUSH (c); - (*pending_exact)++; - break; - } /* switch (c) */ - } /* while p != pend */ - - - /* Through the pattern now. */ - - if (fixup_alt_jump) - STORE_JUMP (jump_past_alt, fixup_alt_jump, b); - - if (!COMPILE_STACK_EMPTY) - return REG_EPAREN; - - free (compile_stack.stack); - - /* We have succeeded; set the length of the buffer. */ - bufp->used = b - bufp->buffer; - -#ifdef DEBUG - if (debug) - { - DEBUG_PRINT1 ("\nCompiled pattern: \n"); - print_compiled_pattern (bufp); - } -#endif /* DEBUG */ - -#ifndef MATCH_MAY_ALLOCATE - /* Initialize the failure stack to the largest possible stack. This - isn't necessary unless we're trying to avoid calling alloca in - the search and match routines. */ - { - int num_regs = bufp->re_nsub + 1; - - /* Since DOUBLE_FAIL_STACK refuses to double only if the current size - is strictly greater than re_max_failures, the largest possible stack - is 2 * re_max_failures failure points. */ - fail_stack.size = (2 * re_max_failures * MAX_FAILURE_ITEMS); - if (fail_stack.stack) - fail_stack.stack = - (fail_stack_elt_t *) realloc (fail_stack.stack, - (fail_stack.size - * sizeof (fail_stack_elt_t))); - else - fail_stack.stack = - (fail_stack_elt_t *) malloc (fail_stack.size - * sizeof (fail_stack_elt_t)); - - /* Initialize some other variables the matcher uses. */ - RETALLOC_IF (regstart, num_regs, const char *); - RETALLOC_IF (regend, num_regs, const char *); - RETALLOC_IF (old_regstart, num_regs, const char *); - RETALLOC_IF (old_regend, num_regs, const char *); - RETALLOC_IF (best_regstart, num_regs, const char *); - RETALLOC_IF (best_regend, num_regs, const char *); - RETALLOC_IF (reg_info, num_regs, register_info_type); - RETALLOC_IF (reg_dummy, num_regs, const char *); - RETALLOC_IF (reg_info_dummy, num_regs, register_info_type); - } -#endif - - return REG_NOERROR; -} /* regex_compile */ - -/* Subroutines for `regex_compile'. */ - -/* Store OP at LOC followed by two-byte integer parameter ARG. */ - -static void -store_op1 (op, loc, arg) - re_opcode_t op; - unsigned char *loc; - int arg; -{ - *loc = (unsigned char) op; - STORE_NUMBER (loc + 1, arg); -} - - -/* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */ - -static void -store_op2 (op, loc, arg1, arg2) - re_opcode_t op; - unsigned char *loc; - int arg1, arg2; -{ - *loc = (unsigned char) op; - STORE_NUMBER (loc + 1, arg1); - STORE_NUMBER (loc + 3, arg2); -} - - -/* Copy the bytes from LOC to END to open up three bytes of space at LOC - for OP followed by two-byte integer parameter ARG. */ - -static void -insert_op1 (op, loc, arg, end) - re_opcode_t op; - unsigned char *loc; - int arg; - unsigned char *end; -{ - register unsigned char *pfrom = end; - register unsigned char *pto = end + 3; - - while (pfrom != loc) - *--pto = *--pfrom; - - store_op1 (op, loc, arg); -} - - -/* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */ - -static void -insert_op2 (op, loc, arg1, arg2, end) - re_opcode_t op; - unsigned char *loc; - int arg1, arg2; - unsigned char *end; -{ - register unsigned char *pfrom = end; - register unsigned char *pto = end + 5; - - while (pfrom != loc) - *--pto = *--pfrom; - - store_op2 (op, loc, arg1, arg2); -} - - -/* P points to just after a ^ in PATTERN. Return true if that ^ comes - after an alternative or a begin-subexpression. We assume there is at - least one character before the ^. */ - -static boolean -at_begline_loc_p (pattern, p, syntax) - const char *pattern, *p; - reg_syntax_t syntax; -{ - const char *prev = p - 2; - boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; - - return - /* After a subexpression? */ - (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) - /* After an alternative? */ - || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash)); -} - - -/* The dual of at_begline_loc_p. This one is for $. We assume there is - at least one character after the $, i.e., `P < PEND'. */ - -static boolean -at_endline_loc_p (p, pend, syntax) - const char *p, *pend; - int syntax; -{ - const char *next = p; - boolean next_backslash = *next == '\\'; - const char *next_next = p + 1 < pend ? p + 1 : NULL; - - return - /* Before a subexpression? */ - (syntax & RE_NO_BK_PARENS ? *next == ')' - : next_backslash && next_next && *next_next == ')') - /* Before an alternative? */ - || (syntax & RE_NO_BK_VBAR ? *next == '|' - : next_backslash && next_next && *next_next == '|'); -} - - -/* Returns true if REGNUM is in one of COMPILE_STACK's elements and - false if it's not. */ - -static boolean -group_in_compile_stack (compile_stack, regnum) - compile_stack_type compile_stack; - regnum_t regnum; -{ - int this_element; - - for (this_element = compile_stack.avail - 1; - this_element >= 0; - this_element--) - if (compile_stack.stack[this_element].regnum == regnum) - return true; - - return false; -} - - -/* Read the ending character of a range (in a bracket expression) from the - uncompiled pattern *P_PTR (which ends at PEND). We assume the - starting character is in `P[-2]'. (`P[-1]' is the character `-'.) - Then we set the translation of all bits between the starting and - ending characters (inclusive) in the compiled pattern B. - - Return an error code. - - We use these short variable names so we can use the same macros as - `regex_compile' itself. */ - -static reg_errcode_t -compile_range (p_ptr, pend, translate, syntax, b) - const char **p_ptr, *pend; - char *translate; - reg_syntax_t syntax; - unsigned char *b; -{ - unsigned this_char; - - const char *p = *p_ptr; - int range_start, range_end; - - if (p == pend) - return REG_ERANGE; - - /* Even though the pattern is a signed `char *', we need to fetch - with unsigned char *'s; if the high bit of the pattern character - is set, the range endpoints will be negative if we fetch using a - signed char *. - - We also want to fetch the endpoints without translating them; the - appropriate translation is done in the bit-setting loop below. */ - range_start = ((unsigned char *) p)[-2]; - range_end = ((unsigned char *) p)[0]; - - /* Have to increment the pointer into the pattern string, so the - caller isn't still at the ending character. */ - (*p_ptr)++; - - /* If the start is after the end, the range is empty. */ - if (range_start > range_end) - return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR; - - /* Here we see why `this_char' has to be larger than an `unsigned - char' -- the range is inclusive, so if `range_end' == 0xff - (assuming 8-bit characters), we would otherwise go into an infinite - loop, since all characters <= 0xff. */ - for (this_char = range_start; this_char <= range_end; this_char++) - { - SET_LIST_BIT (TRANSLATE (this_char)); - } - - return REG_NOERROR; -} - -/* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in - BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible - characters can start a string that matches the pattern. This fastmap - is used by re_search to skip quickly over impossible starting points. - - The caller must supply the address of a (1 << BYTEWIDTH)-byte data - area as BUFP->fastmap. - - We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in - the pattern buffer. - - Returns 0 if we succeed, -2 if an internal error. */ - -int -re_compile_fastmap (bufp) - struct re_pattern_buffer *bufp; -{ - int j, k; -#ifdef MATCH_MAY_ALLOCATE - fail_stack_type fail_stack; -#endif -#ifndef REGEX_MALLOC - char *destination; -#endif - /* We don't push any register information onto the failure stack. */ - unsigned num_regs = 0; - - register char *fastmap = bufp->fastmap; - unsigned char *pattern = bufp->buffer; - unsigned long size = bufp->used; - unsigned char *p = pattern; - register unsigned char *pend = pattern + size; - - /* Assume that each path through the pattern can be null until - proven otherwise. We set this false at the bottom of switch - statement, to which we get only if a particular path doesn't - match the empty string. */ - boolean path_can_be_null = true; - - /* We aren't doing a `succeed_n' to begin with. */ - boolean succeed_n_p = false; - - assert (fastmap != NULL && p != NULL); - - INIT_FAIL_STACK (); - bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */ - bufp->fastmap_accurate = 1; /* It will be when we're done. */ - bufp->can_be_null = 0; - - while (p != pend || !FAIL_STACK_EMPTY ()) - { - if (p == pend) - { - bufp->can_be_null |= path_can_be_null; - - /* Reset for next path. */ - path_can_be_null = true; - - p = fail_stack.stack[--fail_stack.avail]; - } - - /* We should never be about to go beyond the end of the pattern. */ - assert (p < pend); - -#ifdef SWITCH_ENUM_BUG - switch ((int) ((re_opcode_t) *p++)) -#else - switch ((re_opcode_t) *p++) -#endif - { - - /* I guess the idea here is to simply not bother with a fastmap - if a backreference is used, since it's too hard to figure out - the fastmap for the corresponding group. Setting - `can_be_null' stops `re_search_2' from using the fastmap, so - that is all we do. */ - case duplicate: - bufp->can_be_null = 1; - return 0; - - - /* Following are the cases which match a character. These end - with `break'. */ - - case exactn: - fastmap[p[1]] = 1; - break; - - - case charset: - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) - fastmap[j] = 1; - break; - - - case charset_not: - /* Chars beyond end of map must be allowed. */ - for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) - fastmap[j] = 1; - - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) - fastmap[j] = 1; - break; - - - case wordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == Sword) - fastmap[j] = 1; - break; - - - case notwordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != Sword) - fastmap[j] = 1; - break; - - - case anychar: - /* `.' matches anything ... */ - for (j = 0; j < (1 << BYTEWIDTH); j++) - fastmap[j] = 1; - - /* ... except perhaps newline. */ - if (!(bufp->syntax & RE_DOT_NEWLINE)) - fastmap['\n'] = 0; - - /* Return if we have already set `can_be_null'; if we have, - then the fastmap is irrelevant. Something's wrong here. */ - else if (bufp->can_be_null) - return 0; - - /* Otherwise, have to check alternative paths. */ - break; - - -#ifdef emacs - case syntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == (enum syntaxcode) k) - fastmap[j] = 1; - break; - - - case notsyntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != (enum syntaxcode) k) - fastmap[j] = 1; - break; - - - /* All cases after this match the empty string. These end with - `continue'. */ - - - case before_dot: - case at_dot: - case after_dot: - continue; -#endif /* not emacs */ - - - case no_op: - case begline: - case endline: - case begbuf: - case endbuf: - case wordbound: - case notwordbound: - case wordbeg: - case wordend: - case push_dummy_failure: - continue; - - - case jump_n: - case pop_failure_jump: - case maybe_pop_jump: - case jump: - case jump_past_alt: - case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); - p += j; - if (j > 0) - continue; - - /* Jump backward implies we just went through the body of a - loop and matched nothing. Opcode jumped to should be - `on_failure_jump' or `succeed_n'. Just treat it like an - ordinary jump. For a * loop, it has pushed its failure - point already; if so, discard that as redundant. */ - if ((re_opcode_t) *p != on_failure_jump - && (re_opcode_t) *p != succeed_n) - continue; - - p++; - EXTRACT_NUMBER_AND_INCR (j, p); - p += j; - - /* If what's on the stack is where we are now, pop it. */ - if (!FAIL_STACK_EMPTY () - && fail_stack.stack[fail_stack.avail - 1] == p) - fail_stack.avail--; - - continue; - - - case on_failure_jump: - case on_failure_keep_string_jump: - handle_on_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); - - /* For some patterns, e.g., `(a?)?', `p+j' here points to the - end of the pattern. We don't want to push such a point, - since when we restore it above, entering the switch will - increment `p' past the end of the pattern. We don't need - to push such a point since we obviously won't find any more - fastmap entries beyond `pend'. Such a pattern can match - the null string, though. */ - if (p + j < pend) - { - if (!PUSH_PATTERN_OP (p + j, fail_stack)) - return -2; - } - else - bufp->can_be_null = 1; - - if (succeed_n_p) - { - EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */ - succeed_n_p = false; - } - - continue; - - - case succeed_n: - /* Get to the number of times to succeed. */ - p += 2; - - /* Increment p past the n for when k != 0. */ - EXTRACT_NUMBER_AND_INCR (k, p); - if (k == 0) - { - p -= 4; - succeed_n_p = true; /* Spaghetti code alert. */ - goto handle_on_failure_jump; - } - continue; - - - case set_number_at: - p += 4; - continue; - - - case start_memory: - case stop_memory: - p += 2; - continue; - - - default: - abort (); /* We have listed all the cases. */ - } /* switch *p++ */ - - /* Getting here means we have found the possible starting - characters for one path of the pattern -- and that the empty - string does not match. We need not follow this path further. - Instead, look at the next alternative (remembered on the - stack), or quit if no more. The test at the top of the loop - does these things. */ - path_can_be_null = false; - p = pend; - } /* while p */ - - /* Set `can_be_null' for the last path (also the first path, if the - pattern is empty). */ - bufp->can_be_null |= path_can_be_null; - return 0; -} /* re_compile_fastmap */ - -/* Set REGS to hold NUM_REGS registers, storing them in STARTS and - ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use - this memory for recording register information. STARTS and ENDS - must be allocated using the malloc library routine, and must each - be at least NUM_REGS * sizeof (regoff_t) bytes long. - - If NUM_REGS == 0, then subsequent matches should allocate their own - register data. - - Unless this function is called, the first search or match using - PATTERN_BUFFER will allocate its own register data, without - freeing the old data. */ - -void -re_set_registers (bufp, regs, num_regs, starts, ends) - struct re_pattern_buffer *bufp; - struct re_registers *regs; - unsigned num_regs; - regoff_t *starts, *ends; -{ - if (num_regs) - { - bufp->regs_allocated = REGS_REALLOCATE; - regs->num_regs = num_regs; - regs->start = starts; - regs->end = ends; - } - else - { - bufp->regs_allocated = REGS_UNALLOCATED; - regs->num_regs = 0; - regs->start = regs->end = (regoff_t) 0; - } -} - -/* Searching routines. */ - -/* Like re_search_2, below, but only one string is specified, and - doesn't let you say where to stop matching. */ - -int -re_search (bufp, string, size, startpos, range, regs) - struct re_pattern_buffer *bufp; - const char *string; - int size, startpos, range; - struct re_registers *regs; -{ - return re_search_2 (bufp, NULL, 0, string, size, startpos, range, - regs, size); -} - - -/* Using the compiled pattern in BUFP->buffer, first tries to match the - virtual concatenation of STRING1 and STRING2, starting first at index - STARTPOS, then at STARTPOS + 1, and so on. - - STRING1 and STRING2 have length SIZE1 and SIZE2, respectively. - - RANGE is how far to scan while trying to match. RANGE = 0 means try - only at STARTPOS; in general, the last start tried is STARTPOS + - RANGE. - - In REGS, return the indices of the virtual concatenation of STRING1 - and STRING2 that matched the entire BUFP->buffer and its contained - subexpressions. - - Do not consider matching one past the index STOP in the virtual - concatenation of STRING1 and STRING2. - - We return either the position in the strings at which the match was - found, -1 if no match, or -2 if error (such as failure - stack overflow). */ - -int -re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int startpos; - int range; - struct re_registers *regs; - int stop; -{ - int val; - register char *fastmap = bufp->fastmap; - register char *translate = bufp->translate; - int total_size = size1 + size2; - int endpos = startpos + range; - - /* Check for out-of-range STARTPOS. */ - if (startpos < 0 || startpos > total_size) - return -1; - - /* Fix up RANGE if it might eventually take us outside - the virtual concatenation of STRING1 and STRING2. */ - if (endpos < -1) - range = -1 - startpos; - else if (endpos > total_size) - range = total_size - startpos; - - /* If the search isn't to be a backwards one, don't waste time in a - search for a pattern that must be anchored. */ - if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0) - { - if (startpos > 0) - return -1; - else - range = 1; - } - - /* Update the fastmap now if not correct already. */ - if (fastmap && !bufp->fastmap_accurate) - if (re_compile_fastmap (bufp) == -2) - return -2; - - /* Loop through the string, looking for a place to start matching. */ - for (;;) - { - /* If a fastmap is supplied, skip quickly over characters that - cannot be the start of a match. If the pattern can match the - null string, however, we don't need to skip characters; we want - the first null string. */ - if (fastmap && startpos < total_size && !bufp->can_be_null) - { - if (range > 0) /* Searching forwards. */ - { - register const char *d; - register int lim = 0; - int irange = range; - - if (startpos < size1 && startpos + range >= size1) - lim = range - (size1 - startpos); - - d = (startpos >= size1 ? string2 - size1 : string1) + startpos; - - /* Written out as an if-else to avoid testing `translate' - inside the loop. */ - if (translate) - while (range > lim - && !fastmap[(unsigned char) - translate[(unsigned char) *d++]]) - range--; - else - while (range > lim && !fastmap[(unsigned char) *d++]) - range--; - - startpos += irange - range; - } - else /* Searching backwards. */ - { - register char c = (size1 == 0 || startpos >= size1 - ? string2[startpos - size1] - : string1[startpos]); - - if (!fastmap[(unsigned char) TRANSLATE (c)]) - goto advance; - } - } - - /* If can't match the null string, and that's all we have left, fail. */ - if (range >= 0 && startpos == total_size && fastmap - && !bufp->can_be_null) - return -1; - - val = re_match_2 (bufp, string1, size1, string2, size2, - startpos, regs, stop); - if (val >= 0) - return startpos; - - if (val == -2) - return -2; - - advance: - if (!range) - break; - else if (range > 0) - { - range--; - startpos++; - } - else - { - range++; - startpos--; - } - } - return -1; -} /* re_search_2 */ - -/* Declarations and macros for re_match_2. */ - -static int bcmp_translate (); -static boolean alt_match_null_string_p (), - common_op_match_null_string_p (), - group_match_null_string_p (); - -/* This converts PTR, a pointer into one of the search strings `string1' - and `string2' into an offset from the beginning of that string. */ -#define POINTER_TO_OFFSET(ptr) \ - (FIRST_STRING_P (ptr) \ - ? ((regoff_t) ((ptr) - string1)) \ - : ((regoff_t) ((ptr) - string2 + size1))) - -/* Macros for dealing with the split strings in re_match_2. */ - -#define MATCHING_IN_FIRST_STRING (dend == end_match_1) - -/* Call before fetching a character with *d. This switches over to - string2 if necessary. */ -#define PREFETCH() \ - while (d == dend) \ - { \ - /* End of string2 => fail. */ \ - if (dend == end_match_2) \ - goto fail; \ - /* End of string1 => advance to string2. */ \ - d = string2; \ - dend = end_match_2; \ - } - - -/* Test if at very beginning or at very end of the virtual concatenation - of `string1' and `string2'. If only one string, it's `string2'. */ -#define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2) -#define AT_STRINGS_END(d) ((d) == end2) - - -/* Test if D points to a character which is word-constituent. We have - two special cases to check for: if past the end of string1, look at - the first character in string2; and if before the beginning of - string2, look at the last character in string1. */ -#define WORDCHAR_P(d) \ - (SYNTAX ((d) == end1 ? *string2 \ - : (d) == string2 - 1 ? *(end1 - 1) : *(d)) \ - == Sword) - -/* Test if the character before D and the one at D differ with respect - to being word-constituent. */ -#define AT_WORD_BOUNDARY(d) \ - (AT_STRINGS_BEG (d) || AT_STRINGS_END (d) \ - || WORDCHAR_P (d - 1) != WORDCHAR_P (d)) - - -/* Free everything we malloc. */ -#ifdef MATCH_MAY_ALLOCATE -#ifdef REGEX_MALLOC -#define FREE_VAR(var) if (var) free (var); var = NULL -#define FREE_VARIABLES() \ - do { \ - FREE_VAR (fail_stack.stack); \ - FREE_VAR (regstart); \ - FREE_VAR (regend); \ - FREE_VAR (old_regstart); \ - FREE_VAR (old_regend); \ - FREE_VAR (best_regstart); \ - FREE_VAR (best_regend); \ - FREE_VAR (reg_info); \ - FREE_VAR (reg_dummy); \ - FREE_VAR (reg_info_dummy); \ - } while (0) -#else /* not REGEX_MALLOC */ -/* Some MIPS systems (at least) want this to free alloca'd storage. */ -#define FREE_VARIABLES() alloca (0) -#endif /* not REGEX_MALLOC */ -#else -#define FREE_VARIABLES() /* Do nothing! */ -#endif /* not MATCH_MAY_ALLOCATE */ - -/* These values must meet several constraints. They must not be valid - register values; since we have a limit of 255 registers (because - we use only one byte in the pattern for the register number), we can - use numbers larger than 255. They must differ by 1, because of - NUM_FAILURE_ITEMS above. And the value for the lowest register must - be larger than the value for the highest register, so we do not try - to actually save any registers when none are active. */ -#define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH) -#define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1) - -/* Matching routines. */ - -#ifndef emacs /* Emacs never uses this. */ -/* re_match is like re_match_2 except it takes only a single string. */ - -int -re_match (bufp, string, size, pos, regs) - struct re_pattern_buffer *bufp; - const char *string; - int size, pos; - struct re_registers *regs; - { - return re_match_2 (bufp, NULL, 0, string, size, pos, regs, size); -} -#endif /* not emacs */ - - -/* re_match_2 matches the compiled pattern in BUFP against the - the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 - and SIZE2, respectively). We start matching at POS, and stop - matching at STOP. - - If REGS is non-null and the `no_sub' field of BUFP is nonzero, we - store offsets for the substring each group matched in REGS. See the - documentation for exactly how many groups we fill. - - We return -1 if no match, -2 if an internal error (such as the - failure stack overflowing). Otherwise, we return the length of the - matched substring. */ - -int -re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int pos; - struct re_registers *regs; - int stop; -{ - /* General temporaries. */ - int mcnt; - unsigned char *p1; - - /* Just past the end of the corresponding string. */ - const char *end1, *end2; - - /* Pointers into string1 and string2, just past the last characters in - each to consider matching. */ - const char *end_match_1, *end_match_2; - - /* Where we are in the data, and the end of the current string. */ - const char *d, *dend; - - /* Where we are in the pattern, and the end of the pattern. */ - unsigned char *p = bufp->buffer; - register unsigned char *pend = p + bufp->used; - - /* We use this to map every character in the string. */ - char *translate = bufp->translate; - - /* Failure point stack. Each place that can handle a failure further - down the line pushes a failure point on this stack. It consists of - restart, regend, and reg_info for all registers corresponding to - the subexpressions we're currently inside, plus the number of such - registers, and, finally, two char *'s. The first char * is where - to resume scanning the pattern; the second one is where to resume - scanning the strings. If the latter is zero, the failure point is - a ``dummy''; if a failure happens and the failure point is a dummy, - it gets discarded and the next next one is tried. */ -#ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */ - fail_stack_type fail_stack; -#endif -#ifdef DEBUG - static unsigned failure_id = 0; - unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; -#endif - - /* We fill all the registers internally, independent of what we - return, for use in backreferences. The number here includes - an element for register zero. */ - unsigned num_regs = bufp->re_nsub + 1; - - /* The currently active registers. */ - unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG; - unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG; - - /* Information on the contents of registers. These are pointers into - the input strings; they record just what was matched (on this - attempt) by a subexpression part of the pattern, that is, the - regnum-th regstart pointer points to where in the pattern we began - matching and the regnum-th regend points to right after where we - stopped matching the regnum-th subexpression. (The zeroth register - keeps track of what the whole pattern matches.) */ -#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ - const char **regstart, **regend; -#endif - - /* If a group that's operated upon by a repetition operator fails to - match anything, then the register for its start will need to be - restored because it will have been set to wherever in the string we - are when we last see its open-group operator. Similarly for a - register's end. */ -#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ - const char **old_regstart, **old_regend; -#endif - - /* The is_active field of reg_info helps us keep track of which (possibly - nested) subexpressions we are currently in. The matched_something - field of reg_info[reg_num] helps us tell whether or not we have - matched any of the pattern so far this time through the reg_num-th - subexpression. These two fields get reset each time through any - loop their register is in. */ -#ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */ - register_info_type *reg_info; -#endif - - /* The following record the register info as found in the above - variables when we find a match better than any we've seen before. - This happens as we backtrack through the failure points, which in - turn happens only if we have not yet matched the entire string. */ - unsigned best_regs_set = false; -#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ - const char **best_regstart, **best_regend; -#endif - - /* Logically, this is `best_regend[0]'. But we don't want to have to - allocate space for that if we're not allocating space for anything - else (see below). Also, we never need info about register 0 for - any of the other register vectors, and it seems rather a kludge to - treat `best_regend' differently than the rest. So we keep track of - the end of the best match so far in a separate variable. We - initialize this to NULL so that when we backtrack the first time - and need to test it, it's not garbage. */ - const char *match_end = NULL; - - /* Used when we pop values we don't care about. */ -#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */ - const char **reg_dummy; - register_info_type *reg_info_dummy; -#endif - -#ifdef DEBUG - /* Counts the total number of registers pushed. */ - unsigned num_regs_pushed = 0; -#endif - - DEBUG_PRINT1 ("\n\nEntering re_match_2.\n"); - - INIT_FAIL_STACK (); - -#ifdef MATCH_MAY_ALLOCATE - /* Do not bother to initialize all the register variables if there are - no groups in the pattern, as it takes a fair amount of time. If - there are groups, we include space for register 0 (the whole - pattern), even though we never use it, since it simplifies the - array indexing. We should fix this. */ - if (bufp->re_nsub) - { - regstart = REGEX_TALLOC (num_regs, const char *); - regend = REGEX_TALLOC (num_regs, const char *); - old_regstart = REGEX_TALLOC (num_regs, const char *); - old_regend = REGEX_TALLOC (num_regs, const char *); - best_regstart = REGEX_TALLOC (num_regs, const char *); - best_regend = REGEX_TALLOC (num_regs, const char *); - reg_info = REGEX_TALLOC (num_regs, register_info_type); - reg_dummy = REGEX_TALLOC (num_regs, const char *); - reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type); - - if (!(regstart && regend && old_regstart && old_regend && reg_info - && best_regstart && best_regend && reg_dummy && reg_info_dummy)) - { - FREE_VARIABLES (); - return -2; - } - } -#if defined (REGEX_MALLOC) - else - { - /* We must initialize all our variables to NULL, so that - `FREE_VARIABLES' doesn't try to free them. */ - regstart = regend = old_regstart = old_regend = best_regstart - = best_regend = reg_dummy = NULL; - reg_info = reg_info_dummy = (register_info_type *) NULL; - } -#endif /* REGEX_MALLOC */ -#endif /* MATCH_MAY_ALLOCATE */ - - /* The starting position is bogus. */ - if (pos < 0 || pos > size1 + size2) - { - FREE_VARIABLES (); - return -1; - } - - /* Initialize subexpression text positions to -1 to mark ones that no - start_memory/stop_memory has been seen for. Also initialize the - register information struct. */ - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - regstart[mcnt] = regend[mcnt] - = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE; - - REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE; - IS_ACTIVE (reg_info[mcnt]) = 0; - MATCHED_SOMETHING (reg_info[mcnt]) = 0; - EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0; - } - - /* We move `string1' into `string2' if the latter's empty -- but not if - `string1' is null. */ - if (size2 == 0 && string1 != NULL) - { - string2 = string1; - size2 = size1; - string1 = 0; - size1 = 0; - } - end1 = string1 + size1; - end2 = string2 + size2; - - /* Compute where to stop matching, within the two strings. */ - if (stop <= size1) - { - end_match_1 = string1 + stop; - end_match_2 = string2; - } - else - { - end_match_1 = end1; - end_match_2 = string2 + stop - size1; - } - - /* `p' scans through the pattern as `d' scans through the data. - `dend' is the end of the input string that `d' points within. `d' - is advanced into the following input string whenever necessary, but - this happens before fetching; therefore, at the beginning of the - loop, `d' can be pointing at the end of a string, but it cannot - equal `string2'. */ - if (size1 > 0 && pos <= size1) - { - d = string1 + pos; - dend = end_match_1; - } - else - { - d = string2 + pos - size1; - dend = end_match_2; - } - - DEBUG_PRINT1 ("The compiled pattern is: "); - DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); - DEBUG_PRINT1 ("The string to match is: `"); - DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); - DEBUG_PRINT1 ("'\n"); - - /* This loops over pattern commands. It exits by returning from the - function if the match is complete, or it drops through if the match - fails at this starting point in the input data. */ - for (;;) - { - DEBUG_PRINT2 ("\n0x%x: ", p); - - if (p == pend) - { /* End of pattern means we might have succeeded. */ - DEBUG_PRINT1 ("end of pattern ... "); - - /* If we haven't matched the entire string, and we want the - longest match, try backtracking. */ - if (d != end_match_2) - { - DEBUG_PRINT1 ("backtracking.\n"); - - if (!FAIL_STACK_EMPTY ()) - { /* More failure points to try. */ - boolean same_str_p = (FIRST_STRING_P (match_end) - == MATCHING_IN_FIRST_STRING); - - /* If exceeds best match so far, save it. */ - if (!best_regs_set - || (same_str_p && d > match_end) - || (!same_str_p && !MATCHING_IN_FIRST_STRING)) - { - best_regs_set = true; - match_end = d; - - DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); - - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - best_regstart[mcnt] = regstart[mcnt]; - best_regend[mcnt] = regend[mcnt]; - } - } - goto fail; - } - - /* If no failure points, don't restore garbage. */ - else if (best_regs_set) - { - restore_best_regs: - /* Restore best match. It may happen that `dend == - end_match_1' while the restored d is in string2. - For example, the pattern `x.*y.*z' against the - strings `x-' and `y-z-', if the two strings are - not consecutive in memory. */ - DEBUG_PRINT1 ("Restoring best registers.\n"); - - d = match_end; - dend = ((d >= string1 && d <= end1) - ? end_match_1 : end_match_2); - - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - regstart[mcnt] = best_regstart[mcnt]; - regend[mcnt] = best_regend[mcnt]; - } - } - } /* d != end_match_2 */ - - DEBUG_PRINT1 ("Accepting match.\n"); - - /* If caller wants register contents data back, do it. */ - if (regs && !bufp->no_sub) - { - /* Have the register data arrays been allocated? */ - if (bufp->regs_allocated == REGS_UNALLOCATED) - { /* No. So allocate them with malloc. We need one - extra element beyond `num_regs' for the `-1' marker - GNU code uses. */ - regs->num_regs = MAX (RE_NREGS, num_regs + 1); - regs->start = TALLOC (regs->num_regs, regoff_t); - regs->end = TALLOC (regs->num_regs, regoff_t); - if (regs->start == NULL || regs->end == NULL) - return -2; - bufp->regs_allocated = REGS_REALLOCATE; - } - else if (bufp->regs_allocated == REGS_REALLOCATE) - { /* Yes. If we need more elements than were already - allocated, reallocate them. If we need fewer, just - leave it alone. */ - if (regs->num_regs < num_regs + 1) - { - regs->num_regs = num_regs + 1; - RETALLOC (regs->start, regs->num_regs, regoff_t); - RETALLOC (regs->end, regs->num_regs, regoff_t); - if (regs->start == NULL || regs->end == NULL) - return -2; - } - } - else - { - /* These braces fend off a "empty body in an else-statement" - warning under GCC when assert expands to nothing. */ - assert (bufp->regs_allocated == REGS_FIXED); - } - - /* Convert the pointer data in `regstart' and `regend' to - indices. Register zero has to be set differently, - since we haven't kept track of any info for it. */ - if (regs->num_regs > 0) - { - regs->start[0] = pos; - regs->end[0] = (MATCHING_IN_FIRST_STRING - ? ((regoff_t) (d - string1)) - : ((regoff_t) (d - string2 + size1))); - } - - /* Go through the first `min (num_regs, regs->num_regs)' - registers, since that is all we initialized. */ - for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++) - { - if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt])) - regs->start[mcnt] = regs->end[mcnt] = -1; - else - { - regs->start[mcnt] - = (regoff_t) POINTER_TO_OFFSET (regstart[mcnt]); - regs->end[mcnt] - = (regoff_t) POINTER_TO_OFFSET (regend[mcnt]); - } - } - - /* If the regs structure we return has more elements than - were in the pattern, set the extra elements to -1. If - we (re)allocated the registers, this is the case, - because we always allocate enough to have at least one - -1 at the end. */ - for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++) - regs->start[mcnt] = regs->end[mcnt] = -1; - } /* regs && !bufp->no_sub */ - - FREE_VARIABLES (); - DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", - nfailure_points_pushed, nfailure_points_popped, - nfailure_points_pushed - nfailure_points_popped); - DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); - - mcnt = d - pos - (MATCHING_IN_FIRST_STRING - ? string1 - : string2 - size1); - - DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); - - return mcnt; - } - - /* Otherwise match next pattern command. */ -#ifdef SWITCH_ENUM_BUG - switch ((int) ((re_opcode_t) *p++)) -#else - switch ((re_opcode_t) *p++) -#endif - { - /* Ignore these. Used to ignore the n of succeed_n's which - currently have n == 0. */ - case no_op: - DEBUG_PRINT1 ("EXECUTING no_op.\n"); - break; - - - /* Match the next n pattern characters exactly. The following - byte in the pattern defines n, and the n bytes after that - are the characters to match. */ - case exactn: - mcnt = *p++; - DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt); - - /* This is written out as an if-else so we don't waste time - testing `translate' inside the loop. */ - if (translate) - { - do - { - PREFETCH (); - if (translate[(unsigned char) *d++] != (char) *p++) - goto fail; - } - while (--mcnt); - } - else - { - do - { - PREFETCH (); - if (*d++ != (char) *p++) goto fail; - } - while (--mcnt); - } - SET_REGS_MATCHED (); - break; - - - /* Match any character except possibly a newline or a null. */ - case anychar: - DEBUG_PRINT1 ("EXECUTING anychar.\n"); - - PREFETCH (); - - if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n') - || (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000')) - goto fail; - - SET_REGS_MATCHED (); - DEBUG_PRINT2 (" Matched `%d'.\n", *d); - d++; - break; - - - case charset: - case charset_not: - { - register unsigned char c; - boolean not = (re_opcode_t) *(p - 1) == charset_not; - - DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); - - PREFETCH (); - c = TRANSLATE (*d); /* The character to match. */ - - /* Cast to `unsigned' instead of `unsigned char' in case the - bit list is a full 32 bytes long. */ - if (c < (unsigned) (*p * BYTEWIDTH) - && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - p += 1 + *p; - - if (!not) goto fail; - - SET_REGS_MATCHED (); - d++; - break; - } - - - /* The beginning of a group is represented by start_memory. - The arguments are the register number in the next byte, and the - number of groups inner to this one in the next. The text - matched within the group is recorded (in the internal - registers data structure) under the register number. */ - case start_memory: - DEBUG_PRINT3 ("EXECUTING start_memory %d (%d):\n", *p, p[1]); - - /* Find out if this group can match the empty string. */ - p1 = p; /* To send to group_match_null_string_p. */ - - if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE) - REG_MATCH_NULL_STRING_P (reg_info[*p]) - = group_match_null_string_p (&p1, pend, reg_info); - - /* Save the position in the string where we were the last time - we were at this open-group operator in case the group is - operated upon by a repetition operator, e.g., with `(a*)*b' - against `ab'; then we want to ignore where we are now in - the string in case this attempt to match fails. */ - old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) - ? REG_UNSET (regstart[*p]) ? d : regstart[*p] - : regstart[*p]; - DEBUG_PRINT2 (" old_regstart: %d\n", - POINTER_TO_OFFSET (old_regstart[*p])); - - regstart[*p] = d; - DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p])); - - IS_ACTIVE (reg_info[*p]) = 1; - MATCHED_SOMETHING (reg_info[*p]) = 0; - - /* This is the new highest active register. */ - highest_active_reg = *p; - - /* If nothing was active before, this is the new lowest active - register. */ - if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) - lowest_active_reg = *p; - - /* Move past the register number and inner group count. */ - p += 2; - break; - - - /* The stop_memory opcode represents the end of a group. Its - arguments are the same as start_memory's: the register - number, and the number of inner groups. */ - case stop_memory: - DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]); - - /* We need to save the string position the last time we were at - this close-group operator in case the group is operated - upon by a repetition operator, e.g., with `((a*)*(b*)*)*' - against `aba'; then we want to ignore where we are now in - the string in case this attempt to match fails. */ - old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) - ? REG_UNSET (regend[*p]) ? d : regend[*p] - : regend[*p]; - DEBUG_PRINT2 (" old_regend: %d\n", - POINTER_TO_OFFSET (old_regend[*p])); - - regend[*p] = d; - DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p])); - - /* This register isn't active anymore. */ - IS_ACTIVE (reg_info[*p]) = 0; - - /* If this was the only register active, nothing is active - anymore. */ - if (lowest_active_reg == highest_active_reg) - { - lowest_active_reg = NO_LOWEST_ACTIVE_REG; - highest_active_reg = NO_HIGHEST_ACTIVE_REG; - } - else - { /* We must scan for the new highest active register, since - it isn't necessarily one less than now: consider - (a(b)c(d(e)f)g). When group 3 ends, after the f), the - new highest active register is 1. */ - unsigned char r = *p - 1; - while (r > 0 && !IS_ACTIVE (reg_info[r])) - r--; - - /* If we end up at register zero, that means that we saved - the registers as the result of an `on_failure_jump', not - a `start_memory', and we jumped to past the innermost - `stop_memory'. For example, in ((.)*) we save - registers 1 and 2 as a result of the *, but when we pop - back to the second ), we are at the stop_memory 1. - Thus, nothing is active. */ - if (r == 0) - { - lowest_active_reg = NO_LOWEST_ACTIVE_REG; - highest_active_reg = NO_HIGHEST_ACTIVE_REG; - } - else - highest_active_reg = r; - } - - /* If just failed to match something this time around with a - group that's operated on by a repetition operator, try to - force exit from the ``loop'', and restore the register - information for this group that we had before trying this - last match. */ - if ((!MATCHED_SOMETHING (reg_info[*p]) - || (re_opcode_t) p[-3] == start_memory) - && (p + 2) < pend) - { - boolean is_a_jump_n = false; - - p1 = p + 2; - mcnt = 0; - switch ((re_opcode_t) *p1++) - { - case jump_n: - is_a_jump_n = true; - case pop_failure_jump: - case maybe_pop_jump: - case jump: - case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if (is_a_jump_n) - p1 += 2; - break; - - default: - /* do nothing */ ; - } - p1 += mcnt; - - /* If the next operation is a jump backwards in the pattern - to an on_failure_jump right before the start_memory - corresponding to this stop_memory, exit from the loop - by forcing a failure after pushing on the stack the - on_failure_jump's jump in the pattern, and d. */ - if (mcnt < 0 && (re_opcode_t) *p1 == on_failure_jump - && (re_opcode_t) p1[3] == start_memory && p1[4] == *p) - { - /* If this group ever matched anything, then restore - what its registers were before trying this last - failed match, e.g., with `(a*)*b' against `ab' for - regstart[1], and, e.g., with `((a*)*(b*)*)*' - against `aba' for regend[3]. - - Also restore the registers for inner groups for, - e.g., `((a*)(b*))*' against `aba' (register 3 would - otherwise get trashed). */ - - if (EVER_MATCHED_SOMETHING (reg_info[*p])) - { - unsigned r; - - EVER_MATCHED_SOMETHING (reg_info[*p]) = 0; - - /* Restore this and inner groups' (if any) registers. */ - for (r = *p; r < *p + *(p + 1); r++) - { - regstart[r] = old_regstart[r]; - - /* xx why this test? */ - if ((int) old_regend[r] >= (int) regstart[r]) - regend[r] = old_regend[r]; - } - } - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - PUSH_FAILURE_POINT (p1 + mcnt, d, -2); - - goto fail; - } - } - - /* Move past the register number and the inner group count. */ - p += 2; - break; - - - /* \ has been turned into a `duplicate' command which is - followed by the numeric value of as the register number. */ - case duplicate: - { - register const char *d2, *dend2; - int regno = *p++; /* Get which register to match against. */ - DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); - - /* Can't back reference a group which we've never matched. */ - if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) - goto fail; - - /* Where in input to try to start matching. */ - d2 = regstart[regno]; - - /* Where to stop matching; if both the place to start and - the place to stop matching are in the same string, then - set to the place to stop, otherwise, for now have to use - the end of the first string. */ - - dend2 = ((FIRST_STRING_P (regstart[regno]) - == FIRST_STRING_P (regend[regno])) - ? regend[regno] : end_match_1); - for (;;) - { - /* If necessary, advance to next segment in register - contents. */ - while (d2 == dend2) - { - if (dend2 == end_match_2) break; - if (dend2 == regend[regno]) break; - - /* End of string1 => advance to string2. */ - d2 = string2; - dend2 = regend[regno]; - } - /* At end of register contents => success */ - if (d2 == dend2) break; - - /* If necessary, advance to next segment in data. */ - PREFETCH (); - - /* How many characters left in this segment to match. */ - mcnt = dend - d; - - /* Want how many consecutive characters we can match in - one shot, so, if necessary, adjust the count. */ - if (mcnt > dend2 - d2) - mcnt = dend2 - d2; - - /* Compare that many; failure if mismatch, else move - past them. */ - if (translate - ? bcmp_translate (d, d2, mcnt, translate) - : bcmp (d, d2, mcnt)) - goto fail; - d += mcnt, d2 += mcnt; - } - } - break; - - - /* begline matches the empty string at the beginning of the string - (unless `not_bol' is set in `bufp'), and, if - `newline_anchor' is set, after newlines. */ - case begline: - DEBUG_PRINT1 ("EXECUTING begline.\n"); - - if (AT_STRINGS_BEG (d)) - { - if (!bufp->not_bol) break; - } - else if (d[-1] == '\n' && bufp->newline_anchor) - { - break; - } - /* In all other cases, we fail. */ - goto fail; - - - /* endline is the dual of begline. */ - case endline: - DEBUG_PRINT1 ("EXECUTING endline.\n"); - - if (AT_STRINGS_END (d)) - { - if (!bufp->not_eol) break; - } - - /* We have to ``prefetch'' the next character. */ - else if ((d == end1 ? *string2 : *d) == '\n' - && bufp->newline_anchor) - { - break; - } - goto fail; - - - /* Match at the very beginning of the data. */ - case begbuf: - DEBUG_PRINT1 ("EXECUTING begbuf.\n"); - if (AT_STRINGS_BEG (d)) - break; - goto fail; - - - /* Match at the very end of the data. */ - case endbuf: - DEBUG_PRINT1 ("EXECUTING endbuf.\n"); - if (AT_STRINGS_END (d)) - break; - goto fail; - - - /* on_failure_keep_string_jump is used to optimize `.*\n'. It - pushes NULL as the value for the string on the stack. Then - `pop_failure_point' will keep the current value for the - string, instead of restoring it. To see why, consider - matching `foo\nbar' against `.*\n'. The .* matches the foo; - then the . fails against the \n. But the next thing we want - to do is match the \n against the \n; if we restored the - string value, we would be back at the foo. - - Because this is used only in specific cases, we don't need to - check all the things that `on_failure_jump' does, to make - sure the right things get saved on the stack. Hence we don't - share its code. The only reason to push anything on the - stack at all is that otherwise we would have to change - `anychar's code to do something besides goto fail in this - case; that seems worse than this. */ - case on_failure_keep_string_jump: - DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" %d (to 0x%x):\n", mcnt, p + mcnt); - - PUSH_FAILURE_POINT (p + mcnt, NULL, -2); - break; - - - /* Uses of on_failure_jump: - - Each alternative starts with an on_failure_jump that points - to the beginning of the next alternative. Each alternative - except the last ends with a jump that in effect jumps past - the rest of the alternatives. (They really jump to the - ending jump of the following alternative, because tensioning - these jumps is a hassle.) - - Repeats start with an on_failure_jump that points past both - the repetition text and either the following jump or - pop_failure_jump back to this on_failure_jump. */ - case on_failure_jump: - on_failure: - DEBUG_PRINT1 ("EXECUTING on_failure_jump"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" %d (to 0x%x)", mcnt, p + mcnt); - - /* If this on_failure_jump comes right before a group (i.e., - the original * applied to a group), save the information - for that group and all inner ones, so that if we fail back - to this point, the group's information will be correct. - For example, in \(a*\)*\1, we need the preceding group, - and in \(\(a*\)b*\)\2, we need the inner group. */ - - /* We can't use `p' to check ahead because we push - a failure point to `p + mcnt' after we do this. */ - p1 = p; - - /* We need to skip no_op's before we look for the - start_memory in case this on_failure_jump is happening as - the result of a completed succeed_n, as in \(a\)\{1,3\}b\1 - against aba. */ - while (p1 < pend && (re_opcode_t) *p1 == no_op) - p1++; - - if (p1 < pend && (re_opcode_t) *p1 == start_memory) - { - /* We have a new highest active register now. This will - get reset at the start_memory we are about to get to, - but we will have saved all the registers relevant to - this repetition op, as described above. */ - highest_active_reg = *(p1 + 1) + *(p1 + 2); - if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) - lowest_active_reg = *(p1 + 1); - } - - DEBUG_PRINT1 (":\n"); - PUSH_FAILURE_POINT (p + mcnt, d, -2); - break; - - - /* A smart repeat ends with `maybe_pop_jump'. - We change it to either `pop_failure_jump' or `jump'. */ - case maybe_pop_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT2 ("EXECUTING maybe_pop_jump %d.\n", mcnt); - { - register unsigned char *p2 = p; - - /* Compare the beginning of the repeat with what in the - pattern follows its end. If we can establish that there - is nothing that they would both match, i.e., that we - would have to backtrack because of (as in, e.g., `a*a') - then we can change to pop_failure_jump, because we'll - never have to backtrack. - - This is not true in the case of alternatives: in - `(a|ab)*' we do need to backtrack to the `ab' alternative - (e.g., if the string was `ab'). But instead of trying to - detect that here, the alternative has put on a dummy - failure point which is what we will end up popping. */ - - /* Skip over open/close-group commands. - If what follows this loop is a ...+ construct, - look at what begins its body, since we will have to - match at least one of that. */ - while (1) - { - if (p2 + 2 < pend - && ((re_opcode_t) *p2 == stop_memory - || (re_opcode_t) *p2 == start_memory)) - p2 += 3; - else if (p2 + 6 < pend - && (re_opcode_t) *p2 == dummy_failure_jump) - p2 += 6; - else - break; - } - - p1 = p + mcnt; - /* p1[0] ... p1[2] are the `on_failure_jump' corresponding - to the `maybe_finalize_jump' of this case. Examine what - follows. */ - - /* If we're at the end of the pattern, we can change. */ - if (p2 == pend) - { - /* Consider what happens when matching ":\(.*\)" - against ":/". I don't really understand this code - yet. */ - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 - (" End of pattern: change to `pop_failure_jump'.\n"); - } - - else if ((re_opcode_t) *p2 == exactn - || (bufp->newline_anchor && (re_opcode_t) *p2 == endline)) - { - register unsigned char c - = *p2 == (unsigned char) endline ? '\n' : p2[2]; - - if ((re_opcode_t) p1[3] == exactn && p1[5] != c) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", - c, p1[5]); - } - - else if ((re_opcode_t) p1[3] == charset - || (re_opcode_t) p1[3] == charset_not) - { - int not = (re_opcode_t) p1[3] == charset_not; - - if (c < (unsigned char) (p1[4] * BYTEWIDTH) - && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - /* `not' is equal to 1 if c would match, which means - that we can't change to pop_failure_jump. */ - if (!not) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 (" No match => pop_failure_jump.\n"); - } - } - } - else if ((re_opcode_t) *p2 == charset) - { - register unsigned char c - = *p2 == (unsigned char) endline ? '\n' : p2[2]; - - if ((re_opcode_t) p1[3] == exactn - && ! (p2[1] * BYTEWIDTH > p1[4] - && (p2[1 + p1[4] / BYTEWIDTH] - & (1 << (p1[4] % BYTEWIDTH))))) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", - c, p1[5]); - } - - else if ((re_opcode_t) p1[3] == charset_not) - { - int idx; - /* We win if the charset_not inside the loop - lists every character listed in the charset after. */ - for (idx = 0; idx < p2[1]; idx++) - if (! (p2[2 + idx] == 0 - || (idx < p1[4] - && ((p2[2 + idx] & ~ p1[5 + idx]) == 0)))) - break; - - if (idx == p2[1]) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 (" No match => pop_failure_jump.\n"); - } - } - else if ((re_opcode_t) p1[3] == charset) - { - int idx; - /* We win if the charset inside the loop - has no overlap with the one after the loop. */ - for (idx = 0; idx < p2[1] && idx < p1[4]; idx++) - if ((p2[2 + idx] & p1[5 + idx]) != 0) - break; - - if (idx == p2[1] || idx == p1[4]) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 (" No match => pop_failure_jump.\n"); - } - } - } - } - p -= 2; /* Point at relative address again. */ - if ((re_opcode_t) p[-1] != pop_failure_jump) - { - p[-1] = (unsigned char) jump; - DEBUG_PRINT1 (" Match => jump.\n"); - goto unconditional_jump; - } - /* Note fall through. */ - - - /* The end of a simple repeat has a pop_failure_jump back to - its matching on_failure_jump, where the latter will push a - failure point. The pop_failure_jump takes off failure - points put on by this pop_failure_jump's matching - on_failure_jump; we got through the pattern to here from the - matching on_failure_jump, so didn't fail. */ - case pop_failure_jump: - { - /* We need to pass separate storage for the lowest and - highest registers, even though we don't care about the - actual values. Otherwise, we will restore only one - register from the stack, since lowest will == highest in - `pop_failure_point'. */ - unsigned dummy_low_reg, dummy_high_reg; - unsigned char *pdummy; - const char *sdummy; - - DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); - POP_FAILURE_POINT (sdummy, pdummy, - dummy_low_reg, dummy_high_reg, - reg_dummy, reg_dummy, reg_info_dummy); - } - /* Note fall through. */ - - - /* Unconditionally jump (without popping any failure points). */ - case jump: - unconditional_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */ - DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt); - p += mcnt; /* Do the jump. */ - DEBUG_PRINT2 ("(to 0x%x).\n", p); - break; - - - /* We need this opcode so we can detect where alternatives end - in `group_match_null_string_p' et al. */ - case jump_past_alt: - DEBUG_PRINT1 ("EXECUTING jump_past_alt.\n"); - goto unconditional_jump; - - - /* Normally, the on_failure_jump pushes a failure point, which - then gets popped at pop_failure_jump. We will end up at - pop_failure_jump, also, and with a pattern of, say, `a+', we - are skipping over the on_failure_jump, so we have to push - something meaningless for pop_failure_jump to pop. */ - case dummy_failure_jump: - DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n"); - /* It doesn't matter what we push for the string here. What - the code at `fail' tests is the value for the pattern. */ - PUSH_FAILURE_POINT (0, 0, -2); - goto unconditional_jump; - - - /* At the end of an alternative, we need to push a dummy failure - point in case we are followed by a `pop_failure_jump', because - we don't want the failure point for the alternative to be - popped. For example, matching `(a|ab)*' against `aab' - requires that we match the `ab' alternative. */ - case push_dummy_failure: - DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n"); - /* See comments just above at `dummy_failure_jump' about the - two zeroes. */ - PUSH_FAILURE_POINT (0, 0, -2); - break; - - /* Have to succeed matching what follows at least n times. - After that, handle like `on_failure_jump'. */ - case succeed_n: - EXTRACT_NUMBER (mcnt, p + 2); - DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt); - - assert (mcnt >= 0); - /* Originally, this is how many times we HAVE to succeed. */ - if (mcnt > 0) - { - mcnt--; - p += 2; - STORE_NUMBER_AND_INCR (p, mcnt); - DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p, mcnt); - } - else if (mcnt == 0) - { - DEBUG_PRINT2 (" Setting two bytes from 0x%x to no_op.\n", p+2); - p[2] = (unsigned char) no_op; - p[3] = (unsigned char) no_op; - goto on_failure; - } - break; - - case jump_n: - EXTRACT_NUMBER (mcnt, p + 2); - DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt); - - /* Originally, this is how many times we CAN jump. */ - if (mcnt) - { - mcnt--; - STORE_NUMBER (p + 2, mcnt); - goto unconditional_jump; - } - /* If don't have to jump any more, skip over the rest of command. */ - else - p += 4; - break; - - case set_number_at: - { - DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - p1 = p + mcnt; - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p1, mcnt); - STORE_NUMBER (p1, mcnt); - break; - } - - case wordbound: - DEBUG_PRINT1 ("EXECUTING wordbound.\n"); - if (AT_WORD_BOUNDARY (d)) - break; - goto fail; - - case notwordbound: - DEBUG_PRINT1 ("EXECUTING notwordbound.\n"); - if (AT_WORD_BOUNDARY (d)) - goto fail; - break; - - case wordbeg: - DEBUG_PRINT1 ("EXECUTING wordbeg.\n"); - if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1))) - break; - goto fail; - - case wordend: - DEBUG_PRINT1 ("EXECUTING wordend.\n"); - if (!AT_STRINGS_BEG (d) && WORDCHAR_P (d - 1) - && (!WORDCHAR_P (d) || AT_STRINGS_END (d))) - break; - goto fail; - -#ifdef emacs -#ifdef emacs19 - case before_dot: - DEBUG_PRINT1 ("EXECUTING before_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) >= point) - goto fail; - break; - - case at_dot: - DEBUG_PRINT1 ("EXECUTING at_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) != point) - goto fail; - break; - - case after_dot: - DEBUG_PRINT1 ("EXECUTING after_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) <= point) - goto fail; - break; -#else /* not emacs19 */ - case at_dot: - DEBUG_PRINT1 ("EXECUTING at_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) + 1 != point) - goto fail; - break; -#endif /* not emacs19 */ - - case syntaxspec: - DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt); - mcnt = *p++; - goto matchsyntax; - - case wordchar: - DEBUG_PRINT1 ("EXECUTING Emacs wordchar.\n"); - mcnt = (int) Sword; - matchsyntax: - PREFETCH (); - if (SYNTAX (*d++) != (enum syntaxcode) mcnt) - goto fail; - SET_REGS_MATCHED (); - break; - - case notsyntaxspec: - DEBUG_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt); - mcnt = *p++; - goto matchnotsyntax; - - case notwordchar: - DEBUG_PRINT1 ("EXECUTING Emacs notwordchar.\n"); - mcnt = (int) Sword; - matchnotsyntax: - PREFETCH (); - if (SYNTAX (*d++) == (enum syntaxcode) mcnt) - goto fail; - SET_REGS_MATCHED (); - break; - -#else /* not emacs */ - case wordchar: - DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n"); - PREFETCH (); - if (!WORDCHAR_P (d)) - goto fail; - SET_REGS_MATCHED (); - d++; - break; - - case notwordchar: - DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n"); - PREFETCH (); - if (WORDCHAR_P (d)) - goto fail; - SET_REGS_MATCHED (); - d++; - break; -#endif /* not emacs */ - - default: - abort (); - } - continue; /* Successfully executed one pattern command; keep going. */ - - - /* We goto here if a matching operation fails. */ - fail: - if (!FAIL_STACK_EMPTY ()) - { /* A restart point is known. Restore to that state. */ - DEBUG_PRINT1 ("\nFAIL:\n"); - POP_FAILURE_POINT (d, p, - lowest_active_reg, highest_active_reg, - regstart, regend, reg_info); - - /* If this failure point is a dummy, try the next one. */ - if (!p) - goto fail; - - /* If we failed to the end of the pattern, don't examine *p. */ - assert (p <= pend); - if (p < pend) - { - boolean is_a_jump_n = false; - - /* If failed to a backwards jump that's part of a repetition - loop, need to pop this failure point and use the next one. */ - switch ((re_opcode_t) *p) - { - case jump_n: - is_a_jump_n = true; - case maybe_pop_jump: - case pop_failure_jump: - case jump: - p1 = p + 1; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - - if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n) - || (!is_a_jump_n - && (re_opcode_t) *p1 == on_failure_jump)) - goto fail; - break; - default: - /* do nothing */ ; - } - } - - if (d >= string1 && d <= end1) - dend = end_match_1; - } - else - break; /* Matching at this starting point really fails. */ - } /* for (;;) */ - - if (best_regs_set) - goto restore_best_regs; - - FREE_VARIABLES (); - - return -1; /* Failure to match. */ -} /* re_match_2 */ - -/* Subroutine definitions for re_match_2. */ - - -/* We are passed P pointing to a register number after a start_memory. - - Return true if the pattern up to the corresponding stop_memory can - match the empty string, and false otherwise. - - If we find the matching stop_memory, sets P to point to one past its number. - Otherwise, sets P to an undefined byte less than or equal to END. - - We don't handle duplicates properly (yet). */ - -static boolean -group_match_null_string_p (p, end, reg_info) - unsigned char **p, *end; - register_info_type *reg_info; -{ - int mcnt; - /* Point to after the args to the start_memory. */ - unsigned char *p1 = *p + 2; - - while (p1 < end) - { - /* Skip over opcodes that can match nothing, and return true or - false, as appropriate, when we get to one that can't, or to the - matching stop_memory. */ - - switch ((re_opcode_t) *p1) - { - /* Could be either a loop or a series of alternatives. */ - case on_failure_jump: - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - - /* If the next operation is not a jump backwards in the - pattern. */ - - if (mcnt >= 0) - { - /* Go through the on_failure_jumps of the alternatives, - seeing if any of the alternatives cannot match nothing. - The last alternative starts with only a jump, - whereas the rest start with on_failure_jump and end - with a jump, e.g., here is the pattern for `a|b|c': - - /on_failure_jump/0/6/exactn/1/a/jump_past_alt/0/6 - /on_failure_jump/0/6/exactn/1/b/jump_past_alt/0/3 - /exactn/1/c - - So, we have to first go through the first (n-1) - alternatives and then deal with the last one separately. */ - - - /* Deal with the first (n-1) alternatives, which start - with an on_failure_jump (see above) that jumps to right - past a jump_past_alt. */ - - while ((re_opcode_t) p1[mcnt-3] == jump_past_alt) - { - /* `mcnt' holds how many bytes long the alternative - is, including the ending `jump_past_alt' and - its number. */ - - if (!alt_match_null_string_p (p1, p1 + mcnt - 3, - reg_info)) - return false; - - /* Move to right after this alternative, including the - jump_past_alt. */ - p1 += mcnt; - - /* Break if it's the beginning of an n-th alternative - that doesn't begin with an on_failure_jump. */ - if ((re_opcode_t) *p1 != on_failure_jump) - break; - - /* Still have to check that it's not an n-th - alternative that starts with an on_failure_jump. */ - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if ((re_opcode_t) p1[mcnt-3] != jump_past_alt) - { - /* Get to the beginning of the n-th alternative. */ - p1 -= 3; - break; - } - } - - /* Deal with the last alternative: go back and get number - of the `jump_past_alt' just before it. `mcnt' contains - the length of the alternative. */ - EXTRACT_NUMBER (mcnt, p1 - 2); - - if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info)) - return false; - - p1 += mcnt; /* Get past the n-th alternative. */ - } /* if mcnt > 0 */ - break; - - - case stop_memory: - assert (p1[1] == **p); - *p = p1 + 2; - return true; - - - default: - if (!common_op_match_null_string_p (&p1, end, reg_info)) - return false; - } - } /* while p1 < end */ - - return false; -} /* group_match_null_string_p */ - - -/* Similar to group_match_null_string_p, but doesn't deal with alternatives: - It expects P to be the first byte of a single alternative and END one - byte past the last. The alternative can contain groups. */ - -static boolean -alt_match_null_string_p (p, end, reg_info) - unsigned char *p, *end; - register_info_type *reg_info; -{ - int mcnt; - unsigned char *p1 = p; - - while (p1 < end) - { - /* Skip over opcodes that can match nothing, and break when we get - to one that can't. */ - - switch ((re_opcode_t) *p1) - { - /* It's a loop. */ - case on_failure_jump: - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - break; - - default: - if (!common_op_match_null_string_p (&p1, end, reg_info)) - return false; - } - } /* while p1 < end */ - - return true; -} /* alt_match_null_string_p */ - - -/* Deals with the ops common to group_match_null_string_p and - alt_match_null_string_p. - - Sets P to one after the op and its arguments, if any. */ - -static boolean -common_op_match_null_string_p (p, end, reg_info) - unsigned char **p, *end; - register_info_type *reg_info; -{ - int mcnt; - boolean ret; - int reg_no; - unsigned char *p1 = *p; - - switch ((re_opcode_t) *p1++) - { - case no_op: - case begline: - case endline: - case begbuf: - case endbuf: - case wordbeg: - case wordend: - case wordbound: - case notwordbound: -#ifdef emacs - case before_dot: - case at_dot: - case after_dot: -#endif - break; - - case start_memory: - reg_no = *p1; - assert (reg_no > 0 && reg_no <= MAX_REGNUM); - ret = group_match_null_string_p (&p1, end, reg_info); - - /* Have to set this here in case we're checking a group which - contains a group and a back reference to it. */ - - if (REG_MATCH_NULL_STRING_P (reg_info[reg_no]) == MATCH_NULL_UNSET_VALUE) - REG_MATCH_NULL_STRING_P (reg_info[reg_no]) = ret; - - if (!ret) - return false; - break; - - /* If this is an optimized succeed_n for zero times, make the jump. */ - case jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if (mcnt >= 0) - p1 += mcnt; - else - return false; - break; - - case succeed_n: - /* Get to the number of times to succeed. */ - p1 += 2; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - - if (mcnt == 0) - { - p1 -= 4; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - } - else - return false; - break; - - case duplicate: - if (!REG_MATCH_NULL_STRING_P (reg_info[*p1])) - return false; - break; - - case set_number_at: - p1 += 4; - - default: - /* All other opcodes mean we cannot match the empty string. */ - return false; - } - - *p = p1; - return true; -} /* common_op_match_null_string_p */ - - -/* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN - bytes; nonzero otherwise. */ - -static int -bcmp_translate (s1, s2, len, translate) - unsigned char *s1, *s2; - register int len; - char *translate; -{ - register unsigned char *p1 = s1, *p2 = s2; - while (len) - { - if (translate[*p1++] != translate[*p2++]) return 1; - len--; - } - return 0; -} - -/* Entry points for GNU code. */ - -/* re_compile_pattern is the GNU regular expression compiler: it - compiles PATTERN (of length SIZE) and puts the result in BUFP. - Returns 0 if the pattern was valid, otherwise an error string. - - Assumes the `allocated' (and perhaps `buffer') and `translate' fields - are set in BUFP on entry. - - We call regex_compile to do the actual compilation. */ - -const char * -re_compile_pattern (pattern, length, bufp) - const char *pattern; - int length; - struct re_pattern_buffer *bufp; -{ - reg_errcode_t ret; - - /* GNU code is written to assume at least RE_NREGS registers will be set - (and at least one extra will be -1). */ - bufp->regs_allocated = REGS_UNALLOCATED; - - /* And GNU code determines whether or not to get register information - by passing null for the REGS argument to re_match, etc., not by - setting no_sub. */ - bufp->no_sub = 0; - - /* Match anchors at newline. */ - bufp->newline_anchor = 1; - - ret = regex_compile (pattern, length, re_syntax_options, bufp); - - return re_error_msg[(int) ret]; -} - -/* Entry points compatible with 4.2 BSD regex library. We don't define - them if this is an Emacs or POSIX compilation. */ - -#if !defined (emacs) && !defined (_POSIX_SOURCE) - -/* BSD has one and only one pattern buffer. */ -static struct re_pattern_buffer re_comp_buf; - -char * -re_comp (s) - const char *s; -{ - reg_errcode_t ret; - - if (!s) - { - if (!re_comp_buf.buffer) - return "No previous regular expression"; - return 0; - } - - if (!re_comp_buf.buffer) - { - re_comp_buf.buffer = (unsigned char *) malloc (200); - if (re_comp_buf.buffer == NULL) - return "Memory exhausted"; - re_comp_buf.allocated = 200; - - re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); - if (re_comp_buf.fastmap == NULL) - return "Memory exhausted"; - } - - /* Since `re_exec' always passes NULL for the `regs' argument, we - don't need to initialize the pattern buffer fields which affect it. */ - - /* Match anchors at newlines. */ - re_comp_buf.newline_anchor = 1; - - ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); - - /* Yes, we're discarding `const' here. */ - return (char *) re_error_msg[(int) ret]; -} - - -int -re_exec (s) - const char *s; -{ - const int len = strlen (s); - return - 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0); -} -#endif /* not emacs and not _POSIX_SOURCE */ - -/* POSIX.2 functions. Don't define these for Emacs. */ - -#ifndef emacs - -/* regcomp takes a regular expression as a string and compiles it. - - PREG is a regex_t *. We do not expect any fields to be initialized, - since POSIX says we shouldn't. Thus, we set - - `buffer' to the compiled pattern; - `used' to the length of the compiled pattern; - `syntax' to RE_SYNTAX_POSIX_EXTENDED if the - REG_EXTENDED bit in CFLAGS is set; otherwise, to - RE_SYNTAX_POSIX_BASIC; - `newline_anchor' to REG_NEWLINE being set in CFLAGS; - `fastmap' and `fastmap_accurate' to zero; - `re_nsub' to the number of subexpressions in PATTERN. - - PATTERN is the address of the pattern string. - - CFLAGS is a series of bits which affect compilation. - - If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we - use POSIX basic syntax. - - If REG_NEWLINE is set, then . and [^...] don't match newline. - Also, regexec will try a match beginning after every newline. - - If REG_ICASE is set, then we considers upper- and lowercase - versions of letters to be equivalent when matching. - - If REG_NOSUB is set, then when PREG is passed to regexec, that - routine will report only success or failure, and nothing about the - registers. - - It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for - the return codes and their meanings.) */ - -int -regcomp (preg, pattern, cflags) - regex_t *preg; - const char *pattern; - int cflags; -{ - reg_errcode_t ret; - unsigned syntax - = (cflags & REG_EXTENDED) ? - RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC; - - /* regex_compile will allocate the space for the compiled pattern. */ - preg->buffer = 0; - preg->allocated = 0; - preg->used = 0; - - /* Don't bother to use a fastmap when searching. This simplifies the - REG_NEWLINE case: if we used a fastmap, we'd have to put all the - characters after newlines into the fastmap. This way, we just try - every character. */ - preg->fastmap = 0; - - if (cflags & REG_ICASE) - { - unsigned i; - - preg->translate = (char *) malloc (CHAR_SET_SIZE); - if (preg->translate == NULL) - return (int) REG_ESPACE; - - /* Map uppercase characters to corresponding lowercase ones. */ - for (i = 0; i < CHAR_SET_SIZE; i++) - preg->translate[i] = ISUPPER (i) ? tolower (i) : i; - } - else - preg->translate = NULL; - - /* If REG_NEWLINE is set, newlines are treated differently. */ - if (cflags & REG_NEWLINE) - { /* REG_NEWLINE implies neither . nor [^...] match newline. */ - syntax &= ~RE_DOT_NEWLINE; - syntax |= RE_HAT_LISTS_NOT_NEWLINE; - /* It also changes the matching behavior. */ - preg->newline_anchor = 1; - } - else - preg->newline_anchor = 0; - - preg->no_sub = !!(cflags & REG_NOSUB); - - /* POSIX says a null character in the pattern terminates it, so we - can use strlen here in compiling the pattern. */ - ret = regex_compile (pattern, strlen (pattern), syntax, preg); - - /* POSIX doesn't distinguish between an unmatched open-group and an - unmatched close-group: both are REG_EPAREN. */ - if (ret == REG_ERPAREN) ret = REG_EPAREN; - - return (int) ret; -} - - -/* regexec searches for a given pattern, specified by PREG, in the - string STRING. - - If NMATCH is zero or REG_NOSUB was set in the cflags argument to - `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at - least NMATCH elements, and we set them to the offsets of the - corresponding matched substrings. - - EFLAGS specifies `execution flags' which affect matching: if - REG_NOTBOL is set, then ^ does not match at the beginning of the - string; if REG_NOTEOL is set, then $ does not match at the end. - - We return 0 if we find a match and REG_NOMATCH if not. */ - -int -regexec (preg, string, nmatch, pmatch, eflags) - const regex_t *preg; - const char *string; - size_t nmatch; - regmatch_t pmatch[]; - int eflags; -{ - int ret; - struct re_registers regs; - regex_t private_preg; - int len = strlen (string); - boolean want_reg_info = !preg->no_sub && nmatch > 0; - - private_preg = *preg; - - private_preg.not_bol = !!(eflags & REG_NOTBOL); - private_preg.not_eol = !!(eflags & REG_NOTEOL); - - /* The user has told us exactly how many registers to return - information about, via `nmatch'. We have to pass that on to the - matching routines. */ - private_preg.regs_allocated = REGS_FIXED; - - if (want_reg_info) - { - regs.num_regs = nmatch; - regs.start = TALLOC (nmatch, regoff_t); - regs.end = TALLOC (nmatch, regoff_t); - if (regs.start == NULL || regs.end == NULL) - return (int) REG_NOMATCH; - } - - /* Perform the searching operation. */ - ret = re_search (&private_preg, string, len, - /* start: */ 0, /* range: */ len, - want_reg_info ? ®s : (struct re_registers *) 0); - - /* Copy the register information to the POSIX structure. */ - if (want_reg_info) - { - if (ret >= 0) - { - unsigned r; - - for (r = 0; r < nmatch; r++) - { - pmatch[r].rm_so = regs.start[r]; - pmatch[r].rm_eo = regs.end[r]; - } - } - - /* If we needed the temporary register info, free the space now. */ - free (regs.start); - free (regs.end); - } - - /* We want zero return to mean success, unlike `re_search'. */ - return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH; -} - - -/* Returns a message corresponding to an error code, ERRCODE, returned - from either regcomp or regexec. We don't use PREG here. */ - -size_t -regerror (errcode, preg, errbuf, errbuf_size) - int errcode; - const regex_t *preg; - char *errbuf; - size_t errbuf_size; -{ - const char *msg; - size_t msg_size; - - if (errcode < 0 - || errcode >= (sizeof (re_error_msg) / sizeof (re_error_msg[0]))) - /* Only error codes returned by the rest of the code should be passed - to this routine. If we are given anything else, or if other regex - code generates an invalid error code, then the program has a bug. - Dump core so we can fix it. */ - abort (); - - msg = re_error_msg[errcode]; - - /* POSIX doesn't require that we do anything in this case, but why - not be nice. */ - if (! msg) - msg = "Success"; - - msg_size = strlen (msg) + 1; /* Includes the null. */ - - if (errbuf_size != 0) - { - if (msg_size > errbuf_size) - { - strncpy (errbuf, msg, errbuf_size - 1); - errbuf[errbuf_size - 1] = 0; - } - else - strcpy (errbuf, msg); - } - - return msg_size; -} - - -/* Free dynamically allocated space used by PREG. */ - -void -regfree (preg) - regex_t *preg; -{ - if (preg->buffer != NULL) - free (preg->buffer); - preg->buffer = NULL; - - preg->allocated = 0; - preg->used = 0; - - if (preg->fastmap != NULL) - free (preg->fastmap); - preg->fastmap = NULL; - preg->fastmap_accurate = 0; - - if (preg->translate != NULL) - free (preg->translate); - preg->translate = NULL; -} - -#endif /* not emacs */ - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/gnu/usr.bin/diff/regex.h b/gnu/usr.bin/diff/regex.h deleted file mode 100644 index a495005..0000000 --- a/gnu/usr.bin/diff/regex.h +++ /dev/null @@ -1,490 +0,0 @@ -/* Definitions for data structures and routines for the regular - expression library, version 0.12. - - Copyright (C) 1985, 89, 90, 91, 92, 1993 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __REGEXP_LIBRARY_H__ -#define __REGEXP_LIBRARY_H__ - -/* POSIX says that must be included (by the caller) before - . */ - -#ifdef VMS -/* VMS doesn't have `size_t' in , even though POSIX says it - should be there. */ -#include -#endif - - -/* The following bits are used to determine the regexp syntax we - recognize. The set/not-set meanings are chosen so that Emacs syntax - remains the value 0. The bits are given in alphabetical order, and - the definitions shifted by one from the previous bit; thus, when we - add or remove a bit, only one other definition need change. */ -typedef unsigned reg_syntax_t; - -/* If this bit is not set, then \ inside a bracket expression is literal. - If set, then such a \ quotes the following character. */ -#define RE_BACKSLASH_ESCAPE_IN_LISTS (1) - -/* If this bit is not set, then + and ? are operators, and \+ and \? are - literals. - If set, then \+ and \? are operators and + and ? are literals. */ -#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) - -/* If this bit is set, then character classes are supported. They are: - [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], - [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. - If not set, then character classes are not supported. */ -#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) - -/* If this bit is set, then ^ and $ are always anchors (outside bracket - expressions, of course). - If this bit is not set, then it depends: - ^ is an anchor if it is at the beginning of a regular - expression or after an open-group or an alternation operator; - $ is an anchor if it is at the end of a regular expression, or - before a close-group or an alternation operator. - - This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because - POSIX draft 11.2 says that * etc. in leading positions is undefined. - We already implemented a previous draft which made those constructs - invalid, though, so we haven't changed the code back. */ -#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) - -/* If this bit is set, then special characters are always special - regardless of where they are in the pattern. - If this bit is not set, then special characters are special only in - some contexts; otherwise they are ordinary. Specifically, - * + ? and intervals are only special when not after the beginning, - open-group, or alternation operator. */ -#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) - -/* If this bit is set, then *, +, ?, and { cannot be first in an re or - immediately after an alternation or begin-group operator. */ -#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) - -/* If this bit is set, then . matches newline. - If not set, then it doesn't. */ -#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) - -/* If this bit is set, then . doesn't match NUL. - If not set, then it does. */ -#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) - -/* If this bit is set, nonmatching lists [^...] do not match newline. - If not set, they do. */ -#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) - -/* If this bit is set, either \{...\} or {...} defines an - interval, depending on RE_NO_BK_BRACES. - If not set, \{, \}, {, and } are literals. */ -#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) - -/* If this bit is set, +, ? and | aren't recognized as operators. - If not set, they are. */ -#define RE_LIMITED_OPS (RE_INTERVALS << 1) - -/* If this bit is set, newline is an alternation operator. - If not set, newline is literal. */ -#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) - -/* If this bit is set, then `{...}' defines an interval, and \{ and \} - are literals. - If not set, then `\{...\}' defines an interval. */ -#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) - -/* If this bit is set, (...) defines a group, and \( and \) are literals. - If not set, \(...\) defines a group, and ( and ) are literals. */ -#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) - -/* If this bit is set, then \ matches . - If not set, then \ is a back-reference. */ -#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) - -/* If this bit is set, then | is an alternation operator, and \| is literal. - If not set, then \| is an alternation operator, and | is literal. */ -#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) - -/* If this bit is set, then an ending range point collating higher - than the starting range point, as in [z-a], is invalid. - If not set, then when ending range point collates higher than the - starting range point, the range is ignored. */ -#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) - -/* If this bit is set, then an unmatched ) is ordinary. - If not set, then an unmatched ) is invalid. */ -#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) - -/* This global variable defines the particular regexp syntax to use (for - some interfaces). When a regexp is compiled, the syntax used is - stored in the pattern buffer, so changing this does not affect - already-compiled regexps. */ -extern reg_syntax_t re_syntax_options; - -/* Define combinations of the above bits for the standard possibilities. - (The [[[ comments delimit what gets put into the Texinfo file, so - don't delete them!) */ -/* [[[begin syntaxes]]] */ -#define RE_SYNTAX_EMACS 0 - -#define RE_SYNTAX_AWK \ - (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - -#define RE_SYNTAX_POSIX_AWK \ - (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS) - -#define RE_SYNTAX_GREP \ - (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ - | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ - | RE_NEWLINE_ALT) - -#define RE_SYNTAX_EGREP \ - (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ - | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ - | RE_NO_BK_VBAR) - -#define RE_SYNTAX_POSIX_EGREP \ - (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES) - -/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ -#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC - -#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC - -/* Syntax bits common to both basic and extended POSIX regex syntax. */ -#define _RE_SYNTAX_POSIX_COMMON \ - (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ - | RE_INTERVALS | RE_NO_EMPTY_RANGES) - -#define RE_SYNTAX_POSIX_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) - -/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes - RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this - isn't minimal, since other operators, such as \`, aren't disabled. */ -#define RE_SYNTAX_POSIX_MINIMAL_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) - -#define RE_SYNTAX_POSIX_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - -/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS - replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */ -#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) -/* [[[end syntaxes]]] */ - -/* Maximum number of duplicates an interval can allow. Some systems - (erroneously) define this in other header files, but we want our - value, so remove any previous define. */ -#ifdef RE_DUP_MAX -#undef RE_DUP_MAX -#endif -#define RE_DUP_MAX ((1 << 15) - 1) - - -/* POSIX `cflags' bits (i.e., information for `regcomp'). */ - -/* If this bit is set, then use extended regular expression syntax. - If not set, then use basic regular expression syntax. */ -#define REG_EXTENDED 1 - -/* If this bit is set, then ignore case when matching. - If not set, then case is significant. */ -#define REG_ICASE (REG_EXTENDED << 1) - -/* If this bit is set, then anchors do not match at newline - characters in the string. - If not set, then anchors do match at newlines. */ -#define REG_NEWLINE (REG_ICASE << 1) - -/* If this bit is set, then report only success or fail in regexec. - If not set, then returns differ between not matching and errors. */ -#define REG_NOSUB (REG_NEWLINE << 1) - - -/* POSIX `eflags' bits (i.e., information for regexec). */ - -/* If this bit is set, then the beginning-of-line operator doesn't match - the beginning of the string (presumably because it's not the - beginning of a line). - If not set, then the beginning-of-line operator does match the - beginning of the string. */ -#define REG_NOTBOL 1 - -/* Like REG_NOTBOL, except for the end-of-line. */ -#define REG_NOTEOL (1 << 1) - - -/* If any error codes are removed, changed, or added, update the - `re_error_msg' table in regex.c. */ -typedef enum -{ - REG_NOERROR = 0, /* Success. */ - REG_NOMATCH, /* Didn't find a match (for regexec). */ - - /* POSIX regcomp return error codes. (In the order listed in the - standard.) */ - REG_BADPAT, /* Invalid pattern. */ - REG_ECOLLATE, /* Not implemented. */ - REG_ECTYPE, /* Invalid character class name. */ - REG_EESCAPE, /* Trailing backslash. */ - REG_ESUBREG, /* Invalid back reference. */ - REG_EBRACK, /* Unmatched left bracket. */ - REG_EPAREN, /* Parenthesis imbalance. */ - REG_EBRACE, /* Unmatched \{. */ - REG_BADBR, /* Invalid contents of \{\}. */ - REG_ERANGE, /* Invalid range end. */ - REG_ESPACE, /* Ran out of memory. */ - REG_BADRPT, /* No preceding re for repetition op. */ - - /* Error codes we've added. */ - REG_EEND, /* Premature end. */ - REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ - REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ -} reg_errcode_t; - -/* This data structure represents a compiled pattern. Before calling - the pattern compiler, the fields `buffer', `allocated', `fastmap', - `translate', and `no_sub' can be set. After the pattern has been - compiled, the `re_nsub' field is available. All other fields are - private to the regex routines. */ - -struct re_pattern_buffer -{ -/* [[[begin pattern_buffer]]] */ - /* Space that holds the compiled pattern. It is declared as - `unsigned char *' because its elements are - sometimes used as array indexes. */ - unsigned char *buffer; - - /* Number of bytes to which `buffer' points. */ - unsigned long allocated; - - /* Number of bytes actually used in `buffer'. */ - unsigned long used; - - /* Syntax setting with which the pattern was compiled. */ - reg_syntax_t syntax; - - /* Pointer to a fastmap, if any, otherwise zero. re_search uses - the fastmap, if there is one, to skip over impossible - starting points for matches. */ - char *fastmap; - - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation - is applied to a pattern when it is compiled and to a string - when it is matched. */ - char *translate; - - /* Number of subexpressions found by the compiler. */ - size_t re_nsub; - - /* Zero if this pattern cannot match the empty string, one else. - Well, in truth it's used only in `re_search_2', to see - whether or not we should use the fastmap, so we don't set - this absolutely perfectly; see `re_compile_fastmap' (the - `duplicate' case). */ - unsigned can_be_null : 1; - - /* If REGS_UNALLOCATED, allocate space in the `regs' structure - for `max (RE_NREGS, re_nsub + 1)' groups. - If REGS_REALLOCATE, reallocate space if necessary. - If REGS_FIXED, use what's there. */ -#define REGS_UNALLOCATED 0 -#define REGS_REALLOCATE 1 -#define REGS_FIXED 2 - unsigned regs_allocated : 2; - - /* Set to zero when `regex_compile' compiles a pattern; set to one - by `re_compile_fastmap' if it updates the fastmap. */ - unsigned fastmap_accurate : 1; - - /* If set, `re_match_2' does not return information about - subexpressions. */ - unsigned no_sub : 1; - - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ - unsigned not_bol : 1; - - /* Similarly for an end-of-line anchor. */ - unsigned not_eol : 1; - - /* If true, an anchor at a newline matches. */ - unsigned newline_anchor : 1; - -/* [[[end pattern_buffer]]] */ -}; - -typedef struct re_pattern_buffer regex_t; - - -/* search.c (search_buffer) in Emacs needs this one opcode value. It is - defined both in `regex.c' and here. */ -#define RE_EXACTN_VALUE 1 - -/* Type for byte offsets within the string. POSIX mandates this. */ -typedef int regoff_t; - - -/* This is the structure we store register match data in. See - regex.texinfo for a full description of what registers match. */ -struct re_registers -{ - unsigned num_regs; - regoff_t *start; - regoff_t *end; -}; - - -/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, - `re_match_2' returns information about at least this many registers - the first time a `regs' structure is passed. */ -#ifndef RE_NREGS -#define RE_NREGS 30 -#endif - - -/* POSIX specification for registers. Aside from the different names than - `re_registers', POSIX uses an array of structures, instead of a - structure of arrays. */ -typedef struct -{ - regoff_t rm_so; /* Byte offset from string's start to substring's start. */ - regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ -} regmatch_t; - -/* Declarations for routines. */ - -/* To avoid duplicating every routine declaration -- once with a - prototype (if we are ANSI), and once without (if we aren't) -- we - use the following macro to declare argument types. This - unfortunately clutters up the declarations a bit, but I think it's - worth it. */ - -#if __STDC__ - -#define _RE_ARGS(args) args - -#else /* not __STDC__ */ - -#define _RE_ARGS(args) () - -#endif /* not __STDC__ */ - -/* Sets the current default syntax to SYNTAX, and return the old syntax. - You can also simply assign to the `re_syntax_options' variable. */ -extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); - -/* Compile the regular expression PATTERN, with length LENGTH - and syntax given by the global `re_syntax_options', into the buffer - BUFFER. Return NULL if successful, and an error string if not. */ -extern const char *re_compile_pattern - _RE_ARGS ((const char *pattern, int length, - struct re_pattern_buffer *buffer)); - - -/* Compile a fastmap for the compiled pattern in BUFFER; used to - accelerate searches. Return 0 if successful and -2 if was an - internal error. */ -extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); - - -/* Search in the string STRING (with length LENGTH) for the pattern - compiled into BUFFER. Start searching at position START, for RANGE - characters. Return the starting position of the match, -1 for no - match, or -2 for an internal error. Also return register - information in REGS (if REGS and BUFFER->no_sub are nonzero). */ -extern int re_search - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, int range, struct re_registers *regs)); - - -/* Like `re_search', but search in the concatenation of STRING1 and - STRING2. Also, stop searching at index START + STOP. */ -extern int re_search_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, int range, struct re_registers *regs, int stop)); - - -/* Like `re_search', but return how many characters in STRING the regexp - in BUFFER matched, starting at position START. */ -extern int re_match - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, struct re_registers *regs)); - - -/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ -extern int re_match_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, struct re_registers *regs, int stop)); - - -/* Set REGS to hold NUM_REGS registers, storing them in STARTS and - ENDS. Subsequent matches using BUFFER and REGS will use this memory - for recording register information. STARTS and ENDS must be - allocated with malloc, and must each be at least `NUM_REGS * sizeof - (regoff_t)' bytes long. - - If NUM_REGS == 0, then subsequent matches should allocate their own - register data. - - Unless this function is called, the first search or match using - PATTERN_BUFFER will allocate its own register data, without - freeing the old data. */ -extern void re_set_registers - _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, - unsigned num_regs, regoff_t *starts, regoff_t *ends)); - -/* 4.2 bsd compatibility. */ -extern char *re_comp _RE_ARGS ((const char *)); -extern int re_exec _RE_ARGS ((const char *)); - -/* POSIX compatibility. */ -extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags)); -extern int regexec - _RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch, - regmatch_t pmatch[], int eflags)); -extern size_t regerror - _RE_ARGS ((int errcode, const regex_t *preg, char *errbuf, - size_t errbuf_size)); -extern void regfree _RE_ARGS ((regex_t *preg)); - -#endif /* not __REGEXP_LIBRARY_H__ */ - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/gnu/usr.bin/gdb/ChangeLog b/gnu/usr.bin/gdb/ChangeLog deleted file mode 100644 index 1f2342b..0000000 --- a/gnu/usr.bin/gdb/ChangeLog +++ /dev/null @@ -1,4887 +0,0 @@ -Thu Feb 8 01:11:55 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu) - - * GDB 3.5 released. - - * version.c: Change version number to 3.5 - -Tue Feb 6 15:58:06 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu) - - * m-hp9k320.h: define ATTACH_DETACH. - hp9k320-dep.c [ATTACH_DETACH]: New code. - -Thu Feb 1 17:43:00 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu) - - * valprint.c (is_nan, val_print): Use char * not void *. - - * symmisc.c (print_symbol): Print newline after label. - -Tue Jan 30 15:35:52 1990 Jim Kingdon (kingdon at albert.ai.mit.edu) - - * Makefile.dist (READLINE): Add {readline,history}.texinfo. - - * m-merlin.h: Put in clarifying comments about SHELL_FILE. - config.gdb (merlin): Explain about /usr/local/lib/gdb-sh. - -Sat Jan 27 02:30:27 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu) - - * version.c: Change version number to 3.5alpha.1. - - * dbxread.c (process_one_symbol): Compare context_stack_depth - with !VARIABLES_INSIDE_BLOCK, not VARIABLES_INSIDE_BLOCK. - -Fri Jan 26 01:21:51 1990 Jim Kingdon (kingdon at mole.ai.mit.edu) - - * main.c [ALIGN_STACK_ON_STARTUP]: New code. - m-i386.h: Define ALIGN_STACK_ON_STARTUP. - - * m-merlin.h (NO_SIGINTERRUPT, SHELL_FILE): Define. - - * umax-dep.c (exec_file_command): Add commas to call to - read_section_hdr. - -Tue Jan 23 15:49:47 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu) - - * dbxread.c (define_symbol): Deal with deftype 'X'. - - * convex-dep.c (wait): Make it pid_t. - - * convex-dep.c (comm_registers_info): accept decimal comm register - specification, as "i comm 32768". - - * dbxread.c (process_one_symbol): Make VARIABLES_INSIDE_BLOCK - macro say by itself where variables are. Pass it desc. - m-convex.h (VARIABLES_INSIDE_BLOCK): Nonzero for native compiler. - - * m-convex.h (SET_STACK_LIMIT_HUGE): Define. - (IGNORE_SYMBOL): Take out #ifdef N_MONPT and put in 0xc4. - -Fri Jan 19 20:04:15 1990 Jim Kingdon (kingdon at albert.ai.mit.edu) - - * printcmd.c (print_frame_args): Always set highest_offset to - current_offset when former is -1. - - * dbxread.c (read_struct_type): Print nice error message - when encountering multiple inheritance. - -Thu Jan 18 13:43:30 1990 Jim Kingdon (kingdon at mole.ai.mit.edu) - - * dbxread.c (read_dbx_symtab): Always treat N_FN as a potential - source for a x.o or -lx symbol, ignoring OFILE_FN_FLAGGED. - - * printcmd.c (print_frame_args): Cast -1 to (CORE_ADDR). - - * hp300bsd-dep.c (_initialize_hp300_dep): Get kernel_u_addr. - m-hp300bsd.h (KERNEL_U_ADDR): Use kernel_u_addr. - - * infcmd.c (run_command): #if 0 out call to - breakpoint_clear_ignore_counts. - -Thu Jan 11 12:58:12 1990 Jim Kingdon (kingdon at mole) - - * printcmd.c (print_frame_args) [STRUCT_ARG_SYM_GARBAGE]: - Try looking up name of var before giving up & printing '?'. - -Wed Jan 10 14:00:14 1990 Jim Kingdon (kingdon at pogo) - - * many files: Move stdio.h before param.h. - - * sun3-dep.c (store_inferior_registers): Only try to write FP - regs #ifdef FP0_REGNUM. - -Mon Jan 8 17:56:15 1990 Jim Kingdon (kingdon at pogo) - - * symtab.c: #if 0 out "info methods" code. - -Sat Jan 6 12:33:04 1990 Jim Kingdon (kingdon at pogo) - - * dbxread.c (read_struct_type): Set TYPE_NFN_FIELDS_TOTAL - from all baseclasses; remove vestigial variable baseclass. - - * findvar.c (read_var_value): Check REG_STRUCT_HAS_ADDR. - printcmd.c (print_frame_args): Check STRUCT_ARG_SYM_GARBAGE. - m-sparc.h: Define REG_STRUCT_HAS_ADDR and STRUCT_ARG_SYM_GARBAGE. - - * blockframe.c (get_frame_block): Subtract one from pc if not - innermost frame. - -Fri Dec 29 15:26:33 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * printcmd.c (print_frame_args): check highest_offset != -1, not i. - -Thu Dec 28 16:21:02 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * valops.c (value_struct_elt): Clean up error msg. - - * breakpoint.c (describe_other_breakpoints): - Delete extra space before "also set at" and add period at end. - -Tue Dec 19 10:28:42 1989 Jim Kingdon (kingdon at pogo) - - * source.c (print_source_lines): Tell user which line number - was out of range when printing error message. - -Sun Dec 17 14:14:09 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * blockframe.c (find_pc_partial_function): Use - BLOCK_START (SYMBOL_BLOCK_VALUE (f)) instead of - SYMBOL_VALUE (f) to get start of function. - - * dbxread.c: Make xxmalloc just a #define for xmalloc. - -Thu Dec 14 16:13:16 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * m68k-opcode.h (fseq & following fp instructions): - Change @ to $. - -Fri Dec 8 19:06:44 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * breakpoint.c (breakpoint_clear_ignore_counts): New function. - infcmd.c (run_command): Call it. - -Wed Dec 6 15:03:38 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * valprint.c: Change it so "array-max 0" means there is - no limit. - - * expread.y (yylex): Change error message "invalid token in - expression" to "invalid character '%c' in expression". - -Mon Dec 4 16:12:54 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * blockframe.c (find_pc_partial_function): Always return 1 - for success, 0 for failure, and set *NAME and *ADDRESS to - match the return value. - - * dbxread.c (symbol_file_command): Use perror_with_name on - error from stat. - (psymtab_to_symtab, add_file_command), - core.c (validate_files), source.c (find_source_lines), - default-dep.c (exec_file_command): Check for errors from stat, - fstat, and myread. - -Fri Dec 1 05:16:42 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * valops.c (check_field): When following pointers, just get - their types; don't call value_ind. - -Thu Nov 30 14:45:29 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * config.gdb (pyr): New machine. - core.c [REG_STACK_SEGMENT]: New code. - dbxread.c (process_one_symbol): Cast return from copy_pending - to long before casting to enum namespace. - infrun.c: Split registers_info into DO_REGISTERS_INFO - and registers_info. - m-pyr.h, pyr-{dep.c,opcode.h,pinsn.c}: New files. - - * hp300bsd-dep.c: Stay in sync with default-dep.c. - - * m-hp300bsd.h (IN_SIGTRAMP): Define. - -Mon Nov 27 23:48:21 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * m-sparc.h (EXTRACT_RETURN_VALUE, STORE_RETURN_VALUE): - Return floating point values in %f0. - -Tue Nov 21 00:34:46 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * dbxread.c (read_type): #if 0 out code which skips to - comma following x-ref. - -Sat Nov 18 20:10:54 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * valprint.c (val_print): Undo changes of Nov 11 & 16. - (print_string): Add parameter force_ellipses. - (val_print): Pass force_ellipses true when we stop fetching string - before we get to the end, else pass false. - -Thu Nov 16 11:59:50 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * infrun.c (restore_inferior_status): Don't try to restore - selected frame if the inferior no longer exists. - - * valprint.c (val_print): Rewrite string printing code not to - call print_string. - - * Makefile.dist (clean): Remove xgdb and xgdb.o. - -Tue Nov 14 12:41:47 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * Makefile.dist (XGDB, bindir, xbindir, install, all): New stuff. - -Sat Nov 11 15:29:38 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * valprint.c (val_print): chars_to_get: New variable. - -Thu Nov 9 12:31:47 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * main.c (main): Process "-help" as a switch that doesn't - take an argument. - -Wed Nov 8 13:07:02 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * Makefile.dist (gdb.tar.Z): Add "else true". - -Tue Nov 7 12:25:14 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * infrun.c (restore_inferior_status): Don't dereference fid if NULL. - - * config.gdb (sun3, sun4): Accept "sun3" and "sun4". - -Mon Nov 6 09:49:23 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * Makefile.dist (Makefile): Move comments after commands. - - * *-dep.c [READ_COFF_SYMTAB]: Pass optional header size to - read_section_hdr(). - - * inflow.c: Include regardless of USG. - - * coffread.c (read_section_hdr): Add optional_header_size. - (symbol_file_command): Pass optional header size to - read_section_hdr(). - (read_coff_symtab): Initialize filestring. - - * version.c: Change version to 3.4.xxx. - - * GDB 3.4 released. - -Sun Nov 5 11:39:01 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * version.c: Change version to 3.4. - - * symtab.c (decode_line_1): Only skip past "struct" if it - is there. - - * valops.c (value_ind), eval.c (evaluate_subexp, case UNOP_IND): - Have "*" return an int, not a LONGEST. - - * utils.c (fprintf_filtered): Pass arg{4,5,6} to sprintf. - - * printcmd.c (x_command): Use variable itself rather - than treating it as a pointer only if it is a function. - (See comment "this makes x/i main work"). - - * coffread.c (symbol_file_command): Use error for - "%s does not have a symbol-table.\n". - -Wed Nov 1 19:56:18 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * dbxread.c [BELIEVE_PCC_PROMOTION_TYPE]: New code. - m-sparc.h: Define BELIEVE_PCC_PROMOTION_TYPE. - -Thu Oct 26 12:45:00 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * infrun.c: Include . - - * dbxread.c (read_dbx_symtab, case N_LSYM, case 'T'): - Check for enum types and put constants in psymtab. - -Mon Oct 23 15:02:25 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * dbxread.c (define_symbol, read_dbx_symtab): Handle enum - constants (e.g. "b:c=e6,0"). - -Thu Oct 19 14:57:26 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * stack.c (frame_info): Use FRAME_ARGS_ADDRESS_CORRECT - m-vax.h (FRAME_ARGS_ADDRESS_CORRECT): New macro. - (FRAME_ARGS_ADDRESS): Restore old meaning. - - * frame.h (Frame_unknown): New macro. - stack.c (frame_info): Check for Frame_unknown return from - FRAME_ARGS_ADDRESS. - m-vax.h (FRAME_ARGS_ADDRESS): Sometimes return Frame_unknown. - - * utils.c (fatal_dump_core): Add "internal error" to message. - - * infrun.c (IN_SIGTRAMP): New macro. - (wait_for_inferior): Use IN_SIGTRAMP. - m-vax.h (IN_SIGTRAMP): New macro. - -Wed Oct 18 15:09:22 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * config.gdb, Makefile.dist: Shorten m-i386-sv32.h. - - * coffread.c (symbol_file_command): Pass 0 to select_source_symtab. - -Tue Oct 17 12:24:41 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * i386-dep.c (i386_frame_num_args): Take function from m-i386.h - file. Check for pfi null. - m-i386.h (FRAME_NUM_ARGS): Use i386_frame_num_args. - - * infrun.c (wait_for_inferior): set stop_func_name to 0 - before calling find_pc_partial_function. - -Thu Oct 12 01:08:50 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * breakpoint.c (_initialize_breakpoint): Add "disa". - - * Makefile.dist: Add GLOBAL_CFLAGS and pass to readline. - - * config.gdb (various): "$machine =" -> "machine =". - -Wed Oct 11 11:54:31 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * inflow.c (try_writing_regs): #if 0 out this function. - - * main.c (main): Add "-help" option. - - * dbxread.c (read_dbx_symtab): Merge code for N_FUN with - N_STSYM, etc. - -Mon Oct 9 14:21:55 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * inflow.c (try_writing_regs_command): Don't write past end - of struct user. - - * dbxread.c (read_struct_type): #if 0 out code which checks for - bitpos and bitsize 0. - - * config.gdb: Accept sequent-i386 (not seq386). - (symmetry): Set depfile and paramfile. - - * m-convex.h (IGNORE_SYMBOL): Check for N_MONPT if defined. - -Thu Oct 5 10:14:26 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * default-dep.c (read_inferior_memory): Put #if 0'd out comment - within /* */. - -Wed Oct 4 18:44:41 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * config.gdb: Change /dev/null to m-i386.h for various - 386 machine "opcodefile" entries. - - * config.gdb: Accept seq386 for sequent symmetry. - -Mon Oct 2 09:59:50 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * hp300bsd-dep.c: Fix copyright notice. - -Sun Oct 1 16:25:30 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * Makefile.dist (DEPFILES): Add isi-dep.c. - - * default-dep.c (read_inferior_memory): Move #endif after else. - -Sat Sep 30 12:50:16 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * version.c: Change version number to 3.3.xxx. - - * GDB 3.3 released. - - * version.c: Change version number to 3.3. - - * Makefile.dist (READLINE): Add vi_mode.c - - * config.gdb (i386): Change /dev/null to m-i386.h - - * config.gdb: Add ';;' before 'esac'. - - * Makefile.dist (gdb.tar.Z): Move comment above dependency. - - * dbxread.c (read_ofile_symtab): Check symbol before start - of source file for GCC_COMPILED_FLAG_SYMBOL. - (start_symtab): Don't clear processing_gcc_compilation. - -Thu Sep 28 22:30:23 1989 Roland McGrath (roland at hobbes.ai.mit.edu) - - * valprint.c (print_string): If LENGTH is zero, print "". - -Wed Sep 27 10:15:10 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * config.gdb: "rm tmp.c" -> "rm -f tmp.c". - -Tue Sep 26 13:02:10 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * utils.c (_initialize_utils): Use termcap to set lines_per_page - and chars_per_line. - -Mon Sep 25 10:06:43 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * dbxread.c (read_dbx_symtab, N_SOL): Do not add the same file - more than once. - -Thu Sep 21 12:43:18 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * infcmd.c (unset_environment_command): Delete all variables - if called with no arg. - - * remote.c, inferior.h (remote_{read,write}_inferior_memory): - New functions. - core.c ({read,write}_memory): Use remote_{read,write}_inferior_memory. - - * valops.c (call_function): When reserving stack space for - arguments, call value_arg_coerce. - - * m-hp9k320.h: define BROKEN_LARGE_ALLOCA. - - * breakpoint.c (delete_command): Ask for confirmation only - when there are breakpoints. - - * dbxread.c (read_struct_type): If lookup_basetype_type has - copied a stub type, call add_undefined_type. - - * sparc_pinsn.c (compare_opcodes): Check for "1+i" anywhere - in args. - - * val_print.c (type_print_base): Print stub types as - "". - -Wed Sep 20 07:32:00 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * sparc-opcode.h (swapa): Remove i bit from match. - (all alternate space instructions): Delete surplus "foo rs1+0" - patterns. - - * Makefile.dist (LDFLAGS): Set to $(CFLAGS). - - * remote-multi.shar (remote_utils.c, putpkt): Change csum to unsigned. - -Tue Sep 19 14:15:16 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * sparc-opcode.h: Set i bit in lose for many instructions which - aren't immediate. - - * stack.c (print_frame_info): add "func = 0". - -Mon Sep 18 16:19:48 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * sparc-opcode.h (mov): Add mov to/from %tbr, %psr, %wim. - - * sparc-opcode.h (rett): Fix notation to use suggested assembler - syntax from architecture manual. - - * symmetry-dep.c (I386_REGNO_TO_SYMMETRY): New macro. - (i386_frame_find_saved_regs): Use I386_REGNO_TO_SYMMETRY. - -Sat Sep 16 22:21:17 1989 Jim Kingdon (kingdon at spiff) - - * remote.c (remote_close): Set remote_desc to -1. - - * gdb.texinfo (Output): Fix description of echo to match - reality and ANSI C. - -Fri Sep 15 14:28:59 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * symtab.c (lookup_symbol): Add comment about "asm". - - * sparc-pinsn.c: Use NUMOPCODES. - - * sparc-opcode.h (NUMOPCODES): Use sparc_opcodes[0] not *sparc_opcodes. - -Thu Sep 14 15:25:20 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * dbxread.c (xxmalloc): Print error message before calling abort(). - - * infrun.c (wait_for_inferior): Check for {stop,prev}_func_name - null before passing to strcmp. - -Wed Sep 13 12:34:15 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * sparc-opcode.h: New field delayed. - sparc-pinsn.c (is_delayed_branch): New function. - (print_insn): Check for delayed branches. - - * stack.c (print_frame_info): Use misc_function_vector in - case where ar truncates file names. - -Tue Sep 12 00:16:14 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * convex-dep.c (psw_info): Move "struct pswbit *p" with declarations. - -Mon Sep 11 14:59:57 1989 Jim Kingdon (kingdon at spiff) - - * convex-dep.c (core_file_command): Delete redundant printing - of "Program %s". - - * m-convex.h (ENTRY_POINT): New macro. - - * m-convex.h (FRAME_CHAIN_VALID): Change outside_first_object_file - to outside_startup_file - - * main.c: #if 0 out catch_termination and related code. - - * command.c (lookup_cmd_1): Consider underscores part of - command names. - -Sun Sep 10 09:20:12 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * printcmd.c: Change asdump_command to disassemble_command - (_initialize_printcmd): Change asdump to diassemble. - - * main.c (main): Exit with code 0 if we hit the end of a batch - file. - - * Makefile.dist (libreadline.a): Fix syntax of "CC=${CC}". - -Sat Sep 9 01:07:18 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * values.c (history_info): Renamed to value_history_info. - Command renamed to "info value" (with "info history" still - accepted). - - * sparc-pinsn.c (print_insn): Extend symbolic address printing - to cover "sethi" following by an insn which uses 1+i. - -Fri Sep 8 14:24:01 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * m-hp9k320.h, m-hp300bsd.h, m-altos.h, m-sparc.h, m-sun3.h - (READ_GDB_SYMSEGS): Remove. - dbxread.c [READ_GDB_SYMSEGS]: Remove code to read symsegs. - - * sparc-pinsn.c (print_insn): Detect "sethi-or" pairs and - print symbolic address. - - * sparc-opcode.h (sethi, set): Change lose from 0xc0000000 to - 0xc0c00000000. - - * remote.c (remote_desc): Initialize to -1. - - * Makefile.dist (libreadline.a): Pass CC='${CC}' to readline makefile. - -Thu Sep 7 00:07:17 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * dbxread.c (read_struct_type): Check for static member functions. - values.c, eval.c, valarith.c, valprint.c, valops.c: Merge changes - from Tiemann for static member functions. - - * sparc-opcode.h (tst): Fix all 3 patterns. - - * Makefile.dist (gdb1): New rule. - - * sparc-opcode.h: Change comment about what the disassembler - does with the order of the opcodes. - - * sparc-pinsn.c (compare_opcodes): Put 1+i before i+1. - Also fix mistaken comment about preserving order of original table. - - * sparc-opcode.h (clr, mov): Fix incorrect lose entries. - - * m-symmetry.h (FRAME_NUM_ARGS): Add check to deal with code that - GCC sometimes generates. - - * config.gdb: Change all occurances of "skip" to "/dev/null". - - * README (about languages other than C): Update comments about - Pascal and FORTRAN. - - * sparc-opcode.h (nop): Change lose from 0xae3fffff to 0xfe3fffff. - - * values.c (value_virtual_fn_field): #if 0-out assignment to - VALUE_TYPE(vtbl). - -Wed Sep 6 12:19:22 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * utils.c (fatal_dump_core): New function. - Makefile.dist (MALLOC_FLAGS): use -Dbotch=fatal_dump_core - -Tue Sep 5 15:47:18 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * breakpoint.c (enable_command): With no arg, enable all bkpts. - - * Makefile.dist (Makefile): Remove \"'s around $(MD). - - * Makefile.dist: In "cd readline; make . . ." change first - SYSV_DEFINE to SYSV. - - * m68k-pinsn.c (_initialize_pinsn): Use alternate assembler - syntax #ifdef HPUX_ASM - -Sat Sep 2 23:24:43 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * values.c (history_info): Don't check num_exp[0] if num_exp - is nil (just like recent editing_info change). - -Fri Sep 1 19:19:01 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * gdb.texinfo (inc-history, inc-readline): Copy in the inc-* files - because people might not have makeinfo. - - * README (xgdb): Strengthen nasty comments. - - * gdb.texinfo: Change @setfilename to "gdb.info". - -Thu Aug 31 17:23:50 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * main.c (editing_info): Don't check arg[0] if arg is null. - - * m-vax.h: Add comment about known sigtramp bug. - - * sun3-dep.c, sparc-dep.c (IS_OBJECT_FILE, exec_file_command): - Get right text & data addresses for .o files. - -Wed Aug 30 13:54:19 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * utils.c (tilde_expand): Remove function (it's in readline). - - * sparc-opcode.h (call): Change "8" to "9" in first two - patterns (%g7->%o7). - -Tue Aug 29 16:44:41 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * printcmd.c (whatis_command): Change 4th arg to type_print - from 1 to -1. - -Mon Aug 28 12:22:41 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * dbxread.c (psymtab_to_symtab_1): In "and %s ..." change - pst->filename to pst->dependencies[i]->filename. - - * blockframe.c (FRAMELESS_LOOK_FOR_PROLOGUE): New macro - made from FRAMELESS_FUNCTION_INVOCATION from m-sun3.h except - that it checks for zero return from get_pc_function_start. - m-hp9k320.h, m-hp300bsd.h, m-i386.h, m-isi.h, m-altos.h, - m-news.h, m-sparc.h, m-sun2.h, m-sun3.h, m-symmetry.h - (FRAMELESS_FUNCTION_INVOCATION): Use FRAMELESS_LOOK_FOR_PROLOGUE. - - * dbxread.c (read_struct_type): Give warning and ignore field - if bitpos and bitsize are zero. - -Sun Aug 27 04:55:20 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * dbxread.c (psymtab_to_symtab{,_1}): Print message about - reading in symbols before reading stringtab, not after. - -Sat Aug 26 02:01:53 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * dbxread.c (IS_OBJECT_FILE, ADDR_OF_TEXT_SEGMENT): New macros. - (read_dbx_symtab): Use text_addr & text_size to set end_of_text_addr. - (symbol_file_command): pass text_addr & text_size to read_dbx_symtab. - -Fri Aug 25 23:08:13 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * valprint.c (value_print): Try to give the name of function - pointed to when printing a function pointer. - -Thu Aug 24 23:18:40 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * core.c (xfer_core_file): In cases where MEMADDR is above the - largest address that makes sense, set i to len. - -Thu Aug 24 16:04:17 1989 Roland McGrath (roland at hobbes.ai.mit.edu) - - * valprint.c (print_string): New function to print a character - string, doing array-max limiting and repeat count processing. - (val_print, value_print): Use print_string. - (REPEAT_COUNT_THRESHOLD): New #define, the max number of elts to print - without using a repeat count. Set to ten. - (value_print, val_print): Use REPEAT_COUNT_THRESHOLD. - - * utils.c (printchar): Use {fputs,fprintf}_filtered. - - * valprint.c (val_print): Pass the repeat count arg to the - fprintf_filtered call for "" messages. - -Wed Aug 23 22:53:47 1989 Roland McGrath (roland at hobbes.ai.mit.edu) - - * utils.c: Include . - - * main.c: Declare free. - -Wed Aug 23 05:05:59 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * utils.c, defs.h: Add tilde_expand. - source.c (directory_command), - main.c (cd_command), - main.c (set_history_filename), - dbxread.c (symbol_file_command), - coffread.c (symbol_file_command), - dbxread.c (add_file_command), - symmisc.c (print_symtabs), - *-dep.c (exec_file_command, core_file_command), - main.c (source_command): Use tilde_expand. - - * dbxread.c (read_type): When we get a cross-reference, resolve - it immediately if possible, only calling add_undefined_type if - necessary. - - * gdb.texinfo: Uncomment @includes and put comment at start - of file telling people to use makeinfo. - - * valprint.c (type_print_base): Print the right thing for - bitfields. - - * config.gdb (sun3os3): Set paramfile and depfile. - -Tue Aug 22 05:38:36 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * dbxread.c (symbol_file_command): Pass string table size to - read_dbx_symtab(). - (read_dbx_symtab): Before indexing into string table, check - string table index for reasonableness. - (psymtab_to_symtab{,_1}, read_ofile_symtab): Same. - -Tue Aug 22 04:04:39 1989 Roland McGrath (roland at hobbes.ai.mit.edu) - - * m68k-pinsn.c: Replaced many calls to fprintf and fputs with - calls to fprintf_filtered and fputs_filtered. - (print_insn_arg): Use normal MIT 68k syntax for postincrement, - predecrement, and register indirect addressing modes. - -Mon Aug 21 10:08:02 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * main.c (initialize_signals): Set signal handler for SIGQUIT - and SIGHUP to do_nothing. - - * ns32k-opcode.h (ord): Change 1D1D to 1D2D. - - * ns32k-pinsn.c (print_insn_arg, print_insn): Handle index - bytes correctly. - - * ns32k-opcode.h: Add comments. - - * dbxread.c (read_type): Put enum fields in type.fields in order - that they were found in the debugging symbols (not reverse order). - -Sun Aug 20 21:17:13 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * main.c (source_command): Read .gdbinit if run without argument. - - * source.c (directory_command): Only print "foo already in path" - if from_tty. - - * version.c: Change version number to 3.2.xxx - -Sat Aug 19 00:24:08 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * m-news.h: Define HAVE_WAIT_STRUCT. - - * m-isi.h, isi-dep.c: Replace with new version from Adam de Boor. - config.gdb: Remove isibsd43. - - * main.c (catch_termination): Don't say we have written - .gdb_history until after we really have. - - * convex-dep.c (attach): Add "sleep (1)". - (write_vector_register): Use "LL" with long long constant. - (wait): Close comment. - (wait): Change "unix 7.1 bug" to "unix 7.1 feature" & related - changes in comment. - (scan_stack): And fp with 0x80000000 in while loop test. - (core_file_command): Move code to set COREFILE. - (many places): Change printf to printf_filtered. - (psw_info): Allow argument giving value to print as a psw. - (_initialize_convex_dep): Update docstrings. - - * m-convex.h (WORDS_BIG_ENDIAN): Correct typo ("WRODS") - define NO_SIGINTERRUPT. - define SET_STACK_LIMIT_HUGE. - add "undef BUILTIN_TYPE_LONGEST" before defining it. - Use "LL" after constants in CALL_DUMMY. - - * dbxread.c: In the 3 places it says error "ridiculous string - table size"... delete extra parameter to error. - - * dbxread.c (scan_file_globals): Check for FORTRAN common block. - Allow multiple references for the sake of common blocks. - - * main.c (initialize_main): Set history_filename to include - current directory. - - * valprint.c (decode_format): Don't return a defaulted size - field if osize is zero. - - * gdb.texinfo (Compilation): Update information on -gg symbols. - Document problem with ar. - -Fri Aug 18 19:45:20 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * valprint.c (val_print, value_print): Add "" code. - Also put "..." outside quotes for strings. - - * main.c (initialize_main): Add comment about history output file - being different from history input file. - - * m-newsos3.h: Undefine NO_SIGINTERRUPT. Rearrange a few comments. - - * m-newsos3.h (REGISTER_U_ADDR): Use new version from Hikichi. - - * sparc-opcode.h: Add comment clarifying meaning of the order of - the entries in sparc_opcodes. - - * eval.c (evaluate_subexp, case UNOP_IND): Deal with deferencing - things that are not pointers. - - * valops.c (value_ind): Make dereferencing an int give a LONGEST. - - * expprint.c (print_subexp): Add (int) cast in OP_LAST case. - - * dbxread.c (read_array_type): Set lower and upper if adjustable. - - * symtab.c (lookup_symbol): Don't abort if symbol found in psymtab - but not in symtab. - -Thu Aug 17 15:51:20 1989 Randy Smith (randy at hobbes.ai.mit.edu) - - * config.gdb: Changed "Makefile.c" to "Makefile.dist". - -Thu Aug 17 01:58:04 1989 Roland McGrath (roland at apple-gunkies.ai.mit.edu) - - * sparc-opcode.h (or): Removed incorrect lose bit 0x08000000. - [many]: Changed many `lose' entries to have the 0x10 bit set, so - they don't think %l0 is %g0. - -Wed Aug 16 00:30:44 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * m-symmetry.h (STORE_STRUCT_RETURN): Also write reg 0. - (EXTRACT_RETURN_VALUE): Call symmetry_extract_return_value. - symmetry-dep.c (symmetry_extract_return_value): New fn. - - * main.c (symbol_completion_function): Deal with changed - result_list from lookup_cmd_1 for ambiguous return. - command.c (lookup_cmd): Same. - - * inflow.c [TIOCGETC]: Move #include "param.h" back before - system #includes. Change all #ifdef TIOCGETC to - #if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) - m-i386-sysv3.2.h, m-i386gas-sysv3.2.h: Remove "#undef TIOCGETC" - and add "#define TIOCGETC_BROKEN". - - * command.c (lookup_cmd_1): Give the correct result_list in the - case of an ambiguous return where there is a partial match - (e.g. "info a"). Add comment clarifying what is the correct - result_list. - - * gdb.texinfo (GDB History): Document the two changes below. - - * main.c (command_line_input): Make history expansion not - just occur at the beginning of a line. - - * main.c (initialize_main): Make history expansion off by default. - - * inflow.c: Move #include "param.h" after system #includes. - - * i386-dep.c (i386_float_info): Use U_FPSTATE macro. - - * m-i386-sysv3.2.h, m-i386gas-sysv3.2.h: New files. - Makefile.dist, config.gdb: Know about these new files. - -Tue Aug 15 21:36:11 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * symtab.c (lookup_struct_elt_type): Use type_print rather - than assuming type has a name. - -Tue Aug 15 02:25:43 1989 Roland McGrath (roland at apple-gunkies.ai.mit.edu) - - * sparc-opcode.h (mov): Removed bogus "or i,0,d" pattern. - - * sparc-opcode.h (mov, or): Fixed incorrect `lose' members. - - * sparc-dep.c: Don't include "sparc-opcode.h". - (skip_prologue, isanulled): Declare special types to recognize - instructions, and use them. - - * sparc-pinsn.c (print_insn): Sign-extend 13-bit immediate args. - If they are less than +9, print them in signed decimal instead - of unsigned hex. - - * sparc-opcode.h, sparc-pinsn.c: Completely rewritten to share an - opcode table with gas, and thus produce disassembly that looks - like what the assembler accepts. - -Tue Aug 15 16:20:52 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * symtab.c (find_pc_psymbol): Move best_pc=psymtab->textlow-1 - after test for psymtab null. - - * main.c (editing_info): Remove variable retval. - - * config.gdb (sun3, isi): Comment out obsolete message about telling - it whether you have an FPU (now that it detects it). - - * config.gdb (sun3): Accept sun3os3. - - * m68k-insn.h: Include . - - * m68k-pinsn.h (convert_{to,from}_68881): Add have_fpu code - - * m-newsos3.h: Undefine USE_PCB. That code didn't seem to work. - - * sparc-dep.c: Put in insn_fmt and other stuff from the old - sparc-opcode.h. - - * sparc-opcode.h, sparc-pinsn.c: Correct copyright notice. - - * sparc-opcode.h, sparc-pinsn.c: Replace the old ones with the new - ones by roland. - -Tue Aug 15 02:25:43 1989 Roland McGrath (roland at apple-gunkies.ai.mit.edu) - - * Makefile.dist: Don't define CC at all. - - * Makefile.dist (Makefile): Remove tmp.c after preprocessing. - Use $(MD) instead of M_MAKEDEFINE in the cc command. - - * Makefile.dist: Don't define RL_LIB as - "${READLINE}/libreadline.a", since READLINE is a list of files. - -Mon Aug 14 23:49:29 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * main.c (print_version): Change 1988 to 1989. - - * main.c (copying_info, initialize_main): Remove #if 0'd code. - -Tue Aug 1 14:44:56 1989 Hikichi (hikichi at sran203) - - * m-newsos3.h - (NO_SIGINTERRUPT): have SIGINTERRUPT on NEWS os 3. - - * m-news.h(FRAME_FIND_SAVED_REGS): use the sun3's instead of old - one. - -Mon Aug 14 15:27:01 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * m-news.h, m-newsos3.h, news-dep.c: Merge additional changes - by Hikichi (ChangeLog entries above). - - * Makefile.dist (READLINE): List readline files individually - so we don't accidently get random files from the readline - directory. - - * m-news.h (STORE_RETURN_VALUE, EXTRACT_RETURN_VALUE): - Expect floating point returns to be in fp0. - - * gdb.texinfo (Format options): New node. - - * gdb.texinfo: Comment out "@include"s until bfox fixes the - readline & history docs. - - * dbxread.c (read_addl_syms): Set startup_file_* if necessary at - the end (as well as when we hit ".o"). - - * printcmd.c (decode_format): Set val.format & val.size to '?' at - start and set defaults at end. - - * symtab.c (decode_line_1): Check for class_name null. - - * valops.c: Each place where it compares against field names, - check for null field names. (new t_field_name variables). - - * utils.c (fputs_filtered): Check for linebuffer null before - checking whether to call fputs. Remove later check for linebuffer - null. - -Sun Aug 13 15:56:50 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * m-isi.h, m-sun3.h ({PUSH,POP}_FP_REGS): New macros. - m-sun3.h (NUM_REGS): Conditionalize on FPU. - config.gdb (sun3, isi): Add message about support for machines - without FPU. - - * main.c (catch_termination, initialize_signals): new functions. - - * main.c (editing_info): Add "info editing n" and "info editing +". - Rewrite much of this function. - gdb.texinfo (GDB Readline): Document it. - - * values.c (history_info): Add "info history +". Also add code to - do "info history +" when command is repeated. - gdb.texinfo (Value History): Document "info history +". - - * expprint.c (print_subexp): Add OP_THIS to case stmt. - - * config.gdb (sun4os4): Put quotes around make define. - - * config.gdb: Canonicalize machine name at beginning. - -Sat Aug 12 00:50:59 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * config.gdb: define M_MAKEDEFINE - Makefile (Makefile, MD): Be able to re-make Makefile. - - * main.c (command_line_input): Add comments to - the command history. - - * Makefile.dist (Makefile): Add /bin/false. - -Fri Aug 11 14:35:33 1989 Jim Kingdon (kingdon at spiff) - - * Makefile.dist: Comment out .c.o rule and add TARGET_ARCH. - - * m-altos.h: Include sys/page.h & sys/net.h - - * m-altos.h (FRAME_CHAIN{,_VALID}): Use outside_startup_file. - - * config.gdb (altos, altosgas): Add M_SYSV & M_BSD_NM and remove - M_ALLOCA=alloca.o from makedefine. - - * coffread.c (complete_symtab): Change a_entry to entry. - - * m-altosgas.h: New file. - - * m-symmetry (REGISTER_BYTE): Fix dumb mistake. - -Fri Aug 11 06:39:49 1989 Roland McGrath (roland at hobbes.ai.mit.edu) - - * utils.c (set_screensize_command): Check for ARG being nil, since - that's what execute_command will pass if there's no argument. - - * expread.y (yylex): Recognize "0x" or "0X" as the beginning of a - number. - -Thu Aug 10 15:43:12 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * config.gdb, Makefile.dist: Rename Makefile.c to Makefile.dist. - - * m-altos.h: Add comment about porting to USGR2. - - * config.gdb (sparc): Add -Usparc. - -Wed Aug 9 14:20:39 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * m-sun3os4.h: Define BROKEN_LARGE_ALLOCA. - - * values.c (modify_field): Check for value too large to fit in - bitfield. - - * utils.c (fputs_filtered): Allow LINEBUFFER to be NULL. - - * breakpoint.c (condition_command): Check for attempt to specify - non-numeric breakpoint number. - - * config.gdb, Makefile, m-altos.h, altos-dep.c: Merge Altos - port. - - * README: Change message about editing Makefile. - - * config.gdb: Edit Makefile. - Copied Makefile to Makefile.c and changed to let config.gdb - run us through the C preprocessor. - - * expread.y (yylex): Test correctly for definition of number. - -Wed Aug 9 11:56:05 1989 Randy Smith (randy at hobbes.ai.mit.edu) - - * dbxread.c (read_dbx_symtab): Put bracketing of entry point in - test case for .o symbols so that it will be correct even without - debugging symbols. - (end_psymtab): Took bracketing out. - - * blockframe.c (outside_startup_file): Reverse the sense of the - return value to make the functionality implied by the name - correct. - -Tue Aug 8 11:48:38 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * coffread.c (symbol_file_command): Do not assume presence of a.out - header. - - * blockframe.c: Replace first_object_file_end with - startup_file_{start,end} - (outside_startup_file): New function. - dbxread.c (read_addl_syms, read_dbx_symtab, end_psymbol): set - startup_file_*. Delete first_object_file_end code. - Add entry_point and ENTRY_POINT - coffread.c (complete_symtab): Set startup_file_*. - (first_object_file_end): Add as static. - m-*.h (FRAME_CHAIN, FRAME_CHAIN_VALID): Call outside_startup_file - instead of comparing with first_object_file_end. - - * breakpoint.c (breakpoint_1): Change -1 to (CORE_ADDR)-1. - - * config.gdb (i386, i386gas): Add missing quotes at end of "echo" - - * source.c (directory_command): Add dont_repeat (); - -Mon Aug 7 18:03:51 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * dbxread.c (read_addl_syms): Change strcmp to strncmp and put 3rd - arg back. - - * command.h (struct cmd_list_element): Add comment clarifying - purpose of abbrev_flag. - -Mon Aug 7 12:51:03 1989 Randy Smith (randy at hobbes.ai.mit.edu) - - * printcmd.c (_initialize_printcmd): Changed "undisplay" not to - have abbrev flag set; it isn't an abbreviation of "delete - display", it's an alias. - -Mon Aug 7 00:25:15 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * symtab.c (lookup_symtab_1): Remove filematch (never used). - - * expread.y [type]: Add second argument to 2 calls to - lookup_member_type which were missing them. - - * dbxread.c (symbol_file_command): Add from_tty arg. - Check it before calling query. - - * infcmd.c (tty_command): Add from_tty arg. - - * eval.c (evaluate_subexp): Remove 3rd argument from - calls to value_x_unop. - - * dbxread.c (read_addl_syms): Remove 3rd argument from - call to strcmp. - - * gdb.texinfo (Command editing): @include inc-readline.texinfo - and inc-history.texinfo and reorganize GDB-specific stuff. - - * Makefile: Add line MAKE=make. - - * README (second paragraph): Fix trivial errors. - - * dbxread.c (read_struct_type): Make sure p is initialized. - - * main.c (symbol_completion_function): Complete correctly - on the empty string. - -Sun Aug 6 21:01:59 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * symmetry-dep.c: Remove "long" from definition of i386_follow_jump. - - * gdb.texinfo (Backtrace): Document "where" and "info stack". - - * dbxread.c (cleanup_undefined_types): Strip off "struct " - or "union " from type names before doing comparison - -Sat Aug 5 02:05:36 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * config.gdb (i386, i386gas): Improve makefile editing instructions. - - * Makefile: Fix typo in CLIBS for SYSV. - - * dbxread.c (read_dbx_symtab): Deal with N_GSYM typedefs. - - * dbxread.c (add_file_command): Do not free name. We didn't - allocate it; it just points into arg_string. - - * Makefile, m-*.h: Change LACK_VPRINTF to HAVE_VPRINTF. - -Fri Jul 28 00:07:48 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * valprint.c (val_print): Made sure that all returns returned a - value (usually 0, indicating no memory printed). - - * core.c (read_memory): Changed "return" to "return 0". - - * expread.y (parse_number): Handle scientific notation when the - string does not contain a '.'. - -Thu Jul 27 15:14:03 1989 Randy Smith (randy at hobbes.ai.mit.edu) - - * infrun.c (signals_info): Error if signal number passed is out of - bounds. - - * defs.h: Define alloca to be __builtin_alloca if compiling with - gcc and localized inclusion of alloca.h on the sparc with the - other alloca stuff. - * command.c: Doesn't need to include alloca.h on the sparc; defs.h - does it for you. - - * printcmd.c (print_frame_args): Changed test for call to - print_frame_nameless_args to check i to tell if any args had been - printed. - -Thu Jul 27 04:40:56 1989 Roland McGrath (roland at hobbes.ai.mit.edu) - - * blockframe.c (find_pc_partial_function): Always check that NAME - and/or ADDRESS are not nil before storing into them. - -Wed Jul 26 23:41:21 1989 Roland McGrath (roland at hobbes.ai.mit.edu) - - * m-newsos3.h: Define BROKEN_LARGE_ALLOCA. - * dbxread.c (symbol_file_command, psymtab_to_symtab): - Use xmalloc #ifdef BROKEN_LARGE_ALLOCA. - -Tue Jul 25 16:28:18 1989 Jay Fenlason (hack at apple-gunkies.ai.mit.edu) - - * m68k-opcode.h: moved some of the fmovem entries so they're - all consecutive. This way the assembler doesn't bomb. - -Mon Jul 24 22:45:54 1989 Randy Smith (randy at hobbes.ai.mit.edu) - - * symtab.c (lookup_symbol): Changed error to an informational (if - not very comforting) message about internal problems. This will - get a null symbol returned to decode_line_1, which should force - things to be looked up in the misc function vector. - -Wed Jul 19 13:47:34 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * symtab.c (lookup_symbol): Changed "fatal" to "error" in - external symbol not found in symtab in which it was supposed to be - found. This can be reached because of a bug in ar. - -Tue Jul 18 22:57:43 1989 Randy Smith (roland at hobbes.ai.mit.edu) - - * m-news.h [REGISTER_U_ADDR]: Decreased the assumed offset of fp0 - by 4 to bring it into (apparently) appropriate alignment with - reality. - -Tue Jul 18 18:14:42 1989 Randy Smith (randy at hobbes.ai.mit.edu) - - * Makefile: pinsn.o should depend on opcode.h - - * m68k-opcode.h: Moved fmovemx with register lists to before other - fmovemx. - -Tue Jul 18 11:21:42 1989 Jim Kingdon (kingdon at susie) - - * Makefile, m*.h: Only #define vprintf (to _doprnt or printf, - depends on the system) if the library lacks it (controlled by - LACK_VPRINTF_DEFINE in makefile). Unpleasant, but necessary to - make this work with the GNU C library. - -Mon Jul 17 15:17:48 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * breakpoint.c (breakpoint_1): Change addr-b->address to - b->address-addr. - -Sun Jul 16 16:23:39 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * eval.c (evaluate_subexp): Change error message printed when - right operand of '@' is not an integer to English. - - * infcmd.c (registers_info): Fix call to print_spaces_filtered - to specify right # of arguments. - - * gdb.texinfo (Command Editing): Document info editing command. - - * coffread.c (read_file_hdr): Add MC68MAGIC. - - * source.c (select_source_symtab): Change MAX to max. - -Fri Jul 14 21:19:11 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * infcmd.c (registers_info): Clean up display to look good with long - register names, to say "register" instead of "reg", and to put the - "relative to selected stack frame" bit at the top. - -Fri Jul 14 18:23:09 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (record_misc_function): Put parens around | to force - correct evaluation. - -Wed Jul 12 12:25:53 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * m-newsos3, m-news, infrun.c, Makefile, config.gdb, news-dep.c: - Merge in Hikichi's changes for Sony/News-OS 3 support. - -Tue Jul 11 21:41:32 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * utils.c (fputs_filtered): Don't do any filtering if output is - not to stdout, or if stdout is not a tty. - (fprintf_filtered): Rely on fputs_filtered's check for whether to - do filtering. - -Tue Jul 11 00:33:58 1989 Randy Smith (randy at hobbes.ai.mit.edu) - - * GDB 3.2 Released. - - * valprint.h: Deleted. - - * utils.c (fputs_filtered): Don't do any filtering if filtering is - disabled (lines_per_page == 0). - -Mon Jul 10 22:27:53 1989 Randy Smith (roland at hobbes.ai.mit.edu) - - * expread.y [typebase]: Added "unsigned long int" and "unsigned - short int" to specs. - -Mon Jul 10 21:44:55 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * main.c (main): Make -cd use cd_command to avoid - current_directory with non-absolute pathname. - -Mon Jul 10 00:34:29 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (symbol_file_command): Catch errors from stat (even - though they should never happen). - - * source.c (openp): If the path is null, use the current - directory. - - * dbxread.c (read_dbx_symtab): Put N_SETV symbols into the misc - function vector ... - (record_misc_function): ... as data symbols. - - * utils.c (fprintf_filtered): Return after printing if we aren't - going to do filtering. - - * Makefile: Added several things for make clean to take care of. - - * expread.y: Lowered "@" in precedence below +,-,*,/,%. - - * eval.c (evaluate_subexp): Return an error if the rhs of "@" - isn't integral. - - * Makefile: Added removal of core and gdb[0-9] files to clean - target. - - * Makefile: Made a new target "distclean", which cleans things up - correctly for making a distribution. - -Sun Jul 9 23:21:27 1989 Randy Smith (randy at hobbes.ai.mit.edu) - - * dbxread.c: Surrounded define of gnu symbols with an #ifndef - NO_GNU_STABS in case you don't want them on some machines. - * m-npl.h, m-pn.h: Defined NO_GNU_STABS. - -Sun Jul 9 19:25:22 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * utils.c (fputs_filtered): New function. - (fprintf_filtered): Use fputs_filtered. - utils.c (print_spaces_filtered), - command.c (help_cmd,help_cmd_list), - printcmd.c (print_frame_args), - stack.c (print_block_frame_locals, print_frame_arg_vars), - valprint.c (many functions): Use fputs_filtered instead of - fprintf_filtered to avoid arbitrary limit. - - * utils.c (fprintf_filtered): Fix incorrect comment. - -Sat Jul 8 18:12:01 1989 Randy Smith (randy at hobbes.ai.mit.edu) - - * valprint.c (val_print): Changed assignment of pretty to use - prettyprint as a conditional rather than rely on values of the - enum. - - * Projects: Cleaned up a little for release. - - * main.c (initialize_main): Initialize - rl_completion_entry_function instead of completion_entry_function. - - * Makefile: Modified to use the new readline library setup. - - * breakpoint.c (break_command_1, delete_breakpoint, - enable_breakpoint, disable_breakpoint): Put in new printouts for - xgdb usage triggered off of xgdb_verbose. - * main.c (main): Added check for flag to set xgdb_verbose. - * stack.c (frame_command): Set frame_changed when frame command - used. - -Fri Jul 7 16:20:58 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * Remove valprint.h and move contents to value.h (more logical). - -Fri Jul 7 02:28:06 1989 Randall Smith (randy at rice-chex) - - * m68k-pinsn.c (print_insn): Included a check for register list; - if there is one, make sure to start p after it. - - * breakpoint.c (break_command_1, delete_breakpoint, - enable_breakpoint, disable_breakpoint): #ifdef'd out changes - below; they produce unwanted output in gdb mode in gnu-emacs. - - * gdb.texinfo: Spelled. Also removed index references from - command editing section; the relevance/volume ratio was too low. - Removed all references to the function index. - - * ns32k-opcode.h, ns32k-pinsn.c: Backed out changes of June 24th; - haven't yet received legal papers. - - * .gdbinit: Included message telling the user what it is doing. - - * symmetry-dep.c: Added static decls for i386_get_frame_setup, - i386_follow_jump. - * values.c (unpack_double): Added a return (double)0 at the end to - silence a compiler warning. - - * printcmd.c (containing_function_bounds, asdump_command): Created - to dump the assembly code of a function (support for xgdb and a - useful hack). - (_initialize_printcmd): Added this to command list. - * gdb.texinfo [Memory]: Added documentation for the asdump - command. - * breakpoint.c (break_command_1, delete_breakpoint, - enable_breakpoint, disable_breakpoint): Added extra verbosity for - xgdb conditionalized on the new external frame_full_file_name. - * source.c (identify_source_line): Increase verbosity of fullname - prointout to include pc value. - * stack.c: Added a new variable; "frame_changed" to indicate when - a frame has been changed so that gdb can print out a frame change - message when the frame only changes implicitly. - (print_frame_info): Check the new variable in determining when to - print out a new message and set it to zero when done. - (up_command): Increment it. - (down_command): Decrement it. - - * m68k-pinsn.c (print_insn_arg [lL]): Modified cases for register - lists to reset the point to point to after the word from which the - list is grabbed *if* that would cause point to point farther than - it currently is. - -Thu Jul 6 14:28:11 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * valprint.c (val_print, value_print): Add parameter to control - prettyprinting. - valprint.h: New file containing constants used for passing - prettyprinting parameter to val{,ue}_print. - expprint.c, infcmd.c, printcmd.c, valprint.c, values.c: - Change all calls to val{,ue}_print to use new parameter. - -Mon Jul 3 22:38:11 1989 Randy Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (,process_one_symbol): Moved extern declaration for - index out of function to beginning of file. - -Mon Jul 3 18:40:14 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * gdb.texinfo (Registers): Add "ps" to list of standard registers. - -Sun Jul 2 23:13:03 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * printcmd.c (enable_display): Change d->next to d = d->next so - that "enable display" without args works. - -Fri Jun 30 23:42:04 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * source.c (list_command): Made error message given when no - symtab is loaded clearer. - - * valops.c (value_assign): Make it so that when assigning to an - internal variable, the type of the assignment exp is the type of - the value being assigned. - -Fri Jun 30 12:12:43 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * main.c (verbose_info): Created. - (initialize_main): Put "info verbose" into command list. - - * utils.c (screensize_info): Created. - (_initialize_utils): Defined "info screensize" as a normal command. - - * valprint.c (format_info): Added information about maximum number - of array elements to function. - - * blockframe.c (find_pc_partial_function): Again. - - * blockframe.c (find_pc_partial_function): Replaced a "shouldn't - happen" (which does) with a zero return. - - * main.c (dont_repeat): Moved ahead of first use. - -Thu Jun 29 19:15:08 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * vax-opcode.h: Made minor modifications (moved an instruction and - removed a typo) to bring this into accord with gas' table; also - changed copyright to reflect it being part of both gdb and gas. - - * m68k-opcode.h: Added whole scads and bunches of new stuff for - the m68851 and changed the coptyrightto recognize that the file - was shared between gdb and gas. - - * main.c (stop_sig): Use "dont_repeat ()" instead of *line = 0; - - * core.c (read_memory): Don't do anything if length is 0. - - * Makefile: Added readline.c to the list of files screwed by - having the ansi ioctl.h compilation with gcc. - - * config.gdb: Added sun4os3 & sun4-os3 as availible options. - -Wed Jun 28 02:01:26 1989 Jim Kingdon (kingdon at apple-gunkies.ai.mit.edu) - - * command.c (lookup_cmd): Add ignore_help_classes argument. - (lookup_cmd_1): Add ignore_help_classes argument. - command.c, main.c: Change callers of lookup_cmd{,_1} to supply - value for ignore_help_classes. - -Tue Jun 27 18:01:31 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * utils.c (print_spaces_filtered): Made more efficient. - * defs.h: Declaration. - * valprint.c (val_print): Used in a couple of new places. - -Mon Jun 26 18:27:28 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * m68k-pinsn.c (print_insn_arg ['#', '^']): Combined them into one - case which always gets the argument from the word immediately - following the instruction. - (print_insn_arg ["[lL]w"]): Make sure to always get the register - mask from the word immediately following the instruction. - -Sun Jun 25 19:14:56 1989 Randall Smith (randy at galapas.ai.mit.edu) - - * Makefile: Added hp-include back in as something to distribute. - - * stack.c (print_block_frame_locals): Return value changed from - void to int; return 1 if values printed. Use _filtered. - (print_frame_local_vars): Use return value from - print_block_frame_locals to mention if nothing printed; mention - lack of symbol table, use _filtered. - (print_frame_arg_vars): Tell the user if no symbol table - or no values printed. Use fprintf_filtered instead of fprintf. - * blockframe.c (get_prev_frame_info): Check for no inferior or - core file before crashing. - - * inflow.c (inferior_died): Set current frame to zero to keep from - looking like we're in start. - -Sat Jun 24 15:50:53 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * stack.c (frame_command): Added a check to make sure that there - was an inferior or a core file. - - * expread.y (yylex): Allow floating point numbers of the form ".5" - to be parsed. - - Changes by David Taylor at TMC: - * ns32k-pinsn.c: Added define for ?floating point coprocessor? and - tables for register names to be used for each of the possibilities. - (list_search): Created; searches a list of options for a specific - value. - (print_insn_arg): Added 'Q', 'b', 'M', 'P', 'g', and 'G' options - to the value location switch. - * ns32k-opcode.h: Added several new location flags. - [addr, enter, exit, ext[bwd], exts[bwd], lmr, lpr[bwd], restore, - rett, spr[bwd], smr]: Improved insn format output. - - * symtab.c (list_symbols): Rearrange printing to produce readable - output for "info types". - - * eval.c (evaluate_subexp_for_address): Fixed typo. - - * dbxread.c (read_type): Don't output an error message when - there isn't a ',' after a cross-reference. - - * dbxread.c (read_dbx_symtab): #if'd out N_FN case in - read_dbx_symtab if it has the EXT bit set (otherwise multiple - cases with the same value). - -Fri Jun 23 13:12:08 1989 Randall Smith (randy at plantaris.ai.mit.edu) - - * symmisc.c: Changed decl of print_spaces from static to extern - (since it's defined in utils.c). - - * remote.c (remote_open): Close remote_desc if it's already been - opened. - - * Remote_Makefile, remote_gutils.c, remote_inflow.c, - remote_server.c, remote_utils.c: Combined into remote-multi.shar. - * remote-multi.shar: Created (Vikram Koka's remote stub). - * remote-sa.m68k.shar: Created (Glenn Engel's remcom.c). - * README: Updated to reflect new organization of remote stubs. - - * dbxread.c (read_dbx_symtab): Put an N_FN in with N_FN | N_EXT to - account for those machines which don't use the external bit here. - Sigh. - - * m-symmetry.h: Defined NO_SIGINTERRUPT. - -Thu Jun 22 12:51:37 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * printcmd.c (decode_format): Make sure characters are printed - using a byte size. - - * utils.c (error): Added a terminal_ours here. - - * stack.c (locals_info): Added check for selected frame. - - * dbxread.c (read_type): Checked to make sure that a "," was - actually found in the symbol to end a cross reference. - -Wed Jun 21 10:30:01 1989 Randy Smith (randy at tartarus.uchicago.edu) - - * expread.y (parse_number, [exp]): Allowed for the return of a - number marked as unsigned; this will allow inclusion of unsigned - constants. - - * symtab.h: Put in default definitions for BUILTIN_TYPE_LONGEST - and BUILTIN_TYPE_UNSIGNED_LONGEST. - - * expread.y (parse_number): Will now accept integers suffixed with - a 'u' (though does nothing special with it). - - * valarith.c (value_binop): Added cases to deal with unsigned - arithmetic correctly. - -Tue Jun 20 14:25:54 1989 Randy Smith (randy at tartarus.uchicago.edu) - - * dbxread.c (psymtab_to_symtab_1): Changed reading in info message - to go through printf_filtered. - - * symtab.c (list_symbols): Placed header message after all calls - to psymtab_to_symtab. - - * symtab.c (smash_to_{function, reference, pointer}_type): Carried - attribute of permanence for the type being smashed over the bzero - and allowed any type to point at this one if it is permanent. - - * symtab.c (smash_to_{function, reference, pointer}_type): Fix - typo: check flags of to_type instead of type. - - * m-hp9k320.h: Changed check on __GNU__ predefine to __GNUC__. - - * Makefile: Made MUNCH_DEFINE seperate and based on SYSV_DEFINE; - they aren't the same on hp's. - -Mon Jun 19 17:10:16 1989 Randy Smith (randy at tartarus.uchicago.edu) - - * Makefile: Fixed typo. - - * valops.c (call_function): Error if the inferior has not been - started. - - * ns32k-opcode.h [check[wc], cmpm[bwd], movm[bwd], skpsb]: Fixed - typos. - -Fri Jun 9 16:23:04 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-news.h [NO_SIGINTERRUPT]: Defined. - - * dbxread.c (read_type): Start copy of undefined structure name - past [sue] defining type of cross ref. - - * dbxread.c (process_one_symbol): Changed strchr to index. - - * ns32k-opcode.h, ns32k-pinsn.c: More changes to number of - operands, addition of all of the set condition opcodes, addition - of several flag letters, all patterned after the gas code. - - * ns32k-opcode.h [mov{su,us}[bwd], or[bwd]]: Changed number of - operands from 1 to 2. - -Wed Jun 7 15:04:24 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * symseg.h [TYPE_FLAG_STUB]: Created. - * dbxread.c (read_type): Set flag bit if type is stub. - (cleanup_undefined_types): Don't mark it as a stub if it's been - defined since we first learned about it. - * valprint.c (val_print): Print out a message to that effect if - this type is encountered. - - * symseg.h, symtab.h: Moved the definition of TYPE_FLAG_PERM over - to symseg.h so that all such definitions would be in the same place. - - * valprint.c (val_print): Print out for a - structure if there aren't any. - - * dbxread.c (read_type): Set type name of a cross reference type - to "struct whatever" or something. - -Tue Jun 6 19:40:52 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * breakpoint.c (breakpoint_1): Print out symbolic location of - breakpoints for which there are no debugging symbols. - -Mon Jun 5 15:14:51 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * command.c (help_cmd_list): Made line_size static. - -Sat Jun 3 17:33:45 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * Makefile: Don't include the binutils hp-include directory in the - distribution anymore; refer the users to the binutils distribution. - -Thu Jun 1 16:33:07 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * printcmd.c (disable_display_command): Fixed loop iteration for - no arg case. - - * printcmd.c (disable_display_command): Added from_tty parameter - to function. - - * valops.c (value_of_variable): Call read_var_value with 0 cast to - FRAME instead of CORE_ADDR. - - * eval.c (evaluate_subexp): Corrected number of args passed to - value_subscript (to 2). - - * infrun.c (wait_for_inferior), symtab.c (decode_line_1), - m-convex.h: Changed name of FIRSTLINE_DEBUG_BROKEN to - PROLOGUE_FIRSTLINE_OVERLAP. - - * m-merlin.h: Fixed typo. - * ns32k-opcode.h: Added ns32381 opcodes and "cinv" insn, and fixed - errors in movm[wd], rett, and sfsr. - - * eval.c (evaluate_subexp, evaluate_subexp_for_address), valops.c - (value_zero): Change value_zero over to taking two arguments - instead of three. - - * eval.c (evaluate_subexp) - [OP_VAR_VALUE]: Get correct lval type for AVOID_SIDE_EFFECTS for - all types of symbols. - [BINOP_DIV]: Don't divide if avoiding side effects; just return - an object of the correct type. - [BINOP_REPEAT]: Don't call value_repeat, just allocate a - repeated value. - (evaluete_subexp_for_address) [OP_VAR_VALUE]: Just return a thing - of the right type (after checking to make sure that we are allowed - to take the address of whatever variable has been passed). - -Mon May 29 11:01:02 1989 Randall Smith (randy at galapas.ai.mit.edu) - - * breakpoint.c (until_break_command): Set the breakpoint with a - frame specification so that it won't trip in inferior calls to the - function. Also set things up so that it works based on selected - frame, not current one. - -Sun May 28 15:05:33 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * eval.c (evalue_subexp): Change subscript case to use value_zero - in EVAL_AVOID_SIDE_EFFECTS case. - -Fri May 26 12:03:56 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (read_addl_syms, psymtab_to_symtab): Removed - cleanup_undefined_types; this needs to be done on a symtab basis. - (end_symtab): Called cleanup_undefined_types from here. - (cleanup_undefined_types): No longer uses lookup_symbol (brain - dead idea; oh, well), now it searches through file_symbols. - -Wed May 24 15:52:43 1989 Randall Smith (randy at galapas) - - * source.c (select_source_symtab): Only run through - partial_symtab_list if it exists. - - * coffread.c (read_coff_symtab): Don't unrecord a misc function - when a function symbol is seen for it. - - * expread.y [variable]: Make sure to write a type for memvals if - you don't get a mft you recognize. - -Tue May 23 12:15:57 1989 Randall Smith (randy at plantaris.ai.mit.edu) - - * dbxread.c (read_ofile_symtab, psymtab_to_symtab): Moved cleanup - of undefined types to psymtab_to_symtab. That way it will be - called once for all readins (which will, among other things, - help reduce infinite loops). - - * symtab.h [misc_function_type]: Forced mf_unknown to 0. - * dbxread.c (record_misc_function): Cast enum to unsigned char (to - fit). - * expread.y [variable]: Cast unsigned char back to enum to test. - -Mon May 22 13:08:25 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - Patches by John Gilmore for dealing well with floating point: - * findvar.c (value_from_register, locate_var_value): Used - BYTES_BIG_ENDIAN instead of an inline test. - * m-sparc.h [IEEE_FLOAT]: Created to indicate that the sparc is - IEEE compatible. - * printcmd.c (print_scalar_formatted): Use BYTES_BIG_ENDIAN and - the stream argument for printing; also modify default type for - 'f'. Change handling of invalid floats; changed call syntax for - is_nan. - (print_command): Don't print out anything indicating that - something was recorded on the history list if it wasn't. - * valprint.c (val_print): Fixed to deal properley with new format - of is_nan and unpacking doubles without errors occuring. - (is_nan): Changed argument list and how it figures big endianness - (uses macros). - * values.c (record_latest_value): Return -1 and don't record if - it's an invalid float. - (value_as_double): Changed to use new unpack_double calling - convention. - (unpack_double): Changed not to call error if the float was - invalid; simply to set invp and return. Changed calling syntax. - (unpack_field_as_long, modify_field): Changed to use - BITS_BIG_ENDIAN to determine correct action. - - * m-hp9k320.h [HP_OS_BUG]: Created; deals with problem where a - trap happens after a continue. - * infrun.c (wait_for_inferior): Used. - - * m-convex.h [FIRSTLINE_DEBUG_BROKEN]: Defined a flag to indicate - that the debugging symbols output by the compiler for the first - line of a function were broken. - * infrun.c (wait_for_inferior), symtab.c (decode_line_1): Used. - - * gdb.texinfo [Data, Memory]: Minor cleanups of phrasing. - -Fri May 19 00:16:59 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (add_undefined_type, cleanup_undefined_types): Created - to keep a list of cross references to as yet undefined types. - (read_type): Call add_undefined_type when we run into such a case. - (read_addl_syms, read_ofile_symtab): Call cleanup_undefined_types - when we're done. - - * dbxread.c (psymtab_to_symtab, psymtab_to_symtab_1): Broke - psymtab_to_symtab out into two routines; made sure the string - table was only readin once and the globals were only scanned once, - for any number of dependencies. - -Thu May 18 19:59:18 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-*.h: Defined (or not, as appropriate per machine) - BITS_BIG_ENDIAN, BYTES_BIG_ENDIAN, and WORDS_BIG_ENDIAN. - -Wed May 17 13:37:45 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * main.c (symbol_completion_function): Always complete on result - command list, even if exact match found. If it's really an exact - match, it'll find it again; if there's something longer than it, - it'll get the right result. - - * symtab.c (make_symbol_completion_function): Fixed typo; strcmp - ==> strncmp. - - * dbxread.c (read_dbx_symtab): Change 'G' case to mark symbols as - LOC_EXTERNAL. - - * expread.y [variables]: Changed default type of text symbols to - function returning int so that one can use, eg. strcmp. - - * infrun.c (wait_for_inferior): Include a special flag indicating - that one shouldn't insert the breakpoints on the next step for - returning from a sigtramp and forcing at least one move forward. - - * infrun.c (wait_for_inferior): Change test for nexting into a - function to check for current stack pointer inner than previous - stack pointer. - - * infrun.c (wait_for_inferior): Check for step resume break - address before dealing with normal breakpoints. - - * infrun.c (wait_for_inferior): Added a case to deal with taking - and passing along a signal when single stepping past breakpoints - before inserting breakpoints. - - * infrun.c (wait_for_inferior): Inserted special case to keep - going after taking a signal we are supposed to be taking. - -Tue May 16 12:49:55 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * inflow.c (terminal_ours_1): Cast result of signal to (int - (*)()). - - * gdb.texinfo: Made sure that references to the program were in - upper case. Modify description of the "set prompt" command. - [Running]: Cleaned up introduction. - [Attach]: Cleaned up. - [Stepping]: Change "Proceed" to "Continue running" or "Execute". - Minor cleanup. - [Source Path]: Cleaned up intro. Cleared up distinction between - the executable search path and the source path. Restated effect - of the "directory" command with no arguments. - [Data]: Fixed typos and trivial details. - [Stepping]: Fixed up explanation of "until". - - * source.c (print_source_lines): Print through filter. - - * printcmd.c (x_command): If the format with which to print is - "i", use the address of anything that isn't a pointer instead of - the value. This is for, eg. "x/10i main". - - * gdb.texinfo: Updated last modification date on manual. - -Mon May 15 12:11:33 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * symtab.c (lookup_symtab): Fixed typo (name ==> copy) in call to - lookup_symtab_1. - - * gdb.texinfo: Added documentation for "break [+-]n" and for new - actions of "directory" command (taking multiple directory names at - the same time). - - * m68k-opcode.h: Replaced the version in gdb with an up-to-date - version from the assembler directory. - * m68k-pinsn.c (print_insn_arg): Added cases 'l' & 'L' to switch - to print register lists for movem instructions. - - * dbxread.c, m-convex.h: Moved convex dependent include files over - from dbxread.c to m-convex.h. - - * printcmd.c (disable_display, disable_display_command): Changed - name of first to second, and created first which takes an int as - arg rather than a char pointer. Changed second to use first. - (_initialize_printcmd): Changed to use second as command to call. - (delete_current_display, disable_current_display): Changed name of - first to second, and changed functionality to match. - * infrun.c (normal_stop), main.c (return_to_top_level): Changed to - call disable_current_display. - - * dbxread.c (process_one_symbol, read_dbx_symtab): Changed N_FN to - be N_FN | N_EXT to deal with new Berkeley define; this works with - either the old or the new. - - * Remote_Makefile, remote_gutils.c, remote_inflow.c, - remote_server.c, remote_utils.c: Created. - * Makefile: Included in tag and tar files. - * README: Included a note about them. - - * printcmd.c (print_address): Use find_pc_partial_function to - remove need to readin symtabs for symbolic addresses. - - * source.c (directory_command): Replaced function with new one - that can accept lists of directories seperated by spaces or :'s. - - * inflow.c (new_tty): Replaced calls to dup2 with calls to dup. - -Sun May 14 12:33:16 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * stack.c (args_info): Make sure that you have an inferior or core - file before taking action. - - * ns32k-opcode.h [deiw, deid]: Fixed machine code values for these - opcodes. - - * dbxread.c (scan_file_globals): Modified to use misc function - vector instead of file itself. Killed all arguments to the - funciton; no longer needed. - (psymtab_to_symtab): Changed call for above to reflect new (void) - argument list. - - * dbxread.c (read_dbx_symtab, ): Moved HASH_OFFSET define out of - read_dbx_symtab. - - * expread.y [variable]: Changed default type of misc function in - text space to be (void ()). - - * Makefile: Modified for proper number of s/r conflicts (order is - confusing; the mod that necessitated this change was on May 12th, - not today). - - * expread.y (yylex): Added SIGNED, LONG, SHORT, and INT keywords. - [typename]: Created. - [typebase]: Added rules for LONG, LONG INT, SHORT, SHORT INT, - SIGNED name, and UNSIGNED name (a good approximation of ansi - standard). - - * Makefile: Included .c.o rule to avoid sun's make from throwing - any curves at us. - - * blockframe.c: Included - - * command.c (lookup_cmd): Clear out trailing whitespace. - - * command.c (lookup_cmd_1): Changed malloc to alloca. - -Fri May 12 12:13:12 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * printcmd.c (print_frame_args): Only print nameless args when you - know how many args there are supposed to be and when you've - printed fewer than them. Don't print nameless args between - printed args. - - * symtab.c (make_symbol_completion_function): Fixed typo (= ==> - ==). - - * remote.c (remote_open): ifdef'd out siginterrupt call by #ifndef - NO_SIGINTERRUPT. - * m-umax.h: Defined NO_SIGINTERRUPT. - - * expread.y [ptype, array_mod, func_mod, direct_abs_decl, - abs_decl]: Added rules for parsing and creating arbitrarily - strange types for casts and sizeofs. - - * symtab.c, symtab.h (create_array_type): Created. Some minor - misfeatures; see comments for details (main one being that you - might end up creating two arrays when you only needed one). - -Thu May 11 13:11:49 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * valops.c (value_zero): Add an argument for type of lval. - * eval.c (evaluate_subexp_for_address): Take address properly in - the avoid side affects case (ie. keep track of whether we have an - lval in memory and we can take the address). - (evaluate_subexp): Set the lval type of expressions created with - value_zero properley. - - * valops.c, value.h (value_zero): Created--will return a value of - any type with contents filled with zero. - * symtab.c, symtab.h (lookup_struct_elt_type): Created. - * eval.c (evaluate_subexp): Modified to not read memory when - called with EVAL_AVOID_SIDE_EFFECTS. - - * Makefile: Moved dbxread.c ahead of coffread.c in the list of - source files. - -Wed May 10 11:29:19 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * munch: Make sure that sysv version substitutes for the whole - line. - - * symtab.h: Created an enum misc_function_type to hold the type of - the misc function being recorded. - * dbxread.c (record_misc_function): Branched on dbx symbols to - decide which type to assign to a misc function. - * coffread.c (record_misc_function): Always assign type unknown. - * expread.y [variable]: Now tests based on new values. - -Tue May 9 13:03:54 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * symtab.c: Changed inclusion of (doesn't work on - SYSV) to declaration of index. - - * Makefile: Changed last couple of READLINE_FLAGS SYSV_DEFINE - - * source.c ({forward, reverse}_search_command): Made a default - search file similar to for the list command. - -Mon May 8 18:07:51 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * printcmd.c (print_frame_args): If we don't know how many - arguments there are to this function, don't print the nameless - arguments. We don't know enough to find them. - - * printcmd.c (print_frame_args): Call print_frame_nameless_args - with proper arguments (start & end as offsets from addr). - - * dbxread.c (read_addl_syms): Removed cases to deal with global - symbols; this should all be done in scan_global_symbols. - -Sun May 7 11:36:23 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * Makefile: Added copying.awk to ${OTHERS}. - -Fri May 5 16:49:01 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * valprint.c (type_print_varspec_prefix): Don't pass - passed_a_pointer onto children. - - * valprint.c (type_print_varspec_suffix): Print "array of" with - whatever the "of" is after tha array brackets. - - * valprint.c (type_print_varspec_{prefix,suffix}): Arrange to - parenthesisze pointers to arrays as well as pointers to other - objects. - - * valprint.c (type_print_varspec_suffix): Make sure to print - subscripts of multi-dimensional arrays in the right order. - - * infcmd.c (run_command): Fixed improper usages of variables - within remote debugging branch. - - * Makefile: Added Convex.notes to the list of extra files to carry - around. - - * dbxread.c (symbol_file_command): Made use of alloca or malloc - dependent on macro define. - -Thu May 4 15:47:04 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * Makefile: Changed READLINE_FLAGS to SYSV_DEFINE and called munch - with it also. - * munch: Check first argument for -DSYSV and be looser about - picking up init routines if you find it. - - * coffread.c: Made fclose be of type int. - - * breakpoint.c (_initialize_breakpoint): Put "unset" into class - alias. - -Wed May 3 14:09:12 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-sparc.h [STACK_END_ADDR]: Parameterized off of - machine/vmparam.h (as per John Gilmore's suggestion). - - * blockframe.c (get_prev_frame_info): Changed this function back - to checking frameless invocation first before checking frame - chain. This means that a backtrace up from start will produce the - wrong value, but that a backtrace from a frameless function called - in main will show up correctly. - - * breakpoint.c (_initialize_breakpoint): Added entry in help for - delete that indicates that unset is an alias for it. - - * main.c (symbol_completion_function): Modified recognition of - being within a single command. - -Tue May 2 15:13:45 1989 Randy Smith (randy at gnu) - - * expread.y [variable]: Add some parens to get checking of the - misc function vector right. - -Mon May 1 13:07:03 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * default-dep.c (core_file_command): Made reg_offset unsigned. - - * default-dep.c (core_file_command): Improved error messages for - reading in registers. - - * expread.y: Allowed a BLOCKNAME to be ok for a variable name (as - per C syntax). - - * dbxread.c (psymtab_to_symtab): Flushed stdout after printing - starting message about reading in symbols. - - * printcmd.c (print_frame_args): Switched starting place for - printing of frameless args to be sizeof int above last real arg - printed. - - * printcmd.c (print_frame_args): Modified final call to - print_nameless_args to not use frame slots used array if none had - been used. - - * infrun.c (wait_for_inferior): Take FUNCTION_START_OFFSET into - account when dealing with comparison of pc values to function - addresses. - - * Makefile: Added note about compiling gdb on a Vax running 4.3. - -Sun Apr 30 12:59:46 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * command.c (lookup_cmd): Got correct error message on bad - command. - - * m-sun3.h [ABOUT_TO_RETURN]: Modified to allow any of the return - instructions, including trapv and return from interupt. - - * command.c (lookup_cmd): If a command is found, use it's values - for error reporting and determination of needed subcommands. - - * command.c (lookup_cmd): Use null string for error if cmdtype is - null; pass *line to error instead of **. - - * command.c (lookup_cmd_1): End of command marked by anything but - alpha numeric or '-'. Included ctype.h. - -Fri Apr 28 18:30:49 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * source.c (select_source_symtab): Kept line number from ever - being less than 1 in main decode. - -Wed Apr 26 13:03:20 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * default-dep.c (core_file_command): Fixed typo. - - * utils.c (fprintf_filtered): Don't use return value from - numchars. - - * main.c, command.c (complete_on_cmdlist): Moved function to - command.c. - - * command.c (lookup_cmd): Modified to use my new routine. Old - version is still there, ifdef'd out. - - * command.c, command.h (lookup_cmd_1): Added a routine to do all - of the work of lookup_cmd with no error reporting and full return - of information garnered in search. - -Tue Apr 25 12:37:54 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * breakpoint.c (_initialize_breakpoint): Change "delete - breakpionts" to be in class alias and not have the abbrev flag - set. - - * main.c (symbol_completion_function): Fix to correctly complete - things that correspond to multiword aliases. - - * main.c (complete_on_cmdlist): Don't complete on something if it - isn't a command or prefix (ie. if it's just a help topic). - - * main.c (symbol_completion_function): Set list index to be 0 if - creating a list with just one element. - - * main.c (complete_on_cmdlist): Don't allow things with - abbrev_flag set to be completion values. - (symbol_completion_function): Don't accept an exact match if the - abbrev flag is set. - - * dbxread.c (read_type): Fixed typo in comparision to check if - type number existed. - - * dbxread.c (read_type): Made sure to only call dbx_lookup_type on - typenums if typenums were not -1. - -Mon Apr 24 17:52:12 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * symtab.c: Added strings.h as an include file. - -Fri Apr 21 15:28:38 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * symtab.c (lookup_partial_symtab): Changed to only return a match - if the name match is exact (which is what I want in all cases in - which this is currently used. - -Thu Apr 20 11:12:34 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * m-isi.h [REGISTER_U_ADDR]: Installed new version from net. - * default-dep.c: Deleted inclusion of fcntl.h; apparently not - necessary. - * Makefile: Added comment about compiling on isi under 4.3. - - * breakpoint.c (break_command_1): Only give decode_line_1 the - default_breakpoint_defaults if there's nothing better (ie. make - the default be off of the current_source notes if at all - possible). - - * blockframe.c (get_prev_frame_info): Clean up comments and - delete code ifdefed out around FRAMELESS_FUNCTION_INVOCATION test. - - * remote.c: Added a "?" message to protocol. - (remote_open): Used at startup. - (putpkt): Read whatever garbage comes over the line until we see a - '+' (ie. don't treat garbage as a timeout). - - * valops.c (call_function): Eliminated no longer appropriate - comment. - - * infrun.c (wait_for_inferior): Changed several convex conditional - compilations to be conditional on CANNOT_EXECUTE_STACK. - -Wed Apr 19 10:18:17 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * printcmd.c (print_frame_args): Added code to attempt to deal - with arguments that are bigger than an int. - - Continuation of Convex/Fortran changes: - * printcmd.c (print_scalar_formatted): Added leading zeros to - printing of large integers. - (address_info, print_frame_args): Added code to deal with - LOC_REF_ARG. - (print_nameless_args): Allow param file to specify a routine with - which to print typeless integers. - (printf_command): Deal with long long values well. - * stack.c (print_frame_arg_vars): Change to deal with LOC_REF_ARG. - * symmisc.c (print_symbol): Change to deal with LOC_REF_ARG. - * symseg.h: Added LOC_REF_ARG to enum address_class. - * symtab.c (lookup_block_symbol): Changed to deal with - LOC_REF_ARG. - * valarith.c (value_subscripted_rvalue): Created. - (value_subscript): Used above when app. - (value_less, value_equal): Change to cast to (char *) before doing - comparison, for machines where that casting does something. - * valops.c (call_function): Setup to deal with machines where you - cannot execute code on the stack segment. - * valprint.c (val_print): Make sure that array element size isn't - zero before printing. Set address of default array to address of - first element. Put in a couple of int cast. Removed some convex - specific code. Added check for endianness of machine in case of a - packed structure. Added code for printing typeless integers and - for LONG LONG's. - (set_maximum_command): Change to use parse_and_eval_address to get - argument (so can use expressions there). - * values.c (value_of_internalvar, set_internalvar_component, - set_internalvar, convenience_info): Add in hooks for trapped - internal vars. - (unpack_long): Deal with LONG_LONG. - (value_field): Remove LONGEST cast. - (using_struct_return): Fixed typo ENUM ==> UNION. - * xgdb.c (_initialize_xgdb): Make sure that specify_exec_file_hook - is not called unless we are setting up a windowing environ. - -Tue Apr 18 13:43:37 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - Various changes involved in 1) getting gdb to work on the convex, - and 2) Getting gdb to work with fortran (due to convex!csmith): - * convex-dep.c, convex-opcode.h, m-convex.h, convex-pinsn.c: - Created (or replaced with new files). - * Makefile: Add convex dependent files. Changed default flags to - gnu malloc to be CFLAGS. - * config.gdb: Added convex to list of machines. - * core.c (files_info): Added a FILES_INFO_HOOK to be used if - defined. - (xfer_core_file): Conditionalized compilation of xfer_core_file on - the macro XFER_CORE_FILE. - * coffread.c (record_misc_function): Made sure it zerod type field - (which is now being used; see next). - * dbxread.c: Included some convex dependent include files. - (copy_pending, fix_common_blocks): Created. - [STAB_REG_REGNUM, BELIEVE_PCC_PROMOTION]: Created default values; - may be overridden in m-*.h. - Included data structures for keeping track of common blocks. - (dbx_alloc_type): Modified; if called with negative 1's will - create a type without putting it into the type vector. - (read_dbx_symtab, read_addl_syms): Modified calls to - record_misc_function to include the new information. - (symbol_file_command, psymtab_to_symtab, add_file_command): - Modified reading in of string table to adapt to machines which - *don't* store the size of the string table in the first four bytes - of the string table. - (read_dbx_symtab, scan_file_globals, read_ofile_symtab, - read_addl_syms): Modified assignment of namestring to accept null - index into symtab as ok. - (read_addl_syms): Modified readin of a new object file to fiddle - with common blocks correctly. - (process_one_symbol): Fixed incorrect comment about convex. Get - symbols local to a lexical context from correct spot on a per - machine basis. Catch a bug in pcc which occaisionally puts an SO - where there should be an SOL. Seperate sections for N_BCOMM & - N_ECOMM. - (define_symbol): Ignore symbols with no ":". Use - STAB_REG_TO_REGNUM. Added support for function args calling by - reference. - (read_type): Only read type number if one is there. Remove old - (#if 0'd out) array code. - (read_array_type): Added code for dealing with adjustable (by - parameter) arrays half-heartedly. - (read_enum_type): Allow a ',' to end a list of values. - (read_range_type): Added code to check for long long. - * expread.y: Modified to use LONGEST instead of long where - necessary. Modified to use a default type of int for objects that - weren't in text space. - * findvar.c (locate_var_value, read_var_value): Modified to deal - with args passed by reference. - * inflow.c (create_inferior): Used CREATE_INFERIOR_HOOK if it - exists. - * infrun.c (attach_program): Run terminal inferior when attaching. - (wait_for_inferior): Removed several convex dependencies. - * main.c (float_handler): Created. - Made whatever signal indicates a stop configurable (via macro - STOP_SIGNAL). - (main): Setup use of above as a signal handler. Added check for - "-nw" in args already processed. - (command_line_input): SIGTSTP ==>STOP_SIGNAL. - - * expread.y: Added token BLOCKNAME to remove reduce/reduce - conflict. - * Makefile: Change message to reflect new grammar. - -Mon Apr 17 13:24:59 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * printcmd.c (compare_ints): Created. - (print_frame_args): Modified to always print arguments in the - order in which they were found in the symbol table. Figure out - what apots are missing on the fly. - - * stack.c (up_command): Error if no inferior or core file. - - * m-i386.h, m-symmetry.h [FRAMELESS_FUNCTION_INVOCATION]: Created; - same as m68k. - - * dbxread.c (define_symbol): Changed "desc==0" test to - "processing_gcc_compilation", which is the correct way to do it. - -Sat Apr 15 17:18:38 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * expread.y: Added precedence rules for arglists, ?:, and sizeof - to eliminate some shift-reduce conflicts. - * Makefile: Modified "Expect" message to conform to new results. - -Thu Apr 13 12:29:26 1989 Randall Smith (randy at plantaris.ai.mit.edu) - - * inflow.c (terminal_init_inferior): Fixed typo in recent diff - installation; TIOGETC ==> TIOCGETC. - - * m-vax.h, m-sun2.h, m-sun3.h, m-sparc.h, m-hp*.h, m-isi.h, - m-news.h [FRAMELESS_FUNCTION_INVOCATION]: Created macro with - appropriate definition. - -Wed Apr 12 15:30:29 1989 Randall Smith (randy at plantaris.ai.mit.edu) - - * blockframe.c (get_prev_frame_info): Added in a macro to specify - when a "frame" is called without a frame pointer being setup. - - * Makefile [clean]: Made sure to delete gnu malloc if it was being - used. - -Mon Apr 10 12:43:49 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (process_one_symbol): Reset within_function to 0 after - last RBRAC of a function. - - * dbxread.c (read_struct_type): Changed check for filling in of - TYPE_MAIN_VARIANT of type. - - * inflow.c (create_inferior): Conditionalized fork so that it - would be used if USG was defined and HAVE_VFORK was not defined. - - * defs.h: Added comment about enum command_class element - class_alias. - - * dbxread.c (process_one_symbol): Fixed a typo with interesting - implications for associative processing in the brain (':' ==> 'c'). - - * sparc-dep.c (isabranch): Changed name to isannulled, modified to - deal with coprocessor branches, and improved comment. - (single_step): Changed to trap at npc + 4 instead of pc +8 on - annulled branches. Changed name in call to isabranch as above. - - * m-sun4os4.h (STACK_END_ADDRESS): Changed it to 0xf8000000 under - os 4.0. - -Sat Apr 8 17:04:07 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (process_one_symbol): In the case N_FUN or N_FNAME the - value being refered to is sometimes just a text segment variable. - Catch this case. - - * infrun.c (wait_for_inferior), breakpoint.c - (breakpoint_stop_status): Move the selection of the frame to - inside breakpoint_stop_status so that the frame only gets selected - (and the symbols potentially read in) if the symbols are needed. - - * symtab.c (find_pc_psymbol): Fixed minor misthough (pc >= - fucntion start, not >). - - * breakpoint.c (_initialize_breakpoint): Change "delete" internal - help entry to simply refer to it being a prefix command (since the - list of subcommands is right there on a "help delete"). - -Fri Apr 7 15:22:18 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * blockframe.c (find_pc_partial_function): Created; figures out - what function pc is in (name and address) without reading in any - new symbols. - * symtab.h: Added decl for above. - * infrun.c (wait_for_inferior): Used instead of - find_pc_function_start. - * stack.c (print_frame_info): Used instead of hand coding for same - thing. - - * dbxread.c (psymtab_to_symtab): No longer patch readin pst's out - of the partial_symtab_list; need them there for some checks. - * blockframe.c (block_for_pc), source.c (select_source_symtab), - symtab.c (lookup_symbol, find_pc_symtab, list_symbols): Made extra - sure not to call psymtab_to_symtab with ->readin == 1, since these - psymtab now stay on the list. - * symtab.c (sources_info): Now distinguishes between psymtabs with - readin set and those with it not set. - - * symtab.c (lookup_symtab): Added check through partial symtabs - for name with .c appended. - - * source.c (select_source_symtab): Changed semantics a little so - that the argument means something. - * source.c (list_command), symtab.c (decode_line_1): Changed call - to select_source_symtab to match new conventions. - - * dbxread.c (add_file_command): This command no longer selects a - symbol table to list from. - - * infrun.c (wait_for_inferior): Only call find_pc_function (to - find out if we have debugging symbols for a function and hence if - we should step over or into it) if we are doing a "step". - -Thu Apr 6 12:42:28 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * main.c (command_line_input): Added a local buffer and only - copied information into the global main.c buffer when it is - appropriate for it to be saved (and repeated). - (dont_repeat): Only nail line when we are reading from stdin - (otherwise null lines won't repeat and what's in line needs to be - saved). - (read_command_lines): Fixed typo; you don't what to repeat when - reading command lines from the input stream unless it's standard - input. - - John Gilmore's (gnu@toad.com) mods for USG gdb: - * inflow.c: Removed inclusion of sys/user.h; no longer necessary. - (, terminal_init_inferior, terminal_inferior, terminal_ours_1, - term_status_command, _initialize_inflow) Seperated out declaration - and usage of terminal mode structures based on the existence of - the individual ioctls. - * utils.c (request_quit): Restore signal handler under USG. If - running under USG initialize sys_siglist at run time (too much - variation between systems). - -Wed Apr 5 13:47:24 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - John Gilmore's (gnu@toad.com) mods for USG gdb: - * default-dep.c: Moved include of sys/user.h to after include of - a.out.h. - (store_inferior_registers): Fixed error message. - (core_file_command): Improved error messages from reading in of - u area in core file. Changed calculation of offset of registers - to account for some machines putting it in as an offset rather - than an absolute address. Changed error messages for reading of - registers from core file. - - * coffread.c (read_file_hdr): Added final check for BADMAG macro - to use if couldn't recognize magic number. - * Makefile: Added explicit directions for alloca addition. - Included alloca.c in list of possible library files. Cleaned up - possible library usage. Included additional information on gcc - and include files. - - * source.c, remote.c, inflow.c, dbxread.c, core.c, coffread.c: - Changed include of sys/fcntl.h to an include of fcntl.h (as per - posix; presumably this will break fewer machines. I hopw). - * README: Added a pointer to comments at top of Makefile. - * Makefile: Added a comment about machines which need fcntl.h in - sys. - -Tue Apr 4 11:29:04 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * valprint.c (set_prettyprint_command, set_unionprint_command, - format_info): Created. - (_initialize_valprint): Added to lists of commands. - - * gdb.texinfo [Backtrace]: Added a section describing the format - if symbols have not yet been read in. - - * valprint.c (val_print): Added code to prettyprint structures if - "prettyprint" is set and only to print unions below the top level - if "unionprint" is set. - - * infcmd.c (registers_info), valprint.c (value_print, val_print): - Added argument to call to val_print indicating deptch of recursion. - - * symtab.[ch] (find_pc_psymbol): Created; finds static function - psymbol with value nearest to but under value passed. - * stack.c (print_frame_info): Used above to make sure I have best - fit to pc value. - - * symseg.h (struct partial_symbol): Added value field. - * dbxread.c (read_dbx_symtab): Set value field for partial symbols - saved (so that we can lookup static symbols). - - * symtab.[ch] (find_pc_symtab): Changed to external. - * stack.c (select_frame): Call above to make sure that symbols for - a selected frame is readin. - -Mon Apr 3 12:48:16 1989 Randall Smith (randy at plantaris.ai.mit.edu) - - * stack.c (print_frame_info): Modified to only print out full - stack frame info on symbols whose tables have been read in. - * symtab.c, symtab.h (find_pc_psymtab): Made function external; - above needed it. - - * main.c (,set_verbose_command, initialize_main): Created a - variable "info_verbose" which says to talk it up in various and - sundry places. Added command to set this variable. - * gdb.texinfo (GDB Output): Added documentation on "set verbose" - and changed the name of the "Screen Output" section to "GDB - Output". - * dbxread.c (psymtab_to_symtab): Added information message about - symbol readin. Conditionalized on above. - - * dbxread.c (define_symbol): Made an "i" constant be of class - LOC_CONST and an "r" constant be of class LOC_CONST_BYTES. - - * README: Made a note about modifications which may be necessary - to the manual for this version of gdb. - - * blockframe.c (get_prev_frame_info): Now we get saved address and - check for validity before we check for leafism. This means that - we will catch the fact that we are in start, but we will miss any - fns that start calls without an fp. This should be fine. - - * m-*.h (FRAME_CHAIN): Modified to return 0 if we are in start. - This is usually a test for within the first object file. - * m-sparc.h (FRAME_CHAIN): The test here is simply if the fp saved - off the the start sp is 0. - - * blockframe.c (get_prev_frame_info): Removed check to see if we - were in start. Screws up sparc. - - * m-sparc.h (FRAME_FIND_SAVED_REGISTERS): Changed test for dummy - frame to not need frame to be innermost. - - * gdb.texinfo: Added section on frameless invocations of functions - and when gdb can and can't deal with this. - - * stack.c (frame_info): Disallowed call if no inferior or core - file; fails gracefully if truely bad stack specfication has been - given (ie. parse_frame_specification returns 0). - -Fri Mar 31 13:59:33 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * infrun.c (normal_stop): Changed references to "unset-env" to - "delete env". - - * infcmd.c (_initialize_infcmd): Change reference to set-args in - help run to "set args". - - * remote.c (getpkt): Allow immediate quit when reading from - device; it could be hung. - - * coffread.c (process_coff_symbol): Modify handling of REG - parameter symbols. - -Thu Mar 30 15:27:23 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (symbol_file_command): Use malloc to allocate the - space for the string table in symbol_file_command (and setup a - cleanup for this). This allows a more graceful error failure if - there isn't any memory availible (and probably allows more memory - to be avail, depending on the machine). - - Additional mods for handling GNU C++ (from Tiemann): - * dbxread.c (read_type): Added case for '#' type (method type, I - believe). - (read_struct_type): If type code is undefined, make the main - variant for the type be itself. Allow recognition of bad format - in reading of structure fields. - * eval.c (evaluate_subexp): Modify evaluation of a member of a - structure and pointer to same to make sure that the syntax is - being used correctly and that the member is being accessed correctly. - * symseg.h: Added TYPE_CODE_METHOD to enum type_code. Add a - pointer to an array of argument types to the type structure. - * symtab.c (lookout_method_type, smash_to_method_type): Created. - * symtab.h (TYPE_ARG_TYPES): Created. - * valops.c (call_function): Modified handling of methods to be the - same as handling of functions; no longer check for members. - * valprint.c (val_print, type_print_varspec_{prefix,suffix}, - type_print_base): Added code to print method args correctly. - * values.c (value_virtual_fn_field): Modify access to virtual - function table. - -Wed Mar 29 13:19:34 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * findvar.c: Special cases for REGISTER_WINDOWS: 1) Return 0 if we - are the innermost frame, and 2) return the next frame in's value - if the SP is being looked for. - - * blockframe.c (get_next_frame): Created; returns the next (inner) - frame of the called frame. - * frame.h: Extern delcaration for above. - - * main.c (command_line_input): Stick null at end before doing - history expansion. - -Tue Mar 28 17:35:50 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (read_dbx_symtab): Added namestring assignment to - N_DATA/BSS/ABS case. Sigh. - -Sat Mar 25 17:49:07 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * expread.y: Defined YYDEBUG. - -Fri Mar 24 20:46:55 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * symtab.c (make_symbol_completion_list): Completely rewrote to - never call psymtab_to_symtab, to do a correct search (no - duplicates) through the visible symbols, and to include structure - and union fields in the things that it can match. - -Thu Mar 23 15:27:44 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (dbx_create_type): Created; allocates and inits space - for a type without putting it on the type vector lists. - (dbx_alloc_type): Uses above. - - * Makefile: xgdb.o now produced by default rules for .o.c. - -Fri Mar 17 14:27:50 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * infrun.c: Fixed up inclusion of aouthdr.h on UMAX_PTRACE. - - * Makefile, config.gdb: Added hp300bsd to potential - configurations. - * hp300bsd-dep.c, m-hp300bsd.h: Created. - - * infrun.c (wait_for_inferior): Rewrote to do no access to - inferior until we make sure it's still there. - - * inflow.c (inferior_died): Added a select to force the selected - frame to null when inferior dies. - - * dbxread.c (symbol_file_command): free and zero symfile when - discarding symbols. - - * core.c (xfer_core_file): Extended and cleaned up logic in - interpeting memory address. - - * core.c (xfer_core_file): Extended opening comment. - -Thu Mar 16 15:39:42 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * coffread.c (symbol_file_command): Free symfile name when freeing - contents. - - * blockframe.c (get_prev_frame_info): Added to fatal error message - to indicate that it should never happen. - - * stack.c (frame_info): Printed out value of "saved" sp seperately - to call attention to the fact that it isn't stored in memory - anywhere; the actual previous frames address is printed. - - * m-sparc.h (FRAME_FIND_SAVED_REGS): Set address of sp saved in - frame to value of fp (rather than value of sp in current frame). - - * expread.y: Allow "unsigned" as a type itself, as well as a type - modifier. - - * coffread.c: Added declaration for fclose - -Fri Mar 10 17:22:31 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * main.c (command_line_input): Checked for -1 return from - readline; indicates EOF. - -Fri Mar 3 00:31:27 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * remote.c (remote_open): Cast return from signal to (void (*)) to - avoid problems on machines where the return type of signal is (int - (*)). - - * Makefile: Removed deletion of version control from it (users - will need it for their changes). - -Thu Mar 2 15:32:21 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * symmetry-dep.c (print_1167_regs): Print out effective doubles on - even number regs. - (fetch_inferior_registers): Get the floating point regs also. - - * xgdb.c (do_command): Copied command before calling execute - command (so that execute_command wouldn't write into text space). - - * copying.awk: Created (will produce copying.c as output when - given COPYING as input). - * Makefile: Used above to create copying.c. - * main.c: Took out info_warranty and info_copying. - - * *.*: Changed copyright notice to use new GNU General Public - License (includes necessary changes to manual). - - * xgdb.c (create_text_widget): Created text_widget before I create - the source and sink. - (print_prompt): Added fflush (stdout). - - * Makefile: Added -lXmu to the compilation line for xgdb. Left - the old one there incase people still had R2. - - * README: Added note about -gg format. - - * remote.c (getpkt): Fixed typo; && ==> &. - - * Makefile: Added new variable READLINE_FLAGS so that I could - force compilation of readline.c and history.c with -DSYSV on - system V machines. Mentioned in Makefile comments at top. - -Wed Mar 1 17:01:01 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * hp9k320-dep.c (store_inferior_registers): Fixed typo. - -Fri Feb 24 14:58:45 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * hp9k320-dep.c (store_inferior_registers, - fetch_inferior_registers): Added support for remote debugging. - - * remote.c (remote_timer): Created. - (remote_open, readchar): Setup to timeout reads if they take - longer than "timeout". This allows one to debug how long such - things take. - (putpkt): Modified to print a debugging message (if such things - are enabled) each time it resends a packet. - (getpkt): Modified to make the variable CSUM unsigned and read it - CSUM with an & 0xff (presumably to deal with poor sign extension - on some machines). Also made c1 and c2 unsigned. - (remote_wait): Changed buffer to unsigned status. - (remote_store_registers, remote_write_bytes): Puts a null byte at - the end of the control string. - - * infcmd.c (attach_command, detach_command, _initialize_infcmd): - Made attach_command and detach_command always availible, but - modified them to only allow device file attaches if ATTACH_DETACH - is not defined. - - * gdb.texinfo: Added cross reference from attach command to remote - debugging. - -Thu Feb 23 12:37:59 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * remote.c (remote_close): Created to close the remote connection - and set the remote_debugging flag to 0. - * infcmd.c (detach_command): Now calls the above when appropriate. - - * gdb.texinfo: Removed references to the ``Distribution'' section - in the copyright. - - * main.c, utils.c (ISATTY): Created default defintions of this - macro which use isatty and fileno. - * utils.c (fprintf_filtered, print_spaces_filtered), main.c - (command_loop, command_line_input): Used this macro. - * m-news.h: Created a definition to override this one. - - * utils.c (fprintf_filtered): Made line_size static (clueless). - - * utils.c (fprintf_filtered): Changed max length of line printed - to be 255 chars or twice the format length. - - * symmetry-dep.c, m-symmetry: Fixed typo (^L ==> ). - - * printcmd.c (do_examine): Fixed typo (\n ==> \t). - -Wed Feb 22 16:00:33 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - Contributed by Jay Vosburgh (jay@mentor.cc.purdue.edu) - * m-symmetry.h, symmetry-dep.c: Created. - * Makefile: Added above in appropriate lists. - * config.gdb: Added "symmetry" target. - - * utils.c (prompt_for_continue): Zero'd chars_printed also. - - * utils.c (fprintf_filtered): Call prompt for continue instead of - doing it yourself. - - * dbxread.c (read_dbx_symtab): Added code to conditionalize what - symbol type holds to "x.o" or "-lx" symbol that indicates the - beginning of a new file. - -Tue Feb 21 16:22:13 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * gdb.texinfo: Deleted @ignore block at end of file. - - * findvar.c, stack.c: Changed comments that refered to "frame - address" to "frame id". - - * findvar.c (locate_var_value): Modified so that taking the - address of an array generates an object whose type is a pointer to - the elements of the array. - -Sat Feb 18 16:35:14 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * gdb.texinfo: Removed reference to "!" as a shell escape - character. Added a section on controling screen output - (pagination); changing "Input" section to "User Interface" - section. Changed many inappropriate subsubsection nodes into - subsections nodes (in the readline and history expansion - sections). - -Fri Feb 17 11:10:54 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * utils.c (set_screensize_command): Created. - (_initialize_utils): Added above to setlist. - - * main.c (main): Added check to see if ~/.gdbinit and .gdbinit - were the same file; only one gets read if so. Had to include - sys/stat.h for this. - - * valprint.c (type_print_base): Changed calls to print_spaces to - print_spaces_filtered. - - * main.c (command_line_input): Chaned test for command line - editing to check for stdin and isatty. - - * main.c (command_loop): Call reinitialize_more_filter before each - command (if reading from stdin and it's a tty). - utils.c (initialize_more_filter): Changed name to - reinitialize_more_filter; killed arguments. - utils.c (_initialize_utils): Created; initialized lines_per_page - and chars_per_line here. - - * utils.c (fprintf_filtered): Removed printing of "\\\n" after - printing linesize - 1 chars; assume that the screen display will - take care of that. Still watching that overflow. - - * main.c: Created the global variables linesize and pagesize to - describe the number of chars per line and lines per page. - -Thu Feb 16 17:27:43 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * printcmd.c (do_examine, print_scalar_formatted, print_address, - whatis_command, do_one_display, ptype_command), valprint.c - (value_print, val_print, type_print_method_args, type_print_1, - type_print_derivation_info, type_print_varspec_suffix, - type_print_base), breakpoint.c (breakpoints_info, breakpoint_1), - values.c (history_info), main.c (editing_info, warranty_info, - copying_info), infcmd.c (registers_info), inflow.c - (term_status_command), infrun.c (signals_info), stack.c - (backtrace_command, print_frame_info), symtab.c (list_symbols, - output_source_filename), command.c (help_cmd, help_list, - help_command_list): Replaced calls to printf, fprintf, and putc - with calls to [f]printf_filtered to handle more processing. - Killed local more emulations where I noticed them. - -Wed Feb 15 15:27:36 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * defs.h, utils.c (initialize_more_filter, fprintf_filtered, - printf_filtered): Created a printf that will also act as a more - filter, prompting the user for a whenever the page length - is overflowed. - - * symtab.c (list_symbols): Elminated some code inside of an #if 0. - -Tue Feb 14 11:11:24 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * Makefile: Turned off backup versions for this file; it changes - too often. - - * command.c (lookup_cmd, _initialize_command): Changed '!' so that - it was no longer a shell escape. "sh" must be used. - - * main.c (command_line_input, set_history_expansion, - initialize_main): Turned history expansion on, made it the - default, and only execute it if the first character in the line is - a '!'. - - * version.c, gdb.texinfo: Moved version to 3.2 (as usual, jumping - the gun some time before release). - - * gdb.texinfo: Added sections (adapted from Brian's notes) on - command line editing and history expansion. - - * main.c (set_command_editing, initialize_main): Modified name to - set_editing and modified command to "set editing". - - * Makefile: Put in dependencies for READLINEOBJS. - - * main.c (history_info, command_info): Combined into new command - info; deleted history_info. - (initialize_main): Deleted "info history" command; it was - interfering with the value history. - - * coffread.c (enter_linenos): Modified to do bit copy instead of - pointer dereference, since the clipper machine can't handle having - longs on short boundaries. - (read_file_hdr): Added code to get number of syms for clipper. - - * stack.c (return_command): Fixed method for checking when all of - the necessary frames had been popped. - - * dbxread.c (read_dbx_symtab (ADD_PSYMBOL_TO_LIST)): Fixed typo in - allocation length. - -Mon Feb 13 10:03:27 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * dbxread.c (read_dbx_symtab): Split assignment to namestring into - several different assignments (so that it wouldn't be done except - when it had to be). Shortened switches and duplicated code to - produce the lowest possible execution time. Commented (at top of - switch) which code I duplicated. - - * dbxread.c (read_dbx_symtab): Modified which variables were - register and deleted several variables which weren't used. Also - eliminated 'F' choice from subswitch, broke out strcmp's, reversed - compare on line 1986, and elminated test for !namestring[0]; it is - caught by following test for null index of ':'. - -Sun Feb 12 12:57:56 1989 Randall Smith (randy at plantaris.ai.mit.edu) - - * main.c (gdb_completer_word_break_characters): Turned \~ into ~. - -Sat Feb 11 15:39:06 1989 Randall Smith (randy at plantaris.ai.mit.edu) - - * symtab.c (find_pc_psymtab): Created; checks all psymtab's till - it finds pc. - (find_pc_symtab): Used; fatal error if psymtab found is readin - (should have been caught in symtab loop). - (lookup_symbol): Added check before scan through partial symtab - list for symbol name to be on the misc function vector (only if in - VAR_NAMESPACE). Also made sure that psymtab's weren't fooled with - if they had already been read in. - (list_symbols): Checked through misc_function_vector for matching - names if we were looking for functions. - (make_symbol_completion_list): Checked through - misc_function_vector for matching names. - * dbxread.c (read_dbx_symtab): Don't bother to do processing on - global function types; this will be taken care of by the - misc_function hack. - - * symtab.h: Modified comment on misc_function structure. - -Fri Feb 10 18:09:33 1989 Randall Smith (randy at plantaris.ai.mit.edu) - - * symseg.h, dbxread.c (read_dbx_symtab, init_psymbol_list, - start_psymtab, end_psymtab), coffread.c (_initialize_coff), - symtab.c (lookup_partial_symbol, list_symbols, - make_symbol_completion_list): Changed separate variables for - description of partial symbol allocation into a specific kind of - structure. - - (read_dbx_symtab, process_symbol_for_psymtab): Moved most of - process_symbol_for_psymtab up into read_dbx_symtab, moved a couple - of symbol types down to the ingore section, streamlined (I hope) - code some, modularized access to psymbol lists. - -Thu Feb 9 13:21:19 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * main.c (command_line_input): Made sure that it could recognize - newlines as indications to repeat the last line. - - * symtab.c (_initialize_symtab): Changed size of builtin_type_void - to be 1 for compatibility with gcc. - - * main.c (initialize_main): Made history_expansion the default - when gdb is compiled with HISTORY_EXPANSION. - - * readline.c, readline.h, history.c, history.h, general.h, - emacs_keymap.c, vi_keymap.c, keymaps.c, funmap.c: Made all of - these links to /gp/gnu/bash/* to keep them updated. - * main.c (initialize_main): Made default be command editing on. - -Wed Feb 8 13:32:04 1989 & Smith (randy at hobbes) - - * dbxread.c (read_dbx_symtab): Ignore N_BSLINE on first - readthrough. - - * Makefile: Removed convex-dep.c from list of distribution files. - -Tue Feb 7 14:06:25 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * main.c: Added command lists sethistlist and unsethistlist to - accesible command lists. - (parse_binary_operation): Created to parse a on/1/yes vs. off/0/no - spec. - (set_command_edit, set_history, set_history_expansion, - set_history_write, set_history_size, set_history_filename, - command_info, history_info): Created to allow users to control - various aspects of command line editing. - - * main.c (symbol_creation_function): Created. - (command_line_input, initialize_main): Added rest of stuff - necessary for calling bfox' command editing routines under - run-time control. - * Makefile: Included readline and history source files for command - editing; also made arrangements to make sure that the termcap - library was available. - * symtab.c (make_symbol_completion_list): Created. - -Mon Feb 6 16:25:25 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * main.c: Invented variables to control command editing. - command_editing_p, history_expansion_p, history_size, - write_history_p, history_filename. Initialized them to default - values in initialize_main. - - * infcmd.c (registers_info), infrun.c (signals_info), - * main.c (gdb_read_line): Changed name to command_line_input. - (readline): Changed name to gdb_readline; added second argument - indicating that the read value shouldn't be saved (via malloc). - * infcmd.c (registers_info), infrun.c (signals_info), main.c - (copying_info), symtab.c (output_source_filename, MORE, - list_symbols): Converted to use gdb_readline in place of - gdb_read_line. - - -Sun Feb 5 17:34:38 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * blockframe.c (get_frame_saved_regs): Removed macro expansion - that had accidentally been left in the code. - -Sat Feb 4 17:54:14 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * main.c (gdb_read_line, readline): Added function readline and - converted gdb_read_line to use it. This was a conversion to the - line at a time style of input, in preparation for full command - editing. - -Fri Feb 3 12:39:03 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (read_dbx_symtab): Call end_psymtab at the end of - read_dbx_symtab if any psymtab still needs to be completed. - - * config.gdb, sun3-dep.c: Brought these into accord with the - actual sun2 status (no floating point period; sun3-dep.c unless - has os > 3.0). - * m-sun2os2.h: Deleted; not needed. - - * config.gdb: Added a couple of aliases for machines in the - script. - - * infrun.c: Added inclusion of aouthdr.h inside of #ifdef UMAX - because ptrace needs to know about the a.out header. - - * Makefile: Made dep.o depend on dep.c and config.status only. - - * expread.y: Added declarations of all of the new write_exp_elt - functions at the include section in the top. - - * Makefile: Added a YACC definition so that people can use bison - if they wish. - - * Makefile: Added rms' XGDB-README to the distribution. - - * Makefile: Added removal of init.o on a "make clean". - -Thu Feb 2 16:27:06 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * *-dep.c: Deleted definition of COFF_FORMAT if AOUTHDR was - defined since 1) We *may* (recent mail message) want to define - AOUTHDR under a basically BSD system, and 2) AOUTHDR is sometimes - a typedef in coff encapsulation setups. Also removed #define's of - AOUTHDR if AOUTHDR is already defined (inside of coff format). - * core.c, dbxread.c: Removed #define's of AOUTHDR if AOUTHDR is - already defined (inside of coff format). - -Tue Jan 31 12:56:01 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * GDB 3.1 released. - - * values.c (modify_field): Changed test for endianness to assign - to integer and reference character (so that all bits would be - defined). - -Mon Jan 30 11:41:21 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * news-dep.c: Deleted inclusion of fcntl.h; just duplicates stuff - found in sys/file.h. - - * i386-dep.c: Included default definition of N_SET_MAGIC for - COFF_FORMAT. - - * config.gdb: Added checks for several different operating - systems. - - * coffread.c (read_struct_type): Put in a flag variable so that - one could tell when you got to the end of a structure. - - * sun3-dep.c (core_file_command): Changed #ifdef based on SUNOS4 - to ifdef based on FPU. - - * infrun.c (restore_inferior_status): Changed error message to - "unable to restore previously selected frame". - - * dbxread.c (read_dbx_symtab): Used intermediate variable in error - message reporting a bad symbol type. (scan_file_globals, - read_ofile_symtab, read_addl_syms): Data type of "type" changed to - unsigned char (which is what it is). - * i386-dep.c: Removed define of COFF_FORMAT if AOUTHDR is defined. - Removed define of a_magic to magic (taken care of by N_MAGIC). - (core_file_command): Zero'd core_aouthdr instead of setting magic - to zero. - * i386-pinsn.c: Changed jcxz == jCcxz in jump table. - (putop): Added a case for 'C'. - (OP_J): Added code to handle possible masking of PC value on - certain kinds of data. - m-i386gas.h: Moved COFF_ENCAPSULATE to before inclusion of - m-i386.h and defined NAMES_HAVE_UNDERSCORE. - - * coffread.c (unrecrod_misc_function, read_coff_symtab): Added - symbol number on which error occured to error output. - -Fri Jan 27 11:55:04 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * Makefile: Removed init.c in make clean. Removed it without -f - and with leading - in make ?gdb. - -Thu Jan 26 15:08:03 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - Changes to get it to work on gould NP1. - * dbxread.c (read_dbx_symtab): Included cases for N_NBDATA and - N_NBBSS. - (psymtab_to_symtab): Changed declaration of hdr to - DECLARE_FILE_HEADERS. Changed access to use STRING_TABLE_SIZE and - SYMBOL_TABLE_SIZE. - * gld-pinsn.c (findframe): Added declaration of framechain() as - FRAME_ADDR. - - * coffread.c (read_coff_symtab): Avoided treating typedefs as - external symbol definitions. - -Wed Jan 25 14:45:43 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * Makefile: Removed reference to alloca.c. If they need it, they - can pull alloca.o from the gnu-emacs directory. - - * version.c, gdb.texinfo: Updated version to 3.1 (jumping the gun - a bit so that I won't forget when I release). - - * m-sun2.h, m-sun2os2.h, m-sun3os4.h, config.gdb: Modified code so - that default includes new sun core, ptrace, and attach-detach. - Added defaults for sun 2 os 2. - - Modifications to reset stack limit back to what it used to be just - before exec. All mods inside of #ifdef SET_STACK_LIMIT_HUGE. - * main.c: Added global variable original_stack_limit. - (main): Set original_stack_limit to original stack limit. - * inflow.c: Added inclusion of necessary files and external - reference to original_stack_limit. - (create_inferior): Reset stack limit to original_stack_limit. - - * dbxread.c (read_dbx_symtab): Killed PROFILE_SYMBOLS ifdef. - - * sparc-dep.c (isabranch): Multiplied offset by 4 before adding it - to addr to get target. - - * Makefile: Added definition of SHELL to Makefile. - - * m-sun2os4.h: Added code to define NEW_SUN_PTRACE, NEW_SUN_CORE, - and ATTACH_DETACH. - * sun3-dep.c: Added code to avoid fp regs if we are on a sun2. - -Tue Jan 24 17:59:14 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (read_array_type): Added function. - (read_type): Added call to above instead of inline code. - - * Makefile: Added ${GNU_MALLOC} to the list of dependencies for - the executables. - -Mon Jan 23 15:08:51 1989 Randall Smith (randy at plantaris.ai.mit.edu) - - * gdb.texinfo: Added paragraph to summary describing languages - with which gdb can be run. Also added descriptions of the - "info-methods" and "add-file" commands. - - * symseg.h: Commented a range type as having TYPE_TARGET_TYPE - pointing at the containing type for the range (often int). - * dbxread.c (read_range_type): Added code to do actual range types - if they are defined. Assumed that the length of a range type is - the length of the target type; this is a lie, but will do until - somebody gets back to me as to what these silly dbx symbols mean. - - * dbxread.c (read_range_type): Added code to be more picky about - recognizing builtins as range types, to treat types defined as - subranges of themselves to be subranges of int, and to recognize - the char type idiom from dbx as a special case. - -Sun Jan 22 01:00:13 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-vax.h: Removed definition of FUNCTION_HAS_FRAME_POINTER. - * blockframe.c (get_prev_frame_info): Removed default definition - and use of above. Instead conditionalized checking for leaf nodes - on FUNCTION_START_OFFSET (see comment in code). - -Sat Jan 21 16:59:19 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (read_range_type): Fixed assumption that integer was - always type 1. - - * gdb.texinfo: Fixed spelling mistake and added a note in the - running section making it clear that users may invoke subroutines - directly from gdb. - - * blockframe.c: Setup a default definition for the macro - FUNCTION_HAS_FRAME_POINTER. - (get_prev_frame_info): Used this macro instead of checking - SKIP_PROLOGUE directly. - * m-vax.h: Overroad definition; all functions on the vax have - frame pointers. - -Fri Jan 20 12:25:35 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * core.c: Added default definition of N_MAGIC for COFF_FORMAT. - - * xgdb.c: Installed a fix to keep the thing from dying when there - isn't any frame selected. - - * core.c: Made a change for the UMAX system; needs a different - file included if using that core format. - - * Makefile: Deleted duplicate obstack.h in dbxread.c dependency. - - * munch: Modified (much simpler) to cover (I hope) all cases. - - * utils.c (save_cleanups, restore_cleanups): Added functions to - allow you to push and pop the chain of cleanups to be done. - * defs.h: Declared the new functions. - * main.c (catch_errors): Made sure that the only cleanups which - would be done were the ones put on the chain *after* the current - location. - - * m-*.h (FRAME_CHAIN_VALID): Removed check on pc in the current - frame being valid. - * blockframe.c (get_prev_frame_info): Made the assumption that if - a frame's pc value was within the first object file (presumed to - be /lib/crt0.o), that we shouldn't go any higher. - - * infrun.c (wait_for_inferior): Do *not* execute check for stop pc - at step_resume_break if we are proceeding over a breakpoint (ie. - if trap_expected != 0). - - * Makefile: Added -g to LDFLAGS. - - * m-news.h (POP_FRAME) Fixed typo. - - * printcmd.c (print_frame_args): Modified to print out register - params in order by .stabs entry, not by register number. - - * sparc-opcode.h: Changed declaration of (struct - arith_imm_fmt).simm to be signed (as per architecture manual). - * sparc-pinsn.c (fprint_addr1, print_insn): Forced a cast to an - int, so that we really would get signed behaivior (default for sun - cc is unsigned). - - * i386-dep.c (i386_get_frame_setup): Replace function with new - function provided by pace to fix bug in recognizing prologue. - -Thu Jan 19 11:01:22 1989 Randall Smith (randy at plantaris.ai.mit.edu) - - * infcmd.c (run_command): Changed error message to "Program not - restarted." - - * value.h: Changed "frame" field in value structure to be a - FRAME_ADDR (actually CORE_ADDR) so that it could survive across - calls. - - * m-sun.h (FRAME_FIND_SAVED_REGS): Fixed a typo. - - * value.h: Added lval: "lval_reg_frame_relative" to indicate a - register that must be interpeted relative to a frame. Added - single entry to value structure: "frame", used to indicate which - frame a relative regnum is relative to. - * findvar.c (value_from_register): Modified to correctly setup - these fields when needed. Deleted section to fiddle with last - register copied on little endian machine; multi register - structures will always occupy an integral number of registers. - (find_saved_register): Made extern. - * values.c (allocate_value, allocate_repeat_value): Zero frame - field on creation. - * valops.c (value_assign): Added case for lval_reg_frame_relative; - copy value out, modify it, and copy it back. Desclared - find_saved_register as being external. - * value.h: Removed addition of kludgy structure; thoroughly - commented file. - * values.c (free_value, free_all_values, clear_value_history, - set_internalvar, clear_internavars): Killed free_value. - -Wed Jan 18 20:09:39 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * value.h: Deleted struct partial_storage; left over from - yesterday. - - * findvar.c (value_from_register): Added code to create a value of - type lval_reg_partsaved if a value is in seperate registers and - saved in different places. - -Tue Jan 17 13:50:18 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * value.h: Added lval_reg_partsaved to enum lval_type and - commented enum lval_type. Commented value structure. - Added "struct partial_register_saved" to value struct; added - macros to deal with structure to value.h. - * values.c (free_value): Created; special cases lval_reg_partsaved - (which has a pointer to an array which also needs to be free). - (free_all_values, clear_value_history, set_internalvar, - clear_internalvars): Modified to use free_values. - - * m-sunos4.h: Changed name to sun3os4.h. - * m-sun2os4.h, m-sun4os4.h: Created. - * config.gdb: Added configuration entries for each of the above. - * Makefile: Added into correct lists. - - * Makefile: Added dependencies on a.out.encap.h. Made - a.out.encap.h dependent on a.out.gnu.h and dbxread.c dependent on - stab.gnu.h. - - * infrun.c, remote.c: Removed inclusion of any a.out.h files in - these files; they aren't needed. - - * README: Added comment about bug reporting and comment about - xgdb. - - * Makefile: Added note to HPUX dependent section warning about - problems if compiled with gcc and mentioning the need to add - -Ihp-include to CFLAGS if you compile on those systems. Added a - note about needing the GNU nm with compilers *of gdb* that use the - coff encapsulate feature also. * hp-include: Made symbolic link - over to /gp/gnu/binutils. - - * Makefile: Added TSOBS NTSOBS OBSTACK and REGEX to list of things - to delete in "make clean". Also changed "squeakyclean" target as - "realclean". - - * findvar.c (value_from_register): Added assignment of VALUE_LVAL - to be lval_memory when that is appropriate (original code didn't - bother because it assumed that it was working with a pre lval - memoried value). - - * expread.y (yylex): Changed to only return type THIS if the - symbol "$this" is defined in some block superior or equal to the - current expression context block. - -Mon Jan 16 13:56:44 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-*.h (FRAME_CHAIN_VALID): On machines which check the relation - of FRAME_SAVED_PC (thisframe) to first_object_file_end (all except - gould), make sure that the pc of the current frame also passes (in - case someone stops in _start). - - * findvar.c (value_of_register): Changed error message in case of - no inferior or core file. - - * infcmd.c (registers_info): Added a check for inferior or core - file; error message if not. - - * main.c (gdb_read_line): Modified to take prompt as argument and - output it to stdout. - * infcmd.c (registers_info, signals_info), main.c (command_loop, - read_command_lines, copying_info), symtab.c (decode_line_2, - output_source_filename, MORE, list_symbols): Changed calling - convention used to call gdb_read_line. - - * infcmd.c, infrun.c, main.c, symtab.c: Changed the name of the - function "read_line" to "gdb_read_line". - * breakpoint.c: Deleted external referenced to function - "read_line" (not needed by code). - -Fri Jan 13 12:22:05 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * i386-dep.c: Include a.out.encap.h if COFF_ENCAPSULATE. - (N_SET_MAGIC): Defined if not defined by include file. - (core_file_command): Used N_SET_MAGIC instead of assignment to - a_magic. - (exec_file_command): Stuck in a HEADER_SEEK_FD. - - * config.gdb: Added i386-dep.c as depfile for i386gas choice. - - * munch: Added -I. to cc to pick up things included by the param - file. - - * stab.gnu.def: Changed name to stab.def (stab.gnu.h needs this name). - * Makefile: Changed name here also. - * dbxread.c: Changed name of gnu-stab.h to stab.gnu.h. - - * gnu-stab.h: Changed name to stab.gnu.h. - * stab.gnu.def: Added as link to binutils. - * Makefile: Put both in in the distribution. - -Thu Jan 12 11:33:49 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c: Made which stab.h is included dependent on - COFF_ENCAPSULATE; either or "gnu-stab.h". - * Makefile: Included gnu-stab.h in the list of files to include in - the distribution. - * gnu-stab.h: Made a link to /gp/gnu/binutils/stab.h - - * Makefile: Included a.out.gnu.h and m-i386gas.h in list of - distribution files. - * m-i386gas.h: Changed to include m-i386.h and fiddle with it - instead of being a whole new file. - * a.out.gnu.h: Made a link to /gp/gnu/binutils/a.out.gnu.h. - - Chris Hanson's changes to gdb for hp Unix. - * Makefile: Modified comments on hpux. - * hp9k320-dep.c: #define'd WOPR & moved inclusion of signal.h - * inflow.c: Moved around declaratiosn of and - inside of USG depends and deleted all SYSV ifdef's - (use USG instead). - * munch: Modified to accept any number of spaces between the T and - the symbol name. - - Pace's changes to gdb to work with COFF_ENCAPSULATE (robotussin): - * config.gdb: Added i386gas to targets. - * default-dep.c: Include a.out.encap.h if COFF_ENCAPSULATE. - (N_SET_MAGIC): Defined if not defined by include file. - (core_file_command): Used N_SET_MAGIC instead of assignment to a_magic. - (exec_file_command): Stuck in a HEADER_SEEK_FD. - * infrun.c, remote.c: Added an include of a.out.encap.h if - COFF_ENCAPSULATE defined. This is commented out in these two - files, I presume because the definitions aren't used. - * m-i386gas.h: Created. - * dbxread.c: Included defintions for USG. - (READ_FILE_HEADERS): Now uses HEADER_SEEK_FD if it exists. - (symbol_file_command): Deleted use of HEADER_SEEK_FD. - * core.c: Deleted extra definition of COFF_FORMAT. - (N_MAGIC): Defined to be a_magic if not already defined. - (validate_files): USed N_MAGIC instead of reading a_magic. - -Wed Jan 11 12:51:00 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * remote.c: Upped PBUFSIZ. - (getpkt): Added zeroing of c inside loop in case of error retry. - - * dbxread.c (read_dbx_symtab, process_symbol_for_psymtab): Removed - code to not put stuff with debugging symbols in the misc function - list. Had been ifdef'd out. - - * gdb.texinfo: Added the fact that the return value for a function - is printed if you use return. - - * infrun.c (wait_for_inferior): Removed test in "Have we hit - step_resume_breakpoint" for sp values in proper orientation. Was - in there for recursive calls in functions without frame pointers - and it was screwing up calls to alloca. - - * dbxread.c: Added #ifdef COFF_ENCAPSULATE to include - a.out.encap.h. - (symbol_file_command): Do HEADER_SEEK_FD when defined. - * dbxread.c, core.c: Deleted #ifdef ROBOTUSSIN stuff. - * robotussin.h: Deleted local copy (was symlink). - * a.out.encap.h: Created symlink to - /gp/gnu/binutils/a.out.encap.h. - * Makefile: Removed robotussin.h and included a.out.encap.h in - list of files. - - * valprint.c (val_print, print_scalar_formatted): Changed default - precision of printing float value; now 6 for a float and 16 for a - double. - - * findvar.c (value_from_register): Added code to deal with the - case where a value is spread over several registers. Still don't - deal with the case when some registers are saved in memory and - some aren't. - -Tue Jan 10 17:04:04 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * xgdb.c (xgdb_create_window): Removed third arg (XtDepth) to - frameArgs. - - * infrun.c (handle_command): Error if signal number is less or - equal to 0 or greater or equal to NSIG or a signal number is not - provided. - - * command.c (lookup_cmd): Modified to not convert command section - of command line to lower case in place (in case it isn't a - subcommand, but an argument to a command). - -Fri Jan 6 17:57:34 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c: Changed "text area" to "data area" in comments on - N_SETV. - -Wed Jan 4 12:29:54 1989 Randall Smith (randy at gluteus.ai.mit.edu) - - * dbxread.c: Added definitions of gnu symbol types after inclusion - of a.out.h and stab.h. - -Mon Jan 2 20:38:31 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * eval.c (evaluate_subexp): Binary logical operations needed to - know type to determine whether second value should be evaluated. - Modified to discover type before binup_user_defined_p branch. - Also commented "enum noside". - - * Makefile: Changed invocations of munch to be "./munch". - - * gdb.texinfo: Updated to refer to current version of gdb with - January 1989 last update. - - * coffread.c (end_symtab): Zero context stack when finishing - lexical contexts. - (read_coff_symtab): error if context stack 0 in ".ef" else case. - - * m-*.h (FRAME_SAVED_PC): Changed name of argument from "frame" to - "FRAME" to avoid problems with replacement of "->frame" part of - macro. - - * i386-dep.c (i386_get_frame_setup): Added codestream_get() to - move codestream pointer up to the correct location in "subl $X, - %esp" case. - -Sun Jan 1 14:24:35 1989 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * valprint.c (val_print): Rewrote routine to print string pointed - to by char pointer; was producing incorrect results when print_max - was 0. - -Fri Dec 30 12:13:35 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * dbxread.c (read_dbx_symtab, process_symbol_for_psymtab): Put - everything on the misc function list. - - * Checkpointed distribution. - - * Makefile: Added expread.tab.c to the list of things slated for - distribution. - -Thu Dec 29 10:06:41 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * stack.c (set_backtrace_limit_command, backtrace_limit_info, - bactrace_command, _initialize_stack): Removed modifications for - limit on backtrace. Piping the backtrace through an interuptable - "more" emulation is a better way to do it. - -Wed Dec 28 11:43:09 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * stack.c - (set_backtrace_limit_command): Added command to set a limit to the - number of frames for a backtrace to print by default. - (backtrace_limit_info): To print the current limit. - (backtrace_command): To use the limit. - (_initialize_stack): To initialize the limit to its default value - (30), and add the set and info commands onto the appropriate - command lists. - - * gdb.texinfo: Documented changes to "backtrace" and "commands" - commands. - - * stack.c (backtrace_command): Altered so that a negative argument - would show the last few frames on the stack instead of the first - few. - (_initialize_stack): Modified help documentation. - - * breakpoint.c (commands_command): Altered so that "commands" with - no argument would refer to the last breakpoint set. - (_initialize_breakpoint): Modified help documentation. - - * infrun.c (wait_for_inferior): Removed ifdef on Sun4; now you can - single step through compiler generated sub calls and will die if - you next off of the end of a function. - - * sparc-dep.c (single_step): Fixed typo; "break_insn" ==> "sizeof - break_insn". - - * m-sparc.h (INIT_EXTRA_FRAME_INFO): Set the bottom of a stack - frame to be the bottom of the stack frame inner from this, if that - inner one is a leaf node. - - * dbxread.c (read_dbx_symtab): Check to make sure we don't add a - psymtab to it's own dependency list. - - * dbxread.c (read_dbx_symtab): Modified check for duplicate - dependencies to catch them correctly. - -Tue Dec 27 17:02:09 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-*.h (FRAME_SAVED_PC): Modified macro to take frame info - pointer as argument. - * stack.c (frame_info), blockframe.c (get_prev_frame_info), - gld-pinsn.c (findframe), m-*.h (SAVED_PC_AFTER_CALL, - FRAME_CHAIN_VALID, FRAME_NUM_ARGS): Changed usage of macros to - conform to above. - * m-sparc.h (FRAME_SAVED_PC), sparc-dep.c (frame_saved_pc): - Changed frame_saved_pc to have a frame info pointer as an - argument. - - * m-vax.h, m-umax.h, m-npl.h, infrun.c (wait_for_inferior), - blockframe.c (get_prev_frame_info): Modified SAVED_PC_AFTER_CALL - to take a frame info pointer as an argument. - - * blockframe.c (get_prev_frame_info): Altered the use of the - macros FRAME_CHAIN, FRAME_CHAIN_VALID, and FRAME_CHAIN_COMBINE to - use frame info pointers as arguments instead of frame addresses. - * m-vax.h, m-umax.h, m-sun3.h, m-sun3.h, m-sparc.h, m-pn.h, - m-npl.h, m-news.h, m-merlin.h, m-isi.h, m-hp9k320.h, m-i386.h: - Modified definitions of the above macros to suit. - * m-pn.h, m-npl.h, gould-dep.c (findframe): Modified findframe to - use a frame info argument; also fixed internals (wouldn't work - before). - - * m-sparc.h: Cosmetic changes; reordered some macros and made sure - that nothing went over 80 lines. - -Thu Dec 22 11:49:15 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * Version 3.0 released. - - * README: Deleted note about changing -lobstack to obstack.o. - -Wed Dec 21 11:12:47 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-vax.h (SKIP_PROLOGUE): Now recognizes gcc prologue also. - - * blockframe.c (get_prev_frame_info): Added FUNCTION_START_OFFSET - to result of get_pc_function_start. - * infrun.c (wait_for_inferior): Same. - - * gdb.texinfo: Documented new "step" and "next" behavior in - functions without line number information. - -Tue Dec 20 18:00:45 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * infcmd.c (step_1): Changed behavior of "step" or "next" in a - function witout line number information. It now sets the step - range around the function (to single step out of it) using the - misc function vector, warns the user, and continues. - - * symtab.c (find_pc_line): Zero "end" subsection of returned - symtab_and_line if no symtab found. - -Mon Dec 19 17:44:35 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * i386-pinsn.c (OP_REG): Added code from pace to streamline - disassembly and corrected types. - * i386-dep.c - (i386_follow_jump): Code added to follow byte and word offset - branches. - (i386_get_frame_setup): Expanded to deal with more wide ranging - function prologue. - (i386_frame_find_saved_regs, i386_skip_prologue): Changed to use - i386_get_frame_setup. - - -Sun Dec 18 11:15:03 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-sparc.h: Deleted definition of SUN4_COMPILER_BUG; was designed - to avoid something that I consider a bug in our code, not theirs, - and which I fixed earlier. Also deleted definition of - CANNOT_USE_ARBITRARY_FRAME; no longer used anywhere. - FRAME_SPECIFICATION_DYADIC used instead. - - * infrun.c (wait_for_inferior): On the sun 4, if a function - doesn't have a prologue, a next over it single steps into it. - This gets around the problem of a "call .stret4" at the end of - functions returning structures. - * m-sparc.h: Defined SUN4_COMPILER_FEATURE. - - * main.c (copying_info): Seperated the last printf into two - printfs. The 386 compiler will now handle it. - - * i386-pinsn.c, i386-dep.c: Moved print_387_control_word, - print_387_status_word, print_387_status, and i386_float_info to - dep.c Also included reg.h in dep.c. - -Sat Dec 17 15:31:38 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * main.c (source_command): Don't close instream if it's null - (indicating execution of a user-defined command). - (execute_command): Set instream to null before executing - commands and setup clean stuff to put it back on error. - - * inflow.c (terminal_inferior): Went back to not checking the - ioctl returns; there are some systems when this will simply fail. - It seems that, on most of these systems, nothing bad will happen - by that failure. - - * values.c (value_static_field): Fixed dereferencing of null - pointer. - - * i386-dep.c (i386_follow_jump): Modified to deal with - unconditional byte offsets also. - - * dbxread.c (read_type): Fixed typo in function type case of switch. - - * infcmd.c (run_command): Does not prompt to restart if command is - not from a tty. - -Fri Dec 16 15:21:58 1988 Randy Smith (randy at calvin) - - * gdb.texinfo: Added a third option under the "Cannot Insert - Breakpoints" workarounds. - - * printcmd.c (display_command): Don't do the display unless there - is an active inferior; only set it. - - * findvar.c (value_of_register): Added an error check for calling - this when the inferior isn't active and a core file isn't being - read. - - * config.gdb: Added reminder about modifying REGEX in the - makefile for the 386. - - * i386-pinsn.c, i386-dep.c: Moved m-i386.h helper functions over - to i386-dep.c.b - -Thu Dec 15 14:04:25 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * README: Added a couple of notes about compiling gdb with itself. - - * breakpoint.c (set_momentary_breakpoint): Only takes FRAME_FP of - frame if frame is non-zero. - - * printcmd.c (print_scalar_formatted): Implemented /g size for - hexadecimal format on machines without an 8 byte integer type. It - seems to be non-trivial to implement /g for other formats. - (decode_format): Allowed hexadecimal format to make it through /g - fileter. - -Wed Dec 14 13:27:04 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * expread.y: Converted all calls to write_exp_elt from the parser - to calls to one of write_exp_elt_{opcode, sym, longcst, dblcst, - char, type, intern}. Created all of these routines. This gets - around possible problems in passing one of these things in one ear - and getting something different out the other. Eliminated - SUN4_COMPILER_BUG ifdef's; they are now superfluous. - - * symmisc.c (free_all_psymtabs): Reinited partial_symtab_list to 0. - (_initialize_symmisc): Initialized both symtab_list and - partial_symtab_list. - - * dbxread.c (start_psymtab): Didn't allocate anything on - dependency list. - (end_psymtab): Allocate dependency list on psymbol obstack from - local list. - (add_psymtab_dependency): Deleted. - (read_dbx_symtab): Put dependency on local list if it isn't on it - already. - - * symtab.c: Added definition of psymbol_obstack. - * symtab.h: Added declaration of psymbol_obstack. - * symmisc.c (free_all_psymtabs): Added freeing and - reinitionaliztion of psymbol_obstack. - * dbxread.c (free_all_psymbols): Deleted. - (start_psymtab, end_psymtab, - process_symbol_for_psymtab): Changed most allocation - of partial symbol stuff to be off of psymbol_obstack. - - * symmisc.c (free_psymtab, free_all_psymtabs): Deleted - free_psymtab subroutine. - - * symtab.h: Removed num_includes and includes from partial_symtab - structure; no longer needed now that all include files have their - own psymtab. - * dbxread.c (start_psymtab): Eliminated initialization of above. - (end_psymtab): Eliminated finalization of above; get - includes from seperate list. - (read_dbx_symtab): Moved includes from psymtab list to - their own list; included in call to end_psymtab. - * symmisc.c (free_psymtab): Don't free includes. - -Tue Dec 13 14:48:14 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * i386-pinsn.c: Reformatted entire file to correspond to gnu - software indentation conventions. - - * sparc-dep.c (skip_prologue): Added capability of recognizign - stores of input register parameters into stack slots. - - * sparc-dep.c: Added an include of sparc-opcode.h. - * sparc-pinsn.c, sparc-opcode.h: Moved insn_fmt structures and - unions from pinsn.c to opcode.h. - * sparc-pinsn.c, sparc-dep.c (isabranch, skip_prologue): Moved - this function from pinsn.c to dep.c. - - * Makefile: Put in warnings about compiling with gcc (non-ansi - include files) and compiling with shared libs on Sunos 4.0 (can't - debug something that's been compiled that way). - - * sparc-pinsn.c: Put in a completely new file (provided by - Tiemann) to handle floating point disassembly, load and store - instructions, and etc. better. Made the modifications this file - (ChangeLog) list for sparc-pinsn.c again. - - * symtab.c (output_source_filename): Included "more" emulation hack. - - * symtab.c (output_source_filename): Initialized COLUMN to 0. - (sources_info): Modified to not print out a line for - all of the include files within a partial symtab (since - they have pst's of their own now). Also modified to - make a distinction between those pst's read in and - those not. - - * infrun.c: Included void declaration of single_step() if it's - going to be used. - * sparc-dep.c (single_step): Moved function previous to use of it. - - * Makefile: Took removal of expread.tab.c out of make clean entry - and put it into a new "squeakyclean" entry. - -Mon Dec 12 13:21:02 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * sparc-pinsn.c (skip_prologue): Changed a struct insn_fmt to a - union insn_fmt. - - * inflow.c (terminal_inferior): Checked *all* return codes from - ioctl's and fcntl's in routine. - - * inflow.c (terminal_inferior): Added check for sucess of - TIOCSPGRP ioctl call. Just notifies if bad. - - * dbxread.c (symbol_file_command): Close was getting called twice; - once directly and once through cleanup. Killed the direct call. - -Sun Dec 11 19:40:40 1988 & Smith (randy at hobbes.ai.mit.edu) - - * valprint.c (val_print): Deleted spurious printing of "=" from - TYPE_CODE_REF case. - -Sat Dec 10 16:41:07 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * dbxread.c: Changed allocation of psymbols from using malloc and - realloc to using obstacks. This means they aren't realloc'd out - from under the pointers to them. - -Fri Dec 9 10:33:24 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * sparc-dep.c inflow.c core.c expread.y command.c infrun.c - infcmd.c dbxread.c symmisc.c symtab.c printcmd.c valprint.c - values.c source.c stack.c findvar.c breakpoint.c blockframe.c - main.c: Various cleanups inspired by "gcc -Wall" (without checking - for implicit declarations). - - * Makefile: Cleaned up some more. - - * valops.c, m-*.h (FIX_CALL_DUMMY): Modified to take 5 arguments - as per what sparc needs (programming for a superset of needed - args). - - * dbxread.c (process_symbol_for_psymtab): Modified to be slightly - more picky about what it puts on the list of things *not* to be - put on the misc function list. When/if I shift everything over to - being placed on the misc_function_list, this will go away. - - * inferior.h, infrun.c: Added fields to save in inferior_status - structure. - - * maketarfile: Deleted; functionality is in Makefile now. - - * infrun.c (wait_for_inferior): Modified algorithm for determining - whether or not a single-step was through a subroutine call. See - comments at top of file. - - * dbxread.c (read_dbx_symtab): Made sure that the IGNORE_SYMBOL - macro would be checked during initial readin. - - * dbxread.c (read_ofile_symtab): Added macro GCC_COMPILED_FLAG_SYMBOL - into dbxread.c to indicate what string in a local text symbol will - indicate a file compiled with gcc. Defaults to "gcc_compiled.". - -Thu Dec 8 11:46:22 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-sparc.h (FRAME_FIND_SAVED_REGS): Cleaned up a little to take - advantage of the new frame cache system. - - * inferior.h, infrun.c, valops.c, valops.c, infcmd.c: Changed - mechanism to save inferior status over calls to inferior (eg. - call_function); implemented save_inferior_info and - restore_inferior_info. - - * blockframe.c (get_prev_frame): Simplified this by a direct call - to get_prev_frame_info. - - * frame.h, stack.c, printcmd.c, m-sparc.h, sparc-dep.c: Removed - all uses of frame_id_from_addr. There are short routines like it - still in frame_saved_pc (m-sparc.h) and parse_frame_spec - (stack.c). Eventually the one in frame_saved_pc will go away. - - * infcmd.c, sparc-dep.c: Implemented a new mechanism for - re-selecting the selected frame on return from a call. - - * blockframe.c, stack.c, findvar.c, printcmd.c, m-*.h: Changed - all routines and macros that took a "struct frame_info" as an - argument to take a "struct frame_info *". Routines: findarg, - framechain, print_frame_args, FRAME_ARGS_ADDRESS, - FRAME_STRUCT_ARGS_ADDRESS, FRAME_LOCALS_ADDRESS, FRAME_NUM_ARGS, - FRAME_FIND_SAVED_REGS. - - * frame.h, stack.c, printcmd.c, infcmd.c, findvar.c, breakpoint.c, - blockframe.c, xgdb.c, i386-pinsn.c, gld-pinsn.c, m-umax.h, - m-sun2.h, m-sun3.h, m-sparc.h, m-pn.h, m-npl.h, m-news.h, - m-merlin.h, m-isi.h, m-i386.h, m-hp9k320.h: Changed routines to - use "struct frame_info *" internally. - -Wed Dec 7 12:07:54 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * frame.h, blockframe.c, m-sparc.h, sparc-dep.c: Changed all calls - to get_[prev_]frame_cache_item to get_[prev_]frame_info. - - * blockframe.c: Elminated get_frame_cache_item and - get_prev_frame_cache_item; functionality now taken care of by - get_frame_info and get_prev_frame_info. - - * blockframe.c: Put allocation on an obstack and eliminated fancy - reallocation routines, several variables, and various nasty - things. - - * frame.h, stack.c, infrun.c, blockframe.c, sparc-dep.c: Changed - type FRAME to be a typedef to "struct frame_info *". Had to also - change routines that returned frame id's to return the pointer - instead of the cache index. - - * infcmd.c (finish_command): Used proper method of getting from - function symbol to start of function. Was treating a symbol as a - value. - - * blockframe.c, breakpoint.c, findvar.c, infcmd.c, stack.c, - xgdb.c, i386-pinsn.c, frame.h, m-hp9k320.h, m-i386.h, m-isi.h, - m-merlin.h, m-news.h, m-npl.h, m-pn.h, m-sparc.h, m-sun2.h, - m-sun3.h, m-umax.h: Changed get_frame_info and get_prev_frame_info - to return pointers instead of structures. - - * blockframe.c (get_pc_function_start): Modified to go to misc - function table instead of bombing if pc was in a block without a - containing function. - - * coffread.c: Dup'd descriptor passed to read_coff_symtab and - fdopen'd it so that there wouldn't be multiple closes on the same - fd. Also put (fclose, stream) on the cleanup list. - - * printcmd.c, stack.c: Changed print_frame_args to take a - frame_info struct as argument instead of the address of the args - to the frame. - - * m-i386.h (STORE_STRUCT_RETURN): Decremented sp by sizeof object - to store (an address) rather than 1. - - * dbxread.c (read_dbx_symtab): Set first_object_file_end in - read_dbx_symtab (oops). - - * coffread.c (fill_in_vptr_fieldno): Rewrote TYPE_BASECLASS as - necessary. - -Tue Dec 6 13:03:43 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * coffread.c: Added fake support for partial_symtabs to allow - compilation and execution without there use. - * inflow.c: Added a couple of minor USG mods. - * munch: Put in appropriate conditionals so that it would work on - USG systems. - * Makefile: Made regex.* handled same as obstack.*; made sure tar - file included everything I wanted it to include (including - malloc.c). - - * dbxread.c (end_psymtab): Create an entry in the - partial_symtab_list for each subfile of the .o file just read in. - This allows a "list expread.y:10" to work when we haven't read in - expread.o's symbol stuff yet. - - * symtab.h, dbxread.c (psymtab_to_symtab): Recognize pst->ldsymlen - == 0 as indicating a dummy psymtab, only in existence to cause the - dependency list to be read in. - - * dbxread.c (sort_symtab_syms): Elminated reversal of symbols to - make sure that register debug symbol decls always come before - parameter symbols. After mod below, this is not needed. - - * symtab.c (lookup_block_symbol): Take parameter type symbols - (LOC_ARG or LOC_REGPARM) after any other symbols which match. - - * dbxread.c (read_type): When defining a type in terms of some - other type and the other type is supposed to have a pointer back - to this specific kind of type (pointer, reference, or function), - check to see if *that* type has been created yet. If it has, use - it and fill in the appropriate slot with a pointer to it. - -Mon Dec 5 11:25:04 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * symmisc.c: Eliminated existence of free_inclink_symtabs and - init_free_inclink_symtabs; they aren't called from anywhere, and - if they were they could disrupt gdb's data structure badly - (elimination of struct type's which values that stick around past - elimination of inclink symtabs). - - * dbxread.c (symbol_file_command): Fixed a return pathway out of - the routine to do_cleanups before it left. - - * infcmd.c (set_environment_command), gdb.texinfo: Added - capability to set environmental variable values to null. - - * gdb.texinfo: Modified doc on "break" without args slightly. - -Sun Dec 4 17:03:16 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * dbxread.c (symbol_file_command): Added check; if there weren't - any debugging symbols in the file just read, the user is warned. - - * infcmd.c: Commented set_environment_command (a little). - - * createtags: Cleaned up and commented. - - * Makefile: Updated depen_memory and write_inferior_memory in that errno is - checked after each ptrace and returned to the caller. Used in - value_at to detect references to addresses which are out of - bounds. Also core.c (xfer_core_file): return 1 if invalid - address, 0 otherwise. - - * inflow.c, -infdep.c: removed all calls to ptrace from - inflo, m-sun3.h: Cleaned up dealings with - functions returning structu0 19:19:36 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * symmisc.c: (read_symsegs) Accept only format number 2. Since - the size of the type structure changed when C++ support was added, - format 1 can no longer be used. - - * core.c, m-sunos4.h: (core_file_command) support for SunOS 4.0. - Slight change in the core structure. #ifdef SUNOS4. New file - m-sunos4.h. May want to change config.gdb also. - -Fri Jul 8 19:59:49 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * breakpoint.c: (break_command_1) Allow `break if condition' - rather than parsing `if' as a function name and returning an - error. - -Thu Jul 7 22:22:47 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * C++: valops.c, valprint.c, value.h, values.c: merged code to deal - with C++ expressions. - -Wed Jul 6 03:28:18 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * C++: dbxread.c: (read_dbx_symtab, condense_misc_bunches, - add_file_command) Merged code to read symbol information from - an incrementally linked file. symmisc.c: - (init_free_inclink_symtabs, free_inclink_symtabs) Cleanup - routines. - -Tue Jul 5 02:50:41 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * C++: symtab.c, breakpoint.c, source.c: Merged code to deal with - ambiguous line specifications. In C++ one can have overloaded - function names, so that `list classname::overloadedfuncname' - refers to several different lines, possibly sure currently configured machine - dependent files come first in e at corn-chex.ai.mit.edu) - - * C++: symtab.c: replaced lookup_symtab_1 and lookup_symtab_2 with - a modified lookup_symbol which checks for fields of the current - implied argument `this'. printcmd.c, source.c, symtab.c, - valops.c: Need to change callers once callers are - installed. - -Wed Jun 29 01:26:56 1988 Peter TerMaat (pete at frosted-flakes.ai.mit.edu) - - * C++: eval.c, expprint.c, expread.y, expression.h, valarith.c, - Merged code to deal with evaluation of user-defined operators, - member functions, and virtual functions. - binop_must_be_user_defined tests for user-defined binops, - value_x_binop calls the appropriate operator function. - -Tue Jun 28 02:56:42 1988 Peter TerMaat (pete at frosted-flakes.ai.mit.edu) - - * C++: Makefile: changed the echo: expect 101 shift/reduce conflicts - and 1 reduce/reduce conflict. - - -Local Variables: -mode: indented-text -eval: (auto-fill-mode 1) -left-margin: 8 -fill-column: 74 -version-control: never -End: -ng destructors and - constructors, and flags being defined via public and via - virtual paths. Added fields NEXT_VARIANT, N_BASECLASSES, - and BASECLASSES to this type (tr: Changed types from - having to be derived from a single baseclass to a multiple - base class). - * symtab.h: Added macros to access new fields defined in symseg.h. - Added decl for lookup_basetype_type. - * dbxread.c - (condense_addl_misc_bunches): Function added to condense the misc - function bunches added by reading in a new .o file. - (read_addl_syms): Function added to read in symbols - from a new .o file (incremental linking). - (add_file_command): Command interface function to indicate - incrmental linking of a new .o file; this now calls - read_addl_syms and condense_addl_misc_bunches. - (define_symbol): Modified code to handle types defined from base - types which were not known when the derived class was - output. - (read_struct_type): Modified to better handle description of - struct types as derived types. Possibly derived from - several different base classes. Also added new code to - mark definitions via virtual paths or via public paths. - Killed seperate code to handle classes with destructors - but without constructors and improved marking of classes - as having destructors and constructors. - * infcmd.c: Modified call to val_print (one more argument). - * symtab.c (lookup_member_type): Modified to deal with new - structure in symseg.h. - (lookup_basetype_type): Function added to find or construct a type - ?derived? from the given type. - (decode_line_1): Modified to deal with new type data structures. - Modified to deal with new number of args for - decode_line_2. - (decode_line_2): Changed number of args (?why?). - (init_type): Added inits for new C++ fields from - symseg.h. - *valarith.c - (value_x_binop, value_binop): Added cases for BINOP_MIN & - BINOP_MAX. - * valops.c - (value_struct_elt, check_field, value_struct_elt_for_address): - Changed to deal with multiple possible baseclasses. - (value_of_this): Made SELECTED_FRAME an extern variable. - * valprint.c - (val_print): Added an argument DEREF_REF to dereference references - automatically, instead of printing them like pointers. - Changed number of arguments in recursive calls to itself. - Changed to deal with varibale numbers of base classes. - (value_print): Changed number of arguments to val_print. Print - type of value also if value is a reference. - (type_print_derivation_info): Added function to print out - derivation info a a type. - (type_print_base): Modified to use type_print_derivation_info and - to handle multiple baseclasses. - -Mon Nov 21 10:32:07 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * inflow.c (term_status_command): Add trailing newline to output. - - * sparc-dep.c (do_save_insn, do_restore_insn): Saved - "stop_registers" over the call for the sake of normal_stop and - run_stack_dummy. - - * m-sparc.h (EXTRACT_RETURN_VALUE): Put in parenthesis to force - addition of 8 to the int pointer, not the char pointer. - - * sparc-pinsn.c (print_addr1): Believe that I have gotten the - syntax right for loads and stores as adb does it. - - * symtab.c (list_symbols): Turned search for match on rexegp into - a single loop. - - * dbxread.c (psymtab_to_symtab): Don't read it in if it's already - been read in. - - * dbxread.c (psymtab_to_symtab): Changed error to fatal in - psymtab_to_symtab. - - * expread.y (parse_number): Fixed bug which treated 'l' at end of - number as '0'. - -Fri Nov 18 13:57:33 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * dbxread.c (read_dbx_symtab, process_symbol_for_psymtab): Was - being foolish and using pointers into an array I could realloc. - Converted these pointers into integers. - -Wed Nov 16 11:43:10 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-sparc.h (POP_FRAME): Made the new frame be PC_ADJUST of the - old frame. - - * i386-pinsn.c, m-hp9k320.h, m-isi.h, m-merlin.h, m-news.h, - m-npl.h, m-pn.h, m-sparc.h, m-sun2.h, m-sun3.h, m-umax.h, m-vax.h: - Modified POP_FRAME to use the current frame instead of - read_register (FP_REGNUM) and to flush_cached_frames before - setting the current frame. Also added a call to set the current - frame in those POP_FRAMEs that didn't have it. - - * infrun.c (wait_for_inferior): Moved call to set_current_frame up - to guarrantee that the current frame will always be set when a - POP_FRAME is done. - - * infrun.c (normal_stop): Added something to reset the pc of the - current frame (was incorrect because of DECR_PC_AFTER_BREAK). - - * valprint.c (val_print): Changed to check to see if a string was - out of bounds when being printed and to indicate this if so. - - * convex-dep.c (read_inferior_memory): Changed to return the value - of errno if the call failed (which will be 0 if the call - suceeded). - -Tue Nov 15 10:17:15 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * infrun.c (wait_for_inferior): Two changes: 1) Added code to - not trigger the step breakpoint on recursive calls to functions - without frame info, and 2) Added calls to distinguish recursive - calls within a function without a frame (which next/nexti might - wish to step over) from jumps to the beginning of a function - (which it generally doesn't). - - * m-sparc.h (INIT_EXTRA_FRAME_INFO): Bottom set correctly for leaf - parents. - - * blockframe.c (get_prev_frame_cache_item): Put in mod to check - for a leaf node (by presence or lack of function prologue). If - there is a leaf node, it is assumed that SAVED_PC_AFTER_CALL is - valid. Otherwise, FRAME_SAVED_PC or read_pc is used. - - * blockframe.c, frame.h: Did final deletion of unused routines and - commented problems with getting a pointer into the frame cache in - the frame_info structure comment. - - * blockframe.c, frame.h, stack.c: Killed use of - frame_id_from_frame_info; used frame_id_from_addr instead. - - * blockframe.c, frame.h, stack.c, others (oops): Combined stack - cache and frame info structures. - - * blockframe.c, sparc-dep.c, stack.c: Created the function - create_new_frame and used it in place of bad calls to - frame_id_from_addr. - - * blockframe.c, inflow.c, infrun.c, i386-pinsn.c, m-hp9k320.h, - m-npl.h, m-pn.h, m-sparc.h, m-sun3.h, m-vax.h, default-dep.c, - convex-dep.c, gould-dep.c, hp9k320-dep.c, news-dep.c, sparc-dep.c, - sun3-dep.c, umax-dep.c: Killed use of - set_current_Frame_by_address. Used set_current_frame - (create_new_frame...) instead. - - * frame.h: Killed use of FRAME_FP_ID. - - * infrun.c, blockframe.c: Killed select_frame_by_address. Used - select_frame (get_current_frame (), 0) (which was correct in all - cases that we need to worry about. - -Mon Nov 14 14:19:32 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * frame.h, blockframe.c, stack.c, m-sparc.h, sparc-dep.c: Added - mechanisms to deal with possible specification of frames - dyadically. - -Sun Nov 13 16:03:32 1988 Richard Stallman (rms at sugar-bombs.ai.mit.edu) - - * ns32k-opcode.h: Add insns acbw, acbd. - -Sun Nov 13 15:09:58 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * breakpoint.c: Changed breakpoint structure to use the address of - a given frame (constant across inferior runs) as the criteria for - stopping instead of the frame ident (which varies across inferior - calls). - -Fri Nov 11 13:00:22 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * gld-pinsn.c (findframe): Modified to work with the new frame - id's. Actually, it looks as if this routine should be called with - an address anyway. - - * findvar.c (find_saved_register): Altered bactrace loop to work - off of frames and not frame infos. - - * frame.h, blockframe.c, stack.c, sparc-dep.c, m-sparc.h: Changed - FRAME from being the address of the frame to being a simple ident - which is an index into the frame_cache_item list. - * convex-dep.c, default-dep.c, gould-dep.c, hp9k320-dep.c, - i386-pinsn.c, inflow.c, infrun.c, news-dep.c, sparc-dep.c, - sun3-dep.c, umax-dep.c, m-hp9k320.h, m-npl.h, m-pn.h, m-sparc.h, - m-sun3.h, m-vax.h: Changed calls of the form set_current_frame - (read_register (FP_REGNUM)) to set_current_frame_by_address (...). - -Thu Nov 10 16:57:57 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * frame.h, blockframe.c, gld-pinsn.c, sparc-dep.c, stack.c, - infrun.c, findvar.c, m-sparc.h: Changed the FRAME type to be - purely an identifier, using FRAME_FP and FRAME_FP_ID to convert - back and forth between the two. The identifier is *currently* - still the frame pointer value for that frame. - -Wed Nov 9 17:28:14 1988 Chris Hanson (cph at kleph) - - * m-hp9k320.h (FP_REGISTER_ADDR): Redefine this to return - difference between address of given FP register, and beginning of - `struct user' that it occurs in. - - * hp9k320-dep.c (core_file_command): Fix sign error in size - argument to myread. Change buffer argument to pointer; was - copying entire structure. - (fetch_inferior_registers, store_inferior_registers): Replace - occurrences of `FP_REGISTER_ADDR_DIFF' with `FP_REGISTER_ADDR'. - Flush former definition. - -Wed Nov 9 12:11:37 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * xgdb.c: Killed include of initialize.h. - - * Pulled in xgdb.c from the net. - - * Checkpointed distribution (to provide to 3b2 guy). - - * coffread.c, dbxread.c, symmisc.c, symtab.c, symseg.h: Changed - format of table of line number--pc mapping information. Can - handle negative pc's now. - - * command.c: Deleted local copy of savestring; code in utils.c is - identical. - -Tue Nov 8 11:12:16 1988 Randall Smith (randy at plantaris.ai.mit.edu) - - * gdb.texinfo: Added documentation for shell escape. - -Mon Nov 7 12:27:16 1988 Randall Smith (randy at sugar-bombs.ai.mit.edu) - - * command.c: Added commands for shell escape. - - * core.c, dbxread.c: Added ROBOTUSSIN mods. - - * Checkpointed distribution. - - * printcmd.c (x_command): Yanked error if there is no memory to - examine (could be looking at executable straight). - - * sparc-pinsn.c (print_insn): Amount to leftshift sethi imm by is - now 10 (matches adb in output). - - * printcmd.c (x_command): Don't attempt to set $_ & $__ if there - is no last_examine_value (can happen if you did an x/0). - -Fri Nov 4 13:44:49 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * printcmd.c (x_command): Error if there is no memory to examine. - - * gdb.texinfo: Added "cont" to the command index. - - * sparc-dep.c (do_save_insn): Fixed typo in shift amount. - - * m68k-opcode.h: Fixed opcodes for 68881. - - * breakpoint.c, infcmd.c, source.c: Changed defaults in several - places for decode_line_1 to work off of the default_breakpoint_* - values instead of current_source_* values (the current_source_* - values are off by 5 or so because of listing defaults). - - * stack.c (frame_info): ifdef'd out FRAME_SPECIFCATION_DYADIC in - the stack.c module. If I can't do this right, I don't want to do - it at all. Read the comment there for more info. - -Mon Oct 31 16:23:06 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * gdb.texinfo: Added documentation on the "until" command. - -Sat Oct 29 17:47:10 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * breakpoint.c, infcmd.c: Added UNTIL_COMMAND and subroutines of - it. - - * breakpoint.c, infcmd.c, infrun.c: Added new field to breakpoint - structure (silent, indicating a silent breakpoint), and modified - breakpoint_stop_status and things that read it's return value to - understand it. - -Fri Oct 28 17:45:33 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * dbxread.c, symmisc.c: Assorted speedups for readin, including - special casing most common symbols, and doing buffering instead of - calling malloc. - -Thu Oct 27 11:11:15 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * stack.c, sparc-dep.c, m-sparc.h: Modified to allow "info frame" - to take two arguments on the sparc and do the right thing with - them. - - * dbxread.c (read_dbx_symtab, process_symbol_for_psymtab): Put - stuff to put only symbols that didn't have debugging info on the - misc functions list back in. - -Wed Oct 26 10:10:32 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * valprint.c (type_print_varspec_suffix): Added check for - TYPE_LENGTH(TYPE_TARGET_TYPE(type)) > 0 to prevent divide by 0. - - * printcmd.c (print_formatted): Added check for VALUE_REPEATED; - value_print needs to be called for that. - - * infrun.c (wait_for_inferior): Added break when you decide to - stop on a null function prologue rather than continue stepping. - - * m-sun3.h: Added explanatory comment to REGISTER_RAW_SIZE. - - * expread.y (parse_c_1): Initialized paren_depth for each parse. - -Tue Oct 25 14:19:38 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * valprint.c, coffread.c, dbxread.c: Enum constant values in enum - type now accessed through TYPE_FIELD_BITPOS. - - * dbxread.c (process_symbol_for_psymtab): Added code to deal with - possible lack of a ":" in a debugging symbol (do nothing). - - * symtab.c (decode_line_1): Added check in case of all numbers for - complete lack of symbols. - - * source.c (select_source_symtab): Made sure that this wouldn't - bomb on complete lack of symbols. - -Mon Oct 24 12:28:29 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-sparc.h, findvar.c: Ditched REGISTER_SAVED_UNIQUELY and based - code on REGISTER_IN_WINDOW_P and HAVE_REGISTER_WINDOWS. This will - break when we find a register window machine which saves the - window registers within the context of an inferior frame. - - * sparc-dep.c (frame_saved_pc): Put PC_ADJUST return back in for - frame_saved_pc. Seems correct. - - * findvar.c, m-sparc.h: Created the macro REGISTER_SAVED_UNIQUELY - to handle register window issues (ie. that find_saved_register - wasn't checking the selected frame itself for shit). - - * sparc-dep.c (core_file_command): Offset target of o & g register - bcopy by 1 to hit correct registers. - - * m-sparc.h: Changed STACK_END_ADDR. - -Sun Oct 23 19:41:51 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * sparc-dep.c (core_file_command): Added in code to get the i & l - registers from the stack in the corefile, and blew away some wrong - code to get i & l from inferior. - -Fri Oct 21 15:09:19 1988 Randall Smith (randy at apple-gunkies.ai.mit.edu) - - * m-sparc.h (PUSH_DUMMY_FRAME): Saved the value of the RP register - in the location reserved for i7 (in the created frame); this way - the rp value won't get lost. The pc (what we put into the rp in - this routine) gets saved seperately, so we loose no information. - - * sparc-dep.c (do_save_insn & do_restore_insn): Added a wrapper to - preserve the proceed status state variables around each call to - proceed (the current frame was getting munged because this wasn't - being done). - - * m-sparc.h (FRAME_FIND_SAVED_REGS): Fix bug: saved registers - addresses were being computed using absolute registers number, - rather than numbers relative to each group of regs. - - * m-sparc.h (POP_FRAME): Fixed a bug (I hope) in the context - within which saved reg numbers were being interpetted. The - values to be restored were being gotten in the inferior frame, and - the restoring was done in the superior frame. This means that i - registers must be restored into o registers. - - * sparc-dep.c (do_restore_insn): Modified to take a pc as an - argument, instead of a raw_buffer. This matches (at least it - appears to match) usage from POP_FRAME, which is the only place - from which do_restore_insn is called. - - * sparc-dep.c (do_save_insn and do_restore_insn): Added comments. - - * m-sparc.h (FRAME_FIND_SAVED_REGS): Modified my code to find the - save addresses of out registers to use the in regs off the stack - pointer when the current frame is 1 from the innermost. - -Thu Oct 20 13:56:15 1988 & Smith (randy at hobbes.ai.mit.edu) - - * blockframe.c, m-sparc.h: Removed code associated with - GET_PREV_FRAME_FROM_CACHE_ITEM. This code was not needed for the - sparc; you can always find the previous frames fp from the fp of - the current frame (which is the sp of the previous). It's getting - the information associated with a given frame (ie. saved - registers) that's a bitch, because that stuff is saved relative to - the stack pointer rather than the frame pointer. - - * m-sparc.h (GET_PREV_FRAME_FROM_CACHE_ITEM): Modified to return - the frame pointer of the previous frame instead of the stack - pointer of same. - - * blockframe.c (flush_cached_frames): Modified call to - obstack_free to free back to frame_cache instead of back to zero. - This leaves the obstack control structure in finite state (and - still frees the entry allocated at frame_cache). - -Sat Oct 15 16:30:47 1988 & Smith (randy at tartarus.uchicago.edu) - - * valops.c (call_function): Suicide material here. Fixed a typo; - CALL_DUMMY_STACK_ADJUST was spelled CAll_DUMMY_STACK_ADJUST on - line 530 of the file. This cost me three days. I'm giving up - typing for lent. - -Fri Oct 14 15:10:43 1988 & Smith (randy at tartarus.uchicago.edu) - - * m-sparc.h: Corrected a minor mistake in the dummy frame code - that was getting the 5th argument and the first argument from the - same place. - -Tue Oct 11 11:49:33 1988 & Smith (randy at tartarus.uchicago.edu) - - * infrun.c: Made stop_after_trap and stop_after_attach extern - instead of static so that code which used proceed from machine - dependent files could fiddle with them. - - * blockframe.c, frame.h, sparc-dep.c, m-sparc.h: Changed sense of - ->prev and ->next in struct frame_cache_item to fit usage in rest - of gdb (oops). - -Mon Oct 10 15:32:42 1988 Randy Smith (randy at gargoyle.uchicago.edu) - - * m-sparc.h, sparc-dep.c, blockframe.c, frame.h: Wrote - get_frame_cache_item. Modified FRAME_SAVED_PC and frame_saved_pc - to take only one argument and do the correct thing with it. Added - the two macros I recently defined in blockframe.c to m-sparc.h. - Have yet to compile this thing on a sparc, but I've now merged in - everything that I received from tiemann, either exactly, or simply - effectively. - - * source.c: Added code to allocated space to sals.sals in the case - where no line was specified. - - * blockframe.c, infrun.c: Modified to cache stack frames requested - to minimize accesses to subprocess. - -Tue Oct 4 15:10:39 1988 Randall Smith (randy at cream-of-wheat.ai.mit.edu) - - * config.gdb: Added sparc. - -Mon Oct 3 23:01:22 1988 Randall Smith (randy at cream-of-wheat.ai.mit.edu) - - * Makefile, blockframe.c, command.c, core.c, dbxread.c, defs.h, - expread.y, findvar.c, infcmd.c, inflow.c, infrun.c, sparc-pinsn.c, - m-sparc.h, sparc-def.c, printcmd.c, stack.c, symmisc.c, symseg.h, - valops.c, values.c: Did initial merge of sparc port. This will - not compile; have to do stack frame caching and finish port. - - * inflow.c, gdb.texinfo: `tty' now resets the controling terminal. - -Fri Sep 30 11:31:16 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * inferior.h, infcmd.c, infrun.c: Changed the variable - stop_random_signal to stopped_by_random signal to fit in better - with name conventions (variable is not a direction to the - proceed/resume set; it is information from it). - -Thu Sep 29 13:30:46 1988 Randall Smith (randy at cream-of-wheat.ai.mit.edu) - - * infcmd.c (finish_command): Value type of return value is now - whatever the function returns, not the type of the function (fixed - a bug in printing said value). - - * dbxread.c (read_dbx_symtab, process_symbol_for_psymtab): - Put *all* global symbols into misc_functions. This is what was - happening anyway, and we need it for find_pc_misc_function. - - ** This was eventually taken out, but I didn't mark it in the - ChangeLog. Oops. - - * dbxread.c (process_symbol_for_psymtab): Put every debugger - symbol which survives the top case except for constants on the - symchain. This means that all of these *won't* show up in misc - functions (this will be fixed once I make sure it's broken the way - it's supposed to be). - - * dbxread.c: Modified placement of debugger globals onto the hash - list; now we exclude the stuff after the colon and don't skip the - first character (debugger symbols don't have underscores). - - * dbxread.c: Killed debuginfo stuff with ifdef's. - -Wed Sep 28 14:31:51 1988 Randall Smith (randy at cream-of-wheat.ai.mit.edu) - - * symtab.h, dbxread.c: Modified to deal with BINCL, EINCL, and - EXCL symbols produced by the sun loader by adding a list of - pre-requisite partial_symtabs that each partial symtab needs. - - * symtab.h, dbxread.c, symtab.c, symmisc.c: Modified to avoid - doing a qsort on the local (static) psymbols for each file to - speed startup. This feature is not completely debugged, but it's - inclusion has forced the inclusion of another feature (dealing - with EINCL's, BINCL's and EXCL's) and so I'm going to go in and - deal with them. - - * dbxread.c (process_symbol_for_psymtab): Made sure that the class - of the symbol made it into the partial_symbol entry. - -Tue Sep 27 15:10:26 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * dbxread.c: Fixed bug; init_psymbol_list was not being called - with the right number of arguments (1). - - * dbxread.c: Put ifdef's around N_MAIN, N_M2C, and N_SCOPE to - allow compilation on a microvax. - - * config.gdb: Modified so that "config.gdb vax" would work. - - * dbxread.c, symtab.h, symmisc.h, symtab.c, source.c: Put in many - and varied hacks to speed up gdb startup including: A complete - rewrite of read_dbx_symtab, a modification of the partial_symtab - data type, deletion of select_source_symtab from - symbol_file_command, and optimiztion of the call to strcmp in - compare_psymbols. - -Thu Sep 22 11:08:54 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * dbxread.c (psymtab_to_symtab): Removed call to - init_misc_functions. - - * dbxread.c: Fixed enumeration type clash (used enum instead of - integer constant). - - * breakpoint.c: Fixed typo; lack of \ at end of line in middle of - string constant. - - * symseg.h: Fixed typo; lack of semicolon after structure - definition. - - * command.c, breakpoint.c, printcmd.c: Added cmdlist editing - functions to add commands with the abbrev flag set. Changed - help_cmd_list to recognize this flag and modified unset, - undisplay, and enable, disable, and delete breakpoints to have - this flag set. - -Wed Sep 21 13:34:19 1988 Randall Smith (randy at plantaris.ai.mit.edu) - - * breakpoint.c, infcmd.c, gdb.texinfo: Created "unset" as an alias - for delete, and changed "unset-environment" to be the - "environment" subcommand of "delete". - - * gdb.texinfo, valprint.c: Added documentation in the manual for - breaking the set-* commands into subcommands of set. Changed "set - maximum" to "set array-max". - - * main.c, printcmd.c, breakpoint.c: Moved the declaration of - command lists into main and setup a function in main initializing - them to guarrantee that they would be initialized before calling - any of the individual files initialize routines. - - * command.c (lookup_cmd): A null string subcommand is treated as - an unknown subcommand rather than an ambiguous one (eg. "set $x = - 1" will now work). - - * infrun.c (wait_for_inferior): Put in ifdef for Sony News in - check for trap by INNER_THAN macro. - - * eval.c (evaluate_subexp): Put in catch to keep the user from - attempting to call a non function as a function. - -Tue Sep 20 10:35:53 1988 Randall Smith (randy at oatmeal.ai.mit.edu) - - * dbxread.c (read_dbx_symtab): Installed code to keep track of - which global symbols did not have debugger symbols refering to - them, and recording these via record_misc_function. - - * dbxread.c: Killed code to check for extra global symbols in the - debugger symbol table. - - * printcmd.c, breakpoint.c: Modified help entries for several - commands to make sure that abbreviations were clearly marked and - that the right commands showed up in the help listings. - - * main.c, command.c, breakpoint.c, infcmd.c, printcmd.c, - valprint.c, defs.h: Modified help system to allow help on a class - name to show subcommands as well as commands and help on a command - to show *all* subcommands of that command. - -Fri Sep 16 16:51:19 1988 Randall Smith (randy at gluteus.ai.mit.edu) - - * breakpoint.c (_initialize_breakpoint): Made "breakpoints" - subcommands of enable, disable, and delete use class 0 (ie. they - show up when you do a help xxx now). - - * infcmd.c,printcmd,c,main.c,valprint.c: Changed the set-* - commands into subcommands of set. Created "set variable" for use - with variables whose names might conflict with other subcommands. - - * blockframe.c, dbxread.c, coffread.c, expread.y, source.c: - Fixed mostly minor (and one major one in block_for_pc) bugs - involving checking the partial_symtab_list when a scan through the - symtab_list fails. - -Wed Sep 14 12:02:05 1988 Randall Smith (randy at sugar-smacks.ai.mit.edu) - - * breakpoint.c, gdb.texinfo: Added enable breakpoints, disable - breakpoints and delete breakpoints as synonyms for enable, - disable, and delete. This seemed reasonable because of the - immeninent arrival of watchpoints & etc. - - * gdb.texinfo: Added enable display, disable display, and delete - display to manual. - -Tue Sep 13 16:53:56 1988 Randall Smith (randy at sugar-smacks.ai.mit.edu) - - * inferior.h, infrun.c, infcmd.c: Added variable - stop_random_signal to indicate when a proceed had been stopped by - an unexpected signal. Used this to determine (in normal_stop) - whether the current display point should be deleted. - - * valops.c: Fix to value_ind to check for reference before doing a - COERCE_ARRAY. - -Sun Jul 31 11:42:36 1988 Richard Stallman (rms at frosted-flakes.ai.mit.edu) - - * breakpoint.c (_initialize_breakpoint): Clean up doc for commands - that can now apply also to auto-displays. - - * coffread.c (record_line): Corrected a spazz in editing. - Also removed the two lines that assume line-numbers appear - only in increasing order. - -Tue Jul 26 22:19:06 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * expression.h, eval.c, expprint.c, printcmd.c, valarith.c, - valops.c, valprint.c, values.c, m-*.h: Changes for evaluating and - displaying 64-bit `long long' integers. Each machine must define - a LONGEST type, and a BUILTIN_TYPE_LONGEST. - - * symmisc.c: (print_symtab) check the status of the fopen and call - perror_with_name if needed. - -Thu Jul 21 00:56:11 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * Convex: core.c: changes required by Convex's SOFF format were - isolated in convex-dep.c. - -Wed Jul 20 21:26:10 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * coffread.c, core.c, expread.y, i386-pinsn.c, infcmd.c, inflow.c, - infrun.c, m-i386.h, main.c, remote.c, source.c, valops.c: - Improvements for the handling of the i386 and other machines - running USG. (Several of these files just needed extra header files - such as types.h.) utils.c: added bcopy, bcmp, bzero, getwd, list - of signals, and queue routines for USG systems. Added vfork macro - to i386 - - * printcmd.c, breakpoint.c: New commands to enable/disable - auto-displays. Also `delete display displaynumber' works like - `undisplay displaynumber'. - -Tue Jul 19 02:17:18 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * coffread.c: (coff_lookup_type) Wrong portion of type_vector was - being bzero'd after type_vector was reallocated. - - * printcmd.c: (delete_display) Check for a display chain before - attempting to delete a display. - - * core.c, *-dep.c (*-infdep moved to *-dep): machine-dependent - parts of core.c (core_file_command, exec_file_command) moved to - *-dep.c. - -Mon Jul 18 19:45:51 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * dbxread.c: typo in read_struct_type (missing '=') was causing a - C struct to be parsed as a C++ struct, resulting in a `invalid - character' message. - -Sun Jul 17 22:27:32 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * printcmd.c, symtab.c, valops.c, expread.y: When an expression is - read, the innermost block required to evaluate the expression is - saved in the global variable `innermost_block'. This information - is saved in the `block' field of an auto-display so that - expressions with inactive variables can be skipped. `info display' - tells the user which displays are active and which are not. New - fn `contained_in' returns nonzero if one block is contained within - another. - -Fri Jul 15 01:53:14 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * infrun.c, m-i386.h: Use macro TRAPS_EXPECTED to set number of - traps to skip when sh execs the program. Default is 2, m-i386.h - overrides this and sets to 4. - - * coffread.c, infrun.c: minor changes for the i386. May be able - to eliminate them with more general code. - - * default-infdep.c: #ifdef SYSTEMV, include header file types.h. - Also switched the order of signal.h and user.h, since System 5 - requires signal.h to come first. - - * core.c main.c, remote,c, source.c, inflow.c: #ifdef SYSTEMV, - include various header files. Usually types.h and fcntl.h. - - * utils.c: added queue routines needed by the i386 (and other sys - 5 machines). - - * sys5.c, regex.c, regex.h: new files for sys 5 systems. (The - regex files are simply links to /gp/gnu/lib.) - -Thu Jul 14 01:47:14 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * config.gdb, README: Provide a list of known machines when user - enters an invalid machine. New second arg is operating system, - currently only used with `sunos4' or `os4'. Entry for i386 added. - - * news-infdep.c: new file. - - * m-news.h: new version which deals with new bugs in news800's OS. - -Tue Jul 12 19:52:16 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * Makefile, *.c, munch, config.gdb, README: New initialization - scheme uses nm to find functions whose names begin with - `_initialize_'. Files `initialize.h', `firstfile.c', - `lastfile.c', `m-*init.h' no longer needed. - - * eval.c, symtab.c, valarith.c, valops.c, value.h, values.c: Bug - fixes from gdb+ 2.5.4. evaluate_subexp takes a new arg, type - expected. New fn value_virtual_fn_field. - -Mon Jul 11 00:48:49 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * core.c (read_memory): xfer_core_file was being called with an - extra argument (0) by read_memory. - - * core.c (read_memory), *-infdep.c (read_inferior_memory), - valops.c (value_at): read_memory and read_inferior_memory now work - like write_memory and write_inferior_memory in that errno is - checked after each ptrace and returned to the caller. Used in - value_at to detect references to addresses which are out of - bounds. Also core.c (xfer_core_file): return 1 if invalid - address, 0 otherwise. - - * inflow.c, -infdep.c: removed all calls to ptrace from - inflow.c and put them in machine-dependent files *-infdep.c. - -Sun Jul 10 19:19:36 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * symmisc.c: (read_symsegs) Accept only format number 2. Since - the size of the type structure changed when C++ support was added, - format 1 can no longer be used. - - * core.c, m-sunos4.h: (core_file_command) support for SunOS 4.0. - Slight change in the core structure. #ifdef SUNOS4. New file - m-sunos4.h. May want to change config.gdb also. - -Fri Jul 8 19:59:49 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * breakpoint.c: (break_command_1) Allow `break if condition' - rather than parsing `if' as a function name and returning an - error. - -Thu Jul 7 22:22:47 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * C++: valops.c, valprint.c, value.h, values.c: merged code to deal - with C++ expressions. - -Wed Jul 6 03:28:18 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * C++: dbxread.c: (read_dbx_symtab, condense_misc_bunches, - add_file_command) Merged code to read symbol information from - an incrementally linked file. symmisc.c: - (init_free_inclink_symtabs, free_inclink_symtabs) Cleanup - routines. - -Tue Jul 5 02:50:41 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * C++: symtab.c, breakpoint.c, source.c: Merged code to deal with - ambiguous line specifications. In C++ one can have overloaded - function names, so that `list classname::overloadedfuncname' - refers to several different lines, possibly in different files. - -Fri Jul 1 02:44:20 1988 Peter TerMaat (pete at corn-chex.ai.mit.edu) - - * C++: symtab.c: replaced lookup_symtab_1 and lookup_symtab_2 with - a modified lookup_symbol which checks for fields of the current - implied argument `this'. printcmd.c, source.c, symtab.c, - valops.c: Need to change callers once callers are - installed. - -Wed Jun 29 01:26:56 1988 Peter TerMaat (pete at frosted-flakes.ai.mit.edu) - - * C++: eval.c, expprint.c, expread.y, expression.h, valarith.c, - Merged code to deal with evaluation of user-defined operators, - member functions, and virtual functions. - binop_must_be_user_defined tests for user-defined binops, - value_x_binop calls the appropriate operator function. - -Tue Jun 28 02:56:42 1988 Peter TerMaat (pete at frosted-flakes.ai.mit.edu) - - * C++: Makefile: changed the echo: expect 101 shift/reduce conflicts - and 1 reduce/reduce conflict. - -Local Variables: -mode: indented-text -left-margin: 8 -fill-column: 74 -version-control: never -End: diff --git a/gnu/usr.bin/gdb/Gdbinit b/gnu/usr.bin/gdb/Gdbinit deleted file mode 100644 index bcacd5d..0000000 --- a/gnu/usr.bin/gdb/Gdbinit +++ /dev/null @@ -1,15 +0,0 @@ -echo Setting up the environment for debugging gdb.\n - -b fatal - -b info_command -commands - silent - return -end - -define rr - run -end - -set prompt (top-gdb) diff --git a/gnu/usr.bin/gdb/Makefile.dist b/gnu/usr.bin/gdb/Makefile.dist deleted file mode 100644 index 3cbc91f..0000000 --- a/gnu/usr.bin/gdb/Makefile.dist +++ /dev/null @@ -1,371 +0,0 @@ -/* This file should be run through the C preprocessor by config.gdb - to produce the Makefile. */ - -/* Define this to xgdb if you want to compile xgdb as well as gdb. */ -XGDB= -/* Place to install binaries. */ -bindir=/usr/local/bin -/* Place to install X binaries. */ -xbindir=$(bindir) - -/* System V: If you compile gdb with a compiler which uses the coff - encapsulation feature (this is a function of the compiler used, NOT - of the m-?.h file selected by config.gdb), you must make sure that - the GNU nm is the one that is used by munch. */ - -/* If you are compiling with GCC, make sure that either 1) You use the - -traditional flag, or 2) You have the fixed include files where GCC - can reach them. Otherwise the ioctl calls in inflow.c and readline.c - will be incorrectly compiled. The "fixincludes" script in the gcc - distribution will fix your include files up. */ -/* CC=gcc -traditional */ -CC=cc - -/* It is also possible that you will need to add -I/usr/include/sys to the - CFLAGS section if your system doesn't have fcntl.h in /usr/include (which - is where it should be according to Posix). */ - -YACC=bison -y -v -/* YACC=yacc */ -SHELL=/bin/sh -MAKE=make - -/* Set this up with gcc if you have gnu ld and the loader will print out - line numbers for undefinded refs. */ -/* CC-LD=gcc -static */ -CC-LD=${CC} - -/* If you are using the GNU C library, uncomment the following line. */ -/* HAVE_VPRINTF_DEFINE = -DHAVE_VPRINTF */ - -/* -I. for "#include ". Possibly regex.h also. */ - -/* M_CFLAGS, if defined, has system-dependent CFLAGS. */ -#if !defined(M_CFLAGS) -#define M_CFLAGS -#endif - -/* CFLAGS for both GDB and readline. */ -GLOBAL_CFLAGS = -g M_CFLAGS -CFLAGS = -I. ${HAVE_VPRINTF_DEFINE} ${GLOBAL_CFLAGS} -/* None of the things in CFLAGS will do any harm, and on some systems - (e.g. SunOS4) it is important to use the M_CFLAGS. */ -LDFLAGS = $(CFLAGS) - -/* - define this to be "obstack.o" if you don't have the obstack library installed - you must at the same time define OBSTACK1 as "obstack.o" - so that the dependencies work right. Similarly with REGEX and "regex.o". - You must define REGEX and REGEX1 on USG machines. - If your sysyem is missing alloca(), or, more likely, it's there but - it doesn't work, define ALLOCA & ALLOCA1 */ -OBSTACK = obstack.o -OBSTACK1 = obstack.o - -#ifdef M_REGEX -REGEX = M_REGEX -REGEX1 = M_REGEX -#else -REGEX = -REGEX1 = -#endif - -#ifdef M_ALLOCA -ALLOCA = M_ALLOCA -ALLOCA1 = M_ALLOCA -#else -ALLOCA = -ALLOCA1 = -#endif - -/* - define this to be "malloc.o" if you want to use the gnu malloc routine - (useful for debugging memory allocation problems in gdb). Otherwise, leave - it blank. */ -/* GNU_MALLOC = */ -GNU_MALLOC = malloc.o - -/* Flags to be used in compiling malloc.o - Specify range checking for storage allocation. */ -/* MALLOC_FLAGS = ${CFLAGS} */ -MALLOC_FLAGS = ${CFLAGS} -Drcheck -Dbotch=fatal_dump_core -DMSTATS - -/* Define SYSV if compiling on a system V or HP machine. */ -#ifdef M_SYSV -SYSV_DEFINE = -DSYSV -#else -SYSV_DEFINE = -#endif - -/* MUNCH_DEFINE should be -DSYSV if have System V-style nm, - or null if have BSD-style nm. */ -#ifdef M_BSD_NM -MUNCH_DEFINE = -#else -MUNCH_DEFINE = ${SYSV_DEFINE} -#endif - -/* Flags that describe where you can find the termcap library. - You may need to make other arrangements for USG. */ -TERMCAP = -ltermcap - -/* M_CLIBS, if defined, has system-dependent libs - For example, -lPW for System V to get alloca(). */ -#ifndef M_CLIBS -#define M_CLIBS -#endif -CLIBS = ${ADD_FILES} ${TERMCAP} M_CLIBS - -ADD_FILES = ${OBSTACK} ${REGEX} ${ALLOCA} ${GNU_MALLOC} -ADD_DEPS = ${OBSTACK1} ${REGEX1} ${ALLOCA1} ${GNU_MALLOC} - -SFILES = blockframe.c breakpoint.c dbxread.c coffread.c command.c core.c \ - environ.c eval.c expprint.c findvar.c infcmd.c inflow.c infrun.c \ - kdb-start.c main.c printcmd.c \ - remote.c source.c stack.c standalone.c stuff.c symmisc.c symtab.c \ - utils.c valarith.c valops.c valprint.c values.c version.c expread.y \ - xgdb.c - -DEPFILES = umax-dep.c gould-dep.c default-dep.c sun3-dep.c \ - sparc-dep.c hp9k320-dep.c hp300bsd-dep.c news-dep.c i386-dep.c \ - symmetry-dep.c convex-dep.c altos-dep.c isi-dep.c pyr-dep.c - -PINSNS = gld-pinsn.c i386-pinsn.c sparc-pinsn.c vax-pinsn.c m68k-pinsn.c \ - ns32k-pinsn.c convex-pinsn.c pyr-pinsn.c - -HFILES = command.h defs.h environ.h expression.h frame.h getpagesize.h \ - inferior.h symseg.h symtab.h value.h wait.h \ - a.out.encap.h a.out.gnu.h stab.gnu.h - -OPCODES = m68k-opcode.h pn-opcode.h sparc-opcode.h npl-opcode.h vax-opcode.h \ - ns32k-opcode.h convex-opcode.h pyr-opcode.h - -MFILES = m-hp9k320.h m-hp300bsd.h m-i386.h m-i386gas.h \ - m-i386-sv32.h m-i386g-sv32.h m-isi.h m-merlin.h \ - m-altos.h m-news.h m-newsos3.h m-npl.h m-pn.h \ - m-sparc.h m-sun2.h m-sun3.h m-sun2os4.h \ - m-sun3os4.h m-sun4os4.h m-umax.h m-vax.h m-symmetry.h m-convex.h \ - m-pyr.h - -/* This list of files really shouldn't be in this makefile, but I can't think - of any good way to get the readline makefile to tell us what files - to put in our tarfile. */ -READLINE = readline.c history.c funmap.c \ - emacs_keymap.c vi_keymap.c vi_mode.c keymaps.c \ - readline.h history.h keymaps.h chardefs.h \ - inc-readline.texinfo inc-history.texinfo \ - readline.texinfo history.texinfo \ - Makefile ChangeLog - -REMOTE_EXAMPLES = remote-sa.m68k.shar remote-multi.shar - -POSSLIBS = obstack.h obstack.c regex.c regex.h malloc.c alloca.c - -TESTS = testbpt.c testfun.c testrec.c testreg.c testregs.c - -OTHERS = Makefile.dist createtags munch config.gdb ChangeLog README TAGS \ - gdb.texinfo .gdbinit COPYING expread.tab.c stab.def \ - XGDB-README copying.c Projects Convex.notes copying.awk hp-include - -TAGFILES = ${SFILES} ${DEPFILES} ${PINSNS} ${HFILES} ${OPCODES} ${MFILES} \ - ${POSSLIBS} -TARFILES = ${TAGFILES} ${OTHERS} ${REMOTE_EXAMPLES} - -OBS = main.o blockframe.o breakpoint.o findvar.o stack.o source.o \ - values.o eval.o valops.o valarith.o valprint.o printcmd.o \ - symtab.o symmisc.o coffread.o dbxread.o infcmd.o infrun.o remote.o \ - command.o utils.o expread.o expprint.o pinsn.o environ.o version.o \ - copying.o ${READLINEOBS} - -TSOBS = core.o inflow.o dep.o - -NTSOBS = standalone.o - -TSSTART = /lib/crt0.o - -NTSSTART = kdb-start.o - -RL_LIB = readline/libreadline.a - -/* Do some fancy trickery to produce a line like - -DM_MAKEDEFINE="-DM_SYSV -DM_BSD_NM". -*/ -MD=M_MAKEDEFINE - -/* Avoid funny things that Sun's make throws in for us. */ -/* TARGET_ARCH is supposed to get around it putting in the machine type. - If the "things" up there really is plural, we'll need to do something - else as well. */ -/*.c.o: - ${CC} -c ${CFLAGS} $< */ -TARGET_ARCH= - -all: gdb $(XGDB) - -install: gdb $(XGDB) - cp gdb $(bindir)/gdb.new - mv $(bindir)/gdb.new $(bindir)/gdb - -if [ "$(XGDB)" = xgdb ]; then \ - cp xgdb $(xbindir)/xgdb.new; \ - mv $(xbindir)/xgdb.new $(xbindir)xgdb; \ - fi - -gdb : $(OBS) $(TSOBS) ${ADD_DEPS} ${RL_LIB} - rm -f init.c - ./munch ${MUNCH_DEFINE} $(OBS) $(TSOBS) > init.c - ${CC-LD} $(LDFLAGS) -o gdb init.c $(OBS) $(TSOBS) ${RL_LIB} $(CLIBS) - -/* This is useful when debugging GDB, because Unix doesn't let you run GDB - on itself without copying the executable. So "make gdb1" will make - gdb and put a copy in gdb1, and you can run it with "gdb gdb1". */ -gdb1 : gdb - cp gdb gdb1 - -Makefile : Makefile.dist - cp Makefile.dist tmp.c - $(CC) -E >Makefile tmp.c $(MD) "-DM_MAKEDEFINE=$(MD)" - -rm tmp.c -/* This did not work-- -Usparc became "-Usparc" became "-Usparc. - Or something like that. */ -/* $(CC) -E >Makefile tmp.c $(MD) "-DM_MAKEDEFINE=\"$(MD)\"" */ - -xgdb : $(OBS) $(TSOBS) xgdb.o ${ADD_DEPS} ${RL_LIB} - rm -f init.c - ./munch ${MUNCH_DEFINE} $(OBS) $(TSOBS) xgdb.o > init.c - $(CC-LD) $(LDFLAGS) -o xgdb init.c $(OBS) $(TSOBS) xgdb.o \ - -lXaw -lXmu -lXt -lX11 ${RL_LIB} $(CLIBS) - -/* Old (pre R3) xgdb comp. - $(CC-LD) $(LDFLAGS) -o xgdb init.c $(OBS) $(TSOBS) xgdb.o \ - -lXaw -lXt -lX11 $(CLIBS) */ - -kdb : $(NTSSTART) $(OBS) $(NTSOBS) ${ADD_DEPS} ${RL_LIB} - rm -f init.c - ./munch ${MUNCH_DEFINE} $(OBS) $(NTSOBS) > init.c - $(CC) $(LDFLAGS) -c init.c $(CLIBS) - ld -o kdb $(NTSSTART) $(OBS) $(NTSOBS) init.o ${RL_LIB} -lc $(CLIBS) - -/* If it can figure out the appropriate order, createtags will make sure - that the proper m-*, *-dep, *-pinsn, and *-opcode files come first - in the tags list. It will attempt to do the same for dbxread.c and - coffread.c. This makes using M-. on machine dependent routines much - easier. */ - -TAGS: ${TAGFILES} - createtags ${TAGFILES} -tags: TAGS - -gdb.tar: ${TARFILES} - rm -f gdb.tar - mkdir dist-gdb - cd dist-gdb ; for i in ${TARFILES} ; do ln -s ../$$i . ; done - mkdir dist-gdb/readline - cd dist-gdb/readline ; for i in ${READLINE} ; do ln -s ../../readline/$$i . ; done - tar chf gdb.tar dist-gdb - rm -rf dist-gdb - -/* Remove gdb.tar.Z so stupid compress doesn't ask whether we want to - overwrite it. compress -f is not what we want, because we do want - to know if compress would not make it smaller. */ -gdb.tar.Z: gdb.tar - if [ -f gdb.tar.Z ]; then rm -f gdb.tar.Z; else true; fi - compress gdb.tar - -clean: - rm -f ${OBS} ${TSOBS} ${NTSOBS} ${OBSTACK} ${REGEX} ${GNU_MALLOC} - rm -f init.c init.o - rm -f xgdb.o xgdb - rm -f gdb core gdb.tar gdb.tar.Z make.log - rm -f gdb[0-9] - cd readline ; make clean - -distclean: clean expread.tab.c TAGS - rm -f dep.c opcode.h param.h pinsn.c config.status - rm -f y.output yacc.acts yacc.tmp - rm -f ${TESTS} Makefile - -realclean: clean - rm -f expread.tab.c TAGS - rm -f dep.c opcode.h param.h pinsn.c config.status - rm -f Makefile - -xgdb.o : defs.h param.h symtab.h frame.h - -/* Make copying.c from COPYING */ -copying.c : COPYING copying.awk - awk -f copying.awk < COPYING > copying.c - -expread.tab.c : expread.y - @echo 'Expect 4 shift/reduce conflict.' - ${YACC} expread.y - mv y.tab.c expread.tab.c - -expread.o : expread.tab.c defs.h param.h symtab.h frame.h expression.h - $(CC) -c ${CFLAGS} expread.tab.c - mv expread.tab.o expread.o - -readline/libreadline.a : force_update - cd readline ; ${MAKE} "SYSV=${SYSV_DEFINE}" \ - "DEBUG_FLAGS=${GLOBAL_CFLAGS}" "CC=${CC}" libreadline.a - -force_update : - -/* Only useful if you are using the gnu malloc routines. */ -malloc.o : malloc.c - ${CC} -c ${MALLOC_FLAGS} malloc.c - -/* dep.o depends on config.status in case someone reconfigures gdb out - from under an already compiled gdb. */ -dep.o : dep.c config.status defs.h param.h frame.h inferior.h obstack.h \ - a.out.encap.h - -/* pinsn.o depends on config.status in case someone reconfigures gdb out - from under an already compiled gdb. */ -pinsn.o : pinsn.c config.status defs.h param.h symtab.h obstack.h symseg.h \ - frame.h opcode.h - -/* The rest of this is a standard dependencies list (hand edited output of - cpp -M). It does not include dependencies of .o files on .c files. */ -/* All files which depend on config.status also depend on param.h in case - someone reconfigures gdb out from under an already compiled gdb. */ -blockframe.o : defs.h param.h config.status symtab.h obstack.h symseg.h frame.h -breakpoint.o : defs.h param.h config.status symtab.h obstack.h symseg.h frame.h -coffread.o : defs.h param.h config.status -command.o : command.h defs.h -core.o : defs.h param.h config.status a.out.encap.h -dbxread.o : param.h config.status defs.h symtab.h obstack.h symseg.h a.out.encap.h \ - stab.gnu.h -environ.o : environ.h -eval.o : defs.h param.h config.status symtab.h obstack.h symseg.h value.h expression.h -expprint.o : defs.h symtab.h obstack.h symseg.h param.h config.status expression.h -findvar.o : defs.h param.h config.status symtab.h obstack.h symseg.h frame.h value.h -infcmd.o : defs.h param.h config.status symtab.h obstack.h symseg.h frame.h inferior.h \ - environ.h value.h -inflow.o : defs.h param.h config.status frame.h inferior.h -infrun.o : defs.h param.h config.status symtab.h obstack.h symseg.h frame.h inferior.h \ - wait.h -kdb-start.o : defs.h param.h config.status -main.o : defs.h command.h param.h config.status -malloc.o : getpagesize.h -obstack.o : obstack.h -printcmd.o : defs.h param.h config.status frame.h symtab.h obstack.h symseg.h value.h \ - expression.h -regex.o : regex.h -remote.o : defs.h param.h config.status frame.h inferior.h wait.h -source.o : defs.h symtab.h obstack.h symseg.h param.h config.status -stack.o : defs.h param.h config.status symtab.h obstack.h symseg.h frame.h -standalone.o : defs.h param.h config.status symtab.h obstack.h symseg.h frame.h \ - inferior.h wait.h -symmisc.o : defs.h symtab.h obstack.h symseg.h obstack.h -symtab.o : defs.h symtab.h obstack.h symseg.h param.h config.status obstack.h -utils.o : defs.h param.h config.status -valarith.o : defs.h param.h config.status symtab.h obstack.h symseg.h value.h expression.h -valops.o : defs.h param.h config.status symtab.h obstack.h symseg.h value.h frame.h \ - inferior.h -valprint.o : defs.h param.h config.status symtab.h obstack.h symseg.h value.h -values.o : defs.h param.h config.status symtab.h obstack.h symseg.h value.h - -robotussin.h : getpagesize.h -symtab.h : obstack.h symseg.h -a.out.encap.h : a.out.gnu.h - diff --git a/gnu/usr.bin/gdb/Projects b/gnu/usr.bin/gdb/Projects deleted file mode 100644 index f38f6c7..0000000 --- a/gnu/usr.bin/gdb/Projects +++ /dev/null @@ -1,114 +0,0 @@ - - Suggested projects for aspiring or current GDB hackers - ====================================================== - - (You should probably chat with kingdon@ai.mit.edu to make sure that - no one else is doing the project you chose). - -Add watchpoints (break if a memory location changes). This would -usually have to involve constant single stepping, but occasionally -there is operating system support which gdb should be able to cleanly -use (e.g. on the 80386, there are 4 debug registers. By ptracing an -address into them, you can get a trap on writes or on reads and -writes). - -Rewrite proceed, wait_for_inferior, and normal_stop to clean them up. -Suggestions: - - 1) Make each test in wait_for_inferior a seperate subroutine - call. - 2) Combine wait_for_inferior and normal_stop to clean up - communication via global variables. - 3) See if you can find some way to clean up the global - variables that are used; possibly group them by data flow - and information content? - -Work out some kind of way to allow running the inferior to be done as -a sub-execution of, eg. breakpoint command lists. Currently running -the inferior interupts any command list execution. This would require -some rewriting of wait_for_inferior & friends, and hence should -probably be done in concert with the above. - -Add function arguments to gdb user defined functions. - -Add convenience variables that refer to exec file, symbol file, -selected frame source file, selected frame function, selected frame -line number, etc. - -Add a "suspend" subcommand of the "continue" command to suspend gdb -while continuing execution of the subprocess. Useful when you are -debugging servers and you want to dodge out and initiate a connection -to a server running under gdb. - -Make "handle" understand symbolic signal names. - -Work out and implement a reasonably general mechanism for multi-threaded -processies. There are parts of one implemented in convex-dep.c, if -you want an example. - -A standalone version of gdb on the i386 exists. Anyone who wants to -do some serious working cleaning it up and making it a general -standalone gdb should contact pace@wheaties.ai.mit.edu. - -Add stab information to allow reasonable debugging of inline functions -(possibly they should show up on a stack backtrace? With a note -indicating that they weren't "real"?). - -Implement support for specifying arbitrary locations of stack frames -(in practice, this usually requires specification of both the top and -bottom of the stack frame (fp and sp), since you *must* retrieve the -pc that was saved in the innermost frame). - -Modify the naked "until" command to step until past the current source -line, rather than past the current pc value. This is tricky simply -because the low level routines have no way of specifying a multi-line -step range, and there is no way of saying "don't print stuff when we -stop" from above (otherwise could just call step many times). - -Modify the handling of symbols grouped through BINCL/EINCL stabs to -allocate a partial symtab for each BINCL/EINCL grouping. This will -seriously decrease the size of inter-psymtab dependencies and hence -lessen the amount that needs to be read in when a new source file is -accessed. - -Work out some method of saving breakpoints across the reloading of an -executable. Probably this should be by saving the commands by which -the breakpoints were set and re-executing them (as text locations may -change). - -Do an "x/i $pc" after each stepi or nexti. - -Modify all of the disassemblers to use printf_filtered to get correct -more filtering. - -Modify gdb to work correctly with Pascal. - -Rewrite macros that handle frame chaining and frameless functions. -They should be able to tell the difference between start, main, and a -frameless function called from main. - -Work out what information would need to be included in an executable -by the compiler to allow gdb to debug functions which do not have a -frame pointer. Modify gdb and gcc to do this. - -When `attached' to a program (via either OS support or remote -debugging), gdb should arrange to catch signals which the terminal -might send, as it is unlikely that the program will be able to notice -them. SIGINT and SIGTSTP are obvious examples. - -Enhance the gdb manual with extra examples where needed. - -Arrange for list_command not to use decode_line_1 and thus not require -symbols to be read in simply to read a source file. - -Problem in xgdb; the readline library needs the terminal in CBREAK -mode for command line editing, but this makes it difficult to dispatch -on button presses. Possible solution: use a define to replace getc in -readline.c with a routine that does button dispatches. You should -probably see XGDB-README before you fiddle with XGDB. Also, someone -is implementing a new xgdb; it may not be worth while fiddling with -the old one. - -# Local Variables: -# mode: text -# End: diff --git a/gnu/usr.bin/gdb/README.gnu b/gnu/usr.bin/gdb/README.gnu deleted file mode 100644 index fa54dec..0000000 --- a/gnu/usr.bin/gdb/README.gnu +++ /dev/null @@ -1,142 +0,0 @@ -This is GDB, the GNU source-level debugger, presently running under un*x. - -Before compiling GDB, you must tell GDB what kind of machine you are -running on. To do this, type `config.gdb machine', where machine is -something like `vax' or `sun2'. For a list of valid machine types, -type `config.gdb'. - -Normally config.gdb edits the makefile as necessary. If you have to -edit the makefile on a standard machine listed in config.gdb this -should be considered a bug and reported as such. - -Once these files are set up, just `make' will do everything, -producing an executable `gdb' in this directory. - -If you want a new (current to this release) version of the manual, you -will have to use the gdb.texinfo file provided with this distribution. -The gdb.texinfo file requires the texinfo-format-buffer command from -emacs 18.55 or later. - -About languages other than C... - -C++ support has been integrated into gdb. GDB should work with -FORTRAN programs (if you have problem, please send a bug report), but -I am not aware of anyone who is working on getting it to use the -syntax of any language other than C or C++. Pascal programs which use -sets, subranges, file variables, or nested functions will not -currently work. - -About -gg format... - -Currently GDB version 3.x does *not* support GCC's -gg format. This -is because it (in theory) has fast enough startup on dbx debugging -format object files that -gg format is unnecessary (and hence -undesirable, since it wastes space and processing power in gcc). I -would like to hear people's opinions on the amount of time currently -spent in startup; is it fast enough? - -About remote debugging... - -The two files remote-multi.shar and remote-sa.m68k.shar contain two -examples of a remote stub to be used with remote.c. The the -multi -file is a general stub that can probably be running on various -different flavors of unix to allow debugging over a serial line from -one machine to another. The remote-sa.m68k.shar is designed to run -standalone on a 68k type cpu and communicate properley with the -remote.c stub over a serial line. - -About reporting bugs... - -The correct address for reporting bugs found with gdb is -"bug-gdb@prep.ai.mit.edu". Please send all bugs to that address. - -About xgdb... - -xgdb.c was provided to us by the user community; it is not an integral -part of the gdb distribution. The problem of providing visual -debugging support on top of gdb is peripheral to the GNU project and -(at least right now) we can't afford to put time into it. So while we -will be happy to incorporate user fixes to xgdb.c, we do not guarantee -that it will work and we will not fix bugs reported in it. Someone is -working on writing a new XGDB, so improving (e.g. by fixing it so that -it will work, if it doesn't currently) the current one is not worth it. - -For those intersted in auto display of source and the availability of -an editor while debugging I suggest trying gdb-mode in gnu-emacs. -Comments on this mode are welcome. - -About the machine-dependent files... - -m-.h (param.h is a link to this file). -This file contains macro definitions that express information -about the machine's registers, stack frame format and instructions. - --opcode.h (opcode.h is a link to this file). --pinsn.c (pinsn.c is a link to this file). -These files contain the information necessary to print instructions -for your cpu type. - --dep.c (dep.c is a link to this file). -Those routines which provide a low level interface to ptrace and which -tend to be machine-dependent. (The machine-independent routines are in -`infrun.c' and `inflow.c') - -About writing code for GDB... - -We appreciate having users contribute code that is of general use, but -for it to be included in future GDB releases it must be cleanly -written. We do not want to include changes that will needlessly make future -maintainance difficult. It is not much harder to do things right, and -in the long term it is worth it to the GNU project, and probably to -you individually as well. - -Please code according to the GNU coding standards. If you do not have -a copy, you can request one by sending mail to gnu@prep.ai.mit.edu. - -Please try to avoid making machine-specific changes to -machine-independent files (i.e. all files except "param.h" and -"dep.c". "pinsn.c" and "opcode.h" are processor-specific but not -operating system-dependent). If this is unavoidable, put a hook in -the machine-independent file which calls a (possibly) -machine-dependent macro (for example, the IGNORE_SYMBOL macro can be -used for any symbols which need to be ignored on a specific machine. -Calling IGNORE_SYMBOL in dbxread.c is a lot cleaner than a maze of #if -defined's). The machine-independent code should do whatever "most" -machines want if the macro is not defined in param.h. Using #if -defined can sometimes be OK (e.g. SET_STACK_LIMIT_HUGE) but should be -conditionalized on a specific feature of an operating system (set in -param.h) rather than something like #if defined(vax) or #if -defined(SYSV). - -It is better to replace entire routines which may be system-specific, -rather than put in a whole bunch of hooks which are probably not going -to be helpful for any purpose other than your changes. For example, -if you want to modify dbxread.c to deal with DBX debugging symbols -which are in COFF files rather than BSD a.out files, do something -along the lines of a macro GET_NEXT_SYMBOL, which could have -different definitions for COFF and a.out, rather than trying to put -the necessary changes throughout all the code in dbxread.c that -currently assumes BSD format. - -Please avoid duplicating code. For example, if something needs to be -changed in read_inferior_memory, it is very painful because there is a -copy in every dep.c file. The correct way to do this is to put (in -this case) the standard ptrace interfaces in a separate file ptrace.c, -which is used by all systems which have ptrace. ptrace.c would deal -with variations between systems the same way any system-independent -file would (hooks, #if defined, etc.). - -About debugging gdb with itself... - -You probably want to do a "make TAGS" after you configure your -distribution; this will put the machine dependent routines for your -local machine where they will be accessed first by a M-period . - -Also, make sure that you've compiled gdb with your local cc or taken -appropriate precautions regarding ansification of include files. See -the Makefile for more information. - -The "info" command, when executed without a subcommand in a gdb being -debugged by gdb, will pop you back up to the top level gdb. See -.gdbinit for more details. - diff --git a/gnu/usr.bin/gdb/XGdbinit.samp b/gnu/usr.bin/gdb/XGdbinit.samp deleted file mode 100644 index a99f106..0000000 --- a/gnu/usr.bin/gdb/XGdbinit.samp +++ /dev/null @@ -1,15 +0,0 @@ -button "show" push-to-file %S -button "back" pop-file -button "break in" break %S -button "break at" break %l -button delete delete %b%e -button backtrace -button up -button down -button print print %E -button print* print *(%E) -button next -button step -button "do upto" until %l%e -button finish -button continue cont%e diff --git a/gnu/usr.bin/gdb/Xgdb.ad b/gnu/usr.bin/gdb/Xgdb.ad deleted file mode 100644 index 5f9fe99..0000000 --- a/gnu/usr.bin/gdb/Xgdb.ad +++ /dev/null @@ -1,8 +0,0 @@ -Xgdb*geometry: 580x874-0+28 -Xgdb*src*scrollVertical: whenneeded -Xgdb*src*scrollHorizontal: whenneeded -Xgdb*src*wrap: never -Xgdb*src*editType: read -Xgdb*frame.buttons.allowResize: true -Xgdb*frame.buttons.skipAdjust: true -Xgdb*frame*showGrip: false diff --git a/gnu/usr.bin/gdb/bfd/seclet.c b/gnu/usr.bin/gdb/bfd/seclet.c deleted file mode 100644 index 5dcc59a..0000000 --- a/gnu/usr.bin/gdb/bfd/seclet.c +++ /dev/null @@ -1,185 +0,0 @@ -/* seclet.c - Copyright (C) 1992, 1993 Free Software Foundation, Inc. - Written by Cygnus Support. - -This file is part of BFD, the Binary File Descriptor library. - -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 of the License, 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 this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* This module is part of BFD */ - - -/* The intention is that one day, all the code which uses sections - will change and use seclets instead - maybe seglet would have been - a better name.. - - Anyway, a seclet contains enough info to be able to describe an - area of output memory in one go. - - The only description so far catered for is that of the - <>, which is a select which points to a - <
> and the <> associated with the section, so - that relocation can be done when needed. - - One day there will be more types - they will at least migrate from - the linker's data structures - also there could be extra stuff, - like a bss seclet, which descibes a lump of memory as containing - zeros compactly, without the horrible SEC_* flag cruft. - - -*/ - -#include "bfd.h" -#include "sysdep.h" -#include "libbfd.h" -#include "seclet.h" -#include "coff/internal.h" - -/* Create a new seclet and attach it to a section. */ - -bfd_seclet_type * -DEFUN(bfd_new_seclet,(abfd, section), - bfd *abfd AND - asection *section) -{ - bfd_seclet_type *n = (bfd_seclet_type *)bfd_alloc(abfd, sizeof(bfd_seclet_type)); - if (section->seclets_tail != (bfd_seclet_type *)NULL) { - section->seclets_tail->next = n; - } - else - { - section->seclets_head = n; - } - section->seclets_tail = n; - - return n; -} - -/* Given an indirect seclet which points to an input section, relocate - the contents of the seclet and put the data in its final - destination. */ - -static boolean -DEFUN(rel,(abfd, seclet, output_section, data, relocateable), - bfd *abfd AND - bfd_seclet_type *seclet AND - asection *output_section AND - PTR data AND - boolean relocateable) -{ - if ((output_section->flags & SEC_HAS_CONTENTS) != 0 - && seclet->size) - { - data = (PTR) bfd_get_relocated_section_contents(abfd, seclet, data, - relocateable); - if(bfd_set_section_contents(abfd, - output_section, - data, - seclet->offset, - seclet->size) == false) - { - abort(); - } - } - return true; -} - -/* Put the contents of a seclet in its final destination. */ - -static boolean -DEFUN(seclet_dump_seclet,(abfd, seclet, section, data, relocateable), - bfd *abfd AND - bfd_seclet_type *seclet AND - asection *section AND - PTR data AND - boolean relocateable) -{ - switch (seclet->type) - { - case bfd_indirect_seclet: - /* The contents of this section come from another one somewhere - else */ - return rel(abfd, seclet, section, data, relocateable); - - case bfd_fill_seclet: - /* Fill in the section with us */ - { - char *d = bfd_xmalloc(seclet->size); - unsigned int i; - for (i =0; i < seclet->size; i+=2) { - d[i] = seclet->u.fill.value >> 8; - } - for (i = 1; i < seclet->size; i+=2) { - d[i] = seclet->u.fill.value ; - } - /* Don't bother to fill in empty sections */ - if (!(bfd_get_section_flags(abfd, section) & SEC_HAS_CONTENTS)) - { - return true; - } - return bfd_set_section_contents(abfd, section, d, seclet->offset, - seclet->size); - } - - default: - abort(); - } - - return true; -} - -/* -INTERNAL_FUNCTION - bfd_generic_seclet_link - -SYNOPSIS - boolean bfd_generic_seclet_link - (bfd *abfd, - PTR data, - boolean relocateable); - -DESCRIPTION - - The generic seclet linking routine. The caller should have - set up seclets for all the output sections. The DATA argument - should point to a memory area large enough to hold the largest - section. This function looks through the seclets and moves - the contents into the output sections. If RELOCATEABLE is - true, the orelocation fields of the output sections must - already be initialized. - -*/ - -boolean -DEFUN(bfd_generic_seclet_link,(abfd, data, relocateable), - bfd *abfd AND - PTR data AND - boolean relocateable) -{ - asection *o = abfd->sections; - while (o != (asection *)NULL) - { - bfd_seclet_type *p = o->seclets_head; - while (p != (bfd_seclet_type *)NULL) - { - if (seclet_dump_seclet(abfd, p, o, data, relocateable) == false) - return false; - p = p ->next; - } - o = o->next; - } - - return true; -} diff --git a/gnu/usr.bin/gdb/bfd/seclet.h b/gnu/usr.bin/gdb/bfd/seclet.h deleted file mode 100644 index de5fdff..0000000 --- a/gnu/usr.bin/gdb/bfd/seclet.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Definitions of little sections (seclets) for BFD. - Copyright 1992 Free Software Foundation, Inc. - Hacked by Steve Chamberlain of Cygnus Support. - -This file is part of BFD, the Binary File Descriptor library. - -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 of the License, 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 this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef _SECLET_H -#define _SECLET_H - -enum bfd_seclet_enum -{ - bfd_indirect_seclet, - bfd_fill_seclet -}; - -struct bfd_seclet -{ - struct bfd_seclet *next; - enum bfd_seclet_enum type; - unsigned int offset; - unsigned int size; - union - { - struct - { - asection *section; - asymbol **symbols; - } indirect; - struct { - int value; - } fill; - } - u; -}; - -typedef struct bfd_seclet bfd_seclet_type; - -bfd_seclet_type * -bfd_new_seclet PARAMS ((bfd *, asection *)); - -#endif diff --git a/gnu/usr.bin/gdb/blockframe.c b/gnu/usr.bin/gdb/blockframe.c deleted file mode 100644 index 236d1cd..0000000 --- a/gnu/usr.bin/gdb/blockframe.c +++ /dev/null @@ -1,622 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)blockframe.c 6.4 (Berkeley) 5/11/91"; -#endif /* not lint */ - -/* Get info from stack frames; - convert between frames, blocks, functions and pc values. - Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "frame.h" - -#include - -#if defined(NEWVM) && defined(KERNELDEBUG) -#include /* XXX for FRAME_CHAIN_VALID */ -#endif - -/* Start and end of object file containing the entry point. - STARTUP_FILE_END is the first address of the next file. - This file is assumed to be a startup file - and frames with pc's inside it - are treated as nonexistent. - - Setting these variables is necessary so that backtraces do not fly off - the bottom of the stack. */ -CORE_ADDR startup_file_start; -CORE_ADDR startup_file_end; - -/* Is ADDR outside the startup file? */ -int -outside_startup_file (addr) - CORE_ADDR addr; -{ - return !(addr >= startup_file_start && addr < startup_file_end); -} - -/* Address of innermost stack frame (contents of FP register) */ - -static FRAME current_frame; - -struct block *block_for_pc (); -CORE_ADDR get_pc_function_start (); - -/* - * Cache for frame addresses already read by gdb. Valid only while - * inferior is stopped. Control variables for the frame cache should - * be local to this module. - */ -struct obstack frame_cache_obstack; - -/* Return the innermost (currently executing) stack frame. */ - -FRAME -get_current_frame () -{ - /* We assume its address is kept in a general register; - param.h says which register. */ - - return current_frame; -} - -void -set_current_frame (frame) - FRAME frame; -{ - current_frame = frame; -} - -FRAME -create_new_frame (addr, pc) - FRAME_ADDR addr; - CORE_ADDR pc; -{ - struct frame_info *fci; /* Same type as FRAME */ - - fci = (struct frame_info *) - obstack_alloc (&frame_cache_obstack, - sizeof (struct frame_info)); - - /* Arbitrary frame */ - fci->next = (struct frame_info *) 0; - fci->prev = (struct frame_info *) 0; - fci->frame = addr; - fci->next_frame = 0; /* Since arbitrary */ - fci->pc = pc; - -#ifdef INIT_EXTRA_FRAME_INFO - INIT_EXTRA_FRAME_INFO (fci); -#endif - - return fci; -} - -/* Return the frame that called FRAME. - If FRAME is the original frame (it has no caller), return 0. */ - -FRAME -get_prev_frame (frame) - FRAME frame; -{ - /* We're allowed to know that FRAME and "struct frame_info *" are - the same */ - return get_prev_frame_info (frame); -} - -/* Return the frame that FRAME calls (0 if FRAME is the innermost - frame). */ - -FRAME -get_next_frame (frame) - FRAME frame; -{ - /* We're allowed to know that FRAME and "struct frame_info *" are - the same */ - return frame->next; -} - -/* - * Flush the entire frame cache. - */ -void -flush_cached_frames () -{ - /* Since we can't really be sure what the first object allocated was */ - obstack_free (&frame_cache_obstack, 0); - obstack_init (&frame_cache_obstack); - - current_frame = (struct frame_info *) 0; /* Invalidate cache */ -} - -/* Return a structure containing various interesting information - about a specified stack frame. */ -/* How do I justify including this function? Well, the FRAME - identifier format has gone through several changes recently, and - it's not completely inconceivable that it could happen again. If - it does, have this routine around will help */ - -struct frame_info * -get_frame_info (frame) - FRAME frame; -{ - return frame; -} - -/* If a machine allows frameless functions, it should define a macro - FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) in param.h. FI is the struct - frame_info for the frame, and FRAMELESS should be set to nonzero - if it represents a frameless function invocation. */ - -/* Many machines which allow frameless functions can detect them using - this macro. Such machines should define FRAMELESS_FUNCTION_INVOCATION - to just call this macro. */ -#define FRAMELESS_LOOK_FOR_PROLOGUE(FI, FRAMELESS) \ -{ \ - CORE_ADDR func_start, after_prologue; \ - func_start = (get_pc_function_start ((FI)->pc) + \ - FUNCTION_START_OFFSET); \ - if (func_start) \ - { \ - after_prologue = func_start; \ - SKIP_PROLOGUE (after_prologue); \ - (FRAMELESS) = (after_prologue == func_start); \ - } \ - else \ - /* If we can't find the start of the function, we don't really */ \ - /* know whether the function is frameless, but we should be */ \ - /* able to get a reasonable (i.e. best we can do under the */ \ - /* circumstances) backtrace by saying that it isn't. */ \ - (FRAMELESS) = 0; \ -} - -/* Return a structure containing various interesting information - about the frame that called NEXT_FRAME. Returns NULL - if there is no such frame. */ - -struct frame_info * -get_prev_frame_info (next_frame) - FRAME next_frame; -{ - FRAME_ADDR address; - struct frame_info *prev; - int fromleaf = 0; - - /* If the requested entry is in the cache, return it. - Otherwise, figure out what the address should be for the entry - we're about to add to the cache. */ - - if (!next_frame) - { - if (!current_frame) - { - if (!have_inferior_p () && !have_core_file_p ()) - fatal ("get_prev_frame_info: Called before cache primed. \"Shouldn't happen.\""); - else - error ("No inferior or core file."); - } - - return current_frame; - } - - /* If we have the prev one, return it */ - if (next_frame->prev) - return next_frame->prev; - - /* On some machines it is possible to call a function without - setting up a stack frame for it. On these machines, we - define this macro to take two args; a frameinfo pointer - identifying a frame and a variable to set or clear if it is - or isn't leafless. */ -#ifdef FRAMELESS_FUNCTION_INVOCATION - /* Still don't want to worry about this except on the innermost - frame. This macro will set FROMLEAF if NEXT_FRAME is a - frameless function invocation. */ - if (!(next_frame->next)) - { - FRAMELESS_FUNCTION_INVOCATION (next_frame, fromleaf); - if (fromleaf) - address = next_frame->frame; - } -#endif - - if (!fromleaf) - { - /* Two macros defined in param.h specify the machine-dependent - actions to be performed here. - First, get the frame's chain-pointer. - If that is zero, the frame is the outermost frame or a leaf - called by the outermost frame. This means that if start - calls main without a frame, we'll return 0 (which is fine - anyway). - - Nope; there's a problem. This also returns when the current - routine is a leaf of main. This is unacceptable. We move - this to after the ffi test; I'd rather have backtraces from - start go curfluy than have an abort called from main not show - main. */ - address = FRAME_CHAIN (next_frame); - if (!FRAME_CHAIN_VALID (address, next_frame)) - return 0; - /* If this frame is a leaf, this will be superceeded by the - code below. */ - address = FRAME_CHAIN_COMBINE (address, next_frame); - } - if (address == 0) - return 0; - - prev = (struct frame_info *) - obstack_alloc (&frame_cache_obstack, - sizeof (struct frame_info)); - - if (next_frame) - next_frame->prev = prev; - prev->next = next_frame; - prev->prev = (struct frame_info *) 0; - prev->frame = address; - prev->next_frame = prev->next ? prev->next->frame : 0; - -#ifdef INIT_EXTRA_FRAME_INFO - INIT_EXTRA_FRAME_INFO(prev); -#endif - - /* This entry is in the frame queue now, which is good since - FRAME_SAVED_PC may use that queue to figure out it's value - (see m-sparc.h). We want the pc saved in the inferior frame. */ - prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (next_frame) : - next_frame ? FRAME_SAVED_PC (next_frame) : read_pc ()); - - return prev; -} - -CORE_ADDR -get_frame_pc (frame) - FRAME frame; -{ - struct frame_info *fi; - fi = get_frame_info (frame); - return fi->pc; -} - -/* Find the addresses in which registers are saved in FRAME. */ - -void -get_frame_saved_regs (frame_info_addr, saved_regs_addr) - struct frame_info *frame_info_addr; - struct frame_saved_regs *saved_regs_addr; -{ - FRAME_FIND_SAVED_REGS (frame_info_addr, *saved_regs_addr); -} - -/* Return the innermost lexical block in execution - in a specified stack frame. The frame address is assumed valid. */ - -struct block * -get_frame_block (frame) - FRAME frame; -{ - struct frame_info *fi; - CORE_ADDR pc; - - fi = get_frame_info (frame); - - pc = fi->pc; - if (fi->next_frame != 0) - /* We are not in the innermost frame. We need to subtract one to - get the correct block, in case the call instruction was the - last instruction of the block. If there are any machines on - which the saved pc does not point to after the call insn, we - probably want to make fi->pc point after the call insn anyway. */ - --pc; - return block_for_pc (pc); -} - -struct block * -get_current_block () -{ - return block_for_pc (read_pc ()); -} - -CORE_ADDR -get_pc_function_start (pc) - CORE_ADDR pc; -{ - register struct block *bl = block_for_pc (pc); - register struct symbol *symbol; - if (bl == 0 || (symbol = block_function (bl)) == 0) - { - register int misc_index = find_pc_misc_function (pc); - if (misc_index >= 0) - return misc_function_vector[misc_index].address; - return 0; - } - bl = SYMBOL_BLOCK_VALUE (symbol); - return BLOCK_START (bl); -} - -/* Return the symbol for the function executing in frame FRAME. */ - -struct symbol * -get_frame_function (frame) - FRAME frame; -{ - register struct block *bl = get_frame_block (frame); - if (bl == 0) - return 0; - return block_function (bl); -} - -/* Return the innermost lexical block containing the specified pc value, - or 0 if there is none. */ - -extern struct symtab *psymtab_to_symtab (); - -struct block * -block_for_pc (pc) - register CORE_ADDR pc; -{ - register struct block *b; - register int bot, top, half; - register struct symtab *s; - register struct partial_symtab *ps; - struct blockvector *bl; - - /* First search all symtabs for one whose file contains our pc */ - - for (s = symtab_list; s; s = s->next) - { - bl = BLOCKVECTOR (s); - b = BLOCKVECTOR_BLOCK (bl, 0); - if (BLOCK_START (b) <= pc - && BLOCK_END (b) > pc) - break; - } - - if (s == 0) - for (ps = partial_symtab_list; ps; ps = ps->next) - { - if (ps->textlow <= pc - && ps->texthigh > pc) - { - if (ps->readin) - fatal ("Internal error: pc found in readin psymtab and not in any symtab."); - s = psymtab_to_symtab (ps); - bl = BLOCKVECTOR (s); - b = BLOCKVECTOR_BLOCK (bl, 0); - break; - } - } - - if (s == 0) - return 0; - - /* Then search that symtab for the smallest block that wins. */ - /* Use binary search to find the last block that starts before PC. */ - - bot = 0; - top = BLOCKVECTOR_NBLOCKS (bl); - - while (top - bot > 1) - { - half = (top - bot + 1) >> 1; - b = BLOCKVECTOR_BLOCK (bl, bot + half); - if (BLOCK_START (b) <= pc) - bot += half; - else - top = bot + half; - } - - /* Now search backward for a block that ends after PC. */ - - while (bot >= 0) - { - b = BLOCKVECTOR_BLOCK (bl, bot); - if (BLOCK_END (b) > pc) - return b; - bot--; - } - - return 0; -} - -/* Return the function containing pc value PC. - Returns 0 if function is not known. */ - -struct symbol * -find_pc_function (pc) - CORE_ADDR pc; -{ - register struct block *b = block_for_pc (pc); - if (b == 0) - return 0; - return block_function (b); -} - -/* Finds the "function" (text symbol) that is smaller than PC - but greatest of all of the potential text symbols. Sets - *NAME and/or *ADDRESS conditionally if that pointer is non-zero. - Returns 0 if it couldn't find anything, 1 if it did. On a zero - return, *NAME and *ADDRESS are always set to zero. On a 1 return, - *NAME and *ADDRESS contain real information. */ - -int -find_pc_partial_function (pc, name, address) - CORE_ADDR pc; - char **name; - CORE_ADDR *address; -{ - struct partial_symtab *pst = find_pc_psymtab (pc); - struct symbol *f; - int miscfunc; - struct partial_symbol *psb; - - if (pst) - { - if (pst->readin) - { - /* The information we want has already been read in. - We can go to the already readin symbols and we'll get - the best possible answer. */ - f = find_pc_function (pc); - if (!f) - { - return_error: - /* No availible symbol. */ - if (name != 0) - *name = 0; - if (address != 0) - *address = 0; - return 0; - } - - if (name) - *name = SYMBOL_NAME (f); - if (address) - *address = BLOCK_START (SYMBOL_BLOCK_VALUE (f)); - return 1; - } - - /* Get the information from a combination of the pst - (static symbols), and the misc function vector (extern - symbols). */ - miscfunc = find_pc_misc_function (pc); - psb = find_pc_psymbol (pst, pc); - - if (!psb && miscfunc == -1) - { - goto return_error; - } - if (!psb - || (miscfunc != -1 - && (SYMBOL_VALUE(psb) - < misc_function_vector[miscfunc].address))) - { - if (address) - *address = misc_function_vector[miscfunc].address; - if (name) - *name = misc_function_vector[miscfunc].name; - return 1; - } - else - { - if (address) - *address = SYMBOL_VALUE (psb); - if (name) - *name = SYMBOL_NAME (psb); - return 1; - } - } - else - /* Must be in the misc function stuff. */ - { - miscfunc = find_pc_misc_function (pc); - if (miscfunc == -1) - goto return_error; - if (address) - *address = misc_function_vector[miscfunc].address; - if (name) - *name = misc_function_vector[miscfunc].name; - return 1; - } -} - -/* Find the misc function whose address is the largest - while being less than PC. Return its index in misc_function_vector. - Returns -1 if PC is not in suitable range. */ - -int -find_pc_misc_function (pc) - register CORE_ADDR pc; -{ - register int lo = 0; - register int hi = misc_function_count-1; - register int new; - register int distance; - - /* Note that the last thing in the vector is always _etext. */ - /* Actually, "end", now that non-functions - go on the misc_function_vector. */ - - /* Above statement is not *always* true - fix for case where there are */ - /* no misc functions at all (ie no symbol table has been read). */ - if (hi < 0) return -1; /* no misc functions recorded */ - - /* trivial reject range test */ - if (pc < misc_function_vector[0].address || - pc > misc_function_vector[hi].address) - return -1; - - /* Note that the following search will not return hi if - pc == misc_function_vector[hi].address. If "end" points to the - first unused location, this is correct and the above test - simply needs to be changed to - "pc >= misc_function_vector[hi].address". */ - do { - new = (lo + hi) >> 1; - distance = misc_function_vector[new].address - pc; - if (distance == 0) - return new; /* an exact match */ - else if (distance > 0) - hi = new; - else - lo = new; - } while (hi-lo != 1); - - /* if here, we had no exact match, so return the lower choice */ - return lo; -} - -/* Return the innermost stack frame executing inside of the specified block, - or zero if there is no such frame. */ - -FRAME -block_innermost_frame (block) - struct block *block; -{ - struct frame_info *fi; - register FRAME frame; - register CORE_ADDR start = BLOCK_START (block); - register CORE_ADDR end = BLOCK_END (block); - - frame = 0; - while (1) - { - frame = get_prev_frame (frame); - if (frame == 0) - return 0; - fi = get_frame_info (frame); - if (fi->pc >= start && fi->pc < end) - return frame; - } -} - -void -_initialize_blockframe () -{ - obstack_init (&frame_cache_obstack); -} diff --git a/gnu/usr.bin/gdb/breakpoint.c b/gnu/usr.bin/gdb/breakpoint.c deleted file mode 100644 index b515ed3..0000000 --- a/gnu/usr.bin/gdb/breakpoint.c +++ /dev/null @@ -1,1383 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)breakpoint.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Everything about breakpoints, for GDB. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "frame.h" - -/* This is the sequence of bytes we insert for a breakpoint. */ - -static char break_insn[] = BREAKPOINT; - -/* States of enablement of breakpoint. - `temporary' means disable when hit. - `delete' means delete when hit. */ - -enum enable { disabled, enabled, temporary, delete}; - -/* Not that the ->silent field is not currently used by any commands - (though the code is in there if it was to be and set_raw_breakpoint - does set it to 0). I implemented it because I thought it would be - useful for a hack I had to put in; I'm going to leave it in because - I can see how there might be times when it would indeed be useful */ - -struct breakpoint -{ - struct breakpoint *next; - /* Number assigned to distinguish breakpoints. */ - int number; - /* Address to break at. */ - CORE_ADDR address; - /* Line number of this address. Redundant. */ - int line_number; - /* Symtab of file of this address. Redundant. */ - struct symtab *symtab; - /* Zero means disabled; remember the info but don't break here. */ - enum enable enable; - /* Non-zero means a silent breakpoint (don't print frame info - if we stop here). */ - unsigned char silent; - /* Number of stops at this breakpoint that should - be continued automatically before really stopping. */ - int ignore_count; - /* "Real" contents of byte where breakpoint has been inserted. - Valid only when breakpoints are in the program. */ - char shadow_contents[sizeof break_insn]; - /* Nonzero if this breakpoint is now inserted. */ - char inserted; - /* Nonzero if this is not the first breakpoint in the list - for the given address. */ - char duplicate; - /* Chain of command lines to execute when this breakpoint is hit. */ - struct command_line *commands; - /* Stack depth (address of frame). If nonzero, break only if fp - equals this. */ - FRAME_ADDR frame; - /* Conditional. Break only if this expression's value is nonzero. */ - struct expression *cond; -}; - -#define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next) - -/* Chain of all breakpoints defined. */ - -struct breakpoint *breakpoint_chain; - -/* Number of last breakpoint made. */ - -static int breakpoint_count; - -/* Default address, symtab and line to put a breakpoint at - for "break" command with no arg. - if default_breakpoint_valid is zero, the other three are - not valid, and "break" with no arg is an error. - - This set by print_stack_frame, which calls set_default_breakpoint. */ - -int default_breakpoint_valid; -CORE_ADDR default_breakpoint_address; -struct symtab *default_breakpoint_symtab; -int default_breakpoint_line; - -/* Remaining commands (not yet executed) - of last breakpoint hit. */ - -struct command_line *breakpoint_commands; - -static void delete_breakpoint (); -void clear_momentary_breakpoints (); -void breakpoint_auto_delete (); - -/* Flag indicating extra verbosity for xgdb. */ -extern int xgdb_verbose; - -/* condition N EXP -- set break condition of breakpoint N to EXP. */ - -static void -condition_command (arg, from_tty) - char *arg; - int from_tty; -{ - register struct breakpoint *b; - register char *p; - register int bnum; - register struct expression *expr; - - if (arg == 0) - error_no_arg ("breakpoint number"); - - p = arg; - while (*p >= '0' && *p <= '9') p++; - if (p == arg) - /* There is no number here. (e.g. "cond a == b"). */ - error_no_arg ("breakpoint number"); - bnum = atoi (arg); - - ALL_BREAKPOINTS (b) - if (b->number == bnum) - { - if (b->cond) - { - free (b->cond); - b->cond = 0; /* parse_c_1 can leave this unchanged. */ - } - if (*p == 0) - { - b->cond = 0; - if (from_tty) - printf ("Breakpoint %d now unconditional.\n", bnum); - } - else - { - if (*p != ' ' && *p != '\t') - error ("Arguments must be an integer (breakpoint number) and an expression."); - - /* Find start of expression */ - while (*p == ' ' || *p == '\t') p++; - - arg = p; - b->cond = (struct expression *) parse_c_1 (&arg, block_for_pc (b->address), 0); - if (*arg) - error ("Junk at end of expression"); - } - return; - } - - error ("No breakpoint number %d.", bnum); -} - -static void -commands_command (arg, from_tty) - char *arg; - int from_tty; -{ - register struct breakpoint *b; - register char *p, *p1; - register int bnum; - struct command_line *l; - - /* If we allowed this, we would have problems with when to - free the storage, if we change the commands currently - being read from. */ - - if (breakpoint_commands) - error ("Can't use the \"commands\" command among a breakpoint's commands."); - - /* Allow commands by itself to refer to the last breakpoint. */ - if (arg == 0) - bnum = breakpoint_count; - else - { - p = arg; - if (! (*p >= '0' && *p <= '9')) - error ("Argument must be integer (a breakpoint number)."); - - while (*p >= '0' && *p <= '9') p++; - if (*p) - error ("Unexpected extra arguments following breakpoint number."); - - bnum = atoi (arg); - } - - ALL_BREAKPOINTS (b) - if (b->number == bnum) - { - if (from_tty && input_from_terminal_p ()) - { - printf ("Type commands for when breakpoint %d is hit, one per line.\n\ -End with a line saying just \"end\".\n", bnum); - fflush (stdout); - } - l = read_command_lines (from_tty); - free_command_lines (b->commands); - b->commands = l; - return; - } - error ("No breakpoint number %d.", bnum); -} - -/* Called from command loop to execute the commands - associated with the breakpoint we just stopped at. */ - -void -do_breakpoint_commands () -{ - struct command_line *cmd; - - while (cmd = breakpoint_commands) - { - breakpoint_commands = 0; - execute_command_lines(cmd); - /* If command was "cont", breakpoint_commands is now 0, - of if we stopped at yet another breakpoint which has commands, - it is now the commands for the new breakpoint. */ - } - clear_momentary_breakpoints (); -} - -/* Used when the program is proceeded, to eliminate any remaining - commands attached to the previous breakpoint we stopped at. */ - -void -clear_breakpoint_commands () -{ - breakpoint_commands = 0; - breakpoint_auto_delete (0); -} - -/* Functions to get and set the current list of pending - breakpoint commands. These are used by run_stack_dummy - to preserve the commands around a function call. */ - -struct command_line * -get_breakpoint_commands () -{ - return breakpoint_commands; -} - -void -set_breakpoint_commands (cmds) - struct command_line *cmds; -{ - breakpoint_commands = cmds; -} - -/* insert_breakpoints is used when starting or continuing the program. - remove_breakpoints is used when the program stops. - Both return zero if successful, - or an `errno' value if could not write the inferior. */ - -int -insert_breakpoints () -{ - register struct breakpoint *b; - int val; - -#ifdef BREAKPOINT_DEBUG - printf ("Inserting breakpoints.\n"); -#endif /* BREAKPOINT_DEBUG */ - - ALL_BREAKPOINTS (b) - if (b->enable != disabled && ! b->inserted && ! b->duplicate) - { - read_memory (b->address, b->shadow_contents, sizeof break_insn); - val = write_memory (b->address, break_insn, sizeof break_insn); - if (val) - return val; -#ifdef BREAKPOINT_DEBUG - printf ("Inserted breakpoint at 0x%x, shadow 0x%x, 0x%x.\n", - b->address, b->shadow_contents[0], b->shadow_contents[1]); -#endif /* BREAKPOINT_DEBUG */ - b->inserted = 1; - } - return 0; -} - -int -remove_breakpoints () -{ - register struct breakpoint *b; - int val; - -#ifdef BREAKPOINT_DEBUG - printf ("Removing breakpoints.\n"); -#endif /* BREAKPOINT_DEBUG */ - - ALL_BREAKPOINTS (b) - if (b->inserted) - { - val = write_memory (b->address, b->shadow_contents, sizeof break_insn); - if (val) - return val; - b->inserted = 0; -#ifdef BREAKPOINT_DEBUG - printf ("Removed breakpoint at 0x%x, shadow 0x%x, 0x%x.\n", - b->address, b->shadow_contents[0], b->shadow_contents[1]); -#endif /* BREAKPOINT_DEBUG */ - } - - return 0; -} - -/* Clear the "inserted" flag in all breakpoints. - This is done when the inferior is loaded. */ - -void -mark_breakpoints_out () -{ - register struct breakpoint *b; - - ALL_BREAKPOINTS (b) - b->inserted = 0; -} - -/* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC. - When continuing from a location with a breakpoint, - we actually single step once before calling insert_breakpoints. */ - -int -breakpoint_here_p (pc) - CORE_ADDR pc; -{ - register struct breakpoint *b; - - ALL_BREAKPOINTS (b) - if (b->enable != disabled && b->address == pc) - return 1; - - return 0; -} - -/* Evaluate the expression EXP and return 1 if value is zero. - This is used inside a catch_errors to evaluate the breakpoint condition. */ - -int -breakpoint_cond_eval (exp) - struct expression *exp; -{ - return value_zerop (evaluate_expression (exp)); -} - -/* Return 0 if PC is not the address just after a breakpoint, - or -1 if breakpoint says do not stop now, - or -2 if breakpoint says it has deleted itself and don't stop, - or -3 if hit a breakpoint number -3 (delete when program stops), - or else the number of the breakpoint, - with 0x1000000 added (or subtracted, for a negative return value) for - a silent breakpoint. */ - -int -breakpoint_stop_status (pc, frame_address) - CORE_ADDR pc; - FRAME_ADDR frame_address; -{ - register struct breakpoint *b; - register int cont = 0; - - /* Get the address where the breakpoint would have been. */ - pc -= DECR_PC_AFTER_BREAK; - - ALL_BREAKPOINTS (b) - if (b->enable != disabled && b->address == pc) - { - if (b->frame && b->frame != frame_address) - cont = -1; - else - { - int value_zero; - if (b->cond) - { - /* Need to select the frame, with all that implies - so that the conditions will have the right context. */ - select_frame (get_current_frame (), 0); - value_zero - = catch_errors (breakpoint_cond_eval, b->cond, - "Error occurred in testing breakpoint condition."); - free_all_values (); - } - if (b->cond && value_zero) - { - cont = -1; - } - else if (b->ignore_count > 0) - { - b->ignore_count--; - cont = -1; - } - else - { - if (b->enable == temporary) - b->enable = disabled; - breakpoint_commands = b->commands; - if (b->silent - || (breakpoint_commands - && !strcmp ("silent", breakpoint_commands->line))) - { - if (breakpoint_commands) - breakpoint_commands = breakpoint_commands->next; - return (b->number > 0 ? - 0x1000000 + b->number : - b->number - 0x1000000); - } - return b->number; - } - } - } - - return cont; -} - -static void -breakpoint_1 (bnum) - int bnum; -{ - register struct breakpoint *b; - register struct command_line *l; - register struct symbol *sym; - CORE_ADDR last_addr = (CORE_ADDR)-1; - - ALL_BREAKPOINTS (b) - if (bnum == -1 || bnum == b->number) - { - printf_filtered ("#%-3d %c 0x%08x", b->number, - "nyod"[(int) b->enable], - b->address); - last_addr = b->address; - if (b->symtab) - { - sym = find_pc_function (b->address); - if (sym) - { - fputs_filtered (" in ", stdout); - fputs_demangled (SYMBOL_NAME (sym), stdout, 1); - fputs_filtered (" (", stdout); - } - fputs_filtered (b->symtab->filename, stdout); - printf_filtered (" line %d", b->line_number); - if (sym) fputs_filtered(")", stdout); - } - else - print_address_symbolic (b->address, stdout); - - printf_filtered ("\n"); - - if (b->ignore_count) - printf_filtered ("\tignore next %d hits\n", b->ignore_count); - if (b->frame) - printf_filtered ("\tstop only in stack frame at 0x%x\n", b->frame); - if (b->cond) - { - printf_filtered ("\tbreak only if "); - print_expression (b->cond, stdout); - printf_filtered ("\n"); - } - if (l = b->commands) - while (l) - { - printf_filtered ("\t%s\n", l->line); - l = l->next; - } - } - - /* Compare against (CORE_ADDR)-1 in case some compiler decides - that a comparison of an unsigned with -1 is always false. */ - if (last_addr != (CORE_ADDR)-1) - set_next_address (last_addr); -} - -static void -breakpoints_info (bnum_exp) - char *bnum_exp; -{ - int bnum = -1; - - if (bnum_exp) - bnum = parse_and_eval_address (bnum_exp); - else if (breakpoint_chain == 0) - printf_filtered ("No breakpoints.\n"); - else - printf_filtered ("Breakpoints:\n\ -Num Enb Address Where\n"); - - breakpoint_1 (bnum); -} - -/* Print a message describing any breakpoints set at PC. */ - -static void -describe_other_breakpoints (pc) - register CORE_ADDR pc; -{ - register int others = 0; - register struct breakpoint *b; - - ALL_BREAKPOINTS (b) - if (b->address == pc) - others++; - if (others > 0) - { - printf ("Note: breakpoint%s ", (others > 1) ? "s" : ""); - ALL_BREAKPOINTS (b) - if (b->address == pc) - { - others--; - printf ("%d%s%s ", - b->number, - (b->enable == disabled) ? " (disabled)" : "", - (others > 1) ? "," : ((others == 1) ? " and" : "")); - } - printf ("also set at pc 0x%x.\n", pc); - } -} - -/* Set the default place to put a breakpoint - for the `break' command with no arguments. */ - -void -set_default_breakpoint (valid, addr, symtab, line) - int valid; - CORE_ADDR addr; - struct symtab *symtab; - int line; -{ - default_breakpoint_valid = valid; - default_breakpoint_address = addr; - default_breakpoint_symtab = symtab; - default_breakpoint_line = line; -} - -/* Rescan breakpoints at address ADDRESS, - marking the first one as "first" and any others as "duplicates". - This is so that the bpt instruction is only inserted once. */ - -static void -check_duplicates (address) - CORE_ADDR address; -{ - register struct breakpoint *b; - register int count = 0; - - ALL_BREAKPOINTS (b) - if (b->enable != disabled && b->address == address) - { - count++; - b->duplicate = count > 1; - } -} - -/* Low level routine to set a breakpoint. - Takes as args the three things that every breakpoint must have. - Returns the breakpoint object so caller can set other things. - Does not set the breakpoint number! - Does not print anything. */ - -static struct breakpoint * -set_raw_breakpoint (sal) - struct symtab_and_line sal; -{ - register struct breakpoint *b, *b1; - - b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); - bzero (b, sizeof *b); - b->address = sal.pc; - b->symtab = sal.symtab; - b->line_number = sal.line; - b->enable = enabled; - b->next = 0; - b->silent = 0; - - /* Add this breakpoint to the end of the chain - so that a list of breakpoints will come out in order - of increasing numbers. */ - - b1 = breakpoint_chain; - if (b1 == 0) - breakpoint_chain = b; - else - { - while (b1->next) - b1 = b1->next; - b1->next = b; - } - - check_duplicates (sal.pc); - - return b; -} - -/* Set a breakpoint that will evaporate an end of command - at address specified by SAL. - Restrict it to frame FRAME if FRAME is nonzero. */ - -void -set_momentary_breakpoint (sal, frame) - struct symtab_and_line sal; - FRAME frame; -{ - register struct breakpoint *b; - b = set_raw_breakpoint (sal); - b->number = -3; - b->enable = delete; - b->frame = (frame ? FRAME_FP (frame) : 0); -} - -void -clear_momentary_breakpoints () -{ - register struct breakpoint *b; - ALL_BREAKPOINTS (b) - if (b->number == -3) - { - delete_breakpoint (b); - break; - } -} - -/* Set a breakpoint from a symtab and line. - If TEMPFLAG is nonzero, it is a temporary breakpoint. - Print the same confirmation messages that the breakpoint command prints. */ - -void -set_breakpoint (s, line, tempflag) - struct symtab *s; - int line; - int tempflag; -{ - register struct breakpoint *b; - struct symtab_and_line sal; - - sal.symtab = s; - sal.line = line; - sal.pc = find_line_pc (sal.symtab, sal.line); - if (sal.pc == 0) - error ("No line %d in file \"%s\".\n", sal.line, sal.symtab->filename); - else - { - describe_other_breakpoints (sal.pc); - - b = set_raw_breakpoint (sal); - b->number = ++breakpoint_count; - b->cond = 0; - if (tempflag) - b->enable = temporary; - - printf ("Breakpoint %d at 0x%x", b->number, b->address); - if (b->symtab) - printf (": file %s, line %d.", b->symtab->filename, b->line_number); - printf ("\n"); - } -} - -/* Set a breakpoint according to ARG (function, linenum or *address) - and make it temporary if TEMPFLAG is nonzero. */ - -static void -break_command_1 (arg, tempflag, from_tty) - char *arg; - int tempflag, from_tty; -{ - struct symtabs_and_lines sals; - struct symtab_and_line sal; - register struct expression *cond = 0; - register struct breakpoint *b; - char *save_arg; - int i; - CORE_ADDR pc; - - sals.sals = NULL; - sals.nelts = 0; - - sal.line = sal.pc = sal.end = 0; - sal.symtab = 0; - - /* If no arg given, or if first arg is 'if ', use the default breakpoint. */ - - if (!arg || (arg[0] == 'i' && arg[1] == 'f' - && (arg[2] == ' ' || arg[2] == '\t'))) - { - if (default_breakpoint_valid) - { - sals.sals = (struct symtab_and_line *) - malloc (sizeof (struct symtab_and_line)); - sal.pc = default_breakpoint_address; - sal.line = default_breakpoint_line; - sal.symtab = default_breakpoint_symtab; - sals.sals[0] = sal; - sals.nelts = 1; - } - else - error ("No default breakpoint address now."); - } - else - /* Force almost all breakpoints to be in terms of the - current_source_symtab (which is decode_line_1's default). This - should produce the results we want almost all of the time while - leaving default_breakpoint_* alone. */ - if (default_breakpoint_valid - && (!current_source_symtab - || (arg && (*arg == '+' || *arg == '-')))) - sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, - default_breakpoint_line); - else - sals = decode_line_1 (&arg, 1, 0, 0); - - if (! sals.nelts) - return; - - save_arg = arg; - for (i = 0; i < sals.nelts; i++) - { - sal = sals.sals[i]; - if (sal.pc == 0 && sal.symtab != 0) - { - pc = find_line_pc (sal.symtab, sal.line); - if (pc == 0) - error ("No line %d in file \"%s\".", - sal.line, sal.symtab->filename); - } - else - pc = sal.pc; - - while (arg && *arg) - { - if (arg[0] == 'i' && arg[1] == 'f' - && (arg[2] == ' ' || arg[2] == '\t')) - cond = (struct expression *) parse_c_1 ((arg += 2, &arg), - block_for_pc (pc), 0); - else - error ("Junk at end of arguments."); - } - arg = save_arg; - sals.sals[i].pc = pc; - } - - for (i = 0; i < sals.nelts; i++) - { - sal = sals.sals[i]; - - if (from_tty) - describe_other_breakpoints (sal.pc); - - b = set_raw_breakpoint (sal); - b->number = ++breakpoint_count; - b->cond = cond; - if (tempflag) - b->enable = temporary; - - printf ("Breakpoint %d at 0x%x", b->number, b->address); - if (b->symtab) - printf (": file %s, line %d.", b->symtab->filename, b->line_number); - printf ("\n"); - } - - if (sals.nelts > 1) - { - printf ("Multiple breakpoints were set.\n"); - printf ("Use the \"delete\" command to delete unwanted breakpoints.\n"); - } - free (sals.sals); -} - -static void -break_command (arg, from_tty) - char *arg; - int from_tty; -{ - break_command_1 (arg, 0, from_tty); -} - -static void -tbreak_command (arg, from_tty) - char *arg; - int from_tty; -{ - break_command_1 (arg, 1, from_tty); -} - -/* - * Helper routine for the until_command routine in infcmd.c. Here - * because it uses the mechanisms of breakpoints. - */ -void -until_break_command (arg, from_tty) - char *arg; - int from_tty; -{ - struct symtabs_and_lines sals; - struct symtab_and_line sal; - FRAME prev_frame = get_prev_frame (selected_frame); - - clear_proceed_status (); - - /* Set a breakpoint where the user wants it and at return from - this function */ - - if (default_breakpoint_valid) - sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, - default_breakpoint_line); - else - sals = decode_line_1 (&arg, 1, 0, 0); - - if (sals.nelts != 1) - error ("Couldn't get information on specified line."); - - sal = sals.sals[0]; - free (sals.sals); /* malloc'd, so freed */ - - if (*arg) - error ("Junk at end of arguments."); - - if (sal.pc == 0 && sal.symtab != 0) - sal.pc = find_line_pc (sal.symtab, sal.line); - - if (sal.pc == 0) - error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename); - - set_momentary_breakpoint (sal, selected_frame); - - /* Keep within the current frame */ - - if (prev_frame) - { - struct frame_info *fi; - - fi = get_frame_info (prev_frame); - sal = find_pc_line (fi->pc, 0); - sal.pc = fi->pc; - set_momentary_breakpoint (sal, prev_frame); - } - - proceed (-1, -1, 0); -} - -static void -clear_command (arg, from_tty) - char *arg; - int from_tty; -{ - register struct breakpoint *b, *b1; - struct symtabs_and_lines sals; - struct symtab_and_line sal; - register struct breakpoint *found; - int i; - - if (arg) - { - sals = decode_line_spec (arg, 1); - } - else - { - sals.sals = (struct symtab_and_line *) malloc (sizeof (struct symtab_and_line)); - sal.line = default_breakpoint_line; - sal.symtab = default_breakpoint_symtab; - sal.pc = 0; - if (sal.symtab == 0) - error ("No source file specified."); - - sals.sals[0] = sal; - sals.nelts = 1; - } - - for (i = 0; i < sals.nelts; i++) - { - /* If exact pc given, clear bpts at that pc. - But if sal.pc is zero, clear all bpts on specified line. */ - sal = sals.sals[i]; - found = (struct breakpoint *) 0; - while (breakpoint_chain - && (sal.pc ? breakpoint_chain->address == sal.pc - : (breakpoint_chain->symtab == sal.symtab - && breakpoint_chain->line_number == sal.line))) - { - b1 = breakpoint_chain; - breakpoint_chain = b1->next; - b1->next = found; - found = b1; - } - - ALL_BREAKPOINTS (b) - while (b->next - && (sal.pc ? b->next->address == sal.pc - : (b->next->symtab == sal.symtab - && b->next->line_number == sal.line))) - { - b1 = b->next; - b->next = b1->next; - b1->next = found; - found = b1; - } - - if (found == 0) - error ("No breakpoint at %s.", arg); - - if (found->next) from_tty = 1; /* Always report if deleted more than one */ - if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : ""); - while (found) - { - if (from_tty) printf ("%d ", found->number); - b1 = found->next; - delete_breakpoint (found); - found = b1; - } - if (from_tty) putchar ('\n'); - } - free (sals.sals); -} - -/* Delete breakpoint number BNUM if it is a `delete' breakpoint. - This is called after breakpoint BNUM has been hit. - Also delete any breakpoint numbered -3 unless there are breakpoint - commands to be executed. */ - -void -breakpoint_auto_delete (bnum) - int bnum; -{ - register struct breakpoint *b; - if (bnum != 0) - ALL_BREAKPOINTS (b) - if (b->number == bnum) - { - if (b->enable == delete) - delete_breakpoint (b); - break; - } - if (breakpoint_commands == 0) - clear_momentary_breakpoints (); -} - -static void -delete_breakpoint (bpt) - struct breakpoint *bpt; -{ - register struct breakpoint *b; - - if (bpt->inserted) - write_memory (bpt->address, bpt->shadow_contents, sizeof break_insn); - - if (breakpoint_chain == bpt) - breakpoint_chain = bpt->next; - - ALL_BREAKPOINTS (b) - if (b->next == bpt) - { - b->next = bpt->next; - break; - } - - check_duplicates (bpt->address); - - free_command_lines (bpt->commands); - if (bpt->cond) - free (bpt->cond); - - if (xgdb_verbose && bpt->number >=0) - printf ("breakpoint #%d deleted\n", bpt->number); - - free (bpt); -} - -static void map_breakpoint_numbers (); - -static void -delete_command (arg, from_tty) - char *arg; - int from_tty; -{ - register struct breakpoint *b, *b1; - - if (arg == 0) - { - /* Ask user only if there are some breakpoints to delete. */ - if (!from_tty - || breakpoint_chain && query ("Delete all breakpoints? ")) - { - /* No arg; clear all breakpoints. */ - while (breakpoint_chain) - delete_breakpoint (breakpoint_chain); - } - } - else - map_breakpoint_numbers (arg, delete_breakpoint); -} - -/* Delete all breakpoints. - Done when new symtabs are loaded, since the break condition expressions - may become invalid, and the breakpoints are probably wrong anyway. */ - -void -clear_breakpoints () -{ - delete_command (0, 0); -} - -/* Set ignore-count of breakpoint number BPTNUM to COUNT. - If from_tty is nonzero, it prints a message to that effect, - which ends with a period (no newline). */ - -void -set_ignore_count (bptnum, count, from_tty) - int bptnum, count, from_tty; -{ - register struct breakpoint *b; - - if (count < 0) - count = 0; - - ALL_BREAKPOINTS (b) - if (b->number == bptnum) - { - b->ignore_count = count; - if (!from_tty) - return; - else if (count == 0) - printf ("Will stop next time breakpoint %d is reached.", bptnum); - else if (count == 1) - printf ("Will ignore next crossing of breakpoint %d.", bptnum); - else - printf ("Will ignore next %d crossings of breakpoint %d.", - count, bptnum); - return; - } - - error ("No breakpoint number %d.", bptnum); -} - -/* Clear the ignore counts of all breakpoints. */ -void -breakpoint_clear_ignore_counts () -{ - struct breakpoint *b; - - ALL_BREAKPOINTS (b) - b->ignore_count = 0; -} - -/* Command to set ignore-count of breakpoint N to COUNT. */ - -static void -ignore_command (args, from_tty) - char *args; - int from_tty; -{ - register char *p = args; - register int num; - - if (p == 0) - error_no_arg ("a breakpoint number"); - - while (*p >= '0' && *p <= '9') p++; - if (*p && *p != ' ' && *p != '\t') - error ("First argument must be a breakpoint number."); - - num = atoi (args); - - if (*p == 0) - error ("Second argument (specified ignore-count) is missing."); - - set_ignore_count (num, parse_and_eval_address (p), from_tty); - printf ("\n"); -} - -/* Call FUNCTION on each of the breakpoints - whose numbers are given in ARGS. */ - -static void -map_breakpoint_numbers (args, function) - char *args; - void (*function) (); -{ - register char *p = args; - register char *p1; - register int num; - register struct breakpoint *b; - - if (p == 0) - error_no_arg ("one or more breakpoint numbers"); - - while (*p) - { - p1 = p; - while (*p1 >= '0' && *p1 <= '9') p1++; - if (*p1 && *p1 != ' ' && *p1 != '\t') - error ("Arguments must be breakpoint numbers."); - - num = atoi (p); - - ALL_BREAKPOINTS (b) - if (b->number == num) - { - function (b); - goto win; - } - printf ("No breakpoint number %d.\n", num); - win: - p = p1; - while (*p == ' ' || *p == '\t') p++; - } -} - -static void -enable_breakpoint (bpt) - struct breakpoint *bpt; -{ - bpt->enable = enabled; - - if (xgdb_verbose && bpt->number >= 0) - printf ("breakpoint #%d enabled\n", bpt->number); - - check_duplicates (bpt->address); -} - -static void -enable_command (args) - char *args; -{ - struct breakpoint *bpt; - if (args == 0) - ALL_BREAKPOINTS (bpt) - enable_breakpoint (bpt); - else - map_breakpoint_numbers (args, enable_breakpoint); -} - -static void -disable_breakpoint (bpt) - struct breakpoint *bpt; -{ - bpt->enable = disabled; - - if (xgdb_verbose && bpt->number >= 0) - printf ("breakpoint #%d disabled\n", bpt->number); - - check_duplicates (bpt->address); -} - -static void -disable_command (args) - char *args; -{ - register struct breakpoint *bpt; - if (args == 0) - ALL_BREAKPOINTS (bpt) - disable_breakpoint (bpt); - else - map_breakpoint_numbers (args, disable_breakpoint); -} - -static void -enable_once_breakpoint (bpt) - struct breakpoint *bpt; -{ - bpt->enable = temporary; - - check_duplicates (bpt->address); -} - -static void -enable_once_command (args) - char *args; -{ - map_breakpoint_numbers (args, enable_once_breakpoint); -} - -static void -enable_delete_breakpoint (bpt) - struct breakpoint *bpt; -{ - bpt->enable = delete; - - check_duplicates (bpt->address); -} - -static void -enable_delete_command (args) - char *args; -{ - map_breakpoint_numbers (args, enable_delete_breakpoint); -} - -/* - * Use default_breakpoint_'s, or nothing if they aren't valid. - */ -struct symtabs_and_lines -decode_line_spec_1 (string, funfirstline) - char *string; - int funfirstline; -{ - struct symtabs_and_lines sals; - if (string == 0) - error ("Empty line specification."); - if (default_breakpoint_valid) - sals = decode_line_1 (&string, funfirstline, - default_breakpoint_symtab, default_breakpoint_line); - else - sals = decode_line_1 (&string, funfirstline, 0, 0); - if (*string) - error ("Junk at end of line specification: %s", string); - return sals; -} - - -/* Chain containing all defined enable commands. */ - -extern struct cmd_list_element - *enablelist, *disablelist, - *deletelist, *enablebreaklist; - -extern struct cmd_list_element *cmdlist; - -void -_initialize_breakpoint () -{ - breakpoint_chain = 0; - breakpoint_count = 0; - - add_com ("ignore", class_breakpoint, ignore_command, - "Set ignore-count of breakpoint number N to COUNT."); - - add_com ("commands", class_breakpoint, commands_command, - "Set commands to be executed when a breakpoint is hit.\n\ -Give breakpoint number as argument after \"commands\".\n\ -With no argument, the targeted breakpoint is the last one set.\n\ -The commands themselves follow starting on the next line.\n\ -Type a line containing \"end\" to indicate the end of them.\n\ -Give \"silent\" as the first line to make the breakpoint silent;\n\ -then no output is printed when it is hit, except what the commands print."); - - add_com ("condition", class_breakpoint, condition_command, - "Specify breakpoint number N to break only if COND is true.\n\ -N is an integer; COND is a C expression to be evaluated whenever\n\ -breakpoint N is reached. Actually break only when COND is nonzero."); - - add_com ("tbreak", class_breakpoint, tbreak_command, - "Set a temporary breakpoint. Args like \"break\" command.\n\ -Like \"break\" except the breakpoint is only enabled temporarily,\n\ -so it will be disabled when hit. Equivalent to \"break\" followed\n\ -by using \"enable once\" on the breakpoint number."); - - add_prefix_cmd ("enable", class_breakpoint, enable_command, - "Enable some breakpoints or auto-display expressions.\n\ -Give breakpoint numbers (separated by spaces) as arguments.\n\ -With no subcommand, breakpoints are enabled until you command otherwise.\n\ -This is used to cancel the effect of the \"disable\" command.\n\ -With a subcommand you can enable temporarily.\n\ -\n\ -The \"display\" subcommand applies to auto-displays instead of breakpoints.", - &enablelist, "enable ", 1, &cmdlist); - - add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, - "Enable some breakpoints or auto-display expressions.\n\ -Give breakpoint numbers (separated by spaces) as arguments.\n\ -With no subcommand, breakpoints are enabled until you command otherwise.\n\ -This is used to cancel the effect of the \"disable\" command.\n\ -May be abbreviates to simply \"enable\".\n\ -With a subcommand you can enable temporarily.", - &enablebreaklist, "enable breakpoints ", 1, &enablelist); - - add_cmd ("once", no_class, enable_once_command, - "Enable breakpoints for one hit. Give breakpoint numbers.\n\ -If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\ -See the \"tbreak\" command which sets a breakpoint and enables it once.", - &enablebreaklist); - - add_cmd ("delete", no_class, enable_delete_command, - "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ -If a breakpoint is hit while enabled in this fashion, it is deleted.", - &enablebreaklist); - - add_cmd ("delete", no_class, enable_delete_command, - "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ -If a breakpoint is hit while enabled in this fashion, it is deleted.", - &enablelist); - - add_cmd ("once", no_class, enable_once_command, - "Enable breakpoints for one hit. Give breakpoint numbers.\n\ -If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\ -See the \"tbreak\" command which sets a breakpoint and enables it once.", - &enablelist); - - add_prefix_cmd ("disable", class_breakpoint, disable_command, - "Disable some breakpoints or auto-display expressions.\n\ -Arguments are breakpoint numbers with spaces in between.\n\ -To disable all breakpoints, give no argument.\n\ -A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ -\n\ -The \"display\" subcommand applies to auto-displays instead of breakpoints.", - &disablelist, "disable ", 1, &cmdlist); - add_com_alias ("dis", "disable", class_breakpoint, 1); - add_com_alias ("disa", "disable", class_breakpoint, 1); - - add_abbrev_cmd ("breakpoints", class_breakpoint, disable_command, - "Disable some breakpoints or auto-display expressions.\n\ -Arguments are breakpoint numbers with spaces in between.\n\ -To disable all breakpoints, give no argument.\n\ -A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ -This command may be abbreviated \"disable\".", - &disablelist); - - add_prefix_cmd ("delete", class_breakpoint, delete_command, - "Delete some breakpoints or auto-display expressions.\n\ -Arguments are breakpoint numbers with spaces in between.\n\ -To delete all breakpoints, give no argument.\n\ -\n\ -Also a prefix command for deletion of other GDB objects.\n\ -The \"unset\" command is also an alias for \"delete\".", - &deletelist, "delete ", 1, &cmdlist); - add_com_alias ("d", "delete", class_breakpoint, 1); - add_com_alias ("unset", "delete", class_alias, 1); - - add_cmd ("breakpoints", class_alias, delete_command, - "Delete some breakpoints or auto-display expressions.\n\ -Arguments are breakpoint numbers with spaces in between.\n\ -To delete all breakpoints, give no argument.\n\ -This command may be abbreviated \"delete\".", - &deletelist); - - add_com ("clear", class_breakpoint, clear_command, - "Clear breakpoint at specified line or function.\n\ -Argument may be line number, function name, or \"*\" and an address.\n\ -If line number is specified, all breakpoints in that line are cleared.\n\ -If function is specified, breakpoints at beginning of function are cleared.\n\ -If an address is specified, breakpoints at that address are cleared.\n\n\ -With no argument, clears all breakpoints in the line that the selected frame\n\ -is executing in.\n\ -\n\ -See also the \"delete\" command which clears breakpoints by number."); - - add_com ("break", class_breakpoint, break_command, - "Set breakpoint at specified line or function.\n\ -Argument may be line number, function name, or \"*\" and an address.\n\ -If line number is specified, break at start of code for that line.\n\ -If function is specified, break at start of code for that function.\n\ -If an address is specified, break at that exact address.\n\ -With no arg, uses current execution address of selected stack frame.\n\ -This is useful for breaking on return to a stack frame.\n\ -\n\ -Multiple breakpoints at one place are permitted, and useful if conditional.\n\ -\n\ -Do \"help breakpoints\" for info on other commands dealing with breakpoints."); - add_com_alias ("b", "break", class_run, 1); - add_com_alias ("br", "break", class_run, 1); - add_com_alias ("bre", "break", class_run, 1); - add_com_alias ("brea", "break", class_run, 1); - - add_info ("breakpoints", breakpoints_info, - "Status of all breakpoints, or breakpoint number NUMBER.\n\ -Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\ -\"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\ -Then come the address and the file/line number.\n\n\ -Convenience variable \"$_\" and default examine address for \"x\"\n\ -are set to the address of the last breakpoint listed."); -} - diff --git a/gnu/usr.bin/gdb/command.c b/gnu/usr.bin/gdb/command.c deleted file mode 100644 index 79daea4..0000000 --- a/gnu/usr.bin/gdb/command.c +++ /dev/null @@ -1,856 +0,0 @@ -/* Library for reading command lines and decoding commands. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - - 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 1, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "command.h" -#include "defs.h" -#include -#include - -extern char *xmalloc (); - -/* Add element named NAME to command list *LIST. - FUN should be the function to execute the command; - it will get a character string as argument, with leading - and trailing blanks already eliminated. - - DOC is a documentation string for the command. - Its first line should be a complete sentence. - It should start with ? for a command that is an abbreviation - or with * for a command that most users don't need to know about. */ - -struct cmd_list_element * -add_cmd (name, class, fun, doc, list) - char *name; - int class; - void (*fun) (); - char *doc; - struct cmd_list_element **list; -{ - register struct cmd_list_element *c - = (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element)); - - delete_cmd (name, list); - c->next = *list; - c->name = savestring (name, strlen (name)); - c->class = class; - c->function = fun; - c->doc = doc; - c->prefixlist = 0; - c->allow_unknown = 0; - c->abbrev_flag = 0; - c->aux = 0; - *list = c; - return c; -} - -/* Same as above, except that the abbrev_flag is set. */ - -struct cmd_list_element * -add_abbrev_cmd (name, class, fun, doc, list) - char *name; - int class; - void (*fun) (); - char *doc; - struct cmd_list_element **list; -{ - register struct cmd_list_element *c - = (struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element)); - - delete_cmd (name, list); - c->next = *list; - c->name = savestring (name, strlen (name)); - c->class = class; - c->function = fun; - c->doc = doc; - c->prefixlist = 0; - c->allow_unknown = 0; - c->abbrev_flag = 1; - c->aux = 0; - *list = c; - return c; -} - -struct cmd_list_element * -add_alias_cmd (name, oldname, class, abbrev_flag, list) - char *name; - char *oldname; - int class; - int abbrev_flag; - struct cmd_list_element **list; -{ - /* Must do this since lookup_cmd tries to side-effect its first arg */ - char *copied_name; - register struct cmd_list_element *old; - register struct cmd_list_element *c; - copied_name = (char *) alloca (strlen (oldname) + 1); - strcpy (copied_name, oldname); - old = lookup_cmd (&copied_name, *list, 0, 1, 1); - - if (old == 0) - { - delete_cmd (name, list); - return 0; - } - - c = add_cmd (name, class, old->function, old->doc, list); - c->prefixlist = old->prefixlist; - c->prefixname = old->prefixname; - c->allow_unknown = old->allow_unknown; - c->abbrev_flag = abbrev_flag; - c->aux = old->aux; - return c; -} - -/* Like add_cmd but adds an element for a command prefix: - a name that should be followed by a subcommand to be looked up - in another command list. PREFIXLIST should be the address - of the variable containing that list. */ - -struct cmd_list_element * -add_prefix_cmd (name, class, fun, doc, prefixlist, prefixname, - allow_unknown, list) - char *name; - int class; - void (*fun) (); - char *doc; - struct cmd_list_element **prefixlist; - char *prefixname; - int allow_unknown; - struct cmd_list_element **list; -{ - register struct cmd_list_element *c = add_cmd (name, class, fun, doc, list); - c->prefixlist = prefixlist; - c->prefixname = prefixname; - c->allow_unknown = allow_unknown; - return c; -} - -/* Like add_prefix_cmd butsets the abbrev_flag on the new command. */ - -struct cmd_list_element * -add_abbrev_prefix_cmd (name, class, fun, doc, prefixlist, prefixname, - allow_unknown, list) - char *name; - int class; - void (*fun) (); - char *doc; - struct cmd_list_element **prefixlist; - char *prefixname; - int allow_unknown; - struct cmd_list_element **list; -{ - register struct cmd_list_element *c = add_cmd (name, class, fun, doc, list); - c->prefixlist = prefixlist; - c->prefixname = prefixname; - c->allow_unknown = allow_unknown; - c->abbrev_flag = 1; - return c; -} - -/* Remove the command named NAME from the command list. */ - -void -delete_cmd (name, list) - char *name; - struct cmd_list_element **list; -{ - register struct cmd_list_element *c; - - while (*list && !strcmp ((*list)->name, name)) - { - *list = (*list)->next; - } - - if (*list) - for (c = *list; c->next;) - { - if (!strcmp (c->next->name, name)) - c->next = c->next->next; - else - c = c->next; - } -} - -void help_cmd (), help_list (), help_cmd_list (); - -/* This command really has to deal with two things: - * 1) I want documentation on *this string* (usually called by - * "help commandname"). - * 2) I want documentation on *this list* (usually called by - * giving a command that requires subcommands. Also called by saying - * just "help".) - * - * I am going to split this into two seperate comamnds, help_cmd and - * help_list. - */ - -void -help_cmd (command, stream) - char *command; - FILE *stream; -{ - struct cmd_list_element *c; - extern struct cmd_list_element *cmdlist; - - if (!command) - { - help_list (cmdlist, "", -2, stream); - return; - } - - c = lookup_cmd (&command, cmdlist, "", 0, 0); - - if (c == 0) - return; - - /* There are three cases here. - If c->prefixlist is nonzer, we have a prefix command. - Print its documentation, then list its subcommands. - - If c->function is nonzero, we really have a command. - Print its documentation and return. - - If c->function is zero, we have a class name. - Print its documentation (as if it were a command) - and then set class to he number of this class - so that the commands in the class will be listed. */ - - fputs_filtered (c->doc, stream); - fputs_filtered ("\n", stream); - - if (c->prefixlist == 0 && c->function != 0) - return; - fprintf_filtered (stream, "\n"); - - /* If this is a prefix command, print it's subcommands */ - if (c->prefixlist) - help_list (*c->prefixlist, c->prefixname, -1, stream); - - /* If this is a class name, print all of the commands in the class */ - if (c->function == 0) - help_list (cmdlist, "", c->class, stream); -} - -/* - * Get a specific kind of help on a command list. - * - * LIST is the list. - * CMDTYPE is the prefix to use in the title string. - * CLASS is the class with which to list the nodes of this list (see - * documentation for help_cmd_list below), As usual, -1 for - * everything, -2 for just classes, and non-negative for only things - * in a specific class. - * and STREAM is the output stream on which to print things. - * If you call this routine with a class >= 0, it recurses. - */ -void -help_list (list, cmdtype, class, stream) - struct cmd_list_element *list; - char *cmdtype; - int class; - FILE *stream; -{ - int len; - char *cmdtype1, *cmdtype2; - - /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */ - len = strlen (cmdtype); - cmdtype1 = (char *) alloca (len + 1); - cmdtype1[0] = 0; - cmdtype2 = (char *) alloca (len + 4); - cmdtype2[0] = 0; - if (len) - { - cmdtype1[0] = ' '; - strncpy (cmdtype1 + 1, cmdtype, len - 1); - cmdtype1[len] = 0; - strncpy (cmdtype2, cmdtype, len - 1); - strcpy (cmdtype2 + len - 1, " sub"); - } - - if (class == -2) - fprintf_filtered (stream, "List of classes of %scommands:\n\n", cmdtype2); - else - fprintf_filtered (stream, "List of %scommands:\n\n", cmdtype2); - - help_cmd_list (list, class, cmdtype, (class >= 0), stream); - - if (class == -2) - fprintf_filtered (stream, "\n\ -Type \"help%s\" followed by a class name for a list of commands in that class.", - cmdtype1); - - fprintf_filtered (stream, "\n\ -Type \"help%s\" followed by %scommand name for full documentation.\n\ -Command name abbreviations are allowed if unambiguous.\n", - cmdtype1, cmdtype2); -} - - -/* - * Implement a help command on command list LIST. - * RECURSE should be non-zero if this should be done recursively on - * all sublists of LIST. - * PREFIX is the prefix to print before each command name. - * STREAM is the stream upon which the output should be written. - * CLASS should be: - * A non-negative class number to list only commands in that - * class. - * -1 to list all commands in list. - * -2 to list all classes in list. - * - * Note that RECURSE will be active on *all* sublists, not just the - * ones seclected by the criteria above (ie. the selection mechanism - * is at the low level, not the high-level). - */ -void -help_cmd_list (list, class, prefix, recurse, stream) - struct cmd_list_element *list; - int class; - char *prefix; - int recurse; - FILE *stream; -{ - register struct cmd_list_element *c; - register char *p; - static char *line_buffer = 0; - static int line_size; - - if (!line_buffer) - { - line_size = 80; - line_buffer = (char *) xmalloc (line_size); - } - - for (c = list; c; c = c->next) - { - if (c->abbrev_flag == 0 && - (class == -1 - || (class == -2 && c->function == 0) - || (class == c->class && c->function != 0))) - { - fprintf_filtered (stream, "%s%s -- ", prefix, c->name); - /* Print just the first line */ - p = c->doc; - while (*p && *p != '\n') p++; - if (p - c->doc > line_size - 1) - { - line_size = p - c->doc + 1; - free (line_buffer); - line_buffer = (char *) xmalloc (line_size); - } - strncpy (line_buffer, c->doc, p - c->doc); - line_buffer[p - c->doc] = '\0'; - fputs_filtered (line_buffer, stream); - fputs_filtered ("\n", stream); - } - if (recurse - && c->prefixlist != 0 - && c->abbrev_flag == 0) - help_cmd_list (*c->prefixlist, class, c->prefixname, 1, stream); - } -} - -/* This routine takes a line of TEXT and a CLIST in which to - start the lookup. When it returns it will have incremented the text - pointer past the section of text it matched, set *RESULT_LIST to - the list in which the last word was matched, and will return the - cmd list element which the text matches. It will return 0 if no - match at all was possible. It will return -1 if ambigous matches are - possible; in this case *RESULT_LIST will be set to the list in which - there are ambiguous choices (and text will be set to the ambiguous - text string). - - It does no error reporting whatsoever; control will always return - to the superior routine. - - In the case of an ambiguous return (-1), *RESULT_LIST will be set to - point at the prefix_command (ie. the best match) *or* (special - case) will be 0 if no prefix command was ever found. For example, - in the case of "info a", "info" matches without ambiguity, but "a" - could be "args" or "address", so *RESULT_LIST is set to - the cmd_list_element for "info". So in this case - result list should not be interpeted as a pointer to the beginning - of a list; it simply points to a specific command. - - This routine does *not* modify the text pointed to by TEXT. - - If INGNORE_HELP_CLASSES is nonzero, ignore any command list - elements which are actually help classes rather than commands (i.e. - the function field of the struct cmd_list_element is 0). */ - -struct cmd_list_element * -lookup_cmd_1 (text, clist, result_list, ignore_help_classes) - char **text; - struct cmd_list_element *clist, **result_list; - int ignore_help_classes; -{ - char *p, *command; - int len, tmp, nfound; - struct cmd_list_element *found, *c; - - while (**text == ' ' || **text == '\t') - (*text)++; - - /* Treating underscores as part of command words is important - so that "set args_foo()" doesn't get interpreted as - "set args _foo()". */ - for (p = *text; - *p && (isalnum(*p) || *p == '-' || *p == '_'); - p++) - ; - - /* If nothing but whitespace, return 0. */ - if (p == *text) - return 0; - - len = p - *text; - - /* *text and p now bracket the first command word to lookup (and - it's length is len). We copy this into a local temporary, - converting to lower case as we go. */ - - command = (char *) alloca (len + 1); - for (tmp = 0; tmp < len; tmp++) - { - char x = (*text)[tmp]; - command[tmp] = (x >= 'A' && x <= 'Z') ? x - 'A' + 'a' : x; - } - command[len] = '\0'; - - /* Look it up. */ - found = 0; - nfound = 0; - for (c = clist; c; c = c->next) - if (!strncmp (command, c->name, len) - && (!ignore_help_classes || c->function)) - { - found = c; - nfound++; - if (c->name[len] == '\0') - { - nfound = 1; - break; - } - } - - /* If nothing matches, we have a simple failure. */ - if (nfound == 0) - return 0; - - if (nfound > 1) - { - *result_list = 0; /* Will be modified in calling routine - if we know what the prefix command is. - */ - return (struct cmd_list_element *) -1; /* Ambiguous. */ - } - - /* We've matched something on this list. Move text pointer forward. */ - - *text = p; - if (found->prefixlist) - { - c = lookup_cmd_1 (text, *found->prefixlist, result_list, - ignore_help_classes); - if (!c) - { - /* Didn't find anything; this is as far as we got. */ - *result_list = clist; - return found; - } - else if (c == (struct cmd_list_element *) -1) - { - /* We've gotten this far properley, but the next step - is ambiguous. We need to set the result list to the best - we've found (if an inferior hasn't already set it). */ - if (!*result_list) - /* This used to say *result_list = *found->prefixlist - If that was correct, need to modify the documentation - at the top of this function to clarify what is supposed - to be going on. */ - *result_list = found; - return c; - } - else - { - /* We matched! */ - return c; - } - } - else - { - *result_list = clist; - return found; - } -} - -/* Look up the contents of *LINE as a command in the command list LIST. - LIST is a chain of struct cmd_list_element's. - If it is found, return the struct cmd_list_element for that command - and update *LINE to point after the command name, at the first argument. - If not found, call error if ALLOW_UNKNOWN is zero - otherwise (or if error returns) return zero. - Call error if specified command is ambiguous, - unless ALLOW_UNKNOWN is negative. - CMDTYPE precedes the word "command" in the error message. - - If INGNORE_HELP_CLASSES is nonzero, ignore any command list - elements which are actually help classes rather than commands (i.e. - the function field of the struct cmd_list_element is 0). */ - -struct cmd_list_element * -lookup_cmd (line, list, cmdtype, allow_unknown, ignore_help_classes) - char **line; - struct cmd_list_element *list; - char *cmdtype; - int allow_unknown; - int ignore_help_classes; -{ - struct cmd_list_element *last_list = 0; - struct cmd_list_element *c = - lookup_cmd_1 (line, list, &last_list, ignore_help_classes); - char *ptr = (*line) + strlen (*line) - 1; - - /* Clear off trailing whitespace. */ - while (ptr >= *line && (*ptr == ' ' || *ptr == '\t')) - ptr--; - *(ptr + 1) = '\0'; - - if (!c) - { - if (!allow_unknown) - { - if (!*line) - error ("Lack of needed %scommand", cmdtype); - else - { - char *p = *line, *q; - - while (isalnum(*p) || *p == '-') - p++; - - q = (char *) alloca (p - *line + 1); - strncpy (q, *line, p - *line); - q[p-*line] = '\0'; - - error ("Undefined %scommand: \"%s\".", cmdtype, q); - } - } - else - return 0; - } - else if (c == (struct cmd_list_element *) -1) - { - /* Ambigous. Local values should be off prefixlist or called - values. */ - int local_allow_unknown = (last_list ? last_list->allow_unknown : - allow_unknown); - char *local_cmdtype = last_list ? last_list->prefixname : cmdtype; - struct cmd_list_element *local_list = - (last_list ? *(last_list->prefixlist) : list); - - if (local_allow_unknown < 0) - { - if (last_list) - return last_list; /* Found something. */ - else - return 0; /* Found nothing. */ - } - else - { - /* Report as error. */ - int amb_len; - char ambbuf[100]; - - for (amb_len = 0; - ((*line)[amb_len] && (*line)[amb_len] != ' ' - && (*line)[amb_len] != '\t'); - amb_len++) - ; - - ambbuf[0] = 0; - for (c = local_list; c; c = c->next) - if (!strncmp (*line, c->name, amb_len)) - { - if (strlen (ambbuf) + strlen (c->name) + 6 < sizeof ambbuf) - { - if (strlen (ambbuf)) - strcat (ambbuf, ", "); - strcat (ambbuf, c->name); - } - else - { - strcat (ambbuf, ".."); - break; - } - } - error ("Ambiguous %scommand \"%s\": %s.", local_cmdtype, - *line, ambbuf); - } - } - else - { - /* We've got something. It may still not be what the caller - wants (if this command *needs* a subcommand). */ - while (**line == ' ' || **line == '\t') - (*line)++; - - if (c->prefixlist && **line && !c->allow_unknown) - error ("Undefined %scommand: \"%s\".", c->prefixname, *line); - - /* Seems to be what he wants. Return it. */ - return c; - } -} - -#if 0 -/* Look up the contents of *LINE as a command in the command list LIST. - LIST is a chain of struct cmd_list_element's. - If it is found, return the struct cmd_list_element for that command - and update *LINE to point after the command name, at the first argument. - If not found, call error if ALLOW_UNKNOWN is zero - otherwise (or if error returns) return zero. - Call error if specified command is ambiguous, - unless ALLOW_UNKNOWN is negative. - CMDTYPE precedes the word "command" in the error message. */ - -struct cmd_list_element * -lookup_cmd (line, list, cmdtype, allow_unknown) - char **line; - struct cmd_list_element *list; - char *cmdtype; - int allow_unknown; -{ - register char *p; - register struct cmd_list_element *c, *found; - int nfound; - char ambbuf[100]; - char *processed_cmd; - int i, cmd_len; - - /* Skip leading whitespace. */ - - while (**line == ' ' || **line == '\t') - (*line)++; - - /* Clear out trailing whitespace. */ - - p = *line + strlen (*line); - while (p != *line && (p[-1] == ' ' || p[-1] == '\t')) - p--; - *p = 0; - - /* Find end of command name. */ - - p = *line; - while (*p == '-' - || (*p >= 'a' && *p <= 'z') - || (*p >= 'A' && *p <= 'Z') - || (*p >= '0' && *p <= '9')) - p++; - - /* Look up the command name. - If exact match, keep that. - Otherwise, take command abbreviated, if unique. Note that (in my - opinion) a null string does *not* indicate ambiguity; simply the - end of the argument. */ - - if (p == *line) - { - if (!allow_unknown) - error ("Lack of needed %scommand", cmdtype); - return 0; - } - - /* Copy over to a local buffer, converting to lowercase on the way. - This is in case the command being parsed is a subcommand which - doesn't match anything, and that's ok. We want the original - untouched for the routine of the original command. */ - - processed_cmd = (char *) alloca (p - *line + 1); - for (cmd_len = 0; cmd_len < p - *line; cmd_len++) - { - char x = (*line)[cmd_len]; - if (x >= 'A' && x <= 'Z') - processed_cmd[cmd_len] = x - 'A' + 'a'; - else - processed_cmd[cmd_len] = x; - } - processed_cmd[cmd_len] = '\0'; - - /* Check all possibilities in the current command list. */ - found = 0; - nfound = 0; - for (c = list; c; c = c->next) - { - if (!strncmp (processed_cmd, c->name, cmd_len)) - { - found = c; - nfound++; - if (c->name[cmd_len] == 0) - { - nfound = 1; - break; - } - } - } - - /* Report error for undefined command name. */ - - if (nfound != 1) - { - if (nfound > 1 && allow_unknown >= 0) - { - ambbuf[0] = 0; - for (c = list; c; c = c->next) - if (!strncmp (processed_cmd, c->name, cmd_len)) - { - if (strlen (ambbuf) + strlen (c->name) + 6 < sizeof ambbuf) - { - if (strlen (ambbuf)) - strcat (ambbuf, ", "); - strcat (ambbuf, c->name); - } - else - { - strcat (ambbuf, ".."); - break; - } - } - error ("Ambiguous %scommand \"%s\": %s.", cmdtype, - processed_cmd, ambbuf); - } - else if (!allow_unknown) - error ("Undefined %scommand: \"%s\".", cmdtype, processed_cmd); - return 0; - } - - /* Skip whitespace before the argument. */ - - while (*p == ' ' || *p == '\t') p++; - *line = p; - - if (found->prefixlist && *p) - { - c = lookup_cmd (line, *found->prefixlist, found->prefixname, - found->allow_unknown); - if (c) - return c; - } - - return found; -} -#endif - -/* Helper function for SYMBOL_COMPLETION_FUNCTION. */ - -/* Return a vector of char pointers which point to the different - possible completions in LIST of TEXT. */ - -char ** -complete_on_cmdlist (list, text) - struct cmd_list_element *list; - char *text; -{ - struct cmd_list_element *ptr; - char **matchlist; - int sizeof_matchlist; - int matches; - int textlen = strlen (text); - - sizeof_matchlist = 10; - matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *)); - matches = 0; - - for (ptr = list; ptr; ptr = ptr->next) - if (!strncmp (ptr->name, text, textlen) - && !ptr->abbrev_flag - && (ptr->function - || ptr->prefixlist)) - { - if (matches == sizeof_matchlist) - { - sizeof_matchlist *= 2; - matchlist = (char **) xrealloc (matchlist, - (sizeof_matchlist - * sizeof (char *))); - } - - matchlist[matches] = (char *) - xmalloc (strlen (ptr->name) + 1); - strcpy (matchlist[matches++], ptr->name); - } - - if (matches == 0) - { - free (matchlist); - matchlist = 0; - } - else - { - matchlist = (char **) xrealloc (matchlist, ((matches + 1) - * sizeof (char *))); - matchlist[matches] = (char *) 0; - } - - return matchlist; -} - -static void -shell_escape (arg, from_tty) - char *arg; - int from_tty; -{ - int rc, status, pid; - char *p, *user_shell; - extern char *rindex (); - - if ((user_shell = (char *) getenv ("SHELL")) == NULL) - user_shell = "/bin/sh"; - - /* Get the name of the shell for arg0 */ - if ((p = rindex (user_shell, '/')) == NULL) - p = user_shell; - else - p++; /* Get past '/' */ - - if ((pid = fork()) == 0) - { - if (!arg) - execl (user_shell, p, 0); - else - execl (user_shell, p, "-c", arg, 0); - - fprintf (stderr, "Exec of shell failed\n"); - exit (0); - } - - if (pid != -1) - while ((rc = wait (&status)) != pid && rc != -1) - ; - else - error ("Fork failed"); -} - -void -_initialize_command () -{ - add_com ("shell", class_support, shell_escape, - "Execute the rest of the line as a shell command. \n\ -With no arguments, run an inferior shell."); -} diff --git a/gnu/usr.bin/gdb/command.h b/gnu/usr.bin/gdb/command.h deleted file mode 100644 index fe28aef..0000000 --- a/gnu/usr.bin/gdb/command.h +++ /dev/null @@ -1,77 +0,0 @@ -/* Header file for command-reading library command.c. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - - 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 1, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* This structure records one command'd definition. */ - -struct cmd_list_element - { - /* Points to next command in this list. */ - struct cmd_list_element *next; - - /* Name of this command. */ - char *name; - - /* Command class; class values are chosen by application program. */ - int class; - - /* Function definition of this command. - Zero for command class names and for help topics that - are not really commands. */ - void (*function) (); - - /* Documentation of this command (or help topic). - First line is brief documentation; remaining lines form, with it, - the full documentation. First line should end with a period. - Entire string should also end with a period, not a newline. */ - char *doc; - - /* Auxiliary information. - It is up to the calling program to decide what this means. */ - char *aux; - - /* Nonzero identifies a prefix command. For them, the address - of the variable containing the list of subcommands. */ - struct cmd_list_element **prefixlist; - - /* For prefix commands only: - String containing prefix commands to get here: this one - plus any others needed to get to it. Should end in a space. - It is used before the word "command" in describing the - commands reached through this prefix. */ - char *prefixname; - - /* For prefix commands only: - nonzero means do not get an error if subcommand is not - recognized; call the prefix's own function in that case. */ - char allow_unknown; - - /* Nonzero says this is an abbreviation, and should not - be mentioned in lists of commands. - This allows "br" to complete to "break", which it - otherwise wouldn't. */ - char abbrev_flag; - }; - -/* Forward-declarations of the entry-points of command.c. */ - -extern struct cmd_list_element *add_cmd (); -extern struct cmd_list_element *add_alias_cmd (); -extern struct cmd_list_element *add_prefix_cmd (); -extern struct cmd_list_element *lookup_cmd (), *lookup_cmd_1 (); -extern char **complete_on_cmdlist (); -extern void delete_cmd (); -extern void help_cmd (); diff --git a/gnu/usr.bin/gdb/config/Makefile.i386 b/gnu/usr.bin/gdb/config/Makefile.i386 deleted file mode 100644 index cc52aa3..0000000 --- a/gnu/usr.bin/gdb/config/Makefile.i386 +++ /dev/null @@ -1,6 +0,0 @@ -# @(#)Makefile.i386 6.2 (Berkeley) 3/21/91 - -CONFIGSRCS= i386bsd-dep.c i386-pinsn.c - -param.h: - ln -s $(.CURDIR)/config/m-i386bsd.h param.h diff --git a/gnu/usr.bin/gdb/config/default-dep.c b/gnu/usr.bin/gdb/config/default-dep.c deleted file mode 100644 index 13fe7b9..0000000 --- a/gnu/usr.bin/gdb/config/default-dep.c +++ /dev/null @@ -1,585 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - */ - -#ifndef lint -static char sccsid[] = "@(#)default-dep.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Low level interface to ptrace, for GDB when running under Unix. - Copyright (C) 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "frame.h" -#include "inferior.h" - -#ifdef USG -#include -#endif - -#include -#include -#include -#include -/* #include Can we live without this? */ - -#ifdef COFF_ENCAPSULATE -#include "a.out.encap.h" -#else -#include -#endif -#ifndef N_SET_MAGIC -#define N_SET_MAGIC(exec, val) ((exec).a_magic = (val)) -#endif - -#include /* After a.out.h */ -#include -#include - -extern int errno; - -/* This function simply calls ptrace with the given arguments. - It exists so that all calls to ptrace are isolated in this - machine-dependent file. */ -int -call_ptrace (request, pid, arg3, arg4) - int request, pid, arg3, arg4; -{ - return ptrace (request, pid, arg3, arg4); -} - -kill_inferior () -{ - if (remote_debugging) - return; - if (inferior_pid == 0) - return; - ptrace (8, inferior_pid, 0, 0); - wait (0); - inferior_died (); -} - -/* This is used when GDB is exiting. It gives less chance of error.*/ - -kill_inferior_fast () -{ - if (remote_debugging) - return; - if (inferior_pid == 0) - return; - ptrace (8, inferior_pid, 0, 0); - wait (0); -} - -/* Resume execution of the inferior process. - If STEP is nonzero, single-step it. - If SIGNAL is nonzero, give it that signal. */ - -void -resume (step, signal) - int step; - int signal; -{ - errno = 0; - if (remote_debugging) - remote_resume (step, signal); - else - { - ptrace (step ? 9 : 7, inferior_pid, 1, signal); - if (errno) - perror_with_name ("ptrace"); - } -} - -void -fetch_inferior_registers () -{ - register int regno; - register unsigned int regaddr; - char buf[MAX_REGISTER_RAW_SIZE]; - register int i; - - struct user u; - unsigned int offset = (char *) &u.u_ar0 - (char *) &u; - offset = ptrace (3, inferior_pid, offset, 0) - KERNEL_U_ADDR; - - for (regno = 0; regno < NUM_REGS; regno++) - { - regaddr = register_addr (regno, offset); - for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int)) - { - *(int *) &buf[i] = ptrace (3, inferior_pid, regaddr, 0); - regaddr += sizeof (int); - } - supply_register (regno, buf); - } -} - -/* Store our register values back into the inferior. - If REGNO is -1, do this for all registers. - Otherwise, REGNO specifies which register (so we can save time). */ - -store_inferior_registers (regno) - int regno; -{ - register unsigned int regaddr; - char buf[80]; - - struct user u; - unsigned int offset = (char *) &u.u_ar0 - (char *) &u; - offset = ptrace (3, inferior_pid, offset, 0) - KERNEL_U_ADDR; - - if (regno >= 0) - { - regaddr = register_addr (regno, offset); - errno = 0; - ptrace (6, inferior_pid, regaddr, read_register (regno)); - if (errno != 0) - { - sprintf (buf, "writing register number %d", regno); - perror_with_name (buf); - } - } - else for (regno = 0; regno < NUM_REGS; regno++) - { - regaddr = register_addr (regno, offset); - errno = 0; - ptrace (6, inferior_pid, regaddr, read_register (regno)); - if (errno != 0) - { - sprintf (buf, "writing all regs, number %d", regno); - perror_with_name (buf); - } - } -} - -/* Copy LEN bytes from inferior's memory starting at MEMADDR - to debugger memory starting at MYADDR. - On failure (cannot read from inferior, usually because address is out - of bounds) returns the value of errno. */ - -int -read_inferior_memory (memaddr, myaddr, len) - CORE_ADDR memaddr; - char *myaddr; - int len; -{ - register int i; - /* Round starting address down to longword boundary. */ - register CORE_ADDR addr = memaddr & - sizeof (int); - /* Round ending address up; get number of longwords that makes. */ - register int count - = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int); - /* Allocate buffer of that many longwords. */ - register int *buffer = (int *) alloca (count * sizeof (int)); - extern int errno; - - /* Read all the longwords */ - for (i = 0; i < count; i++, addr += sizeof (int)) - { - errno = 0; -#if 0 - /* This is now done by read_memory, because when this function did it, - reading a byte or short int hardware port read whole longs, causing - serious side effects - such as bus errors and unexpected hardware operation. This would - also be a problem with ptrace if the inferior process could read - or write hardware registers, but that's not usually the case. */ - if (remote_debugging) - buffer[i] = remote_fetch_word (addr); - else -#endif - buffer[i] = ptrace (1, inferior_pid, addr, 0); - if (errno) - return errno; - } - - /* Copy appropriate bytes out of the buffer. */ - bcopy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len); - return 0; -} - -/* Copy LEN bytes of data from debugger memory at MYADDR - to inferior's memory at MEMADDR. - On failure (cannot write the inferior) - returns the value of errno. */ - -int -write_inferior_memory (memaddr, myaddr, len) - CORE_ADDR memaddr; - char *myaddr; - int len; -{ - register int i; - /* Round starting address down to longword boundary. */ - register CORE_ADDR addr = memaddr & - sizeof (int); - /* Round ending address up; get number of longwords that makes. */ - register int count - = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int); - /* Allocate buffer of that many longwords. */ - register int *buffer = (int *) alloca (count * sizeof (int)); - extern int errno; - - /* Fill start and end extra bytes of buffer with existing memory data. */ - - if (remote_debugging) - return (remote_write_inferior_memory(memaddr, myaddr, len)); - - buffer[0] = ptrace (1, inferior_pid, addr, 0); - - if (count > 1) - buffer[count - 1] = ptrace (1, inferior_pid, - addr + (count - 1) * sizeof (int), 0); - - /* Copy data to be written over corresponding part of buffer */ - - bcopy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len); - - /* Write the entire buffer. */ - - for (i = 0; i < count; i++, addr += sizeof (int)) - { - errno = 0; - ptrace (4, inferior_pid, addr, buffer[i]); - if (errno) - return errno; - } - - return 0; -} - -/* Work with core dump and executable files, for GDB. - This code would be in core.c if it weren't machine-dependent. */ - -#ifndef N_TXTADDR -#define N_TXTADDR(hdr) 0 -#endif /* no N_TXTADDR */ - -#ifndef N_DATADDR -#define N_DATADDR(hdr) hdr.a_text -#endif /* no N_DATADDR */ - -/* Make COFF and non-COFF names for things a little more compatible - to reduce conditionals later. */ - -#ifdef COFF_FORMAT -#define a_magic magic -#endif - -#ifndef COFF_FORMAT -#ifndef AOUTHDR -#define AOUTHDR struct exec -#endif -#endif - -extern char *sys_siglist[]; - - -/* Hook for `exec_file_command' command to call. */ - -extern void (*exec_file_display_hook) (); - -/* File names of core file and executable file. */ - -extern char *corefile; -extern char *execfile; - -/* Descriptors on which core file and executable file are open. - Note that the execchan is closed when an inferior is created - and reopened if the inferior dies or is killed. */ - -extern int corechan; -extern int execchan; - -/* Last modification time of executable file. - Also used in source.c to compare against mtime of a source file. */ - -extern int exec_mtime; - -/* Virtual addresses of bounds of the two areas of memory in the core file. */ - -extern CORE_ADDR data_start; -extern CORE_ADDR data_end; -extern CORE_ADDR stack_start; -extern CORE_ADDR stack_end; - -/* Virtual addresses of bounds of two areas of memory in the exec file. - Note that the data area in the exec file is used only when there is no core file. */ - -extern CORE_ADDR text_start; -extern CORE_ADDR text_end; - -extern CORE_ADDR exec_data_start; -extern CORE_ADDR exec_data_end; - -/* Address in executable file of start of text area data. */ - -extern int text_offset; - -/* Address in executable file of start of data area data. */ - -extern int exec_data_offset; - -/* Address in core file of start of data area data. */ - -extern int data_offset; - -/* Address in core file of start of stack area data. */ - -extern int stack_offset; - -#ifdef COFF_FORMAT -/* various coff data structures */ - -extern FILHDR file_hdr; -extern SCNHDR text_hdr; -extern SCNHDR data_hdr; - -#endif /* not COFF_FORMAT */ - -/* a.out header saved in core file. */ - -extern AOUTHDR core_aouthdr; - -/* a.out header of exec file. */ - -extern AOUTHDR exec_aouthdr; - -extern void validate_files (); - -core_file_command (filename, from_tty) - char *filename; - int from_tty; -{ - int val; - extern char registers[]; - - /* Discard all vestiges of any previous core file - and mark data and stack spaces as empty. */ - - if (corefile) - free (corefile); - corefile = 0; - - if (corechan >= 0) - close (corechan); - corechan = -1; - - data_start = 0; - data_end = 0; - stack_start = STACK_END_ADDR; - stack_end = STACK_END_ADDR; - - /* Now, if a new core file was specified, open it and digest it. */ - - if (filename) - { - filename = tilde_expand (filename); - make_cleanup (free, filename); - - if (have_inferior_p ()) - error ("To look at a core file, you must kill the inferior with \"kill\"."); - corechan = open (filename, O_RDONLY, 0); - if (corechan < 0) - perror_with_name (filename); - /* 4.2-style (and perhaps also sysV-style) core dump file. */ - { - struct user u; - - unsigned int reg_offset; - - val = myread (corechan, &u, sizeof u); - if (val < 0) - perror_with_name ("Not a core file: reading upage"); - if (val != sizeof u) - error ("Not a core file: could only read %d bytes", val); - - /* We are depending on exec_file_command having been called - previously to set exec_data_start. Since the executable - and the core file share the same text segment, the address - of the data segment will be the same in both. */ - data_start = exec_data_start; - - data_end = data_start + NBPG * u.u_dsize; - stack_start = stack_end - NBPG * u.u_ssize; - data_offset = NBPG * UPAGES; - stack_offset = NBPG * (UPAGES + u.u_dsize); - - /* Some machines put an absolute address in here and some put - the offset in the upage of the regs. */ - reg_offset = (int) u.u_ar0; - if (reg_offset > NBPG * UPAGES) - reg_offset -= KERNEL_U_ADDR; - - /* I don't know where to find this info. - So, for now, mark it as not available. */ - N_SET_MAGIC (core_aouthdr, 0); - - /* Read the register values out of the core file and store - them where `read_register' will find them. */ - - { - register int regno; - - for (regno = 0; regno < NUM_REGS; regno++) - { - char buf[MAX_REGISTER_RAW_SIZE]; - - val = lseek (corechan, register_addr (regno, reg_offset), 0); - if (val < 0 - || (val = myread (corechan, buf, sizeof buf)) < 0) - { - char * buffer = (char *) alloca (strlen (reg_names[regno]) - + 30); - strcpy (buffer, "Reading register "); - strcat (buffer, reg_names[regno]); - - perror_with_name (buffer); - } - - supply_register (regno, buf); - } - } - } - if (filename[0] == '/') - corefile = savestring (filename, strlen (filename)); - else - { - corefile = concat (current_directory, "/", filename); - } - - set_current_frame ( create_new_frame (read_register (FP_REGNUM), - read_pc ())); - select_frame (get_current_frame (), 0); - validate_files (); - } - else if (from_tty) - printf ("No core file now.\n"); -} - -exec_file_command (filename, from_tty) - char *filename; - int from_tty; -{ - int val; - - /* Eliminate all traces of old exec file. - Mark text segment as empty. */ - - if (execfile) - free (execfile); - execfile = 0; - data_start = 0; - data_end -= exec_data_start; - text_start = 0; - text_end = 0; - exec_data_start = 0; - exec_data_end = 0; - if (execchan >= 0) - close (execchan); - execchan = -1; - - /* Now open and digest the file the user requested, if any. */ - - if (filename) - { - filename = tilde_expand (filename); - make_cleanup (free, filename); - - execchan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0, - &execfile); - if (execchan < 0) - perror_with_name (filename); - -#ifdef COFF_FORMAT - { - int aout_hdrsize; - int num_sections; - - if (read_file_hdr (execchan, &file_hdr) < 0) - error ("\"%s\": not in executable format.", execfile); - - aout_hdrsize = file_hdr.f_opthdr; - num_sections = file_hdr.f_nscns; - - if (read_aout_hdr (execchan, &exec_aouthdr, aout_hdrsize) < 0) - error ("\"%s\": can't read optional aouthdr", execfile); - - if (read_section_hdr (execchan, _TEXT, &text_hdr, num_sections, - aout_hdrsize) < 0) - error ("\"%s\": can't read text section header", execfile); - - if (read_section_hdr (execchan, _DATA, &data_hdr, num_sections, - aout_hdrsize) < 0) - error ("\"%s\": can't read data section header", execfile); - - text_start = exec_aouthdr.text_start; - text_end = text_start + exec_aouthdr.tsize; - text_offset = text_hdr.s_scnptr; - exec_data_start = exec_aouthdr.data_start; - exec_data_end = exec_data_start + exec_aouthdr.dsize; - exec_data_offset = data_hdr.s_scnptr; - data_start = exec_data_start; - data_end += exec_data_start; - exec_mtime = file_hdr.f_timdat; - } -#else /* not COFF_FORMAT */ - { - struct stat st_exec; - -#ifdef HEADER_SEEK_FD - HEADER_SEEK_FD (execchan); -#endif - - val = myread (execchan, &exec_aouthdr, sizeof (AOUTHDR)); - - if (val < 0) - perror_with_name (filename); - - text_start = N_TXTADDR (exec_aouthdr); - exec_data_start = N_DATADDR (exec_aouthdr); - - text_offset = N_TXTOFF (exec_aouthdr); - exec_data_offset = N_TXTOFF (exec_aouthdr) + exec_aouthdr.a_text; - - text_end = text_start + exec_aouthdr.a_text; - exec_data_end = exec_data_start + exec_aouthdr.a_data; - data_start = exec_data_start; - data_end += exec_data_start; - - if (fstat (execchan, &st_exec) < 0) - perror_with_name (filename); - exec_mtime = st_exec.st_mtime; - } -#endif /* not COFF_FORMAT */ - - validate_files (); - } - else if (from_tty) - printf ("No exec file now.\n"); - - /* Tell display code (if any) about the changed file name. */ - if (exec_file_display_hook) - (*exec_file_display_hook) (filename); -} diff --git a/gnu/usr.bin/gdb/config/i386-dep.c b/gnu/usr.bin/gdb/config/i386-dep.c deleted file mode 100644 index c4630d0..0000000 --- a/gnu/usr.bin/gdb/config/i386-dep.c +++ /dev/null @@ -1,1275 +0,0 @@ -/* Low level interface to ptrace, for GDB when running on the Intel 386. - Copyright (C) 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "frame.h" -#include "inferior.h" - -#ifdef USG -#include -#endif - -#include -#include -#include -#include -#include -#include - -#ifdef COFF_ENCAPSULATE -#include "a.out.encap.h" -#else -#include -#endif - -#ifndef N_SET_MAGIC -#ifdef COFF_FORMAT -#define N_SET_MAGIC(exec, val) ((exec).magic = (val)) -#else -#define N_SET_MAGIC(exec, val) ((exec).a_magic = (val)) -#endif -#endif - -#include -#include - -#include - -extern int errno; - -/* This function simply calls ptrace with the given arguments. - It exists so that all calls to ptrace are isolated in this - machine-dependent file. */ -int -call_ptrace (request, pid, arg3, arg4) - int request, pid, arg3, arg4; -{ - return ptrace (request, pid, arg3, arg4); -} - -kill_inferior () -{ - if (remote_debugging) - return; - if (inferior_pid == 0) - return; - ptrace (8, inferior_pid, 0, 0); - wait (0); - inferior_died (); -} - -/* This is used when GDB is exiting. It gives less chance of error.*/ - -kill_inferior_fast () -{ - if (remote_debugging) - return; - if (inferior_pid == 0) - return; - ptrace (8, inferior_pid, 0, 0); - wait (0); -} - -/* Resume execution of the inferior process. - If STEP is nonzero, single-step it. - If SIGNAL is nonzero, give it that signal. */ - -void -resume (step, signal) - int step; - int signal; -{ - errno = 0; - if (remote_debugging) - remote_resume (step, signal); - else - { - ptrace (step ? 9 : 7, inferior_pid, 1, signal); - if (errno) - perror_with_name ("ptrace"); - } -} - -void -fetch_inferior_registers () -{ - register int regno; - register unsigned int regaddr; - char buf[MAX_REGISTER_RAW_SIZE]; - register int i; - - struct user u; - unsigned int offset = (char *) &u.u_ar0 - (char *) &u; - offset = ptrace (3, inferior_pid, offset, 0) - KERNEL_U_ADDR; - - for (regno = 0; regno < NUM_REGS; regno++) - { - regaddr = register_addr (regno, offset); - for (i = 0; i < REGISTER_RAW_SIZE (regno); i += sizeof (int)) - { - *(int *) &buf[i] = ptrace (3, inferior_pid, regaddr, 0); - regaddr += sizeof (int); - } - supply_register (regno, buf); - } -} - -/* Store our register values back into the inferior. - If REGNO is -1, do this for all registers. - Otherwise, REGNO specifies which register (so we can save time). */ - -store_inferior_registers (regno) - int regno; -{ - register unsigned int regaddr; - char buf[80]; - - struct user u; - unsigned int offset = (char *) &u.u_ar0 - (char *) &u; - offset = ptrace (3, inferior_pid, offset, 0) - KERNEL_U_ADDR; - - if (regno >= 0) - { - regaddr = register_addr (regno, offset); - errno = 0; - ptrace (6, inferior_pid, regaddr, read_register (regno)); - if (errno != 0) - { - sprintf (buf, "writing register number %d", regno); - perror_with_name (buf); - } - } - else for (regno = 0; regno < NUM_REGS; regno++) - { - regaddr = register_addr (regno, offset); - errno = 0; - ptrace (6, inferior_pid, regaddr, read_register (regno)); - if (errno != 0) - { - sprintf (buf, "writing register number %d", regno); - perror_with_name (buf); - } - } -} - -/* Copy LEN bytes from inferior's memory starting at MEMADDR - to debugger memory starting at MYADDR. - On failure (cannot read from inferior, usually because address is out - of bounds) returns the value of errno. */ - -int -read_inferior_memory (memaddr, myaddr, len) - CORE_ADDR memaddr; - char *myaddr; - int len; -{ - register int i; - /* Round starting address down to longword boundary. */ - register CORE_ADDR addr = memaddr & - sizeof (int); - /* Round ending address up; get number of longwords that makes. */ - register int count - = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int); - /* Allocate buffer of that many longwords. */ - register int *buffer = (int *) alloca (count * sizeof (int)); - extern int errno; - - /* Read all the longwords */ - for (i = 0; i < count; i++, addr += sizeof (int)) - { - errno = 0; - if (remote_debugging) - buffer[i] = remote_fetch_word (addr); - else - buffer[i] = ptrace (1, inferior_pid, addr, 0); - if (errno) - return errno; - } - - /* Copy appropriate bytes out of the buffer. */ - bcopy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len); - return 0; -} - -/* Copy LEN bytes of data from debugger memory at MYADDR - to inferior's memory at MEMADDR. - On failure (cannot write the inferior) - returns the value of errno. */ - -int -write_inferior_memory (memaddr, myaddr, len) - CORE_ADDR memaddr; - char *myaddr; - int len; -{ - register int i; - /* Round starting address down to longword boundary. */ - register CORE_ADDR addr = memaddr & - sizeof (int); - /* Round ending address up; get number of longwords that makes. */ - register int count - = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int); - /* Allocate buffer of that many longwords. */ - register int *buffer = (int *) alloca (count * sizeof (int)); - extern int errno; - - /* Fill start and end extra bytes of buffer with existing memory data. */ - - if (remote_debugging) - buffer[0] = remote_fetch_word (addr); - else - buffer[0] = ptrace (1, inferior_pid, addr, 0); - - if (count > 1) - { - if (remote_debugging) - buffer[count - 1] - = remote_fetch_word (addr + (count - 1) * sizeof (int)); - else - buffer[count - 1] - = ptrace (1, inferior_pid, - addr + (count - 1) * sizeof (int), 0); - } - - /* Copy data to be written over corresponding part of buffer */ - - bcopy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len); - - /* Write the entire buffer. */ - - for (i = 0; i < count; i++, addr += sizeof (int)) - { - errno = 0; - if (remote_debugging) - remote_store_word (addr, buffer[i]); - else - ptrace (4, inferior_pid, addr, buffer[i]); - if (errno) - return errno; - } - - return 0; -} - -/* Work with core dump and executable files, for GDB. - This code would be in core.c if it weren't machine-dependent. */ - -#ifndef N_TXTADDR -#define N_TXTADDR(hdr) 0 -#endif /* no N_TXTADDR */ - -#ifndef N_DATADDR -#define N_DATADDR(hdr) hdr.a_text -#endif /* no N_DATADDR */ - -/* Make COFF and non-COFF names for things a little more compatible - to reduce conditionals later. */ - -#ifndef COFF_FORMAT -#ifndef AOUTHDR -#define AOUTHDR struct exec -#endif -#endif - -extern char *sys_siglist[]; - - -/* Hook for `exec_file_command' command to call. */ - -extern void (*exec_file_display_hook) (); - -/* File names of core file and executable file. */ - -extern char *corefile; -extern char *execfile; - -/* Descriptors on which core file and executable file are open. - Note that the execchan is closed when an inferior is created - and reopened if the inferior dies or is killed. */ - -extern int corechan; -extern int execchan; - -/* Last modification time of executable file. - Also used in source.c to compare against mtime of a source file. */ - -extern int exec_mtime; - -/* Virtual addresses of bounds of the two areas of memory in the core file. */ - -extern CORE_ADDR data_start; -extern CORE_ADDR data_end; -extern CORE_ADDR stack_start; -extern CORE_ADDR stack_end; - -/* Virtual addresses of bounds of two areas of memory in the exec file. - Note that the data area in the exec file is used only when there is no core file. */ - -extern CORE_ADDR text_start; -extern CORE_ADDR text_end; - -extern CORE_ADDR exec_data_start; -extern CORE_ADDR exec_data_end; - -/* Address in executable file of start of text area data. */ - -extern int text_offset; - -/* Address in executable file of start of data area data. */ - -extern int exec_data_offset; - -/* Address in core file of start of data area data. */ - -extern int data_offset; - -/* Address in core file of start of stack area data. */ - -extern int stack_offset; - -#ifdef COFF_FORMAT -/* various coff data structures */ - -extern FILHDR file_hdr; -extern SCNHDR text_hdr; -extern SCNHDR data_hdr; - -#endif /* not COFF_FORMAT */ - -/* a.out header saved in core file. */ - -extern AOUTHDR core_aouthdr; - -/* a.out header of exec file. */ - -extern AOUTHDR exec_aouthdr; - -extern void validate_files (); - -core_file_command (filename, from_tty) - char *filename; - int from_tty; -{ - int val; - extern char registers[]; - - /* Discard all vestiges of any previous core file - and mark data and stack spaces as empty. */ - - if (corefile) - free (corefile); - corefile = 0; - - if (corechan >= 0) - close (corechan); - corechan = -1; - - data_start = 0; - data_end = 0; - stack_start = STACK_END_ADDR; - stack_end = STACK_END_ADDR; - - /* Now, if a new core file was specified, open it and digest it. */ - - if (filename) - { - filename = tilde_expand (filename); - make_cleanup (free, filename); - - if (have_inferior_p ()) - error ("To look at a core file, you must kill the inferior with \"kill\"."); - corechan = open (filename, O_RDONLY, 0); - if (corechan < 0) - perror_with_name (filename); - /* 4.2-style (and perhaps also sysV-style) core dump file. */ - { - struct user u; - - int reg_offset; - - val = myread (corechan, &u, sizeof u); - if (val < 0) - perror_with_name (filename); - data_start = exec_data_start; - - data_end = data_start + NBPG * u.u_dsize; - stack_start = stack_end - NBPG * u.u_ssize; - data_offset = NBPG * UPAGES; - stack_offset = NBPG * (UPAGES + u.u_dsize); - reg_offset = (int) u.u_ar0 - KERNEL_U_ADDR; - - /* I don't know where to find this info. - So, for now, mark it as not available. */ -/* N_SET_MAGIC (core_aouthdr, 0); */ - bzero ((char *) &core_aouthdr, sizeof core_aouthdr); - - /* Read the register values out of the core file and store - them where `read_register' will find them. */ - - { - register int regno; - - for (regno = 0; regno < NUM_REGS; regno++) - { - char buf[MAX_REGISTER_RAW_SIZE]; - - val = lseek (corechan, register_addr (regno, reg_offset), 0); - if (val < 0) - perror_with_name (filename); - - val = myread (corechan, buf, sizeof buf); - if (val < 0) - perror_with_name (filename); - supply_register (regno, buf); - } - } - } - if (filename[0] == '/') - corefile = savestring (filename, strlen (filename)); - else - { - corefile = concat (current_directory, "/", filename); - } - - set_current_frame ( create_new_frame (read_register (FP_REGNUM), - read_pc ())); - select_frame (get_current_frame (), 0); - validate_files (); - } - else if (from_tty) - printf ("No core file now.\n"); -} - -exec_file_command (filename, from_tty) - char *filename; - int from_tty; -{ - int val; - - /* Eliminate all traces of old exec file. - Mark text segment as empty. */ - - if (execfile) - free (execfile); - execfile = 0; - data_start = 0; - data_end -= exec_data_start; - text_start = 0; - text_end = 0; - exec_data_start = 0; - exec_data_end = 0; - if (execchan >= 0) - close (execchan); - execchan = -1; - - /* Now open and digest the file the user requested, if any. */ - - if (filename) - { - filename = tilde_expand (filename); - make_cleanup (free, filename); - - execchan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0, - &execfile); - if (execchan < 0) - perror_with_name (filename); - -#ifdef COFF_FORMAT - { - int aout_hdrsize; - int num_sections; - - if (read_file_hdr (execchan, &file_hdr) < 0) - error ("\"%s\": not in executable format.", execfile); - - aout_hdrsize = file_hdr.f_opthdr; - num_sections = file_hdr.f_nscns; - - if (read_aout_hdr (execchan, &exec_aouthdr, aout_hdrsize) < 0) - error ("\"%s\": can't read optional aouthdr", execfile); - - if (read_section_hdr (execchan, _TEXT, &text_hdr, num_sections, - aout_hdrsize) < 0) - error ("\"%s\": can't read text section header", execfile); - - if (read_section_hdr (execchan, _DATA, &data_hdr, num_sections, - aout_hdrsize) < 0) - error ("\"%s\": can't read data section header", execfile); - - text_start = exec_aouthdr.text_start; - text_end = text_start + exec_aouthdr.tsize; - text_offset = text_hdr.s_scnptr; - exec_data_start = exec_aouthdr.data_start; - exec_data_end = exec_data_start + exec_aouthdr.dsize; - exec_data_offset = data_hdr.s_scnptr; - data_start = exec_data_start; - data_end += exec_data_start; - exec_mtime = file_hdr.f_timdat; - } -#else /* not COFF_FORMAT */ - { - struct stat st_exec; - -#ifdef HEADER_SEEK_FD - HEADER_SEEK_FD (execchan); -#endif - - val = myread (execchan, &exec_aouthdr, sizeof (AOUTHDR)); - - if (val < 0) - perror_with_name (filename); - - text_start = N_TXTADDR (exec_aouthdr); - exec_data_start = N_DATADDR (exec_aouthdr); - - text_offset = N_TXTOFF (exec_aouthdr); - exec_data_offset = N_TXTOFF (exec_aouthdr) + exec_aouthdr.a_text; - - text_end = text_start + exec_aouthdr.a_text; - exec_data_end = exec_data_start + exec_aouthdr.a_data; - data_start = exec_data_start; - data_end += exec_data_start; - - fstat (execchan, &st_exec); - exec_mtime = st_exec.st_mtime; - } -#endif /* not COFF_FORMAT */ - - validate_files (); - } - else if (from_tty) - printf ("No exec file now.\n"); - - /* Tell display code (if any) about the changed file name. */ - if (exec_file_display_hook) - (*exec_file_display_hook) (filename); -} - -/* helper functions for m-i386.h */ - -/* stdio style buffering to minimize calls to ptrace */ -static CORE_ADDR codestream_next_addr; -static CORE_ADDR codestream_addr; -static unsigned char codestream_buf[sizeof (int)]; -static int codestream_off; -static int codestream_cnt; - -#define codestream_tell() (codestream_addr + codestream_off) -#define codestream_peek() (codestream_cnt == 0 ? \ - codestream_fill(1): codestream_buf[codestream_off]) -#define codestream_get() (codestream_cnt-- == 0 ? \ - codestream_fill(0) : codestream_buf[codestream_off++]) - -static unsigned char -codestream_fill (peek_flag) -{ - codestream_addr = codestream_next_addr; - codestream_next_addr += sizeof (int); - codestream_off = 0; - codestream_cnt = sizeof (int); - read_memory (codestream_addr, - (unsigned char *)codestream_buf, - sizeof (int)); - - if (peek_flag) - return (codestream_peek()); - else - return (codestream_get()); -} - -static void -codestream_seek (place) -{ - codestream_next_addr = place & -sizeof (int); - codestream_cnt = 0; - codestream_fill (1); - while (codestream_tell() != place) - codestream_get (); -} - -static void -codestream_read (buf, count) - unsigned char *buf; -{ - unsigned char *p; - int i; - p = buf; - for (i = 0; i < count; i++) - *p++ = codestream_get (); -} - -/* next instruction is a jump, move to target */ -static -i386_follow_jump () -{ - int long_delta; - short short_delta; - char byte_delta; - int data16; - int pos; - - pos = codestream_tell (); - - data16 = 0; - if (codestream_peek () == 0x66) - { - codestream_get (); - data16 = 1; - } - - switch (codestream_get ()) - { - case 0xe9: - /* relative jump: if data16 == 0, disp32, else disp16 */ - if (data16) - { - codestream_read ((unsigned char *)&short_delta, 2); - pos += short_delta + 3; /* include size of jmp inst */ - } - else - { - codestream_read ((unsigned char *)&long_delta, 4); - pos += long_delta + 5; - } - break; - case 0xeb: - /* relative jump, disp8 (ignore data16) */ - codestream_read ((unsigned char *)&byte_delta, 1); - pos += byte_delta + 2; - break; - } - codestream_seek (pos + data16); -} - -/* - * find & return amound a local space allocated, and advance codestream to - * first register push (if any) - * - * if entry sequence doesn't make sense, return -1, and leave - * codestream pointer random - */ -static long -i386_get_frame_setup (pc) -{ - unsigned char op; - - codestream_seek (pc); - - i386_follow_jump (); - - op = codestream_get (); - - if (op == 0x58) /* popl %eax */ - { - /* - * this function must start with - * - * popl %eax 0x58 - * xchgl %eax, (%esp) 0x87 0x04 0x24 - * or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00 - * - * (the system 5 compiler puts out the second xchg - * inst, and the assembler doesn't try to optimize it, - * so the 'sib' form gets generated) - * - * this sequence is used to get the address of the return - * buffer for a function that returns a structure - */ - int pos; - unsigned char buf[4]; - static unsigned char proto1[3] = { 0x87,0x04,0x24 }; - static unsigned char proto2[4] = { 0x87,0x44,0x24,0x00 }; - pos = codestream_tell (); - codestream_read (buf, 4); - if (bcmp (buf, proto1, 3) == 0) - pos += 3; - else if (bcmp (buf, proto2, 4) == 0) - pos += 4; - - codestream_seek (pos); - op = codestream_get (); /* update next opcode */ - } - - if (op == 0x55) /* pushl %esp */ - { - /* check for movl %esp, %ebp - can be written two ways */ - switch (codestream_get ()) - { - case 0x8b: - if (codestream_get () != 0xec) - return (-1); - break; - case 0x89: - if (codestream_get () != 0xe5) - return (-1); - break; - default: - return (-1); - } - /* check for stack adjustment - * - * subl $XXX, %esp - * - * note: you can't subtract a 16 bit immediate - * from a 32 bit reg, so we don't have to worry - * about a data16 prefix - */ - op = codestream_peek (); - if (op == 0x83) - { - /* subl with 8 bit immed */ - codestream_get (); - if (codestream_get () != 0xec) - return (-1); - /* subl with signed byte immediate - * (though it wouldn't make sense to be negative) - */ - return (codestream_get()); - } - else if (op == 0x81) - { - /* subl with 32 bit immed */ - int locals; - codestream_get(); - if (codestream_get () != 0xec) - return (-1); - /* subl with 32 bit immediate */ - codestream_read ((unsigned char *)&locals, 4); - return (locals); - } - else - { - return (0); - } - } - else if (op == 0xc8) - { - /* enter instruction: arg is 16 bit unsigned immed */ - unsigned short slocals; - codestream_read ((unsigned char *)&slocals, 2); - codestream_get (); /* flush final byte of enter instruction */ - return (slocals); - } - return (-1); -} - -/* Return number of args passed to a frame. - Can return -1, meaning no way to tell. */ - -/* on the 386, the instruction following the call could be: - * popl %ecx - one arg - * addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits - * anything else - zero args - */ - -int -i386_frame_num_args (fi) - struct frame_info fi; -{ - int retpc; - unsigned char op; - struct frame_info *pfi; - - pfi = get_prev_frame_info ((fi)); - if (pfi == 0) - { - /* Note: this can happen if we are looking at the frame for - main, because FRAME_CHAIN_VALID won't let us go into - start. If we have debugging symbols, that's not really - a big deal; it just means it will only show as many arguments - to main as are declared. */ - return -1; - } - else - { - retpc = pfi->pc; - op = read_memory_integer (retpc, 1); - if (op == 0x59) - /* pop %ecx */ - return 1; - else if (op == 0x83) - { - op = read_memory_integer (retpc+1, 1); - if (op == 0xc4) - /* addl $, %esp */ - return (read_memory_integer (retpc+2,1)&0xff)/4; - else - return 0; - } - else if (op == 0x81) - { /* add with 32 bit immediate */ - op = read_memory_integer (retpc+1, 1); - if (op == 0xc4) - /* addl $, %esp */ - return read_memory_integer (retpc+2, 4) / 4; - else - return 0; - } - else - { - return 0; - } - } -} - -/* - * parse the first few instructions of the function to see - * what registers were stored. - * - * We handle these cases: - * - * The startup sequence can be at the start of the function, - * or the function can start with a branch to startup code at the end. - * - * %ebp can be set up with either the 'enter' instruction, or - * 'pushl %ebp, movl %esp, %ebp' (enter is too slow to be useful, - * but was once used in the sys5 compiler) - * - * Local space is allocated just below the saved %ebp by either the - * 'enter' instruction, or by 'subl $, %esp'. 'enter' has - * a 16 bit unsigned argument for space to allocate, and the - * 'addl' instruction could have either a signed byte, or - * 32 bit immediate. - * - * Next, the registers used by this function are pushed. In - * the sys5 compiler they will always be in the order: %edi, %esi, %ebx - * (and sometimes a harmless bug causes it to also save but not restore %eax); - * however, the code below is willing to see the pushes in any order, - * and will handle up to 8 of them. - * - * If the setup sequence is at the end of the function, then the - * next instruction will be a branch back to the start. - */ - -i386_frame_find_saved_regs (fip, fsrp) - struct frame_info *fip; - struct frame_saved_regs *fsrp; -{ - unsigned long locals; - unsigned char *p; - unsigned char op; - CORE_ADDR dummy_bottom; - CORE_ADDR adr; - int i; - - bzero (fsrp, sizeof *fsrp); - - /* if frame is the end of a dummy, compute where the - * beginning would be - */ - dummy_bottom = fip->frame - 4 - NUM_REGS*4 - CALL_DUMMY_LENGTH; - - /* check if the PC is in the stack, in a dummy frame */ - if (dummy_bottom <= fip->pc && fip->pc <= fip->frame) - { - /* all regs were saved by push_call_dummy () */ - adr = fip->frame - 4; - for (i = 0; i < NUM_REGS; i++) - { - fsrp->regs[i] = adr; - adr -= 4; - } - return; - } - - locals = i386_get_frame_setup (get_pc_function_start (fip->pc)); - - if (locals >= 0) - { - adr = fip->frame - 4 - locals; - for (i = 0; i < 8; i++) - { - op = codestream_get (); - if (op < 0x50 || op > 0x57) - break; - fsrp->regs[op - 0x50] = adr; - adr -= 4; - } - } - - fsrp->regs[PC_REGNUM] = fip->frame + 4; - fsrp->regs[FP_REGNUM] = fip->frame; -} - -/* return pc of first real instruction */ -i386_skip_prologue (pc) -{ - unsigned char op; - int i; - - if (i386_get_frame_setup (pc) < 0) - return (pc); - - /* found valid frame setup - codestream now points to - * start of push instructions for saving registers - */ - - /* skip over register saves */ - for (i = 0; i < 8; i++) - { - op = codestream_peek (); - /* break if not pushl inst */ - if (op < 0x50 || op > 0x57) - break; - codestream_get (); - } - - i386_follow_jump (); - - return (codestream_tell ()); -} - -i386_push_dummy_frame () -{ - CORE_ADDR sp = read_register (SP_REGNUM); - int regnum; - - sp = push_word (sp, read_register (PC_REGNUM)); - sp = push_word (sp, read_register (FP_REGNUM)); - write_register (FP_REGNUM, sp); - for (regnum = 0; regnum < NUM_REGS; regnum++) - sp = push_word (sp, read_register (regnum)); - write_register (SP_REGNUM, sp); -} - -i386_pop_frame () -{ - FRAME frame = get_current_frame (); - CORE_ADDR fp; - int regnum; - struct frame_saved_regs fsr; - struct frame_info *fi; - - fi = get_frame_info (frame); - fp = fi->frame; - get_frame_saved_regs (fi, &fsr); - for (regnum = 0; regnum < NUM_REGS; regnum++) - { - CORE_ADDR adr; - adr = fsr.regs[regnum]; - if (adr) - write_register (regnum, read_memory_integer (adr, 4)); - } - write_register (FP_REGNUM, read_memory_integer (fp, 4)); - write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); - write_register (SP_REGNUM, fp + 8); - flush_cached_frames (); - set_current_frame ( create_new_frame (read_register (FP_REGNUM), - read_pc ())); -} - -/* this table must line up with REGISTER_NAMES in m-i386.h */ -/* symbols like 'EAX' come from */ -static int regmap[] = -{ - EAX, ECX, EDX, EBX, - UESP, EBP, ESI, EDI, - EIP, EFL, CS, SS, - DS, ES, FS, GS, -}; - -/* blockend is the value of u.u_ar0, and points to the - * place where GS is stored - */ -i386_register_u_addr (blockend, regnum) -{ -#if 0 - /* this will be needed if fp registers are reinstated */ - /* for now, you can look at them with 'info float' - * sys5 wont let you change them with ptrace anyway - */ - if (regnum >= FP0_REGNUM && regnum <= FP7_REGNUM) - { - int ubase, fpstate; - struct user u; - ubase = blockend + 4 * (SS + 1) - KSTKSZ; - fpstate = ubase + ((char *)&u.u_fpstate - (char *)&u); - return (fpstate + 0x1c + 10 * (regnum - FP0_REGNUM)); - } - else -#endif - return (blockend + 4 * regmap[regnum]); - -} - -i387_to_double (from, to) - char *from; - char *to; -{ - long *lp; - /* push extended mode on 387 stack, then pop in double mode - * - * first, set exception masks so no error is generated - - * number will be rounded to inf or 0, if necessary - */ - asm ("pushl %eax"); /* grab a stack slot */ - asm ("fstcw (%esp)"); /* get 387 control word */ - asm ("movl (%esp),%eax"); /* save old value */ - asm ("orl $0x3f,%eax"); /* mask all exceptions */ - asm ("pushl %eax"); - asm ("fldcw (%esp)"); /* load new value into 387 */ - - asm ("movl 8(%ebp),%eax"); - asm ("fldt (%eax)"); /* push extended number on 387 stack */ - asm ("fwait"); - asm ("movl 12(%ebp),%eax"); - asm ("fstpl (%eax)"); /* pop double */ - asm ("fwait"); - - asm ("popl %eax"); /* flush modified control word */ - asm ("fnclex"); /* clear exceptions */ - asm ("fldcw (%esp)"); /* restore original control word */ - asm ("popl %eax"); /* flush saved copy */ -} - -double_to_i387 (from, to) - char *from; - char *to; -{ - /* push double mode on 387 stack, then pop in extended mode - * no errors are possible because every 64-bit pattern - * can be converted to an extended - */ - asm ("movl 8(%ebp),%eax"); - asm ("fldl (%eax)"); - asm ("fwait"); - asm ("movl 12(%ebp),%eax"); - asm ("fstpt (%eax)"); - asm ("fwait"); -} - -struct env387 -{ - unsigned short control; - unsigned short r0; - unsigned short status; - unsigned short r1; - unsigned short tag; - unsigned short r2; - unsigned long eip; - unsigned short code_seg; - unsigned short opcode; - unsigned long operand; - unsigned short operand_seg; - unsigned short r3; - unsigned char regs[8][10]; -}; - -static -print_387_control_word (control) -unsigned short control; -{ - printf ("control 0x%04x: ", control); - printf ("compute to "); - switch ((control >> 8) & 3) - { - case 0: printf ("24 bits; "); break; - case 1: printf ("(bad); "); break; - case 2: printf ("53 bits; "); break; - case 3: printf ("64 bits; "); break; - } - printf ("round "); - switch ((control >> 10) & 3) - { - case 0: printf ("NEAREST; "); break; - case 1: printf ("DOWN; "); break; - case 2: printf ("UP; "); break; - case 3: printf ("CHOP; "); break; - } - if (control & 0x3f) - { - printf ("mask:"); - if (control & 0x0001) printf (" INVALID"); - if (control & 0x0002) printf (" DENORM"); - if (control & 0x0004) printf (" DIVZ"); - if (control & 0x0008) printf (" OVERF"); - if (control & 0x0010) printf (" UNDERF"); - if (control & 0x0020) printf (" LOS"); - printf (";"); - } - printf ("\n"); - if (control & 0xe080) printf ("warning: reserved bits on 0x%x\n", - control & 0xe080); -} - -static -print_387_status_word (status) - unsigned short status; -{ - printf ("status 0x%04x: ", status); - if (status & 0xff) - { - printf ("exceptions:"); - if (status & 0x0001) printf (" INVALID"); - if (status & 0x0002) printf (" DENORM"); - if (status & 0x0004) printf (" DIVZ"); - if (status & 0x0008) printf (" OVERF"); - if (status & 0x0010) printf (" UNDERF"); - if (status & 0x0020) printf (" LOS"); - if (status & 0x0040) printf (" FPSTACK"); - printf ("; "); - } - printf ("flags: %d%d%d%d; ", - (status & 0x4000) != 0, - (status & 0x0400) != 0, - (status & 0x0200) != 0, - (status & 0x0100) != 0); - - printf ("top %d\n", (status >> 11) & 7); -} - -static -print_387_status (status, ep) - unsigned short status; - struct env387 *ep; -{ - int i; - int bothstatus; - int top; - int fpreg; - unsigned char *p; - - bothstatus = ((status != 0) && (ep->status != 0)); - if (status != 0) - { - if (bothstatus) - printf ("u: "); - print_387_status_word (status); - } - - if (ep->status != 0) - { - if (bothstatus) - printf ("e: "); - print_387_status_word (ep->status); - } - - print_387_control_word (ep->control); - printf ("last exception: "); - printf ("opcode 0x%x; ", ep->opcode); - printf ("pc 0x%x:0x%x; ", ep->code_seg, ep->eip); - printf ("operand 0x%x:0x%x\n", ep->operand_seg, ep->operand); - - top = (ep->status >> 11) & 7; - - printf ("regno tag msb lsb value\n"); - for (fpreg = 7; fpreg >= 0; fpreg--) - { - double val; - - printf ("%s %d: ", fpreg == top ? "=>" : " ", fpreg); - - switch ((ep->tag >> (fpreg * 2)) & 3) - { - case 0: printf ("valid "); break; - case 1: printf ("zero "); break; - case 2: printf ("trap "); break; - case 3: printf ("empty "); break; - } - for (i = 9; i >= 0; i--) - printf ("%02x", ep->regs[fpreg][i]); - - i387_to_double (ep->regs[fpreg], (char *)&val); - printf (" %g\n", val); - } - if (ep->r0) - printf ("warning: reserved0 is 0x%x\n", ep->r0); - if (ep->r1) - printf ("warning: reserved1 is 0x%x\n", ep->r1); - if (ep->r2) - printf ("warning: reserved2 is 0x%x\n", ep->r2); - if (ep->r3) - printf ("warning: reserved3 is 0x%x\n", ep->r3); -} - -#ifndef U_FPSTATE -#define U_FPSTATE(u) u.u_fpstate -#endif - -i386_float_info () -{ - struct user u; /* just for address computations */ - int i; - /* fpstate defined in */ - struct fpstate *fpstatep; - char buf[sizeof (struct fpstate) + 2 * sizeof (int)]; - unsigned int uaddr; - char fpvalid; - unsigned int rounded_addr; - unsigned int rounded_size; - extern int corechan; - int skip; - - uaddr = (char *)&u.u_fpvalid - (char *)&u; - if (have_inferior_p()) - { - unsigned int data; - unsigned int mask; - - rounded_addr = uaddr & -sizeof (int); - data = ptrace (3, inferior_pid, rounded_addr, 0); - mask = 0xff << ((uaddr - rounded_addr) * 8); - - fpvalid = ((data & mask) != 0); - } - else - { - if (lseek (corechan, uaddr, 0) < 0) - perror ("seek on core file"); - if (myread (corechan, &fpvalid, 1) < 0) - perror ("read on core file"); - - } - - if (fpvalid == 0) - { - printf ("no floating point status saved\n"); - return; - } - - uaddr = (char *)&U_FPSTATE(u) - (char *)&u; - if (have_inferior_p ()) - { - int *ip; - - rounded_addr = uaddr & -sizeof (int); - rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) + - sizeof (int) - 1) / sizeof (int); - skip = uaddr - rounded_addr; - - ip = (int *)buf; - for (i = 0; i < rounded_size; i++) - { - *ip++ = ptrace (3, inferior_pid, rounded_addr, 0); - rounded_addr += sizeof (int); - } - } - else - { - if (lseek (corechan, uaddr, 0) < 0) - perror_with_name ("seek on core file"); - if (myread (corechan, buf, sizeof (struct fpstate)) < 0) - perror_with_name ("read from core file"); - skip = 0; - } - - fpstatep = (struct fpstate *)(buf + skip); - print_387_status (fpstatep->status, (struct env387 *)fpstatep->state); -} - diff --git a/gnu/usr.bin/gdb/config/i386-pinsn.c b/gnu/usr.bin/gdb/config/i386-pinsn.c deleted file mode 100644 index 649baaf..0000000 --- a/gnu/usr.bin/gdb/config/i386-pinsn.c +++ /dev/null @@ -1,1812 +0,0 @@ -/* Print i386 instructions for GDB, the GNU debugger. - Copyright (C) 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* - * 80386 instruction printer by Pace Willisson (pace@prep.ai.mit.edu) - * July 1988 - */ - -/* - * The main tables describing the instructions is essentially a copy - * of the "Opcode Map" chapter (Appendix A) of the Intel 80386 - * Programmers Manual. Usually, there is a capital letter, followed - * by a small letter. The capital letter tell the addressing mode, - * and the small letter tells about the operand size. Refer to - * the Intel manual for details. - */ - -#include -#include - -#define Eb OP_E, b_mode -#define indirEb OP_indirE, b_mode -#define Gb OP_G, b_mode -#define Ev OP_E, v_mode -#define indirEv OP_indirE, v_mode -#define Ew OP_E, w_mode -#define Ma OP_E, v_mode -#define M OP_E, 0 -#define Mp OP_E, 0 /* ? */ -#define Gv OP_G, v_mode -#define Gw OP_G, w_mode -#define Rw OP_rm, w_mode -#define Rd OP_rm, d_mode -#define Ib OP_I, b_mode -#define sIb OP_sI, b_mode /* sign extened byte */ -#define Iv OP_I, v_mode -#define Iw OP_I, w_mode -#define Jb OP_J, b_mode -#define Jv OP_J, v_mode -#define ONE OP_ONE, 0 -#define Cd OP_C, d_mode -#define Dd OP_D, d_mode -#define Td OP_T, d_mode - -#define eAX OP_REG, eAX_reg -#define eBX OP_REG, eBX_reg -#define eCX OP_REG, eCX_reg -#define eDX OP_REG, eDX_reg -#define eSP OP_REG, eSP_reg -#define eBP OP_REG, eBP_reg -#define eSI OP_REG, eSI_reg -#define eDI OP_REG, eDI_reg -#define AL OP_REG, al_reg -#define CL OP_REG, cl_reg -#define DL OP_REG, dl_reg -#define BL OP_REG, bl_reg -#define AH OP_REG, ah_reg -#define CH OP_REG, ch_reg -#define DH OP_REG, dh_reg -#define BH OP_REG, bh_reg -#define AX OP_REG, ax_reg -#define DX OP_REG, dx_reg -#define indirDX OP_REG, indir_dx_reg - -#define Sw OP_SEG, w_mode -#define Ap OP_DIR, lptr -#define Av OP_DIR, v_mode -#define Ob OP_OFF, b_mode -#define Ov OP_OFF, v_mode -#define Xb OP_DSSI, b_mode -#define Xv OP_DSSI, v_mode -#define Yb OP_ESDI, b_mode -#define Yv OP_ESDI, v_mode - -#define es OP_REG, es_reg -#define ss OP_REG, ss_reg -#define cs OP_REG, cs_reg -#define ds OP_REG, ds_reg -#define fs OP_REG, fs_reg -#define gs OP_REG, gs_reg - -int OP_E(), OP_indirE(), OP_G(), OP_I(), OP_sI(), OP_REG(); -int OP_J(), OP_SEG(); -int OP_DIR(), OP_OFF(), OP_DSSI(), OP_ESDI(), OP_ONE(), OP_C(); -int OP_D(), OP_T(), OP_rm(); - - -#define b_mode 1 -#define v_mode 2 -#define w_mode 3 -#define d_mode 4 - -#define es_reg 100 -#define cs_reg 101 -#define ss_reg 102 -#define ds_reg 103 -#define fs_reg 104 -#define gs_reg 105 -#define eAX_reg 107 -#define eCX_reg 108 -#define eDX_reg 109 -#define eBX_reg 110 -#define eSP_reg 111 -#define eBP_reg 112 -#define eSI_reg 113 -#define eDI_reg 114 - -#define lptr 115 - -#define al_reg 116 -#define cl_reg 117 -#define dl_reg 118 -#define bl_reg 119 -#define ah_reg 120 -#define ch_reg 121 -#define dh_reg 122 -#define bh_reg 123 - -#define ax_reg 124 -#define cx_reg 125 -#define dx_reg 126 -#define bx_reg 127 -#define sp_reg 128 -#define bp_reg 129 -#define si_reg 130 -#define di_reg 131 - -#define indir_dx_reg 150 - -#define GRP1b NULL, NULL, 0 -#define GRP1S NULL, NULL, 1 -#define GRP1Ss NULL, NULL, 2 -#define GRP2b NULL, NULL, 3 -#define GRP2S NULL, NULL, 4 -#define GRP2b_one NULL, NULL, 5 -#define GRP2S_one NULL, NULL, 6 -#define GRP2b_cl NULL, NULL, 7 -#define GRP2S_cl NULL, NULL, 8 -#define GRP3b NULL, NULL, 9 -#define GRP3S NULL, NULL, 10 -#define GRP4 NULL, NULL, 11 -#define GRP5 NULL, NULL, 12 -#define GRP6 NULL, NULL, 13 -#define GRP7 NULL, NULL, 14 -#define GRP8 NULL, NULL, 15 - -#define FLOATCODE 50 -#define FLOAT NULL, NULL, FLOATCODE - -struct dis386 { - char *name; - int (*op1)(); - int bytemode1; - int (*op2)(); - int bytemode2; - int (*op3)(); - int bytemode3; -}; - -struct dis386 dis386[] = { - /* 00 */ - { "addb", Eb, Gb }, - { "addS", Ev, Gv }, - { "addb", Gb, Eb }, - { "addS", Gv, Ev }, - { "addb", AL, Ib }, - { "addS", eAX, Iv }, - { "pushl", es }, - { "popl", es }, - /* 08 */ - { "orb", Eb, Gb }, - { "orS", Ev, Gv }, - { "orb", Gb, Eb }, - { "orS", Gv, Ev }, - { "orb", AL, Ib }, - { "orS", eAX, Iv }, - { "pushl", cs }, - { "(bad)" }, /* 0x0f extended opcode escape */ - /* 10 */ - { "adcb", Eb, Gb }, - { "adcS", Ev, Gv }, - { "adcb", Gb, Eb }, - { "adcS", Gv, Ev }, - { "adcb", AL, Ib }, - { "adcS", eAX, Iv }, - { "pushl", ss }, - { "popl", ss }, - /* 18 */ - { "sbbb", Eb, Gb }, - { "sbbS", Ev, Gv }, - { "sbbb", Gb, Eb }, - { "sbbS", Gv, Ev }, - { "sbbb", AL, Ib }, - { "sbbS", eAX, Iv }, - { "pushl", ds }, - { "popl", ds }, - /* 20 */ - { "andb", Eb, Gb }, - { "andS", Ev, Gv }, - { "andb", Gb, Eb }, - { "andS", Gv, Ev }, - { "andb", AL, Ib }, - { "andS", eAX, Iv }, - { "(bad)" }, /* SEG ES prefix */ - { "daa" }, - /* 28 */ - { "subb", Eb, Gb }, - { "subS", Ev, Gv }, - { "subb", Gb, Eb }, - { "subS", Gv, Ev }, - { "subb", AL, Ib }, - { "subS", eAX, Iv }, - { "(bad)" }, /* SEG CS prefix */ - { "das" }, - /* 30 */ - { "xorb", Eb, Gb }, - { "xorS", Ev, Gv }, - { "xorb", Gb, Eb }, - { "xorS", Gv, Ev }, - { "xorb", AL, Ib }, - { "xorS", eAX, Iv }, - { "(bad)" }, /* SEG SS prefix */ - { "aaa" }, - /* 38 */ - { "cmpb", Eb, Gb }, - { "cmpS", Ev, Gv }, - { "cmpb", Gb, Eb }, - { "cmpS", Gv, Ev }, - { "cmpb", AL, Ib }, - { "cmpS", eAX, Iv }, - { "(bad)" }, /* SEG DS prefix */ - { "aas" }, - /* 40 */ - { "incS", eAX }, - { "incS", eCX }, - { "incS", eDX }, - { "incS", eBX }, - { "incS", eSP }, - { "incS", eBP }, - { "incS", eSI }, - { "incS", eDI }, - /* 48 */ - { "decS", eAX }, - { "decS", eCX }, - { "decS", eDX }, - { "decS", eBX }, - { "decS", eSP }, - { "decS", eBP }, - { "decS", eSI }, - { "decS", eDI }, - /* 50 */ - { "pushS", eAX }, - { "pushS", eCX }, - { "pushS", eDX }, - { "pushS", eBX }, - { "pushS", eSP }, - { "pushS", eBP }, - { "pushS", eSI }, - { "pushS", eDI }, - /* 58 */ - { "popS", eAX }, - { "popS", eCX }, - { "popS", eDX }, - { "popS", eBX }, - { "popS", eSP }, - { "popS", eBP }, - { "popS", eSI }, - { "popS", eDI }, - /* 60 */ - { "pusha" }, - { "popa" }, - { "boundS", Gv, Ma }, - { "arpl", Ew, Gw }, - { "(bad)" }, /* seg fs */ - { "(bad)" }, /* seg gs */ - { "(bad)" }, /* op size prefix */ - { "(bad)" }, /* adr size prefix */ - /* 68 */ - { "pushS", Iv }, /* 386 book wrong */ - { "imulS", Gv, Ev, Iv }, - { "pushl", sIb }, /* push of byte really pushes 4 bytes */ - { "imulS", Gv, Ev, Ib }, - { "insb", Yb, indirDX }, - { "insS", Yv, indirDX }, - { "outsb", indirDX, Xb }, - { "outsS", indirDX, Xv }, - /* 70 */ - { "jo", Jb }, - { "jno", Jb }, - { "jb", Jb }, - { "jae", Jb }, - { "je", Jb }, - { "jne", Jb }, - { "jbe", Jb }, - { "ja", Jb }, - /* 78 */ - { "js", Jb }, - { "jns", Jb }, - { "jp", Jb }, - { "jnp", Jb }, - { "jl", Jb }, - { "jnl", Jb }, - { "jle", Jb }, - { "jg", Jb }, - /* 80 */ - { GRP1b }, - { GRP1S }, - { "(bad)" }, - { GRP1Ss }, - { "testb", Eb, Gb }, - { "testS", Ev, Gv }, - { "xchgb", Eb, Gb }, - { "xchgS", Ev, Gv }, - /* 88 */ - { "movb", Eb, Gb }, - { "movS", Ev, Gv }, - { "movb", Gb, Eb }, - { "movS", Gv, Ev }, - { "movw", Ew, Sw }, - { "leaS", Gv, M }, - { "movw", Sw, Ew }, - { "popS", Ev }, - /* 90 */ - { "nop" }, - { "xchgS", eCX, eAX }, - { "xchgS", eDX, eAX }, - { "xchgS", eBX, eAX }, - { "xchgS", eSP, eAX }, - { "xchgS", eBP, eAX }, - { "xchgS", eSI, eAX }, - { "xchgS", eDI, eAX }, - /* 98 */ - { "cwtl" }, - { "cltd" }, - { "lcall", Ap }, - { "(bad)" }, /* fwait */ - { "pushf" }, - { "popf" }, - { "sahf" }, - { "lahf" }, - /* a0 */ - { "movb", AL, Ob }, - { "movS", eAX, Ov }, - { "movb", Ob, AL }, - { "movS", Ov, eAX }, - { "movsb", Yb, Xb }, - { "movsS", Yv, Xv }, - { "cmpsb", Yb, Xb }, - { "cmpsS", Yv, Xv }, - /* a8 */ - { "testb", AL, Ib }, - { "testS", eAX, Iv }, - { "stosb", Yb, AL }, - { "stosS", Yv, eAX }, - { "lodsb", AL, Xb }, - { "lodsS", eAX, Xv }, - { "scasb", AL, Xb }, - { "scasS", eAX, Xv }, - /* b0 */ - { "movb", AL, Ib }, - { "movb", CL, Ib }, - { "movb", DL, Ib }, - { "movb", BL, Ib }, - { "movb", AH, Ib }, - { "movb", CH, Ib }, - { "movb", DH, Ib }, - { "movb", BH, Ib }, - /* b8 */ - { "movS", eAX, Iv }, - { "movS", eCX, Iv }, - { "movS", eDX, Iv }, - { "movS", eBX, Iv }, - { "movS", eSP, Iv }, - { "movS", eBP, Iv }, - { "movS", eSI, Iv }, - { "movS", eDI, Iv }, - /* c0 */ - { GRP2b }, - { GRP2S }, - { "ret", Iw }, - { "ret" }, - { "lesS", Gv, Mp }, - { "ldsS", Gv, Mp }, - { "movb", Eb, Ib }, - { "movS", Ev, Iv }, - /* c8 */ - { "enter", Iw, Ib }, - { "leave" }, - { "lret", Iw }, - { "lret" }, - { "int3" }, - { "int", Ib }, - { "into" }, - { "iret" }, - /* d0 */ - { GRP2b_one }, - { GRP2S_one }, - { GRP2b_cl }, - { GRP2S_cl }, - { "aam", Ib }, - { "aad", Ib }, - { "(bad)" }, - { "xlat" }, - /* d8 */ - { FLOAT }, - { FLOAT }, - { FLOAT }, - { FLOAT }, - { FLOAT }, - { FLOAT }, - { FLOAT }, - { FLOAT }, - /* e0 */ - { "loopne", Jb }, - { "loope", Jb }, - { "loop", Jb }, - { "jCcxz", Jb }, - { "inb", AL, Ib }, - { "inS", eAX, Ib }, - { "outb", Ib, AL }, - { "outS", Ib, eAX }, - /* e8 */ - { "call", Av }, - { "jmp", Jv }, - { "ljmp", Ap }, - { "jmp", Jb }, - { "inb", AL, indirDX }, - { "inS", eAX, indirDX }, - { "outb", indirDX, AL }, - { "outS", indirDX, eAX }, - /* f0 */ - { "(bad)" }, /* lock prefix */ - { "(bad)" }, - { "(bad)" }, /* repne */ - { "(bad)" }, /* repz */ - { "hlt" }, - { "cmc" }, - { GRP3b }, - { GRP3S }, - /* f8 */ - { "clc" }, - { "stc" }, - { "cli" }, - { "sti" }, - { "cld" }, - { "std" }, - { GRP4 }, - { GRP5 }, -}; - -struct dis386 dis386_twobyte[] = { - /* 00 */ - { GRP6 }, - { GRP7 }, - { "larS", Gv, Ew }, - { "lslS", Gv, Ew }, - { "(bad)" }, - { "(bad)" }, - { "clts" }, - { "(bad)" }, - /* 08 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 10 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 18 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 20 */ - /* these are all backward in appendix A of the intel book */ - { "movl", Rd, Cd }, - { "movl", Rd, Dd }, - { "movl", Cd, Rd }, - { "movl", Dd, Rd }, - { "movl", Rd, Td }, - { "(bad)" }, - { "movl", Td, Rd }, - { "(bad)" }, - /* 28 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 30 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 38 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 40 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 48 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 50 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 58 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 60 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 68 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 70 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 78 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* 80 */ - { "jo", Jv }, - { "jno", Jv }, - { "jb", Jv }, - { "jae", Jv }, - { "je", Jv }, - { "jne", Jv }, - { "jbe", Jv }, - { "ja", Jv }, - /* 88 */ - { "js", Jv }, - { "jns", Jv }, - { "jp", Jv }, - { "jnp", Jv }, - { "jl", Jv }, - { "jge", Jv }, - { "jle", Jv }, - { "jg", Jv }, - /* 90 */ - { "seto", Eb }, - { "setno", Eb }, - { "setb", Eb }, - { "setae", Eb }, - { "sete", Eb }, - { "setne", Eb }, - { "setbe", Eb }, - { "seta", Eb }, - /* 98 */ - { "sets", Eb }, - { "setns", Eb }, - { "setp", Eb }, - { "setnp", Eb }, - { "setl", Eb }, - { "setge", Eb }, - { "setle", Eb }, - { "setg", Eb }, - /* a0 */ - { "pushl", fs }, - { "popl", fs }, - { "(bad)" }, - { "btS", Ev, Gv }, - { "shldS", Ev, Gv, Ib }, - { "shldS", Ev, Gv, CL }, - { "(bad)" }, - { "(bad)" }, - /* a8 */ - { "pushl", gs }, - { "popl", gs }, - { "(bad)" }, - { "btsS", Ev, Gv }, - { "shrdS", Ev, Gv, Ib }, - { "shrdS", Ev, Gv, CL }, - { "(bad)" }, - { "imulS", Gv, Ev }, - /* b0 */ - { "(bad)" }, - { "(bad)" }, - { "lssS", Gv, Mp }, /* 386 lists only Mp */ - { "btrS", Ev, Gv }, - { "lfsS", Gv, Mp }, /* 386 lists only Mp */ - { "lgsS", Gv, Mp }, /* 386 lists only Mp */ - { "movzbS", Gv, Eb }, - { "movzwS", Gv, Ew }, - /* b8 */ - { "(bad)" }, - { "(bad)" }, - { GRP8 }, - { "btcS", Ev, Gv }, - { "bsfS", Gv, Ev }, - { "bsrS", Gv, Ev }, - { "movsbS", Gv, Eb }, - { "movswS", Gv, Ew }, - /* c0 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* c8 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* d0 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* d8 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* e0 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* e8 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* f0 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - /* f8 */ - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, - { "(bad)" }, { "(bad)" }, { "(bad)" }, { "(bad)" }, -}; - -static char obuf[100]; -static char *obufp; -static char scratchbuf[100]; -static unsigned char *start_codep; -static unsigned char *codep; -static int mod; -static int rm; -static int reg; - -static char *names32[]={ - "%eax","%ecx","%edx","%ebx", "%esp","%ebp","%esi","%edi", -}; -static char *names16[] = { - "%ax","%cx","%dx","%bx","%sp","%bp","%si","%di", -}; -static char *names8[] = { - "%al","%cl","%dl","%bl","%ah","%ch","%dh","%bh", -}; -static char *names_seg[] = { - "%es","%cs","%ss","%ds","%fs","%gs","%?","%?", -}; - -struct dis386 grps[][8] = { - /* GRP1b */ - { - { "addb", Eb, Ib }, - { "orb", Eb, Ib }, - { "adcb", Eb, Ib }, - { "sbbb", Eb, Ib }, - { "andb", Eb, Ib }, - { "subb", Eb, Ib }, - { "xorb", Eb, Ib }, - { "cmpb", Eb, Ib } - }, - /* GRP1S */ - { - { "addS", Ev, Iv }, - { "orS", Ev, Iv }, - { "adcS", Ev, Iv }, - { "sbbS", Ev, Iv }, - { "andS", Ev, Iv }, - { "subS", Ev, Iv }, - { "xorS", Ev, Iv }, - { "cmpS", Ev, Iv } - }, - /* GRP1Ss */ - { - { "addS", Ev, sIb }, - { "orS", Ev, sIb }, - { "adcS", Ev, sIb }, - { "sbbS", Ev, sIb }, - { "andS", Ev, sIb }, - { "subS", Ev, sIb }, - { "xorS", Ev, sIb }, - { "cmpS", Ev, sIb } - }, - /* GRP2b */ - { - { "rolb", Eb, Ib }, - { "rorb", Eb, Ib }, - { "rclb", Eb, Ib }, - { "rcrb", Eb, Ib }, - { "shlb", Eb, Ib }, - { "shrb", Eb, Ib }, - { "(bad)" }, - { "sarb", Eb, Ib }, - }, - /* GRP2S */ - { - { "rolS", Ev, Ib }, - { "rorS", Ev, Ib }, - { "rclS", Ev, Ib }, - { "rcrS", Ev, Ib }, - { "shlS", Ev, Ib }, - { "shrS", Ev, Ib }, - { "(bad)" }, - { "sarS", Ev, Ib }, - }, - /* GRP2b_one */ - { - { "rolb", Eb }, - { "rorb", Eb }, - { "rclb", Eb }, - { "rcrb", Eb }, - { "shlb", Eb }, - { "shrb", Eb }, - { "(bad)" }, - { "sarb", Eb }, - }, - /* GRP2S_one */ - { - { "rolS", Ev }, - { "rorS", Ev }, - { "rclS", Ev }, - { "rcrS", Ev }, - { "shlS", Ev }, - { "shrS", Ev }, - { "(bad)" }, - { "sarS", Ev }, - }, - /* GRP2b_cl */ - { - { "rolb", Eb, CL }, - { "rorb", Eb, CL }, - { "rclb", Eb, CL }, - { "rcrb", Eb, CL }, - { "shlb", Eb, CL }, - { "shrb", Eb, CL }, - { "(bad)" }, - { "sarb", Eb, CL }, - }, - /* GRP2S_cl */ - { - { "rolS", Ev, CL }, - { "rorS", Ev, CL }, - { "rclS", Ev, CL }, - { "rcrS", Ev, CL }, - { "shlS", Ev, CL }, - { "shrS", Ev, CL }, - { "(bad)" }, - { "sarS", Ev, CL } - }, - /* GRP3b */ - { - { "testb", Eb, Ib }, - { "(bad)", Eb }, - { "notb", Eb }, - { "negb", Eb }, - { "mulb", AL, Eb }, - { "imulb", AL, Eb }, - { "divb", AL, Eb }, - { "idivb", AL, Eb } - }, - /* GRP3S */ - { - { "testS", Ev, Iv }, - { "(bad)" }, - { "notS", Ev }, - { "negS", Ev }, - { "mulS", eAX, Ev }, - { "imulS", eAX, Ev }, - { "divS", eAX, Ev }, - { "idivS", eAX, Ev }, - }, - /* GRP4 */ - { - { "incb", Eb }, - { "decb", Eb }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - }, - /* GRP5 */ - { - { "incS", Ev }, - { "decS", Ev }, - { "call", indirEv }, - { "lcall", indirEv }, - { "jmp", indirEv }, - { "ljmp", indirEv }, - { "pushS", Ev }, - { "(bad)" }, - }, - /* GRP6 */ - { - { "sldt", Ew }, - { "str", Ew }, - { "lldt", Ew }, - { "ltr", Ew }, - { "verr", Ew }, - { "verw", Ew }, - { "(bad)" }, - { "(bad)" } - }, - /* GRP7 */ - { - { "sgdt", Ew }, - { "sidt", Ew }, - { "lgdt", Ew }, - { "lidt", Ew }, - { "smsw", Ew }, - { "(bad)" }, - { "lmsw", Ew }, - { "(bad)" }, - }, - /* GRP8 */ - { - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { "btS", Ev, Ib }, - { "btsS", Ev, Ib }, - { "btrS", Ev, Ib }, - { "btcS", Ev, Ib }, - } -}; - -#define PREFIX_REPZ 1 -#define PREFIX_REPNZ 2 -#define PREFIX_LOCK 4 -#define PREFIX_CS 8 -#define PREFIX_SS 0x10 -#define PREFIX_DS 0x20 -#define PREFIX_ES 0x40 -#define PREFIX_FS 0x80 -#define PREFIX_GS 0x100 -#define PREFIX_DATA 0x200 -#define PREFIX_ADR 0x400 -#define PREFIX_FWAIT 0x800 - -static int prefixes; - -ckprefix () -{ - prefixes = 0; - while (1) - { - switch (*codep) - { - case 0xf3: - prefixes |= PREFIX_REPZ; - break; - case 0xf2: - prefixes |= PREFIX_REPNZ; - break; - case 0xf0: - prefixes |= PREFIX_LOCK; - break; - case 0x2e: - prefixes |= PREFIX_CS; - break; - case 0x36: - prefixes |= PREFIX_SS; - break; - case 0x3e: - prefixes |= PREFIX_DS; - break; - case 0x26: - prefixes |= PREFIX_ES; - break; - case 0x64: - prefixes |= PREFIX_FS; - break; - case 0x65: - prefixes |= PREFIX_GS; - break; - case 0x66: - prefixes |= PREFIX_DATA; - break; - case 0x67: - prefixes |= PREFIX_ADR; - break; - case 0x9b: - prefixes |= PREFIX_FWAIT; - break; - default: - return; - } - codep++; - } -} - -static int dflag; -static int aflag; - -static char op1out[100], op2out[100], op3out[100]; -static int start_pc; - -/* - * disassemble the first instruction in 'inbuf'. You have to make - * sure all of the bytes of the instruction are filled in. - * On the 386's of 1988, the maximum length of an instruction is 15 bytes. - * (see topic "Redundant prefixes" in the "Differences from 8086" - * section of the "Virtual 8086 Mode" chapter.) - * 'pc' should be the address of this instruction, it will - * be used to print the target address if this is a relative jump or call - * 'outbuf' gets filled in with the disassembled instruction. it should - * be long enough to hold the longest disassembled instruction. - * 100 bytes is certainly enough, unless symbol printing is added later - * The function returns the length of this instruction in bytes. - */ -i386dis (pc, inbuf, outbuf) - int pc; - unsigned char *inbuf; - char *outbuf; -{ - struct dis386 *dp; - char *p; - int i; - int enter_instruction; - char *first, *second, *third; - int needcomma; - - obuf[0] = 0; - op1out[0] = 0; - op2out[0] = 0; - op3out[0] = 0; - - start_pc = pc; - start_codep = inbuf; - codep = inbuf; - - ckprefix (); - - if (*codep == 0xc8) - enter_instruction = 1; - else - enter_instruction = 0; - - obufp = obuf; - - if (prefixes & PREFIX_REPZ) - oappend ("repz "); - if (prefixes & PREFIX_REPNZ) - oappend ("repnz "); - if (prefixes & PREFIX_LOCK) - oappend ("lock "); - - if ((prefixes & PREFIX_FWAIT) - && ((*codep < 0xd8) || (*codep > 0xdf))) - { - /* fwait not followed by floating point instruction */ - oappend ("fwait"); - strcpy (outbuf, obuf); - return (1); - } - - /* these would be initialized to 0 if disassembling for 8086 or 286 */ - dflag = 1; - aflag = 1; - - if (prefixes & PREFIX_DATA) - dflag ^= 1; - - if (prefixes & PREFIX_ADR) - { - aflag ^= 1; - oappend ("addr16 "); - } - - if (*codep == 0x0f) - dp = &dis386_twobyte[*++codep]; - else - dp = &dis386[*codep]; - codep++; - mod = (*codep >> 6) & 3; - reg = (*codep >> 3) & 7; - rm = *codep & 7; - - if (dp->name == NULL && dp->bytemode1 == FLOATCODE) - { - dofloat (); - } - else - { - if (dp->name == NULL) - dp = &grps[dp->bytemode1][reg]; - - putop (dp->name); - - obufp = op1out; - if (dp->op1) - (*dp->op1)(dp->bytemode1); - - obufp = op2out; - if (dp->op2) - (*dp->op2)(dp->bytemode2); - - obufp = op3out; - if (dp->op3) - (*dp->op3)(dp->bytemode3); - } - - obufp = obuf + strlen (obuf); - for (i = strlen (obuf); i < 6; i++) - oappend (" "); - oappend (" "); - - /* enter instruction is printed with operands in the - * same order as the intel book; everything else - * is printed in reverse order - */ - if (enter_instruction) - { - first = op1out; - second = op2out; - third = op3out; - } - else - { - first = op3out; - second = op2out; - third = op1out; - } - needcomma = 0; - if (*first) - { - oappend (first); - needcomma = 1; - } - if (*second) - { - if (needcomma) - oappend (","); - oappend (second); - needcomma = 1; - } - if (*third) - { - if (needcomma) - oappend (","); - oappend (third); - } - strcpy (outbuf, obuf); - return (codep - inbuf); -} - -char *float_mem[] = { - /* d8 */ - "fadds", - "fmuls", - "fcoms", - "fcomps", - "fsubs", - "fsubrs", - "fdivs", - "fdivrs", - /* d9 */ - "flds", - "(bad)", - "fsts", - "fstps", - "fldenv", - "fldcw", - "fNstenv", - "fNstcw", - /* da */ - "fiaddl", - "fimull", - "ficoml", - "ficompl", - "fisubl", - "fisubrl", - "fidivl", - "fidivrl", - /* db */ - "fildl", - "(bad)", - "fistl", - "fistpl", - "(bad)", - "fldt", - "(bad)", - "fstpt", - /* dc */ - "faddl", - "fmull", - "fcoml", - "fcompl", - "fsubl", - "fsubrl", - "fdivl", - "fdivrl", - /* dd */ - "fldl", - "(bad)", - "fstl", - "fstpl", - "frstor", - "(bad)", - "fNsave", - "fNstsw", - /* de */ - "fiadd", - "fimul", - "ficom", - "ficomp", - "fisub", - "fisubr", - "fidiv", - "fidivr", - /* df */ - "fild", - "(bad)", - "fist", - "fistp", - "fbld", - "fildll", - "fbstp", - "fistpll", -}; - -#define ST OP_ST, 0 -#define STi OP_STi, 0 -int OP_ST(), OP_STi(); - -#define FGRPd9_2 NULL, NULL, 0 -#define FGRPd9_4 NULL, NULL, 1 -#define FGRPd9_5 NULL, NULL, 2 -#define FGRPd9_6 NULL, NULL, 3 -#define FGRPd9_7 NULL, NULL, 4 -#define FGRPda_5 NULL, NULL, 5 -#define FGRPdb_4 NULL, NULL, 6 -#define FGRPde_3 NULL, NULL, 7 -#define FGRPdf_4 NULL, NULL, 8 - -struct dis386 float_reg[][8] = { - /* d8 */ - { - { "fadd", ST, STi }, - { "fmul", ST, STi }, - { "fcom", STi }, - { "fcomp", STi }, - { "fsub", ST, STi }, - { "fsubr", ST, STi }, - { "fdiv", ST, STi }, - { "fdivr", ST, STi }, - }, - /* d9 */ - { - { "fld", STi }, - { "fxch", STi }, - { FGRPd9_2 }, - { "(bad)" }, - { FGRPd9_4 }, - { FGRPd9_5 }, - { FGRPd9_6 }, - { FGRPd9_7 }, - }, - /* da */ - { - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { FGRPda_5 }, - { "(bad)" }, - { "(bad)" }, - }, - /* db */ - { - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { FGRPdb_4 }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - }, - /* dc */ - { - { "fadd", STi, ST }, - { "fmul", STi, ST }, - { "(bad)" }, - { "(bad)" }, - { "fsub", STi, ST }, - { "fsubr", STi, ST }, - { "fdiv", STi, ST }, - { "fdivr", STi, ST }, - }, - /* dd */ - { - { "ffree", STi }, - { "(bad)" }, - { "fst", STi }, - { "fstp", STi }, - { "fucom", STi }, - { "fucomp", STi }, - { "(bad)" }, - { "(bad)" }, - }, - /* de */ - { - { "faddp", STi, ST }, - { "fmulp", STi, ST }, - { "(bad)" }, - { FGRPde_3 }, - { "fsubp", STi, ST }, - { "fsubrp", STi, ST }, - { "fdivp", STi, ST }, - { "fdivrp", STi, ST }, - }, - /* df */ - { - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - { FGRPdf_4 }, - { "(bad)" }, - { "(bad)" }, - { "(bad)" }, - }, -}; - - -char *fgrps[][8] = { - /* d9_2 0 */ - { - "fnop","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)", - }, - - /* d9_4 1 */ - { - "fchs","fabs","(bad)","(bad)","ftst","fxam","(bad)","(bad)", - }, - - /* d9_5 2 */ - { - "fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2","fldz","(bad)", - }, - - /* d9_6 3 */ - { - "f2xm1","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp", - }, - - /* d9_7 4 */ - { - "fprem","fyl2xp1","fsqrt","fsincos","frndint","fscale","fsin","fcos", - }, - - /* da_5 5 */ - { - "(bad)","fucompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)", - }, - - /* db_4 6 */ - { - "feni(287 only)","fdisi(287 only)","fNclex","fNinit", - "fNsetpm(287 only)","(bad)","(bad)","(bad)", - }, - - /* de_3 7 */ - { - "(bad)","fcompp","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)", - }, - - /* df_4 8 */ - { - "fNstsw","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)", - }, -}; - - -dofloat () -{ - struct dis386 *dp; - unsigned char floatop; - - floatop = codep[-1]; - - if (mod != 3) - { - putop (float_mem[(floatop - 0xd8) * 8 + reg]); - obufp = op1out; - OP_E (v_mode); - return; - } - codep++; - - dp = &float_reg[floatop - 0xd8][reg]; - if (dp->name == NULL) - { - putop (fgrps[dp->bytemode1][rm]); - /* instruction fnstsw is only one with strange arg */ - if (floatop == 0xdf && *codep == 0xe0) - strcpy (op1out, "%eax"); - } - else - { - putop (dp->name); - obufp = op1out; - if (dp->op1) - (*dp->op1)(dp->bytemode1); - obufp = op2out; - if (dp->op2) - (*dp->op2)(dp->bytemode2); - } -} - -/* ARGSUSED */ -OP_ST (ignore) -{ - oappend ("%st"); -} - -/* ARGSUSED */ -OP_STi (ignore) -{ - sprintf (scratchbuf, "%%st(%d)", rm); - oappend (scratchbuf); -} - - -/* capital letters in template are macros */ -putop (template) - char *template; -{ - char *p; - - for (p = template; *p; p++) - { - switch (*p) - { - default: - *obufp++ = *p; - break; - case 'C': /* For jcxz/jecxz */ - if (aflag == 0) - *obufp++ = 'e'; - break; - case 'N': - if ((prefixes & PREFIX_FWAIT) == 0) - *obufp++ = 'n'; - break; - case 'S': - /* operand size flag */ - if (dflag) - *obufp++ = 'l'; - else - *obufp++ = 'w'; - break; - } - } - *obufp = 0; -} - -oappend (s) -char *s; -{ - strcpy (obufp, s); - obufp += strlen (s); - *obufp = 0; -} - -append_prefix () -{ - if (prefixes & PREFIX_CS) - oappend ("%cs:"); - if (prefixes & PREFIX_DS) - oappend ("%ds:"); - if (prefixes & PREFIX_SS) - oappend ("%ss:"); - if (prefixes & PREFIX_ES) - oappend ("%es:"); - if (prefixes & PREFIX_FS) - oappend ("%fs:"); - if (prefixes & PREFIX_GS) - oappend ("%gs:"); -} - -OP_indirE (bytemode) -{ - oappend ("*"); - OP_E (bytemode); -} - -OP_E (bytemode) -{ - int disp; - int havesib; - int didoutput = 0; - int base; - int index; - int scale; - int havebase; - - /* skip mod/rm byte */ - codep++; - - havesib = 0; - havebase = 0; - disp = 0; - - if (mod == 3) - { - switch (bytemode) - { - case b_mode: - oappend (names8[rm]); - break; - case w_mode: - oappend (names16[rm]); - break; - case v_mode: - if (dflag) - oappend (names32[rm]); - else - oappend (names16[rm]); - break; - default: - oappend (""); - break; - } - return; - } - - append_prefix (); - if (rm == 4) - { - havesib = 1; - havebase = 1; - scale = (*codep >> 6) & 3; - index = (*codep >> 3) & 7; - base = *codep & 7; - codep++; - } - - switch (mod) - { - case 0: - switch (rm) - { - case 4: - /* implies havesib and havebase */ - if (base == 5) { - havebase = 0; - disp = get32 (); - } - break; - case 5: - disp = get32 (); - break; - default: - havebase = 1; - base = rm; - break; - } - break; - case 1: - disp = *(char *)codep++; - if (rm != 4) - { - havebase = 1; - base = rm; - } - break; - case 2: - disp = get32 (); - if (rm != 4) - { - havebase = 1; - base = rm; - } - break; - } - - if (mod != 0 || rm == 5 || (havesib && base == 5)) - { - sprintf (scratchbuf, "%d", disp); - oappend (scratchbuf); - } - - if (havebase || havesib) - { - oappend ("("); - if (havebase) - oappend (names32[base]); - if (havesib) - { - if (index != 4) - { - sprintf (scratchbuf, ",%s", names32[index]); - oappend (scratchbuf); - } - sprintf (scratchbuf, ",%d", 1 << scale); - oappend (scratchbuf); - } - oappend (")"); - } -} - -OP_G (bytemode) -{ - switch (bytemode) - { - case b_mode: - oappend (names8[reg]); - break; - case w_mode: - oappend (names16[reg]); - break; - case d_mode: - oappend (names32[reg]); - break; - case v_mode: - if (dflag) - oappend (names32[reg]); - else - oappend (names16[reg]); - break; - default: - oappend (""); - break; - } -} - -get32 () -{ - int x = 0; - - x = *codep++ & 0xff; - x |= (*codep++ & 0xff) << 8; - x |= (*codep++ & 0xff) << 16; - x |= (*codep++ & 0xff) << 24; - return (x); -} - -get16 () -{ - int x = 0; - - x = *codep++ & 0xff; - x |= (*codep++ & 0xff) << 8; - return (x); -} - -OP_REG (code) -{ - char *s; - - switch (code) - { - case indir_dx_reg: s = "(%dx)"; break; - case ax_reg: case cx_reg: case dx_reg: case bx_reg: - case sp_reg: case bp_reg: case si_reg: case di_reg: - s = names16[code - ax_reg]; - break; - case es_reg: case ss_reg: case cs_reg: - case ds_reg: case fs_reg: case gs_reg: - s = names_seg[code - es_reg]; - break; - case al_reg: case ah_reg: case cl_reg: case ch_reg: - case dl_reg: case dh_reg: case bl_reg: case bh_reg: - s = names8[code - al_reg]; - break; - case eAX_reg: case eCX_reg: case eDX_reg: case eBX_reg: - case eSP_reg: case eBP_reg: case eSI_reg: case eDI_reg: - if (dflag) - s = names32[code - eAX_reg]; - else - s = names16[code - eAX_reg]; - break; - default: - s = ""; - break; - } - oappend (s); -} - -OP_I (bytemode) -{ - int op; - - switch (bytemode) - { - case b_mode: - op = *codep++ & 0xff; - break; - case v_mode: - if (dflag) - op = get32 (); - else - op = get16 (); - break; - case w_mode: - op = get16 (); - break; - default: - oappend (""); - return; - } - sprintf (scratchbuf, "$0x%x", op); - oappend (scratchbuf); -} - -OP_sI (bytemode) -{ - int op; - - switch (bytemode) - { - case b_mode: - op = *(char *)codep++; - break; - case v_mode: - if (dflag) - op = get32 (); - else - op = (short)get16(); - break; - case w_mode: - op = (short)get16 (); - break; - default: - oappend (""); - return; - } - sprintf (scratchbuf, "$0x%x", op); - oappend (scratchbuf); -} - -OP_J (bytemode) -{ - int disp; - int mask = -1; - - switch (bytemode) - { - case b_mode: - disp = *(char *)codep++; - break; - case v_mode: - if (dflag) - disp = get32 (); - else - { - disp = (short)get16 (); - /* for some reason, a data16 prefix on a jump instruction - means that the pc is masked to 16 bits after the - displacement is added! */ - mask = 0xffff; - } - break; - default: - oappend (""); - return; - } - - sprintf (scratchbuf, "0x%x", - (start_pc + codep - start_codep + disp) & mask); - oappend (scratchbuf); -} - -/* ARGSUSED */ -OP_SEG (dummy) -{ - static char *sreg[] = { - "%es","%cs","%ss","%ds","%fs","%gs","%?","%?", - }; - - oappend (sreg[reg]); -} - -OP_DIR (size) -{ - int seg, offset; - - switch (size) - { - case lptr: - if (aflag) - { - offset = get32 (); - seg = get16 (); - } - else - { - offset = get16 (); - seg = get16 (); - } - sprintf (scratchbuf, "0x%x,0x%x", seg, offset); - oappend (scratchbuf); - break; - case v_mode: - if (aflag) - offset = get32 (); - else - offset = (short)get16 (); - - sprintf (scratchbuf, "0x%x", - start_pc + codep - start_codep + offset); - oappend (scratchbuf); - break; - default: - oappend (""); - break; - } -} - -/* ARGSUSED */ -OP_OFF (bytemode) -{ - int off; - - if (aflag) - off = get32 (); - else - off = get16 (); - - sprintf (scratchbuf, "0x%x", off); - oappend (scratchbuf); -} - -/* ARGSUSED */ -OP_ESDI (dummy) -{ - oappend ("%es:("); - oappend (aflag ? "%edi" : "%di"); - oappend (")"); -} - -/* ARGSUSED */ -OP_DSSI (dummy) -{ - oappend ("%ds:("); - oappend (aflag ? "%esi" : "%si"); - oappend (")"); -} - -/* ARGSUSED */ -OP_ONE (dummy) -{ - oappend ("1"); -} - -/* ARGSUSED */ -OP_C (dummy) -{ - codep++; /* skip mod/rm */ - sprintf (scratchbuf, "%%cr%d", reg); - oappend (scratchbuf); -} - -/* ARGSUSED */ -OP_D (dummy) -{ - codep++; /* skip mod/rm */ - sprintf (scratchbuf, "%%db%d", reg); - oappend (scratchbuf); -} - -/* ARGSUSED */ -OP_T (dummy) -{ - codep++; /* skip mod/rm */ - sprintf (scratchbuf, "%%tr%d", reg); - oappend (scratchbuf); -} - -OP_rm (bytemode) -{ - switch (bytemode) - { - case d_mode: - oappend (names32[rm]); - break; - case w_mode: - oappend (names16[rm]); - break; - } -} - -/* GDB interface */ -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "frame.h" -#include "inferior.h" - -#define MAXLEN 20 -print_insn (memaddr, stream) - CORE_ADDR memaddr; - FILE *stream; -{ - unsigned char buffer[MAXLEN]; - /* should be expanded if disassembler prints symbol names */ - char outbuf[100]; - int n; - - read_memory (memaddr, buffer, MAXLEN); - - n = i386dis ((int)memaddr, buffer, outbuf); - - fputs (outbuf, stream); - - return (n); -} - diff --git a/gnu/usr.bin/gdb/config/i386bsd-dep.c b/gnu/usr.bin/gdb/config/i386bsd-dep.c deleted file mode 100644 index 16286ee..0000000 --- a/gnu/usr.bin/gdb/config/i386bsd-dep.c +++ /dev/null @@ -1,1889 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)i386bsd-dep.c 6.10 (Berkeley) 6/26/91"; -#endif /* not lint */ - -/* Low level interface to ptrace, for GDB when running on the Intel 386. - Copyright (C) 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "frame.h" -#include "inferior.h" -#include "value.h" - -#include -#include -#include -#include -#include - -#include - -#ifndef N_SET_MAGIC -#define N_SET_MAGIC(exec, val) ((exec).a_magic = (val)) -#endif - -#include -#include -#include -#define curpcb Xcurpcb /* XXX avoid leaking declaration from pcb.h */ -#include -#undef curpcb -#include -#include -#include - -#include - -#ifdef KERNELDEBUG -#ifndef NEWVM -#include -#include -#else -#include /* for curproc */ -#endif -#include -#include -#include -#include "symtab.h" /* XXX */ - -#undef vtophys /* XXX */ - -extern int kernel_debugging; - -#define KERNOFF ((unsigned)KERNBASE) -#ifndef NEWVM -#define INKERNEL(x) ((x) >= KERNOFF && (x) < KERNOFF + ctob(slr)) -#define INUPAGE(x) \ - ((x) >= KERNEL_U_ADDR && (x) < KERNEL_U_ADDR + NBPG) -#else -#define INKERNEL(x) ((x) >= KERNOFF) -#endif - -#define PT_ADDR_ANY ((caddr_t) 1) - -/* - * Convert from sysmap pte index to system virtual address & vice-versa. - * (why aren't these in one of the system vm macro files???) - */ -#define smxtob(a) (sbr + (a) * sizeof(pte)) -#define btosmx(b) (((b) - sbr) / sizeof(pte)) - -static int ok_to_cache(); -static int found_pcb; -#ifdef NEWVM -static CORE_ADDR curpcb; -static CORE_ADDR kstack; -#endif - -static void setregmap(); - -extern int errno; - -/* - * This function simply calls ptrace with the given arguments. It exists so - * that all calls to ptrace are isolated in this machine-dependent file. - */ -int -call_ptrace(request, pid, arg3, arg4) - int request; - pid_t pid; - caddr_t arg3; - int arg4; -{ - return(ptrace(request, pid, arg3, arg4)); -} - -kill_inferior() -{ - if (remote_debugging) { -#ifdef KERNELDEBUG - if (kernel_debugging) - /* - * It's a very, very bad idea to go away leaving - * breakpoints in a remote kernel or to leave it - * stopped at a breakpoint. - */ - clear_breakpoints(); -#endif - remote_close(0); - inferior_died(); - } else if (inferior_pid != 0) { - ptrace(PT_KILL, inferior_pid, 0, 0); - wait(0); - inferior_died(); - } -} - -/* - * This is used when GDB is exiting. It gives less chance of error. - */ -kill_inferior_fast() -{ - if (remote_debugging) { -#ifdef KERNELDEBUG - if (kernel_debugging) - clear_breakpoints(); -#endif - remote_close(0); - return; - } - if (inferior_pid == 0) - return; - - ptrace(PT_KILL, inferior_pid, 0, 0); - wait(0); -} - -/* - * Resume execution of the inferior process. If STEP is nonzero, single-step - * it. If SIGNAL is nonzero, give it that signal. - */ -void -resume(step, signal) - int step; - int signal; -{ - errno = 0; - if (remote_debugging) - remote_resume(step, signal); - else { - ptrace(step ? PT_STEP : PT_CONTINUE, inferior_pid, - PT_ADDR_ANY, signal); - if (errno) - perror_with_name("ptrace"); - } -} - -#ifdef ATTACH_DETACH -extern int attach_flag; - -/* - * Start debugging the process whose number is PID. - */ -attach(pid) - int pid; -{ - errno = 0; - ptrace(PT_ATTACH, pid, 0, 0); - if (errno) - perror_with_name("ptrace"); - attach_flag = 1; - return pid; -} - -/* - * Stop debugging the process whose number is PID and continue it - * with signal number SIGNAL. SIGNAL = 0 means just continue it. - */ -void -detach(signal) - int signal; -{ - errno = 0; - ptrace(PT_DETACH, inferior_pid, PT_ADDR_ANY, signal); - if (errno) - perror_with_name("ptrace"); - attach_flag = 0; -} -#endif /* ATTACH_DETACH */ - -static unsigned int -get_register_offset() -{ - unsigned int offset; - struct user u; /* XXX */ - unsigned int flags = (char *) &u.u_pcb.pcb_flags - (char *) &u; - - setregmap(ptrace(PT_READ_U, inferior_pid, (caddr_t)flags, 0)); - -#ifdef NEWVM - offset = (char *) &u.u_kproc.kp_proc.p_regs - (char *) &u; - offset = ptrace(PT_READ_U, inferior_pid, (caddr_t)offset, 0) - - USRSTACK; -#else - offset = (char *) &u.u_ar0 - (char *) &u; - offset = ptrace(PT_READ_U, inferior_pid, (caddr_t)offset, 0) - - KERNEL_U_ADDR; -#endif - - return offset; -} - -void -fetch_inferior_registers() -{ - register int regno; - register unsigned int regaddr; - char buf[MAX_REGISTER_RAW_SIZE]; - register int i; - unsigned int offset; - - if (remote_debugging) { - extern char registers[]; - - remote_fetch_registers(registers); - return; - } - - offset = get_register_offset(); - - for (regno = 0; regno < NUM_REGS; regno++) { - regaddr = register_addr(regno, offset); - for (i = 0; i < REGISTER_RAW_SIZE(regno); i += sizeof(int)) { - *(int *)&buf[i] = ptrace(PT_READ_U, inferior_pid, - (caddr_t)regaddr, 0); - regaddr += sizeof(int); - } - supply_register(regno, buf); - } -} - -/* - * Store our register values back into the inferior. If REGNO is -1, do this - * for all registers. Otherwise, REGNO specifies which register (so we can - * save time). - */ -store_inferior_registers(regno) - int regno; -{ - register unsigned int regaddr; - char buf[80]; - extern char registers[]; - register int i; - unsigned int offset; - - if (remote_debugging) { - extern char registers[]; - - remote_store_registers(registers); - return; - } - - offset = get_register_offset(); - - if (regno >= 0) { - regaddr = register_addr(regno, offset); - for (i = 0; i < REGISTER_RAW_SIZE(regno); i += sizeof(int)) { - errno = 0; - ptrace(PT_WRITE_U, inferior_pid, (caddr_t)regaddr, - *(int *) ®isters[REGISTER_BYTE(regno) + i]); - if (errno != 0) { - sprintf(buf, "writing register number %d(%d)", - regno, i); - perror_with_name(buf); - } - regaddr += sizeof(int); - } - } else - for (regno = 0; regno < NUM_REGS; regno++) { - regaddr = register_addr(regno, offset); - for (i = 0; i < REGISTER_RAW_SIZE(regno); - i += sizeof(int)) { - errno = 0; - ptrace(PT_WRITE_U, inferior_pid, - (caddr_t)regaddr, - *(int *) ®isters[REGISTER_BYTE(regno) + i]); - if (errno != 0) { - sprintf(buf, - "writing register number %d(%d)", - regno, i); - perror_with_name(buf); - } - regaddr += sizeof(int); - } - } -} - -/* - * Copy LEN bytes from inferior's memory starting at MEMADDR to debugger - * memory starting at MYADDR. On failure (cannot read from inferior, usually - * because address is out of bounds) returns the value of errno. - */ -int -read_inferior_memory(memaddr, myaddr, len) - CORE_ADDR memaddr; - char *myaddr; - int len; -{ - register int i; - /* Round starting address down to longword boundary. */ - register CORE_ADDR addr = memaddr & -sizeof(int); - /* Round ending address up; get number of longwords that makes. */ - register int count = (((memaddr + len) - addr) + sizeof(int) - 1) / - sizeof(int); - /* Allocate buffer of that many longwords. */ - register int *buffer = (int *) alloca(count * sizeof(int)); - extern int errno; - - if (remote_debugging) - return (remote_read_inferior_memory(memaddr, myaddr, len)); - - /* Read all the longwords */ - errno = 0; - for (i = 0; i < count && errno == 0; i++, addr += sizeof(int)) - buffer[i] = ptrace(PT_READ_I, inferior_pid, (caddr_t)addr, 0); - - /* Copy appropriate bytes out of the buffer. */ - bcopy((char *) buffer + (memaddr & (sizeof(int) - 1)), myaddr, len); - return(errno); -} - -/* - * Copy LEN bytes of data from debugger memory at MYADDR to inferior's memory - * at MEMADDR. On failure (cannot write the inferior) returns the value of - * errno. - */ - -int -write_inferior_memory(memaddr, myaddr, len) - CORE_ADDR memaddr; - char *myaddr; - int len; -{ - register int i; - /* Round starting address down to longword boundary. */ - register CORE_ADDR addr = memaddr & -sizeof(int); - /* Round ending address up; get number of longwords that makes. */ - register int count = (((memaddr + len) - addr) + sizeof(int) - 1) / - sizeof(int); - /* Allocate buffer of that many longwords. */ - register int *buffer = (int *) alloca(count * sizeof(int)); - extern int errno; - - /* - * Fill start and end extra bytes of buffer with existing memory - * data. - */ - if (remote_debugging) - return (remote_write_inferior_memory(memaddr, myaddr, len)); - - /* - * Fill start and end extra bytes of buffer with existing memory - * data. - */ - buffer[0] = ptrace(PT_READ_I, inferior_pid, (caddr_t)addr, 0); - - if (count > 1) - buffer[count - 1] = ptrace(PT_READ_I, inferior_pid, - (caddr_t)addr + (count - 1) * sizeof(int), 0); - - /* Copy data to be written over corresponding part of buffer */ - - bcopy(myaddr, (char *) buffer + (memaddr & (sizeof(int) - 1)), len); - - /* Write the entire buffer. */ - - errno = 0; - for (i = 0; i < count && errno == 0; i++, addr += sizeof(int)) - ptrace(PT_WRITE_I, inferior_pid, (caddr_t)addr, buffer[i]); - - return(errno); -} - - -/* - * Work with core dump and executable files, for GDB. - * This code would be in core.c if it weren't machine-dependent. - */ - -#ifndef N_TXTADDR -#define N_TXTADDR(hdr) 0 -#endif /* no N_TXTADDR */ - -#ifndef N_DATADDR -#define N_DATADDR(hdr) hdr.a_text -#endif /* no N_DATADDR */ - -/* - * Make COFF and non-COFF names for things a little more compatible to reduce - * conditionals later. - */ - -#ifndef AOUTHDR -#define AOUTHDR struct exec -#endif - -extern char *sys_siglist[]; - - -/* Hook for `exec_file_command' command to call. */ - -extern void (*exec_file_display_hook) (); - -/* File names of core file and executable file. */ - -extern char *corefile; -extern char *execfile; - -/* Descriptors on which core file and executable file are open. - Note that the execchan is closed when an inferior is created - and reopened if the inferior dies or is killed. */ - -extern int corechan; -extern int execchan; - -/* Last modification time of executable file. - Also used in source.c to compare against mtime of a source file. */ - -extern int exec_mtime; - -/* Virtual addresses of bounds of the two areas of memory in the core file. */ - -extern CORE_ADDR data_start; -extern CORE_ADDR data_end; -extern CORE_ADDR stack_start; -extern CORE_ADDR stack_end; - -/* Virtual addresses of bounds of two areas of memory in the exec file. - Note that the data area in the exec file is used only when there is no core file. */ - -extern CORE_ADDR text_start; -extern CORE_ADDR text_end; - -extern CORE_ADDR exec_data_start; -extern CORE_ADDR exec_data_end; - -/* Address in executable file of start of text area data. */ - -extern int text_offset; - -/* Address in executable file of start of data area data. */ - -extern int exec_data_offset; - -/* Address in core file of start of data area data. */ - -extern int data_offset; - -/* Address in core file of start of stack area data. */ - -extern int stack_offset; - -/* a.out header saved in core file. */ - -extern AOUTHDR core_aouthdr; - -/* a.out header of exec file. */ - -extern AOUTHDR exec_aouthdr; - -extern void validate_files (); - -extern int (*core_file_hook)(); - -#ifdef KERNELDEBUG -/* - * Kernel debugging routines. - */ - -#define IOTOP 0x100000 /* XXX should get this from include file */ -#define IOBASE 0xa0000 /* XXX should get this from include file */ - -static CORE_ADDR file_offset; -static CORE_ADDR lowram; -static CORE_ADDR sbr; -static CORE_ADDR slr; -static struct pcb pcb; - -static CORE_ADDR -ksym_lookup(name) - char *name; -{ - struct symbol *sym; - int i; - - if ((i = lookup_misc_func(name)) < 0) - error("kernel symbol `%s' not found.", name); - - return (misc_function_vector[i].address); -} - -/* - * return true if 'len' bytes starting at 'addr' can be read out as - * longwords and/or locally cached (this is mostly for memory mapped - * i/o register access when debugging remote kernels). - * - * XXX the HP code does this differently with NEWVM - */ -static int -ok_to_cache(addr, len) -{ - static CORE_ADDR atdevbase; - - if (! atdevbase) - atdevbase = ksym_lookup("atdevbase"); - - if (addr >= atdevbase && addr < atdevbase + (IOTOP - IOBASE)) - return (0); - - return (1); -} - -static -physrd(addr, dat, len) - u_int addr; - char *dat; -{ - if (lseek(corechan, addr - file_offset, L_SET) == -1) - return (-1); - if (read(corechan, dat, len) != len) - return (-1); - - return (0); -} - -/* - * When looking at kernel data space through /dev/mem or with a core file, do - * virtual memory mapping. - */ -#ifdef NEWVM -static CORE_ADDR -vtophys(addr) - CORE_ADDR addr; -{ - CORE_ADDR v; - struct pte pte; - static CORE_ADDR PTD = -1; - CORE_ADDR current_ptd; - - /* - * If we're looking at the kernel stack, - * munge the address to refer to the user space mapping instead; - * that way we get the requested process's kstack, not the running one. - */ - if (addr >= kstack && addr < kstack + ctob(UPAGES)) - addr = (addr - kstack) + curpcb; - - /* - * We may no longer have a linear system page table... - * - * Here's the scoop. IdlePTD contains the physical address - * of a page table directory that always maps the kernel. - * IdlePTD is in memory that is mapped 1-to-1, so we can - * find it easily given its 'virtual' address from ksym_lookup(). - * For hysterical reasons, the value of IdlePTD is stored in sbr. - * - * To look up a kernel address, we first convert it to a 1st-level - * address and look it up in IdlePTD. This gives us the physical - * address of a page table page; we extract the 2nd-level part of - * VA and read the 2nd-level pte. Finally, we add the offset part - * of the VA into the physical address from the pte and return it. - * - * User addresses are a little more complicated. If we don't have - * a current PCB from read_pcb(), we use PTD, which is the (fixed) - * virtual address of the current ptd. Since it's NOT in 1-to-1 - * kernel space, we must look it up using IdlePTD. If we do have - * a pcb, we get the ptd from pcb_ptd. - */ - - if (INKERNEL(addr)) - current_ptd = sbr; - else if (found_pcb == 0) { - if (PTD == -1) - PTD = vtophys(ksym_lookup("PTD")); - current_ptd = PTD; - } else - current_ptd = pcb.pcb_ptd; - - /* - * Read the first-level page table (ptd). - */ - v = current_ptd + ((unsigned)addr >> PD_SHIFT) * sizeof pte; - if (physrd(v, (char *)&pte, sizeof pte) || pte.pg_v == 0) - return (~0); - - /* - * Read the second-level page table. - */ - v = i386_ptob(pte.pg_pfnum) + ((addr&PT_MASK) >> PG_SHIFT) * sizeof pte; - if (physrd(v, (char *) &pte, sizeof(pte)) || pte.pg_v == 0) - return (~0); - - addr = i386_ptob(pte.pg_pfnum) + (addr & PGOFSET); -#if 0 - printf("vtophys(%x) -> %x\n", oldaddr, addr); -#endif - return (addr); -} -#else -static CORE_ADDR -vtophys(addr) - CORE_ADDR addr; -{ - CORE_ADDR v; - struct pte pte; - CORE_ADDR oldaddr = addr; - - if (found_pcb == 0 && INUPAGE(addr)) { - static CORE_ADDR pSwtchmap; - - if (pSwtchmap == 0) - pSwtchmap = vtophys(ksym_lookup("Swtchmap")); - addr = pSwtchmap; - } else if (INKERNEL(addr)) { - /* - * In system space get system pte. If valid or reclaimable - * then physical address is combination of its page number - * and the page offset of the original address. - */ - addr = smxtob(btop(addr - KERNOFF)) - KERNOFF; - } else { - v = btop(addr); - if (v < pcb.pcb_p0lr) - addr = (CORE_ADDR) pcb.pcb_p0br + - v * sizeof (struct pte); - else if (v >= pcb.pcb_p1lr && v < P1PAGES) - addr = (CORE_ADDR) pcb.pcb_p0br + - ((pcb.pcb_szpt * NPTEPG - HIGHPAGES) - - (BTOPUSRSTACK - v)) * sizeof (struct pte); - else - return (~0); - - /* - * For p0/p1 address, user-level page table should be in - * kernel vm. Do second-level indirect by recursing. - */ - if (!INKERNEL(addr)) - return (~0); - - addr = vtophys(addr); - } - /* - * Addr is now address of the pte of the page we are interested in; - * get the pte and paste up the physical address. - */ - if (physrd(addr, (char *) &pte, sizeof(pte))) - return (~0); - - if (pte.pg_v == 0 && (pte.pg_fod || pte.pg_pfnum == 0)) - return (~0); - - addr = (CORE_ADDR)ptob(pte.pg_pfnum) + (oldaddr & PGOFSET); -#if 0 - printf("vtophys(%x) -> %x\n", oldaddr, addr); -#endif - return (addr); -} - -#endif - -static -kvread(addr) - CORE_ADDR addr; -{ - CORE_ADDR paddr = vtophys(addr); - - if (paddr != ~0) - if (physrd(paddr, (char *)&addr, sizeof(addr)) == 0); - return (addr); - - return (~0); -} - -static void -read_pcb(uaddr) - u_int uaddr; -{ - int i; - int *pcb_regs = (int *)&pcb; - -#ifdef NEWVM - if (physrd(uaddr, (char *)&pcb, sizeof pcb)) - error("cannot read pcb at %x\n", uaddr); - printf("current pcb at %x\n", uaddr); -#else - if (physrd(uaddr, (char *)&pcb, sizeof pcb)) - error("cannot read pcb at %x\n", uaddr); - printf("p0br %x p0lr %x p1br %x p1lr %x\n", - pcb.pcb_p0br, pcb.pcb_p0lr, pcb.pcb_p1br, pcb.pcb_p1lr); -#endif - - /* - * get the register values out of the sys pcb and - * store them where `read_register' will find them. - */ - for (i = 0; i < 8; ++i) - supply_register(i, &pcb_regs[i+10]); - supply_register(8, &pcb_regs[8]); /* eip */ - supply_register(9, &pcb_regs[9]); /* eflags */ - for (i = 10; i < 13; ++i) /* cs, ss, ds */ - supply_register(i, &pcb_regs[i+9]); - supply_register(13, &pcb_regs[18]); /* es */ - for (i = 14; i < 16; ++i) /* fs, gs */ - supply_register(i, &pcb_regs[i+8]); - - /* XXX 80387 registers? */ -} - -static void -setup_kernel_debugging() -{ - struct stat stb; - int devmem = 0; - CORE_ADDR addr; - - fstat(corechan, &stb); - if ((stb.st_mode & S_IFMT) == S_IFCHR && stb.st_rdev == makedev(2, 0)) - devmem = 1; - -#ifdef NEWVM - physrd(ksym_lookup("IdlePTD") - KERNOFF, &sbr, sizeof sbr); - slr = 2 * NPTEPG; /* XXX temporary */ - printf("IdlePTD %x\n", sbr); - curpcb = ksym_lookup("curpcb") - KERNOFF; - physrd(curpcb, &curpcb, sizeof curpcb); - kstack = ksym_lookup("kstack"); -#else - sbr = ksym_lookup("Sysmap"); - slr = ksym_lookup("Syssize"); - printf("sbr %x slr %x\n", sbr, slr); -#endif - - /* - * pcb where "panic" saved registers in first thing in current - * u area. - */ -#ifndef NEWVM - read_pcb(vtophys(ksym_lookup("u"))); -#endif - found_pcb = 1; - if (!devmem) { - /* find stack frame */ - CORE_ADDR panicstr; - char buf[256]; - register char *cp; - - panicstr = kvread(ksym_lookup("panicstr")); - if (panicstr == ~0) - return; - (void) kernel_core_file_hook(panicstr, buf, sizeof(buf)); - for (cp = buf; cp < &buf[sizeof(buf)] && *cp; cp++) - if (!isascii(*cp) || (!isprint(*cp) && !isspace(*cp))) - *cp = '?'; - if (*cp) - *cp = '\0'; - printf("panic: %s\n", buf); - read_pcb(ksym_lookup("dumppcb") - KERNOFF); - } -#ifdef NEWVM - else - read_pcb(vtophys(kstack)); -#endif - - stack_start = USRSTACK; - stack_end = USRSTACK + ctob(UPAGES); -} - -set_paddr_command(arg) - char *arg; -{ - u_int uaddr; - - if (!arg) - error_no_arg("ps-style address for new current process"); - if (!kernel_debugging) - error("not debugging kernel"); - uaddr = (u_int) parse_and_eval_address(arg); -#ifndef NEWVM - read_pcb(ctob(uaddr)); -#else - /* p_addr is now a pcb virtual address */ - read_pcb(vtophys(uaddr)); - curpcb = uaddr; -#endif - - flush_cached_frames(); - set_current_frame(create_new_frame(read_register(FP_REGNUM), read_pc())); - select_frame(get_current_frame(), 0); -} - -/* - * read len bytes from kernel virtual address 'addr' into local - * buffer 'buf'. Return 0 if read ok, 1 otherwise. On read - * errors, portion of buffer not read is zeroed. - */ -kernel_core_file_hook(addr, buf, len) - CORE_ADDR addr; - char *buf; - int len; -{ - int i; - CORE_ADDR paddr; - - while (len > 0) { - paddr = vtophys(addr); - if (paddr == ~0) { - bzero(buf, len); - return (1); - } - /* we can't read across a page boundary */ - i = min(len, NBPG - (addr & PGOFSET)); - if (physrd(paddr, buf, i)) { - bzero(buf, len); - return (1); - } - buf += i; - addr += i; - len -= i; - } - return (0); -} -#endif - -core_file_command(filename, from_tty) - char *filename; - int from_tty; -{ - int val; - extern char registers[]; -#ifdef KERNELDEBUG - struct stat stb; -#endif - - /* - * Discard all vestiges of any previous core file and mark data and - * stack spaces as empty. - */ - if (corefile) - free(corefile); - corefile = 0; - core_file_hook = 0; - - if (corechan >= 0) - close(corechan); - corechan = -1; - - /* Now, if a new core file was specified, open it and digest it. */ - - if (filename == 0) { - if (from_tty) - printf("No core file now.\n"); - return; - } - filename = tilde_expand(filename); - make_cleanup(free, filename); - if (have_inferior_p()) - error("To look at a core file, you must kill the inferior with \"kill\"."); - corechan = open(filename, O_RDONLY, 0); - if (corechan < 0) - perror_with_name(filename); - -#ifdef KERNELDEBUG - fstat(corechan, &stb); - - if (kernel_debugging) { - setup_kernel_debugging(); - core_file_hook = kernel_core_file_hook; - } else if ((stb.st_mode & S_IFMT) == S_IFCHR && - stb.st_rdev == makedev(2, 1)) { - /* looking at /dev/kmem */ - data_offset = data_start = KERNOFF; - data_end = ~0; /* XXX */ - stack_end = stack_start = data_end; - } else -#endif - { - /* - * 4.2-style core dump file. - */ - struct user u; - unsigned int reg_offset; - - val = myread(corechan, &u, sizeof u); - if (val < 0) - perror_with_name("Not a core file: reading upage"); - if (val != sizeof u) - error("Not a core file: could only read %d bytes", val); - - /* - * We are depending on exec_file_command having been - * called previously to set exec_data_start. Since - * the executable and the core file share the same - * text segment, the address of the data segment will - * be the same in both. - */ - data_start = exec_data_start; - -#ifndef NEWVM - data_end = data_start + NBPG * u.u_dsize; - stack_start = stack_end - NBPG * u.u_ssize; - data_offset = NBPG * UPAGES; - stack_offset = NBPG * (UPAGES + u.u_dsize); - - /* - * Some machines put an absolute address in here and - * some put the offset in the upage of the regs. - */ - reg_offset = (int) u.u_ar0 - KERNEL_U_ADDR; -#else - stack_end = (CORE_ADDR) u.u_kproc.kp_eproc.e_vm.vm_maxsaddr - + MAXSSIZ; - - data_end = data_start + - NBPG * u.u_kproc.kp_eproc.e_vm.vm_dsize; - stack_start = stack_end - - NBPG * u.u_kproc.kp_eproc.e_vm.vm_ssize; - data_offset = NBPG * UPAGES; - stack_offset = NBPG * - (UPAGES + u.u_kproc.kp_eproc.e_vm.vm_dsize); - - reg_offset = (int) u.u_kproc.kp_proc.p_regs - USRSTACK; -#endif - - setregmap(u.u_pcb.pcb_flags); - - /* - * I don't know where to find this info. So, for now, - * mark it as not available. - */ - /* N_SET_MAGIC (core_aouthdr, 0); */ - bzero ((char *) &core_aouthdr, sizeof core_aouthdr); - - /* - * Read the register values out of the core file and - * store them where `read_register' will find them. - */ - { - register int regno; - - for (regno = 0; regno < NUM_REGS; regno++) { - char buf[MAX_REGISTER_RAW_SIZE]; - - val = lseek(corechan, register_addr(regno, reg_offset), 0); - if (val < 0 - || (val = myread(corechan, buf, sizeof buf)) < 0) { - char *buffer = (char *) alloca(strlen(reg_names[regno]) + 30); - strcpy(buffer, "Reading register "); - strcat(buffer, reg_names[regno]); - perror_with_name(buffer); - } - supply_register(regno, buf); - } - } - } -#endif - if (filename[0] == '/') - corefile = savestring(filename, strlen(filename)); - else - corefile = concat(current_directory, "/", filename); - - set_current_frame(create_new_frame(read_register(FP_REGNUM), - read_pc())); - select_frame(get_current_frame(), 0); - validate_files(); -} - -exec_file_command(filename, from_tty) - char *filename; - int from_tty; -{ - int val; - - /* - * Eliminate all traces of old exec file. Mark text segment as empty. - */ - - if (execfile) - free(execfile); - execfile = 0; - data_start = 0; - data_end = 0; - stack_start = 0; - stack_end = 0; - text_start = 0; - text_end = 0; - exec_data_start = 0; - exec_data_end = 0; - if (execchan >= 0) - close(execchan); - execchan = -1; - - /* Now open and digest the file the user requested, if any. */ - - if (filename) { - filename = tilde_expand(filename); - make_cleanup(free, filename); - - execchan = openp(getenv("PATH"), 1, filename, O_RDONLY, 0, - &execfile); - if (execchan < 0) - perror_with_name(filename); - - { - struct stat st_exec; - -#ifdef HEADER_SEEK_FD - HEADER_SEEK_FD(execchan); -#endif - - val = myread(execchan, &exec_aouthdr, sizeof(AOUTHDR)); - - if (val < 0) - perror_with_name(filename); - -#ifdef KERNELDEBUG - if (kernel_debugging) { - /* Gross and disgusting XXX */ - text_start = KERNTEXT_BASE; - exec_data_start = KERNTEXT_BASE + - (exec_aouthdr.a_text + 4095) & ~ 4095; - } else { -#endif - text_start = N_TXTADDR(exec_aouthdr); - exec_data_start = N_DATADDR(exec_aouthdr); -#ifdef KERNELDEBUG - } -#endif - - text_offset = N_TXTOFF(exec_aouthdr); - exec_data_offset = N_TXTOFF(exec_aouthdr) + exec_aouthdr.a_text; - - text_end = text_start + exec_aouthdr.a_text; - exec_data_end = exec_data_start + exec_aouthdr.a_data; - - fstat(execchan, &st_exec); - exec_mtime = st_exec.st_mtime; - } - - validate_files(); - } else if (from_tty) - printf("No exec file now.\n"); - - /* Tell display code (if any) about the changed file name. */ - if (exec_file_display_hook) - (*exec_file_display_hook) (filename); -} - -int dummy_code[] = { - 0xb8909090, /* nop; nop; nop; movl $0x32323232,%eax */ - 0x32323232, -#define DUMMY_CALL_INDEX 1 - 0x90ccd0ff, /* call %eax; int3; nop */ -}; - -/* - * Build `dummy' call instructions on inferior's stack to cause - * it to call a subroutine. - * - * N.B. - code in wait_for_inferior requires that sp < pc < fp when - * we take the trap 2 above so it will recognize that we stopped - * at a `dummy' call. So, after the call sp is *not* decremented - * to clean the arguments, code & other stuff we lay on the stack. - * Since the regs are restored to saved values at the breakpoint, - * sp will get reset correctly. Also, this restore means we don't - * have to construct frame linkage info to save pc & fp. The lack - * of frame linkage means we can't do a backtrace, etc., if the - * called function gets a fault or hits a breakpoint but code in - * run_stack_dummy makes this impossible anyway. - */ -CORE_ADDR -setup_dummy(sp, funaddr, nargs, args, struct_return_bytes, pushfn) - CORE_ADDR sp; - CORE_ADDR funaddr; - int nargs; - value *args; - int struct_return_bytes; - CORE_ADDR (*pushfn)(); -{ - int padding, i; - CORE_ADDR top = sp, struct_addr, pc; - - i = arg_stacklen(nargs, args) + struct_return_bytes - + sizeof(dummy_code); - if (i & 3) - padding = 4 - (i & 3); - else - padding = 0; - pc = sp - sizeof(dummy_code); - sp = pc - padding - struct_return_bytes; - struct_addr = sp; - while (--nargs >= 0) - sp = (*pushfn)(sp, *args++); - if (struct_return_bytes) - STORE_STRUCT_RETURN(struct_addr, sp); - write_register(SP_REGNUM, sp); - - dummy_code[DUMMY_CALL_INDEX] = (int)funaddr; - write_memory(pc, (char *)dummy_code, sizeof(dummy_code)); - - return pc; -} - -/* helper functions for m-i386.h */ - -/* stdio style buffering to minimize calls to ptrace */ -static CORE_ADDR codestream_next_addr; -static CORE_ADDR codestream_addr; -static unsigned char codestream_buf[sizeof (int)]; -static int codestream_off; -static int codestream_cnt; - -#define codestream_tell() (codestream_addr + codestream_off) -#define codestream_peek() (codestream_cnt == 0 ? \ - codestream_fill(1): codestream_buf[codestream_off]) -#define codestream_get() (codestream_cnt-- == 0 ? \ - codestream_fill(0) : codestream_buf[codestream_off++]) - -static unsigned char -codestream_fill (peek_flag) -{ - codestream_addr = codestream_next_addr; - codestream_next_addr += sizeof (int); - codestream_off = 0; - codestream_cnt = sizeof (int); - read_memory (codestream_addr, - (unsigned char *)codestream_buf, - sizeof (int)); - - if (peek_flag) - return (codestream_peek()); - else - return (codestream_get()); -} - -static void -codestream_seek (place) -{ - codestream_next_addr = place & -sizeof (int); - codestream_cnt = 0; - codestream_fill (1); - while (codestream_tell() != place) - codestream_get (); -} - -static void -codestream_read (buf, count) - unsigned char *buf; -{ - unsigned char *p; - int i; - p = buf; - for (i = 0; i < count; i++) - *p++ = codestream_get (); -} - -/* next instruction is a jump, move to target */ -static -i386_follow_jump () -{ - int long_delta; - short short_delta; - char byte_delta; - int data16; - int pos; - - pos = codestream_tell (); - - data16 = 0; - if (codestream_peek () == 0x66) - { - codestream_get (); - data16 = 1; - } - - switch (codestream_get ()) - { - case 0xe9: - /* relative jump: if data16 == 0, disp32, else disp16 */ - if (data16) - { - codestream_read ((unsigned char *)&short_delta, 2); - pos += short_delta + 3; /* include size of jmp inst */ - } - else - { - codestream_read ((unsigned char *)&long_delta, 4); - pos += long_delta + 5; - } - break; - case 0xeb: - /* relative jump, disp8 (ignore data16) */ - codestream_read ((unsigned char *)&byte_delta, 1); - pos += byte_delta + 2; - break; - } - codestream_seek (pos + data16); -} - -/* - * find & return amound a local space allocated, and advance codestream to - * first register push (if any) - * - * if entry sequence doesn't make sense, return -1, and leave - * codestream pointer random - */ -static long -i386_get_frame_setup (pc) -{ - unsigned char op; - - codestream_seek (pc); - - i386_follow_jump (); - - op = codestream_get (); - - if (op == 0x58) /* popl %eax */ - { - /* - * this function must start with - * - * popl %eax 0x58 - * xchgl %eax, (%esp) 0x87 0x04 0x24 - * or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00 - * - * (the system 5 compiler puts out the second xchg - * inst, and the assembler doesn't try to optimize it, - * so the 'sib' form gets generated) - * - * this sequence is used to get the address of the return - * buffer for a function that returns a structure - */ - int pos; - unsigned char buf[4]; - static unsigned char proto1[3] = { 0x87,0x04,0x24 }; - static unsigned char proto2[4] = { 0x87,0x44,0x24,0x00 }; - pos = codestream_tell (); - codestream_read (buf, 4); - if (bcmp (buf, proto1, 3) == 0) - pos += 3; - else if (bcmp (buf, proto2, 4) == 0) - pos += 4; - - codestream_seek (pos); - op = codestream_get (); /* update next opcode */ - } - - if (op == 0x55) /* pushl %esp */ - { - /* check for movl %esp, %ebp - can be written two ways */ - switch (codestream_get ()) - { - case 0x8b: - if (codestream_get () != 0xec) - return (-1); - break; - case 0x89: - if (codestream_get () != 0xe5) - return (-1); - break; - default: - return (-1); - } - /* check for stack adjustment - * - * subl $XXX, %esp - * - * note: you can't subtract a 16 bit immediate - * from a 32 bit reg, so we don't have to worry - * about a data16 prefix - */ - op = codestream_peek (); - if (op == 0x83) - { - /* subl with 8 bit immed */ - codestream_get (); - if (codestream_get () != 0xec) - return (-1); - /* subl with signed byte immediate - * (though it wouldn't make sense to be negative) - */ - return (codestream_get()); - } - else if (op == 0x81) - { - /* subl with 32 bit immed */ - int locals; - codestream_get(); - if (codestream_get () != 0xec) - return (-1); - /* subl with 32 bit immediate */ - codestream_read ((unsigned char *)&locals, 4); - return (locals); - } - else - { - return (0); - } - } - else if (op == 0xc8) - { - /* enter instruction: arg is 16 bit unsigned immed */ - unsigned short slocals; - codestream_read ((unsigned char *)&slocals, 2); - codestream_get (); /* flush final byte of enter instruction */ - return (slocals); - } - return (-1); -} - -/* Return number of args passed to a frame. - Can return -1, meaning no way to tell. */ - -/* on the 386, the instruction following the call could be: - * popl %ecx - one arg - * addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits - * anything else - zero args - */ - -int -i386_frame_num_args (fi) - struct frame_info fi; -{ - int retpc; - unsigned char op; - struct frame_info *pfi; - - pfi = get_prev_frame_info ((fi)); - if (pfi == 0) - { - /* Note: this can happen if we are looking at the frame for - main, because FRAME_CHAIN_VALID won't let us go into - start. If we have debugging symbols, that's not really - a big deal; it just means it will only show as many arguments - to main as are declared. */ - return -1; - } - else - { - retpc = pfi->pc; - op = read_memory_integer (retpc, 1); - if (op == 0x59) - /* pop %ecx */ - return 1; - else if (op == 0x83) - { - op = read_memory_integer (retpc+1, 1); - if (op == 0xc4) - /* addl $, %esp */ - return (read_memory_integer (retpc+2,1)&0xff)/4; - else - return 0; - } - else if (op == 0x81) - { /* add with 32 bit immediate */ - op = read_memory_integer (retpc+1, 1); - if (op == 0xc4) - /* addl $, %esp */ - return read_memory_integer (retpc+2, 4) / 4; - else - return 0; - } - else - { - return 0; - } - } -} - -/* - * parse the first few instructions of the function to see - * what registers were stored. - * - * We handle these cases: - * - * The startup sequence can be at the start of the function, - * or the function can start with a branch to startup code at the end. - * - * %ebp can be set up with either the 'enter' instruction, or - * 'pushl %ebp, movl %esp, %ebp' (enter is too slow to be useful, - * but was once used in the sys5 compiler) - * - * Local space is allocated just below the saved %ebp by either the - * 'enter' instruction, or by 'subl $, %esp'. 'enter' has - * a 16 bit unsigned argument for space to allocate, and the - * 'addl' instruction could have either a signed byte, or - * 32 bit immediate. - * - * Next, the registers used by this function are pushed. In - * the sys5 compiler they will always be in the order: %edi, %esi, %ebx - * (and sometimes a harmless bug causes it to also save but not restore %eax); - * however, the code below is willing to see the pushes in any order, - * and will handle up to 8 of them. - * - * If the setup sequence is at the end of the function, then the - * next instruction will be a branch back to the start. - */ - -i386_frame_find_saved_regs (fip, fsrp) - struct frame_info *fip; - struct frame_saved_regs *fsrp; -{ - unsigned long locals; - unsigned char *p; - unsigned char op; - CORE_ADDR dummy_bottom; - CORE_ADDR adr; - int i; - - bzero (fsrp, sizeof *fsrp); - -#if 0 - /* if frame is the end of a dummy, compute where the - * beginning would be - */ - dummy_bottom = fip->frame - 4 - NUM_REGS*4 - CALL_DUMMY_LENGTH; - - /* check if the PC is in the stack, in a dummy frame */ - if (dummy_bottom <= fip->pc && fip->pc <= fip->frame) - { - /* all regs were saved by push_call_dummy () */ - adr = fip->frame - 4; - for (i = 0; i < NUM_REGS; i++) - { - fsrp->regs[i] = adr; - adr -= 4; - } - return; - } -#endif - - locals = i386_get_frame_setup (get_pc_function_start (fip->pc)); - - if (locals >= 0) - { - adr = fip->frame - 4 - locals; - for (i = 0; i < 8; i++) - { - op = codestream_get (); - if (op < 0x50 || op > 0x57) - break; - fsrp->regs[op - 0x50] = adr; - adr -= 4; - } - } - - fsrp->regs[PC_REGNUM] = fip->frame + 4; - fsrp->regs[FP_REGNUM] = fip->frame; -} - -/* return pc of first real instruction */ -i386_skip_prologue (pc) -{ - unsigned char op; - int i; - - if (i386_get_frame_setup (pc) < 0) - return (pc); - - /* found valid frame setup - codestream now points to - * start of push instructions for saving registers - */ - - /* skip over register saves */ - for (i = 0; i < 8; i++) - { - op = codestream_peek (); - /* break if not pushl inst */ - if (op < 0x50 || op > 0x57) - break; - codestream_get (); - } - - i386_follow_jump (); - - return (codestream_tell ()); -} - -i386_pop_frame () -{ - FRAME frame = get_current_frame (); - CORE_ADDR fp; - int regnum; - struct frame_saved_regs fsr; - struct frame_info *fi; - - fi = get_frame_info (frame); - fp = fi->frame; - get_frame_saved_regs (fi, &fsr); - for (regnum = 0; regnum < NUM_REGS; regnum++) - { - CORE_ADDR adr; - adr = fsr.regs[regnum]; - if (adr) - write_register (regnum, read_memory_integer (adr, 4)); - } - write_register (FP_REGNUM, read_memory_integer (fp, 4)); - write_register (PC_REGNUM, read_memory_integer (fp + 4, 4)); - write_register (SP_REGNUM, fp + 8); - flush_cached_frames (); - set_current_frame ( create_new_frame (read_register (FP_REGNUM), - read_pc ())); -} - -/* this table must line up with REGISTER_NAMES in m-i386.h */ -/* symbols like 'EAX' come from */ -static int trapmap[] = -{ - tEAX, tECX, tEDX, tEBX, - tESP, tEBP, tESI, tEDI, - tEIP, tEFLAGS, tCS, tSS, - tDS, tES, tES, tES /* lies: no fs or gs */ -}; -#if defined(FM_TRAP) || defined(EX_TRAPSTK) -static int syscallmap[] = -{ - sEAX, sECX, sEDX, sEBX, - sESP, sEBP, sESI, sEDI, - sEIP, sEFLAGS, sCS, sSS, - sCS, sCS, sCS, sCS /* lies: no ds, es, fs or gs */ -}; -#endif -static int *regmap; - -static void -setregmap(flags) - int flags; -{ -#ifdef FM_TRAP - regmap = flags & FM_TRAP ? trapmap: syscallmap; -#elif EX_TRAPSTK - regmap = flags & EX_TRAPSTK ? trapmap : syscallmap; -#else - regmap = trapmap; /* the lesser evil */ -#endif -} - -/* blockend is the value of u.u_ar0, and points to the - * place where GS is stored - */ -i386_register_u_addr (blockend, regnum) -{ -#if 0 - /* this will be needed if fp registers are reinstated */ - /* for now, you can look at them with 'info float' - * sys5 wont let you change them with ptrace anyway - */ - if (regnum >= FP0_REGNUM && regnum <= FP7_REGNUM) - { - int ubase, fpstate; - struct user u; - ubase = blockend + 4 * (SS + 1) - KSTKSZ; - fpstate = ubase + ((char *)&u.u_fpstate - (char *)&u); - return (fpstate + 0x1c + 10 * (regnum - FP0_REGNUM)); - } - else -#endif - return (blockend + 4 * regmap[regnum]); -} - -i387_to_double (from, to) - char *from; - char *to; -{ - long *lp; - /* push extended mode on 387 stack, then pop in double mode - * - * first, set exception masks so no error is generated - - * number will be rounded to inf or 0, if necessary - */ - asm ("pushl %eax"); /* grab a stack slot */ - asm ("fstcw (%esp)"); /* get 387 control word */ - asm ("movl (%esp),%eax"); /* save old value */ - asm ("orl $0x3f,%eax"); /* mask all exceptions */ - asm ("pushl %eax"); - asm ("fldcw (%esp)"); /* load new value into 387 */ - - asm ("movl 8(%ebp),%eax"); - asm ("fldt (%eax)"); /* push extended number on 387 stack */ - asm ("fwait"); - asm ("movl 12(%ebp),%eax"); - asm ("fstpl (%eax)"); /* pop double */ - asm ("fwait"); - - asm ("popl %eax"); /* flush modified control word */ - asm ("fnclex"); /* clear exceptions */ - asm ("fldcw (%esp)"); /* restore original control word */ - asm ("popl %eax"); /* flush saved copy */ -} - -double_to_i387 (from, to) - char *from; - char *to; -{ - /* push double mode on 387 stack, then pop in extended mode - * no errors are possible because every 64-bit pattern - * can be converted to an extended - */ - asm ("movl 8(%ebp),%eax"); - asm ("fldl (%eax)"); - asm ("fwait"); - asm ("movl 12(%ebp),%eax"); - asm ("fstpt (%eax)"); - asm ("fwait"); -} - -struct env387 -{ - unsigned short control; - unsigned short r0; - unsigned short status; - unsigned short r1; - unsigned short tag; - unsigned short r2; - unsigned long eip; - unsigned short code_seg; - unsigned short opcode; - unsigned long operand; - unsigned short operand_seg; - unsigned short r3; - unsigned char regs[8][10]; -}; - -static -print_387_control_word (control) -unsigned short control; -{ - printf ("control 0x%04x: ", control); - printf ("compute to "); - switch ((control >> 8) & 3) - { - case 0: printf ("24 bits; "); break; - case 1: printf ("(bad); "); break; - case 2: printf ("53 bits; "); break; - case 3: printf ("64 bits; "); break; - } - printf ("round "); - switch ((control >> 10) & 3) - { - case 0: printf ("NEAREST; "); break; - case 1: printf ("DOWN; "); break; - case 2: printf ("UP; "); break; - case 3: printf ("CHOP; "); break; - } - if (control & 0x3f) - { - printf ("mask:"); - if (control & 0x0001) printf (" INVALID"); - if (control & 0x0002) printf (" DENORM"); - if (control & 0x0004) printf (" DIVZ"); - if (control & 0x0008) printf (" OVERF"); - if (control & 0x0010) printf (" UNDERF"); - if (control & 0x0020) printf (" LOS"); - printf (";"); - } - printf ("\n"); - if (control & 0xe080) printf ("warning: reserved bits on 0x%x\n", - control & 0xe080); -} - -static -print_387_status_word (status) - unsigned short status; -{ - printf ("status 0x%04x: ", status); - if (status & 0xff) - { - printf ("exceptions:"); - if (status & 0x0001) printf (" INVALID"); - if (status & 0x0002) printf (" DENORM"); - if (status & 0x0004) printf (" DIVZ"); - if (status & 0x0008) printf (" OVERF"); - if (status & 0x0010) printf (" UNDERF"); - if (status & 0x0020) printf (" LOS"); - if (status & 0x0040) printf (" FPSTACK"); - printf ("; "); - } - printf ("flags: %d%d%d%d; ", - (status & 0x4000) != 0, - (status & 0x0400) != 0, - (status & 0x0200) != 0, - (status & 0x0100) != 0); - - printf ("top %d\n", (status >> 11) & 7); -} - -static -print_387_status (status, ep) - unsigned short status; - struct env387 *ep; -{ - int i; - int bothstatus; - int top; - int fpreg; - unsigned char *p; - - bothstatus = ((status != 0) && (ep->status != 0)); - if (status != 0) - { - if (bothstatus) - printf ("u: "); - print_387_status_word (status); - } - - if (ep->status != 0) - { - if (bothstatus) - printf ("e: "); - print_387_status_word (ep->status); - } - - print_387_control_word (ep->control); - printf ("last exception: "); - printf ("opcode 0x%x; ", ep->opcode); - printf ("pc 0x%x:0x%x; ", ep->code_seg, ep->eip); - printf ("operand 0x%x:0x%x\n", ep->operand_seg, ep->operand); - - top = (ep->status >> 11) & 7; - - printf (" regno tag msb lsb value\n"); - for (fpreg = 7; fpreg >= 0; fpreg--) - { - int st_regno; - double val; - - /* The physical regno `fpreg' is only relevant as an index into the - * tag word. Logical `%st' numbers are required for indexing `p->regs. - */ - st_regno = (fpreg + 8 - top) & 0x7; - - printf ("%%st(%d) %s ", st_regno, fpreg == top ? "=>" : " "); - - switch ((ep->tag >> (fpreg * 2)) & 3) - { - case 0: printf ("valid "); break; - case 1: printf ("zero "); break; - case 2: printf ("trap "); break; - case 3: printf ("empty "); break; - } - for (i = 9; i >= 0; i--) - printf ("%02x", ep->regs[st_regno][i]); - - i387_to_double (ep->regs[st_regno], (char *)&val); - printf (" %g\n", val); - } -#if 0 /* reserved fields are always 0xffff on 486's */ - if (ep->r0) - printf ("warning: reserved0 is 0x%x\n", ep->r0); - if (ep->r1) - printf ("warning: reserved1 is 0x%x\n", ep->r1); - if (ep->r2) - printf ("warning: reserved2 is 0x%x\n", ep->r2); - if (ep->r3) - printf ("warning: reserved3 is 0x%x\n", ep->r3); -#endif -} - -#ifdef __386BSD__ -#define fpstate save87 -#define U_FPSTATE(u) u.u_pcb.pcb_savefpu -#endif - -#ifndef U_FPSTATE -#define U_FPSTATE(u) u.u_fpstate -#endif - -i386_float_info () -{ - struct user u; /* just for address computations */ - int i; - /* fpstate defined in */ - struct fpstate *fpstatep; - char buf[sizeof (struct fpstate) + 2 * sizeof (int)]; - unsigned int uaddr; - char fpvalid; - unsigned int rounded_addr; - unsigned int rounded_size; - extern int corechan; - int skip; - -#ifndef __386BSD__ /* XXX - look at pcb flags */ - uaddr = (char *)&u.u_fpvalid - (char *)&u; - if (have_inferior_p()) - { - unsigned int data; - unsigned int mask; - - rounded_addr = uaddr & -sizeof (int); - data = ptrace (PT_READ_U, inferior_pid, (caddr_t)rounded_addr, 0); - mask = 0xff << ((uaddr - rounded_addr) * 8); - - fpvalid = ((data & mask) != 0); - } - else - { - if (lseek (corechan, uaddr, 0) < 0) - perror ("seek on core file"); - if (myread (corechan, &fpvalid, 1) < 0) - perror ("read on core file"); - - } - - if (fpvalid == 0) - { - printf ("no floating point status saved\n"); - return; - } -#endif /* not __386BSD__ */ - - uaddr = (char *)&U_FPSTATE(u) - (char *)&u; - if (have_inferior_p ()) - { - int *ip; - - rounded_addr = uaddr & -sizeof (int); - rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) + - sizeof (int) - 1) / sizeof (int); - skip = uaddr - rounded_addr; - - ip = (int *)buf; - for (i = 0; i < rounded_size; i++) - { - *ip++ = ptrace (PT_READ_U, inferior_pid, (caddr_t)rounded_addr, 0); - rounded_addr += sizeof (int); - } - } - else - { - if (lseek (corechan, uaddr, 0) < 0) - perror_with_name ("seek on core file"); - if (myread (corechan, buf, sizeof (struct fpstate)) < 0) - perror_with_name ("read from core file"); - skip = 0; - } - -#ifdef __386BSD__ - print_387_status (0, (struct env387 *)buf); -#else - fpstatep = (struct fpstate *)(buf + skip); - print_387_status (fpstatep->status, (struct env387 *)fpstatep->state); -#endif -} - -void -_initialize_i386bsd_dep() -{ -#ifdef KERNELDEBUG - add_com ("process-address", class_obscure, set_paddr_command, - "The process identified by (ps-style) ADDR becomes the\n\ -\"current\" process context for kernel debugging."); - add_com_alias ("paddr", "process-address", class_obscure, 0); -#endif -} diff --git a/gnu/usr.bin/gdb/config/m-i386-sv32.h b/gnu/usr.bin/gdb/config/m-i386-sv32.h deleted file mode 100644 index 38fb4eb..0000000 --- a/gnu/usr.bin/gdb/config/m-i386-sv32.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Macro defintions for i386, running System V 3.2. - Copyright (C) 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "m-i386.h" - -/* Apparently there is inconsistency among various System V's about what - the name of this field is. */ -#define U_FPSTATE(u) u.u_fps.u_fpstate - -/* TIOCGETC is defined in System V 3.2 termio.h, but struct tchars - is not. This makes problems for inflow.c. */ -#define TIOCGETC_BROKEN diff --git a/gnu/usr.bin/gdb/config/m-i386.h b/gnu/usr.bin/gdb/config/m-i386.h deleted file mode 100644 index 5449ec4..0000000 --- a/gnu/usr.bin/gdb/config/m-i386.h +++ /dev/null @@ -1,394 +0,0 @@ -/* Macro defintions for i386. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Define the bit, byte, and word ordering of the machine. */ -/* #define BITS_BIG_ENDIAN */ -/* #define BYTES_BIG_ENDIAN */ -/* #define WORDS_BIG_ENDIAN */ - -/* - * Changes for 80386 by Pace Willisson (pace@prep.ai.mit.edu) - * July 1988 - */ - - -#ifndef i386 -#define i386 -#endif - -/* I'm running gdb 3.4 under 386/ix 2.0.2, which is a derivative of AT&T's -Sys V/386 3.2. - -On some machines, gdb crashes when it's starting up while calling the -vendor's termio tgetent() routine. It always works when run under -itself (actually, under 3.2, it's not an infinitely recursive bug.) -After some poking around, it appears that depending on the environment -size, or whether you're running YP, or the phase of the moon or something, -the stack is not always long-aligned when main() is called, and tgetent() -takes strong offense at that. On some machines this bug never appears, but -on those where it does, it occurs quite reliably. */ -#define ALIGN_STACK_ON_STARTUP - -/* define USG if you are using sys5 /usr/include's */ -#define USG - -/* USG systems need these */ -#define vfork() fork() -#define MAXPATHLEN 500 - -/* define this if you don't have the extension to coff that allows - * file names to appear in the string table - * (aux.x_file.x_foff) - */ -#define COFF_NO_LONG_FILE_NAMES - -/* turn this on when rest of gdb is ready */ -/* #define IEEE_FLOAT */ - -#define NBPG NBPC -#define UPAGES USIZE - -#define HAVE_TERMIO - -/* Get rid of any system-imposed stack limit if possible. */ - -/* #define SET_STACK_LIMIT_HUGE not in sys5 */ - -/* Define this if the C compiler puts an underscore at the front - of external names before giving them to the linker. */ - -/* #define NAMES_HAVE_UNDERSCORE */ - -/* Specify debugger information format. */ - -/* #define READ_DBX_FORMAT */ -#define COFF_FORMAT - -/* number of traps that happen between exec'ing the shell - * to run an inferior, and when we finally get to - * the inferior code. This is 2 on most implementations. - */ -#define START_INFERIOR_TRAPS_EXPECTED 4 - -/* Offset from address of function to start of its code. - Zero on most machines. */ - -#define FUNCTION_START_OFFSET 0 - -/* Advance PC across any function entry prologue instructions - to reach some "real" code. */ - -#define SKIP_PROLOGUE(frompc) {(frompc) = i386_skip_prologue((frompc));} - -/* Immediately after a function call, return the saved pc. - Can't always go through the frames for this because on some machines - the new frame is not set up until the new function executes - some instructions. */ - -#define SAVED_PC_AFTER_CALL(frame) \ - (read_memory_integer (read_register (SP_REGNUM), 4)) - -/* This is the amount to subtract from u.u_ar0 - to get the offset in the core file of the register values. */ - -#define KERNEL_U_ADDR 0xe0000000 - -/* Address of end of stack space. */ - -#define STACK_END_ADDR 0x80000000 - -/* Stack grows downward. */ - -#define INNER_THAN < - -/* Sequence of bytes for breakpoint instruction. */ - -#define BREAKPOINT {0xcc} - -/* Amount PC must be decremented by after a breakpoint. - This is often the number of bytes in BREAKPOINT - but not always. */ - -#define DECR_PC_AFTER_BREAK 1 - -/* Nonzero if instruction at PC is a return instruction. */ - -#define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 1) == 0xc3) - -/* Return 1 if P points to an invalid floating point value. - LEN is the length in bytes -- not relevant on the 386. */ - -#define INVALID_FLOAT(p, len) (0) - -/* code to execute to print interesting information about the - * floating point processor (if any) - * No need to define if there is nothing to do. - */ -#define FLOAT_INFO { i386_float_info (); } - - -/* Largest integer type */ -#define LONGEST long - -/* Name of the builtin type for the LONGEST type above. */ -#define BUILTIN_TYPE_LONGEST builtin_type_long - -/* Say how long (ordinary) registers are. */ - -#define REGISTER_TYPE long - -/* Number of machine registers */ - -#define NUM_REGS 16 - -/* Initializer for an array of names of registers. - There should be NUM_REGS strings in this initializer. */ - -/* the order of the first 8 registers must match the compiler's - * numbering scheme (which is the same as the 386 scheme) - * also, this table must match regmap in i386-pinsn.c. - */ -#define REGISTER_NAMES { "eax", "ecx", "edx", "ebx", \ - "esp", "ebp", "esi", "edi", \ - "eip", "ps", "cs", "ss", \ - "ds", "es", "fs", "gs", \ - } - -/* Register numbers of various important registers. - Note that some of these values are "real" register numbers, - and correspond to the general registers of the machine, - and some are "phony" register numbers which are too large - to be actual register numbers as far as the user is concerned - but do serve to get the desired values when passed to read_register. */ - -#define FP_REGNUM 5 /* Contains address of executing stack frame */ -#define SP_REGNUM 4 /* Contains address of top of stack */ - -#define PC_REGNUM 8 -#define PS_REGNUM 9 - -#define REGISTER_U_ADDR(addr, blockend, regno) \ - (addr) = i386_register_u_addr ((blockend),(regno)); - -/* Total amount of space needed to store our copies of the machine's - register state, the array `registers'. */ -#define REGISTER_BYTES (NUM_REGS * 4) - -/* Index within `registers' of the first byte of the space for - register N. */ - -#define REGISTER_BYTE(N) ((N)*4) - -/* Number of bytes of storage in the actual machine representation - for register N. */ - -#define REGISTER_RAW_SIZE(N) (4) - -/* Number of bytes of storage in the program's representation - for register N. */ - -#define REGISTER_VIRTUAL_SIZE(N) (4) - -/* Largest value REGISTER_RAW_SIZE can have. */ - -#define MAX_REGISTER_RAW_SIZE 4 - -/* Largest value REGISTER_VIRTUAL_SIZE can have. */ - -#define MAX_REGISTER_VIRTUAL_SIZE 4 - -/* Nonzero if register N requires conversion - from raw format to virtual format. */ - -#define REGISTER_CONVERTIBLE(N) (0) - -/* Convert data from raw format for register REGNUM - to virtual format for register REGNUM. */ - -#define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) {bcopy ((FROM), (TO), 4);} - -/* Convert data from virtual format for register REGNUM - to raw format for register REGNUM. */ - -#define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) {bcopy ((FROM), (TO), 4);} - -/* Return the GDB type object for the "standard" data type - of data in register N. */ - -#define REGISTER_VIRTUAL_TYPE(N) (builtin_type_int) - -/* Store the address of the place in which to copy the structure the - subroutine will return. This is called from call_function. */ - -#define STORE_STRUCT_RETURN(ADDR, SP) \ - { (SP) -= sizeof (ADDR); \ - write_memory ((SP), &(ADDR), sizeof (ADDR)); } - -/* Extract from an array REGBUF containing the (raw) register state - a function return value of type TYPE, and copy that, in virtual format, - into VALBUF. */ - -#define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ - bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE)) - -/* Write into appropriate registers a function return value - of type TYPE, given in virtual format. */ - -#define STORE_RETURN_VALUE(TYPE,VALBUF) \ - write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE)) - -/* Extract from an array REGBUF containing the (raw) register state - the address in which a function should return its structure value, - as a CORE_ADDR (or an expression that can be used as one). */ - -#define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF)) - - -/* Describe the pointer in each stack frame to the previous stack frame - (its caller). */ - -/* FRAME_CHAIN takes a frame's nominal address - and produces the frame's chain-pointer. - - FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address - and produces the nominal address of the caller frame. - - However, if FRAME_CHAIN_VALID returns zero, - it means the given frame is the outermost one and has no caller. - In that case, FRAME_CHAIN_COMBINE is not used. */ - -#define FRAME_CHAIN(thisframe) \ - (outside_startup_file ((thisframe)->pc) ? \ - read_memory_integer ((thisframe)->frame, 4) :\ - 0) - -#define FRAME_CHAIN_VALID(chain, thisframe) \ - (chain != 0 && (outside_startup_file (FRAME_SAVED_PC (thisframe)))) - -#define FRAME_CHAIN_COMBINE(chain, thisframe) (chain) - -/* Define other aspects of the stack frame. */ - -/* A macro that tells us whether the function invocation represented - by FI does not have a frame on the stack associated with it. If it - does not, FRAMELESS is set to 1, else 0. */ -#define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \ - FRAMELESS_LOOK_FOR_PROLOGUE(FI, FRAMELESS) - -#define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4)) - -#define FRAME_ARGS_ADDRESS(fi) ((fi)->frame) - -#define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame) - -/* Return number of args passed to a frame. - Can return -1, meaning no way to tell. */ - -#define FRAME_NUM_ARGS(numargs, fi) (numargs) = i386_frame_num_args(fi) - -/* Return number of bytes at start of arglist that are not really args. */ - -#define FRAME_ARGS_SKIP 8 - -/* Put here the code to store, into a struct frame_saved_regs, - the addresses of the saved registers of frame described by FRAME_INFO. - This includes special registers such as pc and fp saved in special - ways in the stack frame. sp is even more special: - the address we return for it IS the sp for the next frame. */ - -#define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \ -{ i386_frame_find_saved_regs ((frame_info), &(frame_saved_regs)); } - - -/* Things needed for making the inferior call functions. */ - -/* Push an empty stack frame, to record the current PC, etc. */ - -#define PUSH_DUMMY_FRAME { i386_push_dummy_frame (); } - -/* Discard from the stack the innermost frame, restoring all registers. */ - -#define POP_FRAME { i386_pop_frame (); } - -/* this is - * call 11223344 (32 bit relative) - * int3 - */ - -#define CALL_DUMMY { 0x223344e8, 0xcc11 } - -#define CALL_DUMMY_LENGTH 8 - -#define CALL_DUMMY_START_OFFSET 0 /* Start execution at beginning of dummy */ - -/* Insert the specified number of args and function address - into a call sequence of the above form stored at DUMMYNAME. */ - -#define FIX_CALL_DUMMY(dummyname, pc, fun, nargs, type) \ -{ \ - int from, to, delta, loc; \ - loc = (int)(read_register (SP_REGNUM) - CALL_DUMMY_LENGTH); \ - from = loc + 5; \ - to = (int)(fun); \ - delta = to - from; \ - *(int *)((char *)(dummyname) + 1) = delta; \ -} - - -#if 0 -/* Interface definitions for kernel debugger KDB. */ - -/* Map machine fault codes into signal numbers. - First subtract 0, divide by 4, then index in a table. - Faults for which the entry in this table is 0 - are not handled by KDB; the program's own trap handler - gets to handle then. */ - -#define FAULT_CODE_ORIGIN 0 -#define FAULT_CODE_UNITS 4 -#define FAULT_TABLE \ -{ 0, 0, 0, 0, 0, 0, 0, 0, \ - 0, 0, 0, 0, 0, 0, 0, 0, \ - 0, 0, 0, 0, 0, 0, 0, 0} - -/* Start running with a stack stretching from BEG to END. - BEG and END should be symbols meaningful to the assembler. - This is used only for kdb. */ - -#define INIT_STACK(beg, end) {} - -/* Push the frame pointer register on the stack. */ -#define PUSH_FRAME_PTR {} - -/* Copy the top-of-stack to the frame pointer register. */ -#define POP_FRAME_PTR {} - -/* After KDB is entered by a fault, push all registers - that GDB thinks about (all NUM_REGS of them), - so that they appear in order of ascending GDB register number. - The fault code will be on the stack beyond the last register. */ - -#define PUSH_REGISTERS {} - -/* Assuming the registers (including processor status) have been - pushed on the stack in order of ascending GDB register number, - restore them and return to the address in the saved PC register. */ - -#define POP_REGISTERS {} -#endif diff --git a/gnu/usr.bin/gdb/config/m-i386bsd.h b/gnu/usr.bin/gdb/config/m-i386bsd.h deleted file mode 100644 index 15d97b2..0000000 --- a/gnu/usr.bin/gdb/config/m-i386bsd.h +++ /dev/null @@ -1,375 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1991 by William Jolitz at UUNET Technologies, Inc. - * - * @(#)m-i386bsd.h 6.7 (Berkeley) 5/8/91 - */ - -/* Macro definitions for i386. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Define the bit, byte, and word ordering of the machine. */ -/* #define BITS_BIG_ENDIAN */ -/* #define BYTES_BIG_ENDIAN */ -/* #define WORDS_BIG_ENDIAN */ - -/* - * Changes for 80386 by Pace Willisson (pace@prep.ai.mit.edu) - * July 1988 - * [ MODIFIED FOR 386BSD W. Jolitz ] - */ - -#ifndef i386 -#define i386 1 -#define i386b 1 -#endif - -#define IEEE_FLOAT -#define LONG_LONG - -/* Library stuff: POSIX tty (not supported yet), V7 tty (sigh), vprintf. */ - -#define HAVE_TERMIOS 1 -#define USE_OLD_TTY 1 -#define HAVE_VPRINTF 1 - -/* We support local and remote kernel debugging. */ - -#define KERNELDEBUG 1 - -/* Get rid of any system-imposed stack limit if possible. */ - -#define SET_STACK_LIMIT_HUGE - -/* Define this if the C compiler puts an underscore at the front - of external names before giving them to the linker. */ - -#define NAMES_HAVE_UNDERSCORE - -/* Specify debugger information format. */ - -#define READ_DBX_FORMAT - -/* number of traps that happen between exec'ing the shell - * to run an inferior, and when we finally get to - * the inferior code. This is 2 on most implementations. - */ -#define START_INFERIOR_TRAPS_EXPECTED 2 - -/* Offset from address of function to start of its code. - Zero on most machines. */ - -#define FUNCTION_START_OFFSET 0 - -/* Advance PC across any function entry prologue instructions - to reach some "real" code. */ - -#define SKIP_PROLOGUE(frompc) {(frompc) = i386_skip_prologue((frompc));} - -/* Immediately after a function call, return the saved pc. - Can't always go through the frames for this because on some machines - the new frame is not set up until the new function executes - some instructions. */ - -#define SAVED_PC_AFTER_CALL(frame) \ - (read_memory_integer (read_register (SP_REGNUM), 4)) - -/* This is the amount to subtract from u.u_ar0 - to get the offset in the core file of the register values. */ - -#ifdef NEWVM -#include -#define KERNEL_U_ADDR USRSTACK -#else -#define KERNEL_U_ADDR 0xfdffd000 -#endif - -/* Address of end of stack space. */ - -#define STACK_END_ADDR KERNEL_U_ADDR - -/* Stack grows downward. */ - -#define INNER_THAN < - -/* Sequence of bytes for breakpoint instruction. */ - -#define BREAKPOINT {0xcc} - -/* Amount PC must be decremented by after a breakpoint. - This is often the number of bytes in BREAKPOINT - but not always. */ - -#define DECR_PC_AFTER_BREAK 1 - -/* Nonzero if instruction at PC is a return instruction. */ - -#define ABOUT_TO_RETURN(pc) \ - strchr("\302\303\312\313\317", read_memory_integer(pc, 1)) - -/* Return 1 if P points to an invalid floating point value. - LEN is the length in bytes -- not relevant on the 386. */ - -#define INVALID_FLOAT(p, len) (0) - -/* code to execute to print interesting information about the - * floating point processor (if any) - * No need to define if there is nothing to do. - */ -#define FLOAT_INFO { i386_float_info (); } - - -/* Largest integer type */ -#define LONGEST long long - -/* Name of the builtin type for the LONGEST type above. */ -#define BUILTIN_TYPE_LONGEST builtin_type_long_long - -/* Say how long (ordinary) registers are. */ - -#define REGISTER_TYPE long - -/* Number of machine registers */ - -#define NUM_REGS 16 - -/* Initializer for an array of names of registers. - There should be NUM_REGS strings in this initializer. */ - -/* the order of the first 8 registers must match the compiler's - * numbering scheme (which is the same as the 386 scheme) - * also, this table must match regmap in i386-pinsn.c. - */ -#define REGISTER_NAMES { "eax", "ecx", "edx", "ebx", \ - "esp", "ebp", "esi", "edi", \ - "eip", "ps", "cs", "ss", \ - "ds", "es", "fs", "gs", \ - } - -/* Register numbers of various important registers. - Note that some of these values are "real" register numbers, - and correspond to the general registers of the machine, - and some are "phony" register numbers which are too large - to be actual register numbers as far as the user is concerned - but do serve to get the desired values when passed to read_register. */ - -#define FP_REGNUM 5 /* Contains address of executing stack frame */ -#define SP_REGNUM 4 /* Contains address of top of stack */ - -#define PC_REGNUM 8 -#define PS_REGNUM 9 - -#define REGISTER_U_ADDR(addr, blockend, regno) \ - (addr) = i386_register_u_addr ((blockend),(regno)); - -/* Total amount of space needed to store our copies of the machine's - register state, the array `registers'. */ -#define REGISTER_BYTES (NUM_REGS * 4) - -/* Index within `registers' of the first byte of the space for - register N. */ - -#define REGISTER_BYTE(N) ((N)*4) - -/* Number of bytes of storage in the actual machine representation - for register N. */ - -#define REGISTER_RAW_SIZE(N) (4) - -/* Number of bytes of storage in the program's representation - for register N. */ - -#define REGISTER_VIRTUAL_SIZE(N) (4) - -/* Largest value REGISTER_RAW_SIZE can have. */ - -#define MAX_REGISTER_RAW_SIZE 4 - -/* Largest value REGISTER_VIRTUAL_SIZE can have. */ - -#define MAX_REGISTER_VIRTUAL_SIZE 4 - -/* Nonzero if register N requires conversion - from raw format to virtual format. */ - -#define REGISTER_CONVERTIBLE(N) (0) - -/* Convert data from raw format for register REGNUM - to virtual format for register REGNUM. */ - -#define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO) {bcopy ((FROM), (TO), 4);} - -/* Convert data from virtual format for register REGNUM - to raw format for register REGNUM. */ - -#define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO) {bcopy ((FROM), (TO), 4);} - -/* Return the GDB type object for the "standard" data type - of data in register N. */ - -#define REGISTER_VIRTUAL_TYPE(N) (builtin_type_int) - -/* Store the address of the place in which to copy the structure the - subroutine will return. This is called from call_function. */ - -#define STORE_STRUCT_RETURN(ADDR, SP) \ - { (SP) -= sizeof (ADDR); \ - write_memory ((SP), &(ADDR), sizeof (ADDR)); } - -/* Extract from an array REGBUF containing the (raw) register state - a function return value of type TYPE, and copy that, in virtual format, - into VALBUF. */ - -#define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \ - bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE)) - -/* Write into appropriate registers a function return value - of type TYPE, given in virtual format. */ - -#define STORE_RETURN_VALUE(TYPE,VALBUF) \ - write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE)) - -/* Extract from an array REGBUF containing the (raw) register state - the address in which a function should return its structure value, - as a CORE_ADDR (or an expression that can be used as one). */ - -#define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF)) - - -/* Describe the pointer in each stack frame to the previous stack frame - (its caller). */ - -/* FRAME_CHAIN takes a frame's nominal address - and produces the frame's chain-pointer. - - FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address - and produces the nominal address of the caller frame. - - However, if FRAME_CHAIN_VALID returns zero, - it means the given frame is the outermost one and has no caller. - In that case, FRAME_CHAIN_COMBINE is not used. */ - -#define FRAME_CHAIN(thisframe) \ - (outside_startup_file ((thisframe)->pc) ? \ - read_memory_integer ((thisframe)->frame, 4) :\ - 0) - -#ifdef KERNELDEBUG -#define KERNTEXT_BASE 0xfe000000 -#ifdef NEWVM -#define KERNSTACK_TOP (read_register(SP_REGNUM) + 0x2000) /* approximate */ -#else -/* #define KERNSTACK_TOP (P1PAGES << PGSHIFT) */ -#define KERNSTACK_TOP 0xfe000000 -#endif -extern int kernel_debugging; -#define FRAME_CHAIN_VALID(chain, thisframe) \ - (chain != 0 && \ - !kernel_debugging ? outside_startup_file(FRAME_SAVED_PC(thisframe)) :\ - (chain >= read_register(SP_REGNUM) && chain < KERNSTACK_TOP)) -#else -#define FRAME_CHAIN_VALID(chain, thisframe) \ - (chain != 0 && (outside_startup_file (FRAME_SAVED_PC (thisframe)))) -#endif - -#define FRAME_CHAIN_COMBINE(chain, thisframe) (chain) - -/* Define other aspects of the stack frame. */ - -/* A macro that tells us whether the function invocation represented - by FI does not have a frame on the stack associated with it. If it - does not, FRAMELESS is set to 1, else 0. */ -#define FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) \ - FRAMELESS_LOOK_FOR_PROLOGUE(FI, FRAMELESS) - -#define FRAME_SAVED_PC(FRAME) (read_memory_integer ((FRAME)->frame + 4, 4)) - -#define FRAME_ARGS_ADDRESS(fi) ((fi)->frame) - -#define FRAME_LOCALS_ADDRESS(fi) ((fi)->frame) - -/* Return number of args passed to a frame. - Can return -1, meaning no way to tell. */ - -#define FRAME_NUM_ARGS(numargs, fi) (numargs) = i386_frame_num_args(fi) - -/* Return number of bytes at start of arglist that are not really args. */ - -#define FRAME_ARGS_SKIP 8 - -/* Put here the code to store, into a struct frame_saved_regs, - the addresses of the saved registers of frame described by FRAME_INFO. - This includes special registers such as pc and fp saved in special - ways in the stack frame. sp is even more special: - the address we return for it IS the sp for the next frame. */ - -#define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs) \ -{ i386_frame_find_saved_regs ((frame_info), &(frame_saved_regs)); } - - -/* Discard from the stack the innermost frame, restoring all registers. */ - -#define POP_FRAME { i386_pop_frame (); } - -#define NEW_CALL_FUNCTION - -#if 0 -/* Interface definitions for kernel debugger KDB. */ - -/* Map machine fault codes into signal numbers. - First subtract 0, divide by 4, then index in a table. - Faults for which the entry in this table is 0 - are not handled by KDB; the program's own trap handler - gets to handle then. */ - -#define FAULT_CODE_ORIGIN 0 -#define FAULT_CODE_UNITS 4 -#define FAULT_TABLE \ -{ 0, 0, 0, 0, 0, 0, 0, 0, \ - 0, 0, 0, 0, 0, 0, 0, 0, \ - 0, 0, 0, 0, 0, 0, 0, 0} - -/* Start running with a stack stretching from BEG to END. - BEG and END should be symbols meaningful to the assembler. - This is used only for kdb. */ - -#define INIT_STACK(beg, end) {} - -/* Push the frame pointer register on the stack. */ -#define PUSH_FRAME_PTR {} - -/* Copy the top-of-stack to the frame pointer register. */ -#define POP_FRAME_PTR {} - -/* After KDB is entered by a fault, push all registers - that GDB thinks about (all NUM_REGS of them), - so that they appear in order of ascending GDB register number. - The fault code will be on the stack beyond the last register. */ - -#define PUSH_REGISTERS {} - -/* Assuming the registers (including processor status) have been - pushed on the stack in order of ascending GDB register number, - restore them and return to the address in the saved PC register. */ - -#define POP_REGISTERS {} -#endif diff --git a/gnu/usr.bin/gdb/config/m-i386g-sv32.h b/gnu/usr.bin/gdb/config/m-i386g-sv32.h deleted file mode 100644 index 3d69eea..0000000 --- a/gnu/usr.bin/gdb/config/m-i386g-sv32.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Macro defintions for i386, running System V 3.2. - Copyright (C) 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "m-i386gas.h" - -/* Apparently there is inconsistency among various System V's about what - the name of this field is. */ -#define U_FPSTATE(u) u.u_fps.u_fpstate - -/* TIOCGETC is defined in System V 3.2 termio.h, but struct tchars - is not. This makes problems for inflow.c. */ -#define TIOCGETC_BROKEN diff --git a/gnu/usr.bin/gdb/config/m-i386gas.h b/gnu/usr.bin/gdb/config/m-i386gas.h deleted file mode 100644 index fbd2138..0000000 --- a/gnu/usr.bin/gdb/config/m-i386gas.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Macro definitions for i386 using the GNU object file format. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* - * Changes for 80386 by Pace Willisson (pace@prep.ai.mit.edu) - * July 1988 - * - * i386gnu: COFF_ENCAPSULATE - */ - - -#define COFF_ENCAPSULATE - -#include "m-i386.h" - - -#define NAMES_HAVE_UNDERSCORE - -#undef COFF_FORMAT -#define READ_DBX_FORMAT - diff --git a/gnu/usr.bin/gdb/copying.c b/gnu/usr.bin/gdb/copying.c deleted file mode 100644 index b3d7519..0000000 --- a/gnu/usr.bin/gdb/copying.c +++ /dev/null @@ -1,215 +0,0 @@ -/* Do not modify this file; it is created automatically - by copying.awk. */ -extern int immediate_quit; -static void -copying_info () -{ - immediate_quit++; - printf_filtered ("\n"); - printf_filtered (" GNU GENERAL PUBLIC LICENSE\n"); - printf_filtered (" Version 1, February 1989\n"); - printf_filtered ("\n"); - printf_filtered (" Copyright (C) 1989 Free Software Foundation, Inc.\n"); - printf_filtered (" 675 Mass Ave, Cambridge, MA 02139, USA\n"); - printf_filtered (" Everyone is permitted to copy and distribute verbatim copies\n"); - printf_filtered (" of this license document, but changing it is not allowed.\n"); - printf_filtered ("\n"); - printf_filtered (" Preamble\n"); - printf_filtered ("\n"); - printf_filtered (" The license agreements of most software companies try to keep users\n"); - printf_filtered ("at the mercy of those companies. By contrast, our General Public\n"); - printf_filtered ("License is intended to guarantee your freedom to share and change free\n"); - printf_filtered ("software--to make sure the software is free for all its users. The\n"); - printf_filtered ("General Public License applies to the Free Software Foundation's\n"); - printf_filtered ("software and to any other program whose authors commit to using it.\n"); - printf_filtered ("You can use it for your programs, too.\n"); - printf_filtered ("\n"); - printf_filtered (" When we speak of free software, we are referring to freedom, not\n"); - printf_filtered ("price. Specifically, the General Public License is designed to make\n"); - printf_filtered ("sure that you have the freedom to give away or sell copies of free\n"); - printf_filtered ("software, that you receive source code or can get it if you want it,\n"); - printf_filtered ("that you can change the software or use pieces of it in new free\n"); - printf_filtered ("programs; and that you know you can do these things.\n"); - printf_filtered ("\n"); - printf_filtered (" To protect your rights, we need to make restrictions that forbid\n"); - printf_filtered ("anyone to deny you these rights or to ask you to surrender the rights.\n"); - printf_filtered ("These restrictions translate to certain responsibilities for you if you\n"); - printf_filtered ("distribute copies of the software, or if you modify it.\n"); - printf_filtered ("\n"); - printf_filtered (" For example, if you distribute copies of a such a program, whether\n"); - printf_filtered ("gratis or for a fee, you must give the recipients all the rights that\n"); - printf_filtered ("you have. You must make sure that they, too, receive or can get the\n"); - printf_filtered ("source code. And you must tell them their rights.\n"); - printf_filtered ("\n"); - printf_filtered (" We protect your rights with two steps: (1) copyright the software, and\n"); - printf_filtered ("(2) offer you this license which gives you legal permission to copy,\n"); - printf_filtered ("distribute and/or modify the software.\n"); - printf_filtered ("\n"); - printf_filtered (" Also, for each author's protection and ours, we want to make certain\n"); - printf_filtered ("that everyone understands that there is no warranty for this free\n"); - printf_filtered ("software. If the software is modified by someone else and passed on, we\n"); - printf_filtered ("want its recipients to know that what they have is not the original, so\n"); - printf_filtered ("that any problems introduced by others will not reflect on the original\n"); - printf_filtered ("authors' reputations.\n"); - printf_filtered ("\n"); - printf_filtered (" The precise terms and conditions for copying, distribution and\n"); - printf_filtered ("modification follow.\n"); - printf_filtered (" \n"); - printf_filtered (" GNU GENERAL PUBLIC LICENSE\n"); - printf_filtered (" TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"); - printf_filtered ("\n"); - printf_filtered (" 0. This License Agreement applies to any program or other work which\n"); - printf_filtered ("contains a notice placed by the copyright holder saying it may be\n"); - printf_filtered ("distributed under the terms of this General Public License. The\n"); - printf_filtered ("\"Program\", below, refers to any such program or work, and a \"work based\n"); - printf_filtered ("on the Program\" means either the Program or any work containing the\n"); - printf_filtered ("Program or a portion of it, either verbatim or with modifications. Each\n"); - printf_filtered ("licensee is addressed as \"you\".\n"); - printf_filtered ("\n"); - printf_filtered (" 1. You may copy and distribute verbatim copies of the Program's source\n"); - printf_filtered ("code as you receive it, in any medium, provided that you conspicuously and\n"); - printf_filtered ("appropriately publish on each copy an appropriate copyright notice and\n"); - printf_filtered ("disclaimer of warranty; keep intact all the notices that refer to this\n"); - printf_filtered ("General Public License and to the absence of any warranty; and give any\n"); - printf_filtered ("other recipients of the Program a copy of this General Public License\n"); - printf_filtered ("along with the Program. You may charge a fee for the physical act of\n"); - printf_filtered ("transferring a copy.\n"); - printf_filtered ("\n"); - printf_filtered (" 2. You may modify your copy or copies of the Program or any portion of\n"); - printf_filtered ("it, and copy and distribute such modifications under the terms of Paragraph\n"); - printf_filtered ("1 above, provided that you also do the following:\n"); - printf_filtered ("\n"); - printf_filtered (" a) cause the modified files to carry prominent notices stating that\n"); - printf_filtered (" you changed the files and the date of any change; and\n"); - printf_filtered ("\n"); - printf_filtered (" b) cause the whole of any work that you distribute or publish, that\n"); - printf_filtered (" in whole or in part contains the Program or any part thereof, either\n"); - printf_filtered (" with or without modifications, to be licensed at no charge to all\n"); - printf_filtered (" third parties under the terms of this General Public License (except\n"); - printf_filtered (" that you may choose to grant warranty protection to some or all\n"); - printf_filtered (" third parties, at your option).\n"); - printf_filtered ("\n"); - printf_filtered (" c) If the modified program normally reads commands interactively when\n"); - printf_filtered (" run, you must cause it, when started running for such interactive use\n"); - printf_filtered (" in the simplest and most usual way, to print or display an\n"); - printf_filtered (" announcement including an appropriate copyright notice and a notice\n"); - printf_filtered (" that there is no warranty (or else, saying that you provide a\n"); - printf_filtered (" warranty) and that users may redistribute the program under these\n"); - printf_filtered (" conditions, and telling the user how to view a copy of this General\n"); - printf_filtered (" Public License.\n"); - printf_filtered ("\n"); - printf_filtered (" d) You may charge a fee for the physical act of transferring a\n"); - printf_filtered (" copy, and you may at your option offer warranty protection in\n"); - printf_filtered (" exchange for a fee.\n"); - printf_filtered ("\n"); - printf_filtered ("Mere aggregation of another independent work with the Program (or its\n"); - printf_filtered ("derivative) on a volume of a storage or distribution medium does not bring\n"); - printf_filtered ("the other work under the scope of these terms.\n"); - printf_filtered (" \n"); - printf_filtered (" 3. You may copy and distribute the Program (or a portion or derivative of\n"); - printf_filtered ("it, under Paragraph 2) in object code or executable form under the terms of\n"); - printf_filtered ("Paragraphs 1 and 2 above provided that you also do one of the following:\n"); - printf_filtered ("\n"); - printf_filtered (" a) accompany it with the complete corresponding machine-readable\n"); - printf_filtered (" source code, which must be distributed under the terms of\n"); - printf_filtered (" Paragraphs 1 and 2 above; or,\n"); - printf_filtered ("\n"); - printf_filtered (" b) accompany it with a written offer, valid for at least three\n"); - printf_filtered (" years, to give any third party free (except for a nominal charge\n"); - printf_filtered (" for the cost of distribution) a complete machine-readable copy of the\n"); - printf_filtered (" corresponding source code, to be distributed under the terms of\n"); - printf_filtered (" Paragraphs 1 and 2 above; or,\n"); - printf_filtered ("\n"); - printf_filtered (" c) accompany it with the information you received as to where the\n"); - printf_filtered (" corresponding source code may be obtained. (This alternative is\n"); - printf_filtered (" allowed only for noncommercial distribution and only if you\n"); - printf_filtered (" received the program in object code or executable form alone.)\n"); - printf_filtered ("\n"); - printf_filtered ("Source code for a work means the preferred form of the work for making\n"); - printf_filtered ("modifications to it. For an executable file, complete source code means\n"); - printf_filtered ("all the source code for all modules it contains; but, as a special\n"); - printf_filtered ("exception, it need not include source code for modules which are standard\n"); - printf_filtered ("libraries that accompany the operating system on which the executable\n"); - printf_filtered ("file runs, or for standard header files or definitions files that\n"); - printf_filtered ("accompany that operating system.\n"); - printf_filtered ("\n"); - printf_filtered (" 4. You may not copy, modify, sublicense, distribute or transfer the\n"); - printf_filtered ("Program except as expressly provided under this General Public License.\n"); - printf_filtered ("Any attempt otherwise to copy, modify, sublicense, distribute or transfer\n"); - printf_filtered ("the Program is void, and will automatically terminate your rights to use\n"); - printf_filtered ("the Program under this License. However, parties who have received\n"); - printf_filtered ("copies, or rights to use copies, from you under this General Public\n"); - printf_filtered ("License will not have their licenses terminated so long as such parties\n"); - printf_filtered ("remain in full compliance.\n"); - printf_filtered ("\n"); - printf_filtered (" 5. By copying, distributing or modifying the Program (or any work based\n"); - printf_filtered ("on the Program) you indicate your acceptance of this license to do so,\n"); - printf_filtered ("and all its terms and conditions.\n"); - printf_filtered ("\n"); - printf_filtered (" 6. Each time you redistribute the Program (or any work based on the\n"); - printf_filtered ("Program), the recipient automatically receives a license from the original\n"); - printf_filtered ("licensor to copy, distribute or modify the Program subject to these\n"); - printf_filtered ("terms and conditions. You may not impose any further restrictions on the\n"); - printf_filtered ("recipients' exercise of the rights granted herein.\n"); - printf_filtered (" \n"); - printf_filtered (" 7. The Free Software Foundation may publish revised and/or new versions\n"); - printf_filtered ("of the General Public License from time to time. Such new versions will\n"); - printf_filtered ("be similar in spirit to the present version, but may differ in detail to\n"); - printf_filtered ("address new problems or concerns.\n"); - printf_filtered ("\n"); - printf_filtered ("Each version is given a distinguishing version number. If the Program\n"); - printf_filtered ("specifies a version number of the license which applies to it and \"any\n"); - printf_filtered ("later version\", you have the option of following the terms and conditions\n"); - printf_filtered ("either of that version or of any later version published by the Free\n"); - printf_filtered ("Software Foundation. If the Program does not specify a version number of\n"); - printf_filtered ("the license, you may choose any version ever published by the Free Software\n"); - printf_filtered ("Foundation.\n"); - printf_filtered ("\n"); - printf_filtered (" 8. If you wish to incorporate parts of the Program into other free\n"); - printf_filtered ("programs whose distribution conditions are different, write to the author\n"); - printf_filtered ("to ask for permission. For software which is copyrighted by the Free\n"); - printf_filtered ("Software Foundation, write to the Free Software Foundation; we sometimes\n"); - printf_filtered ("make exceptions for this. Our decision will be guided by the two goals\n"); - printf_filtered ("of preserving the free status of all derivatives of our free software and\n"); - printf_filtered ("of promoting the sharing and reuse of software generally.\n"); - printf_filtered ("\n"); - immediate_quit--; -} - -static void -warranty_info () -{ - immediate_quit++; - printf_filtered (" NO WARRANTY\n"); - printf_filtered ("\n"); - printf_filtered (" 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n"); - printf_filtered ("FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN\n"); - printf_filtered ("OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n"); - printf_filtered ("PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n"); - printf_filtered ("OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"); - printf_filtered ("MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS\n"); - printf_filtered ("TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE\n"); - printf_filtered ("PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n"); - printf_filtered ("REPAIR OR CORRECTION.\n"); - printf_filtered ("\n"); - printf_filtered (" 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n"); - printf_filtered ("WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n"); - printf_filtered ("REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n"); - printf_filtered ("INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n"); - printf_filtered ("OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n"); - printf_filtered ("TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n"); - printf_filtered ("YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n"); - printf_filtered ("PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n"); - printf_filtered ("POSSIBILITY OF SUCH DAMAGES.\n"); - printf_filtered ("\n"); - immediate_quit--; -} - -void -_initialize_copying () -{ - add_info ("copying", copying_info, - "Conditions for redistributing copies of GDB."); - add_info ("warranty", warranty_info, - "Various kinds of warranty you do not have."); -} diff --git a/gnu/usr.bin/gdb/core.c b/gnu/usr.bin/gdb/core.c deleted file mode 100644 index 307addb..0000000 --- a/gnu/usr.bin/gdb/core.c +++ /dev/null @@ -1,581 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)core.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Work with core dump and executable files, for GDB. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "frame.h" /* required by inferior.h */ -#include "inferior.h" - -#ifdef USG -#include -#include -#endif - -#ifdef COFF_ENCAPSULATE -#include "a.out.encap.h" -#else -#include -#endif -#ifndef N_MAGIC -#ifdef COFF_FORMAT -#define N_MAGIC(exec) ((exec).magic) -#else -#define N_MAGIC(exec) ((exec).a_magic) -#endif -#endif -#include -#include -#include -#include -#include - -#ifdef UMAX_CORE -#include -#else -#include -#endif - -#ifndef N_TXTADDR -#define N_TXTADDR(hdr) 0 -#endif /* no N_TXTADDR */ - -#ifndef N_DATADDR -#define N_DATADDR(hdr) hdr.a_text -#endif /* no N_DATADDR */ - -#ifndef COFF_FORMAT -#ifndef AOUTHDR -#define AOUTHDR struct exec -#endif -#endif - -extern char *sys_siglist[]; - -extern core_file_command (), exec_file_command (); - -/* Hook for `exec_file_command' command to call. */ - -void (*exec_file_display_hook) (); - -/* File names of core file and executable file. */ - -char *corefile; -char *execfile; - -/* Descriptors on which core file and executable file are open. - Note that the execchan is closed when an inferior is created - and reopened if the inferior dies or is killed. */ - -int corechan; -int execchan; - -/* Last modification time of executable file. - Also used in source.c to compare against mtime of a source file. */ - -int exec_mtime; - -/* Virtual addresses of bounds of the two areas of memory in the core file. */ - -CORE_ADDR data_start; -CORE_ADDR data_end; -CORE_ADDR stack_start; -CORE_ADDR stack_end; - -#if defined (REG_STACK_SEGMENT) -/* Start and end of the register stack segment. */ -CORE_ADDR reg_stack_start; -CORE_ADDR reg_stack_end; -#endif /* REG_STACK_SEGMENT */ - -/* Virtual addresses of bounds of two areas of memory in the exec file. - Note that the data area in the exec file is used only when there is no core file. */ - -CORE_ADDR text_start; -CORE_ADDR text_end; - -CORE_ADDR exec_data_start; -CORE_ADDR exec_data_end; - -/* Offset within executable file of start of text area data. */ - -int text_offset; - -/* Offset within executable file of start of data area data. */ - -int exec_data_offset; - -/* Offset within core file of start of data area data. */ - -int data_offset; - -/* Offset within core file of start of stack area data. */ - -int stack_offset; - -#ifdef COFF_FORMAT -/* various coff data structures */ - -FILHDR file_hdr; -SCNHDR text_hdr; -SCNHDR data_hdr; - -#endif /* not COFF_FORMAT */ - -/* a.out header saved in core file. */ - -AOUTHDR core_aouthdr; - -/* a.out header of exec file. */ - -AOUTHDR exec_aouthdr; - -void validate_files (); -unsigned int register_addr (); - -/* Call this to specify the hook for exec_file_command to call back. - This is called from the x-window display code. */ - -void -specify_exec_file_hook (hook) - void (*hook) (); -{ - exec_file_display_hook = hook; -} - -/* The exec file must be closed before running an inferior. - If it is needed again after the inferior dies, it must - be reopened. */ - -void -close_exec_file () -{ - if (execchan >= 0) - close (execchan); - execchan = -1; -} - -void -reopen_exec_file () -{ - if (execchan < 0 && execfile != 0) - { - char *filename = concat (execfile, "", ""); - exec_file_command (filename, 0); - free (filename); - } -} - -/* If we have both a core file and an exec file, - print a warning if they don't go together. - This should really check that the core file came - from that exec file, but I don't know how to do it. */ - -void -validate_files () -{ - if (execfile != 0 && corefile != 0) - { - struct stat st_core; - - if (fstat (corechan, &st_core) < 0) - /* It might be a good idea to print an error message. - On the other hand, if the user tries to *do* anything with - the core file, (s)he'll find out soon enough. */ - return; - - if (N_MAGIC (core_aouthdr) != 0 - && bcmp (&core_aouthdr, &exec_aouthdr, sizeof core_aouthdr)) - printf ("Warning: core file does not match specified executable file.\n"); - else if (exec_mtime > st_core.st_mtime) { -#ifdef KERNELDEBUG - extern int kernel_debugging; - if (!kernel_debugging) -#endif - printf ("Warning: exec file is newer than core file.\n"); - } - } -} - -/* Return the name of the executable file as a string. - ERR nonzero means get error if there is none specified; - otherwise return 0 in that case. */ - -char * -get_exec_file (err) - int err; -{ - if (err && execfile == 0) - error ("No executable file specified.\n\ -Use the \"exec-file\" and \"symbol-file\" commands."); - return execfile; -} - -int -have_core_file_p () -{ - return corefile != 0; -} - -static void -files_info () -{ - char *symfile; - extern char *get_sym_file (); - - if (execfile) - printf ("Executable file \"%s\".\n", execfile); - else - printf ("No executable file\n"); - if (corefile == 0) - printf ("No core dump file\n"); - else - printf ("Core dump file \"%s\".\n", corefile); - - if (have_inferior_p ()) - printf ("Using the running image of the program, rather than these files.\n"); - - symfile = get_sym_file (); - if (symfile != 0) - printf ("Symbols from \"%s\".\n", symfile); - -#ifdef FILES_INFO_HOOK - if (FILES_INFO_HOOK ()) - return; -#endif - - if (! have_inferior_p ()) - { - if (execfile) - { - printf ("Text segment in executable from 0x%x to 0x%x.\n", - text_start, text_end); - printf ("Data segment in executable from 0x%x to 0x%x.\n", - exec_data_start, exec_data_end); - if (corefile) - printf ("(But since we have a core file, we're using...)\n"); - } - if (corefile) - { - printf ("Data segment in core file from 0x%x to 0x%x.\n", - data_start, data_end); - printf ("Stack segment in core file from 0x%x to 0x%x.\n", - stack_start, stack_end); - } - } -} - -/* Read "memory data" from core file and/or executable file. - Returns zero if successful, 1 if xfer_core_file failed, errno value if - ptrace failed. */ - -int -read_memory (memaddr, myaddr, len) - CORE_ADDR memaddr; - char *myaddr; - int len; -{ - if (len == 0) - return 0; - - if (have_inferior_p ()) - { - if (remote_debugging) - return remote_read_inferior_memory (memaddr, myaddr, len); - else - return read_inferior_memory (memaddr, myaddr, len); - } - else - return xfer_core_file (memaddr, myaddr, len); -} - -/* Write LEN bytes of data starting at address MYADDR - into debugged program memory at address MEMADDR. - Returns zero if successful, or an errno value if ptrace failed. */ - -int -write_memory (memaddr, myaddr, len) - CORE_ADDR memaddr; - char *myaddr; - int len; -{ - if (have_inferior_p ()) - { - if (remote_debugging) - return remote_write_inferior_memory (memaddr, myaddr, len); - else - return write_inferior_memory (memaddr, myaddr, len); - } - else - error ("Can write memory only when program being debugged is running."); -} - -#ifndef XFER_CORE_FILE -int (*core_file_hook)(); /* hook to handle special core files like - like /dev/mem and crash dumps */ - -/* Read from the program's memory (except for inferior processes). - This function is misnamed, since it only reads, never writes; and - since it will use the core file and/or executable file as necessary. - - It should be extended to write as well as read, FIXME, for patching files. - - Return 0 if address could be read, 1 if not. */ - -int -xfer_core_file (memaddr, myaddr, len) - CORE_ADDR memaddr; - char *myaddr; - int len; -{ - register int i; - register int val; - int xferchan; - char **xferfile; - int fileptr; - int returnval = 0; - - if (core_file_hook) - return ((*core_file_hook)(memaddr, myaddr, len)); - - while (len > 0) - { - xferfile = 0; - xferchan = 0; - - /* Determine which file the next bunch of addresses reside in, - and where in the file. Set the file's read/write pointer - to point at the proper place for the desired address - and set xferfile and xferchan for the correct file. - - If desired address is nonexistent, leave them zero. - - i is set to the number of bytes that can be handled - along with the next address. - - We put the most likely tests first for efficiency. */ - - /* Note that if there is no core file - data_start and data_end are equal. */ - if (memaddr >= data_start && memaddr < data_end) - { - i = min (len, data_end - memaddr); - fileptr = memaddr - data_start + data_offset; - xferfile = &corefile; - xferchan = corechan; - } - /* Note that if there is no core file - stack_start and stack_end are equal. */ - else if (memaddr >= stack_start && memaddr < stack_end) - { - i = min (len, stack_end - memaddr); - fileptr = memaddr - stack_start + stack_offset; - xferfile = &corefile; - xferchan = corechan; - } -#ifdef REG_STACK_SEGMENT - /* Pyramids have an extra segment in the virtual address space - for the (control) stack of register-window frames */ - else if (memaddr >= reg_stack_start && memaddr < reg_stack_end) - { - i = min (len, reg_stack_end - memaddr); - fileptr = memaddr - reg_stack_start + reg_stack_offset; - xferfile = &corefile; - xferchan = corechan; - } -#endif /* REG_STACK_SEGMENT */ - - else if (corechan < 0 - && memaddr >= exec_data_start && memaddr < exec_data_end) - { - i = min (len, exec_data_end - memaddr); - fileptr = memaddr - exec_data_start + exec_data_offset; - xferfile = &execfile; - xferchan = execchan; - } - else if (memaddr >= text_start && memaddr < text_end) - { - i = min (len, text_end - memaddr); - fileptr = memaddr - text_start + text_offset; - xferfile = &execfile; - xferchan = execchan; - } - else if (memaddr < text_start) - { - i = min (len, text_start - memaddr); - } - else if (memaddr >= text_end - && memaddr < (corechan >= 0? data_start : exec_data_start)) - { - i = min (len, data_start - memaddr); - } - else if (corechan >= 0 - && memaddr >= data_end && memaddr < stack_start) - { - i = min (len, stack_start - memaddr); - } - else if (corechan < 0 && memaddr >= exec_data_end) - { - /* Since there is nothing at higher addresses than data - (without a core file or an inferior, there is no - stack, set i to do the rest of the operation now. */ - i = len; - } -#ifdef REG_STACK_SEGMENT - else if (memaddr >= reg_stack_end && reg_stack_end != 0) - { - i = min (len, reg_stack_start - memaddr); - } - else if (memaddr >= stack_end && memaddr < reg_stack_start) -#else /* no REG_STACK_SEGMENT. */ - else if (memaddr >= stack_end && stack_end != 0) -#endif /* no REG_STACK_SEGMENT. */ - { - /* Since there is nothing at higher addresses than - the stack, set i to do the rest of the operation now. */ - i = len; - } - else - { - /* Address did not classify into one of the known ranges. - This shouldn't happen; we catch the endpoints. */ - fatal ("Internal: Bad case logic in xfer_core_file."); - } - - /* Now we know which file to use. - Set up its pointer and transfer the data. */ - if (xferfile) - { - if (*xferfile == 0) - if (xferfile == &execfile) - error ("No program file to examine."); - else - error ("No core dump file or running program to examine."); - val = lseek (xferchan, fileptr, 0); - if (val == -1) - perror_with_name (*xferfile); - val = myread (xferchan, myaddr, i); - if (val < 0) - perror_with_name (*xferfile); - } - /* If this address is for nonexistent memory, - read zeros if reading, or do nothing if writing. - Actually, we never right. */ - else - { - bzero (myaddr, i); - returnval = 1; - } - - memaddr += i; - myaddr += i; - len -= i; - } - return returnval; -} -#endif /* XFER_CORE_FILE */ - -/* My replacement for the read system call. - Used like `read' but keeps going if `read' returns too soon. */ - -int -myread (desc, addr, len) - int desc; - char *addr; - int len; -{ - register int val; - int orglen = len; - - while (len > 0) - { - val = read (desc, addr, len); - if (val < 0) - return val; - if (val == 0) - return orglen - len; - len -= val; - addr += val; - } - return orglen; -} - -#ifdef REGISTER_U_ADDR - -/* Return the address in the core dump or inferior of register REGNO. - BLOCKEND is the address of the end of the user structure. */ - -unsigned int -register_addr (regno, blockend) - int regno; - int blockend; -{ - int addr; - - if (regno < 0 || regno >= NUM_REGS) - error ("Invalid register number %d.", regno); - - REGISTER_U_ADDR (addr, blockend, regno); - - return addr; -} - -#endif /* REGISTER_U_ADDR */ - -void -_initialize_core() -{ - corechan = -1; - execchan = -1; - corefile = 0; - execfile = 0; - exec_file_display_hook = 0; - - text_start = 0; - text_end = 0; - data_start = 0; - data_end = 0; - exec_data_start = 0; - exec_data_end = 0; - stack_start = STACK_END_ADDR; - stack_end = STACK_END_ADDR; - - add_com ("core-file", class_files, core_file_command, - "Use FILE as core dump for examining memory and registers.\n\ -No arg means have no core file."); - add_com ("exec-file", class_files, exec_file_command, - "Use FILE as program for getting contents of pure memory.\n\ -If FILE cannot be found as specified, your execution directory path\n\ -is searched for a command of that name.\n\ -No arg means have no executable file."); - add_info ("files", files_info, "Names of files being debugged."); -} - diff --git a/gnu/usr.bin/gdb/cplus-dem.c b/gnu/usr.bin/gdb/cplus-dem.c deleted file mode 100644 index 8ea9c8b..0000000 --- a/gnu/usr.bin/gdb/cplus-dem.c +++ /dev/null @@ -1,996 +0,0 @@ -/* Demangler for GNU C++ - Copyright (C) 1989 Free Software Foundation, Inc. - written by James Clark (jjc@jclark.uucp) - - 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 1, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* This is for g++ 1.36.1 (November 6 version). It will probably - require changes for any other version. - - Modified for g++ 1.36.2 (November 18 version). */ - -/* This file exports one function - - char *cplus_demangle (const char *name, int mode) - - If NAME is a mangled function name produced by GNU C++, then - a pointer to a malloced string giving a C++ representation - of the name will be returned; otherwise NULL will be returned. - It is the caller's responsibility to free the string which - is returned. - - If MODE > 0, then ANSI qualifiers such as `const' and `void' are output. - Otherwise they are not. - If MODE >= 0, parameters are emitted; otherwise not. - - For example, - - cplus_demangle ("foo__1Ai", 0) => "A::foo(int)" - cplus_demangle ("foo__1Ai", 1) => "A::foo(int)" - cplus_demangle ("foo__1Ai", -1) => "A::foo" - - cplus_demangle ("foo__1Afe", 0) => "A::foo(float,...)" - cplus_demangle ("foo__1Afe", 1) => "A::foo(float,...)" - cplus_demangle ("foo__1Afe", -1) => "A::foo" - - This file imports xmalloc and xrealloc, which are like malloc and - realloc except that they generate a fatal error if there is no - available memory. */ - -/* #define nounderscore 1 /* define this is names don't start with _ */ - -#include -#include - -#ifdef USG -#include -#include -#else -#include -#define memcpy(s1, s2, n) bcopy ((s2), (s1), (n)) -#define memcmp(s1, s2, n) bcmp ((s2), (s1), (n)) -#define strchr index -#define strrchr rindex -#endif - -#ifndef __STDC__ -#define const -#endif - -#ifdef __STDC__ -extern char *cplus_demangle (const char *type, int mode); -#else -extern char *cplus_demangle (); -#endif - -#ifdef __STDC__ -extern char *xmalloc (int); -extern char *xrealloc (char *, int); -#else -extern char *xmalloc (); -extern char *xrealloc (); -#endif - -static char **typevec = 0; -static int ntypes = 0; -static int typevec_size = 0; - -static struct { - const char *in; - const char *out; -} optable[] = { - "new", " new", - "delete", " delete", - "ne", "!=", - "eq", "==", - "ge", ">=", - "gt", ">", - "le", "<=", - "lt", "<", - "plus", "+", - "minus", "-", - "mult", "*", - "convert", "+", /* unary + */ - "negate", "-", /* unary - */ - "trunc_mod", "%", - "trunc_div", "/", - "truth_andif", "&&", - "truth_orif", "||", - "truth_not", "!", - "postincrement", "++", - "postdecrement", "--", - "bit_ior", "|", - "bit_xor", "^", - "bit_and", "&", - "bit_not", "~", - "call", "()", - "cond", "?:", - "alshift", "<<", - "arshift", ">>", - "component", "->", - "indirect", "*", - "method_call", "->()", - "addr", "&", /* unary & */ - "array", "[]", - "nop", "", /* for operator= */ -}; - -/* Beware: these aren't '\0' terminated. */ - -typedef struct { - char *b; /* pointer to start of string */ - char *p; /* pointer after last character */ - char *e; /* pointer after end of allocated space */ -} string; - -#ifdef __STDC__ -static void string_need (string *s, int n); -static void string_delete (string *s); -static void string_init (string *s); -static void string_clear (string *s); -static int string_empty (string *s); -static void string_append (string *p, const char *s); -static void string_appends (string *p, string *s); -static void string_appendn (string *p, const char *s, int n); -static void string_prepend (string *p, const char *s); -#if 0 -static void string_prepends (string *p, string *s); -#endif -static void string_prependn (string *p, const char *s, int n); -static int get_count (const char **type, int *count); -static int do_args (const char **type, string *decl, int arg_mode); -static int do_type (const char **type, string *result, int arg_mode); -static int do_arg (const char **type, string *result, int arg_mode); -static void munge_function_name (string *name, int arg_mode); -static void remember_type (const char *type, int len); -#else -static void string_need (); -static void string_delete (); -static void string_init (); -static void string_clear (); -static int string_empty (); -static void string_append (); -static void string_appends (); -static void string_appendn (); -static void string_prepend (); -static void string_prepends (); -static void string_prependn (); -static int get_count (); -static int do_args (); -static int do_type (); -static int do_arg (); -static int do_args (); -static void munge_function_name (); -static void remember_type (); -#endif - -char * -cplus_demangle (type, arg_mode) - const char *type; - int arg_mode; -{ - string decl; - int n; - int success = 0; - int constructor = 0; - int const_flag = 0; - int i; - const char *p; -#ifndef LONGERNAMES - const char *premangle; -#endif - -# define print_ansi_qualifiers (arg_mode > 0) -# define print_arg_types (arg_mode >= 0) - - if (type == NULL || *type == '\0') - return NULL; -#ifndef nounderscore - if (*type++ != '_') - return NULL; -#endif - p = type; - while (*p != '\0' && !(*p == '_' && p[1] == '_')) - p++; - if (*p == '\0') - { - /* destructor */ - if (type[0] == '_' && type[1] == '$' && type[2] == '_') - { - int n = (strlen (type) - 3)*2 + 3 + 2 + 1; - char *tem = (char *) xmalloc (n); - strcpy (tem, type + 3); - strcat (tem, "::~"); - strcat (tem, type + 3); - strcat (tem, "()"); - return tem; - } - /* static data member */ - if (*type != '_' && (p = strchr (type, '$')) != NULL) - { - int n = strlen (type) + 2; - char *tem = (char *) xmalloc (n); - memcpy (tem, type, p - type); - strcpy (tem + (p - type), "::"); - strcpy (tem + (p - type) + 2, p + 1); - return tem; - } - /* virtual table "_vt$" */ - if (type[0] == '_' && type[1] == 'v' && type[2] == 't' && type[3] == '$') - { - int n = strlen (type + 4) + 14 + 1; - char *tem = (char *) xmalloc (n); - strcpy (tem, type + 4); - strcat (tem, " virtual table"); - return tem; - } - return NULL; - } - - string_init (&decl); - - if (p == type) - { - if (!isdigit (p[2])) - { - string_delete (&decl); - return NULL; - } - constructor = 1; - } - else - { - string_appendn (&decl, type, p - type); - munge_function_name (&decl, arg_mode); - } - p += 2; - -#ifndef LONGERNAMES - premangle = p; -#endif - switch (*p) - { - case 'C': - /* a const member function */ - if (!isdigit (p[1])) - { - string_delete (&decl); - return NULL; - } - p += 1; - const_flag = 1; - /* fall through */ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - n = 0; - do - { - n *= 10; - n += *p - '0'; - p += 1; - } - while (isdigit (*p)); - if (strlen (p) < n) - { - string_delete (&decl); - return NULL; - } - if (constructor) - { - string_appendn (&decl, p, n); - string_append (&decl, "::"); - string_appendn (&decl, p, n); - } - else - { - string_prepend (&decl, "::"); - string_prependn (&decl, p, n); - } - p += n; -#ifndef LONGERNAMES - remember_type (premangle, p - premangle); -#endif - success = do_args (&p, &decl, arg_mode); - if (const_flag && print_arg_types) - string_append (&decl, " const"); - break; - case 'F': - p += 1; - success = do_args (&p, &decl, arg_mode); - break; - } - - for (i = 0; i < ntypes; i++) - if (typevec[i] != NULL) - free (typevec[i]); - ntypes = 0; - if (typevec != NULL) - { - free ((char *)typevec); - typevec = NULL; - typevec_size = 0; - } - - if (success) - { - string_appendn (&decl, "", 1); - return decl.b; - } - else - { - string_delete (&decl); - return NULL; - } -} - -static int -get_count (type, count) - const char **type; - int *count; -{ - if (!isdigit (**type)) - return 0; - *count = **type - '0'; - *type += 1; - /* see flush_repeats in cplus-method.c */ - if (isdigit (**type)) - { - const char *p = *type; - int n = *count; - do - { - n *= 10; - n += *p - '0'; - p += 1; - } - while (isdigit (*p)); - if (*p == '_') - { - *type = p + 1; - *count = n; - } - } - return 1; -} - -/* result will be initialised here; it will be freed on failure */ - -static int -do_type (type, result, arg_mode) - const char **type; - string *result; - int arg_mode; -{ - int n; - int done; - int non_empty = 0; - int success; - string decl; - const char *remembered_type; - - string_init (&decl); - string_init (result); - - done = 0; - success = 1; - while (success && !done) - { - int member; - switch (**type) - { - case 'P': - *type += 1; - string_prepend (&decl, "*"); - break; - - case 'R': - *type += 1; - string_prepend (&decl, "&"); - break; - - case 'T': - *type += 1; - if (!get_count (type, &n) || n >= ntypes) - success = 0; - else - { - remembered_type = typevec[n]; - type = &remembered_type; - } - break; - - case 'F': - *type += 1; - if (!string_empty (&decl) && decl.b[0] == '*') - { - string_prepend (&decl, "("); - string_append (&decl, ")"); - } - if (!do_args (type, &decl, arg_mode) || **type != '_') - success = 0; - else - *type += 1; - break; - - case 'M': - case 'O': - { - int constp = 0; - int volatilep = 0; - - member = **type == 'M'; - *type += 1; - if (!isdigit (**type)) - { - success = 0; - break; - } - n = 0; - do - { - n *= 10; - n += **type - '0'; - *type += 1; - } - while (isdigit (**type)); - if (strlen (*type) < n) - { - success = 0; - break; - } - string_append (&decl, ")"); - string_prepend (&decl, "::"); - string_prependn (&decl, *type, n); - string_prepend (&decl, "("); - *type += n; - if (member) - { - if (**type == 'C') - { - *type += 1; - constp = 1; - } - if (**type == 'V') - { - *type += 1; - volatilep = 1; - } - if (*(*type)++ != 'F') - { - success = 0; - break; - } - } - if ((member && !do_args (type, &decl, arg_mode)) || **type != '_') - { - success = 0; - break; - } - *type += 1; - if (! print_ansi_qualifiers) - break; - if (constp) - { - if (non_empty) - string_append (&decl, " "); - else - non_empty = 1; - string_append (&decl, "const"); - } - if (volatilep) - { - if (non_empty) - string_append (&decl, " "); - else - non_empty = 1; - string_append (&decl, "volatile"); - } - break; - } - - case 'C': - if ((*type)[1] == 'P') - { - *type += 1; - if (print_ansi_qualifiers) - { - if (!string_empty (&decl)) - string_prepend (&decl, " "); - string_prepend (&decl, "const"); - } - break; - } - - /* fall through */ - default: - done = 1; - break; - } - } - - done = 0; - non_empty = 0; - while (success && !done) - { - switch (**type) - { - case 'C': - *type += 1; - if (print_ansi_qualifiers) - { - if (non_empty) - string_append (result, " "); - else - non_empty = 1; - string_append (result, "const"); - } - break; - case 'U': - *type += 1; - if (non_empty) - string_append (result, " "); - else - non_empty = 1; - string_append (result, "unsigned"); - break; - case 'V': - *type += 1; - if (print_ansi_qualifiers) - { - if (non_empty) - string_append (result, " "); - else - non_empty = 1; - string_append (result, "volatile"); - } - break; - default: - done = 1; - break; - } - } - - if (success) - switch (**type) - { - case '\0': - case '_': - break; - case 'v': - *type += 1; - if (non_empty) - string_append (result, " "); - string_append (result, "void"); - break; - case 'x': - *type += 1; - if (non_empty) - string_append (result, " "); - string_append (result, "long long"); - break; - case 'l': - *type += 1; - if (non_empty) - string_append (result, " "); - string_append (result, "long"); - break; - case 'i': - *type += 1; - if (non_empty) - string_append (result, " "); - string_append (result, "int"); - break; - case 's': - *type += 1; - if (non_empty) - string_append (result, " "); - string_append (result, "short"); - break; - case 'c': - *type += 1; - if (non_empty) - string_append (result, " "); - string_append (result, "char"); - break; - case 'r': - *type += 1; - if (non_empty) - string_append (result, " "); - string_append (result, "long double"); - break; - case 'd': - *type += 1; - if (non_empty) - string_append (result, " "); - string_append (result, "double"); - break; - case 'f': - *type += 1; - if (non_empty) - string_append (result, " "); - string_append (result, "float"); - break; - case 'G': - *type += 1; - if (!isdigit (**type)) - { - success = 0; - break; - } - /* fall through */ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - n = 0; - do - { - n *= 10; - n += **type - '0'; - *type += 1; - } - while (isdigit (**type)); - if (strlen (*type) < n) - { - success = 0; - break; - } - if (non_empty) - string_append (result, " "); - string_appendn (result, *type, n); - *type += n; - break; - default: - success = 0; - break; - } - - if (success) - { - if (!string_empty (&decl)) - { - string_append (result, " "); - string_appends (result, &decl); - } - string_delete (&decl); - return 1; - } - else - { - string_delete (&decl); - string_delete (result); - return 0; - } -} - -/* `result' will be initialised in do_type; it will be freed on failure */ - -static int -do_arg (type, result, arg_mode) - const char **type; - string *result; - int arg_mode; -{ - const char *start = *type; - - if (!do_type (type, result, arg_mode)) - return 0; - remember_type (start, *type - start); - return 1; -} - -static void -remember_type (start, len) - const char *start; - int len; -{ - char *tem; - - if (ntypes >= typevec_size) - { - if (typevec_size == 0) - { - typevec_size = 3; - typevec = (char **) xmalloc (sizeof (char*)*typevec_size); - } - else - { - typevec_size *= 2; - typevec = (char **) xrealloc ((char *)typevec, sizeof (char*)*typevec_size); - } - } - tem = (char *) xmalloc (len + 1); - memcpy (tem, start, len); - tem[len] = '\0'; - typevec[ntypes++] = tem; -} - -/* `decl' must be already initialised, usually non-empty; - it won't be freed on failure */ - -static int -do_args (type, decl, arg_mode) - const char **type; - string *decl; - int arg_mode; -{ - string arg; - int need_comma = 0; - - if (print_arg_types) - string_append (decl, "("); - - while (**type != '_' && **type != '\0' && **type != 'e' && **type != 'v') - { - if (**type == 'N') - { - int r; - int t; - *type += 1; - if (!get_count (type, &r) || !get_count (type, &t) || t >= ntypes) - return 0; - while (--r >= 0) - { - const char *tem = typevec[t]; - if (need_comma && print_arg_types) - string_append (decl, ", "); - if (!do_arg (&tem, &arg, arg_mode)) - return 0; - if (print_arg_types) - string_appends (decl, &arg); - string_delete (&arg); - need_comma = 1; - } - } - else - { - if (need_comma & print_arg_types) - string_append (decl, ", "); - if (!do_arg (type, &arg, arg_mode)) - return 0; - if (print_arg_types) - string_appends (decl, &arg); - string_delete (&arg); - need_comma = 1; - } - } - - if (**type == 'v') - *type += 1; - else if (**type == 'e') - { - *type += 1; - if (print_arg_types) - { - if (need_comma) - string_append (decl, ","); - string_append (decl, "..."); - } - } - - if (print_arg_types) - string_append (decl, ")"); - return 1; -} - -static void -munge_function_name (name, arg_mode) - string *name; - int arg_mode; -{ - if (!string_empty (name) && name->p - name->b >= 3 - && name->b[0] == 'o' && name->b[1] == 'p' && name->b[2] == '$') - { - int i; - /* see if it's an assignment expression */ - if (name->p - name->b >= 10 /* op$assign_ */ - && memcmp (name->b + 3, "assign_", 7) == 0) - { - for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++) - { - int len = name->p - name->b - 10; - if (strlen (optable[i].in) == len - && memcmp (optable[i].in, name->b + 10, len) == 0) - { - string_clear (name); - string_append (name, "operator"); - string_append (name, optable[i].out); - string_append (name, "="); - return; - } - } - } - else - { - for (i = 0; i < sizeof (optable)/sizeof (optable[0]); i++) - { - int len = name->p - name->b - 3; - if (strlen (optable[i].in) == len - && memcmp (optable[i].in, name->b + 3, len) == 0) - { - string_clear (name); - string_append (name, "operator"); - string_append (name, optable[i].out); - return; - } - } - } - return; - } - else if (!string_empty (name) && name->p - name->b >= 5 - && memcmp (name->b, "type$", 5) == 0) - { - /* type conversion operator */ - string type; - const char *tem = name->b + 5; - if (do_type (&tem, &type, arg_mode)) - { - string_clear (name); - string_append (name, "operator "); - string_appends (name, &type); - string_delete (&type); - return; - } - } -} - -/* a mini string-handling package */ - -static void -string_need (s, n) - string *s; - int n; -{ - if (s->b == NULL) - { - if (n < 32) - n = 32; - s->p = s->b = (char *) xmalloc (n); - s->e = s->b + n; - } - else if (s->e - s->p < n) - { - int tem = s->p - s->b; - n += tem; - n *= 2; - s->b = (char *) xrealloc (s->b, n); - s->p = s->b + tem; - s->e = s->b + n; - } -} - -static void -string_delete (s) - string *s; -{ - if (s->b != NULL) - { - free (s->b); - s->b = s->e = s->p = NULL; - } -} - -static void -string_init (s) - string *s; -{ - s->b = s->p = s->e = NULL; -} - -static void -string_clear (s) - string *s; -{ - s->p = s->b; -} - -static int -string_empty (s) - string *s; -{ - return s->b == s->p; -} - -static void -string_append (p, s) - string *p; - const char *s; -{ - int n; - if (s == NULL || *s == '\0') - return; - n = strlen (s); - string_need (p, n); - memcpy (p->p, s, n); - p->p += n; -} - -static void -string_appends (p, s) - string *p, *s; -{ - int n; - if (s->b == s->p) - return; - n = s->p - s->b; - string_need (p, n); - memcpy (p->p, s->b, n); - p->p += n; -} - -static void -string_appendn (p, s, n) - string *p; - const char *s; - int n; -{ - if (n == 0) - return; - string_need (p, n); - memcpy (p->p, s, n); - p->p += n; -} - -static void -string_prepend (p, s) - string *p; - const char *s; -{ - if (s == NULL || *s == '\0') - return; - string_prependn (p, s, strlen (s)); -} - -#if 0 -static void -string_prepends (p, s) - string *p, *s; -{ - if (s->b == s->p) - return; - string_prependn (p, s->b, s->p - s->b); -} -#endif - -static void -string_prependn (p, s, n) - string *p; - const char *s; - int n; -{ - char *q; - - if (n == 0) - return; - string_need (p, n); - for (q = p->p - 1; q >= p->b; q--) - q[n] = q[0]; - memcpy (p->b, s, n); - p->p += n; -} diff --git a/gnu/usr.bin/gdb/dbxread.c b/gnu/usr.bin/gdb/dbxread.c deleted file mode 100644 index 7a25665..0000000 --- a/gnu/usr.bin/gdb/dbxread.c +++ /dev/null @@ -1,5727 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)dbxread.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Read dbx symbol tables and convert to internal format, for GDB. - Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Symbol read-in occurs in two phases: - 1. A scan (read_dbx_symtab()) of the entire executable, whose sole - purpose is to make a list of symbols (partial symbol table) - which will cause symbols - to be read in if referenced. This scan happens when the - "symbol-file" command is given (symbol_file_command()). - 2. Full read-in of symbols. (psymtab_to_symtab()). This happens - when a symbol in a file for which symbols have not yet been - read in is referenced. - 2a. The "add-file" command. Similar to #2. */ - -#include -#include "defs.h" -#include "param.h" - -#ifdef READ_DBX_FORMAT - -#ifdef USG -#include -#include -#define L_SET 0 -#define L_INCR 1 -#endif - -#ifdef COFF_ENCAPSULATE -#include "a.out.encap.h" -#include "stab.gnu.h" -#else -#include -#include -#endif -#include - -#ifndef NO_GNU_STABS -/* - * Define specifically gnu symbols here. - */ - -/* The following type indicates the definition of a symbol as being - an indirect reference to another symbol. The other symbol - appears as an undefined reference, immediately following this symbol. - - Indirection is asymmetrical. The other symbol's value will be used - to satisfy requests for the indirect symbol, but not vice versa. - If the other symbol does not have a definition, libraries will - be searched to find a definition. */ -#ifndef N_INDR -#define N_INDR 0xa -#endif - -/* The following symbols refer to set elements. - All the N_SET[ATDB] symbols with the same name form one set. - Space is allocated for the set in the text section, and each set - element's value is stored into one word of the space. - The first word of the space is the length of the set (number of elements). - - The address of the set is made into an N_SETV symbol - whose name is the same as the name of the set. - This symbol acts like a N_DATA global symbol - in that it can satisfy undefined external references. */ - -#ifndef N_SETA -#define N_SETA 0x14 /* Absolute set element symbol */ -#endif /* This is input to LD, in a .o file. */ - -#ifndef N_SETT -#define N_SETT 0x16 /* Text set element symbol */ -#endif /* This is input to LD, in a .o file. */ - -#ifndef N_SETD -#define N_SETD 0x18 /* Data set element symbol */ -#endif /* This is input to LD, in a .o file. */ - -#ifndef N_SETB -#define N_SETB 0x1A /* Bss set element symbol */ -#endif /* This is input to LD, in a .o file. */ - -/* Macros dealing with the set element symbols defined in a.out.h */ -#define SET_ELEMENT_P(x) ((x)>=N_SETA&&(x)<=(N_SETB|N_EXT)) -#define TYPE_OF_SET_ELEMENT(x) ((x)-N_SETA+N_ABS) - -#ifndef N_SETV -#define N_SETV 0x1C /* Pointer to set vector in data area. */ -#endif /* This is output from LD. */ - -#ifndef N_WARNING -#define N_WARNING 0x1E /* Warning message to print if file included */ -#endif /* This is input to ld */ - -#ifndef __GNU_STAB__ - -/* Line number for the data section. This is to be used to describe - the source location of a variable declaration. */ -#ifndef N_DSLINE -#define N_DSLINE (N_SLINE+N_DATA-N_TEXT) -#endif - -/* Line number for the bss section. This is to be used to describe - the source location of a variable declaration. */ -#ifndef N_BSLINE -#define N_BSLINE (N_SLINE+N_BSS-N_TEXT) -#endif - -#endif /* not __GNU_STAB__ */ -#endif /* NO_GNU_STABS */ - -#include -#include -#include -#include - -#include "symtab.h" - -#ifndef COFF_FORMAT -#ifndef AOUTHDR -#define AOUTHDR struct exec -#endif -#endif - -static void add_symbol_to_list (); -static void read_dbx_symtab (); -static void process_one_symbol (); -static void free_all_psymbols (); -static struct type *read_type (); -static struct type *read_range_type (); -static struct type *read_enum_type (); -static struct type *read_struct_type (); -static struct type *read_array_type (); -static long read_number (); -static void read_huge_number (); -static void finish_block (); -static struct blockvector *make_blockvector (); -static struct symbol *define_symbol (); -static void start_subfile (); -static int hashname (); -static void hash_symsegs (); -static struct pending *copy_pending (); -static void fix_common_block (); - -static void add_undefined_type (); -static void cleanup_undefined_types (); - -extern char *index(); - -extern struct symtab *read_symsegs (); -extern void free_all_symtabs (); -extern void free_all_psymtabs (); -extern void free_inclink_symtabs (); - -/* C++ */ -static struct type **read_args (); - -/* Macro to determine which symbols to ignore when reading the first symbol - of a file. Some machines override this definition. */ -#ifdef N_NSYMS -#ifndef IGNORE_SYMBOL -/* This code is used on Ultrix systems. Ignore it */ -#define IGNORE_SYMBOL(type) (type == N_NSYMS) -#endif -#else -#ifndef IGNORE_SYMBOL -/* Don't ignore any symbols. */ -#define IGNORE_SYMBOL(type) (0) -#endif -#endif /* not N_NSYMS */ - -/* Macro for number of symbol table entries (in usual a.out format). - Some machines override this definition. */ -#ifndef NUMBER_OF_SYMBOLS -#ifdef COFF_HEADER -#define NUMBER_OF_SYMBOLS \ - ((COFF_HEADER(hdr) ? hdr.coffhdr.filehdr.f_nsyms : hdr.a_syms) / \ - sizeof (struct nlist)) -#else -#define NUMBER_OF_SYMBOLS (hdr.a_syms / sizeof (struct nlist)) -#endif -#endif - -/* Macro for file-offset of symbol table (in usual a.out format). */ -#ifndef SYMBOL_TABLE_OFFSET -#define SYMBOL_TABLE_OFFSET N_SYMOFF (hdr) -#endif - -/* Macro for file-offset of string table (in usual a.out format). */ -#ifndef STRING_TABLE_OFFSET -#define STRING_TABLE_OFFSET (N_SYMOFF (hdr) + hdr.a_syms) -#endif - -/* Macro to store the length of the string table data in INTO. */ -#ifndef READ_STRING_TABLE_SIZE -#define READ_STRING_TABLE_SIZE(INTO) \ -{ val = myread (desc, &INTO, sizeof INTO); \ - if (val < 0) perror_with_name (name); } -#endif - -/* Macro to declare variables to hold the file's header data. */ -#ifndef DECLARE_FILE_HEADERS -#define DECLARE_FILE_HEADERS AOUTHDR hdr -#endif - -/* Macro to read the header data from descriptor DESC and validate it. - NAME is the file name, for error messages. */ -#ifndef READ_FILE_HEADERS -#ifdef HEADER_SEEK_FD -#define READ_FILE_HEADERS(DESC, NAME) \ -{ HEADER_SEEK_FD (DESC); \ - val = myread (DESC, &hdr, sizeof hdr); \ - if (val < 0) perror_with_name (NAME); \ - if (N_BADMAG (hdr)) \ - error ("File \"%s\" not in executable format.", NAME); } -#else -#define READ_FILE_HEADERS(DESC, NAME) \ -{ val = myread (DESC, &hdr, sizeof hdr); \ - if (val < 0) perror_with_name (NAME); \ - if (N_BADMAG (hdr)) \ - error ("File \"%s\" not in executable format.", NAME); } -#endif -#endif - -/* Non-zero if this is an object (.o) file, rather than an executable. - Distinguishing between the two is rarely necessary (and seems like - a hack, but there is no other way to do ADDR_OF_TEXT_SEGMENT - right for SunOS). */ -#if !defined (IS_OBJECT_FILE) -/* This will not work - if someone decides to make ld preserve relocation info. */ -#define IS_OBJECT_FILE (hdr.a_trsize != 0) -#endif - -/* Macro for size of text segment */ -#ifndef SIZE_OF_TEXT_SEGMENT -#define SIZE_OF_TEXT_SEGMENT hdr.a_text -#endif - -/* Get the address in debugged memory of the start - of the text segment. */ -#if !defined (ADDR_OF_TEXT_SEGMENT) -#if defined (N_TXTADDR) -#define ADDR_OF_TEXT_SEGMENT (IS_OBJECT_FILE ? 0 : N_TXTADDR (hdr)) -#else /* no N_TXTADDR */ -#define ADDR_OF_TEXT_SEGMENT 0 -#endif /* no N_TXTADDR */ -#endif /* no ADDR_OF_TEXT_SEGMENT */ - -/* Macro to get entry point from headers. */ -#ifndef ENTRY_POINT -#define ENTRY_POINT hdr.a_entry -#endif - -/* Macro for name of symbol to indicate a file compiled with gcc. */ -#ifndef GCC_COMPILED_FLAG_SYMBOL -#define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled." -#endif - -/* Convert stab register number (from `r' declaration) to a gdb REGNUM. */ - -#ifndef STAB_REG_TO_REGNUM -#define STAB_REG_TO_REGNUM(VALUE) (VALUE) -#endif - -/* Define this as 1 if a pcc declaration of a char or short argument - gives the correct address. Otherwise assume pcc gives the - address of the corresponding int, which is not the same on a - big-endian machine. */ - -#ifndef BELIEVE_PCC_PROMOTION -#define BELIEVE_PCC_PROMOTION 0 -#endif - -/* Nonzero means give verbose info on gdb action. From main.c. */ -extern int info_verbose; - -/* Chain of symtabs made from reading the file's symsegs. - These symtabs do not go into symtab_list themselves, - but the information is copied from them when appropriate - to make the symtabs that will exist permanently. */ - -static struct symtab *symseg_chain; - -/* Symseg symbol table for the file whose data we are now processing. - It is one of those in symseg_chain. Or 0, for a compilation that - has no symseg. */ - -static struct symtab *current_symseg; - -/* Name of source file whose symbol data we are now processing. - This comes from a symbol of type N_SO. */ - -static char *last_source_file; - -/* Core address of start of text of current source file. - This too comes from the N_SO symbol. */ - -static CORE_ADDR last_source_start_addr; - -/* End of the text segment of the executable file, - as found in the symbol _etext. */ - -static CORE_ADDR end_of_text_addr; - -/* The list of sub-source-files within the current individual compilation. - Each file gets its own symtab with its own linetable and associated info, - but they all share one blockvector. */ - -struct subfile -{ - struct subfile *next; - char *name; - struct linetable *line_vector; - int line_vector_length; - int line_vector_index; - int prev_line_number; -}; - -static struct subfile *subfiles; - -static struct subfile *current_subfile; - -/* Count symbols as they are processed, for error messages. */ - -static int symnum; - -/* Vector of types defined so far, indexed by their dbx type numbers. - (In newer sun systems, dbx uses a pair of numbers in parens, - as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be - translated through the type_translations hash table to get - the index into the type vector.) */ - -static struct typevector *type_vector; - -/* Number of elements allocated for type_vector currently. */ - -static int type_vector_length; - -/* Vector of line number information. */ - -static struct linetable *line_vector; - -/* Index of next entry to go in line_vector_index. */ - -static int line_vector_index; - -/* Last line number recorded in the line vector. */ - -static int prev_line_number; - -/* Number of elements allocated for line_vector currently. */ - -static int line_vector_length; - -/* Hash table of global symbols whose values are not known yet. - They are chained thru the SYMBOL_VALUE, since we don't - have the correct data for that slot yet. */ -/* The use of the LOC_BLOCK code in this chain is nonstandard-- - it refers to a FORTRAN common block rather than the usual meaning. */ - -#define HASHSIZE 127 -static struct symbol *global_sym_chain[HASHSIZE]; - -/* Record the symbols defined for each context in a list. - We don't create a struct block for the context until we - know how long to make it. */ - -#define PENDINGSIZE 100 - -struct pending -{ - struct pending *next; - int nsyms; - struct symbol *symbol[PENDINGSIZE]; -}; - -/* List of free `struct pending' structures for reuse. */ -struct pending *free_pendings; - -/* Here are the three lists that symbols are put on. */ - -struct pending *file_symbols; /* static at top level, and types */ - -struct pending *global_symbols; /* global functions and variables */ - -struct pending *local_symbols; /* everything local to lexical context */ - -/* List of symbols declared since the last BCOMM. This list is a tail - of local_symbols. When ECOMM is seen, the symbols on the list - are noted so their proper addresses can be filled in later, - using the common block base address gotten from the assembler - stabs. */ - -struct pending *common_block; -int common_block_i; - -/* Stack representing unclosed lexical contexts - (that will become blocks, eventually). */ - -struct context_stack -{ - struct pending *locals; - struct pending_block *old_blocks; - struct symbol *name; - CORE_ADDR start_addr; - int depth; -}; - -struct context_stack *context_stack; - -/* Index of first unused entry in context stack. */ -int context_stack_depth; - -/* Currently allocated size of context stack. */ - -int context_stack_size; - -/* Nonzero if within a function (so symbols should be local, - if nothing says specifically). */ - -int within_function; - -/* List of blocks already made (lexical contexts already closed). - This is used at the end to make the blockvector. */ - -struct pending_block -{ - struct pending_block *next; - struct block *block; -}; - -struct pending_block *pending_blocks; - -extern CORE_ADDR startup_file_start; /* From blockframe.c */ -extern CORE_ADDR startup_file_end; /* From blockframe.c */ - -/* File name symbols were loaded from. */ - -static char *symfile; - -/* Low and high symbol values (inclusive) for the global variable - entries in the symbol file. */ - -static int first_global_sym, last_global_sym; - -/* Structures with which to manage partial symbol allocation. */ - -struct psymbol_allocation_list global_psymbols, static_psymbols; - -/* Global variable which, when set, indicates that we are processing a - .o file compiled with gcc */ - -static unsigned char processing_gcc_compilation; - -/* Make a list of forward references which haven't been defined. */ -static struct type **undef_types; -static int undef_types_allocated, undef_types_length; - - /* Setup a define to deal cleanly with the underscore problem */ - -#ifdef NAMES_HAVE_UNDERSCORE -#define HASH_OFFSET 1 -#else -#define HASH_OFFSET 0 -#endif - -#if 0 -/* I'm not sure why this is here. To debug bugs which cause - an infinite loop of allocations, I suppose. In any event, - dumping core when out of memory isn't usually right. */ -static int -xxmalloc (n) -{ - int v = malloc (n); - if (v == 0) - { - fprintf (stderr, "Virtual memory exhausted.\n"); - abort (); - } - return v; -} -#else /* not 0 */ -#define xxmalloc xmalloc -#endif /* not 0 */ - -/* Make a copy of the string at PTR with SIZE characters in the symbol obstack - (and add a null character at the end in the copy). - Returns the address of the copy. */ - -static char * -obsavestring (ptr, size) - char *ptr; - int size; -{ - register char *p = (char *) obstack_alloc (symbol_obstack, size + 1); - /* Open-coded bcopy--saves function call time. - These strings are usually short. */ - { - register char *p1 = ptr; - register char *p2 = p; - char *end = ptr + size; - while (p1 != end) - *p2++ = *p1++; - } - p[size] = 0; - return p; -} - -/* Concatenate strings S1, S2 and S3; return the new string. - Space is found in the symbol_obstack. */ - -static char * -obconcat (s1, s2, s3) - char *s1, *s2, *s3; -{ - register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1; - register char *val = (char *) obstack_alloc (symbol_obstack, len); - strcpy (val, s1); - strcat (val, s2); - strcat (val, s3); - return val; -} - -/* Support for Sun changes to dbx symbol format */ - -/* For each identified header file, we have a table of types defined - in that header file. - - header_files maps header file names to their type tables. - It is a vector of n_header_files elements. - Each element describes one header file. - It contains a vector of types. - - Sometimes it can happen that the same header file produces - different results when included in different places. - This can result from conditionals or from different - things done before including the file. - When this happens, there are multiple entries for the file in this table, - one entry for each distinct set of results. - The entries are distinguished by the INSTANCE field. - The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is - used to match header-file references to their corresponding data. */ - -struct header_file -{ - char *name; /* Name of header file */ - int instance; /* Numeric code distinguishing instances - of one header file that produced - different results when included. - It comes from the N_BINCL or N_EXCL. */ - struct type **vector; /* Pointer to vector of types */ - int length; /* Allocated length (# elts) of that vector */ -}; - -static struct header_file *header_files; - -static int n_header_files; - -static int n_allocated_header_files; - -/* During initial symbol readin, we need to have a structure to keep - track of which psymtabs have which bincls in them. This structure - is used during readin to setup the list of dependencies within each - partial symbol table. */ - -struct header_file_location -{ - char *name; /* Name of header file */ - int instance; /* See above */ - struct partial_symtab *pst; /* Partial symtab that has the - BINCL/EINCL defs for this file */ -}; - -/* The actual list and controling variables */ -static struct header_file_location *bincl_list, *next_bincl; -static int bincls_allocated; - -/* Within each object file, various header files are assigned numbers. - A type is defined or referred to with a pair of numbers - (FILENUM,TYPENUM) where FILENUM is the number of the header file - and TYPENUM is the number within that header file. - TYPENUM is the index within the vector of types for that header file. - - FILENUM == 1 is special; it refers to the main source of the object file, - and not to any header file. FILENUM != 1 is interpreted by looking it up - in the following table, which contains indices in header_files. */ - -static int *this_object_header_files; - -static int n_this_object_header_files; - -static int n_allocated_this_object_header_files; - -/* When a header file is getting special overriding definitions - for one source file, record here the header_files index - of its normal definition vector. - At other times, this is -1. */ - -static int header_file_prev_index; - -/* At the start of reading dbx symbols, allocate our tables. */ - -static void -init_header_files () -{ - n_allocated_header_files = 10; - header_files = (struct header_file *) xxmalloc (10 * sizeof (struct header_file)); - n_header_files = 0; - - n_allocated_this_object_header_files = 10; - this_object_header_files = (int *) xxmalloc (10 * sizeof (int)); -} - -/* At the end of reading dbx symbols, free our tables. */ - -static void -free_header_files () -{ - register int i; - for (i = 0; i < n_header_files; i++) - free (header_files[i].name); - if (header_files) free (header_files); - if (this_object_header_files) - free (this_object_header_files); -} - -/* Called at the start of each object file's symbols. - Clear out the mapping of header file numbers to header files. */ - -static void -new_object_header_files () -{ - /* Leave FILENUM of 0 free for builtin types and this file's types. */ - n_this_object_header_files = 1; - header_file_prev_index = -1; -} - -/* Add header file number I for this object file - at the next successive FILENUM. */ - -static void -add_this_object_header_file (i) - int i; -{ - if (n_this_object_header_files == n_allocated_this_object_header_files) - { - n_allocated_this_object_header_files *= 2; - this_object_header_files - = (int *) xrealloc (this_object_header_files, - n_allocated_this_object_header_files * sizeof (int)); - } - - this_object_header_files[n_this_object_header_files++] = i; -} - -/* Add to this file an "old" header file, one already seen in - a previous object file. NAME is the header file's name. - INSTANCE is its instance code, to select among multiple - symbol tables for the same header file. */ - -static void -add_old_header_file (name, instance) - char *name; - int instance; -{ - register struct header_file *p = header_files; - register int i; - - for (i = 0; i < n_header_files; i++) - if (!strcmp (p[i].name, name) && instance == p[i].instance) - { - add_this_object_header_file (i); - return; - } - error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.", - symnum); -} - -/* Add to this file a "new" header file: definitions for its types follow. - NAME is the header file's name. - Most often this happens only once for each distinct header file, - but not necessarily. If it happens more than once, INSTANCE has - a different value each time, and references to the header file - use INSTANCE values to select among them. - - dbx output contains "begin" and "end" markers for each new header file, - but at this level we just need to know which files there have been; - so we record the file when its "begin" is seen and ignore the "end". */ - -static void -add_new_header_file (name, instance) - char *name; - int instance; -{ - register int i; - register struct header_file *p = header_files; - header_file_prev_index = -1; - -#if 0 - /* This code was used before I knew about the instance codes. - My first hypothesis is that it is not necessary now - that instance codes are handled. */ - - /* Has this header file a previous definition? - If so, make a new entry anyway so that this use in this source file - gets a separate entry. Later source files get the old entry. - Record here the index of the old entry, so that any type indices - not previously defined can get defined in the old entry as - well as in the new one. */ - - for (i = 0; i < n_header_files; i++) - if (!strcmp (p[i].name, name)) - { - header_file_prev_index = i; - } - -#endif - - /* Make sure there is room for one more header file. */ - - if (n_header_files == n_allocated_header_files) - { - n_allocated_header_files *= 2; - header_files = (struct header_file *) - xrealloc (header_files, - (n_allocated_header_files - * sizeof (struct header_file))); - } - - /* Create an entry for this header file. */ - - i = n_header_files++; - header_files[i].name = savestring (name, strlen(name)); - header_files[i].instance = instance; - header_files[i].length = 10; - header_files[i].vector - = (struct type **) xxmalloc (10 * sizeof (struct type *)); - bzero (header_files[i].vector, 10 * sizeof (struct type *)); - - add_this_object_header_file (i); -} - -/* Look up a dbx type-number pair. Return the address of the slot - where the type for that number-pair is stored. - The number-pair is in TYPENUMS. - - This can be used for finding the type associated with that pair - or for associating a new type with the pair. */ - -static struct type ** -dbx_lookup_type (typenums) - int typenums[2]; -{ - register int filenum = typenums[0], index = typenums[1]; - - if (filenum < 0 || filenum >= n_this_object_header_files) - error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.", - filenum, index, symnum); - - if (filenum == 0) - { - /* Type is defined outside of header files. - Find it in this object file's type vector. */ - if (index >= type_vector_length) - { - type_vector_length *= 2; - type_vector = (struct typevector *) - xrealloc (type_vector, - (sizeof (struct typevector) - + type_vector_length * sizeof (struct type *))); - bzero (&type_vector->type[type_vector_length / 2], - type_vector_length * sizeof (struct type *) / 2); - } - return &type_vector->type[index]; - } - else - { - register int real_filenum = this_object_header_files[filenum]; - register struct header_file *f; - - if (real_filenum >= n_header_files) - abort (); - - f = &header_files[real_filenum]; - - if (index >= f->length) - { - f->length *= 2; - f->vector = (struct type **) - xrealloc (f->vector, f->length * sizeof (struct type *)); - bzero (&f->vector[f->length / 2], - f->length * sizeof (struct type *) / 2); - } - return &f->vector[index]; - } -} - -/* Create a type object. Occaisionally used when you need a type - which isn't going to be given a type number. */ - -static struct type * -dbx_create_type () -{ - register struct type *type = - (struct type *) obstack_alloc (symbol_obstack, sizeof (struct type)); - - bzero (type, sizeof (struct type)); - TYPE_VPTR_FIELDNO (type) = -1; - return type; -} - -/* Make sure there is a type allocated for type numbers TYPENUMS - and return the type object. - This can create an empty (zeroed) type object. - TYPENUMS may be (-1, -1) to return a new type object that is not - put into the type vector, and so may not be referred to by number. */ - -static struct type * -dbx_alloc_type (typenums) - int typenums[2]; -{ - register struct type **type_addr; - register struct type *type; - - if (typenums[1] != -1) - { - type_addr = dbx_lookup_type (typenums); - type = *type_addr; - } - else - { - type_addr = 0; - type = 0; - } - - /* If we are referring to a type not known at all yet, - allocate an empty type for it. - We will fill it in later if we find out how. */ - if (type == 0) - { - type = dbx_create_type (); - if (type_addr) - *type_addr = type; - } - - return type; -} - -#if 0 -static struct type ** -explicit_lookup_type (real_filenum, index) - int real_filenum, index; -{ - register struct header_file *f = &header_files[real_filenum]; - - if (index >= f->length) - { - f->length *= 2; - f->vector = (struct type **) - xrealloc (f->vector, f->length * sizeof (struct type *)); - bzero (&f->vector[f->length / 2], - f->length * sizeof (struct type *) / 2); - } - return &f->vector[index]; -} -#endif - -/* maintain the lists of symbols and blocks */ - -/* Add a symbol to one of the lists of symbols. */ -static void -add_symbol_to_list (symbol, listhead) - struct symbol *symbol; - struct pending **listhead; -{ - /* We keep PENDINGSIZE symbols in each link of the list. - If we don't have a link with room in it, add a new link. */ - if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE) - { - register struct pending *link; - if (free_pendings) - { - link = free_pendings; - free_pendings = link->next; - } - else - link = (struct pending *) xxmalloc (sizeof (struct pending)); - - link->next = *listhead; - *listhead = link; - link->nsyms = 0; - } - - (*listhead)->symbol[(*listhead)->nsyms++] = symbol; -} - -/* At end of reading syms, or in case of quit, - really free as many `struct pending's as we can easily find. */ - -static void -really_free_pendings () -{ - struct pending *next, *next1; - struct pending_block *bnext, *bnext1; - - for (next = free_pendings; next; next = next1) - { - next1 = next->next; - free (next); - } - free_pendings = 0; - - for (bnext = pending_blocks; bnext; bnext = bnext1) - { - bnext1 = bnext->next; - free (bnext); - } - pending_blocks = 0; - - for (next = file_symbols; next; next = next1) - { - next1 = next->next; - free (next); - } - for (next = global_symbols; next; next = next1) - { - next1 = next->next; - free (next); - } -} - -/* Take one of the lists of symbols and make a block from it. - Keep the order the symbols have in the list (reversed from the input file). - Put the block on the list of pending blocks. */ - -static void -finish_block (symbol, listhead, old_blocks, start, end) - struct symbol *symbol; - struct pending **listhead; - struct pending_block *old_blocks; - CORE_ADDR start, end; -{ - register struct pending *next, *next1; - register struct block *block; - register struct pending_block *pblock; - struct pending_block *opblock; - register int i; - - /* Count the length of the list of symbols. */ - - for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next); - - block = (struct block *) obstack_alloc (symbol_obstack, - (sizeof (struct block) - + ((i - 1) - * sizeof (struct symbol *)))); - - /* Copy the symbols into the block. */ - - BLOCK_NSYMS (block) = i; - for (next = *listhead; next; next = next->next) - { - register int j; - for (j = next->nsyms - 1; j >= 0; j--) - BLOCK_SYM (block, --i) = next->symbol[j]; - } - - BLOCK_START (block) = start; - BLOCK_END (block) = end; - BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */ - BLOCK_GCC_COMPILED (block) = processing_gcc_compilation; - - /* Put the block in as the value of the symbol that names it. */ - - if (symbol) - { - SYMBOL_BLOCK_VALUE (symbol) = block; - BLOCK_FUNCTION (block) = symbol; - } - else - BLOCK_FUNCTION (block) = 0; - - /* Now "free" the links of the list, and empty the list. */ - - for (next = *listhead; next; next = next1) - { - next1 = next->next; - next->next = free_pendings; - free_pendings = next; - } - *listhead = 0; - - /* Install this block as the superblock - of all blocks made since the start of this scope - that don't have superblocks yet. */ - - opblock = 0; - for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next) - { - if (BLOCK_SUPERBLOCK (pblock->block) == 0) - BLOCK_SUPERBLOCK (pblock->block) = block; - opblock = pblock; - } - - /* Record this block on the list of all blocks in the file. - Put it after opblock, or at the beginning if opblock is 0. - This puts the block in the list after all its subblocks. */ - - /* Allocate in the symbol_obstack to save time. - It wastes a little space. */ - pblock = (struct pending_block *) - obstack_alloc (symbol_obstack, - sizeof (struct pending_block)); - pblock->block = block; - if (opblock) - { - pblock->next = opblock->next; - opblock->next = pblock; - } - else - { - pblock->next = pending_blocks; - pending_blocks = pblock; - } -} - -static struct blockvector * -make_blockvector () -{ - register struct pending_block *next, *next1; - register struct blockvector *blockvector; - register int i; - - /* Count the length of the list of blocks. */ - - for (next = pending_blocks, i = 0; next; next = next->next, i++); - - blockvector = (struct blockvector *) - obstack_alloc (symbol_obstack, - (sizeof (struct blockvector) - + (i - 1) * sizeof (struct block *))); - - /* Copy the blocks into the blockvector. - This is done in reverse order, which happens to put - the blocks into the proper order (ascending starting address). - finish_block has hair to insert each block into the list - after its subblocks in order to make sure this is true. */ - - BLOCKVECTOR_NBLOCKS (blockvector) = i; - for (next = pending_blocks; next; next = next->next) - BLOCKVECTOR_BLOCK (blockvector, --i) = next->block; - -#if 0 /* Now we make the links in the obstack, so don't free them. */ - /* Now free the links of the list, and empty the list. */ - - for (next = pending_blocks; next; next = next1) - { - next1 = next->next; - free (next); - } -#endif - pending_blocks = 0; - - return blockvector; -} - -/* Manage the vector of line numbers. */ - -static void -record_line (line, pc) - int line; - CORE_ADDR pc; -{ - struct linetable_entry *e; - /* Ignore the dummy line number in libg.o */ - - if (line == 0xffff) - return; - - /* Make sure line vector is big enough. */ - - if (line_vector_index + 1 >= line_vector_length) - { - line_vector_length *= 2; - line_vector = (struct linetable *) - xrealloc (line_vector, - (sizeof (struct linetable) - + line_vector_length * sizeof (struct linetable_entry))); - current_subfile->line_vector = line_vector; - } - - e = line_vector->item + line_vector_index++; - e->line = line; e->pc = pc; -} - -/* Start a new symtab for a new source file. - This is called when a dbx symbol of type N_SO is seen; - it indicates the start of data for one original source file. */ - -static void -start_symtab (name, start_addr) - char *name; - CORE_ADDR start_addr; -{ - register struct symtab *s; - - last_source_file = name; - last_source_start_addr = start_addr; - file_symbols = 0; - global_symbols = 0; - within_function = 0; - - /* Context stack is initially empty, with room for 10 levels. */ - context_stack - = (struct context_stack *) xxmalloc (10 * sizeof (struct context_stack)); - context_stack_size = 10; - context_stack_depth = 0; - - new_object_header_files (); - - for (s = symseg_chain; s; s = s->next) - if (s->ldsymoff == symnum * sizeof (struct nlist)) - break; - current_symseg = s; - if (s != 0) - return; - - type_vector_length = 160; - type_vector = (struct typevector *) - xxmalloc (sizeof (struct typevector) - + type_vector_length * sizeof (struct type *)); - bzero (type_vector->type, type_vector_length * sizeof (struct type *)); - - /* Initialize the list of sub source files with one entry - for this file (the top-level source file). */ - - subfiles = 0; - current_subfile = 0; - start_subfile (name); - -#if 0 /* This is now set at the beginning of read_ofile_symtab */ - /* Set default for compiler to pcc; assume that we aren't processing - a gcc compiled file until proved otherwise. */ - - processing_gcc_compilation = 0; -#endif -} - -/* Handle an N_SOL symbol, which indicates the start of - code that came from an included (or otherwise merged-in) - source file with a different name. */ - -static void -start_subfile (name) - char *name; -{ - register struct subfile *subfile; - - /* Save the current subfile's line vector data. */ - - if (current_subfile) - { - current_subfile->line_vector_index = line_vector_index; - current_subfile->line_vector_length = line_vector_length; - current_subfile->prev_line_number = prev_line_number; - } - - /* See if this subfile is already known as a subfile of the - current main source file. */ - - for (subfile = subfiles; subfile; subfile = subfile->next) - { - if (!strcmp (subfile->name, name)) - { - line_vector = subfile->line_vector; - line_vector_index = subfile->line_vector_index; - line_vector_length = subfile->line_vector_length; - prev_line_number = subfile->prev_line_number; - current_subfile = subfile; - return; - } - } - - /* This subfile is not known. Add an entry for it. */ - - line_vector_index = 0; - line_vector_length = 1000; - prev_line_number = -2; /* Force first line number to be explicit */ - line_vector = (struct linetable *) - xxmalloc (sizeof (struct linetable) - + line_vector_length * sizeof (struct linetable_entry)); - - /* Make an entry for this subfile in the list of all subfiles - of the current main source file. */ - - subfile = (struct subfile *) xxmalloc (sizeof (struct subfile)); - subfile->next = subfiles; - subfile->name = savestring (name, strlen (name)); - subfile->line_vector = line_vector; - subfiles = subfile; - current_subfile = subfile; -} - -/* Finish the symbol definitions for one main source file, - close off all the lexical contexts for that file - (creating struct block's for them), then make the struct symtab - for that file and put it in the list of all such. - - END_ADDR is the address of the end of the file's text. */ - -static void -end_symtab (end_addr) - CORE_ADDR end_addr; -{ - register struct symtab *symtab; - register struct blockvector *blockvector; - register struct subfile *subfile; - register struct linetable *lv; - struct subfile *nextsub; - - if (current_symseg != 0) - { - last_source_file = 0; - current_symseg = 0; - return; - } - - /* Finish the lexical context of the last function in the file; - pop the context stack. */ - - if (context_stack_depth > 0) - { - register struct context_stack *cstk; - context_stack_depth--; - cstk = &context_stack[context_stack_depth]; - /* Make a block for the local symbols within. */ - finish_block (cstk->name, &local_symbols, cstk->old_blocks, - cstk->start_addr, end_addr); - } - - /* Cleanup any undefined types that have been left hanging around - (this needs to be done before the finish_blocks so that - file_symbols is still good). */ - cleanup_undefined_types (); - - /* Finish defining all the blocks of this symtab. */ - finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr); - finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr); - blockvector = make_blockvector (); - - current_subfile->line_vector_index = line_vector_index; - - /* Now create the symtab objects proper, one for each subfile. */ - /* (The main file is one of them.) */ - - for (subfile = subfiles; subfile; subfile = nextsub) - { - symtab = (struct symtab *) xxmalloc (sizeof (struct symtab)); - symtab->free_ptr = 0; - - /* Fill in its components. */ - symtab->blockvector = blockvector; - type_vector->length = type_vector_length; - symtab->typevector = type_vector; - symtab->free_code = free_linetable; - if (subfile->next == 0) - symtab->free_ptr = (char *) type_vector; - - symtab->filename = subfile->name; - lv = subfile->line_vector; - lv->nitems = subfile->line_vector_index; - symtab->linetable = (struct linetable *) - xrealloc (lv, (sizeof (struct linetable) - + lv->nitems * sizeof (struct linetable_entry))); - symtab->nlines = 0; - symtab->line_charpos = 0; - - /* Link the new symtab into the list of such. */ - symtab->next = symtab_list; - symtab_list = symtab; - - nextsub = subfile->next; - free (subfile); - } - - type_vector = 0; - type_vector_length = -1; - line_vector = 0; - line_vector_length = -1; - last_source_file = 0; -} - -#ifdef N_BINCL - -/* Handle the N_BINCL and N_EINCL symbol types - that act like N_SOL for switching source files - (different subfiles, as we call them) within one object file, - but using a stack rather than in an arbitrary order. */ - -struct subfile_stack -{ - struct subfile_stack *next; - char *name; - int prev_index; -}; - -struct subfile_stack *subfile_stack; - -static void -push_subfile () -{ - register struct subfile_stack *tem - = (struct subfile_stack *) xxmalloc (sizeof (struct subfile_stack)); - - tem->next = subfile_stack; - subfile_stack = tem; - if (current_subfile == 0 || current_subfile->name == 0) - abort (); - tem->name = current_subfile->name; - tem->prev_index = header_file_prev_index; -} - -static char * -pop_subfile () -{ - register char *name; - register struct subfile_stack *link = subfile_stack; - - if (link == 0) - abort (); - - name = link->name; - subfile_stack = link->next; - header_file_prev_index = link->prev_index; - free (link); - - return name; -} -#endif /* Have N_BINCL */ - -/* Accumulate the misc functions in bunches of 127. - At the end, copy them all into one newly allocated structure. */ - -#define MISC_BUNCH_SIZE 127 - -struct misc_bunch -{ - struct misc_bunch *next; - struct misc_function contents[MISC_BUNCH_SIZE]; -}; - -/* Bunch currently being filled up. - The next field points to chain of filled bunches. */ - -static struct misc_bunch *misc_bunch; - -/* Number of slots filled in current bunch. */ - -static int misc_bunch_index; - -/* Total number of misc functions recorded so far. */ - -static int misc_count; - -static void -init_misc_functions () -{ - misc_count = 0; - misc_bunch = 0; - misc_bunch_index = MISC_BUNCH_SIZE; -} - -static void -record_misc_function (name, address, type) - char *name; - CORE_ADDR address; - int type; -{ - register struct misc_bunch *new; - register unsigned char mtype; - - if (misc_bunch_index == MISC_BUNCH_SIZE) - { - new = (struct misc_bunch *) xxmalloc (sizeof (struct misc_bunch)); - misc_bunch_index = 0; - new->next = misc_bunch; - misc_bunch = new; - } - misc_bunch->contents[misc_bunch_index].name = name; - misc_bunch->contents[misc_bunch_index].address = address; - switch (type &~ N_EXT) - { - case N_TEXT: mtype = mf_text; break; - case N_DATA: mtype = mf_data; break; - case N_BSS: mtype = mf_bss; break; - case N_ABS: mtype = mf_abs; break; -#ifdef N_SETV - case N_SETV: mtype = mf_data; break; -#endif - default: mtype = mf_unknown; break; - } - misc_bunch->contents[misc_bunch_index].type = mtype; - misc_bunch_index++; - misc_count++; -} - -static int -compare_misc_functions (fn1, fn2) - struct misc_function *fn1, *fn2; -{ - /* Return a signed result based on unsigned comparisons - so that we sort into unsigned numeric order. */ - if (fn1->address < fn2->address) - return -1; - if (fn1->address > fn2->address) - return 1; - return 0; -} - -static void -discard_misc_bunches () -{ - register struct misc_bunch *next; - - while (misc_bunch) - { - next = misc_bunch->next; - free (misc_bunch); - misc_bunch = next; - } -} - -/* INCLINK nonzero means bunches are from an incrementally-linked file. - Add them to the existing bunches. - Otherwise INCLINK is zero, and we start from scratch. */ -static void -condense_misc_bunches (inclink) - int inclink; -{ - register int i, j; - register struct misc_bunch *bunch; -#ifdef NAMES_HAVE_UNDERSCORE - int offset = 1; -#else - int offset = 0; -#endif - - if (inclink) - { - misc_function_vector - = (struct misc_function *) - xrealloc (misc_function_vector, (misc_count + misc_function_count) - * sizeof (struct misc_function)); - j = misc_function_count; - } - else - { - misc_function_vector - = (struct misc_function *) - xxmalloc (misc_count * sizeof (struct misc_function)); - j = 0; - } - - bunch = misc_bunch; - while (bunch) - { - for (i = 0; i < misc_bunch_index; i++) - { - misc_function_vector[j] = bunch->contents[i]; - misc_function_vector[j].name - = obconcat (misc_function_vector[j].name - + (misc_function_vector[j].name[0] == '_' ? offset : 0), - "", ""); - j++; - } - bunch = bunch->next; - misc_bunch_index = MISC_BUNCH_SIZE; - } - - if (inclink) - misc_function_count += misc_count; - else - misc_function_count = j; - - /* Sort the misc functions by address. */ - - qsort (misc_function_vector, misc_function_count, - sizeof (struct misc_function), - compare_misc_functions); - - /* (re)build the hash table (positions changed during the sort) */ - - for (i = 0; i < MISC_FUNC_HASH_SIZE; ++i) - misc_function_hash_tab[i] = -1; - for (i = 0; i < misc_function_count; ++i) - { - j = hash_symbol(misc_function_vector[i].name) & (MISC_FUNC_HASH_SIZE - 1); - misc_function_vector[i].next = misc_function_hash_tab[j]; - misc_function_hash_tab[j] = i; - } -} - -/* Call sort_syms to sort alphabetically - the symbols of each block of each symtab. */ - -static int -compare_symbols (s1, s2) - struct symbol **s1, **s2; -{ - register int namediff; - - /* Compare the initial characters. */ - namediff = SYMBOL_NAME (*s1)[0] - SYMBOL_NAME (*s2)[0]; - if (namediff != 0) return namediff; - - /* If they match, compare the rest of the names. */ - namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2)); - if (namediff != 0) return namediff; - - /* For symbols of the same name, registers should come first. */ - return ((SYMBOL_CLASS (*s2) == LOC_REGISTER) - - (SYMBOL_CLASS (*s1) == LOC_REGISTER)); -} - -static void sort_symtab_syms (); - -static void -sort_syms () -{ - register struct symtab *s; - - for (s = symtab_list; s; s = s->next) - sort_symtab_syms (s); -} - -static void -sort_symtab_syms (s) - register struct symtab *s; -{ - register struct blockvector *bv = BLOCKVECTOR (s); - int nbl = BLOCKVECTOR_NBLOCKS (bv); - int i; - register struct block *b; - - /* Note that in the following sort, we always make sure that - register debug symbol declarations always come before regular - debug symbol declarations (as might happen when parameters are - then put into registers by the compiler). We do this by a - correct compare in compare_symbols, and by the reversal of the - symbols if we don't sort. This works as long as a register debug - symbol always comes after a parameter debug symbol. */ - - /* This is no longer necessary; lookup_block_symbol now always - prefers some other declaration over a parameter declaration. We - still sort the thing (that is necessary), but we don't reverse it - if we shouldn't sort it. */ - - for (i = 0; i < nbl; i++) - { - b = BLOCKVECTOR_BLOCK (bv, i); - if (BLOCK_SHOULD_SORT (b)) - qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b), - sizeof (struct symbol *), compare_symbols); - } -} - - -extern struct symtab *psymtab_to_symtab (); - -/* The entry point. */ -static CORE_ADDR entry_point; - -static char *symfile_string_table; -static int symfile_string_table_size; - -/* This is the symbol-file command. Read the file, analyze its symbols, - and add a struct symtab to symtab_list. */ - -void -symbol_file_command (name, from_tty) - char *name; - int from_tty; -{ - register int desc; - DECLARE_FILE_HEADERS; - struct nlist *nlist; - - /* The string table. */ - char *stringtab; - - /* The size of the string table (buffer is a bizarre name...). */ - long buffer; - - register int val; - extern void close (); - struct cleanup *old_chain; - struct symtab *symseg; - struct stat statbuf; - - dont_repeat (); - - if (name == 0) - { - if ((symtab_list || partial_symtab_list) - && from_tty - && !query ("Discard symbol table? ", 0)) - error ("Not confirmed."); - if (symfile) - free (symfile); - symfile = 0; - free_all_symtabs (); - free_all_psymtabs (); - return; - } - - name = tilde_expand (name); - make_cleanup (free, name); - - if ((symtab_list || partial_symtab_list) - && !query ("Load new symbol table from \"%s\"? ", name)) - error ("Not confirmed."); - - { - char *absolute_name; - desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name); - if (desc < 0) - perror_with_name (name); - else - name = absolute_name; - } - - old_chain = make_cleanup (close, desc); - make_cleanup (free_current_contents, &name); - - READ_FILE_HEADERS (desc, name); - - entry_point = ENTRY_POINT; - - if (NUMBER_OF_SYMBOLS == 0) - { - if (symfile) - free (symfile); - symfile = 0; - free_all_symtabs (); - free_all_psymtabs (); - printf ("%s has no symbol-table; symbols discarded.\n", name); - fflush (stdout); - do_cleanups (old_chain); - return; - } - - printf ("Reading symbol data from %s...", name); - fflush (stdout); - - /* Now read the string table, all at once. */ - val = lseek (desc, STRING_TABLE_OFFSET, 0); - if (val < 0) - perror_with_name (name); - if (stat (name, &statbuf) == -1) - perror_with_name (name); - READ_STRING_TABLE_SIZE (buffer); - if (buffer >= 0 && buffer < statbuf.st_size) - { - /* This should speed things up without consuming much - extra memory (because probably little of the space is going - to be reused anyway, whether in data or stack space). - - A quick test (running GDB on itself and setting 9 breakpoints - in different files) showed that memory usage was almost - identical for the two cases. */ -#if 0 -#ifdef BROKEN_LARGE_ALLOCA - stringtab = (char *) xmalloc (buffer); - make_cleanup (free, stringtab); -#else - stringtab = (char *) alloca (buffer); -#endif -#endif - stringtab = (char *) xmalloc (buffer); - symfile_string_table = stringtab; - symfile_string_table_size = buffer; - } - else - stringtab = NULL; - if (stringtab == NULL) - error ("ridiculous string table size: %d bytes", buffer); - - /* Usually READ_STRING_TABLE_SIZE will have shifted the file pointer. - Occaisionally, it won't. */ - val = lseek (desc, STRING_TABLE_OFFSET, L_SET); - if (val < 0) - perror_with_name (name); - val = myread (desc, stringtab, buffer); - if (val < 0) - perror_with_name (name); - - /* Throw away the old symbol table. */ - - if (symfile) - free (symfile); - symfile = 0; - free_all_symtabs (); - free_all_psymtabs (); - - /* Empty the hash table of global syms looking for values. */ - bzero (global_sym_chain, sizeof global_sym_chain); - - /* Symsegs are no longer supported by GDB. Setting symseg_chain to - 0 is easier than finding all the symseg code and eliminating it. */ - symseg_chain = 0; - - /* Position to read the symbol table. Do not read it all at once. */ - val = lseek (desc, SYMBOL_TABLE_OFFSET, 0); - if (val < 0) - perror_with_name (name); - - /* Don't put these on the cleanup chain; they need to stick around - until the next call to symbol_file_command. *Then* we'll free - them. */ - free_header_files (); - init_header_files (); - - init_misc_functions (); - make_cleanup (discard_misc_bunches, 0); - - free_pendings = 0; - pending_blocks = 0; - file_symbols = 0; - global_symbols = 0; - make_cleanup (really_free_pendings, 0); - - /* Now that the symbol table data of the executable file are all in core, - process them and define symbols accordingly. Closes desc. */ - - read_dbx_symtab (desc, stringtab, buffer, NUMBER_OF_SYMBOLS, 0, - ADDR_OF_TEXT_SEGMENT, SIZE_OF_TEXT_SEGMENT); - - /* Go over the misc functions and install them in vector. */ - - condense_misc_bunches (0); - - /* Don't allow char * to have a typename (else would get caddr_t.) */ - - TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0; - - /* Make a default for file to list. */ - - symfile = savestring (name, strlen (name)); - - /* Call to select_source_symtab used to be here; it was using too - much time. I'll make sure that list_sources can handle the lack - of current_source_symtab */ - - do_cleanups (old_chain); /* Descriptor closed here */ - - /* Free the symtabs made by read_symsegs, but not their contents, - which have been copied into symtabs on symtab_list. */ - while (symseg_chain) - { - register struct symtab *s = symseg_chain->next; - free (symseg_chain); - symseg_chain = s; - } - - if (!partial_symtab_list) - printf ("\n(no debugging symbols found)..."); - - printf ("done.\n"); - fflush (stdout); -} - -/* Return name of file symbols were loaded from, or 0 if none.. */ - -char * -get_sym_file () -{ - return symfile; -} - -/* Buffer for reading the symbol table entries. */ -static struct nlist symbuf[4096]; -static int symbuf_idx; -static int symbuf_end; - -/* I/O descriptor for reading the symbol table. */ -static int symtab_input_desc; - -/* The address of the string table - of the object file we are reading (as copied into core). */ -static char *stringtab_global; - -/* Refill the symbol table input buffer - and set the variables that control fetching entries from it. - Reports an error if no data available. - This function can read past the end of the symbol table - (into the string table) but this does no harm. */ - -static int -fill_symbuf () -{ - int nbytes = myread (symtab_input_desc, symbuf, sizeof (symbuf)); - if (nbytes <= 0) - error ("error or end of file reading symbol table"); - symbuf_end = nbytes / sizeof (struct nlist); - symbuf_idx = 0; - return 1; -} - -/* dbx allows the text of a symbol name to be continued into the - next symbol name! When such a continuation is encountered - (a \ at the end of the text of a name) - call this function to get the continuation. */ - -static char * -next_symbol_text () -{ - if (symbuf_idx == symbuf_end) - fill_symbuf (); - symnum++; - return symbuf[symbuf_idx++].n_un.n_strx + stringtab_global; -} - -/* - * Initializes storage for all of the partial symbols that will be - * created by read_dbx_symtab and subsidiaries. - */ -void -init_psymbol_list (total_symbols) - int total_symbols; -{ - /* Current best guess is that there are approximately a twentieth - of the total symbols (in a debugging file) are global or static - oriented symbols */ - global_psymbols.size = total_symbols / 10; - static_psymbols.size = total_symbols / 10; - global_psymbols.next = global_psymbols.list = (struct partial_symbol *) - xmalloc (global_psymbols.size * sizeof (struct partial_symbol)); - static_psymbols.next = static_psymbols.list = (struct partial_symbol *) - xmalloc (static_psymbols.size * sizeof (struct partial_symbol)); -} - -/* - * Initialize the list of bincls to contain none and have some - * allocated. - */ -static void -init_bincl_list (number) - int number; -{ - bincls_allocated = number; - next_bincl = bincl_list = (struct header_file_location *) - xmalloc (bincls_allocated * sizeof(struct header_file_location)); -} - -/* - * Add a bincl to the list. - */ -static void -add_bincl_to_list (pst, name, instance) - struct partial_symtab *pst; - char *name; - int instance; -{ - if (next_bincl >= bincl_list + bincls_allocated) - { - int offset = next_bincl - bincl_list; - bincls_allocated *= 2; - bincl_list = (struct header_file_location *) - xrealloc (bincl_list, - bincls_allocated * sizeof (struct header_file_location)); - next_bincl = bincl_list + offset; - } - next_bincl->pst = pst; - next_bincl->instance = instance; - next_bincl++->name = name; -} - -/* - * Given a name, value pair, find the corresponding - * bincl in the list. Return the partial symtab associated - * with that header_file_location. - */ -struct partial_symtab * -find_corresponding_bincl_psymtab (name, instance) - char *name; - int instance; -{ - struct header_file_location *bincl; - - for (bincl = bincl_list; bincl < next_bincl; bincl++) - if (bincl->instance == instance - && !strcmp (name, bincl->name)) - return bincl->pst; - - return (struct partial_symtab *) 0; -} - -/* - * Free the storage allocated for the bincl list. - */ -static void -free_bincl_list () -{ - free (bincl_list); - bincls_allocated = 0; -} - -static struct partial_symtab *start_psymtab (); -static void add_psymtab_dependency (); -static void end_psymtab(); - -static int -compare_psymbols (s1, s2) - register struct partial_symbol *s1, *s2; -{ - register char - *st1 = SYMBOL_NAME (s1), - *st2 = SYMBOL_NAME (s2); - register int i; - - if (st1[0] - st2[0]) - return (st1[0] - st2[0]); - if (st1[1] - st2[1]) - return (st1[1] - st2[1]); - if (i = strcmp(st1, st2)) - return (i); - /* Next comparison implements policy that used to be in lookup_symbol: - * it would search psymtabs in psymtab_list order (reverse order of - * declaration) & take first occurance of symbol it found. So, we - * collate duplicate names in reverse psymtab order. */ - return (s2->pst - s1->pst); -} - -/* Given pointers to an a.out symbol table in core containing dbx - style data, setup partial_symtab's describing each source file for - which debugging information is available. NLISTLEN is the number - of symbols in the symbol table. All symbol names are given as - offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of - STRINGTAB. - - I have no idea whether or not this routine should be setup to deal - with inclinks. It seems reasonable to me that they be dealt with - standardly, so I am not going to make a strong effort to deal with - them here. - */ - -static void -read_dbx_symtab (desc, stringtab, stringtab_size, nlistlen, inclink, - text_addr, text_size) - int desc; - register char *stringtab; - register long stringtab_size; - register int nlistlen; - int inclink; - unsigned text_addr; - int text_size; -{ - register struct nlist *bufp; - register char *namestring; - register struct partial_symbol *psym; - register struct psymbol_allocation_list *psymbol_struct; - - int nsl; - int past_first_source_file = 0; - CORE_ADDR last_o_file_start = 0; - char *last_o_file_name = "*bogus*"; - struct cleanup *old_chain; - char *p; - enum namespace ns; - enum address_class class; - -#ifdef PROFILE_TYPES - int i; - int profile_types [256]; - int strcmp_called = 0; - int autovars = 0; - int global_funs = 0; -#endif - - /* Current partial symtab */ - struct partial_symtab *pst; - - /* List of current psymtab's include files */ - char **psymtab_include_list; - int includes_allocated; - int includes_used; - - /* Index within current psymtab dependency list */ - struct partial_symtab **dependency_list; - int dependencies_used, dependencies_allocated; - -#ifdef PROFILE_TYPES - for (i = 0; i < 256; i++) - profile_types[i] = 0; -#endif - - stringtab_global = stringtab; - - pst = (struct partial_symtab *) 0; - - includes_allocated = 30; - includes_used = 0; - psymtab_include_list = (char **) alloca (includes_allocated * - sizeof (char *)); - - dependencies_allocated = 30; - dependencies_used = 0; - dependency_list = - (struct partial_symtab **) alloca (dependencies_allocated * - sizeof (struct partial_symtab *)); - - old_chain = make_cleanup (free_all_psymtabs, 0); - - /* Init bincl list */ - init_bincl_list (20); - make_cleanup (free_bincl_list, 0); - - /* Setup global partial symbol list */ - init_psymbol_list (nlistlen); - - last_source_file = 0; - -#ifdef END_OF_TEXT_DEFAULT - end_of_text_addr = END_OF_TEXT_DEFAULT; -#else - end_of_text_addr = text_addr + text_size; -#endif - - symtab_input_desc = desc; /* This is needed for fill_symbuf below */ - symbuf_end = symbuf_idx = 0; - - for (symnum = 0; symnum < nlistlen; symnum++) - { - /* Get the symbol for this run and pull out some info */ - QUIT; /* allow this to be interruptable */ - if (symbuf_idx == symbuf_end) - fill_symbuf (); - bufp = &symbuf[symbuf_idx++]; - -#ifdef PROFILE_TYPES - profile_types[bufp->n_type]++; -#endif - - /* - * Special case to speed up readin. - */ - if (bufp->n_type == N_SLINE) continue; - - /* Ok. There is a lot of code duplicated in the rest of this - switch statiement (for efficiency reasons). Since I don't - like duplicating code, I will do my penance here, and - describe the code which is duplicated: - - *) The assignment to namestring. - *) The call to index. - *) The addition of a partial symbol the the two partial - symbol lists. This last is a large section of code, so - I've imbedded it in the following macro. - */ - -/* Set namestring based on bufp. */ -#define SET_NAMESTRING()\ - if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size) \ - error ("Invalid symbol data: bad string table offset: %d", \ - bufp->n_un.n_strx); \ - namestring = bufp->n_un.n_strx + stringtab - -#define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE)\ - do { \ - if ((LIST).next >= \ - (LIST).list + (LIST).size) \ - { \ - (LIST).list = (struct partial_symbol *) \ - xrealloc ((LIST).list, \ - ((LIST).size * 2 \ - * sizeof (struct partial_symbol))); \ - /* Next assumes we only went one over. Should be good if \ - program works correctly */ \ - (LIST).next = \ - (LIST).list + (LIST).size; \ - (LIST).size *= 2; \ - } \ - psym = (LIST).next++; \ - \ - SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \ - (NAMELENGTH) + 1); \ - strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \ - SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \ - SYMBOL_NAMESPACE (psym) = (NAMESPACE); \ - SYMBOL_CLASS (psym) = (CLASS); \ - SYMBOL_VALUE (psym) = (VALUE); \ - } while (0); - - - switch (bufp->n_type) - { - /* - * Standard, non-debugger, symbols - */ - - case N_TEXT | N_EXT: - /* Catch etext */ - - SET_NAMESTRING(); - - if (namestring[6] == '\0' && namestring[5] == 't' - && namestring[4] == 'x' && namestring[3] == 'e' - && namestring[2] == 't' && namestring[1] == 'e' - && namestring[0] == '_') - end_of_text_addr = bufp->n_value; - - /* Figure out beginning and end of global linker symbol - section and put non-debugger specified symbols on - tmp_symchain */ - - last_global_sym = symnum; - if (!first_global_sym) first_global_sym = symnum; - - record_misc_function (namestring, bufp->n_value, - bufp->n_type); /* Always */ - - continue; - -#ifdef N_NBTEXT - case N_NBTEXT | N_EXT: -#endif -#ifdef N_NBDATA - case N_NBDATA | N_EXT: -#endif -#ifdef N_NBBSS - case N_NBBSS | N_EXT: -#endif -#ifdef N_SETV - case N_SETV | N_EXT: -#endif - case N_ABS | N_EXT: - case N_DATA | N_EXT: - case N_BSS | N_EXT: - /* Figure out beginning and end of global linker symbol - section and put non-debugger specified symbols on - tmp_symchain */ - - SET_NAMESTRING(); - - last_global_sym = symnum; - if (!first_global_sym) first_global_sym = symnum; - - /* Not really a function here, but... */ - record_misc_function (namestring, bufp->n_value, - bufp->n_type); /* Always */ - - continue; - -#ifdef N_NBTEXT - case N_NBTEXT: -#endif - - /* We need to be able to deal with both N_FN or N_TEXT, - because we have no way of knowing whether the sys-supplied ld - or GNU ld was used to make the executable. */ -#if ! (N_FN & N_EXT) - case N_FN: -#endif - case N_FN | N_EXT: - case N_TEXT: - SET_NAMESTRING(); - if ((namestring[0] == '-' && namestring[1] == 'l') - || (namestring [(nsl = strlen (namestring)) - 1] == 'o' - && namestring [nsl - 2] == '.')) - { - if (entry_point < bufp->n_value - && entry_point >= last_o_file_start) - { - startup_file_start = last_o_file_start; - startup_file_end = bufp->n_value; - } - if (past_first_source_file && pst) - { - end_psymtab (pst, psymtab_include_list, includes_used, - symnum * sizeof (struct nlist), bufp->n_value, - dependency_list, dependencies_used, - global_psymbols.next, static_psymbols.next); - pst = (struct partial_symtab *) 0; - includes_used = 0; - dependencies_used = 0; - } - else - past_first_source_file = 1; - last_o_file_start = bufp->n_value; - last_o_file_name = namestring; - nsl = strlen(namestring); - if (namestring[nsl-2] == '.' && namestring[nsl-1] == 'o') - namestring[nsl-2] = 0; - } - else if (strcmp(namestring, "gcc_compiled.")) - { - if (*namestring == '_') - ++namestring; - namestring = obconcat(last_o_file_name, ":", namestring); - last_global_sym = symnum; - if (!first_global_sym) - first_global_sym = symnum; - record_misc_function(namestring, bufp->n_value, bufp->n_type); - } - continue; - - case N_ABS: - case N_DATA: - case N_BSS: - SET_NAMESTRING(); - if (*namestring == '_') - ++namestring; - namestring = obconcat(last_o_file_name, ":", namestring); - last_global_sym = symnum; - if (!first_global_sym) - first_global_sym = symnum; - record_misc_function(namestring, bufp->n_value, bufp->n_type); - continue; - - case N_UNDF: - case N_UNDF | N_EXT: -#ifdef N_NBDATA - case N_NBDATA: -#endif -#ifdef N_NBBSS - case N_NBBSS: -#endif - - /* Keep going . . .*/ - - /* - * Special symbol types for GNU - */ -#ifdef N_INDR - case N_INDR: - case N_INDR | N_EXT: -#endif -#ifdef N_SETA - case N_SETA: - case N_SETA | N_EXT: - case N_SETT: - case N_SETT | N_EXT: - case N_SETD: - case N_SETD | N_EXT: - case N_SETB: - case N_SETB | N_EXT: - case N_SETV: -#endif - continue; - - /* - * Debugger symbols - */ - - case N_SO: - /* End the current partial symtab and start a new one */ - - SET_NAMESTRING(); - - if (pst && past_first_source_file) - { - end_psymtab (pst, psymtab_include_list, includes_used, - symnum * sizeof (struct nlist), bufp->n_value, - dependency_list, dependencies_used, - global_psymbols.next, static_psymbols.next); - pst = (struct partial_symtab *) 0; - includes_used = 0; - dependencies_used = 0; - } - else - past_first_source_file = 1; - - pst = start_psymtab (namestring, bufp->n_value, - symnum * sizeof (struct nlist), - global_psymbols.next, static_psymbols.next); - - continue; - -#ifdef N_BINCL - case N_BINCL: - /* Add this bincl to the bincl_list for future EXCLs. No - need to save the string; it'll be around until - read_dbx_symtab function return */ - - SET_NAMESTRING(); - - add_bincl_to_list (pst, namestring, bufp->n_value); - - /* Mark down an include file in the current psymtab */ - - psymtab_include_list[includes_used++] = namestring; - if (includes_used >= includes_allocated) - { - char **orig = psymtab_include_list; - - psymtab_include_list = (char **) - alloca ((includes_allocated *= 2) * - sizeof (char *)); - bcopy (orig, psymtab_include_list, - includes_used * sizeof (char *)); - } - - continue; -#endif - - case N_SOL: - /* Mark down an include file in the current psymtab */ - - SET_NAMESTRING(); - - /* In C++, one may expect the same filename to come round many - times, when code is coming alternately from the main file - and from inline functions in other files. So I check to see - if this is a file we've seen before. - - This seems to be a lot of time to be spending on N_SOL, but - things like "break expread.y:435" need to work (I - suppose the psymtab_include_list could be hashed or put - in a binary tree, if profiling shows this is a major hog). */ - { - register int i; - for (i = 0; i < includes_used; i++) - if (!strcmp (namestring, psymtab_include_list[i])) - { - i = -1; - break; - } - if (i == -1) - continue; - } - - psymtab_include_list[includes_used++] = namestring; - if (includes_used >= includes_allocated) - { - char **orig = psymtab_include_list; - - psymtab_include_list = (char **) - alloca ((includes_allocated *= 2) * - sizeof (char *)); - bcopy (orig, psymtab_include_list, - includes_used * sizeof (char *)); - } - continue; - - case N_LSYM: /* Typedef or automatic variable. */ - SET_NAMESTRING(); - - p = (char *) index (namestring, ':'); - - /* Skip if there is no :. */ - if (!p) continue; - - switch (p[1]) - { - case 'T': - ADD_PSYMBOL_TO_LIST (namestring, p - namestring, - STRUCT_NAMESPACE, LOC_TYPEDEF, - static_psymbols, bufp->n_value); - goto check_enum; - case 't': - ADD_PSYMBOL_TO_LIST (namestring, p - namestring, - VAR_NAMESPACE, LOC_TYPEDEF, - static_psymbols, bufp->n_value); - check_enum: - /* If this is an enumerated type, we need to - add all the enum constants to the partial symbol - table. This does not cover enums without names, e.g. - "enum {a, b} c;" in C, but fortunately those are - rare. There is no way for GDB to find those from the - enum type without spending too much time on it. Thus - to solve this problem, the compiler needs to put out separate - constant symbols ('c' N_LSYMS) for enum constants in - enums without names. */ - - /* We are looking for something of the form - ":" ("t" | "T") [ "="] "e" - { ":" ","} ";". */ - - /* Skip over the colon and the 't' or 'T'. */ - p += 2; - /* This type may be given a number. Skip over it. */ - while ((*p >= '0' && *p <= '9') - || *p == '=') - p++; - - if (*p++ == 'e') - { - /* We have found an enumerated type. */ - /* According to comments in read_enum_type - a comma could end it instead of a semicolon. - I don't know where that happens. - Accept either. */ - while (*p && *p != ';' && *p != ',') - { - char *q; - - /* Check for and handle cretinous dbx symbol name - continuation! */ - if (*p == '\\') - p = next_symbol_text (); - - /* Point to the character after the name - of the enum constant. */ - for (q = p; *q && *q != ':'; q++) - ; - /* Note that the value doesn't matter for - enum constants in psymtabs, just in symtabs. */ - ADD_PSYMBOL_TO_LIST (p, q - p, - VAR_NAMESPACE, LOC_CONST, - static_psymbols, 0); - /* Point past the name. */ - p = q; - /* Skip over the value. */ - while (*p && *p != ',') - p++; - /* Advance past the comma. */ - if (*p) - p++; - } - } - - continue; - case 'c': - /* Constant, e.g. from "const" in Pascal. */ - ADD_PSYMBOL_TO_LIST (namestring, p - namestring, - VAR_NAMESPACE, LOC_CONST, - static_psymbols, bufp->n_value); - continue; - default: -#ifdef PROFILE_TYPES - if (isalpha(p[1])) - printf ("Funny...LSYM with a letter that isn't a type\n"); - autovars++; -#endif - /* Skip if the thing following the : is - not a letter (which indicates declaration of a local - variable, which we aren't interested in). */ - continue; - } - - case N_FUN: -#if 0 - /* This special-casing of N_FUN is just wrong; N_FUN - does not mean "function"; it means "text segment". - So N_FUN can go with 'V', etc. as well as 'f' or 'F'. */ - - SET_NAMESTRING(); - - p = (char *) index (namestring, ':'); - - if (!p || p[1] == 'F') continue; - -#ifdef PROFILE_TYPES - if (p[1] != 'f') - printf ("Funny...FUN with a letter that isn't 'F' or 'f'.\n"); - global_funs++; -#endif - - ADD_PSYMBOL_TO_LIST (namestring, p - namestring, - VAR_NAMESPACE, LOC_BLOCK, - static_psymbols, bufp->n_value); - - continue; -#endif /* 0 */ - case N_GSYM: /* Global (extern) variable; can be - data or bss (sigh). */ - case N_STSYM: /* Data seg var -- static */ - case N_LCSYM: /* BSS " */ - - /* Following may probably be ignored; I'll leave them here - for now (until I do Pascal and Modula 2 extensions). */ - - case N_PC: /* I may or may not need this; I - suspect not. */ -#ifdef N_M2C - case N_M2C: /* I suspect that I can ignore this here. */ - case N_SCOPE: /* Same. */ -#endif - - SET_NAMESTRING(); - - p = (char *) index (namestring, ':'); - if (!p) - continue; /* Not a debugging symbol. */ - - process_symbol_for_psymtab: - - /* Main processing section for debugging symbols which - the initial read through the symbol tables needs to worry - about. If we reach this point, the symbol which we are - considering is definitely one we are interested in. - p must also contain the (valid) index into the namestring - which indicates the debugging type symbol. */ - - switch (p[1]) - { - case 'c': - ADD_PSYMBOL_TO_LIST (namestring, p - namestring, - VAR_NAMESPACE, LOC_CONST, - static_psymbols, bufp->n_value); - continue; - case 'S': - ADD_PSYMBOL_TO_LIST (namestring, p - namestring, - VAR_NAMESPACE, LOC_STATIC, - static_psymbols, bufp->n_value); - continue; - case 'G': - ADD_PSYMBOL_TO_LIST (namestring, p - namestring, - VAR_NAMESPACE, LOC_EXTERNAL, - global_psymbols, bufp->n_value); - continue; - - case 't': - ADD_PSYMBOL_TO_LIST (namestring, p - namestring, - VAR_NAMESPACE, LOC_TYPEDEF, - global_psymbols, bufp->n_value); - continue; - - case 'f': - ADD_PSYMBOL_TO_LIST (namestring, p - namestring, - VAR_NAMESPACE, LOC_BLOCK, - static_psymbols, bufp->n_value); - continue; - - /* Two things show up here (hopefully); static symbols of - local scope (static used inside braces) or extensions - of structure symbols. We can ignore both. */ - case 'V': - case '(': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - /* Global functions are ignored here. I'm not - sure what psymtab they go into (or just the misc - function vector). */ - case 'F': - continue; - - default: - fatal ("Internal error: Unexpected debugging symbol type '%c' at symnum %d.\n", - p[1], symnum); - } - -#ifdef N_BINCL - case N_EXCL: - - SET_NAMESTRING(); - - /* Find the corresponding bincl and mark that psymtab on the - psymtab dependency list */ - { - struct partial_symtab *needed_pst = - find_corresponding_bincl_psymtab (namestring, bufp->n_value); - - /* If this include file was defined earlier in this file, - leave it alone. */ - if (needed_pst == pst) continue; - - if (needed_pst) - { - int i; - int found = 0; - - for (i = 0; i < dependencies_used; i++) - if (dependency_list[i] == needed_pst) - { - found = 1; - break; - } - - /* If it's already in the list, skip the rest. */ - if (found) continue; - - dependency_list[dependencies_used++] = needed_pst; - if (dependencies_used >= dependencies_allocated) - { - struct partial_symtab **orig = dependency_list; - dependency_list = - (struct partial_symtab **) - alloca ((dependencies_allocated *= 2) - * sizeof (struct partial_symtab *)); - bcopy (orig, dependency_list, - (dependencies_used - * sizeof (struct partial_symtab *))); -#ifdef DEBUG_INFO - fprintf (stderr, "Had to reallocate dependency list.\n"); - fprintf (stderr, "New dependencies allocated: %d\n", - dependencies_allocated); -#endif - } - } - else - error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.", - symnum); - } - continue; - - case N_EINCL: -#endif -#ifdef N_DSLINE - case N_DSLINE: -#endif -#ifdef N_BSLINE - case N_BSLINE: -#endif - case N_SSYM: /* Claim: Structure or union element. - Hopefully, I can ignore this. */ - case N_ENTRY: /* Alternate entry point; can ignore. */ -#ifdef N_MAIN - case N_MAIN: /* Can definitely ignore this. */ -#endif - case N_LENG: - case N_BCOMM: - case N_ECOMM: - case N_ECOML: - case N_FNAME: - case N_SLINE: - case N_RSYM: - case N_PSYM: - case N_LBRAC: - case N_RBRAC: - /* These symbols aren't interesting; don't worry about them */ - - continue; - - default: - /* If we haven't found it yet, we've got problems */ - - if (IGNORE_SYMBOL (bufp->n_type)) - continue; - - fatal ("Bad symbol type 0x%x encountered in gdb scan", bufp->n_type); - } - } - - /* If there's stuff to be cleaned up, clean it up. */ - if (entry_point < bufp->n_value - && entry_point >= last_o_file_start) - { - startup_file_start = last_o_file_start; - startup_file_end = bufp->n_value; - } - - if (pst) - { - end_psymtab (pst, psymtab_include_list, includes_used, - symnum * sizeof (struct nlist), end_of_text_addr, - dependency_list, dependencies_used, - global_psymbols.next, static_psymbols.next); - includes_used = 0; - dependencies_used = 0; - pst = (struct partial_symtab *) 0; - } - - /* sort the global & static symtab list so we can binary search them */ - qsort (global_psymbols.list, global_psymbols.next - global_psymbols.list, - sizeof (struct partial_symbol), compare_psymbols); - qsort (static_psymbols.list, static_psymbols.next - static_psymbols.list, - sizeof (struct partial_symbol), compare_psymbols); - free_bincl_list (); - discard_cleanups (old_chain); -#ifdef PROFILE_TYPES - { - int i, j; -#define __define_stab(SYM, NUMBER, NAME) {NUMBER, NAME}, - static struct xyzzy { - unsigned char symnum; - char *name; - } tmp_list[] = { -#include "stab.def" - {0x1, "eREF"}, - {0x2, "ABS"}, - {0x3, "eABS"}, - {0x4, "TEXT"}, - {0x5, "eTEXT"}, - {0x6, "DATA"}, - {0x7, "eDATA"}, - {0x8, "BSS"}, - {0x9, "eBSS"}, - {0x12, "COMM"}, - {0x13, "eCOMM"}, - {0x1f, "FN"}, - {0, "Unknown"}, -}; - for (i = 0; i < 256; i++) - { - for (j = 0; j < (sizeof (tmp_list) / sizeof (struct xyzzy)) - 1; j++) - if (tmp_list[j].symnum == i) - break; - printf ("Symbol \"%s\" (0x%x) occured %d times.\n", - tmp_list[j].name, i, profile_types[i]); - } - printf ("Auto vars (under LSYM): %d\n", autovars); - printf ("Global funs (under FUN): %d\n", global_funs); - } -#endif -} - -/* - * Allocate and partially fill a partial symtab. It will be - * completely filled at the end of the symbol list. - */ -static struct partial_symtab * -start_psymtab (filename, textlow, ldsymoff, global_syms, static_syms) - char *filename; - int textlow; - int ldsymoff; - struct partial_symbol *global_syms; - struct partial_symbol *static_syms; -{ - struct partial_symtab *result = - (struct partial_symtab *) obstack_alloc (psymbol_obstack, - sizeof (struct partial_symtab)); - - result->filename = - (char *) obstack_alloc (psymbol_obstack, - strlen (filename) + 1); - strcpy (result->filename, filename); - - result->textlow = textlow; - result->ldsymoff = ldsymoff; - - result->readin = 0; - - result->globals_offset = global_syms - global_psymbols.list; - result->statics_offset = static_syms - static_psymbols.list; - - result->n_global_syms = 0; - result->n_static_syms = 0; - - return result; -} - - -/* Close off the current usage of a partial_symbol table entry. This - involves setting the correct number of includes (with a realloc), - setting the high text mark, setting the symbol length in the - executable, and setting the length of the global and static lists - of psymbols. - - The global symbols and static symbols are then seperately sorted. - - Then the partial symtab is put on the global list. - *** List variables and peculiarities of same. *** - */ -static void -end_psymtab (pst, include_list, num_includes, capping_symbol_offset, - capping_text, dependency_list, number_dependencies, - capping_global, capping_static) - struct partial_symtab *pst; - char **include_list; - int num_includes; - int capping_symbol_offset; - int capping_text; - struct partial_symtab **dependency_list; - int number_dependencies; - struct partial_symbol *capping_global, *capping_static; -{ - int i; - register struct partial_symbol *ps; - - pst->ldsymlen = capping_symbol_offset - pst->ldsymoff; - pst->texthigh = capping_text; - - pst->n_global_syms = - capping_global - (global_psymbols.list + pst->globals_offset); - pst->n_static_syms = - capping_static - (static_psymbols.list + pst->statics_offset); - - pst->dependencies = (struct partial_symtab **) - obstack_alloc (psymbol_obstack, - number_dependencies * sizeof (struct partial_symtab *)); - bcopy (dependency_list, pst->dependencies, - number_dependencies * sizeof (struct partial_symtab *)); - pst->number_of_dependencies = number_dependencies; - - for (i = 0; i < num_includes; i++) - { - /* Eventually, put this on obstack */ - struct partial_symtab *subpst = - (struct partial_symtab *) - obstack_alloc (psymbol_obstack, - sizeof (struct partial_symtab)); - - subpst->filename = - (char *) obstack_alloc (psymbol_obstack, - strlen (include_list[i]) + 1); - strcpy (subpst->filename, include_list[i]); - - subpst->ldsymoff = - subpst->ldsymlen = - subpst->textlow = - subpst->texthigh = 0; - subpst->readin = 0; - - subpst->dependencies = (struct partial_symtab **) - obstack_alloc (psymbol_obstack, - sizeof (struct partial_symtab *)); - subpst->dependencies[0] = pst; - subpst->number_of_dependencies = 1; - - subpst->globals_offset = - subpst->n_global_syms = - subpst->statics_offset = - subpst->n_static_syms = 0; - - subpst->next = partial_symtab_list; - partial_symtab_list = subpst; - } - - for (ps = global_psymbols.list + pst->globals_offset; - ps < capping_global; ++ps) - ps->pst = pst; - for (ps = static_psymbols.list + pst->statics_offset; - ps < capping_static; ++ps) - ps->pst = pst; - - /* Put the psymtab on the psymtab list */ - pst->next = partial_symtab_list; - partial_symtab_list = pst; -} - - -/* Helper routines for psymtab_to_symtab. */ -static void scan_file_globals (); -static void read_ofile_symtab (); - -static void -psymtab_to_symtab_1 (pst, desc, stringtab, stringtab_size, sym_offset) - struct partial_symtab *pst; - int desc; - char *stringtab; - int stringtab_size; - int sym_offset; -{ - struct cleanup *old_chain; - int i; - - if (!pst) - return; - - if (pst->readin) - { - fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n", - pst->filename); - return; - } - - /* Read in all partial symbtabs on which this one is dependent */ - for (i = 0; i < pst->number_of_dependencies; i++) - if (!pst->dependencies[i]->readin) - { - /* Inform about additional files that need to be read in. */ - if (info_verbose) - { - printf_filtered (" and %s...", pst->dependencies[i]->filename); - fflush (stdout); - } - psymtab_to_symtab_1 (pst->dependencies[i], desc, - stringtab, stringtab_size, sym_offset); - } - - if (pst->ldsymlen) /* Otherwise it's a dummy */ - { - /* Init stuff necessary for reading in symbols */ - free_pendings = 0; - pending_blocks = 0; - file_symbols = 0; - global_symbols = 0; - old_chain = make_cleanup (really_free_pendings, 0); - - /* Read in this files symbols */ - lseek (desc, sym_offset, L_SET); - read_ofile_symtab (desc, stringtab, stringtab_size, - pst->ldsymoff, - pst->ldsymlen, pst->textlow, - pst->texthigh - pst->textlow, 0); - sort_symtab_syms (symtab_list); /* At beginning since just added */ - - do_cleanups (old_chain); - } - - pst->readin = 1; -} - -/* - * Read in all of the symbols for a given psymtab for real. Return - * the value of the symtab you create. Do not free the storage - * allocated to the psymtab; it may have pointers to it. - */ -struct symtab * -psymtab_to_symtab(pst) - struct partial_symtab *pst; -{ - int desc; - DECLARE_FILE_HEADERS; - char *stringtab; - struct partial_symtab **list_patch; - int stsize, val; - struct stat statbuf; - struct cleanup *old_chain; - extern void close (); - int i; - struct symtab *result; - char *name = symfile; /* Some of the macros require the */ - /* variable "name" to be defined in */ - /* the context in which they execute */ - /* (Yech!) */ - - if (!pst) - return 0; - - if (pst->readin) - { - fprintf (stderr, "Psymtab for %s already read in. Shouldn't happen.\n", - pst->filename); - return 0; - } - - if (!name) - error("No symbol file currently specified; use command symbol-file"); - - if (pst->ldsymlen || pst->number_of_dependencies) - { - /* Print the message now, before reading the string table, - to avoid disconcerting pauses. */ - if (info_verbose) - { - printf_filtered ("Reading in symbols for %s...", pst->filename); - fflush (stdout); - } - - /* Open symbol file and read in string table */ - if (stat (name, &statbuf) < 0) - perror_with_name (name); - desc = open(name, O_RDONLY, 0); /* symbol_file_command - guarrantees that the symbol file name - will be absolute, so there is no - need for openp */ - - old_chain = make_cleanup (close, desc); - - if (desc < 0) - error("Symbol file not readable"); - - READ_FILE_HEADERS (desc, name); - -#if 0 - /* Read in the string table */ - lseek (desc, STRING_TABLE_OFFSET, L_SET); - READ_STRING_TABLE_SIZE (stsize); - if (stsize >= 0 && stsize < statbuf.st_size) - { -#ifdef BROKEN_LARGE_ALLOCA - stringtab = (char *) xmalloc (stsize); - make_cleanup (free, stringtab); -#else - stringtab = (char *) alloca (stsize); -#endif - } - else - stringtab = NULL; - if (stringtab == NULL) - error ("ridiculous string table size: %d bytes", stsize); - - /* Usually READ_STRING_TABLE_SIZE will have shifted the file pointer. - Occaisionally, it won't. */ - val = lseek (desc, STRING_TABLE_OFFSET, L_SET); - if (val < 0) - perror_with_name (name); - val = myread (desc, stringtab, stsize); - if (val < 0) - perror_with_name (name); -#endif /* 0 */ - stringtab = symfile_string_table; - stsize = symfile_string_table_size; - - psymtab_to_symtab_1 (pst, desc, stringtab, stsize, - SYMBOL_TABLE_OFFSET); - - /* Match with global symbols. This only needs to be done once, - after all of the symtabs and dependencies have been read in. */ - scan_file_globals (); - - do_cleanups (old_chain); - - /* Finish up the debug error message. */ - if (info_verbose) - printf_filtered ("done.\n"); - } - - /* Search through list for correct name. */ - for (result = symtab_list; result; result = result->next) - if (!strcmp (result->filename, pst->filename)) - return result; - - return 0; -} - -/* - * Scan through all of the global symbols defined in the object file, - * assigning values to the debugging symbols that need to be assigned - * to. Get these symbols from the misc function list. - */ -static void -scan_file_globals () -{ - int hash; - int mf; - - for (mf = 0; mf < misc_function_count; mf++) - { - char *namestring = misc_function_vector[mf].name; - struct symbol *sym, *prev; - - QUIT; - - prev = (struct symbol *) 0; - - /* Get the hash index and check all the symbols - under that hash index. */ - - hash = hashname (namestring); - - for (sym = global_sym_chain[hash]; sym;) - { - if (*namestring == SYMBOL_NAME (sym)[0] - && !strcmp(namestring + 1, SYMBOL_NAME (sym) + 1)) - { - /* Splice this symbol out of the hash chain and - assign the value we have to it. */ - if (prev) - SYMBOL_VALUE (prev) = SYMBOL_VALUE (sym); - else - global_sym_chain[hash] - = (struct symbol *) SYMBOL_VALUE (sym); - - /* Check to see whether we need to fix up a common block. */ - /* Note: this code might be executed several times for - the same symbol if there are multiple references. */ - if (SYMBOL_CLASS (sym) == LOC_BLOCK) - fix_common_block (sym, misc_function_vector[mf].address); - else - SYMBOL_VALUE (sym) = misc_function_vector[mf].address; - - if (prev) - sym = (struct symbol *) SYMBOL_VALUE (prev); - else - sym = global_sym_chain[hash]; - } - else - { - prev = sym; - sym = (struct symbol *) SYMBOL_VALUE (sym); - } - } - } -} - -/* - * Read in a defined section of a specific object file's symbols. - * - * DESC is the file descriptor for the file, positioned at the - * beginning of the symtab - * STRINGTAB is a pointer to the files string - * table, already read in - * SYM_OFFSET is the offset within the file of - * the beginning of the symbols we want to read, NUM_SUMBOLS is the - * number of symbols to read - * TEXT_OFFSET is the offset to be added to - * all values of symbols coming in and - * TEXT_SIZE is the size of the text segment read in. - * OFFSET is a flag which indicates that the value of all of the - * symbols should be offset by TEXT_OFFSET (for the purposes of - * incremental linking). - */ - -static void -read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset, - sym_size, text_offset, text_size, offset) - int desc; - register char *stringtab; - int sym_offset; - int sym_size; - int text_offset; - int text_size; - int offset; -{ - register char *namestring; - register struct symbol *sym, *prev; - int hash; - struct cleanup *old_chain; - struct nlist *bufp; - unsigned char type; -#ifdef N_BINCL - subfile_stack = 0; -#endif - - stringtab_global = stringtab; - last_source_file = 0; - - symtab_input_desc = desc; - symbuf_end = symbuf_idx = 0; - - /* It is necessary to actually read one symbol *before* the start - of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL - occurs before the N_SO symbol. - - Detecting this in read_dbx_symtab - would slow down initial readin, so we look for it here instead. */ - if (sym_offset >= sizeof (struct nlist)) - { - lseek (desc, sym_offset - sizeof (struct nlist), L_INCR); - fill_symbuf (); - bufp = &symbuf[symbuf_idx++]; - - if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size) - error ("Invalid symbol data: bad string table offset: %d", - bufp->n_un.n_strx); - namestring = bufp->n_un.n_strx + stringtab; - - processing_gcc_compilation = - (bufp->n_type == N_TEXT - && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL)); - } - else - { - /* The N_SO starting this symtab is the first symbol, so we - better not check the symbol before it. I'm not this can - happen, but it doesn't hurt to check for it. */ - lseek(desc, sym_offset, L_INCR); - processing_gcc_compilation = 0; - } - - if (symbuf_idx == symbuf_end) - fill_symbuf(); - bufp = &symbuf[symbuf_idx]; - if ((unsigned char) bufp->n_type != N_SO) - fatal("First symbol in segment of executable not a source symbol"); - - for (symnum = 0; - symnum < sym_size / sizeof(struct nlist); - symnum++) - { - QUIT; /* Allow this to be interruptable */ - if (symbuf_idx == symbuf_end) - fill_symbuf(); - bufp = &symbuf[symbuf_idx++]; - type = bufp->n_type; - - if (offset && - (type == N_TEXT || type == N_DATA || type == N_BSS)) - bufp->n_value += text_offset; - - if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size) - error ("Invalid symbol data: bad string table offset: %d", - bufp->n_un.n_strx); - namestring = bufp->n_un.n_strx + stringtab; - - if (type & N_STAB) - process_one_symbol(type, bufp->n_desc, - bufp->n_value, namestring); - /* We skip checking for a new .o or -l file; that should never - happen in this routine. */ - else if (type == N_TEXT - && !strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL)) - /* I don't think this code will ever be executed, because - the GCC_COMPILED_FLAG_SYMBOL usually is right before - the N_SO symbol which starts this source file. - However, there is no reason not to accept - the GCC_COMPILED_FLAG_SYMBOL anywhere. */ - processing_gcc_compilation = 1; - else if (type & N_EXT || type == N_TEXT -#ifdef N_NBTEXT - || type == N_NBTEXT -#endif - ) - /* Global symbol: see if we came across a dbx defintion for - a corresponding symbol. If so, store the value. Remove - syms from the chain when their values are stored, but - search the whole chain, as there may be several syms from - different files with the same name. */ - /* This is probably not true. Since the files will be read - in one at a time, each reference to a global symbol will - be satisfied in each file as it appears. So we skip this - section. */ - &stringtab_global; /* For debugger; am I right? */ - } - end_symtab (text_offset + text_size); -} - -static int -hashname (name) - char *name; -{ - register char *p = name; - register int total = p[0]; - register int c; - - c = p[1]; - total += c << 2; - if (c) - { - c = p[2]; - total += c << 4; - if (c) - total += p[3] << 6; - } - - /* Ensure result is positive. */ - if (total < 0) total += (1000 << 6); - return total % HASHSIZE; -} - -/* Put all appropriate global symbols in the symseg data - onto the hash chains so that their addresses will be stored - when seen later in loader global symbols. */ - -static void -hash_symsegs () -{ - /* Look at each symbol in each block in each symseg symtab. */ - struct symtab *s; - for (s = symseg_chain; s; s = s->next) - { - register int n; - for (n = BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s)) - 1; n >= 0; n--) - { - register struct block *b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), n); - register int i; - for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--) - { - register struct symbol *sym = BLOCK_SYM (b, i); - - /* Put the symbol on a chain if its value is an address - that is figured out by the loader. */ - - if (SYMBOL_CLASS (sym) == LOC_EXTERNAL) - { - register int hash = hashname (SYMBOL_NAME (sym)); - SYMBOL_VALUE (sym) = (int) global_sym_chain[hash]; - global_sym_chain[hash] = sym; - SYMBOL_CLASS (sym) = LOC_STATIC; - } - } - } - } -} - -static void -process_one_symbol (type, desc, value, name) - int type, desc; - CORE_ADDR value; - char *name; -{ - register struct context_stack *new; - char *colon_pos; - - /* Something is wrong if we see real data before - seeing a source file name. */ - - if (last_source_file == 0 && type != N_SO) - { - /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines - where that code is defined. */ - if (IGNORE_SYMBOL (type)) - return; - - error ("Invalid symbol data: does not start by identifying a source file."); - } - - switch (type) - { - case N_FUN: - case N_FNAME: - /* Either of these types of symbols indicates the start of - a new function. We must process its "name" normally for dbx, - but also record the start of a new lexical context, and possibly - also the end of the lexical context for the previous function. */ - /* This is not always true. This type of symbol may indicate a - text segment variable. */ - - colon_pos = index (name, ':'); - if (!colon_pos++ - || (*colon_pos != 'f' && *colon_pos != 'F')) - { - define_symbol (value, name, desc); - break; - } - - within_function = 1; - if (context_stack_depth > 0) - { - new = &context_stack[--context_stack_depth]; - /* Make a block for the local symbols within. */ - finish_block (new->name, &local_symbols, new->old_blocks, - new->start_addr, value); - } - /* Stack must be empty now. */ - if (context_stack_depth != 0) - error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.", - symnum); - - new = &context_stack[context_stack_depth++]; - new->old_blocks = pending_blocks; - new->start_addr = value; - new->name = define_symbol (value, name, desc); - local_symbols = 0; - break; - - case N_LBRAC: - /* This "symbol" just indicates the start of an inner lexical - context within a function. */ - - if (context_stack_depth == context_stack_size) - { - context_stack_size *= 2; - context_stack = (struct context_stack *) - xrealloc (context_stack, - (context_stack_size - * sizeof (struct context_stack))); - } - - new = &context_stack[context_stack_depth++]; - new->depth = desc; - new->locals = local_symbols; - new->old_blocks = pending_blocks; - new->start_addr = value; - new->name = 0; - local_symbols = 0; - break; - - case N_RBRAC: - /* This "symbol" just indicates the end of an inner lexical - context that was started with N_LBRAC. */ - new = &context_stack[--context_stack_depth]; - if (desc != new->depth) - error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum); - - /* Some native compilers put the variable decls inside of an - LBRAC/RBRAC block. This macro should be nonzero if this - is true. DESC is N_DESC from the N_RBRAC symbol. */ -#if !defined (VARIABLES_INSIDE_BLOCK) -#define VARIABLES_INSIDE_BLOCK(desc) 0 -#endif - - /* Can only use new->locals as local symbols here if we're in - gcc or on a machine that puts them before the lbrack. */ - if (!VARIABLES_INSIDE_BLOCK(desc)) - local_symbols = new->locals; - - /* If this is not the outermost LBRAC...RBRAC pair in the - function, its local symbols preceded it, and are the ones - just recovered from the context stack. Defined the block for them. - - If this is the outermost LBRAC...RBRAC pair, there is no - need to do anything; leave the symbols that preceded it - to be attached to the function's own block. However, if - it is so, we need to indicate that we just moved outside - of the function. */ - if (local_symbols - && context_stack_depth > !VARIABLES_INSIDE_BLOCK(desc)) - { - /* Muzzle a compiler bug that makes end < start. */ - if (new->start_addr > value) - new->start_addr = value; - /* Make a block for the local symbols within. */ - finish_block (0, &local_symbols, new->old_blocks, - new->start_addr + last_source_start_addr, - value + last_source_start_addr); - } - else - { - within_function = 0; - } - if (VARIABLES_INSIDE_BLOCK(desc)) - /* Now pop locals of block just finished. */ - local_symbols = new->locals; - break; - - case N_FN | N_EXT: - /* This kind of symbol supposedly indicates the start - of an object file. In fact this type does not appear. */ - break; - - case N_SO: - /* This type of symbol indicates the start of data - for one source file. - Finish the symbol table of the previous source file - (if any) and start accumulating a new symbol table. */ -#ifdef PCC_SOL_BROKEN - /* pcc bug, occasionally puts out SO for SOL. */ - if (context_stack_depth > 0) - { - start_subfile (name); - break; - } -#endif - if (last_source_file) - end_symtab (value); - start_symtab (name, value); - break; - - case N_SOL: - /* This type of symbol indicates the start of data for - a sub-source-file, one whose contents were copied or - included in the compilation of the main source file - (whose name was given in the N_SO symbol.) */ - start_subfile (name); - break; - -#ifdef N_BINCL - case N_BINCL: - push_subfile (); - add_new_header_file (name, value); - start_subfile (name); - break; - - case N_EINCL: - start_subfile (pop_subfile ()); - break; - - case N_EXCL: - add_old_header_file (name, value); - break; -#endif /* have N_BINCL */ - - case N_SLINE: - /* This type of "symbol" really just records - one line-number -- core-address correspondence. - Enter it in the line list for this symbol table. */ - record_line (desc, value); - break; - - case N_BCOMM: - if (common_block) - error ("Invalid symbol data: common within common at symtab pos %d", - symnum); - common_block = local_symbols; - common_block_i = local_symbols ? local_symbols->nsyms : 0; - break; - - case N_ECOMM: - /* Symbols declared since the BCOMM are to have the common block - start address added in when we know it. common_block points to - the first symbol after the BCOMM in the local_symbols list; - copy the list and hang it off the symbol for the common block name - for later fixup. */ - { - int i; - struct pending *link = local_symbols; - struct symbol *sym = - (struct symbol *) xmalloc (sizeof (struct symbol)); - bzero (sym, sizeof *sym); - SYMBOL_NAME (sym) = savestring (name, strlen (name)); - SYMBOL_CLASS (sym) = LOC_BLOCK; - SYMBOL_NAMESPACE (sym) = (enum namespace)((long) - copy_pending (local_symbols, common_block_i, common_block)); - i = hashname (SYMBOL_NAME (sym)); - SYMBOL_VALUE (sym) = (int) global_sym_chain[i]; - global_sym_chain[i] = sym; - common_block = 0; - break; - } - - case N_ECOML: - case N_LENG: - break; - - default: - if (name) - define_symbol (value, name, desc); - } -} - -/* This function was added for C++ functionality. I presume that it - condenses the bunches formed by reading in an additional .o file - (incremental linking). */ - -static void -condense_addl_misc_bunches () -{ - register int i, j; - register struct misc_bunch *bunch; -#ifdef NAMES_HAVE_UNDERSCORE - int offset = 1; -#else - int offset = 0; -#endif - - misc_function_vector - = (struct misc_function *) xrealloc (misc_function_vector, - (misc_count + misc_function_count) * sizeof (struct misc_function)); - - j = misc_function_count; - bunch = misc_bunch; - while (bunch) - { - for (i = 0; i < misc_bunch_index; i++) - { - misc_function_vector[j] = bunch->contents[i]; - misc_function_vector[j].name - = concat (misc_function_vector[j].name - + (misc_function_vector[j].name[0] == '_' ? offset : 0), - "", ""); - j++; - } - bunch = bunch->next; - misc_bunch_index = MISC_BUNCH_SIZE; - } - - misc_function_count += misc_count; - - /* Sort the misc functions by address. */ - - qsort (misc_function_vector, misc_function_count, - sizeof (struct misc_function), compare_misc_functions); -} - - -/* Read in another .o file and create a symtab entry for it.*/ - -static void -read_addl_syms (desc, stringtab, nlistlen, text_addr, text_size) - int desc; - register char *stringtab; - register int nlistlen; - unsigned text_addr; - int text_size; -{ - FILE *stream = fdopen (desc, "r"); - register char *namestring; - register struct symbol *sym, *prev; - int hash; - -#ifdef N_BINCL - subfile_stack = 0; -#endif - - last_source_file = 0; - bzero (global_sym_chain, sizeof global_sym_chain); - symtab_input_desc = desc; - stringtab_global = stringtab; - fill_symbuf (); - - for (symnum = 0; symnum < nlistlen; symnum++) - { - struct nlist *bufp; - unsigned char type; - - QUIT; /* allow this to be interruptable */ - if (symbuf_idx == symbuf_end) - fill_symbuf (); - bufp = &symbuf[symbuf_idx++]; - type = bufp->n_type & N_TYPE; - namestring = bufp->n_un.n_strx + stringtab; - - if( (type == N_TEXT) || (type == N_DATA) || (type == N_BSS) ) - { - /* Relocate this file's symbol table information - to the address it has been loaded into. */ - bufp->n_value += text_addr; - } - - type = bufp->n_type; - - if (type & N_STAB) - process_one_symbol (type, bufp->n_desc, - bufp->n_value, namestring); - /* A static text symbol whose name ends in ".o" - can only mean the start of another object file. - So end the symtab of the source file we have been processing. - This is how we avoid counting the libraries as part - or the last source file. - Also this way we find end of first object file (crt0). */ - else if ((type == N_TEXT -#ifdef N_NBTEXT - || type == N_NBTEXT -#endif - ) - && (!strcmp (namestring + strlen (namestring) - 2, ".o")) - || ! strncmp (namestring, "-l", 2)) - { - if (last_source_file) - end_symtab (bufp->n_value); - } - else if (type & N_EXT || type == N_TEXT -#ifdef N_NBTEXT - || type == N_NBTEXT -#endif - ) - { - int used_up = 0; - - /* Record the location of _etext. */ - if (type == (N_TEXT | N_EXT) - && !strcmp (namestring, "_etext")) - end_of_text_addr = bufp->n_value; - -#if 0 - /* 25 Sep 89: The following seems to be stolen from - read_ofile_symtab, and is wrong here (i.e. there was no - first pass for add-file symbols). */ - /* This shouldn't be necessary, as we now do all of this work - in scan_global syms and all misc functions should have been - recorded on the first pass. */ - /* Global symbol: see if we came across a dbx definition - for a corresponding symbol. If so, store the value. - Remove syms from the chain when their values are stored, - but search the whole chain, as there may be several syms - from different files with the same name. */ - if (type & N_EXT) - { - prev = 0; -#ifdef NAMES_HAVE_UNDERSCORE - hash = hashname (namestring + 1); -#else /* not NAMES_HAVE_UNDERSCORE */ - hash = hashname (namestring); -#endif /* not NAMES_HAVE_UNDERSCORE */ - for (sym = global_sym_chain[hash]; - sym;) - { - if ( -#ifdef NAMES_HAVE_UNDERSCORE - *namestring == '_' - && namestring[1] == SYMBOL_NAME (sym)[0] - && - !strcmp (namestring + 2, SYMBOL_NAME (sym) + 1) -#else /* NAMES_HAVE_UNDERSCORE */ - namestring[0] == SYMBOL_NAME (sym)[0] - && - !strcmp (namestring + 1, SYMBOL_NAME (sym) + 1) -#endif /* NAMES_HAVE_UNDERSCORE */ - ) - { - if (prev) - SYMBOL_VALUE (prev) = SYMBOL_VALUE (sym); - else - global_sym_chain[hash] - = (struct symbol *) SYMBOL_VALUE (sym); - if (SYMBOL_CLASS (sym) == LOC_BLOCK) - fix_common_block (sym, bufp->n_value); - else - SYMBOL_VALUE (sym) = bufp->n_value; - if (prev) - sym = (struct symbol *) SYMBOL_VALUE (prev); - else - sym = global_sym_chain[hash]; - - used_up = 1; - } - else - { - prev = sym; - sym = (struct symbol *) SYMBOL_VALUE (sym); - } - } - } - - /* Defined global or text symbol: record as a misc function - if it didn't give its address to a debugger symbol above. */ - if (type <= (N_TYPE | N_EXT) - && type != N_EXT - && ! used_up) - record_misc_function (namestring, bufp->n_value, - bufp->n_type); -#endif /* 0 */ - } - } - - if (last_source_file) - end_symtab (text_addr + text_size); - - fclose (stream); -} - -/* C++: - This function allows the addition of incrementally linked object files. - Since this has a fair amount of code in common with symbol_file_command, - it might be worthwhile to consolidate things, as was done with - read_dbx_symtab and condense_misc_bunches. */ - -void -add_file_command (arg_string) - char* arg_string; -{ - register int desc; - DECLARE_FILE_HEADERS; - struct nlist *nlist; - char *stringtab; - long buffer; - register int val; - extern void close (); - struct cleanup *old_chain; - struct symtab *symseg; - struct stat statbuf; - char *name; - unsigned text_addr; - - if (arg_string == 0) - error ("add-file takes a file name and an address"); - - arg_string = tilde_expand (arg_string); - make_cleanup (free, arg_string); - - for( ; *arg_string == ' '; arg_string++ ); - name = arg_string; - for( ; *arg_string && *arg_string != ' ' ; arg_string++ ); - *arg_string++ = (char) 0; - - if (name[0] == 0) - error ("add-file takes a file name and an address"); - - text_addr = parse_and_eval_address (arg_string); - - dont_repeat (); - - if (!query ("add symbol table from filename \"%s\" at text_addr = 0x%x\n", - name, text_addr)) - error ("Not confirmed."); - - desc = open (name, O_RDONLY); - if (desc < 0) - perror_with_name (name); - - old_chain = make_cleanup (close, desc); - - READ_FILE_HEADERS (desc, name); - - if (NUMBER_OF_SYMBOLS == 0) - { - printf ("%s does not have a symbol-table.\n", name); - fflush (stdout); - return; - } - - printf ("Reading symbol data from %s...", name); - fflush (stdout); - - /* Now read the string table, all at once. */ - val = lseek (desc, STRING_TABLE_OFFSET, 0); - if (val < 0) - perror_with_name (name); - if (stat (name, &statbuf) < 0) - perror_with_name (name); - READ_STRING_TABLE_SIZE (buffer); - if (buffer >= 0 && buffer < statbuf.st_size) - { -#ifdef BROKEN_LARGE_ALLOCA - stringtab = (char *) xmalloc (buffer); - make_cleanup (free, stringtab); -#else - stringtab = (char *) alloca (buffer); -#endif - } - else - stringtab = NULL; - if (stringtab == NULL) - error ("ridiculous string table size: %d bytes", buffer); - - /* Usually READ_STRING_TABLE_SIZE will have shifted the file pointer. - Occaisionally, it won't. */ - val = lseek (desc, STRING_TABLE_OFFSET, 0); - if (val < 0) - perror_with_name (name); - val = myread (desc, stringtab, buffer); - if (val < 0) - perror_with_name (name); - - /* Symsegs are no longer supported by GDB. Setting symseg_chain to - 0 is easier than finding all the symseg code and eliminating it. */ - symseg_chain = 0; - - /* Position to read the symbol table. Do not read it all at once. */ - val = lseek (desc, SYMBOL_TABLE_OFFSET, 0); - if (val < 0) - perror_with_name (name); - - init_misc_functions (); - make_cleanup (discard_misc_bunches, 0); - init_header_files (); - make_cleanup (free_header_files, 0); - free_pendings = 0; - pending_blocks = 0; - file_symbols = 0; - global_symbols = 0; - make_cleanup (really_free_pendings, 0); - - read_addl_syms (desc, stringtab, NUMBER_OF_SYMBOLS, text_addr, - SIZE_OF_TEXT_SEGMENT); - - - /* Sort symbols alphabetically within each block. */ - - sort_syms (); - - /* Go over the misc functions and install them in vector. */ - - condense_addl_misc_bunches (1); - - /* Don't allow char * to have a typename (else would get caddr_t.) */ - - TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0; - - do_cleanups (old_chain); - - /* Free the symtabs made by read_symsegs, but not their contents, - which have been copied into symtabs on symtab_list. */ - while (symseg_chain) - { - register struct symtab *s = symseg_chain->next; - free (symseg_chain); - symseg_chain = s; - } - - printf ("done.\n"); - fflush (stdout); -} - -/* Read a number by which a type is referred to in dbx data, - or perhaps read a pair (FILENUM, TYPENUM) in parentheses. - Just a single number N is equivalent to (0,N). - Return the two numbers by storing them in the vector TYPENUMS. - TYPENUMS will then be used as an argument to dbx_lookup_type. */ - -static void -read_type_number (pp, typenums) - register char **pp; - register int *typenums; -{ - if (**pp == '(') - { - (*pp)++; - typenums[0] = read_number (pp, ','); - typenums[1] = read_number (pp, ')'); - } - else - { - typenums[0] = 0; - typenums[1] = read_number (pp, 0); - } -} - - - -static struct symbol * -define_symbol (value, string, desc) - int value; - char *string; - int desc; -{ - register struct symbol *sym - = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol)); - char *p = (char *) index (string, ':'); - int deftype; - register int i; - - /* Ignore syms with empty names. */ - if (string[0] == 0) - return 0; - - /* Ignore old-style symbols from cc -go */ - if (p == 0) - return 0; - - SYMBOL_NAME (sym) - = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1)); - /* Open-coded bcopy--saves function call time. */ - { - register char *p1 = string; - register char *p2 = SYMBOL_NAME (sym); - while (p1 != p) - *p2++ = *p1++; - *p2++ = '\0'; - } - p++; - /* Determine the type of name being defined. */ - if ((*p >= '0' && *p <= '9') || *p == '(') - deftype = 'l'; - else - deftype = *p++; - - /* c is a special case, not followed by a type-number. - SYMBOL:c=iVALUE for an integer constant symbol. - SYMBOL:c=rVALUE for a floating constant symbol. - SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. - e.g. "b:c=e6,0" for "const b = blob1" - (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ - if (deftype == 'c') - { - if (*p++ != '=') - error ("Invalid symbol data at symtab pos %d.", symnum); - switch (*p++) - { - case 'r': - { - double d = atof (p); - char *value; - - SYMBOL_TYPE (sym) = builtin_type_double; - value = (char *) obstack_alloc (symbol_obstack, sizeof (double)); - bcopy (&d, value, sizeof (double)); - SYMBOL_VALUE_BYTES (sym) = value; - SYMBOL_CLASS (sym) = LOC_CONST_BYTES; - } - break; - case 'i': - { - SYMBOL_TYPE (sym) = builtin_type_int; - SYMBOL_VALUE (sym) = atoi (p); - SYMBOL_CLASS (sym) = LOC_CONST; - } - break; - case 'e': - /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. - e.g. "b:c=e6,0" for "const b = blob1" - (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ - { - int typenums[2]; - - read_type_number (&p, typenums); - if (*p++ != ',') - error ("Invalid symbol data: no comma in enum const symbol"); - - SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums); - SYMBOL_VALUE (sym) = atoi (p); - SYMBOL_CLASS (sym) = LOC_CONST; - } - break; - default: - error ("Invalid symbol data at symtab pos %d.", symnum); - } - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &file_symbols); - return sym; - } - - /* Now usually comes a number that says which data type, - and possibly more stuff to define the type - (all of which is handled by read_type) */ - - if (deftype == 'p' && *p == 'F') - /* pF is a two-letter code that means a function parameter in Fortran. - The type-number specifies the type of the return value. - Translate it into a pointer-to-function type. */ - { - p++; - SYMBOL_TYPE (sym) - = lookup_pointer_type (lookup_function_type (read_type (&p))); - } - else - { - struct type *type = read_type (&p); - - if ((deftype == 'F' || deftype == 'f') - && TYPE_CODE (type) != TYPE_CODE_FUNC) - SYMBOL_TYPE (sym) = lookup_function_type (type); - else - SYMBOL_TYPE (sym) = type; - } - - switch (deftype) - { - case 'f': - SYMBOL_CLASS (sym) = LOC_BLOCK; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &file_symbols); - break; - - case 'F': - SYMBOL_CLASS (sym) = LOC_BLOCK; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &global_symbols); - break; - - case 'G': - /* For a class G (global) symbol, it appears that the - value is not correct. It is necessary to search for the - corresponding linker definition to find the value. - These definitions appear at the end of the namelist. */ - i = hashname (SYMBOL_NAME (sym)); - SYMBOL_VALUE (sym) = (int) global_sym_chain[i]; - global_sym_chain[i] = sym; - SYMBOL_CLASS (sym) = LOC_STATIC; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &global_symbols); - break; - - /* This case is faked by a conditional above, - when there is no code letter in the dbx data. - Dbx data never actually contains 'l'. */ - case 'l': - SYMBOL_CLASS (sym) = LOC_LOCAL; - SYMBOL_VALUE (sym) = value; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &local_symbols); - break; - - case 'p': - SYMBOL_CLASS (sym) = LOC_ARG; - SYMBOL_VALUE (sym) = value; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &local_symbols); - - /* If it's gcc compiled, if it says `short', believe it. */ - if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION) - break; - -#if defined(BELIEVE_PCC_PROMOTION_TYPE) - /* This macro is defined on machines (e.g. sparc) where - we should believe the type of a PCC 'short' argument, - but shouldn't believe the address (the address is - the address of the corresponding int). Note that - this is only different from the BELIEVE_PCC_PROMOTION - case on big-endian machines. - - My guess is that this correction, as opposed to changing - the parameter to an 'int' (as done below, for PCC - on most machines), is the right thing to do - on all machines, but I don't want to risk breaking - something that already works. On most PCC machines, - the sparc problem doesn't come up because the calling - function has to zero the top bytes (not knowing whether - the called function wants an int or a short), so there - is no practical difference between an int and a short - (except perhaps what happens when the GDB user types - "print short_arg = 0x10000;"). - Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler - actually produces the correct address (we don't need to fix it - up). I made this code adapt so that it will offset the symbol - if it was pointing at an int-aligned location and not - otherwise. This way you can use the same gdb for 4.0.x and - 4.1 systems. */ - - if (0 == SYMBOL_VALUE (sym) % sizeof (int)) - { - if (SYMBOL_TYPE (sym) == builtin_type_char - || SYMBOL_TYPE (sym) == builtin_type_unsigned_char) - SYMBOL_VALUE (sym) += 3; - else if (SYMBOL_TYPE (sym) == builtin_type_short - || SYMBOL_TYPE (sym) == builtin_type_unsigned_short) - SYMBOL_VALUE (sym) += 2; - } - break; - -#else /* no BELIEVE_PCC_PROMOTION_TYPE. */ - - /* If PCC says a parameter is a short or a char, - it is really an int. */ - if (SYMBOL_TYPE (sym) == builtin_type_char - || SYMBOL_TYPE (sym) == builtin_type_short) - SYMBOL_TYPE (sym) = builtin_type_int; - else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char - || SYMBOL_TYPE (sym) == builtin_type_unsigned_short) - SYMBOL_TYPE (sym) = builtin_type_unsigned_int; - break; - -#endif /* no BELIEVE_PCC_PROMOTION_TYPE. */ - - case 'P': - SYMBOL_CLASS (sym) = LOC_REGPARM; - SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (value); - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &local_symbols); - break; - - case 'r': -/* XXX */ -#ifdef sparc -{ - struct symbol *s0; - - /* - * If we see a parm decl immediately followed by a reg decl of - * the same name (and in the same block), we change it to a single - * instance of a reg parm. Sun's cc will generate these. - */ - if (local_symbols && - (s0 = local_symbols->symbol[local_symbols->nsyms - 1]) && - SYMBOL_CLASS(s0) == LOC_ARG && - strcmp(SYMBOL_NAME(s0), SYMBOL_NAME(sym)) == 0) { - SYMBOL_CLASS (s0) = LOC_REGPARM; - SYMBOL_VALUE (s0) = STAB_REG_TO_REGNUM (value); - SYMBOL_NAMESPACE (s0) = VAR_NAMESPACE; - return s0; - } -} -#endif - SYMBOL_CLASS (sym) = LOC_REGISTER; - SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (value); - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &local_symbols); - break; - - case 'S': - /* Static symbol at top level of file */ - SYMBOL_CLASS (sym) = LOC_STATIC; - SYMBOL_VALUE (sym) = value; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &file_symbols); - break; - - case 't': - SYMBOL_CLASS (sym) = LOC_TYPEDEF; - SYMBOL_VALUE (sym) = value; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0 - && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0) - TYPE_NAME (SYMBOL_TYPE (sym)) = - obsavestring (SYMBOL_NAME (sym), - strlen (SYMBOL_NAME (sym))); - /* C++ vagaries: we may have a type which is derived from - a base type which did not have its name defined when the - derived class was output. We fill in the derived class's - base part member's name here in that case. */ - else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT - || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION) - && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym))) - { - int i; - for (i = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)); i > 0; i--) - if (TYPE_FIELD_NAME (SYMBOL_TYPE (sym), i - 1) == 0) - TYPE_FIELD_NAME (SYMBOL_TYPE (sym), i - 1) = - TYPE_NAME (TYPE_BASECLASS (SYMBOL_TYPE (sym), i)); - } - - add_symbol_to_list (sym, &file_symbols); - break; - - case 'T': - SYMBOL_CLASS (sym) = LOC_TYPEDEF; - SYMBOL_VALUE (sym) = value; - SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; - if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0 - && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0) - TYPE_NAME (SYMBOL_TYPE (sym)) - = obconcat ("", - (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM - ? "enum " - : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT - ? "struct " : "union ")), - SYMBOL_NAME (sym)); - add_symbol_to_list (sym, &file_symbols); - break; - - case 'V': - /* Static symbol of local scope */ - SYMBOL_CLASS (sym) = LOC_STATIC; - SYMBOL_VALUE (sym) = value; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &local_symbols); - break; - - case 'v': - /* Reference parameter */ - SYMBOL_CLASS (sym) = LOC_REF_ARG; - SYMBOL_VALUE (sym) = value; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &local_symbols); - break; - - case 'X': - /* This is used by Sun FORTRAN for "function result value". - Sun claims ("dbx and dbxtool interfaces", 2nd ed) - that Pascal uses it too, but when I tried it Pascal used - "x:3" (local symbol) instead. */ - SYMBOL_CLASS (sym) = LOC_LOCAL; - SYMBOL_VALUE (sym) = value; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &local_symbols); - break; - - default: - error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum); - } - return sym; -} - -/* What about types defined as forward references inside of a small lexical - scope? */ -/* Add a type to the list of undefined types to be checked through - once this file has been read in. */ -static void -add_undefined_type (type) - struct type *type; -{ - if (undef_types_length == undef_types_allocated) - { - undef_types_allocated *= 2; - undef_types = (struct type **) - xrealloc (undef_types, - undef_types_allocated * sizeof (struct type *)); - } - undef_types[undef_types_length++] = type; -} - -/* Add here something to go through each undefined type, see if it's - still undefined, and do a full lookup if so. */ -static void -cleanup_undefined_types () -{ - struct type **type, *ntype; - struct symbol *sym; - - for (type = undef_types; type < undef_types + undef_types_length; type++) - { - struct type *ntype = 0; - /* Reasonable test to see if it's been defined since. */ - if (TYPE_NFIELDS (*type) == 0) - { - struct pending *ppt; - int i; - /* Name of the type, without "struct" or "union" */ - char *typename = TYPE_NAME (*type); - - if (!strncmp (typename, "struct ", 7)) - typename += 7; - if (!strncmp (typename, "union ", 6)) - typename += 6; - - for (ppt = file_symbols; ppt; ppt = ppt->next) - for (i = 0; i < ppt->nsyms; i++) - { - struct symbol *sym = ppt->symbol[i]; - - if (SYMBOL_CLASS (sym) == LOC_TYPEDEF - && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE - && (TYPE_CODE (SYMBOL_TYPE (sym)) == - TYPE_CODE (*type)) - && !strcmp (SYMBOL_NAME (sym), typename)) - bcopy (SYMBOL_TYPE (sym), *type, sizeof (struct type)); - } - } - else - /* It has been defined; don't mark it as a stub. */ - TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB; - } - undef_types_length = 0; -} - - - -/* Read a dbx type reference or definition; - return the type that is meant. - This can be just a number, in which case it references - a type already defined and placed in type_vector. - Or the number can be followed by an =, in which case - it means to define a new type according to the text that - follows the =. */ - -static -struct type * -read_type (pp) - register char **pp; -{ - register struct type *type = 0; - register int n; - struct type *type1; - int typenums[2]; - int xtypenums[2]; - char *tmpc; - - /* Read type number if present. The type number may be omitted. - for instance in a two-dimensional array declared with type - "ar1;1;10;ar1;1;10;4". */ - if ((**pp >= '0' && **pp <= '9') - || **pp == '(') - { - read_type_number (pp, typenums); - - /* Detect random reference to type not yet defined. - Allocate a type object but leave it zeroed. */ - if (**pp != '=') - return dbx_alloc_type (typenums); - - *pp += 2; - } - else - { - /* 'typenums=' not present, type is anonymous. Read and return - the definition, but don't put it in the type vector. */ - typenums[0] = typenums[1] = -1; - *pp += 1; - } - - switch ((*pp)[-1]) - { - case 'x': - { - enum type_code code; - - /* Used to index through file_symbols. */ - struct pending *ppt; - int i; - - /* Name including "struct", etc. */ - char *type_name; - - /* Name without "struct", etc. */ - char *type_name_only; - - { - char *prefix; - char *from, *to; - - /* Set the type code according to the following letter. */ - switch ((*pp)[0]) - { - case 's': - code = TYPE_CODE_STRUCT; - prefix = "struct "; - break; - case 'u': - code = TYPE_CODE_UNION; - prefix = "union "; - break; - case 'e': - code = TYPE_CODE_ENUM; - prefix = "enum "; - break; - default: - error ("Bad type cross reference at symnum: %d.", symnum); - } - - to = type_name = (char *) - obstack_alloc (symbol_obstack, - (strlen (prefix) + - ((char *) index (*pp, ':') - (*pp)) + 1)); - - /* Copy the prefix. */ - from = prefix; - while (*to++ = *from++) - ; - to--; - - type_name_only = to; - - /* Copy the name. */ - from = *pp + 1; - while ((*to++ = *from++) != ':') - ; - *--to = '\0'; - - /* Set the pointer ahead of the name which we just read. */ - *pp = from; - -#if 0 - /* The following hack is clearly wrong, because it doesn't - check whether we are in a baseclass. I tried to reproduce - the case that it is trying to fix, but I couldn't get - g++ to put out a cross reference to a basetype. Perhaps - it doesn't do it anymore. */ - /* Note: for C++, the cross reference may be to a base type which - has not yet been seen. In this case, we skip to the comma, - which will mark the end of the base class name. (The ':' - at the end of the base class name will be skipped as well.) - But sometimes (ie. when the cross ref is the last thing on - the line) there will be no ','. */ - from = (char *) index (*pp, ','); - if (from) - *pp = from; -#endif /* 0 */ - } - - /* Now check to see whether the type has already been declared. */ - /* This is necessary at least in the case where the - program says something like - struct foo bar[5]; - The compiler puts out a cross-reference; we better find - set the length of the structure correctly so we can - set the length of the array. */ - for (ppt = file_symbols; ppt; ppt = ppt->next) - for (i = 0; i < ppt->nsyms; i++) - { - struct symbol *sym = ppt->symbol[i]; - - if (SYMBOL_CLASS (sym) == LOC_TYPEDEF - && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE - && (TYPE_CODE (SYMBOL_TYPE (sym)) == code) - && !strcmp (SYMBOL_NAME (sym), type_name_only)) - { - obstack_free (symbol_obstack, type_name); - type = SYMBOL_TYPE (sym); - return type; - } - } - - /* Didn't find the type to which this refers, so we must - be dealing with a forward reference. Allocate a type - structure for it, and keep track of it so we can - fill in the rest of the fields when we get the full - type. */ - type = dbx_alloc_type (typenums); - TYPE_CODE (type) = code; - TYPE_NAME (type) = type_name; - - TYPE_FLAGS (type) |= TYPE_FLAG_STUB; - - add_undefined_type (type); - return type; - } - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '(': - (*pp)--; - read_type_number (pp, xtypenums); - type = *dbx_lookup_type (xtypenums); - if (type == 0) - type = builtin_type_void; - if (typenums[0] != -1) - *dbx_lookup_type (typenums) = type; - break; - - case '*': - type1 = read_type (pp); - if (TYPE_POINTER_TYPE (type1)) - { - type = TYPE_POINTER_TYPE (type1); - if (typenums[0] != -1) - *dbx_lookup_type (typenums) = type; - } - else - { - type = dbx_alloc_type (typenums); - smash_to_pointer_type (type, type1); - } - break; - - case '@': - { - struct type *domain = read_type (pp); - char c; - struct type *memtype; - - if (*(*pp)++ != ',') - error ("invalid member type data format, at symtab pos %d.", - symnum); - - memtype = read_type (pp); - type = dbx_alloc_type (typenums); - smash_to_member_type (type, domain, memtype); - } - break; - - case '#': - { - struct type *domain = read_type (pp); - char c; - struct type *return_type; - struct type **args; - - if (*(*pp)++ != ',') - error ("invalid member type data format, at symtab pos %d.", - symnum); - - return_type = read_type (pp); - args = read_args (pp, ';'); - type = dbx_alloc_type (typenums); - smash_to_method_type (type, domain, return_type, args); - } - break; - - case '&': - type1 = read_type (pp); - if (TYPE_REFERENCE_TYPE (type1)) - { - type = TYPE_REFERENCE_TYPE (type1); - if (typenums[0] != -1) - *dbx_lookup_type (typenums) = type; - } - else - { - type = dbx_alloc_type (typenums); - smash_to_reference_type (type, type1); - } - break; - - case 'f': - type1 = read_type (pp); - if (TYPE_FUNCTION_TYPE (type1)) - { - type = TYPE_FUNCTION_TYPE (type1); - if (typenums[0] != -1) - *dbx_lookup_type (typenums) = type; - } - else - { - type = dbx_alloc_type (typenums); - smash_to_function_type (type, type1); - } - break; - - case 'r': - type = read_range_type (pp, typenums); - if (typenums[0] != -1) - *dbx_lookup_type (typenums) = type; - break; - - case 'e': - type = dbx_alloc_type (typenums); - type = read_enum_type (pp, type); - *dbx_lookup_type (typenums) = type; - break; - - case 's': - type = dbx_alloc_type (typenums); - type = read_struct_type (pp, type); - break; - - case 'u': - type = dbx_alloc_type (typenums); - type = read_struct_type (pp, type); - TYPE_CODE (type) = TYPE_CODE_UNION; - break; - - case 'a': - if (*(*pp)++ != 'r') - error ("Invalid symbol data: unrecognized type-code `a%c' %s %d.", - (*pp)[-1], "at symtab position", symnum); - - type = dbx_alloc_type (typenums); - type = read_array_type (pp, type); - break; - - default: - error ("Invalid symbol data: unrecognized type-code `%c' at symtab pos %d.", - (*pp)[-1], symnum); - } - - if (type == 0) - abort (); - -#if 0 - /* If this is an overriding temporary alteration for a header file's - contents, and this type number is unknown in the global definition, - put this type into the global definition at this type number. */ - if (header_file_prev_index >= 0) - { - register struct type **tp - = explicit_lookup_type (header_file_prev_index, typenums[1]); - if (*tp == 0) - *tp = type; - } -#endif - return type; -} - -/* This page contains subroutines of read_type. */ - -/* Read the description of a structure (or union type) - and return an object describing the type. */ - -static struct type * -read_struct_type (pp, type) - char **pp; - register struct type *type; -{ - struct nextfield - { - struct nextfield *next; - int visibility; - struct field field; - }; - - struct next_fnfield - { - struct next_fnfield *next; - int visibility; - struct fn_field fn_field; - }; - - struct next_fnfieldlist - { - struct next_fnfieldlist *next; - struct fn_fieldlist fn_fieldlist; - }; - - register struct nextfield *list = 0; - struct nextfield *new; - int totalsize; - char *name; - register char *p; - int nfields = 0; - register int n; - - register struct next_fnfieldlist *mainlist = 0; - int nfn_fields = 0; - int read_possible_virtual_info = 0; - - if (TYPE_MAIN_VARIANT (type) == 0) - { - TYPE_MAIN_VARIANT (type) = type; - } - - TYPE_CODE (type) = TYPE_CODE_STRUCT; - - /* First comes the total size in bytes. */ - - TYPE_LENGTH (type) = read_number (pp, 0); - - /* C++: Now, if the class is a derived class, then the next character - will be a '!', followed by the number of base classes derived from. - Each element in the list contains visibility information, - the offset of this base class in the derived structure, - and then the base type. */ - if (**pp == '!') - { - int i, n_baseclasses, offset; - struct type **baseclass_vec; - struct type *baseclass; - int via_public; - - /* Nonzero if it is a virtual baseclass, i.e., - - struct A{}; - struct B{}; - struct C : public B, public virtual A {}; - - B is a baseclass of C; A is a virtual baseclass for C. This is a C++ - 2.0 language feature. */ - int via_virtual; - - *pp += 1; - - n_baseclasses = read_number (pp, ','); - baseclass_vec = (struct type **) - obstack_alloc (symbol_obstack, - (n_baseclasses) * sizeof (struct type **)) - 1; - - for (i = 1; i <= n_baseclasses; i++) - { - if (**pp == '\\') - *pp = next_symbol_text (); - - switch (*(*pp)++) - { - case '0': - via_virtual = 0; - break; - case '1': - via_virtual = 1; - break; - default: - error ("Invalid symbol data: bad visibility format at symtab pos %d", - symnum); - } - - switch (*(*pp)++) - { - case '0': - via_public = 0; - break; - case '2': - via_public = 1; - break; - default: - error ("Invalid symbol data: bad visibility format at symtab pos %d.", - symnum); - } - - /* Offset of the portion of the object corresponding to - this baseclass. Always zero in the absence of - multiple inheritance. */ - offset = read_number (pp, ','); - baseclass = read_type (pp); - *pp += 1; /* skip trailing ';' */ - - if (offset != 0) - { - static int error_printed = 0; - - if (!error_printed) - { - fprintf (stderr, -"\nWarning: GDB has limited understanding of multiple inheritance..."); - error_printed = 1; - } - offset = 0; - } - - baseclass_vec[i] = lookup_basetype_type (baseclass, offset, via_virtual, via_public); - - /* Since lookup_basetype_type can copy the type, - it might copy a stub type (complete with stub flag). - If so, we need to add it to the list of undefined types - to clean up later. Even if lookup_basetype_type - didn't copy the type, adding it to the undefined list - will not do any harm. */ - if (TYPE_FLAGS(baseclass_vec[i]) & TYPE_FLAG_STUB) - add_undefined_type (baseclass_vec[i]); - - /* Make this baseclass visible for structure-printing purposes. */ - new = (struct nextfield *) alloca (sizeof (struct nextfield)); - new->next = list; - list = new; - list->field.type = baseclass_vec[i]; - list->field.name = TYPE_NAME (baseclass_vec[i]); - list->field.bitpos = offset; - list->field.bitsize = 0; /* this should be an unpacked field! */ - nfields++; - } - TYPE_N_BASECLASSES (type) = n_baseclasses; - TYPE_BASECLASSES (type) = baseclass_vec; - } - - /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one. - At the end, we see a semicolon instead of a field. - - In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for - a static field. - - The `?' is a placeholder for one of '+' (public visibility), - '0' (protected visibility), and '-' (private visibility). */ - - /* We better set p right now, in case there are no fields at all... */ - p = *pp; - - while (**pp != ';') - { - int visibility; - - /* Check for and handle cretinous dbx symbol name continuation! */ - if (**pp == '\\') *pp = next_symbol_text (); - - /* Get space to record the next field's data. */ - new = (struct nextfield *) alloca (sizeof (struct nextfield)); - new->next = list; - list = new; - - /* Get the field name. */ - p = *pp; - while (*p != ':') p++; - list->field.name = obsavestring (*pp, p - *pp); - - /* C++: Check to see if we have hit the methods yet. */ - if (p[1] == ':') - break; - - *pp = p + 1; - - /* This means we have a visibility for a field coming. */ - if (**pp == '/') - { - switch (*++*pp) - { - case '0': - visibility = 0; - *pp += 1; - break; - - case '1': - visibility = 1; - *pp += 1; - break; - - case '2': - visibility = 2; - *pp += 1; - break; - } - } - /* else normal dbx-style format. */ - - list->field.type = read_type (pp); - if (**pp == ':') - { - list->field.bitpos = (long)-1; - p = ++(*pp); - while (*p != ';') p++; - list->field.bitsize = (long) savestring (*pp, p - *pp); - *pp = p + 1; - nfields++; - continue; - } - else if (**pp != ',') - error ("Invalid symbol data: bad structure-type format at symtab pos %d.", - symnum); - (*pp)++; /* Skip the comma. */ - list->field.bitpos = read_number (pp, ','); - list->field.bitsize = read_number (pp, ';'); - -#if 0 - /* This is wrong because this is identical to the symbols - produced for GCC 0-size arrays. For example: - typedef union { - int num; - char str[0]; - } foo; - The code which dumped core in such circumstances should be - fixed not to dump core. */ - - /* g++ -g0 can put out bitpos & bitsize zero for a static - field. This does not give us any way of getting its - class, so we can't know its name. But we can just - ignore the field so we don't dump core and other nasty - stuff. */ - if (list->field.bitpos == 0 - && list->field.bitsize == 0) - { - /* Have we given the warning yet? */ - static int warning_given = 0; - - /* Only give the warning once, no matter how many class - variables there are. */ - if (!warning_given) - { - warning_given = 1; - fprintf_filtered (stderr, "\n\ -Warning: DBX-style class variable debugging information encountered.\n\ -You seem to have compiled your program with \ -\"g++ -g0\" instead of \"g++ -g\".\n\ -Therefore GDB will not know about your class variables.\n\ -"); - } - - /* Ignore this field. */ - list = list->next; - } - else -#endif /* 0 */ - { - /* Detect an unpacked field and mark it as such. - dbx gives a bit size for all fields. - Note that forward refs cannot be packed, - and treat enums as if they had the width of ints. */ - if (TYPE_CODE (list->field.type) != TYPE_CODE_INT - && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM) - list->field.bitsize = 0; - if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type) - || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM - && (list->field.bitsize - == 8 * TYPE_LENGTH (builtin_type_int)) - ) - ) - && - list->field.bitpos % 8 == 0) - list->field.bitsize = 0; - nfields++; - } - } - - /* Now come the method fields, as NAME::methods - where each method is of the form TYPENUM,ARGS,...:PHYSNAME; - At the end, we see a semicolon instead of a field. - - For the case of overloaded operators, the format is - OPERATOR::*.methods, where OPERATOR is the string "operator", - `*' holds the place for an operator name (such as `+=') - and `.' marks the end of the operator name. */ - if (p[1] == ':') - { - /* Now, read in the methods. To simplify matters, we - "unread" the name that has been read, so that we can - start from the top. */ - - p = *pp; - - /* chill the list of fields: the last entry (at the head) - is a partially constructed entry which we now scrub. */ - list = list->next; - - /* For each list of method lists... */ - do - { - int i; - struct next_fnfield *sublist = 0; - struct fn_field *fn_fields = 0; - int length = 0; - struct next_fnfieldlist *new_mainlist = - (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist)); - - /* read in the name. */ - while (*p != ':') p++; - if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == '$') - { - static char opname[] = "operator"; - char *o = opname + strlen(opname); - - /* Skip past '::'. */ - p += 2; - while (*p != '.') - *o++ = *p++; - new_mainlist->fn_fieldlist.name = savestring (opname, o - opname); - /* Skip past '.' */ - *pp = p + 1; - } - else - { - i = 0; - new_mainlist->fn_fieldlist.name = savestring (*pp, p - *pp); - /* Skip past '::'. */ - *pp = p + 2; - } - - do - { - struct next_fnfield *new_sublist = - (struct next_fnfield *)alloca (sizeof (struct next_fnfield)); - - /* Check for and handle cretinous dbx symbol name continuation! */ - if (**pp == '\\') *pp = next_symbol_text (); - - new_sublist->fn_field.type = read_type (pp); - if (**pp != ':') - error ("invalid symtab info for method at symbol number %d.", - symnum); - *pp += 1; - new_sublist->fn_field.args = - TYPE_ARG_TYPES (new_sublist->fn_field.type); - p = *pp; - while (*p != ';') p++; - new_sublist->fn_field.physname = savestring (*pp, p - *pp); - *pp = p + 1; - new_sublist->visibility = *(*pp)++ - '0'; - if (**pp == '\\') *pp = next_symbol_text (); - - switch (*(*pp)++) - { - case '*': - /* virtual member function, followed by index. */ - new_sublist->fn_field.voffset = read_number (pp, ';') + 1; - break; - case '?': - /* static member function. */ - new_sublist->fn_field.voffset = 1; - break; - default: - /* **pp == '.'. */ - /* normal member function. */ - new_sublist->fn_field.voffset = 0; - break; - } - - new_sublist->next = sublist; - sublist = new_sublist; - length++; - } - while (**pp != ';'); - - *pp += 1; - - new_mainlist->fn_fieldlist.fn_fields = - (struct fn_field *) obstack_alloc (symbol_obstack, - sizeof (struct fn_field) * length); - TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) = - (int *) obstack_alloc (symbol_obstack, - sizeof (int) * (1 + (length >> 5))); - - TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) = - (int *) obstack_alloc (symbol_obstack, - sizeof (int) * (1 + (length >> 5))); - - for (i = length; sublist; sublist = sublist->next) - { - new_mainlist->fn_fieldlist.fn_fields[--i] = sublist->fn_field; - if (sublist->visibility == 0) - B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i); - else if (sublist->visibility == 1) - B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i); - } - - new_mainlist->fn_fieldlist.length = length; - new_mainlist->next = mainlist; - mainlist = new_mainlist; - nfn_fields++; - } - while (**pp != ';'); - } - - *pp += 1; - - /* Now create the vector of fields, and record how big it is. */ - - TYPE_NFIELDS (type) = nfields; - TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, - sizeof (struct field) * nfields); - TYPE_FIELD_PRIVATE_BITS (type) = - (int *) obstack_alloc (symbol_obstack, - sizeof (int) * (1 + (nfields >> 5))); - TYPE_FIELD_PROTECTED_BITS (type) = - (int *) obstack_alloc (symbol_obstack, - sizeof (int) * (1 + (nfields >> 5))); - - TYPE_NFN_FIELDS (type) = nfn_fields; - TYPE_NFN_FIELDS_TOTAL (type) = nfn_fields; - - { - int i; - for (i = 1; i <= TYPE_N_BASECLASSES (type); ++i) - TYPE_NFN_FIELDS_TOTAL (type) += - TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i)); - } - - TYPE_FN_FIELDLISTS (type) = - (struct fn_fieldlist *) obstack_alloc (symbol_obstack, - sizeof (struct fn_fieldlist) * nfn_fields); - - /* Copy the saved-up fields into the field vector. */ - - for (n = nfields; list; list = list->next) - { - TYPE_FIELD (type, --n) = list->field; - if (list->visibility == 0) - SET_TYPE_FIELD_PRIVATE (type, n); - else if (list->visibility == 1) - SET_TYPE_FIELD_PROTECTED (type, n); - } - - for (n = nfn_fields; mainlist; mainlist = mainlist->next) - TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist; - - if (**pp == '~') - { - *pp += 1; - - if (**pp == '=') - { - TYPE_FLAGS (type) - |= TYPE_FLAG_HAS_CONSTRUCTOR | TYPE_FLAG_HAS_DESTRUCTOR; - *pp += 1; - } - else if (**pp == '+') - { - TYPE_FLAGS (type) |= TYPE_FLAG_HAS_CONSTRUCTOR; - *pp += 1; - } - else if (**pp == '-') - { - TYPE_FLAGS (type) |= TYPE_FLAG_HAS_DESTRUCTOR; - *pp += 1; - } - - /* Read either a '%' or the final ';'. */ - if (*(*pp)++ == '%') - { - /* Now we must record the virtual function table pointer's - field information. */ - - struct type *t; - int i; - - t = read_type (pp); - p = (*pp)++; - while (*p != ';') p++; - TYPE_VPTR_BASETYPE (type) = t; - if (type == t) - { - if (TYPE_FIELD_NAME (t, 0) == 0) - TYPE_VPTR_FIELDNO (type) = i = 0; - else for (i = TYPE_NFIELDS (t) - 1; i >= 0; --i) - if (! strncmp (TYPE_FIELD_NAME (t, i), *pp, - strlen (TYPE_FIELD_NAME (t, i)))) - { - TYPE_VPTR_FIELDNO (type) = i; - break; - } - if (i < 0) - error ("virtual function table field not found"); - } - else - TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, 1)); - *pp = p + 1; - } - else - { - TYPE_VPTR_BASETYPE (type) = 0; - TYPE_VPTR_FIELDNO (type) = -1; - } - } - else - { - TYPE_VPTR_BASETYPE (type) = 0; - TYPE_VPTR_FIELDNO (type) = -1; - } - - return type; -} - -/* Read a definition of an array type, - and create and return a suitable type object. - Also creates a range type which represents the bounds of that - array. */ -static struct type * -read_array_type (pp, type) - register char **pp; - register struct type *type; -{ - struct type *index_type, *element_type, *range_type; - int lower, upper; - int adjustable = 0; - - /* Format of an array type: - "ar;lower;upper;". Put code in - to handle this. - - Fortran adjustable arrays use Adigits or Tdigits for lower or upper; - for these, produce a type like float[][]. */ - - index_type = read_type (pp); - if (*(*pp)++ != ';') - error ("Invalid symbol data; improper format of array type decl."); - - if (!(**pp >= '0' && **pp <= '9')) - { - *pp += 1; - adjustable = 1; - } - lower = read_number (pp, ';'); - - if (!(**pp >= '0' && **pp <= '9')) - { - *pp += 1; - adjustable = 1; - } - upper = read_number (pp, ';'); - - element_type = read_type (pp); - - if (adjustable) - { - lower = 0; - upper = -1; - } - - { - /* Create range type. */ - range_type = (struct type *) obstack_alloc (symbol_obstack, - sizeof (struct type)); - TYPE_CODE (range_type) = TYPE_CODE_RANGE; - TYPE_TARGET_TYPE (range_type) = index_type; - - /* This should never be needed. */ - TYPE_LENGTH (range_type) = sizeof (int); - - TYPE_NFIELDS (range_type) = 2; - TYPE_FIELDS (range_type) = - (struct field *) obstack_alloc (symbol_obstack, - 2 * sizeof (struct field)); - TYPE_FIELD_BITPOS (range_type, 0) = lower; - TYPE_FIELD_BITPOS (range_type, 1) = upper; - } - - TYPE_CODE (type) = TYPE_CODE_ARRAY; - TYPE_TARGET_TYPE (type) = element_type; - TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type); - TYPE_NFIELDS (type) = 1; - TYPE_FIELDS (type) = - (struct field *) obstack_alloc (symbol_obstack, - sizeof (struct field)); - TYPE_FIELD_TYPE (type, 0) = range_type; - - return type; -} - - -/* Read a definition of an enumeration type, - and create and return a suitable type object. - Also defines the symbols that represent the values of the type. */ - -static struct type * -read_enum_type (pp, type) - register char **pp; - register struct type *type; -{ - register char *p; - char *name; - register long n; - register struct symbol *sym; - int nsyms = 0; - struct pending **symlist; - struct pending *osyms, *syms; - int o_nsyms; - - if (within_function) - symlist = &local_symbols; - else - symlist = &file_symbols; - osyms = *symlist; - o_nsyms = osyms ? osyms->nsyms : 0; - - /* Read the value-names and their values. - The input syntax is NAME:VALUE,NAME:VALUE, and so on. - A semicolon or comman instead of a NAME means the end. */ - while (**pp && **pp != ';' && **pp != ',') - { - /* Check for and handle cretinous dbx symbol name continuation! */ - if (**pp == '\\') *pp = next_symbol_text (); - - p = *pp; - while (*p != ':') p++; - name = obsavestring (*pp, p - *pp); - *pp = p + 1; - n = read_number (pp, ','); - - sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol)); - bzero (sym, sizeof (struct symbol)); - SYMBOL_NAME (sym) = name; - SYMBOL_CLASS (sym) = LOC_CONST; - SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - SYMBOL_VALUE (sym) = n; - add_symbol_to_list (sym, symlist); - nsyms++; - } - - if (**pp == ';') - (*pp)++; /* Skip the semicolon. */ - - /* Now fill in the fields of the type-structure. */ - - TYPE_LENGTH (type) = sizeof (int); - TYPE_CODE (type) = TYPE_CODE_ENUM; - TYPE_NFIELDS (type) = nsyms; - TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms); - - /* Find the symbols for the values and put them into the type. - The symbols can be found in the symlist that we put them on - to cause them to be defined. osyms contains the old value - of that symlist; everything up to there was defined by us. */ - /* Note that we preserve the order of the enum constants, so - that in something like "enum {FOO, LAST_THING=FOO}" we print - FOO, not LAST_THING. */ - - for (syms = *symlist, n = 0; syms; syms = syms->next) - { - int j = 0; - if (syms == osyms) - j = o_nsyms; - for (; j < syms->nsyms; j++) - { - struct symbol *sym = syms->symbol[j]; - SYMBOL_TYPE (sym) = type; - TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (sym); - TYPE_FIELD_VALUE (type, n) = 0; - TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (sym); - TYPE_FIELD_BITSIZE (type, n++) = 0; - } - if (syms == osyms) - break; - } - - return type; -} - -#define MAX_OF_TYPE(t) ((1 << (sizeof (t) - 1)) - 1) -#define MIN_OF_TYPE(t) (-(1 << (sizeof (t) - 1))) - -static struct type * -read_range_type (pp, typenums) - char **pp; - int typenums[2]; -{ - int rangenums[2]; - long n2, n3; - int n2bits, n3bits; - int self_subrange; - struct type *result_type; - struct type *index_type; - - /* First comes a type we are a subrange of. - In C it is usually 0, 1 or the type being defined. */ - read_type_number (pp, rangenums); - self_subrange = (rangenums[0] == typenums[0] && - rangenums[1] == typenums[1]); - - /* A semicolon should now follow; skip it. */ - if (**pp == ';') - (*pp)++; - - /* The remaining two operands are usually lower and upper bounds - of the range. But in some special cases they mean something else. */ - read_huge_number (pp, ';', &n2, &n2bits); - read_huge_number (pp, ';', &n3, &n3bits); - - if (n2bits == -1 || n3bits == -1) - error ("Unrecognized type range %s.", pp); - - if (n2bits != 0 || n3bits != 0) -#ifdef LONG_LONG - { - char got_signed = 0; - char got_unsigned = 0; - /* Number of bits in the type. */ - int nbits; - - /* Range from 0 to is an unsigned large integral type. */ - if ((n2bits == 0 && n2 == 0) && n3bits != 0) - { - got_unsigned = 1; - nbits = n3bits; - } - /* Range fro to -1 is a large signed - integral type. */ - else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1) - { - got_signed = 1; - nbits = n2bits; - } - - /* Check for "long long". */ - if (got_signed && nbits == CHAR_BIT * sizeof (long long)) - return builtin_type_long_long; - if (got_unsigned && nbits == CHAR_BIT * sizeof (long long)) - return builtin_type_unsigned_long_long; - - error ("Large type isn't a long long."); - } -#else /* LONG_LONG */ - error ("Type long long not supported on this machine."); -#endif - - /* A type defined as a subrange of itself, with bounds both 0, is void. */ - if (self_subrange && n2 == 0 && n3 == 0) - return builtin_type_void; - - /* If n3 is zero and n2 is not, we want a floating type, - and n2 is the width in bytes. - - Fortran programs appear to use this for complex types also, - and they give no way to distinguish between double and single-complex! - We don't have complex types, so we would lose on all fortran files! - So return type `double' for all of those. It won't work right - for the complex values, but at least it makes the file loadable. */ - - if (n3 == 0 && n2 > 0) - { - if (n2 == sizeof (float)) - return builtin_type_float; - return builtin_type_double; - } - - /* If the upper bound is -1, it must really be an unsigned int. */ - - else if (n2 == 0 && n3 == -1) - { - if (sizeof (int) == sizeof (long)) - return builtin_type_unsigned_int; - else - return builtin_type_unsigned_long; - } - - /* Special case: char is defined (Who knows why) as a subrange of - itself with range 0-127. */ - else if (self_subrange && n2 == 0 && n3 == 127) - return builtin_type_char; - - /* Assumptions made here: Subrange of self is equivalent to subrange - of int. */ - else if (n2 == 0 - && (self_subrange || - *dbx_lookup_type (rangenums) == builtin_type_int)) - { - /* an unsigned type */ - if (n3 == UINT_MAX) - return builtin_type_unsigned_int; - if (n3 == ULONG_MAX) - return builtin_type_unsigned_long; - if (n3 == USHRT_MAX) - return builtin_type_unsigned_short; - if (n3 == UCHAR_MAX) - return builtin_type_unsigned_char; - } -#ifdef LONG_LONG - else if (n3 == 0 && n2 == -sizeof (long long)) - return builtin_type_long_long; -#endif - else if (n2 == -n3 -1) - { - /* a signed type */ - if (n3 == INT_MAX) - return builtin_type_int; - if (n3 == LONG_MAX) - return builtin_type_long; - if (n3 == SHRT_MAX) - return builtin_type_short; - if (n3 == CHAR_MAX) - return builtin_type_char; - } - - /* We have a real range type on our hands. Allocate space and - return a real pointer. */ - - /* At this point I don't have the faintest idea how to deal with - a self_subrange type; I'm going to assume that this is used - as an idiom, and that all of them are special cases. So . . . */ - if (self_subrange) - error ("Type defined as subrange of itself: %s.", pp); - - result_type = (struct type *) obstack_alloc (symbol_obstack, - sizeof (struct type)); - bzero (result_type, sizeof (struct type)); - - TYPE_TARGET_TYPE (result_type) = (self_subrange ? - builtin_type_int : - *dbx_lookup_type(rangenums)); - - /* We have to figure out how many bytes it takes to hold this - range type. I'm going to assume that anything that is pushing - the bounds of a long was taken care of above. */ - if (n2 >= MIN_OF_TYPE(char) && n3 <= MAX_OF_TYPE(char)) - TYPE_LENGTH (result_type) = 1; - else if (n2 >= MIN_OF_TYPE(short) && n3 <= MAX_OF_TYPE(short)) - TYPE_LENGTH (result_type) = sizeof (short); - else if (n2 >= MIN_OF_TYPE(int) && n3 <= MAX_OF_TYPE(int)) - TYPE_LENGTH (result_type) = sizeof (int); - else if (n2 >= MIN_OF_TYPE(long) && n3 <= MAX_OF_TYPE(long)) - TYPE_LENGTH (result_type) = sizeof (long); - else - error ("Ranged type doesn't fit within known sizes."); - - TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type)); - TYPE_CODE (result_type) = TYPE_CODE_RANGE; - TYPE_NFIELDS (result_type) = 2; - TYPE_FIELDS (result_type) = - (struct field *) obstack_alloc (symbol_obstack, - 2 * sizeof (struct field)); - bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field)); - TYPE_FIELD_BITPOS (result_type, 0) = n2; - TYPE_FIELD_BITPOS (result_type, 1) = n3; - - return result_type; -} - -/* Read a number from the string pointed to by *PP. - The value of *PP is advanced over the number. - If END is nonzero, the character that ends the - number must match END, or an error happens; - and that character is skipped if it does match. - If END is zero, *PP is left pointing to that character. */ - -static long -read_number (pp, end) - char **pp; - int end; -{ - register char *p = *pp; - register long n = 0; - register int c; - int sign = 1; - - /* Handle an optional leading minus sign. */ - - if (*p == '-') - { - sign = -1; - p++; - } - - /* Read the digits, as far as they go. */ - - while ((c = *p++) >= '0' && c <= '9') - { - n *= 10; - n += c - '0'; - } - if (end) - { - if (c && c != end) - error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum); - } - else - --p; - - *pp = p; - return n * sign; -} - -static void -read_huge_number (pp, end, valu, bits) - char **pp; - int end; - long *valu; - int *bits; -{ - char *p = *pp; - int sign = 1; - long n = 0; - int radix = 10; - char overflow = 0; - int nbits = 0; - int c; - long upper_limit; - - /* Handle an optional leading minus sign. */ - - if (*p == '-') - { - sign = -1; - p++; - } - - /* Leading zero means octal. GCC uses this to output values larger - than an int (because that would be hard in decimal). */ - if (*p == '0') - { - radix = 8; - p++; - } - - upper_limit = LONG_MAX / radix; - while ((c = *p++) >= '0' && c <= '9') - { - if (n <= upper_limit) - { - n *= radix; - n += c - '0'; - } - else - overflow = 1; - - /* This depends on large values being output in octal, which is - what GCC does. */ - if (radix == 8) - { - if (nbits == 0) - { - if (c == '0') - /* Ignore leading zeroes. */ - ; - else if (c == '1') - nbits = 1; - else if (c == '2' || c == '3') - nbits = 2; - else - nbits = 3; - } - else - nbits += 3; - } - } - if (end) - { - if (c && c != end) - { - if (bits != NULL) - *bits = -1; - return; - } - } - else - --p; - - *pp = p; - if (overflow) - { - if (nbits == 0) - { - /* Large decimal constants are an error (because it is hard to - count how many bits are in them). */ - if (bits != NULL) - *bits = -1; - return; - } - - /* -0x7f is the same as 0x80. So deal with it by adding one to - the number of bits. */ - if (sign == -1) - ++nbits; - if (bits) - *bits = nbits; - } - else - { - if (valu) - *valu = n * sign; - if (bits) - *bits = 0; - } -} - -/* Read in an argument list. This is a list of types. It is terminated with - a ':', FYI. Return the list of types read in. */ -static struct type ** -read_args (pp, end) - char **pp; - int end; -{ - struct type *types[1024], **rval; /* allow for fns of 1023 parameters */ - int n = 0; - - while (**pp != end) - { - if (**pp != ',') - error ("Invalid argument list: no ',', at symtab pos %d", symnum); - *pp += 1; - - /* Check for and handle cretinous dbx symbol name continuation! */ - if (**pp == '\\') - *pp = next_symbol_text (); - - types[n++] = read_type (pp); - } - *pp += 1; /* get past `end' (the ':' character) */ - - if (n == 1) - { - rval = (struct type **) xmalloc (2 * sizeof (struct type *)); - } - else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID) - { - rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *)); - bzero (rval + n, sizeof (struct type *)); - } - else - { - rval = (struct type **) xmalloc (n * sizeof (struct type *)); - } - bcopy (types, rval, n * sizeof (struct type *)); - return rval; -} - -/* This function is really horrible, but to avoid it, there would need - to be more filling in of forward references. THIS SHOULD BE MOVED OUT - OF COFFREAD.C AND DBXREAD.C TO SOME PLACE WHERE IT CAN BE SHARED */ -int -fill_in_vptr_fieldno (type) - struct type *type; -{ - if (TYPE_VPTR_FIELDNO (type) < 0) - TYPE_VPTR_FIELDNO (type) = - fill_in_vptr_fieldno (TYPE_BASECLASS (type, 1)); - return TYPE_VPTR_FIELDNO (type); -} - -/* Copy a pending list, used to record the contents of a common - block for later fixup. BUG FIX by rde@topexpress.co.uk */ -static struct pending * -copy_pending (beg, begi, end) - struct pending *beg, *end; - int begi; -{ - struct pending *new = 0; - struct pending *next; - - /* rde note: `begi' is an offset in block `end', NOT `beg' */ - for (next = beg; next != 0; next = next->next) - { - register int j; - for (j = next == end ? begi : 0; j < next->nsyms; j++) - add_symbol_to_list (next->symbol[j], &new); - - if (next == end) - break; - } - return new; -} - -/* Add a common block's start address to the offset of each symbol - declared to be in it (by being between a BCOMM/ECOMM pair that uses - the common block name). */ - -static void -fix_common_block (sym, value) - struct symbol *sym; - int value; -{ - struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym); - for ( ; next; next = next->next) - { - register int j; - for (j = next->nsyms - 1; j >= 0; j--) - SYMBOL_VALUE (next->symbol[j]) += value; - } -} - -void -_initialize_dbxread () -{ - symfile = 0; - header_files = (struct header_file *) 0; - this_object_header_files = (int *) 0; - - undef_types_allocated = 20; - undef_types_length = 0; - undef_types = (struct type **) xmalloc (undef_types_allocated * - sizeof (struct type *)); - - add_com ("symbol-file", class_files, symbol_file_command, - "Load symbol table (in dbx format) from executable file FILE."); - - add_com ("add-file", class_files, add_file_command, - "Load the symbols from FILE, assuming its code is at TEXT_START.") ; -} - -#endif /* READ_DBX_FORMAT */ diff --git a/gnu/usr.bin/gdb/defs.h b/gnu/usr.bin/gdb/defs.h deleted file mode 100644 index de744fc..0000000 --- a/gnu/usr.bin/gdb/defs.h +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - * - * @(#)defs.h 6.3 (Berkeley) 5/8/91 - */ - -/* Basic definitions for GDB, the GNU debugger. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#define CORE_ADDR unsigned int - -#define min(a, b) ((a) < (b) ? (a) : (b)) -#define max(a, b) ((a) > (b) ? (a) : (b)) - -extern char *savestring (); -extern char *concat (); -extern char *xmalloc (), *xrealloc (); -extern int parse_escape (); -extern char *reg_names[]; - -/* Various possibilities for alloca. */ -#ifdef sparc -#include -#else -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else -extern char *alloca (); -#endif -#endif - -extern int quit_flag; - -extern int immediate_quit; - -#define QUIT { if (quit_flag) quit (); } - -/* Notes on classes: class_alias is for alias commands which are not - abbreviations of the original command. */ - -enum command_class -{ - no_class = -1, class_run = 0, class_vars, class_stack, - class_files, class_support, class_info, class_breakpoint, - class_alias, class_obscure, class_user, -}; - -/* the cleanup list records things that have to be undone - if an error happens (descriptors to be closed, memory to be freed, etc.) - Each link in the chain records a function to call and an - argument to give it. - - Use make_cleanup to add an element to the cleanup chain. - Use do_cleanups to do all cleanup actions back to a given - point in the chain. Use discard_cleanups to remove cleanups - from the chain back to a given point, not doing them. */ - -struct cleanup -{ - struct cleanup *next; - void (*function) (); - int arg; -}; - -extern void do_cleanups (); -extern void discard_cleanups (); -extern struct cleanup *make_cleanup (); -extern struct cleanup *save_cleanups (); -extern void restore_cleanups (); -extern void free_current_contents (); -extern void reinitialize_more_filter (); -extern void fputs_filtered (); -extern void fprintf_filtered (); -extern void printf_filtered (); -extern void print_spaces_filtered (); -extern char *tilde_expand (); - -/* Structure for saved commands lines - (for breakpoints, defined commands, etc). */ - -struct command_line -{ - struct command_line *next; - char *line; - int type; /* statement type */ -#define CL_END 0 -#define CL_NORMAL 1 -#define CL_WHILE 2 -#define CL_IF 3 -#define CL_EXITLOOP 4 -#define CL_NOP 5 - struct command_line *body; /* body of loop for while, body of if */ - struct command_line *elsebody; /* body of else part of if */ -}; - -extern struct command_line *read_command_lines (); -extern void do_command_lines(); - -/* String containing the current directory (what getwd would return). */ - -char *current_directory; - diff --git a/gnu/usr.bin/gdb/doc/ChangeLog b/gnu/usr.bin/gdb/doc/ChangeLog deleted file mode 100644 index fb86719..0000000 --- a/gnu/usr.bin/gdb/doc/ChangeLog +++ /dev/null @@ -1,783 +0,0 @@ -Tue Oct 19 14:21:18 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo (Sourc Path): index entries for $cwd, $pdir - - * a4rc.sed: update to work with Andreas Vogel papersize params - - * refcard.tex: use Andreas Vogel simplifications of papersize - params; remove useless version info; update copyright date. - -Tue Oct 19 10:46:22 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * gdb.texinfo (Symbols): Add class NAME to doc for ptype. - -Tue Oct 12 09:11:45 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * gdb.texinfo (Files): Say what address the load command loads it at. - - * stabs.texinfo (Common Blocks): Minor cleanups. - - * stabs.texinfo: Update ld stabs in elf relocation to reflect the fact - that Sun has backed away from the linker kludge and thus the relevant - issue is changes to the SunPRO tools, not the Solaris linker. - - * stabs.texinfo (Traditional Integer Types): Clean up description - of octal bounds a little bit. Document extra leading zeroes. - -Thu Oct 7 16:15:37 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * gdb.texinfo (Signaling): Update for symbolic symbol names - and add a section explaining the difference between the GDB - signal command and the shell kill utility. - -Wed Oct 6 13:23:01 1993 Tom Lord (lord@rtl.cygnus.com) - - * libgdb.texinfo: added `@' to braces that were unescaped. - -Mon Oct 4 10:42:18 1993 Tom Lord (lord@rtl.cygnus.com) - - * libgdb.texinfo: new file. Spec for the gdb library. - -Sun Oct 3 15:26:56 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Include Files): Fix typo (start -> end). - -Thu Sep 30 18:24:56 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo, remote.texi: assorted small improvements, mostly - from Melissa at FSF's editing pass. - -Thu Sep 30 11:54:38 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * gdb.texinfo: Remove stuff about ar and 14 character filenames. - I believe this was fixed by the 13 Sep 89 change to print_frame_info. - Also, modern versions of ar like BSD 4.4 or SVR4 don't have this bug. - -Wed Sep 22 21:22:11 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * remote.texi (Bootstrapping): Discuss 386 call gates. - -Sat Sep 18 17:10:44 1993 Jim Kingdon (kingdon@poseidon.cygnus.com) - - * stabs.texinfo (Based Variables): New node. - -Thu Sep 16 17:48:55 1993 Jim Kingdon (kingdon@cirdan.cygnus.com) - - * stabs.texinfo (Negative Type Numbers): Re-write discussions of - names, sizes, and formats to suggest how not to lose. - -Sat Sep 11 09:35:11 1993 Jim Kingdon (kingdon@poseidon.cygnus.com) - - * stabs.texinfo (Methods): Fix typo. - -Fri Sep 10 06:34:20 1993 David J. Mackenzie (djm@thepub.cygnus.com) - - * gdb.texinfo: Fix a few typos. - -Wed Sep 8 09:11:52 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * gdb.texinfo: Clarify how well it works with Fortran. - - * stabs.texinfo (Stabs In ELF, Statics, ELF Transformations): - More on relocating stabs in ELF files. - -Tue Sep 7 13:45:02 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Stabs In ELF): Talk about N_FUN value. - -Mon Sep 6 19:23:18 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Local Variable Parameters): Talk about nameless - parameters on VAX. - -Fri Sep 3 17:06:08 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo: @up/@down -> @raisesections/@lowersections - -Fri Sep 3 12:04:15 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo: Make info author notice match the TeX author notice. - -Tue Aug 31 13:21:06 1993 David J. Mackenzie (djm@thepub.cygnus.com) - - * stabs.texinfo: Initial-caps all words in node names and - non-trivial words in section names. - -Mon Aug 30 11:13:16 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo: Many minor cleanups. - - * stabs.texinfo: Remove @deffn except from Expanded Reference node. - -Sat Aug 28 12:08:09 1993 David J. MacKenzie (djm@edison.eng.umd.edu) - - * stabs.texinfo: Remove full description of big example. - It's not really helpful; just use pieces of it where appropriate. - Add more Texinfo formatting directives (@samp, etc.). - Use @deffn to define stab types. - Eliminate some wordiness. Break up some nodes. - Add an (alphabetized) index of symbol types. - Use consistent capitalization style in node and section names. - -Thu Aug 26 06:36:31 1993 Fred Fish (fnf@deneb.cygnus.com) - - * gdb.texinfo: Change typo "Two two" to "The two". - -Sun Aug 22 12:15:18 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (XCOFF-differences): Remove references to - non-existent types N_DECL and N_RPSYM. - - * stabs.texinfo (String Field): Say that type attributes bug is - fixed in GDB 4.10, since it is. - - * stabs.texinfo: Clean up djm cleanups, and more cleanups of my own. - -Sat Aug 21 04:32:28 1993 David MacKenzie (djm@cygnus.com) - - * stabs.texinfo: Formatting cleanups. - -Fri Aug 20 20:49:53 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo: When explaining the n_type of a stab, standardize - how we do it ('#' as a comment indicator, "36 is N_FUN" as text, - no tabs, use @r). - (Global Variables): Clean up. - -Tue Aug 17 15:57:27 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Stack Variables): Re-write. - -Mon Aug 16 21:20:08 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Stabs-in-elf): Talk about getting the start - addresses of a source file. Also revise formatting. - Change "object module" or "object file" to "source file". - Various: Miscellaneous cleanups. - -Thu Aug 12 15:11:51 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo: Point to mangling info in gcc's gpcompare.texi. - -Tue Aug 10 16:57:49 1993 Stan Shebs (shebs@rtl.cygnus.com) - - * gdbint.texinfo: Removed many nonsensical machine-collected - host and target conditionals, described some of the remainder. - -Tue Aug 10 13:28:30 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * gdbint.texinfo (Getting Started): Use @itemize, not @table. - - * gdbint.texinfo (Top): Add name to @top line, and re-write the - paragraph which follows. - - * gdbint.texinfo (Host): Use @code not @samp for Makefile - variables. Looks better and avoids overful hbox. - -Fri Jul 30 18:26:21 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Procedures): Improve stuff on nested functions. - -Thu Jul 29 15:10:58 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * remote.texi: (MIPS Remote) clearer doc for set/show timeout, - retransmit-timeout - -Thu Jul 29 13:16:09 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * gdbint.texinfo: Update statement about `some ancient Unix - systems, like Ultrix 4.0' to Ultrix 4.2. - -Wed Jul 28 15:26:53 1993 Roland H. Pesch (pesch@el_bosque.cygnus.com) - - * h8-cfg.texi, all-cfg.texi: new flag GDBSERVER - - * Makefile.in: depend on remote.texi rather than gdbinv-s.texi - - * remote.texi: (Server) New node on gdbserver. (Remote Serial, - ST2000 Remote, MIPS Remote): mention `host:port' syntax for TCP. - - * remote.texi: new name for former gdbinv-s.texi - - * gdb.texinfo: use remote.texi rather than gdbinv-s.texi - -Wed Jul 28 08:26:24 1993 Ian Lance Taylor (ian@cygnus.com) - - * gdbinv-s.texi: Documented timeout and retransmit-timeout - variables for MIPS remote debugging protocol. - -Mon Jul 26 13:00:09 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Negative Type Numbers): FORTRAN LOGICAL fix. - -Tue Jul 20 16:30:41 1993 Jim Kingdon (kingdon@deneb.cygnus.com) - - * Makefile.in (refcard.dvi): Use srcdir where necessary. - -Mon Jul 19 12:02:50 1993 Roland H. Pesch (pesch@cygnus.com) - - * gdb.texinfo: repair conditional bugs in text markup - -Fri Jul 16 18:57:50 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo, all-cfg.texi, h8-cfg.texi: introduce MOD2 switch - to select Modula-2 material. - -Thu Jul 15 13:15:01 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo: Cleanups regarding statics. - - * gdbinv-s.texi (Bootstrapping): Document exceptionHandler. - (Debug Session): Mention exceptionHandler. Add xref to Bootstrapping. - -Mon Jul 12 13:37:02 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo: N_MAIN is sometimes used for C. - -Fri Jul 9 09:47:02 1993 Peter Schauer (pes@regent.e-technik.tu-muenchen.de) - - * gdbint.texinfo (Host, Target Conditionals): Remove TM_FILE_OVERRIDE. - -Tue Jul 6 12:41:28 1993 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo (Target Conditionals): Remove NO_TYPEDEFS, - removed from the code by Kingdon. - -Tue Jul 6 12:24:34 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * gdb.texinfo (Break Commands): Remove stuff about flushing terminal - input when evaluating breakpoint conditions; the bug has been fixed. - - * gdb.texinfo (Continuing and Stepping): Argument to "continue" - sets the ignore count to N-1, not to N. - -Thu Jul 1 14:57:42 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * refcard.tex (\hoffset): correct longstanding error to match - intended offset; avoids cutting off edge on some printers - -Wed Jun 30 18:23:06 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Parameters): Say that order of stabs is significant. - -Fri Jun 25 21:34:52 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Common Blocks): Say what Sun FORTRAN does. - -Fri Jun 25 16:15:10 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * Makefile.in: (REFEDITS) new var to control whether PS or CM - fonts and whether US or A4 paper for GDB refcard; (refcard.dvi) - collect sed edits if any, apply to refcard before formatting; - (refcard.ps) stop implying PS fonts if PS output requested; - (lrefcard.ps) delete extra target for variant PS fonts - - * refcard.tex: parametrize papersize dependent info, collect - in easily replaced spot - - * a4rc.sed: new file, edits to refcard for A4 paper - -Fri Jun 25 14:21:46 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Negative Type Numbers): Type -16 is 4 bytes. - -Wed Jun 23 15:02:50 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Negative Type Numbers): Minor character cleanups. - -Tue Jun 22 16:31:52 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo: Express disapproval of 'D' symbol descriptor - politely rather than rudely. - -Fri Jun 18 19:42:09 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo: Document common blocks. - -Fri Jun 18 12:12:57 1993 Fred Fish (fnf@cygnus.com) - - * stabs.texinfo: Add some basic info about stabs-in-elf. - -Fri Jun 18 13:57:09 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Top): Minor cleanup. - -Mon Jun 14 16:16:51 1993 david d `zoo' zuhn (zoo at rtl.cygnus.com) - - * Makefile.in (install-info): remove parentdir support - -Tue Jun 15 18:11:39 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo (Copying): delete this node and references to it; - RMS says this manual need not carry GPL. (passim): Improvements - from last round at FSF, largely due to Ian Taylor review, and - minor formatting improvements. - - * gdbinv-s.texi (passim): Improvements from last round at FSF, - largely due to Ian Taylor review. (Debug Session): minor edits to - new text. - -Sun Jun 13 12:52:39 1993 Jim Kingdon (kingdon@cygnus.com) - - * Makefile.in (realclean): Remove info and dvi files too. - -Sat Jun 12 16:09:22 1993 Jim Kingdon (kingdon@cygnus.com) - - * {all,h8}-config.texi: Rename to *-cfg.texi for 14 char filenames. - * Makefile.in: Change accordingly. gdb-config.texi -> gdb-cfg.texi. - * gdb.texinfo: Change accordingly. - - * stabs.texinfo: Clean up N_{L,R}BRAC. Discuss what addresses of - N_{L,R}BRAC,N_SLINE are relative to. - -Fri Jun 11 15:15:55 1993 Jim Kingdon (kingdon@cygnus.com) - - * Makefile.in (GDBvn.texi): Update atomically. - -Wed Jun 9 10:58:16 1993 Jim Kingdon (kingdon@cygnus.com) - - * gdbinv-s.texi (Debug Session): Document exceptionHook. - -Tue Jun 8 13:42:04 1993 Jim Kingdon (kingdon@cygnus.com) - - * gdb.texinfo (Print Settings): Move all stuff relating to symbolic - addresses together. Also motivate the set print symbol-filename - command and suggest other solutions. - -Tue Jun 1 22:46:43 1993 Fred Fish (fnf@cygnus.com) - - * gdb.texinfo (set print elements): Note that the number of - elements is set to unlimited by "set print elements 0". - -Mon May 31 08:06:55 1993 Jim Kingdon (kingdon@cygnus.com) - - * stabs.texinfo (Builtin Type Descriptors): Try to clarify what - NF_LDOUBLE means. - (Stab Types): Include Solaris stab types. - (Procedures): Document Solaris extensions. - -Thu May 27 06:20:42 1993 Peter Schauer (pes@regent.e-technik.tu-muenchen.de) - - * gdb.texinfo: Add `set print symbol-filename' doc. - -Wed May 26 00:26:42 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Arrays): Talk about type definition vs. type - information. - - * stabs.texinfo (Builtin Type Descriptors): Talk about omitting - the trailing semicolon. - -Tue May 25 14:49:42 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Line Numbers, Source Files): Re-write these two nodes - and merge in other parts of the document addressing these subjects. - gdbint.texinfo (XCOFF): Remove info which is now in stabs.texinfo. - - * stabs.texinfo (Subranges, Arrays): Try to explain about the semicolon - at the end of a range type. - - * stabs.texinfo (Subranges): "A offset" and "T offset" are not - AIX extensions. - -Mon May 24 09:00:33 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Stabs Format): Misc fixes. - -Sat May 22 10:40:56 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Constants): Allow an `e' constant to be non-enum. - (Traditional builtin types): Document convex convention for long long. - (Negative builtin types): Discuss type names, and misc fixes. - -Fri May 21 11:20:31 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Builtin Type Descriptors): Document the floating - point types used with @samp{R} type descriptor. - (Symbol Descriptors): Describe how to handle conflict between - different meanings of @samp{P} symbol descriptor. - -Thu May 20 13:35:10 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo: Remove node Quick Reference and put its children - directly under the main menu. - - * stabs.texinfo: Many more changes to bring it into line with - AIX documentation and reality. I think it now has all the - information from the AIX documentation, except that I burned - out when I got to variant records (Pascal and Modula-2) and - all the COBOL types. Oh well, we can add them later when we're - worrying more about those languages. - - * stabs.texinfo (Automatic variables): Talk about what it means - to omit the symbol descriptor. - -Tue May 18 17:59:18 1993 Jim Kingdon (kingdon@lioth.cygnus.com) - - * stabs.texinfo (Parameters): Add "(sometimes)" when describing - gcc2 behavior with promoted args. - -Fri May 14 21:35:29 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo: include readline appendices in info version of manual - -Fri May 7 11:56:18 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdbinv-s.texi (Remote Serial): describe new ^C behavior in - target remote. - - * gdb.texinfo (Machine Code): more index entries for disassemble - -Fri May 7 10:12:30 1993 Fred Fish (fnf@cygnus.com) - - * Clarify the intended use of the gdb-testers and gdb-patches - mailing lists, and shrink gzip comment. - -Thu May 6 16:39:50 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo (Shell Commands): do not mention SHELL env var in - DOSHOST configuration of manual. - - * gdb.texinfo (MIPS Stack): new node. - - * all-config.texi (MIPS) new switch. - - * gdbinv-s.texi (Nindy Options) Remove two instances of future - tense; (MIPS Remote) new node. - - * gdb.texinfo (passim) rephrases to work around makeinfo @value - bug; (Environment) less passive, other small cleanups in text about - .cshrc/.bashrc; (Invoking GDB) new MIPS Remote menu entry; - (Remote) new MIPS Remote menu entry. - -Thu Apr 29 09:36:25 1993 Jim Kingdon (kingdon@cygnus.com) - - * stabs.texinfo: Many changes to include information from the - AIX documentation. - - * gdb.texinfo (Environment): Mention pitfall with .cshrc. - -Tue Apr 27 14:02:57 1993 Jim Kingdon (kingdon@cygnus.com) - - * gdbint.texinfo (new node Debugging GDB, elsewhere): - Move a bunch of information from ../README. - (Getting Started): New node. - -Fri Apr 23 17:21:13 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdbinv-s.texi, gdb.texinfo: include Hitachi SH target - - * gdb.texinfo: advance manual revision dates to present - - * gdbinv-s.texi, gdb.texinfo, all-config.texi, h8-config.texi: - stop using silly Roman numerals in @set variable names - -Fri Apr 23 07:30:01 1993 Jim Kingdon (kingdon@cygnus.com) - - * stabs.texinfo (Parameters): Keep trying to get this right. - -Wed Apr 21 15:18:47 1993 Jim Kingdon (kingdon@cygnus.com) - - * stabs.texinfo (Parameters): More on "local parameters". - -Mon Apr 19 08:00:51 1993 Jim Kingdon (kingdon@cygnus.com) - - * stabs.texinfo (Parameters): Re-do "local parameters" section. - -Sun Apr 18 09:47:45 1993 Jim Kingdon (kingdon@cygnus.com) - - * stabs.texinfo (Symbol descriptors): Re-do using @table and @xref. - (Parameters): Rewrite. - (xcoff-differences, Sun-differences): Minor changes. - -Thu Apr 15 02:35:24 1993 John Gilmore (gnu@cacophony.cygnus.com) - - * stabs.texinfo: Minor cleanup. - -Wed Apr 14 17:31:00 1993 Jim Kingdon (kingdon@cygnus.com) - - * gdbint.texinfo: Minor xcoff stuff. - -Wed Apr 7 14:11:07 1993 Fred Fish (fnf@cygnus.com) - - * gdbint.texinfo: Update for new config directory structure. - Add info about internal type data structures. - -Mon Apr 5 09:06:30 1993 Ian Lance Taylor (ian@cygnus.com) - - * Makefile.in (SFILES_INCLUDED): gdb-config.texi is no longer in - $(srcdir). - (gdb-config.texi): Depend on file in $(srcdir). - -Fri Apr 2 16:55:13 1993 Jim Kingdon (kingdon@cygnus.com) - - * stabs.texinfo: Fixes about N_SO. - -Fri Mar 26 18:00:35 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo: include list of nonstandard init file names - - * *-config.texi: new switch GENERIC for text that applies *only* - to (usual) multiple-target version of manual - - * gdb.texinfo, gdbinv-s.texi: Update conditional markup to correct - h8 config - - * gdb.texinfo: depend on latest fixed makeinfo, use conditionals - in menus (rather than conditionally selected multiple alternative - menus). - - * Makefile.in: define and use DOC_CONFIG var to select - configuration for GDB user manual. - - * gdb-config.texi: delete from repository, generate from Makefile. - - * all-config.texi: normal `generic' configuration file, formerly - stored as gdb-config.texi - -Wed Mar 24 14:03:19 1993 david d `zoo' zuhn (zoo at poseidon.cygnus.com) - - * Makefile.in: add dvi target to build all .dvi files - -Tue Mar 23 16:03:24 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo, gdvinv-s.texinfo: formatting improvements. - -Fri Mar 19 21:46:50 1993 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Doc NO_MMALLOC and NO_MMALLOC_CHECK as - host conditionals. - * stabs.texinfo: More array fixes inspired by Jim's. - -Fri Mar 19 10:23:34 1993 Jim Kingdon (kingdon@cygnus.com) - - * stabs.texinfo: Fixes re arrays and continuations. - - * gdbint.texinfo: Add XCOFF node. - -Mon Mar 8 15:52:18 1993 John Gilmore (gnu@cygnus.com) - - * gdb.texinfo: Add `set print max-symbolic-offset' doc. - -Sun Feb 21 17:09:38 1993 Per Bothner (bothner@rtl.cygnus.com) - - * stabs.texinfo: Fix for array types to mention lower bounds. - -Thu Feb 18 01:19:49 1993 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Update PTRACE_ARG3_TYPE doc, pull PT_*. - -Wed Feb 17 08:15:24 1993 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Remove SET_STACK_LIMIT_HUGE from target defines. - -Thu Feb 11 10:38:40 1993 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Fix thinko (NM_FILE => NAT_FILE). Found - by Michael Ben-Gershon . - -Wed Feb 10 23:59:19 1993 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Eliminate IBM6000_HOST, document IBM6000_TARGET. - -Tue Feb 9 18:26:21 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo, gdbinv-s.texi: misc updates - -Sat Feb 6 10:25:47 1993 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Brief documentation for longjmp support, - from an email msg by Stu. - -Fri Feb 5 14:10:15 1993 John Gilmore (gnu@cygnus.com) - - * stabs.texinfo: Fix description of floating point "range" - types (which really define basic types). Reported by Jim Meehan, - . - - * gdbint.texinfo: Remove COFF_NO_LONG_FILE_NAMES define, now gone. - -Thu Feb 4 13:56:46 1993 Ian Lance Taylor (ian@cygnus.com) - - * gdbint.texinfo: Slightly expand section on supporting a new - object file format. - -Thu Feb 4 01:49:04 1993 John Gilmore (gnu@cygnus.com) - - * Makefile.in (refcard.ps, lrefcard.ps): Remove psref.tex - intermediate file. - -Tue Feb 2 12:18:06 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo, gdbinv-s.texi: miscellaneous stylistic cleanups - -Mon Feb 1 15:35:47 1993 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdbinv-s.texi: z8000 simulator target name is just "sim" - - * gdbinv-s.texi: Mention that Z8000 simulator can simulate Z8001 - as well as Z8002. - -Sat Nov 28 06:51:35 1992 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Add sections on clean design and on how to send - in changes. - -Mon Nov 9 23:57:02 1992 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Add how to declare the result of make_cleanup. - -Mon Oct 26 11:09:47 1992 John Gilmore (gnu@cygnus.com) - - * gdb.texinfo: Fix typo, reported by Karl Berry. - -Fri Oct 23 00:41:21 1992 John Gilmore (gnu@cygnus.com) - - * gdb.texinfo: Add opcodes dir to GDB distribution description. - -Sat Oct 10 18:04:58 1992 david d `zoo' zuhn (zoo at cirdan.cygnus.com) - - * gdbint.texinfo: fixed a stray email address (needs @@), - added @table @code to node "Native Conditionals" - -Tue Sep 22 00:34:15 1992 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Describe coding style of GDB. - -Mon Sep 21 19:32:16 1992 John Gilmore (gnu@cygnus.com) - - * stabs.texinfo: Minor wording changes. - -Tue Sep 15 02:57:09 1992 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Improve release doc slightly. - -Fri Sep 11 01:34:25 1992 John Gilmore (gnu@sphagnum.cygnus.com) - - * gdbint.texinfo: Improve doc of GDB config macros. - -Wed Sep 9 16:52:06 1992 John Gilmore (gnu@cygnus.com) - - * stabs.texinfo: Remove Bothner's changes for C++ nested types. - These will be reinserted when examined. - -Mon Aug 24 01:17:55 1992 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Make a start at documenting all the #if macros - in GDB. At least list them all, and start separating them into - host-specific and target-specific. - -Tue Aug 18 15:59:13 1992 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdbinv-s.m4.in: refrain from using @cartouche for just a few - examples (not consistent w others). - gdb.texinfo: issue disclaimer paragraph on cmdline options only - for generic vn of doc - -Tue Aug 18 14:53:27 1992 Ian Lance Taylor (ian@cygnus.com) - - * Makefile.in: always create installation directories. - -Tue Aug 18 14:11:50 1992 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo: in h8 config, do not describe searching commands. - -Mon Aug 17 18:07:59 1992 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo, none.m4, h8.m4, gdbinv-s.m4.in: improve H8/300 - conditionals; introduce a few generic switches that may be - useful for other cross-dev or dos-hosted configs. - - * gdb.texinfo: fix typo in "info reg" description - -Sun Aug 16 01:16:18 1992 John Gilmore (gnu@cygnus.com) - - * stabs.texinfo: Minor updates from running TeX over it. - * Makefile.in (stabs.dvi, stabs.ps): Add. - -Sat Aug 15 20:52:24 1992 Per Bothner (bothner@rtl.cygnus.com) - - * stabs.texinfo: Stabs documentation, written by Julia Menapace. - First pass at converting it to texinfo. - -Sat Aug 15 03:14:59 1992 John Gilmore (gnu@cygnus.com) - - * gdb.texinfo, refcard.tex: Document mult args on `info reg'. - * Makefile.in (refcard.ps, lrefcard.ps): Add missing $(srdir). - -Fri Aug 14 21:08:47 1992 John Gilmore (gnu@cygnus.com) - - * gdbint.texinfo: Add section on partial symbol tables. - -Sat Jun 20 16:31:10 1992 John Gilmore (gnu at cygnus.com) - - * gdb.texinfo: document `set remotedebug' and `set - rstack_high_address'. - -Thu May 14 17:09:48 1992 Roland H. Pesch (pesch@fowanton.cygnus.com) - - * gdb.texinfo: slight expansion of new text on reading info files - * gdbinv-s.m4.in: correct and expand info on cross-debugging - H8/300 from DOS. - -Tue May 12 12:22:47 1992 John Gilmore (gnu at cygnus.com) - - * gdb.texinfo: `info user' => `show user'. Noticed by David Taylor. - -Mon May 11 19:06:27 1992 John Gilmore (gnu at cygnus.com) - - * gdb.texinfo: Say how to read the `info' files. - -Tue May 5 12:11:38 1992 K. Richard Pixley (rich@cygnus.com) - - * Makefile.in: gm4 -> m4. - -Fri Apr 10 17:50:43 1992 John Gilmore (gnu at rtl.cygnus.com) - - * gdb.texinfo: Update for GDB-4.5. Move `Formatting - Documentation' ahead of `Installing GDB' to match README. - Update shared library doc, -readnow and -mapped, and directory - structure (add glob and mmalloc). Update configure doc. - -Tue Mar 24 23:28:38 1992 K. Richard Pixley (rich@cygnus.com) - - * Makefile.in: remove $(srcdir) from gdb.info rule. - -Sat Mar 7 18:44:50 1992 K. Richard Pixley (rich@rtl.cygnus.com) - - * Makefile.in: commented out gdb-all.texinfo rule. This is - temporary. - -Wed Feb 26 18:04:40 1992 K. Richard Pixley (rich@cygnus.com) - - * Makefile.in, configure.in: removed traces of namesubdir, - -subdirs, $(subdir), $(unsubdir), some rcs triggers. Forced - copyrights to '92, changed some from Cygnus to FSF. - -Fri Dec 13 09:47:31 1991 John Gilmore (gnu at cygnus.com) - - * gdb.texinfo: Improve how we ask for bug reports. - -Tue Dec 10 04:07:21 1991 K. Richard Pixley (rich at rtl.cygnus.com) - - * Makefile.in: infodir belongs in datadir. - -Fri Dec 6 23:57:34 1991 K. Richard Pixley (rich at rtl.cygnus.com) - - * Makefile.in: remove spaces following hyphens, bsd make can't - cope. install using INSTALL_DATA. added clean-info. added - standards.text support. - -Thu Dec 5 22:46:12 1991 K. Richard Pixley (rich at rtl.cygnus.com) - - * Makefile.in: idestdir and ddestdir go away. Added copyrights - and shift gpl to v2. Added ChangeLog if it didn't exist. docdir - and mandir now keyed off datadir by default. - - -Local Variables: -mode: indented-text -left-margin: 8 -fill-column: 74 -version-control: never -End: diff --git a/gnu/usr.bin/gdb/doc/Makefile.in b/gnu/usr.bin/gdb/doc/Makefile.in deleted file mode 100644 index d5ae290..0000000 --- a/gnu/usr.bin/gdb/doc/Makefile.in +++ /dev/null @@ -1,327 +0,0 @@ -##Copyright (C) 1991, 1992 Free Software Foundation, Inc. - -# Makefile for GDB documentation. -# This file is part of GDB. - -# 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 of the License, 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 this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -srcdir = . - -prefix = /usr/local - -infodir = $(prefix)/info - -SHELL = /bin/sh - -INSTALL = install -c -INSTALL_PROGRAM = $(INSTALL) -INSTALL_DATA = $(INSTALL) - -# main GDB source directory -gdbdir = $(srcdir)/.. - -# where to find texinfo; GDB dist should include a recent one -TEXIDIR=${gdbdir}/../texinfo - -# where to find makeinfo, preferably one designed for texinfo-2 -MAKEINFO=makeinfo - -# where to find texi2roff, ditto -TEXI2ROFF=texi2roff - -# Where is the source dir for the READLINE library doc? -# Traditionally readline is in .. or . -READLINE_DIR = ${gdbdir}/../readline/doc - -SET_TEXINPUTS = TEXINPUTS=${TEXIDIR}:.:$(srcdir):$(READLINE_DIR):$$TEXINPUTS - -# There may be alternate predefined collections of switches to configure -# the GDB manual. Normally this is not done in synch with the software -# config system, since this choice tends to be independent; most people -# want a doc config of `all' for a generic manual, regardless of sw config. -DOC_CONFIG = all - -# This list of sed edits will edit the GDB reference card -# for what fonts and what papersize to use. -# By default (NO edits applied), the refcard uses: -# - Computer Modern (CM) fonts -# - US letter paper (8.5x11in) -# List some of the following files for alternative fonts and paper: -# a4rc.sed use A4 paper (297 x 210 mm) -# psrc.sed use PostScript fonts (Karl Berry short TeX names) -# lpsrc.sed use PostScript fonts (full PostScript names in TeX) -# e.g. for A4, Postscript: REFEDITS = a4rc.sed psrc.sed -# for A4, CM fonts: REFEDITS = a4rc.sed -# for US, PS fonts: REFEDITS = psrc.sed -# for default: -REFEDITS = - -# Don Knuth's TeX formatter -TEX = tex - -# auxiliary program for sorting Texinfo indices -TEXINDEX = texindex - -# Main GDB manual's source files -SFILES_INCLUDED = gdb-cfg.texi $(srcdir)/remote.texi - -SFILES_LOCAL = $(srcdir)/gdb.texinfo GDBvn.texi $(SFILES_INCLUDED) - -SFILES_DOC = $(SFILES_LOCAL) \ - $(READLINE_DIR)/rluser.texinfo $(READLINE_DIR)/inc-hist.texi - -#### Host, target, and site specific Makefile fragments come in here. -### - -all install: - -info: gdb.info gdbint.info stabs.info -dvi: gdb.dvi refcard.dvi gdbint.dvi -all-doc: gdb.info gdb.dvi refcard.dvi gdb-internals gdbint.dvi - -install-info: info - for i in *.info* ; do \ - $(INSTALL_DATA) $$i $(infodir)/$$i ; \ - done - -STAGESTUFF = *.info* gdb-all.texi GDBvn.texi - -# Copy the object files from a particular stage into a subdirectory. -stage1: force - -mkdir stage1 - -mv $(STAGESTUFF) stage1 - -stage2: force - -mkdir stage2 - -mv $(STAGESTUFF) stage2 - -stage3: force - -mkdir stage3 - -mv $(STAGESTUFF) stage3 - -against=stage2 - -comparison: force - for i in $(STAGESTUFF) ; do cmp $$i $(against)/$$i ; done - -de-stage1: force - -(cd stage1 ; mv -f * ..) - -rmdir stage1 - -de-stage2: force - -(cd stage2 ; mv -f * ..) - -rmdir stage2 - -de-stage3: force - -(cd stage3 ; mv -f * ..) - -rmdir stage3 - -clean-info: - rm -f gdb.info* gdbint.info* stabs.info* - -clean-dvi: - rm -f gdb.dvi refcard.dvi gdbint.dvi stabs.dvi sedref.dvi - -mostlyclean: clean-info clean-dvi - rm -f gdb.?? gdb.??? gdb.mm gdb.ms gdb.me - rm -f links2roff - rm -f refcard.ps lrefcard.ps refcard.log sedref.* *~ - rm -f gdbint.?? gdbint.??? stabs.?? stabs.??? - -clean: mostlyclean - rm -f GDBvn.texi rluser.texinfo inc-hist.texi - -distclean: clean - rm -f Makefile config.status - -realclean: distclean clean-dvi clean-info - -# GDB QUICK REFERENCE (dvi output) -refcard.dvi : refcard.tex $(REFEDITS) - if [ -z "$(REFEDITS)" ]; then \ - cp $(srcdir)/refcard.tex sedref.tex ; \ - else \ - echo > tmp.sed ; \ - for f in "$(REFEDITS)" ; do \ - cat $(srcdir)/$$f >>tmp.sed ; done ; \ - sed -f tmp.sed $(srcdir)/refcard.tex >sedref.tex ; \ - fi - $(SET_TEXINPUTS) $(TEX) sedref.tex - mv sedref.dvi refcard.dvi - rm -f sedref.log sedref.tex tmp.sed - -refcard.ps : refcard.dvi - dvips -t landscape refcard.dvi -o - -# File to record current GDB version number (copied from main dir Makefile.in) -GDBvn.texi : ${gdbdir}/Makefile.in - echo "@set GDBVN `sed <$(srcdir)/../Makefile.in -n 's/VERSION = //p'`" > ./GDBvn.new - mv GDBvn.new GDBvn.texi - -# Updated atomically -.PRECIOUS: GDBvn.texi - -# Choose configuration for GDB manual (normally `all'; normally not tied into -# `configure' script because most users prefer generic version of manual, -# not one for their binary config---which may not be specifically -# defined anyways). -gdb-cfg.texi: ${srcdir}/${DOC_CONFIG}-cfg.texi - ln -s ${srcdir}/${DOC_CONFIG}-cfg.texi gdb-cfg.texi || \ - ln ${srcdir}/${DOC_CONFIG}-cfg.texi gdb-cfg.texi || \ - cp ${srcdir}/${DOC_CONFIG}-cfg.texi gdb-cfg.texi - -# GDB MANUAL: texinfo source, using @set/@clear/@value/@ifset/@ifclear -# If your texinfo or makeinfo don't support these, get a new texinfo release -# -# The nonsense with GDBvn.texi gets this to run with both Sun and GNU make. -# Note that we can *generate* GDBvn.texi, but since we distribute one in the -# source directory for the benefit of people who *don't* use this makefile, -# VPATH will often tell make not to bother building it, because the one -# in the srcdir is up to date. (if not, then make should build one here). - -# GDB MANUAL: TeX dvi file -gdb.dvi: ${SFILES_DOC} - if [ ! -f ./GDBvn.texi ]; then \ - ln -s $(srcdir)/GDBvn.texi . || \ - ln $(srcdir)/GDBvn.texi . || \ - cp $(srcdir)/GDBvn.texi . ; else true; fi - $(SET_TEXINPUTS) $(TEX) gdb.texinfo - $(SET_TEXINPUTS) $(TEX) gdb.texinfo - $(TEXINDEX) gdb.?? - $(SET_TEXINPUTS) $(TEX) gdb.texinfo - rm -f gdb.?? gdb.log gdb.aux gdb.toc gdb.??s - -# GDB MANUAL: info file -# We're using texinfo2, and older makeinfo's may not be able to -# cope with all the markup. -gdb.info: ${SFILES_DOC} - $(MAKEINFO) -I ${READLINE_DIR} -I $(srcdir) -o ./gdb.info gdb.texinfo - -# GDB MANUAL: roff translations -# Try to use a recent texi2roff. v2 was put on prep in jan91. -# If you want an index, see texi2roff doc for postprocessing -# and add -i to texi2roff invocations below. -# Workarounds for texi2roff-2 (probably fixed in later texi2roff's, delete -# corresponding -e lines when later texi2roff's are current) -# + @ifinfo's deleted explicitly due to texi2roff-2 bug w nested constructs. -# + @c's deleted explicitly because texi2roff sees texinfo commands in them -# + @ (that's at-BLANK) not recognized by texi2roff, turned into blank -# + @alphaenumerate is ridiculously new, turned into @enumerate - -# texi2roff doesn't have a notion of include dirs, so we have to fake -# it out for gdb manual's include files---but only if not configured -# in main sourcedir. -links2roff: $(SFILES_INCLUDED) - if [ ! -f gdb.texinfo ]; then \ - ln -s $(SFILES_INCLUDED) . || \ - ln $(SFILES_INCLUDED) . || \ - cp $(SFILES_INCLUDED) . ; \ - fi - touch links2roff - -# "Readline" appendices. Get them also due to lack of includes, -# regardless of whether or not configuring in main sourcedir. -# @ftable removed due to bug in texi2roff-2; if your texi2roff -# is newer, try just ln or cp -rluser.texinfo: ${READLINE_DIR}/rluser.texinfo - sed -e 's/^@ftable/@table/g' \ - -e 's/^@end ftable/@end table/g' \ - ${READLINE_DIR}/rluser.texinfo > ./rluser.texinfo - -inc-hist.texi: ${READLINE_DIR}/inc-hist.texi - ln -s ${READLINE_DIR}/inc-hist.texi . || \ - ln ${READLINE_DIR}/inc-hist.texi . || \ - cp ${READLINE_DIR}/inc-hist.texi . - -# gdb manual suitable for [gtn]roff -me -gdb.me: $(SFILES_LOCAL) links2roff rluser.texinfo inc-hist.texi - sed -e '/\\input texinfo/d' \ - -e '/@c TEXI2ROFF-KILL/,/@c END TEXI2ROFF-KILL/d' \ - -e '/^@ifinfo/,/^@end ifinfo/d' \ - -e '/^@c /d' \ - -e 's/{.*,,/{/' \ - -e 's/@ / /g' \ - -e 's/^@alphaenumerate/@enumerate/g' \ - -e 's/^@end alphaenumerate/@end enumerate/g' \ - $(srcdir)/gdb.texinfo | \ - $(TEXI2ROFF) -me | \ - sed -e 's/---/\\(em/g' \ - >gdb.me - -# gdb manual suitable for [gtn]roff -ms -gdb.ms: $(SFILES_LOCAL) links2roff rluser.texinfo inc-hist.texi - sed -e '/\\input texinfo/d' \ - -e '/@c TEXI2ROFF-KILL/,/@c END TEXI2ROFF-KILL/d' \ - -e '/^@ifinfo/,/^@end ifinfo/d' \ - -e '/^@c /d' \ - -e 's/{.*,,/{/' \ - -e 's/@ / /g' \ - -e 's/^@alphaenumerate/@enumerate/g' \ - -e 's/^@end alphaenumerate/@end enumerate/g' \ - $(srcdir)/gdb.texinfo | \ - $(TEXI2ROFF) -ms | \ - sed -e 's/---/\\(em/g' \ - >gdb.ms - -# gdb manual suitable for [tn]roff -mm -# '@noindent's removed due to texi2roff-2 mm bug; if yours is newer, -# try leaving them in -gdb.mm: $(SFILES_LOCAL) links2roff rluser.texinfo inc-hist.texi - sed -e '/\\input texinfo/d' \ - -e '/@c TEXI2ROFF-KILL/,/@c END TEXI2ROFF-KILL/d' \ - -e '/^@ifinfo/,/^@end ifinfo/d' \ - -e '/^@c /d' \ - -e 's/{.*,,/{/' \ - -e '/@noindent/d' \ - -e 's/@ / /g' \ - -e 's/^@alphaenumerate/@enumerate/g' \ - -e 's/^@end alphaenumerate/@end enumerate/g' \ - $(srcdir)/gdb.texinfo | \ - $(TEXI2ROFF) -mm | \ - sed -e 's/---/\\(em/g' \ - >gdb.mm - -# GDB INTERNALS MANUAL: TeX dvi file -gdbint.dvi : gdbint.texinfo - $(SET_TEXINPUTS) $(TEX) gdbint.texinfo - $(TEXINDEX) gdbint.?? - $(SET_TEXINPUTS) $(TEX) gdbint.texinfo - rm -f gdbint.?? gdbint.aux gdbint.cps gdbint.fns gdbint.kys \ - gdbint.log gdbint.pgs gdbint.toc gdbint.tps gdbint.vrs - -# GDB INTERNALS MANUAL: info file -gdb-internals: gdbint.info - -gdbint.info: gdbint.texinfo - $(MAKEINFO) -o gdbint.info $(srcdir)/gdbint.texinfo - -stabs.info: stabs.texinfo - $(MAKEINFO) -o stabs.info $(srcdir)/stabs.texinfo - -# STABS DOCUMENTATION: TeX dvi file -stabs.dvi : stabs.texinfo - $(SET_TEXINPUTS) $(TEX) stabs.texinfo - $(TEXINDEX) stabs.?? - $(SET_TEXINPUTS) $(TEX) stabs.texinfo - rm -f stabs.?? stabs.aux stabs.cps stabs.fns stabs.kys \ - stabs.log stabs.pgs stabs.toc stabs.tps stabs.vrs - -stabs.ps: stabs.dvi - dvips -o stabs.ps stabs - -force: - -Makefile: $(srcdir)/Makefile.in $(host_makefile_frag) $(target_makefile_frag) - $(SHELL) ./config.status diff --git a/gnu/usr.bin/gdb/doc/a4rc.sed b/gnu/usr.bin/gdb/doc/a4rc.sed deleted file mode 100644 index 2292290..0000000 --- a/gnu/usr.bin/gdb/doc/a4rc.sed +++ /dev/null @@ -1,11 +0,0 @@ -/--- Papersize params:/,/--- end papersize params/c\ -%------- Papersize params:\ -%% A4 paper (297x210mm)\ -%%\ -\\totalwidth=297mm % total width of paper\ -\\totalheight=210mm % total height of paper\ -\\hmargin=5mm % horizontal margin width\ -\\vmargin=10mm % vertical margin width\ -\\secskip=.6pc % space between refcard secs\ -\\lskip=1pt % extra skip between \\sec entries\ -%------- end papersize params diff --git a/gnu/usr.bin/gdb/doc/config.status b/gnu/usr.bin/gdb/doc/config.status deleted file mode 100755 index 5d2c6dd..0000000 --- a/gnu/usr.bin/gdb/doc/config.status +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# This file was generated automatically by configure. Do not edit. -# This directory was configured as follows: -../../configure --host=i386-unknown-freebsd --target=i386-unknown-freebsd -norecursion -# diff --git a/gnu/usr.bin/gdb/doc/configure.in b/gnu/usr.bin/gdb/doc/configure.in deleted file mode 100644 index 1d2b47e..0000000 --- a/gnu/usr.bin/gdb/doc/configure.in +++ /dev/null @@ -1,7 +0,0 @@ -srcname="GDB doc" -srctrigger=gdb.texinfo -# per-host: -# per-target: - -files="" -links="" diff --git a/gnu/usr.bin/gdb/doc/gdb.info b/gnu/usr.bin/gdb/doc/gdb.info deleted file mode 100644 index c326469..0000000 --- a/gnu/usr.bin/gdb/doc/gdb.info +++ /dev/null @@ -1,213 +0,0 @@ -This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input -file gdb.texinfo. - -START-INFO-DIR-ENTRY -* Gdb:: The GNU debugger. -END-INFO-DIR-ENTRY - This file documents the GNU debugger GDB. - - This is Edition 4.09, August 1993, of `Debugging with GDB: the GNU -Source-Level Debugger' for GDB Version 4.11. - - Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software -Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the entire resulting derived work is distributed under the terms -of a permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions. - - -Indirect: -gdb.info-1: 992 -gdb.info-2: 50863 -gdb.info-3: 98423 -gdb.info-4: 145674 -gdb.info-5: 194815 -gdb.info-6: 244253 -gdb.info-7: 290141 -gdb.info-8: 335234 - -Tag Table: -(Indirect) -Node: Top992 -Node: Summary2561 -Node: Free Software3754 -Node: Contributors4492 -Node: New Features8199 -Node: Sample Session12215 -Node: Invocation19094 -Node: Invoking GDB19559 -Node: File Options21298 -Node: Mode Options24476 -Node: Quitting GDB26641 -Node: Shell Commands27359 -Node: Commands28106 -Node: Command Syntax28739 -Node: Completion30598 -Node: Help34666 -Node: Running38442 -Node: Compilation39426 -Node: Starting41224 -Node: Arguments44411 -Node: Environment45412 -Node: Working Directory48518 -Node: Input/Output49258 -Node: Attach50863 -Node: Kill Process53122 -Node: Process Information54097 -Node: Stopping55350 -Node: Breakpoints56423 -Node: Set Breaks58622 -Node: Set Watchpoints65221 -Node: Exception Handling66051 -Node: Delete Breaks68610 -Node: Disabling70238 -Node: Conditions72881 -Node: Break Commands77378 -Node: Breakpoint Menus80225 -Node: Error in Breakpoints81935 -Node: Continuing and Stepping82839 -Node: Signals89318 -Node: Stack92940 -Node: Frames94414 -Node: Backtrace96691 -Node: Selection98423 -Node: Frame Info100917 -Node: MIPS Stack102984 -Node: Source103857 -Node: List104806 -Node: Search108286 -Node: Source Path109085 -Node: Machine Code111763 -Node: Data114236 -Node: Expressions116111 -Node: Variables117793 -Node: Arrays120314 -Node: Output Formats122397 -Node: Memory124456 -Node: Auto Display128727 -Node: Print Settings132474 -Node: Value History140630 -Node: Convenience Vars143017 -Node: Registers145674 -Node: Floating Point Hardware150276 -Node: Languages150781 -Node: Setting151949 -Node: Manually152483 -Node: Automatically153663 -Node: Show154980 -Node: Checks155888 -Node: Type Checking157244 -Node: Range Checking159924 -Node: Support162265 -Node: C163185 -Node: C Operators164016 -Node: C Constants168071 -Node: Cplus expressions169974 -Node: C Defaults172597 -Node: C Checks173215 -Node: Debugging C173926 -Node: Debugging C plus plus174404 -Node: Modula-2176416 -Node: M2 Operators177308 -Node: Built-In Func/Proc180308 -Node: M2 Constants183051 -Node: M2 Defaults184640 -Node: Deviations185239 -Node: M2 Checks186330 -Node: M2 Scope187130 -Node: GDB/M2188142 -Node: Symbols189081 -Node: Altering194815 -Node: Assignment195797 -Node: Jumping197907 -Node: Signaling199914 -Node: Returning201034 -Node: Calling202226 -Node: Patching202700 -Node: GDB Files203782 -Node: Files204247 -Node: Symbol Errors214466 -Node: Targets218064 -Node: Active Targets218954 -Node: Target Commands220530 -Node: Remote223904 -Node: Remote Serial225315 -Node: Stub Contents227768 -Node: Bootstrapping229877 -Node: Debug Session233057 -Node: Protocol236218 -Node: Server239069 -Node: i960-Nindy Remote242748 -Node: Nindy Startup243568 -Node: Nindy Options244253 -Node: Nindy Reset245867 -Node: UDI29K Remote246251 -Node: EB29K Remote247172 -Node: Comms (EB29K)248006 -Node: gdb-EB29K251189 -Node: Remote Log252555 -Node: ST2000 Remote253030 -Node: VxWorks Remote254499 -Node: VxWorks Connection256224 -Node: VxWorks Download257150 -Node: VxWorks Attach258886 -Node: Hitachi Remote259281 -Node: MIPS Remote260790 -Node: Simulator262861 -Node: Controlling GDB264351 -Node: Prompt264962 -Node: Editing265571 -Node: History266338 -Node: Screen Size269024 -Node: Numbers270420 -Node: Messages/Warnings271538 -Node: Sequences274587 -Node: Define275147 -Node: Hooks277144 -Node: Command Files278547 -Node: Output280302 -Node: Emacs282714 -Node: GDB Bugs288669 -Node: Bug Criteria289387 -Node: Bug Reporting290141 -Node: Command Line Editing297342 -Node: Introduction and Notation297763 -Node: Readline Interaction298780 -Node: Readline Bare Essentials299914 -Node: Readline Movement Commands301417 -Node: Readline Killing Commands302303 -Node: Readline Arguments303941 -Node: Readline Init File304887 -Node: Readline Init Syntax305708 -Node: Commands For Moving309640 -Node: Commands For History310260 -Node: Commands For Text311330 -Node: Commands For Killing313046 -Node: Numeric Arguments314168 -Node: Commands For Completion314606 -Node: Miscellaneous Commands315325 -Node: Readline Vi Mode316077 -Node: Using History Interactively316784 -Node: History Interaction317141 -Node: Event Designators318189 -Node: Word Designators318828 -Node: Modifiers319724 -Node: Renamed Commands320469 -Node: Formatting Documentation322131 -Node: Installing GDB325465 -Node: Separate Objdir328945 -Node: Config Names331490 -Node: configure Options332918 -Node: Index335234 - -End Tag Table diff --git a/gnu/usr.bin/gdb/doc/gdb.info-1 b/gnu/usr.bin/gdb/doc/gdb.info-1 deleted file mode 100644 index a1d7120..0000000 --- a/gnu/usr.bin/gdb/doc/gdb.info-1 +++ /dev/null @@ -1,1304 +0,0 @@ -This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input -file gdb.texinfo. - -START-INFO-DIR-ENTRY -* Gdb:: The GNU debugger. -END-INFO-DIR-ENTRY - This file documents the GNU debugger GDB. - - This is Edition 4.09, August 1993, of `Debugging with GDB: the GNU -Source-Level Debugger' for GDB Version 4.11. - - Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software -Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the entire resulting derived work is distributed under the terms -of a permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions. - - -File: gdb.info, Node: Top, Next: Summary, Prev: (DIR), Up: (DIR) - -Debugging with GDB -****************** - - This file describes GDB, the GNU symbolic debugger. - - This is Edition 4.09, August 1993, for GDB Version 4.11. - -* Menu: - -* Summary:: Summary of GDB - -* New Features:: New features since GDB version 3.5 - -* Sample Session:: A sample GDB session - -* Invocation:: Getting in and out of GDB -* Commands:: GDB commands -* Running:: Running programs under GDB -* Stopping:: Stopping and continuing -* Stack:: Examining the stack -* Source:: Examining source files -* Data:: Examining data - -* Languages:: Using GDB with different languages - - -* Symbols:: Examining the symbol table -* Altering:: Altering execution -* GDB Files:: GDB files -* Targets:: Specifying a debugging target -* Controlling GDB:: Controlling GDB -* Sequences:: Canned sequences of commands - -* Emacs:: Using GDB under GNU Emacs - -* GDB Bugs:: Reporting bugs in GDB -* Command Line Editing:: Facilities of the readline library -* Using History Interactively:: - -* Renamed Commands:: - -* Formatting Documentation:: How to format and print GDB documentation -* Installing GDB:: Installing GDB - -* Index:: Index - - -File: gdb.info, Node: Summary, Next: New Features, Prev: Top, Up: Top - -Summary of GDB -************** - - The purpose of a debugger such as GDB is to allow you to see what is -going on "inside" another program while it executes--or what another -program was doing at the moment it crashed. - - GDB can do four main kinds of things (plus other things in support of -these) to help you catch bugs in the act: - - * Start your program, specifying anything that might affect its - behavior. - - * Make your program stop on specified conditions. - - * Examine what has happened, when your program has stopped. - - * Change things in your program, so you can experiment with - correcting the effects of one bug and go on to learn about another. - - You can use GDB to debug programs written in C, C++, and Modula-2. -G{No Value For "DBN"} can be used to debug programs written in Fortran, -although it does not yet support entering expressions, printing values, -etc. using Fortran syntax. It may be necessary to refer to some -variables with a trailing underscore. - -* Menu: - -* Free Software:: Freely redistributable software -* Contributors:: Contributors to GDB - - -File: gdb.info, Node: Free Software, Next: Contributors, Up: Summary - -Free software -============= - - GDB is "free software", protected by the GNU General Public License -(GPL). The GPL gives you the freedom to copy or adapt a licensed -program--but every person getting a copy also gets with it the freedom -to modify that copy (which means that they must get access to the -source code), and the freedom to distribute further copies. Typical -software companies use copyrights to limit your freedoms; the Free -Software Foundation uses the GPL to preserve these freedoms. - - Fundamentally, the General Public License is a license which says -that you have these freedoms and that you cannot take these freedoms -away from anyone else. - - -File: gdb.info, Node: Contributors, Prev: Free Software, Up: Summary - -Contributors to GDB -=================== - - Richard Stallman was the original author of GDB, and of many other -GNU programs. Many others have contributed to its development. This -section attempts to credit major contributors. One of the virtues of -free software is that everyone is free to contribute to it; with -regret, we cannot actually acknowledge everyone here. The file -`ChangeLog' in the GDB distribution approximates a blow-by-blow account. - - Changes much prior to version 2.0 are lost in the mists of time. - - *Plea:* Additions to this section are particularly welcome. If you - or your friends (or enemies, to be evenhanded) have been unfairly - omitted from this list, we would like to add your names! - - So that they may not regard their long labor as thankless, we -particularly thank those who shepherded GDB through major releases: Fred -Fish (releases 4.11, 4.10, 4.9), Stu Grossman and John Gilmore (releases -4.8, 4.7, 4.6, 4.5, 4.4), John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and -3.9); Jim Kingdon (releases 3.5, 3.4, 3.3); and Randy Smith (releases -3.2, 3.1, 3.0). As major maintainer of GDB for some period, each -contributed significantly to the structure, stability, and capabilities -of the entire debugger. - - Richard Stallman, assisted at various times by Peter TerMaat, Chris -Hanson, and Richard Mlynarik, handled releases through 2.8. - - Michael Tiemann is the author of most of the GNU C++ support in GDB, -with significant additional contributions from Per Bothner. James -Clark wrote the GNU C++ demangler. Early work on C++ was by Peter -TerMaat (who also did much general update work leading to release 3.0). - - GDB 4 uses the BFD subroutine library to examine multiple -object-file formats; BFD was a joint project of David V. -Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore. - - David Johnson wrote the original COFF support; Pace Willison did the -original support for encapsulated COFF. - - Adam de Boor and Bradley Davis contributed the ISI Optimum V support. -Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS -support. Jean-Daniel Fekete contributed Sun 386i support. Chris -Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki -Hasei contributed Sony/News OS 3 support. David Johnson contributed -Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support. -Keith Packard contributed NS32K support. Doug Rabson contributed Acorn -Risc Machine support. Chris Smith contributed Convex support (and -Fortran debugging). Jonathan Stone contributed Pyramid support. -Michael Tiemann contributed SPARC support. Tim Tucker contributed -support for the Gould NP1 and Gould Powernode. Pace Willison -contributed Intel 386 support. Jay Vosburgh contributed Symmetry -support. - - Rich Schaefer and Peter Schauer helped with support of SunOS shared -libraries. - - Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about -several machine instruction sets. - - Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped -develop remote debugging. Intel Corporation and Wind River Systems -contributed remote debugging modules for their products. - - Brian Fox is the author of the readline libraries providing -command-line editing and command history. - - Andrew Beers of SUNY Buffalo wrote the language-switching code, the -Modula-2 support, and contributed the Languages chapter of this manual. - - Fred Fish wrote most of the support for Unix System Vr4. He also -enhanced the command-completion support to cover C++ overloaded symbols. - - Hitachi America, Ltd. sponsored the support for Hitachi -microprocessors. - - -File: gdb.info, Node: New Features, Next: Sample Session, Prev: Summary, Up: Top - -New Features since GDB Version 3.5 -********************************** - -*Targets* - Using the new command `target', you can select at runtime whether - you are debugging local files, local processes, standalone systems - over a serial port, realtime systems over a TCP/IP connection, - etc. The command `load' can download programs into a remote - system. Serial stubs are available for Motorola 680x0, Intel - 80386, and Sparc remote systems; GDB also supports debugging - realtime processes running under VxWorks, using SunRPC Remote - Procedure Calls over TCP/IP to talk to a debugger stub on the - target system. Internally, GDB now uses a function vector to - mediate access to different targets; if you need to add your own - support for a remote protocol, this makes it much easier. - -*Watchpoints* - GDB now sports watchpoints as well as breakpoints. You can use a - watchpoint to stop execution whenever the value of an expression - changes, without having to predict a particular place in your - program where this may happen. - -*Wide Output* - Commands that issue wide output now insert newlines at places - designed to make the output more readable. - -*Object Code Formats* - GDB uses a new library called the Binary File Descriptor (BFD) - Library to permit it to switch dynamically, without - reconfiguration or recompilation, between different object-file - formats. Formats currently supported are COFF, ELF, a.out, Intel - 960 b.out, MIPS ECOFF, HPPA SOM (with stabs debugging), and - S-records; files may be read as .o files, archive libraries, or - core dumps. BFD is available as a subroutine library so that - other programs may take advantage of it, and the other GNU binary - utilities are being converted to use it. - -*Configuration and Ports* - Compile-time configuration (to select a particular architecture and - operating system) is much easier. The script `configure' now - allows you to configure GDB as either a native debugger or a - cross-debugger. *Note Installing GDB::, for details on how to - configure. - -*Interaction* - The user interface to the GDB control variables is simpler, and is - consolidated in two commands, `set' and `show'. Output lines are - now broken at readable places, rather than overflowing onto the - next line. You can suppress output of machine-level addresses, - displaying only source language information. - -*C++* - GDB now supports C++ multiple inheritance (if used with a GCC - version 2 compiler), and also has limited support for C++ exception - handling, with the commands `catch' and `info catch': GDB can - break when an exception is raised, before the stack is peeled back - to the exception handler's context. - -*Modula-2* - GDB now has preliminary support for the GNU Modula-2 compiler, - currently under development at the State University of New York at - Buffalo. Coordinated development of both GDB and the GNU Modula-2 - compiler will continue. Other Modula-2 compilers are currently - not supported, and attempting to debug programs compiled with them - will likely result in an error as the symbol table of the - executable is read in. - -*Command Rationalization* - Many GDB commands have been renamed to make them easier to remember - and use. In particular, the subcommands of `info' and - `show'/`set' are grouped to make the former refer to the state of - your program, and the latter refer to the state of GDB itself. - *Note Renamed Commands::, for details on what commands were - renamed. - -*Shared Libraries* - GDB 4 can debug programs and core files that use SunOS, SVR4, or - IBM RS/6000 shared libraries. - -*Reference Card* - GDB 4 has a reference card. *Note Formatting the Documentation: - Formatting Documentation, for instructions about how to print it. - - -File: gdb.info, Node: Sample Session, Next: Invocation, Prev: New Features, Up: Top - -A Sample GDB Session -******************** - - You can use this manual at your leisure to read all about GDB. -However, a handful of commands are enough to get started using the -debugger. This chapter illustrates those commands. - - One of the preliminary versions of GNU `m4' (a generic macro -processor) exhibits the following bug: sometimes, when we change its -quote strings from the default, the commands used to capture one macro -definition within another stop working. In the following short `m4' -session, we define a macro `foo' which expands to `0000'; we then use -the `m4' built-in `defn' to define `bar' as the same thing. However, -when we change the open quote string to `' and the close quote -string to `', the same procedure fails to define a new synonym -`baz': - - $ cd gnu/m4 - $ ./m4 - define(foo,0000) - - foo - 0000 - define(bar,defn(`foo')) - - bar - 0000 - changequote(,) - - define(baz,defn(foo)) - baz - C-d - m4: End of input: 0: fatal error: EOF in string - -Let us use GDB to try to see what is going on. - - $ gdb m4 - GDB is free software and you are welcome to distribute copies - of it under certain conditions; type "show copying" to see - the conditions. - There is absolutely no warranty for GDB; type "show warranty" - for details. - GDB 4.11, Copyright 1993 Free Software Foundation, Inc... - (gdb) - -GDB reads only enough symbol data to know where to find the rest when -needed; as a result, the first prompt comes up very quickly. We now -tell GDB to use a narrower display width than usual, so that examples -will fit in this manual. - - (gdb) set width 70 - -We need to see how the `m4' built-in `changequote' works. Having -looked at the source, we know the relevant subroutine is -`m4_changequote', so we set a breakpoint there with the GDB `break' -command. - - (gdb) break m4_changequote - Breakpoint 1 at 0x62f4: file builtin.c, line 879. - -Using the `run' command, we start `m4' running under GDB control; as -long as control does not reach the `m4_changequote' subroutine, the -program runs as usual: - - (gdb) run - Starting program: /work/Editorial/gdb/gnu/m4/m4 - define(foo,0000) - - foo - 0000 - -To trigger the breakpoint, we call `changequote'. GDB suspends -execution of `m4', displaying information about the context where it -stops. - - changequote(,) - - Breakpoint 1, m4_changequote (argc=3, argv=0x33c70) - at builtin.c:879 - 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3)) - -Now we use the command `n' (`next') to advance execution to the next -line of the current function. - - (gdb) n - 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\ - : nil, - -`set_quotes' looks like a promising subroutine. We can go into it by -using the command `s' (`step') instead of `next'. `step' goes to the -next line to be executed in *any* subroutine, so it steps into -`set_quotes'. - - (gdb) s - set_quotes (lq=0x34c78 "", rq=0x34c88 "") - at input.c:530 - 530 if (lquote != def_lquote) - -The display that shows the subroutine where `m4' is now suspended (and -its arguments) is called a stack frame display. It shows a summary of -the stack. We can use the `backtrace' command (which can also be -spelled `bt'), to see where we are in the stack as a whole: the -`backtrace' command displays a stack frame for each active subroutine. - - (gdb) bt - #0 set_quotes (lq=0x34c78 "", rq=0x34c88 "") - at input.c:530 - #1 0x6344 in m4_changequote (argc=3, argv=0x33c70) - at builtin.c:882 - #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242 - #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30) - at macro.c:71 - #4 0x79dc in expand_input () at macro.c:40 - #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195 - -We will step through a few more lines to see what happens. The first -two times, we can use `s'; the next two times we use `n' to avoid -falling into the `xstrdup' subroutine. - - (gdb) s - 0x3b5c 532 if (rquote != def_rquote) - (gdb) s - 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \ - def_lquote : xstrdup(lq); - (gdb) n - 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ - : xstrdup(rq); - (gdb) n - 538 len_lquote = strlen(rquote); - -The last line displayed looks a little odd; we can examine the variables -`lquote' and `rquote' to see if they are in fact the new left and right -quotes we specified. We use the command `p' (`print') to see their -values. - - (gdb) p lquote - $1 = 0x35d40 "" - (gdb) p rquote - $2 = 0x35d50 "" - -`lquote' and `rquote' are indeed the new left and right quotes. To -look at some context, we can display ten lines of source surrounding -the current line with the `l' (`list') command. - - (gdb) l - 533 xfree(rquote); - 534 - 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\ - : xstrdup (lq); - 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\ - : xstrdup (rq); - 537 - 538 len_lquote = strlen(rquote); - 539 len_rquote = strlen(lquote); - 540 } - 541 - 542 void - -Let us step past the two lines that set `len_lquote' and `len_rquote', -and then examine the values of those variables. - - (gdb) n - 539 len_rquote = strlen(lquote); - (gdb) n - 540 } - (gdb) p len_lquote - $3 = 9 - (gdb) p len_rquote - $4 = 7 - -That certainly looks wrong, assuming `len_lquote' and `len_rquote' are -meant to be the lengths of `lquote' and `rquote' respectively. We can -set them to better values using the `p' command, since it can print the -value of any expression--and that expression can include subroutine -calls and assignments. - - (gdb) p len_lquote=strlen(lquote) - $5 = 7 - (gdb) p len_rquote=strlen(rquote) - $6 = 9 - -Is that enough to fix the problem of using the new quotes with the `m4' -built-in `defn'? We can allow `m4' to continue executing with the `c' -(`continue') command, and then try the example that caused trouble -initially: - - (gdb) c - Continuing. - - define(baz,defn(foo)) - - baz - 0000 - -Success! The new quotes now work just as well as the default ones. The -problem seems to have been just the two typos defining the wrong -lengths. We allow `m4' exit by giving it an EOF as input: - - C-d - Program exited normally. - -The message `Program exited normally.' is from GDB; it indicates `m4' -has finished executing. We can end our GDB session with the GDB `quit' -command. - - (gdb) quit - - -File: gdb.info, Node: Invocation, Next: Commands, Prev: Sample Session, Up: Top - -Getting In and Out of GDB -************************* - - This chapter discusses how to start GDB, and how to get out of it. -(The essentials: type `gdb' to start GDB, and type `quit' or `C-d' to -exit.) - -* Menu: - -* Invoking GDB:: How to start GDB -* Quitting GDB:: How to quit GDB -* Shell Commands:: How to use shell commands inside GDB - - -File: gdb.info, Node: Invoking GDB, Next: Quitting GDB, Up: Invocation - -Invoking GDB -============ - - Invoke GDB by running the program `gdb'. Once started, GDB reads -commands from the terminal until you tell it to exit. - - You can also run `gdb' with a variety of arguments and options, to -specify more of your debugging environment at the outset. - - The command-line options described here are designed to cover a -variety of situations; in some environments, some of these options may -effectively be unavailable. - - The most usual way to start GDB is with one argument, specifying an -executable program: - - gdb PROGRAM - -You can also start with both an executable program and a core file -specified: - - gdb PROGRAM CORE - - You can, instead, specify a process ID as a second argument, if you -want to debug a running process: - - gdb PROGRAM 1234 - -would attach GDB to process `1234' (unless you also have a file named -`1234'; GDB does check for a core file first). - - Taking advantage of the second command-line argument requires a -fairly complete operating system; when you use GDB as a remote debugger -attached to a bare board, there may not be any notion of "process", and -there is often no way to get a core dump. - -You can further control how GDB starts up by using command-line -options. GDB itself can remind you of the options available. - -Type - - gdb -help - -to display all available options and briefly describe their use (`gdb --h' is a shorter equivalent). - - All options and command line arguments you give are processed in -sequential order. The order makes a difference when the `-x' option is -used. - -* Menu: - - - -* File Options:: Choosing files -* Mode Options:: Choosing modes - - -File: gdb.info, Node: File Options, Next: Mode Options, Up: Invoking GDB - -Choosing files --------------- - - When GDB starts, it reads any arguments other than options as -specifying an executable file and core file (or process ID). This is -the same as if the arguments were specified by the `-se' and `-c' -options respectively. (GDB reads the first argument that does not have -an associated option flag as equivalent to the `-se' option followed by -that argument; and the second argument that does not have an associated -option flag, if any, as equivalent to the `-c' option followed by that -argument.) - - Many options have both long and short forms; both are shown in the -following list. GDB also recognizes the long forms if you truncate -them, so long as enough of the option is present to be unambiguous. -(If you prefer, you can flag option arguments with `--' rather than -`-', though we illustrate the more usual convention.) - -`-symbols FILE' -`-s FILE' - Read symbol table from file FILE. - -`-exec FILE' -`-e FILE' - Use file FILE as the executable file to execute when appropriate, - and for examining pure data in conjunction with a core dump. - -`-se FILE' - Read symbol table from file FILE and use it as the executable file. - -`-core FILE' -`-c FILE' - Use file FILE as a core dump to examine. - -`-c NUMBER' - Connect to process ID NUMBER, as with the `attach' command (unless - there is a file in core-dump format named NUMBER, in which case - `-c' specifies that file as a core dump to read). - -`-command FILE' -`-x FILE' - Execute GDB commands from file FILE. *Note Command files: Command - Files. - -`-directory DIRECTORY' -`-d DIRECTORY' - Add DIRECTORY to the path to search for source files. - -`-m' -`-mapped' - *Warning: this option depends on operating system facilities that - are not supported on all systems.* - If memory-mapped files are available on your system through the - `mmap' system call, you can use this option to have GDB write the - symbols from your program into a reusable file in the current - directory. If the program you are debugging is called - `/tmp/fred', the mapped symbol file will be `./fred.syms'. Future - GDB debugging sessions will notice the presence of this file, and - will quickly map in symbol information from it, rather than reading - the symbol table from the executable program. - - The `.syms' file is specific to the host machine where GDB is run. - It holds an exact image of the internal GDB symbol table. It - cannot be shared across multiple host platforms. - -`-r' -`-readnow' - Read each symbol file's entire symbol table immediately, rather - than the default, which is to read it incrementally as it is - needed. This makes startup slower, but makes future operations - faster. - - The `-mapped' and `-readnow' options are typically combined in order -to build a `.syms' file that contains complete symbol information. -(*Note Commands to specify files: Files, for information on `.syms' -files.) A simple GDB invocation to do nothing but build a `.syms' file -for future use is: - - gdb -batch -nx -mapped -readnow programname - - -File: gdb.info, Node: Mode Options, Prev: File Options, Up: Invoking GDB - -Choosing modes --------------- - - You can run GDB in various alternative modes--for example, in batch -mode or quiet mode. - -`-nx' -`-n' - Do not execute commands from any initialization files (normally - called `.gdbinit'). Normally, the commands in these files are - executed after all the command options and arguments have been - processed. *Note Command files: Command Files. - -`-quiet' -`-q' - "Quiet". Do not print the introductory and copyright messages. - These messages are also suppressed in batch mode. - -`-batch' - Run in batch mode. Exit with status `0' after processing all the - command files specified with `-x' (and all commands from - initialization files, if not inhibited with `-n'). Exit with - nonzero status if an error occurs in executing the GDB commands in - the command files. - - Batch mode may be useful for running GDB as a filter, for example - to download and run a program on another computer; in order to - make this more useful, the message - - Program exited normally. - - (which is ordinarily issued whenever a program running under GDB - control terminates) is not issued when running in batch mode. - -`-cd DIRECTORY' - Run GDB using DIRECTORY as its working directory, instead of the - current directory. - -`-fullname' -`-f' - Emacs sets this option when it runs GDB as a subprocess. It tells - GDB to output the full file name and line number in a standard, - recognizable fashion each time a stack frame is displayed (which - includes each time your program stops). This recognizable format - looks like two `\032' characters, followed by the file name, line - number and character position separated by colons, and a newline. - The Emacs-to-GDB interface program uses the two `\032' characters - as a signal to display the source code for the frame. - -`-b BPS' - Set the line speed (baud rate or bits per second) of any serial - interface used by GDB for remote debugging. - -`-tty DEVICE' - Run using DEVICE for your program's standard input and output. - - -File: gdb.info, Node: Quitting GDB, Next: Shell Commands, Prev: Invoking GDB, Up: Invocation - -Quitting GDB -============ - -`quit' - To exit GDB, use the `quit' command (abbreviated `q'), or type an - end-of-file character (usually `C-d'). - - An interrupt (often `C-c') will not exit from GDB, but rather will -terminate the action of any GDB command that is in progress and return -to GDB command level. It is safe to type the interrupt character at -any time because GDB does not allow it to take effect until a time when -it is safe. - - If you have been using GDB to control an attached process or device, -you can release it with the `detach' command (*note Debugging an -already-running process: Attach.). - - -File: gdb.info, Node: Shell Commands, Prev: Quitting GDB, Up: Invocation - -Shell commands -============== - - If you need to execute occasional shell commands during your -debugging session, there is no need to leave or suspend GDB; you can -just use the `shell' command. - -`shell COMMAND STRING' - Invoke a the standard shell to execute COMMAND STRING. If it - exists, the environment variable `SHELL' determines which shell to - run. Otherwise GDB uses `/bin/sh'. - - The utility `make' is often needed in development environments. You -do not have to use the `shell' command for this purpose in GDB: - -`make MAKE-ARGS' - Execute the `make' program with the specified arguments. This is - equivalent to `shell make MAKE-ARGS'. - - -File: gdb.info, Node: Commands, Next: Running, Prev: Invocation, Up: Top - -GDB Commands -************ - - You can abbreviate a GDB command to the first few letters of the -command name, if that abbreviation is unambiguous; and you can repeat -certain GDB commands by typing just RET. You can also use the TAB key -to get GDB to fill out the rest of a word in a command (or to show you -the alternatives available, if there is more than one possibility). - -* Menu: - -* Command Syntax:: How to give commands to GDB -* Completion:: Command completion -* Help:: How to ask GDB for help - - -File: gdb.info, Node: Command Syntax, Next: Completion, Up: Commands - -Command syntax -============== - - A GDB command is a single line of input. There is no limit on how -long it can be. It starts with a command name, which is followed by -arguments whose meaning depends on the command name. For example, the -command `step' accepts an argument which is the number of times to -step, as in `step 5'. You can also use the `step' command with no -arguments. Some command names do not allow any arguments. - - GDB command names may always be truncated if that abbreviation is -unambiguous. Other possible command abbreviations are listed in the -documentation for individual commands. In some cases, even ambiguous -abbreviations are allowed; for example, `s' is specially defined as -equivalent to `step' even though there are other commands whose names -start with `s'. You can test abbreviations by using them as arguments -to the `help' command. - - A blank line as input to GDB (typing just RET) means to repeat the -previous command. Certain commands (for example, `run') will not repeat -this way; these are commands for which unintentional repetition might -cause trouble and which you are unlikely to want to repeat. - - The `list' and `x' commands, when you repeat them with RET, -construct new arguments rather than repeating exactly as typed. This -permits easy scanning of source or memory. - - GDB can also use RET in another way: to partition lengthy output, in -a way similar to the common utility `more' (*note Screen size: Screen -Size.). Since it is easy to press one RET too many in this situation, -GDB disables command repetition after any command that generates this -sort of display. - - Any text from a `#' to the end of the line is a comment; it does -nothing. This is useful mainly in command files (*note Command files: -Command Files.). - - -File: gdb.info, Node: Completion, Next: Help, Prev: Command Syntax, Up: Commands - -Command completion -================== - - GDB can fill in the rest of a word in a command for you, if there is -only one possibility; it can also show you what the valid possibilities -are for the next word in a command, at any time. This works for GDB -commands, GDB subcommands, and the names of symbols in your program. - - Press the TAB key whenever you want GDB to fill out the rest of a -word. If there is only one possibility, GDB will fill in the word, and -wait for you to finish the command (or press RET to enter it). For -example, if you type - - (gdb) info bre TAB - -GDB fills in the rest of the word `breakpoints', since that is the only -`info' subcommand beginning with `bre': - - (gdb) info breakpoints - -You can either press RET at this point, to run the `info breakpoints' -command, or backspace and enter something else, if `breakpoints' does -not look like the command you expected. (If you were sure you wanted -`info breakpoints' in the first place, you might as well just type RET -immediately after `info bre', to exploit command abbreviations rather -than command completion). - - If there is more than one possibility for the next word when you -press TAB, GDB will sound a bell. You can either supply more -characters and try again, or just press TAB a second time, and GDB will -display all the possible completions for that word. For example, you -might want to set a breakpoint on a subroutine whose name begins with -`make_', but when you type `b make_TAB' GDB just sounds the bell. -Typing TAB again will display all the function names in your program -that begin with those characters, for example: - - (gdb) b make_ TAB -GDB sounds bell; press TAB again, to see: - make_a_section_from_file make_environ - make_abs_section make_function_type - make_blockvector make_pointer_type - make_cleanup make_reference_type - make_command make_symbol_completion_list - (gdb) b make_ - -After displaying the available possibilities, GDB copies your partial -input (`b make_' in the example) so you can finish the command. - - If you just want to see the list of alternatives in the first place, -you can press `M-?' rather than pressing TAB twice. `M-?' means `META -?'. You can type this either by holding down a key designated as the -META shift on your keyboard (if there is one) while typing `?', or as -ESC followed by `?'. - - Sometimes the string you need, while logically a "word", may contain -parentheses or other characters that GDB normally excludes from its -notion of a word. To permit word completion to work in this situation, -you may enclose words in `'' (single quote marks) in GDB commands. - - The most likely situation where you might need this is in typing the -name of a C++ function. This is because C++ allows function overloading -(multiple definitions of the same function, distinguished by argument -type). For example, when you want to set a breakpoint you may need to -distinguish whether you mean the version of `name' that takes an `int' -parameter, `name(int)', or the version that takes a `float' parameter, -`name(float)'. To use the word-completion facilities in this -situation, type a single quote `'' at the beginning of the function -name. This alerts GDB that it may need to consider more information -than usual when you press TAB or `M-?' to request word completion: - - (gdb) b 'bubble( M-? - bubble(double,double) bubble(int,int) - (gdb) b 'bubble( - - In some cases, GDB can tell that completing a name will require -quotes. When this happens, GDB will insert the quote for you (while -completing as much as it can) if you do not type the quote in the first -place: - - (gdb) b bub TAB -GDB alters your input line to the following, and rings a bell: - (gdb) b 'bubble( - -In general, GDB can tell that a quote is needed (and inserts it) if you -have not yet started typing the argument list when you ask for -completion on an overloaded symbol. - - -File: gdb.info, Node: Help, Prev: Completion, Up: Commands - -Getting help -============ - - You can always ask GDB itself for information on its commands, using -the command `help'. - -`help' -`h' - You can use `help' (abbreviated `h') with no arguments to display - a short list of named classes of commands: - - (gdb) help - List of classes of commands: - - running -- Running the program - stack -- Examining the stack - data -- Examining data - breakpoints -- Making program stop at certain points - files -- Specifying and examining files - status -- Status inquiries - support -- Support facilities - user-defined -- User-defined commands - aliases -- Aliases of other commands - obscure -- Obscure features - - Type "help" followed by a class name for a list of - commands in that class. - Type "help" followed by command name for full - documentation. - Command name abbreviations are allowed if unambiguous. - (gdb) - -`help CLASS' - Using one of the general help classes as an argument, you can get a - list of the individual commands in that class. For example, here - is the help display for the class `status': - - (gdb) help status - Status inquiries. - - List of commands: - - show -- Generic command for showing things set - with "set" - info -- Generic command for printing status - - Type "help" followed by command name for full - documentation. - Command name abbreviations are allowed if unambiguous. - (gdb) - -`help COMMAND' - With a command name as `help' argument, GDB will display a short - paragraph on how to use that command. - - In addition to `help', you can use the GDB commands `info' and -`show' to inquire about the state of your program, or the state of GDB -itself. Each command supports many topics of inquiry; this manual -introduces each of them in the appropriate context. The listings under -`info' and under `show' in the Index point to all the sub-commands. -*Note Index::. - -`info' - This command (abbreviated `i') is for describing the state of your - program. For example, you can list the arguments given to your - program with `info args', list the registers currently in use with - `info registers', or list the breakpoints you have set with `info - breakpoints'. You can get a complete list of the `info' - sub-commands with `help info'. - -`show' - In contrast, `show' is for describing the state of GDB itself. - You can change most of the things you can `show', by using the - related command `set'; for example, you can control what number - system is used for displays with `set radix', or simply inquire - which is currently in use with `show radix'. - - To display all the settable parameters and their current values, - you can use `show' with no arguments; you may also use `info set'. - Both commands produce the same display. - - Here are three miscellaneous `show' subcommands, all of which are -exceptional in lacking corresponding `set' commands: - -`show version' - Show what version of GDB is running. You should include this - information in GDB bug-reports. If multiple versions of GDB are in - use at your site, you may occasionally want to determine which - version of GDB you are running; as GDB evolves, new commands are - introduced, and old ones may wither away. The version number is - also announced when you start GDB. - -`show copying' - Display information about permission for copying GDB. - -`show warranty' - Display the GNU "NO WARRANTY" statement. - - -File: gdb.info, Node: Running, Next: Stopping, Prev: Commands, Up: Top - -Running Programs Under GDB -************************** - - When you run a program under GDB, you must first generate debugging -information when you compile it. You may start it with its arguments, -if any, in an environment of your choice. You may redirect your -program's input and output, debug an already running process, or kill a -child process. - -* Menu: - -* Compilation:: Compiling for debugging -* Starting:: Starting your program - -* Arguments:: Your program's arguments -* Environment:: Your program's environment -* Working Directory:: Your program's working directory -* Input/Output:: Your program's input and output -* Attach:: Debugging an already-running process -* Kill Process:: Killing the child process -* Process Information:: Additional process information - - -File: gdb.info, Node: Compilation, Next: Starting, Up: Running - -Compiling for debugging -======================= - - In order to debug a program effectively, you need to generate -debugging information when you compile it. This debugging information -is stored in the object file; it describes the data type of each -variable or function and the correspondence between source line numbers -and addresses in the executable code. - - To request debugging information, specify the `-g' option when you -run the compiler. - - Many C compilers are unable to handle the `-g' and `-O' options -together. Using those compilers, you cannot generate optimized -executables containing debugging information. - - GCC, the GNU C compiler, supports `-g' with or without `-O', making -it possible to debug optimized code. We recommend that you *always* -use `-g' whenever you compile a program. You may think your program is -correct, but there is no sense in pushing your luck. - - When you debug a program compiled with `-g -O', remember that the -optimizer is rearranging your code; the debugger will show you what is -really there. Do not be too surprised when the execution path does not -exactly match your source file! An extreme example: if you define a -variable, but never use it, GDB will never see that variable--because -the compiler optimizes it out of existence. - - Some things do not work as well with `-g -O' as with just `-g', -particularly on machines with instruction scheduling. If in doubt, -recompile with `-g' alone, and if this fixes the problem, please report -it as a bug (including a test case!). - - Older versions of the GNU C compiler permitted a variant option -`-gg' for debugging information. GDB no longer supports this format; -if your GNU C compiler has this option, do not use it. - - -File: gdb.info, Node: Starting, Next: Arguments, Prev: Compilation, Up: Running - -Starting your program -===================== - -`run' -`r' - Use the `run' command to start your program under GDB. You must - first specify the program name (except on VxWorks) with an - argument to GDB (*note Getting In and Out of GDB: Invocation.), or - by using the `file' or `exec-file' command (*note Commands to - specify files: Files.). - - If you are running your program in an execution environment that -supports processes, `run' creates an inferior process and makes that -process run your program. (In environments without processes, `run' -jumps to the start of your program.) - - The execution of a program is affected by certain information it -receives from its superior. GDB provides ways to specify this -information, which you must do *before* starting your program. (You -can change it after starting your program, but such changes will only -affect your program the next time you start it.) This information may -be divided into four categories: - -The *arguments.* - Specify the arguments to give your program as the arguments of the - `run' command. If a shell is available on your target, the shell - is used to pass the arguments, so that you may use normal - conventions (such as wildcard expansion or variable substitution) - in describing the arguments. In Unix systems, you can control - which shell is used with the `SHELL' environment variable. *Note - Your program's arguments: Arguments. - -The *environment.* - Your program normally inherits its environment from GDB, but you - can use the GDB commands `set environment' and `unset environment' - to change parts of the environment that will be given to your - program. *Note Your program's environment: Environment. - -The *working directory.* - Your program inherits its working directory from GDB. You can set - the GDB working directory with the `cd' command in GDB. *Note - Your program's working directory: Working Directory. - -The *standard input and output.* - Your program normally uses the same device for standard input and - standard output as GDB is using. You can redirect input and output - in the `run' command line, or you can use the `tty' command to set - a different device for your program. *Note Your program's input - and output: Input/Output. - - *Warning:* While input and output redirection work, you cannot use - pipes to pass the output of the program you are debugging to - another program; if you attempt this, GDB is likely to wind up - debugging the wrong program. - - When you issue the `run' command, your program begins to execute -immediately. *Note Stopping and continuing: Stopping, for discussion -of how to arrange for your program to stop. Once your program has -stopped, you may call functions in your program, using the `print' or -`call' commands. *Note Examining Data: Data. - - If the modification time of your symbol file has changed since the -last time GDB read its symbols, GDB will discard its symbol table and -re-read it. When it does this, GDB tries to retain your current -breakpoints. - - -File: gdb.info, Node: Arguments, Next: Environment, Prev: Starting, Up: Running - -Your program's arguments -======================== - - The arguments to your program can be specified by the arguments of -the `run' command. They are passed to a shell, which expands wildcard -characters and performs redirection of I/O, and thence to your program. -Your `SHELL' environment variable (if it exists) specifies what shell -GDB if you do not define `SHELL', GDB uses `/bin/sh'. - - `run' with no arguments uses the same arguments used by the previous -`run', or those set by the `set args' command. - -`set args' - Specify the arguments to be used the next time your program is - run. If `set args' has no arguments, `run' will execute your - program with no arguments. Once you have run your program with - arguments, using `set args' before the next `run' is the only way - to run it again without arguments. - -`show args' - Show the arguments to give your program when it is started. - - -File: gdb.info, Node: Environment, Next: Working Directory, Prev: Arguments, Up: Running - -Your program's environment -========================== - - The "environment" consists of a set of environment variables and -their values. Environment variables conventionally record such things -as your user name, your home directory, your terminal type, and your -search path for programs to run. Usually you set up environment -variables with the shell and they are inherited by all the other -programs you run. When debugging, it can be useful to try running your -program with a modified environment without having to start GDB over -again. - -`path DIRECTORY' - Add DIRECTORY to the front of the `PATH' environment variable (the - search path for executables), for both GDB and your program. You - may specify several directory names, separated by `:' or - whitespace. If DIRECTORY is already in the path, it is moved to - the front, so it will be searched sooner. - - You can use the string `$cwd' to refer to whatever is the current - working directory at the time GDB searches the path. If you use - `.' instead, it refers to the directory where you executed the - `path' command. GDB replaces `.' in the DIRECTORY argument (with - the current path) before adding DIRECTORY to the search path. - -`show paths' - Display the list of search paths for executables (the `PATH' - environment variable). - -`show environment [VARNAME]' - Print the value of environment variable VARNAME to be given to - your program when it starts. If you do not supply VARNAME, print - the names and values of all environment variables to be given to - your program. You can abbreviate `environment' as `env'. - -`set environment VARNAME [=] VALUE' - Set environment variable VARNAME to VALUE. The value changes for - your program only, not for GDB itself. VALUE may be any string; - the values of environment variables are just strings, and any - interpretation is supplied by your program itself. The VALUE - parameter is optional; if it is eliminated, the variable is set to - a null value. - - For example, this command: - - set env USER = foo - - tells a Unix program, when subsequently run, that its user is named - `foo'. (The spaces around `=' are used for clarity here; they are - not actually required.) - -`unset environment VARNAME' - Remove variable VARNAME from the environment to be passed to your - program. This is different from `set env VARNAME ='; `unset - environment' removes the variable from the environment, rather - than assigning it an empty value. - - *Warning:* GDB runs your program using the shell indicated by your -`SHELL' environment variable if it exists (or `/bin/sh' if not). If -your `SHELL' variable names a shell that runs an initialization -file--such as `.cshrc' for C-shell, or `.bashrc' for BASH--any -variables you set in that file will affect your program. You may wish -to move setting of environment variables to files that are only run -when you sign on, such as `.login' or `.profile'. - - -File: gdb.info, Node: Working Directory, Next: Input/Output, Prev: Environment, Up: Running - -Your program's working directory -================================ - - Each time you start your program with `run', it inherits its working -directory from the current working directory of GDB. The GDB working -directory is initially whatever it inherited from its parent process -(typically the shell), but you can specify a new working directory in -GDB with the `cd' command. - - The GDB working directory also serves as a default for the commands -that specify files for GDB to operate on. *Note Commands to specify -files: Files. - -`cd DIRECTORY' - Set the GDB working directory to DIRECTORY. - -`pwd' - Print the GDB working directory. - - -File: gdb.info, Node: Input/Output, Next: Attach, Prev: Working Directory, Up: Running - -Your program's input and output -=============================== - - By default, the program you run under GDB does input and output to -the same terminal that GDB uses. GDB switches the terminal to its own -terminal modes to interact with you, but it records the terminal modes -your program was using and switches back to them when you continue -running your program. - -`info terminal' - Displays information recorded by GDB about the terminal modes your - program is using. - - You can redirect your program's input and/or output using shell -redirection with the `run' command. For example, - - run > outfile - -starts your program, diverting its output to the file `outfile'. - - Another way to specify where your program should do input and output -is with the `tty' command. This command accepts a file name as -argument, and causes this file to be the default for future `run' -commands. It also resets the controlling terminal for the child -process, for future `run' commands. For example, - - tty /dev/ttyb - -directs that processes started with subsequent `run' commands default -to do input and output on the terminal `/dev/ttyb' and have that as -their controlling terminal. - - An explicit redirection in `run' overrides the `tty' command's -effect on the input/output device, but not its effect on the controlling -terminal. - - When you use the `tty' command or redirect input in the `run' -command, only the input *for your program* is affected. The input for -GDB still comes from your terminal. - diff --git a/gnu/usr.bin/gdb/doc/gdb.info-2 b/gnu/usr.bin/gdb/doc/gdb.info-2 deleted file mode 100644 index e8be2fa..0000000 --- a/gnu/usr.bin/gdb/doc/gdb.info-2 +++ /dev/null @@ -1,1165 +0,0 @@ -This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input -file gdb.texinfo. - -START-INFO-DIR-ENTRY -* Gdb:: The GNU debugger. -END-INFO-DIR-ENTRY - This file documents the GNU debugger GDB. - - This is Edition 4.09, August 1993, of `Debugging with GDB: the GNU -Source-Level Debugger' for GDB Version 4.11. - - Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software -Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the entire resulting derived work is distributed under the terms -of a permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions. - - -File: gdb.info, Node: Attach, Next: Kill Process, Prev: Input/Output, Up: Running - -Debugging an already-running process -==================================== - -`attach PROCESS-ID' - This command attaches to a running process--one that was started - outside GDB. (`info files' will show your active targets.) The - command takes as argument a process ID. The usual way to find out - the process-id of a Unix process is with the `ps' utility, or with - the `jobs -l' shell command. - - `attach' will not repeat if you press RET a second time after - executing the command. - - To use `attach', your program must be running in an environment -which supports processes; for example, `attach' does not work for -programs on bare-board targets that lack an operating system. You must -also have permission to send the process a signal. - - When using `attach', you should first use the `file' command to -specify the program running in the process and load its symbol table. -*Note Commands to Specify Files: Files. - - The first thing GDB does after arranging to debug the specified -process is to stop it. You can examine and modify an attached process -with all the GDB commands that are ordinarily available when you start -processes with `run'. You can insert breakpoints; you can step and -continue; you can modify storage. If you would rather the process -continue running, you may use the `continue' command after attaching -GDB to the process. - -`detach' - When you have finished debugging the attached process, you can use - the `detach' command to release it from GDB control. Detaching - the process continues its execution. After the `detach' command, - that process and GDB become completely independent once more, and - you are ready to `attach' another process or start one with `run'. - `detach' will not repeat if you press RET again after executing - the command. - - If you exit GDB or use the `run' command while you have an attached -process, you kill that process. By default, you will be asked for -confirmation if you try to do either of these things; you can control -whether or not you need to confirm by using the `set confirm' command -(*note Optional warnings and messages: Messages/Warnings.). - - -File: gdb.info, Node: Kill Process, Next: Process Information, Prev: Attach, Up: Running - -Killing the child process -========================= - -`kill' - Kill the child process in which your program is running under GDB. - - This command is useful if you wish to debug a core dump instead of a -running process. GDB ignores any core dump file while your program is -running. - - On some operating systems, a program cannot be executed outside GDB -while you have breakpoints set on it inside GDB. You can use the -`kill' command in this situation to permit running your program outside -the debugger. - - The `kill' command is also useful if you wish to recompile and -relink your program, since on many systems it is impossible to modify an -executable file while it is running in a process. In this case, when -you next type `run', GDB will notice that the file has changed, and -will re-read the symbol table (while trying to preserve your current -breakpoint settings). - - -File: gdb.info, Node: Process Information, Prev: Kill Process, Up: Running - -Additional process information -============================== - - Some operating systems provide a facility called `/proc' that can be -used to examine the image of a running process using file-system -subroutines. If GDB is configured for an operating system with this -facility, the command `info proc' is available to report on several -kinds of information about the process running your program. - -`info proc' - Summarize available information about the process. - -`info proc mappings' - Report on the address ranges accessible in the program, with - information on whether your program may read, write, or execute - each range. - -`info proc times' - Starting time, user CPU time, and system CPU time for your program - and its children. - -`info proc id' - Report on the process IDs related to your program: its own process - ID, the ID of its parent, the process group ID, and the session ID. - -`info proc status' - General information on the state of the process. If the process is - stopped, this report includes the reason for stopping, and any - signal received. - -`info proc all' - Show all the above information about the process. - - -File: gdb.info, Node: Stopping, Next: Stack, Prev: Running, Up: Top - -Stopping and Continuing -*********************** - - The principal purposes of using a debugger are so that you can stop -your program before it terminates; or so that, if your program runs into -trouble, you can investigate and find out why. - - Inside GDB, your program may stop for any of several reasons, such as -a signal, a breakpoint, or reaching a new line after a GDB command such -as `step'. You may then examine and change variables, set new -breakpoints or remove old ones, and then continue execution. Usually, -the messages shown by GDB provide ample explanation of the status of -your program--but you can also explicitly request this information at -any time. - -`info program' - Display information about the status of your program: whether it is - running or not, what process it is, and why it stopped. - -* Menu: - - -* Breakpoints:: Breakpoints, watchpoints, and exceptions - - -* Continuing and Stepping:: Resuming execution - -* Signals:: Signals - - -File: gdb.info, Node: Breakpoints, Next: Continuing and Stepping, Up: Stopping - -Breakpoints, watchpoints, and exceptions -======================================== - - A "breakpoint" makes your program stop whenever a certain point in -the program is reached. For each breakpoint, you can add various -conditions to control in finer detail whether your program will stop. -You can set breakpoints with the `break' command and its variants -(*note Setting breakpoints: Set Breaks.), to specify the place where -your program should stop by line number, function name or exact address -in the program. In languages with exception handling (such as GNU -C++), you can also set breakpoints where an exception is raised (*note -Breakpoints and exceptions: Exception Handling.). - - A "watchpoint" is a special breakpoint that stops your program when -the value of an expression changes. You must use a different command -to set watchpoints (*note Setting watchpoints: Set Watchpoints.), but -aside from that, you can manage a watchpoint like any other breakpoint: -you enable, disable, and delete both breakpoints and watchpoints using -the same commands. - - You can arrange to have values from your program displayed -automatically whenever GDB stops at a breakpoint. *Note Automatic -display: Auto Display. - - GDB assigns a number to each breakpoint or watchpoint when you -create it; these numbers are successive integers starting with one. In -many of the commands for controlling various features of breakpoints you -use the breakpoint number to say which breakpoint you want to change. -Each breakpoint may be "enabled" or "disabled"; if disabled, it has no -effect on your program until you enable it again. - -* Menu: - -* Set Breaks:: Setting breakpoints -* Set Watchpoints:: Setting watchpoints - -* Exception Handling:: Breakpoints and exceptions - -* Delete Breaks:: Deleting breakpoints -* Disabling:: Disabling breakpoints -* Conditions:: Break conditions -* Break Commands:: Breakpoint command lists - -* Breakpoint Menus:: Breakpoint menus - -* Error in Breakpoints:: "Cannot insert breakpoints" - - -File: gdb.info, Node: Set Breaks, Next: Set Watchpoints, Up: Breakpoints - -Setting breakpoints -------------------- - - Breakpoints are set with the `break' command (abbreviated `b'). The -debugger convenience variable `$bpnum' records the number of the -beakpoint you've set most recently; see *Note Convenience variables: -Convenience Vars, for a discussion of what you can do with convenience -variables. - - You have several ways to say where the breakpoint should go. - -`break FUNCTION' - Set a breakpoint at entry to function FUNCTION. When using source - languages that permit overloading of symbols, such as C++, - FUNCTION may refer to more than one possible place to break. - *Note Breakpoint menus: Breakpoint Menus, for a discussion of that - situation. - -`break +OFFSET' -`break -OFFSET' - Set a breakpoint some number of lines forward or back from the - position at which execution stopped in the currently selected - frame. - -`break LINENUM' - Set a breakpoint at line LINENUM in the current source file. That - file is the last file whose source text was printed. This - breakpoint will stop your program just before it executes any of - the code on that line. - -`break FILENAME:LINENUM' - Set a breakpoint at line LINENUM in source file FILENAME. - -`break FILENAME:FUNCTION' - Set a breakpoint at entry to function FUNCTION found in file - FILENAME. Specifying a file name as well as a function name is - superfluous except when multiple files contain similarly named - functions. - -`break *ADDRESS' - Set a breakpoint at address ADDRESS. You can use this to set - breakpoints in parts of your program which do not have debugging - information or source files. - -`break' - When called without any arguments, `break' sets a breakpoint at - the next instruction to be executed in the selected stack frame - (*note Examining the Stack: Stack.). In any selected frame but the - innermost, this will cause your program to stop as soon as control - returns to that frame. This is similar to the effect of a - `finish' command in the frame inside the selected frame--except - that `finish' does not leave an active breakpoint. If you use - `break' without an argument in the innermost frame, GDB will stop - the next time it reaches the current location; this may be useful - inside loops. - - GDB normally ignores breakpoints when it resumes execution, until - at least one instruction has been executed. If it did not do - this, you would be unable to proceed past a breakpoint without - first disabling the breakpoint. This rule applies whether or not - the breakpoint already existed when your program stopped. - -`break ... if COND' - Set a breakpoint with condition COND; evaluate the expression COND - each time the breakpoint is reached, and stop only if the value is - nonzero--that is, if COND evaluates as true. `...' stands for one - of the possible arguments described above (or no argument) - specifying where to break. *Note Break conditions: Conditions, - for more information on breakpoint conditions. - -`tbreak ARGS' - Set a breakpoint enabled only for one stop. ARGS are the same as - for the `break' command, and the breakpoint is set in the same - way, but the breakpoint is automatically disabled after the first - time your program stops there. *Note Disabling breakpoints: - Disabling. - -`rbreak REGEX' - Set breakpoints on all functions matching the regular expression - REGEX. This command sets an unconditional breakpoint on all - matches, printing a list of all breakpoints it set. Once these - breakpoints are set, they are treated just like the breakpoints - set with the `break' command. They can be deleted, disabled, made - conditional, etc., in the standard ways. - - When debugging C++ programs, `rbreak' is useful for setting - breakpoints on overloaded functions that are not members of any - special classes. - -`info breakpoints [N]' -`info break [N]' -`info watchpoints [N]' - Print a table of all breakpoints and watchpoints set and not - deleted, with the following columns for each breakpoint: - - *Breakpoint Numbers* - *Type* - Breakpoint or watchpoint. - - *Disposition* - Whether the breakpoint is marked to be disabled or deleted - when hit. - - *Enabled or Disabled* - Enabled breakpoints are marked with `y'. `n' marks - breakpoints that are not enabled. - - *Address* - Where the breakpoint is in your program, as a memory address - - *What* - Where the breakpoint is in the source for your program, as a - file and line number. - - If a breakpoint is conditional, `info break' shows the condition on - the line following the affected breakpoint; breakpoint commands, - if any, are listed after that. - - `info break' with a breakpoint number N as argument lists only - that breakpoint. The convenience variable `$_' and the default - examining-address for the `x' command are set to the address of - the last breakpoint listed (*note Examining memory: Memory.). - - GDB allows you to set any number of breakpoints at the same place in -your program. There is nothing silly or meaningless about this. When -the breakpoints are conditional, this is even useful (*note Break -conditions: Conditions.). - - GDB itself sometimes sets breakpoints in your program for special -purposes, such as proper handling of `longjmp' (in C programs). These -internal breakpoints are assigned negative numbers, starting with `-1'; -`info breakpoints' does not display them. - - You can see these breakpoints with the GDB maintenance command -`maint info breakpoints'. - -`maint info breakpoints' - Using the same format as `info breakpoints', display both the - breakpoints you've set explicitly, and those GDB is using for - internal purposes. Internal breakpoints are shown with negative - breakpoint numbers. The type column identifies what kind of - breakpoint is shown: - - `breakpoint' - Normal, explicitly set breakpoint. - - `watchpoint' - Normal, explicitly set watchpoint. - - `longjmp' - Internal breakpoint, used to handle correctly stepping through - `longjmp' calls. - - `longjmp resume' - Internal breakpoint at the target of a `longjmp'. - - `until' - Temporary internal breakpoint used by the GDB `until' command. - - `finish' - Temporary internal breakpoint used by the GDB `finish' - command. - - -File: gdb.info, Node: Set Watchpoints, Next: Exception Handling, Prev: Set Breaks, Up: Breakpoints - -Setting watchpoints -------------------- - - You can use a watchpoint to stop execution whenever the value of an -expression changes, without having to predict a particular place where -this may happen. - - Watchpoints currently execute two orders of magnitude more slowly -than other breakpoints, but this can be well worth it to catch errors -where you have no clue what part of your program is the culprit. Some -processors provide special hardware to support watchpoint evaluation; -future releases of GDB will use such hardware if it is available. - -`watch EXPR' - Set a watchpoint for an expression. - -`info watchpoints' - This command prints a list of watchpoints and breakpoints; it is - the same as `info break'. - - -File: gdb.info, Node: Exception Handling, Next: Delete Breaks, Prev: Set Watchpoints, Up: Breakpoints - -Breakpoints and exceptions --------------------------- - - Some languages, such as GNU C++, implement exception handling. You -can use GDB to examine what caused your program to raise an exception, -and to list the exceptions your program is prepared to handle at a -given point in time. - -`catch EXCEPTIONS' - You can set breakpoints at active exception handlers by using the - `catch' command. EXCEPTIONS is a list of names of exceptions to - catch. - - You can use `info catch' to list active exception handlers. *Note -Information about a frame: Frame Info. - - There are currently some limitations to exception handling in GDB. -These will be corrected in a future release. - - * If you call a function interactively, GDB normally returns control - to you when the function has finished executing. If the call - raises an exception, however, the call may bypass the mechanism - that returns control to you and cause your program to simply - continue running until it hits a breakpoint, catches a signal that - GDB is listening for, or exits. - - * You cannot raise an exception interactively. - - * You cannot interactively install an exception handler. - - Sometimes `catch' is not the best way to debug exception handling: -if you need to know exactly where an exception is raised, it is better -to stop *before* the exception handler is called, since that way you -can see the stack before any unwinding takes place. If you set a -breakpoint in an exception handler instead, it may not be easy to find -out where the exception was raised. - - To stop just before an exception handler is called, you need some -knowledge of the implementation. In the case of GNU C++, exceptions are -raised by calling a library function named `__raise_exception' which -has the following ANSI C interface: - - /* ADDR is where the exception identifier is stored. - ID is the exception identifier. */ - void __raise_exception (void **ADDR, void *ID); - -To make the debugger catch all exceptions before any stack unwinding -takes place, set a breakpoint on `__raise_exception' (*note -Breakpoints; watchpoints; and exceptions: Breakpoints.). - - With a conditional breakpoint (*note Break conditions: Conditions.) -that depends on the value of ID, you can stop your program when a -specific exception is raised. You can use multiple conditional -breakpoints to stop your program when any of a number of exceptions are -raised. - - -File: gdb.info, Node: Delete Breaks, Next: Disabling, Prev: Exception Handling, Up: Breakpoints - -Deleting breakpoints --------------------- - - It is often necessary to eliminate a breakpoint or watchpoint once it -has done its job and you no longer want your program to stop there. -This is called "deleting" the breakpoint. A breakpoint that has been -deleted no longer exists; it is forgotten. - - With the `clear' command you can delete breakpoints according to -where they are in your program. With the `delete' command you can -delete individual breakpoints or watchpoints by specifying their -breakpoint numbers. - - It is not necessary to delete a breakpoint to proceed past it. GDB -automatically ignores breakpoints on the first instruction to be -executed when you continue execution without changing the execution -address. - -`clear' - Delete any breakpoints at the next instruction to be executed in - the selected stack frame (*note Selecting a frame: Selection.). - When the innermost frame is selected, this is a good way to delete - a breakpoint where your program just stopped. - -`clear FUNCTION' -`clear FILENAME:FUNCTION' - Delete any breakpoints set at entry to the function FUNCTION. - -`clear LINENUM' -`clear FILENAME:LINENUM' - Delete any breakpoints set at or within the code of the specified - line. - -`delete [breakpoints] [BNUMS...]' - Delete the breakpoints or watchpoints of the numbers specified as - arguments. If no argument is specified, delete all breakpoints - (GDB asks confirmation, unless you have `set confirm off'). You - can abbreviate this command as `d'. - - -File: gdb.info, Node: Disabling, Next: Conditions, Prev: Delete Breaks, Up: Breakpoints - -Disabling breakpoints ---------------------- - - Rather than deleting a breakpoint or watchpoint, you might prefer to -"disable" it. This makes the breakpoint inoperative as if it had been -deleted, but remembers the information on the breakpoint so that you -can "enable" it again later. - - You disable and enable breakpoints and watchpoints with the `enable' -and `disable' commands, optionally specifying one or more breakpoint -numbers as arguments. Use `info break' or `info watch' to print a list -of breakpoints or watchpoints if you do not know which numbers to use. - - A breakpoint or watchpoint can have any of four different states of -enablement: - - * Enabled. The breakpoint will stop your program. A breakpoint set - with the `break' command starts out in this state. - - * Disabled. The breakpoint has no effect on your program. - - * Enabled once. The breakpoint will stop your program, but when it - does so it will become disabled. A breakpoint set with the - `tbreak' command starts out in this state. - - * Enabled for deletion. The breakpoint will stop your program, but - immediately after it does so it will be deleted permanently. - - You can use the following commands to enable or disable breakpoints -and watchpoints: - -`disable [breakpoints] [BNUMS...]' - Disable the specified breakpoints--or all breakpoints, if none are - listed. A disabled breakpoint has no effect but is not forgotten. - All options such as ignore-counts, conditions and commands are - remembered in case the breakpoint is enabled again later. You may - abbreviate `disable' as `dis'. - -`enable [breakpoints] [BNUMS...]' - Enable the specified breakpoints (or all defined breakpoints). - They become effective once again in stopping your program. - -`enable [breakpoints] once BNUMS...' - Enable the specified breakpoints temporarily. Each will be - disabled again the next time it stops your program. - -`enable [breakpoints] delete BNUMS...' - Enable the specified breakpoints to work once and then die. Each - of the breakpoints will be deleted the next time it stops your - program. - - Save for a breakpoint set with `tbreak' (*note Setting breakpoints: -Set Breaks.), breakpoints that you set are initially enabled; -subsequently, they become disabled or enabled only when you use one of -the commands above. (The command `until' can set and delete a -breakpoint of its own, but it will not change the state of your other -breakpoints; see *Note Continuing and stepping: Continuing and -Stepping.) - - -File: gdb.info, Node: Conditions, Next: Break Commands, Prev: Disabling, Up: Breakpoints - -Break conditions ----------------- - - The simplest sort of breakpoint breaks every time your program -reaches a specified place. You can also specify a "condition" for a -breakpoint. A condition is just a Boolean expression in your -programming language (*note Expressions: Expressions.). A breakpoint -with a condition evaluates the expression each time your program -reaches it, and your program stops only if the condition is *true*. - - This is the converse of using assertions for program validation; in -that situation, you want to stop when the assertion is violated--that -is, when the condition is false. In C, if you want to test an -assertion expressed by the condition ASSERT, you should set the -condition `! ASSERT' on the appropriate breakpoint. - - Conditions are also accepted for watchpoints; you may not need them, -since a watchpoint is inspecting the value of an expression anyhow--but -it might be simpler, say, to just set a watchpoint on a variable name, -and specify a condition that tests whether the new value is an -interesting one. - - Break conditions can have side effects, and may even call functions -in your program. This can be useful, for example, to activate functions -that log program progress, or to use your own print functions to format -special data structures. The effects are completely predictable unless -there is another enabled breakpoint at the same address. (In that -case, GDB might see the other breakpoint first and stop your program -without checking the condition of this one.) Note that breakpoint -commands are usually more convenient and flexible for the purpose of -performing side effects when a breakpoint is reached (*note Breakpoint -command lists: Break Commands.). - - Break conditions can be specified when a breakpoint is set, by using -`if' in the arguments to the `break' command. *Note Setting -breakpoints: Set Breaks. They can also be changed at any time with the -`condition' command. The `watch' command does not recognize the `if' -keyword; `condition' is the only way to impose a further condition on a -watchpoint. - -`condition BNUM EXPRESSION' - Specify EXPRESSION as the break condition for breakpoint or - watchpoint number BNUM. From now on, this breakpoint will stop - your program only if the value of EXPRESSION is true (nonzero, in - C). When you use `condition', GDB checks EXPRESSION immediately - for syntactic correctness, and to determine whether symbols in it - have referents in the context of your breakpoint. GDB does not - actually evaluate EXPRESSION at the time the `condition' command - is given, however. *Note Expressions: Expressions. - -`condition BNUM' - Remove the condition from breakpoint number BNUM. It becomes an - ordinary unconditional breakpoint. - - A special case of a breakpoint condition is to stop only when the -breakpoint has been reached a certain number of times. This is so -useful that there is a special way to do it, using the "ignore count" -of the breakpoint. Every breakpoint has an ignore count, which is an -integer. Most of the time, the ignore count is zero, and therefore has -no effect. But if your program reaches a breakpoint whose ignore count -is positive, then instead of stopping, it just decrements the ignore -count by one and continues. As a result, if the ignore count value is -N, the breakpoint will not stop the next N times it is reached. - -`ignore BNUM COUNT' - Set the ignore count of breakpoint number BNUM to COUNT. The next - COUNT times the breakpoint is reached, your program's execution - will not stop; other than to decrement the ignore count, GDB takes - no action. - - To make the breakpoint stop the next time it is reached, specify a - count of zero. - - When you use `continue' to resume execution of your program from a - breakpoint, you can specify an ignore count directly as an - argument to `continue', rather than using `ignore'. *Note - Continuing and stepping: Continuing and Stepping. - - If a breakpoint has a positive ignore count and a condition, the - condition is not checked. Once the ignore count reaches zero, the - condition will be checked. - - You could achieve the effect of the ignore count with a condition - such as `$foo-- <= 0' using a debugger convenience variable that - is decremented each time. *Note Convenience variables: - Convenience Vars. - - -File: gdb.info, Node: Break Commands, Next: Breakpoint Menus, Prev: Conditions, Up: Breakpoints - -Breakpoint command lists ------------------------- - - You can give any breakpoint (or watchpoint) a series of commands to -execute when your program stops due to that breakpoint. For example, -you might want to print the values of certain expressions, or enable -other breakpoints. - -`commands [BNUM]' -`... COMMAND-LIST ...' -`end' - Specify a list of commands for breakpoint number BNUM. The - commands themselves appear on the following lines. Type a line - containing just `end' to terminate the commands. - - To remove all commands from a breakpoint, type `commands' and - follow it immediately with `end'; that is, give no commands. - - With no BNUM argument, `commands' refers to the last breakpoint or - watchpoint set (not to the breakpoint most recently encountered). - - Pressing RET as a means of repeating the last GDB command is -disabled within a COMMAND-LIST. - - You can use breakpoint commands to start your program up again. -Simply use the `continue' command, or `step', or any other command that -resumes execution. - - Any other commands in the command list, after a command that resumes -execution, are ignored. This is because any time you resume execution -(even with a simple `next' or `step'), you may encounter another -breakpoint--which could have its own command list, leading to -ambiguities about which list to execute. - - If the first command you specify in a command list is `silent', the -usual message about stopping at a breakpoint is not printed. This may -be desirable for breakpoints that are to print a specific message and -then continue. If none of the remaining commands print anything, you -will see no sign that the breakpoint was reached. `silent' is -meaningful only at the beginning of a breakpoint command list. - - The commands `echo', `output', and `printf' allow you to print -precisely controlled output, and are often useful in silent -breakpoints. *Note Commands for controlled output: Output. - - For example, here is how you could use breakpoint commands to print -the value of `x' at entry to `foo' whenever `x' is positive. - - break foo if x>0 - commands - silent - printf "x is %d\n",x - cont - end - - One application for breakpoint commands is to compensate for one bug -so you can test for another. Put a breakpoint just after the erroneous -line of code, give it a condition to detect the case in which something -erroneous has been done, and give it commands to assign correct values -to any variables that need them. End with the `continue' command so -that your program does not stop, and start with the `silent' command so -that no output is produced. Here is an example: - - break 403 - commands - silent - set x = y + 4 - cont - end - - -File: gdb.info, Node: Breakpoint Menus, Next: Error in Breakpoints, Prev: Break Commands, Up: Breakpoints - -Breakpoint menus ----------------- - - Some programming languages (notably C++) permit a single function -name to be defined several times, for application in different contexts. -This is called "overloading". When a function name is overloaded, -`break FUNCTION' is not enough to tell GDB where you want a breakpoint. -If you realize this will be a problem, you can use something like -`break FUNCTION(TYPES)' to specify which particular version of the -function you want. Otherwise, GDB offers you a menu of numbered -choices for different possible breakpoints, and waits for your -selection with the prompt `>'. The first two options are always `[0] -cancel' and `[1] all'. Typing `1' sets a breakpoint at each definition -of FUNCTION, and typing `0' aborts the `break' command without setting -any new breakpoints. - - For example, the following session excerpt shows an attempt to set a -breakpoint at the overloaded symbol `String::after'. We choose three -particular definitions of that function name: - - (gdb) b String::after - [0] cancel - [1] all - [2] file:String.cc; line number:867 - [3] file:String.cc; line number:860 - [4] file:String.cc; line number:875 - [5] file:String.cc; line number:853 - [6] file:String.cc; line number:846 - [7] file:String.cc; line number:735 - > 2 4 6 - Breakpoint 1 at 0xb26c: file String.cc, line 867. - Breakpoint 2 at 0xb344: file String.cc, line 875. - Breakpoint 3 at 0xafcc: file String.cc, line 846. - Multiple breakpoints were set. - Use the "delete" command to delete unwanted - breakpoints. - (gdb) - - -File: gdb.info, Node: Error in Breakpoints, Prev: Breakpoint Menus, Up: Breakpoints - -"Cannot insert breakpoints" ---------------------------- - - Under some operating systems, breakpoints cannot be used in a -program if any other process is running that program. In this -situation, attempting to run or continue a program with a breakpoint -causes GDB to stop the other process. - - When this happens, you have three ways to proceed: - - 1. Remove or disable the breakpoints, then continue. - - 2. Suspend GDB, and copy the file containing your program to a new - name. Resume GDB and use the `exec-file' command to specify that - GDB should run your program under that name. Then start your - program again. - - 3. Relink your program so that the text segment is nonsharable, using - the linker option `-N'. The operating system limitation may not - apply to nonsharable executables. - - -File: gdb.info, Node: Continuing and Stepping, Next: Signals, Prev: Breakpoints, Up: Stopping - -Continuing and stepping -======================= - - "Continuing" means resuming program execution until your program -completes normally. In contrast, "stepping" means executing just one -more "step" of your program, where "step" may mean either one line of -source code, or one machine instruction (depending on what particular -command you use). Either when continuing or when stepping, your -program may stop even sooner, due to a breakpoint or a signal. (If due -to a signal, you may want to use `handle', or use `signal 0' to resume -execution. *Note Signals: Signals.) - -`continue [IGNORE-COUNT]' -`c [IGNORE-COUNT]' -`fg [IGNORE-COUNT]' - Resume program execution, at the address where your program last - stopped; any breakpoints set at that address are bypassed. The - optional argument IGNORE-COUNT allows you to specify a further - number of times to ignore a breakpoint at this location; its - effect is like that of `ignore' (*note Break conditions: - Conditions.). - - The argument IGNORE-COUNT is meaningful only when your program - stopped due to a breakpoint. At other times, the argument to - `continue' is ignored. - - The synonyms `c' and `fg' are provided purely for convenience, and - have exactly the same behavior as `continue'. - - To resume execution at a different place, you can use `return' -(*note Returning from a function: Returning.) to go back to the calling -function; or `jump' (*note Continuing at a different address: Jumping.) -to go to an arbitrary location in your program. - - A typical technique for using stepping is to set a breakpoint (*note -Breakpoints; watchpoints; and exceptions: Breakpoints.) at the -beginning of the function or the section of your program where a -problem is believed to lie, run your program until it stops at that -breakpoint, and then step through the suspect area, examining the -variables that are interesting, until you see the problem happen. - -`step' - Continue running your program until control reaches a different - source line, then stop it and return control to GDB. This command - is abbreviated `s'. - - *Warning:* If you use the `step' command while control is - within a function that was compiled without debugging - information, execution proceeds until control reaches a - function that does have debugging information. - -`step COUNT' - Continue running as in `step', but do so COUNT times. If a - breakpoint is reached, or a signal not related to stepping occurs - before COUNT steps, stepping stops right away. - -`next [COUNT]' - Continue to the next source line in the current (innermost) stack - frame. Similar to `step', but any function calls appearing within - the line of code are executed without stopping. Execution stops - when control reaches a different line of code at the stack level - which was executing when the `next' command was given. This - command is abbreviated `n'. - - An argument COUNT is a repeat count, as for `step'. - - `next' within a function that lacks debugging information acts like - `step', but any function calls appearing within the code of the - function are executed without stopping. - -`finish' - Continue running until just after function in the selected stack - frame returns. Print the returned value (if any). - - Contrast this with the `return' command (*note Returning from a - function: Returning.). - -`until' -`u' - Continue running until a source line past the current line, in the - current stack frame, is reached. This command is used to avoid - single stepping through a loop more than once. It is like the - `next' command, except that when `until' encounters a jump, it - automatically continues execution until the program counter is - greater than the address of the jump. - - This means that when you reach the end of a loop after single - stepping though it, `until' will cause your program to continue - execution until the loop is exited. In contrast, a `next' command - at the end of a loop will simply step back to the beginning of the - loop, which would force you to step through the next iteration. - - `until' always stops your program if it attempts to exit the - current stack frame. - - `until' may produce somewhat counterintuitive results if the order - of machine code does not match the order of the source lines. For - example, in the following excerpt from a debugging session, the `f' - (`frame') command shows that execution is stopped at line `206'; - yet when we use `until', we get to line `195': - - (gdb) f - #0 main (argc=4, argv=0xf7fffae8) at m4.c:206 - 206 expand_input(); - (gdb) until - 195 for ( ; argc > 0; NEXTARG) { - - This happened because, for execution efficiency, the compiler had - generated code for the loop closure test at the end, rather than - the start, of the loop--even though the test in a C `for'-loop is - written before the body of the loop. The `until' command appeared - to step back to the beginning of the loop when it advanced to this - expression; however, it has not really gone to an earlier - statement--not in terms of the actual machine code. - - `until' with no argument works by means of single instruction - stepping, and hence is slower than `until' with an argument. - -`until LOCATION' -`u LOCATION' - Continue running your program until either the specified location - is reached, or the current stack frame returns. LOCATION is any of - the forms of argument acceptable to `break' (*note Setting - breakpoints: Set Breaks.). This form of the command uses - breakpoints, and hence is quicker than `until' without an argument. - -`stepi' -`si' - Execute one machine instruction, then stop and return to the - debugger. - - It is often useful to do `display/i $pc' when stepping by machine - instructions. This will cause the next instruction to be executed - to be displayed automatically at each stop. *Note Automatic - display: Auto Display. - - An argument is a repeat count, as in `step'. - -`nexti' -`ni' - Execute one machine instruction, but if it is a function call, - proceed until the function returns. - - An argument is a repeat count, as in `next'. - - -File: gdb.info, Node: Signals, Prev: Continuing and Stepping, Up: Stopping - -Signals -======= - - A signal is an asynchronous event that can happen in a program. The -operating system defines the possible kinds of signals, and gives each -kind a name and a number. For example, in Unix `SIGINT' is the signal -a program gets when you type an interrupt (often `C-c'); `SIGSEGV' is -the signal a program gets from referencing a place in memory far away -from all the areas in use; `SIGALRM' occurs when the alarm clock timer -goes off (which happens only if your program has requested an alarm). - - Some signals, including `SIGALRM', are a normal part of the -functioning of your program. Others, such as `SIGSEGV', indicate -errors; these signals are "fatal" (kill your program immediately) if the -program has not specified in advance some other way to handle the -signal. `SIGINT' does not indicate an error in your program, but it is -normally fatal so it can carry out the purpose of the interrupt: to -kill the program. - - GDB has the ability to detect any occurrence of a signal in your -program. You can tell GDB in advance what to do for each kind of -signal. - - Normally, GDB is set up to ignore non-erroneous signals like -`SIGALRM' (so as not to interfere with their role in the functioning of -your program) but to stop your program immediately whenever an error -signal happens. You can change these settings with the `handle' -command. - -`info signals' - Print a table of all the kinds of signals and how GDB has been - told to handle each one. You can use this to see the signal - numbers of all the defined types of signals. - -`handle SIGNAL KEYWORDS...' - Change the way GDB handles signal SIGNAL. SIGNAL can be the - number of a signal or its name (with or without the `SIG' at the - beginning). The KEYWORDS say what change to make. - - The keywords allowed by the `handle' command can be abbreviated. -Their full names are: - -`nostop' - GDB should not stop your program when this signal happens. It may - still print a message telling you that the signal has come in. - -`stop' - GDB should stop your program when this signal happens. This - implies the `print' keyword as well. - -`print' - GDB should print a message when this signal happens. - -`noprint' - GDB should not mention the occurrence of the signal at all. This - implies the `nostop' keyword as well. - -`pass' - GDB should allow your program to see this signal; your program - will be able to handle the signal, or may be terminated if the - signal is fatal and not handled. - -`nopass' - GDB should not allow your program to see this signal. - - When a signal stops your program, the signal is not visible until you -continue. Your program will see the signal then, if `pass' is in -effect for the signal in question *at that time*. In other words, -after GDB reports a signal, you can use the `handle' command with -`pass' or `nopass' to control whether that signal will be seen by your -program when you later continue it. - - You can also use the `signal' command to prevent your program from -seeing a signal, or cause it to see a signal it normally would not see, -or to give it any signal at any time. For example, if your program -stopped due to some sort of memory reference error, you might store -correct values into the erroneous variables and continue, hoping to see -more execution; but your program would probably terminate immediately as -a result of the fatal signal once it saw the signal. To prevent this, -you can continue with `signal 0'. *Note Giving your program a signal: -Signaling. - - -File: gdb.info, Node: Stack, Next: Source, Prev: Stopping, Up: Top - -Examining the Stack -******************* - - When your program has stopped, the first thing you need to know is -where it stopped and how it got there. - - Each time your program performs a function call, the information -about where in your program the call was made from is saved in a block -of data called a "stack frame". The frame also contains the arguments -of the call and the local variables of the function that was called. -All the stack frames are allocated in a region of memory called the -"call stack". - - When your program stops, the GDB commands for examining the stack -allow you to see all of this information. - - One of the stack frames is "selected" by GDB and many GDB commands -refer implicitly to the selected frame. In particular, whenever you -ask GDB for the value of a variable in your program, the value is found -in the selected frame. There are special GDB commands to select -whichever frame you are interested in. - - When your program stops, GDB automatically selects the currently -executing frame and describes it briefly as the `frame' command does -(*note Information about a frame: Frame Info.). - -* Menu: - -* Frames:: Stack frames -* Backtrace:: Backtraces -* Selection:: Selecting a frame -* Frame Info:: Information on a frame - -* MIPS Stack:: MIPS machines and the function stack - - -File: gdb.info, Node: Frames, Next: Backtrace, Up: Stack - -Stack frames -============ - - The call stack is divided up into contiguous pieces called "stack -frames", or "frames" for short; each frame is the data associated with -one call to one function. The frame contains the arguments given to -the function, the function's local variables, and the address at which -the function is executing. - - When your program is started, the stack has only one frame, that of -the function `main'. This is called the "initial" frame or the -"outermost" frame. Each time a function is called, a new frame is -made. Each time a function returns, the frame for that function -invocation is eliminated. If a function is recursive, there can be -many frames for the same function. The frame for the function in which -execution is actually occurring is called the "innermost" frame. This -is the most recently created of all the stack frames that still exist. - - Inside your program, stack frames are identified by their addresses. -A stack frame consists of many bytes, each of which has its own -address; each kind of computer has a convention for choosing one of -those bytes whose address serves as the address of the frame. Usually -this address is kept in a register called the "frame pointer register" -while execution is going on in that frame. - - GDB assigns numbers to all existing stack frames, starting with zero -for the innermost frame, one for the frame that called it, and so on -upward. These numbers do not really exist in your program; they are -assigned by GDB to give you a way of designating stack frames in GDB -commands. - - Some compilers provide a way to compile functions so that they -operate without stack frames. (For example, the `gcc' option -`-fomit-frame-pointer' will generate functions without a frame.) This -is occasionally done with heavily used library functions to save the -frame setup time. GDB has limited facilities for dealing with these -function invocations. If the innermost function invocation has no -stack frame, GDB will nevertheless regard it as though it had a -separate frame, which is numbered zero as usual, allowing correct -tracing of the function call chain. However, GDB has no provision for -frameless functions elsewhere in the stack. - - -File: gdb.info, Node: Backtrace, Next: Selection, Prev: Frames, Up: Stack - -Backtraces -========== - - A backtrace is a summary of how your program got where it is. It -shows one line per frame, for many frames, starting with the currently -executing frame (frame zero), followed by its caller (frame one), and -on up the stack. - -`backtrace' -`bt' - Print a backtrace of the entire stack: one line per frame for all - frames in the stack. - - You can stop the backtrace at any time by typing the system - interrupt character, normally `C-c'. - -`backtrace N' -`bt N' - Similar, but print only the innermost N frames. - -`backtrace -N' -`bt -N' - Similar, but print only the outermost N frames. - - The names `where' and `info stack' (abbreviated `info s') are -additional aliases for `backtrace'. - - Each line in the backtrace shows the frame number and the function -name. The program counter value is also shown--unless you use `set -print address off'. The backtrace also shows the source file name and -line number, as well as the arguments to the function. The program -counter value is omitted if it is at the beginning of the code for that -line number. - - Here is an example of a backtrace. It was made with the command `bt -3', so it shows the innermost three frames. - - #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8) - at builtin.c:993 - #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242 - #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08) - at macro.c:71 - (More stack frames follow...) - -The display for frame zero does not begin with a program counter value, -indicating that your program has stopped at the beginning of the code -for line `993' of `builtin.c'. - diff --git a/gnu/usr.bin/gdb/doc/gdb.info-3 b/gnu/usr.bin/gdb/doc/gdb.info-3 deleted file mode 100644 index aea5862..0000000 --- a/gnu/usr.bin/gdb/doc/gdb.info-3 +++ /dev/null @@ -1,1264 +0,0 @@ -This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input -file gdb.texinfo. - -START-INFO-DIR-ENTRY -* Gdb:: The GNU debugger. -END-INFO-DIR-ENTRY - This file documents the GNU debugger GDB. - - This is Edition 4.09, August 1993, of `Debugging with GDB: the GNU -Source-Level Debugger' for GDB Version 4.11. - - Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software -Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the entire resulting derived work is distributed under the terms -of a permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions. - - -File: gdb.info, Node: Selection, Next: Frame Info, Prev: Backtrace, Up: Stack - -Selecting a frame -================= - - Most commands for examining the stack and other data in your program -work on whichever stack frame is selected at the moment. Here are the -commands for selecting a stack frame; all of them finish by printing a -brief description of the stack frame just selected. - -`frame N' -`f N' - Select frame number N. Recall that frame zero is the innermost - (currently executing) frame, frame one is the frame that called the - innermost one, and so on. The highest-numbered frame is the one - for `main'. - -`frame ADDR' -`f ADDR' - Select the frame at address ADDR. This is useful mainly if the - chaining of stack frames has been damaged by a bug, making it - impossible for GDB to assign numbers properly to all frames. In - addition, this can be useful when your program has multiple stacks - and switches between them. - - On the SPARC architecture, `frame' needs two addresses to select - an arbitrary frame: a frame pointer and a stack pointer. - -`up N' - Move N frames up the stack. For positive numbers N, this advances - toward the outermost frame, to higher frame numbers, to frames - that have existed longer. N defaults to one. - -`down N' - Move N frames down the stack. For positive numbers N, this - advances toward the innermost frame, to lower frame numbers, to - frames that were created more recently. N defaults to one. You - may abbreviate `down' as `do'. - - All of these commands end by printing two lines of output describing -the frame. The first line shows the frame number, the function name, -the arguments, and the source file and line number of execution in that -frame. The second line shows the text of that source line. - - For example: - (gdb) up - #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) - at env.c:10 - 10 read_input_file (argv[i]); - - After such a printout, the `list' command with no arguments will -print ten lines centered on the point of execution in the frame. *Note -Printing source lines: List. - -`up-silently N' -`down-silently N' - These two commands are variants of `up' and `down', respectively; - they differ in that they do their work silently, without causing - display of the new frame. They are intended primarily for use in - GDB command scripts, where the output might be unnecessary and - distracting. - - -File: gdb.info, Node: Frame Info, Next: MIPS Stack, Prev: Selection, Up: Stack - -Information about a frame -========================= - - There are several other commands to print information about the -selected stack frame. - -`frame' -`f' - When used without any argument, this command does not change which - frame is selected, but prints a brief description of the currently - selected stack frame. It can be abbreviated `f'. With an - argument, this command is used to select a stack frame. *Note - Selecting a frame: Selection. - -`info frame' -`info f' - This command prints a verbose description of the selected stack - frame, including the address of the frame, the addresses of the - next frame down (called by this frame) and the next frame up - (caller of this frame), the language that the source code - corresponding to this frame was written in, the address of the - frame's arguments, the program counter saved in it (the address of - execution in the caller frame), and which registers were saved in - the frame. The verbose description is useful when something has - gone wrong that has made the stack format fail to fit the usual - conventions. - -`info frame ADDR' -`info f ADDR' - Print a verbose description of the frame at address ADDR, without - selecting that frame. The selected frame remains unchanged by - this command. - -`info args' - Print the arguments of the selected frame, each on a separate line. - -`info locals' - Print the local variables of the selected frame, each on a separate - line. These are all variables (declared either static or - automatic) accessible at the point of execution of the selected - frame. - -`info catch' - Print a list of all the exception handlers that are active in the - current stack frame at the current point of execution. To see - other exception handlers, visit the associated frame (using the - `up', `down', or `frame' commands); then type `info catch'. *Note - Breakpoints and exceptions: Exception Handling. - - -File: gdb.info, Node: MIPS Stack, Prev: Frame Info, Up: Stack - -MIPS machines and the function stack -==================================== - - MIPS based computers use an unusual stack frame, which sometimes -requires GDB to search backward in the object code to find the -beginning of a function. - - To improve response time (especially for embedded applications, where -GDB may be restricted to a slow serial line for this search) you may -want to limit the size of this search, using one of these commands: - -`set heuristic-fence-post LIMIT' - Restrict GDBN to examining at most LIMIT bytes in its search for - the beginning of a function. A value of `0' (the default) means - there is no limit. - -`show heuristic-fence-post' - Display the current limit. - -These commands are available *only* when GDB is configured for -debugging programs on MIPS processors. - - -File: gdb.info, Node: Source, Next: Data, Prev: Stack, Up: Top - -Examining Source Files -********************** - - GDB can print parts of your program's source, since the debugging -information recorded in the program tells GDB what source files were -used to build it. When your program stops, GDB spontaneously prints -the line where it stopped. Likewise, when you select a stack frame -(*note Selecting a frame: Selection.), GDB prints the line where -execution in that frame has stopped. You can print other portions of -source files by explicit command. - - If you use GDB through its GNU Emacs interface, you may prefer to use -Emacs facilities to view source; *note Using GDB under GNU Emacs: -Emacs.. - -* Menu: - -* List:: Printing source lines - -* Search:: Searching source files - -* Source Path:: Specifying source directories -* Machine Code:: Source and machine code - - -File: gdb.info, Node: List, Next: Search, Up: Source - -Printing source lines -===================== - - To print lines from a source file, use the `list' command -(abbreviated `l'). There are several ways to specify what part of the -file you want to print. - - Here are the forms of the `list' command most commonly used: - -`list LINENUM' - Print lines centered around line number LINENUM in the current - source file. - -`list FUNCTION' - Print lines centered around the beginning of function FUNCTION. - -`list' - Print more lines. If the last lines printed were printed with a - `list' command, this prints lines following the last lines - printed; however, if the last line printed was a solitary line - printed as part of displaying a stack frame (*note Examining the - Stack: Stack.), this prints lines centered around that line. - -`list -' - Print lines just before the lines last printed. - - By default, GDB prints ten source lines with any of these forms of -the `list' command. You can change this using `set listsize': - -`set listsize COUNT' - Make the `list' command display COUNT source lines (unless the - `list' argument explicitly specifies some other number). - -`show listsize' - Display the number of lines that `list' will currently display by - default. - - Repeating a `list' command with RET discards the argument, so it is -equivalent to typing just `list'. This is more useful than listing the -same lines again. An exception is made for an argument of `-'; that -argument is preserved in repetition so that each repetition moves up in -the source file. - - In general, the `list' command expects you to supply zero, one or two -"linespecs". Linespecs specify source lines; there are several ways of -writing them but the effect is always to specify some source line. -Here is a complete description of the possible arguments for `list': - -`list LINESPEC' - Print lines centered around the line specified by LINESPEC. - -`list FIRST,LAST' - Print lines from FIRST to LAST. Both arguments are linespecs. - -`list ,LAST' - Print lines ending with LAST. - -`list FIRST,' - Print lines starting with FIRST. - -`list +' - Print lines just after the lines last printed. - -`list -' - Print lines just before the lines last printed. - -`list' - As described in the preceding table. - - Here are the ways of specifying a single source line--all the kinds -of linespec. - -`NUMBER' - Specifies line NUMBER of the current source file. When a `list' - command has two linespecs, this refers to the same source file as - the first linespec. - -`+OFFSET' - Specifies the line OFFSET lines after the last line printed. When - used as the second linespec in a `list' command that has two, this - specifies the line OFFSET lines down from the first linespec. - -`-OFFSET' - Specifies the line OFFSET lines before the last line printed. - -`FILENAME:NUMBER' - Specifies line NUMBER in the source file FILENAME. - -`FUNCTION' - Specifies the line of the open-brace that begins the body of the - function FUNCTION. - -`FILENAME:FUNCTION' - Specifies the line of the open-brace that begins the body of the - function FUNCTION in the file FILENAME. You only need the file - name with a function name to avoid ambiguity when there are - identically named functions in different source files. - -`*ADDRESS' - Specifies the line containing the program address ADDRESS. - ADDRESS may be any expression. - - -File: gdb.info, Node: Search, Next: Source Path, Prev: List, Up: Source - -Searching source files -====================== - - There are two commands for searching through the current source file -for a regular expression. - -`forward-search REGEXP' -`search REGEXP' - The command `forward-search REGEXP' checks each line, starting - with the one following the last line listed, for a match for - REGEXP. It lists the line that is found. You can use synonym - `search REGEXP' or abbreviate the command name as `fo'. - -`reverse-search REGEXP' - The command `reverse-search REGEXP' checks each line, starting - with the one before the last line listed and going backward, for a - match for REGEXP. It lists the line that is found. You can - abbreviate this command as `rev'. - - -File: gdb.info, Node: Source Path, Next: Machine Code, Prev: Search, Up: Source - -Specifying source directories -============================= - - Executable programs sometimes do not record the directories of the -source files from which they were compiled, just the names. Even when -they do, the directories could be moved between the compilation and -your debugging session. GDB has a list of directories to search for -source files; this is called the "source path". Each time GDB wants a -source file, it tries all the directories in the list, in the order -they are present in the list, until it finds a file with the desired -name. Note that the executable search path is *not* used for this -purpose. Neither is the current working directory, unless it happens -to be in the source path. - - If GDB cannot find a source file in the source path, and the object -program records a directory, GDB tries that directory too. If the -source path is empty, and there is no record of the compilation -directory, GDB will, as a last resort, look in the current directory. - - Whenever you reset or rearrange the source path, GDB will clear out -any information it has cached about where source files are found, where -each line is in the file, etc. - - When you start GDB, its source path is empty. To add other -directories, use the `directory' command. - -`directory DIRNAME ...' - Add directory DIRNAME to the front of the source path. Several - directory names may be given to this command, separated by `:' or - whitespace. You may specify a directory that is already in the - source path; this moves it forward, so it will be searched sooner. - - You can use the string `$cdir' to refer to the compilation - directory (if one is recorded), and `$cwd' to refer to the current - working directory. `$cwd' is not the same as `.'--the former - tracks the current working directory as it changes during your GDB - session, while the latter is immediately expanded to the current - directory at the time you add an entry to the source path. - -`directory' - Reset the source path to empty again. This requires confirmation. - -`show directories' - Print the source path: show which directories it contains. - - If your source path is cluttered with directories that are no longer -of interest, GDB may sometimes cause confusion by finding the wrong -versions of source. You can correct the situation as follows: - - 1. Use `directory' with no argument to reset the source path to empty. - - 2. Use `directory' with suitable arguments to reinstall the - directories you want in the source path. You can add all the - directories in one command. - - -File: gdb.info, Node: Machine Code, Prev: Source Path, Up: Source - -Source and machine code -======================= - - You can use the command `info line' to map source lines to program -addresses (and vice versa), and the command `disassemble' to display a -range of addresses as machine instructions. - -`info line LINESPEC' - Print the starting and ending addresses of the compiled code for - source line LINESPEC. You can specify source lines in any of the - ways understood by the `list' command (*note Printing source - lines: List.). - - For example, we can use `info line' to discover the location of the -object code for the first line of function `m4_changequote': - - (gdb) info line m4_changecom - Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350. - -We can also inquire (using `*ADDR' as the form for LINESPEC) what -source line covers a particular address: - (gdb) info line *0x63ff - Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404. - - After `info line', the default address for the `x' command is -changed to the starting address of the line, so that `x/i' is -sufficient to begin examining the machine code (*note Examining memory: -Memory.). Also, this address is saved as the value of the convenience -variable `$_' (*note Convenience variables: Convenience Vars.). - -`disassemble' - This specialized command dumps a range of memory as machine - instructions. The default memory range is the function - surrounding the program counter of the selected frame. A single - argument to this command is a program counter value; the function - surrounding this value will be dumped. Two arguments specify a - range of addresses (first inclusive, second exclusive) to dump. - - We can use `disassemble' to inspect the object code range shown in -the last `info line' example (the example shows SPARC machine -instructions): - - (gdb) disas 0x63e4 0x6404 - Dump of assembler code from 0x63e4 to 0x6404: - 0x63e4 : ble 0x63f8 - 0x63e8 : sethi %hi(0x4c00), %o0 - 0x63ec : ld [%i1+4], %o0 - 0x63f0 : b 0x63fc - 0x63f4 : ld [%o0+4], %o0 - 0x63f8 : or %o0, 0x1a4, %o0 - 0x63fc : call 0x9288 - 0x6400 : nop - End of assembler dump. - - -File: gdb.info, Node: Data, Next: Languages, Prev: Source, Up: Top - -Examining Data -************** - - The usual way to examine data in your program is with the `print' -command (abbreviated `p'), or its synonym `inspect'. It evaluates and -prints the value of an expression of the language your program is -written in (*note Using GDB with Different Languages: Languages.). - -`print EXP' -`print /F EXP' - EXP is an expression (in the source language). By default the - value of EXP is printed in a format appropriate to its data type; - you can choose a different format by specifying `/F', where F is a - letter specifying the format; *note Output formats: Output - Formats.. - -`print' -`print /F' - If you omit EXP, GDB displays the last value again (from the - "value history"; *note Value history: Value History.). This - allows you to conveniently inspect the same value in an - alternative format. - - A more low-level way of examining data is with the `x' command. It -examines data in memory at a specified address and prints it in a -specified format. *Note Examining memory: Memory. - - If you are interested in information about types, or about how the -fields of a struct or class are declared, use the `ptype EXP' command -rather than `print'. *Note Examining the Symbol Table: Symbols. - -* Menu: - -* Expressions:: Expressions -* Variables:: Program variables -* Arrays:: Artificial arrays -* Output Formats:: Output formats -* Memory:: Examining memory -* Auto Display:: Automatic display -* Print Settings:: Print settings -* Value History:: Value history -* Convenience Vars:: Convenience variables -* Registers:: Registers - -* Floating Point Hardware:: Floating point hardware - - -File: gdb.info, Node: Expressions, Next: Variables, Up: Data - -Expressions -=========== - - `print' and many other GDB commands accept an expression and compute -its value. Any kind of constant, variable or operator defined by the -programming language you are using is valid in an expression in GDB. -This includes conditional expressions, function calls, casts and string -constants. It unfortunately does not include symbols defined by -preprocessor `#define' commands. - - Because C is so widespread, most of the expressions shown in -examples in this manual are in C. *Note Using GDB with Different -Languages: Languages, for information on how to use expressions in other -languages. - - In this section, we discuss operators that you can use in GDB -expressions regardless of your programming language. - - Casts are supported in all languages, not just in C, because it is so -useful to cast a number into a pointer so as to examine a structure at -that address in memory. - - GDB supports these operators in addition to those of programming -languages: - -`@' - `@' is a binary operator for treating parts of memory as arrays. - *Note Artificial arrays: Arrays, for more information. - -`::' - `::' allows you to specify a variable in terms of the file or - function where it is defined. *Note Program variables: Variables. - -`{TYPE} ADDR' - Refers to an object of type TYPE stored at address ADDR in memory. - ADDR may be any expression whose value is an integer or pointer - (but parentheses are required around binary operators, just as in - a cast). This construct is allowed regardless of what kind of - data is normally supposed to reside at ADDR. - - -File: gdb.info, Node: Variables, Next: Arrays, Prev: Expressions, Up: Data - -Program variables -================= - - The most common kind of expression to use is the name of a variable -in your program. - - Variables in expressions are understood in the selected stack frame -(*note Selecting a frame: Selection.); they must either be global (or -static) or be visible according to the scope rules of the programming -language from the point of execution in that frame. This means that in -the function - - foo (a) - int a; - { - bar (a); - { - int b = test (); - bar (b); - } - } - -you can examine and use the variable `a' whenever your program is -executing within the function `foo', but you can only use or examine -the variable `b' while your program is executing inside the block where -`b' is declared. - - There is an exception: you can refer to a variable or function whose -scope is a single source file even if the current execution point is not -in this file. But it is possible to have more than one such variable or -function with the same name (in different source files). If that -happens, referring to that name has unpredictable effects. If you wish, -you can specify a static variable in a particular function or file, -using the colon-colon notation: - - FILE::VARIABLE - FUNCTION::VARIABLE - -Here FILE or FUNCTION is the name of the context for the static -VARIABLE. In the case of file names, you can use quotes to make sure -GDB parses the file name as a single word--for example, to print a -global value of `x' defined in `f2.c': - - (gdb) p 'f2.c'::x - - This use of `::' is very rarely in conflict with the very similar -use of the same notation in C++. GDB also supports use of the C++ -scope resolution operator in GDB expressions. - - *Warning:* Occasionally, a local variable may appear to have the - wrong value at certain points in a function--just after entry to a - new scope, and just before exit. - You may see this problem when you are stepping by machine -instructions. This is because on most machines, it takes more than one -instruction to set up a stack frame (including local variable -definitions); if you are stepping by machine instructions, variables -may appear to have the wrong values until the stack frame is completely -built. On exit, it usually also takes more than one machine -instruction to destroy a stack frame; after you begin stepping through -that group of instructions, local variable definitions may be gone. - - -File: gdb.info, Node: Arrays, Next: Output Formats, Prev: Variables, Up: Data - -Artificial arrays -================= - - It is often useful to print out several successive objects of the -same type in memory; a section of an array, or an array of dynamically -determined size for which only a pointer exists in the program. - - You can do this by referring to a contiguous span of memory as an -"artificial array", using the binary operator `@'. The left operand of -`@' should be the first element of the desired array, as an individual -object. The right operand should be the desired length of the array. -The result is an array value whose elements are all of the type of the -left argument. The first element is actually the left argument; the -second element comes from bytes of memory immediately following those -that hold the first element, and so on. Here is an example. If a -program says - - int *array = (int *) malloc (len * sizeof (int)); - -you can print the contents of `array' with - - p *array@len - - The left operand of `@' must reside in memory. Array values made -with `@' in this way behave just like other arrays in terms of -subscripting, and are coerced to pointers when used in expressions. -Artificial arrays most often appear in expressions via the value history -(*note Value history: Value History.), after printing one out. - - Sometimes the artificial array mechanism is not quite enough; in -moderately complex data structures, the elements of interest may not -actually be adjacent--for example, if you are interested in the values -of pointers in an array. One useful work-around in this situation is -to use a convenience variable (*note Convenience variables: Convenience -Vars.) as a counter in an expression that prints the first interesting -value, and then repeat that expression via RET. For instance, suppose -you have an array `dtab' of pointers to structures, and you are -interested in the values of a field `fv' in each structure. Here is an -example of what you might type: - - set $i = 0 - p dtab[$i++]->fv - RET - RET - ... - - -File: gdb.info, Node: Output Formats, Next: Memory, Prev: Arrays, Up: Data - -Output formats -============== - - By default, GDB prints a value according to its data type. Sometimes -this is not what you want. For example, you might want to print a -number in hex, or a pointer in decimal. Or you might want to view data -in memory at a certain address as a character string or as an -instruction. To do these things, specify an "output format" when you -print a value. - - The simplest use of output formats is to say how to print a value -already computed. This is done by starting the arguments of the -`print' command with a slash and a format letter. The format letters -supported are: - -`x' - Regard the bits of the value as an integer, and print the integer - in hexadecimal. - -`d' - Print as integer in signed decimal. - -`u' - Print as integer in unsigned decimal. - -`o' - Print as integer in octal. - -`t' - Print as integer in binary. The letter `t' stands for "two". (1) - -`a' - Print as an address, both absolute in hex and as an offset from the - nearest preceding symbol. This format can be used to discover - where (in what function) an unknown address is located: - - (gdb) p/a 0x54320 - $3 = 0x54320 <_initialize_vx+396> - -`c' - Regard as an integer and print it as a character constant. - -`f' - Regard the bits of the value as a floating point number and print - using typical floating point syntax. - - For example, to print the program counter in hex (*note -Registers::.), type - - p/x $pc - -Note that no space is required before the slash; this is because command -names in GDB cannot contain a slash. - - To reprint the last value in the value history with a different -format, you can use the `print' command with just a format and no -expression. For example, `p/x' reprints the last value in hex. - - ---------- Footnotes ---------- - - (1) `b' cannot be used because these format letters are also used -with the `x' command, where `b' stands for "byte"; *note Examining -memory: Memory.. - - -File: gdb.info, Node: Memory, Next: Auto Display, Prev: Output Formats, Up: Data - -Examining memory -================ - - You can use the command `x' (for "examine") to examine memory in any -of several formats, independently of your program's data types. - -`x/NFU ADDR' -`x ADDR' -`x' - Use the `x' command to examine memory. - - N, F, and U are all optional parameters that specify how much memory -to display and how to format it; ADDR is an expression giving the -address where you want to start displaying memory. If you use defaults -for NFU, you need not type the slash `/'. Several commands set -convenient defaults for ADDR. - -N, the repeat count - The repeat count is a decimal integer; the default is 1. It - specifies how much memory (counting by units U) to display. - -F, the display format - The display format is one of the formats used by `print', or `s' - (null-terminated string) or `i' (machine instruction). The - default is `x' (hexadecimal) initially, or the format from the - last time you used either `x' or `print'. - -U, the unit size - The unit size is any of - - `b' - Bytes. - - `h' - Halfwords (two bytes). - - `w' - Words (four bytes). This is the initial default. - - `g' - Giant words (eight bytes). - - Each time you specify a unit size with `x', that size becomes the - default unit the next time you use `x'. (For the `s' and `i' - formats, the unit size is ignored and is normally not written.) - -ADDR, starting display address - ADDR is the address where you want GDB to begin displaying memory. - The expression need not have a pointer value (though it may); it - is always interpreted as an integer address of a byte of memory. - *Note Expressions: Expressions, for more information on - expressions. The default for ADDR is usually just after the last - address examined--but several other commands also set the default - address: `info breakpoints' (to the address of the last breakpoint - listed), `info line' (to the starting address of a line), and - `print' (if you use it to display a value from memory). - - For example, `x/3uh 0x54320' is a request to display three halfwords -(`h') of memory, formatted as unsigned decimal integers (`u'), starting -at address `0x54320'. `x/4xw $sp' prints the four words (`w') of -memory above the stack pointer (here, `$sp'; *note Registers::.) in -hexadecimal (`x'). - - Since the letters indicating unit sizes are all distinct from the -letters specifying output formats, you do not have to remember whether -unit size or format comes first; either order will work. The output -specifications `4xw' and `4wx' mean exactly the same thing. (However, -the count N must come first; `wx4' will not work.) - - Even though the unit size U is ignored for the formats `s' and `i', -you might still want to use a count N; for example, `3i' specifies that -you want to see three machine instructions, including any operands. -The command `disassemble' gives an alternative way of inspecting -machine instructions; *note Source and machine code: Machine Code.. - - All the defaults for the arguments to `x' are designed to make it -easy to continue scanning memory with minimal specifications each time -you use `x'. For example, after you have inspected three machine -instructions with `x/3i ADDR', you can inspect the next seven with just -`x/7'. If you use RET to repeat the `x' command, the repeat count N is -used again; the other arguments default as for successive uses of `x'. - - The addresses and contents printed by the `x' command are not saved -in the value history because there is often too much of them and they -would get in the way. Instead, GDB makes these values available for -subsequent use in expressions as values of the convenience variables -`$_' and `$__'. After an `x' command, the last address examined is -available for use in expressions in the convenience variable `$_'. The -contents of that address, as examined, are available in the convenience -variable `$__'. - - If the `x' command has a repeat count, the address and contents saved -are from the last memory unit printed; this is not the same as the last -address printed if several units were printed on the last line of -output. - - -File: gdb.info, Node: Auto Display, Next: Print Settings, Prev: Memory, Up: Data - -Automatic display -================= - - If you find that you want to print the value of an expression -frequently (to see how it changes), you might want to add it to the -"automatic display list" so that GDB will print its value each time -your program stops. Each expression added to the list is given a -number to identify it; to remove an expression from the list, you -specify that number. The automatic display looks like this: - - 2: foo = 38 - 3: bar[5] = (struct hack *) 0x3804 - -This display shows item numbers, expressions and their current values. -As with displays you request manually using `x' or `print', you can -specify the output format you prefer; in fact, `display' decides -whether to use `print' or `x' depending on how elaborate your format -specification is--it uses `x' if you specify a unit size, or one of the -two formats (`i' and `s') that are only supported by `x'; otherwise it -uses `print'. - -`display EXP' - Add the expression EXP to the list of expressions to display each - time your program stops. *Note Expressions: Expressions. - - `display' will not repeat if you press RET again after using it. - -`display/FMT EXP' - For FMT specifying only a display format and not a size or count, - add the expression EXP to the auto-display list but arrange to - display it each time in the specified format FMT. *Note Output - formats: Output Formats. - -`display/FMT ADDR' - For FMT `i' or `s', or including a unit-size or a number of units, - add the expression ADDR as a memory address to be examined each - time your program stops. Examining means in effect doing `x/FMT - ADDR'. *Note Examining memory: Memory. - - For example, `display/i $pc' can be helpful, to see the machine -instruction about to be executed each time execution stops (`$pc' is a -common name for the program counter; *note Registers::.). - -`undisplay DNUMS...' -`delete display DNUMS...' - Remove item numbers DNUMS from the list of expressions to display. - - `undisplay' will not repeat if you press RET after using it. - (Otherwise you would just get the error `No display number ...'.) - -`disable display DNUMS...' - Disable the display of item numbers DNUMS. A disabled display - item is not printed automatically, but is not forgotten. It may be - enabled again later. - -`enable display DNUMS...' - Enable display of item numbers DNUMS. It becomes effective once - again in auto display of its expression, until you specify - otherwise. - -`display' - Display the current values of the expressions on the list, just as - is done when your program stops. - -`info display' - Print the list of expressions previously set up to display - automatically, each one with its item number, but without showing - the values. This includes disabled expressions, which are marked - as such. It also includes expressions which would not be - displayed right now because they refer to automatic variables not - currently available. - - If a display expression refers to local variables, then it does not -make sense outside the lexical context for which it was set up. Such an -expression is disabled when execution enters a context where one of its -variables is not defined. For example, if you give the command -`display last_char' while inside a function with an argument -`last_char', then this argument will be displayed while your program -continues to stop inside that function. When it stops elsewhere--where -there is no variable `last_char'--display is disabled. The next time -your program stops where `last_char' is meaningful, you can enable the -display expression once again. - - -File: gdb.info, Node: Print Settings, Next: Value History, Prev: Auto Display, Up: Data - -Print settings -============== - - GDB provides the following ways to control how arrays, structures, -and symbols are printed. - -These settings are useful for debugging programs in any language: - -`set print address' -`set print address on' - GDB will print memory addresses showing the location of stack - traces, structure values, pointer values, breakpoints, and so - forth, even when it also displays the contents of those addresses. - The default is on. For example, this is what a stack frame - display looks like, with `set print address on': - - (gdb) f - #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>") - at input.c:530 - 530 if (lquote != def_lquote) - -`set print address off' - Do not print addresses when displaying their contents. For - example, this is the same stack frame displayed with `set print - address off': - - (gdb) set print addr off - (gdb) f - #0 set_quotes (lq="<<", rq=">>") at input.c:530 - 530 if (lquote != def_lquote) - - You can use `set print address off' to eliminate all machine - dependent displays from the GDB interface. For example, with - `print address off', you should get the same text for backtraces on - all machines--whether or not they involve pointer arguments. - -`show print address' - Show whether or not addresses are to be printed. - - When GDB prints a symbolic address, it normally prints the closest -earlier symbol plus an offset. If that symbol does not uniquely -identify the address (for example, it is a name whose scope is a single -source file), you may need to disambiguate. One way to do this is with -`info line', for example `info line *0x4537'. Alternately, you can set -GDB to print the source file and line number when it prints a symbolic -address: - -`set print symbol-filename on' - Tell GDB to print the source file name and line number of a symbol - in the symbolic form of an address. - -`set print symbol-filename off' - Do not print source file name and line number of a symbol. This - is the default. - -`show print symbol-filename' - Show whether or not GDB will print the source file name and line - number of a symbol in the symbolic form of an address. - - Also, you may wish to see the symbolic form only if the address being -printed is reasonably close to the closest earlier symbol: - -`set print max-symbolic-offset MAX-OFFSET' - Tell GDB to only display the symbolic form of an address if the - offset between the closest earlier symbol and the address is less - than MAX-OFFSET. The default is 0, which means to always print the - symbolic form of an address, if any symbol precedes it. - -`show print max-symbolic-offset' - Ask how large the maximum offset is that GDB will print in a - symbolic address. - -`set print array' -`set print array on' - GDB will pretty-print arrays. This format is more convenient to - read, but uses more space. The default is off. - -`set print array off' - Return to compressed format for arrays. - -`show print array' - Show whether compressed or pretty format is selected for displaying - arrays. - -`set print elements NUMBER-OF-ELEMENTS' - If GDB is printing a large array, it will stop printing after it - has printed the number of elements set by the `set print elements' - command. This limit also applies to the display of strings. - Setting the number of elements to zero means that the printing is - unlimited. - -`show print elements' - Display the number of elements of a large array that GDB will print - before losing patience. - -`set print pretty on' - Cause GDB to print structures in an indented format with one - member per line, like this: - - $1 = { - next = 0x0, - flags = { - sweet = 1, - sour = 1 - }, - meat = 0x54 "Pork" - } - -`set print pretty off' - Cause GDB to print structures in a compact format, like this: - - $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \ - meat = 0x54 "Pork"} - - This is the default format. - -`show print pretty' - Show which format GDB will use to print structures. - -`set print sevenbit-strings on' - Print using only seven-bit characters; if this option is set, GDB - will display any eight-bit characters (in strings or character - values) using the notation `\'NNN. For example, `M-a' is - displayed as `\341'. - -`set print sevenbit-strings off' - Print using either seven-bit or eight-bit characters, as required. - This is the default. - -`show print sevenbit-strings' - Show whether or not GDB will print only seven-bit characters. - -`set print union on' - Tell GDB to print unions which are contained in structures. This - is the default setting. - -`set print union off' - Tell GDB not to print unions which are contained in structures. - -`show print union' - Ask GDB whether or not it will print unions which are contained in - structures. - - For example, given the declarations - - typedef enum {Tree, Bug} Species; - typedef enum {Big_tree, Acorn, Seedling} Tree_forms; - typedef enum {Caterpillar, Cocoon, Butterfly} - Bug_forms; - - struct thing { - Species it; - union { - Tree_forms tree; - Bug_forms bug; - } form; - }; - - struct thing foo = {Tree, {Acorn}}; - - with `set print union on' in effect `p foo' would print - - $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}} - - and with `set print union off' in effect it would print - - $1 = {it = Tree, form = {...}} - -These settings are of interest when debugging C++ programs: - -`set print demangle' -`set print demangle on' - Print C++ names in their source form rather than in the encoded - ("mangled") form passed to the assembler and linker for type-safe - linkage. The default is `on'. - -`show print demangle' - Show whether C++ names will be printed in mangled or demangled - form. - -`set print asm-demangle' -`set print asm-demangle on' - Print C++ names in their source form rather than their mangled - form, even in assembler code printouts such as instruction - disassemblies. The default is off. - -`show print asm-demangle' - Show whether C++ names in assembly listings will be printed in - mangled or demangled form. - -`set demangle-style STYLE' - Choose among several encoding schemes used by different compilers - to represent C++ names. The choices for STYLE are currently: - - `auto' - Allow GDB to choose a decoding style by inspecting your - program. - - `gnu' - Decode based on the GNU C++ compiler (`g++') encoding - algorithm. - - `lucid' - Decode based on the Lucid C++ compiler (`lcc') encoding - algorithm. - - `arm' - Decode using the algorithm in the `C++ Annotated Reference - Manual'. *Warning:* this setting alone is not sufficient to - allow debugging `cfront'-generated executables. GDB would - require further enhancement to permit that. - -`show demangle-style' - Display the encoding style currently in use for decoding C++ - symbols. - -`set print object' -`set print object on' - When displaying a pointer to an object, identify the *actual* - (derived) type of the object rather than the *declared* type, using - the virtual function table. - -`set print object off' - Display only the declared type of objects, without reference to the - virtual function table. This is the default setting. - -`show print object' - Show whether actual, or declared, object types will be displayed. - -`set print vtbl' -`set print vtbl on' - Pretty print C++ virtual function tables. The default is off. - -`set print vtbl off' - Do not pretty print C++ virtual function tables. - -`show print vtbl' - Show whether C++ virtual function tables are pretty printed, or - not. - - -File: gdb.info, Node: Value History, Next: Convenience Vars, Prev: Print Settings, Up: Data - -Value history -============= - - Values printed by the `print' command are saved in the GDB "value -history" so that you can refer to them in other expressions. Values are -kept until the symbol table is re-read or discarded (for example with -the `file' or `symbol-file' commands). When the symbol table changes, -the value history is discarded, since the values may contain pointers -back to the types defined in the symbol table. - - The values printed are given "history numbers" by which you can -refer to them. These are successive integers starting with one. -`print' shows you the history number assigned to a value by printing -`$NUM = ' before the value; here NUM is the history number. - - To refer to any previous value, use `$' followed by the value's -history number. The way `print' labels its output is designed to -remind you of this. Just `$' refers to the most recent value in the -history, and `$$' refers to the value before that. `$$N' refers to the -Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is -equivalent to `$$', and `$$0' is equivalent to `$'. - - For example, suppose you have just printed a pointer to a structure -and want to see the contents of the structure. It suffices to type - - p *$ - - If you have a chain of structures where the component `next' points -to the next one, you can print the contents of the next one with this: - - p *$.next - -You can print successive links in the chain by repeating this -command--which you can do by just typing RET. - - Note that the history records values, not expressions. If the value -of `x' is 4 and you type these commands: - - print x - set x=5 - -then the value recorded in the value history by the `print' command -remains 4 even though the value of `x' has changed. - -`show values' - Print the last ten values in the value history, with their item - numbers. This is like `p $$9' repeated ten times, except that - `show values' does not change the history. - -`show values N' - Print ten history values centered on history item number N. - -`show values +' - Print ten history values just after the values last printed. If - no more values are available, produces no display. - - Pressing RET to repeat `show values N' has exactly the same effect -as `show values +'. - - -File: gdb.info, Node: Convenience Vars, Next: Registers, Prev: Value History, Up: Data - -Convenience variables -===================== - - GDB provides "convenience variables" that you can use within GDB to -hold on to a value and refer to it later. These variables exist -entirely within GDB; they are not part of your program, and setting a -convenience variable has no direct effect on further execution of your -program. That is why you can use them freely. - - Convenience variables are prefixed with `$'. Any name preceded by -`$' can be used for a convenience variable, unless it is one of the -predefined machine-specific register names (*note Registers::.). -(Value history references, in contrast, are *numbers* preceded by `$'. -*Note Value history: Value History.) - - You can save a value in a convenience variable with an assignment -expression, just as you would set a variable in your program. For -example: - - set $foo = *object_ptr - -would save in `$foo' the value contained in the object pointed to by -`object_ptr'. - - Using a convenience variable for the first time creates it, but its -value is `void' until you assign a new value. You can alter the value -with another assignment at any time. - - Convenience variables have no fixed types. You can assign a -convenience variable any type of value, including structures and -arrays, even if that variable already has a value of a different type. -The convenience variable, when used as an expression, has the type of -its current value. - -`show convenience' - Print a list of convenience variables used so far, and their - values. Abbreviated `show con'. - - One of the ways to use a convenience variable is as a counter to be -incremented or a pointer to be advanced. For example, to print a field -from successive elements of an array of structures: - - set $i = 0 - print bar[$i++]->contents - ... repeat that command by typing RET. - - Some convenience variables are created automatically by GDB and given -values likely to be useful. - -`$_' - The variable `$_' is automatically set by the `x' command to the - last address examined (*note Examining memory: Memory.). Other - commands which provide a default address for `x' to examine also - set `$_' to that address; these commands include `info line' and - `info breakpoint'. The type of `$_' is `void *' except when set - by the `x' command, in which case it is a pointer to the type of - `$__'. - -`$__' - The variable `$__' is automatically set by the `x' command to the - value found in the last address examined. Its type is chosen to - match the format in which the data was printed. - diff --git a/gnu/usr.bin/gdb/doc/gdb.info-4 b/gnu/usr.bin/gdb/doc/gdb.info-4 deleted file mode 100644 index b0758fa..0000000 --- a/gnu/usr.bin/gdb/doc/gdb.info-4 +++ /dev/null @@ -1,1349 +0,0 @@ -This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input -file gdb.texinfo. - -START-INFO-DIR-ENTRY -* Gdb:: The GNU debugger. -END-INFO-DIR-ENTRY - This file documents the GNU debugger GDB. - - This is Edition 4.09, August 1993, of `Debugging with GDB: the GNU -Source-Level Debugger' for GDB Version 4.11. - - Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software -Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the entire resulting derived work is distributed under the terms -of a permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions. - - -File: gdb.info, Node: Registers, Next: Floating Point Hardware, Prev: Convenience Vars, Up: Data - -Registers -========= - - You can refer to machine register contents, in expressions, as -variables with names starting with `$'. The names of registers are -different for each machine; use `info registers' to see the names used -on your machine. - -`info registers' - Print the names and values of all registers except floating-point - registers (in the selected stack frame). - -`info all-registers' - Print the names and values of all registers, including - floating-point registers. - -`info registers REGNAME ...' - Print the relativized value of each specified register REGNAME. - rEGNAME may be any register name valid on the machine you are - using, with or without the initial `$'. - - GDB has four "standard" register names that are available (in -expressions) on most machines--whenever they do not conflict with an -architecture's canonical mnemonics for registers. The register names -`$pc' and `$sp' are used for the program counter register and the stack -pointer. `$fp' is used for a register that contains a pointer to the -current stack frame, and `$ps' is used for a register that contains the -processor status. For example, you could print the program counter in -hex with - - p/x $pc - -or print the instruction to be executed next with - - x/i $pc - -or add four to the stack pointer(1) with - - set $sp += 4 - - Whenever possible, these four standard register names are available -on your machine even though the machine has different canonical -mnemonics, so long as there is no conflict. The `info registers' -command shows the canonical names. For example, on the SPARC, `info -registers' displays the processor status register as `$psr' but you can -also refer to it as `$ps'. - - GDB always considers the contents of an ordinary register as an -integer when the register is examined in this way. Some machines have -special registers which can hold nothing but floating point; these -registers are considered to have floating point values. There is no way -to refer to the contents of an ordinary register as floating point value -(although you can *print* it as a floating point value with `print/f -$REGNAME'). - - Some registers have distinct "raw" and "virtual" data formats. This -means that the data format in which the register contents are saved by -the operating system is not the same one that your program normally -sees. For example, the registers of the 68881 floating point -coprocessor are always saved in "extended" (raw) format, but all C -programs expect to work with "double" (virtual) format. In such cases, -GDB normally works with the virtual format only (the format that makes -sense for your program), but the `info registers' command prints the -data in both formats. - - Normally, register values are relative to the selected stack frame -(*note Selecting a frame: Selection.). This means that you get the -value that the register would contain if all stack frames farther in -were exited and their saved registers restored. In order to see the -true contents of hardware registers, you must select the innermost -frame (with `frame 0'). - - However, GDB must deduce where registers are saved, from the machine -code generated by your compiler. If some registers are not saved, or if -GDB is unable to locate the saved registers, the selected stack frame -will make no difference. - -`set rstack_high_address ADDRESS' - On AMD 29000 family processors, registers are saved in a separate - "register stack". There is no way for GDB to determine the extent - of this stack. Normally, GDB just assumes that the stack is "large - enough". This may result in GDB referencing memory locations that - do not exist. If necessary, you can get around this problem by - specifying the ending address of the register stack with the `set - rstack_high_address' command. The argument should be an address, - which you will probably want to precede with `0x' to specify in - hexadecimal. - -`show rstack_high_address' - Display the current limit of the register stack, on AMD 29000 - family processors. - - ---------- Footnotes ---------- - - (1) This is a way of removing one word from the stack, on machines -where stacks grow downward in memory (most machines, nowadays). This -assumes that the innermost stack frame is selected; setting `$sp' is -not allowed when other stack frames are selected. To pop entire frames -off the stack, regardless of machine architecture, use `return'; *note -Returning from a function: Returning.. - - -File: gdb.info, Node: Floating Point Hardware, Prev: Registers, Up: Data - -Floating point hardware -======================= - - Depending on the host machine architecture, GDB may be able to give -you more information about the status of the floating point hardware. - -`info float' - Display hardware-dependent information about the floating point - unit. The exact contents and layout vary depending on the - floating point chip; on some platforms, `info float' is not - available at all. - - -File: gdb.info, Node: Languages, Next: Symbols, Prev: Data, Up: Top - -Using GDB with Different Languages -********************************** - - Although programming languages generally have common aspects, they -are rarely expressed in the same manner. For instance, in ANSI C, -dereferencing a pointer `p' is accomplished by `*p', but in Modula-2, -it is accomplished by `p^'. Values can also be represented (and -displayed) differently. Hex numbers in C are written like `0x1ae', -while in Modula-2 they appear as `1AEH'. - - Language-specific information is built into GDB for some languages, -allowing you to express operations like the above in your program's -native language, and allowing GDB to output values in a manner -consistent with the syntax of your program's native language. The -language you use to build expressions, called the "working language", -can be selected manually, or GDB can set it automatically. - -* Menu: - -* Setting:: Switching between source languages -* Show:: Displaying the language - -* Checks:: Type and range checks - -* Support:: Supported languages - - -File: gdb.info, Node: Setting, Next: Show, Up: Languages - -Switching between source languages -================================== - - There are two ways to control the working language--either have GDB -set it automatically, or select it manually yourself. You can use the -`set language' command for either purpose. On startup, GDB defaults to -setting the language automatically. - -* Menu: - -* Manually:: Setting the working language manually -* Automatically:: Having GDB infer the source language - - -File: gdb.info, Node: Manually, Next: Automatically, Up: Setting - -Setting the working language ----------------------------- - - If you allow GDB to set the language automatically, expressions are -interpreted the same way in your debugging session and your program. - - If you wish, you may set the language manually. To do this, issue -the command `set language LANG', where LANG is the name of a language, -such as `c' or `modula-2'. For a list of the supported languages, type -`set language'. - - Setting the language manually prevents GDB from updating the working -language automatically. This can lead to confusion if you try to debug -a program when the working language is not the same as the source -language, when an expression is acceptable to both languages--but means -different things. For instance, if the current source file were -written in C, and GDB was parsing Modula-2, a command such as: - - print a = b + c - -might not have the effect you intended. In C, this means to add `b' -and `c' and place the result in `a'. The result printed would be the -value of `a'. In Modula-2, this means to compare `a' to the result of -`b+c', yielding a `BOOLEAN' value. - - -File: gdb.info, Node: Automatically, Prev: Manually, Up: Setting - -Having GDB infer the source language ------------------------------------- - - To have GDB set the working language automatically, use `set -language local' or `set language auto'. GDB then infers the language -that a program was written in by looking at the name of its source -files, and examining their extensions: - -`*.mod' - Modula-2 source file - -`*.c' - C source file - -`*.C' -`*.cc' - C++ source file - - This information is recorded for each function or procedure in a -source file. When your program stops in a frame (usually by -encountering a breakpoint), GDB sets the working language to the -language recorded for the function in that frame. If the language for -a frame is unknown (that is, if the function or block corresponding to -the frame was defined in a source file that does not have a recognized -extension), the current working language is not changed, and GDB issues -a warning. - - This may not seem necessary for most programs, which are written -entirely in one source language. However, program modules and libraries -written in one source language can be used by a main program written in -a different source language. Using `set language auto' in this case -frees you from having to set the working language manually. - - -File: gdb.info, Node: Show, Next: Checks, Prev: Setting, Up: Languages - -Displaying the language -======================= - - The following commands will help you find out which language is the -working language, and also what language source files were written in. - -`show language' - Display the current working language. This is the language you - can use with commands such as `print' to build and compute - expressions that may involve variables in your program. - -`info frame' - Among the other information listed here (*note Information about a - frame: Frame Info.) is the source language for this frame. This - is the language that will become the working language if you ever - use an identifier that is in this frame. - -`info source' - Among the other information listed here (*note Examining the - Symbol Table: Symbols.) is the source language of this source file. - - -File: gdb.info, Node: Checks, Next: Support, Prev: Show, Up: Languages - -Type and range checking -======================= - - *Warning:* In this release, the GDB commands for type and range - checking are included, but they do not yet have any effect. This - section documents the intended facilities. - - Some languages are designed to guard you against making seemingly -common errors through a series of compile- and run-time checks. These -include checking the type of arguments to functions and operators, and -making sure mathematical overflows are caught at run time. Checks such -as these help to ensure a program's correctness once it has been -compiled by eliminating type mismatches, and providing active checks -for range errors when your program is running. - - GDB can check for conditions like the above if you wish. Although -GDB will not check the statements in your program, it can check -expressions entered directly into GDB for evaluation via the `print' -command, for example. As with the working language, GDB can also -decide whether or not to check automatically based on your program's -source language. *Note Supported languages: Support, for the default -settings of supported languages. - -* Menu: - -* Type Checking:: An overview of type checking -* Range Checking:: An overview of range checking - - -File: gdb.info, Node: Type Checking, Next: Range Checking, Up: Checks - -An overview of type checking ----------------------------- - - Some languages, such as Modula-2, are strongly typed, meaning that -the arguments to operators and functions have to be of the correct type, -otherwise an error occurs. These checks prevent type mismatch errors -from ever causing any run-time problems. For example, - - 1 + 2 => 3 -but - error--> 1 + 2.3 - - The second example fails because the `CARDINAL' 1 is not -type-compatible with the `REAL' 2.3. - - For expressions you use in GDB commands, you can tell the GDB type -checker to skip checking; to treat any mismatches as errors and abandon -the expression; or only issue warnings when type mismatches occur, but -evaluate the expression anyway. When you choose the last of these, GDB -evaluates expressions like the second example above, but also issues a -warning. - - Even though you may turn type checking off, other type-based reasons -may prevent GDB from evaluating an expression. For instance, GDB does -not know how to add an `int' and a `struct foo'. These particular type -errors have nothing to do with the language in use, and usually arise -from expressions, such as the one described above, which make little -sense to evaluate anyway. - - Each language defines to what degree it is strict about type. For -instance, both Modula-2 and C require the arguments to arithmetical -operators to be numbers. In C, enumerated types and pointers can be -represented as numbers, so that they are valid arguments to mathematical -operators. *Note Supported languages: Support, for further details on -specific languages. - - GDB provides some additional commands for controlling the type -checker: - -`set check type auto' - Set type checking on or off based on the current working language. - *Note Supported languages: Support, for the default settings for - each language. - -`set check type on' -`set check type off' - Set type checking on or off, overriding the default setting for the - current working language. Issue a warning if the setting does not - match the language default. If any type mismatches occur in - evaluating an expression while typechecking is on, GDB prints a - message and aborts evaluation of the expression. - -`set check type warn' - Cause the type checker to issue warnings, but to always attempt to - evaluate the expression. Evaluating the expression may still be - impossible for other reasons. For example, GDB cannot add numbers - and structures. - -`show type' - Show the current setting of the type checker, and whether or not - GDB is setting it automatically. - - -File: gdb.info, Node: Range Checking, Prev: Type Checking, Up: Checks - -An overview of range checking ------------------------------ - - In some languages (such as Modula-2), it is an error to exceed the -bounds of a type; this is enforced with run-time checks. Such range -checking is meant to ensure program correctness by making sure -computations do not overflow, or indices on an array element access do -not exceed the bounds of the array. - - For expressions you use in GDB commands, you can tell GDB to treat -range errors in one of three ways: ignore them, always treat them as -errors and abandon the expression, or issue warnings but evaluate the -expression anyway. - - A range error can result from numerical overflow, from exceeding an -array index bound, or when you type a constant that is not a member of -any type. Some languages, however, do not treat overflows as an error. -In many implementations of C, mathematical overflow causes the result -to "wrap around" to lower values--for example, if M is the largest -integer value, and S is the smallest, then - - M + 1 => S - - This, too, is specific to individual languages, and in some cases -specific to individual compilers or machines. *Note Supported -languages: Support, for further details on specific languages. - - GDB provides some additional commands for controlling the range -checker: - -`set check range auto' - Set range checking on or off based on the current working language. - *Note Supported languages: Support, for the default settings for - each language. - -`set check range on' -`set check range off' - Set range checking on or off, overriding the default setting for - the current working language. A warning is issued if the setting - does not match the language default. If a range error occurs, - then a message is printed and evaluation of the expression is - aborted. - -`set check range warn' - Output messages when the GDB range checker detects a range error, - but attempt to evaluate the expression anyway. Evaluating the - expression may still be impossible for other reasons, such as - accessing memory that the process does not own (a typical example - from many Unix systems). - -`show range' - Show the current setting of the range checker, and whether or not - it is being set automatically by GDB. - - -File: gdb.info, Node: Support, Prev: Checks, Up: Languages - -Supported languages -=================== - - GDB 4 supports C, C++, and Modula-2. Some GDB features may be used -in expressions regardless of the language you use: the GDB `@' and `::' -operators, and the `{type}addr' construct (*note Expressions: -Expressions.) can be used with the constructs of any supported language. - - The following sections detail to what degree each source language is -supported by GDB. These sections are not meant to be language -tutorials or references, but serve only as a reference guide to what the -GDB expression parser will accept, and what input and output formats -should look like for different languages. There are many good books -written on each of these languages; please look to these for a language -reference or tutorial. - -* Menu: - -* C:: C and C++ -* Modula-2:: Modula-2 - - -File: gdb.info, Node: C, Next: Modula-2, Up: Support - -C and C++ ---------- - - Since C and C++ are so closely related, many features of GDB apply -to both languages. Whenever this is the case, we discuss both languages -together. - - The C++ debugging facilities are jointly implemented by the GNU C++ -compiler and GDB. Therefore, to debug your C++ code effectively, you -must compile your C++ programs with the GNU C++ compiler, `g++'. - -* Menu: - -* C Operators:: C and C++ operators -* C Constants:: C and C++ constants -* Cplus expressions:: C++ expressions -* C Defaults:: Default settings for C and C++ - -* C Checks:: C and C++ type and range checks - -* Debugging C:: GDB and C -* Debugging C plus plus:: Special features for C++ - - -File: gdb.info, Node: C Operators, Next: C Constants, Up: C - -C and C++ operators -------------------- - - Operators must be defined on values of specific types. For instance, -`+' is defined on numbers, but not on structures. Operators are often -defined on groups of types. - - For the purposes of C and C++, the following definitions hold: - - * *Integral types* include `int' with any of its storage-class - specifiers; `char'; and `enum'. - - * *Floating-point types* include `float' and `double'. - - * *Pointer types* include all types defined as `(TYPE *)'. - - * *Scalar types* include all of the above. - -The following operators are supported. They are listed here in order -of increasing precedence: - -`,' - The comma or sequencing operator. Expressions in a - comma-separated list are evaluated from left to right, with the - result of the entire expression being the last expression - evaluated. - -`=' - Assignment. The value of an assignment expression is the value - assigned. Defined on scalar types. - -`OP=' - Used in an expression of the form `A OP= B', and translated to - `A = A OP B'. `OP=' and `=' have the same precendence. OP is any - one of the operators `|', `^', `&', `<<', `>>', `+', `-', `*', - `/', `%'. - -`?:' - The ternary operator. `A ? B : C' can be thought of as: if A - then B else C. A should be of an integral type. - -`||' - Logical OR. Defined on integral types. - -`&&' - Logical AND. Defined on integral types. - -`|' - Bitwise OR. Defined on integral types. - -`^' - Bitwise exclusive-OR. Defined on integral types. - -`&' - Bitwise AND. Defined on integral types. - -`==, !=' - Equality and inequality. Defined on scalar types. The value of - these expressions is 0 for false and non-zero for true. - -`<, >, <=, >=' - Less than, greater than, less than or equal, greater than or equal. - Defined on scalar types. The value of these expressions is 0 for - false and non-zero for true. - -`<<, >>' - left shift, and right shift. Defined on integral types. - -`@' - The GDB "artificial array" operator (*note Expressions: - Expressions.). - -`+, -' - Addition and subtraction. Defined on integral types, - floating-point types and pointer types. - -`*, /, %' - Multiplication, division, and modulus. Multiplication and - division are defined on integral and floating-point types. - Modulus is defined on integral types. - -`++, --' - Increment and decrement. When appearing before a variable, the - operation is performed before the variable is used in an - expression; when appearing after it, the variable's value is used - before the operation takes place. - -`*' - Pointer dereferencing. Defined on pointer types. Same precedence - as `++'. - -`&' - Address operator. Defined on variables. Same precedence as `++'. - - For debugging C++, GDB implements a use of `&' beyond what is - allowed in the C++ language itself: you can use `&(&REF)' (or, if - you prefer, simply `&&REF') to examine the address where a C++ - reference variable (declared with `&REF') is stored. - -`-' - Negative. Defined on integral and floating-point types. Same - precedence as `++'. - -`!' - Logical negation. Defined on integral types. Same precedence as - `++'. - -`~' - Bitwise complement operator. Defined on integral types. Same - precedence as `++'. - -`., ->' - Structure member, and pointer-to-structure member. For - convenience, GDB regards the two as equivalent, choosing whether - to dereference a pointer based on the stored type information. - Defined on `struct' and `union' data. - -`[]' - Array indexing. `A[I]' is defined as `*(A+I)'. Same precedence - as `->'. - -`()' - Function parameter list. Same precedence as `->'. - -`::' - C++ scope resolution operator. Defined on `struct', `union', and - `class' types. - -`::' - Doubled colons also represent the GDB scope operator (*note - Expressions: Expressions.). Same precedence as `::', above. - - -File: gdb.info, Node: C Constants, Next: Cplus expressions, Prev: C Operators, Up: C - -C and C++ constants -------------------- - - GDB allows you to express the constants of C and C++ in the -following ways: - - * Integer constants are a sequence of digits. Octal constants are - specified by a leading `0' (ie. zero), and hexadecimal constants by - a leading `0x' or `0X'. Constants may also end with a letter `l', - specifying that the constant should be treated as a `long' value. - - * Floating point constants are a sequence of digits, followed by a - decimal point, followed by a sequence of digits, and optionally - followed by an exponent. An exponent is of the form: - `e[[+]|-]NNN', where NNN is another sequence of digits. The `+' - is optional for positive exponents. - - * Enumerated constants consist of enumerated identifiers, or their - integral equivalents. - - * Character constants are a single character surrounded by single - quotes (`''), or a number--the ordinal value of the corresponding - character (usually its ASCII value). Within quotes, the single - character may be represented by a letter or by "escape sequences", - which are of the form `\NNN', where NNN is the octal representation - of the character's ordinal value; or of the form `\X', where `X' - is a predefined special character--for example, `\n' for newline. - - * String constants are a sequence of character constants surrounded - by double quotes (`"'). - - * Pointer constants are an integral value. You can also write - pointers to constants using the C operator `&'. - - * Array constants are comma-separated lists surrounded by braces `{' - and `}'; for example, `{1,2,3}' is a three-element array of - integers, `{{1,2}, {3,4}, {5,6}}' is a three-by-two array, and - `{&"hi", &"there", &"fred"}' is a three-element array of pointers. - - -File: gdb.info, Node: Cplus expressions, Next: C Defaults, Prev: C Constants, Up: C - -C++ expressions ---------------- - - GDB expression handling has a number of extensions to interpret a -significant subset of C++ expressions. - - *Warning:* Most of these extensions depend on the use of additional - debugging information in the symbol table, and thus require a rich, - extendable object code format. In particular, if your system uses - a.out, MIPS ECOFF, RS/6000 XCOFF, or Sun ELF with stabs extensions - to the symbol table, these facilities are all available. Where - the object code format is standard COFF, on the other hand, most - of the C++ support in GDB will *not* work, nor can it. For the - standard SVr4 debugging format, DWARF in ELF, the standard is - still evolving, so the C++ support in GDB is still fragile; when - this debugging format stabilizes, however, C++ support will also - be available on systems that use it. - - 1. Member function calls are allowed; you can use expressions like - - count = aml->GetOriginal(x, y) - - 2. While a member function is active (in the selected stack frame), - your expressions have the same namespace available as the member - function; that is, GDB allows implicit references to the class - instance pointer `this' following the same rules as C++. - - 3. You can call overloaded functions; GDB will resolve the function - call to the right definition, with one restriction--you must use - arguments of the type required by the function that you want to - call. GDB will not perform conversions requiring constructors or - user-defined type operators. - - 4. GDB understands variables declared as C++ references; you can use - them in expressions just as you do in C++ source--they are - automatically dereferenced. - - In the parameter list shown when GDB displays a frame, the values - of reference variables are not displayed (unlike other variables); - this avoids clutter, since references are often used for large - structures. The *address* of a reference variable is always - shown, unless you have specified `set print address off'. - - 5. GDB supports the C++ name resolution operator `::'--your - expressions can use it just as expressions in your program do. - Since one scope may be defined in another, you can use `::' - repeatedly if necessary, for example in an expression like - `SCOPE1::SCOPE2::NAME'. GDB also allows resolving name scope by - reference to source files, in both C and C++ debugging (*note - Program variables: Variables.). - - -File: gdb.info, Node: C Defaults, Next: C Checks, Prev: Cplus expressions, Up: C - -C and C++ defaults ------------------- - - If you allow GDB to set type and range checking automatically, they -both default to `off' whenever the working language changes to C or -C++. This happens regardless of whether you, or GDB, selected the -working language. - - If you allow GDB to set the language automatically, it sets the -working language to C or C++ on entering code compiled from a source -file whose name ends with `.c', `.C', or `.cc'. *Note Having GDB infer -the source language: Automatically, for further details. - - -File: gdb.info, Node: C Checks, Next: Debugging C, Prev: C Defaults, Up: C - -C and C++ type and range checks -------------------------------- - - By default, when GDB parses C or C++ expressions, type checking is -not used. However, if you turn type checking on, GDB will consider two -variables type equivalent if: - - * The two variables are structured and have the same structure, - union, or enumerated tag. - - * Two two variables have the same type name, or types that have been - declared equivalent through `typedef'. - - Range checking, if turned on, is done on mathematical operations. -Array indices are not checked, since they are often used to index a -pointer that is not itself an array. - - -File: gdb.info, Node: Debugging C, Next: Debugging C plus plus, Prev: C Checks, Up: C - -GDB and C ---------- - - The `set print union' and `show print union' commands apply to the -`union' type. When set to `on', any `union' that is inside a `struct' -or `class' will also be printed. Otherwise, it will appear as `{...}'. - - The `@' operator aids in the debugging of dynamic arrays, formed -with pointers and a memory allocation function. *Note Expressions: -Expressions. - - -File: gdb.info, Node: Debugging C plus plus, Prev: Debugging C, Up: C - -GDB features for C++ --------------------- - - Some GDB commands are particularly useful with C++, and some are -designed specifically for use with C++. Here is a summary: - -`breakpoint menus' - When you want a breakpoint in a function whose name is overloaded, - GDB breakpoint menus help you specify which function definition - you want. *Note Breakpoint menus: Breakpoint Menus. - -`rbreak REGEX' - Setting breakpoints using regular expressions is helpful for - setting breakpoints on overloaded functions that are not members - of any special classes. *Note Setting breakpoints: Set Breaks. - -`catch EXCEPTIONS' -`info catch' - Debug C++ exception handling using these commands. *Note - Breakpoints and exceptions: Exception Handling. - -`ptype TYPENAME' - Print inheritance relationships as well as other information for - type TYPENAME. *Note Examining the Symbol Table: Symbols. - -`set print demangle' -`show print demangle' -`set print asm-demangle' -`show print asm-demangle' - Control whether C++ symbols display in their source form, both when - displaying code as C++ source and when displaying disassemblies. - *Note Print settings: Print Settings. - -`set print object' -`show print object' - Choose whether to print derived (actual) or declared types of - objects. *Note Print settings: Print Settings. - -`set print vtbl' -`show print vtbl' - Control the format for printing virtual function tables. *Note - Print settings: Print Settings. - -`Overloaded symbol names' - You can specify a particular definition of an overloaded symbol, - using the same notation that is used to declare such symbols in - C++: type `SYMBOL(TYPES)' rather than just SYMBOL. You can also - use the GDB command-line word completion facilities to list the - available choices, or to finish the type list for you. *Note - Command completion: Completion, for details on how to do this. - - -File: gdb.info, Node: Modula-2, Prev: C, Up: Support - -Modula-2 --------- - - The extensions made to GDB to support Modula-2 only support output -from the GNU Modula-2 compiler (which is currently being developed). -Other Modula-2 compilers are not currently supported, and attempting to -debug executables produced by them will most likely result in an error -as GDB reads in the executable's symbol table. - -* Menu: - -* M2 Operators:: Built-in operators -* Built-In Func/Proc:: Built-in functions and procedures -* M2 Constants:: Modula-2 constants -* M2 Defaults:: Default settings for Modula-2 -* Deviations:: Deviations from standard Modula-2 -* M2 Checks:: Modula-2 type and range checks -* M2 Scope:: The scope operators `::' and `.' -* GDB/M2:: GDB and Modula-2 - - -File: gdb.info, Node: M2 Operators, Next: Built-In Func/Proc, Up: Modula-2 - -Operators ---------- - - Operators must be defined on values of specific types. For instance, -`+' is defined on numbers, but not on structures. Operators are often -defined on groups of types. For the purposes of Modula-2, the -following definitions hold: - - * *Integral types* consist of `INTEGER', `CARDINAL', and their - subranges. - - * *Character types* consist of `CHAR' and its subranges. - - * *Floating-point types* consist of `REAL'. - - * *Pointer types* consist of anything declared as `POINTER TO TYPE'. - - * *Scalar types* consist of all of the above. - - * *Set types* consist of `SET' and `BITSET' types. - - * *Boolean types* consist of `BOOLEAN'. - -The following operators are supported, and appear in order of -increasing precedence: - -`,' - Function argument or array index separator. - -`:=' - Assignment. The value of VAR `:=' VALUE is VALUE. - -`<, >' - Less than, greater than on integral, floating-point, or enumerated - types. - -`<=, >=' - Less than, greater than, less than or equal to, greater than or - equal to on integral, floating-point and enumerated types, or set - inclusion on set types. Same precedence as `<'. - -`=, <>, #' - Equality and two ways of expressing inequality, valid on scalar - types. Same precedence as `<'. In GDB scripts, only `<>' is - available for inequality, since `#' conflicts with the script - comment character. - -`IN' - Set membership. Defined on set types and the types of their - members. Same precedence as `<'. - -`OR' - Boolean disjunction. Defined on boolean types. - -`AND, &' - Boolean conjuction. Defined on boolean types. - -`@' - The GDB "artificial array" operator (*note Expressions: - Expressions.). - -`+, -' - Addition and subtraction on integral and floating-point types, or - union and difference on set types. - -`*' - Multiplication on integral and floating-point types, or set - intersection on set types. - -`/' - Division on floating-point types, or symmetric set difference on - set types. Same precedence as `*'. - -`DIV, MOD' - Integer division and remainder. Defined on integral types. Same - precedence as `*'. - -`-' - Negative. Defined on `INTEGER' and `REAL' data. - -`^' - Pointer dereferencing. Defined on pointer types. - -`NOT' - Boolean negation. Defined on boolean types. Same precedence as - `^'. - -`.' - `RECORD' field selector. Defined on `RECORD' data. Same - precedence as `^'. - -`[]' - Array indexing. Defined on `ARRAY' data. Same precedence as `^'. - -`()' - Procedure argument list. Defined on `PROCEDURE' objects. Same - precedence as `^'. - -`::, .' - GDB and Modula-2 scope operators. - - *Warning:* Sets and their operations are not yet supported, so GDB - will treat the use of the operator `IN', or the use of operators - `+', `-', `*', `/', `=', , `<>', `#', `<=', and `>=' on sets as an - error. - - -File: gdb.info, Node: Built-In Func/Proc, Next: M2 Constants, Prev: M2 Operators, Up: Modula-2 - -Built-in functions and procedures ---------------------------------- - - Modula-2 also makes available several built-in procedures and -functions. In describing these, the following metavariables are used: - -A - represents an `ARRAY' variable. - -C - represents a `CHAR' constant or variable. - -I - represents a variable or constant of integral type. - -M - represents an identifier that belongs to a set. Generally used in - the same function with the metavariable S. The type of S should - be `SET OF MTYPE' (where MTYPE is the type of M). - -N - represents a variable or constant of integral or floating-point - type. - -R - represents a variable or constant of floating-point type. - -T - represents a type. - -V - represents a variable. - -X - represents a variable or constant of one of many types. See the - explanation of the function for details. - - All Modula-2 built-in procedures also return a result, described -below. - -`ABS(N)' - Returns the absolute value of N. - -`CAP(C)' - If C is a lower case letter, it returns its upper case equivalent, - otherwise it returns its argument - -`CHR(I)' - Returns the character whose ordinal value is I. - -`DEC(V)' - Decrements the value in the variable V. Returns the new value. - -`DEC(V,I)' - Decrements the value in the variable V by I. Returns the new - value. - -`EXCL(M,S)' - Removes the element M from the set S. Returns the new set. - -`FLOAT(I)' - Returns the floating point equivalent of the integer I. - -`HIGH(A)' - Returns the index of the last member of A. - -`INC(V)' - Increments the value in the variable V. Returns the new value. - -`INC(V,I)' - Increments the value in the variable V by I. Returns the new - value. - -`INCL(M,S)' - Adds the element M to the set S if it is not already there. - Returns the new set. - -`MAX(T)' - Returns the maximum value of the type T. - -`MIN(T)' - Returns the minimum value of the type T. - -`ODD(I)' - Returns boolean TRUE if I is an odd number. - -`ORD(X)' - Returns the ordinal value of its argument. For example, the - ordinal value of a character is its ASCII value (on machines - supporting the ASCII character set). X must be of an ordered - type, which include integral, character and enumerated types. - -`SIZE(X)' - Returns the size of its argument. X can be a variable or a type. - -`TRUNC(R)' - Returns the integral part of R. - -`VAL(T,I)' - Returns the member of the type T whose ordinal value is I. - - *Warning:* Sets and their operations are not yet supported, so - GDB will treat the use of procedures `INCL' and `EXCL' as an error. - - -File: gdb.info, Node: M2 Constants, Next: M2 Defaults, Prev: Built-In Func/Proc, Up: Modula-2 - -Constants ---------- - - GDB allows you to express the constants of Modula-2 in the following -ways: - - * Integer constants are simply a sequence of digits. When used in an - expression, a constant is interpreted to be type-compatible with - the rest of the expression. Hexadecimal integers are specified by - a trailing `H', and octal integers by a trailing `B'. - - * Floating point constants appear as a sequence of digits, followed - by a decimal point and another sequence of digits. An optional - exponent can then be specified, in the form `E[+|-]NNN', where - `[+|-]NNN' is the desired exponent. All of the digits of the - floating point constant must be valid decimal (base 10) digits. - - * Character constants consist of a single character enclosed by a - pair of like quotes, either single (`'') or double (`"'). They may - also be expressed by their ordinal value (their ASCII value, - usually) followed by a `C'. - - * String constants consist of a sequence of characters enclosed by a - pair of like quotes, either single (`'') or double (`"'). Escape - sequences in the style of C are also allowed. *Note C and C++ - constants: C Constants, for a brief explanation of escape - sequences. - - * Enumerated constants consist of an enumerated identifier. - - * Boolean constants consist of the identifiers `TRUE' and `FALSE'. - - * Pointer constants consist of integral values only. - - * Set constants are not yet supported. - - -File: gdb.info, Node: M2 Defaults, Next: Deviations, Prev: M2 Constants, Up: Modula-2 - -Modula-2 defaults ------------------ - - If type and range checking are set automatically by GDB, they both -default to `on' whenever the working language changes to Modula-2. -This happens regardless of whether you, or GDB, selected the working -language. - - If you allow GDB to set the language automatically, then entering -code compiled from a file whose name ends with `.mod' will set the -working language to Modula-2. *Note Having GDB set the language -automatically: Automatically, for further details. - - -File: gdb.info, Node: Deviations, Next: M2 Checks, Prev: M2 Defaults, Up: Modula-2 - -Deviations from standard Modula-2 ---------------------------------- - - A few changes have been made to make Modula-2 programs easier to -debug. This is done primarily via loosening its type strictness: - - * Unlike in standard Modula-2, pointer constants can be formed by - integers. This allows you to modify pointer variables during - debugging. (In standard Modula-2, the actual address contained in - a pointer variable is hidden from you; it can only be modified - through direct assignment to another pointer variable or - expression that returned a pointer.) - - * C escape sequences can be used in strings and characters to - represent non-printable characters. GDB will print out strings - with these escape sequences embedded. Single non-printable - characters are printed using the `CHR(NNN)' format. - - * The assignment operator (`:=') returns the value of its right-hand - argument. - - * All built-in procedures both modify *and* return their argument. - - -File: gdb.info, Node: M2 Checks, Next: M2 Scope, Prev: Deviations, Up: Modula-2 - -Modula-2 type and range checks ------------------------------- - - *Warning:* in this release, GDB does not yet perform type or range - checking. - - GDB considers two Modula-2 variables type equivalent if: - - * They are of types that have been declared equivalent via a `TYPE - T1 = T2' statement - - * They have been declared on the same line. (Note: This is true of - the GNU Modula-2 compiler, but it may not be true of other - compilers.) - - As long as type checking is enabled, any attempt to combine variables -whose types are not equivalent is an error. - - Range checking is done on all mathematical operations, assignment, -array index bounds, and all built-in functions and procedures. - - -File: gdb.info, Node: M2 Scope, Next: GDB/M2, Prev: M2 Checks, Up: Modula-2 - -The scope operators `::' and `.' --------------------------------- - - There are a few subtle differences between the Modula-2 scope -operator (`.') and the GDB scope operator (`::'). The two have similar -syntax: - - - MODULE . ID - SCOPE :: ID - -where SCOPE is the name of a module or a procedure, MODULE the name of -a module, and ID is any declared identifier within your program, except -another module. - - Using the `::' operator makes GDB search the scope specified by -SCOPE for the identifier ID. If it is not found in the specified -scope, then GDB will search all scopes enclosing the one specified by -SCOPE. - - Using the `.' operator makes GDB search the current scope for the -identifier specified by ID that was imported from the definition module -specified by MODULE. With this operator, it is an error if the -identifier ID was not imported from definition module MODULE, or if ID -is not an identifier in MODULE. - - -File: gdb.info, Node: GDB/M2, Prev: M2 Scope, Up: Modula-2 - -GDB and Modula-2 ----------------- - - Some GDB commands have little use when debugging Modula-2 programs. -Five subcommands of `set print' and `show print' apply specifically to -C and C++: `vtbl', `demangle', `asm-demangle', `object', and `union'. -The first four apply to C++, and the last to the C `union' type, which -has no direct analogue in Modula-2. - - The `@' operator (*note Expressions: Expressions.), while available -while using any language, is not useful with Modula-2. Its intent is -to aid the debugging of "dynamic arrays", which cannot be created in -Modula-2 as they can in C or C++. However, because an address can be -specified by an integral constant, the construct `{TYPE}ADREXP' is -still useful. (*note Expressions: Expressions.) - - In GDB scripts, the Modula-2 inequality operator `#' is interpreted -as the beginning of a comment. Use `<>' instead. - - -File: gdb.info, Node: Symbols, Next: Altering, Prev: Languages, Up: Top - -Examining the Symbol Table -************************** - - The commands described in this section allow you to inquire about the -symbols (names of variables, functions and types) defined in your -program. This information is inherent in the text of your program and -does not change as your program executes. GDB finds it in your -program's symbol table, in the file indicated when you started GDB -(*note Choosing files: File Options.), or by one of the file-management -commands (*note Commands to specify files: Files.). - - Occasionally, you may need to refer to symbols that contain unusual -characters, which GDB ordinarily treats as word delimiters. The most -frequent case is in referring to static variables in other source files -(*note Program variables: Variables.). File names are recorded in -object files as debugging symbols, but GDB would ordinarily parse a -typical file name, like `foo.c', as the three words `foo' `.' `c'. To -allow GDB to recognize `foo.c' as a single symbol, enclose it in single -quotes; for example, - - p 'foo.c'::x - -looks up the value of `x' in the scope of the file `foo.c'. - -`info address SYMBOL' - Describe where the data for SYMBOL is stored. For a register - variable, this says which register it is kept in. For a - non-register local variable, this prints the stack-frame offset at - which the variable is always stored. - - Note the contrast with `print &SYMBOL', which does not work at all - for a register variable, and for a stack local variable prints the - exact address of the current instantiation of the variable. - -`whatis EXP' - Print the data type of expression EXP. EXP is not actually - evaluated, and any side-effecting operations (such as assignments - or function calls) inside it do not take place. *Note - Expressions: Expressions. - -`whatis' - Print the data type of `$', the last value in the value history. - -`ptype TYPENAME' - Print a description of data type TYPENAME. TYPENAME may be the - name of a type, or for C code it may have the form `class - CLASS-NAME', `struct STRUCT-TAG', `union UNION-TAG' or `enum - ENUM-TAG'. - -`ptype EXP' -`ptype' - Print a description of the type of expression EXP. `ptype' - differs from `whatis' by printing a detailed description, instead - of just the name of the type. - - For example, for this variable declaration: - - struct complex {double real; double imag;} v; - - the two commands give this output: - - (gdb) whatis v - type = struct complex - (gdb) ptype v - type = struct complex { - double real; - double imag; - } - - As with `whatis', using `ptype' without an argument refers to the - type of `$', the last value in the value history. - -`info types REGEXP' -`info types' - Print a brief description of all types whose name matches REGEXP - (or all types in your program, if you supply no argument). Each - complete typename is matched as though it were a complete line; - thus, `i type value' gives information on all types in your - program whose name includes the string `value', but `i type - ^value$' gives information only on types whose complete name is - `value'. - - This command differs from `ptype' in two ways: first, like - `whatis', it does not print a detailed description; second, it - lists all source files where a type is defined. - -`info source' - Show the name of the current source file--that is, the source file - for the function containing the current point of execution--and - the language it was written in. - -`info sources' - Print the names of all source files in your program for which - there is debugging information, organized into two lists: files - whose symbols have already been read, and files whose symbols will - be read when needed. - -`info functions' - Print the names and data types of all defined functions. - -`info functions REGEXP' - Print the names and data types of all defined functions whose - names contain a match for regular expression REGEXP. Thus, `info - fun step' finds all functions whose names include `step'; `info - fun ^step' finds those whose names start with `step'. - -`info variables' - Print the names and data types of all variables that are declared - outside of functions (i.e., excluding local variables). - -`info variables REGEXP' - Print the names and data types of all variables (except for local - variables) whose names contain a match for regular expression - REGEXP. - -`maint print symbols FILENAME' -`maint print psymbols FILENAME' -`maint print msymbols FILENAME' - Write a dump of debugging symbol data into the file FILENAME. - These commands are used to debug the GDB symbol-reading code. Only - symbols with debugging data are included. If you use `maint print - symbols', GDB includes all the symbols for which it has already - collected full details: that is, FILENAME reflects symbols for - only those files whose symbols GDB has read. You can use the - command `info sources' to find out which files these are. If you - use `maint print psymbols' instead, the dump shows information - about symbols that GDB only knows partially--that is, symbols - defined in files that GDB has skimmed, but not yet read - completely. Finally, `maint print msymbols' dumps just the - minimal symbol information required for each object file from - which GDB has read some symbols. *Note Commands to specify files: - Files, for a discussion of how GDB reads symbols (in the - description of `symbol-file'). - diff --git a/gnu/usr.bin/gdb/doc/gdb.info-5 b/gnu/usr.bin/gdb/doc/gdb.info-5 deleted file mode 100644 index ecf3d18..0000000 --- a/gnu/usr.bin/gdb/doc/gdb.info-5 +++ /dev/null @@ -1,1215 +0,0 @@ -This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input -file gdb.texinfo. - -START-INFO-DIR-ENTRY -* Gdb:: The GNU debugger. -END-INFO-DIR-ENTRY - This file documents the GNU debugger GDB. - - This is Edition 4.09, August 1993, of `Debugging with GDB: the GNU -Source-Level Debugger' for GDB Version 4.11. - - Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software -Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the entire resulting derived work is distributed under the terms -of a permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions. - - -File: gdb.info, Node: Altering, Next: GDB Files, Prev: Symbols, Up: Top - -Altering Execution -****************** - - Once you think you have found an error in your program, you might -want to find out for certain whether correcting the apparent error -would lead to correct results in the rest of the run. You can find the -answer by experiment, using the GDB features for altering execution of -the program. - - For example, you can store new values into variables or memory -locations, give your program a signal, restart it at a different -address, or even return prematurely from a function to its caller. - -* Menu: - -* Assignment:: Assignment to variables -* Jumping:: Continuing at a different address - -* Signaling:: Giving your program a signal - -* Returning:: Returning from a function -* Calling:: Calling your program's functions -* Patching:: Patching your program - - -File: gdb.info, Node: Assignment, Next: Jumping, Up: Altering - -Assignment to variables -======================= - - To alter the value of a variable, evaluate an assignment expression. -*Note Expressions: Expressions. For example, - - print x=4 - -stores the value 4 into the variable `x', and then prints the value of -the assignment expression (which is 4). *Note Using GDB with Different -Languages: Languages, for more information on operators in supported -languages. - - If you are not interested in seeing the value of the assignment, use -the `set' command instead of the `print' command. `set' is really the -same as `print' except that the expression's value is not printed and -is not put in the value history (*note Value history: Value History.). -The expression is evaluated only for its effects. - - If the beginning of the argument string of the `set' command appears -identical to a `set' subcommand, use the `set variable' command instead -of just `set'. This command is identical to `set' except for its lack -of subcommands. For example, if your program has a variable `width', -you get an error if you try to set a new value with just `set width=13', -because GDB has the command `set width': - - (gdb) whatis width - type = double - (gdb) p width - $4 = 13 - (gdb) set width=47 - Invalid syntax in expression. - -The invalid expression, of course, is `=47'. In order to actually set -the program's variable `width', use - - (gdb) set var width=47 - - GDB allows more implicit conversions in assignments than C; you can -freely store an integer value into a pointer variable or vice versa, -and you can convert any structure to any other structure that is the -same length or shorter. - - To store values into arbitrary places in memory, use the `{...}' -construct to generate a value of specified type at a specified address -(*note Expressions: Expressions.). For example, `{int}0x83040' refers -to memory location `0x83040' as an integer (which implies a certain size -and representation in memory), and - - set {int}0x83040 = 4 - -stores the value 4 into that memory location. - - -File: gdb.info, Node: Jumping, Next: Signaling, Prev: Assignment, Up: Altering - -Continuing at a different address -================================= - - Ordinarily, when you continue your program, you do so at the place -where it stopped, with the `continue' command. You can instead -continue at an address of your own choosing, with the following -commands: - -`jump LINESPEC' - Resume execution at line LINESPEC. Execution will stop - immediately if there is a breakpoint there. *Note Printing source - lines: List, for a description of the different forms of LINESPEC. - - The `jump' command does not change the current stack frame, or the - stack pointer, or the contents of any memory location or any - register other than the program counter. If line LINESPEC is in a - different function from the one currently executing, the results - may be bizarre if the two functions expect different patterns of - arguments or of local variables. For this reason, the `jump' - command requests confirmation if the specified line is not in the - function currently executing. However, even bizarre results are - predictable if you are well acquainted with the machine-language - code of your program. - -`jump *ADDRESS' - Resume execution at the instruction at address ADDRESS. - - You can get much the same effect as the `jump' command by storing a -new value into the register `$pc'. The difference is that this does -not start your program running; it only changes the address where it -*will* run when it is continued. For example, - - set $pc = 0x485 - -causes the next `continue' command or stepping command to execute at -address `0x485', rather than at the address where your program stopped. -*Note Continuing and stepping: Continuing and Stepping. - - The most common occasion to use the `jump' command is to back up, -perhaps with more breakpoints set, over a portion of a program that has -already executed, in order to examine its execution in more detail. - - -File: gdb.info, Node: Signaling, Next: Returning, Prev: Jumping, Up: Altering - -Giving your program a signal -============================ - -`signal SIGNAL' - Resume execution where your program stopped, but immediately give - it the signal SIGNAL. SIGNAL can be the name or the number of a - signal. For example, on many systems `signal 2' and `signal - SIGINT' are both ways of sending an interrupt signal. - - Alternatively, if SIGNAL is zero, continue execution without - giving a signal. This is useful when your program stopped on - account of a signal and would ordinary see the signal when resumed - with the `continue' command; `signal 0' causes it to resume - without a signal. - - `signal' does not repeat when you press RET a second time after - executing the command. - - Invoking the `signal' command is not the same as invoking the `kill' -utility from the shell. Sending a signal with `kill' causes GDB to -decide what to do with the signal depending on the signal handling -tables (*note Signals::.). The `signal' command passes the signal -directly to your program. - - -File: gdb.info, Node: Returning, Next: Calling, Prev: Signaling, Up: Altering - -Returning from a function -========================= - -`return' -`return EXPRESSION' - You can cancel execution of a function call with the `return' - command. If you give an EXPRESSION argument, its value is used as - the function's return value. - - When you use `return', GDB discards the selected stack frame (and -all frames within it). You can think of this as making the discarded -frame return prematurely. If you wish to specify a value to be -returned, give that value as the argument to `return'. - - This pops the selected stack frame (*note Selecting a frame: -Selection.), and any other frames inside of it, leaving its caller as -the innermost remaining frame. That frame becomes selected. The -specified value is stored in the registers used for returning values of -functions. - - The `return' command does not resume execution; it leaves the -program stopped in the state that would exist if the function had just -returned. In contrast, the `finish' command (*note Continuing and -stepping: Continuing and Stepping.) resumes execution until the -selected stack frame returns naturally. - - -File: gdb.info, Node: Calling, Next: Patching, Prev: Returning, Up: Altering - -Calling program functions -========================= - -`call EXPR' - Evaluate the expression EXPR without displaying `void' returned - values. - - You can use this variant of the `print' command if you want to -execute a function from your program, but without cluttering the output -with `void' returned values. The result is printed and saved in the -value history, if it is not void. - - -File: gdb.info, Node: Patching, Prev: Calling, Up: Altering - -Patching programs -================= - - By default, GDB opens the file containing your program's executable -code (or the corefile) read-only. This prevents accidental alterations -to machine code; but it also prevents you from intentionally patching -your program's binary. - - If you'd like to be able to patch the binary, you can specify that -explicitly with the `set write' command. For example, you might want -to turn on internal debugging flags, or even to make emergency repairs. - -`set write on' -`set write off' - If you specify `set write on', GDB will open executable and core - files for both reading and writing; if you specify `set write off' - (the default), GDB will open them read-only. - - If you have already loaded a file, you must load it again (using - the `exec-file' or `core-file' command) after changing `set - write', for your new setting to take effect. - -`show write' - Display whether executable files and core files will be opened for - writing as well as reading. - - -File: gdb.info, Node: GDB Files, Next: Targets, Prev: Altering, Up: Top - -GDB Files -********* - - GDB needs to know the file name of the program to be debugged, both -in order to read its symbol table and in order to start your program. -To debug a core dump of a previous run, you must also tell GDB the name -of the core dump file. - -* Menu: - -* Files:: Commands to specify files -* Symbol Errors:: Errors reading symbol files - - -File: gdb.info, Node: Files, Next: Symbol Errors, Up: GDB Files - -Commands to specify files -========================= - - The usual way to specify executable and core dump file names is with -the command arguments given when you start GDB (*note Getting In and -Out of GDB: Invocation.. - - Occasionally it is necessary to change to a different file during a -GDB session. Or you may run GDB and forget to specify a file you want -to use. In these situations the GDB commands to specify new files are -useful. - -`file FILENAME' - Use FILENAME as the program to be debugged. It is read for its - symbols and for the contents of pure memory. It is also the - program executed when you use the `run' command. If you do not - specify a directory and the file is not found in the GDB working - directory, GDB uses the environment variable `PATH' as a list of - directories to search, just as the shell does when looking for a - program to run. You can change the value of this variable, for - both GDB and your program, using the `path' command. - - On systems with memory-mapped files, an auxiliary symbol table file - `FILENAME.syms' may be available for FILENAME. If it is, GDB will - map in the symbol table from `FILENAME.syms', starting up more - quickly. See the descriptions of the options `-mapped' and - `-readnow' (available on the command line, and with the commands - `file', `symbol-file', or `add-symbol-file'), for more information. - -`file' - `file' with no argument makes GDB discard any information it has - on both executable file and the symbol table. - -`exec-file [ FILENAME ]' - Specify that the program to be run (but not the symbol table) is - found in FILENAME. GDB will search the environment variable `PATH' - if necessary to locate your program. Omitting FILENAME means to - discard information on the executable file. - -`symbol-file [ FILENAME ]' - Read symbol table information from file FILENAME. `PATH' is - searched when necessary. Use the `file' command to get both symbol - table and program to run from the same file. - - `symbol-file' with no argument clears out GDB information on your - program's symbol table. - - The `symbol-file' command causes GDB to forget the contents of its - convenience variables, the value history, and all breakpoints and - auto-display expressions. This is because they may contain - pointers to the internal data recording symbols and data types, - which are part of the old symbol table data being discarded inside - GDB. - - `symbol-file' will not repeat if you press RET again after - executing it once. - - When GDB is configured for a particular environment, it will - understand debugging information in whatever format is the standard - generated for that environment; you may use either a GNU compiler, - or other compilers that adhere to the local conventions. Best - results are usually obtained from GNU compilers; for example, - using `gcc' you can generate debugging information for optimized - code. - - On some kinds of object files, the `symbol-file' command does not - normally read the symbol table in full right away. Instead, it - scans the symbol table quickly to find which source files and - which symbols are present. The details are read later, one source - file at a time, as they are needed. - - The purpose of this two-stage reading strategy is to make GDB - start up faster. For the most part, it is invisible except for - occasional pauses while the symbol table details for a particular - source file are being read. (The `set verbose' command can turn - these pauses into messages if desired. *Note Optional warnings - and messages: Messages/Warnings.) - - We have not implemented the two-stage strategy for COFF yet. When - the symbol table is stored in COFF format, `symbol-file' reads the - symbol table data in full right away. - -`symbol-file FILENAME [ -readnow ] [ -mapped ]' -`file FILENAME [ -readnow ] [ -mapped ]' - You can override the GDB two-stage strategy for reading symbol - tables by using the `-readnow' option with any of the commands that - load symbol table information, if you want to be sure GDB has the - entire symbol table available. - - If memory-mapped files are available on your system through the - `mmap' system call, you can use another option, `-mapped', to - cause GDB to write the symbols for your program into a reusable - file. Future GDB debugging sessions will map in symbol information - from this auxiliary symbol file (if the program has not changed), - rather than spending time reading the symbol table from the - executable program. Using the `-mapped' option has the same - effect as starting GDB with the `-mapped' command-line option. - - You can use both options together, to make sure the auxiliary - symbol file has all the symbol information for your program. - - The auxiliary symbol file for a program called MYPROG is called - `MYPROG.syms'. Once this file exists (so long as it is newer than - the corresponding executable), GDB will always attempt to use it - when you debug MYPROG; no special options or commands are needed. - - The `.syms' file is specific to the host machine where you run - GDB. It holds an exact image of the internal GDB symbol table. - It cannot be shared across multiple host platforms. - -`core-file [ FILENAME ]' - Specify the whereabouts of a core dump file to be used as the - "contents of memory". Traditionally, core files contain only some - parts of the address space of the process that generated them; GDB - can access the executable file itself for other parts. - - `core-file' with no argument specifies that no core file is to be - used. - - Note that the core file is ignored when your program is actually - running under GDB. So, if you have been running your program and - you wish to debug a core file instead, you must kill the - subprocess in which the program is running. To do this, use the - `kill' command (*note Killing the child process: Kill Process.). - -`load FILENAME' - Depending on what remote debugging facilities are configured into - GDB, the `load' command may be available. Where it exists, it is - meant to make FILENAME (an executable) available for debugging on - the remote system--by downloading, or dynamic linking, for example. - `load' also records the FILENAME symbol table in GDB, like the - `add-symbol-file' command. - - If your GDB does not have a `load' command, attempting to execute - it gets the error message "`You can't do that when your target is - ...'" - - The file is loaded at whatever address is specified in the - executable. For some object file formats, like a.out, the object - file format fixes the address and so it won't necessarily match - the address you gave to the linker. - - On VxWorks, `load' will dynamically link FILENAME on the current - target system as well as adding its symbols in GDB. - - With the Nindy interface to an Intel 960 board, `load' will - download FILENAME to the 960 as well as adding its symbols in GDB. - - When you select remote debugging to a Hitachi SH, H8/300, or - H8/500 board (*note GDB and Hitachi Microprocessors: Hitachi - Remote.), the `load' command downloads your program to the Hitachi - board and also opens it as the current executable target for GDB - on your host (like the `file' command). - - `load' will not repeat if you press RET again after using it. - -`add-symbol-file FILENAME ADDRESS' -`add-symbol-file FILENAME ADDRESS [ -readnow ] [ -mapped ]' - The `add-symbol-file' command reads additional symbol table - information from the file FILENAME. You would use this command - when FILENAME has been dynamically loaded (by some other means) - into the program that is running. ADDRESS should be the memory - address at which the file has been loaded; GDB cannot figure this - out for itself. You can specify ADDRESS as an expression. - - The symbol table of the file FILENAME is added to the symbol table - originally read with the `symbol-file' command. You can use the - `add-symbol-file' command any number of times; the new symbol data - thus read keeps adding to the old. To discard all old symbol data - instead, use the `symbol-file' command. - - `add-symbol-file' will not repeat if you press RET after using it. - - You can use the `-mapped' and `-readnow' options just as with the - `symbol-file' command, to change how GDB manages the symbol table - information for FILENAME. - -`info files' -`info target' - `info files' and `info target' are synonymous; both print the - current target (*note Specifying a Debugging Target: Targets.), - including the names of the executable and core dump files - currently in use by GDB, and the files from which symbols were - loaded. The command `help targets' lists all possible targets - rather than current ones. - - All file-specifying commands allow both absolute and relative file -names as arguments. GDB always converts the file name to an absolute -path name and remembers it that way. - - GDB supports SunOS, SVR4, and IBM RS/6000 shared libraries. GDB -automatically loads symbol definitions from shared libraries when you -use the `run' command, or when you examine a core file. (Before you -issue the `run' command, GDB will not understand references to a -function in a shared library, however--unless you are debugging a core -file). - -`info share' -`info sharedlibrary' - Print the names of the shared libraries which are currently loaded. - -`sharedlibrary REGEX' -`share REGEX' - This is an obsolescent command; you can use it to explicitly load - shared object library symbols for files matching a Unix regular - expression, but as with files loaded automatically, it will only - load shared libraries required by your program for a core file or - after typing `run'. If REGEX is omitted all shared libraries - required by your program are loaded. - - -File: gdb.info, Node: Symbol Errors, Prev: Files, Up: GDB Files - -Errors reading symbol files -=========================== - - While reading a symbol file, GDB will occasionally encounter -problems, such as symbol types it does not recognize, or known bugs in -compiler output. By default, GDB does not notify you of such problems, -since they are relatively common and primarily of interest to people -debugging compilers. If you are interested in seeing information about -ill-constructed symbol tables, you can either ask GDB to print only one -message about each such type of problem, no matter how many times the -problem occurs; or you can ask GDB to print more messages, to see how -many times the problems occur, with the `set complaints' command (*note -Optional warnings and messages: Messages/Warnings.). - - The messages currently printed, and their meanings, include: - -`inner block not inside outer block in SYMBOL' - The symbol information shows where symbol scopes begin and end - (such as at the start of a function or a block of statements). - This error indicates that an inner scope block is not fully - contained in its outer scope blocks. - - GDB circumvents the problem by treating the inner block as if it - had the same scope as the outer block. In the error message, - SYMBOL may be shown as "`(don't know)'" if the outer block is not a - function. - -`block at ADDRESS out of order' - The symbol information for symbol scope blocks should occur in - order of increasing addresses. This error indicates that it does - not do so. - - GDB does not circumvent this problem, and will have trouble - locating symbols in the source file whose symbols it is reading. - (You can often determine what source file is affected by specifying - `set verbose on'. *Note Optional warnings and messages: - Messages/Warnings.) - -`bad block start address patched' - The symbol information for a symbol scope block has a start address - smaller than the address of the preceding source line. This is - known to occur in the SunOS 4.1.1 (and earlier) C compiler. - - GDB circumvents the problem by treating the symbol scope block as - starting on the previous source line. - -`bad string table offset in symbol N' - Symbol number N contains a pointer into the string table which is - larger than the size of the string table. - - GDB circumvents the problem by considering the symbol to have the - name `foo', which may cause other problems if many symbols end up - with this name. - -`unknown symbol type `0xNN'' - The symbol information contains new data types that GDB does not - yet know how to read. `0xNN' is the symbol type of the - misunderstood information, in hexadecimal. - - GDB circumvents the error by ignoring this symbol information. - This will usually allow your program to be debugged, though - certain symbols will not be accessible. If you encounter such a - problem and feel like debugging it, you can debug `gdb' with - itself, breakpoint on `complain', then go up to the function - `read_dbx_symtab' and examine `*bufp' to see the symbol. - -`stub type has NULL name' - GDB could not find the full definition for a struct or class. - -`const/volatile indicator missing (ok if using g++ v1.x), got...' - The symbol information for a C++ member function is missing some - information that recent versions of the compiler should have output - for it. - -`info mismatch between compiler and debugger' - GDB could not parse a type specification output by the compiler. - - -File: gdb.info, Node: Targets, Next: Controlling GDB, Prev: GDB Files, Up: Top - -Specifying a Debugging Target -***************************** - - A "target" is the execution environment occupied by your program. -Often, GDB runs in the same host environment as your program; in that -case, the debugging target is specified as a side effect when you use -the `file' or `core' commands. When you need more flexibility--for -example, running GDB on a physically separate host, or controlling a -standalone system over a serial port or a realtime system over a TCP/IP -connection--you can use the `target' command to specify one of the -target types configured for GDB (*note Commands for managing targets: -Target Commands.). - -* Menu: - -* Active Targets:: Active targets -* Target Commands:: Commands for managing targets -* Remote:: Remote debugging - - -File: gdb.info, Node: Active Targets, Next: Target Commands, Up: Targets - -Active targets -============== - - There are three classes of targets: processes, core files, and -executable files. GDB can work concurrently on up to three active -targets, one in each class. This allows you to (for example) start a -process and inspect its activity without abandoning your work on a core -file. - - For example, if you execute `gdb a.out', then the executable file -`a.out' is the only active target. If you designate a core file as -well--presumably from a prior run that crashed and coredumped--then GDB -has two active targets and will use them in tandem, looking first in -the corefile target, then in the executable file, to satisfy requests -for memory addresses. (Typically, these two classes of target are -complementary, since core files contain only a program's read-write -memory--variables and so on--plus machine status, while executable -files contain only the program text and initialized data.) - - When you type `run', your executable file becomes an active process -target as well. When a process target is active, all GDB commands -requesting memory addresses refer to that target; addresses in an -active core file or executable file target are obscured while the -process target is active. - - Use the `core-file' and `exec-file' commands to select a new core -file or executable target (*note Commands to specify files: Files.). -To specify as a target a process that is already running, use the -`attach' command (*note Debugging an already-running process: Attach.). - - -File: gdb.info, Node: Target Commands, Next: Remote, Prev: Active Targets, Up: Targets - -Commands for managing targets -============================= - -`target TYPE PARAMETERS' - Connects the GDB host environment to a target machine or process. - A target is typically a protocol for talking to debugging - facilities. You use the argument TYPE to specify the type or - protocol of the target machine. - - Further PARAMETERS are interpreted by the target protocol, but - typically include things like device names or host names to connect - with, process numbers, and baud rates. - - The `target' command will not repeat if you press RET again after - executing the command. - -`help target' - Displays the names of all targets available. To display targets - currently selected, use either `info target' or `info files' - (*note Commands to specify files: Files.). - -`help target NAME' - Describe a particular target, including any parameters necessary to - select it. - - Here are some common targets (available, or not, depending on the GDB -configuration): - -`target exec PROGRAM' - An executable file. `target exec PROGRAM' is the same as - `exec-file PROGRAM'. - -`target core FILENAME' - A core dump file. `target core FILENAME' is the same as - `core-file FILENAME'. - -`target remote DEV' - Remote serial target in GDB-specific protocol. The argument DEV - specifies what serial device to use for the connection (e.g. - `/dev/ttya'). *Note Remote debugging: Remote. - -`target sim' - CPU simulator. *Note Simulated CPU Target: Simulator. - -`target udi KEYWORD' - Remote AMD29K target, using the AMD UDI protocol. The KEYWORD - argument specifies which 29K board or simulator to use. *Note GDB - and the UDI protocol for AMD29K: UDI29K Remote. - -`target amd-eb DEV SPEED PROG' - Remote PC-resident AMD EB29K board, attached over serial lines. - dEV is the serial device, as for `target remote'; SPEED allows you - to specify the linespeed; and PROG is the name of the program to - be debugged, as it appears to DOS on the PC. *Note GDB with a - remote EB29K: EB29K Remote. - -`target hms' - A Hitachi SH, H8/300, or H8/500 board, attached via serial line to - your host. Use special commands `device' and `speed' to control - the serial line and the communications speed used. *Note GDB and - Hitachi Microprocessors: Hitachi Remote. - -`target nindy DEVICENAME' - An Intel 960 board controlled by a Nindy Monitor. DEVICENAME is - the name of the serial device to use for the connection, e.g. - `/dev/ttya'. *Note GDB with a remote i960 (Nindy): i960-Nindy - Remote. - -`target st2000 DEV SPEED' - A Tandem ST2000 phone switch, running Tandem's STDBUG protocol. - dEV is the name of the device attached to the ST2000 serial line; - SPEED is the communication line speed. The arguments are not used - if GDB is configured to connect to the ST2000 using TCP or Telnet. - *Note GDB with a Tandem ST2000: ST2000 Remote. - -`target vxworks MACHINENAME' - A VxWorks system, attached via TCP/IP. The argument MACHINENAME - is the target system's machine name or IP address. *Note GDB and - VxWorks: VxWorks Remote. - - Different targets are available on different configurations of GDB; -your configuration may have more or fewer targets. - - -File: gdb.info, Node: Remote, Prev: Target Commands, Up: Targets - -Remote debugging -================ - - If you are trying to debug a program running on a machine that -cannot run GDB in the usual way, it is often useful to use remote -debugging. For example, you might use remote debugging on an operating -system kernel, or on a small system which does not have a general -purpose operating system powerful enough to run a full-featured -debugger. - - Some configurations of GDB have special serial or TCP/IP interfaces -to make this work with particular debugging targets. In addition, GDB -comes with a generic serial protocol (specific to GDB, but not specific -to any particular target system) which you can use if you write the -remote stubs--the code that will run on the remote system to -communicate with GDB. - - Other remote targets may be available in your configuration of GDB; -use `help targets' to list them. - -* Menu: - - -* Remote Serial:: GDB remote serial protocol - -* i960-Nindy Remote:: GDB with a remote i960 (Nindy) - -* UDI29K Remote:: GDB and the UDI protocol for AMD29K -* EB29K Remote:: GDB with a remote EB29K - -* VxWorks Remote:: GDB and VxWorks - -* ST2000 Remote:: GDB with a Tandem ST2000 - -* Hitachi Remote:: GDB and Hitachi Microprocessors - -* MIPS Remote:: GDB and MIPS boards - -* Simulator:: Simulated CPU target - - -File: gdb.info, Node: Remote Serial, Next: i960-Nindy Remote, Up: Remote - -The GDB remote serial protocol ------------------------------- - - To debug a program running on another machine (the debugging -"target" machine), you must first arrange for all the usual -prerequisites for the program to run by itself. For example, for a C -program, you need - - 1. A startup routine to set up the C runtime environment; these - usually have a name like `crt0'. The startup routine may be - supplied by your hardware supplier, or you may have to write your - own. - - 2. You probably need a C subroutine library to support your program's - subroutine calls, notably managing input and output. - - 3. A way of getting your program to the other machine--for example, a - download program. These are often supplied by the hardware - manufacturer, but you may have to write your own from hardware - documentation. - - The next step is to arrange for your program to use a serial port to -communicate with the machine where GDB is running (the "host" machine). -In general terms, the scheme looks like this: - -*On the host,* - GDB already understands how to use this protocol; when everything - else is set up, you can simply use the `target remote' command - (*note Specifying a Debugging Target: Targets.). - -*On the target,* - you must link with your program a few special-purpose subroutines - that implement the GDB remote serial protocol. The file - containing these subroutines is called a "debugging stub". - - On certain remote targets, you can use an auxiliary program - `gdbserver' instead of linking a stub into your program. *Note - Using the `gdbserver' program: Server, for details. - - The debugging stub is specific to the architecture of the remote -machine; for example, use `sparc-stub.c' to debug programs on SPARC -boards. - - These working remote stubs are distributed with GDB: - -`sparc-stub.c' - For SPARC architectures. - -`m68k-stub.c' - For Motorola 680x0 architectures. - -`i386-stub.c' - For Intel 386 and compatible architectures. - - The `README' file in the GDB distribution may list other recently -added stubs. - -* Menu: - -* Stub Contents:: What the stub can do for you -* Bootstrapping:: What you must do for the stub -* Debug Session:: Putting it all together -* Protocol:: Outline of the communication protocol - -* Server:: Using the `gdbserver' program - - -File: gdb.info, Node: Stub Contents, Next: Bootstrapping, Up: Remote Serial - -What the stub can do for you ----------------------------- - - The debugging stub for your architecture supplies these three -subroutines: - -`set_debug_traps' - This routine arranges for `handle_exception' to run when your - program stops. You must call this subroutine explicitly near the - beginning of your program. - -`handle_exception' - This is the central workhorse, but your program never calls it - explicitly--the setup code arranges for `handle_exception' to run - when a trap is triggered. - - `handle_exception' takes control when your program stops during - execution (for example, on a breakpoint), and mediates - communications with GDB on the host machine. This is where the - communications protocol is implemented; `handle_exception' acts as - the GDB representative on the target machine; it begins by sending - summary information on the state of your program, then continues - to execute, retrieving and transmitting any information GDB needs, - until you execute a GDB command that makes your program resume; at - that point, `handle_exception' returns control to your own code on - the target machine. - -`breakpoint' - Use this auxiliary subroutine to make your program contain a - breakpoint. Depending on the particular situation, this may be - the only way for GDB to get control. For instance, if your target - machine has some sort of interrupt button, you won't need to call - this; pressing the interrupt button will transfer control to - `handle_exception'--in effect, to GDB. On some machines, simply - receiving characters on the serial port may also trigger a trap; - again, in that situation, you don't need to call `breakpoint' from - your own program--simply running `target remote' from the host GDB - session will get control. - - Call `breakpoint' if none of these is true, or if you simply want - to make certain your program stops at a predetermined point for the - start of your debugging session. - - -File: gdb.info, Node: Bootstrapping, Next: Debug Session, Prev: Stub Contents, Up: Remote Serial - -What you must do for the stub ------------------------------ - - The debugging stubs that come with GDB are set up for a particular -chip architecture, but they have no information about the rest of your -debugging target machine. To allow the stub to work, you must supply -these special low-level subroutines: - -`int getDebugChar()' - Write this subroutine to read a single character from the serial - port. It may be identical to `getchar' for your target system; a - different name is used to allow you to distinguish the two if you - wish. - -`void putDebugChar(int)' - Write this subroutine to write a single character to the serial - port. It may be identical to `putchar' for your target system; a - different name is used to allow you to distinguish the two if you - wish. - -`void exceptionHandler (int EXCEPTION_NUMBER, void *EXCEPTION_ADDRESS)' - Write this function to install EXCEPTION_ADDRESS in the exception - handling tables. You need to do this because the stub does not - have any way of knowing what the exception handling tables on your - target system are like (for example, the processor's table might - be in ROM, containing entries which point to a table in RAM). - eXCEPTION_NUMBER is the exception number which should be changed; - its meaning is architecture-dependent (for example, different - numbers might represent divide by zero, misaligned access, etc). - When this exception occurs, control should be transferred directly - to EXCEPTION_ADDRESS, and the processor state (stack, registers, - etc.) should be just as it is when a processor exception occurs. - So if you want to use a jump instruction to reach - EXCEPTION_ADDRESS, it should be a simple jump, not a jump to - subroutine. - - For the 386, EXCEPTION_ADDRESS should be installed as an interrupt - gate so that interrupts are masked while the handler runs. The - gate should be at privilege level 0 (the most privileged level). - The SPARC and 68k stubs are able to mask interrupts themself - without help from `exceptionHandler'. - -`void flush_i_cache()' - Write this subroutine to flush the instruction cache, if any, on - your target machine. If there is no instruction cache, this - subroutine may be a no-op. - - On target machines that have instruction caches, GDB requires this - function to make certain that the state of your program is stable. - -You must also make sure this library routine is available: - -`void *memset(void *, int, int)' - This is the standard library function `memset' that sets an area of - memory to a known value. If you have one of the free versions of - `libc.a', `memset' can be found there; otherwise, you must either - obtain it from your hardware manufacturer, or write your own. - - If you do not use the GNU C compiler, you may need other standard -library subroutines as well; this will vary from one stub to another, -but in general the stubs are likely to use any of the common library -subroutines which `gcc' generates as inline code. - - -File: gdb.info, Node: Debug Session, Next: Protocol, Prev: Bootstrapping, Up: Remote Serial - -Putting it all together ------------------------ - - In summary, when your program is ready to debug, you must follow -these steps. - - 1. Make sure you have the supporting low-level routines (*note What - you must do for the stub: Bootstrapping.): - `getDebugChar', `putDebugChar', - `flush_i_cache', `memset', `exceptionHandler'. - - 2. Insert these lines near the top of your program: - - set_debug_traps(); - breakpoint(); - - 3. For the 680x0 stub only, you need to provide a variable called - `exceptionHook'. Normally you just use - - void (*exceptionHook)() = 0; - - but if before calling `set_debug_traps', you set it to point to a - function in your program, that function is called when `GDB' - continues after stopping on a trap (for example, bus error). The - function indicated by `exceptionHook' is called with one - parameter: an `int' which is the exception number. - - 4. Compile and link together: your program, the GDB debugging stub for - your target architecture, and the supporting subroutines. - - 5. Make sure you have a serial connection between your target machine - and the GDB host, and identify the serial port used for this on - the host. - - 6. Download your program to your target machine (or get it there by - whatever means the manufacturer provides), and start it. - - 7. To start remote debugging, run GDB on the host machine, and specify - as an executable file the program that is running in the remote - machine. This tells GDB how to find your program's symbols and - the contents of its pure text. - - Then establish communication using the `target remote' command. - Its argument specifies how to communicate with the target - machine--either via a devicename attached to a direct serial line, - or a TCP port (usually to a terminal server which in turn has a - serial line to the target). For example, to use a serial line - connected to the device named `/dev/ttyb': - - target remote /dev/ttyb - - To use a TCP connection, use an argument of the form `HOST:port'. - For example, to connect to port 2828 on a terminal server named - `manyfarms': - - target remote manyfarms:2828 - - Now you can use all the usual commands to examine and change data -and to step and continue the remote program. - - To resume the remote program and stop debugging it, use the `detach' -command. - - Whenever GDB is waiting for the remote program, if you type the -interrupt character (often C-C), GDB attempts to stop the program. -This may or may not succeed, depending in part on the hardware and the -serial drivers the remote system uses. If you type the interrupt -character once again, GDB displays this prompt: - - Interrupted while waiting for the program. - Give up (and stop debugging it)? (y or n) - - If you type `y', GDB abandons the remote debugging session. (If you -decide you want to try again later, you can use `target remote' again -to connect once more.) If you type `n', GDB goes back to waiting. - - -File: gdb.info, Node: Protocol, Next: Server, Prev: Debug Session, Up: Remote Serial - -Outline of the communication protocol -------------------------------------- - - The stub files provided with GDB implement the target side of the -communication protocol, and the GDB side is implemented in the GDB -source file `remote.c'. Normally, you can simply allow these -subroutines to communicate, and ignore the details. (If you're -implementing your own stub file, you can still ignore the details: start -with one of the existing stub files. `sparc-stub.c' is the best -organized, and therefore the easiest to read.) - - However, there may be occasions when you need to know something about -the protocol--for example, if there is only one serial port to your -target machine, you might want your program to do something special if -it recognizes a packet meant for GDB. - - All GDB commands and responses (other than acknowledgements, which -are single characters) are sent as a packet which includes a checksum. -A packet is introduced with the character `$', and ends with the -character `#' followed by a two-digit checksum: - - $PACKET INFO#CHECKSUM - -CHECKSUM is computed as the modulo 256 sum of the PACKET INFO -characters. - - When either the host or the target machine receives a packet, the -first response expected is an acknowledgement: a single character, -either `+' (to indicate the package was received correctly) or `-' (to -request retransmission). - - The host (GDB) sends commands, and the target (the debugging stub -incorporated in your program) sends data in response. The target also -sends data when your program stops. - - Command packets are distinguished by their first character, which -identifies the kind of command. - - These are the commands currently supported: - -`g' - Requests the values of CPU registers. - -`G' - Sets the values of CPU registers. - -`mADDR,COUNT' - Read COUNT bytes at location ADDR. - -`MADDR,COUNT:...' - Write COUNT bytes at location ADDR. - -`c' -`cADDR' - Resume execution at the current address (or at ADDR if supplied). - -`s' -`sADDR' - Step the target program for one instruction, from either the - current program counter or from ADDR if supplied. - -`k' - Kill the target program. - -`?' - Report the most recent signal. To allow you to take advantage of - the GDB signal handling commands, one of the functions of the - debugging stub is to report CPU traps as the corresponding POSIX - signal values. - - If you have trouble with the serial connection, you can use the -command `set remotedebug'. This makes GDB report on all packets sent -back and forth across the serial line to the remote machine. The -packet-debugging information is printed on the GDB standard output -stream. `set remotedebug off' turns it off, and `show remotedebug' -will show you its current state. - - -File: gdb.info, Node: Server, Prev: Protocol, Up: Remote Serial - -Using the `gdbserver' program ------------------------------ - - `gdbserver' is a control program for Unix-like systems, which allows -you to connect your program with a remote GDB via `target remote'--but -without linking in the usual debugging stub. - - `gdbserver' is not a complete replacement for the debugging stubs, -because it requires essentially the same operating-system facilities -that GDB itself does. In fact, a system that can run `gdbserver' to -connect to a remote GDB could also run GDBN locally! `gdbserver' is -sometimes useful nevertheless, because it is a much smaller program -than GDB itself. It is also easier to port than all of GDBN, so you -may be able to get started more quickly on a new system by using -`gdbserver'. - - GDB and `gdbserver' communicate via either a serial line or a TCP -connection, using the standard GDB remote serial protocol. - -*On the target,* - you need to have a copy of the program you want to debug. - `gdbserver' does not need your program's symbol table, so you can - strip the program if necessary to save space. GDB on the host - system does all the symbol handling. - - To use the server, you must tell it how to communicate with {No - Value For "GDB"}; the name of your program; and the arguments for - your program. The syntax is: - - target> gdbserver COMM PROGRAM [ ARGS ... ] - - COMM is either a device name (to use a serial line) or a TCP - hostname and portnumber. For example, to debug emacs with the - argument `foo.txt' and communicate with GDB over the serial port - `/dev/com1': - - target> gdbserver /dev/com1 emacs foo.txt - - `gdbserver' waits passively for the host GDB to communicate with - it. - - To use a TCP connection instead of a serial line: - - target> gdbserver host:2345 emacs foo.txt - - The only difference from the previous example is the first - argument, specifying that you are communicating with the host GDB - via TCP. The `host:2345' argument means that `gdbserver' is to - expect a TCP connection from machine `host' to local TCP port 2345. - (Currently, the `host' part is ignored.) You can choose any number - you want for the port number as long as it does not conflict with - any TCP ports already in use on the target system.(1) You must use - the same port number with the host GDB `target remote' command. - -*On the host,* - you need an unstripped copy of your program, since GDB needs - symbols and debugging information. Start up GDB as usual, using - the name of the local copy of your program as the first argument. - (You may also need the `--baud' option if the serial line is - running at anything other than 9600 bps.) After that, use `target - remote' to establish communications with `gdbserver'. Its - argument is either a device name (usually a serial device, like - `/dev/ttyb'), or a TCP port descriptof in the form `HOST:PORT'. - For example: - - (gdb) target remote /dev/ttyb - - communicates with the server via serial line `/dev/ttyb', and - - (gdb) target remote the-target:2345 - - communicates via a TCP connection to port 2345 on host - `the-target'. For TCP connections, you must start up `gdbserver' - prior to using the `target remote' command. Otherwise you may get - an error whose text depends on the host system, but which usually - looks something like `Connection refused'. - - ---------- Footnotes ---------- - - (1) If you choose a port number that conflicts with another -service, `gdbserver' prints an error message and exits. - - -File: gdb.info, Node: i960-Nindy Remote, Next: UDI29K Remote, Prev: Remote Serial, Up: Remote - -GDB with a remote i960 (Nindy) ------------------------------- - - "Nindy" is a ROM Monitor program for Intel 960 target systems. When -GDB is configured to control a remote Intel 960 using Nindy, you can -tell GDB how to connect to the 960 in several ways: - - * Through command line options specifying serial port, version of the - Nindy protocol, and communications speed; - - * By responding to a prompt on startup; - - * By using the `target' command at any point during your GDB - session. *Note Commands for managing targets: Target Commands. - -* Menu: - -* Nindy Startup:: Startup with Nindy -* Nindy Options:: Options for Nindy -* Nindy Reset:: Nindy reset command - - -File: gdb.info, Node: Nindy Startup, Next: Nindy Options, Up: i960-Nindy Remote - -Startup with Nindy ------------------- - - If you simply start `gdb' without using any command-line options, -you are prompted for what serial port to use, *before* you reach the -ordinary GDB prompt: - - Attach /dev/ttyNN -- specify NN, or "quit" to quit: - -Respond to the prompt with whatever suffix (after `/dev/tty') -identifies the serial port you want to use. You can, if you choose, -simply start up with no Nindy connection by responding to the prompt -with an empty line. If you do this and later wish to attach to Nindy, -use `target' (*note Commands for managing targets: Target Commands.). - diff --git a/gnu/usr.bin/gdb/doc/gdb.info-6 b/gnu/usr.bin/gdb/doc/gdb.info-6 deleted file mode 100644 index 8a746fd..0000000 --- a/gnu/usr.bin/gdb/doc/gdb.info-6 +++ /dev/null @@ -1,1220 +0,0 @@ -This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input -file gdb.texinfo. - -START-INFO-DIR-ENTRY -* Gdb:: The GNU debugger. -END-INFO-DIR-ENTRY - This file documents the GNU debugger GDB. - - This is Edition 4.09, August 1993, of `Debugging with GDB: the GNU -Source-Level Debugger' for GDB Version 4.11. - - Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software -Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the entire resulting derived work is distributed under the terms -of a permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions. - - -File: gdb.info, Node: Nindy Options, Next: Nindy Reset, Prev: Nindy Startup, Up: i960-Nindy Remote - -Options for Nindy ------------------ - - These are the startup options for beginning your GDB session with a -Nindy-960 board attached: - -`-r PORT' - Specify the serial port name of a serial interface to be used to - connect to the target system. This option is only available when - GDB is configured for the Intel 960 target architecture. You may - specify PORT as any of: a full pathname (e.g. `-r /dev/ttya'), a - device name in `/dev' (e.g. `-r ttya'), or simply the unique - suffix for a specific `tty' (e.g. `-r a'). - -`-O' - (An uppercase letter "O", not a zero.) Specify that GDB should use - the "old" Nindy monitor protocol to connect to the target system. - This option is only available when GDB is configured for the Intel - 960 target architecture. - - *Warning:* if you specify `-O', but are actually trying to - connect to a target system that expects the newer protocol, - the connection fails, appearing to be a speed mismatch. GDB - repeatedly attempts to reconnect at several different line - speeds. You can abort this process with an interrupt. - -`-brk' - Specify that GDB should first send a `BREAK' signal to the target - system, in an attempt to reset it, before connecting to a Nindy - target. - - *Warning:* Many target systems do not have the hardware that - this requires; it only works with a few boards. - - The standard `-b' option controls the line speed used on the serial -port. - - -File: gdb.info, Node: Nindy Reset, Prev: Nindy Options, Up: i960-Nindy Remote - -Nindy reset command -------------------- - -`reset' - For a Nindy target, this command sends a "break" to the remote - target system; this is only useful if the target has been equipped - with a circuit to perform a hard reset (or some other interesting - action) when a break is detected. - - -File: gdb.info, Node: UDI29K Remote, Next: EB29K Remote, Prev: i960-Nindy Remote, Up: Remote - -GDB and the UDI protocol for AMD29K ------------------------------------ - - GDB supports AMD's UDI ("Universal Debugger Interface") protocol for -debugging the a29k processor family. To use this configuration with -AMD targets running the MiniMON monitor, you need the program `MONTIP', -available from AMD at no charge. You can also use GDB with the UDI -conformant a29k simulator program `ISSTIP', also available from AMD. - -`target udi KEYWORD' - Select the UDI interface to a remote a29k board or simulator, where - KEYWORD is an entry in the AMD configuration file `udi_soc'. This - file contains keyword entries which specify parameters used to - connect to a29k targets. If the `udi_soc' file is not in your - working directory, you must set the environment variable `UDICONF' - to its pathname. - - -File: gdb.info, Node: EB29K Remote, Next: VxWorks Remote, Prev: UDI29K Remote, Up: Remote - -GDB and the EBMON protocol for AMD29K -------------------------------------- - - AMD distributes a 29K development board meant to fit in a PC, -together with a DOS-hosted monitor program called `EBMON'. As a -shorthand term, this development system is called the "EB29K". To use -GDB from a Unix system to run programs on the EB29K board, you must -first connect a serial cable between the PC (which hosts the EB29K -board) and a serial port on the Unix system. In the following, we -assume you've hooked the cable between the PC's `COM1' port and -`/dev/ttya' on the Unix system. - -* Menu: - -* Comms (EB29K):: Communications setup -* gdb-EB29K:: EB29K cross-debugging -* Remote Log:: Remote log - - -File: gdb.info, Node: Comms (EB29K), Next: gdb-EB29K, Up: EB29K Remote - -Communications setup --------------------- - - The next step is to set up the PC's port, by doing something like -this in DOS on the PC: - - C:\> MODE com1:9600,n,8,1,none - -This example--run on an MS DOS 4.0 system--sets the PC port to 9600 -bps, no parity, eight data bits, one stop bit, and no "retry" action; -you must match the communications parameters when establishing the Unix -end of the connection as well. - - To give control of the PC to the Unix side of the serial line, type -the following at the DOS console: - - C:\> CTTY com1 - -(Later, if you wish to return control to the DOS console, you can use -the command `CTTY con'--but you must send it over the device that had -control, in our example over the `COM1' serial line). - - From the Unix host, use a communications program such as `tip' or -`cu' to communicate with the PC; for example, - - cu -s 9600 -l /dev/ttya - -The `cu' options shown specify, respectively, the linespeed and the -serial port to use. If you use `tip' instead, your command line may -look something like the following: - - tip -9600 /dev/ttya - -Your system may require a different name where we show `/dev/ttya' as -the argument to `tip'. The communications parameters, including which -port to use, are associated with the `tip' argument in the "remote" -descriptions file--normally the system table `/etc/remote'. - - Using the `tip' or `cu' connection, change the DOS working directory -to the directory containing a copy of your 29K program, then start the -PC program `EBMON' (an EB29K control program supplied with your board -by AMD). You should see an initial display from `EBMON' similar to the -one that follows, ending with the `EBMON' prompt `#'-- - - C:\> G: - - G:\> CD \usr\joe\work29k - - G:\USR\JOE\WORK29K> EBMON - Am29000 PC Coprocessor Board Monitor, version 3.0-18 - Copyright 1990 Advanced Micro Devices, Inc. - Written by Gibbons and Associates, Inc. - - Enter '?' or 'H' for help - - PC Coprocessor Type = EB29K - I/O Base = 0x208 - Memory Base = 0xd0000 - - Data Memory Size = 2048KB - Available I-RAM Range = 0x8000 to 0x1fffff - Available D-RAM Range = 0x80002000 to 0x801fffff - - PageSize = 0x400 - Register Stack Size = 0x800 - Memory Stack Size = 0x1800 - - CPU PRL = 0x3 - Am29027 Available = No - Byte Write Available = Yes - - # ~. - - Then exit the `cu' or `tip' program (done in the example by typing -`~.' at the `EBMON' prompt). `EBMON' will keep running, ready for GDB -to take over. - - For this example, we've assumed what is probably the most convenient -way to make sure the same 29K program is on both the PC and the Unix -system: a PC/NFS connection that establishes "drive `G:'" on the PC as -a file system on the Unix host. If you do not have PC/NFS or something -similar connecting the two systems, you must arrange some other -way--perhaps floppy-disk transfer--of getting the 29K program from the -Unix system to the PC; GDB will *not* download it over the serial line. - - -File: gdb.info, Node: gdb-EB29K, Next: Remote Log, Prev: Comms (EB29K), Up: EB29K Remote - -EB29K cross-debugging ---------------------- - - Finally, `cd' to the directory containing an image of your 29K -program on the Unix system, and start GDB--specifying as argument the -name of your 29K program: - - cd /usr/joe/work29k - gdb myfoo - - Now you can use the `target' command: - - target amd-eb /dev/ttya 9600 MYFOO - -In this example, we've assumed your program is in a file called -`myfoo'. Note that the filename given as the last argument to `target -amd-eb' should be the name of the program as it appears to DOS. In our -example this is simply `MYFOO', but in general it can include a DOS -path, and depending on your transfer mechanism may not resemble the -name on the Unix side. - - At this point, you can set any breakpoints you wish; when you are -ready to see your program run on the 29K board, use the GDB command -`run'. - - To stop debugging the remote program, use the GDB `detach' command. - - To return control of the PC to its console, use `tip' or `cu' once -again, after your GDB session has concluded, to attach to `EBMON'. You -can then type the command `q' to shut down `EBMON', returning control -to the DOS command-line interpreter. Type `CTTY con' to return command -input to the main DOS console, and type `~.' to leave `tip' or `cu'. - - -File: gdb.info, Node: Remote Log, Prev: gdb-EB29K, Up: EB29K Remote - -Remote log ----------- - - The `target amd-eb' command creates a file `eb.log' in the current -working directory, to help debug problems with the connection. -`eb.log' records all the output from `EBMON', including echoes of the -commands sent to it. Running `tail -f' on this file in another window -often helps to understand trouble with `EBMON', or unexpected events on -the PC side of the connection. - - -File: gdb.info, Node: ST2000 Remote, Next: Hitachi Remote, Prev: VxWorks Remote, Up: Remote - -GDB with a Tandem ST2000 ------------------------- - - To connect your ST2000 to the host system, see the manufacturer's -manual. Once the ST2000 is physically attached, you can run - - target st2000 DEV SPEED - -to establish it as your debugging environment. DEV is normally the -name of a serial device, such as `/dev/ttya', connected to the ST2000 -via a serial line. You can instead specify DEV as a TCP connection -(for example, to a serial line attached via a terminal concentrator) -using the syntax `HOSTNAME:PORTNUMBER'. - - The `load' and `attach' commands are *not* defined for this target; -you must load your program into the ST2000 as you normally would for -standalone operation. GDB will read debugging information (such as -symbols) from a separate, debugging version of the program available on -your host computer. - - These auxiliary GDB commands are available to help you with the -ST2000 environment: - -`st2000 COMMAND' - Send a COMMAND to the STDBUG monitor. See the manufacturer's - manual for available commands. - -`connect' - Connect the controlling terminal to the STDBUG command monitor. - When you are done interacting with STDBUG, typing either of two - character sequences will get you back to the GDB command prompt: - `RET~.' (Return, followed by tilde and period) or `RET~C-d' - (Return, followed by tilde and control-D). - - -File: gdb.info, Node: VxWorks Remote, Next: ST2000 Remote, Prev: EB29K Remote, Up: Remote - -GDB and VxWorks ---------------- - - GDB enables developers to spawn and debug tasks running on networked -VxWorks targets from a Unix host. Already-running tasks spawned from -the VxWorks shell can also be debugged. GDB uses code that runs on -both the Unix host and on the VxWorks target. The program `gdb' is -installed and executed on the Unix host. (It may be installed with the -name `vxgdb', to distinguish it from a GDB for debugging programs on -the host itself.) - - The following information on connecting to VxWorks was current when -this manual was produced; newer releases of VxWorks may use revised -procedures. - - The remote debugging interface (RDB) routines are installed and -executed on the VxWorks target. These routines are included in the -VxWorks library `rdb.a' and are incorporated into the system image when -source-level debugging is enabled in the VxWorks configuration. - - If you wish, you can define `INCLUDE_RDB' in the VxWorks -configuration file `configAll.h' to include the RDB interface routines -and spawn the source debugging task `tRdbTask' when VxWorks is booted. -For more information on configuring and remaking VxWorks, see the -manufacturer's manual. - - Once you have included the RDB interface in your VxWorks system image -and set your Unix execution search path to find GDB, you are ready to -run GDB. From your Unix host, run `gdb' (or `vxgdb', depending on your -installation). - - GDB comes up showing the prompt: - - (vxgdb) - -* Menu: - -* VxWorks Connection:: Connecting to VxWorks -* VxWorks Download:: VxWorks download -* VxWorks Attach:: Running tasks - - -File: gdb.info, Node: VxWorks Connection, Next: VxWorks Download, Up: VxWorks Remote - -Connecting to VxWorks ---------------------- - - The GDB command `target' lets you connect to a VxWorks target on the -network. To connect to a target whose host name is "`tt'", type: - - (vxgdb) target vxworks tt - - GDB displays messages like these: - - Attaching remote machine across net... - Connected to tt. - - GDB then attempts to read the symbol tables of any object modules -loaded into the VxWorks target since it was last booted. GDB locates -these files by searching the directories listed in the command search -path (*note Your program's environment: Environment.); if it fails to -find an object file, it displays a message such as: - - prog.o: No such file or directory. - - When this happens, add the appropriate directory to the search path -with the GDB command `path', and execute the `target' command again. - - -File: gdb.info, Node: VxWorks Download, Next: VxWorks Attach, Prev: VxWorks Connection, Up: VxWorks Remote - -VxWorks download ----------------- - - If you have connected to the VxWorks target and you want to debug an -object that has not yet been loaded, you can use the GDB `load' command -to download a file from Unix to VxWorks incrementally. The object file -given as an argument to the `load' command is actually opened twice: -first by the VxWorks target in order to download the code, then by GDB -in order to read the symbol table. This can lead to problems if the -current working directories on the two systems differ. If both systems -have NFS mounted the same filesystems, you can avoid these problems by -using absolute paths. Otherwise, it is simplest to set the working -directory on both systems to the directory in which the object file -resides, and then to reference the file by its name, without any path. -For instance, a program `prog.o' may reside in `VXPATH/vw/demo/rdb' in -VxWorks and in `HOSTPATH/vw/demo/rdb' on the host. To load this -program, type this on VxWorks: - - -> cd "VXPATH/vw/demo/rdb" - - Then, in GDB, type: - - (vxgdb) cd HOSTPATH/vw/demo/rdb - (vxgdb) load prog.o - - GDB displays a response similar to this: - - Reading symbol data from wherever/vw/demo/rdb/prog.o... done. - - You can also use the `load' command to reload an object module after -editing and recompiling the corresponding source file. Note that this -will cause GDB to delete all currently-defined breakpoints, -auto-displays, and convenience variables, and to clear the value -history. (This is necessary in order to preserve the integrity of -debugger data structures that reference the target system's symbol -table.) - - -File: gdb.info, Node: VxWorks Attach, Prev: VxWorks Download, Up: VxWorks Remote - -Running tasks -------------- - - You can also attach to an existing task using the `attach' command as -follows: - - (vxgdb) attach TASK - -where TASK is the VxWorks hexadecimal task ID. The task can be running -or suspended when you attach to it. If running, it will be suspended at -the time of attachment. - - -File: gdb.info, Node: Hitachi Remote, Next: MIPS Remote, Prev: ST2000 Remote, Up: Remote - -GDB and Hitachi Microprocessors -------------------------------- - - GDB needs to know these things to talk to your Hitachi SH, H8/300, -or H8/500: - - 1. that you want to use `target hms', the remote debugging interface - for Hitachi microprocessors (this is the default when GDB is - configured specifically for the Hitachi SH, H8/300, or H8/500); - - 2. what serial device connects your host to your Hitachi board (the - first serial device available on your host is the default); - - - Use the special `gdb' command `device PORT' if you need to -explicitly set the serial device. The default PORT is the first -available port on your host. This is only necessary on Unix hosts, -where it is typically something like `/dev/ttya'. - - `gdb' has another special command to set the communications speed: -`speed BPS'. This command also is only used from Unix hosts; on DOS -hosts, set the line speed as usual from outside GDB with the DOS `mode' -command (for instance, `mode com2:9600,n,8,1,p' for a 9600 bps -connection). - - The `device' and `speed' commands are available only when you use a -Unix host to debug your Hitachi microprocessor programs. If you use a -DOS host, GDB depends on an auxiliary terminate-and-stay-resident -program called `asynctsr' to communicate with the development board -through a PC serial port. You must also use the DOS `mode' command to -set up the serial port on the DOS side. - - -File: gdb.info, Node: MIPS Remote, Next: Simulator, Prev: Hitachi Remote, Up: Remote - -GDB and remote MIPS boards --------------------------- - - GDB can use the MIPS remote debugging protocol to talk to a MIPS -board attached to a serial line. This is available when you configure -GDB with `--target=mips-idt-ecoff'. - - To run a program on the board, start up `gdb' with the name of your -program as the argument. To connect to the board, use the command -`target mips PORT', where PORT is the name of the serial port connected -to the board. If the program has not already been downloaded to the -board, you may use the `load' command to download it. You can then use -all the usual GDB commands. - - You can also specify PORT as a TCP connection (for instance, to a -serial line managed by a terminal concentrator), using the syntax -`HOSTNAME:PORTNUMBER'. - - You can see some debugging information about communications with the -board by setting the `remotedebug' variable. If you set it to 1 using -`set remotedebug 1' every packet will be displayed. If you set it to 2 -every character will be displayed. You can check the current value at -any time with the command `show remotedebug'. - - You can control the timeout used while waiting for a packet, in the -MIPS remote protocol, with the `set timeout SECONDS' command. The -default is 5 seconds. Similarly, you can control the timeout used while -waiting for an acknowledgement of a packet with the `set -retransmit-timeout SECONDS' command. The default is 3 seconds. You -can inspect both values with `show timeout' and `show -retransmit-timeout'. (These commands are *only* available when GDB is -configured for `--target=mips-idt-ecoff'.) - - If your target board does not support the MIPS floating point -coprocessor, you should use the command `set mipsfpu off' (you may wish -to put this in your .gdbinit file). This tells GDB how to find the -return value of functions which return floating point values. It also -allows GDB to avoid saving the floating point registers when calling -functions on the board. - - -File: gdb.info, Node: Simulator, Prev: MIPS Remote, Up: Remote - -Simulated CPU target --------------------- - - For some configurations, GDB includes a CPU simulator that you can -use instead of a hardware CPU to debug your programs. Currently, a -simulator is available when GDB is configured to debug Zilog Z8000 or -Hitachi microprocessor targets. - - For the Z8000 family, `target sim' simulates either the Z8002 (the -unsegmented variant of the Z8000 architecture) or the Z8001 (the -segmented variant). The simulator recognizes which architecture is -appropriate by inspecting the object code. - -`target sim' - Debug programs on a simulated CPU (which CPU depends on the GDB - configuration) - -After specifying this target, you can debug programs for the simulated -CPU in the same style as programs for your host computer; use the -`file' command to load a new program image, the `run' command to run -your program, and so on. - - As well as making available all the usual machine registers (see -`info reg'), this debugging target provides three additional items of -information as specially named registers: - -`cycles' - Counts clock-ticks in the simulator. - -`insts' - Counts instructions run in the simulator. - -`time' - Execution time in 60ths of a second. - - You can refer to these values in GDB expressions with the usual -conventions; for example, `b fputc if $cycles>5000' sets a conditional -breakpoint that will suspend only after at least 5000 simulated clock -ticks. - - -File: gdb.info, Node: Controlling GDB, Next: Sequences, Prev: Targets, Up: Top - -Controlling GDB -*************** - - You can alter the way GDB interacts with you by using the `set' -command. For commands controlling how GDB displays data, *note Print -settings: Print Settings.; other settings are described here. - -* Menu: - -* Prompt:: Prompt -* Editing:: Command editing -* History:: Command history -* Screen Size:: Screen size -* Numbers:: Numbers -* Messages/Warnings:: Optional warnings and messages - - -File: gdb.info, Node: Prompt, Next: Editing, Up: Controlling GDB - -Prompt -====== - - GDB indicates its readiness to read a command by printing a string -called the "prompt". This string is normally `(gdb)'. You can change -the prompt string with the `set prompt' command. For instance, when -debugging GDB with GDB, it is useful to change the prompt in one of the -GDB sessions so that you can always tell which one you are talking to. - -`set prompt NEWPROMPT' - Directs GDB to use NEWPROMPT as its prompt string henceforth. - -`show prompt' - Prints a line of the form: `Gdb's prompt is: YOUR-PROMPT' - - -File: gdb.info, Node: Editing, Next: History, Prev: Prompt, Up: Controlling GDB - -Command editing -=============== - - GDB reads its input commands via the "readline" interface. This GNU -library provides consistent behavior for programs which provide a -command line interface to the user. Advantages are `emacs'-style or -`vi'-style inline editing of commands, `csh'-like history substitution, -and a storage and recall of command history across debugging sessions. - - You may control the behavior of command line editing in GDB with the -command `set'. - -`set editing' -`set editing on' - Enable command line editing (enabled by default). - -`set editing off' - Disable command line editing. - -`show editing' - Show whether command line editing is enabled. - - -File: gdb.info, Node: History, Next: Screen Size, Prev: Editing, Up: Controlling GDB - -Command history -=============== - - GDB can keep track of the commands you type during your debugging -sessions, so that you can be certain of precisely what happened. Use -these commands to manage the GDB command history facility. - -`set history filename FNAME' - Set the name of the GDB command history file to FNAME. This is - the file from which GDB will read an initial command history list - or to which it will write this list when it exits. This list is - accessed through history expansion or through the history command - editing characters listed below. This file defaults to the value - of the environment variable `GDBHISTFILE', or to `./.gdb_history' - if this variable is not set. - -`set history save' -`set history save on' - Record command history in a file, whose name may be specified with - the `set history filename' command. By default, this option is - disabled. - -`set history save off' - Stop recording command history in a file. - -`set history size SIZE' - Set the number of commands which GDB will keep in its history list. - This defaults to the value of the environment variable `HISTSIZE', - or to 256 if this variable is not set. - - History expansion assigns special meaning to the character `!'. - - Since `!' is also the logical not operator in C, history expansion -is off by default. If you decide to enable history expansion with the -`set history expansion on' command, you may sometimes need to follow -`!' (when it is used as logical not, in an expression) with a space or -a tab to prevent it from being expanded. The readline history -facilities will not attempt substitution on the strings `!=' and `!(', -even when history expansion is enabled. - - The commands to control history expansion are: - -`set history expansion on' -`set history expansion' - Enable history expansion. History expansion is off by default. - -`set history expansion off' - Disable history expansion. - - The readline code comes with more complete documentation of - editing and history expansion features. Users unfamiliar with - `emacs' or `vi' may wish to read it. - -`show history' -`show history filename' -`show history save' -`show history size' -`show history expansion' - These commands display the state of the GDB history parameters. - `show history' by itself displays all four states. - -`show commands' - Display the last ten commands in the command history. - -`show commands N' - Print ten commands centered on command number N. - -`show commands +' - Print ten commands just after the commands last printed. - - -File: gdb.info, Node: Screen Size, Next: Numbers, Prev: History, Up: Controlling GDB - -Screen size -=========== - - Certain commands to GDB may produce large amounts of information -output to the screen. To help you read all of it, GDB pauses and asks -you for input at the end of each page of output. Type RET when you -want to continue the output, or `q' to discard the remaining output. -Also, the screen width setting determines when to wrap lines of output. -Depending on what is being printed, GDB tries to break the line at a -readable place, rather than simply letting it overflow onto the -following line. - - Normally GDB knows the size of the screen from the termcap data base -together with the value of the `TERM' environment variable and the -`stty rows' and `stty cols' settings. If this is not correct, you can -override it with the `set height' and `set width' commands: - -`set height LPP' -`show height' -`set width CPL' -`show width' - These `set' commands specify a screen height of LPP lines and a - screen width of CPL characters. The associated `show' commands - display the current settings. - - If you specify a height of zero lines, GDB will not pause during - output no matter how long the output is. This is useful if output - is to a file or to an editor buffer. - - Likewise, you can specify `set width 0' to prevent GDB from - wrapping its output. - - -File: gdb.info, Node: Numbers, Next: Messages/Warnings, Prev: Screen Size, Up: Controlling GDB - -Numbers -======= - - You can always enter numbers in octal, decimal, or hexadecimal in -GDB by the usual conventions: octal numbers begin with `0', decimal -numbers end with `.', and hexadecimal numbers begin with `0x'. Numbers -that begin with none of these are, by default, entered in base 10; -likewise, the default display for numbers--when no particular format is -specified--is base 10. You can change the default base for both input -and output with the `set radix' command. - -`set radix BASE' - Set the default base for numeric input and display. Supported - choices for BASE are decimal 8, 10, or 16. BASE must itself be - specified either unambiguously or using the current default radix; - for example, any of - - set radix 012 - set radix 10. - set radix 0xa - - will set the base to decimal. On the other hand, `set radix 10' - will leave the radix unchanged no matter what it was. - -`show radix' - Display the current default base for numeric input and display. - - -File: gdb.info, Node: Messages/Warnings, Prev: Numbers, Up: Controlling GDB - -Optional warnings and messages -============================== - - By default, GDB is silent about its inner workings. If you are -running on a slow machine, you may want to use the `set verbose' -command. It will make GDB tell you when it does a lengthy internal -operation, so you will not think it has crashed. - - Currently, the messages controlled by `set verbose' are those which -announce that the symbol table for a source file is being read; see -`symbol-file' in *Note Commands to specify files: Files. - -`set verbose on' - Enables GDB output of certain informational messages. - -`set verbose off' - Disables GDB output of certain informational messages. - -`show verbose' - Displays whether `set verbose' is on or off. - - By default, if GDB encounters bugs in the symbol table of an object -file, it is silent; but if you are debugging a compiler, you may find -this information useful (*note Errors reading symbol files: Symbol -Errors.). - -`set complaints LIMIT' - Permits GDB to output LIMIT complaints about each type of unusual - symbols before becoming silent about the problem. Set LIMIT to - zero to suppress all complaints; set it to a large number to - prevent complaints from being suppressed. - -`show complaints' - Displays how many symbol complaints GDB is permitted to produce. - - By default, GDB is cautious, and asks what sometimes seems to be a -lot of stupid questions to confirm certain commands. For example, if -you try to run a program which is already running: - - (gdb) run - The program being debugged has been started already. - Start it from the beginning? (y or n) - - If you are willing to unflinchingly face the consequences of your own -commands, you can disable this "feature": - -`set confirm off' - Disables confirmation requests. - -`set confirm on' - Enables confirmation requests (the default). - -`show confirm' - Displays state of confirmation requests. - - Some systems allow individual object files that make up your program -to be replaced without stopping and restarting your program. For -example, in VxWorks you can simply recompile a defective object file -and keep on running. If you are running on one of these systems, you -can allow GDB to reload the symbols for automatically relinked modules: - -`set symbol-reloading on' - Replace symbol definitions for the corresponding source file when - an object file with a particular name is seen again. - -`set symbol-reloading off' - Do not replace symbol definitions when re-encountering object - files of the same name. This is the default state; if you are not - running on a system that permits automatically relinking modules, - you should leave `symbol-reloading' off, since otherwise GDB may - discard symbols when linking large programs, that may contain - several modules (from different directories or libraries) with the - same name. - -`show symbol-reloading' - Show the current `on' or `off' setting. - - -File: gdb.info, Node: Sequences, Next: Emacs, Prev: Controlling GDB, Up: Top - -Canned Sequences of Commands -**************************** - - Aside from breakpoint commands (*note Breakpoint command lists: -Break Commands.), GDB provides two ways to store sequences of commands -for execution as a unit: user-defined commands and command files. - -* Menu: - -* Define:: User-defined commands -* Hooks:: User-defined command hooks -* Command Files:: Command files -* Output:: Commands for controlled output - - -File: gdb.info, Node: Define, Next: Hooks, Up: Sequences - -User-defined commands -===================== - - A "user-defined command" is a sequence of GDB commands to which you -assign a new name as a command. This is done with the `define' command. - -`define COMMANDNAME' - Define a command named COMMANDNAME. If there is already a command - by that name, you are asked to confirm that you want to redefine - it. - - The definition of the command is made up of other GDB command - lines, which are given following the `define' command. The end of - these commands is marked by a line containing `end'. - -`document COMMANDNAME' - Give documentation to the user-defined command COMMANDNAME. The - command COMMANDNAME must already be defined. This command reads - lines of documentation just as `define' reads the lines of the - command definition, ending with `end'. After the `document' - command is finished, `help' on command COMMANDNAME will print the - documentation you have specified. - - You may use the `document' command again to change the - documentation of a command. Redefining the command with `define' - does not change the documentation. - -`help user-defined' - List all user-defined commands, with the first line of the - documentation (if any) for each. - -`show user' -`show user COMMANDNAME' - Display the GDB commands used to define COMMANDNAME (but not its - documentation). If no COMMANDNAME is given, display the - definitions for all user-defined commands. - - User-defined commands do not take arguments. When they are -executed, the commands of the definition are not printed. An error in -any command stops execution of the user-defined command. - - Commands that would ask for confirmation if used interactively -proceed without asking when used inside a user-defined command. Many -GDB commands that normally print messages to say what they are doing -omit the messages when used in a user-defined command. - - -File: gdb.info, Node: Hooks, Next: Command Files, Prev: Define, Up: Sequences - -User-defined command hooks -========================== - - You may define *hooks*, which are a special kind of user-defined -command. Whenever you run the command `foo', if the user-defined -command `hook-foo' exists, it is executed (with no arguments) before -that command. - - In addition, a pseudo-command, `stop' exists. Defining -(`hook-stop') makes the associated commands execute every time -execution stops in your program: before breakpoint commands are run, -displays are printed, or the stack frame is printed. - - For example, to ignore `SIGALRM' signals while single-stepping, but -treat them normally during normal execution, you could define: - - define hook-stop - handle SIGALRM nopass - end - - define hook-run - handle SIGALRM pass - end - - define hook-continue - handle SIGLARM pass - end - - You can define a hook for any single-word command in GDB, but not -for command aliases; you should define a hook for the basic command -name, e.g. `backtrace' rather than `bt'. If an error occurs during -the execution of your hook, execution of GDB commands stops and GDB -issues a prompt (before the command that you actually typed had a -chance to run). - - If you try to define a hook which does not match any known command, -you will get a warning from the `define' command. - - -File: gdb.info, Node: Command Files, Next: Output, Prev: Hooks, Up: Sequences - -Command files -============= - - A command file for GDB is a file of lines that are GDB commands. -Comments (lines starting with `#') may also be included. An empty line -in a command file does nothing; it does not mean to repeat the last -command, as it would from the terminal. - - When you start GDB, it automatically executes commands from its -"init files". These are files named `.gdbinit'. GDB reads the init -file (if any) in your home directory and then the init file (if any) in -the current working directory. (The init files are not executed if you -use the `-nx' option; *note Choosing modes: Mode Options..) - - On some configurations of GDB, the init file is known by a different -name (these are typically environments where a specialized form of GDB -may need to coexist with other forms, hence a different name for the -specialized version's init file). These are the environments with -special init file names: - - * VxWorks (Wind River Systems real-time OS): `.vxgdbinit' - - * OS68K (Enea Data Systems real-time OS): `.os68gdbinit' - - * ES-1800 (Ericsson Telecom AB M68000 emulator): `.esgdbinit' - - You can also request the execution of a command file with the -`source' command: - -`source FILENAME' - Execute the command file FILENAME. - - The lines in a command file are executed sequentially. They are not -printed as they are executed. An error in any command terminates -execution of the command file. - - Commands that would ask for confirmation if used interactively -proceed without asking when used in a command file. Many GDB commands -that normally print messages to say what they are doing omit the -messages when called from command files. - - -File: gdb.info, Node: Output, Prev: Command Files, Up: Sequences - -Commands for controlled output -============================== - - During the execution of a command file or a user-defined command, -normal GDB output is suppressed; the only output that appears is what is -explicitly printed by the commands in the definition. This section -describes three commands useful for generating exactly the output you -want. - -`echo TEXT' - Print TEXT. Nonprinting characters can be included in TEXT using - C escape sequences, such as `\n' to print a newline. *No newline - will be printed unless you specify one.* In addition to the - standard C escape sequences, a backslash followed by a space - stands for a space. This is useful for displaying a string with - spaces at the beginning or the end, since leading and trailing - spaces are otherwise trimmed from all arguments. To print ` and - foo = ', use the command `echo \ and foo = \ '. - - A backslash at the end of TEXT can be used, as in C, to continue - the command onto subsequent lines. For example, - - echo This is some text\n\ - which is continued\n\ - onto several lines.\n - - produces the same output as - - echo This is some text\n - echo which is continued\n - echo onto several lines.\n - -`output EXPRESSION' - Print the value of EXPRESSION and nothing but that value: no - newlines, no `$NN = '. The value is not entered in the value - history either. *Note Expressions: Expressions, for more - information on expressions. - -`output/FMT EXPRESSION' - Print the value of EXPRESSION in format FMT. You can use the same - formats as for `print'. *Note Output formats: Output Formats, for - more information. - -`printf STRING, EXPRESSIONS...' - Print the values of the EXPRESSIONS under the control of STRING. - The EXPRESSIONS are separated by commas and may be either numbers - or pointers. Their values are printed as specified by STRING, - exactly as if your program were to execute the C subroutine - - printf (STRING, EXPRESSIONS...); - - For example, you can print two values in hex like this: - - printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo - - The only backslash-escape sequences that you can use in the format - string are the simple ones that consist of backslash followed by a - letter. - - -File: gdb.info, Node: Emacs, Next: GDB Bugs, Prev: Sequences, Up: Top - -Using GDB under GNU Emacs -************************* - - A special interface allows you to use GNU Emacs to view (and edit) -the source files for the program you are debugging with GDB. - - To use this interface, use the command `M-x gdb' in Emacs. Give the -executable file you want to debug as an argument. This command starts -GDB as a subprocess of Emacs, with input and output through a newly -created Emacs buffer. - - Using GDB under Emacs is just like using GDB normally except for two -things: - - * All "terminal" input and output goes through the Emacs buffer. - - This applies both to GDB commands and their output, and to the input -and output done by the program you are debugging. - - This is useful because it means that you can copy the text of -previous commands and input them again; you can even use parts of the -output in this way. - - All the facilities of Emacs' Shell mode are available for interacting -with your program. In particular, you can send signals the usual -way--for example, `C-c C-c' for an interrupt, `C-c C-z' for a stop. - - * GDB displays source code through Emacs. - - Each time GDB displays a stack frame, Emacs automatically finds the -source file for that frame and puts an arrow (`=>') at the left margin -of the current line. Emacs uses a separate buffer for source display, -and splits the screen to show both your GDB session and the source. - - Explicit GDB `list' or search commands still produce output as -usual, but you probably will have no reason to use them. - - *Warning:* If the directory where your program resides is not your - current directory, it can be easy to confuse Emacs about the - location of the source files, in which case the auxiliary display - buffer will not appear to show your source. GDB can find programs - by searching your environment's `PATH' variable, so the GDB input - and output session will proceed normally; but Emacs does not get - enough information back from GDB to locate the source files in - this situation. To avoid this problem, either start GDB mode from - the directory where your program resides, or specify a full path - name when prompted for the `M-x gdb' argument. - - A similar confusion can result if you use the GDB `file' command to - switch to debugging a program in some other location, from an - existing GDB buffer in Emacs. - - By default, `M-x gdb' calls the program called `gdb'. If you need -to call GDB by a different name (for example, if you keep several -configurations around, with different names) you can set the Emacs -variable `gdb-command-name'; for example, - - (setq gdb-command-name "mygdb") - -(preceded by `ESC ESC', or typed in the `*scratch*' buffer, or in your -`.emacs' file) will make Emacs call the program named "`mygdb'" instead. - - In the GDB I/O buffer, you can use these special Emacs commands in -addition to the standard Shell mode commands: - -`C-h m' - Describe the features of Emacs' GDB Mode. - -`M-s' - Execute to another source line, like the GDB `step' command; also - update the display window to show the current file and location. - -`M-n' - Execute to next source line in this function, skipping all function - calls, like the GDB `next' command. Then update the display window - to show the current file and location. - -`M-i' - Execute one instruction, like the GDB `stepi' command; update - display window accordingly. - -`M-x gdb-nexti' - Execute to next instruction, using the GDB `nexti' command; update - display window accordingly. - -`C-c C-f' - Execute until exit from the selected stack frame, like the GDB - `finish' command. - -`M-c' - Continue execution of your program, like the GDB `continue' - command. - - *Warning:* In Emacs v19, this command is `C-c C-p'. - -`M-u' - Go up the number of frames indicated by the numeric argument - (*note Numeric Arguments: (emacs)Arguments.), like the GDB `up' - command. - - *Warning:* In Emacs v19, this command is `C-c C-u'. - -`M-d' - Go down the number of frames indicated by the numeric argument, - like the GDB `down' command. - - *Warning:* In Emacs v19, this command is `C-c C-d'. - -`C-x &' - Read the number where the cursor is positioned, and insert it at - the end of the GDB I/O buffer. For example, if you wish to - disassemble code around an address that was displayed earlier, - type `disassemble'; then move the cursor to the address display, - and pick up the argument for `disassemble' by typing `C-x &'. - - You can customize this further by defining elements of the list - `gdb-print-command'; once it is defined, you can format or - otherwise process numbers picked up by `C-x &' before they are - inserted. A numeric argument to `C-x &' will both indicate that - you wish special formatting, and act as an index to pick an - element of the list. If the list element is a string, the number - to be inserted is formatted using the Emacs function `format'; - otherwise the number is passed as an argument to the corresponding - list element. - - In any source file, the Emacs command `C-x SPC' (`gdb-break') tells -GDB to set a breakpoint on the source line point is on. - - If you accidentally delete the source-display buffer, an easy way to -get it back is to type the command `f' in the GDB buffer, to request a -frame display; when you run under Emacs, this will recreate the source -buffer if necessary to show you the context of the current frame. - - The source files displayed in Emacs are in ordinary Emacs buffers -which are visiting the source files in the usual way. You can edit the -files with these buffers if you wish; but keep in mind that GDB -communicates with Emacs in terms of line numbers. If you add or delete -lines from the text, the line numbers that GDB knows will cease to -correspond properly with the code. - - -File: gdb.info, Node: GDB Bugs, Next: Command Line Editing, Prev: Emacs, Up: Top - -Reporting Bugs in GDB -********************* - - Your bug reports play an essential role in making GDB reliable. - - Reporting a bug may help you by bringing a solution to your problem, -or it may not. But in any case the principal function of a bug report -is to help the entire community by making the next version of GDB work -better. Bug reports are your contribution to the maintenance of GDB. - - In order for a bug report to serve its purpose, you must include the -information that enables us to fix the bug. - -* Menu: - -* Bug Criteria:: Have you found a bug? -* Bug Reporting:: How to report bugs - - -File: gdb.info, Node: Bug Criteria, Next: Bug Reporting, Up: GDB Bugs - -Have you found a bug? -===================== - - If you are not sure whether you have found a bug, here are some -guidelines: - - * If the debugger gets a fatal signal, for any input whatever, that - is a GDB bug. Reliable debuggers never crash. - - * If GDB produces an error message for valid input, that is a bug. - - * If GDB does not produce an error message for invalid input, that - is a bug. However, you should note that your idea of "invalid - input" might be our idea of "an extension" or "support for - traditional practice". - - * If you are an experienced user of debugging tools, your suggestions - for improvement of GDB are welcome in any case. - diff --git a/gnu/usr.bin/gdb/doc/gdb.info-7 b/gnu/usr.bin/gdb/doc/gdb.info-7 deleted file mode 100644 index 963527e..0000000 --- a/gnu/usr.bin/gdb/doc/gdb.info-7 +++ /dev/null @@ -1,1233 +0,0 @@ -This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input -file gdb.texinfo. - -START-INFO-DIR-ENTRY -* Gdb:: The GNU debugger. -END-INFO-DIR-ENTRY - This file documents the GNU debugger GDB. - - This is Edition 4.09, August 1993, of `Debugging with GDB: the GNU -Source-Level Debugger' for GDB Version 4.11. - - Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software -Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the entire resulting derived work is distributed under the terms -of a permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions. - - -File: gdb.info, Node: Bug Reporting, Prev: Bug Criteria, Up: GDB Bugs - -How to report bugs -================== - - A number of companies and individuals offer support for GNU products. -If you obtained GDB from a support organization, we recommend you -contact that organization first. - - You can find contact information for many support companies and -individuals in the file `etc/SERVICE' in the GNU Emacs distribution. - - In any event, we also recommend that you send bug reports for GDB to -one of these addresses: - - bug-gdb@prep.ai.mit.edu - {ucbvax|mit-eddie|uunet}!prep.ai.mit.edu!bug-gdb - - *Do not send bug reports to `info-gdb', or to `help-gdb', or to any -newsgroups.* Most users of GDB do not want to receive bug reports. -Those that do, have arranged to receive `bug-gdb'. - - The mailing list `bug-gdb' has a newsgroup `gnu.gdb.bug' which -serves as a repeater. The mailing list and the newsgroup carry exactly -the same messages. Often people think of posting bug reports to the -newsgroup instead of mailing them. This appears to work, but it has one -problem which can be crucial: a newsgroup posting often lacks a mail -path back to the sender. Thus, if we need to ask for more information, -we may be unable to reach you. For this reason, it is better to send -bug reports to the mailing list. - - As a last resort, send bug reports on paper to: - - GNU Debugger Bugs - Free Software Foundation - 545 Tech Square - Cambridge, MA 02139 - - The fundamental principle of reporting bugs usefully is this: -*report all the facts*. If you are not sure whether to state a fact or -leave it out, state it! - - Often people omit facts because they think they know what causes the -problem and assume that some details do not matter. Thus, you might -assume that the name of the variable you use in an example does not -matter. Well, probably it does not, but one cannot be sure. Perhaps -the bug is a stray memory reference which happens to fetch from the -location where that name is stored in memory; perhaps, if the name were -different, the contents of that location would fool the debugger into -doing the right thing despite the bug. Play it safe and give a -specific, complete example. That is the easiest thing for you to do, -and the most helpful. - - Keep in mind that the purpose of a bug report is to enable us to fix -the bug if it is new to us. It is not as important as what happens if -the bug is already known. Therefore, always write your bug reports on -the assumption that the bug has not been reported previously. - - Sometimes people give a few sketchy facts and ask, "Does this ring a -bell?" Those bug reports are useless, and we urge everyone to *refuse -to respond to them* except to chide the sender to report bugs properly. - - To enable us to fix the bug, you should include all these things: - - * The version of GDB. GDB announces it if you start with no - arguments; you can also print it at any time using `show version'. - - Without this, we will not know whether there is any point in - looking for the bug in the current version of GDB. - - * The type of machine you are using, and the operating system name - and version number. - - * What compiler (and its version) was used to compile GDB--e.g. - "gcc-2.0". - - * What compiler (and its version) was used to compile the program you - are debugging--e.g. "gcc-2.0". - - * The command arguments you gave the compiler to compile your - example and observe the bug. For example, did you use `-O'? To - guarantee you will not omit something important, list them all. A - copy of the Makefile (or the output from make) is sufficient. - - If we were to try to guess the arguments, we would probably guess - wrong and then we might not encounter the bug. - - * A complete input script, and all necessary source files, that will - reproduce the bug. - - * A description of what behavior you observe that you believe is - incorrect. For example, "It gets a fatal signal." - - Of course, if the bug is that GDB gets a fatal signal, then we will - certainly notice it. But if the bug is incorrect output, we might - not notice unless it is glaringly wrong. We are human, after all. - You might as well not give us a chance to make a mistake. - - Even if the problem you experience is a fatal signal, you should - still say so explicitly. Suppose something strange is going on, - such as, your copy of GDB is out of synch, or you have encountered - a bug in the C library on your system. (This has happened!) Your - copy might crash and ours would not. If you told us to expect a - crash, then when ours fails to crash, we would know that the bug - was not happening for us. If you had not told us to expect a - crash, then we would not be able to draw any conclusion from our - observations. - - * If you wish to suggest changes to the GDB source, send us context - diffs. If you even discuss something in the GDB source, refer to - it by context, not by line number. - - The line numbers in our development sources will not match those - in your sources. Your line numbers would convey no useful - information to us. - - Here are some things that are not necessary: - - * A description of the envelope of the bug. - - Often people who encounter a bug spend a lot of time investigating - which changes to the input file will make the bug go away and which - changes will not affect it. - - This is often time consuming and not very useful, because the way - we will find the bug is by running a single example under the - debugger with breakpoints, not by pure deduction from a series of - examples. We recommend that you save your time for something else. - - Of course, if you can find a simpler example to report *instead* - of the original one, that is a convenience for us. Errors in the - output will be easier to spot, running under the debugger will take - less time, etc. - - However, simplification is not vital; if you do not want to do - this, report the bug anyway and send us the entire test case you - used. - - * A patch for the bug. - - A patch for the bug does help us if it is a good one. But do not - omit the necessary information, such as the test case, on the - assumption that a patch is all we need. We might see problems - with your patch and decide to fix the problem another way, or we - might not understand it at all. - - Sometimes with a program as complicated as GDB it is very hard to - construct an example that will make the program follow a certain - path through the code. If you do not send us the example, we will - not be able to construct one, so we will not be able to verify - that the bug is fixed. - - And if we cannot understand what bug you are trying to fix, or why - your patch should be an improvement, we will not install it. A - test case will help us to understand. - - * A guess about what the bug is or what it depends on. - - Such guesses are usually wrong. Even we cannot guess right about - such things without first using the debugger to find the facts. - - -File: gdb.info, Node: Command Line Editing, Next: Using History Interactively, Prev: GDB Bugs, Up: Top - -Command Line Editing -******************** - - This text describes GNU's command line editing interface. - -* Menu: - -* Introduction and Notation:: Notation used in this text. -* Readline Interaction:: The minimum set of commands for editing a line. -* Readline Init File:: Customizing Readline from a user's view. - - -File: gdb.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing - -Introduction to Line Editing -============================ - - The following paragraphs describe the notation we use to represent -keystrokes. - - The text C-k is read as `Control-K' and describes the character -produced when the Control key is depressed and the k key is struck. - - The text M-k is read as `Meta-K' and describes the character -produced when the meta key (if you have one) is depressed, and the k -key is struck. If you do not have a meta key, the identical keystroke -can be generated by typing ESC first, and then typing k. Either -process is known as "metafying" the k key. - - The text M-C-k is read as `Meta-Control-k' and describes the -character produced by "metafying" C-k. - - In addition, several keys have their own names. Specifically, DEL, -ESC, LFD, SPC, RET, and TAB all stand for themselves when seen in this -text, or in an init file (*note Readline Init File::., for more info). - - -File: gdb.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing - -Readline Interaction -==================== - - Often during an interactive session you type in a long line of text, -only to notice that the first word on the line is misspelled. The -Readline library gives you a set of commands for manipulating the text -as you type it in, allowing you to just fix your typo, and not forcing -you to retype the majority of the line. Using these editing commands, -you move the cursor to the place that needs correction, and delete or -insert the text of the corrections. Then, when you are satisfied with -the line, you simply press RETURN. You do not have to be at the end of -the line to press RETURN; the entire line is accepted regardless of the -location of the cursor within the line. - -* Menu: - -* Readline Bare Essentials:: The least you need to know about Readline. -* Readline Movement Commands:: Moving about the input line. -* Readline Killing Commands:: How to delete text, and how to get it back! -* Readline Arguments:: Giving numeric arguments to commands. - - -File: gdb.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction - -Readline Bare Essentials ------------------------- - - In order to enter characters into the line, simply type them. The -typed character appears where the cursor was, and then the cursor moves -one space to the right. If you mistype a character, you can use DEL to -back up, and delete the mistyped character. - - Sometimes you may miss typing a character that you wanted to type, -and not notice your error until you have typed several other -characters. In that case, you can type C-b to move the cursor to the -left, and then correct your mistake. Aftwerwards, you can move the -cursor to the right with C-f. - - When you add text in the middle of a line, you will notice that -characters to the right of the cursor get `pushed over' to make room -for the text that you have inserted. Likewise, when you delete text -behind the cursor, characters to the right of the cursor get `pulled -back' to fill in the blank space created by the removal of the text. A -list of the basic bare essentials for editing the text of an input line -follows. - -C-b - Move back one character. - -C-f - Move forward one character. - -DEL - Delete the character to the left of the cursor. - -C-d - Delete the character underneath the cursor. - -Printing characters - Insert itself into the line at the cursor. - -C-_ - Undo the last thing that you did. You can undo all the way back - to an empty line. - - -File: gdb.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction - -Readline Movement Commands --------------------------- - - The above table describes the most basic possible keystrokes that -you need in order to do editing of the input line. For your -convenience, many other commands have been added in addition to C-b, -C-f, C-d, and DEL. Here are some commands for moving more rapidly -about the line. - -C-a - Move to the start of the line. - -C-e - Move to the end of the line. - -M-f - Move forward a word. - -M-b - Move backward a word. - -C-l - Clear the screen, reprinting the current line at the top. - - Notice how C-f moves forward a character, while M-f moves forward a -word. It is a loose convention that control keystrokes operate on -characters while meta keystrokes operate on words. - - -File: gdb.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction - -Readline Killing Commands -------------------------- - - "Killing" text means to delete the text from the line, but to save -it away for later use, usually by "yanking" it back into the line. If -the description for a command says that it `kills' text, then you can -be sure that you can get the text back in a different (or the same) -place later. - - Here is the list of commands for killing text. - -C-k - Kill the text from the current cursor position to the end of the - line. - -M-d - Kill from the cursor to the end of the current word, or if between - words, to the end of the next word. - -M-DEL - Kill from the cursor to the start of the previous word, or if - between words, to the start of the previous word. - -C-w - Kill from the cursor to the previous whitespace. This is - different than M-DEL because the word boundaries differ. - - And, here is how to "yank" the text back into the line. Yanking is - -C-y - Yank the most recently killed text back into the buffer at the - cursor. - -M-y - Rotate the kill-ring, and yank the new top. You can only do this - if the prior command is C-y or M-y. - - When you use a kill command, the text is saved in a "kill-ring". -Any number of consecutive kills save all of the killed text together, so -that when you yank it back, you get it in one clean sweep. The kill -ring is not line specific; the text that you killed on a previously -typed line is available to be yanked back later, when you are typing -another line. - - -File: gdb.info, Node: Readline Arguments, Prev: Readline Killing Commands, Up: Readline Interaction - -Readline Arguments ------------------- - - You can pass numeric arguments to Readline commands. Sometimes the -argument acts as a repeat count, other times it is the sign of the -argument that is significant. If you pass a negative argument to a -command which normally acts in a forward direction, that command will -act in a backward direction. For example, to kill text back to the -start of the line, you might type M- C-k. - - The general way to pass numeric arguments to a command is to type -meta digits before the command. If the first `digit' you type is a -minus sign (-), then the sign of the argument will be negative. Once -you have typed one meta digit to get the argument started, you can type -the remainder of the digits, and then the command. For example, to give -the C-d command an argument of 10, you could type M-1 0 C-d. - - -File: gdb.info, Node: Readline Init File, Prev: Readline Interaction, Up: Command Line Editing - -Readline Init File -================== - - Although the Readline library comes with a set of Emacs-like -keybindings, it is possible that you would like to use a different set -of keybindings. You can customize programs that use Readline by putting -commands in an "init" file in your home directory. The name of this -file is `~/.inputrc'. - - When a program which uses the Readline library starts up, the -`~/.inputrc' file is read, and the keybindings are set. - - In addition, the C-x C-r command re-reads this init file, thus -incorporating any changes that you might have made to it. - -* Menu: - -* Readline Init Syntax:: Syntax for the commands in `~/.inputrc'. -* Readline Vi Mode:: Switching to `vi' mode in Readline. - - -File: gdb.info, Node: Readline Init Syntax, Next: Readline Vi Mode, Up: Readline Init File - -Readline Init Syntax --------------------- - - There are only four constructs allowed in the `~/.inputrc' file: - -Variable Settings - You can change the state of a few variables in Readline. You do - this by using the `set' command within the init file. Here is how - you would specify that you wish to use Vi line editing commands: - - set editing-mode vi - - Right now, there are only a few variables which can be set; so few - in fact, that we just iterate them here: - - `editing-mode' - The `editing-mode' variable controls which editing mode you - are using. By default, GNU Readline starts up in Emacs - editing mode, where the keystrokes are most similar to Emacs. - This variable can either be set to `emacs' or `vi'. - - `horizontal-scroll-mode' - This variable can either be set to `On' or `Off'. Setting it - to `On' means that the text of the lines that you edit will - scroll horizontally on a single screen line when they are - larger than the width of the screen, instead of wrapping onto - a new screen line. By default, this variable is set to `Off'. - - `mark-modified-lines' - This variable when set to `On', says to display an asterisk - (`*') at the starts of history lines which have been modified. - This variable is off by default. - - `prefer-visible-bell' - If this variable is set to `On' it means to use a visible - bell if one is available, rather than simply ringing the - terminal bell. By default, the value is `Off'. - -Key Bindings - The syntax for controlling keybindings in the `~/.inputrc' file is - simple. First you have to know the name of the command that you - want to change. The following pages contain tables of the command - name, the default keybinding, and a short description of what the - command does. - - Once you know the name of the command, simply place the name of - the key you wish to bind the command to, a colon, and then the - name of the command on a line in the `~/.inputrc' file. The name - of the key can be expressed in different ways, depending on which - is most comfortable for you. - - KEYNAME: FUNCTION-NAME or MACRO - KEYNAME is the name of a key spelled out in English. For - example: - Control-u: universal-argument - Meta-Rubout: backward-kill-word - Control-o: ">&output" - - In the above example, C-u is bound to the function - `universal-argument', and C-o is bound to run the macro - expressed on the right hand side (that is, to insert the text - `>&output' into the line). - - "KEYSEQ": FUNCTION-NAME or MACRO - KEYSEQ differs from KEYNAME above in that strings denoting an - entire key sequence can be specified. Simply place the key - sequence in double quotes. GNU Emacs style key escapes can - be used, as in the following example: - - "\C-u": universal-argument - "\C-x\C-r": re-read-init-file - "\e[11~": "Function Key 1" - - In the above example, C-u is bound to the function - `universal-argument' (just as it was in the first example), - C-x C-r is bound to the function `re-read-init-file', and ESC - [ 1 1 ~ is bound to insert the text `Function Key 1'. - -* Menu: - -* Commands For Moving:: Moving about the line. -* Commands For History:: Getting at previous lines. -* Commands For Text:: Commands for changing text. -* Commands For Killing:: Commands for killing and yanking. -* Numeric Arguments:: Specifying numeric arguments, repeat counts. -* Commands For Completion:: Getting Readline to do the typing for you. -* Miscellaneous Commands:: Other miscillaneous commands. - - -File: gdb.info, Node: Commands For Moving, Next: Commands For History, Up: Readline Init Syntax - -Commands For Moving -------------------- - -`beginning-of-line (C-a)' - Move to the start of the current line. - -`end-of-line (C-e)' - Move to the end of the line. - -`forward-char (C-f)' - Move forward a character. - -`backward-char (C-b)' - Move back a character. - -`forward-word (M-f)' - Move forward to the end of the next word. - -`backward-word (M-b)' - Move back to the start of this, or the previous, word. - -`clear-screen (C-l)' - Clear the screen leaving the current line at the top of the screen. - - -File: gdb.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Readline Init Syntax - -Commands For Manipulating The History -------------------------------------- - -`accept-line (Newline, Return)' - Accept the line regardless of where the cursor is. If this line is - non-empty, add it to the history list. If this line was a history - line, then restore the history line to its original state. - -`previous-history (C-p)' - Move `up' through the history list. - -`next-history (C-n)' - Move `down' through the history list. - -`beginning-of-history (M-<)' - Move to the first line in the history. - -`end-of-history (M->)' - Move to the end of the input history, i.e., the line you are - entering! - -`reverse-search-history (C-r)' - Search backward starting at the current line and moving `up' - through the history as necessary. This is an incremental search. - -`forward-search-history (C-s)' - Search forward starting at the current line and moving `down' - through the the history as neccessary. - - -File: gdb.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Readline Init Syntax - -Commands For Changing Text --------------------------- - -`delete-char (C-d)' - Delete the character under the cursor. If the cursor is at the - beginning of the line, and there are no characters in the line, and - the last character typed was not C-d, then return EOF. - -`backward-delete-char (Rubout)' - Delete the character behind the cursor. A numeric arg says to kill - the characters instead of deleting them. - -`quoted-insert (C-q, C-v)' - Add the next character that you type to the line verbatim. This is - how to insert things like C-q for example. - -`tab-insert (M-TAB)' - Insert a tab character. - -`self-insert (a, b, A, 1, !, ...)' - Insert yourself. - -`transpose-chars (C-t)' - Drag the character before point forward over the character at - point. Point moves forward as well. If point is at the end of - the line, then transpose the two characters before point. - Negative args don't work. - -`transpose-words (M-t)' - Drag the word behind the cursor past the word in front of the - cursor moving the cursor over that word as well. - -`upcase-word (M-u)' - Uppercase all letters in the current (or following) word. With a - negative argument, do the previous word, but do not move point. - -`downcase-word (M-l)' - Lowercase all letters in the current (or following) word. With a - negative argument, do the previous word, but do not move point. - -`capitalize-word (M-c)' - Uppercase the first letter in the current (or following) word. - With a negative argument, do the previous word, but do not move - point. - - -File: gdb.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Readline Init Syntax - -Killing And Yanking -------------------- - -`kill-line (C-k)' - Kill the text from the current cursor position to the end of the - line. - -`backward-kill-line ()' - Kill backward to the beginning of the line. This is normally - unbound. - -`kill-word (M-d)' - Kill from the cursor to the end of the current word, or if between - words, to the end of the next word. - -`backward-kill-word (M-DEL)' - Kill the word behind the cursor. - -`unix-line-discard (C-u)' - Do what C-u used to do in Unix line input. We save the killed - text on the kill-ring, though. - -`unix-word-rubout (C-w)' - Do what C-w used to do in Unix line input. The killed text is - saved on the kill-ring. This is different than backward-kill-word - because the word boundaries differ. - -`yank (C-y)' - Yank the top of the kill ring into the buffer at point. - -`yank-pop (M-y)' - Rotate the kill-ring, and yank the new top. You can only do this - if the prior command is yank or yank-pop. - - -File: gdb.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Readline Init Syntax - -Specifying Numeric Arguments ----------------------------- - -`digit-argument (M-0, M-1, ... M--)' - Add this digit to the argument already accumulating, or start a new - argument. M- starts a negative argument. - -`universal-argument ()' - Do what C-u does in emacs. By default, this is not bound. - - -File: gdb.info, Node: Commands For Completion, Next: Miscellaneous Commands, Prev: Numeric Arguments, Up: Readline Init Syntax - -Letting Readline Type For You ------------------------------ - -`complete (TAB)' - Attempt to do completion on the text before point. This is - implementation defined. Generally, if you are typing a filename - argument, you can do filename completion; if you are typing a - command, you can do command completion, if you are typing in a - symbol to GDB, you can do symbol name completion, if you are - typing in a variable to Bash, you can do variable name - completion... - -`possible-completions (M-?)' - List the possible completions of the text before point. - - -File: gdb.info, Node: Miscellaneous Commands, Prev: Commands For Completion, Up: Readline Init Syntax - -Some Miscellaneous Commands ---------------------------- - -`re-read-init-file (C-x C-r)' - Read in the contents of your `~/.inputrc' file, and incorporate - any bindings found there. - -`abort (C-g)' - Stop running the current editing command. - -`prefix-meta (ESC)' - Make the next character that you type be metafied. This is for - people without a meta key. Typing ESC f is equivalent to typing - M-f. - -`undo (C-_)' - Incremental undo, separately remembered for each line. - -`revert-line (M-r)' - Undo all changes made to this line. This is like typing the `undo' - command enough times to get back to the beginning. - - -File: gdb.info, Node: Readline Vi Mode, Prev: Readline Init Syntax, Up: Readline Init File - -Readline Vi Mode ----------------- - - While the Readline library does not have a full set of Vi editing -functions, it does contain enough to allow simple editing of the line. - - In order to switch interactively between Emacs and Vi editing modes, -use the command M-C-j (toggle-editing-mode). - - When you enter a line in Vi mode, you are already placed in -`insertion' mode, as if you had typed an `i'. Pressing ESC switches -you into `edit' mode, where you can edit the text of the line with the -standard Vi movement keys, move to previous history lines with `k', and -following lines with `j', and so forth. - - -File: gdb.info, Node: Using History Interactively, Next: Renamed Commands, Prev: Command Line Editing, Up: Top - -Using History Interactively -*************************** - - This chapter describes how to use the GNU History Library -interactively, from a user's standpoint. - -* Menu: - -* History Interaction:: What it feels like using History as a user. - - -File: gdb.info, Node: History Interaction, Up: Using History Interactively - -History Interaction -=================== - - The History library provides a history expansion feature that is -similar to the history expansion in Csh. The following text describes -the sytax that you use to manipulate the history information. - - History expansion takes place in two parts. The first is to -determine which line from the previous history should be used during -substitution. The second is to select portions of that line for -inclusion into the current one. The line selected from the previous -history is called the "event", and the portions of that line that are -acted upon are called "words". The line is broken into words in the -same fashion that the Bash shell does, so that several English (or -Unix) words surrounded by quotes are considered as one word. - -* Menu: - -* Event Designators:: How to specify which history line to use. -* Word Designators:: Specifying which words are of interest. -* Modifiers:: Modifying the results of susbstitution. - - -File: gdb.info, Node: Event Designators, Next: Word Designators, Up: History Interaction - -Event Designators ------------------ - - An event designator is a reference to a command line entry in the -history list. - -`!' - Start a history subsititution, except when followed by a space, - tab, or the end of the line... = or (. - -`!!' - Refer to the previous command. This is a synonym for `!-1'. - -`!n' - Refer to command line N. - -`!-n' - Refer to the command line N lines back. - -`!string' - Refer to the most recent command starting with STRING. - -`!?string'[`?'] - Refer to the most recent command containing STRING. - - -File: gdb.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction - -Word Designators ----------------- - - A : separates the event specification from the word designator. It -can be omitted if the word designator begins with a ^, $, * or %. -Words are numbered from the beginning of the line, with the first word -being denoted by a 0 (zero). - -`0 (zero)' - The zero'th word. For many applications, this is the command word. - -`n' - The N'th word. - -`^' - The first argument. that is, word 1. - -`$' - The last argument. - -`%' - The word matched by the most recent `?string?' search. - -`x-y' - A range of words; `-Y' Abbreviates `0-Y'. - -`*' - All of the words, excepting the zero'th. This is a synonym for - `1-$'. It is not an error to use * if there is just one word in - the event. The empty string is returned in that case. - - -File: gdb.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction - -Modifiers ---------- - - After the optional word designator, you can add a sequence of one or -more of the following modifiers, each preceded by a :. - -`#' - The entire command line typed so far. This means the current - command, not the previous command, so it really isn't a word - designator, and doesn't belong in this section. - -`h' - Remove a trailing pathname component, leaving only the head. - -`r' - Remove a trailing suffix of the form `.'SUFFIX, leaving the - basename. - -`e' - Remove all but the suffix. - -`t' - Remove all leading pathname components, leaving the tail. - -`p' - Print the new command but do not execute it. - - -File: gdb.info, Node: Renamed Commands, Next: Formatting Documentation, Prev: Using History Interactively, Up: Top - -Renamed Commands -**************** - - The following commands were renamed in GDB 4, in order to make the -command set as a whole more consistent and easier to use and remember: - - OLD COMMAND NEW COMMAND - --------------- ------------------------------- - add-syms add-symbol-file - delete environment unset environment - info convenience show convenience - info copying show copying - info directories show directories - info editing show commands - info history show values - info targets help target - info values show values - info version show version - info warranty show warranty - set/show addressprint set/show print address - set/show array-max set/show print elements - set/show arrayprint set/show print array - set/show asm-demangle set/show print asm-demangle - set/show caution set/show confirm - set/show demangle set/show print demangle - set/show history write set/show history save - set/show prettyprint set/show print pretty - set/show screen-height set/show height - set/show screen-width set/show width - set/show sevenbit-strings set/show print sevenbit-strings - set/show unionprint set/show print union - set/show vtblprint set/show print vtbl - - unset [No longer an alias for delete] - - -File: gdb.info, Node: Formatting Documentation, Next: Installing GDB, Prev: Renamed Commands, Up: Top - -Formatting Documentation -************************ - - The GDB 4 release includes an already-formatted reference card, ready -for printing with PostScript or GhostScript, in the `gdb' subdirectory -of the main source directory(1). If you can use PostScript or -GhostScript with your printer, you can print the reference card -immediately with `refcard.ps'. - - The release also includes the source for the reference card. You -can format it, using TeX, by typing: - - make refcard.dvi - - The GDB reference card is designed to print in landscape mode on US -"letter" size paper; that is, on a sheet 11 inches wide by 8.5 inches -high. You will need to specify this form of printing as an option to -your DVI output program. - - All the documentation for GDB comes as part of the machine-readable -distribution. The documentation is written in Texinfo format, which is -a documentation system that uses a single source file to produce both -on-line information and a printed manual. You can use one of the Info -formatting commands to create the on-line version of the documentation -and TeX (or `texi2roff') to typeset the printed version. - - GDB includes an already formatted copy of the on-line Info version of -this manual in the `gdb' subdirectory. The main Info file is -`gdb-VERSION-NUMBER/gdb/gdb.info', and it refers to subordinate files -matching `gdb.info*' in the same directory. If necessary, you can -print out these files, or read them with any editor; but they are -easier to read using the `info' subsystem in GNU Emacs or the -standalone `info' program, available as part of the GNU Texinfo -distribution. - - If you want to format these Info files yourself, you need one of the -Info formatting programs, such as `texinfo-format-buffer' or `makeinfo'. - - If you have `makeinfo' installed, and are in the top level GDB -source directory (`gdb-4.11', in the case of version 4.11), you can -make the Info file by typing: - - cd gdb - make gdb.info - - If you want to typeset and print copies of this manual, you need TeX, -a program to print its DVI output files, and `texinfo.tex', the Texinfo -definitions file. - - TeX is a typesetting program; it does not print files directly, but -produces output files called DVI files. To print a typeset document, -you need a program to print DVI files. If your system has TeX -installed, chances are it has such a program. The precise command to -use depends on your system; `lpr -d' is common; another (for PostScript -devices) is `dvips'. The DVI print command may require a file name -without any extension or a `.dvi' extension. - - TeX also requires a macro definitions file called `texinfo.tex'. -This file tells TeX how to typeset a document written in Texinfo -format. On its own, TeX cannot read, much less typeset a Texinfo file. -`texinfo.tex' is distributed with GDB and is located in the -`gdb-VERSION-NUMBER/texinfo' directory. - - If you have TeX and a DVI printer program installed, you can typeset -and print this manual. First switch to the the `gdb' subdirectory of -the main source directory (for example, to `gdb-4.11/gdb') and then -type: - - make gdb.dvi - - ---------- Footnotes ---------- - - (1) In `gdb-4.11/gdb/refcard.ps' of the version 4.11 release. - - -File: gdb.info, Node: Installing GDB, Next: Index, Prev: Formatting Documentation, Up: Top - -Installing GDB -************** - - GDB comes with a `configure' script that automates the process of -preparing GDB for installation; you can then use `make' to build the -`gdb' program. - - The GDB distribution includes all the source code you need for GDB in -a single directory, whose name is usually composed by appending the -version number to `gdb'. - - For example, the GDB version 4.11 distribution is in the `gdb-4.11' -directory. That directory contains: - -`gdb-4.11/configure (and supporting files)' - script for configuring GDB and all its supporting libraries. - -`gdb-4.11/gdb' - the source specific to GDB itself - -`gdb-4.11/bfd' - source for the Binary File Descriptor library - -`gdb-4.11/include' - GNU include files - -`gdb-4.11/libiberty' - source for the `-liberty' free software library - -`gdb-4.11/opcodes' - source for the library of opcode tables and disassemblers - -`gdb-4.11/readline' - source for the GNU command-line interface - -`gdb-4.11/glob' - source for the GNU filename pattern-matching subroutine - -`gdb-4.11/mmalloc' - source for the GNU memory-mapped malloc package - - The simplest way to configure and build GDB is to run `configure' -from the `gdb-VERSION-NUMBER' source directory, which in this example -is the `gdb-4.11' directory. - - First switch to the `gdb-VERSION-NUMBER' source directory if you are -not already in it; then run `configure'. Pass the identifier for the -platform on which GDB will run as an argument. - - For example: - - cd gdb-4.11 - ./configure HOST - make - -where HOST is an identifier such as `sun4' or `decstation', that -identifies the platform where GDB will run. (You can often leave off -HOST; `configure' tries to guess the correct value by examining your -system.) - - Running `configure HOST' and then running `make' builds the `bfd', -`readline', `mmalloc', and `libiberty' libraries, then `gdb' itself. -The configured source files, and the binaries, are left in the -corresponding source directories. - - `configure' is a Bourne-shell (`/bin/sh') script; if your system -does not recognize this automatically when you run a different shell, -you may need to run `sh' on it explicitly: - - sh configure HOST - - If you run `configure' from a directory that contains source -directories for multiple libraries or programs, such as the `gdb-4.11' -source directory for version 4.11, `configure' creates configuration -files for every directory level underneath (unless you tell it not to, -with the `--norecursion' option). - - You can run the `configure' script from any of the subordinate -directories in the GDB distribution if you only want to configure that -subdirectory, but be sure to specify a path to it. - - For example, with version 4.11, type the following to configure only -the `bfd' subdirectory: - - cd gdb-4.11/bfd - ../configure HOST - - You can install `gdb' anywhere; it has no hardwired paths. However, -you should make sure that the shell on your path (named by the `SHELL' -environment variable) is publicly readable. Remember that GDB uses the -shell to start your program--some systems refuse to let GDB debug child -processes whose programs are not readable. - -* Menu: - -* Separate Objdir:: Compiling GDB in another directory -* Config Names:: Specifying names for hosts and targets -* configure Options:: Summary of options for configure - - -File: gdb.info, Node: Separate Objdir, Next: Config Names, Up: Installing GDB - -Compiling GDB in another directory -================================== - - If you want to run GDB versions for several host or target machines, -you need a different `gdb' compiled for each combination of host and -target. `configure' is designed to make this easy by allowing you to -generate each configuration in a separate subdirectory, rather than in -the source directory. If your `make' program handles the `VPATH' -feature (GNU `make' does), running `make' in each of these directories -builds the `gdb' program specified there. - - To build `gdb' in a separate directory, run `configure' with the -`--srcdir' option to specify where to find the source. (You also need -to specify a path to find `configure' itself from your working -directory. If the path to `configure' would be the same as the -argument to `--srcdir', you can leave out the `--srcdir' option; it -will be assumed.) - - For example, with version 4.11, you can build GDB in a separate -directory for a Sun 4 like this: - - cd gdb-4.11 - mkdir ../gdb-sun4 - cd ../gdb-sun4 - ../gdb-4.11/configure sun4 - make - - When `configure' builds a configuration using a remote source -directory, it creates a tree for the binaries with the same structure -(and using the same names) as the tree under the source directory. In -the example, you'd find the Sun 4 library `libiberty.a' in the -directory `gdb-sun4/libiberty', and GDB itself in `gdb-sun4/gdb'. - - One popular reason to build several GDB configurations in separate -directories is to configure GDB for cross-compiling (where GDB runs on -one machine--the host--while debugging programs that run on another -machine--the target). You specify a cross-debugging target by giving -the `--target=TARGET' option to `configure'. - - When you run `make' to build a program or library, you must run it -in a configured directory--whatever directory you were in when you -called `configure' (or one of its subdirectories). - - The `Makefile' that `configure' generates in each source directory -also runs recursively. If you type `make' in a source directory such -as `gdb-4.11' (or in a separate configured directory configured with -`--srcdir=PATH/gdb-4.11'), you will build all the required libraries, -and then build GDB. - - When you have multiple hosts or targets configured in separate -directories, you can run `make' on them in parallel (for example, if -they are NFS-mounted on each of the hosts); they will not interfere -with each other. - - -File: gdb.info, Node: Config Names, Next: configure Options, Prev: Separate Objdir, Up: Installing GDB - -Specifying names for hosts and targets -====================================== - - The specifications used for hosts and targets in the `configure' -script are based on a three-part naming scheme, but some short -predefined aliases are also supported. The full naming scheme encodes -three pieces of information in the following pattern: - - ARCHITECTURE-VENDOR-OS - - For example, you can use the alias `sun4' as a HOST argument, or as -the value for TARGET in a `--target=TARGET' option. The equivalent -full name is `sparc-sun-sunos4'. - - The `configure' script accompanying GDB does not provide any query -facility to list all supported host and target names or aliases. -`configure' calls the Bourne shell script `config.sub' to map -abbreviations to full names; you can read the script, if you wish, or -you can use it to test your guesses on abbreviations--for example: - - % sh config.sub sun4 - sparc-sun-sunos4.1.1 - % sh config.sub sun3 - m68k-sun-sunos4.1.1 - % sh config.sub decstation - mips-dec-ultrix4.2 - % sh config.sub hp300bsd - m68k-hp-bsd - % sh config.sub i386v - i386-unknown-sysv - % sh config.sub i786v - Invalid configuration `i786v': machine `i786v' not recognized - -`config.sub' is also distributed in the GDB source directory -(`gdb-4.11', for version 4.11). - - -File: gdb.info, Node: configure Options, Prev: Config Names, Up: Installing GDB - -`configure' options -=================== - - Here is a summary of the `configure' options and arguments that are -most often useful for building GDB. `configure' also has several other -options not listed here. *note : (configure.info)What Configure Does, -for a full explanation of `configure'. - - configure [--help] - [--prefix=DIR] - [--srcdir=PATH] - [--norecursion] [--rm] - [--target=TARGET] HOST - -You may introduce options with a single `-' rather than `--' if you -prefer; but you may abbreviate option names if you use `--'. - -`--help' - Display a quick summary of how to invoke `configure'. - -`-prefix=DIR' - Configure the source to install programs and files under directory - `DIR'. - -`--srcdir=PATH' - *Warning: using this option requires GNU `make', or another `make' - that implements the `VPATH' feature.* - Use this option to make configurations in directories separate - from the GDB source directories. Among other things, you can use - this to build (or maintain) several configurations simultaneously, - in separate directories. `configure' writes configuration - specific files in the current directory, but arranges for them to - use the source in the directory PATH. `configure' will create - directories under the working directory in parallel to the source - directories below PATH. - -`--norecursion' - Configure only the directory level where `configure' is executed; - do not propagate configuration to subdirectories. - -`--rm' - *Remove* files otherwise built during configuration. - -`--target=TARGET' - Configure GDB for cross-debugging programs running on the specified - TARGET. Without this option, GDB is configured to debug programs - that run on the same machine (HOST) as GDB itself. - - There is no convenient way to generate a list of all available - targets. - -`HOST ...' - Configure GDB to run on the specified HOST. - - There is no convenient way to generate a list of all available - hosts. - -`configure' accepts other options, for compatibility with configuring -other GNU tools recursively; but these are the only options that affect -GDB or its supporting libraries. - diff --git a/gnu/usr.bin/gdb/doc/gdb.info-8 b/gnu/usr.bin/gdb/doc/gdb.info-8 deleted file mode 100644 index 1d259e0..0000000 --- a/gnu/usr.bin/gdb/doc/gdb.info-8 +++ /dev/null @@ -1,657 +0,0 @@ -This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input -file gdb.texinfo. - -START-INFO-DIR-ENTRY -* Gdb:: The GNU debugger. -END-INFO-DIR-ENTRY - This file documents the GNU debugger GDB. - - This is Edition 4.09, August 1993, of `Debugging with GDB: the GNU -Source-Level Debugger' for GDB Version 4.11. - - Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software -Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the entire resulting derived work is distributed under the terms -of a permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions. - - -File: gdb.info, Node: Index, Prev: Installing GDB, Up: Top - -Index -***** - -* Menu: - -* #: Command Syntax. -* $bpnum: Set Breaks. -* $cdir: Source Path. -* $cwd: Source Path. -* $_: Convenience Vars. -* $__: Convenience Vars. -* .: M2 Scope. -* .esgdbinit: Command Files. -* .os68gdbinit: Command Files. -* .vxgdbinit: Command Files. -* /proc: Process Information. -* 386: Remote Serial. -* 680x0: Remote Serial. -* @: Arrays. -* # in Modula-2: GDB/M2. -* $$: Value History. -* $_ and info breakpoints: Set Breaks. -* $_ and info line: Machine Code. -* $_, $__, and value history: Memory. -* $: Value History. -* breakpoint subroutine, remote: Stub Contents. -* heuristic-fence-post (MIPS): MIPS Stack. -* remotedebug, MIPS protocol: MIPS Remote. -* retransmit-timeout, MIPS protocol: MIPS Remote. -* timeout, MIPS protocol: MIPS Remote. -* vi style command editing: Readline Vi Mode. -* .gdbinit: Command Files. -* COFF versus C++: Cplus expressions. -* ECOFF and C++: Cplus expressions. -* ELF/DWARF and C++: Cplus expressions. -* ELF/stabs and C++: Cplus expressions. -* XCOFF and C++: Cplus expressions. -* GDB bugs, reporting: Bug Reporting. -* {TYPE}: Expressions. -* a.out and C++: Cplus expressions. -* abbreviation: Command Syntax. -* active targets: Active Targets. -* add-symbol-file: Files. -* add-syms: Renamed Commands. -* AMD 29K register stack: Registers. -* AMD EB29K: Target Commands. -* AMD29K via UDI: UDI29K Remote. -* arguments (to your program): Arguments. -* artificial array: Arrays. -* assembly instructions: Machine Code. -* assignment: Assignment. -* attach: Attach. -* attach: Attach. -* automatic display: Auto Display. -* b: Set Breaks. -* backtrace: Backtrace. -* break: Set Breaks. -* break in overloaded functions: Debugging C plus plus. -* breakpoint commands: Break Commands. -* breakpoint conditions: Conditions. -* breakpoint numbers: Breakpoints. -* breakpoint on memory address: Breakpoints. -* breakpoint on variable modification: Breakpoints. -* breakpoints: Breakpoints. -* bt: Backtrace. -* bug criteria: Bug Criteria. -* bug reports: Bug Reporting. -* bugs in GDB: GDB Bugs. -* c: Continuing and Stepping. -* C and C++: C. -* C and C++ checks: C Checks. -* C and C++ constants: C Operators. -* C and C++ defaults: C Defaults. -* C and C++ operators: C. -* C++: C. -* C++ and object formats: Cplus expressions. -* C++ exception handling: Debugging C plus plus. -* C++ scope resolution: Variables. -* C++ support, not in COFF: Cplus expressions. -* C++ symbol decoding style: Print Settings. -* C++ symbol display: Debugging C plus plus. -* call: Calling. -* call overloaded functions: Cplus expressions. -* call stack: Stack. -* calling functions: Calling. -* calling make: Shell Commands. -* casts, to view memory: Expressions. -* catch: Exception Handling. -* catch exceptions: Frame Info. -* cd: Working Directory. -* cdir: Source Path. -* checks, range: Type Checking. -* checks, type: Checks. -* checksum, for GDB remote: Protocol. -* clear: Delete Breaks. -* clearing breakpoints, watchpoints: Delete Breaks. -* colon, doubled as scope operator: M2 Scope. -* colon-colon: M2 Scope. -* colon-colon: Variables. -* command files: Hooks. -* command files: Command Files. -* command line editing: Editing. -* commands: Break Commands. -* commands for C++: Debugging C plus plus. -* commands to STDBUG (ST2000): ST2000 Remote. -* comment: Command Syntax. -* compilation directory: Source Path. -* completion: Completion. -* completion of quoted strings: Completion. -* condition: Conditions. -* conditional breakpoints: Conditions. -* configuring GDB: Installing GDB. -* confirmation: Messages/Warnings. -* connect (to STDBUG): ST2000 Remote. -* continue: Continuing and Stepping. -* continuing: Continuing and Stepping. -* controlling terminal: Input/Output. -* convenience variables: Convenience Vars. -* core: Files. -* core dump file: Files. -* core-file: Files. -* CPU simulator: Simulator. -* crash of debugger: Bug Criteria. -* current directory: Source Path. -* cwd: Source Path. -* d: Delete Breaks. -* debugger crash: Bug Criteria. -* debugging optimized code: Compilation. -* debugging stub, example: Protocol. -* debugging target: Targets. -* define: Define. -* delete: Delete Breaks. -* delete breakpoints: Delete Breaks. -* delete display: Auto Display. -* delete environment: Renamed Commands. -* deleting breakpoints, watchpoints: Delete Breaks. -* detach: Attach. -* device: Hitachi Remote. -* directories for source files: Source Path. -* directory: Source Path. -* directory, compilation: Source Path. -* directory, current: Source Path. -* dis: Disabling. -* disable: Disabling. -* disable breakpoints: Disabling. -* disable display: Auto Display. -* disabled breakpoints: Disabling. -* disassemble: Machine Code. -* display: Auto Display. -* display of expressions: Auto Display. -* do: Selection. -* document: Define. -* documentation: Formatting Documentation. -* down: Selection. -* down-silently: Selection. -* download to H8/300 or H8/500: Files. -* download to Hitachi SH: Files. -* download to Nindy-960: Files. -* download to VxWorks: VxWorks Download. -* dynamic linking: Files. -* eb.log: Remote Log. -* EB29K board: EB29K Remote. -* EBMON: Comms (EB29K). -* echo: Output. -* editing: Editing. -* editing-mode: Readline Init Syntax. -* emacs: Emacs. -* enable: Disabling. -* enable breakpoints: Disabling. -* enable display: Auto Display. -* enabled breakpoints: Disabling. -* end: Break Commands. -* entering numbers: Numbers. -* environment (of your program): Environment. -* error on valid input: Bug Criteria. -* event designators: Event Designators. -* examining data: Data. -* examining memory: Memory. -* exception handlers: Exception Handling. -* exception handlers: Frame Info. -* exceptionHandler: Bootstrapping. -* exec-file: Files. -* executable file: Files. -* exiting GDB: Quitting GDB. -* expansion: History Interaction. -* expressions: Expressions. -* expressions in C or C++: C. -* expressions in C++: Cplus expressions. -* expressions in Modula-2: Modula-2. -* f: Selection. -* fatal signal: Bug Criteria. -* fatal signals: Signals. -* fg: Continuing and Stepping. -* file: Files. -* finish: Continuing and Stepping. -* flinching: Messages/Warnings. -* floating point: Floating Point Hardware. -* floating point registers: Registers. -* floating point, MIPS remote: MIPS Remote. -* flush_i_cache: Bootstrapping. -* foo: Symbol Errors. -* format options: Print Settings. -* formatted output: Output Formats. -* Fortran: Summary. -* forward-search: Search. -* frame: Selection. -* frame: Frames. -* frame number: Frames. -* frame pointer: Frames. -* frameless execution: Frames. -* g++: C. -* GDB reference card: Formatting Documentation. -* gdbserver: Server. -* getDebugChar: Bootstrapping. -* GNU C++: C. -* h: Help. -* H8/300 or H8/500 download: Files. -* H8/300 or H8/500 simulator: Simulator. -* handle: Signals. -* handle_exception: Stub Contents. -* handling signals: Signals. -* help: Help. -* help target: Target Commands. -* help user-defined: Define. -* history expansion: History. -* history file: History. -* history number: Value History. -* history save: History. -* history size: History. -* history substitution: History. -* Hitachi SH download: Files. -* Hitachi SH simulator: Simulator. -* horizontal-scroll-mode: Readline Init Syntax. -* i: Help. -* i/o: Input/Output. -* i386-stub.c: Remote Serial. -* i960: i960-Nindy Remote. -* ignore: Conditions. -* ignore count (of breakpoint): Conditions. -* INCLUDE_RDB: VxWorks Remote. -* info: Help. -* info address: Symbols. -* info all-registers: Registers. -* info args: Frame Info. -* info breakpoints: Set Breaks. -* info catch: Frame Info. -* info convenience: Renamed Commands. -* info copying: Renamed Commands. -* info directories: Renamed Commands. -* info display: Auto Display. -* info editing: Renamed Commands. -* info f: Frame Info. -* info files: Files. -* info float: Floating Point Hardware. -* info frame: Frame Info. -* info frame: Show. -* info functions: Symbols. -* info history: Renamed Commands. -* info line: Machine Code. -* info locals: Frame Info. -* info proc: Process Information. -* info proc id: Process Information. -* info proc mappings: Process Information. -* info proc status: Process Information. -* info proc times: Process Information. -* info program: Stopping. -* info registers: Registers. -* info s: Backtrace. -* info set: Help. -* info share: Files. -* info sharedlibrary: Files. -* info signals: Signals. -* info source: Symbols. -* info source: Show. -* info sources: Symbols. -* info stack: Backtrace. -* info target: Files. -* info targets: Renamed Commands. -* info terminal: Input/Output. -* info types: Symbols. -* info values: Renamed Commands. -* info variables: Symbols. -* info version: Renamed Commands. -* info warranty: Renamed Commands. -* info watchpoints: Set Watchpoints. -* inheritance: Debugging C plus plus. -* init file: Command Files. -* init file name: Command Files. -* initial frame: Frames. -* innermost frame: Frames. -* inspect: Data. -* installation: Installing GDB. -* instructions, assembly: Machine Code. -* Intel: Remote Serial. -* interaction, readline: Readline Interaction. -* internal GDB breakpoints: Set Breaks. -* interrupt: Quitting GDB. -* interrupting remote programs: Debug Session. -* invalid input: Bug Criteria. -* jump: Jumping. -* kill: Kill Process. -* l: List. -* languages: Languages. -* latest breakpoint: Set Breaks. -* leaving GDB: Quitting GDB. -* linespec: List. -* list: List. -* listing machine instructions: Machine Code. -* load: Files. -* log file for EB29K: Remote Log. -* m68k-stub.c: Remote Serial. -* machine instructions: Machine Code. -* maint info breakpoints: Set Breaks. -* maint print psymbols: Symbols. -* maint print symbols: Symbols. -* make: Shell Commands. -* mapped: Files. -* mark-modified-lines: Readline Init Syntax. -* member functions: Cplus expressions. -* memory tracing: Breakpoints. -* memory, viewing as typed object: Expressions. -* memory-mapped symbol file: Files. -* memset: Bootstrapping. -* MIPS boards: MIPS Remote. -* MIPS remote floating point: MIPS Remote. -* MIPS stack: MIPS Stack. -* Modula-2: Modula-2. -* Modula-2 built-ins: M2 Operators. -* Modula-2 checks: M2 Checks. -* Modula-2 constants: Built-In Func/Proc. -* Modula-2 defaults: M2 Defaults. -* Modula-2 operators: M2 Operators. -* Modula-2, deviations from: Deviations. -* Motorola 680x0: Remote Serial. -* multiple targets: Active Targets. -* n: Continuing and Stepping. -* names of symbols: Symbols. -* namespace in C++: Cplus expressions. -* negative breakpoint numbers: Set Breaks. -* next: Continuing and Stepping. -* nexti: Continuing and Stepping. -* ni: Continuing and Stepping. -* Nindy: i960-Nindy Remote. -* number representation: Numbers. -* numbers for breakpoints: Breakpoints. -* object formats and C++: Cplus expressions. -* online documentation: Help. -* optimized code, debugging: Compilation. -* outermost frame: Frames. -* output: Output. -* output formats: Output Formats. -* overloading: Breakpoint Menus. -* overloading in C++: Debugging C plus plus. -* packets, reporting on stdout: Protocol. -* partial symbol dump: Symbols. -* patching binaries: Patching. -* path: Environment. -* pauses in output: Screen Size. -* pipes: Starting. -* prefer-visible-bell: Readline Init Syntax. -* print: Data. -* print settings: Print Settings. -* printf: Output. -* printing data: Data. -* process image: Process Information. -* prompt: Prompt. -* protocol, GDB remote serial: Protocol. -* ptype: Symbols. -* putDebugChar: Bootstrapping. -* pwd: Working Directory. -* q: Quitting GDB. -* quit: Quitting GDB. -* quotes in commands: Completion. -* quoting names: Symbols. -* raise exceptions: Exception Handling. -* range checking: Type Checking. -* rbreak: Set Breaks. -* reading symbols immediately: Files. -* readline: Editing. -* readnow: Files. -* redirection: Input/Output. -* reference card: Formatting Documentation. -* reference declarations: Cplus expressions. -* register stack, AMD29K: Registers. -* registers: Registers. -* regular expression: Set Breaks. -* reloading symbols: Messages/Warnings. -* remote connection without stubs: Server. -* remote debugging: Remote. -* remote programs, interrupting: Debug Session. -* remote serial debugging summary: Debug Session. -* remote serial debugging, overview: Remote Serial. -* remote serial protocol: Protocol. -* remote serial stub: Stub Contents. -* remote serial stub list: Remote Serial. -* remote serial stub, initialization: Stub Contents. -* remote serial stub, main routine: Stub Contents. -* remote stub, example: Protocol. -* remote stub, support routines: Bootstrapping. -* repeating commands: Command Syntax. -* reporting bugs in GDB: GDB Bugs. -* reset: Nindy Reset. -* response time, MIPS debugging: MIPS Stack. -* resuming execution: Continuing and Stepping. -* RET: Command Syntax. -* return: Returning. -* returning from a function: Returning. -* reverse-search: Search. -* run: Starting. -* running: Starting. -* running 29K programs: EB29K Remote. -* running VxWorks tasks: VxWorks Attach. -* s: Continuing and Stepping. -* saving symbol table: Files. -* scope: M2 Scope. -* search: Search. -* searching: Search. -* selected frame: Stack. -* serial connections, debugging: Protocol. -* serial device, Hitachi micros: Hitachi Remote. -* serial line speed, Hitachi micros: Hitachi Remote. -* serial line, target remote: Debug Session. -* serial protocol, GDB remote: Protocol. -* set addressprint: Renamed Commands. -* set args: Arguments. -* set array-max: Renamed Commands. -* set arrayprint: Renamed Commands. -* set asm-demangle: Renamed Commands. -* set caution: Renamed Commands. -* set check: Range Checking. -* set check: Type Checking. -* set check range: Range Checking. -* set check type: Type Checking. -* set complaints: Messages/Warnings. -* set confirm: Messages/Warnings. -* set demangle: Renamed Commands. -* set demangle-style: Print Settings. -* set editing: Editing. -* set environment: Environment. -* set height: Screen Size. -* set history expansion: History. -* set history filename: History. -* set history save: History. -* set history size: History. -* set history write: Renamed Commands. -* set language: Manually. -* set listsize: List. -* set mipsfpu off: MIPS Remote. -* set prettyprint: Renamed Commands. -* set print address: Print Settings. -* set print array: Print Settings. -* set print asm-demangle: Print Settings. -* set print demangle: Print Settings. -* set print elements: Print Settings. -* set print max-symbolic-offset: Print Settings. -* set print object: Print Settings. -* set print pretty: Print Settings. -* set print sevenbit-strings: Print Settings. -* set print symbol-filename: Print Settings. -* set print union: Print Settings. -* set print vtbl: Print Settings. -* set prompt: Prompt. -* set radix: Numbers. -* set remotedebug: Protocol. -* set retransmit-timeout: MIPS Remote. -* set rstack_high_address: Registers. -* set screen-height: Renamed Commands. -* set screen-width: Renamed Commands. -* set sevenbit-strings: Renamed Commands. -* set symbol-reloading: Messages/Warnings. -* set timeout: MIPS Remote. -* set unionprint: Renamed Commands. -* set variable: Assignment. -* set verbose: Messages/Warnings. -* set vtblprint: Renamed Commands. -* set width: Screen Size. -* set write: Patching. -* setting variables: Assignment. -* setting watchpoints: Set Watchpoints. -* set_debug_traps: Stub Contents. -* share: Files. -* shared libraries: Files. -* sharedlibrary: Files. -* shell: Shell Commands. -* shell escape: Shell Commands. -* show: Help. -* show addressprint: Renamed Commands. -* show args: Arguments. -* show array-max: Renamed Commands. -* show arrayprint: Renamed Commands. -* show asm-demangle: Renamed Commands. -* show caution: Renamed Commands. -* show check range: Range Checking. -* show check type: Type Checking. -* show commands: History. -* show complaints: Messages/Warnings. -* show confirm: Messages/Warnings. -* show convenience: Convenience Vars. -* show copying: Help. -* show demangle: Renamed Commands. -* show demangle-style: Print Settings. -* show directories: Source Path. -* show editing: Editing. -* show environment: Environment. -* show height: Screen Size. -* show history: History. -* show history write: Renamed Commands. -* show language: Show. -* show listsize: List. -* show paths: Environment. -* show prettyprint: Renamed Commands. -* show print address: Print Settings. -* show print array: Print Settings. -* show print asm-demangle: Print Settings. -* show print demangle: Print Settings. -* show print elements: Print Settings. -* show print max-symbolic-offset: Print Settings. -* show print object: Print Settings. -* show print pretty: Print Settings. -* show print sevenbit-strings: Print Settings. -* show print symbol-filename: Print Settings. -* show print union: Print Settings. -* show print vtbl: Print Settings. -* show prompt: Prompt. -* show radix: Numbers. -* show remotedebug: Protocol. -* show retransmit-timeout: MIPS Remote. -* show rstack_high_address: Registers. -* show screen-height: Renamed Commands. -* show screen-width: Renamed Commands. -* show sevenbit-strings: Renamed Commands. -* show timeout: MIPS Remote. -* show unionprint: Renamed Commands. -* show user: Define. -* show values: Value History. -* show verbose: Messages/Warnings. -* show version: Help. -* show vtblprint: Renamed Commands. -* show warranty: Help. -* show width: Screen Size. -* show write: Patching. -* si: Continuing and Stepping. -* signal: Signaling. -* signals: Signals. -* silent: Break Commands. -* sim: Simulator. -* simulator: Simulator. -* simulator, H8/300 or H8/500: Simulator. -* simulator, Hitachi SH: Simulator. -* simulator, Z8000: Simulator. -* size of screen: Screen Size. -* source: Command Files. -* source path: Source Path. -* sparc-stub.c: Remote Serial. -* speed: Hitachi Remote. -* st2000 CMD: ST2000 Remote. -* ST2000 auxiliary commands: ST2000 Remote. -* stack frame: Frames. -* stack on MIPS: MIPS Stack. -* stacking targets: Active Targets. -* starting: Starting. -* STDBUG commands (ST2000): ST2000 Remote. -* step: Continuing and Stepping. -* stepi: Continuing and Stepping. -* stepping: Continuing and Stepping. -* stub example, remote debugging: Protocol. -* stupid questions: Messages/Warnings. -* symbol decoding style, C++: Print Settings. -* symbol dump: Symbols. -* symbol names: Symbols. -* symbol overloading: Breakpoint Menus. -* symbol table: Files. -* symbol-file: Files. -* symbols, reading immediately: Files. -* target: Targets. -* target amd-eb: Target Commands. -* target core: Target Commands. -* target exec: Target Commands. -* target hms: Target Commands. -* target mips PORT: MIPS Remote. -* target nindy: Target Commands. -* target remote: Target Commands. -* target sim: Target Commands. -* target sim: Simulator. -* target st2000: Target Commands. -* target udi: Target Commands. -* target vxworks: Target Commands. -* tbreak: Set Breaks. -* TCP port, target remote: Debug Session. -* terminal: Input/Output. -* this: Cplus expressions. -* toggle-editing-mode: Readline Vi Mode. -* tty: Input/Output. -* type casting memory: Expressions. -* type checking: Checks. -* type conversions in C++: Cplus expressions. -* u: Continuing and Stepping. -* udi: UDI29K Remote. -* UDI: UDI29K Remote. -* undisplay: Auto Display. -* unset: Renamed Commands. -* unset environment: Environment. -* until: Continuing and Stepping. -* up: Selection. -* up-silently: Selection. -* user-defined command: Define. -* value history: Value History. -* variable name conflict: Variables. -* variable values, wrong: Variables. -* variables, setting: Assignment. -* version number: Help. -* VxWorks: VxWorks Remote. -* watch: Set Watchpoints. -* watchpoints: Breakpoints. -* whatis: Symbols. -* where: Backtrace. -* word completion: Completion. -* working directory: Source Path. -* working directory (of your program): Working Directory. -* working language: Languages. -* writing into corefiles: Patching. -* writing into executables: Patching. -* wrong values: Variables. -* x: Memory. -* Z8000 simulator: Simulator. - - diff --git a/gnu/usr.bin/gdb/doc/libgdb.texinfo b/gnu/usr.bin/gdb/doc/libgdb.texinfo deleted file mode 100644 index c67c3a8..0000000 --- a/gnu/usr.bin/gdb/doc/libgdb.texinfo +++ /dev/null @@ -1,1471 +0,0 @@ -\input texinfo @c -*-texinfo-*- -@c %**start of header -@setfilename libgdb.info -@settitle Libgdb -@setchapternewpage odd -@c %**end of header - -@ifinfo -This file documents libgdb, the GNU library for symbolic debuggers. - -Copyright 1993 Cygnus Support - -Permission is granted to ... -@end ifinfo - -@c This title page illustrates only one of the -@c two methods of forming a title page. - -@titlepage -@title Libgdb -@subtitle Version 0.1 -@subtitle 27 Sep 1993 -@author Thomas Lord - -@c The following two commands -@c start the copyright page. -@page -@vskip 0pt plus 1filll -Copyright @copyright{} 1993 COPYRIGHT-OWNER - -Published by ... - -Permission is granted to ... -@end titlepage - -@node Top, Overview, (dir), (dir) - -@ifinfo - -Libgdb is a library which provides the core functionality of a symbolic -debugger. It is derived from GNU GDB and depends on the BFD library. - -This is an early draft of this document. Subsequent versions will likely -contain revisions, deletions and additions. - -This document applies to version 0.0. - -Text marked `[[[' indicates areas which require expansion. - -Many nodes describe library entry points by giving a prototype and brief -description: - -@deftypefun {const char **} gdb_warranty () -(warranty_info) -Return a pointer to the text of the GDB disclaimer. -@end deftypefun - -The parenthesized symbols (e.g. `(warranty_info)') refer to the -existing GDB source and generally indicate where to find code with -which to implement the library function. -@end ifinfo - -@menu -* Copying:: Your rights and freedoms. -* Overview:: The basics of libgdb and this document. -* Conventions:: Programming conventions for users of libgdb. -* Targets:: Selecting debugging targets and symbol tables. -* Symtabs:: Accessing symbol tables and debugging information. -* Source:: Relating inferiors to source files. -* Running:: Creating, continuing, and stepping through an - inferior process. -* Stopping:: Using breakpoints, signaling an inferior. -* Stack:: Accessing an inferior's execution stack. -* Expressions:: How to parse and evaluate expressions in the - context of an inferior. -* Values:: Data from the inferior, the values of expressions. -* Examining:: Formatting values as strings. -* Types:: Examining the types of an inferiors data. -@end menu - - -@node Copying, Overview, top, top -@comment node-name, next, previous, up -@chapter Copying -@cindex copying - -blah blah - -@node Overview, Conventions, Copying, top -@comment node-name, next, previous, up -@chapter Overview -@cindex overview -@cindex definitions - - -Libgdb is a library which provides the core functionality of a symbolic -debugger. It is derived from GNU GDB and depends on the BFD library. - -target -inferior - - - -@node Conventions, Targets, Overview, top -@comment node-name, next, previous, up -@chapter Programming Conventions for Libgdb Clients -@cindex Conventions - -@heading Naming Conventions - -Names intentionally exported from libgdb all begin @code{gdb_} -as in @code{gdb_use_file}. - - -@heading Error Returns - -Libgdb functions that might not succeed generally have a return -type of @code{gdb_error_t}. - -@deftypefun {const char *} gdb_error_msg (gdb_error_t @var{error}) -returns a reasonable error message for @var{error}. -@end deftypefun - - -@heading Blocking I/O - -[[[....]]] - - -@heading Global Parameters -@subheading the current directory -@deftypefun gdb_error_t gdb_cd (char * @var{dir}) -Specify gdb's default directory as well as the working -directory for the inferior (when first started).@* -(cd_command) -@end deftypefun - -@deftypefun {char *} gdb_copy_pwd () -Make a copy of the name of gdb's default directory.@* -(pwd_command) -@end deftypefun - - -@subheading controlling the input/output radix -@deftypefun gdb_error_t gdb_set_base (int) -Change the default output radix to 10 or 16, or set it to 0 -(heuristic). This command is mostly obsolete now that the print -command allows formats to apply to aggregates, but is still handy -occasionally.@* -(set_base_command) -@end deftypefun - -@deftypefun gdb_error_t gdb_set_input_radix (int) -@deftypefunx gdb_error_t gdb_set_output_radix (int) -@deftypefunx gdb_error_t gdb_set_radix (int) -Valid output radixes are only 0 (heuristic), 10, and 16.@* -(set_radix) -@end deftypefun - - -@subheading manipulating environments -@deftp Type {struct environ} -@example -struct environ -@{ - int allocated; - char ** vector; -@} -@end example -A `struct environ' holds a description of environment -variable bindings. -@end deftp - -@deftypefun {struct environ *} gdb_make_environ () -Create a new (empty) environment.@* -(make_environ) -@end deftypefun - -@deftypefun {void} gdb_free_environ (struct environ *) -Free an environment allocated by `gdb_make_environ'.@* -(free_environ) -@end deftypefun - -@deftypefun {void} gdb_init_environ (struct environ * env) -Copy the processes environment into ENV.@* -(init_environ) -@end deftypefun - -@deftypefun {char **} gdb_get_in_environ (const struct environ * @var{env}, const char * @var{var}) -Look up the binding of @var{var} in @var{env}.@* -(get_in_environ) -@end deftypefun - - -@deftypefun {void} gdb_set_in_environ (struct environ * @var{env}, const char * @var{var}, const char * @var{value}) -Lookup/bind variables within an environment. -(set_in_environ) -@end deftypefun - - -@subheading legal notices -@deftypefun {char **} gdb_copying () -@deftypefunx {char **} gdb_warranty () -These return pointers to NULL terminated arrays of strings. -They contain text which describes the conditions under which -libgdb is distributed (`gdb_copying') and which explains to -users that there is no warranty for libgdb (`gdb_warranty').@* -(show_warranty_command, show_copying_command) -@end deftypefun - - -@subheading the inferior's terminal -@deftypefun void gdb_inferiors_io (int @var{std_in}, int @var{std_out}, int @var{std_err}) -Assert that the given descriptors should be copied into -descriptors 0, 1, and 2 of the inferior when it -is next run. -@end deftypefun - - -@heading callbacks - -One idiom used in several places deserves mention. -At times, it makes sense for libgdb functions to -invoke functions provided by the libgdb client. -Where this is the case, callback structures are used -to refer to client functions. For example, here -are the declarations for a callback to which libgdb -will pass an integer and a character pointer. - -@example -struct a_gdb_cback; -typedef void (*a_gdb_cback_fn) (struct a_gdb_cback *, - int, char *); -@end example - -Suppose the client wants the callback to be implemented -by @code{foo} which we will assume takes not only the integer -and character pointer, but also a floating point number. -The client could use these declarations: - -@example -struct my_cback -@{ - struct a_gdb_cback gdb_cback; /* must be first */ - float magic_number; -@}; - -void -foo_helper (struct a_gdb_cback * callback, int i, char * cp) -@{ - foo ( ((struct my_cback *)callback)->magic_number, i, c); -@} - -struct my_cback -@{ - foo_helper, - 1079252848.8 -@} the_cback; -@end example - - -@subheading stream callbacks - -A common kind of callback takes just a character pointer, -presumed to point to part or all of an informational -message. - -@example -struct gdb_stream_cback; -typedef void (*gdb_stream_cback_fn) (struct gdb_stream_cback *, - char *); -@end example - - -@subheading integer callbacks - -Another common kind of callback takes just an integer. - -@example -struct gdb_int_cback; -typedef void (*gdb_int_cback_fn) (struct gdb_int_cback *, int); -@end example - -@node Targets, Symtabs, Conventions, top -@comment node-name, next, previous, up -@chapter Selecting Targets and Symbol Tables for Debugging -@cindex targets - -@deftypefun gdb_error_t gdb_use_file (char * @var{filename}) -Arrange to read both executable code and symbol table information -from FILENAME. - -This is exactly equivalent to a sequence of two calls: -@example - gdb_use_exec_file (filename); - gdb_use_symbol_file (filename); -@end example -(file_command) -@end deftypefun - - -@deftypefun gdb_error_t gdb_use_exec_file (char * @var{filename}) -Read the code to debug from `filename'.@* -(exec_file_command) -@end deftypefun - - -@deftypefun {char *} gdb_get_exec_file () -Return the name of the executable file as a string or 0 -if there is none. -@end deftypefun - - -@deftypefun gdb_error_t gdb_use_core (char * @var{filename}) -Specify the whereabouts of a core dump file to be used as the -"contents of memory". Traditionally, core files contain only some -parts of the address space of the process that generated them; GDB -can access the executable file itself for other parts. - -If @var{filename} is @code{NULL}, no core file is used.@* -(core_file_command) -@end deftypefun - - -@deftypefun gdb_error_t gdb_use_symbol_file (char * @var{filename}) -Arrange to read symbol table information from `filename'. - -This is the same as: - - gdb_symbol_file_add (filename, 1, (CORE_ADDR)0, 1, 0, 0); - -See @code{gdb_symbol_file_add} for finer control over the symbol -table.@* -(symbol_file_command) -@end deftypefun - - -@deftypefun gdb_error_t gdb_symbol_file_add (@var{name}, @var{verbose}, @var{text_addr}, @var{replace}, @var{eager}) -Arrange to read additional symbol table information from -the file `name'. - -The arguments are: -@itemize @minus -@item struct gdb_stream_cback * @var{info_out} - -Callback to handle informational output. - -@item char * @var{name} - -If not 0, verbose output will occur. - -@item int @var{be_verbose} - -Regulates the amount of informational output produced. - -@item CORE_ADDR @var{text_addr} - -is the address at which the named file is presumed to have -been loaded. - -@item int @var{replace}@* - -If not 0, this will become the only file -in the symbol table -- all previously loaded -symbol table information will be discarded. - -@item int @var{readnow} - -If not 0, eagerly read symbols from this file,otherwise -symbols will only be read lazily (as needed). -@end itemize -@end deftypefun - - -@deftypefun {char *} gdb_copy_exec_path () -Make a copy of the execution path.@* -[[[implement: strsave(get_in_environ (inferior_environ, "PATH"));]]]@* -(path_info) -@end deftypefun - - -@deftypefun void gdb_mod_exec_path (char * @var{dirnames}) -Add zero or more directories to the front of the execution path. -@var{dirnames} should be a colon separated list of directory names.@* -(path_command) -@end deftypefun - - -@deftypefun gdb_error_t gdb_target_device (char * @var{name}) -Connects the libgdb host environment to a target machine -or process.@* -(target foo) -@end deftypefun - - -@deftypefun gdb_error_t gdb_set_baud (int @var{rate}) -If using a remote target connected by a serial port, -use RATE as the communication speed. -@end deftypefun - - -@deftypefun gdb_error_t gdb_set_target_debugging (int @var{level}) -Choose the level of verboseness of with which a remote -target produces debugging output. -@end deftypefun - -@node Symtabs, Source, Targets, top -@comment node-name, next, previous, up -@chapter Accessing symbol tables and debugging information. -@cindex Symtabs -@cindex {Symbol Tables} - -@deftp Type {struct symtab} -Each source file is represented by a struct symtab. -In many contexts, @code{struct symtab *} is used in preference -to a {char *} filename to refer to the source. -@end deftp - - -@deftypefun {char *} gdb_symtab_to_filename (struct symtab *) -@deftypefunx {char *} gdb_symtab_to_dirname (struct symtab *) -Return the location of the file corresponding to this symtab. -@code{gdb_symtab_to_dirname} might return @code{NULL} if no directory -is known. @code{gdb_symtab_to_line_count} might return -1 if line -number information is unavailable. -@end deftypefun - -@deftypefun int gdb_symtab_to_line_count (struct symtab *) -(See also `Source') -@end deftypefun - - -@deftypefun {struct symtab *} gdb_filename_to_symtab (char * @var{filename}) -Lookup the symbol table of a source file named NAME.@* -(lookup_symtab) -@end deftypefun - - -@deftp Type {struct symtab_and_line} -@example -struct symtab_and_line -@{ - struct symtab *symtab; - int line; - CORE_ADDR pc; - CORE_ADDR end; -@} -@end example - -@code{struct symtab_and_line} is used to refer to a particular line -of source code. It is used to locate breakpoints in the source -code and the executable. - -@code{line} starts at 1 and proceeds through symtab->nlines. -0 is never a valid line number; it is used to indicate -that line number information is not available. -@end deftp - - -@deftypefun {struct symtab_and_line} gdb_find_pc_line (CORE_ADDR @var{pc}, int @var{notcurrent}) -Find the source file and line number for a given @var{pc} value. -Return a structure containing a symtab pointer, a line number, -and a pc range for the entire source line. -The value's @code{.pc} field is NOT the specified @var{pc}. -@var{notcurrent} nonzero means, if specified pc is on a line boundary, -use the line that ends there. Otherwise, in that case, the line -that begins there is used.@* -(find_pc_line) -@end deftypefun - - -@deftypefun gdb_error_t gdb_find_line (struct symtab_and_line * @var{out}, struct symtab *, int) -Create a symtab_and_line for a given symtab and line number. -In other words, if you know the source file and line, -this returns a location for the breakpoint.@* -(resolve_sal_pc) -@end deftypefun - - -@deftypefun {struct symtabs_and_lines} gdb_decode_line (@var{argptr}, @var{firstln}, @var{default_symtab}, @var{default_line}, @var{canonical}) -@example - char ** argptr; - int funfirstline; - struct symtab * default_symtab; - int default_line; - char *** canonical; -@end example - Parse a string that specifies a line number in GDB syntax. - @var{argptr} will be advanced over the characters actually parsed. - - The string can be: - - LINENUM -- that line number in current file. PC returned is 0. - FILE:LINENUM -- that line in that file. PC returned is 0. - FUNCTION -- line number of openbrace of that function. - PC returned is the start of the function. - VARIABLE -- line number of definition of that variable. - PC returned is 0. - FILE:FUNCTION -- likewise, but prefer functions in that file. - *EXPR -- line in which address EXPR appears. - - FUNCTION may be an undebuggable function found in minimal symbol - table. - - If the argument FUNFIRSTLINE is nonzero, we want the first line - of real code inside a function when a function is specified. - - DEFAULT_SYMTAB specifies the file to use if none is specified. - It defaults to current_source_symtab. - - DEFAULT_LINE specifies the line number to use for relative line - numbers (that start with signs). Defaults to current_source_line. - If CANONICAL is non-NULL, store an array of strings containing the - canonical line specs there if necessary. Currently overloaded - member functions and line numbers or static functions without a - filename yield a canonical line spec. The array and the line spec - strings are allocated on the heap, it is the callers responsibility - to free them. - - Note that it is possible to return zero for the symtab - if no file is validly specified. Callers must check that. - Also, the line number returned may be invalid. - - The return value of this function includes allocated memory - which the caller is responsible for freeing: - - struct symtabs_and_lines sals; - sals = decode_line_spec (arg, 1); - .... - free (sals.sals);@* -(decode_line_1) -@end deftypefun - - -@deftp Type {struct block *} -Lexical environments in the program are represented by struct block. -These are useful as arguements to expression parsing functions (see -`Expressions'). -@end deftp - - -@deftypefun {struct block *} gdb_block_for_pc (CORE_ADDR) -Return the innermost lexical block containing the -specified pc value, or 0 if there is none.@* -(block_for_pc) -@end deftypefun - - -@deftypefun {struct block *} gdb_get_frame_block (FRAME @var{frame}) -This returns the block being executed by a given -stack frame (see `Stack')@* -(get_frame_block) -@end deftypefun - - -@deftypefun int gdb_find_line_pc_range (@var{syms}, @var{line}, @var{start_out}, @var{end_out}) -@example -struct symtab * @var{start_out}; -int @var{line}; -CORE_ADDR * @var{start_out}; -CORE_ADDR * @var{end_out}; -@end example -Find the range of pc values in a line.@* -Store the starting pc of the line into @code{*@var{startptr}}. -and the ending pc (start of next line) into @code{*@var{endptr}}. - -Returns 1 to indicate success.@* -Returns 0 if could not find the specified line.@* -(find_line_pc_range) -@end deftypefun - - -@deftypefun int gdb_find_pc_partial_function (@var{pc}, @var{name}, @var{address}, @var{endaddr}) -@example -CORE_ADDR @var{pc}; -char **@var{name}; -CORE_ADDR *@var{address}; -CORE_ADDR *@var{endaddr}; -@end example -Finds the "function" (text symbol) that is smaller than @var{pc} but -greatest of all of the potential text symbols. Sets @code{*@var{name}} -and/or @code{*@var{address}} conditionally if that pointer is non-null. If -@var{endaddr} is non-null, then set @code{*@var{endaddr}} to be the end of -the function (exclusive), but passing @var{endaddr} as non-null means that -the function might cause symbols to be read. This function either succeeds -or fails (not halfway succeeds). If it succeeds, it sets -@code{*@var{name}}, @code{*@var{address}}, and @code{*@var{endaddr}} to -real information and returns 1. If it fails, it sets @code{*@var{name}}, -@code{*@var{address}}, and @code{*@var{endaddr}} to zero and returns 0. - -@example - pc = get_frame_pc (selected_frame); - if (find_pc_partial_function (pc, &name, &low, &high) == 0) - error ("No function contains program counter for selected frame.\n"); -@end example -(find_pc_partial_function) -@end deftypefun - - -@deftypefun void gdb_list_symbols (@var{info_out}, @var{regexp}, @var{class}, @var{bpt}) -@example -struct gdb_stream_cback * @var{info_out}; -char * @var{regexp}; -int @var{class}; -int @var{bpt}; -@end example -List all symbols (if @var{regexp} is NULL) or all symbols matching @var{regexp}. - - -If @var{class} is ... -@itemize @bullet -@item -0, list all symbols except functions, type names, and -constants (enums). -@item -1, list only functions. -@item -2, list only type names. -@item -3, list only method names. -@end itemize -BPT is non-zero if set a breakpoint at the functions we find.@* -(variables_info, functions_info, types_info, list_symbols) -@end deftypefun - - -@deftypefun int gdb_locals_info (struct gdb_stream_cback * @var{info_out}, FRAME @var{frame}) -Print all the local variables in the given frame. -including all the blocks active in that frame -at its current pc. - -Returns 1 if the job was done, -or 0 if nothing was printed because we have no info -on the function running in @var{frame}.@* -(locals_info) -@end deftypefun - - -@deftypefun int print_frame_arg_vars (struct gdb_stream_cback *, FRAME) -Similar to `gdb_locals_info'.@* -(args_info) -@end deftypefun - -@node Source, Running, Symtabs, top -@comment node-name, next, previous, up -@chapter Relating Inferiors to Source Files -@cindex source -@cindex {source files} - -How to find the source that corresponds to executable code and the -executable code that corresponds to a line of source. - -@deftypefun {char *} gdb_copy_source_fullname (struct symtab *@var{s}) -Return a copy of the full path name to a source file. -(See `Symtabs' for more information about filenames -and symbol tables.). -@end deftypefun - - -@deftypefun int gdb_open_source_file (struct symtab *@var{s}) -Open a source file corresponding to @var{s}. Returns a file descriptor -or negative number for error. -[[[We may decide not to provide this function.]]]@* -(open_source_file) -@end deftypefun - - -@deftypefun int gdb_source_line_pos (struct symtab * @var{s}, int @var{lineno}) -Return the byte offset of a given line of source -or a negative number if @var{lineno} is out of range.@* -(find_source_lines) -@end deftypefun - - - -- IDIOM: The gdb command `show directories'. -@example - puts_filtered ("Source directories searched: "); - puts_filtered (source_path); - puts_filtered ("\n"); -@end example -(show_directories) - - -@deftypefun {char *} gdb_source_path () -Return the path in which source files are sought.@* -(source_path) -@end deftypefun - - -@deftypefun void gdb_modify_source_path (char * @var{dirnames}) -Change the source path according to dirnames.@* -(directory_command) -@end deftypefun - - -See `Symtabs' for functions relating symbol tables to files. -(source_info) - - -See `Symtabs' for functions relating source lines to PC values. -(line_info) - - -[[[Try to expose sources_info without having to introduce struct object *?]]] -(sources_info) - - -@node Running, Stopping, Source, top -@comment node-name, next, previous, up -@chapter Creating, Continuing, and Stepping Through an Inferior Process -@cindex running - - -@deftypefun gdb_error_t gdb_target_create_inferior (@var{exec}, @var{args}, @var{environ}) -@example -char * @var{exec_file}; -char * @var{inferior_args}; -char ** @var{inferior_environment_vector}; -@end example -Create a running inferior. -[[[I think the exec_file parameter is redundant. Perhaps this will take -only two arguments.]]]@* -(run_command, target_create_inferior) -@end deftypefun - - -@deftypefun int gdb_target_has_execution () -Return non-0 if an inferior is running.@* -(target_has_execution) -@end deftypefun - - -@deftypefun void gdb_target_kill () -Kill the inferior process. Make it go away. -The inferior may become a core file. -If so, gdb_target_has_stack() will return non-0.@* -(target_kill) -@end deftypefun - - -@deftypefun gdb_error_t gdb_step_1 (@var{skip_subs}, @var{single_inst}, @var{repeat_count}) -@example -int skip_subs; -int single_inst; -int repeat_count; -@end example -Continue a program a little bit. Roughly: -@example - for (; count > 0; --count) - gdb_clear_proceed_status (); - gdb_proceed (...); -@end example -(next_command, nexti_command, step_command, stepi_command) -@end deftypefun - - - -- IDIOM: Continuing a program where it stopped. -@example - gdb_clear_proceed_status (); - gdb_proceed ((CORE_ADDR) -1, -1, 0); -@end example -(continue_command) - - - -- IDIOM: Continuing a program giving it a specified signal. -@example - gdb_clear_proceed_status (); - gdb_proceed ((CORE_ADDR) -1, signum, 0); -@end example -(signal_command) - - -@deftypefun {char *} strtosigno (char * @var{str}) -(Typical use:) -@example - signum = strtosigno (signum_exp); - - if (signum == 0) - /* Not found as a name, try it as an expression. */ - signum = parse_and_eval_address (signum_exp); - - gdb_clear_proceed_status (); - gdb_proceed (); -@end example -@end deftypefun - - - -- IDIOM: Continuing a program at a specified address. -@example - gdb_clear_proceed_status (); - gdb_proceed (addr, 0, 0); -@end example -(jump_command) - - -@deftypefun gdb_error_t gdb_finish () -"finish": Set a temporary breakpoint at the place -the selected frame will return to, then continue. -This is a convenience function but it summarizes a lot -of other stuff.@* -(finish_command) -@end deftypefun - - -@deftypefun void gdb_clear_proceed_status () -Clear out all variables saying what to do when inferior is continued. -First do this, then set the ones you want, then call @code{gdb_proceed}. - - [[[Some of these should be documented, others hidden.]]] -@example - The variables are: - trap_expected = 0; - step_range_start = 0; - step_range_end = 0; - step_frame_address = 0; - step_over_calls = -1; - stop_after_trap = 0; - stop_soon_quietly = 0; - proceed_to_finish = 0; - breakpoint_proceeded = 1; /* We're about to proceed... */ - - /* Discard any remaining commands or status from previous stop. */ - bpstat_clear (&stop_bpstat); -@end example -(clear_proceed_status) -@end deftypefun - - -@deftypefun void gdb_proceed (CORE_ADDR @var{addr}, int @var{signal}, int @var{step}) -Basic routine for continuing the program in various fashions. - -@var{addr} is the address to resume at, or -1 for resume where stopped.@* -@var{signal} is the signal to give it, or 0 for none, -or -1 for act according to how it stopped.@* -@var{step} is nonzero if should trap after one instruction. --1 means return after that and print nothing.@* -You should probably set various step_... variables -before calling here, if you are stepping. - -You should call @code{gdb_clear_proceed_status} before calling proceed. -(See the documentation for @code{gdb_clear_proceed_status} for more -parameters to @code{gdb_proceed}).@* -(proceed) -@end deftypefun - - -@deftypefun gdb_error_t gdb_return (value @var{return_value}, FRAME @var{frame}) -Make @var{frame} return to @var{value} to it's caller. -Unlike the other functions in this section, this doesn't -call proceed. -(return_command) -@end deftypefun - - -@deftypefun int gdb_inferior_pid () -0 or the valid pid of an inferior. -@end deftypefun - - -@deftypefun gdb_error_t gdb_attach (int @var{pid}) -takes a program started up outside of gdb and -`attaches'' to it. This stops it cold in its tracks and allows us -to start debugging it. and wait for the trace-trap that results -from attaching.@* -(attach_command) -@end deftypefun - - -@deftypefun gdb_error_t gdb_detach (int @var{signal_num}) -Takes a program previously attached to and detaches it. -The program resumes execution and will no longer stop -on signals, etc. We better not have left any breakpoints -in the program or it'll die when it hits one. For this -to work, it may be necessary for the process to have been -previously attached. It *might* work if the program was -started via the normal ptrace (PTRACE_TRACEME).@* -(detach_command) -@end deftypefun - -@node Stopping, Stack, Running, top -@comment node-name, next, previous, up -@chapter Using Breakpoints, Signaling an Inferior -@cindex stopping -@cindex breakpoints - - -@deftp Type {struct breakpoint} -Breakpoints are typically represented @code{struct breakpoint *}. -@end deftp - - -@deftypefun {struct breakpoint *} gdb_find_breakpoint (int) -Find a breakpoint given it's number (return 0 if it doesn't exist). -@end deftypefun - -@deftypefun gdb_error_t gdb_set_break (struct breakpoint * @var{brk_out}, struct symtab_and_line) -@deftypefunx gdb_error_t gdb_set_tbreak (struct breakpoint *, struct symtab_and_line) -@deftypefunx gdb_error_t gdb_set_until (struct breakpoint *, struct symtab_and_line) -These three are like their command language counterparts. -They are front ends to `gdb_set_raw_breakpoint'. -See `Symtabs' for sources of `struct symtab_and_line'.@* -(break_command, break_command_1, until_command, tbreak_command) -@end deftypefun - - -@deftypefun gdb_error_t gdb_set_watchpt (@var{brk_out}, @var{exp_string}, @var{exp}, @var{exp_valid_block}) -@example -struct breakpoint * @var{brk_out}; -char * @var{exp_string}; -struct expression * @var{exp}; -struct block * @var{expression_valid_block}; -@end example -Set a watchpoint for the given expression.@* -(watch_command) -@end deftypefun - - -@deftypefun void gdb_set_ignore_count (int @var{bptnum}, int @var{count}) -Set ignore-count of breakpoint number BPTNUM to COUNT.@* -(set_ignore_count) -@end deftypefun - - -@deftypefun {struct gdb_bp_condition *} gdb_set_condition (@var{bp}, @var{exp_str}, @var{cond}) -@example -int @var{pbtnum}; -char * @var{exp_str}; -struct gdb_bp_condition * @var{cond}; - -typedef int (*gdb_bp_fn) (struct gdb_bp_condition *, int bp_num); -struct gdb_bp_condition -@{ - gdb_bp_fn fn; -@}; -@end example -Add a condition to a breakpoint. -The condition is a callback which should return -0 to skip the breakpoint, and 1 to break at it. -It is called at times when the break might occur. - -A useful application of these callbacks to attach -an expression to breakpoints like the gdb `condition' -command. See `Expressions' for the parsing and -evaluation of expressions.@* -(condition_command) -@end deftypefun - - -@deftypefun gdb_error_t gdb_enable_breakpoint (struct breakpoint * @var{bpt}, int @var{once}) -@deftypefunx gdb_error_t gdb_disable_breakpoint (struct breakpoint * @var{bpt}) -Enable/disable a breakpoint. If `once' is not 0, the -breakpoint is only temporarily enabled.@* -(enable_breakpoint, disable_breakpoint, enable_command) -@end deftypefun - - -@deftypefun gdb_error_t gdb_delete_breakpoint (struct breakpoint * @var{bpt}) -Delete a breakpoint and clean up all traces of it in the -data structures.@* -(delete_breakpoint) -@end deftypefun - - -@deftypefun void gdb_clear_breakpoints (struct symtabs_and_lines * @var{sals}) -Clear breakpoints from a list of program locations as -might be returned by `gdb_decode_line' (see `Symtabs').@* -(clear_command) -@end deftypefun - - -@deftypefun {static struct symtabs_and_lines} get_catch_sals (int @var{this_level_only}) -Return the line numbers of all exception handlers currently -active (or `this_level_only'?? [[[?]]]). -[[[The implementation should remember to resolve_sal_pc]]] -@end deftypefun - - -@deftp Type {struct breakpoint_cback} -@example -typedef void (*breakpoint_cback_fn) (struct breakpoint_cback *, int bp_num); -struct breakpoint_cback -@{ - breakpoint_cback_fn fn; -@}; -@end example - -Breakpoints can have an associated function which is called -when the program is stopped by that breakpoint.@* -(commands_command) -@end deftp - - -@deftypefun {struct breakpoint_cback *} gdb_set_breakpoint_cback (int @var{bp_num}, struct breakpoint_cback *) -This sets a breakpoint callback and returns the previous callback value -for that breakpoint. -[[[In the long run, the command interpreter should be available - for the use of hooks like this one.]]] -@end deftypefun - - -@deftypefun {struct breakpoint_cback *} gdb_get_breakpoint_cback (int @var{bp_num}) -@end deftypefun - - -@deftypefun void gdb_breakpoints_info (struct gdb_stream_cback, int @var{bp_num}, int @var{watches}) -Print information on breakpoint number @var{bnum}, or -1 if all. -If @var{watches} is zero, process only breakpoints; if @var{watches} -is nonzero, process only watchpoints. -[[[In the long run, expose the information read off by this function.]]]@* -(info breakpoints, info watchpoints, breakpoints_info, breakpoint_1) -@end deftypefun - - -@deftypefun void gdb_catch_info (struct gdb_stream_cback *) -Print a list of all the exception handlers that are active in the -current stack frame at the current point of execution.@* -(catch_info) -@end deftypefun - - -@deftypefun void gdb_handle_command (char * @var{args}) -Takes arguments like the gdb command `handle' and has -the same effect.@* -(handle_command) -@end deftypefun - - -@deftypefun void gdb_signals_info (struct gdb_stream_cback *) -Show how signals are handled.@* -(signals_info) -@end deftypefun - - -@node Stack, Expressions, Stopping, top -@comment node-name, next, previous, up -@chapter Accessing An Inferior's Execution Stack -@cindex stack -@cindex FRAME -@cindex {stack frames} - - - -@deftp Type FRAME -This type representing active stack frames in the inferior. -Consider this type opaque. -@end deftp - - -@deftypefun FRAME gdb_get_innermost_frame () -Returns the innermost frame or the frame most recently designated -as current by a call to gdb_set_current_frame.@* -(get_current_frame) -@end deftypefun - - -@deftypefun FRAME gdb_get_caller_frame (FRAME @var{frame}) -Return the frame that called @var{frame}.@* -If @var{frame} is the original frame (it has no caller), return 0.@* -(get_prev_frame) -@end deftypefun - - -@deftypefun FRAME gdb_get_called_frame (FRAME @var{frame}) -Return the frame that @var{frame} calls (0 if @var{frame} is the innermost -frame).@* -(get_next_frame) -@end deftypefun - - -@deftypefun FRAME gdb_parse_frame_specification (char * @var{frame_exp}) -Read a frame specification in whatever the appropriate format is. -Call @code{error}() If the specification is in any way invalid (i.e. -this function never returns NULL).@* -(parse_frame_specification) -@end deftypefun - - -@deftypefun CORE_ADDR get_frame_pc (FRAME @var{frame})@* -(Example use: Implementing @code{disassemble_command})@* -(get_frame_pc) -@end deftypefun - - -@deftypefun FRAME gdb_selected_frame () -The "selected" stack frame is used by default for local and -arg access. May be @code{NULL}, for no selected frame.@* -(variable selected_frame) -@end deftypefun - - -@deftypefun int gdb_selected_frame_level () -Level of the selected frame:@* -0 for innermost,@* -1 for its caller,@* -or -1 for frame specified by address with no defined level.@* -(variable selected_frame_level) -@end deftypefun - - -@deftypefun void gdb_select_frame (FRAME @var{frame}, int @var{level}) -Select frame @var{frame}, and note that its stack level is @var{level}. -@var{level} may be -1 if an actual level number is not known. -Calls @code{set_language} to establish the correct language for the -selected frame. -@end deftypefun - - - -- IDIOM: Computing Frame Levels@* -@example -/* Try to figure out what level this frame is as before a - call to gdb_select_frame. But if there is - no current stack, don't error out, just pass -1 - instead. */ -frame1 = 0; -level = -1; -if (get_current_frame()) @{ - for (frame1 = get_prev_frame (0); - frame1 && frame1 != frame; - frame1 = get_prev_frame (frame1)) - level++; -@} -@end example - - -@deftypefun void gdb_print_stack_frame (@var{cback}, @var{frame}, @var{level}, @var{source}) -@example -struct gdb_stream_cback * @var{cback}; -FRAME @var{frame}; -int @var{level}; -int @var{source}; -@end example -Print a stack frame briefly. @var{frame} should be the frame id -and @var{level} should be its level in the stack (or -1 for level not defined). -This prints the level, the function executing, the arguments, -and the file name and line number.@* -If the pc is not at the beginning of the source line, -the actual pc is printed at the beginning.@* -If @var{source} is 1, print the source line as well.@* -If @var{source} is -1, print ONLY the source line.@* -(print_stack_frame) -@end deftypefun - - -@deftypefun void gdb_print_backtrace (cback, @var{count}, @var{from_tty}) -@example -struct gdb_stream_cback * @var{cback}; -int @var{count}; -int @var{from_tty}; -@end example -Print briefly all stack frames or just the innermost @var{count} frames.@* -(backtrace_command) -@end deftypefun - - -@deftypefun FRAME gdb_find_relative_frame (FRAME @var{frame}, int * @var{level_offset_ptr}) -Find a frame a certain number of levels away from @var{frame}. -@var{level_offset_ptr} points to an int containing the number of levels. -Positive means go to earlier frames (up); negative, the reverse. -The int that contains the number of levels is counted toward -zero as the frames for those levels are found. -If the top or bottom frame is reached, that frame is returned, -but the final value of @var{*level_offset_ptr} is nonzero and indicates -how much farther the original request asked to go. -@end deftypefun - - -@deftypefun FRAME gdb_select_frame_downward (int @var{count}) -@deftypefunx FRAME gdb_select_frame_upward (int @var{count}) -Simply a combination of find_relative_frame and select_frame. -Returns the newly selected frame.@* -(down_silently_command, up_silently_command) -@end deftypefun - - -@deftypefun void gdb_frame_info (struct gdb_stream_cback * @var{cback}, FRAME @var{frame}) -Print verbosely the selected the argument @var{frame}. -This means absolutely all information in the frame is printed.@* -(frame_info) -@end deftypefun - - -@node Expressions, Values, Stack, top -@comment node-name, next, previous, up -@chapter How to Parse and Evaluate Expressions -@cindex parsing -@cindex expressions -@cindex {expression evaluation} -@cindex evaluation - - -@deftp Type {struct expression *} -This represents a parsed expression as might be used for a -breakpoint condition. -@end deftp - - -@deftp Type {struct block} -Describes a lexical environment. -@end deftp - -See also `Values' -See also `Examining' - - -@deftypefun struct expression * parse_exp_1 (char ** @var{stringptr}, struct block * @var{block} int @var{comma}) -Read an expression from the string @code{*@var{stringptr}} points to, -parse it, and return a pointer to a struct expression that we malloc. -Use @var{block} as the lexical context for variable names; -if @var{block} is zero, use the block of the selected stack frame. -Meanwhile, advance @code{*@var{stringptr}} to point after the expression, -at the first nonwhite character that is not part of the expression -(possibly a null character). - -If @var{comma} is nonzero, stop if a comma is reached. -(See `Stack' for information about the selected frame) -@end deftypefun - - -@deftypefun gdb_error_t gdb_evaluate_expression (value * @var{value_out}, struct expression * @var{exp}) -Evaluate an expression. See `values' for more information about -the return type.@* -(evaluate_expression) -@end deftypefun - - -@deftypefun value gdb_evaluate_type (struct expression @var{*exp}) -Evaluate an expression, avoiding all memory references -and getting a value whose type alone is correct.@* -(evaluate_type) -@end deftypefun - - - -@node Values, Examining, Expressions, top -@comment node-name, next, previous, up -@chapter Data from the Inferior, the Values of Expressions -@cindex values -@cindex {expression values} - -Values are allocated by functions such as @code{gdb_evaluate_expression}. -All currently allocated values are on the list @code{all_values} and can be -freed by calling @code{gdb_free_all_values}. - -To preserve a value across calls to @code{gdb_free_all_values}, use -@code{gdb_release_value}. Values added to the history list are automaticly -released. To free a released value use @code{gdb_free_value}. - - -@deftypefun void gdb_free_value (value) -Free the memory associated with a released value. -Do not call this function except on values that have been -passed to @code{gdb_release_value}.@* -(gdb_value_free) -@end deftypefun - - -@deftypefun void gdb_free_all_values (void) -Free all allocated values which haven't been released. -This should be called periodically from outside the dynamic -scope of libgdb functions.@* -(free_all_values) -@end deftypefun - - -@deftypefun void gdb_release_value (value @var{val}) -Remove a value from the list @code{all_values} in order to -protect it from @code{gdb_free_all_values}.@* -(release_value) -@end deftypefun - - -There is a `history list' -- a numbered list of values for -future reference. These can be referred to in expressions, -for example. - -@deftypefun int gdb_record_latest_value (value @var{val}) -Add a value to the history list.@* -(record_latest_value) -@end deftypefun - - -@deftypefun value gdb_access_value_history (int @var{index}) -Retrieve a value from the history list.@* -(access_value_history) -@end deftypefun - - -[[[At the moment, the only libgdb use for values is - string formatting (see `Examining'). So, they are treated - as opaque. It'd be useful to expose more of them in the long run.]]] - - -@node Examining, Types, Values, top -@comment node-name, next, previous, up -@chapter Formatting Values as Strings -@cindex examining -@cindex printing -@cindex formatting -@cindex {pretty printing} - - -Many functions in this section use @code{struct gdb_stream_cback}. -That structure is explained in `Basics'. - - -@deftypefun void gdb_print_formatted (struct gdb_stream_cback * @var{cback}, value @var{val}, int @var{format}, int @var{size}) -Print value @var{val} on a stream according to @var{format}, a letter or 0. -Do not end with a newline. -0 means print @var{val} according to its own type. -@var{size} is the letter for the size of datum being printed. -This is used to pad hex numbers so they line up.@* -(print_formatted) -@end deftypefun - - -@deftypefun static void gdb_printf_command (struct gdb_stream_cback * @var{cback}, char * @var{format}, value * @var{values}, int @var{n_values})@* -(printf_command) -@end deftypefun - - -@deftypefun int gdb_value_print (struct gdb_stream_cback * @var{cback}, @var{value}, int @var{format}, enum @var{val_prettyprint}) -Print the value @var{val} in C-ish syntax on @var{stream}. -@var{format} is a format-letter, or 0 for print in natural format of data type. -If the object printed is a string pointer, returns -the number of string bytes printed. -[[[implementation: watch the change in argument order]]]@* -(value_print) -@end deftypefun - - - -- IDIOM: This prints the values of all convenience variables: -@example -for (var = internalvars; var; var = var->next) -@{ -printf_filtered ("$%s = ", var->name); -value_print (var->value, stdout, 0, Val_pretty_default); -printf_filtered ("\n"); -@} -@end example - - -@deftypefun int gdb_print_insn (struct gdb_stream_cback * @var{cback}, CORE_ADDR @var{memaddr}) -Print the instruction at @var{memaddr} and return the -length of the instruction in bytes.@* -(print_insn) -@end deftypefun - - -@deftypefun void gdb_print_address (struct gdb_stream_cback * @var{cback}, CORE_ADDR @var{addr}) -Print address @var{addr} symbolically on @var{stream}. -First print it as a number. Then perhaps print -@code{} after the number.@* -(print_address) -@end deftypefun - - - -- IDIOM: This is the core of a dissasemble command: -@example -for (pc = low; pc < high; ) -@{ - print_address (pc, stdout); - printf_filtered (":\t"); - pc += print_insn (pc, stdout); - printf_filtered ("\n"); -@} -@end example -Advice for computing pc extents like @code{low} and @code{high} -can be found in `Symtabs' -- for example, @code{gdb_find_line_pc_range}.@* -(disassemble_command) - - -@deftypefun void gdb_print_registers (struct gdb_stream_cback * @var{cback}, int @var{regnum}, int @var{fpregs}, int @var{fancy}) -Print the values of registers. -@var{regnum} can be -1 (print all the registers) or a specific register number. -If @var{regnum} is -1, @var{fpregs} determines whether floating point registers are -shown.@* -(info registers, info all-registers, nofp_registers_info, all_registers_info) -@end deftypefun - - -@deftypefun char * gdb_register_name (int @var{i}) -Look up a register name by number. -@end deftypefun - - -@deftypefun int gdb_parse_register_name (char ** @var{name}) -Parse a register name and advance a text pointer. -Return -1 for bogus names. -@end deftypefun - - -@deftypefun CORE_ADDR gdb_read_pc () -Return the contents of the inferior's program counter. -@end deftypefun - - -@deftypefun int gdb_is_stepping () -If true, the inferior is stopped after being stepped. -@end deftypefun - - -@deftypefun void gdb_current_breakpoints (gdb_int_cback) -Call a callback for each of the current breakpoints.@* -(program_info) -@end deftypefun - - -@deftypefun int gdb_stop_signal () -Return the signal that stopped the inferior. -@end deftypefun - - -@deftypefun char * strsigno (int) -Return a symbolic name for a signal. -@end deftypefun - - -@deftypefun void gdb_target_info (struct gdb_stream_cback *) -Print status information about target we're accessing.@* -(target_files_info, e.g. child_files_info) -@end deftypefun - - -float_info -[[[what is appropriate?]]] - - -@deftypefun void gdb_address_info (struct gdb_stream_cback * @var{cback}, char * @var{symbol}); -Like the `info address' command -- show where @var{symbol} -is located.@* -(address_info) -@end deftypefun - - -@node Types, top, Examining, top -@comment node-name, next, previous, up -@chapter Examining the Types of an Inferior's Data -@cindex types - - -@deftp Type {struct type} -@code{struct type *} is used to represent a type. For example, that is -the type returned by the macro @code{VALUE_TYPE(val)} which yields the -type of inferior data recorded in @code{val}. (see `evaluate_type' in -`Expressions'). -@end deftp - - -@deftypefun void type_print (@var{type}, @var{varstring}, @var{stream_cback}, @var{show}) -@example -struct type @var{*type}; -char @var{*varstring}; -struct gdb_stream_cback * @var{stream_cback}; -FILE @var{*stream}; -int @var{show}; -@end example -Print a description of a type @var{type} in the form of a declaration of a -variable named @var{varstring}. (@var{varstring} is demangled if necessary.) -Output goes to @var{stream_cback}. - -If @var{show} is positive, we show the contents of the outermost level -of structure even if there is a type name that could be used instead. -If @var{show} is negative, we never show the details of elements' types. -(See `Basics' for an explanation of `struct gdb_stream_cback'). -@end deftypefun - - -[[[In the long run, we need something to programmaticly read off type - structures in a machine/language independent way.]]] - -@bye diff --git a/gnu/usr.bin/gdb/doc/lpsrc.sed b/gnu/usr.bin/gdb/doc/lpsrc.sed deleted file mode 100644 index 1c7af4a..0000000 --- a/gnu/usr.bin/gdb/doc/lpsrc.sed +++ /dev/null @@ -1,13 +0,0 @@ -/font defs: ---/,/end font defs ---/c\ -%-------------------- PostScript (long names) font defs: -----------------\ -\\font\\bbf=Times-Bold at 10pt\ -\\font\\vbbf=Times-Bold at 12pt\ -\\font\\smrm=Times-Roman at 6pt\ -\\font\\brm=Times-Roman at 10pt\ -\\font\\rm=Times-Roman at 8pt\ -\\font\\it=Times-Italic at 8pt\ -\\font\\tt=Courier at 8pt\ -% Used only for \copyright, replacing plain TeX macro.\ -\\font\\sym=Symbol at 7pt\ -\\def\\copyright{{\\sym\\char'323}}\ -%-------------------- end font defs --------------------------------- diff --git a/gnu/usr.bin/gdb/doc/psrc.sed b/gnu/usr.bin/gdb/doc/psrc.sed deleted file mode 100644 index 9bb557e..0000000 --- a/gnu/usr.bin/gdb/doc/psrc.sed +++ /dev/null @@ -1,13 +0,0 @@ -/font defs: ---/,/end font defs ---/c\ -%-------------------- PostScript (K Berry names) font defs: --------------\ -\\font\\bbf=ptmb at 10pt\ -\\font\\vbbf=ptmb at 12pt\ -\\font\\smrm=ptmr at 6pt\ -\\font\\brm=ptmr at 10pt\ -\\font\\rm=ptmr at 8pt\ -\\font\\it=ptmri at 8pt\ -\\font\\tt=pcrr at 8pt\ -% Used only for \copyright, replacing plain TeX macro.\ -\\font\\sym=psyr at 7pt\ -\\def\\copyright{{\\sym\\char'323}}\ -%-------------------- end font defs --------------------------------- diff --git a/gnu/usr.bin/gdb/doc/refcard.ps b/gnu/usr.bin/gdb/doc/refcard.ps deleted file mode 100644 index 0046b79..0000000 --- a/gnu/usr.bin/gdb/doc/refcard.ps +++ /dev/null @@ -1,798 +0,0 @@ -%!PS-Adobe-2.0 -%%Creator: dvips 5.47 Copyright 1986-91 Radical Eye Software -%%Title: refcard.dvi -%%Pages: 2 1 -%%BoundingBox: 0 0 612 792 -%%EndComments -%%BeginProcSet: tex.pro -/TeXDict 200 dict def TeXDict begin /N /def load def /B{bind def}N /S /exch -load def /X{S N}B /TR /translate load N /isls false N /vsize 10 N /@rigin{ -isls{[0 1 -1 0 0 0]concat}if 72 Resolution div 72 VResolution div neg scale -Resolution VResolution vsize neg mul TR matrix currentmatrix dup dup 4 get -round 4 exch put dup dup 5 get round 5 exch put setmatrix}N /@letter{/vsize 10 -N}B /@landscape{/isls true N /vsize -1 N}B /@a4{/vsize 10.6929133858 N}B /@a3{ -/vsize 15.5531 N}B /@ledger{/vsize 16 N}B /@legal{/vsize 13 N}B /@manualfeed{ -statusdict /manualfeed true put}B /@copies{/#copies X}B /FMat[1 0 0 -1 0 0]N -/FBB[0 0 0 0]N /nn 0 N /IE 0 N /ctr 0 N /df-tail{/nn 8 dict N nn begin -/FontType 3 N /FontMatrix fntrx N /FontBBox FBB N string /base X array -/BitMaps X /BuildChar{CharBuilder}N /Encoding IE N end dup{/foo setfont}2 -array copy cvx N load 0 nn put /ctr 0 N[}B /df{/sf 1 N /fntrx FMat N df-tail} -B /dfs{div /sf X /fntrx[sf 0 0 sf neg 0 0]N df-tail}B /E{pop nn dup definefont -setfont}B /ch-width{ch-data dup length 5 sub get}B /ch-height{ch-data dup -length 4 sub get}B /ch-xoff{128 ch-data dup length 3 sub get sub}B /ch-yoff{ -ch-data dup length 2 sub get 127 sub}B /ch-dx{ch-data dup length 1 sub get}B -/ch-image{ch-data dup type /stringtype ne{ctr get /ctr ctr 1 add N}if}B /id 0 -N /rw 0 N /rc 0 N /gp 0 N /cp 0 N /G 0 N /sf 0 N /CharBuilder{save 3 1 roll S -dup /base get 2 index get S /BitMaps get S get /ch-data X pop /ctr 0 N ch-dx 0 -ch-xoff ch-yoff ch-height sub ch-xoff ch-width add ch-yoff setcachedevice -ch-width ch-height true[1 0 0 -1 -.1 ch-xoff sub ch-yoff .1 add]{ch-image} -imagemask restore}B /D{/cc X dup type /stringtype ne{]}if nn /base get cc ctr -put nn /BitMaps get S ctr S sf 1 ne{dup dup length 1 sub dup 2 index S get sf -div put}if put /ctr ctr 1 add N}B /I{cc 1 add D}B /bop{userdict /bop-hook -known{bop-hook}if /SI save N @rigin 0 0 moveto}N /eop{clear SI restore -showpage userdict /eop-hook known{eop-hook}if}N /@start{userdict /start-hook -known{start-hook}if /VResolution X /Resolution X 1000 div /DVImag X /IE 256 -array N 0 1 255{IE S 1 string dup 0 3 index put cvn put}for}N /p /show load N -/RMat[1 0 0 -1 0 0]N /BDot 260 string N /rulex 0 N /ruley 0 N /v{/ruley X -/rulex X V}B /V statusdict begin /product where{pop product dup length 7 ge{0 -7 getinterval(Display)eq}{pop false}ifelse}{false}ifelse end{{gsave TR -.1 -.1 -TR 1 1 scale rulex ruley false RMat{BDot}imagemask grestore}}{{gsave TR -.1 --.1 TR rulex ruley scale 1 1 false RMat{BDot}imagemask grestore}}ifelse B /a{ -moveto}B /delta 0 N /tail{dup /delta X 0 rmoveto}B /M{S p delta add tail}B /b{ -S p tail}B /c{-4 M}B /d{-3 M}B /e{-2 M}B /f{-1 M}B /g{0 M}B /h{1 M}B /i{2 M}B -/j{3 M}B /k{4 M}B /w{0 rmoveto}B /l{p -4 w}B /m{p -3 w}B /n{p -2 w}B /o{p -1 w -}B /q{p 1 w}B /r{p 2 w}B /s{p 3 w}B /t{p 4 w}B /x{0 S rmoveto}B /y{3 2 roll p -a}B /bos{/SS save N}B /eos{clear SS restore}B end -%%EndProcSet -TeXDict begin 1000 300 300 @start /Fa 3 104 df<0003FE0000000FFF8000003C01E000 -00F000780001C0001C00030000060006000003000C0000018018000000C018000000C030000000 -603000000060600000003060000000306000000030C000000018C000000018C000000018C00000 -0018C000000018C000000018C000000018C000000018C000000018600000003060000000306000 -0000303000000060300000006018000000C018000000C00C000001800600000300030000060001 -C0001C0000F0007800003C01E000000FFF80000003FE000025277E9D2A>13 -D<003C00E001C00180038003800380038003800380038003800380038003800380038003000700 -1C00F0001C00070003000380038003800380038003800380038003800380038003800380018001 -C000E0003C0E297D9E15>102 DI E /Fb 1 59 -df<60F0F06004047C830C>58 D E /Fc 61 125 df<01F8000604000C0E00180E001800001800 -00180000FFFE001806001806001806001806001806001806001806001806001806001806001806 -007E1F801114809313>12 D<01FE00060E000C0E00180600180600180600180600FFFE00180600 -1806001806001806001806001806001806001806001806001806001806007E1F801114809313> -I<4100E380618020802080208041004100820009097F9311>34 D<020002000F8032406220C210 -C270C270E220F2007F003FC00FE002E002704230E230C2308220426022C01F00020002000C187E -9511>36 D<40E06020202040408003097D9309>39 D<01020408103020606040C0C0C0C0C0C0C0 -C0C0C040606020301008040201081E7E950D>I<80402010080C04060602030303030303030303 -03020606040C0810204080081E7E950D>I<006000006000006000006000006000006000006000 -006000006000006000FFFFF0FFFFF0006000006000006000006000006000006000006000006000 -00600000600014167E9119>43 D<40E06020202040408003097D8209>II<40 -E04003037D8209>I<0010003000600060006000C000C000C00180018003000300030006000600 -06000C000C000C0018001800300030003000600060006000C000C0000C1D7E9511>I<0F0030C0 -606060604020C030C030C030C030C030C030C030C030C03040206060606030C00F000C137E9211 ->I<0C001C00EC000C000C000C000C000C000C000C000C000C000C000C000C000C000C000C00FF -C00A137D9211>I<1F0060C06060F070F030603000700070006000C001C0018002000400081010 -1020207FE0FFE00C137E9211>I<40E0400000000000000040E040030D7D8C09>58 -D<40E0400000000000000040E06020202040408003137D8C09>I<003000003000007800007800 -007800009C00009C00011E00010E00010E0002070002070004038007FF800403800801C00801C0 -1000E03800E0FE07FC16147F9319>65 DI<00FC200703600C00E0180060300060700020600020E00000E00000E00000E00000 -E00000E000006000207000203000201800400C008007030000FC0013147E9318>III<00FC200703600C00E0180060300060700020600020E00000E00000 -E00000E00000E00FF8E000E06000E07000E03000E01800E00C00E007036000FC2015147E931A> -71 D76 -DII<01 -F800070E001C03803801C03000C07000E0600060E00070E00070E00070E00070E00070E0007070 -00E07000E03000C03801C01C0380070E0001F80014147E9319>II82 D<7FFFF0607030407010407010807008807008807008007000007000007000007000 -00700000700000700000700000700000700000700000700007FF0015147F9318>84 -DI87 -D89 D<208041004100820082 -008200C300E380410009097A9311>92 D<7F00E1C0E0404060006007E038606060C060C064C064 -61E43E380E0D7E8C11>97 DI<0FE0187020706020C000C000C000C000C00060 -00201018200FC00C0D7F8C0F>I<00780018001800180018001800180F98187820386018C018C0 -18C018C018C0186018203810580F9E0F147F9312>I<0F80104020206030C010FFF0C000C000C0 -006000201018200FC00C0D7F8C0F>I<03C00CE018E01840180018001800FF0018001800180018 -0018001800180018001800180018007F000B1480930A>I<0F3C30E62040606060606060204030 -C02F00600060003FE03FF06018C00CC00CC00C601830300FC00F147F8C11>I -I<2070200000000000F03030303030303030303030FC06157F9409>I<02070200000000000F03 -0303030303030303030303030343E2E67C081B82940A>IIIII<0FC0186020106018C00CC00CC00CC00CC00C -6018601838700FC00E0D7F8C11>II<0F88184820386018C018C018C018C018C018 -6018203818580F9800180018001800180018007E0F137F8C11>II<3E806180C080C080E0007E003F8003C080C0 -80C0C0C0E1809F000A0D7F8C0D>I<10001000100030007000FF80300030003000300030003000 -300030803080308011000E0009127F910D>IIIIIII124 D E /Fd 2 94 df91 -D93 D E /Fe 27 123 df<001F8F000020D9800060990000C0300000C03000 -00C0300000C0300007FFFE000180300001806000018060000180600001806000030060000300C0 -000300C0000300C0000300C0000600C00006018000060180000601800004010000CCC30000C8C6 -000070780000191A819315>11 D<000FF000301800601000600000C00000C00000C00007FFE000 -C0600180600180C00180C00180C00180C00181800301900301900301900301A00300E006000006 -0000060000C40000C80000700000151A819314>I45 -D<000080000180000300000300000600000600000C000018000018000030000030000060000060 -0000C0000180000180000300000300000600000C00000C00001800001800003000003000006000 -00C00000C00000800000111D7E9512>47 D<07C03F8000C00C0001600800016008000120080001 -300800023010000218100002181000020C1000040C200004042000040620000402200008034000 -080340000801C0000801C00018008000FE00800019147E9319>78 D<07B00C7010703060606060 -606060C0C0C0C8C0C841C862D03C700D0D7C8C12>97 D<7C000C00180018001800180030003700 -388030C060C060C060C060C0C180C180C1004300660038000A147C9310>I<07800C4010603040 -600060006000C000C0004020404021801E000B0D7C8C10>I<007C000C00180018001800180030 -07B00C7010703060606060606060C0C0C0C8C0C841C862D03C700E147C9312>I<07800C401020 -304060407F8060004000C0004020604021801E000B0D7C8C10>I<001C00660064006000C000C0 -00C007F800C001800180018001800180030003000300030003000200060006000600C400C80070 -000F1A81930B>I<01D8023804380C3018301830183030603060306010E019C00EC000C000C001 -80C180C3007C000D137E8C10>I<3E0006000C000C000C000C00180019E01E3018303830303030 -3030306060606460C460C4C0C8C0700E147D9312>I<02060000000000384C4C8C981818303262 -62643807147D930B>I<7C0C181818183030303060606060C0D0D0D0D06006147C9309>108 -D<30F878590D8C4E0E0C9C0E0C980C0C180C0C180C0C3018183018193018313018316030326030 -1C180D7D8C1C>I<30F05B184C189C189818181818183030303230623062606460380F0D7D8C13> -I<03800C6018203030603060306030C060C06040C0608023001E000C0D7C8C12>I<0C78168C13 -0426062606060606060C0C0C0C0C080C101A2019C018001800300030003000FC000F137F8C12> -I<31F05A184C109C009800180018003000300030003000600060000D0D7D8C0F>114 -D<0700188018C0308038001E001F0003800180C180810082007C000A0D7D8C0E>I<04000C000C -000C001800FF8018001800300030003000300060006100610062006400380009127D910C>I<38 -184C184C188C3098301830183030603064306430E411E80E380E0D7D8C12>I<38104C384C108C -10981018101810302030203040304018800F000D0D7D8C10>I<071E09E311C221802180018001 -800300030403044308C51078E0100D7F8C10>120 D<38184C184C188C30983018301830306030 -60306030E011C00EC000C000802180630046003C000D137D8C11>I<06100F2010E00040008001 -0002000C00102020203840478083000C0D7E8C0E>I E /Ff 55 123 df<0100030003000F803F -E073704338C338C338C31073007F003FC00FE003F003384318E318E318E33073603FC00F800300 -030001000D1A7E9612>36 D<07001F8019C039C039C039C039BE3B3E3E701C701C701CE03EE06F -E0E7C0E3C4E38E63CE7EFC3C380F147F9312>38 D<070007000700E738FFF87FF01FC01FC07FF0 -FFF8E7380700070007000D0E7E9012>42 D<038003800380038003800380FFFEFFFEFFFE038003 -8003800380038003800F0F7F9112>I<60F0F878183030E0C00509798312>II<60F0F0600404798312>I<0018003800380070007000E000E001C001C001C003800380 -070007000E000E001C001C001C003800380070007000E000E000C0000D1A7E9612>I<07C00FE0 -1C703838701C701CE00EE00EE00EE00EE00EE00EE00EE01E701C701C38381C700FE007C00F147F -9312>I<0F803FC070E0E070E038E038403800380030007000E000C00180030006000C00183830 -387FF87FF80D147E9312>50 D<0FE03FF07838701C201C001C0038007807E007F00038001C000E -000E400EE00EE01C78383FF00FC00F147F9312>I55 -D<60F0F06000000000000060F0F060040E798D12>58 D<0038007801F003E00F801F003C00F800 -F000F8003C001F000F8003E001F0007800380D117E9212>60 DI<4000E000F0007C003E000F8007C001E000F8007800F801E007C00F -803E007C00F000E00040000D137E9312>I<03E007F01E18381C30FC71FE739EE30EE70EE70EE7 -0EE70EE30C739C71F830F038001E0E07FE03F80F147F9312>64 D<03E60FFE1C3E381E700E700E -600EE000E000E000E000E000E000600E700E700E381C1C380FF003E00F147F9312>67 -D69 DI73 D77 -DI<3FE07FF07070E038E038E038E038E038E038E038E038E038E038E038E038 -E038E03870707FF03FE00D147E9312>II82 -D<1F303FF070F0E070E070E070E00070007F003FC00FE000F0003800386038E038E030F070FFE0 -CF800D147E9312>I<7FFEFFFEE38EE38EE38E0380038003800380038003800380038003800380 -0380038003801FF01FF00F147F9312>II<3F807FC070E0207000700FF03FF07870E070E070E07070F03FFE1F3E0F0E7E8D12> -97 DI<07F01FF8383870106000E000E000E000E0006000703838381FF007E0 -0D0E7E8D12>I<00F800F8003800380038003807B81FF8387870386038E038E038E038E0386038 -707838781FFE0FBE0F147F9312>I<07801FE0387070706038E038FFF8FFF8E000600070383838 -1FF007C00D0E7E8D12>I<007E00FF01C70382038003807FFEFFFE038003800380038003800380 -03800380038003803FF83FF81014809312>I<0F9E1FFF38E7707070707070707038E03FC03F80 -70003FE03FF83FFC701EE00EE00EE00E600C783C1FF00FE010167F8D12>II< -06000F000F000600000000000000FF00FF000700070007000700070007000700070007000700FF -F0FFF00C157D9412>I<00C001E001E000C00000000000001FE01FE000E000E000E000E000E000 -E000E000E000E000E000E000E000E000E000E040C0E1C0FF807E000B1C7E9412>IIIII<0F803FE038E07070E038E038E038E038E038F0787070 -38E03FE00F800D0E7E8D12>II<079C1FFC387C703C601CE01CE01CE01C -E01C601C703C387C1FFC079C001C001C001C001C001C007F007F10157F8D12>II<1FF03FF06070C070E000 -7F003FE00FF000786018E018F030FFE0DFC00D0E7E8D12>I<06000E000E000E007FF8FFF80E00 -0E000E000E000E000E000E000E380E380E3807F003C00D127F9112>IIII<7C7C7C7C1CF00EE00FC007C00380078007C00EE01EF0 -1C70FC7EFC7E0F0E7F8D12>II<3FFC7FFC7038707000E001C003800700 -0E001C1C381C701CFFFCFFFC0E0E7F8D12>I E /Fg 35 122 df<00038000000380000007C000 -0007C0000007C000000FE000000FE000001FF000001BF000001BF0000031F8000031F8000061FC -000060FC0000E0FE0000C07E0000C07E0001803F0001FFFF0003FFFF8003001F8003001F800600 -0FC006000FC00E000FE00C0007E0FFC07FFEFFC07FFE1F1C7E9B24>65 DI<001FE02000FFF8 -E003F80FE007C003E00F8001E01F0000E03E0000E03E0000607E0000607C000060FC000000FC00 -0000FC000000FC000000FC000000FC000000FC000000FC0000007C0000607E0000603E0000603E -0000C01F0000C00F80018007C0030003F80E0000FFFC00001FE0001B1C7D9B22>III -I<000FF008007FFE3801FC07F807E001F80F8000781F0000783F0000383E0000387E0000187C00 -0018FC000000FC000000FC000000FC000000FC000000FC000000FC007FFFFC007FFF7C0001F87E -0001F83E0001F83F0001F81F0001F80F8001F807E001F801FC07F8007FFE78000FF818201C7D9B -26>II76 D78 D80 D<07F8201FFEE03C07E07801E07000 -E0F000E0F00060F00060F80000FE0000FFE0007FFE003FFF003FFF800FFFC007FFE0007FE00003 -F00001F00000F0C000F0C000F0C000E0E000E0F001C0FC03C0EFFF0083FC00141C7D9B1B>83 -D<7FFFFFE07FFFFFE0781F81E0701F80E0601F8060E01F8070C01F8030C01F8030C01F8030C01F -8030001F8000001F8000001F8000001F8000001F8000001F8000001F8000001F8000001F800000 -1F8000001F8000001F8000001F8000001F8000001F8000001F800007FFFE0007FFFE001C1C7E9B -21>II87 D<0FF8001C1E003E0F803E07803E07 -C01C07C00007C0007FC007E7C01F07C03C07C07C07C0F807C0F807C0F807C0780BC03E13F80FE1 -F815127F9117>97 DI<03FC000E0E001C1F003C1F00781F -00780E00F80000F80000F80000F80000F80000F800007800007801803C01801C03000E0E0003F8 -0011127E9115>I<000FF0000FF00001F00001F00001F00001F00001F00001F00001F00001F000 -01F001F9F00F07F01C03F03C01F07801F07801F0F801F0F801F0F801F0F801F0F801F0F801F078 -01F07801F03C01F01C03F00F0FFE03F9FE171D7E9C1B>I<01FC000F07001C03803C01C07801C0 -7801E0F801E0F801E0FFFFE0F80000F80000F800007800007C00603C00601E00C00F038001FC00 -13127F9116>I<03F8F00E0F381E0F381C07303C07803C07803C07803C07801C07001E0F000E0E -001BF8001000001800001800001FFF001FFFC00FFFE01FFFF07801F8F00078F00078F000787000 -707800F01E03C007FF00151B7F9118>103 DI<1E003F00 -3F003F003F001E00000000000000000000000000FF00FF001F001F001F001F001F001F001F001F -001F001F001F001F001F001F00FFE0FFE00B1E7F9D0E>I -107 DIII<01FC000F07801C01 -C03C01E07800F07800F0F800F8F800F8F800F8F800F8F800F8F800F87800F07800F03C01E01E03 -C00F078001FC0015127F9118>II114 D<1FD830786018E018E018F000FF807FE07FF01FF807FC007CC01CC01CE01CE018F8 -30CFC00E127E9113>I<0300030003000300070007000F000F003FFCFFFC1F001F001F001F001F -001F001F001F001F001F0C1F0C1F0C1F0C0F08079803F00E1A7F9913>II120 -DI E /Fh 47 122 df<020408103020604040C0C0C0C0C0C0C0C0404060203010 -080402071A7F920C>40 D<8040201018080C0404060606060606060604040C081810204080071A -7E920C>I<40E060202040408003087E8209>44 D<40E04003037E8209>46 -D<0C003C00CC000C000C000C000C000C000C000C000C000C000C000C000C00FF8009107E8F0F> -49 D<1F00618040C08060C0600060006000C00180030006000C00102020207FC0FFC00B107F8F -0F>I<1F00218060C060C000C0008001800F00008000400060C060C060804060801F000B107F8F -0F>I<0300030007000F000B001300330023004300C300FFE003000300030003001FE00B107F8F -0F>I<1F00318060C0C040C060C060C06040E021E01E600060004060C0608043003E000B107F8F -0F>57 D<40E040000000000040E060202040408003107E8A09>59 D<03E0000C180010040023C2 -004631004C0D00980C80980C80980C80980C80980C804C0C80463C8023C7001000000C038003FC -0011117E9017>64 D66 D<03F10C0B1807300360014001C000C000C000C000C0004001600130 -0218020C0C03F010117E9016>II70 -D<03F1000C0B00180700300300600100400100C00000C00000C00000C03FC0C003004003006003 -003003001803000C070003F90012117E9017>I73 D76 D78 D80 -D82 D<1F2060E0006080208020800060003E001F80 -00C00060002080208020C040E0C09F000B117E9011>I<7FFF8060C18040C080C0C0C080C04080 -C04000C00000C00000C00000C00000C00000C00000C00000C00000C00000C0000FFC0012117F90 -16>III<3E006300018001800F8031804180C190C19063903DE00C0B7F8A0F>97 -DI<1F8030C06000C000C000C000C000C000604030801F000A0B7F8A0E>I<01E0006000600060 -006000600F6030E06060C060C060C060C060C060606030E01F780D117F9011>I<1F00318060C0 -C0C0FFC0C000C000C000604030801F000A0B7F8A0E>I<07000D801800180018001800FE001800 -180018001800180018001800180018007E00091180900A>I<1EF0331061806180618033003E00 -400060003F803FC060E0C060C060C06060C01F000C117F8A0F>II<30703000000000F03030 -30303030303030FC0612809108>I107 DIII<1F00318060C0 -C060C060C060C060C06060C031801F000B0B7F8A0F>II114 D<3E028280783E038181C2BC080B7F8A0C>I<10103030FE3030 -303030323232321C070F7F8E0C>IIII121 -D E /Fi 12 86 df66 -D<0003FE0080001FFF818000FF01E38001F8003F8003E0001F8007C0000F800F800007801F8000 -07803F000003803F000003807F000001807E000001807E00000180FE00000000FE00000000FE00 -000000FE00000000FE00000000FE00000000FE00000000FE000000007E000000007E000001807F -000001803F000001803F000003801F800003000F8000030007C000060003F0000C0001F8003800 -00FF00F000001FFFC0000003FE000021227DA128>IIII<0003FE0040001FFFC0C0007F00F1C001F8003FC003F0 -000FC007C00007C00FC00003C01F800003C03F000001C03F000001C07F000000C07E000000C07E -000000C0FE00000000FE00000000FE00000000FE00000000FE00000000FE00000000FE00000000 -FE000FFFFC7E000FFFFC7F00001FC07F00001FC03F00001FC03F00001FC01F80001FC00FC0001F -C007E0001FC003F0001FC001FC003FC0007F80E7C0001FFFC3C00003FF00C026227DA12C>I73 -D75 D78 D<0007FC0000003FFF800000FC07E00003F001F80007E000FC000FC0007E001F8000 -3F001F80003F003F00001F803F00001F807F00001FC07E00000FC07E00000FC0FE00000FE0FE00 -000FE0FE00000FE0FE00000FE0FE00000FE0FE00000FE0FE00000FE0FE00000FE0FE00000FE07E -00000FC07F00001FC07F00001FC03F00001F803F81F03F801F83F83F000FC70C7E0007E606FC00 -03F607F80000FF07E000003FFF80000007FF80200000038020000001C020000001E0E0000001FF -E0000001FFC0000000FFC0000000FFC00000007F800000007F000000001E00232C7DA12A>81 -DI85 D E end -%%EndProlog -%%BeginSetup -%%Feature: *Resolution 300 -TeXDict begin @landscape -%%EndSetup -%%Page: 1 1 -bop -225 -183 a Fi(GDB)14 b(QUICK)g(REFERENCE)22 b Fh(GDB)14 -b(V)n(ersion)h(4)-225 -91 y Fg(Essen)o(tial)c(Commands)-225 --45 y Ff(gdb)i Fe(pr)n(o)n(gr)n(am)f Fd([)p Fe(c)n(or)n(e)p -Fd(])24 b Fc(debug)14 b Fe(pr)n(o)n(gr)n(am)e Fd([)p Fc(using)i(coredump)g -Fe(c)n(or)n(e)p Fd(])-225 9 y Ff(b)f Fd([)p Fe(\014le)p Ff(:)p -Fd(])p Fe(function)68 b Fc(set)13 b(breakp)q(oin)o(t)i(at)e -Fe(function)g Fd([)p Fc(in)h Fe(\014le)p Fd(])-225 63 y Ff(run)f -Fd([)p Fe(ar)n(glist)p Fd(])126 b Fc(start)13 b(y)o(our)h(program)f -Fd([)p Fc(with)h Fe(ar)n(glist)p Fd(])-225 106 y Ff(bt)274 -b Fc(bac)o(ktrace:)20 b(displa)o(y)c(program)d(stac)o(k)-225 -143 y Ff(p)g Fe(expr)214 b Fc(displa)o(y)15 b(the)f(v)n(alue)h(of)e(an)h -(expression)-225 180 y Ff(c)292 b Fc(con)o(tin)o(ue)14 b(running)h(y)o(our)f -(program)-225 218 y Ff(n)292 b Fc(next)14 b(line,)h(stepping)g(o)o(v)o(er)f -(function)g(calls)-225 255 y Ff(s)292 b Fc(next)14 b(line,)h(stepping)g(in)o -(to)f(function)h(calls)-225 352 y Fg(Starting)c(GDB)-225 398 -y Ff(gdb)256 b Fc(start)13 b(GDB,)h(with)g(no)g(debugging)g(\014les)-225 -435 y Ff(gdb)f Fe(pr)n(o)n(gr)n(am)121 b Fc(b)q(egin)14 b(debugging)g -Fe(pr)n(o)n(gr)n(am)-225 472 y Ff(gdb)f Fe(pr)n(o)n(gr)n(am)f(c)n(or)n(e)48 -b Fc(debug)14 b(coredump)g Fe(c)n(or)n(e)f Fc(pro)q(duced)h(b)o(y)105 -510 y Fe(pr)n(o)n(gr)n(am)-225 548 y Ff(gdb)f(--help)135 b -Fc(describ)q(e)14 b(command)g(line)g(options)-225 647 y Fg(Stopping)c(GDB) --225 692 y Ff(quit)238 b Fc(exit)14 b(GDB;)g(also)g Ff(q)f -Fc(or)g Ff(EOF)g Fc(\(eg)g Ff(C-d)p Fc(\))-225 734 y Ff(INTERRUPT)148 -b Fc(\(eg)13 b Ff(C-c)p Fc(\))g(terminate)g(curren)o(t)h(command,)h(or)105 -771 y(send)g(to)e(running)i(pro)q(cess)-225 868 y Fg(Getting)c(Help)-225 -914 y Ff(help)238 b Fc(list)14 b(classes)g(of)g(commands)-225 -951 y Ff(help)e Fe(class)155 b Fc(one-line)14 b(descriptions)h(for)f -(commands)g(in)105 988 y Fe(class)-225 1021 y Ff(help)e Fe(c)n(ommand)83 -b Fc(describ)q(e)14 b Fe(c)n(ommand)-225 1119 y Fg(Executing)e(y)o(our)h -(Program)-225 1165 y Ff(run)g Fe(ar)n(glist)150 b Fc(start)13 -b(y)o(our)h(program)f(with)i Fe(ar)n(glist)-225 1203 y Ff(run)256 -b Fc(start)13 b(y)o(our)h(program)f(with)i(curren)o(t)f(argumen)o(t)105 -1240 y(list)-225 1273 y Ff(run)f Fb(:)7 b(:)g(:)12 b Ff(<)p -Fe(inf)h Ff(>)p Fe(outf)32 b Fc(start)13 b(y)o(our)h(program)f(with)i(input,) -g(output)105 1310 y(redirected)-225 1360 y Ff(kill)238 b Fc(kill)15 -b(running)g(program)-225 1434 y Ff(tty)e Fe(dev)193 b Fc(use)14 -b Fe(dev)f Fc(as)g(stdin)i(and)f(stdout)g(for)g(next)g Ff(run)-225 -1472 y(set)f(args)f Fe(ar)n(glist)66 b Fc(sp)q(ecify)15 b Fe(ar)n(glist)d -Fc(for)i(next)g Ff(run)-225 1509 y(set)f(args)171 b Fc(sp)q(ecify)15 -b(empt)o(y)f(argumen)o(t)g(list)-225 1546 y Ff(show)e(args)154 -b Fc(displa)o(y)15 b(argumen)o(t)f(list)-225 1621 y Ff(show)e(environment)28 -b Fc(sho)o(w)13 b(all)i(en)o(vironmen)o(t)g(v)n(ariables)-225 -1659 y Ff(show)d(env)h Fe(var)110 b Fc(sho)o(w)13 b(v)n(alue)i(of)f(en)o -(vironmen)o(t)h(v)n(ariable)f Fe(var)-225 1696 y Ff(set)f(env)g -Fe(var)f(string)28 b Fc(set)13 b(en)o(vironmen)o(t)j(v)n(ariable)e -Fe(var)-225 1733 y Ff(unset)e(env)h Fe(var)92 b Fc(remo)o(v)o(e)13 -b Fe(var)g Fc(from)h(en)o(vironmen)o(t)-225 1820 y Fg(Shell)d(Commands)-225 -1866 y Ff(cd)i Fe(dir)217 b Fc(c)o(hange)13 b(w)o(orking)h(directory)g(to)f -Fe(dir)-225 1903 y Ff(pwd)256 b Fc(Prin)o(t)15 b(w)o(orking)e(directory)-225 -1941 y Ff(make)f Fb(:)7 b(:)g(:)176 b Fc(call)14 b(\\)p Ff(make)p -Fc(")-225 1978 y Ff(shell)e Fe(cmd)146 b Fc(execute)13 b(arbitrary)h(shell)h -(command)f(string)-225 2100 y Fd([)f(])h Fh(surround)f(optional)j(argumen)o -(ts)45 b Fb(:)7 b(:)g(:)13 b Fh(sho)o(w)h(one)f(or)h(more)f(argumen)o(ts)-216 -2174 y(c)-230 2175 y Fa(\015)p Fh(1991,)h(1992)h(F)n(ree)d(Soft)o(w)o(are)h -(F)n(oundation,)h(Inc.)60 b(P)o(ermissions)15 b(on)f(bac)o(k)p -800 -217 1 9 v 800 2175 V 875 -183 a Fg(Breakp)q(oin)o(ts)d(and)j(W)l(atc)o -(hp)q(oin)o(ts)875 -132 y Ff(break)e Fd([)p Fe(\014le)p Ff(:)p -Fd(])p Fe(line)875 -86 y Ff(b)i Fd([)p Fe(\014le)p Ff(:)p Fd(])p -Fe(line)1185 -132 y Fc(set)g(breakp)q(oin)o(t)g(at)f Fe(line)h -Fc(n)o(um)o(b)q(er)h Fd([)p Fc(in)f Fe(\014le)p Fd(])1185 -94 -y Fc(eg:)33 b Ff(break)12 b(main.c:37)875 -32 y(break)g Fd([)p -Fe(\014le)p Ff(:)p Fd(])p Fe(func)57 b Fc(set)14 b(breakp)q(oin)o(t)g(at)f -Fe(func)h Fd([)p Fc(in)g Fe(\014le)p Fd(])875 11 y Ff(break)e(+)p -Fe(o\013set)875 48 y Ff(break)g(-)p Fe(o\013set)1185 11 y Fc(set)i(break)f -(at)h Fe(o\013set)f Fc(lines)i(from)f(curren)o(t)g(stop)875 -87 y Ff(break)e(*)p Fe(addr)121 b Fc(set)14 b(breakp)q(oin)o(t)g(at)f -(address)h Fe(addr)875 124 y Ff(break)220 b Fc(set)14 b(breakp)q(oin)o(t)g -(at)f(next)i(instruction)875 161 y Ff(break)d Fb(:)7 b(:)g(:)12 -b Ff(if)i Fe(expr)31 b Fc(break)14 b(conditionally)h(on)f(nonzero)f -Fe(expr)875 211 y Ff(cond)g Fe(n)h Fd([)p Fe(expr)p Fd(])103 -b Fc(new)13 b(conditional)i(expression)g(on)e(breakp)q(oin)o(t)1206 -248 y Fe(n)p Fc(;)h(mak)o(e)g(unconditional)h(if)g(no)e Fe(expr)875 -286 y Ff(tbreak)f Fb(:)7 b(:)g(:)140 b Fc(temp)q(orary)13 b(break;)i(disable) -f(when)g(reac)o(hed)875 324 y Ff(rbreak)e Fe(r)n(e)n(gex)115 -b Fc(break)14 b(on)f(all)i(functions)g(matc)o(hing)f Fe(r)n(e)n(gex)875 -361 y Ff(watch)e Fe(expr)143 b Fc(set)14 b(a)f(w)o(atc)o(hp)q(oin)o(t)h(for)f -(expression)i Fe(expr)875 398 y Ff(catch)d Fe(x)192 b Fc(break)14 -b(at)f(C++)i(handler)f(for)g(exception)g Fe(x)875 473 y Ff(info)f(break)135 -b Fc(sho)o(w)13 b(de\014ned)i(breakp)q(oin)o(ts)875 511 y Ff(info)e(watch)135 -b Fc(sho)o(w)13 b(de\014ned)i(w)o(atc)o(hp)q(oin)o(ts)875 585 -y Ff(clear)220 b Fc(delete)14 b(breakp)q(oin)o(ts)g(at)g(next)g(instruction) -875 635 y Ff(clear)e Fd([)p Fe(\014le)p Ff(:)p Fd(])p Fe(fun)73 -b Fc(delete)14 b(breakp)q(oin)o(ts)g(at)g(en)o(try)g(to)f Fe(fun)p -Fc(\(\))875 688 y Ff(clear)f Fd([)p Fe(\014le)p Ff(:)p Fd(])p -Fe(line)66 b Fc(delete)14 b(breakp)q(oin)o(ts)g(on)g(source)f(line)875 -742 y Ff(delete)f Fd([)p Fe(n)p Fd(])147 b Fc(delete)14 b(breakp)q(oin)o(ts)g -Fd([)p Fc(or)f(breakp)q(oin)o(t)i Fe(n)p Fd(])875 823 y Ff(disable)c -Fd([)p Fe(n)p Fd(])130 b Fc(disable)15 b(breakp)q(oin)o(ts)f -Fd([)p Fc(or)f(breakp)q(oin)o(t)i Fe(n)p Fd(])875 877 y Ff(enable)d -Fd([)p Fe(n)p Fd(])147 b Fc(enable)14 b(breakp)q(oin)o(ts)g -Fd([)p Fc(or)f(breakp)q(oin)o(t)i Fe(n)p Fd(])875 931 y Ff(enable)d(once)g -Fd([)p Fe(n)p Fd(])63 b Fc(enable)14 b(breakp)q(oin)o(ts)g -Fd([)p Fc(or)f(breakp)q(oin)o(t)i Fe(n)p Fd(])p Fc(;)1206 969 -y(disable)f(again)g(when)f(reac)o(hed)875 1018 y Ff(enable)f(del)h -Fd([)p Fe(n)p Fd(])80 b Fc(enable)14 b(breakp)q(oin)o(ts)g -Fd([)p Fc(or)f(breakp)q(oin)o(t)i Fe(n)p Fd(])p Fc(;)1206 1055 -y(delete)e(when)h(reac)o(hed)875 1105 y Ff(ignore)e Fe(n)i(c)n(ount)76 -b Fc(ignore)13 b(breakp)q(oin)o(t)i Fe(n)p Fc(,)f Fe(c)n(ount)g -Fc(times)875 1180 y Ff(commands)d Fe(n)946 1217 y Fd([)p Ff(silent)p -Fd(])946 1255 y Fe(c)n(ommand-list)1185 1180 y Fc(execute)i(GDB)h -Fe(c)n(ommand-list)e Fc(ev)o(ery)j(time)1206 1217 y(breakp)q(oin)o(t)f -Fe(n)g Fc(is)g(reac)o(hed.)21 b Fd([)p Ff(silent)1206 1263 -y Fc(suppresses)14 b(default)h(displa)o(y)p Fd(])875 1306 y -Ff(end)256 b Fc(end)14 b(of)g Fe(c)n(ommand-list)875 1393 y -Fg(Program)f(Stac)o(k)875 1445 y Ff(backtrace)e Fd([)p Fe(n)p -Fd(])875 1490 y Ff(bt)i Fd([)p Fe(n)p Fd(])1185 1445 y Fc(prin)o(t)i(trace)e -(of)g(all)h(frames)g(in)h(stac)o(k;)f(or)f(of)h Fe(n)1206 1482 -y Fc(frames|innermost)g(if)h Fe(n)p Ff(>0)p Fc(,)e(outermost)h(if)1206 -1519 y Fe(n)p Ff(<0)875 1563 y(frame)e Fd([)p Fe(n)p Fd(])165 -b Fc(select)13 b(frame)h(n)o(um)o(b)q(er)h Fe(n)f Fc(or)f(frame)h(at)g -(address)1206 1600 y Fe(n)p Fc(;)g(if)h(no)e Fe(n)p Fc(,)i(displa)o(y)g -(curren)o(t)f(frame)875 1639 y Ff(up)f Fe(n)242 b Fc(select)13 -b(frame)h Fe(n)g Fc(frames)g(up)875 1676 y Ff(down)f Fe(n)206 -b Fc(select)13 b(frame)h Fe(n)g Fc(frames)g(do)o(wn)875 1720 -y Ff(info)f(frame)f Fd([)p Fe(addr)p Fd(])30 b Fc(describ)q(e)14 -b(selected)g(frame,)g(or)f(frame)h(at)f Fe(addr)875 1763 y -Ff(info)g(args)153 b Fc(argumen)o(ts)14 b(of)f(selected)h(frame)875 -1800 y Ff(info)f(locals)117 b Fc(lo)q(cal)13 b(v)n(ariables)i(of)e(selected)h -(frame)875 1844 y Ff(info)f(reg)f Fd([)p Fe(rn)p Fd(])p Fb(:)7 -b(:)g(:)875 1889 y Ff(info)13 b(all-reg)e Fd([)p Fe(rn)p Fd(])1185 -1844 y Fc(register)i(v)n(alues)i Fd([)p Fc(for)e(regs)g Fe(rn)s -Fd(])g Fc(in)h(selected)1206 1881 y(frame;)g Ff(all-reg)d Fc(includes)k -(\015oating)e(p)q(oin)o(t)875 1933 y Ff(info)g(catch)135 b -Fc(exception)14 b(handlers)h(activ)o(e)e(in)i(selected)f(frame)p -1900 -217 V 1900 2175 V 1975 -183 a Fg(Execution)f(Con)o(trol)1975 --138 y Ff(continue)e Fd([)p Fe(c)n(ount)p Fd(])1975 -92 y Ff(c)j -Fd([)p Fe(c)n(ount)p Fd(])2285 -138 y Fc(con)o(tin)o(ue)g(running;)i(if)e -Fe(c)n(ount)g Fc(sp)q(eci\014ed,)g(ignore)2306 -100 y(this)g(breakp)q(oin)o -(t)h(next)f Fe(c)n(ount)g Fc(times)1975 -26 y Ff(step)f Fd([)p -Fe(c)n(ount)p Fd(])1975 20 y Ff(s)h Fd([)p Fe(c)n(ount)p Fd(])2285 --26 y Fc(execute)g(un)o(til)h(another)e(line)i(reac)o(hed;)f(rep)q(eat)2306 -12 y Fe(c)n(ount)f Fc(times)i(if)f(sp)q(eci\014ed)1975 74 y -Ff(stepi)e Fd([)p Fe(c)n(ount)p Fd(])1975 120 y Ff(si)h Fd([)p -Fe(c)n(ount)p Fd(])2285 74 y Fc(step)h(b)o(y)h(mac)o(hine)f(instructions)h -(rather)f(than)2306 111 y(source)f(lines)1975 186 y Ff(next)g -Fd([)p Fe(c)n(ount)p Fd(])1975 232 y Ff(n)h Fd([)p Fe(c)n(ount)p -Fd(])2285 186 y Fc(execute)g(next)g(line,)h(including)h(an)o(y)e(function) -2306 223 y(calls)1975 286 y Ff(nexti)e Fd([)p Fe(c)n(ount)p -Fd(])1975 331 y Ff(ni)h Fd([)p Fe(c)n(ount)p Fd(])2285 286 -y Fc(next)h(mac)o(hine)h(instruction)g(rather)e(than)2306 323 -y(source)g(line)1975 398 y Ff(until)f Fd([)p Fe(lo)n(c)n(ation)p -Fd(])67 b Fc(run)14 b(un)o(til)i(next)e(instruction)h(\(or)e -Fe(lo)n(c)n(ation)p Fc(\))1975 441 y Ff(finish)202 b Fc(run)14 -b(un)o(til)i(selected)e(stac)o(k)f(frame)h(returns)1975 484 -y Ff(return)e Fd([)p Fe(expr)p Fd(])101 b Fc(p)q(op)14 b(selected)g(stac)o(k) -f(frame)h(without)2306 522 y(executing)g Fd([)p Fc(setting)f(return)i(v)n -(alue)p Fd(])1975 566 y Ff(signal)d Fe(num)125 b Fc(resume)14 -b(execution)g(with)g(signal)h Fe(s)f Fc(\(none)f(if)i Ff(0)p -Fc(\))1975 604 y Ff(jump)e Fe(line)1975 641 y Ff(jump)g(*)p -Fe(addr)n(ess)2285 604 y Fc(resume)h(execution)g(at)g(sp)q(eci\014ed)g -Fe(line)f Fc(n)o(um)o(b)q(er)2306 641 y(or)g Fe(addr)n(ess)1975 -681 y Ff(set)g(var=)p Fe(expr)106 b Fc(ev)n(aluate)14 b Fe(expr)e -Fc(without)i(displa)o(ying)i(it;)f(use)2306 718 y(for)e(altering)h(program)f -(v)n(ariables)1975 815 y Fg(Displa)o(y)1975 867 y Ff(print)f -Fd([)p Ff(/)p Fe(f)6 b Fd(])13 b([)p Fe(expr)p Fd(])1975 913 -y Ff(p)h Fd([)p Ff(/)p Fe(f)5 b Fd(])13 b([)p Fe(expr)p Fd(])2285 -867 y Fc(sho)o(w)h(v)n(alue)g(of)g Fe(expr)e Fd([)p Fc(or)h(last)h(v)n(alue)h -Ff($)p Fd(])2306 904 y Fc(according)e(to)g(format)h Fe(f)p -Fc(:)2046 956 y Ff(x)221 b Fc(hexadecimal)2046 993 y Ff(d)g -Fc(signed)14 b(decimal)2046 1030 y Ff(u)221 b Fc(unsigned)15 -b(decimal)2046 1068 y Ff(o)221 b Fc(o)q(ctal)2046 1105 y Ff(t)g -Fc(binary)2046 1142 y Ff(a)g Fc(address,)14 b(absolute)g(and)g(relativ)o(e) -2046 1180 y Ff(c)221 b Fc(c)o(haracter)2046 1217 y Ff(f)g Fc(\015oating)13 -b(p)q(oin)o(t)1975 1266 y Ff(call)g Fd([)p Ff(/)p Fe(f)5 b -Fd(])13 b Fe(expr)89 b Fc(lik)o(e)15 b Ff(print)d Fc(but)i(do)q(es)g(not)g -(displa)o(y)h Ff(void)1975 1320 y(x)f Fd([)p Ff(/)p Fe(Nuf)5 -b Fd(])14 b Fe(expr)98 b Fc(examine)14 b(memory)g(at)g(address)g -Fe(expr)p Fc(;)f(optional)2306 1358 y(format)g(sp)q(ec)h(follo)o(ws)g(slash) -2011 1396 y Fe(N)249 b Fc(coun)o(t)14 b(of)f(ho)o(w)h(man)o(y)h(units)g(to)e -(displa)o(y)2011 1433 y Fe(u)256 b Fc(unit)15 b(size;)f(one)g(of)2356 -1471 y Ff(b)f Fc(individual)k(b)o(ytes)2356 1508 y Ff(h)c Fc(halfw)o(ords)h -(\(t)o(w)o(o)f(b)o(ytes\))2356 1545 y Ff(w)g Fc(w)o(ords)h(\(four)g(b)o -(ytes\))2356 1583 y Ff(g)f Fc(gian)o(t)h(w)o(ords)f(\(eigh)o(t)h(b)o(ytes\)) -2011 1620 y Fe(f)263 b Fc(prin)o(ting)15 b(format.)21 b(An)o(y)14 -b Ff(print)e Fc(format,)i(or)2356 1657 y Ff(s)f Fc(n)o(ull-terminated)j -(string)2356 1695 y Ff(i)d Fc(mac)o(hine)h(instructions)1975 -1738 y Ff(disassem)d Fd([)p Fe(addr)p Fd(])62 b Fc(displa)o(y)15 -b(memory)g(as)e(mac)o(hine)h(instructions)1975 1840 y Fg(Automatic)e(Displa)o -(y)1975 1891 y Ff(display)g Fd([)p Ff(/)p Fe(f)5 b Fd(])13 -b Fe(expr)36 b Fc(sho)o(w)14 b(v)n(alue)g(of)g Fe(expr)e Fc(eac)o(h)i(time)g -(program)2306 1929 y(stops)g Fd([)p Fc(according)e(to)i(format)f -Fe(f)6 b Fd(])1975 1972 y Ff(display)184 b Fc(displa)o(y)15 -b(all)g(enabled)f(expressions)h(on)f(list)1975 2014 y Ff(undisplay)d -Fe(n)118 b Fc(remo)o(v)o(e)14 b(n)o(um)o(b)q(er\(s\))h Fe(n)f -Fc(from)g(list)h(of)2306 2051 y(automatically)f(displa)o(y)o(ed)h -(expressions)1975 2091 y Ff(disable)d(disp)g Fe(n)69 b Fc(disable)15 -b(displa)o(y)g(for)f(expression\(s\))h(n)o(um)o(b)q(er)g Fe(n)1975 -2132 y Ff(enable)d(disp)g Fe(n)87 b Fc(enable)14 b(displa)o(y)h(for)f -(expression\(s\))h(n)o(um)o(b)q(er)g Fe(n)1975 2170 y Ff(info)e(display)99 -b Fc(n)o(um)o(b)q(ered)15 b(list)g(of)e(displa)o(y)j(expressions)p -eop -%%Page: 2 2 -bop -225 -183 a Fg(Expressions)-225 -138 y Fe(expr)245 b Fc(an)13 -b(expression)i(in)g(C,)f(C++,)g(or)g(Mo)q(dula-2)105 -100 y(\(including)i -(function)f(calls\),)f(or:)-225 -60 y Fe(addr)s Ff(@)p Fe(len)176 -b Fc(an)13 b(arra)o(y)h(of)f Fe(len)h Fc(elemen)o(ts)h(b)q(eginning)f(at)105 --23 y Fe(addr)-225 10 y(\014le)p Ff(::)p Fe(nm)182 b Fc(a)13 -b(v)n(ariable)h(or)g(function)h Fe(nm)e Fc(de\014ned)i(in)f -Fe(\014le)-225 59 y Fa(f)p Fe(typ)n(e)p Fa(g)p Fe(addr)138 -b Fc(read)13 b(memory)h(at)g Fe(addr)e Fc(as)h(sp)q(eci\014ed)h -Fe(typ)n(e)-225 105 y Ff($)292 b Fc(most)13 b(recen)o(t)h(displa)o(y)o(ed)i -(v)n(alue)-225 142 y Ff($)p Fe(n)273 b(n)p Fc(th)14 b(displa)o(y)o(ed)i(v)n -(alue)-225 179 y Ff($$)274 b Fc(displa)o(y)o(ed)15 b(v)n(alue)g(previous)g -(to)e($)-225 217 y Ff($$)p Fe(n)255 b(n)p Fc(th)14 b(displa)o(y)o(ed)i(v)n -(alue)e(bac)o(k)g(from)g($)-225 254 y Ff($)p -205 254 11 2 -v 292 w Fc(last)g(address)g(examined)g(with)h Ff(x)-225 291 -y($)p -205 291 V -193 291 V 292 w Fc(v)n(alue)f(at)g(address)g($)p -357 291 10 2 v -225 329 a Ff($)p Fe(var)243 b Fc(con)o(v)o(enience)14 -b(v)n(ariable;)h(assign)f(an)o(y)g(v)n(alue)-225 410 y Ff(show)e(values)g -Fd([)p Fe(n)p Fd(])63 b Fc(sho)o(w)13 b(last)h(10)f(v)n(alues)i -Fd([)p Fc(or)e(surrounding)i($)p Fe(n)p Fd(])-225 453 y Ff(show)d -(convenience)28 b Fc(displa)o(y)15 b(all)f(con)o(v)o(enience)h(v)n(ariables) --225 550 y Fg(Sym)o(b)q(ol)d(T)l(able)-225 595 y Ff(info)g(address)g -Fe(s)74 b Fc(sho)o(w)13 b(where)h(sym)o(b)q(ol)h Fe(s)f Fc(is)g(stored)-225 -645 y Ff(info)e(func)h Fd([)p Fe(r)n(e)n(gex)p Fd(])42 b Fc(sho)o(w)13 -b(names,)i(t)o(yp)q(es)f(of)g(de\014ned)g(functions)105 682 -y(\(all,)h(or)e(matc)o(hing)h Fe(r)n(e)n(gex)p Fc(\))-225 733 -y Ff(info)e(var)h Fd([)p Fe(r)n(e)n(gex)p Fd(])60 b Fc(sho)o(w)13 -b(names,)i(t)o(yp)q(es)f(of)g(global)f(v)n(ariables)i(\(all,)105 -770 y(or)f(matc)o(hing)g Fe(r)n(e)n(gex)p Fc(\))-225 821 y -Ff(whatis)e Fd([)p Fe(expr)p Fd(])-225 867 y Ff(ptype)g Fd([)p -Fe(expr)p Fd(])85 821 y Fc(sho)o(w)h(data)h(t)o(yp)q(e)g(of)g -Fe(expr)e Fd([)p Fc(or)h Ff($)p Fd(])g Fc(without)105 858 y(ev)n(aluating;)i -Ff(ptype)d Fc(giv)o(es)i(more)g(detail)-225 910 y Ff(ptype)e -Fe(typ)n(e)147 b Fc(describ)q(e)14 b(t)o(yp)q(e,)h(struct,)f(union,)h(or)f -(en)o(um)-225 1008 y Fg(GDB)f(Scripts)-225 1054 y Ff(source)f -Fe(script)104 b Fc(read,)14 b(execute)f(GDB)h(commands)g(from)g(\014le)105 -1091 y Fe(script)-225 1147 y Ff(define)e Fe(cmd)-154 1184 y(c)n(ommand-list) -85 1147 y Fc(create)g(new)i(GDB)g(command)g Fe(cmd)p Fc(;)f(execute)105 -1184 y(script)i(de\014ned)f(b)o(y)h Fe(c)n(ommand-list)-225 -1222 y Ff(end)256 b Fc(end)14 b(of)g Fe(c)n(ommand-list)-225 -1260 y Ff(document)d Fe(cmd)-154 1297 y(help-text)85 1260 y -Fc(create)h(online)j(do)q(cumen)o(tation)f(for)f(new)h(GDB)105 -1297 y(command)g Fe(cmd)-225 1335 y Ff(end)256 b Fc(end)14 -b(of)g Fe(help-text)-225 1432 y Fg(Signals)-225 1478 y Ff(handle)e -Fe(signal)h(act)44 b Fc(sp)q(ecify)15 b(GDB)e(actions)h(for)f -Fe(signal)p Fc(:)-190 1515 y Ff(print)185 b Fc(announce)13 -b(signal)-190 1553 y Ff(noprint)149 b Fc(b)q(e)13 b(silen)o(t)i(for)f(signal) --190 1590 y Ff(stop)203 b Fc(halt)14 b(execution)g(on)g(signal)-190 -1627 y Ff(nostop)167 b Fc(do)13 b(not)h(halt)g(execution)-190 -1665 y Ff(pass)203 b Fc(allo)o(w)13 b(y)o(our)h(program)f(to)h(handle)g -(signal)-190 1702 y Ff(nopass)167 b Fc(do)13 b(not)h(allo)o(w)g(y)o(our)g -(program)f(to)g(see)h(signal)-225 1739 y Ff(info)e(signals)100 -b Fc(sho)o(w)13 b(table)h(of)g(signals,)h(GDB)e(action)h(for)f(eac)o(h)-225 -1838 y Fg(Debugging)e(T)l(argets)-225 1884 y Ff(target)h Fe(typ)n(e)g(p)n(ar) -n(am)24 b Fc(connect)13 b(to)g(target)g(mac)o(hine,)i(pro)q(cess,)e(or)h -(\014le)-225 1921 y Ff(help)e(target)118 b Fc(displa)o(y)15 -b(a)o(v)n(ailable)g(targets)-225 1958 y Ff(attach)d Fe(p)n(ar)n(am)97 -b Fc(connect)13 b(to)g(another)h(pro)q(cess)-225 1996 y Ff(detach)202 -b Fc(release)13 b(target)f(from)i(GDB)g(con)o(trol)p 800 -217 -1 9 v 800 2175 V 875 -183 a Fg(Con)o(trollin)o(g)d(GDB)875 --138 y Ff(set)i Fe(p)n(ar)n(am)f(value)61 b Fc(set)14 b(one)f(of)h(GDB's)g -(in)o(ternal)h(parameters)875 -100 y Ff(show)e Fe(p)n(ar)n(am)132 -b Fc(displa)o(y)15 b(curren)o(t)f(setting)g(of)g(parameter)875 --51 y(P)o(arameters)f(understo)q(o)q(d)h(b)o(y)h Ff(set)e Fc(and)h -Ff(show)p Fc(:)910 -13 y Ff(complaints)d Fe(limit)i Fc(n)o(um)o(b)q(er)i(of)e -(messages)h(on)f(un)o(usual)j(sym)o(b)q(ols)910 28 y Ff(confirm)c -Fe(on/o\013)43 b Fc(enable)14 b(or)f(disable)i(cautionary)f(queries)910 -66 y Ff(editing)e Fe(on/o\013)43 b Fc(con)o(trol)13 b Ff(readline)e -Fc(command-line)k(editing)910 103 y Ff(height)d Fe(lpp)110 -b Fc(n)o(um)o(b)q(er)15 b(of)e(lines)i(b)q(efore)f(pause)g(in)g(displa)o(y) -910 145 y Ff(language)d Fe(lang)58 b Fc(Language)12 b(for)h(GDB)h -(expressions)h(\()p Ff(auto)p Fc(,)e Ff(c)g Fc(or)1206 182 -y Ff(modula-2)p Fc(\))910 222 y Ff(listsize)e Fe(n)101 b Fc(n)o(um)o(b)q(er) -15 b(of)e(lines)i(sho)o(wn)f(b)o(y)h Ff(list)910 259 y(prompt)d -Fe(str)114 b Fc(use)14 b Fe(str)f Fc(as)g(GDB)h(prompt)910 -297 y Ff(radix)e Fe(b)n(ase)111 b Fc(o)q(ctal,)13 b(decimal,)i(or)e(hex)i(n)o -(um)o(b)q(er)1206 334 y(represen)o(tation)910 374 y Ff(verbose)d -Fe(on/o\013)43 b Fc(con)o(trol)13 b(messages)g(when)h(loading)g(sym)o(b)q -(ols)910 411 y Ff(width)e Fe(cpl)130 b Fc(n)o(um)o(b)q(er)15 -b(of)e(c)o(haracters)g(b)q(efore)h(line)g(folded)910 449 y -Ff(write)e Fe(on/o\013)79 b Fc(Allo)o(w)13 b(or)h(forbid)g(patc)o(hing)h -(binary)m(,)g(core)e(\014les)1206 486 y(\(when)g(reop)q(ened)h(with)g -Ff(exec)f Fc(or)g Ff(core)p Fc(\))910 526 y Ff(history)f Fb(:)7 -b(:)g(:)910 563 y Ff(h)14 b Fb(:)7 b(:)g(:)1185 526 y Fc(groups)14 -b(with)g(the)g(follo)o(wing)g(options:)910 598 y Ff(h)g(exp)f -Fe(o\013/on)82 b Fc(disable/enable)14 b Ff(readline)d Fc(history)k(expansion) -910 635 y Ff(h)f(file)e Fe(\014lename)33 b Fc(\014le)14 b(for)f(recording)h -(GDB)f(command)h(history)910 672 y Ff(h)g(size)e Fe(size)104 -b Fc(n)o(um)o(b)q(er)15 b(of)e(commands)h(k)o(ept)h(in)f(history)h(list)910 -710 y Ff(h)f(save)e Fe(o\013/on)65 b Fc(con)o(trol)13 b(use)h(of)g(external)g -(\014le)g(for)f(command)1206 747 y(history)910 803 y Ff(print)f -Fb(:)7 b(:)g(:)910 840 y Ff(p)14 b Fb(:)7 b(:)g(:)1185 803 -y Fc(groups)14 b(with)g(the)g(follo)o(wing)g(options:)910 882 -y Ff(p)g(address)d Fe(on/o\013)h Fc(prin)o(t)j(memory)f(addresses)g(in)g -(stac)o(ks,)h(v)n(alues)910 923 y Ff(p)f(array)e Fe(o\013/on)47 -b Fc(compact)13 b(or)g(attractiv)o(e)g(format)h(for)g(arra)o(ys)910 -965 y Ff(p)g(demangl)d Fe(on/o\013)h Fc(source)h(\(demangled\))h(or)g(in)o -(ternal)g(form)g(for)1206 1002 y(C++)g(sym)o(b)q(ols)910 1042 -y Ff(p)g(asm-dem)d Fe(on/o\013)h Fc(demangle)i(C++)g(sym)o(b)q(ols)h(in)g -(mac)o(hine-)1206 1079 y(instruction)g(output)910 1118 y Ff(p)f(elements)d -Fe(limit)17 b Fc(n)o(um)o(b)q(er)e(of)e(arra)o(y)h(elemen)o(ts)g(to)g(displa) -o(y)910 1160 y Ff(p)g(object)e Fe(on/o\013)29 b Fc(prin)o(t)15 -b(C++)f(deriv)o(ed)h(t)o(yp)q(es)g(for)e(ob)r(jects)910 1201 -y Ff(p)h(pretty)e Fe(o\013/on)29 b Fc(struct)14 b(displa)o(y:)23 -b(compact)13 b(or)g(inden)o(ted)910 1243 y Ff(p)h(union)e Fe(on/o\013)47 -b Fc(displa)o(y)15 b(of)f(union)h(mem)o(b)q(ers)910 1284 y -Ff(p)f(vtbl)e Fe(o\013/on)65 b Fc(displa)o(y)15 b(of)f(C++)h(virtual)f -(function)h(tables)875 1359 y Ff(show)e(commands)81 b Fc(sho)o(w)13 -b(last)h(10)f(commands)875 1396 y Ff(show)g(commands)e Fe(n)51 -b Fc(sho)o(w)13 b(10)g(commands)h(around)g(n)o(um)o(b)q(er)h -Fe(n)875 1434 y Ff(show)e(commands)e(+)52 b Fc(sho)o(w)13 b(next)i(10)e -(commands)875 1521 y Fg(W)l(orking)g(Files)875 1573 y Ff(file)g -Fd([)p Fe(\014le)p Fd(])156 b Fc(use)14 b Fe(\014le)f Fc(for)h(b)q(oth)g(sym) -o(b)q(ols)h(and)f(executable;)1206 1610 y(with)g(no)g(arg,)f(discard)h(b)q -(oth)875 1659 y Ff(core)f Fd([)p Fe(\014le)p Fd(])156 b Fc(read)13 -b Fe(\014le)h Fc(as)f(coredump;)i(or)e(discard)875 1713 y Ff(exec)g -Fd([)p Fe(\014le)p Fd(])156 b Fc(use)14 b Fe(\014le)f Fc(as)h(executable)g -(only;)h(or)e(discard)875 1767 y Ff(symbol)f Fd([)p Fe(\014le)p -Fd(])121 b Fc(use)14 b(sym)o(b)q(ol)h(table)f(from)g Fe(\014le)p -Fc(;)f(or)h(discard)875 1810 y Ff(load)f Fe(\014le)180 b Fc(dynamically)15 -b(link)h Fe(\014le)f Fc(and)f(add)g(its)h(sym)o(b)q(ols)875 -1848 y Ff(add-sym)c Fe(\014le)j(addr)45 b Fc(read)13 b(additional)i(sym)o(b)q -(ols)g(from)f Fe(\014le)p Fc(,)1206 1885 y(dynamically)h(loaded)f(at)f -Fe(addr)875 1923 y Ff(info)g(files)135 b Fc(displa)o(y)15 b(w)o(orking)f -(\014les)g(and)g(targets)f(in)i(use)875 1961 y Ff(path)e Fe(dirs)167 -b Fc(add)14 b Fe(dirs)f Fc(to)g(fron)o(t)h(of)g(path)g(searc)o(hed)f(for)1206 -1998 y(executable)g(and)h(sym)o(b)q(ol)h(\014les)875 2037 y -Ff(show)e(path)153 b Fc(displa)o(y)15 b(executable)f(and)g(sym)o(b)q(ol)h -(\014le)f(path)875 2074 y Ff(info)f(share)135 b Fc(list)15 -b(names)e(of)h(shared)g(libraries)h(curren)o(tly)1206 2111 -y(loaded)p 1900 -217 V 1900 2175 V 1975 -183 a Fg(Source)e(Files)1975 --138 y Ff(dir)g Fe(names)148 b Fc(add)14 b(directory)g Fe(names)f -Fc(to)h(fron)o(t)g(of)f(source)2306 -100 y(path)1975 -62 y -Ff(dir)256 b Fc(clear)13 b(source)h(path)1975 -25 y Ff(show)f(dir)171 -b Fc(sho)o(w)14 b(curren)o(t)g(source)f(path)1975 50 y Ff(list)238 -b Fc(sho)o(w)14 b(next)g(ten)g(lines)h(of)e(source)1975 87 -y Ff(list)g(-)207 b Fc(sho)o(w)14 b(previous)g(ten)g(lines)1975 -125 y Ff(list)f Fe(lines)156 b Fc(displa)o(y)15 b(source)f(surrounding)h -Fe(lines)p Fc(,)f(sp)q(eci\014ed)2306 162 y(as:)2011 206 y -Fd([)p Fe(\014le)p Ff(:)p Fd(])p Fe(num)122 b Fc(line)15 b(n)o(um)o(b)q(er)g -Fd([)p Fc(in)f(named)g(\014le)p Fd(])2011 260 y([)p Fe(\014le)p -Ff(:)p Fd(])p Fe(function)63 b Fc(b)q(eginning)15 b(of)e(function)i -Fd([)p Fc(in)f(named)g(\014le)p Fd(])2011 303 y Ff(+)p Fe(o\013)217 -b(o\013)14 b Fc(lines)h(after)e(last)h(prin)o(ted)2011 340 -y Ff(-)p Fe(o\013)217 b(o\013)14 b Fc(lines)h(previous)f(to)g(last)g(prin)o -(ted)2011 377 y Ff(*)p Fe(addr)n(ess)145 b Fc(line)15 b(con)o(taining)f -Fe(addr)n(ess)1975 415 y Ff(list)f Fe(f)p Ff(,)p Fe(l)187 b -Fc(from)14 b(line)h Fe(f)e Fc(to)g(line)i Fe(l)1975 452 y Ff(info)e(line)f -Fe(num)76 b Fc(sho)o(w)14 b(starting,)g(ending)g(addresses)g(of)2306 -489 y(compiled)g(co)q(de)f(for)h(source)f(line)i Fe(num)1975 -528 y Ff(info)e(source)117 b Fc(sho)o(w)14 b(name)f(of)h(curren)o(t)g(source) -f(\014le)1975 565 y Ff(info)g(sources)99 b Fc(list)15 b(all)f(source)f -(\014les)h(in)h(use)1975 603 y Ff(forw)e Fe(r)n(e)n(gex)150 -b Fc(searc)o(h)13 b(follo)o(wing)h(source)g(lines)h(for)e Fe(r)n(e)n(gex)1975 -640 y Ff(rev)g Fe(r)n(e)n(gex)168 b Fc(searc)o(h)13 b(preceding)h(source)g -(lines)h(for)e Fe(r)n(e)n(gex)1975 737 y Fg(GDB)g(under)f(GNU)i(Emacs)1975 -782 y Ff(M-x)f(gdb)189 b Fc(run)14 b(GDB)g(under)h(Emacs)1975 -820 y Ff(C-h)e(m)225 b Fc(describ)q(e)14 b(GDB)g(mo)q(de)1975 -857 y Ff(M-s)256 b Fc(step)14 b(one)f(line)i(\()p Ff(step)p -Fc(\))1975 899 y Ff(M-n)256 b Fc(next)14 b(line)h(\()p Ff(next)p -Fc(\))1975 936 y Ff(M-i)256 b Fc(step)14 b(one)f(instruction)i(\()p -Ff(stepi)p Fc(\))1975 978 y Ff(C-c)e(C-f)189 b Fc(\014nish)15 -b(curren)o(t)f(stac)o(k)g(frame)f(\()p Ff(finish)p Fc(\))1975 -1015 y Ff(M-c)256 b Fc(con)o(tin)o(ue)14 b(\()p Ff(cont)p Fc(\))1975 -1052 y Ff(M-u)256 b Fc(up)14 b Fe(ar)n(g)f Fc(frames)h(\()p -Ff(up)p Fc(\))1975 1094 y Ff(M-d)256 b Fc(do)o(wn)14 b Fe(ar)n(g)f -Fc(frames)h(\()p Ff(down)p Fc(\))1975 1131 y Ff(C-x)f(&)225 -b Fc(cop)o(y)14 b(n)o(um)o(b)q(er)h(from)f(p)q(oin)o(t,)h(insert)f(at)f(end) -1975 1169 y Ff(C-x)g(SPC)189 b Fc(\(in)14 b(source)g(\014le\))g(set)f(break)h -(at)g(p)q(oin)o(t)1975 1267 y Fg(GDB)f(License)1975 1313 y -Ff(show)g(copying)99 b Fc(Displa)o(y)15 b(GNU)e(General)g(Public)i(License) -1975 1350 y Ff(show)e(warranty)81 b Fc(There)13 b(is)i(NO)e(W)l(ARRANTY)g -(for)h(GDB.)2306 1387 y(Displa)o(y)h(full)g(no-w)o(arran)o(t)o(y)f(statemen)o -(t.)2024 1622 y Fh(Cop)o(yrigh)o(t)2185 1621 y(c)2171 1622 -y Fa(\015)o Fh(1991,)h(1992,)f(1993)h(F)n(ree)d(Soft)o(w)o(are)i(F)n -(oundation,)f(Inc.)2215 1660 y(Roland)i(P)o(esc)o(h)f(\(p)q(esc)o(h@cygn)o -(us.com\))1997 1697 y(The)f(author)h(assumes)f(no)h(resp)q(onsibilit)o(y)j -(for)c(an)o(y)h(errors)g(on)g(this)h(card.)1975 1759 y(This)g(card)e(ma)o(y)g -(b)q(e)g(freely)h(distributed)g(under)f(the)g(terms)g(of)g(the)h(GNU)1975 -1797 y(General)h(Public)g(License.)2012 1834 y(Please)f(con)o(tribute)g(to)g -(dev)o(elopmen)o(t)e(of)i(this)h(card)e(b)o(y)h(annotating)h(it.)1975 -1896 y(GDB)g(itself)f(is)h(free)e(soft)o(w)o(are;)g(y)o(ou)h(are)g(w)o -(elcome)e(to)i(distribute)h(copies)f(of)1975 1934 y(it)h(under)e(the)g(terms) -g(of)g(the)g(GNU)i(General)g(Public)g(License.)20 b(There)12 -b(is)1975 1971 y(absolutely)k(no)d(w)o(arran)o(t)o(y)i(for)e(GDB.)p -eop -%%Trailer -end -userdict /end-hook known{end-hook}if -%%EOF diff --git a/gnu/usr.bin/gdb/doc/refcard.tex b/gnu/usr.bin/gdb/doc/refcard.tex deleted file mode 100644 index 5899608..0000000 --- a/gnu/usr.bin/gdb/doc/refcard.tex +++ /dev/null @@ -1,646 +0,0 @@ -%%%%%%%%%%%%%%%% gdb-refcard.tex %%%%%%%%%%%%%%%% - -%This file is TeX source for a reference card describing GDB, the GNU debugger. -%$Id: refcard.tex,v 1.1.1.1 1993/10/30 21:59:42 jkh Exp $ -%Copyright (C) 1991, 1992 Free Software Foundation, Inc. -%Permission is granted to make and distribute verbatim copies of -%this reference provided the copyright notices and permission notices -%are preserved on all copies. -% -%TeX markup is a programming language; accordingly this file is source -%for a program to generate a reference. -% -%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 1, 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 can find a copy of the GNU General Public License in the GDB -%manual; or write to the Free Software Foundation, Inc., -%675 Mass Ave, Cambridge, MA 02139, USA. -% -%You can contact the author as: pesch@cygnus.com -% -% Roland Pesch -% Cygnus Support -% 1937 Landings Drive -% Mountain View, CA 94043 USA -% -% +1 415 903 1400 -% -% -% -% 22-AUG-1993 Andreas Vogel -% -% Modifications made in order to handle different papersizes correctly. -% You only have to set the total width and height of the paper, the -% horizontal and vertical margin space measured from *paper edge* -% and the interline and interspec spacing. -% In order to support a new papersize, you have to fiddle with the -% latter four dimensions. Just try out a few values. -% All other values will be computed at process time so it should be -% quite easy to support different paper sizes - only four values to -% guess :-) -% -% To find the configuration places, just search for the string -% "CONFIGURATION". -% -% Andreas Vogel (av@ssw.de) -% -% -% -% Uncomment the following `magnification' command if you want to print -% out in a larger font. Caution! You may need larger paper. You had -% best avoid using 3-column output if you try this. See the ``Three -% column format'' section below if you want to print in three column -% format. -% -%\magnification=\magstep 1 -% -% NOTE ON INTENTIONAL OMISSIONS: This reference card includes most GDB -% commands, but due to space constraints there are some things I chose -% to omit. In general, not all synonyms for commands are covered, nor -% all variations of a command. -% The GDB-under-Emacs section omits gdb-mode functions without default -% keybindings. GDB startup options are not described. -% set print sevenbit-strings, set symbol-reloading omitted. -% printsyms, printpsyms, omitted since they're for GDB maintenance primarily -% share omitted due to obsolescence -% set check range/type omitted at least til code is in GDB. -% -%-------------------- Three column format ----------------------- - -%%%% --- To disable three column format, comment out this entire section - -% Three-column format for landscape printing - -%-------- Papersize defs: - -\newdimen\totalwidth \newdimen\totalheight -\newdimen\hmargin \newdimen\vmargin -\newdimen\secskip \newdimen\lskip -\newdimen\barwidth \newdimen\barheight -\newdimen\intersecwidth - -%% -%% START CONFIGURATION - PAPERSIZE DEFINITIONS -%------- Papersize params: -%% US letter paper (8.5x11in) -%% -\totalwidth=11in % total width of paper -\totalheight=8.5in % total height of paper -\hmargin=.25in % horizontal margin width -\vmargin=.25in % vertical margin width -\secskip=1pc % space between refcard secs -\lskip=2pt % extra skip between \sec entries -%------- end papersize params -%% -%% change according to personal taste, not papersize dependent -%% -\barwidth=.1pt % width of the cropmark bar -\barheight=2pt % height of the cropmark bar -\intersecwidth=0.5em % width between \itmwid and \dfnwid -%% -%% END CONFIGURATION - PAPERSIZE DEFINITIONS -%% - -%% -%% values to be computed - nothing to configure -%% -\newdimen\fullhsize % width of area without margins -\newdimen\itmwid % width of item column -\newdimen\dfnwid % width of definition column -\newdimen\temp % only for temporary use - -%% -%% adjust the offsets so the margins are measured *from paper edge* -%% -\hoffset=-1in \advance \hoffset by \hmargin -\voffset=-1in \advance \voffset by \vmargin - -%% -%% fullhsize = totalwidth - (2 * hmargin) -%% -\fullhsize=\totalwidth -\temp=\hmargin \multiply \temp by 2 \advance \fullhsize by -\temp - -%% -%% hsize = (fullhsize - (4 * hmargin) - (2 * barwidth)) / 3 -%% -\hsize=\fullhsize -\temp=\hmargin \multiply \temp by 4 \advance \hsize by -\temp -\temp=\barwidth \multiply \temp by 2 \advance \hsize by -\temp -\divide \hsize by 3 - -%% -%% vsize = totalheight - (2 * vmargin) -%% -\vsize=\totalheight -\temp=\vmargin \multiply \temp by 2 \advance \vsize by -\temp - -%% -%% itmwid = (hsize - intersecwidth) * 1/3 -%% dfnwid = (hsize - intersecwidth) * 2/3 -%% -\temp=\hsize \advance \temp by -\intersecwidth \divide \temp by 3 -\itmwid=\temp -\dfnwid=\hsize \advance \dfnwid by -\itmwid - -%-------- end papersize defs - - -\def\fulline{\hbox to \fullhsize} -\let\lcr=L \newbox\leftcolumn\newbox\centercolumn -\output={\if L\lcr - \global\setbox\leftcolumn=\columnbox \global\let\lcr=C - \else - \if C\lcr - \global\setbox\centercolumn=\columnbox \global\let\lcr=R - \else \tripleformat \global\let\lcr=L - \fi - \fi -% \ifnum\outputpenalty>-20000 \else\dosupereject\fi - } - -%% -%% START CONFIGURATION - ALTERNATIVE FOLDING GUIDES -%% -%% For NO printed folding guide, -%% comment out other \def\vdecor's and uncomment: - -%\def\vdecor{\hskip\hmargin plus1fil\hskip\barwidth plus1fil\hskip\hmargin plus1fil} - -%% For SOLID LINE folding guide, -%% comment out other \def\vdecor's and uncomment: - -%\def\vdecor{\hskip\hmargin plus1fil \vrule width \barwidth \hskip\hmargin plus1fil} - -%% For SMALL MARKS NEAR TOP AND BOTTOM as folding guide, -%% comment out other \def\vdecor's and uncomment: - -\def\vdecor{\hskip\hmargin plus1fil -\vbox to \vsize{\hbox to \barwidth{\vrule height\barheight width\barwidth}\vfill -\hbox to \barwidth{\vrule height\barheight width\barwidth}}%THIS PERCENT SIGN IS ESSENTIAL -\hskip\hmargin plus1fil} - -%% -%% END CONFIGURATION - ALTERNATIVES FOR FOLDING GUIDES -%% - -\def\tripleformat{\shipout\vbox{\fulline{\box\leftcolumn\vdecor - \box\centercolumn\vdecor - \columnbox} - } - \advancepageno} -\def\columnbox{\leftline{\pagebody}} -\def\bye{\par\vfill - \supereject - \if R\lcr \null\vfill\eject\fi - \end} - -%-------------------- end three column format ----------------------- - -%-------------------- Computer Modern font defs: -------------------- -\font\bbf=cmbx10 -\font\vbbf=cmbx12 -\font\smrm=cmr6 -\font\brm=cmr10 -\font\rm=cmr7 -\font\it=cmti7 -\font\tt=cmtt8 -%-------------------- end font defs --------------------------------- - -% -\hyphenpenalty=5000\tolerance=2000\raggedright\raggedbottom -\normalbaselineskip=9pt\baselineskip=9pt -% -\parindent=0pt -\parskip=0pt -\footline={\vbox to0pt{\hss}} -% -\def\ctl#1{{\tt C-#1}} -\def\opt#1{{\brm[{\rm #1}]}} -\def\xtra#1{\noalign{\smallskip{\tt#1}}} -% -\long\def\sec#1;#2\endsec{\vskip \secskip -\halign{% -%COL 1 (of halign): -\vtop{\hsize=\itmwid\tt -##\par\vskip \lskip }\hfil -%COL 2 (of halign): -&\vtop{\hsize=\dfnwid\hangafter=1\hangindent=\intersecwidth -\rm ##\par\vskip \lskip}\cr -%Tail of \long\def fills in halign body with \sec args: -\noalign{{\bbf #1}\vskip \lskip} -#2 -} -} - -{\vbbf GDB QUICK REFERENCE}\hfil{\smrm GDB Version 4}\qquad - -\sec Essential Commands; -gdb {\it program} \opt{{\it core}}&debug {\it program} \opt{using -coredump {\it core}}\cr -b \opt{\it file\tt:}{\it function}&set breakpoint at {\it function} \opt{in \it file}\cr -run \opt{{\it arglist}}&start your program \opt{with {\it arglist}}\cr -bt& backtrace: display program stack\cr -p {\it expr}&display the value of an expression\cr -c &continue running your program\cr -n &next line, stepping over function calls\cr -s &next line, stepping into function calls\cr -\endsec - -\sec Starting GDB; -gdb&start GDB, with no debugging files\cr -gdb {\it program}&begin debugging {\it program}\cr -gdb {\it program core}&debug coredump {\it core} produced by {\it -program}\cr -gdb --help&describe command line options\cr -\endsec - -\sec Stopping GDB; -quit&exit GDB; also {\tt q} or {\tt EOF} (eg \ctl{d})\cr -INTERRUPT&(eg \ctl{c}) terminate current command, or send to running process\cr -\endsec - -\sec Getting Help; -help&list classes of commands\cr -help {\it class}&one-line descriptions for commands in {\it class}\cr -help {\it command}&describe {\it command}\cr -\endsec - -\sec Executing your Program; -run {\it arglist}&start your program with {\it arglist}\cr -run&start your program with current argument list\cr -run $\ldots$ <{\it inf} >{\it outf}&start your program with input, output -redirected\cr -\cr -kill&kill running program\cr -\cr -tty {\it dev}&use {\it dev} as stdin and stdout for next {\tt run}\cr -set args {\it arglist}&specify {\it arglist} for next -{\tt run}\cr -set args&specify empty argument list\cr -show args&display argument list\cr -\cr -show environment&show all environment variables\cr -show env {\it var}&show value of environment variable {\it var}\cr -set env {\it var} {\it string}&set environment variable {\it var}\cr -unset env {\it var}&remove {\it var} from environment\cr -\endsec - -\sec Shell Commands; -cd {\it dir}&change working directory to {\it dir}\cr -pwd&Print working directory\cr -make $\ldots$&call ``{\tt make}''\cr -shell {\it cmd}&execute arbitrary shell command string\cr -\endsec - -\vfill -\line{\smrm \opt{ } surround optional arguments \hfill $\ldots$ show -one or more arguments} -\vskip\baselineskip -\centerline{\smrm \copyright 1991, 1992 Free Software Foundation, Inc.\qquad Permissions on back} -\eject -\sec Breakpoints and Watchpoints; -break \opt{\it file\tt:}{\it line}\par -b \opt{\it file\tt:}{\it line}&set breakpoint at {\it line} number \opt{in \it file}\par -eg:\quad{\tt break main.c:37}\quad\cr -break \opt{\it file\tt:}{\it func}&set breakpoint at {\it -func} \opt{in \it file}\cr -break +{\it offset}\par -break -{\it offset}&set break at {\it offset} lines from current stop\cr -break *{\it addr}&set breakpoint at address {\it addr}\cr -break&set breakpoint at next instruction\cr -break $\ldots$ if {\it expr}&break conditionally on nonzero {\it expr}\cr -cond {\it n} \opt{\it expr}&new conditional expression on breakpoint -{\it n}; make unconditional if no {\it expr}\cr -tbreak $\ldots$&temporary break; disable when reached\cr -rbreak {\it regex}&break on all functions matching {\it regex}\cr -watch {\it expr}&set a watchpoint for expression {\it expr}\cr -catch {\it x}&break at C++ handler for exception {\it x}\cr -\cr -info break&show defined breakpoints\cr -info watch&show defined watchpoints\cr -\cr -clear&delete breakpoints at next instruction\cr -clear \opt{\it file\tt:}{\it fun}&delete breakpoints at entry to {\it fun}()\cr -clear \opt{\it file\tt:}{\it line}&delete breakpoints on source line \cr -delete \opt{{\it n}}&delete breakpoints -\opt{or breakpoint {\it n}}\cr -\cr -disable \opt{{\it n}}&disable breakpoints -\opt{or breakpoint {\it n}} -\cr -enable \opt{{\it n}}&enable breakpoints -\opt{or breakpoint {\it n}} -\cr -enable once \opt{{\it n}}&enable breakpoints \opt{or breakpoint {\it n}}; -disable again when reached -\cr -enable del \opt{{\it n}}&enable breakpoints \opt{or breakpoint {\it n}}; -delete when reached -\cr -\cr -ignore {\it n} {\it count}&ignore breakpoint {\it n}, {\it count} -times\cr -\cr -commands {\it n}\par -\qquad \opt{\tt silent}\par -\qquad {\it command-list}&execute GDB {\it command-list} every time breakpoint {\it n} is reached. \opt{{\tt silent} suppresses default -display}\cr -end&end of {\it command-list}\cr -\endsec - -\sec Program Stack; -backtrace \opt{\it n}\par -bt \opt{\it n}&print trace of all frames in stack; or of {\it n} -frames---innermost if {\it n}{\tt >0}, outermost if {\it n}{\tt <0}\cr -frame \opt{\it n}&select frame number {\it n} or frame at address {\it -n}; if no {\it n}, display current frame\cr -up {\it n}&select frame {\it n} frames up\cr -down {\it n}&select frame {\it n} frames down\cr -info frame \opt{\it addr}&describe selected frame, or frame at -{\it addr}\cr -info args&arguments of selected frame\cr -info locals&local variables of selected frame\cr -info reg \opt{\it rn}$\ldots$\par -info all-reg \opt{\it rn}®ister values \opt{for regs {\it rn\/}} in -selected frame; {\tt all-reg} includes floating point\cr -info catch&exception handlers active in selected frame\cr -\endsec - -\vfill\eject -\sec Execution Control; -continue \opt{\it count}\par -c \opt{\it count}&continue running; if {\it count} specified, ignore -this breakpoint next {\it count} times\cr -\cr -step \opt{\it count}\par -s \opt{\it count}&execute until another line reached; repeat {\it count} times if -specified\cr -stepi \opt{\it count}\par -si \opt{\it count}&step by machine instructions rather than source -lines\cr -\cr -next \opt{\it count}\par -n \opt{\it count}&execute next line, including any function calls\cr -nexti \opt{\it count}\par -ni \opt{\it count}&next machine instruction rather than source -line\cr -\cr -until \opt{\it location}&run until next instruction (or {\it -location})\cr -finish&run until selected stack frame returns\cr -return \opt{\it expr}&pop selected stack frame without executing -\opt{setting return value}\cr -signal {\it num}&resume execution with signal {\it s} (none if {\tt 0})\cr -jump {\it line}\par -jump *{\it address}&resume execution at specified {\it line} number or -{\it address}\cr -set var={\it expr}&evaluate {\it expr} without displaying it; use for -altering program variables\cr -\endsec - -\sec Display; -print \opt{\tt/{\it f}\/} \opt{\it expr}\par -p \opt{\tt/{\it f}\/} \opt{\it expr}&show value of {\it expr} \opt{or -last value \tt \$} according to format {\it f}:\cr -\qquad x&hexadecimal\cr -\qquad d&signed decimal\cr -\qquad u&unsigned decimal\cr -\qquad o&octal\cr -\qquad t&binary\cr -\qquad a&address, absolute and relative\cr -\qquad c&character\cr -\qquad f&floating point\cr -call \opt{\tt /{\it f}\/} {\it expr}&like {\tt print} but does not display -{\tt void}\cr -x \opt{\tt/{\it Nuf}\/} {\it expr}&examine memory at address {\it expr}; -optional format spec follows slash\cr -\quad {\it N}&count of how many units to display\cr -\quad {\it u}&unit size; one of\cr -&{\tt\qquad b}\ individual bytes\cr -&{\tt\qquad h}\ halfwords (two bytes)\cr -&{\tt\qquad w}\ words (four bytes)\cr -&{\tt\qquad g}\ giant words (eight bytes)\cr -\quad {\it f}&printing format. Any {\tt print} format, or\cr -&{\tt\qquad s}\ null-terminated string\cr -&{\tt\qquad i}\ machine instructions\cr -disassem \opt{\it addr}&display memory as machine instructions\cr -\endsec - -\sec Automatic Display; -display \opt{\tt/\it f\/} {\it expr}&show value of {\it expr} each time -program stops \opt{according to format {\it f}\/}\cr -display&display all enabled expressions on list\cr -undisplay {\it n}&remove number(s) {\it n} from list of -automatically displayed expressions\cr -disable disp {\it n}&disable display for expression(s) number {\it -n}\cr -enable disp {\it n}&enable display for expression(s) number {\it -n}\cr -info display&numbered list of display expressions\cr -\endsec - -\vfill\eject - -\sec Expressions; -{\it expr}&an expression in C, C++, or Modula-2 (including function calls), or:\cr -{\it addr\/}@{\it len}&an array of {\it len} elements beginning at {\it -addr}\cr -{\it file}::{\it nm}&a variable or function {\it nm} defined in {\it -file}\cr -$\tt\{${\it type}$\tt\}${\it addr}&read memory at {\it addr} as specified -{\it type}\cr -\$&most recent displayed value\cr -\${\it n}&{\it n}th displayed value\cr -\$\$&displayed value previous to \$\cr -\$\${\it n}&{\it n}th displayed value back from \$\cr -\$\_&last address examined with {\tt x}\cr -\$\_\_&value at address \$\_\cr -\${\it var}&convenience variable; assign any value\cr -\cr -show values \opt{{\it n}}&show last 10 values \opt{or surrounding -\${\it n}}\cr -show convenience&display all convenience variables\cr -\endsec - -\sec Symbol Table; -info address {\it s}&show where symbol {\it s} is stored\cr -info func \opt{\it regex}&show names, types of defined functions -(all, or matching {\it regex})\cr -info var \opt{\it regex}&show names, types of global variables (all, -or matching {\it regex})\cr -whatis \opt{\it expr}\par -ptype \opt{\it expr}&show data type of {\it expr} \opt{or \tt \$} -without evaluating; {\tt ptype} gives more detail\cr -ptype {\it type}&describe type, struct, union, or enum\cr -\endsec - -\sec GDB Scripts; -source {\it script}&read, execute GDB commands from file {\it -script}\cr -\cr -define {\it cmd}\par -\qquad {\it command-list}&create new GDB command {\it cmd}; -execute script defined by {\it command-list}\cr -end&end of {\it command-list}\cr -document {\it cmd}\par -\qquad {\it help-text}&create online documentation -for new GDB command {\it cmd}\cr -end&end of {\it help-text}\cr -\endsec - -\sec Signals; -handle {\it signal} {\it act}&specify GDB actions for {\it signal}:\cr -\quad print&announce signal\cr -\quad noprint&be silent for signal\cr -\quad stop&halt execution on signal\cr -\quad nostop&do not halt execution\cr -\quad pass&allow your program to handle signal\cr -\quad nopass&do not allow your program to see signal\cr -info signals&show table of signals, GDB action for each\cr -\endsec - -\sec Debugging Targets; -target {\it type} {\it param}&connect to target machine, process, or file\cr -help target&display available targets\cr -attach {\it param}&connect to another process\cr -detach&release target from GDB control\cr -\endsec - -\vfill\eject -\sec Controlling GDB; -set {\it param} {\it value}&set one of GDB's internal parameters\cr -show {\it param}&display current setting of parameter\cr -\xtra{\rm Parameters understood by {\tt set} and {\tt show}:} -\quad complaints {\it limit}&number of messages on unusual symbols\cr -\quad confirm {\it on/off}&enable or disable cautionary queries\cr -\quad editing {\it on/off}&control {\tt readline} command-line editing\cr -\quad height {\it lpp}&number of lines before pause in display\cr -\quad language {\it lang}&Language for GDB expressions ({\tt auto}, {\tt c} or -{\tt modula-2})\cr -\quad listsize {\it n}&number of lines shown by {\tt list}\cr -\quad prompt {\it str}&use {\it str} as GDB prompt\cr -\quad radix {\it base}&octal, decimal, or hex number representation\cr -\quad verbose {\it on/off}&control messages when loading -symbols\cr -\quad width {\it cpl}&number of characters before line folded\cr -\quad write {\it on/off}&Allow or forbid patching binary, core files -(when reopened with {\tt exec} or {\tt core}) -\cr -\quad history $\ldots$\par -\quad h $\ldots$&groups with the following options:\cr -\quad h exp {\it off/on}&disable/enable {\tt readline} history expansion\cr -\quad h file {\it filename}&file for recording GDB command history\cr -\quad h size {\it size}&number of commands kept in history list\cr -\quad h save {\it off/on}&control use of external file for -command history\cr -\cr -\quad print $\ldots$\par -\quad p $\ldots$&groups with the following options:\cr -\quad p address {\it on/off}&print memory addresses in stacks, -values\cr -\quad p array {\it off/on}&compact or attractive format for -arrays\cr -\quad p demangl {\it on/off}&source (demangled) or internal form for C++ -symbols\cr -\quad p asm-dem {\it on/off}&demangle C++ symbols in -machine-instruction output\cr -\quad p elements {\it limit}&number of array elements to display\cr -\quad p object {\it on/off}&print C++ derived types for objects\cr -\quad p pretty {\it off/on}&struct display: compact or indented\cr -\quad p union {\it on/off}&display of union members\cr -\quad p vtbl {\it off/on}&display of C++ virtual function -tables\cr -\cr -show commands&show last 10 commands\cr -show commands {\it n}&show 10 commands around number {\it n}\cr -show commands +&show next 10 commands\cr -\endsec - -\sec Working Files; -file \opt{\it file}&use {\it file} for both symbols and executable; -with no arg, discard both\cr -core \opt{\it file}&read {\it file} as coredump; or discard\cr -exec \opt{\it file}&use {\it file} as executable only; or discard\cr -symbol \opt{\it file}&use symbol table from {\it file}; or discard\cr -load {\it file}&dynamically link {\it file\/} and add its symbols\cr -add-sym {\it file} {\it addr}&read additional symbols from {\it file}, -dynamically loaded at {\it addr}\cr -info files&display working files and targets in use\cr -path {\it dirs}&add {\it dirs} to front of path searched for -executable and symbol files\cr -show path&display executable and symbol file path\cr -info share&list names of shared libraries currently loaded\cr -\endsec - -\vfill\eject -\sec Source Files; -dir {\it names}&add directory {\it names} to front of source path\cr -dir&clear source path\cr -show dir&show current source path\cr -\cr -list&show next ten lines of source\cr -list -&show previous ten lines\cr -list {\it lines}&display source surrounding {\it lines}, -specified as:\cr -\quad{\opt{\it file\tt:}\it num}&line number \opt{in named file}\cr -\quad{\opt{\it file\tt:}\it function}&beginning of function \opt{in -named file}\cr -\quad{\tt +\it off}&{\it off} lines after last printed\cr -\quad{\tt -\it off}&{\it off} lines previous to last printed\cr -\quad{\tt*\it address}&line containing {\it address}\cr -list {\it f},{\it l}&from line {\it f} to line {\it l}\cr -info line {\it num}&show starting, ending addresses of compiled code for -source line {\it num}\cr -info source&show name of current source file\cr -info sources&list all source files in use\cr -forw {\it regex}&search following source lines for {\it regex}\cr -rev {\it regex}&search preceding source lines for {\it regex}\cr -\endsec - -\sec GDB under GNU Emacs; -M-x gdb&run GDB under Emacs\cr -\ctl{h} m&describe GDB mode\cr -M-s&step one line ({\tt step})\cr -M-n&next line ({\tt next})\cr -M-i&step one instruction ({\tt stepi})\cr -\ctl{c} \ctl{f}&finish current stack frame ({\tt finish})\cr -M-c&continue ({\tt cont})\cr -M-u&up {\it arg} frames ({\tt up})\cr -M-d&down {\it arg} frames ({\tt down})\cr -\ctl{x} \&© number from point, insert at end\cr -\ctl{x} SPC&(in source file) set break at point\cr -\endsec - -\sec GDB License; -show copying&Display GNU General Public License\cr -show warranty&There is NO WARRANTY for GDB. Display full no-warranty -statement.\cr -\endsec - - -\vfill -{\smrm\parskip=6pt -\centerline{Copyright \copyright 1991, 1992, 1993 Free Software Foundation, Inc.} -\centerline{Roland Pesch (pesch@cygnus.com)} -\centerline{The author assumes no responsibility for any errors on this card.} - -This card may be freely distributed under the terms of the GNU -General Public License. - -\centerline{Please contribute to development of this card by -annotating it.} - -GDB itself is free software; you are welcome to distribute copies of -it under the terms of the GNU General Public License. There is -absolutely no warranty for GDB. -} -\end diff --git a/gnu/usr.bin/gdb/environ.c b/gnu/usr.bin/gdb/environ.c deleted file mode 100644 index 0220166..0000000 --- a/gnu/usr.bin/gdb/environ.c +++ /dev/null @@ -1,185 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)environ.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* environ.c -- library for manipulating environments for GNU. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - - 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 1, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#define min(a, b) ((a) < (b) ? (a) : (b)) -#define max(a, b) ((a) > (b) ? (a) : (b)) - -#include "environ.h" - -/* Return a new environment object. */ - -struct environ * -make_environ () -{ - register struct environ *e; - - e = (struct environ *) xmalloc (sizeof (struct environ)); - - e->allocated = 10; - e->vector = (char **) xmalloc ((e->allocated + 1) * sizeof (char *)); - e->vector[0] = 0; - return e; -} - -/* Free an environment and all the strings in it. */ - -void -free_environ (e) - register struct environ *e; -{ - register char **vector = e->vector; - - while (*vector) - free (*vector++); - - free (e); -} - -/* Copy the environment given to this process into E. - Also copies all the strings in it, so we can be sure - that all strings in these environments are safe to free. */ - -void -init_environ (e) - register struct environ *e; -{ - extern char **environ; - register int i; - - for (i = 0; environ[i]; i++); - - if (e->allocated < i) - { - e->allocated = max (i, e->allocated + 10); - e->vector = (char **) xrealloc (e->vector, - (e->allocated + 1) * sizeof (char *)); - } - - bcopy (environ, e->vector, (i + 1) * sizeof (char *)); - - while (--i >= 0) - { - register int len = strlen (e->vector[i]) + 1; - register char *new = (char *) xmalloc (len); - bcopy (e->vector[i], new, len); - e->vector[i] = new; - } -} - -/* Return the vector of environment E. - This is used to get something to pass to execve. */ - -char ** -environ_vector (e) - struct environ *e; -{ - return e->vector; -} - -/* Return the value in environment E of variable VAR. */ - -char * -get_in_environ (e, var) - struct environ *e; - char *var; -{ - register int len = strlen (var); - register char **vector = e->vector; - register char *s; - - for (; s = *vector; vector++) - if (!strncmp (s, var, len) - && s[len] == '=') - return &s[len + 1]; - - return 0; -} - -/* Store the value in E of VAR as VALUE. */ - -void -set_in_environ (e, var, value) - struct environ *e; - char *var; - char *value; -{ - register int i; - register int len = strlen (var); - register char **vector = e->vector; - register char *s; - - for (i = 0; s = vector[i]; i++) - if (!strncmp (s, var, len) - && s[len] == '=') - break; - - if (s == 0) - { - if (i == e->allocated) - { - e->allocated += 10; - vector = (char **) xrealloc (vector, - (e->allocated + 1) * sizeof (char *)); - e->vector = vector; - } - vector[i + 1] = 0; - } - else - free (s); - - s = (char *) xmalloc (len + strlen (value) + 2); - strcpy (s, var); - strcat (s, "="); - strcat (s, value); - vector[i] = s; - return; -} - -/* Remove the setting for variable VAR from environment E. */ - -void -unset_in_environ (e, var) - struct environ *e; - char *var; -{ - register int len = strlen (var); - register char **vector = e->vector; - register char *s; - - for (; s = *vector; vector++) - if (!strncmp (s, var, len) - && s[len] == '=') - { - free (s); - bcopy (vector + 1, vector, - (e->allocated - (vector - e->vector)) * sizeof (char *)); - e->vector[e->allocated - 1] = 0; - return; - } -} diff --git a/gnu/usr.bin/gdb/environ.h b/gnu/usr.bin/gdb/environ.h deleted file mode 100644 index 13f31f4..0000000 --- a/gnu/usr.bin/gdb/environ.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Header for environment manipulation library. - Copyright (C) 1989, Free Software Foundation. - - 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 1, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* We manipulate environments represented as these structures. */ - -struct environ -{ - /* Number of usable slots allocated in VECTOR. - VECTOR always has one slot not counted here, - to hold the terminating zero. */ - int allocated; - /* A vector of slots, ALLOCATED + 1 of them. - The first few slots contain strings "VAR=VALUE" - and the next one contains zero. - Then come some unused slots. */ - char **vector; -}; - -struct environ *make_environ (); -void free_environ (); -void init_environ (); -char *get_in_environ (); -void set_in_environ (); -void unset_in_environ (); -char **environ_vector (); diff --git a/gnu/usr.bin/gdb/eval.c b/gnu/usr.bin/gdb/eval.c deleted file mode 100644 index 60779e6..0000000 --- a/gnu/usr.bin/gdb/eval.c +++ /dev/null @@ -1,1065 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)eval.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Evaluate expressions for GDB. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "value.h" -#include "expression.h" - - -/* Parse the string EXP as a C expression, evaluate it, - and return the result as a number. */ - -CORE_ADDR -parse_and_eval_address (exp) - char *exp; -{ - struct expression *expr = parse_c_expression (exp); - register CORE_ADDR addr; - register struct cleanup *old_chain - = make_cleanup (free_current_contents, &expr); - - addr = (CORE_ADDR) value_as_long (evaluate_expression (expr)); - do_cleanups (old_chain); - return addr; -} - -/* Like parse_and_eval_address but takes a pointer to a char * variable - and advanced that variable across the characters parsed. */ - -CORE_ADDR -parse_and_eval_address_1 (expptr) - char **expptr; -{ - struct expression *expr = parse_c_1 (expptr, 0, 0); - register CORE_ADDR addr; - register struct cleanup *old_chain - = make_cleanup (free_current_contents, &expr); - - addr = value_as_long (evaluate_expression (expr)); - do_cleanups (old_chain); - return addr; -} - -value -parse_and_eval (exp) - char *exp; -{ - struct expression *expr = parse_c_expression (exp); - register value val; - register struct cleanup *old_chain - = make_cleanup (free_current_contents, &expr); - - val = evaluate_expression (expr); - do_cleanups (old_chain); - return val; -} - -/* Parse up to a comma (or to a closeparen) - in the string EXPP as an expression, evaluate it, and return the value. - EXPP is advanced to point to the comma. */ - -value -parse_to_comma_and_eval (expp) - char **expp; -{ - struct expression *expr = parse_c_1 (expp, 0, 1); - register value val; - register struct cleanup *old_chain - = make_cleanup (free_current_contents, &expr); - - val = evaluate_expression (expr); - do_cleanups (old_chain); - return val; -} - -/* Evaluate an expression in internal prefix form - such as is constructed by expread.y. - - See expression.h for info on the format of an expression. */ - -static value evaluate_subexp (); -static value evaluate_subexp_for_address (); -static value evaluate_subexp_for_sizeof (); -static value evaluate_subexp_with_coercion (); - -/* return true if 'var' has an address in inferior's memory. */ -static int -value_has_lval(var) - register struct symbol *var; -{ - switch (SYMBOL_CLASS(var)) - { - case LOC_STATIC: - case LOC_LABEL: - case LOC_ARG: - case LOC_REF_ARG: - case LOC_LOCAL: - case LOC_BLOCK: - return (1); - } - return (0); -} - -/* Values of NOSIDE argument to eval_subexp. */ -enum noside -{ EVAL_NORMAL, - EVAL_SKIP, /* Only effect is to increment pos. */ - EVAL_AVOID_SIDE_EFFECTS, /* Don't modify any variables or - call any functions. The value - returned will have the correct - type, and will have an - approximately correct lvalue - type (inaccuracy: anything that is - listed as being in a register in - the function in which it was - declared will be lval_register). */ -}; - -value -evaluate_expression (exp) - struct expression *exp; -{ - int pc = 0; - return evaluate_subexp (0, exp, &pc, EVAL_NORMAL); -} - -/* Evaluate an expression, avoiding all memory references - and getting a value whose type alone is correct. */ - -value -evaluate_type (exp) - struct expression *exp; -{ - int pc = 0; - return evaluate_subexp (0, exp, &pc, EVAL_AVOID_SIDE_EFFECTS); -} - -static value -evaluate_subexp (expect_type, exp, pos, noside) - struct type *expect_type; - register struct expression *exp; - register int *pos; - enum noside noside; -{ - enum exp_opcode op; - int tem; - register int pc, pc2, oldpos; - register value arg1, arg2, arg3; - int nargs; - value *argvec; - - pc = (*pos)++; - op = exp->elts[pc].opcode; - - switch (op) - { - case OP_SCOPE: - tem = strlen (&exp->elts[pc + 2].string); - (*pos) += 3 + ((tem + sizeof (union exp_element)) - / sizeof (union exp_element)); - return value_static_field (exp->elts[pc + 1].type, - &exp->elts[pc + 2].string, -1); - - case OP_LONG: - (*pos) += 3; - return value_from_long (exp->elts[pc + 1].type, - exp->elts[pc + 2].longconst); - - case OP_DOUBLE: - (*pos) += 3; - return value_from_double (exp->elts[pc + 1].type, - exp->elts[pc + 2].doubleconst); - - case OP_VAR_VALUE: - (*pos) += 2; - if (noside == EVAL_SKIP) - goto nosideret; - if (noside == EVAL_AVOID_SIDE_EFFECTS) - { - struct symbol * sym = exp->elts[pc + 1].symbol; - enum lval_type lv; - - switch (SYMBOL_CLASS (sym)) - { - case LOC_CONST: - case LOC_LABEL: - case LOC_CONST_BYTES: - lv = not_lval; - case LOC_REGISTER: - case LOC_REGPARM: - lv = lval_register; - default: - lv = lval_memory; - } - - return value_zero (SYMBOL_TYPE (sym), lv); - } - else - return value_of_variable (exp->elts[pc + 1].symbol); - - case OP_LAST: - (*pos) += 2; - return access_value_history ((int) exp->elts[pc + 1].longconst); - - case OP_REGISTER: - (*pos) += 2; - return value_of_register ((int) exp->elts[pc + 1].longconst); - - case OP_INTERNALVAR: - (*pos) += 2; - return value_of_internalvar (exp->elts[pc + 1].internalvar); - - case OP_STRING: - tem = strlen (&exp->elts[pc + 1].string); - (*pos) += 2 + ((tem + sizeof (union exp_element)) - / sizeof (union exp_element)); - if (noside == EVAL_SKIP) - goto nosideret; - return value_string (&exp->elts[pc + 1].string, tem); - - case TERNOP_COND: - /* Skip third and second args to evaluate the first one. */ - arg1 = evaluate_subexp (0, exp, pos, noside); - if (value_zerop (arg1)) - { - evaluate_subexp (0, exp, pos, EVAL_SKIP); - return evaluate_subexp (0, exp, pos, noside); - } - else - { - arg2 = evaluate_subexp (0, exp, pos, noside); - evaluate_subexp (0, exp, pos, EVAL_SKIP); - return arg2; - } - - case OP_FUNCALL: - (*pos) += 2; - op = exp->elts[*pos].opcode; - if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR) - { - int fnptr; - int tem2; - - nargs = (int) exp->elts[pc + 1].longconst + 1; - /* First, evaluate the structure into arg2 */ - pc2 = (*pos)++; - - if (noside == EVAL_SKIP) - goto nosideret; - - if (op == STRUCTOP_MEMBER) - { - arg2 = evaluate_subexp_for_address (exp, pos, noside); - } - else - { - arg2 = evaluate_subexp (0, exp, pos, noside); - } - - /* If the function is a virtual function, then the - aggregate value (providing the structure) plays - its part by providing the vtable. Otherwise, - it is just along for the ride: call the function - directly. */ - - arg1 = evaluate_subexp (0, exp, pos, noside); - - fnptr = (int) value_as_long (arg1); - if (fnptr < 128) - { - struct type *basetype; - int i, j; - basetype = TYPE_TARGET_TYPE (VALUE_TYPE (arg2)); - basetype = TYPE_VPTR_BASETYPE (basetype); - for (i = TYPE_NFN_FIELDS (basetype) - 1; i >= 0; i--) - { - struct fn_field *f = TYPE_FN_FIELDLIST1 (basetype, i); - /* If one is virtual, then all are virtual. */ - if (TYPE_FN_FIELD_VIRTUAL_P (f, 0)) - for (j = TYPE_FN_FIELDLIST_LENGTH (basetype, i) - 1; j >= 0; --j) - if (TYPE_FN_FIELD_VOFFSET (f, j) == fnptr) - { - value vtbl; - value base = value_ind (arg2); - struct type *fntype = lookup_pointer_type (TYPE_FN_FIELD_TYPE (f, j)); - - if (TYPE_VPTR_FIELDNO (basetype) < 0) - TYPE_VPTR_FIELDNO (basetype) - = fill_in_vptr_fieldno (basetype); - - VALUE_TYPE (base) = basetype; - vtbl = value_field (base, TYPE_VPTR_FIELDNO (basetype)); - VALUE_TYPE (vtbl) = lookup_pointer_type (fntype); - VALUE_TYPE (arg1) = builtin_type_int; - arg1 = value_subscript (vtbl, arg1); - VALUE_TYPE (arg1) = fntype; - goto got_it; - } - } - if (i < 0) - error ("virtual function at index %d not found", fnptr); - } - else - { - VALUE_TYPE (arg1) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))); - } - got_it: - - /* Now, say which argument to start evaluating from */ - tem = 2; - } - else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR) - { - /* Hair for method invocations */ - int tem2; - - nargs = (int) exp->elts[pc + 1].longconst + 1; - /* First, evaluate the structure into arg2 */ - pc2 = (*pos)++; - tem2 = strlen (&exp->elts[pc2 + 1].string); - *pos += 2 + (tem2 + sizeof (union exp_element)) / sizeof (union exp_element); - if (noside == EVAL_SKIP) - goto nosideret; - - if (op == STRUCTOP_STRUCT) - { - arg2 = evaluate_subexp_for_address (exp, pos, noside); - } - else - { - arg2 = evaluate_subexp (0, exp, pos, noside); - } - /* Now, say which argument to start evaluating from */ - tem = 2; - } - else - { - nargs = (int) exp->elts[pc + 1].longconst; - tem = 0; - } - argvec = (value *) alloca (sizeof (value) * (nargs + 2)); - for (; tem <= nargs; tem++) - /* Ensure that array expressions are coerced into pointer objects. */ - argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside); - - /* signal end of arglist */ - argvec[tem] = 0; - - if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR) - { - int static_memfuncp; - - argvec[1] = arg2; - argvec[0] = - value_struct_elt (arg2, argvec+1, &exp->elts[pc2 + 1].string, - &static_memfuncp, - op == STRUCTOP_STRUCT - ? "structure" : "structure pointer"); - if (static_memfuncp) - { - argvec[1] = argvec[0]; - nargs--; - argvec++; - } - } - else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR) - { - argvec[1] = arg2; - argvec[0] = arg1; - } - - if (noside == EVAL_SKIP) - goto nosideret; - if (noside == EVAL_AVOID_SIDE_EFFECTS) - { - /* If the return type doesn't look like a function type, call an - error. This can happen if somebody tries to turn a variable into - a function call. This is here because people often want to - call, eg, strcmp, which gdb doesn't know is a function. If - gdb isn't asked for it's opinion (ie. through "whatis"), - it won't offer it. */ - - struct type *ftype = - TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0])); - - if (ftype) - return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0]))); - else - error ("Expression of type other than \"Function returning ...\" used as function"); - } - return call_function (argvec[0], nargs, argvec + 1); - - case STRUCTOP_STRUCT: - tem = strlen (&exp->elts[pc + 1].string); - (*pos) += 2 + ((tem + sizeof (union exp_element)) - / sizeof (union exp_element)); - - /* Try to convert "foo.bar" into "(&foo)->bar" so we won't copy - * the entire contents of a large struct just to extract one - * value from it. */ - if (noside == EVAL_NORMAL && exp->elts[*pos].opcode == OP_VAR_VALUE - && value_has_lval(exp->elts[*pos + 1].symbol)) - arg1 = evaluate_subexp_for_address(exp, pos, noside); - else - arg1 = evaluate_subexp (0, exp, pos, noside); - - if (noside == EVAL_SKIP) - goto nosideret; - if (noside == EVAL_AVOID_SIDE_EFFECTS) - { - register struct type *type = VALUE_TYPE (arg1); - if (TYPE_CODE (type) == TYPE_CODE_PTR) - type = TYPE_TARGET_TYPE (type); - return value_zero (lookup_struct_elt_type (type, - &exp->elts[pc + 1].string), - lval_memory); - } - else - return value_struct_elt (arg1, 0, &exp->elts[pc + 1].string, 0, - "structure"); - - case STRUCTOP_PTR: - tem = strlen (&exp->elts[pc + 1].string); - (*pos) += 2 + (tem + sizeof (union exp_element)) / sizeof (union exp_element); - arg1 = evaluate_subexp (0, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (noside == EVAL_AVOID_SIDE_EFFECTS) - return value_zero (lookup_struct_elt_type (TYPE_TARGET_TYPE - (VALUE_TYPE (arg1)), - &exp->elts[pc + 1].string), - lval_memory); - else - return value_struct_elt (arg1, 0, &exp->elts[pc + 1].string, 0, - "structure pointer"); - - case STRUCTOP_MEMBER: - arg1 = evaluate_subexp_for_address (exp, pos, noside); - arg2 = evaluate_subexp (0, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - /* Now, convert these values to an address. */ - if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_PTR - || ((TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) - != TYPE_CODE_MEMBER) - && (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) - != TYPE_CODE_METHOD))) - error ("non-pointer-to-member value used in pointer-to-member construct"); - arg3 = value_from_long (builtin_type_long, - value_as_long (arg1) + value_as_long (arg2)); - VALUE_TYPE (arg3) = - lookup_pointer_type (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2)))); - return value_ind (arg3); - - case STRUCTOP_MPTR: - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (0, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - /* Now, convert these values to an address. */ - if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_PTR - || (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) != TYPE_CODE_MEMBER - && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) != TYPE_CODE_METHOD)) - error ("non-pointer-to-member value used in pointer-to-member construct"); - arg3 = value_from_long (builtin_type_long, - value_as_long (arg1) + value_as_long (arg2)); - VALUE_TYPE (arg3) = - lookup_pointer_type (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2)))); - return value_ind (arg3); - - case BINOP_ASSIGN: - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); - if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) - return arg1; - if (binop_user_defined_p (op, arg1, arg2)) - return value_x_binop (arg1, arg2, op, 0); - else - return value_assign (arg1, arg2); - - case BINOP_ASSIGN_MODIFY: - (*pos) += 2; - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); - if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) - return arg1; - op = exp->elts[pc + 1].opcode; - if (binop_user_defined_p (op, arg1, arg2)) - return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op); - else if (op == BINOP_ADD) - arg2 = value_add (arg1, arg2); - else if (op == BINOP_SUB) - arg2 = value_sub (arg1, arg2); - else - arg2 = value_binop (arg1, arg2, op); - return value_assign (arg1, arg2); - - case BINOP_ADD: - arg1 = evaluate_subexp_with_coercion (exp, pos, noside); - arg2 = evaluate_subexp_with_coercion (exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (binop_user_defined_p (op, arg1, arg2)) - return value_x_binop (arg1, arg2, op, 0); - else - return value_add (arg1, arg2); - - case BINOP_SUB: - arg1 = evaluate_subexp_with_coercion (exp, pos, noside); - arg2 = evaluate_subexp_with_coercion (exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (binop_user_defined_p (op, arg1, arg2)) - return value_x_binop (arg1, arg2, op, 0); - else - return value_sub (arg1, arg2); - - case BINOP_MUL: - case BINOP_DIV: - case BINOP_REM: - case BINOP_LSH: - case BINOP_RSH: - case BINOP_LOGAND: - case BINOP_LOGIOR: - case BINOP_LOGXOR: - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (0, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (binop_user_defined_p (op, arg1, arg2)) - return value_x_binop (arg1, arg2, op, 0); - else - if (noside == EVAL_AVOID_SIDE_EFFECTS - && op == BINOP_DIV) - return value_zero (VALUE_TYPE (arg1), not_lval); - else - return value_binop (arg1, arg2, op); - - case BINOP_SUBSCRIPT: - arg1 = evaluate_subexp_with_coercion (exp, pos, noside); - arg2 = evaluate_subexp_with_coercion (exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (noside == EVAL_AVOID_SIDE_EFFECTS) - return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)), - VALUE_LVAL (arg1)); - - if (binop_user_defined_p (op, arg1, arg2)) - return value_x_binop (arg1, arg2, op, 0); - else - return value_subscript (arg1, arg2); - - case BINOP_AND: - arg1 = evaluate_subexp (0, exp, pos, noside); - if (noside == EVAL_SKIP) - { - arg2 = evaluate_subexp (0, exp, pos, noside); - goto nosideret; - } - - oldpos = *pos; - arg2 = evaluate_subexp (0, exp, pos, EVAL_AVOID_SIDE_EFFECTS); - *pos = oldpos; - - if (binop_user_defined_p (op, arg1, arg2)) - { - arg2 = evaluate_subexp (0, exp, pos, noside); - return value_x_binop (arg1, arg2, op, 0); - } - else - { - tem = value_zerop (arg1); - arg2 = evaluate_subexp (0, exp, pos, - (tem ? EVAL_SKIP : noside)); - return value_from_long (builtin_type_int, - (LONGEST) (!tem && !value_zerop (arg2))); - } - - case BINOP_OR: - arg1 = evaluate_subexp (0, exp, pos, noside); - if (noside == EVAL_SKIP) - { - arg2 = evaluate_subexp (0, exp, pos, noside); - goto nosideret; - } - - oldpos = *pos; - arg2 = evaluate_subexp (0, exp, pos, EVAL_AVOID_SIDE_EFFECTS); - *pos = oldpos; - - if (binop_user_defined_p (op, arg1, arg2)) - { - arg2 = evaluate_subexp (0, exp, pos, noside); - return value_x_binop (arg1, arg2, op, 0); - } - else - { - tem = value_zerop (arg1); - arg2 = evaluate_subexp (0, exp, pos, - (!tem ? EVAL_SKIP : noside)); - return value_from_long (builtin_type_int, - (LONGEST) (!tem || !value_zerop (arg2))); - } - - case BINOP_EQUAL: - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (binop_user_defined_p (op, arg1, arg2)) - { - return value_x_binop (arg1, arg2, op, 0); - } - else - { - tem = value_equal (arg1, arg2); - return value_from_long (builtin_type_int, (LONGEST) tem); - } - - case BINOP_NOTEQUAL: - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (binop_user_defined_p (op, arg1, arg2)) - { - return value_x_binop (arg1, arg2, op, 0); - } - else - { - tem = value_equal (arg1, arg2); - return value_from_long (builtin_type_int, (LONGEST) ! tem); - } - - case BINOP_LESS: - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (binop_user_defined_p (op, arg1, arg2)) - { - return value_x_binop (arg1, arg2, op, 0); - } - else - { - tem = value_less (arg1, arg2); - return value_from_long (builtin_type_int, (LONGEST) tem); - } - - case BINOP_GTR: - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (binop_user_defined_p (op, arg1, arg2)) - { - return value_x_binop (arg1, arg2, op, 0); - } - else - { - tem = value_less (arg2, arg1); - return value_from_long (builtin_type_int, (LONGEST) tem); - } - - case BINOP_GEQ: - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (binop_user_defined_p (op, arg1, arg2)) - { - return value_x_binop (arg1, arg2, op, 0); - } - else - { - tem = value_less (arg1, arg2); - return value_from_long (builtin_type_int, (LONGEST) ! tem); - } - - case BINOP_LEQ: - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (binop_user_defined_p (op, arg1, arg2)) - { - return value_x_binop (arg1, arg2, op, 0); - } - else - { - tem = value_less (arg2, arg1); - return value_from_long (builtin_type_int, (LONGEST) ! tem); - } - - case BINOP_REPEAT: - arg1 = evaluate_subexp (0, exp, pos, noside); - arg2 = evaluate_subexp (0, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT) - error ("Non-integral right operand for \"@\" operator."); - if (noside == EVAL_AVOID_SIDE_EFFECTS) - return allocate_repeat_value (VALUE_TYPE (arg1), - (int) value_as_long (arg2)); - else - return value_repeat (arg1, (int) value_as_long (arg2)); - - case BINOP_COMMA: - evaluate_subexp (0, exp, pos, noside); - return evaluate_subexp (0, exp, pos, noside); - - case UNOP_NEG: - arg1 = evaluate_subexp (0, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (unop_user_defined_p (op, arg1)) - return value_x_unop (arg1, op); - else - return value_neg (arg1); - - case UNOP_LOGNOT: - arg1 = evaluate_subexp (0, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (unop_user_defined_p (op, arg1)) - return value_x_unop (arg1, op); - else - return value_lognot (arg1); - - case UNOP_ZEROP: - arg1 = evaluate_subexp (0, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (unop_user_defined_p (op, arg1)) - return value_x_unop (arg1, op); - else - return value_from_long (builtin_type_int, - (LONGEST) value_zerop (arg1)); - - case UNOP_IND: - if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR) - expect_type = TYPE_TARGET_TYPE (expect_type); - arg1 = evaluate_subexp (expect_type, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (noside == EVAL_AVOID_SIDE_EFFECTS) - { - if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR - || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF - /* In C you can dereference an array to get the 1st elt. */ - || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY - ) - return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)), - lval_memory); - else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT) - /* GDB allows dereferencing an int. */ - return value_zero (builtin_type_int, lval_memory); - else - error ("Attempt to take contents of a non-pointer value."); - } - return value_ind (arg1); - - case UNOP_ADDR: - /* C++: check for and handle pointer to members. */ - - op = exp->elts[*pos].opcode; - - if (noside == EVAL_SKIP) - { - if (op == OP_SCOPE) - { - char *name = &exp->elts[pc+3].string; - int tem = strlen (name); - (*pos) += 2 + (tem + sizeof (union exp_element)) / sizeof (union exp_element); - } - else - evaluate_subexp (expect_type, exp, pos, EVAL_SKIP); - goto nosideret; - } - - if (op == OP_SCOPE) - { - char *name = &exp->elts[pc+3].string; - int tem = strlen (name); - struct type *domain = exp->elts[pc+2].type; - (*pos) += 2 + (tem + sizeof (union exp_element)) / sizeof (union exp_element); - arg1 = value_struct_elt_for_address (domain, expect_type, name); - if (arg1) - return arg1; - error ("no field `%s' in structure", name); - } - else - return evaluate_subexp_for_address (exp, pos, noside); - - case UNOP_SIZEOF: - if (noside == EVAL_SKIP) - { - evaluate_subexp (0, exp, pos, EVAL_SKIP); - goto nosideret; - } - return evaluate_subexp_for_sizeof (exp, pos); - - case UNOP_CAST: - (*pos) += 2; - arg1 = evaluate_subexp (expect_type, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - return value_cast (exp->elts[pc + 1].type, arg1); - - case UNOP_MEMVAL: - (*pos) += 2; - arg1 = evaluate_subexp (expect_type, exp, pos, noside); - if (noside == EVAL_SKIP) - goto nosideret; - if (noside == EVAL_AVOID_SIDE_EFFECTS) - return value_zero (exp->elts[pc + 1].type, lval_memory); - else - return value_at (exp->elts[pc + 1].type, - (CORE_ADDR) value_as_long (arg1)); - - case UNOP_PREINCREMENT: - arg1 = evaluate_subexp (expect_type, exp, pos, noside); - if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) - return arg1; - else if (unop_user_defined_p (op, arg1)) - { - return value_x_unop (arg1, op); - } - else - { - arg2 = value_add (arg1, value_from_long (builtin_type_char, - (LONGEST) 1)); - return value_assign (arg1, arg2); - } - - case UNOP_PREDECREMENT: - arg1 = evaluate_subexp (expect_type, exp, pos, noside); - if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) - return arg1; - else if (unop_user_defined_p (op, arg1)) - { - return value_x_unop (arg1, op); - } - else - { - arg2 = value_sub (arg1, value_from_long (builtin_type_char, - (LONGEST) 1)); - return value_assign (arg1, arg2); - } - - case UNOP_POSTINCREMENT: - arg1 = evaluate_subexp (expect_type, exp, pos, noside); - if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) - return arg1; - else if (unop_user_defined_p (op, arg1)) - { - return value_x_unop (arg1, op); - } - else - { - arg2 = value_add (arg1, value_from_long (builtin_type_char, - (LONGEST) 1)); - value_assign (arg1, arg2); - return arg1; - } - - case UNOP_POSTDECREMENT: - arg1 = evaluate_subexp (expect_type, exp, pos, noside); - if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) - return arg1; - else if (unop_user_defined_p (op, arg1)) - { - return value_x_unop (arg1, op); - } - else - { - arg2 = value_sub (arg1, value_from_long (builtin_type_char, - (LONGEST) 1)); - value_assign (arg1, arg2); - return arg1; - } - - case OP_THIS: - (*pos) += 1; - return value_of_this (1); - - default: - error ("internal error: I do not know how to evaluate what you gave me"); - } - - nosideret: - return value_from_long (builtin_type_long, (LONGEST) 1); -} - -/* Evaluate a subexpression of EXP, at index *POS, - and return the address of that subexpression. - Advance *POS over the subexpression. - If the subexpression isn't an lvalue, get an error. - NOSIDE may be EVAL_AVOID_SIDE_EFFECTS; - then only the type of the result need be correct. */ - -static value -evaluate_subexp_for_address (exp, pos, noside) - register struct expression *exp; - register int *pos; - enum noside noside; -{ - enum exp_opcode op; - register int pc; - - pc = (*pos); - op = exp->elts[pc].opcode; - - switch (op) - { - case UNOP_IND: - (*pos)++; - return evaluate_subexp (0, exp, pos, noside); - - case UNOP_MEMVAL: - (*pos) += 3; - return value_cast (lookup_pointer_type (exp->elts[pc + 1].type), - evaluate_subexp (0, exp, pos, noside)); - - case OP_VAR_VALUE: - (*pos) += 3; - if (noside == EVAL_AVOID_SIDE_EFFECTS) - { - struct type *type = - lookup_pointer_type (SYMBOL_TYPE (exp->elts[pc + 1].symbol)); - enum address_class sym_class = - SYMBOL_CLASS (exp->elts[pc + 1].symbol); - - if (sym_class == LOC_CONST - || sym_class == LOC_CONST_BYTES - || sym_class == LOC_REGISTER - || sym_class == LOC_REGPARM) - error ("Attempt to take address of register or constant."); - - return - value_zero (type, not_lval); - } - else - return locate_var_value (exp->elts[pc + 1].symbol, (CORE_ADDR) 0); - - default: - if (noside == EVAL_AVOID_SIDE_EFFECTS) - { - value x = evaluate_subexp (0, exp, pos, noside); - if (VALUE_LVAL (x) == lval_memory) - return value_zero (TYPE_POINTER_TYPE (VALUE_TYPE (x)), - not_lval); - else - error ("Attempt to take address of non-lval"); - } - return value_addr (evaluate_subexp (0, exp, pos, noside)); - } -} - -/* Evaluate like `evaluate_subexp' except coercing arrays to pointers. - When used in contexts where arrays will be coerced anyway, - this is equivalent to `evaluate_subexp' - but much faster because it avoids actually fetching array contents. */ - -static value -evaluate_subexp_with_coercion (exp, pos, noside) - register struct expression *exp; - register int *pos; - enum noside noside; -{ - register enum exp_opcode op; - register int pc; - register value val; - - pc = (*pos); - op = exp->elts[pc].opcode; - - switch (op) - { - case OP_VAR_VALUE: - if (TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 1].symbol)) == TYPE_CODE_ARRAY) - { - (*pos) += 3; - val = locate_var_value (exp->elts[pc + 1].symbol, (CORE_ADDR) 0); - return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (exp->elts[pc + 1].symbol))), - val); - } - } - - return evaluate_subexp (0, exp, pos, noside); -} - -/* Evaluate a subexpression of EXP, at index *POS, - and return a value for the size of that subexpression. - Advance *POS over the subexpression. */ - -static value -evaluate_subexp_for_sizeof (exp, pos) - register struct expression *exp; - register int *pos; -{ - enum exp_opcode op; - register int pc; - value val; - - pc = (*pos); - op = exp->elts[pc].opcode; - - switch (op) - { - /* This case is handled specially - so that we avoid creating a value for the result type. - If the result type is very big, it's desirable not to - create a value unnecessarily. */ - case UNOP_IND: - (*pos)++; - val = evaluate_subexp (0, exp, pos, EVAL_AVOID_SIDE_EFFECTS); - return value_from_long (builtin_type_int, (LONGEST) - TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val)))); - - case UNOP_MEMVAL: - (*pos) += 3; - return value_from_long (builtin_type_int, - (LONGEST) TYPE_LENGTH (exp->elts[pc + 1].type)); - - case OP_VAR_VALUE: - (*pos) += 3; - return value_from_long (builtin_type_int, - (LONGEST) TYPE_LENGTH (SYMBOL_TYPE (exp->elts[pc + 1].symbol))); - - default: - val = evaluate_subexp (0, exp, pos, EVAL_AVOID_SIDE_EFFECTS); - return value_from_long (builtin_type_int, - (LONGEST) TYPE_LENGTH (VALUE_TYPE (val))); - } -} diff --git a/gnu/usr.bin/gdb/expprint.c b/gnu/usr.bin/gdb/expprint.c deleted file mode 100644 index 2c63cf8..0000000 --- a/gnu/usr.bin/gdb/expprint.c +++ /dev/null @@ -1,324 +0,0 @@ -/* Print in infix form a struct expression. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "expression.h" -#include "value.h" - - -/* These codes indicate operator precedences, least tightly binding first. */ -/* Adding 1 to a precedence value is done for binary operators, - on the operand which is more tightly bound, so that operators - of equal precedence within that operand will get parentheses. */ -/* PREC_HYPER and PREC_ABOVE_COMMA are not the precedence of any operator; - they are used as the "surrounding precedence" to force - various kinds of things to be parenthesized. */ -enum precedence -{ PREC_NULL, PREC_COMMA, PREC_ABOVE_COMMA, PREC_ASSIGN, PREC_OR, PREC_AND, - PREC_LOGIOR, PREC_LOGAND, PREC_LOGXOR, PREC_EQUAL, PREC_ORDER, - PREC_SHIFT, PREC_ADD, PREC_MUL, PREC_REPEAT, - PREC_HYPER, PREC_PREFIX, PREC_SUFFIX }; - -/* Table mapping opcodes into strings for printing operators - and precedences of the operators. */ - -struct op_print -{ - char *string; - enum exp_opcode opcode; - /* Precedence of operator. These values are used only by comparisons. */ - enum precedence precedence; - int right_assoc; -}; - -static struct op_print op_print_tab[] = - { - {",", BINOP_COMMA, PREC_COMMA, 0}, - {"=", BINOP_ASSIGN, PREC_ASSIGN, 1}, - {"||", BINOP_OR, PREC_OR, 0}, - {"&&", BINOP_AND, PREC_AND, 0}, - {"|", BINOP_LOGIOR, PREC_LOGIOR, 0}, - {"&", BINOP_LOGAND, PREC_LOGAND, 0}, - {"^", BINOP_LOGXOR, PREC_LOGXOR, 0}, - {"==", BINOP_EQUAL, PREC_EQUAL, 0}, - {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, - {"<=", BINOP_LEQ, PREC_ORDER, 0}, - {">=", BINOP_GEQ, PREC_ORDER, 0}, - {">", BINOP_GTR, PREC_ORDER, 0}, - {"<", BINOP_LESS, PREC_ORDER, 0}, - {">>", BINOP_RSH, PREC_SHIFT, 0}, - {"<<", BINOP_LSH, PREC_SHIFT, 0}, - {"+", BINOP_ADD, PREC_ADD, 0}, - {"-", BINOP_SUB, PREC_ADD, 0}, - {"*", BINOP_MUL, PREC_MUL, 0}, - {"/", BINOP_DIV, PREC_MUL, 0}, - {"%", BINOP_REM, PREC_MUL, 0}, - {"@", BINOP_REPEAT, PREC_REPEAT, 0}, - {"-", UNOP_NEG, PREC_PREFIX, 0}, - {"!", UNOP_ZEROP, PREC_PREFIX, 0}, - {"~", UNOP_LOGNOT, PREC_PREFIX, 0}, - {"*", UNOP_IND, PREC_PREFIX, 0}, - {"&", UNOP_ADDR, PREC_PREFIX, 0}, - {"sizeof ", UNOP_SIZEOF, PREC_PREFIX, 0}, - {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0}, - {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0}, - /* C++ */ - {"::", BINOP_SCOPE, PREC_PREFIX, 0}, - }; - -static void print_subexp (); - -void -print_expression (exp, stream) - struct expression *exp; - FILE *stream; -{ - int pc = 0; - print_subexp (exp, &pc, stream, PREC_NULL); -} - -/* Print the subexpression of EXP that starts in position POS, on STREAM. - PREC is the precedence of the surrounding operator; - if the precedence of the main operator of this subexpression is less, - parentheses are needed here. */ - -static void -print_subexp (exp, pos, stream, prec) - register struct expression *exp; - register int *pos; - FILE *stream; - enum precedence prec; -{ - register int tem; - register int pc; - int nargs; - register char *op_str; - int assign_modify = 0; - enum exp_opcode opcode; - enum precedence myprec; - /* Set to 1 for a right-associative operator. */ - int assoc; - - pc = (*pos)++; - opcode = exp->elts[pc].opcode; - switch (opcode) - { - case OP_SCOPE: - myprec = PREC_PREFIX; - assoc = 0; - (*pos) += 2; - print_subexp (exp, pos, stream, (int) myprec + assoc); - fprintf (stream, " :: "); - nargs = strlen (&exp->elts[pc + 2].string); - (*pos) += 1 + (nargs + sizeof (union exp_element)) / sizeof (union exp_element); - - fprintf (stream, &exp->elts[pc + 2].string); - return; - - case OP_LONG: - (*pos) += 3; - value_print (value_from_long (exp->elts[pc + 1].type, - exp->elts[pc + 2].longconst), - stream, 0, Val_no_prettyprint); - return; - - case OP_DOUBLE: - (*pos) += 3; - value_print (value_from_double (exp->elts[pc + 1].type, - exp->elts[pc + 2].doubleconst), - stream, 0, Val_no_prettyprint); - return; - - case OP_VAR_VALUE: - (*pos) += 2; - fprintf (stream, "%s", SYMBOL_NAME (exp->elts[pc + 1].symbol)); - return; - - case OP_LAST: - (*pos) += 2; - fprintf (stream, "$%d", (int) exp->elts[pc + 1].longconst); - return; - - case OP_REGISTER: - (*pos) += 2; - fprintf (stream, "$%s", reg_names[exp->elts[pc + 1].longconst]); - return; - - case OP_INTERNALVAR: - (*pos) += 2; - fprintf (stream, "$%s", - internalvar_name (exp->elts[pc + 1].internalvar)); - return; - - case OP_FUNCALL: - (*pos) += 2; - nargs = exp->elts[pc + 1].longconst; - print_subexp (exp, pos, stream, PREC_SUFFIX); - fprintf (stream, " ("); - for (tem = 0; tem < nargs; tem++) - { - if (tem > 0) - fprintf (stream, ", "); - print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); - } - fprintf (stream, ")"); - return; - - case OP_STRING: - nargs = strlen (&exp->elts[pc + 1].string); - (*pos) += 2 + (nargs + sizeof (union exp_element)) / sizeof (union exp_element); - fprintf (stream, "\""); - for (tem = 0; tem < nargs; tem++) - printchar ((&exp->elts[pc + 1].string)[tem], stream, '"'); - fprintf (stream, "\""); - return; - - case TERNOP_COND: - if ((int) prec > (int) PREC_COMMA) - fprintf (stream, "("); - /* Print the subexpressions, forcing parentheses - around any binary operations within them. - This is more parentheses than are strictly necessary, - but it looks clearer. */ - print_subexp (exp, pos, stream, PREC_HYPER); - fprintf (stream, " ? "); - print_subexp (exp, pos, stream, PREC_HYPER); - fprintf (stream, " : "); - print_subexp (exp, pos, stream, PREC_HYPER); - if ((int) prec > (int) PREC_COMMA) - fprintf (stream, ")"); - return; - - case STRUCTOP_STRUCT: - tem = strlen (&exp->elts[pc + 1].string); - (*pos) += 2 + (tem + sizeof (union exp_element)) / sizeof (union exp_element); - print_subexp (exp, pos, stream, PREC_SUFFIX); - fprintf (stream, ".%s", &exp->elts[pc + 1].string); - return; - - case STRUCTOP_PTR: - tem = strlen (&exp->elts[pc + 1].string); - (*pos) += 2 + (tem + sizeof (union exp_element)) / sizeof (union exp_element); - print_subexp (exp, pos, stream, PREC_SUFFIX); - fprintf (stream, "->%s", &exp->elts[pc + 1].string); - return; - - case BINOP_SUBSCRIPT: - print_subexp (exp, pos, stream, PREC_SUFFIX); - fprintf (stream, "["); - print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); - fprintf (stream, "]"); - return; - - case UNOP_POSTINCREMENT: - print_subexp (exp, pos, stream, PREC_SUFFIX); - fprintf (stream, "++"); - return; - - case UNOP_POSTDECREMENT: - print_subexp (exp, pos, stream, PREC_SUFFIX); - fprintf (stream, "--"); - return; - - case UNOP_CAST: - (*pos) += 2; - if ((int) prec > (int) PREC_PREFIX) - fprintf (stream, "("); - fprintf (stream, "("); - type_print (exp->elts[pc + 1].type, "", stream, 0); - fprintf (stream, ") "); - print_subexp (exp, pos, stream, PREC_PREFIX); - if ((int) prec > (int) PREC_PREFIX) - fprintf (stream, ")"); - return; - - case UNOP_MEMVAL: - (*pos) += 2; - if ((int) prec > (int) PREC_PREFIX) - fprintf (stream, "("); - fprintf (stream, "{"); - type_print (exp->elts[pc + 1].type, "", stream, 0); - fprintf (stream, "} "); - print_subexp (exp, pos, stream, PREC_PREFIX); - if ((int) prec > (int) PREC_PREFIX) - fprintf (stream, ")"); - return; - - case BINOP_ASSIGN_MODIFY: - opcode = exp->elts[pc + 1].opcode; - (*pos) += 2; - myprec = PREC_ASSIGN; - assoc = 1; - assign_modify = 1; - for (tem = 0; tem < sizeof op_print_tab / sizeof op_print_tab[0]; tem++) - if (op_print_tab[tem].opcode == opcode) - { - op_str = op_print_tab[tem].string; - break; - } - - case OP_THIS: - ++(*pos); - fprintf (stream, "this"); - return; - - default: - for (tem = 0; tem < sizeof op_print_tab / sizeof op_print_tab[0]; tem++) - if (op_print_tab[tem].opcode == opcode) - { - op_str = op_print_tab[tem].string; - myprec = op_print_tab[tem].precedence; - assoc = op_print_tab[tem].right_assoc; - break; - } - } - - if ((int) myprec < (int) prec) - fprintf (stream, "("); - if ((int) opcode > (int) BINOP_END) - { - /* Unary prefix operator. */ - fprintf (stream, "%s", op_str); - print_subexp (exp, pos, stream, PREC_PREFIX); - } - else - { - /* Binary operator. */ - /* Print left operand. - If operator is right-associative, - increment precedence for this operand. */ - print_subexp (exp, pos, stream, (int) myprec + assoc); - /* Print the operator itself. */ - if (assign_modify) - fprintf (stream, " %s= ", op_str); - else if (op_str[0] == ',') - fprintf (stream, "%s ", op_str); - else - fprintf (stream, " %s ", op_str); - /* Print right operand. - If operator is left-associative, - increment precedence for this operand. */ - print_subexp (exp, pos, stream, (int) myprec + !assoc); - } - if ((int) myprec < (int) prec) - fprintf (stream, ")"); -} diff --git a/gnu/usr.bin/gdb/expread.y b/gnu/usr.bin/gdb/expread.y deleted file mode 100644 index 96a12c4..0000000 --- a/gnu/usr.bin/gdb/expread.y +++ /dev/null @@ -1,1782 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -/* Parse C expressions for GDB. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Parse a C expression from text in a string, - and return the result as a struct expression pointer. - That structure contains arithmetic operations in reverse polish, - with constants represented by operations that are followed by special data. - See expression.h for the details of the format. - What is important here is that it can be built up sequentially - during the process of parsing; the lower levels of the tree always - come first in the result. */ - -%{ -#ifndef lint -static char sccsid[] = "@(#)expread.y 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -#include -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "frame.h" -#include "expression.h" - -#include - -static struct expression *expout; -static int expout_size; -static int expout_ptr; - -static int yylex (); -static void yyerror (); -static void write_exp_elt (); -static void write_exp_elt_opcode (); -static void write_exp_elt_sym (); -static void write_exp_elt_longcst (); -static void write_exp_elt_dblcst (); -static void write_exp_elt_type (); -static void write_exp_elt_intern (); -static void write_exp_string (); -static void start_arglist (); -static int end_arglist (); -static void free_funcalls (); -static char *copy_name (); - -/* If this is nonzero, this block is used as the lexical context - for symbol names. */ - -static struct block *expression_context_block; - -/* The innermost context required by the stack and register variables - we've encountered so far. */ -struct block *innermost_block; - -/* The block in which the most recently discovered symbol was found. */ -struct block *block_found; - -/* Number of arguments seen so far in innermost function call. */ -static int arglist_len; - -/* Data structure for saving values of arglist_len - for function calls whose arguments contain other function calls. */ - -struct funcall - { - struct funcall *next; - int arglist_len; - }; - -struct funcall *funcall_chain; - -/* This kind of datum is used to represent the name - of a symbol token. */ - -struct stoken - { - char *ptr; - int length; - }; - -/* For parsing of complicated types. - An array should be preceded in the list by the size of the array. */ -enum type_pieces - {tp_end = -1, tp_pointer, tp_reference, tp_array, tp_function}; -static enum type_pieces *type_stack; -static int type_stack_depth, type_stack_size; - -static void push_type (); -static enum type_pieces pop_type (); - -/* Allow debugging of parsing. */ -#define YYDEBUG 1 -%} - -/* Although the yacc "value" of an expression is not used, - since the result is stored in the structure being created, - other node types do have values. */ - -%union - { - LONGEST lval; - unsigned LONGEST ulval; - double dval; - struct symbol *sym; - struct type *tval; - struct stoken sval; - int voidval; - struct block *bval; - enum exp_opcode opcode; - struct internalvar *ivar; - - struct type **tvec; - int *ivec; - } - -%type exp exp1 start variable -%type type typebase -%type nonempty_typelist -%type block - -/* Fancy type parsing. */ -%type func_mod direct_abs_decl abs_decl -%type ptype -%type array_mod - -%token INT CHAR -%token UINT -%token FLOAT - -/* Both NAME and TYPENAME tokens represent symbols in the input, - and both convey their data as strings. - But a TYPENAME is a string that happens to be defined as a typedef - or builtin type name (such as int or char) - and a NAME is any other symbol. - - Contexts where this distinction is not important can use the - nonterminal "name", which matches either NAME or TYPENAME. */ - -%token NAME TYPENAME BLOCKNAME STRING -%type name name_not_typename typename - -%token STRUCT UNION ENUM SIZEOF UNSIGNED COLONCOLON - -/* Special type cases, put in to allow the parser to distinguish different - legal basetypes. */ -%token SIGNED LONG SHORT INT_KEYWORD - -%token LAST REGNAME - -%token VARIABLE - -%token ASSIGN_MODIFY - -/* C++ */ -%token THIS - -%left ',' -%left ABOVE_COMMA -%right '=' ASSIGN_MODIFY -%right '?' -%left OR -%left AND -%left '|' -%left '^' -%left '&' -%left EQUAL NOTEQUAL -%left '<' '>' LEQ GEQ -%left LSH RSH -%left '@' -%left '+' '-' -%left '*' '/' '%' -%right UNARY INCREMENT DECREMENT -%right ARROW '.' '[' '(' -%left COLONCOLON - -%% - -start : exp1 - ; - -/* Expressions, including the comma operator. */ -exp1 : exp - | exp1 ',' exp - { write_exp_elt_opcode (BINOP_COMMA); } - ; - -/* Expressions, not including the comma operator. */ -exp : '*' exp %prec UNARY - { write_exp_elt_opcode (UNOP_IND); } - -exp : '&' exp %prec UNARY - { write_exp_elt_opcode (UNOP_ADDR); } - -exp : '-' exp %prec UNARY - { write_exp_elt_opcode (UNOP_NEG); } - ; - -exp : '!' exp %prec UNARY - { write_exp_elt_opcode (UNOP_ZEROP); } - ; - -exp : '~' exp %prec UNARY - { write_exp_elt_opcode (UNOP_LOGNOT); } - ; - -exp : INCREMENT exp %prec UNARY - { write_exp_elt_opcode (UNOP_PREINCREMENT); } - ; - -exp : DECREMENT exp %prec UNARY - { write_exp_elt_opcode (UNOP_PREDECREMENT); } - ; - -exp : exp INCREMENT %prec UNARY - { write_exp_elt_opcode (UNOP_POSTINCREMENT); } - ; - -exp : exp DECREMENT %prec UNARY - { write_exp_elt_opcode (UNOP_POSTDECREMENT); } - ; - -exp : SIZEOF exp %prec UNARY - { write_exp_elt_opcode (UNOP_SIZEOF); } - ; - -exp : exp ARROW name - { write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string ($3); - write_exp_elt_opcode (STRUCTOP_PTR); } - ; - -exp : exp ARROW '*' exp - { write_exp_elt_opcode (STRUCTOP_MPTR); } - ; - -exp : exp '.' name - { write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string ($3); - write_exp_elt_opcode (STRUCTOP_STRUCT); } - ; - -exp : exp '.' '*' exp - { write_exp_elt_opcode (STRUCTOP_MEMBER); } - ; - -exp : exp '[' exp1 ']' - { write_exp_elt_opcode (BINOP_SUBSCRIPT); } - ; - -exp : exp '(' - /* This is to save the value of arglist_len - being accumulated by an outer function call. */ - { start_arglist (); } - arglist ')' %prec ARROW - { write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_FUNCALL); } - ; - -arglist : - ; - -arglist : exp - { arglist_len = 1; } - ; - -arglist : arglist ',' exp %prec ABOVE_COMMA - { arglist_len++; } - ; - -exp : '{' type '}' exp %prec UNARY - { write_exp_elt_opcode (UNOP_MEMVAL); - write_exp_elt_type ($2); - write_exp_elt_opcode (UNOP_MEMVAL); } - ; - -exp : '(' type ')' exp %prec UNARY - { write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type ($2); - write_exp_elt_opcode (UNOP_CAST); } - ; - -exp : '(' exp1 ')' - { } - ; - -/* Binary operators in order of decreasing precedence. */ - -exp : exp '@' exp - { write_exp_elt_opcode (BINOP_REPEAT); } - ; - -exp : exp '*' exp - { write_exp_elt_opcode (BINOP_MUL); } - ; - -exp : exp '/' exp - { write_exp_elt_opcode (BINOP_DIV); } - ; - -exp : exp '%' exp - { write_exp_elt_opcode (BINOP_REM); } - ; - -exp : exp '+' exp - { write_exp_elt_opcode (BINOP_ADD); } - ; - -exp : exp '-' exp - { write_exp_elt_opcode (BINOP_SUB); } - ; - -exp : exp LSH exp - { write_exp_elt_opcode (BINOP_LSH); } - ; - -exp : exp RSH exp - { write_exp_elt_opcode (BINOP_RSH); } - ; - -exp : exp EQUAL exp - { write_exp_elt_opcode (BINOP_EQUAL); } - ; - -exp : exp NOTEQUAL exp - { write_exp_elt_opcode (BINOP_NOTEQUAL); } - ; - -exp : exp LEQ exp - { write_exp_elt_opcode (BINOP_LEQ); } - ; - -exp : exp GEQ exp - { write_exp_elt_opcode (BINOP_GEQ); } - ; - -exp : exp '<' exp - { write_exp_elt_opcode (BINOP_LESS); } - ; - -exp : exp '>' exp - { write_exp_elt_opcode (BINOP_GTR); } - ; - -exp : exp '&' exp - { write_exp_elt_opcode (BINOP_LOGAND); } - ; - -exp : exp '^' exp - { write_exp_elt_opcode (BINOP_LOGXOR); } - ; - -exp : exp '|' exp - { write_exp_elt_opcode (BINOP_LOGIOR); } - ; - -exp : exp AND exp - { write_exp_elt_opcode (BINOP_AND); } - ; - -exp : exp OR exp - { write_exp_elt_opcode (BINOP_OR); } - ; - -exp : exp '?' exp ':' exp %prec '?' - { write_exp_elt_opcode (TERNOP_COND); } - ; - -exp : exp '=' exp - { write_exp_elt_opcode (BINOP_ASSIGN); } - ; - -exp : exp ASSIGN_MODIFY exp - { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode ($2); - write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } - ; - -exp : INT - { write_exp_elt_opcode (OP_LONG); - if ($1 == (int) $1 || $1 == (unsigned int) $1) - write_exp_elt_type (builtin_type_int); - else - write_exp_elt_type (BUILTIN_TYPE_LONGEST); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_LONG); } - ; - -exp : UINT - { - write_exp_elt_opcode (OP_LONG); - if ($1 == (unsigned int) $1) - write_exp_elt_type (builtin_type_unsigned_int); - else - write_exp_elt_type (BUILTIN_TYPE_UNSIGNED_LONGEST); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_LONG); - } - ; - -exp : CHAR - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_char); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_LONG); } - ; - -exp : FLOAT - { write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type (builtin_type_double); - write_exp_elt_dblcst ($1); - write_exp_elt_opcode (OP_DOUBLE); } - ; - -exp : variable - ; - -exp : LAST - { write_exp_elt_opcode (OP_LAST); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_LAST); } - ; - -exp : REGNAME - { write_exp_elt_opcode (OP_REGISTER); - write_exp_elt_longcst ((LONGEST) $1); - write_exp_elt_opcode (OP_REGISTER); } - ; - -exp : VARIABLE - { write_exp_elt_opcode (OP_INTERNALVAR); - write_exp_elt_intern ($1); - write_exp_elt_opcode (OP_INTERNALVAR); } - ; - -exp : SIZEOF '(' type ')' %prec UNARY - { write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_int); - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3)); - write_exp_elt_opcode (OP_LONG); } - ; - -exp : STRING - { write_exp_elt_opcode (OP_STRING); - write_exp_string ($1); - write_exp_elt_opcode (OP_STRING); } - ; - -/* C++. */ -exp : THIS - { write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (OP_THIS); } - ; - -/* end of C++. */ - -block : BLOCKNAME - { - struct symtab *tem = lookup_symtab (copy_name ($1)); - struct symbol *sym; - - if (tem) - $$ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), 1); - else - { - sym = lookup_symbol (copy_name ($1), - expression_context_block, - VAR_NAMESPACE, 0); - if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) - $$ = SYMBOL_BLOCK_VALUE (sym); - else - error ("No file or function \"%s\".", - copy_name ($1)); - } - } - ; - -block : block COLONCOLON name - { struct symbol *tem - = lookup_symbol (copy_name ($3), $1, VAR_NAMESPACE, 0); - if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK) - error ("No function \"%s\" in specified context.", - copy_name ($3)); - $$ = SYMBOL_BLOCK_VALUE (tem); } - ; - -variable: block COLONCOLON name - { struct symbol *sym; - sym = lookup_symbol (copy_name ($3), $1, VAR_NAMESPACE, 0); - if (sym == 0) - error ("No symbol \"%s\" in specified context.", - copy_name ($3)); - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); } - ; - -variable: typebase COLONCOLON name - { - struct type *type = $1; - if (TYPE_CODE (type) != TYPE_CODE_STRUCT - && TYPE_CODE (type) != TYPE_CODE_UNION) - error ("`%s' is not defined as an aggregate type.", - TYPE_NAME (type)); - - write_exp_elt_opcode (OP_SCOPE); - write_exp_elt_type (type); - write_exp_string ($3); - write_exp_elt_opcode (OP_SCOPE); - } - | COLONCOLON name - { - char *name = copy_name ($2); - struct symbol *sym; - int i; - - sym = lookup_symbol (name, 0, VAR_NAMESPACE, 0); - if (sym) - { - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); - break; - } - for (i = 0; i < misc_function_count; i++) - if (!strcmp (misc_function_vector[i].name, name)) - break; - - if (i < misc_function_count) - { - enum misc_function_type mft = - (enum misc_function_type) - misc_function_vector[i].type; - - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_int); - write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_opcode (UNOP_MEMVAL); - if (mft == mf_data || mft == mf_bss) - write_exp_elt_type (builtin_type_int); - else if (mft == mf_text) - write_exp_elt_type (lookup_function_type (builtin_type_int)); - else - write_exp_elt_type (builtin_type_char); - write_exp_elt_opcode (UNOP_MEMVAL); - } - else - if (symtab_list == 0 - && partial_symtab_list == 0) - error ("No symbol table is loaded. Use the \"symbol-file\" command."); - else - error ("No symbol \"%s\" in current context.", name); - } - ; - -variable: name_not_typename - { struct symbol *sym; - int is_a_field_of_this; - - sym = lookup_symbol (copy_name ($1), - expression_context_block, - VAR_NAMESPACE, - &is_a_field_of_this); - if (sym) - { - switch (sym->class) - { - case LOC_REGISTER: - case LOC_ARG: - case LOC_LOCAL: - if (innermost_block == 0 || - contained_in (block_found, - innermost_block)) - innermost_block = block_found; - } - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); - } - else if (is_a_field_of_this) - { - /* C++: it hangs off of `this'. Must - not inadvertently convert from a method call - to data ref. */ - if (innermost_block == 0 || - contained_in (block_found, innermost_block)) - innermost_block = block_found; - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string ($1); - write_exp_elt_opcode (STRUCTOP_PTR); - } - else - { - register int i; - register char *arg = copy_name ($1); - - for (i = 0; i < misc_function_count; i++) - if (!strcmp (misc_function_vector[i].name, arg)) - break; - - if (i < misc_function_count) - { - enum misc_function_type mft = - (enum misc_function_type) - misc_function_vector[i].type; - - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_int); - write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_opcode (UNOP_MEMVAL); - if (mft == mf_data || mft == mf_bss) - write_exp_elt_type (builtin_type_int); - else if (mft == mf_text) - write_exp_elt_type (lookup_function_type (builtin_type_int)); - else - write_exp_elt_type (builtin_type_char); - write_exp_elt_opcode (UNOP_MEMVAL); - } - else if (symtab_list == 0 - && partial_symtab_list == 0) - error ("No symbol table is loaded. Use the \"symbol-file\" command."); - else - error ("No symbol \"%s\" in current context.", - copy_name ($1)); - } - } - ; - - -ptype : typebase - | typebase abs_decl - { - /* This is where the interesting stuff happens. */ - int done = 0; - int array_size; - struct type *follow_type = $1; - - while (!done) - switch (pop_type ()) - { - case tp_end: - done = 1; - break; - case tp_pointer: - follow_type = lookup_pointer_type (follow_type); - break; - case tp_reference: - follow_type = lookup_reference_type (follow_type); - break; - case tp_array: - array_size = (int) pop_type (); - if (array_size != -1) - follow_type = create_array_type (follow_type, - array_size); - else - follow_type = lookup_pointer_type (follow_type); - break; - case tp_function: - follow_type = lookup_function_type (follow_type); - break; - } - $$ = follow_type; - } - ; - -abs_decl: '*' - { push_type (tp_pointer); $$ = 0; } - | '*' abs_decl - { push_type (tp_pointer); $$ = $2; } - | direct_abs_decl - ; - -direct_abs_decl: '(' abs_decl ')' - { $$ = $2; } - | direct_abs_decl array_mod - { - push_type ((enum type_pieces) $2); - push_type (tp_array); - } - | array_mod - { - push_type ((enum type_pieces) $1); - push_type (tp_array); - $$ = 0; - } - | direct_abs_decl func_mod - { push_type (tp_function); } - | func_mod - { push_type (tp_function); } - ; - -array_mod: '[' ']' - { $$ = -1; } - | '[' INT ']' - { $$ = $2; } - ; - -func_mod: '(' ')' - { $$ = 0; } - ; - -type : ptype - | typebase COLONCOLON '*' - { $$ = lookup_member_type (builtin_type_int, $1); } - | type '(' typebase COLONCOLON '*' ')' - { $$ = lookup_member_type ($1, $3); } - | type '(' typebase COLONCOLON '*' ')' '(' ')' - { $$ = lookup_member_type - (lookup_function_type ($1), $3); } - | type '(' typebase COLONCOLON '*' ')' '(' nonempty_typelist ')' - { $$ = lookup_member_type - (lookup_function_type ($1), $3); - free ($8); } - ; - -typebase - : TYPENAME - { $$ = lookup_typename (copy_name ($1), - expression_context_block, 0); } - | INT_KEYWORD - { $$ = builtin_type_int; } - | LONG - { $$ = builtin_type_long; } - | SHORT - { $$ = builtin_type_short; } - | LONG INT_KEYWORD - { $$ = builtin_type_long; } - | UNSIGNED LONG INT_KEYWORD - { $$ = builtin_type_unsigned_long; } - | SHORT INT_KEYWORD - { $$ = builtin_type_short; } - | UNSIGNED SHORT INT_KEYWORD - { $$ = builtin_type_unsigned_short; } - | STRUCT name - { $$ = lookup_struct (copy_name ($2), - expression_context_block); } - | UNION name - { $$ = lookup_union (copy_name ($2), - expression_context_block); } - | ENUM name - { $$ = lookup_enum (copy_name ($2), - expression_context_block); } - | UNSIGNED typename - { $$ = lookup_unsigned_typename (copy_name ($2)); } - | UNSIGNED - { $$ = builtin_type_unsigned_int; } - | SIGNED typename - { $$ = lookup_typename (copy_name ($2), - expression_context_block, 0); } - | SIGNED - { $$ = builtin_type_int; } - ; - -typename: TYPENAME - | INT_KEYWORD - { - $$.ptr = "int"; - $$.length = 3; - } - | LONG - { - $$.ptr = "long"; - $$.length = 4; - } - | SHORT - { - $$.ptr = "short"; - $$.length = 5; - } - ; - -nonempty_typelist - : type - { $$ = (struct type **)xmalloc (sizeof (struct type *) * 2); - $$[0] = (struct type *)0; - $$[1] = $1; - } - | nonempty_typelist ',' type - { int len = sizeof (struct type *) * ++($1[0]); - $$ = (struct type **)xrealloc ($1, len); - $$[$$[0]] = $3; - } - ; - -name : NAME - | BLOCKNAME - | TYPENAME - ; - -name_not_typename : NAME - | BLOCKNAME - ; - -%% - -/* Begin counting arguments for a function call, - saving the data about any containing call. */ - -static void -start_arglist () -{ - register struct funcall *new = (struct funcall *) xmalloc (sizeof (struct funcall)); - - new->next = funcall_chain; - new->arglist_len = arglist_len; - arglist_len = 0; - funcall_chain = new; -} - -/* Return the number of arguments in a function call just terminated, - and restore the data for the containing function call. */ - -static int -end_arglist () -{ - register int val = arglist_len; - register struct funcall *call = funcall_chain; - funcall_chain = call->next; - arglist_len = call->arglist_len; - free (call); - return val; -} - -/* Free everything in the funcall chain. - Used when there is an error inside parsing. */ - -static void -free_funcalls () -{ - register struct funcall *call, *next; - - for (call = funcall_chain; call; call = next) - { - next = call->next; - free (call); - } -} - -/* This page contains the functions for adding data to the struct expression - being constructed. */ - -/* Add one element to the end of the expression. */ - -/* To avoid a bug in the Sun 4 compiler, we pass things that can fit into - a register through here */ - -static void -write_exp_elt (expelt) - union exp_element expelt; -{ - if (expout_ptr >= expout_size) - { - expout_size *= 2; - expout = (struct expression *) xrealloc (expout, - sizeof (struct expression) - + expout_size * sizeof (union exp_element)); - } - expout->elts[expout_ptr++] = expelt; -} - -static void -write_exp_elt_opcode (expelt) - enum exp_opcode expelt; -{ - union exp_element tmp; - - tmp.opcode = expelt; - - write_exp_elt (tmp); -} - -static void -write_exp_elt_sym (expelt) - struct symbol *expelt; -{ - union exp_element tmp; - - tmp.symbol = expelt; - - write_exp_elt (tmp); -} - -static void -write_exp_elt_longcst (expelt) - LONGEST expelt; -{ - union exp_element tmp; - - tmp.longconst = expelt; - - write_exp_elt (tmp); -} - -static void -write_exp_elt_dblcst (expelt) - double expelt; -{ - union exp_element tmp; - - tmp.doubleconst = expelt; - - write_exp_elt (tmp); -} - -static void -write_exp_elt_type (expelt) - struct type *expelt; -{ - union exp_element tmp; - - tmp.type = expelt; - - write_exp_elt (tmp); -} - -static void -write_exp_elt_intern (expelt) - struct internalvar *expelt; -{ - union exp_element tmp; - - tmp.internalvar = expelt; - - write_exp_elt (tmp); -} - -/* Add a string constant to the end of the expression. - Follow it by its length in bytes, as a separate exp_element. */ - -static void -write_exp_string (str) - struct stoken str; -{ - register int len = str.length; - register int lenelt - = (len + sizeof (union exp_element)) / sizeof (union exp_element); - - expout_ptr += lenelt; - - if (expout_ptr >= expout_size) - { - expout_size = max (expout_size * 2, expout_ptr + 10); - expout = (struct expression *) - xrealloc (expout, (sizeof (struct expression) - + (expout_size * sizeof (union exp_element)))); - } - bcopy (str.ptr, (char *) &expout->elts[expout_ptr - lenelt], len); - ((char *) &expout->elts[expout_ptr - lenelt])[len] = 0; - write_exp_elt_longcst ((LONGEST) len); -} - -/* During parsing of a C expression, the pointer to the next character - is in this variable. */ - -static char *lexptr; - -/* Tokens that refer to names do so with explicit pointer and length, - so they can share the storage that lexptr is parsing. - - When it is necessary to pass a name to a function that expects - a null-terminated string, the substring is copied out - into a block of storage that namecopy points to. - - namecopy is allocated once, guaranteed big enough, for each parsing. */ - -static char *namecopy; - -/* Current depth in parentheses within the expression. */ - -static int paren_depth; - -/* Nonzero means stop parsing on first comma (if not within parentheses). */ - -static int comma_terminates; - -/* Take care of parsing a number (anything that starts with a digit). - Set yylval and return the token type; update lexptr. - LEN is the number of characters in it. */ - -/*** Needs some error checking for the float case ***/ - -static int -parse_number (olen) - int olen; -{ - register char *p = lexptr; - register LONGEST n = 0; - register int c; - register int base = 10; - register int len = olen; - char *err_copy; - int unsigned_p = 0; - - extern double atof (); - - for (c = 0; c < len; c++) - if (p[c] == '.') - { - /* It's a float since it contains a point. */ - yylval.dval = atof (p); - lexptr += len; - return FLOAT; - } - - if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2))) - { - p += 2; - base = 16; - len -= 2; - } - else if (*p == '0') - base = 8; - - while (len-- > 0) - { - c = *p++; - if (c >= 'A' && c <= 'Z') c += 'a' - 'A'; - if (c != 'l' && c != 'u') - n *= base; - if (c >= '0' && c <= '9') - n += c - '0'; - else - { - if (base == 16 && c >= 'a' && c <= 'f') - n += c - 'a' + 10; - else if (len == 0 && c == 'l') - ; - else if (len == 0 && c == 'u') - unsigned_p = 1; - else if (base == 10 && len != 0 && (c == 'e' || c == 'E')) - { - /* Scientific notation, where we are unlucky enough not - to have a '.' in the string. */ - yylval.dval = atof (lexptr); - lexptr += olen; - return FLOAT; - } - else - { - err_copy = (char *) alloca (olen + 1); - bcopy (lexptr, err_copy, olen); - err_copy[olen] = 0; - error ("Invalid number \"%s\".", err_copy); - } - } - } - - lexptr = p; - if (unsigned_p) - { - yylval.ulval = n; - return UINT; - } - else - { - yylval.lval = n; - return INT; - } -} - -struct token -{ - char *operator; - int token; - enum exp_opcode opcode; -}; - -static struct token tokentab3[] = - { - {">>=", ASSIGN_MODIFY, BINOP_RSH}, - {"<<=", ASSIGN_MODIFY, BINOP_LSH} - }; - -static struct token tokentab2[] = - { - {"+=", ASSIGN_MODIFY, BINOP_ADD}, - {"-=", ASSIGN_MODIFY, BINOP_SUB}, - {"*=", ASSIGN_MODIFY, BINOP_MUL}, - {"/=", ASSIGN_MODIFY, BINOP_DIV}, - {"%=", ASSIGN_MODIFY, BINOP_REM}, - {"|=", ASSIGN_MODIFY, BINOP_LOGIOR}, - {"&=", ASSIGN_MODIFY, BINOP_LOGAND}, - {"^=", ASSIGN_MODIFY, BINOP_LOGXOR}, - {"++", INCREMENT, BINOP_END}, - {"--", DECREMENT, BINOP_END}, - {"->", ARROW, BINOP_END}, - {"&&", AND, BINOP_END}, - {"||", OR, BINOP_END}, - {"::", COLONCOLON, BINOP_END}, - {"<<", LSH, BINOP_END}, - {">>", RSH, BINOP_END}, - {"==", EQUAL, BINOP_END}, - {"!=", NOTEQUAL, BINOP_END}, - {"<=", LEQ, BINOP_END}, - {">=", GEQ, BINOP_END} - }; - -/* assign machine-independent names to certain registers - * (unless overridden by the REGISTER_NAMES table) - */ -struct std_regs { - char *name; - int regnum; -} std_regs[] = { -#ifdef PC_REGNUM - { "pc", PC_REGNUM }, -#endif -#ifdef FP_REGNUM - { "fp", FP_REGNUM }, -#endif -#ifdef SP_REGNUM - { "sp", SP_REGNUM }, -#endif -#ifdef PS_REGNUM - { "ps", PS_REGNUM }, -#endif -}; - -#define NUM_STD_REGS (sizeof std_regs / sizeof std_regs[0]) - -/* Read one token, getting characters through lexptr. */ - -static int -yylex () -{ - register int c; - register int namelen; - register int i; - register char *tokstart; - - retry: - - tokstart = lexptr; - /* See if it is a special token of length 3. */ - for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++) - if (!strncmp (tokstart, tokentab3[i].operator, 3)) - { - lexptr += 3; - yylval.opcode = tokentab3[i].opcode; - return tokentab3[i].token; - } - - /* See if it is a special token of length 2. */ - for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++) - if (!strncmp (tokstart, tokentab2[i].operator, 2)) - { - lexptr += 2; - yylval.opcode = tokentab2[i].opcode; - return tokentab2[i].token; - } - - switch (c = *tokstart) - { - case 0: - return 0; - - case ' ': - case '\t': - case '\n': - lexptr++; - goto retry; - - case '\'': - lexptr++; - c = *lexptr++; - if (c == '\\') - c = parse_escape (&lexptr); - yylval.lval = c; - c = *lexptr++; - if (c != '\'') - error ("Invalid character constant."); - return CHAR; - - case '(': - paren_depth++; - lexptr++; - return c; - - case ')': - if (paren_depth == 0) - return 0; - paren_depth--; - lexptr++; - return c; - - case ',': - if (comma_terminates && paren_depth == 0) - return 0; - lexptr++; - return c; - - case '.': - /* Might be a floating point number. */ - if (lexptr[1] >= '0' && lexptr[1] <= '9') - break; /* Falls into number code. */ - - case '+': - case '-': - case '*': - case '/': - case '%': - case '|': - case '&': - case '^': - case '~': - case '!': - case '@': - case '<': - case '>': - case '[': - case ']': - case '?': - case ':': - case '=': - case '{': - case '}': - lexptr++; - return c; - - case '"': - for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++) - if (c == '\\') - { - c = tokstart[++namelen]; - if (c >= '0' && c <= '9') - { - c = tokstart[++namelen]; - if (c >= '0' && c <= '9') - c = tokstart[++namelen]; - } - } - yylval.sval.ptr = tokstart + 1; - yylval.sval.length = namelen - 1; - lexptr += namelen + 1; - return STRING; - } - - /* Is it a number? */ - /* Note: We have already dealt with the case of the token '.'. - See case '.' above. */ - if ((c >= '0' && c <= '9') || c == '.') - { - /* It's a number. */ - int got_dot = 0, got_e = 0; - register char *p = tokstart; - int hex = c == '0' && (p[1] == 'x' || p[1] == 'X'); - if (hex) - p += 2; - for (;; ++p) - { - if (!hex && !got_e && (*p == 'e' || *p == 'E')) - got_dot = got_e = 1; - else if (!hex && !got_dot && *p == '.') - got_dot = 1; - else if (got_e && (p[-1] == 'e' || p[-1] == 'E') - && (*p == '-' || *p == '+')) - /* This is the sign of the exponent, not the end of the - number. */ - continue; - else if (!got_dot && !got_e && (*p=='l'||*p=='L')){ - ++p; break; - } - else if (!got_dot && !got_e && !hex && (*p=='u'||*p=='U')){ - ++p; break; - } - else if (*p < '0' || *p > '9' - && (!hex || ((*p < 'a' || *p > 'f') - && (*p < 'A' || *p > 'F')))) - break; - } - return parse_number (p - tokstart); - } - - if (!(c == '_' || c == '$' - || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) - /* We must have come across a bad character (e.g. ';'). */ - error ("Invalid character '%c' in expression.", c); - - /* It's a name. See how long it is. */ - namelen = 0; - for (c = tokstart[namelen]; - (c == '_' || c == '$' || (c >= '0' && c <= '9') - || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); - c = tokstart[++namelen]) - ; - - /* The token "if" terminates the expression and is NOT - removed from the input stream. */ - if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f') - { - return 0; - } - - lexptr += namelen; - - /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1) - and $$digits (equivalent to $<-digits> if you could type that). - Make token type LAST, and put the number (the digits) in yylval. */ - - if (*tokstart == '$') - { - register int negate = 0; - c = 1; - /* Double dollar means negate the number and add -1 as well. - Thus $$ alone means -1. */ - if (namelen >= 2 && tokstart[1] == '$') - { - negate = 1; - c = 2; - } - if (c == namelen) - { - /* Just dollars (one or two) */ - yylval.lval = - negate; - return LAST; - } - /* Is the rest of the token digits? */ - for (; c < namelen; c++) - if (!(tokstart[c] >= '0' && tokstart[c] <= '9')) - break; - if (c == namelen) - { - yylval.lval = atoi (tokstart + 1 + negate); - if (negate) - yylval.lval = - yylval.lval; - return LAST; - } - } - - /* Handle tokens that refer to machine registers: - $ followed by a register name. */ - - if (*tokstart == '$') { - for (c = 0; c < NUM_REGS; c++) - if (namelen - 1 == strlen (reg_names[c]) - && !strncmp (tokstart + 1, reg_names[c], namelen - 1)) - { - yylval.lval = c; - return REGNAME; - } - for (c = 0; c < NUM_STD_REGS; c++) - if (namelen - 1 == strlen (std_regs[c].name) - && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1)) - { - yylval.lval = std_regs[c].regnum; - return REGNAME; - } - } - /* Catch specific keywords. Should be done with a data structure. */ - switch (namelen) - { - case 8: - if (!strncmp (tokstart, "unsigned", 8)) - return UNSIGNED; - break; - case 6: - if (!strncmp (tokstart, "struct", 6)) - return STRUCT; - if (!strncmp (tokstart, "signed", 6)) - return SIGNED; - if (!strncmp (tokstart, "sizeof", 6)) - return SIZEOF; - break; - case 5: - if (!strncmp (tokstart, "union", 5)) - return UNION; - if (!strncmp (tokstart, "short", 5)) - return SHORT; - break; - case 4: - if (!strncmp (tokstart, "enum", 4)) - return ENUM; - if (!strncmp (tokstart, "long", 4)) - return LONG; - if (!strncmp (tokstart, "this", 4) - && lookup_symbol ("$this", expression_context_block, - VAR_NAMESPACE, 0)) - return THIS; - break; - case 3: - if (!strncmp (tokstart, "int", 3)) - return INT_KEYWORD; - break; - default: - break; - } - - yylval.sval.ptr = tokstart; - yylval.sval.length = namelen; - - /* Any other names starting in $ are debugger internal variables. */ - - if (*tokstart == '$') - { - yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1); - return VARIABLE; - } - - /* Use token-type BLOCKNAME for symbols that happen to be defined as - functions or symtabs. If this is not so, then ... - Use token-type TYPENAME for symbols that happen to be defined - currently as names of types; NAME for other symbols. - The caller is not constrained to care about the distinction. */ - { - char *tmp = copy_name (yylval.sval); - struct symbol *sym; - - if (lookup_partial_symtab (tmp)) - return BLOCKNAME; - sym = lookup_symbol (tmp, expression_context_block, - VAR_NAMESPACE, 0); - if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) - return BLOCKNAME; - if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1)) - return TYPENAME; - return NAME; - } -} - -static void -yyerror () -{ - error ("Invalid syntax in expression."); -} - -/* Return a null-terminated temporary copy of the name - of a string token. */ - -static char * -copy_name (token) - struct stoken token; -{ - bcopy (token.ptr, namecopy, token.length); - namecopy[token.length] = 0; - return namecopy; -} - -/* Reverse an expression from suffix form (in which it is constructed) - to prefix form (in which we can conveniently print or execute it). */ - -static void prefixify_subexp (); - -static void -prefixify_expression (expr) - register struct expression *expr; -{ - register int len = sizeof (struct expression) + - expr->nelts * sizeof (union exp_element); - register struct expression *temp; - register int inpos = expr->nelts, outpos = 0; - - temp = (struct expression *) alloca (len); - - /* Copy the original expression into temp. */ - bcopy (expr, temp, len); - - prefixify_subexp (temp, expr, inpos, outpos); -} - -/* Return the number of exp_elements in the subexpression of EXPR - whose last exp_element is at index ENDPOS - 1 in EXPR. */ - -static int -length_of_subexp (expr, endpos) - register struct expression *expr; - register int endpos; -{ - register int oplen = 1; - register int args = 0; - register int i; - - if (endpos < 0) - error ("?error in length_of_subexp"); - - i = (int) expr->elts[endpos - 1].opcode; - - switch (i) - { - /* C++ */ - case OP_SCOPE: - oplen = 4 + ((expr->elts[endpos - 2].longconst - + sizeof (union exp_element)) - / sizeof (union exp_element)); - break; - - case OP_LONG: - case OP_DOUBLE: - oplen = 4; - break; - - case OP_VAR_VALUE: - case OP_LAST: - case OP_REGISTER: - case OP_INTERNALVAR: - oplen = 3; - break; - - case OP_FUNCALL: - oplen = 3; - args = 1 + expr->elts[endpos - 2].longconst; - break; - - case UNOP_CAST: - case UNOP_MEMVAL: - oplen = 3; - args = 1; - break; - - case STRUCTOP_STRUCT: - case STRUCTOP_PTR: - args = 1; - case OP_STRING: - oplen = 3 + ((expr->elts[endpos - 2].longconst - + sizeof (union exp_element)) - / sizeof (union exp_element)); - break; - - case TERNOP_COND: - args = 3; - break; - - case BINOP_ASSIGN_MODIFY: - oplen = 3; - args = 2; - break; - - /* C++ */ - case OP_THIS: - oplen = 2; - break; - - default: - args = 1 + (i < (int) BINOP_END); - } - - while (args > 0) - { - oplen += length_of_subexp (expr, endpos - oplen); - args--; - } - - return oplen; -} - -/* Copy the subexpression ending just before index INEND in INEXPR - into OUTEXPR, starting at index OUTBEG. - In the process, convert it from suffix to prefix form. */ - -static void -prefixify_subexp (inexpr, outexpr, inend, outbeg) - register struct expression *inexpr; - struct expression *outexpr; - register int inend; - int outbeg; -{ - register int oplen = 1; - register int args = 0; - register int i; - int *arglens; - enum exp_opcode opcode; - - /* Compute how long the last operation is (in OPLEN), - and also how many preceding subexpressions serve as - arguments for it (in ARGS). */ - - opcode = inexpr->elts[inend - 1].opcode; - switch (opcode) - { - /* C++ */ - case OP_SCOPE: - oplen = 4 + ((inexpr->elts[inend - 2].longconst - + sizeof (union exp_element)) - / sizeof (union exp_element)); - break; - - case OP_LONG: - case OP_DOUBLE: - oplen = 4; - break; - - case OP_VAR_VALUE: - case OP_LAST: - case OP_REGISTER: - case OP_INTERNALVAR: - oplen = 3; - break; - - case OP_FUNCALL: - oplen = 3; - args = 1 + inexpr->elts[inend - 2].longconst; - break; - - case UNOP_CAST: - case UNOP_MEMVAL: - oplen = 3; - args = 1; - break; - - case STRUCTOP_STRUCT: - case STRUCTOP_PTR: - args = 1; - case OP_STRING: - oplen = 3 + ((inexpr->elts[inend - 2].longconst - + sizeof (union exp_element)) - / sizeof (union exp_element)); - - break; - - case TERNOP_COND: - args = 3; - break; - - case BINOP_ASSIGN_MODIFY: - oplen = 3; - args = 2; - break; - - /* C++ */ - case OP_THIS: - oplen = 2; - break; - - default: - args = 1 + ((int) opcode < (int) BINOP_END); - } - - /* Copy the final operator itself, from the end of the input - to the beginning of the output. */ - inend -= oplen; - bcopy (&inexpr->elts[inend], &outexpr->elts[outbeg], - oplen * sizeof (union exp_element)); - outbeg += oplen; - - /* Find the lengths of the arg subexpressions. */ - arglens = (int *) alloca (args * sizeof (int)); - for (i = args - 1; i >= 0; i--) - { - oplen = length_of_subexp (inexpr, inend); - arglens[i] = oplen; - inend -= oplen; - } - - /* Now copy each subexpression, preserving the order of - the subexpressions, but prefixifying each one. - In this loop, inend starts at the beginning of - the expression this level is working on - and marches forward over the arguments. - outbeg does similarly in the output. */ - for (i = 0; i < args; i++) - { - oplen = arglens[i]; - inend += oplen; - prefixify_subexp (inexpr, outexpr, inend, outbeg); - outbeg += oplen; - } -} - -/* This page contains the two entry points to this file. */ - -/* Read a C expression from the string *STRINGPTR points to, - parse it, and return a pointer to a struct expression that we malloc. - Use block BLOCK as the lexical context for variable names; - if BLOCK is zero, use the block of the selected stack frame. - Meanwhile, advance *STRINGPTR to point after the expression, - at the first nonwhite character that is not part of the expression - (possibly a null character). - - If COMMA is nonzero, stop if a comma is reached. */ - -struct expression * -parse_c_1 (stringptr, block, comma) - char **stringptr; - struct block *block; -{ - struct cleanup *old_chain; - - lexptr = *stringptr; - - paren_depth = 0; - type_stack_depth = 0; - - comma_terminates = comma; - - if (lexptr == 0 || *lexptr == 0) - error_no_arg ("expression to compute"); - - old_chain = make_cleanup (free_funcalls, 0); - funcall_chain = 0; - - expression_context_block = block ? block : get_selected_block (); - - namecopy = (char *) alloca (strlen (lexptr) + 1); - expout_size = 10; - expout_ptr = 0; - expout = (struct expression *) - xmalloc (sizeof (struct expression) - + expout_size * sizeof (union exp_element)); - make_cleanup (free_current_contents, &expout); - if (yyparse ()) - yyerror (); - discard_cleanups (old_chain); - expout->nelts = expout_ptr; - expout = (struct expression *) - xrealloc (expout, - sizeof (struct expression) - + expout_ptr * sizeof (union exp_element)); - prefixify_expression (expout); - *stringptr = lexptr; - return expout; -} - -/* Parse STRING as an expression, and complain if this fails - to use up all of the contents of STRING. */ - -struct expression * -parse_c_expression (string) - char *string; -{ - register struct expression *exp; - exp = parse_c_1 (&string, 0, 0); - if (*string) - error ("Junk after end of expression."); - return exp; -} - -static void -push_type (tp) - enum type_pieces tp; -{ - if (type_stack_depth == type_stack_size) - { - type_stack_size *= 2; - type_stack = (enum type_pieces *) - xrealloc (type_stack, type_stack_size * sizeof (enum type_pieces)); - } - type_stack[type_stack_depth++] = tp; -} - -static enum type_pieces -pop_type () -{ - if (type_stack_depth) - return type_stack[--type_stack_depth]; - return tp_end; -} - -void -_initialize_expread () -{ - type_stack_size = 80; - type_stack_depth = 0; - type_stack = (enum type_pieces *) - xmalloc (type_stack_size * sizeof (enum type_pieces)); -} diff --git a/gnu/usr.bin/gdb/expression.h b/gnu/usr.bin/gdb/expression.h deleted file mode 100644 index 5a5e20e..0000000 --- a/gnu/usr.bin/gdb/expression.h +++ /dev/null @@ -1,191 +0,0 @@ -/* Definitions for expressions stored in reversed prefix form, for GDB. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Definitions for saved C expressions. */ - -/* An expression is represented as a vector of union exp_element's. - Each exp_element is an opcode, except that some opcodes cause - the following exp_element to be treated as a long or double constant - or as a variable. The opcodes are obeyed, using a stack for temporaries. - The value is left on the temporary stack at the end. */ - -/* When it is necessary to include a string, - it can occupy as many exp_elements as it needs. - We find the length of the string using strlen, - divide to find out how many exp_elements are used up, - and skip that many. Strings, like numbers, are indicated - by the preceding opcode. */ - -enum exp_opcode -{ -/* BINOP_... operate on two values computed by following subexpressions, - replacing them by one result value. They take no immediate arguments. */ - BINOP_ADD, /* + */ - BINOP_SUB, /* - */ - BINOP_MUL, /* * */ - BINOP_DIV, /* / */ - BINOP_REM, /* % */ - BINOP_LSH, /* << */ - BINOP_RSH, /* >> */ - BINOP_AND, /* && */ - BINOP_OR, /* || */ - BINOP_LOGAND, /* & */ - BINOP_LOGIOR, /* | */ - BINOP_LOGXOR, /* ^ */ - BINOP_EQUAL, /* == */ - BINOP_NOTEQUAL, /* != */ - BINOP_LESS, /* < */ - BINOP_GTR, /* > */ - BINOP_LEQ, /* <= */ - BINOP_GEQ, /* >= */ - BINOP_REPEAT, /* @ */ - BINOP_ASSIGN, /* = */ - BINOP_COMMA, /* , */ - BINOP_SUBSCRIPT, /* x[y] */ - BINOP_EXP, /* Exponentiation */ - -/* C++. */ - BINOP_MIN, /* ? */ - BINOP_SCOPE, /* :: */ - - /* STRUCTOP_MEMBER is used for pointer-to-member constructs. - X . * Y translates into X STRUCTOP_MEMBER Y. */ - STRUCTOP_MEMBER, - /* STRUCTOP_MPTR is used for pointer-to-member constructs - when X is a pointer instead of an aggregate. */ - STRUCTOP_MPTR, -/* end of C++. */ - - BINOP_END, - - BINOP_ASSIGN_MODIFY, /* +=, -=, *=, and so on. - The following exp_element is another opcode, - a BINOP_, saying how to modify. - Then comes another BINOP_ASSIGN_MODIFY, - making three exp_elements in total. */ - -/* Operates on three values computed by following subexpressions. */ - TERNOP_COND, /* ?: */ - -/* The OP_... series take immediate following arguments. - After the arguments come another OP_... (the same one) - so that the grouping can be recognized from the end. */ - -/* OP_LONG is followed by a type pointer in the next exp_element - and the long constant value in the following exp_element. - Then comes another OP_LONG. - Thus, the operation occupies four exp_elements. */ - - OP_LONG, -/* OP_DOUBLE is similar but takes a double constant instead of a long one. */ - OP_DOUBLE, -/* OP_VAR_VALUE takes one struct symbol * in the following exp_element, - followed by another OP_VAR_VALUE, making three exp_elements. */ - OP_VAR_VALUE, -/* OP_LAST is followed by an integer in the next exp_element. - The integer is zero for the last value printed, - or it is the absolute number of a history element. - With another OP_LAST at the end, this makes three exp_elements. */ - OP_LAST, -/* OP_REGISTER is followed by an integer in the next exp_element. - This is the number of a register to fetch (as an int). - With another OP_REGISTER at the end, this makes three exp_elements. */ - OP_REGISTER, -/* OP_INTERNALVAR is followed by an internalvar ptr in the next exp_element. - With another OP_INTERNALVAR at the end, this makes three exp_elements. */ - OP_INTERNALVAR, -/* OP_FUNCALL is followed by an integer in the next exp_element. - The integer is the number of args to the function call. - That many plus one values from following subexpressions - are used, the first one being the function. - The integer is followed by a repeat of OP_FUNCALL, - making three exp_elements. */ - OP_FUNCALL, -/* OP_STRING represents a string constant. - Its format is the same as that of a STRUCTOP, but the string - data is just made into a string constant when the operation - is executed. */ - OP_STRING, - -/* UNOP_CAST is followed by a type pointer in the next exp_element. - With another UNOP_CAST at the end, this makes three exp_elements. - It casts the value of the following subexpression. */ - UNOP_CAST, -/* UNOP_MEMVAL is followed by a type pointer in the next exp_element - With another UNOP_MEMVAL at the end, this makes three exp_elements. - It casts the contents of the word addressed by the value of the - following subexpression. */ - UNOP_MEMVAL, -/* UNOP_... operate on one value from a following subexpression - and replace it with a result. They take no immediate arguments. */ - UNOP_NEG, /* Unary - */ - UNOP_ZEROP, /* Unary ! */ - UNOP_LOGNOT, /* Unary ~ */ - UNOP_IND, /* Unary * */ - UNOP_ADDR, /* Unary & */ - UNOP_PREINCREMENT, /* ++ before an expression */ - UNOP_POSTINCREMENT, /* ++ after an expression */ - UNOP_PREDECREMENT, /* -- before an expression */ - UNOP_POSTDECREMENT, /* -- after an expression */ - UNOP_SIZEOF, /* Unary sizeof (followed by expression) */ - -/* STRUCTOP_... operate on a value from a following subexpression - by extracting a structure component specified by a string - that appears in the following exp_elements (as many as needed). - STRUCTOP_STRUCT is used for "." and STRUCTOP_PTR for "->". - They differ only in the error message given in case the value is - not suitable or the structure component specified is not found. - - The length of the string follows in the next exp_element, - (after the string), followed by another STRUCTOP_... code. */ - STRUCTOP_STRUCT, - STRUCTOP_PTR, - -/* C++ */ - /* OP_THIS is just a placeholder for the class instance variable. - It just comes in a tight (OP_THIS, OP_THIS) pair. */ - OP_THIS, - - /* OP_SCOPE surrounds a type name and a field name. The type - name is encoded as one element, but the field name stays as - a string, which, of course, is variable length. */ - OP_SCOPE, - -}; - -union exp_element -{ - enum exp_opcode opcode; - struct symbol *symbol; - LONGEST longconst; - double doubleconst; - char string; - struct type *type; - struct internalvar *internalvar; -}; - -struct expression -{ - int nelts; - union exp_element elts[1]; -}; - -struct expression *parse_c_expression (); -struct expression *parse_c_1 (); diff --git a/gnu/usr.bin/gdb/findvar.c b/gnu/usr.bin/gdb/findvar.c deleted file mode 100644 index 0157d10..0000000 --- a/gnu/usr.bin/gdb/findvar.c +++ /dev/null @@ -1,579 +0,0 @@ -/* Find a variable's value in memory, for GDB, the GNU debugger. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "frame.h" -#include "value.h" - -CORE_ADDR read_register (); - -/* Return the address in which frame FRAME's value of register REGNUM - has been saved in memory. Or return zero if it has not been saved. - If REGNUM specifies the SP, the value we return is actually - the SP value, not an address where it was saved. */ - -CORE_ADDR -find_saved_register (frame, regnum) - FRAME frame; - int regnum; -{ - struct frame_info *fi; - struct frame_saved_regs saved_regs; - - register FRAME frame1 = 0; - register CORE_ADDR addr = 0; - -#ifdef HAVE_REGISTER_WINDOWS - /* We assume that a register in a register window will only be saved - in one place (since the name changes and disappears as you go - towards inner frames), so we only call get_frame_saved_regs on - the current frame. This is directly in contradiction to the - usage below, which assumes that registers used in a frame must be - saved in a lower (more interior) frame. This change is a result - of working on a register window machine; get_frame_saved_regs - always returns the registers saved within a frame, within the - context (register namespace) of that frame. */ - - /* However, note that we don't want this to return anything if - nothing is saved (if there's a frame inside of this one). Also, - callers to this routine asking for the stack pointer want the - stack pointer saved for *this* frame; this is returned from the - next frame. */ - - - if (REGISTER_IN_WINDOW_P(regnum)) - { - frame1 = get_next_frame (frame); - if (!frame1) return 0; /* Registers of this frame are - active. */ - - /* Get the SP from the next frame in; it will be this - current frame. */ - if (regnum != SP_REGNUM) - frame1 = frame; - - fi = get_frame_info (frame1); - get_frame_saved_regs (fi, &saved_regs); - return (saved_regs.regs[regnum] ? - saved_regs.regs[regnum] : 0); - } -#endif /* HAVE_REGISTER_WINDOWS */ - - /* Note that this next routine assumes that registers used in - frame x will be saved only in the frame that x calls and - frames interior to it. This is not true on the sparc, but the - above macro takes care of it, so we should be all right. */ - while (1) - { - QUIT; - frame1 = get_prev_frame (frame1); - if (frame1 == 0 || frame1 == frame) - break; - fi = get_frame_info (frame1); - get_frame_saved_regs (fi, &saved_regs); - if (saved_regs.regs[regnum]) - addr = saved_regs.regs[regnum]; - } - - return addr; -} - -/* Copy the bytes of register REGNUM, relative to the current stack frame, - into our memory at MYADDR. - The number of bytes copied is REGISTER_RAW_SIZE (REGNUM). */ - -void -read_relative_register_raw_bytes (regnum, myaddr) - int regnum; - char *myaddr; -{ - register CORE_ADDR addr; - - if (regnum == FP_REGNUM) - { - bcopy (&FRAME_FP(selected_frame), myaddr, sizeof (CORE_ADDR)); - return; - } - - addr = find_saved_register (selected_frame, regnum); - - if (addr) - { - if (regnum == SP_REGNUM) - { - CORE_ADDR buffer = addr; - bcopy (&buffer, myaddr, sizeof (CORE_ADDR)); - } - else - read_memory (addr, myaddr, REGISTER_RAW_SIZE (regnum)); - return; - } - read_register_bytes (REGISTER_BYTE (regnum), - myaddr, REGISTER_RAW_SIZE (regnum)); -} - -/* Return a `value' with the contents of register REGNUM - in its virtual format, with the type specified by - REGISTER_VIRTUAL_TYPE. */ - -value -value_of_register (regnum) - int regnum; -{ - register CORE_ADDR addr; - register value val; - char raw_buffer[MAX_REGISTER_RAW_SIZE]; - char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; - - if (! (have_inferior_p () || have_core_file_p ())) - error ("Can't get value of register without inferior or core file"); - - addr = find_saved_register (selected_frame, regnum); - if (addr) - { - if (regnum == SP_REGNUM) - return value_from_long (builtin_type_int, (LONGEST) addr); - read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum)); - } - else - read_register_bytes (REGISTER_BYTE (regnum), raw_buffer, - REGISTER_RAW_SIZE (regnum)); - - REGISTER_CONVERT_TO_VIRTUAL (regnum, raw_buffer, virtual_buffer); - val = allocate_value (REGISTER_VIRTUAL_TYPE (regnum)); - bcopy (virtual_buffer, VALUE_CONTENTS (val), REGISTER_VIRTUAL_SIZE (regnum)); - VALUE_LVAL (val) = addr ? lval_memory : lval_register; - VALUE_ADDRESS (val) = addr ? addr : REGISTER_BYTE (regnum); - VALUE_REGNO (val) = regnum; - return val; -} - -/* Low level examining and depositing of registers. - - Note that you must call `fetch_registers' once - before examining or depositing any registers. */ - -char registers[REGISTER_BYTES]; - -/* Copy LEN bytes of consecutive data from registers - starting with the REGBYTE'th byte of register data - into memory at MYADDR. */ - -void -read_register_bytes (regbyte, myaddr, len) - int regbyte; - char *myaddr; - int len; -{ - bcopy (®isters[regbyte], myaddr, len); -} - -/* Copy LEN bytes of consecutive data from memory at MYADDR - into registers starting with the REGBYTE'th byte of register data. */ - -void -write_register_bytes (regbyte, myaddr, len) - int regbyte; - char *myaddr; - int len; -{ - bcopy (myaddr, ®isters[regbyte], len); - if (have_inferior_p ()) - store_inferior_registers (-1); -} - -/* Return the contents of register REGNO, - regarding it as an integer. */ - -CORE_ADDR -read_register (regno) - int regno; -{ - /* This loses when REGISTER_RAW_SIZE (regno) != sizeof (int) */ - return *(int *) ®isters[REGISTER_BYTE (regno)]; -} - -/* Store VALUE in the register number REGNO, regarded as an integer. */ - -void -write_register (regno, val) - int regno, val; -{ - /* This loses when REGISTER_RAW_SIZE (regno) != sizeof (int) */ -#if defined(sun4) - /* This is a no-op on a Sun 4. */ - if (regno == 0) - return; -#endif - - *(int *) ®isters[REGISTER_BYTE (regno)] = val; - - if (have_inferior_p ()) - store_inferior_registers (regno); -} - -/* Record that register REGNO contains VAL. - This is used when the value is obtained from the inferior or core dump, - so there is no need to store the value there. */ - -void -supply_register (regno, val) - int regno; - char *val; -{ - bcopy (val, ®isters[REGISTER_BYTE (regno)], REGISTER_RAW_SIZE (regno)); -} - -/* Given a struct symbol for a variable, - and a stack frame id, read the value of the variable - and return a (pointer to a) struct value containing the value. */ - -value -read_var_value (var, frame) - register struct symbol *var; - FRAME frame; -{ - register value v; - - struct frame_info *fi; - - struct type *type = SYMBOL_TYPE (var); - register CORE_ADDR addr = 0; - int val = SYMBOL_VALUE (var); - register int len; - - v = allocate_value (type); - VALUE_LVAL (v) = lval_memory; /* The most likely possibility. */ - len = TYPE_LENGTH (type); - - if (frame == 0) frame = selected_frame; - - switch (SYMBOL_CLASS (var)) - { - case LOC_CONST: - case LOC_LABEL: - bcopy (&val, VALUE_CONTENTS (v), len); - VALUE_LVAL (v) = not_lval; - return v; - - case LOC_CONST_BYTES: - bcopy (val, VALUE_CONTENTS (v), len); - VALUE_LVAL (v) = not_lval; - return v; - - case LOC_STATIC: - addr = val; - break; - -/* Nonzero if a struct which is located in a register or a LOC_ARG - really contains - the address of the struct, not the struct itself. GCC_P is nonzero - if the function was compiled with GCC. */ -#if !defined (REG_STRUCT_HAS_ADDR) -#define REG_STRUCT_HAS_ADDR(gcc_p) 0 -#endif - - case LOC_ARG: - fi = get_frame_info (frame); - addr = val + FRAME_ARGS_ADDRESS (fi); - break; - - case LOC_REF_ARG: - fi = get_frame_info (frame); - addr = val + FRAME_ARGS_ADDRESS (fi); - addr = read_memory_integer (addr, sizeof (CORE_ADDR)); - break; - - case LOC_LOCAL: - fi = get_frame_info (frame); - addr = val + FRAME_LOCALS_ADDRESS (fi); - break; - - case LOC_TYPEDEF: - error ("Cannot look up value of a typedef"); - - case LOC_BLOCK: - VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (var)); - return v; - - case LOC_REGISTER: - case LOC_REGPARM: - { - struct block *b = get_frame_block (frame); - - v = value_from_register (type, val, frame); - - if (REG_STRUCT_HAS_ADDR(b->gcc_compile_flag) - && TYPE_CODE (type) == TYPE_CODE_STRUCT) - addr = *(CORE_ADDR *)VALUE_CONTENTS (v); - else - return v; - } - } - - read_memory (addr, VALUE_CONTENTS (v), len); - VALUE_ADDRESS (v) = addr; - return v; -} - -/* Return a value of type TYPE, stored in register REGNUM, in frame - FRAME. */ - -value -value_from_register (type, regnum, frame) - struct type *type; - int regnum; - FRAME frame; -{ - char raw_buffer [MAX_REGISTER_RAW_SIZE]; - char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; - CORE_ADDR addr; - value v = allocate_value (type); - int len = TYPE_LENGTH (type); - char *value_bytes = 0; - int value_bytes_copied = 0; - int num_storage_locs; - - VALUE_REGNO (v) = regnum; - - num_storage_locs = (len > REGISTER_VIRTUAL_SIZE (regnum) ? - ((len - 1) / REGISTER_RAW_SIZE (regnum)) + 1 : - 1); - - if (num_storage_locs > 1) - { - /* Value spread across multiple storage locations. */ - - int local_regnum; - int mem_stor = 0, reg_stor = 0; - int mem_tracking = 1; - CORE_ADDR last_addr = 0; - - value_bytes = (char *) alloca (len + MAX_REGISTER_RAW_SIZE); - - /* Copy all of the data out, whereever it may be. */ - - for (local_regnum = regnum; - value_bytes_copied < len; - (value_bytes_copied += REGISTER_RAW_SIZE (local_regnum), - ++local_regnum)) - { - int register_index = local_regnum - regnum; - addr = find_saved_register (frame, local_regnum); - if (addr == 0) - { - read_register_bytes (REGISTER_BYTE (local_regnum), - value_bytes + value_bytes_copied, - REGISTER_RAW_SIZE (local_regnum)); - reg_stor++; - } - else - { - read_memory (addr, value_bytes + value_bytes_copied, - REGISTER_RAW_SIZE (local_regnum)); - mem_stor++; - mem_tracking = - (mem_tracking - && (regnum == local_regnum - || addr == last_addr)); - } - last_addr = addr; - } - - if ((reg_stor && mem_stor) - || (mem_stor && !mem_tracking)) - /* Mixed storage; all of the hassle we just went through was - for some good purpose. */ - { - VALUE_LVAL (v) = lval_reg_frame_relative; - VALUE_FRAME (v) = FRAME_FP (frame); - VALUE_FRAME_REGNUM (v) = regnum; - } - else if (mem_stor) - { - VALUE_LVAL (v) = lval_memory; - VALUE_ADDRESS (v) = find_saved_register (frame, regnum); - } - else if (reg_stor) - { - VALUE_LVAL (v) = lval_register; - VALUE_ADDRESS (v) = REGISTER_BYTE (regnum); - } - else - fatal ("value_from_register: Value not stored anywhere!"); - - /* Any structure stored in more than one register will always be - an inegral number of registers. Otherwise, you'd need to do - some fiddling with the last register copied here for little - endian machines. */ - - /* Copy into the contents section of the value. */ - bcopy (value_bytes, VALUE_CONTENTS (v), len); - - return v; - } - - /* Data is completely contained within a single register. Locate the - register's contents in a real register or in core; - read the data in raw format. */ - - addr = find_saved_register (frame, regnum); - if (addr == 0) - { - /* Value is really in a register. */ - - VALUE_LVAL (v) = lval_register; - VALUE_ADDRESS (v) = REGISTER_BYTE (regnum); - - read_register_bytes (REGISTER_BYTE (regnum), - raw_buffer, REGISTER_RAW_SIZE (regnum)); - } - else - { - /* Value was in a register that has been saved in memory. */ - - read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum)); - VALUE_LVAL (v) = lval_memory; - VALUE_ADDRESS (v) = addr; - } - - /* Convert the raw contents to virtual contents. - (Just copy them if the formats are the same.) */ - - REGISTER_CONVERT_TO_VIRTUAL (regnum, raw_buffer, virtual_buffer); - - if (REGISTER_CONVERTIBLE (regnum)) - { - /* When the raw and virtual formats differ, the virtual format - corresponds to a specific data type. If we want that type, - copy the data into the value. - Otherwise, do a type-conversion. */ - - if (type != REGISTER_VIRTUAL_TYPE (regnum)) - { - /* eg a variable of type `float' in a 68881 register - with raw type `extended' and virtual type `double'. - Fetch it as a `double' and then convert to `float'. */ - v = allocate_value (REGISTER_VIRTUAL_TYPE (regnum)); - bcopy (virtual_buffer, VALUE_CONTENTS (v), len); - v = value_cast (type, v); - } - else - bcopy (virtual_buffer, VALUE_CONTENTS (v), len); - } - else - { - /* Raw and virtual formats are the same for this register. */ - -#ifdef BYTES_BIG_ENDIAN - if (len < REGISTER_RAW_SIZE (regnum)) - { - /* Big-endian, and we want less than full size. */ - VALUE_OFFSET (v) = REGISTER_RAW_SIZE (regnum) - len; - } -#endif - - bcopy (virtual_buffer + VALUE_OFFSET (v), - VALUE_CONTENTS (v), len); - } - - return v; -} - -/* Given a struct symbol for a variable, - and a stack frame id, - return a (pointer to a) struct value containing the variable's address. */ - -value -locate_var_value (var, frame) - register struct symbol *var; - FRAME frame; -{ - register CORE_ADDR addr = 0; - int val = SYMBOL_VALUE (var); - struct frame_info *fi; - struct type *type = SYMBOL_TYPE (var); - struct type *result_type; - - if (frame == 0) frame = selected_frame; - - switch (SYMBOL_CLASS (var)) - { - case LOC_CONST: - case LOC_CONST_BYTES: - error ("Address requested for identifier \"%s\" which is a constant.", - SYMBOL_NAME (var)); - - case LOC_REGISTER: - case LOC_REGPARM: - addr = find_saved_register (frame, val); - if (addr != 0) - { - int len = TYPE_LENGTH (type); -#ifdef BYTES_BIG_ENDIAN - if (len < REGISTER_RAW_SIZE (val)) - /* Big-endian, and we want less than full size. */ - addr += REGISTER_RAW_SIZE (val) - len; -#endif - break; - } - error ("Address requested for identifier \"%s\" which is in a register.", - SYMBOL_NAME (var)); - - case LOC_STATIC: - case LOC_LABEL: - addr = val; - break; - - case LOC_ARG: - fi = get_frame_info (frame); - addr = val + FRAME_ARGS_ADDRESS (fi); - break; - - case LOC_REF_ARG: - fi = get_frame_info (frame); - addr = val + FRAME_ARGS_ADDRESS (fi); - addr = read_memory_integer (addr, sizeof (CORE_ADDR)); - break; - - case LOC_LOCAL: - fi = get_frame_info (frame); - addr = val + FRAME_LOCALS_ADDRESS (fi); - break; - - case LOC_TYPEDEF: - error ("Address requested for identifier \"%s\" which is a typedef.", - SYMBOL_NAME (var)); - - case LOC_BLOCK: - addr = BLOCK_START (SYMBOL_BLOCK_VALUE (var)); - break; - } - - /* Address of an array is of the type of address of it's elements. */ - result_type = - lookup_pointer_type (TYPE_CODE (type) == TYPE_CODE_ARRAY ? - TYPE_TARGET_TYPE (type) : type); - - return value_cast (result_type, - value_from_long (builtin_type_long, (LONGEST) addr)); -} - diff --git a/gnu/usr.bin/gdb/frame.h b/gnu/usr.bin/gdb/frame.h deleted file mode 100644 index 322ddba..0000000 --- a/gnu/usr.bin/gdb/frame.h +++ /dev/null @@ -1,115 +0,0 @@ -/* Definitions for dealing with stack frames, for GDB, the GNU debugger. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Note that frame.h requires param.h! */ - -/* - * FRAME is the type of the identifier of a specific stack frame. It - * is a pointer to the frame cache item corresponding to this frame. - * Please note that frame id's are *not* constant over calls to the - * inferior. Use frame addresses, which are. - * - * FRAME_ADDR is the type of the address of a specific frame. I - * cannot imagine a case in which this would not be CORE_ADDR, so - * maybe it's silly to give it it's own type. Life's rough. - * - * FRAME_FP is a macro which converts from a frame identifier into a - * frame_address. - * - * FRAME_INFO_ID is a macro which "converts" from a frame info pointer - * to a frame id. This is here in case I or someone else decides to - * change the FRAME type again. - * - * This file and blockframe.c are the only places which are allowed to - * use the equivalence between FRAME and struct frame_info *. EXCEPTION: - * value.h uses CORE_ADDR instead of FRAME_ADDR because the compiler - * will accept that in the absense of this file. - */ -typedef struct frame_info *FRAME; -typedef CORE_ADDR FRAME_ADDR; -#define FRAME_FP(fr) ((fr)->frame) -#define FRAME_INFO_ID(f) (f) - -/* - * Caching structure for stack frames. This is also the structure - * used for extended info about stack frames. May add more to this - * structure as it becomes necessary. - * - * Note that the first entry in the cache will always refer to the - * innermost executing frame. This value should be set (is it? - * Check) in something like normal_stop. - */ -struct frame_info - { - /* Nominal address of the frame described. */ - FRAME_ADDR frame; - /* Address at which execution is occurring in this frame. - For the innermost frame, it's the current pc. - For other frames, it is a pc saved in the next frame. */ - CORE_ADDR pc; - /* The frame called by the frame we are describing, or 0. - This may be set even if there isn't a frame called by the one - we are describing (.->next == 0); in that case it is simply the - bottom of this frame */ - FRAME_ADDR next_frame; - /* Anything extra for this structure that may have been defined - in the machine depedent files. */ -#ifdef EXTRA_FRAME_INFO - EXTRA_FRAME_INFO -#endif - /* Pointers to the next and previous frame_info's in this stack. */ - FRAME next, prev; - }; - -/* Describe the saved registers of a frame. */ - -struct frame_saved_regs - { - /* For each register, address of where it was saved on entry to the frame, - or zero if it was not saved on entry to this frame. */ - CORE_ADDR regs[NUM_REGS]; - }; - -/* The stack frame that the user has specified for commands to act on. - Note that one cannot assume this is the address of valid data. */ - -extern FRAME selected_frame; - -extern struct frame_info *get_frame_info (); -extern struct frame_info *get_prev_frame_info (); - -extern FRAME create_new_frame (); - -extern void get_frame_saved_regs (); - -extern FRAME get_prev_frame (); -extern FRAME get_current_frame (); -extern FRAME get_next_frame (); - -extern struct block *get_frame_block (); -extern struct block *get_current_block (); -extern struct block *get_selected_block (); -extern struct symbol *get_frame_function (); -extern struct symbol *get_pc_function (); - -/* In stack.c */ -extern FRAME find_relative_frame (); - -/* Generic pointer value indicating "I don't know." */ -#define Frame_unknown (CORE_ADDR)-1 diff --git a/gnu/usr.bin/gdb/gdb.1 b/gnu/usr.bin/gdb/gdb.1 deleted file mode 100644 index 57d744b..0000000 --- a/gnu/usr.bin/gdb/gdb.1 +++ /dev/null @@ -1,3 +0,0 @@ -.\" %W% (Berkeley) %G% -.\" -.\" placeholder, until we can produce the manual page diff --git a/gnu/usr.bin/gdb/gdb/c-exp.tab.c b/gnu/usr.bin/gdb/gdb/c-exp.tab.c deleted file mode 100644 index 924dfc6..0000000 --- a/gnu/usr.bin/gdb/gdb/c-exp.tab.c +++ /dev/null @@ -1,2648 +0,0 @@ -#ifndef lint -static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; -#endif -#define YYBYACC 1 -#define YYMAJOR 1 -#define YYMINOR 9 -#define yyclearin (yychar=(-1)) -#define yyerrok (yyerrflag=0) -#define YYRECOVERING (yyerrflag!=0) -#define yyparse c_parse -#define yylex c_lex -#define yyerror c_error -#define yychar c_char -#define yyval c_val -#define yylval c_lval -#define yydebug c_debug -#define yynerrs c_nerrs -#define yyerrflag c_errflag -#define yyss c_ss -#define yyssp c_ssp -#define yyvs c_vs -#define yyvsp c_vsp -#define yylhs c_lhs -#define yylen c_len -#define yydefred c_defred -#define yydgoto c_dgoto -#define yysindex c_sindex -#define yyrindex c_rindex -#define yygindex c_gindex -#define yytable c_table -#define yycheck c_check -#define yyname c_name -#define yyrule c_rule -#define YYPREFIX "c_" -#line 38 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" - -#include "defs.h" -#include "expression.h" -#include "parser-defs.h" -#include "value.h" -#include "language.h" -#include "c-lang.h" - -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), - as well as gratuitiously global symbol names, so we can have multiple - yacc generated parsers in gdb. Note that these are only the variables - produced by yacc. If other parser generators (bison, byacc, etc) produce - additional global names that conflict at link time, then those parser - generators need to be fixed instead of adding those names to this list. */ - -#define yymaxdepth c_maxdepth -#define yyparse c_parse -#define yylex c_lex -#define yyerror c_error -#define yylval c_lval -#define yychar c_char -#define yydebug c_debug -#define yypact c_pact -#define yyr1 c_r1 -#define yyr2 c_r2 -#define yydef c_def -#define yychk c_chk -#define yypgo c_pgo -#define yyact c_act -#define yyexca c_exca -#define yyerrflag c_errflag -#define yynerrs c_nerrs -#define yyps c_ps -#define yypv c_pv -#define yys c_s -#define yy_yys c_yys -#define yystate c_state -#define yytmp c_tmp -#define yyv c_v -#define yy_yyv c_yyv -#define yyval c_val -#define yylloc c_lloc -#define yyreds c_reds /* With YYDEBUG defined */ -#define yytoks c_toks /* With YYDEBUG defined */ - -#ifndef YYDEBUG -#define YYDEBUG 0 /* Default to no yydebug support */ -#endif - -int -yyparse PARAMS ((void)); - -static int -yylex PARAMS ((void)); - -void -yyerror PARAMS ((char *)); - -#line 102 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -typedef union - { - LONGEST lval; - struct { - LONGEST val; - struct type *type; - } typed_val; - double dval; - struct symbol *sym; - struct type *tval; - struct stoken sval; - struct ttype tsym; - struct symtoken ssym; - int voidval; - struct block *bval; - enum exp_opcode opcode; - struct internalvar *ivar; - - struct type **tvec; - int *ivec; - } YYSTYPE; -#line 125 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -/* YYSTYPE gets defined by %union */ -static int -parse_number PARAMS ((char *, int, int, YYSTYPE *)); -#line 121 "y.tab.c" -#define INT 257 -#define FLOAT 258 -#define STRING 259 -#define NAME 260 -#define TYPENAME 261 -#define NAME_OR_INT 262 -#define STRUCT 263 -#define CLASS 264 -#define UNION 265 -#define ENUM 266 -#define SIZEOF 267 -#define UNSIGNED 268 -#define COLONCOLON 269 -#define TEMPLATE 270 -#define ERROR 271 -#define SIGNED_KEYWORD 272 -#define LONG 273 -#define SHORT 274 -#define INT_KEYWORD 275 -#define CONST_KEYWORD 276 -#define VOLATILE_KEYWORD 277 -#define LAST 278 -#define REGNAME 279 -#define VARIABLE 280 -#define ASSIGN_MODIFY 281 -#define THIS 282 -#define ABOVE_COMMA 283 -#define OROR 284 -#define ANDAND 285 -#define EQUAL 286 -#define NOTEQUAL 287 -#define LEQ 288 -#define GEQ 289 -#define LSH 290 -#define RSH 291 -#define UNARY 292 -#define INCREMENT 293 -#define DECREMENT 294 -#define ARROW 295 -#define BLOCKNAME 296 -#define YYERRCODE 256 -short c_lhs[] = { -1, - 0, 0, 3, 2, 2, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 21, 1, 6, 20, 20, 20, 7, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 19, 19, 4, 5, 5, - 4, 4, 4, 14, 14, 14, 14, 14, 14, 13, - 13, 13, 13, 13, 12, 12, 12, 12, 12, 15, - 15, 11, 11, 8, 8, 8, 8, 8, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 18, 18, 18, 18, 10, 10, 16, 16, 16, - 16, 17, 17, -}; -short c_len[] = { 2, - 1, 1, 1, 1, 3, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 3, 3, 4, 3, 3, - 4, 4, 0, 5, 1, 0, 1, 3, 1, 3, - 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 5, 3, 3, 1, 1, 1, 1, 1, - 1, 1, 4, 1, 1, 1, 3, 3, 3, 4, - 1, 2, 1, 1, 2, 2, 2, 3, 3, 1, - 2, 1, 2, 1, 3, 2, 1, 2, 1, 2, - 3, 2, 3, 1, 3, 6, 8, 9, 1, 1, - 1, 1, 2, 3, 2, 3, 3, 4, 2, 3, - 2, 2, 2, 2, 2, 1, 2, 1, 5, 2, - 2, 1, 1, 1, 1, 1, 3, 1, 1, 1, - 1, 1, 1, -}; -short c_defred[] = { 0, - 56, 58, 64, 132, 99, 57, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, - 60, 61, 62, 65, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 25, 0, 0, 0, 2, 59, 71, - 0, 0, 0, 94, 73, 0, 128, 130, 131, 129, - 111, 112, 113, 114, 0, 0, 0, 122, 0, 0, - 123, 115, 72, 0, 124, 125, 117, 0, 103, 109, - 120, 121, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 13, 14, 0, 0, 0, 23, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 89, 0, 77, 87, 0, 0, 0, 0, 104, - 110, 0, 106, 33, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, - 16, 0, 20, 19, 0, 0, 0, 29, 0, 0, - 30, 0, 95, 0, 69, 78, 79, 83, 81, 0, - 90, 92, 0, 0, 0, 0, 0, 88, 86, 0, - 0, 108, 0, 0, 0, 0, 0, 22, 0, 0, - 0, 0, 70, 91, 0, 0, 93, 85, 119, 0, - 24, 0, 0, 0, 0, 97, 0, 98, -}; -short c_dgoto[] = { 35, - 36, 78, 38, 39, 40, 41, 169, 183, 57, 185, - 122, 123, 124, 44, 125, 175, 45, 62, 46, 113, - 166, -}; -short c_sindex[] = { 1773, - 0, 0, 0, 0, 0, 0, -243, -243, -243, -243, - 1839, -240, -243, -243, -56, -260, -266, 0, 1303, 1303, - 0, 0, 0, 0, 1773, 1773, 1773, 1773, 1773, 1773, - 0, 1773, 1773, 0, 0, 2134, -24, 0, 0, 0, - 1773, -16, -36, 0, 0, -233, 0, 0, 0, 0, - 0, 0, 0, 0, 1773, 83, -219, 0, -217, -208, - 0, 0, 0, 57, 0, 0, 0, -199, 0, 0, - 0, 0, 83, 83, 83, 83, 83, 74, -12, 83, - 83, 1773, 1773, 1773, 1773, 1773, 1773, 1773, 1773, 1773, - 1773, 1773, 1773, 1773, 1773, 1773, 1773, 1773, 1773, 1773, - 1773, 1773, 1773, 0, 0, 2136, 2175, 1773, 0, 1773, - 2134, -28, -17, 1303, -35, 31, 31, 31, 31, -90, - 1807, 0, -3, 0, 0, -243, 49, -52, -148, 0, - 0, 1303, 0, 0, 1773, 2134, 2134, 2099, 2197, 2208, - 2236, 2269, 2304, 2474, 2474, 743, 743, 743, 743, 615, - 615, 273, 320, 320, 83, 83, 83, 0, 1773, 0, - 0, 1773, 0, 0, -44, 1773, 2134, 0, 1773, 1773, - 0, -137, 0, -243, 0, 0, 0, 0, 0, 63, - 0, 0, -16, 28, 80, 117, 477, 0, 0, 0, - 1653, 0, -32, 83, 1773, 83, 83, 0, 106, 83, - 2134, 136, 0, 0, 145, 1303, 0, 0, 0, 2169, - 0, 129, -16, 155, 2276, 0, 171, 0, -}; -short c_rindex[] = { 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1146, 0, 0, 1403, 1413, 1691, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 16, 188, 0, 0, 0, - -13, 206, 79, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 213, 0, 0, 1716, 1721, - 0, 0, 0, 0, 0, 0, 0, 1730, 0, 0, - 0, 0, 311, 402, 414, 487, 515, 0, 0, 583, - 673, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -19, 0, 0, 0, 0, 10, 52, 111, 359, 0, - 0, 0, 492, 0, 0, 0, 0, 0, 1746, 0, - 0, 0, 0, 0, 0, 668, 892, 0, 881, 153, - 479, 1135, 128, 1583, 1620, 1366, 1438, 1546, 1572, 1264, - 1312, 1236, 1182, 1224, 782, 794, 853, 40, 0, 0, - 0, 0, 0, 0, 0, 193, 239, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 201, -30, 0, 0, 0, 0, 0, 99, - 138, 0, 0, 928, 0, 967, 1056, 0, 0, 1110, - -18, 0, 0, 0, 0, 0, 0, 0, 0, 110, - 0, 0, 257, 544, 0, 0, 0, 0, -}; -short c_gindex[] = { 0, - 2543, 5, 0, 0, 42, 0, 107, 75, 450, 13, - 115, 0, 148, 0, 120, 989, 0, 215, 0, 81, - 0, -}; -#define YYTABLESIZE 2769 -short c_table[] = { 110, - 133, 118, 181, 121, 37, 119, 173, 114, 70, 75, - 74, 114, 68, 74, 69, 4, 47, 48, 49, 110, - 58, 27, 28, 114, 27, 28, 170, 114, 135, 209, - 26, 74, 59, 60, 61, 126, 187, 133, 133, 130, - 133, 133, 133, 133, 133, 133, 133, 133, 198, 128, - 75, 76, 50, 75, 120, 129, 4, 130, 133, 4, - 133, 133, 133, 133, 133, 118, 131, 121, 118, 119, - 121, 75, 119, 174, 42, 133, 130, 130, 74, 130, - 130, 130, 130, 130, 130, 130, 130, 120, 114, 191, - 174, 133, 76, 133, 133, 76, 168, 130, 68, 130, - 130, 130, 130, 130, 79, 27, 28, 168, 4, 53, - 82, 26, 165, 76, 134, 112, 132, 110, 120, 74, - 207, 120, 109, 206, 133, 133, 192, 48, 107, 127, - 130, 202, 130, 130, 75, 68, 68, 63, 68, 68, - 68, 68, 68, 68, 68, 68, 211, 160, 163, 170, - 53, 82, 51, 53, 82, 204, 68, 208, 68, 68, - 68, 68, 68, 130, 130, 48, 180, 53, 48, 214, - 53, 48, 82, 108, 63, 63, 76, 212, 63, 63, - 63, 63, 63, 63, 63, 48, 173, 1, 48, 68, - 48, 68, 68, 51, 215, 63, 51, 63, 63, 63, - 63, 63, 53, 74, 58, 3, 193, 47, 48, 49, - 51, 218, 15, 51, 206, 51, 65, 66, 61, 171, - 48, 48, 68, 68, 47, 48, 49, 217, 63, 67, - 63, 63, 115, 26, 53, 82, 26, 188, 5, 116, - 117, 126, 189, 50, 126, 51, 199, 0, 0, 15, - 15, 48, 48, 15, 15, 15, 15, 15, 0, 15, - 50, 63, 63, 176, 177, 178, 179, 0, 186, 66, - 15, 0, 15, 15, 15, 15, 15, 51, 0, 5, - 213, 133, 5, 0, 133, 133, 133, 133, 133, 133, - 133, 133, 0, 133, 133, 133, 205, 127, 0, 0, - 127, 0, 0, 116, 117, 15, 15, 0, 99, 103, - 7, 0, 109, 0, 101, 99, 0, 100, 107, 102, - 130, 0, 0, 130, 130, 130, 130, 130, 130, 130, - 130, 5, 130, 130, 130, 0, 15, 15, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, - 0, 7, 7, 7, 7, 7, 103, 7, 80, 109, - 0, 101, 0, 108, 0, 107, 102, 67, 7, 0, - 7, 7, 7, 7, 7, 104, 105, 106, 0, 68, - 0, 0, 68, 68, 68, 68, 68, 68, 68, 68, - 53, 68, 68, 68, 0, 0, 0, 0, 0, 80, - 0, 8, 80, 7, 7, 0, 0, 0, 48, 0, - 108, 48, 48, 6, 0, 0, 0, 0, 63, 0, - 80, 63, 63, 63, 63, 63, 63, 63, 63, 0, - 0, 0, 63, 51, 7, 7, 51, 51, 8, 8, - 0, 0, 8, 8, 8, 8, 8, 0, 8, 43, - 6, 6, 0, 0, 6, 6, 6, 6, 6, 8, - 6, 8, 8, 8, 8, 8, 0, 0, 71, 72, - 0, 6, 0, 6, 6, 6, 6, 6, 50, 43, - 0, 0, 0, 80, 0, 0, 11, 0, 0, 0, - 43, 84, 0, 15, 8, 8, 15, 15, 15, 15, - 15, 15, 15, 15, 43, 0, 6, 6, 0, 0, - 0, 0, 0, 0, 12, 0, 0, 182, 0, 50, - 0, 0, 50, 11, 11, 8, 8, 11, 11, 11, - 11, 11, 84, 11, 0, 84, 50, 6, 6, 50, - 0, 50, 0, 96, 11, 0, 11, 11, 11, 11, - 11, 12, 12, 84, 0, 12, 12, 12, 12, 12, - 0, 12, 0, 172, 0, 104, 105, 106, 0, 0, - 184, 50, 12, 0, 12, 12, 12, 12, 12, 11, - 11, 184, 9, 0, 96, 0, 0, 96, 0, 0, - 0, 7, 0, 0, 7, 7, 7, 7, 7, 7, - 7, 7, 50, 50, 0, 96, 0, 12, 12, 0, - 11, 11, 104, 105, 106, 0, 84, 0, 0, 9, - 9, 0, 0, 9, 9, 9, 9, 9, 0, 9, - 0, 0, 0, 0, 0, 0, 184, 0, 12, 12, - 9, 0, 9, 9, 9, 9, 9, 0, 0, 0, - 0, 103, 0, 0, 109, 184, 101, 99, 0, 100, - 107, 102, 0, 0, 184, 0, 0, 55, 96, 0, - 0, 0, 10, 0, 0, 9, 9, 0, 98, 0, - 0, 0, 8, 0, 0, 8, 8, 8, 8, 8, - 8, 8, 8, 0, 6, 0, 0, 6, 6, 6, - 6, 6, 6, 6, 6, 108, 9, 9, 55, 10, - 10, 55, 0, 10, 10, 10, 10, 10, 0, 10, - 0, 0, 0, 0, 0, 55, 0, 0, 0, 0, - 10, 0, 10, 10, 10, 10, 10, 5, 0, 7, - 8, 9, 10, 0, 12, 0, 14, 0, 15, 16, - 17, 18, 19, 20, 0, 0, 0, 0, 0, 50, - 55, 0, 50, 50, 0, 10, 10, 11, 0, 0, - 11, 11, 11, 11, 11, 11, 11, 11, 0, 103, - 0, 35, 109, 0, 101, 99, 0, 100, 107, 102, - 0, 0, 55, 36, 0, 12, 10, 10, 12, 12, - 12, 12, 12, 12, 12, 12, 98, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 35, 35, - 0, 0, 35, 35, 35, 35, 35, 0, 35, 0, - 36, 36, 0, 108, 36, 36, 36, 36, 36, 35, - 36, 35, 35, 35, 35, 35, 0, 0, 0, 0, - 0, 36, 37, 36, 36, 36, 36, 36, 0, 0, - 0, 0, 0, 9, 0, 0, 9, 9, 9, 9, - 9, 9, 9, 9, 35, 35, 0, 0, 0, 0, - 52, 0, 0, 0, 0, 0, 36, 36, 0, 37, - 37, 54, 0, 37, 37, 37, 37, 37, 0, 37, - 0, 0, 0, 0, 0, 35, 35, 104, 105, 106, - 37, 0, 37, 37, 37, 37, 37, 36, 36, 0, - 0, 52, 0, 0, 52, 0, 0, 32, 0, 0, - 0, 0, 54, 0, 0, 54, 0, 0, 52, 0, - 0, 52, 0, 52, 0, 37, 37, 0, 0, 54, - 0, 0, 0, 10, 0, 0, 10, 10, 10, 10, - 10, 10, 10, 10, 32, 32, 18, 0, 32, 32, - 32, 32, 32, 52, 32, 0, 37, 37, 0, 0, - 0, 0, 0, 0, 54, 32, 0, 32, 32, 32, - 32, 32, 0, 0, 0, 51, 52, 53, 54, 0, - 0, 63, 64, 18, 18, 52, 0, 18, 18, 18, - 18, 18, 0, 18, 0, 0, 54, 0, 0, 0, - 32, 32, 0, 0, 18, 0, 18, 18, 18, 18, - 18, 0, 96, 97, 0, 104, 105, 106, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 32, 32, 0, 0, 21, 0, 0, 0, 18, - 18, 0, 35, 0, 0, 35, 35, 35, 35, 35, - 35, 35, 35, 0, 36, 0, 0, 36, 36, 36, - 36, 36, 36, 36, 36, 0, 0, 0, 0, 0, - 18, 18, 21, 21, 161, 164, 21, 21, 21, 21, - 21, 0, 21, 0, 0, 0, 0, 0, 0, 31, - 0, 0, 0, 21, 190, 21, 21, 21, 21, 21, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 37, 49, 0, 37, 37, 37, 37, - 37, 37, 37, 37, 0, 116, 31, 31, 21, 21, - 31, 31, 31, 31, 31, 0, 31, 0, 0, 0, - 0, 52, 203, 0, 52, 0, 0, 31, 0, 31, - 31, 31, 31, 31, 0, 49, 0, 0, 49, 21, - 21, 38, 0, 116, 0, 116, 116, 116, 0, 116, - 0, 0, 49, 0, 0, 49, 0, 49, 0, 0, - 0, 0, 31, 31, 0, 0, 0, 116, 32, 0, - 0, 32, 32, 32, 32, 32, 32, 32, 32, 38, - 0, 0, 38, 39, 38, 38, 38, 49, 49, 0, - 0, 0, 0, 31, 31, 34, 116, 0, 0, 38, - 0, 38, 38, 38, 38, 38, 0, 18, 0, 0, - 18, 18, 18, 18, 18, 18, 18, 18, 49, 49, - 0, 39, 0, 40, 39, 0, 39, 39, 39, 0, - 116, 0, 0, 34, 38, 38, 34, 0, 0, 34, - 0, 39, 0, 39, 39, 39, 39, 39, 0, 0, - 0, 0, 0, 34, 0, 34, 34, 34, 34, 34, - 0, 40, 0, 0, 40, 38, 38, 40, 0, 0, - 0, 41, 0, 0, 0, 0, 39, 39, 0, 0, - 0, 40, 0, 40, 40, 40, 40, 0, 34, 34, - 0, 0, 0, 0, 0, 0, 21, 0, 0, 21, - 21, 21, 21, 21, 21, 21, 21, 39, 39, 41, - 0, 0, 41, 0, 0, 41, 40, 40, 0, 34, - 34, 0, 0, 0, 0, 46, 0, 0, 0, 41, - 0, 41, 41, 41, 41, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 40, 40, 0, - 31, 0, 0, 31, 31, 31, 31, 31, 31, 31, - 31, 0, 118, 46, 41, 41, 46, 0, 0, 46, - 0, 0, 101, 0, 116, 49, 0, 0, 49, 49, - 0, 116, 116, 46, 0, 46, 46, 46, 46, 0, - 0, 0, 0, 0, 0, 41, 41, 47, 0, 0, - 118, 0, 118, 118, 118, 0, 118, 0, 0, 0, - 101, 0, 101, 101, 101, 0, 101, 0, 46, 46, - 0, 0, 38, 0, 118, 38, 38, 38, 38, 38, - 38, 38, 38, 0, 101, 47, 0, 0, 47, 0, - 0, 47, 0, 0, 0, 0, 0, 0, 0, 46, - 46, 0, 0, 118, 0, 47, 0, 47, 47, 47, - 47, 0, 0, 101, 39, 0, 0, 39, 39, 39, - 39, 39, 39, 39, 39, 0, 34, 0, 0, 34, - 34, 34, 34, 34, 34, 34, 34, 118, 0, 0, - 47, 47, 0, 0, 0, 0, 0, 101, 0, 0, - 0, 0, 0, 0, 40, 44, 0, 40, 40, 40, - 40, 40, 40, 40, 40, 0, 0, 0, 0, 0, - 0, 47, 47, 5, 0, 7, 8, 9, 10, 0, - 12, 45, 14, 0, 15, 16, 17, 18, 19, 20, - 0, 0, 42, 44, 0, 0, 44, 0, 0, 44, - 0, 0, 41, 0, 0, 41, 41, 41, 41, 41, - 41, 41, 41, 44, 0, 44, 44, 44, 44, 45, - 0, 0, 45, 0, 0, 45, 0, 0, 0, 43, - 42, 0, 0, 42, 0, 0, 42, 0, 0, 45, - 0, 45, 45, 45, 45, 0, 0, 0, 44, 44, - 42, 0, 0, 42, 0, 42, 46, 0, 0, 46, - 46, 46, 46, 46, 46, 0, 0, 43, 0, 0, - 43, 0, 0, 43, 45, 45, 0, 0, 0, 44, - 44, 118, 0, 0, 0, 42, 42, 43, 118, 118, - 43, 101, 43, 0, 0, 32, 0, 0, 101, 101, - 102, 0, 30, 0, 0, 45, 45, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 42, 42, 0, 0, - 0, 0, 43, 43, 0, 124, 0, 0, 47, 0, - 125, 47, 47, 47, 47, 47, 47, 0, 102, 105, - 102, 102, 102, 0, 102, 0, 0, 0, 0, 0, - 0, 0, 0, 43, 43, 107, 0, 0, 0, 0, - 0, 0, 102, 124, 0, 124, 124, 124, 125, 124, - 125, 125, 125, 0, 125, 0, 0, 105, 0, 105, - 105, 105, 0, 105, 0, 34, 0, 124, 33, 0, - 0, 102, 125, 107, 0, 107, 107, 107, 0, 107, - 0, 105, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 32, 124, 107, 0, 0, - 25, 125, 30, 0, 27, 102, 0, 26, 0, 0, - 105, 0, 0, 0, 0, 0, 44, 0, 0, 44, - 44, 44, 44, 44, 44, 0, 107, 0, 0, 0, - 124, 0, 0, 0, 118, 125, 121, 182, 119, 0, - 0, 0, 45, 0, 105, 45, 45, 45, 45, 45, - 45, 0, 0, 42, 0, 0, 42, 42, 42, 42, - 107, 32, 0, 0, 0, 0, 25, 0, 55, 0, - 27, 0, 0, 26, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 34, 0, 120, 33, 0, - 43, 0, 0, 43, 43, 43, 43, 0, 0, 1, - 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 14, 0, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 0, 24, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 28, 29, 0, 31, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 102, - 0, 34, 0, 0, 33, 0, 102, 102, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 124, 0, 0, 0, 0, 125, - 0, 124, 124, 0, 0, 0, 125, 125, 105, 0, - 0, 0, 0, 0, 0, 105, 105, 0, 0, 0, - 0, 0, 0, 0, 107, 0, 0, 0, 0, 0, - 0, 107, 107, 0, 0, 0, 0, 0, 0, 1, - 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 14, 0, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 0, 24, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 28, 29, 5, 31, 7, - 8, 9, 10, 0, 12, 0, 14, 0, 15, 16, - 17, 18, 19, 20, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, - 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 0, - 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 28, 29, 0, 31, 103, 89, 0, 109, 0, - 101, 99, 0, 100, 107, 102, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 195, 0, 92, 83, - 93, 84, 98, 0, 0, 0, 0, 0, 0, 0, - 103, 89, 0, 109, 0, 101, 99, 159, 100, 107, - 102, 0, 0, 0, 0, 0, 0, 0, 0, 108, - 0, 0, 88, 92, 83, 93, 84, 98, 0, 0, - 0, 0, 0, 0, 0, 103, 89, 0, 109, 0, - 101, 99, 0, 100, 107, 102, 162, 0, 0, 0, - 0, 0, 87, 0, 108, 0, 0, 88, 92, 0, - 93, 84, 98, 103, 89, 0, 109, 0, 101, 99, - 0, 100, 107, 102, 103, 89, 0, 109, 0, 101, - 99, 0, 100, 107, 102, 0, 92, 87, 93, 108, - 98, 0, 88, 0, 0, 0, 0, 92, 0, 93, - 0, 98, 103, 89, 0, 109, 0, 101, 99, 0, - 100, 107, 102, 0, 0, 0, 0, 108, 0, 0, - 88, 0, 87, 0, 0, 92, 0, 93, 108, 98, - 0, 88, 0, 0, 0, 103, 89, 0, 109, 0, - 101, 99, 0, 100, 107, 102, 216, 0, 0, 0, - 87, 0, 0, 0, 0, 0, 108, 0, 92, 88, - 93, 87, 98, 0, 0, 0, 0, 0, 0, 0, - 103, 0, 0, 109, 0, 101, 99, 0, 100, 107, - 102, 0, 0, 0, 0, 0, 0, 0, 0, 108, - 0, 0, 0, 92, 0, 93, 0, 98, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 82, - 0, 0, 85, 86, 90, 91, 94, 95, 96, 97, - 0, 104, 105, 106, 108, 47, 158, 49, 7, 8, - 9, 10, 0, 12, 0, 14, 0, 15, 16, 17, - 18, 19, 20, 0, 82, 0, 0, 85, 86, 90, - 91, 94, 95, 96, 97, 0, 104, 105, 106, 0, - 0, 50, 0, 0, 47, 158, 49, 7, 8, 9, - 10, 0, 12, 0, 14, 0, 15, 16, 17, 18, - 19, 20, 85, 86, 90, 91, 94, 95, 96, 97, - 0, 104, 105, 106, 0, 0, 0, 0, 0, 0, - 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 86, 90, 91, 94, 95, 96, 97, 0, 104, - 105, 106, 0, 90, 91, 94, 95, 96, 97, 0, - 104, 105, 106, 0, 0, 0, 0, 0, 0, 0, - 103, 0, 0, 109, 0, 101, 99, 0, 100, 107, - 102, 90, 91, 94, 95, 96, 97, 0, 104, 105, - 106, 0, 0, 92, 0, 93, 5, 98, 7, 8, - 9, 10, 0, 12, 0, 14, 0, 15, 16, 17, - 18, 19, 20, 56, 90, 91, 94, 95, 96, 97, - 0, 104, 105, 106, 108, 0, 0, 73, 74, 75, - 76, 77, 0, 0, 80, 81, 0, 0, 0, 0, - 0, 0, 0, 111, 0, 0, 0, 0, 0, 90, - 91, 94, 95, 96, 97, 0, 104, 105, 106, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 136, 137, 138, 139, 140, 141, - 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, - 152, 153, 154, 155, 156, 157, 0, 0, 0, 0, - 0, 0, 167, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 194, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 196, 0, 0, 197, 0, 0, 0, 111, 0, - 0, 200, 201, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 194, 0, 0, 0, 210, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 94, 95, 96, 97, 0, 104, 105, 106, -}; -short c_check[] = { 44, - 0, 38, 93, 40, 0, 42, 42, 40, 275, 0, - 41, 40, 273, 44, 275, 0, 260, 261, 262, 44, - 261, 41, 41, 40, 44, 44, 44, 40, 41, 62, - 44, 62, 273, 274, 275, 269, 40, 37, 38, 0, - 40, 41, 42, 43, 44, 45, 46, 47, 93, 269, - 41, 0, 296, 44, 91, 273, 41, 275, 58, 44, - 60, 61, 62, 63, 64, 38, 275, 40, 38, 42, - 40, 62, 42, 126, 0, 275, 37, 38, 0, 40, - 41, 42, 43, 44, 45, 46, 47, 91, 40, 41, - 126, 91, 41, 93, 94, 44, 125, 58, 0, 60, - 61, 62, 63, 64, 30, 125, 125, 125, 93, 0, - 0, 125, 108, 62, 41, 41, 60, 44, 91, 41, - 41, 91, 40, 44, 124, 125, 275, 0, 46, 55, - 91, 269, 93, 94, 125, 37, 38, 0, 40, 41, - 42, 43, 44, 45, 46, 47, 41, 106, 107, 44, - 41, 41, 0, 44, 44, 93, 58, 41, 60, 61, - 62, 63, 64, 124, 125, 38, 257, 58, 41, 41, - 61, 44, 62, 91, 37, 38, 125, 42, 41, 42, - 43, 44, 45, 46, 47, 58, 42, 0, 61, 91, - 63, 93, 94, 41, 40, 58, 44, 60, 61, 62, - 63, 64, 93, 125, 261, 0, 132, 260, 261, 262, - 58, 41, 0, 61, 44, 63, 273, 274, 275, 113, - 93, 94, 124, 125, 260, 261, 262, 215, 91, 15, - 93, 94, 269, 41, 125, 125, 44, 123, 0, 276, - 277, 41, 123, 296, 44, 93, 166, -1, -1, 37, - 38, 124, 125, 41, 42, 43, 44, 45, -1, 47, - 296, 124, 125, 116, 117, 118, 119, -1, 121, 269, - 58, -1, 60, 61, 62, 63, 64, 125, -1, 41, - 206, 281, 44, -1, 284, 285, 286, 287, 288, 289, - 290, 291, -1, 293, 294, 295, 269, 41, -1, -1, - 44, -1, -1, 276, 277, 93, 94, -1, 269, 37, - 0, -1, 40, -1, 42, 43, -1, 45, 46, 47, - 281, -1, -1, 284, 285, 286, 287, 288, 289, 290, - 291, 93, 293, 294, 295, -1, 124, 125, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 37, 38, -1, - -1, 41, 42, 43, 44, 45, 37, 47, 0, 40, - -1, 42, -1, 91, -1, 46, 47, 269, 58, -1, - 60, 61, 62, 63, 64, 293, 294, 295, -1, 281, - -1, -1, 284, 285, 286, 287, 288, 289, 290, 291, - 281, 293, 294, 295, -1, -1, -1, -1, -1, 41, - -1, 0, 44, 93, 94, -1, -1, -1, 281, -1, - 91, 284, 285, 0, -1, -1, -1, -1, 281, -1, - 62, 284, 285, 286, 287, 288, 289, 290, 291, -1, - -1, -1, 295, 281, 124, 125, 284, 285, 37, 38, - -1, -1, 41, 42, 43, 44, 45, -1, 47, 0, - 37, 38, -1, -1, 41, 42, 43, 44, 45, 58, - 47, 60, 61, 62, 63, 64, -1, -1, 19, 20, - -1, 58, -1, 60, 61, 62, 63, 64, 0, 30, - -1, -1, -1, 125, -1, -1, 0, -1, -1, -1, - 41, 0, -1, 281, 93, 94, 284, 285, 286, 287, - 288, 289, 290, 291, 55, -1, 93, 94, -1, -1, - -1, -1, -1, -1, 0, -1, -1, 41, -1, 41, - -1, -1, 44, 37, 38, 124, 125, 41, 42, 43, - 44, 45, 41, 47, -1, 44, 58, 124, 125, 61, - -1, 63, -1, 0, 58, -1, 60, 61, 62, 63, - 64, 37, 38, 62, -1, 41, 42, 43, 44, 45, - -1, 47, -1, 114, -1, 293, 294, 295, -1, -1, - 121, 93, 58, -1, 60, 61, 62, 63, 64, 93, - 94, 132, 0, -1, 41, -1, -1, 44, -1, -1, - -1, 281, -1, -1, 284, 285, 286, 287, 288, 289, - 290, 291, 124, 125, -1, 62, -1, 93, 94, -1, - 124, 125, 293, 294, 295, -1, 125, -1, -1, 37, - 38, -1, -1, 41, 42, 43, 44, 45, -1, 47, - -1, -1, -1, -1, -1, -1, 187, -1, 124, 125, - 58, -1, 60, 61, 62, 63, 64, -1, -1, -1, - -1, 37, -1, -1, 40, 206, 42, 43, -1, 45, - 46, 47, -1, -1, 215, -1, -1, 0, 125, -1, - -1, -1, 0, -1, -1, 93, 94, -1, 64, -1, - -1, -1, 281, -1, -1, 284, 285, 286, 287, 288, - 289, 290, 291, -1, 281, -1, -1, 284, 285, 286, - 287, 288, 289, 290, 291, 91, 124, 125, 41, 37, - 38, 44, -1, 41, 42, 43, 44, 45, -1, 47, - -1, -1, -1, -1, -1, 58, -1, -1, -1, -1, - 58, -1, 60, 61, 62, 63, 64, 261, -1, 263, - 264, 265, 266, -1, 268, -1, 270, -1, 272, 273, - 274, 275, 276, 277, -1, -1, -1, -1, -1, 281, - 93, -1, 284, 285, -1, 93, 94, 281, -1, -1, - 284, 285, 286, 287, 288, 289, 290, 291, -1, 37, - -1, 0, 40, -1, 42, 43, -1, 45, 46, 47, - -1, -1, 125, 0, -1, 281, 124, 125, 284, 285, - 286, 287, 288, 289, 290, 291, 64, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 37, 38, - -1, -1, 41, 42, 43, 44, 45, -1, 47, -1, - 37, 38, -1, 91, 41, 42, 43, 44, 45, 58, - 47, 60, 61, 62, 63, 64, -1, -1, -1, -1, - -1, 58, 0, 60, 61, 62, 63, 64, -1, -1, - -1, -1, -1, 281, -1, -1, 284, 285, 286, 287, - 288, 289, 290, 291, 93, 94, -1, -1, -1, -1, - 0, -1, -1, -1, -1, -1, 93, 94, -1, 37, - 38, 0, -1, 41, 42, 43, 44, 45, -1, 47, - -1, -1, -1, -1, -1, 124, 125, 293, 294, 295, - 58, -1, 60, 61, 62, 63, 64, 124, 125, -1, - -1, 41, -1, -1, 44, -1, -1, 0, -1, -1, - -1, -1, 41, -1, -1, 44, -1, -1, 58, -1, - -1, 61, -1, 63, -1, 93, 94, -1, -1, 58, - -1, -1, -1, 281, -1, -1, 284, 285, 286, 287, - 288, 289, 290, 291, 37, 38, 0, -1, 41, 42, - 43, 44, 45, 93, 47, -1, 124, 125, -1, -1, - -1, -1, -1, -1, 93, 58, -1, 60, 61, 62, - 63, 64, -1, -1, -1, 7, 8, 9, 10, -1, - -1, 13, 14, 37, 38, 125, -1, 41, 42, 43, - 44, 45, -1, 47, -1, -1, 125, -1, -1, -1, - 93, 94, -1, -1, 58, -1, 60, 61, 62, 63, - 64, -1, 290, 291, -1, 293, 294, 295, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 124, 125, -1, -1, 0, -1, -1, -1, 93, - 94, -1, 281, -1, -1, 284, 285, 286, 287, 288, - 289, 290, 291, -1, 281, -1, -1, 284, 285, 286, - 287, 288, 289, 290, 291, -1, -1, -1, -1, -1, - 124, 125, 37, 38, 106, 107, 41, 42, 43, 44, - 45, -1, 47, -1, -1, -1, -1, -1, -1, 0, - -1, -1, -1, 58, 126, 60, 61, 62, 63, 64, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 281, 0, -1, 284, 285, 286, 287, - 288, 289, 290, 291, -1, 0, 37, 38, 93, 94, - 41, 42, 43, 44, 45, -1, 47, -1, -1, -1, - -1, 281, 174, -1, 284, -1, -1, 58, -1, 60, - 61, 62, 63, 64, -1, 41, -1, -1, 44, 124, - 125, 0, -1, 38, -1, 40, 41, 42, -1, 44, - -1, -1, 58, -1, -1, 61, -1, 63, -1, -1, - -1, -1, 93, 94, -1, -1, -1, 62, 281, -1, - -1, 284, 285, 286, 287, 288, 289, 290, 291, 38, - -1, -1, 41, 0, 43, 44, 45, 93, 94, -1, - -1, -1, -1, 124, 125, 0, 91, -1, -1, 58, - -1, 60, 61, 62, 63, 64, -1, 281, -1, -1, - 284, 285, 286, 287, 288, 289, 290, 291, 124, 125, - -1, 38, -1, 0, 41, -1, 43, 44, 45, -1, - 125, -1, -1, 38, 93, 94, 41, -1, -1, 44, - -1, 58, -1, 60, 61, 62, 63, 64, -1, -1, - -1, -1, -1, 58, -1, 60, 61, 62, 63, 64, - -1, 38, -1, -1, 41, 124, 125, 44, -1, -1, - -1, 0, -1, -1, -1, -1, 93, 94, -1, -1, - -1, 58, -1, 60, 61, 62, 63, -1, 93, 94, - -1, -1, -1, -1, -1, -1, 281, -1, -1, 284, - 285, 286, 287, 288, 289, 290, 291, 124, 125, 38, - -1, -1, 41, -1, -1, 44, 93, 94, -1, 124, - 125, -1, -1, -1, -1, 0, -1, -1, -1, 58, - -1, 60, 61, 62, 63, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 124, 125, -1, - 281, -1, -1, 284, 285, 286, 287, 288, 289, 290, - 291, -1, 0, 38, 93, 94, 41, -1, -1, 44, - -1, -1, 0, -1, 269, 281, -1, -1, 284, 285, - -1, 276, 277, 58, -1, 60, 61, 62, 63, -1, - -1, -1, -1, -1, -1, 124, 125, 0, -1, -1, - 38, -1, 40, 41, 42, -1, 44, -1, -1, -1, - 38, -1, 40, 41, 42, -1, 44, -1, 93, 94, - -1, -1, 281, -1, 62, 284, 285, 286, 287, 288, - 289, 290, 291, -1, 62, 38, -1, -1, 41, -1, - -1, 44, -1, -1, -1, -1, -1, -1, -1, 124, - 125, -1, -1, 91, -1, 58, -1, 60, 61, 62, - 63, -1, -1, 91, 281, -1, -1, 284, 285, 286, - 287, 288, 289, 290, 291, -1, 281, -1, -1, 284, - 285, 286, 287, 288, 289, 290, 291, 125, -1, -1, - 93, 94, -1, -1, -1, -1, -1, 125, -1, -1, - -1, -1, -1, -1, 281, 0, -1, 284, 285, 286, - 287, 288, 289, 290, 291, -1, -1, -1, -1, -1, - -1, 124, 125, 261, -1, 263, 264, 265, 266, -1, - 268, 0, 270, -1, 272, 273, 274, 275, 276, 277, - -1, -1, 0, 38, -1, -1, 41, -1, -1, 44, - -1, -1, 281, -1, -1, 284, 285, 286, 287, 288, - 289, 290, 291, 58, -1, 60, 61, 62, 63, 38, - -1, -1, 41, -1, -1, 44, -1, -1, -1, 0, - 38, -1, -1, 41, -1, -1, 44, -1, -1, 58, - -1, 60, 61, 62, 63, -1, -1, -1, 93, 94, - 58, -1, -1, 61, -1, 63, 281, -1, -1, 284, - 285, 286, 287, 288, 289, -1, -1, 38, -1, -1, - 41, -1, -1, 44, 93, 94, -1, -1, -1, 124, - 125, 269, -1, -1, -1, 93, 94, 58, 276, 277, - 61, 269, 63, -1, -1, 33, -1, -1, 276, 277, - 0, -1, 40, -1, -1, 124, 125, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 124, 125, -1, -1, - -1, -1, 93, 94, -1, 0, -1, -1, 281, -1, - 0, 284, 285, 286, 287, 288, 289, -1, 38, 0, - 40, 41, 42, -1, 44, -1, -1, -1, -1, -1, - -1, -1, -1, 124, 125, 0, -1, -1, -1, -1, - -1, -1, 62, 38, -1, 40, 41, 42, 38, 44, - 40, 41, 42, -1, 44, -1, -1, 38, -1, 40, - 41, 42, -1, 44, -1, 123, -1, 62, 126, -1, - -1, 91, 62, 38, -1, 40, 41, 42, -1, 44, - -1, 62, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 33, 91, 62, -1, -1, - 38, 91, 40, -1, 42, 125, -1, 45, -1, -1, - 91, -1, -1, -1, -1, -1, 281, -1, -1, 284, - 285, 286, 287, 288, 289, -1, 91, -1, -1, -1, - 125, -1, -1, -1, 38, 125, 40, 41, 42, -1, - -1, -1, 281, -1, 125, 284, 285, 286, 287, 288, - 289, -1, -1, 281, -1, -1, 284, 285, 286, 287, - 125, 33, -1, -1, -1, -1, 38, -1, 40, -1, - 42, -1, -1, 45, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 123, -1, 91, 126, -1, - 281, -1, -1, 284, 285, 286, 287, -1, -1, 257, - 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, - 268, 269, 270, -1, 272, 273, 274, 275, 276, 277, - 278, 279, 280, -1, 282, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 293, 294, -1, 296, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 269, - -1, 123, -1, -1, 126, -1, 276, 277, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 269, -1, -1, -1, -1, 269, - -1, 276, 277, -1, -1, -1, 276, 277, 269, -1, - -1, -1, -1, -1, -1, 276, 277, -1, -1, -1, - -1, -1, -1, -1, 269, -1, -1, -1, -1, -1, - -1, 276, 277, -1, -1, -1, -1, -1, -1, 257, - 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, - 268, 269, 270, -1, 272, 273, 274, 275, 276, 277, - 278, 279, 280, -1, 282, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 293, 294, 261, 296, 263, - 264, 265, 266, -1, 268, -1, 270, -1, 272, 273, - 274, 275, 276, 277, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 257, 258, 259, 260, 261, - 262, 263, 264, 265, 266, 267, 268, 269, 270, -1, - 272, 273, 274, 275, 276, 277, 278, 279, 280, -1, - 282, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 293, 294, -1, 296, 37, 38, -1, 40, -1, - 42, 43, -1, 45, 46, 47, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 58, -1, 60, 61, - 62, 63, 64, -1, -1, -1, -1, -1, -1, -1, - 37, 38, -1, 40, -1, 42, 43, 42, 45, 46, - 47, -1, -1, -1, -1, -1, -1, -1, -1, 91, - -1, -1, 94, 60, 61, 62, 63, 64, -1, -1, - -1, -1, -1, -1, -1, 37, 38, -1, 40, -1, - 42, 43, -1, 45, 46, 47, 42, -1, -1, -1, - -1, -1, 124, -1, 91, -1, -1, 94, 60, -1, - 62, 63, 64, 37, 38, -1, 40, -1, 42, 43, - -1, 45, 46, 47, 37, 38, -1, 40, -1, 42, - 43, -1, 45, 46, 47, -1, 60, 124, 62, 91, - 64, -1, 94, -1, -1, -1, -1, 60, -1, 62, - -1, 64, 37, 38, -1, 40, -1, 42, 43, -1, - 45, 46, 47, -1, -1, -1, -1, 91, -1, -1, - 94, -1, 124, -1, -1, 60, -1, 62, 91, 64, - -1, 94, -1, -1, -1, 37, 38, -1, 40, -1, - 42, 43, -1, 45, 46, 47, 41, -1, -1, -1, - 124, -1, -1, -1, -1, -1, 91, -1, 60, 94, - 62, 124, 64, -1, -1, -1, -1, -1, -1, -1, - 37, -1, -1, 40, -1, 42, 43, -1, 45, 46, - 47, -1, -1, -1, -1, -1, -1, -1, -1, 91, - -1, -1, -1, 60, -1, 62, -1, 64, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 281, - -1, -1, 284, 285, 286, 287, 288, 289, 290, 291, - -1, 293, 294, 295, 91, 260, 261, 262, 263, 264, - 265, 266, -1, 268, -1, 270, -1, 272, 273, 274, - 275, 276, 277, -1, 281, -1, -1, 284, 285, 286, - 287, 288, 289, 290, 291, -1, 293, 294, 295, -1, - -1, 296, -1, -1, 260, 261, 262, 263, 264, 265, - 266, -1, 268, -1, 270, -1, 272, 273, 274, 275, - 276, 277, 284, 285, 286, 287, 288, 289, 290, 291, - -1, 293, 294, 295, -1, -1, -1, -1, -1, -1, - 296, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 285, 286, 287, 288, 289, 290, 291, -1, 293, - 294, 295, -1, 286, 287, 288, 289, 290, 291, -1, - 293, 294, 295, -1, -1, -1, -1, -1, -1, -1, - 37, -1, -1, 40, -1, 42, 43, -1, 45, 46, - 47, 286, 287, 288, 289, 290, 291, -1, 293, 294, - 295, -1, -1, 60, -1, 62, 261, 64, 263, 264, - 265, 266, -1, 268, -1, 270, -1, 272, 273, 274, - 275, 276, 277, 11, 286, 287, 288, 289, 290, 291, - -1, 293, 294, 295, 91, -1, -1, 25, 26, 27, - 28, 29, -1, -1, 32, 33, -1, -1, -1, -1, - -1, -1, -1, 41, -1, -1, -1, -1, -1, 286, - 287, 288, 289, 290, 291, -1, 293, 294, 295, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 82, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, - 98, 99, 100, 101, 102, 103, -1, -1, -1, -1, - -1, -1, 110, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 135, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 159, -1, -1, 162, -1, -1, -1, 166, -1, - -1, 169, 170, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 191, -1, -1, -1, 195, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 288, 289, 290, 291, -1, 293, 294, 295, -}; -#define YYFINAL 35 -#ifndef YYDEBUG -#define YYDEBUG 0 -#endif -#define YYMAXTOKEN 296 -#if YYDEBUG -char *c_name[] = { -"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -"'!'",0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'","','","'-'","'.'","'/'",0,0,0, -0,0,0,0,0,0,0,"':'",0,"'<'","'='","'>'","'?'","'@'",0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,"'['",0,"']'","'^'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,"'{'","'|'","'}'","'~'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"INT","FLOAT", -"STRING","NAME","TYPENAME","NAME_OR_INT","STRUCT","CLASS","UNION","ENUM", -"SIZEOF","UNSIGNED","COLONCOLON","TEMPLATE","ERROR","SIGNED_KEYWORD","LONG", -"SHORT","INT_KEYWORD","CONST_KEYWORD","VOLATILE_KEYWORD","LAST","REGNAME", -"VARIABLE","ASSIGN_MODIFY","THIS","ABOVE_COMMA","OROR","ANDAND","EQUAL", -"NOTEQUAL","LEQ","GEQ","LSH","RSH","UNARY","INCREMENT","DECREMENT","ARROW", -"BLOCKNAME", -}; -char *c_rule[] = { -"$accept : start", -"start : exp1", -"start : type_exp", -"type_exp : type", -"exp1 : exp", -"exp1 : exp1 ',' exp", -"exp : '*' exp", -"exp : '&' exp", -"exp : '-' exp", -"exp : '!' exp", -"exp : '~' exp", -"exp : INCREMENT exp", -"exp : DECREMENT exp", -"exp : exp INCREMENT", -"exp : exp DECREMENT", -"exp : SIZEOF exp", -"exp : exp ARROW name", -"exp : exp ARROW qualified_name", -"exp : exp ARROW '*' exp", -"exp : exp '.' name", -"exp : exp '.' qualified_name", -"exp : exp '.' '*' exp", -"exp : exp '[' exp1 ']'", -"$$1 :", -"exp : exp '(' $$1 arglist ')'", -"lcurly : '{'", -"arglist :", -"arglist : exp", -"arglist : arglist ',' exp", -"rcurly : '}'", -"exp : lcurly arglist rcurly", -"exp : lcurly type rcurly exp", -"exp : '(' type ')' exp", -"exp : '(' exp1 ')'", -"exp : exp '@' exp", -"exp : exp '*' exp", -"exp : exp '/' exp", -"exp : exp '%' exp", -"exp : exp '+' exp", -"exp : exp '-' exp", -"exp : exp LSH exp", -"exp : exp RSH exp", -"exp : exp EQUAL exp", -"exp : exp NOTEQUAL exp", -"exp : exp LEQ exp", -"exp : exp GEQ exp", -"exp : exp '<' exp", -"exp : exp '>' exp", -"exp : exp '&' exp", -"exp : exp '^' exp", -"exp : exp '|' exp", -"exp : exp ANDAND exp", -"exp : exp OROR exp", -"exp : exp '?' exp ':' exp", -"exp : exp '=' exp", -"exp : exp ASSIGN_MODIFY exp", -"exp : INT", -"exp : NAME_OR_INT", -"exp : FLOAT", -"exp : variable", -"exp : LAST", -"exp : REGNAME", -"exp : VARIABLE", -"exp : SIZEOF '(' type ')'", -"exp : STRING", -"exp : THIS", -"block : BLOCKNAME", -"block : block COLONCOLON name", -"variable : block COLONCOLON name", -"qualified_name : typebase COLONCOLON name", -"qualified_name : typebase COLONCOLON '~' name", -"variable : qualified_name", -"variable : COLONCOLON name", -"variable : name_not_typename", -"ptype : typebase", -"ptype : typebase CONST_KEYWORD", -"ptype : typebase VOLATILE_KEYWORD", -"ptype : typebase abs_decl", -"ptype : typebase CONST_KEYWORD abs_decl", -"ptype : typebase VOLATILE_KEYWORD abs_decl", -"abs_decl : '*'", -"abs_decl : '*' abs_decl", -"abs_decl : '&'", -"abs_decl : '&' abs_decl", -"abs_decl : direct_abs_decl", -"direct_abs_decl : '(' abs_decl ')'", -"direct_abs_decl : direct_abs_decl array_mod", -"direct_abs_decl : array_mod", -"direct_abs_decl : direct_abs_decl func_mod", -"direct_abs_decl : func_mod", -"array_mod : '[' ']'", -"array_mod : '[' INT ']'", -"func_mod : '(' ')'", -"func_mod : '(' nonempty_typelist ')'", -"type : ptype", -"type : typebase COLONCOLON '*'", -"type : type '(' typebase COLONCOLON '*' ')'", -"type : type '(' typebase COLONCOLON '*' ')' '(' ')'", -"type : type '(' typebase COLONCOLON '*' ')' '(' nonempty_typelist ')'", -"typebase : TYPENAME", -"typebase : INT_KEYWORD", -"typebase : LONG", -"typebase : SHORT", -"typebase : LONG INT_KEYWORD", -"typebase : UNSIGNED LONG INT_KEYWORD", -"typebase : LONG LONG", -"typebase : LONG LONG INT_KEYWORD", -"typebase : UNSIGNED LONG LONG", -"typebase : UNSIGNED LONG LONG INT_KEYWORD", -"typebase : SHORT INT_KEYWORD", -"typebase : UNSIGNED SHORT INT_KEYWORD", -"typebase : STRUCT name", -"typebase : CLASS name", -"typebase : UNION name", -"typebase : ENUM name", -"typebase : UNSIGNED typename", -"typebase : UNSIGNED", -"typebase : SIGNED_KEYWORD typename", -"typebase : SIGNED_KEYWORD", -"typebase : TEMPLATE name '<' type '>'", -"typebase : CONST_KEYWORD typebase", -"typebase : VOLATILE_KEYWORD typebase", -"typename : TYPENAME", -"typename : INT_KEYWORD", -"typename : LONG", -"typename : SHORT", -"nonempty_typelist : type", -"nonempty_typelist : nonempty_typelist ',' type", -"name : NAME", -"name : BLOCKNAME", -"name : TYPENAME", -"name : NAME_OR_INT", -"name_not_typename : NAME", -"name_not_typename : BLOCKNAME", -}; -#endif -#ifdef YYSTACKSIZE -#undef YYMAXDEPTH -#define YYMAXDEPTH YYSTACKSIZE -#else -#ifdef YYMAXDEPTH -#define YYSTACKSIZE YYMAXDEPTH -#else -#define YYSTACKSIZE 500 -#define YYMAXDEPTH 500 -#endif -#endif -int yydebug; -int yynerrs; -int yyerrflag; -int yychar; -short *yyssp; -YYSTYPE *yyvsp; -YYSTYPE yyval; -YYSTYPE yylval; -short yyss[YYSTACKSIZE]; -YYSTYPE yyvs[YYSTACKSIZE]; -#define yystacksize YYSTACKSIZE -#line 914 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" - -/* Take care of parsing a number (anything that starts with a digit). - Set yylval and return the token type; update lexptr. - LEN is the number of characters in it. */ - -/*** Needs some error checking for the float case ***/ - -static int -parse_number (p, len, parsed_float, putithere) - register char *p; - register int len; - int parsed_float; - YYSTYPE *putithere; -{ - register LONGEST n = 0; - register LONGEST prevn = 0; - register int i = 0; - register int c; - register int base = input_radix; - int unsigned_p = 0; - int long_p = 0; - unsigned LONGEST high_bit; - struct type *signed_type; - struct type *unsigned_type; - - if (parsed_float) - { - /* It's a float since it contains a point or an exponent. */ - putithere->dval = atof (p); - return FLOAT; - } - - /* Handle base-switching prefixes 0x, 0t, 0d, 0 */ - if (p[0] == '0') - switch (p[1]) - { - case 'x': - case 'X': - if (len >= 3) - { - p += 2; - base = 16; - len -= 2; - } - break; - - case 't': - case 'T': - case 'd': - case 'D': - if (len >= 3) - { - p += 2; - base = 10; - len -= 2; - } - break; - - default: - base = 8; - break; - } - - while (len-- > 0) - { - c = *p++; - if (c >= 'A' && c <= 'Z') - c += 'a' - 'A'; - if (c != 'l' && c != 'u') - n *= base; - if (c >= '0' && c <= '9') - n += i = c - '0'; - else - { - if (base > 10 && c >= 'a' && c <= 'f') - n += i = c - 'a' + 10; - else if (len == 0 && c == 'l') - long_p = 1; - else if (len == 0 && c == 'u') - unsigned_p = 1; - else - return ERROR; /* Char not a digit */ - } - if (i >= base) - return ERROR; /* Invalid digit in this base */ - - /* Portably test for overflow (only works for nonzero values, so make - a second check for zero). */ - if((prevn >= n) && n != 0) - unsigned_p=1; /* Try something unsigned */ - /* If range checking enabled, portably test for unsigned overflow. */ - if(RANGE_CHECK && n!=0) - { - if((unsigned_p && (unsigned)prevn >= (unsigned)n)) - range_error("Overflow on numeric constant."); - } - prevn=n; - } - - /* If the number is too big to be an int, or it's got an l suffix - then it's a long. Work out if this has to be a long by - shifting right and and seeing if anything remains, and the - target int size is different to the target long size. - - In the expression below, we could have tested - (n >> TARGET_INT_BIT) - to see if it was zero, - but too many compilers warn about that, when ints and longs - are the same size. So we shift it twice, with fewer bits - each time, for the same result. */ - - if ( (TARGET_INT_BIT != TARGET_LONG_BIT - && ((n >> 2) >> (TARGET_INT_BIT-2))) /* Avoid shift warning */ - || long_p) - { - high_bit = ((unsigned LONGEST)1) << (TARGET_LONG_BIT-1); - unsigned_type = builtin_type_unsigned_long; - signed_type = builtin_type_long; - } - else - { - high_bit = ((unsigned LONGEST)1) << (TARGET_INT_BIT-1); - unsigned_type = builtin_type_unsigned_int; - signed_type = builtin_type_int; - } - - putithere->typed_val.val = n; - - /* If the high bit of the worked out type is set then this number - has to be unsigned. */ - - if (unsigned_p || (n & high_bit)) - { - putithere->typed_val.type = unsigned_type; - } - else - { - putithere->typed_val.type = signed_type; - } - - return INT; -} - -struct token -{ - char *operator; - int token; - enum exp_opcode opcode; -}; - -static const struct token tokentab3[] = - { - {">>=", ASSIGN_MODIFY, BINOP_RSH}, - {"<<=", ASSIGN_MODIFY, BINOP_LSH} - }; - -static const struct token tokentab2[] = - { - {"+=", ASSIGN_MODIFY, BINOP_ADD}, - {"-=", ASSIGN_MODIFY, BINOP_SUB}, - {"*=", ASSIGN_MODIFY, BINOP_MUL}, - {"/=", ASSIGN_MODIFY, BINOP_DIV}, - {"%=", ASSIGN_MODIFY, BINOP_REM}, - {"|=", ASSIGN_MODIFY, BINOP_BITWISE_IOR}, - {"&=", ASSIGN_MODIFY, BINOP_BITWISE_AND}, - {"^=", ASSIGN_MODIFY, BINOP_BITWISE_XOR}, - {"++", INCREMENT, BINOP_END}, - {"--", DECREMENT, BINOP_END}, - {"->", ARROW, BINOP_END}, - {"&&", ANDAND, BINOP_END}, - {"||", OROR, BINOP_END}, - {"::", COLONCOLON, BINOP_END}, - {"<<", LSH, BINOP_END}, - {">>", RSH, BINOP_END}, - {"==", EQUAL, BINOP_END}, - {"!=", NOTEQUAL, BINOP_END}, - {"<=", LEQ, BINOP_END}, - {">=", GEQ, BINOP_END} - }; - -/* Read one token, getting characters through lexptr. */ - -static int -yylex () -{ - int c; - int namelen; - unsigned int i; - char *tokstart; - char *tokptr; - int tempbufindex; - static char *tempbuf; - static int tempbufsize; - - retry: - - tokstart = lexptr; - /* See if it is a special token of length 3. */ - for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++) - if (STREQN (tokstart, tokentab3[i].operator, 3)) - { - lexptr += 3; - yylval.opcode = tokentab3[i].opcode; - return tokentab3[i].token; - } - - /* See if it is a special token of length 2. */ - for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++) - if (STREQN (tokstart, tokentab2[i].operator, 2)) - { - lexptr += 2; - yylval.opcode = tokentab2[i].opcode; - return tokentab2[i].token; - } - - switch (c = *tokstart) - { - case 0: - return 0; - - case ' ': - case '\t': - case '\n': - lexptr++; - goto retry; - - case '\'': - /* We either have a character constant ('0' or '\177' for example) - or we have a quoted symbol reference ('foo(int,int)' in C++ - for example). */ - lexptr++; - c = *lexptr++; - if (c == '\\') - c = parse_escape (&lexptr); - - yylval.typed_val.val = c; - yylval.typed_val.type = builtin_type_char; - - c = *lexptr++; - if (c != '\'') - { - namelen = skip_quoted (tokstart) - tokstart; - if (namelen > 2) - { - lexptr = tokstart + namelen; - if (lexptr[-1] != '\'') - error ("Unmatched single quote."); - namelen -= 2; - tokstart++; - goto tryname; - } - error ("Invalid character constant."); - } - return INT; - - case '(': - paren_depth++; - lexptr++; - return c; - - case ')': - if (paren_depth == 0) - return 0; - paren_depth--; - lexptr++; - return c; - - case ',': - if (comma_terminates && paren_depth == 0) - return 0; - lexptr++; - return c; - - case '.': - /* Might be a floating point number. */ - if (lexptr[1] < '0' || lexptr[1] > '9') - goto symbol; /* Nope, must be a symbol. */ - /* FALL THRU into number case. */ - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - { - /* It's a number. */ - int got_dot = 0, got_e = 0, toktype; - register char *p = tokstart; - int hex = input_radix > 10; - - if (c == '0' && (p[1] == 'x' || p[1] == 'X')) - { - p += 2; - hex = 1; - } - else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D')) - { - p += 2; - hex = 0; - } - - for (;; ++p) - { - /* This test includes !hex because 'e' is a valid hex digit - and thus does not indicate a floating point number when - the radix is hex. */ - if (!hex && !got_e && (*p == 'e' || *p == 'E')) - got_dot = got_e = 1; - /* This test does not include !hex, because a '.' always indicates - a decimal floating point number regardless of the radix. */ - else if (!got_dot && *p == '.') - got_dot = 1; - else if (got_e && (p[-1] == 'e' || p[-1] == 'E') - && (*p == '-' || *p == '+')) - /* This is the sign of the exponent, not the end of the - number. */ - continue; - /* We will take any letters or digits. parse_number will - complain if past the radix, or if L or U are not final. */ - else if ((*p < '0' || *p > '9') - && ((*p < 'a' || *p > 'z') - && (*p < 'A' || *p > 'Z'))) - break; - } - toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval); - if (toktype == ERROR) - { - char *err_copy = (char *) alloca (p - tokstart + 1); - - memcpy (err_copy, tokstart, p - tokstart); - err_copy[p - tokstart] = 0; - error ("Invalid number \"%s\".", err_copy); - } - lexptr = p; - return toktype; - } - - case '+': - case '-': - case '*': - case '/': - case '%': - case '|': - case '&': - case '^': - case '~': - case '!': - case '@': - case '<': - case '>': - case '[': - case ']': - case '?': - case ':': - case '=': - case '{': - case '}': - symbol: - lexptr++; - return c; - - case '"': - - /* Build the gdb internal form of the input string in tempbuf, - translating any standard C escape forms seen. Note that the - buffer is null byte terminated *only* for the convenience of - debugging gdb itself and printing the buffer contents when - the buffer contains no embedded nulls. Gdb does not depend - upon the buffer being null byte terminated, it uses the length - string instead. This allows gdb to handle C strings (as well - as strings in other languages) with embedded null bytes */ - - tokptr = ++tokstart; - tempbufindex = 0; - - do { - /* Grow the static temp buffer if necessary, including allocating - the first one on demand. */ - if (tempbufindex + 1 >= tempbufsize) - { - tempbuf = (char *) xrealloc (tempbuf, tempbufsize += 64); - } - switch (*tokptr) - { - case '\0': - case '"': - /* Do nothing, loop will terminate. */ - break; - case '\\': - tokptr++; - c = parse_escape (&tokptr); - if (c == -1) - { - continue; - } - tempbuf[tempbufindex++] = c; - break; - default: - tempbuf[tempbufindex++] = *tokptr++; - break; - } - } while ((*tokptr != '"') && (*tokptr != '\0')); - if (*tokptr++ != '"') - { - error ("Unterminated string in expression."); - } - tempbuf[tempbufindex] = '\0'; /* See note above */ - yylval.sval.ptr = tempbuf; - yylval.sval.length = tempbufindex; - lexptr = tokptr; - return (STRING); - } - - if (!(c == '_' || c == '$' - || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) - /* We must have come across a bad character (e.g. ';'). */ - error ("Invalid character '%c' in expression.", c); - - /* It's a name. See how long it is. */ - namelen = 0; - for (c = tokstart[namelen]; - (c == '_' || c == '$' || (c >= '0' && c <= '9') - || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); - c = tokstart[++namelen]) - ; - - /* The token "if" terminates the expression and is NOT - removed from the input stream. */ - if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f') - { - return 0; - } - - lexptr += namelen; - - /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1) - and $$digits (equivalent to $<-digits> if you could type that). - Make token type LAST, and put the number (the digits) in yylval. */ - - tryname: - if (*tokstart == '$') - { - register int negate = 0; - c = 1; - /* Double dollar means negate the number and add -1 as well. - Thus $$ alone means -1. */ - if (namelen >= 2 && tokstart[1] == '$') - { - negate = 1; - c = 2; - } - if (c == namelen) - { - /* Just dollars (one or two) */ - yylval.lval = - negate; - return LAST; - } - /* Is the rest of the token digits? */ - for (; c < namelen; c++) - if (!(tokstart[c] >= '0' && tokstart[c] <= '9')) - break; - if (c == namelen) - { - yylval.lval = atoi (tokstart + 1 + negate); - if (negate) - yylval.lval = - yylval.lval; - return LAST; - } - } - - /* Handle tokens that refer to machine registers: - $ followed by a register name. */ - - if (*tokstart == '$') { - for (c = 0; c < NUM_REGS; c++) - if (namelen - 1 == strlen (reg_names[c]) - && STREQN (tokstart + 1, reg_names[c], namelen - 1)) - { - yylval.lval = c; - return REGNAME; - } - for (c = 0; c < num_std_regs; c++) - if (namelen - 1 == strlen (std_regs[c].name) - && STREQN (tokstart + 1, std_regs[c].name, namelen - 1)) - { - yylval.lval = std_regs[c].regnum; - return REGNAME; - } - } - /* Catch specific keywords. Should be done with a data structure. */ - switch (namelen) - { - case 8: - if (STREQN (tokstart, "unsigned", 8)) - return UNSIGNED; - if (current_language->la_language == language_cplus - && STREQN (tokstart, "template", 8)) - return TEMPLATE; - if (STREQN (tokstart, "volatile", 8)) - return VOLATILE_KEYWORD; - break; - case 6: - if (STREQN (tokstart, "struct", 6)) - return STRUCT; - if (STREQN (tokstart, "signed", 6)) - return SIGNED_KEYWORD; - if (STREQN (tokstart, "sizeof", 6)) - return SIZEOF; - break; - case 5: - if (current_language->la_language == language_cplus - && STREQN (tokstart, "class", 5)) - return CLASS; - if (STREQN (tokstart, "union", 5)) - return UNION; - if (STREQN (tokstart, "short", 5)) - return SHORT; - if (STREQN (tokstart, "const", 5)) - return CONST_KEYWORD; - break; - case 4: - if (STREQN (tokstart, "enum", 4)) - return ENUM; - if (STREQN (tokstart, "long", 4)) - return LONG; - if (current_language->la_language == language_cplus - && STREQN (tokstart, "this", 4)) - { - static const char this_name[] = - { CPLUS_MARKER, 't', 'h', 'i', 's', '\0' }; - - if (lookup_symbol (this_name, expression_context_block, - VAR_NAMESPACE, (int *) NULL, - (struct symtab **) NULL)) - return THIS; - } - break; - case 3: - if (STREQN (tokstart, "int", 3)) - return INT_KEYWORD; - break; - default: - break; - } - - yylval.sval.ptr = tokstart; - yylval.sval.length = namelen; - - /* Any other names starting in $ are debugger internal variables. */ - - if (*tokstart == '$') - { - yylval.ivar = lookup_internalvar (copy_name (yylval.sval) + 1); - return VARIABLE; - } - - /* Use token-type BLOCKNAME for symbols that happen to be defined as - functions or symtabs. If this is not so, then ... - Use token-type TYPENAME for symbols that happen to be defined - currently as names of types; NAME for other symbols. - The caller is not constrained to care about the distinction. */ - { - char *tmp = copy_name (yylval.sval); - struct symbol *sym; - int is_a_field_of_this = 0; - int hextype; - - sym = lookup_symbol (tmp, expression_context_block, - VAR_NAMESPACE, - current_language->la_language == language_cplus - ? &is_a_field_of_this : (int *) NULL, - (struct symtab **) NULL); - if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK) || - lookup_partial_symtab (tmp)) - { - yylval.ssym.sym = sym; - yylval.ssym.is_a_field_of_this = is_a_field_of_this; - return BLOCKNAME; - } - if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF) - { - char *p; - char *namestart; - struct symbol *best_sym; - - /* Look ahead to detect nested types. This probably should be - done in the grammar, but trying seemed to introduce a lot - of shift/reduce and reduce/reduce conflicts. It's possible - that it could be done, though. Or perhaps a non-grammar, but - less ad hoc, approach would work well. */ - - /* Since we do not currently have any way of distinguishing - a nested type from a non-nested one (the stabs don't tell - us whether a type is nested), we just ignore the - containing type. */ - - p = lexptr; - best_sym = sym; - while (1) - { - /* Skip whitespace. */ - while (*p == ' ' || *p == '\t' || *p == '\n') - ++p; - if (*p == ':' && p[1] == ':') - { - /* Skip the `::'. */ - p += 2; - /* Skip whitespace. */ - while (*p == ' ' || *p == '\t' || *p == '\n') - ++p; - namestart = p; - while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9') - || (*p >= 'a' && *p <= 'z') - || (*p >= 'A' && *p <= 'Z')) - ++p; - if (p != namestart) - { - struct symbol *cur_sym; - /* As big as the whole rest of the expression, which is - at least big enough. */ - char *tmp = alloca (strlen (namestart)); - - memcpy (tmp, namestart, p - namestart); - tmp[p - namestart] = '\0'; - cur_sym = lookup_symbol (tmp, expression_context_block, - VAR_NAMESPACE, (int *) NULL, - (struct symtab **) NULL); - if (cur_sym) - { - if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF) - { - best_sym = cur_sym; - lexptr = p; - } - else - break; - } - else - break; - } - else - break; - } - else - break; - } - - yylval.tsym.type = SYMBOL_TYPE (best_sym); - return TYPENAME; - } - if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0) - return TYPENAME; - - /* Input names that aren't symbols but ARE valid hex numbers, - when the input radix permits them, can be names or numbers - depending on the parse. Note we support radixes > 16 here. */ - if (!sym && - ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) || - (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10))) - { - YYSTYPE newlval; /* Its value is ignored. */ - hextype = parse_number (tokstart, namelen, 0, &newlval); - if (hextype == INT) - { - yylval.ssym.sym = sym; - yylval.ssym.is_a_field_of_this = is_a_field_of_this; - return NAME_OR_INT; - } - } - - /* Any other kind of symbol */ - yylval.ssym.sym = sym; - yylval.ssym.is_a_field_of_this = is_a_field_of_this; - return NAME; - } -} - -void -yyerror (msg) - char *msg; -{ - error (msg ? msg : "Invalid syntax in expression."); -} -#line 1706 "y.tab.c" -#define YYABORT goto yyabort -#define YYREJECT goto yyabort -#define YYACCEPT goto yyaccept -#define YYERROR goto yyerrlab -int -yyparse() -{ - register int yym, yyn, yystate; -#if YYDEBUG - register char *yys; - extern char *getenv(); - - if (yys = getenv("YYDEBUG")) - { - yyn = *yys; - if (yyn >= '0' && yyn <= '9') - yydebug = yyn - '0'; - } -#endif - - yynerrs = 0; - yyerrflag = 0; - yychar = (-1); - - yyssp = yyss; - yyvsp = yyvs; - *yyssp = yystate = 0; - -yyloop: - if (yyn = yydefred[yystate]) goto yyreduce; - if (yychar < 0) - { - if ((yychar = yylex()) < 0) yychar = 0; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, reading %d (%s)\n", - YYPREFIX, yystate, yychar, yys); - } -#endif - } - if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yychar) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, shifting to state %d\n", - YYPREFIX, yystate, yytable[yyn]); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate = yytable[yyn]; - *++yyvsp = yylval; - yychar = (-1); - if (yyerrflag > 0) --yyerrflag; - goto yyloop; - } - if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yychar) - { - yyn = yytable[yyn]; - goto yyreduce; - } - if (yyerrflag) goto yyinrecovery; -#ifdef lint - goto yynewerror; -#endif -yynewerror: - yyerror("syntax error"); -#ifdef lint - goto yyerrlab; -#endif -yyerrlab: - ++yynerrs; -yyinrecovery: - if (yyerrflag < 3) - { - yyerrflag = 3; - for (;;) - { - if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, error recovery shifting\ - to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate = yytable[yyn]; - *++yyvsp = yylval; - goto yyloop; - } - else - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: error recovery discarding state %d\n", - YYPREFIX, *yyssp); -#endif - if (yyssp <= yyss) goto yyabort; - --yyssp; - --yyvsp; - } - } - } - else - { - if (yychar == 0) goto yyabort; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, error recovery discards token %d (%s)\n", - YYPREFIX, yystate, yychar, yys); - } -#endif - yychar = (-1); - goto yyloop; - } -yyreduce: -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, reducing by rule %d (%s)\n", - YYPREFIX, yystate, yyn, yyrule[yyn]); -#endif - yym = yylen[yyn]; - yyval = yyvsp[1-yym]; - switch (yyn) - { -case 3: -#line 211 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type(yyvsp[0].tval); - write_exp_elt_opcode(OP_TYPE);} -break; -case 5: -#line 219 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_COMMA); } -break; -case 6: -#line 224 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_IND); } -break; -case 7: -#line 227 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_ADDR); } -break; -case 8: -#line 230 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_NEG); } -break; -case 9: -#line 234 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); } -break; -case 10: -#line 238 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_COMPLEMENT); } -break; -case 11: -#line 242 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_PREINCREMENT); } -break; -case 12: -#line 246 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_PREDECREMENT); } -break; -case 13: -#line 250 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_POSTINCREMENT); } -break; -case 14: -#line 254 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_POSTDECREMENT); } -break; -case 15: -#line 258 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_SIZEOF); } -break; -case 16: -#line 262 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string (yyvsp[0].sval); - write_exp_elt_opcode (STRUCTOP_PTR); } -break; -case 17: -#line 268 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ /* exp->type::name becomes exp->*(&type::name) */ - /* Note: this doesn't work if name is a - static member! FIXME */ - write_exp_elt_opcode (UNOP_ADDR); - write_exp_elt_opcode (STRUCTOP_MPTR); } -break; -case 18: -#line 275 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (STRUCTOP_MPTR); } -break; -case 19: -#line 279 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string (yyvsp[0].sval); - write_exp_elt_opcode (STRUCTOP_STRUCT); } -break; -case 20: -#line 285 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ /* exp.type::name becomes exp.*(&type::name) */ - /* Note: this doesn't work if name is a - static member! FIXME */ - write_exp_elt_opcode (UNOP_ADDR); - write_exp_elt_opcode (STRUCTOP_MEMBER); } -break; -case 21: -#line 293 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (STRUCTOP_MEMBER); } -break; -case 22: -#line 297 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_SUBSCRIPT); } -break; -case 23: -#line 303 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ start_arglist (); } -break; -case 24: -#line 305 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_FUNCALL); } -break; -case 25: -#line 311 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ start_arglist (); } -break; -case 27: -#line 318 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ arglist_len = 1; } -break; -case 28: -#line 322 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ arglist_len++; } -break; -case 29: -#line 326 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.lval = end_arglist () - 1; } -break; -case 30: -#line 329 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (OP_ARRAY); - write_exp_elt_longcst ((LONGEST) 0); - write_exp_elt_longcst ((LONGEST) yyvsp[0].lval); - write_exp_elt_opcode (OP_ARRAY); } -break; -case 31: -#line 336 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_MEMVAL); - write_exp_elt_type (yyvsp[-2].tval); - write_exp_elt_opcode (UNOP_MEMVAL); } -break; -case 32: -#line 342 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (yyvsp[-2].tval); - write_exp_elt_opcode (UNOP_CAST); } -break; -case 33: -#line 348 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ } -break; -case 34: -#line 354 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_REPEAT); } -break; -case 35: -#line 358 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_MUL); } -break; -case 36: -#line 362 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_DIV); } -break; -case 37: -#line 366 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_REM); } -break; -case 38: -#line 370 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_ADD); } -break; -case 39: -#line 374 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_SUB); } -break; -case 40: -#line 378 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_LSH); } -break; -case 41: -#line 382 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_RSH); } -break; -case 42: -#line 386 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_EQUAL); } -break; -case 43: -#line 390 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_NOTEQUAL); } -break; -case 44: -#line 394 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_LEQ); } -break; -case 45: -#line 398 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_GEQ); } -break; -case 46: -#line 402 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_LESS); } -break; -case 47: -#line 406 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_GTR); } -break; -case 48: -#line 410 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_BITWISE_AND); } -break; -case 49: -#line 414 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_BITWISE_XOR); } -break; -case 50: -#line 418 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_BITWISE_IOR); } -break; -case 51: -#line 422 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_LOGICAL_AND); } -break; -case 52: -#line 426 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_LOGICAL_OR); } -break; -case 53: -#line 430 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (TERNOP_COND); } -break; -case 54: -#line 434 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_ASSIGN); } -break; -case 55: -#line 438 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode (yyvsp[-1].opcode); - write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); } -break; -case 56: -#line 444 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (yyvsp[0].typed_val.type); - write_exp_elt_longcst ((LONGEST)(yyvsp[0].typed_val.val)); - write_exp_elt_opcode (OP_LONG); } -break; -case 57: -#line 451 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ YYSTYPE val; - parse_number (yyvsp[0].ssym.stoken.ptr, yyvsp[0].ssym.stoken.length, 0, &val); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (val.typed_val.type); - write_exp_elt_longcst ((LONGEST)val.typed_val.val); - write_exp_elt_opcode (OP_LONG); - } -break; -case 58: -#line 462 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type (builtin_type_double); - write_exp_elt_dblcst (yyvsp[0].dval); - write_exp_elt_opcode (OP_DOUBLE); } -break; -case 60: -#line 472 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (OP_LAST); - write_exp_elt_longcst ((LONGEST) yyvsp[0].lval); - write_exp_elt_opcode (OP_LAST); } -break; -case 61: -#line 478 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (OP_REGISTER); - write_exp_elt_longcst ((LONGEST) yyvsp[0].lval); - write_exp_elt_opcode (OP_REGISTER); } -break; -case 62: -#line 484 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (OP_INTERNALVAR); - write_exp_elt_intern (yyvsp[0].ivar); - write_exp_elt_opcode (OP_INTERNALVAR); } -break; -case 63: -#line 490 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_int); - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH (yyvsp[-1].tval)); - write_exp_elt_opcode (OP_LONG); } -break; -case 64: -#line 497 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ /* C strings are converted into array constants with - an explicit null byte added at the end. Thus - the array upper bound is the string length. - There is no such thing in C as a completely empty - string. */ - char *sp = yyvsp[0].sval.ptr; int count = yyvsp[0].sval.length; - while (count-- > 0) - { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_char); - write_exp_elt_longcst ((LONGEST)(*sp++)); - write_exp_elt_opcode (OP_LONG); - } - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_char); - write_exp_elt_longcst ((LONGEST)'\0'); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_opcode (OP_ARRAY); - write_exp_elt_longcst ((LONGEST) 0); - write_exp_elt_longcst ((LONGEST) (yyvsp[0].sval.length)); - write_exp_elt_opcode (OP_ARRAY); } -break; -case 65: -#line 522 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (OP_THIS); } -break; -case 66: -#line 529 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ - if (yyvsp[0].ssym.sym != 0) - yyval.bval = SYMBOL_BLOCK_VALUE (yyvsp[0].ssym.sym); - else - { - struct symtab *tem = - lookup_symtab (copy_name (yyvsp[0].ssym.stoken)); - if (tem) - yyval.bval = BLOCKVECTOR_BLOCK - (BLOCKVECTOR (tem), STATIC_BLOCK); - else - error ("No file or function \"%s\".", - copy_name (yyvsp[0].ssym.stoken)); - } - } -break; -case 67: -#line 547 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ struct symbol *tem - = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, - VAR_NAMESPACE, (int *) NULL, - (struct symtab **) NULL); - if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK) - error ("No function \"%s\" in specified context.", - copy_name (yyvsp[0].sval)); - yyval.bval = SYMBOL_BLOCK_VALUE (tem); } -break; -case 68: -#line 558 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ struct symbol *sym; - sym = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, - VAR_NAMESPACE, (int *) NULL, - (struct symtab **) NULL); - if (sym == 0) - error ("No symbol \"%s\" in specified context.", - copy_name (yyvsp[0].sval)); - - write_exp_elt_opcode (OP_VAR_VALUE); - /* block_found is set by lookup_symbol. */ - write_exp_elt_block (block_found); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); } -break; -case 69: -#line 574 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ - struct type *type = yyvsp[-2].tval; - if (TYPE_CODE (type) != TYPE_CODE_STRUCT - && TYPE_CODE (type) != TYPE_CODE_UNION) - error ("`%s' is not defined as an aggregate type.", - TYPE_NAME (type)); - - write_exp_elt_opcode (OP_SCOPE); - write_exp_elt_type (type); - write_exp_string (yyvsp[0].sval); - write_exp_elt_opcode (OP_SCOPE); - } -break; -case 70: -#line 587 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ - struct type *type = yyvsp[-3].tval; - struct stoken tmp_token; - if (TYPE_CODE (type) != TYPE_CODE_STRUCT - && TYPE_CODE (type) != TYPE_CODE_UNION) - error ("`%s' is not defined as an aggregate type.", - TYPE_NAME (type)); - - if (!STREQ (type_name_no_tag (type), yyvsp[0].sval.ptr)) - error ("invalid destructor `%s::~%s'", - type_name_no_tag (type), yyvsp[0].sval.ptr); - - tmp_token.ptr = (char*) alloca (yyvsp[0].sval.length + 2); - tmp_token.length = yyvsp[0].sval.length + 1; - tmp_token.ptr[0] = '~'; - memcpy (tmp_token.ptr+1, yyvsp[0].sval.ptr, yyvsp[0].sval.length); - tmp_token.ptr[tmp_token.length] = 0; - write_exp_elt_opcode (OP_SCOPE); - write_exp_elt_type (type); - write_exp_string (tmp_token); - write_exp_elt_opcode (OP_SCOPE); - } -break; -case 72: -#line 613 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ - char *name = copy_name (yyvsp[0].sval); - struct symbol *sym; - struct minimal_symbol *msymbol; - - sym = - lookup_symbol (name, (const struct block *) NULL, - VAR_NAMESPACE, (int *) NULL, - (struct symtab **) NULL); - if (sym) - { - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); - break; - } - - msymbol = lookup_minimal_symbol (name, - (struct objfile *) NULL); - if (msymbol != NULL) - { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_long); - write_exp_elt_longcst ((LONGEST) SYMBOL_VALUE_ADDRESS (msymbol)); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_opcode (UNOP_MEMVAL); - if (msymbol -> type == mst_data || - msymbol -> type == mst_bss) - write_exp_elt_type (builtin_type_int); - else if (msymbol -> type == mst_text) - write_exp_elt_type (lookup_function_type (builtin_type_int)); - else - write_exp_elt_type (builtin_type_char); - write_exp_elt_opcode (UNOP_MEMVAL); - } - else - if (!have_full_symbols () && !have_partial_symbols ()) - error ("No symbol table is loaded. Use the \"file\" command."); - else - error ("No symbol \"%s\" in current context.", name); - } -break; -case 73: -#line 658 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ struct symbol *sym = yyvsp[0].ssym.sym; - - if (sym) - { - if (symbol_read_needs_frame (sym)) - { - if (innermost_block == 0 || - contained_in (block_found, - innermost_block)) - innermost_block = block_found; - } - - write_exp_elt_opcode (OP_VAR_VALUE); - /* We want to use the selected frame, not - another more inner frame which happens to - be in the same block. */ - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); - } - else if (yyvsp[0].ssym.is_a_field_of_this) - { - /* C++: it hangs off of `this'. Must - not inadvertently convert from a method call - to data ref. */ - if (innermost_block == 0 || - contained_in (block_found, innermost_block)) - innermost_block = block_found; - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (OP_THIS); - write_exp_elt_opcode (STRUCTOP_PTR); - write_exp_string (yyvsp[0].ssym.stoken); - write_exp_elt_opcode (STRUCTOP_PTR); - } - else - { - struct minimal_symbol *msymbol; - register char *arg = copy_name (yyvsp[0].ssym.stoken); - - msymbol = lookup_minimal_symbol (arg, - (struct objfile *) NULL); - if (msymbol != NULL) - { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_long); - write_exp_elt_longcst ((LONGEST) SYMBOL_VALUE_ADDRESS (msymbol)); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_opcode (UNOP_MEMVAL); - if (msymbol -> type == mst_data || - msymbol -> type == mst_bss) - write_exp_elt_type (builtin_type_int); - else if (msymbol -> type == mst_text) - write_exp_elt_type (lookup_function_type (builtin_type_int)); - else - write_exp_elt_type (builtin_type_char); - write_exp_elt_opcode (UNOP_MEMVAL); - } - else if (!have_full_symbols () && !have_partial_symbols ()) - error ("No symbol table is loaded. Use the \"file\" command."); - else - error ("No symbol \"%s\" in current context.", - copy_name (yyvsp[0].ssym.stoken)); - } - } -break; -case 77: -#line 737 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = follow_types (yyvsp[-1].tval); } -break; -case 78: -#line 739 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = follow_types (yyvsp[-2].tval); } -break; -case 79: -#line 741 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = follow_types (yyvsp[-2].tval); } -break; -case 80: -#line 745 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ push_type (tp_pointer); yyval.voidval = 0; } -break; -case 81: -#line 747 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ push_type (tp_pointer); yyval.voidval = yyvsp[0].voidval; } -break; -case 82: -#line 749 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ push_type (tp_reference); yyval.voidval = 0; } -break; -case 83: -#line 751 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ push_type (tp_reference); yyval.voidval = yyvsp[0].voidval; } -break; -case 85: -#line 756 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.voidval = yyvsp[-1].voidval; } -break; -case 86: -#line 758 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ - push_type_int (yyvsp[0].lval); - push_type (tp_array); - } -break; -case 87: -#line 763 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ - push_type_int (yyvsp[0].lval); - push_type (tp_array); - yyval.voidval = 0; - } -break; -case 88: -#line 773 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ push_type (tp_function); } -break; -case 89: -#line 775 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ push_type (tp_function); } -break; -case 90: -#line 779 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.lval = -1; } -break; -case 91: -#line 781 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.lval = yyvsp[-1].typed_val.val; } -break; -case 92: -#line 785 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.voidval = 0; } -break; -case 93: -#line 787 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ free ((PTR)yyvsp[-1].tvec); yyval.voidval = 0; } -break; -case 95: -#line 794 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_member_type (builtin_type_int, yyvsp[-2].tval); } -break; -case 96: -#line 796 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_member_type (yyvsp[-5].tval, yyvsp[-3].tval); } -break; -case 97: -#line 798 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_member_type - (lookup_function_type (yyvsp[-7].tval), yyvsp[-5].tval); } -break; -case 98: -#line 801 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_member_type - (lookup_function_type (yyvsp[-8].tval), yyvsp[-6].tval); - free ((PTR)yyvsp[-1].tvec); } -break; -case 99: -#line 808 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = yyvsp[0].tsym.type; } -break; -case 100: -#line 810 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_int; } -break; -case 101: -#line 812 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_long; } -break; -case 102: -#line 814 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_short; } -break; -case 103: -#line 816 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_long; } -break; -case 104: -#line 818 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_unsigned_long; } -break; -case 105: -#line 820 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_long_long; } -break; -case 106: -#line 822 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_long_long; } -break; -case 107: -#line 824 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_unsigned_long_long; } -break; -case 108: -#line 826 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_unsigned_long_long; } -break; -case 109: -#line 828 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_short; } -break; -case 110: -#line 830 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_unsigned_short; } -break; -case 111: -#line 832 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_struct (copy_name (yyvsp[0].sval), - expression_context_block); } -break; -case 112: -#line 835 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_struct (copy_name (yyvsp[0].sval), - expression_context_block); } -break; -case 113: -#line 838 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_union (copy_name (yyvsp[0].sval), - expression_context_block); } -break; -case 114: -#line 841 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_enum (copy_name (yyvsp[0].sval), - expression_context_block); } -break; -case 115: -#line 844 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_unsigned_typename (TYPE_NAME(yyvsp[0].tsym.type)); } -break; -case 116: -#line 846 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_unsigned_int; } -break; -case 117: -#line 848 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_signed_typename (TYPE_NAME(yyvsp[0].tsym.type)); } -break; -case 118: -#line 850 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = builtin_type_int; } -break; -case 119: -#line 852 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = lookup_template_type(copy_name(yyvsp[-3].sval), yyvsp[-1].tval, - expression_context_block); - } -break; -case 120: -#line 858 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = yyvsp[0].tval; } -break; -case 121: -#line 859 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tval = yyvsp[0].tval; } -break; -case 123: -#line 864 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ - yyval.tsym.stoken.ptr = "int"; - yyval.tsym.stoken.length = 3; - yyval.tsym.type = builtin_type_int; - } -break; -case 124: -#line 870 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ - yyval.tsym.stoken.ptr = "long"; - yyval.tsym.stoken.length = 4; - yyval.tsym.type = builtin_type_long; - } -break; -case 125: -#line 876 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ - yyval.tsym.stoken.ptr = "short"; - yyval.tsym.stoken.length = 5; - yyval.tsym.type = builtin_type_short; - } -break; -case 126: -#line 885 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.tvec = (struct type **) xmalloc (sizeof (struct type *) * 2); - yyval.ivec[0] = 1; /* Number of types in vector */ - yyval.tvec[1] = yyvsp[0].tval; - } -break; -case 127: -#line 890 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ int len = sizeof (struct type *) * (++(yyvsp[-2].ivec[0]) + 1); - yyval.tvec = (struct type **) xrealloc ((char *) yyvsp[-2].tvec, len); - yyval.tvec[yyval.ivec[0]] = yyvsp[0].tval; - } -break; -case 128: -#line 896 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.sval = yyvsp[0].ssym.stoken; } -break; -case 129: -#line 897 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.sval = yyvsp[0].ssym.stoken; } -break; -case 130: -#line 898 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.sval = yyvsp[0].tsym.stoken; } -break; -case 131: -#line 899 "/usr/src/gnu/usr.bin/gdb/gdb/c-exp.y" -{ yyval.sval = yyvsp[0].ssym.stoken; } -break; -#line 2593 "y.tab.c" - } - yyssp -= yym; - yystate = *yyssp; - yyvsp -= yym; - yym = yylhs[yyn]; - if (yystate == 0 && yym == 0) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: after reduction, shifting from state 0 to\ - state %d\n", YYPREFIX, YYFINAL); -#endif - yystate = YYFINAL; - *++yyssp = YYFINAL; - *++yyvsp = yyval; - if (yychar < 0) - { - if ((yychar = yylex()) < 0) yychar = 0; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, reading %d (%s)\n", - YYPREFIX, YYFINAL, yychar, yys); - } -#endif - } - if (yychar == 0) goto yyaccept; - goto yyloop; - } - if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yystate) - yystate = yytable[yyn]; - else - yystate = yydgoto[yym]; -#if YYDEBUG - if (yydebug) - printf("%sdebug: after reduction, shifting from state %d \ -to state %d\n", YYPREFIX, *yyssp, yystate); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate; - *++yyvsp = yyval; - goto yyloop; -yyoverflow: - yyerror("yacc stack overflow"); -yyabort: - return (1); -yyaccept: - return (0); -} diff --git a/gnu/usr.bin/gdb/gdb/ch-exp.tab.c b/gnu/usr.bin/gdb/gdb/ch-exp.tab.c deleted file mode 100644 index 7adab65..0000000 --- a/gnu/usr.bin/gdb/gdb/ch-exp.tab.c +++ /dev/null @@ -1,2854 +0,0 @@ -#ifndef lint -static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; -#endif -#define YYBYACC 1 -#define YYMAJOR 1 -#define YYMINOR 9 -#define yyclearin (yychar=(-1)) -#define yyerrok (yyerrflag=0) -#define YYRECOVERING (yyerrflag!=0) -#define yyparse ch_parse -#define yylex ch_lex -#define yyerror ch_error -#define yychar ch_char -#define yyval ch_val -#define yylval ch_lval -#define yydebug ch_debug -#define yynerrs ch_nerrs -#define yyerrflag ch_errflag -#define yyss ch_ss -#define yyssp ch_ssp -#define yyvs ch_vs -#define yyvsp ch_vsp -#define yylhs ch_lhs -#define yylen ch_len -#define yydefred ch_defred -#define yydgoto ch_dgoto -#define yysindex ch_sindex -#define yyrindex ch_rindex -#define yygindex ch_gindex -#define yytable ch_table -#define yycheck ch_check -#define yyname ch_name -#define yyrule ch_rule -#define YYPREFIX "ch_" -#line 55 "./ch-exp.y" - -#include "defs.h" -#include -#include "expression.h" -#include "language.h" -#include "value.h" -#include "parser-defs.h" -#include "ch-lang.h" - -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), - as well as gratuitiously global symbol names, so we can have multiple - yacc generated parsers in gdb. Note that these are only the variables - produced by yacc. If other parser generators (bison, byacc, etc) produce - additional global names that conflict at link time, then those parser - generators need to be fixed instead of adding those names to this list. */ - -#define yymaxdepth chill_maxdepth -#define yyparse chill_parse -#define yylex chill_lex -#define yyerror chill_error -#define yylval chill_lval -#define yychar chill_char -#define yydebug chill_debug -#define yypact chill_pact -#define yyr1 chill_r1 -#define yyr2 chill_r2 -#define yydef chill_def -#define yychk chill_chk -#define yypgo chill_pgo -#define yyact chill_act -#define yyexca chill_exca -#define yyerrflag chill_errflag -#define yynerrs chill_nerrs -#define yyps chill_ps -#define yypv chill_pv -#define yys chill_s -#define yy_yys chill_yys -#define yystate chill_state -#define yytmp chill_tmp -#define yyv chill_v -#define yy_yyv chill_yyv -#define yyval chill_val -#define yylloc chill_lloc -#define yyreds chill_reds /* With YYDEBUG defined */ -#define yytoks chill_toks /* With YYDEBUG defined */ - -#ifndef YYDEBUG -#define YYDEBUG 0 /* Default to no yydebug support */ -#endif - -int -yyparse PARAMS ((void)); - -static int -yylex PARAMS ((void)); - -void -yyerror PARAMS ((char *)); - -#line 120 "./ch-exp.y" -typedef union - { - LONGEST lval; - unsigned LONGEST ulval; - struct { - LONGEST val; - struct type *type; - } typed_val; - double dval; - struct symbol *sym; - struct type *tval; - struct stoken sval; - struct ttype tsym; - struct symtoken ssym; - int voidval; - struct block *bval; - enum exp_opcode opcode; - struct internalvar *ivar; - - struct type **tvec; - int *ivec; - } YYSTYPE; -#line 119 "y.tab.c" -#define FIXME_01 257 -#define FIXME_02 258 -#define FIXME_03 259 -#define FIXME_04 260 -#define FIXME_05 261 -#define FIXME_06 262 -#define FIXME_07 263 -#define FIXME_08 264 -#define FIXME_09 265 -#define FIXME_10 266 -#define FIXME_11 267 -#define FIXME_12 268 -#define FIXME_13 269 -#define FIXME_14 270 -#define FIXME_15 271 -#define FIXME_16 272 -#define FIXME_17 273 -#define FIXME_18 274 -#define FIXME_19 275 -#define FIXME_20 276 -#define FIXME_21 277 -#define FIXME_22 278 -#define FIXME_24 279 -#define FIXME_25 280 -#define FIXME_26 281 -#define FIXME_27 282 -#define FIXME_28 283 -#define FIXME_29 284 -#define FIXME_30 285 -#define INTEGER_LITERAL 286 -#define BOOLEAN_LITERAL 287 -#define CHARACTER_LITERAL 288 -#define FLOAT_LITERAL 289 -#define GENERAL_PROCEDURE_NAME 290 -#define LOCATION_NAME 291 -#define SET_LITERAL 292 -#define EMPTINESS_LITERAL 293 -#define CHARACTER_STRING_LITERAL 294 -#define BIT_STRING_LITERAL 295 -#define TYPENAME 296 -#define FIELD_NAME 297 -#define CASE 298 -#define OF 299 -#define ESAC 300 -#define LOGIOR 301 -#define ORIF 302 -#define LOGXOR 303 -#define LOGAND 304 -#define ANDIF 305 -#define NOTEQUAL 306 -#define GTR 307 -#define LEQ 308 -#define IN 309 -#define SLASH_SLASH 310 -#define MOD 311 -#define REM 312 -#define NOT 313 -#define POINTER 314 -#define RECEIVE 315 -#define UP 316 -#define IF 317 -#define THEN 318 -#define ELSE 319 -#define FI 320 -#define ELSIF 321 -#define ILLEGAL_TOKEN 322 -#define NUM 323 -#define PRED 324 -#define SUCC 325 -#define ABS 326 -#define CARD 327 -#define MAX_TOKEN 328 -#define MIN_TOKEN 329 -#define SIZE 330 -#define UPPER 331 -#define LOWER 332 -#define LENGTH 333 -#define GDB_REGNAME 334 -#define GDB_LAST 335 -#define GDB_VARIABLE 336 -#define GDB_ASSIGNMENT 337 -#define YYERRCODE 256 -short ch_lhs[] = { -1, - 0, 0, 20, 20, 21, 1, 1, 2, 2, 2, - 2, 2, 45, 45, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, - 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, - 6, 6, 6, 7, 8, 9, 9, 62, 10, 11, - 11, 12, 13, 14, 15, 17, 18, 19, 22, 22, - 22, 23, 23, 24, 25, 25, 26, 27, 28, 28, - 28, 28, 29, 29, 29, 30, 30, 30, 30, 30, - 30, 30, 30, 31, 31, 31, 31, 32, 32, 32, - 32, 32, 33, 33, 33, 33, 34, 34, 34, 60, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 49, 49, 49, 49, 61, 50, 50, 51, - 44, 52, 53, 54, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 46, 47, 48, 55, 56, 57, 58, - 59, -}; -short ch_len[] = { 2, - 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, - 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 4, 6, 6, 0, 5, 6, - 6, 2, 2, 1, 1, 1, 1, 3, 1, 1, - 1, 5, 9, 2, 2, 4, 1, 4, 1, 3, - 3, 3, 1, 3, 3, 1, 3, 3, 3, 3, - 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, - 3, 3, 1, 2, 2, 2, 2, 2, 1, 3, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 1, 4, 4, 4, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, -}; -short ch_defred[] = { 0, - 5, 12, 44, 54, 56, 57, 125, 126, 127, 128, - 129, 36, 37, 38, 39, 35, 8, 40, 41, 42, - 43, 117, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 10, 9, 11, 0, 0, 6, 0, 15, 16, 17, - 18, 19, 20, 21, 22, 23, 24, 25, 26, 55, - 27, 28, 0, 1, 4, 3, 61, 0, 0, 0, - 0, 0, 88, 93, 31, 32, 33, 34, 0, 0, - 60, 0, 138, 0, 30, 29, 94, 0, 95, 0, - 0, 141, 98, 0, 137, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 52, 7, - 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 53, 0, 58, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 122, 123, 124, 0, 0, 0, - 0, 0, 0, 118, 0, 0, 0, 120, 0, 100, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 89, 90, 91, 92, 130, - 131, 0, 0, 134, 136, 0, 0, 0, 140, 0, - 0, 139, 64, 0, 0, 0, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 0, 0, 0, 110, 111, - 112, 45, 0, 0, 0, 0, 13, 0, 0, 0, - 65, 0, 62, 0, 0, 0, 133, 0, 132, 0, - 135, 0, 0, 49, 0, 0, 67, 0, 0, 114, - 115, 116, 47, 46, 50, 51, 14, 0, 68, 66, - 0, 63, -}; -short ch_dgoto[] = { 44, - 85, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 137, 196, 238, 190, 68, 69, 70, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 182, - 183, 230, 228, 80, 218, 186, 232, 187, 149, 155, - 159, 150, 151, 152, 96, 84, 193, 191, 93, 81, - 88, 188, -}; -short ch_sindex[] = { 457, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -262, 879, 879, 893, -215, 622, -258, 50, - 51, 52, 53, 56, 57, 58, 67, 72, 73, 75, - 0, 0, 0, 0, -221, 0, -293, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -261, 0, 0, 0, 0, -248, -275, -44, - -30, -33, 0, 0, 0, 0, 0, 0, 88, 91, - 0, 92, 0, -165, 0, 0, 0, 92, 0, 0, - -293, 0, 0, 94, 0, -181, 622, 622, 622, 622, - 622, 622, 622, 636, 622, 622, 622, 457, 0, 0, - 0, 797, 797, 797, 797, 797, 797, 797, 797, 797, - 797, 797, 797, 797, 797, 797, 797, 797, 797, 797, - -233, -270, 0, -137, 0, -132, -272, 112, 118, 119, - 120, 121, 122, 128, 0, 0, 0, 129, 130, 132, - 141, 143, 92, 0, 144, 92, 146, 0, 149, 0, - -275, -275, -275, -44, -44, -30, -30, -30, -30, -30, - -30, -30, -33, -33, -33, 0, 0, 0, 0, 0, - 0, -39, 115, 0, 0, 126, -120, 622, 0, 106, - 142, 0, 0, -132, -258, -110, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 622, 622, 622, 0, 0, - 0, 0, -64, -61, -63, -64, 0, -34, -103, 622, - 0, -181, 0, 174, 181, -22, 0, 182, 0, 184, - 0, 192, 193, 0, 622, 622, 0, 177, -272, 0, - 0, 0, 0, 0, 0, 0, 0, 150, 0, 0, - -55, 0, -}; -short ch_rindex[] = { 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 82, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 24, 0, 0, 0, 0, 506, 255, 191, - 145, 95, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 237, 0, 0, 0, 0, 0, 0, 0, 59, - 204, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 714, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, -40, 0, 0, - 0, 0, 205, 0, 0, 206, 0, 0, 0, 0, - 567, 573, 577, 531, 554, 168, 180, 208, 231, 500, - 522, 545, 105, 133, 158, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -}; -short ch_gindex[] = { 0, - 1230, 0, -23, 0, 0, 185, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 26, 148, - 0, 1162, 0, 31, 15, 22, 0, 0, -56, -104, - -45, -37, -92, 55, 0, 0, 0, 0, 0, 0, - 0, 0, 43, 0, 63, 0, 0, 0, 0, 154, - 0, 0, 0, 0, 71, 0, 87, 0, 0, 0, - 5, 0, -}; -#define YYTABLESIZE 1466 -short ch_table[] = { 30, - 30, 212, 91, 109, 82, 184, 234, 185, 127, 235, - 164, 165, 124, 128, 125, 121, 117, 119, 242, 83, - 110, 235, 95, 29, 12, 13, 14, 15, 115, 116, - 18, 19, 20, 21, 176, 177, 178, 179, 180, 181, - 30, 30, 30, 30, 30, 30, 194, 30, 195, 86, - 86, 86, 112, 113, 114, 161, 162, 163, 97, 30, - 30, 30, 30, 29, 29, 29, 29, 29, 29, 92, - 29, 166, 167, 168, 169, 170, 171, 172, 87, 89, - 91, 99, 29, 29, 29, 29, 173, 174, 175, 97, - 98, 99, 100, 30, 84, 101, 102, 103, 30, 97, - 97, 97, 97, 97, 85, 97, 104, 133, 153, 156, - 156, 105, 106, 133, 107, 108, 29, 97, 97, 97, - 97, 121, 99, 99, 99, 99, 99, 131, 99, 86, - 132, 28, 86, 134, 135, 84, 136, 84, 84, 84, - 99, 99, 99, 99, 76, 85, 189, 85, 85, 85, - 192, 97, 197, 84, 84, 84, 84, 87, 198, 199, - 200, 201, 202, 85, 85, 85, 85, 77, 203, 204, - 205, 206, 214, 86, 99, 86, 86, 86, 133, 78, - 207, 133, 208, 215, 209, 76, 210, 84, 76, 211, - 73, 86, 86, 86, 86, 216, 219, 85, 87, 220, - 87, 87, 87, 76, 76, 76, 76, 79, 77, 223, - 227, 77, 229, 231, 240, 236, 87, 87, 87, 87, - 78, 241, 243, 78, 244, 86, 77, 77, 77, 77, - 80, 73, 245, 246, 73, 249, 2, 76, 78, 78, - 78, 78, 251, 121, 252, 113, 119, 111, 79, 73, - 87, 79, 239, 250, 69, 160, 30, 248, 233, 157, - 77, 118, 120, 122, 123, 222, 79, 79, 79, 79, - 226, 80, 78, 30, 80, 0, 213, 129, 130, 126, - 221, 0, 0, 73, 0, 0, 0, 0, 0, 80, - 80, 80, 80, 0, 0, 69, 0, 30, 69, 0, - 79, 30, 30, 30, 30, 30, 30, 30, 30, 30, - 30, 30, 30, 69, 30, 0, 0, 0, 0, 0, - 29, 0, 0, 80, 29, 29, 29, 29, 29, 29, - 29, 29, 29, 29, 29, 29, 0, 29, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 69, 0, 0, - 0, 0, 0, 0, 0, 30, 0, 0, 0, 97, - 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, - 97, 0, 30, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 0, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, - 85, 85, 85, 85, 85, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 86, 86, 86, 86, 86, 86, 86, - 86, 86, 86, 0, 0, 76, 76, 76, 76, 76, - 76, 76, 76, 76, 0, 0, 0, 0, 87, 87, - 87, 87, 87, 87, 87, 87, 87, 87, 77, 77, - 77, 77, 77, 77, 77, 77, 77, 0, 0, 0, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 0, - 0, 73, 73, 73, 73, 73, 28, 0, 0, 81, - 0, 24, 0, 0, 0, 59, 0, 0, 79, 79, - 79, 79, 79, 79, 79, 79, 79, 0, 0, 0, - 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, - 74, 80, 80, 80, 80, 80, 80, 80, 80, 80, - 81, 0, 0, 81, 83, 0, 59, 0, 0, 59, - 0, 0, 0, 75, 0, 69, 69, 69, 81, 81, - 81, 81, 82, 0, 59, 82, 70, 0, 0, 0, - 0, 74, 71, 0, 74, 0, 72, 0, 0, 0, - 82, 82, 82, 82, 0, 83, 0, 0, 83, 74, - 0, 0, 81, 0, 75, 0, 0, 75, 59, 0, - 0, 0, 0, 83, 83, 83, 83, 70, 0, 0, - 70, 0, 75, 71, 82, 0, 71, 72, 0, 0, - 72, 0, 0, 74, 0, 70, 0, 0, 0, 0, - 0, 71, 0, 0, 0, 72, 0, 83, 0, 0, - 0, 0, 0, 0, 0, 0, 75, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 70, - 0, 28, 0, 0, 0, 71, 24, 0, 0, 72, - 0, 0, 0, 0, 0, 28, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 2, 3, 4, 5, 6, - 0, 0, 0, 7, 8, 9, 10, 11, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 48, 23, 0, 0, 0, 48, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, - 26, 27, 0, 29, 0, 0, 0, 0, 0, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 0, 0, 0, 0, 0, 0, 0, - 81, 81, 81, 81, 81, 81, 81, 81, 81, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 82, 82, 82, 82, 82, 82, 82, 82, - 82, 74, 74, 74, 74, 74, 28, 0, 0, 0, - 0, 24, 0, 0, 0, 83, 83, 83, 83, 83, - 83, 83, 83, 83, 75, 75, 75, 75, 75, 0, - 0, 0, 0, 0, 0, 0, 0, 70, 70, 70, - 0, 0, 0, 71, 71, 71, 0, 72, 72, 72, - 2, 3, 4, 5, 6, 0, 0, 0, 7, 8, - 9, 10, 11, 0, 2, 3, 4, 5, 6, 145, - 146, 147, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 28, 23, - 0, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 28, 0, 25, 26, 27, 0, 29, 0, - 0, 0, 0, 0, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, - 42, 43, 48, 48, 48, 48, 48, 0, 0, 0, - 48, 48, 48, 48, 48, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, - 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, - 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 48, 48, 48, 0, - 48, 0, 0, 0, 0, 0, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, - 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, - 0, 0, 0, 7, 8, 9, 10, 11, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, - 26, 27, 0, 0, 0, 0, 0, 0, 0, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 0, 0, 0, 0, 2, 3, 4, - 5, 6, 0, 0, 0, 7, 8, 9, 10, 11, - 0, 2, 3, 4, 5, 6, 0, 0, 0, 7, - 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 20, 21, 22, 0, 0, 0, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 94, - 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, - 0, 30, 31, 32, 33, 34, 35, 36, 37, 38, - 39, 40, 41, 42, 43, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 45, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 90, 0, 45, 138, 139, - 140, 141, 142, 143, 144, 0, 154, 154, 158, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 45, 45, 45, 45, - 45, 45, 45, 148, 45, 45, 45, 45, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 217, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 224, 225, 217, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 237, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 247, 237, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 45, 45, 45, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 45, 45, -}; -short ch_check[] = { 40, - 0, 41, 26, 297, 0, 276, 41, 278, 42, 44, - 115, 116, 43, 47, 45, 60, 61, 62, 41, 282, - 314, 44, 281, 0, 286, 287, 288, 289, 304, 305, - 292, 293, 294, 295, 127, 128, 129, 130, 272, 273, - 40, 41, 42, 43, 44, 45, 319, 47, 321, 24, - 25, 26, 301, 302, 303, 112, 113, 114, 0, 59, - 60, 61, 62, 40, 41, 42, 43, 44, 45, 285, - 47, 117, 118, 119, 120, 121, 122, 123, 24, 25, - 104, 0, 59, 60, 61, 62, 124, 125, 126, 40, - 40, 40, 40, 93, 0, 40, 40, 40, 40, 41, - 42, 43, 44, 45, 0, 47, 40, 82, 104, 105, - 106, 40, 40, 88, 40, 337, 93, 59, 60, 61, - 62, 40, 41, 42, 43, 44, 45, 40, 47, 104, - 40, 40, 0, 299, 41, 41, 318, 43, 44, 45, - 59, 60, 61, 62, 0, 41, 284, 43, 44, 45, - 283, 93, 41, 59, 60, 61, 62, 0, 41, 41, - 41, 41, 41, 59, 60, 61, 62, 0, 41, 41, - 41, 40, 58, 41, 93, 43, 44, 45, 153, 0, - 40, 156, 40, 58, 41, 41, 41, 93, 44, 41, - 0, 59, 60, 61, 62, 316, 91, 93, 41, 58, - 43, 44, 45, 59, 60, 61, 62, 0, 41, 320, - 275, 44, 274, 277, 41, 319, 59, 60, 61, 62, - 41, 41, 41, 44, 41, 93, 59, 60, 61, 62, - 0, 41, 41, 41, 44, 59, 0, 93, 59, 60, - 61, 62, 93, 40, 300, 41, 41, 63, 41, 59, - 93, 44, 222, 239, 0, 108, 297, 236, 216, 106, - 93, 306, 307, 308, 309, 195, 59, 60, 61, 62, - 208, 41, 93, 314, 44, -1, 316, 311, 312, 310, - 194, -1, -1, 93, -1, -1, -1, -1, -1, 59, - 60, 61, 62, -1, -1, 41, -1, 297, 44, -1, - 93, 301, 302, 303, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 59, 314, -1, -1, -1, -1, -1, - 297, -1, -1, 93, 301, 302, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, -1, 314, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 93, -1, -1, - -1, -1, -1, -1, -1, 297, -1, -1, -1, 301, - 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, - 312, -1, 314, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 301, 302, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, -1, 301, 302, 303, 304, 305, - 306, 307, 308, 309, 310, 301, 302, 303, 304, 305, - 306, 307, 308, 309, 310, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 301, 302, 303, 304, 305, 306, 307, - 308, 309, 310, -1, -1, 301, 302, 303, 304, 305, - 306, 307, 308, 309, -1, -1, -1, -1, 301, 302, - 303, 304, 305, 306, 307, 308, 309, 310, 301, 302, - 303, 304, 305, 306, 307, 308, 309, -1, -1, -1, - 301, 302, 303, 304, 305, 306, 307, 308, 309, -1, - -1, 301, 302, 303, 304, 305, 40, -1, -1, 0, - -1, 45, -1, -1, -1, 0, -1, -1, 301, 302, - 303, 304, 305, 306, 307, 308, 309, -1, -1, -1, - -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, - 0, 301, 302, 303, 304, 305, 306, 307, 308, 309, - 41, -1, -1, 44, 0, -1, 41, -1, -1, 44, - -1, -1, -1, 0, -1, 301, 302, 303, 59, 60, - 61, 62, 41, -1, 59, 44, 0, -1, -1, -1, - -1, 41, 0, -1, 44, -1, 0, -1, -1, -1, - 59, 60, 61, 62, -1, 41, -1, -1, 44, 59, - -1, -1, 93, -1, 41, -1, -1, 44, 93, -1, - -1, -1, -1, 59, 60, 61, 62, 41, -1, -1, - 44, -1, 59, 41, 93, -1, 44, 41, -1, -1, - 44, -1, -1, 93, -1, 59, -1, -1, -1, -1, - -1, 59, -1, -1, -1, 59, -1, 93, -1, -1, - -1, -1, -1, -1, -1, -1, 93, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 93, - -1, 40, -1, -1, -1, 93, 45, -1, -1, 93, - -1, -1, -1, -1, -1, 40, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 257, -1, 259, 260, 261, 262, 263, - -1, -1, -1, 267, 268, 269, 270, 271, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 286, 287, 288, 289, 290, 291, 292, 293, - 294, 295, 296, 40, 298, -1, -1, -1, 45, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 313, - 314, 315, -1, 317, -1, -1, -1, -1, -1, 323, - 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, - 334, 335, 336, -1, -1, -1, -1, -1, -1, -1, - 301, 302, 303, 304, 305, 306, 307, 308, 309, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 301, 302, 303, 304, 305, 306, 307, 308, - 309, 301, 302, 303, 304, 305, 40, -1, -1, -1, - -1, 45, -1, -1, -1, 301, 302, 303, 304, 305, - 306, 307, 308, 309, 301, 302, 303, 304, 305, -1, - -1, -1, -1, -1, -1, -1, -1, 301, 302, 303, - -1, -1, -1, 301, 302, 303, -1, 301, 302, 303, - 259, 260, 261, 262, 263, -1, -1, -1, 267, 268, - 269, 270, 271, -1, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 286, 287, 288, - 289, 290, 291, 292, 293, 294, 295, 296, 40, 298, - -1, 286, 287, 288, 289, 290, 291, 292, 293, 294, - 295, 296, 40, -1, 313, 314, 315, -1, 317, -1, - -1, -1, -1, -1, 323, 324, 325, 326, 327, 328, - 329, 330, 331, 332, 333, 334, 335, 336, 323, 324, - 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, - 335, 336, 259, 260, 261, 262, 263, -1, -1, -1, - 267, 268, 269, 270, 271, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 286, - 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, - -1, 298, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 313, 314, 315, -1, - 317, -1, -1, -1, -1, -1, 323, 324, 325, 326, - 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, - -1, -1, -1, -1, -1, 259, 260, 261, 262, 263, - -1, -1, -1, 267, 268, 269, 270, 271, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 286, 287, 288, 289, 290, 291, 292, 293, - 294, 295, 296, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 313, - 314, 315, -1, -1, -1, -1, -1, -1, -1, 323, - 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, - 334, 335, 336, -1, -1, -1, -1, 259, 260, 261, - 262, 263, -1, -1, -1, 267, 268, 269, 270, 271, - -1, 259, 260, 261, 262, 263, -1, -1, -1, 267, - 268, 269, 270, 271, 286, 287, 288, 289, 290, 291, - 292, 293, 294, 295, 296, -1, -1, -1, 286, 287, - 288, 289, 290, 291, 292, 293, 294, 295, 296, 28, - -1, -1, 314, 315, -1, -1, -1, -1, -1, -1, - -1, 323, 324, 325, 326, 327, 328, 329, 330, 331, - 332, 333, 334, 335, 336, 323, 324, 325, 326, 327, - 328, 329, 330, 331, 332, 333, 334, 335, 336, 0, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 26, -1, 28, 97, 98, - 99, 100, 101, 102, 103, -1, 105, 106, 107, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 97, 98, 99, 100, - 101, 102, 103, 104, 105, 106, 107, 108, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 188, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 206, 207, 208, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 220, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 235, 236, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 188, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 206, 207, 208, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 220, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 235, 236, -}; -#define YYFINAL 44 -#ifndef YYDEBUG -#define YYDEBUG 0 -#endif -#define YYMAXTOKEN 337 -#if YYDEBUG -char *ch_name[] = { -"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'","'.'","'/'",0,0,0,0,0,0,0,0,0,0, -"':'","';'","'<'","'='","'>'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,"'['",0,"']'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,"FIXME_01","FIXME_02","FIXME_03","FIXME_04", -"FIXME_05","FIXME_06","FIXME_07","FIXME_08","FIXME_09","FIXME_10","FIXME_11", -"FIXME_12","FIXME_13","FIXME_14","FIXME_15","FIXME_16","FIXME_17","FIXME_18", -"FIXME_19","FIXME_20","FIXME_21","FIXME_22","FIXME_24","FIXME_25","FIXME_26", -"FIXME_27","FIXME_28","FIXME_29","FIXME_30","INTEGER_LITERAL","BOOLEAN_LITERAL", -"CHARACTER_LITERAL","FLOAT_LITERAL","GENERAL_PROCEDURE_NAME","LOCATION_NAME", -"SET_LITERAL","EMPTINESS_LITERAL","CHARACTER_STRING_LITERAL", -"BIT_STRING_LITERAL","TYPENAME","FIELD_NAME","CASE","OF","ESAC","LOGIOR","ORIF", -"LOGXOR","LOGAND","ANDIF","NOTEQUAL","GTR","LEQ","IN","SLASH_SLASH","MOD","REM", -"NOT","POINTER","RECEIVE","UP","IF","THEN","ELSE","FI","ELSIF","ILLEGAL_TOKEN", -"NUM","PRED","SUCC","ABS","CARD","MAX_TOKEN","MIN_TOKEN","SIZE","UPPER","LOWER", -"LENGTH","GDB_REGNAME","GDB_LAST","GDB_VARIABLE","GDB_ASSIGNMENT", -}; -char *ch_rule[] = { -"$accept : start", -"start : value", -"start : mode_name", -"value : expression", -"value : undefined_value", -"undefined_value : FIXME_01", -"location : access_name", -"location : primitive_value POINTER", -"access_name : LOCATION_NAME", -"access_name : GDB_LAST", -"access_name : GDB_REGNAME", -"access_name : GDB_VARIABLE", -"access_name : FIXME_03", -"expression_list : expression", -"expression_list : expression_list ',' expression", -"primitive_value : location_contents", -"primitive_value : value_name", -"primitive_value : literal", -"primitive_value : tuple", -"primitive_value : value_string_element", -"primitive_value : value_string_slice", -"primitive_value : value_array_element", -"primitive_value : value_array_slice", -"primitive_value : value_structure_field", -"primitive_value : expression_conversion", -"primitive_value : value_procedure_call", -"primitive_value : value_built_in_routine_call", -"primitive_value : start_expression", -"primitive_value : zero_adic_operator", -"primitive_value : parenthesised_expression", -"location_contents : location", -"value_name : synonym_name", -"value_name : value_enumeration_name", -"value_name : value_do_with_name", -"value_name : value_receive_name", -"value_name : GENERAL_PROCEDURE_NAME", -"literal : INTEGER_LITERAL", -"literal : BOOLEAN_LITERAL", -"literal : CHARACTER_LITERAL", -"literal : FLOAT_LITERAL", -"literal : SET_LITERAL", -"literal : EMPTINESS_LITERAL", -"literal : CHARACTER_STRING_LITERAL", -"literal : BIT_STRING_LITERAL", -"tuple : FIXME_04", -"value_string_element : string_primitive_value '(' start_element ')'", -"value_string_slice : string_primitive_value '(' left_element ':' right_element ')'", -"value_string_slice : string_primitive_value '(' start_element UP slice_size ')'", -"$$1 :", -"value_array_element : array_primitive_value '(' $$1 expression_list ')'", -"value_array_slice : array_primitive_value '(' lower_element ':' upper_element ')'", -"value_array_slice : array_primitive_value '(' first_element UP slice_size ')'", -"value_structure_field : primitive_value FIELD_NAME", -"expression_conversion : mode_name parenthesised_expression", -"value_procedure_call : FIXME_05", -"value_built_in_routine_call : chill_value_built_in_routine_call", -"start_expression : FIXME_06", -"zero_adic_operator : FIXME_07", -"parenthesised_expression : '(' expression ')'", -"expression : operand_0", -"expression : single_assignment_action", -"expression : conditional_expression", -"conditional_expression : IF boolean_expression then_alternative else_alternative FI", -"conditional_expression : CASE case_selector_list OF value_case_alternative '[' ELSE sub_expression ']' ESAC", -"then_alternative : THEN subexpression", -"else_alternative : ELSE subexpression", -"else_alternative : ELSIF boolean_expression then_alternative else_alternative", -"sub_expression : expression", -"value_case_alternative : case_label_specification ':' sub_expression ';'", -"operand_0 : operand_1", -"operand_0 : operand_0 LOGIOR operand_1", -"operand_0 : operand_0 ORIF operand_1", -"operand_0 : operand_0 LOGXOR operand_1", -"operand_1 : operand_2", -"operand_1 : operand_1 LOGAND operand_2", -"operand_1 : operand_1 ANDIF operand_2", -"operand_2 : operand_3", -"operand_2 : operand_2 '=' operand_3", -"operand_2 : operand_2 NOTEQUAL operand_3", -"operand_2 : operand_2 '>' operand_3", -"operand_2 : operand_2 GTR operand_3", -"operand_2 : operand_2 '<' operand_3", -"operand_2 : operand_2 LEQ operand_3", -"operand_2 : operand_2 IN operand_3", -"operand_3 : operand_4", -"operand_3 : operand_3 '+' operand_4", -"operand_3 : operand_3 '-' operand_4", -"operand_3 : operand_3 SLASH_SLASH operand_4", -"operand_4 : operand_5", -"operand_4 : operand_4 '*' operand_5", -"operand_4 : operand_4 '/' operand_5", -"operand_4 : operand_4 MOD operand_5", -"operand_4 : operand_4 REM operand_5", -"operand_5 : operand_6", -"operand_5 : '-' operand_6", -"operand_5 : NOT operand_6", -"operand_5 : parenthesised_expression literal", -"operand_6 : POINTER location", -"operand_6 : RECEIVE buffer_location", -"operand_6 : primitive_value", -"single_assignment_action : location GDB_ASSIGNMENT value", -"chill_value_built_in_routine_call : NUM '(' expression ')'", -"chill_value_built_in_routine_call : PRED '(' expression ')'", -"chill_value_built_in_routine_call : SUCC '(' expression ')'", -"chill_value_built_in_routine_call : ABS '(' expression ')'", -"chill_value_built_in_routine_call : CARD '(' expression ')'", -"chill_value_built_in_routine_call : MAX_TOKEN '(' expression ')'", -"chill_value_built_in_routine_call : MIN_TOKEN '(' expression ')'", -"chill_value_built_in_routine_call : SIZE '(' location ')'", -"chill_value_built_in_routine_call : SIZE '(' mode_argument ')'", -"chill_value_built_in_routine_call : UPPER '(' upper_lower_argument ')'", -"chill_value_built_in_routine_call : LOWER '(' upper_lower_argument ')'", -"chill_value_built_in_routine_call : LENGTH '(' length_argument ')'", -"mode_argument : mode_name", -"mode_argument : array_mode_name '(' expression ')'", -"mode_argument : string_mode_name '(' expression ')'", -"mode_argument : variant_structure_mode_name '(' expression_list ')'", -"mode_name : TYPENAME", -"upper_lower_argument : expression", -"upper_lower_argument : mode_name", -"length_argument : expression", -"array_primitive_value : primitive_value", -"array_mode_name : FIXME_08", -"string_mode_name : FIXME_09", -"variant_structure_mode_name : FIXME_10", -"synonym_name : FIXME_11", -"value_enumeration_name : FIXME_12", -"value_do_with_name : FIXME_13", -"value_receive_name : FIXME_14", -"string_primitive_value : FIXME_15", -"start_element : FIXME_16", -"left_element : FIXME_17", -"right_element : FIXME_18", -"slice_size : FIXME_19", -"lower_element : FIXME_20", -"upper_element : FIXME_21", -"first_element : FIXME_22", -"boolean_expression : FIXME_26", -"case_selector_list : FIXME_27", -"subexpression : FIXME_28", -"case_label_specification : FIXME_29", -"buffer_location : FIXME_30", -}; -#endif -#ifdef YYSTACKSIZE -#undef YYMAXDEPTH -#define YYMAXDEPTH YYSTACKSIZE -#else -#ifdef YYMAXDEPTH -#define YYSTACKSIZE YYMAXDEPTH -#else -#define YYSTACKSIZE 500 -#define YYMAXDEPTH 500 -#endif -#endif -int yydebug; -int yynerrs; -int yyerrflag; -int yychar; -short *yyssp; -YYSTYPE *yyvsp; -YYSTYPE yyval; -YYSTYPE yylval; -short yyss[YYSTACKSIZE]; -YYSTYPE yyvs[YYSTACKSIZE]; -#define yystacksize YYSTACKSIZE -#line 994 "./ch-exp.y" - -/* Implementation of a dynamically expandable buffer for processing input - characters acquired through lexptr and building a value to return in - yylval. */ - -static char *tempbuf; /* Current buffer contents */ -static int tempbufsize; /* Size of allocated buffer */ -static int tempbufindex; /* Current index into buffer */ - -#define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */ - -#define CHECKBUF(size) \ - do { \ - if (tempbufindex + (size) >= tempbufsize) \ - { \ - growbuf_by_size (size); \ - } \ - } while (0); - -/* Grow the static temp buffer if necessary, including allocating the first one - on demand. */ - -static void -growbuf_by_size (count) - int count; -{ - int growby; - - growby = max (count, GROWBY_MIN_SIZE); - tempbufsize += growby; - if (tempbuf == NULL) - { - tempbuf = (char *) xmalloc (tempbufsize); - } - else - { - tempbuf = (char *) xrealloc (tempbuf, tempbufsize); - } -} - -/* Try to consume a simple name string token. If successful, returns - a pointer to a nullbyte terminated copy of the name that can be used - in symbol table lookups. If not successful, returns NULL. */ - -static char * -match_simple_name_string () -{ - char *tokptr = lexptr; - - if (isalpha (*tokptr)) - { - char *result; - do { - tokptr++; - } while (isalnum (*tokptr) || (*tokptr == '_')); - yylval.sval.ptr = lexptr; - yylval.sval.length = tokptr - lexptr; - lexptr = tokptr; - result = copy_name (yylval.sval); - for (tokptr = result; *tokptr; tokptr++) - if (isupper (*tokptr)) - *tokptr = tolower(*tokptr); - return result; - } - return (NULL); -} - -/* Start looking for a value composed of valid digits as set by the base - in use. Note that '_' characters are valid anywhere, in any quantity, - and are simply ignored. Since we must find at least one valid digit, - or reject this token as an integer literal, we keep track of how many - digits we have encountered. */ - -static int -decode_integer_value (base, tokptrptr, ivalptr) - int base; - char **tokptrptr; - int *ivalptr; -{ - char *tokptr = *tokptrptr; - int temp; - int digits = 0; - - while (*tokptr != '\0') - { - temp = tolower (*tokptr); - tokptr++; - switch (temp) - { - case '_': - continue; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - temp -= '0'; - break; - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - temp -= 'a'; - temp += 10; - break; - default: - temp = base; - break; - } - if (temp < base) - { - digits++; - *ivalptr *= base; - *ivalptr += temp; - } - else - { - /* Found something not in domain for current base. */ - tokptr--; /* Unconsume what gave us indigestion. */ - break; - } - } - - /* If we didn't find any digits, then we don't have a valid integer - value, so reject the entire token. Otherwise, update the lexical - scan pointer, and return non-zero for success. */ - - if (digits == 0) - { - return (0); - } - else - { - *tokptrptr = tokptr; - return (1); - } -} - -static int -decode_integer_literal (valptr, tokptrptr) - int *valptr; - char **tokptrptr; -{ - char *tokptr = *tokptrptr; - int base = 0; - int ival = 0; - int explicit_base = 0; - - /* Look for an explicit base specifier, which is optional. */ - - switch (*tokptr) - { - case 'd': - case 'D': - explicit_base++; - base = 10; - tokptr++; - break; - case 'b': - case 'B': - explicit_base++; - base = 2; - tokptr++; - break; - case 'h': - case 'H': - explicit_base++; - base = 16; - tokptr++; - break; - case 'o': - case 'O': - explicit_base++; - base = 8; - tokptr++; - break; - default: - base = 10; - break; - } - - /* If we found an explicit base ensure that the character after the - explicit base is a single quote. */ - - if (explicit_base && (*tokptr++ != '\'')) - { - return (0); - } - - /* Attempt to decode whatever follows as an integer value in the - indicated base, updating the token pointer in the process and - computing the value into ival. Also, if we have an explicit - base, then the next character must not be a single quote, or we - have a bitstring literal, so reject the entire token in this case. - Otherwise, update the lexical scan pointer, and return non-zero - for success. */ - - if (!decode_integer_value (base, &tokptr, &ival)) - { - return (0); - } - else if (explicit_base && (*tokptr == '\'')) - { - return (0); - } - else - { - *valptr = ival; - *tokptrptr = tokptr; - return (1); - } -} - -/* If it wasn't for the fact that floating point values can contain '_' - characters, we could just let strtod do all the hard work by letting it - try to consume as much of the current token buffer as possible and - find a legal conversion. Unfortunately we need to filter out the '_' - characters before calling strtod, which we do by copying the other - legal chars to a local buffer to be converted. However since we also - need to keep track of where the last unconsumed character in the input - buffer is, we have transfer only as many characters as may compose a - legal floating point value. */ - -static int -match_float_literal () -{ - char *tokptr = lexptr; - char *buf; - char *copy; - double dval; - extern double strtod (); - - /* Make local buffer in which to build the string to convert. This is - required because underscores are valid in chill floating point numbers - but not in the string passed to strtod to convert. The string will be - no longer than our input string. */ - - copy = buf = (char *) alloca (strlen (tokptr) + 1); - - /* Transfer all leading digits to the conversion buffer, discarding any - underscores. */ - - while (isdigit (*tokptr) || *tokptr == '_') - { - if (*tokptr != '_') - { - *copy++ = *tokptr; - } - tokptr++; - } - - /* Now accept either a '.', or one of [eEdD]. Dot is legal regardless - of whether we found any leading digits, and we simply accept it and - continue on to look for the fractional part and/or exponent. One of - [eEdD] is legal only if we have seen digits, and means that there - is no fractional part. If we find neither of these, then this is - not a floating point number, so return failure. */ - - switch (*tokptr++) - { - case '.': - /* Accept and then look for fractional part and/or exponent. */ - *copy++ = '.'; - break; - - case 'e': - case 'E': - case 'd': - case 'D': - if (copy == buf) - { - return (0); - } - *copy++ = 'e'; - goto collect_exponent; - break; - - default: - return (0); - break; - } - - /* We found a '.', copy any fractional digits to the conversion buffer, up - to the first nondigit, non-underscore character. */ - - while (isdigit (*tokptr) || *tokptr == '_') - { - if (*tokptr != '_') - { - *copy++ = *tokptr; - } - tokptr++; - } - - /* Look for an exponent, which must start with one of [eEdD]. If none - is found, jump directly to trying to convert what we have collected - so far. */ - - switch (*tokptr) - { - case 'e': - case 'E': - case 'd': - case 'D': - *copy++ = 'e'; - tokptr++; - break; - default: - goto convert_float; - break; - } - - /* Accept an optional '-' or '+' following one of [eEdD]. */ - - collect_exponent: - if (*tokptr == '+' || *tokptr == '-') - { - *copy++ = *tokptr++; - } - - /* Now copy an exponent into the conversion buffer. Note that at the - moment underscores are *not* allowed in exponents. */ - - while (isdigit (*tokptr)) - { - *copy++ = *tokptr++; - } - - /* If we transfered any chars to the conversion buffer, try to interpret its - contents as a floating point value. If any characters remain, then we - must not have a valid floating point string. */ - - convert_float: - *copy = '\0'; - if (copy != buf) - { - dval = strtod (buf, ©); - if (*copy == '\0') - { - yylval.dval = dval; - lexptr = tokptr; - return (FLOAT_LITERAL); - } - } - return (0); -} - -/* Recognize a string literal. A string literal is a nonzero sequence - of characters enclosed in matching single or double quotes, except that - a single character inside single quotes is a character literal, which - we reject as a string literal. To embed the terminator character inside - a string, it is simply doubled (I.E. "this""is""one""string") */ - -static int -match_string_literal () -{ - char *tokptr = lexptr; - - for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++) - { - CHECKBUF (1); - if (*tokptr == *lexptr) - { - if (*(tokptr + 1) == *lexptr) - { - tokptr++; - } - else - { - break; - } - } - tempbuf[tempbufindex++] = *tokptr; - } - if (*tokptr == '\0' /* no terminator */ - || tempbufindex == 0 /* no string */ - || (tempbufindex == 1 && *tokptr == '\'')) /* char literal */ - { - return (0); - } - else - { - tempbuf[tempbufindex] = '\0'; - yylval.sval.ptr = tempbuf; - yylval.sval.length = tempbufindex; - lexptr = ++tokptr; - return (CHARACTER_STRING_LITERAL); - } -} - -/* Recognize a character literal. A character literal is single character - or a control sequence, enclosed in single quotes. A control sequence - is a comma separated list of one or more integer literals, enclosed - in parenthesis and introduced with a circumflex character. - - EX: 'a' '^(7)' '^(7,8)' - - As a GNU chill extension, the syntax C'xx' is also recognized as a - character literal, where xx is a hex value for the character. - - Note that more than a single character, enclosed in single quotes, is - a string literal. - - Also note that the control sequence form is not in GNU Chill since it - is ambiguous with the string literal form using single quotes. I.E. - is '^(7)' a character literal or a string literal. In theory it it - possible to tell by context, but GNU Chill doesn't accept the control - sequence form, so neither do we (for now the code is disabled). - - Returns CHARACTER_LITERAL if a match is found. - */ - -static int -match_character_literal () -{ - char *tokptr = lexptr; - int ival = 0; - - if ((tolower (*tokptr) == 'c') && (*(tokptr + 1) == '\'')) - { - /* We have a GNU chill extension form, so skip the leading "C'", - decode the hex value, and then ensure that we have a trailing - single quote character. */ - tokptr += 2; - if (!decode_integer_value (16, &tokptr, &ival) || (*tokptr != '\'')) - { - return (0); - } - tokptr++; - } - else if (*tokptr == '\'') - { - tokptr++; - - /* Determine which form we have, either a control sequence or the - single character form. */ - - if ((*tokptr == '^') && (*(tokptr + 1) == '(')) - { -#if 0 /* Disable, see note above. -fnf */ - /* Match and decode a control sequence. Return zero if we don't - find a valid integer literal, or if the next unconsumed character - after the integer literal is not the trailing ')'. - FIXME: We currently don't handle the multiple integer literal - form. */ - tokptr += 2; - if (!decode_integer_literal (&ival, &tokptr) || (*tokptr++ != ')')) - { - return (0); - } -#else - return (0); -#endif - } - else - { - ival = *tokptr++; - } - - /* The trailing quote has not yet been consumed. If we don't find - it, then we have no match. */ - - if (*tokptr++ != '\'') - { - return (0); - } - } - else - { - /* Not a character literal. */ - return (0); - } - yylval.typed_val.val = ival; - yylval.typed_val.type = builtin_type_chill_char; - lexptr = tokptr; - return (CHARACTER_LITERAL); -} - -/* Recognize an integer literal, as specified in Z.200 sec 5.2.4.2. - Note that according to 5.2.4.2, a single "_" is also a valid integer - literal, however GNU-chill requires there to be at least one "digit" - in any integer literal. */ - -static int -match_integer_literal () -{ - char *tokptr = lexptr; - int ival; - - if (!decode_integer_literal (&ival, &tokptr)) - { - return (0); - } - else - { - yylval.typed_val.val = ival; - yylval.typed_val.type = builtin_type_int; - lexptr = tokptr; - return (INTEGER_LITERAL); - } -} - -/* Recognize a bit-string literal, as specified in Z.200 sec 5.2.4.8 - Note that according to 5.2.4.8, a single "_" is also a valid bit-string - literal, however GNU-chill requires there to be at least one "digit" - in any bit-string literal. */ - -static int -match_bitstring_literal () -{ - char *tokptr = lexptr; - int mask; - int bitoffset = 0; - int bitcount = 0; - int base; - int digit; - - tempbufindex = 0; - - /* Look for the required explicit base specifier. */ - - switch (*tokptr++) - { - case 'b': - case 'B': - base = 2; - break; - case 'o': - case 'O': - base = 8; - break; - case 'h': - case 'H': - base = 16; - break; - default: - return (0); - break; - } - - /* Ensure that the character after the explicit base is a single quote. */ - - if (*tokptr++ != '\'') - { - return (0); - } - - while (*tokptr != '\0' && *tokptr != '\'') - { - digit = tolower (*tokptr); - tokptr++; - switch (digit) - { - case '_': - continue; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - digit -= '0'; - break; - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - digit -= 'a'; - digit += 10; - break; - default: - return (0); - break; - } - if (digit >= base) - { - /* Found something not in domain for current base. */ - return (0); - } - else - { - /* Extract bits from digit, starting with the msbit appropriate for - the current base, and packing them into the bitstring byte, - starting at the lsbit. */ - for (mask = (base >> 1); mask > 0; mask >>= 1) - { - bitcount++; - CHECKBUF (1); - if (digit & mask) - { - tempbuf[tempbufindex] |= (1 << bitoffset); - } - bitoffset++; - if (bitoffset == HOST_CHAR_BIT) - { - bitoffset = 0; - tempbufindex++; - } - } - } - } - - /* Verify that we consumed everything up to the trailing single quote, - and that we found some bits (IE not just underbars). */ - - if (*tokptr++ != '\'') - { - return (0); - } - else - { - yylval.sval.ptr = tempbuf; - yylval.sval.length = bitcount; - lexptr = tokptr; - return (BIT_STRING_LITERAL); - } -} - -/* Recognize tokens that start with '$'. These include: - - $regname A native register name or a "standard - register name". - Return token GDB_REGNAME. - - $variable A convenience variable with a name chosen - by the user. - Return token GDB_VARIABLE. - - $digits Value history with index , starting - from the first value which has index 1. - Return GDB_LAST. - - $$digits Value history with index relative - to the last value. I.E. $$0 is the last - value, $$1 is the one previous to that, $$2 - is the one previous to $$1, etc. - Return token GDB_LAST. - - $ | $0 | $$0 The last value in the value history. - Return token GDB_LAST. - - $$ An abbreviation for the second to the last - value in the value history, I.E. $$1 - Return token GDB_LAST. - - Note that we currently assume that register names and convenience - variables follow the convention of starting with a letter or '_'. - - */ - -static int -match_dollar_tokens () -{ - char *tokptr; - int regno; - int namelength; - int negate; - int ival; - - /* We will always have a successful match, even if it is just for - a single '$', the abbreviation for $$0. So advance lexptr. */ - - tokptr = ++lexptr; - - if (*tokptr == '_' || isalpha (*tokptr)) - { - /* Look for a match with a native register name, usually something - like "r0" for example. */ - - for (regno = 0; regno < NUM_REGS; regno++) - { - namelength = strlen (reg_names[regno]); - if (STREQN (tokptr, reg_names[regno], namelength) - && !isalnum (tokptr[namelength])) - { - yylval.lval = regno; - lexptr += namelength + 1; - return (GDB_REGNAME); - } - } - - /* Look for a match with a standard register name, usually something - like "pc", which gdb always recognizes as the program counter - regardless of what the native register name is. */ - - for (regno = 0; regno < num_std_regs; regno++) - { - namelength = strlen (std_regs[regno].name); - if (STREQN (tokptr, std_regs[regno].name, namelength) - && !isalnum (tokptr[namelength])) - { - yylval.lval = std_regs[regno].regnum; - lexptr += namelength; - return (GDB_REGNAME); - } - } - - /* Attempt to match against a convenience variable. Note that - this will always succeed, because if no variable of that name - already exists, the lookup_internalvar will create one for us. - Also note that both lexptr and tokptr currently point to the - start of the input string we are trying to match, and that we - have already tested the first character for non-numeric, so we - don't have to treat it specially. */ - - while (*tokptr == '_' || isalnum (*tokptr)) - { - tokptr++; - } - yylval.sval.ptr = lexptr; - yylval.sval.length = tokptr - lexptr; - yylval.ivar = lookup_internalvar (copy_name (yylval.sval)); - lexptr = tokptr; - return (GDB_VARIABLE); - } - - /* Since we didn't match against a register name or convenience - variable, our only choice left is a history value. */ - - if (*tokptr == '$') - { - negate = 1; - ival = 1; - tokptr++; - } - else - { - negate = 0; - ival = 0; - } - - /* Attempt to decode more characters as an integer value giving - the index in the history list. If successful, the value will - overwrite ival (currently 0 or 1), and if not, ival will be - left alone, which is good since it is currently correct for - the '$' or '$$' case. */ - - decode_integer_literal (&ival, &tokptr); - yylval.lval = negate ? -ival : ival; - lexptr = tokptr; - return (GDB_LAST); -} - -struct token -{ - char *operator; - int token; -}; - -static const struct token idtokentab[] = -{ - { "length", LENGTH }, - { "lower", LOWER }, - { "upper", UPPER }, - { "andif", ANDIF }, - { "pred", PRED }, - { "succ", SUCC }, - { "card", CARD }, - { "size", SIZE }, - { "orif", ORIF }, - { "num", NUM }, - { "abs", ABS }, - { "max", MAX_TOKEN }, - { "min", MIN_TOKEN }, - { "mod", MOD }, - { "rem", REM }, - { "not", NOT }, - { "xor", LOGXOR }, - { "and", LOGAND }, - { "in", IN }, - { "or", LOGIOR } -}; - -static const struct token tokentab2[] = -{ - { ":=", GDB_ASSIGNMENT }, - { "//", SLASH_SLASH }, - { "->", POINTER }, - { "/=", NOTEQUAL }, - { "<=", LEQ }, - { ">=", GTR } -}; - -/* Read one token, getting characters through lexptr. */ -/* This is where we will check to make sure that the language and the - operators used are compatible. */ - -static int -yylex () -{ - unsigned int i; - int token; - char *simplename; - struct symbol *sym; - - /* Skip over any leading whitespace. */ - while (isspace (*lexptr)) - { - lexptr++; - } - /* Look for special single character cases which can't be the first - character of some other multicharacter token. */ - switch (*lexptr) - { - case '\0': - return (0); - case ',': - case '=': - case ';': - case '!': - case '+': - case '*': - case '(': - case ')': - case '[': - case ']': - return (*lexptr++); - } - /* Look for characters which start a particular kind of multicharacter - token, such as a character literal, register name, convenience - variable name, string literal, etc. */ - switch (*lexptr) - { - case '\'': - case '\"': - /* First try to match a string literal, which is any nonzero - sequence of characters enclosed in matching single or double - quotes, except that a single character inside single quotes - is a character literal, so we have to catch that case also. */ - token = match_string_literal (); - if (token != 0) - { - return (token); - } - if (*lexptr == '\'') - { - token = match_character_literal (); - if (token != 0) - { - return (token); - } - } - break; - case 'C': - case 'c': - token = match_character_literal (); - if (token != 0) - { - return (token); - } - break; - case '$': - token = match_dollar_tokens (); - if (token != 0) - { - return (token); - } - break; - } - /* See if it is a special token of length 2. */ - for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++) - { - if (STREQN (lexptr, tokentab2[i].operator, 2)) - { - lexptr += 2; - return (tokentab2[i].token); - } - } - /* Look for single character cases which which could be the first - character of some other multicharacter token, but aren't, or we - would already have found it. */ - switch (*lexptr) - { - case '-': - case ':': - case '/': - case '<': - case '>': - return (*lexptr++); - } - /* Look for a float literal before looking for an integer literal, so - we match as much of the input stream as possible. */ - token = match_float_literal (); - if (token != 0) - { - return (token); - } - token = match_bitstring_literal (); - if (token != 0) - { - return (token); - } - token = match_integer_literal (); - if (token != 0) - { - return (token); - } - - /* Try to match a simple name string, and if a match is found, then - further classify what sort of name it is and return an appropriate - token. Note that attempting to match a simple name string consumes - the token from lexptr, so we can't back out if we later find that - we can't classify what sort of name it is. */ - - simplename = match_simple_name_string (); - - if (simplename != NULL) - { - /* See if it is a reserved identifier. */ - for (i = 0; i < sizeof (idtokentab) / sizeof (idtokentab[0]); i++) - { - if (STREQ (simplename, idtokentab[i].operator)) - { - return (idtokentab[i].token); - } - } - - /* Look for other special tokens. */ - if (STREQ (simplename, "true")) - { - yylval.ulval = 1; - return (BOOLEAN_LITERAL); - } - if (STREQ (simplename, "false")) - { - yylval.ulval = 0; - return (BOOLEAN_LITERAL); - } - - sym = lookup_symbol (simplename, expression_context_block, - VAR_NAMESPACE, (int *) NULL, - (struct symtab **) NULL); - if (sym != NULL) - { - yylval.ssym.stoken.ptr = NULL; - yylval.ssym.stoken.length = 0; - yylval.ssym.sym = sym; - yylval.ssym.is_a_field_of_this = 0; /* FIXME, C++'ism */ - switch (SYMBOL_CLASS (sym)) - { - case LOC_BLOCK: - /* Found a procedure name. */ - return (GENERAL_PROCEDURE_NAME); - case LOC_STATIC: - /* Found a global or local static variable. */ - return (LOCATION_NAME); - case LOC_REGISTER: - case LOC_ARG: - case LOC_REF_ARG: - case LOC_REGPARM: - case LOC_REGPARM_ADDR: - case LOC_LOCAL: - case LOC_LOCAL_ARG: - case LOC_BASEREG: - case LOC_BASEREG_ARG: - if (innermost_block == NULL - || contained_in (block_found, innermost_block)) - { - innermost_block = block_found; - } - return (LOCATION_NAME); - break; - case LOC_CONST: - case LOC_LABEL: - return (LOCATION_NAME); - break; - case LOC_TYPEDEF: - yylval.tsym.type = SYMBOL_TYPE (sym); - return TYPENAME; - case LOC_UNDEF: - case LOC_CONST_BYTES: - case LOC_OPTIMIZED_OUT: - error ("Symbol \"%s\" names no location.", simplename); - break; - } - } - else if (!have_full_symbols () && !have_partial_symbols ()) - { - error ("No symbol table is loaded. Use the \"file\" command."); - } - else - { - error ("No symbol \"%s\" in current context.", simplename); - } - } - - /* Catch single character tokens which are not part of some - longer token. */ - - switch (*lexptr) - { - case '.': /* Not float for example. */ - lexptr++; - while (isspace (*lexptr)) lexptr++; - simplename = match_simple_name_string (); - if (!simplename) - return '.'; - return FIELD_NAME; - } - - return (ILLEGAL_TOKEN); -} - -void -yyerror (msg) - char *msg; /* unused */ -{ - printf ("Parsing: %s\n", lexptr); - if (yychar < 256) - { - error ("Invalid syntax in expression near character '%c'.", yychar); - } - else - { - error ("Invalid syntax in expression"); - } -} -#line 1836 "y.tab.c" -#define YYABORT goto yyabort -#define YYREJECT goto yyabort -#define YYACCEPT goto yyaccept -#define YYERROR goto yyerrlab -int -yyparse() -{ - register int yym, yyn, yystate; -#if YYDEBUG - register char *yys; - extern char *getenv(); - - if (yys = getenv("YYDEBUG")) - { - yyn = *yys; - if (yyn >= '0' && yyn <= '9') - yydebug = yyn - '0'; - } -#endif - - yynerrs = 0; - yyerrflag = 0; - yychar = (-1); - - yyssp = yyss; - yyvsp = yyvs; - *yyssp = yystate = 0; - -yyloop: - if (yyn = yydefred[yystate]) goto yyreduce; - if (yychar < 0) - { - if ((yychar = yylex()) < 0) yychar = 0; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, reading %d (%s)\n", - YYPREFIX, yystate, yychar, yys); - } -#endif - } - if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yychar) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, shifting to state %d\n", - YYPREFIX, yystate, yytable[yyn]); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate = yytable[yyn]; - *++yyvsp = yylval; - yychar = (-1); - if (yyerrflag > 0) --yyerrflag; - goto yyloop; - } - if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yychar) - { - yyn = yytable[yyn]; - goto yyreduce; - } - if (yyerrflag) goto yyinrecovery; -#ifdef lint - goto yynewerror; -#endif -yynewerror: - yyerror("syntax error"); -#ifdef lint - goto yyerrlab; -#endif -yyerrlab: - ++yynerrs; -yyinrecovery: - if (yyerrflag < 3) - { - yyerrflag = 3; - for (;;) - { - if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, error recovery shifting\ - to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate = yytable[yyn]; - *++yyvsp = yylval; - goto yyloop; - } - else - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: error recovery discarding state %d\n", - YYPREFIX, *yyssp); -#endif - if (yyssp <= yyss) goto yyabort; - --yyssp; - --yyvsp; - } - } - } - else - { - if (yychar == 0) goto yyabort; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, error recovery discards token %d (%s)\n", - YYPREFIX, yystate, yychar, yys); - } -#endif - yychar = (-1); - goto yyloop; - } -yyreduce: -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, reducing by rule %d (%s)\n", - YYPREFIX, yystate, yyn, yyrule[yyn]); -#endif - yym = yylen[yyn]; - yyval = yyvsp[1-yym]; - switch (yyn) - { -case 1: -#line 312 "./ch-exp.y" -{ } -break; -case 2: -#line 314 "./ch-exp.y" -{ write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type(yyvsp[0].tsym.type); - write_exp_elt_opcode(OP_TYPE);} -break; -case 3: -#line 320 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 4: -#line 324 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 5: -#line 330 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 7: -#line 339 "./ch-exp.y" -{ - write_exp_elt_opcode (UNOP_IND); - } -break; -case 8: -#line 347 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_block (NULL); - write_exp_elt_sym (yyvsp[0].ssym.sym); - write_exp_elt_opcode (OP_VAR_VALUE); - } -break; -case 9: -#line 354 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_LAST); - write_exp_elt_longcst (yyvsp[0].lval); - write_exp_elt_opcode (OP_LAST); - } -break; -case 10: -#line 360 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_REGISTER); - write_exp_elt_longcst (yyvsp[0].lval); - write_exp_elt_opcode (OP_REGISTER); - } -break; -case 11: -#line 366 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_INTERNALVAR); - write_exp_elt_intern (yyvsp[0].ivar); - write_exp_elt_opcode (OP_INTERNALVAR); - } -break; -case 12: -#line 372 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 13: -#line 380 "./ch-exp.y" -{ - arglist_len = 1; - } -break; -case 14: -#line 384 "./ch-exp.y" -{ - arglist_len++; - } -break; -case 15: -#line 391 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 16: -#line 395 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 17: -#line 399 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 18: -#line 403 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 19: -#line 407 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 20: -#line 411 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 21: -#line 415 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 22: -#line 419 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 23: -#line 423 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 24: -#line 427 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 25: -#line 431 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 26: -#line 435 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 27: -#line 439 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 28: -#line 443 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 29: -#line 447 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 30: -#line 455 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 31: -#line 463 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 32: -#line 467 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 33: -#line 471 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 34: -#line 475 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 35: -#line 479 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_VAR_VALUE); - write_exp_elt_block (NULL); - write_exp_elt_sym (yyvsp[0].ssym.sym); - write_exp_elt_opcode (OP_VAR_VALUE); - } -break; -case 36: -#line 490 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (yyvsp[0].typed_val.type); - write_exp_elt_longcst ((LONGEST) (yyvsp[0].typed_val.val)); - write_exp_elt_opcode (OP_LONG); - } -break; -case 37: -#line 497 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_BOOL); - write_exp_elt_longcst ((LONGEST) yyvsp[0].ulval); - write_exp_elt_opcode (OP_BOOL); - } -break; -case 38: -#line 503 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (yyvsp[0].typed_val.type); - write_exp_elt_longcst ((LONGEST) (yyvsp[0].typed_val.val)); - write_exp_elt_opcode (OP_LONG); - } -break; -case 39: -#line 510 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type (builtin_type_double); - write_exp_elt_dblcst (yyvsp[0].dval); - write_exp_elt_opcode (OP_DOUBLE); - } -break; -case 40: -#line 517 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 41: -#line 521 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 42: -#line 525 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_STRING); - write_exp_string (yyvsp[0].sval); - write_exp_elt_opcode (OP_STRING); - } -break; -case 43: -#line 531 "./ch-exp.y" -{ - write_exp_elt_opcode (OP_BITSTRING); - write_exp_bitstring (yyvsp[0].sval); - write_exp_elt_opcode (OP_BITSTRING); - } -break; -case 44: -#line 541 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 45: -#line 550 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 46: -#line 558 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 47: -#line 562 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 48: -#line 572 "./ch-exp.y" -{ start_arglist (); } -break; -case 49: -#line 574 "./ch-exp.y" -{ - write_exp_elt_opcode (MULTI_SUBSCRIPT); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (MULTI_SUBSCRIPT); - } -break; -case 50: -#line 584 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 51: -#line 588 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 52: -#line 596 "./ch-exp.y" -{ write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string (yyvsp[0].sval); - write_exp_elt_opcode (STRUCTOP_STRUCT); - } -break; -case 53: -#line 605 "./ch-exp.y" -{ - write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (yyvsp[-1].tsym.type); - write_exp_elt_opcode (UNOP_CAST); - } -break; -case 54: -#line 615 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 55: -#line 623 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 56: -#line 631 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 57: -#line 639 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 58: -#line 647 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 59: -#line 655 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 60: -#line 659 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 61: -#line 663 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 62: -#line 669 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 63: -#line 673 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 64: -#line 679 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 65: -#line 685 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 66: -#line 689 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 67: -#line 695 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 68: -#line 701 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 69: -#line 709 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 70: -#line 713 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_BITWISE_IOR); - } -break; -case 71: -#line 717 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 72: -#line 721 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_BITWISE_XOR); - } -break; -case 73: -#line 729 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 74: -#line 733 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_BITWISE_AND); - } -break; -case 75: -#line 737 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 76: -#line 745 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 77: -#line 749 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_EQUAL); - } -break; -case 78: -#line 753 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_NOTEQUAL); - } -break; -case 79: -#line 757 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_GTR); - } -break; -case 80: -#line 761 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_GEQ); - } -break; -case 81: -#line 765 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_LESS); - } -break; -case 82: -#line 769 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_LEQ); - } -break; -case 83: -#line 773 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 84: -#line 782 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 85: -#line 786 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_ADD); - } -break; -case 86: -#line 790 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_SUB); - } -break; -case 87: -#line 794 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_CONCAT); - } -break; -case 88: -#line 802 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 89: -#line 806 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_MUL); - } -break; -case 90: -#line 810 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_DIV); - } -break; -case 91: -#line 814 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_MOD); - } -break; -case 92: -#line 818 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_REM); - } -break; -case 93: -#line 826 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 94: -#line 830 "./ch-exp.y" -{ - write_exp_elt_opcode (UNOP_NEG); - } -break; -case 95: -#line 834 "./ch-exp.y" -{ - write_exp_elt_opcode (UNOP_LOGICAL_NOT); - } -break; -case 96: -#line 840 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_CONCAT); - } -break; -case 97: -#line 848 "./ch-exp.y" -{ - write_exp_elt_opcode (UNOP_ADDR); - } -break; -case 98: -#line 852 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 99: -#line 856 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 100: -#line 866 "./ch-exp.y" -{ - write_exp_elt_opcode (BINOP_ASSIGN); - } -break; -case 101: -#line 875 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 102: -#line 879 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 103: -#line 883 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 104: -#line 887 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 105: -#line 891 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 106: -#line 895 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 107: -#line 899 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 108: -#line 903 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 109: -#line 907 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 110: -#line 911 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 111: -#line 915 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 112: -#line 919 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 113: -#line 925 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 114: -#line 929 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 115: -#line 933 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 116: -#line 937 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 118: -#line 946 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 119: -#line 950 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 120: -#line 956 "./ch-exp.y" -{ - yyval.voidval = 0; /* FIXME */ - } -break; -case 121: -#line 964 "./ch-exp.y" -{ - yyval.voidval = 0; - } -break; -case 122: -#line 972 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 123: -#line 973 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 124: -#line 974 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 125: -#line 975 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 126: -#line 976 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 127: -#line 977 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 128: -#line 978 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 129: -#line 979 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 130: -#line 980 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 131: -#line 981 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 132: -#line 982 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 133: -#line 983 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 134: -#line 984 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 135: -#line 985 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 136: -#line 986 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 137: -#line 987 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 138: -#line 988 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 139: -#line 989 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 140: -#line 990 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -case 141: -#line 991 "./ch-exp.y" -{ yyval.voidval = 0; } -break; -#line 2799 "y.tab.c" - } - yyssp -= yym; - yystate = *yyssp; - yyvsp -= yym; - yym = yylhs[yyn]; - if (yystate == 0 && yym == 0) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: after reduction, shifting from state 0 to\ - state %d\n", YYPREFIX, YYFINAL); -#endif - yystate = YYFINAL; - *++yyssp = YYFINAL; - *++yyvsp = yyval; - if (yychar < 0) - { - if ((yychar = yylex()) < 0) yychar = 0; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, reading %d (%s)\n", - YYPREFIX, YYFINAL, yychar, yys); - } -#endif - } - if (yychar == 0) goto yyaccept; - goto yyloop; - } - if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yystate) - yystate = yytable[yyn]; - else - yystate = yydgoto[yym]; -#if YYDEBUG - if (yydebug) - printf("%sdebug: after reduction, shifting from state %d \ -to state %d\n", YYPREFIX, *yyssp, yystate); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate; - *++yyvsp = yyval; - goto yyloop; -yyoverflow: - yyerror("yacc stack overflow"); -yyabort: - return (1); -yyaccept: - return (0); -} diff --git a/gnu/usr.bin/gdb/gdb/freebsd-solib.c b/gnu/usr.bin/gdb/gdb/freebsd-solib.c deleted file mode 100644 index 5b6e4c0..0000000 --- a/gnu/usr.bin/gdb/gdb/freebsd-solib.c +++ /dev/null @@ -1,1469 +0,0 @@ -/* Handle SunOS and SVR4 shared libraries for GDB, the GNU Debugger. - Copyright 1990, 1991, 1992 Free Software Foundation, Inc. - -This file is part of GDB. - -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 of the License, 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 this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* modified for FreeBSD, since the names in link.h are totally different! - 6.1.94 */ - -#include "defs.h" - -#include -#include -#include -#ifndef SVR4_SHARED_LIBS - /* SunOS shared libs need the nlist structure. */ -#include -#endif -#include -#include -#include - -#include "symtab.h" -#include "bfd.h" -#include "symfile.h" -#include "objfiles.h" -#include "gdbcore.h" -#include "command.h" -#include "target.h" -#include "frame.h" -#include "regex.h" -#include "inferior.h" -#include "language.h" - -#define MAX_PATH_SIZE 256 /* FIXME: Should be dynamic */ - -/* On SVR4 systems, for the initial implementation, use some runtime startup - symbol as the "startup mapping complete" breakpoint address. The models - for SunOS and SVR4 dynamic linking debugger support are different in that - SunOS hits one breakpoint when all mapping is complete while using the SVR4 - debugger support takes two breakpoint hits for each file mapped, and - there is no way to know when the "last" one is hit. Both these - mechanisms should be tied to a "breakpoint service routine" that - gets automatically executed whenever one of the breakpoints indicating - a change in mapping is hit. This is a future enhancement. (FIXME) */ - -#define BKPT_AT_SYMBOL 1 - -#if defined (BKPT_AT_SYMBOL) && defined (SVR4_SHARED_LIBS) -static char *bkpt_names[] = { -#ifdef SOLIB_BKPT_NAME - SOLIB_BKPT_NAME, /* Prefer configured name if it exists. */ -#endif - "_start", - "main", - NULL -}; -#endif - -/* local data declarations */ - -#ifndef SVR4_SHARED_LIBS - -#define DEBUG_BASE "_DYNAMIC" -#ifdef OLD_FreeBSD_LD -#define LM_ADDR(so) ((so) -> lm.lm_addr) -#define LM_NEXT(so) ((so) -> lm.lm_next) -#define LM_NAME(so) ((so) -> lm.lm_name) -static struct link_dynamic dynamic_copy; -static struct link_dynamic_2 ld_2_copy; -static struct ld_debug debug_copy; -#else -#define LM_ADDR(so) ((so) -> lm.som_addr) -#define LM_NEXT(so) ((so) -> lm.som_next) -#define LM_NAME(so) ((so) -> lm.som_path) -static struct _dynamic dynamic_copy; -static struct section_dispatch_table ld_2_copy; -static struct so_debug debug_copy; -#endif -static CORE_ADDR debug_addr; -static CORE_ADDR flag_addr; - -#else /* SVR4_SHARED_LIBS */ - -#define DEBUG_BASE "_r_debug" -#define LM_ADDR(so) ((so) -> lm.l_addr) -#define LM_NEXT(so) ((so) -> lm.l_next) -#define LM_NAME(so) ((so) -> lm.l_name) -static struct r_debug debug_copy; -char shadow_contents[BREAKPOINT_MAX]; /* Stash old bkpt addr contents */ - -#endif /* !SVR4_SHARED_LIBS */ - -struct so_list { - struct so_list *next; /* next structure in linked list */ -#ifdef OLD_FreeBSD_LD - struct link_map lm; /* copy of link map from inferior */ - struct link_map *lmaddr; /* addr in inferior lm was read from */ -#else - struct so_map lm; /* copy of link map from inferior */ - struct so_map *lmaddr; /* addr in inferior lm was read from */ -#endif - CORE_ADDR lmend; /* upper addr bound of mapped object */ - char so_name[MAX_PATH_SIZE]; /* shared object lib name (FIXME) */ - char symbols_loaded; /* flag: symbols read in yet? */ - char from_tty; /* flag: print msgs? */ - struct objfile *objfile; /* objfile for loaded lib */ - struct section_table *sections; - struct section_table *sections_end; - struct section_table *textsection; - bfd *abfd; -}; - -static struct so_list *so_list_head; /* List of known shared objects */ -static CORE_ADDR debug_base; /* Base of dynamic linker structures */ -static CORE_ADDR breakpoint_addr; /* Address where end bkpt is set */ - -extern int -fdmatch PARAMS ((int, int)); /* In libiberty */ - -/* Local function prototypes */ - -static void -special_symbol_handling PARAMS ((struct so_list *)); - -static void -sharedlibrary_command PARAMS ((char *, int)); - -static int -enable_break PARAMS ((void)); - -static int -disable_break PARAMS ((void)); - -static void -info_sharedlibrary_command PARAMS ((char *, int)); - -static int -symbol_add_stub PARAMS ((char *)); - -static struct so_list * -find_solib PARAMS ((struct so_list *)); - -#ifdef OLD_FreeBSD_LD -static struct link_map * -#else -static struct so_map * -#endif -first_link_map_member PARAMS ((void)); - -static CORE_ADDR -locate_base PARAMS ((void)); - -static void -solib_map_sections PARAMS ((struct so_list *)); - -#ifdef SVR4_SHARED_LIBS - -static int -look_for_base PARAMS ((int, CORE_ADDR)); - -static CORE_ADDR -bfd_lookup_symbol PARAMS ((bfd *, char *)); - -#else - -static void -solib_add_common_symbols PARAMS ((struct rt_symbol *, struct objfile *)); - -#endif - -/* - -LOCAL FUNCTION - - solib_map_sections -- open bfd and build sections for shared lib - -SYNOPSIS - - static void solib_map_sections (struct so_list *so) - -DESCRIPTION - - Given a pointer to one of the shared objects in our list - of mapped objects, use the recorded name to open a bfd - descriptor for the object, build a section table, and then - relocate all the section addresses by the base address at - which the shared object was mapped. - -FIXMES - - In most (all?) cases the shared object file name recorded in the - dynamic linkage tables will be a fully qualified pathname. For - cases where it isn't, do we really mimic the systems search - mechanism correctly in the below code (particularly the tilde - expansion stuff?). - */ - -static void -solib_map_sections (so) - struct so_list *so; -{ - char *filename; - char *scratch_pathname; - int scratch_chan; - struct section_table *p; - struct cleanup *old_chain; - bfd *abfd; - - filename = tilde_expand (so -> so_name); - old_chain = make_cleanup (free, filename); - - scratch_chan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0, - &scratch_pathname); - if (scratch_chan < 0) - { - scratch_chan = openp (getenv ("LD_LIBRARY_PATH"), 1, filename, - O_RDONLY, 0, &scratch_pathname); - } - if (scratch_chan < 0) - { - perror_with_name (filename); - } - /* Leave scratch_pathname allocated. abfd->name will point to it. */ - - abfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan); - if (!abfd) - { - close (scratch_chan); - error ("Could not open `%s' as an executable file: %s", - scratch_pathname, bfd_errmsg (bfd_error)); - } - /* Leave bfd open, core_xfer_memory and "info files" need it. */ - so -> abfd = abfd; - abfd -> cacheable = true; - - if (!bfd_check_format (abfd, bfd_object)) - { - error ("\"%s\": not in executable format: %s.", - scratch_pathname, bfd_errmsg (bfd_error)); - } - if (build_section_table (abfd, &so -> sections, &so -> sections_end)) - { - error ("Can't find the file sections in `%s': %s", - bfd_get_filename (exec_bfd), bfd_errmsg (bfd_error)); - } - - for (p = so -> sections; p < so -> sections_end; p++) - { - /* Relocate the section binding addresses as recorded in the shared - object's file by the base address to which the object was actually - mapped. */ - p -> addr += (CORE_ADDR) LM_ADDR (so); - p -> endaddr += (CORE_ADDR) LM_ADDR (so); - so -> lmend = (CORE_ADDR) max (p -> endaddr, so -> lmend); - if (STREQ (p -> sec_ptr -> name, ".text")) - { - so -> textsection = p; - } - } - - /* Free the file names, close the file now. */ - do_cleanups (old_chain); -} - -/* Read all dynamically loaded common symbol definitions from the inferior - and add them to the minimal symbol table for the shared library objfile. */ - -#ifndef SVR4_SHARED_LIBS - -/* In GDB 4.9 this routine was a real performance hog. According to - some gprof data which mtranle@paris.IntelliCorp.COM (Minh Tran-Le) - sent, almost all the time spend in solib_add (up to 20 minutes with - 35 shared libraries) was spent here, with 5/6 in - lookup_minimal_symbol and 1/6 in read_memory. - - To fix this, we moved the call to special_symbol_handling out of the - loop in solib_add, so this only gets called once, rather than once - for every shared library, and also removed the call to lookup_minimal_symbol - in this routine. */ - -static void -solib_add_common_symbols (rtc_symp, objfile) - struct rt_symbol *rtc_symp; - struct objfile *objfile; -{ - struct rt_symbol inferior_rtc_symb; - struct nzlist inferior_rtc_nzlist; - int len; - char *name; - char *origname; - - init_minimal_symbol_collection (); - make_cleanup (discard_minimal_symbols, 0); - - while (rtc_symp) - { - read_memory ((CORE_ADDR) rtc_symp, - (char *) &inferior_rtc_symb, - sizeof (inferior_rtc_symb)); - read_memory ((CORE_ADDR) inferior_rtc_symb.rt_sp, - (char *) &inferior_rtc_nzlist, - sizeof(inferior_rtc_nzlist)); - if (inferior_rtc_nzlist.nz_type == N_COMM) - { - /* FIXME: The length of the symbol name is not available, but in the - current implementation the common symbol is allocated immediately - behind the name of the symbol. */ - len = inferior_rtc_nzlist.nz_value - inferior_rtc_nzlist.nz_strx; - - origname = name = xmalloc (len); - read_memory ((CORE_ADDR) inferior_rtc_nzlist.nz_name, name, len); - - /* Don't enter the symbol twice if the target is re-run. */ - - if (name[0] == bfd_get_symbol_leading_char (objfile->obfd)) - { - name++; - } - -#if 0 - /* I think this is unnecessary, GDB can probably deal with - duplicate minimal symbols, more or less. And the duplication - which used to happen because this was called for each shared - library is gone now that we are just called once. */ - /* FIXME: Do we really want to exclude symbols which happen - to match symbols for other locations in the inferior's - address space, even when they are in different linkage units? */ - if (lookup_minimal_symbol (name, (struct objfile *) NULL) == NULL) -#endif - { - name = obsavestring (name, strlen (name), - &objfile -> symbol_obstack); - prim_record_minimal_symbol (name, inferior_rtc_nzlist.nz_value, - mst_bss); - } - free (origname); - } - rtc_symp = inferior_rtc_symb.rt_next; - } - - /* Install any minimal symbols that have been collected as the current - minimal symbols for this objfile. */ - - install_minimal_symbols (objfile); -} - -#endif /* SVR4_SHARED_LIBS */ - -#ifdef SVR4_SHARED_LIBS - -/* - -LOCAL FUNCTION - - bfd_lookup_symbol -- lookup the value for a specific symbol - -SYNOPSIS - - CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname) - -DESCRIPTION - - An expensive way to lookup the value of a single symbol for - bfd's that are only temporary anyway. This is used by the - shared library support to find the address of the debugger - interface structures in the shared library. - - Note that 0 is specifically allowed as an error return (no - such symbol). - - FIXME: See if there is a less "expensive" way of doing this. - Also see if there is already another bfd or gdb function - that specifically does this, and if so, use it. -*/ - -static CORE_ADDR -bfd_lookup_symbol (abfd, symname) - bfd *abfd; - char *symname; -{ - unsigned int storage_needed; - asymbol *sym; - asymbol **symbol_table; - unsigned int number_of_symbols; - unsigned int i; - struct cleanup *back_to; - CORE_ADDR symaddr = 0; - - storage_needed = get_symtab_upper_bound (abfd); - - if (storage_needed > 0) - { - symbol_table = (asymbol **) xmalloc (storage_needed); - back_to = make_cleanup (free, (PTR)symbol_table); - number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table); - - for (i = 0; i < number_of_symbols; i++) - { - sym = *symbol_table++; - if (STREQ (sym -> name, symname)) - { - /* Bfd symbols are section relative. */ - symaddr = sym -> value + sym -> section -> vma; - break; - } - } - do_cleanups (back_to); - } - return (symaddr); -} - -/* - -LOCAL FUNCTION - - look_for_base -- examine file for each mapped address segment - -SYNOPSYS - - static int look_for_base (int fd, CORE_ADDR baseaddr) - -DESCRIPTION - - This function is passed to proc_iterate_over_mappings, which - causes it to get called once for each mapped address space, with - an open file descriptor for the file mapped to that space, and the - base address of that mapped space. - - Our job is to find the symbol DEBUG_BASE in the file that this - fd is open on, if it exists, and if so, initialize the dynamic - linker structure base address debug_base. - - Note that this is a computationally expensive proposition, since - we basically have to open a bfd on every call, so we specifically - avoid opening the exec file. - */ - -static int -look_for_base (fd, baseaddr) - int fd; - CORE_ADDR baseaddr; -{ - bfd *interp_bfd; - CORE_ADDR address; - - /* If the fd is -1, then there is no file that corresponds to this - mapped memory segment, so skip it. Also, if the fd corresponds - to the exec file, skip it as well. */ - - if ((fd == -1) || fdmatch (fileno ((FILE *)(exec_bfd -> iostream)), fd)) - { - return (0); - } - - /* Try to open whatever random file this fd corresponds to. Note that - we have no way currently to find the filename. Don't gripe about - any problems we might have, just fail. */ - - if ((interp_bfd = bfd_fdopenr ("unnamed", gnutarget, fd)) == NULL) - { - return (0); - } - if (!bfd_check_format (interp_bfd, bfd_object)) - { - bfd_close (interp_bfd); - return (0); - } - - /* Now try to find our DEBUG_BASE symbol in this file, which we at - least know to be a valid ELF executable or shared library. */ - - if ((address = bfd_lookup_symbol (interp_bfd, DEBUG_BASE)) == 0) - { - bfd_close (interp_bfd); - return (0); - } - - /* Eureka! We found the symbol. But now we may need to relocate it - by the base address. If the symbol's value is less than the base - address of the shared library, then it hasn't yet been relocated - by the dynamic linker, and we have to do it ourself. FIXME: Note - that we make the assumption that the first segment that corresponds - to the shared library has the base address to which the library - was relocated. */ - - if (address < baseaddr) - { - address += baseaddr; - } - debug_base = address; - bfd_close (interp_bfd); - return (1); -} - -#endif - -/* - -LOCAL FUNCTION - - locate_base -- locate the base address of dynamic linker structs - -SYNOPSIS - - CORE_ADDR locate_base (void) - -DESCRIPTION - - For both the SunOS and SVR4 shared library implementations, if the - inferior executable has been linked dynamically, there is a single - address somewhere in the inferior's data space which is the key to - locating all of the dynamic linker's runtime structures. This - address is the value of the symbol defined by the macro DEBUG_BASE. - The job of this function is to find and return that address, or to - return 0 if there is no such address (the executable is statically - linked for example). - - For SunOS, the job is almost trivial, since the dynamic linker and - all of it's structures are statically linked to the executable at - link time. Thus the symbol for the address we are looking for has - already been added to the minimal symbol table for the executable's - objfile at the time the symbol file's symbols were read, and all we - have to do is look it up there. Note that we explicitly do NOT want - to find the copies in the shared library. - - The SVR4 version is much more complicated because the dynamic linker - and it's structures are located in the shared C library, which gets - run as the executable's "interpreter" by the kernel. We have to go - to a lot more work to discover the address of DEBUG_BASE. Because - of this complexity, we cache the value we find and return that value - on subsequent invocations. Note there is no copy in the executable - symbol tables. - - Note that we can assume nothing about the process state at the time - we need to find this address. We may be stopped on the first instruc- - tion of the interpreter (C shared library), the first instruction of - the executable itself, or somewhere else entirely (if we attached - to the process for example). - - */ - -static CORE_ADDR -locate_base () -{ - -#ifndef SVR4_SHARED_LIBS - - struct minimal_symbol *msymbol; - CORE_ADDR address = 0; - - /* For SunOS, we want to limit the search for DEBUG_BASE to the executable - being debugged, since there is a duplicate named symbol in the shared - library. We don't want the shared library versions. */ - - msymbol = lookup_minimal_symbol (DEBUG_BASE, symfile_objfile); - if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0)) - { - address = SYMBOL_VALUE_ADDRESS (msymbol); - } - return (address); - -#else /* SVR4_SHARED_LIBS */ - - /* Check to see if we have a currently valid address, and if so, avoid - doing all this work again and just return the cached address. If - we have no cached address, ask the /proc support interface to iterate - over the list of mapped address segments, calling look_for_base() for - each segment. When we are done, we will have either found the base - address or not. */ - - if (debug_base == 0) - { - proc_iterate_over_mappings (look_for_base); - } - return (debug_base); - -#endif /* !SVR4_SHARED_LIBS */ - -} - -/* - -LOCAL FUNCTION - - first_link_map_member -- locate first member in dynamic linker's map - -SYNOPSIS - - static struct link_map *first_link_map_member (void) - -DESCRIPTION - - Read in a copy of the first member in the inferior's dynamic - link map from the inferior's dynamic linker structures, and return - a pointer to the copy in our address space. -*/ - -#ifdef OLD_FreeBSD_LD -static struct link_map * -#else -static struct so_map * -#endif -first_link_map_member () -{ -#ifdef OLD_FreeBSD_LD - struct link_map *lm = NULL; -#else - struct so_map *lm = NULL; -#endif - -#ifndef SVR4_SHARED_LIBS - - read_memory (debug_base, (char *) &dynamic_copy, sizeof (dynamic_copy)); -#ifdef OLD_FreeBSD_LD - if (dynamic_copy.ld_version >= 2) - { - /* It is a version that we can deal with, so read in the secondary - structure and find the address of the link map list from it. */ - read_memory ((CORE_ADDR) dynamic_copy.ld_un.ld_2, (char *) &ld_2_copy, - sizeof (struct link_dynamic_2)); - lm = ld_2_copy.ld_loaded; - } -#else - if (dynamic_copy.d_version >= 2) - { - /* It is a version that we can deal with, so read in the secondary - structure and find the address of the link map list from it. */ - read_memory ((CORE_ADDR) dynamic_copy.d_un.d_sdt, (char *) &ld_2_copy, - sizeof (struct section_dispatch_table)); - lm = ld_2_copy.sdt_loaded; - } -#endif -#else /* SVR4_SHARED_LIBS */ - - read_memory (debug_base, (char *) &debug_copy, sizeof (struct r_debug)); - /* FIXME: Perhaps we should validate the info somehow, perhaps by - checking r_version for a known version number, or r_state for - RT_CONSISTENT. */ - lm = debug_copy.r_map; - -#endif /* !SVR4_SHARED_LIBS */ - - return (lm); -} - -/* - -LOCAL FUNCTION - - find_solib -- step through list of shared objects - -SYNOPSIS - - struct so_list *find_solib (struct so_list *so_list_ptr) - -DESCRIPTION - - This module contains the routine which finds the names of any - loaded "images" in the current process. The argument in must be - NULL on the first call, and then the returned value must be passed - in on subsequent calls. This provides the capability to "step" down - the list of loaded objects. On the last object, a NULL value is - returned. - - The arg and return value are "struct link_map" pointers, as defined - in . - */ - -static struct so_list * -find_solib (so_list_ptr) - struct so_list *so_list_ptr; /* Last lm or NULL for first one */ -{ - struct so_list *so_list_next = NULL; -#ifdef OLD_FreeBSD_LD - struct link_map *lm = NULL; -#else - struct so_map *lm = NULL; -#endif - struct so_list *new; - - if (so_list_ptr == NULL) - { - /* We are setting up for a new scan through the loaded images. */ - if ((so_list_next = so_list_head) == NULL) - { - /* We have not already read in the dynamic linking structures - from the inferior, lookup the address of the base structure. */ - debug_base = locate_base (); - if (debug_base != 0) - { - /* Read the base structure in and find the address of the first - link map list member. */ - lm = first_link_map_member (); - } - } - } - else - { - /* We have been called before, and are in the process of walking - the shared library list. Advance to the next shared object. */ - if ((lm = LM_NEXT (so_list_ptr)) == NULL) - { - /* We have hit the end of the list, so check to see if any were - added, but be quiet if we can't read from the target any more. */ - int status = target_read_memory ((CORE_ADDR) so_list_ptr -> lmaddr, - (char *) &(so_list_ptr -> lm), -#ifdef OLD_FreeBSD_LD - sizeof (struct link_map)); -#else - sizeof (struct so_map)); -#endif - if (status == 0) - { - lm = LM_NEXT (so_list_ptr); - } - else - { - lm = NULL; - } - } - so_list_next = so_list_ptr -> next; - } - if ((so_list_next == NULL) && (lm != NULL)) - { - /* Get next link map structure from inferior image and build a local - abbreviated load_map structure */ - new = (struct so_list *) xmalloc (sizeof (struct so_list)); - memset ((char *) new, 0, sizeof (struct so_list)); - new -> lmaddr = lm; - /* Add the new node as the next node in the list, or as the root - node if this is the first one. */ - if (so_list_ptr != NULL) - { - so_list_ptr -> next = new; - } - else - { - so_list_head = new; - } - so_list_next = new; - read_memory ((CORE_ADDR) lm, (char *) &(new -> lm), -#ifdef OLD_FreeBSD_LD - sizeof (struct link_map)); -#else - sizeof (struct so_map)); -#endif - /* For the SVR4 version, there is one entry that has no name - (for the inferior executable) since it is not a shared object. */ - if (LM_NAME (new) != 0) - { - if (!target_read_string((CORE_ADDR) LM_NAME (new), new -> so_name, - MAX_PATH_SIZE - 1)) - error ("find_solib: Can't read pathname for load map\n"); - new -> so_name[MAX_PATH_SIZE - 1] = 0; - solib_map_sections (new); - } - } - return (so_list_next); -} - -/* A small stub to get us past the arg-passing pinhole of catch_errors. */ - -static int -symbol_add_stub (arg) - char *arg; -{ - register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */ - - so -> objfile = symbol_file_add (so -> so_name, so -> from_tty, - (unsigned int) so -> textsection -> addr, - 0, 0, 0); - return (1); -} - -/* - -GLOBAL FUNCTION - - solib_add -- add a shared library file to the symtab and section list - -SYNOPSIS - - void solib_add (char *arg_string, int from_tty, - struct target_ops *target) - -DESCRIPTION - -*/ - -void -solib_add (arg_string, from_tty, target) - char *arg_string; - int from_tty; - struct target_ops *target; -{ - register struct so_list *so = NULL; /* link map state variable */ - - /* Last shared library that we read. */ - struct so_list *so_last = NULL; - - char *re_err; - int count; - int old; - - if ((re_err = re_comp (arg_string ? arg_string : ".")) != NULL) - { - error ("Invalid regexp: %s", re_err); - } - - /* Getting new symbols may change our opinion about what is - frameless. */ - reinit_frame_cache (); - - while ((so = find_solib (so)) != NULL) - { - if (so -> so_name[0] && re_exec (so -> so_name)) - { - so -> from_tty = from_tty; - if (so -> symbols_loaded) - { - if (from_tty) - { - printf ("Symbols already loaded for %s\n", so -> so_name); - } - } - else if (catch_errors - (symbol_add_stub, (char *) so, - "Error while reading shared library symbols:\n", - RETURN_MASK_ALL)) - { - so_last = so; - so -> symbols_loaded = 1; - } - } - } - - /* Now add the shared library sections to the section table of the - specified target, if any. */ - if (target) - { - /* Count how many new section_table entries there are. */ - so = NULL; - count = 0; - while ((so = find_solib (so)) != NULL) - { - if (so -> so_name[0]) - { - count += so -> sections_end - so -> sections; - } - } - - if (count) - { - /* Reallocate the target's section table including the new size. */ - if (target -> to_sections) - { - old = target -> to_sections_end - target -> to_sections; - target -> to_sections = (struct section_table *) - xrealloc ((char *)target -> to_sections, - (sizeof (struct section_table)) * (count + old)); - } - else - { - old = 0; - target -> to_sections = (struct section_table *) - xmalloc ((sizeof (struct section_table)) * count); - } - target -> to_sections_end = target -> to_sections + (count + old); - - /* Add these section table entries to the target's table. */ - while ((so = find_solib (so)) != NULL) - { - if (so -> so_name[0]) - { - count = so -> sections_end - so -> sections; - memcpy ((char *) (target -> to_sections + old), - so -> sections, - (sizeof (struct section_table)) * count); - old += count; - } - } - } - } - - /* Calling this once at the end means that we put all the minimal - symbols for commons into the objfile for the last shared library. - Since they are in common, this should not be a problem. If we - delete the objfile with the minimal symbols, we can put all the - symbols into a new objfile (and will on the next call to solib_add). - - An alternate approach would be to create an objfile just for - common minsyms, thus not needing any objfile argument to - solib_add_common_symbols. */ - - if (so_last) - special_symbol_handling (so_last); -} - -/* - -LOCAL FUNCTION - - info_sharedlibrary_command -- code for "info sharedlibrary" - -SYNOPSIS - - static void info_sharedlibrary_command () - -DESCRIPTION - - Walk through the shared library list and print information - about each attached library. -*/ - -static void -info_sharedlibrary_command (ignore, from_tty) - char *ignore; - int from_tty; -{ - register struct so_list *so = NULL; /* link map state variable */ - int header_done = 0; - - if (exec_bfd == NULL) - { - printf ("No exec file.\n"); - return; - } - while ((so = find_solib (so)) != NULL) - { - if (so -> so_name[0]) - { - if (!header_done) - { - printf("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read", - "Shared Object Library"); - header_done++; - } - printf ("%-12s", - local_hex_string_custom ((unsigned long) LM_ADDR (so), - "08l")); - printf ("%-12s", - local_hex_string_custom ((unsigned long) so -> lmend, - "08l")); - printf ("%-12s", so -> symbols_loaded ? "Yes" : "No"); - printf ("%s\n", so -> so_name); - } - } - if (so_list_head == NULL) - { - printf ("No shared libraries loaded at this time.\n"); - } -} - -/* - -GLOBAL FUNCTION - - solib_address -- check to see if an address is in a shared lib - -SYNOPSIS - - int solib_address (CORE_ADDR address) - -DESCRIPTION - - Provides a hook for other gdb routines to discover whether or - not a particular address is within the mapped address space of - a shared library. Any address between the base mapping address - and the first address beyond the end of the last mapping, is - considered to be within the shared library address space, for - our purposes. - - For example, this routine is called at one point to disable - breakpoints which are in shared libraries that are not currently - mapped in. - */ - -int -solib_address (address) - CORE_ADDR address; -{ - register struct so_list *so = 0; /* link map state variable */ - - while ((so = find_solib (so)) != NULL) - { - if (so -> so_name[0]) - { - if ((address >= (CORE_ADDR) LM_ADDR (so)) && - (address < (CORE_ADDR) so -> lmend)) - { - return (1); - } - } - } - return (0); -} - -/* Called by free_all_symtabs */ - -void -clear_solib() -{ - struct so_list *next; - char *bfd_filename; - - while (so_list_head) - { - if (so_list_head -> sections) - { - free ((PTR)so_list_head -> sections); - } - if (so_list_head -> abfd) - { - bfd_filename = bfd_get_filename (so_list_head -> abfd); - bfd_close (so_list_head -> abfd); - } - else - /* This happens for the executable on SVR4. */ - bfd_filename = NULL; - - next = so_list_head -> next; - if (bfd_filename) - free ((PTR)bfd_filename); - free ((PTR)so_list_head); - so_list_head = next; - } - debug_base = 0; -} - -/* - -LOCAL FUNCTION - - disable_break -- remove the "mapping changed" breakpoint - -SYNOPSIS - - static int disable_break () - -DESCRIPTION - - Removes the breakpoint that gets hit when the dynamic linker - completes a mapping change. - -*/ - -static int -disable_break () -{ - int status = 1; - -#ifndef SVR4_SHARED_LIBS - - int in_debugger = 0; - - /* Read the debugger structure from the inferior to retrieve the - address of the breakpoint and the original contents of the - breakpoint address. Remove the breakpoint by writing the original - contents back. */ - - read_memory (debug_addr, (char *) &debug_copy, sizeof (debug_copy)); - - /* Set `in_debugger' to zero now. */ - - write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger)); - -#ifdef OLD_FreeBSD_LD - breakpoint_addr = (CORE_ADDR) debug_copy.ldd_bp_addr; - write_memory (breakpoint_addr, (char *) &debug_copy.ldd_bp_inst, - sizeof (debug_copy.ldd_bp_inst)); -#else - breakpoint_addr = (CORE_ADDR) debug_copy.dd_bpt_addr; - write_memory (breakpoint_addr, (char *) &debug_copy.dd_bpt_shadow, - sizeof (debug_copy.dd_bpt_shadow)); -#endif - -#else /* SVR4_SHARED_LIBS */ - - /* Note that breakpoint address and original contents are in our address - space, so we just need to write the original contents back. */ - - if (memory_remove_breakpoint (breakpoint_addr, shadow_contents) != 0) - { - status = 0; - } - -#endif /* !SVR4_SHARED_LIBS */ - - /* For the SVR4 version, we always know the breakpoint address. For the - SunOS version we don't know it until the above code is executed. - Grumble if we are stopped anywhere besides the breakpoint address. */ - - if (stop_pc != breakpoint_addr) - { - warning ("stopped at unknown breakpoint while handling shared libraries"); - } - - return (status); -} - -/* - -LOCAL FUNCTION - - enable_break -- arrange for dynamic linker to hit breakpoint - -SYNOPSIS - - int enable_break (void) - -DESCRIPTION - - Both the SunOS and the SVR4 dynamic linkers have, as part of their - debugger interface, support for arranging for the inferior to hit - a breakpoint after mapping in the shared libraries. This function - enables that breakpoint. - - For SunOS, there is a special flag location (in_debugger) which we - set to 1. When the dynamic linker sees this flag set, it will set - a breakpoint at a location known only to itself, after saving the - original contents of that place and the breakpoint address itself, - in it's own internal structures. When we resume the inferior, it - will eventually take a SIGTRAP when it runs into the breakpoint. - We handle this (in a different place) by restoring the contents of - the breakpointed location (which is only known after it stops), - chasing around to locate the shared libraries that have been - loaded, then resuming. - - For SVR4, the debugger interface structure contains a member (r_brk) - which is statically initialized at the time the shared library is - built, to the offset of a function (_r_debug_state) which is guaran- - teed to be called once before mapping in a library, and again when - the mapping is complete. At the time we are examining this member, - it contains only the unrelocated offset of the function, so we have - to do our own relocation. Later, when the dynamic linker actually - runs, it relocates r_brk to be the actual address of _r_debug_state(). - - The debugger interface structure also contains an enumeration which - is set to either RT_ADD or RT_DELETE prior to changing the mapping, - depending upon whether or not the library is being mapped or unmapped, - and then set to RT_CONSISTENT after the library is mapped/unmapped. -*/ - -static int -enable_break () -{ - int success = 0; - -#ifndef SVR4_SHARED_LIBS - - int j; - int in_debugger; - - /* Get link_dynamic structure */ - - j = target_read_memory (debug_base, (char *) &dynamic_copy, - sizeof (dynamic_copy)); - if (j) - { - /* unreadable */ - return (0); - } - - /* Calc address of debugger interface structure */ - -#ifdef OLD_FreeBSD_LD - debug_addr = (CORE_ADDR) dynamic_copy.ldd; -#else - debug_addr = (CORE_ADDR) dynamic_copy.d_debug; -#endif - - /* Calc address of `in_debugger' member of debugger interface structure */ - -#ifdef OLD_FreeBSD_LD - flag_addr = debug_addr + (CORE_ADDR) ((char *) &debug_copy.ldd_in_debugger - - (char *) &debug_copy); -#else - flag_addr = debug_addr + (CORE_ADDR) ((char *) &debug_copy.dd_in_debugger - - (char *) &debug_copy); -#endif - - /* Write a value of 1 to this member. */ - - in_debugger = 1; - write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger)); - success = 1; - -#else /* SVR4_SHARED_LIBS */ - -#ifdef BKPT_AT_SYMBOL - - struct minimal_symbol *msymbol; - char **bkpt_namep; - CORE_ADDR bkpt_addr; - - /* Scan through the list of symbols, trying to look up the symbol and - set a breakpoint there. Terminate loop when we/if we succeed. */ - - breakpoint_addr = 0; - for (bkpt_namep = bkpt_names; *bkpt_namep != NULL; bkpt_namep++) - { - msymbol = lookup_minimal_symbol (*bkpt_namep, symfile_objfile); - if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0)) - { - bkpt_addr = SYMBOL_VALUE_ADDRESS (msymbol); - if (target_insert_breakpoint (bkpt_addr, shadow_contents) == 0) - { - breakpoint_addr = bkpt_addr; - success = 1; - break; - } - } - } - -#else /* !BKPT_AT_SYMBOL */ - - struct symtab_and_line sal; - - /* Read the debugger interface structure directly. */ - - read_memory (debug_base, (char *) &debug_copy, sizeof (debug_copy)); - - /* Set breakpoint at the debugger interface stub routine that will - be called just prior to each mapping change and again after the - mapping change is complete. Set up the (nonexistent) handler to - deal with hitting these breakpoints. (FIXME). */ - - warning ("'%s': line %d: missing SVR4 support code", __FILE__, __LINE__); - success = 1; - -#endif /* BKPT_AT_SYMBOL */ - -#endif /* !SVR4_SHARED_LIBS */ - - return (success); -} - -/* - -GLOBAL FUNCTION - - solib_create_inferior_hook -- shared library startup support - -SYNOPSIS - - void solib_create_inferior_hook() - -DESCRIPTION - - When gdb starts up the inferior, it nurses it along (through the - shell) until it is ready to execute it's first instruction. At this - point, this function gets called via expansion of the macro - SOLIB_CREATE_INFERIOR_HOOK. - - For SunOS executables, this first instruction is typically the - one at "_start", or a similar text label, regardless of whether - the executable is statically or dynamically linked. The runtime - startup code takes care of dynamically linking in any shared - libraries, once gdb allows the inferior to continue. - - For SVR4 executables, this first instruction is either the first - instruction in the dynamic linker (for dynamically linked - executables) or the instruction at "start" for statically linked - executables. For dynamically linked executables, the system - first exec's /lib/libc.so.N, which contains the dynamic linker, - and starts it running. The dynamic linker maps in any needed - shared libraries, maps in the actual user executable, and then - jumps to "start" in the user executable. - - For both SunOS shared libraries, and SVR4 shared libraries, we - can arrange to cooperate with the dynamic linker to discover the - names of shared libraries that are dynamically linked, and the - base addresses to which they are linked. - - This function is responsible for discovering those names and - addresses, and saving sufficient information about them to allow - their symbols to be read at a later time. - -FIXME - - Between enable_break() and disable_break(), this code does not - properly handle hitting breakpoints which the user might have - set in the startup code or in the dynamic linker itself. Proper - handling will probably have to wait until the implementation is - changed to use the "breakpoint handler function" method. - - Also, what if child has exit()ed? Must exit loop somehow. - */ - -void -solib_create_inferior_hook() -{ - /* If we are using the BKPT_AT_SYMBOL code, then we don't need the base - yet. In fact, in the case of a SunOS4 executable being run on - Solaris, we can't get it yet. find_solib will get it when it needs - it. */ -#if !(defined (SVR4_SHARED_LIBS) && defined (BKPT_AT_SYMBOL)) - if ((debug_base = locate_base ()) == 0) - { - /* Can't find the symbol or the executable is statically linked. */ - return; - } -#endif - - if (!enable_break ()) - { - warning ("shared library handler failed to enable breakpoint"); - return; - } - - /* Now run the target. It will eventually hit the breakpoint, at - which point all of the libraries will have been mapped in and we - can go groveling around in the dynamic linker structures to find - out what we need to know about them. */ - - clear_proceed_status (); - stop_soon_quietly = 1; - stop_signal = 0; - do - { - target_resume (-1, 0, stop_signal); - wait_for_inferior (); - } - while (stop_signal != SIGTRAP); - stop_soon_quietly = 0; - - /* We are now either at the "mapping complete" breakpoint (or somewhere - else, a condition we aren't prepared to deal with anyway), so adjust - the PC as necessary after a breakpoint, disable the breakpoint, and - add any shared libraries that were mapped in. */ - - if (DECR_PC_AFTER_BREAK) - { - stop_pc -= DECR_PC_AFTER_BREAK; - write_register (PC_REGNUM, stop_pc); - } - - if (!disable_break ()) - { - warning ("shared library handler failed to disable breakpoint"); - } - - solib_add ((char *) 0, 0, (struct target_ops *) 0); -} - -/* - -LOCAL FUNCTION - - special_symbol_handling -- additional shared library symbol handling - -SYNOPSIS - - void special_symbol_handling (struct so_list *so) - -DESCRIPTION - - Once the symbols from a shared object have been loaded in the usual - way, we are called to do any system specific symbol handling that - is needed. - - For Suns, this consists of grunging around in the dynamic linkers - structures to find symbol definitions for "common" symbols and - adding them to the minimal symbol table for the corresponding - objfile. - -*/ - -static void -special_symbol_handling (so) -struct so_list *so; -{ -#ifndef SVR4_SHARED_LIBS - int j; - - if (debug_addr == 0) - { - /* Get link_dynamic structure */ - - j = target_read_memory (debug_base, (char *) &dynamic_copy, - sizeof (dynamic_copy)); - if (j) - { - /* unreadable */ - return; - } - - /* Calc address of debugger interface structure */ - /* FIXME, this needs work for cross-debugging of core files - (byteorder, size, alignment, etc). */ - -#ifdef OLD_FreeBSD_LD - debug_addr = (CORE_ADDR) dynamic_copy.ldd; -#else - debug_addr = (CORE_ADDR) dynamic_copy.d_debug; -#endif - } - - /* Read the debugger structure from the inferior, just to make sure - we have a current copy. */ - - j = target_read_memory (debug_addr, (char *) &debug_copy, - sizeof (debug_copy)); - if (j) - return; /* unreadable */ - - /* Get common symbol definitions for the loaded object. */ - -#ifdef OLD_FreeBSD_LD - if (debug_copy.ldd_cp) - { - solib_add_common_symbols (debug_copy.ldd_cp, so -> objfile); - } -#else - if (debug_copy.dd_cc) - { - solib_add_common_symbols (debug_copy.dd_cc, so -> objfile); - } -#endif - -#endif /* !SVR4_SHARED_LIBS */ -} - - -/* - -LOCAL FUNCTION - - sharedlibrary_command -- handle command to explicitly add library - -SYNOPSIS - - static void sharedlibrary_command (char *args, int from_tty) - -DESCRIPTION - -*/ - -static void -sharedlibrary_command (args, from_tty) -char *args; -int from_tty; -{ - dont_repeat (); - solib_add (args, from_tty, (struct target_ops *) 0); -} - -void -_initialize_solib() -{ - - add_com ("sharedlibrary", class_files, sharedlibrary_command, - "Load shared object library symbols for files matching REGEXP."); - add_info ("sharedlibrary", info_sharedlibrary_command, - "Status of loaded shared object libraries."); -} diff --git a/gnu/usr.bin/gdb/gdb/m2-exp.tab.c b/gnu/usr.bin/gdb/gdb/m2-exp.tab.c deleted file mode 100644 index 53b1385..0000000 --- a/gnu/usr.bin/gdb/gdb/m2-exp.tab.c +++ /dev/null @@ -1,1991 +0,0 @@ -#ifndef lint -static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; -#endif -#define YYBYACC 1 -#define YYMAJOR 1 -#define YYMINOR 9 -#define yyclearin (yychar=(-1)) -#define yyerrok (yyerrflag=0) -#define YYRECOVERING (yyerrflag!=0) -#define yyparse m2_parse -#define yylex m2_lex -#define yyerror m2_error -#define yychar m2_char -#define yyval m2_val -#define yylval m2_lval -#define yydebug m2_debug -#define yynerrs m2_nerrs -#define yyerrflag m2_errflag -#define yyss m2_ss -#define yyssp m2_ssp -#define yyvs m2_vs -#define yyvsp m2_vsp -#define yylhs m2_lhs -#define yylen m2_len -#define yydefred m2_defred -#define yydgoto m2_dgoto -#define yysindex m2_sindex -#define yyrindex m2_rindex -#define yygindex m2_gindex -#define yytable m2_table -#define yycheck m2_check -#define yyname m2_name -#define yyrule m2_rule -#define YYPREFIX "m2_" -#line 40 "./m2-exp.y" - -#include "defs.h" -#include "expression.h" -#include "language.h" -#include "value.h" -#include "parser-defs.h" -#include "m2-lang.h" - -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), - as well as gratuitiously global symbol names, so we can have multiple - yacc generated parsers in gdb. Note that these are only the variables - produced by yacc. If other parser generators (bison, byacc, etc) produce - additional global names that conflict at link time, then those parser - generators need to be fixed instead of adding those names to this list. */ - -#define yymaxdepth m2_maxdepth -#define yyparse m2_parse -#define yylex m2_lex -#define yyerror m2_error -#define yylval m2_lval -#define yychar m2_char -#define yydebug m2_debug -#define yypact m2_pact -#define yyr1 m2_r1 -#define yyr2 m2_r2 -#define yydef m2_def -#define yychk m2_chk -#define yypgo m2_pgo -#define yyact m2_act -#define yyexca m2_exca -#define yyerrflag m2_errflag -#define yynerrs m2_nerrs -#define yyps m2_ps -#define yypv m2_pv -#define yys m2_s -#define yy_yys m2_yys -#define yystate m2_state -#define yytmp m2_tmp -#define yyv m2_v -#define yy_yyv m2_yyv -#define yyval m2_val -#define yylloc m2_lloc -#define yyreds m2_reds /* With YYDEBUG defined */ -#define yytoks m2_toks /* With YYDEBUG defined */ - -#ifndef YYDEBUG -#define YYDEBUG 0 /* Default to no yydebug support */ -#endif - -int -yyparse PARAMS ((void)); - -static int -yylex PARAMS ((void)); - -void -yyerror PARAMS ((char *)); - -#if 0 -static char * -make_qualname PARAMS ((char *, char *)); -#endif - -static int -parse_number PARAMS ((int)); - -/* The sign of the number being parsed. */ -static int number_sign = 1; - -/* The block that the module specified by the qualifer on an identifer is - contained in, */ -#if 0 -static struct block *modblock=0; -#endif - -#line 121 "./m2-exp.y" -typedef union - { - LONGEST lval; - unsigned LONGEST ulval; - double dval; - struct symbol *sym; - struct type *tval; - struct stoken sval; - int voidval; - struct block *bval; - enum exp_opcode opcode; - struct internalvar *ivar; - - struct type **tvec; - int *ivec; - } YYSTYPE; -#line 129 "y.tab.c" -#define INT 257 -#define HEX 258 -#define ERROR 259 -#define UINT 260 -#define M2_TRUE 261 -#define M2_FALSE 262 -#define CHAR 263 -#define FLOAT 264 -#define STRING 265 -#define NAME 266 -#define BLOCKNAME 267 -#define IDENT 268 -#define VARNAME 269 -#define TYPENAME 270 -#define SIZE 271 -#define CAP 272 -#define ORD 273 -#define HIGH 274 -#define ABS 275 -#define MIN_FUNC 276 -#define MAX_FUNC 277 -#define FLOAT_FUNC 278 -#define VAL 279 -#define CHR 280 -#define ODD 281 -#define TRUNC 282 -#define INC 283 -#define DEC 284 -#define INCL 285 -#define EXCL 286 -#define COLONCOLON 287 -#define LAST 288 -#define REGNAME 289 -#define INTERNAL_VAR 290 -#define ABOVE_COMMA 291 -#define ASSIGN 292 -#define LEQ 293 -#define GEQ 294 -#define NOTEQUAL 295 -#define IN 296 -#define OROR 297 -#define LOGICAL_AND 298 -#define DIV 299 -#define MOD 300 -#define UNARY 301 -#define DOT 302 -#define NOT 303 -#define QID 304 -#define YYERRCODE 256 -short m2_lhs[] = { -1, - 0, 0, 2, 1, 8, 1, 1, 1, 9, 9, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 3, 3, 12, 1, 13, 1, 10, 10, 10, - 11, 11, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 6, 7, 7, 4, 4, 4, 4, - 5, -}; -short m2_len[] = { 2, - 1, 1, 1, 2, 0, 3, 2, 2, 1, 1, - 4, 4, 4, 4, 4, 4, 4, 6, 4, 4, - 4, 2, 4, 6, 4, 6, 3, 1, 3, 6, - 6, 3, 4, 0, 5, 0, 5, 0, 1, 3, - 1, 3, 4, 4, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 1, 1, 1, 3, 1, 1, 3, 1, - 1, -}; -short m2_defred[] = { 0, - 65, 66, 63, 64, 67, 68, 73, 80, 75, 81, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 70, 71, 78, 0, - 5, 0, 9, 10, 0, 0, 0, 2, 28, 69, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 4, 0, 34, 36, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 45, 0, 0, 32, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 29, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, - 79, 76, 72, 11, 12, 14, 13, 15, 16, 17, - 0, 19, 20, 21, 0, 23, 0, 25, 0, 0, - 0, 0, 0, 0, 0, 44, 33, 0, 0, 0, - 0, 0, 0, 35, 37, 18, 24, 26, 30, 31, - 0, -}; -short m2_dgoto[] = { 36, - 66, 38, 39, 40, 47, 42, 43, 64, 44, 68, - 164, 137, 138, -}; -short m2_sindex[] = { 1597, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1779, -27, -21, -15, -10, -6, -3, -2, 18, 20, - 24, 31, 38, 39, 59, 77, 0, 0, 0, 1597, - 0, 1597, 0, 0, 1597, 0, 1670, 0, 0, 0, - -26, -256, 0, 1597, 1597, -24, -26, 1597, 1597, 1597, - 1597, -218, -218, 1597, -218, 1597, 1597, 1597, 1597, 1597, - 1597, 1597, -24, 1597, 939, 1670, -37, -17, 1597, 1597, - 1597, 1597, 1597, 1597, 1597, 1597, -118, 1597, 1597, 1597, - 1597, 1597, 1597, 1597, 1597, 1597, 0, -186, 0, 0, - 1597, 1597, -259, -24, -30, 967, 1002, 1044, 1079, 78, - 83, 1160, 74, 1268, 1323, 1351, 866, 894, 1183, 1404, - -24, 0, 1597, 1597, 0, 1727, -25, -25, -25, -25, - -25, -25, -25, 1597, 0, 8, 80, 192, 117, 49, - 49, -24, -24, -24, -24, 0, 1597, 1597, 1449, -11, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1597, 0, 0, 0, 1597, 0, 1597, 0, 1597, 1597, - -24, 1670, 1670, -44, -20, 0, 0, 1484, 1512, 1547, - 1617, 1628, 1597, 0, 0, 0, 0, 0, 0, 0, - 1670, -}; -short m2_rindex[] = { 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, -9, 0, 121, 0, 0, 0, - 135, 0, 1, 0, 0, 12, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 40, 0, 0, -35, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, -9, 0, 68, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 106, 0, 0, 0, 0, 98, 568, 575, 598, 653, - 677, 779, 838, -9, 0, 0, 561, 539, 502, 465, - 489, 134, 145, 220, 411, 0, 0, -12, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 435, -18, -42, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -16, -}; -short m2_gindex[] = { 0, - 2066, 0, 61, 0, 341, 0, 0, 0, 0, -88, - 0, 0, 0, -}; -#define YYTABLESIZE 2239 -short m2_table[] = { 173, - 77, 41, 91, 140, 124, 39, 141, 142, 39, 91, - 143, 22, 48, 91, 90, 90, 83, 81, 49, 82, - 175, 84, 40, 114, 50, 40, 114, 42, 38, 51, - 93, 38, 114, 52, 38, 77, 53, 54, 80, 7, - 77, 77, 77, 77, 77, 77, 22, 77, 174, 165, - 41, 10, 22, 22, 22, 22, 22, 55, 22, 56, - 77, 77, 77, 57, 77, 89, 89, 8, 87, 87, - 58, 22, 22, 22, 7, 22, 42, 59, 60, 136, - 7, 7, 7, 7, 7, 92, 7, 113, 90, 39, - 83, 77, 92, 77, 77, 84, 92, 62, 61, 7, - 7, 7, 8, 7, 22, 6, 40, 115, 8, 8, - 8, 8, 8, 167, 8, 38, 62, 151, 148, 90, - 1, 83, 81, 149, 82, 77, 84, 8, 8, 8, - 92, 8, 7, 47, 3, 0, 22, 125, 62, 89, - 6, 62, 87, 80, 48, 0, 6, 6, 6, 6, - 6, 10, 6, 0, 0, 0, 90, 0, 83, 81, - 8, 82, 0, 84, 7, 6, 6, 6, 47, 6, - 89, 0, 0, 87, 47, 47, 47, 47, 47, 48, - 47, 0, 0, 0, 0, 48, 48, 48, 48, 48, - 62, 48, 8, 47, 47, 47, 0, 47, 6, 0, - 0, 0, 0, 0, 48, 48, 48, 89, 48, 0, - 87, 0, 0, 0, 0, 0, 0, 0, 0, 49, - 0, 0, 62, 0, 0, 0, 47, 0, 0, 0, - 6, 90, 0, 83, 81, 0, 82, 48, 84, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 49, 80, 0, 0, 47, 0, - 49, 49, 49, 49, 49, 0, 49, 0, 0, 48, - 0, 78, 79, 85, 86, 0, 88, 88, 0, 49, - 49, 49, 89, 49, 0, 87, 0, 74, 0, 0, - 0, 0, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 0, 77, 22, 22, 22, 22, 22, 22, 22, - 22, 22, 49, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 41, 0, 0, 0, 49, 0, 0, 85, 86, 0, - 88, 0, 0, 0, 0, 0, 0, 0, 0, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, - 0, 0, 0, 0, 0, 67, 0, 79, 85, 86, - 0, 88, 0, 0, 0, 95, 0, 0, 0, 0, - 0, 0, 100, 101, 0, 103, 0, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 0, 0, 0, 0, - 50, 0, 0, 0, 0, 85, 86, 126, 88, 0, - 0, 0, 0, 0, 0, 47, 47, 47, 47, 47, - 47, 47, 47, 47, 43, 0, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 50, 0, 0, 0, 0, - 0, 50, 50, 50, 50, 50, 0, 50, 0, 0, - 0, 0, 0, 0, 51, 0, 0, 0, 0, 43, - 50, 50, 50, 0, 50, 43, 43, 43, 43, 43, - 0, 43, 0, 0, 0, 0, 0, 0, 52, 0, - 85, 86, 0, 88, 43, 43, 43, 0, 43, 51, - 0, 46, 0, 50, 0, 51, 0, 51, 51, 51, - 0, 49, 49, 49, 49, 49, 49, 49, 49, 49, - 0, 0, 0, 52, 51, 51, 51, 43, 51, 52, - 0, 52, 52, 52, 0, 50, 46, 0, 60, 0, - 0, 0, 46, 0, 0, 46, 0, 0, 52, 52, - 52, 0, 52, 0, 0, 0, 0, 51, 0, 43, - 61, 46, 46, 46, 0, 46, 0, 58, 0, 0, - 0, 0, 0, 60, 59, 0, 0, 0, 0, 60, - 0, 52, 60, 0, 0, 0, 0, 0, 0, 51, - 0, 0, 0, 0, 46, 61, 0, 56, 60, 60, - 60, 61, 58, 0, 61, 0, 0, 0, 58, 59, - 0, 58, 0, 52, 0, 59, 0, 0, 59, 0, - 61, 61, 61, 0, 0, 0, 46, 58, 58, 58, - 0, 60, 56, 0, 59, 59, 59, 0, 56, 0, - 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 57, 61, 0, 0, 0, 56, 56, 56, - 58, 0, 0, 60, 0, 0, 0, 59, 0, 0, - 0, 0, 0, 0, 0, 0, 53, 0, 0, 0, - 0, 0, 0, 0, 0, 61, 0, 57, 0, 0, - 56, 0, 58, 57, 0, 0, 57, 0, 0, 59, - 0, 0, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 53, 57, 57, 57, 0, 0, 53, 0, 0, - 53, 0, 56, 0, 0, 0, 43, 43, 43, 43, - 43, 43, 43, 43, 43, 0, 53, 53, 53, 0, - 0, 0, 0, 0, 0, 57, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 51, 51, 51, 51, - 51, 51, 51, 0, 0, 0, 0, 0, 0, 53, - 0, 0, 0, 0, 0, 0, 0, 57, 54, 0, - 52, 52, 52, 52, 52, 52, 52, 0, 0, 0, - 0, 0, 0, 46, 46, 46, 46, 46, 46, 46, - 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 54, 0, 0, 0, 0, 0, 54, - 0, 0, 54, 0, 0, 0, 0, 0, 0, 0, - 60, 60, 60, 60, 60, 60, 60, 55, 54, 54, - 54, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 61, 61, 61, 61, 61, 61, 0, 58, - 58, 58, 58, 58, 0, 0, 59, 59, 59, 59, - 59, 54, 55, 0, 0, 0, 0, 0, 55, 0, - 0, 55, 0, 0, 0, 0, 0, 0, 0, 56, - 56, 56, 56, 56, 0, 0, 0, 55, 55, 55, - 76, 0, 0, 54, 0, 90, 156, 83, 81, 155, - 82, 0, 84, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 70, 74, 71, 76, 80, - 55, 0, 0, 90, 158, 83, 81, 157, 82, 0, - 84, 0, 0, 0, 57, 57, 57, 57, 57, 0, - 0, 0, 0, 70, 74, 71, 89, 80, 0, 87, - 0, 0, 55, 0, 0, 0, 0, 0, 53, 53, - 53, 53, 53, 76, 0, 0, 0, 0, 90, 112, - 83, 81, 0, 82, 89, 84, 0, 87, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 70, 74, - 71, 76, 80, 0, 0, 0, 90, 144, 83, 81, - 0, 82, 0, 84, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 70, 74, 71, 89, - 80, 0, 87, 0, 0, 0, 76, 0, 0, 0, - 0, 90, 145, 83, 81, 0, 82, 0, 84, 0, - 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, - 87, 70, 74, 71, 0, 80, 0, 0, 0, 0, - 54, 54, 54, 54, 54, 0, 0, 0, 76, 0, - 0, 0, 0, 90, 146, 83, 81, 0, 82, 0, - 84, 0, 89, 0, 0, 87, 0, 0, 0, 0, - 0, 0, 0, 70, 74, 71, 0, 80, 0, 0, - 0, 0, 0, 76, 0, 0, 0, 0, 90, 147, - 83, 81, 0, 82, 0, 84, 0, 0, 0, 55, - 55, 55, 55, 55, 89, 0, 0, 87, 70, 74, - 71, 0, 80, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 69, 72, 73, - 75, 77, 78, 79, 85, 86, 0, 88, 0, 89, - 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 69, 72, 73, 75, 77, - 78, 79, 85, 86, 76, 88, 0, 0, 0, 90, - 150, 83, 81, 0, 82, 0, 84, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 76, 0, 70, - 74, 71, 90, 80, 83, 81, 159, 82, 0, 84, - 69, 72, 73, 75, 77, 78, 79, 85, 86, 0, - 88, 0, 70, 74, 71, 0, 80, 0, 0, 0, - 89, 0, 0, 87, 0, 0, 0, 0, 69, 72, - 73, 75, 77, 78, 79, 85, 86, 0, 88, 0, - 0, 0, 0, 89, 0, 0, 87, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 69, 72, 73, 75, 77, 78, 79, - 85, 86, 76, 88, 0, 0, 0, 90, 152, 83, - 81, 0, 82, 0, 84, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 70, 74, 71, - 0, 80, 0, 0, 0, 69, 72, 73, 75, 77, - 78, 79, 85, 86, 0, 88, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 76, 89, 0, - 0, 87, 90, 153, 83, 81, 0, 82, 0, 84, - 69, 72, 73, 75, 77, 78, 79, 85, 86, 0, - 88, 0, 70, 74, 71, 76, 80, 0, 0, 0, - 90, 154, 83, 81, 0, 82, 0, 84, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 70, 74, 71, 89, 80, 0, 87, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 76, 0, - 0, 89, 0, 90, 87, 83, 81, 160, 82, 0, - 84, 69, 72, 73, 75, 77, 78, 79, 85, 86, - 0, 88, 0, 70, 74, 71, 0, 80, 0, 0, - 0, 0, 0, 0, 69, 72, 73, 75, 77, 78, - 79, 85, 86, 76, 88, 0, 0, 0, 90, 166, - 83, 81, 0, 82, 89, 84, 0, 87, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 70, 74, - 71, 0, 80, 0, 0, 0, 0, 0, 76, 0, - 0, 0, 0, 90, 176, 83, 81, 0, 82, 0, - 84, 0, 0, 0, 0, 0, 0, 0, 0, 89, - 0, 0, 87, 70, 74, 71, 76, 80, 0, 0, - 0, 90, 177, 83, 81, 0, 82, 0, 84, 69, - 72, 73, 75, 77, 78, 79, 85, 86, 0, 88, - 0, 70, 74, 71, 89, 80, 0, 87, 0, 0, - 0, 76, 0, 0, 0, 0, 90, 178, 83, 81, - 0, 82, 0, 84, 0, 0, 0, 0, 0, 0, - 0, 0, 89, 0, 0, 87, 70, 74, 71, 0, - 80, 0, 0, 0, 69, 72, 73, 75, 77, 78, - 79, 85, 86, 0, 88, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 32, 89, 0, 30, - 87, 31, 69, 72, 73, 75, 77, 78, 79, 85, - 86, 76, 88, 0, 0, 0, 90, 179, 83, 81, - 0, 82, 76, 84, 0, 0, 0, 90, 180, 83, - 81, 0, 82, 0, 84, 0, 70, 74, 71, 0, - 80, 0, 0, 0, 0, 0, 0, 70, 74, 71, - 0, 80, 0, 0, 0, 69, 72, 73, 75, 77, - 78, 79, 85, 86, 76, 88, 0, 89, 0, 90, - 87, 83, 81, 0, 82, 0, 84, 0, 89, 35, - 0, 87, 34, 0, 0, 0, 0, 0, 0, 70, - 74, 71, 0, 80, 0, 0, 0, 0, 0, 0, - 69, 72, 73, 75, 77, 78, 79, 85, 86, 0, - 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 89, 76, 0, 87, 0, 0, 90, 0, 83, 81, - 0, 82, 0, 84, 0, 69, 72, 73, 75, 77, - 78, 79, 85, 86, 0, 88, 70, 74, 71, 0, - 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 69, 72, 73, 75, 77, 78, 79, - 85, 86, 0, 88, 0, 0, 0, 89, 45, 0, - 87, 30, 0, 31, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 69, 72, - 73, 75, 77, 78, 79, 85, 86, 0, 88, 0, - 0, 0, 0, 1, 0, 0, 2, 3, 4, 5, - 6, 7, 8, 9, 0, 0, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 0, 27, 28, 29, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, - 0, 35, 0, 0, 34, 0, 0, 0, 69, 72, - 73, 75, 77, 78, 79, 85, 86, 0, 88, 69, - 72, 73, 75, 77, 78, 79, 85, 86, 0, 88, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 69, 72, 73, 75, 77, 78, 79, 85, 86, - 0, 88, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 72, - 73, 75, 77, 78, 79, 85, 86, 0, 88, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 2, 3, - 4, 5, 6, 7, 8, 9, 0, 0, 10, 11, - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, - 22, 23, 24, 25, 26, 37, 27, 28, 29, 0, - 0, 0, 0, 0, 0, 0, 46, 0, 0, 0, - 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 63, 0, 65, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 94, - 65, 0, 0, 96, 97, 98, 99, 0, 0, 102, - 0, 104, 105, 106, 107, 108, 109, 110, 0, 111, - 0, 0, 0, 0, 116, 117, 118, 119, 120, 121, - 122, 123, 0, 127, 128, 129, 130, 131, 132, 133, - 134, 135, 0, 0, 0, 0, 139, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 161, 162, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 163, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 168, 0, 0, 0, - 169, 0, 170, 0, 171, 172, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 181, -}; -short m2_check[] = { 44, - 0, 44, 40, 92, 123, 41, 266, 267, 44, 40, - 41, 0, 40, 40, 40, 40, 42, 43, 40, 45, - 41, 47, 41, 44, 40, 44, 44, 44, 41, 40, - 287, 44, 44, 40, 44, 35, 40, 40, 64, 0, - 40, 41, 42, 43, 44, 45, 35, 47, 93, 138, - 93, 270, 41, 42, 43, 44, 45, 40, 47, 40, - 60, 61, 62, 40, 64, 91, 91, 0, 94, 94, - 40, 60, 61, 62, 35, 64, 93, 40, 40, 266, - 41, 42, 43, 44, 45, 123, 47, 125, 40, 125, - 42, 91, 123, 93, 94, 47, 123, 0, 40, 60, - 61, 62, 35, 64, 93, 0, 125, 125, 41, 42, - 43, 44, 45, 125, 47, 125, 40, 44, 41, 40, - 0, 42, 43, 41, 45, 125, 47, 60, 61, 62, - 123, 64, 93, 0, 0, -1, 125, 77, 41, 91, - 35, 44, 94, 64, 0, -1, 41, 42, 43, 44, - 45, 270, 47, -1, -1, -1, 40, -1, 42, 43, - 93, 45, -1, 47, 125, 60, 61, 62, 35, 64, - 91, -1, -1, 94, 41, 42, 43, 44, 45, 35, - 47, -1, -1, -1, -1, 41, 42, 43, 44, 45, - 93, 47, 125, 60, 61, 62, -1, 64, 93, -1, - -1, -1, -1, -1, 60, 61, 62, 91, 64, -1, - 94, -1, -1, -1, -1, -1, -1, -1, -1, 0, - -1, -1, 125, -1, -1, -1, 93, -1, -1, -1, - 125, 40, -1, 42, 43, -1, 45, 93, 47, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 35, 64, -1, -1, 125, -1, - 41, 42, 43, 44, 45, -1, 47, -1, -1, 125, - -1, 297, 298, 299, 300, -1, 302, 302, -1, 60, - 61, 62, 91, 64, -1, 94, -1, 287, -1, -1, - -1, -1, 292, 293, 294, 295, 296, 297, 298, 299, - 300, -1, 302, 292, 293, 294, 295, 296, 297, 298, - 299, 300, 93, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 292, 293, 294, 295, 296, 297, 298, 299, 300, - 0, -1, -1, -1, 125, -1, -1, 299, 300, -1, - 302, -1, -1, -1, -1, -1, -1, -1, -1, 292, - 293, 294, 295, 296, 297, 298, 299, 300, -1, -1, - -1, -1, -1, -1, -1, 35, -1, 298, 299, 300, - -1, 302, -1, -1, -1, 45, -1, -1, -1, -1, - -1, -1, 52, 53, -1, 55, -1, 292, 293, 294, - 295, 296, 297, 298, 299, 300, -1, -1, -1, -1, - 0, -1, -1, -1, -1, 299, 300, 77, 302, -1, - -1, -1, -1, -1, -1, 292, 293, 294, 295, 296, - 297, 298, 299, 300, 0, -1, 292, 293, 294, 295, - 296, 297, 298, 299, 300, 35, -1, -1, -1, -1, - -1, 41, 42, 43, 44, 45, -1, 47, -1, -1, - -1, -1, -1, -1, 0, -1, -1, -1, -1, 35, - 60, 61, 62, -1, 64, 41, 42, 43, 44, 45, - -1, 47, -1, -1, -1, -1, -1, -1, 0, -1, - 299, 300, -1, 302, 60, 61, 62, -1, 64, 35, - -1, 0, -1, 93, -1, 41, -1, 43, 44, 45, - -1, 292, 293, 294, 295, 296, 297, 298, 299, 300, - -1, -1, -1, 35, 60, 61, 62, 93, 64, 41, - -1, 43, 44, 45, -1, 125, 35, -1, 0, -1, - -1, -1, 41, -1, -1, 44, -1, -1, 60, 61, - 62, -1, 64, -1, -1, -1, -1, 93, -1, 125, - 0, 60, 61, 62, -1, 64, -1, 0, -1, -1, - -1, -1, -1, 35, 0, -1, -1, -1, -1, 41, - -1, 93, 44, -1, -1, -1, -1, -1, -1, 125, - -1, -1, -1, -1, 93, 35, -1, 0, 60, 61, - 62, 41, 35, -1, 44, -1, -1, -1, 41, 35, - -1, 44, -1, 125, -1, 41, -1, -1, 44, -1, - 60, 61, 62, -1, -1, -1, 125, 60, 61, 62, - -1, 93, 35, -1, 60, 61, 62, -1, 41, -1, - -1, 44, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 0, 93, -1, -1, -1, 60, 61, 62, - 93, -1, -1, 125, -1, -1, -1, 93, -1, -1, - -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, - -1, -1, -1, -1, -1, 125, -1, 35, -1, -1, - 93, -1, 125, 41, -1, -1, 44, -1, -1, 125, - -1, -1, 292, 293, 294, 295, 296, 297, 298, 299, - 300, 35, 60, 61, 62, -1, -1, 41, -1, -1, - 44, -1, 125, -1, -1, -1, 292, 293, 294, 295, - 296, 297, 298, 299, 300, -1, 60, 61, 62, -1, - -1, -1, -1, -1, -1, 93, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 292, 293, 294, 295, - 296, 297, 298, -1, -1, -1, -1, -1, -1, 93, - -1, -1, -1, -1, -1, -1, -1, 125, 0, -1, - 292, 293, 294, 295, 296, 297, 298, -1, -1, -1, - -1, -1, -1, 292, 293, 294, 295, 296, 297, 298, - -1, 125, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 35, -1, -1, -1, -1, -1, 41, - -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, - 292, 293, 294, 295, 296, 297, 298, 0, 60, 61, - 62, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 292, 293, 294, 295, 296, 297, -1, 292, - 293, 294, 295, 296, -1, -1, 292, 293, 294, 295, - 296, 93, 35, -1, -1, -1, -1, -1, 41, -1, - -1, 44, -1, -1, -1, -1, -1, -1, -1, 292, - 293, 294, 295, 296, -1, -1, -1, 60, 61, 62, - 35, -1, -1, 125, -1, 40, 41, 42, 43, 44, - 45, -1, 47, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 60, 61, 62, 35, 64, - 93, -1, -1, 40, 41, 42, 43, 44, 45, -1, - 47, -1, -1, -1, 292, 293, 294, 295, 296, -1, - -1, -1, -1, 60, 61, 62, 91, 64, -1, 94, - -1, -1, 125, -1, -1, -1, -1, -1, 292, 293, - 294, 295, 296, 35, -1, -1, -1, -1, 40, 41, - 42, 43, -1, 45, 91, 47, -1, 94, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 60, 61, - 62, 35, 64, -1, -1, -1, 40, 41, 42, 43, - -1, 45, -1, 47, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 60, 61, 62, 91, - 64, -1, 94, -1, -1, -1, 35, -1, -1, -1, - -1, 40, 41, 42, 43, -1, 45, -1, 47, -1, - -1, -1, -1, -1, -1, -1, -1, 91, -1, -1, - 94, 60, 61, 62, -1, 64, -1, -1, -1, -1, - 292, 293, 294, 295, 296, -1, -1, -1, 35, -1, - -1, -1, -1, 40, 41, 42, 43, -1, 45, -1, - 47, -1, 91, -1, -1, 94, -1, -1, -1, -1, - -1, -1, -1, 60, 61, 62, -1, 64, -1, -1, - -1, -1, -1, 35, -1, -1, -1, -1, 40, 41, - 42, 43, -1, 45, -1, 47, -1, -1, -1, 292, - 293, 294, 295, 296, 91, -1, -1, 94, 60, 61, - 62, -1, 64, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 292, 293, 294, - 295, 296, 297, 298, 299, 300, -1, 302, -1, 91, - -1, -1, 94, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 292, 293, 294, 295, 296, - 297, 298, 299, 300, 35, 302, -1, -1, -1, 40, - 41, 42, 43, -1, 45, -1, 47, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 35, -1, 60, - 61, 62, 40, 64, 42, 43, 44, 45, -1, 47, - 292, 293, 294, 295, 296, 297, 298, 299, 300, -1, - 302, -1, 60, 61, 62, -1, 64, -1, -1, -1, - 91, -1, -1, 94, -1, -1, -1, -1, 292, 293, - 294, 295, 296, 297, 298, 299, 300, -1, 302, -1, - -1, -1, -1, 91, -1, -1, 94, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 292, 293, 294, 295, 296, 297, 298, - 299, 300, 35, 302, -1, -1, -1, 40, 41, 42, - 43, -1, 45, -1, 47, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 60, 61, 62, - -1, 64, -1, -1, -1, 292, 293, 294, 295, 296, - 297, 298, 299, 300, -1, 302, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 35, 91, -1, - -1, 94, 40, 41, 42, 43, -1, 45, -1, 47, - 292, 293, 294, 295, 296, 297, 298, 299, 300, -1, - 302, -1, 60, 61, 62, 35, 64, -1, -1, -1, - 40, 41, 42, 43, -1, 45, -1, 47, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 60, 61, 62, 91, 64, -1, 94, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 35, -1, - -1, 91, -1, 40, 94, 42, 43, 44, 45, -1, - 47, 292, 293, 294, 295, 296, 297, 298, 299, 300, - -1, 302, -1, 60, 61, 62, -1, 64, -1, -1, - -1, -1, -1, -1, 292, 293, 294, 295, 296, 297, - 298, 299, 300, 35, 302, -1, -1, -1, 40, 41, - 42, 43, -1, 45, 91, 47, -1, 94, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 60, 61, - 62, -1, 64, -1, -1, -1, -1, -1, 35, -1, - -1, -1, -1, 40, 41, 42, 43, -1, 45, -1, - 47, -1, -1, -1, -1, -1, -1, -1, -1, 91, - -1, -1, 94, 60, 61, 62, 35, 64, -1, -1, - -1, 40, 41, 42, 43, -1, 45, -1, 47, 292, - 293, 294, 295, 296, 297, 298, 299, 300, -1, 302, - -1, 60, 61, 62, 91, 64, -1, 94, -1, -1, - -1, 35, -1, -1, -1, -1, 40, 41, 42, 43, - -1, 45, -1, 47, -1, -1, -1, -1, -1, -1, - -1, -1, 91, -1, -1, 94, 60, 61, 62, -1, - 64, -1, -1, -1, 292, 293, 294, 295, 296, 297, - 298, 299, 300, -1, 302, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 40, 91, -1, 43, - 94, 45, 292, 293, 294, 295, 296, 297, 298, 299, - 300, 35, 302, -1, -1, -1, 40, 41, 42, 43, - -1, 45, 35, 47, -1, -1, -1, 40, 41, 42, - 43, -1, 45, -1, 47, -1, 60, 61, 62, -1, - 64, -1, -1, -1, -1, -1, -1, 60, 61, 62, - -1, 64, -1, -1, -1, 292, 293, 294, 295, 296, - 297, 298, 299, 300, 35, 302, -1, 91, -1, 40, - 94, 42, 43, -1, 45, -1, 47, -1, 91, 123, - -1, 94, 126, -1, -1, -1, -1, -1, -1, 60, - 61, 62, -1, 64, -1, -1, -1, -1, -1, -1, - 292, 293, 294, 295, 296, 297, 298, 299, 300, -1, - 302, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 91, 35, -1, 94, -1, -1, 40, -1, 42, 43, - -1, 45, -1, 47, -1, 292, 293, 294, 295, 296, - 297, 298, 299, 300, -1, 302, 60, 61, 62, -1, - 64, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 292, 293, 294, 295, 296, 297, 298, - 299, 300, -1, 302, -1, -1, -1, 91, 40, -1, - 94, 43, -1, 45, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 292, 293, - 294, 295, 296, 297, 298, 299, 300, -1, 302, -1, - -1, -1, -1, 257, -1, -1, 260, 261, 262, 263, - 264, 265, 266, 267, -1, -1, 270, 271, 272, 273, - 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, - 284, 285, 286, -1, 288, 289, 290, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 303, - -1, 123, -1, -1, 126, -1, -1, -1, 292, 293, - 294, 295, 296, 297, 298, 299, 300, -1, 302, 292, - 293, 294, 295, 296, 297, 298, 299, 300, -1, 302, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 292, 293, 294, 295, 296, 297, 298, 299, 300, - -1, 302, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 293, - 294, 295, 296, 297, 298, 299, 300, -1, 302, -1, - -1, -1, -1, -1, -1, 257, -1, -1, 260, 261, - 262, 263, 264, 265, 266, 267, -1, -1, 270, 271, - 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, - 282, 283, 284, 285, 286, 0, 288, 289, 290, -1, - -1, -1, -1, -1, -1, -1, 11, -1, -1, -1, - -1, 303, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 30, -1, 32, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 44, - 45, -1, -1, 48, 49, 50, 51, -1, -1, 54, - -1, 56, 57, 58, 59, 60, 61, 62, -1, 64, - -1, -1, -1, -1, 69, 70, 71, 72, 73, 74, - 75, 76, -1, 78, 79, 80, 81, 82, 83, 84, - 85, 86, -1, -1, -1, -1, 91, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 113, 114, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 137, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 151, -1, -1, -1, - 155, -1, 157, -1, 159, 160, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 173, -}; -#define YYFINAL 36 -#ifndef YYDEBUG -#define YYDEBUG 0 -#endif -#define YYMAXTOKEN 304 -#if YYDEBUG -char *m2_name[] = { -"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,"'#'",0,0,"'&'",0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0, -0,0,0,0,"'<'","'='","'>'",0,"'@'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,"'['",0,"']'","'^'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,"'{'",0,"'}'","'~'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"INT","HEX","ERROR","UINT","M2_TRUE", -"M2_FALSE","CHAR","FLOAT","STRING","NAME","BLOCKNAME","IDENT","VARNAME", -"TYPENAME","SIZE","CAP","ORD","HIGH","ABS","MIN_FUNC","MAX_FUNC","FLOAT_FUNC", -"VAL","CHR","ODD","TRUNC","INC","DEC","INCL","EXCL","COLONCOLON","LAST", -"REGNAME","INTERNAL_VAR","ABOVE_COMMA","ASSIGN","LEQ","GEQ","NOTEQUAL","IN", -"OROR","LOGICAL_AND","DIV","MOD","UNARY","DOT","NOT","QID", -}; -char *m2_rule[] = { -"$accept : start", -"start : exp", -"start : type_exp", -"type_exp : type", -"exp : exp '^'", -"$$1 :", -"exp : '-' $$1 exp", -"exp : '+' exp", -"exp : not_exp exp", -"not_exp : NOT", -"not_exp : '~'", -"exp : CAP '(' exp ')'", -"exp : ORD '(' exp ')'", -"exp : ABS '(' exp ')'", -"exp : HIGH '(' exp ')'", -"exp : MIN_FUNC '(' type ')'", -"exp : MAX_FUNC '(' type ')'", -"exp : FLOAT_FUNC '(' exp ')'", -"exp : VAL '(' type ',' exp ')'", -"exp : CHR '(' exp ')'", -"exp : ODD '(' exp ')'", -"exp : TRUNC '(' exp ')'", -"exp : SIZE exp", -"exp : INC '(' exp ')'", -"exp : INC '(' exp ',' exp ')'", -"exp : DEC '(' exp ')'", -"exp : DEC '(' exp ',' exp ')'", -"exp : exp DOT NAME", -"exp : set", -"exp : exp IN set", -"exp : INCL '(' exp ',' exp ')'", -"exp : EXCL '(' exp ',' exp ')'", -"set : '{' arglist '}'", -"set : type '{' arglist '}'", -"$$2 :", -"exp : exp '[' $$2 non_empty_arglist ']'", -"$$3 :", -"exp : exp '(' $$3 arglist ')'", -"arglist :", -"arglist : exp", -"arglist : arglist ',' exp", -"non_empty_arglist : exp", -"non_empty_arglist : non_empty_arglist ',' exp", -"exp : '{' type '}' exp", -"exp : type '(' exp ')'", -"exp : '(' exp ')'", -"exp : exp '@' exp", -"exp : exp '*' exp", -"exp : exp '/' exp", -"exp : exp DIV exp", -"exp : exp MOD exp", -"exp : exp '+' exp", -"exp : exp '-' exp", -"exp : exp '=' exp", -"exp : exp NOTEQUAL exp", -"exp : exp '#' exp", -"exp : exp LEQ exp", -"exp : exp GEQ exp", -"exp : exp '<' exp", -"exp : exp '>' exp", -"exp : exp LOGICAL_AND exp", -"exp : exp OROR exp", -"exp : exp ASSIGN exp", -"exp : M2_TRUE", -"exp : M2_FALSE", -"exp : INT", -"exp : UINT", -"exp : CHAR", -"exp : FLOAT", -"exp : variable", -"exp : LAST", -"exp : REGNAME", -"exp : SIZE '(' type ')'", -"exp : STRING", -"block : fblock", -"fblock : BLOCKNAME", -"fblock : block COLONCOLON BLOCKNAME", -"variable : fblock", -"variable : INTERNAL_VAR", -"variable : block COLONCOLON NAME", -"variable : NAME", -"type : TYPENAME", -}; -#endif -#ifdef YYSTACKSIZE -#undef YYMAXDEPTH -#define YYMAXDEPTH YYSTACKSIZE -#else -#ifdef YYMAXDEPTH -#define YYSTACKSIZE YYMAXDEPTH -#else -#define YYSTACKSIZE 500 -#define YYMAXDEPTH 500 -#endif -#endif -int yydebug; -int yynerrs; -int yyerrflag; -int yychar; -short *yyssp; -YYSTYPE *yyvsp; -YYSTYPE yyval; -YYSTYPE yylval; -short yyss[YYSTACKSIZE]; -YYSTYPE yyvs[YYSTACKSIZE]; -#define yystacksize YYSTACKSIZE -#line 658 "./m2-exp.y" - -#if 0 /* FIXME! */ -int -overflow(a,b) - long a,b; -{ - return (MAX_OF_TYPE(builtin_type_m2_int) - b) < a; -} - -int -uoverflow(a,b) - unsigned long a,b; -{ - return (MAX_OF_TYPE(builtin_type_m2_card) - b) < a; -} -#endif /* FIXME */ - -/* Take care of parsing a number (anything that starts with a digit). - Set yylval and return the token type; update lexptr. - LEN is the number of characters in it. */ - -/*** Needs some error checking for the float case ***/ - -static int -parse_number (olen) - int olen; -{ - register char *p = lexptr; - register LONGEST n = 0; - register LONGEST prevn = 0; - register int c,i,ischar=0; - register int base = input_radix; - register int len = olen; - int unsigned_p = number_sign == 1 ? 1 : 0; - - if(p[len-1] == 'H') - { - base = 16; - len--; - } - else if(p[len-1] == 'C' || p[len-1] == 'B') - { - base = 8; - ischar = p[len-1] == 'C'; - len--; - } - - /* Scan the number */ - for (c = 0; c < len; c++) - { - if (p[c] == '.' && base == 10) - { - /* It's a float since it contains a point. */ - yylval.dval = atof (p); - lexptr += len; - return FLOAT; - } - if (p[c] == '.' && base != 10) - error("Floating point numbers must be base 10."); - if (base == 10 && (p[c] < '0' || p[c] > '9')) - error("Invalid digit \'%c\' in number.",p[c]); - } - - while (len-- > 0) - { - c = *p++; - n *= base; - if( base == 8 && (c == '8' || c == '9')) - error("Invalid digit \'%c\' in octal number.",c); - if (c >= '0' && c <= '9') - i = c - '0'; - else - { - if (base == 16 && c >= 'A' && c <= 'F') - i = c - 'A' + 10; - else - return ERROR; - } - n+=i; - if(i >= base) - return ERROR; - if(!unsigned_p && number_sign == 1 && (prevn >= n)) - unsigned_p=1; /* Try something unsigned */ - /* Don't do the range check if n==i and i==0, since that special - case will give an overflow error. */ - if(RANGE_CHECK && n!=i && i) - { - if((unsigned_p && (unsigned)prevn >= (unsigned)n) || - ((!unsigned_p && number_sign==-1) && -prevn <= -n)) - range_error("Overflow on numeric constant."); - } - prevn=n; - } - - lexptr = p; - if(*p == 'B' || *p == 'C' || *p == 'H') - lexptr++; /* Advance past B,C or H */ - - if (ischar) - { - yylval.ulval = n; - return CHAR; - } - else if ( unsigned_p && number_sign == 1) - { - yylval.ulval = n; - return UINT; - } - else if((unsigned_p && (n<0))) { - range_error("Overflow on numeric constant -- number too large."); - /* But, this can return if range_check == range_warn. */ - } - yylval.lval = n; - return INT; -} - - -/* Some tokens */ - -static struct -{ - char name[2]; - int token; -} tokentab2[] = -{ - { {'<', '>'}, NOTEQUAL }, - { {':', '='}, ASSIGN }, - { {'<', '='}, LEQ }, - { {'>', '='}, GEQ }, - { {':', ':'}, COLONCOLON }, - -}; - -/* Some specific keywords */ - -struct keyword { - char keyw[10]; - int token; -}; - -static struct keyword keytab[] = -{ - {"OR" , OROR }, - {"IN", IN },/* Note space after IN */ - {"AND", LOGICAL_AND}, - {"ABS", ABS }, - {"CHR", CHR }, - {"DEC", DEC }, - {"NOT", NOT }, - {"DIV", DIV }, - {"INC", INC }, - {"MAX", MAX_FUNC }, - {"MIN", MIN_FUNC }, - {"MOD", MOD }, - {"ODD", ODD }, - {"CAP", CAP }, - {"ORD", ORD }, - {"VAL", VAL }, - {"EXCL", EXCL }, - {"HIGH", HIGH }, - {"INCL", INCL }, - {"SIZE", SIZE }, - {"FLOAT", FLOAT_FUNC }, - {"TRUNC", TRUNC }, -}; - - -/* Read one token, getting characters through lexptr. */ - -/* This is where we will check to make sure that the language and the operators used are - compatible */ - -static int -yylex () -{ - register int c; - register int namelen; - register int i; - register char *tokstart; - register char quote; - - retry: - - tokstart = lexptr; - - - /* See if it is a special token of length 2 */ - for( i = 0 ; i < sizeof tokentab2 / sizeof tokentab2[0] ; i++) - if(STREQN(tokentab2[i].name, tokstart, 2)) - { - lexptr += 2; - return tokentab2[i].token; - } - - switch (c = *tokstart) - { - case 0: - return 0; - - case ' ': - case '\t': - case '\n': - lexptr++; - goto retry; - - case '(': - paren_depth++; - lexptr++; - return c; - - case ')': - if (paren_depth == 0) - return 0; - paren_depth--; - lexptr++; - return c; - - case ',': - if (comma_terminates && paren_depth == 0) - return 0; - lexptr++; - return c; - - case '.': - /* Might be a floating point number. */ - if (lexptr[1] >= '0' && lexptr[1] <= '9') - break; /* Falls into number code. */ - else - { - lexptr++; - return DOT; - } - -/* These are character tokens that appear as-is in the YACC grammar */ - case '+': - case '-': - case '*': - case '/': - case '^': - case '<': - case '>': - case '[': - case ']': - case '=': - case '{': - case '}': - case '#': - case '@': - case '~': - case '&': - lexptr++; - return c; - - case '\'' : - case '"': - quote = c; - for (namelen = 1; (c = tokstart[namelen]) != quote && c != '\0'; namelen++) - if (c == '\\') - { - c = tokstart[++namelen]; - if (c >= '0' && c <= '9') - { - c = tokstart[++namelen]; - if (c >= '0' && c <= '9') - c = tokstart[++namelen]; - } - } - if(c != quote) - error("Unterminated string or character constant."); - yylval.sval.ptr = tokstart + 1; - yylval.sval.length = namelen - 1; - lexptr += namelen + 1; - - if(namelen == 2) /* Single character */ - { - yylval.ulval = tokstart[1]; - return CHAR; - } - else - return STRING; - } - - /* Is it a number? */ - /* Note: We have already dealt with the case of the token '.'. - See case '.' above. */ - if ((c >= '0' && c <= '9')) - { - /* It's a number. */ - int got_dot = 0, got_e = 0; - register char *p = tokstart; - int toktype; - - for (++p ;; ++p) - { - if (!got_e && (*p == 'e' || *p == 'E')) - got_dot = got_e = 1; - else if (!got_dot && *p == '.') - got_dot = 1; - else if (got_e && (p[-1] == 'e' || p[-1] == 'E') - && (*p == '-' || *p == '+')) - /* This is the sign of the exponent, not the end of the - number. */ - continue; - else if ((*p < '0' || *p > '9') && - (*p < 'A' || *p > 'F') && - (*p != 'H')) /* Modula-2 hexadecimal number */ - break; - } - toktype = parse_number (p - tokstart); - if (toktype == ERROR) - { - char *err_copy = (char *) alloca (p - tokstart + 1); - - memcpy (err_copy, tokstart, p - tokstart); - err_copy[p - tokstart] = 0; - error ("Invalid number \"%s\".", err_copy); - } - lexptr = p; - return toktype; - } - - if (!(c == '_' || c == '$' - || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) - /* We must have come across a bad character (e.g. ';'). */ - error ("Invalid character '%c' in expression.", c); - - /* It's a name. See how long it is. */ - namelen = 0; - for (c = tokstart[namelen]; - (c == '_' || c == '$' || (c >= '0' && c <= '9') - || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); - c = tokstart[++namelen]) - ; - - /* The token "if" terminates the expression and is NOT - removed from the input stream. */ - if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f') - { - return 0; - } - - lexptr += namelen; - - /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1) - and $$digits (equivalent to $<-digits> if you could type that). - Make token type LAST, and put the number (the digits) in yylval. */ - - if (*tokstart == '$') - { - register int negate = 0; - c = 1; - /* Double dollar means negate the number and add -1 as well. - Thus $$ alone means -1. */ - if (namelen >= 2 && tokstart[1] == '$') - { - negate = 1; - c = 2; - } - if (c == namelen) - { - /* Just dollars (one or two) */ - yylval.lval = - negate; - return LAST; - } - /* Is the rest of the token digits? */ - for (; c < namelen; c++) - if (!(tokstart[c] >= '0' && tokstart[c] <= '9')) - break; - if (c == namelen) - { - yylval.lval = atoi (tokstart + 1 + negate); - if (negate) - yylval.lval = - yylval.lval; - return LAST; - } - } - - /* Handle tokens that refer to machine registers: - $ followed by a register name. */ - - if (*tokstart == '$') { - for (c = 0; c < NUM_REGS; c++) - if (namelen - 1 == strlen (reg_names[c]) - && STREQN (tokstart + 1, reg_names[c], namelen - 1)) - { - yylval.lval = c; - return REGNAME; - } - for (c = 0; c < num_std_regs; c++) - if (namelen - 1 == strlen (std_regs[c].name) - && STREQN (tokstart + 1, std_regs[c].name, namelen - 1)) - { - yylval.lval = std_regs[c].regnum; - return REGNAME; - } - } - - - /* Lookup special keywords */ - for(i = 0 ; i < sizeof(keytab) / sizeof(keytab[0]) ; i++) - if(namelen == strlen(keytab[i].keyw) && STREQN(tokstart,keytab[i].keyw,namelen)) - return keytab[i].token; - - yylval.sval.ptr = tokstart; - yylval.sval.length = namelen; - - /* Any other names starting in $ are debugger internal variables. */ - - if (*tokstart == '$') - { - yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1); - return INTERNAL_VAR; - } - - - /* Use token-type BLOCKNAME for symbols that happen to be defined as - functions. If this is not so, then ... - Use token-type TYPENAME for symbols that happen to be defined - currently as names of types; NAME for other symbols. - The caller is not constrained to care about the distinction. */ - { - - - char *tmp = copy_name (yylval.sval); - struct symbol *sym; - - if (lookup_partial_symtab (tmp)) - return BLOCKNAME; - sym = lookup_symbol (tmp, expression_context_block, - VAR_NAMESPACE, 0, NULL); - if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) - return BLOCKNAME; - if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1)) - return TYPENAME; - - if(sym) - { - switch(sym->class) - { - case LOC_STATIC: - case LOC_REGISTER: - case LOC_ARG: - case LOC_REF_ARG: - case LOC_REGPARM: - case LOC_REGPARM_ADDR: - case LOC_LOCAL: - case LOC_LOCAL_ARG: - case LOC_BASEREG: - case LOC_BASEREG_ARG: - case LOC_CONST: - case LOC_CONST_BYTES: - case LOC_OPTIMIZED_OUT: - return NAME; - - case LOC_TYPEDEF: - return TYPENAME; - - case LOC_BLOCK: - return BLOCKNAME; - - case LOC_UNDEF: - error("internal: Undefined class in m2lex()"); - - case LOC_LABEL: - error("internal: Unforseen case in m2lex()"); - } - } - else - { - /* Built-in BOOLEAN type. This is sort of a hack. */ - if(STREQN(tokstart,"TRUE",4)) - { - yylval.ulval = 1; - return M2_TRUE; - } - else if(STREQN(tokstart,"FALSE",5)) - { - yylval.ulval = 0; - return M2_FALSE; - } - } - - /* Must be another type of name... */ - return NAME; - } -} - -#if 0 /* Unused */ -static char * -make_qualname(mod,ident) - char *mod, *ident; -{ - char *new = xmalloc(strlen(mod)+strlen(ident)+2); - - strcpy(new,mod); - strcat(new,"."); - strcat(new,ident); - return new; -} -#endif /* 0 */ - -void -yyerror(msg) - char *msg; /* unused */ -{ - printf("Parsing: %s\n",lexptr); - if (yychar < 256) - error("Invalid syntax in expression near character '%c'.",yychar); - else - error("Invalid syntax in expression"); -} - -#line 1366 "y.tab.c" -#define YYABORT goto yyabort -#define YYREJECT goto yyabort -#define YYACCEPT goto yyaccept -#define YYERROR goto yyerrlab -int -yyparse() -{ - register int yym, yyn, yystate; -#if YYDEBUG - register char *yys; - extern char *getenv(); - - if (yys = getenv("YYDEBUG")) - { - yyn = *yys; - if (yyn >= '0' && yyn <= '9') - yydebug = yyn - '0'; - } -#endif - - yynerrs = 0; - yyerrflag = 0; - yychar = (-1); - - yyssp = yyss; - yyvsp = yyvs; - *yyssp = yystate = 0; - -yyloop: - if (yyn = yydefred[yystate]) goto yyreduce; - if (yychar < 0) - { - if ((yychar = yylex()) < 0) yychar = 0; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, reading %d (%s)\n", - YYPREFIX, yystate, yychar, yys); - } -#endif - } - if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yychar) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, shifting to state %d\n", - YYPREFIX, yystate, yytable[yyn]); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate = yytable[yyn]; - *++yyvsp = yylval; - yychar = (-1); - if (yyerrflag > 0) --yyerrflag; - goto yyloop; - } - if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yychar) - { - yyn = yytable[yyn]; - goto yyreduce; - } - if (yyerrflag) goto yyinrecovery; -#ifdef lint - goto yynewerror; -#endif -yynewerror: - yyerror("syntax error"); -#ifdef lint - goto yyerrlab; -#endif -yyerrlab: - ++yynerrs; -yyinrecovery: - if (yyerrflag < 3) - { - yyerrflag = 3; - for (;;) - { - if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, error recovery shifting\ - to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate = yytable[yyn]; - *++yyvsp = yylval; - goto yyloop; - } - else - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: error recovery discarding state %d\n", - YYPREFIX, *yyssp); -#endif - if (yyssp <= yyss) goto yyabort; - --yyssp; - --yyvsp; - } - } - } - else - { - if (yychar == 0) goto yyabort; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, error recovery discards token %d (%s)\n", - YYPREFIX, yystate, yychar, yys); - } -#endif - yychar = (-1); - goto yyloop; - } -yyreduce: -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, reducing by rule %d (%s)\n", - YYPREFIX, yystate, yyn, yyrule[yyn]); -#endif - yym = yylen[yyn]; - yyval = yyvsp[1-yym]; - switch (yyn) - { -case 3: -#line 197 "./m2-exp.y" -{ write_exp_elt_opcode(OP_TYPE); - write_exp_elt_type(yyvsp[0].tval); - write_exp_elt_opcode(OP_TYPE); - } -break; -case 4: -#line 206 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_IND); } -break; -case 5: -#line 209 "./m2-exp.y" -{ number_sign = -1; } -break; -case 6: -#line 211 "./m2-exp.y" -{ number_sign = 1; - write_exp_elt_opcode (UNOP_NEG); } -break; -case 7: -#line 216 "./m2-exp.y" -{ write_exp_elt_opcode(UNOP_PLUS); } -break; -case 8: -#line 220 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); } -break; -case 11: -#line 228 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_CAP); } -break; -case 12: -#line 232 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_ORD); } -break; -case 13: -#line 236 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_ABS); } -break; -case 14: -#line 240 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_HIGH); } -break; -case 15: -#line 244 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_MIN); - write_exp_elt_type (yyvsp[-1].tval); - write_exp_elt_opcode (UNOP_MIN); } -break; -case 16: -#line 250 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_MAX); - write_exp_elt_type (yyvsp[-1].tval); - write_exp_elt_opcode (UNOP_MIN); } -break; -case 17: -#line 256 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_FLOAT); } -break; -case 18: -#line 260 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_VAL); - write_exp_elt_type (yyvsp[-3].tval); - write_exp_elt_opcode (BINOP_VAL); } -break; -case 19: -#line 266 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_CHR); } -break; -case 20: -#line 270 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_ODD); } -break; -case 21: -#line 274 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_TRUNC); } -break; -case 22: -#line 278 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_SIZEOF); } -break; -case 23: -#line 283 "./m2-exp.y" -{ write_exp_elt_opcode(UNOP_PREINCREMENT); } -break; -case 24: -#line 287 "./m2-exp.y" -{ write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode(BINOP_ADD); - write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); } -break; -case 25: -#line 293 "./m2-exp.y" -{ write_exp_elt_opcode(UNOP_PREDECREMENT);} -break; -case 26: -#line 297 "./m2-exp.y" -{ write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); - write_exp_elt_opcode(BINOP_SUB); - write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); } -break; -case 27: -#line 303 "./m2-exp.y" -{ write_exp_elt_opcode (STRUCTOP_STRUCT); - write_exp_string (yyvsp[0].sval); - write_exp_elt_opcode (STRUCTOP_STRUCT); } -break; -case 29: -#line 312 "./m2-exp.y" -{ error("Sets are not implemented.");} -break; -case 30: -#line 316 "./m2-exp.y" -{ error("Sets are not implemented.");} -break; -case 31: -#line 320 "./m2-exp.y" -{ error("Sets are not implemented.");} -break; -case 32: -#line 323 "./m2-exp.y" -{ error("Sets are not implemented.");} -break; -case 33: -#line 325 "./m2-exp.y" -{ error("Sets are not implemented.");} -break; -case 34: -#line 334 "./m2-exp.y" -{ start_arglist(); } -break; -case 35: -#line 336 "./m2-exp.y" -{ write_exp_elt_opcode (MULTI_SUBSCRIPT); - write_exp_elt_longcst ((LONGEST) end_arglist()); - write_exp_elt_opcode (MULTI_SUBSCRIPT); } -break; -case 36: -#line 344 "./m2-exp.y" -{ start_arglist (); } -break; -case 37: -#line 346 "./m2-exp.y" -{ write_exp_elt_opcode (OP_FUNCALL); - write_exp_elt_longcst ((LONGEST) end_arglist ()); - write_exp_elt_opcode (OP_FUNCALL); } -break; -case 39: -#line 355 "./m2-exp.y" -{ arglist_len = 1; } -break; -case 40: -#line 359 "./m2-exp.y" -{ arglist_len++; } -break; -case 41: -#line 364 "./m2-exp.y" -{ arglist_len = 1; } -break; -case 42: -#line 369 "./m2-exp.y" -{ arglist_len++; } -break; -case 43: -#line 374 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_MEMVAL); - write_exp_elt_type (yyvsp[-2].tval); - write_exp_elt_opcode (UNOP_MEMVAL); } -break; -case 44: -#line 380 "./m2-exp.y" -{ write_exp_elt_opcode (UNOP_CAST); - write_exp_elt_type (yyvsp[-3].tval); - write_exp_elt_opcode (UNOP_CAST); } -break; -case 45: -#line 386 "./m2-exp.y" -{ } -break; -case 46: -#line 394 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_REPEAT); } -break; -case 47: -#line 398 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_MUL); } -break; -case 48: -#line 402 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_DIV); } -break; -case 49: -#line 406 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_INTDIV); } -break; -case 50: -#line 410 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_REM); } -break; -case 51: -#line 414 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_ADD); } -break; -case 52: -#line 418 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_SUB); } -break; -case 53: -#line 422 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_EQUAL); } -break; -case 54: -#line 426 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_NOTEQUAL); } -break; -case 55: -#line 428 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_NOTEQUAL); } -break; -case 56: -#line 432 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_LEQ); } -break; -case 57: -#line 436 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_GEQ); } -break; -case 58: -#line 440 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_LESS); } -break; -case 59: -#line 444 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_GTR); } -break; -case 60: -#line 448 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_LOGICAL_AND); } -break; -case 61: -#line 452 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_LOGICAL_OR); } -break; -case 62: -#line 456 "./m2-exp.y" -{ write_exp_elt_opcode (BINOP_ASSIGN); } -break; -case 63: -#line 463 "./m2-exp.y" -{ write_exp_elt_opcode (OP_BOOL); - write_exp_elt_longcst ((LONGEST) yyvsp[0].ulval); - write_exp_elt_opcode (OP_BOOL); } -break; -case 64: -#line 469 "./m2-exp.y" -{ write_exp_elt_opcode (OP_BOOL); - write_exp_elt_longcst ((LONGEST) yyvsp[0].ulval); - write_exp_elt_opcode (OP_BOOL); } -break; -case 65: -#line 475 "./m2-exp.y" -{ write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_m2_int); - write_exp_elt_longcst ((LONGEST) yyvsp[0].lval); - write_exp_elt_opcode (OP_LONG); } -break; -case 66: -#line 482 "./m2-exp.y" -{ - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_m2_card); - write_exp_elt_longcst ((LONGEST) yyvsp[0].ulval); - write_exp_elt_opcode (OP_LONG); - } -break; -case 67: -#line 491 "./m2-exp.y" -{ write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_m2_char); - write_exp_elt_longcst ((LONGEST) yyvsp[0].ulval); - write_exp_elt_opcode (OP_LONG); } -break; -case 68: -#line 499 "./m2-exp.y" -{ write_exp_elt_opcode (OP_DOUBLE); - write_exp_elt_type (builtin_type_m2_real); - write_exp_elt_dblcst (yyvsp[0].dval); - write_exp_elt_opcode (OP_DOUBLE); } -break; -case 70: -#line 510 "./m2-exp.y" -{ write_exp_elt_opcode (OP_LAST); - write_exp_elt_longcst ((LONGEST) yyvsp[0].lval); - write_exp_elt_opcode (OP_LAST); } -break; -case 71: -#line 516 "./m2-exp.y" -{ write_exp_elt_opcode (OP_REGISTER); - write_exp_elt_longcst ((LONGEST) yyvsp[0].lval); - write_exp_elt_opcode (OP_REGISTER); } -break; -case 72: -#line 522 "./m2-exp.y" -{ write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_int); - write_exp_elt_longcst ((LONGEST) TYPE_LENGTH (yyvsp[-1].tval)); - write_exp_elt_opcode (OP_LONG); } -break; -case 73: -#line 529 "./m2-exp.y" -{ write_exp_elt_opcode (OP_M2_STRING); - write_exp_string (yyvsp[0].sval); - write_exp_elt_opcode (OP_M2_STRING); } -break; -case 74: -#line 536 "./m2-exp.y" -{ yyval.bval = SYMBOL_BLOCK_VALUE(yyvsp[0].sym); } -break; -case 75: -#line 540 "./m2-exp.y" -{ struct symbol *sym - = lookup_symbol (copy_name (yyvsp[0].sval), expression_context_block, - VAR_NAMESPACE, 0, NULL); - yyval.sym = sym;} -break; -case 76: -#line 549 "./m2-exp.y" -{ struct symbol *tem - = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, - VAR_NAMESPACE, 0, NULL); - if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK) - error ("No function \"%s\" in specified context.", - copy_name (yyvsp[0].sval)); - yyval.sym = tem; - } -break; -case 77: -#line 561 "./m2-exp.y" -{ write_exp_elt_opcode(OP_VAR_VALUE); - write_exp_elt_block (NULL); - write_exp_elt_sym (yyvsp[0].sym); - write_exp_elt_opcode (OP_VAR_VALUE); } -break; -case 78: -#line 569 "./m2-exp.y" -{ write_exp_elt_opcode (OP_INTERNALVAR); - write_exp_elt_intern (yyvsp[0].ivar); - write_exp_elt_opcode (OP_INTERNALVAR); } -break; -case 79: -#line 576 "./m2-exp.y" -{ struct symbol *sym; - sym = lookup_symbol (copy_name (yyvsp[0].sval), yyvsp[-2].bval, - VAR_NAMESPACE, 0, NULL); - if (sym == 0) - error ("No symbol \"%s\" in specified context.", - copy_name (yyvsp[0].sval)); - - write_exp_elt_opcode (OP_VAR_VALUE); - /* block_found is set by lookup_symbol. */ - write_exp_elt_block (block_found); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); } -break; -case 80: -#line 592 "./m2-exp.y" -{ struct symbol *sym; - int is_a_field_of_this; - - sym = lookup_symbol (copy_name (yyvsp[0].sval), - expression_context_block, - VAR_NAMESPACE, - &is_a_field_of_this, - NULL); - if (sym) - { - if (symbol_read_needs_frame (sym)) - { - if (innermost_block == 0 || - contained_in (block_found, - innermost_block)) - innermost_block = block_found; - } - - write_exp_elt_opcode (OP_VAR_VALUE); - /* We want to use the selected frame, not - another more inner frame which happens to - be in the same block. */ - write_exp_elt_block (NULL); - write_exp_elt_sym (sym); - write_exp_elt_opcode (OP_VAR_VALUE); - } - else - { - struct minimal_symbol *msymbol; - register char *arg = copy_name (yyvsp[0].sval); - - msymbol = lookup_minimal_symbol (arg, - (struct objfile *) NULL); - if (msymbol != NULL) - { - write_exp_elt_opcode (OP_LONG); - write_exp_elt_type (builtin_type_long); - write_exp_elt_longcst ((LONGEST) SYMBOL_VALUE_ADDRESS (msymbol)); - write_exp_elt_opcode (OP_LONG); - write_exp_elt_opcode (UNOP_MEMVAL); - if (msymbol -> type == mst_data || - msymbol -> type == mst_bss) - write_exp_elt_type (builtin_type_int); - else if (msymbol -> type == mst_text) - write_exp_elt_type (lookup_function_type (builtin_type_int)); - else - write_exp_elt_type (builtin_type_char); - write_exp_elt_opcode (UNOP_MEMVAL); - } - else if (!have_full_symbols () && !have_partial_symbols ()) - error ("No symbol table is loaded. Use the \"symbol-file\" command."); - else - error ("No symbol \"%s\" in current context.", - copy_name (yyvsp[0].sval)); - } - } -break; -case 81: -#line 652 "./m2-exp.y" -{ yyval.tval = lookup_typename (copy_name (yyvsp[0].sval), - expression_context_block, 0); } -break; -#line 1936 "y.tab.c" - } - yyssp -= yym; - yystate = *yyssp; - yyvsp -= yym; - yym = yylhs[yyn]; - if (yystate == 0 && yym == 0) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: after reduction, shifting from state 0 to\ - state %d\n", YYPREFIX, YYFINAL); -#endif - yystate = YYFINAL; - *++yyssp = YYFINAL; - *++yyvsp = yyval; - if (yychar < 0) - { - if ((yychar = yylex()) < 0) yychar = 0; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, reading %d (%s)\n", - YYPREFIX, YYFINAL, yychar, yys); - } -#endif - } - if (yychar == 0) goto yyaccept; - goto yyloop; - } - if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yystate) - yystate = yytable[yyn]; - else - yystate = yydgoto[yym]; -#if YYDEBUG - if (yydebug) - printf("%sdebug: after reduction, shifting from state %d \ -to state %d\n", YYPREFIX, *yyssp, yystate); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate; - *++yyvsp = yyval; - goto yyloop; -yyoverflow: - yyerror("yacc stack overflow"); -yyabort: - return (1); -yyaccept: - return (0); -} diff --git a/gnu/usr.bin/gdb/gdb/putenv.c b/gnu/usr.bin/gdb/gdb/putenv.c deleted file mode 100644 index e2ea357..0000000 --- a/gnu/usr.bin/gdb/gdb/putenv.c +++ /dev/null @@ -1,111 +0,0 @@ -/****************************************************************/ -/* */ -/* putenv(3) */ -/* */ -/* Change or add an environment entry */ -/* */ -/****************************************************************/ -/* origination 1987-Oct-7 T. Holm */ -/****************************************************************/ - -/* -Path: hoptoad!pacbell!ames!ll-xn!mit-eddie!uw-beaver!ssc-vax!uvicctr!tholm -From: tholm@uvicctr.UUCP (Terrence W. Holm) -Newsgroups: comp.os.minix -Subject: putenv(3) -Message-ID: <395@uvicctr.UUCP> -Date: 5 May 88 06:40:52 GMT -Organization: University of Victoria, Victoria B.C. Canada - -EFTH Minix report #2 - May 1988 - putenv(3) - -This is an implementation of putenv(3) that we -wrote for Minix. Please consider this a public -domain program. -*/ - -#include - -#define PSIZE sizeof(char *) - -extern char **environ; - -char *strchr(); -char *malloc(); - -/****************************************************************/ -/* */ -/* int */ -/* putenv( entry ) */ -/* */ -/* The "entry" should follow the form */ -/* "NAME=VALUE". This routine will search the */ -/* user environment for "NAME" and replace its */ -/* value with "VALUE". */ -/* */ -/* Note that "entry" is not copied, it is used */ -/* as the environment entry. This means that it */ -/* must not be unallocated or otherwise modifed */ -/* by the caller, unless it is replaced by a */ -/* subsequent putenv(). */ -/* */ -/* If the name is not found in the environment, */ -/* then a new vector of pointers is allocated, */ -/* "entry" is put at the end and the global */ -/* variable "environ" is updated. */ -/* */ -/* This function normally returns NULL, but -1 */ -/* is returned if it can not allocate enough */ -/* space using malloc(3), or "entry" does not */ -/* contain a '='. */ -/* */ -/****************************************************************/ - - -int -putenv( entry ) - char *entry; -{ - unsigned length; - unsigned size; - char *temp; - char **p; - char **new_environ; - - /* Find the length of the "NAME=" */ - - temp = strchr(entry,'='); - if ( temp == 0 ) - return( -1 ); - - length = (unsigned) (temp - entry + 1); - - - /* Scan through the environment looking for "NAME=" */ - - for ( p=environ; *p != 0 ; p++ ) - if ( strncmp( entry, *p, length ) == 0 ) - { - *p = entry; - return( 0 ); - } - - - /* The name was not found, build a bigger environment */ - - size = p - environ; - - new_environ = (char **) malloc( (size+2)*PSIZE ); - - if ( new_environ == (char **) NULL ) - return( -1 ); - - memcpy ((char *) new_environ, (char *) environ, size*PSIZE ); - - new_environ[size] = entry; - new_environ[size+1] = NULL; - - environ = new_environ; - - return(0); -} diff --git a/gnu/usr.bin/gdb/gdb/regex.c b/gnu/usr.bin/gdb/gdb/regex.c deleted file mode 100644 index 3f30284..0000000 --- a/gnu/usr.bin/gdb/gdb/regex.c +++ /dev/null @@ -1,1744 +0,0 @@ -/* Extended regular expression matching and search library. - Copyright (C) 1985, 1989 Free Software Foundation, Inc. - -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 of the License, 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 this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* To test, compile with -Dtest. - This Dtestable feature turns this into a self-contained program - which reads a pattern, describes how it compiles, - then reads a string and searches for it. */ - -#ifdef emacs - -/* The `emacs' switch turns on certain special matching commands - that make sense only in emacs. */ - -#include "config.h" -#include "lisp.h" -#include "buffer.h" -#include "syntax.h" - -#else /* not emacs */ - -#include "defs.h" -#include - -/* - * Define the syntax stuff, so we can do the \<...\> things. - */ - -#ifndef Sword /* must be non-zero in some of the tests below... */ -#define Sword 1 -#endif - -#define SYNTAX(c) re_syntax_table[c] - -#ifdef SYNTAX_TABLE - -char *re_syntax_table; - -#else - -static char re_syntax_table[256]; - -static void -init_syntax_once () -{ - register int c; - static int done = 0; - - if (done) - return; - - memset (re_syntax_table, '\0', sizeof re_syntax_table); - - for (c = 'a'; c <= 'z'; c++) - re_syntax_table[c] = Sword; - - for (c = 'A'; c <= 'Z'; c++) - re_syntax_table[c] = Sword; - - for (c = '0'; c <= '9'; c++) - re_syntax_table[c] = Sword; - - done = 1; -} - -#endif /* SYNTAX_TABLE */ -#endif /* not emacs */ - -#include "regex.h" - -/* Number of failure points to allocate space for initially, - when matching. If this number is exceeded, more space is allocated, - so it is not a hard limit. */ - -#ifndef NFAILURES -#define NFAILURES 80 -#endif /* NFAILURES */ - -/* width of a byte in bits */ - -#define BYTEWIDTH 8 - -/* We remove any previous definition of `SIGN_EXTEND_CHAR', - since ours (we hope) works properly with all combinations of - machines, compilers, `char' and `unsigned char' argument types. - (Per Bothner suggested the basic approach.) */ -#undef SIGN_EXTEND_CHAR -#if __STDC__ -#define SIGN_EXTEND_CHAR(c) ((signed char) (c)) -#else /* not __STDC__ */ -/* As in Harbison and Steele. */ -#define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128) -#endif - -static int obscure_syntax = 0; - -/* Specify the precise syntax of regexp for compilation. - This provides for compatibility for various utilities - which historically have different, incompatible syntaxes. - - The argument SYNTAX is a bit-mask containing the two bits - RE_NO_BK_PARENS and RE_NO_BK_VBAR. */ - -int -re_set_syntax (syntax) - int syntax; -{ - int ret; - - ret = obscure_syntax; - obscure_syntax = syntax; - return ret; -} - -/* re_compile_pattern takes a regular-expression string - and converts it into a buffer full of byte commands for matching. - - PATTERN is the address of the pattern string - SIZE is the length of it. - BUFP is a struct re_pattern_buffer * which points to the info - on where to store the byte commands. - This structure contains a char * which points to the - actual space, which should have been obtained with malloc. - re_compile_pattern may use realloc to grow the buffer space. - - The number of bytes of commands can be found out by looking in - the struct re_pattern_buffer that bufp pointed to, - after re_compile_pattern returns. -*/ - -#define PATPUSH(ch) (*b++ = (char) (ch)) - -#define PATFETCH(c) \ - {if (p == pend) goto end_of_pattern; \ - c = * (unsigned char *) p++; \ - if (translate) c = translate[c]; } - -#define PATFETCH_RAW(c) \ - {if (p == pend) goto end_of_pattern; \ - c = * (unsigned char *) p++; } - -#define PATUNFETCH p-- - -/* This is not an arbitrary limit: the arguments which represent offsets - into the pattern are two bytes long. So if 2^16 bytes turns out to - be too small, many things would have to change. */ -#define MAX_BUF_SIZE (1 << 16) - - -/* Extend the buffer by twice its current size via realloc and - reset the pointers that pointed into the old block to point to the - correct places in the new one. If extending the buffer results in it - being larger than MAX_BUF_SIZE, then flag memory exhausted. */ -#define EXTEND_BUFFER \ - do { \ - char *old_buffer = bufp->buffer; \ - if (bufp->allocated == MAX_BUF_SIZE) \ - goto too_big; \ - bufp->allocated <<= 1; \ - if (bufp->allocated > MAX_BUF_SIZE) \ - bufp->allocated = MAX_BUF_SIZE; \ - bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated);\ - if (bufp->buffer == NULL) \ - goto memory_exhausted; \ - /* If the buffer moved, move all the pointers into it. */ \ - if (old_buffer != bufp->buffer) \ - { \ - b = (b - old_buffer) + bufp->buffer; \ - begalt = (begalt - old_buffer) + bufp->buffer; \ - if (fixup_jump) \ - fixup_jump = (fixup_jump - old_buffer) + bufp->buffer;\ - if (laststart) \ - laststart = (laststart - old_buffer) + bufp->buffer; \ - if (pending_exact) \ - pending_exact = (pending_exact - old_buffer) + bufp->buffer; \ - } \ - } while (0) - -static void store_jump (), insert_jump (); - -char * -re_compile_pattern (pattern, size, bufp) - char *pattern; - int size; - struct re_pattern_buffer *bufp; -{ - register char *b = bufp->buffer; - register char *p = pattern; - char *pend = pattern + size; - register unsigned c, c1; - char *p1; - unsigned char *translate = (unsigned char *) bufp->translate; - - /* address of the count-byte of the most recently inserted "exactn" command. - This makes it possible to tell whether a new exact-match character - can be added to that command or requires a new "exactn" command. */ - - char *pending_exact = 0; - - /* address of the place where a forward-jump should go - to the end of the containing expression. - Each alternative of an "or", except the last, ends with a forward-jump - of this sort. */ - - char *fixup_jump = 0; - - /* address of start of the most recently finished expression. - This tells postfix * where to find the start of its operand. */ - - char *laststart = 0; - - /* In processing a repeat, 1 means zero matches is allowed */ - - char zero_times_ok; - - /* In processing a repeat, 1 means many matches is allowed */ - - char many_times_ok; - - /* address of beginning of regexp, or inside of last \( */ - - char *begalt = b; - - /* Stack of information saved by \( and restored by \). - Four stack elements are pushed by each \(: - First, the value of b. - Second, the value of fixup_jump. - Third, the value of regnum. - Fourth, the value of begalt. */ - - int stackb[40]; - int *stackp = stackb; - int *stacke = stackb + 40; - int *stackt; - - /* Counts \('s as they are encountered. Remembered for the matching \), - where it becomes the "register number" to put in the stop_memory command */ - - int regnum = 1; - - bufp->fastmap_accurate = 0; - -#ifndef emacs -#ifndef SYNTAX_TABLE - /* - * Initialize the syntax table. - */ - init_syntax_once(); -#endif -#endif - - if (bufp->allocated == 0) - { - bufp->allocated = 28; - if (bufp->buffer) - /* EXTEND_BUFFER loses when bufp->allocated is 0 */ - bufp->buffer = (char *) realloc (bufp->buffer, 28); - else - /* Caller did not allocate a buffer. Do it for him */ - bufp->buffer = (char *) malloc (28); - if (!bufp->buffer) goto memory_exhausted; - begalt = b = bufp->buffer; - } - - while (p != pend) - { - if (b - bufp->buffer > bufp->allocated - 10) - /* Note that EXTEND_BUFFER clobbers c */ - EXTEND_BUFFER; - - PATFETCH (c); - - switch (c) - { - case '$': - if (obscure_syntax & RE_TIGHT_VBAR) - { - if (! (obscure_syntax & RE_CONTEXT_INDEP_OPS) && p != pend) - goto normal_char; - /* Make operand of last vbar end before this `$'. */ - if (fixup_jump) - store_jump (fixup_jump, jump, b); - fixup_jump = 0; - PATPUSH (endline); - break; - } - - /* $ means succeed if at end of line, but only in special contexts. - If randomly in the middle of a pattern, it is a normal character. */ - if (p == pend || *p == '\n' - || (obscure_syntax & RE_CONTEXT_INDEP_OPS) - || (obscure_syntax & RE_NO_BK_PARENS - ? *p == ')' - : *p == '\\' && p[1] == ')') - || (obscure_syntax & RE_NO_BK_VBAR - ? *p == '|' - : *p == '\\' && p[1] == '|')) - { - PATPUSH (endline); - break; - } - goto normal_char; - - case '^': - /* ^ means succeed if at beg of line, but only if no preceding pattern. */ - - if (laststart && p[-2] != '\n' - && ! (obscure_syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - if (obscure_syntax & RE_TIGHT_VBAR) - { - if (p != pattern + 1 - && ! (obscure_syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - PATPUSH (begline); - begalt = b; - } - else - PATPUSH (begline); - break; - - case '+': - case '?': - if (obscure_syntax & RE_BK_PLUS_QM) - goto normal_char; - handle_plus: - case '*': - /* If there is no previous pattern, char not special. */ - if (!laststart && ! (obscure_syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - /* If there is a sequence of repetition chars, - collapse it down to equivalent to just one. */ - zero_times_ok = 0; - many_times_ok = 0; - while (1) - { - zero_times_ok |= c != '+'; - many_times_ok |= c != '?'; - if (p == pend) - break; - PATFETCH (c); - if (c == '*') - ; - else if (!(obscure_syntax & RE_BK_PLUS_QM) - && (c == '+' || c == '?')) - ; - else if ((obscure_syntax & RE_BK_PLUS_QM) - && c == '\\') - { - int c1; - PATFETCH (c1); - if (!(c1 == '+' || c1 == '?')) - { - PATUNFETCH; - PATUNFETCH; - break; - } - c = c1; - } - else - { - PATUNFETCH; - break; - } - } - - /* Star, etc. applied to an empty pattern is equivalent - to an empty pattern. */ - if (!laststart) - break; - - /* Now we know whether 0 matches is allowed, - and whether 2 or more matches is allowed. */ - if (many_times_ok) - { - /* If more than one repetition is allowed, - put in a backward jump at the end. */ - store_jump (b, maybe_finalize_jump, laststart - 3); - b += 3; - } - insert_jump (on_failure_jump, laststart, b + 3, b); - pending_exact = 0; - b += 3; - if (!zero_times_ok) - { - /* At least one repetition required: insert before the loop - a skip over the initial on-failure-jump instruction */ - insert_jump (dummy_failure_jump, laststart, laststart + 6, b); - b += 3; - } - break; - - case '.': - laststart = b; - PATPUSH (anychar); - break; - - case '[': - while (b - bufp->buffer - > bufp->allocated - 3 - (1 << BYTEWIDTH) / BYTEWIDTH) - /* Note that EXTEND_BUFFER clobbers c */ - EXTEND_BUFFER; - - laststart = b; - if (*p == '^') - PATPUSH (charset_not), p++; - else - PATPUSH (charset); - p1 = p; - - PATPUSH ((1 << BYTEWIDTH) / BYTEWIDTH); - /* Clear the whole map */ - memset (b, '\0', (1 << BYTEWIDTH) / BYTEWIDTH); - /* Read in characters and ranges, setting map bits */ - while (1) - { - PATFETCH (c); - if (c == ']' && p != p1 + 1) break; - if (*p == '-' && p[1] != ']') - { - PATFETCH (c1); - PATFETCH (c1); - while (c <= c1) - b[c / BYTEWIDTH] |= 1 << (c % BYTEWIDTH), c++; - } - else - { - b[c / BYTEWIDTH] |= 1 << (c % BYTEWIDTH); - } - } - /* Discard any bitmap bytes that are all 0 at the end of the map. - Decrement the map-length byte too. */ - while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) - b[-1]--; - b += b[-1]; - break; - - case '(': - if (! (obscure_syntax & RE_NO_BK_PARENS)) - goto normal_char; - else - goto handle_open; - - case ')': - if (! (obscure_syntax & RE_NO_BK_PARENS)) - goto normal_char; - else - goto handle_close; - - case '\n': - if (! (obscure_syntax & RE_NEWLINE_OR)) - goto normal_char; - else - goto handle_bar; - - case '|': - if (! (obscure_syntax & RE_NO_BK_VBAR)) - goto normal_char; - else - goto handle_bar; - - case '\\': - if (p == pend) goto invalid_pattern; - PATFETCH_RAW (c); - switch (c) - { - case '(': - if (obscure_syntax & RE_NO_BK_PARENS) - goto normal_backsl; - handle_open: - if (stackp == stacke) goto nesting_too_deep; - if (regnum < RE_NREGS) - { - PATPUSH (start_memory); - PATPUSH (regnum); - } - *stackp++ = b - bufp->buffer; - *stackp++ = fixup_jump ? fixup_jump - bufp->buffer + 1 : 0; - *stackp++ = regnum++; - *stackp++ = begalt - bufp->buffer; - fixup_jump = 0; - laststart = 0; - begalt = b; - break; - - case ')': - if (obscure_syntax & RE_NO_BK_PARENS) - goto normal_backsl; - handle_close: - if (stackp == stackb) goto unmatched_close; - begalt = *--stackp + bufp->buffer; - if (fixup_jump) - store_jump (fixup_jump, jump, b); - if (stackp[-1] < RE_NREGS) - { - PATPUSH (stop_memory); - PATPUSH (stackp[-1]); - } - stackp -= 2; - fixup_jump = 0; - if (*stackp) - fixup_jump = *stackp + bufp->buffer - 1; - laststart = *--stackp + bufp->buffer; - break; - - case '|': - if (obscure_syntax & RE_NO_BK_VBAR) - goto normal_backsl; - handle_bar: - insert_jump (on_failure_jump, begalt, b + 6, b); - pending_exact = 0; - b += 3; - if (fixup_jump) - store_jump (fixup_jump, jump, b); - fixup_jump = b; - b += 3; - laststart = 0; - begalt = b; - break; - -#ifdef emacs - case '=': - PATPUSH (at_dot); - break; - - case 's': - laststart = b; - PATPUSH (syntaxspec); - PATFETCH (c); - PATPUSH (syntax_spec_code[c]); - break; - - case 'S': - laststart = b; - PATPUSH (notsyntaxspec); - PATFETCH (c); - PATPUSH (syntax_spec_code[c]); - break; -#endif /* emacs */ - - case 'w': - laststart = b; - PATPUSH (wordchar); - break; - - case 'W': - laststart = b; - PATPUSH (notwordchar); - break; - - case '<': - PATPUSH (wordbeg); - break; - - case '>': - PATPUSH (wordend); - break; - - case 'b': - PATPUSH (wordbound); - break; - - case 'B': - PATPUSH (notwordbound); - break; - - case '`': - PATPUSH (begbuf); - break; - - case '\'': - PATPUSH (endbuf); - break; - - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - c1 = c - '0'; - if (c1 >= regnum) - goto normal_char; - for (stackt = stackp - 2; stackt > stackb; stackt -= 4) - if (*stackt == c1) - goto normal_char; - laststart = b; - PATPUSH (duplicate); - PATPUSH (c1); - break; - - case '+': - case '?': - if (obscure_syntax & RE_BK_PLUS_QM) - goto handle_plus; - - default: - normal_backsl: - /* You might think it would be useful for \ to mean - not to translate; but if we don't translate it - it will never match anything. */ - if (translate) c = translate[c]; - goto normal_char; - } - break; - - default: - normal_char: - if (!pending_exact || pending_exact + *pending_exact + 1 != b - || *pending_exact == 0177 || *p == '*' || *p == '^' - || ((obscure_syntax & RE_BK_PLUS_QM) - ? *p == '\\' && (p[1] == '+' || p[1] == '?') - : (*p == '+' || *p == '?'))) - { - laststart = b; - PATPUSH (exactn); - pending_exact = b; - PATPUSH (0); - } - PATPUSH (c); - (*pending_exact)++; - } - } - - if (fixup_jump) - store_jump (fixup_jump, jump, b); - - if (stackp != stackb) goto unmatched_open; - - bufp->used = b - bufp->buffer; - return 0; - - invalid_pattern: - return "Invalid regular expression"; - - unmatched_open: - return "Unmatched \\("; - - unmatched_close: - return "Unmatched \\)"; - - end_of_pattern: - return "Premature end of regular expression"; - - nesting_too_deep: - return "Nesting too deep"; - - too_big: - return "Regular expression too big"; - - memory_exhausted: - return "Memory exhausted"; -} - -/* Store where `from' points a jump operation to jump to where `to' points. - `opcode' is the opcode to store. */ - -static void -store_jump (from, opcode, to) - char *from, *to; - char opcode; -{ - from[0] = opcode; - from[1] = (to - (from + 3)) & 0377; - from[2] = (to - (from + 3)) >> 8; -} - -/* Open up space at char FROM, and insert there a jump to TO. - CURRENT_END gives te end of the storage no in use, - so we know how much data to copy up. - OP is the opcode of the jump to insert. - - If you call this function, you must zero out pending_exact. */ - -static void -insert_jump (op, from, to, current_end) - char op; - char *from, *to, *current_end; -{ - register char *pto = current_end + 3; - register char *pfrom = current_end; - while (pfrom != from) - *--pto = *--pfrom; - store_jump (from, op, to); -} - -/* Given a pattern, compute a fastmap from it. - The fastmap records which of the (1 << BYTEWIDTH) possible characters - can start a string that matches the pattern. - This fastmap is used by re_search to skip quickly over totally implausible text. - - The caller must supply the address of a (1 << BYTEWIDTH)-byte data area - as bufp->fastmap. - The other components of bufp describe the pattern to be used. */ - -void -re_compile_fastmap (bufp) - struct re_pattern_buffer *bufp; -{ - unsigned char *pattern = (unsigned char *) bufp->buffer; - int size = bufp->used; - register char *fastmap = bufp->fastmap; - register unsigned char *p = pattern; - register unsigned char *pend = pattern + size; - register int j; - unsigned char *translate = (unsigned char *) bufp->translate; - - unsigned char *stackb[NFAILURES]; - unsigned char **stackp = stackb; - - memset (fastmap, '\0', (1 << BYTEWIDTH)); - bufp->fastmap_accurate = 1; - bufp->can_be_null = 0; - - while (p) - { - if (p == pend) - { - bufp->can_be_null = 1; - break; - } -#ifdef SWITCH_ENUM_BUG - switch ((int) ((enum regexpcode) *p++)) -#else - switch ((enum regexpcode) *p++) -#endif - { - case exactn: - if (translate) - fastmap[translate[p[1]]] = 1; - else - fastmap[p[1]] = 1; - break; - - case begline: - case before_dot: - case at_dot: - case after_dot: - case begbuf: - case endbuf: - case wordbound: - case notwordbound: - case wordbeg: - case wordend: - continue; - - case endline: - if (translate) - fastmap[translate['\n']] = 1; - else - fastmap['\n'] = 1; - if (bufp->can_be_null != 1) - bufp->can_be_null = 2; - break; - - case finalize_jump: - case maybe_finalize_jump: - case jump: - case dummy_failure_jump: - bufp->can_be_null = 1; - j = *p++ & 0377; - j += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p += j + 1; /* The 1 compensates for missing ++ above */ - if (j > 0) - continue; - /* Jump backward reached implies we just went through - the body of a loop and matched nothing. - Opcode jumped to should be an on_failure_jump. - Just treat it like an ordinary jump. - For a * loop, it has pushed its failure point already; - if so, discard that as redundant. */ - if ((enum regexpcode) *p != on_failure_jump) - continue; - p++; - j = *p++ & 0377; - j += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p += j + 1; /* The 1 compensates for missing ++ above */ - if (stackp != stackb && *stackp == p) - stackp--; - continue; - - case on_failure_jump: - j = *p++ & 0377; - j += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p++; - *++stackp = p + j; - continue; - - case start_memory: - case stop_memory: - p++; - continue; - - case duplicate: - bufp->can_be_null = 1; - fastmap['\n'] = 1; - case anychar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (j != '\n') - fastmap[j] = 1; - if (bufp->can_be_null) - return; - /* Don't return; check the alternative paths - so we can set can_be_null if appropriate. */ - break; - - case wordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == Sword) - fastmap[j] = 1; - break; - - case notwordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != Sword) - fastmap[j] = 1; - break; - -#ifdef emacs - case syntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == (enum syntaxcode) k) - fastmap[j] = 1; - break; - - case notsyntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != (enum syntaxcode) k) - fastmap[j] = 1; - break; -#endif /* emacs */ - - case charset: - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) - { - if (translate) - fastmap[translate[j]] = 1; - else - fastmap[j] = 1; - } - break; - - case charset_not: - /* Chars beyond end of map must be allowed */ - for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) - if (translate) - fastmap[translate[j]] = 1; - else - fastmap[j] = 1; - - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) - { - if (translate) - fastmap[translate[j]] = 1; - else - fastmap[j] = 1; - } - break; - } - - /* Get here means we have successfully found the possible starting characters - of one path of the pattern. We need not follow this path any farther. - Instead, look at the next alternative remembered in the stack. */ - if (stackp != stackb) - p = *stackp--; - else - break; - } -} - -/* Like re_search_2, below, but only one string is specified. */ - -int -re_search (pbufp, string, size, startpos, range, regs) - struct re_pattern_buffer *pbufp; - char *string; - int size, startpos, range; - struct re_registers *regs; -{ - return re_search_2 (pbufp, 0, 0, string, size, startpos, range, regs, size); -} - -/* Like re_match_2 but tries first a match starting at index STARTPOS, - then at STARTPOS + 1, and so on. - RANGE is the number of places to try before giving up. - If RANGE is negative, the starting positions tried are - STARTPOS, STARTPOS - 1, etc. - It is up to the caller to make sure that range is not so large - as to take the starting position outside of the input strings. - -The value returned is the position at which the match was found, - or -1 if no match was found, - or -2 if error (such as failure stack overflow). */ - -int -re_search_2 (pbufp, string1, size1, string2, size2, startpos, range, regs, mstop) - struct re_pattern_buffer *pbufp; - char *string1, *string2; - int size1, size2; - int startpos; - register int range; - struct re_registers *regs; - int mstop; -{ - register char *fastmap = pbufp->fastmap; - register unsigned char *translate = (unsigned char *) pbufp->translate; - int total = size1 + size2; - int val; - - /* Update the fastmap now if not correct already */ - if (fastmap && !pbufp->fastmap_accurate) - re_compile_fastmap (pbufp); - - /* Don't waste time in a long search for a pattern - that says it is anchored. */ - if (pbufp->used > 0 && (enum regexpcode) pbufp->buffer[0] == begbuf - && range > 0) - { - if (startpos > 0) - return -1; - else - range = 1; - } - - while (1) - { - /* If a fastmap is supplied, skip quickly over characters - that cannot possibly be the start of a match. - Note, however, that if the pattern can possibly match - the null string, we must test it at each starting point - so that we take the first null string we get. */ - - if (fastmap && startpos < total && pbufp->can_be_null != 1) - { - if (range > 0) - { - register int lim = 0; - register unsigned char *p; - int irange = range; - if (startpos < size1 && startpos + range >= size1) - lim = range - (size1 - startpos); - - p = ((unsigned char *) - &(startpos >= size1 ? string2 - size1 : string1)[startpos]); - - if (translate) - { - while (range > lim && !fastmap[translate[*p++]]) - range--; - } - else - { - while (range > lim && !fastmap[*p++]) - range--; - } - startpos += irange - range; - } - else - { - register unsigned char c; - if (startpos >= size1) - c = string2[startpos - size1]; - else - c = string1[startpos]; - c &= 0xff; - if (translate ? !fastmap[translate[c]] : !fastmap[c]) - goto advance; - } - } - - if (range >= 0 && startpos == total - && fastmap && pbufp->can_be_null == 0) - return -1; - - val = re_match_2 (pbufp, string1, size1, string2, size2, startpos, regs, mstop); - if (0 <= val) - { - if (val == -2) - return -2; - return startpos; - } - -#ifdef C_ALLOCA - alloca (0); -#endif /* C_ALLOCA */ - - advance: - if (!range) break; - if (range > 0) range--, startpos++; else range++, startpos--; - } - return -1; -} - -#ifndef emacs /* emacs never uses this */ -int -re_match (pbufp, string, size, pos, regs) - struct re_pattern_buffer *pbufp; - char *string; - int size, pos; - struct re_registers *regs; -{ - return re_match_2 (pbufp, 0, 0, string, size, pos, regs, size); -} -#endif /* emacs */ - -/* Maximum size of failure stack. Beyond this, overflow is an error. */ - -int re_max_failures = 2000; - -static int memcmp_translate(); -/* Match the pattern described by PBUFP - against data which is the virtual concatenation of STRING1 and STRING2. - SIZE1 and SIZE2 are the sizes of the two data strings. - Start the match at position POS. - Do not consider matching past the position MSTOP. - - If pbufp->fastmap is nonzero, then it had better be up to date. - - The reason that the data to match are specified as two components - which are to be regarded as concatenated - is so this function can be used directly on the contents of an Emacs buffer. - - -1 is returned if there is no match. -2 is returned if there is - an error (such as match stack overflow). Otherwise the value is the length - of the substring which was matched. */ - -int -re_match_2 (pbufp, string1, size1, string2, size2, pos, regs, mstop) - struct re_pattern_buffer *pbufp; - unsigned char *string1, *string2; - int size1, size2; - int pos; - struct re_registers *regs; - int mstop; -{ - register unsigned char *p = (unsigned char *) pbufp->buffer; - register unsigned char *pend = p + pbufp->used; - /* End of first string */ - unsigned char *end1; - /* End of second string */ - unsigned char *end2; - /* Pointer just past last char to consider matching */ - unsigned char *end_match_1, *end_match_2; - register unsigned char *d, *dend; - register int mcnt; - unsigned char *translate = (unsigned char *) pbufp->translate; - - /* Failure point stack. Each place that can handle a failure further down the line - pushes a failure point on this stack. It consists of two char *'s. - The first one pushed is where to resume scanning the pattern; - the second pushed is where to resume scanning the strings. - If the latter is zero, the failure point is a "dummy". - If a failure happens and the innermost failure point is dormant, - it discards that failure point and tries the next one. */ - - unsigned char *initial_stack[2 * NFAILURES]; - unsigned char **stackb = initial_stack; - unsigned char **stackp = stackb, **stacke = &stackb[2 * NFAILURES]; - - /* Information on the "contents" of registers. - These are pointers into the input strings; they record - just what was matched (on this attempt) by some part of the pattern. - The start_memory command stores the start of a register's contents - and the stop_memory command stores the end. - - At that point, regstart[regnum] points to the first character in the register, - regend[regnum] points to the first character beyond the end of the register, - regstart_seg1[regnum] is true iff regstart[regnum] points into string1, - and regend_seg1[regnum] is true iff regend[regnum] points into string1. */ - - unsigned char *regstart[RE_NREGS]; - unsigned char *regend[RE_NREGS]; - unsigned char regstart_seg1[RE_NREGS], regend_seg1[RE_NREGS]; - - /* Set up pointers to ends of strings. - Don't allow the second string to be empty unless both are empty. */ - if (!size2) - { - string2 = string1; - size2 = size1; - string1 = 0; - size1 = 0; - } - end1 = string1 + size1; - end2 = string2 + size2; - - /* Compute where to stop matching, within the two strings */ - if (mstop <= size1) - { - end_match_1 = string1 + mstop; - end_match_2 = string2; - } - else - { - end_match_1 = end1; - end_match_2 = string2 + mstop - size1; - } - - /* Initialize \) text positions to -1 - to mark ones that no \( or \) has been seen for. */ - - for (mcnt = 0; mcnt < sizeof (regend) / sizeof (*regend); mcnt++) - regend[mcnt] = (unsigned char *) -1; - - /* `p' scans through the pattern as `d' scans through the data. - `dend' is the end of the input string that `d' points within. - `d' is advanced into the following input string whenever necessary, - but this happens before fetching; - therefore, at the beginning of the loop, - `d' can be pointing at the end of a string, - but it cannot equal string2. */ - - if (pos <= size1) - d = string1 + pos, dend = end_match_1; - else - d = string2 + pos - size1, dend = end_match_2; - -/* Write PREFETCH; just before fetching a character with *d. */ -#define PREFETCH \ - while (d == dend) \ - { if (dend == end_match_2) goto fail; /* end of string2 => failure */ \ - d = string2; /* end of string1 => advance to string2. */ \ - dend = end_match_2; } - - /* This loop loops over pattern commands. - It exits by returning from the function if match is complete, - or it drops through if match fails at this starting point in the input data. */ - - while (1) - { - if (p == pend) - /* End of pattern means we have succeeded! */ - { - /* If caller wants register contents data back, convert it to indices */ - if (regs) - { - regs->start[0] = pos; - if (dend == end_match_1) - regs->end[0] = d - string1; - else - regs->end[0] = d - string2 + size1; - for (mcnt = 1; mcnt < RE_NREGS; mcnt++) - { - if (regend[mcnt] == (unsigned char *) -1) - { - regs->start[mcnt] = -1; - regs->end[mcnt] = -1; - continue; - } - if (regstart_seg1[mcnt]) - regs->start[mcnt] = regstart[mcnt] - string1; - else - regs->start[mcnt] = regstart[mcnt] - string2 + size1; - if (regend_seg1[mcnt]) - regs->end[mcnt] = regend[mcnt] - string1; - else - regs->end[mcnt] = regend[mcnt] - string2 + size1; - } - } - if (dend == end_match_1) - return (d - string1 - pos); - else - return d - string2 + size1 - pos; - } - - /* Otherwise match next pattern command */ -#ifdef SWITCH_ENUM_BUG - switch ((int) ((enum regexpcode) *p++)) -#else - switch ((enum regexpcode) *p++) -#endif - { - - /* \( is represented by a start_memory, \) by a stop_memory. - Both of those commands contain a "register number" argument. - The text matched within the \( and \) is recorded under that number. - Then, \ turns into a `duplicate' command which - is followed by the numeric value of as the register number. */ - - case start_memory: - regstart[*p] = d; - regstart_seg1[*p++] = (dend == end_match_1); - break; - - case stop_memory: - regend[*p] = d; - regend_seg1[*p++] = (dend == end_match_1); - break; - - case duplicate: - { - int regno = *p++; /* Get which register to match against */ - register unsigned char *d2, *dend2; - - d2 = regstart[regno]; - dend2 = ((regstart_seg1[regno] == regend_seg1[regno]) - ? regend[regno] : end_match_1); - while (1) - { - /* Advance to next segment in register contents, if necessary */ - while (d2 == dend2) - { - if (dend2 == end_match_2) break; - if (dend2 == regend[regno]) break; - d2 = string2, dend2 = regend[regno]; /* end of string1 => advance to string2. */ - } - /* At end of register contents => success */ - if (d2 == dend2) break; - - /* Advance to next segment in data being matched, if necessary */ - PREFETCH; - - /* mcnt gets # consecutive chars to compare */ - mcnt = dend - d; - if (mcnt > dend2 - d2) - mcnt = dend2 - d2; - /* Compare that many; failure if mismatch, else skip them. */ - if (translate ? memcmp_translate (d, d2, mcnt, translate) : memcmp (d, d2, mcnt)) - goto fail; - d += mcnt, d2 += mcnt; - } - } - break; - - case anychar: - /* fetch a data character */ - PREFETCH; - /* Match anything but a newline. */ - if ((translate ? translate[*d++] : *d++) == '\n') - goto fail; - break; - - case charset: - case charset_not: - { - /* Nonzero for charset_not */ - int not = 0; - register int c; - if (*(p - 1) == (unsigned char) charset_not) - not = 1; - - /* fetch a data character */ - PREFETCH; - - if (translate) - c = translate [*d]; - else - c = *d; - - if (c < *p * BYTEWIDTH - && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - p += 1 + *p; - - if (!not) goto fail; - d++; - break; - } - - case begline: - if (d == string1 || d[-1] == '\n') - break; - goto fail; - - case endline: - if (d == end2 - || (d == end1 ? (size2 == 0 || *string2 == '\n') : *d == '\n')) - break; - goto fail; - - /* "or" constructs ("|") are handled by starting each alternative - with an on_failure_jump that points to the start of the next alternative. - Each alternative except the last ends with a jump to the joining point. - (Actually, each jump except for the last one really jumps - to the following jump, because tensioning the jumps is a hassle.) */ - - /* The start of a stupid repeat has an on_failure_jump that points - past the end of the repeat text. - This makes a failure point so that, on failure to match a repetition, - matching restarts past as many repetitions have been found - with no way to fail and look for another one. */ - - /* A smart repeat is similar but loops back to the on_failure_jump - so that each repetition makes another failure point. */ - - case on_failure_jump: - if (stackp == stacke) - { - unsigned char **stackx; - if (stacke - stackb > re_max_failures * 2) - return -2; - stackx = (unsigned char **) alloca (2 * (stacke - stackb) - * sizeof (char *)); - memcpy (stackx, stackb, (stacke - stackb) * sizeof (char *)); - stackp = stackx + (stackp - stackb); - stacke = stackx + 2 * (stacke - stackb); - stackb = stackx; - } - mcnt = *p++ & 0377; - mcnt += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p++; - *stackp++ = mcnt + p; - *stackp++ = d; - break; - - /* The end of a smart repeat has an maybe_finalize_jump back. - Change it either to a finalize_jump or an ordinary jump. */ - - case maybe_finalize_jump: - mcnt = *p++ & 0377; - mcnt += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p++; - { - register unsigned char *p2 = p; - /* Compare what follows with the begining of the repeat. - If we can establish that there is nothing that they would - both match, we can change to finalize_jump */ - while (p2 != pend - && (*p2 == (unsigned char) stop_memory - || *p2 == (unsigned char) start_memory)) - p2++; - if (p2 == pend) - p[-3] = (unsigned char) finalize_jump; - else if (*p2 == (unsigned char) exactn - || *p2 == (unsigned char) endline) - { - register int c = *p2 == (unsigned char) endline ? '\n' : p2[2]; - register unsigned char *p1 = p + mcnt; - /* p1[0] ... p1[2] are an on_failure_jump. - Examine what follows that */ - if (p1[3] == (unsigned char) exactn && p1[5] != c) - p[-3] = (unsigned char) finalize_jump; - else if (p1[3] == (unsigned char) charset - || p1[3] == (unsigned char) charset_not) - { - int not = p1[3] == (unsigned char) charset_not; - if (c < p1[4] * BYTEWIDTH - && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - /* not is 1 if c would match */ - /* That means it is not safe to finalize */ - if (!not) - p[-3] = (unsigned char) finalize_jump; - } - } - } - p -= 2; - if (p[-1] != (unsigned char) finalize_jump) - { - p[-1] = (unsigned char) jump; - goto nofinalize; - } - - /* The end of a stupid repeat has a finalize-jump - back to the start, where another failure point will be made - which will point after all the repetitions found so far. */ - - case finalize_jump: - stackp -= 2; - - case jump: - nofinalize: - mcnt = *p++ & 0377; - mcnt += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p += mcnt + 1; /* The 1 compensates for missing ++ above */ - break; - - case dummy_failure_jump: - if (stackp == stacke) - { - unsigned char **stackx - = (unsigned char **) alloca (2 * (stacke - stackb) - * sizeof (char *)); - memcpy (stackx, stackb, (stacke - stackb) * sizeof (char *)); - stackp = stackx + (stackp - stackb); - stacke = stackx + 2 * (stacke - stackb); - stackb = stackx; - } - *stackp++ = 0; - *stackp++ = 0; - goto nofinalize; - - case wordbound: - if (d == string1 /* Points to first char */ - || d == end2 /* Points to end */ - || (d == end1 && size2 == 0)) /* Points to end */ - break; - if ((SYNTAX (d[-1]) == Sword) - != (SYNTAX (d == end1 ? *string2 : *d) == Sword)) - break; - goto fail; - - case notwordbound: - if (d == string1 /* Points to first char */ - || d == end2 /* Points to end */ - || (d == end1 && size2 == 0)) /* Points to end */ - goto fail; - if ((SYNTAX (d[-1]) == Sword) - != (SYNTAX (d == end1 ? *string2 : *d) == Sword)) - goto fail; - break; - - case wordbeg: - if (d == end2 /* Points to end */ - || (d == end1 && size2 == 0) /* Points to end */ - || SYNTAX (* (d == end1 ? string2 : d)) != Sword) /* Next char not a letter */ - goto fail; - if (d == string1 /* Points to first char */ - || SYNTAX (d[-1]) != Sword) /* prev char not letter */ - break; - goto fail; - - case wordend: - if (d == string1 /* Points to first char */ - || SYNTAX (d[-1]) != Sword) /* prev char not letter */ - goto fail; - if (d == end2 /* Points to end */ - || (d == end1 && size2 == 0) /* Points to end */ - || SYNTAX (d == end1 ? *string2 : *d) != Sword) /* Next char not a letter */ - break; - goto fail; - -#ifdef emacs - case before_dot: - if (((d - string2 <= (unsigned) size2) - ? d - bf_p2 : d - bf_p1) - <= point) - goto fail; - break; - - case at_dot: - if (((d - string2 <= (unsigned) size2) - ? d - bf_p2 : d - bf_p1) - == point) - goto fail; - break; - - case after_dot: - if (((d - string2 <= (unsigned) size2) - ? d - bf_p2 : d - bf_p1) - >= point) - goto fail; - break; - - case wordchar: - mcnt = (int) Sword; - goto matchsyntax; - - case syntaxspec: - mcnt = *p++; - matchsyntax: - PREFETCH; - if (SYNTAX (*d++) != (enum syntaxcode) mcnt) goto fail; - break; - - case notwordchar: - mcnt = (int) Sword; - goto matchnotsyntax; - - case notsyntaxspec: - mcnt = *p++; - matchnotsyntax: - PREFETCH; - if (SYNTAX (*d++) == (enum syntaxcode) mcnt) goto fail; - break; -#else - case wordchar: - PREFETCH; - if (SYNTAX (*d++) == 0) goto fail; - break; - - case notwordchar: - PREFETCH; - if (SYNTAX (*d++) != 0) goto fail; - break; -#endif /* not emacs */ - - case begbuf: - if (d == string1) /* Note, d cannot equal string2 */ - break; /* unless string1 == string2. */ - goto fail; - - case endbuf: - if (d == end2 || (d == end1 && size2 == 0)) - break; - goto fail; - - case exactn: - /* Match the next few pattern characters exactly. - mcnt is how many characters to match. */ - mcnt = *p++; - if (translate) - { - do - { - PREFETCH; - if (translate[*d++] != *p++) goto fail; - } - while (--mcnt); - } - else - { - do - { - PREFETCH; - if (*d++ != *p++) goto fail; - } - while (--mcnt); - } - break; - } - continue; /* Successfully matched one pattern command; keep matching */ - - /* Jump here if any matching operation fails. */ - fail: - if (stackp != stackb) - /* A restart point is known. Restart there and pop it. */ - { - if (!stackp[-2]) - { /* If innermost failure point is dormant, flush it and keep looking */ - stackp -= 2; - goto fail; - } - d = *--stackp; - p = *--stackp; - if (d >= string1 && d <= end1) - dend = end_match_1; - } - else break; /* Matching at this starting point really fails! */ - } - return -1; /* Failure to match */ -} - -static int -memcmp_translate (s1, s2, len, translate) - unsigned char *s1, *s2; - register int len; - unsigned char *translate; -{ - register unsigned char *p1 = s1, *p2 = s2; - while (len) - { - if (translate [*p1++] != translate [*p2++]) return 1; - len--; - } - return 0; -} - -/* Entry points compatible with bsd4.2 regex library */ - -#ifndef emacs - -static struct re_pattern_buffer re_comp_buf; - -char * -re_comp (s) - const char *s; -{ - if (!s) - { - if (!re_comp_buf.buffer) - return "No previous regular expression"; - return 0; - } - - if (!re_comp_buf.buffer) - { - if (!(re_comp_buf.buffer = (char *) malloc (200))) - return "Memory exhausted"; - re_comp_buf.allocated = 200; - if (!(re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH))) - return "Memory exhausted"; - } - return re_compile_pattern (s, strlen (s), &re_comp_buf); -} - -int -re_exec (s) - char *s; -{ - int len = strlen (s); - return 0 <= re_search (&re_comp_buf, s, len, 0, len, 0); -} - -#endif /* emacs */ - -#ifdef test - -#include - -/* Indexed by a character, gives the upper case equivalent of the character */ - -static char upcase[0400] = - { 000, 001, 002, 003, 004, 005, 006, 007, - 010, 011, 012, 013, 014, 015, 016, 017, - 020, 021, 022, 023, 024, 025, 026, 027, - 030, 031, 032, 033, 034, 035, 036, 037, - 040, 041, 042, 043, 044, 045, 046, 047, - 050, 051, 052, 053, 054, 055, 056, 057, - 060, 061, 062, 063, 064, 065, 066, 067, - 070, 071, 072, 073, 074, 075, 076, 077, - 0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107, - 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, - 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, - 0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137, - 0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107, - 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, - 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, - 0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177, - 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207, - 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217, - 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227, - 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237, - 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247, - 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257, - 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, - 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, - 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307, - 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317, - 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327, - 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, - 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347, - 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357, - 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, - 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377 - }; - -main (argc, argv) - int argc; - char **argv; -{ - char pat[80]; - struct re_pattern_buffer buf; - int i; - char c; - char fastmap[(1 << BYTEWIDTH)]; - - /* Allow a command argument to specify the style of syntax. */ - if (argc > 1) - obscure_syntax = atoi (argv[1]); - - buf.allocated = 40; - buf.buffer = (char *) malloc (buf.allocated); - buf.fastmap = fastmap; - buf.translate = upcase; - - while (1) - { - gets (pat); - - if (*pat) - { - re_compile_pattern (pat, strlen(pat), &buf); - - for (i = 0; i < buf.used; i++) - printchar (buf.buffer[i]); - - putchar_unfiltered ('\n'); - - printf_unfiltered ("%d allocated, %d used.\n", buf.allocated, buf.used); - - re_compile_fastmap (&buf); - printf_unfiltered ("Allowed by fastmap: "); - for (i = 0; i < (1 << BYTEWIDTH); i++) - if (fastmap[i]) printchar (i); - putchar_unfiltered ('\n'); - } - - gets (pat); /* Now read the string to match against */ - - i = re_match (&buf, pat, strlen (pat), 0, 0); - printf_unfiltered ("Match value %d.\n", i); - } -} - -#ifdef NOTDEF -print_buf (bufp) - struct re_pattern_buffer *bufp; -{ - int i; - - printf_unfiltered ("buf is :\n----------------\n"); - for (i = 0; i < bufp->used; i++) - printchar (bufp->buffer[i]); - - printf_unfiltered ("\n%d allocated, %d used.\n", bufp->allocated, bufp->used); - - printf_unfiltered ("Allowed by fastmap: "); - for (i = 0; i < (1 << BYTEWIDTH); i++) - if (bufp->fastmap[i]) - printchar (i); - printf_unfiltered ("\nAllowed by translate: "); - if (bufp->translate) - for (i = 0; i < (1 << BYTEWIDTH); i++) - if (bufp->translate[i]) - printchar (i); - printf_unfiltered ("\nfastmap is%s accurate\n", bufp->fastmap_accurate ? "" : "n't"); - printf_unfiltered ("can %s be null\n----------", bufp->can_be_null ? "" : "not"); -} -#endif - -printchar (c) - char c; -{ - if (c < 041 || c >= 0177) - { - putchar_unfiltered ('\\'); - putchar_unfiltered (((c >> 6) & 3) + '0'); - putchar_unfiltered (((c >> 3) & 7) + '0'); - putchar_unfiltered ((c & 7) + '0'); - } - else - putchar_unfiltered (c); -} - -error (string) - char *string; -{ - puts_unfiltered (string); - exit (1); -} - -#endif /* test */ diff --git a/gnu/usr.bin/gdb/gdb/regex.h b/gnu/usr.bin/gdb/gdb/regex.h deleted file mode 100644 index a4ed6d3..0000000 --- a/gnu/usr.bin/gdb/gdb/regex.h +++ /dev/null @@ -1,181 +0,0 @@ -/* Definitions for data structures callers pass the regex library. - Copyright (C) 1985, 1989 Free Software Foundation, Inc. - -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 of the License, 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 this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Define number of parens for which we record the beginnings and ends. - This affects how much space the `struct re_registers' type takes up. */ -#ifndef RE_NREGS -#define RE_NREGS 10 -#endif - -/* These bits are used in the obscure_syntax variable to choose among - alternative regexp syntaxes. */ - -/* 1 means plain parentheses serve as grouping, and backslash - parentheses are needed for literal searching. - 0 means backslash-parentheses are grouping, and plain parentheses - are for literal searching. */ -#define RE_NO_BK_PARENS 1 - -/* 1 means plain | serves as the "or"-operator, and \| is a literal. - 0 means \| serves as the "or"-operator, and | is a literal. */ -#define RE_NO_BK_VBAR 2 - -/* 0 means plain + or ? serves as an operator, and \+, \? are literals. - 1 means \+, \? are operators and plain +, ? are literals. */ -#define RE_BK_PLUS_QM 4 - -/* 1 means | binds tighter than ^ or $. - 0 means the contrary. */ -#define RE_TIGHT_VBAR 8 - -/* 1 means treat \n as an _OR operator - 0 means treat it as a normal character */ -#define RE_NEWLINE_OR 16 - -/* 0 means that a special characters (such as *, ^, and $) always have - their special meaning regardless of the surrounding context. - 1 means that special characters may act as normal characters in some - contexts. Specifically, this applies to: - ^ - only special at the beginning, or after ( or | - $ - only special at the end, or before ) or | - *, +, ? - only special when not after the beginning, (, or | */ -#define RE_CONTEXT_INDEP_OPS 32 - -/* Now define combinations of bits for the standard possibilities. */ -#define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS) -#define RE_SYNTAX_EGREP (RE_SYNTAX_AWK | RE_NEWLINE_OR) -#define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR) -#define RE_SYNTAX_EMACS 0 - -/* This data structure is used to represent a compiled pattern. */ - -struct re_pattern_buffer - { - char *buffer; /* Space holding the compiled pattern commands. */ - int allocated; /* Size of space that buffer points to */ - int used; /* Length of portion of buffer actually occupied */ - char *fastmap; /* Pointer to fastmap, if any, or zero if none. */ - /* re_search uses the fastmap, if there is one, - to skip quickly over totally implausible characters */ - char *translate; /* Translate table to apply to all characters before comparing. - Or zero for no translation. - The translation is applied to a pattern when it is compiled - and to data when it is matched. */ - char fastmap_accurate; - /* Set to zero when a new pattern is stored, - set to one when the fastmap is updated from it. */ - char can_be_null; /* Set to one by compiling fastmap - if this pattern might match the null string. - It does not necessarily match the null string - in that case, but if this is zero, it cannot. - 2 as value means can match null string - but at end of range or before a character - listed in the fastmap. */ - }; - -/* Structure to store "register" contents data in. - - Pass the address of such a structure as an argument to re_match, etc., - if you want this information back. - - start[i] and end[i] record the string matched by \( ... \) grouping i, - for i from 1 to RE_NREGS - 1. - start[0] and end[0] record the entire string matched. */ - -struct re_registers - { - int start[RE_NREGS]; - int end[RE_NREGS]; - }; - -/* These are the command codes that appear in compiled regular expressions, one per byte. - Some command codes are followed by argument bytes. - A command code can specify any interpretation whatever for its arguments. - Zero-bytes may appear in the compiled regular expression. */ - -enum regexpcode - { - unused, - exactn, /* followed by one byte giving n, and then by n literal bytes */ - begline, /* fails unless at beginning of line */ - endline, /* fails unless at end of line */ - jump, /* followed by two bytes giving relative address to jump to */ - on_failure_jump, /* followed by two bytes giving relative address of place - to resume at in case of failure. */ - finalize_jump, /* Throw away latest failure point and then jump to address. */ - maybe_finalize_jump, /* Like jump but finalize if safe to do so. - This is used to jump back to the beginning - of a repeat. If the command that follows - this jump is clearly incompatible with the - one at the beginning of the repeat, such that - we can be sure that there is no use backtracking - out of repetitions already completed, - then we finalize. */ - dummy_failure_jump, /* jump, and push a dummy failure point. - This failure point will be thrown away - if an attempt is made to use it for a failure. - A + construct makes this before the first repeat. */ - anychar, /* matches any one character */ - charset, /* matches any one char belonging to specified set. - First following byte is # bitmap bytes. - Then come bytes for a bit-map saying which chars are in. - Bits in each byte are ordered low-bit-first. - A character is in the set if its bit is 1. - A character too large to have a bit in the map - is automatically not in the set */ - charset_not, /* similar but match any character that is NOT one of those specified */ - start_memory, /* starts remembering the text that is matched - and stores it in a memory register. - followed by one byte containing the register number. - Register numbers must be in the range 0 through NREGS. */ - stop_memory, /* stops remembering the text that is matched - and stores it in a memory register. - followed by one byte containing the register number. - Register numbers must be in the range 0 through NREGS. */ - duplicate, /* match a duplicate of something remembered. - Followed by one byte containing the index of the memory register. */ - before_dot, /* Succeeds if before dot */ - at_dot, /* Succeeds if at dot */ - after_dot, /* Succeeds if after dot */ - begbuf, /* Succeeds if at beginning of buffer */ - endbuf, /* Succeeds if at end of buffer */ - wordchar, /* Matches any word-constituent character */ - notwordchar, /* Matches any char that is not a word-constituent */ - wordbeg, /* Succeeds if at word beginning */ - wordend, /* Succeeds if at word end */ - wordbound, /* Succeeds if at a word boundary */ - notwordbound, /* Succeeds if not at a word boundary */ - syntaxspec, /* Matches any character whose syntax is specified. - followed by a byte which contains a syntax code, Sword or such like */ - notsyntaxspec /* Matches any character whose syntax differs from the specified. */ - }; - -extern char *re_compile_pattern (); -/* Is this really advertised? */ -extern void re_compile_fastmap (); -extern int re_search (), re_search_2 (); -extern int re_match (), re_match_2 (); - -/* 4.2 bsd compatibility (yuck) */ -extern char *re_comp (); -extern int re_exec (); - -#ifdef SYNTAX_TABLE -extern char *re_syntax_table; -#endif - -extern int re_set_syntax (); diff --git a/gnu/usr.bin/gdb/gdb/y.tab.h b/gnu/usr.bin/gdb/gdb/y.tab.h deleted file mode 100644 index 62e0883..0000000 --- a/gnu/usr.bin/gdb/gdb/y.tab.h +++ /dev/null @@ -1,65 +0,0 @@ -#define INT 257 -#define HEX 258 -#define ERROR 259 -#define UINT 260 -#define M2_TRUE 261 -#define M2_FALSE 262 -#define CHAR 263 -#define FLOAT 264 -#define STRING 265 -#define NAME 266 -#define BLOCKNAME 267 -#define IDENT 268 -#define VARNAME 269 -#define TYPENAME 270 -#define SIZE 271 -#define CAP 272 -#define ORD 273 -#define HIGH 274 -#define ABS 275 -#define MIN_FUNC 276 -#define MAX_FUNC 277 -#define FLOAT_FUNC 278 -#define VAL 279 -#define CHR 280 -#define ODD 281 -#define TRUNC 282 -#define INC 283 -#define DEC 284 -#define INCL 285 -#define EXCL 286 -#define COLONCOLON 287 -#define LAST 288 -#define REGNAME 289 -#define INTERNAL_VAR 290 -#define ABOVE_COMMA 291 -#define ASSIGN 292 -#define LEQ 293 -#define GEQ 294 -#define NOTEQUAL 295 -#define IN 296 -#define OROR 297 -#define LOGICAL_AND 298 -#define DIV 299 -#define MOD 300 -#define UNARY 301 -#define DOT 302 -#define NOT 303 -#define QID 304 -typedef union - { - LONGEST lval; - unsigned LONGEST ulval; - double dval; - struct symbol *sym; - struct type *tval; - struct stoken sval; - int voidval; - struct block *bval; - enum exp_opcode opcode; - struct internalvar *ivar; - - struct type **tvec; - int *ivec; - } YYSTYPE; -extern YYSTYPE m2_lval; diff --git a/gnu/usr.bin/gdb/getpagesize.h b/gnu/usr.bin/gdb/getpagesize.h deleted file mode 100644 index 32adae6..0000000 --- a/gnu/usr.bin/gdb/getpagesize.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifdef BSD -#ifndef BSD4_1 -#define HAVE_GETPAGESIZE -#endif -#endif - -#ifndef HAVE_GETPAGESIZE - -#include - -#ifdef EXEC_PAGESIZE -#define getpagesize() EXEC_PAGESIZE -#else -#ifdef NBPG -#define getpagesize() NBPG * CLSIZE -#ifndef CLSIZE -#define CLSIZE 1 -#endif /* no CLSIZE */ -#else /* no NBPG */ -#define getpagesize() NBPC -#endif /* no NBPG */ -#endif /* no EXEC_PAGESIZE */ - -#endif /* not HAVE_GETPAGESIZE */ - diff --git a/gnu/usr.bin/gdb/infcmd.c b/gnu/usr.bin/gdb/infcmd.c deleted file mode 100644 index 378784f..0000000 --- a/gnu/usr.bin/gdb/infcmd.c +++ /dev/null @@ -1,1204 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)infcmd.c 6.4 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Memory-access and commands for inferior process, for GDB. - Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "frame.h" -#include "inferior.h" -#include "environ.h" -#include "value.h" - -#include -#include - -extern char *sys_siglist[]; - -#define ERROR_NO_INFERIOR \ - if (inferior_pid == 0) error ("The program is not being run."); - -/* String containing arguments to give to the program, - with a space added at the front. Just a space means no args. */ - -static char *inferior_args; - -/* File name for default use for standard in/out in the inferior. */ - -char *inferior_io_terminal; - -/* Pid of our debugged inferior, or 0 if no inferior now. */ - -int inferior_pid; - -/* Last signal that the inferior received (why it stopped). */ - -int stop_signal; - -/* Address at which inferior stopped. */ - -CORE_ADDR stop_pc; - -/* Stack frame when program stopped. */ - -FRAME_ADDR stop_frame_address; - -/* Number of breakpoint it stopped at, or 0 if none. */ - -int stop_breakpoint; - -/* Nonzero if stopped due to a step command. */ - -int stop_step; - -/* Nonzero if stopped due to completion of a stack dummy routine. */ - -int stop_stack_dummy; - -/* Nonzero if stopped due to a random (unexpected) signal in inferior - process. */ - -int stopped_by_random_signal; - -/* Range to single step within. - If this is nonzero, respond to a single-step signal - by continuing to step if the pc is in this range. */ - -CORE_ADDR step_range_start; /* Inclusive */ -CORE_ADDR step_range_end; /* Exclusive */ - -/* Stack frame address as of when stepping command was issued. - This is how we know when we step into a subroutine call, - and how to set the frame for the breakpoint used to step out. */ - -FRAME_ADDR step_frame_address; - -/* 1 means step over all subroutine calls. - -1 means step over calls to undebuggable functions. */ - -int step_over_calls; - -/* If stepping, nonzero means step count is > 1 - so don't print frame next time inferior stops - if it stops due to stepping. */ - -int step_multi; - -/* Environment to use for running inferior, - in format described in environ.h. */ - -struct environ *inferior_environ; - -CORE_ADDR read_pc (); -struct command_line *get_breakpoint_commands (); -void breakpoint_clear_ignore_counts (); - - -int -have_inferior_p () -{ - return inferior_pid != 0; -} - -static void -set_args_command (args) - char *args; -{ - free (inferior_args); - if (!args) args = ""; - inferior_args = concat (" ", args, ""); -} - -void -tty_command (file, from_tty) - char *file; - int from_tty; -{ - if (file == 0) - error_no_arg ("terminal name for running target process"); - - inferior_io_terminal = savestring (file, strlen (file)); -} - -static void -run_command (args, from_tty) - char *args; - int from_tty; -{ - extern char **environ; - register int i; - char *exec_file; - char *allargs; - - extern int sys_nerr; - extern char *sys_errlist[]; - extern int errno; - - dont_repeat (); - - if (inferior_pid) - { - extern int inhibit_confirm; - if (!(inhibit_confirm || - query ("The program being debugged has been started already.\n\ -Start it from the beginning? "))) - error ("Program not restarted."); - kill_inferior (); - } - -#if 0 - /* On the other hand, some users want to do - break open - ignore 1 40 - run - So it's not clear what is best. */ - - /* It is confusing to the user for ignore counts to stick around - from previous runs of the inferior. So clear them. */ - breakpoint_clear_ignore_counts (); -#endif - - exec_file = (char *) get_exec_file (1); - - if (remote_debugging) - { - if (from_tty) - { - printf ("Starting program: %s\n", exec_file); - fflush (stdout); - } - } - else - { - if (args) - set_args_command (args); - - if (from_tty) - { - printf ("Starting program: %s%s\n", - exec_file, inferior_args); - fflush (stdout); - } - - allargs = concat ("exec ", exec_file, inferior_args); - inferior_pid = create_inferior (allargs, environ_vector (inferior_environ)); - } - - clear_proceed_status (); - - start_inferior (); -} - -void -cont_command (proc_count_exp, from_tty) - char *proc_count_exp; - int from_tty; -{ - ERROR_NO_INFERIOR; - - clear_proceed_status (); - - /* If have argument, set proceed count of breakpoint we stopped at. */ - - if (stop_breakpoint > 0 && proc_count_exp) - { - set_ignore_count (stop_breakpoint, - parse_and_eval_address (proc_count_exp) - 1, - from_tty); - if (from_tty) - printf (" "); - } - - if (from_tty) - printf ("Continuing.\n"); - - proceed (-1, -1, 0); -} - -/* Step until outside of current statement. */ -static void step_1 (); - -static void -step_command (count_string) -{ - step_1 (0, 0, count_string); -} - -/* Likewise, but skip over subroutine calls as if single instructions. */ - -static void -next_command (count_string) -{ - step_1 (1, 0, count_string); -} - -/* Likewise, but step only one instruction. */ - -static void -stepi_command (count_string) -{ - step_1 (0, 1, count_string); -} - -static void -nexti_command (count_string) -{ - step_1 (1, 1, count_string); -} - -static void -step_1 (skip_subroutines, single_inst, count_string) - int skip_subroutines; - int single_inst; - char *count_string; -{ - register int count = 1; - - ERROR_NO_INFERIOR; - count = count_string ? parse_and_eval_address (count_string) : 1; - - for (; count > 0; count--) - { - clear_proceed_status (); - - step_frame_address = FRAME_FP (get_current_frame ()); - - if (! single_inst) - { - find_pc_line_pc_range (stop_pc, &step_range_start, &step_range_end); - if (step_range_end == 0) - { - int misc; - - misc = find_pc_misc_function (stop_pc); - terminal_ours (); - printf ("Current function has no line number information.\n"); - fflush (stdout); - - /* No info or after _etext ("Can't happen") */ - if (misc == -1 || misc == misc_function_count - 1) - error ("No data available on pc function."); - - printf ("Single stepping until function exit.\n"); - fflush (stdout); - - step_range_start = misc_function_vector[misc].address; - step_range_end = misc_function_vector[misc + 1].address; - } - } - else - { - /* Say we are stepping, but stop after one insn whatever it does. - Don't step through subroutine calls even to undebuggable - functions. */ - step_range_start = step_range_end = 1; - if (!skip_subroutines) - step_over_calls = 0; - } - - if (skip_subroutines) - step_over_calls = 1; - - step_multi = (count > 1); - proceed (-1, -1, 1); - if (! stop_step) - break; - } -} - -/* Continue program at specified address. */ - -static void -jump_command (arg, from_tty) - char *arg; - int from_tty; -{ - register CORE_ADDR addr; - struct symtabs_and_lines sals; - struct symtab_and_line sal; - - ERROR_NO_INFERIOR; - - if (!arg) - error_no_arg ("starting address"); - - sals = decode_line_spec_1 (arg, 1); - if (sals.nelts != 1) - { - error ("Unreasonable jump request"); - } - - sal = sals.sals[0]; - free (sals.sals); - - if (sal.symtab == 0 && sal.pc == 0) - error ("No source file has been specified."); - - if (sal.pc == 0) - sal.pc = find_line_pc (sal.symtab, sal.line); - - { - struct symbol *fn = get_frame_function (get_current_frame ()); - struct symbol *sfn = find_pc_function (sal.pc); - if (fn != 0 && sfn != fn - && ! query ("Line %d is not in `%s'. Jump anyway? ", - sal.line, SYMBOL_NAME (fn))) - error ("Not confirmed."); - } - - if (sal.pc == 0) - error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename); - - addr = sal.pc; - - clear_proceed_status (); - - if (from_tty) - printf ("Continuing at 0x%x.\n", addr); - - proceed (addr, 0, 0); -} - -/* Continue program giving it specified signal. */ - -static void -signal_command (signum_exp, from_tty) - char *signum_exp; - int from_tty; -{ - register int signum; - - dont_repeat (); /* Too dangerous. */ - ERROR_NO_INFERIOR; - - if (!signum_exp) - error_no_arg ("signal number"); - - signum = parse_and_eval_address (signum_exp); - - clear_proceed_status (); - - if (from_tty) - printf ("Continuing with signal %d.\n", signum); - - proceed (stop_pc, signum, 0); -} - -/* Execute a "stack dummy", a piece of code stored in the stack - by the debugger to be executed in the inferior. - - To call: first, do PUSH_DUMMY_FRAME. - Then push the contents of the dummy. It should end with a breakpoint insn. - Then call here, passing address at which to start the dummy. - - The contents of all registers are saved before the dummy frame is popped - and copied into the buffer BUFFER. - - The dummy's frame is automatically popped whenever that break is hit. - If that is the first time the program stops, run_stack_dummy - returns to its caller with that frame already gone. - Otherwise, the caller never gets returned to. */ - -/* 4 => return instead of letting the stack dummy run. */ - -static int stack_dummy_testing = 0; - -void -run_stack_dummy (addr, buffer) - CORE_ADDR addr; - REGISTER_TYPE *buffer; -{ - /* Now proceed, having reached the desired place. */ - clear_proceed_status (); -#ifdef notdef - if (stack_dummy_testing & 4) - { - POP_FRAME; - return; - } -#endif - proceed (addr, 0, 0); - - if (!stop_stack_dummy) - error ("Cannot continue previously requested operation."); - - /* On return, the stack dummy has been popped already. */ - - read_register_bytes(0, buffer, REGISTER_BYTES); -} - -/* Proceed until we reach the given line as argument or exit the - function. When called with no argument, proceed until we reach a - different source line with pc greater than our current one or exit - the function. We skip calls in both cases. - - The effect of this command with an argument is identical to setting - a momentary breakpoint at the line specified and executing - "finish". - - Note that eventually this command should probably be changed so - that only source lines are printed out when we hit the breakpoint - we set. I'm going to postpone this until after a hopeful rewrite - of wait_for_inferior and the proceed status code. -- randy */ - -void -until_next_command (arg, from_tty) - char *arg; - int from_tty; -{ - FRAME frame; - CORE_ADDR pc; - struct symbol *func; - struct symtab_and_line sal; - - clear_proceed_status (); - - frame = get_current_frame (); - - /* Step until either exited from this function or greater - than the current line (if in symbolic section) or pc (if - not). */ - - pc = read_pc (); - func = find_pc_function (pc); - - if (!func) - { - int misc_func = find_pc_misc_function (pc); - - if (misc_func != -1) - error ("Execution is not within a known function."); - - step_range_start = misc_function_vector[misc_func].address; - step_range_end = pc; - } - else - { - sal = find_pc_line (pc, 0); - - step_range_start = BLOCK_START (SYMBOL_BLOCK_VALUE (func)); - step_range_end = sal.end; - } - - step_over_calls = 1; - step_frame_address = FRAME_FP (frame); - - step_multi = 0; /* Only one call to proceed */ - - proceed (-1, -1, 1); -} - -void -until_command (arg, from_tty) - char *arg; - int from_tty; -{ - if (!have_inferior_p ()) - error ("The program is not being run."); - - if (arg) - until_break_command (arg, from_tty); - else - until_next_command (arg, from_tty); -} - -/* "finish": Set a temporary breakpoint at the place - the selected frame will return to, then continue. */ - -static void -finish_command (arg, from_tty) - char *arg; - int from_tty; -{ - struct symtab_and_line sal; - register FRAME frame; - struct frame_info *fi; - register struct symbol *function; - - if (!have_inferior_p ()) - error ("The program is not being run."); - if (arg) - error ("The \"finish\" command does not take any arguments."); - - frame = get_prev_frame (selected_frame); - if (frame == 0) - error ("\"finish\" not meaningful in the outermost frame."); - - clear_proceed_status (); - - fi = get_frame_info (frame); - sal = find_pc_line (fi->pc, 0); - sal.pc = fi->pc; - set_momentary_breakpoint (sal, frame); - - /* Find the function we will return from. */ - - fi = get_frame_info (selected_frame); - function = find_pc_function (fi->pc); - - if (from_tty) - { - printf ("Run till exit from "); - print_selected_frame (); - } - - proceed (-1, -1, 0); - - if (stop_breakpoint == -3 && function != 0) - { - struct type *value_type; - register value val; - CORE_ADDR funcaddr; - extern char registers[]; - - value_type = TYPE_TARGET_TYPE (SYMBOL_TYPE (function)); - if (!value_type) - fatal ("internal: finish_command: function has no target type"); - - if (TYPE_CODE (value_type) == TYPE_CODE_VOID) - return; - - funcaddr = BLOCK_START (SYMBOL_BLOCK_VALUE (function)); - - val = value_being_returned (value_type, registers, - using_struct_return (function, - funcaddr, - value_type)); - - printf ("Value returned is $%d = ", record_latest_value (val)); - value_print (val, stdout, 0, Val_no_prettyprint); - putchar ('\n'); - } -} - -static void -program_info () -{ - if (inferior_pid == 0) - { - printf ("The program being debugged is not being run.\n"); - return; - } - - printf ("Program being debugged is in process %d, stopped at 0x%x.\n", - inferior_pid, stop_pc); - if (stop_step) - printf ("It stopped after being stepped.\n"); - else if (stop_breakpoint > 0) - printf ("It stopped at breakpoint %d.\n", stop_breakpoint); - else if (stop_signal) - printf ("It stopped with signal %d (%s).\n", - stop_signal, sys_siglist[stop_signal]); - - printf ("\nType \"info stack\" or \"info reg\" for more information.\n"); -} - -static void -environment_info (var) - char *var; -{ - if (var) - { - register char *val = get_in_environ (inferior_environ, var); - if (val) - printf ("%s = %s\n", var, val); - else - printf ("Environment variable \"%s\" not defined.\n", var); - } - else - { - register char **vector = environ_vector (inferior_environ); - while (*vector) - printf ("%s\n", *vector++); - } -} - -static void -set_environment_command (arg) - char *arg; -{ - register char *p, *val, *var; - int nullset = 0; - - if (arg == 0) - error_no_arg ("environment variable and value"); - - /* Find seperation between variable name and value */ - p = (char *) index (arg, '='); - val = (char *) index (arg, ' '); - - if (p != 0 && val != 0) - { - /* We have both a space and an equals. If the space is before the - equals and the only thing between the two is more space, use - the equals */ - if (p > val) - while (*val == ' ') - val++; - - /* Take the smaller of the two. If there was space before the - "=", they will be the same right now. */ - p = arg + min (p - arg, val - arg); - } - else if (val != 0 && p == 0) - p = val; - - if (p == arg) - error_no_arg ("environment variable to set"); - - if (p == 0 || p[1] == 0) - { - nullset = 1; - if (p == 0) - p = arg + strlen (arg); /* So that savestring below will work */ - } - else - { - /* Not setting variable value to null */ - val = p + 1; - while (*val == ' ' || *val == '\t') - val++; - } - - while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) p--; - - var = savestring (arg, p - arg); - if (nullset) - { - printf ("Setting environment variable \"%s\" to null value.\n", var); - set_in_environ (inferior_environ, var, ""); - } - else - set_in_environ (inferior_environ, var, val); - free (var); -} - -static void -unset_environment_command (var, from_tty) - char *var; - int from_tty; -{ - if (var == 0) - /* If there is no argument, delete all environment variables. - Ask for confirmation if reading from the terminal. */ - if (!from_tty || query ("Delete all environment variables? ")) - { - free_environ (inferior_environ); - inferior_environ = make_environ (); - } - - unset_in_environ (inferior_environ, var); -} - -/* Read an integer from debugged memory, given address and number of bytes. */ - -long -read_memory_integer (memaddr, len) - CORE_ADDR memaddr; - int len; -{ - char cbuf; - short sbuf; - int ibuf; - long lbuf; - int result_err; - extern int sys_nerr; - extern char *sys_errlist[]; - - if (len == sizeof (char)) - { - result_err = read_memory (memaddr, &cbuf, len); - if (result_err) - error ("Error reading memory address 0x%x: %s (%d).", - memaddr, (result_err < sys_nerr ? - sys_errlist[result_err] : - "uknown error"), result_err); - return cbuf; - } - if (len == sizeof (short)) - { - result_err = read_memory (memaddr, &sbuf, len); - if (result_err) - error ("Error reading memory address 0x%x: %s (%d).", - memaddr, (result_err < sys_nerr ? - sys_errlist[result_err] : - "uknown error"), result_err); - return sbuf; - } - if (len == sizeof (int)) - { - result_err = read_memory (memaddr, &ibuf, len); - if (result_err) - error ("Error reading memory address 0x%x: %s (%d).", - memaddr, (result_err < sys_nerr ? - sys_errlist[result_err] : - "uknown error"), result_err); - return ibuf; - } - if (len == sizeof (lbuf)) - { - result_err = read_memory (memaddr, &lbuf, len); - if (result_err) - error ("Error reading memory address 0x%x: %s (%d).", - memaddr, (result_err < sys_nerr ? - sys_errlist[result_err] : - "uknown error"), result_err); - return lbuf; - } - error ("Cannot handle integers of %d bytes.", len); -} - -CORE_ADDR -read_pc () -{ - return (CORE_ADDR) read_register (PC_REGNUM); -} - -void -write_pc (val) - CORE_ADDR val; -{ - write_register (PC_REGNUM, (long) val); -#ifdef NPC_REGNUM - write_register (NPC_REGNUM, (long) val+4); -#endif -} - -char *reg_names[] = REGISTER_NAMES; - -#if !defined (DO_REGISTERS_INFO) -static void -print_one_register(i) - int i; -{ - unsigned char raw_buffer[MAX_REGISTER_RAW_SIZE]; - unsigned char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; - REGISTER_TYPE val; - - /* Get the data in raw format, then convert also to virtual format. */ - read_relative_register_raw_bytes (i, raw_buffer); - REGISTER_CONVERT_TO_VIRTUAL (i, raw_buffer, virtual_buffer); - - fputs_filtered (reg_names[i], stdout); - print_spaces_filtered (15 - strlen (reg_names[i]), stdout); - - /* If virtual format is floating, print it that way. */ - if (TYPE_CODE (REGISTER_VIRTUAL_TYPE (i)) == TYPE_CODE_FLT - && ! INVALID_FLOAT (virtual_buffer, REGISTER_VIRTUAL_SIZE (i))) - val_print (REGISTER_VIRTUAL_TYPE (i), virtual_buffer, 0, - stdout, 0, 1, 0, Val_pretty_default); - /* Else if virtual format is too long for printf, - print in hex a byte at a time. */ - else if (REGISTER_VIRTUAL_SIZE (i) > sizeof (long)) - { - register int j; - printf_filtered ("0x"); - for (j = 0; j < REGISTER_VIRTUAL_SIZE (i); j++) - printf_filtered ("%02x", virtual_buffer[j]); - } - /* Else print as integer in hex and in decimal. */ - else - { - long val; - - bcopy (virtual_buffer, &val, sizeof (long)); - if (val == 0) - printf_filtered ("0"); - else - printf_filtered ("0x%08x %d", val, val); - } - - /* If register has different raw and virtual formats, - print the raw format in hex now. */ - - if (REGISTER_CONVERTIBLE (i)) - { - register int j; - - printf_filtered (" (raw 0x"); - for (j = 0; j < REGISTER_RAW_SIZE (i); j++) - printf_filtered ("%02x", raw_buffer[j]); - printf_filtered (")"); - } - printf_filtered ("\n"); -} - - -/* Print out the machine register regnum. If regnum is -1, - print all registers. - For most machines, having all_registers_info() print the - register(s) one per line is good enough. If a different format - is required, (eg, for SPARC or Pyramid 90x, which both have - lots of regs), or there is an existing convention for showing - all the registers, define the macro DO_REGISTERS_INFO(regnum) - to provide that format. */ -static void -do_registers_info (regnum, fpregs) - int regnum; - int fpregs; -{ - register int i; - - if (regnum >= 0) { - print_one_register(regnum); - return; - } -#ifdef notdef - printf_filtered ( -"Register Contents (relative to selected stack frame)\n\n"); -#endif - for (i = 0; i < NUM_REGS; i++) - if (TYPE_CODE(REGISTER_VIRTUAL_TYPE(i)) != TYPE_CODE_FLT || - fpregs) - print_one_register(i); -} -#endif /* no DO_REGISTERS_INFO. */ - -static void -registers_info (addr_exp, fpregs) - char *addr_exp; - int fpregs; -{ - int regnum; - - if (!have_inferior_p () && !have_core_file_p ()) - error ("No inferior or core file"); - - if (addr_exp) - { - if (*addr_exp >= '0' && *addr_exp <= '9') - regnum = atoi (addr_exp); - else - { - register char *p = addr_exp; - if (p[0] == '$') - p++; - for (regnum = 0; regnum < NUM_REGS; regnum++) - if (!strcmp (p, reg_names[regnum])) - break; - if (regnum == NUM_REGS) - error ("%s: invalid register name.", addr_exp); - } - } - else - regnum = -1; - -#ifdef DO_REGISTERS_INFO - DO_REGISTERS_INFO(regnum); -#else - do_registers_info(regnum, fpregs); -#endif -} - -static void -all_registers_info (addr_exp) - char *addr_exp; -{ - registers_info(addr_exp, 1); -} - -static void -nofp_registers_info (addr_exp) - char *addr_exp; -{ - registers_info(addr_exp, 0); -} - - -#ifdef ATTACH_DETACH -#define PROCESS_ATTACH_ALLOWED 1 -#else -#define PROCESS_ATTACH_ALLOWED 0 -#endif -/* - * TODO: - * Should save/restore the tty state since it might be that the - * program to be debugged was started on this tty and it wants - * the tty in some state other than what we want. If it's running - * on another terminal or without a terminal, then saving and - * restoring the tty state is a harmless no-op. - * This only needs to be done if we are attaching to a process. - */ - -/* - * attach_command -- - * takes a program started up outside of gdb and ``attaches'' to it. - * This stops it cold in its tracks and allows us to start tracing it. - * For this to work, we must be able to send the process a - * signal and we must have the same effective uid as the program. - */ -static void -attach_command (args, from_tty) - char *args; - int from_tty; -{ - char *exec_file; - int pid; - int remote = 0; - - dont_repeat(); - - if (!args) - error_no_arg ("process-id or device file to attach"); - - while (*args == ' ' || *args == '\t') args++; - - if (args[0] < '0' || args[0] > '9') - remote = 1; - else -#ifndef ATTACH_DETACH - error ("Can't attach to a process on this machine."); -#else - pid = atoi (args); -#endif - - if (inferior_pid) - { - if (query ("A program is being debugged already. Kill it? ")) - kill_inferior (); - else - error ("Inferior not killed."); - } - - exec_file = (char *) get_exec_file (1); - - if (from_tty) - { - if (remote) - printf ("Attaching remote machine\n"); - else - printf ("Attaching program: %s pid %d\n", - exec_file, pid); - fflush (stdout); - } - - if (remote) - { - remote_open (args, from_tty); - start_remote (); - } -#ifdef ATTACH_DETACH - else - attach_program (pid); -#endif -} - -/* - * detach_command -- - * takes a program previously attached to and detaches it. - * The program resumes execution and will no longer stop - * on signals, etc. We better not have left any breakpoints - * in the program or it'll die when it hits one. For this - * to work, it may be necessary for the process to have been - * previously attached. It *might* work if the program was - * started via the normal ptrace (PTRACE_TRACEME). - */ - -static void -detach_command (args, from_tty) - char *args; - int from_tty; -{ - int signal = 0; - -#ifdef ATTACH_DETACH - if (inferior_pid && !remote_debugging) - { - if (from_tty) - { - char *exec_file = (char *)get_exec_file (0); - if (exec_file == 0) - exec_file = ""; - printf ("Detaching program: %s pid %d\n", - exec_file, inferior_pid); - fflush (stdout); - } - if (args) - signal = atoi (args); - - detach (signal); - inferior_pid = 0; - } - else -#endif - { - if (!remote_debugging) - error ("Not currently attached to subsidiary or remote process."); - - if (args) - error ("Argument given to \"detach\" when remotely debugging."); - - inferior_pid = 0; - remote_close (from_tty); - } -} - -/* ARGSUSED */ -static void -float_info (addr_exp) - char *addr_exp; -{ -#ifdef FLOAT_INFO - FLOAT_INFO; -#else - printf ("No floating point info available for this processor.\n"); -#endif -} - -extern struct cmd_list_element *setlist, *deletelist; - -void -_initialize_infcmd () -{ - add_com ("tty", class_run, tty_command, - "Set terminal for future runs of program being debugged."); - - add_cmd ("args", class_run, set_args_command, - "Specify arguments to give program being debugged when it is started.\n\ -Follow this command with any number of args, to be passed to the program.", - &setlist); - - add_info ("environment", environment_info, - "The environment to give the program, or one variable's value.\n\ -With an argument VAR, prints the value of environment variable VAR to\n\ -give the program being debugged. With no arguments, prints the entire\n\ -environment to be given to the program."); - - add_cmd ("environment", class_run, unset_environment_command, - "Cancel environment variable VAR for the program.\n\ -This does not affect the program until the next \"run\" command.", - &deletelist); - - add_cmd ("environment", class_run, set_environment_command, - "Set environment variable value to give the program.\n\ -Arguments are VAR VALUE where VAR is variable name and VALUE is value.\n\ -VALUES of environment variables are uninterpreted strings.\n\ -This does not affect the program until the next \"run\" command.", - &setlist); - -#ifdef ATTACH_DETACH - add_com ("attach", class_run, attach_command, - "Attach to a process that was started up outside of GDB.\n\ -This command may take as argument a process id or a device file.\n\ -For a process id, you must have permission to send the process a signal,\n\ -and it must have the same effective uid as the debugger.\n\ -For a device file, the file must be a connection to a remote debug server.\n\n\ -Before using \"attach\", you must use the \"exec-file\" command\n\ -to specify the program running in the process,\n\ -and the \"symbol-file\" command to load its symbol table."); -#else - add_com ("attach", class_run, attach_command, - "Attach to a process that was started up outside of GDB.\n\ -This commands takes as an argument the name of a device file.\n\ -This file must be a connection to a remote debug server.\n\n\ -Before using \"attach\", you must use the \"exec-file\" command\n\ -to specify the program running in the process,\n\ -and the \"symbol-file\" command to load its symbol table."); -#endif - add_com ("detach", class_run, detach_command, - "Detach the process previously attached.\n\ -The process is no longer traced and continues its execution."); - - add_com ("signal", class_run, signal_command, - "Continue program giving it signal number SIGNUMBER."); - - add_com ("stepi", class_run, stepi_command, - "Step one instruction exactly.\n\ -Argument N means do this N times (or till program stops for another reason)."); - add_com_alias ("si", "stepi", class_alias, 0); - - add_com ("nexti", class_run, nexti_command, - "Step one instruction, but proceed through subroutine calls.\n\ -Argument N means do this N times (or till program stops for another reason)."); - add_com_alias ("ni", "nexti", class_alias, 0); - - add_com ("finish", class_run, finish_command, - "Execute until selected stack frame returns.\n\ -Upon return, the value returned is printed and put in the value history."); - - add_com ("next", class_run, next_command, - "Step program, proceeding through subroutine calls.\n\ -Like the \"step\" command as long as subroutine calls do not happen;\n\ -when they do, the call is treated as one instruction.\n\ -Argument N means do this N times (or till program stops for another reason)."); - add_com_alias ("n", "next", class_run, 1); - - add_com ("step", class_run, step_command, - "Step program until it reaches a different source line.\n\ -Argument N means do this N times (or till program stops for another reason)."); - add_com_alias ("s", "step", class_run, 1); - - add_com ("until", class_run, until_command, - "Execute until the program reaches a source line greater than the current\n\ -or a specified line or address or function (same args as break command).\n\ -Execution will also stop upon exit from the current stack frame."); - add_com_alias ("u", "until", class_run, 1); - - add_com ("jump", class_run, jump_command, - "Continue program being debugged at specified line or address.\n\ -Give as argument either LINENUM or *ADDR, where ADDR is an expression\n\ -for an address to start at."); - - add_com ("cont", class_run, cont_command, - "Continue program being debugged, after signal or breakpoint.\n\ -If proceeding from breakpoint, a number N may be used as an argument:\n\ -then the same breakpoint won't break until the Nth time it is reached."); - add_com_alias ("c", "cont", class_run, 1); - - add_com ("run", class_run, run_command, - "Start debugged program. You may specify arguments to give it.\n\ -Args may include \"*\", or \"[...]\"; they are expanded using \"sh\".\n\ -Input and output redirection with \">\", \"<\", or \">>\" are also allowed.\n\n\ -With no arguments, uses arguments last specified (with \"run\" or \"set args\".\n\ -To cancel previous arguments and run with no arguments,\n\ -use \"set args\" without arguments."); - add_com_alias ("r", "run", class_run, 1); - - add_info ("registers", nofp_registers_info, - "List of registers and their contents, for selected stack frame.\n\ -Register name as argument means describe only that register.\n\ -(Doesn't display floating point registers; use 'info all-registers'.)\n"); - - add_info ("all-registers", all_registers_info, - "List of registers and their contents, for selected stack frame.\n\ -Register name as argument means describe only that register."); - - add_info ("program", program_info, - "Execution status of the program."); - - add_info ("float", float_info, - "Print the status of the floating point unit\n"); - - inferior_args = savestring (" ", 1); /* By default, no args. */ - inferior_environ = make_environ (); - init_environ (inferior_environ); -} - diff --git a/gnu/usr.bin/gdb/inferior.h b/gnu/usr.bin/gdb/inferior.h deleted file mode 100644 index 04c662e..0000000 --- a/gnu/usr.bin/gdb/inferior.h +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - * - * @(#)inferior.h 6.3 (Berkeley) 5/8/91 - */ - -/* Variables that describe the inferior process running under GDB: - Where it is, why it stopped, and how to step it. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* - * Structure in which to save the status of the inferior. Save - * through "save_inferior_status", restore through - * "restore_inferior_status". - * This pair of routines should be called around any transfer of - * control to the inferior which you don't want showing up in your - * control variables. - */ -struct inferior_status { - int pc_changed; - int stop_signal; - int stop_pc; - int stop_frame_address; - int stop_breakpoint; - int stop_step; - int stop_stack_dummy; - int stopped_by_random_signal; - int trap_expected; - CORE_ADDR step_range_start; - CORE_ADDR step_range_end; - FRAME_ADDR step_frame_address; - int step_over_calls; - CORE_ADDR step_resume_break_address; - int stop_after_trap; - int stop_after_attach; - FRAME_ADDR selected_frame_address; - int selected_level; - struct command_line *breakpoint_commands; - char register_context[REGISTER_BYTES]; - int restore_stack_info; -}; - -void save_inferior_status (), restore_inferior_status (); - -/* File name for default use for standard in/out in the inferior. */ - -extern char *inferior_io_terminal; - -/* Pid of our debugged inferior, or 0 if no inferior now. */ - -extern int inferior_pid; - -/* Nonzero if debugging a remote machine via a serial link or ethernet. */ -extern int remote_debugging; - -/* Routines for use in remote debugging. Documented in remote.c. */ -int remote_read_inferior_memory (); -int remote_write_inferior_memory (); - -/* Last signal that the inferior received (why it stopped). */ - -extern int stop_signal; - -/* Address at which inferior stopped. */ - -extern CORE_ADDR stop_pc; - -/* Stack frame when program stopped. */ - -extern FRAME_ADDR stop_frame_address; - -/* Number of breakpoint it stopped at, or 0 if none. */ - -extern int stop_breakpoint; - -/* Nonzero if stopped due to a step command. */ - -extern int stop_step; - -/* Nonzero if stopped due to completion of a stack dummy routine. */ - -extern int stop_stack_dummy; - -/* Nonzero if program stopped due to a random (unexpected) signal in - inferior process. */ - -extern int stopped_by_random_signal; - -/* Range to single step within. - If this is nonzero, respond to a single-step signal - by continuing to step if the pc is in this range. */ - -extern CORE_ADDR step_range_start; /* Inclusive */ -extern CORE_ADDR step_range_end; /* Exclusive */ - -/* Stack frame address as of when stepping command was issued. - This is how we know when we step into a subroutine call, - and how to set the frame for the breakpoint used to step out. */ - -extern FRAME_ADDR step_frame_address; - -/* 1 means step over all subroutine calls. - -1 means step over calls to undebuggable functions. */ - -extern int step_over_calls; - -/* If stepping, nonzero means step count is > 1 - so don't print frame next time inferior stops - if it stops due to stepping. */ - -extern int step_multi; - -/* Save register contents here when about to pop a stack dummy frame. */ - -extern char stop_registers[REGISTER_BYTES]; - -/* Nonzero if pc has been changed by the debugger - since the inferior stopped. */ - -extern int pc_changed; - -long read_memory_integer (); diff --git a/gnu/usr.bin/gdb/inflow.c b/gnu/usr.bin/gdb/inflow.c deleted file mode 100644 index 209fcf3..0000000 --- a/gnu/usr.bin/gdb/inflow.c +++ /dev/null @@ -1,569 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)inflow.c 6.5 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Low level interface to ptrace, for GDB when running under Unix. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "frame.h" -#include "inferior.h" - -#ifdef USG -#include -#endif - -/* Some USG-esque systems (some of which are BSD-esque enough so that USG - is not defined) want this header, and it won't do any harm. */ -#include - -#include -#include -#include - -#ifdef HAVE_TERMIO -#include -#undef TIOCGETP -#define TIOCGETP TCGETA -#undef TIOCSETN -#define TIOCSETN TCSETA -#undef TIOCSETP -#define TIOCSETP TCSETAF -#define TERMINAL struct termio -#else -#include -#include -#include -#define TERMINAL struct sgttyb -#endif - -#ifdef SET_STACK_LIMIT_HUGE -#include -#include -extern int original_stack_limit; -#endif /* SET_STACK_LIMIT_HUGE */ - -extern int errno; - -/* Nonzero if we are debugging an attached outside process - rather than an inferior. */ - -int attach_flag; - - -/* Record terminal status separately for debugger and inferior. */ - -static TERMINAL sg_inferior; -static TERMINAL sg_ours; - -static int tflags_inferior; -static int tflags_ours; - -#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) -static struct tchars tc_inferior; -static struct tchars tc_ours; -#endif - -#ifdef TIOCGLTC -static struct ltchars ltc_inferior; -static struct ltchars ltc_ours; -#endif - -#ifdef TIOCLGET -static int lmode_inferior; -static int lmode_ours; -#endif - -#ifdef TIOCGPGRP -static int pgrp_inferior; -static int pgrp_ours; -#else -static int (*sigint_ours) (); -static int (*sigquit_ours) (); -#endif /* TIOCGPGRP */ - -/* Copy of inferior_io_terminal when inferior was last started. */ -static char *inferior_thisrun_terminal; - -static void terminal_ours_1 (); - -/* Nonzero if our terminal settings are in effect. - Zero if the inferior's settings are in effect. */ -static int terminal_is_ours; - -/* Initialize the terminal settings we record for the inferior, - before we actually run the inferior. */ - -void -terminal_init_inferior () -{ - if (remote_debugging) - return; - - sg_inferior = sg_ours; - tflags_inferior = tflags_ours; - -#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) - tc_inferior = tc_ours; -#endif - -#ifdef TIOCGLTC - ltc_inferior = ltc_ours; -#endif - -#ifdef TIOCLGET - lmode_inferior = lmode_ours; -#endif - -#ifdef TIOCGPGRP - pgrp_inferior = inferior_pid; -#endif /* TIOCGPGRP */ - - terminal_is_ours = 1; -} - -/* Put the inferior's terminal settings into effect. - This is preparation for starting or resuming the inferior. */ - -void -terminal_inferior () -{ - if (remote_debugging) - return; - - if (terminal_is_ours) /* && inferior_thisrun_terminal == 0) */ - { - fcntl (0, F_SETFL, tflags_inferior); - fcntl (0, F_SETFL, tflags_inferior); - ioctl (0, TIOCSETN, &sg_inferior); - -#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) - ioctl (0, TIOCSETC, &tc_inferior); -#endif -#ifdef TIOCGLTC - ioctl (0, TIOCSLTC, <c_inferior); -#endif -#ifdef TIOCLGET - ioctl (0, TIOCLSET, &lmode_inferior); -#endif - -#ifdef TIOCGPGRP - ioctl (0, TIOCSPGRP, &pgrp_inferior); -#else - sigint_ours = (int (*) ()) signal (SIGINT, SIG_IGN); - sigquit_ours = (int (*) ()) signal (SIGQUIT, SIG_IGN); -#endif /* TIOCGPGRP */ - } - terminal_is_ours = 0; -} - -/* Put some of our terminal settings into effect, - enough to get proper results from our output, - but do not change into or out of RAW mode - so that no input is discarded. - - After doing this, either terminal_ours or terminal_inferior - should be called to get back to a normal state of affairs. */ - -void -terminal_ours_for_output () -{ - if (remote_debugging) - return; - - terminal_ours_1 (1); -} - -/* Put our terminal settings into effect. - First record the inferior's terminal settings - so they can be restored properly later. */ - -void -terminal_ours () -{ - if (remote_debugging) - return; - - terminal_ours_1 (0); -} - -static void -terminal_ours_1 (output_only) - int output_only; -{ -#ifdef TIOCGPGRP - /* Ignore this signal since it will happen when we try to set the pgrp. */ - void (*osigttou) (); -#endif /* TIOCGPGRP */ - - if (!terminal_is_ours) /* && inferior_thisrun_terminal == 0) */ - { - terminal_is_ours = 1; - -#ifdef TIOCGPGRP - osigttou = signal (SIGTTOU, SIG_IGN); - - ioctl (0, TIOCGPGRP, &pgrp_inferior); - ioctl (0, TIOCSPGRP, &pgrp_ours); - - signal (SIGTTOU, osigttou); -#else - signal (SIGINT, sigint_ours); - signal (SIGQUIT, sigquit_ours); -#endif /* TIOCGPGRP */ - - tflags_inferior = fcntl (0, F_GETFL, 0); - ioctl (0, TIOCGETP, &sg_inferior); - -#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) - ioctl (0, TIOCGETC, &tc_inferior); -#endif -#ifdef TIOCGLTC - ioctl (0, TIOCGLTC, <c_inferior); -#endif -#ifdef TIOCLGET - ioctl (0, TIOCLGET, &lmode_inferior); -#endif - } - -#ifdef HAVE_TERMIO - sg_ours.c_lflag |= ICANON; - if (output_only && !(sg_inferior.c_lflag & ICANON)) - sg_ours.c_lflag &= ~ICANON; -#else /* not HAVE_TERMIO */ - sg_ours.sg_flags &= ~RAW & ~CBREAK; - if (output_only) - sg_ours.sg_flags |= (RAW | CBREAK) & sg_inferior.sg_flags; -#endif /* not HAVE_TERMIO */ - - fcntl (0, F_SETFL, tflags_ours); - fcntl (0, F_SETFL, tflags_ours); - ioctl (0, TIOCSETN, &sg_ours); - -#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) - ioctl (0, TIOCSETC, &tc_ours); -#endif -#ifdef TIOCGLTC - ioctl (0, TIOCSLTC, <c_ours); -#endif -#ifdef TIOCLGET - ioctl (0, TIOCLSET, &lmode_ours); -#endif - -#ifdef HAVE_TERMIO - sg_ours.c_lflag |= ICANON; -#else /* not HAVE_TERMIO */ - sg_ours.sg_flags &= ~RAW & ~CBREAK; -#endif /* not HAVE_TERMIO */ -} - -static void -term_status_command () -{ - register int i; - - if (remote_debugging) - { - printf_filtered ("No terminal status when remote debugging.\n"); - return; - } - - printf_filtered ("Inferior's terminal status (currently saved by GDB):\n"); - -#ifdef HAVE_TERMIO - - printf_filtered ("fcntl flags = 0x%x, c_iflag = 0x%x, c_oflag = 0x%x,\n", - tflags_inferior, sg_inferior.c_iflag, sg_inferior.c_oflag); - printf_filtered ("c_cflag = 0x%x, c_lflag = 0x%x, c_line = 0x%x.\n", - sg_inferior.c_cflag, sg_inferior.c_lflag, sg_inferior.c_line); - printf_filtered ("c_cc: "); - for (i = 0; (i < NCC); i += 1) - printf_filtered ("0x%x ", sg_inferior.c_cc[i]); - printf_filtered ("\n"); - -#else /* not HAVE_TERMIO */ - - printf_filtered ("fcntl flags = 0x%x, sgttyb.sg_flags = 0x%x, owner pid = %d.\n", - tflags_inferior, sg_inferior.sg_flags, pgrp_inferior); - -#endif /* not HAVE_TERMIO */ - -#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) - printf_filtered ("tchars: "); - for (i = 0; i < sizeof (struct tchars); i++) - printf_filtered ("0x%x ", ((char *)&tc_inferior)[i]); - printf_filtered ("\n"); -#endif - -#ifdef TIOCGLTC - printf_filtered ("ltchars: "); - for (i = 0; i < sizeof (struct ltchars); i++) - printf_filtered ("0x%x ", ((char *)<c_inferior)[i]); - printf_filtered ("\n"); - ioctl (0, TIOCSLTC, <c_ours); -#endif - -#ifdef TIOCLGET - printf_filtered ("lmode: %x\n", lmode_inferior); -#endif -} - -static void -new_tty (ttyname) - char *ttyname; -{ - register int tty; - register int fd; - -#ifdef TIOCNOTTY - /* Disconnect the child process from our controlling terminal. */ - tty = open("/dev/tty", O_RDWR); - if (tty > 0) - { - ioctl(tty, TIOCNOTTY, 0); - close(tty); - } -#endif - - /* Now open the specified new terminal. */ - - tty = open(ttyname, O_RDWR); - if (tty == -1) - _exit(1); - - /* Avoid use of dup2; doesn't exist on all systems. */ - if (tty != 0) - { close (0); dup (tty); } - if (tty != 1) - { close (1); dup (tty); } - if (tty != 2) - { close (2); dup (tty); } - if (tty > 2) - close(tty); -} - -/* Start an inferior process and returns its pid. - ALLARGS is a string containing shell command to run the program. - ENV is the environment vector to pass. */ - -#ifndef SHELL_FILE -#define SHELL_FILE "/bin/sh" -#endif - -int -create_inferior (allargs, env) - char *allargs; - char **env; -{ - int pid; - char *shell_command; - extern int sys_nerr; - extern char *sys_errlist[]; - extern int errno; - - /* If desired, concat something onto the front of ALLARGS. - SHELL_COMMAND is the result. */ -#ifdef SHELL_COMMAND_CONCAT - shell_command = (char *) alloca (strlen (SHELL_COMMAND_CONCAT) + strlen (allargs) + 1); - strcpy (shell_command, SHELL_COMMAND_CONCAT); - strcat (shell_command, allargs); -#else - shell_command = allargs; -#endif - - /* exec is said to fail if the executable is open. */ - close_exec_file (); - -#if defined(USG) && !defined(HAVE_VFORK) - pid = fork (); -#else - pid = vfork (); -#endif - - if (pid < 0) - perror_with_name ("vfork"); - - if (pid == 0) - { -#ifdef TIOCGPGRP - /* Run inferior in a separate process group. */ - setpgrp (getpid (), getpid ()); -#endif /* TIOCGPGRP */ - -#ifdef SET_STACK_LIMIT_HUGE - /* Reset the stack limit back to what it was. */ - { - struct rlimit rlim; - - getrlimit (RLIMIT_STACK, &rlim); - rlim.rlim_cur = original_stack_limit; - setrlimit (RLIMIT_STACK, &rlim); - } -#endif /* SET_STACK_LIMIT_HUGE */ - - - inferior_thisrun_terminal = inferior_io_terminal; - if (inferior_io_terminal != 0) - new_tty (inferior_io_terminal); - -/* It seems that changing the signal handlers for the inferior after - a vfork also changes them for the superior. See comments in - initialize_signals for how we get the right signal handlers - for the inferior. */ -/* Not needed on Sun, at least, and loses there - because it clobbers the superior. */ -/*??? signal (SIGQUIT, SIG_DFL); - signal (SIGINT, SIG_DFL); */ - - call_ptrace (0); - execle (SHELL_FILE, "sh", "-c", shell_command, 0, env); - - fprintf (stderr, "Cannot exec %s: %s.\n", SHELL_FILE, - errno < sys_nerr ? sys_errlist[errno] : "unknown error"); - fflush (stderr); - _exit (0177); - } - -#ifdef TIOCGPGRP - /* Avoid race with TIOCSPGRP: guarantee that inferior's pgrp exists. */ - setpgrp (pid, pid); -#endif /* TIOCGPGRP */ - -#ifdef CREATE_INFERIOR_HOOK - CREATE_INFERIOR_HOOK (pid); -#endif - return pid; -} - -/* Kill the inferior process. Make us have no inferior. */ - -static void -kill_command () -{ - if (remote_debugging) - { - inferior_pid = 0; - return; - } - if (inferior_pid == 0) - error ("The program is not being run."); - if (!query ("Kill the inferior process? ")) - error ("Not confirmed."); - kill_inferior (); -} - -void -inferior_died () -{ - inferior_pid = 0; - attach_flag = 0; - mark_breakpoints_out (); - select_frame ((FRAME) 0, -1); - reopen_exec_file (); - if (have_core_file_p ()) - set_current_frame ( create_new_frame (read_register (FP_REGNUM), - read_pc ())); - else - set_current_frame (0); -} - -#if 0 -/* This function is just for testing, and on some systems (Sony NewsOS - 3.2) also includes which leads to errors - (since on this system at least sys/time.h is not protected against - multiple inclusion). */ -static void -try_writing_regs_command () -{ - register int i; - register int value; - extern int errno; - - if (inferior_pid == 0) - error ("There is no inferior process now."); - - /* A Sun 3/50 or 3/60 (at least) running SunOS 4.0.3 will have a - kernel panic if we try to write past the end of the user area. - Presumably Sun will fix this bug (it has been reported), but it - is tacky to crash the system, so at least on SunOS4 we need to - stop writing when we hit the end of the user area. */ - for (i = 0; i < sizeof (struct user); i += 2) - { - QUIT; - errno = 0; - value = call_ptrace (3, inferior_pid, i, 0); - call_ptrace (6, inferior_pid, i, value); - if (errno == 0) - { - printf (" Succeeded with address 0x%x; value 0x%x (%d).\n", - i, value, value); - } - else if ((i & 0377) == 0) - printf (" Failed at 0x%x.\n", i); - } -} -#endif - -void -_initialize_inflow () -{ - add_com ("term-status", class_obscure, term_status_command, - "Print info on inferior's saved terminal status."); - -#if 0 - add_com ("try-writing-regs", class_obscure, try_writing_regs_command, - "Try writing all locations in inferior's system block.\n\ -Report which ones can be written."); -#endif - - add_com ("kill", class_run, kill_command, - "Kill execution of program being debugged."); - - inferior_pid = 0; - - ioctl (0, TIOCGETP, &sg_ours); - tflags_ours = fcntl (0, F_GETFL, 0); - -#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) - ioctl (0, TIOCGETC, &tc_ours); -#endif -#ifdef TIOCGLTC - ioctl (0, TIOCGLTC, <c_ours); -#endif -#ifdef TIOCLGET - ioctl (0, TIOCLGET, &lmode_ours); -#endif - -#ifdef TIOCGPGRP - ioctl (0, TIOCGPGRP, &pgrp_ours); -#endif /* TIOCGPGRP */ - - terminal_is_ours = 1; -} - diff --git a/gnu/usr.bin/gdb/infrun.c b/gnu/usr.bin/gdb/infrun.c deleted file mode 100644 index 887a0bb..0000000 --- a/gnu/usr.bin/gdb/infrun.c +++ /dev/null @@ -1,1459 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)infrun.c 6.4 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Start and stop the inferior process, for GDB. - Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Notes on the algorithm used in wait_for_inferior to determine if we - just did a subroutine call when stepping. We have the following - information at that point: - - Current and previous (just before this step) pc. - Current and previous sp. - Current and previous start of current function. - - If the start's of the functions don't match, then - - a) We did a subroutine call. - - In this case, the pc will be at the beginning of a function. - - b) We did a subroutine return. - - Otherwise. - - c) We did a longjmp. - - If we did a longjump, we were doing "nexti", since a next would - have attempted to skip over the assembly language routine in which - the longjmp is coded and would have simply been the equivalent of a - continue. I consider this ok behaivior. We'd like one of two - things to happen if we are doing a nexti through the longjmp() - routine: 1) It behaves as a stepi, or 2) It acts like a continue as - above. Given that this is a special case, and that anybody who - thinks that the concept of sub calls is meaningful in the context - of a longjmp, I'll take either one. Let's see what happens. - - Acts like a subroutine return. I can handle that with no problem - at all. - - -->So: If the current and previous beginnings of the current - function don't match, *and* the pc is at the start of a function, - we've done a subroutine call. If the pc is not at the start of a - function, we *didn't* do a subroutine call. - - -->If the beginnings of the current and previous function do match, - either: - - a) We just did a recursive call. - - In this case, we would be at the very beginning of a - function and 1) it will have a prologue (don't jump to - before prologue, or 2) (we assume here that it doesn't have - a prologue) there will have been a change in the stack - pointer over the last instruction. (Ie. it's got to put - the saved pc somewhere. The stack is the usual place. In - a recursive call a register is only an option if there's a - prologue to do something with it. This is even true on - register window machines; the prologue sets up the new - window. It might not be true on a register window machine - where the call instruction moved the register window - itself. Hmmm. One would hope that the stack pointer would - also change. If it doesn't, somebody send me a note, and - I'll work out a more general theory. - randy@wheaties.ai.mit.edu). This is true (albeit slipperly - so) on all machines I'm aware of: - - m68k: Call changes stack pointer. Regular jumps don't. - - sparc: Recursive calls must have frames and therefor, - prologues. - - vax: All calls have frames and hence change the - stack pointer. - - b) We did a return from a recursive call. I don't see that we - have either the ability or the need to distinguish this - from an ordinary jump. The stack frame will be printed - when and if the frame pointer changes; if we are in a - function without a frame pointer, it's the users own - lookout. - - c) We did a jump within a function. We assume that this is - true if we didn't do a recursive call. - - d) We are in no-man's land ("I see no symbols here"). We - don't worry about this; it will make calls look like simple - jumps (and the stack frames will be printed when the frame - pointer moves), which is a reasonably non-violent response. - -#if 0 - We skip this; it causes more problems than it's worth. -#ifdef SUN4_COMPILER_FEATURE - We do a special ifdef for the sun 4, forcing it to single step - into calls which don't have prologues. This means that we can't - nexti over leaf nodes, we can probably next over them (since they - won't have debugging symbols, usually), and we can next out of - functions returning structures (with a "call .stret4" at the end). -#endif -#endif -*/ - - - - - -#include -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "frame.h" -#include "inferior.h" -#include "wait.h" - -#include - -/* unistd.h is needed to #define X_OK */ -#ifdef USG -#include -#else -#include -#endif - -#ifdef UMAX_PTRACE -#include -#include -#include -#endif /* UMAX_PTRACE */ - -/* Required by . */ -#include -/* Required by , at least on system V. */ -#include -/* Needed by IN_SIGTRAMP on some machines (e.g. vax). */ -#include -/* Needed by IN_SIGTRAMP on some machines (e.g. vax). */ -#include - -extern char *sys_siglist[]; -extern int errno; - -/* Sigtramp is a routine that the kernel calls (which then calls the - signal handler). On most machines it is a library routine that - is linked into the executable. - - This macro, given a program counter value and the name of the - function in which that PC resides (which can be null if the - name is not known), returns nonzero if the PC and name show - that we are in sigtramp. - - On most machines just see if the name is sigtramp (and if we have - no name, assume we are not in sigtramp). */ -#if !defined (IN_SIGTRAMP) -#define IN_SIGTRAMP(pc, name) \ - name && !strcmp ("_sigtramp", name) -#endif - -/* Tables of how to react to signals; the user sets them. */ - -static char signal_stop[NSIG]; -static char signal_print[NSIG]; -static char signal_program[NSIG]; - -/* Nonzero if breakpoints are now inserted in the inferior. */ - -static int breakpoints_inserted; - -/* Function inferior was in as of last step command. */ - -static struct symbol *step_start_function; - -/* This is the sequence of bytes we insert for a breakpoint. */ - -static char break_insn[] = BREAKPOINT; - -/* Nonzero => address for special breakpoint for resuming stepping. */ - -static CORE_ADDR step_resume_break_address; - -/* Original contents of the byte where the special breakpoint is. */ - -static char step_resume_break_shadow[sizeof break_insn]; - -/* Nonzero means the special breakpoint is a duplicate - so it has not itself been inserted. */ - -static int step_resume_break_duplicate; - -/* Nonzero if we are expecting a trace trap and should proceed from it. - 2 means expecting 2 trace traps and should continue both times. - That occurs when we tell sh to exec the program: we will get - a trap after the exec of sh and a second when the program is exec'd. */ - -static int trap_expected; - -/* Nonzero if the next time we try to continue the inferior, it will - step one instruction and generate a spurious trace trap. - This is used to compensate for a bug in HP-UX. */ - -static int trap_expected_after_continue; - -/* Nonzero means expecting a trace trap - and should stop the inferior and return silently when it happens. */ - -int stop_after_trap; - -/* Nonzero means expecting a trace trap due to attaching to a process. */ - -int stop_after_attach; - -/* Nonzero if pc has been changed by the debugger - since the inferior stopped. */ - -int pc_changed; - -/* Nonzero if debugging a remote machine via a serial link or ethernet. */ - -int remote_debugging; - -/* Nonzero if program stopped due to error trying to insert breakpoints. */ - -static int breakpoints_failed; - -/* Nonzero if inferior is in sh before our program got exec'd. */ - -static int running_in_shell; - -/* Nonzero after stop if current stack frame should be printed. */ - -static int stop_print_frame; - -#ifdef NO_SINGLE_STEP -extern int one_stepped; /* From machine dependent code */ -extern void single_step (); /* Same. */ -#endif /* NO_SINGLE_STEP */ - -static void insert_step_breakpoint (); -static void remove_step_breakpoint (); -static void wait_for_inferior (); -static void normal_stop (); - - -/* Clear out all variables saying what to do when inferior is continued. - First do this, then set the ones you want, then call `proceed'. */ - -void -clear_proceed_status () -{ - trap_expected = 0; - step_range_start = 0; - step_range_end = 0; - step_frame_address = 0; - step_over_calls = -1; - step_resume_break_address = 0; - stop_after_trap = 0; - stop_after_attach = 0; - - /* Discard any remaining commands left by breakpoint we had stopped at. */ - clear_breakpoint_commands (); -} - -/* Basic routine for continuing the program in various fashions. - - ADDR is the address to resume at, or -1 for resume where stopped. - SIGNAL is the signal to give it, or 0 for none, - or -1 for act according to how it stopped. - STEP is nonzero if should trap after one instruction. - -1 means return after that and print nothing. - You should probably set various step_... variables - before calling here, if you are stepping. - - You should call clear_proceed_status before calling proceed. */ - -void -proceed (addr, signal, step) - CORE_ADDR addr; - int signal; - int step; -{ - int oneproc = 0; - - if (step > 0) - step_start_function = find_pc_function (read_pc ()); - if (step < 0) - stop_after_trap = 1; - - if (addr == -1) - { - /* If there is a breakpoint at the address we will resume at, - step one instruction before inserting breakpoints - so that we do not stop right away. */ - - if (!pc_changed && breakpoint_here_p (read_pc ())) - oneproc = 1; - } - else - { - write_register (PC_REGNUM, addr); -#ifdef NPC_REGNUM - write_register (NPC_REGNUM, addr + 4); -#endif - } - - if (trap_expected_after_continue) - { - /* If (step == 0), a trap will be automatically generated after - the first instruction is executed. Force step one - instruction to clear this condition. This should not occur - if step is nonzero, but it is harmless in that case. */ - oneproc = 1; - trap_expected_after_continue = 0; - } - - if (oneproc) - /* We will get a trace trap after one instruction. - Continue it automatically and insert breakpoints then. */ - trap_expected = 1; - else - { - int temp = insert_breakpoints (); - if (temp) - { - print_sys_errmsg ("ptrace", temp); - error ("Cannot insert breakpoints.\n\ -The same program may be running in another process."); - } - breakpoints_inserted = 1; - } - - /* Install inferior's terminal modes. */ - terminal_inferior (); - - if (signal >= 0) - stop_signal = signal; - /* If this signal should not be seen by program, - give it zero. Used for debugging signals. */ - else if (stop_signal < NSIG && !signal_program[stop_signal]) - stop_signal= 0; - - /* Resume inferior. */ - resume (oneproc || step, stop_signal); - - /* Wait for it to stop (if not standalone) - and in any case decode why it stopped, and act accordingly. */ - - wait_for_inferior (); - normal_stop (); -} - -/* Writing the inferior pc as a register calls this function - to inform infrun that the pc has been set in the debugger. */ - -void -writing_pc (val) - CORE_ADDR val; -{ - stop_pc = val; - pc_changed = 1; -} - -/* Start an inferior process for the first time. - Actually it was started by the fork that created it, - but it will have stopped one instruction after execing sh. - Here we must get it up to actual execution of the real program. */ - -void -start_inferior () -{ - /* We will get a trace trap after one instruction. - Continue it automatically. Eventually (after shell does an exec) - it will get another trace trap. Then insert breakpoints and continue. */ - -#ifdef START_INFERIOR_TRAPS_EXPECTED - trap_expected = START_INFERIOR_TRAPS_EXPECTED; -#else - trap_expected = 2; -#endif - - running_in_shell = 0; /* Set to 1 at first SIGTRAP, 0 at second. */ - trap_expected_after_continue = 0; - breakpoints_inserted = 0; - mark_breakpoints_out (); - - /* Set up the "saved terminal modes" of the inferior - based on what modes we are starting it with. */ - terminal_init_inferior (); - - /* Install inferior's terminal modes. */ - terminal_inferior (); - - if (remote_debugging) - { - trap_expected = 0; - fetch_inferior_registers(); - set_current_frame (create_new_frame (read_register (FP_REGNUM), - read_pc ())); - stop_frame_address = FRAME_FP (get_current_frame()); - inferior_pid = 3; - if (insert_breakpoints()) - fatal("Can't insert breakpoints"); - breakpoints_inserted = 1; - proceed(-1, -1, 0); - } - else - { - wait_for_inferior (); - normal_stop (); - } -} - -/* Start or restart remote-debugging of a machine over a serial link. */ - -void -restart_remote () -{ - clear_proceed_status (); - running_in_shell = 0; - trap_expected = 0; - stop_after_attach = 1; - inferior_pid = 3; - wait_for_inferior (); - normal_stop(); -} - -void -start_remote () -{ - breakpoints_inserted = 0; - mark_breakpoints_out (); - restart_remote(); -} - -#ifdef ATTACH_DETACH - -/* Attach to process PID, then initialize for debugging it - and wait for the trace-trap that results from attaching. */ - -void -attach_program (pid) - int pid; -{ - attach (pid); - inferior_pid = pid; - - mark_breakpoints_out (); - terminal_init_inferior (); - clear_proceed_status (); - stop_after_attach = 1; - /*proceed (-1, 0, -2);*/ - terminal_inferior (); - wait_for_inferior (); - normal_stop (); -} -#endif /* ATTACH_DETACH */ - -/* Wait for control to return from inferior to debugger. - If inferior gets a signal, we may decide to start it up again - instead of returning. That is why there is a loop in this function. - When this function actually returns it means the inferior - should be left stopped and GDB should read more commands. */ - -static void -wait_for_inferior () -{ - register int pid; - WAITTYPE w; - CORE_ADDR pc; - int tem; - int another_trap; - int random_signal; - CORE_ADDR stop_sp, prev_sp; - CORE_ADDR prev_func_start, stop_func_start; - char *prev_func_name, *stop_func_name; - CORE_ADDR prologue_pc; - int stop_step_resume_break; - CORE_ADDR step_resume_break_sp; - int newmisc; - int newfun_pc; - struct symtab_and_line sal; - int prev_pc; - extern CORE_ADDR text_end; - int remove_breakpoints_on_following_step = 0; - - prev_pc = read_pc (); - (void) find_pc_partial_function (prev_pc, &prev_func_name, - &prev_func_start); - prev_func_start += FUNCTION_START_OFFSET; - prev_sp = read_register (SP_REGNUM); - - while (1) - { - /* Clean up saved state that will become invalid. */ - pc_changed = 0; - flush_cached_frames (); - - if (remote_debugging) - remote_wait (&w); - else - { - pid = wait (&w); - if (pid != inferior_pid) - continue; - } - - /* See if the process still exists; clean up if it doesn't. */ - if (WIFEXITED (w)) - { - terminal_ours_for_output (); - if (WEXITSTATUS (w)) - printf ("\nProgram exited with code 0%o.\n", WEXITSTATUS (w)); - else - printf ("\nProgram exited normally.\n"); - fflush (stdout); - inferior_died (); -#ifdef NO_SINGLE_STEP - one_stepped = 0; -#endif - stop_print_frame = 0; - break; - } - else if (!WIFSTOPPED (w)) - { - kill_inferior (); - stop_print_frame = 0; - stop_signal = WTERMSIG (w); - terminal_ours_for_output (); - printf ("\nProgram terminated with signal %d, %s\n", - stop_signal, - stop_signal < NSIG - ? sys_siglist[stop_signal] - : "(undocumented)"); - printf ("The inferior process no longer exists.\n"); - fflush (stdout); -#ifdef NO_SINGLE_STEP - one_stepped = 0; -#endif - break; - } - -#ifdef NO_SINGLE_STEP - if (one_stepped) - single_step (0); /* This actually cleans up the ss */ -#endif /* NO_SINGLE_STEP */ - - fetch_inferior_registers (); - stop_pc = read_pc (); - set_current_frame ( create_new_frame (read_register (FP_REGNUM), - read_pc ())); - - stop_frame_address = FRAME_FP (get_current_frame ()); - stop_sp = read_register (SP_REGNUM); - stop_func_start = 0; - stop_func_name = 0; - /* Don't care about return value; stop_func_start and stop_func_name - will both be 0 if it doesn't work. */ - (void) find_pc_partial_function (stop_pc, &stop_func_name, - &stop_func_start); - stop_func_start += FUNCTION_START_OFFSET; - another_trap = 0; - stop_breakpoint = 0; - stop_step = 0; - stop_stack_dummy = 0; - stop_print_frame = 1; - stop_step_resume_break = 0; - random_signal = 0; - stopped_by_random_signal = 0; - breakpoints_failed = 0; - - /* Look at the cause of the stop, and decide what to do. - The alternatives are: - 1) break; to really stop and return to the debugger, - 2) drop through to start up again - (set another_trap to 1 to single step once) - 3) set random_signal to 1, and the decision between 1 and 2 - will be made according to the signal handling tables. */ - - stop_signal = WSTOPSIG (w); - - /* First, distinguish signals caused by the debugger from signals - that have to do with the program's own actions. - Note that breakpoint insns may cause SIGTRAP or SIGILL - or SIGEMT, depending on the operating system version. - Here we detect when a SIGILL or SIGEMT is really a breakpoint - and change it to SIGTRAP. */ - - if (stop_signal == SIGTRAP - || (breakpoints_inserted && - (stop_signal == SIGILL - || stop_signal == SIGEMT)) - || stop_after_attach) - { - if (stop_signal == SIGTRAP && stop_after_trap) - { - stop_print_frame = 0; - break; - } - if (stop_after_attach) - break; - /* Don't even think about breakpoints - if still running the shell that will exec the program - or if just proceeded over a breakpoint. */ - if (stop_signal == SIGTRAP && trap_expected) - stop_breakpoint = 0; - else - { - /* See if there is a breakpoint at the current PC. */ -#if DECR_PC_AFTER_BREAK - /* Notice the case of stepping through a jump - that leads just after a breakpoint. - Don't confuse that with hitting the breakpoint. - What we check for is that 1) stepping is going on - and 2) the pc before the last insn does not match - the address of the breakpoint before the current pc. */ - if (!(prev_pc != stop_pc - DECR_PC_AFTER_BREAK - && step_range_end && !step_resume_break_address)) -#endif /* DECR_PC_AFTER_BREAK not zero */ - { - /* See if we stopped at the special breakpoint for - stepping over a subroutine call. */ - if (stop_pc - DECR_PC_AFTER_BREAK - == step_resume_break_address) - { - stop_step_resume_break = 1; - if (DECR_PC_AFTER_BREAK) - { - stop_pc -= DECR_PC_AFTER_BREAK; - write_register (PC_REGNUM, stop_pc); - pc_changed = 0; - } - } - else - { - stop_breakpoint = - breakpoint_stop_status (stop_pc, stop_frame_address); - /* Following in case break condition called a - function. */ - stop_print_frame = 1; - if (stop_breakpoint && DECR_PC_AFTER_BREAK) - { - stop_pc -= DECR_PC_AFTER_BREAK; - write_register (PC_REGNUM, stop_pc); -#ifdef NPC_REGNUM - write_register (NPC_REGNUM, stop_pc + 4); -#endif - pc_changed = 0; - } - } - } - } - - if (stop_signal == SIGTRAP) - random_signal - = !(stop_breakpoint || trap_expected - || stop_step_resume_break -#ifndef CANNOT_EXECUTE_STACK - || (stop_sp INNER_THAN stop_pc - && stop_pc INNER_THAN stop_frame_address) -#else - || stop_pc == text_end - 2 -#endif - || (step_range_end && !step_resume_break_address)); - else - { - random_signal - = !(stop_breakpoint - || stop_step_resume_break -#ifdef sony_news - || (stop_sp INNER_THAN stop_pc - && stop_pc INNER_THAN stop_frame_address) -#endif - - ); - if (!random_signal) - stop_signal = SIGTRAP; - } - } - else - random_signal = 1; - - /* For the program's own signals, act according to - the signal handling tables. */ - - if (random_signal - && !(running_in_shell && stop_signal == SIGSEGV)) - { - /* Signal not for debugging purposes. */ - int printed = 0; - - stopped_by_random_signal = 1; - - if (stop_signal >= NSIG - || signal_print[stop_signal]) - { - printed = 1; - terminal_ours_for_output (); - printf ("\nProgram received signal %d, %s\n", - stop_signal, - stop_signal < NSIG - ? sys_siglist[stop_signal] - : "(undocumented)"); - fflush (stdout); - } - if (stop_signal >= NSIG - || signal_stop[stop_signal]) - break; - /* If not going to stop, give terminal back - if we took it away. */ - else if (printed) - terminal_inferior (); - } - - /* Handle cases caused by hitting a breakpoint. */ - - if (!random_signal - && (stop_breakpoint || stop_step_resume_break)) - { - /* Does a breakpoint want us to stop? */ - if (stop_breakpoint && stop_breakpoint != -1 - && stop_breakpoint != -0x1000001) - { - /* 0x1000000 is set in stop_breakpoint as returned by - breakpoint_stop_status to indicate a silent - breakpoint. */ - if ((stop_breakpoint > 0 ? stop_breakpoint : - -stop_breakpoint) - & 0x1000000) - { - stop_print_frame = 0; - if (stop_breakpoint > 0) - stop_breakpoint -= 0x1000000; - else - stop_breakpoint += 0x1000000; - } - break; - } - /* But if we have hit the step-resumption breakpoint, - remove it. It has done its job getting us here. - The sp test is to make sure that we don't get hung - up in recursive calls in functions without frame - pointers. If the stack pointer isn't outside of - where the breakpoint was set (within a routine to be - stepped over), we're in the middle of a recursive - call. Not true for reg window machines (sparc) - because the must change frames to call things and - the stack pointer doesn't have to change if it - the bp was set in a routine without a frame (pc can - be stored in some other window). - - The removal of the sp test is to allow calls to - alloca. Nasty things were happening. Oh, well, - gdb can only handle one level deep of lack of - frame pointer. */ - if (stop_step_resume_break - && (step_frame_address == 0 - || (stop_frame_address == step_frame_address))) - { - remove_step_breakpoint (); - step_resume_break_address = 0; - } - /* Otherwise, must remove breakpoints and single-step - to get us past the one we hit. */ - else - { - remove_breakpoints (); - remove_step_breakpoint (); - breakpoints_inserted = 0; - another_trap = 1; - } - - /* We come here if we hit a breakpoint but should not - stop for it. Possibly we also were stepping - and should stop for that. So fall through and - test for stepping. But, if not stepping, - do not stop. */ - } - - /* If this is the breakpoint at the end of a stack dummy, - just stop silently. */ -#ifndef CANNOT_EXECUTE_STACK - if (stop_sp INNER_THAN stop_pc - && stop_pc INNER_THAN stop_frame_address) -#else - if (stop_pc == text_end - 2) -#endif - { - stop_print_frame = 0; - stop_stack_dummy = 1; -#ifdef HP_OS_BUG - trap_expected_after_continue = 1; -#endif - break; - } - - if (step_resume_break_address) - /* Having a step-resume breakpoint overrides anything - else having to do with stepping commands until - that breakpoint is reached. */ - ; - /* If stepping through a line, keep going if still within it. */ - else if (!random_signal - && step_range_end - && stop_pc >= step_range_start - && stop_pc < step_range_end - /* The step range might include the start of the - function, so if we are at the start of the - step range and either the stack or frame pointers - just changed, we've stepped outside */ - && !(stop_pc == step_range_start - && stop_frame_address - && (stop_sp INNER_THAN prev_sp - || stop_frame_address != step_frame_address))) - { - /* Don't step through the return from a function - unless that is the first instruction stepped through. */ - if (ABOUT_TO_RETURN (stop_pc)) - { - stop_step = 1; - break; - } - } - - /* We stepped out of the stepping range. See if that was due - to a subroutine call that we should proceed to the end of. */ - else if (!random_signal && step_range_end) - { - if (stop_func_start) - { - prologue_pc = stop_func_start; - SKIP_PROLOGUE (prologue_pc); - } - - /* Did we just take a signal? */ - if (IN_SIGTRAMP (stop_pc, stop_func_name) - && !IN_SIGTRAMP (prev_pc, prev_func_name)) - { - /* This code is needed at least in the following case: - The user types "next" and then a signal arrives (before - the "next" is done). */ - /* We've just taken a signal; go until we are back to - the point where we took it and one more. */ - step_resume_break_address = prev_pc; - step_resume_break_duplicate = - breakpoint_here_p (step_resume_break_address); - step_resume_break_sp = stop_sp; - if (breakpoints_inserted) - insert_step_breakpoint (); - /* Make sure that the stepping range gets us past - that instruction. */ - if (step_range_end == 1) - step_range_end = (step_range_start = prev_pc) + 1; - remove_breakpoints_on_following_step = 1; - } - - /* ==> See comments at top of file on this algorithm. <==*/ - - else if (stop_pc == stop_func_start - && (stop_func_start != prev_func_start - || prologue_pc != stop_func_start - || stop_sp != prev_sp)) - { - /* It's a subroutine call */ - if (step_over_calls > 0 - || (step_over_calls && find_pc_function (stop_pc) == 0)) - { - /* A subroutine call has happened. */ - /* Set a special breakpoint after the return */ - step_resume_break_address = - SAVED_PC_AFTER_CALL (get_current_frame ()); - step_resume_break_duplicate - = breakpoint_here_p (step_resume_break_address); - step_resume_break_sp = stop_sp; - if (breakpoints_inserted) - insert_step_breakpoint (); - } - /* Subroutine call with source code we should not step over. - Do step to the first line of code in it. */ - else if (step_over_calls) - { - SKIP_PROLOGUE (stop_func_start); - sal = find_pc_line (stop_func_start, 0); - /* Use the step_resume_break to step until - the end of the prologue, even if that involves jumps - (as it seems to on the vax under 4.2). */ - /* If the prologue ends in the middle of a source line, - continue to the end of that source line. - Otherwise, just go to end of prologue. */ -#ifdef PROLOGUE_FIRSTLINE_OVERLAP - /* no, don't either. It skips any code that's - legitimately on the first line. */ -#else - if (sal.end && sal.pc != stop_func_start) - stop_func_start = sal.end; -#endif - - if (stop_func_start == stop_pc) - { - /* We are already there: stop now. */ - stop_step = 1; - break; - } - else - /* Put the step-breakpoint there and go until there. */ - { - step_resume_break_address = stop_func_start; - step_resume_break_sp = stop_sp; - - step_resume_break_duplicate - = breakpoint_here_p (step_resume_break_address); - if (breakpoints_inserted) - insert_step_breakpoint (); - /* Do not specify what the fp should be when we stop - since on some machines the prologue - is where the new fp value is established. */ - step_frame_address = 0; - /* And make sure stepping stops right away then. */ - step_range_end = step_range_start; - } - } - else - { - /* We get here only if step_over_calls is 0 and we - just stepped into a subroutine. I presume - that step_over_calls is only 0 when we're - supposed to be stepping at the assembly - language level.*/ - stop_step = 1; - break; - } - } - /* No subroutince call; stop now. */ - else - { - stop_step = 1; - break; - } - } - - /* Save the pc before execution, to compare with pc after stop. */ - prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ - prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER - BREAK is defined, the - original pc would not have - been at the start of a - function. */ - prev_func_name = stop_func_name; - prev_sp = stop_sp; - - /* If we did not do break;, it means we should keep - running the inferior and not return to debugger. */ - - /* If trap_expected is 2, it means continue once more - and insert breakpoints at the next trap. - If trap_expected is 1 and the signal was SIGSEGV, it means - the shell is doing some memory allocation--just resume it - with SIGSEGV. - Otherwise insert breakpoints now, and possibly single step. */ - - if (trap_expected > 1) - { - trap_expected--; - running_in_shell = 1; - resume (0, 0); - } - else if (running_in_shell && stop_signal == SIGSEGV) - { - resume (0, SIGSEGV); - } - else if (trap_expected && stop_signal != SIGTRAP) - { - /* We took a signal which we are supposed to pass through to - the inferior and we haven't yet gotten our trap. Simply - continue. */ - resume ((step_range_end && !step_resume_break_address) - || trap_expected, - stop_signal); - } - else - { - /* Here, we are not awaiting another exec to get - the program we really want to debug. - Insert breakpoints now, unless we are trying - to one-proceed past a breakpoint. */ - running_in_shell = 0; - /* If we've just finished a special step resume and we don't - want to hit a breakpoint, pull em out. */ - if (!step_resume_break_address && - remove_breakpoints_on_following_step) - { - remove_breakpoints_on_following_step = 0; - remove_breakpoints (); - breakpoints_inserted = 0; - } - else if (!breakpoints_inserted && !another_trap) - { - insert_step_breakpoint (); - breakpoints_failed = insert_breakpoints (); - if (breakpoints_failed) - break; - breakpoints_inserted = 1; - } - - trap_expected = another_trap; - - if (stop_signal == SIGTRAP) - stop_signal = 0; - - resume ((step_range_end && !step_resume_break_address) - || trap_expected, - stop_signal); - } - } -} - -/* Here to return control to GDB when the inferior stops for real. - Print appropriate messages, remove breakpoints, give terminal our modes. - - RUNNING_IN_SHELL nonzero means the shell got a signal before - exec'ing the program we wanted to run. - STOP_PRINT_FRAME nonzero means print the executing frame - (pc, function, args, file, line number and line text). - BREAKPOINTS_FAILED nonzero means stop was due to error - attempting to insert breakpoints. */ - -static void -normal_stop () -{ - /* Make sure that the current_frame's pc is correct. This - is a correction for setting up the frame info before doing - DECR_PC_AFTER_BREAK */ - if (inferior_pid) - (get_current_frame ())->pc = read_pc (); - - if (breakpoints_failed) - { - terminal_ours_for_output (); - print_sys_errmsg ("ptrace", breakpoints_failed); - printf ("Stopped; cannot insert breakpoints.\n\ -The same program may be running in another process.\n"); - } - - if (inferior_pid) - remove_step_breakpoint (); - - if (inferior_pid && breakpoints_inserted) - if (remove_breakpoints ()) - { - terminal_ours_for_output (); - printf ("Cannot remove breakpoints because program is no longer writable.\n\ -It must be running in another process.\n\ -Further execution is probably impossible.\n"); - } - - breakpoints_inserted = 0; - - /* Delete the breakpoint we stopped at, if it wants to be deleted. - Delete any breakpoint that is to be deleted at the next stop. */ - - breakpoint_auto_delete (stop_breakpoint); - - /* If an auto-display called a function and that got a signal, - delete that auto-display to avoid an infinite recursion. */ - - if (stopped_by_random_signal) - disable_current_display (); - - if (step_multi && stop_step) - return; - - terminal_ours (); - - if (running_in_shell) - { - if (stop_signal == SIGSEGV) - { - char *exec_file = (char *) get_exec_file (1); - - if (access (exec_file, X_OK) != 0) - printf ("The file \"%s\" is not executable.\n", exec_file); - else - /* I don't think we should ever get here. - wait_for_inferior now ignores SIGSEGV's which happen in - the shell (since the Bourne shell (/bin/sh) has some - rather, er, uh, *unorthodox* memory management - involving catching SIGSEGV). */ - printf ("\ -You have just encountered a bug in \"sh\". GDB starts your program\n\ -by running \"sh\" with a command to exec your program.\n\ -This is so that \"sh\" will process wildcards and I/O redirection.\n\ -This time, \"sh\" crashed.\n\ -\n\ -One known bug in \"sh\" bites when the environment takes up a lot of space.\n\ -Try \"info env\" to see the environment; then use \"delete env\" to kill\n\ -some variables whose values are large; then do \"run\" again.\n\ -\n\ -If that works, you might want to put those \"delete env\" commands\n\ -into a \".gdbinit\" file in this directory so they will happen every time.\n"); - } - /* Don't confuse user with his program's symbols on sh's data. */ - stop_print_frame = 0; - } - - if (inferior_pid == 0) - return; - - /* Select innermost stack frame except on return from a stack dummy routine, - or if the program has exited. */ - if (!stop_stack_dummy) - { - select_frame (get_current_frame (), 0); - - if (stop_print_frame) - { - if (stop_breakpoint > 0) - printf ("\nBpt %d, ", stop_breakpoint); - print_sel_frame (stop_step - && step_frame_address == stop_frame_address - && step_start_function == find_pc_function (stop_pc)); - /* Display the auto-display expressions. */ - do_displays (); - } - } - - if (stop_stack_dummy) - { - /* Pop the empty frame that contains the stack dummy. - POP_FRAME ends with a setting of the current frame, so we - can use that next. */ -#ifndef NEW_CALL_FUNCTION - POP_FRAME; -#endif - select_frame (get_current_frame (), 0); - } -} - -static void -insert_step_breakpoint () -{ - if (step_resume_break_address && !step_resume_break_duplicate) - { - read_memory (step_resume_break_address, - step_resume_break_shadow, sizeof break_insn); - write_memory (step_resume_break_address, - break_insn, sizeof break_insn); - } -} - -static void -remove_step_breakpoint () -{ - if (step_resume_break_address && !step_resume_break_duplicate) - write_memory (step_resume_break_address, step_resume_break_shadow, - sizeof break_insn); -} - -/* Specify how various signals in the inferior should be handled. */ - -static void -handle_command (args, from_tty) - char *args; - int from_tty; -{ - register char *p = args; - int signum = 0; - register int digits, wordlen; - - if (!args) - error_no_arg ("signal to handle"); - - while (*p) - { - /* Find the end of the next word in the args. */ - for (wordlen = 0; p[wordlen] && p[wordlen] != ' ' && p[wordlen] != '\t'; - wordlen++); - for (digits = 0; p[digits] >= '0' && p[digits] <= '9'; digits++); - - /* If it is all digits, it is signal number to operate on. */ - if (digits == wordlen) - { - signum = atoi (p); - if (signum <= 0 || signum >= NSIG) - { - p[wordlen] = '\0'; - error ("Invalid signal %s given as argument to \"handle\".", p); - } - if (signum == SIGTRAP || signum == SIGINT) - { - if (!query ("Signal %d is used by the debugger.\nAre you sure you want to change it? ", signum)) - error ("Not confirmed."); - } - } - else if (signum == 0) - error ("First argument is not a signal number."); - - /* Else, if already got a signal number, look for flag words - saying what to do for it. */ - else if (!strncmp (p, "stop", wordlen)) - { - signal_stop[signum] = 1; - signal_print[signum] = 1; - } - else if (wordlen >= 2 && !strncmp (p, "print", wordlen)) - signal_print[signum] = 1; - else if (wordlen >= 2 && !strncmp (p, "pass", wordlen)) - signal_program[signum] = 1; - else if (!strncmp (p, "ignore", wordlen)) - signal_program[signum] = 0; - else if (wordlen >= 3 && !strncmp (p, "nostop", wordlen)) - signal_stop[signum] = 0; - else if (wordlen >= 4 && !strncmp (p, "noprint", wordlen)) - { - signal_print[signum] = 0; - signal_stop[signum] = 0; - } - else if (wordlen >= 4 && !strncmp (p, "nopass", wordlen)) - signal_program[signum] = 0; - else if (wordlen >= 3 && !strncmp (p, "noignore", wordlen)) - signal_program[signum] = 1; - /* Not a number and not a recognized flag word => complain. */ - else - { - p[wordlen] = 0; - error ("Unrecognized flag word: \"%s\".", p); - } - - /* Find start of next word. */ - p += wordlen; - while (*p == ' ' || *p == '\t') p++; - } - - if (from_tty) - { - /* Show the results. */ - printf ("Number\tStop\tPrint\tPass to program\tDescription\n"); - printf ("%d\t", signum); - printf ("%s\t", signal_stop[signum] ? "Yes" : "No"); - printf ("%s\t", signal_print[signum] ? "Yes" : "No"); - printf ("%s\t\t", signal_program[signum] ? "Yes" : "No"); - printf ("%s\n", sys_siglist[signum]); - } -} - -/* Print current contents of the tables set by the handle command. */ - -static void -signals_info (signum_exp) - char *signum_exp; -{ - register int i; - printf_filtered ("Number\tStop\tPrint\tPass to program\tDescription\n"); - - if (signum_exp) - { - i = parse_and_eval_address (signum_exp); - if (i >= NSIG || i < 0) - error ("Signal number out of bounds."); - printf_filtered ("%d\t", i); - printf_filtered ("%s\t", signal_stop[i] ? "Yes" : "No"); - printf_filtered ("%s\t", signal_print[i] ? "Yes" : "No"); - printf_filtered ("%s\t\t", signal_program[i] ? "Yes" : "No"); - printf_filtered ("%s\n", sys_siglist[i]); - return; - } - - printf_filtered ("\n"); - for (i = 0; i < NSIG; i++) - { - QUIT; - - printf_filtered ("%d\t", i); - printf_filtered ("%s\t", signal_stop[i] ? "Yes" : "No"); - printf_filtered ("%s\t", signal_print[i] ? "Yes" : "No"); - printf_filtered ("%s\t\t", signal_program[i] ? "Yes" : "No"); - printf_filtered ("%s\n", sys_siglist[i]); - } - - printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); -} - -/* Save all of the information associated with the inferior<==>gdb - connection. INF_STATUS is a pointer to a "struct inferior_status" - (defined in inferior.h). */ - -struct command_line *get_breakpoint_commands (); - -void -save_inferior_status (inf_status, restore_stack_info) - struct inferior_status *inf_status; - int restore_stack_info; -{ - inf_status->pc_changed = pc_changed; - inf_status->stop_signal = stop_signal; - inf_status->stop_pc = stop_pc; - inf_status->stop_frame_address = stop_frame_address; - inf_status->stop_breakpoint = stop_breakpoint; - inf_status->stop_step = stop_step; - inf_status->stop_stack_dummy = stop_stack_dummy; - inf_status->stopped_by_random_signal = stopped_by_random_signal; - inf_status->trap_expected = trap_expected; - inf_status->step_range_start = step_range_start; - inf_status->step_range_end = step_range_end; - inf_status->step_frame_address = step_frame_address; - inf_status->step_over_calls = step_over_calls; - inf_status->step_resume_break_address = step_resume_break_address; - inf_status->stop_after_trap = stop_after_trap; - inf_status->stop_after_attach = stop_after_attach; - inf_status->breakpoint_commands = get_breakpoint_commands (); - inf_status->restore_stack_info = restore_stack_info; - - read_register_bytes(0, inf_status->register_context, REGISTER_BYTES); - record_selected_frame (&(inf_status->selected_frame_address), - &(inf_status->selected_level)); - return; -} - -void -restore_inferior_status (inf_status) - struct inferior_status *inf_status; -{ - FRAME fid; - int level = inf_status->selected_level; - - pc_changed = inf_status->pc_changed; - stop_signal = inf_status->stop_signal; - stop_pc = inf_status->stop_pc; - stop_frame_address = inf_status->stop_frame_address; - stop_breakpoint = inf_status->stop_breakpoint; - stop_step = inf_status->stop_step; - stop_stack_dummy = inf_status->stop_stack_dummy; - stopped_by_random_signal = inf_status->stopped_by_random_signal; - trap_expected = inf_status->trap_expected; - step_range_start = inf_status->step_range_start; - step_range_end = inf_status->step_range_end; - step_frame_address = inf_status->step_frame_address; - step_over_calls = inf_status->step_over_calls; - step_resume_break_address = inf_status->step_resume_break_address; - stop_after_trap = inf_status->stop_after_trap; - stop_after_attach = inf_status->stop_after_attach; - set_breakpoint_commands (inf_status->breakpoint_commands); - - write_register_bytes(0, inf_status->register_context, REGISTER_BYTES); - - /* The inferior can be gone if the user types "print exit(0)" - (and perhaps other times). */ - if (have_inferior_p() && inf_status->restore_stack_info) - { - flush_cached_frames(); - set_current_frame(create_new_frame(read_register (FP_REGNUM), - read_pc())); - - fid = find_relative_frame (get_current_frame (), &level); - - if (fid == 0 || - FRAME_FP (fid) != inf_status->selected_frame_address || - level != 0) - { - /* I'm not sure this error message is a good idea. I have - only seen it occur after "Can't continue previously - requested operation" (we get called from do_cleanups), in - which case it just adds insult to injury (one confusing - error message after another. Besides which, does the - user really care if we can't restore the previously - selected frame? */ - fprintf (stderr, "Unable to restore previously selected frame.\n"); - select_frame (get_current_frame (), 0); - return; - } - - select_frame (fid, inf_status->selected_level); - } - return; -} - - -void -_initialize_infrun () -{ - register int i; - - add_info ("signals", signals_info, - "What debugger does when program gets various signals.\n\ -Specify a signal number as argument to print info on that signal only."); - - add_com ("handle", class_run, handle_command, - "Specify how to handle a signal.\n\ -Args are signal number followed by flags.\n\ -Flags allowed are \"stop\", \"print\", \"pass\",\n\ - \"nostop\", \"noprint\" or \"nopass\".\n\ -Print means print a message if this signal happens.\n\ -Stop means reenter debugger if this signal happens (implies print).\n\ -Pass means let program see this signal; otherwise program doesn't know.\n\ -Pass and Stop may be combined."); - - for (i = 0; i < NSIG; i++) - { - signal_stop[i] = 1; - signal_print[i] = 1; - signal_program[i] = 1; - } - - /* Signals caused by debugger's own actions - should not be given to the program afterwards. */ - signal_program[SIGTRAP] = 0; - signal_program[SIGINT] = 0; - - /* Signals that are not errors should not normally enter the debugger. */ -#ifdef SIGALRM - signal_stop[SIGALRM] = 0; - signal_print[SIGALRM] = 0; -#endif /* SIGALRM */ -#ifdef SIGVTALRM - signal_stop[SIGVTALRM] = 0; - signal_print[SIGVTALRM] = 0; -#endif /* SIGVTALRM */ -#ifdef SIGPROF - signal_stop[SIGPROF] = 0; - signal_print[SIGPROF] = 0; -#endif /* SIGPROF */ -#ifdef SIGCHLD - signal_stop[SIGCHLD] = 0; - signal_print[SIGCHLD] = 0; -#endif /* SIGCHLD */ -#ifdef SIGCLD - signal_stop[SIGCLD] = 0; - signal_print[SIGCLD] = 0; -#endif /* SIGCLD */ -#ifdef SIGIO - signal_stop[SIGIO] = 0; - signal_print[SIGIO] = 0; -#endif /* SIGIO */ -#ifdef SIGURG - signal_stop[SIGURG] = 0; - signal_print[SIGURG] = 0; -#endif /* SIGURG */ -} - diff --git a/gnu/usr.bin/gdb/kgdb_proto.h b/gnu/usr.bin/gdb/kgdb_proto.h deleted file mode 100644 index 8bbd5be..0000000 --- a/gnu/usr.bin/gdb/kgdb_proto.h +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Steven McCanne of Lawrence Berkeley Laboratory. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)kgdb_proto.h 6.3 (Berkeley) 5/8/91 - * - * - * $Header: /home/cvs/386BSD/src/usr.bin/gdb/kgdb_proto.h,v 1.1.1.1 1993/06/12 14:52:25 rgrimes Exp $ (LBL) - */ - -/* - * Message types. - */ -#define KGDB_MEM_R 0x01 -#define KGDB_MEM_W 0x02 -#define KGDB_REG_R 0x03 -#define KGDB_REG_W 0x04 -#define KGDB_CONT 0x05 -#define KGDB_STEP 0x06 -#define KGDB_KILL 0x07 -#define KGDB_SIGNAL 0x08 -#define KGDB_EXEC 0x09 - -#define KGDB_CMD(x) ((x) & 0x0f) - -/* - * Message flags. - */ -#define KGDB_ACK 0x80 -#define KGDB_DELTA 0x40 -#define KGDB_MORE 0x20 -#define KGDB_SEQ 0x10 diff --git a/gnu/usr.bin/gdb/main.c b/gnu/usr.bin/gdb/main.c deleted file mode 100644 index 323de87..0000000 --- a/gnu/usr.bin/gdb/main.c +++ /dev/null @@ -1,2241 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)main.c 6.6 (Berkeley) 5/13/91"; -#endif /* not lint */ - -/* Top level for GDB, the GNU debugger. - Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "command.h" -#include "param.h" -#include "expression.h" - -#ifdef USG -#include -#include -#endif - -#include -#include -#include -#include -#include -#include - -#ifdef SET_STACK_LIMIT_HUGE -#include -#include - -int original_stack_limit; -#endif - -/* If this definition isn't overridden by the header files, assume - that isatty and fileno exist on this system. */ -#ifndef ISATTY -#define ISATTY(FP) (isatty (fileno (FP))) -#endif - -extern void free (); - -/* Version number of GDB, as a string. */ - -extern char *version; - -/* - * Declare all cmd_list_element's - */ - -/* Chain containing all defined commands. */ - -struct cmd_list_element *cmdlist; - -/* Chain containing all defined info subcommands. */ - -struct cmd_list_element *infolist; - -/* Chain containing all defined enable subcommands. */ - -struct cmd_list_element *enablelist; - -/* Chain containing all defined disable subcommands. */ - -struct cmd_list_element *disablelist; - -/* Chain containing all defined delete subcommands. */ - -struct cmd_list_element *deletelist; - -/* Chain containing all defined "enable breakpoint" subcommands. */ - -struct cmd_list_element *enablebreaklist; - -/* Chain containing all defined set subcommands */ - -struct cmd_list_element *setlist; - -/* Chain containing all defined \"set history\". */ - -struct cmd_list_element *sethistlist; - -/* Chain containing all defined \"unset history\". */ - -struct cmd_list_element *unsethistlist; - -/* stdio stream that command input is being read from. */ - -FILE *instream; - -/* Current working directory. */ - -char *current_directory; - -/* The directory name is actually stored here (usually). */ -static char dirbuf[MAXPATHLEN]; - -#ifdef KERNELDEBUG -/* Nonzero if we're debugging /dev/mem or a kernel crash dump */ - -int kernel_debugging; -#endif - -/* Nonzero to inhibit confirmation of quitting or restarting - a stopped inferior. */ -int inhibit_confirm; - -/* Nonzero if we can write in text or core file */ - -int writeable_text; - -/* The number of lines on a page, and the number of spaces - in a line. */ -int linesize, pagesize; - -/* Nonzero if we should refrain from using an X window. */ - -int inhibit_windows = 0; - -/* Function to call before reading a command, if nonzero. - The function receives two args: an input stream, - and a prompt string. */ - -void (*window_hook) (); - -extern int frame_file_full_name; -int xgdb_verbose; - -void execute_command(); -void free_command_lines (); -char *gdb_readline (); -char *command_line_input (); -static void initialize_main (); -static void initialize_cmd_lists (); -void command_loop (); -static void source_command (); -static void print_gdb_version (); -static void float_handler (); -static void cd_command (); - -char *getenv (); - -/* gdb prints this when reading a command interactively */ -static char *prompt; - -/* Buffer used for reading command lines, and the size - allocated for it so far. */ - -char *line; -int linesize; - - -/* This is how `error' returns to command level. */ - -jmp_buf to_top_level; - -void -return_to_top_level () -{ - quit_flag = 0; - immediate_quit = 0; - clear_breakpoint_commands (); - clear_momentary_breakpoints (); - disable_current_display (); - do_cleanups (0); - longjmp (to_top_level, 1); -} - -/* Call FUNC with arg ARG, catching any errors. - If there is no error, return the value returned by FUNC. - If there is an error, return zero after printing ERRSTRING - (which is in addition to the specific error message already printed). */ - -int -catch_errors (func, arg, errstring) - int (*func) (); - int arg; - char *errstring; -{ - jmp_buf saved; - int val; - struct cleanup *saved_cleanup_chain; - - saved_cleanup_chain = save_cleanups (); - - bcopy (to_top_level, saved, sizeof (jmp_buf)); - - if (setjmp (to_top_level) == 0) - val = (*func) (arg); - else - { - fprintf (stderr, "%s\n", errstring); - val = 0; - } - - restore_cleanups (saved_cleanup_chain); - - bcopy (saved, to_top_level, sizeof (jmp_buf)); - return val; -} - -/* Handler for SIGHUP. */ - -static void -disconnect () -{ - kill_inferior_fast (); - signal (SIGHUP, SIG_DFL); - kill (getpid (), SIGHUP); -} - -/* Clean up on error during a "source" command (or execution of a - user-defined command). - Close the file opened by the command - and restore the previous input stream. */ - -static void -source_cleanup (stream) - FILE *stream; -{ - /* Instream may be 0; set to it when executing user-defined command. */ - if (instream) - fclose (instream); - instream = stream; -} - -/* - * Source $HOME/.gdbinit and $cwd/.gdbinit. - * If X is enabled, also $HOME/.xgdbinit and $cwd/.xgdbinit.source - */ -void -source_init_files() -{ - char *homedir, initfile[256]; - int samedir = 0; - - /* Read init file, if it exists in home directory */ - homedir = getenv ("HOME"); - if (homedir) { - struct stat homebuf, cwdbuf; - - sprintf(initfile, "%s/.gdbinit", homedir); - if (access (initfile, R_OK) == 0) - if (!setjmp (to_top_level)) - source_command (initfile); - if (!inhibit_windows) { - sprintf(initfile, "%s/.xgdbinit", homedir); - if (access (initfile, R_OK) == 0) - if (!setjmp (to_top_level)) - source_command (initfile); - } - /* Determine if current directory is the same as the home - directory, so we don't source the same file twice. */ - - bzero (&homebuf, sizeof (struct stat)); - bzero (&cwdbuf, sizeof (struct stat)); - - stat(homedir, &homebuf); - stat(".", &cwdbuf); - - samedir = bcmp(&homebuf, &cwdbuf, sizeof(struct stat)) == 0; - } - /* Read the input file in the current directory, *if* it isn't - the same file (it should exist, also). */ - if (!samedir) { - if (access (".gdbinit", R_OK) == 0) - if (!setjmp (to_top_level)) - source_command (".gdbinit"); - if (access (".xgdbinit", R_OK) == 0) - if (!setjmp (to_top_level)) - source_command (".xgdbinit"); - } -} - - -int -main (argc, argv, envp) - int argc; - char **argv; - char **envp; -{ - int count; - int inhibit_gdbinit = 0; - int quiet = 1; - int batch = 0; - register int i; - char *cp; - - /* XXX Windows only for xgdb. */ - char *strrchr(); - if (cp = strrchr(argv[0], '/')) - ++cp; - else - cp = argv[0]; - if (*cp != 'x') - inhibit_windows = 1; - -#if defined (ALIGN_STACK_ON_STARTUP) - i = (int) &count & 0x3; - if (i != 0) - alloca (4 - i); -#endif - - quit_flag = 0; - linesize = 100; - line = (char *) xmalloc (linesize); - *line = 0; - instream = stdin; - - getwd (dirbuf); - current_directory = dirbuf; - -#ifdef SET_STACK_LIMIT_HUGE - { - struct rlimit rlim; - - /* Set the stack limit huge so that alloca (particularly stringtab - * in dbxread.c) does not fail. */ - getrlimit (RLIMIT_STACK, &rlim); - original_stack_limit = rlim.rlim_cur; - rlim.rlim_cur = rlim.rlim_max; - setrlimit (RLIMIT_STACK, &rlim); - } -#endif /* SET_STACK_LIMIT_HUGE */ - - /* Look for flag arguments. */ - - for (i = 1; i < argc; i++) - { - if (!strcmp (argv[i], "-q") || !strcmp (argv[i], "-quiet")) - quiet = 1; - else if (!strcmp (argv[i], "-nx")) - inhibit_gdbinit = 1; - else if (!strcmp (argv[i], "-nw")) - inhibit_windows = 1; - else if (!strcmp (argv[i], "-batch")) - batch = 1, quiet = 1; - else if (!strcmp (argv[i], "-fullname")) - frame_file_full_name = 1; - else if (!strcmp (argv[i], "-xgdb_verbose")) - xgdb_verbose = 1; - /* -help: print a summary of command line switches. */ - else if (!strcmp (argv[i], "-help")) - { - fputs ("\ -This is GDB, the GNU debugger. Use the command\n\ - gdb [options] [executable [core-file]]\n\ -to enter the debugger.\n\ -\n\ -Options available are:\n\ - -help Print this message.\n\ - -quiet Do not print version number on startup.\n\ - -fullname Output information used by emacs-GDB interface.\n\ - -batch Exit after processing options.\n\ - -nx Do not read .gdbinit file.\n\ - -tty TTY Use TTY for input/output by the program being debugged.\n\ - -cd DIR Change current directory to DIR.\n\ - -directory DIR Search for source files in DIR.\n\ - -command FILE Execute GDB commands from FILE.\n\ - -symbols SYMFILE Read symbols from SYMFILE.\n\ - -exec EXECFILE Use EXECFILE as the executable.\n\ - -se FILE Use FILE as symbol file and executable file.\n\ - -core COREFILE Analyze the core dump COREFILE.\n\ - -k Kernel debugging.\n\ - -w Writeable text.\n\ - -v Print GNU message and version number on startup.\n\ - -nc Don't confirm quit or run commands.\n\ -\n\ -For more information, type \"help\" from within GDB, or consult the\n\ -GDB manual (available as on-line info or a printed manual).\n", stderr); - /* Exiting after printing this message seems like - the most useful thing to do. */ - exit (0); - } -#ifdef KERNELDEBUG - else if (!strcmp (argv[i], "-k")) - kernel_debugging = 1; -#endif - else if (!strcmp (argv[i], "-w")) - writeable_text = 1; - else if (!strcmp (argv[i], "-v")) - quiet = 0; - else if (!strcmp (argv[i], "-nc")) - inhibit_confirm = 1; - else if (argv[i][0] == '-') - /* Other options take arguments, so don't confuse an - argument with an option. */ - i++; - } - - /* Run the init function of each source file */ - - initialize_cmd_lists (); /* This needs to be done first */ - initialize_all_files (); - initialize_main (); /* But that omits this file! Do it now */ - initialize_signals (); - - if (!quiet) - print_gdb_version (); - - /* Process the command line arguments. */ - - count = 0; - for (i = 1; i < argc; i++) - { - extern void exec_file_command (), symbol_file_command (); - extern void core_file_command (); - register char *arg = argv[i]; - /* Args starting with - say what to do with the following arg - as a filename. */ - if (arg[0] == '-') - { - extern void tty_command (), directory_command (); - - if (!strcmp (arg, "-q") || !strcmp (arg, "-nx") - || !strcmp (arg, "-quiet") || !strcmp (arg, "-batch") - || !strcmp (arg, "-fullname") || !strcmp (arg, "-nw") - || !strcmp (arg, "-xgdb_verbose") - || !strcmp (arg, "-help") - || !strcmp (arg, "-k") - || !strcmp (arg, "-w") - || !strcmp (arg, "-v") - || !strcmp (arg, "-nc")) - /* Already processed above */ - continue; - - if (++i == argc) - fprintf (stderr, "No argument follows \"%s\".\n", arg); - if (!setjmp (to_top_level)) - { - /* -s foo: get syms from foo. -e foo: execute foo. - -se foo: do both with foo. -c foo: use foo as core dump. */ - if (!strcmp (arg, "-se")) - { - exec_file_command (argv[i], !batch); - symbol_file_command (argv[i], !batch); - } - else if (!strcmp (arg, "-s") || !strcmp (arg, "-symbols")) - symbol_file_command (argv[i], !batch); - else if (!strcmp (arg, "-e") || !strcmp (arg, "-exec")) - exec_file_command (argv[i], !batch); - else if (!strcmp (arg, "-c") || !strcmp (arg, "-core")) - core_file_command (argv[i], !batch); - /* -x foo: execute commands from foo. */ - else if (!strcmp (arg, "-x") || !strcmp (arg, "-command") - || !strcmp (arg, "-commands")) - source_command (argv[i]); - /* -d foo: add directory `foo' to source-file directory - search-list */ - else if (!strcmp (arg, "-d") || !strcmp (arg, "-dir") - || !strcmp (arg, "-directory")) - directory_command (argv[i], 0); - /* -cd FOO: specify current directory as FOO. - GDB remembers the precise string FOO as the dirname. */ - else if (!strcmp (arg, "-cd")) - { - cd_command (argv[i], 0); - init_source_path (); - } - /* -t /def/ttyp1: use /dev/ttyp1 for inferior I/O. */ - else if (!strcmp (arg, "-t") || !strcmp (arg, "-tty")) - tty_command (argv[i], 0); - - else - error ("Unknown command-line switch: \"%s\"\n", arg); - } - } - else - { - /* Args not thus accounted for - are treated as, first, the symbol/executable file - and, second, the core dump file. */ - count++; - if (!setjmp (to_top_level)) - switch (count) - { - case 1: - exec_file_command (arg, !batch); - symbol_file_command (arg, !batch); - break; - - case 2: - core_file_command (arg, !batch); - break; - - case 3: - fprintf (stderr, "Excess command line args ignored. (%s%s)\n", - arg, (i == argc - 1) ? "" : " ..."); - } - } - } - - if (!inhibit_gdbinit) - source_init_files(); - - if (batch) - { -#if 0 - fatal ("Attempt to read commands from stdin in batch mode."); -#endif - /* We have hit the end of the batch file. */ - exit (0); - } - - if (!quiet) - printf ("Type \"help\" for a list of commands.\n"); - - /* The command loop. */ - - while (1) - { - if (!setjmp (to_top_level)) - command_loop (); - if (ISATTY(stdin)) - clearerr (stdin); /* Don't get hung if C-d is typed. */ - else if (feof(instream)) /* Avoid endless loops for redirected stdin */ - break; - } - exit (0); -} - - -static void -do_nothing () -{ -} - -/* Read commands from `instream' and execute them - until end of file. */ -void -command_loop () -{ - struct cleanup *old_chain; - register int toplevel = (instream == stdin); - register int interactive = (toplevel && ISATTY(stdin)); - - while (!feof (instream)) - { - register char *cmd_line; - - quit_flag = 0; - if (interactive) - reinitialize_more_filter (); - old_chain = make_cleanup (do_nothing, 0); - cmd_line = command_line_input (prompt, toplevel); - execute_command (cmd_line, toplevel); - /* Do any commands attached to breakpoint we stopped at. */ - do_breakpoint_commands (); - do_cleanups (old_chain); - } -} - -/* Commands call this if they do not want to be repeated by null lines. */ - -void -dont_repeat () -{ - /* If we aren't reading from standard input, we are saving the last - thing read from stdin in line and don't want to delete it. Null lines - won't repeat here in any case. */ - if (instream == stdin) - *line = 0; -} - -/* Read a line from the stream "instream" without command line editing. - - It prints PROMPT once at the start. - Action is compatible with "readline" (i.e., space for typing is - malloced & should be freed by caller). */ -char * -gdb_readline (prompt) - char *prompt; -{ - int c; - char *result; - int input_index = 0; - int result_size = 80; - - if (prompt) - { - printf (prompt); - fflush (stdout); - } - - result = (char *) xmalloc (result_size); - - while (1) - { - c = fgetc (instream ? instream : stdin); - if (c == EOF) - { - free(result); - return ((char *)0); - } - if (c == '\n') - break; - - result[input_index++] = c; - if (input_index >= result_size) - { - result_size <= 1; - result = (char *)xrealloc(result, result_size); - } - } - result[input_index++] = '\0'; - return result; -} - -/* Declaration for fancy readline with command line editing. */ -char *readline (); - -/* Variables which control command line editing and history - substitution. These variables are given default values at the end - of this file. */ -static int command_editing_p; -static int history_expansion_p; -static int write_history_p; -static int history_size; -static char *history_filename; - -/* Variables which are necessary for fancy command line editing. */ -char *gdb_completer_word_break_characters = - " \t\n!@#$%^&*()-+=|~`}{[]\"';:?/>.<,"; - -/* Functions that are used as part of the fancy command line editing. */ - -/* Generate symbol names one by one for the completer. If STATE is - zero, then we need to initialize, otherwise the initialization has - already taken place. TEXT is what we expect the symbol to start - with. RL_LINE_BUFFER is available to be looked at; it contains the - entire text of the line. RL_POINT is the offset in that line of - the cursor. You should pretend that the line ends at RL_POINT. */ -char * -symbol_completion_function (text, state) - char *text; - int state; -{ - char **make_symbol_completion_list (); - static char **list = (char **)NULL; - static int index; - char *output; - extern char *rl_line_buffer; - extern int rl_point; - char *tmp_command, *p; - struct cmd_list_element *c, *result_list; - - if (!state) - { - /* Free the storage used by LIST, but not by the strings inside. This is - because rl_complete_internal () frees the strings. */ - if (list) - free (list); - list = 0; - index = 0; - - /* Decide whether to complete on a list of gdb commands or on - symbols. */ - tmp_command = (char *) alloca (rl_point + 1); - p = tmp_command; - - strncpy (tmp_command, rl_line_buffer, rl_point); - tmp_command[rl_point] = '\0'; - - if (rl_point == 0) - { - /* An empty line we want to consider ambiguous; that is, - it could be any command. */ - c = (struct cmd_list_element *) -1; - result_list = 0; - } - else - c = lookup_cmd_1 (&p, cmdlist, &result_list, 1); - - /* Move p up to the next interesting thing. */ - while (*p == ' ' || *p == '\t') - p++; - - if (!c) - /* He's typed something unrecognizable. Sigh. */ - list = (char **) 0; - else if (c == (struct cmd_list_element *) -1) - { - if (p + strlen(text) != tmp_command + rl_point) - error ("Unrecognized command."); - - /* He's typed something ambiguous. This is easier. */ - if (result_list) - list = complete_on_cmdlist (*result_list->prefixlist, text); - else - list = complete_on_cmdlist (cmdlist, text); - } - else - { - /* If we've gotten this far, gdb has recognized a full - command. There are several possibilities: - - 1) We need to complete on the command. - 2) We need to complete on the possibilities coming after - the command. - 2) We need to complete the text of what comes after the - command. */ - - if (!*p && *text) - /* Always (might be longer versions of thie command). */ - list = complete_on_cmdlist (result_list, text); - else if (!*p && !*text) - { - if (c->prefixlist) - list = complete_on_cmdlist (*c->prefixlist, ""); - else - list = make_symbol_completion_list (""); - } - else - { - if (c->prefixlist && !c->allow_unknown) - { - *p = '\0'; - error ("\"%s\" command requires a subcommand.", - tmp_command); - } - else - list = make_symbol_completion_list (text); - } - } - } - - /* If the debugged program wasn't compiled with symbols, or if we're - clearly completing on a command and no command matches, return - NULL. */ - if (!list) - return ((char *)NULL); - - output = list[index]; - if (output) - index++; - - return (output); -} - - -void -print_prompt () -{ - if (prompt) - { - printf ("%s", prompt); - fflush (stdout); - } -} - - -#ifdef HAVE_TERMIO -#include -static struct termio norm_tty; - -static void -suspend_sig() -{ - int tty = fileno(stdin); - struct termio cur_tty; - - ioctl(tty, TCGETA, &cur_tty); - ioctl(tty, TCSETAW, &norm_tty); - - (void) sigsetmask(0); - signal(SIGTSTP, SIG_DFL); - kill(0, SIGTSTP); - - /* - * we've just been resumed -- current tty params become new - * 'normal' params (in case tset/stty was done while we were - * suspended). Merge values that readline might have changed - * into new params, then restore term mode. - */ - ioctl(tty, TCGETA, &norm_tty); - cur_tty.c_lflag = (cur_tty.c_lflag & (ICANON|ECHO|ISIG)) | - (norm_tty.c_lflag &~ (ICANON|ECHO|ISIG)); - cur_tty.c_iflag = (cur_tty.c_iflag & (IXON|ISTRIP|INPCK)) | - (norm_tty.c_iflag &~ (IXON|ISTRIP|INPCK)); - ioctl(tty, TCSETAW, &cur_tty); - - signal(SIGTSTP, suspend_sig); - print_prompt(); - - /* - * Forget about any previous command -- null line now will do - * nothing. - */ - dont_repeat(); -} - -#else - -#include -#include -#include - -static struct sgttyb norm_tty; -static struct tchars norm_tchars; -static struct ltchars norm_ltchars; -static int norm_lflags; - -#ifdef PASS8 -#define RL_TFLAGS (RAW|CRMOD|ECHO|CBREAK|PASS8) -#else -#define RL_TFLAGS (RAW|CRMOD|ECHO|CBREAK) -#endif - -static void -suspend_sig() -{ - int tty = fileno(stdin); - struct sgttyb cur_tty; - struct tchars cur_tchars; - struct ltchars cur_ltchars; - int cur_lflags; - int cur_flags; - - ioctl(tty, TIOCGETP, &cur_tty); - ioctl(tty, TIOCGETC, &cur_tchars); - ioctl(tty, TIOCLGET, &cur_lflags); - ioctl(tty, TIOCGLTC, &cur_ltchars); - - ioctl(tty, TIOCSETP, &norm_tty); - ioctl(tty, TIOCSETC, &norm_tchars); - ioctl(tty, TIOCLSET, &norm_lflags); - ioctl(tty, TIOCSLTC, &norm_ltchars); - - (void) sigsetmask(0); - signal(SIGTSTP, SIG_DFL); - kill(0, SIGTSTP); - - /* - * we've just been resumed -- current tty params become new - * 'normal' params (in case tset/stty was done while we were - * suspended). Merge values that readline might have changed - * into new params, then restore term mode. - */ - ioctl(tty, TIOCGETP, &norm_tty); - cur_flags = cur_tty.sg_flags; - cur_tty = norm_tty; - cur_tty.sg_flags = (cur_tty.sg_flags &~ RL_TFLAGS) - | (cur_flags & RL_TFLAGS); - - ioctl(tty, TIOCLGET, &norm_lflags); -#ifdef LPASS8 - cur_lflags = (cur_lflags &~ LPASS8) | (cur_flags & LPASS8); -#endif - ioctl(tty, TIOCGETC, &norm_tchars); - ioctl(tty, TIOCGLTC, &norm_ltchars); - - ioctl(tty, TIOCSETP, &cur_tty); - ioctl(tty, TIOCSETC, &cur_tchars); - ioctl(tty, TIOCLSET, &cur_lflags); - ioctl(tty, TIOCSLTC, &cur_ltchars); - - signal(SIGTSTP, suspend_sig); - print_prompt(); - - /* - * Forget about any previous command -- null line now will do - * nothing. - */ - dont_repeat(); -} -#endif /* HAVE_TERMIO */ - -/* Initialize signal handlers. */ -initialize_signals () -{ - extern void request_quit (); - int tty = fileno(stdin); - - signal (SIGINT, request_quit); - - /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get - passed to the inferior, which we don't want. It would be - possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but - on BSD4.3 systems using vfork, that will (apparently) affect the - GDB process as well as the inferior (the signal handling tables - being shared between the two, apparently). Since we establish - a handler for SIGQUIT, when we call exec it will set the signal - to SIG_DFL for us. */ - signal (SIGQUIT, do_nothing); - if (signal (SIGHUP, do_nothing) != SIG_IGN) - signal (SIGHUP, disconnect); - signal (SIGFPE, float_handler); - - ioctl(tty, TIOCGETP, &norm_tty); - ioctl(tty, TIOCLGET, &norm_lflags); - ioctl(tty, TIOCGETC, &norm_tchars); - ioctl(tty, TIOCGLTC, &norm_ltchars); - signal(SIGTSTP, suspend_sig); -} - -char * -finish_command_input(inputline, repeat, interactive) - register char *inputline; - int repeat; - int interactive; -{ - static char *do_free; - - if (do_free) { - free(do_free); - do_free = NULL; - } - - /* Do history expansion if that is wished. */ - if (interactive && history_expansion_p) { - int expanded; - - expanded = history_expand(inputline, &do_free); - if (expanded) { - /* Print the changes. */ - puts(do_free); - - /* An error acts like no input. */ - if (expanded < 0) { - *do_free = 0; - return (do_free); - } - } - inputline = do_free; - } - /* get rid of any leading whitespace */ - while (isspace(*inputline)) - ++inputline; - /* - * If we just got an empty line, and that is supposed to repeat the - * previous command, return the value in the global buffer. - */ - if (*inputline == 0) { - if (repeat) - return (line); - } else if (interactive) - add_history(inputline); - - /* - * If line is a comment, clear it out. - * Note: comments are added to the command history. This is useful - * when you type a command, and then realize you don't want to - * execute it quite yet. You can comment out the command and then - * later fetch it from the value history and remove the '#'. - */ - if (*inputline == '#') - *inputline = 0; - else if (repeat) { - /* Save into global buffer. */ - register int i = strlen(inputline) + 1; - - if (i > linesize) { - line = xrealloc(line, i); - linesize = i; - } - strcpy(line, inputline); - } - return (inputline); -} - -static char * -get_a_cmd_line(prompt, interactive) - char *prompt; - int interactive; -{ - register char *cp; - - /* Control-C quits instantly if typed while reading input. */ - immediate_quit++; - if (interactive && command_editing_p) { - extern void (*rl_event_hook)(); - - rl_event_hook = window_hook; - cp = readline(prompt); - } else { - if (interactive) { - if (window_hook) { - print_prompt(); - (*window_hook)(); - } - } else - prompt = NULL; - cp = gdb_readline(prompt); - } - --immediate_quit; - return (cp); -} - -/* Read one line from the command input stream `instream' - Returns the address of the start of the line. - - *If* the instream == stdin & stdin is a terminal, the line read - is copied into the file line saver (global var char *line, - length linesize) so that it can be duplicated. - - This routine either uses fancy command line editing or - simple input as the user has requested. */ - -char * -command_line_input(prompt, repeat) - char *prompt; - int repeat; -{ - static char *do_free; - register int interactive = (instream == stdin && ISATTY(instream)); - register char *cp; - register int i; - - if (do_free) { - free(do_free); - do_free = NULL; - } - cp = get_a_cmd_line(prompt, interactive); - - /* - * handle continued lines (this loop is not particularly - * efficient because it's rare). - */ - while (cp && cp[i = strlen(cp) - 1] == '\\') { - register char *np = get_a_cmd_line(prompt, interactive); - register int j; - - if (np == NULL) { - cp[i] = 0; - break; - } - j = strlen(np); - cp = xrealloc(cp, i + j + 1); - strcpy(cp + i, np); - free(np); - } - if (cp == NULL) - return (""); - do_free = cp; - return (finish_command_input(cp, repeat, interactive)); -} - - -#define MAX_USER_ARGS 32 - -static struct user_args { - struct { - char *arg; - int len; - } a[10]; -} uargs[MAX_USER_ARGS]; - -static struct user_args *user_arg = uargs; - -static void -arg_cleanup(ap) - struct user_args *ap; -{ - user_arg = ap; -} - -/* Bind arguments $arg0, $arg1, ..., for a user defined command. */ -struct cleanup * -setup_user_args(p) - char *p; -{ - register int i; - struct cleanup *old_chain = make_cleanup(arg_cleanup, user_arg); - - if (++user_arg >= &uargs[MAX_USER_ARGS]) - error("user defined functions nested too deeply\n"); - - bzero(user_arg, sizeof(*user_arg)); - - i = 0; - while (*p) { - while (isspace(*p)) - ++p; - user_arg->a[i].arg = p; - while (*p && ! isspace(*p)) - ++p; - user_arg->a[i].len = p - user_arg->a[i].arg; - ++i; - } - return (old_chain); -} - -static char * -findarg(str) - register char *str; -{ - register char *cp = str; - extern char *index(); - - while (cp = index(cp, '$')) { - if (strncmp(cp, "$arg", 4) == 0 && isdigit(cp[4])) - return (cp); - ++cp; - } - return (char *)0; -} - -/* expand arguments from "line" into "new" */ -static void -expand_args(line, new) - register char *line, *new; -{ - register char *cp = findarg(line); - - while (cp = findarg(line)) { - int i, len; - - bcopy(line, new, cp - line); - new += cp - line; - i = cp[4] - '0'; - if (len = user_arg->a[i].len) { - bcopy(user_arg->a[i].arg, new, len); - new += len; - } - line = cp + 5; - } - strcpy(new, line); -} - -/* expand any arguments in "line" then execute the result */ -static void -expand_and_execute(line, from_tty) - char *line; - int from_tty; -{ - void execute_command(); - char new[1024]; - - if (! findarg(line)) { - execute_command(line, from_tty); - return; - } - expand_args(line, new); - execute_command(new, from_tty); -} - -char * -read_one_command_line(prompt, from_tty) - char *prompt; -{ - register char *p, *p1; - - dont_repeat(); - p = command_line_input(prompt, from_tty); - - /* Remove trailing blanks. */ - p1 = p + strlen(p); - while (--p1 > p && (*p1 == ' ' || *p1 == '\t')) - ; - *++p1 = 0; - return (p); -} - -static char cmd_prompt[] = " > "; - -int -parse_control_structure(rootcmd, from_tty, level) - struct command_line *rootcmd; - int from_tty; -{ - struct command_line *cmd = (struct command_line *)xmalloc(sizeof(*cmd)); - char *prompt; - - ++level; - prompt = from_tty? &cmd_prompt[sizeof(cmd_prompt) - 1 - 2*level] : - (char *)0; - bzero(cmd, sizeof(*cmd)); - rootcmd->body = cmd; - while (1) { - char *p = read_one_command_line(prompt, from_tty); - - p = savestring(p, strlen(p)); - cmd->line = p; - if (!strncmp(p, "while ", 6)) { - cmd->type = CL_WHILE; - if (parse_control_structure(cmd, from_tty, level)) - return (1); - } else if (!strncmp(p, "if ", 3)) { - cmd->type = CL_IF; - if (parse_control_structure(cmd, from_tty, level)) { - struct command_line *tmp; - int stat; - - cmd->elsebody = cmd->body; - stat = parse_control_structure(cmd, from_tty, - level); - tmp = cmd->elsebody; - cmd->elsebody = cmd->body; - cmd->body = tmp; - if (stat) - return (1); - } - } else if (!strcmp(p, "else")) { - cmd->type = CL_END; - return (1); - } else if (!strcmp(p, "end")) { - cmd->type = CL_END; - return (0); - } else if (!strcmp(p, "exitloop")) { - cmd->type = CL_EXITLOOP; - } else { - cmd->type = CL_NORMAL; - } - cmd->next = (struct command_line *)xmalloc(sizeof(*cmd)); - cmd = cmd->next; - bzero(cmd, sizeof(*cmd)); - } - /* NOTREACHED */ -} - -int -execute_control_structure(cmd) - register struct command_line *cmd; -{ - char expn[1024]; - struct expression *cond; - int stat; - - while (cmd) { - QUIT; - switch (cmd->type) { - case CL_END: - return (0); - case CL_NORMAL: - expand_and_execute(cmd->line, 0); - break; - case CL_WHILE: - expand_args(cmd->line + 6, expn); - cond = parse_c_expression(expn); - while (breakpoint_cond_eval(cond) == 0) - if (execute_control_structure(cmd->body)) - break; - free(cond); - break; - case CL_IF: - expand_args(cmd->line + 3, expn); - cond = parse_c_expression(expn); - stat = breakpoint_cond_eval(cond); - free(cond); - if (stat == 0) { - if (execute_control_structure(cmd->body)) - return (1); - } else if (cmd->elsebody) { - if (execute_control_structure(cmd->elsebody)) - return (1); - } - break; - case CL_EXITLOOP: - return (1); - } - cmd = cmd->next; - } - free_all_values(); -} - -execute_command_lines(cmd) - struct command_line *cmd; -{ - struct cleanup *old_chain = make_cleanup(source_cleanup, instream); - - /* - * Set the instream to 0, indicating execution of a user-defined - * function. - */ - ++immediate_quit; - instream = (FILE *) 0; - (void)execute_control_structure(cmd); - --immediate_quit; - do_cleanups(old_chain); -} - -/* do following command lines if expression true */ -if_command(p, from_tty) - char *p; - int from_tty; -{ - struct cleanup *old_chain; - struct command_line *cmd = (struct command_line *)xmalloc(sizeof(*cmd)); - char buf[128]; - - sprintf(buf, "if %s", p); - - bzero(cmd, sizeof(*cmd)); - old_chain = make_cleanup(free_command_lines, cmd); - cmd->type = CL_IF; - cmd->line = savestring(buf, strlen(buf)); - /* XXX cmd->line? */ - if (parse_control_structure(cmd, from_tty, 0)) { - struct command_line *tmp; - - cmd->elsebody = cmd->body; - (void) parse_control_structure(cmd, from_tty, 0); - tmp = cmd->elsebody; - cmd->elsebody = cmd->body; - cmd->body = tmp; - } - (void) execute_command_lines(cmd); - do_cleanups(old_chain); -} - -/* do following command lines while expression true */ -while_command(p, from_tty) - char *p; - int from_tty; -{ - struct cleanup *old_chain; - struct command_line *cmd = (struct command_line *)xmalloc(sizeof(*cmd)); - char buf[128]; - - sprintf(buf, "while %s", p); - - bzero(cmd, sizeof(*cmd)); - old_chain = make_cleanup(free_command_lines, cmd); - cmd->type = CL_WHILE; - cmd->line = savestring(buf, strlen(buf)); - (void)parse_control_structure(cmd, from_tty, 0); - (void)execute_command_lines(cmd); - do_cleanups(old_chain); -} - -/* - * Execute the line P as a command. - * Pass FROM_TTY as second argument to the defining function. - */ -void -execute_command (p, from_tty) - char *p; - int from_tty; -{ - register struct cmd_list_element *c; - register struct command_line *cmdlines; - - free_all_values(); - if (*p) { - c = lookup_cmd(&p, cmdlist, "", 0, 1); - if (c->function == 0) - error("That is not a command, just a help topic."); - else if (c->class == (int) class_user) { - struct cleanup *old_chain = setup_user_args(p); - - cmdlines = (struct command_line *) c->function; - if (cmdlines) - (void)execute_command_lines(cmdlines); - - do_cleanups(old_chain); - } else - /* Pass null arg rather than an empty one. */ - (*c->function) (*p ? p : 0, from_tty); - } -} - -/* - * Read lines from the input stream and accumulate them in a chain of struct - * command_line's which is then returned. - */ -struct command_line * -read_command_lines(from_tty) - int from_tty; -{ - struct cleanup *old_chain; - struct command_line *cmd = (struct command_line *)xmalloc(sizeof(*cmd)); - struct command_line *next; - - bzero(cmd, sizeof(*cmd)); - old_chain = make_cleanup(free_command_lines, cmd); - cmd->type = CL_NOP; - (void)parse_control_structure(cmd, from_tty, 0); - dont_repeat(); - discard_cleanups(old_chain); - next = cmd->body; - free(cmd); - return (next); -} - -/* Free a chain of struct command_line's. */ - -void -free_command_lines(cmds) - struct command_line *cmds; -{ - struct command_line *next; - - while (cmds) { - if (cmds->body) - free(cmds->body); - if (cmds->elsebody) - free(cmds->elsebody); - if (cmds->line) - free(cmds->line); - next = cmds->next; - free(cmds); - cmds = next; - } -} - -/* Add an element to the list of info subcommands. */ - -void -add_info (name, fun, doc) - char *name; - void (*fun) (); - char *doc; -{ - add_cmd (name, no_class, fun, doc, &infolist); -} - -/* Add an alias to the list of info subcommands. */ - -void -add_info_alias (name, oldname, abbrev_flag) - char *name; - char *oldname; - int abbrev_flag; -{ - add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist); -} - -/* The "info" command is defined as a prefix, with allow_unknown = 0. - Therefore, its own definition is called only for "info" with no args. */ - -static void -info_command () -{ - printf ("\"info\" must be followed by the name of an info command.\n"); - help_list (infolist, "info ", -1, stdout); -} - -/* Add an element to the list of commands. */ - -void -add_com (name, class, fun, doc) - char *name; - int class; - void (*fun) (); - char *doc; -{ - add_cmd (name, class, fun, doc, &cmdlist); -} - -/* Add an alias or abbreviation command to the list of commands. */ - -void -add_com_alias (name, oldname, class, abbrev_flag) - char *name; - char *oldname; - int class; - int abbrev_flag; -{ - add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist); -} - -void -error_no_arg (why) - char *why; -{ - error ("Argument required (%s).", why); -} - -static void -help_command (command, from_tty) - char *command; - int from_tty; /* Ignored */ -{ - help_cmd (command, stdout); -} - -static void -validate_comname (comname) - char *comname; -{ - register char *p; - - if (comname == 0) - error_no_arg ("name of command to define"); - - p = comname; - while (*p) - { - if (!(*p >= 'A' && *p <= 'Z') - && !(*p >= 'a' && *p <= 'z') - && !(*p >= '0' && *p <= '9') - && *p != '-') - error ("Junk in argument list: \"%s\"", p); - p++; - } -} - -static void -define_command (comname, from_tty) - char *comname; - int from_tty; -{ - register struct command_line *cmds; - register struct cmd_list_element *c; - char *tem = comname; - - validate_comname (comname); - - c = lookup_cmd (&tem, cmdlist, "", -1, 1); - if (c) - { - if (c->class == (int) class_user || c->class == (int) class_alias) - tem = "Redefine command \"%s\"? "; - else - tem = "Really redefine built-in command \"%s\"? "; - if (!query (tem, comname)) - error ("Command \"%s\" not redefined.", comname); - } - - if (from_tty) - { - printf ("Type commands for definition of \"%s\".\n\ -End with a line saying just \"end\".\n", comname); - fflush (stdout); - } - comname = savestring (comname, strlen (comname)); - - cmds = read_command_lines (from_tty); - - if (c && c->class == (int) class_user) - free_command_lines (c->function); - - add_com (comname, class_user, cmds, - (c && c->class == (int) class_user) - ? c->doc : savestring ("User-defined.", 13)); -} - -static void -document_command (comname, from_tty) - char *comname; - int from_tty; -{ - register struct cmd_list_element *c; - register char *p; - register char *cp; - register char *doc = 0; - register int len; - char *tmp = comname; - - validate_comname (comname); - c = lookup_cmd (&tmp, cmdlist, "", 0, 1); - if (c->class != (int) class_user) - error ("Command \"%s\" is built-in.", comname); - - if (from_tty) - printf ("Type documentation for \"%s\". \ -End with a line saying just \"end\".\n", comname); - - while (p = read_one_command_line(from_tty? "> " : 0, from_tty)) - { - if (strcmp(p, "end") == 0) - break; - len = strlen(p) + 1; - if (! doc) - { - doc = xmalloc(len); - cp = doc; - } - else - { - int i = cp - doc; - doc = xrealloc(doc, i + len); - cp = doc + i; - } - strcpy(cp, p); - cp += len; - cp[-1] = '\n'; - } - if (doc && cp > doc) - cp[-1] = 0; - if (c->doc) - free (c->doc); - c->doc = doc; -} - -static void -print_gdb_version () -{ - printf ("GDB %s, Copyright (C) 1989 Free Software Foundation, Inc.\n\ -There is ABSOLUTELY NO WARRANTY for GDB; type \"info warranty\" for details.\n\ -GDB is free software and you are welcome to distribute copies of it\n\ - under certain conditions; type \"info copying\" to see the conditions.\n", - version); -} - -static void -version_info () -{ - immediate_quit++; - print_gdb_version (); - immediate_quit--; -} - - -/* Command to specify a prompt string instead of "(gdb) ". */ - -void -set_prompt_command (text) - char *text; -{ - char *p, *q; - register int c; - char *new; - - if (text == 0) - error_no_arg ("string to which to set prompt"); - - new = (char *) xmalloc (strlen (text) + 2); - p = text; q = new; - while (c = *p++) - { - if (c == '\\') - { - /* \ at end of argument is used after spaces - so they won't be lost. */ - if (*p == 0) - break; - c = parse_escape (&p); - if (c == 0) - break; /* C loses */ - else if (c > 0) - *q++ = c; - } - else - *q++ = c; - } - if (*(p - 1) != '\\') - *q++ = ' '; - *q++ = '\0'; - new = (char *) xrealloc (new, q - new); - free (prompt); - prompt = new; -} - -static void -quit_command () -{ - extern void exec_file_command (); - if (have_inferior_p ()) - { - if (inhibit_confirm || query ("The program is running. Quit anyway? ")) - { - /* Prevent any warning message from reopen_exec_file, in case - we have a core file that's inconsistent with the exec file. */ - exec_file_command (0, 0); - kill_inferior (); - } - else - error ("Not confirmed."); - } - /* Save the history information if it is appropriate to do so. */ - if (write_history_p && history_filename) - write_history (history_filename); - exit (0); -} - -int -input_from_terminal_p () -{ - return instream == stdin; -} - -static void -pwd_command (arg, from_tty) - char *arg; - int from_tty; -{ - if (arg) error ("The \"pwd\" command does not take an argument: %s", arg); - getwd (dirbuf); - - if (strcmp (dirbuf, current_directory)) - printf ("Working directory %s\n (canonically %s).\n", - current_directory, dirbuf); - else - printf ("Working directory %s.\n", current_directory); -} - -static void -cd_command (dir, from_tty) - char *dir; - int from_tty; -{ - int len; - int change; - - if (dir == 0) - error_no_arg ("new working directory"); - - dir = tilde_expand (dir); - make_cleanup (free, dir); - - len = strlen (dir); - dir = savestring (dir, len - (len > 1 && dir[len-1] == '/')); - if (dir[0] == '/') - current_directory = dir; - else - { - current_directory = concat (current_directory, "/", dir); - free (dir); - } - - /* Now simplify any occurrences of `.' and `..' in the pathname. */ - - change = 1; - while (change) - { - char *p; - change = 0; - - for (p = current_directory; *p;) - { - if (!strncmp (p, "/./", 2) - && (p[2] == 0 || p[2] == '/')) - strcpy (p, p + 2); - else if (!strncmp (p, "/..", 3) - && (p[3] == 0 || p[3] == '/') - && p != current_directory) - { - char *q = p; - while (q != current_directory && q[-1] != '/') q--; - if (q != current_directory) - { - strcpy (q-1, p+3); - p = q-1; - } - } - else p++; - } - } - - if (chdir (dir) < 0) - perror_with_name (dir); - - if (from_tty) - pwd_command ((char *) 0, 1); -} - -static void -source_command (arg, from_tty) - char *arg; - int from_tty; -{ - FILE *stream; - struct cleanup *cleanups; - char *file = arg; - char *path; - - if (file == 0) - /* Let source without arguments read .gdbinit. */ - file = ".gdbinit"; - - file = tilde_expand (file); - make_cleanup (free, file); - -#ifdef KERNELDEBUG - if (path = getenv(kernel_debugging? "KGDBPATH" : "GDBPATH")) -#else - if (path = getenv("GDBPATH")) -#endif - { - int fd = openp(path, 1, file, O_RDONLY, 0, 0); - - if (fd == -1) - stream = 0; - else - stream = fdopen(fd, "r"); - } - else - stream = fopen (file, "r"); - - if (stream == 0) - perror_with_name (file); - - cleanups = make_cleanup (source_cleanup, instream); - - instream = stream; - - command_loop (); - - do_cleanups (cleanups); -} - -static void -echo_command (text) - char *text; -{ - char *p = text; - register int c; - - if (text) - while (c = *p++) - { - if (c == '\\') - { - /* \ at end of argument is used after spaces - so they won't be lost. */ - if (*p == 0) - return; - - c = parse_escape (&p); - if (c >= 0) - fputc (c, stdout); - } - else - fputc (c, stdout); - } - fflush(stdout); -} - -static void -dump_me_command () -{ - if (query ("Should GDB dump core? ")) - { - signal (SIGQUIT, SIG_DFL); - kill (getpid (), SIGQUIT); - } -} - -int -parse_binary_operation (caller, arg) - char *caller, *arg; -{ - int length; - - if (!arg || !*arg) - return 1; - - length = strlen (arg); - - while (arg[length - 1] == ' ' || arg[length - 1] == '\t') - length--; - - if (!strncmp (arg, "on", length) - || !strncmp (arg, "1", length) - || !strncmp (arg, "yes", length)) - return 1; - else - if (!strncmp (arg, "off", length) - || !strncmp (arg, "0", length) - || !strncmp (arg, "no", length)) - return 0; - else - error ("\"%s\" not given a binary valued argument.", caller); -} - -/* Functions to manipulate command line editing control variables. */ - -static void -set_editing (arg, from_tty) - char *arg; - int from_tty; -{ - command_editing_p = parse_binary_operation ("set command-editing", arg); -} - -/* Number of commands to print in each call to editing_info. */ -#define Hist_print 10 -static void -editing_info (arg, from_tty) - char *arg; - int from_tty; -{ - /* Index for history commands. Relative to history_base. */ - int offset; - - /* Number of the history entry which we are planning to display next. - Relative to history_base. */ - static int num = 0; - - /* The first command in the history which doesn't exist (i.e. one more - than the number of the last command). Relative to history_base. */ - int hist_len; - - struct _hist_entry { - char *line; - char *data; - } *history_get(); - extern int history_base; - - printf_filtered ("Interactive command editing is %s.\n", - command_editing_p ? "on" : "off"); - - printf_filtered ("History expansion of command input is %s.\n", - history_expansion_p ? "on" : "off"); - printf_filtered ("Writing of a history record upon exit is %s.\n", - write_history_p ? "enabled" : "disabled"); - printf_filtered ("The size of the history list (number of stored commands) is %d.\n", - history_size); - printf_filtered ("The name of the history record is \"%s\".\n\n", - history_filename ? history_filename : ""); - - /* Print out some of the commands from the command history. */ - /* First determine the length of the history list. */ - hist_len = history_size; - for (offset = 0; offset < history_size; offset++) - { - if (!history_get (history_base + offset)) - { - hist_len = offset; - break; - } - } - - if (arg) - { - if (arg[0] == '+' && arg[1] == '\0') - /* "info editing +" should print from the stored position. */ - ; - else - /* "info editing " should print around command number . */ - num = (parse_and_eval_address (arg) - history_base) - Hist_print / 2; - } - /* "info editing" means print the last Hist_print commands. */ - else - { - num = hist_len - Hist_print; - } - - if (num < 0) - num = 0; - - /* If there are at least Hist_print commands, we want to display the last - Hist_print rather than, say, the last 6. */ - if (hist_len - num < Hist_print) - { - num = hist_len - Hist_print; - if (num < 0) - num = 0; - } - - if (num == hist_len - Hist_print) - printf_filtered ("The list of the last %d commands is:\n\n", Hist_print); - else - printf_filtered ("Some of the stored commands are:\n\n"); - - for (offset = num; offset < num + Hist_print && offset < hist_len; offset++) - { - printf_filtered ("%5d %s\n", history_base + offset, - (history_get (history_base + offset))->line); - } - - /* The next command we want to display is the next one that we haven't - displayed yet. */ - num += Hist_print; - - /* If the user repeats this command with return, it should do what - "info editing +" does. This is unnecessary if arg is null, - because "info editing +" is not useful after "info editing". */ - if (from_tty && arg) - { - arg[0] = '+'; - arg[1] = '\0'; - } -} - -static void -set_history_expansion (arg, from_tty) - char *arg; - int from_tty; -{ - history_expansion_p = parse_binary_operation ("set history expansion", arg); -} - -static void -set_history_write (arg, from_tty) - char *arg; - int from_tty; -{ - write_history_p = parse_binary_operation ("set history write", arg); -} - -static void -set_history (arg, from_tty) - char *arg; - int from_tty; -{ - printf ("\"set history\" must be followed by the name of a history subcommand.\n"); - help_list (sethistlist, "set history ", -1, stdout); -} - -static void -set_history_size (arg, from_tty) - char *arg; - int from_tty; -{ - if (!*arg) - error_no_arg ("set history size"); - - history_size = atoi (arg); -} - -static void -set_history_filename (arg, from_tty) - char *arg; - int from_tty; -{ - int i; - - if (!arg) - error_no_arg ("history file name"); - - arg = tilde_expand (arg); - make_cleanup (free, arg); - - i = strlen (arg) - 1; - - free (history_filename); - - while (i > 0 && (arg[i] == ' ' || arg[i] == '\t')) - i--; - ++i; - - if (!*arg) - history_filename = (char *) 0; - else - history_filename = savestring (arg, i + 1); - history_filename[i] = '\0'; -} - -int info_verbose; - -static void -set_verbose_command (arg, from_tty) - char *arg; - int from_tty; -{ - info_verbose = parse_binary_operation ("set verbose", arg); -} - -static void -verbose_info (arg, from_tty) - char *arg; - int from_tty; -{ - if (arg) - error ("\"info verbose\" does not take any arguments.\n"); - - printf ("Verbose printing of information is %s.\n", - info_verbose ? "on" : "off"); -} - -static void -float_handler () -{ - error ("Invalid floating value encountered or computed."); -} - - -static void -initialize_cmd_lists () -{ - cmdlist = (struct cmd_list_element *) 0; - infolist = (struct cmd_list_element *) 0; - enablelist = (struct cmd_list_element *) 0; - disablelist = (struct cmd_list_element *) 0; - deletelist = (struct cmd_list_element *) 0; - enablebreaklist = (struct cmd_list_element *) 0; - setlist = (struct cmd_list_element *) 0; - sethistlist = (struct cmd_list_element *) 0; - unsethistlist = (struct cmd_list_element *) 0; -} - -static void -initialize_main () -{ - char *tmpenv; - /* Command line editing externals. */ - extern int (*rl_completion_entry_function)(); - extern char *rl_completer_word_break_characters; - extern char *rl_readline_name; - - /* Set default verbose mode on. */ - info_verbose = 1; - -#ifdef KERNELDEBUG - if (kernel_debugging) - prompt = savestring ("(kgdb) ", 7); - else -#endif - prompt = savestring ("(gdb) ", 6); - - /* Set the important stuff up for command editing. */ - command_editing_p = 1; - history_expansion_p = 0; - write_history_p = 0; - - if (tmpenv = getenv ("HISTSIZE")) - history_size = atoi (tmpenv); - else - history_size = 256; - - stifle_history (history_size); - - if (tmpenv = getenv ("GDBHISTFILE")) - history_filename = savestring (tmpenv, strlen(tmpenv)); - else - /* We include the current directory so that if the user changes - directories the file written will be the same as the one - that was read. */ - history_filename = concat (current_directory, "/.gdb_history", ""); - - read_history (history_filename); - - /* Setup important stuff for command line editing. */ - rl_completion_entry_function = (int (*)()) symbol_completion_function; - rl_completer_word_break_characters = gdb_completer_word_break_characters; - rl_readline_name = "gdb"; - - /* Define the classes of commands. - They will appear in the help list in the reverse of this order. */ - - add_cmd ("obscure", class_obscure, 0, "Obscure features.", &cmdlist); - add_cmd ("alias", class_alias, 0, "Aliases of other commands.", &cmdlist); - add_cmd ("user", class_user, 0, "User-defined commands.\n\ -The commands in this class are those defined by the user.\n\ -Use the \"define\" command to define a command.", &cmdlist); - add_cmd ("support", class_support, 0, "Support facilities.", &cmdlist); - add_cmd ("status", class_info, 0, "Status inquiries.", &cmdlist); - add_cmd ("files", class_files, 0, "Specifying and examining files.", &cmdlist); - add_cmd ("breakpoints", class_breakpoint, 0, "Making program stop at certain points.", &cmdlist); - add_cmd ("data", class_vars, 0, "Examining data.", &cmdlist); - add_cmd ("stack", class_stack, 0, "Examining the stack.\n\ -The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\ -counting from zero for the innermost (currently executing) frame.\n\n\ -At any time gdb identifies one frame as the \"selected\" frame.\n\ -Variable lookups are done with respect to the selected frame.\n\ -When the program being debugged stops, gdb selects the innermost frame.\n\ -The commands below can be used to select other frames by number or address.", - &cmdlist); - add_cmd ("running", class_run, 0, "Running the program.", &cmdlist); - - add_com ("pwd", class_files, pwd_command, - "Print working directory. This is used for your program as well."); - add_com ("cd", class_files, cd_command, - "Set working directory to DIR for debugger and program being debugged.\n\ -The change does not take effect for the program being debugged\n\ -until the next time it is started."); - - add_cmd ("prompt", class_support, set_prompt_command, - "Change gdb's prompt from the default of \"(gdb)\"", - &setlist); - add_com ("echo", class_support, echo_command, - "Print a constant string. Give string as argument.\n\ -C escape sequences may be used in the argument.\n\ -No newline is added at the end of the argument;\n\ -use \"\\n\" if you want a newline to be printed.\n\ -Since leading and trailing whitespace are ignored in command arguments,\n\ -if you want to print some you must use \"\\\" before leading whitespace\n\ -to be printed or after trailing whitespace."); - add_com ("document", class_support, document_command, - "Document a user-defined command.\n\ -Give command name as argument. Give documentation on following lines.\n\ -End with a line of just \"end\"."); - add_com ("define", class_support, define_command, - "Define a new command name. Command name is argument.\n\ -Definition appears on following lines, one command per line.\n\ -End with a line of just \"end\".\n\ -Use the \"document\" command to give documentation for the new command.\n\ -Commands defined in this way do not take arguments."); - - add_com ("source", class_support, source_command, - "Read commands from a file named FILE.\n\ -Note that the file \".gdbinit\" is read automatically in this way\n\ -when gdb is started."); - add_com ("quit", class_support, quit_command, "Exit gdb."); - add_com ("help", class_support, help_command, "Print list of commands."); - add_com_alias ("q", "quit", class_support, 1); - add_com_alias ("h", "help", class_support, 1); - add_com ("while", class_support, while_command, - "execute following commands while condition is true.\n\ -Expression for condition follows \"while\" keyword."); - add_com ("if", class_support, if_command, - "execute following commands if condition is true.\n\ -Expression for condition follows \"if\" keyword."); - add_cmd ("verbose", class_support, set_verbose_command, - "Change the number of informational messages gdb prints.", - &setlist); - add_info ("verbose", verbose_info, - "Status of gdb's verbose printing option.\n"); - - add_com ("dump-me", class_obscure, dump_me_command, - "Get fatal error; make debugger dump its core."); - - add_cmd ("editing", class_support, set_editing, - "Enable or disable command line editing.\n\ -Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\ -Without an argument, command line editing is enabled.", &setlist); - - add_prefix_cmd ("history", class_support, set_history, - "Generic command for setting command history parameters.", - &sethistlist, "set history ", 0, &setlist); - - add_cmd ("expansion", no_class, set_history_expansion, - "Enable or disable history expansion on command input.\n\ -Without an argument, history expansion is enabled.", &sethistlist); - - add_cmd ("write", no_class, set_history_write, - "Enable or disable saving of the history record on exit.\n\ -Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\ -Without an argument, saving is enabled.", &sethistlist); - - add_cmd ("size", no_class, set_history_size, - "Set the size of the command history, \n\ -ie. the number of previous commands to keep a record of.", &sethistlist); - - add_cmd ("filename", no_class, set_history_filename, - "Set the filename in which to record the command history\n\ - (the list of previous commands of which a record is kept).", &sethistlist); - - add_prefix_cmd ("info", class_info, info_command, - "Generic command for printing status.", - &infolist, "info ", 0, &cmdlist); - add_com_alias ("i", "info", class_info, 1); - - add_info ("editing", editing_info, "Status of command editor."); - - add_info ("version", version_info, "Report what version of GDB this is."); -} diff --git a/gnu/usr.bin/gdb/ngdb.i386/Makefile b/gnu/usr.bin/gdb/ngdb.i386/Makefile deleted file mode 100644 index 3bf4c6c..0000000 --- a/gnu/usr.bin/gdb/ngdb.i386/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# %W% (Berkeley) %G% - -.include "../config/Makefile.$(MACHINE)" - -PROG= ngdb -SRCS= i386bsd-dep.c blockframe.c -GDBOBJS+= i386-pinsn.o \ - breakpoint.o command.o copying.o core.o \ - cplus-dem.o dbxread.o environ.o eval.o expprint.o \ - expread.o findvar.o infcmd.o inflow.o infrun.o \ - main.o obstack.o printcmd.o regex.o remote.o \ - remote-sl.o source.o stack.o symmisc.o symtab.o \ - utils.o valarith.o valops.o valprint.o values.o \ - version.o \ - funmap.o history.o keymaps.o readline.o \ - init.o -CFLAGS+= -g -I$(.CURDIR) -I.. -I$(.CURDIR)/.. -I$(.CURDIR)/../config \ - -I/usr/src/sys.newvm \ - -DNEWVM -DHAVE_VPRINTF -DVI_MODE -DKERNELDEBUG -# CC= /usr/old/bin/cc -# CC= cc -traditional -LDADD+= $(GDBOBJS:S/^/..\//g) -ltermcap -NOMAN= noman - -.PATH: $(.CURDIR)/../config $(.CURDIR)/.. - -.include diff --git a/gnu/usr.bin/gdb/obstack.c b/gnu/usr.bin/gdb/obstack.c deleted file mode 100644 index 6f4b282..0000000 --- a/gnu/usr.bin/gdb/obstack.c +++ /dev/null @@ -1,313 +0,0 @@ -/* obstack.c - subroutines used implicitly by object stack macros - Copyright (C) 1988 Free Software Foundation, Inc. - -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 1, 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 this program; if not, write to the Free Software -Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - - -In other words, you are welcome to use, share and improve this program. -You are forbidden to forbid anyone else to use, share and improve -what you give them. Help stamp out software-hoarding! */ - - -#include "obstack.h" - -#ifdef __STDC__ -#define POINTER void * -#else -#define POINTER char * -#endif - -/* Determine default alignment. */ -struct fooalign {char x; double d;}; -#define DEFAULT_ALIGNMENT ((char *)&((struct fooalign *) 0)->d - (char *)0) -/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT. - But in fact it might be less smart and round addresses to as much as - DEFAULT_ROUNDING. So we prepare for it to do that. */ -union fooround {long x; double d;}; -#define DEFAULT_ROUNDING (sizeof (union fooround)) - -/* When we copy a long block of data, this is the unit to do it with. - On some machines, copying successive ints does not work; - in such a case, redefine COPYING_UNIT to `long' (if that works) - or `char' as a last resort. */ -#ifndef COPYING_UNIT -#define COPYING_UNIT int -#endif - -/* The non-GNU-C macros copy the obstack into this global variable - to avoid multiple evaluation. */ - -struct obstack *_obstack; - -/* Initialize an obstack H for use. Specify chunk size SIZE (0 means default). - Objects start on multiples of ALIGNMENT (0 means use default). - CHUNKFUN is the function to use to allocate chunks, - and FREEFUN the function to free them. */ - -void -_obstack_begin (h, size, alignment, chunkfun, freefun) - struct obstack *h; - int size; - int alignment; - POINTER (*chunkfun) (); - void (*freefun) (); -{ - register struct _obstack_chunk* chunk; /* points to new chunk */ - - if (alignment == 0) - alignment = DEFAULT_ALIGNMENT; - if (size == 0) - /* Default size is what GNU malloc can fit in a 4096-byte block. - Pick a number small enough that when rounded up to DEFAULT_ROUNDING - it is still smaller than 4096 - 4. */ - { - int extra = 4; - if (extra < DEFAULT_ROUNDING) - extra = DEFAULT_ROUNDING; - size = 4096 - extra; - } - - h->chunkfun = (struct _obstack_chunk * (*)()) chunkfun; - h->freefun = freefun; - h->chunk_size = size; - h->alignment_mask = alignment - 1; - - chunk = h->chunk = (*h->chunkfun) (h->chunk_size); - h->next_free = h->object_base = chunk->contents; - h->chunk_limit = chunk->limit - = (char *) chunk + h->chunk_size; - chunk->prev = 0; -} - -/* Allocate a new current chunk for the obstack *H - on the assumption that LENGTH bytes need to be added - to the current object, or a new object of length LENGTH allocated. - Copies any partial object from the end of the old chunk - to the beginning of the new one. */ - -void -_obstack_newchunk (h, length) - struct obstack *h; - int length; -{ - register struct _obstack_chunk* old_chunk = h->chunk; - register struct _obstack_chunk* new_chunk; - register long new_size; - register int obj_size = h->next_free - h->object_base; - register int i; - - /* Compute size for new chunk. */ - new_size = (obj_size + length) << 1; - if (new_size < h->chunk_size) - new_size = h->chunk_size; - - /* Allocate and initialize the new chunk. */ - new_chunk = h->chunk = (*h->chunkfun) (new_size); - new_chunk->prev = old_chunk; - new_chunk->limit = h->chunk_limit = (char *) new_chunk + new_size; - - /* Move the existing object to the new chunk. - Word at a time is fast and is safe because these - structures are aligned at least that much. */ - for (i = (obj_size + sizeof (COPYING_UNIT) - 1) / sizeof (COPYING_UNIT) - 1; - i >= 0; i--) - ((COPYING_UNIT *)new_chunk->contents)[i] - = ((COPYING_UNIT *)h->object_base)[i]; - - h->object_base = new_chunk->contents; - h->next_free = h->object_base + obj_size; -} - -/* Return nonzero if object OBJ has been allocated from obstack H. - This is here for debugging. - If you use it in a program, you are probably losing. */ - -int -_obstack_allocated_p (h, obj) - struct obstack *h; - POINTER obj; -{ - register struct _obstack_chunk* lp; /* below addr of any objects in this chunk */ - register struct _obstack_chunk* plp; /* point to previous chunk if any */ - - lp = (h)->chunk; - while (lp != 0 && ((POINTER)lp > obj || (POINTER)(lp)->limit < obj)) - { - plp = lp -> prev; - lp = plp; - } - return lp != 0; -} - -/* Free objects in obstack H, including OBJ and everything allocate - more recently than OBJ. If OBJ is zero, free everything in H. */ - -void -#ifdef __STDC__ -#undef obstack_free -obstack_free (struct obstack *h, POINTER obj) -#else -_obstack_free (h, obj) - struct obstack *h; - POINTER obj; -#endif -{ - register struct _obstack_chunk* lp; /* below addr of any objects in this chunk */ - register struct _obstack_chunk* plp; /* point to previous chunk if any */ - - lp = (h)->chunk; - while (lp != 0 && ((POINTER)lp > obj || (POINTER)(lp)->limit < obj)) - { - plp = lp -> prev; - (*h->freefun) (lp); - lp = plp; - } - if (lp) - { - (h)->object_base = (h)->next_free = (char *)(obj); - (h)->chunk_limit = lp->limit; - (h)->chunk = lp; - } - else if (obj != 0) - /* obj is not in any of the chunks! */ - abort (); -} - -/* Let same .o link with output of gcc and other compilers. */ - -#ifdef __STDC__ -void -_obstack_free (h, obj) - struct obstack *h; - POINTER obj; -{ - obstack_free (h, obj); -} -#endif - -#if 0 -/* These are now turned off because the applications do not use it - and it uses bcopy via obstack_grow, which causes trouble on sysV. */ - -/* Now define the functional versions of the obstack macros. - Define them to simply use the corresponding macros to do the job. */ - -#ifdef __STDC__ -/* These function definitions do not work with non-ANSI preprocessors; - they won't pass through the macro names in parentheses. */ - -/* The function names appear in parentheses in order to prevent - the macro-definitions of the names from being expanded there. */ - -POINTER (obstack_base) (obstack) - struct obstack *obstack; -{ - return obstack_base (obstack); -} - -POINTER (obstack_next_free) (obstack) - struct obstack *obstack; -{ - return obstack_next_free (obstack); -} - -int (obstack_object_size) (obstack) - struct obstack *obstack; -{ - return obstack_object_size (obstack); -} - -int (obstack_room) (obstack) - struct obstack *obstack; -{ - return obstack_room (obstack); -} - -void (obstack_grow) (obstack, pointer, length) - struct obstack *obstack; - POINTER pointer; - int length; -{ - obstack_grow (obstack, pointer, length); -} - -void (obstack_grow0) (obstack, pointer, length) - struct obstack *obstack; - POINTER pointer; - int length; -{ - obstack_grow0 (obstack, pointer, length); -} - -void (obstack_1grow) (obstack, character) - struct obstack *obstack; - int character; -{ - obstack_1grow (obstack, character); -} - -void (obstack_blank) (obstack, length) - struct obstack *obstack; - int length; -{ - obstack_blank (obstack, length); -} - -void (obstack_1grow_fast) (obstack, character) - struct obstack *obstack; - int character; -{ - obstack_1grow_fast (obstack, character); -} - -void (obstack_blank_fast) (obstack, length) - struct obstack *obstack; - int length; -{ - obstack_blank_fast (obstack, length); -} - -POINTER (obstack_finish) (obstack) - struct obstack *obstack; -{ - return obstack_finish (obstack); -} - -POINTER (obstack_alloc) (obstack, length) - struct obstack *obstack; - int length; -{ - return obstack_alloc (obstack, length); -} - -POINTER (obstack_copy) (obstack, pointer, length) - struct obstack *obstack; - POINTER pointer; - int length; -{ - return obstack_copy (obstack, pointer, length); -} - -POINTER (obstack_copy0) (obstack, pointer, length) - struct obstack *obstack; - POINTER pointer; - int length; -{ - return obstack_copy0 (obstack, pointer, length); -} - -#endif /* __STDC__ */ - -#endif /* 0 */ diff --git a/gnu/usr.bin/gdb/obstack.h b/gnu/usr.bin/gdb/obstack.h deleted file mode 100644 index 27c017e..0000000 --- a/gnu/usr.bin/gdb/obstack.h +++ /dev/null @@ -1,372 +0,0 @@ -/* obstack.h - object stack macros - Copyright (C) 1988 Free Software Foundation, Inc. - -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 1, 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 this program; if not, write to the Free Software -Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - - -In other words, you are welcome to use, share and improve this program. -You are forbidden to forbid anyone else to use, share and improve -what you give them. Help stamp out software-hoarding! */ - - -/* Summary: - -All the apparent functions defined here are macros. The idea -is that you would use these pre-tested macros to solve a -very specific set of problems, and they would run fast. -Caution: no side-effects in arguments please!! They may be -evaluated MANY times!! - -These macros operate a stack of objects. Each object starts life -small, and may grow to maturity. (Consider building a word syllable -by syllable.) An object can move while it is growing. Once it has -been "finished" it never changes address again. So the "top of the -stack" is typically an immature growing object, while the rest of the -stack is of mature, fixed size and fixed address objects. - -These routines grab large chunks of memory, using a function you -supply, called `obstack_chunk_alloc'. On occasion, they free chunks, -by calling `obstack_chunk_free'. You must define them and declare -them before using any obstack macros. - -Each independent stack is represented by a `struct obstack'. -Each of the obstack macros expects a pointer to such a structure -as the first argument. - -One motivation for this package is the problem of growing char strings -in symbol tables. Unless you are "facist pig with a read-only mind" -[Gosper's immortal quote from HAKMEM item 154, out of context] you -would not like to put any arbitrary upper limit on the length of your -symbols. - -In practice this often means you will build many short symbols and a -few long symbols. At the time you are reading a symbol you don't know -how long it is. One traditional method is to read a symbol into a -buffer, realloc()ating the buffer every time you try to read a symbol -that is longer than the buffer. This is beaut, but you still will -want to copy the symbol from the buffer to a more permanent -symbol-table entry say about half the time. - -With obstacks, you can work differently. Use one obstack for all symbol -names. As you read a symbol, grow the name in the obstack gradually. -When the name is complete, finalize it. Then, if the symbol exists already, -free the newly read name. - -The way we do this is to take a large chunk, allocating memory from -low addresses. When you want to build a aymbol in the chunk you just -add chars above the current "high water mark" in the chunk. When you -have finished adding chars, because you got to the end of the symbol, -you know how long the chars are, and you can create a new object. -Mostly the chars will not burst over the highest address of the chunk, -because you would typically expect a chunk to be (say) 100 times as -long as an average object. - -In case that isn't clear, when we have enough chars to make up -the object, THEY ARE ALREADY CONTIGUOUS IN THE CHUNK (guaranteed) -so we just point to it where it lies. No moving of chars is -needed and this is the second win: potentially long strings need -never be explicitly shuffled. Once an object is formed, it does not -change its address during its lifetime. - -When the chars burst over a chunk boundary, we allocate a larger -chunk, and then copy the partly formed object from the end of the old -chunk to the beggining of the new larger chunk. We then carry on -accreting characters to the end of the object as we normaly would. - -A special macro is provided to add a single char at a time to a -growing object. This allows the use of register variables, which -break the ordinary 'growth' macro. - -Summary: - We allocate large chunks. - We carve out one object at a time from the current chunk. - Once carved, an object never moves. - We are free to append data of any size to the currently - growing object. - Exactly one object is growing in an obstack at any one time. - You can run one obstack per control block. - You may have as many control blocks as you dare. - Because of the way we do it, you can `unwind' a obstack - back to a previous state. (You may remove objects much - as you would with a stack.) -*/ - - -/* Don't do the contents of this file more than once. */ - -#ifndef __OBSTACKS__ -#define __OBSTACKS__ - -/* We use subtraction of (char *)0 instead of casting to int - because on word-addressable machines a simple cast to int - may ignore the byte-within-word field of the pointer. */ - -#ifndef __PTR_TO_INT -#define __PTR_TO_INT(P) ((P) - (char *)0) -#endif - -#ifndef __INT_TO_PTR -#define __INT_TO_PTR(P) ((P) + (char *)0) -#endif - -struct _obstack_chunk /* Lives at front of each chunk. */ -{ - char *limit; /* 1 past end of this chunk */ - struct _obstack_chunk *prev; /* address of prior chunk or NULL */ - char contents[4]; /* objects begin here */ -}; - -struct obstack /* control current object in current chunk */ -{ - long chunk_size; /* preferred size to allocate chunks in */ - struct _obstack_chunk* chunk; /* address of current struct obstack_chunk */ - char *object_base; /* address of object we are building */ - char *next_free; /* where to add next char to current object */ - char *chunk_limit; /* address of char after current chunk */ - int temp; /* Temporary for some macros. */ - int alignment_mask; /* Mask of alignment for each object. */ - struct _obstack_chunk *(*chunkfun) (); /* User's fcn to allocate a chunk. */ - void (*freefun) (); /* User's function to free a chunk. */ -}; - -#ifdef __STDC__ - -/* Do the function-declarations after the structs - but before defining the macros. */ - -void obstack_init (struct obstack *obstack); - -void * obstack_alloc (struct obstack *obstack, int size); - -void * obstack_copy (struct obstack *obstack, void *address, int size); -void * obstack_copy0 (struct obstack *obstack, void *address, int size); - -void obstack_free (struct obstack *obstack, void *block); - -void obstack_blank (struct obstack *obstack, int size); - -void obstack_grow (struct obstack *obstack, void *data, int size); -void obstack_grow0 (struct obstack *obstack, void *data, int size); - -void obstack_1grow (struct obstack *obstack, int data_char); - -void * obstack_finish (struct obstack *obstack); - -int obstack_object_size (struct obstack *obstack); - -int obstack_room (struct obstack *obstack); -void obstack_1grow_fast (struct obstack *obstack, int data_char); -void obstack_blank_fast (struct obstack *obstack, int size); - -void * obstack_base (struct obstack *obstack); -void * obstack_next_free (struct obstack *obstack); -int obstack_alignment_mask (struct obstack *obstack); -int obstack_chunk_size (struct obstack *obstack); - -#endif /* __STDC__ */ - -/* Non-ANSI C cannot really support alternative functions for these macros, - so we do not declare them. */ - -/* Pointer to beginning of object being allocated or to be allocated next. - Note that this might not be the final address of the object - because a new chunk might be needed to hold the final size. */ - -#define obstack_base(h) ((h)->object_base) - -/* Size for allocating ordinary chunks. */ - -#define obstack_chunk_size(h) ((h)->chunk_size) - -/* Pointer to next byte not yet allocated in current chunk. */ - -#define obstack_next_free(h) ((h)->next_free) - -/* Mask specifying low bits that should be clear in address of an object. */ - -#define obstack_alignment_mask(h) ((h)->alignment_mask) - -#define obstack_init(h) \ - _obstack_begin ((h), 0, 0, obstack_chunk_alloc, obstack_chunk_free) - -#define obstack_begin(h, size) \ - _obstack_begin ((h), (size), 0, obstack_chunk_alloc, obstack_chunk_free) - -#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = achar) - -#define obstack_blank_fast(h,n) ((h)->next_free += (n)) - -#if defined (__GNUC__) && defined (__STDC__) - -/* For GNU C, if not -traditional, - we can define these macros to compute all args only once - without using a global variable. - Also, we can avoid using the `temp' slot, to make faster code. */ - -#define obstack_object_size(OBSTACK) \ - ({ struct obstack *__o = (OBSTACK); \ - (unsigned) (__o->next_free - __o->object_base); }) - -#define obstack_room(OBSTACK) \ - ({ struct obstack *__o = (OBSTACK); \ - (unsigned) (__o->chunk_limit - __o->next_free); }) - -#define obstack_grow(OBSTACK,where,length) \ -({ struct obstack *__o = (OBSTACK); \ - int __len = (length); \ - ((__o->next_free + __len > __o->chunk_limit) \ - ? _obstack_newchunk (__o, __len) : 0); \ - bcopy (where, __o->next_free, __len); \ - __o->next_free += __len; \ - (void) 0; }) - -#define obstack_grow0(OBSTACK,where,length) \ -({ struct obstack *__o = (OBSTACK); \ - int __len = (length); \ - ((__o->next_free + __len + 1 > __o->chunk_limit) \ - ? _obstack_newchunk (__o, __len + 1) : 0), \ - bcopy (where, __o->next_free, __len), \ - __o->next_free += __len, \ - *(__o->next_free)++ = 0; \ - (void) 0; }) - -#define obstack_1grow(OBSTACK,datum) \ -({ struct obstack *__o = (OBSTACK); \ - ((__o->next_free + 1 > __o->chunk_limit) \ - ? _obstack_newchunk (__o, 1) : 0), \ - *(__o->next_free)++ = (datum); \ - (void) 0; }) - -#define obstack_blank(OBSTACK,length) \ -({ struct obstack *__o = (OBSTACK); \ - int __len = (length); \ - ((__o->next_free + __len > __o->chunk_limit) \ - ? _obstack_newchunk (__o, __len) : 0); \ - __o->next_free += __len; \ - (void) 0; }) - -#define obstack_alloc(OBSTACK,length) \ -({ struct obstack *__h = (OBSTACK); \ - obstack_blank (__h, (length)); \ - obstack_finish (__h); }) - -#define obstack_copy(OBSTACK,where,length) \ -({ struct obstack *__h = (OBSTACK); \ - obstack_grow (__h, (where), (length)); \ - obstack_finish (__h); }) - -#define obstack_copy0(OBSTACK,where,length) \ -({ struct obstack *__h = (OBSTACK); \ - obstack_grow0 (__h, (where), (length)); \ - obstack_finish (__h); }) - -#define obstack_finish(OBSTACK) \ -({ struct obstack *__o = (OBSTACK); \ - void *value = (void *) __o->object_base; \ - __o->next_free \ - = __INT_TO_PTR ((__PTR_TO_INT (__o->next_free)+__o->alignment_mask)\ - & ~ (__o->alignment_mask)); \ - ((__o->next_free - (char *)__o->chunk \ - > __o->chunk_limit - (char *)__o->chunk) \ - ? (__o->next_free = __o->chunk_limit) : 0); \ - __o->object_base = __o->next_free; \ - value; }) - -#define obstack_free(OBSTACK, OBJ) \ -({ struct obstack *__o = (OBSTACK); \ - void *__obj = (OBJ); \ - if (__obj >= (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \ - __o->next_free = __o->object_base = __obj; \ - else (obstack_free) (__o, __obj); }) - -#else /* not __GNUC__ or not __STDC__ */ - -/* The non-GNU macros copy the obstack-pointer into this global variable - to avoid multiple evaluation. */ - -extern struct obstack *_obstack; - -#define obstack_object_size(h) \ - (unsigned) (_obstack = (h), (h)->next_free - (h)->object_base) - -#define obstack_room(h) \ - (unsigned) (_obstack = (h), (h)->chunk_limit - (h)->next_free) - -#define obstack_grow(h,where,length) \ -( (h)->temp = (length), \ - (((h)->next_free + (h)->temp > (h)->chunk_limit) \ - ? _obstack_newchunk ((h), (h)->temp) : 0), \ - bcopy (where, (h)->next_free, (h)->temp), \ - (h)->next_free += (h)->temp) - -#define obstack_grow0(h,where,length) \ -( (h)->temp = (length), \ - (((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \ - ? _obstack_newchunk ((h), (h)->temp + 1) : 0), \ - bcopy (where, (h)->next_free, (h)->temp), \ - (h)->next_free += (h)->temp, \ - *((h)->next_free)++ = 0) - -#define obstack_1grow(h,datum) \ -( (((h)->next_free + 1 > (h)->chunk_limit) \ - ? _obstack_newchunk ((h), 1) : 0), \ - *((h)->next_free)++ = (datum)) - -#define obstack_blank(h,length) \ -( (h)->temp = (length), \ - (((h)->next_free + (h)->temp > (h)->chunk_limit) \ - ? _obstack_newchunk ((h), (h)->temp) : 0), \ - (h)->next_free += (h)->temp) - -#define obstack_alloc(h,length) \ - (obstack_blank ((h), (length)), obstack_finish ((h))) - -#define obstack_copy(h,where,length) \ - (obstack_grow ((h), (where), (length)), obstack_finish ((h))) - -#define obstack_copy0(h,where,length) \ - (obstack_grow0 ((h), (where), (length)), obstack_finish ((h))) - -#define obstack_finish(h) \ -( (h)->temp = __PTR_TO_INT ((h)->object_base), \ - (h)->next_free \ - = __INT_TO_PTR ((__PTR_TO_INT ((h)->next_free)+(h)->alignment_mask) \ - & ~ ((h)->alignment_mask)), \ - (((h)->next_free - (char *)(h)->chunk \ - > (h)->chunk_limit - (char *)(h)->chunk) \ - ? ((h)->next_free = (h)->chunk_limit) : 0), \ - (h)->object_base = (h)->next_free, \ - __INT_TO_PTR ((h)->temp)) - -#ifdef __STDC__ -#define obstack_free(h,obj) \ -( (h)->temp = (char *)(obj) - (char *) (h)->chunk, \ - (((h)->temp >= 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\ - ? (int) ((h)->next_free = (h)->object_base \ - = (h)->temp + (char *) (h)->chunk) \ - : ((obstack_free) ((h), (h)->temp + (char *) (h)->chunk), 0))) -#else -#define obstack_free(h,obj) \ -( (h)->temp = (char *)(obj) - (char *) (h)->chunk, \ - (((h)->temp >= 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\ - ? (int) ((h)->next_free = (h)->object_base \ - = (h)->temp + (char *) (h)->chunk) \ - : (int) _obstack_free ((h), (h)->temp + (char *) (h)->chunk))) -#endif - -#endif /* not __GNUC__ or not __STDC__ */ - -#endif /* not __OBSTACKS__ */ - diff --git a/gnu/usr.bin/gdb/printcmd.c b/gnu/usr.bin/gdb/printcmd.c deleted file mode 100644 index 6edd7bd..0000000 --- a/gnu/usr.bin/gdb/printcmd.c +++ /dev/null @@ -1,1867 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)printcmd.c 6.5 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Print values for GNU debugger GDB. - Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "frame.h" -#include "symtab.h" -#include "value.h" -#include "expression.h" - -struct format_data -{ - int count; - char format; - char size; -}; - -/* Last specified output format. */ - -static char last_format = 'x'; - -/* Last specified examination size. 'b', 'h', 'w' or `q'. */ - -static char last_size = 'w'; - -/* Default address to examine next. */ - -static CORE_ADDR next_address; - -/* Last address examined. */ - -static CORE_ADDR last_examine_address; - -/* Contents of last address examined. - This is not valid past the end of the `x' command! */ - -static value last_examine_value; - -/* Number of auto-display expression currently being displayed. - So that we can deleted it if we get an error or a signal within it. - -1 when not doing one. */ - -int current_display_number; - -static void do_one_display (); - -void do_displays (); -void print_address (); -void print_floating (); -void print_scalar_formatted (); -void print_formatted_address (); - - -/* Decode a format specification. *STRING_PTR should point to it. - OFORMAT and OSIZE are used as defaults for the format and size - if none are given in the format specification. - If OSIZE is zero, then the size field of the returned value - should be set only if a size is explicitly specified by the - user. - The structure returned describes all the data - found in the specification. In addition, *STRING_PTR is advanced - past the specification and past all whitespace following it. */ - -struct format_data -decode_format (string_ptr, oformat, osize) - char **string_ptr; - char oformat; - char osize; -{ - struct format_data val; - register char *p = *string_ptr; - - val.format = '?'; - val.size = '?'; - val.count = 1; - - if (*p >= '0' && *p <= '9') - val.count = atoi (p); - while (*p >= '0' && *p <= '9') p++; - - /* Now process size or format letters that follow. */ - - while (1) - { - if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g') - val.size = *p++; -#ifdef LONG_LONG - else if (*p == 'l') - { - val.size = 'g'; - p++; - } -#endif - else if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z')) - val.format = *p++; - else - break; - } - -#ifndef LONG_LONG - /* Make sure 'g' size is not used on integer types. - Well, actually, we can handle hex. */ - if (val.size == 'g' && val.format != 'f' && val.format != 'x') - val.size = 'w'; -#endif - - while (*p == ' ' || *p == '\t') p++; - *string_ptr = p; - - /* Set defaults for format and size if not specified. */ - if (val.format == '?') - { - if (val.size == '?') - { - /* Neither has been specified. */ - val.format = oformat; - val.size = osize; - } - else - /* If a size is specified, any format makes a reasonable - default except 'i'. */ - val.format = oformat == 'i' ? 'x' : oformat; - } - else if (val.size == '?') - switch (val.format) - { - case 'a': - case 's': - case 'A': - /* Addresses must be words. */ - val.size = osize ? 'w' : osize; - break; - case 'f': - /* Floating point has to be word or giantword. */ - if (osize == 'w' || osize == 'g') - val.size = osize; - else - /* Default it to giantword if the last used size is not - appropriate. */ - val.size = osize ? 'g' : osize; - break; - case 'c': - /* Characters default to one byte. */ - val.size = osize ? 'b' : osize; - break; - default: - /* The default is the size most recently specified. */ - val.size = osize; - } - - return val; -} - -/* Print value VAL on stdout according to FORMAT, a letter or 0. - Do not end with a newline. - 0 means print VAL according to its own type. - SIZE is the letter for the size of datum being printed. - This is used to pad hex numbers so they line up. */ - -static void -print_formatted (val, format, size) - register value val; - register char format; - char size; -{ - int len = TYPE_LENGTH (VALUE_TYPE (val)); - - if (VALUE_LVAL (val) == lval_memory) - next_address = VALUE_ADDRESS (val) + len; - - switch (format) - { - case 's': - next_address = VALUE_ADDRESS (val) - + value_print (value_addr (val), stdout, 0, Val_pretty_default); - break; - - case 'i': - next_address = VALUE_ADDRESS (val) - + print_insn (VALUE_ADDRESS (val), stdout); - break; - - default: - if (format == 0 - || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_ARRAY - || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRUCT - || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_UNION - || VALUE_REPEATED (val)) - value_print (val, stdout, format, Val_pretty_default); - else - print_scalar_formatted (VALUE_CONTENTS (val), VALUE_TYPE (val), - format, size, stdout); - } -} - -/* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR, - according to letters FORMAT and SIZE on STREAM. - FORMAT may not be zero. Formats s and i are not supported at this level. - - This is how the elements of an array or structure are printed - with a format. */ - -void -print_scalar_formatted (valaddr, type, format, size, stream) - char *valaddr; - struct type *type; - char format; - int size; - FILE *stream; -{ - LONGEST val_long; - int len = TYPE_LENGTH (type); - - if (size == 'g' && sizeof (LONGEST) < 8 - && format == 'x') - { - /* ok, we're going to have to get fancy here. Assumption: a - long is four bytes. */ - unsigned long v1, v2, tmp; - - v1 = unpack_long (builtin_type_long, valaddr); - v2 = unpack_long (builtin_type_long, valaddr + 4); - -#ifdef BYTES_BIG_ENDIAN -#else - /* Little endian -- swap the two for printing */ - tmp = v1; - v1 = v2; - v2 = tmp; -#endif - - switch (format) - { - case 'x': - fprintf_filtered (stream, "0x%08x%08x", v1, v2); - break; - default: - error ("Output size \"g\" unimplemented for format \"%c\".", - format); - } - return; - } - - val_long = unpack_long (type, valaddr); - - /* If value is unsigned, truncate it in case negative. */ - if (format != 'd') - { - if (len == sizeof (char)) - val_long &= (1 << 8 * sizeof(char)) - 1; - else if (len == sizeof (short)) - val_long &= (1 << 8 * sizeof(short)) - 1; - else if (len == sizeof (long)) - val_long &= (unsigned long) - 1; - } - - switch (format) - { - case 'x': -#ifdef LONG_LONG - if (!size) - size = (len < sizeof (long long) ? 'w' : 'g'); - switch (size) - { - case 'b': - fprintf_filtered (stream, "0x%02llx", val_long); - break; - case 'h': - fprintf_filtered (stream, "0x%04llx", val_long); - break; - case 0: /* no size specified, like in print */ - case 'w': - fprintf_filtered (stream, "0x%08llx", val_long); - break; - case 'g': - fprintf_filtered (stream, "0x%016llx", val_long); - break; - default: - error ("Undefined output size \"%c\".", size); - } -#else - switch (size) - { - case 'b': - fprintf_filtered (stream, "0x%02x", val_long); - break; - case 'h': - fprintf_filtered (stream, "0x%04x", val_long); - break; - case 0: /* no size specified, like in print */ - case 'w': - fprintf_filtered (stream, "0x%08x", val_long); - break; - case 'g': - fprintf_filtered (stream, "0x%o16x", val_long); - break; - default: - error ("Undefined output size \"%c\".", size); - } -#endif /* not LONG_LONG */ - break; - - case 'd': -#ifdef LONG_LONG - fprintf_filtered (stream, "%lld", val_long); -#else - fprintf_filtered (stream, "%d", val_long); -#endif - break; - - case 'u': -#ifdef LONG_LONG - fprintf_filtered (stream, "%llu", val_long); -#else - fprintf_filtered (stream, "%u", val_long); -#endif - break; - - case 'o': - if (val_long) -#ifdef LONG_LONG - fprintf_filtered (stream, "0%llo", val_long); -#else - fprintf_filtered (stream, "0%o", val_long); -#endif - else - fprintf_filtered (stream, "0"); - break; - - case 'a': - print_address ((CORE_ADDR) val_long, stream); - break; - - case 'A': - print_formatted_address ((CORE_ADDR) val_long, stream); - break; - - case 'c': - value_print (value_from_long (builtin_type_char, val_long), stream, 0, - Val_pretty_default); - break; - - case 'f': - if (len == sizeof (float)) - type = builtin_type_float; - else if (len == sizeof (double)) - type = builtin_type_double; - print_floating(valaddr, type, stream); - break; - - case 0: - abort (); - - default: - error ("Undefined output format \"%c\".", format); - } -} - -/* Print a floating point value of type TYPE, pointed to in GDB by VALADDR, - on STREAM. */ - -void -print_floating(valaddr, type, stream) - char *valaddr; - struct type *type; - FILE *stream; -{ - double doub; - int inv; - int len = TYPE_LENGTH (type); - - doub = unpack_double (type, valaddr, &inv); - if (inv) - fprintf_filtered (stream, "Invalid float value"); - else if (doub != doub) - { - /* Surely it is an IEEE floating point NaN. */ - - long low, high, *arg = (long *)valaddr; /* ASSUMED 32 BITS */ - int nonneg; - - if (len <= sizeof(float)) - { - /* It's single precision. */ - low = *arg; - nonneg = low >= 0; - low &= 0x7fffff; - high = 0; - } - else - { - /* It's double precision. - Get the high and low words of the fraction. - Distinguish big and little-endian machines. */ -#ifdef WORDS_BIG_ENDIAN - low = arg[1], high = arg[0]; -#else - low = arg[0], high = arg[1]; -#endif - nonneg = high >= 0; - high &= 0xfffff; - } - if (high) - fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonneg, high, low); - else - fprintf_filtered (stream, "-NaN(0x%lx)" + nonneg, low); - } - else - fprintf_filtered (stream, len <= sizeof(float) ? "%.6g" : "%.17g", doub); -} - -/* Specify default address for `x' command. - `info lines' uses this. */ - -void -set_next_address (addr) - CORE_ADDR addr; -{ - next_address = addr; - - /* Make address available to the user as $_. */ - set_internalvar (lookup_internalvar ("_"), - value_from_long (builtin_type_int, (LONGEST) addr)); -} - -/* Optionally print address ADDR symbolically as on STREAM. */ - -void -print_address_symbolic (addr, stream) - CORE_ADDR addr; - FILE *stream; -{ - register char *format; - int name_location; - register int i = find_pc_misc_function (addr); - - /* If nothing comes out, don't print anything symbolic. */ - if (i < 0) return; - name_location = misc_function_vector[i].address; - - if (addr - name_location) - format = " <%s+%d>"; - else - format = " <%s>"; - - fprintf_filtered (stream, format, - misc_function_vector[i].name, addr - name_location); -} - -/* Print address ADDR symbolically on STREAM. - First print it as a number. Then perhaps print - after the number. */ - -void -print_address (addr, stream) - CORE_ADDR addr; - FILE *stream; -{ - fprintf_filtered (stream, "0x%x", addr); - print_address_symbolic (addr, stream); -} - -/* Like print_address but opnly prints symbolically. */ - -void -print_formatted_address (addr, stream) - CORE_ADDR addr; - FILE *stream; -{ - register int i = 0; - register char *format; - register struct symbol *fs; - char *name; - int name_location; - - i = find_pc_partial_function (addr, &name, &name_location); - - /* If nothing comes out, don't print anything symbolic. */ - - if (i == 0) - fprintf_filtered (stream, "0x%x", addr); - else if (addr - name_location) - fprintf_filtered (stream, "%s+%d", name, addr - name_location); - else - fprintf_filtered (stream, "%s", name); -} - -/* Examine data at address ADDR in format FMT. - Fetch it from memory and print on stdout. */ - -static void -do_examine (fmt, addr) - struct format_data fmt; - CORE_ADDR addr; -{ - register char format = 0; - register char size; - register int count = 1; - struct type *val_type; - register int i; - register int maxelts; - - format = fmt.format; - size = fmt.size; - count = fmt.count; - next_address = addr; - - /* String or instruction format implies fetch single bytes - regardless of the specified size. */ - if (format == 's' || format == 'i') - size = 'b'; - - if (size == 'b') - val_type = builtin_type_char; - else if (size == 'h') - val_type = builtin_type_short; - else if (size == 'w') - val_type = builtin_type_long; - else if (size == 'g') -#ifndef LONG_LONG - val_type = builtin_type_double; -#else - val_type = builtin_type_long_long; -#endif - - maxelts = 8; - if (size == 'w') - maxelts = 4; - if (size == 'g') - maxelts = 2; - if (format == 's' || format == 'i') - maxelts = 1; - - /* Print as many objects as specified in COUNT, at most maxelts per line, - with the address of the next one at the start of each line. */ - - while (count > 0) - { - print_address (next_address, stdout); - printf_filtered (":"); - for (i = maxelts; - i > 0 && count > 0; - i--, count--) - { - printf_filtered ("\t"); - /* Note that print_formatted sets next_address for the next - object. */ - last_examine_address = next_address; - last_examine_value = value_at (val_type, next_address); - print_formatted (last_examine_value, format, size); - } - printf_filtered ("\n"); - fflush (stdout); - } -} - -static void -validate_format (fmt, cmdname) - struct format_data fmt; - char *cmdname; -{ - if (fmt.size != 0) - error ("Size letters are meaningless in \"%s\" command.", cmdname); - if (fmt.count != 1) - error ("Item count other than 1 is meaningless in \"%s\" command.", - cmdname); - if (fmt.format == 'i' || fmt.format == 's') - error ("Format letter \"%c\" is meaningless in \"%s\" command.", - fmt.format, cmdname); -} - -static void -print_command (exp) - char *exp; -{ - struct expression *expr; - register struct cleanup *old_chain = 0; - register char format = 0; - register value val; - struct format_data fmt; - int histindex; - int cleanup = 0; - - if (exp && *exp == '/') - { - exp++; - fmt = decode_format (&exp, last_format, 0); - validate_format (fmt, "print"); - last_format = format = fmt.format; - } - - if (exp && *exp) - { - expr = parse_c_expression (exp); - old_chain = make_cleanup (free_current_contents, &expr); - cleanup = 1; - val = evaluate_expression (expr); - } - else - val = access_value_history (0); - - histindex = record_latest_value (val); - if (histindex >= 0) printf_filtered ("$%d = ", histindex); - - print_formatted (val, format, fmt.size); - printf_filtered ("\n"); - - if (cleanup) - do_cleanups (old_chain); -} - -static void -output_command (exp) - char *exp; -{ - struct expression *expr; - register struct cleanup *old_chain; - register char format = 0; - register value val; - struct format_data fmt; - - if (exp && *exp == '/') - { - exp++; - fmt = decode_format (&exp, 0, 0); - validate_format (fmt, "print"); - format = fmt.format; - } - - expr = parse_c_expression (exp); - old_chain = make_cleanup (free_current_contents, &expr); - - val = evaluate_expression (expr); - - print_formatted (val, format, fmt.size); - - do_cleanups (old_chain); -} - -static void -set_command (exp) - char *exp; -{ - struct expression *expr = parse_c_expression (exp); - register struct cleanup *old_chain - = make_cleanup (free_current_contents, &expr); - evaluate_expression (expr); - do_cleanups (old_chain); -} - -static void -address_info (exp) - char *exp; -{ - register struct symbol *sym; - register CORE_ADDR val; - int is_a_field_of_this; /* C++: lookup_symbol sets this to nonzero - if exp is a field of `this'. */ - - if (exp == 0) - error ("Argument required."); - - sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE, - &is_a_field_of_this); - if (sym == 0) - { - register int i; - - if (is_a_field_of_this) - { - printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp); - return; - } - - for (i = 0; i < misc_function_count; i++) - if (!strcmp (misc_function_vector[i].name, exp)) - break; - - if (i < misc_function_count) - printf ("Symbol \"%s\" is at 0x%x in a file compiled without -g.\n", - exp, misc_function_vector[i].address); - else - error ("No symbol \"%s\" in current context.", exp); - return; - } - - printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym)); - val = SYMBOL_VALUE (sym); - - switch (SYMBOL_CLASS (sym)) - { - case LOC_CONST: - case LOC_CONST_BYTES: - printf ("constant"); - break; - - case LOC_LABEL: - printf ("a label at address 0x%x", val); - break; - - case LOC_REGISTER: - printf ("a variable in register %s", reg_names[val]); - break; - - case LOC_STATIC: - printf ("static at address 0x%x", val); - break; - - case LOC_REGPARM: - printf ("an argument in register %s", reg_names[val]); - break; - - case LOC_ARG: - printf ("an argument at offset %d", val); - break; - - case LOC_LOCAL: - printf ("a local variable at frame offset %d", val); - break; - - case LOC_REF_ARG: - printf ("a reference argument at offset %d", val); - break; - - case LOC_TYPEDEF: - printf ("a typedef"); - break; - - case LOC_BLOCK: - printf ("a function at address 0x%x", - BLOCK_START (SYMBOL_BLOCK_VALUE (sym))); - break; - } - printf (".\n"); -} - -static void -x_command (exp, from_tty) - char *exp; - int from_tty; -{ - struct expression *expr; - struct format_data fmt; - struct cleanup *old_chain; - struct value *val; - - fmt.format = last_format; - fmt.size = last_size; - fmt.count = 1; - - if (exp && *exp == '/') - { - exp++; - fmt = decode_format (&exp, last_format, last_size); - last_size = fmt.size; - last_format = fmt.format; - } - - /* If we have an expression, evaluate it and use it as the address. */ - - if (exp != 0 && *exp != 0) - { - expr = parse_c_expression (exp); - /* Cause expression not to be there any more - if this command is repeated with Newline. - But don't clobber a user-defined command's definition. */ - if (from_tty) - *exp = 0; - old_chain = make_cleanup (free_current_contents, &expr); - val = evaluate_expression (expr); - /* In rvalue contexts, such as this, functions are coerced into - pointers to functions. This makes "x/i main" work. */ - if (/* last_format == 'i' - && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC - && VALUE_LVAL (val) == lval_memory) - next_address = VALUE_ADDRESS (val); - else - next_address = (CORE_ADDR) value_as_long (val); - do_cleanups (old_chain); - } - - do_examine (fmt, next_address); - - /* Set a couple of internal variables if appropriate. */ - if (last_examine_value) - { - /* Make last address examined available to the user as $_. */ - set_internalvar (lookup_internalvar ("_"), - value_from_long (builtin_type_int, - (LONGEST) last_examine_address)); - - /* Make contents of last address examined available to the user as $__.*/ - set_internalvar (lookup_internalvar ("__"), last_examine_value); - } -} - -/* Commands for printing types of things. */ - -static void -whatis_command (exp) - char *exp; -{ - struct expression *expr; - register value val; - register struct cleanup *old_chain; - - if (exp) - { - expr = parse_c_expression (exp); - old_chain = make_cleanup (free_current_contents, &expr); - val = evaluate_type (expr); - } - else - val = access_value_history (0); - - printf_filtered ("type = "); - /* Most of the time users do not want to see all the fields - in a structure. If they do they can use the "ptype" command. - Hence the "-1" below. */ - type_print (VALUE_TYPE (val), "", stdout, -1); - printf_filtered ("\n"); - - if (exp) - do_cleanups (old_chain); -} - -static void -ptype_command (typename) - char *typename; -{ - register char *p = typename; - register int len; - extern struct block *get_current_block (); - register struct block *b - = (have_inferior_p () || have_core_file_p ()) ? get_current_block () : 0; - register struct type *type; - - if (typename == 0) - error_no_arg ("type name"); - - while (*p && *p != ' ' && *p != '\t') p++; - len = p - typename; - while (*p == ' ' || *p == '\t') p++; - - if (len == 6 && !strncmp (typename, "struct", 6)) - type = lookup_struct (p, b); - else if (len == 5 && !strncmp (typename, "union", 5)) - type = lookup_union (p, b); - else if (len == 4 && !strncmp (typename, "enum", 4)) - type = lookup_enum (p, b); - else - { - type = lookup_typename (typename, b, 1); - if (type == 0) - { - register struct symbol *sym - = lookup_symbol (typename, b, STRUCT_NAMESPACE, 0); - if (sym == 0) - error ("No type named %s.", typename); - printf_filtered ("No type named %s, but there is a ", - typename); - switch (TYPE_CODE (SYMBOL_TYPE (sym))) - { - case TYPE_CODE_STRUCT: - printf_filtered ("struct"); - break; - - case TYPE_CODE_UNION: - printf_filtered ("union"); - break; - - case TYPE_CODE_ENUM: - printf_filtered ("enum"); - } - printf_filtered (" %s. Type \"help ptype\".\n", typename); - type = SYMBOL_TYPE (sym); - } - } - - type_print (type, "", stdout, 1); - printf_filtered ("\n"); -} - -enum display_status {disabled, enabled}; - -struct display -{ - /* Chain link to next auto-display item. */ - struct display *next; - /* Expression to be evaluated and displayed. */ - struct expression *exp; - /* Item number of this auto-display item. */ - int number; - /* Display format specified. */ - struct format_data format; - /* Innermost block required by this expression when evaluated */ - struct block *block; - /* Status of this display (enabled or disabled) */ - enum display_status status; -}; - -/* Chain of expressions whose values should be displayed - automatically each time the program stops. */ - -static struct display *display_chain; - -static int display_number; - -/* Add an expression to the auto-display chain. - Specify the expression. */ - -static void -display_command (exp, from_tty) - char *exp; - int from_tty; -{ - struct format_data fmt; - register struct expression *expr; - register struct display *new; - extern struct block *innermost_block; - - if (exp == 0) - { - do_displays (); - return; - } - - if (*exp == '/') - { - exp++; - fmt = decode_format (&exp, 0, 0); - if (fmt.size && fmt.format == 0) - fmt.format = 'x'; - if (fmt.format == 'i' || fmt.format == 's') - fmt.size = 'b'; - } - else - { - fmt.format = 0; - fmt.size = 0; - fmt.count = 0; - } - - innermost_block = 0; - expr = parse_c_expression (exp); - - new = (struct display *) xmalloc (sizeof (struct display)); - - new->exp = expr; - new->block = innermost_block; - new->next = display_chain; - new->number = ++display_number; - new->format = fmt; - new->status = enabled; - display_chain = new; - - if (from_tty && have_inferior_p ()) - do_one_display (new); - - dont_repeat (); -} - -static void -free_display (d) - struct display *d; -{ - free (d->exp); - free (d); -} - -/* Clear out the display_chain. - Done when new symtabs are loaded, since this invalidates - the types stored in many expressions. */ - -void -clear_displays () -{ - register struct display *d; - - while (d = display_chain) - { - free (d->exp); - display_chain = d->next; - free (d); - } -} - -/* Delete the auto-display number NUM. */ - -void -delete_display (num) - int num; -{ - register struct display *d1, *d; - - if (!display_chain) - error ("No display number %d.", num); - - if (display_chain->number == num) - { - d1 = display_chain; - display_chain = d1->next; - free_display (d1); - } - else - for (d = display_chain; ; d = d->next) - { - if (d->next == 0) - error ("No display number %d.", num); - if (d->next->number == num) - { - d1 = d->next; - d->next = d1->next; - free_display (d1); - break; - } - } -} - -/* Delete some values from the auto-display chain. - Specify the element numbers. */ - -static void -undisplay_command (args) - char *args; -{ - register char *p = args; - register char *p1; - register int num; - register struct display *d, *d1; - - if (args == 0) - { - if (query ("Delete all auto-display expressions? ")) - clear_displays (); - dont_repeat (); - return; - } - - while (*p) - { - p1 = p; - while (*p1 >= '0' && *p1 <= '9') p1++; - if (*p1 && *p1 != ' ' && *p1 != '\t') - error ("Arguments must be display numbers."); - - num = atoi (p); - - delete_display (num); - - p = p1; - while (*p == ' ' || *p == '\t') p++; - } - dont_repeat (); -} - -/* Display a single auto-display. - Do nothing if the display cannot be printed in the current context, - or if the display is disabled. */ - -static void -do_one_display (d) - struct display *d; -{ - int within_current_scope; - - if (d->status == disabled) - return; - - if (d->block) - within_current_scope = contained_in (get_selected_block (), d->block); - else - within_current_scope = 1; - if (!within_current_scope) - return; - - current_display_number = d->number; - - printf_filtered ("%d: ", d->number); - if (d->format.size) - { - printf_filtered ("x/"); - if (d->format.count != 1) - printf_filtered ("%d", d->format.count); - printf_filtered ("%c", d->format.format); - if (d->format.format != 'i' && d->format.format != 's') - printf_filtered ("%c", d->format.size); - printf_filtered (" "); - print_expression (d->exp, stdout); - if (d->format.count != 1) - printf_filtered ("\n"); - else - printf_filtered (" "); - do_examine (d->format, - (CORE_ADDR) value_as_long (evaluate_expression (d->exp))); - - } - else - { - if (d->format.format) - printf_filtered ("/%c ", d->format.format); - print_expression (d->exp, stdout); - printf_filtered (" = "); - print_formatted (evaluate_expression (d->exp), - d->format.format, d->format.size); - printf_filtered ("\n"); - } - - fflush (stdout); - current_display_number = -1; -} - -/* Display all of the values on the auto-display chain which can be - evaluated in the current scope. */ - -void -do_displays () -{ - register struct display *d; - - for (d = display_chain; d; d = d->next) - do_one_display (d); -} - -/* Delete the auto-display which we were in the process of displaying. - This is done when there is an error or a signal. */ - -void -disable_display (num) - int num; -{ - register struct display *d; - - for (d = display_chain; d; d = d->next) - if (d->number == num) - { - d->status = disabled; - return; - } - printf ("No display number %d.\n", num); -} - -void -disable_current_display () -{ - if (current_display_number >= 0) - { - disable_display (current_display_number); - fprintf (stderr, "Disabling display %d to avoid infinite recursion.\n", - current_display_number); - } - current_display_number = -1; -} - -static void -display_info () -{ - register struct display *d; - - if (!display_chain) - printf ("There are no auto-display expressions now.\n"); - else - printf_filtered ("Auto-display expressions now in effect:\n\ -Num Enb Expression\n"); - - for (d = display_chain; d; d = d->next) - { - printf_filtered ("%d: %c ", d->number, "ny"[(int)d->status]); - if (d->format.size) - printf_filtered ("/%d%c%c ", d->format.count, d->format.size, - d->format.format); - else if (d->format.format) - printf_filtered ("/%c ", d->format.format); - print_expression (d->exp, stdout); - if (d->block && !contained_in (get_selected_block (), d->block)) - printf_filtered (" (cannot be evaluated in the current context)"); - printf_filtered ("\n"); - fflush (stdout); - } -} - -void -enable_display (args) - char *args; -{ - register char *p = args; - register char *p1; - register int num; - register struct display *d; - - if (p == 0) - { - for (d = display_chain; d; d = d->next) - d->status = enabled; - } - else - while (*p) - { - p1 = p; - while (*p1 >= '0' && *p1 <= '9') - p1++; - if (*p1 && *p1 != ' ' && *p1 != '\t') - error ("Arguments must be display numbers."); - - num = atoi (p); - - for (d = display_chain; d; d = d->next) - if (d->number == num) - { - d->status = enabled; - goto win; - } - printf ("No display number %d.\n", num); - win: - p = p1; - while (*p == ' ' || *p == '\t') - p++; - } -} - -void -disable_display_command (args, from_tty) - char *args; - int from_tty; -{ - register char *p = args; - register char *p1; - register int num; - register struct display *d; - - if (p == 0) - { - for (d = display_chain; d; d = d->next) - d->status = disabled; - } - else - while (*p) - { - p1 = p; - while (*p1 >= '0' && *p1 <= '9') - p1++; - if (*p1 && *p1 != ' ' && *p1 != '\t') - error ("Arguments must be display numbers."); - - num = atoi (p); - - disable_display (atoi (p)); - - p = p1; - while (*p == ' ' || *p == '\t') - p++; - } -} - - -/* Print the value in stack frame FRAME of a variable - specified by a struct symbol. */ - -void -print_variable_value (var, frame, stream) - struct symbol *var; - FRAME frame; - FILE *stream; -{ - value val = read_var_value (var, frame); - value_print (val, stream, 0, Val_pretty_default); -} - -static int -compare_ints (i, j) - int *i, *j; -{ - return *i - *j; -} - -/* Print the arguments of a stack frame, given the function FUNC - running in that frame (as a symbol), the info on the frame, - and the number of args according to the stack frame (or -1 if unknown). */ - -static void print_frame_nameless_args (); - -void -print_frame_args (func, fi, num, stream) - struct symbol *func; - struct frame_info *fi; - int num; - FILE *stream; -{ - struct block *b; - int nsyms = 0; - int first = 1; - register int i; - register int last_regparm = 0; - register struct symbol *lastsym, *sym, *nextsym; - register value val; - /* Offset of stack argument that is at the highest offset. - -1 if we haven't come to a stack argument yet. */ - CORE_ADDR highest_offset = (CORE_ADDR) -1; - register CORE_ADDR addr = FRAME_ARGS_ADDRESS (fi); - - if (func) - { - b = SYMBOL_BLOCK_VALUE (func); - nsyms = BLOCK_NSYMS (b); - } - - for (i = 0; i < nsyms; i++) - { - QUIT; - sym = BLOCK_SYM (b, i); - - if (SYMBOL_CLASS (sym) != LOC_REGPARM - && SYMBOL_CLASS (sym) != LOC_ARG - && SYMBOL_CLASS (sym) != LOC_REF_ARG) - continue; - - /* Print the next arg. */ - if (SYMBOL_CLASS (sym) == LOC_REGPARM) - val = value_from_register (SYMBOL_TYPE (sym), - SYMBOL_VALUE (sym), - FRAME_INFO_ID (fi)); - else - { - int current_offset = SYMBOL_VALUE (sym); - int arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym)); - - if (SYMBOL_CLASS (sym) == LOC_REF_ARG) - val = value_at (SYMBOL_TYPE (sym), - read_memory_integer (addr + current_offset, - sizeof (CORE_ADDR))); - else - val = value_at (SYMBOL_TYPE (sym), addr + current_offset); - - /* Round up address of next arg to multiple of size of int. */ - current_offset - = (((current_offset + sizeof (int) - 1) / sizeof (int)) - * sizeof (int)); - - /* If this is the highest offset seen yet, set highest_offset. */ - if (highest_offset == (CORE_ADDR)-1 - || ((current_offset - + (arg_size - sizeof (int) + 3) / (sizeof (int))) - > highest_offset)) - highest_offset = current_offset; - } - - if (! first) - fprintf_filtered (stream, ", "); - fputs_filtered (SYMBOL_NAME (sym), stream); - fputs_filtered ("=", stream); - -/* Nonzero if a LOC_ARG which is a struct is useless. */ -#if !defined (STRUCT_ARG_SYM_GARBAGE) -#define STRUCT_ARG_SYM_GARBAGE(gcc_p) 0 -#endif - - if (STRUCT_ARG_SYM_GARBAGE (b->gcc_compile_flag) - && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT - && SYMBOL_CLASS (sym) == LOC_ARG) - { - /* Try looking up that name. SunOS4 puts out a usable - symbol as a local variable (in addition to the one - for the arg). */ - struct symbol *sym2 = - lookup_symbol (SYMBOL_NAME (sym), b, VAR_NAMESPACE, 0); - - if (sym2 != NULL) - val = value_of_variable (sym2); - else - { - fputs_filtered ("?", stream); - first = 0; - continue; - } - } - - value_print (val, stream, 0, Val_no_prettyprint); - first = 0; - } - - /* Don't print nameless args in situations where we don't know - enough about the stack to find them. */ - if (num != -1) - { - if (highest_offset != (CORE_ADDR) -1 - && num * sizeof (int) + FRAME_ARGS_SKIP > highest_offset) - print_frame_nameless_args (fi, addr, - highest_offset + sizeof (int), - num * sizeof (int) + FRAME_ARGS_SKIP, - stream); - else - print_frame_nameless_args (fi, addr, FRAME_ARGS_SKIP, - num * sizeof (int) + FRAME_ARGS_SKIP, - stream); - } -} - -static void -print_frame_nameless_args (fi, argsaddr, start, end, stream) - struct frame_info *fi; - CORE_ADDR argsaddr; - int start; - int end; - FILE *stream; -{ - extern void (*default_scalar_print)(); - LONGEST v; - int p = start; - char *s = ""; - - for (p = start; p < end; p += sizeof(int)) { - QUIT; -#if defined(NAMELESS_ARG) - v = NAMELESS_ARG(fi, (p - start) / sizeof(int)); -#else - v = read_memory_integer (argsaddr + p, sizeof (int)); -#endif - fprintf_filtered (stream, s); - s = ", "; - (*default_scalar_print) (stream, builtin_type_int, v); - } -} - -static void -printf_command (arg) - char *arg; -{ - register char *f; - register char *s = arg; - char *string; - value *val_args; - int nargs = 0; - int allocated_args = 20; - char *arg_bytes; - - val_args = (value *) xmalloc (allocated_args * sizeof (value)); - - if (s == 0) - error_no_arg ("format-control string and values to print"); - - /* Skip white space before format string */ - while (*s == ' ' || *s == '\t') s++; - - /* A format string should follow, enveloped in double quotes */ - if (*s++ != '"') - error ("Bad format string, missing '\"'."); - - /* Parse the format-control string and copy it into the string STRING, - processing some kinds of escape sequence. */ - - f = string = (char *) alloca (strlen (s) + 1); - while (*s != '"') - { - int c = *s++; - switch (c) - { - case '\0': - error ("Bad format string, non-terminated '\"'."); - /* doesn't return */ - - case '\\': - switch (c = *s++) - { - case '\\': - *f++ = '\\'; - break; - case 'n': - *f++ = '\n'; - break; - case 't': - *f++ = '\t'; - break; - case 'r': - *f++ = '\r'; - break; - case '"': - *f++ = '"'; - break; - default: - /* ??? TODO: handle other escape sequences */ - error ("Unrecognized \\ escape character in format string."); - } - break; - - default: - *f++ = c; - } - } - - /* Skip over " and following space and comma. */ - s++; - *f++ = '\0'; - while (*s == ' ' || *s == '\t') s++; - - if (*s != ',' && *s != 0) - error ("Invalid argument syntax"); - - if (*s == ',') s++; - while (*s == ' ' || *s == '\t') s++; - - { - /* Now scan the string for %-specs and see what kinds of args they want. - argclass[I] classifies the %-specs so we can give vprintf something - of the right size. */ - - enum argclass {int_arg, string_arg, double_arg, long_long_arg}; - enum argclass *argclass; - int nargs_wanted; - int argindex; - int lcount; - int i; - - argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass); - nargs_wanted = 0; - f = string; - while (*f) - if (*f++ == '%') - { - lcount = 0; - while (index ("0123456789.hlL-+ #", *f)) - { - if (*f == 'l' || *f == 'L') - lcount++; - f++; - } - if (*f == 's') - argclass[nargs_wanted++] = string_arg; - else if (*f == 'e' || *f == 'f' || *f == 'g') - argclass[nargs_wanted++] = double_arg; - else if (lcount > 1) - argclass[nargs_wanted++] = long_long_arg; - else if (*f != '%') - argclass[nargs_wanted++] = int_arg; - f++; - } - - /* Now, parse all arguments and evaluate them. - Store the VALUEs in VAL_ARGS. */ - - while (*s != '\0') - { - char *s1; - if (nargs == allocated_args) - val_args = (value *) xrealloc (val_args, - (allocated_args *= 2) - * sizeof (value)); - s1 = s; - val_args[nargs] = parse_to_comma_and_eval (&s1); - - /* If format string wants a float, unchecked-convert the value to - floating point of the same size */ - - if (argclass[nargs] == double_arg) - { - if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float)) - VALUE_TYPE (val_args[nargs]) = builtin_type_float; - if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double)) - VALUE_TYPE (val_args[nargs]) = builtin_type_double; - } - nargs++; - s = s1; - if (*s == ',') - s++; - } - - if (nargs != nargs_wanted) - error ("Wrong number of arguments for specified format-string"); - - /* Now lay out an argument-list containing the arguments - as doubles, integers and C pointers. */ - - arg_bytes = (char *) alloca (sizeof (double) * nargs); - argindex = 0; - for (i = 0; i < nargs; i++) - { - if (argclass[i] == string_arg) - { - char *str; - int tem, j; - tem = value_as_long (val_args[i]); - - /* This is a %s argument. Find the length of the string. */ - for (j = 0; ; j++) - { - char c; - QUIT; - read_memory (tem + j, &c, 1); - if (c == 0) - break; - } - - /* Copy the string contents into a string inside GDB. */ - str = (char *) alloca (j + 1); - read_memory (tem, str, j); - str[j] = 0; - - /* Pass address of internal copy as the arg to vprintf. */ - *((int *) &arg_bytes[argindex]) = (int) str; - argindex += sizeof (int); - } - else if (VALUE_TYPE (val_args[i])->code == TYPE_CODE_FLT) - { - *((double *) &arg_bytes[argindex]) = value_as_double (val_args[i]); - argindex += sizeof (double); - } - else -#ifdef LONG_LONG - if (argclass[i] == long_long_arg) - { - *(long long *) &arg_bytes[argindex] = value_as_long (val_args[i]); - argindex += sizeof (long long); - } - else -#endif - { - *((int *) &arg_bytes[argindex]) = value_as_long (val_args[i]); - argindex += sizeof (int); - } - } - } - vprintf (string, arg_bytes); -} - -/* Helper function for asdump_command. Finds the bounds of a function - for a specified section of text. PC is an address within the - function which you want bounds for; *LOW and *HIGH are set to the - beginning (inclusive) and end (exclusive) of the function. This - function returns 1 on success and 0 on failure. */ - -static int -containing_function_bounds (pc, low, high) - CORE_ADDR pc, *low, *high; -{ - int scan; - - if (!find_pc_partial_function (pc, 0, low)) - return 0; - - scan = *low; - do { - scan++; - if (!find_pc_partial_function (scan, 0, high)) - return 0; - } while (*low == *high); - - return 1; -} - -/* Dump a specified section of assembly code. With no command line - arguments, this command will dump the assembly code for the - function surrounding the pc value in the selected frame. With one - argument, it will dump the assembly code surrounding that pc value. - Two arguments are interpeted as bounds within which to dump - assembly. */ - -static void -disassemble_command (arg, from_tty) - char *arg; - int from_tty; -{ - CORE_ADDR low, high; - CORE_ADDR pc; - char *space_index; - - if (!arg) - { - if (!selected_frame) - error ("No frame selected.\n"); - - pc = get_frame_pc (selected_frame); - if (!containing_function_bounds (pc, &low, &high)) - error ("No function contains pc specified by selected frame.\n"); - } - else if (!(space_index = (char *) index (arg, ' '))) - { - /* One argument. */ - pc = parse_and_eval_address (arg); - if (!containing_function_bounds (pc, &low, &high)) - error ("No function contains specified pc.\n"); - } - else - { - /* Two arguments. */ - *space_index = '\0'; - low = parse_and_eval_address (arg); - high = parse_and_eval_address (space_index + 1); - } - - printf_filtered ("Dump of assembler code "); - if (!space_index) - { - char *name; - find_pc_partial_function (pc, &name, 0); - printf_filtered ("for function %s:\n", name); - } - else - printf_filtered ("from 0x%x to 0x%x:\n", low, high); - - /* Dump the specified range. */ - for (pc = low; pc < high; ) - { - QUIT; - print_address (pc, stdout); - printf_filtered (":\t"); - pc += print_insn (pc, stdout); - printf_filtered ("\n"); - } - printf_filtered ("End of assembler dump.\n"); - fflush (stdout); -} - - -extern struct cmd_list_element *enablelist, *disablelist, *deletelist; -extern struct cmd_list_element *cmdlist, *setlist; - -void -_initialize_printcmd () -{ - current_display_number = -1; - - add_info ("address", address_info, - "Describe where variable VAR is stored."); - - add_com ("x", class_vars, x_command, - "Examine memory: x/FMT ADDRESS.\n\ -ADDRESS is an expression for the memory address to examine.\n\ -FMT is a repeat count followed by a format letter and a size letter.\n\ -Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\ - f(float), a(address), i(instruction), c(char) and s(string).\n\ -Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\ - g is meaningful only with f, for type double.\n\ -The specified number of objects of the specified size are printed\n\ -according to the format.\n\n\ -Defaults for format and size letters are those previously used.\n\ -Default count is 1. Default address is following last thing printed\n\ -with this command or \"print\"."); - - add_com ("disassemble", class_vars, disassemble_command, - "Disassemble a specified section of memory.\n\ -Default is the function surrounding the pc of the selected frame.\n\ -With a single argument, the function surrounding that address is dumped.\n\ -Two arguments are taken as a range of memory to dump."); - - add_com ("ptype", class_vars, ptype_command, - "Print definition of type TYPE.\n\ -Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\ -or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\ -The selected stack frame's lexical context is used to look up the name."); - - add_com ("whatis", class_vars, whatis_command, - "Print data type of expression EXP."); - - add_info ("display", display_info, - "Expressions to display when program stops, with code numbers."); - - add_cmd ("undisplay", class_vars, undisplay_command, - "Cancel some expressions to be displayed when program stops.\n\ -Arguments are the code numbers of the expressions to stop displaying.\n\ -No argument means cancel all automatic-display expressions.\n\ -\"delete display\" has the same effect as this command.\n\ -Do \"info display\" to see current list of code numbers.", - &cmdlist); - - add_com ("display", class_vars, display_command, - "Print value of expression EXP each time the program stops.\n\ -/FMT may be used before EXP as in the \"print\" command.\n\ -/FMT \"i\" or \"s\" or including a size-letter is allowed,\n\ -as in the \"x\" command, and then EXP is used to get the address to examine\n\ -and examining is done as in the \"x\" command.\n\n\ -With no argument, display all currently requested auto-display expressions.\n\ -Use \"undisplay\" to cancel display requests previously made."); - - add_cmd ("display", class_vars, enable_display, - "Enable some expressions to be displayed when program stops.\n\ -Arguments are the code numbers of the expressions to resume displaying.\n\ -No argument means enable all automatic-display expressions.\n\ -Do \"info display\" to see current list of code numbers.", &enablelist); - - add_cmd ("display", class_vars, disable_display_command, - "Disable some expressions to be displayed when program stops.\n\ -Arguments are the code numbers of the expressions to stop displaying.\n\ -No argument means disable all automatic-display expressions.\n\ -Do \"info display\" to see current list of code numbers.", &disablelist); - - add_cmd ("display", class_vars, undisplay_command, - "Cancel some expressions to be displayed when program stops.\n\ -Arguments are the code numbers of the expressions to stop displaying.\n\ -No argument means cancel all automatic-display expressions.\n\ -Do \"info display\" to see current list of code numbers.", &deletelist); - - add_com ("printf", class_vars, printf_command, - "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ -This is useful for formatted output in user-defined commands."); - add_com ("output", class_vars, output_command, - "Like \"print\" but don't put in value history and don't print newline.\n\ -This is useful in user-defined commands."); - - add_prefix_cmd ("set", class_vars, set_command, -"Perform an assignment VAR = EXP.\n\ -You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\ -(names starting with $), a register (a few standard names starting with $),\n\ -or an actual variable in the program being debugged. EXP is any expression.\n\ -Use \"set variable\" for variables with names identical to set subcommands.\n\ -\nWith a subcommand, this command modifies parts of the gdb environment", - &setlist, "set ", 1, &cmdlist); - - add_cmd ("variable", class_vars, set_command, - "Perform an assignment VAR = EXP.\n\ -You must type the \"=\". VAR may be a debugger \"convenience\" variable\n\ -(names starting with $), a register (a few standard names starting with $),\n\ -or an actual variable in the program being debugged. EXP is any expression.\n\ -This may usually be abbreviated to simply \"set\".", - &setlist); - - add_com ("print", class_vars, print_command, - concat ("Print value of expression EXP.\n\ -Variables accessible are those of the lexical environment of the selected\n\ -stack frame, plus all those whose scope is global or an entire file.\n\ -\n\ -$NUM gets previous value number NUM. $ and $$ are the last two values.\n\ -$$NUM refers to NUM'th value back from the last one.\n\ -Names starting with $ refer to registers (with the values they would have\n\ -if the program were to return to the stack frame now selected, restoring\n\ -all registers saved by frames farther in) or else to debugger\n\ -\"convenience\" variables (any such name not a known register).\n\ -Use assignment expressions to give values to convenience variables.\n", - "\n\ -\{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\ -@ is a binary operator for treating consecutive data objects\n\ -anywhere in memory as an array. FOO@NUM gives an array whose first\n\ -element is FOO, whose second element is stored in the space following\n\ -where FOO is stored, etc. FOO must be an expression whose value\n\ -resides in memory.\n", - "\n\ -EXP may be preceded with /FMT, where FMT is a format letter\n\ -but no count or size letter (see \"x\" command).")); - add_com_alias ("p", "print", class_vars, 1); -} diff --git a/gnu/usr.bin/gdb/readline/ChangeLog b/gnu/usr.bin/gdb/readline/ChangeLog deleted file mode 100644 index b72a59d..0000000 --- a/gnu/usr.bin/gdb/readline/ChangeLog +++ /dev/null @@ -1,98 +0,0 @@ -Thu Feb 8 01:04:00 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu) - - * Makefile (the *other* libreadline.a): Uncomment out ranlib line. - -Thu Feb 1 17:50:22 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu) - - * Makefile (libreadline.a): Uncomment out ranlib line. - -Sun Nov 26 16:29:11 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * readline.c (rl_deprep_terminal): Only restore local_mode_flags - if they had been set. - -Thu Oct 19 17:18:40 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * Move vi_doing_insert from vi_mode.c to readline.c - - * readline.c: Move compare_strings before its use. - Remove declarations. - - * readline.c: Move defining_kbd_macro above rl_dispatch. - (rl_dispatch): Remove "extern int defining_kbd_macro". - -Mon Oct 16 11:56:03 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * readline.c (rl_set_signals): Remove unnecessary "static int - rl_signal_handler()". - -Sat Sep 30 14:51:56 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * readline.c (rl_initialize): Change parsing_conditionalized_out - to static. - (rl_dispatch): Change defining_kbd_macro to static. - (rl_newline): Change vi_doing_insert to static. - -Fri Sep 8 09:00:45 1989 Brian Fox (bfox at aurel) - - * readline.c: rl_prep_terminal (). Only turn on 8th bit - as meta-bit iff the terminal is not using parity. - -Sun Sep 3 08:57:40 1989 Brian Fox (bfox at aurel) - - * readline.c: start_insert (). Uses multiple - insertion call in cases where that makes sense. - - rl_insert (). Read type-ahead buffer for additional - keys that are bound to rl_insert, and insert them - all at once. Make insertion of single keys given - with an argument much more efficient. - -Tue Aug 8 18:13:57 1989 Brian Fox (bfox at aurel) - - * readline.c: Changed handling of EOF. readline () returns - (char *)EOF or consed string. The EOF character is read from the - tty, or if the tty doesn't have one, defaults to C-d. - - * readline.c: Added support for event driven programs. - rl_event_hook is the address of a function you want called - while Readline is waiting for input. - - * readline.c: Cleanup time. Functions without type declarations - do not use return with a value. - - * history.c: history_expand () has new variable which is the - characters to ignore immediately following history_expansion_char. - -Sun Jul 16 08:14:00 1989 Brian Fox (bfox at aurel) - - * rl_prep_terminal () - BSD version turns off C-s, C-q, C-y, C-v. - - * readline.c -- rl_prep_terminal () - SYSV version hacks readline_echoing_p. - BSD version turns on passing of the 8th bit for the duration - of reading the line. - -Tue Jul 11 06:25:01 1989 Brian Fox (bfox at aurel) - - * readline.c: new variable rl_tilde_expander. - If non-null, this contains the address of a function to call if - the standard meaning for expanding a tilde fails. The function is - called with the text sans tilde (as in "foo"), and returns a - malloc()'ed string which is the expansion, or a NULL pointer if - there is no expansion. - - * readline.h - new file chardefs.h - Separates things that only readline.c needs from the standard - header file publishing interesting things about readline. - - * readline.c: - readline_default_bindings () now looks at terminal chararacters - and binds those as well. - -Wed Jun 28 20:20:51 1989 Brian Fox (bfox at aurel) - - * Made readline and history into independent libraries. - - diff --git a/gnu/usr.bin/gdb/readline/Makefile.gnu b/gnu/usr.bin/gdb/readline/Makefile.gnu deleted file mode 100644 index dc11539..0000000 --- a/gnu/usr.bin/gdb/readline/Makefile.gnu +++ /dev/null @@ -1,114 +0,0 @@ -## -*- text -*- #################################################### -# # -# Makefile for readline and history libraries. # -# # -#################################################################### - -# Here is a rule for making .o files from .c files that doesn't force -# the type of the machine (like -sun3) into the flags. -.c.o: - $(CC) -c $(CFLAGS) $(LOCAL_INCLUDES) $(CPPFLAGS) $*.c - -# Destination installation directory. The libraries are copied to DESTDIR -# when you do a `make install', and the header files to INCDIR/readline/*.h. -DESTDIR = /usr/gnu/lib -INCDIR = /usr/gnu/include - -# Define TYPES as -DVOID_SIGHANDLER if your operating system uses -# a return type of "void" for signal handlers. -TYPES = -DVOID_SIGHANDLER - -# Define SYSV as -DSYSV if you are using a System V operating system. -#SYSV = -DSYSV - -# HP-UX compilation requires the BSD library. -#LOCAL_LIBS = -lBSD - -# Xenix compilation requires -ldir -lx -#LOCAL_LIBS = -ldir -lx - -# Comment this out if you don't think that anyone will ever desire -# the vi line editing mode and features. -READLINE_DEFINES = -DVI_MODE - -DEBUG_FLAGS = -g -LDFLAGS = $(DEBUG_FLAGS) -CFLAGS = $(DEBUG_FLAGS) $(TYPE) $(SYSV) -I. - -# A good alternative is gcc -traditional. -#CC = gcc -traditional -CC = cc -RANLIB = /usr/bin/ranlib -AR = ar -RM = rm -CP = cp - -LOCAL_INCLUDES = -I../ - -CSOURCES = readline.c history.c funmap.c keymaps.c vi_mode.c \ - emacs_keymap.c vi_keymap.c keymaps.c - -HSOURCES = readline.h chardefs.h history.h keymaps.h -SOURCES = $(CSOURCES) $(HSOURCES) - -DOCUMENTATION = readline.texinfo inc-readline.texinfo \ - history.texinfo inc-history.texinfo - -SUPPORT = COPYING Makefile $(DOCUMENTATION) ChangeLog - -THINGS_TO_TAR = $(SOURCES) $(SUPPORT) - -########################################################################## - -all: libreadline.a - -libreadline.a: readline.o history.o funmap.o keymaps.o - $(RM) -f libreadline.a - $(AR) clq libreadline.a readline.o history.o funmap.o keymaps.o - if [ -f $(RANLIB) ]; then $(RANLIB) libreadline.a; fi - -readline.o: readline.h chardefs.h keymaps.h history.h readline.c vi_mode.c - $(CC) -c $(CFLAGS) $(CPPFLAGS) $(READLINE_DEFINES) \ - $(LOCAL_INCLUDES) $*.c - -history.o: history.c history.h - $(CC) -c $(CFLAGS) $(CPPFLAGS) $(READLINE_DEFINES) \ - $(LOCAL_INCLUDES) $*.c - -funmap.o: readline.h - $(CC) -c $(CFLAGS) $(CPPFLAGS) $(READLINE_DEFINES) \ - $(LOCAL_INCLUDES) $*.c - -keymaps.o: emacs_keymap.c vi_keymap.c keymaps.h chardefs.h keymaps.c - $(CC) -c $(CFLAGS) $(CPPFLAGS) $(READLINE_DEFINES) \ - $(LOCAL_INCLUDES) $*.c - -libtest: libreadline.a libtest.c - $(CC) -o libtest $(CFLAGS) $(CPPFLAGS) -L. libtest.c -lreadline -ltermcap - -readline: readline.c history.o keymaps.o funmap.o readline.h chardefs.h - $(CC) $(CFLAGS) $(CPPFLAGS) $(READLINE_DEFINES) \ - $(LOCAL_INCLUDES) -DTEST -o readline readline.c funmap.o \ - keymaps.o history.o -L. -ltermcap - -readline.tar: $(THINGS_TO_TAR) - tar -cf readline.tar $(THINGS_TO_TAR) - -readline.tar.Z: readline.tar - compress -f readline.tar - -install: $(DESTDIR)/libreadline.a includes - -includes: - if [ ! -r $(INCDIR)/readline ]; then\ - mkdir $(INCDIR)/readline;\ - chmod a+r $(INCDIR)/readline;\ - fi - $(CP) readline.h keymaps.h chardefs.h $(INCDIR)/readline/ -clean: - rm -f *.o *.a *.log *.cp *.tp *.vr *.fn *.aux *.pg *.toc - -$(DESTDIR)/libreadline.a: libreadline.a - -mv $(DESTDIR)/libreadline.a $(DESTDIR)/libreadline.old - cp libreadline.a $(DESTDIR)/libreadline.a - $(RANLIB) -t $(DESTDIR)/libreadline.a diff --git a/gnu/usr.bin/gdb/readline/chardefs.h b/gnu/usr.bin/gdb/readline/chardefs.h deleted file mode 100644 index 9749ae4..0000000 --- a/gnu/usr.bin/gdb/readline/chardefs.h +++ /dev/null @@ -1,50 +0,0 @@ -/* chardefs.h -- Character definitions for readline. */ -#ifndef _CHARDEFS_ - -#ifndef savestring -#define savestring(x) (char *)strcpy (xmalloc (1 + strlen (x)), (x)) -#endif - -#ifndef whitespace -#define whitespace(c) (((c) == ' ') || ((c) == '\t')) -#endif - -#ifdef CTRL -#undef CTRL -#endif - -/* Some character stuff. */ -#define control_character_threshold 0x020 /* smaller than this is control */ -#define meta_character_threshold 0x07f /* larger than this is Meta. */ -#define control_character_bit 0x40 /* 0x000000, must be off. */ -#define meta_character_bit 0x080 /* x0000000, must be on. */ - -#define CTRL(c) ((c) & (~control_character_bit)) -#define META(c) ((c) | meta_character_bit) - -#define UNMETA(c) ((c) & (~meta_character_bit)) -#define UNCTRL(c) to_upper(((c)|control_character_bit)) - -#define lowercase_p(c) (((c) > ('a' - 1) && (c) < ('z' + 1))) -#define uppercase_p(c) (((c) > ('A' - 1) && (c) < ('Z' + 1))) - -#define pure_alphabetic(c) (lowercase_p(c) || uppercase_p(c)) - -#ifndef to_upper -#define to_upper(c) (lowercase_p(c) ? ((c) - 32) : (c)) -#define to_lower(c) (uppercase_p(c) ? ((c) + 32) : (c)) -#endif - -#define CTRL_P(c) ((c) < control_character_threshold) -#define META_P(c) ((c) > meta_character_threshold) - -#define NEWLINE '\n' -#define RETURN CTRL('M') -#define RUBOUT 0x07f -#define TAB '\t' -#define ABORT_CHAR CTRL('G') -#define PAGE CTRL('L') -#define SPACE 0x020 -#define ESC CTRL('[') - -#endif /* _CHARDEFS_ */ diff --git a/gnu/usr.bin/gdb/readline/emacs_keymap.c b/gnu/usr.bin/gdb/readline/emacs_keymap.c deleted file mode 100644 index 7030e69..0000000 --- a/gnu/usr.bin/gdb/readline/emacs_keymap.c +++ /dev/null @@ -1,472 +0,0 @@ -/* emacs_keymap.c -- the keymap for emacs_mode in readline (). */ - -/* Copyright (C) 1988,1989 Free Software Foundation, Inc. - - This file is part of GNU Readline, a library for reading lines - of text with interactive input and history editing. - - Readline 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 1, or (at your option) any - later version. - - Readline 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 Readline; see the file COPYING. If not, write to the Free - Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef FILE -#include -#endif /* FILE */ - -#include "readline.h" - -/* An array of function pointers, one for each possible key. - If the type byte is ISKMAP, then the pointer is the address of - a keymap. */ - -KEYMAP_ENTRY_ARRAY emacs_standard_keymap = { - - /* Control keys. */ - { ISFUNC, (Function *)0x0 }, /* Control-@ */ - { ISFUNC, rl_beg_of_line }, /* Control-a */ - { ISFUNC, rl_backward }, /* Control-b */ - { ISFUNC, (Function *)0x0 }, /* Control-c */ - { ISFUNC, rl_delete }, /* Control-d */ - { ISFUNC, rl_end_of_line }, /* Control-e */ - { ISFUNC, rl_forward }, /* Control-f */ - { ISFUNC, rl_abort }, /* Control-g */ - { ISFUNC, rl_backward }, /* Control-h */ - { ISFUNC, rl_complete }, /* Control-i */ - { ISFUNC, rl_newline }, /* Control-j */ - { ISFUNC, rl_kill_line }, /* Control-k */ - { ISFUNC, rl_clear_screen }, /* Control-l */ - { ISFUNC, rl_newline }, /* Control-m */ - { ISFUNC, rl_get_next_history }, /* Control-n */ - { ISFUNC, (Function *)0x0 }, /* Control-o */ - { ISFUNC, rl_get_previous_history }, /* Control-p */ - { ISFUNC, rl_quoted_insert }, /* Control-q */ - { ISFUNC, rl_reverse_search_history }, /* Control-r */ - { ISFUNC, rl_forward_search_history }, /* Control-s */ - { ISFUNC, rl_transpose_chars }, /* Control-t */ - { ISFUNC, rl_unix_line_discard }, /* Control-u */ - { ISFUNC, rl_quoted_insert }, /* Control-v */ - { ISFUNC, rl_unix_word_rubout }, /* Control-w */ - { ISKMAP, (Function *)emacs_ctlx_keymap }, /* Control-x */ - { ISFUNC, rl_yank }, /* Control-y */ - { ISFUNC, (Function *)0x0 }, /* Control-z */ - { ISKMAP, (Function *)emacs_meta_keymap }, /* Control-[ */ - { ISFUNC, (Function *)0x0 }, /* Control-\ */ - { ISFUNC, (Function *)0x0 }, /* Control-] */ - { ISFUNC, (Function *)0x0 }, /* Control-^ */ - { ISFUNC, rl_undo_command }, /* Control-_ */ - - /* The start of printing characters. */ - { ISFUNC, rl_insert }, /* SPACE */ - { ISFUNC, rl_insert }, /* ! */ - { ISFUNC, rl_insert }, /* " */ - { ISFUNC, rl_insert }, /* # */ - { ISFUNC, rl_insert }, /* $ */ - { ISFUNC, rl_insert }, /* % */ - { ISFUNC, rl_insert }, /* & */ - { ISFUNC, rl_insert }, /* ' */ - { ISFUNC, rl_insert }, /* ( */ - { ISFUNC, rl_insert }, /* ) */ - { ISFUNC, rl_insert }, /* * */ - { ISFUNC, rl_insert }, /* + */ - { ISFUNC, rl_insert }, /* , */ - { ISFUNC, rl_insert }, /* - */ - { ISFUNC, rl_insert }, /* . */ - { ISFUNC, rl_insert }, /* / */ - - /* Regular digits. */ - { ISFUNC, rl_insert }, /* 0 */ - { ISFUNC, rl_insert }, /* 1 */ - { ISFUNC, rl_insert }, /* 2 */ - { ISFUNC, rl_insert }, /* 3 */ - { ISFUNC, rl_insert }, /* 4 */ - { ISFUNC, rl_insert }, /* 5 */ - { ISFUNC, rl_insert }, /* 6 */ - { ISFUNC, rl_insert }, /* 7 */ - { ISFUNC, rl_insert }, /* 8 */ - { ISFUNC, rl_insert }, /* 9 */ - - /* A little more punctuation. */ - { ISFUNC, rl_insert }, /* : */ - { ISFUNC, rl_insert }, /* ; */ - { ISFUNC, rl_insert }, /* < */ - { ISFUNC, rl_insert }, /* = */ - { ISFUNC, rl_insert }, /* > */ - { ISFUNC, rl_insert }, /* ? */ - { ISFUNC, rl_insert }, /* @ */ - - /* Uppercase alphabet. */ - { ISFUNC, rl_insert }, /* A */ - { ISFUNC, rl_insert }, /* B */ - { ISFUNC, rl_insert }, /* C */ - { ISFUNC, rl_insert }, /* D */ - { ISFUNC, rl_insert }, /* E */ - { ISFUNC, rl_insert }, /* F */ - { ISFUNC, rl_insert }, /* G */ - { ISFUNC, rl_insert }, /* H */ - { ISFUNC, rl_insert }, /* I */ - { ISFUNC, rl_insert }, /* J */ - { ISFUNC, rl_insert }, /* K */ - { ISFUNC, rl_insert }, /* L */ - { ISFUNC, rl_insert }, /* M */ - { ISFUNC, rl_insert }, /* N */ - { ISFUNC, rl_insert }, /* O */ - { ISFUNC, rl_insert }, /* P */ - { ISFUNC, rl_insert }, /* Q */ - { ISFUNC, rl_insert }, /* R */ - { ISFUNC, rl_insert }, /* S */ - { ISFUNC, rl_insert }, /* T */ - { ISFUNC, rl_insert }, /* U */ - { ISFUNC, rl_insert }, /* V */ - { ISFUNC, rl_insert }, /* W */ - { ISFUNC, rl_insert }, /* X */ - { ISFUNC, rl_insert }, /* Y */ - { ISFUNC, rl_insert }, /* Z */ - - /* Some more punctuation. */ - { ISFUNC, rl_insert }, /* [ */ - { ISFUNC, rl_insert }, /* \ */ - { ISFUNC, rl_insert }, /* ] */ - { ISFUNC, rl_insert }, /* ^ */ - { ISFUNC, rl_insert }, /* _ */ - { ISFUNC, rl_insert }, /* ` */ - - /* Lowercase alphabet. */ - { ISFUNC, rl_insert }, /* a */ - { ISFUNC, rl_insert }, /* b */ - { ISFUNC, rl_insert }, /* c */ - { ISFUNC, rl_insert }, /* d */ - { ISFUNC, rl_insert }, /* e */ - { ISFUNC, rl_insert }, /* f */ - { ISFUNC, rl_insert }, /* g */ - { ISFUNC, rl_insert }, /* h */ - { ISFUNC, rl_insert }, /* i */ - { ISFUNC, rl_insert }, /* j */ - { ISFUNC, rl_insert }, /* k */ - { ISFUNC, rl_insert }, /* l */ - { ISFUNC, rl_insert }, /* m */ - { ISFUNC, rl_insert }, /* n */ - { ISFUNC, rl_insert }, /* o */ - { ISFUNC, rl_insert }, /* p */ - { ISFUNC, rl_insert }, /* q */ - { ISFUNC, rl_insert }, /* r */ - { ISFUNC, rl_insert }, /* s */ - { ISFUNC, rl_insert }, /* t */ - { ISFUNC, rl_insert }, /* u */ - { ISFUNC, rl_insert }, /* v */ - { ISFUNC, rl_insert }, /* w */ - { ISFUNC, rl_insert }, /* x */ - { ISFUNC, rl_insert }, /* y */ - { ISFUNC, rl_insert }, /* z */ - - /* Final punctuation. */ - { ISFUNC, rl_insert }, /* { */ - { ISFUNC, rl_insert }, /* | */ - { ISFUNC, rl_insert }, /* } */ - { ISFUNC, rl_insert }, /* ~ */ - { ISFUNC, rl_rubout } /* RUBOUT */ -}; - -KEYMAP_ENTRY_ARRAY emacs_meta_keymap = { - - /* Meta keys. Just like above, but the high bit is set. */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-@ */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-a */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-b */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-c */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-d */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-e */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-f */ - { ISFUNC, rl_abort }, /* Meta-Control-g */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-h */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-i */ - { ISFUNC, rl_vi_editing_mode }, /* Meta-Control-j */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-k */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-l */ - { ISFUNC, rl_vi_editing_mode }, /* Meta-Control-m */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-n */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-o */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-p */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-q */ - { ISFUNC, rl_revert_line }, /* Meta-Control-r */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-s */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-t */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-u */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-v */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-w */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-x */ - { ISFUNC, rl_yank_nth_arg }, /* Meta-Control-y */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-z */ - - { ISFUNC, (Function *)0x0 }, /* Meta-Control-[ */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-\ */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-] */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-^ */ - { ISFUNC, (Function *)0x0 }, /* Meta-Control-_ */ - - /* The start of printing characters. */ - { ISFUNC, (Function *)0x0 }, /* Meta-SPACE */ - { ISFUNC, (Function *)0x0 }, /* Meta-! */ - { ISFUNC, (Function *)0x0 }, /* Meta-" */ - { ISFUNC, (Function *)0x0 }, /* Meta-# */ - { ISFUNC, (Function *)0x0 }, /* Meta-$ */ - { ISFUNC, (Function *)0x0 }, /* Meta-% */ - { ISFUNC, (Function *)0x0 }, /* Meta-& */ - { ISFUNC, (Function *)0x0 }, /* Meta-' */ - { ISFUNC, (Function *)0x0 }, /* Meta-( */ - { ISFUNC, (Function *)0x0 }, /* Meta-) */ - { ISFUNC, (Function *)0x0 }, /* Meta-* */ - { ISFUNC, (Function *)0x0 }, /* Meta-+ */ - { ISFUNC, (Function *)0x0 }, /* Meta-, */ - { ISFUNC, rl_digit_argument }, /* Meta-- */ - { ISFUNC, (Function *)0x0 }, /* Meta-. */ - { ISFUNC, (Function *)0x0 }, /* Meta-/ */ - - /* Regular digits. */ - { ISFUNC, rl_digit_argument }, /* Meta-0 */ - { ISFUNC, rl_digit_argument }, /* Meta-1 */ - { ISFUNC, rl_digit_argument }, /* Meta-2 */ - { ISFUNC, rl_digit_argument }, /* Meta-3 */ - { ISFUNC, rl_digit_argument }, /* Meta-4 */ - { ISFUNC, rl_digit_argument }, /* Meta-5 */ - { ISFUNC, rl_digit_argument }, /* Meta-6 */ - { ISFUNC, rl_digit_argument }, /* Meta-7 */ - { ISFUNC, rl_digit_argument }, /* Meta-8 */ - { ISFUNC, rl_digit_argument }, /* Meta-9 */ - - /* A little more punctuation. */ - { ISFUNC, (Function *)0x0 }, /* Meta-: */ - { ISFUNC, (Function *)0x0 }, /* Meta-; */ - { ISFUNC, rl_beginning_of_history }, /* Meta-< */ - { ISFUNC, (Function *)0x0 }, /* Meta-= */ - { ISFUNC, rl_end_of_history }, /* Meta-> */ - { ISFUNC, rl_possible_completions }, /* Meta-? */ - { ISFUNC, (Function *)0x0 }, /* Meta-@ */ - - /* Uppercase alphabet. */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-A */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-B */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-C */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-D */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-E */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-F */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-G */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-H */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-I */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-J */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-K */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-L */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-M */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-N */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-O */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-P */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-Q */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-R */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-S */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-T */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-U */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-V */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-W */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-X */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-Y */ - { ISFUNC, rl_do_lowercase_version }, /* Meta-Z */ - - /* Some more punctuation. */ - { ISFUNC, (Function *)0x0 }, /* Meta-[ */ - { ISFUNC, (Function *)0x0 }, /* Meta-\ */ - { ISFUNC, (Function *)0x0 }, /* Meta-] */ - { ISFUNC, (Function *)0x0 }, /* Meta-^ */ - { ISFUNC, (Function *)0x0 }, /* Meta-_ */ - { ISFUNC, (Function *)0x0 }, /* Meta-` */ - - /* Lowercase alphabet. */ - { ISFUNC, (Function *)0x0 }, /* Meta-a */ - { ISFUNC, rl_backward_word }, /* Meta-b */ - { ISFUNC, rl_capitalize_word }, /* Meta-c */ - { ISFUNC, rl_kill_word }, /* Meta-d */ - { ISFUNC, (Function *)0x0 }, /* Meta-e */ - { ISFUNC, rl_forward_word }, /* Meta-f */ - { ISFUNC, (Function *)0x0 }, /* Meta-g */ - { ISFUNC, (Function *)0x0 }, /* Meta-h */ - { ISFUNC, (Function *)0x0 }, /* Meta-i */ - { ISFUNC, (Function *)0x0 }, /* Meta-j */ - { ISFUNC, (Function *)0x0 }, /* Meta-k */ - { ISFUNC, rl_downcase_word }, /* Meta-l */ - { ISFUNC, (Function *)0x0 }, /* Meta-m */ - { ISFUNC, (Function *)0x0 }, /* Meta-n */ - { ISFUNC, (Function *)0x0 }, /* Meta-o */ - { ISFUNC, (Function *)0x0 }, /* Meta-p */ - { ISFUNC, (Function *)0x0 }, /* Meta-q */ - { ISFUNC, rl_revert_line }, /* Meta-r */ - { ISFUNC, (Function *)0x0 }, /* Meta-s */ - { ISFUNC, rl_transpose_words }, /* Meta-t */ - { ISFUNC, rl_upcase_word }, /* Meta-u */ - { ISFUNC, (Function *)0x0 }, /* Meta-v */ - { ISFUNC, (Function *)0x0 }, /* Meta-w */ - { ISFUNC, (Function *)0x0 }, /* Meta-x */ - { ISFUNC, rl_yank_pop }, /* Meta-y */ - { ISFUNC, (Function *)0x0 }, /* Meta-z */ - - /* Final punctuation. */ - { ISFUNC, (Function *)0x0 }, /* Meta-{ */ - { ISFUNC, (Function *)0x0 }, /* Meta-| */ - { ISFUNC, (Function *)0x0 }, /* Meta-} */ - { ISFUNC, (Function *)0x0 }, /* Meta-~ */ - { ISFUNC, rl_backward_kill_word } /* Meta-rubout */ -}; - -KEYMAP_ENTRY_ARRAY emacs_ctlx_keymap = { - - /* Control keys. */ - { ISFUNC, (Function *)0x0 }, /* Control-@ */ - { ISFUNC, (Function *)0x0 }, /* Control-a */ - { ISFUNC, (Function *)0x0 }, /* Control-b */ - { ISFUNC, (Function *)0x0 }, /* Control-c */ - { ISFUNC, (Function *)0x0 }, /* Control-d */ - { ISFUNC, (Function *)0x0 }, /* Control-e */ - { ISFUNC, (Function *)0x0 }, /* Control-f */ - { ISFUNC, rl_abort }, /* Control-g */ - { ISFUNC, (Function *)0x0 }, /* Control-h */ - { ISFUNC, (Function *)0x0 }, /* Control-i */ - { ISFUNC, (Function *)0x0 }, /* Control-j */ - { ISFUNC, (Function *)0x0 }, /* Control-k */ - { ISFUNC, (Function *)0x0 }, /* Control-l */ - { ISFUNC, (Function *)0x0 }, /* Control-m */ - { ISFUNC, (Function *)0x0 }, /* Control-n */ - { ISFUNC, (Function *)0x0 }, /* Control-o */ - { ISFUNC, (Function *)0x0 }, /* Control-p */ - { ISFUNC, (Function *)0x0 }, /* Control-q */ - { ISFUNC, rl_re_read_init_file }, /* Control-r */ - { ISFUNC, (Function *)0x0 }, /* Control-s */ - { ISFUNC, (Function *)0x0 }, /* Control-t */ - { ISFUNC, rl_undo_command }, /* Control-u */ - { ISFUNC, (Function *)0x0 }, /* Control-v */ - { ISFUNC, (Function *)0x0 }, /* Control-w */ - { ISFUNC, (Function *)0x0 }, /* Control-x */ - { ISFUNC, (Function *)0x0 }, /* Control-y */ - { ISFUNC, (Function *)0x0 }, /* Control-z */ - { ISFUNC, (Function *)0x0 }, /* Control-[ */ - { ISFUNC, (Function *)0x0 }, /* Control-\ */ - { ISFUNC, (Function *)0x0 }, /* Control-] */ - { ISFUNC, (Function *)0x0 }, /* Control-^ */ - { ISFUNC, (Function *)0x0 }, /* Control-_ */ - - /* The start of printing characters. */ - { ISFUNC, (Function *)0x0 }, /* SPACE */ - { ISFUNC, (Function *)0x0 }, /* ! */ - { ISFUNC, (Function *)0x0 }, /* " */ - { ISFUNC, (Function *)0x0 }, /* # */ - { ISFUNC, (Function *)0x0 }, /* $ */ - { ISFUNC, (Function *)0x0 }, /* % */ - { ISFUNC, (Function *)0x0 }, /* & */ - { ISFUNC, (Function *)0x0 }, /* ' */ - { ISFUNC, rl_start_kbd_macro }, /* ( */ - { ISFUNC, rl_end_kbd_macro }, /* ) */ - { ISFUNC, (Function *)0x0 }, /* * */ - { ISFUNC, (Function *)0x0 }, /* + */ - { ISFUNC, (Function *)0x0 }, /* , */ - { ISFUNC, (Function *)0x0 }, /* - */ - { ISFUNC, (Function *)0x0 }, /* . */ - { ISFUNC, (Function *)0x0 }, /* / */ - - /* Regular digits. */ - { ISFUNC, (Function *)0x0 }, /* 0 */ - { ISFUNC, (Function *)0x0 }, /* 1 */ - { ISFUNC, (Function *)0x0 }, /* 2 */ - { ISFUNC, (Function *)0x0 }, /* 3 */ - { ISFUNC, (Function *)0x0 }, /* 4 */ - { ISFUNC, (Function *)0x0 }, /* 5 */ - { ISFUNC, (Function *)0x0 }, /* 6 */ - { ISFUNC, (Function *)0x0 }, /* 7 */ - { ISFUNC, (Function *)0x0 }, /* 8 */ - { ISFUNC, (Function *)0x0 }, /* 9 */ - - /* A little more punctuation. */ - { ISFUNC, (Function *)0x0 }, /* : */ - { ISFUNC, (Function *)0x0 }, /* ; */ - { ISFUNC, (Function *)0x0 }, /* < */ - { ISFUNC, (Function *)0x0 }, /* = */ - { ISFUNC, (Function *)0x0 }, /* > */ - { ISFUNC, (Function *)0x0 }, /* ? */ - { ISFUNC, (Function *)0x0 }, /* @ */ - - /* Uppercase alphabet. */ - { ISFUNC, rl_do_lowercase_version }, /* A */ - { ISFUNC, rl_do_lowercase_version }, /* B */ - { ISFUNC, rl_do_lowercase_version }, /* C */ - { ISFUNC, rl_do_lowercase_version }, /* D */ - { ISFUNC, rl_do_lowercase_version }, /* E */ - { ISFUNC, rl_do_lowercase_version }, /* F */ - { ISFUNC, rl_do_lowercase_version }, /* G */ - { ISFUNC, rl_do_lowercase_version }, /* H */ - { ISFUNC, rl_do_lowercase_version }, /* I */ - { ISFUNC, rl_do_lowercase_version }, /* J */ - { ISFUNC, rl_do_lowercase_version }, /* K */ - { ISFUNC, rl_do_lowercase_version }, /* L */ - { ISFUNC, rl_do_lowercase_version }, /* M */ - { ISFUNC, rl_do_lowercase_version }, /* N */ - { ISFUNC, rl_do_lowercase_version }, /* O */ - { ISFUNC, rl_do_lowercase_version }, /* P */ - { ISFUNC, rl_do_lowercase_version }, /* Q */ - { ISFUNC, rl_do_lowercase_version }, /* R */ - { ISFUNC, rl_do_lowercase_version }, /* S */ - { ISFUNC, rl_do_lowercase_version }, /* T */ - { ISFUNC, rl_do_lowercase_version }, /* U */ - { ISFUNC, rl_do_lowercase_version }, /* V */ - { ISFUNC, rl_do_lowercase_version }, /* W */ - { ISFUNC, rl_do_lowercase_version }, /* X */ - { ISFUNC, rl_do_lowercase_version }, /* Y */ - { ISFUNC, rl_do_lowercase_version }, /* Z */ - - /* Some more punctuation. */ - { ISFUNC, (Function *)0x0 }, /* [ */ - { ISFUNC, (Function *)0x0 }, /* \ */ - { ISFUNC, (Function *)0x0 }, /* ] */ - { ISFUNC, (Function *)0x0 }, /* ^ */ - { ISFUNC, (Function *)0x0 }, /* _ */ - { ISFUNC, (Function *)0x0 }, /* ` */ - - /* Lowercase alphabet. */ - { ISFUNC, (Function *)0x0 }, /* a */ - { ISFUNC, (Function *)0x0 }, /* b */ - { ISFUNC, (Function *)0x0 }, /* c */ - { ISFUNC, (Function *)0x0 }, /* d */ - { ISFUNC, rl_call_last_kbd_macro }, /* e */ - { ISFUNC, (Function *)0x0 }, /* f */ - { ISFUNC, (Function *)0x0 }, /* g */ - { ISFUNC, (Function *)0x0 }, /* h */ - { ISFUNC, (Function *)0x0 }, /* i */ - { ISFUNC, (Function *)0x0 }, /* j */ - { ISFUNC, (Function *)0x0 }, /* k */ - { ISFUNC, (Function *)0x0 }, /* l */ - { ISFUNC, (Function *)0x0 }, /* m */ - { ISFUNC, (Function *)0x0 }, /* n */ - { ISFUNC, (Function *)0x0 }, /* o */ - { ISFUNC, (Function *)0x0 }, /* p */ - { ISFUNC, (Function *)0x0 }, /* q */ - { ISFUNC, rl_re_read_init_file }, /* r */ - { ISFUNC, (Function *)0x0 }, /* s */ - { ISFUNC, (Function *)0x0 }, /* t */ - { ISFUNC, (Function *)0x0 }, /* u */ - { ISFUNC, (Function *)0x0 }, /* v */ - { ISFUNC, (Function *)0x0 }, /* w */ - { ISFUNC, (Function *)0x0 }, /* x */ - { ISFUNC, (Function *)0x0 }, /* y */ - { ISFUNC, (Function *)0x0 }, /* z */ - - /* Final punctuation. */ - { ISFUNC, (Function *)0x0 }, /* { */ - { ISFUNC, (Function *)0x0 }, /* | */ - { ISFUNC, (Function *)0x0 }, /* } */ - { ISFUNC, (Function *)0x0 }, /* ~ */ - { ISFUNC, rl_backward_kill_line } /* RUBOUT */ -}; diff --git a/gnu/usr.bin/gdb/readline/funmap.c b/gnu/usr.bin/gdb/readline/funmap.c deleted file mode 100644 index 357e716..0000000 --- a/gnu/usr.bin/gdb/readline/funmap.c +++ /dev/null @@ -1,217 +0,0 @@ -/* funmap.c -- attach names to functions. */ - -/* Copyright (C) 1988,1989 Free Software Foundation, Inc. - - This file is part of GNU Readline, a library for reading lines - of text with interactive input and history editing. - - Readline 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 1, or (at your option) any - later version. - - Readline 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 Readline; see the file COPYING. If not, write to the Free - Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#define STATIC_MALLOC -#ifndef STATIC_MALLOC -extern char *xmalloc (), *xrealloc (); -#else -static char *xmalloc (), *xrealloc (); -#endif - -#ifndef FILE -#include -#endif /* FILE */ - -#include "readline.h" - -FUNMAP **funmap = (FUNMAP **)NULL; -static int funmap_size = 0; - -static int just_testing_ar_tmp = 0; -static int just_testing_ar_tmp_2 = 5; -int foo_testing_ar; - -static int funmap_entry = 0; - -static FUNMAP default_funmap[] = { - { "beginning-of-line", rl_beg_of_line }, - { "backward-char", rl_backward }, - { "delete-char", rl_delete }, - { "end-of-line", rl_end_of_line }, - { "forward-char", rl_forward }, - { "accept-line", rl_newline }, - { "kill-line", rl_kill_line }, - { "clear-screen", rl_clear_screen }, - { "next-history", rl_get_next_history }, - { "previous-history", rl_get_previous_history }, - { "quoted-insert", rl_quoted_insert }, - { "reverse-search-history", rl_reverse_search_history }, - { "forward-search-history", rl_forward_search_history }, - { "transpose-chars", rl_transpose_chars }, - { "unix-line-discard", rl_unix_line_discard }, - { "unix-word-rubout", rl_unix_word_rubout }, - { "yank", rl_yank }, - { "yank-pop", rl_yank_pop }, - { "yank-nth-arg", rl_yank_nth_arg }, - { "backward-delete-char", rl_rubout }, - { "backward-word", rl_backward_word }, - { "kill-word", rl_kill_word }, - { "forward-word", rl_forward_word }, - { "tab-insert", rl_tab_insert }, - { "backward-kill-word", rl_backward_kill_word }, - { "backward-kill-line", rl_backward_kill_line }, - { "transpose-words", rl_transpose_words }, - { "digit-argument", rl_digit_argument }, - { "complete", rl_complete }, - { "possible-completions", rl_possible_completions }, - { "do-lowercase-version", rl_do_lowercase_version }, - { "digit-argument", rl_digit_argument }, - { "universal-argument", rl_universal_argument }, - { "abort", rl_abort }, - { "undo", rl_undo_command }, - { "upcase-word", rl_upcase_word }, - { "downcase-word", rl_downcase_word }, - { "capitalize-word", rl_capitalize_word }, - { "revert-line", rl_revert_line }, - { "beginning-of-history", rl_beginning_of_history }, - { "end-of-history", rl_end_of_history }, - { "self-insert", rl_insert }, - { "start-kbd-macro", rl_start_kbd_macro }, - { "end-kbd-macro", rl_end_kbd_macro }, - { "re-read-init-file", rl_re_read_init_file }, -#ifdef VI_MODE - { "vi-movement-mode", rl_vi_movement_mode }, - { "vi-insertion-mode", rl_vi_insertion_mode }, - { "vi-arg-digit", rl_vi_arg_digit }, - { "vi-prev-word", rl_vi_prev_word }, - { "vi-next-word", rl_vi_next_word }, - { "vi-char-search", rl_vi_char_search }, - { "vi-editing-mode", rl_vi_editing_mode }, - { "vi-eof-maybe", rl_vi_eof_maybe }, - { "vi-append-mode", rl_vi_append_mode }, - { "vi-put", rl_vi_put }, - { "vi-append-eol", rl_vi_append_eol }, - { "vi-insert-beg", rl_vi_insert_beg }, - { "vi-delete", rl_vi_delete }, - { "vi-comment", rl_vi_comment }, - { "vi-first-print", rl_vi_first_print }, - { "vi-fword", rl_vi_fword }, - { "vi-fWord", rl_vi_fWord }, - { "vi-bword", rl_vi_bword }, - { "vi-bWord", rl_vi_bWord }, - { "vi-eword", rl_vi_eword }, - { "vi-eWord", rl_vi_eWord }, - { "vi-end-word", rl_vi_end_word }, - { "vi-change-case", rl_vi_change_case }, - { "vi-match", rl_vi_match }, - { "vi-bracktype", rl_vi_bracktype }, - { "vi-change-char", rl_vi_change_char }, - { "vi-yank-arg", rl_vi_yank_arg }, - { "vi-search", rl_vi_search }, - { "vi-search-again", rl_vi_search_again }, - { "vi-dosearch", rl_vi_dosearch }, - { "vi-subst", rl_vi_subst }, - { "vi-overstrike", rl_vi_overstrike }, - { "vi-overstrike-delete", rl_vi_overstrike_delete }, - { "vi-replace, ", rl_vi_replace }, - { "vi-column", rl_vi_column }, - { "vi-delete-to", rl_vi_delete_to }, - { "vi-change-to", rl_vi_change_to }, - { "vi-yank-to", rl_vi_yank_to }, - { "vi-complete", rl_vi_complete }, -#endif /* VI_MODE */ - - {(char *)NULL, (Function *)NULL } -}; - -rl_add_funmap_entry (name, function) - char *name; - Function *function; -{ - if (funmap_entry + 2 >= funmap_size) - if (!funmap) - funmap = (FUNMAP **)xmalloc ((funmap_size = 80) * sizeof (FUNMAP *)); - else - funmap = - (FUNMAP **)xrealloc (funmap, (funmap_size += 80) * sizeof (FUNMAP *)); - - funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP)); - funmap[funmap_entry]->name = name; - funmap[funmap_entry]->function = function; - - funmap[++funmap_entry] = (FUNMAP *)NULL; -} - -static int funmap_initialized = 0; - -/* Make the funmap contain all of the default entries. */ -rl_initialize_funmap () -{ - register int i; - - if (funmap_initialized) - return; - - for (i = 0; default_funmap[i].name; i++) - rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function); - - funmap_initialized = 1; -} - -/* Things that mean `Control'. */ -char *possible_control_prefixes[] = { - "Control-", "C-", "CTRL-", (char *)NULL -}; - -char *possible_meta_prefixes[] = { - "Meta", "M-", (char *)NULL -}; - -#ifdef STATIC_MALLOC - -/* **************************************************************** */ -/* */ -/* xmalloc and xrealloc () */ -/* */ -/* **************************************************************** */ - -static char * -xmalloc (bytes) - int bytes; -{ - static memory_error_and_abort (); - char *temp = (char *)malloc (bytes); - - if (!temp) - memory_error_and_abort (); - return (temp); -} - -static char * -xrealloc (pointer, bytes) - char *pointer; - int bytes; -{ - static memory_error_and_abort (); - char *temp = (char *)realloc (pointer, bytes); - - if (!temp) - memory_error_and_abort (); - return (temp); -} - -static -memory_error_and_abort () -{ - fprintf (stderr, "history: Out of virtual memory!\n"); - abort (); -} -#endif /* STATIC_MALLOC */ diff --git a/gnu/usr.bin/gdb/readline/history.c b/gnu/usr.bin/gdb/readline/history.c deleted file mode 100644 index 7087718..0000000 --- a/gnu/usr.bin/gdb/readline/history.c +++ /dev/null @@ -1,1462 +0,0 @@ -/* History.c -- standalone history library */ - -/* Copyright (C) 1989 Free Software Foundation, Inc. - - This file contains the GNU History Library (the Library), a set of - routines for managing the text of previously typed lines. - - The Library 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 1, or (at your option) - any later version. - - The Library 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. - - The GNU General Public License is often shipped with GNU software, and - is generally kept in a file called COPYING or LICENSE. If you do not - have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* The goal is to make the implementation transparent, so that you - don't have to know what data types are used, just what functions - you can call. I think I have done that. */ - -/* Remove these declarations when we have a complete libgnu.a. */ -#define STATIC_MALLOC -#ifndef STATIC_MALLOC -extern char *xmalloc (), *xrealloc (); -#else -static char *xmalloc (), *xrealloc (); -#endif - -#include - -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else -#if defined (sparc) && defined (sun) -#include -#else -extern char *alloca (); -#endif -#endif - -#include "history.h" - -#ifndef savestring -#define savestring(x) (char *)strcpy (xmalloc (1 + strlen (x)), (x)) -#endif - -#ifndef whitespace -#define whitespace(c) (((c) == ' ') || ((c) == '\t')) -#endif - -#ifndef digit -#define digit(c) ((c) >= '0' && (c) <= '9') -#endif - -#ifndef member -#define member(c, s) ((c) ? index ((s), (c)) : 0) -#endif - -/* **************************************************************** */ -/* */ -/* History functions */ -/* */ -/* **************************************************************** */ - -/* An array of HIST_ENTRY. This is where we store the history. */ -static HIST_ENTRY **the_history = (HIST_ENTRY **)NULL; - -/* Non-zero means that we have enforced a limit on the amount of - history that we save. */ -static int history_stifled = 0; - -/* If HISTORY_STIFLED is non-zero, then this is the maximum number of - entries to remember. */ -static int max_input_history; - -/* The current location of the interactive history pointer. Just makes - life easier for outside callers. */ -static int history_offset = 0; - -/* The number of strings currently stored in the input_history list. */ -static int history_length = 0; - -/* The current number of slots allocated to the input_history. */ -static int history_size = 0; - -/* The number of slots to increase the_history by. */ -#define DEFAULT_HISTORY_GROW_SIZE 50 - -/* The character that represents the start of a history expansion - request. This is usually `!'. */ -char history_expansion_char = '!'; - -/* The character that invokes word substitution if found at the start of - a line. This is usually `^'. */ -char history_subst_char = '^'; - -/* During tokenization, if this character is seen as the first character - of a word, then it, and all subsequent characters upto a newline are - ignored. For a Bourne shell, this should be '#'. Bash special cases - the interactive comment character to not be a comment delimiter. */ -char history_comment_char = '\0'; - -/* The list of characters which inhibit the expansion of text if found - immediately following history_expansion_char. */ -char *history_no_expand_chars = " \t\n\r="; - -/* The logical `base' of the history array. It defaults to 1. */ -int history_base = 1; - -/* Begin a session in which the history functions might be used. This - initializes interactive variables. */ -void -using_history () -{ - history_offset = history_length; -} - -/* Place STRING at the end of the history list. The data field - is set to NULL. */ -void -add_history (string) - char *string; -{ - HIST_ENTRY *temp; - - if (history_stifled && (history_length == max_input_history)) { - register int i; - - /* If the history is stifled, and history_length is zero, - and it equals max_input_history, we don't save items. */ - if (!history_length) - return; - - /* If there is something in the slot, then remove it. */ - if (the_history[0]) { - free (the_history[0]->line); - free (the_history[0]); - } - - for (i = 0; i < history_length; i++) - the_history[i] = the_history[i + 1]; - - history_base++; - - } else { - - if (!history_size) { - the_history = - (HIST_ENTRY **)xmalloc ((history_size = DEFAULT_HISTORY_GROW_SIZE) - * sizeof (HIST_ENTRY *)); - history_length = 1; - - } else { - if (history_length == (history_size - 1)) { - the_history = - (HIST_ENTRY **)xrealloc (the_history, - ((history_size += DEFAULT_HISTORY_GROW_SIZE) - * sizeof (HIST_ENTRY *))); - } - history_length++; - } - } - - temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); - temp->line = savestring (string); - temp->data = (char *)NULL; - - the_history[history_length] = (HIST_ENTRY *)NULL; - the_history[history_length - 1] = temp; -} - -/* Make the history entry at WHICH have LINE and DATA. This returns - the old entry so you can dispose of the data. In the case of an - invalid WHICH, a NULL pointer is returned. */ -HIST_ENTRY * -replace_history_entry (which, line, data) - int which; - char *line; - char *data; -{ - HIST_ENTRY *temp = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); - HIST_ENTRY *old_value; - - if (which >= history_length) - return ((HIST_ENTRY *)NULL); - - old_value = the_history[which]; - - temp->line = savestring (line); - temp->data = data; - the_history[which] = temp; - - return (old_value); -} - -/* Returns the magic number which says what history element we are - looking at now. In this implementation, it returns history_offset. */ -int -where_history () -{ - return (history_offset); -} - -/* Search the history for STRING, starting at history_offset. - If DIRECTION < 0, then the search is through previous entries, - else through subsequent. If the string is found, then - current_history () is the history entry, and the value of this function - is the offset in the line of that history entry that the string was - found in. Otherwise, nothing is changed, and a -1 is returned. */ -int -history_search (string, direction) - char *string; - int direction; -{ - register int i = history_offset; - register int reverse = (direction < 0); - register char *line; - register int index; - int string_len = strlen (string); - - /* Take care of trivial cases first. */ - - if (!history_length || (i == history_length) && !reverse) - return (-1); - - if (reverse && (i == history_length)) - i--; - - while (1) - { - /* Search each line in the history list for STRING. */ - - /* At limit for direction? */ - if ((reverse && i < 0) || - (!reverse && i == history_length)) - return (-1); - - line = the_history[i]->line; - index = strlen (line); - - /* If STRING is longer than line, no match. */ - if (string_len > index) - goto next_line; - - /* Do the actual search. */ - if (reverse) - { - index -= string_len; - - while (index >= 0) - { - if (strncmp (string, line + index, string_len) == 0) - { - history_offset = i; - return (index); - } - index--; - } - } - else - { - register int limit = (string_len - index) + 1; - index = 0; - - while (index < limit) - { - if (strncmp (string, line + index, string_len) == 0) - { - history_offset = i; - return (index); - } - index++; - } - } - next_line: - if (reverse) - i--; - else - i++; - } -} - -/* Remove history element WHICH from the history. The removed - element is returned to you so you can free the line, data, - and containing structure. */ -HIST_ENTRY * -remove_history (which) - int which; -{ - HIST_ENTRY *return_value; - - if (which >= history_length || !history_length) - return_value = (HIST_ENTRY *)NULL; - else - { - register int i; - return_value = the_history[which]; - - for (i = which; i < history_length; i++) - the_history[i] = the_history[i + 1]; - - history_length--; - } - return (return_value); -} - -/* Stifle the history list, remembering only MAX number of lines. */ -void -stifle_history (max) - int max; -{ - if (history_length > max) - { - register int i, j; - - /* This loses because we cannot free the data. */ - for (i = 0; i < (history_length - max); i++) - { - free (the_history[i]->line); - free (the_history[i]); - } - history_base = i; - for (j = 0, i = history_length - max; j < max; i++, j++) - the_history[j] = the_history[i]; - the_history[j] = (HIST_ENTRY *)NULL; - history_length = j; - } - history_stifled = 1; - max_input_history = max; -} - -/* Stop stifling the history. This returns the previous amount the history - was stifled by. The value is positive if the history was stifled, negative - if it wasn't. */ -int -unstifle_history () -{ - int result = max_input_history; - if (history_stifled) - { - result = - result; - history_stifled = 0; - } - return (result); -} - -/* Return the string that should be used in the place of this - filename. This only matters when you don't specify the - filename to read_history (), or write_history (). */ -static char * -history_filename (filename) - char *filename; -{ - char *return_val = filename ? savestring (filename) : (char *)NULL; - - if (!return_val) - { - char *home = (char *)getenv ("HOME"); - if (!home) home = "."; - return_val = (char *)xmalloc (2 + strlen (home) + strlen (".history")); - strcpy (return_val, home); - strcat (return_val, "/"); - strcat (return_val, ".history"); - } - return (return_val); -} - -/* What to use until the line gets too big. */ -#define TYPICAL_LINE_SIZE 2048 - -/* Add the contents of FILENAME to the history list, a line at a time. - If FILENAME is NULL, then read from ~/.history. Returns 0 if - successful, or errno if not. */ -int -read_history (filename) - char *filename; -{ - char *input = history_filename (filename); - FILE *file = fopen (input, "r"); - char *line = (char *)xmalloc (TYPICAL_LINE_SIZE); - int line_size = TYPICAL_LINE_SIZE; - int done = 0; - - if (!file) - { - extern int errno; - free (line); - return (errno); - } - - while (!done) - { - int c; - int i; - - i = 0; - while (!(done = ((c = getc (file)) == EOF))) - { - if (c == '\n') - break; - - line [i++] = c; - if (i == line_size) - line = (char *)xrealloc (line, line_size += TYPICAL_LINE_SIZE); - } - line[i] = '\0'; - if (line[0]) - add_history (line); - } - free (line); - fclose (file); - return (0); -} - -/* Overwrite FILENAME with the current history. If FILENAME is NULL, - then write the history list to ~/.history. Values returned - are as in read_history ().*/ -int -write_history (filename) - char *filename; -{ - extern int errno; - char *output = history_filename (filename); - FILE *file = fopen (output, "w"); - register int i; - - if (!file) return (errno); - if (!history_length) return (0); - - for (i = 0; i < history_length; i++) - fprintf (file, "%s\n", the_history[i]->line); - - fclose (file); - return (0); -} - -/* Return the history entry at the current position, as determined by - history_offset. If there is no entry there, return a NULL pointer. */ -HIST_ENTRY * -current_history () -{ - if ((history_offset == history_length) || !the_history) - return ((HIST_ENTRY *)NULL); - else - return (the_history[history_offset]); -} - -/* Back up history_offset to the previous history entry, and return - a pointer to that entry. If there is no previous entry then return - a NULL pointer. */ -HIST_ENTRY * -previous_history () -{ - if (!history_offset) - return ((HIST_ENTRY *)NULL); - else - return (the_history[--history_offset]); -} - -/* Move history_offset forward to the next history entry, and return - a pointer to that entry. If there is no next entry then return a - NULL pointer. */ -HIST_ENTRY * -next_history () -{ - if (history_offset == history_length) - return ((HIST_ENTRY *)NULL); - else - return (the_history[++history_offset]); -} - -/* Return the current history array. The caller has to be carefull, since this - is the actual array of data, and could be bashed or made corrupt easily. - The array is terminated with a NULL pointer. */ -HIST_ENTRY ** -history_list () -{ - return (the_history); -} - -/* Return the history entry which is logically at OFFSET in the history array. - OFFSET is relative to history_base. */ -HIST_ENTRY * -history_get (offset) - int offset; -{ - int index = offset - history_base; - - if (index >= history_length || - index < 0 || - !the_history) - return ((HIST_ENTRY *)NULL); - return (the_history[index]); -} - -/* Search for STRING in the history list. DIR is < 0 for searching - backwards. POS is an absolute index into the history list at - which point to begin searching. */ -int -history_search_pos (string, dir, pos) - char *string; - int dir, pos; -{ - int ret, old = where_history (); - history_set_pos (pos); - if (history_search (string, dir) == -1) - { - history_set_pos (old); - return (-1); - } - ret = where_history (); - history_set_pos (old); - return ret; -} - -/* Make the current history item be the one at POS, an absolute index. - Returns zero if POS is out of range, else non-zero. */ -int -history_set_pos (pos) - int pos; -{ - if (pos > history_length || pos < 0 || !the_history) - return (0); - history_offset = pos; - return (1); -} - - -/* **************************************************************** */ -/* */ -/* History Expansion */ -/* */ -/* **************************************************************** */ - -/* Hairy history expansion on text, not tokens. This is of general - use, and thus belongs in this library. */ - -/* The last string searched for in a !?string? search. */ -static char *search_string = (char *)NULL; - -/* Return the event specified at TEXT + OFFSET modifying OFFSET to - point to after the event specifier. Just a pointer to the history - line is returned; NULL is returned in the event of a bad specifier. - You pass STRING with *INDEX equal to the history_expansion_char that - begins this specification. - DELIMITING_QUOTE is a character that is allowed to end the string - specification for what to search for in addition to the normal - characters `:', ` ', `\t', `\n', and sometimes `?'. - So you might call this function like: - line = get_history_event ("!echo:p", &index, 0); */ -char * -get_history_event (string, caller_index, delimiting_quote) - char *string; - int *caller_index; - int delimiting_quote; -{ - register int i = *caller_index; - int which, sign = 1; - HIST_ENTRY *entry; - - /* The event can be specified in a number of ways. - - !! the previous command - !n command line N - !-n current command-line minus N - !str the most recent command starting with STR - !?str[?] - the most recent command containing STR - - All values N are determined via HISTORY_BASE. */ - - if (string[i] != history_expansion_char) - return ((char *)NULL); - - /* Move on to the specification. */ - i++; - - /* Handle !! case. */ - if (string[i] == history_expansion_char) - { - i++; - which = history_base + (history_length - 1); - *caller_index = i; - goto get_which; - } - - /* Hack case of numeric line specification. */ - read_which: - if (string[i] == '-') - { - sign = -1; - i++; - } - - if (digit (string[i])) - { - int start = i; - - /* Get the extent of the digits. */ - for (; digit (string[i]); i++); - - /* Get the digit value. */ - sscanf (string + start, "%d", &which); - - *caller_index = i; - - if (sign < 0) - which = (history_length + history_base) - which; - - get_which: - if (entry = history_get (which)) - return (entry->line); - - return ((char *)NULL); - } - - /* This must be something to search for. If the spec begins with - a '?', then the string may be anywhere on the line. Otherwise, - the string must be found at the start of a line. */ - { - int index; - char *temp; - int substring_okay = 0; - - if (string[i] == '?') - { - substring_okay++; - i++; - } - - for (index = i; string[i]; i++) - if (whitespace (string[i]) || - string[i] == '\n' || - string[i] == ':' || - (substring_okay && string[i] == '?') || - string[i] == delimiting_quote) - break; - - temp = (char *)alloca (1 + (i - index)); - strncpy (temp, &string[index], (i - index)); - temp[i - index] = '\0'; - - if (string[i] == '?') - i++; - - *caller_index = i; - - search_again: - - index = history_search (temp, -1); - - if (index < 0) - search_lost: - { - history_offset = history_length; - return ((char *)NULL); - } - - if (index == 0 || substring_okay || - (strncmp (temp, the_history[history_offset]->line, - strlen (temp)) == 0)) - { - search_won: - entry = current_history (); - history_offset = history_length; - - /* If this was a substring search, then remember the string that - we matched for word substitution. */ - if (substring_okay) - { - if (search_string) - free (search_string); - search_string = savestring (temp); - } - - return (entry->line); - } - - if (history_offset) - history_offset--; - else - goto search_lost; - - goto search_again; - } -} - -/* Expand the string STRING, placing the result into OUTPUT, a pointer - to a string. Returns: - - 0) If no expansions took place (or, if the only change in - the text was the de-slashifying of the history expansion - character) - 1) If expansions did take place - -1) If there was an error in expansion. - - If an error ocurred in expansion, then OUTPUT contains a descriptive - error message. */ -int -history_expand (string, output) - char *string; - char **output; -{ - register int j, l = strlen (string); - int i, word_spec_error = 0; - int cc, modified = 0; - char *word_spec, *event; - int starting_index, only_printing = 0, substitute_globally = 0; - - char *get_history_word_specifier (), *rindex (); - - /* The output string, and its length. */ - int len = 0; - char *result = (char *)NULL; - - /* Used in add_string; */ - char *temp, tt[2], tbl[3]; - - /* Prepare the buffer for printing error messages. */ - result = (char *)xmalloc (len = 255); - - result[0] = tt[1] = tbl[2] = '\0'; - tbl[0] = '\\'; - tbl[1] = history_expansion_char; - - /* Grovel the string. Only backslash can quote the history escape - character. We also handle arg specifiers. */ - - /* Before we grovel forever, see if the history_expansion_char appears - anywhere within the text. */ - - /* The quick substitution character is a history expansion all right. That - is to say, "^this^that^" is equivalent to "!!:s^this^that^", and in fact, - that is the substitution that we do. */ - if (string[0] == history_subst_char) - { - char *format_string = (char *)alloca (10 + strlen (string)); - - sprintf (format_string, "%c%c:s%s", - history_expansion_char, history_expansion_char, - string); - string = format_string; - l += 4; - goto grovel; - } - - /* If not quick substitution, still maybe have to do expansion. */ - - /* `!' followed by one of the characters in history_no_expand_chars - is NOT an expansion. */ - for (i = 0; string[i]; i++) - if (string[i] == history_expansion_char) - if (!string[i + 1] || member (string[i + 1], history_no_expand_chars)) - continue; - else - goto grovel; - - free (result); - *output = savestring (string); - return (0); - - grovel: - - for (i = j = 0; i < l; i++) - { - int tchar = string[i]; - if (tchar == history_expansion_char) - tchar = -3; - - switch (tchar) - { - case '\\': - if (string[i + 1] == history_expansion_char) - { - i++; - temp = tbl; - goto do_add; - } - else - goto add_char; - - /* case history_expansion_char: */ - case -3: - starting_index = i + 1; - cc = string[i + 1]; - - /* If the history_expansion_char is followed by one of the - characters in history_no_expand_chars, then it is not a - candidate for expansion of any kind. */ - if (member (cc, history_no_expand_chars)) - goto add_char; - - /* There is something that is listed as a `word specifier' in csh - documentation which means `the expanded text to this point'. - That is not a word specifier, it is an event specifier. */ - - if (cc == '#') - goto hack_pound_sign; - - /* If it is followed by something that starts a word specifier, - then !! is implied as the event specifier. */ - - if (member (cc, ":$*%^")) - { - char fake_s[2]; - int fake_i = 0; - i++; - fake_s[0] = fake_s[1] = history_expansion_char; - fake_s[2] = '\0'; - event = get_history_event (fake_s, &fake_i); - } - else - { - int quoted_search_delimiter = 0; - - /* If the character before this `!' is a double or single - quote, then this expansion takes place inside of the - quoted string. If we have to search for some text ("!foo"), - allow the delimiter to end the search string. */ - if (i && (string[i - 1] == '\'' || string[i - 1] == '"')) - quoted_search_delimiter = string[i - 1]; - - event = get_history_event (string, &i, quoted_search_delimiter); - } - - if (!event) - event_not_found: - { - int l = 1 + (i - starting_index); - - temp = (char *)alloca (1 + l); - strncpy (temp, string + starting_index, l); - temp[l - 1] = 0; - sprintf (result, "%s: %s.", temp, - word_spec_error ? "Bad word specifier" : "Event not found"); - error_exit: - *output = result; - return (-1); - } - - /* If a word specifier is found, then do what that requires. */ - starting_index = i; - - word_spec = get_history_word_specifier (string, event, &i); - - /* There is no such thing as a `malformed word specifier'. However, - it is possible for a specifier that has no match. In that case, - we complain. */ - if (word_spec == (char *)-1) - bad_word_spec: - { - word_spec_error++; - goto event_not_found; - } - - /* If no word specifier, than the thing of interest was the event. */ - if (!word_spec) - temp = event; - else - { - temp = (char *)alloca (1 + strlen (word_spec)); - strcpy (temp, word_spec); - free (word_spec); - } - - /* Perhaps there are other modifiers involved. Do what they say. */ - - hack_specials: - - if (string[i] == ':') - { - char *tstr; - - switch (string[i + 1]) - { - /* :p means make this the last executed line. So we - return an error state after adding this line to the - history. */ - case 'p': - only_printing++; - goto next_special; - - /* :t discards all but the last part of the pathname. */ - case 't': - tstr = rindex (temp, '/'); - if (tstr) - temp = ++tstr; - goto next_special; - - /* :h discards the last part of a pathname. */ - case 'h': - tstr = rindex (temp, '/'); - if (tstr) - *tstr = '\0'; - goto next_special; - - /* :r discards the suffix. */ - case 'r': - tstr = rindex (temp, '.'); - if (tstr) - *tstr = '\0'; - goto next_special; - - /* :e discards everything but the suffix. */ - case 'e': - tstr = rindex (temp, '.'); - if (tstr) - temp = tstr; - goto next_special; - - /* :s/this/that substitutes `this' for `that'. */ - /* :gs/this/that substitutes `this' for `that' globally. */ - case 'g': - if (string[i + 2] == 's') - { - i++; - substitute_globally = 1; - goto substitute; - } - else - - case 's': - substitute: - { - char *this, *that, *new_event; - int delimiter = 0; - int si, l_this, l_that, l_temp = strlen (temp); - - if (i + 2 < strlen (string)) - delimiter = string[i + 2]; - - if (!delimiter) - break; - - i += 3; - - /* Get THIS. */ - for (si = i; string[si] && string[si] != delimiter; si++); - l_this = (si - i); - this = (char *)alloca (1 + l_this); - strncpy (this, string + i, l_this); - this[l_this] = '\0'; - - i = si; - if (string[si]) - i++; - - /* Get THAT. */ - for (si = i; string[si] && string[si] != delimiter; si++); - l_that = (si - i); - that = (char *)alloca (1 + l_that); - strncpy (that, string + i, l_that); - that[l_that] = '\0'; - - i = si; - if (string[si]) i++; - - /* Ignore impossible cases. */ - if (l_this > l_temp) - goto cant_substitute; - - /* Find the first occurrence of THIS in TEMP. */ - si = 0; - for (; (si + l_this) <= l_temp; si++) - if (strncmp (temp + si, this, l_this) == 0) - { - new_event = - (char *)alloca (1 + (l_that - l_this) + l_temp); - strncpy (new_event, temp, si); - strncpy (new_event + si, that, l_that); - strncpy (new_event + si + l_that, - temp + si + l_this, - l_temp - (si + l_this)); - new_event[(l_that - l_this) + l_temp] = '\0'; - temp = new_event; - - if (substitute_globally) - { - si += l_that; - l_temp = strlen (temp); - substitute_globally++; - continue; - } - - goto hack_specials; - } - - cant_substitute: - - if (substitute_globally > 1) - { - substitute_globally = 0; - goto hack_specials; - } - - goto event_not_found; - } - - /* :# is the line so far. Note that we have to - alloca () it since RESULT could be realloc ()'ed - below in add_string. */ - case '#': - hack_pound_sign: - if (result) - { - temp = (char *)alloca (1 + strlen (result)); - strcpy (temp, result); - } - else - temp = ""; - - next_special: - i += 2; - goto hack_specials; - } - - } - /* Believe it or not, we have to back the pointer up by one. */ - --i; - goto add_string; - - /* A regular character. Just add it to the output string. */ - default: - add_char: - tt[0] = string[i]; - temp = tt; - goto do_add; - - add_string: - modified++; - - do_add: - j += strlen (temp); - while (j > len) - result = (char *)xrealloc (result, (len += 255)); - - strcpy (result + (j - strlen (temp)), temp); - } - } - - *output = result; - - if (only_printing) - { - add_history (result); - return (-1); - } - - return (modified != 0); -} - -/* Return a consed string which is the word specified in SPEC, and found - in FROM. NULL is returned if there is no spec. -1 is returned if - the word specified cannot be found. CALLER_INDEX is the offset in - SPEC to start looking; it is updated to point to just after the last - character parsed. */ -char * -get_history_word_specifier (spec, from, caller_index) - char *spec, *from; - int *caller_index; -{ - register int i = *caller_index; - int first, last; - int expecting_word_spec = 0; - char *history_arg_extract (); - - /* The range of words to return doesn't exist yet. */ - first = last = 0; - - /* If we found a colon, then this *must* be a word specification. If - it isn't, then it is an error. */ - if (spec[i] == ':') - i++, expecting_word_spec++; - - /* Handle special cases first. */ - - /* `%' is the word last searched for. */ - if (spec[i] == '%') - { - *caller_index = i + 1; - if (search_string) - return (savestring (search_string)); - else - return (savestring ("")); - } - - /* `*' matches all of the arguments, but not the command. */ - if (spec[i] == '*') - { - *caller_index = i + 1; - return (history_arg_extract (1, '$', from)); - } - - /* `$' is last arg. */ - if (spec[i] == '$') - { - *caller_index = i + 1; - return (history_arg_extract ('$', '$', from)); - } - - /* Try to get FIRST and LAST figured out. */ - if (spec[i] == '-' || spec[i] == '^') - { - first = 1; - goto get_last; - } - - get_first: - if (digit (spec[i]) && expecting_word_spec) - { - sscanf (spec + i, "%d", &first); - for (; digit (spec[i]); i++); - } - else - return ((char *)NULL); - - get_last: - if (spec[i] == '^') - { - i++; - last = 1; - goto get_args; - } - - if (spec[i] != '-') - { - last = first; - goto get_args; - } - - i++; - - if (digit (spec[i])) - { - sscanf (spec + i, "%d", &last); - for (; digit (spec[i]); i++); - } - else - if (spec[i] == '$') - { - i++; - last = '$'; - } - - get_args: - { - char *result = (char *)NULL; - - *caller_index = i; - - if (last >= first) - result = history_arg_extract (first, last, from); - - if (result) - return (result); - else - return ((char *)-1); - } -} - -/* Extract the args specified, starting at FIRST, and ending at LAST. - The args are taken from STRING. */ -char * -history_arg_extract (first, last, string) - int first, last; - char *string; -{ - register int i, len; - char *result = (char *)NULL; - int size = 0, offset = 0; - - char **history_tokenize (), **list; - - if (!(list = history_tokenize (string))) - return ((char *)NULL); - - for (len = 0; list[len]; len++); - - if (last == '$') - last = len - 1; - - if (first == '$') - first = len - 1; - - last++; - - if (first > len || last > len) - result = ((char *)NULL); - else { - for (i = first; i < last; i++) - { - int l = strlen (list[i]); - - if (!result) - result = (char *)xmalloc ((size = (2 + l))); - else - result = (char *)xrealloc (result, (size += (2 + l))); - strcpy (result + offset, list[i]); - offset += l; - if (i + 1 < last) - { - strcpy (result + offset, " "); - offset++; - } - } - } - - for (i = 0; i < len; i++) - free (list[i]); - - free (list); - - return (result); -} - -#define slashify_in_quotes "\\`\"$" - -/* Return an array of tokens, much as the shell might. The tokens are - parsed out of STRING. */ -char ** -history_tokenize (string) - char *string; -{ - char **result = (char **)NULL; - register int i, start, result_index, size; - int len; - - i = result_index = size = 0; - - /* Get a token, and stuff it into RESULT. The tokens are split - exactly where the shell would split them. */ - get_token: - - /* Skip leading whitespace. */ - for (; string[i] && whitespace(string[i]); i++); - - start = i; - - if (!string[i] || string[i] == history_comment_char) - return (result); - - if (member (string[i], "()\n")) { - i++; - goto got_token; - } - - if (member (string[i], "<>;&|")) { - int peek = string[i + 1]; - - if (peek == string[i]) { - if (peek == '<') { - if (string[1 + 2] == '-') - i++; - i += 2; - goto got_token; - } - - if (member (peek, ">:&|")) { - i += 2; - goto got_token; - } - } else { - if ((peek == '&' && - (string[i] == '>' || string[i] == '<')) || - ((peek == '>') && - (string[i] == '&'))) { - i += 2; - goto got_token; - } - } - i++; - goto got_token; - } - - /* Get word from string + i; */ - { - int delimiter = 0; - - if (member (string[i], "\"'`")) - delimiter = string[i++]; - - for (;string[i]; i++) { - - if (string[i] == '\\') { - - if (string[i + 1] == '\n') { - i++; - continue; - } else { - if (delimiter != '\'') - if ((delimiter != '"') || - (member (string[i], slashify_in_quotes))) { - i++; - continue; - } - } - } - - if (delimiter && string[i] == delimiter) { - delimiter = 0; - continue; - } - - if (!delimiter && (member (string[i], " \t\n;&()|<>"))) - goto got_token; - - if (!delimiter && member (string[i], "\"'`")) { - delimiter = string[i]; - continue; - } - } - got_token: - - len = i - start; - if (result_index + 2 >= size) { - if (!size) - result = (char **)xmalloc ((size = 10) * (sizeof (char *))); - else - result = - (char **)xrealloc (result, ((size += 10) * (sizeof (char *)))); - } - result[result_index] = (char *)xmalloc (1 + len); - strncpy (result[result_index], string + start, len); - result[result_index][len] = '\0'; - result_index++; - result[result_index] = (char *)NULL; - } - if (string[i]) - goto get_token; - - return (result); -} - -#ifdef STATIC_MALLOC - -/* **************************************************************** */ -/* */ -/* xmalloc and xrealloc () */ -/* */ -/* **************************************************************** */ - -static char * -xmalloc (bytes) - int bytes; -{ - static memory_error_and_abort (); - char *temp = (char *)malloc (bytes); - - if (!temp) - memory_error_and_abort (); - return (temp); -} - -static char * -xrealloc (pointer, bytes) - char *pointer; - int bytes; -{ - static memory_error_and_abort (); - char *temp = (char *)realloc (pointer, bytes); - - if (!temp) - memory_error_and_abort (); - return (temp); -} - -static -memory_error_and_abort () -{ - fprintf (stderr, "history: Out of virtual memory!\n"); - abort (); -} -#endif /* STATIC_MALLOC */ - - -/* **************************************************************** */ -/* */ -/* Test Code */ -/* */ -/* **************************************************************** */ -#ifdef TEST -main () -{ - char line[1024], *t; - int done = 0; - - line[0] = 0; - - while (!done) - { - fprintf (stdout, "history%% "); - t = gets (line); - - if (!t) - strcpy (line, "quit"); - - if (line[0]) - { - char *expansion; - int result; - - using_history (); - - result = history_expand (line, &expansion); - strcpy (line, expansion); - free (expansion); - if (result) - fprintf (stderr, "%s\n", line); - - if (result < 0) - continue; - - add_history (line); - } - - if (strcmp (line, "quit") == 0) done = 1; - if (strcmp (line, "save") == 0) write_history (0); - if (strcmp (line, "read") == 0) read_history (0); - if (strcmp (line, "list") == 0) - { - register HIST_ENTRY **the_list = history_list (); - register int i; - - if (the_list) - for (i = 0; the_list[i]; i++) - fprintf (stdout, "%d: %s\n", i + history_base, the_list[i]->line); - } - if (strncmp (line, "delete", strlen ("delete")) == 0) - { - int which; - if ((sscanf (line + strlen ("delete"), "%d", &which)) == 1) - { - HIST_ENTRY *entry = remove_history (which); - if (!entry) - fprintf (stderr, "No such entry %d\n", which); - else - { - free (entry->line); - free (entry); - } - } - else - { - fprintf (stderr, "non-numeric arg given to `delete'\n"); - } - } - } -} - -#endif /* TEST */ - -/* -* Local variables: -* compile-command: "gcc -g -DTEST -o history history.c" -* end: -*/ diff --git a/gnu/usr.bin/gdb/readline/history.h b/gnu/usr.bin/gdb/readline/history.h deleted file mode 100644 index 0bac209..0000000 --- a/gnu/usr.bin/gdb/readline/history.h +++ /dev/null @@ -1,108 +0,0 @@ -/* History.h -- the names of functions that you can call in history. */ - -typedef struct _hist_entry { - char *line; - char *data; -} HIST_ENTRY; - -/* For convenience only. You set this when interpreting history commands. - It is the logical offset of the first history element. */ -extern int history_base; - -/* Begin a session in which the history functions might be used. This - just initializes the interactive variables. */ -extern void using_history (); - -/* Place STRING at the end of the history list. - The associated data field (if any) is set to NULL. */ -extern void add_history (); - -/* Returns the number which says what history element we are now - looking at. */ -extern int where_history (); - -/* Set the position in the history list to POS. */ -int history_set_pos (); - -/* Search for STRING in the history list, starting at POS, an - absolute index into the list. DIR, if negative, says to search - backwards from POS, else forwards. - Returns the absolute index of the history element where STRING - was found, or -1 otherwise. */ -extern int history_search_pos (); - -/* A reasonably useless function, only here for completeness. WHICH - is the magic number that tells us which element to delete. The - elements are numbered from 0. */ -extern HIST_ENTRY *remove_history (); - -/* Stifle the history list, remembering only MAX number of entries. */ -extern void stifle_history (); - -/* Stop stifling the history. This returns the previous amount the - history was stifled by. The value is positive if the history was - stifled, negative if it wasn't. */ -extern int unstifle_history (); - -/* Add the contents of FILENAME to the history list, a line at a time. - If FILENAME is NULL, then read from ~/.history. Returns 0 if - successful, or errno if not. */ -extern int read_history (); - -/* Append the current history to FILENAME. If FILENAME is NULL, - then append the history list to ~/.history. Values returned - are as in read_history (). */ -extern int write_history (); - - -/* Make the history entry at WHICH have LINE and DATA. This returns - the old entry so you can dispose of the data. In the case of an - invalid WHICH, a NULL pointer is returned. */ -extern HIST_ENTRY *replace_history_entry (); - -/* Return the history entry at the current position, as determined by - history_offset. If there is no entry there, return a NULL pointer. */ -HIST_ENTRY *current_history (); - -/* Back up history_offset to the previous history entry, and return - a pointer to that entry. If there is no previous entry, return - a NULL pointer. */ -extern HIST_ENTRY *previous_history (); - -/* Move history_offset forward to the next item in the input_history, - and return the a pointer to that entry. If there is no next entry, - return a NULL pointer. */ -extern HIST_ENTRY *next_history (); - -/* Return a NULL terminated array of HIST_ENTRY which is the current input - history. Element 0 of this list is the beginning of time. If there - is no history, return NULL. */ -extern HIST_ENTRY **history_list (); - -/* Search the history for STRING, starting at history_offset. - If DIRECTION < 0, then the search is through previous entries, - else through subsequent. If the string is found, then - current_history () is the history entry, and the value of this function - is the offset in the line of that history entry that the string was - found in. Otherwise, nothing is changed, and a -1 is returned. */ -extern int history_search (); - -/* Expand the string STRING, placing the result into OUTPUT, a pointer - to a string. Returns: - - 0) If no expansions took place (or, if the only change in - the text was the de-slashifying of the history expansion - character) - 1) If expansions did take place - -1) If there was an error in expansion. - - If an error ocurred in expansion, then OUTPUT contains a descriptive - error message. */ -extern int history_expand (); - -/* Extract a string segment consisting of the FIRST through LAST - arguments present in STRING. Arguments are broken up as in - the shell. */ -extern char *history_arg_extract (); - - diff --git a/gnu/usr.bin/gdb/readline/keymaps.c b/gnu/usr.bin/gdb/readline/keymaps.c deleted file mode 100644 index e0c5e39..0000000 --- a/gnu/usr.bin/gdb/readline/keymaps.c +++ /dev/null @@ -1,172 +0,0 @@ -/* keymaps.c -- Functions and keymaps for the GNU Readline library. */ - -/* Copyright (C) 1988,1989 Free Software Foundation, Inc. - - This file is part of GNU Readline, a library for reading lines - of text with interactive input and history editing. - - Readline 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 1, or (at your option) any - later version. - - Readline 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 Readline; see the file COPYING. If not, write to the Free - Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "keymaps.h" -#include "emacs_keymap.c" - -#ifdef VI_MODE -#include "vi_keymap.c" -#endif - -/* Remove these declarations when we have a complete libgnu.a. */ -#define STATIC_MALLOC -#ifndef STATIC_MALLOC -extern char *xmalloc (), *xrealloc (); -#else -static char *xmalloc (), *xrealloc (); -#endif - -/* **************************************************************** */ -/* */ -/* Functions for manipulating Keymaps. */ -/* */ -/* **************************************************************** */ - - -/* Return a new, empty keymap. - Free it with free() when you are done. */ -Keymap -rl_make_bare_keymap () -{ - register int i; - Keymap keymap = (Keymap)xmalloc (128 * sizeof (KEYMAP_ENTRY)); - - for (i = 0; i < 128; i++) - { - keymap[i].type = ISFUNC; - keymap[i].function = (Function *)NULL; - } - - for (i = 'A'; i < ('Z' + 1); i++) - { - keymap[i].type = ISFUNC; - keymap[i].function = rl_do_lowercase_version; - } - - return (keymap); -} - -/* Return a new keymap which is a copy of MAP. */ -Keymap -rl_copy_keymap (map) - Keymap map; -{ - register int i; - Keymap temp = rl_make_bare_keymap (); - - for (i = 0; i < 128; i++) - { - temp[i].type = map[i].type; - temp[i].function = map[i].function; - } - return (temp); -} - -/* Return a new keymap with the printing characters bound to rl_insert, - the uppercase Meta characters bound to run their lowercase equivalents, - and the Meta digits bound to produce numeric arguments. */ -Keymap -rl_make_keymap () -{ - extern rl_insert (), rl_rubout (), rl_do_lowercase_version (); - extern rl_digit_argument (); - register int i; - Keymap newmap; - - newmap = rl_make_bare_keymap (); - - /* All printing characters are self-inserting. */ - for (i = ' '; i < 126; i++) - newmap[i].function = rl_insert; - - newmap[TAB].function = rl_insert; - newmap[RUBOUT].function = rl_rubout; - - return (newmap); -} - -/* Free the storage associated with MAP. */ -rl_discard_keymap (map) - Keymap (map); -{ - int i; - - if (!map) - return; - - for (i = 0; i < 128; i++) - { - switch (map[i].type) - { - case ISFUNC: - break; - - case ISKMAP: - rl_discard_keymap ((Keymap)map[i].function); - break; - - case ISMACR: - free ((char *)map[i].function); - break; - } - } -} - -#ifdef STATIC_MALLOC - -/* **************************************************************** */ -/* */ -/* xmalloc and xrealloc () */ -/* */ -/* **************************************************************** */ - -static char * -xmalloc (bytes) - int bytes; -{ - static memory_error_and_abort (); - char *temp = (char *)malloc (bytes); - - if (!temp) - memory_error_and_abort (); - return (temp); -} - -static char * -xrealloc (pointer, bytes) - char *pointer; - int bytes; -{ - static memory_error_and_abort (); - char *temp = (char *)realloc (pointer, bytes); - - if (!temp) - memory_error_and_abort (); - return (temp); -} - -static -memory_error_and_abort () -{ - fprintf (stderr, "readline: Out of virtual memory!\n"); - abort (); -} -#endif /* STATIC_MALLOC */ diff --git a/gnu/usr.bin/gdb/readline/keymaps.h b/gnu/usr.bin/gdb/readline/keymaps.h deleted file mode 100644 index 3c577b3..0000000 --- a/gnu/usr.bin/gdb/readline/keymaps.h +++ /dev/null @@ -1,53 +0,0 @@ -/* keymaps.h -- Manipulation of readline keymaps. */ - -#ifndef _KEYMAPS_H_ -#define _KEYMAPS_H_ - -#include - -#ifndef __FUNCTION_DEF -typedef int Function (); -#define __FUNCTION_DEF -#endif - -/* A keymap contains one entry for each key in the ASCII set. - Each entry consists of a type and a pointer. - POINTER is the address of a function to run, or the - address of a keymap to indirect through. - TYPE says which kind of thing POINTER is. */ -typedef struct _keymap_entry { - char type; - Function *function; -} KEYMAP_ENTRY; - -/* I wanted to make the above structure contain a union of: - union { Function *function; struct _keymap_entry *keymap; } value; - but this made it impossible for me to create a static array. - Maybe I need C lessons. */ - -typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[128]; -typedef KEYMAP_ENTRY *Keymap; - -/* The values that TYPE can have in a keymap entry. */ -#define ISFUNC 0 -#define ISKMAP 1 -#define ISMACR 2 - -extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap, emacs_meta_keymap, emacs_ctlx_keymap; -extern KEYMAP_ENTRY_ARRAY vi_insertion_keymap, vi_movement_keymap; - -/* Return a new, empty keymap. - Free it with free() when you are done. */ -Keymap rl_make_bare_keymap (); - -/* Return a new keymap which is a copy of MAP. */ -Keymap rl_copy_keymap (); - -/* Return a new keymap with the printing characters bound to rl_insert, - the lowercase Meta characters bound to run their equivalents, and - the Meta digits bound to produce numeric arguments. */ -Keymap rl_make_keymap (); - -#endif /* _KEYMAPS_H_ */ - - diff --git a/gnu/usr.bin/gdb/readline/readline.c b/gnu/usr.bin/gdb/readline/readline.c deleted file mode 100644 index 3e8f9a3..0000000 --- a/gnu/usr.bin/gdb/readline/readline.c +++ /dev/null @@ -1,5557 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)readline.c 6.4 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* readline.c -- a general facility for reading lines of input - with emacs style editing and completion. */ - -/* Copyright (C) 1987,1989 Free Software Foundation, Inc. - - This file contains the Readline Library (the Library), a set of - routines for providing Emacs style line input to programs that ask - for it. - - The Library 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 1, or (at your option) - any later version. - - The Library 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. - - The GNU General Public License is often shipped with GNU software, and - is generally kept in a file called COPYING or LICENSE. If you do not - have a copy of the license, write to the Free Software Foundation, - 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Remove these declarations when we have a complete libgnu.a. */ -#define STATIC_MALLOC -#ifndef STATIC_MALLOC -extern char *xmalloc (), *xrealloc (); -#else -static char *xmalloc (), *xrealloc (); -#endif - -#include -#include -#include -#include -#include -#include - -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else -#if defined (sparc) && defined (sun) -#include -#endif -#endif - -#define NEW_TTY_DRIVER -#if defined (SYSV) || defined (hpux) -#undef NEW_TTY_DRIVER -#include -#else -#include -#endif - -#include -extern int errno; - -#include - -/* These next are for filename completion. Perhaps this belongs - in a different place. */ -#include - -#include -#ifdef SYSV -struct passwd *getpwuid (), *getpwent (); -#endif - -#define HACK_TERMCAP_MOTION - -#ifndef SYSV -#include -#else /* SYSV */ -#ifdef hpux -#include -#else -#include -#define direct dirent -#define d_namlen d_reclen -#endif /* hpux */ -#endif /* SYSV */ - -/* Some standard library routines. */ -#include "readline.h" -#include "history.h" - -#ifndef digit -#define digit(c) ((c) >= '0' && (c) <= '9') -#endif - -#ifndef isletter -#define isletter(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z')) -#endif - -#ifndef digit_value -#define digit_value(c) ((c) - '0') -#endif - -#ifndef member -char *index (); -#define member(c, s) ((c) ? index ((s), (c)) : 0) -#endif - -#ifndef isident -#define isident(c) ((isletter(c) || digit(c) || c == '_')) -#endif - -#ifndef exchange -#define exchange(x, y) {int temp = x; x = y; y = temp;} -#endif - -static update_line (); -static void output_character_function (); -static delete_chars (); -static start_insert (); -static end_insert (); - -/* This typedef is equivalant to the one for Function; it allows us - to say SigHandler *foo = signal (SIGKILL, SIG_IGN); */ -typedef void SigHandler (); - -#ifdef SIGWINCH -static void rl_handle_sigwinch (); -static SigHandler *old_sigwinch = (SigHandler *)NULL; -#endif - -/* If on, then readline handles signals in a way that doesn't screw. */ -/* #define HANDLE_SIGNALS */ - -#if defined (SYSV) -#ifdef HANDLE_SIGNALS -#undef HANDLE_SIGNALS -#endif -#endif - -/* Stupid comparison routine for qsort () ing strings. */ -static int -compare_strings (s1, s2) - char **s1, **s2; -{ - return (strcmp (*s1, *s2)); -} - - -/* **************************************************************** */ -/* */ -/* Line editing input utility */ -/* */ -/* **************************************************************** */ - -/* A pointer to the keymap that is currently in use. - By default, it is the standard emacs keymap. */ -Keymap keymap = emacs_standard_keymap; - -#define vi_mode 0 -#define emacs_mode 1 - -/* The current style of editing. */ -int rl_editing_mode = emacs_mode; - -/* Non-zero if the previous command was a kill command. */ -static int last_command_was_kill = 0; - -/* The current value of the numeric argument specified by the user. */ -int rl_numeric_arg = 1; - -/* Non-zero if an argument was typed. */ -int rl_explicit_arg = 0; - -/* Temporary value used while generating the argument. */ -static int arg_sign = 1; - -/* Non-zero means we have been called at least once before. */ -static int rl_initialized = 0; - -/* If non-zero, this program is running in an EMACS buffer. */ -static char *running_in_emacs = (char *)NULL; - -/* The current offset in the current input line. */ -int rl_point; - -/* Mark in the current input line. */ -int rl_mark; - -/* Length of the current input line. */ -int rl_end; - -/* Make this non-zero to return the current input_line. */ -int rl_done; - -/* The last function executed by readline. */ -Function *rl_last_func = (Function *)NULL; - -/* Top level environment for readline_internal (). */ -static jmp_buf readline_top_level; - -/* The streams we interact with. */ -static FILE *in_stream, *out_stream; - -/* The names of the streams that we do input and output to. */ -FILE *rl_instream = stdin, *rl_outstream = stdout; - -/* Non-zero means echo characters as they are read. */ -int readline_echoing_p = 1; - -/* Current prompt. */ -char *rl_prompt; - -/* The number of characters read in order to type this complete command. */ -int rl_key_sequence_length = 0; - -/* If non-zero, then this is the address of a function to call just - before readline_internal () prints the first prompt. */ -Function *rl_startup_hook = (Function *)NULL; - -/* What we use internally. You should always refer to RL_LINE_BUFFER. */ -static char *the_line; - -/* The character that can generate an EOF. Really read from - the terminal driver... just defaulted here. */ -static int eof_char = CTRL ('D'); - -/* Non-zero makes this the next keystroke to read. */ -int rl_pending_input = 0; - -/* Pointer to a useful terminal name. */ -char *rl_terminal_name = (char *)NULL; - -/* Line buffer and maintenence. */ -char *rl_line_buffer = (char *)NULL; -static int rl_line_buffer_len = 0; -#define DEFAULT_BUFFER_SIZE 256 - - -/* **************************************************************** */ -/* */ -/* Top Level Functions */ -/* */ -/* **************************************************************** */ - -/* Read a line of input. Prompt with PROMPT. A NULL PROMPT means - none. A return value of NULL means that EOF was encountered. */ -char * -readline (prompt) - char *prompt; -{ - static rl_prep_terminal (), rl_deprep_terminal (); - char *readline_internal (); - char *value; - - rl_prompt = prompt; - - /* If we are at EOF return a NULL string. */ - if (rl_pending_input == EOF) - { - rl_pending_input = 0; - return ((char *)NULL); - } - - rl_initialize (); - rl_prep_terminal (); - -#ifdef SIGWINCH - old_sigwinch = (SigHandler *)signal (SIGWINCH, rl_handle_sigwinch); -#endif - -#ifdef HANDLE_SIGNALS - rl_set_signals (); -#endif - - value = readline_internal (); - rl_deprep_terminal (); - -#ifdef SIGWINCH - signal (SIGWINCH, old_sigwinch); -#endif - -#ifdef HANDLE_SIGNALS - rl_clear_signals (); -#endif - - return (value); -} - -/* Read a line of input from the global rl_instream, doing output on - the global rl_outstream. - If rl_prompt is non-null, then that is our prompt. */ -char * -readline_internal () -{ - int lastc, c, eof_found; - - in_stream = rl_instream; out_stream = rl_outstream; - lastc = eof_found = 0; - - if (rl_startup_hook) - (*rl_startup_hook) (); - - if (!readline_echoing_p) - { - if (rl_prompt) { - fprintf (out_stream, "%s", rl_prompt); - fflush(out_stream); - } - } - else - { - rl_on_new_line (); - rl_redisplay (); -#ifdef VI_MODE - if (rl_editing_mode == vi_mode) - rl_vi_insertion_mode (); -#endif /* VI_MODE */ - } - - while (!rl_done) - { - int lk = last_command_was_kill; - int code = setjmp (readline_top_level); - - if (code) - rl_redisplay (); - - if (!rl_pending_input) - { - /* Then initialize the argument and number of keys read. */ - rl_init_argument (); - rl_key_sequence_length = 0; - } - - c = rl_read_key (); - - /* EOF typed to a non-blank line is a . */ - if (c == EOF && rl_end) - c = NEWLINE; - - /* The character eof_char typed to blank line, and not as the - previous character is interpreted as EOF. */ - if (((c == eof_char && lastc != c) || c == EOF) && !rl_end) - { - eof_found = 1; - break; - } - - lastc = c; - rl_dispatch (c, keymap); - - /* If there was no change in last_command_was_kill, then no kill - has taken place. Note that if input is pending we are reading - a prefix command, so nothing has changed yet. */ - if (!rl_pending_input) - { - if (lk == last_command_was_kill) - last_command_was_kill = 0; - } - -#ifdef VI_MODE - /* In vi mode, when you exit insert mode, the cursor moves back - over the previous character. We explicitly check for that here. */ - if (rl_editing_mode == vi_mode && keymap == vi_movement_keymap) - rl_vi_check (); -#endif - - if (!rl_done) - rl_redisplay (); - } - - /* Restore the original of this history line, iff the line that we - are editing was originally in the history, AND the line has changed. */ - { - HIST_ENTRY *entry = current_history (); - - if (entry && rl_undo_list) - { - char *temp = savestring (the_line); - rl_revert_line (); - entry = replace_history_entry (where_history (), the_line, - (HIST_ENTRY *)NULL); - free_history_entry (entry); - - strcpy (the_line, temp); - free (temp); - } - } - - /* At any rate, it is highly likely that this line has an undo list. Get - rid of it now. */ - if (rl_undo_list) - free_undo_list (); - - if (eof_found) - return (char *)NULL; - else - return (savestring (the_line)); -} - - -/* Variables for keyboard macros. */ - -/* The currently executing macro string. If this is non-zero, - then it is a malloc ()'ed string where input is coming from. */ -static char *executing_macro = (char *)NULL; - -/* The offset in the above string to the next character to be read. */ -static int executing_macro_index = 0; - -/* Non-zero means to save keys that we dispatch on in a kbd macro. */ -static int defining_kbd_macro = 0; - -/* The current macro string being built. Characters get stuffed - in here by add_macro_char (). */ -static char *current_macro = (char *)NULL; - -/* The size of the buffer allocated to current_macro. */ -static int current_macro_size = 0; - -/* The index at which characters are being added to current_macro. */ -static int current_macro_index = 0; - -/* A structure used to save nested macro strings. - It is a linked list of string/index for each saved macro. */ -struct saved_macro { - struct saved_macro *next; - char *string; - int index; -}; - -/* The list of saved macros. */ -struct saved_macro *macro_list = (struct saved_macro *)NULL; - - -/* **************************************************************** */ -/* */ -/* Signal Handling */ -/* */ -/* **************************************************************** */ - -#ifdef SIGWINCH -static void -rl_handle_sigwinch (sig, code, scp) - int sig, code; - struct sigcontext *scp; -{ - char *term = rl_terminal_name, *getenv (); - - if (readline_echoing_p) - { - if (!term) - term = getenv ("TERM"); - if (!term) - term = "dumb"; - rl_reset_terminal (term); -#ifdef NEVER - crlf (); - rl_forced_update_display (); -#endif - } - - if (old_sigwinch && - old_sigwinch != (SigHandler *)SIG_IGN && - old_sigwinch != (SigHandler *)SIG_DFL) - (*old_sigwinch)(sig, code, scp); -} -#endif /* SIGWINCH */ - -#ifdef HANDLE_SIGNALS -/* Interrupt handling. */ -static SigHandler *old_int = (SigHandler *)NULL, - *old_tstp = (SigHandler *)NULL, - *old_ttou = (SigHandler *)NULL, - *old_ttin = (SigHandler *)NULL, - *old_cont = (SigHandler *)NULL; - -/* Handle an interrupt character. */ -static void -rl_signal_handler (sig, code, scp) - int sig, code; - struct sigcontext *scp; -{ - static rl_prep_terminal (), rl_deprep_terminal (); - - switch (sig) - { - case SIGINT: - free_undo_list (); - rl_clear_message (); - rl_init_argument (); -#ifdef SIGWINCH - signal (SIGWINCH, old_sigwinch); -#endif - -#ifdef SIGTSTP - case SIGTSTP: - case SIGTTOU: - case SIGTTIN: -#endif - - rl_clean_up_for_exit (); - rl_deprep_terminal (); - rl_clear_signals (); - rl_pending_input = 0; - - kill (getpid (), sig); - sigsetmask (0); - - rl_prep_terminal (); - rl_set_signals (); - } -} - -rl_set_signals () -{ - old_int = (SigHandler *)signal (SIGINT, rl_signal_handler); - - if (old_int == (SigHandler *)SIG_IGN) - signal (SIGINT, SIG_IGN); - -#ifdef SIGTSTP - old_tstp = (SigHandler *)signal (SIGTSTP, rl_signal_handler); - if (old_tstp == (SigHandler *)SIG_IGN) - signal (SIGTSTP, SIG_IGN); -#endif -#ifdef SIGTTOU - old_ttou = (SigHandler *)signal (SIGTTOU, rl_signal_handler); - old_ttin = (SigHandler *)signal (SIGTTIN, rl_signal_handler); -#endif -} - -rl_clear_signals () -{ - signal (SIGINT, old_int); - -#ifdef SIGTSTP - signal (SIGTSTP, old_tstp); -#endif -#ifdef SIGTTOU - signal (SIGTTOU, old_ttou); - signal (SIGTTIN, old_ttin); -#endif -} -#endif /* HANDLE_SIGNALS */ - - - -/* **************************************************************** */ -/* */ -/* Character Input Buffering */ -/* */ -/* **************************************************************** */ - -/* If the terminal was in xoff state when we got to it, then xon_char - contains the character that is supposed to start it again. */ -static int xon_char, xoff_state; -static int pop_index = 0, push_index = 0, ibuffer_len = 511; -static unsigned char ibuffer[512]; - -/* Non-null means it is a pointer to a function to run while waiting for - character input. */ -Function *rl_event_hook = (Function *)NULL; - -#define any_typein (push_index != pop_index) - -/* Add KEY to the buffer of characters to be read. */ -rl_stuff_char (key) - int key; -{ - if (key == EOF) - { - key = NEWLINE; - rl_pending_input = EOF; - } - ibuffer[push_index++] = key; - if (push_index >= ibuffer_len) - push_index = 0; -} - -/* Return the amount of space available in the - buffer for stuffing characters. */ -int -ibuffer_space () -{ - if (pop_index > push_index) - return (pop_index - push_index); - else - return (ibuffer_len - (push_index - pop_index)); -} - -/* Get a key from the buffer of characters to be read. - Result is KEY if there was a key, or -2 if there wasn't. */ -int -rl_get_char () -{ - int key; - - if (push_index == pop_index) - return (-2); - - key = ibuffer[pop_index++]; - - if (pop_index >= ibuffer_len) - pop_index = 0; - - return (key); -} - -/* Stuff KEY into the *front* of the input buffer. - Returns non-zero if successful, zero if there is - no space left in the buffer. */ -int -rl_unget_char (key) - int key; -{ - if (ibuffer_space ()) - { - pop_index--; - if (pop_index < 0) - pop_index = ibuffer_len - 1; - ibuffer[pop_index] = key; - return (1); - } - return (0); -} - - - -static void -rl_getc (stream) - FILE *stream; -{ - int result; - int nchar; - int tty = fileno(stream); - char buf[512]; /* XXX - must be at least as large as ibuffer */ - - while (1) - { - if (ioctl(tty, FIONREAD, &nchar) == -1) - nchar = sizeof(buf); - else if (nchar <= 0) - nchar = 1; - result = ibuffer_space(); - if (nchar > result) - nchar = result; - result = read(tty, buf, nchar); - if (result > 0) - { - register char *cp = buf; - - while (--result >= 0) - rl_stuff_char(*cp++); - return; - } - if (errno != EINTR) - { - rl_stuff_char(EOF); - return; - } - } -} - -/* Read a key, including pending input. */ -int -rl_read_key () -{ - int c; - - rl_key_sequence_length++; - - if (rl_pending_input) - { - c = rl_pending_input; - rl_pending_input = 0; - } - else - { - static int next_macro_key (); - - /* If input is coming from a macro, then use that. */ - if (c = next_macro_key ()) - return (c); - - while ((c = rl_get_char()) == -2) - { - if (rl_event_hook) - { - (*rl_event_hook) (); - if ((c = rl_get_char()) != -2) - return (c); - } - rl_getc(in_stream); - } - } -#ifdef TIOCSTART - /* Ugh. But I can't think of a better way. */ - if (xoff_state && c == xon_char) - { - ioctl (fileno (in_stream), TIOCSTART, 0); - xoff_state = 0; - return rl_read_key (); - } -#endif /* TIOCSTART */ - return (c); -} - -/* Do the command associated with KEY in MAP. - If the associated command is really a keymap, then read - another key, and dispatch into that map. */ -rl_dispatch (key, map) - register int key; - Keymap map; -{ - if (defining_kbd_macro) - { - static add_macro_char (); - - add_macro_char (key); - } - - if (key > 127 && key < 256) - { - if (map[ESC].type == ISKMAP) - { - map = (Keymap)map[ESC].function; - key -= 128; - rl_dispatch (key, map); - } - else - ding (); - return; - } - - switch (map[key].type) - { - case ISFUNC: - { - Function *func = map[key].function; - - if (func != (Function *)NULL) - { - /* Special case rl_do_lowercase_version (). */ - if (func == rl_do_lowercase_version) - { - rl_dispatch (to_lower (key), map); - return; - } - - (*map[key].function)(rl_numeric_arg * arg_sign, key); - } - else - { - ding (); - return; - } - } - break; - - case ISKMAP: - if (map[key].function != (Function *)NULL) - { - int newkey; - - rl_key_sequence_length++; - newkey = rl_read_key (); - rl_dispatch (newkey, (Keymap)map[key].function); - } - else - { - ding (); - return; - } - break; - - case ISMACR: - if (map[key].function != (Function *)NULL) - { - static with_macro_input (); - char *macro = savestring ((char *)map[key].function); - - with_macro_input (macro); - return; - } - break; - } - - /* If we have input pending, then the last command was a prefix - command. Don't change the state of rl_last_func. */ - if (!rl_pending_input) - rl_last_func = map[key].function; -} - - -/* **************************************************************** */ -/* */ -/* Hacking Keyboard Macros */ -/* */ -/* **************************************************************** */ - -/* Set up to read subsequent input from STRING. - STRING is free ()'ed when we are done with it. */ -static -with_macro_input (string) - char *string; -{ - static push_executing_macro (); - - push_executing_macro (); - executing_macro = string; - executing_macro_index = 0; -} - -/* Return the next character available from a macro, or 0 if - there are no macro characters. */ -static int -next_macro_key () -{ - if (!executing_macro) - return (0); - - if (!executing_macro[executing_macro_index]) - { - static pop_executing_macro (); - - pop_executing_macro (); - return (next_macro_key ()); - } - - return (executing_macro[executing_macro_index++]); -} - -/* Save the currently executing macro on a stack of saved macros. */ -static -push_executing_macro () -{ - struct saved_macro *saver; - - saver = (struct saved_macro *)xmalloc (sizeof (struct saved_macro)); - saver->next = macro_list; - saver->index = executing_macro_index; - saver->string = executing_macro; - - macro_list = saver; -} - -/* Discard the current macro, replacing it with the one - on the top of the stack of saved macros. */ -static -pop_executing_macro () -{ - if (executing_macro) - free (executing_macro); - - executing_macro = (char *)NULL; - executing_macro_index = 0; - - if (macro_list) - { - struct saved_macro *disposer = macro_list; - executing_macro = macro_list->string; - executing_macro_index = macro_list->index; - macro_list = macro_list->next; - free (disposer); - } -} - -/* Add a character to the macro being built. */ -static -add_macro_char (c) - int c; -{ - if (current_macro_index + 1 >= current_macro_size) - { - if (!current_macro) - current_macro = (char *)xmalloc (current_macro_size = 25); - else - current_macro = - (char *)xrealloc (current_macro, current_macro_size += 25); - } - - current_macro[current_macro_index++] = c; - current_macro[current_macro_index] = '\0'; -} - -/* Begin defining a keyboard macro. - Keystrokes are recorded as they are executed. - End the definition with rl_end_kbd_macro (). - If a numeric argument was explicitly typed, then append this - definition to the end of the existing macro, and start by - re-executing the existing macro. */ -rl_start_kbd_macro (ignore1, ignore2) - int ignore1, ignore2; -{ - if (defining_kbd_macro) - rl_abort (); - - if (rl_explicit_arg) - { - if (current_macro) - with_macro_input (savestring (current_macro)); - } - else - current_macro_index = 0; - - defining_kbd_macro = 1; -} - -/* Stop defining a keyboard macro. - A numeric argument says to execute the macro right now, - that many times, counting the definition as the first time. */ -rl_end_kbd_macro (count, ignore) - int count, ignore; -{ - if (!defining_kbd_macro) - rl_abort (); - - current_macro_index -= (rl_key_sequence_length - 1); - current_macro[current_macro_index] = '\0'; - - defining_kbd_macro = 0; - - rl_call_last_kbd_macro (--count, 0); -} - -/* Execute the most recently defined keyboard macro. - COUNT says how many times to execute it. */ -rl_call_last_kbd_macro (count, ignore) - int count, ignore; -{ - if (!current_macro) - rl_abort (); - - while (count--) - with_macro_input (savestring (current_macro)); -} - - -/* Non-zero means do not parse any lines other than comments and - parser directives. */ -static unsigned char parsing_conditionalized_out = 0; - -/* **************************************************************** */ -/* */ -/* Initializations */ -/* */ -/* **************************************************************** */ - -/* Initliaze readline (and terminal if not already). */ -rl_initialize () -{ - extern char *rl_display_prompt; - - /* If we have never been called before, initialize the - terminal and data structures. */ - if (!rl_initialized) - { - readline_initialize_everything (); - rl_initialized++; - } - - /* Initalize the current line information. */ - rl_point = rl_end = 0; - the_line = rl_line_buffer; - the_line[0] = 0; - - /* We aren't done yet. We haven't even gotten started yet! */ - rl_done = 0; - - /* Tell the history routines what is going on. */ - start_using_history (); - - /* Make the display buffer match the state of the line. */ - { - extern char *rl_display_prompt; - extern int forced_display; - - rl_on_new_line (); - - rl_display_prompt = rl_prompt ? rl_prompt : ""; - forced_display = 1; - } - - /* No such function typed yet. */ - rl_last_func = (Function *)NULL; - - /* Parsing of key-bindings begins in an enabled state. */ - { - parsing_conditionalized_out = 0; - } -} - -/* Initialize the entire state of the world. */ -readline_initialize_everything () -{ - /* Find out if we are running in Emacs. */ - running_in_emacs = (char *)getenv ("EMACS"); - - /* Allocate data structures. */ - if (!rl_line_buffer) - rl_line_buffer = - (char *)xmalloc (rl_line_buffer_len = DEFAULT_BUFFER_SIZE); - - /* Initialize the terminal interface. */ - init_terminal_io ((char *)NULL); - - /* Bind tty characters to readline functions. */ - readline_default_bindings (); - - /* Initialize the function names. */ - rl_initialize_funmap (); - - /* Read in the init file. */ - rl_read_init_file ((char *)NULL); - - /* If the completion parser's default word break characters haven't - been set yet, then do so now. */ - { - extern char *rl_completer_word_break_characters; - extern char *rl_basic_word_break_characters; - - if (rl_completer_word_break_characters == (char *)NULL) - rl_completer_word_break_characters = rl_basic_word_break_characters; - } -} - -/* If this system allows us to look at the values of the regular - input editing characters, then bind them to their readline - equivalents. */ -readline_default_bindings () -{ -#ifdef TIOCGETP - struct sgttyb ttybuff; - int tty = fileno (rl_instream); - - if (ioctl (tty, TIOCGETP, &ttybuff) != -1) - { - int erase = ttybuff.sg_erase, kill = ttybuff.sg_kill; - - if (erase != -1 && keymap[erase].type == ISFUNC) - keymap[erase].function = rl_rubout; - - if (kill != -1 && keymap[kill].type == ISFUNC) - keymap[kill].function = rl_unix_line_discard; - } - -#ifdef TIOCGLTC - { - struct ltchars lt; - - if (ioctl (tty, TIOCGLTC, <) != -1) - { - int erase = lt.t_werasc, nextc = lt.t_lnextc; - - if (erase != -1 && keymap[erase].type == ISFUNC) - keymap[erase].function = rl_unix_word_rubout; - - if (nextc != -1 && keymap[nextc].type == ISFUNC) - keymap[nextc].function = rl_quoted_insert; - } - } -#endif /* TIOCGLTC */ -#endif /* TIOCGETP */ -} - - -/* **************************************************************** */ -/* */ -/* Numeric Arguments */ -/* */ -/* **************************************************************** */ - -/* Handle C-u style numeric args, as well as M--, and M-digits. */ - -/* Add the current digit to the argument in progress. */ -rl_digit_argument (ignore, key) - int ignore, key; -{ - rl_pending_input = key; - rl_digit_loop (); -} - -/* What to do when you abort reading an argument. */ -rl_discard_argument () -{ - ding (); - rl_clear_message (); - rl_init_argument (); -} - -/* Create a default argument. */ -rl_init_argument () -{ - rl_numeric_arg = arg_sign = 1; - rl_explicit_arg = 0; -} - -/* C-u, universal argument. Multiply the current argument by 4. - Read a key. If the key has nothing to do with arguments, then - dispatch on it. If the key is the abort character then abort. */ -rl_universal_argument () -{ - rl_numeric_arg *= 4; - rl_digit_loop (); -} - -rl_digit_loop () -{ - int key, c; - while (1) - { - rl_message ("(arg: %d) ", arg_sign * rl_numeric_arg); - key = c = rl_read_key (); - - if (keymap[c].type == ISFUNC && - keymap[c].function == rl_universal_argument) - { - rl_numeric_arg *= 4; - continue; - } - c = UNMETA (c); - if (numeric (c)) - { - if (rl_explicit_arg) - rl_numeric_arg = (rl_numeric_arg * 10) + (c - '0'); - else - rl_numeric_arg = (c - '0'); - rl_explicit_arg = 1; - } - else - { - if (c == '-' && !rl_explicit_arg) - { - rl_numeric_arg = 1; - arg_sign = -1; - } - else - { - rl_clear_message (); - rl_dispatch (key, keymap); - return; - } - } - } -} - - -/* **************************************************************** */ -/* */ -/* Display stuff */ -/* */ -/* **************************************************************** */ - -/* This is the stuff that is hard for me. I never seem to write good - display routines in C. Let's see how I do this time. */ - -/* (PWP) Well... Good for a simple line updater, but totally ignores - the problems of input lines longer than the screen width. - - update_line and the code that calls it makes a multiple line, - automatically wrapping line update. Carefull attention needs - to be paid to the vertical position variables. - - handling of terminals with autowrap on (incl. DEC braindamage) - could be improved a bit. Right now I just cheat and decrement - screenwidth by one. */ - -/* Keep two buffers; one which reflects the current contents of the - screen, and the other to draw what we think the new contents should - be. Then compare the buffers, and make whatever changes to the - screen itself that we should. Finally, make the buffer that we - just drew into be the one which reflects the current contents of the - screen, and place the cursor where it belongs. - - Commands that want to can fix the display themselves, and then let - this function know that the display has been fixed by setting the - RL_DISPLAY_FIXED variable. This is good for efficiency. */ - -/* Termcap variables: */ -extern char *term_up, *term_dc, *term_cr; -extern int screenheight, screenwidth, terminal_can_insert; - -/* What YOU turn on when you have handled all redisplay yourself. */ -int rl_display_fixed = 0; - -/* The visible cursor position. If you print some text, adjust this. */ -int last_c_pos = 0; -int last_v_pos = 0; - -/* The last left edge of text that was displayed. This is used when - doing horizontal scrolling. It shifts in thirds of a screenwidth. */ -static int last_lmargin = 0; - -/* The line display buffers. One is the line currently displayed on - the screen. The other is the line about to be displayed. */ -static char *visible_line = (char *)NULL; -static char *invisible_line = (char *)NULL; - -/* Number of lines currently on screen minus 1. */ -int vis_botlin = 0; - -/* A buffer for `modeline' messages. */ -char msg_buf[128]; - -/* Non-zero forces the redisplay even if we thought it was unnecessary. */ -int forced_display = 0; - -/* The stuff that gets printed out before the actual text of the line. - This is usually pointing to rl_prompt. */ -char *rl_display_prompt = (char *)NULL; - -/* Default and initial buffer size. Can grow. */ -static int line_size = 1024; - -/* Non-zero means to always use horizontal scrolling in line display. */ -int horizontal_scroll_mode = 0; - -/* I really disagree with this, but my boss (among others) insists that we - support compilers that don't work. I don't think we are gaining by doing - so; what is the advantage in producing better code if we can't use it? */ -/* The following two declarations belong inside the - function block, not here. */ -static void move_cursor_relative (); -static void output_some_chars (); - -/* Basic redisplay algorithm. */ -rl_redisplay () -{ - register int in, out, c, linenum; - register char *line = invisible_line; - int c_pos = 0; - int inv_botlin = 0; /* Number of lines in newly drawn buffer. */ - - extern int readline_echoing_p; - - if (!readline_echoing_p) - return; - - if (!rl_display_prompt) - rl_display_prompt = ""; - - if (!invisible_line) - { - visible_line = (char *)xmalloc (line_size); - invisible_line = (char *)xmalloc (line_size); - line = invisible_line; - for (in = 0; in < line_size; in++) - { - visible_line[in] = 0; - invisible_line[in] = 1; - } - rl_on_new_line (); - } - - /* Draw the line into the buffer. */ - c_pos = -1; - - /* Mark the line as modified or not. We only do this for history - lines. */ - out = 0; - if (current_history () && rl_undo_list) - { - line[out++] = '*'; - line[out] = '\0'; - } - - /* If someone thought that the redisplay was handled, but the currently - visible line has a different modification state than the one about - to become visible, then correct the callers misconception. */ - if (visible_line[0] != invisible_line[0]) - rl_display_fixed = 0; - - strncpy (line + out, rl_display_prompt, strlen (rl_display_prompt)); - out += strlen (rl_display_prompt); - line[out] = '\0'; - - for (in = 0; in < rl_end; in++) - { - c = the_line[in]; - - if (out + 1 >= line_size) - { - line_size *= 2; - visible_line = (char *)xrealloc (visible_line, line_size); - invisible_line = (char *)xrealloc (invisible_line, line_size); - line = invisible_line; - } - - if (in == rl_point) - c_pos = out; - - if (c > 127) - { - line[out++] = 'M'; - line[out++] = '-'; - line[out++] = c - 128; - } -#define DISPLAY_TABS -#ifdef DISPLAY_TABS - else if (c == '\t') - { - register int newout = (out | (int)7) + 1; - while (out < newout) - line[out++] = ' '; - } -#endif - else if (c < 32) - { - line[out++] = 'C'; - line[out++] = '-'; - line[out++] = c + 64; - } - else - line[out++] = c; - } - line[out] = '\0'; - if (c_pos < 0) - c_pos = out; - - /* PWP: now is when things get a bit hairy. The visible and invisible - line buffers are really multiple lines, which would wrap every - (screenwidth - 1) characters. Go through each in turn, finding - the changed region and updating it. The line order is top to bottom. */ - - /* If we can move the cursor up and down, then use multiple lines, - otherwise, let long lines display in a single terminal line, and - horizontally scroll it. */ - - if (!horizontal_scroll_mode && term_up && *term_up) - { - int total_screen_chars = (screenwidth * screenheight); - - if (!rl_display_fixed || forced_display) - { - forced_display = 0; - - /* If we have more than a screenful of material to display, then - only display a screenful. We should display the last screen, - not the first. I'll fix this in a minute. */ - if (out >= total_screen_chars) - out = total_screen_chars - 1; - - /* Number of screen lines to display. */ - inv_botlin = out / screenwidth; - - /* For each line in the buffer, do the updating display. */ - for (linenum = 0; linenum <= inv_botlin; linenum++) - update_line (linenum > vis_botlin ? "" - : &visible_line[linenum * screenwidth], - &invisible_line[linenum * screenwidth], - linenum); - - /* We may have deleted some lines. If so, clear the left over - blank ones at the bottom out. */ - if (vis_botlin > inv_botlin) - { - char *tt; - for (; linenum <= vis_botlin; linenum++) - { - tt = &visible_line[linenum * screenwidth]; - move_vert (linenum); - move_cursor_relative (0, tt); - clear_to_eol ((linenum == vis_botlin)? - strlen (tt) : screenwidth); - } - } - vis_botlin = inv_botlin; - - /* Move the cursor where it should be. */ - move_vert (c_pos / screenwidth); - move_cursor_relative (c_pos % screenwidth, - &invisible_line[(c_pos / screenwidth) * screenwidth]); - } - } - else /* Do horizontal scrolling. */ - { - int lmargin; - - /* Always at top line. */ - last_v_pos = 0; - - /* If the display position of the cursor would be off the edge - of the screen, start the display of this line at an offset that - leaves the cursor on the screen. */ - if (c_pos - last_lmargin > screenwidth - 2) - lmargin = (c_pos / (screenwidth / 3) - 2) * (screenwidth / 3); - else if (c_pos - last_lmargin < 1) - lmargin = ((c_pos - 1) / (screenwidth / 3)) * (screenwidth / 3); - else - lmargin = last_lmargin; - - /* If the first character on the screen isn't the first character - in the display line, indicate this with a special character. */ - if (lmargin > 0) - line[lmargin] = '<'; - - if (lmargin + screenwidth < out) - line[lmargin + screenwidth - 1] = '>'; - - if (!rl_display_fixed || forced_display || lmargin != last_lmargin) - { - forced_display = 0; - update_line (&visible_line[last_lmargin], - &invisible_line[lmargin], 0); - - move_cursor_relative (c_pos - lmargin, &invisible_line[lmargin]); - last_lmargin = lmargin; - } - } - fflush (out_stream); - - /* Swap visible and non-visible lines. */ - { - char *temp = visible_line; - visible_line = invisible_line; - invisible_line = temp; - rl_display_fixed = 0; - } -} - -/* PWP: update_line() is based on finding the middle difference of each - line on the screen; vis: - - /old first difference - /beginning of line | /old last same /old EOL - v v v v -old: eddie> Oh, my little gruntle-buggy is to me, as lurgid as -new: eddie> Oh, my little buggy says to me, as lurgid as - ^ ^ ^ ^ - \beginning of line | \new last same \new end of line - \new first difference - - All are character pointers for the sake of speed. Special cases for - no differences, as well as for end of line additions must be handeled. - - Could be made even smarter, but this works well enough */ -static -update_line (old, new, current_line) - register char *old, *new; - int current_line; -{ - register char *ofd, *ols, *oe, *nfd, *nls, *ne; - int lendiff, wsatend; - - /* Find first difference. */ - for (ofd = old, nfd = new; - (ofd - old < screenwidth) && *ofd && (*ofd == *nfd); - ofd++, nfd++) - ; - - /* Move to the end of the screen line. */ - for (oe = ofd; ((oe - old) < screenwidth) && *oe; oe++); - for (ne = nfd; ((ne - new) < screenwidth) && *ne; ne++); - - /* If no difference, continue to next line. */ - if (ofd == oe && nfd == ne) - return; - - wsatend = 1; /* flag for trailing whitespace */ - ols = oe - 1; /* find last same */ - nls = ne - 1; - while ((*ols == *nls) && (ols > ofd) && (nls > nfd)) - { - if (*ols != ' ') - wsatend = 0; - ols--; - nls--; - } - - if (wsatend) - { - ols = oe; - nls = ne; - } - else if (*ols != *nls) - { - if (*ols) /* don't step past the NUL */ - ols++; - if (*nls) - nls++; - } - - move_vert (current_line); - move_cursor_relative (ofd - old, old); - - /* if (len (new) > len (old)) */ - lendiff = (nls - nfd) - (ols - ofd); - - /* Insert (diff(len(old),len(new)) ch */ - if (lendiff > 0) - { - if (terminal_can_insert) - { - extern char *term_IC; - - /* Sometimes it is cheaper to print the characters rather than - use the terminal's capabilities. */ - if ((2 * (ne - nfd)) < lendiff && (!term_IC || !*term_IC)) - { - output_some_chars (nfd, (ne - nfd)); - last_c_pos += (ne - nfd); - } - else - { - if (*ols) - { - start_insert (lendiff); - output_some_chars (nfd, lendiff); - last_c_pos += lendiff; - end_insert (); - } - else - { - /* At the end of a line the characters do not have to - be "inserted". They can just be placed on the screen. */ - output_some_chars (nfd, lendiff); - last_c_pos += lendiff; - } - /* Copy (new) chars to screen from first diff to last match. */ - if (((nls - nfd) - lendiff) > 0) - { - output_some_chars (&nfd[lendiff], ((nls - nfd) - lendiff)); - last_c_pos += ((nls - nfd) - lendiff); - } - } - } - else - { /* cannot insert chars, write to EOL */ - output_some_chars (nfd, (ne - nfd)); - last_c_pos += (ne - nfd); - } - } - else /* Delete characters from line. */ - { - /* If possible and inexpensive to use terminal deletion, then do so. */ - if (term_dc && (2 * (ne - nfd)) >= (-lendiff)) - { - if (lendiff) - delete_chars (-lendiff); /* delete (diff) characters */ - - /* Copy (new) chars to screen from first diff to last match */ - if ((nls - nfd) > 0) - { - output_some_chars (nfd, (nls - nfd)); - last_c_pos += (nls - nfd); - } - } - /* Otherwise, print over the existing material. */ - else - { - output_some_chars (nfd, (ne - nfd)); - last_c_pos += (ne - nfd); - clear_to_eol ((oe - old) - (ne - new)); - } - } -} - -/* (PWP) tell the update routines that we have moved onto a - new (empty) line. */ -rl_on_new_line () -{ - if (visible_line) - visible_line[0] = '\0'; - - last_c_pos = last_v_pos = 0; - vis_botlin = last_lmargin = 0; -} - -/* Actually update the display, period. */ -rl_forced_update_display () -{ - if (visible_line) - { - register char *temp = visible_line; - - while (*temp) *temp++ = '\0'; - } - rl_on_new_line (); - forced_display++; - rl_redisplay (); -} - -/* Move the cursor from last_c_pos to NEW, which are buffer indices. - DATA is the contents of the screen line of interest; i.e., where - the movement is being done. */ -static void -move_cursor_relative (new, data) - int new; - char *data; -{ - register int i; - static void output_character_function (); - - /* It may be faster to output a CR, and then move forwards instead - of moving backwards. */ - if (new + 1 < last_c_pos - new) - { - tputs (term_cr, 1, output_character_function); - last_c_pos = 0; - } - - if (last_c_pos == new) return; - - if (last_c_pos < new) - { - /* Move the cursor forward. We do it by printing the command - to move the cursor forward if there is one, else print that - portion of the output buffer again. Which is cheaper? */ - - /* The above comment is left here for posterity. It is faster - to print one character (non-control) than to print a control - sequence telling the terminal to move forward one character. - That kind of control is for people who don't know what the - data is underneath the cursor. */ -#ifdef HACK_TERMCAP_MOTION - extern char *term_forward_char; - - if (term_forward_char) - for (i = last_c_pos; i < new; i++) - tputs (term_forward_char, 1, output_character_function); - else - for (i = last_c_pos; i < new; i++) - putc (data[i], out_stream); -#else - for (i = last_c_pos; i < new; i++) - putc (data[i], out_stream); -#endif /* HACK_TERMCAP_MOTION */ - } - else - backspace (last_c_pos - new); - last_c_pos = new; -} - -/* PWP: move the cursor up or down. */ -move_vert (to) - int to; -{ - void output_character_function (); - register int delta, i; - - if (last_v_pos == to) return; - - if (to > screenheight) - return; - - if ((delta = to - last_v_pos) > 0) - { - for (i = 0; i < delta; i++) - putc ('\n', out_stream); - tputs (term_cr, 1, output_character_function); - last_c_pos = 0; /* because crlf() will do \r\n */ - } - else - { /* delta < 0 */ - if (term_up && *term_up) - for (i = 0; i < -delta; i++) - tputs (term_up, 1, output_character_function); - } - last_v_pos = to; /* now to is here */ -} - -/* Physically print C on out_stream. This is for functions which know - how to optimize the display. */ -rl_show_char (c) - int c; -{ - if (c > 127) - { - fprintf (out_stream, "M-"); - c -= 128; - } - -#ifdef DISPLAY_TABS - if (c < 32 && c != '\t') -#else - if (c < 32) -#endif - { - - c += 64; - } - - putc (c, out_stream); - fflush (out_stream); -} - -#ifdef DISPLAY_TABS -int -rl_character_len (c, pos) - register int c, pos; -{ - if (c < ' ' || c > 126) - { - if (c == '\t') - return (((pos | (int)7) + 1) - pos); - else - return (3); - } - else - return (1); -} -#else -int -rl_character_len (c) - int c; -{ - if (c < ' ' || c > 126) - return (3); - else - return (1); -} -#endif /* DISPLAY_TAB */ - -/* How to print things in the "echo-area". The prompt is treated as a - mini-modeline. */ -rl_message (string, arg1, arg2) - char *string; -{ - sprintf (msg_buf, string, arg1, arg2); - rl_display_prompt = msg_buf; - rl_redisplay (); -} - -/* How to clear things from the "echo-area". */ -rl_clear_message () -{ - rl_display_prompt = rl_prompt; - rl_redisplay (); -} - -/* **************************************************************** */ -/* */ -/* Terminal and Termcap */ -/* */ -/* **************************************************************** */ - -static char *term_buffer = (char *)NULL; -static char *term_string_buffer = (char *)NULL; - -/* Non-zero means this terminal can't really do anything. */ -int dumb_term = 0; - -char PC; -char *BC, *UP; - -/* Some strings to control terminal actions. These are output by tputs (). */ -char *term_goto, *term_clreol, *term_cr, *term_clrpag, *term_backspace; - -int screenwidth, screenheight; - -/* Non-zero if we determine that the terminal can do character insertion. */ -int terminal_can_insert = 0; - -/* How to insert characters. */ -char *term_im, *term_ei, *term_ic, *term_ip, *term_IC; - -/* How to delete characters. */ -char *term_dc, *term_DC; - -#ifdef HACK_TERMCAP_MOTION -char *term_forward_char; -#endif /* HACK_TERMCAP_MOTION */ - -/* How to go up a line. */ -char *term_up; - -/* Re-initialize the terminal considering that the TERM/TERMCAP variable - has changed. */ -rl_reset_terminal (terminal_name) - char *terminal_name; -{ - init_terminal_io (terminal_name); -} - -init_terminal_io (terminal_name) - char *terminal_name; -{ - char *term = (terminal_name? terminal_name : (char *)getenv ("TERM")); - char *tgetstr (), *buffer; - - - if (!term_string_buffer) - term_string_buffer = (char *)xmalloc (2048); - - if (!term_buffer) - term_buffer = (char *)xmalloc (2048); - - buffer = term_string_buffer; - - term_clrpag = term_cr = term_clreol = (char *)NULL; - - if (!term) - term = "dumb"; - - if (tgetent (term_buffer, term) < 0) - { - dumb_term = 1; - return; - } - - BC = tgetstr ("pc", &buffer); - PC = buffer ? *buffer : 0; - - term_backspace = tgetstr ("le", &buffer); - - term_cr = tgetstr ("cr", &buffer); - term_clreol = tgetstr ("ce", &buffer); - term_clrpag = tgetstr ("cl", &buffer); - - if (!term_cr) - term_cr = "\r"; - -#ifdef HACK_TERMCAP_MOTION - term_forward_char = tgetstr ("nd", &buffer); -#endif /* HACK_TERMCAP_MOTION */ - - screenwidth = tgetnum ("co"); - if (screenwidth <= 0) - screenwidth = 80; - screenwidth--; /* PWP: avoid autowrap bugs */ - - screenheight = tgetnum ("li"); - if (screenheight <= 0) - screenheight = 24; - - term_im = tgetstr ("im", &buffer); - term_ei = tgetstr ("ei", &buffer); - term_IC = tgetstr ("IC", &buffer); - term_ic = tgetstr ("ic", &buffer); - term_ip = tgetstr ("ip", &buffer); - term_IC = tgetstr ("IC", &buffer); - - /* "An application program can assume that the terminal can do - character insertion if *any one of* the capabilities `IC', - `im', `ic' or `ip' is provided." */ -#ifdef notdef - /* XXX Circumvent broken code. */ - terminal_can_insert = (term_IC || term_im || term_ic || term_ip); -#endif - - term_up = tgetstr ("up", &buffer); - term_dc = tgetstr ("dc", &buffer); - term_DC = tgetstr ("DC", &buffer); -} - -/* A function for the use of tputs () */ -static void -output_character_function (c) - int c; -{ - putc (c, out_stream); -} - -/* Write COUNT characters from STRING to the output stream. */ -static void -output_some_chars (string, count) - char *string; - int count; -{ - fwrite (string, 1, count, out_stream); -} - - -/* Delete COUNT characters from the display line. */ -static -delete_chars (count) - int count; -{ - if (count > screenwidth) - return; - - if (term_DC && *term_DC) - { - char *tgoto (), *buffer; - buffer = tgoto (term_DC, 0, count); - tputs (buffer, 1, output_character_function); - } - else - { - if (term_dc && *term_dc) - while (count--) - tputs (term_dc, 1, output_character_function); - } -} - -/* Prepare to insert by inserting COUNT blank spaces. */ -static -start_insert (count) - int count; -{ - if (term_im && *term_im) - tputs (term_im, 1, output_character_function); - - if (term_IC && *term_IC && - (count > 1 || !term_ic || !*term_ic)) - { - char *tgoto (), *buffer; - buffer = tgoto (term_IC, 0, count); - tputs (buffer, 1, output_character_function); - } - else - { - if (term_ic && *term_ic) - while (count--) - tputs (term_ic, 1, output_character_function); - } -} - -/* We are finished doing our insertion. Send ending string. */ -static -end_insert () -{ - if (term_ei && *term_ei) - tputs (term_ei, 1, output_character_function); -} - -/* Move the cursor back. */ -backspace (count) - int count; -{ - register int i; - - if (term_backspace) - for (i = 0; i < count; i++) - tputs (term_backspace, 1, output_character_function); - else - for (i = 0; i < count; i++) - putc ('\b', out_stream); -} - -/* Move to the start of the next line. */ -crlf () -{ - tputs (term_cr, 1, output_character_function); - putc ('\n', out_stream); -} - -/* Clear to the end of the line. COUNT is the minimum - number of character spaces to clear, */ -clear_to_eol (count) - int count; -{ - if (term_clreol) { - tputs (term_clreol, 1, output_character_function); - } else { - register int i; - /* Do one more character space. */ - count++; - for (i = 0; i < count; i++) - putc (' ', out_stream); - backspace (count); - } -} - - -/* **************************************************************** */ -/* */ -/* Saving and Restoring the TTY */ -/* */ -/* **************************************************************** */ - -#ifdef NEW_TTY_DRIVER - -/* Standard flags, including ECHO. */ -static int original_tty_flags = 0; - -/* Local mode flags, like LPASS8. */ -static int local_mode_flags = 0; - -/* Terminal characters. This has C-s and C-q in it. */ -static struct tchars original_tchars; - -/* Local special characters. This has the interrupt characters in it. */ -static struct ltchars original_ltchars; - -/* We use this to get and set the tty_flags. */ -static struct sgttyb the_ttybuff; - -/* Put the terminal in CBREAK mode so that we can detect key presses. */ -static -rl_prep_terminal () -{ - int tty = fileno (rl_instream); - - /* We always get the latest tty values. Maybe stty changed them. */ - - ioctl (tty, TIOCGETP, &the_ttybuff); - original_tty_flags = the_ttybuff.sg_flags; - - readline_echoing_p = (original_tty_flags & ECHO); - - /* If this terminal doesn't care how the 8th bit is used, - then we can use it for the meta-key. - We check by seeing if BOTH odd and even parity are allowed. */ - if ((the_ttybuff.sg_flags & (ODDP | EVENP)) == (ODDP | EVENP)) - { -#ifdef PASS8 - the_ttybuff.sg_flags |= PASS8; -#endif - -#if defined (TIOCLGET) && defined (LPASS8) - { - int flags; - ioctl (tty, TIOCLGET, &flags); - local_mode_flags = flags; - flags |= LPASS8; - ioctl (tty, TIOCLSET, &flags); - } -#endif - } - -#ifdef TIOCGETC - { - struct tchars temp; - - ioctl (tty, TIOCGETC, &original_tchars); - bcopy (&original_tchars, &temp, sizeof (struct tchars)); - - /* Get rid of C-s and C-q. - We remember the value of startc (C-q) so that if the terminal is in - xoff state, the user can xon it by pressing that character. */ - xon_char = temp.t_startc; - temp.t_stopc = -1; - temp.t_startc = -1; - - /* If there is an XON character, bind it to restart the output. */ - if (xon_char != -1) - rl_bind_key (xon_char, rl_restart_output); - - /* If there is an EOF char, bind eof_char to it. */ - if (temp.t_eofc != -1) - eof_char = temp.t_eofc; - -#ifdef NEVER - /* Get rid of C-\ and C-c. */ - temp.t_intrc = temp.t_quitc = -1; -#endif - - ioctl (tty, TIOCSETC, &temp); - } -#endif /* TIOCGETC */ - -#ifdef TIOCGLTC - { - struct ltchars temp; - - ioctl (tty, TIOCGLTC, &original_ltchars); - bcopy (&original_ltchars, &temp, sizeof (struct ltchars)); - - /* Make the interrupt keys go away. Just enough to make people happy. */ - temp.t_dsuspc = -1; /* C-y */ - temp.t_lnextc = -1; /* C-v */ - - ioctl (tty, TIOCSLTC, &temp); - } -#endif /* TIOCGLTC */ - - the_ttybuff.sg_flags &= ~ECHO; - the_ttybuff.sg_flags |= CBREAK; - ioctl (tty, TIOCSETN, &the_ttybuff); -} - -/* Restore the terminal to its original state. */ -static -rl_deprep_terminal () -{ - int tty = fileno (rl_instream); - -#if defined (TIOCLGET) && defined (LPASS8) - if ((the_ttybuff.sg_flags & (ODDP | EVENP)) == (ODDP | EVENP)) - ioctl (tty, TIOCLSET, &local_mode_flags); -#endif - -#ifdef TIOCSLTC - ioctl (tty, TIOCSLTC, &original_ltchars); -#endif - -#ifdef TIOCSETC - ioctl (tty, TIOCSETC, &original_tchars); -#endif - - the_ttybuff.sg_flags = original_tty_flags; - ioctl (tty, TIOCSETN, &the_ttybuff); - readline_echoing_p = 1; -} - -#else /* !defined (NEW_TTY_DRIVER) */ -static struct termio otio; - -static -rl_prep_terminal () -{ - int tty = fileno (rl_instream); - struct termio tio; - - ioctl (tty, TCGETA, &tio); - ioctl (tty, TCGETA, &otio); - - readline_echoing_p = (tio.c_lflag & ECHO); - - tio.c_lflag &= ~(ICANON|ECHO); - tio.c_iflag &= ~(IXON|ISTRIP|INPCK); - -#ifndef HANDLE_SIGNALS - tio.c_lflag &= ~ISIG; -#endif - - tio.c_cc[VEOF] = 1; /* really: MIN */ - tio.c_cc[VEOL] = 0; /* really: TIME */ - ioctl (tty, TCSETAW,&tio); -} - -static -rl_deprep_terminal () -{ - int tty = fileno (rl_instream); - ioctl (tty, TCSETAW, &otio); -} -#endif /* NEW_TTY_DRIVER */ - - -/* **************************************************************** */ -/* */ -/* Utility Functions */ -/* */ -/* **************************************************************** */ - -/* Return 0 if C is not a member of the class of characters that belong - in words, or 1 if it is. */ - -int allow_pathname_alphabetic_chars = 0; -char *pathname_alphabetic_chars = "/-_=~.#$"; - -int -alphabetic (c) - int c; -{ - if (pure_alphabetic (c) || (numeric (c))) - return (1); - - if (allow_pathname_alphabetic_chars) - return ((int)rindex (pathname_alphabetic_chars, c)); - else - return (0); -} - -/* Return non-zero if C is a numeric character. */ -int -numeric (c) - int c; -{ - return (c >= '0' && c <= '9'); -} - -/* Ring the terminal bell. */ -int -ding () -{ - if (readline_echoing_p) - { - fprintf (stderr, "\007"); - fflush (stderr); - } - return (-1); -} - -/* How to abort things. */ -rl_abort () -{ - ding (); - rl_clear_message (); - rl_init_argument (); - rl_pending_input = 0; - - defining_kbd_macro = 0; - while (executing_macro) - pop_executing_macro (); - - longjmp (readline_top_level, 1); -} - -/* Return a copy of the string between FROM and TO. - FROM is inclusive, TO is not. */ -char * -rl_copy (from, to) - int from, to; -{ - register int length; - char *copy; - - /* Fix it if the caller is confused. */ - if (from > to) { - int t = from; - from = to; - to = t; - } - - length = to - from; - copy = (char *)xmalloc (1 + length); - strncpy (copy, the_line + from, length); - copy[length] = '\0'; - return (copy); -} - - -/* **************************************************************** */ -/* */ -/* Insert and Delete */ -/* */ -/* **************************************************************** */ - - -/* Insert a string of text into the line at point. This is the only - way that you should do insertion. rl_insert () calls this - function. */ -rl_insert_text (string) - char *string; -{ - extern int doing_an_undo; - register int i, l = strlen (string); - while (rl_end + l >= rl_line_buffer_len) - { - rl_line_buffer = - (char *)xrealloc (rl_line_buffer, - rl_line_buffer_len += DEFAULT_BUFFER_SIZE); - the_line = rl_line_buffer; - } - - for (i = rl_end; i >= rl_point; i--) - the_line[i + l] = the_line[i]; - strncpy (the_line + rl_point, string, l); - - /* Remember how to undo this if we aren't undoing something. */ - if (!doing_an_undo) - { - /* If possible and desirable, concatenate the undos. */ - if ((strlen (string) == 1) && - rl_undo_list && - (rl_undo_list->what == UNDO_INSERT) && - (rl_undo_list->end == rl_point) && - (rl_undo_list->end - rl_undo_list->start < 20)) - rl_undo_list->end++; - else - rl_add_undo (UNDO_INSERT, rl_point, rl_point + l, (char *)NULL); - } - rl_point += l; - rl_end += l; - the_line[rl_end] = '\0'; -} - -/* Delete the string between FROM and TO. FROM is - inclusive, TO is not. */ -rl_delete_text (from, to) - int from, to; -{ - extern int doing_an_undo; - register char *text; - - /* Fix it if the caller is confused. */ - if (from > to) { - int t = from; - from = to; - to = t; - } - text = rl_copy (from, to); - strncpy (the_line + from, the_line + to, rl_end - to); - - /* Remember how to undo this delete. */ - if (!doing_an_undo) - rl_add_undo (UNDO_DELETE, from, to, text); - else - free (text); - - rl_end -= (to - from); - the_line[rl_end] = '\0'; -} - - -/* **************************************************************** */ -/* */ -/* Readline character functions */ -/* */ -/* **************************************************************** */ - -/* This is not a gap editor, just a stupid line input routine. No hair - is involved in writing any of the functions, and none should be. */ - -/* Note that: - - rl_end is the place in the string that we would place '\0'; - i.e., it is always safe to place '\0' there. - - rl_point is the place in the string where the cursor is. Sometimes - this is the same as rl_end. - - Any command that is called interactively receives two arguments. - The first is a count: the numeric arg pased to this command. - The second is the key which invoked this command. -*/ - - -/* **************************************************************** */ -/* */ -/* Movement Commands */ -/* */ -/* **************************************************************** */ - -/* Note that if you `optimize' the display for these functions, you cannot - use said functions in other functions which do not do optimizing display. - I.e., you will have to update the data base for rl_redisplay, and you - might as well let rl_redisplay do that job. */ - -/* Move forward COUNT characters. */ -rl_forward (count) - int count; -{ - if (count < 0) - rl_backward (-count); - else - while (count) - { -#ifdef VI_MODE - if (rl_point == (rl_end - (rl_editing_mode == vi_mode))) -#else - if (rl_point == rl_end) -#endif - { - ding (); - return; - } - else - rl_point++; - --count; - } -} - -/* Move backward COUNT characters. */ -rl_backward (count) - int count; -{ - if (count < 0) - rl_forward (-count); - else - while (count) - { - if (!rl_point) - { - ding (); - return; - } - else - --rl_point; - --count; - } -} - -/* Move to the beginning of the line. */ -rl_beg_of_line () -{ - rl_point = 0; -} - -/* Move to the end of the line. */ -rl_end_of_line () -{ - rl_point = rl_end; -} - -/* Move forward a word. We do what Emacs does. */ -rl_forward_word (count) - int count; -{ - int c; - - if (count < 0) - { - rl_backward_word (-count); - return; - } - - while (count) - { - if (rl_point == rl_end) - return; - - /* If we are not in a word, move forward until we are in one. - Then, move forward until we hit a non-alphabetic character. */ - c = the_line[rl_point]; - if (!alphabetic (c)) - { - while (++rl_point < rl_end) - { - c = the_line[rl_point]; - if (alphabetic (c)) break; - } - } - if (rl_point == rl_end) return; - while (++rl_point < rl_end) - { - c = the_line[rl_point]; - if (!alphabetic (c)) break; - } - --count; - } -} - -/* Move backward a word. We do what Emacs does. */ -rl_backward_word (count) - int count; -{ - int c; - - if (count < 0) - { - rl_forward_word (-count); - return; - } - - while (count) - { - if (!rl_point) - return; - - /* Like rl_forward_word (), except that we look at the characters - just before point. */ - - c = the_line[rl_point - 1]; - if (!alphabetic (c)) - { - while (--rl_point) - { - c = the_line[rl_point - 1]; - if (alphabetic (c)) break; - } - } - - while (rl_point) - { - c = the_line[rl_point - 1]; - if (!alphabetic (c)) - break; - else --rl_point; - } - --count; - } -} - -/* Clear the current line. Numeric argument to C-l does this. */ -rl_refresh_line () -{ - int curr_line = last_c_pos / screenwidth; - - move_vert(curr_line); - move_cursor_relative (0, the_line); /* XXX is this right */ - rl_forced_update_display (); - rl_display_fixed = 1; -} - -/* C-l typed to a line without quoting clears the screen, and then reprints - the prompt and the current input line. Given a numeric arg, redraw only - the current line. */ -rl_clear_screen () -{ - extern char *term_clrpag; - static void output_character_function (); - - if (rl_explicit_arg) - { - rl_refresh_line (); - return; - } - - if (term_clrpag) - tputs (term_clrpag, 1, output_character_function); - else - crlf (); - - rl_forced_update_display (); - rl_display_fixed = 1; -} - - -/* **************************************************************** */ -/* */ -/* Text commands */ -/* */ -/* **************************************************************** */ - -/* Insert the character C at the current location, moving point forward. */ -rl_insert (count, c) - int count, c; -{ - register int i; - char *string; - - if (count <= 0) - return; - - /* If we can optimize, then do it. But don't let people crash - readline because of extra large arguments. */ - if (count > 1 && count < 1024) - { - string = (char *)alloca (1 + count); - - for (i = 0; i < count; i++) - string[i] = c; - - string[i] = '\0'; - rl_insert_text (string); - return; - } - - if (count > 1024) - { - int descreaser; - - string = (char *)alloca (1024 + 1); - - for (i = 0; i < 1024; i++) - string[i] = c; - - while (count) - { - descreaser = (count > 1024 ? 1024 : count); - string[descreaser] = '\0'; - rl_insert_text (string); - count -= descreaser; - } - return; - } - - /* We are inserting a single character. - If there is pending input, then make a string of all of the - pending characters that are bound to rl_insert, and insert - them all. */ - if (any_typein) - { - int slen, key = 0, t; - - i = 0; - string = (char *)alloca (ibuffer_len + 1); - string[i++] = c; - - while ((key = rl_get_char()) != -2 && - (keymap[key].type == ISFUNC && - keymap[key].function == rl_insert)) - string[i++] = key; - - if (key != -2) - rl_unget_char (key); - - string[i] = '\0'; - rl_insert_text (string); - return; - } - else - { - /* Inserting a single character. */ - string = (char *)alloca (2); - - string[1] = '\0'; - string[0] = c; - rl_insert_text (string); - } -} - -/* Insert the next typed character verbatim. */ -rl_quoted_insert (count) - int count; -{ - int c = rl_read_key (in_stream); - rl_insert (count, c); -} - -/* Insert a tab character. */ -rl_tab_insert (count) - int count; -{ - rl_insert (count, '\t'); -} - -#ifdef VI_MODE -/* Non-zero means enter insertion mode. */ -static vi_doing_insert = 0; -#endif - -/* What to do when a NEWLINE is pressed. We accept the whole line. - KEY is the key that invoked this command. I guess it could have - meaning in the future. */ -rl_newline (count, key) - int count, key; -{ - - rl_done = 1; - -#ifdef VI_MODE - { - if (vi_doing_insert) - { - rl_end_undo_group (); - vi_doing_insert = 0; - } - } -#endif /* VI_MODE */ - - if (readline_echoing_p) - { - move_vert (vis_botlin); - vis_botlin = 0; - crlf (); - fflush (out_stream); - rl_display_fixed++; - } -} - -rl_clean_up_for_exit () -{ - if (readline_echoing_p) - { - move_vert (vis_botlin); - vis_botlin = 0; - fflush (out_stream); - rl_restart_output (); - } -} - -/* What to do for some uppercase characters, like meta characters, - and some characters appearing in emacs_ctlx_keymap. This function - is just a stub, you bind keys to it and the code in rl_dispatch () - is special cased. */ -rl_do_lowercase_version (ignore1, ignore2) - int ignore1, ignore2; -{ -} - -/* Rubout the character behind point. */ -rl_rubout (count) - int count; -{ - if (count < 0) - { - rl_delete (-count); - return; - } - - if (!rl_point) - { - ding (); - return; - } - - if (count > 1) - { - int orig_point = rl_point; - rl_backward (count); - rl_kill_text (orig_point, rl_point); - } - else - { - int c = the_line[--rl_point]; - rl_delete_text (rl_point, rl_point + 1); - - if (rl_point == rl_end && alphabetic (c) && last_c_pos) - { - backspace (1); - putc (' ', out_stream); - backspace (1); - last_c_pos--; - rl_display_fixed++; - } - } -} - -/* Delete the character under the cursor. Given a numeric argument, - kill that many characters instead. */ -rl_delete (count, invoking_key) - int count; -{ - if (count < 0) - { - rl_rubout (-count); - return; - } - - if (rl_point == rl_end) - { - ding (); - return; - } - -#ifdef VI_MODE - if ((count > 1) || ((count == 1) && (rl_editing_mode == vi_mode))) -#else - if (count > 1) -#endif - { - int orig_point = rl_point; - while (count && (rl_point < rl_end)) - { - rl_point++; - count--; - } - rl_kill_text (orig_point, rl_point); - rl_point = orig_point; - } - else - rl_delete_text (rl_point, rl_point + 1); -} - - -/* **************************************************************** */ -/* */ -/* Kill commands */ -/* */ -/* **************************************************************** */ - -/* The next two functions mimic unix line editing behaviour, except they - save the deleted text on the kill ring. This is safer than not saving - it, and since we have a ring, nobody should get screwed. */ - -/* This does what C-w does in Unix. We can't prevent people from - using behaviour that they expect. */ -rl_unix_word_rubout () -{ - if (!rl_point) ding (); - else { - int orig_point = rl_point; - while (rl_point && whitespace (the_line[rl_point - 1])) - rl_point--; - while (rl_point && !whitespace (the_line[rl_point - 1])) - rl_point--; - rl_kill_text (rl_point, orig_point); - } -} - -/* Here is C-u doing what Unix does. You don't *have* to use these - key-bindings. We have a choice of killing the entire line, or - killing from where we are to the start of the line. We choose the - latter, because if you are a Unix weenie, then you haven't backspaced - into the line at all, and if you aren't, then you know what you are - doing. */ -rl_unix_line_discard () -{ - if (!rl_point) ding (); - else { - rl_kill_text (rl_point, 0); - rl_point = 0; - } -} - - - -/* **************************************************************** */ -/* */ -/* Commands For Typos */ -/* */ -/* **************************************************************** */ - -/* Random and interesting things in here. */ - - -/* **************************************************************** */ -/* */ -/* Changing Case */ -/* */ -/* **************************************************************** */ - -/* The three kinds of things that we know how to do. */ -#define UpCase 1 -#define DownCase 2 -#define CapCase 3 - -/* Uppercase the word at point. */ -rl_upcase_word (count) - int count; -{ - rl_change_case (count, UpCase); -} - -/* Lowercase the word at point. */ -rl_downcase_word (count) - int count; -{ - rl_change_case (count, DownCase); -} - -/* Upcase the first letter, downcase the rest. */ -rl_capitalize_word (count) - int count; -{ - rl_change_case (count, CapCase); -} - -/* The meaty function. - Change the case of COUNT words, performing OP on them. - OP is one of UpCase, DownCase, or CapCase. - If a negative argument is given, leave point where it started, - otherwise, leave it where it moves to. */ -rl_change_case (count, op) - int count, op; -{ - register int start = rl_point, end; - int state = 0; - - rl_forward_word (count); - end = rl_point; - - if (count < 0) - { - int temp = start; - start = end; - end = temp; - } - - /* We are going to modify some text, so let's prepare to undo it. */ - rl_modifying (start, end); - - for (; start < end; start++) - { - switch (op) - { - case UpCase: - the_line[start] = to_upper (the_line[start]); - break; - - case DownCase: - the_line[start] = to_lower (the_line[start]); - break; - - case CapCase: - if (state == 0) - { - the_line[start] = to_upper (the_line[start]); - state = 1; - } - else - { - the_line[start] = to_lower (the_line[start]); - } - if (!pure_alphabetic (the_line[start])) - state = 0; - break; - - default: - abort (); - } - } - rl_point = end; -} - -/* **************************************************************** */ -/* */ -/* Transposition */ -/* */ -/* **************************************************************** */ - -/* Transpose the words at point. */ -rl_transpose_words (count) - int count; -{ - char *word1, *word2; - int w1_beg, w1_end, w2_beg, w2_end; - int orig_point = rl_point; - - if (!count) return; - - /* Find the two words. */ - rl_forward_word (count); - w2_end = rl_point; - rl_backward_word (1); - w2_beg = rl_point; - rl_backward_word (count); - w1_beg = rl_point; - rl_forward_word (1); - w1_end = rl_point; - - /* Do some check to make sure that there really are two words. */ - if ((w1_beg == w2_beg) || (w2_beg < w1_end)) - { - ding (); - rl_point = orig_point; - return; - } - - /* Get the text of the words. */ - word1 = rl_copy (w1_beg, w1_end); - word2 = rl_copy (w2_beg, w2_end); - - /* We are about to do many insertions and deletions. Remember them - as one operation. */ - rl_begin_undo_group (); - - /* Do the stuff at word2 first, so that we don't have to worry - about word1 moving. */ - rl_point = w2_beg; - rl_delete_text (w2_beg, w2_end); - rl_insert_text (word1); - - rl_point = w1_beg; - rl_delete_text (w1_beg, w1_end); - rl_insert_text (word2); - - /* This is exactly correct since the text before this point has not - changed in length. */ - rl_point = w2_end; - - /* I think that does it. */ - rl_end_undo_group (); - free (word1); free (word2); -} - -/* Transpose the characters at point. If point is at the end of the line, - then transpose the characters before point. */ -rl_transpose_chars (count) - int count; -{ - if (!count) - return; - - if (!rl_point || rl_end < 2) { - ding (); - return; - } - - while (count) { - if (rl_point == rl_end) { - int t = the_line[rl_point - 1]; - the_line[rl_point - 1] = the_line[rl_point - 2]; - the_line[rl_point - 2] = t; - } else { - int t = the_line[rl_point]; - the_line[rl_point] = the_line[rl_point - 1]; - the_line[rl_point - 1] = t; - if (count < 0 && rl_point) - rl_point--; - else - rl_point++; - } - if (count < 0) - count++; - else - count--; - } -} - - -/* **************************************************************** */ -/* */ -/* Bogus Flow Control */ -/* */ -/* **************************************************************** */ - -rl_restart_output (count, key) - int count, key; -{ - int fildes = fileno (stdin); -#ifdef TIOCSTART - ioctl (fildes, TIOCSTART, 0); -#endif /* TIOCSTART */ -} - -/* **************************************************************** */ -/* */ -/* Completion matching, from readline's point of view. */ -/* */ -/* **************************************************************** */ - -/* Pointer to the generator function for completion_matches (). - NULL means to use filename_entry_function (), the default filename - completer. */ -Function *rl_completion_entry_function = (Function *)NULL; - -/* Pointer to alternative function to create matches. - Function is called with TEXT, START, and END. - START and END are indices in RL_LINE_BUFFER saying what the boundaries - of TEXT are. - If this function exists and returns NULL then call the value of - rl_completion_entry_function to try to match, otherwise use the - array of strings returned. */ -Function *rl_attempted_completion_function = (Function *)NULL; - -/* Complete the word at or before point. You have supplied the function - that does the initial simple matching selection algorithm (see - completion_matches ()). The default is to do filename completion. */ -rl_complete (ignore, invoking_key) - int ignore, invoking_key; -{ - rl_complete_internal (TAB); - if (running_in_emacs) - printf ("%s", the_line); -} - -/* List the possible completions. See description of rl_complete (). */ -rl_possible_completions () -{ - rl_complete_internal ('?'); -} - -/* The user must press "y" or "n". Non-zero return means "y" pressed. */ -get_y_or_n () -{ - int c; - loop: - c = rl_read_key (in_stream); - if (c == 'y' || c == 'Y') return (1); - if (c == 'n' || c == 'N') return (0); - if (c == ABORT_CHAR) rl_abort (); - ding (); goto loop; -} - -/* Up to this many items will be displayed in response to a - possible-completions call. After that, we ask the user if - she is sure she wants to see them all. */ -int rl_completion_query_items = 100; - -/* The basic list of characters that signal a break between words for the - completer routine. The contents of this variable is what breaks words - in the shell, i.e. " \t\n\"\\'`@$><=" */ -char *rl_basic_word_break_characters = " \t\n\"\\'`@$><="; - -/* The list of characters that signal a break between words for - rl_complete_internal. The default list is the contents of - rl_basic_word_break_characters. */ -char *rl_completer_word_break_characters = (char *)NULL; - -/* List of characters that are word break characters, but should be left - in TEXT when it is passed to the completion function. The shell uses - this to help determine what kind of completing to do. */ -char *rl_special_prefixes = (char *)NULL; - -/* If non-zero, then disallow duplicates in the matches. */ -int rl_ignore_completion_duplicates = 1; - -/* Non-zero means that the results of the matches are to be treated - as filenames. This is ALWAYS zero on entry, and can only be changed - within a completion entry finder function. */ -int rl_filename_completion_desired = 0; - -/* Complete the word at or before point. - WHAT_TO_DO says what to do with the completion. - `?' means list the possible completions. - TAB means do standard completion. - `*' means insert all of the possible completions. */ -rl_complete_internal (what_to_do) - int what_to_do; -{ - char *filename_completion_function (); - char **completion_matches (), **matches; - Function *our_func; - int start, end, delimiter = 0; - char *text; - - if (rl_completion_entry_function) - our_func = rl_completion_entry_function; - else - our_func = (int (*)())filename_completion_function; - - /* Only the completion entry function can change this. */ - rl_filename_completion_desired = 0; - - /* We now look backwards for the start of a filename/variable word. */ - end = rl_point; - if (rl_point) - { - while (--rl_point && - !rindex (rl_completer_word_break_characters, the_line[rl_point])); - - /* If we are at a word break, then advance past it. */ - if (rindex (rl_completer_word_break_characters, (the_line[rl_point]))) - { - /* If the character that caused the word break was a quoting - character, then remember it as the delimiter. */ - if (rindex ("\"'", the_line[rl_point]) && (end - rl_point) > 1) - delimiter = the_line[rl_point]; - - /* If the character isn't needed to determine something special - about what kind of completion to perform, then advance past it. */ - - if (!rl_special_prefixes || - !rindex (rl_special_prefixes, the_line[rl_point])) - rl_point++; - } - } - - start = rl_point; - rl_point = end; - text = rl_copy (start, end); - - /* If the user wants to TRY to complete, but then wants to give - up and use the default completion function, they set the - variable rl_attempted_completion_function. */ - if (rl_attempted_completion_function) - { - matches = - (char **)(*rl_attempted_completion_function) (text, start, end); - - if (matches) - goto after_usual_completion; - } - - matches = completion_matches (text, our_func, start, end); - - after_usual_completion: - free (text); - - if (!matches) - ding (); - else - { - register int i; - - some_matches: - - /* It seems to me that in all the cases we handle we would like - to ignore duplicate possiblilities. Scan for the text to - insert being identical to the other completions. */ - if (rl_ignore_completion_duplicates) - { - char *lowest_common; - int j, newlen = 0; - - /* Sort the items. */ - /* It is safe to sort this array, because the lowest common - denominator found in matches[0] will remain in place. */ - for (i = 0; matches[i]; i++); - qsort (matches, i, sizeof (char *), compare_strings); - - /* Remember the lowest common denimator for it may be unique. */ - lowest_common = savestring (matches[0]); - - for (i = 0; matches[i + 1]; i++) - { - if (strcmp (matches[i], matches[i + 1]) == 0) - { - free (matches[i]); - matches[i] = (char *)-1; - } - else - newlen++; - } - - /* We have marked all the dead slots with (char *)-1. - Copy all the non-dead entries into a new array. */ - { - char **temp_array = - (char **)malloc ((3 + newlen) * sizeof (char *)); - - for (i = 1, j = 1; matches[i]; i++) - if (matches[i] != (char *)-1) - temp_array[j++] = matches[i]; - temp_array[j] = (char *)NULL; - - if (matches[0] != (char *)-1) - free (matches[0]); - free (matches); - - matches = temp_array; - } - - /* Place the lowest common denominator back in [0]. */ - matches[0] = lowest_common; - - /* If there is one string left, and it is identical to the - lowest common denominator, then the LCD is the string to - insert. */ - if (j == 2 && strcmp (matches[0], matches[1]) == 0) - { - free (matches[1]); - matches[1] = (char *)NULL; - } - } - - switch (what_to_do) - { - case TAB: - rl_delete_text (start, rl_point); - rl_point = start; - rl_insert_text (matches[0]); - - /* If there are more matches, ring the bell to indicate. - If this was the only match, and we are hacking files, - check the file to see if it was a directory. If so, - add a '/' to the name. If not, and we are at the end - of the line, then add a space. */ - if (matches[1]) - { - ding (); /* There are other matches remaining. */ - } - else - { - char temp_string[2]; - - temp_string[0] = delimiter ? delimiter : ' '; - temp_string[1] = '\0'; - - if (rl_filename_completion_desired) - { - struct stat finfo; - char *tilde_expand (); - char *filename = tilde_expand (matches[0]); - - if ((stat (filename, &finfo) == 0) && - ((finfo.st_mode & S_IFMT) == S_IFDIR)) - { - if (the_line[rl_point] != '/') - rl_insert_text ("/"); - } - else - { - if (rl_point == rl_end) - rl_insert_text (temp_string); - } - free (filename); - } - else - { - if (rl_point == rl_end) - rl_insert_text (temp_string); - } - } - break; - - case '*': - { - int i = 1; - - rl_delete_text (start, rl_point); - rl_point = start; - rl_begin_undo_group (); - if (matches[1]) - { - while (matches[i]) - { - rl_insert_text (matches[i++]); - rl_insert_text (" "); - } - } - else - { - rl_insert_text (matches[0]); - rl_insert_text (" "); - } - rl_end_undo_group (); - } - break; - - - case '?': - { - int len, count, limit, max = 0; - int j, k, l; - - /* Handle simple case first. What if there is only one answer? */ - if (!matches[1]) - { - char *temp; - - if (rl_filename_completion_desired) - temp = rindex (matches[0], '/'); - else - temp = (char *)NULL; - - if (!temp) - temp = matches[0]; - else - temp++; - - crlf (); - fprintf (out_stream, "%s", temp); - crlf (); - goto restart; - } - - /* There is more than one answer. Find out how many there are, - and find out what the maximum printed length of a single entry - is. */ - for (i = 1; matches[i]; i++) - { - char *temp = (char *)NULL; - - /* If we are hacking filenames, then only count the characters - after the last slash in the pathname. */ - if (rl_filename_completion_desired) - temp = rindex (matches[i], '/'); - else - temp = (char *)NULL; - - if (!temp) - temp = matches[i]; - else - temp++; - - if (strlen (temp) > max) - max = strlen (temp); - } - - len = i; - - /* If there are many items, then ask the user if she - really wants to see them all. */ - if (len >= rl_completion_query_items) - { - crlf (); - fprintf (out_stream, - "There are %d possibilities. Do you really", len); - crlf (); - fprintf (out_stream, "wish to see them all? (y or n)"); - fflush (out_stream); - if (!get_y_or_n ()) - { - crlf (); - goto restart; - } - } - /* How many items of MAX length can we fit in the screen window? */ - max += 2; - limit = screenwidth / max; - if (limit != 1 && (limit * max == screenwidth)) - limit--; - - /* How many iterations of the printing loop? */ - count = (len + (limit - 1)) / limit; - - /* Watch out for special case. If LEN is less than LIMIT, then - just do the inner printing loop. */ - if (len < limit) count = 1; - - /* Sort the items if they are not already sorted. */ - if (!rl_ignore_completion_duplicates) - { - qsort (matches, len, sizeof (char *), compare_strings); - } - - /* Print the sorted items, up-and-down alphabetically, like - ls might. */ - crlf (); - - for (i = 1; i < count + 1; i++) - { - for (j = 0, l = i; j < limit; j++) - { - if (l > len || !matches[l]) - { - break; - } - else - { - char *temp = (char *)NULL; - - if (rl_filename_completion_desired) - temp = rindex (matches[l], '/'); - else - temp = (char *)NULL; - - if (!temp) - temp = matches[l]; - else - temp++; - - fprintf (out_stream, "%s", temp); - for (k = 0; k < max - strlen (temp); k++) - putc (' ', out_stream); - } - l += count; - } - crlf (); - } - restart: - - rl_on_new_line (); - } - break; - - default: - abort (); - } - - for (i = 0; matches[i]; i++) - free (matches[i]); - free (matches); - } -} - -/* A completion function for usernames. - TEXT contains a partial username preceded by a random - character (usually `~'). */ -char * -username_completion_function (text, state) - int state; - char *text; -{ - static char *username = (char *)NULL; - static struct passwd *entry; - static int namelen; - - if (!state) - { - if (username) - free (username); - username = savestring (&text[1]); - namelen = strlen (username); - setpwent (); - } - - while (entry = getpwent ()) - { - if (strncmp (username, entry->pw_name, namelen) == 0) - break; - } - - if (!entry) - { - endpwent (); - return ((char *)NULL); - } - else - { - char *value = (char *)xmalloc (2 + strlen (entry->pw_name)); - *value = *text; - strcpy (value + 1, entry->pw_name); - rl_filename_completion_desired = 1; - return (value); - } -} - -/* If non-null, this contains the address of a function to call if the - standard meaning for expanding a tilde fails. The function is called - with the text (sans tilde, as in "foo"), and returns a malloc()'ed string - which is the expansion, or a NULL pointer if there is no expansion. */ -Function *rl_tilde_expander = (Function *)NULL; - -/* Expand FILENAME if it begins with a tilde. This always returns - a new string. */ -char * -tilde_expand (filename) - char *filename; -{ - char *dirname = filename ? savestring (filename) : (char *)NULL; - - if (dirname && *dirname == '~') - { - char *temp_name; - if (!dirname[1] || dirname[1] == '/') - { - /* Prepend $HOME to the rest of the string. */ - char *temp_home = (char *)getenv ("HOME"); - - temp_name = (char *)alloca (1 + strlen (&dirname[1]) - + (temp_home? strlen (temp_home) : 0)); - temp_name[0] = '\0'; - if (temp_home) - strcpy (temp_name, temp_home); - strcat (temp_name, &dirname[1]); - free (dirname); - dirname = savestring (temp_name); - } - else - { - struct passwd *getpwnam (), *user_entry; - char *username = (char *)alloca (257); - int i, c; - - for (i = 1; c = dirname[i]; i++) - { - if (c == '/') break; - else username[i - 1] = c; - } - username[i - 1] = '\0'; - - if (!(user_entry = getpwnam (username))) - { - /* If the calling program has a special syntax for - expanding tildes, and we couldn't find a standard - expansion, then let them try. */ - if (rl_tilde_expander) - { - char *expansion; - - expansion = (char *)(*rl_tilde_expander) (username); - - if (expansion) - { - temp_name = (char *)alloca (1 + strlen (expansion) - + strlen (&dirname[i])); - strcpy (temp_name, expansion); - strcat (temp_name, &dirname[i]); - free (expansion); - goto return_name; - } - } - /* - * We shouldn't report errors. - */ - } - else - { - temp_name = (char *)alloca (1 + strlen (user_entry->pw_dir) - + strlen (&dirname[i])); - strcpy (temp_name, user_entry->pw_dir); - strcat (temp_name, &dirname[i]); - return_name: - free (dirname); - dirname = savestring (temp_name); - } - } - } - return (dirname); -} - - -/* **************************************************************** */ -/* */ -/* Undo, and Undoing */ -/* */ -/* **************************************************************** */ - -/* Non-zero tells rl_delete_text and rl_insert_text to not add to - the undo list. */ -int doing_an_undo = 0; - -/* The current undo list for THE_LINE. */ -UNDO_LIST *rl_undo_list = (UNDO_LIST *)NULL; - -/* Remember how to undo something. Concatenate some undos if that - seems right. */ -rl_add_undo (what, start, end, text) - enum undo_code what; - int start, end; - char *text; -{ - UNDO_LIST *temp = (UNDO_LIST *)xmalloc (sizeof (UNDO_LIST)); - temp->what = what; - temp->start = start; - temp->end = end; - temp->text = text; - temp->next = rl_undo_list; - rl_undo_list = temp; -} - -/* Free the existing undo list. */ -free_undo_list () -{ - while (rl_undo_list) { - UNDO_LIST *release = rl_undo_list; - rl_undo_list = rl_undo_list->next; - - if (release->what == UNDO_DELETE) - free (release->text); - - free (release); - } -} - -/* Undo the next thing in the list. Return 0 if there - is nothing to undo, or non-zero if there was. */ -int -rl_do_undo () -{ - UNDO_LIST *release; - int waiting_for_begin = 0; - -undo_thing: - if (!rl_undo_list) - return (0); - - doing_an_undo = 1; - - switch (rl_undo_list->what) { - - /* Undoing deletes means inserting some text. */ - case UNDO_DELETE: - rl_point = rl_undo_list->start; - rl_insert_text (rl_undo_list->text); - free (rl_undo_list->text); - break; - - /* Undoing inserts means deleting some text. */ - case UNDO_INSERT: - rl_delete_text (rl_undo_list->start, rl_undo_list->end); - rl_point = rl_undo_list->start; - break; - - /* Undoing an END means undoing everything 'til we get to - a BEGIN. */ - case UNDO_END: - waiting_for_begin++; - break; - - /* Undoing a BEGIN means that we are done with this group. */ - case UNDO_BEGIN: - if (waiting_for_begin) - waiting_for_begin--; - else - abort (); - break; - } - - doing_an_undo = 0; - - release = rl_undo_list; - rl_undo_list = rl_undo_list->next; - free (release); - - if (waiting_for_begin) - goto undo_thing; - - return (1); -} - -/* Begin a group. Subsequent undos are undone as an atomic operation. */ -rl_begin_undo_group () -{ - rl_add_undo (UNDO_BEGIN, 0, 0, 0); -} - -/* End an undo group started with rl_begin_undo_group (). */ -rl_end_undo_group () -{ - rl_add_undo (UNDO_END, 0, 0, 0); -} - -/* Save an undo entry for the text from START to END. */ -rl_modifying (start, end) - int start, end; -{ - if (start > end) - { - int t = start; - start = end; - end = t; - } - - if (start != end) - { - char *temp = rl_copy (start, end); - rl_begin_undo_group (); - rl_add_undo (UNDO_DELETE, start, end, temp); - rl_add_undo (UNDO_INSERT, start, end, (char *)NULL); - rl_end_undo_group (); - } -} - -/* Revert the current line to its previous state. */ -rl_revert_line () -{ - if (!rl_undo_list) ding (); - else { - while (rl_undo_list) - rl_do_undo (); - } -} - -/* Do some undoing of things that were done. */ -rl_undo_command (count) -{ - if (count < 0) return; /* Nothing to do. */ - - while (count) - { - if (rl_do_undo ()) - { - count--; - } - else - { - ding (); - break; - } - } -} - -/* **************************************************************** */ -/* */ -/* History Utilities */ -/* */ -/* **************************************************************** */ - -/* We already have a history library, and that is what we use to control - the history features of readline. However, this is our local interface - to the history mechanism. */ - -/* While we are editing the history, this is the saved - version of the original line. */ -HIST_ENTRY *saved_line_for_history = (HIST_ENTRY *)NULL; - -/* Set the history pointer back to the last entry in the history. */ -start_using_history () -{ - using_history (); - if (saved_line_for_history) - free_history_entry (saved_line_for_history); - - saved_line_for_history = (HIST_ENTRY *)NULL; -} - -/* Free the contents (and containing structure) of a HIST_ENTRY. */ -free_history_entry (entry) - HIST_ENTRY *entry; -{ - if (!entry) return; - if (entry->line) - free (entry->line); - free (entry); -} - -/* Perhaps put back the current line if it has changed. */ -maybe_replace_line () -{ - HIST_ENTRY *temp = current_history (); - - /* If the current line has changed, save the changes. */ - if (temp && ((UNDO_LIST *)(temp->data) != rl_undo_list)) { - temp = replace_history_entry (where_history (), the_line, rl_undo_list); - free (temp->line); - free (temp); - } -} - -/* Put back the saved_line_for_history if there is one. */ -maybe_unsave_line () -{ - if (saved_line_for_history) { - strcpy (the_line, saved_line_for_history->line); - rl_undo_list = (UNDO_LIST *)saved_line_for_history->data; - free_history_entry (saved_line_for_history); - saved_line_for_history = (HIST_ENTRY *)NULL; - rl_end = rl_point = strlen (the_line); - } else { - ding (); - } -} - -/* Save the current line in saved_line_for_history. */ -maybe_save_line () -{ - if (!saved_line_for_history) { - saved_line_for_history = (HIST_ENTRY *)xmalloc (sizeof (HIST_ENTRY)); - saved_line_for_history->line = savestring (the_line); - saved_line_for_history->data = (char *)rl_undo_list; - } -} - - - -/* **************************************************************** */ -/* */ -/* History Commands */ -/* */ -/* **************************************************************** */ - -/* Meta-< goes to the start of the history. */ -rl_beginning_of_history () -{ - rl_get_previous_history (1 + where_history ()); -} - -/* Meta-> goes to the end of the history. (The current line). */ -rl_end_of_history () -{ - maybe_replace_line (); - using_history (); - maybe_unsave_line (); -} - -/* Move down to the next history line. */ -rl_get_next_history (count) - int count; -{ - HIST_ENTRY *temp = (HIST_ENTRY *)NULL; - - if (count < 0) - { - rl_get_previous_history (-count); - return; - } - - if (!count) - return; - - maybe_replace_line (); - - while (count) - { - temp = next_history (); - if (!temp) - break; - --count; - } - - if (!temp) - maybe_unsave_line (); - else - { - strcpy (the_line, temp->line); - rl_undo_list = (UNDO_LIST *)temp->data; - rl_end = rl_point = strlen (the_line); - } -} - -/* Get the previous item out of our interactive history, making it the current - line. If there is no previous history, just ding. */ -rl_get_previous_history (count) - int count; -{ - HIST_ENTRY *old_temp = (HIST_ENTRY *)NULL; - HIST_ENTRY *temp = (HIST_ENTRY *)NULL; - - if (count < 0) - { - rl_get_next_history (-count); - return; - } - - if (!count) - return; - - /* If we don't have a line saved, then save this one. */ - maybe_save_line (); - - /* If the current line has changed, save the changes. */ - maybe_replace_line (); - - while (count) - { - temp = previous_history (); - if (!temp) - break; - else - old_temp = temp; - --count; - } - - /* If there was a large argument, and we moved back to the start of the - history, that is not an error. So use the last value found. */ - if (!temp && old_temp) - temp = old_temp; - - if (!temp) - ding (); - else - { - strcpy (the_line, temp->line); - rl_undo_list = (UNDO_LIST *)temp->data; - rl_end = rl_point = strlen (the_line); -#ifdef VI_MODE - if (rl_editing_mode == vi_mode) - rl_point = 0; -#endif /* VI_MODE */ - } -} - -/* There is a command in ksh which yanks into this line, the last word - of the previous line. Here it is. We left it on M-. */ -rl_yank_previous_last_arg (ignore) - int ignore; -{ -} - - - -/* **************************************************************** */ -/* */ -/* I-Search and Searching */ -/* */ -/* **************************************************************** */ - -/* Search backwards through the history looking for a string which is typed - interactively. Start with the current line. */ -rl_reverse_search_history (sign, key) - int sign; - int key; -{ - rl_search_history (-sign, key); -} - -/* Search forwards through the history looking for a string which is typed - interactively. Start with the current line. */ -rl_forward_search_history (sign, key) - int sign; - int key; -{ - rl_search_history (sign, key); -} - -/* Display the current state of the search in the echo-area. - SEARCH_STRING contains the string that is being searched for, - DIRECTION is zero for forward, or 1 for reverse, - WHERE is the history list number of the current line. If it is - -1, then this line is the starting one. */ -rl_display_search (search_string, reverse_p, where) - char *search_string; - int reverse_p, where; -{ - char *message = (char *)NULL; - - message = - (char *)alloca (1 + (search_string ? strlen (search_string) : 0) + 30); - - *message = '\0'; - -#ifdef NEVER - if (where != -1) - sprintf (message, "[%d]", where + history_base); -#endif - - strcat (message, "("); - - if (reverse_p) - strcat (message, "reverse-"); - - strcat (message, "i-search)`"); - - if (search_string) - strcat (message, search_string); - - strcat (message, "': "); - rl_message (message, 0, 0); - rl_redisplay (); -} - -/* Search through the history looking for an interactively typed string. - This is analogous to i-search. We start the search in the current line. - DIRECTION is which direction to search; > 0 means forward, < 0 means - backwards. */ -rl_search_history (direction, invoking_key) - int direction; - int invoking_key; -{ - /* The string that the user types in to search for. */ - char *search_string = (char *)alloca (128); - - /* The current length of SEARCH_STRING. */ - int search_string_index; - - /* The list of lines to search through. */ - char **lines; - - /* The length of LINES. */ - int hlen; - - /* Where we get LINES from. */ - HIST_ENTRY **hlist = history_list (); - - int orig_point = rl_point; - int orig_line = where_history (); - int last_found_line = orig_line; - int c, done = 0; - register int i = 0; - - - /* The line currently being searched. */ - char *sline; - - /* Offset in that line. */ - int index; - - /* Non-zero if we are doing a reverse search. */ - int reverse = (direction < 0); - - /* Create an arrary of pointers to the lines that we want to search. */ - - maybe_replace_line (); - if (hlist) - for (i = 0; hlist[i]; i++); - - /* Allocate space for this many lines, +1 for the current input line, - and remember those lines. */ - lines = (char **)alloca ((1 + (hlen = i)) * sizeof (char *)); - for (i = 0; i < hlen; i++) - lines[i] = hlist[i]->line; - - if (saved_line_for_history) - lines[i] = saved_line_for_history->line; - else - { - /* So I have to type it in this way instead. */ - lines[i] = (char *)alloca (1 + strlen (the_line)); - strcpy (lines[i], &the_line[0]); - } - - hlen++; - - /* The line where we start the search. */ - i = orig_line; - - /* Initialize search parameters. */ - *search_string = '\0'; - search_string_index = 0; - - rl_display_search (search_string, reverse, -1); - - sline = the_line; - index = rl_point; - - while (!done) - { - c = rl_read_key (in_stream); - - /* Hack C to Do What I Mean. */ - { - Function *f = (Function *)NULL; - - if (keymap[c].type == ISFUNC) - f = keymap[c].function; - - if (f == rl_reverse_search_history) - c = reverse ? -1 : -2; - else if (f == rl_forward_search_history) - c = !reverse ? -1 : -2; - } - - switch (c) - { - case ESC: - done = 1; - continue; - - /* case invoking_key: */ - case -1: - goto search_again; - - /* switch directions */ - case -2: - direction = -direction; - reverse = (direction < 0); - - goto do_search; - - case CTRL ('G'): - strcpy (the_line, lines[orig_line]); - rl_point = orig_point; - rl_end = strlen (the_line); - rl_clear_message (); - return; - - default: - if (c < 32 || c > 126) - { - rl_execute_next (c); - done = 1; - continue; - } - else - { - search_string[search_string_index++] = c; - search_string[search_string_index] = '\0'; - goto do_search; - - search_again: - - if (!search_string_index) - continue; - else - { - if (reverse) - --index; - else - if (index != strlen (sline)) - ++index; - else - ding (); - } - do_search: - - while (1) - { - if (reverse) - { - while (index >= 0) - if (strncmp - (search_string, - sline + index, - search_string_index) == 0) - goto string_found; - else - index--; - } - else - { - register int limit = - (strlen (sline) - search_string_index) + 1; - - while (index < limit) - { - if (strncmp (search_string, - sline + index, - search_string_index) == 0) - goto string_found; - index++; - } - } - - next_line: - i += direction; - - /* At limit for direction? */ - if ((reverse && i < 0) || - (!reverse && i == hlen)) - goto search_failed; - - sline = lines[i]; - if (reverse) - index = strlen (sline); - else - index = 0; - - /* If the search string is longer than the current - line, no match. */ - if (search_string_index > strlen (sline)) - goto next_line; - - /* Start actually searching. */ - if (reverse) - index -= search_string_index; - } - - search_failed: - /* We cannot find the search string. Ding the bell. */ - ding (); - i = last_found_line; - break; - - string_found: - /* We have found the search string. Just display it. But don't - actually move there in the history list until the user accepts - the location. */ - strcpy (the_line, lines[i]); - rl_point = index; - rl_end = strlen (the_line); - last_found_line = i; - rl_display_search (search_string, reverse, - (i == orig_line) ? -1 : i); - } - } - continue; - } - /* The user has won. They found the string that they wanted. Now all - we have to do is place them there. */ - { - int now = last_found_line; - - /* First put back the original state. */ - strcpy (the_line, lines[orig_line]); - - if (now < orig_line) - rl_get_previous_history (orig_line - now); - else - rl_get_next_history (now - orig_line); - - rl_point = index; - rl_clear_message (); - } -} - -/* Make C be the next command to be executed. */ -rl_execute_next (c) - int c; -{ - rl_pending_input = c; -} - -/* **************************************************************** */ -/* */ -/* Killing Mechanism */ -/* */ -/* **************************************************************** */ - -/* What we assume for a max number of kills. */ -#define DEFAULT_MAX_KILLS 10 - -/* The real variable to look at to find out when to flush kills. */ -int rl_max_kills = DEFAULT_MAX_KILLS; - -/* Where to store killed text. */ -char **rl_kill_ring = (char **)NULL; - -/* Where we are in the kill ring. */ -int rl_kill_index = 0; - -/* How many slots we have in the kill ring. */ -int rl_kill_ring_length = 0; - -/* How to say that you only want to save a certain amount - of kill material. */ -rl_set_retained_kills (num) - int num; -{} - -/* The way to kill something. This appends or prepends to the last - kill, if the last command was a kill command. if FROM is less - than TO, then the text is appended, otherwise prepended. If the - last command was not a kill command, then a new slot is made for - this kill. */ -rl_kill_text (from, to) - int from, to; -{ - int slot; - char *text = rl_copy (from, to); - - /* Is there anything to kill? */ - if (from == to) { - free (text); - last_command_was_kill++; - return; - } - - /* Delete the copied text from the line. */ - rl_delete_text (from, to); - - /* First, find the slot to work with. */ - if (!last_command_was_kill) { - - /* Get a new slot. */ - if (!rl_kill_ring) { - - /* If we don't have any defined, then make one. */ - rl_kill_ring = - (char **)xmalloc (((rl_kill_ring_length = 1) + 1) * sizeof (char *)); - slot = 1; - - } else { - - /* We have to add a new slot on the end, unless we have exceeded - the max limit for remembering kills. */ - slot = rl_kill_ring_length; - if (slot == rl_max_kills) { - register int i; - free (rl_kill_ring[0]); - for (i = 0; i < slot; i++) - rl_kill_ring[i] = rl_kill_ring[i + 1]; - } else { - rl_kill_ring = - (char **)xrealloc (rl_kill_ring, - ((slot = (rl_kill_ring_length += 1)) + 1) - * sizeof (char *)); - } - } - slot--; - } else { - slot = rl_kill_ring_length - 1; - } - - /* If the last command was a kill, prepend or append. */ - if (last_command_was_kill) { - char *old = rl_kill_ring[slot]; - char *new = (char *)xmalloc (1 + strlen (old) + strlen (text)); - - if (from < to) { - strcpy (new, old); - strcat (new, text); - } else { - strcpy (new, text); - strcat (new, old); - } - free (old); - free (text); - rl_kill_ring[slot] = new; - } else { - rl_kill_ring[slot] = text; - } - rl_kill_index = slot; - last_command_was_kill++; -} - -/* Now REMEMBER! In order to do prepending or appending correctly, kill - commands always make rl_point's original position be the FROM argument, - and rl_point's extent be the TO argument. */ - - -/* **************************************************************** */ -/* */ -/* Killing Commands */ -/* */ -/* **************************************************************** */ - -/* Delete the word at point, saving the text in the kill ring. */ -rl_kill_word (count) - int count; -{ - int orig_point = rl_point; - - if (count < 0) - rl_backward_kill_word (-count); - else - { - rl_forward_word (count); - - if (rl_point != orig_point) - rl_kill_text (orig_point, rl_point); - - rl_point = orig_point; - } -} - -/* Rubout the word before point, placing it on the kill ring. */ -rl_backward_kill_word (count) - int count; -{ - int orig_point = rl_point; - - if (count < 0) - rl_kill_word (-count); - else - { - rl_backward_word (count); - - if (rl_point != orig_point) - rl_kill_text (orig_point, rl_point); - } -} - -/* Kill from here to the end of the line. If DIRECTION is negative, kill - back to the line start instead. */ -rl_kill_line (direction) - int direction; -{ - int orig_point = rl_point; - - if (direction < 0) - rl_backward_kill_line (1); - else - { - rl_end_of_line (); - if (orig_point != rl_point) - rl_kill_text (orig_point, rl_point); - rl_point = orig_point; - } -} - -/* Kill backwards to the start of the line. If DIRECTION is negative, kill - forwards to the line end instead. */ -rl_backward_kill_line (direction) - int direction; -{ - int orig_point = rl_point; - - if (direction < 0) - rl_kill_line (1); - else - { - if (!rl_point) - ding (); - else - { - rl_beg_of_line (); - rl_kill_text (orig_point, rl_point); - } - } -} - -/* Yank back the last killed text. This ignores arguments. */ -rl_yank () -{ - if (!rl_kill_ring) rl_abort (); - rl_insert_text (rl_kill_ring[rl_kill_index]); -} - -/* If the last command was yank, or yank_pop, and the text just - before point is identical to the current kill item, then - delete that text from the line, rotate the index down, and - yank back some other text. */ -rl_yank_pop () -{ - int l; - - if (((rl_last_func != rl_yank_pop) && (rl_last_func != rl_yank)) || - !rl_kill_ring) - { - rl_abort (); - } - - l = strlen (rl_kill_ring[rl_kill_index]); - if (((rl_point - l) >= 0) && - (strncmp (the_line + (rl_point - l), - rl_kill_ring[rl_kill_index], l) == 0)) - { - rl_delete_text ((rl_point - l), rl_point); - rl_point -= l; - rl_kill_index--; - if (rl_kill_index < 0) - rl_kill_index = rl_kill_ring_length - 1; - rl_yank (); - } - else - rl_abort (); - -} - -/* Yank the COUNTth argument from the previous history line. */ -rl_yank_nth_arg (count, ignore) - int count; -{ - register HIST_ENTRY *entry = previous_history (); - char *arg; - - if (entry) - next_history (); - else - { - ding (); - return; - } - - arg = history_arg_extract (count, count, entry->line); - if (!arg || !*arg) - { - ding (); - return; - } - - rl_begin_undo_group (); - if (rl_point && the_line[rl_point - 1] != ' ') - rl_insert_text (" "); - rl_insert_text (arg); - free (arg); - rl_end_undo_group (); -} - -/* Vi Mode. */ -#ifdef VI_MODE -#include "vi_mode.c" -#endif /* VI_MODE */ - -/* How to toggle back and forth between editing modes. */ -rl_vi_editing_mode () -{ -#ifdef VI_MODE - rl_editing_mode = vi_mode; - rl_vi_insertion_mode (); -#endif /* VI_MODE */ -} - -rl_emacs_editing_mode () -{ - rl_editing_mode = emacs_mode; - keymap = emacs_standard_keymap; -} - - -/* **************************************************************** */ -/* */ -/* Completion */ -/* */ -/* **************************************************************** */ - -/* Non-zero means that case is not significant in completion. */ -int completion_case_fold = 0; - -/* Return an array of (char *) which is a list of completions for TEXT. - If there are no completions, return a NULL pointer. - The first entry in the returned array is the substitution for TEXT. - The remaining entries are the possible completions. - The array is terminated with a NULL pointer. - - ENTRY_FUNCTION is a function of two args, and returns a (char *). - The first argument is TEXT. - The second is a state argument; it should be zero on the first call, and - non-zero on subsequent calls. It returns a NULL pointer to the caller - when there are no more matches. - */ -char ** -completion_matches (text, entry_function) - char *text; - char *(*entry_function) (); -{ - /* Number of slots in match_list. */ - int match_list_size; - - /* The list of matches. */ - char **match_list = - (char **)xmalloc (((match_list_size = 10) + 1) * sizeof (char *)); - - /* Number of matches actually found. */ - int matches = 0; - - /* Temporary string binder. */ - char *string; - - match_list[1] = (char *)NULL; - - while (string = (*entry_function) (text, matches)) - { - if (matches + 1 == match_list_size) - match_list = - (char **)xrealloc (match_list, - ((match_list_size += 10) + 1) * sizeof (char *)); - - match_list[++matches] = string; - match_list[matches + 1] = (char *)NULL; - } - - /* If there were any matches, then look through them finding out the - lowest common denominator. That then becomes match_list[0]. */ - if (matches) - { - register int i = 1; - int low = 100000; /* Count of max-matched characters. */ - - /* If only one match, just use that. */ - if (matches == 1) - { - match_list[0] = match_list[1]; - match_list[1] = (char *)NULL; - } - else - { - /* Otherwise, compare each member of the list with - the next, finding out where they stop matching. */ - - while (i < matches) - { - register int c1, c2, si; - - if (completion_case_fold) - { - for (si = 0; - (c1 = to_lower(match_list[i][si])) && - (c2 = to_lower(match_list[i + 1][si])); - si++) - if (c1 != c2) break; - } - else - { - for (si = 0; - (c1 = match_list[i][si]) && - (c2 = match_list[i + 1][si]); - si++) - if (c1 != c2) break; - } - - if (low > si) low = si; - i++; - } - match_list[0] = (char *)xmalloc (low + 1); - strncpy (match_list[0], match_list[1], low); - match_list[0][low] = '\0'; - } - } - else /* There were no matches. */ - { - free (match_list); - match_list = (char **)NULL; - } - return (match_list); -} - -/* Okay, now we write the entry_function for filename completion. In the - general case. Note that completion in the shell is a little different - because of all the pathnames that must be followed when looking up the - completion for a command. */ -char * -filename_completion_function (text, state) - int state; - char *text; -{ - static DIR *directory; - static char *filename = (char *)NULL; - static char *dirname = (char *)NULL; - static char *users_dirname = (char *)NULL; - static int filename_len; - - struct direct *entry = (struct direct *)NULL; - - /* If we don't have any state, then do some initialization. */ - if (!state) - { - char *temp; - - if (dirname) free (dirname); - if (filename) free (filename); - if (users_dirname) free (users_dirname); - - filename = savestring (text); - if (!*text) text = "."; - dirname = savestring (text); - - temp = rindex (dirname, '/'); - - if (temp) - { - strcpy (filename, ++temp); - *temp = '\0'; - } - else - strcpy (dirname, "."); - - /* We aren't done yet. We also support the "~user" syntax. */ - - /* Save the version of the directory that the user typed. */ - users_dirname = savestring (dirname); - { - char *tilde_expand (), *temp_dirname = tilde_expand (dirname); - free (dirname); - dirname = temp_dirname; -#ifdef SHELL - { - extern int follow_symbolic_links; - char *make_absolute (); - - if (follow_symbolic_links && (strcmp (dirname, ".") != 0)) - { - temp_dirname = make_absolute (dirname, get_working_directory ("")); - - if (temp_dirname) - { - free (dirname); - dirname = temp_dirname; - } - } - } -#endif /* SHELL */ - } - directory = opendir (dirname); - filename_len = strlen (filename); - - rl_filename_completion_desired = 1; - } - - /* At this point we should entertain the possibility of hacking wildcarded - filenames, like /usr/man*\/te. If the directory name contains - globbing characters, then build an array of directories to glob on, and - glob on the first one. */ - - /* Now that we have some state, we can read the directory. */ - - while (directory && (entry = readdir (directory))) - { - /* Special case for no filename. - All entries except "." and ".." match. */ - if (!filename_len) - { - if ((strcmp (entry->d_name, ".") != 0) && - (strcmp (entry->d_name, "..") != 0)) - break; - } - else - { - /* Otherwise, if these match upto the length of filename, then - it is a match. */ -#ifdef TMB_SYSV - if ((strlen (entry->d_name) >= filename_len) && - (strncmp (filename, entry->d_name, filename_len) == 0)) -#else - if ((entry->d_namlen >= filename_len) && - (strncmp (filename, entry->d_name, filename_len) == 0)) -#endif /* TMB_SYSV */ - { - break; - } - } - } - - if (!entry) - { - if (directory) - { - closedir (directory); - directory = (DIR *)NULL; - } - return (char *)NULL; - } - else - { - char *temp; - - if (dirname && (strcmp (dirname, ".") != 0)) - { -#ifdef TMB_SYSV - temp = (char *)xmalloc (1 + strlen (users_dirname) - + strlen (entry->d_name)); -#else - temp = (char *)xmalloc (1 + strlen (users_dirname) - + entry->d_namlen); -#endif /* TMB_SYSV */ - strcpy (temp, users_dirname); - strcat (temp, entry->d_name); - } - else - { - temp = (savestring (entry->d_name)); - } - return (temp); - } -} - - -/* **************************************************************** */ -/* */ -/* Binding keys */ -/* */ -/* **************************************************************** */ - -/* rl_add_defun (char *name, Function *function, int key) - Add NAME to the list of named functions. Make FUNCTION - be the function that gets called. - If KEY is not -1, then bind it. */ -rl_add_defun (name, function, key) - char *name; - Function *function; - int key; -{ - if (key != -1) - rl_bind_key (key, function); - rl_add_funmap_entry (name, function); -} - -/* Bind KEY to FUNCTION. Returns non-zero if KEY is out of range. */ -int -rl_bind_key (key, function) - int key; - Function *function; -{ - if (key < 0) - return (key); - - if (key > 127 && key < 256) - { - if (keymap[ESC].type == ISKMAP) - { - Keymap escmap = (Keymap)keymap[ESC].function; - - key -= 128; - escmap[key].type = ISFUNC; - escmap[key].function = function; - return (0); - } - return (key); - } - - keymap[key].type = ISFUNC; - keymap[key].function = function; - return (0); -} - -/* Bind KEY to FUNCTION in MAP. Returns non-zero in case of invalid - KEY. */ -int -rl_bind_key_in_map (key, function, map) - int key; - Function *function; - Keymap map; -{ - int result; - Keymap oldmap = keymap; - - keymap = map; - result = rl_bind_key (key, function); - keymap = oldmap; - return (result); -} - -/* Make KEY do nothing in the currently selected keymap. - Returns non-zero in case of error. */ -int -rl_unbind_key (key) - int key; -{ - return (rl_bind_key (key, (Function *)NULL)); -} - -/* Make KEY do nothing in MAP. - Returns non-zero in case of error. */ -int -rl_unbind_key_in_map (key, map) - int key; - Keymap map; -{ - return (rl_bind_key_in_map (key, (Function *)NULL, map)); -} - -/* Bind the key sequence represented by the string KEYSEQ to - FUNCTION. This makes new keymaps as necessary. The initial - place to do bindings is in MAP. */ -rl_set_key (keyseq, function, map) - char *keyseq; - Function *function; - Keymap map; -{ - rl_generic_bind (ISFUNC, keyseq, function, map); -} - -/* Bind the key sequence represented by the string KEYSEQ to - the string of characters MACRO. This makes new keymaps as - necessary. The initial place to do bindings is in MAP. */ -rl_macro_bind (keyseq, macro, map) - char *keyseq, *macro; - Keymap map; -{ - char *macro_keys = (char *)xmalloc (2 * (strlen (macro))); - int macro_keys_len; - - if (rl_translate_keyseq (macro, macro_keys, ¯o_keys_len)) - { - free (macro_keys); - return; - } - rl_generic_bind (ISMACR, keyseq, macro_keys, map); -} - -/* Bind the key sequence represented by the string KEYSEQ to - the arbitrary pointer DATA. TYPE says what kind of data is - pointed to by DATA, right now this can be a function (ISFUNC), - a macro (ISMACR), or a keymap (ISKMAP). This makes new keymaps - as necessary. The initial place to do bindings is in MAP. */ -rl_generic_bind (type, keyseq, data, map) - int type; - char *keyseq, *data; - Keymap map; -{ - char *keys; - int keys_len; - register int i; - int start; - - /* If no keys to bind to, exit right away. */ - if (!keyseq || !*keyseq) - { - if (type == ISMACR) - free (data); - return; - } - - keys = (char *)alloca (1 + (2 * strlen (keyseq))); - - /* Translate the ASCII representation of KEYSEQ into an array - of characters. Stuff the characters into ARRAY, and the - length of ARRAY into LENGTH. */ - if (rl_translate_keyseq (keyseq, keys, &keys_len)) - return; - - /* Handle mapping of the ESC Key in vi mode */ - start = 0; -#ifdef VI_MODE - if ((rl_editing_mode == vi_mode) && (keys[0] == ESC)) - { - start++; - map = vi_movement_keymap; - if(keys[1] == ESC) - { - extern KEYMAP_ENTRY_ARRAY vi_escape_keymap; - - start++; - map = vi_escape_keymap; - } - } -#endif - - /* Bind keys, making new keymaps as necessary. */ - for (i = start; i < keys_len; i++) - { - if (i + 1 < keys_len) - { - if (map[keys[i]].type != ISKMAP) - { - if (map[i].type == ISMACR) - free ((char *)map[i].function); - - map[keys[i]].type = ISKMAP; - map[keys[i]].function = (Function *)rl_make_bare_keymap (); - } - map = (Keymap)map[keys[i]].function; - } - else - { - if (map[keys[i]].type == ISMACR) - free ((char *)map[keys[i]].function); - - map[keys[i]].function = (Function *)data; - map[keys[i]].type = type; - } - } -} - -/* Translate the ASCII representation of SEQ, stuffing the - values into ARRAY, an array of characters. LEN gets the - final length of ARRAY. Return non-zero if there was an - error parsing SEQ. */ -rl_translate_keyseq (seq, array, len) - char *seq, *array; - int *len; -{ - register int i, c, l = 0; - - for (i = 0; c = seq[i]; i++) - { - if (c == '\\') - { - c = seq[++i]; - - if (!c) - break; - - if (((c == 'C' || c == 'M') && seq[i + 1] == '-') || - (c == 'e')) - { - /* Handle special case of backwards define. */ - if (strncmp (&seq[i], "C-\\M-", 5) == 0) - { - array[l++] = ESC; - i += 5; - array[l++] = CTRL (to_upper (seq[i])); - if (!seq[i]) - i--; - continue; - } - - switch (c) - { - case 'M': - i++; - array[l++] = ESC; - break; - - case 'C': - i += 2; - array[l++] = CTRL (to_upper (seq[i])); - break; - - case 'e': - array[l++] = ESC; - } - - continue; - } - } - array[l++] = c; - } - - array[l] = '\0'; - *len = l; - return (0); -} - -/* Return a pointer to the function that STRING represents. - If STRING doesn't have a matching function, then a NULL pointer - is returned. */ -Function * -rl_named_function (string) - char *string; -{ - register int i; - static int stricmp (); - - for (i = 0; funmap[i]; i++) - if (stricmp (funmap[i]->name, string) == 0) - return (funmap[i]->function); - return ((Function *)NULL); -} - -/* The last key bindings file read. */ -static char *last_readline_init_file = "~/.inputrc"; - -/* Re-read the current keybindings file. */ -rl_re_read_init_file (count, ignore) - int count, ignore; -{ - rl_read_init_file (last_readline_init_file); -} - -/* Do key bindings from a file. If FILENAME is NULL it defaults - to `~/.inputrc'. If the file existed and could be opened and - read, 0 is returned, otherwise errno is returned. */ -int -rl_read_init_file (filename) - char *filename; -{ - int line_size, line_index; - char *line = (char *)xmalloc (line_size = 100); - char *openname; - FILE *file; - - int c; - - /* Default the filename. */ - if (!filename) - filename = "~/.inputrc"; - - openname = tilde_expand (filename); - - /* Open the file. */ - file = fopen (openname, "r"); - free (openname); - - if (!file) - return (errno); - - last_readline_init_file = filename; - - /* Loop reading lines from the file. Lines that start with `#' are - comments, all other lines are commands for readline initialization. */ - while ((c = getc(file)) != EOF) - { - /* If comment, flush to EOL. */ - if (c == '#') - { - while ((c = getc(file)) != EOF && c != '\n'); - if (c == EOF) - goto function_exit; - continue; - } - - /* Otherwise, this is the start of a line. Read the - line from the file. */ - line_index = 0; - while (c != EOF && c != '\n') - { - line[line_index++] = c; - if (line_index == line_size) - line = (char *)xrealloc (line, line_size += 100); - c = getc (file); - } - line[line_index] = '\0'; - - /* Parse the line. */ - rl_parse_and_bind (line); - } - -function_exit: - - free (line); - /* Close up the file and exit. */ - fclose (file); - return (0); -} - - -/* **************************************************************** */ -/* */ -/* Parser Directives */ -/* */ -/* **************************************************************** */ - -/* Conditionals. */ - -/* Calling programs set this to have their argv[0]. */ -char *rl_readline_name = "other"; - -/* Stack of previous values of parsing_conditionalized_out. */ -static unsigned char *if_stack = (unsigned char *)NULL; -static int if_stack_depth = 0; -static int if_stack_size = 0; - -/* Push parsing_conditionalized_out, and set parser state based on ARGS. */ -parser_if (args) - char *args; -{ - register int i; - static int stricmp (); - - /* Push parser state. */ - if (if_stack_depth + 1 >= if_stack_size) - { - if (!if_stack) - if_stack = (unsigned char *)xmalloc (if_stack_size = 20); - else - if_stack = (unsigned char *)xrealloc (if_stack, if_stack_size += 20); - } - if_stack[if_stack_depth++] = parsing_conditionalized_out; - - /* We only check to see if the first word in ARGS is the same as the - value stored in rl_readline_name. */ - - /* Isolate first argument. */ - for (i = 0; args[i] && !whitespace (args[i]); i++); - - if (args[i]) - args[i++] = '\0'; - - if (stricmp (args, rl_readline_name) == 0) - parsing_conditionalized_out = 0; - else - parsing_conditionalized_out = 1; -} - -/* Invert the current parser state if there is anything on the stack. */ -parser_else (args) - char *args; -{ - if (if_stack_depth) - parsing_conditionalized_out = !parsing_conditionalized_out; - else - { - /* *** What, no error message? *** */ - } -} - -/* Terminate a conditional, popping the value of - parsing_conditionalized_out from the stack. */ -parser_endif (args) - char *args; -{ - if (if_stack_depth) - parsing_conditionalized_out = if_stack[--if_stack_depth]; - else - { - /* *** What, no error message? *** */ - } -} - -/* Associate textual names with actual functions. */ -static struct { - char *name; - Function *function; -} parser_directives [] = { - { "if", parser_if }, - { "endif", parser_endif }, - { "else", parser_else }, - { (char *)0x0, (Function *)0x0 } -}; - -/* Handle a parser directive. STATEMENT is the line of the directive - without any leading `$'. */ -static int -handle_parser_directive (statement) - char *statement; -{ - register int i; - char *directive, *args; - static int stricmp (); - - /* Isolate the actual directive. */ - - /* Skip whitespace. */ - for (i = 0; whitespace (statement[i]); i++); - - directive = &statement[i]; - - for (; statement[i] && !whitespace (statement[i]); i++); - - if (statement[i]) - statement[i++] = '\0'; - - for (; statement[i] && whitespace (statement[i]); i++); - - args = &statement[i]; - - /* Lookup the command, and act on it. */ - for (i = 0; parser_directives[i].name; i++) - if (stricmp (directive, parser_directives[i].name) == 0) - { - (*parser_directives[i].function) (args); - return (0); - } - - /* *** Should an error message be output? */ - return (1); -} - -/* Read the binding command from STRING and perform it. - A key binding command looks like: Keyname: function-name\0, - a variable binding command looks like: set variable value. - A new-style keybinding looks like "\C-x\C-x": exchange-point-and-mark. */ -rl_parse_and_bind (string) - char *string; -{ - extern char *possible_control_prefixes[], *possible_meta_prefixes[]; - char *funname, *kname; - static int substring_member_of_array (), stricmp (); - register int c; - int key, i; - - if (!string || !*string || *string == '#') - return; - - /* If this is a parser directive, act on it. */ - if (*string == '$') - { - handle_parser_directive (&string[1]); - return; - } - - /* If we are supposed to be skipping parsing right now, then do it. */ - if (parsing_conditionalized_out) - return; - - i = 0; - /* If this keyname is a complex key expression surrounded by quotes, - advance to after the matching close quote. */ - if (*string == '"') - { - for (i = 1; c = string[i]; i++) - { - if (c == '"' && string[i - 1] != '\\') - break; - } - } - - /* Advance to the colon (:) or whitespace which separates the two objects. */ - for (; (c = string[i]) && c != ':' && c != ' ' && c != '\t'; i++ ); - - /* Mark the end of the command (or keyname). */ - if (string[i]) - string[i++] = '\0'; - - /* If this is a command to set a variable, then do that. */ - if (stricmp (string, "set") == 0) - { - char *var = string + i; - char *value; - - /* Make VAR point to start of variable name. */ - while (*var && whitespace (*var)) var++; - - /* Make value point to start of value string. */ - value = var; - while (*value && !whitespace (*value)) value++; - if (*value) - *value++ = '\0'; - while (*value && whitespace (*value)) value++; - - rl_variable_bind (var, value); - return; - } - - /* Skip any whitespace between keyname and funname. */ - for (; string[i] && whitespace (string[i]); i++); - funname = &string[i]; - - /* Now isolate funname. - For straight function names just look for whitespace, since - that will signify the end of the string. But this could be a - macro definition. In that case, the string is quoted, so skip - to the matching delimiter. */ - if (*funname == '\'' || *funname == '"') - { - int delimiter = string[i++]; - - for (; c = string[i]; i++) - { - if (c == delimiter && string[i - 1] != '\\') - break; - } - if (c) - i++; - } - - /* Advance to the end of the string. */ - for (; string[i] && !whitespace (string[i]); i++); - - /* No extra whitespace at the end of the string. */ - string[i] = '\0'; - - /* If this is a new-style key-binding, then do the binding with - rl_set_key (). Otherwise, let the older code deal with it. */ - if (*string == '"') - { - char *seq = (char *)alloca (1 + strlen (string)); - register int j, k = 0; - - for (j = 1; string[j]; j++) - { - if (string[j] == '"' && string[j - 1] != '\\') - break; - - seq[k++] = string[j]; - } - seq[k] = '\0'; - - /* Binding macro? */ - if (*funname == '\'' || *funname == '"') - { - j = strlen (funname); - - if (j && funname[j - 1] == *funname) - funname[j - 1] = '\0'; - - rl_macro_bind (seq, &funname[1], keymap); - } - else - rl_set_key (seq, rl_named_function (funname), keymap); - - return; - } - - /* Get the actual character we want to deal with. */ - kname = rindex (string, '-'); - if (!kname) - kname = string; - else - kname++; - - key = glean_key_from_name (kname); - - /* Add in control and meta bits. */ - if (substring_member_of_array (string, possible_control_prefixes)) - key = CTRL (to_upper (key)); - - if (substring_member_of_array (string, possible_meta_prefixes)) - key = META (key); - - /* Temporary. Handle old-style keyname with macro-binding. */ - if (*funname == '\'' || *funname == '"') - { - char seq[2]; - int fl = strlen (funname); - - seq[0] = key; seq[1] = '\0'; - if (fl && funname[fl - 1] == *funname) - funname[fl - 1] = '\0'; - - rl_macro_bind (seq, &funname[1], keymap); - } - else - rl_bind_key (key, rl_named_function (funname)); -} - -rl_variable_bind (name, value) - char *name, *value; -{ - static int strnicmp (), stricmp (); - - if (stricmp (name, "editing-mode") == 0) - { - if (strnicmp (value, "vi", 2) == 0) - { -#ifdef VI_MODE - keymap = vi_insertion_keymap; - rl_editing_mode = vi_mode; -#endif /* VI_MODE */ - } - else if (strnicmp (value, "emacs", 5) == 0) - { - keymap = emacs_standard_keymap; - rl_editing_mode = emacs_mode; - } - } - else if (stricmp (name, "horizontal-scroll-mode") == 0) - { - if (!*value || stricmp (value, "On") == 0) - horizontal_scroll_mode = 1; - else - horizontal_scroll_mode = 0; - } -} - -/* Return the character which matches NAME. - For example, `Space' returns ' '. */ - -typedef struct { - char *name; - int value; -} assoc_list; - -assoc_list name_key_alist[] = { - { "Space", ' ' }, - { "SPC", ' ' }, - { "Rubout", 0x7f }, - { "DEL", 0x7f }, - { "Tab", 0x09 }, - { "Newline", '\n' }, - { "Return", '\r' }, - { "RET", '\r' }, - { "LFD", '\n' }, - { "Escape", '\033' }, - { "ESC", '\033' }, - - { (char *)0x0, 0 } -}; - -int -glean_key_from_name (name) - char *name; -{ - register int i; - static int stricmp (); - - for (i = 0; name_key_alist[i].name; i++) - if (stricmp (name, name_key_alist[i].name) == 0) - return (name_key_alist[i].value); - - return (*name); -} - - -/* **************************************************************** */ -/* */ -/* String Utility Functions */ -/* */ -/* **************************************************************** */ - -/* Return non-zero if any members of ARRAY are a substring in STRING. */ -static int -substring_member_of_array (string, array) - char *string, **array; -{ - static char *strindex (); - - while (*array) - { - if (strindex (string, *array)) - return (1); - array++; - } - return (0); -} - -/* Whoops, Unix doesn't have strnicmp. */ - -/* Compare at most COUNT characters from string1 to string2. Case - doesn't matter. */ -static int -strnicmp (string1, string2, count) - char *string1, *string2; -{ - register char ch1, ch2; - - while (count) { - ch1 = *string1++; - ch2 = *string2++; - if (to_upper(ch1) == to_upper(ch2)) - count--; - else break; - } - return (count); -} - -/* strcmp (), but caseless. */ -static int -stricmp (string1, string2) - char *string1, *string2; -{ - register char ch1, ch2; - - while (*string1 && *string2) { - ch1 = *string1++; - ch2 = *string2++; - if (to_upper(ch1) != to_upper(ch2)) - return (1); - } - return (*string1 | *string2); -} - -/* Determine if s2 occurs in s1. If so, return a pointer to the - match in s1. The compare is case insensitive. */ -static char * -strindex (s1, s2) - register char *s1, *s2; -{ - register int i, l = strlen (s2); - register int len = strlen (s1); - - for (i = 0; (len - i) >= l; i++) - if (strnicmp (&s1[i], s2, l) == 0) - return (s1 + i); - return ((char *)NULL); -} - - -#ifdef STATIC_MALLOC - -/* **************************************************************** */ -/* */ -/* xmalloc and xrealloc () */ -/* */ -/* **************************************************************** */ - -static char * -xmalloc (bytes) - int bytes; -{ - static memory_error_and_abort (); - char *temp = (char *)malloc (bytes); - - if (!temp) - memory_error_and_abort (); - return (temp); -} - -static char * -xrealloc (pointer, bytes) - char *pointer; - int bytes; -{ - static memory_error_and_abort (); - char *temp = (char *)realloc (pointer, bytes); - - if (!temp) - memory_error_and_abort (); - return (temp); -} - -static -memory_error_and_abort () -{ - fprintf (stderr, "readline: Out of virtual memory!\n"); - abort (); -} -#endif /* STATIC_MALLOC */ - - -/* **************************************************************** */ -/* */ -/* Testing Readline */ -/* */ -/* **************************************************************** */ - -#ifdef TEST - -main () -{ - HIST_ENTRY **history_list (); - char *temp = (char *)NULL; - char *prompt = "readline% "; - int done = 0; - - while (!done) - { - temp = readline (prompt); - - /* Test for EOF. */ - if (!temp) - exit (1); - - /* If there is anything on the line, print it and remember it. */ - if (*temp) - { - fprintf (stderr, "%s\r\n", temp); - add_history (temp); - } - - /* Check for `command' that we handle. */ - if (strcmp (temp, "quit") == 0) - done = 1; - - if (strcmp (temp, "list") == 0) { - HIST_ENTRY **list = history_list (); - register int i; - if (list) { - for (i = 0; list[i]; i++) { - fprintf (stderr, "%d: %s\r\n", i, list[i]->line); - free (list[i]->line); - } - free (list); - } - } - free (temp); - } -} - -#endif /* TEST */ - - -/* - * Local variables: - * compile-command: "gcc -g -traditional -I. -I.. -DTEST -o readline readline.c keymaps.o funmap.o history.o -ltermcap" - * end: - */ diff --git a/gnu/usr.bin/gdb/readline/readline.h b/gnu/usr.bin/gdb/readline/readline.h deleted file mode 100644 index 7d7fbe7..0000000 --- a/gnu/usr.bin/gdb/readline/readline.h +++ /dev/null @@ -1,161 +0,0 @@ -/* Readline.h -- the names of functions callable from within readline. */ - -#ifndef _READLINE_H_ -#define _READLINE_H_ - -#include - -#ifndef __FUNCTION_DEF -typedef int Function (); -#define __FUNCTION_DEF -#endif - -/* The functions for manipulating the text of the line within readline. -Most of these functions are bound to keys by default. */ -extern int -rl_beg_of_line (), rl_backward (), rl_delete (), rl_end_of_line (), -rl_forward (), ding (), rl_backward (), rl_newline (), rl_kill_line (), -rl_clear_screen (), rl_get_next_history (), rl_get_previous_history (), -rl_quoted_insert (), rl_reverse_search_history (), rl_transpose_chars -(), rl_unix_line_discard (), rl_quoted_insert (), rl_unix_word_rubout -(), rl_yank (), rl_rubout (), rl_backward_word (), rl_kill_word (), -rl_forward_word (), rl_tab_insert (), rl_yank_pop (), rl_yank_nth_arg (), -rl_backward_kill_word (), rl_backward_kill_line (), rl_transpose_words -(), rl_complete (), rl_possible_completions (), rl_do_lowercase_version -(), rl_digit_argument (), rl_universal_argument (), rl_abort (), -rl_undo_command (), rl_revert_line (), rl_beginning_of_history (), -rl_end_of_history (), rl_forward_search_history (), rl_insert (), -rl_upcase_word (), rl_downcase_word (), rl_capitalize_word (), -rl_restart_output (), rl_re_read_init_file (); - -/* These are *both* defined even when VI_MODE is not. */ -extern int rl_vi_editing_mode (), rl_emacs_editing_mode (); - -#ifdef VI_MODE -/* Things for vi mode. */ -extern int rl_vi_movement_mode (), rl_vi_insertion_mode (), rl_vi_arg_digit (), -rl_vi_prev_word (), rl_vi_next_word (), rl_vi_char_search (), -rl_vi_eof_maybe (), rl_vi_append_mode (), rl_vi_put (), -rl_vi_append_eol (), rl_vi_insert_beg (), rl_vi_delete (), rl_vi_comment (), -rl_vi_first_print (), rl_vi_fword (), rl_vi_fWord (), rl_vi_bword (), -rl_vi_bWord (), rl_vi_eword (), rl_vi_eWord (), rl_vi_end_word (), -rl_vi_change_case (), rl_vi_match (), rl_vi_bracktype (), rl_vi_change_char (), -rl_vi_yank_arg (), rl_vi_search (), rl_vi_search_again (), -rl_vi_dosearch (), rl_vi_subst (), rl_vi_overstrike (), -rl_vi_overstrike_delete (), rl_vi_replace(), rl_vi_column (), -rl_vi_delete_to (), rl_vi_change_to (), rl_vi_yank_to (), rl_vi_complete (); -#endif /* VI_MODE */ - -/* Keyboard macro commands. */ -extern int -rl_start_kbd_macro (), rl_end_kbd_macro (), rl_call_last_kbd_macro (); - -/* Maintaining the state of undo. We remember individual deletes and inserts - on a chain of things to do. */ - -/* The actions that undo knows how to undo. Notice that UNDO_DELETE means - to insert some text, and UNDO_INSERT means to delete some text. I.e., - the code tells undo what to undo, not how to undo it. */ -enum undo_code { UNDO_DELETE, UNDO_INSERT, UNDO_BEGIN, UNDO_END }; - -/* What an element of THE_UNDO_LIST looks like. */ -typedef struct undo_list { - struct undo_list *next; - int start, end; /* Where the change took place. */ - char *text; /* The text to insert, if undoing a delete. */ - enum undo_code what; /* Delete, Insert, Begin, End. */ -} UNDO_LIST; - -/* The current undo list for RL_LINE_BUFFER. */ -extern UNDO_LIST *rl_undo_list; - -/* The data structure for mapping textual names to code addresses. */ -typedef struct { - char *name; - Function *function; -} FUNMAP; - -extern FUNMAP **funmap; - -/* **************************************************************** */ -/* */ -/* Well Published Variables */ -/* */ -/* **************************************************************** */ - -/* The name of the calling program. You should initialize this to - whatever was in argv[0]. It is used when parsing conditionals. */ -extern char *rl_readline_name; - -/* The line buffer that is in use. */ -extern char *rl_line_buffer; - -/* The location of point, and end. */ -extern int rl_point, rl_end; - -/* The name of the terminal to use. */ -extern char *rl_terminal_name; - -/* The input and output streams. */ -extern FILE *rl_instream, *rl_outstream; - -/* The basic list of characters that signal a break between words for the - completer routine. The contents of this variable is what breaks words - in the shell, i.e. "n\"\\'`@$>". */ -extern char *rl_basic_word_break_characters; - -/* The list of characters that signal a break between words for - rl_complete_internal. The default list is the contents of - rl_basic_word_break_characters. */ -extern char *rl_completer_word_break_characters; - -/* List of characters that are word break characters, but should be left - in TEXT when it is passed to the completion function. The shell uses - this to help determine what kind of completing to do. */ -extern char *rl_special_prefixes; - -/* Pointer to the generator function for completion_matches (). - NULL means to use filename_entry_function (), the default filename - completer. */ -extern Function *rl_completion_entry_function; - -/* Pointer to alternative function to create matches. - Function is called with TEXT, START, and END. - START and END are indices in RL_LINE_BUFFER saying what the boundaries - of TEXT are. - If this function exists and returns NULL then call the value of - rl_completion_entry_function to try to match, otherwise use the - array of strings returned. */ -extern Function *rl_attempted_completion_function; - -/* If non-null, this contains the address of a function to call if the - standard meaning for expanding a tilde fails. The function is called - with the text (sans tilde, as in "foo"), and returns a malloc()'ed string - which is the expansion, or a NULL pointer if there is no expansion. */ -extern Function *rl_tilde_expander; - -/* If non-zero, then this is the address of a function to call just - before readline_internal () prints the first prompt. */ -extern Function *rl_startup_hook; - -/* **************************************************************** */ -/* */ -/* Well Published Functions */ -/* */ -/* **************************************************************** */ - -/* Read a line of input. Prompt with PROMPT. A NULL PROMPT means none. */ -extern char *readline (); - -/* Return an array of strings which are the result of repeatadly calling - FUNC with TEXT. */ -extern char **completion_matches (); - -/* rl_add_defun (char *name, Function *function, int key) - Add NAME to the list of named functions. Make FUNCTION - be the function that gets called. - If KEY is not -1, then bind it. */ -extern int rl_add_defun (); - -#endif /* _READLINE_H_ */ - diff --git a/gnu/usr.bin/gdb/readline/vi_keymap.c b/gnu/usr.bin/gdb/readline/vi_keymap.c deleted file mode 100644 index 71c7ec8..0000000 --- a/gnu/usr.bin/gdb/readline/vi_keymap.c +++ /dev/null @@ -1,484 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - * - * @(#)vi_keymap.c 6.4 (Berkeley) 5/8/91 - */ - -/* vi_keymap.c -- the keymap for vi_mode in readline (). */ - -/* Copyright (C) 1988,1989 Free Software Foundation, Inc. - - This file is part of GNU Readline, a library for reading lines - of text with interactive input and history editing. - - Readline 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 1, or (at your option) any - later version. - - Readline 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 Readline; see the file COPYING. If not, write to the Free - Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef FILE -#include -#endif /* FILE */ - -#include "readline.h" - -extern KEYMAP_ENTRY_ARRAY vi_escape_keymap; - -/* The keymap arrays for handling vi mode. */ -KEYMAP_ENTRY_ARRAY vi_movement_keymap = { - - /* The regular control keys come first. */ - { ISFUNC, (Function *)0x0 }, /* Control-@ */ - { ISFUNC, (Function *)0x0 }, /* Control-a */ - { ISFUNC, (Function *)0x0 }, /* Control-b */ - { ISFUNC, (Function *)0x0 }, /* Control-c */ - { ISFUNC, rl_vi_eof_maybe }, /* Control-d */ - { ISFUNC, rl_emacs_editing_mode }, /* Control-e */ - { ISFUNC, (Function *)0x0 }, /* Control-f */ - { ISFUNC, rl_abort }, /* Control-g */ - { ISFUNC, rl_backward }, /* Control-h */ - { ISFUNC, (Function *)0x0 }, /* Control-i */ - { ISFUNC, rl_newline }, /* Control-j */ - { ISFUNC, rl_kill_line }, /* Control-k */ - { ISFUNC, rl_clear_screen }, /* Control-l */ - { ISFUNC, rl_newline }, /* Control-m */ - { ISFUNC, rl_get_next_history }, /* Control-n */ - { ISFUNC, (Function *)0x0 }, /* Control-o */ - { ISFUNC, rl_get_previous_history }, /* Control-p */ - { ISFUNC, rl_quoted_insert }, /* Control-q */ - { ISFUNC, rl_reverse_search_history }, /* Control-r */ - { ISFUNC, rl_forward_search_history }, /* Control-s */ - { ISFUNC, rl_transpose_chars }, /* Control-t */ - { ISFUNC, rl_unix_line_discard }, /* Control-u */ - { ISFUNC, rl_quoted_insert }, /* Control-v */ - { ISFUNC, rl_unix_word_rubout }, /* Control-w */ - { ISFUNC, (Function *)0x0 }, /* Control-x */ - { ISFUNC, rl_yank }, /* Control-y */ - { ISFUNC, (Function *)0x0 }, /* Control-z */ - - { ISKMAP, (Function *)vi_escape_keymap }, /* Control-[ */ - { ISFUNC, (Function *)0x0 }, /* Control-\ */ - { ISFUNC, (Function *)0x0 }, /* Control-] */ - { ISFUNC, (Function *)0x0 }, /* Control-^ */ - { ISFUNC, rl_undo_command }, /* Control-_ */ - - /* The start of printing characters. */ - { ISFUNC, rl_forward }, /* SPACE */ - { ISFUNC, (Function *)0x0 }, /* ! */ - { ISFUNC, (Function *)0x0 }, /* " */ - { ISFUNC, rl_vi_comment }, /* # */ - { ISFUNC, rl_end_of_line }, /* $ */ - { ISFUNC, rl_vi_match }, /* % */ - { ISFUNC, (Function *)0x0 }, /* & */ - { ISFUNC, (Function *)0x0 }, /* ' */ - { ISFUNC, (Function *)0x0 }, /* ( */ - { ISFUNC, (Function *)0x0 }, /* ) */ - { ISFUNC, rl_vi_complete }, /* * */ - { ISFUNC, rl_get_previous_history}, /* + */ - { ISFUNC, rl_vi_char_search }, /* , */ - { ISFUNC, rl_get_next_history }, /* - */ - { ISFUNC, (Function *)0x0 }, /* . */ - { ISFUNC, rl_vi_search }, /* / */ - - /* Regular digits. */ - { ISFUNC, rl_vi_arg_digit }, /* 0 */ - { ISFUNC, rl_vi_arg_digit }, /* 1 */ - { ISFUNC, rl_vi_arg_digit }, /* 2 */ - { ISFUNC, rl_vi_arg_digit }, /* 3 */ - { ISFUNC, rl_vi_arg_digit }, /* 4 */ - { ISFUNC, rl_vi_arg_digit }, /* 5 */ - { ISFUNC, rl_vi_arg_digit }, /* 6 */ - { ISFUNC, rl_vi_arg_digit }, /* 7 */ - { ISFUNC, rl_vi_arg_digit }, /* 8 */ - { ISFUNC, rl_vi_arg_digit }, /* 9 */ - - /* A little more punctuation. */ - { ISFUNC, (Function *)0x0 }, /* : */ - { ISFUNC, rl_vi_char_search }, /* ; */ - { ISFUNC, (Function *)0x0 }, /* < */ - { ISFUNC, (Function *)0x0 }, /* = */ - { ISFUNC, (Function *)0x0 }, /* > */ - { ISFUNC, rl_vi_search }, /* ? */ - { ISFUNC, (Function *)0x0 }, /* @ */ - - /* Uppercase alphabet. */ - { ISFUNC, rl_vi_append_eol }, /* A */ - { ISFUNC, rl_vi_prev_word}, /* B */ - { ISFUNC, rl_vi_change_to }, /* C */ - { ISFUNC, rl_vi_delete_to }, /* D */ - { ISFUNC, rl_vi_end_word }, /* E */ - { ISFUNC, rl_vi_char_search }, /* F */ - { ISFUNC, (Function *)0x0 }, /* G */ - { ISFUNC, (Function *)0x0 }, /* H */ - { ISFUNC, rl_vi_insert_beg }, /* I */ - { ISFUNC, (Function *)0x0 }, /* J */ - { ISFUNC, (Function *)0x0 }, /* K */ - { ISFUNC, (Function *)0x0 }, /* L */ - { ISFUNC, (Function *)0x0 }, /* M */ - { ISFUNC, rl_vi_search_again }, /* N */ - { ISFUNC, (Function *)0x0 }, /* O */ - { ISFUNC, rl_vi_put }, /* P */ - { ISFUNC, (Function *)0x0 }, /* Q */ - { ISFUNC, rl_vi_replace }, /* R */ - { ISFUNC, rl_vi_subst }, /* S */ - { ISFUNC, rl_vi_char_search }, /* T */ - { ISFUNC, rl_revert_line }, /* U */ - { ISFUNC, (Function *)0x0 }, /* V */ - { ISFUNC, rl_vi_next_word }, /* W */ - { ISFUNC, rl_rubout }, /* X */ - { ISFUNC, rl_vi_yank_to }, /* Y */ - { ISFUNC, (Function *)0x0 }, /* Z */ - - /* Some more punctuation. */ - { ISFUNC, (Function *)0x0 }, /* [ */ - { ISFUNC, (Function *)0x0 }, /* \ */ - { ISFUNC, (Function *)0x0 }, /* ] */ - { ISFUNC, rl_vi_first_print }, /* ^ */ - { ISFUNC, rl_vi_yank_arg }, /* _ */ - { ISFUNC, (Function *)0x0 }, /* ` */ - - /* Lowercase alphabet. */ - { ISFUNC, rl_vi_append_mode }, /* a */ - { ISFUNC, rl_vi_prev_word }, /* b */ - { ISFUNC, rl_vi_change_to }, /* c */ - { ISFUNC, rl_vi_delete_to }, /* d */ - { ISFUNC, rl_vi_end_word }, /* e */ - { ISFUNC, rl_vi_char_search }, /* f */ - { ISFUNC, (Function *)0x0 }, /* g */ - { ISFUNC, rl_backward }, /* h */ - { ISFUNC, rl_vi_insertion_mode }, /* i */ - { ISFUNC, rl_get_next_history }, /* j */ - { ISFUNC, rl_get_previous_history }, /* k */ - { ISFUNC, rl_forward }, /* l */ - { ISFUNC, (Function *)0x0 }, /* m */ - { ISFUNC, rl_vi_search_again }, /* n */ - { ISFUNC, (Function *)0x0 }, /* o */ - { ISFUNC, rl_vi_put }, /* p */ - { ISFUNC, (Function *)0x0 }, /* q */ - { ISFUNC, rl_vi_change_char }, /* r */ - { ISFUNC, rl_vi_subst }, /* s */ - { ISFUNC, rl_vi_char_search }, /* t */ - { ISFUNC, rl_undo_command }, /* u */ - { ISFUNC, (Function *)0x0 }, /* v */ - { ISFUNC, rl_vi_next_word }, /* w */ - { ISFUNC, rl_vi_delete }, /* x */ - { ISFUNC, rl_vi_yank_to }, /* y */ - { ISFUNC, (Function *)0x0 }, /* z */ - - /* Final punctuation. */ - { ISFUNC, (Function *)0x0 }, /* { */ - { ISFUNC, rl_vi_column }, /* | */ - { ISFUNC, (Function *)0x0 }, /* } */ - { ISFUNC, rl_vi_change_case }, /* ~ */ - { ISFUNC, rl_backward } /* RUBOUT */ -}; - - -KEYMAP_ENTRY_ARRAY vi_insertion_keymap = { - - /* The regular control keys come first. */ - { ISFUNC, (Function *)0x0 }, /* Control-@ */ - { ISFUNC, rl_insert }, /* Control-a */ - { ISFUNC, rl_insert }, /* Control-b */ - { ISFUNC, rl_insert }, /* Control-c */ - { ISFUNC, rl_vi_eof_maybe }, /* Control-d */ - { ISFUNC, rl_insert }, /* Control-e */ - { ISFUNC, rl_insert }, /* Control-f */ - { ISFUNC, rl_insert }, /* Control-g */ - { ISFUNC, rl_rubout }, /* Control-h */ - { ISFUNC, rl_complete }, /* Control-i */ - { ISFUNC, rl_newline }, /* Control-j */ - { ISFUNC, rl_insert }, /* Control-k */ - { ISFUNC, rl_insert }, /* Control-l */ - { ISFUNC, rl_newline }, /* Control-m */ - { ISFUNC, rl_insert }, /* Control-n */ - { ISFUNC, rl_insert }, /* Control-o */ - { ISFUNC, rl_insert }, /* Control-p */ - { ISFUNC, rl_insert }, /* Control-q */ - { ISFUNC, rl_reverse_search_history }, /* Control-r */ - { ISFUNC, rl_forward_search_history }, /* Control-s */ - { ISFUNC, rl_transpose_chars }, /* Control-t */ - { ISFUNC, rl_unix_line_discard }, /* Control-u */ - { ISFUNC, rl_quoted_insert }, /* Control-v */ - { ISFUNC, rl_unix_word_rubout }, /* Control-w */ - { ISFUNC, rl_insert }, /* Control-x */ - { ISFUNC, rl_yank }, /* Control-y */ - { ISFUNC, rl_insert }, /* Control-z */ - - { ISFUNC, rl_vi_movement_mode }, /* Control-[ */ - { ISFUNC, rl_insert }, /* Control-\ */ - { ISFUNC, rl_insert }, /* Control-] */ - { ISFUNC, rl_insert }, /* Control-^ */ - { ISFUNC, rl_undo_command }, /* Control-_ */ - - /* The start of printing characters. */ - { ISFUNC, rl_insert }, /* SPACE */ - { ISFUNC, rl_insert }, /* ! */ - { ISFUNC, rl_insert }, /* " */ - { ISFUNC, rl_insert }, /* # */ - { ISFUNC, rl_insert }, /* $ */ - { ISFUNC, rl_insert }, /* % */ - { ISFUNC, rl_insert }, /* & */ - { ISFUNC, rl_insert }, /* ' */ - { ISFUNC, rl_insert }, /* ( */ - { ISFUNC, rl_insert }, /* ) */ - { ISFUNC, rl_insert }, /* * */ - { ISFUNC, rl_insert }, /* + */ - { ISFUNC, rl_insert }, /* , */ - { ISFUNC, rl_insert }, /* - */ - { ISFUNC, rl_insert }, /* . */ - { ISFUNC, rl_insert }, /* / */ - - /* Regular digits. */ - { ISFUNC, rl_insert }, /* 0 */ - { ISFUNC, rl_insert }, /* 1 */ - { ISFUNC, rl_insert }, /* 2 */ - { ISFUNC, rl_insert }, /* 3 */ - { ISFUNC, rl_insert }, /* 4 */ - { ISFUNC, rl_insert }, /* 5 */ - { ISFUNC, rl_insert }, /* 6 */ - { ISFUNC, rl_insert }, /* 7 */ - { ISFUNC, rl_insert }, /* 8 */ - { ISFUNC, rl_insert }, /* 9 */ - - /* A little more punctuation. */ - { ISFUNC, rl_insert }, /* : */ - { ISFUNC, rl_insert }, /* ; */ - { ISFUNC, rl_insert }, /* < */ - { ISFUNC, rl_insert }, /* = */ - { ISFUNC, rl_insert }, /* > */ - { ISFUNC, rl_insert }, /* ? */ - { ISFUNC, rl_insert }, /* @ */ - - /* Uppercase alphabet. */ - { ISFUNC, rl_insert }, /* A */ - { ISFUNC, rl_insert }, /* B */ - { ISFUNC, rl_insert }, /* C */ - { ISFUNC, rl_insert }, /* D */ - { ISFUNC, rl_insert }, /* E */ - { ISFUNC, rl_insert }, /* F */ - { ISFUNC, rl_insert }, /* G */ - { ISFUNC, rl_insert }, /* H */ - { ISFUNC, rl_insert }, /* I */ - { ISFUNC, rl_insert }, /* J */ - { ISFUNC, rl_insert }, /* K */ - { ISFUNC, rl_insert }, /* L */ - { ISFUNC, rl_insert }, /* M */ - { ISFUNC, rl_insert }, /* N */ - { ISFUNC, rl_insert }, /* O */ - { ISFUNC, rl_insert }, /* P */ - { ISFUNC, rl_insert }, /* Q */ - { ISFUNC, rl_insert }, /* R */ - { ISFUNC, rl_insert }, /* S */ - { ISFUNC, rl_insert }, /* T */ - { ISFUNC, rl_insert }, /* U */ - { ISFUNC, rl_insert }, /* V */ - { ISFUNC, rl_insert }, /* W */ - { ISFUNC, rl_insert }, /* X */ - { ISFUNC, rl_insert }, /* Y */ - { ISFUNC, rl_insert }, /* Z */ - - /* Some more punctuation. */ - { ISFUNC, rl_insert }, /* [ */ - { ISFUNC, rl_insert }, /* \ */ - { ISFUNC, rl_insert }, /* ] */ - { ISFUNC, rl_insert }, /* ^ */ - { ISFUNC, rl_insert }, /* _ */ - { ISFUNC, rl_insert }, /* ` */ - - /* Lowercase alphabet. */ - { ISFUNC, rl_insert }, /* a */ - { ISFUNC, rl_insert }, /* b */ - { ISFUNC, rl_insert }, /* c */ - { ISFUNC, rl_insert }, /* d */ - { ISFUNC, rl_insert }, /* e */ - { ISFUNC, rl_insert }, /* f */ - { ISFUNC, rl_insert }, /* g */ - { ISFUNC, rl_insert }, /* h */ - { ISFUNC, rl_insert }, /* i */ - { ISFUNC, rl_insert }, /* j */ - { ISFUNC, rl_insert }, /* k */ - { ISFUNC, rl_insert }, /* l */ - { ISFUNC, rl_insert }, /* m */ - { ISFUNC, rl_insert }, /* n */ - { ISFUNC, rl_insert }, /* o */ - { ISFUNC, rl_insert }, /* p */ - { ISFUNC, rl_insert }, /* q */ - { ISFUNC, rl_insert }, /* r */ - { ISFUNC, rl_insert }, /* s */ - { ISFUNC, rl_insert }, /* t */ - { ISFUNC, rl_insert }, /* u */ - { ISFUNC, rl_insert }, /* v */ - { ISFUNC, rl_insert }, /* w */ - { ISFUNC, rl_insert }, /* x */ - { ISFUNC, rl_insert }, /* y */ - { ISFUNC, rl_insert }, /* z */ - - /* Final punctuation. */ - { ISFUNC, rl_insert }, /* { */ - { ISFUNC, rl_insert }, /* | */ - { ISFUNC, rl_insert }, /* } */ - { ISFUNC, rl_insert }, /* ~ */ - { ISFUNC, rl_rubout } /* RUBOUT */ -}; - -KEYMAP_ENTRY_ARRAY vi_escape_keymap = { - - /* The regular control keys come first. */ - { ISFUNC, (Function *)0x0 }, /* Control-@ */ - { ISFUNC, (Function *)0x0 }, /* Control-a */ - { ISFUNC, (Function *)0x0 }, /* Control-b */ - { ISFUNC, (Function *)0x0 }, /* Control-c */ - { ISFUNC, (Function *)0x0 }, /* Control-d */ - { ISFUNC, (Function *)0x0 }, /* Control-e */ - { ISFUNC, (Function *)0x0 }, /* Control-f */ - { ISFUNC, (Function *)0x0 }, /* Control-g */ - { ISFUNC, (Function *)0x0 }, /* Control-h */ - { ISFUNC, rl_tab_insert}, /* Control-i */ - { ISFUNC, rl_emacs_editing_mode}, /* Control-j */ - { ISFUNC, rl_kill_line }, /* Control-k */ - { ISFUNC, (Function *)0x0 }, /* Control-l */ - { ISFUNC, rl_emacs_editing_mode}, /* Control-m */ - { ISFUNC, (Function *)0x0 }, /* Control-n */ - { ISFUNC, (Function *)0x0 }, /* Control-o */ - { ISFUNC, (Function *)0x0 }, /* Control-p */ - { ISFUNC, (Function *)0x0 }, /* Control-q */ - { ISFUNC, (Function *)0x0 }, /* Control-r */ - { ISFUNC, (Function *)0x0 }, /* Control-s */ - { ISFUNC, (Function *)0x0 }, /* Control-t */ - { ISFUNC, (Function *)0x0 }, /* Control-u */ - { ISFUNC, (Function *)0x0 }, /* Control-v */ - { ISFUNC, (Function *)0x0 }, /* Control-w */ - { ISFUNC, (Function *)0x0 }, /* Control-x */ - { ISFUNC, (Function *)0x0 }, /* Control-y */ - { ISFUNC, (Function *)0x0 }, /* Control-z */ - - { ISFUNC, rl_vi_movement_mode }, /* Control-[ */ - { ISFUNC, (Function *)0x0 }, /* Control-\ */ - { ISFUNC, (Function *)0x0 }, /* Control-] */ - { ISFUNC, (Function *)0x0 }, /* Control-^ */ - { ISFUNC, rl_undo_command }, /* Control-_ */ - - /* The start of printing characters. */ - { ISFUNC, (Function *)0x0 }, /* SPACE */ - { ISFUNC, (Function *)0x0 }, /* ! */ - { ISFUNC, (Function *)0x0 }, /* " */ - { ISFUNC, (Function *)0x0 }, /* # */ - { ISFUNC, (Function *)0x0 }, /* $ */ - { ISFUNC, (Function *)0x0 }, /* % */ - { ISFUNC, (Function *)0x0 }, /* & */ - { ISFUNC, (Function *)0x0 }, /* ' */ - { ISFUNC, (Function *)0x0 }, /* ( */ - { ISFUNC, (Function *)0x0 }, /* ) */ - { ISFUNC, (Function *)0x0 }, /* * */ - { ISFUNC, (Function *)0x0 }, /* + */ - { ISFUNC, (Function *)0x0 }, /* , */ - { ISFUNC, (Function *)0x0 }, /* - */ - { ISFUNC, (Function *)0x0 }, /* . */ - { ISFUNC, (Function *)0x0 }, /* / */ - - /* Regular digits. */ - { ISFUNC, rl_vi_arg_digit }, /* 0 */ - { ISFUNC, rl_vi_arg_digit }, /* 1 */ - { ISFUNC, rl_vi_arg_digit }, /* 2 */ - { ISFUNC, rl_vi_arg_digit }, /* 3 */ - { ISFUNC, rl_vi_arg_digit }, /* 4 */ - { ISFUNC, rl_vi_arg_digit }, /* 5 */ - { ISFUNC, rl_vi_arg_digit }, /* 6 */ - { ISFUNC, rl_vi_arg_digit }, /* 7 */ - { ISFUNC, rl_vi_arg_digit }, /* 8 */ - { ISFUNC, rl_vi_arg_digit }, /* 9 */ - - /* A little more punctuation. */ - { ISFUNC, (Function *)0x0 }, /* : */ - { ISFUNC, (Function *)0x0 }, /* ; */ - { ISFUNC, (Function *)0x0 }, /* < */ - { ISFUNC, (Function *)0x0 }, /* = */ - { ISFUNC, (Function *)0x0 }, /* > */ - { ISFUNC, (Function *)0x0 }, /* ? */ - { ISFUNC, (Function *)0x0 }, /* @ */ - - /* Uppercase alphabet. */ - { ISFUNC, rl_do_lowercase_version }, /* A */ - { ISFUNC, rl_do_lowercase_version }, /* B */ - { ISFUNC, rl_do_lowercase_version }, /* C */ - { ISFUNC, rl_do_lowercase_version }, /* D */ - { ISFUNC, rl_do_lowercase_version }, /* E */ - { ISFUNC, rl_do_lowercase_version }, /* F */ - { ISFUNC, rl_do_lowercase_version }, /* G */ - { ISFUNC, rl_do_lowercase_version }, /* H */ - { ISFUNC, rl_do_lowercase_version }, /* I */ - { ISFUNC, rl_do_lowercase_version }, /* J */ - { ISFUNC, rl_do_lowercase_version }, /* K */ - { ISFUNC, rl_do_lowercase_version }, /* L */ - { ISFUNC, rl_do_lowercase_version }, /* M */ - { ISFUNC, rl_do_lowercase_version }, /* N */ - { ISFUNC, rl_do_lowercase_version }, /* O */ - { ISFUNC, rl_do_lowercase_version }, /* P */ - { ISFUNC, rl_do_lowercase_version }, /* Q */ - { ISFUNC, rl_do_lowercase_version }, /* R */ - { ISFUNC, rl_do_lowercase_version }, /* S */ - { ISFUNC, rl_do_lowercase_version }, /* T */ - { ISFUNC, rl_do_lowercase_version }, /* U */ - { ISFUNC, rl_do_lowercase_version }, /* V */ - { ISFUNC, rl_do_lowercase_version }, /* W */ - { ISFUNC, rl_do_lowercase_version }, /* X */ - { ISFUNC, rl_do_lowercase_version }, /* Y */ - { ISFUNC, rl_do_lowercase_version }, /* Z */ - - /* Some more punctuation. */ - { ISFUNC, (Function *)0x0 }, /* [ */ - { ISFUNC, (Function *)0x0 }, /* \ */ - { ISFUNC, (Function *)0x0 }, /* ] */ - { ISFUNC, (Function *)0x0 }, /* ^ */ - { ISFUNC, (Function *)0x0 }, /* _ */ - { ISFUNC, (Function *)0x0 }, /* ` */ - - /* Lowercase alphabet. */ - { ISFUNC, (Function *)0x0 }, /* a */ - { ISFUNC, (Function *)0x0 }, /* b */ - { ISFUNC, (Function *)0x0 }, /* c */ - { ISFUNC, (Function *)0x0 }, /* d */ - { ISFUNC, (Function *)0x0 }, /* e */ - { ISFUNC, (Function *)0x0 }, /* f */ - { ISFUNC, (Function *)0x0 }, /* g */ - { ISFUNC, (Function *)0x0 }, /* h */ - { ISFUNC, (Function *)0x0 }, /* i */ - { ISFUNC, (Function *)0x0 }, /* j */ - { ISFUNC, (Function *)0x0 }, /* k */ - { ISFUNC, (Function *)0x0 }, /* l */ - { ISFUNC, (Function *)0x0 }, /* m */ - { ISFUNC, (Function *)0x0 }, /* n */ - { ISFUNC, (Function *)0x0 }, /* o */ - { ISFUNC, (Function *)0x0 }, /* p */ - { ISFUNC, (Function *)0x0 }, /* q */ - { ISFUNC, (Function *)0x0 }, /* r */ - { ISFUNC, (Function *)0x0 }, /* s */ - { ISFUNC, (Function *)0x0 }, /* t */ - { ISFUNC, (Function *)0x0 }, /* u */ - { ISFUNC, (Function *)0x0 }, /* v */ - { ISFUNC, (Function *)0x0 }, /* w */ - { ISFUNC, (Function *)0x0 }, /* x */ - { ISFUNC, (Function *)0x0 }, /* y */ - { ISFUNC, (Function *)0x0 }, /* z */ - - /* Final punctuation. */ - { ISFUNC, (Function *)0x0 }, /* { */ - { ISFUNC, (Function *)0x0 }, /* | */ - { ISFUNC, (Function *)0x0 }, /* } */ - { ISFUNC, (Function *)0x0 }, /* ~ */ - { ISFUNC, rl_backward_kill_word } /* RUBOUT */ -}; diff --git a/gnu/usr.bin/gdb/readline/vi_mode.c b/gnu/usr.bin/gdb/readline/vi_mode.c deleted file mode 100644 index 3a13cc6..0000000 --- a/gnu/usr.bin/gdb/readline/vi_mode.c +++ /dev/null @@ -1,875 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - * - * @(#)vi_mode.c 6.4 (Berkeley) 5/8/91 - */ - -/* vi_mode.c -- A vi emulation mode for Bash. - Mostly written by Jeff Sparkes (jeff1@????). - */ - - -/* **************************************************************** */ -/* */ -/* VI Emulation Mode */ -/* */ -/* **************************************************************** */ - -/* Last string searched for from `/' or `?'. */ -static char *vi_last_search = (char *)NULL; -static int vi_histpos; - -/* *** UNCLEAN *** */ -/* Command keys which do movement for xxx_to commands. */ -static char *vi_motion = " hl^$0ftFt;,%wbeWBE|"; - -/* Keymap used for vi replace characters. Created dynamically since - rarely used. */ -static Keymap vi_replace_map = (Keymap)NULL; - -/* The number of characters inserted in the last replace operation. */ -static vi_replace_count = 0; - -/* Yank the nth arg from the previous line into this line at point. */ -rl_vi_yank_arg (count) - int count; -{ - rl_yank_nth_arg (count); -} - -/* Search again for the last thing searched for. */ -rl_vi_search_again (ignore, key) - int ignore, key; -{ - switch (key) - { - case 'n': - rl_vi_dosearch (vi_last_search, -1); - break; - - case 'N': - rl_vi_dosearch (vi_last_search, 1); - break; - } -} - -/* Do a vi style search. */ -rl_vi_search (count, key) - int count, key; -{ - int dir, c; - char *p; - - switch (key) - { - case '?': - dir = 1; - break; - - case '/': - dir = -1; - break; - - default: - ding (); - return; - } - - vi_histpos = where_history (); - maybe_save_line (); - - /* Reuse the line input buffer to read the search string. */ - the_line[0] = 0; - rl_end = rl_point = 0; - p = (char *)alloca (2 + (rl_prompt ? strlen (rl_prompt) : 0)); - - sprintf (p, "%s%c", rl_prompt ? rl_prompt : "", key); - - rl_message (p); - - while (c = rl_read_key (in_stream)) - { - switch (c) - { - case CTRL('W'): - case CTRL('U'): - case CTRL('H'): - case RUBOUT: - rl_dispatch (c, keymap); - break; - - case ESC: - case RETURN: - case NEWLINE: - goto dosearch; - break; - - case CTRL('C'): - maybe_unsave_line (); - rl_clear_message (); - rl_point = 0; - ding (); - return; - - default: - rl_insert (1, c); - break; - } - rl_redisplay (); - } - dosearch: - if (vi_last_search) - free (vi_last_search); - - vi_last_search = savestring (the_line); - rl_vi_dosearch (the_line, dir); -} - -rl_vi_dosearch (string, dir) - char *string; - int dir; -{ - int old, save = vi_histpos; - HIST_ENTRY *h; - - if (string == 0 || *string == 0 || vi_histpos < 0) - { - ding (); - return; - } - - if ((save = history_search_pos (string, dir, vi_histpos + dir)) == -1) - { - maybe_unsave_line (); - rl_clear_message (); - rl_point = 0; - ding (); - return; - } - - vi_histpos = save; - - old = where_history (); - history_set_pos (vi_histpos); - h = current_history (); - history_set_pos (old); - - strcpy (the_line, h->line); - rl_undo_list = (UNDO_LIST *)h->data; - rl_end = strlen (the_line); - rl_point = 0; - rl_clear_message (); -} - -/* Completion, from vi's point of view. */ -rl_vi_complete (ignore, key) - int ignore, key; -{ - if (!whitespace (the_line[rl_point])) - { - rl_vi_end_word (1, 'E'); - rl_point++; - } - rl_complete_internal ('*'); - rl_vi_insertion_mode (); -} - -/* Previous word in vi mode. */ -rl_vi_prev_word (count, key) - int count, key; -{ - if (count < 0) - { - rl_vi_next_word (-count, key); - return; - } - - if (uppercase_p (key)) - rl_vi_bWord (count); - else - rl_vi_bword (count); -} - -/* Next word in vi mode. */ -rl_vi_next_word (count, key) - int count; -{ - if (count < 0) - { - rl_vi_prev_word (-count, key); - return; - } - - if (uppercase_p (key)) - rl_vi_fWord (count); - else - rl_vi_fword (count); -} - -/* Move to the end of the ?next? word. */ -rl_vi_end_word (count, key) - int count, key; -{ - if (count < 0) - { - ding (); - return; - } - - if (uppercase_p (key)) - rl_vi_eWord (count); - else - rl_vi_eword (count); -} - -/* Move forward a word the way that 'W' does. */ -rl_vi_fWord (count) - int count; -{ - while (count-- && rl_point < (rl_end - 1)) - { - /* Skip until whitespace. */ - while (!whitespace (the_line[rl_point]) && rl_point < rl_end) - rl_point++; - - /* Now skip whitespace. */ - while (whitespace (the_line[rl_point]) && rl_point < rl_end) - rl_point++; - } -} - -rl_vi_bWord (count) - int count; -{ - while (count-- && rl_point > 0) - { - while (rl_point-- >= 0 && whitespace (the_line[rl_point])); - while (rl_point >= 0 && !whitespace (the_line[rl_point])) - rl_point--; - rl_point++; - } -} - -rl_vi_eWord (count) - int count; -{ - while (count -- && rl_point < (rl_end - 1)) - { - while (rl_point++ < rl_end && whitespace (the_line[rl_point])); - while (rl_point++ < rl_end && !whitespace (the_line[rl_point])); - rl_point--; - } -} - -rl_vi_fword (count) - int count; -{ - while (count -- && rl_point < (rl_end - 1)) - { - if (isident (the_line[rl_point])) - { - while (isident (the_line[rl_point]) && rl_point < rl_end) - rl_point += 1; - } - else if (!whitespace (the_line[rl_point])) - { - while (!isident (the_line[rl_point]) && - !whitespace (the_line[rl_point]) && rl_point < rl_end) - rl_point += 1; - } - - while (whitespace (the_line[rl_point]) && rl_point < rl_end) - rl_point++; - } -} - -rl_vi_bword (count) - int count; -{ - while (count -- && rl_point > 0) - { - while (--rl_point > 0 && whitespace (the_line[rl_point])); - if (rl_point > 0) - { - if (isident (the_line[rl_point])) - while (--rl_point >= 0 && isident (the_line[rl_point])); - else - while (--rl_point >= 0 && !isident (the_line[rl_point]) && - !whitespace (the_line[rl_point])); - rl_point++; - } - } -} - -rl_vi_eword (count) - int count; -{ - while (count -- && rl_point < rl_end - 1) - { - while (++rl_point < rl_end && whitespace (the_line[rl_point])); - - if (rl_point < rl_end) - { - if (isident (the_line[rl_point])) - while (++rl_point < rl_end && isident (the_line[rl_point])); - else - while (++rl_point < rl_end && !isident (the_line[rl_point]) - && !whitespace (the_line[rl_point])); - rl_point--; - } - } -} - -rl_vi_insert_beg () -{ - rl_beg_of_line (); - rl_vi_insertion_mode (); - return 0; -} - -rl_vi_append_mode () -{ - if (rl_point < rl_end) - rl_point += 1; - rl_vi_insertion_mode (); - return 0; -} - -rl_vi_append_eol () -{ - rl_end_of_line (); - rl_vi_append_mode (); - return 0; -} - -/* What to do in the case of C-d. */ -rl_vi_eof_maybe (count, c) - int count, c; -{ - rl_newline (1, '\n'); -} - -/* Insertion mode stuff. */ - -/* Switching from one mode to the other really just involves - switching keymaps. */ -rl_vi_insertion_mode () -{ - keymap = vi_insertion_keymap; -} - -rl_vi_movement_mode () -{ - if (rl_point > 0) - rl_backward (1); - - keymap = vi_movement_keymap; - if (vi_doing_insert) - { - rl_end_undo_group (); - vi_doing_insert = 0; - } -} - -rl_vi_arg_digit (count, c) - int count, c; -{ - if (c == '0' && rl_numeric_arg == 1 && !rl_explicit_arg) - rl_beg_of_line (); - else - rl_digit_argument (count, c); -} - -/* Doesn't take an arg count in vi */ -rl_vi_change_case (ignore1, ignore2) - int ignore1, ignore2; -{ - char c = 0; - - if (uppercase_p (the_line[rl_point])) - c = to_lower (the_line[rl_point]); - else if (lowercase_p (the_line[rl_point])) - c = to_upper (the_line[rl_point]); - - /* Vi is kind of strange here. */ - if (c) - { - rl_begin_undo_group (); - rl_delete (1); - rl_insert (1, c); - rl_end_undo_group (); - rl_vi_check (); - } - else - rl_forward (1); -} - -rl_vi_put (count, key) - int count, key; -{ - if (!uppercase_p (key)) - { - if(rl_point != rl_end) - rl_point++; - } - - rl_yank (); - rl_backward (1); -} - -rl_vi_check () -{ - if (rl_point && rl_point == rl_end) - rl_point--; -} - -rl_vi_column (count) -{ - if (count > rl_end) - rl_end_of_line (); - else - rl_point = count - 1; -} - -int -rl_vi_domove () -{ - int c, save; - - rl_mark = rl_point; - c = rl_read_key (in_stream); - - if (!member (c, vi_motion)) - { - if (digit (c)) - { - save = rl_numeric_arg; - rl_digit_loop1 (); - rl_numeric_arg *= save; - } - else - return (-1); - } - - rl_dispatch (c, keymap); - - /* No change in position means the command failed. */ - if (rl_mark == rl_point) - return (-1); - - if ((c == 'w' || c == 'W') && rl_point < rl_end) - { - rl_point--; - while((rl_point > 0) && whitespace (the_line[rl_point])) - rl_point--; - rl_point++; - } - - if (rl_mark < rl_point) - exchange (rl_point, rl_mark); - - return (0); -} - -/* A simplified loop for vi. Don't dispatch key at end. - Don't recognize minus sign? */ -rl_digit_loop1 () -{ - int key, c; - - while (1) - { - rl_message ("(arg: %d) ", arg_sign * rl_numeric_arg); - key = c = rl_read_key (); - - if (keymap[c].type == ISFUNC && - keymap[c].function == rl_universal_argument) - { - rl_numeric_arg *= 4; - continue; - } - c = UNMETA (c); - if (numeric (c)) - { - if (rl_explicit_arg) - rl_numeric_arg = (rl_numeric_arg * 10) + (c - '0'); - else - rl_numeric_arg = (c - '0'); - rl_explicit_arg = 1; - } - else - { - rl_clear_message (); - rl_stuff_char (key); - } - } -} - -rl_vi_delete_to (count, key) - int count, key; -{ - if (uppercase_p (key)) - rl_stuff_char ('$'); - - if (rl_vi_domove ()) - { - ding (); - return; - } - - rl_kill_text (rl_point, rl_mark); -} - -rl_vi_change_to (count, key) - int count, key; -{ - if (uppercase_p (key)) - rl_stuff_char ('$'); - - if (rl_vi_domove ()) - { - ding (); - return; - } - - rl_begin_undo_group (); - vi_doing_insert = 1; - rl_kill_text (rl_point, rl_mark); - rl_vi_insertion_mode (); -} - -rl_vi_yank_to (count, key) - int count, key; -{ - int save = rl_point; - - if (uppercase_p (key)) - rl_stuff_char ('$'); - - if (rl_vi_domove ()) - { - ding (); - return; - } - - rl_begin_undo_group (); - rl_kill_text (rl_point, rl_mark); - rl_end_undo_group (); - rl_do_undo (); - rl_point = save; -} - -rl_vi_delete (count) -{ - if (rl_point >= rl_end - 1) - { - rl_delete (count); - if (rl_point > 0) - rl_backward (1); - } - else - rl_delete (count); -} - -/* Turn the current line into a comment in shell history. A ksh function */ -rl_vi_comment () -{ - rl_beg_of_line (); - rl_insert_text (": "); /* # doesn't work in interactive mode */ - rl_redisplay (); - rl_newline (1, '\010'); -} - -rl_vi_first_print () -{ - rl_back_to_indent (); -} - -rl_back_to_indent (ignore1, ignore2) - int ignore1, ignore2; -{ - rl_beg_of_line (); - while (rl_point < rl_end && whitespace (the_line[rl_point])) - rl_point++; -} - -/* NOTE: it is necessary that opposite directions are inverses */ -#define FTO 1 /* forward to */ -#define BTO -1 /* backward to */ -#define FFIND 2 /* forward find */ -#define BFIND -2 /* backward find */ - -rl_vi_char_search (count, key) - int count, key; -{ - static char target; - static int orig_dir, dir; - int pos; - - if (key == ';' || key == ',') - dir = (key == ';' ? orig_dir : -orig_dir); - else - { - target = rl_read_key(); - - switch (key) - { - case 't': - orig_dir = dir = FTO; - break; - - case 'T': - orig_dir = dir = BTO; - break; - - case 'f': - orig_dir = dir = FFIND; - break; - - case 'F': - orig_dir = dir = BFIND; - break; - } - } - - pos = rl_point; - - if (dir < 0) - { - pos--; - do - { - if (the_line[pos] == target) - { - if (dir == BTO) - rl_point = pos + 1; - else - rl_point = pos; - return; - } - } - while (pos--); - - if (pos < 0) - { - ding (); - return; - } - } - else - { /* dir > 0 */ - pos++; - do - { - if (the_line[pos] == target) - { - if (dir == FTO) - rl_point = pos - 1; - else - rl_point = pos; - return; - } - } - while (++pos < rl_end); - - if (pos >= (rl_end - 1)) - ding (); - } -} - -/* Match brackets */ -rl_vi_match () -{ - int count = 1, brack, pos; - - pos = rl_point; - if ((brack = rl_vi_bracktype (the_line[rl_point])) == 0) - { - while ((brack = rl_vi_bracktype (the_line[rl_point])) == 0 && - rl_point < rl_end - 1) - rl_forward (1); - - if (brack <= 0) - { - rl_point = pos; - ding (); - return; - } - } - - pos = rl_point; - - if (brack < 0) - { - while (count) - { - if (--pos >= 0) - { - int b = rl_vi_bracktype (the_line[pos]); - if (b == -brack) - count--; - else if (b == brack) - count++; - } - else - { - ding (); - return; - } - } - } - else - { /* brack > 0 */ - while (count) - { - if (++pos < rl_end) - { - int b = rl_vi_bracktype (the_line[pos]); - if (b == -brack) - count--; - else if (b == brack) - count++; - } - else - { - ding (); - return; - } - } - } - rl_point = pos; -} - -int -rl_vi_bracktype (c) - int c; -{ - switch (c) - { - case '(': return 1; - case ')': return -1; - case '[': return 2; - case ']': return -2; - case '{': return 3; - case '}': return -3; - default: return 0; - } -} - -rl_vi_change_char () -{ - int c; - - c = rl_read_key(); - - switch (c) - { - case '\033': - case CTRL('C'): - return; - - default: - rl_begin_undo_group (); - rl_delete (1); - rl_insert (1, c); - rl_end_undo_group (); - break; - } -} - -rl_vi_subst (count, key) - int count, key; -{ - rl_begin_undo_group (); - vi_doing_insert = 1; - - if (uppercase_p (key)) - { - rl_beg_of_line (); - rl_kill_line (1); - } - else - rl_delete (1); - - rl_vi_insertion_mode (); -} - -rl_vi_overstrike (count, key) - int count, key; -{ - int i; - - if (vi_doing_insert == 0) - { - vi_doing_insert = 1; - rl_begin_undo_group (); - } - - for (i = 0; i < count; i++) - { - vi_replace_count++; - rl_begin_undo_group (); - - if (rl_point < rl_end) - { - rl_delete (1); - rl_insert (1, key); - } - else - rl_insert (1, key); - - rl_end_undo_group (); - } -} - -rl_vi_overstrike_delete (count) - int count; -{ - int i, s; - - for (i = 0; i < count; i++) - { - if (vi_replace_count == 0) - { - ding (); - break; - } - s = rl_point; - - if (rl_do_undo ()) - vi_replace_count--; - - if (rl_point == s) - rl_backward (1); - } - - if (vi_replace_count == 0 && vi_doing_insert) - { - rl_end_undo_group (); - rl_do_undo (); - vi_doing_insert = 0; - } -} - -rl_vi_replace () -{ - int i; - - vi_replace_count = 0; - - vi_replace_map = rl_make_bare_keymap (); - - for (i = ' '; i < 127; i++) - vi_replace_map[i].function = rl_vi_overstrike; - - vi_replace_map[RUBOUT].function = rl_vi_overstrike_delete; - vi_replace_map[CTRL('H')].function = rl_vi_overstrike_delete; - vi_replace_map[ESC].function = rl_vi_movement_mode; - vi_replace_map[RETURN].function = rl_newline; - vi_replace_map[NEWLINE].function = rl_newline; - keymap = vi_replace_map; -} diff --git a/gnu/usr.bin/gdb/regex.c b/gnu/usr.bin/gdb/regex.c deleted file mode 100644 index 45c3478..0000000 --- a/gnu/usr.bin/gdb/regex.c +++ /dev/null @@ -1,1738 +0,0 @@ -/* Extended regular expression matching and search library. - Copyright (C) 1985, 1989 Free Software Foundation, Inc. - - 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 1, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - - In other words, you are welcome to use, share and improve this program. - You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! */ - - -/* To test, compile with -Dtest. - This Dtestable feature turns this into a self-contained program - which reads a pattern, describes how it compiles, - then reads a string and searches for it. */ - -#ifdef emacs - -/* The `emacs' switch turns on certain special matching commands - that make sense only in emacs. */ - -#include "config.h" -#include "lisp.h" -#include "buffer.h" -#include "syntax.h" - -#else /* not emacs */ - -#ifdef USG -#ifndef BSTRING -#define bcopy(s,d,n) memcpy((d),(s),(n)) -#define bcmp(s1,s2,n) memcmp((s1),(s2),(n)) -#define bzero(s,n) memset((s),0,(n)) -#endif -#endif - -/* Make alloca work the best possible way. */ -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else -#ifdef sparc -#include -#endif -#endif - -/* - * Define the syntax stuff, so we can do the \<...\> things. - */ - -#ifndef Sword /* must be non-zero in some of the tests below... */ -#define Sword 1 -#endif - -#define SYNTAX(c) re_syntax_table[c] - -#ifdef SYNTAX_TABLE - -char *re_syntax_table; - -#else - -static char re_syntax_table[256]; - -static void -init_syntax_once () -{ - register int c; - static int done = 0; - - if (done) - return; - - bzero (re_syntax_table, sizeof re_syntax_table); - - for (c = 'a'; c <= 'z'; c++) - re_syntax_table[c] = Sword; - - for (c = 'A'; c <= 'Z'; c++) - re_syntax_table[c] = Sword; - - for (c = '0'; c <= '9'; c++) - re_syntax_table[c] = Sword; - - done = 1; -} - -#endif /* SYNTAX_TABLE */ -#endif /* not emacs */ - -#include "regex.h" - -/* Number of failure points to allocate space for initially, - when matching. If this number is exceeded, more space is allocated, - so it is not a hard limit. */ - -#ifndef NFAILURES -#define NFAILURES 80 -#endif /* NFAILURES */ - -/* width of a byte in bits */ - -#define BYTEWIDTH 8 - -#ifndef SIGN_EXTEND_CHAR -#define SIGN_EXTEND_CHAR(x) (x) -#endif - -static int obscure_syntax = 0; - -/* Specify the precise syntax of regexp for compilation. - This provides for compatibility for various utilities - which historically have different, incompatible syntaxes. - - The argument SYNTAX is a bit-mask containing the two bits - RE_NO_BK_PARENS and RE_NO_BK_VBAR. */ - -int -re_set_syntax (syntax) -{ - int ret; - - ret = obscure_syntax; - obscure_syntax = syntax; - return ret; -} - -/* re_compile_pattern takes a regular-expression string - and converts it into a buffer full of byte commands for matching. - - PATTERN is the address of the pattern string - SIZE is the length of it. - BUFP is a struct re_pattern_buffer * which points to the info - on where to store the byte commands. - This structure contains a char * which points to the - actual space, which should have been obtained with malloc. - re_compile_pattern may use realloc to grow the buffer space. - - The number of bytes of commands can be found out by looking in - the struct re_pattern_buffer that bufp pointed to, - after re_compile_pattern returns. -*/ - -#define PATPUSH(ch) (*b++ = (char) (ch)) - -#define PATFETCH(c) \ - {if (p == pend) goto end_of_pattern; \ - c = * (unsigned char *) p++; \ - if (translate) c = translate[c]; } - -#define PATFETCH_RAW(c) \ - {if (p == pend) goto end_of_pattern; \ - c = * (unsigned char *) p++; } - -#define PATUNFETCH p-- - -#define EXTEND_BUFFER \ - { char *old_buffer = bufp->buffer; \ - if (bufp->allocated == (1<<16)) goto too_big; \ - bufp->allocated *= 2; \ - if (bufp->allocated > (1<<16)) bufp->allocated = (1<<16); \ - if (!(bufp->buffer = (char *) realloc (bufp->buffer, bufp->allocated))) \ - goto memory_exhausted; \ - c = bufp->buffer - old_buffer; \ - b += c; \ - if (fixup_jump) \ - fixup_jump += c; \ - if (laststart) \ - laststart += c; \ - begalt += c; \ - if (pending_exact) \ - pending_exact += c; \ - } - -static int store_jump (), insert_jump (); - -char * -re_compile_pattern (pattern, size, bufp) - char *pattern; - int size; - struct re_pattern_buffer *bufp; -{ - register char *b = bufp->buffer; - register char *p = pattern; - char *pend = pattern + size; - register unsigned c, c1; - char *p1; - unsigned char *translate = (unsigned char *) bufp->translate; - - /* address of the count-byte of the most recently inserted "exactn" command. - This makes it possible to tell whether a new exact-match character - can be added to that command or requires a new "exactn" command. */ - - char *pending_exact = 0; - - /* address of the place where a forward-jump should go - to the end of the containing expression. - Each alternative of an "or", except the last, ends with a forward-jump - of this sort. */ - - char *fixup_jump = 0; - - /* address of start of the most recently finished expression. - This tells postfix * where to find the start of its operand. */ - - char *laststart = 0; - - /* In processing a repeat, 1 means zero matches is allowed */ - - char zero_times_ok; - - /* In processing a repeat, 1 means many matches is allowed */ - - char many_times_ok; - - /* address of beginning of regexp, or inside of last \( */ - - char *begalt = b; - - /* Stack of information saved by \( and restored by \). - Four stack elements are pushed by each \(: - First, the value of b. - Second, the value of fixup_jump. - Third, the value of regnum. - Fourth, the value of begalt. */ - - int stackb[40]; - int *stackp = stackb; - int *stacke = stackb + 40; - int *stackt; - - /* Counts \('s as they are encountered. Remembered for the matching \), - where it becomes the "register number" to put in the stop_memory command */ - - int regnum = 1; - - bufp->fastmap_accurate = 0; - -#ifndef emacs -#ifndef SYNTAX_TABLE - /* - * Initialize the syntax table. - */ - init_syntax_once(); -#endif -#endif - - if (bufp->allocated == 0) - { - bufp->allocated = 28; - if (bufp->buffer) - /* EXTEND_BUFFER loses when bufp->allocated is 0 */ - bufp->buffer = (char *) realloc (bufp->buffer, 28); - else - /* Caller did not allocate a buffer. Do it for him */ - bufp->buffer = (char *) malloc (28); - if (!bufp->buffer) goto memory_exhausted; - begalt = b = bufp->buffer; - } - - while (p != pend) - { - if (b - bufp->buffer > bufp->allocated - 10) - /* Note that EXTEND_BUFFER clobbers c */ - EXTEND_BUFFER; - - PATFETCH (c); - - switch (c) - { - case '$': - if (obscure_syntax & RE_TIGHT_VBAR) - { - if (! (obscure_syntax & RE_CONTEXT_INDEP_OPS) && p != pend) - goto normal_char; - /* Make operand of last vbar end before this `$'. */ - if (fixup_jump) - store_jump (fixup_jump, jump, b); - fixup_jump = 0; - PATPUSH (endline); - break; - } - - /* $ means succeed if at end of line, but only in special contexts. - If randomly in the middle of a pattern, it is a normal character. */ - if (p == pend || *p == '\n' - || (obscure_syntax & RE_CONTEXT_INDEP_OPS) - || (obscure_syntax & RE_NO_BK_PARENS - ? *p == ')' - : *p == '\\' && p[1] == ')') - || (obscure_syntax & RE_NO_BK_VBAR - ? *p == '|' - : *p == '\\' && p[1] == '|')) - { - PATPUSH (endline); - break; - } - goto normal_char; - - case '^': - /* ^ means succeed if at beg of line, but only if no preceding pattern. */ - - if (laststart && p[-2] != '\n' - && ! (obscure_syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - if (obscure_syntax & RE_TIGHT_VBAR) - { - if (p != pattern + 1 - && ! (obscure_syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - PATPUSH (begline); - begalt = b; - } - else - PATPUSH (begline); - break; - - case '+': - case '?': - if (obscure_syntax & RE_BK_PLUS_QM) - goto normal_char; - handle_plus: - case '*': - /* If there is no previous pattern, char not special. */ - if (!laststart && ! (obscure_syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - /* If there is a sequence of repetition chars, - collapse it down to equivalent to just one. */ - zero_times_ok = 0; - many_times_ok = 0; - while (1) - { - zero_times_ok |= c != '+'; - many_times_ok |= c != '?'; - if (p == pend) - break; - PATFETCH (c); - if (c == '*') - ; - else if (!(obscure_syntax & RE_BK_PLUS_QM) - && (c == '+' || c == '?')) - ; - else if ((obscure_syntax & RE_BK_PLUS_QM) - && c == '\\') - { - int c1; - PATFETCH (c1); - if (!(c1 == '+' || c1 == '?')) - { - PATUNFETCH; - PATUNFETCH; - break; - } - c = c1; - } - else - { - PATUNFETCH; - break; - } - } - - /* Star, etc. applied to an empty pattern is equivalent - to an empty pattern. */ - if (!laststart) - break; - - /* Now we know whether 0 matches is allowed, - and whether 2 or more matches is allowed. */ - if (many_times_ok) - { - /* If more than one repetition is allowed, - put in a backward jump at the end. */ - store_jump (b, maybe_finalize_jump, laststart - 3); - b += 3; - } - insert_jump (on_failure_jump, laststart, b + 3, b); - pending_exact = 0; - b += 3; - if (!zero_times_ok) - { - /* At least one repetition required: insert before the loop - a skip over the initial on-failure-jump instruction */ - insert_jump (dummy_failure_jump, laststart, laststart + 6, b); - b += 3; - } - break; - - case '.': - laststart = b; - PATPUSH (anychar); - break; - - case '[': - while (b - bufp->buffer - > bufp->allocated - 3 - (1 << BYTEWIDTH) / BYTEWIDTH) - /* Note that EXTEND_BUFFER clobbers c */ - EXTEND_BUFFER; - - laststart = b; - if (*p == '^') - PATPUSH (charset_not), p++; - else - PATPUSH (charset); - p1 = p; - - PATPUSH ((1 << BYTEWIDTH) / BYTEWIDTH); - /* Clear the whole map */ - bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH); - /* Read in characters and ranges, setting map bits */ - while (1) - { - PATFETCH (c); - if (c == ']' && p != p1 + 1) break; - if (*p == '-' && p[1] != ']') - { - PATFETCH (c1); - PATFETCH (c1); - while (c <= c1) - b[c / BYTEWIDTH] |= 1 << (c % BYTEWIDTH), c++; - } - else - { - b[c / BYTEWIDTH] |= 1 << (c % BYTEWIDTH); - } - } - /* Discard any bitmap bytes that are all 0 at the end of the map. - Decrement the map-length byte too. */ - while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) - b[-1]--; - b += b[-1]; - break; - - case '(': - if (! (obscure_syntax & RE_NO_BK_PARENS)) - goto normal_char; - else - goto handle_open; - - case ')': - if (! (obscure_syntax & RE_NO_BK_PARENS)) - goto normal_char; - else - goto handle_close; - - case '\n': - if (! (obscure_syntax & RE_NEWLINE_OR)) - goto normal_char; - else - goto handle_bar; - - case '|': - if (! (obscure_syntax & RE_NO_BK_VBAR)) - goto normal_char; - else - goto handle_bar; - - case '\\': - if (p == pend) goto invalid_pattern; - PATFETCH_RAW (c); - switch (c) - { - case '(': - if (obscure_syntax & RE_NO_BK_PARENS) - goto normal_backsl; - handle_open: - if (stackp == stacke) goto nesting_too_deep; - if (regnum < RE_NREGS) - { - PATPUSH (start_memory); - PATPUSH (regnum); - } - *stackp++ = b - bufp->buffer; - *stackp++ = fixup_jump ? fixup_jump - bufp->buffer + 1 : 0; - *stackp++ = regnum++; - *stackp++ = begalt - bufp->buffer; - fixup_jump = 0; - laststart = 0; - begalt = b; - break; - - case ')': - if (obscure_syntax & RE_NO_BK_PARENS) - goto normal_backsl; - handle_close: - if (stackp == stackb) goto unmatched_close; - begalt = *--stackp + bufp->buffer; - if (fixup_jump) - store_jump (fixup_jump, jump, b); - if (stackp[-1] < RE_NREGS) - { - PATPUSH (stop_memory); - PATPUSH (stackp[-1]); - } - stackp -= 2; - fixup_jump = 0; - if (*stackp) - fixup_jump = *stackp + bufp->buffer - 1; - laststart = *--stackp + bufp->buffer; - break; - - case '|': - if (obscure_syntax & RE_NO_BK_VBAR) - goto normal_backsl; - handle_bar: - insert_jump (on_failure_jump, begalt, b + 6, b); - pending_exact = 0; - b += 3; - if (fixup_jump) - store_jump (fixup_jump, jump, b); - fixup_jump = b; - b += 3; - laststart = 0; - begalt = b; - break; - -#ifdef emacs - case '=': - PATPUSH (at_dot); - break; - - case 's': - laststart = b; - PATPUSH (syntaxspec); - PATFETCH (c); - PATPUSH (syntax_spec_code[c]); - break; - - case 'S': - laststart = b; - PATPUSH (notsyntaxspec); - PATFETCH (c); - PATPUSH (syntax_spec_code[c]); - break; -#endif /* emacs */ - - case 'w': - laststart = b; - PATPUSH (wordchar); - break; - - case 'W': - laststart = b; - PATPUSH (notwordchar); - break; - - case '<': - PATPUSH (wordbeg); - break; - - case '>': - PATPUSH (wordend); - break; - - case 'b': - PATPUSH (wordbound); - break; - - case 'B': - PATPUSH (notwordbound); - break; - - case '`': - PATPUSH (begbuf); - break; - - case '\'': - PATPUSH (endbuf); - break; - - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - c1 = c - '0'; - if (c1 >= regnum) - goto normal_char; - for (stackt = stackp - 2; stackt > stackb; stackt -= 4) - if (*stackt == c1) - goto normal_char; - laststart = b; - PATPUSH (duplicate); - PATPUSH (c1); - break; - - case '+': - case '?': - if (obscure_syntax & RE_BK_PLUS_QM) - goto handle_plus; - - default: - normal_backsl: - /* You might think it would be useful for \ to mean - not to translate; but if we don't translate it - it will never match anything. */ - if (translate) c = translate[c]; - goto normal_char; - } - break; - - default: - normal_char: - if (!pending_exact || pending_exact + *pending_exact + 1 != b - || *pending_exact == 0177 || *p == '*' || *p == '^' - || ((obscure_syntax & RE_BK_PLUS_QM) - ? *p == '\\' && (p[1] == '+' || p[1] == '?') - : (*p == '+' || *p == '?'))) - { - laststart = b; - PATPUSH (exactn); - pending_exact = b; - PATPUSH (0); - } - PATPUSH (c); - (*pending_exact)++; - } - } - - if (fixup_jump) - store_jump (fixup_jump, jump, b); - - if (stackp != stackb) goto unmatched_open; - - bufp->used = b - bufp->buffer; - return 0; - - invalid_pattern: - return "Invalid regular expression"; - - unmatched_open: - return "Unmatched \\("; - - unmatched_close: - return "Unmatched \\)"; - - end_of_pattern: - return "Premature end of regular expression"; - - nesting_too_deep: - return "Nesting too deep"; - - too_big: - return "Regular expression too big"; - - memory_exhausted: - return "Memory exhausted"; -} - -/* Store where `from' points a jump operation to jump to where `to' points. - `opcode' is the opcode to store. */ - -static int -store_jump (from, opcode, to) - char *from, *to; - char opcode; -{ - from[0] = opcode; - from[1] = (to - (from + 3)) & 0377; - from[2] = (to - (from + 3)) >> 8; -} - -/* Open up space at char FROM, and insert there a jump to TO. - CURRENT_END gives te end of the storage no in use, - so we know how much data to copy up. - OP is the opcode of the jump to insert. - - If you call this function, you must zero out pending_exact. */ - -static int -insert_jump (op, from, to, current_end) - char op; - char *from, *to, *current_end; -{ - register char *pto = current_end + 3; - register char *pfrom = current_end; - while (pfrom != from) - *--pto = *--pfrom; - store_jump (from, op, to); -} - -/* Given a pattern, compute a fastmap from it. - The fastmap records which of the (1 << BYTEWIDTH) possible characters - can start a string that matches the pattern. - This fastmap is used by re_search to skip quickly over totally implausible text. - - The caller must supply the address of a (1 << BYTEWIDTH)-byte data area - as bufp->fastmap. - The other components of bufp describe the pattern to be used. */ - -void -re_compile_fastmap (bufp) - struct re_pattern_buffer *bufp; -{ - unsigned char *pattern = (unsigned char *) bufp->buffer; - int size = bufp->used; - register char *fastmap = bufp->fastmap; - register unsigned char *p = pattern; - register unsigned char *pend = pattern + size; - register int j, k; - unsigned char *translate = (unsigned char *) bufp->translate; - - unsigned char *stackb[NFAILURES]; - unsigned char **stackp = stackb; - - bzero (fastmap, (1 << BYTEWIDTH)); - bufp->fastmap_accurate = 1; - bufp->can_be_null = 0; - - while (p) - { - if (p == pend) - { - bufp->can_be_null = 1; - break; - } -#ifdef SWITCH_ENUM_BUG - switch ((int) ((enum regexpcode) *p++)) -#else - switch ((enum regexpcode) *p++) -#endif - { - case exactn: - if (translate) - fastmap[translate[p[1]]] = 1; - else - fastmap[p[1]] = 1; - break; - - case begline: - case before_dot: - case at_dot: - case after_dot: - case begbuf: - case endbuf: - case wordbound: - case notwordbound: - case wordbeg: - case wordend: - continue; - - case endline: - if (translate) - fastmap[translate['\n']] = 1; - else - fastmap['\n'] = 1; - if (bufp->can_be_null != 1) - bufp->can_be_null = 2; - break; - - case finalize_jump: - case maybe_finalize_jump: - case jump: - case dummy_failure_jump: - bufp->can_be_null = 1; - j = *p++ & 0377; - j += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p += j + 1; /* The 1 compensates for missing ++ above */ - if (j > 0) - continue; - /* Jump backward reached implies we just went through - the body of a loop and matched nothing. - Opcode jumped to should be an on_failure_jump. - Just treat it like an ordinary jump. - For a * loop, it has pushed its failure point already; - if so, discard that as redundant. */ - if ((enum regexpcode) *p != on_failure_jump) - continue; - p++; - j = *p++ & 0377; - j += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p += j + 1; /* The 1 compensates for missing ++ above */ - if (stackp != stackb && *stackp == p) - stackp--; - continue; - - case on_failure_jump: - j = *p++ & 0377; - j += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p++; - *++stackp = p + j; - continue; - - case start_memory: - case stop_memory: - p++; - continue; - - case duplicate: - bufp->can_be_null = 1; - fastmap['\n'] = 1; - case anychar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (j != '\n') - fastmap[j] = 1; - if (bufp->can_be_null) - return; - /* Don't return; check the alternative paths - so we can set can_be_null if appropriate. */ - break; - - case wordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == Sword) - fastmap[j] = 1; - break; - - case notwordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != Sword) - fastmap[j] = 1; - break; - -#ifdef emacs - case syntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == (enum syntaxcode) k) - fastmap[j] = 1; - break; - - case notsyntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != (enum syntaxcode) k) - fastmap[j] = 1; - break; -#endif /* emacs */ - - case charset: - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) - { - if (translate) - fastmap[translate[j]] = 1; - else - fastmap[j] = 1; - } - break; - - case charset_not: - /* Chars beyond end of map must be allowed */ - for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) - if (translate) - fastmap[translate[j]] = 1; - else - fastmap[j] = 1; - - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) - { - if (translate) - fastmap[translate[j]] = 1; - else - fastmap[j] = 1; - } - break; - } - - /* Get here means we have successfully found the possible starting characters - of one path of the pattern. We need not follow this path any farther. - Instead, look at the next alternative remembered in the stack. */ - if (stackp != stackb) - p = *stackp--; - else - break; - } -} - -/* Like re_search_2, below, but only one string is specified. */ - -int -re_search (pbufp, string, size, startpos, range, regs) - struct re_pattern_buffer *pbufp; - char *string; - int size, startpos, range; - struct re_registers *regs; -{ - return re_search_2 (pbufp, 0, 0, string, size, startpos, range, regs, size); -} - -/* Like re_match_2 but tries first a match starting at index STARTPOS, - then at STARTPOS + 1, and so on. - RANGE is the number of places to try before giving up. - If RANGE is negative, the starting positions tried are - STARTPOS, STARTPOS - 1, etc. - It is up to the caller to make sure that range is not so large - as to take the starting position outside of the input strings. - -The value returned is the position at which the match was found, - or -1 if no match was found, - or -2 if error (such as failure stack overflow). */ - -int -re_search_2 (pbufp, string1, size1, string2, size2, startpos, range, regs, mstop) - struct re_pattern_buffer *pbufp; - char *string1, *string2; - int size1, size2; - int startpos; - register int range; - struct re_registers *regs; - int mstop; -{ - register char *fastmap = pbufp->fastmap; - register unsigned char *translate = (unsigned char *) pbufp->translate; - int total = size1 + size2; - int val; - - /* Update the fastmap now if not correct already */ - if (fastmap && !pbufp->fastmap_accurate) - re_compile_fastmap (pbufp); - - /* Don't waste time in a long search for a pattern - that says it is anchored. */ - if (pbufp->used > 0 && (enum regexpcode) pbufp->buffer[0] == begbuf - && range > 0) - { - if (startpos > 0) - return -1; - else - range = 1; - } - - while (1) - { - /* If a fastmap is supplied, skip quickly over characters - that cannot possibly be the start of a match. - Note, however, that if the pattern can possibly match - the null string, we must test it at each starting point - so that we take the first null string we get. */ - - if (fastmap && startpos < total && pbufp->can_be_null != 1) - { - if (range > 0) - { - register int lim = 0; - register unsigned char *p; - int irange = range; - if (startpos < size1 && startpos + range >= size1) - lim = range - (size1 - startpos); - - p = ((unsigned char *) - &(startpos >= size1 ? string2 - size1 : string1)[startpos]); - - if (translate) - { - while (range > lim && !fastmap[translate[*p++]]) - range--; - } - else - { - while (range > lim && !fastmap[*p++]) - range--; - } - startpos += irange - range; - } - else - { - register unsigned char c; - if (startpos >= size1) - c = string2[startpos - size1]; - else - c = string1[startpos]; - c &= 0xff; - if (translate ? !fastmap[translate[c]] : !fastmap[c]) - goto advance; - } - } - - if (range >= 0 && startpos == total - && fastmap && pbufp->can_be_null == 0) - return -1; - - val = re_match_2 (pbufp, string1, size1, string2, size2, startpos, regs, mstop); - if (0 <= val) - { - if (val == -2) - return -2; - return startpos; - } - -#ifdef C_ALLOCA - alloca (0); -#endif /* C_ALLOCA */ - - advance: - if (!range) break; - if (range > 0) range--, startpos++; else range++, startpos--; - } - return -1; -} - -#ifndef emacs /* emacs never uses this */ -int -re_match (pbufp, string, size, pos, regs) - struct re_pattern_buffer *pbufp; - char *string; - int size, pos; - struct re_registers *regs; -{ - return re_match_2 (pbufp, 0, 0, string, size, pos, regs, size); -} -#endif /* emacs */ - -/* Maximum size of failure stack. Beyond this, overflow is an error. */ - -int re_max_failures = 2000; - -static int bcmp_translate(); -/* Match the pattern described by PBUFP - against data which is the virtual concatenation of STRING1 and STRING2. - SIZE1 and SIZE2 are the sizes of the two data strings. - Start the match at position POS. - Do not consider matching past the position MSTOP. - - If pbufp->fastmap is nonzero, then it had better be up to date. - - The reason that the data to match are specified as two components - which are to be regarded as concatenated - is so this function can be used directly on the contents of an Emacs buffer. - - -1 is returned if there is no match. -2 is returned if there is - an error (such as match stack overflow). Otherwise the value is the length - of the substring which was matched. */ - -int -re_match_2 (pbufp, string1, size1, string2, size2, pos, regs, mstop) - struct re_pattern_buffer *pbufp; - unsigned char *string1, *string2; - int size1, size2; - int pos; - struct re_registers *regs; - int mstop; -{ - register unsigned char *p = (unsigned char *) pbufp->buffer; - register unsigned char *pend = p + pbufp->used; - /* End of first string */ - unsigned char *end1; - /* End of second string */ - unsigned char *end2; - /* Pointer just past last char to consider matching */ - unsigned char *end_match_1, *end_match_2; - register unsigned char *d, *dend; - register int mcnt; - unsigned char *translate = (unsigned char *) pbufp->translate; - - /* Failure point stack. Each place that can handle a failure further down the line - pushes a failure point on this stack. It consists of two char *'s. - The first one pushed is where to resume scanning the pattern; - the second pushed is where to resume scanning the strings. - If the latter is zero, the failure point is a "dummy". - If a failure happens and the innermost failure point is dormant, - it discards that failure point and tries the next one. */ - - unsigned char *initial_stack[2 * NFAILURES]; - unsigned char **stackb = initial_stack; - unsigned char **stackp = stackb, **stacke = &stackb[2 * NFAILURES]; - - /* Information on the "contents" of registers. - These are pointers into the input strings; they record - just what was matched (on this attempt) by some part of the pattern. - The start_memory command stores the start of a register's contents - and the stop_memory command stores the end. - - At that point, regstart[regnum] points to the first character in the register, - regend[regnum] points to the first character beyond the end of the register, - regstart_seg1[regnum] is true iff regstart[regnum] points into string1, - and regend_seg1[regnum] is true iff regend[regnum] points into string1. */ - - unsigned char *regstart[RE_NREGS]; - unsigned char *regend[RE_NREGS]; - unsigned char regstart_seg1[RE_NREGS], regend_seg1[RE_NREGS]; - - /* Set up pointers to ends of strings. - Don't allow the second string to be empty unless both are empty. */ - if (!size2) - { - string2 = string1; - size2 = size1; - string1 = 0; - size1 = 0; - } - end1 = string1 + size1; - end2 = string2 + size2; - - /* Compute where to stop matching, within the two strings */ - if (mstop <= size1) - { - end_match_1 = string1 + mstop; - end_match_2 = string2; - } - else - { - end_match_1 = end1; - end_match_2 = string2 + mstop - size1; - } - - /* Initialize \) text positions to -1 - to mark ones that no \( or \) has been seen for. */ - - for (mcnt = 0; mcnt < sizeof (regend) / sizeof (*regend); mcnt++) - regend[mcnt] = (unsigned char *) -1; - - /* `p' scans through the pattern as `d' scans through the data. - `dend' is the end of the input string that `d' points within. - `d' is advanced into the following input string whenever necessary, - but this happens before fetching; - therefore, at the beginning of the loop, - `d' can be pointing at the end of a string, - but it cannot equal string2. */ - - if (pos <= size1) - d = string1 + pos, dend = end_match_1; - else - d = string2 + pos - size1, dend = end_match_2; - -/* Write PREFETCH; just before fetching a character with *d. */ -#define PREFETCH \ - while (d == dend) \ - { if (dend == end_match_2) goto fail; /* end of string2 => failure */ \ - d = string2; /* end of string1 => advance to string2. */ \ - dend = end_match_2; } - - /* This loop loops over pattern commands. - It exits by returning from the function if match is complete, - or it drops through if match fails at this starting point in the input data. */ - - while (1) - { - if (p == pend) - /* End of pattern means we have succeeded! */ - { - /* If caller wants register contents data back, convert it to indices */ - if (regs) - { - regs->start[0] = pos; - if (dend == end_match_1) - regs->end[0] = d - string1; - else - regs->end[0] = d - string2 + size1; - for (mcnt = 1; mcnt < RE_NREGS; mcnt++) - { - if (regend[mcnt] == (unsigned char *) -1) - { - regs->start[mcnt] = -1; - regs->end[mcnt] = -1; - continue; - } - if (regstart_seg1[mcnt]) - regs->start[mcnt] = regstart[mcnt] - string1; - else - regs->start[mcnt] = regstart[mcnt] - string2 + size1; - if (regend_seg1[mcnt]) - regs->end[mcnt] = regend[mcnt] - string1; - else - regs->end[mcnt] = regend[mcnt] - string2 + size1; - } - } - if (dend == end_match_1) - return (d - string1 - pos); - else - return d - string2 + size1 - pos; - } - - /* Otherwise match next pattern command */ -#ifdef SWITCH_ENUM_BUG - switch ((int) ((enum regexpcode) *p++)) -#else - switch ((enum regexpcode) *p++) -#endif - { - - /* \( is represented by a start_memory, \) by a stop_memory. - Both of those commands contain a "register number" argument. - The text matched within the \( and \) is recorded under that number. - Then, \ turns into a `duplicate' command which - is followed by the numeric value of as the register number. */ - - case start_memory: - regstart[*p] = d; - regstart_seg1[*p++] = (dend == end_match_1); - break; - - case stop_memory: - regend[*p] = d; - regend_seg1[*p++] = (dend == end_match_1); - break; - - case duplicate: - { - int regno = *p++; /* Get which register to match against */ - register unsigned char *d2, *dend2; - - d2 = regstart[regno]; - dend2 = ((regstart_seg1[regno] == regend_seg1[regno]) - ? regend[regno] : end_match_1); - while (1) - { - /* Advance to next segment in register contents, if necessary */ - while (d2 == dend2) - { - if (dend2 == end_match_2) break; - if (dend2 == regend[regno]) break; - d2 = string2, dend2 = regend[regno]; /* end of string1 => advance to string2. */ - } - /* At end of register contents => success */ - if (d2 == dend2) break; - - /* Advance to next segment in data being matched, if necessary */ - PREFETCH; - - /* mcnt gets # consecutive chars to compare */ - mcnt = dend - d; - if (mcnt > dend2 - d2) - mcnt = dend2 - d2; - /* Compare that many; failure if mismatch, else skip them. */ - if (translate ? bcmp_translate (d, d2, mcnt, translate) : bcmp (d, d2, mcnt)) - goto fail; - d += mcnt, d2 += mcnt; - } - } - break; - - case anychar: - /* fetch a data character */ - PREFETCH; - /* Match anything but a newline. */ - if ((translate ? translate[*d++] : *d++) == '\n') - goto fail; - break; - - case charset: - case charset_not: - { - /* Nonzero for charset_not */ - int not = 0; - register int c; - if (*(p - 1) == (unsigned char) charset_not) - not = 1; - - /* fetch a data character */ - PREFETCH; - - if (translate) - c = translate [*d]; - else - c = *d; - - if (c < *p * BYTEWIDTH - && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - p += 1 + *p; - - if (!not) goto fail; - d++; - break; - } - - case begline: - if (d == string1 || d[-1] == '\n') - break; - goto fail; - - case endline: - if (d == end2 - || (d == end1 ? (size2 == 0 || *string2 == '\n') : *d == '\n')) - break; - goto fail; - - /* "or" constructs ("|") are handled by starting each alternative - with an on_failure_jump that points to the start of the next alternative. - Each alternative except the last ends with a jump to the joining point. - (Actually, each jump except for the last one really jumps - to the following jump, because tensioning the jumps is a hassle.) */ - - /* The start of a stupid repeat has an on_failure_jump that points - past the end of the repeat text. - This makes a failure point so that, on failure to match a repetition, - matching restarts past as many repetitions have been found - with no way to fail and look for another one. */ - - /* A smart repeat is similar but loops back to the on_failure_jump - so that each repetition makes another failure point. */ - - case on_failure_jump: - if (stackp == stacke) - { - unsigned char **stackx; - if (stacke - stackb > re_max_failures * 2) - return -2; - stackx = (unsigned char **) alloca (2 * (stacke - stackb) - * sizeof (char *)); - bcopy (stackb, stackx, (stacke - stackb) * sizeof (char *)); - stackp = stackx + (stackp - stackb); - stacke = stackx + 2 * (stacke - stackb); - stackb = stackx; - } - mcnt = *p++ & 0377; - mcnt += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p++; - *stackp++ = mcnt + p; - *stackp++ = d; - break; - - /* The end of a smart repeat has an maybe_finalize_jump back. - Change it either to a finalize_jump or an ordinary jump. */ - - case maybe_finalize_jump: - mcnt = *p++ & 0377; - mcnt += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p++; - { - register unsigned char *p2 = p; - /* Compare what follows with the begining of the repeat. - If we can establish that there is nothing that they would - both match, we can change to finalize_jump */ - while (p2 != pend - && (*p2 == (unsigned char) stop_memory - || *p2 == (unsigned char) start_memory)) - p2++; - if (p2 == pend) - p[-3] = (unsigned char) finalize_jump; - else if (*p2 == (unsigned char) exactn - || *p2 == (unsigned char) endline) - { - register int c = *p2 == (unsigned char) endline ? '\n' : p2[2]; - register unsigned char *p1 = p + mcnt; - /* p1[0] ... p1[2] are an on_failure_jump. - Examine what follows that */ - if (p1[3] == (unsigned char) exactn && p1[5] != c) - p[-3] = (unsigned char) finalize_jump; - else if (p1[3] == (unsigned char) charset - || p1[3] == (unsigned char) charset_not) - { - int not = p1[3] == (unsigned char) charset_not; - if (c < p1[4] * BYTEWIDTH - && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - /* not is 1 if c would match */ - /* That means it is not safe to finalize */ - if (!not) - p[-3] = (unsigned char) finalize_jump; - } - } - } - p -= 2; - if (p[-1] != (unsigned char) finalize_jump) - { - p[-1] = (unsigned char) jump; - goto nofinalize; - } - - /* The end of a stupid repeat has a finalize-jump - back to the start, where another failure point will be made - which will point after all the repetitions found so far. */ - - case finalize_jump: - stackp -= 2; - - case jump: - nofinalize: - mcnt = *p++ & 0377; - mcnt += SIGN_EXTEND_CHAR (*(char *)p) << 8; - p += mcnt + 1; /* The 1 compensates for missing ++ above */ - break; - - case dummy_failure_jump: - if (stackp == stacke) - { - unsigned char **stackx - = (unsigned char **) alloca (2 * (stacke - stackb) - * sizeof (char *)); - bcopy (stackb, stackx, (stacke - stackb) * sizeof (char *)); - stackp = stackx + (stackp - stackb); - stacke = stackx + 2 * (stacke - stackb); - stackb = stackx; - } - *stackp++ = 0; - *stackp++ = 0; - goto nofinalize; - - case wordbound: - if (d == string1 /* Points to first char */ - || d == end2 /* Points to end */ - || (d == end1 && size2 == 0)) /* Points to end */ - break; - if ((SYNTAX (d[-1]) == Sword) - != (SYNTAX (d == end1 ? *string2 : *d) == Sword)) - break; - goto fail; - - case notwordbound: - if (d == string1 /* Points to first char */ - || d == end2 /* Points to end */ - || (d == end1 && size2 == 0)) /* Points to end */ - goto fail; - if ((SYNTAX (d[-1]) == Sword) - != (SYNTAX (d == end1 ? *string2 : *d) == Sword)) - goto fail; - break; - - case wordbeg: - if (d == end2 /* Points to end */ - || (d == end1 && size2 == 0) /* Points to end */ - || SYNTAX (* (d == end1 ? string2 : d)) != Sword) /* Next char not a letter */ - goto fail; - if (d == string1 /* Points to first char */ - || SYNTAX (d[-1]) != Sword) /* prev char not letter */ - break; - goto fail; - - case wordend: - if (d == string1 /* Points to first char */ - || SYNTAX (d[-1]) != Sword) /* prev char not letter */ - goto fail; - if (d == end2 /* Points to end */ - || (d == end1 && size2 == 0) /* Points to end */ - || SYNTAX (d == end1 ? *string2 : *d) != Sword) /* Next char not a letter */ - break; - goto fail; - -#ifdef emacs - case before_dot: - if (((d - string2 <= (unsigned) size2) - ? d - bf_p2 : d - bf_p1) - <= point) - goto fail; - break; - - case at_dot: - if (((d - string2 <= (unsigned) size2) - ? d - bf_p2 : d - bf_p1) - == point) - goto fail; - break; - - case after_dot: - if (((d - string2 <= (unsigned) size2) - ? d - bf_p2 : d - bf_p1) - >= point) - goto fail; - break; - - case wordchar: - mcnt = (int) Sword; - goto matchsyntax; - - case syntaxspec: - mcnt = *p++; - matchsyntax: - PREFETCH; - if (SYNTAX (*d++) != (enum syntaxcode) mcnt) goto fail; - break; - - case notwordchar: - mcnt = (int) Sword; - goto matchnotsyntax; - - case notsyntaxspec: - mcnt = *p++; - matchnotsyntax: - PREFETCH; - if (SYNTAX (*d++) == (enum syntaxcode) mcnt) goto fail; - break; -#else - case wordchar: - PREFETCH; - if (SYNTAX (*d++) == 0) goto fail; - break; - - case notwordchar: - PREFETCH; - if (SYNTAX (*d++) != 0) goto fail; - break; -#endif /* not emacs */ - - case begbuf: - if (d == string1) /* Note, d cannot equal string2 */ - break; /* unless string1 == string2. */ - goto fail; - - case endbuf: - if (d == end2 || (d == end1 && size2 == 0)) - break; - goto fail; - - case exactn: - /* Match the next few pattern characters exactly. - mcnt is how many characters to match. */ - mcnt = *p++; - if (translate) - { - do - { - PREFETCH; - if (translate[*d++] != *p++) goto fail; - } - while (--mcnt); - } - else - { - do - { - PREFETCH; - if (*d++ != *p++) goto fail; - } - while (--mcnt); - } - break; - } - continue; /* Successfully matched one pattern command; keep matching */ - - /* Jump here if any matching operation fails. */ - fail: - if (stackp != stackb) - /* A restart point is known. Restart there and pop it. */ - { - if (!stackp[-2]) - { /* If innermost failure point is dormant, flush it and keep looking */ - stackp -= 2; - goto fail; - } - d = *--stackp; - p = *--stackp; - if (d >= string1 && d <= end1) - dend = end_match_1; - } - else break; /* Matching at this starting point really fails! */ - } - return -1; /* Failure to match */ -} - -static int -bcmp_translate (s1, s2, len, translate) - unsigned char *s1, *s2; - register int len; - unsigned char *translate; -{ - register unsigned char *p1 = s1, *p2 = s2; - while (len) - { - if (translate [*p1++] != translate [*p2++]) return 1; - len--; - } - return 0; -} - -/* Entry points compatible with bsd4.2 regex library */ - -#ifndef emacs - -static struct re_pattern_buffer re_comp_buf; - -char * -re_comp (s) - char *s; -{ - if (!s) - { - if (!re_comp_buf.buffer) - return "No previous regular expression"; - return 0; - } - - if (!re_comp_buf.buffer) - { - if (!(re_comp_buf.buffer = (char *) malloc (200))) - return "Memory exhausted"; - re_comp_buf.allocated = 200; - if (!(re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH))) - return "Memory exhausted"; - } - return re_compile_pattern (s, strlen (s), &re_comp_buf); -} - -int -re_exec (s) - char *s; -{ - int len = strlen (s); - return 0 <= re_search (&re_comp_buf, s, len, 0, len, 0); -} - -#endif /* emacs */ - -#ifdef test - -#include - -/* Indexed by a character, gives the upper case equivalent of the character */ - -static char upcase[0400] = - { 000, 001, 002, 003, 004, 005, 006, 007, - 010, 011, 012, 013, 014, 015, 016, 017, - 020, 021, 022, 023, 024, 025, 026, 027, - 030, 031, 032, 033, 034, 035, 036, 037, - 040, 041, 042, 043, 044, 045, 046, 047, - 050, 051, 052, 053, 054, 055, 056, 057, - 060, 061, 062, 063, 064, 065, 066, 067, - 070, 071, 072, 073, 074, 075, 076, 077, - 0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107, - 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, - 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, - 0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137, - 0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107, - 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117, - 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127, - 0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177, - 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207, - 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217, - 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227, - 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237, - 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247, - 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257, - 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267, - 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277, - 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307, - 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317, - 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327, - 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337, - 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347, - 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357, - 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367, - 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377 - }; - -main (argc, argv) - int argc; - char **argv; -{ - char pat[80]; - struct re_pattern_buffer buf; - int i; - char c; - char fastmap[(1 << BYTEWIDTH)]; - - /* Allow a command argument to specify the style of syntax. */ - if (argc > 1) - obscure_syntax = atoi (argv[1]); - - buf.allocated = 40; - buf.buffer = (char *) malloc (buf.allocated); - buf.fastmap = fastmap; - buf.translate = upcase; - - while (1) - { - gets (pat); - - if (*pat) - { - re_compile_pattern (pat, strlen(pat), &buf); - - for (i = 0; i < buf.used; i++) - printchar (buf.buffer[i]); - - putchar ('\n'); - - printf ("%d allocated, %d used.\n", buf.allocated, buf.used); - - re_compile_fastmap (&buf); - printf ("Allowed by fastmap: "); - for (i = 0; i < (1 << BYTEWIDTH); i++) - if (fastmap[i]) printchar (i); - putchar ('\n'); - } - - gets (pat); /* Now read the string to match against */ - - i = re_match (&buf, pat, strlen (pat), 0, 0); - printf ("Match value %d.\n", i); - } -} - -#ifdef NOTDEF -print_buf (bufp) - struct re_pattern_buffer *bufp; -{ - int i; - - printf ("buf is :\n----------------\n"); - for (i = 0; i < bufp->used; i++) - printchar (bufp->buffer[i]); - - printf ("\n%d allocated, %d used.\n", bufp->allocated, bufp->used); - - printf ("Allowed by fastmap: "); - for (i = 0; i < (1 << BYTEWIDTH); i++) - if (bufp->fastmap[i]) - printchar (i); - printf ("\nAllowed by translate: "); - if (bufp->translate) - for (i = 0; i < (1 << BYTEWIDTH); i++) - if (bufp->translate[i]) - printchar (i); - printf ("\nfastmap is%s accurate\n", bufp->fastmap_accurate ? "" : "n't"); - printf ("can %s be null\n----------", bufp->can_be_null ? "" : "not"); -} -#endif - -printchar (c) - char c; -{ - if (c < 041 || c >= 0177) - { - putchar ('\\'); - putchar (((c >> 6) & 3) + '0'); - putchar (((c >> 3) & 7) + '0'); - putchar ((c & 7) + '0'); - } - else - putchar (c); -} - -error (string) - char *string; -{ - puts (string); - exit (1); -} - -#endif /* test */ diff --git a/gnu/usr.bin/gdb/regex.h b/gnu/usr.bin/gdb/regex.h deleted file mode 100644 index d0d8a82..0000000 --- a/gnu/usr.bin/gdb/regex.h +++ /dev/null @@ -1,185 +0,0 @@ -/* Definitions for data structures callers pass the regex library. - Copyright (C) 1985, 1989 Free Software Foundation, Inc. - - 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 1, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - - In other words, you are welcome to use, share and improve this program. - You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! */ - - -/* Define number of parens for which we record the beginnings and ends. - This affects how much space the `struct re_registers' type takes up. */ -#ifndef RE_NREGS -#define RE_NREGS 10 -#endif - -/* These bits are used in the obscure_syntax variable to choose among - alternative regexp syntaxes. */ - -/* 1 means plain parentheses serve as grouping, and backslash - parentheses are needed for literal searching. - 0 means backslash-parentheses are grouping, and plain parentheses - are for literal searching. */ -#define RE_NO_BK_PARENS 1 - -/* 1 means plain | serves as the "or"-operator, and \| is a literal. - 0 means \| serves as the "or"-operator, and | is a literal. */ -#define RE_NO_BK_VBAR 2 - -/* 0 means plain + or ? serves as an operator, and \+, \? are literals. - 1 means \+, \? are operators and plain +, ? are literals. */ -#define RE_BK_PLUS_QM 4 - -/* 1 means | binds tighter than ^ or $. - 0 means the contrary. */ -#define RE_TIGHT_VBAR 8 - -/* 1 means treat \n as an _OR operator - 0 means treat it as a normal character */ -#define RE_NEWLINE_OR 16 - -/* 0 means that a special characters (such as *, ^, and $) always have - their special meaning regardless of the surrounding context. - 1 means that special characters may act as normal characters in some - contexts. Specifically, this applies to: - ^ - only special at the beginning, or after ( or | - $ - only special at the end, or before ) or | - *, +, ? - only special when not after the beginning, (, or | */ -#define RE_CONTEXT_INDEP_OPS 32 - -/* Now define combinations of bits for the standard possibilities. */ -#define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS) -#define RE_SYNTAX_EGREP (RE_SYNTAX_AWK | RE_NEWLINE_OR) -#define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR) -#define RE_SYNTAX_EMACS 0 - -/* This data structure is used to represent a compiled pattern. */ - -struct re_pattern_buffer - { - char *buffer; /* Space holding the compiled pattern commands. */ - int allocated; /* Size of space that buffer points to */ - int used; /* Length of portion of buffer actually occupied */ - char *fastmap; /* Pointer to fastmap, if any, or zero if none. */ - /* re_search uses the fastmap, if there is one, - to skip quickly over totally implausible characters */ - char *translate; /* Translate table to apply to all characters before comparing. - Or zero for no translation. - The translation is applied to a pattern when it is compiled - and to data when it is matched. */ - char fastmap_accurate; - /* Set to zero when a new pattern is stored, - set to one when the fastmap is updated from it. */ - char can_be_null; /* Set to one by compiling fastmap - if this pattern might match the null string. - It does not necessarily match the null string - in that case, but if this is zero, it cannot. - 2 as value means can match null string - but at end of range or before a character - listed in the fastmap. */ - }; - -/* Structure to store "register" contents data in. - - Pass the address of such a structure as an argument to re_match, etc., - if you want this information back. - - start[i] and end[i] record the string matched by \( ... \) grouping i, - for i from 1 to RE_NREGS - 1. - start[0] and end[0] record the entire string matched. */ - -struct re_registers - { - int start[RE_NREGS]; - int end[RE_NREGS]; - }; - -/* These are the command codes that appear in compiled regular expressions, one per byte. - Some command codes are followed by argument bytes. - A command code can specify any interpretation whatever for its arguments. - Zero-bytes may appear in the compiled regular expression. */ - -enum regexpcode - { - unused, - exactn, /* followed by one byte giving n, and then by n literal bytes */ - begline, /* fails unless at beginning of line */ - endline, /* fails unless at end of line */ - jump, /* followed by two bytes giving relative address to jump to */ - on_failure_jump, /* followed by two bytes giving relative address of place - to resume at in case of failure. */ - finalize_jump, /* Throw away latest failure point and then jump to address. */ - maybe_finalize_jump, /* Like jump but finalize if safe to do so. - This is used to jump back to the beginning - of a repeat. If the command that follows - this jump is clearly incompatible with the - one at the beginning of the repeat, such that - we can be sure that there is no use backtracking - out of repetitions already completed, - then we finalize. */ - dummy_failure_jump, /* jump, and push a dummy failure point. - This failure point will be thrown away - if an attempt is made to use it for a failure. - A + construct makes this before the first repeat. */ - anychar, /* matches any one character */ - charset, /* matches any one char belonging to specified set. - First following byte is # bitmap bytes. - Then come bytes for a bit-map saying which chars are in. - Bits in each byte are ordered low-bit-first. - A character is in the set if its bit is 1. - A character too large to have a bit in the map - is automatically not in the set */ - charset_not, /* similar but match any character that is NOT one of those specified */ - start_memory, /* starts remembering the text that is matched - and stores it in a memory register. - followed by one byte containing the register number. - Register numbers must be in the range 0 through NREGS. */ - stop_memory, /* stops remembering the text that is matched - and stores it in a memory register. - followed by one byte containing the register number. - Register numbers must be in the range 0 through NREGS. */ - duplicate, /* match a duplicate of something remembered. - Followed by one byte containing the index of the memory register. */ - before_dot, /* Succeeds if before dot */ - at_dot, /* Succeeds if at dot */ - after_dot, /* Succeeds if after dot */ - begbuf, /* Succeeds if at beginning of buffer */ - endbuf, /* Succeeds if at end of buffer */ - wordchar, /* Matches any word-constituent character */ - notwordchar, /* Matches any char that is not a word-constituent */ - wordbeg, /* Succeeds if at word beginning */ - wordend, /* Succeeds if at word end */ - wordbound, /* Succeeds if at a word boundary */ - notwordbound, /* Succeeds if not at a word boundary */ - syntaxspec, /* Matches any character whose syntax is specified. - followed by a byte which contains a syntax code, Sword or such like */ - notsyntaxspec /* Matches any character whose syntax differs from the specified. */ - }; - -extern char *re_compile_pattern (); -/* Is this really advertised? */ -extern void re_compile_fastmap (); -extern int re_search (), re_search_2 (); -extern int re_match (), re_match_2 (); - -/* 4.2 bsd compatibility (yuck) */ -extern char *re_comp (); -extern int re_exec (); - -#ifdef SYNTAX_TABLE -extern char *re_syntax_table; -#endif diff --git a/gnu/usr.bin/gdb/remote-sl.c b/gnu/usr.bin/gdb/remote-sl.c deleted file mode 100644 index 4c72197..0000000 --- a/gnu/usr.bin/gdb/remote-sl.c +++ /dev/null @@ -1,10 +0,0 @@ -/* - * The binary remote protocol is still under development at LBL; - * the current version can't be released. - * Sorry, folks... - */ -int -sl_open() -{ - return -1; -} diff --git a/gnu/usr.bin/gdb/remote.c b/gnu/usr.bin/gdb/remote.c deleted file mode 100644 index 59658a8..0000000 --- a/gnu/usr.bin/gdb/remote.c +++ /dev/null @@ -1,626 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Van Jacobson and Steven McCanne of Lawrence Berkeley Laboratory. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Header: /home/cvs/386BSD/src/usr.bin/gdb/remote.c,v 1.1.1.1 1993/06/12 14:52:22 rgrimes Exp $; - */ - -#ifndef lint -static char sccsid[] = "@(#)remote.c 6.5 (Berkeley) 5/8/91"; -#endif /* not lint */ - -#include "param.h" - -#include -#include - -#include -#include -#include -#include - -#include "defs.h" -#include "frame.h" -#include "inferior.h" -#include "wait.h" - -#include "kgdb_proto.h" - -static FILE *kiodebug; -static int icache = 1; -extern int kernel_debugging; - -static int remote_cache_valid; -static int remote_instub; - -static void remote_signal(); -static void remote_debug(); -static void print_msg(); - -static int remote_mtu; -static int (*send_msg)(); -static int (*recv_msg)(); -static void (*closelink)(); - -static u_char *inbuffer; -static u_char *outbuffer; - -/* - * Statistics. - */ -static int remote_ierrs; -static int remote_oerrs; -static int remote_seqerrs; -static int remote_spurious; - -#define PUTCMD(cmd) m_xchg(cmd, (u_char *)0, 0, (u_char *)0, (int *)0) - -/* - * Send an outbound message to the remote machine and read the reply. - * Either or both message buffers may be NULL. - */ -static int -m_xchg(type, out, outlen, in, inlen) - int type; - u_char *out; - int outlen; - u_char *in; - int *inlen; -{ - register int err, (*send)() = send_msg, (*recv)() = recv_msg; - int ack; - static int seqbit = 0; - - if (!remote_instub) { - remote_instub = 1; - PUTCMD(KGDB_EXEC); - } - - seqbit ^= KGDB_SEQ; - while (1) { - err = (*send)(type | seqbit, out, outlen); - if (err) { - ++remote_oerrs; - if (kiodebug) - remote_debug("send error %d\n", err); - } - if (kiodebug) - print_msg(type | seqbit, out, outlen, 'O'); - - recv: - err = (*recv)(&ack, in, inlen); - if (err) { - ++remote_ierrs; - if (kiodebug) - remote_debug("recv error %d\n", err); - remote_cache_valid = 0; - } else if (kiodebug) - print_msg(ack, in, inlen ? *inlen : 0, 'I'); - - if (err) - continue; - - if ((ack & KGDB_ACK) == 0 || KGDB_CMD(ack) != KGDB_CMD(type)) { - ++remote_spurious; - continue; - } - if ((ack & KGDB_SEQ) ^ seqbit) { - ++remote_seqerrs; - goto recv; - } - return ack; - } -} - -/* - * Wait for the specified message type. Discard anything else. - * (this is used by 'remote-signal' to help us resync with other side.) - */ -static void -m_recv(type, in, inlen) - int type; - u_char *in; - int *inlen; -{ - int reply, err; - - while (1) { - err = (*recv_msg)(&reply, in, inlen); - if (err) { - ++remote_ierrs; - if (kiodebug) - remote_debug("recv error %d\n", err); - } else if (kiodebug) - print_msg(reply, in, inlen ? *inlen : 0, 'I'); - - if (KGDB_CMD(reply) == type) - return; - ++remote_spurious; - } -} - -/* - * Send a message. Do not wait for *any* response from the other side. - * Some other thread of control will pick up the ack that will be generated. - */ -static void -m_send(type, buf, len) - int type; - u_char *buf; - int len; -{ - int err; - - if (!remote_instub) { - remote_instub = 1; - PUTCMD(KGDB_EXEC); - } - - err = (*send_msg)(type, buf, len); - if (err) { - ++remote_ierrs; - if (kiodebug) - remote_debug("[send error %d] ", err); - } - if (kiodebug) - print_msg(type, buf, len, 'O'); -} - -/* - * Open a connection to a remote debugger. - * NAME is the filename used for communication. - */ -void -remote_open(name, from_tty) - char *name; - int from_tty; -{ - int bufsize; - - remote_debugging = 0; - if (sl_open(name, &send_msg, &recv_msg, &closelink, &remote_mtu, - &bufsize)) - return; - if (from_tty) - printf("Remote debugging using %s\n", name); - remote_debugging = 1; - - remote_cache_valid = 0; - - inbuffer = (u_char *)malloc(bufsize); - outbuffer = (u_char *)malloc(bufsize); - - remote_signal(); - - remote_ierrs = 0; - remote_oerrs = 0; - remote_spurious = 0; -} - -/* - * Close the open connection to the remote debugger. Use this when you want - * to detach and do something else with your gdb. - */ -void -remote_close(from_tty) - int from_tty; -{ - if (!remote_debugging) - error("remote debugging not enabled"); - - remote_debugging = 0; - /* - * Take remote machine out of debug mode. - */ - (void)PUTCMD(KGDB_KILL); - (*closelink)(); - if (from_tty) - printf("Ending remote debugging\n"); - - free((char *)inbuffer); - free((char *)outbuffer); -} - -/* - * Tell the remote machine to resume. - */ -int -remote_resume(step, signal) - int step, signal; -{ - if (!step) { - (void)PUTCMD(KGDB_CONT); - remote_instub = 0; - } else { -#ifdef NO_SINGLE_STEP - single_step(0); -#else - (void)PUTCMD(KGDB_STEP); -#endif - } -} - -/* - * Wait until the remote machine stops, then return, storing status in STATUS - * just as `wait' would. - */ -int -remote_wait(status) - WAITTYPE *status; -{ - int len; - - WSETEXIT((*status), 0); - /* - * When the machine stops, it will send us a KGDB_SIGNAL message, - * so we wait for one of these. - */ - m_recv(KGDB_SIGNAL, inbuffer, &len); - WSETSTOP((*status), inbuffer[0]); -} - -/* - * Register context as of last remote_fetch_registers(). - */ -static char reg_cache[REGISTER_BYTES]; - -/* - * Read the remote registers into the block REGS. - */ -void -remote_fetch_registers(regs) - char *regs; -{ - int regno, len, rlen, ack; - u_char *cp, *ep; - - regno = -1; - do { - outbuffer[0] = regno + 1; - ack = m_xchg(remote_cache_valid ? - KGDB_REG_R|KGDB_DELTA : KGDB_REG_R, - outbuffer, 1, inbuffer, &len); - cp = inbuffer; - ep = cp + len; - while (cp < ep) { - regno = *cp++; - rlen = REGISTER_RAW_SIZE(regno); - bcopy((char *)cp, - ®_cache[REGISTER_BYTE(regno)], rlen); - cp += rlen; - } - } while (ack & KGDB_MORE); - - remote_cache_valid = 1; - bcopy(reg_cache, regs, REGISTER_BYTES); -} - -/* - * Store the remote registers from the contents of the block REGS. - */ -void -remote_store_registers(regs) - char *regs; -{ - u_char *cp, *ep; - int regno, off, rlen; - - cp = outbuffer; - ep = cp + remote_mtu; - - for (regno = 0; regno < NUM_REGS; ++regno) { - off = REGISTER_BYTE(regno); - rlen = REGISTER_RAW_SIZE(regno); - if (!remote_cache_valid || - bcmp(®s[off], ®_cache[off], rlen) != 0) { - if (cp + rlen + 1 >= ep) { - (void)m_xchg(KGDB_REG_W, - outbuffer, cp - outbuffer, - (u_char *)0, (int *)0); - cp = outbuffer; - } - *cp++ = regno; - bcopy(®s[off], cp, rlen); - cp += rlen; - } - } - if (cp != outbuffer) - (void)m_xchg(KGDB_REG_W, outbuffer, cp - outbuffer, - (u_char *)0, (int *)0); - bcopy(regs, reg_cache, REGISTER_BYTES); -} - -/* - * Store a chunk of memory into the remote host. - * 'remote_addr' is the address in the remote memory space. - * 'cp' is the address of the buffer in our space, and 'len' is - * the number of bytes. Returns an errno status. - */ -int -remote_write_inferior_memory(remote_addr, cp, len) - CORE_ADDR remote_addr; - u_char *cp; - int len; -{ - int cnt; - - while (len > 0) { - cnt = min(len, remote_mtu - 4); - bcopy((char *)&remote_addr, outbuffer, 4); - bcopy(cp, outbuffer + 4, cnt); - (void)m_xchg(KGDB_MEM_W, outbuffer, cnt + 4, inbuffer, &len); - - if (inbuffer[0]) - return inbuffer[0]; - - remote_addr += cnt; - cp += cnt; - len -= cnt; - } - return 0; -} - -/* - * Read memory data directly from the remote machine. - * 'remote_addr' is the address in the remote memory space. - * 'cp' is the address of the buffer in our space, and 'len' is - * the number of bytes. Returns an errno status. - */ -static int -remote_read_memory(remote_addr, cp, len) - CORE_ADDR remote_addr; - u_char *cp; - int len; -{ - int cnt, inlen; - - while (len > 0) { - cnt = min(len, remote_mtu - 1); - outbuffer[0] = cnt; - bcopy((char *)&remote_addr, (char *)&outbuffer[1], 4); - - (void)m_xchg(KGDB_MEM_R, outbuffer, 5, inbuffer, &inlen); - - if (inbuffer[0] != 0) - return inbuffer[0]; - - if (cnt != inlen - 1) - /* XXX */ - error("remote_read_memory() request botched"); - - bcopy((char *)&inbuffer[1], (char *)cp, cnt); - - remote_addr += cnt; - cp += cnt; - len -= cnt; - } - return 0; -} - -int -remote_read_inferior_memory(remote_addr, cp, len) - CORE_ADDR remote_addr; - char *cp; - int len; -{ - int stat = 0; - - if (icache) { - extern CORE_ADDR text_start, text_end; - CORE_ADDR xferend = remote_addr + len; - - if (remote_addr < text_end && text_start < xferend) { - /* - * at least part of this xfer is in the text - * space -- xfer the overlap from the exec file. - */ - if (remote_addr >= text_start && xferend < text_end) - return (xfer_core_file(remote_addr, cp, len)); - if (remote_addr >= text_start) { - int i = text_end - remote_addr; - - if (stat = xfer_core_file(remote_addr, cp, i)) - return (stat); - remote_addr += i; - cp += i; - len -= i; - } else if (xferend <= text_end) { - int i = xferend - text_start; - - len = text_start - remote_addr; - if (stat = xfer_core_file(text_start, - cp + len, i)) - return (stat); - } - } - } - return remote_read_memory(remote_addr, cp, len); -} - -/* - * Signal the remote machine. The remote end might be idle or it might - * already be in debug mode -- we need to handle both case. Thus, we use - * the framing character as the wakeup byte, and send a SIGNAL packet. - * If the remote host is idle, the framing character will wake it up. - * If it is in the kgdb stub, then we will get a SIGNAL reply. - */ -static void -remote_signal() -{ - if (!remote_debugging) - printf("Remote debugging not enabled.\n"); - else { - remote_instub = 0; - m_send(KGDB_SIGNAL, (u_char *)0, 0); - } -} - -static void -remote_signal_command() -{ - extern int stop_after_attach; - - if (!remote_debugging) - error("Not debugging remote."); - remote_cache_valid = 0; - remote_signal(); - restart_remote(); -} - -/* - * Print a message for debugging. - */ -static void -print_msg(type, buf, len, dir) - int type; - u_char *buf; - int len; - int dir; -{ - int i; - char *s; - - switch (KGDB_CMD(type)) { - case KGDB_MEM_R: s = "memr"; break; - case KGDB_MEM_W: s = "memw"; break; - case KGDB_REG_R: s = "regr"; break; - case KGDB_REG_W: s = "regw"; break; - case KGDB_CONT: s = "cont"; break; - case KGDB_STEP: s = "step"; break; - case KGDB_KILL: s = "kill"; break; - case KGDB_SIGNAL: s = "sig "; break; - case KGDB_EXEC: s = "exec"; break; - default: s = "unk "; break; - } - remote_debug("%c %c%c%c%c %s (%02x): ", dir, - (type & KGDB_ACK) ? 'A' : '.', - (type & KGDB_DELTA) ? 'D' : '.', - (type & KGDB_MORE) ? 'M' : '.', - (type & KGDB_SEQ) ? '-' : '+', - s, type); - if (buf) - for (i = 0; i < len; ++i) - remote_debug("%02x", buf[i]); - remote_debug("\n"); -} - -static void -set_remote_text_refs_command(arg, from_tty) - char *arg; - int from_tty; -{ - icache = !parse_binary_operation("set remote-text-refs", arg); -} - -static void -remote_debug_command(arg, from_tty) - char *arg; - int from_tty; -{ - char *name; - - if (kiodebug != 0 && kiodebug != stderr) - (void)fclose(kiodebug); - - if (arg == 0) { - kiodebug = 0; - printf("Remote debugging off.\n"); - return; - } - if (arg[0] == '-') { - kiodebug = stderr; - name = "stderr"; - } else { - kiodebug = fopen(arg, "w"); - if (kiodebug == 0) { - printf("Cannot open '%s'.\n", arg); - return; - } - name = arg; - } - printf("Remote debugging output routed to %s.\n", name); -} - -/* ARGSUSED */ -static void -remote_info(arg, from_tty) - char *arg; - int from_tty; -{ - printf("Using %s for text references.\n", - icache? "local executable" : "remote"); - printf("Protocol debugging is %s.\n", kiodebug? "on" : "off"); - printf("%d spurious input messages.\n", remote_spurious); - printf("%d input errors; %d output errors; %d sequence errors.\n", - remote_ierrs, remote_oerrs, remote_seqerrs); -} - -/* VARARGS */ -static void -remote_debug(va_alist) - va_dcl -{ - register char *cp; - va_list ap; - - va_start(ap); - cp = va_arg(ap, char *); - (void)vfprintf(kiodebug, cp, ap); - va_end(ap); - fflush(kiodebug); -} - -extern struct cmd_list_element *setlist; - -void -_initialize_remote() -{ - add_com("remote-signal", class_run, remote_signal_command, - "If remote debugging, send interrupt signal to remote."); - add_cmd("remote-text-refs", class_support, - set_remote_text_refs_command, -"Enable/disable use of local executable for text segment references.\n\ -If on, all memory read/writes go to remote.\n\ -If off, text segment reads use the local executable.", - &setlist); - - add_com("remote-debug", class_run, remote_debug_command, -"With a file name argument, enables output of remote protocol debugging\n\ -messages to said file. If file is `-', stderr is used.\n\ -With no argument, remote debugging is disabled."); - - add_info("remote", remote_info, - "Show current settings of remote debugging options."); -} - diff --git a/gnu/usr.bin/gdb/source.c b/gnu/usr.bin/gdb/source.c deleted file mode 100644 index bb65e1c..0000000 --- a/gnu/usr.bin/gdb/source.c +++ /dev/null @@ -1,1166 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)source.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* List lines of source files for GDB, the GNU debugger. - Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include -#include "defs.h" -#include "param.h" -#include "symtab.h" - -#ifdef USG -#include -#include -#endif - -#include -#include -#include - -/* Path of directories to search for source files. - Same format as the PATH environment variable's value. */ - -static char *source_path; - -/* Symtab of default file for listing lines of. */ - -struct symtab *current_source_symtab; - -/* Default next line to list. */ - -int current_source_line; - -/* Line number of last line printed. Default for various commands. - current_source_line is usually, but not always, the same as this. */ - -static int last_line_listed; - -/* First line number listed by last listing command. */ - -static int first_line_listed; - - -struct symtab *psymtab_to_symtab (); - -/* Set the source file default for the "list" command, specifying a - symtab. Sigh. Behaivior specification: If it is called with a - non-zero argument, that is the symtab to select. If it is not, - first lookup "main"; if it exists, use the symtab and line it - defines. If not, take the last symtab in the symtab_list (if it - exists) or the last symtab in the psytab_list (if *it* exists). If - none of this works, report an error. */ - -void -select_source_symtab (s) - register struct symtab *s; -{ - struct symtabs_and_lines sals; - struct symtab_and_line sal; - struct partial_symtab *ps, *cs_pst; - - if (s) - { - current_source_symtab = s; - current_source_line = 1; - return; - } - - /* Make the default place to list be the function `main' - if one exists. */ - if (lookup_symbol ("main", 0, VAR_NAMESPACE, 0)) - { - sals = decode_line_spec ("main", 1); - sal = sals.sals[0]; - free (sals.sals); - current_source_symtab = sal.symtab; - current_source_line = max (sal.line - 9, 1); - return; - } - - /* All right; find the last file in the symtab list (ignoring .h's). */ - - if (s = symtab_list) - { - do - { - char *name = s->filename; - int len = strlen (name); - if (! (len > 2 && !strcmp (&name[len - 2], ".h"))) - current_source_symtab = s; - s = s->next; - } - while (s); - current_source_line = 1; - } - else if (partial_symtab_list) - { - ps = partial_symtab_list; - while (ps) - { - char *name = ps->filename; - int len = strlen (name); - if (! (len > 2 && !strcmp (&name[len - 2], ".h"))) - cs_pst = ps; - ps = ps->next; - } - if (cs_pst) - if (cs_pst->readin) - fatal ("Internal: select_source_symtab: readin pst found and no symtabs."); - else - current_source_symtab = psymtab_to_symtab (cs_pst); - else - current_source_symtab = 0; - current_source_line = 1; - } -} - -static void -directories_info () -{ - printf ("Source directories searched: %s\n", source_path); -} - -void -init_source_path () -{ - register struct symtab *s; - - source_path = savestring (current_directory, strlen (current_directory)); - - /* Forget what we learned about line positions in source files; - must check again now since files may be found in - a different directory now. */ - for (s = symtab_list; s; s = s->next) - if (s->line_charpos != 0) - { - free (s->line_charpos); - s->line_charpos = 0; - } -} - -void -directory_command (dirname, from_tty) - char *dirname; - int from_tty; -{ - char *old = source_path; - - dont_repeat (); - - if (dirname == 0) - { - if (query ("Reinitialize source path to %s? ", current_directory)) - { - init_source_path (); - free (old); - } - } - else - { - dirname = tilde_expand (dirname); - make_cleanup (free, dirname); - - do - { - char *name = dirname; - register char *p; - struct stat st; - - { - char *colon = index (name, ':'); - char *space = index (name, ' '); - char *tab = index (name, '\t'); - if (colon == 0 && space == 0 && tab == 0) - p = dirname = name + strlen (name); - else - { - p = 0; - if (colon != 0 && (p == 0 || colon < p)) - p = colon; - if (space != 0 && (p == 0 || space < p)) - p = space; - if (tab != 0 && (p == 0 || tab < p)) - p = tab; - dirname = p + 1; - while (*dirname == ':' || *dirname == ' ' || *dirname == '\t') - ++dirname; - } - } - - if (p[-1] == '/') - /* Sigh. "foo/" => "foo" */ - --p; - *p = '\0'; - - while (p[-1] == '.') - { - if (p - name == 1) - { - /* "." => getwd (). */ - name = current_directory; - goto append; - } - else if (p[-2] == '/') - { - if (p - name == 2) - { - /* "/." => "/". */ - *--p = '\0'; - goto append; - } - else - { - /* "...foo/." => "...foo". */ - p -= 2; - *p = '\0'; - continue; - } - } - else - break; - } - - if (*name != '/') - name = concat (current_directory, "/", name); - else - name = savestring (name, p - name); - make_cleanup (free, name); - - if (stat (name, &st) < 0) - perror_with_name (name); - if ((st.st_mode & S_IFMT) != S_IFDIR) - error ("%s is not a directory.", name); - - append: - { - register unsigned int len = strlen (name); - - p = source_path; - while (1) - { - if (!strncmp (p, name, len) - && (p[len] == '\0' || p[len] == ':')) - { - if (from_tty) - printf ("\"%s\" is already in the source path.\n", name); - break; - } - p = index (p, ':'); - if (p != 0) - ++p; - else - break; - } - if (p == 0) - { - source_path = concat (old, ":", name); - free (old); - old = source_path; - } - } - } while (*dirname != '\0'); - if (from_tty) - directories_info (); - } -} - -/* Open a file named STRING, searching path PATH (dir names sep by colons) - using mode MODE and protection bits PROT in the calls to open. - If TRY_CWD_FIRST, try to open ./STRING before searching PATH. - (ie pretend the first element of PATH is ".") - If FILENAMED_OPENED is non-null, set it to a newly allocated string naming - the actual file opened (this string will always start with a "/" - - If a file is found, return the descriptor. - Otherwise, return -1, with errno set for the last name we tried to open. */ - -/* >>>> This should only allow files of certain types, - >>>> eg executable, non-directory */ -int -openp (path, try_cwd_first, string, mode, prot, filename_opened) - char *path; - int try_cwd_first; - char *string; - int mode; - int prot; - char **filename_opened; -{ - register int fd; - register char *filename; - register char *p, *p1; - register int len; - - if (!path) - path = "."; - - /* ./foo => foo */ - while (string[0] == '.' && string[1] == '/') - string += 2; - - if (try_cwd_first || string[0] == '/') - { - filename = string; - fd = open (filename, mode, prot); - if (fd >= 0 || string[0] == '/') - goto done; - } - - filename = (char *) alloca (strlen (path) + strlen (string) + 2); - fd = -1; - for (p = path; p; p = p1 ? p1 + 1 : 0) - { - p1 = (char *) index (p, ':'); - if (p1) - len = p1 - p; - else - len = strlen (p); - - strncpy (filename, p, len); - filename[len] = 0; - strcat (filename, "/"); - strcat (filename, string); - - fd = open (filename, mode, prot); - if (fd >= 0) break; - } - - done: - if (filename_opened) - if (fd < 0) - *filename_opened = (char *) 0; - else if (filename[0] == '/') - *filename_opened = savestring (filename, strlen (filename)); - else - { - *filename_opened = concat (current_directory, "/", filename); - } - - return fd; -} - -/* Create and initialize the table S->line_charpos that records - the positions of the lines in the source file, which is assumed - to be open on descriptor DESC. - All set S->nlines to the number of such lines. */ - -static void -find_source_lines (s, desc) - struct symtab *s; - int desc; -{ - struct stat st; - register char *data, *p, *end; - int nlines = 0; - int lines_allocated = 1000; - int *line_charpos = (int *) xmalloc (lines_allocated * sizeof (int)); - extern int exec_mtime; - - if (fstat (desc, &st) < 0) - perror_with_name (s->filename); - if (get_exec_file (0) != 0 && exec_mtime < st.st_mtime) - printf ("Source file is more recent than executable.\n"); - - data = (char *) alloca (st.st_size); - if (myread (desc, data, st.st_size) < 0) - perror_with_name (s->filename); - end = data + st.st_size; - p = data; - line_charpos[0] = 0; - nlines = 1; - while (p != end) - { - if (*p++ == '\n' - /* A newline at the end does not start a new line. */ - && p != end) - { - if (nlines == lines_allocated) - { - lines_allocated *= 2; - line_charpos = (int *) xrealloc (line_charpos, - sizeof (int) * lines_allocated); - } - line_charpos[nlines++] = p - data; - } - } - s->nlines = nlines; - s->line_charpos = (int *) xrealloc (line_charpos, nlines * sizeof (int)); -} - -/* Return the character position of a line LINE in symtab S. - Return 0 if anything is invalid. */ - -int -source_line_charpos (s, line) - struct symtab *s; - int line; -{ - if (!s) return 0; - if (!s->line_charpos || line <= 0) return 0; - if (line > s->nlines) - line = s->nlines; - return s->line_charpos[line - 1]; -} - -/* Return the line number of character position POS in symtab S. */ - -int -source_charpos_line (s, chr) - register struct symtab *s; - register int chr; -{ - register int line = 0; - register int *lnp; - - if (s == 0 || s->line_charpos == 0) return 0; - lnp = s->line_charpos; - /* Files are usually short, so sequential search is Ok */ - while (line < s->nlines && *lnp <= chr) - { - line++; - lnp++; - } - if (line >= s->nlines) - line = s->nlines; - return line; -} - -/* Get full pathname and line number positions for a symtab. - Return nonzero if line numbers may have changed. - Set *FULLNAME to actual name of the file as found by `openp', - or to 0 if the file is not found. */ - -int -get_filename_and_charpos (s, line, fullname) - struct symtab *s; - int line; - char **fullname; -{ - register int desc, linenums_changed = 0; - - desc = openp (source_path, 0, s->filename, O_RDONLY, 0, &s->fullname); - if (desc < 0) - { - if (fullname) - *fullname = NULL; - return 0; - } - if (fullname) - *fullname = s->fullname; - if (s->line_charpos == 0) linenums_changed = 1; - if (linenums_changed) find_source_lines (s, desc); - close (desc); - return linenums_changed; -} - -/* Print text describing the full name of the source file S - and the line number LINE and its corresponding character position. - The text starts with two Ctrl-z so that the Emacs-GDB interface - can easily find it. - - MID_STATEMENT is nonzero if the PC is not at the beginning of that line. - - Return 1 if successful, 0 if could not find the file. */ - -int -identify_source_line (s, line, mid_statement) - struct symtab *s; - int line; - int mid_statement; -{ - if (s->line_charpos == 0) - get_filename_and_charpos (s, line, 0); - if (s->fullname == 0) - return 0; - printf ("\032\032%s:%d:%d:%s:0x%x\n", s->fullname, - line, s->line_charpos[line - 1], - mid_statement ? "middle" : "beg", - get_frame_pc (get_current_frame())); - current_source_line = line; - first_line_listed = line; - last_line_listed = line; - current_source_symtab = s; - return 1; -} - -/* Print source lines from the file of symtab S, - starting with line number LINE and stopping before line number STOPLINE. */ - -void -print_source_lines (s, line, stopline, noerror) - struct symtab *s; - int line, stopline; - int noerror; -{ - register int c; - register int desc; - register FILE *stream; - int nlines = stopline - line; - - desc = openp (source_path, 0, s->filename, O_RDONLY, 0, &s->fullname); - if (desc < 0) - { - extern int errno; - if (noerror && line + 1 == stopline) - { - /* can't find the file - tell user where we are anyway */ - current_source_symtab = s; - current_source_line = line; - first_line_listed = line; - last_line_listed = line; - printf_filtered ("%d\t(%s)\n", current_source_line++, s->filename); - } - else - { - if (! noerror) - perror_with_name (s->filename); - print_sys_errmsg (s->filename, errno); - } - return; - } - - if (s->line_charpos == 0) - find_source_lines (s, desc); - - if (line < 1 || line > s->nlines) - { - close (desc); - error ("Line number %d out of range; %s has %d lines.", - line, s->filename, s->nlines); - } - - if (lseek (desc, s->line_charpos[line - 1], 0) < 0) - { - close (desc); - perror_with_name (s->filename); - } - - current_source_symtab = s; - current_source_line = line; - first_line_listed = line; - - stream = fdopen (desc, "r"); - clearerr (stream); - - while (nlines-- > 0) - { - c = fgetc (stream); - if (c == EOF) break; - last_line_listed = current_source_line; - printf_filtered ("%d\t", current_source_line++); - do - { - if (c < 040 && c != '\t' && c != '\n') - printf_filtered ("^%c", c + 0100); - else if (c == 0177) - printf_filtered ("^?"); - else - printf_filtered ("%c", c); - } while (c != '\n' && (c = fgetc (stream)) >= 0); - } - - fclose (stream); -} - - - -/* - C++ - Print a list of files and line numbers which a user may choose from - in order to list a function which was specified ambiguously - (as with `list classname::overloadedfuncname', for example). - The vector in SALS provides the filenames and line numbers. - */ -static void -ambiguous_line_spec (sals) - struct symtabs_and_lines *sals; -{ - int i; - - for (i = 0; i < sals->nelts; ++i) - printf("file: \"%s\", line number: %d\n", - sals->sals[i].symtab->filename, sals->sals[i].line); -} - - -static void -file_command(arg, from_tty) - char *arg; - int from_tty; -{ - struct symtabs_and_lines sals; - struct symtab_and_line sal; - struct symbol *sym; - char *arg1; - int linenum_beg = 0; - char *p; - - if (symtab_list == 0 && partial_symtab_list == 0) - error ("No symbol table is loaded. Use the \"symbol-file\" command."); - - /* Pull in a current source symtab if necessary */ - if (arg == 0 || arg[0] == 0) { - if (current_source_symtab == 0) - select_source_symtab(0); - else - printf("%s\n", current_source_symtab->filename); - return; - } - arg1 = arg; - sals = decode_line_1 (&arg1, 0, 0, 0); - - if (! sals.nelts) - return; /* C++ */ - - if (sals.nelts > 1) - { - ambiguous_line_spec (&sals); - free (sals.sals); - return; - } - - sal = sals.sals[0]; - free (sals.sals); - - /* Record whether the BEG arg is all digits. */ - - for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; ++p) - ; - linenum_beg = (p == arg1); - - /* if line was specified by address, - print exactly which line, and which file. - In this case, sal.symtab == 0 means address is outside - of all known source files, not that user failed to give a filename. */ - if (*arg == '*') - { - if (sal.symtab == 0) - error ("No source file for address 0x%x.", sal.pc); - sym = find_pc_function (sal.pc); - if (sym) - printf ("0x%x is in %s (%s, line %d).\n", - sal.pc, SYMBOL_NAME (sym), sal.symtab->filename, sal.line); - else - printf ("0x%x is in %s, line %d.\n", - sal.pc, sal.symtab->filename, sal.line); - } - - /* If line was not specified by just a line number, - and it does not imply a symtab, it must be an undebuggable symbol - which means no source code. */ - - if (sal.symtab == 0) - { - if (! linenum_beg) - error ("No line number known for %s.", arg); - else - error ("No default source file yet. Do \"help list\"."); - } - else - { - current_source_symtab = sal.symtab; - current_source_line = sal.line; - first_line_listed = sal.line; - } -} - -#define PUSH_STACK_SIZE 32 -static struct { - struct symtab *symtab; - int line; -} push_stack[PUSH_STACK_SIZE]; - -static unsigned int push_stack_ptr; - -static void -push_to_file_command (arg, from_tty) - char *arg; - int from_tty; -{ - struct symtab *cursym = current_source_symtab; - int curline = current_source_line; - register unsigned int i; - - file_command(arg, from_tty); - - /* if we got back, command was successful */ - i = push_stack_ptr; - push_stack[i].symtab = cursym; - push_stack[i].line = curline; - push_stack_ptr = (i + 1) & (PUSH_STACK_SIZE - 1); -} - -static void -pop_file_command (arg, from_tty) - char *arg; - int from_tty; -{ - register unsigned int i = push_stack_ptr; - - /* if there's something on the stack, pop it & clear the slot. */ - i = (i + (PUSH_STACK_SIZE - 1)) & (PUSH_STACK_SIZE - 1); - if (push_stack[i].symtab) { - current_source_symtab = push_stack[i].symtab; - first_line_listed = current_source_line = push_stack[i].line; - push_stack[i].symtab = NULL; - push_stack_ptr = i; - } -} - - -static void -list_command (arg, from_tty) - char *arg; - int from_tty; -{ - struct symtabs_and_lines sals, sals_end; - struct symtab_and_line sal, sal_end; - struct symbol *sym; - char *arg1; - int no_end = 1; - int dummy_end = 0; - int dummy_beg = 0; - int linenum_beg = 0; - char *p; - - if (symtab_list == 0 && partial_symtab_list == 0) - error ("No symbol table is loaded. Use the \"symbol-file\" command."); - - /* Pull in a current source symtab if necessary */ - if (current_source_symtab == 0 && - (arg == 0 || arg[0] == '+' || arg[0] == '-')) - select_source_symtab (0); - - /* "l" or "l +" lists next ten lines. */ - - if (arg == 0 || !strcmp (arg, "+")) - { - if (current_source_symtab == 0) - error ("No default source file yet. Do \"help list\"."); - print_source_lines (current_source_symtab, current_source_line, - current_source_line + 10, 0); - return; - } - - /* "l -" lists previous ten lines, the ones before the ten just listed. */ - if (!strcmp (arg, "-")) - { - if (current_source_symtab == 0) - error ("No default source file yet. Do \"help list\"."); - print_source_lines (current_source_symtab, - max (first_line_listed - 10, 1), - first_line_listed, 0); - return; - } - - /* Now if there is only one argument, decode it in SAL - and set NO_END. - If there are two arguments, decode them in SAL and SAL_END - and clear NO_END; however, if one of the arguments is blank, - set DUMMY_BEG or DUMMY_END to record that fact. */ - - arg1 = arg; - if (*arg1 == ',') - dummy_beg = 1; - else - { - sals = decode_line_1 (&arg1, 0, 0, 0); - - if (! sals.nelts) return; /* C++ */ - if (sals.nelts > 1) - { - ambiguous_line_spec (&sals); - free (sals.sals); - return; - } - - sal = sals.sals[0]; - free (sals.sals); - } - - /* Record whether the BEG arg is all digits. */ - - for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; p++); - linenum_beg = (p == arg1); - - while (*arg1 == ' ' || *arg1 == '\t') - arg1++; - if (*arg1 == ',') - { - no_end = 0; - arg1++; - while (*arg1 == ' ' || *arg1 == '\t') - arg1++; - if (*arg1 == 0) - dummy_end = 1; - else - { - if (dummy_beg) - sals_end = decode_line_1 (&arg1, 0, 0, 0); - else - sals_end = decode_line_1 (&arg1, 0, sal.symtab, sal.line); - if (sals_end.nelts == 0) - return; - if (sals_end.nelts > 1) - { - ambiguous_line_spec (&sals_end); - free (sals_end.sals); - return; - } - sal_end = sals_end.sals[0]; - free (sals_end.sals); - } - } - - if (*arg1) - error ("Junk at end of line specification."); - - if (!no_end && !dummy_beg && !dummy_end - && sal.symtab != sal_end.symtab) - error ("Specified start and end are in different files."); - if (dummy_beg && dummy_end) - error ("Two empty args do not say what lines to list."); - - /* if line was specified by address, - first print exactly which line, and which file. - In this case, sal.symtab == 0 means address is outside - of all known source files, not that user failed to give a filename. */ - if (*arg == '*') - { - if (sal.symtab == 0) - error ("No source file for address 0x%x.", sal.pc); - sym = find_pc_function (sal.pc); - if (sym) - printf ("0x%x is in %s (%s, line %d).\n", - sal.pc, SYMBOL_NAME (sym), sal.symtab->filename, sal.line); - else - printf ("0x%x is in %s, line %d.\n", - sal.pc, sal.symtab->filename, sal.line); - } - - /* If line was not specified by just a line number, - and it does not imply a symtab, it must be an undebuggable symbol - which means no source code. */ - - if (! linenum_beg && sal.symtab == 0) - error ("No line number known for %s.", arg); - - /* If this command is repeated with RET, - turn it into the no-arg variant. */ - - if (from_tty) - *arg = 0; - - if (dummy_beg && sal_end.symtab == 0) - error ("No default source file yet. Do \"help list\"."); - if (dummy_beg) - print_source_lines (sal_end.symtab, max (sal_end.line - 9, 1), - sal_end.line + 1, 0); - else if (sal.symtab == 0) - error ("No default source file yet. Do \"help list\"."); - else if (no_end) - print_source_lines (sal.symtab, max (sal.line - 5, 1), sal.line + 5, 0); - else - print_source_lines (sal.symtab, sal.line, - dummy_end ? sal.line + 10 : sal_end.line + 1, - 0); -} - -/* Print info on range of pc's in a specified line. */ - -static void -line_info (arg, from_tty) - char *arg; - int from_tty; -{ - struct symtabs_and_lines sals; - struct symtab_and_line sal; - int start_pc, end_pc; - int i; - - if (arg == 0) - { - sal.symtab = current_source_symtab; - sal.line = last_line_listed; - sals.nelts = 1; - sals.sals = (struct symtab_and_line *) - xmalloc (sizeof (struct symtab_and_line)); - sals.sals[0] = sal; - } - else - { - sals = decode_line_spec_1 (arg, 0); - - /* If this command is repeated with RET, - turn it into the no-arg variant. */ - if (from_tty) - *arg = 0; - } - - /* C++ More than one line may have been specified, as when the user - specifies an overloaded function name. Print info on them all. */ - for (i = 0; i < sals.nelts; i++) - { - sal = sals.sals[i]; - - if (sal.symtab == 0) - error ("No source file specified."); - - if (sal.line > 0 - && find_line_pc_range (sal.symtab, sal.line, &start_pc, &end_pc)) - { - if (start_pc == end_pc) - printf ("Line %d of \"%s\" is at pc 0x%x but contains no code.\n", - sal.line, sal.symtab->filename, start_pc); - else - printf ("Line %d of \"%s\" starts at pc 0x%x and ends at 0x%x.\n", - sal.line, sal.symtab->filename, start_pc, end_pc); - /* x/i should display this line's code. */ - set_next_address (start_pc); - /* Repeating "info line" should do the following line. */ - last_line_listed = sal.line + 1; - } - else - printf ("Line number %d is out of range for \"%s\".\n", - sal.line, sal.symtab->filename); - } -} - -/* Commands to search the source file for a regexp. */ - -static void -forward_search_command (regex, from_tty) - char *regex; -{ - register int c; - register int desc; - register FILE *stream; - int line = last_line_listed + 1; - char *msg; - - msg = (char *) re_comp (regex); - if (msg) - error (msg); - - if (current_source_symtab == 0) - select_source_symtab (0); - - /* Search from last_line_listed+1 in current_source_symtab */ - - desc = openp (source_path, 0, current_source_symtab->filename, - O_RDONLY, 0, ¤t_source_symtab->fullname); - if (desc < 0) - perror_with_name (current_source_symtab->filename); - - if (current_source_symtab->line_charpos == 0) - find_source_lines (current_source_symtab, desc); - - if (line < 1 || line > current_source_symtab->nlines) - { - close (desc); - error ("Expression not found"); - } - - if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0) - { - close (desc); - perror_with_name (current_source_symtab->filename); - } - - stream = fdopen (desc, "r"); - clearerr (stream); - while (1) { - char buf[4096]; /* Should be reasonable??? */ - register char *p = buf; - - c = fgetc (stream); - if (c == EOF) - break; - do { - *p++ = c; - } while (c != '\n' && (c = fgetc (stream)) >= 0); - - /* we now have a source line in buf, null terminate and match */ - *p = 0; - if (re_exec (buf) > 0) - { - /* Match! */ - fclose (stream); - print_source_lines (current_source_symtab, - line, line+1, 0); - current_source_line = max (line - 5, 1); - return; - } - line++; - } - - printf ("Expression not found\n"); - fclose (stream); -} - -static void -reverse_search_command (regex, from_tty) - char *regex; -{ - register int c; - register int desc; - register FILE *stream; - int line = last_line_listed - 1; - char *msg; - - msg = (char *) re_comp (regex); - if (msg) - error (msg); - - if (current_source_symtab == 0) - select_source_symtab (0); - - /* Search from last_line_listed-1 in current_source_symtab */ - - desc = openp (source_path, 0, current_source_symtab->filename, - O_RDONLY, 0, ¤t_source_symtab->fullname); - if (desc < 0) - perror_with_name (current_source_symtab->filename); - - if (current_source_symtab->line_charpos == 0) - find_source_lines (current_source_symtab, desc); - - if (line < 1 || line > current_source_symtab->nlines) - { - close (desc); - error ("Expression not found"); - } - - if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0) - { - close (desc); - perror_with_name (current_source_symtab->filename); - } - - stream = fdopen (desc, "r"); - clearerr (stream); - while (1) - { - char buf[4096]; /* Should be reasonable??? */ - register char *p = buf; - - c = fgetc (stream); - if (c == EOF) - break; - do { - *p++ = c; - } while (c != '\n' && (c = fgetc (stream)) >= 0); - - /* We now have a source line in buf; null terminate and match. */ - *p = 0; - if (re_exec (buf) > 0) - { - /* Match! */ - fclose (stream); - print_source_lines (current_source_symtab, - line, line+1, 0); - current_source_line = max (line - 5, 1); - return; - } - line--; - if (fseek (stream, current_source_symtab->line_charpos[line - 1], 0) < 0) - { - fclose (stream); - perror_with_name (current_source_symtab->filename); - } - } - - printf ("Expression not found\n"); - fclose (stream); - return; -} - -void -_initialize_source () -{ - current_source_symtab = 0; - init_source_path (); - - add_com ("directory", class_files, directory_command, - "Add directory DIR to end of search path for source files.\n\ -With no argument, reset the search path to just the working directory\n\ -and forget cached info on line positions in source files."); - - add_info ("directories", directories_info, - "Current search path for finding source files."); - - add_info ("line", line_info, - "Core addresses of the code for a source line.\n\ -Line can be specified as\n\ - LINENUM, to list around that line in current file,\n\ - FILE:LINENUM, to list around that line in that file,\n\ - FUNCTION, to list around beginning of that function,\n\ - FILE:FUNCTION, to distinguish among like-named static functions.\n\ -Default is to describe the last source line that was listed.\n\n\ -This sets the default address for \"x\" to the line's first instruction\n\ -so that \"x/i\" suffices to start examining the machine code.\n\ -The address is also stored as the value of \"$_\"."); - - add_com ("forward-search", class_files, forward_search_command, - "Search for regular expression (see regex(3)) from last line listed."); - add_com_alias ("search", "forward-search", class_files, 0); - - add_com ("reverse-search", class_files, reverse_search_command, - "Search backward for regular expression (see regex(3)) from last line listed."); - - add_com ("list", class_files, list_command, - "List specified function or line.\n\ -With no argument, lists ten more lines after or around previous listing.\n\ -\"list -\" lists the ten lines before a previous ten-line listing.\n\ -One argument specifies a line, and ten lines are listed around that line.\n\ -Two arguments with comma between specify starting and ending lines to list.\n\ -Lines can be specified in these ways:\n\ - LINENUM, to list around that line in current file,\n\ - FILE:LINENUM, to list around that line in that file,\n\ - FUNCTION, to list around beginning of that function,\n\ - FILE:FUNCTION, to distinguish among like-named static functions.\n\ - *ADDRESS, to list around the line containing that address.\n\ -With two args if one is empty it stands for ten lines away from the other arg."); - add_com ("file", class_files, file_command, - "Select current file, function and line for display or list.\n\ -Specification can have the form:\n\ - LINENUM, to select that line in current file,\n\ - FILE:LINENUM, to select that line in that file,\n\ - FUNCTION, to select beginning of that function,\n\ - FILE:FUNCTION, to distinguish among like-named static functions.\n\ - *ADDRESS, to select the line containing that address."); - add_com ("push-to-file", class_files, push_to_file_command, - "Like \"file\" command but remembers current file & line on a stack.\n\ -Can later return to current file with \"pop-file\" command.\n\ -Up to 32 file positions can be pushed on stack."); - add_com ("pop-file", class_files, pop_file_command, - "Pops back to file position saved by most recent \"push-to-file\".\n\ -If everything has been popped from stack, command does nothing."); -} - diff --git a/gnu/usr.bin/gdb/stab.def b/gnu/usr.bin/gdb/stab.def deleted file mode 100644 index b81cda4..0000000 --- a/gnu/usr.bin/gdb/stab.def +++ /dev/null @@ -1,115 +0,0 @@ -/* Table of DBX symbol codes for the GNU system. - Copyright (C) 1988 Free Software Foundation, Inc. - - 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 1, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Global variable. Only the name is significant. - To find the address, look in the corresponding external symbol. */ -__define_stab (N_GSYM, 0x20, "GSYM") - -/* Function name for BSD Fortran. Only the name is significant. - To find the address, look in the corresponding external symbol. */ -__define_stab (N_FNAME, 0x22, "FNAME") - -/* Function name or text-segment variable for C. Value is its address. - Desc is supposedly starting line number, but GCC doesn't set it - and DBX seems not to miss it. */ -__define_stab (N_FUN, 0x24, "FUN") - -/* Data-segment variable with internal linkage. Value is its address. */ -__define_stab (N_STSYM, 0x26, "STSYM") - -/* BSS-segment variable with internal linkage. Value is its address. */ -__define_stab (N_LCSYM, 0x28, "LCSYM") - -/* Name of main routine. Only the name is significant. - This is not used in C. */ -__define_stab (N_MAIN, 0x2a, "MAIN") - -/* Register variable. Value is number of register. */ -__define_stab (N_RSYM, 0x40, "RSYM") - -/* Structure or union element. Value is offset in the structure. */ -__define_stab (N_SSYM, 0x60, "SSYM") - -/* Parameter variable. Value is offset from argument pointer. - (On most machines the argument pointer is the same as the frame pointer. */ -__define_stab (N_PSYM, 0xa0, "PSYM") - -/* Automatic variable in the stack. Value is offset from frame pointer. - Also used for type descriptions. */ -__define_stab (N_LSYM, 0x80, "LSYM") - -/* Alternate entry point. Value is its address. */ -__define_stab (N_ENTRY, 0xa4, "ENTRY") - -/* Name of main source file. - Value is starting text address of the compilation. */ -__define_stab (N_SO, 0x64, "SO") - -/* Name of sub-source file. - Value is starting text address of the compilation. */ -__define_stab (N_SOL, 0x84, "SOL") - -/* Line number in text segment. Desc is the line number; - value is corresponding address. */ -__define_stab (N_SLINE, 0x44, "SLINE") -/* Similar, for data segment. */ -__define_stab (N_DSLINE, 0x46, "DSLINE") -/* Similar, for bss segment. */ -__define_stab (N_BSLINE, 0x48, "BSLINE") - -/* Beginning of an include file. Only Sun uses this. - In an object file, only the name is significant. - The Sun linker puts data into some of the other fields. */ -__define_stab (N_BINCL, 0x82, "BINCL") -/* End of an include file. No name. - These two act as brackets around the file's output. - In an object file, there is no significant data in this entry. - The Sun linker puts data into some of the fields. */ -__define_stab (N_EINCL, 0xa2, "EINCL") -/* Place holder for deleted include file. - This appears only in output from the Sun linker. */ -__define_stab (N_EXCL, 0xc2, "EXCL") - -/* Beginning of lexical block. - The desc is the nesting level in lexical blocks. - The value is the address of the start of the text for the block. - The variables declared inside the block *precede* the N_LBRAC symbol. */ -__define_stab (N_LBRAC, 0xc0, "LBRAC") -/* End of a lexical block. Desc matches the N_LBRAC's desc. - The value is the address of the end of the text for the block. */ -__define_stab (N_RBRAC, 0xe0, "RBRAC") - -/* Begin named common block. Only the name is significant. */ -__define_stab (N_BCOMM, 0xe2, "BCOMM") -/* Begin named common block. Only the name is significant - (and it should match the N_BCOMM). */ -__define_stab (N_ECOMM, 0xe4, "ECOMM") -/* End common (local name): value is address. - I'm not sure how this is used. */ -__define_stab (N_ECOML, 0xe8, "ECOML") -/* Second symbol entry containing a length-value for the preceding entry. - The value is the length. */ -__define_stab (N_LENG, 0xfe, "LENG") - -/* Global symbol in Pascal. - Supposedly the value is its line number; I'm skeptical. */ -__define_stab (N_PC, 0x30, "PC") - -/* Modula-2 compilation unit. Can someone say what info it contains? */ -__define_stab (N_M2C, 0x42, "M2C") -/* Modula-2 scope information. Can someone say what info it contains? */ -__define_stab (N_SCOPE, 0xc4, "SCOPE") diff --git a/gnu/usr.bin/gdb/stack.c b/gnu/usr.bin/gdb/stack.c deleted file mode 100644 index 91218aa..0000000 --- a/gnu/usr.bin/gdb/stack.c +++ /dev/null @@ -1,960 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)stack.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Print and select stack frames for GDB, the GNU debugger. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* modified by rjc Thu Nov 1 16:46:57 1990, fixed return_command so that - it can return values, it still has problems when running on pmax, - cannot write register 65 */ - -#include - -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "frame.h" -#include "value.h" - - -/* Thie "selected" stack frame is used by default for local and arg access. - May be zero, for no selected frame. */ - -FRAME selected_frame; - -/* Level of the selected frame: - 0 for innermost, 1 for its caller, ... - or -1 for frame specified by address with no defined level. */ - -int selected_frame_level; - -/* Nonzero means print the full filename and linenumber - when a frame is printed, and do so in a format programs can parse. */ - -int frame_file_full_name = 0; - -static void select_calling_frame (); - -void print_frame_info (); - -/* Print a stack frame briefly. FRAME should be the frame id - and LEVEL should be its level in the stack (or -1 for level not defined). - This prints the level, the function executing, the arguments, - and the file name and line number. - If the pc is not at the beginning of the source line, - the actual pc is printed at the beginning. - - If SOURCE is 1, print the source line as well. - If SOURCE is -1, print ONLY the source line. */ - -static void -print_stack_frame (frame, level, source) - FRAME frame; - int level; - int source; -{ - struct frame_info *fi; - - fi = get_frame_info (frame); - - print_frame_info (fi, level, source, 1); -} - -/* Flag which will indicate when the frame has been changed - by and "up" or "down" command. */ -static int frame_changed; - -void -print_frame_info (fi, level, source, args) - struct frame_info *fi; - register int level; - int source; - int args; -{ - struct symtab_and_line sal; - struct symbol *func; - register char *funname = 0; - int numargs; - struct partial_symtab *pst; - - /* Don't give very much information if we haven't readin the - symbol table yet. */ - pst = find_pc_psymtab (fi->pc); - if (pst && !pst->readin) - { - /* Abbreviated information. */ - char *fname; - - if (!find_pc_partial_function (fi->pc, &fname, 0)) - fname = "??"; - - printf_filtered ("#%-2d ", level); - printf_filtered ("0x%x in ", fi->pc); - - fputs_demangled(fname, stdout, -1); - fputs_filtered(" (...)\n", stdout); - - return; - } - - sal = find_pc_line (fi->pc, fi->next_frame); - func = find_pc_function (fi->pc); - if (func) - { - /* In certain pathological cases, the symtabs give the wrong - function (when we are in the first function in a file which - is compiled without debugging symbols, the previous function - is compiled with debugging symbols, and the "foo.o" symbol - that is supposed to tell us where the file with debugging symbols - ends has been truncated by ar because it is longer than 15 - characters). - - So look in the misc_function_vector as well, and if it comes - up with a larger address for the function use that instead. - I don't think this can ever cause any problems; - there shouldn't be any - misc_function_vector symbols in the middle of a function. */ - int misc_index = find_pc_misc_function (fi->pc); - if (misc_index >= 0 - && (misc_function_vector[misc_index].address - > BLOCK_START (SYMBOL_BLOCK_VALUE (func)))) - { - /* In this case we have no way of knowing the source file - and line number, so don't print them. */ - sal.symtab = 0; - /* We also don't know anything about the function besides - its address and name. */ - func = 0; - funname = misc_function_vector[misc_index].name; - } - else - funname = SYMBOL_NAME (func); - } - else - { - register int misc_index = find_pc_misc_function (fi->pc); - if (misc_index >= 0) - funname = misc_function_vector[misc_index].name; - } - - if (frame_changed || source >= 0 || !sal.symtab) - { - if (level >= 0) - printf_filtered ("#%-2d ", level); - else if (frame_changed) - printf ("#%-2d ", 0); - if (fi->pc != sal.pc || !sal.symtab) - printf_filtered ("0x%x in ", fi->pc); - fputs_demangled(funname ? funname : "??", stdout, -1); - printf_filtered(" ("); - if (args) - { - if (func) - numargs = -1; - else - FRAME_NUM_ARGS (numargs, fi); - - print_frame_args (func, fi, numargs, stdout); - } - printf_filtered (")"); - if (sal.symtab) - printf_filtered (" (%s line %d)", sal.symtab->filename, sal.line); - printf_filtered ("\n"); - } - - if ((frame_changed || source != 0) && sal.symtab) - { - int done = 0; - int mid_statement = source < 0 && fi->pc != sal.pc; - if (frame_file_full_name) - done = identify_source_line (sal.symtab, sal.line, mid_statement); - if (!done) - { - if (mid_statement) - printf_filtered ("0x%x\t", fi->pc); - print_source_lines (sal.symtab, sal.line, sal.line + 1, 1); - } - current_source_line = max (sal.line - 5, 1); - } - frame_changed = 0; - if (source != 0) - set_default_breakpoint (1, fi->pc, sal.symtab, sal.line); - - fflush (stdout); -} - -/* Call here to print info on selected frame, after a trap. */ - -void -print_sel_frame (just_source) - int just_source; -{ - print_stack_frame (selected_frame, -1, just_source ? -1 : 1); -} - -/* Print info on the selected frame, including level number - but not source. */ - -void -print_selected_frame () -{ - print_stack_frame (selected_frame, selected_frame_level, 0); -} - -void flush_cached_frames (); - -#ifdef FRAME_SPECIFICATION_DYADIC -extern FRAME setup_arbitrary_frame (); -#endif - -/* - * Read a frame specification in whatever the appropriate format is. - */ -static FRAME -parse_frame_specification (frame_exp) - char *frame_exp; -{ - int numargs = 0; - int arg1, arg2; - - if (frame_exp) - { - char *addr_string, *p; - struct cleanup *tmp_cleanup; - struct frame_info *fci; - - while (*frame_exp == ' ') frame_exp++; - for (p = frame_exp; *p && *p != ' '; p++) - ; - - if (*frame_exp) - { - numargs = 1; - addr_string = savestring(frame_exp, p - frame_exp); - - { - tmp_cleanup = make_cleanup (free, addr_string); - arg1 = parse_and_eval_address (addr_string); - do_cleanups (tmp_cleanup); - } - - while (*p == ' ') p++; - - if (*p) - { - numargs = 2; - arg2 = parse_and_eval_address (p); - } - } - } - - switch (numargs) - { - case 0: - return selected_frame; - /* NOTREACHED */ - case 1: - { - int level = arg1; - FRAME fid = find_relative_frame (get_current_frame (), &level); - FRAME tfid; - - if (level == 0) - /* find_relative_frame was successful */ - return fid; - - /* If (s)he specifies the frame with an address, he deserves what - (s)he gets. Still, give the highest one that matches. */ - - for (fid = get_current_frame (); - fid && FRAME_FP (fid) != arg1; - fid = get_prev_frame (fid)) - ; - - if (fid) - while ((tfid = get_prev_frame (fid)) && - (FRAME_FP (tfid) == arg1)) - fid = tfid; - -#ifdef FRAME_SPECIFICATION_DYADIC - if (!fid) - error ("Incorrect number of args in frame specification"); - - return fid; -#else - return create_new_frame (arg1, 0); -#endif - } - /* NOTREACHED */ - case 2: - /* Must be addresses */ -#ifndef FRAME_SPECIFICATION_DYADIC - error ("Incorrect number of args in frame specification"); -#else - return setup_arbitrary_frame (arg1, arg2); -#endif - /* NOTREACHED */ - } - fatal ("Internal: Error in parsing in parse_frame_specification"); - /* NOTREACHED */ -} - -/* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except - that if it is unsure about the answer, it returns Frame_unknown - instead of guessing (this happens on the VAX, for example). - - On most machines, we never have to guess about the args address, - so FRAME_ARGS_ADDRESS{,_CORRECT} are the same. */ -#if !defined (FRAME_ARGS_ADDRESS_CORRECT) -#define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS -#endif - -/* Print verbosely the selected frame or the frame at address ADDR. - This means absolutely all information in the frame is printed. */ - -static void -frame_info (addr_exp) - char *addr_exp; -{ - FRAME frame; - struct frame_info *fi; - struct frame_saved_regs fsr; - struct symtab_and_line sal; - struct symbol *func; - FRAME calling_frame; - int i, count; - char *funname = 0; - - if (!(have_inferior_p () || have_core_file_p ())) - error ("No inferior or core file."); - - frame = parse_frame_specification (addr_exp); - if (!frame) - error ("Invalid frame specified."); - - fi = get_frame_info (frame); - get_frame_saved_regs (fi, &fsr); - sal = find_pc_line (fi->pc, fi->next_frame); - func = get_frame_function (frame); - if (func) - funname = SYMBOL_NAME (func); - else - { - register int misc_index = find_pc_misc_function (fi->pc); - if (misc_index >= 0) - funname = misc_function_vector[misc_index].name; - } - calling_frame = get_prev_frame (frame); - - if (!addr_exp && selected_frame_level >= 0) - printf ("Stack level %d, frame at 0x%x:\n pc = 0x%x", - selected_frame_level, FRAME_FP(frame), fi->pc); - else - printf ("Stack frame at 0x%x:\n pc = 0x%x", - FRAME_FP(frame), fi->pc); - - if (funname) - printf (" in %s", funname); - if (sal.symtab) - printf (" (%s line %d)", sal.symtab->filename, sal.line); - printf ("; saved pc 0x%x\n", FRAME_SAVED_PC (frame)); - if (calling_frame) - printf (" called by frame at 0x%x", FRAME_FP (calling_frame)); - if (fi->next_frame && calling_frame) - printf (","); - if (fi->next_frame) - printf (" caller of frame at 0x%x", fi->next_frame); - if (fi->next_frame || calling_frame) - printf ("\n"); - - { - /* Address of the argument list for this frame, or Frame_unknown. */ - CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi); - /* Number of args for this frame, or -1 if unknown. */ - int numargs; - - if (arg_list != Frame_unknown) - { - printf (" Arglist at 0x%x,", arg_list); - - FRAME_NUM_ARGS (numargs, fi); - if (numargs < 0) - printf (" args: "); - else if (numargs == 0) - printf (" no args."); - else if (numargs == 1) - printf (" 1 arg: "); - else - printf (" %d args: ", numargs); - print_frame_args (func, fi, numargs, stdout); - printf ("\n"); - } - } - - /* The sp is special; what's returned isn't the save address, but - actually the value of the previous frame's sp. */ - printf (" Previous frame's sp is 0x%x\n", fsr.regs[SP_REGNUM]); - count = 0; - for (i = 0; i < NUM_REGS; i++) - if (fsr.regs[i] && i != SP_REGNUM) - { - if (count % 4 != 0) - printf (", "); - else - { - if (count == 0) - printf (" Saved registers:"); - printf ("\n "); - } - printf ("%s at 0x%x", reg_names[i], fsr.regs[i]); - count++; - } - if (count) - printf ("\n"); -} - -#if 0 -/* Set a limit on the number of frames printed by default in a - backtrace. */ - -static int backtrace_limit; - -static void -set_backtrace_limit_command (count_exp, from_tty) - char *count_exp; - int from_tty; -{ - int count = parse_and_eval_address (count_exp); - - if (count < 0) - error ("Negative argument not meaningful as backtrace limit."); - - backtrace_limit = count; -} - -static void -backtrace_limit_info (arg, from_tty) - char *arg; - int from_tty; -{ - if (arg) - error ("\"Info backtrace-limit\" takes no arguments."); - - printf ("Backtrace limit: %d.\n", backtrace_limit); -} -#endif - -/* Print briefly all stack frames or just the innermost COUNT frames. */ - -static void -backtrace_command (count_exp) - char *count_exp; -{ - struct frame_info *fi; - register int count; - register FRAME frame; - register int i; - register FRAME trailing; - register int trailing_level; - - /* The following code must do two things. First, it must - set the variable TRAILING to the frame from which we should start - printing. Second, it must set the variable count to the number - of frames which we should print, or -1 if all of them. */ - trailing = get_current_frame (); - trailing_level = 0; - if (count_exp) - { - count = parse_and_eval_address (count_exp); - if (count < 0) - { - FRAME current; - - count = -count; - - current = trailing; - while (current && count--) - current = get_prev_frame (current); - - /* Will stop when CURRENT reaches the top of the stack. TRAILING - will be COUNT below it. */ - while (current) - { - trailing = get_prev_frame (trailing); - current = get_prev_frame (current); - trailing_level++; - } - - count = -1; - } - } - else - count = -1; - - for (i = 0, frame = trailing; - frame && count--; - i++, frame = get_prev_frame (frame)) - { - QUIT; - fi = get_frame_info (frame); - print_frame_info (fi, trailing_level + i, 0, 1); - } - - /* If we've stopped before the end, mention that. */ - if (frame) - printf_filtered ("(More stack frames follow...)\n"); -} - -/* Print the local variables of a block B active in FRAME. - Return 1 if any variables were printed; 0 otherwise. */ - -static int -print_block_frame_locals (b, frame, stream) - struct block *b; - register FRAME frame; - register FILE *stream; -{ - int nsyms; - register int i; - register struct symbol *sym; - register int values_printed = 0; - - nsyms = BLOCK_NSYMS (b); - - for (i = 0; i < nsyms; i++) - { - sym = BLOCK_SYM (b, i); - if (SYMBOL_CLASS (sym) == LOC_LOCAL - || SYMBOL_CLASS (sym) == LOC_REGISTER - || SYMBOL_CLASS (sym) == LOC_STATIC) - { - values_printed = 1; - fputs_filtered (SYMBOL_NAME (sym), stream); - fputs_filtered (" = ", stream); - print_variable_value (sym, frame, stream); - fprintf_filtered (stream, "\n"); - fflush (stream); - } - } - return values_printed; -} - -/* Print on STREAM all the local variables in frame FRAME, - including all the blocks active in that frame - at its current pc. - - Returns 1 if the job was done, - or 0 if nothing was printed because we have no info - on the function running in FRAME. */ - -static int -print_frame_local_vars (frame, stream) - register FRAME frame; - register FILE *stream; -{ - register struct block *block = get_frame_block (frame); - register int values_printed = 0; - - if (block == 0) - { - fprintf_filtered (stream, "No symbol table info available.\n"); - fflush (stream); - return 0; - } - - while (block != 0) - { - if (print_block_frame_locals (block, frame, stream)) - values_printed = 1; - /* After handling the function's top-level block, stop. - Don't continue to its superblock, the block of - per-file symbols. */ - if (BLOCK_FUNCTION (block)) - break; - block = BLOCK_SUPERBLOCK (block); - } - - if (!values_printed) - { - fprintf_filtered (stream, "No locals.\n"); - fflush (stream); - } - - return 1; -} - -static void -locals_info () -{ - if (!have_inferior_p () && !have_core_file_p ()) - error ("No inferior or core file."); - - print_frame_local_vars (selected_frame, stdout); -} - -static int -print_frame_arg_vars (frame, stream) - register FRAME frame; - register FILE *stream; -{ - struct symbol *func = get_frame_function (frame); - register struct block *b; - int nsyms; - register int i; - register struct symbol *sym; - register int values_printed = 0; - - if (func == 0) - { - fprintf_filtered (stream, "No symbol table info available.\n"); - fflush (stream); - return 0; - } - - b = SYMBOL_BLOCK_VALUE (func); - nsyms = BLOCK_NSYMS (b); - - for (i = 0; i < nsyms; i++) - { - sym = BLOCK_SYM (b, i); - if (SYMBOL_CLASS (sym) == LOC_ARG - || SYMBOL_CLASS (sym) == LOC_REF_ARG - || SYMBOL_CLASS (sym) == LOC_REGPARM) - { - values_printed = 1; - fputs_filtered (SYMBOL_NAME (sym), stream); - fputs_filtered (" = ", stream); - print_variable_value (sym, frame, stream); - fprintf_filtered (stream, "\n"); - fflush (stream); - } - } - - if (!values_printed) - { - fprintf_filtered (stream, "No arguments.\n"); - fflush (stream); - } - - return 1; -} - -static void -args_info () -{ - if (!have_inferior_p () && !have_core_file_p ()) - error ("No inferior or core file."); - print_frame_arg_vars (selected_frame, stdout); -} - -/* Select frame FRAME, and note that its stack level is LEVEL. - LEVEL may be -1 if an actual level number is not known. */ - -void -select_frame (frame, level) - FRAME frame; - int level; -{ - selected_frame = frame; - selected_frame_level = level; - /* Ensure that symbols for this frame are readin. */ - if (frame) - find_pc_symtab (get_frame_info (frame)->pc); -} - -/* Store the selected frame and its level into *FRAMEP and *LEVELP. */ - -void -record_selected_frame (frameaddrp, levelp) - FRAME_ADDR *frameaddrp; - int *levelp; -{ - *frameaddrp = FRAME_FP (selected_frame); - *levelp = selected_frame_level; -} - -/* Return the symbol-block in which the selected frame is executing. - Can return zero under various legitimate circumstances. */ - -struct block * -get_selected_block () -{ - if (!have_inferior_p () && !have_core_file_p ()) - return 0; - - if (!selected_frame) - return get_current_block (); - return get_frame_block (selected_frame); -} - -/* Find a frame a certain number of levels away from FRAME. - LEVEL_OFFSET_PTR points to an int containing the number of levels. - Positive means go to earlier frames (up); negative, the reverse. - The int that contains the number of levels is counted toward - zero as the frames for those levels are found. - If the top or bottom frame is reached, that frame is returned, - but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates - how much farther the original request asked to go. */ - -FRAME -find_relative_frame (frame, level_offset_ptr) - register FRAME frame; - register int* level_offset_ptr; -{ - register FRAME prev; - register FRAME frame1, frame2; - - /* Going up is simple: just do get_prev_frame enough times - or until initial frame is reached. */ - while (*level_offset_ptr > 0) - { - prev = get_prev_frame (frame); - if (prev == 0) - break; - (*level_offset_ptr)--; - frame = prev; - } - /* Going down could be done by iterating get_frame_info to - find the next frame, but that would be quadratic - since get_frame_info must scan all the way from the current frame. - The following algorithm is linear. */ - if (*level_offset_ptr < 0) - { - /* First put frame1 at innermost frame - and frame2 N levels up from there. */ - frame1 = get_current_frame (); - frame2 = frame1; - while (*level_offset_ptr < 0 && frame2 != frame) - { - frame2 = get_prev_frame (frame2); - (*level_offset_ptr) ++; - } - /* Then slide frame1 and frame2 up in synchrony - and when frame2 reaches our starting point - frame1 must be N levels down from there. */ - while (frame2 != frame) - { - frame1 = get_prev_frame (frame1); - frame2 = get_prev_frame (frame2); - } - return frame1; - } - return frame; -} - -/* The "frame" command. With no arg, print selected frame briefly. - With arg LEVEL_EXP, select the frame at level LEVEL if it is a - valid level. Otherwise, treat level_exp as an address expression - and print it. See parse_frame_specification for more info on proper - frame expressions. */ - -static void -frame_command (level_exp, from_tty) - char *level_exp; - int from_tty; -{ - register FRAME frame, frame1; - unsigned int level = 0; - - if (!have_inferior_p () && ! have_core_file_p ()) - error ("No inferior or core file."); - - frame = parse_frame_specification (level_exp); - - for (frame1 = get_prev_frame (0); - frame1 && frame1 != frame; - frame1 = get_prev_frame (frame1)) - level++; - - if (!frame1) - level = 0; - - frame_changed = level; - select_frame (frame, level); - - if (!from_tty) - return; - - print_stack_frame (selected_frame, selected_frame_level, 1); -} - -/* Select the frame up one or COUNT stack levels - from the previously selected frame, and print it briefly. */ - -static void -up_command (count_exp) - char *count_exp; -{ - register FRAME frame; - int count = 1, count1; - if (count_exp) - count = parse_and_eval_address (count_exp); - count1 = count; - - if (!have_inferior_p () && !have_core_file_p ()) - error ("No inferior or core file."); - - frame = find_relative_frame (selected_frame, &count1); - if (count1 != 0 && count_exp == 0) - error ("Initial frame selected; you cannot go up."); - select_frame (frame, selected_frame_level + count - count1); - - print_stack_frame (selected_frame, selected_frame_level, 1); - frame_changed++; -} - -/* Select the frame down one or COUNT stack levels - from the previously selected frame, and print it briefly. */ - -static void -down_command (count_exp) - char *count_exp; -{ - register FRAME frame; - int count = -1, count1; - if (count_exp) - count = - parse_and_eval_address (count_exp); - count1 = count; - - frame = find_relative_frame (selected_frame, &count1); - if (count1 != 0 && count_exp == 0) - error ("Bottom (i.e., innermost) frame selected; you cannot go down."); - select_frame (frame, selected_frame_level + count - count1); - - print_stack_frame (selected_frame, selected_frame_level, 1); - frame_changed--; -} - -static void -return_command (retval_exp, from_tty) - char *retval_exp; - int from_tty; -{ - value return_value; - struct symbol *thisfun = get_frame_function (selected_frame); - FRAME_ADDR selected_frame_addr = FRAME_FP (selected_frame); - - /* If interactive, require confirmation. */ - - if (from_tty) - { - if (thisfun != 0) - { - if (!query ("Make %s return now? ", SYMBOL_NAME (thisfun))) - error ("Not confirmed."); - } - else - if (!query ("Make selected stack frame return now? ")) - error ("Not confirmed."); - } - - /* Do the real work. Pop until the specified frame is current. We - use this method because the selected_frame is not valid after - a POP_FRAME. Note that this will not work if the selected frame - shares it's fp with another frame. */ - - while (selected_frame_addr != FRAME_FP (get_current_frame())) - POP_FRAME; - - /* get the return value while still in this frame */ - if (retval_exp) - return_value = parse_and_eval (retval_exp); - - /* Then pop that frame. */ - POP_FRAME; - - /* Store the return value if there was one */ - - if (retval_exp) - set_return_value (return_value); - - /* If interactive, print the frame that is now current. */ - - if (from_tty) - frame_command ("0", 1); -} - -extern struct cmd_list_element *setlist; - -void -_initialize_stack () -{ -#if 0 - backtrace_limit = 30; -#endif - - add_com ("return", class_stack, return_command, - "Make selected stack frame return to its caller.\n\ -Control remains in the debugger, but when you continue\n\ -execution will resume in the frame above the one now selected.\n\ -If an argument is given, it is an expression for the value to return."); - - add_com ("up", class_stack, up_command, - "Select and print stack frame that called this one.\n\ -An argument says how many frames up to go."); - - add_com ("down", class_stack, down_command, - "Select and print stack frame called by this one.\n\ -An argument says how many frames down to go."); - add_com_alias ("do", "down", class_stack, 1); - - add_com ("frame", class_stack, frame_command, - "Select and print a stack frame.\n\ -With no argument, print the selected stack frame. (See also \"info frame\").\n\ -An argument specifies the frame to select.\n\ -It can be a stack frame number or the address of the frame.\n\ -With argument, nothing is printed if input is coming from\n\ -a command file or a user-defined command."); - - add_com_alias ("f", "frame", class_stack, 1); - - add_com ("backtrace", class_stack, backtrace_command, - "Print backtrace of all stack frames, or innermost COUNT frames.\n\ -With a negative argument, print outermost -COUNT frames."); - add_com_alias ("bt", "backtrace", class_stack, 0); - add_com_alias ("where", "backtrace", class_alias, 0); - add_info ("stack", backtrace_command, - "Backtrace of the stack, or innermost COUNT frames."); - add_info_alias ("s", "stack", 1); - add_info ("frame", frame_info, - "All about selected stack frame, or frame at ADDR."); - add_info_alias ("f", "frame", 1); - add_info ("locals", locals_info, - "Local variables of current stack frame."); - add_info ("args", args_info, - "Argument variables of current stack frame."); - -#if 0 - add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command, - "Specify maximum number of frames for \"backtrace\" to print by default.", - &setlist); - add_info ("backtrace-limit", backtrace_limit_info, - "The maximum number of frames for \"backtrace\" to print by default."); -#endif -} - diff --git a/gnu/usr.bin/gdb/symmisc.c b/gnu/usr.bin/gdb/symmisc.c deleted file mode 100644 index bb4eb50..0000000 --- a/gnu/usr.bin/gdb/symmisc.c +++ /dev/null @@ -1,584 +0,0 @@ -/* Do various things to symbol tables (other than lookup)), for GDB. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - - -#include "defs.h" -#include "symtab.h" - -#include -#include - -static void free_symtab (); - - -/* Free all the symtabs that are currently installed, - and all storage associated with them. - Leaves us in a consistent state with no symtabs installed. */ - -void -free_all_symtabs () -{ - register struct symtab *s, *snext; - - /* All values will be invalid because their types will be! */ - - clear_value_history (); - clear_displays (); - clear_internalvars (); - clear_breakpoints (); - set_default_breakpoint (0, 0, 0, 0); - - current_source_symtab = 0; - - for (s = symtab_list; s; s = snext) - { - snext = s->next; - free_symtab (s); - } - symtab_list = 0; - obstack_free (symbol_obstack, 0); - obstack_init (symbol_obstack); - - if (misc_function_vector) - free (misc_function_vector); - misc_function_count = 0; - misc_function_vector = 0; -} - -/* Free a struct block <- B and all the symbols defined in that block. */ - -static void -free_symtab_block (b) - struct block *b; -{ - register int i, n; - n = BLOCK_NSYMS (b); - for (i = 0; i < n; i++) - { - free (SYMBOL_NAME (BLOCK_SYM (b, i))); - free (BLOCK_SYM (b, i)); - } - free (b); -} - -/* Free all the storage associated with the struct symtab <- S. - Note that some symtabs have contents malloc'ed structure by structure, - while some have contents that all live inside one big block of memory, - and some share the contents of another symbol table and so you should - not free the contents on their behalf (except sometimes the linetable, - which maybe per symtab even when the rest is not). - It is s->free_code that says which alternative to use. */ - -static void -free_symtab (s) - register struct symtab *s; -{ - register int i, n; - register struct blockvector *bv; - register struct type *type; - register struct typevector *tv; - - switch (s->free_code) - { - case free_nothing: - /* All the contents are part of a big block of memory - and some other symtab is in charge of freeing that block. - Therefore, do nothing. */ - break; - - case free_contents: - /* Here all the contents were malloc'ed structure by structure - and must be freed that way. */ - /* First free the blocks (and their symbols. */ - bv = BLOCKVECTOR (s); - n = BLOCKVECTOR_NBLOCKS (bv); - for (i = 0; i < n; i++) - free_symtab_block (BLOCKVECTOR_BLOCK (bv, i)); - /* Free the blockvector itself. */ - free (bv); - /* Free the type vector. */ - tv = TYPEVECTOR (s); - free (tv); - /* Also free the linetable. */ - - case free_linetable: - /* Everything will be freed either by our `free_ptr' - or by some other symbatb, except for our linetable. - Free that now. */ - free (LINETABLE (s)); - break; - } - - /* If there is a single block of memory to free, free it. */ - if (s->free_ptr) - free (s->free_ptr); - - if (s->line_charpos) - free (s->line_charpos); - free (s->filename); - free (s); -} - -/* Convert a raw symbol-segment to a struct symtab, - and relocate its internal pointers so that it is valid. */ - -/* This is how to relocate one pointer, given a name for it. - Works independent of the type of object pointed to. */ -#define RELOCATE(slot) (slot ? (* (char **) &slot += relocation) : 0) - -/* This is the inverse of RELOCATE. We use it when storing - a core address into a slot that has yet to be relocated. */ -#define UNRELOCATE(slot) (slot ? (* (char **) &slot -= relocation) : 0) - -/* During the process of relocation, this holds the amount to relocate by - (the address of the file's symtab data, in core in the debugger). */ -static int relocation; - -#define CORE_RELOCATE(slot) \ - ((slot) += (((slot) < data_start) ? text_relocation \ - : ((slot) < bss_start) ? data_relocation : bss_relocation)) - -#define TEXT_RELOCATE(slot) ((slot) += text_relocation) - -/* Relocation amounts for addresses in the program's core image. */ -static int text_relocation, data_relocation, bss_relocation; - -/* Boundaries that divide program core addresses into text, data and bss; - used to determine which relocation amount to use. */ -static int data_start, bss_start; - -static void relocate_typevector (); -static void relocate_blockvector (); -static void relocate_type (); -static void relocate_block (); -static void relocate_symbol (); -static void relocate_source (); - -/* Relocate a file's symseg so that all the pointers are valid C pointers. - Value is a `struct symtab'; but it is not suitable for direct - insertion into the `symtab_list' because it describes several files. */ - -static struct symtab * -relocate_symtab (root) - struct symbol_root *root; -{ - struct symtab *sp = (struct symtab *) xmalloc (sizeof (struct symtab)); - bzero (sp, sizeof (struct symtab)); - - relocation = (int) root; - text_relocation = root->textrel; - data_relocation = root->datarel; - bss_relocation = root->bssrel; - data_start = root->databeg; - bss_start = root->bssbeg; - - sp->filename = root->filename; - sp->ldsymoff = root->ldsymoff; - sp->language = root->language; - sp->compilation = root->compilation; - sp->version = root->version; - sp->blockvector = root->blockvector; - sp->typevector = root->typevector; - - RELOCATE (TYPEVECTOR (sp)); - RELOCATE (BLOCKVECTOR (sp)); - RELOCATE (sp->version); - RELOCATE (sp->compilation); - RELOCATE (sp->filename); - - relocate_typevector (TYPEVECTOR (sp)); - relocate_blockvector (BLOCKVECTOR (sp)); - - return sp; -} - -static void -relocate_blockvector (blp) - register struct blockvector *blp; -{ - register int nblocks = BLOCKVECTOR_NBLOCKS (blp); - register int i; - for (i = 0; i < nblocks; i++) - RELOCATE (BLOCKVECTOR_BLOCK (blp, i)); - for (i = 0; i < nblocks; i++) - relocate_block (BLOCKVECTOR_BLOCK (blp, i)); -} - -static void -relocate_block (bp) - register struct block *bp; -{ - register int nsyms = BLOCK_NSYMS (bp); - register int i; - - TEXT_RELOCATE (BLOCK_START (bp)); - TEXT_RELOCATE (BLOCK_END (bp)); - - /* These two should not be recursively processed. - The superblock need not be because all blocks are - processed from relocate_blockvector. - The function need not be because it will be processed - under the block which is its scope. */ - RELOCATE (BLOCK_SUPERBLOCK (bp)); - RELOCATE (BLOCK_FUNCTION (bp)); - - for (i = 0; i < nsyms; i++) - RELOCATE (BLOCK_SYM (bp, i)); - - for (i = 0; i < nsyms; i++) - relocate_symbol (BLOCK_SYM (bp, i)); -} - -static void -relocate_symbol (sp) - register struct symbol *sp; -{ - RELOCATE (SYMBOL_NAME (sp)); - if (SYMBOL_CLASS (sp) == LOC_BLOCK) - { - RELOCATE (SYMBOL_BLOCK_VALUE (sp)); - /* We can assume the block that belongs to this symbol - is not relocated yet, since it comes after - the block that contains this symbol. */ - BLOCK_FUNCTION (SYMBOL_BLOCK_VALUE (sp)) = sp; - UNRELOCATE (BLOCK_FUNCTION (SYMBOL_BLOCK_VALUE (sp))); - } - else if (SYMBOL_CLASS (sp) == LOC_STATIC) - CORE_RELOCATE (SYMBOL_VALUE (sp)); - else if (SYMBOL_CLASS (sp) == LOC_LABEL) - TEXT_RELOCATE (SYMBOL_VALUE (sp)); - RELOCATE (SYMBOL_TYPE (sp)); -} - -static void -relocate_typevector (tv) - struct typevector *tv; -{ - register int ntypes = TYPEVECTOR_NTYPES (tv); - register int i; - - for (i = 0; i < ntypes; i++) - RELOCATE (TYPEVECTOR_TYPE (tv, i)); - for (i = 0; i < ntypes; i++) - relocate_type (TYPEVECTOR_TYPE (tv, i)); -} - -/* We cannot come up with an a priori spanning tree - for the network of types, since types can be used - for many symbols and also as components of other types. - Therefore, we need to be able to mark types that we - already have relocated (or are already in the middle of relocating) - as in a garbage collector. */ - -static void -relocate_type (tp) - register struct type *tp; -{ - register int nfields = TYPE_NFIELDS (tp); - register int i; - - RELOCATE (TYPE_NAME (tp)); - RELOCATE (TYPE_TARGET_TYPE (tp)); - RELOCATE (TYPE_FIELDS (tp)); - RELOCATE (TYPE_POINTER_TYPE (tp)); - - for (i = 0; i < nfields; i++) - { - RELOCATE (TYPE_FIELD_TYPE (tp, i)); - RELOCATE (TYPE_FIELD_NAME (tp, i)); - } -} - -static void -relocate_sourcevector (svp) - register struct sourcevector *svp; -{ - register int nfiles = svp->length; - register int i; - for (i = 0; i < nfiles; i++) - RELOCATE (svp->source[i]); - for (i = 0; i < nfiles; i++) - relocate_source (svp->source[i]); -} - -static void -relocate_source (sp) - register struct source *sp; -{ - register int nitems = sp->contents.nitems; - register int i; - - RELOCATE (sp->name); - for (i = 0; i < nitems; i++) - TEXT_RELOCATE (sp->contents.item[i].pc); -} - -/* Read symsegs from file named NAME open on DESC, - make symtabs from them, and return a chain of them. - These symtabs are not suitable for direct use in `symtab_list' - because each one describes a single object file, perhaps many source files. - `symbol_file_command' takes each of these, makes many real symtabs - from it, and then frees it. - - We assume DESC is prepositioned at the end of the string table, - just before the symsegs if there are any. */ - -struct symtab * -read_symsegs (desc, name) - int desc; - char *name; -{ - struct symbol_root root; - register char *data; - register struct symtab *sp, *sp1, *chain = 0; - register int len; - - while (1) - { - len = myread (desc, &root, sizeof root); - if (len == 0 || root.format == 0) - break; - /* format 1 was ok for the original gdb, but since the size of the - type structure changed when C++ support was added, it can no - longer be used. Accept only format 2. */ - if (root.format != 2 || - root.length < sizeof root) - error ("\nInvalid symbol segment format code"); - data = (char *) xmalloc (root.length); - bcopy (&root, data, sizeof root); - len = myread (desc, data + sizeof root, - root.length - sizeof root); - sp = relocate_symtab (data); - RELOCATE (((struct symbol_root *)data)->sourcevector); - relocate_sourcevector (((struct symbol_root *)data)->sourcevector); - sp->next = chain; - chain = sp; - sp->linetable = (struct linetable *) ((struct symbol_root *)data)->sourcevector; - } - - return chain; -} - -static int block_depth (); -void print_spaces (); -static void print_symbol (); - -void -print_symtabs (filename) - char *filename; -{ - FILE *outfile; - register struct symtab *s; - register int i, j; - int len, line, blen; - register struct linetable *l; - struct blockvector *bv; - register struct block *b; - int depth; - struct cleanup *cleanups; - extern int fclose(); - - if (filename == 0) - error_no_arg ("file to write symbol data in"); - - filename = tilde_expand (filename); - make_cleanup (free, filename); - - outfile = fopen (filename, "w"); - if (outfile == 0) - perror_with_name (filename); - - cleanups = make_cleanup (fclose, outfile); - immediate_quit++; - - for (s = symtab_list; s; s = s->next) - { - /* First print the line table. */ - fprintf (outfile, "Symtab for file %s\n\n", s->filename); - fprintf (outfile, "Line table:\n\n"); - l = LINETABLE (s); - len = l->nitems; - for (i = 0; i < len; i++) - fprintf (outfile, " line %d at %x\n", l->item[i].line, - l->item[i].pc); - /* Now print the block info. */ - fprintf (outfile, "\nBlockvector:\n\n"); - bv = BLOCKVECTOR (s); - len = BLOCKVECTOR_NBLOCKS (bv); - for (i = 0; i < len; i++) - { - b = BLOCKVECTOR_BLOCK (bv, i); - depth = block_depth (b) * 2; - print_spaces (depth, outfile); - fprintf (outfile, "block #%03d (object 0x%x) ", i, b); - fprintf (outfile, "[0x%x..0x%x]", BLOCK_START (b), BLOCK_END (b)); - if (BLOCK_SUPERBLOCK (b)) - fprintf (outfile, " (under 0x%x)", BLOCK_SUPERBLOCK (b)); - if (BLOCK_FUNCTION (b)) - fprintf (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b))); - fputc ('\n', outfile); - blen = BLOCK_NSYMS (b); - for (j = 0; j < blen; j++) - { - print_symbol (BLOCK_SYM (b, j), depth + 1, outfile); - } - } - - fprintf (outfile, "\n\n"); - } - - immediate_quit--; - do_cleanups (cleanups); -} - -static void -print_symbol (symbol, depth, outfile) - struct symbol *symbol; - int depth; - FILE *outfile; -{ - print_spaces (depth, outfile); - if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE) - { - fprintf (outfile, "label %s at 0x%x\n", SYMBOL_NAME (symbol), - SYMBOL_VALUE (symbol)); - return; - } - if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE) - { - if (TYPE_NAME (SYMBOL_TYPE (symbol))) - { - type_print_1 (SYMBOL_TYPE (symbol), "", outfile, 1, depth); - } - else - { - fprintf (outfile, "%s %s = ", - (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM - ? "enum" - : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT - ? "struct" : "union")), - SYMBOL_NAME (symbol)); - type_print_1 (SYMBOL_TYPE (symbol), "", outfile, 1, depth); - } - fprintf (outfile, ";\n"); - } - else - { - if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF) - fprintf (outfile, "typedef "); - if (SYMBOL_TYPE (symbol)) - { - type_print_1 (SYMBOL_TYPE (symbol), SYMBOL_NAME (symbol), - outfile, 1, depth); - fprintf (outfile, "; "); - } - else - fprintf (outfile, "%s ", SYMBOL_NAME (symbol)); - - switch (SYMBOL_CLASS (symbol)) - { - case LOC_CONST: - fprintf (outfile, "const %d (0x%x),", - SYMBOL_VALUE (symbol), SYMBOL_VALUE (symbol)); - break; - - case LOC_CONST_BYTES: - fprintf (outfile, "const %d hex bytes:", - TYPE_LENGTH (SYMBOL_TYPE (symbol))); - { - int i; - for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (symbol)); i++) - fprintf (outfile, " %2x", SYMBOL_VALUE_BYTES (symbol) [i]); - fprintf (outfile, ","); - } - break; - - case LOC_STATIC: - fprintf (outfile, "static at 0x%x,", SYMBOL_VALUE (symbol)); - break; - - case LOC_REGISTER: - fprintf (outfile, "register %d,", SYMBOL_VALUE (symbol)); - break; - - case LOC_ARG: - fprintf (outfile, "arg at 0x%x,", SYMBOL_VALUE (symbol)); - break; - - case LOC_REF_ARG: - fprintf (outfile, "reference arg at 0x%x,", SYMBOL_VALUE (symbol)); - break; - - case LOC_REGPARM: - fprintf (outfile, "parameter register %d,", SYMBOL_VALUE (symbol)); - break; - - case LOC_LOCAL: - fprintf (outfile, "local at 0x%x,", SYMBOL_VALUE (symbol)); - break; - - case LOC_TYPEDEF: - break; - - case LOC_LABEL: - fprintf (outfile, "label at 0x%x", SYMBOL_VALUE (symbol)); - break; - - case LOC_BLOCK: - fprintf (outfile, "block (object 0x%x) starting at 0x%x,", - SYMBOL_VALUE (symbol), - BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))); - break; - } - } - fprintf (outfile, "\n"); -} - -/* Return the nexting depth of a block within other blocks in its symtab. */ - -static int -block_depth (block) - struct block *block; -{ - register int i = 0; - while (block = BLOCK_SUPERBLOCK (block)) i++; - return i; -} - -/* - * Free all partial_symtab storage. - */ -void -free_all_psymtabs() -{ - obstack_free (psymbol_obstack, 0); - obstack_init (psymbol_obstack); - partial_symtab_list = (struct partial_symtab *) 0; -} - -void -_initialize_symmisc () -{ - symtab_list = (struct symtab *) 0; - partial_symtab_list = (struct partial_symtab *) 0; - - add_com ("printsyms", class_obscure, print_symtabs, - "Print dump of current symbol definitions to file OUTFILE."); -} - diff --git a/gnu/usr.bin/gdb/symseg.h b/gnu/usr.bin/gdb/symseg.h deleted file mode 100644 index 6a61a17..0000000 --- a/gnu/usr.bin/gdb/symseg.h +++ /dev/null @@ -1,523 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - * - * @(#)symseg.h 6.3 (Berkeley) 5/8/91 - */ - -/* GDB symbol table format definitions. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - Hacked by Michael Tiemann (tiemann@mcc.com) - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Format of GDB symbol table data. - There is one symbol segment for each source file or - independant compilation. These segments are simply concatenated - to form the GDB symbol table. A zero word where the beginning - of a segment is expected indicates there are no more segments. - -Format of a symbol segment: - - The symbol segment begins with a word containing 1 - if it is in the format described here. Other formats may - be designed, with other code numbers. - - The segment contains many objects which point at each other. - The pointers are offsets in bytes from the beginning of the segment. - Thus, each segment can be loaded into core and its pointers relocated - to make valid in-core pointers. - - All the data objects in the segment can be found indirectly from - one of them, the root object, of type `struct symbol_root'. - It appears at the beginning of the segment. - - The total size of the segment, in bytes, appears as the `length' - field of this object. This size includes the size of the - root object. - - All the object data types are defined here to contain pointer types - appropriate for in-core use on a relocated symbol segment. - Casts to and from type int are required for working with - unrelocated symbol segments such as are found in the file. - - The ldsymaddr word is filled in by the loader to contain - the offset (in bytes) within the ld symbol table - of the first nonglobal symbol from this compilation. - This makes it possible to match those symbols - (which contain line number information) reliably with - the segment they go with. - - Core addresses within the program that appear in the symbol segment - are not relocated by the loader. They are inserted by the assembler - and apply to addresses as output by the assembler, so GDB must - relocate them when it loads the symbol segment. It gets the information - on how to relocate from the textrel, datarel, bssrel, databeg and bssbeg - words of the root object. - - The words textrel, datarel and bssrel - are filled in by ld with the amounts to relocate within-the-file - text, data and bss addresses by; databeg and bssbeg can be - used to tell which kind of relocation an address needs. */ - -enum language {language_c}; - -struct symbol_root -{ - int format; /* Data format version */ - int length; /* # bytes in this symbol segment */ - int ldsymoff; /* Offset in ld symtab of this file's syms */ - int textrel; /* Relocation for text addresses */ - int datarel; /* Relocation for data addresses */ - int bssrel; /* Relocation for bss addresses */ - char *filename; /* Name of main source file compiled */ - char *filedir; /* Name of directory it was reached from */ - struct blockvector *blockvector; /* Vector of all symbol-naming blocks */ - struct typevector *typevector; /* Vector of all data types */ - enum language language; /* Code identifying the language used */ - char *version; /* Version info. Not fully specified */ - char *compilation; /* Compilation info. Not fully specified */ - int databeg; /* Address within the file of data start */ - int bssbeg; /* Address within the file of bss start */ - struct sourcevector *sourcevector; /* Vector of line-number info */ -}; - -/* All data types of symbols in the compiled program - are represented by `struct type' objects. - All of these objects are pointed to by the typevector. - The type vector may have empty slots that contain zero. */ - -struct typevector -{ - int length; /* Number of types described */ - struct type *type[1]; -}; - -/* Different kinds of data types are distinguished by the `code' field. */ - -enum type_code -{ - TYPE_CODE_UNDEF, /* Not used; catches errors */ - TYPE_CODE_PTR, /* Pointer type */ - TYPE_CODE_ARRAY, /* Array type, lower bound zero */ - TYPE_CODE_STRUCT, /* C struct or Pascal record */ - TYPE_CODE_UNION, /* C union or Pascal variant part */ - TYPE_CODE_ENUM, /* Enumeration type */ - TYPE_CODE_FUNC, /* Function type */ - TYPE_CODE_INT, /* Integer type */ - TYPE_CODE_FLT, /* Floating type */ - TYPE_CODE_VOID, /* Void type (values zero length) */ - TYPE_CODE_SET, /* Pascal sets */ - TYPE_CODE_RANGE, /* Range (integers within spec'd bounds) */ - TYPE_CODE_PASCAL_ARRAY, /* Array with explicit type of index */ - - /* C++ */ - TYPE_CODE_MEMBER, /* Member type */ - TYPE_CODE_METHOD, /* Method type */ - TYPE_CODE_REF, /* C++ Reference types */ -}; - -/* This appears in a type's flags word for an unsigned integer type. */ -#define TYPE_FLAG_UNSIGNED 1 -/* This appears in a type's flags word - if it is a (pointer to a|function returning a)* built in scalar type. - These types are never freed. */ -#define TYPE_FLAG_PERM 4 -/* This appears in a type's flags word if it is a stub type (eg. if - someone referenced a type that wasn't definined in a source file - via (struct sir_not_appearing_in_this_film *)). */ -#define TYPE_FLAG_STUB 8 -/* Set when a class has a constructor defined */ -#define TYPE_FLAG_HAS_CONSTRUCTOR 256 -/* Set when a class has a destructor defined */ -#define TYPE_FLAG_HAS_DESTRUCTOR 512 -/* Indicates that this type is a public baseclass of another class, - i.e. that all its public methods are available in the derived - class. */ -#define TYPE_FLAG_VIA_PUBLIC 1024 -/* Indicates that this type is a virtual baseclass of another class, - i.e. that if this class is inherited more than once by another - class, only one set of member variables will be included. */ -#define TYPE_FLAG_VIA_VIRTUAL 2048 - -struct type -{ - /* Code for kind of type */ - enum type_code code; - /* Name of this type, or zero if none. - This is used for printing only. - Type names specified as input are defined by symbols. */ - char *name; - /* Length in bytes of storage for a value of this type */ - int length; - /* For a pointer type, describes the type of object pointed to. - For an array type, describes the type of the elements. - For a function or method type, describes the type of the value. - For a range type, describes the type of the full range. - Unused otherwise. */ - struct type *target_type; - /* Type that is a pointer to this type. - Zero if no such pointer-to type is known yet. - The debugger may add the address of such a type - if it has to construct one later. */ - struct type *pointer_type; - /* C++: also need a reference type. */ - struct type *reference_type; - struct type **arg_types; - - /* Type that is a function returning this type. - Zero if no such function type is known here. - The debugger may add the address of such a type - if it has to construct one later. */ - struct type *function_type; - -/* Handling of pointers to members: - TYPE_MAIN_VARIANT is used for pointer and pointer - to member types. Normally it the value of the address of its - containing type. However, for pointers to members, we must be - able to allocate pointer to member types and look them up - from some place of reference. - NEXT_VARIANT is the next element in the chain. */ - struct type *main_variant, *next_variant; - - /* Flags about this type. */ - short flags; - /* Number of fields described for this type */ - short nfields; - /* For structure and union types, a description of each field. - For set and pascal array types, there is one "field", - whose type is the domain type of the set or array. - For range types, there are two "fields", - the minimum and maximum values (both inclusive). - For enum types, each possible value is described by one "field". - - Using a pointer to a separate array of fields - allows all types to have the same size, which is useful - because we can allocate the space for a type before - we know what to put in it. */ - struct field - { - /* Position of this field, counting in bits from start of - containing structure. For a function type, this is the - position in the argument list of this argument. - For a range bound or enum value, this is the value itself. */ - int bitpos; - /* Size of this field, in bits, or zero if not packed. - For an unpacked field, the field's type's length - says how many bytes the field occupies. */ - int bitsize; - /* In a struct or enum type, type of this field. - In a function type, type of this argument. - In an array type, the domain-type of the array. */ - struct type *type; - /* Name of field, value or argument. - Zero for range bounds and array domains. */ - char *name; - } *fields; - - /* C++ */ - int *private_field_bits; - int *protected_field_bits; - - /* Number of methods described for this type */ - short nfn_fields; - /* Number of base classes this type derives from. */ - short n_baseclasses; - - /* Number of methods described for this type plus all the - methods that it derives from. */ - int nfn_fields_total; - - /* For classes, structures, and unions, a description of each field, - which consists of an overloaded name, followed by the types of - arguments that the method expects, and then the name after it - has been renamed to make it distinct. */ - struct fn_fieldlist - { - /* The overloaded name. */ - char *name; - /* The number of methods with this name. */ - int length; - /* The list of methods. */ - struct fn_field - { -#if 0 - /* The overloaded name */ - char *name; -#endif - /* The return value of the method */ - struct type *type; - /* The argument list */ - struct type **args; - /* The name after it has been processed */ - char *physname; - /* If this is a virtual function, the offset into the vtbl-1, - else 0. */ - int voffset; - } *fn_fields; - - int *private_fn_field_bits; - int *protected_fn_field_bits; - - } *fn_fieldlists; - - unsigned char via_protected; - unsigned char via_public; - - /* For types with virtual functions, VPTR_BASETYPE is the base class which - defined the virtual function table pointer. VPTR_FIELDNO is - the field number of that pointer in the structure. - - For types that are pointer to member types, VPTR_BASETYPE - ifs the type that this pointer is a member of. - - Unused otherwise. */ - struct type *vptr_basetype; - - int vptr_fieldno; - - /* If this type has a base class, put it here. - If this type is a pointer type, the chain of member pointer - types goes here. - Unused otherwise. - - Contrary to all maxims of C style and common sense, the baseclasses - are indexed from 1 to N_BASECLASSES rather than 0 to N_BASECLASSES-1 - (i.e. BASECLASSES points to one *before* the first element of - the array). */ - struct type **baseclasses; -}; - -/* All of the name-scope contours of the program - are represented by `struct block' objects. - All of these objects are pointed to by the blockvector. - - Each block represents one name scope. - Each lexical context has its own block. - - The first two blocks in the blockvector are special. - The first one contains all the symbols defined in this compilation - whose scope is the entire program linked together. - The second one contains all the symbols whose scope is the - entire compilation excluding other separate compilations. - In C, these correspond to global symbols and static symbols. - - Each block records a range of core addresses for the code that - is in the scope of the block. The first two special blocks - give, for the range of code, the entire range of code produced - by the compilation that the symbol segment belongs to. - - The blocks appear in the blockvector - in order of increasing starting-address, - and, within that, in order of decreasing ending-address. - - This implies that within the body of one function - the blocks appear in the order of a depth-first tree walk. */ - -struct blockvector -{ - /* Number of blocks in the list. */ - int nblocks; - /* The blocks themselves. */ - struct block *block[1]; -}; - -struct block -{ - /* Addresses in the executable code that are in this block. - Note: in an unrelocated symbol segment in a file, - these are always zero. They can be filled in from the - N_LBRAC and N_RBRAC symbols in the loader symbol table. */ - int startaddr, endaddr; - /* The symbol that names this block, - if the block is the body of a function; - otherwise, zero. - Note: In an unrelocated symbol segment in an object file, - this field may be zero even when the block has a name. - That is because the block is output before the name - (since the name resides in a higher block). - Since the symbol does point to the block (as its value), - it is possible to find the block and set its name properly. */ - struct symbol *function; - /* The `struct block' for the containing block, or 0 if none. */ - /* Note that in an unrelocated symbol segment in an object file - this pointer may be zero when the correct value should be - the second special block (for symbols whose scope is one compilation). - This is because the compiler ouptuts the special blocks at the - very end, after the other blocks. */ - struct block *superblock; - /* A flag indicating whether or not the fucntion corresponding - to this block was compiled with gcc or not. If there is no - function corresponding to this block, this meaning of this flag - is undefined. (In practice it will be 1 if the block was created - while processing a file compiled with gcc and 0 when not). */ - unsigned char gcc_compile_flag; - /* Number of local symbols. */ - int nsyms; - /* The symbols. */ - struct symbol *sym[1]; -}; - -/* Represent one symbol name; a variable, constant, function or typedef. */ - -/* Different name spaces for symbols. Looking up a symbol specifies - a namespace and ignores symbol definitions in other name spaces. - - VAR_NAMESPACE is the usual namespace. - In C, this contains variables, function names, typedef names - and enum type values. - - STRUCT_NAMESPACE is used in C to hold struct, union and enum type names. - Thus, if `struct foo' is used in a C program, - it produces a symbol named `foo' in the STRUCT_NAMESPACE. - - LABEL_NAMESPACE may be used for names of labels (for gotos); - currently it is not used and labels are not recorded at all. */ - -/* For a non-global symbol allocated statically, - the correct core address cannot be determined by the compiler. - The compiler puts an index number into the symbol's value field. - This index number can be matched with the "desc" field of - an entry in the loader symbol table. */ - -enum namespace -{ - UNDEF_NAMESPACE, VAR_NAMESPACE, STRUCT_NAMESPACE, LABEL_NAMESPACE, -}; - -/* An address-class says where to find the value of the symbol in core. */ - -enum address_class -{ - LOC_UNDEF, /* Not used; catches errors */ - LOC_CONST, /* Value is constant int */ - LOC_STATIC, /* Value is at fixed address */ - LOC_REGISTER, /* Value is in register */ - LOC_ARG, /* Value is at spec'd position in arglist */ - LOC_REF_ARG, /* Value address is at spec'd position in */ - /* arglist. */ - LOC_REGPARM, /* Value is at spec'd position in register window */ - LOC_LOCAL, /* Value is at spec'd pos in stack frame */ - LOC_TYPEDEF, /* Value not used; definition in SYMBOL_TYPE - Symbols in the namespace STRUCT_NAMESPACE - all have this class. */ - LOC_LABEL, /* Value is address in the code */ - LOC_BLOCK, /* Value is address of a `struct block'. - Function names have this class. */ - LOC_EXTERNAL, /* Value is at address not in this compilation. - This is used for .comm symbols - and for extern symbols within functions. - Inside GDB, this is changed to LOC_STATIC once the - real address is obtained from a loader symbol. */ - LOC_CONST_BYTES /* Value is a constant byte-sequence. */ -}; - -struct symbol -{ - /* Symbol name */ - char *name; - /* Name space code. */ - enum namespace namespace; - /* Address class */ - enum address_class class; - /* Data type of value */ - struct type *type; - /* constant value, or address if static, or register number, - or offset in arguments, or offset in stack frame. */ - union - { - long value; - struct block *block; /* for LOC_BLOCK */ - char *bytes; /* for LOC_CONST_BYTES */ - } - value; -}; - -struct partial_symbol -{ - /* Symbol name */ - char *name; - /* Name space code. */ - enum namespace namespace; - /* Address class (for info_symbols) */ - enum address_class class; - /* Associated partial symbol table */ - struct partial_symtab *pst; - /* Value (only used for static functions currently). Done this - way so that we can use the struct symbol macros. - Note that the address of a function is SYMBOL_VALUE (pst) - in a partial symbol table, but BLOCK_START (SYMBOL_BLOCK_VALUE (st)) - in a symbol table. */ - union - { - long value; - } - value; -}; - -/* - * Vectors of all partial symbols read in from file; actually declared - * and used in dbxread.c. - */ -extern struct psymbol_allocation_list { - struct partial_symbol *list, *next; - int size; -} global_psymbols, static_psymbols; - - -/* Source-file information. - This describes the relation between source files and line numbers - and addresses in the program text. */ - -struct sourcevector -{ - int length; /* Number of source files described */ - struct source *source[1]; /* Descriptions of the files */ -}; - -/* Each item represents a line-->pc (or the reverse) mapping. This is - somewhat more wasteful of space than one might wish, but since only - the files which are actually debugged are read in to core, we don't - waste much space. - - Each item used to be an int; either minus a line number, or a - program counter. If it represents a line number, that is the line - described by the next program counter value. If it is positive, it - is the program counter at which the code for the next line starts. */ - -struct linetable_entry -{ - int line; - CORE_ADDR pc; -}; - -struct linetable -{ - int nitems; - struct linetable_entry item[1]; -}; - -/* All the information on one source file. */ - -struct source -{ - char *name; /* Name of file */ - struct linetable contents; -}; diff --git a/gnu/usr.bin/gdb/symtab.c b/gnu/usr.bin/gdb/symtab.c deleted file mode 100644 index 4e4bd8e..0000000 --- a/gnu/usr.bin/gdb/symtab.c +++ /dev/null @@ -1,2473 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - * - * $Header: /a/cvs/386BSD/src/gnu/gdb/symtab.c,v 1.1 1993/06/29 09:47:40 nate Exp $; - */ - -#ifndef lint -static char sccsid[] = "@(#)symtab.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Symbol table lookup for the GNU debugger, GDB. - Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "symtab.h" - -#include -#include - -char *index (); -extern char *cplus_demangle (); -extern struct value * value_of_this (); - -/* Allocate an obstack to hold objects that should be freed - when we load a new symbol table. - This includes the symbols made by dbxread - and the types that are not permanent. */ - -struct obstack obstack1; - -struct obstack *symbol_obstack = &obstack1; - -/* This obstack will be used for partial_symbol objects. It can - probably actually be the same as the symbol_obstack above, but I'd - like to keep them seperate for now. If I want to later, I'll - replace one with the other. */ - -struct obstack obstack2; - -struct obstack *psymbol_obstack = &obstack2; - -/* These variables point to the objects - representing the predefined C data types. */ - -struct type *builtin_type_void; -struct type *builtin_type_char; -struct type *builtin_type_short; -struct type *builtin_type_int; -struct type *builtin_type_long; -#ifdef LONG_LONG -struct type *builtin_type_long_long; -#endif -struct type *builtin_type_unsigned_char; -struct type *builtin_type_unsigned_short; -struct type *builtin_type_unsigned_int; -struct type *builtin_type_unsigned_long; -#ifdef LONG_LONG -struct type *builtin_type_unsigned_long_long; -#endif -struct type *builtin_type_float; -struct type *builtin_type_double; - -/* Block in which the most recently searched-for symbol was found. - Might be better to make this a parameter to lookup_symbol and - value_of_this. */ -struct block *block_found; - -/* Functions */ -static int find_line_common (); -int lookup_misc_func (); -struct partial_symtab *lookup_partial_symtab (); -struct symtab *psymtab_to_symtab (); -static struct partial_symbol *lookup_partial_symbol (); - -/* Check for a symtab of a specific name; first in symtabs, then in - psymtabs. *If* there is no '/' in the name, a match after a '/' - in the symtab filename will also work. */ - -static struct symtab * -lookup_symtab_1 (name) - char *name; -{ - register struct symtab *s; - register struct partial_symtab *ps; - register char *slash = index (name, '/'); - register int len = strlen (name); - - for (s = symtab_list; s; s = s->next) - if (!strcmp (name, s->filename)) - return s; - - for (ps = partial_symtab_list; ps; ps = ps->next) - if (!strcmp (name, ps->filename)) - { - if (ps->readin) - fatal ("Internal: readin pst found when no symtab found."); - s = psymtab_to_symtab (ps); - return s; - } - - if (!slash) - { - for (s = symtab_list; s; s = s->next) - { - int l = strlen (s->filename); - - if (s->filename[l - len -1] == '/' - && !strcmp (s->filename + l - len, name)) - return s; - } - - for (ps = partial_symtab_list; ps; ps = ps->next) - { - int l = strlen (ps->filename); - - if (ps->filename[l - len - 1] == '/' - && !strcmp (ps->filename + l - len, name)) - { - if (ps->readin) - fatal ("Internal: readin pst found when no symtab found."); - s = psymtab_to_symtab (ps); - return s; - } - } - } - return 0; -} - -/* Lookup the symbol table of a source file named NAME. Try a couple - of variations if the first lookup doesn't work. */ - -struct symtab * -lookup_symtab (name) - char *name; -{ - register struct symtab *s; - register char *copy; - - s = lookup_symtab_1 (name); - if (s) return s; - - /* If name not found as specified, see if adding ".c" helps. */ - - copy = (char *) alloca (strlen (name) + 3); - strcpy (copy, name); - strcat (copy, ".c"); - s = lookup_symtab_1 (copy); - if (s) return s; - - /* We didn't find anything; die. */ - return 0; -} - -/* Lookup the partial symbol table of a source file named NAME. This - only returns true on an exact match (ie. this semantics are - different from lookup_symtab. */ - -struct partial_symtab * -lookup_partial_symtab (name) -char *name; -{ - register struct partial_symtab *s; - register char *copy; - - for (s = partial_symtab_list; s; s = s->next) - if (!strcmp (name, s->filename)) - return s; - - return 0; -} - -/* Lookup a typedef or primitive type named NAME, - visible in lexical block BLOCK. - If NOERR is nonzero, return zero if NAME is not suitably defined. */ - -struct type * -lookup_typename (name, block, noerr) - char *name; - struct block *block; - int noerr; -{ - register struct symbol *sym = lookup_symbol (name, block, VAR_NAMESPACE, 0); - if (sym == 0 || SYMBOL_CLASS (sym) != LOC_TYPEDEF) - { - if (!strcmp (name, "int")) - return builtin_type_int; - if (!strcmp (name, "long")) - return builtin_type_long; - if (!strcmp (name, "short")) - return builtin_type_short; - if (!strcmp (name, "char")) - return builtin_type_char; - if (!strcmp (name, "float")) - return builtin_type_float; - if (!strcmp (name, "double")) - return builtin_type_double; - if (!strcmp (name, "void")) - return builtin_type_void; - - if (noerr) - return 0; - error ("No type named %s.", name); - } - return SYMBOL_TYPE (sym); -} - -struct type * -lookup_unsigned_typename (name) - char *name; -{ - if (!strcmp (name, "int")) - return builtin_type_unsigned_int; - if (!strcmp (name, "long")) - return builtin_type_unsigned_long; - if (!strcmp (name, "short")) - return builtin_type_unsigned_short; - if (!strcmp (name, "char")) - return builtin_type_unsigned_char; - error ("No type named unsigned %s.", name); -} - -/* Lookup a structure type named "struct NAME", - visible in lexical block BLOCK. */ - -struct type * -lookup_struct (name, block) - char *name; - struct block *block; -{ - register struct symbol *sym - = lookup_symbol (name, block, STRUCT_NAMESPACE, 0); - - if (sym == 0) - error ("No struct type named %s.", name); - if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) - error ("This context has class, union or enum %s, not a struct.", name); - return SYMBOL_TYPE (sym); -} - -/* Lookup a union type named "union NAME", - visible in lexical block BLOCK. */ - -struct type * -lookup_union (name, block) - char *name; - struct block *block; -{ - register struct symbol *sym - = lookup_symbol (name, block, STRUCT_NAMESPACE, 0); - - if (sym == 0) - error ("No union type named %s.", name); - if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION) - error ("This context has class, struct or enum %s, not a union.", name); - return SYMBOL_TYPE (sym); -} - -/* Lookup an enum type named "enum NAME", - visible in lexical block BLOCK. */ - -struct type * -lookup_enum (name, block) - char *name; - struct block *block; -{ - register struct symbol *sym - = lookup_symbol (name, block, STRUCT_NAMESPACE, 0); - if (sym == 0) - error ("No enum type named %s.", name); - if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) - error ("This context has class, struct or union %s, not an enum.", name); - return SYMBOL_TYPE (sym); -} - -/* Given a type TYPE, lookup the type of the component of type named - NAME. */ - -struct type * -lookup_struct_elt_type (type, name) - struct type *type; - char *name; -{ - struct type *t; - int i; - char *errmsg; - - if (TYPE_CODE (type) != TYPE_CODE_STRUCT - && TYPE_CODE (type) != TYPE_CODE_UNION) - { - terminal_ours (); - fflush (stdout); - fprintf (stderr, "Type "); - type_print (type, "", stderr, -1); - fprintf (stderr, " is not a structure or union type.\n"); - return_to_top_level (); - } - - for (i = TYPE_NFIELDS (type) - 1; i >= 0; i--) - if (!strcmp (TYPE_FIELD_NAME (type, i), name)) - return TYPE_FIELD_TYPE (type, i); - - terminal_ours (); - fflush (stdout); - fprintf (stderr, "Type "); - type_print (type, "", stderr, -1); - fprintf (stderr, " has no component named %s\n", name); - return_to_top_level (); -} - -/* Given a type TYPE, return a type of pointers to that type. - May need to construct such a type if this is the first use. - - C++: use TYPE_MAIN_VARIANT and TYPE_CHAIN to keep pointer - to member types under control. */ - -struct type * -lookup_pointer_type (type) - struct type *type; -{ - register struct type *ptype = TYPE_POINTER_TYPE (type); - if (ptype) return TYPE_MAIN_VARIANT (ptype); - - /* This is the first time anyone wanted a pointer to a TYPE. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - ptype = (struct type *) xmalloc (sizeof (struct type)); - else - ptype = (struct type *) obstack_alloc (symbol_obstack, - sizeof (struct type)); - - bzero (ptype, sizeof (struct type)); - TYPE_MAIN_VARIANT (ptype) = ptype; - TYPE_TARGET_TYPE (ptype) = type; - TYPE_POINTER_TYPE (type) = ptype; - /* New type is permanent if type pointed to is permanent. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM; - /* We assume the machine has only one representation for pointers! */ - TYPE_LENGTH (ptype) = sizeof (char *); - TYPE_CODE (ptype) = TYPE_CODE_PTR; - return ptype; -} - -struct type * -lookup_reference_type (type) - struct type *type; -{ - register struct type *rtype = TYPE_REFERENCE_TYPE (type); - if (rtype) return TYPE_MAIN_VARIANT (rtype); - - /* This is the first time anyone wanted a pointer to a TYPE. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - rtype = (struct type *) xmalloc (sizeof (struct type)); - else - rtype = (struct type *) obstack_alloc (symbol_obstack, - sizeof (struct type)); - - bzero (rtype, sizeof (struct type)); - TYPE_MAIN_VARIANT (rtype) = rtype; - TYPE_TARGET_TYPE (rtype) = type; - TYPE_REFERENCE_TYPE (type) = rtype; - /* New type is permanent if type pointed to is permanent. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - TYPE_FLAGS (rtype) |= TYPE_FLAG_PERM; - /* We assume the machine has only one representation for pointers! */ - TYPE_LENGTH (rtype) = sizeof (char *); - TYPE_CODE (rtype) = TYPE_CODE_REF; - return rtype; -} - - -/* Implement direct support for MEMBER_TYPE in GNU C++. - May need to construct such a type if this is the first use. - The TYPE is the type of the member. The DOMAIN is the type - of the aggregate that the member belongs to. */ - -struct type * -lookup_member_type (type, domain) - struct type *type, *domain; -{ - register struct type *mtype = TYPE_MAIN_VARIANT (type); - struct type *main_type; - - main_type = mtype; - while (mtype) - { - if (TYPE_DOMAIN_TYPE (mtype) == domain) - return mtype; - mtype = TYPE_NEXT_VARIANT (mtype); - } - - /* This is the first time anyone wanted this member type. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - mtype = (struct type *) xmalloc (sizeof (struct type)); - else - mtype = (struct type *) obstack_alloc (symbol_obstack, - sizeof (struct type)); - - bzero (mtype, sizeof (struct type)); - if (main_type == 0) - main_type = mtype; - else - { - TYPE_NEXT_VARIANT (mtype) = TYPE_NEXT_VARIANT (main_type); - TYPE_NEXT_VARIANT (main_type) = mtype; - } - TYPE_MAIN_VARIANT (mtype) = main_type; - TYPE_TARGET_TYPE (mtype) = type; - TYPE_DOMAIN_TYPE (mtype) = domain; - /* New type is permanent if type pointed to is permanent. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - TYPE_FLAGS (mtype) |= TYPE_FLAG_PERM; - - /* In practice, this is never used. */ - TYPE_LENGTH (mtype) = 1; - TYPE_CODE (mtype) = TYPE_CODE_MEMBER; - -#if 0 - /* Now splice in the new member pointer type. */ - if (main_type) - { - /* This type was not "smashed". */ - TYPE_CHAIN (mtype) = TYPE_CHAIN (main_type); - TYPE_CHAIN (main_type) = mtype; - } -#endif - - return mtype; -} - -struct type * -lookup_method_type (type, domain, args) - struct type *type, *domain, **args; -{ - register struct type *mtype = TYPE_MAIN_VARIANT (type); - struct type *main_type; - - main_type = mtype; - while (mtype) - { - if (TYPE_DOMAIN_TYPE (mtype) == domain) - { - struct type **t1 = args; - struct type **t2 = TYPE_ARG_TYPES (mtype); - if (t2) - { - int i; - for (i = 0; t1[i] != 0 && t1[i]->code != TYPE_CODE_VOID; i++) - if (t1[i] != t2[i]) - break; - if (t1[i] == t2[i]) - return mtype; - } - } - mtype = TYPE_NEXT_VARIANT (mtype); - } - - /* This is the first time anyone wanted this member type. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - mtype = (struct type *) xmalloc (sizeof (struct type)); - else - mtype = (struct type *) obstack_alloc (symbol_obstack, - sizeof (struct type)); - - bzero (mtype, sizeof (struct type)); - if (main_type == 0) - main_type = mtype; - else - { - TYPE_NEXT_VARIANT (mtype) = TYPE_NEXT_VARIANT (main_type); - TYPE_NEXT_VARIANT (main_type) = mtype; - } - TYPE_MAIN_VARIANT (mtype) = main_type; - TYPE_TARGET_TYPE (mtype) = type; - TYPE_DOMAIN_TYPE (mtype) = domain; - TYPE_ARG_TYPES (mtype) = args; - /* New type is permanent if type pointed to is permanent. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - TYPE_FLAGS (mtype) |= TYPE_FLAG_PERM; - - /* In practice, this is never used. */ - TYPE_LENGTH (mtype) = 1; - TYPE_CODE (mtype) = TYPE_CODE_METHOD; - -#if 0 - /* Now splice in the new member pointer type. */ - if (main_type) - { - /* This type was not "smashed". */ - TYPE_CHAIN (mtype) = TYPE_CHAIN (main_type); - TYPE_CHAIN (main_type) = mtype; - } -#endif - - return mtype; -} - -/* Given a type TYPE, return a type which has offset OFFSET, - via_virtual VIA_VIRTUAL, and via_public VIA_PUBLIC. - May need to construct such a type if none exists. */ -struct type * -lookup_basetype_type (type, offset, via_virtual, via_public) - struct type *type; - int offset; - int via_virtual, via_public; -{ - register struct type *btype = TYPE_MAIN_VARIANT (type); - struct type *main_type; - - if (offset != 0) - { - printf ("Internal error: type offset non-zero in lookup_basetype_type"); - offset = 0; - } - - main_type = btype; - while (btype) - { - if (/* TYPE_OFFSET (btype) == offset - && */ TYPE_VIA_PUBLIC (btype) == via_public - && TYPE_VIA_VIRTUAL (btype) == via_virtual) - return btype; - btype = TYPE_NEXT_VARIANT (btype); - } - - /* This is the first time anyone wanted this member type. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - btype = (struct type *) xmalloc (sizeof (struct type)); - else - btype = (struct type *) obstack_alloc (symbol_obstack, - sizeof (struct type)); - - if (main_type == 0) - { - main_type = btype; - bzero (btype, sizeof (struct type)); - TYPE_MAIN_VARIANT (btype) = main_type; - } - else - { - bcopy (main_type, btype, sizeof (struct type)); - TYPE_NEXT_VARIANT (main_type) = btype; - } -/* TYPE_OFFSET (btype) = offset; */ - if (via_public) - TYPE_FLAGS (btype) |= TYPE_FLAG_VIA_PUBLIC; - if (via_virtual) - TYPE_FLAGS (btype) |= TYPE_FLAG_VIA_VIRTUAL; - /* New type is permanent if type pointed to is permanent. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - TYPE_FLAGS (btype) |= TYPE_FLAG_PERM; - - /* In practice, this is never used. */ - TYPE_LENGTH (btype) = 1; - TYPE_CODE (btype) = TYPE_CODE_STRUCT; - - return btype; -} - -/* Given a type TYPE, return a type of functions that return that type. - May need to construct such a type if this is the first use. */ - -struct type * -lookup_function_type (type) - struct type *type; -{ - register struct type *ptype = TYPE_FUNCTION_TYPE (type); - if (ptype) return ptype; - - /* This is the first time anyone wanted a function returning a TYPE. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - ptype = (struct type *) xmalloc (sizeof (struct type)); - else - ptype = (struct type *) obstack_alloc (symbol_obstack, - sizeof (struct type)); - - bzero (ptype, sizeof (struct type)); - TYPE_TARGET_TYPE (ptype) = type; - TYPE_FUNCTION_TYPE (type) = ptype; - /* New type is permanent if type returned is permanent. */ - if (TYPE_FLAGS (type) & TYPE_FLAG_PERM) - TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM; - TYPE_LENGTH (ptype) = 1; - TYPE_CODE (ptype) = TYPE_CODE_FUNC; - TYPE_NFIELDS (ptype) = 0; - return ptype; -} - -/* Create an array type. Elements will be of type TYPE, and there will - be NUM of them. - - Eventually this should be extended to take two more arguments which - specify the bounds of the array and the type of the index. - It should also be changed to be a "lookup" function, with the - appropriate data structures added to the type field. - Then read array type should call here. */ - -struct type * -create_array_type (element_type, number) - struct type *element_type; - int number; -{ - struct type *result_type = (struct type *) - obstack_alloc (symbol_obstack, sizeof (struct type)); - - bzero (result_type, sizeof (struct type)); - - TYPE_CODE (result_type) = TYPE_CODE_ARRAY; - TYPE_TARGET_TYPE (result_type) = element_type; - TYPE_LENGTH (result_type) = number * TYPE_LENGTH (element_type); - TYPE_NFIELDS (result_type) = 1; - TYPE_FIELDS (result_type) = - (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field)); - TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; - TYPE_VPTR_FIELDNO (result_type) = -1; - - return result_type; -} - - -/* Smash TYPE to be a type of pointers to TO_TYPE. - If TO_TYPE is not permanent and has no pointer-type yet, - record TYPE as its pointer-type. */ - -void -smash_to_pointer_type (type, to_type) - struct type *type, *to_type; -{ - int type_permanent = (TYPE_FLAGS (type) & TYPE_FLAG_PERM); - - bzero (type, sizeof (struct type)); - TYPE_TARGET_TYPE (type) = to_type; - /* We assume the machine has only one representation for pointers! */ - TYPE_LENGTH (type) = sizeof (char *); - TYPE_CODE (type) = TYPE_CODE_PTR; - - TYPE_MAIN_VARIANT (type) = type; - - if (type_permanent) - TYPE_FLAGS (type) |= TYPE_FLAG_PERM; - - if (TYPE_POINTER_TYPE (to_type) == 0 - && (!(TYPE_FLAGS (to_type) & TYPE_FLAG_PERM) - || type_permanent)) - { - TYPE_POINTER_TYPE (to_type) = type; - } -} - -/* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. */ - -void -smash_to_member_type (type, domain, to_type) - struct type *type, *domain, *to_type; -{ - bzero (type, sizeof (struct type)); - TYPE_TARGET_TYPE (type) = to_type; - TYPE_DOMAIN_TYPE (type) = domain; - - /* In practice, this is never needed. */ - TYPE_LENGTH (type) = 1; - TYPE_CODE (type) = TYPE_CODE_MEMBER; - - TYPE_MAIN_VARIANT (type) = lookup_member_type (domain, to_type); -} - -/* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. */ - -void -smash_to_method_type (type, domain, to_type, args) - struct type *type, *domain, *to_type, **args; -{ - bzero (type, sizeof (struct type)); - TYPE_TARGET_TYPE (type) = to_type; - TYPE_DOMAIN_TYPE (type) = domain; - TYPE_ARG_TYPES (type) = args; - - /* In practice, this is never needed. */ - TYPE_LENGTH (type) = 1; - TYPE_CODE (type) = TYPE_CODE_METHOD; - - TYPE_MAIN_VARIANT (type) = lookup_method_type (domain, to_type, args); -} - -/* Smash TYPE to be a type of reference to TO_TYPE. - If TO_TYPE is not permanent and has no pointer-type yet, - record TYPE as its pointer-type. */ - -void -smash_to_reference_type (type, to_type) - struct type *type, *to_type; -{ - int type_permanent = (TYPE_FLAGS (type) & TYPE_FLAG_PERM); - - bzero (type, sizeof (struct type)); - TYPE_TARGET_TYPE (type) = to_type; - /* We assume the machine has only one representation for pointers! */ - TYPE_LENGTH (type) = sizeof (char *); - TYPE_CODE (type) = TYPE_CODE_REF; - - TYPE_MAIN_VARIANT (type) = type; - - if (type_permanent) - TYPE_FLAGS (type) |= TYPE_FLAG_PERM; - - if (TYPE_REFERENCE_TYPE (to_type) == 0 - && (!(TYPE_FLAGS (to_type) & TYPE_FLAG_PERM) - || type_permanent)) - { - TYPE_REFERENCE_TYPE (to_type) = type; - } -} - -/* Smash TYPE to be a type of functions returning TO_TYPE. - If TO_TYPE is not permanent and has no function-type yet, - record TYPE as its function-type. */ - -void -smash_to_function_type (type, to_type) - struct type *type, *to_type; -{ - int type_permanent = (TYPE_FLAGS (type) & TYPE_FLAG_PERM); - - bzero (type, sizeof (struct type)); - TYPE_TARGET_TYPE (type) = to_type; - TYPE_LENGTH (type) = 1; - TYPE_CODE (type) = TYPE_CODE_FUNC; - TYPE_NFIELDS (type) = 0; - - if (type_permanent) - TYPE_FLAGS (type) |= TYPE_FLAG_PERM; - - if (TYPE_FUNCTION_TYPE (to_type) == 0 - && (!(TYPE_FLAGS (to_type) & TYPE_FLAG_PERM) - || type_permanent)) - { - TYPE_FUNCTION_TYPE (to_type) = type; - } -} - -/* Find which partial symtab on the partial_symtab_list contains - PC. Return 0 if none. */ - -struct partial_symtab * -find_pc_psymtab (pc) - register CORE_ADDR pc; -{ - register struct partial_symtab *ps; - - for (ps = partial_symtab_list; ps; ps = ps->next) - if (pc >= ps->textlow && pc < ps->texthigh) - return ps; - - return 0; -} - -/* Find which partial symbol within a psymtab contains PC. Return 0 - if none. Check all psymtabs if PSYMTAB is 0. */ -struct partial_symbol * -find_pc_psymbol (psymtab, pc) - struct partial_symtab *psymtab; - CORE_ADDR pc; -{ - struct partial_symbol *best, *p; - int best_pc; - - if (!psymtab) - psymtab = find_pc_psymtab (pc); - if (!psymtab) - return 0; - - best_pc = psymtab->textlow - 1; - - for (p = static_psymbols.list + psymtab->statics_offset; - (p - (static_psymbols.list + psymtab->statics_offset) - < psymtab->n_static_syms); - p++) - if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE - && SYMBOL_CLASS (p) == LOC_BLOCK - && pc >= SYMBOL_VALUE (p) - && SYMBOL_VALUE (p) > best_pc) - { - best_pc = SYMBOL_VALUE (p); - best = p; - } - if (best_pc == psymtab->textlow - 1) - return 0; - return best; -} - - -static struct symbol *lookup_block_symbol (); - -/* Find the definition for a specified symbol name NAME - in namespace NAMESPACE, visible from lexical block BLOCK. - Returns the struct symbol pointer, or zero if no symbol is found. - C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if - NAME is a field of the current implied argument `this'. If so set - *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero. - BLOCK_FOUND is set to the block in which NAME is found (in the case of - a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */ - -struct symbol * -lookup_symbol (name, block, namespace, is_a_field_of_this) - char *name; - register struct block *block; - enum namespace namespace; - int *is_a_field_of_this; -{ - register int i, n; - register struct symbol *sym; - register struct symtab *s; - register struct partial_symtab *ps; - register struct partial_symbol *psym; - struct blockvector *bv; - - /* Search specified block and its superiors. */ - - while (block != 0) - { - sym = lookup_block_symbol (block, name, namespace); - if (sym) - { - block_found = block; - return sym; - } - block = BLOCK_SUPERBLOCK (block); - } - - /* C++: If requested to do so by the caller, - check to see if NAME is a field of `this'. */ - if (is_a_field_of_this) - { - struct value *v = value_of_this (0); - - *is_a_field_of_this = 0; - if (v && check_field (v, name)) - { - *is_a_field_of_this = 1; - return 0; - } - } - - /* Now search all global blocks. Do the symtab's first, then - check the psymtab's */ - - for (s = symtab_list; s; s = s->next) - { - bv = BLOCKVECTOR (s); - block = BLOCKVECTOR_BLOCK (bv, 0); - sym = lookup_block_symbol (block, name, namespace); - if (sym) - { - block_found = block; - return sym; - } - } - - /* Check for the possibility of the symbol being a global function - that is stored on the misc function vector. Eventually, all - global symbols might be resolved in this way. */ - - if (namespace == VAR_NAMESPACE) - { - int index = lookup_misc_func (name); - - if (index == -1) - { /* Look for a mangled C++ name for NAME. */ - int name_len = strlen (name); - for (index = misc_function_count; --index >= 0; ) - /* Assume orginal name is prefix of mangled name. */ - if (!strncmp (misc_function_vector[index].name, name, name_len)) - { - char *demangled = - cplus_demangle(misc_function_vector[index].name, -1); - if (demangled != NULL) - { - int cond = strcmp (demangled, name); - free (demangled); - if (!cond) - break; - } - } - /* Loop terminates on no match with index == -1. */ - } - - if (index != -1) - { - ps = find_pc_psymtab (misc_function_vector[index].address); - if (ps && !ps->readin) - { - s = psymtab_to_symtab (ps); - bv = BLOCKVECTOR (s); - block = BLOCKVECTOR_BLOCK (bv, 0); - sym = lookup_block_symbol (block, name, namespace); - /* sym == 0 if symbol was found in the psymtab but not - in the symtab. - Return 0 to use the misc_function definition of "foo_". - - This happens for Fortran "foo_" symbols, - which are "foo" in the symtab. - - This can also happen if "asm" is used to make a - regular symbol but not a debugging symbol, e.g. - asm(".globl _main"); - asm("_main:"); - */ - - return sym; - } - } - } - - if (psym = lookup_partial_symbol (name, 1, namespace)) - { - ps = psym->pst; - s = psymtab_to_symtab(ps); - bv = BLOCKVECTOR (s); - block = BLOCKVECTOR_BLOCK (bv, 0); - sym = lookup_block_symbol (block, name, namespace); - if (!sym) - fatal ("Internal: global symbol found in psymtab but not in symtab"); - return sym; - } - - /* Now search all per-file blocks. - Not strictly correct, but more useful than an error. - Do the symtabs first, then check the psymtabs */ - - for (s = symtab_list; s; s = s->next) - { - bv = BLOCKVECTOR (s); - block = BLOCKVECTOR_BLOCK (bv, 1); - sym = lookup_block_symbol (block, name, namespace); - if (sym) - { - block_found = block; - return sym; - } - } - - if (psym = lookup_partial_symbol(name, 0, namespace)) - { - ps = psym->pst; - s = psymtab_to_symtab(ps); - bv = BLOCKVECTOR (s); - block = BLOCKVECTOR_BLOCK (bv, 1); - sym = lookup_block_symbol (block, name, namespace); - if (!sym) - fatal ("Internal: static symbol found in psymtab but not in symtab"); - return sym; - } - - return 0; -} - -/* Look, in partial_symtab PST, for symbol NAME. Check the global - symbols if GLOBAL, the static symbols if not */ - -static struct partial_symbol * -lookup_partial_symbol (name, global, namespace) - register char *name; - register int global; - register enum namespace namespace; -{ - register struct partial_symbol *start, *psym; - register struct partial_symbol *top, *bottom, *center; - register struct partial_symtab *pst; - register int length; - - if (global) - { - start = global_psymbols.list; - length = global_psymbols.next - start; - } - else - { - start = static_psymbols.list; - length = static_psymbols.next - start; - } - - if (!length) - return (struct partial_symbol *) 0; - - /* Binary search. This search is guarranteed to end with center - pointing at the earliest partial symbol with the correct - name. At that point *all* partial symbols with that name - will be checked against the correct namespace. */ - bottom = start; - top = start + length - 1; - while (top > bottom) - { - center = bottom + (top - bottom) / 2; - - assert (center < top); - - if (strcmp (SYMBOL_NAME (center), name) >= 0) - top = center; - else - bottom = center + 1; - } - assert (top == bottom); - - while (strcmp (SYMBOL_NAME (top), name) == 0) - { - if (!top->pst->readin && SYMBOL_NAMESPACE (top) == namespace) - return top; - top ++; - } - - return (struct partial_symbol *) 0; -} - -/* Look for a symbol in block BLOCK. */ - -static struct symbol * -lookup_block_symbol (block, name, namespace) - register struct block *block; - char *name; - enum namespace namespace; -{ - register int bot, top, inc; - register struct symbol *sym, *parameter_sym; - - top = BLOCK_NSYMS (block); - bot = 0; - - /* If the blocks's symbols were sorted, start with a binary search. */ - - if (BLOCK_SHOULD_SORT (block)) - { - /* First, advance BOT to not far before - the first symbol whose name is NAME. */ - - while (1) - { - inc = (top - bot + 1); - /* No need to keep binary searching for the last few bits worth. */ - if (inc < 4) - break; - inc = (inc >> 1) + bot; - sym = BLOCK_SYM (block, inc); - if (SYMBOL_NAME (sym)[0] < name[0]) - bot = inc; - else if (SYMBOL_NAME (sym)[0] > name[0]) - top = inc; - else if (strcmp (SYMBOL_NAME (sym), name) < 0) - bot = inc; - else - top = inc; - } - - /* Now scan forward until we run out of symbols, - find one whose name is greater than NAME, - or find one we want. - If there is more than one symbol with the right name and namespace, - we return the first one. dbxread.c is careful to make sure - that if one is a register then it comes first. */ - - top = BLOCK_NSYMS (block); - while (bot < top) - { - sym = BLOCK_SYM (block, bot); - inc = SYMBOL_NAME (sym)[0] - name[0]; - if (inc == 0) - inc = strcmp (SYMBOL_NAME (sym), name); - if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace) - return sym; - if (inc > 0) - return 0; - bot++; - } - return 0; - } - - /* Here if block isn't sorted. - This loop is equivalent to the loop above, - but hacked greatly for speed. - - Note that parameter symbols do not always show up last in the - list; this loop makes sure to take anything else other than - parameter symbols first; it only uses parameter symbols as a - last resort. Note that this only takes up extra computation - time on a match. */ - - parameter_sym = (struct symbol *) 0; - top = BLOCK_NSYMS (block); - inc = name[0]; - while (bot < top) - { - sym = BLOCK_SYM (block, bot); - if (SYMBOL_NAME (sym)[0] == inc - && !strcmp (SYMBOL_NAME (sym), name) - && SYMBOL_NAMESPACE (sym) == namespace) - { - if (SYMBOL_CLASS (sym) == LOC_ARG - || SYMBOL_CLASS (sym) == LOC_REF_ARG - || SYMBOL_CLASS (sym) == LOC_REGPARM) - parameter_sym = sym; - else - return sym; - } - bot++; - } - return parameter_sym; /* Will be 0 if not found. */ -} - -/* Return the symbol for the function which contains a specified - lexical block, described by a struct block BL. */ - -struct symbol * -block_function (bl) - struct block *bl; -{ - while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0) - bl = BLOCK_SUPERBLOCK (bl); - - return BLOCK_FUNCTION (bl); -} - -/* Subroutine of find_pc_line */ - -struct symtab * -find_pc_symtab (pc) - register CORE_ADDR pc; -{ - register struct block *b; - struct blockvector *bv; - register struct symtab *s; - register struct partial_symtab *ps; - - /* Search all symtabs for one whose file contains our pc */ - - for (s = symtab_list; s; s = s->next) - { - bv = BLOCKVECTOR (s); - b = BLOCKVECTOR_BLOCK (bv, 0); - if (BLOCK_START (b) <= pc - && BLOCK_END (b) > pc) - break; - } - - if (!s) - { - ps = find_pc_psymtab (pc); - if (ps && ps->readin) - fatal ("Internal error: pc in read in psymtab, but not in symtab."); - - if (ps) - s = psymtab_to_symtab (ps); - } - - return s; -} - -/* Find the source file and line number for a given PC value. - Return a structure containing a symtab pointer, a line number, - and a pc range for the entire source line. - The value's .pc field is NOT the specified pc. - NOTCURRENT nonzero means, if specified pc is on a line boundary, - use the line that ends there. Otherwise, in that case, the line - that begins there is used. */ - -struct symtab_and_line -find_pc_line (pc, notcurrent) - CORE_ADDR pc; - int notcurrent; -{ - struct symtab *s; - register struct linetable *l; - register int len; - register int i; - register struct linetable_entry *item; - struct symtab_and_line value; - struct blockvector *bv; - - /* Info on best line seen so far, and where it starts, and its file. */ - - int best_line = 0; - CORE_ADDR best_pc = 0; - CORE_ADDR best_end = 0; - struct symtab *best_symtab = 0; - - /* Store here the first line number - of a file which contains the line at the smallest pc after PC. - If we don't find a line whose range contains PC, - we will use a line one less than this, - with a range from the start of that file to the first line's pc. */ - int alt_line = 0; - CORE_ADDR alt_pc = 0; - struct symtab *alt_symtab = 0; - - /* Info on best line seen in this file. */ - - int prev_line; - CORE_ADDR prev_pc; - - /* Info on first line of this file. */ - - int first_line; - CORE_ADDR first_pc; - - /* If this pc is not from the current frame, - it is the address of the end of a call instruction. - Quite likely that is the start of the following statement. - But what we want is the statement containing the instruction. - Fudge the pc to make sure we get that. */ - - if (notcurrent) pc -= 1; - - s = find_pc_symtab (pc); - if (s == 0) - { - value.symtab = 0; - value.line = 0; - value.pc = pc; - value.end = 0; - return value; - } - - bv = BLOCKVECTOR (s); - - /* Look at all the symtabs that share this blockvector. - They all have the same apriori range, that we found was right; - but they have different line tables. */ - - for (; s && BLOCKVECTOR (s) == bv; s = s->next) - { - /* Find the best line in this symtab. */ - l = LINETABLE (s); - len = l->nitems; - prev_line = -1; - first_line = -1; - for (i = 0; i < len; i++) - { - item = &(l->item[i]); - - if (first_line < 0) - { - first_line = item->line; - first_pc = item->pc; - } - /* Return the last line that did not start after PC. */ - if (pc >= item->pc) - { - prev_line = item->line; - prev_pc = item->pc; - } - else - break; - } - - /* Is this file's best line closer than the best in the other files? - If so, record this file, and its best line, as best so far. */ - if (prev_line >= 0 && prev_pc > best_pc) - { - best_pc = prev_pc; - best_line = prev_line; - best_symtab = s; - if (i < len) - best_end = item->pc; - else - best_end = 0; - } - /* Is this file's first line closer than the first lines of other files? - If so, record this file, and its first line, as best alternate. */ - if (first_line >= 0 && first_pc > pc - && (alt_pc == 0 || first_pc < alt_pc)) - { - alt_pc = first_pc; - alt_line = first_line; - alt_symtab = s; - } - } - if (best_symtab == 0) - { - value.symtab = alt_symtab; - value.line = alt_line - 1; - value.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, 0)); - value.end = alt_pc; - } - else - { - value.symtab = best_symtab; - value.line = best_line; - value.pc = best_pc; - value.end = (best_end ? best_end - : (alt_pc ? alt_pc - : BLOCK_END (BLOCKVECTOR_BLOCK (bv, 0)))); - } - return value; -} - -/* Find the PC value for a given source file and line number. - Returns zero for invalid line number. - The source file is specified with a struct symtab. */ - -CORE_ADDR -find_line_pc (symtab, line) - struct symtab *symtab; - int line; -{ - register struct linetable *l; - register int index; - int dummy; - - if (symtab == 0) - return 0; - l = LINETABLE (symtab); - index = find_line_common(l, line, &dummy); - return index ? l->item[index].pc : 0; -} - -/* Find the range of pc values in a line. - Store the starting pc of the line into *STARTPTR - and the ending pc (start of next line) into *ENDPTR. - Returns 1 to indicate success. - Returns 0 if could not find the specified line. */ - -int -find_line_pc_range (symtab, thisline, startptr, endptr) - struct symtab *symtab; - int thisline; - CORE_ADDR *startptr, *endptr; -{ - register struct linetable *l; - register int index; - int exact_match; /* did we get an exact linenumber match */ - register CORE_ADDR prev_pc; - CORE_ADDR last_pc; - - if (symtab == 0) - return 0; - - l = LINETABLE (symtab); - index = find_line_common (l, thisline, &exact_match); - if (index) - { - *startptr = l->item[index].pc; - /* If we have not seen an entry for the specified line, - assume that means the specified line has zero bytes. */ - if (!exact_match || index == l->nitems-1) - *endptr = *startptr; - else - /* Perhaps the following entry is for the following line. - It's worth a try. */ - if (l->item[index+1].line == thisline + 1) - *endptr = l->item[index+1].pc; - else - *endptr = find_line_pc (symtab, thisline+1); - return 1; - } - - return 0; -} - -/* Given a line table and a line number, return the index into the line - table for the pc of the nearest line whose number is >= the specified one. - Return 0 if none is found. The value is never zero is it is an index. - - Set *EXACT_MATCH nonzero if the value returned is an exact match. */ - -static int -find_line_common (l, lineno, exact_match) - register struct linetable *l; - register int lineno; - int *exact_match; -{ - register int i; - register int len; - - /* BEST is the smallest linenumber > LINENO so far seen, - or 0 if none has been seen so far. - BEST_INDEX identifies the item for it. */ - - int best_index = 0; - int best = 0; - - int nextline = -1; - - if (lineno <= 0) - return 0; - - len = l->nitems; - for (i = 0; i < len; i++) - { - register struct linetable_entry *item = &(l->item[i]); - - if (item->line == lineno) - { - *exact_match = 1; - return i; - } - - if (item->line > lineno && (best == 0 || item->line < best)) - { - best = item->line; - best_index = i; - } - } - - /* If we got here, we didn't get an exact match. */ - - *exact_match = 0; - return best_index; -} - -int -find_pc_line_pc_range (pc, startptr, endptr) - CORE_ADDR pc; - CORE_ADDR *startptr, *endptr; -{ - struct symtab_and_line sal; - sal = find_pc_line (pc, 0); - *startptr = sal.pc; - *endptr = sal.end; - return sal.symtab != 0; -} - -/* Parse a string that specifies a line number. - Pass the address of a char * variable; that variable will be - advanced over the characters actually parsed. - - The string can be: - - LINENUM -- that line number in current file. PC returned is 0. - FILE:LINENUM -- that line in that file. PC returned is 0. - FUNCTION -- line number of openbrace of that function. - PC returned is the start of the function. - FILE:FUNCTION -- likewise, but prefer functions in that file. - *EXPR -- line in which address EXPR appears. - - FUNCTION may be an undebuggable function found in misc_function_vector. - - If the argument FUNFIRSTLINE is nonzero, we want the first line - of real code inside a function when a function is specified. - - DEFAULT_SYMTAB specifies the file to use if none is specified. - It defaults to current_source_symtab. - DEFAULT_LINE specifies the line number to use for relative - line numbers (that start with signs). Defaults to current_source_line. - - Note that it is possible to return zero for the symtab - if no file is validly specified. Callers must check that. - Also, the line number returned may be invalid. */ - -struct symtabs_and_lines -decode_line_1 (argptr, funfirstline, default_symtab, default_line) - char **argptr; - int funfirstline; - struct symtab *default_symtab; - int default_line; -{ - struct symtabs_and_lines decode_line_2 (); - struct symtabs_and_lines values; - struct symtab_and_line value; - register char *p, *p1; - register struct symtab *s; - register struct symbol *sym; - register CORE_ADDR pc; - register int i; - char *copy; - struct symbol *sym_class; - char *class_name, *method_name, *phys_name; - int method_counter; - int i1; - struct symbol **sym_arr; - struct type *t, *field; - char **physnames; - - /* Defaults have defaults. */ - - if (default_symtab == 0) - { - default_symtab = current_source_symtab; - default_line = current_source_line; - } - - /* See if arg is *PC */ - - if (**argptr == '*') - { - (*argptr)++; - pc = parse_and_eval_address_1 (argptr); - values.sals = (struct symtab_and_line *) - malloc (sizeof (struct symtab_and_line)); - values.nelts = 1; - values.sals[0] = find_pc_line (pc, 0); - values.sals[0].pc = pc; - return values; - } - - /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */ - - s = 0; - - for (p = *argptr; *p; p++) - { - if (p[0] == ':' || p[0] == ' ' || p[0] == '\t') - break; - } - while (p[0] == ' ' || p[0] == '\t') p++; - - if (p[0] == ':') - { - - /* C++ */ - if (p[1] ==':') - { - /* Extract the class name. */ - p1 = p; - while (p != *argptr && p[-1] == ' ') --p; - copy = (char *) alloca (p - *argptr + 1); - bcopy (*argptr, copy, p - *argptr); - copy[p - *argptr] = 0; - - /* Discard the class name from the arg. */ - p = p1 + 2; - while (*p == ' ' || *p == '\t') p++; - *argptr = p; - - sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0); - - if (sym_class && - (TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT - || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION)) - { - /* Arg token is not digits => try it as a function name - Find the next token (everything up to end or next whitespace). */ - p = *argptr; - while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++; - copy = (char *) alloca (p - *argptr + 1); - bcopy (*argptr, copy, p - *argptr); - copy[p - *argptr] = '\0'; - - /* no line number may be specified */ - while (*p == ' ' || *p == '\t') p++; - *argptr = p; - - sym = 0; - i1 = 0; /* counter for the symbol array */ - t = SYMBOL_TYPE (sym_class); - sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*)); - physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*)); - - if (destructor_name_p (copy, t)) - { - /* destructors are a special case. */ - struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0); - int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1; - phys_name = TYPE_FN_FIELD_PHYSNAME (f, len); - physnames[i1] = (char *)alloca (strlen (phys_name) + 1); - strcpy (physnames[i1], phys_name); - sym_arr[i1] = lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class), VAR_NAMESPACE, 0); - if (sym_arr[i1]) i1++; - } - else while (t) - { - class_name = TYPE_NAME (t); - /* Ignore this class if it doesn't have a name. - This prevents core dumps, but is just a workaround - because we might not find the function in - certain cases, such as - struct D {virtual int f();} - struct C : D {virtual int g();} - (in this case g++ 1.35.1- does not put out a name - for D as such, it defines type 19 (for example) in - the same stab as C, and then does a - .stabs "D:T19" and a .stabs "D:t19". - Thus - "break C::f" should not be looking for field f in - the class named D, - but just for the field f in the baseclasses of C - (no matter what their names). - - However, I don't know how to replace the code below - that depends on knowing the name of D. */ - if (class_name) - { - /* We just want the class name. In the context - of C++, stripping off "struct " is always - sensible. */ - if (strncmp("struct ", class_name, 7) == 0) - class_name += 7; - if (strncmp("union ", class_name, 6) == 0) - class_name += 6; - - sym_class = lookup_symbol (class_name, 0, STRUCT_NAMESPACE, 0); - for (method_counter = TYPE_NFN_FIELDS (SYMBOL_TYPE (sym_class)) - 1; - method_counter >= 0; - --method_counter) - { - int field_counter; - struct fn_field *f = - TYPE_FN_FIELDLIST1 (SYMBOL_TYPE (sym_class), method_counter); - - method_name = TYPE_FN_FIELDLIST_NAME (SYMBOL_TYPE (sym_class), method_counter); - if (!strcmp (copy, method_name)) - /* Find all the fields with that name. */ - for (field_counter = TYPE_FN_FIELDLIST_LENGTH (SYMBOL_TYPE (sym_class), method_counter) - 1; - field_counter >= 0; - --field_counter) - { - phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); - physnames[i1] = (char*) alloca (strlen (phys_name) + 1); - strcpy (physnames[i1], phys_name); - sym_arr[i1] = lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class), VAR_NAMESPACE, 0); - if (sym_arr[i1]) i1++; - } - } - } - if (TYPE_N_BASECLASSES (t)) - t = TYPE_BASECLASS(t, 1); - else - break; - } - - if (i1 == 1) - { - /* There is exactly one field with that name. */ - sym = sym_arr[0]; - - if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) - { - /* Arg is the name of a function */ - pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET; - if (funfirstline) - SKIP_PROLOGUE (pc); - values.sals = (struct symtab_and_line *)malloc (sizeof (struct symtab_and_line)); - values.nelts = 1; - values.sals[0] = find_pc_line (pc, 0); - values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc; - } - else - { - values.nelts = 0; - } - return values; - } - if (i1 > 0) - { - /* There is more than one field with that name - (overloaded). Ask the user which one to use. */ - return decode_line_2 (argptr, sym_arr, physnames, - i1, funfirstline); - } - else - error ("that class does not have any method named %s",copy); - } - else - error("no class, struct, or union named %s", copy ); - } - /* end of C++ */ - - - /* Extract the file name. */ - p1 = p; - while (p != *argptr && p[-1] == ' ') --p; - copy = (char *) alloca (p - *argptr + 1); - bcopy (*argptr, copy, p - *argptr); - copy[p - *argptr] = 0; - - /* Find that file's data. */ - s = lookup_symtab (copy); - if (s == 0) - { - if (symtab_list == 0 && partial_symtab_list == 0) - error ("No symbol table is loaded. Use the \"symbol-file\" command."); - error ("No source file named %s.", copy); - } - - /* Discard the file name from the arg. */ - p = p1 + 1; - while (*p == ' ' || *p == '\t') p++; - *argptr = p; - } - - /* S is specified file's symtab, or 0 if no file specified. - arg no longer contains the file name. */ - - /* Check whether arg is all digits (and sign) */ - - p = *argptr; - if (*p == '-' || *p == '+') p++; - while (*p >= '0' && *p <= '9') - p++; - - if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ',')) - { - /* We found a token consisting of all digits -- at least one digit. */ - enum sign {none, plus, minus} sign = none; - - /* This is where we need to make sure that we have good defaults. - We must guarrantee that this section of code is never executed - when we are called with just a function name, since - select_source_symtab calls us with such an argument */ - - if (s == 0 && default_symtab == 0) - { - if (symtab_list == 0 && partial_symtab_list == 0) - error ("No symbol table is loaded. Use the \"symbol-file\" command."); - select_source_symtab (0); - default_symtab = current_source_symtab; - default_line = current_source_line; - } - - if (**argptr == '+') - sign = plus, (*argptr)++; - else if (**argptr == '-') - sign = minus, (*argptr)++; - value.line = atoi (*argptr); - switch (sign) - { - case plus: - if (p == *argptr) - value.line = 5; - if (s == 0) - value.line = default_line + value.line; - break; - case minus: - if (p == *argptr) - value.line = 15; - if (s == 0) - value.line = default_line - value.line; - else - value.line = 1; - break; - } - - while (*p == ' ' || *p == '\t') p++; - *argptr = p; - if (s == 0) - s = default_symtab; - value.symtab = s; - value.pc = 0; - values.sals = (struct symtab_and_line *)malloc (sizeof (struct symtab_and_line)); - values.sals[0] = value; - values.nelts = 1; - return values; - } - - /* Arg token is not digits => try it as a function name - Find the next token (everything up to end or next whitespace). */ - p = *argptr; - while (*p && *p != ' ' && *p != '\t' && *p != ',') p++; - copy = (char *) alloca (p - *argptr + 1); - bcopy (*argptr, copy, p - *argptr); - copy[p - *argptr] = 0; - while (*p == ' ' || *p == '\t') p++; - *argptr = p; - - /* Look up that token as a function. - If file specified, use that file's per-file block to start with. */ - - if (s == 0) - /* use current file as default if none is specified. */ - s = default_symtab; - - sym = lookup_symbol (copy, s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), 1) : 0, - VAR_NAMESPACE, 0); - - if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) - { - /* Arg is the name of a function */ - pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET; - if (funfirstline) - SKIP_PROLOGUE (pc); - value = find_pc_line (pc, 0); -#ifdef PROLOGUE_FIRSTLINE_OVERLAP - /* Convex: no need to suppress code on first line, if any */ - value.pc = pc; -#else - value.pc = (value.end && value.pc != pc) ? value.end : pc; -#endif - values.sals = (struct symtab_and_line *)malloc (sizeof (struct symtab_and_line)); - values.sals[0] = value; - values.nelts = 1; - return values; - } - - if (sym) - error ("%s is not a function.", copy); - - if (symtab_list == 0 && partial_symtab_list == 0) - error ("No symbol table is loaded. Use the \"symbol-file\" command."); - - if ((i = lookup_misc_func (copy)) >= 0) - { - value.symtab = 0; - value.line = 0; - value.pc = misc_function_vector[i].address + FUNCTION_START_OFFSET; - if (funfirstline) - SKIP_PROLOGUE (value.pc); - values.sals = (struct symtab_and_line *)malloc (sizeof (struct symtab_and_line)); - values.sals[0] = value; - values.nelts = 1; - return values; - } - - error ("Function %s not defined.", copy); -} - -struct symtabs_and_lines -decode_line_spec (string, funfirstline) - char *string; - int funfirstline; -{ - struct symtabs_and_lines sals; - if (string == 0) - error ("Empty line specification."); - sals = decode_line_1 (&string, funfirstline, - current_source_symtab, current_source_line); - if (*string) - error ("Junk at end of line specification: %s", string); - return sals; -} - -/* Given a list of NELTS symbols in sym_arr (with corresponding - mangled names in physnames), return a list of lines to operate on - (ask user if necessary). */ -struct symtabs_and_lines -decode_line_2 (argptr, sym_arr, physnames, nelts, funfirstline) - char **argptr; - struct symbol *sym_arr[]; - char *physnames[]; - int nelts; - int funfirstline; -{ - char *getenv(); - struct symtabs_and_lines values, return_values; - register CORE_ADDR pc; - char *args, *arg1, *command_line_input (); - int i; - char *prompt; - - values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line)); - return_values.sals = (struct symtab_and_line *) malloc (nelts * sizeof(struct symtab_and_line)); - - i = 0; - printf("[0] cancel\n[1] all\n"); - while (i < nelts) - { - if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK) - { - /* Arg is the name of a function */ - pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i])) - + FUNCTION_START_OFFSET; - if (funfirstline) - SKIP_PROLOGUE (pc); - values.sals[i] = find_pc_line (pc, 0); - values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ? values.sals[i].end : pc; - printf("[%d] file:%s; line number:%d\n", - (i+2), values.sals[i].symtab->filename, values.sals[i].line); - } - else printf ("?HERE\n"); - i++; - } - - if ((prompt = getenv ("PS2")) == NULL) - { - prompt = ">"; - } - printf("%s ",prompt); - fflush(stdout); - - args = command_line_input (0, 0); - - if (args == 0) - error_no_arg ("one or more choice numbers"); - - i = 0; - while (*args) - { - int num; - - arg1 = args; - while (*arg1 >= '0' && *arg1 <= '9') arg1++; - if (*arg1 && *arg1 != ' ' && *arg1 != '\t') - error ("Arguments must be choice numbers."); - - num = atoi (args); - - if (num == 0) - error ("cancelled"); - else if (num == 1) - { - bcopy (values.sals, return_values.sals, (nelts * sizeof(struct symtab_and_line))); - return_values.nelts = nelts; - return return_values; - } - - if (num > nelts + 2) - { - printf ("No choice number %d.\n", num); - } - else - { - num -= 2; - if (values.sals[num].pc) - { - return_values.sals[i++] = values.sals[num]; - values.sals[num].pc = 0; - } - else - { - printf ("duplicate request for %d ignored.\n", num); - } - } - - args = arg1; - while (*args == ' ' || *args == '\t') args++; - } - return_values.nelts = i; - return return_values; -} - -/* hash a symbol ("hashpjw" from Aho, Sethi & Ullman, p.436) */ - -int -hash_symbol(str) - register char *str; -{ - register unsigned int h = 0, g; - register unsigned char c; - - while (c = *(unsigned char *)str++) { - h = (h << 4) + c; - if (g = h & 0xf0000000) { - h = h ^ (g >> 24); - h = h ^ g; - } - } - return ((int)h); -} - -/* Return the index of misc function named NAME. */ - -int -lookup_misc_func (name) - register char *name; -{ - register int i = hash_symbol(name) & (MISC_FUNC_HASH_SIZE - 1); - - if (misc_function_vector == 0) - error("No symbol file"); - - i = misc_function_hash_tab[i]; - while (i >= 0) - { - if (strcmp(misc_function_vector[i].name, name) == 0) - break; - i = misc_function_vector[i].next; - } - return (i); -} - -/* - * Slave routine for sources_info. Force line breaks at ,'s. - */ -static void -output_source_filename (name, next) -char *name; -int next; -{ - static int column = 0; - - if (column != 0 && column + strlen (name) >= 70) - { - printf_filtered ("\n"); - column = 0; - } - else if (column != 0) - { - printf_filtered (" "); - column++; - } - printf_filtered ("%s", name); - column += strlen (name); - if (next) - { - printf_filtered (","); - column++; - } - - if (!next) column = 0; -} - -static void -sources_info () -{ - register struct symtab *s; - register struct partial_symtab *ps; - register int column = 0; - - if (symtab_list == 0 && partial_symtab_list == 0) - { - printf ("No symbol table is loaded.\n"); - return; - } - - printf_filtered ("Source files for which symbols have been read in:\n\n"); - - for (s = symtab_list; s; s = s->next) - output_source_filename (s->filename, s->next); - printf_filtered ("\n\n"); - - printf_filtered ("Source files for which symbols will be read in on demand:\n\n"); - - for (ps = partial_symtab_list; ps; ps = ps->next) - if (!ps->readin) - output_source_filename (ps->filename, ps->next); - printf_filtered ("\n"); -} - -/* List all symbols (if REGEXP is 0) or all symbols matching REGEXP. - If CLASS is zero, list all symbols except functions and type names. - If CLASS is 1, list only functions. - If CLASS is 2, list only type names. */ - -static void sort_block_syms (); - -static void -list_symbols (regexp, class) - char *regexp; - int class; -{ - register struct symtab *s; - register struct partial_symtab *ps; - register struct blockvector *bv; - struct blockvector *prev_bv = 0; - register struct block *b; - register int i, j; - register struct symbol *sym; - struct partial_symbol *psym, *bound; - char *val; - static char *classnames[] - = {"variable", "function", "type", "method"}; - int print_count = 0; - int found_in_file = 0; - - if (regexp) - if (val = (char *) re_comp (regexp)) - error ("Invalid regexp: %s", val); - - /* Search through the partial_symtab_list *first* for all symbols - matching the regexp. That way we don't have to reproduce all of - the machinery below. */ - for (psym = global_psymbols.list, bound = global_psymbols.next; ; - psym = static_psymbols.list, bound = static_psymbols.next) - { - for (; psym < bound; ++psym) - { - if (psym->pst->readin) - continue; - - QUIT; - /* If it would match (logic taken from loop below) - load the file and go on to the next one */ - if ((regexp == 0 || re_exec (SYMBOL_NAME (psym))) - && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF - && SYMBOL_CLASS (psym) != LOC_BLOCK) - || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK) - || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF) - || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK))) - psymtab_to_symtab(psym->pst); - } - if (psym == static_psymbols.next) - break; - } - - /* Printout here so as to get after the "Reading in symbols" - messages which will be generated above. */ - printf_filtered (regexp - ? "All %ss matching regular expression \"%s\":\n" - : "All defined %ss:\n", - classnames[class], - regexp); - - /* Here, *if* the class is correct (function only, right now), we - should search through the misc function vector for symbols that - match and call find_pc_psymtab on them. If find_pc_psymtab returns - 0, don't worry about it (already read in or no debugging info). */ - - if (class == 1) - { - for (i = 0; i < misc_function_count; i++) - if (regexp == 0 || re_exec (misc_function_vector[i].name)) - { - ps = find_pc_psymtab (misc_function_vector[i].address); - if (ps && !ps->readin) - psymtab_to_symtab (ps); - } - } - - for (s = symtab_list; s; s = s->next) - { - found_in_file = 0; - bv = BLOCKVECTOR (s); - /* Often many files share a blockvector. - Scan each blockvector only once so that - we don't get every symbol many times. - It happens that the first symtab in the list - for any given blockvector is the main file. */ - if (bv != prev_bv) - for (i = 0; i < 2; i++) - { - b = BLOCKVECTOR_BLOCK (bv, i); - /* Skip the sort if this block is always sorted. */ - if (!BLOCK_SHOULD_SORT (b)) - sort_block_syms (b); - for (j = 0; j < BLOCK_NSYMS (b); j++) - { - QUIT; - sym = BLOCK_SYM (b, j); - if ((regexp == 0 || re_exec (SYMBOL_NAME (sym))) - && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF - && SYMBOL_CLASS (sym) != LOC_BLOCK) - || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK) - || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF) - || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK))) - { - if (!found_in_file) - { - printf_filtered ("\nFile %s:\n", s->filename); - print_count += 2; - } - found_in_file = 1; - if (class != 2 && i == 1) - printf_filtered ("static "); - if (class == 2 - && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE) - printf_filtered ("typedef "); - - if (class < 3) - { - type_print (SYMBOL_TYPE (sym), - (SYMBOL_CLASS (sym) == LOC_TYPEDEF - ? "" : SYMBOL_NAME (sym)), - stdout, 0); - - if (class == 2 - && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE - && (TYPE_NAME ((SYMBOL_TYPE (sym))) == 0 - || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (sym))), - SYMBOL_NAME (sym)))) - printf_filtered (" %s", SYMBOL_NAME (sym)); - - printf_filtered (";\n"); - } - else - { -# if 0 - char buf[1024]; - type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0); - type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0); - sprintf (buf, " %s::", TYPE_NAME (t)); - type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout); -# endif - } - } - } - } - prev_bv = bv; - } -} - -static void -variables_info (regexp) - char *regexp; -{ - list_symbols (regexp, 0); -} - -static void -functions_info (regexp) - char *regexp; -{ - list_symbols (regexp, 1); -} - -static void -types_info (regexp) - char *regexp; -{ - list_symbols (regexp, 2); -} - -#if 0 -/* Tiemann says: "info methods was never implemented." */ -static void -methods_info (regexp) - char *regexp; -{ - list_symbols (regexp, 3); -} -#endif /* 0 */ - -/* Call sort_block_syms to sort alphabetically the symbols of one block. */ - -static int -compare_symbols (s1, s2) - struct symbol **s1, **s2; -{ - /* Names that are less should come first. */ - register int namediff = strcmp (SYMBOL_NAME (*s1), SYMBOL_NAME (*s2)); - if (namediff != 0) return namediff; - /* For symbols of the same name, registers should come first. */ - return ((SYMBOL_CLASS (*s2) == LOC_REGISTER) - - (SYMBOL_CLASS (*s1) == LOC_REGISTER)); -} - -static void -sort_block_syms (b) - register struct block *b; -{ - qsort (&BLOCK_SYM (b, 0), BLOCK_NSYMS (b), - sizeof (struct symbol *), compare_symbols); -} - -/* Initialize the standard C scalar types. */ - -static -struct type * -init_type (code, length, uns, name) - enum type_code code; - int length, uns; - char *name; -{ - register struct type *type; - - type = (struct type *) xmalloc (sizeof (struct type)); - bzero (type, sizeof *type); - TYPE_MAIN_VARIANT (type) = type; - TYPE_CODE (type) = code; - TYPE_LENGTH (type) = length; - TYPE_FLAGS (type) = uns ? TYPE_FLAG_UNSIGNED : 0; - TYPE_FLAGS (type) |= TYPE_FLAG_PERM; - TYPE_NFIELDS (type) = 0; - TYPE_NAME (type) = name; - - /* C++ fancies. */ - TYPE_NFN_FIELDS (type) = 0; - TYPE_N_BASECLASSES (type) = 0; - TYPE_BASECLASSES (type) = 0; - return type; -} - -/* Return Nonzero if block a is lexically nested within block b, - or if a and b have the same pc range. - Return zero otherwise. */ -int -contained_in (a, b) - struct block *a, *b; -{ - if (!a || !b) - return 0; - return a->startaddr >= b->startaddr && a->endaddr <= b->endaddr; -} - - -/* Helper routine for make_symbol_completion_list. */ - -int return_val_size, return_val_index; -char **return_val; - -void -completion_list_add_symbol (symname) - char *symname; -{ - if (return_val_index + 3 > return_val_size) - return_val = - (char **)xrealloc (return_val, - (return_val_size *= 2) * sizeof (char *)); - - return_val[return_val_index] = - (char *)xmalloc (1 + strlen (symname)); - - strcpy (return_val[return_val_index], symname); - - return_val[++return_val_index] = (char *)NULL; -} - -/* Return a NULL terminated array of all symbols (regardless of class) which - begin by matching TEXT. If the answer is no symbols, then the return value - is an array which contains only a NULL pointer. - - Problem: All of the symbols have to be copied because readline - frees them. I'm not going to worry about this; hopefully there - won't be that many. */ - -char ** -make_symbol_completion_list (text) - char *text; -{ - register struct symtab *s; - register struct partial_symtab *ps; - register struct blockvector *bv; - struct blockvector *prev_bv = 0; - register struct block *b, *surrounding_static_block; - extern struct block *get_selected_block (); - register int i, j; - register struct symbol *sym; - struct partial_symbol *psym; - - int text_len = strlen (text); - return_val_size = 100; - return_val_index = 0; - return_val = - (char **)xmalloc ((1 + return_val_size) *sizeof (char *)); - return_val[0] = (char *)NULL; - - /* Look through the partial symtabs for all symbols which begin - by matching TEXT. Add each one that you find to the list. */ - - for (ps = partial_symtab_list; ps; ps = ps->next) - { - /* If the psymtab's been read in we'll get it when we search - through the blockvector. */ - if (ps->readin) continue; - - for (psym = global_psymbols.list + ps->globals_offset; - psym < (global_psymbols.list + ps->globals_offset - + ps->n_global_syms); - psym++) - { - QUIT; /* If interrupted, then quit. */ - if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0)) - completion_list_add_symbol (SYMBOL_NAME (psym)); - } - - for (psym = static_psymbols.list + ps->statics_offset; - psym < (static_psymbols.list + ps->statics_offset - + ps->n_static_syms); - psym++) - { - QUIT; - if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0)) - completion_list_add_symbol (SYMBOL_NAME (psym)); - } - } - - /* At this point scan through the misc function vector and add each - symbol you find to the list. Eventually we want to ignore - anything that isn't a text symbol (everything else will be - handled by the psymtab code above). */ - - for (i = 0; i < misc_function_count; i++) - if (!strncmp (text, misc_function_vector[i].name, text_len)) - completion_list_add_symbol (misc_function_vector[i].name); - - /* Search upwards from currently selected frame (so that we can - complete on local vars. */ - for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b)) - { - if (!BLOCK_SUPERBLOCK (b)) - surrounding_static_block = b; /* For elmin of dups */ - - /* Also catch fields of types defined in this places which - match our text string. Only complete on types visible - from current context. */ - for (i = 0; i < BLOCK_NSYMS (b); i++) - { - register struct symbol *sym = BLOCK_SYM (b, i); - - if (!strncmp (SYMBOL_NAME (sym), text, text_len)) - completion_list_add_symbol (SYMBOL_NAME (sym)); - - if (SYMBOL_CLASS (sym) == LOC_TYPEDEF) - { - struct type *t = SYMBOL_TYPE (sym); - enum type_code c = TYPE_CODE (t); - - if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT) - for (j = 0; j < TYPE_NFIELDS (t); j++) - if (TYPE_FIELD_NAME (t, j) && - !strncmp (TYPE_FIELD_NAME (t, j), text, text_len)) - completion_list_add_symbol (TYPE_FIELD_NAME (t, j)); - } - } - } - - /* Go through the symtabs and check the externs and statics for - symbols which match. */ - - for (s = symtab_list; s; s = s->next) - { - struct block *b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), 0); - - for (i = 0; i < BLOCK_NSYMS (b); i++) - if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len)) - completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i))); - } - - for (s = symtab_list; s; s = s->next) - { - struct block *b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), 1); - - /* Don't do this block twice. */ - if (b == surrounding_static_block) continue; - - for (i = 0; i < BLOCK_NSYMS (b); i++) - if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len)) - completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i))); - } - - return (return_val); -} - -void -_initialize_symtab () -{ - add_info ("variables", variables_info, - "All global and static variable names, or those matching REGEXP."); - add_info ("functions", functions_info, - "All function names, or those matching REGEXP."); - add_info ("types", types_info, - "All types names, or those matching REGEXP."); -#if 0 - add_info ("methods", methods_info, - "All method names, or those matching REGEXP::REGEXP.\n\ -If the class qualifier is ommited, it is assumed to be the current scope.\n\ -If the first REGEXP is ommited, then all methods matching the second REGEXP\n\ -are listed."); -#endif - add_info ("sources", sources_info, - "Source files in the program."); - - obstack_init (symbol_obstack); - obstack_init (psymbol_obstack); - - builtin_type_void = init_type (TYPE_CODE_VOID, 1, 0, "void"); - - builtin_type_float = init_type (TYPE_CODE_FLT, sizeof (float), 0, "float"); - builtin_type_double = init_type (TYPE_CODE_FLT, sizeof (double), 0, "double"); - - builtin_type_char = init_type (TYPE_CODE_INT, sizeof (char), 0, "char"); - builtin_type_short = init_type (TYPE_CODE_INT, sizeof (short), 0, "short"); - builtin_type_long = init_type (TYPE_CODE_INT, sizeof (long), 0, "long"); - builtin_type_int = init_type (TYPE_CODE_INT, sizeof (int), 0, "int"); - - builtin_type_unsigned_char = init_type (TYPE_CODE_INT, sizeof (char), 1, "unsigned char"); - builtin_type_unsigned_short = init_type (TYPE_CODE_INT, sizeof (short), 1, "unsigned short"); - builtin_type_unsigned_long = init_type (TYPE_CODE_INT, sizeof (long), 1, "unsigned long"); - builtin_type_unsigned_int = init_type (TYPE_CODE_INT, sizeof (int), 1, "unsigned int"); -#ifdef LONG_LONG - builtin_type_long_long = - init_type (TYPE_CODE_INT, sizeof (long long), 0, "long long"); - builtin_type_unsigned_long_long = - init_type (TYPE_CODE_INT, sizeof (long long), 1, "unsigned long long"); -#endif -} - diff --git a/gnu/usr.bin/gdb/symtab.h b/gnu/usr.bin/gdb/symtab.h deleted file mode 100644 index fefed60..0000000 --- a/gnu/usr.bin/gdb/symtab.h +++ /dev/null @@ -1,384 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - * - * @(#)symtab.h 6.3 (Berkeley) 5/8/91 - */ - -/* Symbol table definitions for GDB. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include - -/* An obstack to hold objects that should be freed - when we load a new symbol table. - This includes the symbols made by dbxread - and the types that are not permanent. */ - -extern struct obstack *symbol_obstack; -extern struct obstack *psymbol_obstack; - -/* Some definitions and declarations to go with use of obstacks. */ -#define obstack_chunk_alloc xmalloc -#define obstack_chunk_free free -extern char *xmalloc (); -extern void free (); - -/* gdb can know one or several symbol tables at the same time; - the ultimate intent is to have one for each separately-compiled module. - Each such symbol table is recorded by a struct symtab, and they - are all chained together. */ - -/* In addition, gdb can record any number of miscellaneous undebuggable - functions' addresses. In a system that appends _ to function names, - the _'s are removed from the names stored in this table. */ - -/* Actually, the misc function list is used to store *all* of the - global symbols (text, data, bss, and abs). It is sometimes used - to figure out what symtabs to read in. The "type" field appears - never to be used. */ - -enum misc_function_type {mf_unknown = 0, mf_text, mf_data, mf_bss, mf_abs}; - -struct misc_function -{ - char *name; - CORE_ADDR address; - int next; /* index of next in this hash bucket */ - unsigned char type; /* Really enum misc_function_type. */ -}; - -/* Address and length of the vector recording all misc function names/addresses. */ - -struct misc_function *misc_function_vector; -int misc_function_count; -#define MISC_FUNC_HASH_SIZE (2048) -int misc_function_hash_tab[MISC_FUNC_HASH_SIZE]; - -#include "symseg.h" - -/* Each source file is represented by a struct symtab. */ -/* These objects are chained through the `next' field. */ - -struct symtab - { - /* Chain of all existing symtabs. */ - struct symtab *next; - /* List of all symbol scope blocks for this symtab. */ - struct blockvector *blockvector; - /* Table mapping core addresses to line numbers for this file. */ - struct linetable *linetable; - /* Vector containing all types defined for this symtab. */ - struct typevector *typevector; - /* Name of this source file. */ - char *filename; - /* This component says how to free the data we point to: - free_contents => do a tree walk and free each object. - free_nothing => do nothing; some other symtab will free - the data this one uses. - free_linetable => free just the linetable. */ - enum free_code {free_nothing, free_contents, free_linetable} - free_code; - /* Pointer to one block of storage to be freed, if nonzero. */ - char *free_ptr; - /* Total number of lines found in source file. */ - int nlines; - /* Array mapping line number to character position. */ - int *line_charpos; - /* Language of this source file. */ - enum language language; - /* String of version information. May be zero. */ - char *version; - /* String of compilation information. May be zero. */ - char *compilation; - /* Offset within loader symbol table - of first local symbol for this file. */ - int ldsymoff; - /* Full name of file as found by searching the source path. - 0 if not yet known. */ - char *fullname; - }; - -/* - * Each source file that has not been fully read in is represented by - * a partial_symtab. This contains the information on where in the - * executable the debugging symbols for a specific file are, and a - * list of names of global symbols which are located in this file. - */ -struct partial_symtab -{ - /* Chain of all existing partial symtabs. */ - struct partial_symtab *next; - /* Name of the source file which this partial_symtab defines */ - char *filename; - /* Offset within loader symbol table of first local symbol for this - file and length (in bytes) of the section of the symbol table - devoted to this file's symbols (actually, the section bracketed - may contain more than just this files symbols - If ldsymlen is 0, the only reason for this things existence is - the dependency list below. Nothing else will happen when it is - read in. */ - int ldsymoff, ldsymlen; - /* Range of text addresses covered by this file; texthigh is the - beginning of the next section. */ - int textlow, texthigh; - /* Non-zero if the symtab corresponding to this psymtab has been - readin */ - unsigned char readin; - /* Array of pointers to all of the partial_symtab s which this one - depends one. Since this array can only be set to previous or - the current (?) psymtab, this dependency tree is guarranteed not - to have any loops. */ - struct partial_symtab **dependencies; - int number_of_dependencies; - /* Global symbol list. This list will be sorted after readin to - improve access. Binary search will be the usual method of - finding a symbol within it. globals_offset is an integer offset - within ps_globals */ - int globals_offset, n_global_syms; - /* Static symbol list. This list will *not* be sorted after readin; - to find a symbol in it, exhaustive search must be used. This is - reasonable because searches through this list will eventually - lead to either the read in of a files symbols for real (assumed - to take a *lot* of time; check) or an error (and we don't care - how long errors take). */ - int statics_offset, n_static_syms; -}; - -/* This is the list of struct symtab's that gdb considers current. */ - -struct symtab *symtab_list; - -/* This is the list of struct partial_symtab's that gdb may need to access */ - -struct partial_symtab *partial_symtab_list; - -/* This symtab variable specifies the current file for printing source lines */ - -struct symtab *current_source_symtab; - -/* This is the next line to print for listing source lines. */ - -int current_source_line; - -#define BLOCKLIST(symtab) (symtab)->blockvector -#define BLOCKVECTOR(symtab) (symtab)->blockvector - -#define TYPEVECTOR(symtab) (symtab)->typevector - -#define LINELIST(symtab) (symtab)->linetable -#define LINETABLE(symtab) (symtab)->linetable - -/* Macros normally used to access components of symbol table structures. */ - -#define BLOCKLIST_NBLOCKS(blocklist) (blocklist)->nblocks -#define BLOCKLIST_BLOCK(blocklist,n) (blocklist)->block[n] -#define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks -#define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n] - -#define TYPEVECTOR_NTYPES(typelist) (typelist)->length -#define TYPEVECTOR_TYPE(typelist,n) (typelist)->type[n] - -#define BLOCK_START(bl) (bl)->startaddr -#define BLOCK_END(bl) (bl)->endaddr -#define BLOCK_NSYMS(bl) (bl)->nsyms -#define BLOCK_SYM(bl, n) (bl)->sym[n] -#define BLOCK_FUNCTION(bl) (bl)->function -#define BLOCK_SUPERBLOCK(bl) (bl)->superblock -#define BLOCK_GCC_COMPILED(bl) (bl)->gcc_compile_flag - -/* Nonzero if symbols of block BL should be sorted alphabetically. */ -#define BLOCK_SHOULD_SORT(bl) ((bl)->nsyms >= 40) - -#define SYMBOL_NAME(symbol) (symbol)->name -#define SYMBOL_NAMESPACE(symbol) (symbol)->namespace -#define SYMBOL_CLASS(symbol) (symbol)->class -#define SYMBOL_VALUE(symbol) (symbol)->value.value -#define SYMBOL_VALUE_BYTES(symbol) (symbol)->value.bytes -#define SYMBOL_BLOCK_VALUE(symbol) (symbol)->value.block -#define SYMBOL_TYPE(symbol) (symbol)->type - -/* Some macros for bitfields. */ -#define B_SET(a,x) (a[x>>5] |= (1 << (x&31))) -#define B_CLR(a,x) (a[x>>5] &= ~(1 << (x&31))) -#define B_TST(a,x) (a[x>>5] & (1 << (x&31))) - -#define TYPE_NAME(thistype) (thistype)->name -#define TYPE_TARGET_TYPE(thistype) (thistype)->target_type -#define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type -#define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type -#define TYPE_FUNCTION_TYPE(thistype) (thistype)->function_type -#define TYPE_MAIN_VARIANT(thistype) (thistype)->main_variant -#define TYPE_NEXT_VARIANT(thistype) (thistype)->next_variant -#define TYPE_LENGTH(thistype) (thistype)->length -#define TYPE_FLAGS(thistype) (thistype)->flags -#define TYPE_UNSIGNED(thistype) ((thistype)->flags & TYPE_FLAG_UNSIGNED) -#define TYPE_CODE(thistype) (thistype)->code -#define TYPE_NFIELDS(thistype) (thistype)->nfields -#define TYPE_FIELDS(thistype) (thistype)->fields -/* C++ */ -#define TYPE_VPTR_BASETYPE(thistype) (thistype)->vptr_basetype -#define TYPE_DOMAIN_TYPE(thistype) (thistype)->vptr_basetype -#define TYPE_VPTR_FIELDNO(thistype) (thistype)->vptr_fieldno -#define TYPE_FN_FIELDS(thistype) (thistype)->fn_fields -#define TYPE_NFN_FIELDS(thistype) (thistype)->nfn_fields -#define TYPE_NFN_FIELDS_TOTAL(thistype) (thistype)->nfn_fields_total -#define TYPE_BASECLASSES(thistype) (thistype)->baseclasses -#define TYPE_ARG_TYPES(thistype) (thistype)->arg_types -#define TYPE_BASECLASS(thistype,index) (thistype)->baseclasses[index] -#define TYPE_N_BASECLASSES(thistype) (thistype)->n_baseclasses -#define TYPE_VIA_PUBLIC(thistype) ((thistype)->flags & TYPE_FLAG_VIA_PUBLIC) -#define TYPE_VIA_VIRTUAL(thistype) ((thistype)->flags & TYPE_FLAG_VIA_VIRTUAL) - -#define TYPE_FIELD(thistype, n) (thistype)->fields[n] -#define TYPE_FIELD_TYPE(thistype, n) (thistype)->fields[n].type -#define TYPE_FIELD_NAME(thistype, n) (thistype)->fields[n].name -#define TYPE_FIELD_VALUE(thistype, n) (* (int*) &(thistype)->fields[n].type) -#define TYPE_FIELD_BITPOS(thistype, n) (thistype)->fields[n].bitpos -#define TYPE_FIELD_BITSIZE(thistype, n) (thistype)->fields[n].bitsize -#define TYPE_FIELD_PACKED(thistype, n) (thistype)->fields[n].bitsize - -#define TYPE_FIELD_PRIVATE_BITS(thistype) (thistype)->private_field_bits -#define TYPE_FIELD_PROTECTED_BITS(thistype) (thistype)->protected_field_bits -#define SET_TYPE_FIELD_PRIVATE(thistype, n) B_SET ((thistype)->private_field_bits, (n)) -#define SET_TYPE_FIELD_PROTECTED(thistype, n) B_SET ((thistype)->protected_field_bits, (n)) -#define TYPE_FIELD_PRIVATE(thistype, n) B_TST((thistype)->private_field_bits, (n)) -#define TYPE_FIELD_PROTECTED(thistype, n) B_TST((thistype)->protected_field_bits, (n)) - -#define TYPE_HAS_DESTRUCTOR(thistype) ((thistype)->flags & TYPE_FLAG_HAS_DESTRUCTOR) -#define TYPE_HAS_CONSTRUCTOR(thistype) ((thistype)->flags & TYPE_FLAG_HAS_CONSTRUCTOR) - -#define TYPE_FIELD_STATIC(thistype, n) ((thistype)->fields[n].bitpos == -1) -#define TYPE_FIELD_STATIC_PHYSNAME(thistype, n) ((char *)(thistype)->fields[n].bitsize) - -#define TYPE_FN_FIELDLISTS(thistype) (thistype)->fn_fieldlists -#define TYPE_FN_FIELDLIST(thistype, n) (thistype)->fn_fieldlists[n] -#define TYPE_FN_FIELDLIST1(thistype, n) (thistype)->fn_fieldlists[n].fn_fields -#define TYPE_FN_FIELDLIST_NAME(thistype, n) (thistype)->fn_fieldlists[n].name -#define TYPE_FN_FIELDLIST_LENGTH(thistype, n) (thistype)->fn_fieldlists[n].length - -#define TYPE_FN_FIELD(thistype, n) (thistype)[n] -#define TYPE_FN_FIELD_NAME(thistype, n) (thistype)[n].name -#define TYPE_FN_FIELD_TYPE(thistype, n) (thistype)[n].type -#define TYPE_FN_FIELD_ARGS(thistype, n) (thistype)[n].args -#define TYPE_FN_FIELD_PHYSNAME(thistype, n) (thistype)[n].physname -#define TYPE_FN_FIELD_VIRTUAL_P(thistype, n) ((thistype)[n].voffset < 0) -#define TYPE_FN_FIELD_STATIC_P(thistype, n) ((thistype)[n].voffset > 0) -#define TYPE_FN_FIELD_VOFFSET(thistype, n) ((thistype)[n].voffset-1) - -#define TYPE_FN_PRIVATE_BITS(thistype) (thistype).private_fn_field_bits -#define TYPE_FN_PROTECTED_BITS(thistype) (thistype).protected_fn_field_bits -#define SET_TYPE_FN_PRIVATE(thistype, n) B_SET ((thistype).private_fn_field_bits, n) -#define SET_TYPE_FN_PROTECTED(thistype, n) B_SET ((thistype).protected_fn_field_bits, n) -#define TYPE_FN_PRIVATE(thistype, n) B_TST ((thistype).private_fn_field_bits, n) -#define TYPE_FN_PROTECTED(thistype, n) B_TST ((thistype).protected_fn_field_bits, n) - -/* Functions that work on the objects described above */ - -extern struct symtab *lookup_symtab (); -extern struct symbol *lookup_symbol (); -extern struct type *lookup_typename (); -extern struct type *lookup_unsigned_typename (); -extern struct type *lookup_struct (); -extern struct type *lookup_union (); -extern struct type *lookup_enum (); -extern struct type *lookup_struct_elt_type (); -extern struct type *lookup_pointer_type (); -extern struct type *lookup_function_type (); -extern struct type *lookup_basetype_type (); -extern struct type *create_array_type (); -extern struct symbol *block_function (); -extern struct symbol *find_pc_function (); -extern int find_pc_partial_function (); -extern struct partial_symtab *find_pc_psymtab (); -extern struct symtab *find_pc_symtab (); -extern struct partial_symbol *find_pc_psymbol (); -extern int find_pc_misc_function (); - -/* C++ stuff. */ -extern struct type *lookup_reference_type (); -extern struct type *lookup_member_type (); -extern struct type *lookup_class (); -/* end of C++ stuff. */ - -extern struct type *builtin_type_void; -extern struct type *builtin_type_char; -extern struct type *builtin_type_short; -extern struct type *builtin_type_int; -extern struct type *builtin_type_long; -extern struct type *builtin_type_unsigned_char; -extern struct type *builtin_type_unsigned_short; -extern struct type *builtin_type_unsigned_int; -extern struct type *builtin_type_unsigned_long; -extern struct type *builtin_type_float; -extern struct type *builtin_type_double; - -#ifdef LONG_LONG -extern struct type *builtin_type_long_long; -extern struct type *builtin_type_unsigned_long_long; - -#ifndef BUILTIN_TYPE_LONGEST -#define BUILTIN_TYPE_LONGEST builtin_type_long_long -#endif - -#ifndef BUILTIN_TYPE_UNSIGNED_LONGEST -#define BUILTIN_TYPE_UNSIGNED_LONGEST builtin_type_unsigned_long_long -#endif - -#else /* LONG_LONG */ - -#ifndef BUILTIN_TYPE_LONGEST -#define BUILTIN_TYPE_LONGEST builtin_type_long -#endif - -#ifndef BUILTIN_TYPE_UNSIGNED_LONGEST -#define BUILTIN_TYPE_UNSIGNED_LONGEST builtin_type_unsigned_long -#endif - -#endif - -struct symtab_and_line -{ - struct symtab *symtab; - int line; - CORE_ADDR pc; - CORE_ADDR end; -}; - -struct symtabs_and_lines -{ - struct symtab_and_line *sals; - int nelts; -}; - -/* Given a pc value, return line number it is in. - Second arg nonzero means if pc is on the boundary - use the previous statement's line number. */ - -struct symtab_and_line find_pc_line (); - -/* Given a string, return the line specified by it. - For commands like "list" and "breakpoint". */ - -struct symtabs_and_lines decode_line_spec (); -struct symtabs_and_lines decode_line_spec_1 (); -struct symtabs_and_lines decode_line_1 (); diff --git a/gnu/usr.bin/gdb/utils.c b/gnu/usr.bin/gdb/utils.c deleted file mode 100644 index b03f2be..0000000 --- a/gnu/usr.bin/gdb/utils.c +++ /dev/null @@ -1,1096 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - * - * $Header: /home/cvs/386BSD/src/usr.bin/gdb/utils.c,v 1.1.1.1 1993/06/12 14:52:20 rgrimes Exp $; - */ - -#ifndef lint -static char sccsid[] = "@(#)utils.c 6.4 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* General utility routines for GDB, the GNU debugger. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "param.h" - -#include -#include -#include -#include -#include -#include -#include "defs.h" -#ifdef HAVE_TERMIO -#include -#endif - -/* If this definition isn't overridden by the header files, assume - that isatty and fileno exist on this system. */ -#ifndef ISATTY -#define ISATTY(FP) (isatty (fileno (FP))) -#endif - -extern FILE *instream; - -void error (); -void fatal (); - -/* Chain of cleanup actions established with make_cleanup, - to be executed if an error happens. */ - -static struct cleanup *cleanup_chain; - -/* Nonzero means a quit has been requested. */ - -int quit_flag; - -/* Nonzero means quit immediately if Control-C is typed now, - rather than waiting until QUIT is executed. */ - -int immediate_quit; - -/* Add a new cleanup to the cleanup_chain, - and return the previous chain pointer - to be passed later to do_cleanups or discard_cleanups. - Args are FUNCTION to clean up with, and ARG to pass to it. */ - -struct cleanup * -make_cleanup (function, arg) - void (*function) (); - int arg; -{ - register struct cleanup *new - = (struct cleanup *) xmalloc (sizeof (struct cleanup)); - register struct cleanup *old_chain = cleanup_chain; - - new->next = cleanup_chain; - new->function = function; - new->arg = arg; - cleanup_chain = new; - - return old_chain; -} - -/* Discard cleanups and do the actions they describe - until we get back to the point OLD_CHAIN in the cleanup_chain. */ - -void -do_cleanups (old_chain) - register struct cleanup *old_chain; -{ - register struct cleanup *ptr; - while ((ptr = cleanup_chain) != old_chain) - { - (*ptr->function) (ptr->arg); - cleanup_chain = ptr->next; - free (ptr); - } -} - -/* Discard cleanups, not doing the actions they describe, - until we get back to the point OLD_CHAIN in the cleanup_chain. */ - -void -discard_cleanups (old_chain) - register struct cleanup *old_chain; -{ - register struct cleanup *ptr; - while ((ptr = cleanup_chain) != old_chain) - { - cleanup_chain = ptr->next; - free (ptr); - } -} - -/* Set the cleanup_chain to 0, and return the old cleanup chain. */ -struct cleanup * -save_cleanups () -{ - struct cleanup *old_chain = cleanup_chain; - - cleanup_chain = 0; - return old_chain; -} - -/* Restore the cleanup chain from a previously saved chain. */ -void -restore_cleanups (chain) - struct cleanup *chain; -{ - cleanup_chain = chain; -} - -/* This function is useful for cleanups. - Do - - foo = xmalloc (...); - old_chain = make_cleanup (free_current_contents, &foo); - - to arrange to free the object thus allocated. */ - -void -free_current_contents (location) - char **location; -{ - free (*location); -} - -/* Generally useful subroutines used throughout the program. */ - -/* Like malloc but get error if no storage available. */ - -char * -xmalloc (size) - long size; -{ - register char *val = (char *) malloc (size); - if (!val) - fatal ("virtual memory exhausted.", 0); - return val; -} - -/* Like realloc but get error if no storage available. */ - -char * -xrealloc (ptr, size) - char *ptr; - long size; -{ - register char *val = (char *) realloc (ptr, size); - if (!val) - fatal ("virtual memory exhausted.", 0); - return val; -} - -/* Print the system error message for errno, and also mention STRING - as the file name for which the error was encountered. - Then return to command level. */ - -void -perror_with_name (string) - char *string; -{ - extern int sys_nerr; - extern char *sys_errlist[]; - extern int errno; - char *err; - char *combined; - - if (errno < sys_nerr) - err = sys_errlist[errno]; - else - err = "unknown error"; - - combined = (char *) alloca (strlen (err) + strlen (string) + 3); - strcpy (combined, string); - strcat (combined, ": "); - strcat (combined, err); - - error ("%s.", combined); -} - -/* Print the system error message for ERRCODE, and also mention STRING - as the file name for which the error was encountered. */ - -void -print_sys_errmsg (string, errcode) - char *string; - int errcode; -{ - extern int sys_nerr; - extern char *sys_errlist[]; - char *err; - char *combined; - - if (errcode < sys_nerr) - err = sys_errlist[errcode]; - else - err = "unknown error"; - - combined = (char *) alloca (strlen (err) + strlen (string) + 3); - strcpy (combined, string); - strcat (combined, ": "); - strcat (combined, err); - - printf ("%s.\n", combined); -} - -void -quit () -{ -#ifdef HAVE_TERMIO - ioctl (fileno (stdout), TCFLSH, 1); -#else /* not HAVE_TERMIO */ - ioctl (fileno (stdout), TIOCFLUSH, 0); -#endif /* not HAVE_TERMIO */ -#ifdef TIOCGPGRP - error ("Quit"); -#else - error ("Quit (expect signal %d when inferior is resumed)", SIGINT); -#endif /* TIOCGPGRP */ -} - -/* Control C comes here */ - -void -request_quit () -{ - extern int remote_debugging; - - quit_flag = 1; - -#ifdef USG - /* Restore the signal handler. */ - signal (SIGINT, request_quit); -#endif - - if (immediate_quit) - quit(); -} - -/* Print an error message and return to command level. - STRING is the error message, used as a fprintf string, - and ARG is passed as an argument to it. */ - -void -error (string, arg1, arg2, arg3) - char *string; - int arg1, arg2, arg3; -{ - terminal_ours (); /* Should be ok even if no inf. */ - fflush (stdout); - fprintf (stderr, string, arg1, arg2, arg3); - fprintf (stderr, "\n"); - return_to_top_level (); -} - -/* Print an error message and exit reporting failure. - This is for a error that we cannot continue from. - STRING and ARG are passed to fprintf. */ - -void -fatal (string, arg) - char *string; - int arg; -{ - fprintf (stderr, "gdb: "); - fprintf (stderr, string, arg); - fprintf (stderr, "\n"); - exit (1); -} - -/* Print an error message and exit, dumping core. - STRING is a printf-style control string, and ARG is a corresponding - argument. */ -void -fatal_dump_core (string, arg) - char *string; - int arg; -{ - /* "internal error" is always correct, since GDB should never dump - core, no matter what the input. */ - fprintf (stderr, "gdb internal error: "); - fprintf (stderr, string, arg); - fprintf (stderr, "\n"); - signal (SIGQUIT, SIG_DFL); - kill (getpid (), SIGQUIT); - /* We should never get here, but just in case... */ - exit (1); -} - -/* Make a copy of the string at PTR with SIZE characters - (and add a null character at the end in the copy). - Uses malloc to get the space. Returns the address of the copy. */ - -char * -savestring (ptr, size) - char *ptr; - int size; -{ - register char *p = (char *) xmalloc (size + 1); - bcopy (ptr, p, size); - p[size] = 0; - return p; -} - -char * -concat (s1, s2, s3) - char *s1, *s2, *s3; -{ - register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1; - register char *val = (char *) xmalloc (len); - strcpy (val, s1); - strcat (val, s2); - strcat (val, s3); - return val; -} - -void -print_spaces (n, file) - register int n; - register FILE *file; -{ - while (n-- > 0) - fputc (' ', file); -} - -/* Ask user a y-or-n question and return 1 iff answer is yes. - Takes three args which are given to printf to print the question. - The first, a control string, should end in "? ". - It should not say how to answer, because we do that. */ - -int -query (ctlstr, arg1, arg2) - char *ctlstr; -{ - register int answer; - - /* Automatically answer "yes" if input is not from a terminal. */ - if (!input_from_terminal_p ()) - return 1; - - while (1) - { - printf (ctlstr, arg1, arg2); - printf ("(y or n) "); - fflush (stdout); - answer = fgetc (stdin); - clearerr (stdin); /* in case of C-d */ - if (answer != '\n') - while (fgetc (stdin) != '\n') clearerr (stdin); - if (answer >= 'a') - answer -= 040; - if (answer == 'Y') - return 1; - if (answer == 'N') - return 0; - printf ("Please answer y or n.\n"); - } -} - -/* Parse a C escape sequence. STRING_PTR points to a variable - containing a pointer to the string to parse. That pointer - is updated past the characters we use. The value of the - escape sequence is returned. - - A negative value means the sequence \ newline was seen, - which is supposed to be equivalent to nothing at all. - - If \ is followed by a null character, we return a negative - value and leave the string pointer pointing at the null character. - - If \ is followed by 000, we return 0 and leave the string pointer - after the zeros. A value of 0 does not mean end of string. */ - -int -parse_escape (string_ptr) - char **string_ptr; -{ - register int c = *(*string_ptr)++; - switch (c) - { - case 'a': - return '\a'; - case 'b': - return '\b'; - case 'e': - return 033; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - case 'v': - return '\v'; - case '\n': - return -2; - case 0: - (*string_ptr)--; - return 0; - case '^': - c = *(*string_ptr)++; - if (c == '\\') - c = parse_escape (string_ptr); - if (c == '?') - return 0177; - return (c & 0200) | (c & 037); - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - { - register int i = c - '0'; - register int count = 0; - while (++count < 3) - { - if ((c = *(*string_ptr)++) >= '0' && c <= '7') - { - i *= 8; - i += c - '0'; - } - else - { - (*string_ptr)--; - break; - } - } - return i; - } - default: - return c; - } -} - -/* Print the character CH on STREAM as part of the contents - of a literal string whose delimiter is QUOTER. */ - -void -printchar (ch, stream, quoter) - unsigned char ch; - FILE *stream; - int quoter; -{ - register int c = ch; - if (c < 040 || c >= 0177) - switch (c) - { - case '\n': - fputs_filtered ("\\n", stream); - break; - case '\b': - fputs_filtered ("\\b", stream); - break; - case '\t': - fputs_filtered ("\\t", stream); - break; - case '\f': - fputs_filtered ("\\f", stream); - break; - case '\r': - fputs_filtered ("\\r", stream); - break; - case '\033': - fputs_filtered ("\\e", stream); - break; - case '\007': - fputs_filtered ("\\a", stream); - break; - default: - fprintf_filtered (stream, "\\%.3o", (unsigned int) c); - break; - } - else - { - if (c == '\\' || c == quoter) - fputs_filtered ("\\", stream); - fprintf_filtered (stream, "%c", c); - } -} - -static int lines_per_page, lines_printed, chars_per_line, chars_printed; - -/* Set values of page and line size. */ -static void -set_screensize_command (arg, from_tty) - char *arg; - int from_tty; -{ - char *p = arg; - char *p1; - int tolinesize = lines_per_page; - int tocharsize = chars_per_line; - - if (p == 0) - error_no_arg ("set screensize"); - - while (*p >= '0' && *p <= '9') - p++; - - if (*p && *p != ' ' && *p != '\t') - error ("Non-integral argument given to \"set screensize\"."); - - tolinesize = atoi (arg); - - while (*p == ' ' || *p == '\t') - p++; - - if (*p) - { - p1 = p; - while (*p1 >= '0' && *p1 <= '9') - p1++; - - if (*p1) - error ("Non-integral second argument given to \"set screensize\"."); - - tocharsize = atoi (p); - } - - lines_per_page = tolinesize; - chars_per_line = tocharsize; -} - -static void -instream_cleanup(stream) - FILE *stream; -{ - instream = stream; -} - -static void -prompt_for_continue () -{ - if (ISATTY(stdin) && ISATTY(stdout)) - { - struct cleanup *old_chain = make_cleanup(instream_cleanup, instream); - char *cp, *gdb_readline(); - - instream = stdin; - immediate_quit++; - if (cp = gdb_readline ("---Type to continue---")) - free(cp); - chars_printed = lines_printed = 0; - immediate_quit--; - do_cleanups(old_chain); - } -} - -/* Reinitialize filter; ie. tell it to reset to original values. */ - -void -reinitialize_more_filter () -{ - lines_printed = 0; - chars_printed = 0; -} - -static void -screensize_info (arg, from_tty) - char *arg; - int from_tty; -{ - if (arg) - error ("\"info screensize\" does not take any arguments."); - - if (!lines_per_page) - printf ("Output more filtering is disabled.\n"); - else - { - printf ("Output more filtering is enabled with\n"); - printf ("%d lines per page and %d characters per line.\n", - lines_per_page, chars_per_line); - } -} - -/* Like fputs but pause after every screenful. - Unlike fputs, fputs_filtered does not return a value. - It is OK for LINEBUFFER to be NULL, in which case just don't print - anything. - - Note that a longjmp to top level may occur in this routine - (since prompt_for_continue may do so) so this routine should not be - called when cleanups are not in place. */ - -void -fputs_filtered (linebuffer, stream) - char *linebuffer; - FILE *stream; -{ - char *lineptr; - - if (linebuffer == 0) - return; - - /* Don't do any filtering if it is disabled. */ - if (stream != stdout || !ISATTY(stdout) || lines_per_page == 0) - { - fputs (linebuffer, stream); - return; - } - - /* Go through and output each character. Show line extension - when this is necessary; prompt user for new page when this is - necessary. */ - - lineptr = linebuffer; - while (*lineptr) - { - /* Possible new page. */ - if (lines_printed >= lines_per_page - 1) - prompt_for_continue (); - - while (*lineptr && *lineptr != '\n') - { - /* Print a single line. */ - if (*lineptr == '\t') - { - putc ('\t', stream); - /* Shifting right by 3 produces the number of tab stops - we have already passed, and then adding one and - shifting left 3 advances to the next tab stop. */ - chars_printed = ((chars_printed >> 3) + 1) << 3; - lineptr++; - } - else - { - putc (*lineptr, stream); - chars_printed++; - lineptr++; - } - - if (chars_printed >= chars_per_line) - { - chars_printed = 0; - lines_printed++; - /* Possible new page. */ - if (lines_printed >= lines_per_page - 1) - prompt_for_continue (); - } - } - - if (*lineptr == '\n') - { - lines_printed++; - putc ('\n', stream); - lineptr++; - chars_printed = 0; - } - } -} - -/* fputs_demangled is a variant of fputs_filtered that - demangles g++ names.*/ - -void -fputs_demangled (linebuffer, stream, arg_mode) - char *linebuffer; - FILE *stream; -{ -#ifdef __STDC__ - extern char *cplus_demangle (const char *, int); -#else - extern char *cplus_demangle (); -#endif -#define SYMBOL_MAX 1024 - -#define SYMBOL_CHAR(c) (isascii(c) && (isalnum(c) || (c) == '_' || (c) == '$')) - - char buf[SYMBOL_MAX+1]; - char *p; - - if (linebuffer == NULL) - return; - - p = linebuffer; - - while ( *p != (char) 0 ) { - int i = 0; - - /* collect non-interesting characters into buf */ - while ( *p != (char) 0 && !SYMBOL_CHAR(*p) ) { - buf[i++] = *p; - p++; - } - if (i > 0) { - /* output the non-interesting characters without demangling */ - buf[i] = (char) 0; - fputs_filtered(buf, stream); - i = 0; /* reset buf */ - } - - /* and now the interesting characters */ - while (i < SYMBOL_MAX && *p != (char) 0 && SYMBOL_CHAR(*p) ) { - buf[i++] = *p; - p++; - } - buf[i] = (char) 0; - if (i > 0) { - char * result; - - if ( (result = cplus_demangle(buf, arg_mode)) != NULL ) { - fputs_filtered(result, stream); - free(result); - } - else { - fputs_filtered(buf, stream); - } - } - } -} - -/* Print ARG1, ARG2, and ARG3 on stdout using format FORMAT. If this - information is going to put the amount written since the last call - to INIIALIZE_MORE_FILTER or the last page break over the page size, - print out a pause message and do a gdb_readline to get the users - permision to continue. - - Unlike fprintf, this function does not return a value. - - Note that this routine has a restriction that the length of the - final output line must be less than 255 characters *or* it must be - less than twice the size of the format string. This is a very - arbitrary restriction, but it is an internal restriction, so I'll - put it in. This means that the %s format specifier is almost - useless; unless the caller can GUARANTEE that the string is short - enough, fputs_filtered should be used instead. - - Note also that a longjmp to top level may occur in this routine - (since prompt_for_continue may do so) so this routine should not be - called when cleanups are not in place. */ - -void -fprintf_filtered (stream, format, arg1, arg2, arg3, arg4, arg5, arg6) - FILE *stream; - char *format; - int arg1, arg2, arg3, arg4, arg5, arg6; -{ - static char *linebuffer = (char *) 0; - static int line_size; - int format_length = strlen (format); - int numchars; - - /* Allocated linebuffer for the first time. */ - if (!linebuffer) - { - linebuffer = (char *) xmalloc (255); - line_size = 255; - } - - /* Reallocate buffer to a larger size if this is necessary. */ - if (format_length * 2 > line_size) - { - line_size = format_length * 2; - - /* You don't have to copy. */ - free (linebuffer); - linebuffer = (char *) xmalloc (line_size); - } - - /* This won't blow up if the restrictions described above are - followed. */ - (void) sprintf (linebuffer, format, arg1, arg2, arg3, arg4, arg5, arg6); - - fputs_filtered (linebuffer, stream); -} - -void -printf_filtered (format, arg1, arg2, arg3, arg4, arg5, arg6) - char *format; - int arg1, arg2, arg3, arg4, arg5, arg6; -{ - fprintf_filtered (stdout, format, arg1, arg2, arg3, arg4, arg5, arg6); -} - -/* Print N spaces. */ -void -print_spaces_filtered (n, stream) - int n; - FILE *stream; -{ - register char *s = (char *) alloca (n + 1); - register char *t = s; - - while (n--) - *t++ = ' '; - *t = '\0'; - - fputs_filtered (s, stream); -} - - -#ifdef USG -bcopy (from, to, count) -char *from, *to; -{ - memcpy (to, from, count); -} - -bcmp (from, to, count) -{ - return (memcmp (to, from, count)); -} - -bzero (to, count) -char *to; -{ - while (count--) - *to++ = 0; -} - -getwd (buf) -char *buf; -{ - getcwd (buf, MAXPATHLEN); -} - -char * -index (s, c) - char *s; -{ - char *strchr (); - return strchr (s, c); -} - -char * -rindex (s, c) - char *s; -{ - char *strrchr (); - return strrchr (s, c); -} - -#ifndef USG -char *sys_siglist[32] = { - "SIG0", - "SIGHUP", - "SIGINT", - "SIGQUIT", - "SIGILL", - "SIGTRAP", - "SIGIOT", - "SIGEMT", - "SIGFPE", - "SIGKILL", - "SIGBUS", - "SIGSEGV", - "SIGSYS", - "SIGPIPE", - "SIGALRM", - "SIGTERM", - "SIGUSR1", - "SIGUSR2", - "SIGCLD", - "SIGPWR", - "SIGWIND", - "SIGPHONE", - "SIGPOLL", -}; -#endif - -/* Queue routines */ - -struct queue { - struct queue *forw; - struct queue *back; -}; - -insque (item, after) -struct queue *item; -struct queue *after; -{ - item->forw = after->forw; - after->forw->back = item; - - item->back = after; - after->forw = item; -} - -remque (item) -struct queue *item; -{ - item->forw->back = item->back; - item->back->forw = item->forw; -} -#endif /* USG */ - -#ifdef USG -/* There is too much variation in Sys V signal numbers and names, so - we must initialize them at runtime. */ -static char undoc[] = "(undocumented)"; - -char *sys_siglist[NSIG]; -#endif /* USG */ - -extern struct cmd_list_element *setlist; - -void -_initialize_utils () -{ - int i; - add_cmd ("screensize", class_support, set_screensize_command, - "Change gdb's notion of the size of the output screen.\n\ -The first argument is the number of lines on a page.\n\ -The second argument (optional) is the number of characters on a line.", - &setlist); - add_info ("screensize", screensize_info, - "Show gdb's current notion of the size of the output screen."); - - /* These defaults will be used if we are unable to get the correct - values from termcap. */ - lines_per_page = 24; - chars_per_line = 80; - /* Initialize the screen height and width from termcap. */ - { - int termtype = getenv ("TERM"); - - /* Positive means success, nonpositive means failure. */ - int status; - - /* 2048 is large enough for all known terminals, according to the - GNU termcap manual. */ - char term_buffer[2048]; - - if (termtype) - { - status = tgetent (term_buffer, termtype); - if (status > 0) - { - int val; - - val = tgetnum ("li"); - if (val >= 0) - lines_per_page = val; - else - /* The number of lines per page is not mentioned - in the terminal description. This probably means - that paging is not useful (e.g. emacs shell window), - so disable paging. */ - lines_per_page = 0; - - val = tgetnum ("co"); - if (val >= 0) - chars_per_line = val; - } - } - } - -#ifdef USG - /* Initialize signal names. */ - for (i = 0; i < NSIG; i++) - sys_siglist[i] = undoc; - -#ifdef SIGHUP - sys_siglist[SIGHUP ] = "SIGHUP"; -#endif -#ifdef SIGINT - sys_siglist[SIGINT ] = "SIGINT"; -#endif -#ifdef SIGQUIT - sys_siglist[SIGQUIT ] = "SIGQUIT"; -#endif -#ifdef SIGILL - sys_siglist[SIGILL ] = "SIGILL"; -#endif -#ifdef SIGTRAP - sys_siglist[SIGTRAP ] = "SIGTRAP"; -#endif -#ifdef SIGIOT - sys_siglist[SIGIOT ] = "SIGIOT"; -#endif -#ifdef SIGEMT - sys_siglist[SIGEMT ] = "SIGEMT"; -#endif -#ifdef SIGFPE - sys_siglist[SIGFPE ] = "SIGFPE"; -#endif -#ifdef SIGKILL - sys_siglist[SIGKILL ] = "SIGKILL"; -#endif -#ifdef SIGBUS - sys_siglist[SIGBUS ] = "SIGBUS"; -#endif -#ifdef SIGSEGV - sys_siglist[SIGSEGV ] = "SIGSEGV"; -#endif -#ifdef SIGSYS - sys_siglist[SIGSYS ] = "SIGSYS"; -#endif -#ifdef SIGPIPE - sys_siglist[SIGPIPE ] = "SIGPIPE"; -#endif -#ifdef SIGALRM - sys_siglist[SIGALRM ] = "SIGALRM"; -#endif -#ifdef SIGTERM - sys_siglist[SIGTERM ] = "SIGTERM"; -#endif -#ifdef SIGUSR1 - sys_siglist[SIGUSR1 ] = "SIGUSR1"; -#endif -#ifdef SIGUSR2 - sys_siglist[SIGUSR2 ] = "SIGUSR2"; -#endif -#ifdef SIGCLD - sys_siglist[SIGCLD ] = "SIGCLD"; -#endif -#ifdef SIGCHLD - sys_siglist[SIGCHLD ] = "SIGCHLD"; -#endif -#ifdef SIGPWR - sys_siglist[SIGPWR ] = "SIGPWR"; -#endif -#ifdef SIGTSTP - sys_siglist[SIGTSTP ] = "SIGTSTP"; -#endif -#ifdef SIGTTIN - sys_siglist[SIGTTIN ] = "SIGTTIN"; -#endif -#ifdef SIGTTOU - sys_siglist[SIGTTOU ] = "SIGTTOU"; -#endif -#ifdef SIGSTOP - sys_siglist[SIGSTOP ] = "SIGSTOP"; -#endif -#ifdef SIGXCPU - sys_siglist[SIGXCPU ] = "SIGXCPU"; -#endif -#ifdef SIGXFSZ - sys_siglist[SIGXFSZ ] = "SIGXFSZ"; -#endif -#ifdef SIGVTALRM - sys_siglist[SIGVTALRM ] = "SIGVTALRM"; -#endif -#ifdef SIGPROF - sys_siglist[SIGPROF ] = "SIGPROF"; -#endif -#ifdef SIGWINCH - sys_siglist[SIGWINCH ] = "SIGWINCH"; -#endif -#ifdef SIGCONT - sys_siglist[SIGCONT ] = "SIGCONT"; -#endif -#ifdef SIGURG - sys_siglist[SIGURG ] = "SIGURG"; -#endif -#ifdef SIGIO - sys_siglist[SIGIO ] = "SIGIO"; -#endif -#ifdef SIGWIND - sys_siglist[SIGWIND ] = "SIGWIND"; -#endif -#ifdef SIGPHONE - sys_siglist[SIGPHONE ] = "SIGPHONE"; -#endif -#ifdef SIGPOLL - sys_siglist[SIGPOLL ] = "SIGPOLL"; -#endif -#endif /* USG */ -} diff --git a/gnu/usr.bin/gdb/valarith.c b/gnu/usr.bin/gdb/valarith.c deleted file mode 100644 index 8e76899..0000000 --- a/gnu/usr.bin/gdb/valarith.c +++ /dev/null @@ -1,690 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)valarith.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Perform arithmetic and other operations on values, for GDB. - Copyright (C) 1986, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "value.h" -#include "expression.h" - - -value value_x_binop (); -value value_subscripted_rvalue (); - -value -value_add (arg1, arg2) - value arg1, arg2; -{ - register value val, valint, valptr; - register int len; - - COERCE_ARRAY (arg1); - COERCE_ARRAY (arg2); - - if ((TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR - || TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_PTR) - && - (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT - || TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_INT)) - /* Exactly one argument is a pointer, and one is an integer. */ - { - if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR) - { - valptr = arg1; - valint = arg2; - } - else - { - valptr = arg2; - valint = arg1; - } - len = TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (valptr))); - if (len == 0) len = 1; /* For (void *) */ - val = value_from_long (builtin_type_long, - value_as_long (valptr) - + (len * value_as_long (valint))); - VALUE_TYPE (val) = VALUE_TYPE (valptr); - return val; - } - - return value_binop (arg1, arg2, BINOP_ADD); -} - -value -value_sub (arg1, arg2) - value arg1, arg2; -{ - register value val; - - COERCE_ARRAY (arg1); - COERCE_ARRAY (arg2); - - if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR - && - TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_INT) - { - val = value_from_long (builtin_type_long, - value_as_long (arg1) - - TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) * value_as_long (arg2)); - VALUE_TYPE (val) = VALUE_TYPE (arg1); - return val; - } - - if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR - && - VALUE_TYPE (arg1) == VALUE_TYPE (arg2)) - { - val = value_from_long (builtin_type_long, - (value_as_long (arg1) - value_as_long (arg2)) - / TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)))); - return val; - } - - return value_binop (arg1, arg2, BINOP_SUB); -} - -/* Return the value of ARRAY[IDX]. */ - -value -value_subscript (array, idx) - value array, idx; -{ - if (TYPE_CODE (VALUE_TYPE (array)) == TYPE_CODE_ARRAY - && VALUE_LVAL (array) != lval_memory) - return value_subscripted_rvalue (array, idx); - else - return value_ind (value_add (array, idx)); -} - -/* Return the value of EXPR[IDX], expr an aggregate rvalue - (eg, a vector register) */ - -value -value_subscripted_rvalue (array, idx) - value array, idx; -{ - struct type *elt_type = TYPE_TARGET_TYPE (VALUE_TYPE (array)); - int elt_size = TYPE_LENGTH (elt_type); - int elt_offs = elt_size * value_as_long (idx); - value v; - - if (elt_offs >= TYPE_LENGTH (VALUE_TYPE (array))) - error ("no such vector element"); - - if (TYPE_CODE (elt_type) == TYPE_CODE_FLT) - { - if (elt_size == sizeof (float)) - v = value_from_double (elt_type, (double) *(float *) - (VALUE_CONTENTS (array) + elt_offs)); - else - v = value_from_double (elt_type, *(double *) - (VALUE_CONTENTS (array) + elt_offs)); - } - else - { - int offs; - union {int i; char c;} test; - test.i = 1; - if (test.c == 1) - offs = 0; - else - offs = sizeof (LONGEST) - elt_size; - v = value_from_long (elt_type, *(LONGEST *) - (VALUE_CONTENTS (array) + elt_offs - offs)); - } - - if (VALUE_LVAL (array) == lval_internalvar) - VALUE_LVAL (v) = lval_internalvar_component; - else - VALUE_LVAL (v) = not_lval; - VALUE_ADDRESS (v) = VALUE_ADDRESS (array); - VALUE_OFFSET (v) = VALUE_OFFSET (array) + elt_offs; - VALUE_BITSIZE (v) = elt_size * 8; - return v; -} - -/* Check to see if either argument is a structure. This is called so - we know whether to go ahead with the normal binop or look for a - user defined function instead. - - For now, we do not overload the `=' operator. */ - -int -binop_user_defined_p (op, arg1, arg2) - enum exp_opcode op; - value arg1, arg2; -{ - if (op == BINOP_ASSIGN) - return 0; - return (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_STRUCT - || TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_STRUCT - || (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF - && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_STRUCT) - || (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_REF - && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg2))) == TYPE_CODE_STRUCT)); -} - -/* Check to see if argument is a structure. This is called so - we know whether to go ahead with the normal unop or look for a - user defined function instead. - - For now, we do not overload the `&' operator. */ - -int unop_user_defined_p (op, arg1) - enum exp_opcode op; - value arg1; -{ - if (op == UNOP_ADDR) - return 0; - return (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_STRUCT - || (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF - && TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1))) == TYPE_CODE_STRUCT)); -} - -/* We know either arg1 or arg2 is a structure, so try to find the right - user defined function. Create an argument vector that calls - arg1.operator @ (arg1,arg2) and return that value (where '@' is any - binary operator which is legal for GNU C++). */ - -value -value_x_binop (arg1, arg2, op, otherop) - value arg1, arg2; - int op, otherop; -{ - value * argvec; - char *ptr; - char tstr[13]; - int static_memfuncp; - - COERCE_ENUM (arg1); - COERCE_ENUM (arg2); - - /* now we know that what we have to do is construct our - arg vector and find the right function to call it with. */ - - if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_STRUCT) - error ("friend functions not implemented yet"); - - argvec = (value *) alloca (sizeof (value) * 4); - argvec[1] = value_addr (arg1); - argvec[2] = arg2; - argvec[3] = 0; - - /* make the right function name up */ - strcpy(tstr, "operator __"); - ptr = tstr+9; - switch (op) - { - case BINOP_ADD: strcpy(ptr,"+"); break; - case BINOP_SUB: strcpy(ptr,"-"); break; - case BINOP_MUL: strcpy(ptr,"*"); break; - case BINOP_DIV: strcpy(ptr,"/"); break; - case BINOP_REM: strcpy(ptr,"%"); break; - case BINOP_LSH: strcpy(ptr,"<<"); break; - case BINOP_RSH: strcpy(ptr,">>"); break; - case BINOP_LOGAND: strcpy(ptr,"&"); break; - case BINOP_LOGIOR: strcpy(ptr,"|"); break; - case BINOP_LOGXOR: strcpy(ptr,"^"); break; - case BINOP_AND: strcpy(ptr,"&&"); break; - case BINOP_OR: strcpy(ptr,"||"); break; - case BINOP_MIN: strcpy(ptr,"?"); break; - case BINOP_ASSIGN: strcpy(ptr,"="); break; - case BINOP_ASSIGN_MODIFY: - switch (otherop) - { - case BINOP_ADD: strcpy(ptr,"+="); break; - case BINOP_SUB: strcpy(ptr,"-="); break; - case BINOP_MUL: strcpy(ptr,"*="); break; - case BINOP_DIV: strcpy(ptr,"/="); break; - case BINOP_REM: strcpy(ptr,"%="); break; - case BINOP_LOGAND: strcpy(ptr,"&="); break; - case BINOP_LOGIOR: strcpy(ptr,"|="); break; - case BINOP_LOGXOR: strcpy(ptr,"^="); break; - default: - error ("Invalid binary operation specified."); - } - break; - case BINOP_SUBSCRIPT: strcpy(ptr,"[]"); break; - case BINOP_EQUAL: strcpy(ptr,"=="); break; - case BINOP_NOTEQUAL: strcpy(ptr,"!="); break; - case BINOP_LESS: strcpy(ptr,"<"); break; - case BINOP_GTR: strcpy(ptr,">"); break; - case BINOP_GEQ: strcpy(ptr,">="); break; - case BINOP_LEQ: strcpy(ptr,"<="); break; - default: - error ("Invalid binary operation specified."); - } - argvec[0] = value_struct_elt (arg1, argvec+1, tstr, &static_memfuncp, "structure"); - if (argvec[0]) - { - if (static_memfuncp) - { - argvec[1] = argvec[0]; - argvec++; - } - return call_function (argvec[0], 2 - static_memfuncp, argvec + 1); - } - error ("member function %s not found", tstr); -} - -/* We know that arg1 is a structure, so try to find a unary user - defined operator that matches the operator in question. - Create an argument vector that calls arg1.operator @ (arg1) - and return that value (where '@' is (almost) any unary operator which - is legal for GNU C++). */ - -value -value_x_unop (arg1, op) - value arg1; - int op; -{ - value * argvec; - char *ptr; - char tstr[13]; - int static_memfuncp; - - COERCE_ENUM (arg1); - - /* now we know that what we have to do is construct our - arg vector and find the right function to call it with. */ - - if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_STRUCT) - error ("friend functions not implemented yet"); - - argvec = (value *) alloca (sizeof (value) * 3); - argvec[1] = value_addr (arg1); - argvec[2] = 0; - - /* make the right function name up */ - strcpy(tstr,"operator __"); - ptr = tstr+9; - switch (op) - { - case UNOP_PREINCREMENT: strcpy(ptr,"++"); break; - case UNOP_PREDECREMENT: strcpy(ptr,"++"); break; - case UNOP_POSTINCREMENT: strcpy(ptr,"++"); break; - case UNOP_POSTDECREMENT: strcpy(ptr,"++"); break; - case UNOP_ZEROP: strcpy(ptr,"!"); break; - case UNOP_LOGNOT: strcpy(ptr,"~"); break; - case UNOP_NEG: strcpy(ptr,"-"); break; - default: - error ("Invalid binary operation specified."); - } - argvec[0] = value_struct_elt (arg1, argvec+1, tstr, &static_memfuncp, "structure"); - if (argvec[0]) - { - if (static_memfuncp) - { - argvec[1] = argvec[0]; - argvec++; - } - return call_function (argvec[0], 1 - static_memfuncp, argvec + 1); - } - error ("member function %s not found", tstr); -} - -/* Perform a binary operation on two integers or two floats. - Does not support addition and subtraction on pointers; - use value_add or value_sub if you want to handle those possibilities. */ - -value -value_binop (arg1, arg2, op) - value arg1, arg2; - int op; -{ - register value val; - - COERCE_ENUM (arg1); - COERCE_ENUM (arg2); - - if ((TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_FLT - && - TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_INT) - || - (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_FLT - && - TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT)) - error ("Argument to arithmetic operation not a number."); - - if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_FLT - || - TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_FLT) - { - double v1, v2, v; - v1 = value_as_double (arg1); - v2 = value_as_double (arg2); - switch (op) - { - case BINOP_ADD: - v = v1 + v2; - break; - - case BINOP_SUB: - v = v1 - v2; - break; - - case BINOP_MUL: - v = v1 * v2; - break; - - case BINOP_DIV: - v = v1 / v2; - break; - - default: - error ("Integer-only operation on floating point number."); - } - - val = allocate_value (builtin_type_double); - *(double *) VALUE_CONTENTS (val) = v; - } - else - /* Integral operations here. */ - { - /* Should we promote to unsigned longest? */ - if ((TYPE_UNSIGNED (VALUE_TYPE (arg1)) - || TYPE_UNSIGNED (VALUE_TYPE (arg2))) - && (TYPE_LENGTH (VALUE_TYPE (arg1)) >= sizeof (unsigned LONGEST) - || TYPE_LENGTH (VALUE_TYPE (arg2)) >= sizeof (unsigned LONGEST))) - { - unsigned LONGEST v1, v2, v; - v1 = (unsigned LONGEST) value_as_long (arg1); - v2 = (unsigned LONGEST) value_as_long (arg2); - - switch (op) - { - case BINOP_ADD: - v = v1 + v2; - break; - - case BINOP_SUB: - v = v1 - v2; - break; - - case BINOP_MUL: - v = v1 * v2; - break; - - case BINOP_DIV: - v = v1 / v2; - break; - - case BINOP_REM: - v = v1 % v2; - break; - - case BINOP_LSH: - v = v1 << v2; - break; - - case BINOP_RSH: - v = v1 >> v2; - break; - - case BINOP_LOGAND: - v = v1 & v2; - break; - - case BINOP_LOGIOR: - v = v1 | v2; - break; - - case BINOP_LOGXOR: - v = v1 ^ v2; - break; - - case BINOP_AND: - v = v1 && v2; - break; - - case BINOP_OR: - v = v1 || v2; - break; - - case BINOP_MIN: - v = v1 < v2 ? v1 : v2; - break; - - case BINOP_MAX: - v = v1 > v2 ? v1 : v2; - break; - - default: - error ("Invalid binary operation on numbers."); - } - - val = allocate_value (BUILTIN_TYPE_UNSIGNED_LONGEST); - *(unsigned LONGEST *) VALUE_CONTENTS (val) = v; - } - else - { - LONGEST v1, v2, v; - v1 = value_as_long (arg1); - v2 = value_as_long (arg2); - - switch (op) - { - case BINOP_ADD: - v = v1 + v2; - break; - - case BINOP_SUB: - v = v1 - v2; - break; - - case BINOP_MUL: - v = v1 * v2; - break; - - case BINOP_DIV: - v = v1 / v2; - break; - - case BINOP_REM: - v = v1 % v2; - break; - - case BINOP_LSH: - v = v1 << v2; - break; - - case BINOP_RSH: - v = v1 >> v2; - break; - - case BINOP_LOGAND: - v = v1 & v2; - break; - - case BINOP_LOGIOR: - v = v1 | v2; - break; - - case BINOP_LOGXOR: - v = v1 ^ v2; - break; - - case BINOP_AND: - v = v1 && v2; - break; - - case BINOP_OR: - v = v1 || v2; - break; - - case BINOP_MIN: - v = v1 < v2 ? v1 : v2; - break; - - case BINOP_MAX: - v = v1 > v2 ? v1 : v2; - break; - - default: - error ("Invalid binary operation on numbers."); - } - - val = allocate_value (BUILTIN_TYPE_LONGEST); - *(LONGEST *) VALUE_CONTENTS (val) = v; - } - } - - return val; -} - -/* Simulate the C operator ! -- return 1 if ARG1 contains zeros. */ - -int -value_zerop (arg1) - value arg1; -{ - register int len; - register char *p; - - COERCE_ARRAY (arg1); - - len = TYPE_LENGTH (VALUE_TYPE (arg1)); - p = VALUE_CONTENTS (arg1); - - while (--len >= 0) - { - if (*p++) - break; - } - - return len < 0; -} - -/* Simulate the C operator == by returning a 1 - iff ARG1 and ARG2 have equal contents. */ - -int -value_equal (arg1, arg2) - register value arg1, arg2; - -{ - register int len; - register char *p1, *p2; - enum type_code code1; - enum type_code code2; - - COERCE_ARRAY (arg1); - COERCE_ARRAY (arg2); - - code1 = TYPE_CODE (VALUE_TYPE (arg1)); - code2 = TYPE_CODE (VALUE_TYPE (arg2)); - - if (code1 == TYPE_CODE_INT && code2 == TYPE_CODE_INT) - return value_as_long (arg1) == value_as_long (arg2); - else if ((code1 == TYPE_CODE_FLT || code1 == TYPE_CODE_INT) - && (code2 == TYPE_CODE_FLT || code2 == TYPE_CODE_INT)) - return value_as_double (arg1) == value_as_double (arg2); - else if ((code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_INT) - || (code2 == TYPE_CODE_PTR && code1 == TYPE_CODE_INT)) - return (char *) value_as_long (arg1) == (char *) value_as_long (arg2); - else if (code1 == code2 - && ((len = TYPE_LENGTH (VALUE_TYPE (arg1))) - == TYPE_LENGTH (VALUE_TYPE (arg2)))) - { - p1 = VALUE_CONTENTS (arg1); - p2 = VALUE_CONTENTS (arg2); - while (--len >= 0) - { - if (*p1++ != *p2++) - break; - } - return len < 0; - } - else - error ("Invalid type combination in equality test."); -} - -/* Simulate the C operator < by returning 1 - iff ARG1's contents are less than ARG2's. */ - -int -value_less (arg1, arg2) - register value arg1, arg2; -{ - register enum type_code code1; - register enum type_code code2; - - COERCE_ARRAY (arg1); - COERCE_ARRAY (arg2); - - code1 = TYPE_CODE (VALUE_TYPE (arg1)); - code2 = TYPE_CODE (VALUE_TYPE (arg2)); - - if (code1 == TYPE_CODE_INT && code2 == TYPE_CODE_INT) - return value_as_long (arg1) < value_as_long (arg2); - else if ((code1 == TYPE_CODE_FLT || code1 == TYPE_CODE_INT) - && (code2 == TYPE_CODE_FLT || code2 == TYPE_CODE_INT)) - return value_as_double (arg1) < value_as_double (arg2); - else if ((code1 == TYPE_CODE_PTR || code1 == TYPE_CODE_INT) - && (code2 == TYPE_CODE_PTR || code2 == TYPE_CODE_INT)) - return (char *) value_as_long (arg1) < (char *) value_as_long (arg2); - else - error ("Invalid type combination in ordering comparison."); -} - -/* The unary operators - and ~. Both free the argument ARG1. */ - -value -value_neg (arg1) - register value arg1; -{ - register struct type *type; - - COERCE_ENUM (arg1); - - type = VALUE_TYPE (arg1); - - if (TYPE_CODE (type) == TYPE_CODE_FLT) - return value_from_double (type, - value_as_double (arg1)); - else if (TYPE_CODE (type) == TYPE_CODE_INT) - return value_from_long (type, - value_as_long (arg1)); - else - error ("Argument to negate operation not a number."); -} - -value -value_lognot (arg1) - register value arg1; -{ - COERCE_ENUM (arg1); - - if (TYPE_CODE (VALUE_TYPE (arg1)) != TYPE_CODE_INT) - error ("Argument to complement operation not an integer."); - - return value_from_long (VALUE_TYPE (arg1), ~ value_as_long (arg1)); -} - diff --git a/gnu/usr.bin/gdb/valops.c b/gnu/usr.bin/gdb/valops.c deleted file mode 100644 index ab5652c..0000000 --- a/gnu/usr.bin/gdb/valops.c +++ /dev/null @@ -1,1418 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)valops.c 6.4 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Perform non-arithmetic operations on values, for GDB. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include "stdio.h" -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "value.h" -#include "frame.h" -#include "inferior.h" - -/* Cast value ARG2 to type TYPE and return as a value. - More general than a C cast: accepts any two types of the same length, - and if ARG2 is an lvalue it can be cast into anything at all. */ - -value -value_cast (type, arg2) - struct type *type; - register value arg2; -{ - register enum type_code code1; - register enum type_code code2; - register int scalar; - - /* Coerce arrays but not enums. Enums will work as-is - and coercing them would cause an infinite recursion. */ - if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_ENUM) - COERCE_ARRAY (arg2); - - code1 = TYPE_CODE (type); - code2 = TYPE_CODE (VALUE_TYPE (arg2)); - scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT - || code2 == TYPE_CODE_ENUM); - - if (code1 == TYPE_CODE_FLT && scalar) - return value_from_double (type, value_as_double (arg2)); - else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM) - && (scalar || code2 == TYPE_CODE_PTR)) - return value_from_long (type, value_as_long (arg2)); - else if (TYPE_LENGTH (type) == TYPE_LENGTH (VALUE_TYPE (arg2))) - { - VALUE_TYPE (arg2) = type; - return arg2; - } - else if (VALUE_LVAL (arg2) == lval_memory) - { - return value_at (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2)); - } - else - error ("Invalid cast."); -} - -/* Create a value of type TYPE that is zero, and return it. */ - -value -value_zero (type, lv) - struct type *type; - enum lval_type lv; -{ - register value val = allocate_value (type); - - bzero (VALUE_CONTENTS (val), TYPE_LENGTH (type)); - VALUE_LVAL (val) = lv; - - return val; -} - -/* Return the value with a specified type located at specified address. */ - -value -value_at (type, addr) - struct type *type; - CORE_ADDR addr; -{ - register value val = allocate_value (type); - int temp; - - temp = read_memory (addr, VALUE_CONTENTS (val), TYPE_LENGTH (type)); - if (temp) - { - if (have_inferior_p () && !remote_debugging) - print_sys_errmsg ("ptrace", temp); - /* Actually, address between addr and addr + len was out of bounds. */ - error ("Cannot read memory: address 0x%x out of bounds.", addr); - } - - VALUE_LVAL (val) = lval_memory; - VALUE_ADDRESS (val) = addr; - - return val; -} - -/* Store the contents of FROMVAL into the location of TOVAL. - Return a new value with the location of TOVAL and contents of FROMVAL. */ - -value -value_assign (toval, fromval) - register value toval, fromval; -{ - register struct type *type = VALUE_TYPE (toval); - register value val; - char raw_buffer[MAX_REGISTER_RAW_SIZE]; - char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; - int use_buffer = 0; - - extern CORE_ADDR find_saved_register (); - - COERCE_ARRAY (fromval); - - if (VALUE_LVAL (toval) != lval_internalvar) - fromval = value_cast (type, fromval); - - /* If TOVAL is a special machine register requiring conversion - of program values to a special raw format, - convert FROMVAL's contents now, with result in `raw_buffer', - and set USE_BUFFER to the number of bytes to write. */ - - if (VALUE_REGNO (toval) >= 0 - && REGISTER_CONVERTIBLE (VALUE_REGNO (toval))) - { - int regno = VALUE_REGNO (toval); - if (VALUE_TYPE (fromval) != REGISTER_VIRTUAL_TYPE (regno)) - fromval = value_cast (REGISTER_VIRTUAL_TYPE (regno), fromval); - bcopy (VALUE_CONTENTS (fromval), virtual_buffer, - REGISTER_VIRTUAL_SIZE (regno)); - REGISTER_CONVERT_TO_RAW (regno, virtual_buffer, raw_buffer); - use_buffer = REGISTER_RAW_SIZE (regno); - } - - switch (VALUE_LVAL (toval)) - { - case lval_internalvar: - set_internalvar (VALUE_INTERNALVAR (toval), fromval); - break; - - case lval_internalvar_component: - set_internalvar_component (VALUE_INTERNALVAR (toval), - VALUE_OFFSET (toval), - VALUE_BITPOS (toval), - VALUE_BITSIZE (toval), - fromval); - break; - - case lval_memory: - if (VALUE_BITSIZE (toval)) - { - int val; - read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), - &val, sizeof val); - modify_field (&val, (int) value_as_long (fromval), - VALUE_BITPOS (toval), VALUE_BITSIZE (toval)); - write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), - &val, sizeof val); - } - else if (use_buffer) - write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), - raw_buffer, use_buffer); - else - write_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), - VALUE_CONTENTS (fromval), TYPE_LENGTH (type)); - break; - - case lval_register: - if (VALUE_BITSIZE (toval)) - { - int val; - - read_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), - &val, sizeof val); - modify_field (&val, (int) value_as_long (fromval), - VALUE_BITPOS (toval), VALUE_BITSIZE (toval)); - write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), - &val, sizeof val); - } - else if (use_buffer) - write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), - raw_buffer, use_buffer); - else - write_register_bytes (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval), - VALUE_CONTENTS (fromval), TYPE_LENGTH (type)); - break; - - case lval_reg_frame_relative: - { - /* value is stored in a series of registers in the frame - specified by the structure. Copy that value out, modify - it, and copy it back in. */ - int amount_to_copy = (VALUE_BITSIZE (toval) ? 1 : TYPE_LENGTH (type)); - int reg_size = REGISTER_RAW_SIZE (VALUE_FRAME_REGNUM (toval)); - int byte_offset = VALUE_OFFSET (toval) % reg_size; - int reg_offset = VALUE_OFFSET (toval) / reg_size; - int amount_copied; - char *buffer = (char *) alloca (amount_to_copy); - int regno; - FRAME frame; - CORE_ADDR addr; - - /* Figure out which frame this is in currently. */ - for (frame = get_current_frame (); - frame && FRAME_FP (frame) != VALUE_FRAME (toval); - frame = get_prev_frame (frame)) - ; - - if (!frame) - error ("Value being assigned to is no longer active."); - - amount_to_copy += (reg_size - amount_to_copy % reg_size); - - /* Copy it out. */ - for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset, - amount_copied = 0); - amount_copied < amount_to_copy; - amount_copied += reg_size, regno++) - { - addr = find_saved_register (frame, regno); - if (addr == 0) - read_register_bytes (REGISTER_BYTE (regno), - buffer + amount_copied, - reg_size); - else - read_memory (addr, buffer + amount_copied, reg_size); - } - - /* Modify what needs to be modified. */ - if (VALUE_BITSIZE (toval)) - modify_field (buffer + byte_offset, - (int) value_as_long (fromval), - VALUE_BITPOS (toval), VALUE_BITSIZE (toval)); - else if (use_buffer) - bcopy (raw_buffer, buffer + byte_offset, use_buffer); - else - bcopy (VALUE_CONTENTS (fromval), buffer + byte_offset, - TYPE_LENGTH (type)); - - /* Copy it back. */ - for ((regno = VALUE_FRAME_REGNUM (toval) + reg_offset, - amount_copied = 0); - amount_copied < amount_to_copy; - amount_copied += reg_size, regno++) - { - addr = find_saved_register (frame, regno); - if (addr == 0) - write_register_bytes (REGISTER_BYTE (regno), - buffer + amount_copied, - reg_size); - else - write_memory (addr, buffer + amount_copied, reg_size); - } - } - break; - - - default: - error ("Left side of = operation is not an lvalue."); - } - - /* Return a value just like TOVAL except with the contents of FROMVAL - (except in the case of the type if TOVAL is an internalvar). */ - - if (VALUE_LVAL (toval) == lval_internalvar - || VALUE_LVAL (toval) == lval_internalvar_component) - { - type = VALUE_TYPE (fromval); - } - - val = allocate_value (type); - bcopy (toval, val, VALUE_CONTENTS (val) - (char *) val); - bcopy (VALUE_CONTENTS (fromval), VALUE_CONTENTS (val), TYPE_LENGTH (type)); - VALUE_TYPE (val) = type; - - return val; -} - -/* Extend a value VAL to COUNT repetitions of its type. */ - -value -value_repeat (arg1, count) - value arg1; - int count; -{ - register value val; - - if (VALUE_LVAL (arg1) != lval_memory) - error ("Only values in memory can be extended with '@'."); - if (count < 1) - error ("Invalid number %d of repetitions.", count); - - val = allocate_repeat_value (VALUE_TYPE (arg1), count); - - read_memory (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1), - VALUE_CONTENTS (val), - TYPE_LENGTH (VALUE_TYPE (val)) * count); - VALUE_LVAL (val) = lval_memory; - VALUE_ADDRESS (val) = VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1); - - return val; -} - -value -value_of_variable (var) - struct symbol *var; -{ - return read_var_value (var, (FRAME) 0); -} - -/* Given a value which is an array, return a value which is - a pointer to its first element. */ - -value -value_coerce_array (arg1) - value arg1; -{ - register struct type *type; - register value val; - - if (VALUE_LVAL (arg1) != lval_memory) - error ("Attempt to take address of value not located in memory."); - - /* Get type of elements. */ - if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY) - type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1)); - else - /* A phony array made by value_repeat. - Its type is the type of the elements, not an array type. */ - type = VALUE_TYPE (arg1); - - /* Get the type of the result. */ - type = lookup_pointer_type (type); - val = value_from_long (builtin_type_long, - (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1))); - VALUE_TYPE (val) = type; - return val; -} - -/* Return a pointer value for the object for which ARG1 is the contents. */ - -value -value_addr (arg1) - value arg1; -{ - register struct type *type; - register value val, arg1_coerced; - - /* Taking the address of an array is really a no-op - once the array is coerced to a pointer to its first element. */ - arg1_coerced = arg1; - COERCE_ARRAY (arg1_coerced); - if (arg1 != arg1_coerced) - return arg1_coerced; - - if (VALUE_LVAL (arg1) != lval_memory) - error ("Attempt to take address of value not located in memory."); - - /* Get the type of the result. */ - type = lookup_pointer_type (VALUE_TYPE (arg1)); - val = value_from_long (builtin_type_long, - (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1))); - VALUE_TYPE (val) = type; - return val; -} - -/* Given a value of a pointer type, apply the C unary * operator to it. */ - -value -value_ind (arg1) - value arg1; -{ - /* Must do this before COERCE_ARRAY, otherwise an infinite loop - will result */ - if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF) - return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)), - (CORE_ADDR) value_as_long (arg1)); - - COERCE_ARRAY (arg1); - - if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_MEMBER) - error ("not implemented: member types in value_ind"); - - /* Allow * on an integer so we can cast it to whatever we want. - This returns an int, which seems like the most C-like thing - to do. "long long" variables are rare enough that - BUILTIN_TYPE_LONGEST would seem to be a mistake. */ - if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT) - return value_at (builtin_type_int, - (CORE_ADDR) value_as_long (arg1)); - else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR) - return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)), - (CORE_ADDR) value_as_long (arg1)); - else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF) - return value_at (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)), - (CORE_ADDR) value_as_long (arg1)); - error ("Attempt to take contents of a non-pointer value."); -} - -/* Pushing small parts of stack frames. */ - -/* Push one word (the size of object that a register holds). */ - -CORE_ADDR -push_word (sp, buffer) - CORE_ADDR sp; - REGISTER_TYPE buffer; -{ - register int len = sizeof (REGISTER_TYPE); - -#if 1 INNER_THAN 2 - sp -= len; - write_memory (sp, &buffer, len); -#else /* stack grows upward */ - write_memory (sp, &buffer, len); - sp += len; -#endif /* stack grows upward */ - - return sp; -} - -/* Push LEN bytes with data at BUFFER. */ - -CORE_ADDR -push_bytes (sp, buffer, len) - CORE_ADDR sp; - char *buffer; - int len; -{ -#if 1 INNER_THAN 2 - sp -= len; - write_memory (sp, buffer, len); -#else /* stack grows upward */ - write_memory (sp, buffer, len); - sp += len; -#endif /* stack grows upward */ - - return sp; -} - -/* Push onto the stack the specified value VALUE. */ - -CORE_ADDR -value_push (sp, arg) - register CORE_ADDR sp; - value arg; -{ - register int len = TYPE_LENGTH (VALUE_TYPE (arg)); - -#if 1 INNER_THAN 2 - sp -= len; - write_memory (sp, VALUE_CONTENTS (arg), len); -#else /* stack grows upward */ - write_memory (sp, VALUE_CONTENTS (arg), len); - sp += len; -#endif /* stack grows upward */ - - return sp; -} - -/* Perform the standard coercions that are specified - for arguments to be passed to C functions. */ - -value -value_arg_coerce (arg) - value arg; -{ - register struct type *type; - - COERCE_ENUM (arg); - - type = VALUE_TYPE (arg); - - if (TYPE_CODE (type) == TYPE_CODE_INT - && TYPE_LENGTH (type) < sizeof (int)) - return value_cast (builtin_type_int, arg); - - if (type == builtin_type_float) - return value_cast (builtin_type_double, arg); - - return arg; -} - -/* Push the value ARG, first coercing it as an argument - to a C function. */ - -CORE_ADDR -value_arg_push (sp, arg) - register CORE_ADDR sp; - value arg; -{ - return value_push (sp, value_arg_coerce (arg)); -} - -#ifdef NEW_CALL_FUNCTION - -int -arg_stacklen(nargs, args) - int nargs; - value *args; -{ - int len = 0; - - while (--nargs >= 0) - len += TYPE_LENGTH(VALUE_TYPE(value_arg_coerce(args[nargs]))); - - return len; -} - -CORE_ADDR -function_address(function, type) - value function; - struct type **type; -{ - register CORE_ADDR funaddr; - register struct type *ftype = VALUE_TYPE(function); - register enum type_code code = TYPE_CODE(ftype); - - /* - * If it's a member function, just look at the function part - * of it. - */ - - /* Determine address to call. */ - if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD) { - funaddr = VALUE_ADDRESS(function); - *type = TYPE_TARGET_TYPE(ftype); - } else if (code == TYPE_CODE_PTR) { - funaddr = value_as_long(function); - if (TYPE_CODE(TYPE_TARGET_TYPE(ftype)) == TYPE_CODE_FUNC - || TYPE_CODE(TYPE_TARGET_TYPE(ftype)) == TYPE_CODE_METHOD) - *type = TYPE_TARGET_TYPE(TYPE_TARGET_TYPE(ftype)); - else - *type = builtin_type_int; - } else if (code == TYPE_CODE_INT) { - /* - * Handle the case of functions lacking debugging - * info. Their values are characters since their - * addresses are char - */ - if (TYPE_LENGTH(ftype) == 1) - - funaddr = value_as_long(value_addr(function)); - else - /* - * Handle integer used as address of a - * function. - */ - funaddr = value_as_long(function); - - *type = builtin_type_int; - } else - error("Invalid data type for function to be called."); - - return funaddr; -} - -/* Perform a function call in the inferior. - ARGS is a vector of values of arguments (NARGS of them). - FUNCTION is a value, the function to be called. - Returns a value representing what the function returned. - May fail to return, if a breakpoint or signal is hit - during the execution of the function. */ - -value -call_function(function, nargs, args) - value function; - int nargs; - value *args; -{ - register CORE_ADDR sp, pc; - struct type *value_type; - struct inferior_status inf_status; - struct cleanup *old_chain; - register CORE_ADDR funaddr; - int struct_return_bytes; - char retbuf[REGISTER_BYTES]; - - if (!have_inferior_p()) - error("Cannot invoke functions if the inferior is not running."); - - save_inferior_status(&inf_status, 1); - old_chain = make_cleanup(restore_inferior_status, &inf_status); - - sp = read_register(SP_REGNUM); - funaddr = function_address(function, &value_type); - /* - * Are we returning a value using a structure return or a - * normal value return? - */ - if (using_struct_return(function, funaddr, value_type)) - struct_return_bytes = TYPE_LENGTH(value_type); - else - struct_return_bytes = 0; - /* - * Create a call sequence customized for this function and - * the number of arguments for it. - */ - pc = setup_dummy(sp, funaddr, nargs, args, - struct_return_bytes, value_arg_push); - - /* - * Execute the stack dummy stub. The register state will be - * returned in retbuf. It is restored below. - */ - run_stack_dummy(pc, retbuf); - - /* - * This will restore the register context that existed before - * we called the dummy function. - */ - do_cleanups(old_chain); - - return value_being_returned(value_type, retbuf, struct_return_bytes); -} -#else - -/* Perform a function call in the inferior. - ARGS is a vector of values of arguments (NARGS of them). - FUNCTION is a value, the function to be called. - Returns a value representing what the function returned. - May fail to return, if a breakpoint or signal is hit - during the execution of the function. */ - -value -call_function (function, nargs, args) - value function; - int nargs; - value *args; -{ - register CORE_ADDR sp; - register int i; - CORE_ADDR start_sp; - static REGISTER_TYPE dummy[] = CALL_DUMMY; - REGISTER_TYPE dummy1[sizeof dummy / sizeof (REGISTER_TYPE)]; - CORE_ADDR old_sp; - struct type *value_type; - unsigned char struct_return; - CORE_ADDR struct_addr; - struct inferior_status inf_status; - struct cleanup *old_chain; - - if (!have_inferior_p ()) - error ("Cannot invoke functions if the inferior is not running."); - - save_inferior_status (&inf_status, 1); - old_chain = make_cleanup (restore_inferior_status, &inf_status); - - /* PUSH_DUMMY_FRAME is responsible for saving the inferior registers - (and POP_FRAME for restoring them). (At least on most machines) - they are saved on the stack in the inferior. */ - PUSH_DUMMY_FRAME; - - old_sp = sp = read_register (SP_REGNUM); - -#if 1 INNER_THAN 2 /* Stack grows down */ - sp -= sizeof dummy; - start_sp = sp; -#else /* Stack grows up */ - start_sp = sp; - sp += sizeof dummy; -#endif - - { - register CORE_ADDR funaddr; - register struct type *ftype = VALUE_TYPE (function); - register enum type_code code = TYPE_CODE (ftype); - - /* If it's a member function, just look at the function - part of it. */ - - /* Determine address to call. */ - if (code == TYPE_CODE_FUNC || code == TYPE_CODE_METHOD) - { - funaddr = VALUE_ADDRESS (function); - value_type = TYPE_TARGET_TYPE (ftype); - } - else if (code == TYPE_CODE_PTR) - { - funaddr = value_as_long (function); - if (TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_FUNC - || TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_METHOD) - value_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype)); - else - value_type = builtin_type_int; - } - else if (code == TYPE_CODE_INT) - { - /* Handle the case of functions lacking debugging info. - Their values are characters since their addresses are char */ - if (TYPE_LENGTH (ftype) == 1) - funaddr = value_as_long (value_addr (function)); - else - /* Handle integer used as address of a function. */ - funaddr = value_as_long (function); - - value_type = builtin_type_int; - } - else - error ("Invalid data type for function to be called."); - - /* Are we returning a value using a structure return or a normal - value return? */ - - struct_return = using_struct_return (function, funaddr, value_type); - - /* Create a call sequence customized for this function - and the number of arguments for it. */ - bcopy (dummy, dummy1, sizeof dummy); - FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, value_type); - } - -#ifndef CANNOT_EXECUTE_STACK - write_memory (start_sp, dummy1, sizeof dummy); - -#else - /* Convex Unix prohibits executing in the stack segment. */ - /* Hope there is empty room at the top of the text segment. */ - { - extern CORE_ADDR text_end; - static checked = 0; - if (!checked) - for (start_sp = text_end - sizeof dummy; start_sp < text_end; ++start_sp) - if (read_memory_integer (start_sp, 1) != 0) - error ("text segment full -- no place to put call"); - checked = 1; - sp = old_sp; - start_sp = text_end - sizeof dummy; - write_memory (start_sp, dummy1, sizeof dummy); - } -#endif /* CANNOT_EXECUTE_STACK */ -#ifdef STACK_ALIGN - /* If stack grows down, we must leave a hole at the top. */ - { - int len = 0; - - /* Reserve space for the return structure to be written on the - stack, if necessary */ - - if (struct_return) - len += TYPE_LENGTH (value_type); - - for (i = nargs - 1; i >= 0; i--) - len += TYPE_LENGTH (VALUE_TYPE (value_arg_coerce (args[i]))); -#ifdef CALL_DUMMY_STACK_ADJUST - len += CALL_DUMMY_STACK_ADJUST; -#endif -#if 1 INNER_THAN 2 - sp -= STACK_ALIGN (len) - len; -#else - sp += STACK_ALIGN (len) - len; -#endif - } -#endif /* STACK_ALIGN */ - - /* Reserve space for the return structure to be written on the - stack, if necessary */ - - if (struct_return) - { -#if 1 INNER_THAN 2 - sp -= TYPE_LENGTH (value_type); - struct_addr = sp; -#else - struct_addr = sp; - sp += TYPE_LENGTH (value_type); -#endif - } - - for (i = nargs - 1; i >= 0; i--) - sp = value_arg_push (sp, args[i]); - -#ifdef CALL_DUMMY_STACK_ADJUST -#if 1 INNER_THAN 2 - sp -= CALL_DUMMY_STACK_ADJUST; -#else - sp += CALL_DUMMY_STACK_ADJUST; -#endif -#endif /* CALL_DUMMY_STACK_ADJUST */ - - /* Store the address at which the structure is supposed to be - written. Note that this (and the code which reserved the space - above) assumes that gcc was used to compile this function. Since - it doesn't cost us anything but space and if the function is pcc - it will ignore this value, we will make that assumption. - - Also note that on some machines (like the sparc) pcc uses this - convention in a slightly twisted way also. */ - - if (struct_return) - STORE_STRUCT_RETURN (struct_addr, sp); - - /* Write the stack pointer. This is here because the statement above - might fool with it */ - write_register (SP_REGNUM, sp); - - /* Figure out the value returned by the function. */ - { - char retbuf[REGISTER_BYTES]; - - /* Execute the stack dummy routine, calling FUNCTION. - When it is done, discard the empty frame - after storing the contents of all regs into retbuf. */ - run_stack_dummy (start_sp + CALL_DUMMY_START_OFFSET, retbuf); - - do_cleanups (old_chain); - - return value_being_returned (value_type, retbuf, struct_return); - } -} -#endif - -/* Create a value for a string constant: - Call the function malloc in the inferior to get space for it, - then copy the data into that space - and then return the address with type char *. - PTR points to the string constant data; LEN is number of characters. */ - -value -value_string (ptr, len) - char *ptr; - int len; -{ - register value val; - register struct symbol *sym; - value blocklen; - register char *copy = (char *) alloca (len + 1); - char *i = ptr; - register char *o = copy, *ibeg = ptr; - register int c; -#ifdef KERNELDEBUG - extern int kernel_debugging; - - if (kernel_debugging) - error("Can't stuff string constants into kernel (yet)."); -#endif - - /* Copy the string into COPY, processing escapes. - We could not conveniently process them in expread - because the string there wants to be a substring of the input. */ - - while (i - ibeg < len) - { - c = *i++; - if (c == '\\') - { - c = parse_escape (&i); - if (c == -1) - continue; - } - *o++ = c; - } - *o = 0; - - /* Get the length of the string after escapes are processed. */ - - len = o - copy; - - /* Find the address of malloc in the inferior. */ - - sym = lookup_symbol ("malloc", 0, VAR_NAMESPACE, 0); - if (sym != 0) - { - if (SYMBOL_CLASS (sym) != LOC_BLOCK) - error ("\"malloc\" exists in this program but is not a function."); - val = value_of_variable (sym); - } - else - { - register int i; - for (i = 0; i < misc_function_count; i++) - if (!strcmp (misc_function_vector[i].name, "malloc")) - break; - if (i < misc_function_count) - val = value_from_long (builtin_type_long, - (LONGEST) misc_function_vector[i].address); - else - error ("String constants require the program to have a function \"malloc\"."); - } - - blocklen = value_from_long (builtin_type_int, (LONGEST) (len + 1)); - val = call_function (val, 1, &blocklen); - if (value_zerop (val)) - error ("No memory available for string constant."); - write_memory ((CORE_ADDR) value_as_long (val), copy, len + 1); - VALUE_TYPE (val) = lookup_pointer_type (builtin_type_char); - return val; -} - -static int -type_field_index(t, name) - register struct type *t; - register char *name; -{ - register int i; - - for (i = TYPE_NFIELDS(t); --i >= 0;) - { - register char *t_field_name = TYPE_FIELD_NAME (t, i); - - if (t_field_name && !strcmp (t_field_name, name)) - break; - } - return (i); -} - -/* Given ARG1, a value of type (pointer to a)* structure/union, - extract the component named NAME from the ultimate target structure/union - and return it as a value with its appropriate type. - ERR is used in the error message if ARG1's type is wrong. - - C++: ARGS is a list of argument types to aid in the selection of - an appropriate method. Also, handle derived types. - - STATIC_MEMFUNCP, if non-NULL, points to a caller-supplied location - where the truthvalue of whether the function that was resolved was - a static member function or not. - - ERR is an error message to be printed in case the field is not found. */ - -value -value_struct_elt (arg1, args, name, static_memfuncp, err) - register value arg1, *args; - char *name; - int *static_memfuncp; - char *err; -{ - register struct type *t; - register int i; - int found = 0; - - struct type *baseclass; - - COERCE_ARRAY (arg1); - - t = VALUE_TYPE (arg1); - - /* Check for the usual case: we have pointer, target type is a struct - * and `name' is a legal field of the struct. In this case, we can - * just snarf the value of the field & not waste time while value_ind - * sucks over the entire struct. */ - if (! args) - { - if (TYPE_CODE(t) == TYPE_CODE_PTR - && (TYPE_CODE((baseclass = TYPE_TARGET_TYPE(t))) == TYPE_CODE_STRUCT - || TYPE_CODE(baseclass) == TYPE_CODE_UNION) - && (i = type_field_index(baseclass, name)) >= 0) - { - register int offset; - register struct type *f = TYPE_FIELD_TYPE(baseclass, i); - - offset = TYPE_FIELD_BITPOS(baseclass, i) >> 3; - if (TYPE_FIELD_BITSIZE(baseclass, i) == 0) - return value_at(f, (CORE_ADDR)(value_as_long(arg1) + offset)); - } - } - - /* Follow pointers until we get to a non-pointer. */ - - while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF) - { - arg1 = value_ind (arg1); - COERCE_ARRAY (arg1); - t = VALUE_TYPE (arg1); - } - - if (TYPE_CODE (t) == TYPE_CODE_MEMBER) - error ("not implemented: member type in value_struct_elt"); - - if (TYPE_CODE (t) != TYPE_CODE_STRUCT - && TYPE_CODE (t) != TYPE_CODE_UNION) - error ("Attempt to extract a component of a value that is not a %s.", err); - - baseclass = t; - - /* Assume it's not, unless we see that it is. */ - if (static_memfuncp) - *static_memfuncp =0; - - if (!args) - { - /* if there are no arguments ...do this... */ - - /* Try as a variable first, because if we succeed, there - is less work to be done. */ - while (t) - { - i = type_field_index(t, name); - if (i >= 0) - return TYPE_FIELD_STATIC (t, i) - ? value_static_field (t, name, i) : value_field (arg1, i); - - if (TYPE_N_BASECLASSES (t) == 0) - break; - - t = TYPE_BASECLASS (t, 1); - VALUE_TYPE (arg1) = t; /* side effect! */ - } - - /* C++: If it was not found as a data field, then try to - return it as a pointer to a method. */ - t = baseclass; - VALUE_TYPE (arg1) = t; /* side effect! */ - - if (destructor_name_p (name, t)) - error ("use `info method' command to print out value of destructor"); - - while (t) - { - for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i) - { - if (! strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name)) - { - error ("use `info method' command to print value of method \"%s\"", name); - } - } - - if (TYPE_N_BASECLASSES (t) == 0) - break; - - t = TYPE_BASECLASS (t, 1); - } - - error ("There is no field named %s.", name); - return 0; - } - - if (destructor_name_p (name, t)) - { - if (!args[1]) - { - /* destructors are a special case. */ - return (value)value_fn_field (arg1, 0, - TYPE_FN_FIELDLIST_LENGTH (t, 0)); - } - else - { - error ("destructor should not have any argument"); - } - } - - /* This following loop is for methods with arguments. */ - while (t) - { - /* Look up as method first, because that is where we - expect to find it first. */ - for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; i--) - { - struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); - - if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name)) - { - int j; - struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); - - found = 1; - for (j = TYPE_FN_FIELDLIST_LENGTH (t, i) - 1; j >= 0; --j) - if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j), - TYPE_FN_FIELD_ARGS (f, j), args)) - { - if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) - return (value)value_virtual_fn_field (arg1, f, j, t); - if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp) - *static_memfuncp = 1; - return (value)value_fn_field (arg1, i, j); - } - } - } - - if (TYPE_N_BASECLASSES (t) == 0) - break; - - t = TYPE_BASECLASS (t, 1); - VALUE_TYPE (arg1) = t; /* side effect! */ - } - - if (found) - { - error ("Structure method %s not defined for arglist.", name); - return 0; - } - else - { - /* See if user tried to invoke data as function */ - t = baseclass; - while (t) - { - i = type_field_index(t, name); - if (i >= 0) - return TYPE_FIELD_STATIC (t, i) - ? value_static_field (t, name, i) : value_field (arg1, i); - - if (TYPE_N_BASECLASSES (t) == 0) - break; - - t = TYPE_BASECLASS (t, 1); - VALUE_TYPE (arg1) = t; /* side effect! */ - } - error ("Structure has no component named %s.", name); - } -} - -/* C++: return 1 is NAME is a legitimate name for the destructor - of type TYPE. If TYPE does not have a destructor, or - if NAME is inappropriate for TYPE, an error is signaled. */ -int -destructor_name_p (name, type) - char *name; - struct type *type; -{ - /* destructors are a special case. */ - char *dname = TYPE_NAME (type); - - if (name[0] == '~') - { - if (! TYPE_HAS_DESTRUCTOR (type)) - error ("type `%s' does not have destructor defined", - TYPE_NAME (type)); - /* Skip past the "struct " at the front. */ - while (*dname++ != ' ') ; - if (strcmp (dname, name+1)) - error ("destructor specification error"); - else - return 1; - } - return 0; -} - -/* C++: Given ARG1, a value of type (pointer to a)* structure/union, - return 1 if the component named NAME from the ultimate - target structure/union is defined, otherwise, return 0. */ - -int -check_field (arg1, name) - register value arg1; - char *name; -{ - register struct type *t; - register int i; - int found = 0; - - struct type *baseclass; - - COERCE_ARRAY (arg1); - - t = VALUE_TYPE (arg1); - - /* Follow pointers until we get to a non-pointer. */ - - while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF) - t = TYPE_TARGET_TYPE (t); - - if (TYPE_CODE (t) == TYPE_CODE_MEMBER) - error ("not implemented: member type in check_field"); - - if (TYPE_CODE (t) != TYPE_CODE_STRUCT - && TYPE_CODE (t) != TYPE_CODE_UNION) - error ("Internal error: `this' is not an aggregate"); - - baseclass = t; - - while (t) - { - for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--) - { - char *t_field_name = TYPE_FIELD_NAME (t, i); - if (t_field_name && !strcmp (t_field_name, name)) - goto success; - } - if (TYPE_N_BASECLASSES (t) == 0) - break; - - t = TYPE_BASECLASS (t, 1); - VALUE_TYPE (arg1) = t; /* side effect! */ - } - - /* C++: If it was not found as a data field, then try to - return it as a pointer to a method. */ - t = baseclass; - - /* Destructors are a special case. */ - if (destructor_name_p (name, t)) - goto success; - - while (t) - { - for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i) - { - if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name)) - return 1; - } - - if (TYPE_N_BASECLASSES (t) == 0) - break; - - t = TYPE_BASECLASS (t, 1); - } - return 0; - - success: - t = VALUE_TYPE (arg1); - while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF) - { - arg1 = value_ind (arg1); - COERCE_ARRAY (arg1); - t = VALUE_TYPE (arg1); - } -} - -/* C++: Given an aggregate type DOMAIN, and a member name NAME, - return the address of this member as a pointer to member - type. If INTYPE is non-null, then it will be the type - of the member we are looking for. This will help us resolve - pointers to member functions. */ - -value -value_struct_elt_for_address (domain, intype, name) - struct type *domain, *intype; - char *name; -{ - register struct type *t = domain; - register int i; - int found = 0; - value v; - - struct type *baseclass; - - if (TYPE_CODE (t) != TYPE_CODE_STRUCT - && TYPE_CODE (t) != TYPE_CODE_UNION) - error ("Internal error: non-aggregate type to value_struct_elt_for_address"); - - baseclass = t; - - while (t) - { - for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--) - { - char *t_field_name = TYPE_FIELD_NAME (t, i); - if (t_field_name && !strcmp (t_field_name, name)) - { - if (TYPE_FIELD_PACKED (t, i)) - error ("pointers to bitfield members not allowed"); - - v = value_from_long (builtin_type_int, - (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3)); - VALUE_TYPE (v) = lookup_pointer_type ( - lookup_member_type (TYPE_FIELD_TYPE (t, i), baseclass)); - return v; - } - } - - if (TYPE_N_BASECLASSES (t) == 0) - break; - - t = TYPE_BASECLASS (t, 1); - } - - /* C++: If it was not found as a data field, then try to - return it as a pointer to a method. */ - t = baseclass; - - /* Destructors are a special case. */ - if (destructor_name_p (name, t)) - { - error ("pointers to destructors not implemented yet"); - } - - /* Perform all necessary dereferencing. */ - while (intype && TYPE_CODE (intype) == TYPE_CODE_PTR) - intype = TYPE_TARGET_TYPE (intype); - - while (t) - { - for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i) - { - if (!strcmp (TYPE_FN_FIELDLIST_NAME (t, i), name)) - { - int j = TYPE_FN_FIELDLIST_LENGTH (t, i); - struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); - - if (intype == 0 && j > 1) - error ("non-unique member `%s' requires type instantiation", name); - if (intype) - { - while (j--) - if (TYPE_FN_FIELD_TYPE (f, j) == intype) - break; - if (j < 0) - error ("no member function matches that type instantiation"); - } - else - j = 0; - - if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) - { - v = value_from_long (builtin_type_long, - (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j)); - } - else - { - struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j), - 0, VAR_NAMESPACE, 0); - v = locate_var_value (s, 0); - } - VALUE_TYPE (v) = lookup_pointer_type (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j), baseclass)); - return v; - } - } - - if (TYPE_N_BASECLASSES (t) == 0) - break; - - t = TYPE_BASECLASS (t, 1); - } - return 0; -} - -/* Compare two argument lists and return the position in which they differ, - or zero if equal. - - STATICP is nonzero if the T1 argument list came from a - static member function. - - For non-static member functions, we ignore the first argument, - which is the type of the instance variable. This is because we want - to handle calls with objects from derived classes. This is not - entirely correct: we should actually check to make sure that a - requested operation is type secure, shouldn't we? */ - -int -typecmp (staticp, t1, t2) - int staticp; - struct type *t1[]; - value t2[]; -{ - int i; - - if (staticp && t1 == 0) - return t2[1] != 0; - if (t1 == 0) - return 1; - if (t1[0]->code == TYPE_CODE_VOID) return 0; - if (t1[!staticp] == 0) return 0; - for (i = !staticp; t1[i] && t1[i]->code != TYPE_CODE_VOID; i++) - { - if (! t2[i] - || t1[i]->code != t2[i]->type->code - || t1[i]->target_type != t2[i]->type->target_type) - return i+1; - } - if (!t1[i]) return 0; - return t2[i] ? i+1 : 0; -} - -/* C++: return the value of the class instance variable, if one exists. - Flag COMPLAIN signals an error if the request is made in an - inappropriate context. */ -value -value_of_this (complain) - int complain; -{ - extern FRAME selected_frame; - struct symbol *func, *sym; - char *funname = 0; - struct block *b; - int i; - - if (selected_frame == 0) - if (complain) - error ("no frame selected"); - else return 0; - - func = get_frame_function (selected_frame); - if (func) - funname = SYMBOL_NAME (func); - else - if (complain) - error ("no `this' in nameless context"); - else return 0; - - b = SYMBOL_BLOCK_VALUE (func); - i = BLOCK_NSYMS (b); - if (i <= 0) - if (complain) - error ("no args, no `this'"); - else return 0; - - sym = BLOCK_SYM (b, 0); - if (strncmp ("$this", SYMBOL_NAME (sym), 5)) - if (complain) - error ("current stack frame not in method"); - else return 0; - - return read_var_value (sym, selected_frame); -} diff --git a/gnu/usr.bin/gdb/valprint.c b/gnu/usr.bin/gdb/valprint.c deleted file mode 100644 index 781eb29..0000000 --- a/gnu/usr.bin/gdb/valprint.c +++ /dev/null @@ -1,1430 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)valprint.c 6.5 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Print values for GNU debugger gdb. - Copyright (C) 1986, 1988, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "value.h" - -/* GNU software is only expected to run on systems with 32-bit integers. */ -#define UINT_MAX 0xffffffff - -/* Maximum number of chars to print for a string pointer value - or vector contents, or UINT_MAX for no limit. */ - -static unsigned int print_max; - -static void type_print_varspec_suffix (); -static void type_print_varspec_prefix (); -static void type_print_base (); -static void type_print_method_args (); - - -char **unsigned_type_table; -char **signed_type_table; -char **float_type_table; - - -/* Print repeat counts if there are more than this - many repetitions of an element in an array. */ -#define REPEAT_COUNT_THRESHOLD 10 - -/* Print the character string STRING, printing at most LENGTH characters. - Printing stops early if the number hits print_max; repeat counts - are printed as appropriate. Print ellipses at the end if we - had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */ - -void -print_string (stream, string, length, force_ellipses) - FILE *stream; - char *string; - unsigned int length; - int force_ellipses; -{ - register unsigned int i; - unsigned int things_printed = 0; - int in_quotes = 0; - int need_comma = 0; - - if (length == 0) - { - fputs_filtered ("\"\"", stdout); - return; - } - - for (i = 0; i < length && things_printed < print_max; ++i) - { - /* Position of the character we are examining - to see whether it is repeated. */ - unsigned int rep1; - /* Number of repititions we have detected so far. */ - unsigned int reps; - - QUIT; - - if (need_comma) - { - fputs_filtered (", ", stream); - need_comma = 0; - } - - rep1 = i + 1; - reps = 1; - while (rep1 < length && string[rep1] == string[i]) - { - ++rep1; - ++reps; - } - - if (reps > REPEAT_COUNT_THRESHOLD) - { - if (in_quotes) - { - fputs_filtered ("\", ", stream); - in_quotes = 0; - } - fputs_filtered ("'", stream); - printchar (string[i], stream, '\''); - fprintf_filtered (stream, "' ", reps); - i = rep1 - 1; - things_printed += REPEAT_COUNT_THRESHOLD; - need_comma = 1; - } - else - { - if (!in_quotes) - { - fputs_filtered ("\"", stream); - in_quotes = 1; - } - printchar (string[i], stream, '"'); - ++things_printed; - } - } - - /* Terminate the quotes if necessary. */ - if (in_quotes) - fputs_filtered ("\"", stream); - - if (force_ellipses || i < length) - fputs_filtered ("...", stream); -} - -/* Print the value VAL in C-ish syntax on stream STREAM. - FORMAT is a format-letter, or 0 for print in natural format of data type. - If the object printed is a string pointer, returns - the number of string bytes printed. */ - -int -value_print (val, stream, format, pretty) - value val; - FILE *stream; - char format; - enum val_prettyprint pretty; -{ - register unsigned int i, n, typelen; - - /* A "repeated" value really contains several values in a row. - They are made by the @ operator. - Print such values as if they were arrays. */ - - if (VALUE_REPEATED (val)) - { - n = VALUE_REPETITIONS (val); - typelen = TYPE_LENGTH (VALUE_TYPE (val)); - fprintf_filtered (stream, "{"); - /* Print arrays of characters using string syntax. */ - if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT - && format == 0) - print_string (stream, VALUE_CONTENTS (val), n, 0); - else - { - unsigned int things_printed = 0; - - for (i = 0; i < n && things_printed < print_max; i++) - { - /* Position of the array element we are examining to see - whether it is repeated. */ - unsigned int rep1; - /* Number of repititions we have detected so far. */ - unsigned int reps; - - if (i != 0) - fprintf_filtered (stream, ", "); - - rep1 = i + 1; - reps = 1; - while (rep1 < n - && !bcmp (VALUE_CONTENTS (val) + typelen * i, - VALUE_CONTENTS (val) + typelen * rep1, typelen)) - { - ++reps; - ++rep1; - } - - if (reps > REPEAT_COUNT_THRESHOLD) - { - val_print (VALUE_TYPE (val), - VALUE_CONTENTS (val) + typelen * i, - VALUE_ADDRESS (val) + typelen * i, - stream, format, 1, 0, pretty); - fprintf (stream, " ", reps); - i = rep1 - 1; - things_printed += REPEAT_COUNT_THRESHOLD; - } - else - { - val_print (VALUE_TYPE (val), - VALUE_CONTENTS (val) + typelen * i, - VALUE_ADDRESS (val) + typelen * i, - stream, format, 1, 0, pretty); - things_printed++; - } - } - if (i < n) - fprintf_filtered (stream, "..."); - } - fprintf_filtered (stream, "}"); - return n * typelen; - } - else - { - /* If it is a pointer, indicate what it points to. - - Print type also if it is a reference. - - C++: if it is a member pointer, we will take care - of that when we print it. */ - if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR - || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF) - { - fprintf_filtered (stream, "("); - type_print (VALUE_TYPE (val), "", stream, -1); - fprintf_filtered (stream, ") "); - - /* If this is a function pointer, try to print what - function it is pointing to by name. */ - if (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (val))) - == TYPE_CODE_FUNC) - { - print_address (((int *) VALUE_CONTENTS (val))[0], stream); - /* Return value is irrelevant except for string pointers. */ - return 0; - } - } - return val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), - VALUE_ADDRESS (val), stream, format, 1, 0, pretty); - } -} - -static int prettyprint; /* Controls prettyprinting of structures. */ -int unionprint; /* Controls printing of nested unions. */ -static void scalar_print_hack(); -void (*default_scalar_print)() = scalar_print_hack; - -/* Print data of type TYPE located at VALADDR (within GDB), - which came from the inferior at address ADDRESS, - onto stdio stream STREAM according to FORMAT - (a letter or 0 for natural format). - - If the data are a string pointer, returns the number of - sting characters printed. - - if DEREF_REF is nonzero, then dereference references, - otherwise just print them like pointers. - - The PRETTY parameter controls prettyprinting. */ - -int -val_print (type, valaddr, address, stream, format, - deref_ref, recurse, pretty) - struct type *type; - char *valaddr; - CORE_ADDR address; - FILE *stream; - char format; - int deref_ref; - int recurse; - enum val_prettyprint pretty; -{ - register unsigned int i; - int len, n_baseclasses; - struct type *elttype; - int eltlen; - LONGEST val; - unsigned char c; - - if (pretty == Val_pretty_default) - { - pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint; - } - - QUIT; - - if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) - { - fprintf_filtered (stream, ""); - fflush (stream); - return 0; - } - - switch (TYPE_CODE (type)) - { - case TYPE_CODE_ARRAY: - if (TYPE_LENGTH (type) >= 0 - && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) - { - elttype = TYPE_TARGET_TYPE (type); - eltlen = TYPE_LENGTH (elttype); - len = TYPE_LENGTH (type) / eltlen; - fprintf_filtered (stream, "{"); - /* For an array of chars, print with string syntax. */ - if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT - && format == 0) - print_string (stream, valaddr, len, 0); - else - { - unsigned int things_printed = 0; - - for (i = 0; i < len && things_printed < print_max; i++) - { - /* Position of the array element we are examining to see - whether it is repeated. */ - unsigned int rep1; - /* Number of repititions we have detected so far. */ - unsigned int reps; - - if (i > 0) - fprintf_filtered (stream, ", "); - - rep1 = i + 1; - reps = 1; - while (rep1 < len - && !bcmp (valaddr + i * eltlen, - valaddr + rep1 * eltlen, eltlen)) - { - ++reps; - ++rep1; - } - - if (reps > REPEAT_COUNT_THRESHOLD) - { - val_print (elttype, valaddr + i * eltlen, - 0, stream, format, deref_ref, - recurse + 1, pretty); - fprintf_filtered (stream, " ", reps); - i = rep1 - 1; - things_printed += REPEAT_COUNT_THRESHOLD; - } - else - { - val_print (elttype, valaddr + i * eltlen, - 0, stream, format, deref_ref, - recurse + 1, pretty); - things_printed++; - } - } - if (i < len) - fprintf_filtered (stream, "..."); - } - fprintf_filtered (stream, "}"); - break; - } - /* Array of unspecified length: treat like pointer to first elt. */ - valaddr = (char *) &address; - - case TYPE_CODE_PTR: - if (format) - { - print_scalar_formatted (valaddr, type, format, 0, stream); - break; - } - if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD) - { - struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)); - struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)); - struct fn_field *f; - int j, len2; - char *kind = ""; - - val = unpack_long (builtin_type_int, valaddr); - if (val < 128) - { - len = TYPE_NFN_FIELDS (domain); - for (i = 0; i < len; i++) - { - f = TYPE_FN_FIELDLIST1 (domain, i); - len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i); - - for (j = 0; j < len2; j++) - { - QUIT; - if (TYPE_FN_FIELD_VOFFSET (f, j) == val) - { - kind = "virtual"; - goto common; - } - } - } - } - else - { - struct symbol *sym = find_pc_function ((CORE_ADDR) val); - if (sym == 0) - error ("invalid pointer to member function"); - len = TYPE_NFN_FIELDS (domain); - for (i = 0; i < len; i++) - { - f = TYPE_FN_FIELDLIST1 (domain, i); - len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i); - - for (j = 0; j < len2; j++) - { - QUIT; - if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j))) - goto common; - } - } - } - common: - if (i < len) - { - fprintf_filtered (stream, "&"); - type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0); - fprintf (stream, kind); - if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' - && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$') - type_print_method_args - (TYPE_FN_FIELD_ARGS (f, j) + 1, "~", - TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream); - else - type_print_method_args - (TYPE_FN_FIELD_ARGS (f, j), "", - TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream); - break; - } - fprintf_filtered (stream, "("); - type_print (type, "", stream, -1); - fprintf_filtered (stream, ") %d", (int) val >> 3); - } - else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER) - { - struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)); - struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)); - char *kind = ""; - - /* VAL is a byte offset into the structure type DOMAIN. - Find the name of the field for that offset and - print it. */ - int extra = 0; - int bits = 0; - len = TYPE_NFIELDS (domain); - /* @@ Make VAL into bit offset */ - val = unpack_long (builtin_type_int, valaddr) << 3; - for (i = 0; i < len; i++) - { - int bitpos = TYPE_FIELD_BITPOS (domain, i); - QUIT; - if (val == bitpos) - break; - if (val < bitpos && i > 0) - { - int ptrsize = (TYPE_LENGTH (builtin_type_char) * TYPE_LENGTH (target)); - /* Somehow pointing into a field. */ - i -= 1; - extra = (val - TYPE_FIELD_BITPOS (domain, i)); - if (extra & 0x3) - bits = 1; - else - extra >>= 3; - break; - } - } - if (i < len) - { - fprintf_filtered (stream, "&"); - type_print_base (domain, stream, 0, 0); - fprintf_filtered (stream, "::"); - fputs_filtered (TYPE_FIELD_NAME (domain, i), stream); - if (extra) - fprintf_filtered (stream, " + %d bytes", extra); - if (bits) - fprintf_filtered (stream, " (offset in bits)"); - break; - } - fprintf_filtered (stream, "%d", val >> 3); - } - else - { - fprintf_filtered (stream, "0x%x", * (int *) valaddr); - /* For a pointer to char or unsigned char, - also print the string pointed to, unless pointer is null. */ - - /* For an array of chars, print with string syntax. */ - elttype = TYPE_TARGET_TYPE (type); - i = 0; /* Number of characters printed. */ - if (TYPE_LENGTH (elttype) == 1 - && TYPE_CODE (elttype) == TYPE_CODE_INT - && format == 0 - && unpack_long (type, valaddr) != 0 - /* If print_max is UINT_MAX, the alloca below will fail. - In that case don't try to print the string. */ - && print_max < UINT_MAX) - { - fprintf_filtered (stream, " "); - - /* Get first character. */ - if (read_memory ( (CORE_ADDR) unpack_long (type, valaddr), - &c, 1)) - { - /* First address out of bounds. */ - fprintf_filtered (stream, "
", - (* (int *) valaddr)); - break; - } - else - { - /* A real string. */ - int out_of_bounds = 0; - char *string = (char *) alloca (print_max); - - /* If the loop ends by us hitting print_max characters, - we need to have elipses at the end. */ - int force_ellipses = 1; - - /* This loop only fetches print_max characters, even - though print_string might want to print more - (with repeated characters). This is so that - we don't spend forever fetching if we print - a long string consisting of the same character - repeated. */ - while (i < print_max) - { - QUIT; - if (read_memory ((CORE_ADDR) unpack_long (type, valaddr) - + i, &c, 1)) - { - out_of_bounds = 1; - force_ellipses = 0; - break; - } - else if (c == '\0') - { - force_ellipses = 0; - break; - } - else - string[i++] = c; - } - - if (i != 0) - print_string (stream, string, i, force_ellipses); - if (out_of_bounds) - fprintf_filtered (stream, - "
", - (*(int *) valaddr) + i); - } - - fflush (stream); - } - /* Return number of characters printed, plus one for the - terminating null if we have "reached the end". */ - return i + (print_max && i != print_max); - } - break; - - case TYPE_CODE_MEMBER: - error ("not implemented: member type in val_print"); - break; - - case TYPE_CODE_REF: - fprintf_filtered (stream, "(0x%x &) = ", * (int *) valaddr); - /* De-reference the reference. */ - if (deref_ref) - { - if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF) - { - value val = value_at (TYPE_TARGET_TYPE (type), * (int *) valaddr); - val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), - VALUE_ADDRESS (val), stream, format, - deref_ref, recurse + 1, pretty); - } - else - fprintf_filtered (stream, "???"); - } - break; - - case TYPE_CODE_UNION: - if (recurse && !unionprint) - { - fprintf_filtered (stream, "{...}"); - break; - } - /* Fall through. */ - case TYPE_CODE_STRUCT: - fprintf_filtered (stream, "{"); - len = TYPE_NFIELDS (type); - n_baseclasses = TYPE_N_BASECLASSES (type); - for (i = 1; i <= n_baseclasses; i++) - { - fprintf_filtered (stream, "\n"); - if (pretty) - print_spaces_filtered (2 + 2 * recurse, stream); - fputs_filtered ("<", stream); - fputs_filtered (TYPE_NAME (TYPE_BASECLASS (type, i)), stream); - fputs_filtered ("> = ", stream); - val_print (TYPE_FIELD_TYPE (type, 0), - valaddr + TYPE_FIELD_BITPOS (type, i-1) / 8, - 0, stream, 0, 0, recurse + 1, pretty); - } - if (i > 1) { - fprintf_filtered (stream, "\n"); - print_spaces_filtered (2 + 2 * recurse, stream); - fputs_filtered ("members of ", stream); - fputs_filtered (TYPE_NAME (type), stream); - fputs_filtered (": ", stream); - } - if (!len && i == 1) - fprintf_filtered (stream, ""); - else - { - for (i -= 1; i < len; i++) - { - if (i > n_baseclasses) fprintf_filtered (stream, ", "); - if (pretty) - { - fprintf_filtered (stream, "\n"); - print_spaces_filtered (2 + 2 * recurse, stream); - } - fputs_filtered (TYPE_FIELD_NAME (type, i), stream); - fputs_filtered (" = ", stream); - /* check if static field */ - if (TYPE_FIELD_STATIC (type, i)) - { - value v; - - v = value_static_field (type, TYPE_FIELD_NAME (type, i), i); - val_print (TYPE_FIELD_TYPE (type, i), - VALUE_CONTENTS (v), 0, stream, format, - deref_ref, recurse + 1, pretty); - } - else if (TYPE_FIELD_PACKED (type, i)) - { - char *valp = (char *) & val; - union {int i; char c;} test; - test.i = 1; - if (test.c != 1) - valp += sizeof val - TYPE_LENGTH (TYPE_FIELD_TYPE (type, i)); - val = unpack_field_as_long (type, valaddr, i); - val_print (TYPE_FIELD_TYPE (type, i), valp, 0, - stream, format, deref_ref, recurse + 1, pretty); - } - else - { - val_print (TYPE_FIELD_TYPE (type, i), - valaddr + TYPE_FIELD_BITPOS (type, i) / 8, - 0, stream, format, deref_ref, - recurse + 1, pretty); - } - } - if (pretty) - { - fprintf_filtered (stream, "\n"); - print_spaces_filtered (2 * recurse, stream); - } - } - fprintf_filtered (stream, "}"); - break; - - case TYPE_CODE_ENUM: - if (format) - { - print_scalar_formatted (valaddr, type, format, 0, stream); - break; - } - len = TYPE_NFIELDS (type); - val = unpack_long (builtin_type_int, valaddr); - for (i = 0; i < len; i++) - { - QUIT; - if (val == TYPE_FIELD_BITPOS (type, i)) - break; - } - if (i < len) - fputs_filtered (TYPE_FIELD_NAME (type, i), stream); - else - fprintf_filtered (stream, "%d", (int) val); - break; - - case TYPE_CODE_FUNC: - if (format) - { - print_scalar_formatted (valaddr, type, format, 0, stream); - break; - } - fprintf_filtered (stream, "{"); - type_print (type, "", stream, -1); - fprintf_filtered (stream, "} "); - fprintf_filtered (stream, "0x%x", address); - break; - - case TYPE_CODE_INT: - if (format) - print_scalar_formatted (valaddr, type, format, 0, stream); - else - { - (*default_scalar_print)(stream, type, unpack_long(type, valaddr)); -#ifdef notdef - if (TYPE_LENGTH (type) == 1) - { - fprintf_filtered (stream, " '"); - printchar ((unsigned char) unpack_long (type, valaddr), - stream, '\''); - fprintf_filtered (stream, "'"); - } -#endif - } - break; - - case TYPE_CODE_FLT: - if (format) - print_scalar_formatted (valaddr, type, format, 0, stream); - else - print_floating (valaddr, type, stream); - break; - - case TYPE_CODE_VOID: - fprintf_filtered (stream, "void"); - break; - - default: - error ("Invalid type code in symbol table."); - } - fflush (stream); - return 0; -} - -/* Print a description of a type TYPE - in the form of a declaration of a variable named VARSTRING. - Output goes to STREAM (via stdio). - If SHOW is positive, we show the contents of the outermost level - of structure even if there is a type name that could be used instead. - If SHOW is negative, we never show the details of elements' types. */ - -void -type_print (type, varstring, stream, show) - struct type *type; - char *varstring; - FILE *stream; - int show; -{ - type_print_1 (type, varstring, stream, show, 0); -} - -/* LEVEL is the depth to indent lines by. */ - -void -type_print_1 (type, varstring, stream, show, level) - struct type *type; - char *varstring; - FILE *stream; - int show; - int level; -{ - register enum type_code code; - type_print_base (type, stream, show, level); - code = TYPE_CODE (type); - if ((varstring && *varstring) - || - /* Need a space if going to print stars or brackets; - but not if we will print just a type name. */ - ((show > 0 || TYPE_NAME (type) == 0) - && - (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC - || code == TYPE_CODE_METHOD - || code == TYPE_CODE_ARRAY - || code == TYPE_CODE_MEMBER - || code == TYPE_CODE_REF))) - fprintf_filtered (stream, " "); - type_print_varspec_prefix (type, stream, show, 0); - fputs_filtered (varstring, stream); - type_print_varspec_suffix (type, stream, show, 0); -} - -/* Print the method arguments ARGS to the file STREAM. */ -static void -type_print_method_args (args, prefix, varstring, staticp, stream) - struct type **args; - char *prefix, *varstring; - int staticp; - FILE *stream; -{ - int i; - - fputs_filtered (" ", stream); - fputs_filtered (prefix, stream); - fputs_filtered (varstring, stream); - fputs_filtered (" (", stream); - if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID) - { - i = !staticp; /* skip the class variable */ - while (1) - { - type_print (args[i++], "", stream, 0); - if (!args[i]) - { - fprintf_filtered (stream, " ..."); - break; - } - else if (args[i]->code != TYPE_CODE_VOID) - { - fprintf_filtered (stream, ", "); - } - else break; - } - } - fprintf_filtered (stream, ")"); -} - -/* If TYPE is a derived type, then print out derivation - information. Print out all layers of the type heirarchy - until we encounter one with multiple inheritance. - At that point, print out that ply, and return. */ -static void -type_print_derivation_info (stream, type) - FILE *stream; - struct type *type; -{ - char *name; - int i, n_baseclasses = TYPE_N_BASECLASSES (type); - struct type *basetype = 0; - - while (type && n_baseclasses == 1) - { - basetype = TYPE_BASECLASS (type, 1); - if (TYPE_NAME (basetype) && (name = TYPE_NAME (basetype))) - { - while (*name != ' ') name++; - fprintf_filtered (stream, ": %s%s ", - TYPE_VIA_PUBLIC (basetype) ? "public" : "private", - TYPE_VIA_VIRTUAL (basetype) ? " virtual" : ""); - fputs_filtered (name + 1, stream); - fputs_filtered (" ", stream); - } - n_baseclasses = TYPE_N_BASECLASSES (basetype); - type = basetype; - } - - if (type) - { - if (n_baseclasses != 0) - fprintf_filtered (stream, ": "); - for (i = 1; i <= n_baseclasses; i++) - { - basetype = TYPE_BASECLASS (type, i); - if (TYPE_NAME (basetype) && (name = TYPE_NAME (basetype))) - { - while (*name != ' ') name++; - fprintf_filtered (stream, "%s%s ", - TYPE_VIA_PUBLIC (basetype) ? "public" : "private", - TYPE_VIA_VIRTUAL (basetype) ? " virtual" : ""); - fputs_filtered (name + 1, stream); - } - if (i < n_baseclasses) - fprintf_filtered (stream, ", "); - } - fprintf_filtered (stream, " "); - } -} - -/* Print any asterisks or open-parentheses needed before the - variable name (to describe its type). - - On outermost call, pass 0 for PASSED_A_PTR. - On outermost call, SHOW > 0 means should ignore - any typename for TYPE and show its details. - SHOW is always zero on recursive calls. */ - -static void -type_print_varspec_prefix (type, stream, show, passed_a_ptr) - struct type *type; - FILE *stream; - int show; - int passed_a_ptr; -{ - if (type == 0) - return; - - if (TYPE_NAME (type) && show <= 0) - return; - - QUIT; - - switch (TYPE_CODE (type)) - { - case TYPE_CODE_PTR: - type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); - fprintf_filtered (stream, "*"); - break; - - case TYPE_CODE_MEMBER: - if (passed_a_ptr) - fprintf_filtered (stream, "("); - type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, - 0); - fprintf_filtered (stream, " "); - type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, - passed_a_ptr); - fprintf_filtered (stream, "::"); - break; - - case TYPE_CODE_METHOD: - if (passed_a_ptr) - fprintf (stream, "("); - type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, - 0); - fprintf_filtered (stream, " "); - type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, - passed_a_ptr); - fprintf_filtered (stream, "::"); - break; - - case TYPE_CODE_REF: - type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1); - fprintf_filtered (stream, "&"); - break; - - case TYPE_CODE_FUNC: - type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, - 0); - if (passed_a_ptr) - fprintf_filtered (stream, "("); - break; - - case TYPE_CODE_ARRAY: - type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, - 0); - if (passed_a_ptr) - fprintf_filtered (stream, "("); - } -} - -/* Print any array sizes, function arguments or close parentheses - needed after the variable name (to describe its type). - Args work like type_print_varspec_prefix. */ - -static void -type_print_varspec_suffix (type, stream, show, passed_a_ptr) - struct type *type; - FILE *stream; - int show; - int passed_a_ptr; -{ - if (type == 0) - return; - - if (TYPE_NAME (type) && show <= 0) - return; - - QUIT; - - switch (TYPE_CODE (type)) - { - case TYPE_CODE_ARRAY: - if (passed_a_ptr) - fprintf_filtered (stream, ")"); - - fprintf_filtered (stream, "["); - if (TYPE_LENGTH (type) >= 0 - && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0) - fprintf_filtered (stream, "%d", - (TYPE_LENGTH (type) - / TYPE_LENGTH (TYPE_TARGET_TYPE (type)))); - fprintf_filtered (stream, "]"); - - type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, - 0); - break; - - case TYPE_CODE_MEMBER: - if (passed_a_ptr) - fprintf_filtered (stream, ")"); - type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0); - break; - - case TYPE_CODE_METHOD: - if (passed_a_ptr) - fprintf_filtered (stream, ")"); - type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0); - if (passed_a_ptr) - { - int i; - struct type **args = TYPE_ARG_TYPES (type); - - fprintf_filtered (stream, "("); - if (args[1] == 0) - fprintf_filtered (stream, "..."); - else for (i = 1; args[i] != 0 && args[i]->code != TYPE_CODE_VOID; i++) - { - type_print_1 (args[i], "", stream, -1, 0); - if (args[i+1] == 0) - fprintf_filtered (stream, "..."); - else if (args[i+1]->code != TYPE_CODE_VOID) - fprintf_filtered (stream, ","); - } - fprintf_filtered (stream, ")"); - } - break; - - case TYPE_CODE_PTR: - case TYPE_CODE_REF: - type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1); - break; - - case TYPE_CODE_FUNC: - type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, - passed_a_ptr); - if (passed_a_ptr) - fprintf_filtered (stream, ")"); - fprintf_filtered (stream, "()"); - break; - } -} - -/* Print the name of the type (or the ultimate pointer target, - function value or array element), or the description of a - structure or union. - - SHOW nonzero means don't print this type as just its name; - show its real definition even if it has a name. - SHOW zero means print just typename or struct tag if there is one - SHOW negative means abbreviate structure elements. - SHOW is decremented for printing of structure elements. - - LEVEL is the depth to indent by. - We increase it for some recursive calls. */ - -static void -type_print_base (type, stream, show, level) - struct type *type; - FILE *stream; - int show; - int level; -{ - char *name; - register int i; - register int len; - register int lastval; - - QUIT; - - if (type == 0) - { - fprintf_filtered (stream, "type unknown"); - return; - } - - if (TYPE_NAME (type) && show <= 0) - { - fputs_filtered (TYPE_NAME (type), stream); - return; - } - - switch (TYPE_CODE (type)) - { - case TYPE_CODE_ARRAY: - case TYPE_CODE_PTR: - case TYPE_CODE_MEMBER: - case TYPE_CODE_REF: - case TYPE_CODE_FUNC: - case TYPE_CODE_METHOD: - type_print_base (TYPE_TARGET_TYPE (type), stream, show, level); - break; - - case TYPE_CODE_STRUCT: - fprintf_filtered (stream, "struct "); - goto struct_union; - - case TYPE_CODE_UNION: - fprintf_filtered (stream, "union "); - struct_union: - if (TYPE_NAME (type) && (name = TYPE_NAME (type))) - { - while (*name != ' ') name++; - fputs_filtered (name + 1, stream); - fputs_filtered (" ", stream); - } - if (show < 0) - fprintf_filtered (stream, "{...}"); - else - { - int i; - - type_print_derivation_info (stream, type); - - fprintf_filtered (stream, "{"); - len = TYPE_NFIELDS (type); - if (len) - fprintf_filtered (stream, "\n"); - else - { - if (TYPE_FLAGS (type) & TYPE_FLAG_STUB) - fprintf_filtered (stream, "\n"); - else - fprintf_filtered (stream, "\n"); - } - - /* If there is a base class for this type, - do not print the field that it occupies. */ - for (i = TYPE_N_BASECLASSES (type); i < len; i++) - { - QUIT; - /* Don't print out virtual function table. */ - if (! strncmp (TYPE_FIELD_NAME (type, i), - "_vptr$", 6)) - continue; - - print_spaces_filtered (level + 4, stream); - if (TYPE_FIELD_STATIC (type, i)) - { - fprintf_filtered (stream, "static "); - } - type_print_1 (TYPE_FIELD_TYPE (type, i), - TYPE_FIELD_NAME (type, i), - stream, show - 1, level + 4); - if (!TYPE_FIELD_STATIC (type, i) - && TYPE_FIELD_PACKED (type, i)) - { - /* It is a bitfield. This code does not attempt - to look at the bitpos and reconstruct filler, - unnamed fields. This would lead to misleading - results if the compiler does not put out fields - for such things (I don't know what it does). */ - fprintf_filtered (stream, " : %d", - TYPE_FIELD_BITSIZE (type, i)); - } - fprintf_filtered (stream, ";\n"); - } - - /* C++: print out the methods */ - len = TYPE_NFN_FIELDS (type); - if (len) fprintf_filtered (stream, "\n"); - for (i = 0; i < len; i++) - { - struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i); - int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i); - - for (j = 0; j < len2; j++) - { - QUIT; - print_spaces_filtered (level + 4, stream); - if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) - fprintf_filtered (stream, "virtual "); - else if (TYPE_FN_FIELD_STATIC_P (f, j)) - fprintf_filtered (stream, "static "); - type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)), "", stream, 0); - if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_' - && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$') - type_print_method_args - (TYPE_FN_FIELD_ARGS (f, j) + 1, "~", - TYPE_FN_FIELDLIST_NAME (type, i), 0, stream); - else - type_print_method_args - (TYPE_FN_FIELD_ARGS (f, j), "", - TYPE_FN_FIELDLIST_NAME (type, i), - TYPE_FN_FIELD_STATIC_P (f, j), stream); - - fprintf_filtered (stream, ";\n"); - } - if (len2) fprintf_filtered (stream, "\n"); - } - - print_spaces_filtered (level, stream); - fprintf_filtered (stream, "}"); - } - break; - - case TYPE_CODE_ENUM: - fprintf_filtered (stream, "enum "); - if (TYPE_NAME (type)) - { - name = TYPE_NAME (type); - while (*name != ' ') name++; - fputs_filtered (name + 1, stream); - fputs_filtered (" ", stream); - } - if (show < 0) - fprintf_filtered (stream, "{...}"); - else - { - fprintf_filtered (stream, "{"); - len = TYPE_NFIELDS (type); - lastval = 0; - for (i = 0; i < len; i++) - { - QUIT; - if (i) fprintf_filtered (stream, ", "); - fputs_filtered (TYPE_FIELD_NAME (type, i), stream); - if (lastval != TYPE_FIELD_BITPOS (type, i)) - { - fprintf_filtered (stream, " : %d", TYPE_FIELD_BITPOS (type, i)); - lastval = TYPE_FIELD_BITPOS (type, i); - } - lastval++; - } - fprintf_filtered (stream, "}"); - } - break; - - case TYPE_CODE_INT: - if (TYPE_UNSIGNED (type)) - name = unsigned_type_table[TYPE_LENGTH (type)]; - else - name = signed_type_table[TYPE_LENGTH (type)]; - fputs_filtered (name, stream); - break; - - case TYPE_CODE_FLT: - name = float_type_table[TYPE_LENGTH (type)]; - fputs_filtered (name, stream); - break; - - case TYPE_CODE_VOID: - fprintf_filtered (stream, "void"); - break; - - case 0: - fprintf_filtered (stream, "struct unknown"); - break; - - default: - error ("Invalid type code in symbol table."); - } -} - -static void -scalar_print_decimal(stream, type, val) - FILE *stream; - struct type *type; - LONGEST val; -{ - fprintf_filtered(stream, TYPE_UNSIGNED(type)? "%lu":"%ld", val); -} - -static void -scalar_print_hex(stream, type, val) - FILE *stream; - struct type *type; - LONGEST val; -{ - switch (TYPE_LENGTH(type)) { - case 1: - fprintf_filtered (stream, "0x%02lx", val); - break; - case 2: - fprintf_filtered (stream, "0x%04lx", val); - break; - case 4: - fprintf_filtered (stream, "0x%08lx", val); - break; - default: - fprintf_filtered (stream, "0x%lx", val); - break; - } -} - -static void -scalar_print_octal(stream, type, val) - FILE *stream; - struct type *type; - LONGEST val; -{ - switch (TYPE_LENGTH(type)) { - case 1: - fprintf_filtered (stream, "0%03lo", val); - break; - case 2: - fprintf_filtered (stream, "0%06lo", val); - break; - case 4: - fprintf_filtered (stream, "0%012lo", val); - break; - default: - fprintf_filtered (stream, "0%lo", val); - break; - } -} - -static void -scalar_print_hack(stream, type, val) - FILE *stream; - struct type *type; - LONGEST val; -{ - if (TYPE_UNSIGNED(type)) - scalar_print_hex(stream, type, val); - else - scalar_print_decimal(stream, type, val); -} - -static void -set_maximum_command (arg) - char *arg; -{ - if (!arg) error_no_arg ("value for maximum elements to print"); - print_max = parse_and_eval_address (arg); - if (print_max == 0) - print_max = UINT_MAX; -} - -static void -set_base_command(arg) - char *arg; -{ - int base; - - if (!arg) - base = 0; - else - base = parse_and_eval_address (arg); - switch (base) { - default: - default_scalar_print = scalar_print_hack; - break; - case 8: - default_scalar_print = scalar_print_octal; - break; - case 10: - default_scalar_print = scalar_print_decimal; - break; - case 16: - default_scalar_print = scalar_print_hex; - break; - } -} - -static void -set_prettyprint_command (arg, from_tty) - char *arg; - int from_tty; -{ - prettyprint = parse_binary_operation ("set prettyprint", arg); -} - -static void -set_unionprint_command (arg, from_tty) - char *arg; - int from_tty; -{ - unionprint = parse_binary_operation ("set unionprint", arg); -} - -format_info (arg, from_tty) - char *arg; - int from_tty; -{ - if (arg) - error ("\"info format\" does not take any arguments."); - printf ("Prettyprinting of structures is %s.\n", - prettyprint ? "on" : "off"); - printf ("Printing of unions interior to structures is %s.\n", - unionprint ? "on" : "off"); - if (print_max == UINT_MAX) - printf_filtered - ("There is no maximum number of array elements printed.\n"); - else - printf_filtered - ("The maximum number of array elements printed is %d.\n", print_max); -} - -extern struct cmd_list_element *setlist; - -void -_initialize_valprint () -{ - add_cmd ("base", class_support, set_base_command, - "Change default integer print radix to 8, 10 or 16\n\ -No args returns to the ad-hoc default of `16' for unsigned values\n\ -and `10' otherwise.", - &setlist); - add_cmd ("array-max", class_vars, set_maximum_command, - "Set NUMBER as limit on string chars or array elements to print.\n\ -\"set array-max 0\" causes there to be no limit.", - &setlist); - - add_cmd ("prettyprint", class_support, set_prettyprint_command, - "Turn prettyprinting of structures on and off.", - &setlist); - add_alias_cmd ("pp", "prettyprint", class_support, 1, &setlist); - - add_cmd ("unionprint", class_support, set_unionprint_command, - "Turn printing of unions interior to structures on and off.", - &setlist); - - add_info ("format", format_info, - "Show current settings of data formatting options."); - - /* Give people the defaults which they are used to. */ - prettyprint = 0; - unionprint = 1; - - print_max = 200; - - unsigned_type_table - = (char **) xmalloc ((1 + sizeof (unsigned LONGEST)) * sizeof (char *)); - bzero (unsigned_type_table, (1 + sizeof (unsigned LONGEST))); - unsigned_type_table[sizeof (unsigned char)] = "unsigned char"; - unsigned_type_table[sizeof (unsigned short)] = "unsigned short"; - unsigned_type_table[sizeof (unsigned long)] = "unsigned long"; - unsigned_type_table[sizeof (unsigned int)] = "unsigned int"; -#ifdef LONG_LONG - unsigned_type_table[sizeof (unsigned long long)] = "unsigned long long"; -#endif - - signed_type_table - = (char **) xmalloc ((1 + sizeof (LONGEST)) * sizeof (char *)); - bzero (signed_type_table, (1 + sizeof (LONGEST))); - signed_type_table[sizeof (char)] = "char"; - signed_type_table[sizeof (short)] = "short"; - signed_type_table[sizeof (long)] = "long"; - signed_type_table[sizeof (int)] = "int"; -#ifdef LONG_LONG - signed_type_table[sizeof (long long)] = "long long"; -#endif - - float_type_table - = (char **) xmalloc ((1 + sizeof (double)) * sizeof (char *)); - bzero (float_type_table, (1 + sizeof (double))); - float_type_table[sizeof (float)] = "float"; - float_type_table[sizeof (double)] = "double"; -} - diff --git a/gnu/usr.bin/gdb/value.h b/gnu/usr.bin/gdb/value.h deleted file mode 100644 index 07dd8e8..0000000 --- a/gnu/usr.bin/gdb/value.h +++ /dev/null @@ -1,212 +0,0 @@ -/* Definitions for values of C expressions, for GDB. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* - * The structure which defines the type of a value. It should never - * be possible for a program lval value to survive over a call to the inferior - * (ie to be put into the history list or an internal variable). - */ -enum lval_type { - /* Not an lval. */ - not_lval, - /* In memory. Could be a saved register. */ - lval_memory, - /* In a register. */ - lval_register, - /* In a gdb internal variable. */ - lval_internalvar, - /* Part of a gdb internal variable (structure field). */ - lval_internalvar_component, - /* In a register series in a frame not the current one, which may have been - partially saved or saved in different places (otherwise would be - lval_register or lval_memory). */ - lval_reg_frame_relative, -}; - -struct value - { - /* Type of value; either not an lval, or one of the various - different possible kinds of lval. */ - enum lval_type lval; - /* Location of value (if lval). */ - union - { - /* Address in inferior or byte of registers structure. */ - CORE_ADDR address; - /* Pointer to interrnal variable. */ - struct internalvar *internalvar; - /* Number of register. Only used with - lval_reg_frame_relative. */ - int regnum; - } location; - /* Describes offset of a value within lval a structure in bytes. */ - int offset; - /* Only used for bitfields; number of bits contained in them. */ - int bitsize; - /* Only used for bitfields; position of start of field. */ - int bitpos; - /* Frame value is relative to. In practice, this address is only - used if the value is stored in several registers in other than - the current frame, and these registers have not all been saved - at the same place in memory. This will be described in the - lval enum above as "lval_reg_frame_relative". */ - CORE_ADDR frame_addr; - /* Type of the value. */ - struct type *type; - /* Values are stored in a chain, so that they can be deleted - easily over calls to the inferior. Values assigned to internal - variables or put into the value history are taken off this - list. */ - struct value *next; - /* If an lval is forced to repeat, a new value is created with - these fields set. The new value is not an lval. */ - short repeated; - short repetitions; - /* Register number if the value is from a register. Is not kept - if you take a field of a structure that is stored in a - register. Shouldn't it be? */ - short regno; - /* Actual contents of the value. For use of this value; setting - it uses the stuff above. */ - long contents[1]; - }; - -typedef struct value *value; - -#define VALUE_TYPE(val) (val)->type -#define VALUE_CONTENTS(val) ((char *) (val)->contents) -#define VALUE_LVAL(val) (val)->lval -#define VALUE_ADDRESS(val) (val)->location.address -#define VALUE_INTERNALVAR(val) (val)->location.internalvar -#define VALUE_FRAME_REGNUM(val) ((val)->location.regnum) -#define VALUE_FRAME(val) ((val)->frame_addr) -#define VALUE_OFFSET(val) (val)->offset -#define VALUE_BITSIZE(val) (val)->bitsize -#define VALUE_BITPOS(val) (val)->bitpos -#define VALUE_NEXT(val) (val)->next -#define VALUE_REPEATED(val) (val)->repeated -#define VALUE_REPETITIONS(val) (val)->repetitions -#define VALUE_REGNO(val) (val)->regno - -/* If ARG is an array, convert it to a pointer. - If ARG is an enum, convert it to an integer. - - References are dereferenced. */ - -#define COERCE_ARRAY(arg) \ -{ if (TYPE_CODE ( VALUE_TYPE (arg)) == TYPE_CODE_REF) \ - arg = value_ind (arg); \ - if (VALUE_REPEATED (arg) \ - || TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ARRAY) \ - arg = value_coerce_array (arg); \ - if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM) \ - arg = value_cast (builtin_type_unsigned_int, arg); \ -} - -/* If ARG is an enum, convert it to an integer. */ - -#define COERCE_ENUM(arg) \ -{ if (TYPE_CODE ( VALUE_TYPE (arg)) == TYPE_CODE_REF) \ - arg = value_ind (arg); \ - if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ENUM) \ - arg = value_cast (builtin_type_unsigned_int, arg); \ -} - -/* Internal variables (variables for convenience of use of debugger) - are recorded as a chain of these structures. */ - -struct internalvar -{ - struct internalvar *next; - char *name; - value value; -}; - -LONGEST value_as_long (); -double value_as_double (); -LONGEST unpack_long (); -double unpack_double (); -long unpack_field_as_long (); -value value_from_long (); -value value_from_double (); -value value_at (); -value value_from_register (); -value value_of_variable (); -value value_of_register (); -value read_var_value (); -value locate_var_value (); -value allocate_value (); -value allocate_repeat_value (); -value value_string (); - -value value_binop (); -value value_add (); -value value_sub (); -value value_coerce_array (); -value value_ind (); -value value_addr (); -value value_assign (); -value value_neg (); -value value_lognot (); -value value_struct_elt (), value_struct_elt_for_address (); -value value_field (); -value value_cast (); -value value_zero (); -value value_repeat (); -value value_subscript (); - -value call_function (); -value value_being_returned (); -int using_struct_return (); - -value evaluate_expression (); -value evaluate_type (); -value parse_and_eval (); -value parse_to_comma_and_eval (); - -value access_value_history (); -value value_of_internalvar (); -struct internalvar *lookup_internalvar (); - -int value_equal (); -int value_less (); -int value_zerop (); - -/* C++ */ -value value_of_this (); -value value_static_field (); -value value_x_binop (); -value value_x_unop (); -int binop_user_defined_p (); -int unop_user_defined_p (); - -void read_register_bytes (); -void modify_field (); -void type_print (); -void type_print_1 (); - -/* Possibilities for prettyprint parameters to routines which print - things. */ -enum val_prettyprint { - Val_no_prettyprint = 0, - Val_prettyprint, - /* Use the default setting which the user has specified. */ - Val_pretty_default - }; - diff --git a/gnu/usr.bin/gdb/values.c b/gnu/usr.bin/gdb/values.c deleted file mode 100644 index 93a2911..0000000 --- a/gnu/usr.bin/gdb/values.c +++ /dev/null @@ -1,1059 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - */ - -#ifndef lint -static char sccsid[] = "@(#)values.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* Low level packing and unpacking of values for GDB. - Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc. - -This file is part of GDB. - -GDB 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 1, or (at your option) -any later version. - -GDB 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 GDB; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#include -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "value.h" - -/* The value-history records all the values printed - by print commands during this session. Each chunk - records 60 consecutive values. The first chunk on - the chain records the most recent values. - The total number of values is in value_history_count. */ - -#define VALUE_HISTORY_CHUNK 60 - -struct value_history_chunk -{ - struct value_history_chunk *next; - value values[VALUE_HISTORY_CHUNK]; -}; - -/* Chain of chunks now in use. */ - -static struct value_history_chunk *value_history_chain; - -static int value_history_count; /* Abs number of last entry stored */ - - -/* List of all value objects currently allocated - (except for those released by calls to release_value) - This is so they can be freed after each command. */ - -static value all_values; - -/* Allocate a value that has the correct length for type TYPE. */ - -value -allocate_value (type) - struct type *type; -{ - register value val; - - /* If the type we want had no definition in the file it first - * appeared in, it will be marked a `stub'. The real definition - * probably appeared later so try to find it. */ - if (TYPE_FLAGS(type) & TYPE_FLAG_STUB) - { - register char *cp; - register struct symbol *sym; - extern char *index(); - - if (cp = index(TYPE_NAME(type), ' ')) - ++cp; - else - cp = TYPE_NAME(type); - - sym = lookup_symbol(cp, 0, STRUCT_NAMESPACE, 0); - - if (sym && TYPE_CODE(SYMBOL_TYPE(sym)) == TYPE_CODE(type)) - bcopy (SYMBOL_TYPE (sym), type, sizeof (*type)); - } - val = (value) xmalloc (sizeof (struct value) + TYPE_LENGTH (type)); - VALUE_NEXT (val) = all_values; - all_values = val; - VALUE_TYPE (val) = type; - VALUE_LVAL (val) = not_lval; - VALUE_ADDRESS (val) = 0; - VALUE_FRAME (val) = 0; - VALUE_OFFSET (val) = 0; - VALUE_BITPOS (val) = 0; - VALUE_BITSIZE (val) = 0; - VALUE_REPEATED (val) = 0; - VALUE_REPETITIONS (val) = 0; - VALUE_REGNO (val) = -1; - return val; -} - -/* Allocate a value that has the correct length - for COUNT repetitions type TYPE. */ - -value -allocate_repeat_value (type, count) - struct type *type; - int count; -{ - register value val; - - val = (value) xmalloc (sizeof (struct value) + TYPE_LENGTH (type) * count); - VALUE_NEXT (val) = all_values; - all_values = val; - VALUE_TYPE (val) = type; - VALUE_LVAL (val) = not_lval; - VALUE_ADDRESS (val) = 0; - VALUE_FRAME (val) = 0; - VALUE_OFFSET (val) = 0; - VALUE_BITPOS (val) = 0; - VALUE_BITSIZE (val) = 0; - VALUE_REPEATED (val) = 1; - VALUE_REPETITIONS (val) = count; - VALUE_REGNO (val) = -1; - return val; -} - -/* Free all the values that have been allocated (except for those released). - Called after each command, successful or not. */ - -void -free_all_values () -{ - register value val, next; - - for (val = all_values; val; val = next) - { - next = VALUE_NEXT (val); - free (val); - } - - all_values = 0; -} - -/* Remove VAL from the chain all_values - so it will not be freed automatically. */ - -void -release_value (val) - register value val; -{ - register value v; - - if (all_values == val) - { - all_values = val->next; - return; - } - - for (v = all_values; v; v = v->next) - { - if (v->next == val) - { - v->next = val->next; - break; - } - } -} - -/* Return a copy of the value ARG. - It contains the same contents, for same memory address, - but it's a different block of storage. */ - -static value -value_copy (arg) - value arg; -{ - register value val; - register struct type *type = VALUE_TYPE (arg); - if (VALUE_REPEATED (arg)) - val = allocate_repeat_value (type, VALUE_REPETITIONS (arg)); - else - val = allocate_value (type); - VALUE_LVAL (val) = VALUE_LVAL (arg); - VALUE_ADDRESS (val) = VALUE_ADDRESS (arg); - VALUE_OFFSET (val) = VALUE_OFFSET (arg); - VALUE_BITPOS (val) = VALUE_BITPOS (arg); - VALUE_BITSIZE (val) = VALUE_BITSIZE (arg); - VALUE_REGNO (val) = VALUE_REGNO (arg); - bcopy (VALUE_CONTENTS (arg), VALUE_CONTENTS (val), - TYPE_LENGTH (VALUE_TYPE (arg)) - * (VALUE_REPEATED (arg) ? VALUE_REPETITIONS (arg) : 1)); - return val; -} - -/* Access to the value history. */ - -/* Record a new value in the value history. - Returns the absolute history index of the entry. */ - -int -record_latest_value (val) - value val; -{ - int i; - double foo; - - /* Check error now if about to store an invalid float. We return -1 - to the caller, but allow them to continue, e.g. to print it as "Nan". */ - if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FLT) { - foo = unpack_double (VALUE_TYPE (val), VALUE_CONTENTS (val), &i); - if (i) return -1; /* Indicate value not saved in history */ - } - - /* Here we treat value_history_count as origin-zero - and applying to the value being stored now. */ - - i = value_history_count % VALUE_HISTORY_CHUNK; - if (i == 0) - { - register struct value_history_chunk *new - = (struct value_history_chunk *) - xmalloc (sizeof (struct value_history_chunk)); - bzero (new->values, sizeof new->values); - new->next = value_history_chain; - value_history_chain = new; - } - - value_history_chain->values[i] = val; - release_value (val); - - /* Now we regard value_history_count as origin-one - and applying to the value just stored. */ - - return ++value_history_count; -} - -/* Return a copy of the value in the history with sequence number NUM. */ - -value -access_value_history (num) - int num; -{ - register struct value_history_chunk *chunk; - register int i; - register int absnum = num; - - if (absnum <= 0) - absnum += value_history_count; - - if (absnum <= 0) - { - if (num == 0) - error ("The history is empty."); - else if (num == 1) - error ("There is only one value in the history."); - else - error ("History does not go back to $$%d.", -num); - } - if (absnum > value_history_count) - error ("History has not yet reached $%d.", absnum); - - absnum--; - - /* Now absnum is always absolute and origin zero. */ - - chunk = value_history_chain; - for (i = (value_history_count - 1) / VALUE_HISTORY_CHUNK - absnum / VALUE_HISTORY_CHUNK; - i > 0; i--) - chunk = chunk->next; - - return value_copy (chunk->values[absnum % VALUE_HISTORY_CHUNK]); -} - -/* Clear the value history entirely. - Must be done when new symbol tables are loaded, - because the type pointers become invalid. */ - -void -clear_value_history () -{ - register struct value_history_chunk *next; - register int i; - register value val; - - while (value_history_chain) - { - for (i = 0; i < VALUE_HISTORY_CHUNK; i++) - if (val = value_history_chain->values[i]) - free (val); - next = value_history_chain->next; - free (value_history_chain); - value_history_chain = next; - } - value_history_count = 0; -} - -static void -value_history_info (num_exp, from_tty) - char *num_exp; - int from_tty; -{ - register int i; - register value val; - static int num = 1; - - if (num_exp) - { - if (num_exp[0] == '+' && num_exp[1] == '\0') - /* "info history +" should print from the stored position. */ - ; - else - /* "info history " should print around value number . */ - num = parse_and_eval_address (num_exp) - 5; - } - else - { - /* "info history" means print the last 10 values. */ - num = value_history_count - 9; - } - - if (num <= 0) - num = 1; - - for (i = num; i < num + 10 && i <= value_history_count; i++) - { - val = access_value_history (i); - printf_filtered ("$%d = ", i); - value_print (val, stdout, 0, Val_pretty_default); - printf_filtered ("\n"); - } - - /* The next "info history +" should start after what we just printed. */ - num += 10; - - /* Hitting just return after this command should do the same thing as - "info history +". If num_exp is null, this is unnecessary, since - "info history +" is not useful after "info history". */ - if (from_tty && num_exp) - { - num_exp[0] = '+'; - num_exp[1] = '\0'; - } -} - -/* Internal variables. These are variables within the debugger - that hold values assigned by debugger commands. - The user refers to them with a '$' prefix - that does not appear in the variable names stored internally. */ - -static struct internalvar *internalvars; - -/* Look up an internal variable with name NAME. NAME should not - normally include a dollar sign. - - If the specified internal variable does not exist, - one is created, with a void value. */ - -struct internalvar * -lookup_internalvar (name) - char *name; -{ - register struct internalvar *var; - - for (var = internalvars; var; var = var->next) - if (!strcmp (var->name, name)) - return var; - - var = (struct internalvar *) xmalloc (sizeof (struct internalvar)); - var->name = concat (name, "", ""); - var->value = allocate_value (builtin_type_void); - release_value (var->value); - var->next = internalvars; - internalvars = var; - return var; -} - -value -value_of_internalvar (var) - struct internalvar *var; -{ - register value val; - -#ifdef IS_TRAPPED_INTERNALVAR - if (IS_TRAPPED_INTERNALVAR (var->name)) - return VALUE_OF_TRAPPED_INTERNALVAR (var); -#endif - - val = value_copy (var->value); - VALUE_LVAL (val) = lval_internalvar; - VALUE_INTERNALVAR (val) = var; - return val; -} - -void -set_internalvar_component (var, offset, bitpos, bitsize, newval) - struct internalvar *var; - int offset, bitpos, bitsize; - value newval; -{ - register char *addr = VALUE_CONTENTS (var->value) + offset; - -#ifdef IS_TRAPPED_INTERNALVAR - if (IS_TRAPPED_INTERNALVAR (var->name)) - SET_TRAPPED_INTERNALVAR (var, newval, bitpos, bitsize, offset); -#endif - - if (bitsize) - modify_field (addr, (int) value_as_long (newval), - bitpos, bitsize); - else - bcopy (VALUE_CONTENTS (newval), addr, - TYPE_LENGTH (VALUE_TYPE (newval))); -} - -void -set_internalvar (var, val) - struct internalvar *var; - value val; -{ -#ifdef IS_TRAPPED_INTERNALVAR - if (IS_TRAPPED_INTERNALVAR (var->name)) - SET_TRAPPED_INTERNALVAR (var, val, 0, 0, 0); -#endif - - free (var->value); - var->value = value_copy (val); - release_value (var->value); -} - -char * -internalvar_name (var) - struct internalvar *var; -{ - return var->name; -} - -/* Free all internalvars. Done when new symtabs are loaded, - because that makes the values invalid. */ - -void -clear_internalvars () -{ - register struct internalvar *var; - - while (internalvars) - { - var = internalvars; - internalvars = var->next; - free (var->name); - free (var->value); - free (var); - } -} - -static void -convenience_info () -{ - register struct internalvar *var; - int varseen = 0; - - for (var = internalvars; var; var = var->next) - { -#ifdef IS_TRAPPED_INTERNALVAR - if (IS_TRAPPED_INTERNALVAR (var->name)) - continue; -#endif - if (!varseen) - { - printf ("Debugger convenience variables:\n\n"); - varseen = 1; - } - printf ("$%s: ", var->name); - value_print (var->value, stdout, 0, Val_pretty_default); - printf ("\n"); - } - if (!varseen) - printf ("No debugger convenience variables now defined.\n\ -Convenience variables have names starting with \"$\";\n\ -use \"set\" as in \"set $foo = 5\" to define them.\n"); -} - -/* Extract a value as a C number (either long or double). - Knows how to convert fixed values to double, or - floating values to long. - Does not deallocate the value. */ - -LONGEST -value_as_long (val) - register value val; -{ - return unpack_long (VALUE_TYPE (val), VALUE_CONTENTS (val)); -} - -double -value_as_double (val) - register value val; -{ - double foo; - int inv; - - foo = unpack_double (VALUE_TYPE (val), VALUE_CONTENTS (val), &inv); - if (inv) - error ("Invalid floating value found in program."); - return foo; -} - -/* Unpack raw data (copied from debugee) at VALADDR - as a long, or as a double, assuming the raw data is described - by type TYPE. Knows how to convert different sizes of values - and can convert between fixed and floating point. - - C++: It is assumed that the front-end has taken care of - all matters concerning pointers to members. A pointer - to member which reaches here is considered to be equivalent - to an INT (or some size). After all, it is only an offset. */ - -LONGEST -unpack_long (type, valaddr) - struct type *type; - char *valaddr; -{ - register enum type_code code = TYPE_CODE (type); - register int len = TYPE_LENGTH (type); - register int nosign = TYPE_UNSIGNED (type); - - if (code == TYPE_CODE_ENUM) - code = TYPE_CODE_INT; - if (code == TYPE_CODE_FLT) - { - if (len == sizeof (float)) - return * (float *) valaddr; - - if (len == sizeof (double)) - return * (double *) valaddr; - } - else if (code == TYPE_CODE_INT && nosign) - { - if (len == sizeof (char)) - return * (unsigned char *) valaddr; - - if (len == sizeof (short)) - return * (unsigned short *) valaddr; - - if (len == sizeof (int)) - return * (unsigned int *) valaddr; - - if (len == sizeof (long)) - return * (unsigned long *) valaddr; -#ifdef LONG_LONG - if (len == sizeof (long long)) - return * (unsigned long long *) valaddr; -#endif - } - else if (code == TYPE_CODE_INT) - { - if (len == sizeof (char)) - return * (char *) valaddr; - - if (len == sizeof (short)) - return * (short *) valaddr; - - if (len == sizeof (int)) - return * (int *) valaddr; - - if (len == sizeof (long)) - return * (long *) valaddr; - -#ifdef LONG_LONG - if (len == sizeof (long long)) - return * (long long *) valaddr; -#endif - } - else if (code == TYPE_CODE_PTR - || code == TYPE_CODE_REF) - { - if (len == sizeof (char *)) - return (CORE_ADDR) * (char **) valaddr; - } - else if (code == TYPE_CODE_MEMBER) - error ("not implemented: member types in unpack_long"); - - error ("Value not integer or pointer."); -} - -/* Return a double value from the specified type and address. - INVP points to an int which is set to 0 for valid value, - 1 for invalid value (bad float format). In either case, - the returned double is OK to use. */ - -double -unpack_double (type, valaddr, invp) - struct type *type; - char *valaddr; - int *invp; -{ - register enum type_code code = TYPE_CODE (type); - register int len = TYPE_LENGTH (type); - register int nosign = TYPE_UNSIGNED (type); - - *invp = 0; /* Assume valid. */ - if (code == TYPE_CODE_FLT) - { - if (INVALID_FLOAT (valaddr, len)) - { - *invp = 1; - return 1.234567891011121314; - } - - if (len == sizeof (float)) - return * (float *) valaddr; - - if (len == sizeof (double)) - { - /* Some machines require doubleword alignment for doubles. - This code works on them, and on other machines. */ - double temp; - bcopy ((char *) valaddr, (char *) &temp, sizeof (double)); - return temp; - } - } - else if (code == TYPE_CODE_INT && nosign) - { - if (len == sizeof (char)) - return * (unsigned char *) valaddr; - - if (len == sizeof (short)) - return * (unsigned short *) valaddr; - - if (len == sizeof (int)) - return * (unsigned int *) valaddr; - - if (len == sizeof (long)) - return * (unsigned long *) valaddr; - -#ifdef LONG_LONG - if (len == sizeof (long long)) - return * (unsigned long long *) valaddr; -#endif - } - else if (code == TYPE_CODE_INT) - { - if (len == sizeof (char)) - return * (char *) valaddr; - - if (len == sizeof (short)) - return * (short *) valaddr; - - if (len == sizeof (int)) - return * (int *) valaddr; - - if (len == sizeof (long)) - return * (long *) valaddr; - -#ifdef LONG_LONG - if (len == sizeof (long long)) - return * (long long *) valaddr; -#endif - } - - error ("Value not floating number."); - /* NOTREACHED */ - return (double) 0; /* To silence compiler warning. */ -} - -/* Given a value ARG1 of a struct or union type, - extract and return the value of one of its fields. - FIELDNO says which field. - - For C++, must also be able to return values from static fields */ - -value -value_field (arg1, fieldno) - register value arg1; - register int fieldno; -{ - register value v; - register struct type *type = TYPE_FIELD_TYPE (VALUE_TYPE (arg1), fieldno); - register int offset; - - /* Handle packed fields */ - - offset = TYPE_FIELD_BITPOS (VALUE_TYPE (arg1), fieldno) / 8; - if (TYPE_FIELD_BITSIZE (VALUE_TYPE (arg1), fieldno)) - { - v = value_from_long (type, - unpack_field_as_long (VALUE_TYPE (arg1), - VALUE_CONTENTS (arg1), - fieldno)); - VALUE_BITPOS (v) = TYPE_FIELD_BITPOS (VALUE_TYPE (arg1), fieldno) % 8; - VALUE_BITSIZE (v) = TYPE_FIELD_BITSIZE (VALUE_TYPE (arg1), fieldno); - } - else - { - v = allocate_value (type); - bcopy (VALUE_CONTENTS (arg1) + offset, - VALUE_CONTENTS (v), - TYPE_LENGTH (type)); - } - VALUE_LVAL (v) = VALUE_LVAL (arg1); - if (VALUE_LVAL (arg1) == lval_internalvar) - VALUE_LVAL (v) = lval_internalvar_component; - VALUE_ADDRESS (v) = VALUE_ADDRESS (arg1); - VALUE_OFFSET (v) = offset + VALUE_OFFSET (arg1); - return v; -} - -value -value_fn_field (arg1, fieldno, subfieldno) - register value arg1; - register int fieldno; -{ - register value v; - struct fn_field *f = TYPE_FN_FIELDLIST1 (VALUE_TYPE (arg1), fieldno); - register struct type *type = TYPE_FN_FIELD_TYPE (f, subfieldno); - struct symbol *sym; - - sym = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, subfieldno), - 0, VAR_NAMESPACE, 0); - if (! sym) error ("Internal error: could not find physical method named %s", - TYPE_FN_FIELD_PHYSNAME (f, subfieldno)); - - v = allocate_value (type); - VALUE_ADDRESS (v) = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); - VALUE_TYPE (v) = type; - return v; -} - -/* Return a virtual function as a value. - ARG1 is the object which provides the virtual function - table pointer. - F is the list of member functions which contains the desired virtual - function. - J is an index into F which provides the desired virtual function. - TYPE is the basetype which first provides the virtual function table. */ -value -value_virtual_fn_field (arg1, f, j, type) - value arg1; - struct fn_field *f; - int j; - struct type *type; -{ - /* First, get the virtual function table pointer. That comes - with a strange type, so cast it to type `pointer to long' (which - should serve just fine as a function type). Then, index into - the table, and convert final value to appropriate function type. */ - value vfn, vtbl; - value vi = value_from_long (builtin_type_int, - (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j)); - VALUE_TYPE (arg1) = TYPE_VPTR_BASETYPE (type); - - /* This type may have been defined before its virtual function table - was. If so, fill in the virtual function table entry for the - type now. */ - if (TYPE_VPTR_FIELDNO (type) < 0) - TYPE_VPTR_FIELDNO (type) - = fill_in_vptr_fieldno (type); - - /* The virtual function table is now an array of structures - which have the form { int16 offset, delta; void *pfn; }. */ - vtbl = value_ind (value_field (arg1, TYPE_VPTR_FIELDNO (type))); - - /* Index into the virtual function table. This is hard-coded because - looking up a field is not cheap, and it may be important to save - time, e.g. if the user has set a conditional breakpoint calling - a virtual function. */ - vfn = value_field (value_subscript (vtbl, vi), 2); - - /* Reinstantiate the function pointer with the correct type. */ - VALUE_TYPE (vfn) = lookup_pointer_type (TYPE_FN_FIELD_TYPE (f, j)); - return vfn; -} - -/* The value of a static class member does not depend - on its instance, only on its type. If FIELDNO >= 0, - then fieldno is a valid field number and is used directly. - Otherwise, FIELDNAME is the name of the field we are - searching for. If it is not a static field name, an - error is signaled. TYPE is the type in which we look for the - static field member. */ -value -value_static_field (type, fieldname, fieldno) - register struct type *type; - char *fieldname; - register int fieldno; -{ - register value v; - struct symbol *sym; - - if (fieldno < 0) - { - register struct type *t = type; - /* Look for static field. */ - while (t) - { - int i; - for (i = TYPE_NFIELDS (t) - 1; i >= 0; i--) - if (! strcmp (TYPE_FIELD_NAME (t, i), fieldname)) - { - if (TYPE_FIELD_STATIC (t, i)) - { - fieldno = i; - goto found; - } - else - error ("field `%s' is not static"); - } - t = TYPE_BASECLASSES (t) ? TYPE_BASECLASS (t, 1) : 0; - } - - t = type; - - if (destructor_name_p (fieldname, t)) - error ("use `info method' command to print out value of destructor"); - - while (t) - { - int i, j; - - for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; i--) - { - if (! strcmp (TYPE_FN_FIELDLIST_NAME (t, i), fieldname)) - { - error ("use `info method' command to print value of method \"%s\"", fieldname); - } - } - t = TYPE_BASECLASSES (t) ? TYPE_BASECLASS (t, 1) : 0; - } - error("there is no field named %s", fieldname); - } - - found: - - sym = lookup_symbol (TYPE_FIELD_STATIC_PHYSNAME (type, fieldno), - 0, VAR_NAMESPACE, 0); - if (! sym) error ("Internal error: could not find physical static variable named %s", TYPE_FIELD_BITSIZE (type, fieldno)); - - type = TYPE_FIELD_TYPE (type, fieldno); - v = value_at (type, (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym)); - return v; -} - -long -unpack_field_as_long (type, valaddr, fieldno) - struct type *type; - char *valaddr; - int fieldno; -{ - long val; - int bitpos = TYPE_FIELD_BITPOS (type, fieldno); - int bitsize = TYPE_FIELD_BITSIZE (type, fieldno); - - bcopy (valaddr + bitpos / 8, &val, sizeof val); - - /* Extracting bits depends on endianness of the machine. */ -#ifdef BITS_BIG_ENDIAN - val = val >> (sizeof val * 8 - bitpos % 8 - bitsize); -#else - val = val >> (bitpos % 8); -#endif - - val &= (1 << bitsize) - 1; - return val; -} - -void -modify_field (addr, fieldval, bitpos, bitsize) - char *addr; - int fieldval; - int bitpos, bitsize; -{ - long oword; - - /* Reject values too big to fit in the field in question. - Otherwise adjoining fields may be corrupted. */ - if (fieldval & ~((1<> 8) -#define WSTOPSIG(w) ((w) >> 8) -#define WCOREDUMP(w) (((w)&0200) != 0) -#define WTERMSIG(w) ((w) & 0177) -#define WSETEXIT(w, status) ((w) = (status)) -#define WSETSTOP(w,sig) ((w) = (0177 | ((sig) << 8))) - -#else - -#include - -#define WAITTYPE union wait -#ifndef WEXITSTATUS -#define WEXITSTATUS(w) (w).w_retcode -#endif -#ifndef WSTOPSIG -#define WSTOPSIG(w) (w).w_stopsig -#endif -#ifndef WCOREDUMP -#define WCOREDUMP(w) (w).w_coredump -#endif -#ifndef WTERMSIG -#define WTERMSIG(w) (w).w_termsig -#endif -#ifndef WSETEXIT -#define WSETEXIT(w, status) ((w).w_status = (status)) -#endif -#ifndef WSETSTOP -#define WSETSTOP(w,sig) \ - ((w).w_stopsig = (sig), (w).w_coredump = 0, (w).w_termsig = 0177) -#endif - -#endif diff --git a/gnu/usr.bin/gdb/xgdb/Makefile b/gnu/usr.bin/gdb/xgdb/Makefile deleted file mode 100644 index 72c5359..0000000 --- a/gnu/usr.bin/gdb/xgdb/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -# %W% (Berkeley) %G% - -.include "../config/Makefile.$(MACHINE)" - -PROG= xgdb -SRCS= xgdb.c xgdbinit.c -GDBOBJS+= $(CONFIGSRCS:R:S/$/.o/g) \ - blockframe.o breakpoint.o command.o copying.o core.o \ - cplus-dem.o dbxread.o environ.o eval.o expprint.o \ - expread.o findvar.o infcmd.o inflow.o infrun.o \ - main.o obstack.o printcmd.o regex.o remote.o \ - remote-sl.o source.o stack.o symmisc.o symtab.o \ - utils.o valarith.o valops.o valprint.o values.o \ - version.o \ - funmap.o history.o keymaps.o readline.o -CFLAGS+= -I.. -I$(.CURDIR)/.. -I$(.CURDIR)/../config \ - -DHAVE_VPRINTF -DVI_MODE -DKERNELDEBUG -LDFLAGS+= -L/usr/lib/X11 -LDADD+= $(GDBOBJS:S/^/..\//g) -lXaw -lXmu -lXt -lXext -lX11 -ltermcap -NOMAN= noman - -.include "../../Makefile.inc" -.include - -# -# Generate the constructor -# -xgdbinit.c: ../init.c xgdb.c - -(sed -e '/^}$$/d' ../init.c; \ - egrep -h '^_initialize_[^ ]* *\(\)' $(.CURDIR)/xgdb.c; \ - echo ';}') > xgdbinit.c - -CLEANFILES+= xgdbinit.c diff --git a/gnu/usr.bin/gdb/xgdb/xgdb.c b/gnu/usr.bin/gdb/xgdb/xgdb.c deleted file mode 100644 index a2bd4f6..0000000 --- a/gnu/usr.bin/gdb/xgdb/xgdb.c +++ /dev/null @@ -1,700 +0,0 @@ -/*- - * This code is derived from software copyrighted by the Free Software - * Foundation. - * - * Modified 1991 by Donn Seeley at UUNET Technologies, Inc. - * Modified 1990 by Van Jacobson at Lawrence Berkeley Laboratory. - * - * static char rcsid[] = "$Header: /home/cvs/386BSD/src/usr.bin/gdb/xgdb/xgdb.c,v 1.1.1.1 1993/06/12 14:52:36 rgrimes Exp $"; - */ - -#ifndef lint -static char sccsid[] = "@(#)xgdb.c 6.3 (Berkeley) 5/8/91"; -#endif /* not lint */ - -/* - * Interface from GDB to X windows. Copyright (C) 1987 Free Software - * Foundation, Inc. - * - * GDB is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY. No author or distributor accepts responsibility to anyone for - * the consequences of using it or for whether it serves any particular - * purpose or works at all, unless he says so in writing. Refer to the GDB - * General Public License for full details. - * - * Everyone is granted permission to copy, modify and redistribute GDB, but only - * under the conditions described in the GDB General Public License. A copy - * of this license is supposed to have been given to you along with GDB so - * you can know your rights and responsibilities. It should be in a file - * named COPYING. Among other things, the copyright notice and this notice - * must be preserved on all copies. - * - * In other words, go ahead and share GDB, but don't try to stop anyone else - * from sharing it farther. Help stamp out software hoarding! - */ - -/* - * Original version was contributed by Derek Beatty, 30 June 87. - * This version is essentially a re-write of the original by Van - * Jacobson (van@helios.ee.lbl.gov), Nov, 90. - */ - -#include "defs.h" -#include "param.h" -#include "symtab.h" -#include "frame.h" - -extern int stop_breakpoint; - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -extern int errno; -extern char *getenv(); -extern char *malloc(); -extern void bcopy(); -extern int select(); - -extern int get_filename_and_charpos(); -extern int source_line_charpos(); -extern int source_charpos_line(); -extern void execute_command(); -extern void error_no_arg(); -extern void add_com(); - -/* The X display where the window appears. */ - -static char *displayname; -static Display *display; - -static XtAppContext app_context; - -/* Windows manipulated by this package. */ - -static Widget main_widget; -static Widget containing_widget; -static Widget source_name_widget; -static Widget source_text_widget; -static Widget button_box_widget; - -/* Source text display. */ - -static struct frame_info *last_fi; -static CORE_ADDR last_pc; -static struct symtab *last_cur_symtab; -static int last_cur_line; - -static int source_window_line; -static char *source_window_file; -static struct symtab *source_window_symtab; - -static char version_label[64]; -extern char *version; - -/* Forward declarations */ - -static Widget create_text_widget(); - -static int -safe_strcmp(a, b) - register char *a, *b; -{ - register int i; - - if (a == b) - return (0); - if (!a && b) - return (1); - if (a && !b) - return (-1); - return (strcmp(a, b)); -} - - -/* Display an appropriate piece of source code in the source window. */ - -void -xgdb_display_source() -{ - char *filename = NULL; - struct symtab_and_line get_selected_frame_sal(); - struct symtab_and_line sal; - struct frame_info *fi; - - /* Do nothing if called before we are initialized */ - - if (!containing_widget) - return; - - /* - * Figure out what to display (the appropriate hooks to tell - * us don't exist so we guess): If there's a current frame - * and it or its pc changed from the last time we were here, - * display appropriate source line. Otherwise if the current - * source symtab or line is different, display that line. - * Otherwise nothing changed so leave the display alone. - */ - fi = get_frame_info(selected_frame); - if (fi && (fi != last_fi || fi->pc != last_pc)) { - last_fi = fi; - last_pc = fi->pc; - sal = find_pc_line(fi->pc, fi->next_frame); - if (sal.symtab == NULL) { /* XXX */ - sal.symtab = current_source_symtab; - sal.line = current_source_line; - } - current_source_symtab = sal.symtab; - current_source_line = sal.line; - } else if (current_source_symtab != last_cur_symtab || - current_source_line != last_cur_line) { - sal.symtab = last_cur_symtab = current_source_symtab; - sal.line = last_cur_line = current_source_line; - } else - return; - /* - * Do a path search and get the exact filename of this source file. - * Also scan it and find its source lines if not already done. - */ - if (sal.symtab && filename == NULL) { - if (get_filename_and_charpos(sal.symtab, sal.line, &filename)) - /* line numbers may have changed - force highlight */ - source_window_line = -1; - } - - /* - * If the source window is wrong, destroy it and make a new one. - */ - if (safe_strcmp(filename, source_window_file)) { - Arg args[1]; - Widget src = XawTextGetSource(source_text_widget); - - if (filename) { - XtSetArg(args[0], XtNstring, filename); - XtSetValues(src, args, XtNumber(args)); - args[0].name = XtNlabel; - XtSetValues(source_name_widget, args, XtNumber(args)); - } else { - XtSetArg(args[0], XtNstring, "/dev/null"); - XtSetValues(src, args, XtNumber(args)); - XtSetArg(args[0], XtNlabel, ""); - XtSetValues(source_name_widget, args, XtNumber(args)); - } - if (source_window_file) - free(source_window_file); - source_window_file = filename; - source_window_line = sal.line + 1; /* force highlight */ - } - if (sal.symtab && source_window_line != sal.line) { - /* - * Update display and cursor positions as necessary. - * Cursor should be placed on line sal.line. - */ - XawTextPosition l, r; - - source_window_symtab = sal.symtab; - source_window_line = sal.line; - l = source_line_charpos(source_window_symtab, sal.line); - r = source_line_charpos(source_window_symtab, sal.line + 1); - if (r < l) - r = l + 1; - XawTextSetSelection(source_text_widget, l, r); - XawTextScrollToLine(source_text_widget, l, 10, 3); - XawTextSetInsertionPoint(source_text_widget, l); - } -} - - -/* - * Handlers for buttons. - */ - -static int -current_lineno() -{ - XawTextPosition start, finish; - - XawTextGetSelectionPos(source_text_widget, &start, &finish); - if (start >= finish) - start = XawTextGetInsertionPoint(source_text_widget); - - return (source_charpos_line(source_window_symtab, start)); -} - -static char * -append_selection(cp) - char *cp; -{ - int len; - XawTextPosition l, r; - - XawTextGetSelectionPos(source_text_widget, &l, &r); - if ((len = r - l) > 0) { - Widget src = XawTextGetSource(source_text_widget); - - while (len > 0) { - XawTextBlock tb; - - XawTextSourceRead(src, l, &tb, len); - bcopy(tb.ptr, cp, tb.length); - cp += tb.length; - len -= tb.length; - } - if (cp[-1] == 0) - --cp; - } - return (cp); -} - -static char * -append_selection_word(cp) - register char *cp; -{ - register int len; - XawTextPosition l, r; - XawTextBlock tb; - register char c; - register Widget src = XawTextGetSource(source_text_widget); - - XawTextGetSelectionPos(source_text_widget, &l, &r); - if ((len = r - l) <= 0) { - l = XawTextGetInsertionPoint(source_text_widget); - len = 128; /* XXX */ - - /* might have clicked in middle of word -- back up to start */ - for ( ; l > 0; --l) { - XawTextSourceRead(src, l - 1, &tb, 1); - c = tb.ptr[0]; - if (! isalnum(c) && c != '_' && c != '$') - break; - } - } - while (len > 0) { - char *sp; - int i; - - XawTextSourceRead(src, l, &tb, len); - for (sp = tb.ptr, i = tb.length; --i >= 0; ) { - c = *sp++; - if (!isalnum(c) && c != '_' && c != '$') - return (cp); - *cp++ = c; - } - len -= tb.length; - } - return (cp); -} - -static char * -append_selection_expr(cp) - char *cp; -{ - int len; - XawTextPosition l, r; - Widget src = XawTextGetSource(source_text_widget); - XawTextBlock tb; - char *sp; - char c; - - XawTextGetSelectionPos(source_text_widget, &l, &r); - if (r > l) - return (append_selection(cp)); - - l = XawTextGetInsertionPoint(source_text_widget); - - /* might have clicked in middle of word -- back up to start */ - for ( ; l > 0; --l) { - XawTextSourceRead(src, l - 1, &tb, 1); - c = tb.ptr[0]; - if (! isalnum(c) && c != '_' && c != '$') - break; - } - - len = 128; /* XXX */ - while (len > 0) { - int i; - char pstack[64]; - int pcnt = 0; - - XawTextSourceRead(src, l, &tb, len); - for (sp = tb.ptr, i = tb.length; --i >= 0; ) { - switch (c = *sp++) { - case '\n': - case ';': - return (cp); - case '=': - if (cp[-1] != '=') - return (cp - 1); - if (len == 128) - return (cp); - break; - case ',': - if (pcnt <= 0) - return (cp); - break; - case '(': - pstack[pcnt] = ')'; - if (++pcnt >= sizeof(pstack)) - return (cp); - break; - case '[': - pstack[pcnt] = ']'; - if (++pcnt >= sizeof(pstack)) - return (cp); - break; - case ')': - case ']': - if (--pcnt < 0 || pstack[pcnt] != c) - return (cp); - break; - } - *cp++ = c; - } - len -= tb.length; - } - return (cp); -} - -static int input_avail; /* XXX kluge: do_command sets this when command - * data from button is avaialble to force top level - * to break out of its loop. */ -/* - * Handle a button by running the command COMMAND. - */ -static void -do_command(w, command, call_data) - Widget w; - register char *command; - caddr_t call_data; -{ - char cmd_line[256]; - char buf[256]; - register char *out = cmd_line; - char *cp; - register char c; - extern char *finish_command_input(); - - while (c = *command++) { - if (c == '%') { - switch (*command++) { - case 's': /* current selection */ - out = append_selection(out); - break; - case 'S': /* 1st selected "word" at curor */ - out = append_selection_word(out); - break; - case 'e': /* echo cmd before executing */ - break; - case 'E': /* 1st selected expression at curor */ - out = append_selection_expr(out); - break; - - case 'l': /* current line number */ - (void) sprintf(buf, "%d", current_lineno()); - for (cp = buf; c = *cp++; *out++ = c) - ; - break; - case 'L': /* line we're stopped at */ - (void) sprintf(buf, "%d", source_window_line); - for (cp = buf; c = *cp++; *out++ = c) - ; - break; - case 'f': /* current file name */ - for (cp = source_window_symtab->filename; - c = *cp++; *out++ = c) - ; - break; - case 'b': /* break # we're stopped at */ - if (stop_breakpoint <= 0) - /* if no breakpoint, don't do cmd */ - return; - - (void) sprintf(buf, "%d", stop_breakpoint); - for (cp = buf; c = *cp++; *out++ = c) - ; - break; - } - } else - *out++ = c; - } - *out = 0; - reinitialize_more_filter(); - /* have to exit via readline or tty modes stay messed up */ - for (cp = cmd_line; c = *cp++; ) - rl_stuff_char(c); - rl_stuff_char('\n'); - input_avail = 1; -} - -/* - * Define and display all the buttons. - */ -static void -addbutton(parent, name, function, closure) - Widget parent; - char *name; - void (*function) (); - caddr_t closure; -{ - static XtCallbackRec Callback[] = { - {NULL, (caddr_t) NULL}, - {NULL, (caddr_t) NULL}, - }; - static Arg commandArgs[] = { - {XtNlabel, (XtArgVal) NULL}, - {XtNcallback, (XtArgVal) Callback}, - }; - Widget w; - char wname[128]; - register char *cp; - - strcpy(wname, name); - while ((cp = index(wname, '*')) || (cp = index(wname, '.'))) - *cp -= 0x10; - - if (w = XtNameToWidget(parent, wname)) - XtDestroyWidget(w); - - Callback[0].callback = (XtCallbackProc) function; - Callback[0].closure = (caddr_t) closure; - commandArgs[0].value = (XtArgVal) name; - XtCreateManagedWidget(wname, commandWidgetClass, parent, - commandArgs, XtNumber(commandArgs)); -} - -/* - * Create the button windows and store them in `buttons'. - */ -static void -create_buttons(parent) - Widget parent; -{ - addbutton(parent, "quit", do_command, "quit"); -} - -static void -button_command(arg) - char *arg; -{ - char *label; - unsigned int len; - - if (! arg) - error_no_arg("button label and command"); - - for (len = strlen(arg); len > 0 && isspace(arg[len - 1]); --len) - ; - if (len == 0) - error_no_arg("button label and command"); - arg[len] = 0; - - /* make a copy of button label & command for toolkit to use */ - label = malloc(len + 1); - strcpy(label, arg); - - /* find the end of the label */ - if (*label == '"') { - if ((arg = index(++label, '"')) == 0) { - printf("button label missing closing quote\n"); - return; - } - *arg++ = 0; - } else if (arg = index(label, ' ')) - *arg++ = 0; - else - arg = label; - - while (*arg && isspace(*arg)) - ++arg; - - addbutton(button_box_widget, label, do_command, arg); -} - -static void -button_delete_command(arg) - char *arg; -{ - unsigned int len; - Widget w; - register char *cp; - - if (! arg) - error_no_arg("button name"); - - for (len = strlen(arg); len > 0 && isspace(arg[len - 1]); --len) - ; - if (len == 0) - error_no_arg("button name"); - arg[len] = 0; - - /* find the end of the label */ - if (*arg == '"') { - if ((cp = index(++arg, '"')) == 0) { - printf("button label missing closing quote\n"); - return; - } - *cp++ = 0; - } - while ((cp = index(arg, '*')) || (cp = index(arg, '.'))) - *cp -= 0x10; - - if (w = XtNameToWidget(button_box_widget, arg)) - XtDestroyWidget(w); -} - -/* - * Create a "label window" that just displays the string LABEL. - */ -static Widget -create_label(name, label) - char *name, *label; -{ - Arg args[1]; - Widget w; - - XtSetArg(args[0], XtNlabel, label); - w = XtCreateManagedWidget(name, labelWidgetClass, containing_widget, - args, XtNumber(args)); - return (w); -} - -/* - * Create a subwindow of PARENT that displays and scrolls the contents of - * file FILENAME. - */ -static Widget -create_text_widget(parent, filename) - Widget parent; - char *filename; -{ - static Arg arg[] = { - {XtNstring, NULL}, - {XtNtype, XawAsciiFile}, - {XtNcursor, None}, - }; - Widget text_widget; - - arg[0].value = (XtArgVal)filename; - text_widget = XtCreateManagedWidget("src", asciiTextWidgetClass, - parent, arg, XtNumber(arg)); - return (text_widget); -} - -/* - * Entry point to create the widgets representing our display. - */ -void -xgdb_create_window() -{ - /* initialize toolkit, setup defaults */ -#ifdef notyet - main_widget = XtAppInitialize(&app_context, "Xgdb", NULL, 0, - argcptr, argv, NULL, NULL, 0); -#else - char *dummy_argv[] = { "xgdb", 0 }; - int dummy_argc = 1; - main_widget = XtAppInitialize(&app_context, "Xgdb", NULL, 0, - &dummy_argc, dummy_argv, NULL, NULL, 0); -#endif - display = XtDisplay(main_widget); - containing_widget = XtCreateManagedWidget("frame", panedWidgetClass, - main_widget, NULL, 0); - - sprintf(version_label, "XGDB %s", version); - button_box_widget = XtCreateManagedWidget("buttons", boxWidgetClass, - containing_widget, NULL, 0); - create_buttons(button_box_widget); - source_name_widget = create_label("srcLabel", "No source file yet."); - source_text_widget = create_text_widget(containing_widget, "/dev/null"); - - XtRealizeWidget(main_widget); - XFlush(display); -} - -/* - * If we use an X window, the readline input loop is told to call - * this function before reading a character from stdin. - */ -/*ARGSUSED*/ -static void -xgdb_window_hook() -{ - register int inmask = 1 << fileno(stdin); - register int xmask = 1 << ConnectionNumber(display); - register int nfds, pend; - int input_rfds; - XEvent ev; - - /* - * Display our current idea of the `interesting' source file then - * loop, dispatching window events until data is available on - * stdin. Then return so the input data can be processed. - */ - input_avail = 0; - xgdb_display_source(); - - input_rfds = 0; - while (input_avail == 0 && (input_rfds & inmask) == 0) { - pend = XPending(display); - if (!pend) { - input_rfds = inmask | xmask; - nfds = select(32, &input_rfds, 0, 0, - (struct timeval *)0); - if (nfds == -1 && errno == EINTR) - continue; - } - if (pend || (input_rfds & xmask)) { - XNextEvent(display, &ev); - XtDispatchEvent(&ev); - } - } -} - -void -_initialize_xgdb() -{ - extern void (*window_hook) (); - extern int inhibit_windows; - extern struct cmd_list_element *deletelist; - - if (inhibit_windows) - return; - - if (! displayname) { - displayname = getenv("DISPLAY"); - if (! displayname) { - fprintf(stderr, "xgdb: no display name\n"); - inhibit_windows = 1; - return; - } - } - xgdb_create_window(); - window_hook = xgdb_window_hook; - add_com("button", class_support, button_command, -"Add command button to xgdb window. First argument is button\n\ -label, second is command associated with button. Command can\n\ -include printf-like escapes:\n\ - %s for current selection,\n\ - %S for first 'word' of current selection,\n\ - %e for current selection or expression at insertion pt,\n\ - %E for current selection or expression at insertion pt,\n\ - %l for current line number,\n\ - %L for line program stopped at,\n\ - %f for current file name,\n\ - %b for current breakpoint number."); - add_cmd("button", class_support, button_delete_command, -"Delete a button from the xgdb window.\n\ -Argument is name of button to be deleted.", - &deletelist); -} diff --git a/gnu/usr.bin/grep/regex.c b/gnu/usr.bin/grep/regex.c deleted file mode 100644 index e8b5882..0000000 --- a/gnu/usr.bin/grep/regex.c +++ /dev/null @@ -1,4987 +0,0 @@ -/* Extended regular expression matching and search library, - version 0.12. - (Implements POSIX draft P10003.2/D11.2, except for - internationalization features.) - - Copyright (C) 1993 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* AIX requires this to be the first thing in the file. */ -#if defined (_AIX) && !defined (REGEX_MALLOC) - #pragma alloca -#endif - -#define _GNU_SOURCE - -/* We need this for `regex.h', and perhaps for the Emacs include files. */ -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -/* The `emacs' switch turns on certain matching commands - that make sense only in Emacs. */ -#ifdef emacs - -#include "lisp.h" -#include "buffer.h" -#include "syntax.h" - -/* Emacs uses `NULL' as a predicate. */ -#undef NULL - -#else /* not emacs */ - -/* We used to test for `BSTRING' here, but only GCC and Emacs define - `BSTRING', as far as I know, and neither of them use this code. */ -#if HAVE_STRING_H || STDC_HEADERS -#include -#ifndef bcmp -#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) -#endif -#ifndef bcopy -#define bcopy(s, d, n) memcpy ((d), (s), (n)) -#endif -#ifndef bzero -#define bzero(s, n) memset ((s), 0, (n)) -#endif -#else -#include -#endif - -#ifdef STDC_HEADERS -#include -#else -char *malloc (); -char *realloc (); -#endif - - -/* Define the syntax stuff for \<, \>, etc. */ - -/* This must be nonzero for the wordchar and notwordchar pattern - commands in re_match_2. */ -#ifndef Sword -#define Sword 1 -#endif - -#ifdef SYNTAX_TABLE - -extern char *re_syntax_table; - -#else /* not SYNTAX_TABLE */ - -/* How many characters in the character set. */ -#define CHAR_SET_SIZE 256 - -static char re_syntax_table[CHAR_SET_SIZE]; - -static void -init_syntax_once () -{ - register int c; - static int done = 0; - - if (done) - return; - - bzero (re_syntax_table, sizeof re_syntax_table); - - for (c = 'a'; c <= 'z'; c++) - re_syntax_table[c] = Sword; - - for (c = 'A'; c <= 'Z'; c++) - re_syntax_table[c] = Sword; - - for (c = '0'; c <= '9'; c++) - re_syntax_table[c] = Sword; - - re_syntax_table['_'] = Sword; - - done = 1; -} - -#endif /* not SYNTAX_TABLE */ - -#define SYNTAX(c) re_syntax_table[c] - -#endif /* not emacs */ - -/* Get the interface, including the syntax bits. */ -#include "regex.h" - -/* isalpha etc. are used for the character classes. */ -#include - -/* Jim Meyering writes: - - "... Some ctype macros are valid only for character codes that - isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when - using /bin/cc or gcc but without giving an ansi option). So, all - ctype uses should be through macros like ISPRINT... If - STDC_HEADERS is defined, then autoconf has verified that the ctype - macros don't need to be guarded with references to isascii. ... - Defining isascii to 1 should let any compiler worth its salt - eliminate the && through constant folding." */ -#if ! defined (isascii) || defined (STDC_HEADERS) -#undef isascii -#define isascii(c) 1 -#endif - -#ifdef isblank -#define ISBLANK(c) (isascii (c) && isblank (c)) -#else -#define ISBLANK(c) ((c) == ' ' || (c) == '\t') -#endif -#ifdef isgraph -#define ISGRAPH(c) (isascii (c) && isgraph (c)) -#else -#define ISGRAPH(c) (isascii (c) && isprint (c) && !isspace (c)) -#endif - -#define ISPRINT(c) (isascii (c) && isprint (c)) -#define ISDIGIT(c) (isascii (c) && isdigit (c)) -#define ISALNUM(c) (isascii (c) && isalnum (c)) -#define ISALPHA(c) (isascii (c) && isalpha (c)) -#define ISCNTRL(c) (isascii (c) && iscntrl (c)) -#define ISLOWER(c) (isascii (c) && islower (c)) -#define ISPUNCT(c) (isascii (c) && ispunct (c)) -#define ISSPACE(c) (isascii (c) && isspace (c)) -#define ISUPPER(c) (isascii (c) && isupper (c)) -#define ISXDIGIT(c) (isascii (c) && isxdigit (c)) - -#ifndef NULL -#define NULL 0 -#endif - -/* We remove any previous definition of `SIGN_EXTEND_CHAR', - since ours (we hope) works properly with all combinations of - machines, compilers, `char' and `unsigned char' argument types. - (Per Bothner suggested the basic approach.) */ -#undef SIGN_EXTEND_CHAR -#if __STDC__ -#define SIGN_EXTEND_CHAR(c) ((signed char) (c)) -#else /* not __STDC__ */ -/* As in Harbison and Steele. */ -#define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128) -#endif - -/* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we - use `alloca' instead of `malloc'. This is because using malloc in - re_search* or re_match* could cause memory leaks when C-g is used in - Emacs; also, malloc is slower and causes storage fragmentation. On - the other hand, malloc is more portable, and easier to debug. - - Because we sometimes use alloca, some routines have to be macros, - not functions -- `alloca'-allocated space disappears at the end of the - function it is called in. */ - -#ifdef REGEX_MALLOC - -#define REGEX_ALLOCATE malloc -#define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize) - -#else /* not REGEX_MALLOC */ - -/* Emacs already defines alloca, sometimes. */ -#ifndef alloca - -/* Make alloca work the best possible way. */ -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else /* not __GNUC__ */ -#if HAVE_ALLOCA_H -#include -#else /* not __GNUC__ or HAVE_ALLOCA_H */ -#ifndef _AIX /* Already did AIX, up at the top. */ -char *alloca (); -#endif /* not _AIX */ -#endif /* not HAVE_ALLOCA_H */ -#endif /* not __GNUC__ */ - -#endif /* not alloca */ - -#define REGEX_ALLOCATE alloca - -/* Assumes a `char *destination' variable. */ -#define REGEX_REALLOCATE(source, osize, nsize) \ - (destination = (char *) alloca (nsize), \ - bcopy (source, destination, osize), \ - destination) - -#endif /* not REGEX_MALLOC */ - - -/* True if `size1' is non-NULL and PTR is pointing anywhere inside - `string1' or just past its end. This works if PTR is NULL, which is - a good thing. */ -#define FIRST_STRING_P(ptr) \ - (size1 && string1 <= (ptr) && (ptr) <= string1 + size1) - -/* (Re)Allocate N items of type T using malloc, or fail. */ -#define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t))) -#define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t))) -#define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t))) - -#define BYTEWIDTH 8 /* In bits. */ - -#define STREQ(s1, s2) ((strcmp (s1, s2) == 0)) - -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -typedef char boolean; -#define false 0 -#define true 1 - -/* These are the command codes that appear in compiled regular - expressions. Some opcodes are followed by argument bytes. A - command code can specify any interpretation whatsoever for its - arguments. Zero bytes may appear in the compiled regular expression. - - The value of `exactn' is needed in search.c (search_buffer) in Emacs. - So regex.h defines a symbol `RE_EXACTN_VALUE' to be 1; the value of - `exactn' we use here must also be 1. */ - -typedef enum -{ - no_op = 0, - - /* Followed by one byte giving n, then by n literal bytes. */ - exactn = 1, - - /* Matches any (more or less) character. */ - anychar, - - /* Matches any one char belonging to specified set. First - following byte is number of bitmap bytes. Then come bytes - for a bitmap saying which chars are in. Bits in each byte - are ordered low-bit-first. A character is in the set if its - bit is 1. A character too large to have a bit in the map is - automatically not in the set. */ - charset, - - /* Same parameters as charset, but match any character that is - not one of those specified. */ - charset_not, - - /* Start remembering the text that is matched, for storing in a - register. Followed by one byte with the register number, in - the range 0 to one less than the pattern buffer's re_nsub - field. Then followed by one byte with the number of groups - inner to this one. (This last has to be part of the - start_memory only because we need it in the on_failure_jump - of re_match_2.) */ - start_memory, - - /* Stop remembering the text that is matched and store it in a - memory register. Followed by one byte with the register - number, in the range 0 to one less than `re_nsub' in the - pattern buffer, and one byte with the number of inner groups, - just like `start_memory'. (We need the number of inner - groups here because we don't have any easy way of finding the - corresponding start_memory when we're at a stop_memory.) */ - stop_memory, - - /* Match a duplicate of something remembered. Followed by one - byte containing the register number. */ - duplicate, - - /* Fail unless at beginning of line. */ - begline, - - /* Fail unless at end of line. */ - endline, - - /* Succeeds if at beginning of buffer (if emacs) or at beginning - of string to be matched (if not). */ - begbuf, - - /* Analogously, for end of buffer/string. */ - endbuf, - - /* Followed by two byte relative address to which to jump. */ - jump, - - /* Same as jump, but marks the end of an alternative. */ - jump_past_alt, - - /* Followed by two-byte relative address of place to resume at - in case of failure. */ - on_failure_jump, - - /* Like on_failure_jump, but pushes a placeholder instead of the - current string position when executed. */ - on_failure_keep_string_jump, - - /* Throw away latest failure point and then jump to following - two-byte relative address. */ - pop_failure_jump, - - /* Change to pop_failure_jump if know won't have to backtrack to - match; otherwise change to jump. This is used to jump - back to the beginning of a repeat. If what follows this jump - clearly won't match what the repeat does, such that we can be - sure that there is no use backtracking out of repetitions - already matched, then we change it to a pop_failure_jump. - Followed by two-byte address. */ - maybe_pop_jump, - - /* Jump to following two-byte address, and push a dummy failure - point. This failure point will be thrown away if an attempt - is made to use it for a failure. A `+' construct makes this - before the first repeat. Also used as an intermediary kind - of jump when compiling an alternative. */ - dummy_failure_jump, - - /* Push a dummy failure point and continue. Used at the end of - alternatives. */ - push_dummy_failure, - - /* Followed by two-byte relative address and two-byte number n. - After matching N times, jump to the address upon failure. */ - succeed_n, - - /* Followed by two-byte relative address, and two-byte number n. - Jump to the address N times, then fail. */ - jump_n, - - /* Set the following two-byte relative address to the - subsequent two-byte number. The address *includes* the two - bytes of number. */ - set_number_at, - - wordchar, /* Matches any word-constituent character. */ - notwordchar, /* Matches any char that is not a word-constituent. */ - - wordbeg, /* Succeeds if at word beginning. */ - wordend, /* Succeeds if at word end. */ - - wordbound, /* Succeeds if at a word boundary. */ - notwordbound /* Succeeds if not at a word boundary. */ - -#ifdef emacs - ,before_dot, /* Succeeds if before point. */ - at_dot, /* Succeeds if at point. */ - after_dot, /* Succeeds if after point. */ - - /* Matches any character whose syntax is specified. Followed by - a byte which contains a syntax code, e.g., Sword. */ - syntaxspec, - - /* Matches any character whose syntax is not that specified. */ - notsyntaxspec -#endif /* emacs */ -} re_opcode_t; - -/* Common operations on the compiled pattern. */ - -/* Store NUMBER in two contiguous bytes starting at DESTINATION. */ - -#define STORE_NUMBER(destination, number) \ - do { \ - (destination)[0] = (number) & 0377; \ - (destination)[1] = (number) >> 8; \ - } while (0) - -/* Same as STORE_NUMBER, except increment DESTINATION to - the byte after where the number is stored. Therefore, DESTINATION - must be an lvalue. */ - -#define STORE_NUMBER_AND_INCR(destination, number) \ - do { \ - STORE_NUMBER (destination, number); \ - (destination) += 2; \ - } while (0) - -/* Put into DESTINATION a number stored in two contiguous bytes starting - at SOURCE. */ - -#define EXTRACT_NUMBER(destination, source) \ - do { \ - (destination) = *(source) & 0377; \ - (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \ - } while (0) - -#ifdef DEBUG -static void -extract_number (dest, source) - int *dest; - unsigned char *source; -{ - int temp = SIGN_EXTEND_CHAR (*(source + 1)); - *dest = *source & 0377; - *dest += temp << 8; -} - -#ifndef EXTRACT_MACROS /* To debug the macros. */ -#undef EXTRACT_NUMBER -#define EXTRACT_NUMBER(dest, src) extract_number (&dest, src) -#endif /* not EXTRACT_MACROS */ - -#endif /* DEBUG */ - -/* Same as EXTRACT_NUMBER, except increment SOURCE to after the number. - SOURCE must be an lvalue. */ - -#define EXTRACT_NUMBER_AND_INCR(destination, source) \ - do { \ - EXTRACT_NUMBER (destination, source); \ - (source) += 2; \ - } while (0) - -#ifdef DEBUG -static void -extract_number_and_incr (destination, source) - int *destination; - unsigned char **source; -{ - extract_number (destination, *source); - *source += 2; -} - -#ifndef EXTRACT_MACROS -#undef EXTRACT_NUMBER_AND_INCR -#define EXTRACT_NUMBER_AND_INCR(dest, src) \ - extract_number_and_incr (&dest, &src) -#endif /* not EXTRACT_MACROS */ - -#endif /* DEBUG */ - -/* If DEBUG is defined, Regex prints many voluminous messages about what - it is doing (if the variable `debug' is nonzero). If linked with the - main program in `iregex.c', you can enter patterns and strings - interactively. And if linked with the main program in `main.c' and - the other test files, you can run the already-written tests. */ - -#ifdef DEBUG - -/* We use standard I/O for debugging. */ -#include - -/* It is useful to test things that ``must'' be true when debugging. */ -#include - -static int debug = 0; - -#define DEBUG_STATEMENT(e) e -#define DEBUG_PRINT1(x) if (debug) printf (x) -#define DEBUG_PRINT2(x1, x2) if (debug) printf (x1, x2) -#define DEBUG_PRINT3(x1, x2, x3) if (debug) printf (x1, x2, x3) -#define DEBUG_PRINT4(x1, x2, x3, x4) if (debug) printf (x1, x2, x3, x4) -#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ - if (debug) print_partial_compiled_pattern (s, e) -#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ - if (debug) print_double_string (w, s1, sz1, s2, sz2) - - -extern void printchar (); - -/* Print the fastmap in human-readable form. */ - -void -print_fastmap (fastmap) - char *fastmap; -{ - unsigned was_a_range = 0; - unsigned i = 0; - - while (i < (1 << BYTEWIDTH)) - { - if (fastmap[i++]) - { - was_a_range = 0; - printchar (i - 1); - while (i < (1 << BYTEWIDTH) && fastmap[i]) - { - was_a_range = 1; - i++; - } - if (was_a_range) - { - printf ("-"); - printchar (i - 1); - } - } - } - putchar ('\n'); -} - - -/* Print a compiled pattern string in human-readable form, starting at - the START pointer into it and ending just before the pointer END. */ - -void -print_partial_compiled_pattern (start, end) - unsigned char *start; - unsigned char *end; -{ - int mcnt, mcnt2; - unsigned char *p = start; - unsigned char *pend = end; - - if (start == NULL) - { - printf ("(null)\n"); - return; - } - - /* Loop over pattern commands. */ - while (p < pend) - { - printf ("%d:\t", p - start); - - switch ((re_opcode_t) *p++) - { - case no_op: - printf ("/no_op"); - break; - - case exactn: - mcnt = *p++; - printf ("/exactn/%d", mcnt); - do - { - putchar ('/'); - printchar (*p++); - } - while (--mcnt); - break; - - case start_memory: - mcnt = *p++; - printf ("/start_memory/%d/%d", mcnt, *p++); - break; - - case stop_memory: - mcnt = *p++; - printf ("/stop_memory/%d/%d", mcnt, *p++); - break; - - case duplicate: - printf ("/duplicate/%d", *p++); - break; - - case anychar: - printf ("/anychar"); - break; - - case charset: - case charset_not: - { - register int c, last = -100; - register int in_range = 0; - - printf ("/charset [%s", - (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); - - assert (p + *p < pend); - - for (c = 0; c < 256; c++) - if (c / 8 < *p - && (p[1 + (c/8)] & (1 << (c % 8)))) - { - /* Are we starting a range? */ - if (last + 1 == c && ! in_range) - { - putchar ('-'); - in_range = 1; - } - /* Have we broken a range? */ - else if (last + 1 != c && in_range) - { - printchar (last); - in_range = 0; - } - - if (! in_range) - printchar (c); - - last = c; - } - - if (in_range) - printchar (last); - - putchar (']'); - - p += 1 + *p; - } - break; - - case begline: - printf ("/begline"); - break; - - case endline: - printf ("/endline"); - break; - - case on_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/on_failure_jump to %d", p + mcnt - start); - break; - - case on_failure_keep_string_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/on_failure_keep_string_jump to %d", p + mcnt - start); - break; - - case dummy_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/dummy_failure_jump to %d", p + mcnt - start); - break; - - case push_dummy_failure: - printf ("/push_dummy_failure"); - break; - - case maybe_pop_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/maybe_pop_jump to %d", p + mcnt - start); - break; - - case pop_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/pop_failure_jump to %d", p + mcnt - start); - break; - - case jump_past_alt: - extract_number_and_incr (&mcnt, &p); - printf ("/jump_past_alt to %d", p + mcnt - start); - break; - - case jump: - extract_number_and_incr (&mcnt, &p); - printf ("/jump to %d", p + mcnt - start); - break; - - case succeed_n: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/succeed_n to %d, %d times", p + mcnt - start, mcnt2); - break; - - case jump_n: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/jump_n to %d, %d times", p + mcnt - start, mcnt2); - break; - - case set_number_at: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/set_number_at location %d to %d", p + mcnt - start, mcnt2); - break; - - case wordbound: - printf ("/wordbound"); - break; - - case notwordbound: - printf ("/notwordbound"); - break; - - case wordbeg: - printf ("/wordbeg"); - break; - - case wordend: - printf ("/wordend"); - -#ifdef emacs - case before_dot: - printf ("/before_dot"); - break; - - case at_dot: - printf ("/at_dot"); - break; - - case after_dot: - printf ("/after_dot"); - break; - - case syntaxspec: - printf ("/syntaxspec"); - mcnt = *p++; - printf ("/%d", mcnt); - break; - - case notsyntaxspec: - printf ("/notsyntaxspec"); - mcnt = *p++; - printf ("/%d", mcnt); - break; -#endif /* emacs */ - - case wordchar: - printf ("/wordchar"); - break; - - case notwordchar: - printf ("/notwordchar"); - break; - - case begbuf: - printf ("/begbuf"); - break; - - case endbuf: - printf ("/endbuf"); - break; - - default: - printf ("?%d", *(p-1)); - } - - putchar ('\n'); - } - - printf ("%d:\tend of pattern.\n", p - start); -} - - -void -print_compiled_pattern (bufp) - struct re_pattern_buffer *bufp; -{ - unsigned char *buffer = bufp->buffer; - - print_partial_compiled_pattern (buffer, buffer + bufp->used); - printf ("%d bytes used/%d bytes allocated.\n", bufp->used, bufp->allocated); - - if (bufp->fastmap_accurate && bufp->fastmap) - { - printf ("fastmap: "); - print_fastmap (bufp->fastmap); - } - - printf ("re_nsub: %d\t", bufp->re_nsub); - printf ("regs_alloc: %d\t", bufp->regs_allocated); - printf ("can_be_null: %d\t", bufp->can_be_null); - printf ("newline_anchor: %d\n", bufp->newline_anchor); - printf ("no_sub: %d\t", bufp->no_sub); - printf ("not_bol: %d\t", bufp->not_bol); - printf ("not_eol: %d\t", bufp->not_eol); - printf ("syntax: %d\n", bufp->syntax); - /* Perhaps we should print the translate table? */ -} - - -void -print_double_string (where, string1, size1, string2, size2) - const char *where; - const char *string1; - const char *string2; - int size1; - int size2; -{ - unsigned this_char; - - if (where == NULL) - printf ("(null)"); - else - { - if (FIRST_STRING_P (where)) - { - for (this_char = where - string1; this_char < size1; this_char++) - printchar (string1[this_char]); - - where = string2; - } - - for (this_char = where - string2; this_char < size2; this_char++) - printchar (string2[this_char]); - } -} - -#else /* not DEBUG */ - -#undef assert -#define assert(e) - -#define DEBUG_STATEMENT(e) -#define DEBUG_PRINT1(x) -#define DEBUG_PRINT2(x1, x2) -#define DEBUG_PRINT3(x1, x2, x3) -#define DEBUG_PRINT4(x1, x2, x3, x4) -#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) -#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) - -#endif /* not DEBUG */ - -/* Set by `re_set_syntax' to the current regexp syntax to recognize. Can - also be assigned to arbitrarily: each pattern buffer stores its own - syntax, so it can be changed between regex compilations. */ -reg_syntax_t re_syntax_options = RE_SYNTAX_EMACS; - - -/* Specify the precise syntax of regexps for compilation. This provides - for compatibility for various utilities which historically have - different, incompatible syntaxes. - - The argument SYNTAX is a bit mask comprised of the various bits - defined in regex.h. We return the old syntax. */ - -reg_syntax_t -re_set_syntax (syntax) - reg_syntax_t syntax; -{ - reg_syntax_t ret = re_syntax_options; - - re_syntax_options = syntax; - return ret; -} - -/* This table gives an error message for each of the error codes listed - in regex.h. Obviously the order here has to be same as there. */ - -static const char *re_error_msg[] = - { NULL, /* REG_NOERROR */ - "No match", /* REG_NOMATCH */ - "Invalid regular expression", /* REG_BADPAT */ - "Invalid collation character", /* REG_ECOLLATE */ - "Invalid character class name", /* REG_ECTYPE */ - "Trailing backslash", /* REG_EESCAPE */ - "Invalid back reference", /* REG_ESUBREG */ - "Unmatched [ or [^", /* REG_EBRACK */ - "Unmatched ( or \\(", /* REG_EPAREN */ - "Unmatched \\{", /* REG_EBRACE */ - "Invalid content of \\{\\}", /* REG_BADBR */ - "Invalid range end", /* REG_ERANGE */ - "Memory exhausted", /* REG_ESPACE */ - "Invalid preceding regular expression", /* REG_BADRPT */ - "Premature end of regular expression", /* REG_EEND */ - "Regular expression too big", /* REG_ESIZE */ - "Unmatched ) or \\)", /* REG_ERPAREN */ - }; - -/* Subroutine declarations and macros for regex_compile. */ - -static void store_op1 (), store_op2 (); -static void insert_op1 (), insert_op2 (); -static boolean at_begline_loc_p (), at_endline_loc_p (); -static boolean group_in_compile_stack (); -static reg_errcode_t compile_range (); - -/* Fetch the next character in the uncompiled pattern---translating it - if necessary. Also cast from a signed character in the constant - string passed to us by the user to an unsigned char that we can use - as an array index (in, e.g., `translate'). */ -#define PATFETCH(c) \ - do {if (p == pend) return REG_EEND; \ - c = (unsigned char) *p++; \ - if (translate) c = translate[c]; \ - } while (0) - -/* Fetch the next character in the uncompiled pattern, with no - translation. */ -#define PATFETCH_RAW(c) \ - do {if (p == pend) return REG_EEND; \ - c = (unsigned char) *p++; \ - } while (0) - -/* Go backwards one character in the pattern. */ -#define PATUNFETCH p-- - - -/* If `translate' is non-null, return translate[D], else just D. We - cast the subscript to translate because some data is declared as - `char *', to avoid warnings when a string constant is passed. But - when we use a character as a subscript we must make it unsigned. */ -#define TRANSLATE(d) (translate ? translate[(unsigned char) (d)] : (d)) - - -/* Macros for outputting the compiled pattern into `buffer'. */ - -/* If the buffer isn't allocated when it comes in, use this. */ -#define INIT_BUF_SIZE 32 - -/* Make sure we have at least N more bytes of space in buffer. */ -#define GET_BUFFER_SPACE(n) \ - while (b - bufp->buffer + (n) > bufp->allocated) \ - EXTEND_BUFFER () - -/* Make sure we have one more byte of buffer space and then add C to it. */ -#define BUF_PUSH(c) \ - do { \ - GET_BUFFER_SPACE (1); \ - *b++ = (unsigned char) (c); \ - } while (0) - - -/* Ensure we have two more bytes of buffer space and then append C1 and C2. */ -#define BUF_PUSH_2(c1, c2) \ - do { \ - GET_BUFFER_SPACE (2); \ - *b++ = (unsigned char) (c1); \ - *b++ = (unsigned char) (c2); \ - } while (0) - - -/* As with BUF_PUSH_2, except for three bytes. */ -#define BUF_PUSH_3(c1, c2, c3) \ - do { \ - GET_BUFFER_SPACE (3); \ - *b++ = (unsigned char) (c1); \ - *b++ = (unsigned char) (c2); \ - *b++ = (unsigned char) (c3); \ - } while (0) - - -/* Store a jump with opcode OP at LOC to location TO. We store a - relative address offset by the three bytes the jump itself occupies. */ -#define STORE_JUMP(op, loc, to) \ - store_op1 (op, loc, (to) - (loc) - 3) - -/* Likewise, for a two-argument jump. */ -#define STORE_JUMP2(op, loc, to, arg) \ - store_op2 (op, loc, (to) - (loc) - 3, arg) - -/* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */ -#define INSERT_JUMP(op, loc, to) \ - insert_op1 (op, loc, (to) - (loc) - 3, b) - -/* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */ -#define INSERT_JUMP2(op, loc, to, arg) \ - insert_op2 (op, loc, (to) - (loc) - 3, arg, b) - - -/* This is not an arbitrary limit: the arguments which represent offsets - into the pattern are two bytes long. So if 2^16 bytes turns out to - be too small, many things would have to change. */ -#define MAX_BUF_SIZE (1L << 16) - - -/* Extend the buffer by twice its current size via realloc and - reset the pointers that pointed into the old block to point to the - correct places in the new one. If extending the buffer results in it - being larger than MAX_BUF_SIZE, then flag memory exhausted. */ -#define EXTEND_BUFFER() \ - do { \ - unsigned char *old_buffer = bufp->buffer; \ - if (bufp->allocated == MAX_BUF_SIZE) \ - return REG_ESIZE; \ - bufp->allocated <<= 1; \ - if (bufp->allocated > MAX_BUF_SIZE) \ - bufp->allocated = MAX_BUF_SIZE; \ - bufp->buffer = (unsigned char *) realloc (bufp->buffer, bufp->allocated);\ - if (bufp->buffer == NULL) \ - return REG_ESPACE; \ - /* If the buffer moved, move all the pointers into it. */ \ - if (old_buffer != bufp->buffer) \ - { \ - b = (b - old_buffer) + bufp->buffer; \ - begalt = (begalt - old_buffer) + bufp->buffer; \ - if (fixup_alt_jump) \ - fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\ - if (laststart) \ - laststart = (laststart - old_buffer) + bufp->buffer; \ - if (pending_exact) \ - pending_exact = (pending_exact - old_buffer) + bufp->buffer; \ - } \ - } while (0) - - -/* Since we have one byte reserved for the register number argument to - {start,stop}_memory, the maximum number of groups we can report - things about is what fits in that byte. */ -#define MAX_REGNUM 255 - -/* But patterns can have more than `MAX_REGNUM' registers. We just - ignore the excess. */ -typedef unsigned regnum_t; - - -/* Macros for the compile stack. */ - -/* Since offsets can go either forwards or backwards, this type needs to - be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ -typedef int pattern_offset_t; - -typedef struct -{ - pattern_offset_t begalt_offset; - pattern_offset_t fixup_alt_jump; - pattern_offset_t inner_group_offset; - pattern_offset_t laststart_offset; - regnum_t regnum; -} compile_stack_elt_t; - - -typedef struct -{ - compile_stack_elt_t *stack; - unsigned size; - unsigned avail; /* Offset of next open position. */ -} compile_stack_type; - - -#define INIT_COMPILE_STACK_SIZE 32 - -#define COMPILE_STACK_EMPTY (compile_stack.avail == 0) -#define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size) - -/* The next available element. */ -#define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail]) - - -/* Set the bit for character C in a list. */ -#define SET_LIST_BIT(c) \ - (b[((unsigned char) (c)) / BYTEWIDTH] \ - |= 1 << (((unsigned char) c) % BYTEWIDTH)) - - -/* Get the next unsigned number in the uncompiled pattern. */ -#define GET_UNSIGNED_NUMBER(num) \ - { if (p != pend) \ - { \ - PATFETCH (c); \ - while (ISDIGIT (c)) \ - { \ - if (num < 0) \ - num = 0; \ - num = num * 10 + c - '0'; \ - if (p == pend) \ - break; \ - PATFETCH (c); \ - } \ - } \ - } - -#define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ - -#define IS_CHAR_CLASS(string) \ - (STREQ (string, "alpha") || STREQ (string, "upper") \ - || STREQ (string, "lower") || STREQ (string, "digit") \ - || STREQ (string, "alnum") || STREQ (string, "xdigit") \ - || STREQ (string, "space") || STREQ (string, "print") \ - || STREQ (string, "punct") || STREQ (string, "graph") \ - || STREQ (string, "cntrl") || STREQ (string, "blank")) - -/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. - Returns one of error codes defined in `regex.h', or zero for success. - - Assumes the `allocated' (and perhaps `buffer') and `translate' - fields are set in BUFP on entry. - - If it succeeds, results are put in BUFP (if it returns an error, the - contents of BUFP are undefined): - `buffer' is the compiled pattern; - `syntax' is set to SYNTAX; - `used' is set to the length of the compiled pattern; - `fastmap_accurate' is zero; - `re_nsub' is the number of subexpressions in PATTERN; - `not_bol' and `not_eol' are zero; - - The `fastmap' and `newline_anchor' fields are neither - examined nor set. */ - -static reg_errcode_t -regex_compile (pattern, size, syntax, bufp) - const char *pattern; - int size; - reg_syntax_t syntax; - struct re_pattern_buffer *bufp; -{ - /* We fetch characters from PATTERN here. Even though PATTERN is - `char *' (i.e., signed), we declare these variables as unsigned, so - they can be reliably used as array indices. */ - register unsigned char c, c1; - - /* A random tempory spot in PATTERN. */ - const char *p1; - - /* Points to the end of the buffer, where we should append. */ - register unsigned char *b; - - /* Keeps track of unclosed groups. */ - compile_stack_type compile_stack; - - /* Points to the current (ending) position in the pattern. */ - const char *p = pattern; - const char *pend = pattern + size; - - /* How to translate the characters in the pattern. */ - char *translate = bufp->translate; - - /* Address of the count-byte of the most recently inserted `exactn' - command. This makes it possible to tell if a new exact-match - character can be added to that command or if the character requires - a new `exactn' command. */ - unsigned char *pending_exact = 0; - - /* Address of start of the most recently finished expression. - This tells, e.g., postfix * where to find the start of its - operand. Reset at the beginning of groups and alternatives. */ - unsigned char *laststart = 0; - - /* Address of beginning of regexp, or inside of last group. */ - unsigned char *begalt; - - /* Place in the uncompiled pattern (i.e., the {) to - which to go back if the interval is invalid. */ - const char *beg_interval; - - /* Address of the place where a forward jump should go to the end of - the containing expression. Each alternative of an `or' -- except the - last -- ends with a forward jump of this sort. */ - unsigned char *fixup_alt_jump = 0; - - /* Counts open-groups as they are encountered. Remembered for the - matching close-group on the compile stack, so the same register - number is put in the stop_memory as the start_memory. */ - regnum_t regnum = 0; - -#ifdef DEBUG - DEBUG_PRINT1 ("\nCompiling pattern: "); - if (debug) - { - unsigned debug_count; - - for (debug_count = 0; debug_count < size; debug_count++) - printchar (pattern[debug_count]); - putchar ('\n'); - } -#endif /* DEBUG */ - - /* Initialize the compile stack. */ - compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t); - if (compile_stack.stack == NULL) - return REG_ESPACE; - - compile_stack.size = INIT_COMPILE_STACK_SIZE; - compile_stack.avail = 0; - - /* Initialize the pattern buffer. */ - bufp->syntax = syntax; - bufp->fastmap_accurate = 0; - bufp->not_bol = bufp->not_eol = 0; - - /* Set `used' to zero, so that if we return an error, the pattern - printer (for debugging) will think there's no pattern. We reset it - at the end. */ - bufp->used = 0; - - /* Always count groups, whether or not bufp->no_sub is set. */ - bufp->re_nsub = 0; - -#if !defined (emacs) && !defined (SYNTAX_TABLE) - /* Initialize the syntax table. */ - init_syntax_once (); -#endif - - if (bufp->allocated == 0) - { - if (bufp->buffer) - { /* If zero allocated, but buffer is non-null, try to realloc - enough space. This loses if buffer's address is bogus, but - that is the user's responsibility. */ - RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char); - } - else - { /* Caller did not allocate a buffer. Do it for them. */ - bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char); - } - if (!bufp->buffer) return REG_ESPACE; - - bufp->allocated = INIT_BUF_SIZE; - } - - begalt = b = bufp->buffer; - - /* Loop through the uncompiled pattern until we're at the end. */ - while (p != pend) - { - PATFETCH (c); - - switch (c) - { - case '^': - { - if ( /* If at start of pattern, it's an operator. */ - p == pattern + 1 - /* If context independent, it's an operator. */ - || syntax & RE_CONTEXT_INDEP_ANCHORS - /* Otherwise, depends on what's come before. */ - || at_begline_loc_p (pattern, p, syntax)) - BUF_PUSH (begline); - else - goto normal_char; - } - break; - - - case '$': - { - if ( /* If at end of pattern, it's an operator. */ - p == pend - /* If context independent, it's an operator. */ - || syntax & RE_CONTEXT_INDEP_ANCHORS - /* Otherwise, depends on what's next. */ - || at_endline_loc_p (p, pend, syntax)) - BUF_PUSH (endline); - else - goto normal_char; - } - break; - - - case '+': - case '?': - if ((syntax & RE_BK_PLUS_QM) - || (syntax & RE_LIMITED_OPS)) - goto normal_char; - handle_plus: - case '*': - /* If there is no previous pattern... */ - if (!laststart) - { - if (syntax & RE_CONTEXT_INVALID_OPS) - return REG_BADRPT; - else if (!(syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - } - - { - /* Are we optimizing this jump? */ - boolean keep_string_p = false; - - /* 1 means zero (many) matches is allowed. */ - char zero_times_ok = 0, many_times_ok = 0; - - /* If there is a sequence of repetition chars, collapse it - down to just one (the right one). We can't combine - interval operators with these because of, e.g., `a{2}*', - which should only match an even number of `a's. */ - - for (;;) - { - zero_times_ok |= c != '+'; - many_times_ok |= c != '?'; - - if (p == pend) - break; - - PATFETCH (c); - - if (c == '*' - || (!(syntax & RE_BK_PLUS_QM) && (c == '+' || c == '?'))) - ; - - else if (syntax & RE_BK_PLUS_QM && c == '\\') - { - if (p == pend) return REG_EESCAPE; - - PATFETCH (c1); - if (!(c1 == '+' || c1 == '?')) - { - PATUNFETCH; - PATUNFETCH; - break; - } - - c = c1; - } - else - { - PATUNFETCH; - break; - } - - /* If we get here, we found another repeat character. */ - } - - /* Star, etc. applied to an empty pattern is equivalent - to an empty pattern. */ - if (!laststart) - break; - - /* Now we know whether or not zero matches is allowed - and also whether or not two or more matches is allowed. */ - if (many_times_ok) - { /* More than one repetition is allowed, so put in at the - end a backward relative jump from `b' to before the next - jump we're going to put in below (which jumps from - laststart to after this jump). - - But if we are at the `*' in the exact sequence `.*\n', - insert an unconditional jump backwards to the ., - instead of the beginning of the loop. This way we only - push a failure point once, instead of every time - through the loop. */ - assert (p - 1 > pattern); - - /* Allocate the space for the jump. */ - GET_BUFFER_SPACE (3); - - /* We know we are not at the first character of the pattern, - because laststart was nonzero. And we've already - incremented `p', by the way, to be the character after - the `*'. Do we have to do something analogous here - for null bytes, because of RE_DOT_NOT_NULL? */ - if (TRANSLATE (*(p - 2)) == TRANSLATE ('.') - && zero_times_ok - && p < pend && TRANSLATE (*p) == TRANSLATE ('\n') - && !(syntax & RE_DOT_NEWLINE)) - { /* We have .*\n. */ - STORE_JUMP (jump, b, laststart); - keep_string_p = true; - } - else - /* Anything else. */ - STORE_JUMP (maybe_pop_jump, b, laststart - 3); - - /* We've added more stuff to the buffer. */ - b += 3; - } - - /* On failure, jump from laststart to b + 3, which will be the - end of the buffer after this jump is inserted. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump - : on_failure_jump, - laststart, b + 3); - pending_exact = 0; - b += 3; - - if (!zero_times_ok) - { - /* At least one repetition is required, so insert a - `dummy_failure_jump' before the initial - `on_failure_jump' instruction of the loop. This - effects a skip over that instruction the first time - we hit that loop. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6); - b += 3; - } - } - break; - - - case '.': - laststart = b; - BUF_PUSH (anychar); - break; - - - case '[': - { - boolean had_char_class = false; - - if (p == pend) return REG_EBRACK; - - /* Ensure that we have enough space to push a charset: the - opcode, the length count, and the bitset; 34 bytes in all. */ - GET_BUFFER_SPACE (34); - - laststart = b; - - /* We test `*p == '^' twice, instead of using an if - statement, so we only need one BUF_PUSH. */ - BUF_PUSH (*p == '^' ? charset_not : charset); - if (*p == '^') - p++; - - /* Remember the first position in the bracket expression. */ - p1 = p; - - /* Push the number of bytes in the bitmap. */ - BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH); - - /* Clear the whole map. */ - bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH); - - /* charset_not matches newline according to a syntax bit. */ - if ((re_opcode_t) b[-2] == charset_not - && (syntax & RE_HAT_LISTS_NOT_NEWLINE)) - SET_LIST_BIT ('\n'); - - /* Read in characters and ranges, setting map bits. */ - for (;;) - { - if (p == pend) return REG_EBRACK; - - PATFETCH (c); - - /* \ might escape characters inside [...] and [^...]. */ - if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\') - { - if (p == pend) return REG_EESCAPE; - - PATFETCH (c1); - SET_LIST_BIT (c1); - continue; - } - - /* Could be the end of the bracket expression. If it's - not (i.e., when the bracket expression is `[]' so - far), the ']' character bit gets set way below. */ - if (c == ']' && p != p1 + 1) - break; - - /* Look ahead to see if it's a range when the last thing - was a character class. */ - if (had_char_class && c == '-' && *p != ']') - return REG_ERANGE; - - /* Look ahead to see if it's a range when the last thing - was a character: if this is a hyphen not at the - beginning or the end of a list, then it's the range - operator. */ - if (c == '-' - && !(p - 2 >= pattern && p[-2] == '[') - && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^') - && *p != ']') - { - reg_errcode_t ret - = compile_range (&p, pend, translate, syntax, b); - if (ret != REG_NOERROR) return ret; - } - - else if (p[0] == '-' && p[1] != ']') - { /* This handles ranges made up of characters only. */ - reg_errcode_t ret; - - /* Move past the `-'. */ - PATFETCH (c1); - - ret = compile_range (&p, pend, translate, syntax, b); - if (ret != REG_NOERROR) return ret; - } - - /* See if we're at the beginning of a possible character - class. */ - - else if (syntax & RE_CHAR_CLASSES && c == '[' && *p == ':') - { /* Leave room for the null. */ - char str[CHAR_CLASS_MAX_LENGTH + 1]; - - PATFETCH (c); - c1 = 0; - - /* If pattern is `[[:'. */ - if (p == pend) return REG_EBRACK; - - for (;;) - { - PATFETCH (c); - if (c == ':' || c == ']' || p == pend - || c1 == CHAR_CLASS_MAX_LENGTH) - break; - str[c1++] = c; - } - str[c1] = '\0'; - - /* If isn't a word bracketed by `[:' and:`]': - undo the ending character, the letters, and leave - the leading `:' and `[' (but set bits for them). */ - if (c == ':' && *p == ']') - { - int ch; - boolean is_alnum = STREQ (str, "alnum"); - boolean is_alpha = STREQ (str, "alpha"); - boolean is_blank = STREQ (str, "blank"); - boolean is_cntrl = STREQ (str, "cntrl"); - boolean is_digit = STREQ (str, "digit"); - boolean is_graph = STREQ (str, "graph"); - boolean is_lower = STREQ (str, "lower"); - boolean is_print = STREQ (str, "print"); - boolean is_punct = STREQ (str, "punct"); - boolean is_space = STREQ (str, "space"); - boolean is_upper = STREQ (str, "upper"); - boolean is_xdigit = STREQ (str, "xdigit"); - - if (!IS_CHAR_CLASS (str)) return REG_ECTYPE; - - /* Throw away the ] at the end of the character - class. */ - PATFETCH (c); - - if (p == pend) return REG_EBRACK; - - for (ch = 0; ch < 1 << BYTEWIDTH; ch++) - { - if ( (is_alnum && ISALNUM (ch)) - || (is_alpha && ISALPHA (ch)) - || (is_blank && ISBLANK (ch)) - || (is_cntrl && ISCNTRL (ch)) - || (is_digit && ISDIGIT (ch)) - || (is_graph && ISGRAPH (ch)) - || (is_lower && ISLOWER (ch)) - || (is_print && ISPRINT (ch)) - || (is_punct && ISPUNCT (ch)) - || (is_space && ISSPACE (ch)) - || (is_upper && ISUPPER (ch)) - || (is_xdigit && ISXDIGIT (ch))) - SET_LIST_BIT (ch); - } - had_char_class = true; - } - else - { - c1++; - while (c1--) - PATUNFETCH; - SET_LIST_BIT ('['); - SET_LIST_BIT (':'); - had_char_class = false; - } - } - else - { - had_char_class = false; - SET_LIST_BIT (c); - } - } - - /* Discard any (non)matching list bytes that are all 0 at the - end of the map. Decrease the map-length byte too. */ - while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) - b[-1]--; - b += b[-1]; - } - break; - - - case '(': - if (syntax & RE_NO_BK_PARENS) - goto handle_open; - else - goto normal_char; - - - case ')': - if (syntax & RE_NO_BK_PARENS) - goto handle_close; - else - goto normal_char; - - - case '\n': - if (syntax & RE_NEWLINE_ALT) - goto handle_alt; - else - goto normal_char; - - - case '|': - if (syntax & RE_NO_BK_VBAR) - goto handle_alt; - else - goto normal_char; - - - case '{': - if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES) - goto handle_interval; - else - goto normal_char; - - - case '\\': - if (p == pend) return REG_EESCAPE; - - /* Do not translate the character after the \, so that we can - distinguish, e.g., \B from \b, even if we normally would - translate, e.g., B to b. */ - PATFETCH_RAW (c); - - switch (c) - { - case '(': - if (syntax & RE_NO_BK_PARENS) - goto normal_backslash; - - handle_open: - bufp->re_nsub++; - regnum++; - - if (COMPILE_STACK_FULL) - { - RETALLOC (compile_stack.stack, compile_stack.size << 1, - compile_stack_elt_t); - if (compile_stack.stack == NULL) return REG_ESPACE; - - compile_stack.size <<= 1; - } - - /* These are the values to restore when we hit end of this - group. They are all relative offsets, so that if the - whole pattern moves because of realloc, they will still - be valid. */ - COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer; - COMPILE_STACK_TOP.fixup_alt_jump - = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0; - COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer; - COMPILE_STACK_TOP.regnum = regnum; - - /* We will eventually replace the 0 with the number of - groups inner to this one. But do not push a - start_memory for groups beyond the last one we can - represent in the compiled pattern. */ - if (regnum <= MAX_REGNUM) - { - COMPILE_STACK_TOP.inner_group_offset = b - bufp->buffer + 2; - BUF_PUSH_3 (start_memory, regnum, 0); - } - - compile_stack.avail++; - - fixup_alt_jump = 0; - laststart = 0; - begalt = b; - /* If we've reached MAX_REGNUM groups, then this open - won't actually generate any code, so we'll have to - clear pending_exact explicitly. */ - pending_exact = 0; - break; - - - case ')': - if (syntax & RE_NO_BK_PARENS) goto normal_backslash; - - if (COMPILE_STACK_EMPTY) - if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) - goto normal_backslash; - else - return REG_ERPAREN; - - handle_close: - if (fixup_alt_jump) - { /* Push a dummy failure point at the end of the - alternative for a possible future - `pop_failure_jump' to pop. See comments at - `push_dummy_failure' in `re_match_2'. */ - BUF_PUSH (push_dummy_failure); - - /* We allocated space for this jump when we assigned - to `fixup_alt_jump', in the `handle_alt' case below. */ - STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1); - } - - /* See similar code for backslashed left paren above. */ - if (COMPILE_STACK_EMPTY) - if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) - goto normal_char; - else - return REG_ERPAREN; - - /* Since we just checked for an empty stack above, this - ``can't happen''. */ - assert (compile_stack.avail != 0); - { - /* We don't just want to restore into `regnum', because - later groups should continue to be numbered higher, - as in `(ab)c(de)' -- the second group is #2. */ - regnum_t this_group_regnum; - - compile_stack.avail--; - begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset; - fixup_alt_jump - = COMPILE_STACK_TOP.fixup_alt_jump - ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 - : 0; - laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; - this_group_regnum = COMPILE_STACK_TOP.regnum; - /* If we've reached MAX_REGNUM groups, then this open - won't actually generate any code, so we'll have to - clear pending_exact explicitly. */ - pending_exact = 0; - - /* We're at the end of the group, so now we know how many - groups were inside this one. */ - if (this_group_regnum <= MAX_REGNUM) - { - unsigned char *inner_group_loc - = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset; - - *inner_group_loc = regnum - this_group_regnum; - BUF_PUSH_3 (stop_memory, this_group_regnum, - regnum - this_group_regnum); - } - } - break; - - - case '|': /* `\|'. */ - if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR) - goto normal_backslash; - handle_alt: - if (syntax & RE_LIMITED_OPS) - goto normal_char; - - /* Insert before the previous alternative a jump which - jumps to this alternative if the former fails. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (on_failure_jump, begalt, b + 6); - pending_exact = 0; - b += 3; - - /* The alternative before this one has a jump after it - which gets executed if it gets matched. Adjust that - jump so it will jump to this alternative's analogous - jump (put in below, which in turn will jump to the next - (if any) alternative's such jump, etc.). The last such - jump jumps to the correct final destination. A picture: - _____ _____ - | | | | - | v | v - a | b | c - - If we are at `b', then fixup_alt_jump right now points to a - three-byte space after `a'. We'll put in the jump, set - fixup_alt_jump to right after `b', and leave behind three - bytes which we'll fill in when we get to after `c'. */ - - if (fixup_alt_jump) - STORE_JUMP (jump_past_alt, fixup_alt_jump, b); - - /* Mark and leave space for a jump after this alternative, - to be filled in later either by next alternative or - when know we're at the end of a series of alternatives. */ - fixup_alt_jump = b; - GET_BUFFER_SPACE (3); - b += 3; - - laststart = 0; - begalt = b; - break; - - - case '{': - /* If \{ is a literal. */ - if (!(syntax & RE_INTERVALS) - /* If we're at `\{' and it's not the open-interval - operator. */ - || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) - || (p - 2 == pattern && p == pend)) - goto normal_backslash; - - handle_interval: - { - /* If got here, then the syntax allows intervals. */ - - /* At least (most) this many matches must be made. */ - int lower_bound = -1, upper_bound = -1; - - beg_interval = p - 1; - - if (p == pend) - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_EBRACE; - } - - GET_UNSIGNED_NUMBER (lower_bound); - - if (c == ',') - { - GET_UNSIGNED_NUMBER (upper_bound); - if (upper_bound < 0) upper_bound = RE_DUP_MAX; - } - else - /* Interval such as `{1}' => match exactly once. */ - upper_bound = lower_bound; - - if (lower_bound < 0 || upper_bound > RE_DUP_MAX - || lower_bound > upper_bound) - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_BADBR; - } - - if (!(syntax & RE_NO_BK_BRACES)) - { - if (c != '\\') return REG_EBRACE; - - PATFETCH (c); - } - - if (c != '}') - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_BADBR; - } - - /* We just parsed a valid interval. */ - - /* If it's invalid to have no preceding re. */ - if (!laststart) - { - if (syntax & RE_CONTEXT_INVALID_OPS) - return REG_BADRPT; - else if (syntax & RE_CONTEXT_INDEP_OPS) - laststart = b; - else - goto unfetch_interval; - } - - /* If the upper bound is zero, don't want to succeed at - all; jump from `laststart' to `b + 3', which will be - the end of the buffer after we insert the jump. */ - if (upper_bound == 0) - { - GET_BUFFER_SPACE (3); - INSERT_JUMP (jump, laststart, b + 3); - b += 3; - } - - /* Otherwise, we have a nontrivial interval. When - we're all done, the pattern will look like: - set_number_at - set_number_at - succeed_n - - jump_n - (The upper bound and `jump_n' are omitted if - `upper_bound' is 1, though.) */ - else - { /* If the upper bound is > 1, we need to insert - more at the end of the loop. */ - unsigned nbytes = 10 + (upper_bound > 1) * 10; - - GET_BUFFER_SPACE (nbytes); - - /* Initialize lower bound of the `succeed_n', even - though it will be set during matching by its - attendant `set_number_at' (inserted next), - because `re_compile_fastmap' needs to know. - Jump to the `jump_n' we might insert below. */ - INSERT_JUMP2 (succeed_n, laststart, - b + 5 + (upper_bound > 1) * 5, - lower_bound); - b += 5; - - /* Code to initialize the lower bound. Insert - before the `succeed_n'. The `5' is the last two - bytes of this `set_number_at', plus 3 bytes of - the following `succeed_n'. */ - insert_op2 (set_number_at, laststart, 5, lower_bound, b); - b += 5; - - if (upper_bound > 1) - { /* More than one repetition is allowed, so - append a backward jump to the `succeed_n' - that starts this interval. - - When we've reached this during matching, - we'll have matched the interval once, so - jump back only `upper_bound - 1' times. */ - STORE_JUMP2 (jump_n, b, laststart + 5, - upper_bound - 1); - b += 5; - - /* The location we want to set is the second - parameter of the `jump_n'; that is `b-2' as - an absolute address. `laststart' will be - the `set_number_at' we're about to insert; - `laststart+3' the number to set, the source - for the relative address. But we are - inserting into the middle of the pattern -- - so everything is getting moved up by 5. - Conclusion: (b - 2) - (laststart + 3) + 5, - i.e., b - laststart. - - We insert this at the beginning of the loop - so that if we fail during matching, we'll - reinitialize the bounds. */ - insert_op2 (set_number_at, laststart, b - laststart, - upper_bound - 1, b); - b += 5; - } - } - pending_exact = 0; - beg_interval = NULL; - } - break; - - unfetch_interval: - /* If an invalid interval, match the characters as literals. */ - assert (beg_interval); - p = beg_interval; - beg_interval = NULL; - - /* normal_char and normal_backslash need `c'. */ - PATFETCH (c); - - if (!(syntax & RE_NO_BK_BRACES)) - { - if (p > pattern && p[-1] == '\\') - goto normal_backslash; - } - goto normal_char; - -#ifdef emacs - /* There is no way to specify the before_dot and after_dot - operators. rms says this is ok. --karl */ - case '=': - BUF_PUSH (at_dot); - break; - - case 's': - laststart = b; - PATFETCH (c); - BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]); - break; - - case 'S': - laststart = b; - PATFETCH (c); - BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]); - break; -#endif /* emacs */ - - - case 'w': - laststart = b; - BUF_PUSH (wordchar); - break; - - - case 'W': - laststart = b; - BUF_PUSH (notwordchar); - break; - - - case '<': - BUF_PUSH (wordbeg); - break; - - case '>': - BUF_PUSH (wordend); - break; - - case 'b': - BUF_PUSH (wordbound); - break; - - case 'B': - BUF_PUSH (notwordbound); - break; - - case '`': - BUF_PUSH (begbuf); - break; - - case '\'': - BUF_PUSH (endbuf); - break; - - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - if (syntax & RE_NO_BK_REFS) - goto normal_char; - - c1 = c - '0'; - - if (c1 > regnum) - return REG_ESUBREG; - - /* Can't back reference to a subexpression if inside of it. */ - if (group_in_compile_stack (compile_stack, c1)) - goto normal_char; - - laststart = b; - BUF_PUSH_2 (duplicate, c1); - break; - - - case '+': - case '?': - if (syntax & RE_BK_PLUS_QM) - goto handle_plus; - else - goto normal_backslash; - - default: - normal_backslash: - /* You might think it would be useful for \ to mean - not to translate; but if we don't translate it - it will never match anything. */ - c = TRANSLATE (c); - goto normal_char; - } - break; - - - default: - /* Expects the character in `c'. */ - normal_char: - /* If no exactn currently being built. */ - if (!pending_exact - - /* If last exactn not at current position. */ - || pending_exact + *pending_exact + 1 != b - - /* We have only one byte following the exactn for the count. */ - || *pending_exact == (1 << BYTEWIDTH) - 1 - - /* If followed by a repetition operator. */ - || *p == '*' || *p == '^' - || ((syntax & RE_BK_PLUS_QM) - ? *p == '\\' && (p[1] == '+' || p[1] == '?') - : (*p == '+' || *p == '?')) - || ((syntax & RE_INTERVALS) - && ((syntax & RE_NO_BK_BRACES) - ? *p == '{' - : (p[0] == '\\' && p[1] == '{')))) - { - /* Start building a new exactn. */ - - laststart = b; - - BUF_PUSH_2 (exactn, 0); - pending_exact = b - 1; - } - - BUF_PUSH (c); - (*pending_exact)++; - break; - } /* switch (c) */ - } /* while p != pend */ - - - /* Through the pattern now. */ - - if (fixup_alt_jump) - STORE_JUMP (jump_past_alt, fixup_alt_jump, b); - - if (!COMPILE_STACK_EMPTY) - return REG_EPAREN; - - free (compile_stack.stack); - - /* We have succeeded; set the length of the buffer. */ - bufp->used = b - bufp->buffer; - -#ifdef DEBUG - if (debug) - { - DEBUG_PRINT1 ("\nCompiled pattern: \n"); - print_compiled_pattern (bufp); - } -#endif /* DEBUG */ - - return REG_NOERROR; -} /* regex_compile */ - -/* Subroutines for `regex_compile'. */ - -/* Store OP at LOC followed by two-byte integer parameter ARG. */ - -static void -store_op1 (op, loc, arg) - re_opcode_t op; - unsigned char *loc; - int arg; -{ - *loc = (unsigned char) op; - STORE_NUMBER (loc + 1, arg); -} - - -/* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */ - -static void -store_op2 (op, loc, arg1, arg2) - re_opcode_t op; - unsigned char *loc; - int arg1, arg2; -{ - *loc = (unsigned char) op; - STORE_NUMBER (loc + 1, arg1); - STORE_NUMBER (loc + 3, arg2); -} - - -/* Copy the bytes from LOC to END to open up three bytes of space at LOC - for OP followed by two-byte integer parameter ARG. */ - -static void -insert_op1 (op, loc, arg, end) - re_opcode_t op; - unsigned char *loc; - int arg; - unsigned char *end; -{ - register unsigned char *pfrom = end; - register unsigned char *pto = end + 3; - - while (pfrom != loc) - *--pto = *--pfrom; - - store_op1 (op, loc, arg); -} - - -/* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */ - -static void -insert_op2 (op, loc, arg1, arg2, end) - re_opcode_t op; - unsigned char *loc; - int arg1, arg2; - unsigned char *end; -{ - register unsigned char *pfrom = end; - register unsigned char *pto = end + 5; - - while (pfrom != loc) - *--pto = *--pfrom; - - store_op2 (op, loc, arg1, arg2); -} - - -/* P points to just after a ^ in PATTERN. Return true if that ^ comes - after an alternative or a begin-subexpression. We assume there is at - least one character before the ^. */ - -static boolean -at_begline_loc_p (pattern, p, syntax) - const char *pattern, *p; - reg_syntax_t syntax; -{ - const char *prev = p - 2; - boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; - - return - /* After a subexpression? */ - (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) - /* After an alternative? */ - || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash)); -} - - -/* The dual of at_begline_loc_p. This one is for $. We assume there is - at least one character after the $, i.e., `P < PEND'. */ - -static boolean -at_endline_loc_p (p, pend, syntax) - const char *p, *pend; - int syntax; -{ - const char *next = p; - boolean next_backslash = *next == '\\'; - const char *next_next = p + 1 < pend ? p + 1 : NULL; - - return - /* Before a subexpression? */ - (syntax & RE_NO_BK_PARENS ? *next == ')' - : next_backslash && next_next && *next_next == ')') - /* Before an alternative? */ - || (syntax & RE_NO_BK_VBAR ? *next == '|' - : next_backslash && next_next && *next_next == '|'); -} - - -/* Returns true if REGNUM is in one of COMPILE_STACK's elements and - false if it's not. */ - -static boolean -group_in_compile_stack (compile_stack, regnum) - compile_stack_type compile_stack; - regnum_t regnum; -{ - int this_element; - - for (this_element = compile_stack.avail - 1; - this_element >= 0; - this_element--) - if (compile_stack.stack[this_element].regnum == regnum) - return true; - - return false; -} - - -/* Read the ending character of a range (in a bracket expression) from the - uncompiled pattern *P_PTR (which ends at PEND). We assume the - starting character is in `P[-2]'. (`P[-1]' is the character `-'.) - Then we set the translation of all bits between the starting and - ending characters (inclusive) in the compiled pattern B. - - Return an error code. - - We use these short variable names so we can use the same macros as - `regex_compile' itself. */ - -static reg_errcode_t -compile_range (p_ptr, pend, translate, syntax, b) - const char **p_ptr, *pend; - char *translate; - reg_syntax_t syntax; - unsigned char *b; -{ - unsigned this_char; - - const char *p = *p_ptr; - int range_start, range_end; - - if (p == pend) - return REG_ERANGE; - - /* Even though the pattern is a signed `char *', we need to fetch - with unsigned char *'s; if the high bit of the pattern character - is set, the range endpoints will be negative if we fetch using a - signed char *. - - We also want to fetch the endpoints without translating them; the - appropriate translation is done in the bit-setting loop below. */ - range_start = ((unsigned char *) p)[-2]; - range_end = ((unsigned char *) p)[0]; - - /* Have to increment the pointer into the pattern string, so the - caller isn't still at the ending character. */ - (*p_ptr)++; - - /* If the start is after the end, the range is empty. */ - if (range_start > range_end) - return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR; - - /* Here we see why `this_char' has to be larger than an `unsigned - char' -- the range is inclusive, so if `range_end' == 0xff - (assuming 8-bit characters), we would otherwise go into an infinite - loop, since all characters <= 0xff. */ - for (this_char = range_start; this_char <= range_end; this_char++) - { - SET_LIST_BIT (TRANSLATE (this_char)); - } - - return REG_NOERROR; -} - -/* Failure stack declarations and macros; both re_compile_fastmap and - re_match_2 use a failure stack. These have to be macros because of - REGEX_ALLOCATE. */ - - -/* Number of failure points for which to initially allocate space - when matching. If this number is exceeded, we allocate more - space, so it is not a hard limit. */ -#ifndef INIT_FAILURE_ALLOC -#define INIT_FAILURE_ALLOC 5 -#endif - -/* Roughly the maximum number of failure points on the stack. Would be - exactly that if always used MAX_FAILURE_SPACE each time we failed. - This is a variable only so users of regex can assign to it; we never - change it ourselves. */ -int re_max_failures = 2000; - -typedef const unsigned char *fail_stack_elt_t; - -typedef struct -{ - fail_stack_elt_t *stack; - unsigned size; - unsigned avail; /* Offset of next open position. */ -} fail_stack_type; - -#define FAIL_STACK_EMPTY() (fail_stack.avail == 0) -#define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0) -#define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size) -#define FAIL_STACK_TOP() (fail_stack.stack[fail_stack.avail]) - - -/* Initialize `fail_stack'. Do `return -2' if the alloc fails. */ - -#define INIT_FAIL_STACK() \ - do { \ - fail_stack.stack = (fail_stack_elt_t *) \ - REGEX_ALLOCATE (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \ - \ - if (fail_stack.stack == NULL) \ - return -2; \ - \ - fail_stack.size = INIT_FAILURE_ALLOC; \ - fail_stack.avail = 0; \ - } while (0) - - -/* Double the size of FAIL_STACK, up to approximately `re_max_failures' items. - - Return 1 if succeeds, and 0 if either ran out of memory - allocating space for it or it was already too large. - - REGEX_REALLOCATE requires `destination' be declared. */ - -#define DOUBLE_FAIL_STACK(fail_stack) \ - ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \ - ? 0 \ - : ((fail_stack).stack = (fail_stack_elt_t *) \ - REGEX_REALLOCATE ((fail_stack).stack, \ - (fail_stack).size * sizeof (fail_stack_elt_t), \ - ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \ - \ - (fail_stack).stack == NULL \ - ? 0 \ - : ((fail_stack).size <<= 1, \ - 1))) - - -/* Push PATTERN_OP on FAIL_STACK. - - Return 1 if was able to do so and 0 if ran out of memory allocating - space to do so. */ -#define PUSH_PATTERN_OP(pattern_op, fail_stack) \ - ((FAIL_STACK_FULL () \ - && !DOUBLE_FAIL_STACK (fail_stack)) \ - ? 0 \ - : ((fail_stack).stack[(fail_stack).avail++] = pattern_op, \ - 1)) - -/* This pushes an item onto the failure stack. Must be a four-byte - value. Assumes the variable `fail_stack'. Probably should only - be called from within `PUSH_FAILURE_POINT'. */ -#define PUSH_FAILURE_ITEM(item) \ - fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) item - -/* The complement operation. Assumes `fail_stack' is nonempty. */ -#define POP_FAILURE_ITEM() fail_stack.stack[--fail_stack.avail] - -/* Used to omit pushing failure point id's when we're not debugging. */ -#ifdef DEBUG -#define DEBUG_PUSH PUSH_FAILURE_ITEM -#define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_ITEM () -#else -#define DEBUG_PUSH(item) -#define DEBUG_POP(item_addr) -#endif - - -/* Push the information about the state we will need - if we ever fail back to it. - - Requires variables fail_stack, regstart, regend, reg_info, and - num_regs be declared. DOUBLE_FAIL_STACK requires `destination' be - declared. - - Does `return FAILURE_CODE' if runs out of memory. */ - -#define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \ - do { \ - char *destination; \ - /* Must be int, so when we don't save any registers, the arithmetic \ - of 0 + -1 isn't done as unsigned. */ \ - int this_reg; \ - \ - DEBUG_STATEMENT (failure_id++); \ - DEBUG_STATEMENT (nfailure_points_pushed++); \ - DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \ - DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\ - DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\ - \ - DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \ - DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \ - \ - /* Ensure we have enough space allocated for what we will push. */ \ - while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \ - { \ - if (!DOUBLE_FAIL_STACK (fail_stack)) \ - return failure_code; \ - \ - DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \ - (fail_stack).size); \ - DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\ - } \ - \ - /* Push the info, starting with the registers. */ \ - DEBUG_PRINT1 ("\n"); \ - \ - for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \ - this_reg++) \ - { \ - DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \ - DEBUG_STATEMENT (num_regs_pushed++); \ - \ - DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \ - PUSH_FAILURE_ITEM (regstart[this_reg]); \ - \ - DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ - PUSH_FAILURE_ITEM (regend[this_reg]); \ - \ - DEBUG_PRINT2 (" info: 0x%x\n ", reg_info[this_reg]); \ - DEBUG_PRINT2 (" match_null=%d", \ - REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \ - DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \ - DEBUG_PRINT2 (" matched_something=%d", \ - MATCHED_SOMETHING (reg_info[this_reg])); \ - DEBUG_PRINT2 (" ever_matched=%d", \ - EVER_MATCHED_SOMETHING (reg_info[this_reg])); \ - DEBUG_PRINT1 ("\n"); \ - PUSH_FAILURE_ITEM (reg_info[this_reg].word); \ - } \ - \ - DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\ - PUSH_FAILURE_ITEM (lowest_active_reg); \ - \ - DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\ - PUSH_FAILURE_ITEM (highest_active_reg); \ - \ - DEBUG_PRINT2 (" Pushing pattern 0x%x: ", pattern_place); \ - DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \ - PUSH_FAILURE_ITEM (pattern_place); \ - \ - DEBUG_PRINT2 (" Pushing string 0x%x: `", string_place); \ - DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \ - size2); \ - DEBUG_PRINT1 ("'\n"); \ - PUSH_FAILURE_ITEM (string_place); \ - \ - DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \ - DEBUG_PUSH (failure_id); \ - } while (0) - -/* This is the number of items that are pushed and popped on the stack - for each register. */ -#define NUM_REG_ITEMS 3 - -/* Individual items aside from the registers. */ -#ifdef DEBUG -#define NUM_NONREG_ITEMS 5 /* Includes failure point id. */ -#else -#define NUM_NONREG_ITEMS 4 -#endif - -/* We push at most this many items on the stack. */ -#define MAX_FAILURE_ITEMS ((num_regs - 1) * NUM_REG_ITEMS + NUM_NONREG_ITEMS) - -/* We actually push this many items. */ -#define NUM_FAILURE_ITEMS \ - ((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS \ - + NUM_NONREG_ITEMS) - -/* How many items can still be added to the stack without overflowing it. */ -#define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail) - - -/* Pops what PUSH_FAIL_STACK pushes. - - We restore into the parameters, all of which should be lvalues: - STR -- the saved data position. - PAT -- the saved pattern position. - LOW_REG, HIGH_REG -- the highest and lowest active registers. - REGSTART, REGEND -- arrays of string positions. - REG_INFO -- array of information about each subexpression. - - Also assumes the variables `fail_stack' and (if debugging), `bufp', - `pend', `string1', `size1', `string2', and `size2'. */ - -#define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\ -{ \ - DEBUG_STATEMENT (fail_stack_elt_t failure_id;) \ - int this_reg; \ - const unsigned char *string_temp; \ - \ - assert (!FAIL_STACK_EMPTY ()); \ - \ - /* Remove failure points and point to how many regs pushed. */ \ - DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \ - DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \ - DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \ - \ - assert (fail_stack.avail >= NUM_NONREG_ITEMS); \ - \ - DEBUG_POP (&failure_id); \ - DEBUG_PRINT2 (" Popping failure id: %u\n", failure_id); \ - \ - /* If the saved string location is NULL, it came from an \ - on_failure_keep_string_jump opcode, and we want to throw away the \ - saved NULL, thus retaining our current position in the string. */ \ - string_temp = POP_FAILURE_ITEM (); \ - if (string_temp != NULL) \ - str = (const char *) string_temp; \ - \ - DEBUG_PRINT2 (" Popping string 0x%x: `", str); \ - DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ - DEBUG_PRINT1 ("'\n"); \ - \ - pat = (unsigned char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping pattern 0x%x: ", pat); \ - DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ - \ - /* Restore register info. */ \ - high_reg = (unsigned) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \ - \ - low_reg = (unsigned) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping low active reg: %d\n", low_reg); \ - \ - for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \ - { \ - DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \ - \ - reg_info[this_reg].word = POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" info: 0x%x\n", reg_info[this_reg]); \ - \ - regend[this_reg] = (const char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ - \ - regstart[this_reg] = (const char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \ - } \ - \ - DEBUG_STATEMENT (nfailure_points_popped++); \ -} /* POP_FAILURE_POINT */ - -/* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in - BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible - characters can start a string that matches the pattern. This fastmap - is used by re_search to skip quickly over impossible starting points. - - The caller must supply the address of a (1 << BYTEWIDTH)-byte data - area as BUFP->fastmap. - - We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in - the pattern buffer. - - Returns 0 if we succeed, -2 if an internal error. */ - -int -re_compile_fastmap (bufp) - struct re_pattern_buffer *bufp; -{ - int j, k; - fail_stack_type fail_stack; -#ifndef REGEX_MALLOC - char *destination; -#endif - /* We don't push any register information onto the failure stack. */ - unsigned num_regs = 0; - - register char *fastmap = bufp->fastmap; - unsigned char *pattern = bufp->buffer; - unsigned long size = bufp->used; - const unsigned char *p = pattern; - register unsigned char *pend = pattern + size; - - /* Assume that each path through the pattern can be null until - proven otherwise. We set this false at the bottom of switch - statement, to which we get only if a particular path doesn't - match the empty string. */ - boolean path_can_be_null = true; - - /* We aren't doing a `succeed_n' to begin with. */ - boolean succeed_n_p = false; - - assert (fastmap != NULL && p != NULL); - - INIT_FAIL_STACK (); - bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */ - bufp->fastmap_accurate = 1; /* It will be when we're done. */ - bufp->can_be_null = 0; - - while (p != pend || !FAIL_STACK_EMPTY ()) - { - if (p == pend) - { - bufp->can_be_null |= path_can_be_null; - - /* Reset for next path. */ - path_can_be_null = true; - - p = fail_stack.stack[--fail_stack.avail]; - } - - /* We should never be about to go beyond the end of the pattern. */ - assert (p < pend); - -#ifdef SWITCH_ENUM_BUG - switch ((int) ((re_opcode_t) *p++)) -#else - switch ((re_opcode_t) *p++) -#endif - { - - /* I guess the idea here is to simply not bother with a fastmap - if a backreference is used, since it's too hard to figure out - the fastmap for the corresponding group. Setting - `can_be_null' stops `re_search_2' from using the fastmap, so - that is all we do. */ - case duplicate: - bufp->can_be_null = 1; - return 0; - - - /* Following are the cases which match a character. These end - with `break'. */ - - case exactn: - fastmap[p[1]] = 1; - break; - - - case charset: - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) - fastmap[j] = 1; - break; - - - case charset_not: - /* Chars beyond end of map must be allowed. */ - for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) - fastmap[j] = 1; - - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) - fastmap[j] = 1; - break; - - - case wordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == Sword) - fastmap[j] = 1; - break; - - - case notwordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != Sword) - fastmap[j] = 1; - break; - - - case anychar: - /* `.' matches anything ... */ - for (j = 0; j < (1 << BYTEWIDTH); j++) - fastmap[j] = 1; - - /* ... except perhaps newline. */ - if (!(bufp->syntax & RE_DOT_NEWLINE)) - fastmap['\n'] = 0; - - /* Return if we have already set `can_be_null'; if we have, - then the fastmap is irrelevant. Something's wrong here. */ - else if (bufp->can_be_null) - return 0; - - /* Otherwise, have to check alternative paths. */ - break; - - -#ifdef emacs - case syntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == (enum syntaxcode) k) - fastmap[j] = 1; - break; - - - case notsyntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != (enum syntaxcode) k) - fastmap[j] = 1; - break; - - - /* All cases after this match the empty string. These end with - `continue'. */ - - - case before_dot: - case at_dot: - case after_dot: - continue; -#endif /* not emacs */ - - - case no_op: - case begline: - case endline: - case begbuf: - case endbuf: - case wordbound: - case notwordbound: - case wordbeg: - case wordend: - case push_dummy_failure: - continue; - - - case jump_n: - case pop_failure_jump: - case maybe_pop_jump: - case jump: - case jump_past_alt: - case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); - p += j; - if (j > 0) - continue; - - /* Jump backward implies we just went through the body of a - loop and matched nothing. Opcode jumped to should be - `on_failure_jump' or `succeed_n'. Just treat it like an - ordinary jump. For a * loop, it has pushed its failure - point already; if so, discard that as redundant. */ - if ((re_opcode_t) *p != on_failure_jump - && (re_opcode_t) *p != succeed_n) - continue; - - p++; - EXTRACT_NUMBER_AND_INCR (j, p); - p += j; - - /* If what's on the stack is where we are now, pop it. */ - if (!FAIL_STACK_EMPTY () - && fail_stack.stack[fail_stack.avail - 1] == p) - fail_stack.avail--; - - continue; - - - case on_failure_jump: - case on_failure_keep_string_jump: - handle_on_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); - - /* For some patterns, e.g., `(a?)?', `p+j' here points to the - end of the pattern. We don't want to push such a point, - since when we restore it above, entering the switch will - increment `p' past the end of the pattern. We don't need - to push such a point since we obviously won't find any more - fastmap entries beyond `pend'. Such a pattern can match - the null string, though. */ - if (p + j < pend) - { - if (!PUSH_PATTERN_OP (p + j, fail_stack)) - return -2; - } - else - bufp->can_be_null = 1; - - if (succeed_n_p) - { - EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */ - succeed_n_p = false; - } - - continue; - - - case succeed_n: - /* Get to the number of times to succeed. */ - p += 2; - - /* Increment p past the n for when k != 0. */ - EXTRACT_NUMBER_AND_INCR (k, p); - if (k == 0) - { - p -= 4; - succeed_n_p = true; /* Spaghetti code alert. */ - goto handle_on_failure_jump; - } - continue; - - - case set_number_at: - p += 4; - continue; - - - case start_memory: - case stop_memory: - p += 2; - continue; - - - default: - abort (); /* We have listed all the cases. */ - } /* switch *p++ */ - - /* Getting here means we have found the possible starting - characters for one path of the pattern -- and that the empty - string does not match. We need not follow this path further. - Instead, look at the next alternative (remembered on the - stack), or quit if no more. The test at the top of the loop - does these things. */ - path_can_be_null = false; - p = pend; - } /* while p */ - - /* Set `can_be_null' for the last path (also the first path, if the - pattern is empty). */ - bufp->can_be_null |= path_can_be_null; - return 0; -} /* re_compile_fastmap */ - -/* Set REGS to hold NUM_REGS registers, storing them in STARTS and - ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use - this memory for recording register information. STARTS and ENDS - must be allocated using the malloc library routine, and must each - be at least NUM_REGS * sizeof (regoff_t) bytes long. - - If NUM_REGS == 0, then subsequent matches should allocate their own - register data. - - Unless this function is called, the first search or match using - PATTERN_BUFFER will allocate its own register data, without - freeing the old data. */ - -void -re_set_registers (bufp, regs, num_regs, starts, ends) - struct re_pattern_buffer *bufp; - struct re_registers *regs; - unsigned num_regs; - regoff_t *starts, *ends; -{ - if (num_regs) - { - bufp->regs_allocated = REGS_REALLOCATE; - regs->num_regs = num_regs; - regs->start = starts; - regs->end = ends; - } - else - { - bufp->regs_allocated = REGS_UNALLOCATED; - regs->num_regs = 0; - regs->start = regs->end = (regoff_t) 0; - } -} - -/* Searching routines. */ - -/* Like re_search_2, below, but only one string is specified, and - doesn't let you say where to stop matching. */ - -int -re_search (bufp, string, size, startpos, range, regs) - struct re_pattern_buffer *bufp; - const char *string; - int size, startpos, range; - struct re_registers *regs; -{ - return re_search_2 (bufp, NULL, 0, string, size, startpos, range, - regs, size); -} - - -/* Using the compiled pattern in BUFP->buffer, first tries to match the - virtual concatenation of STRING1 and STRING2, starting first at index - STARTPOS, then at STARTPOS + 1, and so on. - - STRING1 and STRING2 have length SIZE1 and SIZE2, respectively. - - RANGE is how far to scan while trying to match. RANGE = 0 means try - only at STARTPOS; in general, the last start tried is STARTPOS + - RANGE. - - In REGS, return the indices of the virtual concatenation of STRING1 - and STRING2 that matched the entire BUFP->buffer and its contained - subexpressions. - - Do not consider matching one past the index STOP in the virtual - concatenation of STRING1 and STRING2. - - We return either the position in the strings at which the match was - found, -1 if no match, or -2 if error (such as failure - stack overflow). */ - -int -re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int startpos; - int range; - struct re_registers *regs; - int stop; -{ - int val; - register char *fastmap = bufp->fastmap; - register char *translate = bufp->translate; - int total_size = size1 + size2; - int endpos = startpos + range; - - /* Check for out-of-range STARTPOS. */ - if (startpos < 0 || startpos > total_size) - return -1; - - /* Fix up RANGE if it might eventually take us outside - the virtual concatenation of STRING1 and STRING2. */ - if (endpos < -1) - range = -1 - startpos; - else if (endpos > total_size) - range = total_size - startpos; - - /* If the search isn't to be a backwards one, don't waste time in a - search for a pattern that must be anchored. */ - if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0) - { - if (startpos > 0) - return -1; - else - range = 1; - } - - /* Update the fastmap now if not correct already. */ - if (fastmap && !bufp->fastmap_accurate) - if (re_compile_fastmap (bufp) == -2) - return -2; - - /* Loop through the string, looking for a place to start matching. */ - for (;;) - { - /* If a fastmap is supplied, skip quickly over characters that - cannot be the start of a match. If the pattern can match the - null string, however, we don't need to skip characters; we want - the first null string. */ - if (fastmap && startpos < total_size && !bufp->can_be_null) - { - if (range > 0) /* Searching forwards. */ - { - register const char *d; - register int lim = 0; - int irange = range; - - if (startpos < size1 && startpos + range >= size1) - lim = range - (size1 - startpos); - - d = (startpos >= size1 ? string2 - size1 : string1) + startpos; - - /* Written out as an if-else to avoid testing `translate' - inside the loop. */ - if (translate) - while (range > lim - && !fastmap[(unsigned char) - translate[(unsigned char) *d++]]) - range--; - else - while (range > lim && !fastmap[(unsigned char) *d++]) - range--; - - startpos += irange - range; - } - else /* Searching backwards. */ - { - register char c = (size1 == 0 || startpos >= size1 - ? string2[startpos - size1] - : string1[startpos]); - - if (!fastmap[(unsigned char) TRANSLATE (c)]) - goto advance; - } - } - - /* If can't match the null string, and that's all we have left, fail. */ - if (range >= 0 && startpos == total_size && fastmap - && !bufp->can_be_null) - return -1; - - val = re_match_2 (bufp, string1, size1, string2, size2, - startpos, regs, stop); - if (val >= 0) - return startpos; - - if (val == -2) - return -2; - - advance: - if (!range) - break; - else if (range > 0) - { - range--; - startpos++; - } - else - { - range++; - startpos--; - } - } - return -1; -} /* re_search_2 */ - -/* Declarations and macros for re_match_2. */ - -static int bcmp_translate (); -static boolean alt_match_null_string_p (), - common_op_match_null_string_p (), - group_match_null_string_p (); - -/* Structure for per-register (a.k.a. per-group) information. - This must not be longer than one word, because we push this value - onto the failure stack. Other register information, such as the - starting and ending positions (which are addresses), and the list of - inner groups (which is a bits list) are maintained in separate - variables. - - We are making a (strictly speaking) nonportable assumption here: that - the compiler will pack our bit fields into something that fits into - the type of `word', i.e., is something that fits into one item on the - failure stack. */ -typedef union -{ - fail_stack_elt_t word; - struct - { - /* This field is one if this group can match the empty string, - zero if not. If not yet determined, `MATCH_NULL_UNSET_VALUE'. */ -#define MATCH_NULL_UNSET_VALUE 3 - unsigned match_null_string_p : 2; - unsigned is_active : 1; - unsigned matched_something : 1; - unsigned ever_matched_something : 1; - } bits; -} register_info_type; - -#define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p) -#define IS_ACTIVE(R) ((R).bits.is_active) -#define MATCHED_SOMETHING(R) ((R).bits.matched_something) -#define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something) - - -/* Call this when have matched a real character; it sets `matched' flags - for the subexpressions which we are currently inside. Also records - that those subexprs have matched. */ -#define SET_REGS_MATCHED() \ - do \ - { \ - unsigned r; \ - for (r = lowest_active_reg; r <= highest_active_reg; r++) \ - { \ - MATCHED_SOMETHING (reg_info[r]) \ - = EVER_MATCHED_SOMETHING (reg_info[r]) \ - = 1; \ - } \ - } \ - while (0) - - -/* This converts PTR, a pointer into one of the search strings `string1' - and `string2' into an offset from the beginning of that string. */ -#define POINTER_TO_OFFSET(ptr) \ - (FIRST_STRING_P (ptr) ? (ptr) - string1 : (ptr) - string2 + size1) - -/* Registers are set to a sentinel when they haven't yet matched. */ -#define REG_UNSET_VALUE ((char *) -1) -#define REG_UNSET(e) ((e) == REG_UNSET_VALUE) - - -/* Macros for dealing with the split strings in re_match_2. */ - -#define MATCHING_IN_FIRST_STRING (dend == end_match_1) - -/* Call before fetching a character with *d. This switches over to - string2 if necessary. */ -#define PREFETCH() \ - while (d == dend) \ - { \ - /* End of string2 => fail. */ \ - if (dend == end_match_2) \ - goto fail; \ - /* End of string1 => advance to string2. */ \ - d = string2; \ - dend = end_match_2; \ - } - - -/* Test if at very beginning or at very end of the virtual concatenation - of `string1' and `string2'. If only one string, it's `string2'. */ -#define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2) -#define AT_STRINGS_END(d) ((d) == end2) - - -/* Test if D points to a character which is word-constituent. We have - two special cases to check for: if past the end of string1, look at - the first character in string2; and if before the beginning of - string2, look at the last character in string1. */ -#define WORDCHAR_P(d) \ - (SYNTAX ((d) == end1 ? *string2 \ - : (d) == string2 - 1 ? *(end1 - 1) : *(d)) \ - == Sword) - -/* Test if the character before D and the one at D differ with respect - to being word-constituent. */ -#define AT_WORD_BOUNDARY(d) \ - (AT_STRINGS_BEG (d) || AT_STRINGS_END (d) \ - || WORDCHAR_P (d - 1) != WORDCHAR_P (d)) - - -/* Free everything we malloc. */ -#ifdef REGEX_MALLOC -#define FREE_VAR(var) if (var) free (var); var = NULL -#define FREE_VARIABLES() \ - do { \ - FREE_VAR (fail_stack.stack); \ - FREE_VAR (regstart); \ - FREE_VAR (regend); \ - FREE_VAR (old_regstart); \ - FREE_VAR (old_regend); \ - FREE_VAR (best_regstart); \ - FREE_VAR (best_regend); \ - FREE_VAR (reg_info); \ - FREE_VAR (reg_dummy); \ - FREE_VAR (reg_info_dummy); \ - } while (0) -#else /* not REGEX_MALLOC */ -/* Some MIPS systems (at least) want this to free alloca'd storage. */ -#define FREE_VARIABLES() alloca (0) -#endif /* not REGEX_MALLOC */ - - -/* These values must meet several constraints. They must not be valid - register values; since we have a limit of 255 registers (because - we use only one byte in the pattern for the register number), we can - use numbers larger than 255. They must differ by 1, because of - NUM_FAILURE_ITEMS above. And the value for the lowest register must - be larger than the value for the highest register, so we do not try - to actually save any registers when none are active. */ -#define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH) -#define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1) - -/* Matching routines. */ - -#ifndef emacs /* Emacs never uses this. */ -/* re_match is like re_match_2 except it takes only a single string. */ - -int -re_match (bufp, string, size, pos, regs) - struct re_pattern_buffer *bufp; - const char *string; - int size, pos; - struct re_registers *regs; - { - return re_match_2 (bufp, NULL, 0, string, size, pos, regs, size); -} -#endif /* not emacs */ - - -/* re_match_2 matches the compiled pattern in BUFP against the - the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 - and SIZE2, respectively). We start matching at POS, and stop - matching at STOP. - - If REGS is non-null and the `no_sub' field of BUFP is nonzero, we - store offsets for the substring each group matched in REGS. See the - documentation for exactly how many groups we fill. - - We return -1 if no match, -2 if an internal error (such as the - failure stack overflowing). Otherwise, we return the length of the - matched substring. */ - -int -re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int pos; - struct re_registers *regs; - int stop; -{ - /* General temporaries. */ - int mcnt; - unsigned char *p1; - - /* Just past the end of the corresponding string. */ - const char *end1, *end2; - - /* Pointers into string1 and string2, just past the last characters in - each to consider matching. */ - const char *end_match_1, *end_match_2; - - /* Where we are in the data, and the end of the current string. */ - const char *d, *dend; - - /* Where we are in the pattern, and the end of the pattern. */ - unsigned char *p = bufp->buffer; - register unsigned char *pend = p + bufp->used; - - /* We use this to map every character in the string. */ - char *translate = bufp->translate; - - /* Failure point stack. Each place that can handle a failure further - down the line pushes a failure point on this stack. It consists of - restart, regend, and reg_info for all registers corresponding to - the subexpressions we're currently inside, plus the number of such - registers, and, finally, two char *'s. The first char * is where - to resume scanning the pattern; the second one is where to resume - scanning the strings. If the latter is zero, the failure point is - a ``dummy''; if a failure happens and the failure point is a dummy, - it gets discarded and the next next one is tried. */ - fail_stack_type fail_stack; -#ifdef DEBUG - static unsigned failure_id = 0; - unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; -#endif - - /* We fill all the registers internally, independent of what we - return, for use in backreferences. The number here includes - an element for register zero. */ - unsigned num_regs = bufp->re_nsub + 1; - - /* The currently active registers. */ - unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG; - unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG; - - /* Information on the contents of registers. These are pointers into - the input strings; they record just what was matched (on this - attempt) by a subexpression part of the pattern, that is, the - regnum-th regstart pointer points to where in the pattern we began - matching and the regnum-th regend points to right after where we - stopped matching the regnum-th subexpression. (The zeroth register - keeps track of what the whole pattern matches.) */ - const char **regstart, **regend; - - /* If a group that's operated upon by a repetition operator fails to - match anything, then the register for its start will need to be - restored because it will have been set to wherever in the string we - are when we last see its open-group operator. Similarly for a - register's end. */ - const char **old_regstart, **old_regend; - - /* The is_active field of reg_info helps us keep track of which (possibly - nested) subexpressions we are currently in. The matched_something - field of reg_info[reg_num] helps us tell whether or not we have - matched any of the pattern so far this time through the reg_num-th - subexpression. These two fields get reset each time through any - loop their register is in. */ - register_info_type *reg_info; - - /* The following record the register info as found in the above - variables when we find a match better than any we've seen before. - This happens as we backtrack through the failure points, which in - turn happens only if we have not yet matched the entire string. */ - unsigned best_regs_set = false; - const char **best_regstart, **best_regend; - - /* Logically, this is `best_regend[0]'. But we don't want to have to - allocate space for that if we're not allocating space for anything - else (see below). Also, we never need info about register 0 for - any of the other register vectors, and it seems rather a kludge to - treat `best_regend' differently than the rest. So we keep track of - the end of the best match so far in a separate variable. We - initialize this to NULL so that when we backtrack the first time - and need to test it, it's not garbage. */ - const char *match_end = NULL; - - /* Used when we pop values we don't care about. */ - const char **reg_dummy; - register_info_type *reg_info_dummy; - -#ifdef DEBUG - /* Counts the total number of registers pushed. */ - unsigned num_regs_pushed = 0; -#endif - - DEBUG_PRINT1 ("\n\nEntering re_match_2.\n"); - - INIT_FAIL_STACK (); - - /* Do not bother to initialize all the register variables if there are - no groups in the pattern, as it takes a fair amount of time. If - there are groups, we include space for register 0 (the whole - pattern), even though we never use it, since it simplifies the - array indexing. We should fix this. */ - if (bufp->re_nsub) - { - regstart = REGEX_TALLOC (num_regs, const char *); - regend = REGEX_TALLOC (num_regs, const char *); - old_regstart = REGEX_TALLOC (num_regs, const char *); - old_regend = REGEX_TALLOC (num_regs, const char *); - best_regstart = REGEX_TALLOC (num_regs, const char *); - best_regend = REGEX_TALLOC (num_regs, const char *); - reg_info = REGEX_TALLOC (num_regs, register_info_type); - reg_dummy = REGEX_TALLOC (num_regs, const char *); - reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type); - - if (!(regstart && regend && old_regstart && old_regend && reg_info - && best_regstart && best_regend && reg_dummy && reg_info_dummy)) - { - FREE_VARIABLES (); - return -2; - } - } -#ifdef REGEX_MALLOC - else - { - /* We must initialize all our variables to NULL, so that - `FREE_VARIABLES' doesn't try to free them. */ - regstart = regend = old_regstart = old_regend = best_regstart - = best_regend = reg_dummy = NULL; - reg_info = reg_info_dummy = (register_info_type *) NULL; - } -#endif /* REGEX_MALLOC */ - - /* The starting position is bogus. */ - if (pos < 0 || pos > size1 + size2) - { - FREE_VARIABLES (); - return -1; - } - - /* Initialize subexpression text positions to -1 to mark ones that no - start_memory/stop_memory has been seen for. Also initialize the - register information struct. */ - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - regstart[mcnt] = regend[mcnt] - = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE; - - REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE; - IS_ACTIVE (reg_info[mcnt]) = 0; - MATCHED_SOMETHING (reg_info[mcnt]) = 0; - EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0; - } - - /* We move `string1' into `string2' if the latter's empty -- but not if - `string1' is null. */ - if (size2 == 0 && string1 != NULL) - { - string2 = string1; - size2 = size1; - string1 = 0; - size1 = 0; - } - end1 = string1 + size1; - end2 = string2 + size2; - - /* Compute where to stop matching, within the two strings. */ - if (stop <= size1) - { - end_match_1 = string1 + stop; - end_match_2 = string2; - } - else - { - end_match_1 = end1; - end_match_2 = string2 + stop - size1; - } - - /* `p' scans through the pattern as `d' scans through the data. - `dend' is the end of the input string that `d' points within. `d' - is advanced into the following input string whenever necessary, but - this happens before fetching; therefore, at the beginning of the - loop, `d' can be pointing at the end of a string, but it cannot - equal `string2'. */ - if (size1 > 0 && pos <= size1) - { - d = string1 + pos; - dend = end_match_1; - } - else - { - d = string2 + pos - size1; - dend = end_match_2; - } - - DEBUG_PRINT1 ("The compiled pattern is: "); - DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); - DEBUG_PRINT1 ("The string to match is: `"); - DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); - DEBUG_PRINT1 ("'\n"); - - /* This loops over pattern commands. It exits by returning from the - function if the match is complete, or it drops through if the match - fails at this starting point in the input data. */ - for (;;) - { - DEBUG_PRINT2 ("\n0x%x: ", p); - - if (p == pend) - { /* End of pattern means we might have succeeded. */ - DEBUG_PRINT1 ("end of pattern ... "); - - /* If we haven't matched the entire string, and we want the - longest match, try backtracking. */ - if (d != end_match_2) - { - DEBUG_PRINT1 ("backtracking.\n"); - - if (!FAIL_STACK_EMPTY ()) - { /* More failure points to try. */ - boolean same_str_p = (FIRST_STRING_P (match_end) - == MATCHING_IN_FIRST_STRING); - - /* If exceeds best match so far, save it. */ - if (!best_regs_set - || (same_str_p && d > match_end) - || (!same_str_p && !MATCHING_IN_FIRST_STRING)) - { - best_regs_set = true; - match_end = d; - - DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); - - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - best_regstart[mcnt] = regstart[mcnt]; - best_regend[mcnt] = regend[mcnt]; - } - } - goto fail; - } - - /* If no failure points, don't restore garbage. */ - else if (best_regs_set) - { - restore_best_regs: - /* Restore best match. It may happen that `dend == - end_match_1' while the restored d is in string2. - For example, the pattern `x.*y.*z' against the - strings `x-' and `y-z-', if the two strings are - not consecutive in memory. */ - DEBUG_PRINT1 ("Restoring best registers.\n"); - - d = match_end; - dend = ((d >= string1 && d <= end1) - ? end_match_1 : end_match_2); - - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - regstart[mcnt] = best_regstart[mcnt]; - regend[mcnt] = best_regend[mcnt]; - } - } - } /* d != end_match_2 */ - - DEBUG_PRINT1 ("Accepting match.\n"); - - /* If caller wants register contents data back, do it. */ - if (regs && !bufp->no_sub) - { - /* Have the register data arrays been allocated? */ - if (bufp->regs_allocated == REGS_UNALLOCATED) - { /* No. So allocate them with malloc. We need one - extra element beyond `num_regs' for the `-1' marker - GNU code uses. */ - regs->num_regs = MAX (RE_NREGS, num_regs + 1); - regs->start = TALLOC (regs->num_regs, regoff_t); - regs->end = TALLOC (regs->num_regs, regoff_t); - if (regs->start == NULL || regs->end == NULL) - return -2; - bufp->regs_allocated = REGS_REALLOCATE; - } - else if (bufp->regs_allocated == REGS_REALLOCATE) - { /* Yes. If we need more elements than were already - allocated, reallocate them. If we need fewer, just - leave it alone. */ - if (regs->num_regs < num_regs + 1) - { - regs->num_regs = num_regs + 1; - RETALLOC (regs->start, regs->num_regs, regoff_t); - RETALLOC (regs->end, regs->num_regs, regoff_t); - if (regs->start == NULL || regs->end == NULL) - return -2; - } - } - else - { - /* These braces fend off a "empty body in an else-statement" - warning under GCC when assert expands to nothing. */ - assert (bufp->regs_allocated == REGS_FIXED); - } - - /* Convert the pointer data in `regstart' and `regend' to - indices. Register zero has to be set differently, - since we haven't kept track of any info for it. */ - if (regs->num_regs > 0) - { - regs->start[0] = pos; - regs->end[0] = (MATCHING_IN_FIRST_STRING ? d - string1 - : d - string2 + size1); - } - - /* Go through the first `min (num_regs, regs->num_regs)' - registers, since that is all we initialized. */ - for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++) - { - if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt])) - regs->start[mcnt] = regs->end[mcnt] = -1; - else - { - regs->start[mcnt] = POINTER_TO_OFFSET (regstart[mcnt]); - regs->end[mcnt] = POINTER_TO_OFFSET (regend[mcnt]); - } - } - - /* If the regs structure we return has more elements than - were in the pattern, set the extra elements to -1. If - we (re)allocated the registers, this is the case, - because we always allocate enough to have at least one - -1 at the end. */ - for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++) - regs->start[mcnt] = regs->end[mcnt] = -1; - } /* regs && !bufp->no_sub */ - - FREE_VARIABLES (); - DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", - nfailure_points_pushed, nfailure_points_popped, - nfailure_points_pushed - nfailure_points_popped); - DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); - - mcnt = d - pos - (MATCHING_IN_FIRST_STRING - ? string1 - : string2 - size1); - - DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); - - return mcnt; - } - - /* Otherwise match next pattern command. */ -#ifdef SWITCH_ENUM_BUG - switch ((int) ((re_opcode_t) *p++)) -#else - switch ((re_opcode_t) *p++) -#endif - { - /* Ignore these. Used to ignore the n of succeed_n's which - currently have n == 0. */ - case no_op: - DEBUG_PRINT1 ("EXECUTING no_op.\n"); - break; - - - /* Match the next n pattern characters exactly. The following - byte in the pattern defines n, and the n bytes after that - are the characters to match. */ - case exactn: - mcnt = *p++; - DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt); - - /* This is written out as an if-else so we don't waste time - testing `translate' inside the loop. */ - if (translate) - { - do - { - PREFETCH (); - if (translate[(unsigned char) *d++] != (char) *p++) - goto fail; - } - while (--mcnt); - } - else - { - do - { - PREFETCH (); - if (*d++ != (char) *p++) goto fail; - } - while (--mcnt); - } - SET_REGS_MATCHED (); - break; - - - /* Match any character except possibly a newline or a null. */ - case anychar: - DEBUG_PRINT1 ("EXECUTING anychar.\n"); - - PREFETCH (); - - if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n') - || (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000')) - goto fail; - - SET_REGS_MATCHED (); - DEBUG_PRINT2 (" Matched `%d'.\n", *d); - d++; - break; - - - case charset: - case charset_not: - { - register unsigned char c; - boolean not = (re_opcode_t) *(p - 1) == charset_not; - - DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); - - PREFETCH (); - c = TRANSLATE (*d); /* The character to match. */ - - /* Cast to `unsigned' instead of `unsigned char' in case the - bit list is a full 32 bytes long. */ - if (c < (unsigned) (*p * BYTEWIDTH) - && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - p += 1 + *p; - - if (!not) goto fail; - - SET_REGS_MATCHED (); - d++; - break; - } - - - /* The beginning of a group is represented by start_memory. - The arguments are the register number in the next byte, and the - number of groups inner to this one in the next. The text - matched within the group is recorded (in the internal - registers data structure) under the register number. */ - case start_memory: - DEBUG_PRINT3 ("EXECUTING start_memory %d (%d):\n", *p, p[1]); - - /* Find out if this group can match the empty string. */ - p1 = p; /* To send to group_match_null_string_p. */ - - if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE) - REG_MATCH_NULL_STRING_P (reg_info[*p]) - = group_match_null_string_p (&p1, pend, reg_info); - - /* Save the position in the string where we were the last time - we were at this open-group operator in case the group is - operated upon by a repetition operator, e.g., with `(a*)*b' - against `ab'; then we want to ignore where we are now in - the string in case this attempt to match fails. */ - old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) - ? REG_UNSET (regstart[*p]) ? d : regstart[*p] - : regstart[*p]; - DEBUG_PRINT2 (" old_regstart: %d\n", - POINTER_TO_OFFSET (old_regstart[*p])); - - regstart[*p] = d; - DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p])); - - IS_ACTIVE (reg_info[*p]) = 1; - MATCHED_SOMETHING (reg_info[*p]) = 0; - - /* This is the new highest active register. */ - highest_active_reg = *p; - - /* If nothing was active before, this is the new lowest active - register. */ - if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) - lowest_active_reg = *p; - - /* Move past the register number and inner group count. */ - p += 2; - break; - - - /* The stop_memory opcode represents the end of a group. Its - arguments are the same as start_memory's: the register - number, and the number of inner groups. */ - case stop_memory: - DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]); - - /* We need to save the string position the last time we were at - this close-group operator in case the group is operated - upon by a repetition operator, e.g., with `((a*)*(b*)*)*' - against `aba'; then we want to ignore where we are now in - the string in case this attempt to match fails. */ - old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) - ? REG_UNSET (regend[*p]) ? d : regend[*p] - : regend[*p]; - DEBUG_PRINT2 (" old_regend: %d\n", - POINTER_TO_OFFSET (old_regend[*p])); - - regend[*p] = d; - DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p])); - - /* This register isn't active anymore. */ - IS_ACTIVE (reg_info[*p]) = 0; - - /* If this was the only register active, nothing is active - anymore. */ - if (lowest_active_reg == highest_active_reg) - { - lowest_active_reg = NO_LOWEST_ACTIVE_REG; - highest_active_reg = NO_HIGHEST_ACTIVE_REG; - } - else - { /* We must scan for the new highest active register, since - it isn't necessarily one less than now: consider - (a(b)c(d(e)f)g). When group 3 ends, after the f), the - new highest active register is 1. */ - unsigned char r = *p - 1; - while (r > 0 && !IS_ACTIVE (reg_info[r])) - r--; - - /* If we end up at register zero, that means that we saved - the registers as the result of an `on_failure_jump', not - a `start_memory', and we jumped to past the innermost - `stop_memory'. For example, in ((.)*) we save - registers 1 and 2 as a result of the *, but when we pop - back to the second ), we are at the stop_memory 1. - Thus, nothing is active. */ - if (r == 0) - { - lowest_active_reg = NO_LOWEST_ACTIVE_REG; - highest_active_reg = NO_HIGHEST_ACTIVE_REG; - } - else - highest_active_reg = r; - } - - /* If just failed to match something this time around with a - group that's operated on by a repetition operator, try to - force exit from the ``loop'', and restore the register - information for this group that we had before trying this - last match. */ - if ((!MATCHED_SOMETHING (reg_info[*p]) - || (re_opcode_t) p[-3] == start_memory) - && (p + 2) < pend) - { - boolean is_a_jump_n = false; - - p1 = p + 2; - mcnt = 0; - switch ((re_opcode_t) *p1++) - { - case jump_n: - is_a_jump_n = true; - case pop_failure_jump: - case maybe_pop_jump: - case jump: - case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if (is_a_jump_n) - p1 += 2; - break; - - default: - /* do nothing */ ; - } - p1 += mcnt; - - /* If the next operation is a jump backwards in the pattern - to an on_failure_jump right before the start_memory - corresponding to this stop_memory, exit from the loop - by forcing a failure after pushing on the stack the - on_failure_jump's jump in the pattern, and d. */ - if (mcnt < 0 && (re_opcode_t) *p1 == on_failure_jump - && (re_opcode_t) p1[3] == start_memory && p1[4] == *p) - { - /* If this group ever matched anything, then restore - what its registers were before trying this last - failed match, e.g., with `(a*)*b' against `ab' for - regstart[1], and, e.g., with `((a*)*(b*)*)*' - against `aba' for regend[3]. - - Also restore the registers for inner groups for, - e.g., `((a*)(b*))*' against `aba' (register 3 would - otherwise get trashed). */ - - if (EVER_MATCHED_SOMETHING (reg_info[*p])) - { - unsigned r; - - EVER_MATCHED_SOMETHING (reg_info[*p]) = 0; - - /* Restore this and inner groups' (if any) registers. */ - for (r = *p; r < *p + *(p + 1); r++) - { - regstart[r] = old_regstart[r]; - - /* xx why this test? */ - if ((int) old_regend[r] >= (int) regstart[r]) - regend[r] = old_regend[r]; - } - } - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - PUSH_FAILURE_POINT (p1 + mcnt, d, -2); - - goto fail; - } - } - - /* Move past the register number and the inner group count. */ - p += 2; - break; - - - /* \ has been turned into a `duplicate' command which is - followed by the numeric value of as the register number. */ - case duplicate: - { - register const char *d2, *dend2; - int regno = *p++; /* Get which register to match against. */ - DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); - - /* Can't back reference a group which we've never matched. */ - if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) - goto fail; - - /* Where in input to try to start matching. */ - d2 = regstart[regno]; - - /* Where to stop matching; if both the place to start and - the place to stop matching are in the same string, then - set to the place to stop, otherwise, for now have to use - the end of the first string. */ - - dend2 = ((FIRST_STRING_P (regstart[regno]) - == FIRST_STRING_P (regend[regno])) - ? regend[regno] : end_match_1); - for (;;) - { - /* If necessary, advance to next segment in register - contents. */ - while (d2 == dend2) - { - if (dend2 == end_match_2) break; - if (dend2 == regend[regno]) break; - - /* End of string1 => advance to string2. */ - d2 = string2; - dend2 = regend[regno]; - } - /* At end of register contents => success */ - if (d2 == dend2) break; - - /* If necessary, advance to next segment in data. */ - PREFETCH (); - - /* How many characters left in this segment to match. */ - mcnt = dend - d; - - /* Want how many consecutive characters we can match in - one shot, so, if necessary, adjust the count. */ - if (mcnt > dend2 - d2) - mcnt = dend2 - d2; - - /* Compare that many; failure if mismatch, else move - past them. */ - if (translate - ? bcmp_translate (d, d2, mcnt, translate) - : bcmp (d, d2, mcnt)) - goto fail; - d += mcnt, d2 += mcnt; - } - } - break; - - - /* begline matches the empty string at the beginning of the string - (unless `not_bol' is set in `bufp'), and, if - `newline_anchor' is set, after newlines. */ - case begline: - DEBUG_PRINT1 ("EXECUTING begline.\n"); - - if (AT_STRINGS_BEG (d)) - { - if (!bufp->not_bol) break; - } - else if (d[-1] == '\n' && bufp->newline_anchor) - { - break; - } - /* In all other cases, we fail. */ - goto fail; - - - /* endline is the dual of begline. */ - case endline: - DEBUG_PRINT1 ("EXECUTING endline.\n"); - - if (AT_STRINGS_END (d)) - { - if (!bufp->not_eol) break; - } - - /* We have to ``prefetch'' the next character. */ - else if ((d == end1 ? *string2 : *d) == '\n' - && bufp->newline_anchor) - { - break; - } - goto fail; - - - /* Match at the very beginning of the data. */ - case begbuf: - DEBUG_PRINT1 ("EXECUTING begbuf.\n"); - if (AT_STRINGS_BEG (d)) - break; - goto fail; - - - /* Match at the very end of the data. */ - case endbuf: - DEBUG_PRINT1 ("EXECUTING endbuf.\n"); - if (AT_STRINGS_END (d)) - break; - goto fail; - - - /* on_failure_keep_string_jump is used to optimize `.*\n'. It - pushes NULL as the value for the string on the stack. Then - `pop_failure_point' will keep the current value for the - string, instead of restoring it. To see why, consider - matching `foo\nbar' against `.*\n'. The .* matches the foo; - then the . fails against the \n. But the next thing we want - to do is match the \n against the \n; if we restored the - string value, we would be back at the foo. - - Because this is used only in specific cases, we don't need to - check all the things that `on_failure_jump' does, to make - sure the right things get saved on the stack. Hence we don't - share its code. The only reason to push anything on the - stack at all is that otherwise we would have to change - `anychar's code to do something besides goto fail in this - case; that seems worse than this. */ - case on_failure_keep_string_jump: - DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" %d (to 0x%x):\n", mcnt, p + mcnt); - - PUSH_FAILURE_POINT (p + mcnt, NULL, -2); - break; - - - /* Uses of on_failure_jump: - - Each alternative starts with an on_failure_jump that points - to the beginning of the next alternative. Each alternative - except the last ends with a jump that in effect jumps past - the rest of the alternatives. (They really jump to the - ending jump of the following alternative, because tensioning - these jumps is a hassle.) - - Repeats start with an on_failure_jump that points past both - the repetition text and either the following jump or - pop_failure_jump back to this on_failure_jump. */ - case on_failure_jump: - on_failure: - DEBUG_PRINT1 ("EXECUTING on_failure_jump"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" %d (to 0x%x)", mcnt, p + mcnt); - - /* If this on_failure_jump comes right before a group (i.e., - the original * applied to a group), save the information - for that group and all inner ones, so that if we fail back - to this point, the group's information will be correct. - For example, in \(a*\)*\1, we need the preceding group, - and in \(\(a*\)b*\)\2, we need the inner group. */ - - /* We can't use `p' to check ahead because we push - a failure point to `p + mcnt' after we do this. */ - p1 = p; - - /* We need to skip no_op's before we look for the - start_memory in case this on_failure_jump is happening as - the result of a completed succeed_n, as in \(a\)\{1,3\}b\1 - against aba. */ - while (p1 < pend && (re_opcode_t) *p1 == no_op) - p1++; - - if (p1 < pend && (re_opcode_t) *p1 == start_memory) - { - /* We have a new highest active register now. This will - get reset at the start_memory we are about to get to, - but we will have saved all the registers relevant to - this repetition op, as described above. */ - highest_active_reg = *(p1 + 1) + *(p1 + 2); - if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) - lowest_active_reg = *(p1 + 1); - } - - DEBUG_PRINT1 (":\n"); - PUSH_FAILURE_POINT (p + mcnt, d, -2); - break; - - - /* A smart repeat ends with `maybe_pop_jump'. - We change it to either `pop_failure_jump' or `jump'. */ - case maybe_pop_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT2 ("EXECUTING maybe_pop_jump %d.\n", mcnt); - { - register unsigned char *p2 = p; - - /* Compare the beginning of the repeat with what in the - pattern follows its end. If we can establish that there - is nothing that they would both match, i.e., that we - would have to backtrack because of (as in, e.g., `a*a') - then we can change to pop_failure_jump, because we'll - never have to backtrack. - - This is not true in the case of alternatives: in - `(a|ab)*' we do need to backtrack to the `ab' alternative - (e.g., if the string was `ab'). But instead of trying to - detect that here, the alternative has put on a dummy - failure point which is what we will end up popping. */ - - /* Skip over open/close-group commands. */ - while (p2 + 2 < pend - && ((re_opcode_t) *p2 == stop_memory - || (re_opcode_t) *p2 == start_memory)) - p2 += 3; /* Skip over args, too. */ - - /* If we're at the end of the pattern, we can change. */ - if (p2 == pend) - { - /* Consider what happens when matching ":\(.*\)" - against ":/". I don't really understand this code - yet. */ - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 - (" End of pattern: change to `pop_failure_jump'.\n"); - } - - else if ((re_opcode_t) *p2 == exactn - || (bufp->newline_anchor && (re_opcode_t) *p2 == endline)) - { - register unsigned char c - = *p2 == (unsigned char) endline ? '\n' : p2[2]; - p1 = p + mcnt; - - /* p1[0] ... p1[2] are the `on_failure_jump' corresponding - to the `maybe_finalize_jump' of this case. Examine what - follows. */ - if ((re_opcode_t) p1[3] == exactn && p1[5] != c) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", - c, p1[5]); - } - - else if ((re_opcode_t) p1[3] == charset - || (re_opcode_t) p1[3] == charset_not) - { - int not = (re_opcode_t) p1[3] == charset_not; - - if (c < (unsigned char) (p1[4] * BYTEWIDTH) - && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - /* `not' is equal to 1 if c would match, which means - that we can't change to pop_failure_jump. */ - if (!not) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 (" No match => pop_failure_jump.\n"); - } - } - } - } - p -= 2; /* Point at relative address again. */ - if ((re_opcode_t) p[-1] != pop_failure_jump) - { - p[-1] = (unsigned char) jump; - DEBUG_PRINT1 (" Match => jump.\n"); - goto unconditional_jump; - } - /* Note fall through. */ - - - /* The end of a simple repeat has a pop_failure_jump back to - its matching on_failure_jump, where the latter will push a - failure point. The pop_failure_jump takes off failure - points put on by this pop_failure_jump's matching - on_failure_jump; we got through the pattern to here from the - matching on_failure_jump, so didn't fail. */ - case pop_failure_jump: - { - /* We need to pass separate storage for the lowest and - highest registers, even though we don't care about the - actual values. Otherwise, we will restore only one - register from the stack, since lowest will == highest in - `pop_failure_point'. */ - unsigned dummy_low_reg, dummy_high_reg; - unsigned char *pdummy; - const char *sdummy; - - DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); - POP_FAILURE_POINT (sdummy, pdummy, - dummy_low_reg, dummy_high_reg, - reg_dummy, reg_dummy, reg_info_dummy); - } - /* Note fall through. */ - - - /* Unconditionally jump (without popping any failure points). */ - case jump: - unconditional_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */ - DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt); - p += mcnt; /* Do the jump. */ - DEBUG_PRINT2 ("(to 0x%x).\n", p); - break; - - - /* We need this opcode so we can detect where alternatives end - in `group_match_null_string_p' et al. */ - case jump_past_alt: - DEBUG_PRINT1 ("EXECUTING jump_past_alt.\n"); - goto unconditional_jump; - - - /* Normally, the on_failure_jump pushes a failure point, which - then gets popped at pop_failure_jump. We will end up at - pop_failure_jump, also, and with a pattern of, say, `a+', we - are skipping over the on_failure_jump, so we have to push - something meaningless for pop_failure_jump to pop. */ - case dummy_failure_jump: - DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n"); - /* It doesn't matter what we push for the string here. What - the code at `fail' tests is the value for the pattern. */ - PUSH_FAILURE_POINT (0, 0, -2); - goto unconditional_jump; - - - /* At the end of an alternative, we need to push a dummy failure - point in case we are followed by a `pop_failure_jump', because - we don't want the failure point for the alternative to be - popped. For example, matching `(a|ab)*' against `aab' - requires that we match the `ab' alternative. */ - case push_dummy_failure: - DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n"); - /* See comments just above at `dummy_failure_jump' about the - two zeroes. */ - PUSH_FAILURE_POINT (0, 0, -2); - break; - - /* Have to succeed matching what follows at least n times. - After that, handle like `on_failure_jump'. */ - case succeed_n: - EXTRACT_NUMBER (mcnt, p + 2); - DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt); - - assert (mcnt >= 0); - /* Originally, this is how many times we HAVE to succeed. */ - if (mcnt > 0) - { - mcnt--; - p += 2; - STORE_NUMBER_AND_INCR (p, mcnt); - DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p, mcnt); - } - else if (mcnt == 0) - { - DEBUG_PRINT2 (" Setting two bytes from 0x%x to no_op.\n", p+2); - p[2] = (unsigned char) no_op; - p[3] = (unsigned char) no_op; - goto on_failure; - } - break; - - case jump_n: - EXTRACT_NUMBER (mcnt, p + 2); - DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt); - - /* Originally, this is how many times we CAN jump. */ - if (mcnt) - { - mcnt--; - STORE_NUMBER (p + 2, mcnt); - goto unconditional_jump; - } - /* If don't have to jump any more, skip over the rest of command. */ - else - p += 4; - break; - - case set_number_at: - { - DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - p1 = p + mcnt; - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p1, mcnt); - STORE_NUMBER (p1, mcnt); - break; - } - - case wordbound: - DEBUG_PRINT1 ("EXECUTING wordbound.\n"); - if (AT_WORD_BOUNDARY (d)) - break; - goto fail; - - case notwordbound: - DEBUG_PRINT1 ("EXECUTING notwordbound.\n"); - if (AT_WORD_BOUNDARY (d)) - goto fail; - break; - - case wordbeg: - DEBUG_PRINT1 ("EXECUTING wordbeg.\n"); - if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1))) - break; - goto fail; - - case wordend: - DEBUG_PRINT1 ("EXECUTING wordend.\n"); - if (!AT_STRINGS_BEG (d) && WORDCHAR_P (d - 1) - && (!WORDCHAR_P (d) || AT_STRINGS_END (d))) - break; - goto fail; - -#ifdef emacs -#ifdef emacs19 - case before_dot: - DEBUG_PRINT1 ("EXECUTING before_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) >= point) - goto fail; - break; - - case at_dot: - DEBUG_PRINT1 ("EXECUTING at_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) != point) - goto fail; - break; - - case after_dot: - DEBUG_PRINT1 ("EXECUTING after_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) <= point) - goto fail; - break; -#else /* not emacs19 */ - case at_dot: - DEBUG_PRINT1 ("EXECUTING at_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) + 1 != point) - goto fail; - break; -#endif /* not emacs19 */ - - case syntaxspec: - DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt); - mcnt = *p++; - goto matchsyntax; - - case wordchar: - DEBUG_PRINT1 ("EXECUTING Emacs wordchar.\n"); - mcnt = (int) Sword; - matchsyntax: - PREFETCH (); - if (SYNTAX (*d++) != (enum syntaxcode) mcnt) - goto fail; - SET_REGS_MATCHED (); - break; - - case notsyntaxspec: - DEBUG_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt); - mcnt = *p++; - goto matchnotsyntax; - - case notwordchar: - DEBUG_PRINT1 ("EXECUTING Emacs notwordchar.\n"); - mcnt = (int) Sword; - matchnotsyntax: - PREFETCH (); - if (SYNTAX (*d++) == (enum syntaxcode) mcnt) - goto fail; - SET_REGS_MATCHED (); - break; - -#else /* not emacs */ - case wordchar: - DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n"); - PREFETCH (); - if (!WORDCHAR_P (d)) - goto fail; - SET_REGS_MATCHED (); - d++; - break; - - case notwordchar: - DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n"); - PREFETCH (); - if (WORDCHAR_P (d)) - goto fail; - SET_REGS_MATCHED (); - d++; - break; -#endif /* not emacs */ - - default: - abort (); - } - continue; /* Successfully executed one pattern command; keep going. */ - - - /* We goto here if a matching operation fails. */ - fail: - if (!FAIL_STACK_EMPTY ()) - { /* A restart point is known. Restore to that state. */ - DEBUG_PRINT1 ("\nFAIL:\n"); - POP_FAILURE_POINT (d, p, - lowest_active_reg, highest_active_reg, - regstart, regend, reg_info); - - /* If this failure point is a dummy, try the next one. */ - if (!p) - goto fail; - - /* If we failed to the end of the pattern, don't examine *p. */ - assert (p <= pend); - if (p < pend) - { - boolean is_a_jump_n = false; - - /* If failed to a backwards jump that's part of a repetition - loop, need to pop this failure point and use the next one. */ - switch ((re_opcode_t) *p) - { - case jump_n: - is_a_jump_n = true; - case maybe_pop_jump: - case pop_failure_jump: - case jump: - p1 = p + 1; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - - if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n) - || (!is_a_jump_n - && (re_opcode_t) *p1 == on_failure_jump)) - goto fail; - break; - default: - /* do nothing */ ; - } - } - - if (d >= string1 && d <= end1) - dend = end_match_1; - } - else - break; /* Matching at this starting point really fails. */ - } /* for (;;) */ - - if (best_regs_set) - goto restore_best_regs; - - FREE_VARIABLES (); - - return -1; /* Failure to match. */ -} /* re_match_2 */ - -/* Subroutine definitions for re_match_2. */ - - -/* We are passed P pointing to a register number after a start_memory. - - Return true if the pattern up to the corresponding stop_memory can - match the empty string, and false otherwise. - - If we find the matching stop_memory, sets P to point to one past its number. - Otherwise, sets P to an undefined byte less than or equal to END. - - We don't handle duplicates properly (yet). */ - -static boolean -group_match_null_string_p (p, end, reg_info) - unsigned char **p, *end; - register_info_type *reg_info; -{ - int mcnt; - /* Point to after the args to the start_memory. */ - unsigned char *p1 = *p + 2; - - while (p1 < end) - { - /* Skip over opcodes that can match nothing, and return true or - false, as appropriate, when we get to one that can't, or to the - matching stop_memory. */ - - switch ((re_opcode_t) *p1) - { - /* Could be either a loop or a series of alternatives. */ - case on_failure_jump: - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - - /* If the next operation is not a jump backwards in the - pattern. */ - - if (mcnt >= 0) - { - /* Go through the on_failure_jumps of the alternatives, - seeing if any of the alternatives cannot match nothing. - The last alternative starts with only a jump, - whereas the rest start with on_failure_jump and end - with a jump, e.g., here is the pattern for `a|b|c': - - /on_failure_jump/0/6/exactn/1/a/jump_past_alt/0/6 - /on_failure_jump/0/6/exactn/1/b/jump_past_alt/0/3 - /exactn/1/c - - So, we have to first go through the first (n-1) - alternatives and then deal with the last one separately. */ - - - /* Deal with the first (n-1) alternatives, which start - with an on_failure_jump (see above) that jumps to right - past a jump_past_alt. */ - - while ((re_opcode_t) p1[mcnt-3] == jump_past_alt) - { - /* `mcnt' holds how many bytes long the alternative - is, including the ending `jump_past_alt' and - its number. */ - - if (!alt_match_null_string_p (p1, p1 + mcnt - 3, - reg_info)) - return false; - - /* Move to right after this alternative, including the - jump_past_alt. */ - p1 += mcnt; - - /* Break if it's the beginning of an n-th alternative - that doesn't begin with an on_failure_jump. */ - if ((re_opcode_t) *p1 != on_failure_jump) - break; - - /* Still have to check that it's not an n-th - alternative that starts with an on_failure_jump. */ - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if ((re_opcode_t) p1[mcnt-3] != jump_past_alt) - { - /* Get to the beginning of the n-th alternative. */ - p1 -= 3; - break; - } - } - - /* Deal with the last alternative: go back and get number - of the `jump_past_alt' just before it. `mcnt' contains - the length of the alternative. */ - EXTRACT_NUMBER (mcnt, p1 - 2); - - if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info)) - return false; - - p1 += mcnt; /* Get past the n-th alternative. */ - } /* if mcnt > 0 */ - break; - - - case stop_memory: - assert (p1[1] == **p); - *p = p1 + 2; - return true; - - - default: - if (!common_op_match_null_string_p (&p1, end, reg_info)) - return false; - } - } /* while p1 < end */ - - return false; -} /* group_match_null_string_p */ - - -/* Similar to group_match_null_string_p, but doesn't deal with alternatives: - It expects P to be the first byte of a single alternative and END one - byte past the last. The alternative can contain groups. */ - -static boolean -alt_match_null_string_p (p, end, reg_info) - unsigned char *p, *end; - register_info_type *reg_info; -{ - int mcnt; - unsigned char *p1 = p; - - while (p1 < end) - { - /* Skip over opcodes that can match nothing, and break when we get - to one that can't. */ - - switch ((re_opcode_t) *p1) - { - /* It's a loop. */ - case on_failure_jump: - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - break; - - default: - if (!common_op_match_null_string_p (&p1, end, reg_info)) - return false; - } - } /* while p1 < end */ - - return true; -} /* alt_match_null_string_p */ - - -/* Deals with the ops common to group_match_null_string_p and - alt_match_null_string_p. - - Sets P to one after the op and its arguments, if any. */ - -static boolean -common_op_match_null_string_p (p, end, reg_info) - unsigned char **p, *end; - register_info_type *reg_info; -{ - int mcnt; - boolean ret; - int reg_no; - unsigned char *p1 = *p; - - switch ((re_opcode_t) *p1++) - { - case no_op: - case begline: - case endline: - case begbuf: - case endbuf: - case wordbeg: - case wordend: - case wordbound: - case notwordbound: -#ifdef emacs - case before_dot: - case at_dot: - case after_dot: -#endif - break; - - case start_memory: - reg_no = *p1; - assert (reg_no > 0 && reg_no <= MAX_REGNUM); - ret = group_match_null_string_p (&p1, end, reg_info); - - /* Have to set this here in case we're checking a group which - contains a group and a back reference to it. */ - - if (REG_MATCH_NULL_STRING_P (reg_info[reg_no]) == MATCH_NULL_UNSET_VALUE) - REG_MATCH_NULL_STRING_P (reg_info[reg_no]) = ret; - - if (!ret) - return false; - break; - - /* If this is an optimized succeed_n for zero times, make the jump. */ - case jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if (mcnt >= 0) - p1 += mcnt; - else - return false; - break; - - case succeed_n: - /* Get to the number of times to succeed. */ - p1 += 2; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - - if (mcnt == 0) - { - p1 -= 4; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - } - else - return false; - break; - - case duplicate: - if (!REG_MATCH_NULL_STRING_P (reg_info[*p1])) - return false; - break; - - case set_number_at: - p1 += 4; - - default: - /* All other opcodes mean we cannot match the empty string. */ - return false; - } - - *p = p1; - return true; -} /* common_op_match_null_string_p */ - - -/* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN - bytes; nonzero otherwise. */ - -static int -bcmp_translate (s1, s2, len, translate) - unsigned char *s1, *s2; - register int len; - char *translate; -{ - register unsigned char *p1 = s1, *p2 = s2; - while (len) - { - if (translate[*p1++] != translate[*p2++]) return 1; - len--; - } - return 0; -} - -/* Entry points for GNU code. */ - -/* re_compile_pattern is the GNU regular expression compiler: it - compiles PATTERN (of length SIZE) and puts the result in BUFP. - Returns 0 if the pattern was valid, otherwise an error string. - - Assumes the `allocated' (and perhaps `buffer') and `translate' fields - are set in BUFP on entry. - - We call regex_compile to do the actual compilation. */ - -const char * -re_compile_pattern (pattern, length, bufp) - const char *pattern; - int length; - struct re_pattern_buffer *bufp; -{ - reg_errcode_t ret; - - /* GNU code is written to assume at least RE_NREGS registers will be set - (and at least one extra will be -1). */ - bufp->regs_allocated = REGS_UNALLOCATED; - - /* And GNU code determines whether or not to get register information - by passing null for the REGS argument to re_match, etc., not by - setting no_sub. */ - bufp->no_sub = 0; - - /* Match anchors at newline. */ - bufp->newline_anchor = 1; - - ret = regex_compile (pattern, length, re_syntax_options, bufp); - - return re_error_msg[(int) ret]; -} - -/* Entry points compatible with 4.2 BSD regex library. We don't define - them if this is an Emacs or POSIX compilation. */ - -#if !defined (emacs) && !defined (_POSIX_SOURCE) - -/* BSD has one and only one pattern buffer. */ -static struct re_pattern_buffer re_comp_buf; - -char * -re_comp (s) - const char *s; -{ - reg_errcode_t ret; - - if (!s) - { - if (!re_comp_buf.buffer) - return "No previous regular expression"; - return 0; - } - - if (!re_comp_buf.buffer) - { - re_comp_buf.buffer = (unsigned char *) malloc (200); - if (re_comp_buf.buffer == NULL) - return "Memory exhausted"; - re_comp_buf.allocated = 200; - - re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); - if (re_comp_buf.fastmap == NULL) - return "Memory exhausted"; - } - - /* Since `re_exec' always passes NULL for the `regs' argument, we - don't need to initialize the pattern buffer fields which affect it. */ - - /* Match anchors at newlines. */ - re_comp_buf.newline_anchor = 1; - - ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); - - /* Yes, we're discarding `const' here. */ - return (char *) re_error_msg[(int) ret]; -} - - -int -re_exec (s) - const char *s; -{ - const int len = strlen (s); - return - 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0); -} -#endif /* not emacs and not _POSIX_SOURCE */ - -/* POSIX.2 functions. Don't define these for Emacs. */ - -#ifndef emacs - -/* regcomp takes a regular expression as a string and compiles it. - - PREG is a regex_t *. We do not expect any fields to be initialized, - since POSIX says we shouldn't. Thus, we set - - `buffer' to the compiled pattern; - `used' to the length of the compiled pattern; - `syntax' to RE_SYNTAX_POSIX_EXTENDED if the - REG_EXTENDED bit in CFLAGS is set; otherwise, to - RE_SYNTAX_POSIX_BASIC; - `newline_anchor' to REG_NEWLINE being set in CFLAGS; - `fastmap' and `fastmap_accurate' to zero; - `re_nsub' to the number of subexpressions in PATTERN. - - PATTERN is the address of the pattern string. - - CFLAGS is a series of bits which affect compilation. - - If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we - use POSIX basic syntax. - - If REG_NEWLINE is set, then . and [^...] don't match newline. - Also, regexec will try a match beginning after every newline. - - If REG_ICASE is set, then we considers upper- and lowercase - versions of letters to be equivalent when matching. - - If REG_NOSUB is set, then when PREG is passed to regexec, that - routine will report only success or failure, and nothing about the - registers. - - It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for - the return codes and their meanings.) */ - -int -regcomp (preg, pattern, cflags) - regex_t *preg; - const char *pattern; - int cflags; -{ - reg_errcode_t ret; - unsigned syntax - = (cflags & REG_EXTENDED) ? - RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC; - - /* regex_compile will allocate the space for the compiled pattern. */ - preg->buffer = 0; - preg->allocated = 0; - preg->used = 0; - - /* Don't bother to use a fastmap when searching. This simplifies the - REG_NEWLINE case: if we used a fastmap, we'd have to put all the - characters after newlines into the fastmap. This way, we just try - every character. */ - preg->fastmap = 0; - - if (cflags & REG_ICASE) - { - unsigned i; - - preg->translate = (char *) malloc (CHAR_SET_SIZE); - if (preg->translate == NULL) - return (int) REG_ESPACE; - - /* Map uppercase characters to corresponding lowercase ones. */ - for (i = 0; i < CHAR_SET_SIZE; i++) - preg->translate[i] = ISUPPER (i) ? tolower (i) : i; - } - else - preg->translate = NULL; - - /* If REG_NEWLINE is set, newlines are treated differently. */ - if (cflags & REG_NEWLINE) - { /* REG_NEWLINE implies neither . nor [^...] match newline. */ - syntax &= ~RE_DOT_NEWLINE; - syntax |= RE_HAT_LISTS_NOT_NEWLINE; - /* It also changes the matching behavior. */ - preg->newline_anchor = 1; - } - else - preg->newline_anchor = 0; - - preg->no_sub = !!(cflags & REG_NOSUB); - - /* POSIX says a null character in the pattern terminates it, so we - can use strlen here in compiling the pattern. */ - ret = regex_compile (pattern, strlen (pattern), syntax, preg); - - /* POSIX doesn't distinguish between an unmatched open-group and an - unmatched close-group: both are REG_EPAREN. */ - if (ret == REG_ERPAREN) ret = REG_EPAREN; - - return (int) ret; -} - - -/* regexec searches for a given pattern, specified by PREG, in the - string STRING. - - If NMATCH is zero or REG_NOSUB was set in the cflags argument to - `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at - least NMATCH elements, and we set them to the offsets of the - corresponding matched substrings. - - EFLAGS specifies `execution flags' which affect matching: if - REG_NOTBOL is set, then ^ does not match at the beginning of the - string; if REG_NOTEOL is set, then $ does not match at the end. - - We return 0 if we find a match and REG_NOMATCH if not. */ - -int -regexec (preg, string, nmatch, pmatch, eflags) - const regex_t *preg; - const char *string; - size_t nmatch; - regmatch_t pmatch[]; - int eflags; -{ - int ret; - struct re_registers regs; - regex_t private_preg; - int len = strlen (string); - boolean want_reg_info = !preg->no_sub && nmatch > 0; - - private_preg = *preg; - - private_preg.not_bol = !!(eflags & REG_NOTBOL); - private_preg.not_eol = !!(eflags & REG_NOTEOL); - - /* The user has told us exactly how many registers to return - information about, via `nmatch'. We have to pass that on to the - matching routines. */ - private_preg.regs_allocated = REGS_FIXED; - - if (want_reg_info) - { - regs.num_regs = nmatch; - regs.start = TALLOC (nmatch, regoff_t); - regs.end = TALLOC (nmatch, regoff_t); - if (regs.start == NULL || regs.end == NULL) - return (int) REG_NOMATCH; - } - - /* Perform the searching operation. */ - ret = re_search (&private_preg, string, len, - /* start: */ 0, /* range: */ len, - want_reg_info ? ®s : (struct re_registers *) 0); - - /* Copy the register information to the POSIX structure. */ - if (want_reg_info) - { - if (ret >= 0) - { - unsigned r; - - for (r = 0; r < nmatch; r++) - { - pmatch[r].rm_so = regs.start[r]; - pmatch[r].rm_eo = regs.end[r]; - } - } - - /* If we needed the temporary register info, free the space now. */ - free (regs.start); - free (regs.end); - } - - /* We want zero return to mean success, unlike `re_search'. */ - return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH; -} - - -/* Returns a message corresponding to an error code, ERRCODE, returned - from either regcomp or regexec. We don't use PREG here. */ - -size_t -regerror (errcode, preg, errbuf, errbuf_size) - int errcode; - const regex_t *preg; - char *errbuf; - size_t errbuf_size; -{ - const char *msg; - size_t msg_size; - - if (errcode < 0 - || errcode >= (sizeof (re_error_msg) / sizeof (re_error_msg[0]))) - /* Only error codes returned by the rest of the code should be passed - to this routine. If we are given anything else, or if other regex - code generates an invalid error code, then the program has a bug. - Dump core so we can fix it. */ - abort (); - - msg = re_error_msg[errcode]; - - /* POSIX doesn't require that we do anything in this case, but why - not be nice. */ - if (! msg) - msg = "Success"; - - msg_size = strlen (msg) + 1; /* Includes the null. */ - - if (errbuf_size != 0) - { - if (msg_size > errbuf_size) - { - strncpy (errbuf, msg, errbuf_size - 1); - errbuf[errbuf_size - 1] = 0; - } - else - strcpy (errbuf, msg); - } - - return msg_size; -} - - -/* Free dynamically allocated space used by PREG. */ - -void -regfree (preg) - regex_t *preg; -{ - if (preg->buffer != NULL) - free (preg->buffer); - preg->buffer = NULL; - - preg->allocated = 0; - preg->used = 0; - - if (preg->fastmap != NULL) - free (preg->fastmap); - preg->fastmap = NULL; - preg->fastmap_accurate = 0; - - if (preg->translate != NULL) - free (preg->translate); - preg->translate = NULL; -} - -#endif /* not emacs */ - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/gnu/usr.bin/grep/regex.h b/gnu/usr.bin/grep/regex.h deleted file mode 100644 index 408dd21..0000000 --- a/gnu/usr.bin/grep/regex.h +++ /dev/null @@ -1,490 +0,0 @@ -/* Definitions for data structures and routines for the regular - expression library, version 0.12. - - Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __REGEXP_LIBRARY_H__ -#define __REGEXP_LIBRARY_H__ - -/* POSIX says that must be included (by the caller) before - . */ - -#ifdef VMS -/* VMS doesn't have `size_t' in , even though POSIX says it - should be there. */ -#include -#endif - - -/* The following bits are used to determine the regexp syntax we - recognize. The set/not-set meanings are chosen so that Emacs syntax - remains the value 0. The bits are given in alphabetical order, and - the definitions shifted by one from the previous bit; thus, when we - add or remove a bit, only one other definition need change. */ -typedef unsigned reg_syntax_t; - -/* If this bit is not set, then \ inside a bracket expression is literal. - If set, then such a \ quotes the following character. */ -#define RE_BACKSLASH_ESCAPE_IN_LISTS (1) - -/* If this bit is not set, then + and ? are operators, and \+ and \? are - literals. - If set, then \+ and \? are operators and + and ? are literals. */ -#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) - -/* If this bit is set, then character classes are supported. They are: - [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], - [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. - If not set, then character classes are not supported. */ -#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) - -/* If this bit is set, then ^ and $ are always anchors (outside bracket - expressions, of course). - If this bit is not set, then it depends: - ^ is an anchor if it is at the beginning of a regular - expression or after an open-group or an alternation operator; - $ is an anchor if it is at the end of a regular expression, or - before a close-group or an alternation operator. - - This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because - POSIX draft 11.2 says that * etc. in leading positions is undefined. - We already implemented a previous draft which made those constructs - invalid, though, so we haven't changed the code back. */ -#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) - -/* If this bit is set, then special characters are always special - regardless of where they are in the pattern. - If this bit is not set, then special characters are special only in - some contexts; otherwise they are ordinary. Specifically, - * + ? and intervals are only special when not after the beginning, - open-group, or alternation operator. */ -#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) - -/* If this bit is set, then *, +, ?, and { cannot be first in an re or - immediately after an alternation or begin-group operator. */ -#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) - -/* If this bit is set, then . matches newline. - If not set, then it doesn't. */ -#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) - -/* If this bit is set, then . doesn't match NUL. - If not set, then it does. */ -#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) - -/* If this bit is set, nonmatching lists [^...] do not match newline. - If not set, they do. */ -#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) - -/* If this bit is set, either \{...\} or {...} defines an - interval, depending on RE_NO_BK_BRACES. - If not set, \{, \}, {, and } are literals. */ -#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) - -/* If this bit is set, +, ? and | aren't recognized as operators. - If not set, they are. */ -#define RE_LIMITED_OPS (RE_INTERVALS << 1) - -/* If this bit is set, newline is an alternation operator. - If not set, newline is literal. */ -#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) - -/* If this bit is set, then `{...}' defines an interval, and \{ and \} - are literals. - If not set, then `\{...\}' defines an interval. */ -#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) - -/* If this bit is set, (...) defines a group, and \( and \) are literals. - If not set, \(...\) defines a group, and ( and ) are literals. */ -#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) - -/* If this bit is set, then \ matches . - If not set, then \ is a back-reference. */ -#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) - -/* If this bit is set, then | is an alternation operator, and \| is literal. - If not set, then \| is an alternation operator, and | is literal. */ -#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) - -/* If this bit is set, then an ending range point collating higher - than the starting range point, as in [z-a], is invalid. - If not set, then when ending range point collates higher than the - starting range point, the range is ignored. */ -#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) - -/* If this bit is set, then an unmatched ) is ordinary. - If not set, then an unmatched ) is invalid. */ -#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) - -/* This global variable defines the particular regexp syntax to use (for - some interfaces). When a regexp is compiled, the syntax used is - stored in the pattern buffer, so changing this does not affect - already-compiled regexps. */ -extern reg_syntax_t re_syntax_options; - -/* Define combinations of the above bits for the standard possibilities. - (The [[[ comments delimit what gets put into the Texinfo file, so - don't delete them!) */ -/* [[[begin syntaxes]]] */ -#define RE_SYNTAX_EMACS 0 - -#define RE_SYNTAX_AWK \ - (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - -#define RE_SYNTAX_POSIX_AWK \ - (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS) - -#define RE_SYNTAX_GREP \ - (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ - | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ - | RE_NEWLINE_ALT) - -#define RE_SYNTAX_EGREP \ - (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ - | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ - | RE_NO_BK_VBAR) - -#define RE_SYNTAX_POSIX_EGREP \ - (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES) - -/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ -#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC - -#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC - -/* Syntax bits common to both basic and extended POSIX regex syntax. */ -#define _RE_SYNTAX_POSIX_COMMON \ - (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ - | RE_INTERVALS | RE_NO_EMPTY_RANGES) - -#define RE_SYNTAX_POSIX_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) - -/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes - RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this - isn't minimal, since other operators, such as \`, aren't disabled. */ -#define RE_SYNTAX_POSIX_MINIMAL_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) - -#define RE_SYNTAX_POSIX_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - -/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS - replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */ -#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) -/* [[[end syntaxes]]] */ - -/* Maximum number of duplicates an interval can allow. Some systems - (erroneously) define this in other header files, but we want our - value, so remove any previous define. */ -#ifdef RE_DUP_MAX -#undef RE_DUP_MAX -#endif -#define RE_DUP_MAX ((1 << 15) - 1) - - -/* POSIX `cflags' bits (i.e., information for `regcomp'). */ - -/* If this bit is set, then use extended regular expression syntax. - If not set, then use basic regular expression syntax. */ -#define REG_EXTENDED 1 - -/* If this bit is set, then ignore case when matching. - If not set, then case is significant. */ -#define REG_ICASE (REG_EXTENDED << 1) - -/* If this bit is set, then anchors do not match at newline - characters in the string. - If not set, then anchors do match at newlines. */ -#define REG_NEWLINE (REG_ICASE << 1) - -/* If this bit is set, then report only success or fail in regexec. - If not set, then returns differ between not matching and errors. */ -#define REG_NOSUB (REG_NEWLINE << 1) - - -/* POSIX `eflags' bits (i.e., information for regexec). */ - -/* If this bit is set, then the beginning-of-line operator doesn't match - the beginning of the string (presumably because it's not the - beginning of a line). - If not set, then the beginning-of-line operator does match the - beginning of the string. */ -#define REG_NOTBOL 1 - -/* Like REG_NOTBOL, except for the end-of-line. */ -#define REG_NOTEOL (1 << 1) - - -/* If any error codes are removed, changed, or added, update the - `re_error_msg' table in regex.c. */ -typedef enum -{ - REG_NOERROR = 0, /* Success. */ - REG_NOMATCH, /* Didn't find a match (for regexec). */ - - /* POSIX regcomp return error codes. (In the order listed in the - standard.) */ - REG_BADPAT, /* Invalid pattern. */ - REG_ECOLLATE, /* Not implemented. */ - REG_ECTYPE, /* Invalid character class name. */ - REG_EESCAPE, /* Trailing backslash. */ - REG_ESUBREG, /* Invalid back reference. */ - REG_EBRACK, /* Unmatched left bracket. */ - REG_EPAREN, /* Parenthesis imbalance. */ - REG_EBRACE, /* Unmatched \{. */ - REG_BADBR, /* Invalid contents of \{\}. */ - REG_ERANGE, /* Invalid range end. */ - REG_ESPACE, /* Ran out of memory. */ - REG_BADRPT, /* No preceding re for repetition op. */ - - /* Error codes we've added. */ - REG_EEND, /* Premature end. */ - REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ - REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ -} reg_errcode_t; - -/* This data structure represents a compiled pattern. Before calling - the pattern compiler, the fields `buffer', `allocated', `fastmap', - `translate', and `no_sub' can be set. After the pattern has been - compiled, the `re_nsub' field is available. All other fields are - private to the regex routines. */ - -struct re_pattern_buffer -{ -/* [[[begin pattern_buffer]]] */ - /* Space that holds the compiled pattern. It is declared as - `unsigned char *' because its elements are - sometimes used as array indexes. */ - unsigned char *buffer; - - /* Number of bytes to which `buffer' points. */ - unsigned long allocated; - - /* Number of bytes actually used in `buffer'. */ - unsigned long used; - - /* Syntax setting with which the pattern was compiled. */ - reg_syntax_t syntax; - - /* Pointer to a fastmap, if any, otherwise zero. re_search uses - the fastmap, if there is one, to skip over impossible - starting points for matches. */ - char *fastmap; - - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation - is applied to a pattern when it is compiled and to a string - when it is matched. */ - char *translate; - - /* Number of subexpressions found by the compiler. */ - size_t re_nsub; - - /* Zero if this pattern cannot match the empty string, one else. - Well, in truth it's used only in `re_search_2', to see - whether or not we should use the fastmap, so we don't set - this absolutely perfectly; see `re_compile_fastmap' (the - `duplicate' case). */ - unsigned can_be_null : 1; - - /* If REGS_UNALLOCATED, allocate space in the `regs' structure - for `max (RE_NREGS, re_nsub + 1)' groups. - If REGS_REALLOCATE, reallocate space if necessary. - If REGS_FIXED, use what's there. */ -#define REGS_UNALLOCATED 0 -#define REGS_REALLOCATE 1 -#define REGS_FIXED 2 - unsigned regs_allocated : 2; - - /* Set to zero when `regex_compile' compiles a pattern; set to one - by `re_compile_fastmap' if it updates the fastmap. */ - unsigned fastmap_accurate : 1; - - /* If set, `re_match_2' does not return information about - subexpressions. */ - unsigned no_sub : 1; - - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ - unsigned not_bol : 1; - - /* Similarly for an end-of-line anchor. */ - unsigned not_eol : 1; - - /* If true, an anchor at a newline matches. */ - unsigned newline_anchor : 1; - -/* [[[end pattern_buffer]]] */ -}; - -typedef struct re_pattern_buffer regex_t; - - -/* search.c (search_buffer) in Emacs needs this one opcode value. It is - defined both in `regex.c' and here. */ -#define RE_EXACTN_VALUE 1 - -/* Type for byte offsets within the string. POSIX mandates this. */ -typedef int regoff_t; - - -/* This is the structure we store register match data in. See - regex.texinfo for a full description of what registers match. */ -struct re_registers -{ - unsigned num_regs; - regoff_t *start; - regoff_t *end; -}; - - -/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, - `re_match_2' returns information about at least this many registers - the first time a `regs' structure is passed. */ -#ifndef RE_NREGS -#define RE_NREGS 30 -#endif - - -/* POSIX specification for registers. Aside from the different names than - `re_registers', POSIX uses an array of structures, instead of a - structure of arrays. */ -typedef struct -{ - regoff_t rm_so; /* Byte offset from string's start to substring's start. */ - regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ -} regmatch_t; - -/* Declarations for routines. */ - -/* To avoid duplicating every routine declaration -- once with a - prototype (if we are ANSI), and once without (if we aren't) -- we - use the following macro to declare argument types. This - unfortunately clutters up the declarations a bit, but I think it's - worth it. */ - -#if __STDC__ - -#define _RE_ARGS(args) args - -#else /* not __STDC__ */ - -#define _RE_ARGS(args) () - -#endif /* not __STDC__ */ - -/* Sets the current default syntax to SYNTAX, and return the old syntax. - You can also simply assign to the `re_syntax_options' variable. */ -extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); - -/* Compile the regular expression PATTERN, with length LENGTH - and syntax given by the global `re_syntax_options', into the buffer - BUFFER. Return NULL if successful, and an error string if not. */ -extern const char *re_compile_pattern - _RE_ARGS ((const char *pattern, int length, - struct re_pattern_buffer *buffer)); - - -/* Compile a fastmap for the compiled pattern in BUFFER; used to - accelerate searches. Return 0 if successful and -2 if was an - internal error. */ -extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); - - -/* Search in the string STRING (with length LENGTH) for the pattern - compiled into BUFFER. Start searching at position START, for RANGE - characters. Return the starting position of the match, -1 for no - match, or -2 for an internal error. Also return register - information in REGS (if REGS and BUFFER->no_sub are nonzero). */ -extern int re_search - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, int range, struct re_registers *regs)); - - -/* Like `re_search', but search in the concatenation of STRING1 and - STRING2. Also, stop searching at index START + STOP. */ -extern int re_search_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, int range, struct re_registers *regs, int stop)); - - -/* Like `re_search', but return how many characters in STRING the regexp - in BUFFER matched, starting at position START. */ -extern int re_match - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, struct re_registers *regs)); - - -/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ -extern int re_match_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, struct re_registers *regs, int stop)); - - -/* Set REGS to hold NUM_REGS registers, storing them in STARTS and - ENDS. Subsequent matches using BUFFER and REGS will use this memory - for recording register information. STARTS and ENDS must be - allocated with malloc, and must each be at least `NUM_REGS * sizeof - (regoff_t)' bytes long. - - If NUM_REGS == 0, then subsequent matches should allocate their own - register data. - - Unless this function is called, the first search or match using - PATTERN_BUFFER will allocate its own register data, without - freeing the old data. */ -extern void re_set_registers - _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, - unsigned num_regs, regoff_t *starts, regoff_t *ends)); - -/* 4.2 bsd compatibility. */ -extern char *re_comp _RE_ARGS ((const char *)); -extern int re_exec _RE_ARGS ((const char *)); - -/* POSIX compatibility. */ -extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags)); -extern int regexec - _RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch, - regmatch_t pmatch[], int eflags)); -extern size_t regerror - _RE_ARGS ((int errcode, const regex_t *preg, char *errbuf, - size_t errbuf_size)); -extern void regfree _RE_ARGS ((regex_t *preg)); - -#endif /* not __REGEXP_LIBRARY_H__ */ - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/gnu/usr.bin/gzip/gzexe.in b/gnu/usr.bin/gzip/gzexe.in deleted file mode 100644 index a28ec3d..0000000 --- a/gnu/usr.bin/gzip/gzexe.in +++ /dev/null @@ -1,151 +0,0 @@ -: -#!/bin/sh -# gzexe: compressor for Unix executables. -# Use this only for binaries that you do not use frequently. -# -# The compressed version is a shell script which decompresses itself after -# skipping $skip lines of shell commands. We try invoking the compressed -# executable with the original name (for programs looking at their name). -# We also try to retain the original file permissions on the compressed file. -# For safety reasons, gzexe will not create setuid or setgid shell scripts. - -# WARNING: the first line of this file must be either : or #!/bin/sh -# The : is required for some old versions of csh. -# On Ultrix, /bin/sh is too buggy, change the first line to: #!/bin/sh5 - -x=`basename $0` -if test $# = 0; then - echo compress executables. original file foo is renamed to foo~ - echo usage: ${x} [-d] files... - echo " -d decompress the executables" - exit 1 -fi - -tmp=gz$$ -trap "rm -f $tmp; exit 1" 1 2 3 5 10 13 15 - -decomp=0 -res=0 -test "$x" = "ungzexe" && decomp=1 -if test "x$1" = "x-d"; then - decomp=1 - shift -fi - -echo hi > zfoo1$$ -echo hi > zfoo2$$ -if test -z "`(${CPMOD-cpmod} zfoo1$$ zfoo2$$) 2>&1`"; then - cpmod=${CPMOD-cpmod} -fi -rm -f zfoo[12]$$ - -tail="" -IFS="${IFS= }"; saveifs="$IFS"; IFS="${IFS}:" -for dir in $PATH; do - test -z "$dir" && dir=. - if test -f $dir/tail; then - tail="$dir/tail" - break - fi -done -IFS="$saveifs" -if test -z "$tail"; then - echo cannot find tail - exit 1 -fi - -for i do - if test ! -f "$i" ; then - echo ${x}: $i not a file - res=1 - continue - fi - if test $decomp -eq 0; then - if sed -e 1d -e 2q "$i" | grep "^skip=[0-9]*$" >/dev/null; then - echo "${x}: $i is already gzexe'd" - continue - fi - fi - if ls -l "$i" | grep '^...[sS]' > /dev/null; then - echo "${x}: $i has setuid permission, unchanged" - continue - fi - if ls -l "$i" | grep '^......[sS]' > /dev/null; then - echo "${x}: $i has setgid permission, unchanged" - continue - fi - case "`basename $i`" in - gzip | tail | chmod | ln | sleep | rm) - echo "${x}: $i would depend on itself"; continue ;; - esac - if test -z "$cpmod"; then - cp -p "$i" $tmp 2>/dev/null || cp "$i" $tmp - if test -w $tmp 2>/dev/null; then - writable=1 - else - writable=0 - chmod u+w $tmp 2>/dev/null - fi - fi - if test $decomp -eq 0; then - sed 1q $0 > $tmp - sed "s|^if tail|if $tail|" >> $tmp <<'EOF' -skip=18 -if tail +$skip $0 | "BINDIR"/gzip -cd > /tmp/gztmp$$; then - /bin/chmod 700 /tmp/gztmp$$ - prog="`echo $0 | /bin/sed 's|^.*/||`" - if /bin/ln /tmp/gztmp$$ "/tmp/$prog" 2>/dev/null; then - trap '/bin/rm -f /tmp/gztmp$$ "/tmp/$prog"; exit $res' 0 - (/bin/sleep 5; /bin/rm -f /tmp/gztmp$$ "/tmp/$prog") 2>/dev/null & - /tmp/"$prog" ${1+"$@"}; res=$? - else - trap '/bin/rm -f /tmp/gztmp$$; exit $res' 0 - (/bin/sleep 5; /bin/rm -f /tmp/gztmp$$) 2>/dev/null & - /tmp/gztmp$$ ${1+"$@"}; res=$? - fi -else - echo Cannot decompress $0; exit 1 -fi; exit $res -EOF - "BINDIR"/gzip -cv9 "$i" >> $tmp || { - /bin/rm -f $tmp - echo ${x}: compression not possible for $i, file unchanged. - res=1 - continue - } - - else - # decompression - skip=18 - if sed -e 1d -e 2q "$i" | grep "^skip=[0-9]*$" >/dev/null; then - eval `sed -e 1d -e 2q "$i"` - fi - if tail +$skip "$i" | "BINDIR"/gzip -cd > $tmp; then - : - else - echo ${x}: $i probably not in gzexe format, file unchanged. - res=1 - continue - fi - fi - rm -f "$i~" - mv "$i" "$i~" || { - echo ${x}: cannot backup $i as $i~ - rm -f $tmp - res=1 - continue - } - mv $tmp "$i" || cp -p $tmp "$i" 2>/dev/null || cp $tmp "$i" || { - echo ${x}: cannot create $i - rm -f $tmp - res=1 - continue - } - rm -f $tmp - if test -n "$cpmod"; then - $cpmod "$i~" "$i" 2>/dev/null - elif test $writable -eq 0; then - chmod u-w $i 2>/dev/null - fi -done -exit $res diff --git a/gnu/usr.bin/ld/TODO b/gnu/usr.bin/ld/TODO deleted file mode 100644 index d37a245..0000000 --- a/gnu/usr.bin/ld/TODO +++ /dev/null @@ -1,4 +0,0 @@ -- Make C++ shared libs work (properly resolve ctor and dtor lists) -- Make -r and -X work together for PIC .o files. - -- Avoid duplicatating shared library specifications in link_objects diff --git a/gnu/usr.bin/man/catman/catman b/gnu/usr.bin/man/catman/catman deleted file mode 100644 index a2d16a1..0000000 --- a/gnu/usr.bin/man/catman/catman +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# usage: sh catman -# put the section numbers here: -SECTIONS="1 2 3 4 5 6 7 8" -MANDIR=/usr/share/man - -formatman() -{ - echo " "$1 "->" $* - (cd cat$section; rm -f $*) - nroff -man < man$section/$1 > cat$section/$1 - catfile=$1; shift - while [ $# -gt 0 ] - do - ln cat$section/$catfile cat$section/$1 - shift - done -} - -cd $MANDIR -for section in $SECTIONS -do - echo formatting section $section ... - - IFS=" " - allfiles=`ls -i1 man$section | sort | awk '{if (inode ~ $1) printf "/" $2; - else printf " " $2; inode = $1 } END {printf "\n"}'` - for files in $allfiles - do - IFS="/" - tfiles=`echo $files` - IFS=" " - formatman $tfiles - done -done -exit 0 diff --git a/gnu/usr.bin/man/catman/catman.sh b/gnu/usr.bin/man/catman/catman.sh deleted file mode 100644 index 456cb57..0000000 --- a/gnu/usr.bin/man/catman/catman.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# usage: sh catman -# put the section numbers here: -SECTIONS="1 2 3 4 5 6 7 8" -MANDIR=/usr/share/man - -formatman() -{ - suffix=`echo $1 | sed -e 's/.*\\.//'` - (cd cat$section; rm -f $*) - if [ ".$suffix" = "%compext%" ]; then - adds= - %zcat% man$section/$1 | nroff -man | %compress% > cat$section/$1$adds - else - adds=%compext% - nroff -man < man$section/$1 | %compress% > cat$section/$1$adds - fi - echo " "$* "->" $1$adds - catfile=$1$adds; shift - while [ $# -gt 0 ] - do - ln cat$section/$catfile cat$section/$1$adds - shift - done -} - -cd $MANDIR -for section in $SECTIONS -do - echo formatting section $section ... - - IFS=" " - allfiles=`ls -i1 man$section | sort | awk '{if (inode ~ $1) printf "/" $2; - else printf " " $2; inode = $1 } END {printf "\n"}'` - for files in $allfiles - do - IFS="/" - tfiles=`echo $files` - IFS=" " - formatman $tfiles - done -done -exit 0 diff --git a/gnu/usr.bin/man/makewhatis/makewhatis.sh b/gnu/usr.bin/man/makewhatis/makewhatis.sh deleted file mode 100644 index 28b871d..0000000 --- a/gnu/usr.bin/man/makewhatis/makewhatis.sh +++ /dev/null @@ -1,120 +0,0 @@ -#!/bin/sh -# -# makewhatis -- update the whatis database in the man directories. -# -# Copyright (c) 1990, 1991, John W. Eaton. -# -# You may distribute under the terms of the GNU General Public -# License as specified in the README file that comes with the man -# distribution. -# -# John W. Eaton -# jwe@che.utexas.edu -# Department of Chemical Engineering -# The University of Texas at Austin -# Austin, Texas 78712 - -PATH=/bin:/usr/local/bin:/usr/ucb:/usr/bin - -if [ $# = 0 ] -then - echo "usage: makewhatis directory [...]" - exit 1 -fi -for dir in $* -do - cd $dir - for subdir in man* - do - if [ -d $subdir ] - then - for f in `find $subdir -type f -print` - do - suffix=`echo $f | sed -e 's/.*\\.//'` - if [ ".$suffix" = "%compext%" ]; then - output=%zcat% - else - output=cat - fi - $output $f | \ - sed -n '/^\.TH.*$/p - /^\.Dt.*$/p - /^\.S[hH][ ]*NAME/,/^\.S[hH]/p'|\ - sed -e 's/\\[ ]*\-/-/ - s/^.P[Pp].*$// - s/\\(em// - s/\\fI// - s/\\fR//' |\ - awk 'BEGIN {insh = 0; inSh = 0; Nd = 0} { - if ($1 == ".TH" || $1 == ".Dt") - sect = $3 - else if (($1 == ".br" && insh == 1)\ - || ($1 == ".SH" && insh == 1)\ - || ($1 == ".Sh" && inSh == 1)) { - if (i > 0 && nc > 0) { - for (k= 1; k <= nc; k++) { - namesect = sprintf("%s (%s)", name[k], sect) - printf("%s", namesect) - printf(" - ") - for (j = 0; j < i-1; j++) - printf("%s ", desc[j]) - printf("%s\n", desc[i-1]) - } - } - count = 0 - i = 0 - nc = 0 - } else if ($1 == ".SH" && insh == 0) { - insh = 1 - count = 0 - i = 0 - nc = 0 - } else if ($1 == ".Sh" && inSh == 0) { - inSh = 1 - i = 0 - nc = 0 - } else if (insh == 1) { - count++ - if (count == 1 && NF > 2) { - start = 2 - for (k = 1; k <= NF; k++) - if ($k == "-") { - start = k + 1 - break - } else { - sub(",","",$k) - if ($k != "") - name[++nc] = $k - } - if (NF >= start) - for (j = start; j <= NF; j++) - desc[i++] = $j - } else { - for (j = 1; j <= NF; j++) - desc[i++] = $j - } - } else if ($1 == ".Nm" && inSh == 1 && Nd == 0) { - for (k = 2; k <= NF; k++) { - sub(",","",$k) - if ($k != "") - name[++nc] = $k - } - } else if ($1 == ".Nd" && inSh == 1) { - Nd = 1 - for (j = 2; j <= NF; j++) - desc[i++] = $j - } else if (Nd == 1) { - start = 1 - if ($1 ~ /\..*/) - start = 2 - for (j = start; j <= NF; j++) - desc[i++] = $j - } - }' - done - fi - done | sort | colrm 80 | uniq > $dir/whatis.db.tmp - mv $dir/whatis.db.tmp $dir/whatis -done - -exit diff --git a/gnu/usr.bin/perl/perl/usub/Makefile b/gnu/usr.bin/perl/perl/usub/Makefile deleted file mode 100644 index 965a98a..0000000 --- a/gnu/usr.bin/perl/perl/usub/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -SRC = .. -GLOBINCS = -LOCINCS = -LIBS = -lcurses -ltermcap `. $(SRC)/config.sh; echo $$libs` - -curseperl: $(SRC)/uperl.o usersub.o curses.o - cc $(SRC)/uperl.o usersub.o curses.o $(LIBS) -o curseperl - -usersub.o: usersub.c - cc -c -I$(SRC) $(GLOBINCS) -DDEBUGGING -g usersub.c - -curses.o: curses.c - cc -c -I$(SRC) $(GLOBINCS) -DDEBUGGING -g curses.c - -curses.c: curses.mus - mus curses.mus >curses.c diff --git a/gnu/usr.bin/pr/Makefile b/gnu/usr.bin/pr/Makefile deleted file mode 100644 index d651c20..0000000 --- a/gnu/usr.bin/pr/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -PROG= pr -SRCS= pr.c getopt.c getopt1.c error.c xmalloc.c version.c - -CFLAGS+=-I${.CURDIR} -DDIRENT=1 -DHAVE_LONG_DOUBLE=1 -DHAVE_LONG_DOUBLE=1 \ - -DHAVE_ST_BLKSIZE=1 -DHAVE_VPRINTF=1 -DRETSIGTYPE=void \ - -DSTDC_HEADERS=1 -DDHAVE_STRERROR=1 -DHAVE_FCNTL_H=1 \ - -DHAVE_LIMITS_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRING_H=1 \ - -DHAVE_UNISTD_H=1 - - -.include diff --git a/gnu/usr.bin/pr/error.c b/gnu/usr.bin/pr/error.c deleted file mode 100644 index 41d66fb..0000000 --- a/gnu/usr.bin/pr/error.c +++ /dev/null @@ -1,117 +0,0 @@ -/* error.c -- error handler for noninteractive utilities - Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Written by David MacKenzie. */ - -#ifdef HAVE_CONFIG_H -#if defined (CONFIG_BROKETS) -/* We use instead of "config.h" so that a compilation - using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h - (which it would do because it found this file in $srcdir). */ -#include -#else -#include "config.h" -#endif -#endif - -#include - -#ifdef HAVE_VPRINTF - -#if __STDC__ -#include -#define VA_START(args, lastarg) va_start(args, lastarg) -#else /* !__STDC__ */ -#include -#define VA_START(args, lastarg) va_start(args) -#endif /* !__STDC__ */ - -#else /* !HAVE_VPRINTF */ - -#ifdef HAVE_DOPRNT -#define va_alist args -#define va_dcl int args; -#else /* !HAVE_DOPRNT */ -#define va_alist a1, a2, a3, a4, a5, a6, a7, a8 -#define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; -#endif /* !HAVE_DOPRNT */ - -#endif /* !HAVE_VPRINTF */ - -#ifdef STDC_HEADERS -#include -#include -#else /* !STDC_HEADERS */ -void exit (); -#endif /* !STDC_HEADERS */ - -extern char *program_name; - -#ifndef HAVE_STRERROR -static char * -private_strerror (errnum) - int errnum; -{ - extern char *sys_errlist[]; - extern int sys_nerr; - - if (errnum > 0 && errnum <= sys_nerr) - return sys_errlist[errnum]; - return "Unknown system error"; -} -#define strerror private_strerror -#endif /* !HAVE_STRERROR */ - -/* Print the program name and error message MESSAGE, which is a printf-style - format string with optional args. - If ERRNUM is nonzero, print its corresponding system error message. - Exit with status STATUS if it is nonzero. */ -/* VARARGS */ -void -#if defined (HAVE_VPRINTF) && __STDC__ -error (int status, int errnum, char *message, ...) -#else /* !HAVE_VPRINTF or !__STDC__ */ -error (status, errnum, message, va_alist) - int status; - int errnum; - char *message; - va_dcl -#endif /* !HAVE_VPRINTF or !__STDC__ */ -{ -#ifdef HAVE_VPRINTF - va_list args; -#endif /* HAVE_VPRINTF */ - - fprintf (stderr, "%s: ", program_name); -#ifdef HAVE_VPRINTF - VA_START (args, message); - vfprintf (stderr, message, args); - va_end (args); -#else /* !HAVE_VPRINTF */ -#ifdef HAVE_DOPRNT - _doprnt (message, &args, stderr); -#else /* !HAVE_DOPRNT */ - fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); -#endif /* !HAVE_DOPRNT */ -#endif /* !HAVE_VPRINTF */ - if (errnum) - fprintf (stderr, ": %s", strerror (errnum)); - putc ('\n', stderr); - fflush (stderr); - if (status) - exit (status); -} diff --git a/gnu/usr.bin/pr/getopt.c b/gnu/usr.bin/pr/getopt.c deleted file mode 100644 index 7a4673b..0000000 --- a/gnu/usr.bin/pr/getopt.c +++ /dev/null @@ -1,757 +0,0 @@ -/* Getopt for GNU. - NOTE: getopt is now part of the C library, so if you don't know what - "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu - before changing it! - - Copyright (C) 1987, 88, 89, 90, 91, 92, 1993 - Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifdef HAVE_CONFIG_H -#if defined (emacs) || defined (CONFIG_BROKETS) -/* We use instead of "config.h" so that a compilation - using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h - (which it would do because it found this file in $srcdir). */ -#include -#else -#include "config.h" -#endif -#endif - -#ifndef __STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - -/* This tells Alpha OSF/1 not to define a getopt prototype in . */ -#ifndef _NO_PROTO -#define _NO_PROTO -#endif - -#include - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#if defined (_LIBC) || !defined (__GNU_LIBRARY__) - - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -/* Don't include stdlib.h for non-GNU C libraries because some of them - contain conflicting prototypes for getopt. */ -#include -#endif /* GNU C library. */ - -/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a - long-named option. Because this is not POSIX.2 compliant, it is - being phased out. */ -/* #define GETOPT_COMPAT */ - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. - - Setting the environment variable POSIXLY_CORRECT disables permutation. - Then the behavior is completely standard. - - GNU application programs can use a third alternative mode in which - they can distinguish the relative order of options and other arguments. */ - -#include "getopt.h" - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -char *optarg = 0; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns EOF, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -/* XXX 1003.2 says this must be 1 before any call. */ -int optind = 0; - -/* The next char to be scanned in the option-element - in which the last option character we returned was found. - This allows us to pick up the scan where we left off. - - If this is zero, or a null string, it means resume the scan - by advancing to the next ARGV-element. */ - -static char *nextchar; - -/* Callers store zero here to inhibit the error message - for unrecognized options. */ - -int opterr = 1; - -/* Set to an option character which was unrecognized. - This must be initialized on some systems to avoid linking in the - system's own getopt implementation. */ - -int optopt = '?'; - -/* Describe how to deal with options that follow non-option ARGV-elements. - - If the caller did not specify anything, - the default is REQUIRE_ORDER if the environment variable - POSIXLY_CORRECT is defined, PERMUTE otherwise. - - REQUIRE_ORDER means don't recognize them as options; - stop option processing when the first non-option is seen. - This is what Unix does. - This mode of operation is selected by either setting the environment - variable POSIXLY_CORRECT, or using `+' as the first character - of the list of option characters. - - PERMUTE is the default. We permute the contents of ARGV as we scan, - so that eventually all the non-options are at the end. This allows options - to be given in any order, even with programs that were not written to - expect this. - - RETURN_IN_ORDER is an option available to programs that were written - to expect options and other ARGV-elements in any order and that care about - the ordering of the two. We describe each non-option ARGV-element - as if it were the argument of an option with character code 1. - Using `-' as the first character of the list of option characters - selects this mode of operation. - - The special argument `--' forces an end of option-scanning regardless - of the value of `ordering'. In the case of RETURN_IN_ORDER, only - `--' can cause `getopt' to return EOF with `optind' != ARGC. */ - -static enum -{ - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER -} ordering; - -#ifdef __GNU_LIBRARY__ -/* We want to avoid inclusion of string.h with non-GNU libraries - because there are many ways it can cause trouble. - On some systems, it contains special magic macros that don't work - in GCC. */ -#include -#define my_index strchr -#else - -/* Avoid depending on library functions or files - whose names are inconsistent. */ - -char *getenv (); - -static char * -my_index (str, chr) - const char *str; - int chr; -{ - while (*str) - { - if (*str == chr) - return (char *) str; - str++; - } - return 0; -} - -/* If using GCC, we can safely declare strlen this way. - If not using GCC, it is ok not to declare it. - (Supposedly there are some machines where it might get a warning, - but changing this conditional to __STDC__ is too risky.) */ -#ifdef __GNUC__ -#ifdef IN_GCC -#include "gstddef.h" -#else -#include -#endif -extern size_t strlen (const char *); -#endif - -#endif /* GNU C library. */ - -/* Handle permutation of arguments. */ - -/* Describe the part of ARGV that contains non-options that have - been skipped. `first_nonopt' is the index in ARGV of the first of them; - `last_nonopt' is the index after the last of them. */ - -static int first_nonopt; -static int last_nonopt; - -/* Exchange two adjacent subsequences of ARGV. - One subsequence is elements [first_nonopt,last_nonopt) - which contains all the non-options that have been skipped so far. - The other is elements [last_nonopt,optind), which contains all - the options processed since those non-options were skipped. - - `first_nonopt' and `last_nonopt' are relocated so that they describe - the new indices of the non-options in ARGV after they are moved. */ - -static void -exchange (argv) - char **argv; -{ - int bottom = first_nonopt; - int middle = last_nonopt; - int top = optind; - char *tem; - - /* Exchange the shorter segment with the far end of the longer segment. - That puts the shorter segment into the right place. - It leaves the longer segment in the right place overall, - but it consists of two parts that need to be swapped next. */ - - while (top > middle && middle > bottom) - { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - - /* Update records for the slots the non-options now occupy. */ - - first_nonopt += (optind - last_nonopt); - last_nonopt = optind; -} - -/* Scan elements of ARGV (whose length is ARGC) for option characters - given in OPTSTRING. - - If an element of ARGV starts with '-', and is not exactly "-" or "--", - then it is an option element. The characters of this element - (aside from the initial '-') are option characters. If `getopt' - is called repeatedly, it returns successively each of the option characters - from each of the option elements. - - If `getopt' finds another option character, it returns that character, - updating `optind' and `nextchar' so that the next call to `getopt' can - resume the scan with the following option character or ARGV-element. - - If there are no more option characters, `getopt' returns `EOF'. - Then `optind' is the index in ARGV of the first ARGV-element - that is not an option. (The ARGV-elements have been permuted - so that those that are not options now come last.) - - OPTSTRING is a string containing the legitimate option characters. - If an option character is seen that is not listed in OPTSTRING, - return '?' after printing an error message. If you set `opterr' to - zero, the error message is suppressed but we still return '?'. - - If a char in OPTSTRING is followed by a colon, that means it wants an arg, - so the following text in the same ARGV-element, or the text of the following - ARGV-element, is returned in `optarg'. Two colons mean an option that - wants an optional arg; if there is text in the current ARGV-element, - it is returned in `optarg', otherwise `optarg' is set to zero. - - If OPTSTRING starts with `-' or `+', it requests different methods of - handling the non-option ARGV-elements. - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - - Long-named options begin with `--' instead of `-'. - Their names may be abbreviated as long as the abbreviation is unique - or is an exact match for some defined option. If they have an - argument, it follows the option name in the same ARGV-element, separated - from the option name by a `=', or else the in next ARGV-element. - When `getopt' finds a long-named option, it returns 0 if that option's - `flag' field is nonzero, the value of the option's `val' field - if the `flag' field is zero. - - The elements of ARGV aren't really const, because we permute them. - But we pretend they're const in the prototype to be compatible - with other systems. - - LONGOPTS is a vector of `struct option' terminated by an - element containing a name which is zero. - - LONGIND returns the index in LONGOPT of the long-named option found. - It is only valid when a long-named option has been found by the most - recent call. - - If LONG_ONLY is nonzero, '-' as well as '--' can introduce - long-named options. */ - -int -_getopt_internal (argc, argv, optstring, longopts, longind, long_only) - int argc; - char *const *argv; - const char *optstring; - const struct option *longopts; - int *longind; - int long_only; -{ - int option_index; - - optarg = 0; - - /* Initialize the internal data when the first call is made. - Start processing options with ARGV-element 1 (since ARGV-element 0 - is the program name); the sequence of previously skipped - non-option ARGV-elements is empty. */ - - if (optind == 0) - { - first_nonopt = last_nonopt = optind = 1; - - nextchar = NULL; - - /* Determine how to handle the ordering of options and nonoptions. */ - - if (optstring[0] == '-') - { - ordering = RETURN_IN_ORDER; - ++optstring; - } - else if (optstring[0] == '+') - { - ordering = REQUIRE_ORDER; - ++optstring; - } - else if (getenv ("POSIXLY_CORRECT") != NULL) - ordering = REQUIRE_ORDER; - else - ordering = PERMUTE; - } - - if (nextchar == NULL || *nextchar == '\0') - { - if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - exchange them so that the options come first. */ - - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (last_nonopt != optind) - first_nonopt = optind; - - /* Now skip any additional non-options - and extend the range of non-options previously skipped. */ - - while (optind < argc - && (argv[optind][0] != '-' || argv[optind][1] == '\0') -#ifdef GETOPT_COMPAT - && (longopts == NULL - || argv[optind][0] != '+' || argv[optind][1] == '\0') -#endif /* GETOPT_COMPAT */ - ) - optind++; - last_nonopt = optind; - } - - /* Special ARGV-element `--' means premature end of options. - Skip it like a null option, - then exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ - - if (optind != argc && !strcmp (argv[optind], "--")) - { - optind++; - - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = optind; - last_nonopt = argc; - - optind = argc; - } - - /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ - - if (optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - optind = first_nonopt; - return EOF; - } - - /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ - - if ((argv[optind][0] != '-' || argv[optind][1] == '\0') -#ifdef GETOPT_COMPAT - && (longopts == NULL - || argv[optind][0] != '+' || argv[optind][1] == '\0') -#endif /* GETOPT_COMPAT */ - ) - { - if (ordering == REQUIRE_ORDER) - return EOF; - optarg = argv[optind++]; - return 1; - } - - /* We have found another option-ARGV-element. - Start decoding its characters. */ - - nextchar = (argv[optind] + 1 - + (longopts != NULL && argv[optind][1] == '-')); - } - - if (longopts != NULL - && ((argv[optind][0] == '-' - && (argv[optind][1] == '-' || long_only)) -#ifdef GETOPT_COMPAT - || argv[optind][0] == '+' -#endif /* GETOPT_COMPAT */ - )) - { - const struct option *p; - char *s = nextchar; - int exact = 0; - int ambig = 0; - const struct option *pfound = NULL; - int indfound; - - while (*s && *s != '=') - s++; - - /* Test all options for either exact match or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; - p++, option_index++) - if (!strncmp (p->name, nextchar, s - nextchar)) - { - if (s - nextchar == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second nonexact match found. */ - ambig = 1; - } - - if (ambig && !exact) - { - if (opterr) - fprintf (stderr, "%s: option `%s' is ambiguous\n", - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - return '?'; - } - - if (pfound != NULL) - { - option_index = indfound; - optind++; - if (*s) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = s + 1; - else - { - if (opterr) - { - if (argv[optind - 1][1] == '-') - /* --option */ - fprintf (stderr, - "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[optind - 1][0], pfound->name); - } - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (opterr) - fprintf (stderr, "%s: option `%s' requires an argument\n", - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ - if (!long_only || argv[optind][1] == '-' -#ifdef GETOPT_COMPAT - || argv[optind][0] == '+' -#endif /* GETOPT_COMPAT */ - || my_index (optstring, *nextchar) == NULL) - { - if (opterr) - { - if (argv[optind][1] == '-') - /* --option */ - fprintf (stderr, "%s: unrecognized option `--%s'\n", - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, "%s: unrecognized option `%c%s'\n", - argv[0], argv[optind][0], nextchar); - } - nextchar = (char *) ""; - optind++; - return '?'; - } - } - - /* Look at and handle the next option-character. */ - - { - char c = *nextchar++; - char *temp = my_index (optstring, c); - - /* Increment `optind' when we start to process its last character. */ - if (*nextchar == '\0') - ++optind; - - if (temp == NULL || c == ':') - { - if (opterr) - { -#if 0 - if (c < 040 || c >= 0177) - fprintf (stderr, "%s: unrecognized option, character code 0%o\n", - argv[0], c); - else - fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c); -#else - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); -#endif - } - optopt = c; - return '?'; - } - if (temp[1] == ':') - { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - optarg = nextchar; - optind++; - } - else - optarg = 0; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (opterr) - { -#if 0 - fprintf (stderr, "%s: option `-%c' requires an argument\n", - argv[0], c); -#else - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, "%s: option requires an argument -- %c\n", - argv[0], c); -#endif - } - optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - nextchar = NULL; - } - } - return c; - } -} - -int -getopt (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; -{ - return _getopt_internal (argc, argv, optstring, - (const struct option *) 0, - (int *) 0, - 0); -} - -#endif /* _LIBC or not __GNU_LIBRARY__. */ - -#ifdef TEST - -/* Compile with -DTEST to make an executable for use in testing - the above definition of `getopt'. */ - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - - c = getopt (argc, argv, "abc:d:0123456789"); - if (c == EOF) - break; - - switch (c) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/gnu/usr.bin/pr/getopt1.c b/gnu/usr.bin/pr/getopt1.c deleted file mode 100644 index f784b57..0000000 --- a/gnu/usr.bin/pr/getopt1.c +++ /dev/null @@ -1,187 +0,0 @@ -/* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987, 88, 89, 90, 91, 92, 1993 - Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifdef HAVE_CONFIG_H -#if defined (emacs) || defined (CONFIG_BROKETS) -/* We use instead of "config.h" so that a compilation - using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h - (which it would do because it found this file in $srcdir). */ -#include -#else -#include "config.h" -#endif -#endif - -#include "getopt.h" - -#ifndef __STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - -#include - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#if defined (_LIBC) || !defined (__GNU_LIBRARY__) - - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -#include -#else -char *getenv (); -#endif - -#ifndef NULL -#define NULL 0 -#endif - -int -getopt_long (argc, argv, options, long_options, opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 0); -} - -/* Like getopt_long, but '-' as well as '--' can indicate a long option. - If an option that starts with '-' (not '--') doesn't match a long option, - but does match a short option, it is parsed as a short option - instead. */ - -int -getopt_long_only (argc, argv, options, long_options, opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 1); -} - - -#endif /* _LIBC or not __GNU_LIBRARY__. */ - -#ifdef TEST - -#include - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - static struct option long_options[] = - { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} - }; - - c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); - if (c == EOF) - break; - - switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/gnu/usr.bin/pr/pr.1 b/gnu/usr.bin/pr/pr.1 deleted file mode 100644 index 814f4e1..0000000 --- a/gnu/usr.bin/pr/pr.1 +++ /dev/null @@ -1,103 +0,0 @@ -.TH PR 1L \" -*- nroff -*- -.SH NAME -pr \- convert text files for printing -.SH SYNOPSIS -.B pr -[+PAGE] [\-COLUMN] [\-abcdfFmrtv] [\-e[in-tab-char[in-tab-width]]] -[\-h header] [\-i[out-tab-char[out-tab-width]]] [\-l page-length] -[\-n[number-separator[digits]]] [\-o left-margin] -[\-s[column-separator]] [\-w page-width] [\-\-help] [\-\-version] [file...] -.SH DESCRIPTION -This manual page -documents the GNU version of -.BR pr . -.B pr -prints on the standard output a paginated and optionally multicolumn -copy of the text files given on the command line, or of the standard -input if no files are given or when the file name `\-' is encountered. -Form feeds in the input cause page breaks in the output. -.SS OPTIONS -.TP -.I \+PAGE -Begin printing with page \fIPAGE\fP. -.TP -.I \-COLUMN -Produce \fICOLUMN\fP-column output and print columns down. The column -width is automatically decreased as \fICOLUMN\fP increases; unless you -use the \fI\-w\fP option to increase the page width as well, this -option might cause some columns to be truncated. -.TP -.I \-a -Print columns across rather than down. -.TP -.I \-b -Balance columns on the last page. -.TP -.I \-c -Print control characters using hat notation (e.g., `^G'); print other -unprintable characters in octal backslash notation. -.TP -.I \-d -Double space the output. -.TP -.I "\-e[in-tab-char[in-tab-width]]" -Expand tabs to spaces on input. Optional argument \fIin-tab-char\fP -is the input tab character, default tab. Optional argument -\fIin-tab-width\fP is the input tab character's width, default 8. -.TP -.I "\-F, \-f" -Use a formfeed instead of newlines to separate output pages. -.TP -.I "\-h header" -Replace the filename in the header with the string \fIheader\fP. -.TP -.I "\-\-help" -Print a usage message and exit with a non-zero status. -.TP -.I "\-i[out-tab-char[out-tab-width]]" -Replace spaces with tabs on output. Optional argument -\fIout-tab-char\fP is the output tab character, default tab. -Optional argument \fIout-tab-width\fP is the output tab character's -width, default 8. -.TP -.I "\-l page-length" -Set the page length to \fIpage-length\fP lines. The default is 66. -If \fIpage-length\fP is less than 10, the headers and footers are -omitted, as if the \fI\-t\fP option had been given. -.TP -.I \-m -Print all files in parallel, one in each column. -.TP -.I "\-n[number-separator[digits]]" -Precede each column with a line number; with parallel files, precede -each line with a line number. Optional argument -\fInumber-separator\fP is the character to print after each number, -default tab. Optional argument \fIdigits\fP is the number of digits -per line number, default 5. -.TP -.I "\-o left-margin" -Offset each line with a margin \fIleft-margin\fP spaces wide. The -total page width is this offset plus the width set with the \fI\-w\fP -option. -.TP -.I \-r -Do not print a warning message when an argument file cannot be opened. -Failure to open a file still makes the exit status nonzero, however. -.TP -.I "\-s[column-separator]" -Separate columns by the single character \fIcolumn-separator\fP, -default tab, instead of spaces. -.TP -.I \-t -Do not print the 5-line header and the 5-line trailer that are -normally on each page, and do not fill out the bottoms of pages (with -blank lines or formfeeds). -.TP -.I \-v -Print unprintable characters in octal backslash notation. -.TP -.I "\-\-version" -Print version information on standard output then exit. -.TP -.I "\-w page-width" -Set the page width to \fIpage-width\fP columns. The default is 72. diff --git a/gnu/usr.bin/pr/pr.c b/gnu/usr.bin/pr/pr.c deleted file mode 100644 index 8ecc2c6..0000000 --- a/gnu/usr.bin/pr/pr.c +++ /dev/null @@ -1,1920 +0,0 @@ -/* pr -- convert text files for printing. - Copyright (C) 1988, 1991 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Author: Pete TerMaat. */ - -/* Things to watch: Sys V screws up on ... - pr -n -3 -s: /usr/dict/words - pr -m -o10 -n /usr/dict/words{,,,} - pr -6 -a -n -o5 /usr/dict/words - - Ideas: - - Keep a things_to_do list of functions to call when we know we have - something to print. Cleaner than current series of checks. - - Improve the printing of control prefixes. - - - Options: - - +PAGE Begin output at page PAGE of the output. - - -COLUMN Produce output that is COLUMN columns wide and print - columns down. - - -a Print columns across rather than down. The input - one - two - three - four - will be printed as - one two three - four - - -b Balance columns on the last page. - - -c Print unprintable characters as control prefixes. - Control-g is printed as ^G. - - -d Double space the output. - - -e[c[k]] Expand tabs to spaces on input. Optional argument C - is the input tab character. (Default is `\t'.) Optional - argument K is the input tab character's width. (Default is 8.) - - -F - -f Use formfeeds instead of newlines to separate pages. - - -h header Replace the filename in the header with the string HEADER. - - -i[c[k]] Replace spaces with tabs on output. Optional argument - C is the output tab character. (Default is `\t'.) Optional - argument K is the output tab character's width. (Default - is 8.) - - -l lines Set the page length to LINES. Default is 66. - - -m Print files in parallel. - - -n[c[k]] Precede each column with a line number. - (With parallel files, precede each line with a line - number.) Optional argument C is the character to print - after each number. (Default `\t'.) Optional argument - K is the number of digits per line number. (Default 5.) - - -o offset Offset each line with a margin OFFSET spaces wide. - Total page width is the size of this offset plus the - width set with `-w'. - - -r Ignore files that can't be opened. - - -s[c] Separate each line with a character. Optional argument C is - the character to be used. Default is `\t'. - - -t Do not print headers or footers. - - -v Print unprintable characters as escape sequences. - Control-G becomes \007. - - -w width Set the page width to WIDTH characters. */ - - -#ifdef HAVE_CONFIG_H -#if defined (CONFIG_BROKETS) -/* We use instead of "config.h" so that a compilation - using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h - (which it would do because it found this file in $srcdir). */ -#include -#else -#include "config.h" -#endif -#endif - -#include -#include -#include -#include -#include "system.h" -#include "version.h" - -char *xmalloc (); -char *xrealloc (); -void error (); - -static int char_to_clump (); -static int read_line (); -static int print_page (); -static int print_stored (); -static int open_file (); -static int skip_to_page (); -static void getoptarg (); -static void usage (); -static void print_files (); -static void init_header (); -static void init_store_cols (); -static void store_columns (); -static void balance (); -static void store_char (); -static void pad_down (); -static void read_rest_of_line (); -static void print_char (); -static void cleanup (); - -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif - -/* Used with start_position in the struct COLUMN described below. - If start_position == ANYWHERE, we aren't truncating columns and - can begin printing a column anywhere. Otherwise we must pad to - the horizontal position start_position. */ -#define ANYWHERE 0 - -/* Each column has one of these structures allocated for it. - If we're only dealing with one file, fp is the same for all - columns. - - The general strategy is to spend time setting up these column - structures (storing columns if necessary), after which printing - is a matter of flitting from column to column and calling - print_func. - - Parallel files, single files printing across in multiple - columns, and single files printing down in multiple columns all - fit the same printing loop. - - print_func Function used to print lines in this column. - If we're storing this column it will be - print_stored(), Otherwise it will be read_line(). - - char_func Function used to process characters in this column. - If we're storing this column it will be store_char(), - otherwise it will be print_char(). - - current_line Index of the current entry in line_vector, which - contains the index of the first character of the - current line in buff[]. - - lines_stored Number of lines in this column which are stored in - buff. - - lines_to_print If we're storing this column, lines_to_print is - the number of stored_lines which remain to be - printed. Otherwise it is the number of lines - we can print without exceeding lines_per_body. - - start_position The horizontal position we want to be in before we - print the first character in this column. - - numbered True means precede this column with a line number. */ - -struct COLUMN -{ - FILE *fp; /* Input stream for this column. */ - char *name; /* File name. */ - enum - { - OPEN, - ON_HOLD, /* Hit a form feed. */ - CLOSED - } status; /* Status of the file pointer. */ - int (*print_func) (); /* Func to print lines in this col. */ - void (*char_func) (); /* Func to print/store chars in this col. */ - int current_line; /* Index of current place in line_vector. */ - int lines_stored; /* Number of lines stored in buff. */ - int lines_to_print; /* No. lines stored or space left on page. */ - int start_position; /* Horizontal position of first char. */ - int numbered; -}; - -typedef struct COLUMN COLUMN; - -#define NULLCOL (COLUMN *)0 - -/* The name under which this program was invoked. */ -char *program_name; - -/* All of the columns to print. */ -static COLUMN *column_vector; - -/* When printing a single file in multiple downward columns, - we store the leftmost columns contiguously in buff. - To print a line from buff, get the index of the first char - from line_vector[i], and print up to line_vector[i + 1]. */ -static char *buff; - -/* Index of the position in buff where the next character - will be stored. */ -static int buff_current; - -/* The number of characters in buff. - Used for allocation of buff and to detect overflow of buff. */ -static int buff_allocated; - -/* Array of indices into buff. - Each entry is an index of the first character of a line. - This is used when storing lines to facilitate shuffling when - we do column balancing on the last page. */ -static int *line_vector; - -/* Array of horizonal positions. - For each line in line_vector, end_vector[line] is the horizontal - position we are in after printing that line. We keep track of this - so that we know how much we need to pad to prepare for the next - column. */ -static int *end_vector; - -/* (-m) True means we're printing multiple files in parallel. */ -static int parallel_files = FALSE; - -/* (-[0-9]+) True means we're given an option explicitly specifying - number of columns. Used to detect when this option is used with -m. */ -static int explicit_columns = FALSE; - -/* (-t) True means we're printing headers and footers. */ -static int extremities = TRUE; - -/* True means we need to print a header as soon as we know we've got input - to print after it. */ -static int print_a_header; - -/* (-h) True means we're using the standard header rather than a - customized one specified by the -h flag. */ -static int standard_header = TRUE; - -/* (-f) True means use formfeeds instead of newlines to separate pages. */ -static int use_form_feed = FALSE; - -/* True means we have read the standard input. */ -static int have_read_stdin = FALSE; - -/* True means the -a flag has been given. */ -static int print_across_flag = FALSE; - -/* True means we're printing one file in multiple (>1) downward columns. */ -static int storing_columns = TRUE; - -/* (-b) True means balance columns on the last page as Sys V does. */ -static int balance_columns = FALSE; - -/* (-l) Number of lines on a page, including header and footer lines. */ -static int lines_per_page = 66; - -/* Number of lines in the header and footer can be reset to 0 using - the -t flag. */ -static int lines_per_header = 5; -static int lines_per_body; -static int lines_per_footer = 5; - -/* (-w) Width in characters of the page. Does not include the width of - the margin. */ -static int chars_per_line = 72; - -/* Number of characters in a column. Based on the gutter and page widths. */ -static int chars_per_column; - -/* (-e) True means convert tabs to spaces on input. */ -static int untabify_input = FALSE; - -/* (-e) The input tab character. */ -static char input_tab_char = '\t'; - -/* (-e) Tabstops are at chars_per_tab, 2*chars_per_tab, 3*chars_per_tab, ... - where the leftmost column is 1. */ -static int chars_per_input_tab = 8; - -/* (-i) True means convert spaces to tabs on output. */ -static int tabify_output = FALSE; - -/* (-i) The output tab character. */ -static char output_tab_char = '\t'; - -/* (-i) The width of the output tab. */ -static int chars_per_output_tab = 8; - -/* Keeps track of pending white space. When we hit a nonspace - character after some whitespace, we print whitespace, tabbing - if necessary to get to output_position + spaces_not_printed. */ -static int spaces_not_printed; - -/* Number of spaces between columns (though tabs can be used when possible to - use up the equivalent amount of space). Not sure if this is worth making - a flag for. BSD uses 0, Sys V uses 1. Sys V looks better. */ -static int chars_per_gutter = 1; - -/* (-o) Number of spaces in the left margin (tabs used when possible). */ -static int chars_per_margin = 0; - -/* Position where the next character will fall. - Leftmost position is 0 + chars_per_margin. - Rightmost position is chars_per_margin + chars_per_line - 1. - This is important for converting spaces to tabs on output. */ -static int output_position; - -/* Horizontal position relative to the current file. - (output_position depends on where we are on the page; - input_position depends on where we are in the file.) - Important for converting tabs to spaces on input. */ -static int input_position; - -/* Count number of failed opens so we can exit with non-zero - status if there were any. */ -static int failed_opens = 0; - -/* The horizontal position we'll be at after printing a tab character - of width c_ from the position h_. */ -#define pos_after_tab(c_, h_) h_ - h_ % c_ + c_ - -/* The number of spaces taken up if we print a tab character with width - c_ from position h_. */ -#define tab_width(c_, h_) - h_ % c_ + c_ - -/* (-NNN) Number of columns of text to print. */ -static int columns = 1; - -/* (+NNN) Page number on which to begin printing. */ -static int first_page_number = 1; - -/* Number of files open (not closed, not on hold). */ -static int files_ready_to_read = 0; - -/* Current page number. Displayed in header. */ -static int page_number; - -/* Current line number. Displayed when -n flag is specified. - - When printing files in parallel (-m flag), line numbering is as follows: - 1 foo goo moo - 2 hoo too zoo - - When printing files across (-a flag), ... - 1 foo 2 moo 3 goo - 4 hoo 3 too 6 zoo - - Otherwise, line numbering is as follows: - 1 foo 3 goo 5 too - 2 moo 4 hoo 6 zoo */ -static int line_number; - -/* (-n) True means lines should be preceded by numbers. */ -static int numbered_lines = FALSE; - -/* (-n) Character which follows each line number. */ -static char number_separator = '\t'; - -/* (-n) Width in characters of a line number. */ -static int chars_per_number = 5; - -/* Used when widening the first column to accommodate numbers -- only - needed when printing files in parallel. Includes width of both the - number and the number_separator. */ -static int number_width; - -/* Buffer sprintf uses to format a line number. */ -static char *number_buff; - -/* (-v) True means unprintable characters are printed as escape sequences. - control-g becomes \007. */ -static int use_esc_sequence = FALSE; - -/* (-c) True means unprintable characters are printed as control prefixes. - control-g becomes ^G. */ -static int use_cntrl_prefix = FALSE; - -/* (-d) True means output is double spaced. */ -static int double_space = FALSE; - -/* Number of files opened initially in init_files. Should be 1 - unless we're printing multiple files in parallel. */ -static int total_files = 0; - -/* (-r) True means don't complain if we can't open a file. */ -static int ignore_failed_opens = FALSE; - -/* (-s) True means we separate columns with a specified character. */ -static int use_column_separator = FALSE; - -/* Character used to separate columns if the the -s flag has been specified. */ -static char column_separator = '\t'; - -/* Number of separator characters waiting to be printed as soon as we - know that we have any input remaining to be printed. */ -static int separators_not_printed; - -/* Position we need to pad to, as soon as we know that we have input - remaining to be printed. */ -static int padding_not_printed; - -/* True means we should pad the end of the page. Remains false until we - know we have a page to print. */ -static int pad_vertically; - -/* (-h) String of characters used in place of the filename in the header. */ -static char *custom_header; - -/* String containing the date, filename or custom header, and "Page ". */ -static char *header; - -static int *clump_buff; - -/* True means we truncate lines longer than chars_per_column. */ -static int truncate_lines = FALSE; - -/* If non-zero, display usage information and exit. */ -static int show_help; - -/* If non-zero, print the version on standard output then exit. */ -static int show_version; - -static struct option const long_options[] = -{ - {"help", no_argument, &show_help, 1}, - {"version", no_argument, &show_version, 1}, - {0, 0, 0, 0} -}; - -/* Return the number of columns that have either an open file or - stored lines. */ - -static int -cols_ready_to_print () -{ - COLUMN *q; - int i; - int n; - - n = 0; - for (q = column_vector, i = 0; i < columns; ++q, ++i) - if (q->status == OPEN || - (storing_columns && q->lines_stored > 0 && q->lines_to_print > 0)) - ++n; - return n; -} - -void -main (argc, argv) - int argc; - char **argv; -{ - int c; - int accum = 0; - int n_files; - char **file_names; - - program_name = argv[0]; - - n_files = 0; - file_names = (argc > 1 - ? (char **) xmalloc ((argc - 1) * sizeof (char *)) - : NULL); - - while (1) - { - c = getopt_long (argc, argv, - "-0123456789abcde::fFh:i::l:mn::o:rs::tvw:", - long_options, (int *) 0); - if (c == 1) /* Non-option argument. */ - { - char *s; - s = optarg; - if (*s == '+') - { - ++s; - if (!ISDIGIT (*s)) - { - error (0, 0, "`+' requires a numeric argument"); - usage (2); - } - /* FIXME: use strtol */ - first_page_number = atoi (s); - } - else - { - file_names[n_files++] = optarg; - } - } - else - { - if (ISDIGIT (c)) - { - accum = accum * 10 + c - '0'; - continue; - } - else - { - if (accum > 0) - { - columns = accum; - explicit_columns = TRUE; - accum = 0; - } - } - } - - if (c == 1) - continue; - - if (c == EOF) - break; - - switch (c) - { - case 0: /* getopt long option */ - break; - - case 'a': - print_across_flag = TRUE; - storing_columns = FALSE; - break; - case 'b': - balance_columns = TRUE; - break; - case 'c': - use_cntrl_prefix = TRUE; - break; - case 'd': - double_space = TRUE; - break; - case 'e': - if (optarg) - getoptarg (optarg, 'e', &input_tab_char, - &chars_per_input_tab); - /* Could check tab width > 0. */ - untabify_input = TRUE; - break; - case 'f': - case 'F': - use_form_feed = TRUE; - break; - case 'h': - custom_header = optarg; - standard_header = FALSE; - break; - case 'i': - if (optarg) - getoptarg (optarg, 'i', &output_tab_char, - &chars_per_output_tab); - /* Could check tab width > 0. */ - tabify_output = TRUE; - break; - case 'l': - lines_per_page = atoi (optarg); - break; - case 'm': - parallel_files = TRUE; - storing_columns = FALSE; - break; - case 'n': - numbered_lines = TRUE; - if (optarg) - getoptarg (optarg, 'n', &number_separator, - &chars_per_number); - break; - case 'o': - chars_per_margin = atoi (optarg); - break; - case 'r': - ignore_failed_opens = TRUE; - break; - case 's': - use_column_separator = TRUE; - if (optarg) - { - char *s; - s = optarg; - column_separator = *s; - if (*++s) - { - fprintf (stderr, "\ -%s: extra characters in the argument to the `-s' option: `%s'\n", - program_name, s); - usage (2); - } - } - break; - case 't': - extremities = FALSE; - break; - case 'v': - use_esc_sequence = TRUE; - break; - case 'w': - chars_per_line = atoi (optarg); - break; - default: - usage (2); - break; - } - } - - if (show_version) - { - printf ("%s\n", version_string); - exit (0); - } - - if (show_help) - usage (0); - - if (parallel_files && explicit_columns) - error (1, 0, - "Cannot specify number of columns when printing in parallel."); - - if (parallel_files && print_across_flag) - error (1, 0, - "Cannot specify both printing across and printing in parallel."); - - for ( ; optind < argc; optind++) - { - file_names[n_files++] = argv[optind]; - } - - if (n_files == 0) - { - /* No file arguments specified; read from standard input. */ - print_files (0, (char **) 0); - } - else - { - if (parallel_files) - print_files (n_files, file_names); - else - { - int i; - for (i=0; i 0) - exit(1); - exit (0); -} - -/* Parse options of the form -scNNN. - - Example: -nck, where 'n' is the option, c is the optional number - separator, and k is the optional width of the field used when printing - a number. */ - -static void -getoptarg (arg, switch_char, character, number) - char *arg, switch_char, *character; - int *number; -{ - if (!ISDIGIT (*arg)) - *character = *arg++; - if (*arg) - { - if (ISDIGIT (*arg)) - *number = atoi (arg); - else - { - fprintf (stderr, "\ -%s: extra characters in the argument to the `-%c' option: `%s'\n", - program_name, switch_char, arg); - usage (2); - } - } -} - -/* Set parameters related to formatting. */ - -static void -init_parameters (number_of_files) - int number_of_files; -{ - int chars_used_by_number = 0; - - lines_per_body = lines_per_page - lines_per_header - lines_per_footer; - if (lines_per_body <= 0) - extremities = FALSE; - if (extremities == FALSE) - lines_per_body = lines_per_page; - - if (double_space) - lines_per_body = lines_per_body / 2; - - /* If input is stdin, cannot print parallel files. BSD dumps core - on this. */ - if (number_of_files == 0) - parallel_files = FALSE; - - if (parallel_files) - columns = number_of_files; - - /* Tabification is assumed for multiple columns. */ - if (columns > 1) - { - if (!use_column_separator) - truncate_lines = TRUE; - - untabify_input = TRUE; - tabify_output = TRUE; - } - else - storing_columns = FALSE; - - if (numbered_lines) - { - if (number_separator == input_tab_char) - { - number_width = chars_per_number + - tab_width (chars_per_input_tab, - (chars_per_margin + chars_per_number)); - } - else - number_width = chars_per_number + 1; - /* The number is part of the column width unless we are - printing files in parallel. */ - if (parallel_files) - chars_used_by_number = number_width; - } - - chars_per_column = (chars_per_line - chars_used_by_number - - (columns - 1) * chars_per_gutter) / columns; - - if (chars_per_column < 1) - error (1, 0, "page width too narrow"); - - if (numbered_lines) - { - if (number_buff != (char *) 0) - free (number_buff); - number_buff = (char *) - xmalloc (2 * chars_per_number * sizeof (char)); - } - - /* Pick the maximum between the tab width and the width of an - escape sequence. */ - if (clump_buff != (int *) 0) - free (clump_buff); - clump_buff = (int *) xmalloc ((chars_per_input_tab > 4 - ? chars_per_input_tab : 4) * sizeof (int)); -} - -/* Open the necessary files, - maintaining a COLUMN structure for each column. - - With multiple files, each column p has a different p->fp. - With single files, each column p has the same p->fp. - Return 1 if (number_of_files > 0) and no files can be opened, - 0 otherwise. */ - -static int -init_fps (number_of_files, av) - int number_of_files; - char **av; -{ - int i, files_left; - COLUMN *p; - FILE *firstfp; - char *firstname; - - total_files = 0; - - if (column_vector != NULLCOL) - free ((char *) column_vector); - column_vector = (COLUMN *) xmalloc (columns * sizeof (COLUMN)); - - if (parallel_files) - { - files_left = number_of_files; - for (p = column_vector; files_left--; ++p, ++av) - { - if (open_file (*av, p) == 0) - { - --p; - --columns; - } - } - if (columns == 0) - return 1; - init_header ("", -1); - } - else - { - p = column_vector; - if (number_of_files > 0) - { - if (open_file (*av, p) == 0) - return 1; - init_header (*av, fileno (p->fp)); - } - else - { - p->name = "standard input"; - p->fp = stdin; - have_read_stdin = TRUE; - p->status = OPEN; - ++total_files; - init_header ("", -1); - } - - firstname = p->name; - firstfp = p->fp; - for (i = columns - 1, ++p; i; --i, ++p) - { - p->name = firstname; - p->fp = firstfp; - p->status = OPEN; - } - } - files_ready_to_read = total_files; - return 0; -} - -/* Determine print_func and char_func, the functions - used by each column for printing and/or storing. - - Determine the horizontal position desired when we begin - printing a column (p->start_position). */ - -static void -init_funcs () -{ - int i, h, h_next; - COLUMN *p; - - h = chars_per_margin; - - if (use_column_separator) - h_next = ANYWHERE; - else - { - /* When numbering lines of parallel files, we enlarge the - first column to accomodate the number. Looks better than - the Sys V approach. */ - if (parallel_files && numbered_lines) - h_next = h + chars_per_column + number_width; - else - h_next = h + chars_per_column; - } - - /* This loop takes care of all but the rightmost column. */ - - for (p = column_vector, i = 1; i < columns; ++p, ++i) - { - if (storing_columns) /* One file, multi columns down. */ - { - p->char_func = store_char; - p->print_func = print_stored; - } - else - /* One file, multi columns across; or parallel files. */ - { - p->char_func = print_char; - p->print_func = read_line; - } - - /* Number only the first column when printing files in - parallel. */ - p->numbered = numbered_lines && (!parallel_files || i == 1); - p->start_position = h; - - /* If we're using separators, all start_positions are - ANYWHERE, except the first column's start_position when - using a margin. */ - - if (use_column_separator) - { - h = ANYWHERE; - h_next = ANYWHERE; - } - else - { - h = h_next + chars_per_gutter; - h_next = h + chars_per_column; - } - } - - /* The rightmost column. - - Doesn't need to be stored unless we intend to balance - columns on the last page. */ - if (storing_columns && balance_columns) - { - p->char_func = store_char; - p->print_func = print_stored; - } - else - { - p->char_func = print_char; - p->print_func = read_line; - } - - p->numbered = numbered_lines && (!parallel_files || i == 1); - p->start_position = h; -} - -/* Open a file. Return nonzero if successful, zero if failed. */ - -static int -open_file (name, p) - char *name; - COLUMN *p; -{ - if (!strcmp (name, "-")) - { - p->name = "standard input"; - p->fp = stdin; - have_read_stdin = 1; - } - else - { - p->name = name; - p->fp = fopen (name, "r"); - } - if (p->fp == NULL) - { - ++failed_opens; - if (!ignore_failed_opens) - error (0, errno, "%s", name); - return 0; - } - p->status = OPEN; - ++total_files; - return 1; -} - -/* Close the file in P. - - If we aren't dealing with multiple files in parallel, we change - the status of all columns in the column list to reflect the close. */ - -static void -close_file (p) - COLUMN *p; -{ - COLUMN *q; - int i; - - if (p->status == CLOSED) - return; - if (ferror (p->fp)) - error (1, errno, "%s", p->name); - if (p->fp != stdin && fclose (p->fp) == EOF) - error (1, errno, "%s", p->name); - - if (!parallel_files) - { - for (q = column_vector, i = columns; i; ++q, --i) - { - q->status = CLOSED; - if (q->lines_stored == 0) - { - q->lines_to_print = 0; - } - } - } - else - { - p->status = CLOSED; - p->lines_to_print = 0; - } - - --files_ready_to_read; -} - -/* Put a file on hold until we start a new page, - since we've hit a form feed. - - If we aren't dealing with parallel files, we must change the - status of all columns in the column list. */ - -static void -hold_file (p) - COLUMN *p; -{ - COLUMN *q; - int i; - - if (!parallel_files) - for (q = column_vector, i = columns; i; ++q, --i) - q->status = ON_HOLD; - else - p->status = ON_HOLD; - p->lines_to_print = 0; - --files_ready_to_read; -} - -/* Undo hold_file -- go through the column list and change any - ON_HOLD columns to OPEN. Used at the end of each page. */ - -static void -reset_status () -{ - int i = columns; - COLUMN *p; - - for (p = column_vector; i; --i, ++p) - if (p->status == ON_HOLD) - { - p->status = OPEN; - files_ready_to_read++; - } -} - -/* Print a single file, or multiple files in parallel. - - Set up the list of columns, opening the necessary files. - Allocate space for storing columns, if necessary. - Skip to first_page_number, if user has asked to skip leading pages. - Determine which functions are appropriate to store/print lines - in each column. - Print the file(s). */ - -static void -print_files (number_of_files, av) - int number_of_files; - char **av; -{ - init_parameters (number_of_files); - if (init_fps (number_of_files, av)) - return; - if (storing_columns) - init_store_cols (); - - if (first_page_number > 1) - { - if (!skip_to_page (first_page_number)) - return; - else - page_number = first_page_number; - } - else - page_number = 1; - - init_funcs (); - - line_number = 1; - while (print_page ()) - ; -} - -/* Generous estimate of number of characters taken up by "Jun 7 00:08 " and - "Page NNNNN". */ -#define CHARS_FOR_DATE_AND_PAGE 50 - -/* Initialize header information. - If DESC is non-negative, it is a file descriptor open to - FILENAME for reading. - - Allocate space for a header string, - Determine the time, insert file name or user-specified string. - - It might be nice to have a "blank headers" option, since - pr -h "" still prints the date and page number. */ - -static void -init_header (filename, desc) - char *filename; - int desc; -{ - int chars_per_header; - char *f = filename; - char *t, *middle; - struct stat st; - - if (filename == 0) - f = ""; - - /* If parallel files or standard input, use current time. */ - if (desc < 0 || !strcmp (filename, "-") || fstat (desc, &st)) - st.st_mtime = time ((time_t *) 0); - t = ctime (&st.st_mtime); - - t[16] = '\0'; /* Mark end of month and time string. */ - t[24] = '\0'; /* Mark end of year string. */ - - middle = standard_header ? f : custom_header; - - chars_per_header = strlen (middle) + CHARS_FOR_DATE_AND_PAGE + 1; - if (header != (char *) 0) - free (header); - header = (char *) xmalloc (chars_per_header * sizeof (char)); - - sprintf (header, "%s %s %s Page", &t[4], &t[20], middle); -} - -/* Set things up for printing a page - - Scan through the columns ... - Determine which are ready to print - (i.e., which have lines stored or open files) - Set p->lines_to_print appropriately - (to p->lines_stored if we're storing, or lines_per_body - if we're reading straight from the file) - Keep track of this total so we know when to stop printing */ - -static void -init_page () -{ - int j; - COLUMN *p; - - if (storing_columns) - { - store_columns (); - for (j = columns - 1, p = column_vector; j; --j, ++p) - { - p->lines_to_print = p->lines_stored; - } - - /* Last column. */ - if (balance_columns) - { - p->lines_to_print = p->lines_stored; - } - /* Since we're not balancing columns, we don't need to store - the rightmost column. Read it straight from the file. */ - else - { - if (p->status == OPEN) - { - p->lines_to_print = lines_per_body; - } - else - p->lines_to_print = 0; - } - } - else - for (j = columns, p = column_vector; j; --j, ++p) - if (p->status == OPEN) - { - p->lines_to_print = lines_per_body; - } - else - p->lines_to_print = 0; -} - -/* Print one page. - - As long as there are lines left on the page and columns ready to print, - Scan across the column list - if the column has stored lines or the file is open - pad to the appropriate spot - print the column - pad the remainder of the page with \n or \f as requested - reset the status of all files -- any files which where on hold because - of formfeeds are now put back into the lineup. */ - -static int -print_page () -{ - int j; - int lines_left_on_page; - COLUMN *p; - - /* Used as an accumulator (with | operator) of successive values of - pad_vertically. The trick is to set pad_vertically - to zero before each run through the inner loop, then after that - loop, it tells us whether a line was actually printed (whether a - newline needs to be output -- or two for double spacing). But those - values have to be accumulated (in pv) so we can invoke pad_down - properly after the outer loop completes. */ - int pv; - - init_page (); - - if (cols_ready_to_print () == 0) - return FALSE; - - if (extremities) - print_a_header = TRUE; - - /* Don't pad unless we know a page was printed. */ - pad_vertically = FALSE; - pv = FALSE; - - lines_left_on_page = lines_per_body; - if (double_space) - lines_left_on_page *= 2; - - while (lines_left_on_page > 0 && cols_ready_to_print () > 0) - { - output_position = 0; - spaces_not_printed = 0; - separators_not_printed = 0; - pad_vertically = FALSE; - - for (j = 1, p = column_vector; j <= columns; ++j, ++p) - { - input_position = 0; - if (p->lines_to_print > 0) - { - padding_not_printed = p->start_position; - - if (!(p->print_func) (p)) - read_rest_of_line (p); - pv |= pad_vertically; - - if (use_column_separator) - ++separators_not_printed; - - --p->lines_to_print; - if (p->lines_to_print <= 0) - { - if (cols_ready_to_print () <= 0) - break; - } - } - } - - if (pad_vertically) - { - putchar ('\n'); - --lines_left_on_page; - } - - if (double_space && pv && extremities) - { - putchar ('\n'); - --lines_left_on_page; - } - } - - pad_vertically = pv; - - if (pad_vertically && extremities) - pad_down (lines_left_on_page + lines_per_footer); - - reset_status (); /* Change ON_HOLD to OPEN. */ - - return TRUE; /* More pages to go. */ -} - -/* Allocate space for storing columns. - - This is necessary when printing multiple columns from a single file. - Lines are stored consecutively in buff, separated by '\0'. - (We can't use a fixed offset since with the '-s' flag lines aren't - truncated.) - - We maintain a list (line_vector) of pointers to the beginnings - of lines in buff. We allocate one more than the number of lines - because the last entry tells us the index of the last character, - which we need to know in order to print the last line in buff. */ - -static void -init_store_cols () -{ - int total_lines = lines_per_body * columns; - int chars_if_truncate = total_lines * (chars_per_column + 1); - - if (line_vector != (int *) 0) - free ((int *) line_vector); - line_vector = (int *) xmalloc ((total_lines + 1) * sizeof (int *)); - - if (end_vector != (int *) 0) - free ((int *) end_vector); - end_vector = (int *) xmalloc (total_lines * sizeof (int *)); - - if (buff != (char *) 0) - free (buff); - buff_allocated = use_column_separator ? 2 * chars_if_truncate - : chars_if_truncate; /* Tune this. */ - buff = (char *) xmalloc (buff_allocated * sizeof (char)); -} - -/* Store all but the rightmost column. - (Used when printing a single file in multiple downward columns) - - For each column - set p->current_line to be the index in line_vector of the - first line in the column - For each line in the column - store the line in buff - add to line_vector the index of the line's first char - buff_start is the index in buff of the first character in the - current line. */ - -static void -store_columns () -{ - int i, j; - int line = 0; - int buff_start; - int last_col; /* The rightmost column which will be saved in buff */ - COLUMN *p; - - buff_current = 0; - buff_start = 0; - - if (balance_columns) - last_col = columns; - else - last_col = columns - 1; - - for (i = 1, p = column_vector; i <= last_col; ++i, ++p) - p->lines_stored = 0; - - for (i = 1, p = column_vector; i <= last_col && files_ready_to_read; - ++i, ++p) - { - p->current_line = line; - for (j = lines_per_body; j && files_ready_to_read; --j) - - if (p->status == OPEN) /* Redundant. Clean up. */ - { - input_position = 0; - - if (!read_line (p, i)) - read_rest_of_line (p); - - if (p->status == OPEN - || buff_start != buff_current) - { - ++p->lines_stored; - line_vector[line] = buff_start; - end_vector[line++] = input_position; - buff_start = buff_current; - } - } - } - - /* Keep track of the location of the last char in buff. */ - line_vector[line] = buff_start; - - if (balance_columns && p->lines_stored != lines_per_body) - balance (line); -} - -static void -balance (total_stored) - int total_stored; -{ - COLUMN *p; - int i, lines; - int first_line = 0; - - for (i = 1, p = column_vector; i <= columns; ++i, ++p) - { - lines = total_stored / columns; - if (i <= total_stored % columns) - ++lines; - - p->lines_stored = lines; - p->current_line = first_line; - - first_line += lines; - } -} - -/* Store a character in the buffer. */ - -static void -store_char (c) - int c; -{ - if (buff_current >= buff_allocated) - { - /* May be too generous. */ - buff_allocated = 2 * buff_allocated; - buff = (char *) xrealloc (buff, buff_allocated * sizeof (char)); - } - buff[buff_current++] = (char) c; -} - -static void -number (p) - COLUMN *p; -{ - int i; - char *s; - - sprintf (number_buff, "%*d", chars_per_number, line_number++); - s = number_buff; - for (i = chars_per_number; i > 0; i--) - (p->char_func) ((int) *s++); - - if (number_separator == input_tab_char) - { - i = number_width - chars_per_number; - while (i-- > 0) - (p->char_func) ((int) ' '); - } - else - (p->char_func) ((int) number_separator); - - if (truncate_lines && !parallel_files) - input_position += number_width; -} - -/* Print (or store) padding until the current horizontal position - is position. */ - -static void -pad_across_to (position) - int position; -{ - register int h = output_position; - - if (tabify_output) - spaces_not_printed = position - output_position; - else - { - while (++h <= position) - putchar (' '); - output_position = position; - } -} - -/* Pad to the bottom of the page. - - If the user has requested a formfeed, use one. - Otherwise, use newlines. */ - -static void -pad_down (lines) - int lines; -{ - register int i; - - if (use_form_feed) - putchar ('\f'); - else - for (i = lines; i; --i) - putchar ('\n'); -} - -/* Read the rest of the line. - - Read from the current column's file until an end of line is - hit. Used when we've truncated a line and we no longer need - to print or store its characters. */ - -static void -read_rest_of_line (p) - COLUMN *p; -{ - register int c; - FILE *f = p->fp; - - while ((c = getc (f)) != '\n') - { - if (c == '\f') - { - hold_file (p); - break; - } - else if (c == EOF) - { - close_file (p); - break; - } - } -} - -/* If we're tabifying output, - - When print_char encounters white space it keeps track - of our desired horizontal position and delays printing - until this function is called. */ - -static void -print_white_space () -{ - register int h_new; - register int h_old = output_position; - register int goal = h_old + spaces_not_printed; - - while (goal - h_old > 1 - && (h_new = pos_after_tab (chars_per_output_tab, h_old)) <= goal) - { - putchar (output_tab_char); - h_old = h_new; - } - while (++h_old <= goal) - putchar (' '); - - output_position = goal; - spaces_not_printed = 0; -} - -/* Print column separators. - - We keep a count until we know that we'll be printing a line, - then print_separators() is called. */ - -static void -print_separators () -{ - for (; separators_not_printed > 0; --separators_not_printed) - print_char (column_separator); -} - -/* Print (or store, depending on p->char_func) a clump of N - characters. */ - -static void -print_clump (p, n, clump) - COLUMN *p; - int n; - int *clump; -{ - while (n--) - (p->char_func) (*clump++); -} - -/* Print a character. - - If we're tabifying, all tabs have been converted to spaces by - process_char(). Keep a count of consecutive spaces, and when - a nonspace is encountered, call print_white_space() to print the - required number of tabs and spaces. */ - -static void -print_char (c) - int c; -{ - if (tabify_output) - { - if (c == ' ') - { - ++spaces_not_printed; - return; - } - else if (spaces_not_printed > 0) - print_white_space (); - - /* Nonprintables are assumed to have width 0, except '\b'. */ - if (!ISPRINT (c)) - { - if (c == '\b') - --output_position; - } - else - ++output_position; - } - putchar (c); -} - -/* Skip to page PAGE before printing. */ - -static int -skip_to_page (page) - int page; -{ - int n, i, j; - COLUMN *p; - - for (n = 1; n < page; ++n) - { - for (i = 1; i <= lines_per_body; ++i) - { - for (j = 1, p = column_vector; j <= columns; ++j, ++p) - read_rest_of_line (p); - } - reset_status (); - } - return files_ready_to_read > 0; -} - -/* Print a header. - - Formfeeds are assumed to use up two lines at the beginning of - the page. */ - -static void -print_header () -{ - if (!use_form_feed) - fprintf (stdout, "\n\n"); - - output_position = 0; - pad_across_to (chars_per_margin); - print_white_space (); - - fprintf (stdout, "%s %d\n\n\n", header, page_number++); - - print_a_header = FALSE; - output_position = 0; -} - -/* Print (or store, if p->char_func is store_char()) a line. - - Read a character to determine whether we have a line or not. - (We may hit EOF, \n, or \f) - - Once we know we have a line, - set pad_vertically = TRUE, meaning it's safe - to pad down at the end of the page, since we do have a page. - print a header if needed. - pad across to padding_not_printed if needed. - print any separators which need to be printed. - print a line number if it needs to be printed. - - Print the clump which corresponds to the first character. - - Enter a loop and keep printing until an end of line condition - exists, or until we exceed chars_per_column. - - Return FALSE if we exceed chars_per_column before reading - an end of line character, TRUE otherwise. */ - -static int -read_line (p) - COLUMN *p; -{ - register int c, chars; - int last_input_position; - - c = getc (p->fp); - - last_input_position = input_position; - switch (c) - { - case '\f': - hold_file (p); - return TRUE; - case EOF: - close_file (p); - return TRUE; - case '\n': - break; - default: - chars = char_to_clump (c); - } - - if (truncate_lines && input_position > chars_per_column) - { - input_position = last_input_position; - return FALSE; - } - - if (p->char_func != store_char) - { - pad_vertically = TRUE; - - if (print_a_header) - print_header (); - - if (padding_not_printed != ANYWHERE) - { - pad_across_to (padding_not_printed); - padding_not_printed = ANYWHERE; - } - - if (use_column_separator) - print_separators (); - } - - if (p->numbered) - number (p); - - if (c == '\n') - return TRUE; - - print_clump (p, chars, clump_buff); - - for (;;) - { - c = getc (p->fp); - - switch (c) - { - case '\n': - return TRUE; - case '\f': - hold_file (p); - return TRUE; - case EOF: - close_file (p); - return TRUE; - } - - last_input_position = input_position; - chars = char_to_clump (c); - if (truncate_lines && input_position > chars_per_column) - { - input_position = last_input_position; - return FALSE; - } - - print_clump (p, chars, clump_buff); - } -} - -/* Print a line from buff. - - If this function has been called, we know we have something to - print. Therefore we set pad_vertically to TRUE, print - a header if necessary, pad across if necessary, and print - separators if necessary. - - Return TRUE, meaning there is no need to call read_rest_of_line. */ - -static int -print_stored (p) - COLUMN *p; -{ - int line = p->current_line++; - register char *first = &buff[line_vector[line]]; - register char *last = &buff[line_vector[line + 1]]; - - pad_vertically = TRUE; - - if (print_a_header) - print_header (); - - if (padding_not_printed != ANYWHERE) - { - pad_across_to (padding_not_printed); - padding_not_printed = ANYWHERE; - } - - if (use_column_separator) - print_separators (); - - while (first != last) - print_char (*first++); - - if (spaces_not_printed == 0) - output_position = p->start_position + end_vector[line]; - - return TRUE; -} - -/* Convert a character to the proper format and return the number of - characters in the resulting clump. Increment input_position by - the width of the clump. - - Tabs are converted to clumps of spaces. - Nonprintable characters may be converted to clumps of escape - sequences or control prefixes. - - Note: the width of a clump is not necessarily equal to the number of - characters in clump_buff. (e.g, the width of '\b' is -1, while the - number of characters is 1.) */ - -static int -char_to_clump (c) - int c; -{ - register int *s = clump_buff; - register int i; - char esc_buff[4]; - int width; - int chars; - - if (c == input_tab_char) - { - width = tab_width (chars_per_input_tab, input_position); - - if (untabify_input) - { - for (i = width; i; --i) - *s++ = ' '; - chars = width; - } - else - { - *s = c; - chars = 1; - } - - } - else if (!ISPRINT (c)) - { - if (use_esc_sequence) - { - width = 4; - chars = 4; - *s++ = '\\'; - sprintf (esc_buff, "%03o", c); - for (i = 0; i <= 2; ++i) - *s++ = (int) esc_buff[i]; - } - else if (use_cntrl_prefix) - { - if (c < 0200) - { - width = 2; - chars = 2; - *s++ = '^'; - *s++ = c ^ 0100; - } - else - { - width = 4; - chars = 4; - *s++ = '\\'; - sprintf (esc_buff, "%03o", c); - for (i = 0; i <= 2; ++i) - *s++ = (int) esc_buff[i]; - } - } - else if (c == '\b') - { - width = -1; - chars = 1; - *s = c; - } - else - { - width = 0; - chars = 1; - *s = c; - } - } - else - { - width = 1; - chars = 1; - *s = c; - } - - input_position += width; - return chars; -} - -/* We've just printed some files and need to clean up things before - looking for more options and printing the next batch of files. - - Free everything we've xmalloc'ed, except `header'. */ - -static void -cleanup () -{ - if (number_buff) - free (number_buff); - if (clump_buff) - free (clump_buff); - if (column_vector) - free (column_vector); - if (line_vector) - free (line_vector); - if (end_vector) - free (end_vector); - if (buff) - free (buff); -} - -/* Complain, print a usage message, and die. */ - -static void -usage (status) - int status; -{ - if (status != 0) - fprintf (stderr, "Try `%s --help' for more information.\n", - program_name); - else - { - printf ("\ -Usage: %s [OPTION]... [FILE]...\n\ -", - program_name); - printf ("\ -\n\ - +PAGE begin printing with page PAGE\n\ - -COLUMN produce COLUMN-column output and print columns down\n\ - -F, -f simulate formfeed with newlines on output\n\ - -a print columns across rather than down\n\ - -b balance columns on the last page\n\ - -c use hat notation (^G) and octal backslash notation\n\ - -d double space the output\n\ - -e[CHAR[WIDTH]] expand input CHARs (TABs) to tab WIDTH (8)\n\ - -h HEADER use HEADER instead of filename in page headers\n\ - -i[CHAR[WIDTH]] replace spaces with CHARs (TABs) to tab WIDTH (8)\n\ - -l PAGE_LENGTH set the page length to PAGE_LENGTH (66) lines\n\ - -m print all files in parallel, one in each column\n\ - -n[SEP[DIGITS]] number lines, use DIGITS (5) digits, then SEP (TAB)\n\ - -o MARGIN offset each line with MARGIN spaces (do not affect -w)\n\ - -r inhibit warning when a file cannot be opened\n\ - -s[SEP] separate columns by character SEP (TAB)\n\ - -t inhibit 5-line page headers and trailers\n\ - -v use octal backslash notation\n\ - -w PAGE_WIDTH set page width to PAGE_WIDTH (72) columns\n\ - --help display this help and exit\n\ - --version output version information and exit\n\ -\n\ --t implied by -l N when N < 10. Without -s, columns are separated by\n\ -spaces. With no FILE, or when FILE is -, read standard input.\n\ -"); - } - exit (status); -} diff --git a/gnu/usr.bin/pr/system.h b/gnu/usr.bin/pr/system.h deleted file mode 100644 index 4aeaaea..0000000 --- a/gnu/usr.bin/pr/system.h +++ /dev/null @@ -1,200 +0,0 @@ -/* system-dependent definitions for textutils programs. - Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Include sys/types.h before this file. */ - -#include - -#ifdef STAT_MACROS_BROKEN -#ifdef S_ISBLK -#undef S_ISBLK -#endif -#ifdef S_ISCHR -#undef S_ISCHR -#endif -#ifdef S_ISDIR -#undef S_ISDIR -#endif -#ifdef S_ISFIFO -#undef S_ISFIFO -#endif -#ifdef S_ISLNK -#undef S_ISLNK -#endif -#ifdef S_ISMPB -#undef S_ISMPB -#endif -#ifdef S_ISMPC -#undef S_ISMPC -#endif -#ifdef S_ISNWK -#undef S_ISNWK -#endif -#ifdef S_ISREG -#undef S_ISREG -#endif -#ifdef S_ISSOCK -#undef S_ISSOCK -#endif -#endif /* STAT_MACROS_BROKEN. */ - -#ifndef S_ISREG /* Doesn't have POSIX.1 stat stuff. */ -#define mode_t unsigned short -#endif -#if !defined(S_ISBLK) && defined(S_IFBLK) -#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) -#endif -#if !defined(S_ISCHR) && defined(S_IFCHR) -#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) -#endif -#if !defined(S_ISDIR) && defined(S_IFDIR) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif -#if !defined(S_ISREG) && defined(S_IFREG) -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#endif -#if !defined(S_ISFIFO) && defined(S_IFIFO) -#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) -#endif -#if !defined(S_ISLNK) && defined(S_IFLNK) -#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -#endif -#if !defined(S_ISSOCK) && defined(S_IFSOCK) -#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) -#endif -#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */ -#define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) -#define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) -#endif -#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */ -#define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) -#endif -#if !defined(HAVE_MKFIFO) -#define mkfifo(path, mode) (mknod ((path), (mode) | S_IFIFO, 0)) -#endif - -#ifdef HAVE_UNISTD_H -#include -#endif -#ifndef _POSIX_VERSION -off_t lseek (); -#endif - -#if defined(HAVE_STRING_H) || defined(STDC_HEADERS) -#if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H) -#include -#endif -#include -#ifndef index -#define index strchr -#endif -#ifndef rindex -#define rindex strrchr -#endif -/* Don't define bcopy; we need one that can handle overlaps. */ -#ifndef bzero -#define bzero(s, n) memset ((s), 0, (n)) -#endif -#ifndef bcmp -#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) -#endif -#else -#include -char *memchr (); -#endif - -#include -#ifdef STDC_HEADERS -#include -#else -char *getenv (); -extern int errno; -#endif - -#if defined(HAVE_FCNTL_H) || defined(_POSIX_VERSION) -#include -#else -#include -#endif - -#if !defined(SEEK_SET) -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 -#endif - -#ifndef _POSIX_SOURCE -#include -#endif - -/* Get or fake the disk device blocksize. - Usually defined by sys/param.h (if at all). */ -#if !defined(DEV_BSIZE) && defined(BSIZE) -#define DEV_BSIZE BSIZE -#endif -#if !defined(DEV_BSIZE) && defined(BBSIZE) /* SGI */ -#define DEV_BSIZE BBSIZE -#endif -#ifndef DEV_BSIZE -#define DEV_BSIZE 4096 -#endif - -/* Extract or fake data from a `struct stat'. - ST_BLKSIZE: Optimal I/O blocksize for the file, in bytes. */ -#ifndef HAVE_ST_BLKSIZE -# define ST_BLKSIZE(statbuf) DEV_BSIZE -#else /* HAVE_ST_BLKSIZE */ -/* Some systems, like Sequents, return st_blksize of 0 on pipes. */ -# define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \ - ? (statbuf).st_blksize : DEV_BSIZE) -#endif /* HAVE_ST_BLKSIZE */ - -#ifndef S_ISLNK -#define lstat stat -#endif - -#ifndef RETSIGTYPE -#define RETSIGTYPE void -#endif - -#include - -#ifndef isascii -#define isascii(c) 1 -#endif - -#ifdef isblank -#define ISBLANK(c) (isascii (c) && isblank (c)) -#else -#define ISBLANK(c) ((c) == ' ' || (c) == '\t') -#endif -#ifdef isgraph -#define ISGRAPH(c) (isascii (c) && isgraph (c)) -#else -#define ISGRAPH(c) (isascii (c) && isprint (c) && !isspace (c)) -#endif - -#define ISPRINT(c) (isascii (c) && isprint (c)) -#define ISDIGIT(c) (isascii (c) && isdigit (c)) -#define ISALNUM(c) (isascii (c) && isalnum (c)) -#define ISALPHA(c) (isascii (c) && isalpha (c)) -#define ISCNTRL(c) (isascii (c) && iscntrl (c)) -#define ISLOWER(c) (isascii (c) && islower (c)) -#define ISPUNCT(c) (isascii (c) && ispunct (c)) -#define ISSPACE(c) (isascii (c) && isspace (c)) -#define ISUPPER(c) (isascii (c) && isupper (c)) -#define ISXDIGIT(c) (isascii (c) && isxdigit (c)) diff --git a/gnu/usr.bin/pr/version.c b/gnu/usr.bin/pr/version.c deleted file mode 100644 index 64c62b19..0000000 --- a/gnu/usr.bin/pr/version.c +++ /dev/null @@ -1,13 +0,0 @@ -#ifdef HAVE_CONFIG_H -#if defined (CONFIG_BROKETS) -/* We use instead of "config.h" so that a compilation - using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h - (which it would do because it found this file in $srcdir). */ -#include -#else -#include "config.h" -#endif -#endif - -#include "version.h" -const char *version_string = "GNU textutils 1.9"; diff --git a/gnu/usr.bin/pr/xmalloc.c b/gnu/usr.bin/pr/xmalloc.c deleted file mode 100644 index 58a81b5..0000000 --- a/gnu/usr.bin/pr/xmalloc.c +++ /dev/null @@ -1,88 +0,0 @@ -/* xmalloc.c -- malloc with out of memory checking - Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifdef HAVE_CONFIG_H -#if defined (CONFIG_BROKETS) -/* We use instead of "config.h" so that a compilation - using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h - (which it would do because it found this file in $srcdir). */ -#include -#else -#include "config.h" -#endif -#endif - -#if __STDC__ -#define VOID void -#else -#define VOID char -#endif - -#include - -#if STDC_HEADERS -#include -#else -VOID *malloc (); -VOID *realloc (); -void free (); -#endif - -#if __STDC__ && defined (HAVE_VPRINTF) -void error (int, int, char const *, ...); -#else -void error (); -#endif - -/* Allocate N bytes of memory dynamically, with error checking. */ - -VOID * -xmalloc (n) - size_t n; -{ - VOID *p; - - p = malloc (n); - if (p == 0) - /* Must exit with 2 for `cmp'. */ - error (2, 0, "virtual memory exhausted"); - return p; -} - -/* Change the size of an allocated block of memory P to N bytes, - with error checking. - If P is NULL, run xmalloc. - If N is 0, run free and return NULL. */ - -VOID * -xrealloc (p, n) - VOID *p; - size_t n; -{ - if (p == 0) - return xmalloc (n); - if (n == 0) - { - free (p); - return 0; - } - p = realloc (p, n); - if (p == 0) - /* Must exit with 2 for `cmp'. */ - error (2, 0, "virtual memory exhausted"); - return p; -} diff --git a/gnu/usr.bin/ptx/regex.h b/gnu/usr.bin/ptx/regex.h deleted file mode 100644 index a495005..0000000 --- a/gnu/usr.bin/ptx/regex.h +++ /dev/null @@ -1,490 +0,0 @@ -/* Definitions for data structures and routines for the regular - expression library, version 0.12. - - Copyright (C) 1985, 89, 90, 91, 92, 1993 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -#ifndef __REGEXP_LIBRARY_H__ -#define __REGEXP_LIBRARY_H__ - -/* POSIX says that must be included (by the caller) before - . */ - -#ifdef VMS -/* VMS doesn't have `size_t' in , even though POSIX says it - should be there. */ -#include -#endif - - -/* The following bits are used to determine the regexp syntax we - recognize. The set/not-set meanings are chosen so that Emacs syntax - remains the value 0. The bits are given in alphabetical order, and - the definitions shifted by one from the previous bit; thus, when we - add or remove a bit, only one other definition need change. */ -typedef unsigned reg_syntax_t; - -/* If this bit is not set, then \ inside a bracket expression is literal. - If set, then such a \ quotes the following character. */ -#define RE_BACKSLASH_ESCAPE_IN_LISTS (1) - -/* If this bit is not set, then + and ? are operators, and \+ and \? are - literals. - If set, then \+ and \? are operators and + and ? are literals. */ -#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) - -/* If this bit is set, then character classes are supported. They are: - [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], - [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. - If not set, then character classes are not supported. */ -#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) - -/* If this bit is set, then ^ and $ are always anchors (outside bracket - expressions, of course). - If this bit is not set, then it depends: - ^ is an anchor if it is at the beginning of a regular - expression or after an open-group or an alternation operator; - $ is an anchor if it is at the end of a regular expression, or - before a close-group or an alternation operator. - - This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because - POSIX draft 11.2 says that * etc. in leading positions is undefined. - We already implemented a previous draft which made those constructs - invalid, though, so we haven't changed the code back. */ -#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) - -/* If this bit is set, then special characters are always special - regardless of where they are in the pattern. - If this bit is not set, then special characters are special only in - some contexts; otherwise they are ordinary. Specifically, - * + ? and intervals are only special when not after the beginning, - open-group, or alternation operator. */ -#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) - -/* If this bit is set, then *, +, ?, and { cannot be first in an re or - immediately after an alternation or begin-group operator. */ -#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) - -/* If this bit is set, then . matches newline. - If not set, then it doesn't. */ -#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) - -/* If this bit is set, then . doesn't match NUL. - If not set, then it does. */ -#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) - -/* If this bit is set, nonmatching lists [^...] do not match newline. - If not set, they do. */ -#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) - -/* If this bit is set, either \{...\} or {...} defines an - interval, depending on RE_NO_BK_BRACES. - If not set, \{, \}, {, and } are literals. */ -#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) - -/* If this bit is set, +, ? and | aren't recognized as operators. - If not set, they are. */ -#define RE_LIMITED_OPS (RE_INTERVALS << 1) - -/* If this bit is set, newline is an alternation operator. - If not set, newline is literal. */ -#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) - -/* If this bit is set, then `{...}' defines an interval, and \{ and \} - are literals. - If not set, then `\{...\}' defines an interval. */ -#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) - -/* If this bit is set, (...) defines a group, and \( and \) are literals. - If not set, \(...\) defines a group, and ( and ) are literals. */ -#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) - -/* If this bit is set, then \ matches . - If not set, then \ is a back-reference. */ -#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) - -/* If this bit is set, then | is an alternation operator, and \| is literal. - If not set, then \| is an alternation operator, and | is literal. */ -#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) - -/* If this bit is set, then an ending range point collating higher - than the starting range point, as in [z-a], is invalid. - If not set, then when ending range point collates higher than the - starting range point, the range is ignored. */ -#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) - -/* If this bit is set, then an unmatched ) is ordinary. - If not set, then an unmatched ) is invalid. */ -#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) - -/* This global variable defines the particular regexp syntax to use (for - some interfaces). When a regexp is compiled, the syntax used is - stored in the pattern buffer, so changing this does not affect - already-compiled regexps. */ -extern reg_syntax_t re_syntax_options; - -/* Define combinations of the above bits for the standard possibilities. - (The [[[ comments delimit what gets put into the Texinfo file, so - don't delete them!) */ -/* [[[begin syntaxes]]] */ -#define RE_SYNTAX_EMACS 0 - -#define RE_SYNTAX_AWK \ - (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - -#define RE_SYNTAX_POSIX_AWK \ - (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS) - -#define RE_SYNTAX_GREP \ - (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ - | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ - | RE_NEWLINE_ALT) - -#define RE_SYNTAX_EGREP \ - (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ - | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ - | RE_NO_BK_VBAR) - -#define RE_SYNTAX_POSIX_EGREP \ - (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES) - -/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ -#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC - -#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC - -/* Syntax bits common to both basic and extended POSIX regex syntax. */ -#define _RE_SYNTAX_POSIX_COMMON \ - (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ - | RE_INTERVALS | RE_NO_EMPTY_RANGES) - -#define RE_SYNTAX_POSIX_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) - -/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes - RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this - isn't minimal, since other operators, such as \`, aren't disabled. */ -#define RE_SYNTAX_POSIX_MINIMAL_BASIC \ - (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) - -#define RE_SYNTAX_POSIX_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ - | RE_UNMATCHED_RIGHT_PAREN_ORD) - -/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS - replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */ -#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ - (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ - | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ - | RE_NO_BK_PARENS | RE_NO_BK_REFS \ - | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) -/* [[[end syntaxes]]] */ - -/* Maximum number of duplicates an interval can allow. Some systems - (erroneously) define this in other header files, but we want our - value, so remove any previous define. */ -#ifdef RE_DUP_MAX -#undef RE_DUP_MAX -#endif -#define RE_DUP_MAX ((1 << 15) - 1) - - -/* POSIX `cflags' bits (i.e., information for `regcomp'). */ - -/* If this bit is set, then use extended regular expression syntax. - If not set, then use basic regular expression syntax. */ -#define REG_EXTENDED 1 - -/* If this bit is set, then ignore case when matching. - If not set, then case is significant. */ -#define REG_ICASE (REG_EXTENDED << 1) - -/* If this bit is set, then anchors do not match at newline - characters in the string. - If not set, then anchors do match at newlines. */ -#define REG_NEWLINE (REG_ICASE << 1) - -/* If this bit is set, then report only success or fail in regexec. - If not set, then returns differ between not matching and errors. */ -#define REG_NOSUB (REG_NEWLINE << 1) - - -/* POSIX `eflags' bits (i.e., information for regexec). */ - -/* If this bit is set, then the beginning-of-line operator doesn't match - the beginning of the string (presumably because it's not the - beginning of a line). - If not set, then the beginning-of-line operator does match the - beginning of the string. */ -#define REG_NOTBOL 1 - -/* Like REG_NOTBOL, except for the end-of-line. */ -#define REG_NOTEOL (1 << 1) - - -/* If any error codes are removed, changed, or added, update the - `re_error_msg' table in regex.c. */ -typedef enum -{ - REG_NOERROR = 0, /* Success. */ - REG_NOMATCH, /* Didn't find a match (for regexec). */ - - /* POSIX regcomp return error codes. (In the order listed in the - standard.) */ - REG_BADPAT, /* Invalid pattern. */ - REG_ECOLLATE, /* Not implemented. */ - REG_ECTYPE, /* Invalid character class name. */ - REG_EESCAPE, /* Trailing backslash. */ - REG_ESUBREG, /* Invalid back reference. */ - REG_EBRACK, /* Unmatched left bracket. */ - REG_EPAREN, /* Parenthesis imbalance. */ - REG_EBRACE, /* Unmatched \{. */ - REG_BADBR, /* Invalid contents of \{\}. */ - REG_ERANGE, /* Invalid range end. */ - REG_ESPACE, /* Ran out of memory. */ - REG_BADRPT, /* No preceding re for repetition op. */ - - /* Error codes we've added. */ - REG_EEND, /* Premature end. */ - REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ - REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ -} reg_errcode_t; - -/* This data structure represents a compiled pattern. Before calling - the pattern compiler, the fields `buffer', `allocated', `fastmap', - `translate', and `no_sub' can be set. After the pattern has been - compiled, the `re_nsub' field is available. All other fields are - private to the regex routines. */ - -struct re_pattern_buffer -{ -/* [[[begin pattern_buffer]]] */ - /* Space that holds the compiled pattern. It is declared as - `unsigned char *' because its elements are - sometimes used as array indexes. */ - unsigned char *buffer; - - /* Number of bytes to which `buffer' points. */ - unsigned long allocated; - - /* Number of bytes actually used in `buffer'. */ - unsigned long used; - - /* Syntax setting with which the pattern was compiled. */ - reg_syntax_t syntax; - - /* Pointer to a fastmap, if any, otherwise zero. re_search uses - the fastmap, if there is one, to skip over impossible - starting points for matches. */ - char *fastmap; - - /* Either a translate table to apply to all characters before - comparing them, or zero for no translation. The translation - is applied to a pattern when it is compiled and to a string - when it is matched. */ - char *translate; - - /* Number of subexpressions found by the compiler. */ - size_t re_nsub; - - /* Zero if this pattern cannot match the empty string, one else. - Well, in truth it's used only in `re_search_2', to see - whether or not we should use the fastmap, so we don't set - this absolutely perfectly; see `re_compile_fastmap' (the - `duplicate' case). */ - unsigned can_be_null : 1; - - /* If REGS_UNALLOCATED, allocate space in the `regs' structure - for `max (RE_NREGS, re_nsub + 1)' groups. - If REGS_REALLOCATE, reallocate space if necessary. - If REGS_FIXED, use what's there. */ -#define REGS_UNALLOCATED 0 -#define REGS_REALLOCATE 1 -#define REGS_FIXED 2 - unsigned regs_allocated : 2; - - /* Set to zero when `regex_compile' compiles a pattern; set to one - by `re_compile_fastmap' if it updates the fastmap. */ - unsigned fastmap_accurate : 1; - - /* If set, `re_match_2' does not return information about - subexpressions. */ - unsigned no_sub : 1; - - /* If set, a beginning-of-line anchor doesn't match at the - beginning of the string. */ - unsigned not_bol : 1; - - /* Similarly for an end-of-line anchor. */ - unsigned not_eol : 1; - - /* If true, an anchor at a newline matches. */ - unsigned newline_anchor : 1; - -/* [[[end pattern_buffer]]] */ -}; - -typedef struct re_pattern_buffer regex_t; - - -/* search.c (search_buffer) in Emacs needs this one opcode value. It is - defined both in `regex.c' and here. */ -#define RE_EXACTN_VALUE 1 - -/* Type for byte offsets within the string. POSIX mandates this. */ -typedef int regoff_t; - - -/* This is the structure we store register match data in. See - regex.texinfo for a full description of what registers match. */ -struct re_registers -{ - unsigned num_regs; - regoff_t *start; - regoff_t *end; -}; - - -/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, - `re_match_2' returns information about at least this many registers - the first time a `regs' structure is passed. */ -#ifndef RE_NREGS -#define RE_NREGS 30 -#endif - - -/* POSIX specification for registers. Aside from the different names than - `re_registers', POSIX uses an array of structures, instead of a - structure of arrays. */ -typedef struct -{ - regoff_t rm_so; /* Byte offset from string's start to substring's start. */ - regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ -} regmatch_t; - -/* Declarations for routines. */ - -/* To avoid duplicating every routine declaration -- once with a - prototype (if we are ANSI), and once without (if we aren't) -- we - use the following macro to declare argument types. This - unfortunately clutters up the declarations a bit, but I think it's - worth it. */ - -#if __STDC__ - -#define _RE_ARGS(args) args - -#else /* not __STDC__ */ - -#define _RE_ARGS(args) () - -#endif /* not __STDC__ */ - -/* Sets the current default syntax to SYNTAX, and return the old syntax. - You can also simply assign to the `re_syntax_options' variable. */ -extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); - -/* Compile the regular expression PATTERN, with length LENGTH - and syntax given by the global `re_syntax_options', into the buffer - BUFFER. Return NULL if successful, and an error string if not. */ -extern const char *re_compile_pattern - _RE_ARGS ((const char *pattern, int length, - struct re_pattern_buffer *buffer)); - - -/* Compile a fastmap for the compiled pattern in BUFFER; used to - accelerate searches. Return 0 if successful and -2 if was an - internal error. */ -extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); - - -/* Search in the string STRING (with length LENGTH) for the pattern - compiled into BUFFER. Start searching at position START, for RANGE - characters. Return the starting position of the match, -1 for no - match, or -2 for an internal error. Also return register - information in REGS (if REGS and BUFFER->no_sub are nonzero). */ -extern int re_search - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, int range, struct re_registers *regs)); - - -/* Like `re_search', but search in the concatenation of STRING1 and - STRING2. Also, stop searching at index START + STOP. */ -extern int re_search_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, int range, struct re_registers *regs, int stop)); - - -/* Like `re_search', but return how many characters in STRING the regexp - in BUFFER matched, starting at position START. */ -extern int re_match - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, - int length, int start, struct re_registers *regs)); - - -/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ -extern int re_match_2 - _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, - int length1, const char *string2, int length2, - int start, struct re_registers *regs, int stop)); - - -/* Set REGS to hold NUM_REGS registers, storing them in STARTS and - ENDS. Subsequent matches using BUFFER and REGS will use this memory - for recording register information. STARTS and ENDS must be - allocated with malloc, and must each be at least `NUM_REGS * sizeof - (regoff_t)' bytes long. - - If NUM_REGS == 0, then subsequent matches should allocate their own - register data. - - Unless this function is called, the first search or match using - PATTERN_BUFFER will allocate its own register data, without - freeing the old data. */ -extern void re_set_registers - _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, - unsigned num_regs, regoff_t *starts, regoff_t *ends)); - -/* 4.2 bsd compatibility. */ -extern char *re_comp _RE_ARGS ((const char *)); -extern int re_exec _RE_ARGS ((const char *)); - -/* POSIX compatibility. */ -extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags)); -extern int regexec - _RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch, - regmatch_t pmatch[], int eflags)); -extern size_t regerror - _RE_ARGS ((int errcode, const regex_t *preg, char *errbuf, - size_t errbuf_size)); -extern void regfree _RE_ARGS ((regex_t *preg)); - -#endif /* not __REGEXP_LIBRARY_H__ */ - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/gnu/usr.bin/send-pr/send-pr.info b/gnu/usr.bin/send-pr/send-pr.info deleted file mode 100644 index 4e98715..0000000 --- a/gnu/usr.bin/send-pr/send-pr.info +++ /dev/null @@ -1,1604 +0,0 @@ -This is Info file send-pr.info, produced by Makeinfo-1.55 from the -input file ./send-pr.texi. - -START-INFO-DIR-ENTRY -* send-pr:: Reporting problems--using send-pr -END-INFO-DIR-ENTRY - - Copyright (C) 1993 Free Software Foundation, Inc. - - Permission is granted to make and distribute verbatim copies of this -manual provided the copyright notice and this permission notice are -preserved on all copies. - - Permission is granted to copy and distribute modified versions of -this manual under the conditions for verbatim copying, provided also -that the entire resulting derived work is distributed under the terms -of a permission notice identical to this one. - - Permission is granted to copy and distribute translations of this -manual into another language, under the above conditions for modified -versions. - - -File: send-pr.info, Node: Top, Next: send-pr in detail, Prev: (DIR), Up: (DIR) - -Overview -******** - - This manual documents `send-pr', version 3.2, which uses electronic -mail to submit support questions and problem reports to a central -Support Site. No body of work is perfect, and support organizations -understand this; `send-pr' is designed to allow users who have problems -to submit reports of these problems to sites responsible for supporting -the products in question, in a defined form which can be read by an -electronically managed database. - - `send-pr' is part of a suite of programs known collectively as -GNATS, the GNU Problem Report Management System. GNATS consists of -several programs which, used in concert, formulate and partially -administer a database of "Problem Reports", or "PRs", at a central -Support Site. A PR goes through several states in its lifetime; GNATS -tracks the PR and all information associated with it through each state -and finally acts as an archive for PRs which have been "closed". - - Because `send-pr' exists as a shell (`/bin/sh') script and as an -Elisp file for use with GNU Emacs, it can be used from any machine on -your network which can run a shell script and/or Emacs. - - In general, you can use any editor and mailer to submit valid Problem -Reports, as long as the format required by GNATS is preserved. -`send-pr' automates the process, however, and ensures that certain -fields necessary for automatic processing are present. `send-pr' is -strongly recommended for all initial problem-oriented correspondence -with your Support Site. The organization you submit Problem Reports to -supplies an address to which further information can be sent; the person -responsible for the category of the problem you report contacts you -directly. - -* Menu: - -* send-pr in detail:: Details about send-pr and GNATS -* Invoking send-pr:: Editing and sending PRs -* An Example:: A working example -* Installing send-pr:: Installing send-pr on your system -* Index:: - - -File: send-pr.info, Node: send-pr in detail, Next: Invoking send-pr, Prev: Top, Up: Top - -Details about send-pr and GNATS -******************************* - - A "Problem Report" is a message that describes a problem you are -having with a body of work. `send-pr' organizes this message into a -form which can be understood and automatically processed by GNATS, the -GNU Problem Report Management System. A Problem Report is organized -into "fields" which contain data describing you, your organization, and -the problem you are announcing (*note Problem Report format: Fields.). -Problem Reports go through several defined states in their lifetimes, -from "open" to "closed" (*note States of Problem Reports: States.). - -* Menu: - -* States:: States of Problem Reports -* Fields:: Problem Report format - - -File: send-pr.info, Node: States, Next: Fields, Up: send-pr in detail - -States of Problem Reports -========================= - - Each PR goes through a defined series of states between origination -and closure. The originator of a PR receives notification -automatically of any state changes. - -"open" - The initial state of a Problem Report. This means the PR has been - filed and the responsible person(s) notified. - -"analyzed" - The responsible person has analyzed the problem. The analysis - should contain a preliminary evaluation of the problem and an - estimate of the amount of time and resources necessary to solve - the problem. It should also suggest possible workarounds. - -"feedback" - The problem has been solved, and the originator has been given a - patch or other fix. The PR remains in this state until the - originator acknowledges that the solution works. - -"closed" - A Problem Report is closed ("the bug stops here") only when any - changes have been integrated, documented, and tested, and the - submitter has confirmed the solution. - -"suspended" - Work on the problem has been postponed. This happens if a timely - solution is not possible or is not cost-effective at the present - time. The PR continues to exist, though a solution is not being - actively sought. If the problem cannot be solved at all, it - should be closed rather than suspended. - - -File: send-pr.info, Node: Fields, Prev: States, Up: send-pr in detail - -Problem Report format -===================== - - The format of a PR is designed to reflect the nature of GNATS as a -database. Information is arranged into "fields", and kept in -individual records (Problem Reports). - - Problem Report fields are denoted by a keyword which begins with `>' -and ends with `:', as in `>Confidential:'. Fields belong to one of -three data types: - -ENUMERATED - One of a specific set of values, which vary according to the - field. The value for each keyword must be on the same line as the - keyword. These values are not configurable (yet). - - For each ENUMERATED keyword, the possible choices are listed in the - `send-pr' template as a comment. The following fields are - ENUMERATED format; see the descriptions of fields below for - explanations of each field in detail: - - >Confidential: >Severity: >Priority: - >Class: >State: >Number: - -TEXT - One single line of text which must begin and end on the same line - (i.e., before a newline) as the keyword. See the descriptions of - fields below for explanations of each field in detail. The - following fields are TEXT format: - - >Submitter-Id: >Originator: >Synopsis: - >Category: >Release: >Responsible: - >Arrival-Date: - -MULTITEXT - Text of any length may occur in this field. MULTITEXT may span - multiple lines and may also include blank lines. A MULTITEXT field - ends only when another keyword appears. See the descriptions of - fields below for explanations of each field in detail. - - The following fields are MULTITEXT format: - - >Organization: >Environment: >Description: - >How-To-Repeat: >Fix: >Audit-Trail: - >Unformatted: - - A Problem Report contains two different types of fields: "Mail -Header" fields, which are used by the mail handler for delivery, and -"Problem Report" fields, which contain information relevant to the -Problem Report and its submitter. A Problem Report is essentially a -specially formatted electronic mail message. - - The following is an example Problem Report. Mail headers are at the -top, followed by GNATS fields, which begin with `>' and end with `:'. -The `Subject:' line in the mail header and the `>Synopsis:' field are -usually duplicates of each other. - - Message-Id: MESSAGE-ID - Date: DATE - From: ADDRESS - Reply-To: ADDRESS - To: BUG-ADDRESS - Subject: SUBJECT - - >Number: GNATS-ID - >Category: CATEGORY - >Synopsis: SYNOPSIS - >Confidential: yes *or* no - >Severity: critical, serious, *or* non-critical - >Priority: high, medium *or* low - >Responsible: RESPONSIBLE - >State: open, analyzed, suspended, feedback, *or* closed - >Class: sw-bug, doc-bug, change-request, support, - *or* duplicate - >Submitter-Id: SUBMITTER-ID - >Arrival-Date: DATE - >Originator: NAME - >Organization: ORGANIZATION - >Release: RELEASE - >Environment: - ENVIRONMENT - >Description: - DESCRIPTION - >How-To-Repeat: - HOW-TO-REPEAT - >Fix: - FIX - >Audit-Trail: - APPENDED-MESSAGES... - State-Changed-From-To: FROM-TO - State-Changed-When: DATE - State-Changed-Why: - REASON - Responsible-Changed-From-To: FROM-TO - Responsible-Changed-When: DATE - Responsible-Changed-Why: - REASON - >Unformatted: - MISCELLANEOUS - -* Menu: - -* Mail header fields:: -* Problem Report fields:: - - -File: send-pr.info, Node: Mail header fields, Next: Problem Report fields, Up: Fields - -Mail header fields ------------------- - - A Problem Report may contain any mail header field described in the -Internet standard RFC-822. However, only the fields which identify the -sender and the subject are required by `send-pr': - -`To:' - The preconfigured mail address for the Support Site where the PR - is to be sent, automatically supplied by `send-pr'. - -`Subject:' - A terse description of the problem. This field normally contains - the same information as the `>Synopsis:' field. - -`From:' - Usually supplied automatically by the originator's mailer; should - contain the originator's electronic mail address. - -`Reply-To:' - A return address to which electronic replies can be sent; in most - cases, the same address as the `From:' field. - - -File: send-pr.info, Node: Problem Report fields, Prev: Mail header fields, Up: Fields - -Problem Report fields ---------------------- - -Field descriptions ------------------- - - The following fields are present whenever a PR is submitted via the -program `send-pr'. GNATS adds additional fields when the PR arrives at -the Support Site; explanations of these follow this list. - -`>Submitter-Id:' - (TEXT) A unique identification code assigned by the Support Site. - It is used to identify all Problem Reports coming from a particular - site. (Submitters without a value for this field can invoke - `send-pr' with the `--request-id' option to apply for one from the - support organization. Problem Reports from those not affiliated - with the support organization should use the default value of `net' - for this field.) - -`>Originator:' - (TEXT) Originator's real name. The default is the value of the - originator's environment variable `NAME'. - -`>Organization:' - (MULTITEXT) The originator's organization. The default value is - set with the variable `DEFAULT_ORGANIZATION' in the `send-pr' - shell script. - -`>Confidential:' - (ENUMERATED) Use of this field depends on the originator's - relationship with the support organization; contractual agreements - often have provisions for preserving confidentiality. Conversely, - a lack of a contract often means that any data provided will not - be considered confidential. Submitters should be advised to - contact the support organization directly if this is an issue. - - If the originator's relationship to the support organization - provides for confidentiality, then if the value of this field is - `yes' the support organization treats the PR as confidential; any - code samples provided are not made publicly available (e.g., in - regression test suites). The default value is `yes'. - -`>Synopsis:' - (TEXT) One-line summary of the problem. `send-pr' copies this - information to the `Subject:' line when you submit a Problem - Report. - -`>Severity:' - (ENUMERATED) The severity of the problem. Accepted values include: - - `critical' - The product, component or concept is completely - non-operational or some essential functionality is missing. - No workaround is known. - - `serious' - The product, component or concept is not working properly or - significant functionality is missing. Problems that would - otherwise be considered `critical' are rated `serious' when a - workaround is known. - - `non-critical' - The product, component or concept is working in general, but - lacks features, has irritating behavior, does something - wrong, or doesn't match its documentation. The default value - is `serious'. - -`>Priority:' - (ENUMERATED) How soon the originator requires a solution. Accepted - values include: - - `high' - A solution is needed as soon as possible. - - `medium' - The problem should be solved in the next release. - - `low' - The problem should be solved in a future release. - - The default value is `medium'. - -`>Category:' - (TEXT) The name of the product, component or concept where the - problem lies. The values for this field are defined by the Support - Site. - -`>Class:' - (ENUMERATED) The class of a problem can be one of the following: - - `sw-bug' - A general product problem. (`sw' stands for "software".) - - `doc-bug' - A problem with the documentation. - - `change-request' - A request for a change in behavior, etc. - - `support' - A support problem or question. - - `duplicate (PR-NUMBER)' - Duplicate PR. PR-NUMBER should be the number of the original - PR. - - The default is `sw-bug'. - -`>Release:' - (TEXT) Release or version number of the product, component or - concept. - -`>Environment:' - (MULTITEXT) Description of the environment where the problem - occured: machine architecture, operating system, host and target - types, libraries, pathnames, etc. - -`>Description:' - (MULTITEXT) Precise description of the problem. - -`>How-To-Repeat:' - (MULTITEXT) Example code, input, or activities to reproduce the - problem. The support organization uses example code both to - reproduce the problem and to test whether the problem is fixed. - Include all preconditions, inputs, outputs, conditions after the - problem, and symptoms. Any additional important information - should be included. Include all the details that would be - necessary for someone else to recreate the problem reported, - however obvious. Sometimes seemingly arbitrary or obvious - information can point the way toward a solution. See also *Note - Helpful hints: Helpful hints. - -`>Fix:' - (MULTITEXT) A description of a solution to the problem, or a patch - which solves the problem. (This field is most often filled in at - the Support Site; we provide it to the submitter in case she has - solved the problem.) - -GNATS adds the following fields when the PR arrives at the Support Site: - -`>Number:' - (ENUMERATED) The incremental identification number for this PR. - - The `>Number:' field is often paired with the `>Category:' field as - - CATEGORY/NUMBER - - in subsequent email messages. This is for historical reasons, as - well as because Problem Reports are stored in subdirectories which - are named by category. - -`>State:' - (ENUMERATED) The current state of the PR. Accepted values are: - - `open' - The PR has been filed and the responsible person notified. - - `analyzed' - The responsible person has analyzed the problem. - - `feedback' - The problem has been solved, and the originator has been - given a patch or other fix. - - `closed' - The changes have been integrated, documented, and tested, and - the originator has confirmed that the solution works. - - `suspended' - Work on the problem has been postponed. - - The initial state of a PR is `open'. *Note States of Problem - Reports: States. - -`>Responsible:' - (TEXT) The person responsible for this category. - -`>Arrival-Date:' - (TEXT) The time that this PR was received by GNATS. The date is - provided automatically by GNATS. - -`>Audit-Trail:' - (MULTITEXT) Tracks related electronic mail as well as changes in - the `>State:' and `>Responsible:' fields with the sub-fields: - - `State-Changed--: OLDSTATE>-State:' field values. - - `Responsible-Changed--: OLDRESP>-Responsible:' field values. - - `State-Changed-By: NAME' - `Responsible-Changed-By: NAME' - The name of the maintainer who effected the change. - - `State-Changed-When: TIMESTAMP' - `Responsible-Changed-When: TIMESTAMP' - The time the change was made. - - `State-Changed-Why: REASON...' - `Responsible-Changed-Why: REASON...' - The reason for the change. - - The `>Audit-Trail:' field also contains any mail messages received - by GNATS related to this PR, in the order received. - -`>Unformatted:' - (MULTITEXT) Any random text found outside the fields in the - original Problem Report. - - -File: send-pr.info, Node: Invoking send-pr, Next: An Example, Prev: send-pr in detail, Up: Top - -Editing and sending PRs -*********************** - - You can invoke `send-pr' from a shell prompt or from within GNU -Emacs using `M-x send-pr'. - -* Menu: - -* using send-pr:: Creating new Problem Reports -* send-pr in Emacs:: Using send-pr from within Emacs -* send-pr from the shell:: Invoking send-pr from the shell -* Helpful hints:: - - -File: send-pr.info, Node: using send-pr, Next: send-pr in Emacs, Up: Invoking send-pr - -Creating new Problem Reports -============================ - - Invoking `send-pr' presents a PR "template" with a number of fields -already filled in. Complete the template as thoroughly as possible to -make a useful bug report. Submit only one bug with each PR. - - A template consists of three sections: - -"Comments" - The top several lines of a blank template consist of a series of - comments that provide some basic instructions for completing the - Problem Report, as well as a list of valid entries for the - `>Category:' field. These comments are all preceded by the string - `SEND-PR:' and are erased automatically when the PR is submitted. - The instructional comments within `<' and `>' are also removed. - (Only these comments are removed; lines you provide that happen to - have those characters in them, such as examples of shell-level - redirection, are not affected.) - -"Mail Header" - `send-pr' creates a standard mail header. `send-pr' completes all - fields except the `Subject:' line with default values. (*Note - Problem Report format: Fields.) - -"GNATS fields" - These are the informational fields that GNATS uses to route your - Problem Report to the responsible party for further action. They - should be filled out as completely as possible. (*Note Problem - Report format: Fields. Also see *Note Helpful hints: Helpful - hints.) - -For examples of a Problem Report template and complete Problem Report, -see *Note An Example::. - - The default template contains your preconfigured `>Submitter-Id:'. -`send-pr' attempts to determine values for the `>Originator:' and -`>Organization:' fields (*note Problem Report format: Fields.). -`send-pr' also attempts to find out some information about your system -and architecture, and places this information in the `>Environment:' -field if it finds any. - - You may submit problem reports to different Support Sites from the -default site by specifying the alternate site when you invoke -`send-pr'. Each `site' has its own list of categories for which it -accepts Problem Reports. (*Note Setting a default SITE: default site.) - - `send-pr' also provides the mail header section of the template with -default values in the `To:', `From:', and `Reply-To:' fields. The -`Subject:' field is empty. - - The template begins with a comment section: - - SEND-PR: -*- send-pr -*- - SEND-PR: Lines starting with `SEND-PR' will be removed - SEND-PR: automatically as well as all comments (the text - SEND-PR: below enclosed in `<' and `>'). - SEND-PR: - SEND-PR: Please consult the document `Reporting Problems - SEND-PR: Using send-pr' if you are not sure how to fill out - SEND-PR: a problem report. - SEND-PR: - SEND-PR: Choose from the following categories: - -and also contains a list of valid `>Category:' values for the Support -Site to whom you are submitting this Problem Report. One (and only -one) of these values should be placed in the `>Category:' field. A -complete sample bug report, from template to completed PR, is shown in -*Note An Example::. For a complete list of valid categories, type -`send-pr -L' at your prompt. *Note Valid Categories: Valid Categories, -for a sample list of categories, . - - The mail header is just below the comment section. Fill out the -`Subject:' field, if it is not already completed using the value of -`>Synopsis:'. The other mail header fields contain default values. - - To: SUPPORT-SITE - Subject: *complete this field* - From: YOUR-LOGIN@YOUR-SITE - Reply-To: YOUR-LOGIN@YOUR-SITE - X-send-pr-version: send-pr 3.2 - -where SUPPORT-SITE is an alias for the Support Site you wish to submit -this PR to. - - The rest of the template contains GNATS fields. Each field is -either automatically completed with valid information (such as your -`>Submitter-Id:') or contains a one-line instruction specifying the -information that field requires in order to be correct. For example, -the `>Confidential:' field expects a value of `yes' or `no', and the -answer must fit on one line; similarly, the `>Synopsis:' field expects -a short synopsis of the problem, which must also fit on one line. Fill -out the fields as completely as possible. *Note Helpful hints: Helpful -hints, for suggestions as to what kinds of information to include. - - In this example, words in *italics* are filled in with -pre-configured information: - - >Submitter-Id: *your submitter-id* - >Originator: *your name here* - >Organization: - *your organization* - >Confidential:<[ yes | no ] (one line)> - >Synopsis: - >Severity: <[non-critical | serious | critical](one line)> - >Priority: <[ low | medium | high ] (one line)> - >Category: - >Class: <[sw-bug | doc-bug | change-request | support]> - >Release: - >Environment: - - - >Description: - - >How-To-Repeat: - - >Fix: - - - When you finish editing the Problem Report, `send-pr' mails it to -the address named in the `To:' field in the mail header. `send-pr' -checks that the complete form contains a valid `>Category:'. - - Your copy of `send-pr' should have already been customized on -installation to reflect your `>Submitter-Id:'. (*Note Installing -`send-pr' on your system: Installing send-pr.) If you don't know your -`>Submitter-Id:', you can request it using `send-pr --request-id'. If -your organization is not affiliated with the site you send Problem -Reports to, a good generic `>Submitter-Id:' to use is `net'. - - If your PR has an invalid value in one of the ENUMERATED fields -(*note Problem Report format: Fields.), `send-pr' places the PR in a -temporary file named `/tmp/pbadNNNN' on your machine. NNNN is the -process identification number given to your current `send-pr' session. -If you are running `send-pr' from the shell, you are prompted as to -whether or not you wish to try editing the same Problem Report again. -If you are running `send-pr' from Emacs, the Problem Report is placed -in the buffer `*send-pr-error*'; you can edit this file and then submit -it with - - M-x gnats-submit-pr - - Any further mail concerning this Problem Report should be -carbon-copied to the GNATS mailing address as well, with the category -and identification number in the `Subject:' line of the message. - - Subject: Re: PR CATEGORY/GNATS-ID: ORIGINAL MESSAGE SUBJECT - -Messages which arrive with `Subject:' lines of this form are -automatically appended to the Problem Report in the `>Audit-Trail:' -field in the order received. - - -File: send-pr.info, Node: send-pr in Emacs, Next: send-pr from the shell, Prev: using send-pr, Up: Invoking send-pr - -Using `send-pr' from within Emacs -================================= - - You can use an interactive `send-pr' interface from within GNU Emacs -to fill out your Problem Report. We recommend that you familiarize -yourself with Emacs before using this feature (*note Introduction: -(emacs)Introduction.). - - Call `send-pr' with `M-x send-pr'.(1) `send-pr' responds with a -Problem Report template preconfigured for the Support Site from which -you received `send-pr'. (If you use `send-pr' locally, the default -Support Site is probably your local site.) - - You may also submit problem reports to different Support Sites from -the default site. To use this feature, invoke `send-pr' with - - C-u M-x send-pr - - `send-pr' prompts you for the name of a SITE. SITE is an alias on -your local machine which points to an alternate Support Site. - - `send-pr' displays the template and prompts you in the minibuffer -with the line: - >Category: other - -Delete the default value `other' *in the minibuffer* and replace it -with the keyword corresponding to your problem (the list of valid -categories is in the topmost section of the PR template). For example, -if the problem you wish to report has to do with the GNU C compiler, -and your support organization accepts bugs submitted for this program -under the category `gcc', delete `other' and then type `gcc[RET]'. -`send-pr' replaces the line - - >Category: - -in the template with - - >Category: gcc - -and moves on to another field. - - `send-pr' provides name completion in the minibuffer. For instance, -you can also type `gc[TAB]', and `send-pr' attempts to complete the -entry for you. Typing `g[TAB]' may not have the same effect if several -possible entries begin with `g'. In that case `send-pr' cannot -complete the entry because it cannot determine whether you mean `gcc' -or, for example, `gdb', if both of those are possible categories. -`send-pr' continues to prompt you for a valid entry until you enter one. - - `send-pr' prompts you interactively to enter each field for which -there is a range of specific choices. If you attempt to enter a value -which is not in the range of acceptable entries, `send-pr' responds -with `[No match]' and allows you to change the entry until it contains -an acceptable value. This avoids unusable information (at least in -these fields) and also avoids typographical errors which could cause -problems later. - - `send-pr' prompts you for the following fields: - - >Category: - >Confidential: (*default*: no) - >Severity: (*default*: serious) - >Priority: (*default*: medium) - >Class: (*default*: sw-bug) - >Release: - >Synopsis: (*this value is copied to `Subject:'*) - -After you complete these fields, `send-pr' places the cursor in the -`>Description:' field and displays the message - - To send the problem report use: C-c C-c - -in the minibuffer. At this point, edit the file in the main buffer to -reflect your specific problem, putting relevant information in the -proper fields. *Note An Example::, for a sample Problem Report. - - `send-pr' provides a few key bindings to make moving around in a -template buffer more simple: - -`C-c C-f' -`M-x change-field' - Changes the field under the cursor. `edit-pr' prompts you for a - new value. - -`M-C-b' -`M-x gnats-backward-field' - Moves the cursor to the beginning of the value of the current - field. - -`M-C-f' -`M-x gnats-forward-field' - Moves the cursor to the end of the value of the current field. - -`M-p' -`M-x gnats-previous-field' - Moves the cursor back one field to the beginning of the value of - the previous field. - -`M-n' -`M-x gnats-next-field' - Moves the cursor forward one field to the beginning of the value - of the next field. - - `send-pr' takes over again when you type `C-c C-c' to send the -message. `send-pr' reports any errors in a separate buffer, which -remains in existence until you send the PR properly (or, of course, -until you explicitly kill the buffer). - - For detailed instructions on using Emacs, see *Note Introduction: -(emacs)Introduction. - - ---------- Footnotes ---------- - - (1) If typing `M-x send-pr' doesn't work, see your system -administrator for help loading `send-pr' into Emacs. - - -File: send-pr.info, Node: send-pr from the shell, Next: Helpful hints, Prev: send-pr in Emacs, Up: Invoking send-pr - -Invoking `send-pr' from the shell -================================= - - send-pr [ SITE ] - [ -f PROBLEM-REPORT | --file PROBLEM-REPORT ] - [ -t MAIL-ADDRESS | --to MAIL-ADDRESS ] - [ --request-id ] - [ -L | --list ] [ -P | --print ] - [ -V | --version] [ -h | --help ] - - SITE is an alias on your local machine which points to an address -used by a Support Site. If this argument is not present, the default -SITE is usually the site which you received `send-pr' from, or your -local site if you use GNATS locally. (*Note Setting a default SITE: -default site.) - - Invoking `send-pr' with no options calls the editor named in your -environment variable `EDITOR' on a default PR template. If the -environment variable `PR_FORM' is set, its value is used as a file name -which contains a valid template. If `PR_FORM' points to a missing or -unreadable file, or if the file is empty, `send-pr' generates an error -message and opens the editor on a default template. - -`-f PROBLEM-REPORT' -`--file PROBLEM-REPORT' - Specifies a file, PROBLEM-REPORT, where a completed Problem Report - already exists. `send-pr' sends the contents of the file without - invoking an editor. If PROBLEM-REPORT is `-', `send-pr' reads - from standard input. - -`-t MAIL-ADDRESS' -`--to MAIL-ADDRESS' - Sends the PR to MAIL-ADDRESS. The default is preset when `send-pr' - is configured. *This option is not recommended*; instead, use the - argument SITE on the command line. - -`--request-id' - Sends a request for a `>Submitter-Id:' to the Support Site. - -`-L' -`--list' - Prints the list of valid `>Category:' values on standard output. - No mail is sent. - -`-P' -`--print' - Displays the PR template. If the variable `PR_FORM' is set in your - environment, the file it specifies is printed. If `PR_FORM' is not - set, `send-pr' prints the standard blank form. If the file - specified by `PR_FORM' doesn't exist, `send-pr' displays an error - message. No mail is sent. - -`-V' -`--version' - Displays the `send-pr' version number and a usage summary. No mail - is sent. - -`-h' -`--help' - Displays a usage summary for `send-pr'. No mail is sent. - - -File: send-pr.info, Node: Helpful hints, Prev: send-pr from the shell, Up: Invoking send-pr - -Helpful hints -============= - - There is no orthodox standard for submitting effective bug reports, -though you might do well to consult the section on submitting bugs for -GNU `gcc' in *Note Reporting Bugs: (gcc)Bugs, by Richard Stallman. -This section contains instructions on what kinds of information to -include and what kinds of mistakes to avoid. - - In general, common sense (assuming such an animal exists) dictates -the kind of information that would be most helpful in tracking down and -resolving problems in software. - * Include anything *you* would want to know if you were looking at - the report from the other end. There's no need to include every - minute detail about your environment, although anything that might - be different from someone else's environment should be included - (your path, for instance). - - * Narratives are often useful, given a certain degree of restraint. - If a person responsible for a bug can see that A was executed, and - then B and then C, knowing that sequence of events might trigger - the realization of an intermediate step that was missing, or an - extra step that might have changed the environment enough to cause - a visible problem. Again, restraint is always in order ("I set - the build running, went to get a cup of coffee (Columbian, cream - but no sugar), talked to Sheila on the phone, and then THIS - happened...") but be sure to include anything relevant. - - * Richard Stallman writes, "The fundamental principle of reporting - bugs usefully is this: *report all the facts*. If you are not sure - whether to state a fact or leave it out, state it!" This holds - true across all problem reporting systems, for computer software - or social injustice or motorcycle maintenance. It is especially - important in the software field due to the major differences - seemingly insignificant changes can make (a changed variable, a - missing semicolon, etc.). - - * Submit only *one* problem with each Problem Report. If you have - multiple problems, use multiple PRs. This aids in tracking each - problem and also in analyzing the problems associated with a given - program. - - * It never hurts to do a little research to find out if the bug - you've found has already been reported. Most software releases - contain lists of known bugs in the Release Notes which come with - the software; see your system administrator if you don't have a - copy of these. - - * The more closely a PR adheres to the standard format, the less - interaction is required by a database administrator to route the - information to the proper place. Keep in mind that anything that - requires human interaction also requires time that might be better - spent in actually fixing the problem. It is therefore in - everyone's best interest that the information contained in a PR be - as correct as possible (in both format and content) at the time of - submission. - - -File: send-pr.info, Node: An Example, Next: Installing send-pr, Prev: Invoking send-pr, Up: Top - -An Example -********** - - Cygnus Support in Mountain View, CA, uses GNATS and `send-pr' -extensively for their support activities. As a support company, Cygnus -finds problem tracking to be a crucial part of everyday business. -Cygnus supports the GNU compiling tools (including GNATS and `send-pr') -over several many platforms - - With each shipment of the Cygnus Support Developer's Kit, customers -receive the latest version of `send-pr', which contains an up-to-date -listing of valid categories (values for the `>Category:' field). Using -these tools, Cygnus' customers can communicate their problems to Cygnus -effectively and receive automatic confirmation of receipt as well as -notification of changes in the status of their reported problems. Much -of Cygnus' support mechanism relies on electronic mail. - - As an example, let's pretend we're a customer of Cygnus Support, and -that we're having a problem compiling some of our software using the -GNU C compiler, which Cygnus supports. - - Assume that we're getting an error in our `bifrabulator' program -wherein the `prestidigitation' routines don't match with the -`whatsitsname'. We've made sure we're following the rules of the -program and checked the Release Notes from Cygnus and found that the bug -isn't already known. In other words, we're pretty sure we've found a -bug. - - Our first step is to call `send-pr'. It really doesn't matter -whether we use `send-pr' from the shell or from within Emacs. Indeed, -if we use Emacs as a primary editor, calling `send-pr' from the shell -is likely to start `send-pr' in an Emacs buffer anyway. So, since our -company, *Imaginary Software, Ltd.*, uses GNU software extensively, -we're pretty familiar with Emacs, so from within Emacs we type - M-x send-pr - -and we're greeted with the following screen: - - SEND-PR: -*- text -*- - SEND-PR: Lines starting with `SEND-PR' will be removed - SEND-PR: automatically as well as all comments (the text - SEND-PR: below enclosed in `<' and `>'). - SEND-PR: Please consult the manual if you are not sure - SEND-PR: how to fill out a problem report. - SEND-PR: - SEND-PR: Choose from the following categories: - SEND-PR: - SEND-PR: bfd binutils bison - SEND-PR: byacc clib config cvs diff - SEND-PR: doc emacs flex g++ gas - SEND-PR: gcc gdb glob gprof grep - SEND-PR: info ispell kerberos ld libg++ - SEND-PR: libiberty make makeinfo mas newlib - SEND-PR: other patch rcs readline send-pr - SEND-PR: test texindex texinfo texinfo.tex - SEND-PR: bifrabulator <---*note: this one is fake* - SEND-PR: - To: cygnus-bugs@cygnus.com - Subject: - From: jeffrey@imaginary.com - Reply-To: jeffrey@imaginary.com - X-send-pr-version: send-pr 3.2 - - >Submitter-Id: imaginary - >Originator: Jeffrey Osier - >Organization: - Imaginary Software, Ltd. - >Confidential: <[ yes | no ] (one line)> - >Synopsis: - >Severity: <[ non-critical | serious | critical ] (one line)> - >Priority: <[ low | medium | high ] (one line)> - >Category: - >Class: <[sw-bug|doc-bug|change-request|support](oneline)> - >Release: - >Environment: - - System: SunOS imaginary.com 4.1.1 1 sun4 - Architecture: sun4 - - >Description: - - >How-To-Repeat: - - >Fix: - -----Emacs: *send-pr* (send-pr Fill)----All------------------ - >Category: other[] - - We know from past experience that we need to set certain information -into each field, so we compile all the information we know about our -problem. We have some sample code which we know should work, even -though it doesn't, so we'll include that. Below is the completed PR; -we send this using `C-c C-c'. (The comments have been truncated). - - SEND-PR: Lines starting with `SEND-PR' will be removed - SEND-PR: automatically as well as all comments (the text - SEND-PR: ... - SEND-PR: - To: cygnus-bugs@cygnus.com - Subject: bifrabulator routines don't match - From: jeffrey@imaginary.com - Reply-To: jeffrey@imaginary.com - X-send-pr-version: send-pr 3.2 - - >Submitter-Id: imaginary - >Originator: Jeffrey Osier - >Organization: - Imaginary Software, Ltd. - >Confidential: no - >Synopsis: bifrabulator routines don't match - >Severity: serious - >Priority: medium - >Category: bifrabulator - >Class: sw-bug - >Release: progressive-930101 - >Environment: - System: SunOS imaginary.com 4.1.1 1 sun4 - Architecture: sun4 (SPARC) - - >Description: - the following code I fed into the bifrabulator came back - with a strange error. apparently, the prestidigitation - routine doesn't match with the whatsitsname in all cases. - - >How-To-Repeat: - call the bifrabulator on the following code. - *code sample...* - - >Fix: - -----Emacs: *send-pr* (send-pr Fill)----All------------------ - To send the problem report use: C-c C-c - - We type `C-c C-c', and off it goes. Now, we depend on Cygnus -Support to figure out the answer to our problem. - - Soon afterward, we get the following message from Cygnus: - - From: gnats (GNATS management) - Sender: gnats-admin - Reply-To: hacker@cygnus.com - To: jeffrey@imaginary.com - Subject: Re: bifrabulator/1425: routines don't match - - Thank you very much for your problem report. - It has the internal identification: g++/1425. - The individual assigned to look at your bug is: hacker - (F.B. Hacker) - - Category: bifrabulator - Responsible: hacker - Synopsis: bifrabulator routines don't match - Arrival-Date: Sat Feb 30 03:12:55 1993 - -This is our receipt that the bug has been accepted and forwarded to the -responsible party. - -A while later, we get the analysis: - - To: jeffrey@imaginary.com - From: hacker@cygnus.com - Subject: Re: bifrabulator/1425: routines don't match - Reply-To: hacker@cygnus.com - - Got your message, Jeff. It seems that the bifrabulator was - confusing the prestidigitation routines with the realitychecker - when lexically parsing the whatsitsname. - - I'm working on robustisizing the bifrabulator now. - - How about lunch next week? - -- - F.B. Hacker - Cygnus Support, Mountain View, CA 415 903 1400 - #include - -About the same time, we get another message from Cygnus. - - From: hacker@cygnus.com - To: jeffrey@imaginary.com - Subject: Re: bifrabulator/1425: doesn't match prestidig - Reply-To: hacker@cygnus.com - - - `F.B. Hacker' changed the state to `analyzed'. - - State-Changed-From-To: open-analyzed - State-Changed-By: hacker - State-Changed-When: Fri Feb 31 1993 08:59:16 1993 - State-Changed-Why: - figured out the problem, working on a patch this afternoon - -- - F.B. Hacker - Cygnus Support, Mountain View, CA 415 903 1400 - #include - -The bug has now been analyzed, and Cygnus is working on a solution. - -Sometime later, we get more mail from F.B.: - - To: jeffrey@imaginary.com - From: hacker@cygnus.com - Subject: Re: bifrabulator/1425: routines don't match - Reply-To: hacker@cygnus.com - - There's a patch now that you can ftp over and check out. - - Hey, that joke you sent me was great! The one about the - strings walking into a bar... my boss laughed for an hour! - -- - F.B. Hacker - Cygnus Support, Mountain View, CA 415 903 1400 - #include - - From: hacker@cygnus.com - To: jeffrey@imaginary.com - Subject: Re: bifrabulator/1425: doesn't match prestidig - Reply-To: hacker@cygnus.com - - - `F.B. Hacker' changed the state to `feedback'. - - State-Changed-From-To: analyzed-feedback - State-Changed-By: hacker - State-Changed-When: Fri Feb 31 1993 23:43:16 1993 - State-Changed-Why: - got the patch finished, notified Jeff at Imaginary Software - -- - F.B. Hacker - Cygnus Support, Mountain View, CA 415 903 1400 - #include - -The bug has gone into "feedback" status now, until we get the patch, -install it and test it. When everything tests well, we can mail F.B. -back and tell him the bug's been fixed, and he can change the state of -the PR from "feedback" to "closed". - - Following is a list of valid `>Category:' entries that are supported -by Cygnus. - -* Menu: - -* Valid Categories:: - - -File: send-pr.info, Node: Valid Categories, Up: An Example - -Valid Categories -================ - -`bfd' - GNU binary file descriptor library. - -`bifrabulator' - This one doesn't actually exist. - -`binutils' - GNU utilities for binary files (`ar', `nm', `size'...). - -`bison' - GNU parser generator. - -`byacc' - Free parser generator. - -`config' - Cygnus Support Software configuration and installation. - -`cvs' - Concurrent Version System. - -`diff' - GNU `diff' program. - -`doc' - Documentation and manuals. - -`emacs' - GNU Emacs editor and related functions. - -`flex' - GNU lexical analyzer. - -`g++' - GNU C++ compiler. - -`gas' - GNU assembler. - -`gcc' - GNU C compiler. - -`gdb' - GNU source code debugger. - -`glob' - The filename globbing functions. - -`gprof' - GNU profiler. - -`grep' - GNU `grep' program. - -`info' - GNU `info' hypertext reader. - -`ispell' - GNU spelling checker. - -`kerberos' - Kerberos authentication system. - -`ld' - GNU linker. - -`libc' - Cygnus Support C Support Library. - -`libg++' - GNU C++ class library. - -`libiberty' - GNU `libiberty' library. - -`libm' - Cygnus Support C Math Library. - -`make' - GNU `make' program. - -`makeinfo' - GNU utility to build Info files from Texinfo documents. - -`mas' - GNU Motorola syntax assembler. - -`newlib' - Cygnus Support C Support and Math Libraries. - -`patch' - GNU bug patch program. - -`gnats' - GNU Problem Report Management System. - -`rcs' - Revision Control System. - -`readline' - GNU `readline' library. - -`send-pr' - GNU Problem Report submitting program. - -`test' - Category to use when testing `send-pr'. - -`texindex' - GNU documentation indexing utility. - -`texinfo' - GNU documentation macros. - -`other' - Anything which is not covered by the above categories. - - -File: send-pr.info, Node: Installing send-pr, Next: Index, Prev: An Example, Up: Top - -Installing `send-pr' on your system -*********************************** - - If you receive `send-pr' as part of a larger software distribution, -it probably gets installed when the full distribution is installed. If -you are using GNATS at your site as well, you must decide where -`send-pr' sends Problem Reports by default; see *Note Setting a default -SITE: default site. - -* Menu: - -* installation:: installing `send-pr' by itself -* default site:: setting a default site - - -File: send-pr.info, Node: installation, Next: default site, Up: Installing send-pr - -Installing `send-pr' by itself -============================== - - Install `send-pr' by following these steps (you may need `root' -access in order to change the `aliases' file and to install `send-pr'): - - * Unpack the distribution into a directory which we refer to as - SRCDIR. - - * Edit the file `Makefile' to reflect local conventions. - Specifically, you should edit the variable `prefix' to alter the - installation location. The default is `/usr/local'. All files are - installed under `prefix' (see below). - - * *Run* - make all install [ info ] [ install-info ] [ clean ] - - The targets mean the following: - - `all' - Builds `send-pr' and `install-sid' - - `install' - Installs the following: - - `install-sid' - `send-pr' - into `PREFIX/bin' - - `send-pr.1' - into `PREFIX/man/man1' - - `SITE' - the list of valid CATEGORIES for the Support Site from - which you received `send-pr', installed as - `PREFIX/lib/gnats/SITE' - - `send-pr.el' - into `PREFIX/lib/emacs/lisp'(1) - - `info (*optional*)' - Builds `send-pr.info' from `send-pr.texi' - (`send-pr.info' is included with this distribution) - - `install-info (*optional*)' - Installs `send-pr.info' into `PREFIX/info' - - `clean (*optional*)' - Removes all intermediary build files that can be rebuilt from - source code - - * Run - - install-sid YOUR-SID - - where YOUR-SID is the identification code you received with - `send-pr'. `send-pr' automatically inserts this value into the - template field `>Submitter-Id:'. If you've downloaded `send-pr' - from the Net, use `net' for this value. - - * Place the following line in `PREFIX/lib/emacs/lisp/default.el', or - instruct your users to place the following line in their `.emacs' - files: - - (autoload 'send-pr "send-pr" "Submit a Problem Report." t) - - * Create a mail alias for the Support Site from which you received - `send-pr', and for every site with which you wish to use `send-pr' - to communicate. Each alias must have a suffix of `-gnats'. The - Support Site(s) will provide the correct addresses where these - aliases should point. For instance, edit your mail aliases file - to contain something like: - - # support sites; for use with send-pr - cygnus-gnats: bugs@cygnus.com # Cygnus Support - bumblebee-gnats: bumblebugs@bumblebee.com # Bumblebee Inc. - mycompany-gnats: bugs@my.company.com (*if you use GNATS locally*) - - `send-pr' automatically searches for these aliases when you type - - send-pr cygnus - send-pr bumblebee - send-pr SITE... - - `send-pr' also uses SITE to determine the categories of problems - accepted by the site in question by looking in - - PREFIX/lib/gnats/SITE - - ---------- Footnotes ---------- - - (1) If your main Emacs lisp repository is in a different directory -from this, substitute that directory for `PREFIX/lib/emacs/lisp'. - - -File: send-pr.info, Node: default site, Prev: installation, Up: Installing send-pr - -Setting a default SITE -====================== - - `send-pr' is capable of sending Problem Reports to any number of -Support Sites, using mail aliases which have `-gnats' appended them. -`send-pr' automatically appends the suffix, so that when you type - - send-pr SITE - -the Problem Report goes to the address noted in the `aliases' file as -`SITE-gnats'. You can do this in the Emacs version of `send-pr' by -invoking the program with - - C-u M-x send-pr - -You are prompted for SITE. - - SITE is also used to error-check the `>Category:' field, as a -precaution against sending mistaken information (and against sending -information to the wrong site). - - You may also simply type - - send-pr - -from the shell (or `M-x send-pr' in Emacs), and the Problem Report you -generate will be sent to the SITE, which is usually the site from which -you received your distribution of `send-pr'. If you use GNATS at your -own organization, the default is usually your local address for -reporting problems. - - To change this, simply edit the file `Makefile' before installing -and change the line - - GNATS_SITE = SITE - -to reflect the site where you wish to send PRs by default. - - -File: send-pr.info, Node: Index, Prev: Installing send-pr, Up: Top - -Index -***** - -* Menu: - -* >Arrival-Date:: Problem Report fields. -* >Audit-Trail:: Problem Report fields. -* >Category:: Problem Report fields. -* >Class:: Problem Report fields. -* >Confidential:: Problem Report fields. -* >Description:: Problem Report fields. -* >Environment:: Problem Report fields. -* >Fix:: Problem Report fields. -* >How-To-Repeat:: Problem Report fields. -* >Number:: Problem Report fields. -* >Organization:: Problem Report fields. -* >Originator:: Problem Report fields. -* >Priority:: Problem Report fields. -* >Release:: Problem Report fields. -* >Responsible:: Problem Report fields. -* >Severity:: Problem Report fields. -* >State:: Problem Report fields. -* >Submitter-Id:: using send-pr. -* >Submitter-Id:: Problem Report fields. -* >Synopsis:: Problem Report fields. -* >Unformatted:: Problem Report fields. -* Arrival-Date field: Problem Report fields. -* Audit-Trail field: Problem Report fields. -* bifrabulator: An Example. -* Category field: Problem Report fields. -* Class field: Problem Report fields. -* Confidential field: Problem Report fields. -* Description field: Problem Report fields. -* Environment field: Problem Report fields. -* Fix field: Problem Report fields. -* From: header: Mail header fields. -* How-To-Repeat field: Problem Report fields. -* Number field: Problem Report fields. -* Organization field: Problem Report fields. -* Originator field: Problem Report fields. -* Priority field: Problem Report fields. -* Release field: Problem Report fields. -* Reply-To: header: Mail header fields. -* Responsible-Changed--: in >Audit-Trail:: Problem Report fields. -* Responsible-Changed-By: in >Audit-Trail:: Problem Report fields. -* Responsible-Changed-When: in >Audit-Trail:: Problem Report fields. -* Responsible-Changed-Why: in >Audit-Trail:: Problem Report fields. -* Responsible field: Problem Report fields. -* send-pr fields: using send-pr. -* send-pr within Emacs: send-pr in Emacs. -* Severity field: Problem Report fields. -* State-Changed--: in >Audit-Trail:: Problem Report fields. -* State-Changed-By: in >Audit-Trail:: Problem Report fields. -* State-Changed-When: in >Audit-Trail:: Problem Report fields. -* State-Changed-Why: in >Audit-Trail:: Problem Report fields. -* State field: Problem Report fields. -* Subject: header: Mail header fields. -* Submitter-Id field: Problem Report fields. -* Submitter-Id field: using send-pr. -* Synopsis field: Problem Report fields. -* To: header: Mail header fields. -* Unformatted field: Problem Report fields. -* *analyzed* state: States. -* *change-request* class: Problem Report fields. -* *closed* state: States. -* *critical* severity problems: Problem Report fields. -* *doc-bug* class: Problem Report fields. -* *duplicate* class: Problem Report fields. -* *Enumerated* data types: Fields. -* *feedback* state: States. -* *high* priority problems: Problem Report fields. -* *low* priority problems: Problem Report fields. -* *medium* priority problems: Problem Report fields. -* *MultiText* data types: Fields. -* *non-critical* severity problems: Problem Report fields. -* *open* state: States. -* *serious* severity problems: Problem Report fields. -* *support* class: Problem Report fields. -* *suspended* state: States. -* *sw-bug* class: Problem Report fields. -* *Text* data types: Fields. -* an example: An Example. -* appending PRs: using send-pr. -* appending PRs: Problem Report fields. -* automatic notification: States. -* bad Problem Reports: using send-pr. -* blank PR template: An Example. -* command line options: send-pr from the shell. -* comment section in the PR template: using send-pr. -* completed Problem Report: An Example. -* completion in Emacs: send-pr in Emacs. -* confidentiality in PRs: Problem Report fields. -* Cygnus Support: An Example. -* database similarities: Fields. -* default SITE: default site. -* default PR template: An Example. -* details about send-pr: send-pr in detail. -* editing and sending PRs: Invoking send-pr. -* effective problem reporting: Helpful hints. -* Emacs: send-pr in Emacs. -* errors: using send-pr. -* example of a completed PR: An Example. -* example of a default template: An Example. -* example of a list of valid categories: Valid Categories. -* example of a state change: An Example. -* example PR: An Example. -* example Problem Report: Fields. -* field format: Problem Report fields. -* fields: Fields. -* fields - list: Problem Report fields. -* final state ("closed"): States. -* foreword to send-pr: Top. -* format: Fields. -* generating new PRs: Invoking send-pr. -* GNATS: Top. -* GNATS database fields: Problem Report fields. -* GNATS fields - list: Problem Report fields. -* GNU software support: An Example. -* helpful hints: Helpful hints. -* Imaginary Software, Ltd.: An Example. -* information to submit: Helpful hints. -* initial state ("open"): States. -* installation: Installing send-pr. -* installation procedure: installation. -* interactive interface: send-pr in Emacs. -* Internet standard RFC-822: Mail header fields. -* introduction to send-pr: Top. -* invalid Problem Reports: using send-pr. -* invoking send-pr from Emacs: send-pr in Emacs. -* invoking send-pr from the shell: send-pr from the shell. -* invoking send-pr: Invoking send-pr. -* kinds of helpful information: Helpful hints. -* life-cycle of a Problem Report: States. -* listing valid categories: send-pr from the shell. -* mail header fields: Mail header fields. -* mail header section: using send-pr. -* name completion in Emacs: send-pr in Emacs. -* other mail: using send-pr. -* other mail: Problem Report fields. -* overview to send-pr: Top. -* PR confidentiality: Problem Report fields. -* Problem Report data types: Fields. -* Problem Report format: Fields. -* Problem Report states: States. -* Problem Report template: Fields. -* Problem Reports: send-pr in detail. -* related mail: Problem Report fields. -* related mail: using send-pr. -* Report all the facts!: Helpful hints. -* sample Problem Report: Fields. -* saving related mail: Problem Report fields. -* saving related mail: using send-pr. -* sending PRs: Invoking send-pr. -* setting a default SITE: default site. -* shell invocation: send-pr from the shell. -* state change example: An Example. -* state--"analyzed": States. -* state--"closed": States. -* state--"feedback": States. -* state--"open": States. -* state--"suspended": States. -* states of Problem Reports: States. -* subsequent mail: Problem Report fields. -* subsequent mail: using send-pr. -* template: using send-pr. -* template comment section: using send-pr. -* using send-pr from within Emacs: send-pr in Emacs. -* Using and Porting GNU CC: Helpful hints. -* using send-pr: Invoking send-pr. -* valid categories: Valid Categories. - - - -Tag Table: -Node: Top827 -Node: send-pr in detail2851 -Node: States3690 -Node: Fields5122 -Node: Mail header fields8791 -Node: Problem Report fields9656 -Node: Invoking send-pr17045 -Node: using send-pr17502 -Node: send-pr in Emacs24509 -Node: send-pr from the shell28914 -Node: Helpful hints31261 -Node: An Example34366 -Node: Valid Categories43466 -Node: Installing send-pr45285 -Node: installation45852 -Node: default site49077 -Node: Index50334 - -End Tag Table diff --git a/gnu/usr.bin/send-pr/send-pr.texi b/gnu/usr.bin/send-pr/send-pr.texi deleted file mode 100644 index b9edd9c..0000000 --- a/gnu/usr.bin/send-pr/send-pr.texi +++ /dev/null @@ -1,657 +0,0 @@ -\input texinfo @c -*-texinfo-*- -@setfilename send-pr.info -@settitle Reporting Problems Using send-pr - -@setchapternewpage odd - -@include version.texi -@set SENDPR - -@ifinfo -@format -START-INFO-DIR-ENTRY -* send-pr:: Reporting problems--using send-pr -END-INFO-DIR-ENTRY -@end format -@end ifinfo - -@ifinfo -Copyright @copyright{} 1993 Free Software Foundation, Inc. - -Permission is granted to make and distribute verbatim copies of -this manual provided the copyright notice and this permission notice -are preserved on all copies. - -@ignore -Permission is granted to process this file through TeX and print the -results, provided the printed document carries a copying permission -notice identical to this one except for the removal of this paragraph -(this paragraph not being relevant to the printed manual). - -@end ignore - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that -the entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions. -@end ifinfo - -@titlepage -@finalout -@title Reporting Problems -@subtitle Using @code{send-pr}, version @value{VERSION} -@subtitle October 1993 -@author Jeffrey M. Osier -@author Cygnus Support -@page - -@vskip 0pt plus 1filll - -Copyright @copyright{} 1993 Free Software Foundation, Inc. - -Permission is granted to make and distribute verbatim copies of -this manual provided the copyright notice and this permission notice -are preserved on all copies. - -Permission is granted to copy and distribute modified versions of this -manual under the conditions for verbatim copying, provided also that -the entire resulting derived work is distributed under the terms of a -permission notice identical to this one. - -Permission is granted to copy and distribute translations of this manual -into another language, under the above conditions for modified versions. - -@end titlepage - -@c --------------------------------------------------------------- -@node Top -@top Overview -@cindex foreword to @code{send-pr} -@cindex overview to @code{send-pr} -@cindex introduction to @code{send-pr} - -This manual documents @code{send-pr}, -@ifinfo -version @value{VERSION}, -@end ifinfo -which uses electronic mail to submit support questions and problem -reports to a central Support Site. No body of work is perfect, and -support organizations understand this; @code{send-pr} is designed to -allow users who have problems to submit reports of these problems to -sites responsible for supporting the products in question, in a defined -form which can be read by an electronically managed database. - -@cindex GNATS -@code{send-pr} is part of a suite of programs known collectively as -@sc{gnats}, the @sc{gnu} Problem Report Management System. @sc{gnats} -consists of several programs which, used in concert, formulate and -partially administer a database of @dfn{Problem Reports}, or @dfn{PRs}, -at a central Support Site. A PR goes through several states in its -lifetime; @sc{gnats} tracks the PR and all information associated with it -through each state and finally acts as an archive for PRs which have -been @dfn{closed}. - -Because @code{send-pr} exists as a shell (@file{/bin/sh}) script and as -an Elisp file for use with @sc{gnu} Emacs, it can be used from any -machine on your network which can run a shell script and/or Emacs. - -In general, you can use any editor and mailer to submit valid Problem -Reports, as long as the format required by @sc{gnats} is preserved. -@code{send-pr} automates the process, however, and ensures that certain -fields necessary for automatic processing are present. @code{send-pr} -is strongly recommended for all initial problem-oriented correspondence -with your Support Site. The organization you submit Problem Reports to -supplies an address to which further information can be sent; the person -responsible for the category of the problem you report contacts you -directly. - -@menu -* send-pr in detail:: Details about send-pr and GNATS -* Invoking send-pr:: Editing and sending PRs -* An Example:: A working example -* Installing send-pr:: Installing send-pr on your system -* Index:: -@end menu - -@node send-pr in detail -@chapter Details about send-pr and GNATS - -@cindex details about @code{send-pr} -@cindex Problem Reports -A @dfn{Problem Report} is a message that describes a problem you are -having with a body of work. @code{send-pr} organizes this message into -a form which can be understood and automatically processed by @sc{gnats}, -the @sc{gnu} Problem Report Management System. A Problem Report is -organized into @dfn{fields} which contain data describing you, your -organization, and the problem you are announcing (@pxref{Fields,,Problem -Report format}). Problem Reports go through several defined states in -their lifetimes, from @dfn{open} to @dfn{closed} (@pxref{States,,States -of Problem Reports}). - -@menu -* States:: States of Problem Reports -* Fields:: Problem Report format -@end menu - -@include states.texi - -@include fields.texi - -@node Invoking send-pr -@chapter Editing and sending PRs -@cindex editing and sending PRs -@cindex sending PRs -@cindex invoking send-pr -@cindex using send-pr -@cindex generating new PRs - -@include s-usage.texi - -@node An Example -@chapter An Example -@cindex an example -@cindex example PR -@cindex Cygnus Support -@cindex GNU software support - -Cygnus Support in Mountain View, CA, uses @sc{gnats} and @code{send-pr} -extensively for their support activities. As a support company, Cygnus -finds problem tracking to be a crucial part of everyday business. -Cygnus supports the @sc{gnu} compiling tools (including @sc{gnats} and -@code{send-pr}) over several many platforms - -With each shipment of the Cygnus Support Developer's Kit, customers -receive the latest version of @code{send-pr}, which contains an -up-to-date listing of valid categories (values for the @code{>Category:} -field). Using these tools, Cygnus' customers can communicate their -problems to Cygnus effectively and receive automatic confirmation of -receipt as well as notification of changes in the status of their -reported problems. Much of Cygnus' support mechanism relies on -electronic mail. - -As an example, let's pretend we're a customer of Cygnus Support, and -that we're having a problem compiling some of our software using the -@sc{gnu} C compiler, which Cygnus supports. - -Assume that we're getting an error in our @code{bifrabulator} program -wherein the @samp{prestidigitation} routines don't match with the -@samp{whatsitsname}. We've made sure we're following the rules of the -program and checked the Release Notes from Cygnus and found that the bug -isn't already known. In other words, we're pretty sure we've found a -bug. - -@cindex Imaginary Software, Ltd. -Our first step is to call @code{send-pr}. It really doesn't matter -whether we use @code{send-pr} from the shell or from within Emacs. -Indeed, if we use Emacs as a primary editor, calling @code{send-pr} from -the shell is likely to start @code{send-pr} in an Emacs buffer anyway. -So, since our company, @emph{Imaginary Software, Ltd.}, uses @sc{gnu} -software extensively, we're pretty familiar with Emacs, so from within -Emacs we type -@smallexample -M-x send-pr -@end smallexample -@noindent -and we're greeted with the following screen: - -@cindex default PR template -@cindex example of a default template -@cindex blank PR template -@cindex @code{bifrabulator} -@cartouche -@smallexample -SEND-PR: -*- text -*- -SEND-PR: Lines starting with `SEND-PR' will be removed -SEND-PR: automatically as well as all comments (the text -SEND-PR: below enclosed in `<' and `>'). -SEND-PR: Please consult the manual if you are not sure -SEND-PR: how to fill out a problem report. -SEND-PR: -SEND-PR: Choose from the following categories: -SEND-PR: -SEND-PR: bfd binutils bison -SEND-PR: byacc clib config cvs diff -SEND-PR: doc emacs flex g++ gas -SEND-PR: gcc gdb glob gprof grep -SEND-PR: info ispell kerberos ld libg++ -SEND-PR: libiberty make makeinfo mas newlib -SEND-PR: other patch rcs readline send-pr -SEND-PR: test texindex texinfo texinfo.tex -SEND-PR: bifrabulator <---@emph{note: this one is fake} -SEND-PR: -To: cygnus-bugs@@cygnus.com -Subject: -From: jeffrey@@imaginary.com -Reply-To: jeffrey@@imaginary.com -X-send-pr-version: send-pr @value{VERSION} - ->Submitter-Id: imaginary ->Originator: Jeffrey Osier ->Organization: -Imaginary Software, Ltd. ->Confidential: <[ yes | no ] (one line)> ->Synopsis: ->Severity: <[ non-critical | serious | critical ] (one line)> ->Priority: <[ low | medium | high ] (one line)> ->Category: ->Class: <[sw-bug|doc-bug|change-request|support](oneline)> ->Release: ->Environment: - -System: SunOS imaginary.com 4.1.1 1 sun4 -Architecture: sun4 - ->Description: - ->How-To-Repeat: - ->Fix: -@iftex -@hrule -@end iftex ------Emacs: *send-pr* (send-pr Fill)----All------------------ -@iftex -@hrule -@end iftex ->Category: other[] -@end smallexample -@end cartouche -@page -We know from past experience that we need to set certain information into -each field, so we compile all the information we know about our problem. -We have some sample code which we know should work, even though it -doesn't, so we'll include that. Below is the completed PR; we send this -using @kbd{C-c C-c}. (The comments have been truncated). - -@cindex completed Problem Report -@cindex example of a completed PR -@cartouche -@smallexample -SEND-PR: Lines starting with `SEND-PR' will be removed -SEND-PR: automatically as well as all comments (the text -SEND-PR: @dots{} -SEND-PR: -To: cygnus-bugs@@cygnus.com -Subject: bifrabulator routines don't match -From: jeffrey@@imaginary.com -Reply-To: jeffrey@@imaginary.com -X-send-pr-version: send-pr @value{VERSION} - ->Submitter-Id: imaginary ->Originator: Jeffrey Osier ->Organization: -Imaginary Software, Ltd. ->Confidential: no ->Synopsis: bifrabulator routines don't match ->Severity: serious ->Priority: medium ->Category: bifrabulator ->Class: sw-bug ->Release: progressive-930101 ->Environment: -System: SunOS imaginary.com 4.1.1 1 sun4 -Architecture: sun4 (SPARC) - ->Description: - the following code I fed into the bifrabulator came back - with a strange error. apparently, the prestidigitation - routine doesn't match with the whatsitsname in all cases. - ->How-To-Repeat: - call the bifrabulator on the following code. - @emph{code sample@dots{}} - ->Fix: -@iftex -@hrule -@end iftex ------Emacs: *send-pr* (send-pr Fill)----All------------------ -@iftex -@hrule -@end iftex -To send the problem report use: C-c C-c -@end smallexample -@end cartouche - -We type @kbd{C-c C-c}, and off it goes. Now, we depend on Cygnus -Support to figure out the answer to our problem. - -Soon afterward, we get the following message from Cygnus: - -@smallexample -@group -From: gnats (GNATS management) -Sender: gnats-admin -Reply-To: hacker@@cygnus.com -To: jeffrey@@imaginary.com -Subject: Re: bifrabulator/1425: routines don't match - -Thank you very much for your problem report. -It has the internal identification: g++/1425. -The individual assigned to look at your bug is: hacker -(F.B. Hacker) - -Category: bifrabulator -Responsible: hacker -Synopsis: bifrabulator routines don't match -Arrival-Date: Sat Feb 30 03:12:55 1993 -@end group -@end smallexample - -@noindent -This is our receipt that the bug has been accepted and forwarded to the -responsible party. - -@noindent -A while later, we get the analysis: - -@smallexample -@group -To: jeffrey@@imaginary.com -From: hacker@@cygnus.com -Subject: Re: bifrabulator/1425: routines don't match -Reply-To: hacker@@cygnus.com - -Got your message, Jeff. It seems that the bifrabulator was -confusing the prestidigitation routines with the realitychecker -when lexically parsing the whatsitsname. - -I'm working on robustisizing the bifrabulator now. - -How about lunch next week? --- -F.B. Hacker -Cygnus Support, Mountain View, CA 415 903 1400 -#include -@end group -@end smallexample - -@noindent -About the same time, we get another message from Cygnus. - -@cindex state change example -@cindex example of a state change -@smallexample -@group -From: hacker@@cygnus.com -To: jeffrey@@imaginary.com -Subject: Re: bifrabulator/1425: doesn't match prestidig -Reply-To: hacker@@cygnus.com - - - `F.B. Hacker' changed the state to `analyzed'. - -State-Changed-From-To: open-analyzed -State-Changed-By: hacker -State-Changed-When: Fri Feb 31 1993 08:59:16 1993 -State-Changed-Why: - figured out the problem, working on a patch this afternoon --- -F.B. Hacker -Cygnus Support, Mountain View, CA 415 903 1400 -#include -@end group -@end smallexample - -@noindent -The bug has now been analyzed, and Cygnus is working on a solution. - -@noindent -Sometime later, we get more mail from F.B.: - -@smallexample -@group -To: jeffrey@@imaginary.com -From: hacker@@cygnus.com -Subject: Re: bifrabulator/1425: routines don't match -Reply-To: hacker@@cygnus.com - -There's a patch now that you can ftp over and check out. - -Hey, that joke you sent me was great! The one about the -strings walking into a bar... my boss laughed for an hour! --- -F.B. Hacker -Cygnus Support, Mountain View, CA 415 903 1400 -#include -@end group -@end smallexample -@sp 2 -@smallexample -@group -From: hacker@@cygnus.com -To: jeffrey@@imaginary.com -Subject: Re: bifrabulator/1425: doesn't match prestidig -Reply-To: hacker@@cygnus.com - - - `F.B. Hacker' changed the state to `feedback'. - -State-Changed-From-To: analyzed-feedback -State-Changed-By: hacker -State-Changed-When: Fri Feb 31 1993 23:43:16 1993 -State-Changed-Why: - got the patch finished, notified Jeff at Imaginary Software --- -F.B. Hacker -Cygnus Support, Mountain View, CA 415 903 1400 -#include -@end group -@end smallexample - -@noindent -The bug has gone into @dfn{feedback} status now, until we get the patch, -install it and test it. When everything tests well, we can mail F.B. -back and tell him the bug's been fixed, and he can change the state of -the PR from @dfn{feedback} to @dfn{closed}. - -Following is a list of valid @samp{>Category:} entries that are -supported by Cygnus. - -@menu -* Valid Categories:: -@end menu - -@c FIXME - is this list up to date? -@include categ.texi - -@node Installing send-pr -@appendix Installing @code{send-pr} on your system -@cindex installation - -If you receive @code{send-pr} as part of a larger software distribution, -it probably gets installed when the full distribution is installed. If -you are using @sc{gnats} at your site as well, you must decide where -@code{send-pr} sends Problem Reports by default; see @ref{default site,, -Setting a default @var{site}}. - -@menu -* installation:: installing `send-pr' by itself -* default site:: setting a default site -@end menu - -@node installation -@section Installing @code{send-pr} by itself -@cindex installation procedure - -Install @code{send-pr} by following these steps (you may need -@code{root} access in order to change the @file{aliases} file and to -install @code{send-pr}): - -@itemize @bullet -@item -Unpack the distribution into a directory which we refer to as -@var{srcdir}. - -@item -Edit the file @file{Makefile} to reflect local conventions. -Specifically, you should edit the variable @samp{prefix} to alter the -installation location. The default is @file{/usr/local}. All files are -installed under @samp{prefix} (see below). - -@item @emph{Run} -@smallexample -make all install [ info ] [ install-info ] [ clean ] -@end smallexample - -@noindent -The targets mean the following: - -@table @code -@item all -Builds @code{send-pr} and @code{install-sid} - -@item install -Installs the following: - -@table @code -@item install-sid -@itemx send-pr -into @file{@var{prefix}/bin} - -@item send-pr.1 -into @file{@var{prefix}/man/man1} - -@item @var{site} -the list of valid @var{categories} for the Support Site from which you -received @code{send-pr}, installed as -@w{@file{@var{prefix}/lib/gnats/@var{site}}} - -@item send-pr.el -into @w{@file{@var{prefix}/lib/emacs/lisp}}@footnote{If your main Emacs -lisp repository is in a different directory from this, substitute that -directory for @w{@file{@var{prefix}/lib/emacs/lisp}}.} -@end table - -@item info (@emph{optional}) -Builds @file{send-pr.info} from @file{send-pr.texi}@* -@c FIXME - is this still true? -(@file{send-pr.info} is included with this distribution) - -@item install-info (@emph{optional}) -Installs @file{send-pr.info} into @w{@file{@var{prefix}/info}} - -@item clean (@emph{optional}) -Removes all intermediary build files that can be rebuilt from source -code -@end table - -@item -Run - -@smallexample -install-sid @var{your-sid} -@end smallexample - -@noindent -where @var{your-sid} is the identification code you received with -@w{@code{send-pr}}. @code{send-pr} automatically inserts this value -into the template field @samp{>Submitter-Id:}. If you've downloaded -@code{send-pr} from the Net, use @samp{net} for this value. - -@item -Place the following line in -@w{@file{@var{prefix}/lib/emacs/lisp/default.el}}, or instruct your -users to place the following line in their @file{.emacs} files: - -@smallexample -(autoload 'send-pr "send-pr" "Submit a Problem Report." t) -@end smallexample - -@item -Create a mail alias for the Support Site from which you received -@code{send-pr}, and for every site with which you wish to use -@code{send-pr} to communicate. Each alias must have a suffix of -@samp{-gnats}. The Support Site(s) will provide the correct addresses -where these aliases should point. For instance, edit your mail aliases -file to contain something like: - -@smallexample -# support sites; for use with send-pr -cygnus-gnats: bugs@@cygnus.com # Cygnus Support -bumblebee-gnats: bumblebugs@@bumblebee.com # Bumblebee Inc. -mycompany-gnats: bugs@@my.company.com (@emph{if you use @sc{gnats} locally}) -@end smallexample - -@code{send-pr} automatically searches for these aliases when you type - -@smallexample -send-pr cygnus -send-pr bumblebee -send-pr @var{site}@dots{} -@end smallexample - -@noindent -@code{send-pr} also uses @var{site} to determine the categories of -problems accepted by the site in question by looking in - -@smallexample -@var{prefix}/lib/gnats/@var{site} -@end smallexample - -@end itemize - -@node default site -@section Setting a default @var{site} -@cindex default @var{site} -@cindex setting a default @var{site} - -@code{send-pr} is capable of sending Problem Reports to any number of -Support Sites, using mail aliases which have @samp{-gnats} appended them. -@code{send-pr} automatically appends the suffix, so that when you type - -@smallexample -send-pr @var{site} -@end smallexample - -@noindent -the Problem Report goes to the address noted in the @file{aliases} file -as @w{@samp{@var{site}-gnats}}. You can do this in the Emacs version of -@code{send-pr} by invoking the program with - -@smallexample -C-u M-x send-pr -@end smallexample - -@noindent -You are prompted for @var{site}. - -@var{site} is also used to error-check the @samp{>Category:} field, as a -precaution against sending mistaken information (and against sending -information to the wrong site). - -You may also simply type - -@smallexample -send-pr -@end smallexample - -@noindent -from the shell (or @w{@samp{M-x send-pr}} in Emacs), and the Problem -Report you generate will be sent to the @var{site}, which is usually the -site from which you received your distribution of @w{@code{send-pr}}. -If you use @sc{gnats} at your own organization, the default is usually -your local address for reporting problems. - -To change this, simply edit the file @file{Makefile} before installing -and change the line - -@smallexample -GNATS_SITE = @var{site} -@end smallexample - -@noindent -to reflect the site where you wish to send PRs by default. - -@c --------------------------------------------------------------- -@node Index -@unnumbered Index - -@printindex cp - -@c --------------------------------------------------------------- -@contents -@bye diff --git a/gnu/usr.bin/tar/regex.c b/gnu/usr.bin/tar/regex.c deleted file mode 100644 index febdb71..0000000 --- a/gnu/usr.bin/tar/regex.c +++ /dev/null @@ -1,4923 +0,0 @@ -/* Extended regular expression matching and search library, - version 0.11. - (Implements POSIX draft P10003.2/D11.2, except for - internationalization features.) - - Copyright (C) 1993 Free Software Foundation, Inc. - - 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* AIX requires this to be the first thing in the file. */ -#if defined (_AIX) && !defined (REGEX_MALLOC) - #pragma alloca -#endif - -#define _GNU_SOURCE - -/* We need this for `regex.h', and perhaps for the Emacs include files. */ -#include -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -/* The `emacs' switch turns on certain matching commands - that make sense only in Emacs. */ -#ifdef emacs - -#include "lisp.h" -#include "buffer.h" -#include "syntax.h" - -/* Emacs uses `NULL' as a predicate. */ -#undef NULL - -#else /* not emacs */ - -/* We used to test for `BSTRING' here, but only GCC and Emacs define - `BSTRING', as far as I know, and neither of them use this code. */ -#if HAVE_STRING_H || STDC_HEADERS -#include -#ifndef bcmp -#define bcmp(s1, s2, n) memcmp ((s1), (s2), (n)) -#endif -#ifndef bcopy -#define bcopy(s, d, n) memcpy ((d), (s), (n)) -#endif -#ifndef bzero -#define bzero(s, n) memset ((s), 0, (n)) -#endif -#else -#include -#endif - -#ifdef STDC_HEADERS -#include -#else -char *malloc (); -char *realloc (); -#endif - - -/* Define the syntax stuff for \<, \>, etc. */ - -/* This must be nonzero for the wordchar and notwordchar pattern - commands in re_match_2. */ -#ifndef Sword -#define Sword 1 -#endif - -#ifdef SYNTAX_TABLE - -extern char *re_syntax_table; - -#else /* not SYNTAX_TABLE */ - -/* How many characters in the character set. */ -#define CHAR_SET_SIZE 256 - -static char re_syntax_table[CHAR_SET_SIZE]; - -static void -init_syntax_once () -{ - register int c; - static int done = 0; - - if (done) - return; - - bzero (re_syntax_table, sizeof re_syntax_table); - - for (c = 0; c < CHAR_SET_SIZE; c++) - if (isalnum(c)) - re_syntax_table[c] = Sword; - - re_syntax_table['_'] = Sword; - - done = 1; -} - -#endif /* not SYNTAX_TABLE */ - -#define SYNTAX(c) re_syntax_table[c] - -#endif /* not emacs */ - -/* Get the interface, including the syntax bits. */ -#include "regex.h" - -/* isalpha etc. are used for the character classes. */ - -#ifdef isblank -#define ISBLANK(c) isblank (c) -#else -#define ISBLANK(c) ((c) == ' ' || (c) == '\t') -#endif -#ifdef isgraph -#define ISGRAPH(c) isgraph (c) -#else -#define ISGRAPH(c) (isprint (c) && !isspace (c)) -#endif - -#define ISPRINT(c) isprint (c) -#define ISDIGIT(c) isdigit (c) -#define ISALNUM(c) isalnum (c) -#define ISALPHA(c) isalpha (c) -#define ISCNTRL(c) iscntrl (c) -#define ISLOWER(c) islower (c) -#define ISPUNCT(c) ispunct (c) -#define ISSPACE(c) isspace (c) -#define ISUPPER(c) isupper (c) -#define ISXDIGIT(c) isxdigit (c) - -#ifndef NULL -#define NULL 0 -#endif - -/* We remove any previous definition of `SIGN_EXTEND_CHAR', - since ours (we hope) works properly with all combinations of - machines, compilers, `char' and `unsigned char' argument types. - (Per Bothner suggested the basic approach.) */ -#undef SIGN_EXTEND_CHAR -#if __STDC__ -#define SIGN_EXTEND_CHAR(c) ((signed char) (c)) -#else /* not __STDC__ */ -/* As in Harbison and Steele. */ -#define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128) -#endif - -/* Should we use malloc or alloca? If REGEX_MALLOC is not defined, we - use `alloca' instead of `malloc'. This is because using malloc in - re_search* or re_match* could cause memory leaks when C-g is used in - Emacs; also, malloc is slower and causes storage fragmentation. On - the other hand, malloc is more portable, and easier to debug. - - Because we sometimes use alloca, some routines have to be macros, - not functions -- `alloca'-allocated space disappears at the end of the - function it is called in. */ - -#ifdef REGEX_MALLOC - -#define REGEX_ALLOCATE malloc -#define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize) - -#else /* not REGEX_MALLOC */ - -/* Emacs already defines alloca, sometimes. */ -#ifndef alloca - -/* Make alloca work the best possible way. */ -#ifdef __GNUC__ -#define alloca __builtin_alloca -#else /* not __GNUC__ */ -#if HAVE_ALLOCA_H -#include -#else /* not __GNUC__ or HAVE_ALLOCA_H */ -#ifndef _AIX /* Already did AIX, up at the top. */ -char *alloca (); -#endif /* not _AIX */ -#endif /* not HAVE_ALLOCA_H */ -#endif /* not __GNUC__ */ - -#endif /* not alloca */ - -#define REGEX_ALLOCATE alloca - -/* Assumes a `char *destination' variable. */ -#define REGEX_REALLOCATE(source, osize, nsize) \ - (destination = (char *) alloca (nsize), \ - bcopy (source, destination, osize), \ - destination) - -#endif /* not REGEX_MALLOC */ - - -/* True if `size1' is non-NULL and PTR is pointing anywhere inside - `string1' or just past its end. This works if PTR is NULL, which is - a good thing. */ -#define FIRST_STRING_P(ptr) \ - (size1 && string1 <= (ptr) && (ptr) <= string1 + size1) - -/* (Re)Allocate N items of type T using malloc, or fail. */ -#define TALLOC(n, t) ((t *) malloc ((n) * sizeof (t))) -#define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t))) -#define REGEX_TALLOC(n, t) ((t *) REGEX_ALLOCATE ((n) * sizeof (t))) - -#define BYTEWIDTH 8 /* In bits. */ - -#define STREQ(s1, s2) ((strcmp (s1, s2) == 0)) - -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -typedef char boolean; -#define false 0 -#define true 1 - -/* These are the command codes that appear in compiled regular - expressions. Some opcodes are followed by argument bytes. A - command code can specify any interpretation whatsoever for its - arguments. Zero bytes may appear in the compiled regular expression. - - The value of `exactn' is needed in search.c (search_buffer) in Emacs. - So regex.h defines a symbol `RE_EXACTN_VALUE' to be 1; the value of - `exactn' we use here must also be 1. */ - -typedef enum -{ - no_op = 0, - - /* Followed by one byte giving n, then by n literal bytes. */ - exactn = 1, - - /* Matches any (more or less) character. */ - anychar, - - /* Matches any one char belonging to specified set. First - following byte is number of bitmap bytes. Then come bytes - for a bitmap saying which chars are in. Bits in each byte - are ordered low-bit-first. A character is in the set if its - bit is 1. A character too large to have a bit in the map is - automatically not in the set. */ - charset, - - /* Same parameters as charset, but match any character that is - not one of those specified. */ - charset_not, - - /* Start remembering the text that is matched, for storing in a - register. Followed by one byte with the register number, in - the range 0 to one less than the pattern buffer's re_nsub - field. Then followed by one byte with the number of groups - inner to this one. (This last has to be part of the - start_memory only because we need it in the on_failure_jump - of re_match_2.) */ - start_memory, - - /* Stop remembering the text that is matched and store it in a - memory register. Followed by one byte with the register - number, in the range 0 to one less than `re_nsub' in the - pattern buffer, and one byte with the number of inner groups, - just like `start_memory'. (We need the number of inner - groups here because we don't have any easy way of finding the - corresponding start_memory when we're at a stop_memory.) */ - stop_memory, - - /* Match a duplicate of something remembered. Followed by one - byte containing the register number. */ - duplicate, - - /* Fail unless at beginning of line. */ - begline, - - /* Fail unless at end of line. */ - endline, - - /* Succeeds if at beginning of buffer (if emacs) or at beginning - of string to be matched (if not). */ - begbuf, - - /* Analogously, for end of buffer/string. */ - endbuf, - - /* Followed by two byte relative address to which to jump. */ - jump, - - /* Same as jump, but marks the end of an alternative. */ - jump_past_alt, - - /* Followed by two-byte relative address of place to resume at - in case of failure. */ - on_failure_jump, - - /* Like on_failure_jump, but pushes a placeholder instead of the - current string position when executed. */ - on_failure_keep_string_jump, - - /* Throw away latest failure point and then jump to following - two-byte relative address. */ - pop_failure_jump, - - /* Change to pop_failure_jump if know won't have to backtrack to - match; otherwise change to jump. This is used to jump - back to the beginning of a repeat. If what follows this jump - clearly won't match what the repeat does, such that we can be - sure that there is no use backtracking out of repetitions - already matched, then we change it to a pop_failure_jump. - Followed by two-byte address. */ - maybe_pop_jump, - - /* Jump to following two-byte address, and push a dummy failure - point. This failure point will be thrown away if an attempt - is made to use it for a failure. A `+' construct makes this - before the first repeat. Also used as an intermediary kind - of jump when compiling an alternative. */ - dummy_failure_jump, - - /* Push a dummy failure point and continue. Used at the end of - alternatives. */ - push_dummy_failure, - - /* Followed by two-byte relative address and two-byte number n. - After matching N times, jump to the address upon failure. */ - succeed_n, - - /* Followed by two-byte relative address, and two-byte number n. - Jump to the address N times, then fail. */ - jump_n, - - /* Set the following two-byte relative address to the - subsequent two-byte number. The address *includes* the two - bytes of number. */ - set_number_at, - - wordchar, /* Matches any word-constituent character. */ - notwordchar, /* Matches any char that is not a word-constituent. */ - - wordbeg, /* Succeeds if at word beginning. */ - wordend, /* Succeeds if at word end. */ - - wordbound, /* Succeeds if at a word boundary. */ - notwordbound /* Succeeds if not at a word boundary. */ - -#ifdef emacs - ,before_dot, /* Succeeds if before point. */ - at_dot, /* Succeeds if at point. */ - after_dot, /* Succeeds if after point. */ - - /* Matches any character whose syntax is specified. Followed by - a byte which contains a syntax code, e.g., Sword. */ - syntaxspec, - - /* Matches any character whose syntax is not that specified. */ - notsyntaxspec -#endif /* emacs */ -} re_opcode_t; - -/* Common operations on the compiled pattern. */ - -/* Store NUMBER in two contiguous bytes starting at DESTINATION. */ - -#define STORE_NUMBER(destination, number) \ - do { \ - (destination)[0] = (number) & 0377; \ - (destination)[1] = (number) >> 8; \ - } while (0) - -/* Same as STORE_NUMBER, except increment DESTINATION to - the byte after where the number is stored. Therefore, DESTINATION - must be an lvalue. */ - -#define STORE_NUMBER_AND_INCR(destination, number) \ - do { \ - STORE_NUMBER (destination, number); \ - (destination) += 2; \ - } while (0) - -/* Put into DESTINATION a number stored in two contiguous bytes starting - at SOURCE. */ - -#define EXTRACT_NUMBER(destination, source) \ - do { \ - (destination) = *(source) & 0377; \ - (destination) += SIGN_EXTEND_CHAR (*((source) + 1)) << 8; \ - } while (0) - -#ifdef DEBUG -static void -extract_number (dest, source) - int *dest; - unsigned char *source; -{ - int temp = SIGN_EXTEND_CHAR (*(source + 1)); - *dest = *source & 0377; - *dest += temp << 8; -} - -#ifndef EXTRACT_MACROS /* To debug the macros. */ -#undef EXTRACT_NUMBER -#define EXTRACT_NUMBER(dest, src) extract_number (&dest, src) -#endif /* not EXTRACT_MACROS */ - -#endif /* DEBUG */ - -/* Same as EXTRACT_NUMBER, except increment SOURCE to after the number. - SOURCE must be an lvalue. */ - -#define EXTRACT_NUMBER_AND_INCR(destination, source) \ - do { \ - EXTRACT_NUMBER (destination, source); \ - (source) += 2; \ - } while (0) - -#ifdef DEBUG -static void -extract_number_and_incr (destination, source) - int *destination; - unsigned char **source; -{ - extract_number (destination, *source); - *source += 2; -} - -#ifndef EXTRACT_MACROS -#undef EXTRACT_NUMBER_AND_INCR -#define EXTRACT_NUMBER_AND_INCR(dest, src) \ - extract_number_and_incr (&dest, &src) -#endif /* not EXTRACT_MACROS */ - -#endif /* DEBUG */ - -/* If DEBUG is defined, Regex prints many voluminous messages about what - it is doing (if the variable `debug' is nonzero). If linked with the - main program in `iregex.c', you can enter patterns and strings - interactively. And if linked with the main program in `main.c' and - the other test files, you can run the already-written tests. */ - -#ifdef DEBUG - -/* We use standard I/O for debugging. */ -#include - -/* It is useful to test things that ``must'' be true when debugging. */ -#include - -static int debug = 0; - -#define DEBUG_STATEMENT(e) e -#define DEBUG_PRINT1(x) if (debug) printf (x) -#define DEBUG_PRINT2(x1, x2) if (debug) printf (x1, x2) -#define DEBUG_PRINT3(x1, x2, x3) if (debug) printf (x1, x2, x3) -#define DEBUG_PRINT4(x1, x2, x3, x4) if (debug) printf (x1, x2, x3, x4) -#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) \ - if (debug) print_partial_compiled_pattern (s, e) -#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) \ - if (debug) print_double_string (w, s1, sz1, s2, sz2) - - -extern void printchar (); - -/* Print the fastmap in human-readable form. */ - -void -print_fastmap (fastmap) - char *fastmap; -{ - unsigned was_a_range = 0; - unsigned i = 0; - - while (i < (1 << BYTEWIDTH)) - { - if (fastmap[i++]) - { - was_a_range = 0; - printchar (i - 1); - while (i < (1 << BYTEWIDTH) && fastmap[i]) - { - was_a_range = 1; - i++; - } - if (was_a_range) - { - printf ("-"); - printchar (i - 1); - } - } - } - putchar ('\n'); -} - - -/* Print a compiled pattern string in human-readable form, starting at - the START pointer into it and ending just before the pointer END. */ - -void -print_partial_compiled_pattern (start, end) - unsigned char *start; - unsigned char *end; -{ - int mcnt, mcnt2; - unsigned char *p = start; - unsigned char *pend = end; - - if (start == NULL) - { - printf ("(null)\n"); - return; - } - - /* Loop over pattern commands. */ - while (p < pend) - { - switch ((re_opcode_t) *p++) - { - case no_op: - printf ("/no_op"); - break; - - case exactn: - mcnt = *p++; - printf ("/exactn/%d", mcnt); - do - { - putchar ('/'); - printchar (*p++); - } - while (--mcnt); - break; - - case start_memory: - mcnt = *p++; - printf ("/start_memory/%d/%d", mcnt, *p++); - break; - - case stop_memory: - mcnt = *p++; - printf ("/stop_memory/%d/%d", mcnt, *p++); - break; - - case duplicate: - printf ("/duplicate/%d", *p++); - break; - - case anychar: - printf ("/anychar"); - break; - - case charset: - case charset_not: - { - register int c; - - printf ("/charset%s", - (re_opcode_t) *(p - 1) == charset_not ? "_not" : ""); - - assert (p + *p < pend); - - for (c = 0; c < *p; c++) - { - unsigned bit; - unsigned char map_byte = p[1 + c]; - - putchar ('/'); - - for (bit = 0; bit < BYTEWIDTH; bit++) - if (map_byte & (1 << bit)) - printchar (c * BYTEWIDTH + bit); - } - p += 1 + *p; - break; - } - - case begline: - printf ("/begline"); - break; - - case endline: - printf ("/endline"); - break; - - case on_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/on_failure_jump/0/%d", mcnt); - break; - - case on_failure_keep_string_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/on_failure_keep_string_jump/0/%d", mcnt); - break; - - case dummy_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/dummy_failure_jump/0/%d", mcnt); - break; - - case push_dummy_failure: - printf ("/push_dummy_failure"); - break; - - case maybe_pop_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/maybe_pop_jump/0/%d", mcnt); - break; - - case pop_failure_jump: - extract_number_and_incr (&mcnt, &p); - printf ("/pop_failure_jump/0/%d", mcnt); - break; - - case jump_past_alt: - extract_number_and_incr (&mcnt, &p); - printf ("/jump_past_alt/0/%d", mcnt); - break; - - case jump: - extract_number_and_incr (&mcnt, &p); - printf ("/jump/0/%d", mcnt); - break; - - case succeed_n: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/succeed_n/0/%d/0/%d", mcnt, mcnt2); - break; - - case jump_n: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/jump_n/0/%d/0/%d", mcnt, mcnt2); - break; - - case set_number_at: - extract_number_and_incr (&mcnt, &p); - extract_number_and_incr (&mcnt2, &p); - printf ("/set_number_at/0/%d/0/%d", mcnt, mcnt2); - break; - - case wordbound: - printf ("/wordbound"); - break; - - case notwordbound: - printf ("/notwordbound"); - break; - - case wordbeg: - printf ("/wordbeg"); - break; - - case wordend: - printf ("/wordend"); - -#ifdef emacs - case before_dot: - printf ("/before_dot"); - break; - - case at_dot: - printf ("/at_dot"); - break; - - case after_dot: - printf ("/after_dot"); - break; - - case syntaxspec: - printf ("/syntaxspec"); - mcnt = *p++; - printf ("/%d", mcnt); - break; - - case notsyntaxspec: - printf ("/notsyntaxspec"); - mcnt = *p++; - printf ("/%d", mcnt); - break; -#endif /* emacs */ - - case wordchar: - printf ("/wordchar"); - break; - - case notwordchar: - printf ("/notwordchar"); - break; - - case begbuf: - printf ("/begbuf"); - break; - - case endbuf: - printf ("/endbuf"); - break; - - default: - printf ("?%d", *(p-1)); - } - } - printf ("/\n"); -} - - -void -print_compiled_pattern (bufp) - struct re_pattern_buffer *bufp; -{ - unsigned char *buffer = bufp->buffer; - - print_partial_compiled_pattern (buffer, buffer + bufp->used); - printf ("%d bytes used/%d bytes allocated.\n", bufp->used, bufp->allocated); - - if (bufp->fastmap_accurate && bufp->fastmap) - { - printf ("fastmap: "); - print_fastmap (bufp->fastmap); - } - - printf ("re_nsub: %d\t", bufp->re_nsub); - printf ("regs_alloc: %d\t", bufp->regs_allocated); - printf ("can_be_null: %d\t", bufp->can_be_null); - printf ("newline_anchor: %d\n", bufp->newline_anchor); - printf ("no_sub: %d\t", bufp->no_sub); - printf ("not_bol: %d\t", bufp->not_bol); - printf ("not_eol: %d\t", bufp->not_eol); - printf ("syntax: %d\n", bufp->syntax); - /* Perhaps we should print the translate table? */ -} - - -void -print_double_string (where, string1, size1, string2, size2) - const char *where; - const char *string1; - const char *string2; - int size1; - int size2; -{ - unsigned this_char; - - if (where == NULL) - printf ("(null)"); - else - { - if (FIRST_STRING_P (where)) - { - for (this_char = where - string1; this_char < size1; this_char++) - printchar (string1[this_char]); - - where = string2; - } - - for (this_char = where - string2; this_char < size2; this_char++) - printchar (string2[this_char]); - } -} - -#else /* not DEBUG */ - -#undef assert -#define assert(e) - -#define DEBUG_STATEMENT(e) -#define DEBUG_PRINT1(x) -#define DEBUG_PRINT2(x1, x2) -#define DEBUG_PRINT3(x1, x2, x3) -#define DEBUG_PRINT4(x1, x2, x3, x4) -#define DEBUG_PRINT_COMPILED_PATTERN(p, s, e) -#define DEBUG_PRINT_DOUBLE_STRING(w, s1, sz1, s2, sz2) - -#endif /* not DEBUG */ - -/* Set by `re_set_syntax' to the current regexp syntax to recognize. Can - also be assigned to arbitrarily: each pattern buffer stores its own - syntax, so it can be changed between regex compilations. */ -reg_syntax_t re_syntax_options = RE_SYNTAX_EMACS; - - -/* Specify the precise syntax of regexps for compilation. This provides - for compatibility for various utilities which historically have - different, incompatible syntaxes. - - The argument SYNTAX is a bit mask comprised of the various bits - defined in regex.h. We return the old syntax. */ - -reg_syntax_t -re_set_syntax (syntax) - reg_syntax_t syntax; -{ - reg_syntax_t ret = re_syntax_options; - - re_syntax_options = syntax; - return ret; -} - -/* This table gives an error message for each of the error codes listed - in regex.h. Obviously the order here has to be same as there. */ - -static const char *re_error_msg[] = - { NULL, /* REG_NOERROR */ - "No match", /* REG_NOMATCH */ - "Invalid regular expression", /* REG_BADPAT */ - "Invalid collation character", /* REG_ECOLLATE */ - "Invalid character class name", /* REG_ECTYPE */ - "Trailing backslash", /* REG_EESCAPE */ - "Invalid back reference", /* REG_ESUBREG */ - "Unmatched [ or [^", /* REG_EBRACK */ - "Unmatched ( or \\(", /* REG_EPAREN */ - "Unmatched \\{", /* REG_EBRACE */ - "Invalid content of \\{\\}", /* REG_BADBR */ - "Invalid range end", /* REG_ERANGE */ - "Memory exhausted", /* REG_ESPACE */ - "Invalid preceding regular expression", /* REG_BADRPT */ - "Premature end of regular expression", /* REG_EEND */ - "Regular expression too big", /* REG_ESIZE */ - "Unmatched ) or \\)", /* REG_ERPAREN */ - }; - -/* Subroutine declarations and macros for regex_compile. */ - -static void store_op1 (), store_op2 (); -static void insert_op1 (), insert_op2 (); -static boolean at_begline_loc_p (), at_endline_loc_p (); -static boolean group_in_compile_stack (); -static reg_errcode_t compile_range (); - -/* Fetch the next character in the uncompiled pattern---translating it - if necessary. Also cast from a signed character in the constant - string passed to us by the user to an unsigned char that we can use - as an array index (in, e.g., `translate'). */ -#define PATFETCH(c) \ - do {if (p == pend) return REG_EEND; \ - c = (unsigned char) *p++; \ - if (translate) c = translate[c]; \ - } while (0) - -/* Fetch the next character in the uncompiled pattern, with no - translation. */ -#define PATFETCH_RAW(c) \ - do {if (p == pend) return REG_EEND; \ - c = (unsigned char) *p++; \ - } while (0) - -/* Go backwards one character in the pattern. */ -#define PATUNFETCH p-- - - -/* If `translate' is non-null, return translate[D], else just D. We - cast the subscript to translate because some data is declared as - `char *', to avoid warnings when a string constant is passed. But - when we use a character as a subscript we must make it unsigned. */ -#define TRANSLATE(d) (translate ? translate[(unsigned char) (d)] : (d)) - - -/* Macros for outputting the compiled pattern into `buffer'. */ - -/* If the buffer isn't allocated when it comes in, use this. */ -#define INIT_BUF_SIZE 32 - -/* Make sure we have at least N more bytes of space in buffer. */ -#define GET_BUFFER_SPACE(n) \ - while (b - bufp->buffer + (n) > bufp->allocated) \ - EXTEND_BUFFER () - -/* Make sure we have one more byte of buffer space and then add C to it. */ -#define BUF_PUSH(c) \ - do { \ - GET_BUFFER_SPACE (1); \ - *b++ = (unsigned char) (c); \ - } while (0) - - -/* Ensure we have two more bytes of buffer space and then append C1 and C2. */ -#define BUF_PUSH_2(c1, c2) \ - do { \ - GET_BUFFER_SPACE (2); \ - *b++ = (unsigned char) (c1); \ - *b++ = (unsigned char) (c2); \ - } while (0) - - -/* As with BUF_PUSH_2, except for three bytes. */ -#define BUF_PUSH_3(c1, c2, c3) \ - do { \ - GET_BUFFER_SPACE (3); \ - *b++ = (unsigned char) (c1); \ - *b++ = (unsigned char) (c2); \ - *b++ = (unsigned char) (c3); \ - } while (0) - - -/* Store a jump with opcode OP at LOC to location TO. We store a - relative address offset by the three bytes the jump itself occupies. */ -#define STORE_JUMP(op, loc, to) \ - store_op1 (op, loc, (to) - (loc) - 3) - -/* Likewise, for a two-argument jump. */ -#define STORE_JUMP2(op, loc, to, arg) \ - store_op2 (op, loc, (to) - (loc) - 3, arg) - -/* Like `STORE_JUMP', but for inserting. Assume `b' is the buffer end. */ -#define INSERT_JUMP(op, loc, to) \ - insert_op1 (op, loc, (to) - (loc) - 3, b) - -/* Like `STORE_JUMP2', but for inserting. Assume `b' is the buffer end. */ -#define INSERT_JUMP2(op, loc, to, arg) \ - insert_op2 (op, loc, (to) - (loc) - 3, arg, b) - - -/* This is not an arbitrary limit: the arguments which represent offsets - into the pattern are two bytes long. So if 2^16 bytes turns out to - be too small, many things would have to change. */ -#define MAX_BUF_SIZE (1L << 16) - - -/* Extend the buffer by twice its current size via realloc and - reset the pointers that pointed into the old block to point to the - correct places in the new one. If extending the buffer results in it - being larger than MAX_BUF_SIZE, then flag memory exhausted. */ -#define EXTEND_BUFFER() \ - do { \ - unsigned char *old_buffer = bufp->buffer; \ - if (bufp->allocated == MAX_BUF_SIZE) \ - return REG_ESIZE; \ - bufp->allocated <<= 1; \ - if (bufp->allocated > MAX_BUF_SIZE) \ - bufp->allocated = MAX_BUF_SIZE; \ - bufp->buffer = (unsigned char *) realloc (bufp->buffer, bufp->allocated);\ - if (bufp->buffer == NULL) \ - return REG_ESPACE; \ - /* If the buffer moved, move all the pointers into it. */ \ - if (old_buffer != bufp->buffer) \ - { \ - b = (b - old_buffer) + bufp->buffer; \ - begalt = (begalt - old_buffer) + bufp->buffer; \ - if (fixup_alt_jump) \ - fixup_alt_jump = (fixup_alt_jump - old_buffer) + bufp->buffer;\ - if (laststart) \ - laststart = (laststart - old_buffer) + bufp->buffer; \ - if (pending_exact) \ - pending_exact = (pending_exact - old_buffer) + bufp->buffer; \ - } \ - } while (0) - - -/* Since we have one byte reserved for the register number argument to - {start,stop}_memory, the maximum number of groups we can report - things about is what fits in that byte. */ -#define MAX_REGNUM 255 - -/* But patterns can have more than `MAX_REGNUM' registers. We just - ignore the excess. */ -typedef unsigned regnum_t; - - -/* Macros for the compile stack. */ - -/* Since offsets can go either forwards or backwards, this type needs to - be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1. */ -typedef int pattern_offset_t; - -typedef struct -{ - pattern_offset_t begalt_offset; - pattern_offset_t fixup_alt_jump; - pattern_offset_t inner_group_offset; - pattern_offset_t laststart_offset; - regnum_t regnum; -} compile_stack_elt_t; - - -typedef struct -{ - compile_stack_elt_t *stack; - unsigned size; - unsigned avail; /* Offset of next open position. */ -} compile_stack_type; - - -#define INIT_COMPILE_STACK_SIZE 32 - -#define COMPILE_STACK_EMPTY (compile_stack.avail == 0) -#define COMPILE_STACK_FULL (compile_stack.avail == compile_stack.size) - -/* The next available element. */ -#define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail]) - - -/* Set the bit for character C in a list. */ -#define SET_LIST_BIT(c) \ - (b[((unsigned char) (c)) / BYTEWIDTH] \ - |= 1 << (((unsigned char) c) % BYTEWIDTH)) - - -/* Get the next unsigned number in the uncompiled pattern. */ -#define GET_UNSIGNED_NUMBER(num) \ - { if (p != pend) \ - { \ - PATFETCH (c); \ - while (ISDIGIT (c)) \ - { \ - if (num < 0) \ - num = 0; \ - num = num * 10 + c - '0'; \ - if (p == pend) \ - break; \ - PATFETCH (c); \ - } \ - } \ - } - -#define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ - -#define IS_CHAR_CLASS(string) \ - (STREQ (string, "alpha") || STREQ (string, "upper") \ - || STREQ (string, "lower") || STREQ (string, "digit") \ - || STREQ (string, "alnum") || STREQ (string, "xdigit") \ - || STREQ (string, "space") || STREQ (string, "print") \ - || STREQ (string, "punct") || STREQ (string, "graph") \ - || STREQ (string, "cntrl") || STREQ (string, "blank")) - -/* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. - Returns one of error codes defined in `regex.h', or zero for success. - - Assumes the `allocated' (and perhaps `buffer') and `translate' - fields are set in BUFP on entry. - - If it succeeds, results are put in BUFP (if it returns an error, the - contents of BUFP are undefined): - `buffer' is the compiled pattern; - `syntax' is set to SYNTAX; - `used' is set to the length of the compiled pattern; - `fastmap_accurate' is zero; - `re_nsub' is the number of subexpressions in PATTERN; - `not_bol' and `not_eol' are zero; - - The `fastmap' and `newline_anchor' fields are neither - examined nor set. */ - -static reg_errcode_t -regex_compile (pattern, size, syntax, bufp) - const char *pattern; - int size; - reg_syntax_t syntax; - struct re_pattern_buffer *bufp; -{ - /* We fetch characters from PATTERN here. Even though PATTERN is - `char *' (i.e., signed), we declare these variables as unsigned, so - they can be reliably used as array indices. */ - register unsigned char c, c1; - - /* A random tempory spot in PATTERN. */ - const char *p1; - - /* Points to the end of the buffer, where we should append. */ - register unsigned char *b; - - /* Keeps track of unclosed groups. */ - compile_stack_type compile_stack; - - /* Points to the current (ending) position in the pattern. */ - const char *p = pattern; - const char *pend = pattern + size; - - /* How to translate the characters in the pattern. */ - char *translate = bufp->translate; - - /* Address of the count-byte of the most recently inserted `exactn' - command. This makes it possible to tell if a new exact-match - character can be added to that command or if the character requires - a new `exactn' command. */ - unsigned char *pending_exact = 0; - - /* Address of start of the most recently finished expression. - This tells, e.g., postfix * where to find the start of its - operand. Reset at the beginning of groups and alternatives. */ - unsigned char *laststart = 0; - - /* Address of beginning of regexp, or inside of last group. */ - unsigned char *begalt; - - /* Place in the uncompiled pattern (i.e., the {) to - which to go back if the interval is invalid. */ - const char *beg_interval; - - /* Address of the place where a forward jump should go to the end of - the containing expression. Each alternative of an `or' -- except the - last -- ends with a forward jump of this sort. */ - unsigned char *fixup_alt_jump = 0; - - /* Counts open-groups as they are encountered. Remembered for the - matching close-group on the compile stack, so the same register - number is put in the stop_memory as the start_memory. */ - regnum_t regnum = 0; - -#ifdef DEBUG - DEBUG_PRINT1 ("\nCompiling pattern: "); - if (debug) - { - unsigned debug_count; - - for (debug_count = 0; debug_count < size; debug_count++) - printchar (pattern[debug_count]); - putchar ('\n'); - } -#endif /* DEBUG */ - - /* Initialize the compile stack. */ - compile_stack.stack = TALLOC (INIT_COMPILE_STACK_SIZE, compile_stack_elt_t); - if (compile_stack.stack == NULL) - return REG_ESPACE; - - compile_stack.size = INIT_COMPILE_STACK_SIZE; - compile_stack.avail = 0; - - /* Initialize the pattern buffer. */ - bufp->syntax = syntax; - bufp->fastmap_accurate = 0; - bufp->not_bol = bufp->not_eol = 0; - - /* Set `used' to zero, so that if we return an error, the pattern - printer (for debugging) will think there's no pattern. We reset it - at the end. */ - bufp->used = 0; - - /* Always count groups, whether or not bufp->no_sub is set. */ - bufp->re_nsub = 0; - -#if !defined (emacs) && !defined (SYNTAX_TABLE) - /* Initialize the syntax table. */ - init_syntax_once (); -#endif - - if (bufp->allocated == 0) - { - if (bufp->buffer) - { /* If zero allocated, but buffer is non-null, try to realloc - enough space. This loses if buffer's address is bogus, but - that is the user's responsibility. */ - RETALLOC (bufp->buffer, INIT_BUF_SIZE, unsigned char); - } - else - { /* Caller did not allocate a buffer. Do it for them. */ - bufp->buffer = TALLOC (INIT_BUF_SIZE, unsigned char); - } - if (!bufp->buffer) return REG_ESPACE; - - bufp->allocated = INIT_BUF_SIZE; - } - - begalt = b = bufp->buffer; - - /* Loop through the uncompiled pattern until we're at the end. */ - while (p != pend) - { - PATFETCH (c); - - switch (c) - { - case '^': - { - if ( /* If at start of pattern, it's an operator. */ - p == pattern + 1 - /* If context independent, it's an operator. */ - || syntax & RE_CONTEXT_INDEP_ANCHORS - /* Otherwise, depends on what's come before. */ - || at_begline_loc_p (pattern, p, syntax)) - BUF_PUSH (begline); - else - goto normal_char; - } - break; - - - case '$': - { - if ( /* If at end of pattern, it's an operator. */ - p == pend - /* If context independent, it's an operator. */ - || syntax & RE_CONTEXT_INDEP_ANCHORS - /* Otherwise, depends on what's next. */ - || at_endline_loc_p (p, pend, syntax)) - BUF_PUSH (endline); - else - goto normal_char; - } - break; - - - case '+': - case '?': - if ((syntax & RE_BK_PLUS_QM) - || (syntax & RE_LIMITED_OPS)) - goto normal_char; - handle_plus: - case '*': - /* If there is no previous pattern... */ - if (!laststart) - { - if (syntax & RE_CONTEXT_INVALID_OPS) - return REG_BADRPT; - else if (!(syntax & RE_CONTEXT_INDEP_OPS)) - goto normal_char; - } - - { - /* Are we optimizing this jump? */ - boolean keep_string_p = false; - - /* 1 means zero (many) matches is allowed. */ - char zero_times_ok = 0, many_times_ok = 0; - - /* If there is a sequence of repetition chars, collapse it - down to just one (the right one). We can't combine - interval operators with these because of, e.g., `a{2}*', - which should only match an even number of `a's. */ - - for (;;) - { - zero_times_ok |= c != '+'; - many_times_ok |= c != '?'; - - if (p == pend) - break; - - PATFETCH (c); - - if (c == '*' - || (!(syntax & RE_BK_PLUS_QM) && (c == '+' || c == '?'))) - ; - - else if (syntax & RE_BK_PLUS_QM && c == '\\') - { - if (p == pend) return REG_EESCAPE; - - PATFETCH (c1); - if (!(c1 == '+' || c1 == '?')) - { - PATUNFETCH; - PATUNFETCH; - break; - } - - c = c1; - } - else - { - PATUNFETCH; - break; - } - - /* If we get here, we found another repeat character. */ - } - - /* Star, etc. applied to an empty pattern is equivalent - to an empty pattern. */ - if (!laststart) - break; - - /* Now we know whether or not zero matches is allowed - and also whether or not two or more matches is allowed. */ - if (many_times_ok) - { /* More than one repetition is allowed, so put in at the - end a backward relative jump from `b' to before the next - jump we're going to put in below (which jumps from - laststart to after this jump). - - But if we are at the `*' in the exact sequence `.*\n', - insert an unconditional jump backwards to the ., - instead of the beginning of the loop. This way we only - push a failure point once, instead of every time - through the loop. */ - assert (p - 1 > pattern); - - /* Allocate the space for the jump. */ - GET_BUFFER_SPACE (3); - - /* We know we are not at the first character of the pattern, - because laststart was nonzero. And we've already - incremented `p', by the way, to be the character after - the `*'. Do we have to do something analogous here - for null bytes, because of RE_DOT_NOT_NULL? */ - if (TRANSLATE (*(p - 2)) == TRANSLATE ('.') - && p < pend && TRANSLATE (*p) == TRANSLATE ('\n') - && !(syntax & RE_DOT_NEWLINE)) - { /* We have .*\n. */ - STORE_JUMP (jump, b, laststart); - keep_string_p = true; - } - else - /* Anything else. */ - STORE_JUMP (maybe_pop_jump, b, laststart - 3); - - /* We've added more stuff to the buffer. */ - b += 3; - } - - /* On failure, jump from laststart to b + 3, which will be the - end of the buffer after this jump is inserted. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (keep_string_p ? on_failure_keep_string_jump - : on_failure_jump, - laststart, b + 3); - pending_exact = 0; - b += 3; - - if (!zero_times_ok) - { - /* At least one repetition is required, so insert a - `dummy_failure_jump' before the initial - `on_failure_jump' instruction of the loop. This - effects a skip over that instruction the first time - we hit that loop. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (dummy_failure_jump, laststart, laststart + 6); - b += 3; - } - } - break; - - - case '.': - laststart = b; - BUF_PUSH (anychar); - break; - - - case '[': - { - boolean had_char_class = false; - - if (p == pend) return REG_EBRACK; - - /* Ensure that we have enough space to push a charset: the - opcode, the length count, and the bitset; 34 bytes in all. */ - GET_BUFFER_SPACE (34); - - laststart = b; - - /* We test `*p == '^' twice, instead of using an if - statement, so we only need one BUF_PUSH. */ - BUF_PUSH (*p == '^' ? charset_not : charset); - if (*p == '^') - p++; - - /* Remember the first position in the bracket expression. */ - p1 = p; - - /* Push the number of bytes in the bitmap. */ - BUF_PUSH ((1 << BYTEWIDTH) / BYTEWIDTH); - - /* Clear the whole map. */ - bzero (b, (1 << BYTEWIDTH) / BYTEWIDTH); - - /* charset_not matches newline according to a syntax bit. */ - if ((re_opcode_t) b[-2] == charset_not - && (syntax & RE_HAT_LISTS_NOT_NEWLINE)) - SET_LIST_BIT ('\n'); - - /* Read in characters and ranges, setting map bits. */ - for (;;) - { - if (p == pend) return REG_EBRACK; - - PATFETCH (c); - - /* \ might escape characters inside [...] and [^...]. */ - if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\') - { - if (p == pend) return REG_EESCAPE; - - PATFETCH (c1); - SET_LIST_BIT (c1); - continue; - } - - /* Could be the end of the bracket expression. If it's - not (i.e., when the bracket expression is `[]' so - far), the ']' character bit gets set way below. */ - if (c == ']' && p != p1 + 1) - break; - - /* Look ahead to see if it's a range when the last thing - was a character class. */ - if (had_char_class && c == '-' && *p != ']') - return REG_ERANGE; - - /* Look ahead to see if it's a range when the last thing - was a character: if this is a hyphen not at the - beginning or the end of a list, then it's the range - operator. */ - if (c == '-' - && !(p - 2 >= pattern && p[-2] == '[') - && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^') - && *p != ']') - { - reg_errcode_t ret - = compile_range (&p, pend, translate, syntax, b); - if (ret != REG_NOERROR) return ret; - } - - else if (p[0] == '-' && p[1] != ']') - { /* This handles ranges made up of characters only. */ - reg_errcode_t ret; - - /* Move past the `-'. */ - PATFETCH (c1); - - ret = compile_range (&p, pend, translate, syntax, b); - if (ret != REG_NOERROR) return ret; - } - - /* See if we're at the beginning of a possible character - class. */ - - else if (syntax & RE_CHAR_CLASSES && c == '[' && *p == ':') - { /* Leave room for the null. */ - char str[CHAR_CLASS_MAX_LENGTH + 1]; - - PATFETCH (c); - c1 = 0; - - /* If pattern is `[[:'. */ - if (p == pend) return REG_EBRACK; - - for (;;) - { - PATFETCH (c); - if (c == ':' || c == ']' || p == pend - || c1 == CHAR_CLASS_MAX_LENGTH) - break; - str[c1++] = c; - } - str[c1] = '\0'; - - /* If isn't a word bracketed by `[:' and:`]': - undo the ending character, the letters, and leave - the leading `:' and `[' (but set bits for them). */ - if (c == ':' && *p == ']') - { - int ch; - boolean is_alnum = STREQ (str, "alnum"); - boolean is_alpha = STREQ (str, "alpha"); - boolean is_blank = STREQ (str, "blank"); - boolean is_cntrl = STREQ (str, "cntrl"); - boolean is_digit = STREQ (str, "digit"); - boolean is_graph = STREQ (str, "graph"); - boolean is_lower = STREQ (str, "lower"); - boolean is_print = STREQ (str, "print"); - boolean is_punct = STREQ (str, "punct"); - boolean is_space = STREQ (str, "space"); - boolean is_upper = STREQ (str, "upper"); - boolean is_xdigit = STREQ (str, "xdigit"); - - if (!IS_CHAR_CLASS (str)) return REG_ECTYPE; - - /* Throw away the ] at the end of the character - class. */ - PATFETCH (c); - - if (p == pend) return REG_EBRACK; - - for (ch = 0; ch < 1 << BYTEWIDTH; ch++) - { - if ( (is_alnum && ISALNUM (ch)) - || (is_alpha && ISALPHA (ch)) - || (is_blank && ISBLANK (ch)) - || (is_cntrl && ISCNTRL (ch)) - || (is_digit && ISDIGIT (ch)) - || (is_graph && ISGRAPH (ch)) - || (is_lower && ISLOWER (ch)) - || (is_print && ISPRINT (ch)) - || (is_punct && ISPUNCT (ch)) - || (is_space && ISSPACE (ch)) - || (is_upper && ISUPPER (ch)) - || (is_xdigit && ISXDIGIT (ch))) - SET_LIST_BIT (ch); - } - had_char_class = true; - } - else - { - c1++; - while (c1--) - PATUNFETCH; - SET_LIST_BIT ('['); - SET_LIST_BIT (':'); - had_char_class = false; - } - } - else - { - had_char_class = false; - SET_LIST_BIT (c); - } - } - - /* Discard any (non)matching list bytes that are all 0 at the - end of the map. Decrease the map-length byte too. */ - while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) - b[-1]--; - b += b[-1]; - } - break; - - - case '(': - if (syntax & RE_NO_BK_PARENS) - goto handle_open; - else - goto normal_char; - - - case ')': - if (syntax & RE_NO_BK_PARENS) - goto handle_close; - else - goto normal_char; - - - case '\n': - if (syntax & RE_NEWLINE_ALT) - goto handle_alt; - else - goto normal_char; - - - case '|': - if (syntax & RE_NO_BK_VBAR) - goto handle_alt; - else - goto normal_char; - - - case '{': - if (syntax & RE_INTERVALS && syntax & RE_NO_BK_BRACES) - goto handle_interval; - else - goto normal_char; - - - case '\\': - if (p == pend) return REG_EESCAPE; - - /* Do not translate the character after the \, so that we can - distinguish, e.g., \B from \b, even if we normally would - translate, e.g., B to b. */ - PATFETCH_RAW (c); - - switch (c) - { - case '(': - if (syntax & RE_NO_BK_PARENS) - goto normal_backslash; - - handle_open: - bufp->re_nsub++; - regnum++; - - if (COMPILE_STACK_FULL) - { - RETALLOC (compile_stack.stack, compile_stack.size << 1, - compile_stack_elt_t); - if (compile_stack.stack == NULL) return REG_ESPACE; - - compile_stack.size <<= 1; - } - - /* These are the values to restore when we hit end of this - group. They are all relative offsets, so that if the - whole pattern moves because of realloc, they will still - be valid. */ - COMPILE_STACK_TOP.begalt_offset = begalt - bufp->buffer; - COMPILE_STACK_TOP.fixup_alt_jump - = fixup_alt_jump ? fixup_alt_jump - bufp->buffer + 1 : 0; - COMPILE_STACK_TOP.laststart_offset = b - bufp->buffer; - COMPILE_STACK_TOP.regnum = regnum; - - /* We will eventually replace the 0 with the number of - groups inner to this one. But do not push a - start_memory for groups beyond the last one we can - represent in the compiled pattern. */ - if (regnum <= MAX_REGNUM) - { - COMPILE_STACK_TOP.inner_group_offset = b - bufp->buffer + 2; - BUF_PUSH_3 (start_memory, regnum, 0); - } - - compile_stack.avail++; - - fixup_alt_jump = 0; - laststart = 0; - begalt = b; - break; - - - case ')': - if (syntax & RE_NO_BK_PARENS) goto normal_backslash; - - if (COMPILE_STACK_EMPTY) - if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) - goto normal_backslash; - else - return REG_ERPAREN; - - handle_close: - if (fixup_alt_jump) - { /* Push a dummy failure point at the end of the - alternative for a possible future - `pop_failure_jump' to pop. See comments at - `push_dummy_failure' in `re_match_2'. */ - BUF_PUSH (push_dummy_failure); - - /* We allocated space for this jump when we assigned - to `fixup_alt_jump', in the `handle_alt' case below. */ - STORE_JUMP (jump_past_alt, fixup_alt_jump, b - 1); - } - - /* See similar code for backslashed left paren above. */ - if (COMPILE_STACK_EMPTY) - if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD) - goto normal_char; - else - return REG_ERPAREN; - - /* Since we just checked for an empty stack above, this - ``can't happen''. */ - assert (compile_stack.avail != 0); - { - /* We don't just want to restore into `regnum', because - later groups should continue to be numbered higher, - as in `(ab)c(de)' -- the second group is #2. */ - regnum_t this_group_regnum; - - compile_stack.avail--; - begalt = bufp->buffer + COMPILE_STACK_TOP.begalt_offset; - fixup_alt_jump - = COMPILE_STACK_TOP.fixup_alt_jump - ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 - : 0; - laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; - this_group_regnum = COMPILE_STACK_TOP.regnum; - - /* We're at the end of the group, so now we know how many - groups were inside this one. */ - if (this_group_regnum <= MAX_REGNUM) - { - unsigned char *inner_group_loc - = bufp->buffer + COMPILE_STACK_TOP.inner_group_offset; - - *inner_group_loc = regnum - this_group_regnum; - BUF_PUSH_3 (stop_memory, this_group_regnum, - regnum - this_group_regnum); - } - } - break; - - - case '|': /* `\|'. */ - if (syntax & RE_LIMITED_OPS || syntax & RE_NO_BK_VBAR) - goto normal_backslash; - handle_alt: - if (syntax & RE_LIMITED_OPS) - goto normal_char; - - /* Insert before the previous alternative a jump which - jumps to this alternative if the former fails. */ - GET_BUFFER_SPACE (3); - INSERT_JUMP (on_failure_jump, begalt, b + 6); - pending_exact = 0; - b += 3; - - /* The alternative before this one has a jump after it - which gets executed if it gets matched. Adjust that - jump so it will jump to this alternative's analogous - jump (put in below, which in turn will jump to the next - (if any) alternative's such jump, etc.). The last such - jump jumps to the correct final destination. A picture: - _____ _____ - | | | | - | v | v - a | b | c - - If we are at `b', then fixup_alt_jump right now points to a - three-byte space after `a'. We'll put in the jump, set - fixup_alt_jump to right after `b', and leave behind three - bytes which we'll fill in when we get to after `c'. */ - - if (fixup_alt_jump) - STORE_JUMP (jump_past_alt, fixup_alt_jump, b); - - /* Mark and leave space for a jump after this alternative, - to be filled in later either by next alternative or - when know we're at the end of a series of alternatives. */ - fixup_alt_jump = b; - GET_BUFFER_SPACE (3); - b += 3; - - laststart = 0; - begalt = b; - break; - - - case '{': - /* If \{ is a literal. */ - if (!(syntax & RE_INTERVALS) - /* If we're at `\{' and it's not the open-interval - operator. */ - || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES)) - || (p - 2 == pattern && p == pend)) - goto normal_backslash; - - handle_interval: - { - /* If got here, then the syntax allows intervals. */ - - /* At least (most) this many matches must be made. */ - int lower_bound = -1, upper_bound = -1; - - beg_interval = p - 1; - - if (p == pend) - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_EBRACE; - } - - GET_UNSIGNED_NUMBER (lower_bound); - - if (c == ',') - { - GET_UNSIGNED_NUMBER (upper_bound); - if (upper_bound < 0) upper_bound = RE_DUP_MAX; - } - else - /* Interval such as `{1}' => match exactly once. */ - upper_bound = lower_bound; - - if (lower_bound < 0 || upper_bound > RE_DUP_MAX - || lower_bound > upper_bound) - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_BADBR; - } - - if (!(syntax & RE_NO_BK_BRACES)) - { - if (c != '\\') return REG_EBRACE; - - PATFETCH (c); - } - - if (c != '}') - { - if (syntax & RE_NO_BK_BRACES) - goto unfetch_interval; - else - return REG_BADBR; - } - - /* We just parsed a valid interval. */ - - /* If it's invalid to have no preceding re. */ - if (!laststart) - { - if (syntax & RE_CONTEXT_INVALID_OPS) - return REG_BADRPT; - else if (syntax & RE_CONTEXT_INDEP_OPS) - laststart = b; - else - goto unfetch_interval; - } - - /* If the upper bound is zero, don't want to succeed at - all; jump from `laststart' to `b + 3', which will be - the end of the buffer after we insert the jump. */ - if (upper_bound == 0) - { - GET_BUFFER_SPACE (3); - INSERT_JUMP (jump, laststart, b + 3); - b += 3; - } - - /* Otherwise, we have a nontrivial interval. When - we're all done, the pattern will look like: - set_number_at - set_number_at - succeed_n - - jump_n - (The upper bound and `jump_n' are omitted if - `upper_bound' is 1, though.) */ - else - { /* If the upper bound is > 1, we need to insert - more at the end of the loop. */ - unsigned nbytes = 10 + (upper_bound > 1) * 10; - - GET_BUFFER_SPACE (nbytes); - - /* Initialize lower bound of the `succeed_n', even - though it will be set during matching by its - attendant `set_number_at' (inserted next), - because `re_compile_fastmap' needs to know. - Jump to the `jump_n' we might insert below. */ - INSERT_JUMP2 (succeed_n, laststart, - b + 5 + (upper_bound > 1) * 5, - lower_bound); - b += 5; - - /* Code to initialize the lower bound. Insert - before the `succeed_n'. The `5' is the last two - bytes of this `set_number_at', plus 3 bytes of - the following `succeed_n'. */ - insert_op2 (set_number_at, laststart, 5, lower_bound, b); - b += 5; - - if (upper_bound > 1) - { /* More than one repetition is allowed, so - append a backward jump to the `succeed_n' - that starts this interval. - - When we've reached this during matching, - we'll have matched the interval once, so - jump back only `upper_bound - 1' times. */ - STORE_JUMP2 (jump_n, b, laststart + 5, - upper_bound - 1); - b += 5; - - /* The location we want to set is the second - parameter of the `jump_n'; that is `b-2' as - an absolute address. `laststart' will be - the `set_number_at' we're about to insert; - `laststart+3' the number to set, the source - for the relative address. But we are - inserting into the middle of the pattern -- - so everything is getting moved up by 5. - Conclusion: (b - 2) - (laststart + 3) + 5, - i.e., b - laststart. - - We insert this at the beginning of the loop - so that if we fail during matching, we'll - reinitialize the bounds. */ - insert_op2 (set_number_at, laststart, b - laststart, - upper_bound - 1, b); - b += 5; - } - } - pending_exact = 0; - beg_interval = NULL; - } - break; - - unfetch_interval: - /* If an invalid interval, match the characters as literals. */ - assert (beg_interval); - p = beg_interval; - beg_interval = NULL; - - /* normal_char and normal_backslash need `c'. */ - PATFETCH (c); - - if (!(syntax & RE_NO_BK_BRACES)) - { - if (p > pattern && p[-1] == '\\') - goto normal_backslash; - } - goto normal_char; - -#ifdef emacs - /* There is no way to specify the before_dot and after_dot - operators. rms says this is ok. --karl */ - case '=': - BUF_PUSH (at_dot); - break; - - case 's': - laststart = b; - PATFETCH (c); - BUF_PUSH_2 (syntaxspec, syntax_spec_code[c]); - break; - - case 'S': - laststart = b; - PATFETCH (c); - BUF_PUSH_2 (notsyntaxspec, syntax_spec_code[c]); - break; -#endif /* emacs */ - - - case 'w': - laststart = b; - BUF_PUSH (wordchar); - break; - - - case 'W': - laststart = b; - BUF_PUSH (notwordchar); - break; - - - case '<': - BUF_PUSH (wordbeg); - break; - - case '>': - BUF_PUSH (wordend); - break; - - case 'b': - BUF_PUSH (wordbound); - break; - - case 'B': - BUF_PUSH (notwordbound); - break; - - case '`': - BUF_PUSH (begbuf); - break; - - case '\'': - BUF_PUSH (endbuf); - break; - - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': - if (syntax & RE_NO_BK_REFS) - goto normal_char; - - c1 = c - '0'; - - if (c1 > regnum) - return REG_ESUBREG; - - /* Can't back reference to a subexpression if inside of it. */ - if (group_in_compile_stack (compile_stack, c1)) - goto normal_char; - - laststart = b; - BUF_PUSH_2 (duplicate, c1); - break; - - - case '+': - case '?': - if (syntax & RE_BK_PLUS_QM) - goto handle_plus; - else - goto normal_backslash; - - default: - normal_backslash: - /* You might think it would be useful for \ to mean - not to translate; but if we don't translate it - it will never match anything. */ - c = TRANSLATE (c); - goto normal_char; - } - break; - - - default: - /* Expects the character in `c'. */ - normal_char: - /* If no exactn currently being built. */ - if (!pending_exact - - /* If last exactn not at current position. */ - || pending_exact + *pending_exact + 1 != b - - /* We have only one byte following the exactn for the count. */ - || *pending_exact == (1 << BYTEWIDTH) - 1 - - /* If followed by a repetition operator. */ - || *p == '*' || *p == '^' - || ((syntax & RE_BK_PLUS_QM) - ? *p == '\\' && (p[1] == '+' || p[1] == '?') - : (*p == '+' || *p == '?')) - || ((syntax & RE_INTERVALS) - && ((syntax & RE_NO_BK_BRACES) - ? *p == '{' - : (p[0] == '\\' && p[1] == '{')))) - { - /* Start building a new exactn. */ - - laststart = b; - - BUF_PUSH_2 (exactn, 0); - pending_exact = b - 1; - } - - BUF_PUSH (c); - (*pending_exact)++; - break; - } /* switch (c) */ - } /* while p != pend */ - - - /* Through the pattern now. */ - - if (fixup_alt_jump) - STORE_JUMP (jump_past_alt, fixup_alt_jump, b); - - if (!COMPILE_STACK_EMPTY) - return REG_EPAREN; - - free (compile_stack.stack); - - /* We have succeeded; set the length of the buffer. */ - bufp->used = b - bufp->buffer; - -#ifdef DEBUG - if (debug) - { - DEBUG_PRINT1 ("\nCompiled pattern: "); - print_compiled_pattern (bufp); - } -#endif /* DEBUG */ - - return REG_NOERROR; -} /* regex_compile */ - -/* Subroutines for `regex_compile'. */ - -/* Store OP at LOC followed by two-byte integer parameter ARG. */ - -static void -store_op1 (op, loc, arg) - re_opcode_t op; - unsigned char *loc; - int arg; -{ - *loc = (unsigned char) op; - STORE_NUMBER (loc + 1, arg); -} - - -/* Like `store_op1', but for two two-byte parameters ARG1 and ARG2. */ - -static void -store_op2 (op, loc, arg1, arg2) - re_opcode_t op; - unsigned char *loc; - int arg1, arg2; -{ - *loc = (unsigned char) op; - STORE_NUMBER (loc + 1, arg1); - STORE_NUMBER (loc + 3, arg2); -} - - -/* Copy the bytes from LOC to END to open up three bytes of space at LOC - for OP followed by two-byte integer parameter ARG. */ - -static void -insert_op1 (op, loc, arg, end) - re_opcode_t op; - unsigned char *loc; - int arg; - unsigned char *end; -{ - register unsigned char *pfrom = end; - register unsigned char *pto = end + 3; - - while (pfrom != loc) - *--pto = *--pfrom; - - store_op1 (op, loc, arg); -} - - -/* Like `insert_op1', but for two two-byte parameters ARG1 and ARG2. */ - -static void -insert_op2 (op, loc, arg1, arg2, end) - re_opcode_t op; - unsigned char *loc; - int arg1, arg2; - unsigned char *end; -{ - register unsigned char *pfrom = end; - register unsigned char *pto = end + 5; - - while (pfrom != loc) - *--pto = *--pfrom; - - store_op2 (op, loc, arg1, arg2); -} - - -/* P points to just after a ^ in PATTERN. Return true if that ^ comes - after an alternative or a begin-subexpression. We assume there is at - least one character before the ^. */ - -static boolean -at_begline_loc_p (pattern, p, syntax) - const char *pattern, *p; - reg_syntax_t syntax; -{ - const char *prev = p - 2; - boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; - - return - /* After a subexpression? */ - (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) - /* After an alternative? */ - || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash)); -} - - -/* The dual of at_begline_loc_p. This one is for $. We assume there is - at least one character after the $, i.e., `P < PEND'. */ - -static boolean -at_endline_loc_p (p, pend, syntax) - const char *p, *pend; - int syntax; -{ - const char *next = p; - boolean next_backslash = *next == '\\'; - const char *next_next = p + 1 < pend ? p + 1 : NULL; - - return - /* Before a subexpression? */ - (syntax & RE_NO_BK_PARENS ? *next == ')' - : next_backslash && next_next && *next_next == ')') - /* Before an alternative? */ - || (syntax & RE_NO_BK_VBAR ? *next == '|' - : next_backslash && next_next && *next_next == '|'); -} - - -/* Returns true if REGNUM is in one of COMPILE_STACK's elements and - false if it's not. */ - -static boolean -group_in_compile_stack (compile_stack, regnum) - compile_stack_type compile_stack; - regnum_t regnum; -{ - int this_element; - - for (this_element = compile_stack.avail - 1; - this_element >= 0; - this_element--) - if (compile_stack.stack[this_element].regnum == regnum) - return true; - - return false; -} - - -/* Read the ending character of a range (in a bracket expression) from the - uncompiled pattern *P_PTR (which ends at PEND). We assume the - starting character is in `P[-2]'. (`P[-1]' is the character `-'.) - Then we set the translation of all bits between the starting and - ending characters (inclusive) in the compiled pattern B. - - Return an error code. - - We use these short variable names so we can use the same macros as - `regex_compile' itself. */ - -static reg_errcode_t -compile_range (p_ptr, pend, translate, syntax, b) - const char **p_ptr, *pend; - char *translate; - reg_syntax_t syntax; - unsigned char *b; -{ - unsigned this_char; - - const char *p = *p_ptr; - int range_start, range_end; - - if (p == pend) - return REG_ERANGE; - - /* Even though the pattern is a signed `char *', we need to fetch - with unsigned char *'s; if the high bit of the pattern character - is set, the range endpoints will be negative if we fetch using a - signed char *. - - We also want to fetch the endpoints without translating them; the - appropriate translation is done in the bit-setting loop below. */ - range_start = ((unsigned char *) p)[-2]; - range_end = ((unsigned char *) p)[0]; - - /* Have to increment the pointer into the pattern string, so the - caller isn't still at the ending character. */ - (*p_ptr)++; - - /* If the start is after the end, the range is empty. */ - if (range_start > range_end) - return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR; - - /* Here we see why `this_char' has to be larger than an `unsigned - char' -- the range is inclusive, so if `range_end' == 0xff - (assuming 8-bit characters), we would otherwise go into an infinite - loop, since all characters <= 0xff. */ - for (this_char = range_start; this_char <= range_end; this_char++) - { - SET_LIST_BIT (TRANSLATE (this_char)); - } - - return REG_NOERROR; -} - -/* Failure stack declarations and macros; both re_compile_fastmap and - re_match_2 use a failure stack. These have to be macros because of - REGEX_ALLOCATE. */ - - -/* Number of failure points for which to initially allocate space - when matching. If this number is exceeded, we allocate more - space, so it is not a hard limit. */ -#ifndef INIT_FAILURE_ALLOC -#define INIT_FAILURE_ALLOC 5 -#endif - -/* Roughly the maximum number of failure points on the stack. Would be - exactly that if always used MAX_FAILURE_SPACE each time we failed. - This is a variable only so users of regex can assign to it; we never - change it ourselves. */ -int re_max_failures = 2000; - -typedef const unsigned char *fail_stack_elt_t; - -typedef struct -{ - fail_stack_elt_t *stack; - unsigned size; - unsigned avail; /* Offset of next open position. */ -} fail_stack_type; - -#define FAIL_STACK_EMPTY() (fail_stack.avail == 0) -#define FAIL_STACK_PTR_EMPTY() (fail_stack_ptr->avail == 0) -#define FAIL_STACK_FULL() (fail_stack.avail == fail_stack.size) -#define FAIL_STACK_TOP() (fail_stack.stack[fail_stack.avail]) - - -/* Initialize `fail_stack'. Do `return -2' if the alloc fails. */ - -#define INIT_FAIL_STACK() \ - do { \ - fail_stack.stack = (fail_stack_elt_t *) \ - REGEX_ALLOCATE (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \ - \ - if (fail_stack.stack == NULL) \ - return -2; \ - \ - fail_stack.size = INIT_FAILURE_ALLOC; \ - fail_stack.avail = 0; \ - } while (0) - - -/* Double the size of FAIL_STACK, up to approximately `re_max_failures' items. - - Return 1 if succeeds, and 0 if either ran out of memory - allocating space for it or it was already too large. - - REGEX_REALLOCATE requires `destination' be declared. */ - -#define DOUBLE_FAIL_STACK(fail_stack) \ - ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \ - ? 0 \ - : ((fail_stack).stack = (fail_stack_elt_t *) \ - REGEX_REALLOCATE ((fail_stack).stack, \ - (fail_stack).size * sizeof (fail_stack_elt_t), \ - ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \ - \ - (fail_stack).stack == NULL \ - ? 0 \ - : ((fail_stack).size <<= 1, \ - 1))) - - -/* Push PATTERN_OP on FAIL_STACK. - - Return 1 if was able to do so and 0 if ran out of memory allocating - space to do so. */ -#define PUSH_PATTERN_OP(pattern_op, fail_stack) \ - ((FAIL_STACK_FULL () \ - && !DOUBLE_FAIL_STACK (fail_stack)) \ - ? 0 \ - : ((fail_stack).stack[(fail_stack).avail++] = pattern_op, \ - 1)) - -/* This pushes an item onto the failure stack. Must be a four-byte - value. Assumes the variable `fail_stack'. Probably should only - be called from within `PUSH_FAILURE_POINT'. */ -#define PUSH_FAILURE_ITEM(item) \ - fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) item - -/* The complement operation. Assumes `fail_stack' is nonempty. */ -#define POP_FAILURE_ITEM() fail_stack.stack[--fail_stack.avail] - -/* Used to omit pushing failure point id's when we're not debugging. */ -#ifdef DEBUG -#define DEBUG_PUSH PUSH_FAILURE_ITEM -#define DEBUG_POP(item_addr) *(item_addr) = POP_FAILURE_ITEM () -#else -#define DEBUG_PUSH(item) -#define DEBUG_POP(item_addr) -#endif - - -/* Push the information about the state we will need - if we ever fail back to it. - - Requires variables fail_stack, regstart, regend, reg_info, and - num_regs be declared. DOUBLE_FAIL_STACK requires `destination' be - declared. - - Does `return FAILURE_CODE' if runs out of memory. */ - -#define PUSH_FAILURE_POINT(pattern_place, string_place, failure_code) \ - do { \ - char *destination; \ - /* Must be int, so when we don't save any registers, the arithmetic \ - of 0 + -1 isn't done as unsigned. */ \ - int this_reg; \ - \ - DEBUG_STATEMENT (failure_id++); \ - DEBUG_STATEMENT (nfailure_points_pushed++); \ - DEBUG_PRINT2 ("\nPUSH_FAILURE_POINT #%u:\n", failure_id); \ - DEBUG_PRINT2 (" Before push, next avail: %d\n", (fail_stack).avail);\ - DEBUG_PRINT2 (" size: %d\n", (fail_stack).size);\ - \ - DEBUG_PRINT2 (" slots needed: %d\n", NUM_FAILURE_ITEMS); \ - DEBUG_PRINT2 (" available: %d\n", REMAINING_AVAIL_SLOTS); \ - \ - /* Ensure we have enough space allocated for what we will push. */ \ - while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \ - { \ - if (!DOUBLE_FAIL_STACK (fail_stack)) \ - return failure_code; \ - \ - DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \ - (fail_stack).size); \ - DEBUG_PRINT2 (" slots available: %d\n", REMAINING_AVAIL_SLOTS);\ - } \ - \ - /* Push the info, starting with the registers. */ \ - DEBUG_PRINT1 ("\n"); \ - \ - for (this_reg = lowest_active_reg; this_reg <= highest_active_reg; \ - this_reg++) \ - { \ - DEBUG_PRINT2 (" Pushing reg: %d\n", this_reg); \ - DEBUG_STATEMENT (num_regs_pushed++); \ - \ - DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \ - PUSH_FAILURE_ITEM (regstart[this_reg]); \ - \ - DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ - PUSH_FAILURE_ITEM (regend[this_reg]); \ - \ - DEBUG_PRINT2 (" info: 0x%x\n ", reg_info[this_reg]); \ - DEBUG_PRINT2 (" match_null=%d", \ - REG_MATCH_NULL_STRING_P (reg_info[this_reg])); \ - DEBUG_PRINT2 (" active=%d", IS_ACTIVE (reg_info[this_reg])); \ - DEBUG_PRINT2 (" matched_something=%d", \ - MATCHED_SOMETHING (reg_info[this_reg])); \ - DEBUG_PRINT2 (" ever_matched=%d", \ - EVER_MATCHED_SOMETHING (reg_info[this_reg])); \ - DEBUG_PRINT1 ("\n"); \ - PUSH_FAILURE_ITEM (reg_info[this_reg].word); \ - } \ - \ - DEBUG_PRINT2 (" Pushing low active reg: %d\n", lowest_active_reg);\ - PUSH_FAILURE_ITEM (lowest_active_reg); \ - \ - DEBUG_PRINT2 (" Pushing high active reg: %d\n", highest_active_reg);\ - PUSH_FAILURE_ITEM (highest_active_reg); \ - \ - DEBUG_PRINT2 (" Pushing pattern 0x%x: ", pattern_place); \ - DEBUG_PRINT_COMPILED_PATTERN (bufp, pattern_place, pend); \ - PUSH_FAILURE_ITEM (pattern_place); \ - \ - DEBUG_PRINT2 (" Pushing string 0x%x: `", string_place); \ - DEBUG_PRINT_DOUBLE_STRING (string_place, string1, size1, string2, \ - size2); \ - DEBUG_PRINT1 ("'\n"); \ - PUSH_FAILURE_ITEM (string_place); \ - \ - DEBUG_PRINT2 (" Pushing failure id: %u\n", failure_id); \ - DEBUG_PUSH (failure_id); \ - } while (0) - -/* This is the number of items that are pushed and popped on the stack - for each register. */ -#define NUM_REG_ITEMS 3 - -/* Individual items aside from the registers. */ -#ifdef DEBUG -#define NUM_NONREG_ITEMS 5 /* Includes failure point id. */ -#else -#define NUM_NONREG_ITEMS 4 -#endif - -/* We push at most this many items on the stack. */ -#define MAX_FAILURE_ITEMS ((num_regs - 1) * NUM_REG_ITEMS + NUM_NONREG_ITEMS) - -/* We actually push this many items. */ -#define NUM_FAILURE_ITEMS \ - ((highest_active_reg - lowest_active_reg + 1) * NUM_REG_ITEMS \ - + NUM_NONREG_ITEMS) - -/* How many items can still be added to the stack without overflowing it. */ -#define REMAINING_AVAIL_SLOTS ((fail_stack).size - (fail_stack).avail) - - -/* Pops what PUSH_FAIL_STACK pushes. - - We restore into the parameters, all of which should be lvalues: - STR -- the saved data position. - PAT -- the saved pattern position. - LOW_REG, HIGH_REG -- the highest and lowest active registers. - REGSTART, REGEND -- arrays of string positions. - REG_INFO -- array of information about each subexpression. - - Also assumes the variables `fail_stack' and (if debugging), `bufp', - `pend', `string1', `size1', `string2', and `size2'. */ - -#define POP_FAILURE_POINT(str, pat, low_reg, high_reg, regstart, regend, reg_info)\ -{ \ - DEBUG_STATEMENT (fail_stack_elt_t failure_id;) \ - int this_reg; \ - const unsigned char *string_temp; \ - \ - assert (!FAIL_STACK_EMPTY ()); \ - \ - /* Remove failure points and point to how many regs pushed. */ \ - DEBUG_PRINT1 ("POP_FAILURE_POINT:\n"); \ - DEBUG_PRINT2 (" Before pop, next avail: %d\n", fail_stack.avail); \ - DEBUG_PRINT2 (" size: %d\n", fail_stack.size); \ - \ - assert (fail_stack.avail >= NUM_NONREG_ITEMS); \ - \ - DEBUG_POP (&failure_id); \ - DEBUG_PRINT2 (" Popping failure id: %u\n", failure_id); \ - \ - /* If the saved string location is NULL, it came from an \ - on_failure_keep_string_jump opcode, and we want to throw away the \ - saved NULL, thus retaining our current position in the string. */ \ - string_temp = POP_FAILURE_ITEM (); \ - if (string_temp != NULL) \ - str = (const char *) string_temp; \ - \ - DEBUG_PRINT2 (" Popping string 0x%x: `", str); \ - DEBUG_PRINT_DOUBLE_STRING (str, string1, size1, string2, size2); \ - DEBUG_PRINT1 ("'\n"); \ - \ - pat = (unsigned char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping pattern 0x%x: ", pat); \ - DEBUG_PRINT_COMPILED_PATTERN (bufp, pat, pend); \ - \ - /* Restore register info. */ \ - high_reg = (unsigned) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping high active reg: %d\n", high_reg); \ - \ - low_reg = (unsigned) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" Popping low active reg: %d\n", low_reg); \ - \ - for (this_reg = high_reg; this_reg >= low_reg; this_reg--) \ - { \ - DEBUG_PRINT2 (" Popping reg: %d\n", this_reg); \ - \ - reg_info[this_reg].word = POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" info: 0x%x\n", reg_info[this_reg]); \ - \ - regend[this_reg] = (const char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" end: 0x%x\n", regend[this_reg]); \ - \ - regstart[this_reg] = (const char *) POP_FAILURE_ITEM (); \ - DEBUG_PRINT2 (" start: 0x%x\n", regstart[this_reg]); \ - } \ - \ - DEBUG_STATEMENT (nfailure_points_popped++); \ -} /* POP_FAILURE_POINT */ - -/* re_compile_fastmap computes a ``fastmap'' for the compiled pattern in - BUFP. A fastmap records which of the (1 << BYTEWIDTH) possible - characters can start a string that matches the pattern. This fastmap - is used by re_search to skip quickly over impossible starting points. - - The caller must supply the address of a (1 << BYTEWIDTH)-byte data - area as BUFP->fastmap. - - We set the `fastmap', `fastmap_accurate', and `can_be_null' fields in - the pattern buffer. - - Returns 0 if we succeed, -2 if an internal error. */ - -int -re_compile_fastmap (bufp) - struct re_pattern_buffer *bufp; -{ - int j, k; - fail_stack_type fail_stack; -#ifndef REGEX_MALLOC - char *destination; -#endif - /* We don't push any register information onto the failure stack. */ - unsigned num_regs = 0; - - register char *fastmap = bufp->fastmap; - unsigned char *pattern = bufp->buffer; - unsigned long size = bufp->used; - const unsigned char *p = pattern; - register unsigned char *pend = pattern + size; - - /* Assume that each path through the pattern can be null until - proven otherwise. We set this false at the bottom of switch - statement, to which we get only if a particular path doesn't - match the empty string. */ - boolean path_can_be_null = true; - - /* We aren't doing a `succeed_n' to begin with. */ - boolean succeed_n_p = false; - - assert (fastmap != NULL && p != NULL); - - INIT_FAIL_STACK (); - bzero (fastmap, 1 << BYTEWIDTH); /* Assume nothing's valid. */ - bufp->fastmap_accurate = 1; /* It will be when we're done. */ - bufp->can_be_null = 0; - - while (p != pend || !FAIL_STACK_EMPTY ()) - { - if (p == pend) - { - bufp->can_be_null |= path_can_be_null; - - /* Reset for next path. */ - path_can_be_null = true; - - p = fail_stack.stack[--fail_stack.avail]; - } - - /* We should never be about to go beyond the end of the pattern. */ - assert (p < pend); - -#ifdef SWITCH_ENUM_BUG - switch ((int) ((re_opcode_t) *p++)) -#else - switch ((re_opcode_t) *p++) -#endif - { - - /* I guess the idea here is to simply not bother with a fastmap - if a backreference is used, since it's too hard to figure out - the fastmap for the corresponding group. Setting - `can_be_null' stops `re_search_2' from using the fastmap, so - that is all we do. */ - case duplicate: - bufp->can_be_null = 1; - return 0; - - - /* Following are the cases which match a character. These end - with `break'. */ - - case exactn: - fastmap[p[1]] = 1; - break; - - - case charset: - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH))) - fastmap[j] = 1; - break; - - - case charset_not: - /* Chars beyond end of map must be allowed. */ - for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) - fastmap[j] = 1; - - for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) - if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) - fastmap[j] = 1; - break; - - - case wordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == Sword) - fastmap[j] = 1; - break; - - - case notwordchar: - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != Sword) - fastmap[j] = 1; - break; - - - case anychar: - /* `.' matches anything ... */ - for (j = 0; j < (1 << BYTEWIDTH); j++) - fastmap[j] = 1; - - /* ... except perhaps newline. */ - if (!(bufp->syntax & RE_DOT_NEWLINE)) - fastmap['\n'] = 0; - - /* Return if we have already set `can_be_null'; if we have, - then the fastmap is irrelevant. Something's wrong here. */ - else if (bufp->can_be_null) - return 0; - - /* Otherwise, have to check alternative paths. */ - break; - - -#ifdef emacs - case syntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == (enum syntaxcode) k) - fastmap[j] = 1; - break; - - - case notsyntaxspec: - k = *p++; - for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != (enum syntaxcode) k) - fastmap[j] = 1; - break; - - - /* All cases after this match the empty string. These end with - `continue'. */ - - - case before_dot: - case at_dot: - case after_dot: - continue; -#endif /* not emacs */ - - - case no_op: - case begline: - case endline: - case begbuf: - case endbuf: - case wordbound: - case notwordbound: - case wordbeg: - case wordend: - case push_dummy_failure: - continue; - - - case jump_n: - case pop_failure_jump: - case maybe_pop_jump: - case jump: - case jump_past_alt: - case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); - p += j; - if (j > 0) - continue; - - /* Jump backward implies we just went through the body of a - loop and matched nothing. Opcode jumped to should be - `on_failure_jump' or `succeed_n'. Just treat it like an - ordinary jump. For a * loop, it has pushed its failure - point already; if so, discard that as redundant. */ - if ((re_opcode_t) *p != on_failure_jump - && (re_opcode_t) *p != succeed_n) - continue; - - p++; - EXTRACT_NUMBER_AND_INCR (j, p); - p += j; - - /* If what's on the stack is where we are now, pop it. */ - if (!FAIL_STACK_EMPTY () - && fail_stack.stack[fail_stack.avail - 1] == p) - fail_stack.avail--; - - continue; - - - case on_failure_jump: - case on_failure_keep_string_jump: - handle_on_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); - - /* For some patterns, e.g., `(a?)?', `p+j' here points to the - end of the pattern. We don't want to push such a point, - since when we restore it above, entering the switch will - increment `p' past the end of the pattern. We don't need - to push such a point since we obviously won't find any more - fastmap entries beyond `pend'. Such a pattern can match - the null string, though. */ - if (p + j < pend) - { - if (!PUSH_PATTERN_OP (p + j, fail_stack)) - return -2; - } - else - bufp->can_be_null = 1; - - if (succeed_n_p) - { - EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */ - succeed_n_p = false; - } - - continue; - - - case succeed_n: - /* Get to the number of times to succeed. */ - p += 2; - - /* Increment p past the n for when k != 0. */ - EXTRACT_NUMBER_AND_INCR (k, p); - if (k == 0) - { - p -= 4; - succeed_n_p = true; /* Spaghetti code alert. */ - goto handle_on_failure_jump; - } - continue; - - - case set_number_at: - p += 4; - continue; - - - case start_memory: - case stop_memory: - p += 2; - continue; - - - default: - abort (); /* We have listed all the cases. */ - } /* switch *p++ */ - - /* Getting here means we have found the possible starting - characters for one path of the pattern -- and that the empty - string does not match. We need not follow this path further. - Instead, look at the next alternative (remembered on the - stack), or quit if no more. The test at the top of the loop - does these things. */ - path_can_be_null = false; - p = pend; - } /* while p */ - - /* Set `can_be_null' for the last path (also the first path, if the - pattern is empty). */ - bufp->can_be_null |= path_can_be_null; - return 0; -} /* re_compile_fastmap */ - -/* Set REGS to hold NUM_REGS registers, storing them in STARTS and - ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use - this memory for recording register information. STARTS and ENDS - must be allocated using the malloc library routine, and must each - be at least NUM_REGS * sizeof (regoff_t) bytes long. - - If NUM_REGS == 0, then subsequent matches should allocate their own - register data. - - Unless this function is called, the first search or match using - PATTERN_BUFFER will allocate its own register data, without - freeing the old data. */ - -void -re_set_registers (bufp, regs, num_regs, starts, ends) - struct re_pattern_buffer *bufp; - struct re_registers *regs; - unsigned num_regs; - regoff_t *starts, *ends; -{ - if (num_regs) - { - bufp->regs_allocated = REGS_REALLOCATE; - regs->num_regs = num_regs; - regs->start = starts; - regs->end = ends; - } - else - { - bufp->regs_allocated = REGS_UNALLOCATED; - regs->num_regs = 0; - regs->start = regs->end = (regoff_t) 0; - } -} - -/* Searching routines. */ - -/* Like re_search_2, below, but only one string is specified, and - doesn't let you say where to stop matching. */ - -int -re_search (bufp, string, size, startpos, range, regs) - struct re_pattern_buffer *bufp; - const char *string; - int size, startpos, range; - struct re_registers *regs; -{ - return re_search_2 (bufp, NULL, 0, string, size, startpos, range, - regs, size); -} - - -/* Using the compiled pattern in BUFP->buffer, first tries to match the - virtual concatenation of STRING1 and STRING2, starting first at index - STARTPOS, then at STARTPOS + 1, and so on. - - STRING1 and STRING2 have length SIZE1 and SIZE2, respectively. - - RANGE is how far to scan while trying to match. RANGE = 0 means try - only at STARTPOS; in general, the last start tried is STARTPOS + - RANGE. - - In REGS, return the indices of the virtual concatenation of STRING1 - and STRING2 that matched the entire BUFP->buffer and its contained - subexpressions. - - Do not consider matching one past the index STOP in the virtual - concatenation of STRING1 and STRING2. - - We return either the position in the strings at which the match was - found, -1 if no match, or -2 if error (such as failure - stack overflow). */ - -int -re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int startpos; - int range; - struct re_registers *regs; - int stop; -{ - int val; - register char *fastmap = bufp->fastmap; - register char *translate = bufp->translate; - int total_size = size1 + size2; - int endpos = startpos + range; - - /* Check for out-of-range STARTPOS. */ - if (startpos < 0 || startpos > total_size) - return -1; - - /* Fix up RANGE if it might eventually take us outside - the virtual concatenation of STRING1 and STRING2. */ - if (endpos < -1) - range = -1 - startpos; - else if (endpos > total_size) - range = total_size - startpos; - - /* If the search isn't to be a backwards one, don't waste time in a - search for a pattern that must be anchored. */ - if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0) - { - if (startpos > 0) - return -1; - else - range = 1; - } - - /* Update the fastmap now if not correct already. */ - if (fastmap && !bufp->fastmap_accurate) - if (re_compile_fastmap (bufp) == -2) - return -2; - - /* Loop through the string, looking for a place to start matching. */ - for (;;) - { - /* If a fastmap is supplied, skip quickly over characters that - cannot be the start of a match. If the pattern can match the - null string, however, we don't need to skip characters; we want - the first null string. */ - if (fastmap && startpos < total_size && !bufp->can_be_null) - { - if (range > 0) /* Searching forwards. */ - { - register const char *d; - register int lim = 0; - int irange = range; - - if (startpos < size1 && startpos + range >= size1) - lim = range - (size1 - startpos); - - d = (startpos >= size1 ? string2 - size1 : string1) + startpos; - - /* Written out as an if-else to avoid testing `translate' - inside the loop. */ - if (translate) - while (range > lim - && !fastmap[(unsigned char) - translate[(unsigned char) *d++]]) - range--; - else - while (range > lim && !fastmap[(unsigned char) *d++]) - range--; - - startpos += irange - range; - } - else /* Searching backwards. */ - { - register char c = (size1 == 0 || startpos >= size1 - ? string2[startpos - size1] - : string1[startpos]); - - if (!fastmap[(unsigned char) TRANSLATE (c)]) - goto advance; - } - } - - /* If can't match the null string, and that's all we have left, fail. */ - if (range >= 0 && startpos == total_size && fastmap - && !bufp->can_be_null) - return -1; - - val = re_match_2 (bufp, string1, size1, string2, size2, - startpos, regs, stop); - if (val >= 0) - return startpos; - - if (val == -2) - return -2; - - advance: - if (!range) - break; - else if (range > 0) - { - range--; - startpos++; - } - else - { - range++; - startpos--; - } - } - return -1; -} /* re_search_2 */ - -/* Declarations and macros for re_match_2. */ - -static int bcmp_translate (); -static boolean alt_match_null_string_p (), - common_op_match_null_string_p (), - group_match_null_string_p (); - -/* Structure for per-register (a.k.a. per-group) information. - This must not be longer than one word, because we push this value - onto the failure stack. Other register information, such as the - starting and ending positions (which are addresses), and the list of - inner groups (which is a bits list) are maintained in separate - variables. - - We are making a (strictly speaking) nonportable assumption here: that - the compiler will pack our bit fields into something that fits into - the type of `word', i.e., is something that fits into one item on the - failure stack. */ -typedef union -{ - fail_stack_elt_t word; - struct - { - /* This field is one if this group can match the empty string, - zero if not. If not yet determined, `MATCH_NULL_UNSET_VALUE'. */ -#define MATCH_NULL_UNSET_VALUE 3 - unsigned match_null_string_p : 2; - unsigned is_active : 1; - unsigned matched_something : 1; - unsigned ever_matched_something : 1; - } bits; -} register_info_type; - -#define REG_MATCH_NULL_STRING_P(R) ((R).bits.match_null_string_p) -#define IS_ACTIVE(R) ((R).bits.is_active) -#define MATCHED_SOMETHING(R) ((R).bits.matched_something) -#define EVER_MATCHED_SOMETHING(R) ((R).bits.ever_matched_something) - - -/* Call this when have matched a real character; it sets `matched' flags - for the subexpressions which we are currently inside. Also records - that those subexprs have matched. */ -#define SET_REGS_MATCHED() \ - do \ - { \ - unsigned r; \ - for (r = lowest_active_reg; r <= highest_active_reg; r++) \ - { \ - MATCHED_SOMETHING (reg_info[r]) \ - = EVER_MATCHED_SOMETHING (reg_info[r]) \ - = 1; \ - } \ - } \ - while (0) - - -/* This converts PTR, a pointer into one of the search strings `string1' - and `string2' into an offset from the beginning of that string. */ -#define POINTER_TO_OFFSET(ptr) \ - (FIRST_STRING_P (ptr) ? (ptr) - string1 : (ptr) - string2 + size1) - -/* Registers are set to a sentinel when they haven't yet matched. */ -#define REG_UNSET_VALUE ((char *) -1) -#define REG_UNSET(e) ((e) == REG_UNSET_VALUE) - - -/* Macros for dealing with the split strings in re_match_2. */ - -#define MATCHING_IN_FIRST_STRING (dend == end_match_1) - -/* Call before fetching a character with *d. This switches over to - string2 if necessary. */ -#define PREFETCH() \ - while (d == dend) \ - { \ - /* End of string2 => fail. */ \ - if (dend == end_match_2) \ - goto fail; \ - /* End of string1 => advance to string2. */ \ - d = string2; \ - dend = end_match_2; \ - } - - -/* Test if at very beginning or at very end of the virtual concatenation - of `string1' and `string2'. If only one string, it's `string2'. */ -#define AT_STRINGS_BEG(d) ((d) == (size1 ? string1 : string2) || !size2) -#define AT_STRINGS_END(d) ((d) == end2) - - -/* Test if D points to a character which is word-constituent. We have - two special cases to check for: if past the end of string1, look at - the first character in string2; and if before the beginning of - string2, look at the last character in string1. */ -#define WORDCHAR_P(d) \ - (SYNTAX ((d) == end1 ? *string2 \ - : (d) == string2 - 1 ? *(end1 - 1) : *(d)) \ - == Sword) - -/* Test if the character before D and the one at D differ with respect - to being word-constituent. */ -#define AT_WORD_BOUNDARY(d) \ - (AT_STRINGS_BEG (d) || AT_STRINGS_END (d) \ - || WORDCHAR_P (d - 1) != WORDCHAR_P (d)) - - -/* Free everything we malloc. */ -#ifdef REGEX_MALLOC -#define FREE_VAR(var) if (var) free (var); var = NULL -#define FREE_VARIABLES() \ - do { \ - FREE_VAR (fail_stack.stack); \ - FREE_VAR (regstart); \ - FREE_VAR (regend); \ - FREE_VAR (old_regstart); \ - FREE_VAR (old_regend); \ - FREE_VAR (best_regstart); \ - FREE_VAR (best_regend); \ - FREE_VAR (reg_info); \ - FREE_VAR (reg_dummy); \ - FREE_VAR (reg_info_dummy); \ - } while (0) -#else /* not REGEX_MALLOC */ -/* Some MIPS systems (at least) want this to free alloca'd storage. */ -#define FREE_VARIABLES() alloca (0) -#endif /* not REGEX_MALLOC */ - - -/* These values must meet several constraints. They must not be valid - register values; since we have a limit of 255 registers (because - we use only one byte in the pattern for the register number), we can - use numbers larger than 255. They must differ by 1, because of - NUM_FAILURE_ITEMS above. And the value for the lowest register must - be larger than the value for the highest register, so we do not try - to actually save any registers when none are active. */ -#define NO_HIGHEST_ACTIVE_REG (1 << BYTEWIDTH) -#define NO_LOWEST_ACTIVE_REG (NO_HIGHEST_ACTIVE_REG + 1) - -/* Matching routines. */ - -#ifndef emacs /* Emacs never uses this. */ -/* re_match is like re_match_2 except it takes only a single string. */ - -int -re_match (bufp, string, size, pos, regs) - struct re_pattern_buffer *bufp; - const char *string; - int size, pos; - struct re_registers *regs; - { - return re_match_2 (bufp, NULL, 0, string, size, pos, regs, size); -} -#endif /* not emacs */ - - -/* re_match_2 matches the compiled pattern in BUFP against the - the (virtual) concatenation of STRING1 and STRING2 (of length SIZE1 - and SIZE2, respectively). We start matching at POS, and stop - matching at STOP. - - If REGS is non-null and the `no_sub' field of BUFP is nonzero, we - store offsets for the substring each group matched in REGS. See the - documentation for exactly how many groups we fill. - - We return -1 if no match, -2 if an internal error (such as the - failure stack overflowing). Otherwise, we return the length of the - matched substring. */ - -int -re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) - struct re_pattern_buffer *bufp; - const char *string1, *string2; - int size1, size2; - int pos; - struct re_registers *regs; - int stop; -{ - /* General temporaries. */ - int mcnt; - unsigned char *p1; - - /* Just past the end of the corresponding string. */ - const char *end1, *end2; - - /* Pointers into string1 and string2, just past the last characters in - each to consider matching. */ - const char *end_match_1, *end_match_2; - - /* Where we are in the data, and the end of the current string. */ - const char *d, *dend; - - /* Where we are in the pattern, and the end of the pattern. */ - unsigned char *p = bufp->buffer; - register unsigned char *pend = p + bufp->used; - - /* We use this to map every character in the string. */ - char *translate = bufp->translate; - - /* Failure point stack. Each place that can handle a failure further - down the line pushes a failure point on this stack. It consists of - restart, regend, and reg_info for all registers corresponding to - the subexpressions we're currently inside, plus the number of such - registers, and, finally, two char *'s. The first char * is where - to resume scanning the pattern; the second one is where to resume - scanning the strings. If the latter is zero, the failure point is - a ``dummy''; if a failure happens and the failure point is a dummy, - it gets discarded and the next next one is tried. */ - fail_stack_type fail_stack; -#ifdef DEBUG - static unsigned failure_id = 0; - unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; -#endif - - /* We fill all the registers internally, independent of what we - return, for use in backreferences. The number here includes - an element for register zero. */ - unsigned num_regs = bufp->re_nsub + 1; - - /* The currently active registers. */ - unsigned lowest_active_reg = NO_LOWEST_ACTIVE_REG; - unsigned highest_active_reg = NO_HIGHEST_ACTIVE_REG; - - /* Information on the contents of registers. These are pointers into - the input strings; they record just what was matched (on this - attempt) by a subexpression part of the pattern, that is, the - regnum-th regstart pointer points to where in the pattern we began - matching and the regnum-th regend points to right after where we - stopped matching the regnum-th subexpression. (The zeroth register - keeps track of what the whole pattern matches.) */ - const char **regstart, **regend; - - /* If a group that's operated upon by a repetition operator fails to - match anything, then the register for its start will need to be - restored because it will have been set to wherever in the string we - are when we last see its open-group operator. Similarly for a - register's end. */ - const char **old_regstart, **old_regend; - - /* The is_active field of reg_info helps us keep track of which (possibly - nested) subexpressions we are currently in. The matched_something - field of reg_info[reg_num] helps us tell whether or not we have - matched any of the pattern so far this time through the reg_num-th - subexpression. These two fields get reset each time through any - loop their register is in. */ - register_info_type *reg_info; - - /* The following record the register info as found in the above - variables when we find a match better than any we've seen before. - This happens as we backtrack through the failure points, which in - turn happens only if we have not yet matched the entire string. */ - unsigned best_regs_set = false; - const char **best_regstart, **best_regend; - - /* Logically, this is `best_regend[0]'. But we don't want to have to - allocate space for that if we're not allocating space for anything - else (see below). Also, we never need info about register 0 for - any of the other register vectors, and it seems rather a kludge to - treat `best_regend' differently than the rest. So we keep track of - the end of the best match so far in a separate variable. We - initialize this to NULL so that when we backtrack the first time - and need to test it, it's not garbage. */ - const char *match_end = NULL; - - /* Used when we pop values we don't care about. */ - const char **reg_dummy; - register_info_type *reg_info_dummy; - -#ifdef DEBUG - /* Counts the total number of registers pushed. */ - unsigned num_regs_pushed = 0; -#endif - - DEBUG_PRINT1 ("\n\nEntering re_match_2.\n"); - - INIT_FAIL_STACK (); - - /* Do not bother to initialize all the register variables if there are - no groups in the pattern, as it takes a fair amount of time. If - there are groups, we include space for register 0 (the whole - pattern), even though we never use it, since it simplifies the - array indexing. We should fix this. */ - if (bufp->re_nsub) - { - regstart = REGEX_TALLOC (num_regs, const char *); - regend = REGEX_TALLOC (num_regs, const char *); - old_regstart = REGEX_TALLOC (num_regs, const char *); - old_regend = REGEX_TALLOC (num_regs, const char *); - best_regstart = REGEX_TALLOC (num_regs, const char *); - best_regend = REGEX_TALLOC (num_regs, const char *); - reg_info = REGEX_TALLOC (num_regs, register_info_type); - reg_dummy = REGEX_TALLOC (num_regs, const char *); - reg_info_dummy = REGEX_TALLOC (num_regs, register_info_type); - - if (!(regstart && regend && old_regstart && old_regend && reg_info - && best_regstart && best_regend && reg_dummy && reg_info_dummy)) - { - FREE_VARIABLES (); - return -2; - } - } -#ifdef REGEX_MALLOC - else - { - /* We must initialize all our variables to NULL, so that - `FREE_VARIABLES' doesn't try to free them. */ - regstart = regend = old_regstart = old_regend = best_regstart - = best_regend = reg_dummy = NULL; - reg_info = reg_info_dummy = (register_info_type *) NULL; - } -#endif /* REGEX_MALLOC */ - - /* The starting position is bogus. */ - if (pos < 0 || pos > size1 + size2) - { - FREE_VARIABLES (); - return -1; - } - - /* Initialize subexpression text positions to -1 to mark ones that no - start_memory/stop_memory has been seen for. Also initialize the - register information struct. */ - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - regstart[mcnt] = regend[mcnt] - = old_regstart[mcnt] = old_regend[mcnt] = REG_UNSET_VALUE; - - REG_MATCH_NULL_STRING_P (reg_info[mcnt]) = MATCH_NULL_UNSET_VALUE; - IS_ACTIVE (reg_info[mcnt]) = 0; - MATCHED_SOMETHING (reg_info[mcnt]) = 0; - EVER_MATCHED_SOMETHING (reg_info[mcnt]) = 0; - } - - /* We move `string1' into `string2' if the latter's empty -- but not if - `string1' is null. */ - if (size2 == 0 && string1 != NULL) - { - string2 = string1; - size2 = size1; - string1 = 0; - size1 = 0; - } - end1 = string1 + size1; - end2 = string2 + size2; - - /* Compute where to stop matching, within the two strings. */ - if (stop <= size1) - { - end_match_1 = string1 + stop; - end_match_2 = string2; - } - else - { - end_match_1 = end1; - end_match_2 = string2 + stop - size1; - } - - /* `p' scans through the pattern as `d' scans through the data. - `dend' is the end of the input string that `d' points within. `d' - is advanced into the following input string whenever necessary, but - this happens before fetching; therefore, at the beginning of the - loop, `d' can be pointing at the end of a string, but it cannot - equal `string2'. */ - if (size1 > 0 && pos <= size1) - { - d = string1 + pos; - dend = end_match_1; - } - else - { - d = string2 + pos - size1; - dend = end_match_2; - } - - DEBUG_PRINT1 ("The compiled pattern is: "); - DEBUG_PRINT_COMPILED_PATTERN (bufp, p, pend); - DEBUG_PRINT1 ("The string to match is: `"); - DEBUG_PRINT_DOUBLE_STRING (d, string1, size1, string2, size2); - DEBUG_PRINT1 ("'\n"); - - /* This loops over pattern commands. It exits by returning from the - function if the match is complete, or it drops through if the match - fails at this starting point in the input data. */ - for (;;) - { - DEBUG_PRINT2 ("\n0x%x: ", p); - - if (p == pend) - { /* End of pattern means we might have succeeded. */ - DEBUG_PRINT1 ("end of pattern ... "); - - /* If we haven't matched the entire string, and we want the - longest match, try backtracking. */ - if (d != end_match_2) - { - DEBUG_PRINT1 ("backtracking.\n"); - - if (!FAIL_STACK_EMPTY ()) - { /* More failure points to try. */ - boolean same_str_p = (FIRST_STRING_P (match_end) - == MATCHING_IN_FIRST_STRING); - - /* If exceeds best match so far, save it. */ - if (!best_regs_set - || (same_str_p && d > match_end) - || (!same_str_p && !MATCHING_IN_FIRST_STRING)) - { - best_regs_set = true; - match_end = d; - - DEBUG_PRINT1 ("\nSAVING match as best so far.\n"); - - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - best_regstart[mcnt] = regstart[mcnt]; - best_regend[mcnt] = regend[mcnt]; - } - } - goto fail; - } - - /* If no failure points, don't restore garbage. */ - else if (best_regs_set) - { - restore_best_regs: - /* Restore best match. It may happen that `dend == - end_match_1' while the restored d is in string2. - For example, the pattern `x.*y.*z' against the - strings `x-' and `y-z-', if the two strings are - not consecutive in memory. */ - DEBUG_PRINT1 ("Restoring best registers.\n"); - - d = match_end; - dend = ((d >= string1 && d <= end1) - ? end_match_1 : end_match_2); - - for (mcnt = 1; mcnt < num_regs; mcnt++) - { - regstart[mcnt] = best_regstart[mcnt]; - regend[mcnt] = best_regend[mcnt]; - } - } - } /* d != end_match_2 */ - - DEBUG_PRINT1 ("Accepting match.\n"); - - /* If caller wants register contents data back, do it. */ - if (regs && !bufp->no_sub) - { - /* Have the register data arrays been allocated? */ - if (bufp->regs_allocated == REGS_UNALLOCATED) - { /* No. So allocate them with malloc. We need one - extra element beyond `num_regs' for the `-1' marker - GNU code uses. */ - regs->num_regs = MAX (RE_NREGS, num_regs + 1); - regs->start = TALLOC (regs->num_regs, regoff_t); - regs->end = TALLOC (regs->num_regs, regoff_t); - if (regs->start == NULL || regs->end == NULL) - return -2; - bufp->regs_allocated = REGS_REALLOCATE; - } - else if (bufp->regs_allocated == REGS_REALLOCATE) - { /* Yes. If we need more elements than were already - allocated, reallocate them. If we need fewer, just - leave it alone. */ - if (regs->num_regs < num_regs + 1) - { - regs->num_regs = num_regs + 1; - RETALLOC (regs->start, regs->num_regs, regoff_t); - RETALLOC (regs->end, regs->num_regs, regoff_t); - if (regs->start == NULL || regs->end == NULL) - return -2; - } - } - else - assert (bufp->regs_allocated == REGS_FIXED); - - /* Convert the pointer data in `regstart' and `regend' to - indices. Register zero has to be set differently, - since we haven't kept track of any info for it. */ - if (regs->num_regs > 0) - { - regs->start[0] = pos; - regs->end[0] = (MATCHING_IN_FIRST_STRING ? d - string1 - : d - string2 + size1); - } - - /* Go through the first `min (num_regs, regs->num_regs)' - registers, since that is all we initialized. */ - for (mcnt = 1; mcnt < MIN (num_regs, regs->num_regs); mcnt++) - { - if (REG_UNSET (regstart[mcnt]) || REG_UNSET (regend[mcnt])) - regs->start[mcnt] = regs->end[mcnt] = -1; - else - { - regs->start[mcnt] = POINTER_TO_OFFSET (regstart[mcnt]); - regs->end[mcnt] = POINTER_TO_OFFSET (regend[mcnt]); - } - } - - /* If the regs structure we return has more elements than - were in the pattern, set the extra elements to -1. If - we (re)allocated the registers, this is the case, - because we always allocate enough to have at least one - -1 at the end. */ - for (mcnt = num_regs; mcnt < regs->num_regs; mcnt++) - regs->start[mcnt] = regs->end[mcnt] = -1; - } /* regs && !bufp->no_sub */ - - FREE_VARIABLES (); - DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", - nfailure_points_pushed, nfailure_points_popped, - nfailure_points_pushed - nfailure_points_popped); - DEBUG_PRINT2 ("%u registers pushed.\n", num_regs_pushed); - - mcnt = d - pos - (MATCHING_IN_FIRST_STRING - ? string1 - : string2 - size1); - - DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); - - return mcnt; - } - - /* Otherwise match next pattern command. */ -#ifdef SWITCH_ENUM_BUG - switch ((int) ((re_opcode_t) *p++)) -#else - switch ((re_opcode_t) *p++) -#endif - { - /* Ignore these. Used to ignore the n of succeed_n's which - currently have n == 0. */ - case no_op: - DEBUG_PRINT1 ("EXECUTING no_op.\n"); - break; - - - /* Match the next n pattern characters exactly. The following - byte in the pattern defines n, and the n bytes after that - are the characters to match. */ - case exactn: - mcnt = *p++; - DEBUG_PRINT2 ("EXECUTING exactn %d.\n", mcnt); - - /* This is written out as an if-else so we don't waste time - testing `translate' inside the loop. */ - if (translate) - { - do - { - PREFETCH (); - if (translate[(unsigned char) *d++] != (char) *p++) - goto fail; - } - while (--mcnt); - } - else - { - do - { - PREFETCH (); - if (*d++ != (char) *p++) goto fail; - } - while (--mcnt); - } - SET_REGS_MATCHED (); - break; - - - /* Match any character except possibly a newline or a null. */ - case anychar: - DEBUG_PRINT1 ("EXECUTING anychar.\n"); - - PREFETCH (); - - if ((!(bufp->syntax & RE_DOT_NEWLINE) && TRANSLATE (*d) == '\n') - || (bufp->syntax & RE_DOT_NOT_NULL && TRANSLATE (*d) == '\000')) - goto fail; - - SET_REGS_MATCHED (); - DEBUG_PRINT2 (" Matched `%d'.\n", *d); - d++; - break; - - - case charset: - case charset_not: - { - register unsigned char c; - boolean not = (re_opcode_t) *(p - 1) == charset_not; - - DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); - - PREFETCH (); - c = TRANSLATE (*d); /* The character to match. */ - - /* Cast to `unsigned' instead of `unsigned char' in case the - bit list is a full 32 bytes long. */ - if (c < (unsigned) (*p * BYTEWIDTH) - && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - p += 1 + *p; - - if (!not) goto fail; - - SET_REGS_MATCHED (); - d++; - break; - } - - - /* The beginning of a group is represented by start_memory. - The arguments are the register number in the next byte, and the - number of groups inner to this one in the next. The text - matched within the group is recorded (in the internal - registers data structure) under the register number. */ - case start_memory: - DEBUG_PRINT3 ("EXECUTING start_memory %d (%d):\n", *p, p[1]); - - /* Find out if this group can match the empty string. */ - p1 = p; /* To send to group_match_null_string_p. */ - - if (REG_MATCH_NULL_STRING_P (reg_info[*p]) == MATCH_NULL_UNSET_VALUE) - REG_MATCH_NULL_STRING_P (reg_info[*p]) - = group_match_null_string_p (&p1, pend, reg_info); - - /* Save the position in the string where we were the last time - we were at this open-group operator in case the group is - operated upon by a repetition operator, e.g., with `(a*)*b' - against `ab'; then we want to ignore where we are now in - the string in case this attempt to match fails. */ - old_regstart[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) - ? REG_UNSET (regstart[*p]) ? d : regstart[*p] - : regstart[*p]; - DEBUG_PRINT2 (" old_regstart: %d\n", - POINTER_TO_OFFSET (old_regstart[*p])); - - regstart[*p] = d; - DEBUG_PRINT2 (" regstart: %d\n", POINTER_TO_OFFSET (regstart[*p])); - - IS_ACTIVE (reg_info[*p]) = 1; - MATCHED_SOMETHING (reg_info[*p]) = 0; - - /* This is the new highest active register. */ - highest_active_reg = *p; - - /* If nothing was active before, this is the new lowest active - register. */ - if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) - lowest_active_reg = *p; - - /* Move past the register number and inner group count. */ - p += 2; - break; - - - /* The stop_memory opcode represents the end of a group. Its - arguments are the same as start_memory's: the register - number, and the number of inner groups. */ - case stop_memory: - DEBUG_PRINT3 ("EXECUTING stop_memory %d (%d):\n", *p, p[1]); - - /* We need to save the string position the last time we were at - this close-group operator in case the group is operated - upon by a repetition operator, e.g., with `((a*)*(b*)*)*' - against `aba'; then we want to ignore where we are now in - the string in case this attempt to match fails. */ - old_regend[*p] = REG_MATCH_NULL_STRING_P (reg_info[*p]) - ? REG_UNSET (regend[*p]) ? d : regend[*p] - : regend[*p]; - DEBUG_PRINT2 (" old_regend: %d\n", - POINTER_TO_OFFSET (old_regend[*p])); - - regend[*p] = d; - DEBUG_PRINT2 (" regend: %d\n", POINTER_TO_OFFSET (regend[*p])); - - /* This register isn't active anymore. */ - IS_ACTIVE (reg_info[*p]) = 0; - - /* If this was the only register active, nothing is active - anymore. */ - if (lowest_active_reg == highest_active_reg) - { - lowest_active_reg = NO_LOWEST_ACTIVE_REG; - highest_active_reg = NO_HIGHEST_ACTIVE_REG; - } - else - { /* We must scan for the new highest active register, since - it isn't necessarily one less than now: consider - (a(b)c(d(e)f)g). When group 3 ends, after the f), the - new highest active register is 1. */ - unsigned char r = *p - 1; - while (r > 0 && !IS_ACTIVE (reg_info[r])) - r--; - - /* If we end up at register zero, that means that we saved - the registers as the result of an `on_failure_jump', not - a `start_memory', and we jumped to past the innermost - `stop_memory'. For example, in ((.)*) we save - registers 1 and 2 as a result of the *, but when we pop - back to the second ), we are at the stop_memory 1. - Thus, nothing is active. */ - if (r == 0) - { - lowest_active_reg = NO_LOWEST_ACTIVE_REG; - highest_active_reg = NO_HIGHEST_ACTIVE_REG; - } - else - highest_active_reg = r; - } - - /* If just failed to match something this time around with a - group that's operated on by a repetition operator, try to - force exit from the ``loop'', and restore the register - information for this group that we had before trying this - last match. */ - if ((!MATCHED_SOMETHING (reg_info[*p]) - || (re_opcode_t) p[-3] == start_memory) - && (p + 2) < pend) - { - boolean is_a_jump_n = false; - - p1 = p + 2; - mcnt = 0; - switch ((re_opcode_t) *p1++) - { - case jump_n: - is_a_jump_n = true; - case pop_failure_jump: - case maybe_pop_jump: - case jump: - case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if (is_a_jump_n) - p1 += 2; - break; - - default: - /* do nothing */ ; - } - p1 += mcnt; - - /* If the next operation is a jump backwards in the pattern - to an on_failure_jump right before the start_memory - corresponding to this stop_memory, exit from the loop - by forcing a failure after pushing on the stack the - on_failure_jump's jump in the pattern, and d. */ - if (mcnt < 0 && (re_opcode_t) *p1 == on_failure_jump - && (re_opcode_t) p1[3] == start_memory && p1[4] == *p) - { - /* If this group ever matched anything, then restore - what its registers were before trying this last - failed match, e.g., with `(a*)*b' against `ab' for - regstart[1], and, e.g., with `((a*)*(b*)*)*' - against `aba' for regend[3]. - - Also restore the registers for inner groups for, - e.g., `((a*)(b*))*' against `aba' (register 3 would - otherwise get trashed). */ - - if (EVER_MATCHED_SOMETHING (reg_info[*p])) - { - unsigned r; - - EVER_MATCHED_SOMETHING (reg_info[*p]) = 0; - - /* Restore this and inner groups' (if any) registers. */ - for (r = *p; r < *p + *(p + 1); r++) - { - regstart[r] = old_regstart[r]; - - /* xx why this test? */ - if ((int) old_regend[r] >= (int) regstart[r]) - regend[r] = old_regend[r]; - } - } - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - PUSH_FAILURE_POINT (p1 + mcnt, d, -2); - - goto fail; - } - } - - /* Move past the register number and the inner group count. */ - p += 2; - break; - - - /* \ has been turned into a `duplicate' command which is - followed by the numeric value of as the register number. */ - case duplicate: - { - register const char *d2, *dend2; - int regno = *p++; /* Get which register to match against. */ - DEBUG_PRINT2 ("EXECUTING duplicate %d.\n", regno); - - /* Can't back reference a group which we've never matched. */ - if (REG_UNSET (regstart[regno]) || REG_UNSET (regend[regno])) - goto fail; - - /* Where in input to try to start matching. */ - d2 = regstart[regno]; - - /* Where to stop matching; if both the place to start and - the place to stop matching are in the same string, then - set to the place to stop, otherwise, for now have to use - the end of the first string. */ - - dend2 = ((FIRST_STRING_P (regstart[regno]) - == FIRST_STRING_P (regend[regno])) - ? regend[regno] : end_match_1); - for (;;) - { - /* If necessary, advance to next segment in register - contents. */ - while (d2 == dend2) - { - if (dend2 == end_match_2) break; - if (dend2 == regend[regno]) break; - - /* End of string1 => advance to string2. */ - d2 = string2; - dend2 = regend[regno]; - } - /* At end of register contents => success */ - if (d2 == dend2) break; - - /* If necessary, advance to next segment in data. */ - PREFETCH (); - - /* How many characters left in this segment to match. */ - mcnt = dend - d; - - /* Want how many consecutive characters we can match in - one shot, so, if necessary, adjust the count. */ - if (mcnt > dend2 - d2) - mcnt = dend2 - d2; - - /* Compare that many; failure if mismatch, else move - past them. */ - if (translate - ? bcmp_translate (d, d2, mcnt, translate) - : bcmp (d, d2, mcnt)) - goto fail; - d += mcnt, d2 += mcnt; - } - } - break; - - - /* begline matches the empty string at the beginning of the string - (unless `not_bol' is set in `bufp'), and, if - `newline_anchor' is set, after newlines. */ - case begline: - DEBUG_PRINT1 ("EXECUTING begline.\n"); - - if (AT_STRINGS_BEG (d)) - { - if (!bufp->not_bol) break; - } - else if (d[-1] == '\n' && bufp->newline_anchor) - { - break; - } - /* In all other cases, we fail. */ - goto fail; - - - /* endline is the dual of begline. */ - case endline: - DEBUG_PRINT1 ("EXECUTING endline.\n"); - - if (AT_STRINGS_END (d)) - { - if (!bufp->not_eol) break; - } - - /* We have to ``prefetch'' the next character. */ - else if ((d == end1 ? *string2 : *d) == '\n' - && bufp->newline_anchor) - { - break; - } - goto fail; - - - /* Match at the very beginning of the data. */ - case begbuf: - DEBUG_PRINT1 ("EXECUTING begbuf.\n"); - if (AT_STRINGS_BEG (d)) - break; - goto fail; - - - /* Match at the very end of the data. */ - case endbuf: - DEBUG_PRINT1 ("EXECUTING endbuf.\n"); - if (AT_STRINGS_END (d)) - break; - goto fail; - - - /* on_failure_keep_string_jump is used to optimize `.*\n'. It - pushes NULL as the value for the string on the stack. Then - `pop_failure_point' will keep the current value for the - string, instead of restoring it. To see why, consider - matching `foo\nbar' against `.*\n'. The .* matches the foo; - then the . fails against the \n. But the next thing we want - to do is match the \n against the \n; if we restored the - string value, we would be back at the foo. - - Because this is used only in specific cases, we don't need to - check all the things that `on_failure_jump' does, to make - sure the right things get saved on the stack. Hence we don't - share its code. The only reason to push anything on the - stack at all is that otherwise we would have to change - `anychar's code to do something besides goto fail in this - case; that seems worse than this. */ - case on_failure_keep_string_jump: - DEBUG_PRINT1 ("EXECUTING on_failure_keep_string_jump"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" %d (to 0x%x):\n", mcnt, p + mcnt); - - PUSH_FAILURE_POINT (p + mcnt, NULL, -2); - break; - - - /* Uses of on_failure_jump: - - Each alternative starts with an on_failure_jump that points - to the beginning of the next alternative. Each alternative - except the last ends with a jump that in effect jumps past - the rest of the alternatives. (They really jump to the - ending jump of the following alternative, because tensioning - these jumps is a hassle.) - - Repeats start with an on_failure_jump that points past both - the repetition text and either the following jump or - pop_failure_jump back to this on_failure_jump. */ - case on_failure_jump: - on_failure: - DEBUG_PRINT1 ("EXECUTING on_failure_jump"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" %d (to 0x%x)", mcnt, p + mcnt); - - /* If this on_failure_jump comes right before a group (i.e., - the original * applied to a group), save the information - for that group and all inner ones, so that if we fail back - to this point, the group's information will be correct. - For example, in \(a*\)*\1, we need the preceding group, - and in \(\(a*\)b*\)\2, we need the inner group. */ - - /* We can't use `p' to check ahead because we push - a failure point to `p + mcnt' after we do this. */ - p1 = p; - - /* We need to skip no_op's before we look for the - start_memory in case this on_failure_jump is happening as - the result of a completed succeed_n, as in \(a\)\{1,3\}b\1 - against aba. */ - while (p1 < pend && (re_opcode_t) *p1 == no_op) - p1++; - - if (p1 < pend && (re_opcode_t) *p1 == start_memory) - { - /* We have a new highest active register now. This will - get reset at the start_memory we are about to get to, - but we will have saved all the registers relevant to - this repetition op, as described above. */ - highest_active_reg = *(p1 + 1) + *(p1 + 2); - if (lowest_active_reg == NO_LOWEST_ACTIVE_REG) - lowest_active_reg = *(p1 + 1); - } - - DEBUG_PRINT1 (":\n"); - PUSH_FAILURE_POINT (p + mcnt, d, -2); - break; - - - /* A smart repeat ends with `maybe_pop_jump'. - We change it to either `pop_failure_jump' or `jump'. */ - case maybe_pop_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT2 ("EXECUTING maybe_pop_jump %d.\n", mcnt); - { - register unsigned char *p2 = p; - - /* Compare the beginning of the repeat with what in the - pattern follows its end. If we can establish that there - is nothing that they would both match, i.e., that we - would have to backtrack because of (as in, e.g., `a*a') - then we can change to pop_failure_jump, because we'll - never have to backtrack. - - This is not true in the case of alternatives: in - `(a|ab)*' we do need to backtrack to the `ab' alternative - (e.g., if the string was `ab'). But instead of trying to - detect that here, the alternative has put on a dummy - failure point which is what we will end up popping. */ - - /* Skip over open/close-group commands. */ - while (p2 + 2 < pend - && ((re_opcode_t) *p2 == stop_memory - || (re_opcode_t) *p2 == start_memory)) - p2 += 3; /* Skip over args, too. */ - - /* If we're at the end of the pattern, we can change. */ - if (p2 == pend) - { - /* Consider what happens when matching ":\(.*\)" - against ":/". I don't really understand this code - yet. */ - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 - (" End of pattern: change to `pop_failure_jump'.\n"); - } - - else if ((re_opcode_t) *p2 == exactn - || (bufp->newline_anchor && (re_opcode_t) *p2 == endline)) - { - register unsigned char c - = *p2 == (unsigned char) endline ? '\n' : p2[2]; - p1 = p + mcnt; - - /* p1[0] ... p1[2] are the `on_failure_jump' corresponding - to the `maybe_finalize_jump' of this case. Examine what - follows. */ - if ((re_opcode_t) p1[3] == exactn && p1[5] != c) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT3 (" %c != %c => pop_failure_jump.\n", - c, p1[5]); - } - - else if ((re_opcode_t) p1[3] == charset - || (re_opcode_t) p1[3] == charset_not) - { - int not = (re_opcode_t) p1[3] == charset_not; - - if (c < (unsigned char) (p1[4] * BYTEWIDTH) - && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH))) - not = !not; - - /* `not' is equal to 1 if c would match, which means - that we can't change to pop_failure_jump. */ - if (!not) - { - p[-3] = (unsigned char) pop_failure_jump; - DEBUG_PRINT1 (" No match => pop_failure_jump.\n"); - } - } - } - } - p -= 2; /* Point at relative address again. */ - if ((re_opcode_t) p[-1] != pop_failure_jump) - { - p[-1] = (unsigned char) jump; - DEBUG_PRINT1 (" Match => jump.\n"); - goto unconditional_jump; - } - /* Note fall through. */ - - - /* The end of a simple repeat has a pop_failure_jump back to - its matching on_failure_jump, where the latter will push a - failure point. The pop_failure_jump takes off failure - points put on by this pop_failure_jump's matching - on_failure_jump; we got through the pattern to here from the - matching on_failure_jump, so didn't fail. */ - case pop_failure_jump: - { - /* We need to pass separate storage for the lowest and - highest registers, even though we don't care about the - actual values. Otherwise, we will restore only one - register from the stack, since lowest will == highest in - `pop_failure_point'. */ - unsigned dummy_low_reg, dummy_high_reg; - unsigned char *pdummy; - const char *sdummy; - - DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n"); - POP_FAILURE_POINT (sdummy, pdummy, - dummy_low_reg, dummy_high_reg, - reg_dummy, reg_dummy, reg_info_dummy); - } - /* Note fall through. */ - - - /* Unconditionally jump (without popping any failure points). */ - case jump: - unconditional_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p); /* Get the amount to jump. */ - DEBUG_PRINT2 ("EXECUTING jump %d ", mcnt); - p += mcnt; /* Do the jump. */ - DEBUG_PRINT2 ("(to 0x%x).\n", p); - break; - - - /* We need this opcode so we can detect where alternatives end - in `group_match_null_string_p' et al. */ - case jump_past_alt: - DEBUG_PRINT1 ("EXECUTING jump_past_alt.\n"); - goto unconditional_jump; - - - /* Normally, the on_failure_jump pushes a failure point, which - then gets popped at pop_failure_jump. We will end up at - pop_failure_jump, also, and with a pattern of, say, `a+', we - are skipping over the on_failure_jump, so we have to push - something meaningless for pop_failure_jump to pop. */ - case dummy_failure_jump: - DEBUG_PRINT1 ("EXECUTING dummy_failure_jump.\n"); - /* It doesn't matter what we push for the string here. What - the code at `fail' tests is the value for the pattern. */ - PUSH_FAILURE_POINT (0, 0, -2); - goto unconditional_jump; - - - /* At the end of an alternative, we need to push a dummy failure - point in case we are followed by a `pop_failure_jump', because - we don't want the failure point for the alternative to be - popped. For example, matching `(a|ab)*' against `aab' - requires that we match the `ab' alternative. */ - case push_dummy_failure: - DEBUG_PRINT1 ("EXECUTING push_dummy_failure.\n"); - /* See comments just above at `dummy_failure_jump' about the - two zeroes. */ - PUSH_FAILURE_POINT (0, 0, -2); - break; - - /* Have to succeed matching what follows at least n times. - After that, handle like `on_failure_jump'. */ - case succeed_n: - EXTRACT_NUMBER (mcnt, p + 2); - DEBUG_PRINT2 ("EXECUTING succeed_n %d.\n", mcnt); - - assert (mcnt >= 0); - /* Originally, this is how many times we HAVE to succeed. */ - if (mcnt > 0) - { - mcnt--; - p += 2; - STORE_NUMBER_AND_INCR (p, mcnt); - DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p, mcnt); - } - else if (mcnt == 0) - { - DEBUG_PRINT2 (" Setting two bytes from 0x%x to no_op.\n", p+2); - p[2] = (unsigned char) no_op; - p[3] = (unsigned char) no_op; - goto on_failure; - } - break; - - case jump_n: - EXTRACT_NUMBER (mcnt, p + 2); - DEBUG_PRINT2 ("EXECUTING jump_n %d.\n", mcnt); - - /* Originally, this is how many times we CAN jump. */ - if (mcnt) - { - mcnt--; - STORE_NUMBER (p + 2, mcnt); - goto unconditional_jump; - } - /* If don't have to jump any more, skip over the rest of command. */ - else - p += 4; - break; - - case set_number_at: - { - DEBUG_PRINT1 ("EXECUTING set_number_at.\n"); - - EXTRACT_NUMBER_AND_INCR (mcnt, p); - p1 = p + mcnt; - EXTRACT_NUMBER_AND_INCR (mcnt, p); - DEBUG_PRINT3 (" Setting 0x%x to %d.\n", p1, mcnt); - STORE_NUMBER (p1, mcnt); - break; - } - - case wordbound: - DEBUG_PRINT1 ("EXECUTING wordbound.\n"); - if (AT_WORD_BOUNDARY (d)) - break; - goto fail; - - case notwordbound: - DEBUG_PRINT1 ("EXECUTING notwordbound.\n"); - if (AT_WORD_BOUNDARY (d)) - goto fail; - break; - - case wordbeg: - DEBUG_PRINT1 ("EXECUTING wordbeg.\n"); - if (WORDCHAR_P (d) && (AT_STRINGS_BEG (d) || !WORDCHAR_P (d - 1))) - break; - goto fail; - - case wordend: - DEBUG_PRINT1 ("EXECUTING wordend.\n"); - if (!AT_STRINGS_BEG (d) && WORDCHAR_P (d - 1) - && (!WORDCHAR_P (d) || AT_STRINGS_END (d))) - break; - goto fail; - -#ifdef emacs -#ifdef emacs19 - case before_dot: - DEBUG_PRINT1 ("EXECUTING before_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) >= point) - goto fail; - break; - - case at_dot: - DEBUG_PRINT1 ("EXECUTING at_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) != point) - goto fail; - break; - - case after_dot: - DEBUG_PRINT1 ("EXECUTING after_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) <= point) - goto fail; - break; -#else /* not emacs19 */ - case at_dot: - DEBUG_PRINT1 ("EXECUTING at_dot.\n"); - if (PTR_CHAR_POS ((unsigned char *) d) + 1 != point) - goto fail; - break; -#endif /* not emacs19 */ - - case syntaxspec: - DEBUG_PRINT2 ("EXECUTING syntaxspec %d.\n", mcnt); - mcnt = *p++; - goto matchsyntax; - - case wordchar: - DEBUG_PRINT1 ("EXECUTING Emacs wordchar.\n"); - mcnt = (int) Sword; - matchsyntax: - PREFETCH (); - if (SYNTAX (*d++) != (enum syntaxcode) mcnt) - goto fail; - SET_REGS_MATCHED (); - break; - - case notsyntaxspec: - DEBUG_PRINT2 ("EXECUTING notsyntaxspec %d.\n", mcnt); - mcnt = *p++; - goto matchnotsyntax; - - case notwordchar: - DEBUG_PRINT1 ("EXECUTING Emacs notwordchar.\n"); - mcnt = (int) Sword; - matchnotsyntax: - PREFETCH (); - if (SYNTAX (*d++) == (enum syntaxcode) mcnt) - goto fail; - SET_REGS_MATCHED (); - break; - -#else /* not emacs */ - case wordchar: - DEBUG_PRINT1 ("EXECUTING non-Emacs wordchar.\n"); - PREFETCH (); - if (!WORDCHAR_P (d)) - goto fail; - SET_REGS_MATCHED (); - d++; - break; - - case notwordchar: - DEBUG_PRINT1 ("EXECUTING non-Emacs notwordchar.\n"); - PREFETCH (); - if (WORDCHAR_P (d)) - goto fail; - SET_REGS_MATCHED (); - d++; - break; -#endif /* not emacs */ - - default: - abort (); - } - continue; /* Successfully executed one pattern command; keep going. */ - - - /* We goto here if a matching operation fails. */ - fail: - if (!FAIL_STACK_EMPTY ()) - { /* A restart point is known. Restore to that state. */ - DEBUG_PRINT1 ("\nFAIL:\n"); - POP_FAILURE_POINT (d, p, - lowest_active_reg, highest_active_reg, - regstart, regend, reg_info); - - /* If this failure point is a dummy, try the next one. */ - if (!p) - goto fail; - - /* If we failed to the end of the pattern, don't examine *p. */ - assert (p <= pend); - if (p < pend) - { - boolean is_a_jump_n = false; - - /* If failed to a backwards jump that's part of a repetition - loop, need to pop this failure point and use the next one. */ - switch ((re_opcode_t) *p) - { - case jump_n: - is_a_jump_n = true; - case maybe_pop_jump: - case pop_failure_jump: - case jump: - p1 = p + 1; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - - if ((is_a_jump_n && (re_opcode_t) *p1 == succeed_n) - || (!is_a_jump_n - && (re_opcode_t) *p1 == on_failure_jump)) - goto fail; - break; - default: - /* do nothing */ ; - } - } - - if (d >= string1 && d <= end1) - dend = end_match_1; - } - else - break; /* Matching at this starting point really fails. */ - } /* for (;;) */ - - if (best_regs_set) - goto restore_best_regs; - - FREE_VARIABLES (); - - return -1; /* Failure to match. */ -} /* re_match_2 */ - -/* Subroutine definitions for re_match_2. */ - - -/* We are passed P pointing to a register number after a start_memory. - - Return true if the pattern up to the corresponding stop_memory can - match the empty string, and false otherwise. - - If we find the matching stop_memory, sets P to point to one past its number. - Otherwise, sets P to an undefined byte less than or equal to END. - - We don't handle duplicates properly (yet). */ - -static boolean -group_match_null_string_p (p, end, reg_info) - unsigned char **p, *end; - register_info_type *reg_info; -{ - int mcnt; - /* Point to after the args to the start_memory. */ - unsigned char *p1 = *p + 2; - - while (p1 < end) - { - /* Skip over opcodes that can match nothing, and return true or - false, as appropriate, when we get to one that can't, or to the - matching stop_memory. */ - - switch ((re_opcode_t) *p1) - { - /* Could be either a loop or a series of alternatives. */ - case on_failure_jump: - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - - /* If the next operation is not a jump backwards in the - pattern. */ - - if (mcnt >= 0) - { - /* Go through the on_failure_jumps of the alternatives, - seeing if any of the alternatives cannot match nothing. - The last alternative starts with only a jump, - whereas the rest start with on_failure_jump and end - with a jump, e.g., here is the pattern for `a|b|c': - - /on_failure_jump/0/6/exactn/1/a/jump_past_alt/0/6 - /on_failure_jump/0/6/exactn/1/b/jump_past_alt/0/3 - /exactn/1/c - - So, we have to first go through the first (n-1) - alternatives and then deal with the last one separately. */ - - - /* Deal with the first (n-1) alternatives, which start - with an on_failure_jump (see above) that jumps to right - past a jump_past_alt. */ - - while ((re_opcode_t) p1[mcnt-3] == jump_past_alt) - { - /* `mcnt' holds how many bytes long the alternative - is, including the ending `jump_past_alt' and - its number. */ - - if (!alt_match_null_string_p (p1, p1 + mcnt - 3, - reg_info)) - return false; - - /* Move to right after this alternative, including the - jump_past_alt. */ - p1 += mcnt; - - /* Break if it's the beginning of an n-th alternative - that doesn't begin with an on_failure_jump. */ - if ((re_opcode_t) *p1 != on_failure_jump) - break; - - /* Still have to check that it's not an n-th - alternative that starts with an on_failure_jump. */ - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if ((re_opcode_t) p1[mcnt-3] != jump_past_alt) - { - /* Get to the beginning of the n-th alternative. */ - p1 -= 3; - break; - } - } - - /* Deal with the last alternative: go back and get number - of the `jump_past_alt' just before it. `mcnt' contains - the length of the alternative. */ - EXTRACT_NUMBER (mcnt, p1 - 2); - - if (!alt_match_null_string_p (p1, p1 + mcnt, reg_info)) - return false; - - p1 += mcnt; /* Get past the n-th alternative. */ - } /* if mcnt > 0 */ - break; - - - case stop_memory: - assert (p1[1] == **p); - *p = p1 + 2; - return true; - - - default: - if (!common_op_match_null_string_p (&p1, end, reg_info)) - return false; - } - } /* while p1 < end */ - - return false; -} /* group_match_null_string_p */ - - -/* Similar to group_match_null_string_p, but doesn't deal with alternatives: - It expects P to be the first byte of a single alternative and END one - byte past the last. The alternative can contain groups. */ - -static boolean -alt_match_null_string_p (p, end, reg_info) - unsigned char *p, *end; - register_info_type *reg_info; -{ - int mcnt; - unsigned char *p1 = p; - - while (p1 < end) - { - /* Skip over opcodes that can match nothing, and break when we get - to one that can't. */ - - switch ((re_opcode_t) *p1) - { - /* It's a loop. */ - case on_failure_jump: - p1++; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - break; - - default: - if (!common_op_match_null_string_p (&p1, end, reg_info)) - return false; - } - } /* while p1 < end */ - - return true; -} /* alt_match_null_string_p */ - - -/* Deals with the ops common to group_match_null_string_p and - alt_match_null_string_p. - - Sets P to one after the op and its arguments, if any. */ - -static boolean -common_op_match_null_string_p (p, end, reg_info) - unsigned char **p, *end; - register_info_type *reg_info; -{ - int mcnt; - boolean ret; - int reg_no; - unsigned char *p1 = *p; - - switch ((re_opcode_t) *p1++) - { - case no_op: - case begline: - case endline: - case begbuf: - case endbuf: - case wordbeg: - case wordend: - case wordbound: - case notwordbound: -#ifdef emacs - case before_dot: - case at_dot: - case after_dot: -#endif - break; - - case start_memory: - reg_no = *p1; - assert (reg_no > 0 && reg_no <= MAX_REGNUM); - ret = group_match_null_string_p (&p1, end, reg_info); - - /* Have to set this here in case we're checking a group which - contains a group and a back reference to it. */ - - if (REG_MATCH_NULL_STRING_P (reg_info[reg_no]) == MATCH_NULL_UNSET_VALUE) - REG_MATCH_NULL_STRING_P (reg_info[reg_no]) = ret; - - if (!ret) - return false; - break; - - /* If this is an optimized succeed_n for zero times, make the jump. */ - case jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - if (mcnt >= 0) - p1 += mcnt; - else - return false; - break; - - case succeed_n: - /* Get to the number of times to succeed. */ - p1 += 2; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - - if (mcnt == 0) - { - p1 -= 4; - EXTRACT_NUMBER_AND_INCR (mcnt, p1); - p1 += mcnt; - } - else - return false; - break; - - case duplicate: - if (!REG_MATCH_NULL_STRING_P (reg_info[*p1])) - return false; - break; - - case set_number_at: - p1 += 4; - - default: - /* All other opcodes mean we cannot match the empty string. */ - return false; - } - - *p = p1; - return true; -} /* common_op_match_null_string_p */ - - -/* Return zero if TRANSLATE[S1] and TRANSLATE[S2] are identical for LEN - bytes; nonzero otherwise. */ - -static int -bcmp_translate (s1, s2, len, translate) - unsigned char *s1, *s2; - register int len; - char *translate; -{ - register unsigned char *p1 = s1, *p2 = s2; - while (len) - { - if (translate[*p1++] != translate[*p2++]) return 1; - len--; - } - return 0; -} - -/* Entry points for GNU code. */ - -/* re_compile_pattern is the GNU regular expression compiler: it - compiles PATTERN (of length SIZE) and puts the result in BUFP. - Returns 0 if the pattern was valid, otherwise an error string. - - Assumes the `allocated' (and perhaps `buffer') and `translate' fields - are set in BUFP on entry. - - We call regex_compile to do the actual compilation. */ - -const char * -re_compile_pattern (pattern, length, bufp) - const char *pattern; - int length; - struct re_pattern_buffer *bufp; -{ - reg_errcode_t ret; - - /* GNU code is written to assume at least RE_NREGS registers will be set - (and at least one extra will be -1). */ - bufp->regs_allocated = REGS_UNALLOCATED; - - /* And GNU code determines whether or not to get register information - by passing null for the REGS argument to re_match, etc., not by - setting no_sub. */ - bufp->no_sub = 0; - - /* Match anchors at newline. */ - bufp->newline_anchor = 1; - - ret = regex_compile (pattern, length, re_syntax_options, bufp); - - return re_error_msg[(int) ret]; -} - -/* Entry points compatible with 4.2 BSD regex library. We don't define - them if this is an Emacs or POSIX compilation. */ - -#if !defined (emacs) && !defined (_POSIX_SOURCE) - -/* BSD has one and only one pattern buffer. */ -static struct re_pattern_buffer re_comp_buf; - -char * -re_comp (s) - const char *s; -{ - reg_errcode_t ret; - - if (!s) - { - if (!re_comp_buf.buffer) - return "No previous regular expression"; - return 0; - } - - if (!re_comp_buf.buffer) - { - re_comp_buf.buffer = (unsigned char *) malloc (200); - if (re_comp_buf.buffer == NULL) - return "Memory exhausted"; - re_comp_buf.allocated = 200; - - re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); - if (re_comp_buf.fastmap == NULL) - return "Memory exhausted"; - } - - /* Since `re_exec' always passes NULL for the `regs' argument, we - don't need to initialize the pattern buffer fields which affect it. */ - - /* Match anchors at newlines. */ - re_comp_buf.newline_anchor = 1; - - ret = regex_compile (s, strlen (s), re_syntax_options, &re_comp_buf); - - /* Yes, we're discarding `const' here. */ - return (char *) re_error_msg[(int) ret]; -} - - -int -re_exec (s) - const char *s; -{ - const int len = strlen (s); - return - 0 <= re_search (&re_comp_buf, s, len, 0, len, (struct re_registers *) 0); -} -#endif /* not emacs and not _POSIX_SOURCE */ - -/* POSIX.2 functions. Don't define these for Emacs. */ - -#ifndef emacs - -/* regcomp takes a regular expression as a string and compiles it. - - PREG is a regex_t *. We do not expect any fields to be initialized, - since POSIX says we shouldn't. Thus, we set - - `buffer' to the compiled pattern; - `used' to the length of the compiled pattern; - `syntax' to RE_SYNTAX_POSIX_EXTENDED if the - REG_EXTENDED bit in CFLAGS is set; otherwise, to - RE_SYNTAX_POSIX_BASIC; - `newline_anchor' to REG_NEWLINE being set in CFLAGS; - `fastmap' and `fastmap_accurate' to zero; - `re_nsub' to the number of subexpressions in PATTERN. - - PATTERN is the address of the pattern string. - - CFLAGS is a series of bits which affect compilation. - - If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we - use POSIX basic syntax. - - If REG_NEWLINE is set, then . and [^...] don't match newline. - Also, regexec will try a match beginning after every newline. - - If REG_ICASE is set, then we considers upper- and lowercase - versions of letters to be equivalent when matching. - - If REG_NOSUB is set, then when PREG is passed to regexec, that - routine will report only success or failure, and nothing about the - registers. - - It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for - the return codes and their meanings.) */ - -int -regcomp (preg, pattern, cflags) - regex_t *preg; - const char *pattern; - int cflags; -{ - reg_errcode_t ret; - unsigned syntax - = (cflags & REG_EXTENDED) ? - RE_SYNTAX_POSIX_EXTENDED : RE_SYNTAX_POSIX_BASIC; - - /* regex_compile will allocate the space for the compiled pattern. */ - preg->buffer = 0; - preg->allocated = 0; - - /* Don't bother to use a fastmap when searching. This simplifies the - REG_NEWLINE case: if we used a fastmap, we'd have to put all the - characters after newlines into the fastmap. This way, we just try - every character. */ - preg->fastmap = 0; - - if (cflags & REG_ICASE) - { - unsigned i; - - preg->translate = (char *) malloc (CHAR_SET_SIZE); - if (preg->translate == NULL) - return (int) REG_ESPACE; - - /* Map uppercase characters to corresponding lowercase ones. */ - for (i = 0; i < CHAR_SET_SIZE; i++) - preg->translate[i] = ISUPPER (i) ? tolower (i) : i; - } - else - preg->translate = NULL; - - /* If REG_NEWLINE is set, newlines are treated differently. */ - if (cflags & REG_NEWLINE) - { /* REG_NEWLINE implies neither . nor [^...] match newline. */ - syntax &= ~RE_DOT_NEWLINE; - syntax |= RE_HAT_LISTS_NOT_NEWLINE; - /* It also changes the matching behavior. */ - preg->newline_anchor = 1; - } - else - preg->newline_anchor = 0; - - preg->no_sub = !!(cflags & REG_NOSUB); - - /* POSIX says a null character in the pattern terminates it, so we - can use strlen here in compiling the pattern. */ - ret = regex_compile (pattern, strlen (pattern), syntax, preg); - - /* POSIX doesn't distinguish between an unmatched open-group and an - unmatched close-group: both are REG_EPAREN. */ - if (ret == REG_ERPAREN) ret = REG_EPAREN; - - return (int) ret; -} - - -/* regexec searches for a given pattern, specified by PREG, in the - string STRING. - - If NMATCH is zero or REG_NOSUB was set in the cflags argument to - `regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at - least NMATCH elements, and we set them to the offsets of the - corresponding matched substrings. - - EFLAGS specifies `execution flags' which affect matching: if - REG_NOTBOL is set, then ^ does not match at the beginning of the - string; if REG_NOTEOL is set, then $ does not match at the end. - - We return 0 if we find a match and REG_NOMATCH if not. */ - -int -regexec (preg, string, nmatch, pmatch, eflags) - const regex_t *preg; - const char *string; - size_t nmatch; - regmatch_t pmatch[]; - int eflags; -{ - int ret; - struct re_registers regs; - regex_t private_preg; - int len = strlen (string); - boolean want_reg_info = !preg->no_sub && nmatch > 0; - - private_preg = *preg; - - private_preg.not_bol = !!(eflags & REG_NOTBOL); - private_preg.not_eol = !!(eflags & REG_NOTEOL); - - /* The user has told us exactly how many registers to return - information about, via `nmatch'. We have to pass that on to the - matching routines. */ - private_preg.regs_allocated = REGS_FIXED; - - if (want_reg_info) - { - regs.num_regs = nmatch; - regs.start = TALLOC (nmatch, regoff_t); - regs.end = TALLOC (nmatch, regoff_t); - if (regs.start == NULL || regs.end == NULL) - return (int) REG_NOMATCH; - } - - /* Perform the searching operation. */ - ret = re_search (&private_preg, string, len, - /* start: */ 0, /* range: */ len, - want_reg_info ? ®s : (struct re_registers *) 0); - - /* Copy the register information to the POSIX structure. */ - if (want_reg_info) - { - if (ret >= 0) - { - unsigned r; - - for (r = 0; r < nmatch; r++) - { - pmatch[r].rm_so = regs.start[r]; - pmatch[r].rm_eo = regs.end[r]; - } - } - - /* If we needed the temporary register info, free the space now. */ - free (regs.start); - free (regs.end); - } - - /* We want zero return to mean success, unlike `re_search'. */ - return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH; -} - - -/* Returns a message corresponding to an error code, ERRCODE, returned - from either regcomp or regexec. We don't use PREG here. */ - -size_t -regerror (errcode, preg, errbuf, errbuf_size) - int errcode; - const regex_t *preg; - char *errbuf; - size_t errbuf_size; -{ - const char *msg; - size_t msg_size; - - if (errcode < 0 - || errcode >= (sizeof (re_error_msg) / sizeof (re_error_msg[0]))) - /* Only error codes returned by the rest of the code should be passed - to this routine. If we are given anything else, or if other regex - code generates an invalid error code, then the program has a bug. - Dump core so we can fix it. */ - abort (); - - msg_size = strlen (msg) + 1; /* Includes the null. */ - - if (errbuf_size != 0) - { - if (msg_size > errbuf_size) - { - strncpy (errbuf, msg, errbuf_size - 1); - errbuf[errbuf_size - 1] = 0; - } - else - strcpy (errbuf, msg); - } - - return msg_size; -} - - -/* Free dynamically allocated space used by PREG. */ - -void -regfree (preg) - regex_t *preg; -{ - if (preg->buffer != NULL) - free (preg->buffer); - preg->buffer = NULL; - - preg->allocated = 0; - preg->used = 0; - - if (preg->fastmap != NULL) - free (preg->fastmap); - preg->fastmap = NULL; - preg->fastmap_accurate = 0; - - if (preg->translate != NULL) - free (preg->translate); - preg->translate = NULL; -} - -#endif /* not emacs */ - -/* -Local variables: -make-backup-files: t -version-control: t -trim-versions-without-asking: nil -End: -*/ diff --git a/gnu/usr.bin/yppush/yp.h b/gnu/usr.bin/yppush/yp.h deleted file mode 100644 index da300d4..0000000 --- a/gnu/usr.bin/yppush/yp.h +++ /dev/null @@ -1,292 +0,0 @@ -/* - * $Id$ - */ - -#define YPMAXRECORD 1024 -#define YPMAXDOMAIN 64 -#define YPMAXMAP 64 -#define YPMAXPEER 64 - -enum ypstat { - YP_TRUE = 1, - YP_NOMORE = 2, - YP_FALSE = 0, - YP_NOMAP = -1, - YP_NODOM = -2, - YP_NOKEY = -3, - YP_BADOP = -4, - YP_BADDB = -5, - YP_YPERR = -6, - YP_BADARGS = -7, - YP_VERS = -8, -}; -typedef enum ypstat ypstat; -bool_t __xdr_ypstat(); - - -enum ypxfrstat { - YPXFR_SUCC = 1, - YPXFR_AGE = 2, - YPXFR_NOMAP = -1, - YPXFR_NODOM = -2, - YPXFR_RSRC = -3, - YPXFR_RPC = -4, - YPXFR_MADDR = -5, - YPXFR_YPERR = -6, - YPXFR_BADARGS = -7, - YPXFR_DBM = -8, - YPXFR_FILE = -9, - YPXFR_SKEW = -10, - YPXFR_CLEAR = -11, - YPXFR_FORCE = -12, - YPXFR_XFRERR = -13, - YPXFR_REFUSED = -14, -}; -typedef enum ypxfrstat ypxfrstat; -bool_t __xdr_ypxfrstat(); - - -typedef char *domainname; -bool_t xdr_domainname(); - - -typedef char *mapname; -bool_t xdr_mapname(); - - -typedef char *peername; -bool_t xdr_peername(); - - -typedef struct { - u_int keydat_len; - char *keydat_val; -} keydat; -bool_t xdr_keydat(); - - -typedef struct { - u_int valdat_len; - char *valdat_val; -} valdat; -bool_t xdr_valdat(); - - -struct ypmap_parms { - domainname domain; - mapname map; - u_int ordernum; - peername peer; -}; -typedef struct ypmap_parms ypmap_parms; -bool_t __xdr_ypmap_parms(); - - -struct ypreq_key { - domainname domain; - mapname map; - keydat key; -}; -typedef struct ypreq_key ypreq_key; -bool_t __xdr_ypreq_key(); - - -struct ypreq_nokey { - domainname domain; - mapname map; -}; -typedef struct ypreq_nokey ypreq_nokey; -bool_t __xdr_ypreq_nokey(); - - -struct ypreq_xfr { - ypmap_parms map_parms; - u_int transid; - u_int prog; - u_int port; -}; -typedef struct ypreq_xfr ypreq_xfr; -bool_t __xdr_ypreq_xfr(); - - -struct ypresp_val { - ypstat stat; - valdat val; -}; -typedef struct ypresp_val ypresp_val; -bool_t __xdr_ypresp_val(); - - -struct ypresp_key_val { - ypstat stat; - keydat key; - valdat val; -}; -typedef struct ypresp_key_val ypresp_key_val; -bool_t __xdr_ypresp_key_val(); - - -struct ypresp_master { - ypstat stat; - peername peer; -}; -typedef struct ypresp_master ypresp_master; -bool_t __xdr_ypresp_master(); - - -struct ypresp_order { - ypstat stat; - u_int ordernum; -}; -typedef struct ypresp_order ypresp_order; -bool_t __xdr_ypresp_order(); - - -struct ypresp_all { - bool_t more; - union { - ypresp_key_val val; - } ypresp_all_u; -}; -typedef struct ypresp_all ypresp_all; -bool_t __xdr_ypresp_all(); - - -struct ypresp_xfr { - u_int transid; - ypxfrstat xfrstat; -}; -typedef struct ypresp_xfr ypresp_xfr; -bool_t __xdr_ypresp_xfr(); - - -struct ypmaplist { - mapname map; - struct ypmaplist *next; -}; -typedef struct ypmaplist ypmaplist; -bool_t __xdr_ypmaplist(); - - -struct ypresp_maplist { - ypstat stat; - ypmaplist *maps; -}; -typedef struct ypresp_maplist ypresp_maplist; -bool_t __xdr_ypresp_maplist(); - - -enum yppush_status { - YPPUSH_SUCC = 1, - YPPUSH_AGE = 2, - YPPUSH_NOMAP = -1, - YPPUSH_NODOM = -2, - YPPUSH_RSRC = -3, - YPPUSH_RPC = -4, - YPPUSH_MADDR = -5, - YPPUSH_YPERR = -6, - YPPUSH_BADARGS = -7, - YPPUSH_DBM = -8, - YPPUSH_FILE = -9, - YPPUSH_SKEW = -10, - YPPUSH_CLEAR = -11, - YPPUSH_FORCE = -12, - YPPUSH_XFRERR = -13, - YPPUSH_REFUSED = -14, -}; -typedef enum yppush_status yppush_status; -bool_t __xdr_yppush_status(); - - -struct yppushresp_xfr { - u_int transid; - yppush_status status; -}; -typedef struct yppushresp_xfr yppushresp_xfr; -bool_t __xdr_yppushresp_xfr(); - - -enum ypbind_resptype { - YPBIND_SUCC_VAL = 1, - YPBIND_FAIL_VAL = 2, -}; -typedef enum ypbind_resptype ypbind_resptype; -bool_t __xdr_ypbind_resptype(); - - -struct ypbind_binding { - char ypbind_binding_addr[4]; - char ypbind_binding_port[2]; -}; -typedef struct ypbind_binding ypbind_binding; -bool_t __xdr_ypbind_binding(); - - -struct ypbind_resp { - ypbind_resptype ypbind_status; - union { - u_int ypbind_error; - ypbind_binding ypbind_bindinfo; - } ypbind_resp_u; -}; -typedef struct ypbind_resp ypbind_resp; -bool_t __xdr_ypbind_resp(); - -#define YPBIND_ERR_ERR 1 -#define YPBIND_ERR_NOSERV 2 -#define YPBIND_ERR_RESC 3 - -struct ypbind_setdom { - domainname ypsetdom_domain; - ypbind_binding ypsetdom_binding; - u_int ypsetdom_vers; -}; -typedef struct ypbind_setdom ypbind_setdom; -bool_t __xdr_ypbind_setdom(); - - -#define YPPROG ((u_long)100004) -#define YPVERS ((u_long)2) -#define YPPROC_NULL ((u_long)0) -extern void *ypproc_null_2(); -#define YPPROC_DOMAIN ((u_long)1) -extern bool_t *ypproc_domain_2(); -#define YPPROC_DOMAIN_NONACK ((u_long)2) -extern bool_t *ypproc_domain_nonack_2(); -#define YPPROC_MATCH ((u_long)3) -extern ypresp_val *ypproc_match_2(); -#define YPPROC_FIRST ((u_long)4) -extern ypresp_key_val *ypproc_first_2(); -#define YPPROC_NEXT ((u_long)5) -extern ypresp_key_val *ypproc_next_2(); -#define YPPROC_XFR ((u_long)6) -extern ypresp_xfr *ypproc_xfr_2(); -#define YPPROC_CLEAR ((u_long)7) -extern void *ypproc_clear_2(); -#define YPPROC_ALL ((u_long)8) -extern ypresp_all *ypproc_all_2(); -#define YPPROC_MASTER ((u_long)9) -extern ypresp_master *ypproc_master_2(); -#define YPPROC_ORDER ((u_long)10) -extern ypresp_order *ypproc_order_2(); -#define YPPROC_MAPLIST ((u_long)11) -extern ypresp_maplist *ypproc_maplist_2(); - - -#define YPPUSH_XFRRESPPROG ((u_long)0x40000000) -#define YPPUSH_XFRRESPVERS ((u_long)1) -#define YPPUSHPROC_NULL ((u_long)0) -extern void *yppushproc_null_1(); -#define YPPUSHPROC_XFRRESP ((u_long)1) -extern yppushresp_xfr *yppushproc_xfrresp_1(); - - -#define YPBINDPROG ((u_long)100007) -#define YPBINDVERS ((u_long)2) -#define YPBINDPROC_NULL ((u_long)0) -extern void *ypbindproc_null_2(); -#define YPBINDPROC_DOMAIN ((u_long)1) -extern ypbind_resp *ypbindproc_domain_2(); -#define YPBINDPROC_SETDOM ((u_long)2) -extern void *ypbindproc_setdom_2(); - diff --git a/gnu/usr.bin/yppush/yp_clnt.c b/gnu/usr.bin/yppush/yp_clnt.c deleted file mode 100644 index 32d9007..0000000 --- a/gnu/usr.bin/yppush/yp_clnt.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - YPS-0.2, NIS-Server for Linux - Copyright (C) 1994 Tobias Reber - - 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 of the License, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - Modified for use with FreeBSD 2.x by Bill Paul (wpaul@ctr.columbia.edu) - - $Id$ -*/ - -/* - * $Author: root $ - * $Log: yp_clnt.c,v $ - * Revision 0.16 1994/01/02 22:48:22 root - * Added strict prototypes - * - * Revision 0.15 1994/01/02 20:09:39 root - * Added GPL notice - * - * Revision 0.14 1993/12/19 12:42:32 root - * *** empty log message *** - * - * Revision 0.13 1993/06/12 09:39:30 root - * Align with include-4.4 - * - */ - -#include -#include -#include -#include -#include -#include -#include "yp.h" - -#ifdef DEBUG -#define PRINTF(x) printf x -#else -#define PRINTF(x) -#endif - -static struct timeval TIMEOUT = { 25, 0 }; - -void * -ypproc_null_2( int *argp, CLIENT *clnt) -{ - static char res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_NULL, xdr_void, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return ((void *)&res); -} - - -bool_t * -ypproc_domain_2( domainname *argp, CLIENT *clnt) -{ - static bool_t res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_DOMAIN, xdr_domainname, argp, xdr_bool, &res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return (&res); -} - - -bool_t * -ypproc_domain_nonack_2( domainname *argp, CLIENT *clnt) -{ - static bool_t res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_DOMAIN_NONACK, xdr_domainname, argp, xdr_bool, &res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return (&res); -} - - -ypresp_val * -ypproc_match_2( ypreq_key *argp, CLIENT *clnt) -{ - static ypresp_val res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_MATCH, __xdr_ypreq_key, argp, __xdr_ypresp_val, &res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return (&res); -} - - -ypresp_key_val * -ypproc_first_2( ypreq_key *argp, CLIENT *clnt) -{ - static ypresp_key_val res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_FIRST, __xdr_ypreq_key, argp, __xdr_ypresp_key_val, &res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return (&res); -} - - -ypresp_key_val * -ypproc_next_2( ypreq_key *argp, CLIENT *clnt) -{ - static ypresp_key_val res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_NEXT, __xdr_ypreq_key, argp, __xdr_ypresp_key_val, &res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return (&res); -} - - -ypresp_xfr * -ypproc_xfr_2( ypreq_xfr *argp, CLIENT *clnt) -{ - static ypresp_xfr res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_XFR, __xdr_ypreq_xfr, argp, __xdr_ypresp_xfr, &res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return (&res); -} - - -void * -ypproc_clear_2( int *argp, CLIENT *clnt) -{ - static char res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_CLEAR, xdr_void, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return ((void *)&res); -} - - -ypresp_all * -ypproc_all_2( ypreq_nokey *argp, CLIENT *clnt) -{ - static ypresp_all res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_ALL, __xdr_ypreq_nokey, argp, __xdr_ypresp_all, &res, TIMEOUT) != RPC_SUCCESS) { - PRINTF(("ypproc_all_2 retuning NULL\n")); - return (NULL); - } - PRINTF(("ypproc_all_2 retuning non-NULL\n")); - return (&res); -} - - -ypresp_master * -ypproc_master_2( ypreq_nokey *argp, CLIENT *clnt) -{ - static ypresp_master res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_MASTER, __xdr_ypreq_nokey, argp, __xdr_ypresp_master, &res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return (&res); -} - - -ypresp_order * -ypproc_order_2( ypreq_nokey *argp, CLIENT *clnt) -{ - static ypresp_order res; - PRINTF (("ypproc_order_2()\n")); - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_ORDER, __xdr_ypreq_nokey, argp, __xdr_ypresp_order, &res, TIMEOUT) != RPC_SUCCESS) { - PRINTF (("ypproc_order_2()\n")); - return (NULL); - } - PRINTF (("ypproc_order_2()\n")); - return (&res); -} - - -ypresp_maplist * -ypproc_maplist_2( domainname *argp, CLIENT *clnt) -{ - static ypresp_maplist res; - - bzero(&res, sizeof(res)); - if (clnt_call(clnt, YPPROC_MAPLIST, xdr_domainname, argp, __xdr_ypresp_maplist, &res, TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return (&res); -} - diff --git a/gnu/usr.bin/yppush/yp_xdr.c b/gnu/usr.bin/yppush/yp_xdr.c deleted file mode 100644 index 5afc8d9c..0000000 --- a/gnu/usr.bin/yppush/yp_xdr.c +++ /dev/null @@ -1,477 +0,0 @@ -/* - YPS-0.2, NIS-Server for Linux - Copyright (C) 1994 Tobias Reber - - 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 of the License, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - Modified for use with FreeBSD 2.x by Bill Paul (wpaul@ctr.columbia.edu) - - $Id$ -*/ - -/* - * $Author: root $ - * $Log: yp_xdr.c,v $ - * Revision 0.20 1994/01/02 22:48:22 root - * Added strict prototypes - * - * Revision 0.19 1994/01/02 20:09:39 root - * Added GPL notice - * - * Revision 0.18 1994/01/02 18:06:13 root - * Fixed another bug in __xdr_ypresp_all - * - * Revision 0.17 1993/12/30 22:34:57 root - * *** empty log message *** - * - * Revision 0.16 1993/12/29 00:37:37 root - * Fixed a bug in __xdr_ypresp_key_val - * - * Revision 0.15 1993/06/16 22:54:12 dok235 - * Fix a bug in ypresp_key_val - * - * Revision 0.14 1993/06/12 09:39:30 root - * Align with include-4.4 - * - * Revision 0.13 1993/06/11 21:45:00 root - * Regenned from yp.x, that came with include-4.4 - * - */ - -/* - * Please do not edit this file. - * It was generated using rpcgen. - */ - -#include -#include - -#ifdef DEBUG -#define PRINTF(x) printf x -#define PRLINENO printf(__FILE__ "(%d): ", __LINE__) -#else -#define PRINTF(x) -#define PRLINENO -#endif - -struct { - union { - int (*encoder)(char *, int, char **, int *, char **, int *); - int (*decoder)(int, char *, int, char *, int, char *); - } foreach; - char *data; -} *__xdr_ypall_callback; - -bool_t -__xdr_ypstat(XDR *xdrs, ypstat *objp) -{ - - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypxfrstat(XDR *xdrs, ypxfrstat *objp) -{ - - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_domainname(XDR *xdrs, domainname *objp) -{ - - if (!xdr_string(xdrs, objp, YPMAXDOMAIN)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_mapname(XDR *xdrs, mapname *objp) -{ - - if (!xdr_string(xdrs, objp, YPMAXMAP)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_peername(XDR *xdrs, peername *objp) -{ - - if (!xdr_string(xdrs, objp, YPMAXPEER)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_keydat(XDR *xdrs, keydat *objp) -{ - - if (!xdr_bytes(xdrs, (char **)&objp->keydat_val, (u_int *)&objp->keydat_len, YPMAXRECORD)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_valdat(XDR *xdrs, valdat *objp) -{ - - if (!xdr_bytes(xdrs, (char **)&objp->valdat_val, (u_int *)&objp->valdat_len, YPMAXRECORD)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypmap_parms(XDR *xdrs, ypmap_parms *objp) -{ - - if (!__xdr_domainname(xdrs, &objp->domain)) { - return (FALSE); - } - if (!__xdr_mapname(xdrs, &objp->map)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->ordernum)) { - return (FALSE); - } - if (!__xdr_peername(xdrs, &objp->peer)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypreq_key(XDR *xdrs, ypreq_key *objp) -{ - - if (!__xdr_domainname(xdrs, &objp->domain)) { - return (FALSE); - } - if (!__xdr_mapname(xdrs, &objp->map)) { - return (FALSE); - } - if (!xdr_keydat(xdrs, &objp->key)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypreq_nokey(XDR *xdrs, ypreq_nokey *objp) -{ - - if (!__xdr_domainname(xdrs, &objp->domain)) { - return (FALSE); - } - if (!__xdr_mapname(xdrs, &objp->map)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypreq_xfr(XDR *xdrs, ypreq_xfr *objp) -{ - - if (!__xdr_ypmap_parms(xdrs, &objp->map_parms)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->transid)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->prog)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->port)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypresp_val(XDR *xdrs, ypresp_val *objp) -{ - - if (!__xdr_ypstat(xdrs, &objp->stat)) { - return (FALSE); - } - if (!xdr_valdat(xdrs, &objp->val)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypresp_key_val(XDR *xdrs, ypresp_key_val *objp) -{ - - if (!__xdr_ypstat(xdrs, &objp->stat)) { - return (FALSE); - } - if (!xdr_valdat(xdrs, &objp->val)) { - return (FALSE); - } - if (!xdr_keydat(xdrs, &objp->key)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypresp_master(XDR *xdrs, ypresp_master *objp) -{ - - if (!__xdr_ypstat(xdrs, &objp->stat)) { - return (FALSE); - } - if (!__xdr_peername(xdrs, &objp->peer)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypresp_order(XDR *xdrs, ypresp_order *objp) -{ - - if (!__xdr_ypstat(xdrs, &objp->stat)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->ordernum)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypresp_all(XDR *xdrs, ypresp_all *objp) -{ - int CallAgain = 0; - PRLINENO; - if (xdrs->x_op == XDR_DECODE) { - while(1) { -#if 1 - int s=objp->ypresp_all_u.val.stat; - bzero((char *)objp, sizeof (*objp)); - objp->ypresp_all_u.val.stat=s; -#endif - if (!xdr_bool(xdrs, &objp->more)) { - return (FALSE); - } - switch (objp->more) { - case TRUE: - if (!__xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) { - return (FALSE); - } - if (CallAgain==0) { - CallAgain=(*(__xdr_ypall_callback->foreach.decoder))( - objp->ypresp_all_u.val.stat, - objp->ypresp_all_u.val.key.keydat_val, - objp->ypresp_all_u.val.key.keydat_len, - objp->ypresp_all_u.val.val.valdat_val, - objp->ypresp_all_u.val.val.valdat_len, - __xdr_ypall_callback->data); - } - break; - case FALSE: - return TRUE; - } -#if 0 - xdrs->x_op=XDR_FREE; - if (!__xdr_ypresp_all(xdrs, objp)) { - return FALSE; - } - xdrs->x_op=XDR_DECODE; -#else - xdr_free(__xdr_ypresp_all, (char *)objp); -#endif - } - } else if (xdrs->x_op == XDR_ENCODE) { - while(1) { - if (!xdr_bool(xdrs, &(objp->more))) { - return (FALSE); - } - if (!__xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) { - printf("__xdr_ypresp_key_val failed\n"); - return (FALSE); - } - if (objp->ypresp_all_u.val.stat!=YP_TRUE) { - objp->more=FALSE; - if (!xdr_bool(xdrs, &(objp->more))) { - return (FALSE); - } - return(TRUE); - } - objp->ypresp_all_u.val.stat = - (enum ypstat)(*(__xdr_ypall_callback->foreach.encoder))( - objp->ypresp_all_u.val.key.keydat_val, - objp->ypresp_all_u.val.key.keydat_len, - &(objp->ypresp_all_u.val.key.keydat_val), - &(objp->ypresp_all_u.val.key.keydat_len), - &(objp->ypresp_all_u.val.val.valdat_val), - &(objp->ypresp_all_u.val.val.valdat_len)); - } - } else { -#if 0 - bool_t more=objp->more; - if (more==TRUE) { - if (!xdr_bool(xdrs, &objp->more)) { - return FALSE; - } - if (!__xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) { - return (FALSE); - } - } -#endif - - return(TRUE); - } -} - -bool_t -__xdr_ypresp_xfr(XDR *xdrs, ypresp_xfr *objp) -{ - - if (!xdr_u_int(xdrs, &objp->transid)) { - return (FALSE); - } - if (!__xdr_ypxfrstat(xdrs, &objp->xfrstat)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypmaplist(XDR *xdrs, ypmaplist *objp) -{ - - if (!__xdr_mapname(xdrs, &objp->map)) { - return (FALSE); - } - if (!xdr_pointer(xdrs, (char **)&objp->next, sizeof(ypmaplist), (xdrproc_t)__xdr_ypmaplist)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypresp_maplist(XDR *xdrs, ypresp_maplist *objp) -{ - - if (!__xdr_ypstat(xdrs, &objp->stat)) { - return (FALSE); - } - if (!xdr_pointer(xdrs, (char **)&objp->maps, sizeof(ypmaplist), (xdrproc_t)__xdr_ypmaplist)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_yppush_status(XDR *xdrs, yppush_status *objp) -{ - - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_yppushresp_xfr(XDR *xdrs, yppushresp_xfr *objp) -{ - - if (!xdr_u_int(xdrs, &objp->transid)) { - return (FALSE); - } - if (!__xdr_yppush_status(xdrs, &objp->status)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypbind_resptype(XDR *xdrs, ypbind_resptype *objp) -{ - - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypbind_binding(XDR *xdrs, ypbind_binding *objp) -{ - - if (!xdr_opaque(xdrs, objp->ypbind_binding_addr, 4)) { - return (FALSE); - } - if (!xdr_opaque(xdrs, objp->ypbind_binding_port, 2)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypbind_resp(XDR *xdrs, ypbind_resp *objp) -{ - - if (!__xdr_ypbind_resptype(xdrs, &objp->ypbind_status)) { - return (FALSE); - } - switch (objp->ypbind_status) { - case YPBIND_FAIL_VAL: - if (!xdr_u_int(xdrs, &objp->ypbind_resp_u.ypbind_error)) { - return (FALSE); - } - break; - case YPBIND_SUCC_VAL: - if (!__xdr_ypbind_binding(xdrs, &objp->ypbind_resp_u.ypbind_bindinfo)) { - return (FALSE); - } - break; - default: - return (FALSE); - } - return (TRUE); -} - -bool_t -__xdr_ypbind_setdom(XDR *xdrs, ypbind_setdom *objp) -{ - - if (!__xdr_domainname(xdrs, &objp->ypsetdom_domain)) { - return (FALSE); - } - if (!__xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding)) { - return (FALSE); - } - if (!xdr_u_int(xdrs, &objp->ypsetdom_vers)) { - return (FALSE); - } - return (TRUE); -} diff --git a/gnu/usr.bin/yppush/ypclnt.c b/gnu/usr.bin/yppush/ypclnt.c deleted file mode 100644 index 0088754..0000000 --- a/gnu/usr.bin/yppush/ypclnt.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - YPS-0.2, NIS-Server for Linux - Copyright (C) 1994 Tobias Reber - - 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 of the License, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - Modified for use with FreeBSd 2.x by Bill Paul (wpaul@ctr.columbia.edu) - - $Id$ -*/ - -/* - * $Author: root $ - * $Log: ypclnt.c,v $ - * Revision 2.0 1994/01/06 16:58:48 root - * Version 2.0 - * - * Revision 0.17 1994/01/02 22:48:22 root - * Added strict prototypes - * - * Revision 0.16 1994/01/02 20:09:39 root - * Added GPL notice - * - * Revision 0.15 1993/12/30 22:34:57 root - * *** empty log message *** - * - * Revision 0.14 1993/12/19 12:42:32 root - * *** empty log message *** - * - * Revision 0.13 1993/06/12 09:39:30 root - * Align with include-4.4 - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -/* - * ypclnt.h does not have a definition for struct dom_binding, - * although it is used there. It is defined in yp_prot.h, but - * we cannot use it here. - */ -struct dom_binding { - void * m; -}; -#include - -#if 0 -#define SOCKSERVER 0x7f000001 -#endif - -static struct sockaddr_in ServerAddress; -static CLIENT *UdpClient=NULL, *TcpClient=NULL; - -void -_yp_unbind(char *DomainName) -{ - if (UdpClient) clnt_destroy(UdpClient); - UdpClient=NULL; - if (TcpClient) clnt_destroy(TcpClient); - TcpClient=NULL; -} - -int -_yp_bind(struct sockaddr_in *ServerAddress, char *DomainName) -{ - struct sockaddr_in UdpServerAddress, TcpServerAddress; - int UdpSockp, TcpSockp; - static struct timeval Wait = { 5, 0 }; - - if (UdpClient || TcpClient) yp_unbind(DomainName); - - bcopy(ServerAddress, &UdpServerAddress, sizeof(*ServerAddress)); - UdpServerAddress.sin_port=0; - UdpSockp=(RPC_ANYSOCK); - bcopy(ServerAddress, &TcpServerAddress, sizeof(*ServerAddress)); - TcpServerAddress.sin_port=0; - TcpSockp=(RPC_ANYSOCK); - if ((UdpClient=clntudp_create(&UdpServerAddress, YPPROG, YPVERS, - Wait, &UdpSockp))==NULL) { - clnt_pcreateerror("UdpClient"); - return(YPERR_RPC); - } - if ((TcpClient=clnttcp_create(&TcpServerAddress, YPPROG, YPVERS, - &TcpSockp, 0, 0))==NULL) { - clnt_pcreateerror("TcpClient"); - return(YPERR_RPC); - } - return(0); - -} - - -int -_yp_clear(char *DomainName) -{ - void *resp; - int Status; - - do { - if (UdpClient==NULL) - if ((Status=yp_bind(DomainName))) return(Status); - if ((resp=ypproc_clear_2(NULL, UdpClient))==NULL) { - clnt_perror(UdpClient, "_yp_clear"); - _yp_unbind(DomainName); - } - } while(resp==NULL); - return 0; -} diff --git a/gnu/usr.bin/yppush/yppush_s.c b/gnu/usr.bin/yppush/yppush_s.c deleted file mode 100644 index 89cc8e8..0000000 --- a/gnu/usr.bin/yppush/yppush_s.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - YPS-0.2, NIS-Server for Linux - Copyright (C) 1994 Tobias Reber - - 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 of the License, 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - Modified for use with FreeBSD 2.x by Bill Paul (wpaul@ctr.columbia.edu) - - $Id$ -*/ -/* - * $Author: root $ - * $Log: yppush_s.c,v $ - * Revision 1.3 1994/01/02 21:59:08 root - * Strict prototypes - * - * Revision 1.2 1994/01/02 20:10:08 root - * Added GPL notice - * - * Revision 1.1 1994/01/02 18:04:08 root - * Initial revision - * - */ - -#include -#include -#include -#include - -enum yppush_status { - YPPUSH_SUCC = 1, - YPPUSH_AGE = 2, - YPPUSH_NOMAP = -1, - YPPUSH_NODOM = -2, - YPPUSH_RSRC = -3, - YPPUSH_RPC = -4, - YPPUSH_MADDR = -5, - YPPUSH_YPERR = -6, - YPPUSH_BADARGS = -7, - YPPUSH_DBM = -8, - YPPUSH_FILE = -9, - YPPUSH_SKEW = -10, - YPPUSH_CLEAR = -11, - YPPUSH_FORCE = -12, - YPPUSH_XFRERR = -13, - YPPUSH_REFUSED = -14, -}; -typedef enum yppush_status yppush_status; -bool_t __xdr_yppush_status(XDR *, void *); - -static inline char * -yppush_err_string(enum yppush_status y) { - switch(y) { - case YPPUSH_SUCC: return "Success"; - case YPPUSH_AGE: return "Master's version not newer"; - case YPPUSH_NOMAP: return "Can't find server for map"; - case YPPUSH_NODOM: return "Domain not supported"; - case YPPUSH_RSRC: return "Local resource alloc failure"; - case YPPUSH_RPC: return "RPC failure talking to server"; - case YPPUSH_MADDR: return "Can't get master address"; - case YPPUSH_YPERR: return "YP server/map db error"; - case YPPUSH_BADARGS: return "Request arguments bad"; - case YPPUSH_DBM: return "Local dbm operation failed"; - case YPPUSH_FILE: return "Local file I/O operation failed"; - case YPPUSH_SKEW: return "Map version skew during transfer"; - case YPPUSH_CLEAR: return "Can't send \"Clear\" req to local ypserv"; - case YPPUSH_FORCE: return "No local order number in map use -f flag."; - case YPPUSH_XFRERR: return "ypxfr error"; - case YPPUSH_REFUSED: return "Transfer request refused by ypserv"; - } -} - -struct yppushresp_xfr { - u_int transid; - yppush_status status; -}; -typedef struct yppushresp_xfr yppushresp_xfr; -bool_t __xdr_yppushresp_xfr(XDR *, void *); - - -#define YPPUSH_XFRRESPPROG ((u_long)0x40000000) -#define YPPUSH_XFRRESPVERS ((u_long)1) - -#define YPPUSHPROC_NULL ((u_long)0) -static inline void * -yppushproc_null_1(void * req, struct svc_req * rqstp) { - static int resp; - return &resp; -} - -#define YPPUSHPROC_XFRRESP ((u_long)1) -static inline void * -yppushproc_xfrresp_1(yppushresp_xfr *req, struct svc_req * rqstp) { - static int resp; - - if (req->status!=YPPUSH_SUCC) - fprintf(stderr, "YPPUSH: %s\n", yppush_err_string(req->status)); - return &resp; -} - -void -yppush_xfrrespprog_1( struct svc_req *rqstp, SVCXPRT *transp) -{ - union { - int fill; - } argument; - char *result; - bool_t (*xdr_argument)(XDR *, void *), (*xdr_result)(XDR *, void *); - char *(*local)( void *, struct svc_req *); - - switch (rqstp->rq_proc) { - case YPPUSHPROC_NULL: - xdr_argument = (bool_t (*)(XDR *, void *))xdr_void; - xdr_result = (bool_t (*)(XDR *, void *))xdr_void; - local = (char *(*)( void *, struct svc_req *)) yppushproc_null_1; - break; - - case YPPUSHPROC_XFRRESP: - xdr_argument = __xdr_yppushresp_xfr; - xdr_result = (bool_t (*)(XDR *, void *))xdr_void; - local = (char *(*)( void *, struct svc_req *)) yppushproc_xfrresp_1; - break; - - default: - svcerr_noproc(transp); - exit(1); - } - bzero((char *)&argument, sizeof(argument)); - if (!svc_getargs(transp, xdr_argument, &argument)) { - svcerr_decode(transp); - exit(1); - } - result = (*local)(&argument, rqstp); - if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { - svcerr_systemerr(transp); - } - if (!svc_freeargs(transp, xdr_argument, &argument)) { - (void)fprintf(stderr, "unable to free arguments\n"); - exit(1); - if (rqstp->rq_proc!=YPPUSHPROC_NULL) - exit(0); - } - exit(0); -} diff --git a/gnu/usr.sbin/yppasswdd/yppasswd_xdr.c b/gnu/usr.sbin/yppasswdd/yppasswd_xdr.c deleted file mode 100644 index 30b55c2..0000000 --- a/gnu/usr.sbin/yppasswdd/yppasswd_xdr.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * yppasswdd - * Copyright 1994 Olaf Kirch, - * - * This program is covered by the GNU General Public License, version 2. - * It is provided in the hope that it is useful. However, the author - * disclaims ALL WARRANTIES, expressed or implied. See the GPL for details. - * - * This file was generated automatically by rpcgen from yppasswd.x, and - * editied manually. - */ - -#include -#include "yppasswd.h" - - -bool_t -xdr_xpasswd(XDR *xdrs, xpasswd *objp) -{ - if (!xdr_string(xdrs, &objp->pw_name, ~0)) { - return (FALSE); - } - if (!xdr_string(xdrs, &objp->pw_passwd, ~0)) { - return (FALSE); - } - if (!xdr_int(xdrs, &objp->pw_uid)) { - return (FALSE); - } - if (!xdr_int(xdrs, &objp->pw_gid)) { - return (FALSE); - } - if (!xdr_string(xdrs, &objp->pw_gecos, ~0)) { - return (FALSE); - } - if (!xdr_string(xdrs, &objp->pw_dir, ~0)) { - return (FALSE); - } - if (!xdr_string(xdrs, &objp->pw_shell, ~0)) { - return (FALSE); - } - return (TRUE); -} - - -bool_t -xdr_yppasswd(XDR *xdrs, yppasswd *objp) -{ - if (!xdr_string(xdrs, &objp->oldpass, ~0)) { - return (FALSE); - } - if (!xdr_xpasswd(xdrs, &objp->newpw)) { - return (FALSE); - } - return (TRUE); -} - - diff --git a/gnu/usr.sbin/ypserv/Makefile b/gnu/usr.sbin/ypserv/Makefile deleted file mode 100644 index edc8ac0..0000000 --- a/gnu/usr.sbin/ypserv/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# $Id: Makefile,v 1.7 1995/07/12 16:28:10 wpaul Exp $ -# From: @(#)Makefile 8.3 (Berkeley) 4/2/94 - -PROG= ypserv -SRCS= dnslookup.c svc_run.c yp_svc.c yp_xdr.c server.c - -CFLAGS+=-Wall -DTCP_WRAPPER=0 -DTCPW_FACILITY=LOG_AUTH -CFLAGS+=-DMAX_CHILDREN=20 -DINSTDIR='"/usr/libexec"' - -MAN8= ypserv.8 - -afterinstall: - ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 \ - ${.CURDIR}/Makefile.yp \ - ${DESTDIR}/var/yp/Makefile - ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ - ${.CURDIR}/mknetid \ - ${DESTDIR}/usr/libexec/mknetid - -.include diff --git a/gnu/usr.sbin/ypserv/Makefile.yp b/gnu/usr.sbin/ypserv/Makefile.yp deleted file mode 100644 index b697070..0000000 --- a/gnu/usr.sbin/ypserv/Makefile.yp +++ /dev/null @@ -1,394 +0,0 @@ -# -# Makefile for the NIS databases -# -# $Id: Makefile.yp,v 1.12 1995/10/26 18:00:35 wpaul Exp $ -# -# This Makefile should only be run on the NIS master server of a domain. -# All updated maps will be pushed to all NIS slave servers listed in the -# /var/yp/ypservers file. Please make sure that the hostnames of all -# NIS servers in your domain are listed in /var/yp/ypservers. -# -# This Makefile can be modified to support more NIS maps if desired. -# - -# If this machine is an NIS master, comment out this next line so -# that changes to the NIS maps can be propagated to the slave servers. -# (By default we assume that we are only serving a small domain with -# only one server.) -# -NOPUSH = "True" - -# If you want to use a FreeBSD NIS server to serve non-FreeBSD clients -# (i.e. clients who expect the password field in the passwd maps to be -# valid) then uncomment this line. This will cause $YPDIR/passwd to -# be generated with valid password fields. This is insecure: FreeBSD -# normally only serves the master.passwd maps (which have real encrypted -# passwords in them) to the superuser on other FreeBSD machines, but -# non-FreeBSD clients (e.g. SunOS, Solaris (without NIS+), IRIX, HP-UX, -# etc...) will only work properly in 'unsecure' mode. -# -#UNSECURE = "True" - -# These are commands which this Makefile needs to properly rebuild the -# NIS databases. Don't change these unless you have a good reason. Also -# be sure not to place an @ in front of /usr/bin/awk: it isn't necessary -# and it'll break everything in sight. -# -AWK = /usr/bin/awk -RM = @/bin/rm -f -RCAT = /bin/cat -CAT = @$(RCAT) - -DBLOAD = /usr/sbin/yp_mkdb -m `hostname` -MKNETID = /usr/libexec/mknetid -YPPUSH = /usr/bin/yppush -DOMAIN = `/bin/domainname` -REVNETGROUP = /usr/libexec/revnetgroup - -YPSRCDIR = /etc -YPDIR = /var/yp -YPMAPDIR = $(YPDIR)/$(DOMAIN) - -# These are the files from which the NIS databases are built. You may edit -# these to taste in the event that you wish to keep your NIS source files -# seperate from your NIS server's actual configuration files. Note that the -# NIS passwd and master.passwd files are stored in /var/yp: the server's -# real password database is not used by default. However, you may use -# the real /etc/passwd and /etc/master.passwd files by: -# -# -# - invoking yppasswdd without the -m option (yppasswdd will use -# /etc/master.passwd if no alternate master.passwd file is specified -# and do a 'pwd_mkdb' as needed). -# - Specifying the location of the master.passwd file using the -# MASTER_PASSWD variable, i.e.: -# -# # make MASTER_PASSWD=/path/to/some/other/master.passwd -# -# - (optionally): editing this Makefile to change the default location. -# -# To add a user, edit $(YPDIR)/master.passwd and type 'make'. The raw -# passwd file will be generated from the master.passwd file automagically. -# -ETHERS = $(YPSRCDIR)/ethers # ethernet addresses (for rarpd) -BOOTPARAMS= $(YPSRCDIR)/bootparams # for booting Sun boxes (bootparamd) -HOSTS = $(YPSRCDIR)/hosts -NETWORKS = $(YPSRCDIR)/networks -PROTOCOLS = $(YPSRCDIR)/protocols -RPC = $(YPSRCDIR)/rpc -SERVICES = $(YPSRCDIR)/services -GROUP = $(YPSRCDIR)/group -NETGROUP = $(YPSRCDIR)/netgroup -PASSWD = $(YPDIR)/passwd -.if !defined(MASTER_PASSWD) -MASTER = $(YPDIR)/master.passwd -.else -MASTER = $(MASTER_PASSWD) -.endif -YPSERVERS = $(YPDIR)/ypservers # List of all NIS servers for a domain -PUBLICKEY = $(YPSRCDIR)/publickey - -target: - @if [ ! -d $(DOMAIN) ]; then mkdir $(DOMAIN); fi; \ - cd $(DOMAIN) ; echo "NIS Map update started on `date`" ; \ - make -f ../Makefile all; echo "NIS Map update completed." - -# If you don't want some of these maps built, feel free to comment -# them out from this list. -# Note that we don't build the ethers or boorparams maps by default -# since /etc/ethers and /etc/bootparams are not likely to be present -# on all systems. -# - -all: master.passwd passwd hosts group networks protocols \ - rpc services servers netid # publickey netgroup ethers bootparam - -ethers: ethers.byname ethers.byaddr -bootparam: bootparams -hosts: hosts.byname hosts.byaddr -networks: networks.byaddr networks.byname -protocols: protocols.bynumber protocols.byname -rpc: rpc.byname rpc.bynumber -services: services.byname -passwd: passwd.byname passwd.byuid -group: group.byname group.bygid -netgrp: netgroup -netid: netid.byname -servers: ypservers -publickey: publickey.byname - -master.passwd: master.passwd.byname master.passwd.byuid - - -ypservers: $(YPSERVERS) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(YPSERVERS) | \ - $(AWK) '{ if ($$1 != "" && $$1 != "#") print $$0"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(YPSERVERS) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - -ethers.byname: $(ETHERS) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(ETHERS) | \ - $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ - print $$2"\t"$$0 }' $^ | $(DBLOAD) -i $(ETHERS) \ - -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) -i $(ETHERS) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -ethers.byaddr: $(ETHERS) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(ETHERS) | \ - $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ - print $$1"\t"$$0 }' $^ | $(DBLOAD) -i $(ETHERS) \ - -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -bootparams: $(BOOTPARAMS) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(BOOTPARAMS) | \ - $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ - print $$0 }' $^ | $(DBLOAD) -i $(BOOTPARAMS) \ - -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -netgroup: $(NETGROUP) netgroup.byhost netgroup.byuser - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(NETGROUP) | \ - $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ - print $$0 }' $^ | $(DBLOAD) -i $(NETGROUP) \ - -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - @$(MAKE) -f ../Makefile netid - - -netgroup.byhost: $(NETGROUP) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(NETGROUP) | $(REVNETGROUP) -h -f $(NETGROUP) | \ - $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ - print $$0 }' $^ | $(DBLOAD) -i $(NETGROUP) \ - -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -netgroup.byuser: $(NETGROUP) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(NETGROUP) | $(REVNETGROUP) -u -f $(NETGROUP) | \ - $(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \ - print $$0 }' $^ | $(DBLOAD) -i $(NETGROUP) \ - -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -hosts.byname: $(HOSTS) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(HOSTS) | \ - $(AWK) '/^[0-9]/ { for (n=2; n<=NF && $$n !~ "#"; n++) \ - print $$n"\t"$$0 }' $^ | $(DBLOAD) -i $(HOSTS) \ - -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - @$(MAKE) -f ../Makefile netid - -hosts.byaddr: $(HOSTS) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(HOSTS) | \ - $(AWK) '$$1 !~ "#" { print $$1"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(HOSTS) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - @$(MAKE) -f ../Makefile netid - - -networks.byname: $(NETWORKS) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(NETWORKS) | \ - $(AWK) \ - '$$1 !~ "#" { print $$1"\t"$$0; \ - for (n=3; n<=NF && $$n !~ "#"; n++) \ - print $$n"\t"$$0 \ - }' $^ | $(DBLOAD) -i $(NETWORKS) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -networks.byaddr: $(NETWORKS) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(NETWORKS) | \ - $(AWK) '$$1 !~ "#" { print $$2"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(NETWORKS) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -protocols.byname: $(PROTOCOLS) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(PROTOCOLS) | \ - $(AWK) \ - '$$1 !~ "#" { print $$1"\t"$$0; \ - for (n=3; n<=NF && $$n !~ "#"; n++) \ - print $$n"\t"$$0 \ - }' $^ | $(DBLOAD) -i $(PROTOCOLS) \ - -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -protocols.bynumber: $(PROTOCOLS) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(PROTOCOLS) | \ - $(AWK) '$$1 !~ "#" { print $$2"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(PROTOCOLS) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -rpc.byname: $(RPC) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(RPC) | \ - $(AWK) \ - '$$1 !~ "#" { print $$1"\t"$$0; \ - for (n=3; n<=NF && $$n !~ "#"; n++) \ - print $$n"\t"$$0 \ - }' $^ | $(DBLOAD) -i $(RPC) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -rpc.bynumber: $(RPC) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(RPC) | \ - $(AWK) '$$1 !~ "#" { print $$2"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(RPC) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -services.byname: $(SERVICES) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(SERVICES) | \ - $(AWK) \ - '$$1 !~ "#" { if (index($$2,"udp")) { printf("%s/udp",$$1) } \ - else { printf("%s/tcp",$$1) }; print "\t"$$0 \ - }' $^ | $(DBLOAD) -i $(SERVICES) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -publickey.byname: $(PUBLICKEY) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(PUBLICKEY) | \ - $(AWK) '$$1 !~ "#" { print $$1"\t"$$2 }' $^ \ - | $(DBLOAD) -i $(PUBLICKEY) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -$(PASSWD): $(MASTER) - @echo "Creating new $@ file from $(MASTER)..." - $(RM) $@ - @if [ ! $(UNSECURE) ]; then \ - $(RCAT) $(MASTER) | \ - $(AWK) -F: '{if ($$1 != "+") \ - print $$1":*:"$$3":"$$4":"$$8":"$$9":"$$10}' $^ \ - > $(PASSWD) ; \ - else $(RCAT) $(MASTER) | \ - $(AWK) -F: '{if ($$1 != "+") \ - print $$1":"$$2":"$$3":"$$4":"$$8":"$$9":"$$10}' $^ \ - > $(PASSWD) ; fi - - -passwd.byname: $(PASSWD) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(PASSWD) | \ - $(AWK) -F: '{ if ($$1 != "+") print $$1"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(PASSWD) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - -passwd.byuid: $(PASSWD) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(PASSWD) | \ - $(AWK) -F: '{ if ($$1 != "+") print $$3"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(PASSWD) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - @$(MAKE) -f ../Makefile netid - - -group.byname: $(GROUP) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(GROUP) | \ - $(AWK) -F: '{ if ($$1 != "+") print $$1"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(GROUP) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -group.bygid: $(GROUP) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(GROUP) | \ - $(AWK) -F: '{ if ($$1 != "+") print $$3"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(GROUP) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - @$(MAKE) -f ../Makefile netid - - -netid.byname: $(GROUP) $(PASSWD) - @echo "Updating $@..." - $(RM) $@ - @$(MKNETID) $(PASSWD) $(GROUP) `basename \`pwd\`` \ - | $(DBLOAD) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -master.passwd.byname: $(MASTER) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(MASTER) | \ - $(AWK) -F: '{ if ($$1 != "+") print $$1"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(MASTER) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi - - -master.passwd.byuid: $(MASTER) - @echo "Updating $@..." - $(RM) $@ - $(CAT) $(MASTER) | \ - $(AWK) -F: '{ if ($$1 != "+") print $$3"\t"$$0 }' $^ \ - | $(DBLOAD) -i $(MASTER) -o $(YPMAPDIR)/$@ - $@ - @if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi - @if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi diff --git a/gnu/usr.sbin/ypserv/dnslookup.c b/gnu/usr.sbin/ypserv/dnslookup.c deleted file mode 100644 index 9d10ecf..0000000 --- a/gnu/usr.sbin/ypserv/dnslookup.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 1995 Bill Paul (wpaul@ctr.columbia.edu) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Bill Paul. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: dnslookup.c,v 1.1 1995/01/31 08:58:52 wpaul Exp $ - */ - -/* -** Do standard and reverse DNS lookups using the resolver library. -** Take care of all the dirty work here so the main program only has to -** pass us a pointer to an array of characters. -** -** We have to use direct resolver calls here otherwise the YP server -** could end up looping by calling itself over and over again until -** it disappeared up its own belly button. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern struct hostent *_gethostbydnsname(); -extern struct hostent *_gethostbydnsaddr(); - -char *parse(hp) -struct hostent *hp; -{ -char *result; -int len,i; -struct in_addr addr; - - len = 16 + strlen(hp->h_name); - for (i = 0; hp->h_aliases[i]; i++) - len += strlen(hp->h_aliases[i]) + 1; - - result = (char *)malloc(len + 1); - bzero(result, len+1); - - bcopy(hp->h_addr, &addr, sizeof(struct in_addr)); - strcat(result, (char *)inet_ntoa(addr)); - strcat(result, " "); - strcat(result, hp->h_name); - - for (i = 0; hp->h_aliases[i]; i++) - { - strcat(result, " "); - strcat(result, hp->h_aliases[i]); - } - - return (result); -} - -char *dnsname(address) -char *address; -{ -struct hostent *hp; - - if (strchr(address, '@')) - return (NULL); - if ((hp = (struct hostent *)_gethostbydnsname(address)) == NULL) - return (NULL); - - return(parse(hp)); -} - -char *dnsaddr(address) -char *address; -{ -struct hostent *hp; -struct in_addr addr; - - if (strchr(address, '@')) - return (NULL); - if (!inet_aton(address, &addr)) - return (NULL); - if ((hp = (struct hostent *)_gethostbydnsaddr(&addr, - sizeof(unsigned long), AF_INET)) == NULL) - return (NULL); - - return(parse(hp)); -} diff --git a/gnu/usr.sbin/ypserv/mknetid b/gnu/usr.sbin/ypserv/mknetid deleted file mode 100644 index 6619b5d..0000000 --- a/gnu/usr.sbin/ypserv/mknetid +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# -# Produce netid.byname map file -# -# Written by O.Kirch, 1994. -# -PASSWD=$1 -GROUP=$2 -DOMAIN=$3 - -tempsed=/tmp/pass.$$ - - # First, get all login/uid info from passwd file - grep -v '^+:' $PASSWD | - awk -F: '{ printf "s/^%s:/%s/\n", $1, $3; }' >$tempsed - # next one is a giant pipe: - grep -v '^+:' $GROUP | - grep -v ':[ ]*$' | - sed 's/^[^:]*:[^:]*:\([0-9]*\):\(.*\)/\1,\2/' | - awk -F, '{ for (n=2; n<=NF; n++) - if ($n != "") print $n":\t"$1; - }' | - sed -f $tempsed | sort | grep -v ':' | - awk 'BEGIN { uid=-1; } - { if (uid == $1) { - groups=groups","$2; - } else { - if (uid != -1) - print uid":"groups; - uid=$1; groups=$2; - } - } - END { if (uid != -1) printf("%s:%s\n", uid, groups); }' | - sed "s/\(.*\):/unix.\1@$DOMAIN &/" - rm -f $tempsed - exit 0 diff --git a/gnu/usr.sbin/ypserv/server.c b/gnu/usr.sbin/ypserv/server.c deleted file mode 100644 index 205a846..0000000 --- a/gnu/usr.sbin/ypserv/server.c +++ /dev/null @@ -1,1384 +0,0 @@ -/* -** server.c YP server routines. -** -** Copyright (c) 1993 Signum Support AB, Sweden -** -** This file is part of the NYS YP Server. -** -** The NYS YP Server 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 of the -** License, or (at your option) any later version. -** -** The NYS YP Server 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 the NYS YP Server; see the file COPYING. If -** not, write to the Free Software Foundation, Inc., 675 Mass Ave, -** Cambridge, MA 02139, USA. -** -** Author: Peter Eriksson -** Ported to FreeBSD and hacked all to pieces -** by Bill Paul -** -** $Id: server.c,v 1.11 1995/07/15 23:27:47 wpaul Exp $ -** -*/ - -#include "system.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "yp.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if __STDC__ -#include -#else -#include -#endif - -#define PERM_SECURE (S_IRUSR|S_IWUSR) -HASHINFO openinfo = { - 4096, /* bsize */ - 32, /* ffactor */ - 256, /* nelem */ - 2048 * 1024, /* cachesize */ - NULL, /* hash */ - 0, /* lorder */ -}; - -#if TCP_WRAPPER -#include "tcpd.h" -int allow_severity=LOG_INFO; -int deny_severity=LOG_WARNING; -#endif - -void verr __P((const char *, _BSD_VA_LIST_)); -void Perror __P((const char *, ...)); - -extern char *dnsname(); -extern char *dnsaddr(); -extern char *_gethostbydnsaddr(); - -extern char *progname; -extern int errno; - -int debug_flag = 0; -int dns_flag = 0; -int children = 0; -int forked = 0; - -void verr(fmt, ap) - const char *fmt; - _BSD_VA_LIST_ ap; - -{ - if (debug_flag) - vfprintf(stderr, fmt, ap); - else - vsyslog(LOG_NOTICE, fmt, ap); -} - -void -#ifdef __STDC__ -Perror(const char *fmt, ...) -#else -Perror(fmt, va_list) - const char *fmt; - va_dcl -#endif -{ - va_list ap; -#ifdef __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - verr(fmt,ap); - va_end(ap); -} - - -/* -** Return 1 if request comes from an authorized host -** -** XXX This function should implement the "securenets" functionality -*/ -static int is_valid_host(struct sockaddr_in *sin) -{ -#if TCP_WRAPPER - extern int hosts_ctl(char *, char *, char *, char *); - int status; - static long oldaddr=0; /* so we dont log multiple times */ - static int oldstatus=-1; - char *h=NULL; - -#ifdef TRYRESOLVE - struct hostent *hp; - - hp = _gethostbydnsaddr((char *) &sin->sin_addr.s_addr, - sizeof (sin->sin_addr.s_addr), AF_INET); - - h = (hp && hp->h_name) ? hp->h_name : NULL; -#endif - -#ifndef FROM_UNKNOWN -#define FROM_UNKNOWN STRING_UNKNOWN -#endif - - status = hosts_ctl(progname, - h?h:FROM_UNKNOWN, - inet_ntoa(sin->sin_addr), - ""); - - if (!status && (sin->sin_addr.s_addr != oldaddr || status != oldstatus)) { - syslog(status?allow_severity:deny_severity, - "%sconnect from %s\n",status?"":"refused ", - h?h:inet_ntoa(sin->sin_addr)); - oldaddr=sin->sin_addr.s_addr; - oldstatus=status; - } - return status; -#else - return 1; -#endif -} - - -void *ypproc_null_2_svc(void *dummy, - struct svc_req *rqstp) -{ - static int foo; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - if (!is_valid_host(rqhost)) - return NULL; - - if (debug_flag) - Perror("ypproc_null() [From: %s:%d]\n", - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - return (void *) &foo; -} - - -/* -** Return 1 if the name is a valid domain name served by us, else 0. -*/ -static int is_valid_domain(const char *domain) -{ - struct stat sbuf; - - - if (domain == NULL || - strcmp(domain, "binding") == 0 || - strcmp(domain, "..") == 0 || - strcmp(domain, ".") == 0 || - strchr(domain, '/')) - return 0; - - if (stat(domain, &sbuf) < 0 || !S_ISDIR(sbuf.st_mode)) - return 0; - - return 1; -} - - - -bool_t *ypproc_domain_2_svc(domainname *name, - struct svc_req *rqstp) -{ - static bool_t result; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - Perror("ypproc_domain(\"%s\") [From: %s:%d]\n", - *name, - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - if (is_valid_domain(*name)) - result = TRUE; - else - result = FALSE; - - if (debug_flag) - Perror("\t-> %s.\n", - (result == TRUE ? "Ok" : "Not served by us")); - - return &result; -} - - -bool_t *ypproc_domain_nonack_2_svc(domainname *name, - struct svc_req *rqstp) -{ - static bool_t result; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - Perror("ypproc_domain_nonack(\"%s\") [From: %s:%d]\n", - *name, - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - if (!is_valid_domain(*name)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid domain)\n"); - - /* Bail out and don't return any RPC value */ - return NULL; - } - - if (debug_flag) - Perror("\t-> OK.\n"); - - result = TRUE; - return &result; -} - - -/* -** Open a DB database -*/ -static DB *open_database(const char *domain, - const char *map) -{ - DB *dbp; - char buf[1025]; - - - if (map[0] == '.' || strchr(map, '/')) - return 0; - - sprintf (buf, "%s/%s", domain, map); - - dbp = dbopen(buf,O_RDONLY|O_EXCL, PERM_SECURE, DB_HASH, &openinfo); - - if (debug_flag > 1 && dbp == NULL) - Perror("dbopen(%s): %s", map, strerror(errno)); - - return dbp; -} - - -#define F_ALL 0x01 -#define F_NEXT 0x02 -#define F_YPALL 0x08 - -/* -** Get a record from a DB database. -** This looks ugly because it emulates the behavior of the original -** GDBM-based routines. Blech. -*/ -int read_database(DB *dbp, - const DBT *ikey, - DBT *okey, - DBT *dval, - int flags) -{ - int first_flag = 0; - DBT nkey, ckey, dummyval; - - - if (ikey == NULL || ikey->data == NULL) - { - (dbp->seq)(dbp,&ckey,&dummyval,R_FIRST); - first_flag = 1; - } - else - { - if ((flags & F_NEXT)) - { - /* - ** This crap would be unnecessary if R_CURSOR actually worked. - */ - if (flags < F_YPALL) - { - (dbp->seq)(dbp,&ckey,&dummyval,R_FIRST); - while(strncmp((char *)ikey->data,ckey.data,(int)ikey->size) || - ikey->size != ckey.size) - (dbp->seq)(dbp,&ckey,&dummyval,R_NEXT); - } - if ((dbp->seq)(dbp,&ckey,&dummyval,R_NEXT)) - ckey.data = NULL; -#ifdef GNU_YPSERV_ARTIFACT - free(dummyval.data); -#endif - } - else - ckey = *ikey; - } - - if (ckey.data == NULL) - { - return (flags & F_NEXT) ? YP_NOMORE : YP_NOKEY; - } - - while (1) - { - if ((dbp->get)(dbp,&ckey,dval,0)) - { -#ifdef GNU_YPSERV_ARTIFACT - /* Free key, unless it comes from the caller! */ - if (ikey == NULL || ckey.data != ikey->data) - free(ckey.data); -#endif - if (ikey && ikey->data != NULL) - { - return YP_NOKEY; - } - else - if (first_flag) - return YP_BADDB; - else - return YP_FALSE; - } - - if ((flags & F_ALL) || strncmp(ckey.data, "YP_", 3) != 0) - { - if (okey) - *okey = ckey; -#ifdef GNU_YPSERV_ARTIFACT - else if (ikey == NULL || ikey->data != ckey.data) - free(ckey.data); -#endif - return YP_TRUE; - } - - /* Free old value */ -#ifdef GNU_YPSERV_ARTIFACT - free(dval->data); -#endif - if ((dbp->seq)(dbp,&nkey,&dummyval,R_NEXT)) - nkey.data = NULL; -#ifdef GNU_YPSERV_ARTIFACT - free(dummyval.data); - - /* Free old key, unless it comes from the caller! */ - if (ikey == NULL || ckey.data != ikey->data) - free(ckey.data); -#endif - if (ckey.data == NULL || nkey.data == NULL) - return YP_NOMORE; - - ckey = nkey; - } -} - - -/* -** Get the DateTimeModified value for a certain map database -*/ -static unsigned long get_dtm(const char *domain, - const char *map) -{ - struct stat sbuf; - char buf[1025]; - - - strcpy(buf, domain); - strcat(buf, "/"); - strcat(buf, map); - - if (stat(buf, &sbuf) < 0) - return 0; - else - return (unsigned long) sbuf.st_mtime; -} - - -/* -** YP function "MATCH" implementation -*/ -ypresp_val *ypproc_match_2_svc(ypreq_key *key, - struct svc_req *rqstp) -{ - static ypresp_val result; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - { - Perror("ypproc_match(): [From: %s:%d]\n", - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - Perror("\t\tdomainname = \"%s\"\n", - key->domain); - Perror("\t\tmapname = \"%s\"\n", - key->map); - Perror("\t\tkeydat = \"%.*s\"\n", - (int) key->key.keydat_len, - key->key.keydat_val); - } - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - /* - ** If this request deals with master.passwd.* and it didn't - ** originate on a privileged port (< 1024), return a YP_YPERR. - ** This is our half-assed way of preventing non-root users - ** on NIS clients from getting at the real password map. Bah. - */ - - if (strstr(key->map, "master.passwd") != NULL && - ntohs(rqhost->sin_port) > 1023) - { - result.stat = YP_YPERR; - return &result; - } - - result.val.valdat_len = 0; - if (result.val.valdat_val) - { -#ifdef GNU_YPSERV_ARTIFACT - /* - * In general, if you malloc() data in an RPC service - * routine, you have to free() it the next time that - * routine is called since the XDR routines won't free - * it for you. However, in this case, we don't have to - * do that because the DB routines do garbage collection - * for us. - */ - free(result.val.valdat_val); -#endif - result.val.valdat_val = NULL; - } - - if (key->domain[0] == '\0' || key->map[0] == '\0') - result.stat = YP_BADARGS; - else if (!is_valid_domain(key->domain)) - result.stat = YP_NODOM; - else - { - DBT rdat, qdat; - - DB *dbp = open_database(key->domain, key->map); - if (dbp == NULL) - result.stat = YP_NOMAP; - else - { - qdat.size = key->key.keydat_len; - qdat.data = key->key.keydat_val; - - result.stat = read_database(dbp, &qdat, NULL, &rdat, F_ALL); - - if (result.stat == YP_TRUE) - { - result.val.valdat_len = rdat.size; - result.val.valdat_val = rdat.data; - } - - (void)(dbp->close)(dbp); - } - } - - if (debug_flag) - { - if (result.stat == YP_TRUE) - Perror("\t-> Value = \"%.*s\"\n", - (int) result.val.valdat_len, - result.val.valdat_val); - else - Perror("\t-> Error #%d\n", result.stat); - } - - - /* - ** Do the jive thing if we didn't find the host in the YP map - ** and we have enabled the magic DNS lookup stuff. - ** - ** DNS lookups are handled in a subprocess so that the server - ** doesn't block while waiting for requests to complete. - */ - if (result.stat != YP_TRUE && strstr(key->map, "hosts") && dns_flag) - { - char *cp = NULL; - - if (children < MAX_CHILDREN && fork()) - { - children++; - return NULL; - } - else - forked++; - - key->key.keydat_val[key->key.keydat_len] = '\0'; - - if (debug_flag) - Perror("Doing DNS lookup of %s\n", key->key.keydat_val); - - if (strcmp(key->map, "hosts.byname") == 0) - cp = dnsname(key->key.keydat_val); - else if (strcmp(key->map, "hosts.byaddr") == 0) - cp = dnsaddr(key->key.keydat_val); - - if (cp) - { - - if (debug_flag) - Perror("\t-> OK (%s)\n", cp); - - result.val.valdat_len = strlen(cp); - result.val.valdat_val = cp; - result.stat = YP_TRUE; - } - else - { - if (debug_flag) - { - Perror("\t-> Not Found\n"); - Perror("DNS lookup: %s",strerror(errno)); - } - - result.stat = YP_NOKEY; - } - } - - return &result; -} - - - -ypresp_key_val *ypproc_first_2_svc(ypreq_nokey *key, - struct svc_req *rqstp) -{ - static ypresp_key_val result; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - { - Perror("ypproc_first(): [From: %s:%d]\n", - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - Perror("\tdomainname = \"%s\"\n", key->domain); - Perror("\tmapname = \"%s\"\n", key->map); -#if 0 - Perror("\tkeydat = \"%.*s\"\n", - (int) key->key.keydat_len, - key->key.keydat_val); -#endif - } - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - /* - ** If this request deals with master.passwd.* and it didn't - ** originate on a privileged port (< 1024), return a YP_YPERR. - ** This is our half-assed way of preventing non-root users - ** on NIS clients from getting at the real password map. Bah. - */ - - if (strstr(key->map, "master.passwd") != NULL && - ntohs(rqhost->sin_port) > 1023) - { - result.stat = YP_YPERR; - return &result; - } - - result.key.keydat_len = 0; - if (result.key.keydat_val) - { -#ifdef GNU_YPSERV_ARTIFACT - free(result.key.keydat_val); -#endif - result.key.keydat_val = NULL; - } - - result.val.valdat_len = 0; - if (result.val.valdat_val) - { -#ifdef GNU_YPSERV_ARTIFACT - free(result.val.valdat_val); -#endif - result.val.valdat_val = NULL; - } - - if (key->map[0] == '\0' || key->domain[0] == '\0') - result.stat = YP_BADARGS; - else if (!is_valid_domain(key->domain)) - result.stat = YP_NODOM; - else - { - DBT dkey, dval; - - DB *dbp = open_database(key->domain, key->map); - if (dbp == NULL) - result.stat = YP_NOMAP; - else - { - result.stat = read_database(dbp, NULL, &dkey, &dval, 0); - - if (result.stat == YP_TRUE) - { - result.key.keydat_len = dkey.size; - result.key.keydat_val = dkey.data; - - result.val.valdat_len = dval.size; - result.val.valdat_val = dval.data; - } - - (void)(dbp->close)(dbp); - } - } - - if (debug_flag) - { - if (result.stat == YP_TRUE) - Perror("\t-> Key = \"%.*s\", Value = \"%.*s\"\n", - (int) result.key.keydat_len, - result.key.keydat_val, - (int) result.val.valdat_len, - result.val.valdat_val); - - else - Perror("\t-> Error #%d\n", result.stat); - } - - return &result; -} - - -ypresp_key_val *ypproc_next_2_svc(ypreq_key *key, - struct svc_req *rqstp) -{ - static ypresp_key_val result; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - { - Perror("ypproc_next(): [From: %s:%d]\n", - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - Perror("\tdomainname = \"%s\"\n", key->domain); - Perror("\tmapname = \"%s\"\n", key->map); - Perror("\tkeydat = \"%.*s\"\n", - (int) key->key.keydat_len, - key->key.keydat_val); - } - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - /* - ** If this request deals with master.passwd.* and it didn't - ** originate on a privileged port (< 1024), return a YP_YPERR. - ** This is our half-assed way of preventing non-root users - ** on NIS clients from getting at the real password map. Bah. - */ - - if (strstr(key->map, "master.passwd") != NULL && - ntohs(rqhost->sin_port) > 1023) - { - result.stat = YP_YPERR; - return &result; - } - - result.key.keydat_len = 0; - if (result.key.keydat_val) - { -#ifdef GNU_YPSERV_ARTIFACT - free(result.key.keydat_val); -#endif - result.key.keydat_val = NULL; - } - - result.val.valdat_len = 0; - if (result.val.valdat_val) - { -#ifdef GNU_YPSERV_ARTIFACT - free(result.val.valdat_val); -#endif - result.val.valdat_val = NULL; - } - - if (key->map[0] == '\0' || key->domain[0] == '\0') - result.stat = YP_BADARGS; - else if (!is_valid_domain(key->domain)) - result.stat = YP_NODOM; - else - { - DBT dkey, dval, okey; - - - DB *dbp = open_database(key->domain, key->map); - if (dbp == NULL) - result.stat = YP_NOMAP; - else - { - dkey.size = key->key.keydat_len; - dkey.data = key->key.keydat_val; - - result.stat = read_database(dbp, &dkey, &okey, &dval, F_NEXT); - - if (result.stat == YP_TRUE) - { - result.key.keydat_len = okey.size; - result.key.keydat_val = okey.data; - - result.val.valdat_len = dval.size; - result.val.valdat_val = dval.data; - } - (void)(dbp->close)(dbp); - } - } - - if (debug_flag) - { - if (result.stat == YP_TRUE) - Perror("\t-> Key = \"%.*s\", Value = \"%.*s\"\n", - (int) result.key.keydat_len, - result.key.keydat_val, - (int) result.val.valdat_len, - result.val.valdat_val); - else - Perror("\t-> Error #%d\n", result.stat); - } - - return &result; -} - - - -static void print_ypmap_parms(const struct ypmap_parms *pp) -{ - Perror("\t\tdomain = \"%s\"\n", pp->domain); - Perror("\t\tmap = \"%s\"\n", pp->map); - Perror("\t\tordernum = %u\n", pp->ordernum); - Perror("\t\tpeer = \"%s\"\n", pp->peer); -} - - -/* -** Clean up after child processes signal their termination. -*/ -void reapchild(sig) -int sig; -{ - int st; - - while (wait3(&st, WNOHANG, NULL) > 0) - children--; -} - -/* -** Stole the ypxfr implementation from the yps package. -*/ -ypresp_xfr *ypproc_xfr_2_svc(ypreq_xfr *xfr, - struct svc_req *rqstp) -{ - static ypresp_xfr result; - struct sockaddr_in *rqhost; - char ypxfr_command[MAXPATHLEN]; - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - { - Perror("ypproc_xfr_2_svc(): [From: %s:%d]\n\tmap_parms:\n", - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - print_ypmap_parms(&xfr->map_parms); - Perror("\t\ttransid = %u\n", xfr->transid); - Perror("\t\tprog = %u\n", xfr->prog); - Perror("\t\tport = %u\n", xfr->port); - } - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - /* - ** If this request originates on a non-privileged port (< 1024), - ** refuse it. We really only need to guard the master.passwd.* - ** maps, but what the hell. - ** This is our half-assed way of preventing non-root users - ** on NIS clients from getting at the real password map. Bah. - */ - - if (ntohs(rqhost->sin_port) > 1023) - { - result.xfrstat = YPXFR_REFUSED; - return &result; - } - - switch(fork()) - { - case 0: - { - char g[11], t[11], p[11]; - - sprintf (ypxfr_command, "%s/ypxfr", INSTDIR); - sprintf (t, "%u", xfr->transid); - sprintf (g, "%u", xfr->prog); - sprintf (p, "%u", xfr->port); - execl(ypxfr_command, "ypxfr", "-d", xfr->map_parms.domain, "-h", - xfr->map_parms.peer, "-f", "-C", t, g, - inet_ntoa(rqhost->sin_addr), p, xfr->map_parms.map, NULL); - Perror("ypxfr execl(): %s",strerror(errno)); - exit(0); - } - case -1: - Perror("fork(): %s",strerror(errno)); - result.xfrstat = YPXFR_XFRERR; - default: - { - result.xfrstat = YPXFR_SUCC; - break; - } - } - - result.transid = xfr->transid; - return &result; -} - - -void *ypproc_clear_2_svc(void *dummy, - struct svc_req *rqstp) -{ - static int foo; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - Perror("ypproc_clear_2_svc() [From: %s:%d]\n", - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - return (void *) &foo; -} - - -static int ypall_close(void *data) -{ - DB *locptr; - - if (debug_flag && data == NULL) - { - Perror("ypall_close() called with NULL pointer.\n"); - return 0; - } - - locptr = (DB *)data; - (void)(locptr->close)(locptr); - return 0; -} - - -static int ypall_encode(ypresp_key_val *val, - void *data) -{ - DBT dkey, dval, okey; - - dkey.data = val->key.keydat_val; - dkey.size = val->key.keydat_len; - - val->stat = read_database((DB *) data, &dkey, &okey, &dval, F_NEXT | F_YPALL); - - if (val->stat == YP_TRUE) - { - val->key.keydat_val = okey.data; - val->key.keydat_len = okey.size; - - val->val.valdat_val = dval.data; - val->val.valdat_len = dval.size; - } - - - return val->stat; -} - - -ypresp_all *ypproc_all_2_svc(ypreq_nokey *nokey, - struct svc_req *rqstp) -{ - static ypresp_all result; - extern __xdr_ypall_cb_t __xdr_ypall_cb; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - { - Perror("ypproc_all_2_svc(): [From: %s:%d]\n", - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - Perror("\t\tdomain = \"%s\"\n", nokey->domain); - Perror("\t\tmap = \"%s\"\n", nokey->map); - } - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - if (children < MAX_CHILDREN && fork()) - { - children++; - return NULL; - } - else - forked++; - - __xdr_ypall_cb.u.encode = NULL; - __xdr_ypall_cb.u.close = NULL; - __xdr_ypall_cb.data = NULL; - - result.more = TRUE; - - /* - ** If this request deals with master.passwd.* and it didn't - ** originate on a privileged port (< 1024), return a YP_YPERR. - ** This is our half-assed way of preventing non-root users - ** on NIS clients from getting at the real password map. Bah. - */ - - if (strstr(nokey->map, "master.passwd") != NULL && - ntohs(rqhost->sin_port) > 1023) - { - result.ypresp_all_u.val.stat = YP_YPERR; - return &result; - } - - if (nokey->map[0] == '\0' || nokey->domain[0] == '\0') - result.ypresp_all_u.val.stat = YP_BADARGS; - else if (!is_valid_domain(nokey->domain)) - result.ypresp_all_u.val.stat = YP_NODOM; - else - { - DBT dkey, dval; - - DB *dbp = open_database(nokey->domain, nokey->map); - if (dbp == NULL) - result.ypresp_all_u.val.stat = YP_NOMAP; - else - { - result.ypresp_all_u.val.stat = read_database(dbp, - NULL, - &dkey, - &dval, - 0); - - if (result.ypresp_all_u.val.stat == YP_TRUE) - { - result.ypresp_all_u.val.key.keydat_len = dkey.size; - result.ypresp_all_u.val.key.keydat_val = dkey.data; - - result.ypresp_all_u.val.val.valdat_len = dval.size; - result.ypresp_all_u.val.val.valdat_val = dval.data; - - __xdr_ypall_cb.u.encode = ypall_encode; - __xdr_ypall_cb.u.close = ypall_close; - __xdr_ypall_cb.data = (void *) dbp; - - return &result; - } - - (void)(dbp->close)(dbp); - } - } - - return &result; -} - - -ypresp_master *ypproc_master_2_svc(ypreq_nokey *nokey, - struct svc_req *rqstp) -{ - static ypresp_master result; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - { - Perror("ypproc_master_2_svc(): [From: %s:%d]\n", - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - Perror("\t\tdomain = \"%s\"\n", nokey->domain); - Perror("\t\tmap = \"%s\"\n", nokey->map); - } - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - /* - ** If this request deals with master.passwd.* and it didn't - ** originate on a privileged port (< 1024), return a YP_YPERR. - ** This is our half-assed way of preventing non-root users - ** on NIS clients from getting at the real password map. Bah. - */ - - if (strstr(nokey->map, "master.passwd") != NULL && - ntohs(rqhost->sin_port) > 1023) - { - result.stat = YP_YPERR; - return &result; - } - - if (result.peer) - { -#ifdef GNU_YPSERV_ARTIFACT - free(result.peer); -#endif - result.peer = NULL; - } - - if (nokey->domain[0] == '\0') - result.stat = YP_BADARGS; - else if (!is_valid_domain(nokey->domain)) - result.stat = YP_NODOM; - else - { - DB *dbp = open_database(nokey->domain, nokey->map); - if (dbp == NULL) - result.stat = YP_NOMAP; - else - { - DBT key, val; - - key.size = sizeof("YP_MASTER_NAME")-1; - key.data = "YP_MASTER_NAME"; - - if ((dbp->get)(dbp,&key,&val,0)) - { - /* No YP_MASTER_NAME record in map? Assume we are Master */ - static char hostbuf[1025]; - - gethostname((char *)&hostbuf, sizeof(hostbuf)-1); - Perror("Hostname: [%s]",hostbuf); - result.peer = strdup(hostbuf); - } - else - { - *(((char *)val.data)+val.size) = '\0'; - result.peer = val.data; - } - - result.stat = YP_TRUE; - (void)(dbp->close)(dbp); - } - } - - if (result.peer == NULL) - result.peer = strdup(""); - - if (debug_flag) - Perror("\t-> Peer = \"%s\"\n", result.peer); - - return &result; -} - - -ypresp_order *ypproc_order_2_svc(ypreq_nokey *nokey, - struct svc_req *rqstp) -{ - static ypresp_order result; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - { - Perror("ypproc_order_2_svc(): [From: %s:%d]\n", - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - Perror("\t\tdomain = \"%s\"\n", nokey->domain); - Perror("\t\tmap = \"%s\"\n", nokey->map); - } - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - /* - ** If this request deals with master.passwd.* and it didn't - ** originate on a privileged port (< 1024), return a YP_YPERR. - ** This is our half-assed way of preventing non-root users - ** on NIS clients from getting at the real password map. Bah. - */ - - if (strstr(nokey->map, "master.passwd") != NULL && - ntohs(rqhost->sin_port) > 1023) - { - result.stat = YP_YPERR; - return &result; - } - - result.ordernum = 0; - - if (nokey->domain[0] == '\0') - result.stat = YP_BADARGS; - else if (!is_valid_domain(nokey->domain)) - result.stat = YP_NODOM; - else - { - DB *dbp = open_database(nokey->domain, nokey->map); - if (dbp == NULL) - result.stat = YP_NOMAP; - else - { - DBT key, val; - - key.size = sizeof("YP_LAST_MODIFIED")-1; - key.data = "YP_LAST_MODIFIED"; - - if ((dbp->get)(dbp,&key,&val,0)) - { - /* No YP_LAST_MODIFIED record in map? Use DTM timestamp.. */ - result.ordernum = get_dtm(nokey->domain, nokey->map); - } - else - { - result.ordernum = atoi(val.data); -#ifdef GNU_YPSERV_ARTIFACT - free(val.data); -#endif - } - - result.stat = YP_TRUE; - (void)(dbp->close)(dbp); - } - } - - if (debug_flag) - Perror("-> Order # %d\n", result.ordernum); - - return &result; -} - - -static void free_maplist(ypmaplist *mlp) -{ - ypmaplist *next; - - while (mlp != NULL) - { - next = mlp->next; - free(mlp->map); - free(mlp); - mlp = next; - } -} - -static int add_maplist(ypmaplist **mlhp, - char *map) -{ - ypmaplist *mlp; - - if (!strncmp(map, ".", strlen(map)) || !strncmp(map, "..", strlen(map))) - return 0; - - mlp = malloc(sizeof(*mlp)); - if (mlp == NULL) - return -1; - - mlp->map = strdup(map); - if (mlp->map == NULL) - { - free(mlp); - return -1; - } - - mlp->next = *mlhp; - *mlhp = mlp; - - return 0; -} - - -ypresp_maplist *ypproc_maplist_2_svc(domainname *name, - struct svc_req *rqstp) -{ - static ypresp_maplist result; - struct sockaddr_in *rqhost; - - - rqhost = svc_getcaller(rqstp->rq_xprt); - - if (debug_flag) - { - Perror("ypproc_maplist_2_svc(): [From: %s:%d]\n", - inet_ntoa(rqhost->sin_addr), - ntohs(rqhost->sin_port)); - - Perror("\t\tdomain = \"%s\"\n", *name); - } - - if (!is_valid_host(rqhost)) - { - if (debug_flag) - Perror("\t-> Ignored (not a valid source host)\n"); - - return NULL; - } - - if (result.maps) - free_maplist(result.maps); - - result.maps = NULL; - - if ((*name)[0] == '\0') - result.stat = YP_BADARGS; - else if (!is_valid_domain(*name)) - result.stat = YP_NODOM; - else - { - DIR *dp; - char dirname[MAXPATHLEN]; - - sprintf(dirname,"./%s",*name); - dp = opendir(dirname); - if (dp == NULL) - { - if (debug_flag) - { - Perror("%s: opendir: %s", progname,strerror(errno)); - } - - result.stat = YP_BADDB; - } - else - { - struct dirent *dep; - - while ((dep = readdir(dp)) != NULL) - if (add_maplist(&result.maps, dep->d_name) < 0) - { - result.stat = YP_YPERR; - break; - } - closedir(dp); - result.stat = YP_TRUE; - } - } - - if (debug_flag) - { - if (result.stat == YP_TRUE) - { - ypmaplist *p; - - p = result.maps; - Perror("-> "); - while (p->next) - { - Perror("%s,", p->map); - p = p->next; - } - putc('\n', stderr); - } - else - Perror("\t-> Error #%d\n", result.stat); - } - - return &result; -} diff --git a/gnu/usr.sbin/ypserv/svc_run.c b/gnu/usr.sbin/ypserv/svc_run.c deleted file mode 100644 index 6f4a52c..0000000 --- a/gnu/usr.sbin/ypserv/svc_run.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. - * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. - * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. - * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 - */ - -#if defined(LIBC_SCCS) && !defined(lint) -/*static char *sccsid = "from: @(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro";*/ -/*static char *sccsid = "from: @(#)svc_run.c 2.1 88/07/29 4.0 RPCSRC";*/ -static char *rcsid = "$Id: svc_run.c,v 1.2 1995/05/30 05:41:35 rgrimes Exp $"; -#endif - -/* - * This is the rpc server side idle loop - * Wait for input, call server program. - */ -#include -#include -#include -#include -#include - -extern int _rpc_dtablesize __P((void)); - -void -my_svc_run() -{ -#ifdef FD_SETSIZE - fd_set readfds; -#else - int readfds; -#endif /* def FD_SETSIZE */ - extern int errno; - extern int forked; - int pid; - - /* Establish the identity of the parent ypserv process. */ - pid = getpid(); - - for (;;) { -#ifdef FD_SETSIZE - readfds = svc_fdset; -#else - readfds = svc_fds; -#endif /* def FD_SETSIZE */ - switch (select(_rpc_dtablesize(), &readfds, NULL, NULL, - (struct timeval *)0)) { - case -1: - if (errno == EINTR) { - continue; - } - perror("svc_run: - select failed"); - return; - case 0: - continue; - default: - svc_getreqset(&readfds); - if (forked && pid != getpid()) - exit(0); - } - } -} diff --git a/gnu/usr.sbin/ypserv/system.h b/gnu/usr.sbin/ypserv/system.h deleted file mode 100644 index 838430a..0000000 --- a/gnu/usr.sbin/ypserv/system.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * $Id$ - */ - -#if (defined(__sun__) || defined(sun)) && !defined(__svr4__) - -/* Stupid SunOS 4 doesn't have prototypes in the header files */ - -/* Some includes just to make the compiler be quiet */ -#include -#include -#include - -extern int fprintf(FILE *fp, const char *format, ...); -extern int _flsbuf(unsigned char c, FILE *fp); -extern int puts(const char *str); -extern int printf(const char *format, ...); - -extern int chdir(const char *path); -extern int gethostname(char *buf, int bufsize); -extern int atoi(const char *str); -extern int perror(const char *str); - -extern int socket (int af, int type, int protocol); -extern int bind (int s, struct sockaddr *name, int namelen); -extern int chdir (const char *path); - -#endif - - -#if (defined(__sun__) || defined(sun)) && defined(__svr4__) - -extern char *strdup(const char *str); - -#define NEED_GETHOSTNAME -#define NEED_SVCSOC_H - -#endif - - -#if defined(hpux) || defined(__hpux__) - -/* HP is really... Ah well. */ - -#define _INCLUDE_HPUX_SOURCE -#define _INCLUDE_XOPEN_SOURCE -#define _INCLUDE_POSIX_SOURCE -#define _INCLUDE_AES_SOURCE - -extern void svcerr_systemerr(); -#endif - - -#if defined(linux) || defined(__linux__) - -/* Need this because some header files doesn't check for __linux__ */ -#if !defined(linux) -#define linux linux -#endif - -/* Needed for non-ANSI prototypes */ -#define _SVID_SOURCE - -/* Needed for gethostname() */ -#define _BSD_SOURCE - -#endif diff --git a/gnu/usr.sbin/ypserv/yp.h b/gnu/usr.sbin/ypserv/yp.h deleted file mode 100644 index 5a3b33a..0000000 --- a/gnu/usr.sbin/ypserv/yp.h +++ /dev/null @@ -1,611 +0,0 @@ -/* - * And thus spoke RPCGEN: - * Please do not edit this file. - * It was generated using rpcgen. - * - * And thus replied Lpd@NannyMUD: - * Who cares? :-) /Peter Eriksson - * - * - * Modification history: - * 940716 pen@signum.se Change "ypreq_key" to "ypreq_nokey" for FIRST. - * - * $Id: yp.h,v 1.1 1995/01/31 08:58:55 wpaul Exp $ - */ - -#ifndef _YP_H_RPCGEN -#define _YP_H_RPCGEN - -#include -#ifdef NEED_SVCSOC_H -#include -#endif - -#define YPMAXRECORD 1024 -#define YPMAXDOMAIN 64 -#define YPMAXMAP 64 -#define YPMAXPEER 64 - -enum ypstat { - YP_TRUE = 1, - YP_NOMORE = 2, - YP_FALSE = 0, - YP_NOMAP = -1, - YP_NODOM = -2, - YP_NOKEY = -3, - YP_BADOP = -4, - YP_BADDB = -5, - YP_YPERR = -6, - YP_BADARGS = -7, - YP_VERS = -8 -}; -typedef enum ypstat ypstat; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypstat(XDR *, ypstat*); -#elif __STDC__ -extern bool_t __xdr_ypstat(XDR *, ypstat*); -#else /* Old Style C */ -bool_t __xdr_ypstat(); -#endif /* Old Style C */ - - -enum ypxfrstat { - YPXFR_SUCC = 1, - YPXFR_AGE = 2, - YPXFR_NOMAP = -1, - YPXFR_NODOM = -2, - YPXFR_RSRC = -3, - YPXFR_RPC = -4, - YPXFR_MADDR = -5, - YPXFR_YPERR = -6, - YPXFR_BADARGS = -7, - YPXFR_DBM = -8, - YPXFR_FILE = -9, - YPXFR_SKEW = -10, - YPXFR_CLEAR = -11, - YPXFR_FORCE = -12, - YPXFR_XFRERR = -13, - YPXFR_REFUSED = -14 -}; -typedef enum ypxfrstat ypxfrstat; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypxfrstat(XDR *, ypxfrstat*); -#elif __STDC__ -extern bool_t __xdr_ypxfrstat(XDR *, ypxfrstat*); -#else /* Old Style C */ -bool_t __xdr_ypxfrstat(); -#endif /* Old Style C */ - - -typedef char *domainname; -#ifdef __cplusplus -extern "C" bool_t __xdr_domainname(XDR *, domainname*); -#elif __STDC__ -extern bool_t __xdr_domainname(XDR *, domainname*); -#else /* Old Style C */ -bool_t __xdr_domainname(); -#endif /* Old Style C */ - - -typedef char *mapname; -#ifdef __cplusplus -extern "C" bool_t __xdr_mapname(XDR *, mapname*); -#elif __STDC__ -extern bool_t __xdr_mapname(XDR *, mapname*); -#else /* Old Style C */ -bool_t __xdr_mapname(); -#endif /* Old Style C */ - - -typedef char *peername; -#ifdef __cplusplus -extern "C" bool_t __xdr_peername(XDR *, peername*); -#elif __STDC__ -extern bool_t __xdr_peername(XDR *, peername*); -#else /* Old Style C */ -bool_t __xdr_peername(); -#endif /* Old Style C */ - - -typedef struct { - u_int keydat_len; - char *keydat_val; -} keydat; -#ifdef __cplusplus -extern "C" bool_t __xdr_keydat(XDR *, keydat*); -#elif __STDC__ -extern bool_t __xdr_keydat(XDR *, keydat*); -#else /* Old Style C */ -bool_t __xdr_keydat(); -#endif /* Old Style C */ - - -typedef struct { - u_int valdat_len; - char *valdat_val; -} valdat; -#ifdef __cplusplus -extern "C" bool_t __xdr_valdat(XDR *, valdat*); -#elif __STDC__ -extern bool_t __xdr_valdat(XDR *, valdat*); -#else /* Old Style C */ -bool_t __xdr_valdat(); -#endif /* Old Style C */ - - -struct ypmap_parms { - domainname domain; - mapname map; - u_int ordernum; - peername peer; -}; -typedef struct ypmap_parms ypmap_parms; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypmap_parms(XDR *, ypmap_parms*); -#elif __STDC__ -extern bool_t __xdr_ypmap_parms(XDR *, ypmap_parms*); -#else /* Old Style C */ -bool_t __xdr_ypmap_parms(); -#endif /* Old Style C */ - - -struct ypreq_key { - domainname domain; - mapname map; - keydat key; -}; -typedef struct ypreq_key ypreq_key; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypreq_key(XDR *, ypreq_key*); -#elif __STDC__ -extern bool_t __xdr_ypreq_key(XDR *, ypreq_key*); -#else /* Old Style C */ -bool_t __xdr_ypreq_key(); -#endif /* Old Style C */ - - -struct ypreq_nokey { - domainname domain; - mapname map; -}; -typedef struct ypreq_nokey ypreq_nokey; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypreq_nokey(XDR *, ypreq_nokey*); -#elif __STDC__ -extern bool_t __xdr_ypreq_nokey(XDR *, ypreq_nokey*); -#else /* Old Style C */ -bool_t __xdr_ypreq_nokey(); -#endif /* Old Style C */ - - -struct ypreq_xfr { - ypmap_parms map_parms; - u_int transid; - u_int prog; - u_int port; -}; -typedef struct ypreq_xfr ypreq_xfr; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypreq_xfr(XDR *, ypreq_xfr*); -#elif __STDC__ -extern bool_t __xdr_ypreq_xfr(XDR *, ypreq_xfr*); -#else /* Old Style C */ -bool_t __xdr_ypreq_xfr(); -#endif /* Old Style C */ - - -struct ypresp_val { - ypstat stat; - valdat val; -}; -typedef struct ypresp_val ypresp_val; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypresp_val(XDR *, ypresp_val*); -#elif __STDC__ -extern bool_t __xdr_ypresp_val(XDR *, ypresp_val*); -#else /* Old Style C */ -bool_t __xdr_ypresp_val(); -#endif /* Old Style C */ - - -struct ypresp_key_val { - ypstat stat; - keydat key; - valdat val; -}; -typedef struct ypresp_key_val ypresp_key_val; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypresp_key_val(XDR *, ypresp_key_val*); -#elif __STDC__ -extern bool_t __xdr_ypresp_key_val(XDR *, ypresp_key_val*); -#else /* Old Style C */ -bool_t __xdr_ypresp_key_val(); -#endif /* Old Style C */ - - -struct ypresp_master { - ypstat stat; - peername peer; -}; -typedef struct ypresp_master ypresp_master; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypresp_master(XDR *, ypresp_master*); -#elif __STDC__ -extern bool_t __xdr_ypresp_master(XDR *, ypresp_master*); -#else /* Old Style C */ -bool_t __xdr_ypresp_master(); -#endif /* Old Style C */ - - -struct ypresp_order { - ypstat stat; - u_int ordernum; -}; -typedef struct ypresp_order ypresp_order; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypresp_order(XDR *, ypresp_order*); -#elif __STDC__ -extern bool_t __xdr_ypresp_order(XDR *, ypresp_order*); -#else /* Old Style C */ -bool_t __xdr_ypresp_order(); -#endif /* Old Style C */ - - -typedef struct -{ - struct - { - int (*encode)(ypresp_key_val *val, void *data); - int (*close)(void *data); - } u; - void *data; -} __xdr_ypall_cb_t; - - -struct ypresp_all { - bool_t more; - union { - ypresp_key_val val; - } ypresp_all_u; -}; -typedef struct ypresp_all ypresp_all; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypresp_all(XDR *, ypresp_all*); -#elif __STDC__ -extern bool_t __xdr_ypresp_all(XDR *, ypresp_all*); -#else /* Old Style C */ -bool_t __xdr_ypresp_all(); -#endif /* Old Style C */ - - -struct ypresp_xfr { - u_int transid; - ypxfrstat xfrstat; -}; -typedef struct ypresp_xfr ypresp_xfr; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypresp_xfr(XDR *, ypresp_xfr*); -#elif __STDC__ -extern bool_t __xdr_ypresp_xfr(XDR *, ypresp_xfr*); -#else /* Old Style C */ -bool_t __xdr_ypresp_xfr(); -#endif /* Old Style C */ - - -struct ypmaplist { - mapname map; - struct ypmaplist *next; -}; -typedef struct ypmaplist ypmaplist; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypmaplist(XDR *, ypmaplist*); -#elif __STDC__ -extern bool_t __xdr_ypmaplist(XDR *, ypmaplist*); -#else /* Old Style C */ -bool_t __xdr_ypmaplist(); -#endif /* Old Style C */ - - -struct ypresp_maplist { - ypstat stat; - ypmaplist *maps; -}; -typedef struct ypresp_maplist ypresp_maplist; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypresp_maplist(XDR *, ypresp_maplist*); -#elif __STDC__ -extern bool_t __xdr_ypresp_maplist(XDR *, ypresp_maplist*); -#else /* Old Style C */ -bool_t __xdr_ypresp_maplist(); -#endif /* Old Style C */ - - -enum yppush_status { - YPPUSH_SUCC = 1, - YPPUSH_AGE = 2, - YPPUSH_NOMAP = -1, - YPPUSH_NODOM = -2, - YPPUSH_RSRC = -3, - YPPUSH_RPC = -4, - YPPUSH_MADDR = -5, - YPPUSH_YPERR = -6, - YPPUSH_BADARGS = -7, - YPPUSH_DBM = -8, - YPPUSH_FILE = -9, - YPPUSH_SKEW = -10, - YPPUSH_CLEAR = -11, - YPPUSH_FORCE = -12, - YPPUSH_XFRERR = -13, - YPPUSH_REFUSED = -14 -}; -typedef enum yppush_status yppush_status; -#ifdef __cplusplus -extern "C" bool_t __xdr_yppush_status(XDR *, yppush_status*); -#elif __STDC__ -extern bool_t __xdr_yppush_status(XDR *, yppush_status*); -#else /* Old Style C */ -bool_t __xdr_yppush_status(); -#endif /* Old Style C */ - - -struct yppushresp_xfr { - u_int transid; - yppush_status status; -}; -typedef struct yppushresp_xfr yppushresp_xfr; -#ifdef __cplusplus -extern "C" bool_t __xdr_yppushresp_xfr(XDR *, yppushresp_xfr*); -#elif __STDC__ -extern bool_t __xdr_yppushresp_xfr(XDR *, yppushresp_xfr*); -#else /* Old Style C */ -bool_t __xdr_yppushresp_xfr(); -#endif /* Old Style C */ - - -enum ypbind_resptype { - YPBIND_SUCC_VAL = 1, - YPBIND_FAIL_VAL = 2 -}; -typedef enum ypbind_resptype ypbind_resptype; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypbind_resptype(XDR *, ypbind_resptype*); -#elif __STDC__ -extern bool_t __xdr_ypbind_resptype(XDR *, ypbind_resptype*); -#else /* Old Style C */ -bool_t __xdr_ypbind_resptype(); -#endif /* Old Style C */ - - -struct ypbind_binding { - char ypbind_binding_addr[4]; - char ypbind_binding_port[2]; -}; -typedef struct ypbind_binding ypbind_binding; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypbind_binding(XDR *, ypbind_binding*); -#elif __STDC__ -extern bool_t __xdr_ypbind_binding(XDR *, ypbind_binding*); -#else /* Old Style C */ -bool_t __xdr_ypbind_binding(); -#endif /* Old Style C */ - - -struct ypbind_resp { - ypbind_resptype ypbind_status; - union { - u_int ypbind_error; - ypbind_binding ypbind_bindinfo; - } ypbind_resp_u; -}; -typedef struct ypbind_resp ypbind_resp; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypbind_resp(XDR *, ypbind_resp*); -#elif __STDC__ -extern bool_t __xdr_ypbind_resp(XDR *, ypbind_resp*); -#else /* Old Style C */ -bool_t __xdr_ypbind_resp(); -#endif /* Old Style C */ - -#define YPBIND_ERR_ERR 1 -#define YPBIND_ERR_NOSERV 2 -#define YPBIND_ERR_RESC 3 - -struct ypbind_setdom { - domainname ypsetdom_domain; - ypbind_binding ypsetdom_binding; - u_int ypsetdom_vers; -}; -typedef struct ypbind_setdom ypbind_setdom; -#ifdef __cplusplus -extern "C" bool_t __xdr_ypbind_setdom(XDR *, ypbind_setdom*); -#elif __STDC__ -extern bool_t __xdr_ypbind_setdom(XDR *, ypbind_setdom*); -#else /* Old Style C */ -bool_t __xdr_ypbind_setdom(); -#endif /* Old Style C */ - - -#define YPPROG ((u_long)100004) -#define YPVERS ((u_long)2) - -#ifdef __cplusplus -#define YPPROC_NULL ((u_long)0) -extern "C" void * ypproc_null_2(void *, CLIENT *); -extern "C" void * ypproc_null_2_svc(void *, struct svc_req *); -#define YPPROC_DOMAIN ((u_long)1) -extern "C" bool_t * ypproc_domain_2(domainname *, CLIENT *); -extern "C" bool_t * ypproc_domain_2_svc(domainname *, struct svc_req *); -#define YPPROC_DOMAIN_NONACK ((u_long)2) -extern "C" bool_t * ypproc_domain_nonack_2(domainname *, CLIENT *); -extern "C" bool_t * ypproc_domain_nonack_2_svc(domainname *, struct svc_req *); -#define YPPROC_MATCH ((u_long)3) -extern "C" ypresp_val * ypproc_match_2(ypreq_key *, CLIENT *); -extern "C" ypresp_val * ypproc_match_2_svc(ypreq_key *, struct svc_req *); -#define YPPROC_FIRST ((u_long)4) -extern "C" ypresp_key_val * ypproc_first_2(ypreq_nokey *, CLIENT *); -extern "C" ypresp_key_val * ypproc_first_2_svc(ypreq_nokey *, struct svc_req *); -#define YPPROC_NEXT ((u_long)5) -extern "C" ypresp_key_val * ypproc_next_2(ypreq_key *, CLIENT *); -extern "C" ypresp_key_val * ypproc_next_2_svc(ypreq_key *, struct svc_req *); -#define YPPROC_XFR ((u_long)6) -extern "C" ypresp_xfr * ypproc_xfr_2(ypreq_xfr *, CLIENT *); -extern "C" ypresp_xfr * ypproc_xfr_2_svc(ypreq_xfr *, struct svc_req *); -#define YPPROC_CLEAR ((u_long)7) -extern "C" void * ypproc_clear_2(void *, CLIENT *); -extern "C" void * ypproc_clear_2_svc(void *, struct svc_req *); -#define YPPROC_ALL ((u_long)8) -extern "C" ypresp_all * ypproc_all_2(ypreq_nokey *, CLIENT *); -extern "C" ypresp_all * ypproc_all_2_svc(ypreq_nokey *, struct svc_req *); -#define YPPROC_MASTER ((u_long)9) -extern "C" ypresp_master * ypproc_master_2(ypreq_nokey *, CLIENT *); -extern "C" ypresp_master * ypproc_master_2_svc(ypreq_nokey *, struct svc_req *); -#define YPPROC_ORDER ((u_long)10) -extern "C" ypresp_order * ypproc_order_2(ypreq_nokey *, CLIENT *); -extern "C" ypresp_order * ypproc_order_2_svc(ypreq_nokey *, struct svc_req *); -#define YPPROC_MAPLIST ((u_long)11) -extern "C" ypresp_maplist * ypproc_maplist_2(domainname *, CLIENT *); -extern "C" ypresp_maplist * ypproc_maplist_2_svc(domainname *, struct svc_req *); - -#elif __STDC__ -#define YPPROC_NULL ((u_long)0) -extern void * ypproc_null_2(void *, CLIENT *); -extern void * ypproc_null_2_svc(void *, struct svc_req *); -#define YPPROC_DOMAIN ((u_long)1) -extern bool_t * ypproc_domain_2(domainname *, CLIENT *); -extern bool_t * ypproc_domain_2_svc(domainname *, struct svc_req *); -#define YPPROC_DOMAIN_NONACK ((u_long)2) -extern bool_t * ypproc_domain_nonack_2(domainname *, CLIENT *); -extern bool_t * ypproc_domain_nonack_2_svc(domainname *, struct svc_req *); -#define YPPROC_MATCH ((u_long)3) -extern ypresp_val * ypproc_match_2(ypreq_key *, CLIENT *); -extern ypresp_val * ypproc_match_2_svc(ypreq_key *, struct svc_req *); -#define YPPROC_FIRST ((u_long)4) -extern ypresp_key_val * ypproc_first_2(ypreq_nokey *, CLIENT *); -extern ypresp_key_val * ypproc_first_2_svc(ypreq_nokey *, struct svc_req *); -#define YPPROC_NEXT ((u_long)5) -extern ypresp_key_val * ypproc_next_2(ypreq_key *, CLIENT *); -extern ypresp_key_val * ypproc_next_2_svc(ypreq_key *, struct svc_req *); -#define YPPROC_XFR ((u_long)6) -extern ypresp_xfr * ypproc_xfr_2(ypreq_xfr *, CLIENT *); -extern ypresp_xfr * ypproc_xfr_2_svc(ypreq_xfr *, struct svc_req *); -#define YPPROC_CLEAR ((u_long)7) -extern void * ypproc_clear_2(void *, CLIENT *); -extern void * ypproc_clear_2_svc(void *, struct svc_req *); -#define YPPROC_ALL ((u_long)8) -extern ypresp_all * ypproc_all_2(ypreq_nokey *, CLIENT *); -extern ypresp_all * ypproc_all_2_svc(ypreq_nokey *, struct svc_req *); -#define YPPROC_MASTER ((u_long)9) -extern ypresp_master * ypproc_master_2(ypreq_nokey *, CLIENT *); -extern ypresp_master * ypproc_master_2_svc(ypreq_nokey *, struct svc_req *); -#define YPPROC_ORDER ((u_long)10) -extern ypresp_order * ypproc_order_2(ypreq_nokey *, CLIENT *); -extern ypresp_order * ypproc_order_2_svc(ypreq_nokey *, struct svc_req *); -#define YPPROC_MAPLIST ((u_long)11) -extern ypresp_maplist * ypproc_maplist_2(domainname *, CLIENT *); -extern ypresp_maplist * ypproc_maplist_2_svc(domainname *, struct svc_req *); - -#else /* Old Style C */ -#define YPPROC_NULL ((u_long)0) -extern void * ypproc_null_2(); -extern void * ypproc_null_2_svc(); -#define YPPROC_DOMAIN ((u_long)1) -extern bool_t * ypproc_domain_2(); -extern bool_t * ypproc_domain_2_svc(); -#define YPPROC_DOMAIN_NONACK ((u_long)2) -extern bool_t * ypproc_domain_nonack_2(); -extern bool_t * ypproc_domain_nonack_2_svc(); -#define YPPROC_MATCH ((u_long)3) -extern ypresp_val * ypproc_match_2(); -extern ypresp_val * ypproc_match_2_svc(); -#define YPPROC_FIRST ((u_long)4) -extern ypresp_key_val * ypproc_first_2(); -extern ypresp_key_val * ypproc_first_2_svc(); -#define YPPROC_NEXT ((u_long)5) -extern ypresp_key_val * ypproc_next_2(); -extern ypresp_key_val * ypproc_next_2_svc(); -#define YPPROC_XFR ((u_long)6) -extern ypresp_xfr * ypproc_xfr_2(); -extern ypresp_xfr * ypproc_xfr_2_svc(); -#define YPPROC_CLEAR ((u_long)7) -extern void * ypproc_clear_2(); -extern void * ypproc_clear_2_svc(); -#define YPPROC_ALL ((u_long)8) -extern ypresp_all * ypproc_all_2(); -extern ypresp_all * ypproc_all_2_svc(); -#define YPPROC_MASTER ((u_long)9) -extern ypresp_master * ypproc_master_2(); -extern ypresp_master * ypproc_master_2_svc(); -#define YPPROC_ORDER ((u_long)10) -extern ypresp_order * ypproc_order_2(); -extern ypresp_order * ypproc_order_2_svc(); -#define YPPROC_MAPLIST ((u_long)11) -extern ypresp_maplist * ypproc_maplist_2(); -extern ypresp_maplist * ypproc_maplist_2_svc(); -#endif /* Old Style C */ - -#define YPPUSH_XFRRESPPROG ((u_long)0x40000000) -#define YPPUSH_XFRRESPVERS ((u_long)1) - -#ifdef __cplusplus -#define YPPUSHPROC_NULL ((u_long)0) -extern "C" void * yppushproc_null_1(void *, CLIENT *); -extern "C" void * yppushproc_null_1_svc(void *, struct svc_req *); -#define YPPUSHPROC_XFRRESP ((u_long)1) -extern "C" yppushresp_xfr * yppushproc_xfrresp_1(void *, CLIENT *); -extern "C" yppushresp_xfr * yppushproc_xfrresp_1_svc(void *, struct svc_req *); - -#elif __STDC__ -#define YPPUSHPROC_NULL ((u_long)0) -extern void * yppushproc_null_1(void *, CLIENT *); -extern void * yppushproc_null_1_svc(void *, struct svc_req *); -#define YPPUSHPROC_XFRRESP ((u_long)1) -extern yppushresp_xfr * yppushproc_xfrresp_1(void *, CLIENT *); -extern yppushresp_xfr * yppushproc_xfrresp_1_svc(void *, struct svc_req *); - -#else /* Old Style C */ -#define YPPUSHPROC_NULL ((u_long)0) -extern void * yppushproc_null_1(); -extern void * yppushproc_null_1_svc(); -#define YPPUSHPROC_XFRRESP ((u_long)1) -extern yppushresp_xfr * yppushproc_xfrresp_1(); -extern yppushresp_xfr * yppushproc_xfrresp_1_svc(); -#endif /* Old Style C */ - -#define YPBINDPROG ((u_long)100007) -#define YPBINDVERS ((u_long)2) - -#ifdef __cplusplus -#define YPBINDPROC_NULL ((u_long)0) -extern "C" void * ypbindproc_null_2(void *, CLIENT *); -extern "C" void * ypbindproc_null_2_svc(void *, struct svc_req *); -#define YPBINDPROC_DOMAIN ((u_long)1) -extern "C" ypbind_resp * ypbindproc_domain_2(domainname *, CLIENT *); -extern "C" ypbind_resp * ypbindproc_domain_2_svc(domainname *, struct svc_req *); -#define YPBINDPROC_SETDOM ((u_long)2) -extern "C" void * ypbindproc_setdom_2(ypbind_setdom *, CLIENT *); -extern "C" void * ypbindproc_setdom_2_svc(ypbind_setdom *, struct svc_req *); - -#elif __STDC__ -#define YPBINDPROC_NULL ((u_long)0) -extern void * ypbindproc_null_2(void *, CLIENT *); -extern void * ypbindproc_null_2_svc(void *, struct svc_req *); -#define YPBINDPROC_DOMAIN ((u_long)1) -extern ypbind_resp * ypbindproc_domain_2(domainname *, CLIENT *); -extern ypbind_resp * ypbindproc_domain_2_svc(domainname *, struct svc_req *); -#define YPBINDPROC_SETDOM ((u_long)2) -extern void * ypbindproc_setdom_2(ypbind_setdom *, CLIENT *); -extern void * ypbindproc_setdom_2_svc(ypbind_setdom *, struct svc_req *); - -#else /* Old Style C */ -#define YPBINDPROC_NULL ((u_long)0) -extern void * ypbindproc_null_2(); -extern void * ypbindproc_null_2_svc(); -#define YPBINDPROC_DOMAIN ((u_long)1) -extern ypbind_resp * ypbindproc_domain_2(); -extern ypbind_resp * ypbindproc_domain_2_svc(); -#define YPBINDPROC_SETDOM ((u_long)2) -extern void * ypbindproc_setdom_2(); -extern void * ypbindproc_setdom_2_svc(); -#endif /* Old Style C */ - -#endif /* !_YP_H_RPCGEN */ diff --git a/gnu/usr.sbin/ypserv/yp_svc.c b/gnu/usr.sbin/ypserv/yp_svc.c deleted file mode 100644 index 739a0e3..0000000 --- a/gnu/usr.sbin/ypserv/yp_svc.c +++ /dev/null @@ -1,430 +0,0 @@ -/* - * And thus spoke RPCGEN: - * Please do not edit this file. - * It was generated using rpcgen. - * - * And thus replied Lpd@NannyMUD: - * Who cares? :-) /Peter Eriksson - * - * $Id: yp_svc.c,v 1.5 1995/07/08 21:42:59 ats Exp $ - */ - -#include "system.h" - -#include "yp.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern int errno; -extern void Perror __P((char *, ...)); -extern void my_svc_run __P((void)); -extern void reapchild __P((int)); - -#ifdef __STDC__ -#define SIG_PF void(*)(int) -#endif - -static void -ypprog_2(struct svc_req *rqstp, register SVCXPRT *transp) -{ - union { - domainname ypproc_domain_2_arg; - domainname ypproc_domain_nonack_2_arg; - ypreq_key ypproc_match_2_arg; - ypreq_key ypproc_first_2_arg; - ypreq_key ypproc_next_2_arg; - ypreq_xfr ypproc_xfr_2_arg; - ypreq_nokey ypproc_all_2_arg; - ypreq_nokey ypproc_master_2_arg; - ypreq_nokey ypproc_order_2_arg; - domainname ypproc_maplist_2_arg; - } argument; - char *result; - xdrproc_t __xdr_argument, __xdr_result; - char *(*local)(char *, struct svc_req *); - - switch (rqstp->rq_proc) { - case YPPROC_NULL: - __xdr_argument = (xdrproc_t) xdr_void; - __xdr_result = (xdrproc_t) xdr_void; - local = (char *(*)(char *, struct svc_req *)) ypproc_null_2_svc; - break; - - case YPPROC_DOMAIN: - __xdr_argument = (xdrproc_t) __xdr_domainname; - __xdr_result = (xdrproc_t) xdr_bool; - local = (char *(*)(char *, struct svc_req *)) ypproc_domain_2_svc; - break; - - case YPPROC_DOMAIN_NONACK: - __xdr_argument = (xdrproc_t) __xdr_domainname; - __xdr_result = (xdrproc_t) xdr_bool; - local = (char *(*)(char *, struct svc_req *)) ypproc_domain_nonack_2_svc; - break; - - case YPPROC_MATCH: - __xdr_argument = (xdrproc_t) __xdr_ypreq_key; - __xdr_result = (xdrproc_t) __xdr_ypresp_val; - local = (char *(*)(char *, struct svc_req *)) ypproc_match_2_svc; - break; - - case YPPROC_FIRST: -#if 0 /* Bug in Sun's yp.x RPC prototype file */ - __xdr_argument = (xdrproc_t) __xdr_ypreq_key; -#else - __xdr_argument = (xdrproc_t) __xdr_ypreq_nokey; -#endif - __xdr_result = (xdrproc_t) __xdr_ypresp_key_val; - local = (char *(*)(char *, struct svc_req *)) ypproc_first_2_svc; - break; - - case YPPROC_NEXT: - __xdr_argument = (xdrproc_t) __xdr_ypreq_key; - __xdr_result = (xdrproc_t) __xdr_ypresp_key_val; - local = (char *(*)(char *, struct svc_req *)) ypproc_next_2_svc; - break; - - case YPPROC_XFR: - __xdr_argument = (xdrproc_t) __xdr_ypreq_xfr; - __xdr_result = (xdrproc_t) __xdr_ypresp_xfr; - local = (char *(*)(char *, struct svc_req *)) ypproc_xfr_2_svc; - break; - - case YPPROC_CLEAR: - __xdr_argument = (xdrproc_t) xdr_void; - __xdr_result = (xdrproc_t) xdr_void; - local = (char *(*)(char *, struct svc_req *)) ypproc_clear_2_svc; - break; - - case YPPROC_ALL: - __xdr_argument = (xdrproc_t) __xdr_ypreq_nokey; - __xdr_result = (xdrproc_t) __xdr_ypresp_all; - local = (char *(*)(char *, struct svc_req *)) ypproc_all_2_svc; - break; - - case YPPROC_MASTER: - __xdr_argument = (xdrproc_t) __xdr_ypreq_nokey; - __xdr_result = (xdrproc_t) __xdr_ypresp_master; - local = (char *(*)(char *, struct svc_req *)) ypproc_master_2_svc; - break; - - case YPPROC_ORDER: - __xdr_argument = (xdrproc_t) __xdr_ypreq_nokey; - __xdr_result = (xdrproc_t) __xdr_ypresp_order; - local = (char *(*)(char *, struct svc_req *)) ypproc_order_2_svc; - break; - - case YPPROC_MAPLIST: - __xdr_argument = (xdrproc_t) __xdr_domainname; - __xdr_result = (xdrproc_t) __xdr_ypresp_maplist; - local = (char *(*)(char *, struct svc_req *)) ypproc_maplist_2_svc; - break; - - default: - svcerr_noproc(transp); - return; - } - (void) memset((char *)&argument, 0, sizeof (argument)); - if (!svc_getargs(transp, __xdr_argument, (caddr_t) &argument)) { - svcerr_decode(transp); - return; - } - result = (*local)((char *)&argument, rqstp); - if (result != NULL && !svc_sendreply(transp, __xdr_result, result)) { - svcerr_systemerr(transp); - } - if (!svc_freeargs(transp, __xdr_argument, (caddr_t) &argument)) { - fprintf(stderr, "unable to free arguments"); - exit(1); - } - return; -} - -#if 0 -static void -yppush_xfrrespprog_1(struct svc_req *rqstp, register SVCXPRT *transp) -{ - union { - int fill; - } argument; - char *result; - xdrproc_t __xdr_argument, __xdr_result; - char *(*local)(char *, struct svc_req *); - - switch (rqstp->rq_proc) { - case YPPUSHPROC_NULL: - __xdr_argument = (xdrproc_t) xdr_void; - __xdr_result = (xdrproc_t) xdr_void; - local = (char *(*)(char *, struct svc_req *)) yppushproc_null_1_svc; - break; - - case YPPUSHPROC_XFRRESP: - __xdr_argument = (xdrproc_t) xdr_void; - __xdr_result = (xdrproc_t) __xdr_yppushresp_xfr; - local = (char *(*)(char *, struct svc_req *)) yppushproc_xfrresp_1_svc; - break; - - default: - svcerr_noproc(transp); - return; - } - (void) memset((char *)&argument, 0, sizeof (argument)); - if (!svc_getargs(transp, __xdr_argument, (caddr_t) &argument)) { - svcerr_decode(transp); - return; - } - result = (*local)((char *)&argument, rqstp); - if (result != NULL && !svc_sendreply(transp, __xdr_result, result)) { - svcerr_systemerr(transp); - } - if (!svc_freeargs(transp, __xdr_argument, (caddr_t) &argument)) { - fprintf(stderr, "unable to free arguments"); - exit(1); - } - return; -} - -static void -ypbindprog_2(struct svc_req *rqstp, register SVCXPRT *transp) -{ - union { - domainname ypbindproc_domain_2_arg; - ypbind_setdom ypbindproc_setdom_2_arg; - } argument; - char *result; - xdrproc_t __xdr_argument, __xdr_result; - char *(*local)(char *, struct svc_req *); - - switch (rqstp->rq_proc) { - case YPBINDPROC_NULL: - __xdr_argument = (xdrproc_t) xdr_void; - __xdr_result = (xdrproc_t) xdr_void; - local = (char *(*)(char *, struct svc_req *)) ypbindproc_null_2_svc; - break; - - case YPBINDPROC_DOMAIN: - __xdr_argument = (xdrproc_t) __xdr_domainname; - __xdr_result = (xdrproc_t) __xdr_ypbind_resp; - local = (char *(*)(char *, struct svc_req *)) ypbindproc_domain_2_svc; - break; - - case YPBINDPROC_SETDOM: - __xdr_argument = (xdrproc_t) __xdr_ypbind_setdom; - __xdr_result = (xdrproc_t) xdr_void; - local = (char *(*)(char *, struct svc_req *)) ypbindproc_setdom_2_svc; - break; - - default: - svcerr_noproc(transp); - return; - } - (void) memset((char *)&argument, 0, sizeof (argument)); - if (!svc_getargs(transp, __xdr_argument, (caddr_t) &argument)) { - svcerr_decode(transp); - return; - } - result = (*local)((char *)&argument, rqstp); - if (result != NULL && !svc_sendreply(transp, __xdr_result, result)) { - svcerr_systemerr(transp); - } - if (!svc_freeargs(transp, __xdr_argument, (caddr_t) &argument)) { - fprintf(stderr, "unable to free arguments"); - exit(1); - } - return; -} -#endif - -extern int debug_flag; -extern int dns_flag; - -#ifndef _PATH_YP -#define _PATH_YP "/var/yp" -#endif -char *path_ypdb = _PATH_YP; - -char *progname; - - -int main(int argc, char **argv) -{ - register SVCXPRT *transp; - int i; - int my_port = -1; - int my_socket; - struct sockaddr_in socket_address; - int result; - int sunos_4_kludge = 0; - struct sigaction sa; - - progname = strrchr (argv[0], '/'); - if (progname == (char *) NULL) - progname = argv[0]; - else - progname++; - - openlog(progname, LOG_PID, TCPW_FACILITY); - - for (i = 1; i < argc && argv[i][0] == '-'; i++) - { - if (strcmp(argv[i], "-debug") == 0 || strcmp(argv[i], "-d") == 0) - debug_flag = 1; - else if (strcmp(argv[i], "-dns") == 0 || strcmp(argv[i], "-b") == 0) - dns_flag = 1; - else if ((argv[i][1] == 'p') && (argv[i][2] >= '0') && (argv[i][2] <= '9')) - my_port = atoi(argv[i] + 2); - else if (strcmp(argv[i], "-k") == 0) - sunos_4_kludge = 1; - else - { - fprintf(stderr, "%s: Unknown command line switch: %s\n", - progname, - argv[i]); - exit(1); - } - } - - if (!debug_flag) - if(daemon(0,0)) - { - perror("daemon()"); - exit (1); - } - - if (debug_flag) - Perror("[Welcome to the NYS YP Server, version 0.13]\n"); - - if (i < argc) - { - path_ypdb = argv[i]; - if (debug_flag) - Perror("Using database directory: %s\n", path_ypdb); - } - - /* Change current directory to database location */ - if (chdir(path_ypdb) < 0) - { - Perror("%s: chdir: %", argv[0], strerror(errno)); - exit(1); - } - - /* - * Ignore SIGPIPEs. They can hurt us if someone does a ypcat - * and then hits CTRL-C before it terminates. - */ - sigaction(SIGPIPE, NULL, &sa); - sa.sa_handler = SIG_IGN; - sa.sa_flags |= SA_RESTART; - sigemptyset(&sa.sa_mask); - sigaction(SIGPIPE, &sa, NULL); - sigaction(SIGCHLD, NULL, &sa); - sa.sa_flags |= SA_RESTART; - sa.sa_handler = reapchild; - sigemptyset(&sa.sa_mask); - sigaction(SIGCHLD, &sa, NULL); - - (void) pmap_unset(YPPROG, YPVERS); - if (sunos_4_kludge) - (void) pmap_unset(YPPROG, 1); - - if (my_port >= 0) - { - my_socket = socket (AF_INET, SOCK_DGRAM, 0); - if (my_socket < 0) - { - Perror("%s: can not create UDP: %s", - progname, strerror(errno)); - exit (1); - } - - socket_address.sin_family = AF_INET; - socket_address.sin_addr.s_addr = htonl (INADDR_ANY); - socket_address.sin_port = htons (my_port); - - result = bind (my_socket, (struct sockaddr *) &socket_address, - sizeof (socket_address)); - if (result < 0) - { - Perror("%s: can not create UDP: %s", - progname, strerror(errno)); - exit (1); - } - } - else - my_socket = RPC_ANYSOCK; - - transp = svcudp_create(my_socket); - if (transp == NULL) { - Perror("cannot create udp service."); - exit(1); - } - if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, IPPROTO_UDP)) { - Perror("unable to register (YPPROG, YPVERS, udp)."); - exit(1); - } - - if (sunos_4_kludge) { - /* - ** This is just to make us reply to YP version 1 calls which SunOS 4's - ** ypbind seems to insist on finding. If someone _really_ tries to - ** use this the they will probably be bitten - _hard_, since I haven't - ** got the faintest idea on how the XDR calls for YP version 1 should - ** look like. The Domain_NoNack call seems to be compatible though :-) - */ - if (!svc_register(transp, YPPROG, 1, ypprog_2, IPPROTO_UDP)) { - fprintf(stderr, "unable to register (YPPROG, 1, udp)."); - exit(1); - } - } - - if (my_port >= 0) - { - my_socket = socket (AF_INET, SOCK_STREAM, 0); - if (my_socket < 0) - { - Perror("%s: can not create TCP: %s", - progname, strerror(errno)); - exit (1); - } - - socket_address.sin_family = AF_INET; - socket_address.sin_addr.s_addr = htonl (INADDR_ANY); - socket_address.sin_port = htons (my_port); - - result = bind (my_socket, (struct sockaddr *) &socket_address, - sizeof (socket_address)); - if (result < 0) - { - Perror("%s: can not create TCP: %s", - progname, strerror(errno)); - exit (1); - } - } - else - my_socket = RPC_ANYSOCK; - - transp = svctcp_create(my_socket, 0, 0); - if (transp == NULL) { - Perror("%s: cannot create tcp service\n", progname); - exit(1); - } - if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, IPPROTO_TCP)) { - Perror("%s: unable to register (YPPROG, YPVERS, tcp)\n", progname); - exit(1); - } - - my_svc_run(); - Perror("svc_run returned"); - exit(1); - /* NOTREACHED */ -} diff --git a/gnu/usr.sbin/ypserv/yp_xdr.c b/gnu/usr.sbin/ypserv/yp_xdr.c deleted file mode 100644 index 9e88645..0000000 --- a/gnu/usr.sbin/ypserv/yp_xdr.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - * And thus spoke RPCGEN: - * Please do not edit this file. - * It was generated using rpcgen. - * - * And thus replied Lpd@NannyMUD: - * Who cares? :-) /Peter Eriksson - * - * - * Modification history: - * 940616 pen@signum.se Major cleanups. - * 940713 pen@signum.se Added SunOS 4 prototypes. - * - * $Id: yp_xdr.c,v 1.1 1995/01/31 08:58:57 wpaul Exp $ - */ - -#include "system.h" - - -#include "yp.h" - -#ifndef NULL -#define NULL 0 -#endif - -__xdr_ypall_cb_t __xdr_ypall_cb; - -bool_t -__xdr_ypstat(XDR *xdrs, ypstat *objp) -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypxfrstat(XDR *xdrs, ypxfrstat *objp) -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_domainname(XDR *xdrs, domainname *objp) -{ - if (!xdr_string(xdrs, objp, YPMAXDOMAIN)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_mapname(XDR *xdrs, mapname *objp) -{ - if (!xdr_string(xdrs, objp, YPMAXMAP)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_peername(XDR *xdrs, peername *objp) -{ - if (!xdr_string(xdrs, objp, YPMAXPEER)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_keydat(XDR *xdrs, keydat *objp) -{ - if (!xdr_bytes(xdrs, (char **)&objp->keydat_val, - (u_int *)&objp->keydat_len, YPMAXRECORD)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_valdat(XDR *xdrs, valdat *objp) -{ - if (!xdr_bytes(xdrs, (char **)&objp->valdat_val, - (u_int *)&objp->valdat_len, YPMAXRECORD)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypmap_parms(XDR *xdrs, ypmap_parms *objp) -{ - if (!__xdr_domainname(xdrs, &objp->domain)) - return FALSE; - - if (!__xdr_mapname(xdrs, &objp->map)) - return FALSE; - - if (!xdr_u_int(xdrs, &objp->ordernum)) - return FALSE; - - if (!__xdr_peername(xdrs, &objp->peer)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypreq_key(XDR *xdrs, ypreq_key *objp) -{ - if (!__xdr_domainname(xdrs, &objp->domain)) - return FALSE; - - if (!__xdr_mapname(xdrs, &objp->map)) - return FALSE; - - if (!__xdr_keydat(xdrs, &objp->key)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypreq_nokey(XDR *xdrs, ypreq_nokey *objp) -{ - if (!__xdr_domainname(xdrs, &objp->domain)) - return FALSE; - - if (!__xdr_mapname(xdrs, &objp->map)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypreq_xfr(XDR *xdrs, ypreq_xfr *objp) -{ - if (!__xdr_ypmap_parms(xdrs, &objp->map_parms)) - return FALSE; - - if (!xdr_u_int(xdrs, &objp->transid)) - return FALSE; - - if (!xdr_u_int(xdrs, &objp->prog)) - return FALSE; - - if (!xdr_u_int(xdrs, &objp->port)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypresp_val(XDR *xdrs, ypresp_val *objp) -{ - if (!__xdr_ypstat(xdrs, &objp->stat)) - return FALSE; - - if (!__xdr_valdat(xdrs, &objp->val)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypresp_key_val(XDR *xdrs, ypresp_key_val *objp) -{ - if (!__xdr_ypstat(xdrs, &objp->stat)) - return FALSE; - -#if 0 /* The Sun-supplied yp.x RPC input file have these in the wrong order */ - if (!__xdr_keydat(xdrs, &objp->key)) - return FALSE; - - if (!__xdr_valdat(xdrs, &objp->val)) - return FALSE; -#else - if (!__xdr_valdat(xdrs, &objp->val)) - return FALSE; - - if (!__xdr_keydat(xdrs, &objp->key)) - return FALSE; -#endif - return TRUE; -} - -bool_t -__xdr_ypresp_master(XDR *xdrs, ypresp_master *objp) -{ - if (!__xdr_ypstat(xdrs, &objp->stat)) - return FALSE; - - if (!__xdr_peername(xdrs, &objp->peer)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypresp_order(XDR *xdrs, ypresp_order *objp) -{ - if (!__xdr_ypstat(xdrs, &objp->stat)) - return FALSE; - - if (!xdr_u_int(xdrs, &objp->ordernum)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypresp_all(XDR *xdrs, ypresp_all *objp) -{ - if (xdrs->x_op == XDR_ENCODE) - { - while (1) - { - if (!xdr_bool(xdrs, &objp->more)) - { - if (__xdr_ypall_cb.u.close != NULL) - (*(__xdr_ypall_cb.u.close))(__xdr_ypall_cb.data); - - __xdr_ypall_cb.data = NULL; - - return FALSE; - } - - if (!__xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) - { - if (__xdr_ypall_cb.u.close != NULL) - (*(__xdr_ypall_cb.u.close))(__xdr_ypall_cb.data); - - __xdr_ypall_cb.data = NULL; - - return FALSE; - } - - if (objp->ypresp_all_u.val.stat != YP_TRUE) - { - objp->more = FALSE; - - if (__xdr_ypall_cb.u.close != NULL) - (*(__xdr_ypall_cb.u.close))(__xdr_ypall_cb.data); - - __xdr_ypall_cb.data = NULL; - - if (!xdr_bool(xdrs, &objp->more)) - return FALSE; - - return TRUE; - } - - if ((*__xdr_ypall_cb.u.encode)(&objp->ypresp_all_u.val, - __xdr_ypall_cb.data) == YP_NOKEY) - objp->more = FALSE; - } - } - -#ifdef NOTYET /* This code isn't needed in the server */ - else if (xdrs->x_op == XDR_DECODE) - { - int more = 0; - - - while (1) - { - if (!xdr_bool(xdrs, &objp->more)) - return FALSE; - - switch (objp->more) - { - case TRUE: - if (!__xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) - return FALSE; - - if (more == 0) - more = (*__xdr_ypall_callback->foreach.decoder) - (&objp->ypresp_all_u.val, __xdr_ypall_callback->data); - break; - - case FALSE: - return TRUE; - - default: - return FALSE; - } - } - return FALSE; - } -#endif - - return TRUE; -} - -bool_t -__xdr_ypresp_xfr(XDR *xdrs, ypresp_xfr *objp) -{ - if (!xdr_u_int(xdrs, &objp->transid)) - return FALSE; - - if (!__xdr_ypxfrstat(xdrs, &objp->xfrstat)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypmaplist(XDR *xdrs, ypmaplist *objp) -{ - if (!__xdr_mapname(xdrs, &objp->map)) - return FALSE; - - if (!xdr_pointer(xdrs, (char **)&objp->next, sizeof(ypmaplist), - (xdrproc_t)__xdr_ypmaplist)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypresp_maplist(XDR *xdrs, ypresp_maplist *objp) -{ - if (!__xdr_ypstat(xdrs, &objp->stat)) - return FALSE; - - if (!xdr_pointer(xdrs, (char **)&objp->maps, sizeof(ypmaplist), - (xdrproc_t)__xdr_ypmaplist)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_yppush_status(XDR *xdrs, yppush_status *objp) -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_yppushresp_xfr(XDR *xdrs, yppushresp_xfr *objp) -{ - if (!xdr_u_int(xdrs, &objp->transid)) - return FALSE; - - if (!__xdr_yppush_status(xdrs, &objp->status)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypbind_resptype(XDR *xdrs, ypbind_resptype *objp) -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypbind_binding(XDR *xdrs, ypbind_binding *objp) -{ - if (!xdr_opaque(xdrs, objp->ypbind_binding_addr, 4)) - return FALSE; - - if (!xdr_opaque(xdrs, objp->ypbind_binding_port, 2)) - return FALSE; - - return TRUE; -} - -bool_t -__xdr_ypbind_resp(XDR *xdrs, ypbind_resp *objp) -{ - if (!__xdr_ypbind_resptype(xdrs, &objp->ypbind_status)) - return FALSE; - - switch (objp->ypbind_status) - { - case YPBIND_FAIL_VAL: - if (!xdr_u_int(xdrs, &objp->ypbind_resp_u.ypbind_error)) - return FALSE; - break; - - case YPBIND_SUCC_VAL: - if (!__xdr_ypbind_binding(xdrs, &objp->ypbind_resp_u.ypbind_bindinfo)) - return FALSE; - break; - - default: - return FALSE; - } - return TRUE; -} - -bool_t -__xdr_ypbind_setdom(XDR *xdrs, ypbind_setdom *objp) -{ - if (!__xdr_domainname(xdrs, &objp->ypsetdom_domain)) - return FALSE; - - if (!__xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding)) - return FALSE; - - if (!xdr_u_int(xdrs, &objp->ypsetdom_vers)) - return FALSE; - - return TRUE; -} diff --git a/gnu/usr.sbin/ypserv/ypserv.8 b/gnu/usr.sbin/ypserv/ypserv.8 deleted file mode 100644 index 43ac853..0000000 --- a/gnu/usr.sbin/ypserv/ypserv.8 +++ /dev/null @@ -1,293 +0,0 @@ -.\" Copyright (c) 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: ypserv.8,v 1.2 1995/02/07 05:04:51 wpaul Exp $ -.\" -.Dd February 4, 1995 -.Dt YPSERV 8 -.Os -.Sh NAME -.Nm ypserv -.Nd "NIS database server" -.Sh SYNOPSIS -.Nm ypserv -.Op Fl dns -.Op Fl debug -.Op Fl k -.Op Fl p Ar port -.Sh DESCRIPTION -.Nm NIS -is an RPC-based service designed to allow a number of UNIX-based -machines to share a common set of configuration files. Rather than -requiring a system administrator to update several copies of files -such as -.Pa /etc/hosts , -.Pa /etc/passwd -and -.Pa /etc/group , -which tend to require frequent changes in most environments, NIS -allows groups of computers to share one set of data which can be -updated from a single location. -.Pp -.Nm ypserv -is the server that distributes NIS databases -to client systems within an NIS -.Nm domain. -Each client in an NIS domain must have its domainname set to -one of the domains served by -.Nm ypserv -using the -.Xr domainname 1 -command. The clients must also run -.Xr ypbind 8 -in order to attach to a particular server, since it is possible to -have serveral servers within a single NIS domain. -.Pp -The databases distributed by -.Nm ypserv -are stored in -.Pa /var/yp/[domainname] -where -.Pa domainname -is the name of the domain being served. There can be several -such directories with different domainnames, and -.Nm ypserv -can handle them all. -.Pp -The databases, or -.Pa maps -as they are often called, -are created by -.Nm /var/yp/Makefile -using several system files as source. The database files are in -.Xr db 3 -format to help speed retrieval when there are many records involved. -In FreeBSD, the -maps are always readable and writable only by root for security -reasons. Technically this is only necessary for the password -maps, but since the data in the other maps can be found in -other world-readable files anyway, it doesn't hurt and it's considered -good general practice. -.Pp -.Nm ypserv -is started by -.Nm /etc/rc -if it has been enabled in -.Nm /etc/sysconfig. -.Sh SPECIAL FEATURES -There are some problems associated with distributing FreeBSD's password -database via NIS: FreeBSD normally only stores encrypted passwords -in -.Pa /etc/master.passwd , -which is readable and writable only by root. By turning this file -into an NIS map, this security feature would be completely defeated. -.Pp -To make up for this, the FreeBSD version of -.Nm ypserv -handles the -.Pa master.passwd.byname -and -.Pa master.basswd.byuid -maps in a special way. When the server receives a request to access -either of these two maps, it will check the TCP port from which the -request originated and return an error if the port number is greater -than 1023. Since only the superuser is allowed to bind to TCP ports -with values less than 1024, the server can use this test to determine -whether or not the access request came from a privileged user. -Any requests made by non-privileged users are therefore rejected. -.Pp -Furthermore, the -.Xr getpwent 3 -routines in FreeBSD's standard C libarary will only attempt to retrieve -data from the -.Pa master.passwd.byname -and -.Pa master.passwd.byuid -maps for the superuser: if a normal user calls any of these functions, -the standard -.Pa passwd.byname -and -.Pa passwd.byuid -maps will be accessed instead. The latter two maps are constructed by -.Nm /var/yp/Makefile -by parsing the -.Pa master.passwd -file and stripping out the password fields, and are therefore -safe to pass on to unprivileged users. In this way, the shadow password -aspect of the protected -.Pa master.passwd -database is maintained through NIS. -.Pp -.Sh NOTES -.Ss Limitations -There are two problems inherent with password shadowing in NIS -that users should -be aware of: -.Bl -enum -offset indent -.It -The 'TCP port less than 1024' test is trivial to defeat for users with -unrestricted access to machines on your network (even those machines -which do not run UNIX-based operating systems). -.It -If you plan to use a FreeBSD system to serve non-FreeBSD clients that -have no support for password shadowing (which is most of them), you -will have to disable the password shadowing entirely by uncommenting the -.Nm UNSECURE=True -entry in -.Nm /var/yp/Makefile . -This will cause the standard -.Pa passwd.byname -and -.Pa passwd.byuid -maps to be generated with valid encrypted password fields, which is -neccesary in order for non-FreeBSD clients to perform user -authentication through NIS. -.El -.Pp -.Ss Security -.Nm ypserv -has support for Wietse Venema's -.Pa tcpwrapper -package built in, though it is not compiled in by default since -the -.Pa tcpwrapper -package is not distributed with FreeBSD. However, if you have -.Nm libwrap.a -and -.Nm tcpd.h , -you can easily recompile -.Nm ypserv -with them, thereby enabling its 'securenets' features: you can -configure -.Nm ypserv -to only handle resquests from machines listed -in the -.Pa tcpwrapper -configuration files, which would help limit vulnerability to the -first limitation listed above. -.Pp -.Ss NIS servers that are also NIS clients -Care must be taken when running -.Nm ypserv -in a multi-server domain where the server machines are also -NIS clients. It is generally a good idea to force the servers to -bind to themselves rather than allowing them to broadcast bind -requests and possibly become bound to each other: strange failure -modes can result if one server goes down and -others are dependent upon on it. (Eventually all the clients will -time out and attempt to bind to other servers, but the delay -involved can be considerable and the failure mode is still present -since the servers might bind to each other all over again). -.Pp -Refer to the -.Xr ypbind 8 -man page for details on how to force it to bind to a particular -server. -.Sh OPTIONS -The following options are supported by -.Nm ypserv : -.Bl -tag -width flag -.It Fl dns -This option affects the way -.Nm ypserv -handles yp_match requests for the -.Pa hosts.byname -and -.Pa hosts.byaddress -maps. By default, if -.Nm ypserv -can't find an entry for a given host in its hosts maps, it will -return an error and perform no further processing. With the -.Fl dns -flag, -.Nm ypserv -will go one step further: rather than giving up immediately, it -will try to resolve the hostname or address using a DNS query. -If the query is successful, -.Nm ypserv -will construct a fake database record and return it to the client, -thereby making it seem as though the client's yp_match request -succeeded. -.Pp -This functionality is provided for compatiblity with SunOS 4.1.x, -which has brain-damaged resolver functions in its standard C -library that depend on NIS for hostname and address resolution. -FreeBSD's resolver can be configured to do DNS -queries directly, therefore it is not necessary to enable this -option when serving only FreeBSD NIS clients. -.It Fl debug -Run the server in debugging mode: the server does not background -itself and prints copious debugging output to stderr for -each -request that it revceives. -.It Fl k -This flag is provided for compatibility with SunOS 4. The -.Xr ypbind 8 -command in SunOS 4 apparently expects to obtain a response from an -NIS v1 server. Starting -.Xr ypserv 8 -with the -.Fl k -flag causes it to register itself as an NIS v1 server and -respond to DOMAIN_NONACK requests. Note carefully: this is merely a -kludge (hence the 'k') to pacify SunOS 4's -.Xr ypbind 8 -command: attempts to make the server actually handle NIS v1 queries -will undoubtedly fail quite miserably. -.It Fl p Ar port -Normally, -.Nm ypserv -will bind itself to a randomly chosen TCP port when it is first -started. This option can be used to force the server to bind to -a particular port instead. -.El -.Sh FILES -.Bl -tag -width Pa -compact -.It Pa /var/yp/[domainname]/[maps] -The NIS maps. -.It Pa /etc/host.conf -Resolver configuration file. -.El -.Sh SEE ALSO -.Xr ypbind 8 , -.Xr yppasswdd 8 , -.Xr yppush 8 , -.Xr ypxfr 8 , -.Xr ypcat 1 , -.Xr yp 8 , -.Xr db 3 -.Sh LICENSE -This program is covered by the GNU Public License version 2. -.Sh AUTHOR -Peter Eriksson (original version) -.br -Bill Paul (port to FreeBSD and various -changes) -- cgit v1.1