70 lines
1.5 KiB
C
70 lines
1.5 KiB
C
/***********************************************************
|
|
** symbol_set - A public domain C modifier library
|
|
** by Allen Webster, "Mr. 4th", allenw@mr4th.com
|
|
**
|
|
** No warranty implied; use at your own risk
|
|
**
|
|
** Read README to get started.
|
|
*/
|
|
|
|
#include "symbol_set.h"
|
|
#include "hello_world.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "symbol_set.c"
|
|
|
|
COMMAND_DEF(Punctuate, "Prints a punctuation", 0){
|
|
printf("!");
|
|
}
|
|
|
|
COMMAND_DEF(Address, "Prints an address to the audience", 1){
|
|
printf("World");
|
|
}
|
|
|
|
COMMAND_DEF(Greet, "Prints a greeting", 1){
|
|
printf("Hello");
|
|
}
|
|
|
|
int main(void){
|
|
// display the legend of rules
|
|
printf("RULES:\n");
|
|
for (SyEach(COMMAND, command)){
|
|
printf("%s -> %s\n", command->name, command->description);
|
|
}
|
|
printf("\n");
|
|
|
|
// init the sequence
|
|
Sy_U32 sequence[] = {
|
|
SyID(COMMAND, Greet), SyID(COMMAND, Address), SyID(COMMAND, Punctuate),
|
|
};
|
|
|
|
// display the sequence
|
|
printf("SEQUENCE:\n");
|
|
for (Sy_U32 i = 0; i < sizeof(sequence)/sizeof(sequence[0]); i += 1){
|
|
Sy_U32 id = sequence[i];
|
|
Command *command = SyAddressFromID(COMMAND, id);
|
|
printf("%s, ", command->name);
|
|
}
|
|
printf("\n\n");
|
|
|
|
// run the sequence
|
|
printf("OUTPUT:\n");
|
|
{
|
|
int prev_was_word = 0;
|
|
for (Sy_U32 i = 0; i < sizeof(sequence)/sizeof(sequence[0]); i += 1){
|
|
Sy_U32 id = sequence[i];
|
|
Command *command = SyAddressFromID(COMMAND, id);
|
|
if (command->is_word && prev_was_word){
|
|
printf(" ");
|
|
}
|
|
command->hook();
|
|
prev_was_word = command->is_word;
|
|
}
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
return(0);
|
|
}
|