📄 awk.h
字号:
/* * awk.h -- Definitions for gawk. *//* * Copyright (C) 1986, 1988, 1989, 1991, 1992 the Free Software Foundation, Inc. * * This file is part of GAWK, the GNU implementation of the * AWK Progamming Language. * * GAWK 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. * * GAWK 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 GAWK; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* ------------------------------ Includes ------------------------------ */#include <stdio.h>#include <limits.h>#include <ctype.h>#include <setjmp.h>#include <varargs.h>#include <time.h>#include <errno.h>#if !defined(errno) && !defined(MSDOS)extern int errno;#endif#ifdef __GNU_LIBRARY__#ifndef linux#include <signum.h>#endif#endif/* ----------------- System dependencies (with more includes) -----------*/#if !defined(VMS) || (!defined(VAXC) && !defined(__DECC))#include <sys/types.h>#include <sys/stat.h>#else /* VMS w/ VAXC or DECC */#include <types.h>#include <stat.h>#include <file.h> /* avoid <fcntl.h> in io.c */#endif#include <signal.h>#include "config.h"#ifdef __STDC__#define P(s) s#define MALLOC_ARG_T size_t#else#define P(s) ()#define MALLOC_ARG_T unsigned#define volatile#define const#endif#ifndef SIGTYPE#define SIGTYPE void#endif#ifdef SIZE_T_MISSINGtypedef unsigned int size_t;#endif#ifndef SZTC#define SZTC#define INTC#endif#ifdef STDC_HEADERS#include <stdlib.h>#include <string.h>#ifdef NeXT#include <libc.h>#undef atof#else#if defined(atarist) || defined(VMS)#include <unixlib.h>#else /* atarist || VMS */#ifndef MSDOS#include <unistd.h>#endif /* MSDOS */#endif /* atarist || VMS */#endif /* Next */#else /* STDC_HEADERS */#include "protos.h"#endif /* STDC_HEADERS */#if defined(ultrix) && !defined(Ultrix41)extern char * getenv P((char *name));extern double atof P((char *s));#endif#ifndef __GNUC__#ifdef sparc/* nasty nasty SunOS-ism */#include <alloca.h>#ifdef lintextern char *alloca();#endif#else /* not sparc */#if !defined(alloca) && !defined(ALLOCA_PROTO)extern char *alloca();#endif#endif /* sparc */#endif /* __GNUC__ */#ifdef HAVE_UNDERSCORE_SETJMP/* nasty nasty berkelixm */#define setjmp _setjmp#define longjmp _longjmp#endif/* * if you don't have vprintf, try this and cross your fingers. */#if defined(VPRINTF_MISSING)#define vfprintf(fp,fmt,arg) _doprnt((fmt), (arg), (fp))#endif#ifdef VMS/* some macros to redirect to code in vms/vms_misc.c */#define exit vms_exit#define open vms_open#define strerror vms_strerror#define strdup vms_strdupextern void exit P((int));extern int open P((const char *,int,...));extern char *strerror P((int));extern char *strdup P((const char *str));extern int vms_devopen P((const char *,int));# ifndef NO_TTY_FWRITE#define fwrite tty_fwrite#define fclose tty_fcloseextern size_t fwrite P((const void *,size_t,size_t,FILE *));extern int fclose P((FILE *));# endifextern FILE *popen P((const char *,const char *));extern int pclose P((FILE *));extern void vms_arg_fixup P((int *,char ***));/* some things not in STDC_HEADERS */extern int gnu_strftime P((char *,size_t,const char *,const struct tm *));extern int unlink P((const char *));extern int getopt P((int,char **,char *));extern int isatty P((int));#ifndef filenoextern int fileno P((FILE *));#endifextern int close(), dup(), dup2(), fstat(), read(), stat();#endif /*VMS*/#ifdef MSDOS#include <io.h>extern FILE *popen P((char *, char *));extern int pclose P((FILE *));#endif#define GNU_REGEX#ifdef GNU_REGEX#include "regex.h"#include "dfa.h"typedef struct Regexp { struct re_pattern_buffer pat; struct re_registers regs; struct regexp dfareg; int dfa;} Regexp;#define RESTART(rp,s) (rp)->regs.start[0]#define REEND(rp,s) (rp)->regs.end[0]#else /* GNU_REGEX */#endif /* GNU_REGEX */#ifdef atarist#define read _text_read /* we do not want all these CR's to mess our input */extern int _text_read (int, char *, int);#endif#ifndef DEFPATH#define DEFPATH ".:/usr/local/lib/awk:/usr/lib/awk"#endif#ifndef ENVSEP#define ENVSEP ':'#endif/* ------------------ Constants, Structures, Typedefs ------------------ */#define AWKNUM doubletypedef enum { /* illegal entry == 0 */ Node_illegal, /* binary operators lnode and rnode are the expressions to work on */ Node_times, Node_quotient, Node_mod, Node_plus, Node_minus, Node_cond_pair, /* conditional pair (see Node_line_range) */ Node_subscript, Node_concat, Node_exp, /* unary operators subnode is the expression to work on *//*10*/ Node_preincrement, Node_predecrement, Node_postincrement, Node_postdecrement, Node_unary_minus, Node_field_spec, /* assignments lnode is the var to assign to, rnode is the exp */ Node_assign, Node_assign_times, Node_assign_quotient, Node_assign_mod,/*20*/ Node_assign_plus, Node_assign_minus, Node_assign_exp, /* boolean binaries lnode and rnode are expressions */ Node_and, Node_or, /* binary relationals compares lnode and rnode */ Node_equal, Node_notequal, Node_less, Node_greater, Node_leq,/*30*/ Node_geq, Node_match, Node_nomatch, /* unary relationals works on subnode */ Node_not, /* program structures */ Node_rule_list, /* lnode is a rule, rnode is rest of list */ Node_rule_node, /* lnode is pattern, rnode is statement */ Node_statement_list, /* lnode is statement, rnode is more list */ Node_if_branches, /* lnode is to run on true, rnode on false */ Node_expression_list, /* lnode is an exp, rnode is more list */ Node_param_list, /* lnode is a variable, rnode is more list */ /* keywords *//*40*/ Node_K_if, /* lnode is conditonal, rnode is if_branches */ Node_K_while, /* lnode is condtional, rnode is stuff to run */ Node_K_for, /* lnode is for_struct, rnode is stuff to run */ Node_K_arrayfor, /* lnode is for_struct, rnode is stuff to run */ Node_K_break, /* no subs */ Node_K_continue, /* no stuff */ Node_K_print, /* lnode is exp_list, rnode is redirect */ Node_K_printf, /* lnode is exp_list, rnode is redirect */ Node_K_next, /* no subs */ Node_K_exit, /* subnode is return value, or NULL *//*50*/ Node_K_do, /* lnode is conditional, rnode stuff to run */ Node_K_return, Node_K_delete, Node_K_getline, Node_K_function, /* lnode is statement list, rnode is params */ /* I/O redirection for print statements */ Node_redirect_output, /* subnode is where to redirect */ Node_redirect_append, /* subnode is where to redirect */ Node_redirect_pipe, /* subnode is where to redirect */ Node_redirect_pipein, /* subnode is where to redirect */ Node_redirect_input, /* subnode is where to redirect */ /* Variables *//*60*/ Node_var, /* rnode is value, lnode is array stuff */ Node_var_array, /* array is ptr to elements, asize num of * eles */ Node_val, /* node is a value - type in flags */ /* Builtins subnode is explist to work on, proc is func to call */ Node_builtin, /* * pattern: conditional ',' conditional ; lnode of Node_line_range * is the two conditionals (Node_cond_pair), other word (rnode place) * is a flag indicating whether or not this range has been entered. */ Node_line_range, /* * boolean test of membership in array lnode is string-valued * expression rnode is array name */ Node_in_array, Node_func, /* lnode is param. list, rnode is body */ Node_func_call, /* lnode is name, rnode is argument list */ Node_cond_exp, /* lnode is conditonal, rnode is if_branches */ Node_regex,/*70*/ Node_hashnode, Node_ahash, Node_NF, Node_NR, Node_FNR, Node_FS, Node_RS, Node_FIELDWIDTHS, Node_IGNORECASE, Node_OFS, Node_ORS, Node_OFMT, Node_CONVFMT, Node_K_nextfile} NODETYPE;/* * NOTE - this struct is a rather kludgey -- it is packed to minimize * space usage, at the expense of cleanliness. Alter at own risk. */typedef struct exp_node { union { struct { union { struct exp_node *lptr; char *param_name; } l; union { struct exp_node *rptr; struct exp_node *(*pptr) (); Regexp *preg; struct for_loop_header *hd; struct exp_node **av; int r_ent; /* range entered */ } r; union { char *name; struct exp_node *extra; } x; short number; unsigned char reflags;# define CASE 1# define CONST 2# define FS_DFLT 4 } nodep; struct { AWKNUM fltnum; /* this is here for optimal packing of * the structure on many machines */ char *sp; size_t slen; unsigned char sref; char idx; } val; struct { struct exp_node *next; char *name; int length; struct exp_node *value; } hash;#define hnext sub.hash.next#define hname sub.hash.name#define hlength sub.hash.length#define hvalue sub.hash.value struct { struct exp_node *next; struct exp_node *name; struct exp_node *value; } ahash;#define ahnext sub.ahash.next#define ahname sub.ahash.name#define ahvalue sub.ahash.value } sub; NODETYPE type; unsigned short flags;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -