You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
input/csv: eliminate magic numbers in options declaration
The CSV input module has grown so many options, that counting them by
hand became tedious and error prone. Eliminate the magic numbers in the
associated code paths.
This also has the side effect that the set is easy to re-order just by
adjusting the enum, no other code is affected. Help text and default
values is much easier to verify and adjust with the symbolic references.
[ see 'git diff --word-diff' for the essence of the change ]
Copy file name to clipboardExpand all lines: src/input/csv.c
+33-20Lines changed: 33 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -965,38 +965,51 @@ static int reset(struct sr_input *in)
965
965
returnSR_OK;
966
966
}
967
967
968
+
enumoption_index {
969
+
OPT_SINGLE_COL,
970
+
OPT_NUM_LOGIC,
971
+
OPT_DELIM,
972
+
OPT_FORMAT,
973
+
OPT_COMMENT,
974
+
OPT_RATE,
975
+
OPT_FIRST_LOGIC,
976
+
OPT_HEADER,
977
+
OPT_START,
978
+
OPT_MAX,
979
+
};
980
+
968
981
staticstructsr_optionoptions[] = {
969
-
{ "single-column", "Single column", "Enable single-column mode, using the specified column (>= 1); 0: multi-col. mode", NULL, NULL },
970
-
{ "numchannels", "Number of logic channels", "The number of (logic) channels (single-col. mode: number of bits beginning at 'first channel', LSB-first)", NULL, NULL },
{ "samplerate", "Samplerate (Hz)", "The sample rate (used during capture) in Hz", NULL, NULL },
975
-
{ "first-channel", "First channel", "The column number of the first channel (multi-col. mode); bit position for the first channel (single-col. mode)", NULL, NULL },
976
-
{ "header", "Interpret first line as header (multi-col. mode)", "Treat the first line as header with channel names (multi-col. mode)", NULL, NULL },
977
-
{ "startline", "Start line", "The line number at which to start processing samples (>= 1)", NULL, NULL },
978
-
ALL_ZERO
982
+
[OPT_SINGLE_COL] ={ "single-column", "Single column", "Enable single-column mode, using the specified column (>= 1); 0: multi-col. mode", NULL, NULL },
983
+
[OPT_NUM_LOGIC] ={ "numchannels", "Number of logic channels", "The number of (logic) channels (single-col. mode: number of bits beginning at 'first channel', LSB-first)", NULL, NULL },
[OPT_RATE] ={ "samplerate", "Samplerate (Hz)", "The sample rate (used during capture) in Hz", NULL, NULL },
988
+
[OPT_FIRST_LOGIC] ={ "first-channel", "First channel", "The column number of the first channel (multi-col. mode); bit position for the first channel (single-col. mode)", NULL, NULL },
989
+
[OPT_HEADER] ={ "header", "Interpret first line as header (multi-col. mode)", "Treat the first line as header with channel names (multi-col. mode)", NULL, NULL },
990
+
[OPT_START] ={ "startline", "Start line", "The line number at which to start processing samples (>= 1)", NULL, NULL },
0 commit comments