home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / vide / videmake.cpp < prev    next >
C/C++ Source or Header  |  1998-09-28  |  6KB  |  259 lines

  1. // V IDE Make Class - all the stuff needed to create
  2. // makefiles, and run make.
  3.  
  4. #include <v/vfilesel.h>
  5. #include <v/vnotice.h>
  6.  
  7. #include "videapp.h"
  8.  
  9. #include "videcmdw.h"
  10.  
  11. #include "videmake.h"
  12. //#include <direct.h>
  13.  
  14.     static int filterIndex = 0;
  15.     static char* filter[] =
  16.       {
  17.         "Make*;make*;Make*.*;make*.*",
  18.         "*",
  19.         0
  20.       };
  21.  
  22. //=====================>>> videMake::videMake <<<===========================
  23.   videMake::videMake()
  24.   {
  25.     _stop = 0;
  26.     cmdw = ((videApp*)theApp)->GetMsgWindow();
  27.   }
  28.  
  29. //=====================>>> videMake::~videMake <<<===========================
  30.   videMake::~videMake()
  31.   {
  32.   }
  33.  
  34. //=====================>>> videMake::DoMake <<<===========================
  35.   int videMake::DoMake(videCmdWindow* parent, char* makecmd)
  36.   {
  37.     char cmd[maxFileNameSize];
  38.     vOS vos;
  39.  
  40.     static char makeCmds[] = "makecmds.vtm" ;
  41.     static char makeErrs[] = "makeerrs.vtm" ;
  42.  
  43.     char* mkpath = ((videApp*)theApp)->GetMkFile();
  44.     cmdw = ((videApp*)theApp)->GetMsgWindow();
  45.  
  46.     if (!*mkpath)
  47.       {
  48.         vNoticeDialog note((vWindow*)cmdw);
  49.         note.Notice("No Makefile specified. Use Select Makefile or Open Project first.");
  50.         return 0;
  51.       }
  52.  
  53.     cmdw->RaiseWindow();
  54.     cmdw->SetRdOnly(0);
  55.     (cmdw->GetTextEd())->SetFileType(gccError);
  56.  
  57.     cmdw->AddLine(mkpath);
  58.  
  59.     _stop = 0;            // not stopping
  60.  
  61.     // Now, change directory
  62.     strcpy(cmd,mkpath);
  63.     int ix = strlen(cmd);
  64.     while (ix > 0)
  65.       {
  66.         if (cmd[ix] == '\\' || cmd[ix] == '/')
  67.           {
  68.             cmd[ix] = 0;
  69.             break;
  70.           }
  71.         --ix;
  72.       }
  73.     char makeFile[256];
  74.     if (ix > 0)
  75.       {
  76.     strcpy(makeFile, &cmd[ix+1]);    // copy the makefile name
  77.     vos.vChDir(cmd);            // change dir
  78.       }
  79.     else
  80.         strcpy(makeFile,cmd);
  81.  
  82.  
  83.     strcpy(cmd, makecmd);        // make or make clean passed from caller
  84.     strcat(cmd, " -n -f ");             // -n for dry run, -f for file
  85.     strcat(cmd, makeFile);        // the name of the make file.
  86.  
  87.     vos.vDeleteFile(makeCmds);
  88.     vos.vDeleteFile(makeErrs);
  89.     if (vos.vRunProcess(cmd,makeCmds,makeErrs,1,1) != 0)
  90.       {
  91.         ShowErrors(cmdw,makeErrs);
  92.          return 0;
  93.       }
  94.  
  95.     theApp->CheckEvents();
  96.     if (_stop)
  97.       {
  98.         cmdw->AddLine("Make Aborted.");
  99.         return 0;
  100.       }
  101.  
  102.     ifstream inFile(makeCmds);
  103.  
  104.     if (!inFile)
  105.     return 0;        // file not there
  106.  
  107.     if (!cmdw)
  108.       {
  109.         inFile.close();
  110.         vos.vDeleteFile(makeCmds);
  111.         return 0;
  112.       }
  113.  
  114.   // read and process makecmds.tmp
  115.     const int maxBuff = 2000;
  116.     char buff[maxBuff+2];
  117.     char displayed[maxBuff+20];
  118.  
  119.     while (inFile.getline(buff,maxBuff))
  120.       {
  121.         strcpy(displayed,"> ");
  122.         strcat(displayed,buff);
  123.     if (!cmdw->AddLine(displayed))
  124.       {
  125.         vNoticeDialog note(theApp);
  126.         note.Notice("File too big -- only paritally read.");
  127.         break;
  128.       }
  129.         char* cp;
  130.         for (cp = buff ; *cp && *cp != '\r' && *cp != '\n' ; ++cp)
  131.             ;
  132.         *cp = 0;
  133.  
  134.         int retv = vos.vRunProcess(buff,0,makeErrs,1,1);
  135.         
  136.         ShowErrors(cmdw,makeErrs);
  137.  
  138.         theApp->CheckEvents();
  139.         if (_stop)
  140.           {
  141.             inFile.close();
  142.             vos.vDeleteFile(makeCmds);
  143.             cmdw->AddLine("Make Aborted.");
  144.             cmdw->SetRdOnly(1);
  145.             return 0;
  146.           }
  147.  
  148.         if (retv != 0)
  149.           {
  150.             inFile.close();
  151.             vos.vDeleteFile(makeCmds);
  152.             cmdw->AddLine("Make failed. Right click error line to open file.");
  153.             cmdw->SetRdOnly(1);
  154.             return 0;
  155.           }
  156.         }
  157.     inFile.close();
  158.     vos.vDeleteFile(makeCmds);
  159.     cmdw->AddLine("--------");
  160.     cmdw->SetRdOnly(1);
  161.     cmdw->RaiseWindow();
  162.     return 1;
  163.   }
  164.  
  165. //=====================>>> videMake::ShowErrors <<<=========================
  166.   void videMake::ShowErrors(videCmdWindow* cmdw, char* errName)
  167.   {
  168.     const int maxBuff = 510;
  169.     char buff[maxBuff+2];
  170.     char displayed[maxBuff+20];
  171.     vOS vos;
  172.  
  173.     ifstream errFile(errName);
  174.  
  175.     if (!errFile)
  176.         return;
  177.  
  178.     while (errFile.getline(buff,maxBuff))
  179.       {
  180.         strcpy(displayed,"  ! ");    // IMPORTANT!  videCmdWindow::GotoErrorLine
  181.         strcat(displayed,buff);         //    REQUIRES this exact format!!!
  182.         cmdw->AddLine(displayed);
  183.         theApp->CheckEvents();
  184.         if (_stop)
  185.           {
  186.             cmdw->AddLine("Make Aborted.");
  187.         vos.vDeleteFile(errName);
  188.             return;
  189.           }
  190.  
  191.       }
  192.     errFile.close();
  193.     vos.vDeleteFile(errName);
  194.   }
  195.  
  196. //=====================>>> videMake::CheckMake <<<===========================
  197.   int videMake::CheckMake(char* makecmd)
  198.   {
  199.     // Check if make would do anything...
  200.     char cmd[maxFileNameSize];
  201.     vOS vos;
  202.  
  203.     static char makeCmds[] = "makecmds.vtm" ;
  204.     static char makeErrs[] = "makeerrs.vtm" ;
  205.  
  206.     char* mkpath = ((videApp*)theApp)->GetMkFile();
  207.  
  208.     videCmdWindow* cmdw = ((videApp*)theApp)->GetMsgWindow();
  209.  
  210.     if (!*mkpath)
  211.       {
  212.     return 0;
  213.       }
  214.  
  215.     // Now, change directory
  216.     strcpy(cmd,mkpath);
  217.     int ix = strlen(cmd);
  218.     while (ix > 0)
  219.       {
  220.         if (cmd[ix] == '\\' || cmd[ix] == '/')
  221.           {
  222.             cmd[ix] = 0;
  223.             break;
  224.           }
  225.         --ix;
  226.       }
  227.     char makeFile[100];
  228.     strcpy(makeFile, &cmd[ix+1]);    // copy the makefile name
  229.     vos.vChDir(cmd);            // change dir
  230.  
  231.     strcpy(cmd, makecmd);        // make or make clean passed from caller
  232.     strcat(cmd, " -n -f ");             // -n for dry run, -f for file
  233.     strcat(cmd, makeFile);        // the name of the make file.
  234.  
  235.     if (vos.vRunProcess(cmd,makeCmds,makeErrs,1,1) != 0)
  236.       {
  237.     vos.vDeleteFile(makeErrs);
  238.     vos.vDeleteFile(makeCmds);
  239.          return 0;
  240.       }
  241.     // OK, then perhaps "nothing to make" issued.
  242.     ifstream inFile(makeCmds);            // open the makecmds file
  243.  
  244.     int retv = 1;
  245.     char buff[256];
  246.     if (inFile.getline(buff,155))
  247.       {
  248.     if (strstr(buff, "Nothing to be done") != 0)
  249.         retv = 0;
  250.       }
  251.     inFile.close();
  252.  
  253.     vos.vDeleteFile(makeErrs);
  254.     vos.vDeleteFile(makeCmds);
  255.     return retv;
  256.   }
  257.  
  258.  
  259.