commit 778f3e3
0uppy
·
2026-07-24 22:36:56 +0000 UTC
parent c21782b
cotton v0.2 - cot's printing was reworked again, not its just print again but you can optionally add /n at the end of a string to do the same println would :P
1 files changed,
+20,
-28
+20,
-28
1@@ -53,8 +53,8 @@ static char
2 return s;
3 }
4
5-static const char *get_var_value
6-(Cotton *cotton, const char *name)
7+static const char
8+*get_var_value(Cotton *cotton, const char *name)
9 {
10 for (int i = 0; i < cotton->var_count; i++) {
11 if (strcmp(cotton->vars[i].name, name) == 0) {
12@@ -66,14 +66,14 @@ static const char *get_var_value
13
14 // da graphics stuff
15
16-static void draw_pixel
17-(Cotton *cotton, int x, int y)
18+static void
19+draw_pixel (Cotton *cotton, int x, int y)
20 {
21 cotton->video[y * VIDEO_WIDTH + x] = cotton->c_cottolette;
22 }
23
24-static void draw_char
25-(Cotton *cotton, char c, int x, int y)
26+static void
27+draw_char (Cotton *cotton, char c, int x, int y)
28 {
29 for (int row = 0; row < FONT_HEIGHT; row++) {
30 uint8_t bits = EIKI_FONT[(uint8_t)c][row];
31@@ -90,11 +90,19 @@ static void draw_char
32 // da commands
33
34 static void
35-cmd_pre_print(Cotton *cotton, CottonWindow *cw, char *arg, int newline) // idfk how else to rename this :sob:
36+cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
37 {
38 if (!arg)
39 return;
40
41+ int nl = 0;
42+ char *nl_str = strstr(arg, " /n");
43+
44+ if (nl_str != NULL) {
45+ nl = 1;
46+ *nl_str = '\0';
47+ }
48+
49 char *text = strip_quotes(arg);
50
51 const char *value = get_var_value(cotton, text);
52@@ -102,7 +110,7 @@ cmd_pre_print(Cotton *cotton, CottonWindow *cw, char *arg, int newline) // idfk
53 text = (char *)value;
54 }
55
56- if (newline) {
57+ if (nl) {
58 printf("%s\n", text);
59 } else {
60 printf("%s", text);
61@@ -125,24 +133,12 @@ cmd_pre_print(Cotton *cotton, CottonWindow *cw, char *arg, int newline) // idfk
62 }
63 }
64
65- if (newline) {
66+ if (nl) {
67 cotton->cursor_x = 0;
68 cotton->cursor_y += FONT_HEIGHT + 4;
69 }
70-
71- cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
72-}
73-
74-static void
75-cmd_print(Cotton *cotton, CottonWindow *cw, char *arg)
76-{
77- cmd_pre_print(cotton, cw, arg, 0);
78-}
79
80-static void
81-cmd_println(Cotton *cotton, CottonWindow *cw, char *arg)
82-{
83- cmd_pre_print(cotton, cw, arg, 1);
84+ cottonwindow_update(cw, cotton->video, sizeof(cotton->video[0]) * VIDEO_WIDTH);
85 }
86
87 static void
88@@ -326,8 +322,8 @@ cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file)
89
90 strip_newline(line);
91
92- // cot shall use # comments like C because C is cool and i love C so bwaaa
93- if (line[0] == '\0' || line[0] == '#')
94+ // there used to be a joke about cot using # comments "like C" which was an inside joke but after this being pointed out because of genuine curiosity i decided to just change the comments in cot to //, more used to that anyway bwaa
95+ if (line[0] == '\0' || line[0] == '//')
96 return;
97
98 char line_copy[MAX_LINE];
99@@ -347,10 +343,6 @@ cotton_interpret(Cotton *cotton, CottonWindow *cw, FILE *file)
100 cmd_print(cotton, cw, arg);
101 }
102
103- else if (strcmp(cmd, "println") == 0) {
104- cmd_println(cotton, cw, arg);
105- }
106-
107 else if (strcmp(cmd, "var") == 0) {
108 cmd_var(cotton, arg);
109 }