diff options
author | alm <alm@FreeBSD.org> | 1994-02-01 00:36:28 +0000 |
---|---|---|
committer | alm <alm@FreeBSD.org> | 1994-02-01 00:36:28 +0000 |
commit | 26c84d7dc70d00b072b13a5757625006586fdede (patch) | |
tree | c82867e2169de15c590a9d6a1c65adf6483131e8 /bin/ed/ed.h | |
parent | 40ec390772e2e083a7986558226c3cc6b72c7378 (diff) | |
download | FreeBSD-src-26c84d7dc70d00b072b13a5757625006586fdede.zip FreeBSD-src-26c84d7dc70d00b072b13a5757625006586fdede.tar.gz |
Fixed range address bug: 1,2, == 2,2 not 2,.
Overhauled the name space, reworked some modules and removed the
obsolescent Addison-Wesley copyright.
Diffstat (limited to 'bin/ed/ed.h')
-rw-r--r-- | bin/ed/ed.h | 290 |
1 files changed, 160 insertions, 130 deletions
diff --git a/bin/ed/ed.h b/bin/ed/ed.h index b390537..ddf86ff 100644 --- a/bin/ed/ed.h +++ b/bin/ed/ed.h @@ -1,11 +1,8 @@ /* ed.h: type and constant definitions for the ed editor. */ /* - * Copyright (c) 1993 The Regents of the University of California. + * Copyright (c) 1993 Andrew Moore * All rights reserved. * - * This code is derived from software contributed to Berkeley by - * Andrew Moore, Talke Studio. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -14,13 +11,6 @@ * 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 @@ -34,22 +24,22 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)ed.h 5.5 (Berkeley) 3/28/93 + * @(#)$Id: ed.h,v 1.4 1993/12/15 15:22:02 alm Exp alm $ */ -#include <unistd.h> -#include <errno.h> #if defined(BSD) && BSD >= 199103 || defined(__386BSD__) # include <sys/param.h> /* for MAXPATHLEN */ #endif +#include <errno.h> +#ifdef sun +# include <limits.h> +#endif #include <regex.h> #include <signal.h> - -#define BITSPERBYTE 8 -#define BITS(type) (BITSPERBYTE * (int)sizeof(type)) -#define CHARBITS BITS(char) -#define INTBITS BITS(int) -#define INTHIBIT (unsigned) (1 << (INTBITS - 1)) +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> #define ERR (-2) #define EMOD (-3) @@ -59,21 +49,28 @@ # define MAXPATHLEN 255 /* _POSIX_PATH_MAX */ #endif -#define MAXFNAME MAXPATHLEN /* max file name size */ #define MINBUFSZ 512 /* minimum buffer size - must be > 0 */ -#define LINECHARS (INTHIBIT - 1) /* max chars per line */ #define SE_MAX 30 /* max subexpressions in a regular expression */ +#ifdef INT_MAX +# define LINECHARS INT_MAX /* max chars per line */ +#else +# define LINECHARS MAXINT /* max chars per line */ +#endif + +/* gflags */ +#define GLB 001 /* global command */ +#define GPR 002 /* print after command */ +#define GLS 004 /* list after command */ +#define GNP 010 /* enumerate after command */ +#define GSG 020 /* global substitute */ typedef regex_t pattern_t; /* Line node */ typedef struct line { - struct line *next; - struct line *prev; + struct line *q_forw; + struct line *q_back; off_t seek; /* address of line in scratch buffer */ - -#define ACTV INTHIBIT /* active bit: high bit of len */ - int len; /* length of line */ } line_t; @@ -98,87 +95,94 @@ typedef struct undo { # define min(a,b) ((a) < (b) ? (a) : (b)) #endif -/* nextln: return line after l mod k */ -#define nextln(l,k) ((l)+1 > (k) ? 0 : (l)+1) - -/* nextln: return line before l mod k */ -#define prevln(l,k) ((l)-1 < 0 ? (k) : (l)-1) - -#define skipblanks() while (isspace(*ibufp) && *ibufp != '\n') ibufp++ +#define INC_MOD(l, k) ((l) + 1 > (k) ? 0 : (l) + 1) +#define DEC_MOD(l, k) ((l) - 1 < 0 ? (k) : (l) - 1) -/* spl1: disable some interrupts (requires reliable signals) */ -#define spl1() mutex++ +/* SPL1: disable some interrupts (requires reliable signals) */ +#define SPL1() mutex++ -/* spl0: enable all interrupts; check sigflags (requires reliable signals) */ -#define spl0() \ +/* SPL0: enable all interrupts; check sigflags (requires reliable signals) */ +#define SPL0() \ if (--mutex == 0) { \ - if (sigflags & (1 << SIGHUP)) dohup(SIGHUP); \ - if (sigflags & (1 << SIGINT)) dointr(SIGINT); \ + if (sigflags & (1 << (SIGHUP - 1))) handle_hup(SIGHUP); \ + if (sigflags & (1 << (SIGINT - 1))) handle_int(SIGINT); \ +} + +/* STRTOL: convert a string to long */ +#define STRTOL(i, p) { \ + if (((i = strtol(p, &p, 10)) == LONG_MIN || i == LONG_MAX) && \ + errno == ERANGE) { \ + sprintf(errmsg, "number out of range"); \ + i = 0; \ + return ERR; \ + } \ } #if defined(sun) || defined(NO_REALLOC_NULL) -/* CKBUF: assure at least a minimum size for buffer b */ -#define CKBUF(b,n,i,err) \ +/* REALLOC: assure at least a minimum size for buffer b */ +#define REALLOC(b,n,i,err) \ if ((i) > (n)) { \ int ti = (n); \ char *ts; \ - spl1(); \ + SPL1(); \ if ((b) != NULL) { \ if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \ fprintf(stderr, "%s\n", strerror(errno)); \ sprintf(errmsg, "out of memory"); \ - spl0(); \ + SPL0(); \ return err; \ } \ } else { \ if ((ts = (char *) malloc(ti += max((i), MINBUFSZ))) == NULL) { \ fprintf(stderr, "%s\n", strerror(errno)); \ sprintf(errmsg, "out of memory"); \ - spl0(); \ + SPL0(); \ return err; \ } \ } \ (n) = ti; \ (b) = ts; \ - spl0(); \ + SPL0(); \ } #else /* NO_REALLOC_NULL */ -/* CKBUF: assure at least a minimum size for buffer b */ -#define CKBUF(b,n,i,err) \ +/* REALLOC: assure at least a minimum size for buffer b */ +#define REALLOC(b,n,i,err) \ if ((i) > (n)) { \ int ti = (n); \ char *ts; \ - spl1(); \ + SPL1(); \ if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \ fprintf(stderr, "%s\n", strerror(errno)); \ sprintf(errmsg, "out of memory"); \ - spl0(); \ + SPL0(); \ return err; \ } \ (n) = ti; \ (b) = ts; \ - spl0(); \ + SPL0(); \ } #endif /* NO_REALLOC_NULL */ -/* requeue: link pred before succ */ -#define requeue(pred, succ) (pred)->next = (succ), (succ)->prev = (pred) +/* REQUE: link pred before succ */ +#define REQUE(pred, succ) (pred)->q_forw = (succ), (succ)->q_back = (pred) -/* insqueue: insert elem in circular queue after pred */ -#define insqueue(elem, pred) \ +#ifdef NEED_INSQUE +/* insque: insert elem in circular queue after pred */ +#define insque(elem, pred) \ { \ - requeue((elem), (pred)->next); \ - requeue((pred), elem); \ + REQUE((elem), (pred)->q_forw); \ + REQUE((pred), elem); \ } -/* remqueue: remove elem from circular queue */ -#define remqueue(elem) requeue((elem)->prev, (elem)->next); +/* remque: remove_lines elem from circular queue */ +#define remque(elem) REQUE((elem)->q_back, (elem)->q_forw); +#endif /* NEED_INSQUE */ -/* nultonl: overwrite ASCII NULs with newlines */ -#define nultonl(s, l) translit(s, l, '\0', '\n') +/* NUL_TO_NEWLINE: overwrite ASCII NULs with newlines */ +#define NUL_TO_NEWLINE(s, l) translit_text(s, l, '\0', '\n') -/* nltonul: overwrite newlines with ASCII NULs */ -#define nltonul(s, l) translit(s, l, '\n', '\0') +/* NEWLINE_TO_NUL: overwrite newlines with ASCII NULs */ +#define NEWLINE_TO_NUL(s, l) translit_text(s, l, '\n', '\0') #ifndef strerror # define strerror(n) sys_errlist[n] @@ -192,75 +196,101 @@ if ((i) > (n)) { \ # endif #endif -/* local function declarations */ -int append __P((long, int)); -int cbcdec __P((char *, FILE *)); -int cbcenc __P((char *, int, FILE *)); -char *ckfn __P((char *)); -int ckglob __P((void)); -int ckrange __P((long, long)); -int desflush __P((FILE *)); -int desgetc __P((FILE *)); -void desinit __P((void)); -int desputc __P((int, FILE *)); -int docmd __P((int)); -void err __P((char *)); -char *ccl __P((char *)); -void clrmark __P((line_t *)); -void cvtkey __P((char *, char *)); -long doglob __P((int)); -void dohup __P((int)); -void dointr __P((int)); -void dowinch __P((int)); -int doprint __P((long, long, int)); -long doread __P((long, char *)); -long dowrite __P((long, long, char *, char *)); -char *esctos __P((char *)); -long patscan __P((pattern_t *, int)); -long getaddr __P((line_t *)); -char *getcmdv __P((int *, int)); -char *getfn __P((void)); -int getkey __P((void)); -char *getlhs __P((int)); -int getline __P((void)); -int getlist __P((void)); -long getmark __P((int)); -long getnum __P((int)); -long getone __P((void)); -line_t *getlp __P((long)); -int getrhs __P((int)); -int getshcmd __P((void)); -char *gettxt __P((line_t *)); -void init_buf __P((void)); -int join __P((long, long)); -int lndelete __P((long, long)); -line_t *lpdup __P((line_t *)); -void lpqueue __P((line_t *)); -void makekey __P((char *)); -char *makesub __P((int)); -int move __P((long, int)); -int oddesc __P((char *, char *)); -void onhup __P((int)); -void onintr __P((int)); -pattern_t *optpat __P((void)); -int putmark __P((int, line_t *)); -void putstr __P((char *, int, long, int)); -char *puttxt __P((char *)); +/* Local Function Declarations */ +void add_line_node __P((line_t *)); +int append_lines __P((long)); +int apply_subst_template __P((char *, regmatch_t *, int, int)); +int build_active_list __P((int)); +int cbc_decode __P((char *, FILE *)); +int cbc_encode __P((char *, int, FILE *)); +int check_addr_range __P((long, long)); +void clear_active_list __P((void)); +void clear_undo_stack __P((void)); +int close_sbuf __P((void)); +int copy_lines __P((long)); +int delete_lines __P((long, long)); +void des_error __P((char *)); +int display_lines __P((long, long, int)); +line_t *dup_line_node __P((line_t *)); +int exec_command __P((void)); +long exec_global __P((int, int)); +void expand_des_key __P((char *, char *)); +int extract_addr_range __P((void)); +char *extract_pattern __P((int)); +int extract_subst_tail __P((int *, int *)); +char *extract_subst_template __P((void)); +int filter_lines __P((long, long, char *)); +int flush_des_file __P((FILE *)); +line_t *get_addressed_line_node __P((long)); +pattern_t *get_compiled_pattern __P((void)); +int get_des_char __P((FILE *)); +char *get_extended_line __P((int *, int)); +char *get_filename __P((void)); +int get_keyword __P((void)); +long get_line_node_addr __P((line_t *)); +long get_matching_node_addr __P((pattern_t *, int)); +long get_marked_node_addr __P((int)); +char *get_sbuf_line __P((line_t *)); +int get_shell_command __P((void)); +int get_stream_line __P((FILE *)); +int get_tty_line __P((void)); +void handle_hup __P((int)); +void handle_int __P((int)); +void handle_winch __P((int)); +int has_trailing_escape __P((char *, char *)); +int hex_to_binary __P((int, int)); +void init_buffers __P((void)); +void init_des_cipher __P((void)); +int is_legal_filename __P((char *)); +int join_lines __P((long, long)); +int mark_line_node __P((line_t *, int)); +int move_lines __P((long)); +line_t *next_active_node __P(()); +long next_addr __P((void)); +int open_sbuf __P((void)); +char *parse_char_class __P((char *)); +int pop_undo_stack __P((void)); +undo_t *push_undo_stack __P((int, long, long)); +int put_des_char __P((int, FILE *)); +char *put_sbuf_line __P((char *)); +int put_stream_line __P((FILE *, char *, int)); +int put_tty_line __P((char *, int, long, int)); void quit __P((int)); -int regsub __P((pattern_t *, line_t *, int)); -int sbclose __P((void)); -int sbopen __P((void)); -int sgetline __P((FILE *)); -int catsub __P((char *, regmatch_t *, int)); -int subst __P((pattern_t *, int)); -int tobinhex __P((int, int)); -int transfer __P((long)); -char *translit __P((char *, int, int, int)); -int undo __P((int)); -undo_t *upush __P((int, long, long)); -void ureset __P((void)); +long read_file __P((char *, long)); +long read_stream __P((FILE *, long)); +int search_and_replace __P((pattern_t *, int, int)); +int set_active_node __P((line_t *)); +void set_des_key __P((char *)); +void signal_hup __P((int)); +void signal_int __P((int)); +char *strip_escapes __P((char *)); +int substitute_matching_text __P((pattern_t *, line_t *, int, int)); +char *translit_text __P((char *, int, int, int)); +void unmark_line_node __P((line_t *)); +void unset_active_nodes __P((line_t *, line_t *)); +long write_file __P((char *, char *, long, long)); +long write_stream __P((FILE *, long, long)); +/* global buffers */ +extern char stdinbuf[]; +extern char *ibuf; +extern char *ibufp; +extern int ibufsz; -extern char *sys_errlist[]; +/* global flags */ +extern int isbinary; +extern int isglobal; +extern int modified; extern int mutex; extern int sigflags; + +/* global vars */ +extern long addr_last; +extern long current_addr; +extern char errmsg[]; +extern long first_addr; +extern int lineno; +extern long second_addr; +#ifdef sun +extern char *sys_errlist[]; +#endif |