slidescript/src/main.c

78 lines
2.0 KiB
C
Raw Normal View History

2021-04-05 04:22:57 -07:00
/*
2021-04-06 01:32:15 -07:00
SlideScript - minimalistic top-down scripting language.
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (GPLv2)
2021-04-05 04:22:57 -07:00
2021-04-06 01:32:15 -07:00
View README file supplied with this software for more details
2021-04-05 04:22:57 -07:00
*/
2021-04-07 15:15:53 -07:00
#define MY_GLOBAL
2021-04-05 04:22:57 -07:00
#include "deps.h"
#include "util.h"
#include "functions.h"
2021-04-06 22:27:35 -07:00
#include "pipe.h"
#include "vars.h"
2021-04-05 04:22:57 -07:00
int main(int argc, char **argv)
{
FILE* script;
2021-04-06 01:32:15 -07:00
char script_line[MAX_STRING_BUFSIZE];
/* If your script lines are over 2KB, stop programming */
2021-04-05 04:22:57 -07:00
if (argc == 1)
{
script = stdin;
}
else
{
parse_args (argc, argv);
script = fopen (argv [1], "r");
}
/* check if config opens successfully */
if(script == NULL) {
printf("Error: failed to open %s.\n", argv[1]);
exit(EXIT_FAILURE);
}
/* Run while loop if file is empty. */
if(script != NULL)
{
/* parse each line from the script in order. */
while(fgets(script_line, sizeof(script_line), script) != NULL)
{
2021-04-06 22:27:35 -07:00
char *return_dat, *pipechk, *return_pipe_dat;
pipechk = ss_piping(script_line);
return_dat = process_line(script_line);
// Blank line, getting up outta here.
if(return_dat == NULL) continue;
2021-04-06 22:27:35 -07:00
if(pipechk != NULL)
{
int varc;
varc = get_var_count();
set_var(varc, "PIPE", return_dat);
// Process functions based on previous pipe return
return_pipe_dat = process_line(pipechk);
// set PIPE var back to NULL after use, keep the struct clean
set_var(varc, "\0", "\0");
// Check to see if there's anything to even display
if(return_pipe_dat == NULL) continue;
// Print the pipe line
printf("%s\n", return_pipe_dat);
}
else
{
// If return is not null, and no pipe; provide the return
printf("%s\n", return_dat);
}
2021-04-05 04:22:57 -07:00
} /* end of while */
} /* file null */
if (argc != 1 ) fclose(script);
exit(EXIT_SUCCESS);
}