grammar.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "3d_all.h"
  4. #include "Berusky3d_kofola_interface.h"
  5. #include "grammar.h"
  6. #include "menu_script.h"
  7. extern char pDataDir[MAX_FILENAME];
  8. int StrtoType(char *pStr)
  9. {
  10. if (!strcmp(pStr, "iV"))
  11. return 0;
  12. if (!strcmp(pStr, "fV"))
  13. return 1;
  14. if (!strcmp(pStr, "sV"))
  15. return 2;
  16. if (!strcmp(pStr, "uV"))
  17. return 3;
  18. return -1;
  19. }
  20. void gr_Add_Mask(char *pMask, GRAMMAR * pGr)
  21. {
  22. char Expression[64];
  23. int cursor = 0, lm = pGr->LastMask;
  24. if (!strlen(pMask))
  25. return;
  26. cursor = Find_Next_Expresion(pMask, cursor, pGr->Mask[lm].cCommand);
  27. cursor = Find_Next_Expresion(pMask, cursor, Expression);
  28. pGr->Mask[lm].iCommand = atoi(Expression);
  29. pGr->Mask[lm].LastParam = 0;
  30. while (cursor != -1) {
  31. cursor = Find_Next_Expresion(pMask, cursor, Expression);
  32. if (cursor != -1) {
  33. pGr->Mask[lm].Parametr[pGr->Mask[lm].LastParam].Type =
  34. StrtoType(Expression);
  35. pGr->Mask[lm].LastParam++;
  36. }
  37. }
  38. pGr->LastMask++;
  39. }
  40. char gr_Load_Grammar(char *pFile, GRAMMAR * pGr)
  41. {
  42. FILE *file;
  43. char text[MAX_FILENAME];
  44. if (chdir(DATA_DIR))
  45. return 0;
  46. construct_path(text, MAX_FILENAME, 2, pDataDir, pFile);
  47. file = fopen(text, "r");
  48. if (!file)
  49. return 0;
  50. pGr->LastMask = 0;
  51. while (!feof(file)) {
  52. if(fgets(text, 256, file)) {
  53. gr_Add_Mask(text, pGr);
  54. strcpy(text, "");
  55. }
  56. }
  57. fclose(file);
  58. return 1;
  59. }