Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tw/tw.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1989-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* tw common definitions
26
*/
27
28
#include <ast.h>
29
#include <expr.h>
30
#include <ls.h>
31
#include <find.h>
32
#include <fs3d.h>
33
#include <ftwalk.h>
34
#include <magic.h>
35
#include <error.h>
36
#include <debug.h>
37
38
#include "cmdarg.h"
39
#include "ftwlocal.h"
40
41
#define ignorecase fts_number
42
43
#define PATH(f) ((f)->status==FTW_NAME?(f)->name:(f)->path)
44
45
#define ACT_CMDARG 1
46
#define ACT_CODE 2
47
#define ACT_CODETYPE 3
48
#define ACT_EVAL 4
49
#define ACT_INTERMEDIATE 5
50
#define ACT_LIST 6
51
#define ACT_SNAPSHOT 7
52
53
#define CMD_IMPLICIT (CMD_USER<<0)
54
55
#define MEMMAKE(s,o) (((s)<<8)|((o)&((1<<8)-1)))
56
#define MEMINDEX(x) (((x)>>8)&((1<<8)-1))
57
#define MEMOFFSET(x) ((x)&((1<<8)-1))
58
59
#define T_type 64
60
#define T_DATE (T_type+1)
61
#define T_GID (T_type+2)
62
#define T_MODE (T_type+3)
63
#define T_PERM (T_type+4)
64
#define T_UID (T_type+5)
65
66
#define F_args 1
67
#define F_atime 2
68
#define F_blocks 3
69
#define F_blksize 4
70
#define F_checksum 5
71
#define F_ctime 6
72
#define F_dev 7
73
#define F_fstype 8
74
#define F_gid 9
75
#define F_gidok 10
76
#define F_info 11
77
#define F_ino 12
78
#define F_level 13
79
#define F_local 14
80
#define F_mode 15
81
#define F_magic 16
82
#define F_md5sum 17
83
#define F_mime 18
84
#define F_mtime 19
85
#define F_name 20
86
#define F_nlink 21
87
#define F_parent 22
88
#define F_perm 23
89
#define F_path 24
90
#define F_rdev 25
91
#define F_size 26
92
#define F_status 27
93
#define F_symlink 28
94
#define F_type 29
95
#define F_uid 30
96
#define F_uidok 31
97
#define F_url 32
98
#define F_view 33
99
#define F_visit 34
100
101
#define C_AGAIN 35
102
#define C_BLK 36
103
#define C_C 37
104
#define C_CHR 38
105
#define C_CTG 39
106
#define C_D 40
107
#define C_DC 41
108
#define C_DIR 42
109
#define C_DNR 43
110
#define C_DNX 44
111
#define C_DOOR 45
112
#define C_DP 46
113
#define C_FIFO 47
114
#define C_FMT 48
115
#define C_FOLLOW 49
116
#define C_LNK 50
117
#define C_NOPOST 51
118
#define C_NR 52
119
#define C_NS 53
120
#define C_NX 54
121
#define C_REG 55
122
#define C_SOCK 56
123
#define C_SKIP 57
124
125
#define X_cmdarg 58
126
#define X_cmdflush 59
127
#define X_sum 60
128
129
#define M_MEMBER 61
130
131
typedef struct /* unique file identifier */
132
{
133
long di[2]; /* dev,ino */
134
} Fileid_t;
135
136
typedef struct /* Fileid_t visit */
137
{
138
Dtlink_t link; /* table link */
139
Fileid_t id; /* file id */
140
Extype_t value[1]; /* visit values */
141
} Visit_t;
142
143
typedef struct Local_s /* local struct */
144
{
145
struct Local_s* next; /* next in free list */
146
Extype_t value[1]; /* member values */
147
} Local_t;
148
149
typedef struct Snapshot_s /* snapshot state */
150
{
151
Sfio_t* sp; /* previous snapshot stream */
152
Sfio_t* tmp; /* tmp string stream */
153
char* prev; /* previous snapshot record */
154
struct
155
{
156
char* path; /* path format */
157
char* easy; /* easy format */
158
char* hard; /* hard format */
159
int delim; /* format delimiter char */
160
} format;
161
} Snapshot_t;
162
163
typedef struct /* program state */
164
{
165
int act; /* leaf node ACT_* */
166
int actII; /* real action for intermediate */
167
Exnode_t* action; /* action expression */
168
int args; /* command arg count */
169
Cmdarg_t* cmd; /* command arg state */
170
int cmdflags; /* cmdopen() flags */
171
int compiled; /* excomp() complete */
172
int errexit; /* exit tw when cmd exit > this */
173
int errors; /* error count */
174
Exdisc_t expr; /* expr discipline */
175
Find_t* find; /* fast find handle */
176
int finderror; /* fast find generation error */
177
int ftwflags; /* tree walk flags */
178
Dt_t* fstab; /* fs type hash table */
179
int icase; /* ignore case in sort */
180
int ignore; /* ignore cmd and dir errors */
181
int info; /* ftw.info checked by user */
182
int intermediate; /* generate intermediate dirs */
183
Local_t* local; /* local struct free list */
184
int localfs; /* restrict to local fs mounts */
185
int localmem; /* ftw.local member count */
186
Magic_t* magic; /* magic tests */
187
Magicdisc_t magicdisc; /* magic discipline */
188
char* pattern; /* fast find pattern */
189
Expr_t* program; /* compiled expressions */
190
int reverse; /* reverse sort sense */
191
Exnode_t* select; /* select expression */
192
int separator; /* xargs list separator */
193
Snapshot_t snapshot; /* snapshot state */
194
int (*sort)(Ftw_t*, Ftw_t*); /* sorter */
195
Exnode_t* sortkey; /* sort key list */
196
Dt_t* vistab; /* visit hash table */
197
int visitmem; /* visit member count */
198
} State_t;
199
200
extern State_t state;
201
202
extern void compile(char*, int);
203
extern long eval(Exnode_t*, Ftw_t*);
204
extern long getnum(Exid_t*, Ftw_t*);
205
extern ssize_t print(Sfio_t*, Ftw_t*, const char*);
206
207