aboutsummaryrefslogtreecommitdiffstats
path: root/cmd.h
blob: d591111f57cd44afbe941182780bd2f7dab79cc7 (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
#ifndef CMD_H
#define CMD_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>
#include <fcntl.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);
void freecmd(Command *cmd);
void printcmd(Command *cmd);

#endif