Example #1
0
int main(int argc, char *argv[])
{
	int i, j;
	char *str;
	FILE *fp;
	BinSTreeNode rootNode;
	for(i = 1; i < argc; i++){
		if(argv[i][0] != '-' && argv[i][0] != '/' && !(isnumber(argv[i][0]))){
			fp = fopen(argv[i], "r");
			if(fp == NULL) exit(1);
			add_from_file(fp, rootNode);
			fclose(fp);
		}
	}
	//	if(rootNode->word == NULL){
	//	while(1){
	//		fgets(str, N, stdin);
	//		add_from_line(str);
	//	}
	//	if(argc == 1) printTree(0);
	for(i = 1; i < argc; i++){
		if(argv[i][0] == '-' || argv[i][0] == '/' || isnumber(argv[i][0])){
			if(strcmp(argv[i], "-p") == 0 && i+1 < argc){
				if(isdigit(argv[i+1][0])){
					printf("printTree, %d\n", atoi((const char*)argv[i+1]));
					i++;
				}else{
					printf("printTree, 0\n");
				}
			}
			if(strcmp(argv[i], "-r") == 0){
				if(i+1 == argc || argv[i+1][0] != '/') exit(1);
				for(i++, j = 1; j < strlen(argv[i]); j++){
						if(argv[i][j] == '/'){
							str = cutstr(argv[i], 1, j-1);
							if(argv[i][j+1] == '0') printf("remove %s all\n", str);
							else printf("remove %s onece\n", str);
							break;
						}
				}
			}
			if(strcmp(argv[i], "-s") == 0){
				if(i+1 == argc || argv[i+1][0] != '/') exit(1);
				for(i++, j = 1; j < strlen(argv[i]); j++){
						if(argv[i][j] == '/'){
							char *str2 = cutstr(argv[i], j+1, strlen(argv[i])-2);
							str = cutstr(argv[i], 1, j-1);
							printf("substitute %s %s\n", str, str2);
							break;
						}
				}
				i++;
			}
		}
	}
		return 0;
}
Example #2
0
int add_from_line(char *str, BinSTreeNode root){
	int i, j;
	for(i = 0, j = 0; str[i-1] != '\n'; i++){
		if(j != i && (str[i] == ' ' || str[i] == '\n')){
			add(root, cutstr(str, j, i-1));
			j = i+1;
		}
		if(str[i] == ' ' && i == j) j++;
	}
	return 0;
}
Example #3
0
void Screen::draw(ascii::Graphics& graphics)
{
	ascii::Rectangle destination(3, 2, 74, 21);

	int charsLeft = revealedChars;
	for (std::vector<Text>::iterator it = text.begin(); it != text.end(); ++it)
	{
		if (it->isVisible())
		{
			std::string tempstr(it->getText());

			std::string cutstr(tempstr.substr(0, charsLeft));
			charsLeft -= cutstr.size();

			graphics.blitStringMultiline(cutstr.c_str(), ascii::Color::Green, destination);

			destination.y += graphics.measureStringMultilineY(it->getText(), destination);

			destination.y++;
		}
	}

	destination.x += 2;

	char num = 49;
	for (std::vector<Action>::iterator it = actions.begin(); it != actions.end(); ++it)
	{
		if (it->isEnabled())
		{
			if (charsLeft)
			{
				graphics.setCharacterColor(destination.x, destination.y, ascii::Color::Green);
				graphics.setCharacter(destination.x, destination.y, num);
				--charsLeft;
			}
			if (charsLeft)
			{
				graphics.setCharacterColor(destination.x + 1, destination.y, ascii::Color::Green);
				graphics.setCharacter(destination.x + 1, destination.y, '-');
				charsLeft--;
			}

			destination.x += 2;

			std::string tempstr(it->getText());
			std::string cutstr = tempstr.substr(0, charsLeft);

			graphics.blitStringMultiline(cutstr.c_str(), ascii::Color::Green, destination);

			charsLeft -= cutstr.size();

			std::vector<Action>::iterator fin = actions.end();
			do
			{
				--fin;
			} while (!fin->isEnabled());

			if (it == fin)
			{
				//it's the last one
				if (cutstr.size() == tempstr.size())
				{
					int x = graphics.measureStringMultilineX(cutstr.c_str(), destination);


					takeInput = true;
					//x++;

					if (totalMS / kFlashMS  % 2 == 1)
					{
						graphics.setBackgroundColor(x, destination.y, ascii::Color::Green);
					}
				}
			}

			++num;

			destination.x -= 2;
			destination.y += graphics.measureStringMultilineY(it->getText(), destination);
		}
	}
}