delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/05/11/16:45:19

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: degoble AT gtech (David. E. Goble)
Newsgroups: comp.os.linux.development.apps,comp.os.msdos.djgpp
Subject: undeclared identifiers: one *c prog not recognising a shared *.h file
Date: Sat, 11 May 2002 20:35:15 GMT
Message-ID: <3cdd7e32.103647057@news.adelaide.on.net>
X-Newsreader: Forte Free Agent 1.21/32.243
NNTP-Posting-Host: dialup-195.99.220.203.acc02-waym-adl.comindico.com.au
X-Trace: duster.adelaide.on.net 1021149336 dialup-195.99.220.203.acc02-waym-adl.comindico.com.au (12 May 2002 06:05:36 +0950)
Lines: 635
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi;

/*
  listing 2 - menu.h
*/

/* screen dimensions*/
#define MAX_ROWS 24
#define MAX_COLUMNS 80

/* keystroke codes and color */
#ifdef HPUX
#define UP_ARROW 	3
#define DOWN_ARROW	2
#define LEFT_ARROW 	4
#define RIGHT_ARROW 	5
#define RETURN		10
#define ESCAPE		27
#endif
#ifdef SUN
#define UP_ARROW 	65
#define DOWN_ARROW	66
#define LEFT_ARROW 	68
#define RIGHT_ARROW 	67
#define RETURN		10
#define ESCAPE		27
#endif
#ifdef VMS
#define UP_ARROW 	274 
#define DOWN_ARROW	275
#define LEFT_ARROW 	276
#define RIGHT_ARROW 	277
#define RETURN		13
#define ESCAPE		291 /* F11 */
#endif
#ifdef BCC
#define MAINCOLOR 	(F_RED | B_BLACK)
#define DIALOGCOLOR	(F_CYAN | B_BLACK)
#define UP_ARROW 	56
#define DOWN_ARROW	50
#define LEFT_ARROW 	52
#define RIGHT_ARROW 	54
#define	RETURN		10
#define ESCAPE		27
#endif

/* macros for portability */
#ifndef VMS
#define BEGX _begx
#define BEGY _begy
#define MAXX _maxx
#else
#define BEGX _beg_x
#define BEGY _beg_y
#define MAXX _max_x
#endif

/* box characters */

#ifdef BCC
#define SINGLE_SIDE   -77 /* single bar */
#define SINGLE_ACROSS -60
#define DOUBLE_SIDE   -70 /* double bar */
#define DOUBLE_ACROSS -51
#else
#define SINGLE_SIDE   '|'
#define SINGLE_ACROSS '-'
#define DOUBLE_SIDE   '"'
#define DOUBLE_ACROSS '='
#endif

#define TCHOICES 3

/* menubar structure */
typedef struct mbar {
	char string[80];
	char letter;
	int pos;
}MENUBAR;

/* pulldown menu choices */
typedef struct choices {
	char string[20];
	char letter;
	int (*funcptr)();
} CHOICES;

/* pulldown menu structure */
typedef struct pmenu {
	int num;
	int maxlength;
	CHOICES *ptr;
} PULLDOWN;

/* prototypes */
WINDOW *topbar(WINDOW *);
WINDOW *pulldown(int,int,int,int);
WINDOW *popup(int,int,int,int);
void move_window(WINDOW *win,int y, int x);
void print_string(WINDOW *,int, int, char *);
void erase_window(WINDOW *);
void delete_window(WINDOW *);
void refresh_window(WINDOW *);
int to_dialogue(char *);
void clear_dialogue(void);
void touch_window(WINDOW *);
char *strmenu(int, MENUBAR *, int);
char menu_choice(char *);
int clean_up(void);
void repaint(void);
char do_pulldown(int,PULLDOWN *, MENUBAR *);
void set_stdscr(void);
void execute_command(int, int, PULLDOWN *);
char do_menubar(WINDOW *, MENUBAR *);
void strtoupper(char *);
void strtolower(char *);
void set_stdscr(void);
char get_keystroke(void);


/*
  listing3 - uilibs.c
*/

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <time.h>
#include <string.h>
#ifdef VMS
#include <smgdef.h>
#endif
#ifdef BCC
#include <dos.h>
#include <conio.h>
#include <ctype.h>
#endif

#include "curses.h"
#include "menu.h"

extern WINDOW *dialogue;
extern WINDOW *tbar;

static bar_size;   /* size of menubar */
static int menu_pos;  /* position in menubar */

/* display menubar */
WINDOW *topbar(WINDOW *win)
{

  WINDOW  *swin;

  int string_count, string_size;

  if((swin = subwin(win,3,(win->MAXX)-4,(win->BEGY)+1,
        (win->BEGX)+2)) == NULL)
    clean_up();

#ifdef BCC
  wattrset(swin, F_BLUE | B_GRAY);
#endif

  box (swin, SINGLE_SIDE,SINGLE_ACROSS);

  bar_size = (swin->MAXX)-2;
  menu_pos=0;

  return  (swin);
}

/* print string to menubar */
char do_menubar(WINDOW *swin, MENUBAR *menubar)
{

  char * menu;

  char buffer[80];

  int status; 

#ifdef VMS
  int keyboard;
  short term_code;
#else
  char term_code;
#endif

#ifdef VMS
  if ( (( status =
      SMG$CREATE_VIRTUAL_KEYBOARD(&keyboard))&1)!=1)
    clean_up();
#endif

  term_code = 0;

  while (term_code != RETURN) {

    /* get the new menubar string */
    menu = strmenu(bar_size, menubar, menu_pos);

    mvwaddstr(swin, 1, 1, menu);
    wrefresh(swin);

    /* get a single keystroke */

#ifdef VMS
    if ( (( status = SMG$READ_KEYSTROKE
         (&keyboard,&term_code))&1)!=1)
      clean_up();
#endif
#ifdef BCC
    term_code = wgetch(swin);
#endif
#ifdef HPUX
    term_code = getch();
#endif
#ifdef SUN
    term_code = getch();
    if (term_code == ESCAPE) {
      getch();
      term_code = getch();
    }
#endif

    /* process keystroke */ 
    switch (term_code) {

      /* arrows check for wrap-around */
      case LEFT_ARROW:
        if (menu_pos == 0)
          menu_pos = TCHOICES-1;
        else
          menu_pos--;
      break;

      case RIGHT_ARROW:
        if (menu_pos == TCHOICES-1)
          menu_pos = 0;
        else
          menu_pos++;
      break;

      /* do nothing */
      case RETURN:
      break;

      /* exit program */
      case ESCAPE:
        clean_up();
      break;

      /* return keyboard input */
      default :
        return (term_code);
      break;

    }

  }

  /* return highlighted option */
  return (menubar[menu_pos].letter);

}

WINDOW *popup(int rows,int columns,int sy,int sx)
{
  WINDOW *win;

  win = newwin(rows, columns, sy, sx);

  if(win == NULL) {
    endwin();
    clean_up();
  }

#ifdef BCC
  wattrset(win, F_BLACK | B_GRAY);
#endif
  box(win, SINGLE_SIDE, SINGLE_ACROSS);
  wrefresh(win);

  return (win);

}


/* erase windows and surrounding box */
void erase_window(WINDOW *win)
{


  werase(win);
  box(win, ' ', ' ');
  wrefresh(win);


}

void delete_window(WINDOW *win)
{

  delwin(win);


}

void refresh_window(WINDOW *win)
{

  wrefresh(win);


}

void touch_window(WINDOW *win)
{

  touchwin(win);
  wrefresh(win);


}

/* process pulldown menu options */
char do_pulldown
      (int i, PULLDOWN *pullmenu, MENUBAR *menubar)
{

  WINDOW *subwin1;

  int j;
  int position, oldpos;

  char *ptr;

  int status;

#ifdef VMS
  int keyboard;
  short term_code;
#else
  char term_code;
#endif

#ifdef VMS
  if ( (( status =
      SMG$CREATE_VIRTUAL_KEYBOARD(&keyboard))&1)!=1)
    clean_up();
#endif

  subwin1 = popup( (pullmenu[i].num)+2,
    (pullmenu[i].maxlength)+2,stdscr->BEGY+3,
      (menubar[i].pos)+2 );
  
  /* print pulldown options */

  for (j=0;j<pullmenu[i].num;j++) {

    ptr = pullmenu[i].ptr[j].string;

    mvwaddstr(subwin1, j+1, 1, ptr );

  }

  term_code = 0;

  position=0;
  oldpos = 0;

  while (term_code != RETURN) {

    /* highlight selected option */

    ptr = pullmenu[i].ptr[position].string;

    strtoupper(ptr);

    mvwaddstr(subwin1, position+1, 1, ptr );

    wrefresh(subwin1);

    /* get keystroke */

#ifdef VMS
    if ( (( status =SMG$READ_KEYSTROKE
        (&keyboard,&term_code)) & 1)!=1)
      clean_up();
#endif
#ifdef BCC
    term_code = wgetch(subwin1);
#endif
#ifdef HPUX
    term_code = getch();
#endif
#ifdef SUN
    term_code = getch();
    if (term_code == ESCAPE) {
      getch();
      term_code = getch();
    }
#endif


    oldpos = position;
  
    /* process keystroke */

    switch (term_code) {

      case UP_ARROW:

        if (position == 0)
          position = pullmenu[i].num-1;
        else
          position--;

      break;

      case DOWN_ARROW:

        if (position == pullmenu[i].num-1)
          position = 0;
        else
          position++;

      break;

      /* do nothing */
      case RETURN:
      break;

      /* get keyboard input and
          erase menu */
      default :
        erase_window(subwin1);
        delwin(subwin1);

        touchwin(stdscr);
        wrefresh(stdscr);
        touchwin(dialogue);
        wrefresh(dialogue);

        return (term_code);
      break;

    }

    /* restore to lowercase */

    ptr = pullmenu[i].ptr[oldpos].string;

    strtolower(ptr);
    mvwaddstr(subwin1, oldpos+1, 1, ptr );

    wrefresh(subwin1);

  }

  /* return highlighted optoin 
     and erase menu */
  delwin(subwin1);
  erase_window(subwin1);
  touchwin(stdscr);
  wrefresh(stdscr);
  touchwin(dialogue);
  wrefresh(dialogue);
  return (pullmenu[i].ptr[position].letter);


}

/* calculate and produce menubar string */
char *strmenu(int length, MENUBAR *menubar, int pos)
{

  int i,j,k;
  int count;
  int string_length;

  static char buffer[100];

  /* determine max length for string */
  string_length = length/TCHOICES;

  k = 0;
  j = 0;

  /* add proper number of options */
  for (i=0;i<TCHOICES;i++) {

    menubar[i].pos = k;

    /* add each option, highlight as necessary */
    for (j=0;menubar[i].string[j]!='\0';j++,k++) {
      if (pos == i)
        buffer[k] = toupper(menubar[i].string[j]);  
      else
        buffer[k] = tolower(menubar[i].string[j]);
    }

    /* pad with spaces to proper length */
    while (k<(string_length*(i+1)+2)) {
      buffer[k] = ' ';
      k++;
    }

  }


  return(buffer);

}

/* initialize the screen at start */
void set_stdscr(void)
{

  int i;

  wclear (stdscr);

#ifdef BCC
  wattrset(stdscr, F_RED | B_BLUE);
  /* fill in screen with color */
  for (i=0;i<MAX_ROWS;i++)
    mvinsertln(i,0);
#endif
  box(stdscr, DOUBLE_SIDE, DOUBLE_ACROSS);

  refresh();

  return;

}

/* print string to dialogue box */
int to_dialogue(char *string)
{

  clear_dialogue();
  mvwaddstr(dialogue, 1, 1, string);
  box(dialogue, SINGLE_SIDE, SINGLE_ACROSS);
  wrefresh(dialogue);

  return;

}

void clear_dialogue(void)
{

  werase(dialogue);
  box(dialogue, SINGLE_SIDE, SINGLE_ACROSS);
  wrefresh(dialogue);

  return;

}

void execute_command
        (int i, int choice, PULLDOWN *pullmenu)
{

  int j;

  touch_window(tbar);

  for (j=0;j<pullmenu[i].num;j++) {

    /* use function pointer to execute command */
    if ( choice == pullmenu[i].ptr[j].letter) {
      (*(pullmenu[i].ptr[j].funcptr))();
      break;
    };

  }

  clear_dialogue();

}

/* convert a string to all uppercase */
void strtoupper(char *string)
{

  int i;

  for (i=0;string[i]!='\0';i++) {

    string[i] = toupper(string[i]);

  }

  return;

}

/* convert a string to all lowercase */
void strtolower(char *string)
{

  int i;

  for (i=0;string[i]!='\0';i++) {

    string[i] = tolower(string[i]);

  }

  return;

}


gcc -c uilibs.c 


uilibs.c: In function `do_menubar':
uilibs.c:77: `RETURN' undeclared (first use in this function)
uilibs.c:77: (Each undeclared identifier is reported only once
uilibs.c:77: for each function it appears in.)
uilibs.c:110: `LEFT_ARROW' undeclared (first use in this function)
uilibs.c:117: `RIGHT_ARROW' undeclared (first use in this function)
uilibs.c:129: `ESCAPE' undeclared (first use in this function)
uilibs.c:111: warning: unreachable code at beginning of switch
statement
uilibs.c: In function `do_pulldown':
uilibs.c:252: `RETURN' undeclared (first use in this function)
uilibs.c:292: `UP_ARROW' undeclared (first use in this function)
uilibs.c:301: `DOWN_ARROW' undeclared (first use in this function)
uilibs.c:294: warning: unreachable code at beginning of switch
statement

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019