Call this v0.1.1
This commit is contained in:
commit
b25886ef13
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
slidescript
|
||||
*.o
|
||||
*.swp
|
||||
|
29
Makefile
Normal file
29
Makefile
Normal file
@ -0,0 +1,29 @@
|
||||
# SlideScript makefile
|
||||
# (C) Copyright 2014-2021 Chris Dorman, some rights reserved (CC-BY-SA 3.0)
|
||||
|
||||
VERSION = \"0.1.1\"
|
||||
EXTRA ?= dev
|
||||
VERSION_EXTRA = \"$(EXTRA)\"
|
||||
|
||||
PREFIX ?= /usr
|
||||
|
||||
CC ?= cc
|
||||
CFLAGS += -O2 -ansi -pedantic -g -Wall -Wextra --param=ssp-buffer-size=2 -fstack-protector-all
|
||||
CPPFLAGS += -DVERSION=$(VERSION) -DVERSION_EXTRA=$(VERSION_EXTRA) -D_FORTIFY_SOURCE=2
|
||||
LDFLAGS += -Wl,-O1,--sort-common,--hash-style=gnu,-z,relro
|
||||
BIN ?= slidescript
|
||||
|
||||
OBJECTS = src/main.o src/functions.o src/util.o
|
||||
|
||||
all: main
|
||||
|
||||
fresh: clean all
|
||||
|
||||
main: $(OBJECTS)
|
||||
$(CC) $(OBJECTS) -o $(BIN) $(LDFLAGS) $(CFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS) $(BIN)
|
||||
|
||||
install:
|
||||
install -D $(BIN) $(DESTDIR)/$(PREFIX)/bin/$(BIN)
|
47
README.md
Normal file
47
README.md
Normal file
@ -0,0 +1,47 @@
|
||||
SlideScript - v0.1.1-dev
|
||||
A simple, user friendly scripting language.
|
||||
====
|
||||
|
||||
Using SlideScript
|
||||
----
|
||||
* Compile SS using the make command.
|
||||
* Modify test.ss to learn the basics of SS.
|
||||
* Run ./slidescript test.ss to execute the script.
|
||||
|
||||
Documentation
|
||||
----
|
||||
Here is a list of functions and features that SlideScript comes with
|
||||
at this moment!
|
||||
* Variable setting
|
||||
variablename=variabledata
|
||||
* Commenting! Examples:
|
||||
# this is a comment
|
||||
* Read and writing to files! Examples:
|
||||
write "file.txt" "This will be written to file.txt"
|
||||
read "file.txt"
|
||||
* Print Example:
|
||||
print "Hi everyone!"
|
||||
* Sleep (Zzz) Example (sleeps for 2 seconds):
|
||||
sleep 2
|
||||
|
||||
Todo list
|
||||
----
|
||||
* Add in-script functions
|
||||
* New static functions
|
||||
* Network sockets
|
||||
|
||||
Done
|
||||
----
|
||||
* Read and write from file
|
||||
* Some simple functions
|
||||
* Variable support
|
||||
|
||||
Changelog
|
||||
----
|
||||
|
||||
V0.1.1
|
||||
* Added variable handling with a buffer size of 2MB per variable, and
|
||||
cap of 2048 variables.
|
||||
* Now operates under the shebang!
|
||||
|
||||
(C) Copyright 2014 Chris Dorman, some rights reserved (CC-BY-SA 3.0)
|
8
src/deps.h
Normal file
8
src/deps.h
Normal file
@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MAX_VAR_NAME_LEN 128
|
||||
#define MAX_VAR_DATA_LEN 2048
|
||||
#define MAXVARS 2048
|
101
src/functions.c
Normal file
101
src/functions.c
Normal file
@ -0,0 +1,101 @@
|
||||
|
||||
#include "deps.h"
|
||||
#include "functions.h"
|
||||
#include "util.h"
|
||||
|
||||
int process_line(char *line)
|
||||
{
|
||||
char *tok_srch = strtok(line, "=\" ");
|
||||
|
||||
/* if line starts with a comment, skip */
|
||||
if(strncmp("#",tok_srch,1) == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* print function */
|
||||
else if(strncmp("print",tok_srch,5) == 0)
|
||||
{
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
printf("%s\n", tok_srch);
|
||||
} /* print function */
|
||||
|
||||
/* sleep function */
|
||||
else if(strncmp("sleep",tok_srch,5) == 0)
|
||||
{
|
||||
tok_srch = strtok(NULL, " ");
|
||||
|
||||
/* if there is a new line, remove it */
|
||||
if(tok_srch[strlen(tok_srch)-1] == '\n')
|
||||
{
|
||||
tok_srch[strlen(tok_srch)-1] = 0;
|
||||
}
|
||||
sleep(atoi(tok_srch));
|
||||
}
|
||||
|
||||
/* write */
|
||||
else if(strncmp("write",tok_srch,5) == 0)
|
||||
{
|
||||
FILE* write_file = NULL;
|
||||
/* strtok to filename of function */
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
/* open file */
|
||||
write_file = fopen(tok_srch, "w");
|
||||
/* Check if file exists and can be opened */
|
||||
if(write_file == NULL)
|
||||
{
|
||||
printf("SlideScript: error: Cannot write to '%s'.\n", tok_srch);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* strtok to the content that will be written to file */
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
fprintf(write_file, "%s\n", tok_srch);
|
||||
fclose(write_file);
|
||||
} /* write function */
|
||||
|
||||
/* read function */
|
||||
else if(strncmp("read",tok_srch,4) == 0)
|
||||
{
|
||||
char read_line[1024];
|
||||
FILE *read_file = NULL;
|
||||
|
||||
/* strtok to filename of function */
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
|
||||
/* open file */
|
||||
read_file = fopen(tok_srch, "r");
|
||||
|
||||
/* Check if file was opened successfully */
|
||||
if(read_file == NULL)
|
||||
{
|
||||
printf("SlideScript: error: failed to open '%s'.\n", tok_srch);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while(fgets(read_line, sizeof(read_line), read_file) != NULL)
|
||||
{
|
||||
printf("%s", read_line);
|
||||
}
|
||||
|
||||
fclose(read_file);
|
||||
} /* read function */
|
||||
|
||||
else if(strcmp(tok_srch, "\n") != 0 && strcmp(tok_srch, "") != 0) {
|
||||
if(tok_srch[strlen(tok_srch)-1] == '\n')
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int varc = get_var_count();
|
||||
char *varname_tmp = tok_srch;
|
||||
tok_srch = strtok(NULL, "=");
|
||||
set_var(varc, varname_tmp, tok_srch);
|
||||
printf("ss: var '%s' -> %s", varname_tmp, get_var_data(varname_tmp));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
1
src/functions.h
Normal file
1
src/functions.h
Normal file
@ -0,0 +1 @@
|
||||
int process_line(char *line);
|
46
src/main.c
Normal file
46
src/main.c
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
SlideScript - Basic scripting for everyday use
|
||||
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (CC-BY-SA 3.0)
|
||||
|
||||
View read me file supplied with this software
|
||||
*/
|
||||
|
||||
#include "deps.h"
|
||||
#include "util.h"
|
||||
#include "functions.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE* script;
|
||||
char script_line[1024];
|
||||
|
||||
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)
|
||||
{
|
||||
process_line(script_line);
|
||||
} /* end of while */
|
||||
} /* file null */
|
||||
|
||||
if (argc != 1 ) fclose(script);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
73
src/util.c
Normal file
73
src/util.c
Normal file
@ -0,0 +1,73 @@
|
||||
#include "deps.h"
|
||||
#include "util.h"
|
||||
|
||||
char *null = "SlideScript: error: Variable not found!\n";
|
||||
|
||||
/*#define tostring(x) #x*/
|
||||
void set_var(int index, char *varname, char *vardata)
|
||||
{
|
||||
strcpy(svars[index].var_name, varname);
|
||||
strcpy(svars[index].var_data, vardata);
|
||||
}
|
||||
|
||||
char *get_var_data(char *varname)
|
||||
{
|
||||
int xx;
|
||||
for(xx = 0; xx < MAXVARS; xx++)
|
||||
{
|
||||
char *varp = svars[xx].var_name;
|
||||
if(*varp == '\0') continue;
|
||||
if(strcmp(varp, varname) == 0)
|
||||
{
|
||||
return svars[xx].var_data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
int get_var_count()
|
||||
{
|
||||
int yy;
|
||||
for(yy = 0; yy < MAXVARS; yy++)
|
||||
{
|
||||
if(strlen(svars[yy].var_name) > 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return yy+1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void parse_args(int argc, char** argv)
|
||||
{
|
||||
/* no arguments given */
|
||||
if(argc == 1)
|
||||
{
|
||||
printf("Error: no file supplied. use %s -h for help\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* -h flag given, show help */
|
||||
else if(argc == 2 && strncmp("-h", argv[1], 2) == 0)
|
||||
{
|
||||
printf("SlideScript - Simple, everyday use, programming script\n"
|
||||
"Arguments:\n\n"
|
||||
"-v\t Display version number\n"
|
||||
"-h\t Display this help page\n"
|
||||
"Usage: %s <filename>\n", argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
/* -v flag given, show version */
|
||||
else if(argc == 2 && strncmp("-v", argv[1], 2) == 0)
|
||||
{
|
||||
printf("SlideScript %s-%s\n", VERSION, VERSION_EXTRA);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
}
|
||||
|
13
src/util.h
Normal file
13
src/util.h
Normal file
@ -0,0 +1,13 @@
|
||||
struct s_variables
|
||||
{
|
||||
char var_name [MAX_VAR_NAME_LEN];
|
||||
char var_data [MAX_VAR_DATA_LEN];
|
||||
};
|
||||
|
||||
typedef struct s_variables VARS;
|
||||
VARS svars[MAXVARS];
|
||||
|
||||
void set_var(int index, char *varname, char *vardata);
|
||||
int get_var_count();
|
||||
char *get_var_data(char *varname);
|
||||
void parse_args(int argc, char** argv);
|
117
test.ss
Executable file
117
test.ss
Executable file
@ -0,0 +1,117 @@
|
||||
#!/usr/bin/slidescript
|
||||
# This is a comment
|
||||
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
testvar1=set some data into a struct
|
||||
testvar2=multiple variables work!
|
||||
futurefeature3=add $testvar2 support :)
|
||||
|
||||
print "Writing to file.txt in 1 second"
|
||||
sleep 1
|
||||
write "file.txt" "This is a test file"
|
||||
print "Reading from file.txt:"
|
||||
read "file.txt"
|
Loading…
x
Reference in New Issue
Block a user