Skip to content

Commit

Permalink
Comment (#29)
Browse files Browse the repository at this point in the history
* c1

* mcomm1

* more comments
  • Loading branch information
freakout42 authored Sep 17, 2024
1 parent 5ce6aab commit 4f39fcd
Show file tree
Hide file tree
Showing 39 changed files with 197 additions and 61 deletions.
2 changes: 1 addition & 1 deletion runform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ run: runform $(EXAMPLE)
# ./runform ../generate/formax.frm ../generate/formax.frm 2>$@

test: runform $(EXAMPLE)
valgrind --quiet $(VALGRINDSUP) --leak-check=yes --track-origins=yes --suppressions=valgrind.sup \
/opt/valgrind/bin/valgrind --quiet $(VALGRINDSUP) --leak-check=yes --track-origins=yes --suppressions=valgrind.sup \
./runform -g/tmp/formax.log $(EXAMPLE) 2>$@
test -f $@ -a ! -s $@

Expand Down
15 changes: 15 additions & 0 deletions runform/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ columni = fieldcount;
return fieldcount;
}

/* orm retrieve respects the colquery conditions */
int Block::select() {
int i;
char wall[MEDSIZE-2];
Expand All @@ -46,35 +47,45 @@ let(where, wall);
return query();
}

/* block field name */
char *Block::cn(int c) {
return F(l[blockfields[c]]).name;
}

/* orm update by bind variables - disable usebindvar=FALSE completely */
int Block::update(int r, int c) {
#ifdef USEBINDVARFALSEENABLED
if (usebindvar) {
#endif
letf((char*)querystr, sizeof(querystr), "update %s set %s = ? where %s = ?", table, cn(c-1), F(l[primarykeys[0]]).name);
bindv[0] = q->v(r, c);
bindv[1] = q->v(r, F(l[primarykeys[0]]).sequencenum);
bindv[2] = NULL;
#ifdef USEBINDVARFALSEENABLED
} else {
letf((char*)querystr, sizeof(querystr), "update %s set %s = '%s' where %s = '%s'", table, cn(c-1), q->v(r, c),
F(l[primarykeys[0]]).name, q->v(r, F(l[primarykeys[0]]).sequencenum));
bindv[0] = NULL;
}
#endif
if ((ret = execute(querystr, bindv))) return ret;
return complete();
}

int Block::destroy(int r) {
#ifdef USEBINDVARFALSEENABLED
if (usebindvar) {
#endif
letf((char*)querystr, sizeof(querystr), "delete from %s where %s = ?", table, F(l[primarykeys[0]]).name);
bindv[0] = q->v(r, F(l[primarykeys[0]]).sequencenum);
bindv[1] = NULL;
#ifdef USEBINDVARFALSEENABLED
} else {
letf((char*)querystr, sizeof(querystr),
"delete from %s where %s = '%s'", table, F(l[primarykeys[0]]).name, q->v(r, F(l[primarykeys[0]]).sequencenum));
bindv[0] = NULL;
}
#endif
if ((ret = execute(querystr, bindv))) return ret;
return complete();
}
Expand All @@ -93,12 +104,16 @@ for (i=0; i<fieldcount; i++) {
catc(t(columnslist), sep);
cats(t(columnslist), F(l[blockfields[i]]).name);
catc(t(valueslist), sep);
#ifdef USEBINDVARFALSEENABLED
if (usebindvar) {
#endif
cats(t(valueslist), "?");
bindv[j++] = q->v(r, i+1);
#ifdef USEBINDVARFALSEENABLED
} else {
letf(t(valueslist), "'%s'", q->v(r, i+1));
}
#endif
sep = ',';
}
}
Expand Down
4 changes: 3 additions & 1 deletion runform/block.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// the block
/* dynamic table setup from config data
* or free access without sql-hassle
*/
class Block: public Record {
public:
int init(Qdata *blk, int rix);
Expand Down
4 changes: 1 addition & 3 deletions runform/cqerror.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* Called by cqparse on error
* does nothing
*/
/* Called by cqparse on error - does nothing */
void cqerror(char *s)
{ ; }

3 changes: 1 addition & 2 deletions runform/curkeys.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* builds curkeys.h for using keys without curses.h
*/
/* builds curkeys.h for using keys macros KEY_* without including curses.h */
#include <stdio.h>
#include <curses.h>

Expand Down
11 changes: 11 additions & 0 deletions runform/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sequencenum = F(b[blockindex].addattribute)(rix-1);
return 0;
}

/* check whether field is editable in current mode */
int Field::noedit() {
switch(CM) {
case MOD_UPDATE: if (isprimarykey || !(updateable || (updnulable && *valuep()==NULL))) return 1; break;
Expand All @@ -50,10 +51,12 @@ switch(CM) {
return 0;
}

/* high level field type adds boolean for special treatment */
ftype Field::fldtype() {
return (fieldtype==FTY_INT && lowvalue==0 && highvalue==1) ? FTY_BOOL : fieldtype;
}

/* display the field according to mode */
void Field::show(int cur) {
int color;
switch(CM) {
Expand All @@ -67,6 +70,7 @@ F(p[1]).writef(line, col, color, displaylen, "%.*s", displaylen, CM==MOD_QUERY ?
if (cur) F(p[1]).wmov(line, col);
}

/* clear field content */
void Field::clear() {
char **v;
if (CM == MOD_QUERY) {
Expand All @@ -83,6 +87,7 @@ char **Field::valuep() {
return F(b[blockindex].q->w)(CB.currentrecord, sequencenum);
}

/* toggle boolean field value between 0 and 1 */
int Field::toggle() {
char **c;
if (CM == MOD_UPDATE && fldtype() == FTY_BOOL) {
Expand All @@ -97,6 +102,7 @@ if (CM == MOD_UPDATE && fldtype() == FTY_BOOL) {
return KEF_CANCEL;
}

/* increment/decrement integer field value */
int Field::increment(int ival) {
char **c;
int a;
Expand All @@ -112,6 +118,7 @@ if (CM == MOD_UPDATE && fieldtype == FTY_INT) {
return 0;
}

/* checks new field value with validation rules */
int Field::validate(char **c, char *buf) {
char *u;
re_t re;
Expand Down Expand Up @@ -160,6 +167,10 @@ if (*c) {
return 0;
}

/* call the field editor depending on pos and current mode
* when changed validate the new content and return next key
* return KEF_CANCEL on cancel | no changes | validation fail
*/
int Field::edit(int pos) {
int pressed;
char buf[BIGSIZE];
Expand Down
2 changes: 1 addition & 1 deletion runform/field.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// the field
/* the field */
class Field {
public:
int field_id;
Expand Down
31 changes: 21 additions & 10 deletions runform/form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let(order, "id");
columni = 3;
}

/* connect all configuration tables to the form database */
void Form::rconnect() {
rerror.connect(*this);
rblock.connect(*this);
Expand All @@ -24,11 +25,11 @@ rmap.connect(*this);
rtrigger.connect(*this);
}

// fill objects with configuation
/* fill objects with configuation */
int Form::fill(int fid) {
int i, s;

// the form itself
/* the form configuration itself */
stmt = NULL;
if ((s = ropen())) return s;
letf(t(where), "id = %d", fid);
Expand All @@ -40,7 +41,7 @@ let(title, q->v(1, 3));
needredraw = 0;
rclose();

// triggers
/* triggers */
if (rtrigger.init(fid)) return 9;
if ((s = rtrigger.query())) return s;
numtrigger = rtrigger.q->rows;
Expand All @@ -50,9 +51,16 @@ for (i=0; i<numtrigger; i++) {
}
rtrigger.rclose();

// pages - page [0]/1.0 is status/edit/message window
// [1]/3.1 is working window
// [2]/2.2 is key help popup
/* i id seq desc
* pages - page [0] 1 0 status/edit/message window
* [1] 4 1 working window
* [2] 2 2 key help popup
* [3] 3 3 editor
* INSERT INTO pages VALUES(1,1,'status',0,'',1,80,0,0,0,0,0);
* INSERT INTO pages VALUES(2,0,'keyhelp',2,'',16,41,2,30,1,1,0);
* INSERT INTO pages VALUES(3,0,'editor',3,'',21,65,2,14,1,1,0);
* INSERT INTO pages VALUES(4,0,'formax',1,'',23,80,1,0,0,1,0);
*/
if (rpage.init(fid)) return 9;
if ((s = rpage.query())) return s;
numpage = rpage.q->rows;
Expand All @@ -66,14 +74,14 @@ for (i=0; i<numpage; i++) {
}
rpage.rclose();

// error messages
/* error messages */
if (rerror.init()) return 9;
if ((s = rerror.query())) return s;
e = rerror.q;
rerror.q = new(Qdata);
rerror.rclose();

// blocks - block 0 is for free queries/sql statements
/* blocks - block 0 is for free queries/sql statements */
if (rblock.init(fid)) return 9;
if ((s = rblock.query())) return s;
numblock = rblock.q->rows;
Expand All @@ -84,7 +92,7 @@ for (i=0; i<numblock; i++) {
}
rblock.rclose();

// fields
/* fields */
if (rfield.init(fid)) return 9;
if ((s = rfield.query())) return s;
numfield = rfield.q->rows;
Expand All @@ -97,14 +105,15 @@ rfield.rclose();
return 0;
}

/* cleanup the form with all blocks and pages */
void Form::clear() {
int i;
e->freed();
for (i=0; i<numblock; i++) b[i].rclose();
for (i=0; i<numpage; i++) p[i].destroy();
}

// set-up screen and pages and execute through the event dispatcher
/* set-up screen and pages and execute through the event dispatcher */
int Form::run() {
int i, s;
if (y.init()) return 6;
Expand All @@ -117,6 +126,7 @@ y.closedisplay();
return s==-1 ? 0 : s;
}

/* application key mapping physical to function */
int Form::mapkey(int ckey) {
int ck;
ck = ispunctation(ckey);
Expand Down Expand Up @@ -152,3 +162,4 @@ switch(ck) { /* C */
default: return ck;
}
}

2 changes: 1 addition & 1 deletion runform/form.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BEGINSQL
// form configuration
/* form configuration */
class Form: public Record {
public:
Form();
Expand Down
3 changes: 3 additions & 0 deletions runform/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,14 @@ int Function::previous_item() { return fmove(0, -1); }
int Function::next_record() { return fmover(1); }
int Function::previous_record() { return fmover(-1); }

/* export functions to javascript */
#define JSEXA(func) jsval_t j_ ## func (struct js *js, jsval_t *args, int nargs) { return js_mknum(u.func()); }
JSEXA(next_item)
JSEXA(previous_item)
JSEXA(next_record)
JSEXA(previous_record)

/* move from field to field */
int Function::fmove(int bi, int fi) {
//F(curblock) = (F(curblock) + F(numblock) + bi) % F(numblock);
if (fi < NFIELD1) F(curfield) = CB.blockfields[ (CF.sequencenum-1 + CB.fieldcount + fi) % CB.fieldcount ];
Expand All @@ -148,6 +150,7 @@ if (CF.noedit()) fmove(0, fi<0 ? -1 : 1);
return 0;
}

/* move from record to record */
int Function::fmover(int ri) {
switch (CM) {
case MOD_QUERY: return 0; break;
Expand Down
2 changes: 1 addition & 1 deletion runform/function.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// event functions - the workhorse
/* event functions - the workhorse */
class Function {
public:
int dispatch();
Expand Down
8 changes: 6 additions & 2 deletions runform/logger.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* logging sql engine via sqlite3 lib - not odbc */
#include <cstdarg>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -25,13 +26,13 @@ static int session = -1;
static char message[MEDSIZE];
static char sqlquery[MEDSIZE*2];

/* the only read is for the session id from the returning clause of _INSERTLOGIN */
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
if (session == 0 && argc == 1) session = atoi(argv[0]);
return 0;
}
// for (i=0; i<argc; i++) {
// fprintf(stderr, "%s", argv[i] ? argv[i] : "NULL");

/* create the tables when not existing */
void Logger::init(char *dsn) {
int rc;
char na[4];
Expand Down Expand Up @@ -80,6 +81,9 @@ sqlite3_exec(db, sqlquery, callback, 0, NULL);
va_end (args);
} }

/* must escape apostrophes and interpolate the bind variables
* so that the queries can be executed by cut and paste
*/
void Logger::logsql(char *sql, char *bnd[]) {
int i, j, k, l, m;
char *r;
Expand Down
1 change: 1 addition & 0 deletions runform/logger.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* logging sql engine via sqlite3 lib - not odbc */
#ifndef SQLITE3_H
typedef struct sqlite3 sqlite3;
#endif
Expand Down
Loading

0 comments on commit 4f39fcd

Please sign in to comment.