/**
 * A user-space application for generating pseudo-random specification compliant CPER records.
 *
 * Author: Lawrence.Tang@arm.com
 **/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libcper/Cper.h>
#include <libcper/generator/cper-generate.h>
#include <libcper/generator/sections/gen-section.h>

void print_help();

int main(int argc, char *argv[])
{
	//If help requested, print help.
	if (argc == 2 && strcmp(argv[1], "--help") == 0) {
		print_help();
		return 0;
	}

	//Parse the command line arguments.
	char *out_file = NULL;
	char *single_section = NULL;
	char **sections = NULL;
	UINT16 num_sections = 0;
	for (int i = 1; i < argc; i++) {
		if (strcmp(argv[i], "--out") == 0 && i < argc - 1) {
			out_file = argv[i + 1];
			i++;
		} else if (strcmp(argv[i], "--single-section") == 0 &&
			   i < argc - 1) {
			single_section = argv[i + 1];
			i++;
		} else if (strcmp(argv[i], "--sections") == 0 && i < argc - 1) {
			//All arguments after this must be section names.
			num_sections = argc - i - 1;
			sections = malloc(sizeof(char *) * num_sections);
			i++;

			for (int j = i; j < argc; j++) {
				sections[j - i] = argv[j];
			}
			break;
		} else {
			printf("Unrecognised argument '%s'. For command information, refer to 'cper-generate --help'.\n",
			       argv[i]);
			return -1;
		}
	}

	//If no output file passed as argument, exit.
	if (out_file == NULL) {
		printf("No output file provided. For command information, refer to 'cper-generate --help'.\n");
		if (sections) {
			free(sections);
		}
		return -1;
	}

	//Open a file handle to write output.
	FILE *cper_file = fopen(out_file, "w");
	if (cper_file == NULL) {
		printf("Could not get a handle for output file '%s', file handle returned null.\n",
		       out_file);
		if (sections) {
			free(sections);
		}
		return -1;
	}

	//Which type are we generating?
	if (single_section != NULL && sections == NULL) {
		generate_single_section_record(single_section, cper_file);
	} else if (sections != NULL && single_section == NULL) {
		generate_cper_record(sections, num_sections, cper_file);
	} else {
		//Invalid arguments.
		printf("Invalid argument. Either both '--sections' and '--single-section' were set, or neither. For command information, refer to 'cper-generate --help'.\n");
		if (sections) {
			free(sections);
		}
		return -1;
	}

	//Close & free remaining resources.
	fclose(cper_file);
	if (sections != NULL) {
		free(sections);
	}
}

//Prints command help for this CPER generator.
void print_help()
{
	printf(":: --out cper.file [--sections section1 ...] [--single-section sectiontype]\n");
	printf("\tGenerates a pseudo-random CPER file with the provided section types and outputs to the given file name.\n\n");
	printf("\tWhen the '--sections' flag is set, all following arguments are section names, and a full CPER log is generated\n");
	printf("\tcontaining the given sections.\n");
	printf("\tWhen the '--single-section' flag is set, the next argument is the single section that should be generated, and\n");
	printf("\ta single section (no header, only a section descriptor & section) CPER file is generated.\n\n");
	printf("\tValid section type names are the following:\n");
	for (size_t i = 0; i < generator_definitions_len; i++) {
		printf("\t\t- %s\n", generator_definitions[i].ShortName);
	}
	printf("\t\t- unknown\n");
	printf("\n:: --help\n");
	printf("\tDisplays help information to the console.\n");
}
