gdb diffs (here they come) (part 1 of 2)

Bob Rose rrr at naucse.UUCP
Sat Aug 13 03:00:35 AEST 1988


[food for line eater]

(Remember this is for gdb out of emacs-18.50 running on a 3b1 (ver3.51))

Here they are, good or bad (remember I was not in a good mode when
I did them.) There is probably some bugs (most in coffread.c.) Let
me quickly explain what they are because I'm been very busy and
won't have must time to support gdb.

Coffread.c reads in the coff file (really 8*). When it reads it in
it take all the global symbol data and puts it in one area. It also
puts with this the range in memory of where these symbols are, the
thing is this range is wrong (and needs to be fix I think) This global
area is also check first whenever you do anything so whenever gdb
looks up an address (to find a linenumber or symbol) it sees it is
in the range of the global data (because the range on the global data
is wrong), then can't find it in the global data so assumes there was
never a linenumber or symbol for it. Actually I think this is pretty
well fixed now but if gdb says there are no symbols for a function you
know you compiled with -g, this is probably it.

I also haven't had much time to test it, things like bit fields and so
on. This should however be a good start. Also gdb works great on gdb.
                                Have fun
                                -bob

BTW Keep me informed of the diffs you do, and if you do need help
drop me some email, I'll try to answer it.

Can you believe I forgot to shar in alloca.s again! (shar Part1 follow this)

---------------------------------alloca.s-------------------------
	file	"alloca.s"
	global	alloca
alloca:
	mov.l	(%sp)+,%a1	# pop return addr from top of stack
	mov.l	(%sp)+,%d0	# pop size in bytes from top of stack
	add.l	&R%1,%d0	# round size up to long word
	and.l	&-4,%d0		# mask out lower two bits of size
	sub.l	%d0,%sp		# allocate by moving stack pointer
	tst.b	P%1(%sp)	# stack probe to allocate pages
	mov.l	%sp,%a0		# return pointer as pointer
	mov.l	%sp,%d0		# return pointer as int to avoid disaster
	add.l	&-4,%sp		# new top of stack
	jmp	(%a1)		# not a normal return
	set	S%1,64		# safety factor for C compiler scratch
	set	R%1,3+S%1	# add to size for rounding
	set	P%1,-132	# probe this far below current top of stack
---------------------------------alloca.s-------------------------

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 2)."
# Contents:  insque.c m-3b1.h regex.c signals.c
# Wrapped by rrr at bobert on Wed Aug 10 13:52:33 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'insque.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'insque.c'\"
else
echo shar: Extracting \"'insque.c'\" \(643 characters\)
sed "s/^X//" >'insque.c' <<'END_OF_FILE'
Xstruct qelem {
X	struct qelem *q_forw;
X	struct qelem *q_back;
X	char *q_data;
X};
X
Xinsque(elem, pred)
Xregister struct qelem *elem, *pred;
X{
X	if (pred == 0) {
X		elem->q_forw = 0;
X		elem->q_back = 0;
X	} else if (pred->q_forw == 0) {
X		elem->q_back = pred;
X		elem->q_forw = 0;
X		pred->q_forw = elem;
X	} else {
X		elem->q_forw = pred->q_forw;
X		elem->q_back = pred;
X		pred->q_forw->q_back = elem;
X		pred->q_forw = elem;
X	}
X}
X
Xremque(elem)
Xregister struct qelem *elem;
X{
X	if (elem->q_forw != 0)
X		elem->q_forw->q_back = elem->q_back;
X	else
X		elem->q_forw = 0;
X
X	if (elem->q_back != 0)
X		elem->q_back->q_forw = elem->q_forw;
X	else
X		elem->q_back = 0;
X}
END_OF_FILE
if test 643 -ne `wc -c <'insque.c'`; then
    echo shar: \"'insque.c'\" unpacked with wrong size!
fi
# end of 'insque.c'
fi
if test -f 'm-3b1.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'m-3b1.h'\"
else
echo shar: Extracting \"'m-3b1.h'\" \(15739 characters\)
sed "s/^X//" >'m-3b1.h' <<'END_OF_FILE'
X/* Parameters for execution on a Sun, for GDB, the GNU debugger.
X   Copyright (C) 1986, 1987 Free Software Foundation, Inc.
X
XGDB is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the GDB General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute GDB,
Xbut only under the conditions described in the GDB General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with GDB so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
XIn other words, go ahead and share GDB, but don't try to stop
Xanyone else from sharing it farther.  Help stamp out software hoarding!
X*/
X
X#ifndef sun2
X#define sun2
X#endif
X
X/* Define this if the C compiler puts an underscore at the front
X   of external names before giving them to the linker.  */
X
X#define F_OK 0
X#define X_OK 1
X#define W_OK 2
X#define R_OK 4
X#define NOMONSTERSTRINGS
X/* #define NAMES_HAVE_UNDERSCORE */
X
X/* Debugger information will be in DBX format.  */
X
X/* #define READ_DBX_FORMAT */
X
X/* Offset from address of function to start of its code.
X   Zero on most machines.  */
X
X#define FUNCTION_START_OFFSET 0
X
X/* Advance PC across any function entry prologue instructions
X   to reach some "real" code.  */
X
X#define SKIP_PROLOGUE(pc)   \
X{ register int op = read_memory_integer (pc, 2);	\
X  if (op == 0047126)				\
X    pc += 4;   /* Skip link #word */			\
X  else if (op == 0044016)			\
X    pc += 6;   /* Skip link #long */			\
X}
X
X/* Immediately after a function call, return the saved pc.
X   Can't go through the frames for this because on some machines
X   the new frame is not set up until the new function executes
X   some instructions.  */
X
X#define SAVED_PC_AFTER_CALL(frame) \
Xread_memory_integer (read_register (SP_REGNUM), 4)
X
X/* This is the amount to subtract from u.u_ar0
X   to get the offset in the core file of the register values.  */
X
X/* #define KERNEL_U_ADDR 0x2800 */
X#define KERNEL_U_ADDR 04266 /* my mom told me so! */
X
X/* Address of end of stack space.  */
X
X#define STACK_END_ADDR 0x1000000
X
X/* Stack grows downward.  */
X
X#define INNER_THAN <
X
X/* Sequence of bytes for breakpoint instruction.  */
X
X/* #define BREAKPOINT {0x4e, 0x4f} */
X/* #define BREAKPOINT {0x4a, 0xfc} */
X#define BREAKPOINT {0x4e, 0x41}
X
X/* Amount PC must be decremented by after a breakpoint.
X   This is often the number of bytes in BREAKPOINT
X   but not always.  */
X
X#define DECR_PC_AFTER_BREAK 2
X
X/* Nonzero if instruction at PC is a return instruction.  */
X
X#define ABOUT_TO_RETURN(pc) (read_memory_integer (pc, 2) == 0x4e76)
X
X/* Return 1 if P points to an invalid floating point value.  */
X
X#define INVALID_FLOAT(p, len) 0   /* Just a first guess; not checked */
X
X/* Say how long registers are.  */
X
X#define REGISTER_TYPE long
X
X/* Number of machine registers */
X
X#define NUM_REGS 18
X
X/* Number that are really general registers */
X
X#define NUM_GENERAL_REGS 16
X
X/* Initializer for an array of names of registers.
X   There should be NUM_REGS strings in this initializer.  */
X
X#define REGISTER_NAMES {"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a0", "a1", "a2", "a3", "a4", "a5", "fp", "sp", "ps", "pc"}
X
X/* Register numbers of various important registers.
X   Note that some of these values are "real" register numbers,
X   and correspond to the general registers of the machine,
X   and some are "phony" register numbers which are too large
X   to be actual register numbers as far as the user is concerned
X   but do serve to get the desired values when passed to read_register.  */
X
X#define FP_REGNUM 14		/* Contains address of executing stack frame */
X#define SP_REGNUM 15		/* Contains address of top of stack */
X#define PS_REGNUM 16		/* Contains processor status */
X#define PC_REGNUM 17		/* Contains program counter */
X
X/* Total amount of space needed to store our copies of the machine's
X   register state, the array `registers'.  */
X#define REGISTER_BYTES (16*4+8)
X
X/* Index within `registers' of the first byte of the space for
X   register N.  */
X
X#define REGISTER_BYTE(N)  ((N) * 4)
X
X/* Number of bytes of storage in the actual machine representation
X   for register N.  On the 68000, all regs are 4 bytes.  */
X
X#define REGISTER_RAW_SIZE(N) 4
X
X/* Number of bytes of storage in the program's representation
X   for register N.  On the 68000, all regs are 4 bytes.  */
X
X#define REGISTER_VIRTUAL_SIZE(N) 4
X
X/* Largest value REGISTER_RAW_SIZE can have.  */
X
X#define MAX_REGISTER_RAW_SIZE 4
X
X/* Largest value REGISTER_VIRTUAL_SIZE can have.  */
X
X#define MAX_REGISTER_VIRTUAL_SIZE 4
X
X/* Nonzero if register N requires conversion
X   from raw format to virtual format.  */
X
X#define REGISTER_CONVERTIBLE(N) 0
X
X/* Convert data from raw format for register REGNUM
X   to virtual format for register REGNUM.  */
X
X#define REGISTER_CONVERT_TO_VIRTUAL(REGNUM,FROM,TO)  bcopy ((FROM), (TO), 4);
X
X/* Convert data from virtual format for register REGNUM
X   to raw format for register REGNUM.  */
X
X#define REGISTER_CONVERT_TO_RAW(REGNUM,FROM,TO)  bcopy ((FROM), (TO), 4);
X
X/* Return the GDB type object for the "standard" data type
X   of data in register N.  */
X
X#define REGISTER_VIRTUAL_TYPE(N)  builtin_type_int
X
X/* Extract from an array REGBUF containing the (raw) register state
X   a function return value of type TYPE, and copy that, in virtual format,
X   into VALBUF.  */
X
X#define EXTRACT_RETURN_VALUE(TYPE,REGBUF,VALBUF) \
X  bcopy (REGBUF, VALBUF, TYPE_LENGTH (TYPE))
X
X/* Write into appropriate registers a function return value
X   of type TYPE, given in virtual format.  */
X
X#define STORE_RETURN_VALUE(TYPE,VALBUF) \
X  write_register_bytes (0, VALBUF, TYPE_LENGTH (TYPE))
X
X/* Extract from an array REGBUF containing the (raw) register state
X   the address in which a function should return its structure value,
X   as a CORE_ADDR (or an expression that can be used as one).  */
X
X#define EXTRACT_STRUCT_VALUE_ADDRESS(REGBUF) (*(int *)(REGBUF))
X
X/* This is a piece of magic that is given a register number REGNO
X   and as BLOCKEND the address in the system of the end of the user structure
X   and stores in ADDR the address in the kernel or core dump
X   of that register.  */
X
X#define REGISTER_U_ADDR(addr, blockend, regno)		\
X{ addr = blockend + regno * 4; }
X
X/* Describe the pointer in each stack frame to the previous stack frame
X   (its caller).  */
X
X/* FRAME_CHAIN takes a frame's nominal address
X   and produces the frame's chain-pointer.
X
X   FRAME_CHAIN_COMBINE takes the chain pointer and the frame's nominal address
X   and produces the nominal address of the caller frame.
X
X   However, if FRAME_CHAIN_VALID returns zero,
X   it means the given frame is the outermost one and has no caller.
X   In that case, FRAME_CHAIN_COMBINE is not used.  */
X
X/* In the case of the Sun, the frame's nominal address
X   is the address of a 4-byte word containing the calling frame's address.  */
X
X#define FRAME_CHAIN(thisframe)  (read_memory_integer (thisframe, 4))
X
X#define FRAME_CHAIN_VALID(chain, thisframe) \
X  (chain != 0 && (FRAME_SAVED_PC (thisframe) >= first_object_file_end))
X
X#define FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
X
X/* Define other aspects of the stack frame.  */
X
X#define FRAME_SAVED_PC(frame) (read_memory_integer (frame + 4, 4))
X
X#define FRAME_ARGS_ADDRESS(fi) (fi.frame)
X
X#define FRAME_LOCALS_ADDRESS(fi) (fi.frame)
X
X/* Set VAL to the number of args passed to frame described by FI.
X   Can set VAL to -1, meaning no way to tell.  */
X
X/* We can't tell how many args there are
X   now that the C compiler delays popping them.  */
X#define FRAME_NUM_ARGS(val,fi) (val = -1)
X
X#if 0
X#define FRAME_NUM_ARGS(val, fi)  \
X{ register CORE_ADDR pc = FRAME_SAVED_PC (fi.frame);		\
X  register int insn = 0177777 & read_memory_integer (pc, 2);	\
X  val = 0;							\
X  if (insn == 0047757 || insn == 0157374)  /* lea W(sp),sp or addaw #W,sp */ \
X    val = read_memory_integer (pc + 2, 2);			\
X  else if ((insn & 0170777) == 0050217 /* addql #N, sp */	\
X	   || (insn & 0170777) == 0050117)  /* addqw */		\
X    { val = (insn >> 9) & 7; if (val == 0) val = 8; }		\
X  else if (insn == 0157774) /* addal #WW, sp */			\
X    val = read_memory_integer (pc + 2, 4);			\
X  val >>= 2; }
X#endif
X
X/* Return number of bytes at start of arglist that are not really args.  */
X
X#define FRAME_ARGS_SKIP 8
X
X/* Put here the code to store, into a struct frame_saved_regs,
X   the addresses of the saved registers of frame described by FRAME_INFO.
X   This includes special registers such as pc and fp saved in special
X   ways in the stack frame.  sp is even more special:
X   the address we return for it IS the sp for the next frame.  */
X
X#define FRAME_FIND_SAVED_REGS(frame_info, frame_saved_regs)		\
X{ register int regnum;							\
X  register int regmask;							\
X  register CORE_ADDR next_addr;						\
X  register CORE_ADDR pc;						\
X  bzero (&frame_saved_regs, sizeof frame_saved_regs);			\
X  if ((frame_info).pc >= (frame_info).frame - CALL_DUMMY_LENGTH - FP_REGNUM*4 - 4 \
X      && (frame_info).pc <= (frame_info).frame)				\
X    { next_addr = (frame_info).frame;					\
X      pc = (frame_info).frame - CALL_DUMMY_LENGTH - FP_REGNUM * 4 - 4; }\
X  else   								\
X    { pc = get_pc_function_start ((frame_info).pc); 			\
X      /* Verify we have a link a6 instruction next;			\
X	 if not we lose.  If we win, find the address above the saved   \
X	 regs using the amount of storage from the link instruction.  */\
X      if (044016 == read_memory_integer (pc, 2))			\
X	next_addr = (frame_info).frame + read_memory_integer (pc += 2, 4), pc+=4; \
X      else if (047126 == read_memory_integer (pc, 2))			\
X	next_addr = (frame_info).frame + read_memory_integer (pc += 2, 2), pc+=2; \
X      else goto lose;							\
X      /* If have an addal #-n, sp next, adjust next_addr.  */		\
X      if ((0177777 & read_memory_integer (pc, 2)) == 0157774)		\
X	next_addr += read_memory_integer (pc += 2, 4), pc += 4;		\
X    }									\
X  /* next should be a moveml to (sp) or -(sp) or a movl r,-(sp) */	\
X  regmask = read_memory_integer (pc + 2, 2);				\
X  if (0044327 == read_memory_integer (pc, 2))				\
X    { pc += 4; /* Regmask's low bit is for register 0, the first written */ \
X      for (regnum = 0; regnum < 16; regnum++, regmask >>= 1)		\
X	if (regmask & 1)						\
X          (frame_saved_regs).regs[regnum] = (next_addr += 4) - 4; }	\
X  else if (0044347 == read_memory_integer (pc, 2))			\
X    { pc += 4; /* Regmask's low bit is for register 15, the first pushed */ \
X      for (regnum = 15; regnum >= 0; regnum--, regmask >>= 1)		\
X	if (regmask & 1)						\
X          (frame_saved_regs).regs[regnum] = (next_addr -= 4); }		\
X  else if (0x2f00 == 0xfff0 & read_memory_integer (pc, 2))		\
X    { regnum = 0xf & read_memory_integer (pc, 2); pc += 2;		\
X      (frame_saved_regs).regs[regnum] = (next_addr -= 4); }		\
X  /* clrw -(sp); movw ccr,-(sp) may follow.  */				\
X  if (0x426742e7 == read_memory_integer (pc, 4))			\
X    (frame_saved_regs).regs[PS_REGNUM] = (next_addr -= 4);		\
X  lose: ;								\
X  (frame_saved_regs).regs[SP_REGNUM] = (frame_info).frame + 8;		\
X  (frame_saved_regs).regs[FP_REGNUM] = (frame_info).frame;		\
X  (frame_saved_regs).regs[PC_REGNUM] = (frame_info).frame + 4;		\
X}
X
X/* Things needed for making the inferior call functions.  */
X
X/* Push an empty stack frame, to record the current PC, etc.  */
X
X#define PUSH_DUMMY_FRAME \
X{ register CORE_ADDR sp = read_register (SP_REGNUM);\
X  register int regnum;				    \
X  sp = push_word (sp, read_register (PC_REGNUM));   \
X  sp = push_word (sp, read_register (FP_REGNUM));   \
X  write_register (FP_REGNUM, sp);		    \
X  for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)  \
X    sp = push_word (sp, read_register (regnum));    \
X  sp = push_word (sp, read_register (PS_REGNUM));   \
X  write_register (SP_REGNUM, sp);  }
X
X/* Discard from the stack the innermost frame, restoring all registers.  */
X
X#define POP_FRAME  \
X{ register CORE_ADDR fp = read_register (FP_REGNUM);		 \
X  register int regnum;						 \
X  struct frame_saved_regs fsr;					 \
X  struct frame_info fi;						 \
X  fi = get_frame_info (fp);					 \
X  get_frame_saved_regs (&fi, &fsr);				 \
X  for (regnum = FP_REGNUM - 1; regnum >= 0; regnum--)		 \
X    if (fsr.regs[regnum])					 \
X      write_register (regnum, read_memory_integer (fsr.regs[regnum], 4)); \
X  if (fsr.regs[PS_REGNUM])					 \
X    write_register (PS_REGNUM, read_memory_integer (fsr.regs[PS_REGNUM], 4)); \
X  write_register (FP_REGNUM, read_memory_integer (fp, 4));	 \
X  write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));   \
X  write_register (SP_REGNUM, fp + 8);				 \
X}
X
X/* This sequence of words is the instructions
X     moveml 0xfffc,-(sp)
X     clrw -(sp)
X     movew ccr,-(sp)
X     /..* The arguments are pushed at this point by GDB;
X	no code is needed in the dummy for this.
X	The CALL_DUMMY_START_OFFSET gives the position of 
X	the following jsr instruction.  *../
X     jsr @#32323232
X     addl #69696969,sp
X     bpt
X     nop
XNote this is 24 bytes.
XWe actually start executing at the jsr, since the pushing of the
Xregisters is done by PUSH_DUMMY_FRAME.  If this were real code,
Xthe arguments for the function called by the jsr would be pushed
Xbetween the moveml and the jsr, and we could allow it to execute through.
XBut the arguments have to be pushed by GDB after the PUSH_DUMMY_FRAME is done,
Xand we cannot allow the moveml to push the registers again lest they be
Xtaken for the arguments.  */
X
X#define CALL_DUMMY {0x48e7fffc, 0x426742e7, 0x4eb93232, 0x3232dffc, 0x69696969, 0x4e4f4e71}
X
X#define CALL_DUMMY_LENGTH 24
X
X#define CALL_DUMMY_START_OFFSET 8
X
X/* Insert the specified number of args and function address
X   into a call sequence of the above form stored at DUMMYNAME.  */
X
X#define FIX_CALL_DUMMY(dummyname, fun, nargs)     \
X{ *(int *)((char *) dummyname + 16) = nargs * 4;  \
X  *(int *)((char *) dummyname + 10) = fun; }
X
X/* Interface definitions for kernel debugger KDB.  */
X
X/* Map machine fault codes into signal numbers.
X   First subtract 0, divide by 4, then index in a table.
X   Faults for which the entry in this table is 0
X   are not handled by KDB; the program's own trap handler
X   gets to handle then.  */
X
X#define FAULT_CODE_ORIGIN 0
X#define FAULT_CODE_UNITS 4
X#define FAULT_TABLE    \
X{ 0, 0, 0, 0, SIGTRAP, 0, 0, 0, \
X  0, SIGTRAP, 0, 0, 0, 0, 0, SIGKILL, \
X  0, 0, 0, 0, 0, 0, 0, 0, \
X  SIGILL }
X
X/* Start running with a stack stretching from BEG to END.
X   BEG and END should be symbols meaningful to the assembler.
X   This is used only for kdb.  */
X
X#define INIT_STACK(beg, end)  \
X{ asm (".globl end");         \
X  asm ("movel $ end, sp");      \
X  asm ("clrl fp"); }
X
X/* Push the frame pointer register on the stack.  */
X#define PUSH_FRAME_PTR        \
X  asm ("movel fp, -(sp)");
X
X/* Copy the top-of-stack to the frame pointer register.  */
X#define POP_FRAME_PTR  \
X  asm ("movl (sp), fp");
X
X/* After KDB is entered by a fault, push all registers
X   that GDB thinks about (all NUM_REGS of them),
X   so that they appear in order of ascending GDB register number.
X   The fault code will be on the stack beyond the last register.  */
X
X#define PUSH_REGISTERS        \
X{ asm ("clrw -(sp)");	      \
X  asm ("pea 10(sp)");	      \
X  asm ("movem $ 0xfffe,-(sp)"); }
X
X/* Assuming the registers (including processor status) have been
X   pushed on the stack in order of ascending GDB register number,
X   restore them and return to the address in the saved PC register.  */
X
X#define POP_REGISTERS          \
X{ asm ("subil $8,28(sp)");     \
X  asm ("movem (sp),$ 0xffff"); \
X  asm ("rte"); }
END_OF_FILE
if test 15739 -ne `wc -c <'m-3b1.h'`; then
    echo shar: \"'m-3b1.h'\" unpacked with wrong size!
fi
# end of 'm-3b1.h'
fi
if test -f 'regex.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'regex.c'\"
else
echo shar: Extracting \"'regex.c'\" \(7886 characters\)
sed "s/^X//" >'regex.c' <<'END_OF_FILE'
X/* @(#)regex.c	4.1 (Berkeley) 12/21/80 */
X#
X
X/*
X * routines to do regular expression matching
X *
X * Entry points:
X *
X *	re_comp(s)
X *		char *s;
X *	 ... returns 0 if the string s was compiled successfully,
X *		     a pointer to an error message otherwise.
X *	     If passed 0 or a null string returns without changing
X *           the currently compiled re (see note 11 below).
X *
X *	re_exec(s)
X *		char *s;
X *	 ... returns 1 if the string s matches the last compiled regular
X *		       expression, 
X *		     0 if the string s failed to match the last compiled
X *		       regular expression, and
X *		    -1 if the compiled regular expression was invalid 
X *		       (indicating an internal error).
X *
X * The strings passed to both re_comp and re_exec may have trailing or
X * embedded newline characters; they are terminated by nulls.
X *
X * The identity of the author of these routines is lost in antiquity;
X * this is essentially the same as the re code in the original V6 ed.
X *
X * The regular expressions recognized are described below. This description
X * is essentially the same as that for ed.
X *
X *	A regular expression specifies a set of strings of characters.
X *	A member of this set of strings is said to be matched by
X *	the regular expression.  In the following specification for
X *	regular expressions the word `character' means any character but NUL.
X *
X *	1.  Any character except a special character matches itself.
X *	    Special characters are the regular expression delimiter plus
X *	    \ [ . and sometimes ^ * $.
X *	2.  A . matches any character.
X *	3.  A \ followed by any character except a digit or ( )
X *	    matches that character.
X *	4.  A nonempty string s bracketed [s] (or [^s]) matches any
X *	    character in (or not in) s. In s, \ has no special meaning,
X *	    and ] may only appear as the first letter. A substring 
X *	    a-b, with a and b in ascending ASCII order, stands for
X *	    the inclusive range of ASCII characters.
X *	5.  A regular expression of form 1-4 followed by * matches a
X *	    sequence of 0 or more matches of the regular expression.
X *	6.  A regular expression, x, of form 1-8, bracketed \(x\)
X *	    matches what x matches.
X *	7.  A \ followed by a digit n matches a copy of the string that the
X *	    bracketed regular expression beginning with the nth \( matched.
X *	8.  A regular expression of form 1-8, x, followed by a regular
X *	    expression of form 1-7, y matches a match for x followed by
X *	    a match for y, with the x match being as long as possible
X *	    while still permitting a y match.
X *	9.  A regular expression of form 1-8 preceded by ^ (or followed
X *	    by $), is constrained to matches that begin at the left
X *	    (or end at the right) end of a line.
X *	10. A regular expression of form 1-9 picks out the longest among
X *	    the leftmost matches in a line.
X *	11. An empty regular expression stands for a copy of the last
X *	    regular expression encountered.
X */
X
X/*
X * constants for re's
X */
X#define	CBRA	1
X#define	CCHR	2
X#define	CDOT	4
X#define	CCL	6
X#define	NCCL	8
X#define	CDOL	10
X#define	CEOF	11
X#define	CKET	12
X#define	CBACK	18
X
X#define	CSTAR	01
X
X#define	ESIZE	512
X#define	NBRA	9
X
Xstatic	char	expbuf[ESIZE], *braslist[NBRA], *braelist[NBRA];
Xstatic	char	circf;
X
X/*
X * compile the regular expression argument into a dfa
X */
Xchar *
Xre_comp(sp)
X	register char	*sp;
X{
X	register int	c;
X	register char	*ep = expbuf;
X	int	cclcnt, numbra = 0;
X	char	*lastep = 0;
X	char	bracket[NBRA];
X	char	*bracketp = &bracket[0];
X	static	char	*retoolong = "Regular expression too long";
X
X#define	comerr(msg) {expbuf[0] = 0; numbra = 0; return(msg); }
X
X	if (sp == 0 || *sp == '\0') {
X		if (*ep == 0)
X			return("No previous regular expression");
X		return(0);
X	}
X	if (*sp == '^') {
X		circf = 1;
X		sp++;
X	}
X	else
X		circf = 0;
X	for (;;) {
X		if (ep >= &expbuf[ESIZE])
X			comerr(retoolong);
X		if ((c = *sp++) == '\0') {
X			if (bracketp != bracket)
X				comerr("unmatched \\(");
X			*ep++ = CEOF;
X			*ep++ = 0;
X			return(0);
X		}
X		if (c != '*')
X			lastep = ep;
X		switch (c) {
X
X		case '.':
X			*ep++ = CDOT;
X			continue;
X
X		case '*':
X			if (lastep == 0 || *lastep == CBRA || *lastep == CKET)
X				goto defchar;
X			*lastep |= CSTAR;
X			continue;
X
X		case '$':
X			if (*sp != '\0')
X				goto defchar;
X			*ep++ = CDOL;
X			continue;
X
X		case '[':
X			*ep++ = CCL;
X			*ep++ = 0;
X			cclcnt = 1;
X			if ((c = *sp++) == '^') {
X				c = *sp++;
X				ep[-2] = NCCL;
X			}
X			do {
X				if (c == '\0')
X					comerr("missing ]");
X				if (c == '-' && ep [-1] != 0) {
X					if ((c = *sp++) == ']') {
X						*ep++ = '-';
X						cclcnt++;
X						break;
X					}
X					while (ep[-1] < c) {
X						*ep = ep[-1] + 1;
X						ep++;
X						cclcnt++;
X						if (ep >= &expbuf[ESIZE])
X							comerr(retoolong);
X					}
X				}
X				*ep++ = c;
X				cclcnt++;
X				if (ep >= &expbuf[ESIZE])
X					comerr(retoolong);
X			} while ((c = *sp++) != ']');
X			lastep[1] = cclcnt;
X			continue;
X
X		case '\\':
X			if ((c = *sp++) == '(') {
X				if (numbra >= NBRA)
X					comerr("too many \\(\\) pairs");
X				*bracketp++ = numbra;
X				*ep++ = CBRA;
X				*ep++ = numbra++;
X				continue;
X			}
X			if (c == ')') {
X				if (bracketp <= bracket)
X					comerr("unmatched \\)");
X				*ep++ = CKET;
X				*ep++ = *--bracketp;
X				continue;
X			}
X			if (c >= '1' && c < ('1' + NBRA)) {
X				*ep++ = CBACK;
X				*ep++ = c - '1';
X				continue;
X			}
X			*ep++ = CCHR;
X			*ep++ = c;
X			continue;
X
X		defchar:
X		default:
X			*ep++ = CCHR;
X			*ep++ = c;
X		}
X	}
X}
X
X/* 
X * match the argument string against the compiled re
X */
Xint
Xre_exec(p1)
X	register char	*p1;
X{
X	register char	*p2 = expbuf;
X	register int	c;
X	int	rv;
X
X	for (c = 0; c < NBRA; c++) {
X		braslist[c] = 0;
X		braelist[c] = 0;
X	}
X	if (circf)
X		return((advance(p1, p2)));
X	/*
X	 * fast check for first character
X	 */
X	if (*p2 == CCHR) {
X		c = p2[1];
X		do {
X			if (*p1 != c)
X				continue;
X			if (rv = advance(p1, p2))
X				return(rv);
X		} while (*p1++);
X		return(0);
X	}
X	/*
X	 * regular algorithm
X	 */
X	do
X		if (rv = advance(p1, p2))
X			return(rv);
X	while (*p1++);
X	return(0);
X}
X
X/* 
X * try to match the next thing in the dfa
X */
Xstatic	int
Xadvance(lp, ep)
X	register char	*lp, *ep;
X{
X	register char	*curlp;
X	int	ct, i;
X	int	rv;
X
X	for (;;)
X		switch (*ep++) {
X
X		case CCHR:
X			if (*ep++ == *lp++)
X				continue;
X			return(0);
X
X		case CDOT:
X			if (*lp++)
X				continue;
X			return(0);
X
X		case CDOL:
X			if (*lp == '\0')
X				continue;
X			return(0);
X
X		case CEOF:
X			return(1);
X
X		case CCL:
X			if (cclass(ep, *lp++, 1)) {
X				ep += *ep;
X				continue;
X			}
X			return(0);
X
X		case NCCL:
X			if (cclass(ep, *lp++, 0)) {
X				ep += *ep;
X				continue;
X			}
X			return(0);
X
X		case CBRA:
X			braslist[*ep++] = lp;
X			continue;
X
X		case CKET:
X			braelist[*ep++] = lp;
X			continue;
X
X		case CBACK:
X			if (braelist[i = *ep++] == 0)
X				return(-1);
X			if (backref(i, lp)) {
X				lp += braelist[i] - braslist[i];
X				continue;
X			}
X			return(0);
X
X		case CBACK|CSTAR:
X			if (braelist[i = *ep++] == 0)
X				return(-1);
X			curlp = lp;
X			ct = braelist[i] - braslist[i];
X			while (backref(i, lp))
X				lp += ct;
X			while (lp >= curlp) {
X				if (rv = advance(lp, ep))
X					return(rv);
X				lp -= ct;
X			}
X			continue;
X
X		case CDOT|CSTAR:
X			curlp = lp;
X			while (*lp++)
X				;
X			goto star;
X
X		case CCHR|CSTAR:
X			curlp = lp;
X			while (*lp++ == *ep)
X				;
X			ep++;
X			goto star;
X
X		case CCL|CSTAR:
X		case NCCL|CSTAR:
X			curlp = lp;
X			while (cclass(ep, *lp++, ep[-1] == (CCL|CSTAR)))
X				;
X			ep += *ep;
X			goto star;
X
X		star:
X			do {
X				lp--;
X				if (rv = advance(lp, ep))
X					return(rv);
X			} while (lp > curlp);
X			return(0);
X
X		default:
X			return(-1);
X		}
X}
X
Xbackref(i, lp)
X	register int	i;
X	register char	*lp;
X{
X	register char	*bp;
X
X	bp = braslist[i];
X	while (*bp++ == *lp++)
X		if (bp >= braelist[i])
X			return(1);
X	return(0);
X}
X
Xint
Xcclass(set, c, af)
X	register char	*set, c;
X	int	af;
X{
X	register int	n;
X
X	if (c == 0)
X		return(0);
X	n = *set++;
X	while (--n)
X		if (*set++ == c)
X			return(af);
X	return(! af);
X}
END_OF_FILE
if test 7886 -ne `wc -c <'regex.c'`; then
    echo shar: \"'regex.c'\" unpacked with wrong size!
fi
# end of 'regex.c'
fi
if test -f 'signals.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'signals.c'\"
else
echo shar: Extracting \"'signals.c'\" \(646 characters\)
sed "s/^X//" >'signals.c' <<'END_OF_FILE'
Xchar *sys_siglist[] = {
X	"no error",
X	"hangup",
X	"interrupt",
X	"quit",
X	"illegal instruction",
X	"trace trap",
X	"IOT instruction",
X	"EMT instruction",
X	"floating point exception",
X	"kill",
X	"bus error",
X	"segmentation violation",
X	"bad argument to system call",
X	"write on a pipe with no one to read it",
X	"alarm clock",
X	"software termination signal",
X	"user defined signal 1",
X	"user defined signal 2",
X	"death of a child",
X	"power-fail restart",
X	"window status changes",
X	"telephone status changes",
X	"signal 22",
X	"signal 23",
X	"signal 24",
X	"signal 25",
X	"signal 26",
X	"signal 27",
X	"signal 28",
X	"signal 29",
X	"signal 30",
X	"signal 31",
X};
END_OF_FILE
if test 646 -ne `wc -c <'signals.c'`; then
    echo shar: \"'signals.c'\" unpacked with wrong size!
fi
# end of 'signals.c'
fi
echo shar: End of archive 1 \(of 2\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0



More information about the Comp.sys.att mailing list