]> git.ipfire.org Git - thirdparty/bash.git/blame - general.h
Imported from ../bash-2.01.1.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
ccc6cda3
JA
21#if !defined (_GENERAL_H_)
22#define _GENERAL_H_
726f6388
JA
23
24#include "stdc.h"
25
d166f048
JA
26#include "bashtypes.h"
27
28#if defined (HAVE_STRING_H)
29# include <string.h>
30#else
31# include <strings.h>
32#endif /* !HAVE_STRING_H */
33
ccc6cda3
JA
34/* Generic pointer type. */
35#if defined (__STDC__)
36# define PTR_T void *
37#else
38# define PTR_T char *
726f6388
JA
39#endif
40
ccc6cda3 41/* NULL pointer type. */
726f6388
JA
42#if !defined (NULL)
43# if defined (__STDC__)
44# define NULL ((void *) 0)
45# else
46# define NULL 0x0
47# endif /* !__STDC__ */
48#endif /* !NULL */
49
726f6388
JA
50#define pointer_to_int(x) (int)((long)(x))
51
ccc6cda3
JA
52extern char *xmalloc (), *xrealloc ();
53
54#if defined (alpha) && defined (__GNUC__) && !defined (strchr) && !defined (__STDC__)
55extern char *strchr (), *strrchr ();
56#endif
57
58#if !defined (strcpy)
59extern char *strcpy ();
60#endif
61
726f6388 62#if !defined (savestring)
726f6388
JA
63# define savestring(x) (char *)strcpy (xmalloc (1 + strlen (x)), (x))
64#endif
65
ccc6cda3
JA
66#ifndef member
67# define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
68#endif
69
726f6388
JA
70#ifndef whitespace
71#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
72#endif
73
74#ifndef digit
75#define digit(c) ((c) >= '0' && (c) <= '9')
76#endif
77
78#ifndef isletter
79#define isletter(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
80#endif
81
82#ifndef digit_value
83#define digit_value(c) ((c) - '0')
84#endif
85
ccc6cda3
JA
86/* Define exactly what a legal shell identifier consists of. */
87#define legal_variable_starter(c) (isletter(c) || (c == '_'))
88#define legal_variable_char(c) (isletter (c) || digit (c) || c == '_')
89
726f6388
JA
90/* Definitions used in subst.c and by the `read' builtin for field
91 splitting. */
92#define spctabnl(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
93
726f6388
JA
94/* All structs which contain a `next' field should have that field
95 as the first field in the struct. This means that functions
96 can be written to handle the general case for linked lists. */
97typedef struct g_list {
98 struct g_list *next;
99} GENERIC_LIST;
100
101/* Here is a generic structure for associating character strings
102 with integers. It is used in the parser for shell tokenization. */
103typedef struct {
104 char *word;
105 int token;
106} STRING_INT_ALIST;
107
108/* A macro to avoid making an uneccessary function call. */
109#define REVERSE_LIST(list, type) \
ccc6cda3
JA
110 ((list && list->next) ? (type)reverse_list ((GENERIC_LIST *)list) \
111 : (type)(list))
726f6388
JA
112
113#if __GNUC__ > 1
114# define FASTCOPY(s, d, n) __builtin_memcpy (d, s, n)
115#else /* !__GNUC__ */
ccc6cda3
JA
116# if !defined (HAVE_BCOPY)
117# if !defined (HAVE_MEMMOVE)
726f6388
JA
118# define FASTCOPY(s, d, n) memcpy (d, s, n)
119# else
120# define FASTCOPY(s, d, n) memmove (d, s, n)
ccc6cda3
JA
121# endif /* !HAVE_MEMMOVE */
122# else /* HAVE_BCOPY */
726f6388 123# define FASTCOPY(s, d, n) bcopy (s, d, n)
ccc6cda3 124# endif /* HAVE_BCOPY */
726f6388
JA
125#endif /* !__GNUC__ */
126
127/* String comparisons that possibly save a function call each. */
128#define STREQ(a, b) ((a)[0] == (b)[0] && strcmp(a, b) == 0)
129#define STREQN(a, b, n) ((a)[0] == (b)[0] && strncmp(a, b, n) == 0)
130
131/* More convenience definitions that possibly save system or libc calls. */
132#define STRLEN(s) (((s) && (s)[0]) ? ((s)[1] ? ((s)[2] ? strlen(s) : 2) : 1) : 0)
133#define FREE(s) do { if (s) free (s); } while (0)
134#define MEMBER(c, s) (((c) && !(s)[1] && c == s[0]) || (member(c, s)))
135
ccc6cda3
JA
136/* A fairly hairy macro to check whether an allocated string has more room,
137 and to resize it using xrealloc if it does not.
138 STR is the string (char *)
139 CIND is the current index into the string (int)
140 ROOM is the amount of additional room we need in the string (int)
141 CSIZE is the currently-allocated size of STR (int)
142 SINCR is how much to increment CSIZE before calling xrealloc (int) */
143
144#define RESIZE_MALLOCED_BUFFER(str, cind, room, csize, sincr) \
145 do { \
146 if ((cind) + (room) >= csize) \
147 { \
148 while ((cind) + (room) >= csize) \
149 csize += (sincr); \
150 str = xrealloc (str, csize); \
151 } \
152 } while (0)
726f6388
JA
153
154/* Function pointers can be declared as (Function *)foo. */
ccc6cda3
JA
155#if !defined (_FUNCTION_DEF)
156# define _FUNCTION_DEF
726f6388
JA
157typedef int Function ();
158typedef void VFunction ();
159typedef char *CPFunction ();
160typedef char **CPPFunction ();
161#endif /* _FUNCTION_DEF */
162
163#define NOW ((time_t) time ((time_t *) 0))
164
165/* Some defines for calling file status functions. */
166#define FS_EXISTS 0x1
167#define FS_EXECABLE 0x2
168#define FS_EXEC_PREFERRED 0x4
169#define FS_EXEC_ONLY 0x8
ccc6cda3
JA
170#define FS_DIRECTORY 0x10
171#define FS_NODIRS 0x20
726f6388 172
ccc6cda3
JA
173/* Declarations for functions defined in xmalloc.c */
174extern char *xmalloc __P((size_t));
175extern char *xrealloc __P((void *, size_t));
176extern void xfree __P((char *));
726f6388 177
ccc6cda3
JA
178/* Declarations for functions defined in general.c */
179extern void posix_initialize __P((int));
726f6388 180
ccc6cda3
JA
181extern char *itos __P((int));
182extern long string_to_long __P((char *));
726f6388 183
ccc6cda3
JA
184#if defined (RLIMTYPE)
185extern RLIMTYPE string_to_rlimtype __P((char *));
186extern void print_rlimtype __P((RLIMTYPE, int));
187#endif
726f6388 188
ccc6cda3
JA
189extern void timeval_to_secs ();
190extern void print_timeval ();
191extern void clock_t_to_secs ();
192extern void print_time_in_hz ();
726f6388 193
726f6388 194extern int all_digits __P((char *));
ccc6cda3 195extern int legal_number __P((char *, long *));
726f6388
JA
196extern int legal_identifier __P((char *));
197extern int check_identifier __P((WORD_DESC *, int));
ccc6cda3 198
726f6388 199extern void unset_nodelay_mode __P((int));
ccc6cda3
JA
200extern void check_dev_tty __P((void));
201extern int same_file (); /* too many problems with prototype */
d166f048 202extern int move_to_high_fd __P((int, int, int));
ccc6cda3
JA
203extern int check_binary_file __P((unsigned char *, int));
204
726f6388
JA
205extern char *canonicalize_pathname __P((char *));
206extern char *make_absolute __P((char *, char *));
207extern int absolute_pathname __P((char *));
208extern int absolute_program __P((char *));
209extern char *base_pathname __P((char *));
210extern char *full_pathname __P((char *));
726f6388 211extern char *polite_directory_format __P((char *));
726f6388 212
ccc6cda3 213extern char *extract_colon_unit __P((char *, int *));
726f6388 214
ccc6cda3
JA
215extern void tilde_initialize __P((void));
216extern char *bash_tilde_expand __P((char *));
726f6388 217
d166f048
JA
218#if defined (__STDC__) && defined (gid_t)
219extern int group_member __P((int));
220#else
221extern int group_member __P((gid_t));
222#endif
223extern char **get_group_list __P((int *));
224
ccc6cda3 225#endif /* _GENERAL_H_ */