Ejemplo n.º 1
0
interp_list *do_join(interp_list *current) {

	interp_list *pointer;	
	char first_interp[NAME_LENGTH];

	pointer = current->next_interp;

	/* The next node must exist and contain a join spine indicator */

	if (pointer == NULL) {
		print_syntax_error(ERROR20);
		current->indicator = '*';
	} else if (pointer->indicator != 'v') {
		print_syntax_error(ERROR21);
		current->indicator = '*';

	/* If it does, join the two spines */

	} else {
		current->indicator = '*';

		/* Keep any necessary statistics for the -v option */

		if (verbose) {
			joined_spines += 1;
		}

		/* Continue to join spines until the end of the list is */
		/* reached or there are no more join path indicators	*/

		while (pointer != NULL && pointer->indicator == 'v') {

			/* They must be compatable spines to join them */

			if (strcmp(current->name,pointer->name) != 0) {
				print_syntax_error(ERROR22);
			}

			/* Delete the next spine */

			pointer = delete_old(pointer,current);
			pointer = pointer->next_interp;
			if (verbose) {
				joined_spines += 1;
			}
		}
	}
	return current;
}
Ejemplo n.º 2
0
void check_new_path(tokens fields) {

	interp_list *pointer;
	int counter;

	counter = 0;
	pointer = interp_header->next_interp;

	/* Loop through each spine (each node in the list of interpretations */

	while (pointer != NULL) {

		/* If the current indicator is and 'N', then the current field 	*/
		/* must be an exclusive interpretation							*/

		if (pointer->indicator == 'N') {
			if (strncmp(fields.token[counter],"**",2) != 0) {
				print_syntax_error(ERROR1);
			}
			pointer->indicator = '*';
		}
		counter += 1;
		pointer = pointer->next_interp;
	}
	new_path = FALSE;
}
Ejemplo n.º 3
0
void process_local(tokens fields) {

	int i;

	/* A local comment may not immediately follow a new path indicator */

	if (new_path) {
		print_syntax_error(ERROR1);
		new_path = FALSE;
	}

	/* Keep statistics for the -v option */

	if (verbose) {
		local_comments += 1;
	}

	/* If the first interpretation record has not yet occurred, print error */

	if (!first_interpretation_yet) {
		print_syntax_error(ERROR9);
		current_no_of_spines = fields.number;
	}

	/* There must exist the correct number of fields */

	if (fields.number != current_no_of_spines) {
		print_syntax_error(ERROR10);
	}

	/* Each spine must begin with an excamation mark and users should be */
	/* warned if a spine begins with 2 exclamation marks				 */

	for (i = 0; i < fields.number; i += 1) {
		if (strncmp(fields.token[i],"!",1) != 0) {
			print_syntax_error(ERROR11);
		} else if (strncmp(fields.token[i],"!!",2) == 0) {
			print_syntax_error(WARNING1);
		}
	}
}
Ejemplo n.º 4
0
void check_first_interp(tokens fields) {

	int i;

	/* Every spine must contain only an exclusive interpretation */

	for (i = 0 ; i < fields.number; i += 1) {
		if (strcmp(fields.token[i],"*") == 0) {
			print_syntax_error(ERROR15);
		}
		if (strncmp(fields.token[i],"**",2) != 0) {
			print_syntax_error(ERROR17);
		} 
		if (strcmp(fields.token[i],"*+") == 0
			   || strcmp(fields.token[i],"*^") == 0
			   || strcmp(fields.token[i],"*-") == 0
			   || strcmp(fields.token[i],"*x") == 0
			   || strcmp(fields.token[i],"*v") == 0) {
			print_syntax_error(ERROR16);
		}
	}
}
Ejemplo n.º 5
0
interp_list *do_exchange(interp_list *current) {

	char temp[NAME_LENGTH];
	int found = FALSE;
	int error = FALSE;
	interp_list *next_exchange;
	interp_list *pointer;

	pointer = current->next_interp;
	next_exchange = NULL;
	current->indicator = '*';

	/* Determine which spines are to be exchanged */

	while (pointer != NULL) {
		if (pointer->indicator == 'x') {
			if (found) {
				error = TRUE;
				pointer->indicator = '*';
			} else {
				next_exchange = pointer;
				found = TRUE;
				pointer->indicator = '*';
			}
		}
		pointer = pointer->next_interp;
	}

	/* There must be exactly two spines to exchange */

	if (error || next_exchange == NULL) {
		print_syntax_error(ERROR19);

	/* Exchange the spines */

	} else {
		strcpy(temp,current->name);
		strcpy(current->name,next_exchange->name);
		strcpy(next_exchange->name,temp);
		if (verbose) {
			exchanged_spines += 2;
		}
	}
	return current;
}
Ejemplo n.º 6
0
void store_indicators(tokens fields) {

	int i;
	interp_list *pointer;

	/* Loop through each spine in the current record */

	pointer = interp_header->next_interp;
	for (i = 0; i < fields.number; i += 1) {

		/* There may not be enough indicators provided */

		if (pointer == NULL) {
			break;
		} else {

			/* Make sure a valid indicator is given */

			if (strcmp(fields.token[i],"*+") != 0
				   && strcmp(fields.token[i],"*^") != 0
				   && strcmp(fields.token[i],"*-") != 0
				   && strcmp(fields.token[i],"*x") != 0
				   && strcmp(fields.token[i],"*v") != 0
				   && strcmp(fields.token[i],"*") != 0) {
				print_syntax_error(ERROR18);
			}

			/* Store the indicator */

			if (strcmp(fields.token[i],"*") == 0) {
				pointer->indicator = '*';
			} else {
				pointer->indicator = fields.token[i][1];
			}
		}
		pointer = pointer->next_interp;
	}
}
Ejemplo n.º 7
0
t_token_list		*lexer(t_program_file *file, t_bool *lexer_result)
{
  t_token_list		*list;
  t_result		result;
  t_file_reader		file_reader;

  list = NULL;
  if (file == NULL)
    return (NULL);
  file_reader = generate_file_reader(file);
  while (string_reader_has_more(&file_reader))
    {
      result = lex_token(&file_reader);
      if (result.type == RESULT_ERROR)
	return (print_syntax_error(&file_reader, &result.syntax_error, list));
      else if (result.type == RESULT_NULL)
	return (print_unexpected_char_error(&file_reader, list));
      else if (result.type == RESULT_TOKEN
	       && add_token_to_list(&list, result.token))
        return (print_error_n("Error while adding token to list.\n"));
    }
  *lexer_result = true;
  return (list);
}
Ejemplo n.º 8
0
void process_data(tokens fields) {

	tokens double_stops;
	char *character;
	int i, j;

	/* A data record may not follow a record with a new path indicator */

	if (new_path) {
		print_syntax_error(ERROR1);	
		new_path = FALSE;
	}

	/* Keep statistics for the -v option */

	if (verbose) {
		number_of_data_records += 1;
	}

	/* A data record may not appear before the first interpretation */
	/* record and must have the correct number of spines			*/

	if (!first_interpretation_yet) {
		print_syntax_error(ERROR12);
		current_no_of_spines = fields.number;
	} else if (current_no_of_spines != fields.number) {
		print_syntax_error(ERROR13);
	}

	/* Loop through each spine in the data record */

	for (j = 0; j < fields.number; j += 1) {

		/* Check for multiple-stop space errors */

		if (strncmp(fields.token[j],SPACE,1) == 0) {
			print_syntax_error(ERROR23);
		}
		character = strrchr(fields.token[j],SPACE_CHAR);
		if (character != NULL) {
			character += 1;
			if (*character == TERMINATE) {
				print_syntax_error(ERROR24);
			}
		} 
		if (strstr(fields.token[j],CONSECUTIVE_SPACE) != NULL) {
				print_syntax_error(ERROR25);
		} 

		/* Give a warning if any spine after the first spine may be   */
		/* misinterpreted as a different type of record in the future */

		if (j > 0) {
			if (strncmp(fields.token[j],"!!",2) == 0) {
				print_syntax_error(WARNING2);
			} else if (strncmp(fields.token[j],"!",1) == 0) {
				print_syntax_error(WARNING3);
			} else if (strncmp(fields.token[j],"**",2) == 0) {
				print_syntax_error(WARNING4);
			} else if (strncmp(fields.token[j],"*",1) == 0) {
				print_syntax_error(WARNING5);
			}
		}

		/* Keep statistics for the -v option */

		if (verbose) {
			if (strcmp(fields.token[j],NULL_TOKEN) == 0) {
				null_tokens += 1;
			}
			character = fields.token[j];
			while (*character != TERMINATE) {
				if (signifiers[*character] == 0) {
					signifiers[*character] = *character;
				}
				character += 1;
			}
		}

		/* Check that no null tokens are allocated in double stops */

		split_string(fields.token[j],SPACE,&double_stops);
		for (i = 0; i < double_stops.number; i += 1) {
			if (strcmp(double_stops.token[i],NULL_TOKEN) ==  0
												&& double_stops.number > 1) {
				print_syntax_error(ERROR26);
				break;
			}
		}
		free_tokens(double_stops);
	}
}
Ejemplo n.º 9
0
void process_interpretation(tokens fields) {

	int spine_path_record;
	int i;

	/* If a new path indicator occurred in the previous record, check the */
	/* current record for an exclusive interpretation in that spine		  */

	if (new_path) {
		check_new_path(fields);
	}

	/* Each spine must begin with an asterisk and cannot contain 2 	*/
	/* asterisks without anything following							*/

	for (i = 0; i < fields.number; i += 1) {
		if (strncmp(fields.token[i],"*",1) != 0) {
			print_syntax_error(ERROR6);
		} else if (strcmp(fields.token[i],"**") == 0) {
			print_syntax_error(ERROR7);
		}
	}

	/* If this is the first interpretation, set the variables and check */
	/* that it is a valid 'first interpretation' record.				*/

	if (!first_interpretation_yet) {
		first_interpretation_yet = TRUE;
		current_no_of_spines = fields.number;
		check_first_interp(fields);
		store_new_interps(fields);

		/* Keep any necessary statistics for the -v option */

		if (verbose) {
			if (current_no_of_spines > maximum_no_of_spines) {
				maximum_no_of_spines = current_no_of_spines;
			}
			if (current_no_of_spines < minimum_no_of_spines
											|| minimum_no_of_spines == 0) {
				minimum_no_of_spines = current_no_of_spines;
			}
		}

	/* Otherwise, determine if the record is a spine path record or not */

	} else {
		if (fields.number != current_no_of_spines) {
			print_syntax_error(ERROR8);
			current_no_of_spines = fields.number;
		}
		spine_path_record = FALSE;
		for (i = 0; i < fields.number; i += 1) {
			if (strcmp(fields.token[i],"*+") == 0
				   || strcmp(fields.token[i],"*^") == 0
				   || strcmp(fields.token[i],"*-") == 0
				   || strcmp(fields.token[i],"*x") == 0
				   || strcmp(fields.token[i],"*v") == 0) {
				spine_path_record = TRUE;
				break;
			}
		}

		/* If it is a spine path record, store and process the indicators */

		if (spine_path_record) {
			store_indicators(fields);
			process_indicators(fields);

			/* Keep any necessary statistics for the -v option */

			if (verbose) {
				if (current_no_of_spines > maximum_no_of_spines) {
					maximum_no_of_spines = current_no_of_spines;
				} else if (fields.number < minimum_no_of_spines) {
					minimum_no_of_spines = fields.number;
				}
			}
			if (current_no_of_spines == 0) {
				first_interpretation_yet = FALSE;
			}

		/* Otherwise, store the new interpretations */

		} else {
			store_new_interps(fields);
		}
	}
}
Ejemplo n.º 10
0
void check_files() {

	tokens fields;					/* Holds each field in a line */
	char *character;
	file_list *current_file;
	char current_line[LINE_LENGTH]; /* Holds current input line   */
	size_t tabs;

	/* If the verbose option was specified, initialize counting variables */

	if (verbose) {
		global_comments = 0;
		local_comments = 0;
		maximum_no_of_spines = 0;
		minimum_no_of_spines = 0;
		number_of_data_records = 0;
		null_tokens = 0;
		added_spines = 0;
		terminated_spines = 0;
		split_spines = 0;
		joined_spines = 0;
		exchanged_spines = 0;
	}

	/* Loop through each file in the list of valid files */

	current_file = file_header->next_file;
	while (current_file != NULL) {
		if (strcmp(current_file->file_name,"STDIN") == 0) {
			current_file->stream = stdin;
		} else {
			current_file->stream = fopen(current_file->file_name,READ_ONLY);
		}

		/* For each file, set these variables */

		fnr = 1;
		strcpy(current_filename,current_file->file_name);
		new_path = FALSE;
		current_no_of_spines = 0;
		first_interpretation_yet = FALSE;

		/* Loop through all input lines for the current file */

		fgets(current_line,LINE_LENGTH,current_file->stream);
		character = strchr(current_line,NEWLINE);
		if (character != NULL) {
			*character = TERMINATE;
		}
		while (!feof(current_file->stream)) {

			/* Check for empty lines */

			if (strcmp(current_line,"\0") == 0) {
					print_syntax_error(ERROR2);
			} else {

				/* Check for initial tab error */

				if (strncmp(current_line,TAB,1) == 0) {
					print_syntax_error(ERROR3);
				}

				/* Check to see if the current line is meant to be	*/
				/* a global comment									*/

				tabs = strspn(current_line,TAB);
				character = current_line + tabs;

				if (strncmp(character,"!!",2) == 0) {
					process_global();
				} else {

					/* Otherwise, check for other tab errors */

					character = strrchr(current_line,TAB_CHAR);
					if (character != NULL) {
						character += 1;
						if (*character == TERMINATE) {
							print_syntax_error(ERROR4);
						}
					}
					if (strstr(current_line,CONSECUTIVE_TABS) != NULL) {
						print_syntax_error(ERROR5);
					} 
	
					/* Check global comments, local comments, interpretation */
					/* records and data records depending on the first 		 */
					/* character of the first field							 */
	
					split_string(current_line,TAB,&fields);
	
					if (fields.number > 0)
						{
						if (strncmp(fields.token[0],"!",1) == 0)
							process_local(fields);
						else if (strncmp(fields.token[0],"*",1) == 0)
							process_interpretation(fields);
						else
							process_data(fields);
						free_tokens(fields);
						}
				}
			}
			fnr += 1;
			fgets(current_line,LINE_LENGTH,current_file->stream);
			character = strchr(current_line,NEWLINE);
			if (character != NULL) {
				*character = TERMINATE;
			}
		}

		/* All spines must be termintated */

		if (current_no_of_spines != 0) {
			print_syntax_error(ERROR14);
		}
		fclose(current_file->stream);
		current_file = current_file->next_file;
	}

	/* Print the verbose information at the end of processing all files */

	if (verbose) {
		print_verbose();
	}
}
Ejemplo n.º 11
0
int load_options(hash_table *table, int argc, char *argv[])
{
	if (table == NULL)
		return ERROR;

	if (argc == 0)
		return SUCCESS;

	int c;
	while(1) {
		static struct option long_options[] = 
		{
			{"xml", required_argument, 0, 'x'},
			{"version", no_argument, 0, 'v'},
			{"help", no_argument, 0, 'h'},
			{"print", no_argument, 0, 'p'},
			{"device", required_argument, 0, 'd'},
			{"exclude", required_argument, 0, 'e'},
			{"only", required_argument, 0, 'o'},
			{"single-process", no_argument, 0, 's'},
			{"fun", no_argument, 0, 'f'},
			{0, 0, 0, 0}
		};
	
		int option_index = 0;
	
		c = getopt_long (argc, argv, "x:vhpd:e:o:sf", long_options, &option_index);

		if (c == -1)
			break;

		if (c == '?' || c == ':') {
			print_syntax_error();
			return ERROR;
		}


		switch (c) {
		
		case 0:
			if (long_options[option_index].flag != 0)
				break;

			printf("option: %s ", long_options[option_index].name);
			if (optarg)
				printf("arg: %s", optarg);
			printf("\n");
			break;
	
		case 'p':
			add_hash_info(table,"print_output", "yes");
			break;
	
		case 'x':
			if (optarg) {
				add_hash_info(table, "xml_output", optarg);
			} else {
				print_syntax_error();
				return ERROR;
			}
			break;
	
		case 'h':
			print_help();
			exit(0);
			break;
	
		case 'f':
			print_fun();
			exit(0);
			break;
	
		case 'v':
			print_version();
			exit(0);
			break;
	
		case 'd':
			if (optarg == NULL || !is_valid_plugin(optarg)) {
				print_syntax_error();
				return ERROR;
			}

			if(equals(optarg, "all")) {
				add_hash_info(table, "all_plugins", "yes");
			} else {
				add_hash_info(table, optarg, "yes");
			}

			break;

		case 'e':
			if (optarg == NULL || !is_valid_plugin(optarg) || equals(optarg, "all")) {
				print_syntax_error();
				return ERROR;
			}
			
			add_hash_info(table, optarg, "no");
			
			break;

		case 'o':
			if (optarg == NULL || !is_valid_plugin(optarg)) {
				return ERROR;
			}

			add_hash_info(table,"only",optarg);

			break;

		case 's':
			add_hash_info(table,"single","yes");
			break;

		}

	}

	return SUCCESS;	
}