Added delete function to scripting language

master
Pentium44 2021-04-05 14:17:14 +00:00
parent b25886ef13
commit d9c0775140
3 changed files with 29 additions and 111 deletions

View File

@ -1 +0,0 @@
This is a test file

View File

@ -44,7 +44,7 @@ int process_line(char *line)
/* Check if file exists and can be opened */
if(write_file == NULL)
{
printf("SlideScript: error: Cannot write to '%s'.\n", tok_srch);
printf("ss: error: cannot write to '%s'.\n", tok_srch);
return 1;
}
@ -70,7 +70,7 @@ int process_line(char *line)
/* Check if file was opened successfully */
if(read_file == NULL)
{
printf("SlideScript: error: failed to open '%s'.\n", tok_srch);
printf("ss: error: failed to open '%s'.\n", tok_srch);
return 1;
}
@ -82,6 +82,28 @@ int process_line(char *line)
fclose(read_file);
} /* read function */
else if(strncmp("delete", tok_srch, 6) == 0) {
tok_srch = strtok(NULL, "\"");
if(access(tok_srch, F_OK) == 0)
{
if(access(tok_srch, W_OK) == 0)
{
remove(tok_srch);
return 0;
}
else
{
printf("ss: error: '%s' is not accessible", tok_srch);
return 1;
}
}
else
{
printf("ss: error: '%s' not found", tok_srch);
return 1;
}
}
else if(strcmp(tok_srch, "\n") != 0 && strcmp(tok_srch, "") != 0) {
if(tok_srch[strlen(tok_srch)-1] == '\n')
{

113
test.ss
View File

@ -1,117 +1,14 @@
#!/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 :)
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
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"