aboutsummaryrefslogtreecommitdiff
path: root/src/main.cc
blob: a884f789e62076251ad3b2524d5fd69e43846bc5 (plain)
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

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <iostream>
#include <vector>
#include <string>

#include "all.h"
#include "test.h"

using namespace std;
using namespace ov4;

/* Global variables */
char sbuf[MAXLINE];         /* for composing sprintf messages */

/*
 * main - The shell's main routine 
 */
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) 
{
    init(); 
    //test(argv);

    char cmdline[MAXLINE];

    /* Redirect stderr to stdout (so that driver will get all output
     * on the pipe connected to stdout) */
    dup2(1, 2);

    /* Parse the command line */

    exe_option(argv);

    // while ((c = getopt(argc, argv, "hvp")) != EOF) {
    //     switch (c) {
    //     case 'h':             /* print help message */
    //         usage();
	//     break;
    //     case 'v':             /* emit additional diagnostic info */
    //         verbose = true;
	//     break;
    //     case 'p':             /* don't print a prompt */
    //         emit_prompt = 0;  /* handy for automatic testing */
	//     break;
	// default:
    //         usage();
	// }
    // }

    

    /* This one provides a clean way to kill the shell */
    Signal(SIGQUIT, sigquit_handler); 

    /* Initialize the job list */
    initjobs();

    /* Execute the shell's read/eval loop */
    while (1) {

	/* Read command line */
    print_prompt();

	if ((fgets(cmdline, MAXLINE, stdin) == NULL) && ferror(stdin))
	    app_error("fgets error");
	if (feof(stdin)) { /* End of file (ctrl-d) */
	    fflush(stdout);
	    exit(0);
	}

	/* Evaluate the command line */
	eval(cmdline);
	fflush(stdout);
	fflush(stdout);
    } 

    exit(0); /* control never reaches here */
}