示例#1
0
/*lee el siguiente item.
 * Consume todo caracter hasta encontrar alguno perteneciente a 'str'.
 *Deja el resultado accesible en 'result'. El llamador se encarga de liberarlo*/
static bstring next_bstring (Lexer *input, const char *str){

	bstring result=NULL;
	/*Pre:*/
	assert (input != NULL);
	/*Leo todos los caracteres anteriores y no pertenecientes a 'str'*/
	if (!lexer_is_off (input)){
		lexer_next_to (input, str);
		/*si (leyo algo) ´o´ (no EOF y no leyo nada)*/
		if (!lexer_is_off (input)){
			result = lexer_item(input);
			/*Si no leyo ningun caracter, destruyo el puntero.
			 * Esto pasa cuando el caracter inmediato a leer pertenece a str
			 * y el item es vacio*/
			if (blength (result) == 0){
				bdestroy (result);
				result=NULL;
			}
		}
	}

	return result;
}
示例#2
0
int parse_string (const string_t client_string, list_s lista) {
	string_t almost_done = NULL;
	string_t done = NULL;
	FILE * strf = NULL;

	int result = CODE_OK;

	assert (client_string != NULL && lista != NULL);
	strf = fmemopen (client_string, strlen(client_string) + 1, "r");
	if (strf != NULL) {
		Lexer * l = lexer_new (strf);

		lexer_next_to (l, "\n");
		almost_done = lexer_item (l);
		if (strncmp (client_string, almost_done, strlen (client_string) - 2) != 0)
			return BAD_EOL;
		lexer_destroy (l);
		fclose (strf);
		
		if (strlen (almost_done) > 1 && almost_done != NULL) {
			strf = fmemopen (almost_done, strlen(almost_done), "r");
			if (strf != NULL) {
				Lexer * j = lexer_new (strf);
				lexer_next_to (j, "\r");
				done = lexer_item (j);
				lexer_destroy (j);
				fclose (strf);

				if (strlen (done) > 1 && done != NULL) {
					strf = fmemopen (done, strlen(done), "r");
					if (strf){
						string_t valid_elem = NULL;
						Lexer * p = lexer_new (strf);
	
						while (!lexer_is_off (p)) {
							lexer_next (p, SUPERALPHANUMERIC);
							valid_elem = lexer_item (p);
							list_adjoin_back (lista, valid_elem);
							lexer_skip (p, BLANK);
						}
						lexer_destroy (p); p = NULL;
						fclose (strf);
					}
					else {
						fprintf (stderr, "fmemopen");
						result = INTERNAL_ERROR;
					}
				}
				else {
					if (done != NULL)
						result = STRING_VOID;
					else
						result = INTERNAL_ERROR;
				}
			}
			else {
				fprintf (stderr, "fmemopen");
				result = INTERNAL_ERROR;
			}
		}
		else {
			if (almost_done != NULL)
				result = STRING_VOID;
			else
				result = INTERNAL_ERROR;
		}
		if(almost_done != NULL) {
			free (almost_done); almost_done = NULL;
		}
		if(done != NULL) {
			free (done); done = NULL;
		}
	}
	else {
		fprintf (stderr, "fmemopen");
		result = INTERNAL_ERROR;
	}

	return result;
}