-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.h
More file actions
395 lines (348 loc) · 15.8 KB
/
Copy pathruntime.h
File metadata and controls
395 lines (348 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/***************************************************************************
* Title: Runtime environment
* -------------------------------------------------------------------------
* Purpose: Runs commands
* Author: Stefan Birrer
* Version: $Revision: 1.1 $
* Last Modification: $Date: 2005/10/13 05:24:59 $
* File: $RCSfile: runtime.h,v $
* Copyright: (C) 2002 by Stefan Birrer
***************************************************************************/
/***************************************************************************
* ChangeLog:
* -------------------------------------------------------------------------
* $Log: runtime.h,v $
* Revision 1.1 2005/10/13 05:24:59 sbirrer
* - added the skeleton files
*
* Revision 1.3 2002/10/23 21:54:27 sempi
* beta release
*
* Revision 1.2 2002/10/21 04:47:05 sempi
* Milestone 2 beta
*
* Revision 1.1 2002/10/15 20:20:56 sempi
* Milestone 1
*
***************************************************************************/
#ifndef __RUNTIME_H__
#define __RUNTIME_H__
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/************System include***********************************************/
/************Private include**********************************************/
/************Defines and Typedefs*****************************************/
/* #defines and typedefs should have their names in all caps.
* Global variables begin with g. Global constants with k. Local
* variables should be in all lower case. When initializing
* structures and arrays, line everything up in neat columns.
*/
#undef EXTERN
#ifdef __RUNTIME_IMPL__
#define EXTERN
#define VAREXTERN(x, y) x = y;
#else
#define EXTERN extern
#define VAREXTERN(x, y) extern x;
#endif
typedef struct command_t
{
char* name;
char *cmdline;
char *redirect_in, *redirect_out;
int input_fd, output_fd;
int is_redirect_in, is_redirect_out;
int bg;
int argc;
char* argv[];
} commandT;
typedef struct Alias_L{
char* name;
char* cmd_name;
char* str;
struct Alias_L* next;
}AliasL;
/************Global Variables*********************************************/
/***********************************************************************
* Title: Force a program exit
* ---------------------------------------------------------------------
* Purpose: Signals that a program exit is required
***********************************************************************/
VAREXTERN(bool forceExit, FALSE);
/************Function Prototypes******************************************/
/***********************************************************************
* Title: Runs a command
* ---------------------------------------------------------------------
* Purpose: Runs a command.
* Input: a command structure
* Output: void
***********************************************************************/
EXTERN void RunCmd(commandT**,int);
/***********************************************************************
* Title: Runs a command in background
* ---------------------------------------------------------------------
* Purpose: Runs a command in background.
* Input: a command structure
* Output: void
***********************************************************************/
EXTERN void RunCmdBg(commandT*);
/***********************************************************************
* Title: Runs two command with a pipe
* ---------------------------------------------------------------------
* Purpose: Runs two command connected with a pipe.
* Input: two command structure
* Output: void
***********************************************************************/
EXTERN void RunCmdPipe(commandT**, int n);
/***********************************************************************
* Title: Runs two command with output redirection
* ---------------------------------------------------------------------
* Purpose: Runs a command and redirects the output to a file.
* Input: a command structure structure and a file name
* Output: void
***********************************************************************/
EXTERN void RunCmdRedirOut(commandT*, char*);
/***********************************************************************
* Title: Runs two command with input redirection
* ---------------------------------------------------------------------
* Purpose: Runs a command and redirects the input to a file.
* Input: a command structure structure and a file name
* Output: void
***********************************************************************/
EXTERN void RunCmdRedirIn(commandT*, char*);
/***********************************************************************
* Title: Stop the foreground process
* ---------------------------------------------------------------------
* Purpose: Stops the current foreground process if there is any.
* Input: void
* Output: void
***********************************************************************/
EXTERN void StopFgProc();
/***********************************************************************
* Title: Create a command structure
* ---------------------------------------------------------------------
* Purpose: Creates a command structure.
* Input: the number of arguments
* Output: the command structure
***********************************************************************/
EXTERN commandT* CreateCmdT(int);
/***********************************************************************
* Title: Release a command structure
* ---------------------------------------------------------------------
* Purpose: Frees the allocated memory of a command structure.
* Input: the command structure
* Output: void
***********************************************************************/
EXTERN void ReleaseCmdT(commandT**);
/***********************************************************************
* Title: Get the current working directory
* ---------------------------------------------------------------------
* Purpose: Gets the current working directory.
* Input: void
* Output: a string containing the current working directory
***********************************************************************/
EXTERN char* getCurrentWorkingDir();
/***********************************************************************
* Title: Get user name
* ---------------------------------------------------------------------
* Purpose: Gets user name logged in on the controlling terminal.
* Input: void
* Output: a string containing the user name
***********************************************************************/
EXTERN char* getLogin();
/***********************************************************************
* Title: Check the jobs
* ---------------------------------------------------------------------
* Purpose: Checks the status of the background jobs.
* Input: void
* Output: void
***********************************************************************/
EXTERN void CheckJobs();
/************************************************************************
* Title: Start jobs in background
* ---------------------------------------------------------------------
* Purpose: To start a process which is hanging in background
* Input: the command structure
* Output: void
***********************************************************************/
EXTERN void start_bg(commandT*);
/************************************************************************
* Title: Start jobs in foreground
* ---------------------------------------------------------------------
* Purpose: To start a process which is hanging in foreground
* Input: the command structure
* Output: void
***********************************************************************/
EXTERN void start_fg(commandT*);
/************************************************************************
* Title: get command
* ---------------------------------------------------------------------
* Purpose: To get commandline from a command structure
* Input: the command structure, int flag
* Output: void
***********************************************************************/
EXTERN char* get_cmd(commandT* cmd, int flag);
/************************************************************************
* Title: Display jobs
* ---------------------------------------------------------------------
* Purpose: To display background jobs in the terminal
* Input: void
* Output: void
***********************************************************************/
EXTERN void DisplayJobs();
/************************************************************************
* Title: Hang fg jobs to bg
* ---------------------------------------------------------------------
* Purpose: To hang up foreground jobs in the background
* Input: void
* Output: void
***********************************************************************/
EXTERN void hang_fg();
/************************************************************************
* Title: add bg job
* ---------------------------------------------------------------------
* Purpose: To add bg jobs to the bgjob list
* Input: int processid, char* process status, bg job struct current
* Output: void
***********************************************************************/
EXTERN void add_bg(int pid, char *job_status, commandT* cmd);
/************************************************************************
* Title: delete bg job
* ---------------------------------------------------------------------
* Purpose: To delete bg jobs from the bgjob list
* Input: int job id
* Output: void
***********************************************************************/
EXTERN void del_bg(int job_id);
/************************************************************************
* Title: delete bg job list
* ---------------------------------------------------------------------
* Purpose: To delete the bg job list and free the memory
* Input: void
* Output: void
***********************************************************************/
EXTERN void del_bglist();
/************************************************************************
* Title: check done bg job
* ---------------------------------------------------------------------
* Purpose: To check done bg job in the list
* Input: void
* Output: void
***********************************************************************/
EXTERN void check_done();
/************************************************************************
* Title: kill foreground job
* ---------------------------------------------------------------------
* Purpose: To kill foreground jobs
* Input: void
* Output: void
***********************************************************************/
EXTERN void kill_fg();
/************************************************************************
* Title: add foreground job
* ---------------------------------------------------------------------
* Purpose: To add foreground job to foreground job list
* Input: int process id, char* job status, the command structure
* Output: void
***********************************************************************/
EXTERN void add_fg(int pid, char *job_status, commandT* cmd);
/************************************************************************
* Title: delete foreground job
* ---------------------------------------------------------------------
* Purpose: To delete foreground job from foreground job list
* Input: int job id
* Output: void
***********************************************************************/
EXTERN void del_fg(int job_id);
/************************************************************************
* Title: delete foreground job list
* ---------------------------------------------------------------------
* Purpose: To delete foreground job list and free the memory
* Input: void
* Output: void
***********************************************************************/
EXTERN void del_fglist();
/************************************************************************
* Title: show alias
* ---------------------------------------------------------------------
* Purpose: To show exist aliases
* Input: void
* Output: void
***********************************************************************/
EXTERN void show_Alias();
/************************************************************************
* Title: delete alias
* ---------------------------------------------------------------------
* Purpose: To delete alias from the alias list
* Input: char* name of alias
* Output: void
***********************************************************************/
EXTERN void del_Alias(char* name);
/************************************************************************
* Title: add alias
* ---------------------------------------------------------------------
* Purpose: To add an alias to alias list
* Input: the command structure
* Output: void
***********************************************************************/
EXTERN void add_Alias(commandT* cmd);
/************************************************************************
* Title: is Alias
* ---------------------------------------------------------------------
* Purpose: To judge the command contains alias or not
* Input: the array of command structure
* Output: void
***********************************************************************/
EXTERN void isAlias(commandT** cmd, int n);
/************************************************************************
* Title: get name
* ---------------------------------------------------------------------
* Purpose: To get name of an alias
* Input: char* str
* Output: char*
***********************************************************************/
EXTERN char* get_name(char* str);
/************************************************************************
* Title: get alias
* ---------------------------------------------------------------------
* Purpose: To get the entire alias command line
* Input: char* str
* Output: char*
***********************************************************************/
EXTERN char* get_alias(char* str);
/************************************************************************
* Title: get command name
* ---------------------------------------------------------------------
* Purpose: To get the command name of an alias
* Input: char* str
* Output: char*
***********************************************************************/
EXTERN char* get_cmd_name(char* str);
/************************************************************************
* Title: get execute
* ---------------------------------------------------------------------
* Purpose: To get the command to be excecute from an alias
* Input: char* str
* Output: char*
***********************************************************************/
EXTERN char* get_exec(char* str);
/************************************************************************
* Title: delete alias list
* ---------------------------------------------------------------------
* Purpose: To delete the alias list an free the memory
* Input: void
* Output: void
***********************************************************************/
EXTERN void del_Aliaslist();
/************************************************************************
* Title: parse ~
* ---------------------------------------------------------------------
* Purpose: To substitude ~ in the command
* Input: char* input
* Output: char*
***********************************************************************/
EXTERN char* parse_wan(char* input);
/************External Declaration*****************************************/
/**************Definition***************************************************/
#endif /* __RUNTIME_H__ */