OLDSPT.CPP 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "mallocx.h"
  5. #include "euro_def.h"
  6. #include "euro_var.h"
  7. #include "euro_dsk.h"
  8. char *script_buffer;
  9. FILE *script_in;
  10. char line[256];
  11. char variable;
  12. int variable_value;
  13. void Getvariable( char *buf );
  14. int GetVariableValue( char *buf );
  15. void ConvertLine(char *buf);
  16. void GetTextString( char *buf);
  17. short GetClubString( char *buf );
  18. char GetFormationType( char *buf );
  19. char GetTeamsCodeNumber( char *buf );
  20. short ImageXcount = 0;
  21. short ImageYcount = 0;
  22. short ImageWcount = 0;
  23. short ImageHcount = 0;
  24. short Pagecount = 0;
  25. short Stringcount = 0;
  26. short Clubcount = 0;
  27. int StringOffset = 0;
  28. int TempOffset = 0;
  29. short Formationcount = 0;
  30. char GroupDrawcount = 0;
  31. short inst;
  32. #define NO_INSTRUCTION 0
  33. #define IMAGE_xCOORD 1
  34. #define IMAGE_yCOORD 2
  35. #define IMAGE_WIDTH 3
  36. #define IMAGE_HEIGHT 4
  37. #define IMAGE_PAGE 5
  38. #define TEXT_STRING 10
  39. #define FORMATION_TYPE 100
  40. #define GROUP_DRAW_TYPE 101
  41. #define PLAYERS_CLUB_NAME 102
  42. #define NULL_INSTRUCTION 255
  43. //********************************************************************************************************************************
  44. char process_script_file( char *file)
  45. {
  46. script_buffer = (char *) mallocx(32768);
  47. if( script_buffer==NULL )
  48. {
  49. printf("\nERROR: Unable to malloc script buffer...");
  50. return(1);
  51. }
  52. else
  53. {
  54. if( script_in = fopen ( file, "rt" ), script_in != NULL )
  55. {
  56. while( ReadLine ( script_in, &line[0] ) >= 0 )
  57. {
  58. inst = 0;
  59. ConvertLine(&line[0]);
  60. memset( line, 0, 256 );
  61. }
  62. fclose(script_in);
  63. }
  64. freex(script_buffer);
  65. }
  66. return(0);
  67. }
  68. //********************************************************************************************************************************
  69. void ConvertLine(char *buf)
  70. {
  71. Getvariable(buf);
  72. while( variable != NO_INSTRUCTION )
  73. {
  74. if ( variable == IMAGE_xCOORD )
  75. { Image_Xcoords[ImageXcount] = GetVariableValue(buf); ImageXcount++; }
  76. if ( variable == IMAGE_yCOORD )
  77. { Image_Ycoords[ImageYcount] = GetVariableValue(buf); ImageYcount++; }
  78. if ( variable == IMAGE_WIDTH )
  79. { Image_Widths[ImageWcount] = GetVariableValue(buf); ImageWcount++; }
  80. if ( variable == IMAGE_HEIGHT )
  81. { Image_Heights[ImageHcount] = GetVariableValue(buf); ImageHcount++; }
  82. if ( variable == IMAGE_PAGE )
  83. { Image_Pages[Pagecount] = GetVariableValue(buf); Pagecount++; }
  84. if ( variable == TEXT_STRING )
  85. { Text[Stringcount] = TextStrings+StringOffset; GetTextString(buf); Stringcount++; }
  86. if ( variable == FORMATION_TYPE )
  87. { FormationInfo[Formationcount] = GetFormationType(buf); Formationcount++; }
  88. if ( variable == GROUP_DRAW_TYPE )
  89. { GroupDrawInfo[GroupDrawcount] = GetTeamsCodeNumber(buf); GroupDrawcount++; }
  90. if ( variable == PLAYERS_CLUB_NAME )
  91. {
  92. TempOffset = StringOffset;
  93. Text[Stringcount] = TextStrings+StringOffset;
  94. short Clubnum = GetClubString(buf);
  95. if ( Clubnum == NOT_FOUND )
  96. {
  97. Clubs[Clubcount] = Stringcount;
  98. Stringcount++;
  99. }
  100. else
  101. {
  102. Clubs[Clubcount] = Clubnum;
  103. StringOffset = TempOffset;
  104. }
  105. Clubcount++;
  106. }
  107. Getvariable(buf);
  108. }
  109. }
  110. //********************************************************************************************************************************
  111. int GetVariableValue( char *buf ) //, int inst )
  112. {
  113. int val, offset;
  114. char number[10];
  115. offset = 0;
  116. val = 0;
  117. while ( buf[inst] > ('0'-1) && buf[inst] < ('9'+1) )
  118. {
  119. number[offset] = buf[inst];
  120. inst++;
  121. offset++;
  122. }
  123. number[offset] = 0;
  124. val = atoi(number);
  125. return ( val );
  126. }
  127. //********************************************************************************************************************************
  128. char GetFormationType( char *buf )
  129. {
  130. int val, offset;
  131. char form = 0;
  132. char number[10];
  133. offset = 0;
  134. val = 0;
  135. if (buf[inst]==' ')
  136. inst++;
  137. while ( buf[inst] > ('0'-1) && buf[inst] < ('9'+1) )
  138. {
  139. number[offset] = buf[inst];
  140. inst++;
  141. if (buf[inst]=='-')
  142. inst++;
  143. offset++;
  144. }
  145. number[offset] = 0;
  146. val = atoi(number);
  147. switch (val)
  148. {
  149. case(316):
  150. form = 0;
  151. break;
  152. case(406):
  153. form = 1;
  154. break;
  155. case(415):
  156. form = 2;
  157. break;
  158. case(424):
  159. form = 3;
  160. break;
  161. case(433):
  162. form = 4;
  163. break;
  164. case(442):
  165. form = 5;
  166. break;
  167. case(514):
  168. form = 6;
  169. break;
  170. case(523):
  171. form = 7;
  172. break;
  173. case(532):
  174. form = 8;
  175. break;
  176. case(631):
  177. form = 9;
  178. break;
  179. }
  180. return ( form );
  181. }
  182. //********************************************************************************************************************************
  183. char GetTeamsCodeNumber( char *buf )
  184. {
  185. char val;
  186. val = 0;
  187. if (buf[inst]==' ')
  188. inst++;
  189. while ( buf[inst] > ('0'-1) && buf[inst] < ('9'+1) )
  190. {
  191. if ( buf[inst+1] < 'a' )
  192. val = ((buf[inst+1]-'A')*4);
  193. else
  194. val = ((buf[inst+1]-'a')*4);
  195. val+= (buf[inst]-'1');
  196. inst+= 2;
  197. }
  198. printf ("val = %d\n", val);
  199. return ( val );
  200. }
  201. //********************************************************************************************************************************
  202. void GetTextString( char *buf ) //, int inst )
  203. {
  204. char CRflag = 2;
  205. while ( CRflag!=0 )
  206. {
  207. if ( buf[inst] == '"' )
  208. CRflag--;
  209. if ( buf[inst] > 31 && buf[inst] != '/' && buf[inst]!='"' && CRflag==1)
  210. {
  211. TextStrings[StringOffset] = buf[inst];
  212. StringOffset++;
  213. }
  214. if ( buf[inst+1] > 31 && buf[inst] == '/' && CRflag==1)
  215. {
  216. TextStrings[StringOffset] = buf[inst+1];
  217. StringOffset++;
  218. inst++;
  219. }
  220. if ( (buf[inst] < 31 && CRflag==1) || StringOffset>16383 )
  221. CRflag = 0;
  222. inst++;
  223. }
  224. TextStrings[StringOffset] = 0;
  225. StringOffset++;
  226. }
  227. //********************************************************************************************************************************
  228. short GetClubString( char *buf )
  229. {
  230. // ****** GET PLAYERS CLUB ******
  231. char PlayerClub[25];
  232. char string[25];
  233. int ClubOffset = 0;
  234. char CRflag = 2;
  235. int CompareOffset = 0;
  236. short ClubFound = NOT_FOUND;
  237. CRflag = 1;
  238. while ( CRflag!=0 )
  239. {
  240. if ( buf[inst] == '"' )
  241. CRflag--;
  242. if ( buf[inst] > 31 && buf[inst]!='"' && CRflag==1)
  243. {
  244. PlayerClub[ClubOffset] = buf[inst];
  245. ClubOffset++;
  246. }
  247. if ( buf[inst] < 31 && CRflag==1 )
  248. CRflag = 0;
  249. inst++;
  250. }
  251. PlayerClub[ClubOffset] = 0;
  252. ClubOffset++;
  253. // ****** SEARCH THROUGH STRING LIST FOR REPEAT OF CLUB NAME ******
  254. for ( short s=0; s < Stringcount ; s++ )
  255. {
  256. int CopyOffset = 0;
  257. while ( CRflag!=0 )
  258. {
  259. if ( TextStrings[CompareOffset] == 0 )
  260. {
  261. string[CopyOffset] = 0;
  262. CRflag = 0;
  263. }
  264. else
  265. {
  266. string[CopyOffset] = TextStrings[CompareOffset];
  267. }
  268. CopyOffset++;
  269. CompareOffset++;
  270. }
  271. if ( strcmpi( PlayerClub, string ) == 0 )
  272. {
  273. ClubFound = s;
  274. // break;
  275. }
  276. }
  277. // ****** THROW CLUB STRING INTO TEXT LIST ******
  278. if ( ClubFound == NOT_FOUND )
  279. {
  280. GetTextString( PlayerClub );
  281. }
  282. return(ClubFound);
  283. }
  284. //********************************************************************************************************************************
  285. void Getvariable( char *buf )
  286. {
  287. variable = NO_INSTRUCTION;
  288. while ( buf[inst] != 0 && variable == NO_INSTRUCTION )
  289. {
  290. if ( buf[inst+1] == ':')
  291. {
  292. if ( buf[inst] == 'x' )
  293. {variable = IMAGE_xCOORD; inst+=2;}
  294. if ( buf[inst] == 'y' )
  295. {variable = IMAGE_yCOORD; inst+=2;}
  296. if ( buf[inst] == 'w' )
  297. {variable = IMAGE_WIDTH; inst+=2;}
  298. if ( buf[inst] == 'h' )
  299. {variable = IMAGE_HEIGHT; inst+=2;}
  300. if ( buf[inst] == 'p' )
  301. {variable = IMAGE_PAGE; inst+=2;}
  302. if ( buf[inst] == 't' )
  303. {variable = TEXT_STRING; inst+=2;}
  304. }
  305. if ( buf[inst+4] == ':')
  306. {
  307. if ( buf[inst] == 'f' && buf[inst+1] == 'o' && buf[inst+2] == 'r' && buf[inst+3] == 'm' )
  308. {variable = FORMATION_TYPE; inst+=5;}
  309. if ( buf[inst] == 'd' && buf[inst+1] == 'r' && buf[inst+2] == 'a' && buf[inst+3] == 'w' )
  310. {variable = GROUP_DRAW_TYPE; inst+=5;}
  311. if ( buf[inst] == 'c' && buf[inst+1] == 'l' && buf[inst+2] == 'u' && buf[inst+3] == 'b' )
  312. {variable = PLAYERS_CLUB_NAME; inst+=5;}
  313. }
  314. if (variable == NO_INSTRUCTION)
  315. inst++;
  316. }
  317. }
  318. //********************************************************************************************************************************