-
Notifications
You must be signed in to change notification settings - Fork 0
/
LOAD.C
170 lines (138 loc) · 5.67 KB
/
LOAD.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "golf.h"
/*
**************************************************************************
load.c Brett A. Morrison
Contains the routines for loading the character buffer into the course
and player arrays.
**************************************************************************
*/
/*
--------------------------------------------------------------------------
LoadCourses
Load one course at a time until end of the buffer is reached.
Inputs:
lpBuffer - the character buffer which stores all the information
*courses - the course array
Outputs:
None
--------------------------------------------------------------------------
*/
void LoadCourses(LPSTR lpBuffer, course_array *courses)
{
long pointer=3; /* pointer to position in buffer array */
(*courses).course_numb = -1; /* counts number of courses in array */
while (lpBuffer[pointer] != '\0') /* do search until the end of buffer */
{
(*courses).course_numb++; /* add one to the counter */
/* load each element of the record */
load_string(&pointer, lpBuffer, (*courses).course[(*courses).course_numb].c_name);
load_string(&pointer, lpBuffer, (*courses).course[(*courses).course_numb].c_street);
load_string(&pointer, lpBuffer, (*courses).course[(*courses).course_numb].c_city);
load_string(&pointer, lpBuffer, (*courses).course[(*courses).course_numb].c_state);
load_string(&pointer, lpBuffer, (*courses).course[(*courses).course_numb].c_zip);
load_string(&pointer, lpBuffer, (*courses).course[(*courses).course_numb].c_phone);
load_string(&pointer, lpBuffer, (*courses).course[(*courses).course_numb].c_rating);
load_holes (&pointer, lpBuffer, (*courses).course[(*courses).course_numb].hole_par);
load_holes (&pointer, lpBuffer, (*courses).course[(*courses).course_numb].hole_handicap);
} /* while */
} /* LoadCourses */
/*
--------------------------------------------------------------------------
LoadPlayers
Load one player at a time until end of the buffer is reached.
Inputs:
lpBuffer - the character buffer which stores all the information
*players - the player array
Outputs:
None
--------------------------------------------------------------------------
*/
void LoadPlayers(LPSTR lpBuffer, player_array *players)
{
long pointer=3; /* pointer to position in buffer array */
(*players).player_numb = -1;
while (lpBuffer[pointer] != '\0') /* do search until the end of buffer */
{
(*players).player_numb++;
/* get the data */
load_string(&pointer, lpBuffer, (*players).player[(*players).player_numb].p_first);
load_string(&pointer, lpBuffer, (*players).player[(*players).player_numb].p_last);
load_string(&pointer, lpBuffer, (*players).player[(*players).player_numb].p_street);
load_string(&pointer, lpBuffer, (*players).player[(*players).player_numb].p_city);
load_string(&pointer, lpBuffer, (*players).player[(*players).player_numb].p_state);
load_string(&pointer, lpBuffer, (*players).player[(*players).player_numb].p_zip);
load_string(&pointer, lpBuffer, (*players).player[(*players).player_numb].p_phone);
load_history(&pointer, lpBuffer, &(*players).player[(*players).player_numb].p_scores); /* load the list */
} /* while */
} /* LoadPlayers */
/*
--------------------------------------------------------------------------
load_string
Gets the next item from the buffer
Inputs:
*pointer - pointer to the current character in the buffer
lpbuffer - the character buffer
Outputs:
string - the string that is extracted
--------------------------------------------------------------------------
*/
void load_string(long *pointer, LPSTR lpBuffer, char string[])
{
int x; /* loop counter */
/* search for eoln, and copy values */
for (x=0; (lpBuffer[*pointer] != '\r'); x++, (*pointer)++)
string[x] = lpBuffer[*pointer];
string[x] = '\0'; /* terminate the string */
(*pointer) += 2; /* set the pointer to the start of the next string */
} /* load_string */
/*
--------------------------------------------------------------------------
load_holes
Loads the array with the appropriate numerical value for each hole.
Inputs:
*pointer - pointer to the current character in the buffer
lpbuffer - the character buffer
Outputs:
holes - the array to store the data
--------------------------------------------------------------------------
*/
void load_holes(long *pointer, LPSTR lpBuffer, score_array holes)
{
int i; /* loop counter */
char temp[SCORE_LENGTH+1];
/* get the next line it is of length 1 */
/* add 2 to pointer to account for the '\n' */
for (i=1; i<=NUM_HOLES; i++)
{
load_string(pointer, lpBuffer, temp);
holes[i] = (short)atoi(temp);
} /* for */
} /* load_holes */
/*
--------------------------------------------------------------------------
load_history
Loads the scores from a players previous golf rounds.
Inputs:
*pointer - pointer to the current character in the buffer
lpbuffer - the character buffer
p_scores - the array of rounds list for the current player
Outputs:
None
--------------------------------------------------------------------------
*/
void load_history(long *pointer, LPSTR lpBuffer, history_array *p_scores)
{
char date[DATE_LENGTH+1];
(*p_scores).round_numb = -1;
while (lpBuffer[*pointer] != END_RECORDS_MARKER)
{
(*p_scores).round_numb++;
load_string(pointer, lpBuffer, date);
(*p_scores).history[(*p_scores).round_numb].date = atol(date);
load_string(pointer, lpBuffer,
(*p_scores).history[(*p_scores).round_numb].course_name);
load_holes(pointer, lpBuffer,
(*p_scores).history[(*p_scores).round_numb].score);
} /* for */
(*pointer) += 3; /* set the pointer to the start of the next string */
} /* load_history */