示例#1
0
文件: Parser.cpp 项目: cburschka/lyx
Parser::Parser(string const & s)
	: lineno_(0), pos_(0),
	  iss_(new idocstringstream(from_utf8(s))), is_(*iss_),
	  encoding_iconv_("UTF-8"),
	  theCatcodesType_(NORMAL_CATCODES), curr_cat_(UNDECIDED_CATCODES),
	  // An idocstringstream can not change the encoding
	  fixed_enc_(true)
{
	catInit();
}
示例#2
0
文件: Parser.cpp 项目: cburschka/lyx
Parser::Parser(idocstream & is, std::string const & fixedenc)
	: lineno_(0), pos_(0), iss_(0), is_(is),
	  encoding_iconv_(fixedenc.empty() ? "UTF-8" : fixedenc),
	  theCatcodesType_(NORMAL_CATCODES), curr_cat_(UNDECIDED_CATCODES),
	  fixed_enc_(!fixedenc.empty())
{
	if (fixed_enc_)
		is_.setEncoding(fixedenc);
	catInit();
}
示例#3
0
文件: Parser.cpp 项目: cburschka/lyx
void Parser::tokenize_one()
{
	catInit();
	char_type c;
	if (!is_.get(c))
		return;

	switch (catcode(c)) {
	case catSpace: {
		docstring s(1, c);
		while (is_.get(c) && catcode(c) == catSpace)
			s += c;
		if (catcode(c) != catSpace)
			is_.putback(c);
		push_back(Token(s, catSpace));
		break;
	}

	case catNewline: {
		++lineno_;
		docstring s(1, getNewline(is_, c));
		while (is_.get(c) && catcode(c) == catNewline) {
			++lineno_;
			s += getNewline(is_, c);
		}
		if (catcode(c) != catNewline)
			is_.putback(c);
		push_back(Token(s, catNewline));
		break;
	}

	case catComment: {
		// We don't treat "%\n" combinations here specially because
		// we want to preserve them in the preamble
		docstring s;
		while (is_.get(c) && catcode(c) != catNewline)
			s += c;
		// handle possible DOS line ending
		if (catcode(c) == catNewline)
			c = getNewline(is_, c);
		// Note: The '%' at the beginning and the '\n' at the end
		// of the comment are not stored.
		++lineno_;
		push_back(Token(s, catComment));
		break;
	}

	case catEscape: {
		is_.get(c);
		if (!is_) {
			error("unexpected end of input");
		} else {
			docstring s(1, c);
			if (catcode(c) == catLetter) {
				// collect letters
				while (is_.get(c) && catcode(c) == catLetter)
					s += c;
				if (catcode(c) != catLetter)
					is_.putback(c);
			}
			push_back(Token(s, catEscape));
		}
		break;
	}

	case catIgnore: {
		cerr << "ignoring a char: " << c << "\n";
		break;
	}

	default:
		push_back(Token(docstring(1, c), catcode(c)));
	}
	//cerr << tokens_.back();
}
示例#4
0
int main(int argc,char** argv)
{
	if(argc!= 2){
		printf("Wrong arguments!\nSintax: GESTAUTS 'file_path'\n");
	return 1;
   }
   time_t seconds = time(NULL);
 
 int entradas = 0;
	int menor_ano = 2015;
	int maior_ano = 0;
	int autores = 0;
	char *filename = argv[1];
	FILE* fl = fopen(filename,"a+");
	int read;
	char * line = NULL;
	size_t len = 0;
	int ano;
	Indice* indice;
	 int i = 0;
	indice = initInd(indice); 

	/*malloc(28*sizeof(Node));
	for(i;i<28;i++)
		indice[i] = NULL;
		*/
	Catalog * catalog;
	catalog = catInit(catalog);

i=0 ;
	while ((read = getline(&line, &len, fl)) != -1) {
	int nap= 0;
	char** nomes;
	lineParser(line,&autores, &ano,&nap,&nomes); 

    if(ano > maior_ano)
    	maior_ano = ano;

    if(ano < menor_ano)
    	menor_ano = ano;
 
catalog = add(catalog,ano,nomes,nap); 

while(nap>0)
{
 indice = addToInd(indice ,nomes[nap-1]);
nap--;
}
 

    //printf("%s\n", nomes[0]);
    entradas++;
 
    free(nomes);
    len= 0;
}
printf("Ficheiro: %s\n", filename);
printf("Publicaçoes: %d\n",entradas );
printf("Numero total de autores: %d\n",autores );
printf("Intervalo de anos: [%d-%d]\n", menor_ano,maior_ano);



printCatalog(catalog);




//printIndice(indice);
free(line);
fclose(fl);
free(indice);
free(catalog);
time_t seconds2 = time(NULL);
printf("time in seconds :: %ld\n", (seconds2-seconds) );
return 0;
}
示例#5
0
int main (int argc, char* argv[])  {
  
	/* Declaring variables used in main */
	wordsList *listHead, *listRun;
	catList *catlistHead, *catlistRun;
	int wordsCount=0, input, lifes, random, i, already;
	char unused[26], used[26], letter, play=0;
	
	
	
	
	
	
	/* If input conditions are not met programm terminates */
	input = checkInput(argc, argv);
	if (input == 0)		{return 0;}

	
	
	/* Creating the list of dictionary words, and counting the words of it */
	listHead = listInit(atoi(argv[1]),argv[3]);
	listRun = listHead;
	while(listRun != NULL){
		wordsCount = wordsCount + 1;				
		listRun = listRun->nxt;
	}
	
	
	/* Initializing the category list */
	catlistHead = catInit(listHead, argv, wordsCount);
	
	
	
	do  {
		
	  
		catlistRun = catlistHead;
		lifes = atoi(argv[2]);
		
		/* Filling the unused letters array */
		unused[0] = 'a';
		used[0] = 0;
		for (i=1; i<=26; i++) {
			unused[i] = unused[i-1] + 1;
			used[i] = 0;
			if (i == 26)  {
				unused[i] = '\0';
				used[i] = '\0';
			}
		}

		/* Main procedure of the game */
		do {
     
			printRoundInfo(lifes, argv, used, unused);
			printf("Word: ");
			printf("%s\n", catlistRun->agent);
			printf("Category size: %d\n", catlistRun->wordsNum);
	
	
			do {
				printf("Guess a letter: "); 
				scanf(" %c", &letter);
				letter = tolower(letter);
			}while(letter<97 ||letter>122);
			printf("\n");
		
			/* Creating the next node(s) of category list and returning the most crowded */
			catlistRun =  newCat(catlistRun, letter, argv);
      
      
			/* If the word isn't found yet...  */
			if (strchr(catlistRun->agent, '_')!=NULL)	{
		  
      
				/* Print message if letter was already used */
				already=0;
				for (i=0; i<26; i++) {
					if (used[i] == letter) {already=1;}
				}
				if (already == 1)		{printf("You have already guessed this letter!\n\n");}
      
      
				/* Burn a life if given letter is not used yet */
				for (i=0; i<26; i++)  {
					if (unused[i] == letter)  {
					used[i] = unused[i];
					unused[i] = 0;
					lifes = lifes - 1;
					}
				}
			}
		
			/* If the word is found print related message */
			else {
				printf("YOU WON! The word is %s\n", catlistRun->agent);
			}
	  
	  
      
			/* If no guesses remaining and the word isn't found yet, print random word from current list */
			if (lifes<1)	{
				srand(time(NULL));
				random = rand()%catlistRun->wordsNum;
				printf("YOU LOST! The word was %s\n", catlistRun->vector[random]);
			}
      
      
      
		/* User wins only if he manages to find the word within the remaining rounds */
		}while( lifes>0 && strchr(catlistRun->agent, '_')!=NULL );
      
		
		
		
		
		
		
		/*Free memmory allocated for second and next node(s) of category list */
		catlistRun = catlistHead->nxt;
		while(catlistRun != NULL)  {
			free(catlistRun->agent);				
			free(catlistRun->vector);			
			free(catlistRun);
			catlistRun = catlistRun->nxt;
		}







		/* User has a chance to play again if he wants */
		do  {
			printf("\nPlay again? (y/n): ");
			scanf(" %c", &play);
			play = tolower(play);
			
			if(play != 'y' && play != 'n')  {
			  
				printf("Please enter y for yes or n for no.\n");
			}

		}while(play != 'y' && play != 'n');
	
	
	
	}while(play != 'n');
	
	
	
	
	
	
	/*Free memmory allocated for list of dictionary words  */
	listRun = listHead;
	while(listRun != NULL)  {
		free(listRun->someWord);
		free(listRun);
		listRun = listRun->nxt;
	} 
	
	
	/*Free memmory allocated for the first node of category list */
	catlistRun = catlistHead;
	free(catlistRun->agent);				
	free(catlistRun->vector);			
	free(catlistRun);
	
	
	
	
	
  
	return 0;

	
}