main.pl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. use strict;
  2. use warnings;
  3. require "structure.pl";
  4. require "game_data.pl";
  5. # default data
  6. my $file_structure = "game_structure";
  7. # compilation data
  8. my @src_files = ();
  9. my $target;
  10. # argument loop
  11. while (my $arg = shift) {
  12. # new structure
  13. if ($arg eq "-s") {
  14. $file_structure = shift;
  15. }
  16. # open game data and check their structure
  17. elsif ($arg eq "-c") {
  18. # file to check
  19. my $file = shift;
  20. # structure to check against
  21. my $structure = game_structure_open($file_structure);
  22. if (!$structure) {
  23. printf("error reading structure: $file_structure\n");
  24. exit 0;
  25. }
  26. # get game data from file
  27. my $game_data = read_file($file);
  28. if (!$game_data) {
  29. printf("error reading game data: $file\n");
  30. exit 0;
  31. }
  32. # check data
  33. if (check_data($game_data, $structure)) {
  34. printf("file '$file' is structured based on $file_structure\n");
  35. }
  36. else {
  37. printf("file '$file' is NOT structure based on $file_structure\n");
  38. }
  39. } # -c : check data against structure
  40. elsif ($arg eq "-t") {
  41. $target = shift;
  42. }
  43. else {
  44. push @src_files, $arg;
  45. }
  46. } # argument loop
  47. if ($target eq "python") {
  48. if (@src_files <= 0) {
  49. printf("no source files given\n");
  50. exit 0;
  51. }
  52. # currently it only parses the first of the source files only
  53. my $game_data = read_file($src_files[0]);
  54. if (!$game_data) {
  55. printf("compilation error: $src_files[0]\n");
  56. exit 0;
  57. }
  58. # compile to python
  59. require("compile_to_python.pl");
  60. compile_to_python($game_data);
  61. }