94 lines
2.2 KiB
C++
94 lines
2.2 KiB
C++
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <fstream>
|
|
#include <getopt.h>
|
|
#include <cstdlib>
|
|
|
|
using namespace std;
|
|
|
|
string getHelpString(){
|
|
return "\nUsage : Blang input-file [OPTION]\n\n"
|
|
" -o output\t\tWrite output to file.\n"
|
|
" -l lib\t\tSearch the library named library.\n"
|
|
" -L dir\t\tadd all the libraries in the folder dir.\n"
|
|
" -v\t\t\tShow version then exit\n"
|
|
" -h\t\t\tShow help then exit\n";
|
|
}
|
|
|
|
string getVersionString(){
|
|
string str;
|
|
/*
|
|
str += "g1m-assembler-mkg1m version ";
|
|
str += BLANG_VERSION;
|
|
str += " release ";
|
|
str += BLANG_RELEASE;
|
|
*/
|
|
return str;
|
|
}
|
|
|
|
int main(int argc,char *argv[])
|
|
{
|
|
vector<string> outputFiles;
|
|
vector<string> inputFiles;
|
|
vector<string> CLibraries;
|
|
vector<string> CLibraryDir;
|
|
|
|
int c;
|
|
opterr = 0; // disable getopt error
|
|
|
|
int option_index = 0;
|
|
static struct option long_options[] = {
|
|
{"version", no_argument, 0, 'v' },
|
|
{"help", no_argument, 0, 'h' },
|
|
{"input", required_argument, 0, 'i' },
|
|
{"output", required_argument, 0, 'o' },
|
|
{0, 0, 0, 0 }
|
|
};
|
|
|
|
while ((c = getopt_long(argc, argv, "o:i:l:L:vh", long_options,&option_index)) != -1){
|
|
switch (c){
|
|
case 'o':
|
|
outputFiles.push_back(optarg); //get output files
|
|
break;
|
|
case 'i':
|
|
inputFiles.push_back(optarg); //get input files
|
|
break;
|
|
case 'l':
|
|
CLibraries.push_back(optarg); //get input files
|
|
break;
|
|
case 'L':
|
|
CLibraryDir.push_back(optarg); //get input files
|
|
break;
|
|
case 'v':
|
|
cout << getVersionString();
|
|
return 0;
|
|
case 'h':
|
|
cout << getHelpString();
|
|
return 0;
|
|
case '?':
|
|
if (optopt == 'o')
|
|
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
|
|
else if (isprint (optopt))
|
|
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
|
|
else
|
|
fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
|
|
return 1;
|
|
default:
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
//get input files
|
|
for (int index = optind; index < argc; index++)
|
|
inputFiles.push_back(argv[index]);
|
|
|
|
if(inputFiles.empty()){
|
|
fprintf (stderr, "No input file\n");
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|