View Issue Details

IDProjectCategoryView StatusLast Update
0002510doodleotherpublic2012-08-13 11:07
ReportermwAssigned ToChristian Grothoff 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformallOSOS Version
Product Version0.7.0 
Target VersionFixed in Version 
Summary0002510: doodle is too verbose
DescriptionUnlike other Unix utilities, in standard operation doodle prints a headline, as well as a message "Not found", if there were no matches. This makes doodle almost useless in shell scripts as there is no easy and failsafe method to remove the extraneous output. Furthermore I noticed the output did not change when doodle is run with a single verbose switch (-V).

The attached patch modifies the doodle.c file so that all nonessential output only appears, if the program is run in verbose mode. To get the current command line behavior with the patched doodle, you can simply define an alias "doodle='doodle -V'". The patch also facilitates a simple solution for the second issue in the doodle documentation: "Ordering of search results" is now possible by simply piping the doodle output through sort.

Additionally the patch makes the use of stdout/stderr more consistent. With the patch applied, all error messages and warnings now go to stderr.
TagsNo tags attached.

Activities

mw

2012-08-12 21:17

reporter  

doodle-verbosity.patch (6,383 bytes)
--- doodle-0.7.0.orig/src/doodle/doodle.c	2010-01-14 11:52:35.000000000 +0100
+++ doodle-0.7.0/src/doodle/doodle.c	2012-08-12 19:29:29.000000000 +0200
@@ -184,10 +184,10 @@
     return 0; /* already processed */
   if (0 != stat(filename,
 		&sbuf)) {
-    printf(_("Call to '%s' for file '%s' failed: %s\n"),
-	   "stat",
-	   filename,
-	   strerror(errno));
+    fprintf(stderr, _("Call to '%s' for file '%s' failed: %s\n"),
+	    "stat",
+	    filename,
+	    strerror(errno));
     return 0;
   }
   if (S_ISREG(sbuf.st_mode)) {
@@ -215,14 +215,15 @@
   char * ename;
 
   if (dbName == NULL) {
-    printf(_("No database specified.  Aborting.\n"));
+    fprintf(stderr, _("No database specified.  Aborting.\n"));
     return -1;
   }
   for (i=strlen(dbName);i>=0;i--) {
     if (dbName[i] == ':') {
-      printf(_("'%s' is an invalid database filename (has a colon) for building database (option '%s').\n"),
-	     dbName,
-	     "-b");
+      fprintf(stderr,
+	      _("'%s' is an invalid database filename (has a colon) for building database (option '%s').\n"),
+	      dbName,
+	      "-b");
       return -1;
     }
   }
@@ -252,9 +253,9 @@
   if (log != NULL) {
     cls.logFile = fopen(log, "w+");
     if (cls.logFile == NULL)
-      printf(_("Could not open '%s' for logging: %s.\n"),
-	     log,
-	     strerror(errno));
+      fprintf(stderr, _("Could not open '%s' for logging: %s.\n"),
+	      log,
+	      strerror(errno));
   }
 
   ret = 0;
@@ -340,15 +341,15 @@
   int ret;
 
  if (dbName == NULL) {
-    printf(_("No database specified. Aborting.\n"));
+    fprintf(stderr, _("No database specified. Aborting.\n"));
     return -1;
   }
   ename = expandFileName(dbName);
   if (0 != stat(ename, &buf)) {
-    printf(_("Call to '%s' for file '%s' failed: %s.\n"),
-	   "stat",
-	   dbName,
-	   strerror(errno));
+    fprintf(stderr, _("Call to '%s' for file '%s' failed: %s.\n"),
+	    "stat",
+	    dbName,
+	    strerror(errno));
     free(ename);
     return -1;
   }
@@ -379,15 +380,15 @@
   char * utf;
 
   if (dbName == NULL) {
-    printf(_("No database specified. Aborting.\n"));
+    fprintf(stderr, _("No database specified. Aborting.\n"));
     return -1;
   }
   ename = expandFileName(dbName);
   if (0 != stat(ename, &buf)) {
-    printf(_("Call to '%s' for file '%s' failed: %s.\n"),
-	   "stat",
-	   dbName,
-	   strerror(errno));
+    fprintf(stderr, _("Call to '%s' for file '%s' failed: %s.\n"),
+	    "stat",
+	    dbName,
+	    strerror(errno));
     free(ename);
     return -1;
   }
@@ -420,16 +421,20 @@
   args.seen_count = 0;
 
   for (i=0;i<argc;i++) {
-    printf(_("Searching for '%s':\n"),
-	   argv[i]);
+    if(verbose) {
+      printf(_("Searching for '%s':\n"),
+	     argv[i]);
+    }
     if (strlen(argv[i]) > MAX_LENGTH) {
-      printf(_("Warning: search string is longer than %d characters, search will not work.\n"),
-	     MAX_LENGTH);
+      fprintf(stderr,
+	      _("Warning: search string is longer than %d characters, search will not work.\n"),
+	      MAX_LENGTH);
       continue; /* no need to even try... */
     }
     if (strlen(argv[i]) > MAX_LENGTH/2) {
-      printf(_("Warning: search string is longer than %d characters, search may not work properly.\n"),
-	     MAX_LENGTH/2);
+      fprintf(stderr,
+	      _("Warning: search string is longer than %d characters, search may not work properly.\n"),
+	      MAX_LENGTH/2);
     }
     utf = convertToUtf8(argv[i],
 			strlen(argv[i]),
@@ -440,7 +445,9 @@
 				  utf,
 				  (DOODLE_ResultCallback) &printIt,
 				  &args)) {
-	printf(_("\tNot found!\n"));
+	if(verbose) {
+	  printf(_("\tNot found!\n"));
+	}
 	ret++;
       }
     } else {
@@ -450,7 +457,9 @@
 					 utf,
 					 (DOODLE_ResultCallback) &printIt,
 					 &args)) {
-	printf(_("\tNot found!\n"));
+	if (verbose) {
+	  printf(_("\tNot found!\n"));
+	}
 	ret++;
       }
     }
@@ -520,31 +529,36 @@
     switch (c) {
     case 'a':
       if (1 != sscanf(optarg, "%ud", &do_approx)) {
-	printf(_("You must pass a number to the '%s' option.\n"),
-	       "-a");
+	fprintf(stderr,
+		_("You must pass a number to the '%s' option.\n"),
+		"-a");
 	return -1;
       }
       if (do_build == 1) {
-	printf(_("The options '%s' and '%s' cannot be used together!\n"),
-	       "-a", "-b");
+	fprintf(stderr,
+		_("The options '%s' and '%s' cannot be used together!\n"),
+		"-a", "-b");
 	return -1;
-      }	
+      }
       break;
     case 'b':
       do_build = 1;
       if (do_approx != 0) {
-	printf(_("The options '%s' and '%s' cannot be used together!\n"),
-	       "-a", "-b");
+	fprintf(stderr,
+		_("The options '%s' and '%s' cannot be used together!\n"),
+		"-a", "-b");
 	return -1;
-      }	
+      }
       if (do_print == 1) {
-	printf(_("The options '%s' and '%s' cannot be used together!\n"),
-	       "-b", "-p");
+	fprintf(stderr,
+		_("The options '%s' and '%s' cannot be used together!\n"),
+		"-b", "-p");
 	return -1;
-      }	
+      }
       if (ignore_case == 1) {
-	printf(_("The options '%s' and '%s' cannot be used together!\n"),
-	       "-b", "-i");
+	fprintf(stderr,
+		_("The options '%s' and '%s' cannot be used together!\n"),
+		"-b", "-i");
 	return -1;
       }
       break;
@@ -563,8 +577,9 @@
     case 'i':
       ignore_case = 1;
       if (do_build == 1) {
-	printf(_("The options '%s' and '%s' cannot be used together!\n"),
-	       "-b", "-i");
+	fprintf(stderr,
+		_("The options '%s' and '%s' cannot be used together!\n"),
+		"-b", "-i");
 	return -1;
       }
       break;
@@ -576,12 +591,13 @@
       break;
     case 'm':
       if (1 != sscanf(optarg, "%u", &mem_limit)) {
-	printf(_("You must pass a number to the '%s' option.\n"),
-	       "-m");
+	fprintf(stderr,
+		_("You must pass a number to the '%s' option.\n"),
+		"-m");
 	return -1;
       }
       if (mem_limit > 0xFFFFFFFF / 1024 / 1024) {
-	printf(_("Specified memory limit is too high.\n"));
+	fprintf(stderr, _("Specified memory limit is too high.\n"));
 	return -1;
       }
       mem_limit *= 1024 * 1024;
@@ -592,10 +608,11 @@
     case 'p':
       do_print = 1;
       if (do_build == 1) {
-	printf(_("The options '%s' and '%s' cannot be used together!\n"),
-	       "-b", "-p");
+	fprintf(stderr,
+		_("The options '%s' and '%s' cannot be used together!\n"),
+		"-b", "-p");
 	return -1;
-      }	
+      }
       break;
     case 'P':
       prunepaths = optarg;
doodle-verbosity.patch (6,383 bytes)

Christian Grothoff

2012-08-13 11:07

manager   ~0006275

Patched as suggested in SVN 23209.

Issue History

Date Modified Username Field Change
2012-08-12 21:17 mw New Issue
2012-08-12 21:17 mw File Added: doodle-verbosity.patch
2012-08-13 11:04 Christian Grothoff Assigned To => Christian Grothoff
2012-08-13 11:04 Christian Grothoff Status new => assigned
2012-08-13 11:07 Christian Grothoff Note Added: 0006275
2012-08-13 11:07 Christian Grothoff Status assigned => resolved
2012-08-13 11:07 Christian Grothoff Resolution open => fixed