ktigcc.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2004-2006 Kevin Kofler
  4. Copyright (C) 2006 Joey Adams
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #include <cstdio>
  18. #include <cstdlib>
  19. #include <unistd.h>
  20. #include <qstring.h>
  21. #include <kapplication.h>
  22. #include <kcmdlineargs.h>
  23. #include <kaboutdata.h>
  24. #include <qtextcodec.h>
  25. #include <kconfig.h>
  26. #include "mainform.h"
  27. using namespace std;
  28. void qCleanupImages_ktigcc();
  29. void qInitImages_ktigcc();
  30. static KCmdLineOptions options[] =
  31. {
  32. { "+[file]", "Project or file to open at startup", 0 },
  33. KCmdLineLastOption
  34. };
  35. const char *tigcc_base;
  36. char tempdir[]="/tmp/ktigccXXXXXX";
  37. char *quill_drv;
  38. KConfig *pconfig;
  39. KAboutData *pabout;
  40. const char *parg;
  41. int main( int argc, char *argv[] )
  42. {
  43. // Match the locale for the default C string <-> QString conversions.
  44. // Hopefully it is a .UTF-8 locale, if it isn't, don't complain about
  45. // characters lost converting!
  46. QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
  47. KAboutData about("ktigcc","TIGCC IDE for KDE","1.00",
  48. "TIGCC C and ASM SDK", KAboutData::License_GPL,
  49. "Copyright (C) 2004-2006 Kevin Kofler and Joey Adams. All rights reserved.\n"
  50. "TIGCC Copyright (C) 1999-2005 The TIGCC Team.",
  51. "Original linker by Xavier and Niklas\n"
  52. "Compiler modifications by Jean, Sebastian and Kevin\n"
  53. "Linker by Sebastian and Kevin\n"
  54. "Documentation by Zeljko\n"
  55. "A68k modifications by Kevin\n"
  56. "Windows IDE by Sebastian\n"
  57. "KTIGCC IDE by Kevin and Joey\n"
  58. "Documentation conversion to CHM by Philipp\n"
  59. "Documentation conversion to Qt Assistant by Kevin",
  60. "http://tigcc.ticalc.org/linux/", "Bugs@tigcc.ticalc.org");
  61. pabout=&about;
  62. KCmdLineArgs::init(argc,argv,&about);
  63. KCmdLineArgs::addCmdLineOptions(options);
  64. KApplication::addCmdLineOptions();
  65. KApplication app;
  66. // Readd the images KDE kindly removes...
  67. qCleanupImages_ktigcc();
  68. qInitImages_ktigcc();
  69. KConfig config("ktigccrc");
  70. pconfig=&config;
  71. if ((tigcc_base = getenv("TIGCC")) == NULL) {
  72. fprintf(stderr, "Fatal error: TIGCC is not defined in the environment. "
  73. "TIGCC must be defined before tigcc can run.\nFor (ba)sh, "
  74. "try: export TIGCC=/path/to/tigcc\nFor (t)csh, try: setenv "
  75. "TIGCC /path/to/tigcc\n");
  76. exit(-1);
  77. }
  78. quill_drv = (char *) malloc (strlen(tigcc_base) + 25);
  79. if (!quill_drv) {
  80. fprintf(stderr, "Fatal error: not enough free memory\n");
  81. exit(-1);
  82. }
  83. sprintf(quill_drv, "%s/bin/quill.drv", tigcc_base);
  84. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  85. sprintf(quill_drv, "%s/bin/Quill.drv", tigcc_base);
  86. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  87. sprintf(quill_drv, "%s/include/c/quill.drv", tigcc_base);
  88. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  89. sprintf(quill_drv, "%s/include/c/Quill.drv", tigcc_base);
  90. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  91. sprintf(quill_drv, "%s/include/quill/quill.drv", tigcc_base);
  92. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  93. sprintf(quill_drv, "%s/include/quill/Quill.drv", tigcc_base);
  94. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  95. sprintf(quill_drv, "%s/include/Quill/quill.drv", tigcc_base);
  96. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  97. sprintf(quill_drv, "%s/include/Quill/Quill.drv", tigcc_base);
  98. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  99. sprintf(quill_drv, "%s/lib/quill.drv", tigcc_base);
  100. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  101. sprintf(quill_drv, "%s/lib/Quill.drv", tigcc_base);
  102. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  103. free(quill_drv);
  104. quill_drv=NULL;
  105. quill_drv_found:
  106. if (!mkdtemp(tempdir)) exit(1);
  107. KCmdLineArgs *args=KCmdLineArgs::parsedArgs();
  108. if (args->count())
  109. parg=args->arg(0);
  110. else
  111. parg=NULL;
  112. MainForm mainForm;
  113. app.setMainWidget( &mainForm );
  114. mainForm.show();
  115. int exitcode=app.exec();
  116. rmdir(tempdir);
  117. return exitcode;
  118. }
  119. void write_temp_file(const char *filename, const char *data, const size_t len)
  120. {
  121. char buffer[strlen(tempdir)+strlen(filename)+2];
  122. sprintf(buffer,"%s/%s",tempdir,filename);
  123. FILE *f=fopen(buffer,"wb");
  124. if (!f) {error: fputs("Fatal error: Can't write temp file!\n",stderr); exit(1);}
  125. if (len) {
  126. if (fwrite(data,1,len,f)<len) goto error;
  127. } else {
  128. if (fputs(data,f)==EOF) goto error;
  129. }
  130. fclose(f);
  131. }
  132. void delete_temp_file(const char *filename)
  133. {
  134. char buffer[strlen(tempdir)+strlen(filename)+2];
  135. sprintf(buffer,"%s/%s",tempdir,filename);
  136. if (unlink(buffer)) {fputs("Fatal error: Can't delete temp file!\n",stderr); exit(1);}
  137. }
  138. void force_qt_assistant_page(int n)
  139. {
  140. char *home=getenv("HOME");
  141. char fname[strlen(home)+20];
  142. sprintf(fname,"%s/.qt/qt_assistantrc",home);
  143. FILE *f=fopen(fname,"r+b");
  144. if (!f) f=fopen(fname,"w+b");
  145. if (!f) exit(1);
  146. fseek(f,0,SEEK_END);
  147. size_t flen=ftell(f);
  148. fseek(f,0,SEEK_SET);
  149. char buffer[flen+1];
  150. memset(buffer,0,flen+1);
  151. if (fread(buffer,1,flen,f)<flen) exit(1);
  152. char *p=strstr(buffer,"SideBarPage=");
  153. if (p) {
  154. fseek(f,p-buffer+12,SEEK_SET);
  155. fputc('0'+n,f);
  156. } else {
  157. fseek(f,0,SEEK_END);
  158. fprintf(f,"\n\n[3.3]\nSideBarPage=%d\n",n);
  159. }
  160. fclose(f);
  161. }