Skip to content

Commit 8846035

Browse files
authored
ALL macros (#403)
1 parent f7c69e7 commit 8846035

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
#DSIXSIX=(d6*10)+d6;@DSIXTYSIX
2-
#DSIXSIXSIX=(d6*100)+(d6*10)+d6
1+
#DSIXSIXSIX=(d6*100)+(d6*10)+d6

doc/gh-pages/notation/custom_macros.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ You can use ranges
4343
You can also use words
4444

4545
`$FRIENDS={JOHN,MARY,TAI}`
46+
47+
**Note:** Currently, if you wish to roll stored dice multiple times, you must do this in seperate statements e.g. `@FRIENDS;@FRIENDS;@FRIENDS`

src/grammar/dice.yacc

+19-11
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,16 @@ void load_builtins(char* root){
16791679
printf("/\n");
16801680
}
16811681
}else{
1682+
char *ext = strrchr(file.name, '.');
1683+
1684+
if(strcmp(".dice", ext) != 0){
1685+
if(verbose){
1686+
printf("Skip %s\n", file.name);
1687+
}
1688+
tinydir_next(&dir);
1689+
continue;
1690+
}
1691+
16821692
count++;
16831693
if(verbose){
16841694
printf("\n");
@@ -1697,18 +1707,16 @@ void load_builtins(char* root){
16971707

16981708
// TODO: Check filename for length
16991709
FILE* fp = fopen(path, "r");
1700-
while (fgets(stored_str, max_macro_length, fp)!=NULL);
1701-
1702-
if(verbose){
1703-
printf("Contents: %s\n",stored_str);
1710+
while (fgets(stored_str, max_macro_length, fp)!=NULL){
1711+
if(verbose){
1712+
printf("Contents: %s\n",stored_str);
1713+
}
1714+
YY_BUFFER_STATE buffer = yy_scan_string(stored_str);
1715+
yyparse();
1716+
yy_delete_buffer(buffer);
1717+
if(gnoll_errno){return;}
17041718
}
17051719
fclose(fp);
1706-
1707-
YY_BUFFER_STATE buffer = yy_scan_string(stored_str);
1708-
yyparse();
1709-
yy_delete_buffer(buffer);
1710-
if(gnoll_errno){return;}
1711-
17121720
free(path);
17131721
free(stored_str);
17141722
}
@@ -1754,7 +1762,7 @@ int main(int argc, char **str){
17541762
0, // Verbose
17551763
0, // Introspect
17561764
0, // Mocking
1757-
0, // Builtins
1765+
1, // Builtins
17581766
0, // Mocking
17591767
0 // Mocking Seed
17601768
);

src/grammar/operations/macros.c

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ void search_macros(char *skey, roll_params *to_store) {
112112

113113
HASH_FIND_INT(macros, &k, s); /* s: output pointer */
114114

115-
116115
if (s == NULL) {
117116
if (verbose) printf("Macro:: UNDEFINED (macros.c)\n");
118117
gnoll_errno = UNDEFINED_MACRO;

src/grammar/util/safe_functions.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ void print_gnoll_errors(){
2222
* @brief A human-readable translation of the gnoll error codes
2323
*
2424
*/
25-
if(verbose){
2625
switch(gnoll_errno){
2726
case SUCCESS:{
28-
printf("%sErrorCheck: No Errors.%s\n",ANSI_COLOR_GREEN, ANSI_COLOR_RESET);
27+
if(verbose){
28+
printf("%sErrorCheck: No Errors.%s\n",ANSI_COLOR_GREEN, ANSI_COLOR_RESET);
29+
}
2930
break;
3031
}
3132
case BAD_ALLOC:{
@@ -80,7 +81,6 @@ void print_gnoll_errors(){
8081
printf("%sErrorCheck: Error (Undetermined. Code %i).%s\n",ANSI_COLOR_RED, gnoll_errno, ANSI_COLOR_RESET);
8182
break;
8283
}
83-
}
8484
}
8585
}
8686

0 commit comments

Comments
 (0)