1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
// V IDE Make Class - all the stuff needed to create
// makefiles, and run make.
#include <v/vfilesel.h>
#include <v/vnotice.h>
#include "videapp.h"
#include "videcmdw.h"
#include "videmake.h"
//#include <direct.h>
static int filterIndex = 0;
static char* filter[] =
{
"Make*;make*;Make*.*;make*.*",
"*",
0
};
//=====================>>> videMake::videMake <<<===========================
videMake::videMake()
{
_stop = 0;
}
//=====================>>> videMake::~videMake <<<===========================
videMake::~videMake()
{
}
//=====================>>> videMake::DoMake <<<===========================
int videMake::DoMake(videCmdWindow* parent, char* makecmd)
{
char cmd[maxFileNameSize];
vOS vos;
static char makeCmds[] = "makecmds.vtm" ;
static char makeErrs[] = "makeerrs.vtm" ;
char* mkpath = ((videApp*)theApp)->GetMkFile();
videCmdWindow* cmdw = ((videApp*)theApp)->GetMsgWindow();
if (!*mkpath)
{
vNoticeDialog note((vWindow*)cmdw);
note.Notice("No makefile specified. Use Select Makefile first.");
return 0;
}
cmdw->SetViewWindow(makecmd);
cmdw->RaiseWindow();
cmdw->SetRdOnly(0);
(cmdw->GetTextEd())->SetFileType(gccError);
cmdw->AddLine(mkpath);
_stop = 0; // not stopping
// Now, change directory
strcpy(cmd,mkpath);
int ix = strlen(cmd);
while (ix > 0)
{
if (cmd[ix] == '\\' || cmd[ix] == '/')
{
cmd[ix] = 0;
break;
}
--ix;
}
char makeFile[100];
strcpy(makeFile, &cmd[ix+1]); // copy the makefile name
vos.vChDir(cmd); // change dir
strcpy(cmd, makecmd); // make or make clean passed from caller
strcat(cmd, " -n -f "); // -n for dry run, -f for file
strcat(cmd, makeFile); // the name of the make file.
if (vos.vRunProcess(cmd,makeCmds,makeErrs,1,1) != 0)
{
ShowErrors(cmdw,makeErrs);
return 0;
}
theApp->CheckEvents();
if (_stop)
{
cmdw->AddLine("Make Aborted.");
return 0;
}
ifstream inFile(makeCmds);
if (!inFile)
return 0; // file not there
if (!cmdw)
{
inFile.close();
vos.vDeleteFile(makeCmds);
return 0;
}
// read and process makecmds.tmp
const int maxBuff = 2000;
char buff[maxBuff+2];
char displayed[maxBuff+20];
while (inFile.getline(buff,maxBuff))
{
strcpy(displayed,"> ");
strcat(displayed,buff);
if (!cmdw->AddLine(displayed))
{
vNoticeDialog note(theApp);
note.Notice("File too big -- only paritally read.");
break;
}
char* cp;
for (cp = buff ; *cp && *cp != '\r' && *cp != '\n' ; ++cp)
;
*cp = 0;
int retv = vos.vRunProcess(buff,0,makeErrs,1,1);
ShowErrors(cmdw,makeErrs);
theApp->CheckEvents();
if (_stop)
{
cmdw->AddLine("Make Aborted.");
return 0;
}
if (retv != 0)
{
inFile.close();
vos.vDeleteFile(makeCmds);
cmdw->AddLine("Make failed. Right click error line to open file.");
cmdw->SetRdOnly(1);
return 0;
}
}
inFile.close();
vos.vDeleteFile(makeCmds);
cmdw->AddLine("Finished.");
cmdw->SetRdOnly(1);
cmdw->RaiseWindow();
return 1;
}
//=====================>>> videMake::ShowErrors <<<=========================
void videMake::ShowErrors(videCmdWindow* cmdw, char* errName)
{
const int maxBuff = 510;
char buff[maxBuff+2];
char displayed[maxBuff+20];
vOS vos;
ifstream errFile(errName);
if (!errFile)
return;
while (errFile.getline(buff,maxBuff))
{
strcpy(displayed," ! "); // IMPORTANT! videCmdWindow::GotoErrorLine
strcat(displayed,buff); // REQUIRES this exact format!!!
cmdw->AddLine(displayed);
theApp->CheckEvents();
if (_stop)
{
cmdw->AddLine("Make Aborted.");
return;
}
}
errFile.close();
vos.vDeleteFile(errName);
}
|