]> git.ipfire.org Git - thirdparty/bash.git/blame - general.h
Imported from ../bash-1.14.7.tar.gz.
[thirdparty/bash.git] / general.h
CommitLineData
726f6388
JA
1/* general.h -- defines that everybody likes to use. */
2
3/* Copyright (C) 1993 Free Software Foundation, Inc.
4
5 This file is part of GNU Bash, the Bourne Again SHell.
6
7 Bash is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with Bash; see the file COPYING. If not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21#if !defined (_GENERAL_H)
22#define _GENERAL_H
23
24#include "stdc.h"
25
26/* just to make sure */
27#if defined (HAVE_UNISTD_H)
28# ifdef CRAY
29# define word __word
30# endif
31# include <unistd.h>
32# ifdef CRAY
33# undef word
34# endif
35#endif
36
37#if !defined (NULL)
38# if defined (__STDC__)
39# define NULL ((void *) 0)
40# else
41# define NULL 0x0
42# endif /* !__STDC__ */
43#endif /* !NULL */
44
45#if defined (HAVE_STRING_H)
46# include <string.h>
47#else
48# include <strings.h>
49#endif /* !HAVE_STRING_H */
50
51#define pointer_to_int(x) (int)((long)(x))
52
53#if !defined (savestring)
54 extern char *xmalloc ();
55# if !defined (strcpy)
56 extern char *strcpy ();
57# endif
58# define savestring(x) (char *)strcpy (xmalloc (1 + strlen (x)), (x))
59#endif
60
61#ifndef whitespace
62#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
63#endif
64
65#ifndef digit
66#define digit(c) ((c) >= '0' && (c) <= '9')
67#endif
68
69#ifndef isletter
70#define isletter(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
71#endif
72
73#ifndef digit_value
74#define digit_value(c) ((c) - '0')
75#endif
76
77/* Definitions used in subst.c and by the `read' builtin for field
78 splitting. */
79#define spctabnl(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
80
81#if !defined (__STDC__) && !defined (strchr)
82extern char *strchr (), *strrchr ();
83#endif /* !strchr */
84
85#ifndef member
86# if defined (alpha) && defined (__GNUC__) /* XXX */
87 extern char *strchr ();
88# endif
89# define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
90#endif
91
92/* All structs which contain a `next' field should have that field
93 as the first field in the struct. This means that functions
94 can be written to handle the general case for linked lists. */
95typedef struct g_list {
96 struct g_list *next;
97} GENERIC_LIST;
98
99/* Here is a generic structure for associating character strings
100 with integers. It is used in the parser for shell tokenization. */
101typedef struct {
102 char *word;
103 int token;
104} STRING_INT_ALIST;
105
106/* A macro to avoid making an uneccessary function call. */
107#define REVERSE_LIST(list, type) \
108 ((list && list->next) ? (type)reverse_list ((GENERIC_LIST *)list) : (type)(list))
109
110#if __GNUC__ > 1
111# define FASTCOPY(s, d, n) __builtin_memcpy (d, s, n)
112#else /* !__GNUC__ */
113# if defined (USG) && !defined (HAVE_BCOPY)
114# if defined (MEMMOVE_MISSING)
115# define FASTCOPY(s, d, n) memcpy (d, s, n)
116# else
117# define FASTCOPY(s, d, n) memmove (d, s, n)
118# endif /* !MEMMOVE_MISSING */
119# else
120# define FASTCOPY(s, d, n) bcopy (s, d, n)
121# endif /* !USG || HAVE_BCOPY */
122#endif /* !__GNUC__ */
123
124/* String comparisons that possibly save a function call each. */
125#define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0)
126#define STREQN(a, b, n) ((a)[0] == (b)[0] && strncmp(a, b, n) == 0)
127
128/* More convenience definitions that possibly save system or libc calls. */
129#define STRLEN(s) (((s) && (s)[0]) ? ((s)[1] ? ((s)[2] ? strlen(s) : 2) : 1) : 0)
130#define FREE(s) do { if (s) free (s); } while (0)
131#define MEMBER(c, s) (((c) && !(s)[1] && c == s[0]) || (member(c, s)))
132
133/* What type is a `generic' pointer? This is used as the first argument
134 to xrealloc. */
135#if defined (__STDC__)
136typedef void *GENPTR;
137#else
138typedef char *GENPTR;
139#endif
140
141/* Function pointers can be declared as (Function *)foo. */
142#if !defined (__FUNCTION_DEF)
143# define __FUNCTION_DEF
144typedef int Function ();
145typedef void VFunction ();
146typedef char *CPFunction ();
147typedef char **CPPFunction ();
148#endif /* _FUNCTION_DEF */
149
150#define NOW ((time_t) time ((time_t *) 0))
151
152/* Some defines for calling file status functions. */
153#define FS_EXISTS 0x1
154#define FS_EXECABLE 0x2
155#define FS_EXEC_PREFERRED 0x4
156#define FS_EXEC_ONLY 0x8
157
158/* Posix and USG systems do not guarantee to restart a read () that is
159 interrupted by a signal. */
160#if defined (USG) || defined (_POSIX_VERSION)
161# define NO_READ_RESTART_ON_SIGNAL
162#endif /* USG || _POSIX_VERSION */
163
164/* Here is a definition for set_signal_handler () which simply expands to
165 a call to signal () for non-Posix systems. The code for set_signal_handler
166 in the Posix case resides in general.c. */
167
168#if defined (VOID_SIGHANDLER)
169# define sighandler void
170#else
171# define sighandler int
172#endif /* !VOID_SIGHANDLER */
173
174typedef sighandler SigHandler ();
175
176#if !defined (_POSIX_VERSION)
177# define set_signal_handler(sig, handler) (SigHandler *)signal (sig, handler)
178#else
179extern SigHandler *set_signal_handler ();
180#endif /* _POSIX_VERSION */
181
182/* This function is defined in trap.c. */
183extern SigHandler *set_sigint_handler __P((void));
184
185/* Declarations for functions defined in general.c */
186extern char *xmalloc __P((int));
187extern char *xrealloc __P((void *, int));
188extern void xfree __P((char *));
189extern char *itos __P((int));
190extern int all_digits __P((char *));
191extern long string_to_long __P((char *));
192extern int legal_identifier __P((char *));
193extern int check_identifier __P((WORD_DESC *, int));
194extern void unset_nodelay_mode __P((int));
195extern void map_over_words __P((WORD_LIST *, Function *));
196
197extern void map_over_list __P((GENERIC_LIST *, Function *));
198extern GENERIC_LIST *reverse_list ();
199extern GENERIC_LIST *delete_element ();
200extern GENERIC_LIST *list_append ();
201extern int list_length ();
202extern int qsort_string_compare ();
203
204extern int find_name_in_list __P((char *, char **));
205extern int array_len __P((char **));
206extern void free_array __P((char **));
207extern char **copy_array __P((char **));
208extern void strip_leading __P((char *));
209extern void strip_trailing __P((char *, int));
210extern char *canonicalize_pathname __P((char *));
211extern char *make_absolute __P((char *, char *));
212extern int absolute_pathname __P((char *));
213extern int absolute_program __P((char *));
214extern char *base_pathname __P((char *));
215extern char *full_pathname __P((char *));
216extern char *strindex __P((char *, char *));
217extern void set_lines_and_columns __P((int, int));
218extern void xbcopy __P((char *, char *, int));
219extern char *polite_directory_format __P((char *));
220extern void tilde_initialize __P((void));
221
222#if !defined (strerror)
223extern char *strerror __P((int));
224#endif
225
226#if defined (RLIMTYPE)
227extern RLIMTYPE string_to_rlimtype __P((char *));
228extern void print_rlimtype __P((RLIMTYPE, int));
229#endif
230
231#if !defined (HAVE_STRCASECMP)
232extern int strnicmp __P((char *, char *, int));
233extern int stricmp __P((char *, char *));
234#else /* HAVE_STRCASECMP */
235# define stricmp strcasecmp
236# define strnicmp strncasecmp
237#endif /* HAVE_STRCASECMP */
238
239extern int dup2 __P((int, int));
240extern char *getwd __P((char *));
241extern int getdtablesize __P((void));
242
243#if defined (USG) && !defined (HAVE_GETHOSTNAME)
244extern int gethostname __P((char *, int));
245#endif /* USG && !HAVE_GETHOSTNAME */
246
247#endif /* _GENERAL_H */