Commit 1b4d047e authored by Zack Wong's avatar Zack Wong

Improve panel structure

parent 0ea29264
......@@ -14,6 +14,11 @@
/* INCLUDES */
/*********************************************************************/
#include "pane.h"
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include <curses.h>
/*********************************************************************/
/* CONSTANT LITERALS */
......@@ -36,6 +41,7 @@ struct STATUS{
"",
};
/*********************************************************************/
/* PANE_A100_DRAW */
/*********************************************************************/
......@@ -43,8 +49,8 @@ void draw(Screen *scr) {
size_t oldy, oldx;
getyx(stdscr, oldy, oldx);
for (int i = 0; scr->flds[i].type != END; ++i) {
Field* fld = &scr->flds[i];
for (FNODE *node = scr->root ; node != NULL; node = node->next) {
Field* fld = node->field;
switch (fld->type) {
case INP:
move(fld->y, fld->x);
......@@ -112,20 +118,39 @@ void draw_status() {
refresh();
}
/*********************************************************************/
/* PANEL_X0100_QUERY_FLD_TREE */
/*********************************************************************/
Field* PANEL_X0100_QUERY_FLD_TREE(Screen* scr, int y, int x) {
return NULL;
} /* PANEL_X0100_QUERY_FLD_TREE */
/*********************************************************************/
/* PANEL_X0200_BUILD_SCREEN */
/*********************************************************************/
Screen* buildScreen(Field *fields) {
Screen* scr;
scr = (Screen*) calloc(1, sizeof(Screen));
scr->flds = fields;
int i = 0;
while (fields[i].type != INP) { ++i; }
scr->inps = &fields[i];
FNODE *prev = NULL;
while (fields[i].type != END) {
FNODE *node = (FNODE*) malloc(sizeof (FNODE));
node->field = &fields[i++];
if (scr->root == NULL) {
scr->root = node;
prev = node;
}
else {
prev->next = node;
prev = node;
}
}
return scr;
}
} /* PANEL_X0200_BUILD_SCREEN */
int start(Screen *scr) {
......@@ -176,8 +201,6 @@ int start(Screen *scr) {
draw_status();
break;
case 'q':
goto cleanup;
default:
break;
}
......
......@@ -41,6 +41,7 @@
/*********************************************************************/
#include <curses.h>
#include <stdint.h>
#include <stddef.h>
#include <malloc.h>
#include <string.h>
#include <stdbool.h>
......@@ -76,18 +77,17 @@ typedef struct Field {
void* (*callback)(char*);
} Field;
typedef struct Mask {
char type:4;
char padding:4;
short fldid;
}Mask;
typedef struct FNODE {
int offset;
Field *field;
struct FNODE *next;
} FNODE;
typedef struct Screen {
Field* flds;
Field* inps;
Field* fstout;
Field* fstinp;
FNODE* root;
Mask cell[80][43];
bool update;
struct Screen* (*submit)(struct Screen*);
}Screen;
......
......@@ -9,6 +9,8 @@ $(PROJECT) Makefile /^$(PROJECT) : $(OBJ) | obj\/$/;" t
BTN src/pane.h /^#define BTN /;" d
CFLAGS Makefile /^CFLAGS = -std=gnu11 -Wall -fpic$/;" m
END src/pane.h /^#define END /;" d
FNODE src/pane.h /^typedef struct FNODE {$/;" s
FNODE src/pane.h /^} FNODE;$/;" t typeref:struct:FNODE
Field src/pane.h /^typedef struct Field {$/;" s
Field src/pane.h /^} Field;$/;" t typeref:struct:Field
HEADERS Makefile /^HEADERS = $(wildcard src\/*.h)$/;" m
......@@ -16,9 +18,8 @@ HGT src/pane.c /^#define HGT /;" d file:
INP src/pane.h /^#define INP /;" d
INPT src/pane.h /^#define INPT /;" d
LBL src/pane.h /^#define LBL /;" d
Mask src/pane.h /^typedef struct Mask {$/;" s
Mask src/pane.h /^}Mask;$/;" t typeref:struct:Mask
OBJ Makefile /^OBJ = $(addprefix obj\/,$(notdir $(SRC:.c=.o)))$/;" m
PANEL_X0100_QUERY_FLD_TREE src/pane.c /^Field* PANEL_X0100_QUERY_FLD_TREE(Screen* scr, int y, int x) {$/;" f typeref:typename:Field *
PANE_H src/pane.h /^#define PANE_H$/;" d
PROJECT Makefile /^PROJECT = icpl$/;" m
RLR src/pane.h /^#define RLR /;" d
......@@ -31,35 +32,35 @@ attr src/pane.h /^ chtype attr;$/;" m struct:Field typeref:typename:chtype
buildScreen src/pane.c /^Screen* buildScreen(Field *fields) {$/;" f typeref:typename:Screen *
byte src/pane.h /^typedef unsigned char byte;$/;" t typeref:typename:unsigned char
callback src/pane.h /^ void* (*callback)(char*);$/;" m struct:Field typeref:typename:void * (*)(char *)
cell src/pane.h /^ Mask cell[80][43];$/;" m struct:Screen typeref:typename:Mask[80][43]
clean Makefile /^clean:$/;" t
debug Makefile /^debug: $(PROJECT)$/;" t
debug Makefile /^debug: CFLAGS += -g$/;" t
draw src/pane.c /^void draw(Screen *scr) {$/;" f typeref:typename:void
draw_status src/pane.c /^void draw_status() {$/;" f typeref:typename:void
fldid src/pane.h /^ short fldid;$/;" m struct:Mask typeref:typename:short
flds src/pane.h /^ Field* flds;$/;" m struct:Screen typeref:typename:Field *
field src/pane.h /^ Field *field;$/;" m struct:FNODE typeref:typename:Field *
fstinp src/pane.h /^ Field* fstinp;$/;" m struct:Screen typeref:typename:Field *
fstout src/pane.h /^ Field* fstout;$/;" m struct:Screen typeref:typename:Field *
inhibit src/pane.c /^ char *inhibit;$/;" m struct:STATUS typeref:typename:char * file:
init src/pane.c /^void init() {$/;" f typeref:typename:void
inps src/pane.h /^ Field* inps;$/;" m struct:Screen typeref:typename:Field *
isInsert src/pane.c /^ bool isInsert;$/;" m struct:STATUS typeref:typename:bool file:
len src/pane.h /^ , len;$/;" m struct:Field typeref:typename:size_t
next src/pane.h /^ struct FNODE *next;$/;" m struct:FNODE typeref:struct:FNODE *
nxfld src/pane.h /^ short nxfld;$/;" m struct:Field typeref:typename:short
obj/ Makefile /^obj\/:$/;" t
obj/%.o Makefile /^obj\/%.o : %.c $(HEADERS) | obj\/$/;" t
obj/%.o Makefile /^obj\/%.o : %.c %.h $(HEADERS) | obj\/$/;" t
padding src/pane.h /^ char padding:4;$/;" m struct:Mask typeref:typename:char:4
offset src/pane.h /^ int offset;$/;" m struct:FNODE typeref:typename:int
profile Makefile /^profile: $(PROJECT)$/;" t
profile Makefile /^profile: CFLAGS += -g -pg$/;" t
rebuild Makefile /^rebuild: clean release$/;" t
release Makefile /^release: $(PROJECT)$/;" t
release Makefile /^release: CFLAGS += -O3$/;" t
root src/pane.h /^ FNODE* root;$/;" m struct:Screen typeref:typename:FNODE *
start src/pane.c /^int start(Screen *scr) {$/;" f typeref:typename:int
status src/pane.c /^}status = {$/;" v typeref:struct:STATUS
submit src/pane.h /^ struct Screen* (*submit)(struct Screen*);$/;" m struct:Screen typeref:struct:Screen * (*)(struct Screen *)
text src/pane.h /^ char* text;$/;" m struct:Field typeref:typename:char *
type src/pane.h /^ byte type : 4;$/;" m struct:Field typeref:typename:byte:4
type src/pane.h /^ char type:4;$/;" m struct:Mask typeref:typename:char:4
update src/pane.h /^ bool update;$/;" m struct:Screen typeref:typename:bool
x src/pane.h /^ , x : 16$/;" m struct:Field typeref:typename:size_t:16
y src/pane.h /^ size_t y : 16$/;" m struct:Field typeref:typename:size_t:16
......@@ -84,7 +84,7 @@ Field MENUFLDS[] = { /* ISPF PRIMARY OPTION MENU */
[BTN5] = { BTN , 0, 48, 0,"Help" , A_NORMAL , },
/************************* INPUTS ***************************/
[INP0] = { INP , 3, 13, 66, "" , INPT , -1 },
[INP0] = { INP , 3, 13, 66, "" , INPT , NULL},
/************************* LABELS ***************************/
[OUT0] = { LBL , 3, 1, 0, "" , TEXT(2) , },
......@@ -109,6 +109,8 @@ bool WK_IS_VALID;
int MAIN_A000_INIT() {
init();
Screen *mainmenu = buildScreen(MENUFLDS);
mainmenu->fstinp = &MENUFLDS[INP0];
mainmenu->fstout = &MENUFLDS[OUT0];
mainmenu->submit = MAIN_A100_SUBMIT;
start(mainmenu);
......@@ -130,10 +132,6 @@ Screen* MAIN_A100_SUBMIT (Screen* self) {
getyx(stdscr, y, x);
if (self->cell[y][x].type == BTN){
/* MAIN_A110_ADD_SUBMENU();*/
return self;
}
MAIN_B120_VALIDATE_MENU();
if (WK_IS_VALID) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment