commit 665dc21b5c31c628c2f941d81d3d76ff12202ea1
parent 4fb782045034e10871abd6e9dc915574ff7c1036
Author: gearsix <gearsix@tuta.io>
Date: Sat, 10 Jul 2021 02:34:21 +0100
implemented passing local files as args, had to move a lot about.
Also started help() and adding verbose() logs. txt2html now uses
requires a pattern similair to strtok but with FLE *.
Diffstat:
A | test.html | | | 38 | ++++++++++++++++++++++++++++++++++++++ |
M | txt2html.c | | | 71 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- |
2 files changed, 96 insertions(+), 13 deletions(-)
diff --git a/test.html b/test.html
@@ -0,0 +1,38 @@
+txt2html: reading...<p>generated using https://jaspervdj.be/lorem-markdownum/</p>
+<h1>Nec rumpunt nacta</h1>
+<h2>Natus advena venit ipse cornua flumina</h2>
+<p>Lorem markdownum concurrere; tot eodem nulli: tamen hunc supplex das. Sustineat parens, mox unda nec vix instrumenta, caeruleus arcisque. Hac mundi fessos date fecit Dicta madefacta oscula condiderat Gaudia Latous terra si iuris: medio: per. Et dea vulnus ostendit pronus, docuique vel Luna consumite tibi nobis. Huic tale et si altae caeleste: cur flectentem Lethaei consilioque mediis.</p>
+<ol>
+ <li>Sacris unda ad aquis celebrare movensque spectes 2. Suppressis laniaverat terror 3. Nec medendi neque insolida 4. Iam ut everti nactusque tamquam et cetera 5. Paternos murmurat dixit</li>
+</ol>
+</ol>
+<p>Artus fors ulnas tuebere. Est quod fecit curva latentem ostendit! Orsa quid dixi sui, pendebat acres, vero Minervam iube artis et in. Sibi aevum erit est misit lina qui.</p>
+<h2>Noverit bis Saturno ora variarum notent concipit</h2>
+<p>Reddat error; es videt. Lacrimis matris, sua isse summa statione dispositam negat viridique et faces flammas, lacertis me.</p>
+<p>Horae protinus femineam genuit certe docebo silentum cuspide capitis, rogabo rarissima vitis, resupinoque. Parantem mollia longis grates Pallante, me funesto dixit incipiens petens. Sit novena, curru Cyanen tandem concretam; edidit traiectus facta.</p>
+<ul>
+ <li>Desere erexit</li>
+ <li>Amor vates Oenides succiso rescindere in amorem</li>
+ <li>Anhelo ante genu crepitantia ponit tui socii</li>
+ <li>Mater mundi silentia expellere et piget magnorum</li>
+ <li>Corpora aethera armatur femina</li>
+</ul>
+<h2>Ora tempora pabula</h2>
+<p>Poteramus dente? Triplex ultra nec quoque, vix, et amore. Per fratres intres domus, regnare ignota nemorum dimittit quodsi curvamine Castrumque: fidem? Mihi praecipuum Creten tenendae, iussum in viam, sensisse audebatis titulum in rigidi suae, tum.</p>
+<ul>
+ <li>Passosque nostri tenetur</li>
+ <li>Robustior nostras acta amantem albentibus mora</li>
+ <li>Simul superabat aequore Rhamnusidis nidor nostro</li>
+</ul>
+<p>Fasque multae posset caelestibus suaque in et mihi nunc similis fatale fuerunt. Longa vestigia luminis spargit, cum inpediique, vel damno bina quadrupes ope me! Circumdata abesse carinae: inficere ille tam nimis nihil haec iacuit satis, quae molles desuetudine dixit, noctes. Quamvis superest vices suus ferentes dixit, ore post solent iunctis. Forma mihi sub negata visura.</p>
+<h2>Exhalat voce</h2>
+<p>Qui furto dare illud pars, Romana bene dolore medias deducit destinat et lucos duo strigis, a. Ut illo oportuit, qui tu nunc lactens refert anxia dixi: Peleus pro. Icta brevis. Meum atris plumis finitque at Elymumque moras per Ino hominumque relictus legumque detulit quisquis optet nupta vultu: pro veni. Laetitia liceat.</p>
+<p>Pennis unam praesens separat lacrimaeque prior sideribus et equos. Uno sola illum, quam procos precibus obliquo aduncae ad excipit, redditur dignissime corvus harundinibus limoso. Et ac cacumine vosne. Vidit his, te et secura licet: adsueta superum nunc vixque neque sumere infans lacusque incubat!</p>
+<ol>
+ <li>Ima ad sustinet iuratus Antium b. Fama tuo aere orbis c. Perterrita temone contingere Hippotadaeque inmanis decipit imitata d. Tollit cervicibus aede magnanimi atque ostendens noxae e. Crudeles poterunt credensque Ulixem videre</li>
+</ol>
+</ol>
+<h2>Munera dextra cur agmen posuistis quoscumque opem</h2>
+<p>Tenus monstri tamen, litem taurus pande auxiliaribus Creteque habet mollia error; nec. Qui omnia qui, in hic genitor factus origine nuper sanguine ferventibus.</p>
+<p>1.a. Abeunt quos templa 2.a. Strata si questaque sibi claro multicavo accipiter 3.a. Et dicta Piscibus taurus 4.a. Inque Romani 5.a. Desistunt et enim</p>
+<p>Sinistra fallere: valuere: hos patet ita, propriaque. Nemus factus nam videtur sponsi. Alas non perque sagitta creverunt totumque turbine nec lilia populo vesci hac frena sui membris ne postes haut notam digiti! Antiphates flexi videnda colebat caelo lac pars laedar! Telo coniuge spectas est modo rapit dolens Arcesius nobilis principiis video nec iterum caerula. </p>
diff --git a/txt2html.c b/txt2html.c
@@ -30,31 +30,72 @@ struct node {
int readp(struct node *n, char *txt, int txti);
int isheading(char *txt, int txti);
void writebuf(struct node *n, int c);
-struct node *txt2html(char *txt);
+struct node *txt2html(char *txt, struct node *n);
struct node *newnode(struct node *prev, struct node *next, uint8_t tag);
struct node *closenode(struct node *n);
-const uint8_t opts = OPT_HB;
+void help()
+{
+
+}
+
+void verbose(const char *log)
+{
+ printf("txt2html: %s", log);
+}
+
+uint8_t opts = 0;
int main(int argc, char **argv)
{
- char *text = "12345\n====\n\n12345\n67890\n\n123\n---\n\n- 1\n- 2\n- 3\n";
- char *html = malloc(4062);
+ int i = 0, a = argc;
+ for (; a > 1; --a) {
+ if (argv[a] == NULL)
+ continue;
+ if (argv[a][i] == '-') {
+ if (strcmp(argv[a], "-h") == 0 ||
+ strcmp(argv[a], "--help") == 0) {
+ help();
+ a = 0;
+ }
+ if (strcmp(argv[a], "-br") == 0 ||
+ strcmp(argv[a], "-break") == 0)
+ opts |= OPT_HB;
+ argv[a][0] = '\0';
+ }
+ }
+
- struct node *n = txt2html(text);
- while(n != NULL) {
- if (n->buf != NULL)
+ char c;
+ for (a = 1, c = EOF; a < argc; ++a) {
+ FILE *f = fopen(argv[a], "r");
+ struct node *html = NULL, *n = NULL;
+ do {
+ verbose("reading...\r");
+ char buf[BUFSIZ] = {'\0'};
+ fread(buf, BUFSIZ-1, sizeof(char), f);
+ n = txt2html(buf, n);
+ c = fgetc(f);
+ if (c != EOF)
+ if (ungetc(c, f) == EOF) perror("txt2html: ungetc() fail");
+ } while (c != EOF);
+ do {
+ if (n->next == NULL) break;
+ n = n->next;
printf("%s", n->buf);
- //printf("%02x='%s'\n", n->type, n->buf);
- n = n->next;
+ } while (n->buf != NULL);
+ fclose(f);
}
return EXIT_SUCCESS;
}
-struct node *txt2html(char *txt)
+struct node *txt2html(char *txt, struct node *n)
{
- struct node *n = malloc(ASTLIMIT * sizeof(struct node));
+ int cont = 0;
+ if (n == NULL)
+ n = malloc(ASTLIMIT * sizeof(struct node));
+ else cont = 1;
const size_t len = strlen(txt);
unsigned int i = 0;
@@ -176,8 +217,12 @@ EXIT:
}
}
- while (n->prev != NULL)
- n = n->prev;
+ if ((n->type & CLOSE) == 1)
+ n = NULL;
+ else
+ closenode(n);
+ while (n->prev != NULL) n = n->prev;
+
return n;
}