Hi, Pavel!

It seems we need to sleep some more, or we shall fix our stupid typos infinite ;)

Pavel Roskin wrote:
: Hello, Andrew!
: 
: You last patch for find.c does more than the ChangeLog says. This change
: in search_content() is not described in ChangeLog.
:
: If you think it's a formatting change, look again - it's not. Sometimes
: (too often actually!) read() returns values other than 0 and 1, for
: example -1.
         ^^^^
: If you want to rewrite this part in a clear, nice way you are welcome to,
: but for now I'm reverting this part of your patch since it causes a
: useless loop with 100% CPU load while attempting to search for contents.

@@ -468,10 +462,7 @@ search_content (Dlg_head *h, char *direc
     enable_interrupt_key ();
     got_interrupt ();
 
-    while (1){
-       i = read (pipe, &c, 1);
-       if (i == 0)
-           break;
+    while ((i = read (pipe, &c, 1)) == 1){
        
        if (c == '\n'){
            p = buffer;

Sometimes read() returns -1, but of course not so often as 0 and 1 ;-)

Well, I rewrote this and did some more. Patch and ChangeLog entry attached.

P.S. Pavel, can you receive and read letters in Russian? My English is not too
well sometimes ;-(

2001-04-27  Andrew V. Samoilov  <[EMAIL PROTECTED]>

        * find.c (search_content): Redo recent change without infinite loop ;-),
        egrep_path hardcoded to "egrep" as it is done in locate_egrep ()  

        (locate_egrep): commented out

        (rotating_dash) [!HAVE_X]: moved into do_search to prevent warning

Index: find.c
===================================================================
RCS file: /cvs/gnome/mc/src/find.c,v
retrieving revision 1.36
diff -u -p -b -r1.36 find.c
--- find.c      2001/04/27 00:00:00     1.36
+++ find.c      2001/04/27 09:22:03
@@ -111,9 +111,6 @@ static WLabel *status_label;        /* Finished
 static WListbox *find_list;    /* Listbox with the file list */
 #endif
 
-/* For nice updating */
-static char *rotating_dash = "|/-\\";
-
 /* This keeps track of the directory stack */
 typedef struct dir_stack {
     char *name;
@@ -388,12 +385,12 @@ find_add_match (Dlg_head *h, char *dir, 
 #endif     
 }
 
+#if 0
 static char *
 locate_egrep (void)
 {
 /* commented out because mc runs egrep via execvp() which searches PATH
     itself. It is likely that egrep in PATH is better than in /bin */
-#if 0
     char *paths [] = {
        "/bin/egrep",
        "/usr/bin/egrep",
@@ -408,9 +405,9 @@ locate_egrep (void)
        if (stat (*p, &s) == 0)
            return *p;
     }
-#endif
     return "egrep";
 }
+#endif
 
 /* 
  * search_content:
@@ -428,7 +425,7 @@ search_content (Dlg_head *h, char *direc
     char c;
     int i;
     pid_t pid;
-    static char *egrep_path;
+    char *egrep_path = "egrep";
     char *egrep_opts = case_sensitive ? "-n" : "-in";
 
     fname = concat_dir_and_file (directory, filename);
@@ -444,9 +441,6 @@ search_content (Dlg_head *h, char *direc
     if (file_fd == -1)
        return;
 
-    if (!egrep_path)
-       egrep_path = locate_egrep ();
-
 #ifndef GREP_STDIN
     pipe = mc_doublepopen (file_fd, -1, &pid, egrep_path, egrep_path, egrep_opts, 
content_pattern, NULL);
 #else /* GREP_STDIN */
@@ -468,10 +462,7 @@ search_content (Dlg_head *h, char *direc
     enable_interrupt_key ();
     got_interrupt ();
 
-    while (1){
-       i = read (pipe, &c, 1);
-       if (i == 0)
-           break;
+    while ((i = read (pipe, &c, 1)) == 1){
        
        if (c == '\n'){
            p = buffer;
@@ -614,9 +605,12 @@ do_search (struct Dlg_head *h)
 
     /* Displays the nice dot */
     count++;
+#ifndef HAVE_X
     if (!(count & 31)){
+       /* For nice updating */
+       char *rotating_dash = "|/-\\";
+
        if (verbose){
-#ifndef HAVE_X
            pos = (pos + 1) % 4;
            attrset (NORMALC);
            dlg_move (h, FIND2_Y-6, FIND2_X - 4);
@@ -625,9 +619,6 @@ do_search (struct Dlg_head *h)
        }
     } else
        goto do_search_begin;
-#else
-        }
-    }
 #endif
     x_flush_events ();
     return 1;
@@ -895,7 +886,7 @@ get_list_info (char **file, char **dir)
        gtk_clist_get_text (GTK_CLIST (g_clist), current_row, 0, file);
        *dir = gtk_clist_get_row_data (GTK_CLIST (g_clist), current_row);
 }
-#else
+#else  /* HAVE_GNOME */
 
 static void
 get_list_info (char **file, char **dir)
@@ -1091,7 +1082,7 @@ kill_gui (void)
     set_idle_proc (find_dlg, 0);
     destroy_dlg (find_dlg);
 }
-#endif
+#endif /* HAVE_GNOME */
 
 static int
 find_file (char *start_dir, char *pattern, char *content, char **dirname,  char 
**filename)

Reply via email to