1998-02-27 07:54:42 +03:00
|
|
|
/* Find file command for the Midnight Commander
|
|
|
|
Copyright (C) The Free Software Foundation
|
|
|
|
Written 1995 by Miguel de Icaza
|
|
|
|
|
|
|
|
Complete rewrote.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2000-08-23 02:50:00 +04:00
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <ctype.h>
|
2001-09-03 09:07:40 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "global.h"
|
2001-09-03 09:07:40 +04:00
|
|
|
#include "tty.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "win.h"
|
|
|
|
#include "color.h"
|
1998-11-18 05:31:23 +03:00
|
|
|
#include "setup.h"
|
1998-12-03 00:27:27 +03:00
|
|
|
#include "find.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Dialog manager and widgets */
|
|
|
|
#include "dlg.h"
|
|
|
|
#include "widget.h"
|
|
|
|
|
|
|
|
#include "dialog.h" /* For do_refresh() */
|
|
|
|
#define DIR_H_INCLUDE_HANDLE_DIRENT
|
|
|
|
#include "dir.h"
|
|
|
|
#include "panel.h" /* current_panel */
|
|
|
|
#include "main.h" /* do_cd, try_to_select */
|
|
|
|
#include "wtools.h"
|
|
|
|
#include "cmd.h" /* view_file_at_line */
|
2001-10-01 10:51:15 +04:00
|
|
|
#include "boxes.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "../vfs/vfs.h"
|
|
|
|
|
|
|
|
/* Size of the find parameters window */
|
2001-04-06 09:21:29 +04:00
|
|
|
#define FIND_Y 14
|
1998-04-08 22:50:24 +04:00
|
|
|
static int FIND_X = 50;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Size of the find window */
|
|
|
|
#define FIND2_Y LINES-4
|
|
|
|
|
2001-07-15 01:44:39 +04:00
|
|
|
static int FIND2_X = 64;
|
|
|
|
#define FIND2_X_USE FIND2_X-20
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* A couple of extra messages we need */
|
|
|
|
enum {
|
|
|
|
B_STOP = B_USER + 1,
|
|
|
|
B_AGAIN,
|
|
|
|
B_PANELIZE,
|
|
|
|
B_TREE,
|
|
|
|
B_VIEW
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A list of directories to be ignores, separated with ':' */
|
|
|
|
char *find_ignore_dirs = 0;
|
|
|
|
|
|
|
|
static WInput *in_start; /* Start path */
|
|
|
|
static WInput *in_name; /* Pattern to search */
|
|
|
|
static WInput *in_with; /* text inside filename */
|
|
|
|
static int running = 0; /* nice flag */
|
|
|
|
static char *find_pattern; /* Pattern to search */
|
|
|
|
static char *content_pattern; /* pattern to search inside files */
|
|
|
|
static int count; /* Number of files displayed */
|
|
|
|
static int matches; /* Number of matches */
|
|
|
|
static int is_start; /* Status of the start/stop toggle button */
|
|
|
|
static char *old_dir;
|
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
static Dlg_head *find_dlg; /* The dialog */
|
|
|
|
|
|
|
|
static WButton *stop_button; /* pointer to the stop button */
|
|
|
|
static WLabel *status_label; /* Finished, Searching etc. */
|
|
|
|
static WListbox *find_list; /* Listbox with the file list */
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* This keeps track of the directory stack */
|
|
|
|
typedef struct dir_stack {
|
|
|
|
char *name;
|
|
|
|
struct dir_stack *prev;
|
|
|
|
} dir_stack ;
|
|
|
|
|
2001-07-15 01:44:39 +04:00
|
|
|
static dir_stack *dir_stack_base = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-04-08 22:50:24 +04:00
|
|
|
static struct {
|
|
|
|
char* text;
|
|
|
|
int len; /* length including space and brackets */
|
|
|
|
int x;
|
|
|
|
} fbuts [] = {
|
|
|
|
{ N_("&Suspend"), 11, 29 },
|
1998-09-29 00:41:28 +04:00
|
|
|
{ N_("Con&tinue"), 12, 29 },
|
1998-04-08 22:50:24 +04:00
|
|
|
{ N_("&Chdir"), 11, 3 },
|
|
|
|
{ N_("&Again"), 9, 17 },
|
|
|
|
{ N_("&Quit"), 8, 43 },
|
|
|
|
{ N_("Pane&lize"), 12, 3 },
|
|
|
|
{ N_("&View - F3"), 13, 20 },
|
|
|
|
{ N_("&Edit - F4"), 13, 38 }
|
|
|
|
};
|
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
static char *add_to_list (char *text, void *closure);
|
|
|
|
static void stop_idle (void *data);
|
|
|
|
static void status_update (char *text);
|
|
|
|
static void get_list_info (char **file, char **dir);
|
|
|
|
|
2002-02-28 16:50:03 +03:00
|
|
|
/* FIXME: r should be local variables */
|
|
|
|
static regex_t *r; /* Pointer to compiled content_pattern */
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/*
|
|
|
|
* find_parameters: gets information from the user
|
|
|
|
*
|
|
|
|
* If the return value is true, then the following holds:
|
|
|
|
*
|
|
|
|
* START_DIR and PATTERN are pointers to char * and upon return they
|
|
|
|
* contain the information provided by the user.
|
|
|
|
*
|
|
|
|
* CONTENT holds a strdup of the contents specified by the user if he
|
|
|
|
* asked for them or 0 if not (note, this is different from the
|
|
|
|
* behavior for the other two parameters.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-04-06 09:21:29 +04:00
|
|
|
static int case_sensitive = 1;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
static int
|
|
|
|
find_parameters (char **start_dir, char **pattern, char **content)
|
|
|
|
{
|
|
|
|
int return_value;
|
|
|
|
char *temp_dir;
|
2001-04-06 09:21:29 +04:00
|
|
|
WCheck *case_sense;
|
2002-09-04 00:04:54 +04:00
|
|
|
static char *case_label = N_("case &Sensitive");
|
2001-04-06 09:21:29 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
static char *in_contents = NULL;
|
|
|
|
static char *in_start_dir = NULL;
|
|
|
|
static char *in_start_name = NULL;
|
|
|
|
|
2002-09-04 00:04:54 +04:00
|
|
|
static char *labs[] =
|
|
|
|
{ N_("Start at:"), N_("Filename:"), N_("Content: ") };
|
2002-10-22 02:26:39 +04:00
|
|
|
static char *buts[] = { N_("&OK"), N_("&Tree"), N_("&Cancel") };
|
2002-02-28 16:50:03 +03:00
|
|
|
static int ilen = 30, istart = 14;
|
|
|
|
static int b0 = 3, b1 = 16, b2 = 36;
|
1998-04-08 22:50:24 +04:00
|
|
|
|
|
|
|
#ifdef ENABLE_NLS
|
2002-09-04 00:04:54 +04:00
|
|
|
static int i18n_flag = 0;
|
|
|
|
|
|
|
|
if (!i18n_flag) {
|
|
|
|
register int i = sizeof (labs) / sizeof (labs[0]);
|
|
|
|
int l1, maxlen = 0;
|
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
l1 = strlen (labs[i] = _(labs[i]));
|
|
|
|
if (l1 > maxlen)
|
|
|
|
maxlen = l1;
|
1998-04-08 22:50:24 +04:00
|
|
|
}
|
2002-09-04 00:04:54 +04:00
|
|
|
i = maxlen + ilen + 7;
|
|
|
|
if (i > FIND_X)
|
|
|
|
FIND_X = i;
|
1998-04-08 22:50:24 +04:00
|
|
|
|
2002-09-04 00:04:54 +04:00
|
|
|
for (i = sizeof (buts) / sizeof (buts[0]), l1 = 0; i--;) {
|
|
|
|
l1 += strlen (buts[i] = _(buts[i]));
|
|
|
|
}
|
|
|
|
l1 += 21;
|
|
|
|
if (l1 > FIND_X)
|
|
|
|
FIND_X = l1;
|
|
|
|
|
|
|
|
ilen = FIND_X - 7 - maxlen; /* for the case of very long buttons :) */
|
|
|
|
istart = FIND_X - 3 - ilen;
|
|
|
|
|
|
|
|
b1 = b0 + strlen (buts[0]) + 7;
|
|
|
|
b2 = FIND_X - (strlen (buts[2]) + 6);
|
|
|
|
|
|
|
|
i18n_flag = 1;
|
|
|
|
case_label = _(case_label);
|
|
|
|
}
|
|
|
|
#endif /* ENABLE_NLS */
|
|
|
|
|
|
|
|
find_par_start:
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!in_start_dir)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
in_start_dir = g_strdup (".");
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!in_start_name)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
in_start_name = g_strdup (easy_patterns ? "*" : ".");
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!in_contents)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
in_contents = g_strdup ("");
|
2002-09-04 00:04:54 +04:00
|
|
|
|
2002-09-02 20:31:33 +04:00
|
|
|
find_dlg = create_dlg (0, 0, FIND_Y, FIND_X, dialog_colors, NULL,
|
2002-09-03 11:42:36 +04:00
|
|
|
"[Find File]", _("Find File"), DLG_CENTER);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-04 00:04:54 +04:00
|
|
|
add_widget (find_dlg, button_new (11, b2, B_CANCEL, NORMAL_BUTTON,
|
|
|
|
buts[2], 0, 0, "cancel"));
|
|
|
|
add_widget (find_dlg, button_new (11, b1, B_TREE, NORMAL_BUTTON,
|
|
|
|
buts[1], 0, 0, "tree"));
|
|
|
|
add_widget (find_dlg, button_new (11, b0, B_ENTER, DEFPUSH_BUTTON,
|
|
|
|
buts[0], 0, 0, "ok"));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-04 00:04:54 +04:00
|
|
|
case_sense =
|
|
|
|
check_new (9, 3, case_sensitive, case_label, "find-case-check");
|
2001-04-07 01:48:11 +04:00
|
|
|
add_widget (find_dlg, case_sense);
|
2001-04-06 09:21:29 +04:00
|
|
|
|
2002-09-04 00:04:54 +04:00
|
|
|
in_with =
|
|
|
|
input_new (7, istart, INPUT_COLOR, ilen, in_contents, "content");
|
2001-04-07 01:48:11 +04:00
|
|
|
add_widget (find_dlg, in_with);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-04 00:04:54 +04:00
|
|
|
in_name =
|
|
|
|
input_new (5, istart, INPUT_COLOR, ilen, in_start_name, "name");
|
2001-04-07 01:48:11 +04:00
|
|
|
add_widget (find_dlg, in_name);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-04 00:04:54 +04:00
|
|
|
in_start =
|
|
|
|
input_new (3, istart, INPUT_COLOR, ilen, in_start_dir, "start");
|
2001-04-07 01:48:11 +04:00
|
|
|
add_widget (find_dlg, in_start);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-04 00:04:54 +04:00
|
|
|
add_widget (find_dlg, label_new (7, 3, labs[2], "label-cont"));
|
|
|
|
add_widget (find_dlg, label_new (5, 3, labs[1], "label-file"));
|
|
|
|
add_widget (find_dlg, label_new (3, 3, labs[0], "label-start"));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
run_dlg (find_dlg);
|
1998-12-02 08:18:20 +03:00
|
|
|
|
2002-09-04 00:04:54 +04:00
|
|
|
switch (find_dlg->ret_value) {
|
1998-12-02 08:18:20 +03:00
|
|
|
case B_CANCEL:
|
1998-02-27 07:54:42 +03:00
|
|
|
return_value = 0;
|
1998-12-02 08:18:20 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case B_TREE:
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
temp_dir = g_strdup (in_start->buffer);
|
2001-04-06 09:21:29 +04:00
|
|
|
case_sensitive = case_sense->state & C_BOOL;
|
1998-02-27 07:54:42 +03:00
|
|
|
destroy_dlg (find_dlg);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (in_start_dir);
|
2002-09-04 00:04:54 +04:00
|
|
|
if (strcmp (temp_dir, ".") == 0) {
|
2002-02-28 16:50:03 +03:00
|
|
|
g_free (temp_dir);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
temp_dir = g_strdup (cpanel->cwd);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2001-10-01 10:51:15 +04:00
|
|
|
in_start_dir = tree_box (temp_dir);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (in_start_dir)
|
2002-02-28 16:50:03 +03:00
|
|
|
g_free (temp_dir);
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
|
|
|
in_start_dir = temp_dir;
|
|
|
|
/* Warning: Dreadful goto */
|
|
|
|
goto find_par_start;
|
1998-12-02 08:18:20 +03:00
|
|
|
break;
|
2002-09-04 00:04:54 +04:00
|
|
|
|
1998-12-02 08:18:20 +03:00
|
|
|
default:
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (in_contents);
|
2002-09-04 00:04:54 +04:00
|
|
|
if (in_with->buffer[0]) {
|
|
|
|
int flags = REG_EXTENDED | REG_NOSUB;
|
2002-02-28 16:50:03 +03:00
|
|
|
|
2002-03-18 23:04:13 +03:00
|
|
|
if (!(case_sense->state & C_BOOL))
|
2002-02-28 16:50:03 +03:00
|
|
|
flags |= REG_ICASE;
|
|
|
|
|
|
|
|
if (regcomp (r, in_with->buffer, flags)) {
|
|
|
|
*content = in_contents = NULL;
|
|
|
|
r = 0;
|
2002-09-04 00:04:54 +04:00
|
|
|
message (1, MSG_ERROR,
|
|
|
|
_(" Malformed regular expression "));
|
2002-02-28 16:50:03 +03:00
|
|
|
return_value = 0;
|
|
|
|
break;
|
|
|
|
}
|
2002-09-04 00:04:54 +04:00
|
|
|
*content = g_strdup (in_with->buffer);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
in_contents = g_strdup (*content);
|
2002-02-28 16:50:03 +03:00
|
|
|
} else {
|
1998-02-27 07:54:42 +03:00
|
|
|
*content = in_contents = NULL;
|
2002-02-28 16:50:03 +03:00
|
|
|
r = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case_sensitive = case_sense->state & C_BOOL;
|
|
|
|
return_value = 1;
|
|
|
|
*start_dir = g_strdup (in_start->buffer);
|
2002-09-04 00:04:54 +04:00
|
|
|
*pattern = g_strdup (in_name->buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (in_start_dir);
|
|
|
|
in_start_dir = g_strdup (*start_dir);
|
|
|
|
g_free (in_start_name);
|
|
|
|
in_start_name = g_strdup (*pattern);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
destroy_dlg (find_dlg);
|
2002-09-04 00:04:54 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
push_directory (char *dir)
|
|
|
|
{
|
|
|
|
dir_stack *new;
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
new = g_new (dir_stack, 1);
|
|
|
|
new->name = g_strdup (dir);
|
1998-02-27 07:54:42 +03:00
|
|
|
new->prev = dir_stack_base;
|
|
|
|
dir_stack_base = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
|
|
|
pop_directory (void)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
dir_stack *next;
|
|
|
|
|
|
|
|
if (dir_stack_base){
|
|
|
|
name = dir_stack_base->name;
|
|
|
|
next = dir_stack_base->prev;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (dir_stack_base);
|
1998-02-27 07:54:42 +03:00
|
|
|
dir_stack_base = next;
|
|
|
|
return name;
|
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
insert_file (char *dir, char *file)
|
|
|
|
{
|
|
|
|
char *tmp_name;
|
|
|
|
static char *dirname;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (dir [0] == PATH_SEP && dir [1] == PATH_SEP)
|
|
|
|
dir++;
|
|
|
|
i = strlen (dir);
|
|
|
|
if (i){
|
|
|
|
if (dir [i - 1] != PATH_SEP){
|
|
|
|
dir [i] = PATH_SEP;
|
|
|
|
dir [i + 1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_dir){
|
|
|
|
if (strcmp (old_dir, dir)){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (old_dir);
|
|
|
|
old_dir = g_strdup (dir);
|
1999-02-11 08:52:55 +03:00
|
|
|
dirname = add_to_list (dir, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
} else {
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
old_dir = g_strdup (dir);
|
1999-02-11 08:52:55 +03:00
|
|
|
dirname = add_to_list (dir, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
tmp_name = g_strconcat (" ", file, NULL);
|
1999-02-11 08:52:55 +03:00
|
|
|
add_to_list (tmp_name, dirname);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (tmp_name);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
find_add_match (Dlg_head *h, char *dir, char *file)
|
|
|
|
{
|
|
|
|
int p = ++matches & 7;
|
|
|
|
|
|
|
|
insert_file (dir, file);
|
1999-02-11 08:52:55 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Scroll nicely */
|
|
|
|
if (!p)
|
|
|
|
listbox_select_last (find_list, 1);
|
|
|
|
else
|
|
|
|
listbox_select_last (find_list, 0);
|
|
|
|
/* Updates the current listing */
|
|
|
|
send_message (h, &find_list->widget, WIDGET_DRAW, 0);
|
|
|
|
if (p == 7)
|
|
|
|
mc_refresh ();
|
|
|
|
}
|
|
|
|
|
2001-09-23 08:06:35 +04:00
|
|
|
/*
|
|
|
|
* get_line_at:
|
|
|
|
*
|
|
|
|
* Returns malloced null-terminated line from file file_fd.
|
|
|
|
* Input is buffered in buf_size long buffer.
|
|
|
|
* Current pos in buf is stored in pos.
|
|
|
|
* n_read - number of read chars.
|
|
|
|
* has_newline - is there newline ?
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
get_line_at (int file_fd, char *buf, int *pos, int *n_read, int buf_size, int *has_newline)
|
|
|
|
{
|
|
|
|
char *buffer = 0;
|
|
|
|
int buffer_size = 0;
|
|
|
|
char ch = 0;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (*pos >= *n_read){
|
|
|
|
*pos = 0;
|
|
|
|
if ((*n_read = mc_read (file_fd, buf, buf_size)) <= 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ch = buf [(*pos)++];
|
|
|
|
if (ch == 0) {
|
|
|
|
/* skip possible leading zero(s) */
|
|
|
|
if (i == 0)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= buffer_size - 1){
|
|
|
|
buffer = g_realloc (buffer, buffer_size += 80);
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer [i++] = ch;
|
|
|
|
|
|
|
|
} while (ch != '\n');
|
|
|
|
|
|
|
|
*has_newline = ch ? 1 : 0;
|
|
|
|
|
|
|
|
if (buffer){
|
|
|
|
buffer [i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/*
|
|
|
|
* search_content:
|
|
|
|
*
|
2002-02-28 16:50:03 +03:00
|
|
|
* Search the global (FIXME) regexp compiled content_pattern string in the
|
1998-02-27 07:54:42 +03:00
|
|
|
* DIRECTORY/FILE. It will add the found entries to the find listbox.
|
|
|
|
*/
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
1998-02-27 07:54:42 +03:00
|
|
|
search_content (Dlg_head *h, char *directory, char *filename)
|
|
|
|
{
|
|
|
|
struct stat s;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
char buffer [BUF_SMALL];
|
2001-09-23 08:06:35 +04:00
|
|
|
char *fname;
|
|
|
|
int file_fd;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
fname = concat_dir_and_file (directory, filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2001-04-24 18:39:38 +04:00
|
|
|
if (mc_stat (fname, &s) != 0 || !S_ISREG (s.st_mode)){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (fname);
|
1998-02-27 07:54:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-04-24 18:39:38 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
file_fd = mc_open (fname, O_RDONLY);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (fname);
|
2001-04-27 14:07:45 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (file_fd == -1)
|
|
|
|
return;
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_snprintf (buffer, sizeof (buffer), _("Grepping in %s"), name_trunc (filename, FIND2_X_USE));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
status_update (buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
mc_refresh ();
|
2001-04-27 14:07:45 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
enable_interrupt_key ();
|
|
|
|
got_interrupt ();
|
2001-04-24 18:39:38 +04:00
|
|
|
|
2002-02-28 16:50:03 +03:00
|
|
|
{
|
2001-09-23 08:06:35 +04:00
|
|
|
int line = 1;
|
|
|
|
int pos = 0;
|
|
|
|
int n_read = 0;
|
|
|
|
int has_newline;
|
|
|
|
char *p;
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
while ((p = get_line_at (file_fd, buffer, &pos, &n_read, sizeof (buffer), &has_newline))){
|
|
|
|
if (found == 0){ /* Search in binary line once */
|
2002-02-28 16:50:03 +03:00
|
|
|
if (regexec (r, p, 1, 0, 0) == 0){
|
2001-09-23 08:06:35 +04:00
|
|
|
g_free (p);
|
|
|
|
p = g_strdup_printf ("%d:%s", line, filename);
|
|
|
|
find_add_match (h, directory, p);
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (has_newline){
|
|
|
|
line++;
|
|
|
|
found = 0;
|
|
|
|
}
|
|
|
|
g_free (p);
|
2001-04-27 14:07:45 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
disable_interrupt_key ();
|
|
|
|
mc_close (file_fd);
|
|
|
|
}
|
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
static int
|
1998-02-27 07:54:42 +03:00
|
|
|
do_search (struct Dlg_head *h)
|
|
|
|
{
|
|
|
|
static struct dirent *dp = 0;
|
|
|
|
static DIR *dirp = 0;
|
|
|
|
static char directory [MC_MAXPATHLEN+2];
|
|
|
|
struct stat tmp_stat;
|
|
|
|
static int pos;
|
|
|
|
static int subdirs_left = 0;
|
2001-09-23 08:06:35 +04:00
|
|
|
char *tmp_name; /* For building file names */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (!h) { /* someone forces me to close dirp */
|
|
|
|
if (dirp) {
|
|
|
|
mc_closedir (dirp);
|
|
|
|
dirp = 0;
|
|
|
|
}
|
|
|
|
dp = 0;
|
1999-02-11 08:52:55 +03:00
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
do_search_begin:
|
|
|
|
while (!dp){
|
|
|
|
|
|
|
|
if (dirp){
|
|
|
|
mc_closedir (dirp);
|
|
|
|
dirp = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!dirp){
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
attrset (REVERSE_COLOR);
|
|
|
|
while (1) {
|
|
|
|
tmp = pop_directory ();
|
|
|
|
if (!tmp){
|
|
|
|
running = 0;
|
1999-02-11 08:52:55 +03:00
|
|
|
status_update (_("Finished"));
|
|
|
|
stop_idle (h);
|
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
if (find_ignore_dirs){
|
1998-12-29 19:52:49 +03:00
|
|
|
int found;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
char *temp_dir = g_strconcat (":", tmp, ":", NULL);
|
1998-12-29 19:52:49 +03:00
|
|
|
|
|
|
|
found = strstr (find_ignore_dirs, temp_dir) != 0;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (temp_dir);
|
1998-12-29 19:52:49 +03:00
|
|
|
if (found)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (tmp);
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy (directory, tmp);
|
2001-04-27 14:07:45 +04:00
|
|
|
g_free (tmp);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (verbose){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
char buffer [BUF_SMALL];
|
1998-02-27 07:54:42 +03:00
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_snprintf (buffer, sizeof (buffer), _("Searching %s"), name_trunc (directory, FIND2_X_USE));
|
1999-02-11 08:52:55 +03:00
|
|
|
status_update (buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1999-04-25 23:57:53 +04:00
|
|
|
/* mc_stat should not be called after mc_opendir
|
|
|
|
because vfs_s_opendir modifies the st_nlink
|
|
|
|
*/
|
1998-02-27 07:54:42 +03:00
|
|
|
mc_stat (directory, &tmp_stat);
|
|
|
|
subdirs_left = tmp_stat.st_nlink - 2;
|
|
|
|
/* Commented out as unnecessary
|
|
|
|
if (subdirs_left < 0)
|
|
|
|
subdirs_left = MAXINT;
|
|
|
|
*/
|
1999-04-25 23:57:53 +04:00
|
|
|
dirp = mc_opendir (directory);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
dp = mc_readdir (dirp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp (dp->d_name, ".") == 0 ||
|
|
|
|
strcmp (dp->d_name, "..") == 0){
|
|
|
|
dp = mc_readdir (dirp);
|
1999-02-11 08:52:55 +03:00
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
tmp_name = concat_dir_and_file (directory, dp->d_name);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (subdirs_left){
|
|
|
|
mc_lstat (tmp_name, &tmp_stat);
|
|
|
|
if (S_ISDIR (tmp_stat.st_mode)){
|
|
|
|
push_directory (tmp_name);
|
|
|
|
subdirs_left--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (regexp_match (find_pattern, dp->d_name, match_file)){
|
|
|
|
if (content_pattern)
|
|
|
|
search_content (h, directory, dp->d_name);
|
|
|
|
else
|
|
|
|
find_add_match (h, directory, dp->d_name);
|
|
|
|
}
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (tmp_name);
|
1998-02-27 07:54:42 +03:00
|
|
|
dp = mc_readdir (dirp);
|
|
|
|
|
|
|
|
/* Displays the nice dot */
|
|
|
|
count++;
|
|
|
|
if (!(count & 31)){
|
2001-04-27 14:07:45 +04:00
|
|
|
/* For nice updating */
|
|
|
|
char *rotating_dash = "|/-\\";
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (verbose){
|
1998-04-15 10:05:34 +04:00
|
|
|
pos = (pos + 1) % 4;
|
1998-02-27 07:54:42 +03:00
|
|
|
attrset (NORMALC);
|
|
|
|
dlg_move (h, FIND2_Y-6, FIND2_X - 4);
|
|
|
|
addch (rotating_dash [pos]);
|
|
|
|
mc_refresh ();
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
goto do_search_begin;
|
1999-02-11 08:52:55 +03:00
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
static void
|
|
|
|
init_find_vars (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1999-02-11 08:52:55 +03:00
|
|
|
char *dir;
|
|
|
|
|
|
|
|
if (old_dir){
|
|
|
|
g_free (old_dir);
|
|
|
|
old_dir = 0;
|
|
|
|
}
|
|
|
|
count = 0;
|
|
|
|
matches = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
/* Remove all the items in the stack */
|
|
|
|
while ((dir = pop_directory ()) != NULL)
|
|
|
|
g_free (dir);
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
static void
|
|
|
|
find_do_view_edit (int unparsed_view, int edit, char *dir, char *file)
|
|
|
|
{
|
|
|
|
char *fullname, *filename;
|
|
|
|
int line;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (content_pattern){
|
1999-02-11 08:52:55 +03:00
|
|
|
filename = strchr (file + 4, ':') + 1;
|
|
|
|
line = atoi (file + 4);
|
1998-02-27 07:54:42 +03:00
|
|
|
} else {
|
1999-02-11 08:52:55 +03:00
|
|
|
filename = file + 4;
|
1998-02-27 07:54:42 +03:00
|
|
|
line = 0;
|
|
|
|
}
|
|
|
|
if (dir [0] == '.' && dir [1] == 0)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
fullname = g_strdup (filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
else if (dir [0] == '.' && dir [1] == PATH_SEP)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
fullname = concat_dir_and_file (dir+2, filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
fullname = concat_dir_and_file (dir, filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (edit)
|
|
|
|
do_edit_at_line (fullname, line);
|
|
|
|
else
|
|
|
|
view_file_at_line (fullname, unparsed_view, use_internal_view, line);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (fullname);
|
1999-02-11 08:52:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_list_info (char **file, char **dir)
|
|
|
|
{
|
|
|
|
listbox_get_current (find_list, file, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
add_to_list (char *text, void *data)
|
|
|
|
{
|
1999-02-13 00:58:05 +03:00
|
|
|
return listbox_add_item (find_list, 0, 0, text, data);
|
1999-02-11 08:52:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stop_idle (void *data)
|
|
|
|
{
|
|
|
|
set_idle_proc (data, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
view_edit_currently_selected_file (int unparsed_view, int edit)
|
|
|
|
{
|
|
|
|
WLEntry *entry = find_list->current;
|
|
|
|
char *dir;
|
|
|
|
|
|
|
|
if (!entry)
|
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
|
|
|
dir = entry->data;
|
|
|
|
|
|
|
|
if (!entry->text || !dir)
|
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
|
|
|
find_do_view_edit (unparsed_view, edit, dir, entry->text);
|
1998-02-27 07:54:42 +03:00
|
|
|
return MSG_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_callback (struct Dlg_head *h, int id, int Msg)
|
|
|
|
{
|
|
|
|
switch (Msg){
|
|
|
|
case DLG_DRAW:
|
|
|
|
common_dialog_repaint (h);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLG_KEY:
|
|
|
|
if (id == KEY_F(3) || id == KEY_F(13)){
|
|
|
|
int unparsed_view = (id == KEY_F(13));
|
|
|
|
return view_edit_currently_selected_file (unparsed_view, 0);
|
|
|
|
}
|
|
|
|
if (id == KEY_F(4)){
|
|
|
|
return view_edit_currently_selected_file (0, 1);
|
|
|
|
}
|
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
|
|
|
case DLG_IDLE:
|
|
|
|
do_search (h);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handles the Stop/Start button in the find window */
|
|
|
|
static int
|
|
|
|
start_stop (int button, void *extra)
|
|
|
|
{
|
|
|
|
running = is_start;
|
|
|
|
set_idle_proc (find_dlg, running);
|
|
|
|
is_start = !is_start;
|
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
status_update (is_start ? _("Stopped") : _("Searching"));
|
1998-04-08 22:50:24 +04:00
|
|
|
button_set_text (stop_button, fbuts [is_start].text);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle view command, when invoked as a button */
|
|
|
|
static int
|
|
|
|
find_do_view_file (int button, void *extra)
|
|
|
|
{
|
|
|
|
view_edit_currently_selected_file (0, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle edit command, when invoked as a button */
|
|
|
|
static int
|
|
|
|
find_do_edit_file (int button, void *extra)
|
|
|
|
{
|
|
|
|
view_edit_currently_selected_file (0, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-02-11 08:52:55 +03:00
|
|
|
setup_gui (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-04-08 22:50:24 +04:00
|
|
|
#ifdef ENABLE_NLS
|
2002-09-04 00:04:54 +04:00
|
|
|
static int i18n_flag = 0;
|
|
|
|
if (!i18n_flag) {
|
|
|
|
register int i = sizeof (fbuts) / sizeof (fbuts[0]);
|
|
|
|
while (i--)
|
|
|
|
fbuts[i].len = strlen (fbuts[i].text = _(fbuts[i].text)) + 3;
|
|
|
|
fbuts[2].len += 2; /* DEFPUSH_BUTTON */
|
|
|
|
i18n_flag = 1;
|
|
|
|
}
|
|
|
|
#endif /* ENABLE_NLS */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dynamically place buttons centered within current window size
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int l0 = max (fbuts[0].len, fbuts[1].len);
|
|
|
|
int l1 = fbuts[2].len + fbuts[3].len + l0 + fbuts[4].len;
|
|
|
|
int l2 = fbuts[5].len + fbuts[6].len + fbuts[7].len;
|
|
|
|
int r1, r2;
|
|
|
|
|
|
|
|
FIND2_X = COLS - 16;
|
|
|
|
|
|
|
|
/* Check, if both button rows fit within FIND2_X */
|
|
|
|
if (l1 + 9 > FIND2_X)
|
|
|
|
FIND2_X = l1 + 9;
|
|
|
|
if (l2 + 8 > FIND2_X)
|
|
|
|
FIND2_X = l2 + 8;
|
|
|
|
|
|
|
|
/* compute amount of space between buttons for each row */
|
|
|
|
r1 = (FIND2_X - 4 - l1) % 5;
|
|
|
|
l1 = (FIND2_X - 4 - l1) / 5;
|
|
|
|
r2 = (FIND2_X - 4 - l2) % 4;
|
|
|
|
l2 = (FIND2_X - 4 - l2) / 4;
|
|
|
|
|
|
|
|
/* ...and finally, place buttons */
|
|
|
|
fbuts[2].x = 2 + r1 / 2 + l1;
|
|
|
|
fbuts[3].x = fbuts[2].x + fbuts[2].len + l1;
|
|
|
|
fbuts[0].x = fbuts[3].x + fbuts[3].len + l1;
|
|
|
|
fbuts[4].x = fbuts[0].x + l0 + l1;
|
|
|
|
fbuts[5].x = 2 + r2 / 2 + l2;
|
|
|
|
fbuts[6].x = fbuts[5].x + fbuts[5].len + l2;
|
|
|
|
fbuts[7].x = fbuts[6].x + fbuts[6].len + l2;
|
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
find_dlg = create_dlg (0, 0, FIND2_Y, FIND2_X, dialog_colors,
|
2002-09-04 00:04:54 +04:00
|
|
|
find_callback, "[Find File]", _("Find File"),
|
|
|
|
DLG_CENTER);
|
|
|
|
|
|
|
|
add_widget (find_dlg,
|
|
|
|
button_new (FIND2_Y - 3, fbuts[7].x, B_VIEW, NORMAL_BUTTON,
|
|
|
|
fbuts[7].text, find_do_edit_file, find_dlg,
|
|
|
|
"button-edit"));
|
|
|
|
add_widget (find_dlg,
|
|
|
|
button_new (FIND2_Y - 3, fbuts[6].x, B_VIEW, NORMAL_BUTTON,
|
|
|
|
fbuts[6].text, find_do_view_file, find_dlg,
|
|
|
|
"button-view"));
|
|
|
|
add_widget (find_dlg,
|
|
|
|
button_new (FIND2_Y - 3, fbuts[5].x, B_PANELIZE,
|
|
|
|
NORMAL_BUTTON, fbuts[5].text, 0, 0,
|
|
|
|
"button-panelize"));
|
|
|
|
|
|
|
|
add_widget (find_dlg,
|
|
|
|
button_new (FIND2_Y - 4, fbuts[4].x, B_CANCEL,
|
|
|
|
NORMAL_BUTTON, fbuts[4].text, 0, 0,
|
|
|
|
"button-quit"));
|
|
|
|
stop_button =
|
|
|
|
button_new (FIND2_Y - 4, fbuts[0].x, B_STOP, NORMAL_BUTTON,
|
|
|
|
fbuts[0].text, start_stop, find_dlg, "start-stop");
|
|
|
|
add_widget (find_dlg, stop_button);
|
|
|
|
add_widget (find_dlg,
|
|
|
|
button_new (FIND2_Y - 4, fbuts[3].x, B_AGAIN,
|
|
|
|
NORMAL_BUTTON, fbuts[3].text, 0, 0,
|
|
|
|
"button-again"));
|
|
|
|
add_widget (find_dlg,
|
|
|
|
button_new (FIND2_Y - 4, fbuts[2].x, B_ENTER,
|
|
|
|
DEFPUSH_BUTTON, fbuts[2].text, 0, 0,
|
|
|
|
"button-chdir"));
|
|
|
|
|
|
|
|
status_label =
|
|
|
|
label_new (FIND2_Y - 6, 4, _("Searching"), "label-search");
|
2001-04-07 01:48:11 +04:00
|
|
|
add_widget (find_dlg, status_label);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-09-04 00:04:54 +04:00
|
|
|
find_list =
|
|
|
|
listbox_new (2, 2, FIND2_X - 4, FIND2_Y - 9, listbox_finish, 0,
|
|
|
|
"listbox");
|
2001-04-07 01:48:11 +04:00
|
|
|
add_widget (find_dlg, find_list);
|
1999-02-11 08:52:55 +03:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
static int
|
|
|
|
run_process (void)
|
|
|
|
{
|
|
|
|
set_idle_proc (find_dlg, 1);
|
|
|
|
run_dlg (find_dlg);
|
|
|
|
return find_dlg->ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
status_update (char *text)
|
|
|
|
{
|
|
|
|
label_set_text (status_label, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
kill_gui (void)
|
|
|
|
{
|
|
|
|
set_idle_proc (find_dlg, 0);
|
|
|
|
destroy_dlg (find_dlg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
find_file (char *start_dir, char *pattern, char *content, char **dirname, char **filename)
|
|
|
|
{
|
|
|
|
int return_value = 0;
|
|
|
|
char *dir;
|
|
|
|
char *dir_tmp, *file_tmp;
|
|
|
|
|
|
|
|
setup_gui ();
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* FIXME: Need to cleanup this, this ought to be passed non-globaly */
|
|
|
|
find_pattern = pattern;
|
|
|
|
content_pattern = content;
|
|
|
|
|
|
|
|
init_find_vars ();
|
|
|
|
push_directory (start_dir);
|
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
return_value = run_process ();
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Remove all the items in the stack */
|
|
|
|
while ((dir = pop_directory ()) != NULL)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (dir);
|
1999-02-11 08:52:55 +03:00
|
|
|
|
|
|
|
get_list_info (&file_tmp, &dir_tmp);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (dir_tmp)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
*dirname = g_strdup (dir_tmp);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (file_tmp)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
*filename = g_strdup (file_tmp);
|
1999-02-11 08:52:55 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (return_value == B_PANELIZE && *filename){
|
2002-10-14 02:23:17 +04:00
|
|
|
int status, link_to_dir, stale_link;
|
1998-02-27 07:54:42 +03:00
|
|
|
int next_free = 0;
|
|
|
|
int i;
|
|
|
|
struct stat buf;
|
|
|
|
WLEntry *entry = find_list->list;
|
|
|
|
dir_list *list = &cpanel->dir;
|
|
|
|
char *dir, *name;
|
|
|
|
|
|
|
|
for (i = 0; entry && i < find_list->count; entry = entry->next, i++){
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
if (content_pattern)
|
|
|
|
filename = strchr (entry->text+4, ':')+1;
|
|
|
|
else
|
|
|
|
filename = entry->text+4;
|
|
|
|
|
|
|
|
if (!entry->text || !entry->data)
|
|
|
|
continue;
|
|
|
|
dir = entry->data;
|
|
|
|
if (dir [0] == '.' && dir [1] == 0)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
name = g_strdup (filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
else if (dir [0] == '.' && dir [1] == PATH_SEP)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
name = concat_dir_and_file (dir + 2, filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
name = concat_dir_and_file (dir, filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
status = handle_path (list, name, &buf, next_free, &link_to_dir,
|
2002-10-14 02:23:17 +04:00
|
|
|
&stale_link);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (status == 0) {
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (name);
|
1998-02-27 07:54:42 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (status == -1) {
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (name);
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't add files more than once to the panel */
|
|
|
|
if (content_pattern && next_free > 0){
|
|
|
|
if (strcmp (list->list [next_free-1].fname, name) == 0) {
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (name);
|
1998-02-27 07:54:42 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!next_free) /* first turn i.e clean old list */
|
1999-03-03 00:33:48 +03:00
|
|
|
panel_clean_dir (cpanel);
|
1998-02-27 07:54:42 +03:00
|
|
|
list->list [next_free].fnamelen = strlen (name);
|
|
|
|
list->list [next_free].fname = name;
|
|
|
|
file_mark (cpanel, next_free, 0);
|
|
|
|
list->list [next_free].f.link_to_dir = link_to_dir;
|
2002-10-14 02:23:17 +04:00
|
|
|
list->list [next_free].f.stale_link = stale_link;
|
1998-12-25 00:37:24 +03:00
|
|
|
list->list [next_free].f.dir_size_computed = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
list->list [next_free].buf = buf;
|
|
|
|
next_free++;
|
|
|
|
if (!(next_free & 15))
|
|
|
|
rotate_dash ();
|
|
|
|
}
|
|
|
|
if (next_free){
|
|
|
|
cpanel->count = next_free;
|
|
|
|
cpanel->is_panelized = 1;
|
1999-03-03 00:33:48 +03:00
|
|
|
/* Done by panel_clean_dir a few lines above
|
1998-02-27 07:54:42 +03:00
|
|
|
cpanel->dirs_marked = 0;
|
|
|
|
cpanel->marked = 0;
|
|
|
|
cpanel->total = 0;
|
|
|
|
cpanel->top_file = 0;
|
1999-03-03 00:33:48 +03:00
|
|
|
cpanel->selected = 0;*/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (start_dir [0] == PATH_SEP){
|
|
|
|
strcpy (cpanel->cwd, PATH_SEP_STR);
|
|
|
|
chdir (PATH_SEP_STR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-11 08:52:55 +03:00
|
|
|
kill_gui ();
|
1998-02-27 07:54:42 +03:00
|
|
|
do_search (0); /* force do_search to release resources */
|
|
|
|
if (old_dir){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (old_dir);
|
1998-02-27 07:54:42 +03:00
|
|
|
old_dir = 0;
|
|
|
|
}
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
do_find (void)
|
|
|
|
{
|
|
|
|
char *start_dir, *pattern, *content;
|
|
|
|
char *filename, *dirname;
|
|
|
|
int v, dir_and_file_set;
|
2002-02-28 16:50:03 +03:00
|
|
|
regex_t rx; /* Compiled content_pattern to search inside files */
|
|
|
|
|
|
|
|
for (r = ℞ find_parameters (&start_dir, &pattern, &content); r = &rx){
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
dirname = filename = NULL;
|
|
|
|
is_start = 0;
|
|
|
|
v = find_file (start_dir, pattern, content, &dirname, &filename);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (start_dir);
|
|
|
|
g_free (pattern);
|
2002-02-28 16:50:03 +03:00
|
|
|
if (r)
|
|
|
|
regfree (r);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (v == B_ENTER){
|
|
|
|
if (dirname || filename){
|
|
|
|
if (dirname){
|
|
|
|
do_cd (dirname, cd_exact);
|
|
|
|
if (filename)
|
|
|
|
try_to_select (cpanel, filename + (content ?
|
|
|
|
(strchr (filename + 4, ':') - filename + 1) : 4) );
|
|
|
|
} else if (filename)
|
|
|
|
do_cd (filename, cd_exact);
|
|
|
|
paint_panel (cpanel);
|
|
|
|
select_item (cpanel);
|
|
|
|
}
|
|
|
|
if (dirname)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (dirname);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (filename)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (content)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (content);
|
1998-02-27 07:54:42 +03:00
|
|
|
dir_and_file_set = dirname && filename;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
if (dirname) g_free (dirname);
|
|
|
|
if (filename) g_free (filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (v == B_CANCEL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (v == B_PANELIZE){
|
|
|
|
if (dir_and_file_set){
|
|
|
|
try_to_select (cpanel, NULL);
|
2001-11-14 22:59:31 +03:00
|
|
|
panel_re_sort (cpanel);
|
1998-02-27 07:54:42 +03:00
|
|
|
paint_panel (cpanel);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|