Main Page   Data Structures   File List   Globals  

convert_from_string.c File Reference

Comverts strings into their original composite datatypes. More...

#include "white_interface.h"

Go to the source code of this file.

Defines

#define TRUE   1
#define FALSE   0

Functions

char * strchr (const char *s, int c)
 C standard library function. More...

int sscanf (const char *s, const char *format,...)
 C standard library function. More...

int is_move (char *str)
 Tests whether a string represents a move message. More...

int is_button (char *str)
 Tests whether a string represents a button message. More...

void poin_entry_Init ()
 VCC Init function. More...

void poin_entry_Run ()
 VCC Run function. More...


Detailed Description

Comverts strings into their original composite datatypes.

This block receives strings that were created by convert_to_string.c and converts them back to their original move or button datatypes. The text string is made up from the fields of the original datatype, separated by commas. The first part of the string identifies the datatype that it is representing.

Definition in file convert_from_string.c.


Define Documentation

#define FALSE   0
 

Definition at line 31 of file convert_from_string.c.

Referenced by is_button, and is_move.

#define TRUE   1
 

Definition at line 30 of file convert_from_string.c.

Referenced by is_button, and is_move.


Function Documentation

int is_button char *    str
 

Tests whether a string represents a button message.

Parameters:
str  A pointer the string.
Returns:
true if the string represents a button messge, false otherwise.

Definition at line 53 of file convert_from_string.c.

References FALSE, and TRUE.

Referenced by poin_entry_Run.

00054 {
00055   if (*str == 'b')
00056     return TRUE;
00057   else
00058     return FALSE;
00059 }

int is_move char *    str
 

Tests whether a string represents a move message.

Parameters:
str  A pointer the string.
Returns:
true if the string represents a move messge, false otherwise.

Definition at line 39 of file convert_from_string.c.

References FALSE, and TRUE.

Referenced by poin_entry_Run.

00040 {
00041   if (*str == 'm')
00042     return TRUE;
00043   else
00044     return FALSE;
00045 }

void poin_entry_Init  
 

VCC Init function.

This function runs when the VCC simulation is first started.

Definition at line 66 of file convert_from_string.c.

00067 {
00068 }

void poin_entry_Run  
 

VCC Run function.

This runs whenever a message arrives at the convert_from_string block's in port.

Definition at line 75 of file convert_from_string.c.

References is_button, is_move, sscanf, and strchr.

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 } 

int sscanf const char *    s,
const char *    format,
...   
 

C standard library function.

Parses a string according to the supplied control string.

Parameters:
s  A pointer to the string to be parsed.
format  A pointer to the control string.
Returns:
An integer error code.

Referenced by poin_entry_Run.

char* strchr const char *    s,
int    c
 

C standard library function.

Finds the location of a particular charactcter within the supplied string.

Parameters:
s  A pointer to the string to search through.
c  The character to search for.
Returns:
A pointer to the first matching character that was found.

Referenced by poin_entry_Run.


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