Main Page   Data Structures   File List   Globals  

convert_from_string.c

Go to the documentation of this file.
00001 #include "white_interface.h"
00002 
00019 char *strchr(const char *s, int c);
00020 
00028 int sscanf(const char *s, const char *format, ...);
00029 
00030 #define TRUE 1
00031 #define FALSE 0
00032 
00033 
00039 int is_move(char *str)
00040 {
00041   if (*str == 'm')
00042     return TRUE;
00043   else
00044     return FALSE;
00045 }
00046 
00053 int is_button(char *str)
00054 {
00055   if (*str == 'b')
00056     return TRUE;
00057   else
00058     return FALSE;
00059 }
00060 
00065 /* Init Function */
00066 void poin_entry_Init()
00067 {
00068 }
00069 
00074 /* Run Function */
00075 void poin_entry_Run()
00076 {
00077   char *comma;
00078   char *input;
00079   move m;
00080   button b;
00081   int player, x1, y1, x2, y2, button_no;
00082 
00083   if (in_Enabled())
00084   {
00085     input = in_Value();
00086     /* find the first comma. */
00087     comma = strchr(input, ',');
00088 
00089     /* if the string represents a move command, construct a move message and 
00090        output it. Note that the part of the string before the first comma is
00091        not looked at when parsing the string. This is because it just identifies
00092        the string as move command. */
00093 
00094     if (is_move(input))
00095     {
00096       sscanf(comma+1, "%d,%d,%d,%d,%d", &player, &x1, &y1, &x2, &y2);
00097       m.player = player;
00098       m.x1 = x1;
00099       m.y1 = y1;
00100       m.x2 = x2;
00101       m.y2 = y2;
00102       move_out_Post(&m);
00103     }
00104 
00105     /* if the string represents a button command, construct a button message
00106        and output it. */
00107 
00108     if (is_button(input))
00109     {
00110       sscanf(comma+1, "%d,%d", &player, &button_no);
00111       b.player = player;
00112       b.button_no = button_no;
00113       button_out_Post(&b);
00114     }
00115   }
00116 } 
00117 

Copyright © 2002 Andrew Bates
Last Updated 04/04/02