Added simple script parsing function
This commit is contained in:
parent
55513bcad0
commit
95bd87a73b
@ -16,6 +16,11 @@ I do plan to give this the ability to be scripted and further as well has
|
|||||||
allowing some customization to the prompt, and per user file. I also plan to
|
allowing some customization to the prompt, and per user file. I also plan to
|
||||||
form processing of for, while, and if statements.
|
form processing of for, while, and if statements.
|
||||||
|
|
||||||
|
Current features
|
||||||
|
-------
|
||||||
|
|
||||||
|
Simple top down script parsing functions
|
||||||
|
|
||||||
Compiling & Running
|
Compiling & Running
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
18
src/main.c
18
src/main.c
@ -242,7 +242,7 @@ void cdsh_loop(void)
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
printf("> ");
|
printf("$ ");
|
||||||
line = cdsh_read_line();
|
line = cdsh_read_line();
|
||||||
args = cdsh_split_line(line);
|
args = cdsh_split_line(line);
|
||||||
status = cdsh_execute(args);
|
status = cdsh_execute(args);
|
||||||
@ -261,19 +261,17 @@ void cdsh_loop(void)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// Load config files, if any.
|
// Load config files, if any.
|
||||||
if(argc < 2 || !strcmp(argv[1], "-?") || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
|
if (argc == 1) {
|
||||||
|
// If cdsh is called by itself, just pull prompt up
|
||||||
|
cdsh_loop();
|
||||||
|
} else if(argc > 2 || !strcmp(argv[1], "-?") || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
|
||||||
printf("usage: cdsh [file location]\n"
|
printf("usage: cdsh [file location]\n"
|
||||||
"Example: cdsh /path/to/script.sh \n");
|
"Example: cdsh /path/to/script.sh \n");
|
||||||
cdsh_exit(0); // exit
|
fflush(stdout);
|
||||||
} else if (argc == 2) {
|
cdsh_exit(0); // exit
|
||||||
|
} else if (argc == 2 && file_exists(argv[1])==0) {
|
||||||
parse(argv[1]);
|
parse(argv[1]);
|
||||||
|
|
||||||
cdsh_exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run command loop.
|
|
||||||
cdsh_loop();
|
|
||||||
|
|
||||||
// Perform any shutdown/cleanup.
|
// Perform any shutdown/cleanup.
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
32
src/parse.c
32
src/parse.c
@ -53,35 +53,35 @@ void parse(char *filename)
|
|||||||
|
|
||||||
// If its the crunchbang, note for now
|
// If its the crunchbang, note for now
|
||||||
if (strncmp("#!",line,2)==0) {
|
if (strncmp("#!",line,2)==0) {
|
||||||
printf("cdsh: found the crunchbang\n");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if line is commented out, skip
|
// if line is commented out, skip
|
||||||
if (strncmp("#",line,1)==0) {
|
if (strncmp("#",line,1)==0) {
|
||||||
printf("cdsh: skipping comment line in file...\n");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(newline,line,1)==0) {
|
if (strncmp(newline,line,1)==0) {
|
||||||
printf("cdsh: skipping empty line in file...\n");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp("exit",cfline,4)==0 || strncmp("EXIT",cfline,4)==0) {
|
char *argvlist[50];
|
||||||
cdsh_exit(0);
|
int argc = 0;
|
||||||
} /*else {
|
|
||||||
int x;
|
char *moocow = cfline;
|
||||||
char *command;
|
|
||||||
for(x = 0; x++; x>=strlen(cfline)) {
|
// Replace tabs with spaces
|
||||||
strncat(command, &cfline[x], 1);
|
while((cfline = strtok(moocow, space)) != NULL) {
|
||||||
}
|
moocow = NULL;
|
||||||
|
argvlist[argc++] = cfline;
|
||||||
cdsh_execute(&command);
|
}
|
||||||
} */
|
|
||||||
|
cdsh_execute(argvlist);
|
||||||
|
|
||||||
} // End while
|
} // End while
|
||||||
} // End if file
|
} // End if file
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
|
cdsh_exit(0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user