Exemplo n.º 1
0
		bool mofile_read_strings_array(util::buffer_reader& reader, uint32_t number_of_strings, uint32_t offset, boost::string_ref* result)
		{
			reader.seek(offset, std::ios::beg);

			std::dynarray<uint32_t> strings_lengths(number_of_strings);

			uint32_t first_offset = 0;
			uint32_t last_offset  = 0;
			for (uint32_t i = 0; i < number_of_strings; i++)
			{
				uint32_t current_length = reader.read<uint32_t>();
				uint32_t current_offset = reader.read<uint32_t>();

				strings_lengths[i] = current_length;

				if (i == 0)
				{
					first_offset = current_offset;
				}

				if (i == (number_of_strings - 1))
				{
					last_offset = current_offset;
				}
			}

			uint32_t string_array_size = last_offset + strings_lengths.back() + 1 - first_offset;
			if (string_array_size == 0)
			{
				return false;
			}

			reader.seek(first_offset, std::ios::beg);

			boost::string_ref string_array(reader.reads_ptr(string_array_size), string_array_size);

			boost::string_ref::iterator iter = string_array.begin();
			for (uint32_t i = 0; i < number_of_strings; i++)
			{
				size_t len = strings_lengths[i] + 1;
				result[i] = boost::string_ref(iter, len);
				iter += len;
			}

			return true;
		}
Exemplo n.º 2
0
int main(void)
{	
	// Create Floppy element
        floppy newfloppy;
        floppy *myfloppy = &newfloppy;

	unsigned short mounted = 0;
	while(1)
	{
		char current_directory[150] = "/";
		// Create a buffer and take input from the command line
		char *buff = NULL;
		buff = takeinfo("prompt: ");
		
		// Create a String array and parse the buff into it
		char **buff_parsed;
		buff_parsed = string_array(buff);
		int n_words = count_words(buff);
		printf("n_words %i\n", n_words);//debug
		// If an empty command line is entered
		if(n_words < 1)
		{
			continue;
		}
		
		//-----------------------------------------------------------------------------------------		
		
		// Run the comands.
		// Check to see if the comand is quit
		if(!strcmp(buff_parsed[0], "quit"))
		{
				exit(1);
		}
		else if(!strcmp(buff_parsed[0], "help"))
		{
			help();
		}
		// Execute comands	
		else if(!strcmp(buff_parsed[0], "clear"))
		{
			if(fork() == 0)
			{
				char *args[2] = { "clear", NULL};
				execv("/usr/bin/clear", args);
				exit(1);
			}
			else
			{
				wait(NULL);
			}
		}
		else if(!strcmp(buff_parsed[0], "fmount"))
		{	
			char temp[strlen(buff_parsed[1]) + 2];
			memcpy(temp,"./", 2);
			
			memcpy(temp, buff_parsed[1], strlen(buff_parsed[1]));
			if( access( buff_parsed[1], F_OK ) != -1 ) 
			{
				fprintf(stderr,"Floppy succesfully mounted\n");
				mount(myfloppy, buff_parsed[1]);
				mounted = 1;
			}
			else 
			{
				//file doesn't exist
				fprintf(stderr,"File/Floppy can't be found\n");
			}
			
		}
		else if(!strcmp(buff_parsed[0], "fumount"))
		{
			if(mounted == 0)
				printf("There's nothing to unmount\n");
			else
			{
				mounted = 0;
				myfloppy = NULL;
				fprintf(stderr,"Unmount succesfull\n");
			}
		}
		else if(!strcmp(buff_parsed[0], "traverse"))
		{
			if(n_words > 1)
			{	// if the -l flag is used print with additional info
				if(!strcmp(buff_parsed[1], "-l"))
				{
					traverse(myfloppy, 19, 1, current_directory);
				}
				else
					fprintf(stderr, "flag doesn't exist");
			}else
			{
				traverse(myfloppy, 19, 0, current_directory);
			}
		}
		else if(!strcmp(buff_parsed[0], "structure"))
		{
			structure(myfloppy);
		}
		else if(!strcmp(buff_parsed[0], "showfat"))
		{
			showfat(myfloppy);
		}
		else
		{
			fprintf(stderr,"This command doesn't exist\n");
		}
	}	
}