cli_classic: replace enum programmer with programmer_entry*

Change-Id: I4c45f278addeea0d486a316435e8dc15d93cbd70
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.de>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/55122
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/71379
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/cli_classic.c b/cli_classic.c
index 41d456c..f20166c 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -121,7 +121,8 @@
 	int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
 	int dont_verify_it = 0, dont_verify_all = 0, list_supported = 0, operation_specified = 0;
 	struct flashrom_layout *layout = NULL;
-	enum programmer prog = PROGRAMMER_INVALID;
+	// enum programmer prog = PROGRAMMER_INVALID;
+	static const struct programmer_entry *prog = NULL;
 	enum {
 		OPTION_IFD = 0x0100,
 		OPTION_FMAP,
@@ -299,15 +300,16 @@
 #endif
 			break;
 		case 'p':
-			if (prog != PROGRAMMER_INVALID) {
+			if (prog != NULL) {
 				cli_classic_abort_usage("Error: --programmer specified "
 					"more than once. You can separate "
 					"multiple\nparameters for a programmer "
 					"with \",\". Please see the man page "
 					"for details.\n");
 			}
-			for (prog = 0; prog < programmer_table_size; prog++) {
-				name = programmer_table[prog]->name;
+			size_t p;
+			for (p = 0; p < programmer_table_size; p++) {
+				name = programmer_table[p]->name;
 				namelen = strlen(name);
 				if (strncmp(optarg, name, namelen) == 0) {
 					switch (optarg[namelen]) {
@@ -317,8 +319,10 @@
 							free(pparam);
 							pparam = NULL;
 						}
+						prog = programmer_table[p];
 						break;
 					case '\0':
+						prog = programmer_table[p];
 						break;
 					default:
 						/* The continue refers to the
@@ -331,7 +335,7 @@
 					break;
 				}
 			}
-			if (prog == PROGRAMMER_INVALID) {
+			if (prog == NULL) {
 				fprintf(stderr, "Error: Unknown programmer \"%s\". Valid choices are:\n",
 					optarg);
 				list_programmers_linebreak(0, 80, 0);
@@ -435,9 +439,9 @@
 		/* Keep chip around for later usage in case a forced read is requested. */
 	}
 
-	if (prog == PROGRAMMER_INVALID) {
+	if (prog == NULL) {
 		if (CONFIG_DEFAULT_PROGRAMMER != PROGRAMMER_INVALID) {
-			prog = CONFIG_DEFAULT_PROGRAMMER;
+			prog = programmer_table[CONFIG_DEFAULT_PROGRAMMER];
 			/* We need to strdup here because we free(pparam) unconditionally later. */
 			pparam = strdup(CONFIG_DEFAULT_PROGRAMMER_ARGS);
 			msg_pinfo("Using default programmer \"%s\" with arguments \"%s\".\n",
@@ -458,7 +462,7 @@
 	/* FIXME: Delay calibration should happen in programmer code. */
 	myusec_calibrate_delay();
 
-	if (programmer_init(programmer_table[prog], pparam)) {
+	if (programmer_init(prog, pparam)) {
 		msg_perr("Error: Programmer initialization failed.\n");
 		ret = 1;
 		goto out_shutdown;