Example #1
0
void ConsoleUI::add_computer()
{
    Computer c = Computer();
    string name_, type_, yearBuilt_, wasBuilt_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Name of Computer:" << endl;
    cout << endl << " -> ";
    cin >> name_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Type of Computer:" << endl;
    cout << endl << " -> ";
    cin >> type_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "When was the computer built? [YYYY]" << endl;
    cout << endl << " -> ";
    cin >> yearBuilt_;
    while (!is_digits(yearBuilt_))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "When was the computer built? [YYYY]" << endl;
        cin >> yearBuilt_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Was the computer built? [Y/N]" << endl;
    cout << endl << " -> ";
    cin >> wasBuilt_;
    while ((wasBuilt_ != "Y") && (wasBuilt_ != "N") && (wasBuilt_ != "y") && (wasBuilt_ != "n"))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;
        cout << "Invalid input! Please try again:" << endl;
        cout << "Was the computer built? [Y/N]" << endl;
        cout << endl << " -> ";
        cin >> wasBuilt_;
    }
    if ((wasBuilt_ == "Y") || (wasBuilt_ == "y"))
    {
        c.set_wasBuilt("Yes");
    }
    else if ((wasBuilt_ == "N") || (wasBuilt_ == "n"))
    {
        c.set_wasBuilt("No");
    }
    fix_string(name_);
    fix_string(type_);
    c.set_name(name_);
    c.set_type(type_);
    c.set_yearBuilt(yearBuilt_);
    dbService.addC(c);
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "\t\t     " << "Computer has been added to the list! \n\n\n\n\n\n\n" << endl;
}
Example #2
0
void ConsoleUI::connect_something()
{
    clear_screen();
    print_allscientists();
    int sci_id;
    string sci_id_str;
    cout << endl << "Insert ID of Scientist that you want to connect:" << endl;
    cout << endl << " -> ";
    cin >> sci_id_str;
    while (!is_digits(sci_id_str))
    {
        cout << "Not a valid input! Please try again:" << endl;
        cout << endl << "Insert ID of Scientist that you want to connect:" << endl;
        cout << endl << " -> ";
        cin >> sci_id_str;
    }
    sci_id = atoi(sci_id_str.c_str());
    clear_screen();
    print_allcomputers();
    cout << endl << "Insert ID of Computer that you want to connect:" << endl;
    cout << endl << " -> ";
    int comp_id;
    string comp_id_str;
    cin >> comp_id_str;
    while (!is_digits(comp_id_str))
    {
        cout << "Not a valid input! Please try again:" << endl;
        cout << endl << "Insert ID of Computer that you want to connect:" << endl;
        cout << endl << " -> ";
        cin >> comp_id_str;
    }
    comp_id = atoi(comp_id_str.c_str());
    dbService.addID(sci_id,comp_id);
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "\t\t     " << "The connection has been added to the list! \n\n\n\n\n" << endl;
}
Example #3
0
bool Station::setStationCode(string new_stationCode) {
    
    // station code must be 3 captital letters or 5 numeric characters
    if (new_stationCode.length() == 5 && is_digits(new_stationCode)) {
        stationCode = new_stationCode;
        return true;
    }

    if (new_stationCode.length() == 3) {
        if (isupper(new_stationCode[0]) && isupper(new_stationCode[1]) && isupper(new_stationCode[2])) {
            stationCode = new_stationCode;
            return true;
        }
    }

    return false;

}
Example #4
0
//filter definition: [<virtual host id>],<shared library name>[,<filter factory function>]
int  parse_filter_definition( char *arg, size_t *vhost_id, char **lib_name, char **fact_function)
{
  char *tok[3];
  int i;

  for(i = 0; i < 3 ; i++ ) {
    tok[i] = 0;
  }

  for(i = 0; i < 3 ; i++ ) {
    tok[i] = strtok( i == 0 ? strdup(arg) : 0, ",");
    if (tok[i] == 0) {
      break;
    }
  }

  if (i == 3) {
   *vhost_id = atoi( tok[0] );
   *lib_name = strdup( tok[1] );
   *fact_function = strdup(tok[2]);
   return 0;
  }

  if (i == 2) {
    i = 0;
    if (is_digits( tok[0] ) ) {
      *vhost_id = atoi( tok[0] );
      i = 1;
    } else {
     *vhost_id = -1;
    }

    *lib_name = strdup( tok[ i ] );
    i += 1;

    if (tok[i] != 0) {
      *fact_function = strdup( tok[ i ] );
    } else {
      *fact_function = "load_filter";
    }
  }
  return 0;
}
Example #5
0
/* 
Pattern:
   1 [VRICLD]<uint>
   2 <uint>
   3 <float>
*/
int token_check( char *token, int pattern ) {
	int status = 0;
	char c;

	switch (pattern) {
		case 1:
			c = *token++;
			if (is_elem( c ) && is_end(is_uint( token )))
				status = 1;
			break;

		case 2:
			if (is_end(is_uint( token )))
				status = 1;
			break;

		case 3:
			if (is_end(is_digits(is_char_eq(is_int( token ), '.'))))
				status = 1;
			break;
	}
	return status;
}
Example #6
0
int main (int argc, char* argv[])
{
	int option_index = 0;
	BGPDATA BGP;
	Initialize(BGP);
	int help = 0;
	while (1) {
                static struct option long_options[] = {
			{"verbose", no_argument, &BGP.verbose, 1},
			{"or", no_argument, &BGP.or_flag, 1},
			{"help", no_argument, &help, 1},
                        {"cidrfile",required_argument,0, 'a'},
                        {"update",required_argument,0, 'b'},
                        {"dir",required_argument,0, 'c'},
			{"startdate",required_argument,0,'d'},
			{"enddate",required_argument,0,'e'},
			{"asnfile",required_argument,0,'f'},
			{"outfile",required_argument,0,'g'},
			{"file",required_argument,0,'h'},
                        {0, 0, 0, 0}
                };
                int c = getopt_long(argc, argv, "", long_options,&option_index);
                if (c == -1) break;
                switch(c) {
			case 0:
				break;
			case 'a':
				BGP.setfile = optarg;
				break;
			case 'b':
				BGP.bgpfile.push_back(optarg);
				break;
			case 'c':
				BGP.dir.push_back(optarg);
				break;
			case 'd':
				BGP.startdate = optarg;
				break;
			case 'e':
				BGP.enddate = optarg;
				break;
			case 'f':
				BGP.asnfile = optarg;
				break;
			case 'g':
				BGP.outfile = optarg;
				break;
			case 'h':
				BGP.file = optarg;
				break;
			default :
				print_help();
				exit(1);
		}
	}
	if (help) { 
		print_help();
		exit(1);
	}

	std::ofstream myFile;

	if(!BGP.outfile.empty()) {
		myFile.open(BGP.outfile.c_str(), std::ios::out);
	}

	std::ofstream &outFile = (BGP.outfile.empty() ? (std::ofstream&)cout : myFile);

	if (!BGP.setfile.empty()) {
		skipset_t *ipset = NULL;
		ReadFile(BGP.setfile,&ipset);
		BGP.ipset = ipset;
	}
	if (!BGP.asnfile.empty()) {
		ReadASNFile(BGP);
	}
	if (BGP.bgpfile.size() > 0) {
		vector<string>::iterator it;
		for (it = BGP.bgpfile.begin(); it != BGP.bgpfile.end(); it++) {
			ReadBGPFile(BGP,*it,outFile);
		}
		if (!BGP.outfile.empty()) {
			outFile.close();
		}
		exit(1);
	}
	if (!BGP.file.empty()) {
		ProcessFiles(BGP,outFile);
		exit(1);
	}
	if (BGP.startdate.empty() || BGP.enddate.empty() || BGP.dir.empty()) {
		print_help();
		exit(1);
	}

	if (BGP.startdate.length() != 8 || BGP.enddate.length() != 8) {
		cout << "The date format is YYYYMMDD and should be of length 8\n";
		exit(1);
	}
	if (!is_digits(BGP.startdate) || !is_digits(BGP.enddate)) {
		cout << "The date format is YYYYMMDD and should be all integers\n";
		exit(1);
	}
	if (BGP.startdate > BGP.enddate) {
		cout << "Start date must come before end date.\n";
		print_help();
		exit(1);
	}
	Traverse(BGP,BGP.startdate,outFile);
	if (BGP.enddate.compare(BGP.startdate) == 0) { exit(1); }
	string nextdate = NextDate(BGP.startdate);
	while (nextdate.compare(BGP.enddate) != 0) {
		Traverse(BGP,nextdate,outFile);
		nextdate = NextDate(nextdate);
	}
	Traverse(BGP,BGP.enddate,outFile);
	if (!BGP.outfile.empty()) {
		outFile.close();
	}

}
Example #7
0
void ConsoleUI::add_scientist()
{
    Scientist s = Scientist();
    string firstname_, lastname_, gender_, birth_, death_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Name of Scientist: [FirstName LastName]" << endl;
    cout << endl << " -> ";
    cin >> firstname_ >> lastname_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Gender of scientist: \n(1) male \n(2) female" << endl;
    cout << endl << " -> ";
    cin >> gender_;
    while ((gender_ != "1") && (gender_ != "2"))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "Gender of scientist: \n(1) male \n(2) female" << endl;
        cout << endl << " -> ";
        cin >> gender_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Birth year of scientist:" << endl;
    cout << endl << " -> ";
    cin >> birth_;
    while (!is_digits(birth_))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "Birth year of scientist:" << endl;
        cout << endl << " -> ";
        cin >> birth_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Scientist's Year of death: " << endl;
    cout << endl << " -> ";
    cin >> death_;
    while (!is_digits(death_) || (atoi(death_.c_str()) < atoi(birth_.c_str())))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        if (!is_digits(death_))
        {
            cout << "Invalid input! Please try again:" << endl;
        }
        else if (atoi(death_.c_str()) < atoi(birth_.c_str()))
        {
            cout << "Year of death should be AFTER year of birth! Please ry again:" << endl;
        }
        cout << "Scientist's Year of death:" << endl;
        cout << endl << " -> ";
        cin >> death_;
    }
    if (gender_ == "1")
    {
        s.set_gender("Male");
    }
    else if (gender_ == "2")
    {
        s.set_gender("Female");
    }
    fix_string(firstname_);
    fix_string(lastname_);
    s.set_firstname(firstname_);
    s.set_lastname(lastname_);
    s.set_birth(birth_);
    s.set_death(death_);
    dbService.addS(s);
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "\t\t     " << "Scientist has been added to the list!\n\n\n\n\n\n\n" << endl;
}