51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
/*
|
|
SlideScript - minimalistic top-down scripting language.
|
|
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (GPLv2)
|
|
|
|
View README file supplied with this software for more details
|
|
*/
|
|
|
|
#include "deps.h"
|
|
#include "util.h"
|
|
#include "functions.h"
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
FILE* script;
|
|
char script_line[MAX_STRING_BUFSIZE];
|
|
/* If your script lines are over 2KB, stop programming */
|
|
|
|
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)
|
|
{
|
|
char *return_dat;
|
|
return_dat = process_line(script_line);
|
|
if(return_dat == NULL) continue;
|
|
// If return is not null, provide the return
|
|
printf("%s\n", return_dat);
|
|
} /* end of while */
|
|
} /* file null */
|
|
|
|
if (argc != 1 ) fclose(script);
|
|
exit(EXIT_SUCCESS);
|
|
}
|