Skip to content

Commit

Permalink
function
Browse files Browse the repository at this point in the history
  • Loading branch information
freakout42 committed Jun 25, 2024
1 parent 88069d2 commit 5ce3e3c
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 31 deletions.
1 change: 1 addition & 0 deletions generate/makeform
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ CREATE TABLE pages
);
INSERT INTO forms (id, name, title) VALUES (1, '$FORM', '$TITLE');
INSERT INTO blocks (form_id, name) VALUES (1, '$TABLE');
INSERT INTO blocks (id, form_id, name) VALUES (0, 1, 'dual');
INSERT INTO pages (form_id, name) VALUES (1, '$TABLE-0');
INSERT INTO pages (id, form_id, name, ysiz, vwpy0, border) VALUES (0, 1, 'formax', 1, 0, 0);
EOF
Expand Down
40 changes: 17 additions & 23 deletions runform/form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,38 @@ if (q.rows != 1) return 7;
id = q.c(1, 1);
name = q.c(1, 2);
title = q.c(1, 3);
close();

if (rblock.init(dbc)) return 9;
if ((s = rblock.query("name"))) return s;
if (rblock.q.rows != 1) return 7;
if (b[0].init(rblock.q, 1));
nb = rblock.q.rows;
if (nb > NBLOCKS) return 7;
for (i=0; i<nb; i++) if (b[i].init(rblock.q, i+1)) return 9;
rblock.close();
cb = 1;

if (rpage.init(dbc)) return 9;
if ((s = rpage.query("name,ysiz,xsiz,vwpy0,vwpx0,border"))) return s;
if (rpage.q.rows > NBLOCKS) return 7;
for (i=0; i<rpage.q.rows; i++) if (p[i].init(rpage.q, i+1)) return 9;
np = rpage.q.rows;
if (np > NBLOCKS) return 7;
for (i=0; i<np; i++) if (p[i].init(rpage.q, i+1)) return 9;
rpage.close();
if (rmap.init(dbc, 1)) return 9;
if ((s = rmap.query("line,mtext"))) return s;
if (p[1].maps(&rmap)) return 9;
rmap.close();

return 0;
}

int Form::run() {
Screen display;
if (display.init()) return 6;
p[0].create();
p[1].create();
p[0].writes(STATUSL, 2, title);
p[0].writef(STATUSL, 12, 0, 4, "%3s-", id);
p[0].writes(STATUSL, 16, name);
p[0].writes(STATUSL, 24, b[0].name);
p[0].writes(STATUSL, 60, p[1].name);
p[0].writes(STATUSL, 67, "runform-");
p[0].writes(STATUSL, 75, (char*)VERSION);
display.refresh();
p[1].refresh();
p[0].refresh();
move(0,0);
display.getkey();
display.close();
close();
int i;
Screen d;
Function u;
if (d.init()) return 6;
for (i=0; i<np; i++) p[i].create();
d.refresh();
lk = 0;
while (u.dispatch()) lk = p[0].wait();
d.close();
return 0;
}
13 changes: 8 additions & 5 deletions runform/form.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
class Form: public Record {
public:
char *id;
char *name;
char *title;
Block b[NBLOCKS];
Page p[NBLOCKS];
int cb;
int cf;
int nb; /* number of blocks */
int np; /* number of pages */
int cb; /* current block */
int cf; /* current field */
int lk; /* last key */
Block *init();
int fill(int id);
int run();
char *id;
char *name;
char *title;
private:
};
13 changes: 13 additions & 0 deletions runform/function.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <string.h>
#include "runform.h"

int Function::dispatch() {
int run;
run = 1;
switch(f.lk) {
case 0: f.p[1].refresh(); break;
case KEY_F(8): run = 0; break;
default: ;
}
return run;
}
6 changes: 6 additions & 0 deletions runform/function.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Function {
public:
int dispatch();
protected:
private:
};
13 changes: 13 additions & 0 deletions runform/page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,16 @@ if (border) wbox();
for (i = 0; i < NLINES; i++) if (map[i]) writes(i+(border?1:0), border?1:0, map[i]);
}

int Page::wait() {
writes(0, 2, f.title);
writef(0, 12, 0, 4, "%3s-", f.id);
writes(0, 16, f.name);
writes(0, 24, f.b[f.cb].name);
writef(0, 30, 0, 3, "%3d", f.lk);
writes(0, 60, f.p[1].name);
writes(0, 67, "runform-");
writes(0, 75, (char*)VERSION);
move(0,0);
refresh();
return getkey();
}
1 change: 1 addition & 0 deletions runform/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Page: public Screen {
void create();
char *name;
int maps(rMap *rmap);
int wait();
protected:
int vwpy0;
int vwpx0;
Expand Down
2 changes: 2 additions & 0 deletions runform/runform.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include "screen.h"
#include "page.h"
#include "form.h"
#include "function.h"
#define let(target,source) strncpy(target, source, sizeof(target))
#define t(target) target, sizeof(target)
extern int letf(char *target, size_t maxlen, char *format, ...);
extern char *xencrypt(char *toe, int rev);
extern int monochrome;
extern Form f;
7 changes: 4 additions & 3 deletions runform/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ termio.c_cc[VSUSP] = 0; /* ctrl-z */
#ifdef VLNEXT
termio.c_cc[VLNEXT] = 0;/* ctrl-v */
#endif
tcsetattr (fileno(stdin), TCSANOW, &termio);
noecho();
cbreak();
tcsetattr (0, TCSANOW, &termio);
nonl();
noecho();
//cbreak();
keypad(stdscr,TRUE);
getmaxyx(stdscr, ysiz, xsiz);
return 0;
Expand Down Expand Up @@ -121,6 +121,7 @@ switch (ch)
case KEY_CTRL('P'): return KEY_UP;
case KEY_CTRL('R'): return KEY_PPAGE;
case KEY_CTRL('V'): return KEY_NPAGE;
case KEY_CTRL('Z'): return KEY_F(8);
}
return ch;
}
Expand Down

0 comments on commit 5ce3e3c

Please sign in to comment.