-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathgoal.c
54 lines (39 loc) · 960 Bytes
/
goal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// To compile and run:
// gcc goal.c -o goal && ./goal
//
// To view expansion:
// gcc -E goal.c
//
// Author: @tolmasky
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define g(X) start("o" #X) ? "" : goal0
#define goal0(X) update("o" #X) ? "" : goal1
#define goal1(X) update("o" #X) ? "" : goal0
char * goal0 = "g";
char * goal1 = "g";
int start(const char * s)
{
goal0 = goal1 = strdup(strlen(s) == 1 ? "go" : "gal");
return 0;
}
int update(const char * s)
{
const char * append = strlen(s) == 1 ? "o" : "al";
int length = strlen(goal0) + strlen(append) + 1;
char * updated = calloc(length, sizeof(char));
strcat(updated, goal0);
strcat(updated, append);
goal0 = goal1 = updated;
return 0;
}
int main()
{
printf("%s\n", g('al'));
printf("%s\n", g()('al'));
printf("%s\n", g()()()()()()('al'));
const char * s = g()()()()()()()()()("al");
printf("%s\n", s);
return 0;
}