From 56a6e78765ed8d4d68d3a8771a18aed61bbd78ba Mon Sep 17 00:00:00 2001 From: Dawid Sobczak Date: Tue, 1 Apr 2025 18:16:28 +0100 Subject: [PATCH] update --- .ignore => .helix/.ignore | 0 00/Makefile | 2 +- 01/Makefile | 6 +- 02/Makefile | 6 +- 03/Makefile | 6 +- 04/Makefile | 6 +- 04a/Makefile | 6 +- 05/Makefile | 2 +- 06/arith.peg | 5 - 06/kitty | 13 -- 06/test.zig | 8 +- Makefile | 8 +- markdown.c | 239 --------------------------- bootstrap.sh => scripts/bootstrap.sh | 0 kitty => scripts/kitty | 0 kitty.conf => scripts/kitty.conf | 0 16 files changed, 18 insertions(+), 289 deletions(-) rename .ignore => .helix/.ignore (100%) delete mode 100644 06/arith.peg delete mode 100755 06/kitty delete mode 100644 markdown.c rename bootstrap.sh => scripts/bootstrap.sh (100%) rename kitty => scripts/kitty (100%) rename kitty.conf => scripts/kitty.conf (100%) diff --git a/.ignore b/.helix/.ignore similarity index 100% rename from .ignore rename to .helix/.ignore diff --git a/00/Makefile b/00/Makefile index b882d3e..3dd4a18 100644 --- a/00/Makefile +++ b/00/Makefile @@ -1,4 +1,4 @@ -all: README.html out00 +all: out00 out00: in00 ./hexcompile %.html: %.md ../markdown diff --git a/01/Makefile b/01/Makefile index f40b401..585706d 100644 --- a/01/Makefile +++ b/01/Makefile @@ -1,9 +1,7 @@ -all: out01 README.html +all: out01 out01: in01 out00 ./out00 out00: in00 ../00/hexcompile -%.html: %.md ../markdown - ../markdown $< clean: - rm -f out00 out01 README.html + rm -f out00 out01 diff --git a/02/Makefile b/02/Makefile index 17b0b0e..8e9a823 100644 --- a/02/Makefile +++ b/02/Makefile @@ -1,9 +1,7 @@ -all: out01 out02 README.html +all: out01 out02 out01: in01 ../01/out00 out02: out01 in02 ./out01 -%.html: %.md ../markdown - ../markdown $< clean: - rm -f out01 out02 README.html + rm -f out01 out02 diff --git a/03/Makefile b/03/Makefile index 2a50640..5443e6e 100644 --- a/03/Makefile +++ b/03/Makefile @@ -1,9 +1,7 @@ -all: out02 out03 README.html +all: out02 out03 out02: in02 ../02/out01 ../02/out01 out03: out02 in03 ./out02 -%.html: %.md ../markdown - ../markdown $< clean: - rm -f out* README.html + rm -f out* diff --git a/04/Makefile b/04/Makefile index ae9568c..28e2dc8 100644 --- a/04/Makefile +++ b/04/Makefile @@ -1,11 +1,9 @@ -all: out03 guessing_game.out out04 README.html +all: out03 guessing_game.out out04 out03: in03 ../03/out02 ../03/out02 -%.html: %.md ../markdown - ../markdown $< out04: in04 out03 ./out03 %.out: % out03 ./out03 $< $@ clean: - rm -f out* README.html *.out + rm -f out* *.out diff --git a/04a/Makefile b/04a/Makefile index f88d708..b8df194 100644 --- a/04a/Makefile +++ b/04a/Makefile @@ -1,9 +1,7 @@ -all: out04 out04a README.html +all: out04 out04a out04: in04 ../04/out03 ../04/out03 out04a: in04a out04 ./out04 -%.html: %.md ../markdown - ../markdown $< clean: - rm -f out* README.html + rm -f out* diff --git a/05/Makefile b/05/Makefile index 74765e1..bb8e458 100644 --- a/05/Makefile +++ b/05/Makefile @@ -47,4 +47,4 @@ $(TCC)1a: $(TCCDIR)/*.c $(TCCDIR)/*.h clean: rm -rf musl-bootstrap rm -rf tcc-bootstrap - rm -f out* README.html *.out *.o $(TCCDIR)/tcc[0123456] $(TCCDIR)/tcc[0123456]a $(TCCDIR)/lib/*.[oa] + rm -f out* *.out *.o $(TCCDIR)/tcc[0123456] $(TCCDIR)/tcc[0123456]a $(TCCDIR)/lib/*.[oa] diff --git a/06/arith.peg b/06/arith.peg deleted file mode 100644 index cf994a4..0000000 --- a/06/arith.peg +++ /dev/null @@ -1,5 +0,0 @@ -Expr <- Sum -Sum <- Product (('+' / '-') Product)* -Product <- Power (('*' / '/') Power)* -Power <- Value ('^' Power)? -Value <- [0-9]+ / '(' Expr ')' \ No newline at end of file diff --git a/06/kitty b/06/kitty deleted file mode 100755 index 5a16c7f..0000000 --- a/06/kitty +++ /dev/null @@ -1,13 +0,0 @@ -new_tab code -layout horizontal -launch --title "code" bash - -new_tab terminal -layout horizontal -launch bash - -new_tab ranger -enabled_layouts horizontal,stack -layout horizontal -launch ranger - diff --git a/06/test.zig b/06/test.zig index 6e4c9c5..8ae7065 100644 --- a/06/test.zig +++ b/06/test.zig @@ -1,6 +1,4 @@ - - - pub fn main() void { - const x = 0; -} \ No newline at end of file + const x = 0; + if (x) {} +} diff --git a/Makefile b/Makefile index c9647d7..07f2436 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: markdown README.html +all: $(MAKE) -C 00 $(MAKE) -C 01 $(MAKE) -C 02 @@ -8,6 +8,8 @@ all: markdown README.html # don't compile all of 05 because it takes a while $(MAKE) -C 05 $(MAKE) -C 05 tcc + $(MAKE) -C 05 tcc-files + $(MAKE) -C 05 musl $(MAKE) -C 06 clean: $(MAKE) -C 00 clean @@ -20,7 +22,3 @@ clean: $(MAKE) -C 06 clean rm -f markdown rm -f README.html -markdown: markdown.c - $(CC) -O2 -o markdown -Wall -Wconversion -Wshadow -std=c89 markdown.c -README.html: markdown README.md - ./markdown README.md diff --git a/markdown.c b/markdown.c deleted file mode 100644 index a99e179..0000000 --- a/markdown.c +++ /dev/null @@ -1,239 +0,0 @@ -/* -a little program to convert markdown to html, for READMEs -I was using markdown.pl but that has some annoying problems -This doesn't support all of markdown; I'll add more as I need it. -*/ - -#include -#include -#include - -/* output text with *s for italics and stuff */ -static void output_md_text(FILE *out, int *flags, int line_number, const char *text) { - enum { - FLAG_I = 0x01, /* italics */ - FLAG_B = 0x02, - FLAG_CODE = 0x04 - }; - const char *p; - - for (p = text; *p; ++p) { - if ((*flags & FLAG_CODE) && *p != '`') { - switch (*p) { - case '<': fprintf(out, "<"); break; - case '>': fprintf(out, ">"); break; - case '&': fprintf(out, "&"); break; - default: putc(*p, out); break; - } - continue; - } - switch (*p) { - case '\\': - ++p; - if (*p == '\0') { - fprintf(stderr, "line %d: Unterminated \\.\n", line_number); - exit(-1); - } - fprintf(out, "%c", *p); - break; - case '*': - if (p[1] == '*') { - /* bold */ - if (*flags & FLAG_B) { - fprintf(out, ""); - *flags &= ~FLAG_B; - } else { - fprintf(out, ""); - *flags |= FLAG_B; - } - ++p; - } else { - /* italics */ - if (*flags & FLAG_I) { - fprintf(out, ""); - *flags &= ~FLAG_I; - } else { - fprintf(out, ""); - *flags |= FLAG_I; - } - } - break; - case '`': - /* code */ - if (*flags & FLAG_CODE) { - fprintf(out, ""); - *flags &= ~FLAG_CODE; - } else { - fprintf(out, ""); - *flags |= FLAG_CODE; - } - break; - case '[': { - /* link */ - char url2[256] = {0}; - const char *label, *url, *label_end, *url_end; - char *dot; - int n_label, n_url; - - label = p+1; - label_end = strchr(label, ']'); - if (!label_end) { - fprintf(stderr, "line %d: Unterminated link.\n", line_number); - exit(-1); - } - if (label_end[1] != '(') { - fprintf(stderr, "line %d: Bad link syntax.\n", line_number); - exit(-1); - } - url = label_end + 2; - url_end = strchr(url, ')'); - if (!url_end) { - fprintf(stderr, "line %d: Unterminated URL.\n", line_number); - exit(-1); - } - - n_label = (int)(label_end - label); - n_url = (int)(url_end - url); - if (n_url > sizeof url2-8) - n_url = sizeof url2-8; - sprintf(url2, "%.*s", n_url, url); - dot = strrchr(url2, '.'); - if (dot && strcmp(dot, ".md") == 0) { - /* replace links to md files with links to html files */ - strcpy(dot, ".html"); - } - fprintf(out, "%.*s", - url2, n_label, label); - p = url_end; - } break; - case '-': - if (p[1] == '-') { - /* em dash */ - fprintf(out, "—"); - ++p; - } else { - goto default_case; - } - break; - default: - default_case: - putc(*p, out); - break; - } - } -} - -int main(int argc, char **argv) { - FILE *in, *out; - char line[1024] = {0}; - char title[256] = {0}; - int flags = 0, txtflags = 0; - int line_number = 0; - enum { - FLAG_UL = 1 - }; - - if (argc < 2) { - fprintf(stderr, "Please provide an input file.\n"); - return -1; - } - - { - const char *in_filename = argv[1]; - char out_filename[256] = {0}; - char *dot; - strncpy(out_filename, argv[1], 200); - dot = strrchr(out_filename, '.'); - if (!dot || strcmp(dot, ".md") != 0) { - fprintf(stderr, "Input filename does not end in .md\n"); - return -1; - } - *dot = '\0'; - strcpy(title, out_filename); - strcpy(dot, ".html"); - - - in = fopen(in_filename, "rb"); - out = fopen(out_filename, "wb"); - } - - if (!in) { - perror("Couldn't open input file"); - return -1; - } - if (!out) { - perror("Couldn't open output file"); - return -1; - } - - fprintf(out, - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "%s\n" - "\n" - "\n" - "

\n", title - ); - while (fgets(line, sizeof line, in)) { - ++line_number; - line[strcspn(line, "\r\n")] = '\0'; - - if (line[0] == '#') { - /* heading */ - int n = 1; - while (line[n] == '#') ++n; - fprintf(out, "

", n); - output_md_text(out, &txtflags, line_number, line + n); - fprintf(out, "

\n", n); - } else if (line[0] == '\0') { - if (flags & FLAG_UL) { - fprintf(out, "\n"); - flags &= ~FLAG_UL; - } - fprintf(out, "

\n

\n"); - } else if (strncmp(line, "- ", 2) == 0) { - /* bullet */ - if (flags & FLAG_UL) { - fprintf(out, "

  • "); - } else { - fprintf(out, "
    • "); - flags |= FLAG_UL; - } - output_md_text(out, &txtflags, line_number, line + 2); - fprintf(out, "\n"); - } else if (strncmp(line, "```", 3) == 0) { - fprintf(out, "
      \n");
      -			
      -			while (fgets(line, sizeof line, in)) {
      -				char *p;
      -				++line_number;
      -				if (strncmp(line, "```", 3) == 0)
      -					break;
      -				for (p = line; *p; ++p) {
      -					switch (*p) {
      -					case '<': fprintf(out, "<"); break;
      -					case '>': fprintf(out, ">"); break;
      -					case '&': fprintf(out, "&"); break;
      -					default: fputc(*p, out); break;
      -					}
      -				}
      -			}
      -
      -			fprintf(out, "
      \n"); - } else { - output_md_text(out, &txtflags, line_number, line); - fprintf(out, "\n"); - } - - - - } - fprintf(out, "

      \n\n\n"); - return 0; -} diff --git a/bootstrap.sh b/scripts/bootstrap.sh similarity index 100% rename from bootstrap.sh rename to scripts/bootstrap.sh diff --git a/kitty b/scripts/kitty similarity index 100% rename from kitty rename to scripts/kitty diff --git a/kitty.conf b/scripts/kitty.conf similarity index 100% rename from kitty.conf rename to scripts/kitty.conf