ktigcc.cpp 6.5 KB

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