From 227247e6ef218e57127db9f08079e8c7ac2fe7d2 Mon Sep 17 00:00:00 2001
From: Ryan Alexander Rice-Smith <rricesmi@uci.edu>
Date: Wed, 5 Feb 2020 06:02:41 +0000
Subject: [PATCH] Replace main.cxx

---
 .../GeoModel/FaserGeoEditor/src/main.cxx      | 87 ++++++++++++++++++-
 1 file changed, 86 insertions(+), 1 deletion(-)

diff --git a/DetectorDescription/GeoModel/FaserGeoEditor/src/main.cxx b/DetectorDescription/GeoModel/FaserGeoEditor/src/main.cxx
index d9ee9d7a..fbb224a7 100644
--- a/DetectorDescription/GeoModel/FaserGeoEditor/src/main.cxx
+++ b/DetectorDescription/GeoModel/FaserGeoEditor/src/main.cxx
@@ -1,14 +1,48 @@
 // main.cpp
 #include "FaserGeoEditorApp.h"
+#include <iostream>
 // #include <QTableView>
 // #include <QStringList>
 // #include <QSqlDatabase>
 // #include <iostream>
 // #include "mymodel.h"
+//#include <string.h>
+//#include <sqlite3.h>
+//#include <fstream>
+
+//string textToBinary(string textFileName, string binFileName = std::string(""));
 
 int main(int argc, char *argv[])
 {
-    FaserGeoEditorApp a(argc, argv);
+    if(argc != 3)
+    {
+        std::cout<<"Error: Require two command line inputs only, first path to application, second path to database, third to indicate binary vs text file\n";
+        std::cout<<"Example: bin/FaserGeoEditor data/geomDB_sqlite t\n";
+        return 0;
+    }
+    string type;
+    string fileName;
+    if( strcmp(argv[2], "t") || strcmp(argv[2], "T"))
+    {
+        type = "t";
+//        fileName = textToBinary(argv[1]);
+    }
+    else if( strcmp(argv[2], "b") || strcmp(argv[2], "B"))
+    {
+        type = "b";
+    }
+    else    
+    {
+        std::cout<<argv[2]<<endl;
+        std::cout<<"Error: third argument incorrectly indicating if file is text or binary; only use t or b to indicate\n";
+        return 0;
+    }
+    char *reducedArgv[2];
+    reducedArgv[0] = argv[0];
+    reducedArgv[1] = argv[1];
+    argc = 2;
+    
+    FaserGeoEditorApp a(argc, reducedArgv, type);
     // QApplication a(argc, argv);
 
     // QTableView tableView;
@@ -19,3 +53,54 @@ int main(int argc, char *argv[])
     // w.show();
     return a.exec();
 }
+/*
+string textToBinary(string textFileName, string binFileName)
+{
+	int rc;
+	char *zErrMsg;
+    sqlite3 *database;
+
+	string sqlFileName = textFileName;
+    sqlFileName.append("sql");
+	string sqlToRun;
+	string singlestring;
+
+	rc = sqlite3_open((sqlFileName).c_str(), &database);
+	if(rc)
+	{
+		cout<<"Failed to open file\n\n";
+        return nullptr;
+	}
+	else
+	{
+		cout<<"File opened\n\n";
+	}
+	
+	cout<<"Enter name of sql file:";
+	cin>>textFileName;
+	ifstream openedFile;
+	openedFile.open(textFileName.c_str());
+
+	while(!openedFile.eof())
+	{
+		sqlToRun.clear();
+		singlestring = "a";
+		while(!openedFile.eof() && *singlestring.rbegin() != ';')
+		{
+			singlestring.clear();
+			getline(openedFile, singlestring);
+			sqlToRun = sqlToRun + singlestring;
+		}
+		rc = sqlite3_exec(database, sqlToRun.c_str(), NULL, 0, &zErrMsg);
+		if( rc!=SQLITE_OK)
+		{
+			cout<<zErrMsg;
+			cout<<"\n";
+			sqlite3_free(zErrMsg);
+		}
+		
+	}
+	cout<<"SQL commands run successfully!\n\n";
+
+	return sqlFileName;
+}*/
-- 
GitLab