Mercurial
annotate playground/main.c @ 108:f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Sat, 03 Jan 2026 17:29:12 -0800 |
| parents | 75de5903355c |
| children | 1c446ab6f945 |
| rev | line source |
|---|---|
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
1 #include <stdio.h> |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
2 #include <stdlib.h> |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
3 |
|
108
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
4 #define REPO_ROOT "/Users/mrjunejune/zenbu" |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
5 |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
6 #include <stdint.h> |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
7 #include <arpa/inet.h> |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
8 |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
9 void run_hg_command(FILE *hg_pipe) { |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
10 char channel; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
11 uint32_t net_len; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
12 |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
13 while (fread(&channel, 1, 1, hg_pipe) == 1) { |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
14 // 1. Read the 4-byte length |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
15 fread(&net_len, 4, 1, hg_pipe); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
16 uint32_t length = ntohl(net_len); |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
17 |
|
108
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
18 // 2. If it's an 'o' (output), it's the data you want |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
19 if (channel == 'o' || channel == 'e') { |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
20 char *buf = malloc(length + 1); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
21 fread(buf, 1, length, hg_pipe); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
22 buf[length] = '\0'; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
23 printf("%s", buf); // This is your capability string |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
24 free(buf); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
25 } |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
26 // 3. IF THE CHANNEL IS 'r', THE COMMAND IS DONE. STOP HERE. |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
27 else if (channel == 'r') { |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
28 int32_t result; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
29 // The 'r' channel payload is the 4-byte return code |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
30 fread(&result, 4, 1, hg_pipe); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
31 printf("\nCommand finished with result: %d\n", ntohl(result)); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
32 break; // <--- THIS IS YOUR EXIT |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
33 } |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
34 } |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
35 } |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
36 |
|
25
342726584be2
[Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
37 int main() |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
38 { |
|
108
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
39 char command[512]; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
40 snprintf(command, sizeof(command), "hg -R %s serve --stdio", REPO_ROOT); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
41 printf("command: %s\n", command); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
42 |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
43 FILE *hg_pipe = popen(command, "r+"); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
44 if (!hg_pipe) |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
45 { |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
46 printf("Failed to open pipe\n"); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
47 return -1; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
48 } |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
49 |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
50 fprintf(hg_pipe, "capabilities\n"); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
51 fflush(hg_pipe); |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
52 |
|
108
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
53 run_hg_command(hg_pipe); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
54 // char *output = malloc(sizeof(char) * 2048); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
55 // char *curr = output; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
56 // int c; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
57 // int number_of_breakline = 0; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
58 // while ((c = fgetc(hg_pipe)) != NULL) |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
59 // { |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
60 // *curr++ = c; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
61 // printf("output: %s\n", output); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
62 // if (c == '\n') |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
63 // number_of_breakline++; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
64 // if (number_of_breakline == 2) |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
65 // break; |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
66 // printf("char: %c\n", c); |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
67 // } |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
68 pclose(hg_pipe); |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
69 |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
70 |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
71 return 0; |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
72 } |
|
108
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
73 |
|
f07abbcd2ec5
[HgWeb] Will probably hold off on using it since it is not urgent.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
74 |