fewfewoijfewoijfewoij try to find circ dependencie
This commit is contained in:
parent
51abd2a174
commit
260041490f
14
bish.cc
14
bish.cc
|
@ -11,7 +11,7 @@
|
|||
#include <vector>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
// #include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sstream>
|
||||
|
@ -25,6 +25,10 @@ using namespace std;
|
|||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
struct sigaction act;
|
||||
act.sa_handler = ctrlCHandler;
|
||||
sigaction(SIGINT, &act, NULL);
|
||||
|
||||
stringstream prompt;
|
||||
static char* line = (char*)NULL;
|
||||
vector<string> path = split(getenv("PATH"), ':');
|
||||
|
@ -57,8 +61,7 @@ int main(int argc, char **argv){
|
|||
// char **args = v_to_cpp(split(line));
|
||||
// parse line
|
||||
command *cmd = parse(split(line));
|
||||
// print_cmd(cmd);
|
||||
// cout << endl;
|
||||
print_cmd(cmd);
|
||||
// clear line var
|
||||
free(line);
|
||||
line = (char*)NULL;
|
||||
|
@ -89,9 +92,10 @@ int main(int argc, char **argv){
|
|||
// run it
|
||||
// also check the path for things
|
||||
else if (kidpid == 0){
|
||||
|
||||
// io redirection
|
||||
if (cmd->outfile != "") {
|
||||
int outfd = open(cmd->outfile.c_str(), O_RDWR | O_CREAT | O_EXCL, 0644);
|
||||
int outfd = open(cmd->outfile.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0644);
|
||||
if (outfd < 0) {
|
||||
perror("outfile");
|
||||
exit(0);
|
||||
|
@ -101,6 +105,7 @@ int main(int argc, char **argv){
|
|||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd->infile != "") {
|
||||
int infd = open(cmd->infile.c_str(), O_RDONLY);
|
||||
if (infd < 0) {
|
||||
|
@ -133,6 +138,7 @@ int main(int argc, char **argv){
|
|||
|
||||
int status;
|
||||
|
||||
if (!cmd->background)
|
||||
do {
|
||||
if (waitpid(kidpid, &status, WUNTRACED | WCONTINUED) == -1) {
|
||||
perror("waitpid");
|
||||
|
|
8
parse.cc
8
parse.cc
|
@ -13,11 +13,11 @@ void print_cmd(command *cmd) {
|
|||
// cout << "args: " << endl;
|
||||
|
||||
if (cmd->background) cout << "backgroud: true" << endl;
|
||||
else cout << "background: false" << endl;
|
||||
|
||||
if (cmd->piping.c_str()) cout << "piping to: " << cmd->piping << endl;
|
||||
if (cmd->infile.c_str()) cout << "infile: " << cmd->infile << endl;
|
||||
if (cmd->outfile.c_str()) cout << "outfile: " << cmd->outfile << endl;
|
||||
if (cmd->piping != "") cout << "piping to: " << cmd->piping << endl;
|
||||
if (cmd->infile != "") cout << "infile: " << cmd->infile << endl;
|
||||
if (cmd->outfile != "") cout << "outfile: " << cmd->outfile << endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
|
||||
|
|
6
parse.h
6
parse.h
|
@ -1,13 +1,12 @@
|
|||
// Ben Harris
|
||||
|
||||
#ifndef _PARSE_
|
||||
#define _PARSE_
|
||||
#ifndef _PARSE_H_
|
||||
#define _PARSE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
// method definitions
|
||||
// command struct
|
||||
struct command {
|
||||
char** args;
|
||||
|
@ -17,6 +16,7 @@ struct command {
|
|||
string outfile;
|
||||
};
|
||||
|
||||
// method definitions
|
||||
void print_cmd(command *cmd);
|
||||
command *parse(vector<string> args);
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
using namespace std;
|
||||
|
||||
|
||||
void ctrlCHandler(int sig) {
|
||||
|
||||
}
|
||||
|
||||
// util methods
|
||||
vector<string> split(const char *str, char c) {
|
||||
vector<string> result;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Ben Harris
|
||||
|
||||
#ifndef _util_fns_
|
||||
#define _util_fns_
|
||||
#ifndef _UTIL_FNS_H_
|
||||
#define _UTIL_FNS_H_
|
||||
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
@ -9,6 +9,7 @@
|
|||
using namespace std;
|
||||
|
||||
// method definitions
|
||||
void ctrlCHandler(int sig);
|
||||
vector<string> split(const char *str, char c = ' ');
|
||||
char** v_to_cpp(vector<string> vargs);
|
||||
|
||||
|
|
Loading…
Reference in New Issue