97 lines
2.1 KiB
C++
97 lines
2.1 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> 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' },
|
|
{"output", required_argument, 0, 'o' },
|
|
{0, 0, 0, 0 }
|
|
};
|
|
|
|
while ((c = getopt_long(argc, argv, "o:l:L:vh", long_options,&option_index)) != -1){
|
|
switch (c){
|
|
case 'o':
|
|
outputFiles.push_back(optarg); //get output 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;
|
|
}
|
|
}
|
|
|
|
string inputStr;
|
|
|
|
if(optind < argc) {
|
|
string file = argv[optind];
|
|
ifstream fileStream(file, std::ios::in);
|
|
if(fileStream.is_open()) {
|
|
// TODO
|
|
} else {
|
|
cerr << "Cannot open file: " << file;
|
|
return 1;
|
|
}
|
|
} else {
|
|
cin >> inputStr;
|
|
}
|
|
|
|
// TODO
|
|
|
|
return 0;
|
|
}
|