(no message)
[unix-history] / usr / src / games / cribbage / io.c
index 38cae27..b806852 100644 (file)
@@ -1,11 +1,17 @@
+static char    *sccsid = "@(#)io.c     1.11 (Berkeley) %G%";
+
 # include      <curses.h>
 # include      <ctype.h>
 # include      <unctrl.h>
 # include      "deck.h"
 # include      "cribbage.h"
 # include      <curses.h>
 # include      <ctype.h>
 # include      <unctrl.h>
 # include      "deck.h"
 # include      "cribbage.h"
+# include      "cribcur.h"
 
 # define       LINESIZE                128
 
 
 # define       LINESIZE                128
 
+# ifdef CTRL
+# undef CTRL
+# endif
 # define       CTRL(X)                 ('X' - 'A' + 1)
 
 # ifndef       attron
 # define       CTRL(X)                 ('X' - 'A' + 1)
 
 # ifndef       attron
@@ -74,12 +80,13 @@ BOOLEAN             brfrank,  brfsuit;
  * printcard:
  *     Print out a card.
  */
  * printcard:
  *     Print out a card.
  */
-printcard(win, cardno, c)
+printcard(win, cardno, c, blank)
 WINDOW         *win;
 int            cardno;
 CARD           c;
 WINDOW         *win;
 int            cardno;
 CARD           c;
+BOOLEAN                blank;
 {
 {
-       prcard(win, cardno * 2, cardno, c, FALSE);
+       prcard(win, cardno * 2, cardno, c, blank);
 }
 
 /*
 }
 
 /*
@@ -111,16 +118,17 @@ BOOLEAN           blank;
  * prhand:
  *     Print a hand of n cards
  */
  * prhand:
  *     Print a hand of n cards
  */
-prhand(h, n, win)
+prhand(h, n, win, blank)
 CARD           h[];
 int            n;
 WINDOW         *win;
 CARD           h[];
 int            n;
 WINDOW         *win;
+BOOLEAN                blank;
 {
        register int    i;
 
        werase(win);
        for (i = 0; i < n; i++)
 {
        register int    i;
 
        werase(win);
        for (i = 0; i < n; i++)
-           printcard(win, i, h[i]);
+           printcard(win, i, *h++, blank);
        wrefresh(win);
 }
 
        wrefresh(win);
 }
 
@@ -144,6 +152,7 @@ char                *prompt;
            exit(74);
        }
        for (;;) {
            exit(74);
        }
        for (;;) {
+           msg(prompt);
            if (incard(&crd)) {                 /* if card is full card */
                if (!isone(crd, hand, n))
                    msg("That's not in your hand");
            if (incard(&crd)) {                 /* if card is full card */
                if (!isone(crd, hand, n))
                    msg("That's not in your hand");
@@ -178,7 +187,6 @@ char                *prompt;
                }
                else
                    msg("Sorry, I missed that");
                }
                else
                    msg("Sorry, I missed that");
-           msg(prompt);
        }
        /* NOTREACHED */
 }
        }
        /* NOTREACHED */
 }
@@ -273,7 +281,7 @@ getuchar()
        c = readchar();
        if (islower(c))
            c = toupper(c);
        c = readchar();
        if (islower(c))
            c = toupper(c);
-       addch(c);
+       waddch(Msgwin, c);
        return c;
 }
 
        return c;
 }
 
@@ -323,7 +331,7 @@ char                *prompt;
  * msg:
  *     Display a message at the top of the screen.
  */
  * msg:
  *     Display a message at the top of the screen.
  */
-char           Msgbuf[BUFSIZ] = "";
+char           Msgbuf[BUFSIZ] = { '\0' };
 
 int            Mpos = 0;
 
 
 int            Mpos = 0;
 
@@ -334,19 +342,6 @@ msg(fmt, args)
 char   *fmt;
 int    args;
 {
 char   *fmt;
 int    args;
 {
-    /*
-     * if the string is "", just clear the line
-     */
-    if (*fmt == '\0') {
-       move(LINES - 1, 0);
-       clrtoeol();
-       Mpos = 0;
-       Hasread = TRUE;
-       return;
-    }
-    /*
-     * otherwise add to the message and flush it out
-     */
     doadd(fmt, &args);
     endmsg();
 }
     doadd(fmt, &args);
     endmsg();
 }
@@ -365,29 +360,55 @@ int       args;
 
 /*
  * endmsg:
 
 /*
  * endmsg:
- *     Display a new msg (giving him a chance to see the previous one
- *     if it is up there with the --More--)
+ *     Display a new msg.
  */
  */
+
+int    Lineno = 0;
+
 endmsg()
 {
 endmsg()
 {
-    if (!Hasread) {
-       move(LINES - 1, Mpos);
-       addstr("--More--");
-       refresh();
-       wait_for(' ');
-    }
+    register int       len;
+    register char      *mp, *omp;
+    static int         lastline = 0;
+
     /*
     /*
-     * All messages should start with uppercase, except ones that
-     * start with a pack addressing character
+     * All messages should start with uppercase
      */
      */
+    mvaddch(lastline + Y_MSG_START, SCORE_X, ' ');
     if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
        Msgbuf[0] = toupper(Msgbuf[0]);
     if (islower(Msgbuf[0]) && Msgbuf[1] != ')')
        Msgbuf[0] = toupper(Msgbuf[0]);
-    mvaddstr(LINES - 1, 0, Msgbuf);
-    clrtoeol();
-    Mpos = Newpos;
+    mp = Msgbuf;
+    len = strlen(mp);
+    if (len / MSG_X + Lineno >= MSG_Y) {
+       while (Lineno < MSG_Y) {
+           wmove(Msgwin, Lineno++, 0);
+           wclrtoeol(Msgwin);
+       }
+       Lineno = 0;
+    }
+    mvaddch(Lineno + Y_MSG_START, SCORE_X, '*');
+    lastline = Lineno;
+    do {
+       mvwaddstr(Msgwin, Lineno, 0, mp);
+       if ((len = strlen(mp)) > MSG_X) {
+           omp = mp;
+           for (mp = &mp[MSG_X-1]; *mp != ' '; mp--)
+               continue;
+           while (*mp == ' ')
+               mp--;
+           mp++;
+           wmove(Msgwin, Lineno, mp - omp);
+           wclrtoeol(Msgwin);
+       }
+       if (++Lineno >= MSG_Y)
+           Lineno = 0;
+    } while (len > MSG_X);
+    wclrtoeol(Msgwin);
+    Mpos = len;
     Newpos = 0;
     Newpos = 0;
+    wrefresh(Msgwin);
     refresh();
     refresh();
-    Hasread = FALSE;
+    wrefresh(Msgwin);
 }
 
 /*
 }
 
 /*
@@ -411,6 +432,28 @@ int        *args;
     Newpos = strlen(Msgbuf);
 }
 
     Newpos = strlen(Msgbuf);
 }
 
+/*
+ * do_wait:
+ *     Wait for the user to type ' ' before doing anything else
+ */
+do_wait()
+{
+    register int line;
+    static char prompt[] = { '-', '-', 'M', 'o', 'r', 'e', '-', '-', '\0' };
+
+    if (Mpos + sizeof prompt < MSG_X)
+       wmove(Msgwin, Lineno > 0 ? Lineno - 1 : MSG_Y - 1, Mpos);
+    else {
+       mvwaddch(Msgwin, Lineno, 0, ' ');
+       wclrtoeol(Msgwin);
+       if (++Lineno >= MSG_Y)
+           Lineno = 0;
+    }
+    waddstr(Msgwin, prompt);
+    wrefresh(Msgwin);
+    wait_for(' ');
+}
+
 /*
  * wait_for
  *     Sit around until the guy types the right key
 /*
  * wait_for
  *     Sit around until the guy types the right key
@@ -446,7 +489,6 @@ over:
        wrefresh(curscr);
        goto over;
     }
        wrefresh(curscr);
        goto over;
     }
-    Hasread = TRUE;
     if (c == '\r')
        return '\n';
     else
     if (c == '\r')
        return '\n';
     else
@@ -463,7 +505,10 @@ getline()
 {
     register char      *sp;
     register int       c, oy, ox;
 {
     register char      *sp;
     register int       c, oy, ox;
+    register WINDOW    *oscr;
 
 
+    oscr = stdscr;
+    stdscr = Msgwin;
     getyx(stdscr, oy, ox);
     refresh();
     /*
     getyx(stdscr, oy, ox);
     refresh();
     /*
@@ -496,10 +541,10 @@ getline()
                c = toupper(c);
            *sp++ = c;
            addstr(unctrl(c));
                c = toupper(c);
            *sp++ = c;
            addstr(unctrl(c));
-/*###366 [cc] Mpos undefined %%%*/
            Mpos++;
        }
     }
     *sp = '\0';
            Mpos++;
        }
     }
     *sp = '\0';
+    stdscr = oscr;
     return linebuf;
 }
     return linebuf;
 }