langtool.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. $langs = array("en","cz","it","es","pl");
  3. function parselang($a) {
  4. $out=array();
  5. foreach ($a as $line){
  6. if (!strpos($line,"MSG")) continue;
  7. //echo $line;
  8. preg_match('/\#define\s*(\S*)\s*(.*)/is',$line,$a);
  9. //print_r($a);die();
  10. if (!$a[1]) continue;
  11. $v = trim($a[2]);
  12. //$v = str_replace('MACHINE_NAME "','"Prusa i3',$v);
  13. $v = str_replace('" FIRMWARE_URL "','https://github.com/prusa3d/Prusa-i3-Plus/',$v);
  14. $v = str_replace('" PROTOCOL_VERSION "','1.0',$v);
  15. $v = str_replace('" STRINGIFY(EXTRUDERS) "','1',$v);
  16. $v = str_replace('" MACHINE_UUID "','00000000-0000-0000-0000-000000000000',$v);
  17. $out[trim($a[1])]=$v;
  18. }
  19. return $out;
  20. }
  21. foreach ($langs as $lang) {
  22. $f = file("language_".$lang.".h");
  23. $$lang = parselang($f);
  24. }
  25. /*
  26. $f = file("language_cz.h");
  27. $cz = parselang($f);
  28. $f = file("language_en.h");
  29. $en = parselang($f);
  30. */
  31. //print_r($cz);
  32. $out="#ifndef LANGUAGE_ALL_H\n#define LANGUAGE_ALL_H\n\nextern unsigned char lang_selected;\nextern const char** MSG_ALL[];\n";
  33. $counter=0;
  34. $langname = 0;
  35. $langsel = 0;
  36. foreach ($cz as $k=>$v) {
  37. $out .= "#define $k MSG_ALL[lang_selected][$counter]\n";
  38. if ($k=="MSG_LANGUAGE_NAME") $langname = $counter;
  39. if ($k=="MSG_LANGUAGE_SELECT") $langsel = $counter;
  40. //$out2 .= "\t".''.$v.','."\n";
  41. //$out3 .= "\t".''.$en[$k].','."\n";
  42. $counter++;
  43. }
  44. $out.="#define LANGUAGE_NAME $langname \n";
  45. $out.="#define LANGUAGE_SELECT $langsel \n";
  46. $out.="#define LANG_NUM ".count($langs)." \n";
  47. $out.="char* CAT2(const char *s1,const char *s2);\n";
  48. $out.="char* CAT4(const char *s1,const char *s2,const char *s3,const char *s4);\n";
  49. $out.="\n\n\n#endif //LANGUAGE_ALL.H";
  50. file_put_contents("language_all.h",$out);
  51. echo ".h created\n";
  52. $out="#include <avr/pgmspace.h>\n#include \"configuration_prusa.h\"\n#define LCD_WIDTH 20\nextern unsigned char lang_selected;\n";
  53. foreach ($langs as $lang) {
  54. $outa[$lang]="const char* MSG".strtoupper($lang)."[] = {";
  55. }
  56. //$out2="const char* MSGCZ[] = {";
  57. //$out3="const char* MSGEN[] = {";
  58. $counter=0;
  59. foreach ($cz as $k=>$v) {
  60. foreach ($langs as $lang) {
  61. $out .= "const char MSG".strtoupper($lang)."${counter}[] PROGMEM = { ".${$lang}[$k]." }; //$k\n";
  62. $outa[$lang].="MSG".strtoupper($lang)."$counter, //$k\n";
  63. if (${$lang}[$k] == "") echo "ERR: In language: ".strtoupper($lang)." string \"".$k."\" NOT FOUND !\n";
  64. }
  65. //$out .= "const char MSGCZ${counter}[] PROGMEM = { $v }; //$k\n";
  66. //$out .= "const char MSGEN${counter}[] PROGMEM = {".$en[$k]."}; //$k\n";
  67. //$out2 .= "MSGCZ$counter, //$k\n";
  68. //$out3 .= "MSGEN$counter, //$k\n";
  69. $counter++;
  70. }
  71. $langlist=array();
  72. foreach ($langs as $lang) {
  73. $out.= $outa[$lang] . "};\n";
  74. $langlist[]="MSG".strtoupper($lang);
  75. }
  76. /*
  77. $out2.="};\n";
  78. $out3.="};\n";
  79. $out .= $out2;
  80. $out .= $out3;
  81. */
  82. $out .= "\n\nconst char** MSG_ALL[] = {".join(",",$langlist)."};";
  83. $tools = <<<EOF
  84. char langbuffer[LCD_WIDTH+1];
  85. char* CAT2(const char *s1,const char *s2) {
  86. unsigned char len=0;
  87. strncpy_P(langbuffer+len,s1,LCD_WIDTH-len);
  88. len+=strlen_P(s1);
  89. strncpy_P(langbuffer+len,s2,LCD_WIDTH-len);
  90. return langbuffer;
  91. }
  92. char* CAT4(const char *s1,const char *s2,const char *s3,const char *s4) {
  93. unsigned char len=0;
  94. strncpy_P(langbuffer+len,s1,LCD_WIDTH-len);
  95. len+=strlen_P(s1);
  96. strncpy_P(langbuffer+len,s2,LCD_WIDTH-len);
  97. len+=strlen_P(s2);
  98. strncpy_P(langbuffer+len,s3,LCD_WIDTH-len);
  99. len+=strlen_P(s3);
  100. strncpy_P(langbuffer+len,s4,LCD_WIDTH-len);
  101. return langbuffer;
  102. }
  103. EOF;
  104. $out.=$tools;
  105. file_put_contents("language_all.cpp",$out);
  106. echo ".cpp created.\nDone!\n";
  107. //const char MSG1[] PROGMEM = MSG_SD_INSERTED;
  108. //const char* MSGCZ[] PROGMEM = {MSG_SD_INSERTED,MSG_SD_REMOVED};