[Commit] librr/src rr_client.c,NONE,1.1 rr_strbuf.c,NONE,1.1 rr_string.c,NONE,1.1 Makefile.am,1.1,1.2 rr.c,1.2,1.3 rr.h,1.3,1.4 rr_board.c,1.4,1.5 rrint.h,1.2,1.3

Carl Worth commit at keithp.com
Thu Jun 5 08:32:44 PDT 2003


Committed by: cworth

Update of /local/src/CVS/librr/src
In directory home.keithp.com:/tmp/cvs-serv29531/src

Modified Files:
	Makefile.am rr.c rr.h rr_board.c rrint.h 
Added Files:
	rr_client.c rr_strbuf.c rr_string.c 
Log Message:
Added preliminary client functionality.

--- NEW FILE: rr_client.c ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: rr_strbuf.c ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: rr_string.c ---
(This appears to be a binary file; contents omitted.)

Index: Makefile.am
===================================================================
RCS file: /local/src/CVS/librr/src/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am	1 Jun 2003 04:27:55 -0000	1.1
+++ Makefile.am	5 Jun 2003 14:32:42 -0000	1.2
@@ -7,7 +7,10 @@
 	rrint.h \
 	rr_board.c \
 	rr_cell.c \
-	rr_history.c
+	rr_client.c \
+	rr_history.c \
+	rr_string.c \
+	rr_strbuf.c
 
 librr_la_LDFLAGS = -version-info @VERSION_INFO@
 

Index: rr.c
===================================================================
RCS file: /local/src/CVS/librr/src/rr.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rr.c	2 Jun 2003 14:16:52 -0000	1.2
+++ rr.c	5 Jun 2003 14:32:42 -0000	1.3
@@ -68,6 +68,18 @@
 	return "move history is empty";
     case RR_STATUS_PARSE_ERROR:
 	return "parse error";
+    case RR_STATUS_IO_ERROR:
+	return "IO error";
+    case RR_STATUS_CONNECT_ERROR:
+	return "cannot connect socket";
+    case RR_STATUS_NOT_CONNECTED:
+	return "not connected";
+    case RR_STATUS_PROTOCOL_ERROR:
+	return "unexpected protocol error";
+    case RR_STATUS_EOF:
+	return "end of file";
+    case RR_STATUS_INVALID_NAME:
+	return "not a unique username";
     default:
 	return "unidentified error";
     }

Index: rr.h
===================================================================
RCS file: /local/src/CVS/librr/src/rr.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- rr.h	2 Jun 2003 14:46:15 -0000	1.3
+++ rr.h	5 Jun 2003 14:32:42 -0000	1.4
@@ -28,16 +28,42 @@
 #define LIBRR_H
 
 typedef struct rr_board rr_board_t;
+typedef struct rr_client rr_client_t;
 
 typedef enum {
     RR_STATUS_SUCCESS = 0,
     RR_STATUS_NO_MEMORY,
     RR_STATUS_ROBOT_NOT_FOUND,
-    RR_STATUS_NOT_DIRECTION,
-    RR_STATUS_BLOCKED,
     RR_STATUS_OCCUPIED,
     RR_STATUS_HISTORY_EMPTY,
-    RR_STATUS_PARSE_ERROR
+    RR_STATUS_PARSE_ERROR,
+    RR_STATUS_IO_ERROR,
+    RR_STATUS_CONNECT_ERROR,
+    RR_STATUS_NOT_CONNECTED,
+    RR_STATUS_PROTOCOL_ERROR,
+    RR_STATUS_EOF,
+    /* Errors from server */
+    RR_STATUS_NO_NAME_SET,
+    RR_STATUS_INVALID_NAME,
+    RR_STATUS_INVALID_COMMAND,
+    RR_STATUS_SYNTAX_ERROR,
+    RR_STATUS_NOT_NUMBER,
+    RR_STATUS_NOT_COLOR,
+    RR_STATUS_NOT_SHAPE,
+    RR_STATUS_NOT_DIRECTION,
+    RR_STATUS_NO_GAME,
+    RR_STATUS_NOT_EMPTY,
+    RR_STATUS_NO_USER,
+    RR_STATUS_NOT_IN_GAME,
+    RR_STATUS_NOT_PLAYING,
+    RR_STATUS_NOT_FINISHED,
+    RR_STATUS_NOT_BIDDING,
+    RR_STATUS_NOT_LOWER,
+    RR_STATUS_NO_BID,
+    RR_STATUS_NOT_ACTIVE,
+    RR_STATUS_BLOCKED,
+    RR_STATUS_TOO_MANY_MOVES,
+    RR_STATUS_UNPARSED_ERROR
 } rr_status_t;
 
 typedef enum {
@@ -199,6 +225,37 @@
 */
 rr_status_t
 rr_board_parse (rr_board_t *board, const char *str);
+
+/* rr_client.c */
+
+rr_client_t *
+rr_client_create (const char *host,
+		  const char *port,
+		  const char *user);
+
+rr_board_t *
+rr_client_get_board (rr_client_t *client);
+
+rr_status_t
+rr_client_helo (rr_client_t *client, const char *user);
+
+rr_status_t
+rr_client_games (rr_client_t *client, char **games);
+
+rr_status_t
+rr_client_new (rr_client_t *client, const char *game);
+
+rr_status_t
+rr_client_join (rr_client_t *client, const char *game);
+
+rr_status_t
+rr_client_update_board (rr_client_t *client);
+
+rr_status_t
+rr_client_show (rr_client_t *client, char **diagram);
+
+void
+rr_client_destroy (rr_client_t *client);
 
 /* rr.c */
 

Index: rr_board.c
===================================================================
RCS file: /local/src/CVS/librr/src/rr_board.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- rr_board.c	2 Jun 2003 14:46:15 -0000	1.4
+++ rr_board.c	5 Jun 2003 14:32:42 -0000	1.5
@@ -24,20 +24,11 @@
  * Author: Carl Worth <carl at theworths.org>
  */
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <ctype.h>
-#include <string.h>
 
 #include "rrint.h"
 
 static rr_status_t
-_rr_board_init (rr_board_t *board, int width, int height);
-
-static void
-_rr_board_fini (rr_board_t *board);
-
-static rr_status_t
 _rr_board_get_robot_char (rr_board_t *board, rr_cell_t *cell, char *r);
 
 static rr_status_t
@@ -82,7 +73,7 @@
     return board;
 }
 
-static rr_status_t
+rr_status_t
 _rr_board_init (rr_board_t *board, int width, int height)
 {
     rr_status_t status;
@@ -122,7 +113,7 @@
     return RR_STATUS_SUCCESS;
 }
 
-static void
+void
 _rr_board_fini (rr_board_t *board)
 {
     int j;
@@ -413,6 +404,9 @@
     int i, j;
     char *s;
     char robot, color, shape;
+
+    if (board->str == NULL)
+	return "{EMPTY BOARD}";
 
 #define C(x) *s++ = (x)
 #define S(x) s += sprintf(s, "%s", (x))

Index: rrint.h
===================================================================
RCS file: /local/src/CVS/librr/src/rrint.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rrint.h	2 Jun 2003 14:16:52 -0000	1.2
+++ rrint.h	5 Jun 2003 14:32:42 -0000	1.3
@@ -27,7 +27,12 @@
 #ifndef RRINT_H
 #define RRINT_H
 
+#include <stdio.h>
+#include <stdlib.h>
 #include <stdint.h>
+#include <stdarg.h>
+#include <string.h>
+#include <pthread.h>
 
 #include "rr.h"
 
@@ -51,6 +56,41 @@
     char *str;
 };
 
+/* NOTE: Changes to this enum must be reflecte in RR_CLIENT_COMMAND array in rr_client.c */
+typedef enum {
+    RR_CMD_HELO,
+    RR_CMD_GAMES,
+    RR_CMD_NEW,
+    RR_CMD_JOIN,
+    RR_CMD_SHOW,
+    RR_CMD_ERROR,
+    RR_CMD_LAST
+} rr_cmd_t;
+
+typedef struct rr_command {
+    rr_cmd_t cmd;
+    char *arg;
+} rr_command_t, rr_request_t, rr_response_t;
+
+struct rr_client {
+    pthread_mutex_t mutex;
+    pthread_t response_thread;
+
+    char *response;
+    char *arg;
+    pthread_cond_t response_cond;
+
+    rr_board_t board;
+
+    int sock;
+};
+
+typedef struct rr_strbuf {
+    char *str;
+    int size;
+    int len;
+} rr_strbuf_t;
+
 /* rr.c */
 char
 _rr_robot_to_char (rr_robot_t robot);
@@ -67,6 +107,14 @@
 char
 _rr_target_shape_to_char (rr_target_shape_t shape);
 
+/* rr_board.c */
+
+rr_status_t
+_rr_board_init (rr_board_t *board, int width, int height);
+
+void
+_rr_board_fini (rr_board_t *board);
+
 /* rr_cell.c */
 void
 _rr_cell_init (rr_cell_t *cell);
@@ -132,5 +180,24 @@
 rr_status_t
 _rr_history_pop (rr_history_t *history,
 		 rr_robot_t *robot, int *x, int *y);
+
+/* rr_strbuf.c */
+
+rr_status_t
+_rr_strbuf_init (rr_strbuf_t *buf);
+
+char *
+_rr_strbuf_fini (rr_strbuf_t *buf);
+
+rr_status_t
+_rr_strbuf_append (rr_strbuf_t *buf, char c);
+
+/* rr_string.c */
+
+int
+_rr_string_sprintf_alloc (char **str, const char *fmt, ...);
+
+int
+_rr_string_sprintf_alloc_va (char **str, const char *fmt, va_list ap);
 
 #endif




More information about the Commit mailing list