OpenCOBOL 1.1pre-rel
Classes | Defines | Functions | Variables
screenio.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ncursesw/ncurses.h>
#include "move.h"
#include "coblocal.h"
#include "screenio.h"
Include dependency graph for screenio.c:

Go to the source code of this file.

Classes

struct  cob_inp_struct

Defines

#define _XOPEN_SOURCE_EXTENDED
#define COB_GEN_SCREENIO
#define COB_INP_SIZE   1920 * sizeof(struct cob_inp_struct)

Functions

void cob_screen_terminate (void)
void cob_screen_display (cob_screen *s, cob_field *line, cob_field *column)
void cob_screen_accept (cob_screen *s, cob_field *line, cob_field *column)
void cob_field_display (cob_field *f, cob_field *line, cob_field *column, cob_field *fgc, cob_field *bgc, cob_field *scroll, const int attr)
void cob_field_accept (cob_field *f, cob_field *line, cob_field *column, cob_field *fgc, cob_field *bgc, cob_field *scroll, const int attr)
void cob_screen_line_col (cob_field *f, const int l_or_c)
void cob_screen_set_mode (const size_t smode)

Variables

int cob_screen_initialized = 0
int cob_screen_mode = 0

Define Documentation

#define _XOPEN_SOURCE_EXTENDED

Definition at line 30 of file screenio.c.

#define COB_GEN_SCREENIO

Definition at line 33 of file screenio.c.

#define COB_INP_SIZE   1920 * sizeof(struct cob_inp_struct)

Definition at line 64 of file screenio.c.


Function Documentation

void cob_field_accept ( cob_field f,
cob_field line,
cob_field column,
cob_field fgc,
cob_field bgc,
cob_field scroll,
const int  attr 
)

Definition at line 855 of file screenio.c.

{
        unsigned char   *p;
        size_t          count;
        int             keyp;
        int             fret;
        int             sline;
        int             scolumn;
        int             cline;
        int             ccolumn;
        int             rightpos;
        int             ateof;
        int             gotbacksp;

        if (!cob_screen_initialized) {
                cob_screen_init ();
        }

        if (scroll) {
                keyp = cob_get_int (scroll);
                if (attr & COB_SCREEN_SCROLL_DOWN) {
                        keyp = -keyp;
                }
                scrollok (stdscr, 1);
                scrl (keyp);
                scrollok (stdscr, 0);
                refresh ();
        }
        cob_exception_code = 0;
        get_line_column (line, column, &sline, &scolumn);
        move (sline, scolumn);
        cob_screen_attr (fgc, bgc, attr);
        p = f->data;
        for (count = 0; count < f->size; count++) {
                if (attr & COB_SCREEN_SECURE) {
                        addch ('*');
                } else if (attr & COB_SCREEN_UPDATE) {
                        fret = *p++;
                        addch ((unsigned int)fret);
                } else if (attr & COB_SCREEN_PROMPT) {
                        addch ('_');
                } else {
                        addch (' ');
                }
        }
        move (sline, scolumn);
        if (!(attr & COB_SCREEN_UPDATE)) {
                if (COB_FIELD_IS_NUMERIC (f)) {
                        cob_move (&cob_zero, f);
                } else {
                        memset (f->data, ' ', f->size);
                }
        }

        fret = 0;
        ateof = 0;
        gotbacksp = 0;
        rightpos = scolumn + f->size - 1;
        p = f->data;
        for (; ;) {
                refresh ();
                keyp = getch ();
                if (keyp == KEY_ENTER || keyp == '\n') {
                        break;
                }
                if (keyp > KEY_F0 && keyp < KEY_F(65)) {
                        fret = 1000 + keyp - KEY_F0;
                        break;
                }
                if (cob_extended_status) {
                        if (keyp == KEY_PPAGE) {
                                fret = 2001;
                                break;
                        }
                        if (keyp == KEY_NPAGE) {
                                fret = 2002;
                                break;
                        }
                        if (keyp == KEY_UP) {
                                fret = 2003;
                                break;
                        }
                        if (keyp == KEY_DOWN) {
                                fret = 2004;
                                break;
                        }
                        if (keyp == KEY_PRINT) {
                                fret = 2006;
                                break;
                        }
                        if (cob_use_esc) {
                                if (keyp == 033) {
                                        fret = 2005;
                                        break;
                                }
                        }
                }
                getyx (stdscr, cline, ccolumn);
                if (keyp == KEY_BACKSPACE || keyp == ('H' & 037) ||
                    keyp == 0177) {
                        if (ccolumn > scolumn) {
                                if (gotbacksp || ccolumn != rightpos) {
                                        ccolumn--;
                                } else {
                                        ateof = 0;
                                }
                                gotbacksp = 1;
                                move (cline, ccolumn);
                                if (attr & COB_SCREEN_SECURE) {
                                        addch ('*');
                                } else {
                                        addch ('_');
                                }
                                move (cline, ccolumn);
                                p = f->data + ccolumn - scolumn;
                                *p = ' ';
                                continue;
                        }
                }
                if (keyp == KEY_HOME) {
                        move (sline, scolumn);
                        p = f->data;
                        ateof = 0;
                        gotbacksp = 0;
                        continue;
                }
                if (keyp == KEY_END) {
                        move (sline, rightpos);
                        p = f->data + f->size - 1;
                        ateof = 0;
                        gotbacksp = 0;
                        continue;
                }
                if (keyp == KEY_LEFT) {
                        if (ccolumn > scolumn) {
                                ccolumn--;
                                move (cline, ccolumn);
                                p = f->data + ccolumn - scolumn;
                                continue;
                        }
                        gotbacksp = 0;
                }
                if (keyp == KEY_RIGHT) {
                        if (ccolumn < rightpos) {
                                ccolumn++;
                                move (cline, ccolumn);
                                p = f->data + ccolumn - scolumn;
                                continue;
                        }
                        gotbacksp = 0;
                }
                if (keyp > 037 && keyp < (int)A_CHARTEXT) {
                        if (COB_FIELD_IS_NUMERIC (f)) {
                                if (keyp < '0' || keyp > '9') {
                                        beep ();
                                        continue;
                                }
                        }
                        gotbacksp = 0;
                        *p = keyp;
                        if (attr & COB_SCREEN_SECURE) {
                                addch ('*');
                        } else {
                                addch ((unsigned int)keyp);
                        }
                        if (ccolumn == rightpos) {
                                if (attr & COB_SCREEN_AUTO) {
                                        break;
                                }
                                move (cline, ccolumn);
                                if (ateof) {
                                        beep ();
                                } else {
                                        ateof = 1;
                                }
                        } else {
                                p++;
                        }
                        continue;
                }
                gotbacksp = 0;
                beep ();
        }
        cob_check_pos_status (fret);
        refresh ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_field_display ( cob_field f,
cob_field line,
cob_field column,
cob_field fgc,
cob_field bgc,
cob_field scroll,
const int  attr 
)

Definition at line 826 of file screenio.c.

{
        int sline;
        int scolumn;

        if (!cob_screen_initialized) {
                cob_screen_init ();
        }

        if (scroll) {
                sline = cob_get_int (scroll);
                if (attr & COB_SCREEN_SCROLL_DOWN) {
                        sline = -sline;
                }
                scrollok (stdscr, 1);
                scrl (sline);
                scrollok (stdscr, 0);
                refresh ();
        }
        get_line_column (line, column, &sline, &scolumn);
        move (sline, scolumn);
        cob_screen_attr (fgc, bgc, attr);
        addnstr ((char *)f->data, (int)f->size);
        refresh ();
}

Here is the call graph for this function:

void cob_screen_accept ( cob_screen s,
cob_field line,
cob_field column 
)

Definition at line 759 of file screenio.c.

{
        struct cob_inp_struct   *sptr;
        struct cob_inp_struct   *sptr2;
        size_t                  idx;
        size_t                  n;
        size_t                  posu;
        size_t                  posd;
        size_t                  prevy;
        size_t                  firsty;
        int                     starty;

        if (!cob_screen_initialized) {
                cob_screen_init ();
        }
        if (!cob_base_inp) {
                cob_base_inp = cob_malloc (COB_INP_SIZE);
        } else {
                memset (cob_base_inp, 0, COB_INP_SIZE);
        }
        cob_exception_code = 0;
        cob_current_y = 0;
        cob_current_x = 0;
        totl_index = 0;
        move (0, 0);
        cob_prep_input (s);
        /* No input fields is an error */
        if (!totl_index) {
                cob_check_pos_status (8000);
                return;
        }
        qsort (cob_base_inp, totl_index, sizeof(struct cob_inp_struct), compare_yx);
        sptr = cob_base_inp;
        starty = sptr->this_y;
        posu = 0;
        posd = 0;
        prevy = 0;
        firsty = 0;
        /* Set up array for Cursor UP/DOWN */
        for (n = 0; n < totl_index; n++) {
                sptr = cob_base_inp + n;
                if (sptr->this_y > starty) {
                        if (!firsty) {
                                firsty = n;
                        }
                        starty = sptr->this_y;
                        sptr2 = cob_base_inp + posd;
                        for (idx = posd; idx < n; idx++, sptr2++) {
                                sptr2->down_index = n;
                        }
                        posu = prevy;
                        prevy = n;
                        posd = n;
                }
                sptr->up_index = posu;
        }
        sptr = cob_base_inp;
        for (n = 0; n < firsty; n++, sptr++) {
                sptr->up_index = posd;
        }
        curr_index = 0;
        global_return = 0;
        cob_screen_get_all ();
        cob_check_pos_status (global_return);
}

Here is the call graph for this function:

void cob_screen_display ( cob_screen s,
cob_field line,
cob_field column 
)

Definition at line 726 of file screenio.c.

{
        int     n;

        if (!cob_screen_initialized) {
                cob_screen_init ();
        }

        switch (s->type) {
        case COB_SCREEN_TYPE_GROUP:
                for (s = s->child; s; s = s->next) {
                        cob_screen_display (s, line, column);
                }
                break;
        case COB_SCREEN_TYPE_FIELD:
                cob_screen_puts (s, s->field);
                break;
        case COB_SCREEN_TYPE_VALUE:
                cob_screen_puts (s, s->value);
                if (s->occurs) {
                        for (n = 1; n < s->occurs; ++n) {
                                cob_screen_puts (s, s->value);
                        }
                }
                break;
        case COB_SCREEN_TYPE_ATTRIBUTE:
                cob_screen_attr (s->foreg, s->backg, s->attr);
                break;
        }
        refresh ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_screen_line_col ( cob_field f,
const int  l_or_c 
)

Definition at line 1045 of file screenio.c.

{
        if (!cob_screen_initialized) {
                cob_screen_init ();
        }
        if (!l_or_c) {
                cob_set_int (f, (int)LINES);
        } else {
                cob_set_int (f, (int)COLS);
        }
}

Here is the call graph for this function:

void cob_screen_set_mode ( const size_t  smode)

Definition at line 1058 of file screenio.c.

{
        if (!smode) {
                refresh ();
                def_prog_mode ();
                endwin ();
        } else {
                reset_prog_mode ();
                refresh ();
        }
}
void cob_screen_terminate ( void  )

Definition at line 297 of file screenio.c.

{
        if (cob_screen_initialized) {
                cob_screen_initialized = 0;
                endwin ();
        }
}

Variable Documentation

Definition at line 51 of file screenio.c.

int cob_screen_mode = 0

Definition at line 52 of file screenio.c.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines