sillyql / silly.cpp
silly.cpp
Raw
// Project Identifier: C0F4DFE8B340D81183C208F70F9D2D797908754D
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <getopt.h>
#include <sstream>
#include <unistd.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include "functions.h"

using namespace std;

int main(int argc, char** argv){
    ios_base::sync_with_stdio(false); // you should already have this
    cin >> std::boolalpha;  // add these two lines
    cout << std::boolalpha; 

    // SET PROGRAM
    // process command line
    Silly silly;
    process_cmd_line(argc, argv, silly);
    // create table map
    unordered_map<string, Table> table_map;

    //initialize strings
    string cmd = "";
    string junk = "";
    string argument = "";
    char command = ' ';
    cout << "% ";
    while(cin >> cmd){
        if (cin.fail()) {
            cerr << "Error: Reading from cin has failed" << endl;
            cin.clear();
            exit(1);
        }

        command = set_command(cmd);

        switch(command){
            case 'c':
                create_table(argument, table_map);
                break;
            case 'i':
                insert_into(argument, table_map);
                break;
            //delete from
            case 'd':
                delete_rows(argument, table_map);
                break;
            //generate index
            case 'g':
                generate_index(argument, table_map);
                break;
            //print
            case 'p':
                print_rows(argument, table_map, silly);
                break;
            //join
            case 'j':
                join_tables(argument, table_map, silly);
                break;
            //remove
            case 'r':
                remove_table(argument, table_map);
                break;
            //comment
            case 'y': 
                cin.ignore(256, '\n');
                break;
            case 'q':
                cout << "Thanks for being silly!\n";
                table_map.clear();
                cin.clear();
                return 0;
            case 'z':
                cout << "Error: unrecognized command\n";
                cin.ignore(256, '\n');
            default:
                break;
        }
    cout << "% ";
    }
    return 0;
}