]> git.cworth.org Git - ttt/commitdiff
2005-12-05 Richard D. Worth <richard@theworths.org>
authorRichard Worth <richard@theworths.org>
Mon, 5 Dec 2005 14:16:41 +0000 (14:16 +0000)
committerRichard Worth <richard@theworths.org>
Mon, 5 Dec 2005 14:16:41 +0000 (14:16 +0000)
        * src/ttt-curses-client.c: (mvprintstr), (mvwprintstr), (wprint),
        (main), (finish): Whitespace changes.

ChangeLog
src/ttt-curses-client.c

index 7cb6add5b59c2c4e7aec7658f9f77c018e1fcdf3..498579a21a3043e9d20b08c3a425e60643258b26 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-12-05  Richard D. Worth  <richard@theworths.org>
+
+       * src/ttt-curses-client.c: (mvprintstr), (mvwprintstr), (wprint),
+       (main), (finish): Whitespace changes.
+
 2005-12-04  Bryan Worth <bryan@theworths.org>
         * src/ttt-socket.c: (ttt_socket_create_client) fixed socket to be
         non-blocking. (ttt_socket_read) added return value for number
 2005-12-04  Bryan Worth <bryan@theworths.org>
         * src/ttt-socket.c: (ttt_socket_create_client) fixed socket to be
         non-blocking. (ttt_socket_read) added return value for number
index b6e5981194b90d19380432198511da990eae243a..47e8370678ea6edd66d5d9bdfd8b8ddc0925d98f 100644 (file)
@@ -1,6 +1,6 @@
-/* ttt-client.c - client handling code for tic-tac-toe game server
+/* ttt-curses-client.c - curses based tic-tac-toe game client
  *
  *
- * Copyright © 2005 Carl Worth
+ * Copyright © 2005 Bryan Worth
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,7 +19,6 @@
  * Author: Bryan Worth <bryan@theworths.org> 
  */
 
  * Author: Bryan Worth <bryan@theworths.org> 
  */
 
-
 /* TODO: see /usr/share/doc/ncurses-devel-5.3/test/view.c for example code
  *      to handle window resizing
  *      
 /* TODO: see /usr/share/doc/ncurses-devel-5.3/test/view.c for example code
  *      to handle window resizing
  *      
  *
  */     
 
  *
  */     
 
-
 #include "ttt-socket.h"
 #include <curses.h>
 #include <signal.h>
 
 #include "ttt-socket.h"
 #include <curses.h>
 #include <signal.h>
 
-static void finish(int sig);
+static void
+finish (int sig);
+
+void
+mvprintstr (int     y,
+           int     x,
+           char    *string,
+           chtype  attrs);
+
+void
+mvwprintstr (WINDOW *window,
+            int    y,
+            int    x,
+            char   *string,
+            chtype attrs);
+
+void
+wprint (WINDOW *window,
+       char   *string);
 
 
-void mvprintstr(int, int, char *, chtype);
-void mvwprintstr(WINDOW *, int, int, char *, chtype);
-void wprint(WINDOW *, char *);
+/*
+ *
+ */
 
 
-void mvprintstr(int y, int x, char *string, chtype attrs)
+void
+mvprintstr (int    y,
+           int    x,
+           char   *string,
+           chtype attrs)
 {
     int xx = 0;
     int l;
 {
     int xx = 0;
     int l;
@@ -51,47 +71,49 @@ void mvprintstr(int y, int x, char *string, chtype attrs)
        xx++;
     }
     cline[l] = '\0';
        xx++;
     }
     cline[l] = '\0';
-    mvaddchstr(y, x, cline);
+    mvaddchstr (y, x, cline);
 }
 
 }
 
-
-void mvwprintstr(WINDOW * window, int y, int x, char *string, chtype attrs)
+void mvwprintstr (WINDOW *window,
+                 int    y,
+                 int    x,
+                 char   *string,
+                 chtype attrs)
 {
     int xx = 0;
     int l;
     chtype cline[1000];
 {
     int xx = 0;
     int l;
     chtype cline[1000];
-    l = strlen(string);
+    l = strlen (string);
     while (xx < l) {
        cline[xx] = string[xx] | attrs;
        xx++;
     }
     cline[l] = '\0';
     while (xx < l) {
        cline[xx] = string[xx] | attrs;
        xx++;
     }
     cline[l] = '\0';
-    mvwaddchstr(window, y, x, cline);
+    mvwaddchstr (window, y, x, cline);
 }
 
 }
 
-
-void wprint(WINDOW * window, char *string)
+void wprint (WINDOW *window,
+            char   *string)
 {
     int xx = 0;
     int l;
     chtype outc;
 {
     int xx = 0;
     int l;
     chtype outc;
-    l = strlen(string);
+    l = strlen (string);
 
     while (xx < l) {
        outc = string[xx];
        if (string[xx] != '\r')
 
     while (xx < l) {
        outc = string[xx];
        if (string[xx] != '\r')
-           waddch(window, outc);
+           waddch (window, outc);
        xx++;
     }
 }
 
        xx++;
     }
 }
 
-
 char *message2;
 int _socket;
 size_t maxread;
 
 char *message2;
 int _socket;
 size_t maxread;
 
-
-int main(int argc, char **argv)
+int
+main (int argc, char **argv)
 {
     char *message;
     char buffer[1000];
 {
     char *message;
     char buffer[1000];
@@ -107,115 +129,114 @@ int main(int argc, char **argv)
     mainwnd = initscr();
     int dlines = LINES - 2, cols = COLS;
 
     mainwnd = initscr();
     int dlines = LINES - 2, cols = COLS;
 
-    (void) nonl();
-    noecho();
-    cbreak();
-    nodelay(mainwnd, TRUE);
-    curs_set(0);
-    refresh();
-    dispwin = newwin(dlines - 1, cols - 2, 0, 0);
-    inpwin = newwin(1, cols - 2, dlines, 0);
-    keypad(mainwnd, TRUE);     // enable keyboard mapping 
-    keypad(inpwin, TRUE);      // enable keyboard mapping 
-    nodelay(inpwin, TRUE);
-    wrefresh(mainwnd);
-    wrefresh(dispwin);
-    wrefresh(inpwin);
-    (void) scrollok(mainwnd, TRUE);
-    (void) scrollok(dispwin, TRUE);
-    (void) scrollok(inpwin, TRUE);
-    (void) idlok(mainwnd, TRUE);
-    (void) idlok(dispwin, TRUE);
-    (void) idlok(inpwin, TRUE);
-    wsetscrreg(dispwin, 0, dlines - 2);
+    (void) nonl ();
+    noecho ();
+    cbreak ();
+    nodelay (mainwnd, TRUE);
+    curs_set (0);
+    refresh ();
+    dispwin = newwin (dlines - 1, cols - 2, 0, 0);
+    inpwin = newwin (1, cols - 2, dlines, 0);
+    keypad (mainwnd, TRUE);    // enable keyboard mapping 
+    keypad (inpwin, TRUE);     // enable keyboard mapping 
+    nodelay (inpwin, TRUE);
+    wrefresh (mainwnd);
+    wrefresh (dispwin);
+    wrefresh (inpwin);
+    (void) scrollok (mainwnd, TRUE);
+    (void) scrollok (dispwin, TRUE);
+    (void) scrollok (inpwin, TRUE);
+    (void) idlok (mainwnd, TRUE);
+    (void) idlok (dispwin, TRUE);
+    (void) idlok (inpwin, TRUE);
+    wsetscrreg (dispwin, 0, dlines - 2);
     
     
-    (void) signal(SIGINT, finish);     /* arrange interrupts to terminate */
-    if (has_colors()) {
-       start_color();
-
-       init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
-       init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
-       init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
-       init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
-       init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
-       init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
-       init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
-       init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
+    (void) signal (SIGINT, finish);    /* arrange interrupts to terminate */
+    if (has_colors ()) {
+       start_color ();
+
+       init_pair (COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
+       init_pair (COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
+       init_pair (COLOR_RED, COLOR_RED, COLOR_BLACK);
+       init_pair (COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
+       init_pair (COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
+       init_pair (COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
+       init_pair (COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
+       init_pair (COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
     }
     }
-    wbkgd(dispwin, COLOR_PAIR(COLOR_WHITE));
-    wbkgd(inpwin, COLOR_PAIR(COLOR_CYAN));
-    wrefresh(dispwin);
-    wrefresh(inpwin);
+    wbkgd (dispwin, COLOR_PAIR (COLOR_WHITE));
+    wbkgd (inpwin, COLOR_PAIR (COLOR_CYAN));
+    wrefresh (dispwin);
+    wrefresh (inpwin);
 
 
-    xasprintf(&host, "localhost");
-    xasprintf(&port, "5334");
-    xasprintf(&message, "HELO bryan\r\n");
+    xasprintf (&host, "localhost");
+    xasprintf (&port, "5334");
+    xasprintf (&message, "HELO bryan\r\n");
 
 
-    ttt_socket_create_client(host, port, &_socket);
-    ttt_socket_write(_socket, message, strlen(message));
+    ttt_socket_create_client (host, port, &_socket);
+    ttt_socket_write (_socket, message, strlen (message));
 
     maxread = 100;
 
     maxread = 100;
-    numread = read(_socket, buffer, maxread);
+    numread = read (_socket, buffer, maxread);
     if (numread > 0) {
        buffer[numread] = '\0';
     if (numread > 0) {
        buffer[numread] = '\0';
-       xasprintf(&message, "%s", buffer);
-       wprint(dispwin, message);
-       wrefresh(dispwin);
+       xasprintf (&message, "%s", buffer);
+       wprint (dispwin, message);
+       wrefresh (dispwin);
     }
     }
-    xasprintf(&message2, "MESSAGE \"");
+    xasprintf (&message2, "MESSAGE \"");
     while (1) {
     while (1) {
-       curs_set(1);
-       c = wgetch(inpwin);
+       curs_set (1);
+       c = wgetch (inpwin);
        if (c != ERR) {
        if (c != ERR) {
-           xasprintf(&message2, "%s%c", message2, (int) c);
-           waddch(inpwin, c);
-           wrefresh(inpwin);
+           xasprintf (&message2, "%s%c", message2, (int) c);
+           waddch (inpwin, c);
+           wrefresh (inpwin);
        }
 
        numread = 0;
        maxread = 100;
        }
 
        numread = 0;
        maxread = 100;
-       numread = read(_socket, buffer, maxread);
+       numread = read (_socket, buffer, maxread);
        if (numread > 0) {
        if (numread > 0) {
-           curs_set(0);
+           curs_set (0);
            buffer[numread] = '\0';
            buffer[numread] = '\0';
-           wprint(dispwin, buffer);
-           wrefresh(dispwin);
-           wrefresh(inpwin);
+           wprint (dispwin, buffer);
+           wrefresh (dispwin);
+           wrefresh (inpwin);
        }
        if ((int) c == 13) {
        }
        if ((int) c == 13) {
-           curs_set(0);
-           xasprintf(&message2, "%s\"\r\n", message2);
-           ttt_socket_write(_socket, message2, strlen(message2));
-           xasprintf(&message2, "MESSAGE \"");
+           curs_set (0);
+           xasprintf (&message2, "%s\"\r\n", message2);
+           ttt_socket_write (_socket, message2, strlen (message2));
+           xasprintf (&message2, "MESSAGE \"");
            maxread = 100;
            maxread = 100;
-           numread = read(_socket, buffer, maxread);
+           numread = read (_socket, buffer, maxread);
            if (numread > 0) {
                buffer[numread] = '\0';
            if (numread > 0) {
                buffer[numread] = '\0';
-               wprint(dispwin, buffer);
+               wprint (dispwin, buffer);
            }
            }
-           wrefresh(dispwin);
-           werase(inpwin);
-           wrefresh(inpwin);
+           wrefresh (dispwin);
+           werase (inpwin);
+           wrefresh (inpwin);
        }
     }
        }
     }
-
-
-
 }
 
 }
 
-
-static void finish(int sig)
+static void
+finish (int sig)
 {
     char buffer[1024];
     ssize_t numread;
     endwin();
 
     /* do your non-curses wrapup here */
 {
     char buffer[1024];
     ssize_t numread;
     endwin();
 
     /* do your non-curses wrapup here */
-    xasprintf(&message2, "QUIT\r\n");
-    ttt_socket_write(_socket, message2, strlen(message2));
+    xasprintf (&message2, "QUIT\r\n");
+    ttt_socket_write (_socket, message2, strlen (message2));
+
     maxread = 100;
     maxread = 100;
-    numread = read(_socket, buffer, maxread);
+    numread = read (_socket, buffer, maxread);
     buffer[numread] = '\0';
     buffer[numread] = '\0';
-    xasprintf(&message2, "%s", buffer);
-    exit(0);
+    xasprintf (&message2, "%s", buffer);
+
+    exit (0);
 }
 }