-
Notifications
You must be signed in to change notification settings - Fork 1
/
lashparser.h
55 lines (46 loc) · 1.73 KB
/
lashparser.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
#ifndef LASHPARSER_H_
#define LASHPARSER_H_
#include <glob.h>
#define QUOTE_MISMATCH -1
#define VALID 1
#define NO_ARGS 0
struct Command{
char *command;
char **args;
char symbolAfter;
char *redirectIn;
char *redirectOut;
int argNum;
};
struct LashParser {
int maxcommands;
int maxargs;
int maxarglength;
int maxinput;
struct Command **commands;
int commandNum;
};
// struct construction and destruction functions
struct Command *newCommand(struct LashParser *parser);
struct LashParser *newLashParser(int commands, int args, int arglength);
void clearParser(struct LashParser *parser);
// command building and parsing functions
int buildCommand (struct LashParser *parser, char *line);
void splitCommands(struct LashParser *parser, char *line);
void parseCommand (struct LashParser *parser, struct Command *commData, int commandIndex);
// string check functions
int atEnd(const int index, const char *line);
int atStart(const int index, const char *line);
int isEscaped(const char *line, const int index);
int insideQuotes(const int index, int quotes[][3], const int numberOfQuotePairs);
int indexNotInArray(int array[][3], const int arrayIndex, const int foundCharIndex);
int findQuoteLocations(const char *line, int quotes[][3]);
int followedBySemiColonOrAmpersand(const char *line, const int index);
// string cleanup/manipulation functions
int copyString(char *copyTo, const char *copyFrom, int startAt, const int endAt);
void cleanString(struct LashParser *parser, char *line);
void replaceTilde(struct LashParser *parser, char *line);
glob_t * expandWildcards(struct LashParser *parser, char *line);
void removeEscapeSlashesAndQuotes(struct LashParser *parser, char *line);
void stripStartAndEndSpacesAndEndingSymbols(char *line);
#endif