Phil/Stuart,
Since I, from the lack of any follow-up messages, had the impression
that my proposed patch for Stuart's problem has failed to attract
public attention in this list (probably because I once again failed to
properly tag it as [patch]), here I try again:
On Thursday 16 October 2008, Phil Dibowitz wrote:
> On Wed, Oct 15, 2008 at 09:49:38PM -0400, Stuart Doherty wrote:
> > The command I use is:
> > sudo concordance -v -C Connectivity.EZHex
>
> That's a *connectivity* file, not a config file. Don't specify a mode
> (it'll figure it out) or use -t for connectivity test. Then you'll get a
> config.
>
> Can you file a bug and I'll add some better error handling code for this?
Phil,
Unless you haven't found something better already, I would suggest the
attached patch.
Note: in the original code, after:
if (mode == MODE_UNSET && file_name) {
the check:
if (file_name) {
will obviously always succeed, so the 'else' branch printing 'No mode....'
will never be reached.
I also deleted:
- err = 0;
as redundant, since it is immediately followed by:
err = init_concord();
Result of a test run:
[EMAIL PROTECTED] concordance]$ ./concordance -C ../../Files/Connectivity.EZHex
Concordance 0.20+CVS
Copyright 2007 Kevin Timmerman and Phil Dibowitz
This software is distributed under the GPLv3.
Error: Input file type recognized as: <connectivity check>
does not match requested mode: <write configuration>
Andreas
Index: concordance.c
RCS file: /cvsroot/concordance/concordance/concordance/concordance.c,v
retrieving revision 1.33
diff -u -3 -p -r1.33 concordance.c
--- concordance.c 12 Oct 2008 22:35:26 -0000 1.33
+++ concordance.c 18 Oct 2008 20:43:41 -0000
@@ -871,6 +871,7 @@ int detect_mode(uint8_t *data, uint32_t
{
int err, type;
+ *mode = MODE_UNSET;
err = identify_file(data, size, &type);
if (err) {
return err;
@@ -897,6 +898,35 @@ int detect_mode(uint8_t *data, uint32_t
return 0;
}
+char *mode_string(int mode)
+{
+ switch (mode) {
+ case MODE_CONNECTIVITY:
+ return "connectivity check";
+ break;
+ case MODE_WRITE_CONFIG:
+ return "write configuration";
+ break;
+ case MODE_WRITE_FIRMWARE:
+ return "write firmware";
+ break;
+ case MODE_LEARN_IR:
+ return "learn IR";
+ break;
+ default:
+ return "unknown";
+ break;
+ }
+}
+
+void report_mode_mismatch(int mode, int file_mode)
+{
+ printf("Error: Input file type recognized as: <%s>\n",
+ mode_string(file_mode));
+ printf(" does not match requested mode: <%s>\n",
+ mode_string(mode));
+}
+
void help()
{
printf("There are two ways to invoke this software. You can specify");
@@ -1076,7 +1106,7 @@ int main(int argc, char *argv[])
{
struct options_t options;
char *file_name;
- int mode, err;
+ int mode, file_mode, err;
uint8_t *data;
uint32_t size;
@@ -1128,23 +1158,34 @@ int main(int argc, char *argv[])
printf("Cannot read input file.\n");
exit(1);
}
+ /*
+ * Now that the file is read, see if we can recognize it:
+ */
+ if (detect_mode(data, size, &file_mode)) {
+ printf("Cannot determine mode of operation from"
+ " file.\n");
+ }
+ /*
+ * If we don't have a mode, lets detect that mode based on
+ * the file.
+ */
+ if (mode == MODE_UNSET) {
+ mode = file_mode;
+ } else {
+ if (mode != file_mode){
+ report_mode_mismatch(mode, file_mode);
+ exit(1);
+ }
+ }
}
/*
- * And if we don't have a mode, lets detect that mode based on
- * the file.
+ * We have checked the parameters and the input file:
+ * If we still don't know what to do, failure is the only option:
*/
- if (mode == MODE_UNSET && file_name) {
- if (file_name) {
- if (detect_mode(data, size, &mode)) {
- printf("Cannot determine mode of operation from"
- " file.\n");
- exit(1);
- }
- } else {
- printf("No mode requested. No work to do.\n");
- exit(1);
- }
+ if (mode == MODE_UNSET) {
+ printf("No mode requested. No work to do.\n");
+ exit(1);
}
/*
@@ -1159,8 +1200,6 @@ int main(int argc, char *argv[])
populate_default_filename(mode, options.binary, &file_name);
}
- err = 0;
-
err = init_concord();
if (err != 0) {
printf("Error initializing libconcord: %s\n",
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
concordance-devel mailing list
concordance-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/concordance-devel