/
pr7.h
146 lines (105 loc) · 3.55 KB
/
pr7.h
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
/* CMPSC 311, Spring 2013, Project 7
*
* Author: Jacob Jones
* Email: jaj5333@psu.edu
*
* Author: Scott Cheloha
* Email: ssc5145@psu.edu
*/
#ifndef PR7_H
#define PR7_H
/* CMPSC 311 Project 7 starter kit
*
* This file is provided as part of the project description and starter kit.
* If you modify it, then put your name, email address, and the date, in this
* comment, and include this file in the materials you turn in.
*/
/*----------------------------------------------------------------------------*/
#include <limits.h>
#include <sys/param.h>
#include <stdbool.h>
/* Global Variables */
extern char *s_filename;
extern const char *prog;
extern char *infile_name;
extern int i_flag;
extern int e_flag;
extern int v_flag;
extern int d_flag;
extern int s_flag;
extern int exec_flag; // 0 for vp, 1 for ve, 2 for lp
extern int command_count;
extern pid_t shell_pid;
extern pid_t fg_pid;
extern pid_t fg_pgid;
extern pid_t bg_pgid;
extern struct process_list *bg_processes;
extern char **environ;
/*----------------------------------------------------------------------------*/
/* Prototypes for functions in pr7.3.c */
/* Prints information for using the shell */
void usage(int status);
/* Starts the prompt with a greeting and lists
* the command line options set.
* Only runs if -v is set at the command line.
*/
void verbose_greeting(void);
/* Reads the startup file specified by the user
* pr7.init is run by default, unless -s is set from the command line.
* a "-" argument to -s sets stdin as the stream to read,
* otherwise the argument is opened as a normal file.
*
* If pr7.init is not present, nothing is said.
* If the file argument to -s is not present the shell complains and exits.
*/
void read_startup_file(bool quiet);
/* prints the prompt to standard output.
* if newline != 0, a newline is printed first.
*/
void print_prompt(int newline);
/* Loop that prints the prompt and processes
* commands entered by the user, line by line.
* Only runs if -i is set at the command line.
*/
int read_input(int argc, char *argv[]);
/* Function containing a getopt() loop for
* processing command line arguments
* and assigning the appropriate global variables.
*
* Runs once at the start of pr7's main()
*/
void eval_options(int argc, char *argv[]);
/* Evaluates a given command and takes appropriate action. */
int eval_line(char *cmdline);
/* Builds the Argv[] array from a command line.
* Run both in prompt() and when a startup file is specified.
*/
int parse(char *buf, char *Argv[]);
void shell_msg(const char* function_name, const char* msg);
/* custom signal handlers for SIGINT and SIGCHLD */
void handler_SIGCHLD(int signum);
void handler_SIGINT(int signum);
/*----------------------------------------------------------------------------*/
/* Some limits for the shell. */
/*
* MAX_LINE input line length
* MAX_PATH directory name length
* MAX_CHILDREN number of child processes
*/
/* use the minimal value for maximal portability */
#ifdef _POSIX_C_SOURCE
#define MAX_LINE _POSIX_MAX_INPUT
#define MAX_PATH _POSIX_PATH_MAX
#define MAX_CHILDREN _POSIX_CHILD_MAX
#else /* use the default value for this system */
#define MAX_LINE MAX_INPUT
#define MAX_PATH PATH_MAX
#define MAX_CHILDREN CHILD_MAX
/* Alternative versions can be obtained from
* #include <unistd.h>
* sysconf(_SC_LINE_MAX)
* sysconf(_SC_CHILD_MAX)
*/
#endif /* _POSIX_C_SOURCE */
/*----------------------------------------------------------------------------*/
#endif /* PR7_H */