Blang/src/ast/src/main.cpp

100 lines
2.2 KiB
C++
Raw Normal View History

2015-06-30 08:17:40 +02:00
#include <iostream>
2015-07-03 16:58:15 +02:00
#include <string>
2015-06-30 08:17:40 +02:00
#include <vector>
2015-07-03 16:58:15 +02:00
#include <map>
2015-06-30 08:17:40 +02:00
#include <fstream>
2016-04-22 21:46:31 +02:00
#include <getopt.h>
2015-07-03 16:58:15 +02:00
#include <cstdlib>
2015-06-30 08:17:40 +02:00
using namespace std;
2015-07-03 18:31:48 +02:00
string getHelpString(){
2016-04-22 21:46:31 +02:00
return "\nUsage : Blang input-file [OPTION]\n\n"
2015-07-03 18:31:48 +02:00
" -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";
}
2015-07-03 17:56:19 +02:00
string getVersionString(){
2016-04-22 21:46:31 +02:00
string str;
/*
str += "g1m-assembler-mkg1m version ";
str += BLANG_VERSION;
str += " release ";
str += BLANG_RELEASE;
*/
return str;
2015-06-30 08:17:40 +02:00
}
int main(int argc,char *argv[])
{
2015-06-30 17:09:08 +02:00
vector<string> outputFiles;
2015-07-03 16:58:15 +02:00
vector<string> CLibraries;
vector<string> CLibraryDir;
2015-06-30 17:09:08 +02:00
int c;
opterr = 0; // disable getopt error
2016-04-22 21:46:31 +02:00
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 }
};
2016-11-28 07:29:13 +01:00
while ((c = getopt_long(argc, argv, "o:l:L:vh", long_options,&option_index)) != -1){
2015-06-30 17:09:08 +02:00
switch (c){
case 'o':
outputFiles.push_back(optarg); //get output files
break;
2015-07-03 16:58:15 +02:00
case 'l':
CLibraries.push_back(optarg); //get input files
break;
case 'L':
CLibraryDir.push_back(optarg); //get input files
break;
2015-07-03 17:56:19 +02:00
case 'v':
cout << getVersionString();
return 0;
2015-07-03 18:31:48 +02:00
case 'h':
cout << getHelpString();
return 0;
2015-06-30 17:09:08 +02:00
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:
2015-07-03 16:58:15 +02:00
return 1;
2015-06-30 17:09:08 +02:00
}
}
2015-07-03 16:58:15 +02:00
2016-11-28 07:29:13 +01:00
string inputStr;
if(optind < argc) {
string file = argv[optind];
ifstream fileStream(file, std::ios::in);
if(fileStream.is_open()) {
2016-11-28 21:48:15 +01:00
string line;
while(getline(fileStream, line)) {
inputStr += line + "\n";
}
2016-11-28 07:29:13 +01:00
} else {
cerr << "Cannot open file: " << file;
return 1;
}
} else {
cin >> inputStr;
2015-07-03 16:58:15 +02:00
}
2016-11-28 07:29:13 +01:00
// TODO
2015-06-30 08:17:40 +02:00
return 0;
}