Example #1
0
///
/// Parsing function for creation of Indexer object. Takes words from file to index
/// and strips them of punctuation, converts all chars to lower case, then compares
/// with strings in skip file. It will finally store those that apply to these 
/// guidelines, including their page number and line number.
///
void Indexer::parseFile()
{
	std::ifstream inFile;
	std::string inputLine;

	inFile.open(inFileName);
	
	if (!inFile.is_open())
	{
		std::cout << "No index file present with that name." << std::endl;
		system("PAUSE");
		exit(0);

	}

	while (!inFile.eof()) // First loop acquires a line from the text file.
	{
		std::getline(inFile, inputLine);

		std::istringstream stringParse(inputLine);

		incLineNmbr();
		while (!stringParse.eof())	// Inner loop breaks line up into strings.
		{
			std::string token;

			stringParse >> token;
			if (token == "")		// Check for empty strings.
				continue;

			if (token == "<newpage>")
			{
				incPageNmbr();
				lineNmbr = 0;

				break;
			}
			punctStrip(token);		// Call function to remove punctuation

			lowerCase(token);		// Convert to lower case.

			if (!wordsToSkip.skipWordcheck(token))	// Check for string in skipWords.
				continue;

			addToIndex(token);
		}
		
	}

	
}
Example #2
0
int cli(FILE* mainio)
{
	char buf[1024];
	List<Word> *inputData;
	List<Data> memory;
	Tree *my;
	int i = 0;
	while (strcmp(buf,"q\n")){
		my = new Tree;
		
		fprintf(stdout,"#");
		fgets(buf,1023,mainio);
		if (!strcmp(buf,"q\n"))
			continue;
		if (!strncmp(buf,"h\n",2)){
			printHelp(stdout);
			continue;
		}
		if (!strncmp(buf,"mem",3) || buf[4] == '\n' || buf[4] == ' '){
			memOut(stdout,memory);
			continue;
		}
		if (!strncmp(buf,"undef",5)){
			if (buf[5]==' '){
				undefine(buf+5,memory);
				continue;
			}
		}
		if (!strncmp(buf,"undefine",8)){
			if (buf[8]==' '){
				undefine(buf+8,memory);
				continue;
			}
		}
		if (!strncmp(buf,"delete",6)){
			if (buf[6]==' '){
				undefine(buf+6,memory);
				continue;
			}
		}
		if (!strncmp(buf,"del",3)){
			if (buf[3]==' '){
				undefine(buf+3,memory);
				continue;
			}
		}
		if (buf[0]=='\n'){
			fprintf(stdout,"Empty. Type \"h\" for help.\n");
			continue;
		}
		//TODO: Implement all CLI commands
		inputData = stringParse(buf);
		improveInput(*inputData);

		my->AltBuild(inputData->tail);
		Node *p = my->root;
		std::cout << my->getTreeCharArr() << std::endl;
		Number rez;
		rez=my->EvaluteTree(memory);
		char out[100]("") ;
		strcpy(out, rez.getNumberString());
		std::cout  << out<<std::endl;
		delete inputData;
	}
	return 0;
}
Example #3
0
void commandLine(){
	inputKey = 0;
	exit = 0;
	temp = 0;
	counter = 0;

	vgaSetup(3);
	vgaSetPos(0,0);
	vgaPrintString( getOSVersion() );

	while( 1 ){
		exit = 0;
		counter = 0;
		vgaPrintString( "BuenOS >" );//prompt input

		while( ( exit == 0 && inputKey == 0 ) || exit == 0 ){//fill input buffer
			inputKey = getKey();

			if( isInput( inputKey ) ){
				if( inputKey == 27 ){//esc
					cursorPos = vgaGetPos();
					vgaSetPos( ( cursorPos->x - counter ), cursorPos->y );
					for( temp = 0; temp < counter; temp++){
						vgaPrint( ' ' );
					}
					vgaSetPos( ( cursorPos->x - counter ), cursorPos->y );
					counter = 0;
					inputBuffer[counter] = 0;
				}
				else if( inputKey == 13 ){//enter
					exit = 1;//finish buffer loop
					inputBuffer[counter] = 0;//null terminate string
					while( counter < sizeOfBuffer ){//null out remaining buffer
						inputBuffer[counter] = 0;
						counter++;
					}
					vgaPrintString( "\r\n" );
				}

				else if( inputKey == 8 ){//backspace
					if( counter != 0 ){
						vgaPrintString( "\b \b" );
						counter--;
						inputBuffer[counter] = 0;
					}
				}
				else if( counter != sizeOfBuffer ){
					vgaPrint( inputKey );
					inputBuffer[counter] = inputKey;
					counter++;
				}
			}
		}
		stringCopy( inputBuffer, tempBuffer );
		stringParseInfo = stringParse( tempBuffer );
		stringParseInfo->argc++;
		stringUppercase( stringParseInfo->argv[0] );

		if( stringLength( stringParseInfo->argv[0] ) != 0 ){
			if( stringEqual( stringParseInfo->argv[0], "HELP" ) )  vgaPrintString( helpString );
			else if( stringEqual( stringParseInfo->argv[0], "CLEAR" ) )  vgaSetup( 3 );
			else if( stringEqual( stringParseInfo->argv[0], "VERSION" ) )  vgaPrintString( getOSVersion() );
			else if( stringEqual( stringParseInfo->argv[0], "ECHO" ) ) {
				stringStrip( stringParseInfo->argv[1], '"' );
				vgaPrintString( stringParseInfo->argv[1] );
				vgaPrintString( "\r\n" );
			}
			else if( stringEqual( stringParseInfo->argv[0], "DIR" ) ){
				getFileList( tempBuffer );
				stringFindAndReplace( tempBuffer, ',', ' ' );
				stringParseInfo = stringParse( tempBuffer );
				temp = 0;
				while( temp <= stringParseInfo->argc ){
					vgaPrintString( stringParseInfo->argv[temp] );
					cursorPos = vgaGetPos();
					vgaSetPos( 12, cursorPos->y );
					vgaPrintString( intToString( getFileSize( stringParseInfo->argv[temp] ) ) );
					vgaPrintString( " bytes\r\n" );
					temp++;
				}
			}
			else if( stringEqual( stringParseInfo->argv[0], "SIZEOF" ) ){
				vgaPrintString( intToString( getFileSize( stringParseInfo->argv[1] ) ) );
				vgaPrintString( " bytes\r\n" );
			}
			else if( stringEqual( stringParseInfo->argv[0], "RENAME" ) ){
				stringUppercase( stringParseInfo->argv[1] );
				stringUppercase( stringParseInfo->argv[2] );
				if( fileExists( stringParseInfo->argv[1] ) && stringLength( stringParseInfo->argv[1] ) != 0 && stringLength( stringParseInfo->argv[2] ) != 0 ){
					if( stringEqual( stringParseInfo->argv[1], "KERNEL.BIN" ) ) vgaPrintString( "Nice try.\r\n" );
					else if( fileExists( stringParseInfo->argv[2] ) || renameFile( stringParseInfo->argv[1], stringParseInfo->argv[2] ) ){
						vgaPrintString( "File " );
						vgaPrintString( stringParseInfo->argv[1] );
						vgaPrintString( " could not be renamed to " );
						vgaPrintString( stringParseInfo->argv[2] );
						vgaPrintString( "\r\n" );
					}
					else{
						vgaPrintString( "File " );
						vgaPrintString( stringParseInfo->argv[1] );
						vgaPrintString( " successfully renamed to " );
						vgaPrintString( stringParseInfo->argv[2] );
						vgaPrintString( "\r\n" );
					}
				}
				else{
					vgaPrintString( "File " );
					vgaPrintString( stringParseInfo->argv[1] );
					vgaPrintString( " cannot be found.\r\n" );
				}
			}
			else if( stringEqual( stringParseInfo->argv[0], "DELETE" ) ){
				stringUppercase( stringParseInfo->argv[1] );
				if( fileExists( stringParseInfo->argv[1] ) && stringLength( stringParseInfo->argv[1] ) != 0 ){
					if( stringEqual( stringParseInfo->argv[1], "KERNEL.BIN" ) != 1 ){
						if( removeFile( stringParseInfo->argv[1] ) ){
							vgaPrintString( "File " );
							vgaPrintString( stringParseInfo->argv[1] );
							vgaPrintString( " could not be deleted\r\n" );
						}
						else{
							vgaPrintString( "File " );
							vgaPrintString( stringParseInfo->argv[1] );
							vgaPrintString( " successfully deleted\r\n" );
						}
					}
					else vgaPrintString( "OMG just stop it. I NEED THAT!\r\n\nIT'S NOT FUNNY! ARGH!\r\n\n\n" );
				}
			}
			else if( stringEqual( stringParseInfo->argv[0], "SHUTDOWN" ) )  shutdown();
			else if( stringEqual( stringParseInfo->argv[0], "RESTART" ) )  restart();
			else runApplication( stringParseInfo );
		}
	}
}