call this v0.2.0-dev
This commit is contained in:
parent
d9c0775140
commit
68dec387b1
2
Makefile
2
Makefile
@ -1,7 +1,7 @@
|
||||
# SlideScript makefile
|
||||
# (C) Copyright 2014-2021 Chris Dorman, some rights reserved (CC-BY-SA 3.0)
|
||||
|
||||
VERSION = \"0.1.1\"
|
||||
VERSION = \"0.2.0\"
|
||||
EXTRA ?= dev
|
||||
VERSION_EXTRA = \"$(EXTRA)\"
|
||||
|
||||
|
36
README.md
36
README.md
@ -5,24 +5,34 @@ A simple, user friendly scripting language.
|
||||
Using SlideScript
|
||||
----
|
||||
* Compile SS using the make command.
|
||||
* Install SS using make install.
|
||||
* Modify test.ss to learn the basics of SS.
|
||||
* Run ./slidescript test.ss to execute the script.
|
||||
* Run ./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:
|
||||
Thie simple way of comments! # Comment is real in this one
|
||||
* Read and writing to flat files. Examples:
|
||||
write "file.txt" "This will be written to file.txt"
|
||||
read "file.txt"
|
||||
* Print Example:
|
||||
* Delete example:
|
||||
delete "file.txt"
|
||||
* Execute example:
|
||||
exec "ls -al"
|
||||
* Print example:
|
||||
print "Hi everyone!"
|
||||
* Sleep (Zzz) Example (sleeps for 2 seconds):
|
||||
* Sleep (Zzz) example (sleeps for 2 seconds):
|
||||
sleep 2
|
||||
* Variable setting
|
||||
variablename=variabledata
|
||||
* Variable passing
|
||||
filename=file.txt -> filename
|
||||
filedata=File '%filename%' is being moved to moo -> %filename% is populated as file.txt
|
||||
write "%filename%" "%filedata%" -> writes filedata contents to file.txt as expected.
|
||||
|
||||
Todo list
|
||||
----
|
||||
@ -32,16 +42,26 @@ Todo list
|
||||
|
||||
Done
|
||||
----
|
||||
* Support for linux system calls
|
||||
* Read and write from file
|
||||
* Some simple functions
|
||||
* Shebang handling
|
||||
* Variable support
|
||||
|
||||
Changelog
|
||||
----
|
||||
V0.2.0
|
||||
* Added "delete" function
|
||||
* Added embedded variable handling to SS functions (variables can be used like everywhere!)
|
||||
* Added linux system calls via exec
|
||||
* Some cleaning up.
|
||||
|
||||
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)
|
||||
Contributions:
|
||||
Robert (OldCoder) Kirary -> shebang support and string manipulations
|
||||
|
||||
(C) Copyright 2014-2021 Chris Dorman, some rights reserved (CC-BY-SA 3.0)
|
||||
|
13
src/deps.h
13
src/deps.h
@ -1,8 +1,21 @@
|
||||
/*
|
||||
SlideScript - minimalistic top-down scripting language.
|
||||
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (CC-BY-SA 3.0)
|
||||
|
||||
View README file supplied with this software for more details
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MAX_VAR_NAME_LEN 128
|
||||
#define MAX_VAR_NAME_BUFSIZE (MAX_VAR_NAME_LEN + 1)
|
||||
#define MAX_STRING_LEN 2048
|
||||
#define MAX_STRING_BUFSIZE (MAX_STRING_LEN + 1)
|
||||
#define MAX_VAR_DATA_LEN 2048
|
||||
#define MAXVARS 2048
|
||||
#define TOKEN '%'
|
||||
#define TOKEN_STR "%"
|
||||
#define NULLBYTE '\0'
|
||||
|
@ -1,3 +1,9 @@
|
||||
/*
|
||||
SlideScript - minimalistic top-down scripting language.
|
||||
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (CC-BY-SA 3.0)
|
||||
|
||||
View README file supplied with this software for more details
|
||||
*/
|
||||
|
||||
#include "deps.h"
|
||||
#include "functions.h"
|
||||
@ -16,8 +22,11 @@ int process_line(char *line)
|
||||
/* print function */
|
||||
else if(strncmp("print",tok_srch,5) == 0)
|
||||
{
|
||||
char *parsed;
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
printf("%s\n", tok_srch);
|
||||
parsed = parse_vars(tok_srch);
|
||||
if(parsed != NULL) printf("%s\n", parsed);
|
||||
/* printf("%s\n", tok_srch); */
|
||||
} /* print function */
|
||||
|
||||
/* sleep function */
|
||||
@ -33,25 +42,43 @@ int process_line(char *line)
|
||||
sleep(atoi(tok_srch));
|
||||
}
|
||||
|
||||
/* system execute function */
|
||||
else if(strncmp("exec",tok_srch,4) == 0)
|
||||
{
|
||||
char *cmd_line;
|
||||
int return_val;
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
cmd_line = parse_vars(tok_srch);
|
||||
return_val = system(cmd_line);
|
||||
if(return_val != 0)
|
||||
{
|
||||
printf("ss:%s exited with error code %d\n", cmd_line, return_val);
|
||||
}
|
||||
}
|
||||
|
||||
/* write */
|
||||
else if(strncmp("write",tok_srch,5) == 0)
|
||||
{
|
||||
char *filename;
|
||||
char *file_content;
|
||||
FILE* write_file = NULL;
|
||||
/* strtok to filename of function */
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
/* open file */
|
||||
write_file = fopen(tok_srch, "w");
|
||||
filename = parse_vars(tok_srch);
|
||||
write_file = fopen(filename, "w");
|
||||
/* Check if file exists and can be opened */
|
||||
if(write_file == NULL)
|
||||
{
|
||||
printf("ss: error: cannot write to '%s'.\n", tok_srch);
|
||||
printf("ss: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);
|
||||
file_content = parse_vars(tok_srch);
|
||||
fprintf(write_file, "%s\n", file_content);
|
||||
fclose(write_file);
|
||||
} /* write function */
|
||||
|
||||
@ -59,13 +86,18 @@ int process_line(char *line)
|
||||
else if(strncmp("read",tok_srch,4) == 0)
|
||||
{
|
||||
char read_line[1024];
|
||||
char *filename;
|
||||
FILE *read_file = NULL;
|
||||
|
||||
/* strtok to filename of function */
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
|
||||
/* Pull any variables out of the file name
|
||||
that may be, and BAM, variable fill! */
|
||||
filename = parse_vars(tok_srch);
|
||||
|
||||
/* open file */
|
||||
read_file = fopen(tok_srch, "r");
|
||||
read_file = fopen(filename, "r");
|
||||
|
||||
/* Check if file was opened successfully */
|
||||
if(read_file == NULL)
|
||||
@ -83,23 +115,26 @@ int process_line(char *line)
|
||||
} /* read function */
|
||||
|
||||
else if(strncmp("delete", tok_srch, 6) == 0) {
|
||||
char *del_filename;
|
||||
tok_srch = strtok(NULL, "\"");
|
||||
if(access(tok_srch, F_OK) == 0)
|
||||
/* Pull variables out of filename if any */
|
||||
del_filename = parse_vars(tok_srch);
|
||||
if(access(del_filename, F_OK) == 0)
|
||||
{
|
||||
if(access(tok_srch, W_OK) == 0)
|
||||
if(access(del_filename, W_OK) == 0)
|
||||
{
|
||||
remove(tok_srch);
|
||||
remove(del_filename);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ss: error: '%s' is not accessible", tok_srch);
|
||||
printf("ss: error: '%s' is not accessible", del_filename);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ss: error: '%s' not found", tok_srch);
|
||||
printf("ss: error: '%s' not found", del_filename);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -114,8 +149,8 @@ int process_line(char *line)
|
||||
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));
|
||||
set_var(varc, varname_tmp, parse_vars(strip_nl(tok_srch)));
|
||||
/* printf("ss: var '%s' -> %s", varname_tmp, get_var_data(varname_tmp)); */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1 +1,8 @@
|
||||
/*
|
||||
SlideScript - minimalistic top-down scripting language.
|
||||
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (CC-BY-SA 3.0)
|
||||
|
||||
View README file supplied with this software for more details
|
||||
*/
|
||||
|
||||
int process_line(char *line);
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
SlideScript - Basic scripting for everyday use
|
||||
SlideScript - minimalistic top-down scripting language.
|
||||
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (CC-BY-SA 3.0)
|
||||
|
||||
View read me file supplied with this software
|
||||
View README file supplied with this software for more details
|
||||
*/
|
||||
|
||||
#include "deps.h"
|
||||
@ -12,7 +12,8 @@
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE* script;
|
||||
char script_line[1024];
|
||||
char script_line[MAX_STRING_BUFSIZE];
|
||||
/* If your script lines are over 2KB, stop programming */
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
|
98
src/util.c
98
src/util.c
@ -1,9 +1,36 @@
|
||||
/*
|
||||
SlideScript - minimalistic top-down scripting language.
|
||||
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (CC-BY-SA 3.0)
|
||||
|
||||
View README file supplied with this software for more details
|
||||
*/
|
||||
|
||||
|
||||
#include "deps.h"
|
||||
#include "util.h"
|
||||
|
||||
char *null = "SlideScript: error: Variable not found!\n";
|
||||
void syn_error(char *message)
|
||||
{
|
||||
printf("%s\n", message);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char *strip_nl (char *string)
|
||||
{
|
||||
int n = strlen (string);
|
||||
|
||||
if ((n-- > 0) && (string [n] == '\n'))
|
||||
{
|
||||
string [n] = NULLBYTE;
|
||||
return string;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no newline found, return the original string */
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
/*#define tostring(x) #x*/
|
||||
void set_var(int index, char *varname, char *vardata)
|
||||
{
|
||||
strcpy(svars[index].var_name, varname);
|
||||
@ -22,7 +49,8 @@ char *get_var_data(char *varname)
|
||||
return svars[xx].var_data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int get_var_count()
|
||||
@ -36,26 +64,70 @@ int get_var_count()
|
||||
}
|
||||
else
|
||||
{
|
||||
return yy+1;
|
||||
return yy;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *parse_vars(char *string)
|
||||
{
|
||||
int str_char, buf_len, var_len;
|
||||
static char finished [MAX_STRING_BUFSIZE];
|
||||
char varbuffer [MAX_VAR_NAME_BUFSIZE];
|
||||
|
||||
/* String pointers */
|
||||
char *input_pointer;
|
||||
char *output_pointer;
|
||||
char *variable_pointer;
|
||||
|
||||
*finished = NULLBYTE;
|
||||
|
||||
for (input_pointer = string, output_pointer = finished;
|
||||
(str_char = *input_pointer) != NULLBYTE;
|
||||
input_pointer++)
|
||||
{
|
||||
if (str_char != TOKEN)
|
||||
{ *output_pointer++ = str_char; *output_pointer = NULLBYTE; continue; }
|
||||
|
||||
variable_pointer = varbuffer;
|
||||
do { *variable_pointer++ = (str_char = *++input_pointer); }
|
||||
while ((str_char != NULLBYTE) && (str_char != TOKEN));
|
||||
|
||||
str_char = *input_pointer;
|
||||
if ((str_char != NULLBYTE) && (str_char != TOKEN))
|
||||
syn_error("ss:error:buffer out of sync");
|
||||
str_char = variable_pointer [-1];
|
||||
if ((str_char != NULLBYTE) && (str_char != TOKEN))
|
||||
syn_error("ss:error:buffer out of sync");
|
||||
|
||||
variable_pointer[-1] = NULLBYTE;
|
||||
|
||||
if(*varbuffer == NULLBYTE)
|
||||
syn_error("ss:error:variable syntax error!");
|
||||
|
||||
variable_pointer = get_var_data(varbuffer);
|
||||
var_len = strlen(variable_pointer);
|
||||
buf_len = strlen(finished) + var_len;
|
||||
|
||||
if(buf_len > MAX_STRING_LEN)
|
||||
syn_error("ss:error:string buffer overflow!");
|
||||
|
||||
strcat (finished, variable_pointer);
|
||||
output_pointer += var_len;
|
||||
if(*input_pointer == NULLBYTE) break;
|
||||
}
|
||||
|
||||
*output_pointer = NULLBYTE;
|
||||
return finished;
|
||||
}
|
||||
|
||||
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)
|
||||
if(argc == 2 && strncmp("-h", argv[1], 2) == 0)
|
||||
{
|
||||
printf("SlideScript - Simple, everyday use, programming script\n"
|
||||
printf("SlideScript - simple top-down scripting language for the average user\n"
|
||||
"Arguments:\n\n"
|
||||
"-v\t Display version number\n"
|
||||
"-h\t Display this help page\n"
|
||||
@ -65,7 +137,7 @@ void parse_args(int argc, char** argv)
|
||||
/* -v flag given, show version */
|
||||
else if(argc == 2 && strncmp("-v", argv[1], 2) == 0)
|
||||
{
|
||||
printf("SlideScript %s-%s\n", VERSION, VERSION_EXTRA);
|
||||
printf("SlideScript %s-%s, Chris Dorman (cddo@riseup.net), 2021\n", VERSION, VERSION_EXTRA);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
10
src/util.h
10
src/util.h
@ -1,3 +1,10 @@
|
||||
/*
|
||||
SlideScript - minimalistic top-down scripting language.
|
||||
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (CC-BY-SA 3.0)
|
||||
|
||||
View README file supplied with this software for more details
|
||||
*/
|
||||
|
||||
struct s_variables
|
||||
{
|
||||
char var_name [MAX_VAR_NAME_LEN];
|
||||
@ -7,7 +14,10 @@ struct s_variables
|
||||
typedef struct s_variables VARS;
|
||||
VARS svars[MAXVARS];
|
||||
|
||||
void syn_error(char *message);
|
||||
char *strip_nl(char *string);
|
||||
void set_var(int index, char *varname, char *vardata);
|
||||
int get_var_count();
|
||||
char *get_var_data(char *varname);
|
||||
char *parse_vars(char *string);
|
||||
void parse_args(int argc, char** argv);
|
||||
|
22
test.ss
22
test.ss
@ -1,14 +1,18 @@
|
||||
#!/usr/bin/slidescript
|
||||
# This is a comment
|
||||
|
||||
variable_name=anything can go after the equal and be parsed on the same line. 'works' like a champion!
|
||||
slidescript_version=v0.1.1
|
||||
slidescript_test_version=v0.0.2
|
||||
ss_filename=file.txt
|
||||
ss_file_content=This will be written to %ss_filename% in due course!
|
||||
ss_exec_command=ls -al
|
||||
|
||||
print "Writing '%ss_file_content%' to '%ss_filename%'"
|
||||
|
||||
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"
|
||||
print "Deleting file.txt"
|
||||
delete "file.txt"
|
||||
|
||||
write "%ss_filename%" "%ss_file_content%"
|
||||
|
||||
read "%ss_filename%"
|
||||
|
||||
delete "%ss_filename%"
|
||||
|
||||
exec "%ss_exec_command%"
|
||||
|
Loading…
x
Reference in New Issue
Block a user