diff options
author | John Ankarström <john@ankarstrom.se> | 2020-10-23 02:08:13 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2020-10-23 02:08:13 +0200 |
commit | 24da48a86bb542be247127258db5fcafab4ba011 (patch) | |
tree | 30e7b826df0d52ae9f5b3b0c779c460b076d2043 | |
parent | 73bcdd66f3b4ce183bf8b9b0b5784830189c37f5 (diff) | |
download | tt-24da48a86bb542be247127258db5fcafab4ba011.tar.gz |
release 1.1
-rw-r--r-- | CHANGELOG.txt | 7 | ||||
-rw-r--r-- | test/indented-triple-pass/1=program.markdown | 34 | ||||
-rw-r--r-- | test/indented-triple-pass/2=program.markdown | 35 | ||||
-rw-r--r-- | test/indented-triple-pass/EXP=program.c | 9 | ||||
-rw-r--r-- | test/indented-triple-pass/OUT=program.c | 9 | ||||
-rw-r--r-- | test/indented-triple-pass/build.bat | 6 | ||||
-rw-r--r-- | test/indented-triple-pass/program.c | 1 | ||||
-rw-r--r-- | test/indented-triple-pass/program.markdown | 28 | ||||
-rw-r--r-- | test/truncation/EXP=test.txt | 3 | ||||
-rw-r--r-- | test/truncation/OUT=test.txt | 3 | ||||
-rw-r--r-- | test/truncation/build.bat | 4 | ||||
-rw-r--r-- | test/truncation/in.txt | 7 | ||||
-rw-r--r-- | test/truncation/test.txt | 3 | ||||
-rw-r--r-- | tt.c | 86 | ||||
-rw-r--r-- | tt.exe | bin | 60928 -> 61440 bytes |
15 files changed, 196 insertions, 39 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt new file mode 100644 index 0000000..c72de1a --- /dev/null +++ b/CHANGELOG.txt @@ -0,0 +1,7 @@ +CHANGELOG ----------------------- 1.1 ---------------------- 2020-05-26 + +NEW: Destination lines can now be space-indented. +FIX: Identifiers in destination lines are now currently truncated. + +NEW: test/indented-triple-pass +NEW: test/truncation
\ No newline at end of file diff --git a/test/indented-triple-pass/1=program.markdown b/test/indented-triple-pass/1=program.markdown new file mode 100644 index 0000000..db170bc --- /dev/null +++ b/test/indented-triple-pass/1=program.markdown @@ -0,0 +1,34 @@ +# My program -> program.c + + char *line; + int line_length; + int line_size; + int main(int argc, char *argv[]) { + int i; + <<main.options>> + ... + } + +## Main function -> main + +Here is the main function: + + int main(int argc, char *argv[]) { + int i; + for (i = 1; i < argc; i++) + ... + ... + } + +### Command-line options -> main.options + + for (i = 1; i < argc; i++) + ... + +### Declarations -> declarations + +So far, we have used the following global variables: + + char *line; + int line_length; + int line_size; diff --git a/test/indented-triple-pass/2=program.markdown b/test/indented-triple-pass/2=program.markdown new file mode 100644 index 0000000..38b3ee9 --- /dev/null +++ b/test/indented-triple-pass/2=program.markdown @@ -0,0 +1,35 @@ +# My program -> program.c + + char *line; + int line_length; + int line_size; + int main(int argc, char *argv[]) { + int i; + for (i = 1; i < argc; i++) + ... + ... + } + +## Main function -> main + +Here is the main function: + + int main(int argc, char *argv[]) { + int i; + for (i = 1; i < argc; i++) + ... + ... + } + +### Command-line options -> main.options + + for (i = 1; i < argc; i++) + ... + +### Declarations -> declarations + +So far, we have used the following global variables: + + char *line; + int line_length; + int line_size; diff --git a/test/indented-triple-pass/EXP=program.c b/test/indented-triple-pass/EXP=program.c new file mode 100644 index 0000000..37a8bc3 --- /dev/null +++ b/test/indented-triple-pass/EXP=program.c @@ -0,0 +1,9 @@ +char *line; +int line_length; +int line_size; +int main(int argc, char *argv[]) { + int i; + for (i = 1; i < argc; i++) + ... + ... +} diff --git a/test/indented-triple-pass/OUT=program.c b/test/indented-triple-pass/OUT=program.c new file mode 100644 index 0000000..37a8bc3 --- /dev/null +++ b/test/indented-triple-pass/OUT=program.c @@ -0,0 +1,9 @@ +char *line; +int line_length; +int line_size; +int main(int argc, char *argv[]) { + int i; + for (i = 1; i < argc; i++) + ... + ... +} diff --git a/test/indented-triple-pass/build.bat b/test/indented-triple-pass/build.bat new file mode 100644 index 0000000..be5a294 --- /dev/null +++ b/test/indented-triple-pass/build.bat @@ -0,0 +1,6 @@ +@echo off +setlocal +cd /d %~dp0 +..\..\tt -d# -o1= program.markdown < program.markdown +..\..\tt -d# -o2= program.markdown < "1=program.markdown" +..\..\tt -d# -oOUT= program.c < "2=program.markdown"
\ No newline at end of file diff --git a/test/indented-triple-pass/program.c b/test/indented-triple-pass/program.c new file mode 100644 index 0000000..d82e40b --- /dev/null +++ b/test/indented-triple-pass/program.c @@ -0,0 +1 @@ +<<program.c>>
\ No newline at end of file diff --git a/test/indented-triple-pass/program.markdown b/test/indented-triple-pass/program.markdown new file mode 100644 index 0000000..6628f00 --- /dev/null +++ b/test/indented-triple-pass/program.markdown @@ -0,0 +1,28 @@ +# My program -> program.c + + <<includes>> + <<declarations>> + <<main>> + +## Main function -> main + +Here is the main function: + + int main(int argc, char *argv[]) { + int i; + <<main.options>> + ... + } + +### Command-line options -> main.options + + for (i = 1; i < argc; i++) + ... + +### Declarations -> declarations + +So far, we have used the following global variables: + + char *line; + int line_length; + int line_size;
\ No newline at end of file diff --git a/test/truncation/EXP=test.txt b/test/truncation/EXP=test.txt new file mode 100644 index 0000000..35a7d8e --- /dev/null +++ b/test/truncation/EXP=test.txt @@ -0,0 +1,3 @@ +long + +far diff --git a/test/truncation/OUT=test.txt b/test/truncation/OUT=test.txt new file mode 100644 index 0000000..35a7d8e --- /dev/null +++ b/test/truncation/OUT=test.txt @@ -0,0 +1,3 @@ +long + +far diff --git a/test/truncation/build.bat b/test/truncation/build.bat new file mode 100644 index 0000000..2253752 --- /dev/null +++ b/test/truncation/build.bat @@ -0,0 +1,4 @@ +@echo off +setlocal +cd /d %~dp0 +..\..\tt -oOUT= test.txt < in.txt
\ No newline at end of file diff --git a/test/truncation/in.txt b/test/truncation/in.txt new file mode 100644 index 0000000..99a0f74 --- /dev/null +++ b/test/truncation/in.txt @@ -0,0 +1,7 @@ +-> loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong + + long + +-> faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + far
\ No newline at end of file diff --git a/test/truncation/test.txt b/test/truncation/test.txt new file mode 100644 index 0000000..6c2c776 --- /dev/null +++ b/test/truncation/test.txt @@ -0,0 +1,3 @@ +<<loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooon>> + +<<faaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar>>
\ No newline at end of file @@ -27,14 +27,14 @@ char *doc_prefix; char *ref; /* current reference */ -char **ins; /* insertions */ +char ***ins; /* insertions */ char **refs; /* references */ int refs_c; /* count */ int refs_s; /* size */ void reference(char *line) { int i, j; - char *ln, **tmp; + char *ln, **tmp, ***tmp2; ln = line; @@ -79,9 +79,9 @@ space: tmp = realloc(refs, refs_s * sizeof(char *)); if (tmp == NULL) err(1, "malloc"); refs = tmp; - tmp = realloc(ins, refs_s * sizeof(char *)); - if (tmp == NULL) err(1, "malloc"); - ins = tmp; + tmp2 = realloc(ins, refs_s * sizeof(char *)); + if (tmp2 == NULL) err(1, "malloc"); + ins = tmp2; for (i = refs_s - 10; i < refs_s; i++) /* TODO: is this right? */ ins[i] = NULL; } @@ -91,8 +91,8 @@ space: } bool code(char *line) { - char *in, *_in; /* current insertion */ - int i, j; + char **tmp; + int i, j, len; if (ref[0] == '\0') return false; if (strlen(code_prefix) > 0) @@ -104,30 +104,34 @@ bool code(char *line) { if (strcmp(refs[i], ref) == 0) break; if (ins[i] == NULL) { - ins[i] = malloc(1 + (strlen(line) + 1) * sizeof(char)); - j = 0; + ins[i] = malloc(1 + 1 * sizeof(char *)); + if (ins[i] == NULL) err(1, "malloc"); + len = 0; } else { - j = strlen(ins[i]); - _in = realloc(ins[i], - 1 + j * sizeof(char) + (strlen(line) + 1) * sizeof(char)); - if (_in == NULL) err(1, "malloc"); - ins[i] = _in; + for (len = 0; ins[i][len] != NULL; len++) ; + tmp = realloc(ins[i], 1 + (len + 1) * sizeof(char *)); + if (tmp == NULL) err(1, "malloc"); + ins[i] = tmp; } - strncpy(ins[i] + j, line + strlen(code_prefix), + ins[i][len+1] = NULL; + + ins[i][len] = malloc(1 + strlen(line) * sizeof(char)); + if (ins[i][len] == NULL) err(1, "malloc"); + + strncpy(ins[i][len], line + strlen(code_prefix), strlen(line) - strlen(code_prefix)); - ins[i][j + strlen(line) - strlen(code_prefix)] = '\n'; - ins[i][j + strlen(line) - strlen(code_prefix) + 1] = 0; + ins[i][len][strlen(line) - strlen(code_prefix)] = 0; return true; } int main(int argc, char *argv[]) { - bool finish, found, iscode, wascode; + bool finish, iscode, wascode; char **a, b, c, *line, *out_prefix, *tangledfile, *tmp; FILE *f, *fo; - int i, j, k; - int line_l, line_s, offset; + int i, j, k, m; + int indent, line_l, line_s, offset; ref = malloc(1 + (REFMAX + 4) * sizeof(char)); /* incl. << and >> */ if (ref == NULL) err(1, "malloc"); @@ -135,7 +139,7 @@ int main(int argc, char *argv[]) { refs_c = 0; refs_s = 10; refs = malloc(refs_s * sizeof(char *)); - ins = malloc(refs_s * sizeof(char *)); + ins = malloc(refs_s * sizeof(char **)); if (refs == NULL || ins == NULL) err(1, "malloc"); for (i = 0; i < refs_s; i++) ins[i] = NULL; @@ -244,41 +248,45 @@ finish2: line[line_l] = '\0'; line_l = 0; /* reset line length count */ - if (strncmp(line, "<<", 2) != 0 - || strncmp(line + strlen(line) - 2, ">>", 2) != 0) { + ref = line; + for (indent = 0; *ref == ' '; ref++) indent++; + + if (strncmp(ref, "<<", 2) != 0 + || strncmp(ref + strlen(ref) - 2, ">>", 2) != 0) { fprintf(f, "%s\n", line); continue; } - line += 2; - line[strlen(line) - 2] = '\0'; + ref += 2; + ref[strlen(ref) - 2] = '\0'; - for (i = 0; i < strlen(line); i++) - if (isspace(line[i])) { + for (i = 0; i < strlen(ref); i++) + if (isspace(ref[i])) { fprintf(f, "%s\n", line); continue; } - if (strlen(line) > REFMAX) + if (strlen(ref) > REFMAX) fprintf(stderr, "Warning: Truncating identifier exceeding %d characters\n", REFMAX); - ref = line; - - found = false; for (i = 0; i < refs_c; i++) - if (strcmp(refs[i], ref) == 0) { found = true; break; } - if (!found) { - fprintf(stderr, "Unreferenced destination: %s\n", ref); - continue; - } + if (strncmp(refs[i], ref, REFMAX) == 0) goto found; + fprintf(stderr, "Unreferenced destination: %s\n", ref); + continue; +found: if (ins[i] == NULL) { fprintf(stderr, "Warning: Insertion for %s is empty\n", ref); continue; } - if (strncmp(ins[i] + strlen(ins[i]) - 2, "\n\n", 2) == 0) - ins[i][strlen(ins[i]) - 1] = '\0'; /* remove extra newline */ - fprintf(f, "%s", ins[i]); + for (j = 0; ins[i][j] != NULL; j++) { + if (ins[i][j + 1] == NULL) { + if (strlen(ins[i][j]) == 0) + break; /* remove extra newline */ + } + for (m = indent; m > 0; m--) putc(' ', f); + fprintf(f, "%s\n", ins[i][j]); + } } if (c != '\n' && !finish) { finish = true; goto finish2; } |