[PATCH 1/2] osmocon: array of download-method names

Christian Vogel vogelchr at vogel.cx
Sun Feb 5 13:01:17 UTC 2012


An array of method names for the parser methods (c123xor, mtk, ...)
has been introduced, so that we can easily convert back and forth.
---
 src/host/osmocon/osmocon.c |   39 ++++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/src/host/osmocon/osmocon.c b/src/host/osmocon/osmocon.c
index fc29506..b3eaedb 100644
--- a/src/host/osmocon/osmocon.c
+++ b/src/host/osmocon/osmocon.c
@@ -126,6 +126,16 @@ enum dnload_mode {
 	MODE_INVALID,
 };
 
+const char * const dnload_mode_str[]={
+	[MODE_C123]="c123",
+	[MODE_C123xor]="c123xor",
+	[MODE_C140]="c140",
+	[MODE_C140xor]="c140xor",
+	[MODE_C155]="c155",
+	[MODE_ROMLOAD]="romload",
+	[MODE_MTK]="mtk",
+};
+
 struct dnload {
 	enum dnload_state state;
 	enum romload_state romload_state;
@@ -1170,24 +1180,21 @@ static int serial_read(struct osmo_fd *fd, unsigned int flags)
 
 static int parse_mode(const char *arg)
 {
-	if (!strcasecmp(arg, "c123"))
-		return MODE_C123;
-	else if (!strcasecmp(arg, "c123xor"))
-		return MODE_C123xor;
-	else if (!strcasecmp(arg, "c140"))
-		return MODE_C140;
-	else if (!strcasecmp(arg, "c140xor"))
-		return MODE_C140xor;
-	else if (!strcasecmp(arg, "c155"))
-		return MODE_C155;
-	else if (!strcasecmp(arg, "romload"))
-		return MODE_ROMLOAD;
-	else if (!strcasecmp(arg, "mtk"))
-		return MODE_MTK;
+	int i;
 
+	for(i=0;i<MODE_INVALID;i++)
+		if(!strcasecmp(arg,dnload_mode_str[i]))
+			return i;
 	return MODE_INVALID;
 }
 
+const char *
+dnload_mode_to_str(enum dnload_mode mode){
+	if(mode < 0 || mode >= MODE_INVALID)
+		return "invalid";
+	return dnload_mode_str[mode];
+}
+
 #define HELP_TEXT \
 	"[ -v | -h ] [ -d [t][r] ] [ -p /dev/ttyXXXX ]\n" \
 	"\t\t [ -s /tmp/osmocom_l2 ]\n" \
@@ -1414,8 +1421,10 @@ int main(int argc, char **argv)
 			break;
 		case 'm':
 			dnload.mode = parse_mode(optarg);
-			if (dnload.mode == MODE_INVALID)
+			if (dnload.mode == MODE_INVALID){
+				fprintf(stderr,"Invalid download mode!\n");
 				usage(argv[0]);
+			}
 			break;
 		case 's':
 			layer2_un_path = optarg;
-- 
1.7.0.4


--X1bOJ3K7DJ5YkBrT
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0002-osmocon-Option-a-runs-program-script-on-upload.patch"



More information about the baseband-devel mailing list