src/gcode.c
void check_instructions(FILE * f)
{
    int i;

    /* File buffer */
    char buffer[OPERATOR_LENGHT];
    int line = 1;

    while (fscanf(f,"%s%*[^\n]",buffer) == 1) {
	bool try = false;

	/* Compares each line's first string to the operators */
	for (i=0;i<total_operators;i++) {
	    if (strcmp(buffer, operators[i]) == 0) {
		try = true;
		line++;
		
		break;
	    } else {
		try = false;
	    }
	}

	/* Checks for invalid operator */
	if (try == false) {
	    errno = 38;
	    
	    printf("Invalid operation on line %d: %s", line, buffer);
	    fflush(stdout);
	    
	    perror("\nERROR");
	    exit(errno);
	}
    }

    /* Unindentified error: shouldn't ever happen */
    if (!feof(f)) {
	errno = 5;
	fflush(stdout);
	
	perror("\nERROR");
	exit(errno);
    }
    
    return;
}
/*
 * Reads the first string in each line of the file.
 *
 * Exit with an error if string is not declared in 'operators'
 * or if there's any trouble opening the file itself.
 */
Reads the first string in each line of the file.
Exit with an error if string is not declared in 'operators'
or if there's any trouble opening the file itself.
Reads the first string in each line of the file . Exit with an error if string is not declared in ' operators ' or if there ' s any trouble opening the file itself .
void check_instructions(FILE * f)
{
    int i;
    char buffer[OPERATOR_LENGHT];
    int line = 1;
    while (fscanf(f,"%s%*[^\n]",buffer) == 1) {
	bool try = false;
	for (i=0;i<total_operators;i++) {
	    if (strcmp(buffer, operators[i]) == 0) {
		try = true;
		line++;
		break;
	    } else {
		try = false;
	    }
	}
	if (try == false) {
	    errno = 38;
	    printf("Invalid operation on line %d: %s", line, buffer);
	    fflush(stdout);
	    perror("\nERROR");
	    exit(errno);
	}
    }
    if (!feof(f)) {
	errno = 5;
	fflush(stdout);
	perror("\nERROR");
	exit(errno);
    }
    return;
}
void check_instructions ( FILE * f ) { int i ; char buffer [ OPERATOR_LENGHT ] ; int line = 1 ; while ( fscanf ( f , " \n " , buffer ) == 1 ) { bool try = false ; for ( i = 0 ; i < total_operators ; i ++ ) { if ( strcmp ( buffer , operators [ i ] ) == 0 ) { try = true ; line ++ ; break ; } else { try = false ; } } if ( try == false ) { errno = 38 ; printf ( " " , line , buffer ) ; fflush ( stdout ) ; perror ( " \n " ) ; exit ( errno ) ; } } if ( ! feof ( f ) ) { errno = 5 ; fflush ( stdout ) ; perror ( " \n " ) ; exit ( errno ) ; } return ; }
Reads the first string in each line of the file.
Reads the first string in each line of the file .
/* File buffer */ /* Compares each line's first string to the operators */ /* Checks for invalid operator */ /* Unindentified error: shouldn't ever happen */