tpr.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software Foundation,
  17. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #include <cstdio>
  20. #include <cstdlib>
  21. #include <unistd.h>
  22. #include <kapplication.h>
  23. #include <kcmdlineargs.h>
  24. #include <kaboutdata.h>
  25. #include <qtextcodec.h>
  26. #include "tpr.h"
  27. #define find_param(s_,t_) find_param_ex((s_),(t_),sizeof(t_)-1)
  28. char *find_param_ex(char *s, const char *t, size_t l)
  29. {
  30. if (!strncmp(s,t,l))
  31. return s+l;
  32. else
  33. return NULL;
  34. }
  35. char *find_numbered_param(char *s, const char*t, int *i)
  36. {
  37. char *p;
  38. int endpos = 0;
  39. int ret = 0;
  40. char arglist[256];
  41. strcpy(arglist, t);
  42. strcat(arglist, "%n");
  43. ret = sscanf(s, arglist, i, &endpos);
  44. if(ret < 1 || !endpos) return NULL;
  45. p = s + endpos;
  46. return p;
  47. }
  48. // converts Windows paths to Unix paths if necessary.
  49. QString convert_path_separators(const char *file)
  50. {
  51. QString s=file;
  52. int o;
  53. #ifndef __WIN32__
  54. while ((o=s.find('\\',0,TRUE))>=0)
  55. s[o]='/';
  56. #endif
  57. return s;
  58. }
  59. char* strip(char *str)
  60. {
  61. int len = strlen(str);
  62. if(len > 0)
  63. if( (str[len-1] == '\r') || (str[len-1] == '\n') )
  64. str[len-1] = '\0';
  65. if(len > 1)
  66. if( (str[len-2] == '\r') || (str[len-2] == '\n') )
  67. str[len-2] = '\0';
  68. return str;
  69. }
  70. /*
  71. Read a line from file and do a clean-up
  72. */
  73. int read_line(FILE *f, char *buffer, int *l)
  74. {
  75. strcpy(buffer, "");
  76. if(feof(f)) return EOF;
  77. fgets(buffer, 256, f);
  78. strip(buffer);
  79. (*l)++;
  80. while( (buffer[0] == '\r') || (buffer[0] == '\n') || (buffer[0] == '\0') )
  81. {
  82. if(feof(f)) return EOF;
  83. fgets(buffer, 256, f);
  84. strip(buffer);
  85. (*l)++;
  86. }
  87. return 0;
  88. }
  89. //some items from the TSR might still be ignored or not shown here.
  90. //if you need one of them, add an entry to one of the
  91. //definition "tables".
  92. //If you add an entry here, don't forget to add something to
  93. // save_tpr!
  94. int parse_file(FILE *f,TPRDataStruct *dest)
  95. {
  96. char buffer[256];
  97. int l = 0;
  98. SectionType stype = SECTION_NONE;
  99. // Some defaults are different when opening an existing project.
  100. dest->settings.cc_switches="";
  101. dest->settings.as_switches="";
  102. dest->settings.a68k_switches="";
  103. dest->libopts.use_ti89=0;
  104. dest->libopts.use_ti92p=0;
  105. dest->libopts.use_v200=0;
  106. dest->libopts.use_minams=0;
  107. dest->libopts.save_screen=0;
  108. while(!feof(f))
  109. {
  110. char *p;
  111. // Get a line from file
  112. if(read_line(f, buffer, &l) == EOF) break;
  113. // Search for sections
  114. if( !strcmp(buffer, "[Settings]") )
  115. {
  116. stype = SECTION_SETTINGS;
  117. continue;
  118. }
  119. if( !strcmp(buffer, "[Library Options]") )
  120. {
  121. stype = SECTION_LIBOPTS;
  122. continue;
  123. }
  124. if( !strcmp(buffer, "[File Editing]") )
  125. {
  126. stype = SECTION_FILEEDIT;
  127. continue;
  128. }
  129. if( !strcmp(buffer, "[Included Files]") )
  130. {
  131. stype = SECTION_FILES;
  132. continue;
  133. }
  134. // Keywords in the [Settings] section
  135. if(stype == SECTION_SETTINGS) {
  136. #define boolean_param(token,setting) \
  137. if ( (p=find_param(buffer, token)) ) \
  138. { \
  139. if(!strcmp(p, "0")) dest->settings.setting = FALSE; \
  140. else if(!strcmp(p, "1")) dest->settings.setting = TRUE; \
  141. else return l; \
  142. continue; \
  143. } else
  144. #define string_vparam(token,var) \
  145. if ( (p=find_param(buffer, token)) ) \
  146. { \
  147. if (*p) dest->var = p; \
  148. continue; \
  149. } else
  150. #define string_param(token,setting) string_vparam(token,settings.setting)
  151. #define ignore_param(token) \
  152. if( (p=find_param(buffer, token)) ) \
  153. { \
  154. continue; \
  155. } else
  156. boolean_param("Archive=",archive)
  157. boolean_param("Pack=",pack)
  158. string_param("Packed Variable=",pack_name)
  159. string_vparam("Project Name=",prj_name)
  160. string_param("GCC Switches=",cc_switches)
  161. string_param("Assembler Switches=",a68k_switches)
  162. ignore_param("Linker Switches=") // Obsolete. Ignore.
  163. ignore_param("GNU Linker Switches=") // Obsolete. Ignore.
  164. string_param("GNU Assembler Switches=",as_switches)
  165. ignore_param("BSR Patch=") // Obsolete. Ignore.
  166. boolean_param("Debug Info=",debug_info)
  167. boolean_param("Standard Library=",std_lib)
  168. string_param("Command Line=",cmd_line)
  169. string_param("Post-Build Process=",post_build)
  170. boolean_param("Use Data Variable=",use_data_var)
  171. string_param("Data Variable=",data_var)
  172. boolean_param("Copy Data Variable=",copy_data_var)
  173. boolean_param("Copy Data Variable if Archived=",copy_data_var_arc)
  174. boolean_param("Optimize NOPs=",optimize_nops)
  175. boolean_param("Optimize Returns=",optimize_returns)
  176. boolean_param("Optimize Branches=",optimize_branches)
  177. boolean_param("Optimize Moves=",optimize_moves)
  178. boolean_param("Optimize Tests=",optimize_tests)
  179. boolean_param("Optimize Calculations=",optimize_calcs)
  180. boolean_param("Remove Unused Sections=",remove_unused)
  181. boolean_param("Binary Output=",outputbin)
  182. boolean_param("Fargo=",fargo)
  183. boolean_param("Flash OS=",flash_os)
  184. boolean_param("Cut Unused Ranges=",cut_ranges)
  185. boolean_param("Reorder Sections=",reorder_sections)
  186. boolean_param("Merge Constants=",merge_constants)
  187. boolean_param("Initialize BSS=",initialize_bss)
  188. return l;
  189. #undef boolean_param
  190. #undef string_vparam
  191. #undef string_param
  192. #undef ignore_param
  193. }
  194. // Keywords in the [Library Options] section
  195. if(stype == SECTION_LIBOPTS) {
  196. #define boolean_param(token,setting) \
  197. if ( (p=find_param(buffer, token)) ) \
  198. { \
  199. if(!strcmp(p, "0")) dest->libopts.setting = FALSE; \
  200. else if(!strcmp(p, "1")) dest->libopts.setting = TRUE; \
  201. else return l; \
  202. continue; \
  203. } else
  204. #define reloc_param(token,setting) \
  205. if ( (p=find_param(buffer, token)) ) \
  206. { \
  207. if (!strcmp(p,"None") || !strcmp(p,"AMS") \
  208. || !strcmp(p,"Direct")) \
  209. dest->libopts.setting = RT_NONE; \
  210. else if (!strcmp(p, "Precomputed")) \
  211. dest->libopts.setting = RT_PRECOMP; \
  212. else if (!strcmp(p, "Kernel")) \
  213. dest->libopts.setting = RT_KERNEL; \
  214. else if (!strcmp(p, "Compressed")) \
  215. dest->libopts.setting = RT_COMPRESSED; \
  216. else if (!strcmp(p, "F-Line")) \
  217. dest->libopts.setting = RT_FLINE; \
  218. else if (strcmp(p, "Unknown")) \
  219. return l; \
  220. continue; \
  221. } else
  222. //this new macro was added to make merging with save_tpr more consistent.
  223. #define minams_param(token,setting) \
  224. if ( (p=find_param(buffer, "Minimum AMS Version=")) ) \
  225. { \
  226. int major, minor; \
  227. if ((strlen(p)==4) \
  228. && (sscanf(p,"%1d.%2d",&major,&minor)==2)) \
  229. dest->libopts.minams = major * 100 + minor; \
  230. else \
  231. return l; \
  232. continue; \
  233. } else
  234. boolean_param("Use TI-89=",use_ti89)
  235. boolean_param("Use TI-92 Plus=",use_ti92p)
  236. boolean_param("Use V200=",use_v200)
  237. boolean_param("Optimize Calc Consts=",opt_calc_consts)
  238. boolean_param("Use Kernel=",use_kernel)
  239. boolean_param("Use PreOS=",use_preos)
  240. boolean_param("Minimum AMS Version Defined=",use_minams)
  241. minams_param("Minimum AMS Version=",minams);
  242. boolean_param("Unofficial OS Support=",unofficial_os)
  243. reloc_param("Reloc Format=",reloc_format)
  244. reloc_param("ROM Call Format=",rom_call_format)
  245. reloc_param("BSS Ref Format=",bss_ref_format)
  246. reloc_param("Data Ref Format=",data_ref_format)
  247. boolean_param("Use F-Line Jumps=",use_fline_jumps)
  248. boolean_param("Use 4-Byte F-Line Jumps=",use_4b_fline_jumps)
  249. boolean_param("Use Internal F-Line Emulator=",use_internal_fline_emu)
  250. boolean_param("Use Return Value=",use_return_value)
  251. boolean_param("Enable Error Return=",enable_error_return)
  252. boolean_param("Save Screen=",save_screen)
  253. boolean_param("Optimize ROM Calls=",opt_rom_calls)
  254. return l;
  255. #undef boolean_param
  256. #undef reloc_param
  257. #undef minams_param
  258. }
  259. // Keywords in the [File Editing] section
  260. if(stype == SECTION_FILEEDIT)
  261. {
  262. if ( (p=find_param(buffer, "Open File=")) ) \
  263. { \
  264. if (*p) dest->open_file = p; \
  265. continue; \
  266. } else return l;
  267. }
  268. // Keywords in the [Included Files] section
  269. if(stype == SECTION_FILES)
  270. {
  271. int v;
  272. if( (p=find_numbered_param(buffer, "C File %i=", &v)) )
  273. {
  274. QString s = convert_path_separators(p);
  275. dest->c_files.path << s;
  276. dest->c_files.folder << QString::null;
  277. continue;
  278. }
  279. else if( (p=find_numbered_param(buffer, "C File %i Folder=", &v)) )
  280. {
  281. dest->c_files.folder[v-1]=p;
  282. continue;
  283. }
  284. else if( (p=find_numbered_param(buffer, "GNU Assembler File %i=", &v)) )
  285. {
  286. QString s = convert_path_separators(p);
  287. dest->s_files.path << s;
  288. dest->s_files.folder << QString::null;
  289. continue;
  290. }
  291. else if( (p=find_numbered_param(buffer, "GNU Assembler File %i Folder=", &v)) )
  292. {
  293. dest->s_files.folder[v-1]=p;
  294. continue;
  295. }
  296. else if( (p=find_numbered_param(buffer, "Header File %i=", &v)) )
  297. {
  298. QString s = convert_path_separators(p);
  299. dest->h_files.path << s;
  300. dest->h_files.folder << QString::null;
  301. continue;
  302. }
  303. else if( (p=find_numbered_param(buffer, "Header File %i Folder=", &v)) )
  304. {
  305. dest->h_files.folder[v-1]=p;
  306. continue;
  307. }
  308. else if( (p=find_numbered_param(buffer, "Assembler File %i=", &v)) )
  309. {
  310. QString s = convert_path_separators(p);
  311. dest->asm_files.path << s;
  312. dest->asm_files.folder << QString::null;
  313. continue;
  314. }
  315. else if( (p=find_numbered_param(buffer, "Assembler File %i Folder=", &v)) )
  316. {
  317. dest->asm_files.folder[v-1]=p;
  318. continue;
  319. }
  320. else if( (p=find_numbered_param(buffer, "Object File %i=", &v)) )
  321. {
  322. QString s = convert_path_separators(p);
  323. dest->o_files.path << s;
  324. dest->o_files.folder << QString::null;
  325. continue;
  326. }
  327. else if( (p=find_numbered_param(buffer, "Object File %i Folder=", &v)) )
  328. {
  329. dest->o_files.folder[v-1]=p;
  330. continue;
  331. }
  332. else if( (p=find_numbered_param(buffer, "Archive File %i=", &v)) )
  333. {
  334. QString s = convert_path_separators(p);
  335. dest->a_files.path << s;
  336. dest->a_files.folder << QString::null;
  337. continue;
  338. }
  339. else if( (p=find_numbered_param(buffer, "Archive File %i Folder=", &v)) )
  340. {
  341. dest->a_files.folder[v-1]=p;
  342. continue;
  343. }
  344. else if( (p=find_numbered_param(buffer, "Text File %i=", &v)) )
  345. {
  346. QString s = convert_path_separators(p);
  347. dest->txt_files.path << s;
  348. dest->txt_files.folder << QString::null;
  349. continue;
  350. }
  351. else if( (p=find_numbered_param(buffer, "Text File %i Folder=", &v)) )
  352. {
  353. dest->txt_files.folder[v-1]=p;
  354. continue;
  355. }
  356. else if( (p=find_numbered_param(buffer, "Quill File %i=", &v)) )
  357. {
  358. QString s = convert_path_separators(p);
  359. dest->quill_files.path << s;
  360. dest->quill_files.folder << QString::null;
  361. continue;
  362. }
  363. else if( (p=find_numbered_param(buffer, "Quill File %i Folder=", &v)) )
  364. {
  365. dest->quill_files.folder[v-1]=p;
  366. continue;
  367. }
  368. else if( (p=find_numbered_param(buffer, "Other File %i=", &v)) )
  369. {
  370. QString s = convert_path_separators(p);
  371. dest->oth_files.path << s;
  372. dest->oth_files.folder << QString::null;
  373. continue;
  374. }
  375. else if( (p=find_numbered_param(buffer, "Other File %i Folder=", &v)) )
  376. {
  377. dest->oth_files.folder[v-1]=p;
  378. continue;
  379. }
  380. else return l;
  381. }
  382. }
  383. return 0;
  384. }
  385. //returns 0 on success
  386. int loadTPR(QString &fileName,TPRDataStruct *dest)
  387. {
  388. FILE *f;
  389. int ret;
  390. f = fopen(fileName, "r");
  391. if(f == NULL) {
  392. return -1;
  393. }
  394. ret=parse_file(f,dest);
  395. fclose(f);
  396. return ret;
  397. }
  398. QString loadFileText(const char *fileName)
  399. {
  400. FILE *f;
  401. f=fopen(fileName,"rb");
  402. if (!f)
  403. return QString::null;
  404. fseek(f,0,SEEK_END);
  405. size_t flen=ftell(f);
  406. fseek(f,0,SEEK_SET);
  407. char buffer[flen+1];
  408. memset(buffer,0,flen+1);
  409. fread(buffer,1,flen,f);
  410. return QString(buffer);
  411. }
  412. QString convert_path_separators_save(QString s)
  413. {
  414. int o;
  415. #ifndef __WIN32__
  416. while ((o=s.find('/',0,TRUE))>=0)
  417. s[o]='\\';
  418. #endif
  419. return s;
  420. }
  421. //this is here because QString::ascii() returns "(null)" on a null string.
  422. const char *smartAscii(const QString &s)
  423. {
  424. if (s.isNull())
  425. return "";
  426. return s.ascii();
  427. }
  428. //To do:
  429. //use macros to merge token with "%d\r\n" and "%s\r\n" instead of adding token to the pattern, which might not be necessary.
  430. //can a macro have absolutely nothing in it? that's why I said i there, since it had to be something to do.
  431. //reloc_param's macro here just puts "None" for the RT_NONE macro, which is probably not entirely correct, but it should work in all cases anyway.
  432. //some parameters are booleans for if a parameter is defined or not. should the parameter be shown anyway, even if the associated boolean is false?
  433. int save_tpr(FILE *f,TPRDataStruct *dest)
  434. {
  435. int i=0,e;
  436. QString tmp;
  437. #define boolean_param(token,setting) fprintf(f,"%s%d\r\n",token,!!dest->settings.setting);
  438. #define string_vparam(token,var) fprintf(f,"%s%s\r\n",token,smartAscii(dest->var));
  439. #define string_param(token,setting) string_vparam(token,settings.setting)
  440. #define ignore_param(token) /**/
  441. fputs("[Settings]\r\n",f);
  442. boolean_param("Archive=",archive)
  443. boolean_param("Pack=",pack)
  444. string_param("Packed Variable=",pack_name)
  445. string_vparam("Project Name=",prj_name)
  446. string_param("GCC Switches=",cc_switches)
  447. string_param("Assembler Switches=",a68k_switches)
  448. ignore_param("Linker Switches=") // Obsolete. Ignore.
  449. ignore_param("GNU Linker Switches=") // Obsolete. Ignore.
  450. string_param("GNU Assembler Switches=",as_switches)
  451. ignore_param("BSR Patch=") // Obsolete. Ignore.
  452. boolean_param("Debug Info=",debug_info)
  453. boolean_param("Standard Library=",std_lib)
  454. string_param("Command Line=",cmd_line)
  455. string_param("Post-Build Process=",post_build)
  456. boolean_param("Use Data Variable=",use_data_var)
  457. string_param("Data Variable=",data_var)
  458. boolean_param("Copy Data Variable=",copy_data_var)
  459. boolean_param("Copy Data Variable if Archived=",copy_data_var_arc)
  460. boolean_param("Optimize NOPs=",optimize_nops)
  461. boolean_param("Optimize Returns=",optimize_returns)
  462. boolean_param("Optimize Branches=",optimize_branches)
  463. boolean_param("Optimize Moves=",optimize_moves)
  464. boolean_param("Optimize Tests=",optimize_tests)
  465. boolean_param("Optimize Calculations=",optimize_calcs)
  466. boolean_param("Remove Unused Sections=",remove_unused)
  467. boolean_param("Binary Output=",outputbin)
  468. boolean_param("Fargo=",fargo)
  469. boolean_param("Flash OS=",flash_os)
  470. boolean_param("Cut Unused Ranges=",cut_ranges)
  471. boolean_param("Reorder Sections=",reorder_sections)
  472. boolean_param("Merge Constants=",merge_constants)
  473. boolean_param("Initialize BSS=",initialize_bss)
  474. #undef boolean_param
  475. #undef string_vparam
  476. #undef string_param
  477. #undef ignore_param
  478. #define boolean_param(token,setting) fprintf(f,"%s%d\r\n",token,!!dest->libopts.setting);
  479. #define reloc_param(token,setting) \
  480. switch(dest->libopts.setting) \
  481. { \
  482. case RT_NONE: \
  483. fprintf(f,"%sNone\r\n",token); \
  484. break; \
  485. case RT_PRECOMP: \
  486. fprintf(f,"%sPrecomputed\r\n",token); \
  487. break; \
  488. case RT_KERNEL: \
  489. fprintf(f,"%sKernel\r\n",token); \
  490. break; \
  491. case RT_COMPRESSED: \
  492. fprintf(f,"%sCompressed\r\n",token); \
  493. break; \
  494. case RT_FLINE: \
  495. fprintf(f,"%sF-Line\r\n",token); \
  496. break; \
  497. }
  498. #define minams_param(token,setting) \
  499. { \
  500. int major,minor; \
  501. major=dest->libopts.setting/100; \
  502. minor=dest->libopts.setting%100; \
  503. if (minor<10) \
  504. fprintf(f,"%s%d.0%d\r\n",token,major,minor); \
  505. else \
  506. fprintf(f,"%s%d.%d\r\n",token,major,minor); \
  507. }
  508. fputs("\r\n[Library Options]\r\n",f);
  509. boolean_param("Use TI-89=",use_ti89)
  510. boolean_param("Use TI-92 Plus=",use_ti92p)
  511. boolean_param("Use V200=",use_v200)
  512. boolean_param("Optimize Calc Consts=",opt_calc_consts)
  513. boolean_param("Use Kernel=",use_kernel)
  514. boolean_param("Use PreOS=",use_preos)
  515. boolean_param("Minimum AMS Version Defined=",use_minams)
  516. minams_param("Minimum AMS Version=",minams);
  517. boolean_param("Unofficial OS Support=",unofficial_os)
  518. reloc_param("Reloc Format=",reloc_format)
  519. reloc_param("ROM Call Format=",rom_call_format)
  520. reloc_param("BSS Ref Format=",bss_ref_format)
  521. reloc_param("Data Ref Format=",data_ref_format)
  522. boolean_param("Use F-Line Jumps=",use_fline_jumps)
  523. boolean_param("Use 4-Byte F-Line Jumps=",use_4b_fline_jumps)
  524. boolean_param("Use Internal F-Line Emulator=",use_internal_fline_emu)
  525. boolean_param("Use Return Value=",use_return_value)
  526. boolean_param("Enable Error Return=",enable_error_return)
  527. boolean_param("Save Screen=",save_screen)
  528. boolean_param("Optimize ROM Calls=",opt_rom_calls)
  529. #undef boolean_param
  530. #undef reloc_param
  531. #undef minams_param
  532. fprintf(f,"\r\n[File Editing]\r\nOpen File=%s\r\n\r\n[Included Files]\r\n",smartAscii(dest->open_file));
  533. #define filepath_param(token,filetype) \
  534. e=dest->filetype.path.count(); \
  535. for(i=0;i<e;i++) \
  536. { \
  537. tmp=convert_path_separators_save(smartAscii(dest->filetype.path[i])); \
  538. fprintf(f,"%s %ld=%s\r\n",token,(long)(i+1),smartAscii(tmp)); \
  539. if (!dest->filetype.folder[i].isEmpty()) \
  540. { \
  541. fprintf(f,"%s %ld Folder=%s\r\n",token,(long)(i+1),smartAscii(dest->filetype.folder[i])); \
  542. } \
  543. }
  544. filepath_param("C File",c_files)
  545. filepath_param("GNU Assembler File",s_files)
  546. filepath_param("Header File",h_files)
  547. filepath_param("Assembler File",asm_files)
  548. filepath_param("Object File",o_files)
  549. filepath_param("Archive File",a_files)
  550. filepath_param("Text File",txt_files)
  551. filepath_param("Quill File",quill_files)
  552. filepath_param("Other File",oth_files)
  553. #undef filepath_param
  554. fputs("\r\n",f);
  555. return 0;
  556. }
  557. //returns 0 on success, -1 if the file isn't there, and -2 if there's not enough memory.
  558. int saveTPR(QString &fileName,TPRDataStruct *src)
  559. {
  560. FILE *f;
  561. int ret;
  562. f=fopen(fileName,"wb");
  563. if (!f)
  564. {
  565. return -1;
  566. }
  567. ret=save_tpr(f,src);
  568. fclose(f);
  569. return ret;
  570. }