ktigcc.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2004-2005 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 "mainform.h"
  22. using namespace std;
  23. void qCleanupImages_ktigcc();
  24. void qInitImages_ktigcc();
  25. const char *tigcc_base;
  26. char tempdir[]="/tmp/ktigccXXXXXX";
  27. char *quill_drv;
  28. int main( int argc, char *argv[] )
  29. {
  30. KCmdLineArgs::init(argc,argv,"KTIGCC","TIGCC IDE for KDE","1.00");
  31. KApplication app;
  32. // Readd the images KDE kindly removes...
  33. qCleanupImages_ktigcc();
  34. qInitImages_ktigcc();
  35. if ((tigcc_base = getenv("TIGCC")) == NULL) {
  36. fprintf(stderr, "Fatal error: TIGCC is not defined in the environment. "
  37. "TIGCC must be defined before tigcc can run.\nFor (ba)sh, "
  38. "try: export TIGCC=/path/to/tigcc\nFor (t)csh, try: setenv "
  39. "TIGCC /path/to/tigcc\n");
  40. exit(-1);
  41. }
  42. quill_drv = (char *) malloc (strlen(tigcc_base) + 25);
  43. if (!quill_drv) {
  44. fprintf(stderr, "Fatal error: not enough free memory\n");
  45. exit(-1);
  46. }
  47. sprintf(quill_drv, "%s/bin/quill.drv", tigcc_base);
  48. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  49. sprintf(quill_drv, "%s/bin/Quill.drv", tigcc_base);
  50. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  51. sprintf(quill_drv, "%s/include/c/quill.drv", tigcc_base);
  52. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  53. sprintf(quill_drv, "%s/include/c/Quill.drv", tigcc_base);
  54. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  55. sprintf(quill_drv, "%s/include/quill/quill.drv", tigcc_base);
  56. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  57. sprintf(quill_drv, "%s/include/quill/Quill.drv", tigcc_base);
  58. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  59. sprintf(quill_drv, "%s/include/Quill/quill.drv", tigcc_base);
  60. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  61. sprintf(quill_drv, "%s/include/Quill/Quill.drv", tigcc_base);
  62. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  63. sprintf(quill_drv, "%s/lib/quill.drv", tigcc_base);
  64. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  65. sprintf(quill_drv, "%s/lib/Quill.drv", tigcc_base);
  66. if(access(quill_drv, F_OK) != -1) goto quill_drv_found;
  67. free(quill_drv);
  68. quill_drv=NULL;
  69. quill_drv_found:
  70. /* Make sure the Kate color schema we need exists */
  71. char *home=getenv("HOME");
  72. char fname[strlen(home)+32];
  73. sprintf(fname,"%s/.kde/share/config/kateschemarc",home);
  74. FILE *f=fopen(fname,"r+b");
  75. if (!f) exit(1);
  76. fseek(f,0,SEEK_END);
  77. size_t flen=ftell(f);
  78. fseek(f,0,SEEK_SET);
  79. char buffer[flen+1];
  80. memset(buffer,0,flen+1);
  81. if (fread(buffer,1,flen,f)<flen) exit(1);
  82. if (!strstr(buffer,"[ktigcc - Grayed Out]\n")) {
  83. fseek(f,0,SEEK_END);
  84. fputs("\n\n[ktigcc - Grayed Out]\n"
  85. "Color Background=230,230,230\n"
  86. "Color Highlighted Bracket=255,255,153\n"
  87. "Color Highlighted Line=230,230,230\n"
  88. "Color Icon Bar=234,233,232\n"
  89. "Color Line Number=0,0,0\n"
  90. "Color MarkType1=0,0,255\n"
  91. "Color MarkType2=255,0,0\n"
  92. "Color MarkType3=255,255,0\n"
  93. "Color MarkType4=255,0,255\n"
  94. "Color MarkType5=160,160,164\n"
  95. "Color MarkType6=0,255,0\n"
  96. "Color MarkType7=255,0,0\n"
  97. "Color Selection=76,89,166\n"
  98. "Color Tab Marker=0,0,0\n"
  99. "Color Word Wrap Marker=120,120,120\n"
  100. "Font=Monospace,10,-1,5,50,0,0,0,1,0\n",f);
  101. }
  102. fclose(f);
  103. if (!mkdtemp(tempdir)) exit(1);
  104. MainForm mainForm;
  105. app.setMainWidget( &mainForm );
  106. mainForm.show();
  107. int exitcode=app.exec();
  108. rmdir(tempdir);
  109. return exitcode;
  110. }
  111. void write_temp_file(const char *filename, const char *data, const size_t len)
  112. {
  113. char buffer[strlen(tempdir)+strlen(filename)+2];
  114. sprintf(buffer,"%s/%s",tempdir,filename);
  115. FILE *f=fopen(buffer,"wb");
  116. if (!f) {error: fputs("Fatal error: Can't write temp file!\n",stderr); exit(1);}
  117. if (len) {
  118. if (fwrite(data,1,len,f)<len) goto error;
  119. } else {
  120. if (fputs(data,f)==EOF) goto error;
  121. }
  122. fclose(f);
  123. }
  124. void delete_temp_file(const char *filename)
  125. {
  126. char buffer[strlen(tempdir)+strlen(filename)+2];
  127. sprintf(buffer,"%s/%s",tempdir,filename);
  128. if (unlink(buffer)) {fputs("Fatal error: Can't delete temp file!\n",stderr); exit(1);}
  129. }