Menu

[73c16a]: / main.cpp  Maximize  Restore  History

Download this file

102 lines (95 with data), 5.2 kB

  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
#include <iostream>// Used for IO froms the compiler
#include <cstdlib>// Used for pauseing the screen
#include <cstdio>// Used for deleteing files
#include <windows.h>// Used for loading the DLLs
#include <vector>// Used for making lists
#include <fstream>// used for file io
#include "Classes.h"// Used for returing the compiler erros
using namespace std;// Use th standard namespace
typedef int (__cdecl *PLUGIN)(string);// The compiler error
vector<HMODULE> DllList;// A list of all of the dlls
vector<PLUGIN> PluginList;// A list of all of the dlls main function
vector<string> DllDir;// A list of all of the DLL's directorys
void SendError(string Msg) // Send an error to the user
{
cout << "[SYSTEM ERROR] " << Msg << endl;// Send the error
system("pause");// Wait for a response
exit(1);// Quit the program
}// End of SendError(string)
void LoadDLLs(void) // Load all of the dlls for the program
{
for(unsigned int i = 0; i != DllDir.size(); i++) // Go through all of the plugins
{
cout << "\t-\"" << DllDir[i].c_str() << "\"";// Show that we are reading the copiler
DllList.push_back(LoadLibrary(DllDir[i].c_str()));// Load the compiler
if(!DllList.back()) // If we could not find the compiler module
{
cout << " failed." << endl;// We could not load the copiler
SendError("Could not load the plugin");// Send the error
}
else // If we found the compiler
{
cout << " worked." << endl;// We could not load the copiler
PluginList.push_back((PLUGIN)GetProcAddress(DllList.back(), "Plugin"));// Get the compiler functions address
if(!PluginList.back())// If the dll did not have the function
SendError("Could not load \"Plugin()\" function!");// Send the error
}// End of if statement
}// go through all of the plugins
}// End of LoadDLLs(void)
void FreeDLLs(void) // Free all of the DLLs we loaded
{
for(unsigned int i = 0; i != DllDir.size(); i++) // Go through all of the plugins
{
cout << "\t-\"" << DllDir[i].c_str() << "\"" << endl;// Show that we are reading the copiler
FreeLibrary(DllList[i]);// Free the compiler
DllList.erase(DllList.begin());// Delete the first element
}// go through all of the plugins
}// End of FreeDLLs(void)
int main(int NArgs, const char* Args[]) // The main program
{
// ARGS
// 1 : Windows location
// 2... : DLL Locations
// 3 : Index of plugin to execute
// 4 : File to send plugin
if(NArgs < 4)// If we have any fewer than three paramente
SendError("Missing executional parameters");// End the error
for(int i = 0; i != NArgs-3; i++)// Go through all of the plugins
DllDir.push_back(Args[i+1]);// Add the dll to the list
cout << "Loading DLLs..." << endl;// Show what we are doing
LoadDLLs();// Load the compiler module
string PluginToExecute = Args[abs(atoi(Args[NArgs-2]))];// Get the name of the plugin to execute
PluginToExecute.erase(0, PluginToExecute.find_last_of("\\/") + 1);// Strip the directory
cout << "Executing " << PluginToExecute << "...\n" << endl;// Show what we are doing
try // Try to compile the code
{
PluginList[abs(atoi(Args[NArgs-2]))-1](Args[NArgs-1]);// Compile the code
}
catch (Compile_Error CE) // If the code had an error
{
// Cant use SendError() because the string contains the line number
string ErrorFile = CE.File;// Get the name of the plugin to execute
ErrorFile.erase(0, ErrorFile.find_last_of("\\/") + 1);// Strip the directory
cout << "File: " << ErrorFile << "\nLine - " << CE.Line << ": " << CE.Message << endl << endl;// Show the error
if(atoi(Args[NArgs-2])>0) system("pause");// Wait for a response
char Buffer[MAX_PATH];// Holds the name of our executable
GetModuleFileName(NULL,Buffer,MAX_PATH);// Get the directory+Filename of the executable
string AppDir = (Buffer);// Convert it to a string
string::size_type pos2 = AppDir.find_last_of( "\\/" );// Only get the directory
AppDir = AppDir.substr( 0, pos2)+"\\";// Only get the directory
FILE* Errors = fopen((AppDir+"BadCompile.txt").c_str(),"w");// Make the file
fprintf(Errors,"There was a compile error :(");// Output the message
fclose(Errors);// Close the file
exit(1);// Quit the program
}// End of try-catch statement
cout << "Freeing DLLs..." << endl;// Show what we are doing
FreeDLLs();// Free all of the modules
char Buffer[MAX_PATH];// Holds the name of our executable
GetModuleFileName(NULL,Buffer,MAX_PATH);// Get the directory+Filename of the executable
string AppDir = (Buffer);// Convert it to a string
string::size_type pos2 = AppDir.find_last_of( "\\/" );// Only get the directory
AppDir = AppDir.substr( 0, pos2)+"\\BadCompile.txt";// Only get the directory
remove(AppDir.c_str());// Remove the compile error file
system("pause");
return 0;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.