commit 81f4675ff9e021dd947ba4c145d5633f0cade50d
parent 4b9c35837a1546b1f8f6bd55926b657a79561f51
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Mon, 26 Jul 2021 20:07:11 +0000
initial code for extra/mdprint
Diffstat:
3 files changed, 58 insertions(+), 5 deletions(-)
diff --git a/extra/mdprint.c b/extra/mdprint.c
@@ -0,0 +1,47 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+
+char *
+newobj(void)
+{
+ char *buf;
+ int fd;
+ long n;
+ fd = open("/mnt/richterm/new", OREAD);
+ if (fd < 0) sysfatal("%r");
+ buf = mallocz(256, 1);
+ n = read(fd, buf, 256);
+ buf[n-1] = '\0';
+ close(fd);
+ return buf;
+}
+
+void
+main(int argc, char **argv)
+{
+ int fd;
+ Biobuf *bp;
+ char *lp;
+ if (argc > 1) {
+ if ((fd = open(argv[1], OREAD)) < 0)
+ sysfatal("can't open %s, %r", argv[1]);
+ } else fd = 0;
+ print("---\n");
+ bp = Bfdopen(fd, OREAD);
+ while ((lp = Brdstr(bp, '\n', 0)) != nil) {
+ char *id;
+ char *path;
+ int td;
+ id = newobj();
+ path = smprint("/mnt/richterm/%s/text", id);
+ print("%s\n", path);
+ //td = open(path, OWRITE);
+ //if (td < 0) sysfatal("%r");
+ //write(td, lp, strlen(lp));
+ //close(td);
+ free(lp);
+ free(id);
+ free(path);
+ }
+}
diff --git a/extra/mkfile b/extra/mkfile
@@ -0,0 +1,5 @@
+</$objtype/mkfile
+
+TARG=mdprint
+
+</sys/src/cmd/mkmany
+\ No newline at end of file
diff --git a/richterm.c b/richterm.c
@@ -213,7 +213,7 @@ generatepage(Rich *rich)
page->count++;
page->view = realloc(page->view, sizeof(View) * (page->count));
v = page->view + page->count - 1;
-
+
v->obj = obj;
v->color = display->black;
if (((Faux *)obj->flink->aux)->data->n > 0) v->color = Ilink;
@@ -227,7 +227,7 @@ generatepage(Rich *rich)
v->dp = sp;
v->length = aux->data->n;
-
+
if ((brkp = strpbrk(v->dp, "\n\t")) != 0) {
v->length = brkp - v->dp;
sp = v->dp + v->length + 1;
@@ -245,10 +245,10 @@ generatepage(Rich *rich)
v->length--;
sp = v->dp + v->length;
}
-
+
v->r = Rpt(pt, Pt(pt.x + stringnwidth(v->font, v->dp, v->length),
pt.y + v->font->height));
-
+
ymax = (ymax > v->r.max.y) ? ymax : v->r.max.y;
pt.x = v->r.max.x;
if (tab != 0) {
@@ -268,7 +268,7 @@ generatepage(Rich *rich)
pt.x = r.min.x;
pt.y = ymax;
}
-
+
if (v->length >= aux->data->n - 1) {
obj++;
if (obj < rich->obj + rich->count) {