コード例 #1
0
ファイル: ibid.c プロジェクト: kushpatel/CPSC223
int main()
{	
	char* line;
	line = getNextLine();
	Hashtable table = tableCreate();
	char* author;
	author = findAuthor(line);
	tableInsert(table, author, line);
	free(author);
	printf("%s\n",line);
	
	char* line2;
	while(line2 = getNextLine())
	{
		if(strcmp(line,line2) == 0)		//if line2 = prev line..print ibid
		{
			printf("%s\n","ibid.");
		}
		else
		{
			author = findAuthor(line2);
			char* authorLine;
			authorLine = (char*)tableSearch(table, author);
			if(authorLine != NULL && !strcmp(authorLine, line2))
			{
				printf("%s%s\n","op. cit. ",author);
			}
			else
			{
				tableInsert(table, author, line2);
				printf("%s\n",line2);
			}
			free(author);
		}
		free(line);
		line = strdup(line2);
		free(line2);
	}
	free(line);
	tableDestroy(table);
	return 0;
}
コード例 #2
0
ファイル: stack.c プロジェクト: kubira/ifj_2009_pr
int push(stack *s, int symb, string *name, tSymbolTable *table) {
  stackItemPtr helper;  // Pomocná promìnné pro vložení nového prvku
  helper = malloc(sizeof(struct stackItem));  // Alokace nového prvku

  if(symb == FUNCTION) {
	  if(strCmpConstStr(name, "sort") == 0) {
		  helper->function = SORT;
	  } else if(strCmpConstStr(name, "find") == 0) {
		  helper->function = FIND;
	  } else {
		  return SYNTAX_ERROR;
	  }
  }

  helper->symbol = symb;  // Symbol na zásobníku - index ve znacích
  helper->nextItem = s->first;  // Nastavení následujícího prvku
  s->first = helper;  // Nastavení prvního prvku na aktuální

  //if(symb == 'E' || symb == ID) printf("\t\t\tPUSH: %s\n", strGetStr(name));

  if(symb != 'E') {
    helper->term = TRUE;
    s->top = helper;
	helper->nextNonTerm = NULL;
  }
  else {
    helper->term = FALSE;
    helper->nextNonTerm = s->firstNonTerm;
    s->firstNonTerm = helper;
  }
  
  if((symb == 0) || (symb == 'E')) {

	  if((helper->tablePtr = tableSearch(table, name)) == NULL) { // nenasel v tabulce, treba vygenerovat promennou
		  return SEM_ERROR;
	  }

  }

  return 0;
}