tpr.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. tpr handling routines adapted from tprbuilder
  4. Copyright (C) 2002 Romain Liévin
  5. Copyright (C) 2002-2006 Kevin Kofler
  6. Copyright (C) 2006 Joey Adams
  7. Copyright (C) 2007 Konrad Meyer
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software Foundation,
  18. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #pragma once
  21. class KUrl;
  22. #include <QString>
  23. #include <QStringList>
  24. #include <QByteArray>
  25. #include <Q3ValueVector>
  26. #include <QPair>
  27. #include <QTextCodec>
  28. /*Structure definitions from tprbuilder source; slightly modified
  29. to work under C++
  30. */
  31. typedef unsigned char Boolean;
  32. /* global enumerations */
  33. enum SectionType_ { SECTION_NONE, SECTION_SETTINGS, SECTION_LIBOPTS,
  34. SECTION_FILEEDIT, SECTION_FILES };
  35. typedef enum SectionType_ SectionType;
  36. /* definitions */
  37. typedef struct tprsettings tprSettings;
  38. struct tprsettings
  39. {
  40. tprsettings() : archive(0),pack(0),debug_info(0),std_lib(1),
  41. use_data_var(0),copy_data_var(1),copy_data_var_arc(1),
  42. optimize_nops(1),optimize_returns(1),optimize_branches(1),
  43. optimize_moves(1),optimize_tests(1),optimize_calcs(1),
  44. remove_unused(1),outputbin(0),fargo(0),flash_os(0),
  45. cut_ranges(1),reorder_sections(1),merge_constants(1),
  46. initialize_bss(1),
  47. cc_switches("-Os -Wall -W -Wwrite-strings -ffunction-sections -fdata-sections"),
  48. as_switches(""),
  49. a68k_switches("-g -t")
  50. {}
  51. Boolean archive; // we want to build an archive
  52. Boolean pack; // we want to pack the executable
  53. Boolean debug_info; // pass -g option to tigcc
  54. Boolean std_lib; // link against tigcc.a
  55. Boolean use_data_var;
  56. Boolean copy_data_var;
  57. Boolean copy_data_var_arc;
  58. Boolean optimize_nops;
  59. Boolean optimize_returns;
  60. Boolean optimize_branches;
  61. Boolean optimize_moves;
  62. Boolean optimize_tests;
  63. Boolean optimize_calcs;
  64. Boolean remove_unused;
  65. Boolean outputbin;
  66. Boolean fargo;
  67. Boolean flash_os;
  68. Boolean cut_ranges;
  69. Boolean reorder_sections;
  70. Boolean merge_constants;
  71. Boolean initialize_bss;
  72. QString pack_name;
  73. QString cc_switches;
  74. QString as_switches;
  75. QString a68k_switches;
  76. QString cmd_line;
  77. QString post_build;
  78. QString data_var;
  79. };
  80. enum tprreloctypes {
  81. RT_NONE, // None (BSS, data var)
  82. RT_DIRECT, // Direct (ROM_CALLs)
  83. RT_AMS, // AMS (relocs)
  84. RT_PRECOMP, // ROM_CALLs only: Precomputed (Optimized)
  85. RT_KERNEL, // Kernel
  86. RT_COMPRESSED, // Compressed
  87. RT_MLINK, // MLink
  88. RT_FLINE // ROM_CALLs only: F-Line
  89. };
  90. typedef enum tprreloctypes tprRelocType;
  91. typedef struct tprlibopts tprLibOpts;
  92. struct tprlibopts
  93. {
  94. tprlibopts() : use_ti89(1),use_ti92p(1),use_v200(1),opt_calc_consts(0),
  95. use_kernel(0),use_preos(0),use_minams(1),
  96. unofficial_os(0),use_fline_jumps(0),use_4b_fline_jumps(0),
  97. use_internal_fline_emu(0),use_return_value(0),
  98. enable_error_return(0),save_screen(1),opt_rom_calls(0),
  99. minams(100),reloc_format(RT_AMS),rom_call_format(RT_DIRECT),
  100. bss_ref_format(RT_KERNEL),data_ref_format(RT_KERNEL)
  101. {}
  102. Boolean use_ti89;
  103. Boolean use_ti92p;
  104. Boolean use_v200;
  105. Boolean opt_calc_consts;
  106. Boolean use_kernel;
  107. Boolean use_preos;
  108. Boolean use_minams;
  109. Boolean unofficial_os;
  110. Boolean use_fline_jumps;
  111. Boolean use_4b_fline_jumps;
  112. Boolean use_internal_fline_emu;
  113. Boolean use_return_value;
  114. Boolean enable_error_return;
  115. Boolean save_screen;
  116. Boolean opt_rom_calls;
  117. int minams;
  118. tprRelocType reloc_format;
  119. tprRelocType rom_call_format;
  120. tprRelocType bss_ref_format;
  121. tprRelocType data_ref_format;
  122. };
  123. typedef struct
  124. {
  125. QStringList path;
  126. QStringList folder;
  127. } TPRFileList;
  128. typedef struct
  129. {
  130. QString prj_name;
  131. QString open_file;
  132. tprSettings settings;
  133. tprLibOpts libopts;
  134. TPRFileList h_files;
  135. TPRFileList c_files;
  136. TPRFileList s_files;
  137. TPRFileList asm_files;
  138. TPRFileList o_files;
  139. TPRFileList a_files;
  140. TPRFileList txt_files;
  141. TPRFileList oth_files;
  142. TPRFileList quill_files;
  143. } TPRDataStruct;
  144. enum {PATH_ERROR,PATH_NOTFOUND,PATH_FILE,PATH_FOLDER}; //return types for getPathType
  145. typedef QVector<QPair<unsigned,unsigned> > LineStartList;
  146. const char *smartAscii(const QString &s);
  147. void newSettings(tprSettings *settings,tprLibOpts *libopts);
  148. int loadTPR(const QString &fileName,TPRDataStruct *dest);
  149. QString loadFileText(const char *fileName);
  150. int peekFirstChar(const char *fileName);
  151. int saveTPR(const QString &fileName,TPRDataStruct *src);
  152. void mkdir_multi(const char *fileName);
  153. int saveAndSplitFileText(const char *fileName, const QString &fileText,
  154. bool split, bool addCLineDirective,
  155. bool addASMLineDirective, const QString &origFileName,
  156. LineStartList *pLineStartList);
  157. void kurlNewFileName(KUrl &dir,const QString &newFileName);
  158. int checkFileName(const QString &fileName,const QStringList &fileNameList);
  159. int copyFile(const char *src, const char *dest);
  160. bool moveFile(const QString &src, const QString &dest);
  161. int insertName(const char *src, const char *dest, const char *name);
  162. int getPathType(const QString &thePath);
  163. QStringList process_libopts(void);
  164. QStringList process_settings(const QString &prjNameUnicode,
  165. const QString &projectBaseName,
  166. QString &pstarterName, QByteArray &packName);
  167. class TiconvTextCodec : public QTextCodec {
  168. public:
  169. static TiconvTextCodec *instance;
  170. TiconvTextCodec() : QTextCodec() {instance=this;}
  171. virtual QByteArray name() const {return "TI-89";}
  172. virtual int mibEnum() const {return 0x71C0;}
  173. protected:
  174. virtual QByteArray convertFromUnicode(const QChar *input, int number, ConverterState *state) const;
  175. virtual QString convertToUnicode(const char *chars, int len, ConverterState *state) const;
  176. };