use computed values in src/gtx/curseswindows.c
[openafs.git] / src / gtx / curseswindows.c
index a1d351b..e1796d5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
  *     Implementation of the gator curses window facility.
  *
  *------------------------------------------------------------------------*/
-#define        IGNORE_STDS_H
+
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
 
 
 #if defined(AFS_HPUX110_ENV) && !defined(__HP_CURSES)
@@ -31,22 +29,17 @@ RCSID
 #endif
 #include <sys/types.h>
 #include <sys/file.h>
-#if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV)
+#if !defined(AFS_SUN5_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD80_ENV)
 #include <sgtty.h>
 #endif
 #include <stdio.h>
 #include <sys/time.h>
 #include <errno.h>
-
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 #include <stdlib.h>
 
+#include <lwp.h>
+
 #include "gtxcurseswin.h"      /*Interface definition */
 #include "gtxobjects.h"
 #include "gtxframe.h"
@@ -108,9 +101,7 @@ struct gwinbaseops gator_curses_gwinbops = {
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_init(adebug)
-     int adebug;
-
+gator_cursesgwin_init(int adebug)
 {                              /*gator_cursesgwin_init */
 
     static char rn[] = "gator_cursesgwin_init";        /*Routine name */
@@ -130,13 +121,13 @@ gator_cursesgwin_init(adebug)
      */
     if (curses_debug)
        fprintf(stderr,
-               "[%s:%s] Allocating %d bytes for curses window private space in base window\n",
+               "[%s:%s] Allocating %" AFS_SIZET_FMT " bytes for curses window private space in base window\n",
                mn, rn, sizeof(struct gator_cursesgwin));
     c_data =
        (struct gator_cursesgwin *)malloc(sizeof(struct gator_cursesgwin));
     if (c_data == (struct gator_cursesgwin *)0) {
        fprintf(stderr,
-               "[%s:%s] Can't allocate %d bytes for curses window private space in base window\n",
+               "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for curses window private space in base window\n",
                mn, rn, sizeof(struct gator_cursesgwin));
        return (-1);
     }
@@ -204,24 +195,22 @@ gator_cursesgwin_init(adebug)
  *------------------------------------------------------------------------*/
 
 struct gwin *
-gator_cursesgwin_create(params)
-     struct gator_cursesgwin_params *params;
-
-{                              /*gator_cursesgwin_create */
-
+gator_cursesgwin_create(void * rock)
+{
     static char rn[] = "gator_cursesgwin_create";      /*Routine name */
+    struct gator_cursesgwin_params *params = (struct gator_cursesgwin_params *)rock;
     struct gwin *newgwin;      /*Ptr to new curses window */
     struct gator_cursesgwin *c_data;   /*Ptr to curses-specific data */
     WINDOW *newcursgwin;       /*Ptr to new curses window */
 
     if (curses_debug)
        fprintf(stderr,
-               "[%s:%s] Allocating %d bytes for new gwin structure\n", mn,
+               "[%s:%s] Allocating %" AFS_SIZET_FMT " bytes for new gwin structure\n", mn,
                rn, sizeof(struct gwin));
     newgwin = (struct gwin *)malloc(sizeof(struct gwin));
     if (newgwin == NULL) {
        fprintf(stderr,
-               "[%s:%s] Can't malloc() %d bytes for new gwin structure: Errno is %d\n",
+               "[%s:%s] Can't malloc() %" AFS_SIZET_FMT " bytes for new gwin structure: Errno is %d\n",
                mn, rn, sizeof(struct gwin), errno);
        return (NULL);
     }
@@ -237,13 +226,13 @@ gator_cursesgwin_create(params)
 
     if (curses_debug)
        fprintf(stderr,
-               "[%s:%s] Allocating %d bytes for curses window private space\n",
+               "[%s:%s] Allocating %" AFS_SIZET_FMT " bytes for curses window private space\n",
                mn, rn, sizeof(struct gator_cursesgwin));
     c_data =
        (struct gator_cursesgwin *)malloc(sizeof(struct gator_cursesgwin));
     if (c_data == (struct gator_cursesgwin *)0) {
        fprintf(stderr,
-               "[%s:%s] Can't allocate %d bytes for curses window private space\n",
+               "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for curses window private space\n",
                mn, rn, sizeof(struct gator_cursesgwin));
        free(newgwin);
        return (NULL);
@@ -306,9 +295,7 @@ gator_cursesgwin_create(params)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_cleanup(gwp)
-     struct gwin *gwp;
-
+gator_cursesgwin_cleanup(struct gwin *gwp)
 {                              /*gator_cursesgwin_cleanup */
 
     static char rn[] = "gator_cursesgwin_cleanup";     /*Routine name */
@@ -321,7 +308,7 @@ gator_cursesgwin_cleanup(gwp)
      * want to clear the screen before we go.
      */
     if (curses_debug)
-       fprintf(stderr, "[%s:%s] Calling wclear() on window at 0x%x\n", mn,
+       fprintf(stderr, "[%s:%s] Calling wclear() on window at %p\n", mn,
                rn, cwp->wp);
     wclear(cwp->wp);
     wrefresh(cwp->wp);
@@ -361,9 +348,7 @@ gator_cursesgwin_cleanup(gwp)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_box(gwp)
-     struct gwin *gwp;
-
+gator_cursesgwin_box(struct gwin *gwp)
 {                              /*gator_cursesgwin_box */
 
     static char rn[] = "gator_cursesgwin_box"; /*Routine name */
@@ -371,7 +356,7 @@ gator_cursesgwin_box(gwp)
 
     cwp = (struct gator_cursesgwin *)(gwp->w_data);
     if (curses_debug)
-       fprintf(stderr, "[%s:%s] Calling box() on window at 0x%x\n", mn, rn,
+       fprintf(stderr, "[%s:%s] Calling box() on window at %p\n", mn, rn,
                cwp->wp);
     box(cwp->wp, cwp->box_vertchar, cwp->box_horizchar);
 
@@ -400,9 +385,7 @@ gator_cursesgwin_box(gwp)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_clear(gwp)
-     struct gwin *gwp;
-
+gator_cursesgwin_clear(struct gwin *gwp)
 {                              /*gator_cursesgwin_clear */
 
     static char rn[] = "gator_cursesgwin_clear";       /*Routine name */
@@ -413,7 +396,7 @@ gator_cursesgwin_clear(gwp)
      */
     cwp = (struct gator_cursesgwin *)(gwp->w_data);
     if (curses_debug)
-       fprintf(stderr, "[%s:%s] Calling wclear() on window at 0x%x\n", mn,
+       fprintf(stderr, "[%s:%s] Calling wclear() on window at %p\n", mn,
                rn, cwp->wp);
     wclear(cwp->wp);
 
@@ -442,9 +425,7 @@ gator_cursesgwin_clear(gwp)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_destroy(gwp)
-     struct gwin *gwp;
-
+gator_cursesgwin_destroy(struct gwin *gwp)
 {                              /*gator_cursesgwin_destroy */
 
     static char rn[] = "gator_cursesgwin_destroy";     /*Routine name */
@@ -452,7 +433,7 @@ gator_cursesgwin_destroy(gwp)
 
     cwp = (struct gator_cursesgwin *)(gwp->w_data);
     if (curses_debug)
-       fprintf(stderr, "[%s:%s] Calling delwin() on window at 0x%x\n", mn,
+       fprintf(stderr, "[%s:%s] Calling delwin() on window at %p\n", mn,
                rn, cwp->wp);
     delwin(cwp->wp);
 
@@ -481,9 +462,7 @@ gator_cursesgwin_destroy(gwp)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_display(gwp)
-     struct gwin *gwp;
-
+gator_cursesgwin_display(struct gwin *gwp)
 {                              /*gator_cursesgwin_display */
 
     struct gator_cursesgwin *cwp;      /*Curses private area ptr */
@@ -521,10 +500,7 @@ gator_cursesgwin_display(gwp)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_drawline(gwp, params)
-     struct gwin *gwp;
-     struct gwin_lineparams *params;
-
+gator_cursesgwin_drawline(struct gwin *gwp, struct gwin_lineparams *params)
 {                              /*gator_cursesgwin_drawline */
 
     static char rn[] = "gator_cursesgwin_drawline";    /*Routine name */
@@ -560,10 +536,7 @@ gator_cursesgwin_drawline(gwp, params)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_drawrectangle(gwp, params)
-     struct gwin *gwp;
-     struct gwin_rectparams *params;
-
+gator_cursesgwin_drawrectangle(struct gwin *gwp, struct gwin_rectparams *params)
 {                              /*gator_cursesgwin_drawrectangle */
 
     static char rn[] = "gator_cursesgwin_drawrectangle";       /*Routine name */
@@ -599,30 +572,32 @@ gator_cursesgwin_drawrectangle(gwp, params)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_drawchar(gwp, params)
-     struct gwin *gwp;
-     struct gwin_charparams *params;
-
+gator_cursesgwin_drawchar(struct gwin *gwp, struct gwin_charparams *params)
 {                              /*gator_cursesgwin_drawchar */
 
     static char rn[] = "gator_cursesgwin_drawchar";    /*Routine name */
     struct gator_cursesgwin *cwp;      /*Ptr to curses private area */
     int curses_x, curses_y;    /*Mapped x,y positions */
+    int code=0;
 
     cwp = (struct gator_cursesgwin *)(gwp->w_data);
     curses_x = GATOR_MAP_X_TO_COL(cwp, params->x);
     curses_y = GATOR_MAP_Y_TO_LINE(cwp, params->y);
     if (curses_debug)
        fprintf(stderr,
-               "[%s:%s] Drawing char '%c' on window at 0x%x at (%d, %d) [line %d, column %d]%s\n",
+               "[%s:%s] Drawing char '%c' on window at %p at (%d, %d) [line %d, column %d]%s\n",
                mn, rn, params->c, cwp->wp, params->x, params->y, curses_y,
                curses_x, (params->highlight ? ", using standout mode" : ""));
     wmove(cwp->wp, curses_y, curses_x);
     if (params->highlight)
-       wstandout(cwp->wp);
+       code=wstandout(cwp->wp);
+        if (code)
+           return (code);
     waddch(cwp->wp, params->c);
     if (params->highlight)
-       wstandend(cwp->wp);
+       code=wstandend(cwp->wp);
+        if (code)
+            return (code);
 
     return (0);
 
@@ -651,32 +626,34 @@ gator_cursesgwin_drawchar(gwp, params)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_drawstring(gwp, params)
-     struct gwin *gwp;
-     struct gwin_strparams *params;
-
+gator_cursesgwin_drawstring(struct gwin *gwp, struct gwin_strparams *params)
 {                              /*gator_cursesgwin_drawstring */
 
     static char rn[] = "gator_cursesgwin_drawstring";  /*Routine name */
     struct gator_cursesgwin *cwp;      /*Ptr to curses private area */
     int curses_x, curses_y;    /*Mapped x,y positions */
+    int code=0;
 
     cwp = (struct gator_cursesgwin *)(gwp->w_data);
     curses_x = GATOR_MAP_X_TO_COL(cwp, params->x);
     curses_y = GATOR_MAP_Y_TO_LINE(cwp, params->y);
     if (curses_debug)
        fprintf(stderr,
-               "[%s:%s] Drawing string '%s' on window at 0x%x at (%d, %d) [line %d, column %d]%s\n",
+               "[%s:%s] Drawing string '%s' on window at %p at (%d, %d) [line %d, column %d]%s\n",
                mn, rn, params->s, cwp->wp, params->x, params->y, curses_y,
                curses_x, (params->highlight ? ", using standout mode" : ""));
     wmove(cwp->wp, curses_y, curses_x);
     if (params->highlight)
-       wstandout(cwp->wp);
+       code=wstandout(cwp->wp);
+       if (code)
+           return (code);
     waddstr(cwp->wp, params->s);
     if (params->highlight)
-       wstandend(cwp->wp);
+       code=wstandend(cwp->wp);
+       if (code)
+           return (code);
 
-    return (0);
+    return (code);
 
 }                              /*gator_cursesgwin_drawstring */
 
@@ -703,10 +680,7 @@ gator_cursesgwin_drawstring(gwp, params)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_invert(gwp, params)
-     struct gwin *gwp;
-     struct gwin_invparams *params;
-
+gator_cursesgwin_invert(struct gwin *gwp, struct gwin_invparams *params)
 {                              /*gator_cursesgwin_invert */
 
     static char rn[] = "gator_cursesgwin_invert";      /*Routine name */
@@ -740,9 +714,7 @@ gator_cursesgwin_invert(gwp, params)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_getchar(gwp)
-     struct gwin *gwp;
-
+gator_cursesgwin_getchar(struct gwin *gwp)
 {                              /*gator_cursesgwin_getchar */
 
     return (getc(stdin));
@@ -770,9 +742,7 @@ gator_cursesgwin_getchar(gwp)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_wait(gwp)
-     struct gwin *gwp;
-
+gator_cursesgwin_wait(struct gwin *gwp)
 {                              /*gator_cursesgwin_wait */
 
     while (!LWP_WaitForKeystroke(-1));
@@ -803,19 +773,13 @@ gator_cursesgwin_wait(gwp)
  *------------------------------------------------------------------------*/
 
 int
-gator_cursesgwin_getdimensions(gwp, aparms)
-     struct gwin_sizeparams *aparms;
-     struct gwin *gwp;
-
+gator_cursesgwin_getdimensions(struct gwin *gwp, struct gwin_sizeparams *aparms)
 {                              /*gator_cursesgwin_getdimensions */
 
     struct gator_cursesgwin *cwp;      /*Curses-specific data */
 
     cwp = (struct gator_cursesgwin *)(gwp->w_data);
-#if defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN60_ENV)
-    aparms->maxx = cwp->wp->maxx;
-    aparms->maxy = cwp->wp->maxy;
-#elif defined(AFS_NBSD_ENV)
+#if defined(AFS_NBSD_ENV) || defined(AFS_DARWIN100_ENV)
     aparms->maxx = getmaxx(cwp->wp);
     aparms->maxy = getmaxy(cwp->wp);
 #else