Initial commit, quick program to help me do the work on Xhads...

This commit is contained in:
Ognjen Milan Robovic 2024-06-04 06:29:23 -04:00
parent 1c2a7b8677
commit 46293ecc77
4 changed files with 182 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
xrocedure

7
compile.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -xe
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -o xrocedure xrocedure.c
exit

7
install.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -xe
cp xrocedure /usr/bin/xrocedure
exit

167
xrocedure.c Normal file
View File

@ -0,0 +1,167 @@
#include <xolatile/xtandard.c>
#include <xolatile/xyntax.c>
enum {
word_abort, word_else, word_new, word_return, word_abs, word_elsif, word_not, word_reverse,
word_abstract, word_end, word_null, word_accept, word_entry, word_select, word_access, word_of,
word_separate, word_aliased, word_exit, word_or, word_some, word_all, word_others, word_subtype,
word_and, word_for, word_out, word_array, word_function, word_at, word_tagged, word_generic,
word_package, word_task, word_begin, word_goto, word_pragma, word_body, word_private, word_then,
word_type, word_case, word_in, word_constant, word_until, word_is, word_raise, word_use,
word_if, word_declare, word_range, word_delay, word_limited, word_record, word_when, word_delta,
word_loop, word_rem, word_while, word_digits, word_renames, word_with, word_do, word_mod,
word_requeue, word_xor, word_procedure, word_protected, word_interface, word_synchronized, word_exception, word_overriding,
word_terminate, word_count
};
int main (void) {
char * separators = ".,:;<=>+-*/&|()\" \t\r\n";
char * keywords [] = {
"abort", "else", "new", "return", "abs", "elsif", "not", "reverse",
"abstract", "end", "null", "accept", "entry", "select", "access", "of",
"separate", "aliased", "exit", "or", "some", "all", "others", "subtype",
"and", "for", "out", "array", "function", "at", "tagged", "generic",
"package", "task", "begin", "goto", "pragma", "body", "private", "then",
"type", "case", "in", "constant", "until", "is", "raise", "use",
"if", "declare", "range", "delay", "limited", "record", "when", "delta",
"loop", "rem", "while", "digits", "renames", "with", "do", "mod",
"requeue", "xor", "procedure", "protected", "interface", "synchronized", "exception", "overriding",
"terminate"
};
int keycodes [word_count] = { 0 };
int x_keyword [word_count] = { 0 };
int word;
int offset = 0;
int select = 0;
int length = 0;
char * buffer = null;
int comment, x_comment = 0,
character, x_character = 0,
string, x_string = 0,
brackets, x_brackets = 0,
operators, x_operators = 0,
number, x_number = 0,
identifier, x_identifier = 0;
comment = syntax_define (false, false, "--", "\n", '\0', 0, 0);
character = syntax_define (false, false, "'", "'", '\\', 0, 0);
string = syntax_define (false, false, "\"", "\"", '\\', 0, 0);
for (word = 0; word != word_count; ++word) {
keycodes [word] = syntax_define (false, true, keywords [word], separators, '\0', 0, 0);
}
brackets = syntax_define (true, false, "()", "", '\0', 0, 0);
operators = syntax_define (true, false, ".,:;<=>+-*/&|'", "", '\0', 0, 0);
number = syntax_define (true, true, "0123456789", separators, '\0', 0, 0);
identifier = syntax_define (true, true, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_", separators, '\0', 0, 0);
buffer = record ();
for (offset = 0; buffer [offset] != '\0'; offset += length) {
select = syntax_select (& buffer [offset], & length);
if (select == comment) x_comment++;
else if (select == character) x_character++;
else if (select == string) x_string++;
else if (select == keycodes [word_abort]) x_keyword [word_abort]++;
else if (select == keycodes [word_else]) x_keyword [word_else]++;
else if (select == keycodes [word_new]) x_keyword [word_new]++;
else if (select == keycodes [word_return]) x_keyword [word_return]++;
else if (select == keycodes [word_abs]) x_keyword [word_abs]++;
else if (select == keycodes [word_elsif]) x_keyword [word_elsif]++;
else if (select == keycodes [word_not]) x_keyword [word_not]++;
else if (select == keycodes [word_reverse]) x_keyword [word_reverse]++;
else if (select == keycodes [word_abstract]) x_keyword [word_abstract]++;
else if (select == keycodes [word_end]) x_keyword [word_end]++;
else if (select == keycodes [word_null]) x_keyword [word_null]++;
else if (select == keycodes [word_accept]) x_keyword [word_accept]++;
else if (select == keycodes [word_entry]) x_keyword [word_entry]++;
else if (select == keycodes [word_select]) x_keyword [word_select]++;
else if (select == keycodes [word_access]) x_keyword [word_access]++;
else if (select == keycodes [word_of]) x_keyword [word_of]++;
else if (select == keycodes [word_separate]) x_keyword [word_separate]++;
else if (select == keycodes [word_aliased]) x_keyword [word_aliased]++;
else if (select == keycodes [word_exit]) x_keyword [word_exit]++;
else if (select == keycodes [word_or]) x_keyword [word_or]++;
else if (select == keycodes [word_some]) x_keyword [word_some]++;
else if (select == keycodes [word_all]) x_keyword [word_all]++;
else if (select == keycodes [word_others]) x_keyword [word_others]++;
else if (select == keycodes [word_subtype]) x_keyword [word_subtype]++;
else if (select == keycodes [word_and]) x_keyword [word_and]++;
else if (select == keycodes [word_for]) x_keyword [word_for]++;
else if (select == keycodes [word_out]) x_keyword [word_out]++;
else if (select == keycodes [word_array]) x_keyword [word_array]++;
else if (select == keycodes [word_function]) x_keyword [word_function]++;
else if (select == keycodes [word_at]) x_keyword [word_at]++;
else if (select == keycodes [word_tagged]) x_keyword [word_tagged]++;
else if (select == keycodes [word_generic]) x_keyword [word_generic]++;
else if (select == keycodes [word_package]) x_keyword [word_package]++;
else if (select == keycodes [word_task]) x_keyword [word_task]++;
else if (select == keycodes [word_begin]) x_keyword [word_begin]++;
else if (select == keycodes [word_goto]) x_keyword [word_goto]++;
else if (select == keycodes [word_pragma]) x_keyword [word_pragma]++;
else if (select == keycodes [word_body]) x_keyword [word_body]++;
else if (select == keycodes [word_private]) x_keyword [word_private]++;
else if (select == keycodes [word_then]) x_keyword [word_then]++;
else if (select == keycodes [word_type]) x_keyword [word_type]++;
else if (select == keycodes [word_case]) x_keyword [word_case]++;
else if (select == keycodes [word_in]) x_keyword [word_in]++;
else if (select == keycodes [word_constant]) x_keyword [word_constant]++;
else if (select == keycodes [word_until]) x_keyword [word_until]++;
else if (select == keycodes [word_is]) x_keyword [word_is]++;
else if (select == keycodes [word_raise]) x_keyword [word_raise]++;
else if (select == keycodes [word_use]) x_keyword [word_use]++;
else if (select == keycodes [word_if]) x_keyword [word_if]++;
else if (select == keycodes [word_declare]) x_keyword [word_declare]++;
else if (select == keycodes [word_range]) x_keyword [word_range]++;
else if (select == keycodes [word_delay]) x_keyword [word_delay]++;
else if (select == keycodes [word_limited]) x_keyword [word_limited]++;
else if (select == keycodes [word_record]) x_keyword [word_record]++;
else if (select == keycodes [word_when]) x_keyword [word_when]++;
else if (select == keycodes [word_delta]) x_keyword [word_delta]++;
else if (select == keycodes [word_loop]) x_keyword [word_loop]++;
else if (select == keycodes [word_rem]) x_keyword [word_rem]++;
else if (select == keycodes [word_while]) x_keyword [word_while]++;
else if (select == keycodes [word_digits]) x_keyword [word_digits]++;
else if (select == keycodes [word_renames]) x_keyword [word_renames]++;
else if (select == keycodes [word_with]) x_keyword [word_with]++;
else if (select == keycodes [word_do]) x_keyword [word_do]++;
else if (select == keycodes [word_mod]) x_keyword [word_mod]++;
else if (select == keycodes [word_requeue]) x_keyword [word_requeue]++;
else if (select == keycodes [word_xor]) x_keyword [word_xor]++;
else if (select == keycodes [word_procedure]) x_keyword [word_procedure]++;
else if (select == keycodes [word_protected]) x_keyword [word_protected]++;
else if (select == keycodes [word_interface]) x_keyword [word_interface]++;
else if (select == keycodes [word_synchronized]) x_keyword [word_synchronized]++;
else if (select == keycodes [word_exception]) x_keyword [word_exception]++;
else if (select == keycodes [word_overriding]) x_keyword [word_overriding]++;
else if (select == keycodes [word_terminate]) x_keyword [word_terminate]++;
else if (select == brackets) x_brackets++;
else if (select == operators) x_operators++;
else if (select == number) x_number++;
else if (select == identifier) x_identifier++;
}
echo ("Comments : "); echo (number_to_string (x_comment)); echo ("\n");
echo ("Strings : "); echo (number_to_string (x_string)); echo ("\n");
echo ("Numbers : "); echo (number_to_string (x_number)); echo ("\n");
echo ("Keywords : List\n");
for (word = 0; word != word_count; ++word) {
if (x_keyword [word] != 0) {
echo ("\t > "); echo (keywords [word]); echo (" <> "); echo (number_to_string (x_keyword [word])); echo ("\n");
}
}
buffer = deallocate (buffer);
return (log_success);
}