commit 281782c21fb8490e654355f063269928b1962691
parent ccbdb75eb0bea1fe173da99fee12dfa1a9dc382e
Author: glenda <glenda@9front.local>
Date: Sun, 31 May 2020 09:35:43 +0000
some changes to getline func
Diffstat:
M | gophra.c | | | 75 | ++++++++++++++++++++++++++++++++++++++++----------------------------------- |
1 file changed, 40 insertions(+), 35 deletions(-)
diff --git a/gophra.c b/gophra.c
@@ -38,32 +38,32 @@ struct Loadctl {
Channel *c;
};
-
-Text text;
+Channel *lc;
History hzero, *hp;
Image *Iborder, *Iwbg, *Iwfg, *Iwfgl, *Istatus;
Rectangle rstatus, rw;
+Text text;
char status[256], path[256], addr[256], type;
-char *tmpfile = "/tmp/gophra.tmp";
+const char *tmpfile = "/tmp/gophra.tmp";
long scroll;
-Channel *lc;
-void usage(void);
-void threadload(void*);
+char* getline(Text*, long);
+int extracturl(char*);
+int runuri(char*);
+int save(char*, char*);
void back(void);
void calcrects(void);
void drawborder(void);
+void drawmenu(void);
void drawstatus(void);
void drawtext(void);
-void drawmenu(void);
-int extracturl(char*);
-char* getline(long);
void handlelink(char*, char, char*);
void loadtext(char*, char*);
+void resize(void);
void runhold(void*);
void runpage(void*);
-int save(char*, char*);
-int runuri(char*);
+void threadload(void*);
+void usage(void);
void
threadmain(int argc, char **argv)
@@ -167,7 +167,7 @@ threadmain(int argc, char **argv)
mpress = 1;
sline = (mv.xy.y - rw.min.y) / font->height +
scroll;
- s = getline(sline);
+ s = getline(&text, sline);
extracturl(s);
snprint(status, 255, "%s/%c%s", addr, type, path);
drawstatus();
@@ -178,7 +178,7 @@ threadmain(int argc, char **argv)
mpress = 1;
sline = (mv.xy.y - rw.min.y) / font->height +
scroll;
- s = getline(sline);
+ s = getline(&text, sline);
extracturl(s);
handlelink(addr, type, path);
if (s != 0) free(s);
@@ -189,13 +189,7 @@ threadmain(int argc, char **argv)
}
break;
case 2: /* resize */
- if(getwindow(display, Refnone) < 0)
- sysfatal("resize failed: %r");
- calcrects();
- drawborder();
- drawstatus();
- drawmenu();
- flushimage(display, 1);
+ resize();
break;
case 3: /* loading */
realloc(text.data, 0);
@@ -255,6 +249,17 @@ usage(void)
}
void
+resize(void)
+{
+ if(getwindow(display, Refnone) < 0) sysfatal("resize failed: %r");
+ calcrects();
+ drawborder();
+ drawstatus();
+ drawmenu();
+ flushimage(display, 1);
+}
+
+void
back(void)
{
History *oldh;
@@ -370,24 +375,24 @@ drawmenu(void)
}
char*
-getline(long ln)
+getline(Text *text, long ln)
{
- char *sbuf, *sp, *tp;
- long lc;
- sbuf = mallocz(sizeof(char) * 1024, 1);
- sp = sbuf;
- tp = text.data;
- for (lc = 0; lc < ln; tp++) {
- if (*tp == '\n') lc++;
- if (tp > text.data + text.size) return 0;
+ char *lbuf;
+ char *lstart, *lend;
+ long lcount;
+ lstart = text->data;
+ for (lcount = 0; lcount < ln; lstart++) {
+ if (*lstart == '\n') lcount++;
+ if (lstart > text->data + text->size) return 0;
}
- while (*tp != '\n') {
- *sp = *tp;
- sp++;
- tp++;
- if (tp > text.data + text.size) return 0;
+ lend = lstart;
+ while (*lend != '\n') {
+ lend++;
+ if (lend > text->data + text->size) return 0;
}
- return sbuf;
+ lbuf = mallocz(sizeof(char) * (lend - lstart + 1), 1);
+ memcpy(lbuf, lstart, lend - lstart);
+ return lbuf;
}
int