Ejemplo n.º 1
0
int launchWordHandler(int index, char * word) {
	int pipefdHandlerInput [2];
	pipe(pipefdHandlerInput);

	int pipefdHandlerOutput [2];
	pipe(pipefdHandlerOutput);

	FILE * fp;
	
	int cpid = fork();

	switch (cpid) { 
	case -1:
		printf("Fork failed; cpid == -1\n");

		exit(1);
	case 0:
		handleWord(pipefdHandlerInput[0], pipefdHandlerOutput[1]);

		exit(0);
	default:
		fp = fdopen(pipefdHandlerInput[1], "w");
		fprintf(fp, "%s\n", word);
		fclose(fp);

		pipefdHandlersOutput[index] = pipefdHandlerOutput[0];

		return 0;
	}


}
Ejemplo n.º 2
0
/*
void addNode(struct node **q, char *d){
	if(*q == NULL) //if no node is found. create new node.
		*q = (struct node *)malloc(sizeof(struct node));
	else{
		while(*q->next != NULL)//find last node and point it to new node
			*q = *q->next;

		*q->next = (struct node *)malloc(sizeof(struct node));
		*q = *q->next;
	}

	*q->data = d;
	*q->next = NULL;
}
*/
void
parseText(char *str, int numberWords )
{
	int i, wordCase=0, wordIndex;

	char * word;
	word = strtok (str, " <>,.-;:\n\t#`~!$%^(?[@',&]).:;\\-\"");

	const char *words[numberWords];
	const char *alphaWords[numberWords];
	long hashAlphaValue[numberWords];
	memset(hashAlphaValue, 0, numberWords*sizeof(long));
	int occur[numberWords];
	memset(occur, 0, numberWords*sizeof(int));
	int caseSensitive[numberWords];
	memset(caseSensitive, 0, numberWords*sizeof(int));

	struct node *nodesArr[numberWords];

	while (word != NULL)
	{
		/*
		struct node *temp;
		temp=nodesArr[i];
		addNode(temp,word);
		*/
		wordIndex=hash(word, numberWords);
		words[wordIndex] = word;
		hashAlphaValue[wordIndex]=hashAlpha(word);
		alphaWords[hashAlpha(word)]=word;
		wordCase=handleWord(word, words[wordIndex]);
		if(wordCase==1){
			occur[wordIndex]++;
		}
		printf("%d\n", hashAlpha("hi how are youword"));
		printf("%d\t%s\t%d\t%s\t\n", wordIndex, words[wordIndex], occur[wordIndex], alphaWords[1]);
		word = strtok (NULL, " <>,.-;:\n\t#`~!$%^(?[@',&]).:;\\-\"");
	}
}
Ejemplo n.º 3
0
Token Scanner::getToken()
{
	/*
		Reads the next available character and dispatches to the
		appropriate FSA for them to parse. 
	*/		


	// do not return MP_COMMENT to the parser
	do 
	{	
		// detect EOF and skip whitespace
		hasToken();	
		char next = peek();	

		// reset the TOKEN and LEXEME variables, FSA will set new values
		_token = MP_NULL;
		_lexeme = "";

		// which FSA to call 
		if (next == '\'') // handle strings, start with ' (single quote)
			handleString();
		else if (isdigit(next))
			handleNumberic();
		else if (isalpha(next) || next=='_' ) // check for identifier
			handleWord();
		else if (next == '{' || next == '}') // handle comments first becuase {} are considered punctation
			handleComment();
		else if (ispunct(next))
			handleSymbol();
		else if (next == EOF) {
			_token = MP_EOF;
			_lexeme = get();
		}
	} while (_token == MP_COMMENT);

	return _token; 
};