aboutsummaryrefslogtreecommitdiffstats
path: root/cmd.h
blob: ce1d44c41e44ea6533bfef3d18e570611c8c05e6 (plain) (blame)
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
#ifndef CMD_H
#define CMD_H

#include <fcntl.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

typedef enum {
    CMD_NORMAL,
    CMD_PIPE,
    CMD_AND,
    CMD_OR,
    // add more command types as needed
} CommandType;

typedef struct Command {
    CommandType type; // the type of the command
    char **args;      // an array of strings for the arguments of the command
    int argc;
    struct Command *left;  // a pointer to the left sub-command
    struct Command *right; // a pointer to the right sub-command
    int redirectFD[3];
    char *redirectFile[3];
    bool background;
} Command;

void showPrompt();
Command *newCmd();

int runCmd(Command *cmd);
int runNormalCmd(Command *cmd);
int runPipeCmd(Command *cmd);
int runAndOrCmd(Command *cmd);

void freeCmd(Command *cmd);

void redirect(Command *cur);

#endif