~ecs/ini

ba0426257e19186f0bf564290ff86b5a4ba8e4c8 — Eyal Sawady 1 year, 1 month ago 9847bdb
main(): replace if with switch
1 files changed, 12 insertions(+), 7 deletions(-)

M frontend.c
M frontend.c => frontend.c +12 -7
@@ 118,10 118,9 @@ static int value_handler(void *user, const char *section,
 */
int main(int argc, char **argv)
{
	if (argc == 1 || argc > 4) {
		printf("Usage: %s <file> [<section> [<key>]]\n", argv[0]);
		return 1;
	} else if (argc == 2) {
	switch (argc) {
	case 2:
		/* this space intentionally left blank */;
		struct array sections = {0, 8, NULL};
		sections.sections = malloc(8 * sizeof(char *));



@@ 131,19 130,25 @@ int main(int argc, char **argv)
			return 2;
		}
		deinit_array(sections);
	} else if (argc == 3) {
		break;
	case 3:
		if (ini_parse(argv[1], key_list_handler, argv[2]) < 0) {
			printf("Cant load '%s'\n", argv[1]);
			return 2;
		}

	} else {
		break;
	case 4:
		/* this space intentionally left blank */;
		struct ini_value ini_value = {argv[2], argv[3]};

		if (ini_parse(argv[1], value_handler, &ini_value) < 0) {
			printf("Cant load '%s'\n", argv[1]);
			return 2;
		}
		break;
	default:
		printf("Usage: %s <file> [<section> [<key>]]\n", argv[0]);
		return 1;
	}
	return 0;
}