void StaffList::mainScreen() {
	//readFile(input_text_file, usth_staff_list, stu_list_size);
	//StaffList l("USTH_staff_list.txt");
	for(;;) {
		cout << endl << endl;
		cout << "USTHStaffManager v7.0" << endl;
		cout << "1. Search." << endl;
		cout << "2. Change staff member info." << endl;
	  cout << "3. Remove staff member." << endl;
	  cout << "4. Add a staff member." << endl;
	  cout << "0. Back." << endl;
	  
	  cout << "What do you want to do, choose one option: ";
	  
	  // Verify a command if it is integer and belong to {0..4}
	  int command;  
		while (true) {
			cin >> command;
			if (cin && (command < 5) && (command > -1)) break;
			cout << "Invalid command!" << endl;
			cin.clear();
			cin.ignore(256,'\n');
		} 
		//////////////////////////////////////////////////////////
		
	  switch (command) {
	  	case 1: mainSearch();
	  					break;
	  					//mainScreen();
	  	case 2: mainChangeStaffInfo();
	  					//mainScreen();
	  					break;
	  	case 3: mainRemoveStaff();
	  					//mainScreen();
	  					break;
	  	case 4: mainAddStaff();
	  					//mainScreen(); 					
	  					break;
	  	case 0: return;
	  	default: 
	  		cout << "Invalid command!" << endl;
	  		mainScreen();
	  		
	  }
	}
}
void LecturerList::mainScreen() {
	//readFile(input_text_file, usth_lecturer_list, stu_list_size);
	//LecturerList l("USTH_lecturer_list.txt");
	for(;;) {
		cout << endl << endl;
		cout << "USTHLecturerManager v6.0" << endl;
		cout << "1. Search." << endl;
		cout << "2. Change lecturer info." << endl;
	  cout << "3. Remove lecturer." << endl;
	  cout << "4. Add a lecturer." << endl;
	  cout << "0. Back." << endl;
	  
	  cout << "Enter a number: ";
	  
	  // Verify a command if it is integer and belong to {0..4}
	  int command;  
		while (true) {
			cin >> command;
			if (cin && (command < 5) && (command > -1)) break;
			cout << "Invalid command!" << endl;
			cin.clear();
			cin.ignore(256,'\n');
		} 
		//////////////////////////////////////////////////////////
		
	  switch (command) {
	  	case 1: mainSearch();
	  					break;
	  					//mainScreen();
	  	case 2: mainChangeLecturerInfo();
	  					//mainScreen();
	  					break;
	  	case 3: mainRemoveLecturer();
	  					//mainScreen();
	  					break;
	  	case 4: mainAddLecturer();
	  					//mainScreen(); 					
	  					break;
	  	case 0: return;
	  	default: 
	  		cout << "Invalid command!" << endl;
	  		mainScreen();
	  		
	  }
	}
}
//"Remove student" main screen for users
//Display lines:
//1. Search.
//2. Remove student by Id.
//0. Back.
//Enter a number:
////////////////////
//When user input, do the respective functions:
//'1': mainSearch()
//'2': removeStudent()
//'0': return;
//Otherwise: print "Invalid command", ask for other input.
void mainRemoveStudent() {
	for(;;) {
		cout << endl << endl;
		cout << "Remove a student: " << endl;
		cout << "1. Search." << endl;
		cout << "2. Remove student by ID." << endl;		
	  cout << "0. Back." << endl;
	  
	  cout << "Enter a number: ";
	  
	  // Verify a command if it is integer and belong to {0..2}
	  int command;  
		while (true) {
			cin >> command;
			if (cin && (command < 3) && (command > -1)) break;
			cout << "Invalid command!" << endl;
			cin.clear();
			cin.ignore(256,'\n');
		} 
		//////////////////////////////////////////////////////////
		
	  switch (command) {
	  	case 1: mainSearch();
	  					break;
	  					//mainScreen();
	  	case 2: removeStudent(usth_student_list, stu_list_size);
	  					//mainScreen();
	  					break;	  	
	  	case 0: return;
	  	default: 
	  		cout << "Invalid command!" << endl;
	  		break;
	  		
	  }		
	}
}
//"Add Staff" main screen for users
//Display lines:
//1. Search.
//2. Enter staff member info.
//0. Back.
//Enter a number:
////////////////////
//When user input, do the respective functions:
//'1': mainSearch()
//'2': createStaff()
//'0': return;
//Otherwise: print "Invalid command", ask for other input.
void StaffList::mainAddStaff() {
	for (;;) {	
		cout << endl << endl;
		cout << "Add a staff member: " << endl;
		cout << "1. Search." << endl;
		cout << "2. Enter staff member info." << endl;
	  cout << "0. Back." << endl;
	  
	  cout << "What do you want to do, choose one option: ";
	  
	  // Verify a command if it is integer and belong to {0..3}
	  int command;  
		while (true) {
			cin >> command;
			if (cin && (command < 4) && (command > -1)) break;
			cout << "Invalid command!" << endl;
			cin.clear();
			cin.ignore(256,'\n');
		} 
		//////////////////////////////////////////////////////////
		
	  switch (command) {
	  	case 1: mainSearch();
	  					break;
	  					//mainAddStaff();
	  	case 2: createStaff();
	  					break;
	  					//mainAddStaff();
	  	case 0: return;
	  	default: 
	  		cout << "Invalid command!" << endl;
	  		break;
	  		
	  }
	}
}
Beispiel #5
0
Datei: fex.cpp Projekt: Flawe/fex
void main(int argc, const char* argv[])
{
	if (argc == 1)
	{
		ShowHelp();
		return;
	}

	// parse arguments
	int i;
	for (i = 1; i < argc - 1; ++i)
	{
		if (argv[i][0] != '-' || strlen(argv[i]) != 2)
		{
			ShowHelp();
			return;
		}

		switch (argv[i][1])
		{
		case 'e':
			i++;
			ParseFilters(argv[i]);
			break;
		case 'd':
			i++;
			AddDirectory(argv[i]);
			break;
		case 'r':
			recursive = true;
			break;
		case 'c':
			cache = true;
			break;
		case 'C':
			recache = true;
			break;
		}
	}

	if (filters.size() == 0)
	{
		printf("fex: no file extensions specified\n");
		return;
	}

	if (folders.size() == 0)
	{
		printf("fex: no directories specified\n");
		return;
	}

	if (i == argc)
	{
		printf("fex: no search pattern specified\n");
		return;
	}

	//LARGE_INTEGER start1, stop1, start2, stop2;
	//QueryPerformanceCounter(&start1);

	// build our data
	BuildPackage();

	//QueryPerformanceCounter(&stop1);

	if (megaBuffer)
	{
		//QueryPerformanceCounter(&start2);

		RE2 mainSearch(argv[argc - 1]);
		RE2 newLineSearch("\n");

		re2::StringPiece newLineString;
		re2::StringPiece megaString(megaBuffer, megaBufferSize);
		int num = 0;
		int lastFound = 0;
		const char* lastNewLine = NULL;
		int lastNumNewLines = 0;
		while (RE2::FindAndConsume(&megaString, mainSearch))
		{
			// identify which file the search hit was in
			for (unsigned int i = lastFound; i < numBufferFiles; ++i)
			{
				if (megaString.data() <= megaBuffer + bufferFiles[i].ptrOffset)
				{
					// do a regexp search to find all newlines for this file up to the point of the hit
					// if previous search had a hit on the same file, use the cached numNewLines and ptr so
					// we don't have to search through entire file again
					const char* beg = NULL;
					int numNewLines = 0;
					if (i == lastFound && lastNewLine != NULL)
					{
						beg = lastNewLine;
						numNewLines += lastNumNewLines;
					}
					else
					{
						beg = i == 0 ? megaBuffer : megaBuffer + bufferFiles[i - 1].ptrOffset;
					}

					const char* end = megaString.data();
					newLineString.set(beg, end - beg);
					
					int lastConsumed = 0;
					int consumed = 0;
					while (consumed = RE2::FindAndConsume(&newLineString, newLineSearch))
					{
						lastConsumed = consumed;
						numNewLines++;
					}
					lastNumNewLines = numNewLines;
					lastNewLine = newLineString.data();

					// copy DISPLAY_LINE_LENGTH characters to a separate buffer so we can use it as a marker for the match
					// break on newline
					for (int c = 0; c < DISPLAY_LINE_LENGTH; ++c)
					{
						if (lastNewLine[c] != '\n')
						{
							displayLine[c] = lastNewLine[c];
						}
						else
						{
							displayLine[c] = '\0';
							break;
						}
					}
					printf("%s:%d:%s\n", bufferFiles[i].name, numNewLines + 1, displayLine);
					lastFound = i;
					break;
				}
			}
			num++;
		}

		//QueryPerformanceCounter(&stop2);
		//printf("fex: data accumulation done in: %.2f seconds, %d files searched\n", (stop1.QuadPart - start1.QuadPart) / 1000000.f, numBufferFiles);
		//printf("fex: regexp match done in: %.2f seconds, found %d instances\n", (stop2.QuadPart - start2.QuadPart) / 1000000.f, num);
	}

	CleanUp();
}