diff --git a/icpl/src/pane.c b/icpl/src/pane.c index 290d5275c7edeb723e9add991b035e08039b22f1..fa4c00db1b6b0cdfde85d464fc968375b43db3aa 100755 --- a/icpl/src/pane.c +++ b/icpl/src/pane.c @@ -17,6 +17,7 @@ #include <stdbool.h> #include <stdlib.h> #include <stdint.h> +#include <ctype.h> #include <curses.h> @@ -24,6 +25,7 @@ /* CONSTANT LITERALS */ /*********************************************************************/ #define HGT 23 +#define WDT 80 /*********************************************************************/ /* FUNCTION DECLARATIONS */ @@ -45,24 +47,40 @@ struct STATUS{ /*********************************************************************/ /* PANE_A100_DRAW */ /*********************************************************************/ -void draw(Screen *scr) { - size_t oldy, oldx; - getyx(stdscr, oldy, oldx); - +void draw(Screen *scr) { + + size_t oldy, oldx; + + getyx(stdscr, oldy, oldx); + + + for (FNODE *node = scr->root ; node != NULL; node = node->next) { Field* fld = node->field; - switch (fld->type) { - case INP: - move(fld->y, fld->x); - attron(fld->attr); - addstr(fld->text); - for (int i = strlen(fld->text); i < fld->len; i++) addch(' '); - break; - case LBL: - move(fld->y, fld->x); - attron(fld->attr); - addstr(fld->text); - break; + switch (fld->type) { + + case INP: + + move(fld->y, fld->x); + + attron(fld->attr); + + addstr(fld->text); + + for (int i = strlen(fld->text); i < fld->len; i++) addch(' '); + + break; + + case LBL: + + move(fld->y, fld->x); + + attron(fld->attr); + + addstr(fld->text); + + break; + case BTN: move(0, fld->x); attron(TEXT(7)); @@ -75,16 +93,19 @@ void draw(Screen *scr) { hline(NCURSES_ACS(*fld->text),fld->len); break; default: - break; + break; + } standend(); } - move(oldy, oldx); + move(oldy, oldx); + } void init() { initscr(); - noecho(); + noecho(); + cbreak(); keypad(stdscr, true); curs_set(1); @@ -119,16 +140,63 @@ void draw_status() { } /*********************************************************************/ -/* PANEL_X0100_QUERY_FLD_TREE */ +/* PANEL_X0100_GET_FLD */ /*********************************************************************/ -Field* PANEL_X0100_QUERY_FLD_TREE(Screen* scr, int y, int x) { +Field* PANEL_X0100_GET_FLD(Screen* scr, int y, int x) { + for (Field *fd = scr->fstinp; fd != NULL; fd = fd->nxfld) { + if (fd->y == y && (x >= fd->x && x < fd->x + fd->len )) { + return fd; + } + } return NULL; -} /* PANEL_X0100_QUERY_FLD_TREE */ +} /* PANEL_X0100_GET_FLD */ + +/*********************************************************************/ +/* PANEL_X0200_PUTCHAR */ +/*********************************************************************/ +Field* PANEL_X0200_PUTCHAR(Screen* scr, int y, int x, char ch) { + Field *fd = PANEL_X0100_GET_FLD(scr, y, x); + if (fd) { + attron(fd->attr); + addch(ch); + standend(); + if (x == fd->x + fd->len -1 ) { + if (fd->nxfld) + move(fd->nxfld->y, fd->nxfld->x); + else + move (y,x); + } + } + + return fd; +} /* PANEL_X0200_PUTCHAR */ + +/*********************************************************************/ +/* PANEL_X0300_GO_HOME */ +/*********************************************************************/ +void PANEL_X0300_GO_HOME(Screen* scr, int *y, int *x) { + Field *fd = PANEL_X0100_GET_FLD(scr, *y, *x); + if (fd) { + *y = fd->y; + *x = fd->x; + } +} /* PANEL_X0300_GO_HOME */ + +/*********************************************************************/ +/* PANEL_X0400_GO_END */ +/*********************************************************************/ +void PANEL_X0400_GO_END(Screen* scr, int *y, int *x) { + Field *fd = PANEL_X0100_GET_FLD(scr, *y, *x); + if (fd) { + *y = fd->y; + *x = fd->x + fd->len -1; + } +} /* PANEL_X0400_GO_END */ /*********************************************************************/ -/* PANEL_X0200_BUILD_SCREEN */ +/* PANEL_X0300_BUILD_SCREEN */ /*********************************************************************/ Screen* buildScreen(Field *fields) { Screen* scr; @@ -152,9 +220,23 @@ Screen* buildScreen(Field *fields) { return scr; } /* PANEL_X0200_BUILD_SCREEN */ +/*********************************************************************/ +/* PANEL_U0100_GET_FIELD_TEXT */ +/*********************************************************************/ +char* PANEL_U0100_GET_FIELD_TEXT(Field *fld) { + char *buf = malloc(WDT + 1); + int x, y; + getyx(stdscr,y, x); + mvinstr(fld->y, fld->x, buf); + move(y,x); + return buf; +} /* PANEL_U0100_GET_FIELD_TEXT */ + + +int start(Screen *scr) { + + init(); -int start(Screen *scr) { - init(); draw(scr); int x, y; @@ -169,48 +251,83 @@ int start(Screen *scr) { int ch = getch(); - switch (ch) { - case KEY_LEFT: - if (x > 0) - x--; - break; - case KEY_RIGHT: - if (x < 79) - x++; - break; - case KEY_UP: - if (y > 0) - y--; - break; - case KEY_DOWN: - if (y < HGT - 1) - y++; - break; - case KEY_HOME: - case KEY_STAB: - case KEY_BTAB: - case KEY_END: + switch (ch) { + + case KEY_LEFT: + + if (x > 0) + + x--; + + break; + + case KEY_RIGHT: + + if (x < 79) + + x++; + + break; + + case KEY_UP: + + if (y > 0) + + y--; + + break; + + case KEY_DOWN: + + if (y < HGT - 1) + + y++; + + break; + + case KEY_HOME: + + PANEL_X0300_GO_HOME(scr, &y, &x); + break; + case KEY_END: + + PANEL_X0400_GO_END(scr, &y, &x); + break; + case KEY_STAB: + + case KEY_BTAB: + + break; case 10: case KEY_ENTER: status.inhibit = "X - SYSTEM"; draw_status(); scr = scr->submit(scr); + if(!scr) + goto exit; status.inhibit = " "; draw_status(); break; default: - break; + if (isprint(ch)) { + if(PANEL_X0200_PUTCHAR(scr, y, x, ch)){ + getyx(stdscr,y, x); + goto redraw;} + } + break; + } addch(chr); +redraw: chr = mvinch(y,x); // save attr attr = chr & A_ATTRIBUTES; chgat(1, A_REVERSE | attr, 0, NULL); draw_status(); } - cleanup: +exit: endwin(); return 0; } diff --git a/icpl/src/pane.h b/icpl/src/pane.h index 80ac69af49c073b56f804508161ebe0f11a92551..c978a04578a535d5b6c1791f2cd6f4da5e1b4eea 100755 --- a/icpl/src/pane.h +++ b/icpl/src/pane.h @@ -73,7 +73,7 @@ typedef struct Field { , len; char* text; chtype attr; - short nxfld; + struct Field *nxfld; void* (*callback)(char*); } Field; @@ -98,5 +98,7 @@ typedef struct Screen { /*********************************************************************/ extern void init(); extern int start(Screen* scr); +Field* PANEL_X0100_GET_FLD(Screen* scr, int y, int x); +extern char* PANEL_U0100_GET_FIELD_TEXT(Field *fld); extern Screen* buildScreen(Field *fields); #endif diff --git a/icpl/tags b/icpl/tags index 1f6da14c130e182d760ddd2ca41756bd32217f95..0499668e60a9930e83cb8aecbe466ad652d5e68f 100644 --- a/icpl/tags +++ b/icpl/tags @@ -19,7 +19,11 @@ INP src/pane.h /^#define INP /;" d INPT src/pane.h /^#define INPT /;" d LBL src/pane.h /^#define LBL /;" d 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 * +PANEL_U0100_GET_FIELD_TEXT src/pane.c /^char* PANEL_U0100_GET_FIELD_TEXT(Field *fld) {$/;" f typeref:typename:char * +PANEL_X0100_GET_FLD src/pane.c /^Field* PANEL_X0100_GET_FLD(Screen* scr, int y, int x) {$/;" f typeref:typename:Field * +PANEL_X0200_PUTCHAR src/pane.c /^Field* PANEL_X0200_PUTCHAR(Screen* scr, int y, int x, char ch) {$/;" f typeref:typename:Field * +PANEL_X0300_GO_HOME src/pane.c /^void PANEL_X0300_GO_HOME(Screen* scr, int *y, int *x) {$/;" f typeref:typename:void +PANEL_X0400_GO_END src/pane.c /^void PANEL_X0400_GO_END(Screen* scr, int *y, int *x) {$/;" f typeref:typename:void PANE_H src/pane.h /^#define PANE_H$/;" d PROJECT Makefile /^PROJECT = icpl$/;" m RLR src/pane.h /^#define RLR /;" d @@ -28,6 +32,7 @@ STATUS src/pane.c /^struct STATUS{$/;" s file: Screen src/pane.h /^typedef struct Screen {$/;" s Screen src/pane.h /^}Screen;$/;" t typeref:struct:Screen TEXT src/pane.h /^#define TEXT(/;" d +WDT src/pane.c /^#define WDT /;" d file: 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 @@ -45,7 +50,7 @@ init src/pane.c /^void init() {$/;" f typeref:typename:void 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 +nxfld src/pane.h /^ struct Field *nxfld;$/;" m struct:Field typeref:struct:Field * obj/ Makefile /^obj\/:$/;" t obj/%.o Makefile /^obj\/%.o : %.c $(HEADERS) | obj\/$/;" t obj/%.o Makefile /^obj\/%.o : %.c %.h $(HEADERS) | obj\/$/;" t diff --git a/ispf/src/main.c b/ispf/src/main.c index d3a581c4509eb21b222af80e0caf946662283aac..38fccf09dedd41e9bb7d2f841f037099a05b8bbc 100755 --- a/ispf/src/main.c +++ b/ispf/src/main.c @@ -40,6 +40,8 @@ /*********************************************************************/ #include "../../icpl/src/pane.h" #include <stdbool.h> /* STDLIB BOOLEANS TYPE */ +#include <string.h> /* STDLIB STRING FUNCTIONS */ +#include <ctype.h> /* STDLIB TYPE UTILITY */ /*********************************************************************/ /* PREPROCESSOR DEFS */ @@ -51,6 +53,7 @@ #define TXTOPT "Option ===>" #define TXTCMD "Command ===>" #define TXTHDR "ISPF Primary Option Menu" +#define TXTQIT "Option X to terminate" enum FLDNUM { BTN0, @@ -67,8 +70,8 @@ enum FLDNUM { /* FUNCTION DECLARATIONS */ /*********************************************************************/ Screen* MAIN_A100_SUBMIT (Screen*); -void MAIN_B130_GET_NEXT_SCREEN (); -void MAIN_B120_VALIDATE_MENU (); +void MAIN_B130_GET_NEXT_SCREEN (Screen*); +void MAIN_B120_DO_MENU_ACTION (); /*********************************************************************/ /* LOCAL DECLARATIONS */ @@ -84,12 +87,13 @@ Field MENUFLDS[] = { /* ISPF PRIMARY OPTION MENU */ [BTN5] = { BTN , 0, 48, 0,"Help" , A_NORMAL , }, /************************* INPUTS ***************************/ - [INP0] = { INP , 3, 13, 66, "" , INPT , NULL}, + [INP0] = { INP , 3, 13, 66, "" , INPT , }, /************************* LABELS ***************************/ [OUT0] = { LBL , 3, 1, 0, "" , TEXT(2) , }, /*AUTO*/ { LBL , 2, 28, 0,TXTHDR , TEXT(4) , }, /*AUTO*/ { LBL , 3, 1, 0,TXTOPT , TEXT(2) , }, + /*AUTO*/ { LBL , 20, 10, 0,TXTQIT , TEXT(7) , }, /************************* RULERS ***************************/ /*AUTO*/ { RLR, 1, 1, 78, "q" , TEXT(4) , }, @@ -100,6 +104,7 @@ Field MENUFLDS[] = { /* ISPF PRIMARY OPTION MENU */ /* WK_STORAGE */ /*********************************************************************/ bool WK_IS_VALID; +Screen *WK_SCREEN; /*********************************************************************/ @@ -128,36 +133,45 @@ int MAIN_A000_INIT() { /* MAIN_A100_SUBMIT */ /*********************************************************************/ Screen* MAIN_A100_SUBMIT (Screen* self) { + WK_SCREEN = self; int y, x; getyx(stdscr, y, x); - MAIN_B120_VALIDATE_MENU(); - if (WK_IS_VALID) { - MAIN_B130_GET_NEXT_SCREEN(); - } - else { - } + Field *WK_CUR_FIELD = PANEL_X0100_GET_FLD(self,y,x); + + if (WK_CUR_FIELD->type == BTN) + MAIN_B120_DO_MENU_ACTION(); + else + MAIN_B130_GET_NEXT_SCREEN(self); - return self; + return WK_SCREEN; } /* MAIN_A100_SUBMIT */ /*********************************************************************/ -/* MAIN_B120_VALIDATE_MENU */ +/* MAIN_B120_DO_MENU_ACTION */ /*********************************************************************/ -void MAIN_B120_VALIDATE_MENU (){ - - +void MAIN_B120_DO_MENU_ACTION() { + addch('*'); return; -} /* MAIN_B120_VALIDATE_MENU */ +} /* MAIN_B120_DO_MENU_ACTION */ /*********************************************************************/ /* MAIN_B130_GET_NEXT_SCREEN */ /*********************************************************************/ -void MAIN_B130_GET_NEXT_SCREEN (){ +void MAIN_B130_GET_NEXT_SCREEN (Screen *self){ + char* text = PANEL_U0100_GET_FIELD_TEXT(self->fstinp); + for (int i = 0; i < strlen(text); ++i) { + text[i] = toupper(text[i]); + } + char* token = strtok(text, " "); + + if (strcmp(token,"X") == 0) + WK_SCREEN = NULL; + // ADD OTHER OPTIONS HERE return;