1
1

Ticket #2097: clean up before 4.7.2 release.

Split assignments and conditions. Type accuracy. Minor optimization.

Thanks Vit Rosin for original patch.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2010-03-30 22:59:41 +04:00
родитель bfd0b2c995
Коммит 4cea5be1ac
33 изменённых файлов: 649 добавлений и 525 удалений

Просмотреть файл

@ -67,7 +67,8 @@ mc_log(const char *fmt, ...)
if (is_logging_enabled()) {
va_start(args, fmt);
logfilename = g_strdup_printf("%s/%s/log", home_dir, MC_USERCONF_DIR);
if ((f = fopen(logfilename, "a")) != NULL) {
f = fopen (logfilename, "a");
if (f != NULL) {
(void)vfprintf(f, fmt, args);
(void)fclose(f);
}

Просмотреть файл

@ -526,13 +526,15 @@ strip_password (char *p, int has_prefix)
if (has_prefix)
{
if ((q = strstr (p, prefixes[i].name)) == 0)
q = strstr (p, prefixes[i].name);
if (q == NULL)
continue;
else
p = q + prefixes[i].len;
}
if ((dir = strchr (p, PATH_SEP)) != NULL)
dir = strchr (p, PATH_SEP);
if (dir != NULL)
*dir = '\0';
/* search for any possible user */
@ -559,7 +561,8 @@ strip_home_and_password (const char *dir)
size_t len;
static char newdir[MC_MAXPATHLEN];
if (home_dir && !strncmp (dir, home_dir, len = strlen (home_dir)) &&
len = strlen (home_dir);
if (home_dir != NULL && strncmp (dir, home_dir, len) == 0 &&
(dir[len] == PATH_SEP || dir[len] == '\0'))
{
newdir[0] = '~';
@ -619,7 +622,8 @@ load_file (const char *filename)
char *data;
long read_size;
if ((data_file = fopen (filename, "r")) == NULL)
data_file = fopen (filename, "r");
if (data_file == NULL)
{
return 0;
}

Просмотреть файл

@ -94,11 +94,12 @@ get_owner (int uid)
char *name;
static int uid_last;
if ((name = i_cache_match (uid, uid_cache, UID_CACHE_SIZE)) != NULL)
name = i_cache_match (uid, uid_cache, UID_CACHE_SIZE);
if (name != NULL)
return name;
pwd = getpwuid (uid);
if (pwd)
if (pwd != NULL)
{
i_cache_add (uid, uid_cache, UID_CACHE_SIZE, pwd->pw_name, &uid_last);
return pwd->pw_name;
@ -118,11 +119,12 @@ get_group (int gid)
char *name;
static int gid_last;
if ((name = i_cache_match (gid, gid_cache, GID_CACHE_SIZE)) != NULL)
name = i_cache_match (gid, gid_cache, GID_CACHE_SIZE);
if (name != NULL)
return name;
grp = getgrgid (gid);
if (grp)
if (grp != NULL)
{
i_cache_add (gid, gid_cache, GID_CACHE_SIZE, grp->gr_name, &gid_last);
return grp->gr_name;
@ -161,7 +163,8 @@ my_system (int flags, const char *shell, const char *command)
/* handler messing the screen after the SIGCONT */
sigaction (SIGTSTP, &startup_handler, &save_stop);
if ((pid = fork ()) < 0)
pid = fork ();
if (pid < 0)
{
fprintf (stderr, "\n\nfork () = -1\n");
return -1;
@ -179,12 +182,12 @@ my_system (int flags, const char *shell, const char *command)
{
gchar **shell_tokens;
const gchar *only_cmd;
shell_tokens = g_strsplit (shell, " ", 2);
shell_tokens = g_strsplit (shell, " ", 2);
if (shell_tokens == NULL)
only_cmd = shell;
else
only_cmd = (*shell_tokens) ? *shell_tokens : shell;
only_cmd = (*shell_tokens != NULL) ? *shell_tokens : shell;
execlp (only_cmd, shell, command, (char *) NULL);

Просмотреть файл

@ -165,7 +165,8 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super,
mode_t mode;
struct vfs_s_inode *root;
if ((fd = mc_open (name, O_RDONLY)) == -1) {
fd = mc_open (name, O_RDONLY);
if (fd == -1) {
message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), name);
return -1;
}
@ -181,7 +182,8 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super,
mc_close (fd);
s = g_strconcat (name, decompress_extension (type), (char *) NULL);
if ((fd = mc_open (s, O_RDONLY)) == -1) {
fd = mc_open (s, O_RDONLY);
if (fd == -1) {
message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), s);
g_free (s);
return -1;
@ -247,7 +249,8 @@ static int cpio_find_head(struct vfs_class *me, struct vfs_s_super *super)
ptr -= top - 128;
top = 128;
}
if((tmp = mc_read(super->u.arch.fd, buf, top)) == 0 || tmp == -1) {
tmp = mc_read (super->u.arch.fd, buf, top);
if (tmp == 0 || tmp == -1) {
message (D_ERROR, MSG_ERROR, _("Premature end of cpio archive\n%s"), super->name);
cpio_free_archive(me, super);
return CPIO_UNKNOWN;
@ -419,7 +422,8 @@ static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *supe
char *name;
struct stat st;
if((len = mc_read(super->u.arch.fd, (char *)&u.buf, HEAD_LENGTH)) < HEAD_LENGTH)
len = mc_read (super->u.arch.fd, (char *)&u.buf, HEAD_LENGTH);
if (len < HEAD_LENGTH)
return STATUS_EOF;
CPIO_POS(super) += len;
if(super->u.arch.type == CPIO_BINRE) {
@ -435,7 +439,8 @@ static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *supe
return STATUS_FAIL;
}
name = g_malloc(u.buf.c_namesize);
if((len = mc_read(super->u.arch.fd, name, u.buf.c_namesize)) < u.buf.c_namesize) {
len = mc_read (super->u.arch.fd, name, u.buf.c_namesize);
if (len < u.buf.c_namesize) {
g_free(name);
return STATUS_EOF;
}
@ -493,8 +498,8 @@ static ssize_t cpio_read_oldc_head(struct vfs_class *me, struct vfs_s_super *sup
return STATUS_FAIL;
}
name = g_malloc(hd.c_namesize);
if((len = mc_read(super->u.arch.fd, name, hd.c_namesize)) == -1 ||
(unsigned long) len < hd.c_namesize) {
len = mc_read (super->u.arch.fd, name, hd.c_namesize);
if ((len == -1) || ((unsigned long) len < hd.c_namesize)) {
g_free (name);
return STATUS_EOF;
}
@ -669,7 +674,9 @@ static ssize_t cpio_read(void *fh, char *buffer, int count)
count = MIN(count, FH->ino->st.st_size - FH->pos);
if ((count = mc_read (fd, buffer, count)) == -1) ERRNOR (errno, -1);
count = mc_read (fd, buffer, count);
if (count == -1)
ERRNOR (errno, -1);
FH->pos += count;
return count;

Просмотреть файл

@ -493,11 +493,14 @@ vfs_s_get_path_mangle (struct vfs_class *me, char *inname, struct vfs_s_super **
archive_name = inname;
vfs_split (inname, &local, &op);
retval = (local) ? local : "";
retval = (local != NULL) ? local : "";
if (MEDATA->archive_check)
if (!(cookie = MEDATA->archive_check (me, archive_name, op)))
if (MEDATA->archive_check != NULL)
{
cookie = MEDATA->archive_check (me, archive_name, op);
if (cookie == NULL)
return NULL;
}
for (super = MEDATA->supers; super != NULL; super = super->next)
{
@ -686,7 +689,9 @@ static int
vfs_s_chdir (struct vfs_class *me, const char *path)
{
void *data;
if (!(data = vfs_s_opendir (me, path)))
data = vfs_s_opendir (me, path);
if (data == NULL)
return -1;
vfs_s_closedir (data);
return 0;
@ -699,7 +704,8 @@ vfs_s_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, i
{
struct vfs_s_inode *ino;
if (!(ino = vfs_s_inode_from_path (me, path, flag)))
ino = vfs_s_inode_from_path (me, path, flag);
if (ino == NULL)
return -1;
*buf = ino->st;
return 0;
@ -757,7 +763,8 @@ vfs_s_open (struct vfs_class *me, const char *file, int flags, int mode)
char *q;
struct vfs_s_inode *ino;
if ((q = vfs_s_get_path (me, file, &super, 0)) == NULL)
q = vfs_s_get_path (me, file, &super, 0);
if (q == NULL)
return NULL;
ino = vfs_s_find_inode (me, super, q, LINK_FOLLOW, FL_NONE);
if (ino && ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)))
@ -1115,7 +1122,7 @@ vfs_s_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
{
struct vfs_s_inode *ino = vfs_s_inode_from_path (me, path, 0);
if (!ino)
if (ino == NULL)
return 0;
if (arg)
ino->super->want_stale = 1;
@ -1142,10 +1149,11 @@ vfs_s_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
static vfsid
vfs_s_getid (struct vfs_class *me, const char *path)
{
struct vfs_s_super *archive;
struct vfs_s_super *archive = NULL;
char *p;
if (!(p = vfs_s_get_path (me, path, &archive, FL_NO_OPEN)))
p = vfs_s_get_path (me, path, &archive, FL_NO_OPEN);
if (p == NULL)
return NULL;
g_free (p);
return (vfsid) archive;

Просмотреть файл

@ -206,7 +206,9 @@ fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[])
if ((pipe (fileset1) < 0) || (pipe (fileset2) < 0))
vfs_die ("Cannot pipe(): %m.");
if ((res = fork ()))
res = fork ();
if (res != 0)
{
if (res < 0)
vfs_die ("Cannot fork(): %m.");
@ -828,18 +830,17 @@ fish_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *lo
close (h);
h = open ("/dev/zero", O_RDONLY);
}
if (n == 0)
break;
if ((t = write (SUP.sockw, buffer, n)) != n)
t = write (SUP.sockw, buffer, n);
if (t != n)
{
if (t == -1)
{
me->verrno = errno;
}
else
{
me->verrno = EIO;
}
goto error_return;
}
tty_disable_interrupt_key ();
@ -923,14 +924,15 @@ fish_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh)
do
{
n = MIN (8192, fh->u.fish.total - fh->u.fish.got);
if (n)
if (n != 0)
{
if ((n = read (SUP.sockr, buffer, n)) < 0)
n = read (SUP.sockr, buffer, n);
if (n < 0)
return;
fh->u.fish.got += n;
}
}
while (n);
while (n != 0);
if (fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE)
print_vfs_message (_("Error reported after abort."));
@ -955,9 +957,9 @@ fish_linear_read (struct vfs_class *me, struct vfs_s_fh *fh, void *buf, int len)
if (n > 0)
fh->u.fish.got += n;
if (n < 0)
else if (n < 0)
fish_linear_abort (me, fh);
if ((!n) && ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE)))
else if (fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE)
ERRNOR (E_REMOTE, -1);
ERRNOR (errno, n);
}
@ -1018,17 +1020,18 @@ fish_send_command (struct vfs_class *me, struct vfs_s_super *super, const char *
const char *crpath; \
char *rpath, *mpath = g_strdup (path); \
struct vfs_s_super *super; \
if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) \
crpath = vfs_s_get_path_mangle (me, mpath, &super, 0); \
if (crpath == NULL) \
{ \
g_free (mpath); \
return -1; \
} \
rpath = strutils_shell_escape(crpath); \
rpath = strutils_shell_escape (crpath); \
g_free (mpath);
#define POSTFIX(flags) \
g_free (rpath); \
return fish_send_command(me, super, buf, flags);
return fish_send_command (me, super, buf, flags);
static int
fish_chmod (struct vfs_class *me, const char *path, int mode)
@ -1055,12 +1058,14 @@ static int fish_##name (struct vfs_class *me, const char *path1, const char *pat
const char *crpath1, *crpath2; \
char *rpath1, *rpath2, *mpath1, *mpath2; \
struct vfs_s_super *super1, *super2; \
if (!(crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0))) \
crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0); \
if (crpath1 == NULL) \
{ \
g_free (mpath1); \
return -1; \
} \
if (!(crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0))) \
crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0); \
if (crpath2 == NULL) \
{ \
g_free (mpath1); \
g_free (mpath2); \
@ -1119,10 +1124,12 @@ fish_chown (struct vfs_class *me, const char *path, int owner, int group)
struct passwd *pw;
struct group *gr;
if ((pw = getpwuid (owner)) == NULL)
pw = getpwuid (owner);
if (pw == NULL)
return 0;
if ((gr = getgrgid (group)) == NULL)
gr = getgrgid (group);
if (gr == NULL)
return 0;
sowner = pw->pw_name;
@ -1179,10 +1186,7 @@ fish_exists (struct vfs_class *me, const char *path)
g_free (rpath);
if (fish_send_command (me, super, buf, OPT_FLUSH) == 0)
return 1;
return 0;
return (fish_send_command (me, super, buf, OPT_FLUSH) == 0) ? 1 : 0;
}

Просмотреть файл

@ -227,8 +227,10 @@ ftpfs_translate_path (struct vfs_class *me, struct vfs_s_super *super, const cha
memmove (p + 1, p + 2, strlen (p + 2) + 1);
/* strip trailing "/." */
if ((p = strrchr (ret, '/')) && *(p + 1) == '.' && *(p + 2) == '\0')
p = strrchr (ret, '/');
if ((p != NULL) && (*(p + 1) == '.') && (*(p + 2) == '\0'))
*p = '\0';
return ret;
}
}
@ -608,33 +610,37 @@ ftpfs_load_no_proxy_list (void)
return;
mc_file = concat_dir_and_file (mc_home, "mc.no_proxy");
if (exist_file (mc_file) && (npf = fopen (mc_file, "r")))
if (exist_file (mc_file))
{
while (fgets (s, sizeof (s), npf))
npf = fopen (mc_file, "r");
if (npf != NULL)
{
if (!(p = strchr (s, '\n')))
{ /* skip bogus entries */
while ((c = fgetc (npf)) != EOF && c != '\n')
;
continue;
while (fgets (s, sizeof (s), npf) != NULL)
{
p = strchr (s, '\n');
if (p == NULL) { /* skip bogus entries */
{
while ((c = fgetc (npf)) != EOF && c != '\n')
;
continue;
}
if (p == s)
continue;
*p = '\0';
np = g_new (struct no_proxy_entry, 1);
np->domain = g_strdup (s);
np->next = NULL;
if (no_proxy)
current->next = np;
else
no_proxy = np;
current = np;
}
if (p == s)
continue;
*p = '\0';
np = g_new (struct no_proxy_entry, 1);
np->domain = g_strdup (s);
np->next = NULL;
if (no_proxy)
current->next = np;
else
no_proxy = np;
current = np;
fclose (npf);
}
fclose (npf);
}
g_free (mc_file);
}
@ -1169,10 +1175,12 @@ ftpfs_open_data_connection (struct vfs_class *me, struct vfs_s_super *super, con
{
struct sockaddr_storage from;
int s, j, data;
socklen_t fromlen = sizeof (from);
socklen_t fromlen = sizeof(from);
if ((s = ftpfs_initconn (me, super)) == -1)
s = ftpfs_initconn (me, super);
if (s == -1)
return -1;
if (ftpfs_changetype (me, super, isbinary) == -1)
return -1;
if (reget > 0)
@ -1191,6 +1199,7 @@ ftpfs_open_data_connection (struct vfs_class *me, struct vfs_s_super *super, con
}
else
j = ftpfs_command (me, super, WAIT_REPLY, "%s", cmd);
if (j != PRELIM)
ERRNOR (EPERM, -1);
tty_enable_interrupt_key ();
@ -1750,7 +1759,8 @@ ftpfs_send_command (struct vfs_class *me, const char *filename, const char *cmd,
int r;
int flush_directory_cache = (flags & OPT_FLUSH);
if (!(rpath = vfs_s_get_path_mangle (me, mpath, &super, 0)))
rpath = vfs_s_get_path_mangle (me, mpath, &super, 0);
if (rpath == NULL)
{
g_free (mpath);
return -1;
@ -2216,8 +2226,10 @@ ftpfs_netrc_lookup (const char *host, char **login, char **pass)
/* Find our own domain name */
if (gethostname (hostname, sizeof (hostname)) < 0)
*hostname = 0;
if (!(domain = strchr (hostname, '.')))
*hostname = '\0';
domain = strchr (hostname, '.');
if (domain == NULL)
domain = "";
/* Scan for "default" and matching "machine" keywords */

Просмотреть файл

@ -212,7 +212,8 @@ mcfs_get_remote_port (struct sockaddr_in *sin, int *version)
#ifdef HAVE_PMAP_GETPORT
int port;
for (*version = RPC_PROGVER; *version >= 1; (*version)--)
if (port = pmap_getport (sin, RPC_PROGNUM, *version, IPPROTO_TCP))
port = pmap_getport (sin, RPC_PROGNUM, *version, IPPROTO_TCP);
if (port != NULL)
return port;
#endif /* HAVE_PMAP_GETPORT */
*version = 1;
@ -237,11 +238,13 @@ mcfs_create_tcp_link (const char *host, int *port, int *version, const char *cal
server_address.sin_family = AF_INET;
/* Try to use the dotted decimal number */
if ((inaddr = inet_addr (host)) != INADDR_NONE)
inaddr = inet_addr (host);
if (inaddr != INADDR_NONE) {
memcpy ((char *) &server_address.sin_addr, (char *) &inaddr,
sizeof (inaddr));
else {
if ((hp = gethostbyname (host)) == NULL) {
} else {
hp = gethostbyname (host);
if (hp == NULL) {
message (D_ERROR, caller, _(" Cannot locate hostname: %s "),
host);
return 0;
@ -259,8 +262,8 @@ mcfs_create_tcp_link (const char *host, int *port, int *version, const char *cal
*version = 1;
server_address.sin_port = htons (*port);
if ((my_socket = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
my_socket = socket (AF_INET, SOCK_STREAM, 0);
if (my_socket < 0) {
message (D_ERROR, caller, _(" Cannot create socket: %s "),
unix_error_string (errno));
return 0;
@ -340,10 +343,8 @@ mcfs_open_link (char *host, char *user, int *port, char *netrcpass)
message (D_ERROR, MSG_ERROR, _(" Too many open connections "));
return 0;
}
if (!
(sock =
mcfs_open_tcp_link (host, user, port, netrcpass, &version)))
sock = mcfs_open_tcp_link (host, user, port, netrcpass, &version);
if (sock == 0)
return 0;
bucket = mcfs_get_free_bucket ();
@ -394,12 +395,14 @@ mcfs_get_path (mcfs_connection **mc, const char *path)
* remote portmapper to get the port number
*/
port = 0;
if ((remote_path =
mcfs_get_host_and_username (path, &host, &user, &port, &pass)))
if (!(*mc = mcfs_open_link (host, user, &port, pass))) {
remote_path = mcfs_get_host_and_username (path, &host, &user, &port, &pass);
if (remote_path != NULL) {
*mc = mcfs_open_link (host, user, &port, pass);
if (*mc == NULL) {
g_free (remote_path);
remote_path = NULL;
}
}
g_free (host);
g_free (user);
if (pass)
@ -445,10 +448,12 @@ mcfs_rpc_two_paths (int command, const char *s1, const char *s2)
mcfs_connection *mc;
char *r1, *r2;
if ((r1 = mcfs_get_path (&mc, s1)) == 0)
r1 = mcfs_get_path (&mc, s1);
if (r1 == NULL)
return -1;
if ((r2 = mcfs_get_path (&mc, s2)) == 0) {
r2 = mcfs_get_path (&mc, s2);
if (r2 == NULL) {
g_free (r1);
return -1;
}
@ -466,7 +471,8 @@ mcfs_rpc_path (int command, const char *path)
mcfs_connection *mc;
char *remote_file;
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
remote_file = mcfs_get_path (&mc, path);
if (remote_file == NULL)
return -1;
rpc_send (mc->sock,
@ -482,7 +488,8 @@ mcfs_rpc_path_int (int command, const char *path, int data)
mcfs_connection *mc;
char *remote_file;
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
remote_file = mcfs_get_path (&mc, path);
if (remote_file == NULL)
return -1;
rpc_send (mc->sock,
@ -499,7 +506,8 @@ mcfs_rpc_path_int_int (int command, const char *path, int n1, int n2)
mcfs_connection *mc;
char *remote_file;
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
remote_file = mcfs_get_path (&mc, path);
if (remote_file == NULL)
return -1;
rpc_send (mc->sock,
@ -537,7 +545,8 @@ mcfs_open (struct vfs_class *me, const char *file, int flags, int mode)
(void) me;
if (!(remote_file = mcfs_get_path (&mc, file)))
remote_file = mcfs_get_path (&mc, file);
if (remote_file == NULL)
return 0;
rpc_send (mc->sock, RPC_INT, MC_OPEN, RPC_STRING, remote_file, RPC_INT,
@ -661,8 +670,9 @@ mcfs_opendir (struct vfs_class *me, const char *dirname)
(void) me;
if (!(remote_dir = mcfs_get_path (&mc, dirname)))
return 0;
remote_dir = mcfs_get_path (&mc, dirname);
if (remote_dir == NULL)
return NULL;
rpc_send (mc->sock, RPC_INT, MC_OPENDIR, RPC_STRING, remote_dir,
RPC_END);
@ -670,10 +680,10 @@ mcfs_opendir (struct vfs_class *me, const char *dirname)
if (0 ==
rpc_get (mc->sock, RPC_INT, &result, RPC_INT, &error_num, RPC_END))
return 0;
return NULL;
if (mcfs_is_error (result, error_num))
return 0;
return NULL;
handle = result;
@ -683,7 +693,7 @@ mcfs_opendir (struct vfs_class *me, const char *dirname)
mcfs_info->entries = 0;
mcfs_info->current = 0;
return mcfs_info;
return (void *) mcfs_info;
}
static int mcfs_get_stat_info (mcfs_connection * mc, struct stat *buf);
@ -880,7 +890,8 @@ mcfs_stat_cmd (int cmd, const char *path, struct stat *buf)
mcfs_connection *mc;
int status, error;
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
remote_file = mcfs_get_path (&mc, path);
if (remote_file == NULL)
return -1;
rpc_send (mc->sock, RPC_INT, cmd, RPC_STRING, remote_file, RPC_END);
@ -970,7 +981,8 @@ mcfs_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
(void) me;
if (!(file = mcfs_get_path (&mc, path)))
remote_file = mcfs_get_path (&mc, path);
if (remote_file == NULL)
return -1;
status = 0;
@ -1005,7 +1017,8 @@ mcfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
(void) me;
if (!(remote_file = mcfs_get_path (&mc, path)))
remote_file = mcfs_get_path (&mc, path);
if (remote_file == NULL)
return -1;
rpc_send (mc->sock, RPC_INT, MC_READLINK, RPC_STRING, remote_file,
@ -1062,7 +1075,8 @@ mcfs_chdir (struct vfs_class *me, const char *path)
(void) me;
if (!(remote_dir = mcfs_get_path (&mc, path)))
remote_file = mcfs_get_path (&mc, path);
if (remote_file == NULL)
return -1;
rpc_send (mc->sock, RPC_INT, MC_CHDIR, RPC_STRING, remote_dir,
@ -1137,12 +1151,11 @@ mcfs_forget (const char *path)
return;
path += 5;
if (path[0] == '/' && path[1] == '/')
if ((path[0] == '/') && (path[1] == '/'))
path += 2;
if ((p =
mcfs_get_host_and_username (path, &host, &user, &port,
&pass)) == 0) {
p = mcfs_get_host_and_username (path, &host, &user, &port, &pass);
if (p == NULL) {
g_free (host);
g_free (user);
if (pass)

Просмотреть файл

@ -799,15 +799,22 @@ mc_pam_auth (const char *username, const char *password)
up.password = password;
conv.appdata_ptr = &up;
if ((status =
pam_start ("mcserv", username, &conv, &pamh)) != PAM_SUCCESS)
status = pam_start ("mcserv", username, &conv, &pamh);
if (status != PAM_SUCCESS)
goto failed_pam;
if ((status = pam_authenticate (pamh, 0)) != PAM_SUCCESS)
status = pam_authenticate (pamh, 0);
if (status != PAM_SUCCESS)
goto failed_pam;
if ((status = pam_acct_mgmt (pamh, 0)) != PAM_SUCCESS)
status = pam_acct_mgmt (pamh, 0);
if (status != PAM_SUCCESS)
goto failed_pam;
if ((status = pam_setcred (pamh, PAM_ESTABLISH_CRED)) != PAM_SUCCESS)
status = pam_setcred (pamh, PAM_ESTABLISH_CRED);
if (status != PAM_SUCCESS)
goto failed_pam;
pam_end (pamh, status);
return 0;
@ -866,11 +873,13 @@ do_ftp_auth (const char *username, const char *password)
local_address.sin_port = htons (21);
/* Convert localhost to usable format */
if ((inaddr = inet_addr ("127.0.0.1")) != INADDR_NONE)
inaddr = inet_addr ("127.0.0.1");
if (inaddr != INADDR_NONE)
memcpy ((char *) &local_address.sin_addr, (char *) &inaddr,
sizeof (inaddr));
if ((my_socket = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
my_socket = socket (AF_INET, SOCK_STREAM, 0);
if (my_socket < 0) {
if (!isDaemon)
fprintf (stderr, "do_auth: can't create socket\n");
return 0;
@ -916,14 +925,16 @@ do_classic_auth (const char *username, const char *password)
struct spwd *spw;
#endif
if ((pw = getpwnam (username)) == 0)
pw = getpwnam (username);
if (pw == NULL)
return 0;
#ifdef HAVE_SHADOW
setspent ();
/* Password expiration is not checked! */
if ((spw = getspnam (username)) == NULL)
spw = getspnam (username);
if (spw == NULL)
encr_pwd = "*";
else
encr_pwd = spw->sp_pwdp;
@ -1200,7 +1211,8 @@ get_client (int port)
struct sockaddr_in client_address, server_address;
int yes = 1;
if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0)
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock < 0)
return "Cannot create socket";
/* Use this to debug: */
@ -1227,7 +1239,8 @@ get_client (int port)
newsocket =
accept (sock, (struct sockaddr *) &client_address, &clilen);
if (isDaemon && (child = fork ())) {
child = fork ();
if (isDaemon != 0 && child != 0) {
int status;
close (newsocket);
@ -1373,10 +1386,12 @@ main (int argc, char *argv[])
register_port (portnum, 0);
if (verbose)
printf ("Using port %d\n", portnum);
if ((result = get_client (portnum)))
result = get_client (portnum);
if (result != NULL)
perror (result);
#ifdef HAVE_PMAP_SET
if (!isDaemon)
if (isDaemon == 0)
pmap_unset (RPC_PROGNUM, RPC_PROGVER);
#endif
}

Просмотреть файл

@ -84,7 +84,8 @@ sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
pname = g_strdup (name);
vfs_split (pname, &inpath, &op);
if ((w = (*me->which) (me, op)) == -1)
w = (*me->which) (me, op);
if (w == -1)
vfs_die ("This cannot happen... Hopefully.\n");
if (!(sfs_flags[w] & F_1) && strcmp (pname, "/")) {
@ -392,9 +393,11 @@ static int sfs_init (struct vfs_class *me)
}
if (!*c)
goto invalid_line;
c++;
*(semi+1) = 0;
if ((semi = strchr (c, '\n')))
semi = strchr (c, '\n');
if (semi != NULL)
*semi = 0;
sfs_prefix [sfs_no] = g_strdup (key);

Просмотреть файл

@ -666,7 +666,8 @@ tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive,
current_tar_position = 0;
/* Open for reading */
if ((tard = tar_open_archive_int (me, name, archive)) == -1)
tard = tar_open_archive_int (me, name, archive);
if (tard == -1)
return -1;
for (;;) {
@ -772,7 +773,9 @@ static ssize_t tar_read (void *fh, char *buffer, int count)
count = MIN(count, FH->ino->st.st_size - FH->pos);
if ((count = mc_read (fd, buffer, count)) == -1) ERRNOR (errno, -1);
count = mc_read (fd, buffer, count);
if (count == -1)
ERRNOR (errno, -1);
FH->pos += count;
return count;

Просмотреть файл

@ -206,17 +206,18 @@ undelfs_loaddel (void)
message (D_ERROR, undelfserr, _(" while allocating block buffer "));
goto free_delarray;
}
if ((retval = ext2fs_open_inode_scan (fs, 0, &scan)))
retval = ext2fs_open_inode_scan (fs, 0, &scan);
if (retval != 0)
{
message (D_ERROR, undelfserr, _(" open_inode_scan: %d "), retval);
goto free_block_buf;
}
if ((retval = ext2fs_get_next_inode (scan, &ino, &inode)))
retval = ext2fs_get_next_inode (scan, &ino, &inode);
if (retval != 0)
{
message (D_ERROR, undelfserr, _(" while starting inode scan %d "), retval);
goto error_out;
}
count = 0;
while (ino)
{
@ -674,7 +675,8 @@ undelfs_chdir (struct vfs_class *me, const char *path)
/* We may use access because ext2 file systems are local */
/* this could be fixed by making an ext2fs io manager to use */
/* our vfs, but that is left as an excercise for the reader */
if ((fd = open (file, O_RDONLY)) == -1)
fd = open (file, O_RDONLY);
if (fd == -1)
{
message (D_ERROR, undelfserr, _(" Cannot open file %s "), file);
g_free (f);

Просмотреть файл

@ -233,7 +233,8 @@ is_week (const char *str, struct tm *tim)
if (!str)
return 0;
if ((pos = strstr (week, str)) != NULL) {
pos = strstr (week, str);
if (pos != NULL) {
if (tim != NULL)
tim->tm_wday = (pos - week) / 3;
return 1;
@ -250,7 +251,8 @@ is_month (const char *str, struct tm *tim)
if (!str)
return 0;
if ((pos = strstr (month, str)) != NULL) {
pos = strstr (month, str);
if (pos != NULL) {
if (tim != NULL)
tim->tm_mon = (pos - month) / 3;
return 1;
@ -287,10 +289,12 @@ is_time (const char *str, struct tm *tim)
{
const char *p, *p2;
if (!str)
if (str == NULL)
return 0;
if ((p = strchr (str, ':')) && (p2 = strrchr (str, ':'))) {
p = strchr (str, ':');
p2 = strrchr (str, ':');
if (p != NULL && p2 != NULL) {
if (p != p2) {
if (sscanf
(str, "%2d:%2d:%2d", &tim->tm_hour, &tim->tm_min,
@ -619,7 +623,8 @@ vfs_parse_filedate (int idx, time_t *t)
tim.tm_year--;
if (l10n || (*t = mktime (&tim)) < 0)
*t = mktime (&tim);
if (l10n || (*t < 0))
*t = 0;
return idx;
}

Просмотреть файл

@ -197,7 +197,7 @@ static struct vfs_class *vfs_list;
int
vfs_register_class (struct vfs_class *vfs)
{
if (vfs->init) /* vfs has own initialization function */
if (vfs->init != NULL) /* vfs has own initialization function */
if (!(*vfs->init) (vfs)) /* but it failed */
return 0;
@ -214,15 +214,15 @@ vfs_prefix_to_class (char *prefix)
struct vfs_class *vfs;
/* Avoid last class (localfs) that would accept any prefix */
for (vfs = vfs_list; vfs->next; vfs = vfs->next)
for (vfs = vfs_list; vfs->next != NULL; vfs = vfs->next)
{
if (vfs->which)
if (vfs->which != NULL)
{
if ((*vfs->which) (vfs, prefix) == -1)
continue;
return vfs;
}
if (vfs->prefix && !strncmp (prefix, vfs->prefix, strlen (vfs->prefix)))
if (vfs->prefix != NULL && strncmp (prefix, vfs->prefix, strlen (vfs->prefix)) == 0)
return vfs;
}
return NULL;
@ -239,24 +239,25 @@ vfs_strip_suffix_from_filename (const char *filename)
char *semi;
char *p;
if (!filename)
if (filename == NULL)
vfs_die ("vfs_strip_suffix_from_path got NULL: impossible");
p = g_strdup (filename);
if (!(semi = strrchr (p, '#')))
semi = strrchr (p, '#');
if (semi == NULL)
return p;
/* Avoid last class (localfs) that would accept any prefix */
for (vfs = vfs_list; vfs->next; vfs = vfs->next)
for (vfs = vfs_list; vfs->next != NULL; vfs = vfs->next)
{
if (vfs->which)
if (vfs->which != NULL)
{
if ((*vfs->which) (vfs, semi + 1) == -1)
continue;
*semi = '\0'; /* Found valid suffix */
return p;
}
if (vfs->prefix && !strncmp (semi + 1, vfs->prefix, strlen (vfs->prefix)))
if (vfs->prefix != NULL && strncmp (semi + 1, vfs->prefix, strlen (vfs->prefix)) == 0)
{
*semi = '\0'; /* Found valid suffix */
return p;
@ -265,15 +266,12 @@ vfs_strip_suffix_from_filename (const char *filename)
return p;
}
static int
static gboolean
path_magic (const char *path)
{
struct stat buf;
if (!stat (path, &buf))
return 0;
return 1;
return (stat (path, &buf) != 0);
}
/**
@ -294,37 +292,38 @@ vfs_split (char *path, char **inpath, char **op)
char *slash;
struct vfs_class *ret;
if (!path)
if (path == NULL)
vfs_die ("Cannot split NULL");
semi = strrchr (path, '#');
if (!semi || !path_magic (path))
if (semi == NULL || !path_magic (path))
return NULL;
slash = strchr (semi, PATH_SEP);
*semi = 0;
*semi = '\0';
if (op)
if (op != NULL)
*op = NULL;
if (inpath)
if (inpath != NULL)
*inpath = NULL;
if (slash)
*slash = 0;
if (slash != NULL)
*slash = '\0';
if ((ret = vfs_prefix_to_class (semi + 1)))
ret = vfs_prefix_to_class (semi + 1);
if (ret != NULL)
{
if (op)
if (op != NULL)
*op = semi + 1;
if (inpath)
*inpath = slash ? slash + 1 : NULL;
if (inpath != NULL)
*inpath = slash != NULL ? slash + 1 : NULL;
return ret;
}
if (slash)
if (slash != NULL)
*slash = PATH_SEP;
ret = vfs_split (path, inpath, op);
*semi = '#';
return ret;
@ -340,19 +339,19 @@ _vfs_get_class (char *path)
g_return_val_if_fail (path, NULL);
semi = strrchr (path, '#');
if (!semi || !path_magic (path))
if (semi == NULL || !path_magic (path))
return NULL;
slash = strchr (semi, PATH_SEP);
*semi = 0;
if (slash)
*slash = 0;
*semi = '\0';
if (slash != NULL)
*slash = '\0';
ret = vfs_prefix_to_class (semi + 1);
if (slash)
if (slash != NULL)
*slash = PATH_SEP;
if (!ret)
if (ret == NULL)
ret = _vfs_get_class (path);
*semi = '#';
@ -498,7 +497,6 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer
errno = EINVAL;
return ESTR_FAILURE;
}
break;
default:
errno = EINVAL;
return ESTR_FAILURE;

Просмотреть файл

@ -150,9 +150,11 @@ do_background (struct FileOpContext *ctx, char *info)
if (pipe (back_comm) == -1)
return -1;
if ((pid = fork ()) == -1)
pid = fork ();
if (pid == -1)
{
int saved_errno = errno;
(void) close (comm[0]);
(void) close (comm[1]);
(void) close (back_comm[0]);
@ -176,11 +178,15 @@ do_background (struct FileOpContext *ctx, char *info)
close (1);
close (2);
if ((nullfd = open ("/dev/null", O_RDWR)) != -1)
nullfd = open ("/dev/null", O_RDWR);
if (nullfd != -1)
{
while (dup2 (nullfd, 0) == -1 && errno == EINTR);
while (dup2 (nullfd, 1) == -1 && errno == EINTR);
while (dup2 (nullfd, 2) == -1 && errno == EINTR);
while (dup2 (nullfd, 0) == -1 && errno == EINTR)
;
while (dup2 (nullfd, 1) == -1 && errno == EINTR)
;
while (dup2 (nullfd, 2) == -1 && errno == EINTR)
;
}
return 0;

Просмотреть файл

@ -57,12 +57,14 @@ load_codepages_list (void)
char *default_codepage = NULL;
fname = concat_dir_and_file (mc_home, CHARSETS_INDEX);
if (!(f = fopen (fname, "r"))) {
f = fopen (fname, "r");
if (f == NULL) {
fprintf (stderr, _("Warning: file %s not found\n"), fname);
g_free (fname);
fname = concat_dir_and_file (mc_home_alt, CHARSETS_INDEX);
if (!(f = fopen (fname, "r"))) {
f = fopen (fname, "r");
if (f == NULL) {
fprintf (stderr, _("Warning: file %s not found\n"), fname);
g_free (fname);

Просмотреть файл

@ -109,7 +109,7 @@ filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
}
/* If we're starting the match process, initialize us a bit. */
if (!state)
if (state == 0)
{
const char *temp;
@ -117,7 +117,7 @@ filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
g_free (filename);
g_free (users_dirname);
if ((*text) && (temp = strrchr (text, PATH_SEP)))
if ((*text != '\0') && (temp = strrchr (text, PATH_SEP)) != NULL)
{
filename = g_strdup (++temp);
dirname = g_strndup (text, temp - text);
@ -205,7 +205,7 @@ filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
break;
}
if (!entry)
if (entry == NULL)
{
if (directory)
{
@ -233,7 +233,7 @@ filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
if (users_dirname[dirlen - 1] != PATH_SEP)
{
temp[dirlen] = PATH_SEP;
temp[dirlen + 1] = 0;
temp[dirlen + 1] = '\0';
}
strcat (temp, entry->d_name);
}
@ -262,7 +262,7 @@ username_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
if (text[0] == '\\' && text[1] == '~')
text++;
if (!state)
if (state == 0)
{ /* Initialization stuff */
setpwent ();
userlen = strlen (text + 1);
@ -276,7 +276,7 @@ username_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
break;
}
if (entry)
if (entry != NULL)
return g_strconcat ("~", entry->pw_name, PATH_SEP_STR, (char *) NULL);
endpwent ();
@ -300,7 +300,7 @@ variable_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
(void) flags;
SHOW_C_CTX ("variable_completion_function");
if (!state)
if (state == 0)
{ /* Initialization stuff */
isbrace = (text[1] == '{');
varlen = strlen (text + 1 + isbrace);
@ -315,9 +315,9 @@ variable_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
env_p++;
}
if (!*env_p)
if (*env_p == NULL)
return NULL;
else
{
char *temp = g_malloc (2 + 2 * isbrace + p - *env_p);
@ -518,10 +518,11 @@ command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS
if (!(flags & INPUT_COMPLETE_COMMANDS))
return 0;
text = strutils_shell_unescape (_text);
flags &= ~INPUT_COMPLETE_SHELL_ESC;
if (!state)
if (state == 0)
{ /* Initialize us a little bit */
isabsolute = strchr (text, PATH_SEP) != NULL;
if (!isabsolute)
@ -529,13 +530,18 @@ command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS
words = bash_reserved;
phase = 0;
text_len = strlen (text);
if (!path && (path = g_strdup (getenv ("PATH"))) != NULL)
if (path == NULL)
{
p = path;
path_end = strchr (p, 0);
while ((p = strchr (p, PATH_ENV_SEP)))
path = g_strdup (getenv ("PATH"));
if (path != NULL)
{
*p++ = 0;
p = path;
path_end = strchr (p, '\0');
while ((p = strchr (p, PATH_ENV_SEP)) != NULL)
{
*p++ = '\0';
}
}
}
}
@ -545,7 +551,7 @@ command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS
{
p = filename_completion_function (text, state, flags);
if (p)
if (p != NULL)
{
char *temp_p = p;
p = strutils_shell_escape (p);
@ -616,11 +622,15 @@ command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS
g_free (path);
path = NULL;
}
else if ((p = strrchr (found, PATH_SEP)) != NULL)
else
{
char *tmp = found;
found = strutils_shell_escape (p + 1);
g_free (tmp);
p = strrchr (found, PATH_SEP);
if (p != NULL)
{
char *tmp = found;
found = strutils_shell_escape (p + 1);
g_free (tmp);
}
}
g_free (text);
@ -1188,8 +1198,9 @@ complete_engine (WInput * in, int what_to_do)
Dlg_head *query_dlg;
WListbox *query_list;
for (p = in->completions + 1; *p; count++, p++)
if ((i = str_term_width1 (*p)) > maxlen)
for (p = in->completions + 1; *p != NULL; count++, p++)
i = str_term_width1 (*p);
if (i > maxlen)
maxlen = i;
start_x = in->widget.x;
start_y = in->widget.y;

Просмотреть файл

@ -829,7 +829,7 @@ scan_diff (FBUF * f, GArray * ops)
}
continue;
}
while (buf[sz - 1] != '\n' && (sz = f_gets (buf, sizeof (buf), f)))
while (buf[sz - 1] != '\n' && (sz = f_gets (buf, sizeof (buf), f)) != 0)
{
}
}
@ -936,14 +936,15 @@ dff_reparse (int ord, const char *filename, const GArray * ops, DFUNC printer, v
int n;
op = &g_array_index (ops, DIFFCMD, i);
n = op->F1 - (op->cmd != add_cmd);
while (line < n && (sz = f_gets (buf, sizeof (buf), f)))
while (line < n && (sz = f_gets (buf, sizeof (buf), f)) != 0)
{
line++;
printer (ctx, EQU_CH, line, off, sz, buf);
off += sz;
while (buf[sz - 1] != '\n')
{
if (!(sz = f_gets (buf, sizeof (buf), f)))
sz = f_gets (buf, sizeof (buf), f);
if (sz == 0)
{
printer (ctx, 0, 0, 0, 1, "\n");
break;
@ -969,14 +970,15 @@ dff_reparse (int ord, const char *filename, const GArray * ops, DFUNC printer, v
if (op->cmd == del_cmd)
{
n = op->F2 - op->F1 + 1;
while (n && (sz = f_gets (buf, sizeof (buf), f)))
while (n != 0 && (sz = f_gets (buf, sizeof (buf), f)) != 0)
{
line++;
printer (ctx, ADD_CH, line, off, sz, buf);
off += sz;
while (buf[sz - 1] != '\n')
{
if (!(sz = f_gets (buf, sizeof (buf), f)))
sz = f_gets (buf, sizeof (buf), f);
if (sz == 0)
{
printer (ctx, 0, 0, 0, 1, "\n");
break;
@ -994,14 +996,15 @@ dff_reparse (int ord, const char *filename, const GArray * ops, DFUNC printer, v
if (op->cmd == 'c')
{
n = op->F2 - op->F1 + 1;
while (n && (sz = f_gets (buf, sizeof (buf), f)))
while (n != 0 && (sz = f_gets (buf, sizeof (buf), f)) != 0)
{
line++;
printer (ctx, CHG_CH, line, off, sz, buf);
off += sz;
while (buf[sz - 1] != '\n')
{
if (!(sz = f_gets (buf, sizeof (buf), f)))
sz = f_gets (buf, sizeof (buf), f);
if (sz == 0)
{
printer (ctx, 0, 0, 0, 1, "\n");
break;
@ -1028,14 +1031,15 @@ dff_reparse (int ord, const char *filename, const GArray * ops, DFUNC printer, v
#undef F2
#undef F1
while ((sz = f_gets (buf, sizeof (buf), f)))
while ((sz = f_gets (buf, sizeof (buf), f)) != 0)
{
line++;
printer (ctx, EQU_CH, line, off, sz, buf);
off += sz;
while (buf[sz - 1] != '\n')
{
if (!(sz = f_gets (buf, sizeof (buf), f)))
sz = f_gets (buf, sizeof (buf), f);
if (sz == 0)
{
printer (ctx, 0, 0, 0, 1, "\n");
break;
@ -1252,8 +1256,10 @@ hdiff_scan (const char *s, int m, const char *t, int n, int min, GArray * hdiff,
BRACKET b;
/* dumbscan (single horizontal diff) -- does not compress whitespace */
for (i = 0; i < m && i < n && s[i] == t[i]; i++);
for (; m > i && n > i && s[m - 1] == t[n - 1]; m--, n--);
for (i = 0; i < m && i < n && s[i] == t[i]; i++)
;
for (; m > i && n > i && s[m - 1] == t[n - 1]; m--, n--)
;
b[0].off = i;
b[0].len = m - i;
@ -1315,7 +1321,7 @@ static int
cvt_cpy (char *dst, const char *src, size_t srcsize, int base, int ts)
{
int i;
for (i = 0; srcsize; i++, src++, dst++, srcsize--)
for (i = 0; srcsize != 0; i++, src++, dst++, srcsize--)
{
*dst = *src;
if (*src == '\t')
@ -1355,7 +1361,7 @@ cvt_ncpy (char *dst, int dstsize, const char **_src, size_t srcsize, int base, i
{
int i;
const char *src = *_src;
for (i = 0; i < dstsize && srcsize; i++, src++, dst++, srcsize--)
for (i = 0; i < dstsize && srcsize != 0; i++, src++, dst++, srcsize--)
{
*dst = *src;
if (*src == '\t')
@ -1401,7 +1407,7 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int
int i;
char *tmp = dst;
const int base = 0;
for (i = 0; dstsize && srcsize && *src != '\n'; i++, src++, srcsize--)
for (i = 0; dstsize != 0 && srcsize != 0 && *src != '\n'; i++, src++, srcsize--)
{
if (*src == '\t')
{
@ -1413,7 +1419,7 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int
{
skip--;
}
else if (dstsize)
else if (dstsize != 0)
{
dstsize--;
*dst++ = ' ';
@ -1445,6 +1451,7 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int
int utf_ch = 0;
gboolean res;
int w;
skip--;
utf_ch = dview_get_utf ((char *)src, &w, &res);
if (w > 1)
@ -1461,7 +1468,7 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int
}
sz = dst - tmp;
}
while (dstsize)
while (dstsize != 0)
{
dstsize--;
*dst++ = ' ';
@ -1498,7 +1505,7 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
int i, k;
char *tmp = dst;
const int base = 0;
for (i = 0, k = 0; dstsize && srcsize && *src != '\n'; i++, k++, src++, srcsize--)
for (i = 0, k = 0; dstsize != 0 && srcsize != 0 && *src != '\n'; i++, k++, src++, srcsize--)
{
if (*src == '\t')
{
@ -1506,11 +1513,11 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
i += j - 1;
while (j-- > 0)
{
if (skip)
if (skip != 0)
{
skip--;
}
else if (dstsize)
else if (dstsize != 0)
{
dstsize--;
*att++ = is_inside (k, hdiff, ord);
@ -1520,7 +1527,7 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
}
else if (src[0] == '\r' && (srcsize == 1 || src[1] == '\n'))
{
if (!skip && show_cr)
if (skip == 0 && show_cr)
{
if (dstsize > 1)
{
@ -1541,11 +1548,12 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
}
else
{
if (skip)
if (skip != 0)
{
int utf_ch = 0;
gboolean res;
int w;
skip--;
utf_ch = dview_get_utf ((char *) src, &w, &res);
if (w > 1)
@ -1563,7 +1571,7 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
}
sz = dst - tmp;
}
while (dstsize)
while (dstsize != 0)
{
dstsize--;
*att++ = 0;
@ -1620,10 +1628,10 @@ cvt_fget (FBUF * f, off_t off, char *dst, size_t dstsize, int skip, int ts, int
while (skip > base)
{
old_base = base;
if (!(sz = f_gets (tmp, amount, f)))
{
sz = f_gets (tmp, amount, f);
if (sz == 0)
break;
}
base = cvt_cpy (cvt, tmp, sz, old_base, ts);
if (cvt[base - old_base - 1] == '\n')
{
@ -1645,17 +1653,18 @@ cvt_fget (FBUF * f, off_t off, char *dst, size_t dstsize, int skip, int ts, int
if (useful <= dstsize)
{
if (useful)
{
if (useful != 0)
memmove (dst, cvt + offset, useful);
}
if (q == NULL && (sz = f_gets (tmp, dstsize - useful + 1, f)))
if (q == NULL)
{
const char *ptr = tmp;
useful += cvt_ncpy (dst + useful, dstsize - useful, &ptr, sz, base, ts) - base;
if (ptr < tmp + sz)
sz = f_gets (tmp, dstsize - useful + 1, f);
if (sz != 0)
{
lastch = *ptr;
const char *ptr = tmp;
useful += cvt_ncpy (dst + useful, dstsize - useful, &ptr, sz, base, ts) - base;
if (ptr < tmp + sz)
lastch = *ptr;
}
}
sz = useful;
@ -1722,9 +1731,9 @@ printer (void *ctx, int ch, int line, off_t off, size_t sz, const char *str)
p.ch = ch;
p.line = line;
p.u.off = off;
if (dsrc == DATA_SRC_MEM && line)
if (dsrc == DATA_SRC_MEM && line != 0)
{
if (sz && str[sz - 1] == '\n')
if (sz != 0 && str[sz - 1] == '\n')
{
sz--;
}
@ -1738,11 +1747,11 @@ printer (void *ctx, int ch, int line, off_t off, size_t sz, const char *str)
{
DIFFLN *p;
p = &g_array_index (a, DIFFLN, a->len - 1);
if (sz && str[sz - 1] == '\n')
if (sz != 0 && str[sz - 1] == '\n')
{
sz--;
}
if (sz > 0)
if (sz != 0)
{
size_t new_size = p->u.len + sz;
char *q = g_realloc (p->p, new_size);
@ -1751,7 +1760,7 @@ printer (void *ctx, int ch, int line, off_t off, size_t sz, const char *str)
}
p->u.len += sz;
}
if (dsrc == DATA_SRC_TMP && (line || !ch))
if (dsrc == DATA_SRC_TMP && (line != 0 || ch == 0))
{
FBUF *f = ((PRINTER_CTX *) ctx)->f;
f_write (f, str, sz);
@ -1925,7 +1934,7 @@ get_line_numbers (const GArray * a, size_t pos, int *linenum, int *lineofs)
*linenum = 0;
*lineofs = 0;
if (a->len)
if (a->len != 0)
{
if (pos >= a->len)
{
@ -1934,13 +1943,13 @@ get_line_numbers (const GArray * a, size_t pos, int *linenum, int *lineofs)
p = &g_array_index (a, DIFFLN, pos);
if (!p->line)
if (p->line == 0)
{
int n;
for (n = pos; n > 0; n--)
{
p--;
if (p->line)
if (p->line != 0)
{
break;
}
@ -2092,12 +2101,12 @@ dview_remove_hunk (WDiff * dview, FILE * merge_file, int from1, int to1)
FILE *f0;
f0 = fopen (dview->file[0], "r");
line = 0;
while (fgets (buf, sizeof (buf), f0) && line < from1 - 1)
while (fgets (buf, sizeof (buf), f0) != NULL && line < from1 - 1)
{
line++;
fputs (buf, merge_file);
}
while (fgets (buf, sizeof (buf), f0))
while (fgets (buf, sizeof (buf), f0) != NULL)
{
line++;
if (line >= to1)
@ -2116,19 +2125,19 @@ dview_add_hunk (WDiff * dview, FILE * merge_file, int from1, int from2, int to2)
f0 = fopen (dview->file[0], "r");
f1 = fopen (dview->file[1], "r");
line = 0;
while (fgets (buf, sizeof (buf), f0) && line < from1 - 1)
while (fgets (buf, sizeof (buf), f0) != NULL && line < from1 - 1)
{
line++;
fputs (buf, merge_file);
}
line = 0;
while (fgets (buf, sizeof (buf), f1) && line <= to2)
while (fgets (buf, sizeof (buf), f1) != NULL && line <= to2)
{
line++;
if (line >= from2)
fputs (buf, merge_file);
}
while (fgets (buf, sizeof (buf), f0))
while (fgets (buf, sizeof (buf), f0) != NULL)
{
fputs (buf, merge_file);
}
@ -2146,19 +2155,19 @@ dview_replace_hunk (WDiff * dview, FILE * merge_file, int from1, int to1, int fr
f0 = fopen (dview->file[0], "r");
f1 = fopen (dview->file[1], "r");
line1 = 0;
while (fgets (buf, sizeof (buf), f0) && line1 < from1 - 1)
while (fgets (buf, sizeof (buf), f0) != NULL && line1 < from1 - 1)
{
line1++;
fputs (buf, merge_file);
}
line2 = 0;
while (fgets (buf, sizeof (buf), f1) && line2 <= to2)
while (fgets (buf, sizeof (buf), f1) != NULL && line2 <= to2)
{
line2++;
if (line2 >= from2)
fputs (buf, merge_file);
}
while (fgets (buf, sizeof (buf), f0))
while (fgets (buf, sizeof (buf), f0) != NULL)
{
line1++;
if (line1 > to1)
@ -2197,10 +2206,9 @@ do_merge_hunk (WDiff * dview)
merge_file_fd = mc_mkstemps (&merge_file_name, "mcmerge", NULL);
if (merge_file_fd == -1)
{
message (D_ERROR, MSG_ERROR,
_(" Cannot create temporary merge file \n %s "),
unix_error_string (errno));
{
message (D_ERROR, MSG_ERROR, _(" Cannot create temporary merge file \n %s "),
unix_error_string (errno));
return;
}
@ -2497,7 +2505,7 @@ dview_display_file (const WDiff * dview, int ord, int r, int c, int height, int
tty_gotoyx (r + j, c - 2);
tty_print_char (ch);
}
if (p->line)
if (p->line != 0)
{
if (display_numbers)
{
@ -2798,25 +2806,23 @@ dview_event (Gpm_Event * event, void *x)
int result = MOU_NORMAL;
/* We are not interested in the release events */
if (!(event->type & (GPM_DOWN | GPM_DRAG)))
if (event->type & (GPM_DOWN | GPM_DRAG) == 0)
{
return result;
}
/* Wheel events */
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN))
if ((event->buttons & GPM_B_UP) != 0 && (event->type & GPM_DOWN) != 0)
{
dview->skip_rows -= 2;
dview->search.last_accessed_num_line = dview->skip_rows;
dview_update (dview);
return result;
}
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN))
else if ((event->buttons & GPM_B_DOWN) != 0 && (event->type & GPM_DOWN) != 0)
{
dview->skip_rows += 2;
dview->search.last_accessed_num_line = dview->skip_rows;
dview_update (dview);
return result;
}
return result;

Просмотреть файл

@ -332,7 +332,8 @@ edit_load_file_fast (WEdit * edit, const char *filename)
edit->curs2 = edit->last_byte;
buf2 = edit->curs2 >> S_EDIT_BUF_SIZE;
edit->utf8 = 0;
if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1)
file = mc_open (filename, O_RDONLY | O_BINARY);
if (file == -1)
{
GString *errmsg = g_string_new (NULL);
g_string_sprintf (errmsg, _(" Cannot open %s for reading "), filename);
@ -594,7 +595,8 @@ edit_insert_file (WEdit * edit, const char *filename)
long current = edit->curs1;
int vertical_insertion = 0;
char *buf;
if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1)
file = mc_open (filename, O_RDONLY | O_BINARY);
if (file == -1)
return 0;
buf = g_malloc0 (TEMP_BUF_LEN);
blocklen = mc_read (file, buf, sizeof (VERTICAL_MAGIC));
@ -602,30 +604,20 @@ edit_insert_file (WEdit * edit, const char *filename)
{
/* if contain signature VERTICAL_MAGIC tnen it vertical block */
if (memcmp (buf, VERTICAL_MAGIC, sizeof (VERTICAL_MAGIC)) == 0)
{
vertical_insertion = 1;
}
else
{
mc_lseek (file, 0, SEEK_SET);
}
}
if (vertical_insertion)
{
blocklen = edit_insert_column_of_text_from_file (edit, file);
}
else
{
while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0)
{
for (i = 0; i < blocklen; i++)
edit_insert (edit, buf[i]);
}
}
edit_cursor_move (edit, current - edit->curs1);
g_free (buf);
mc_close (file);
if (blocklen)
if (blocklen != 0)
return 0;
}
return 1;
@ -1150,7 +1142,7 @@ edit_push_action (WEdit * edit, long c, ...)
if (c == CURS_LEFT_LOTS || c == CURS_RIGHT_LOTS)
{
va_list ap;
edit->undo_stack[sp] = c == CURS_LEFT_LOTS ? CURS_LEFT : CURS_RIGHT;
edit->undo_stack[sp] = (c == CURS_LEFT_LOTS) ? CURS_LEFT : CURS_RIGHT;
edit->stack_pointer = (edit->stack_pointer + 1) & edit->stack_size_mask;
va_start (ap, c);
c = -(va_arg (ap, int));
@ -1239,21 +1231,22 @@ pop_action (WEdit * edit)
{
long c;
unsigned long sp = edit->stack_pointer;
if (sp == edit->stack_bottom)
{
return STACK_BOTTOM;
}
sp = (sp - 1) & edit->stack_size_mask;
if ((c = edit->undo_stack[sp]) >= 0)
c = edit->undo_stack[sp];
if (c >= 0)
{
/* edit->undo_stack[sp] = '@'; */
edit->stack_pointer = (edit->stack_pointer - 1) & edit->stack_size_mask;
return c;
}
if (sp == edit->stack_bottom)
{
return STACK_BOTTOM;
}
c = edit->undo_stack[(sp - 1) & edit->stack_size_mask];
if (edit->undo_stack[sp] == -2)
{
@ -1356,6 +1349,7 @@ edit_insert_ahead (WEdit * edit, int c)
{
if (edit->last_byte >= SIZE_LIMIT)
return;
if (edit->curs1 < edit->start_display)
{
edit->start_display++;
@ -1378,8 +1372,8 @@ edit_insert_ahead (WEdit * edit, int c)
if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE))
edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) -
1] = c;
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE]
[EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c;
edit->last_byte++;
edit->curs2++;
@ -1538,7 +1532,7 @@ edit_move_backward_lots (WEdit * edit, long increment)
}
else
{
if (s)
if (s != 0)
{
memqcpy (edit,
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t -
@ -1603,9 +1597,7 @@ edit_move_backward_lots (WEdit * edit, long increment)
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
}
else
{
g_free (p);
}
}
return edit_get_byte (edit, edit->curs1);
}
@ -1696,14 +1688,12 @@ edit_cursor_move (WEdit * edit, long increment)
long
edit_eol (WEdit * edit, long current)
{
if (current < edit->last_byte)
{
for (;; current++)
if (edit_get_byte (edit, current) == '\n')
break;
}
else
if (current >= edit->last_byte)
return edit->last_byte;
for (;; current++)
if (edit_get_byte (edit, current) == '\n')
break;
return current;
}
@ -1711,14 +1701,12 @@ edit_eol (WEdit * edit, long current)
long
edit_bol (WEdit * edit, long current)
{
if (current > 0)
{
for (;; current--)
if (edit_get_byte (edit, current - 1) == '\n')
break;
}
else
if (current <= 0)
return 0;
for (;; current--)
if (edit_get_byte (edit, current - 1) == '\n')
break;
return current;
}

Просмотреть файл

@ -279,12 +279,13 @@ edit_save_file (WEdit * edit, const char *filename)
ret = mc_chmod (savename, edit->stat1.st_mode);
}
if ((fd =
mc_open (savename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, edit->stat1.st_mode)) == -1)
fd = mc_open (savename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, edit->stat1.st_mode);
if (fd == -1)
goto error_save;
/* pipe save */
if ((p = edit_get_write_filter (savename, real_filename)))
p = edit_get_write_filter (savename, real_filename);
if (p != NULL)
{
FILE *file;
@ -601,7 +602,8 @@ edit_save_as_cmd (WEdit * edit)
{
int file;
different_filename = 1;
if ((file = mc_open (exp, O_RDONLY | O_BINARY)) != -1)
file = mc_open (exp, O_RDONLY | O_BINARY);
if (file != -1)
{
/* the file exists */
mc_close (file);
@ -693,7 +695,8 @@ edit_open_macro_file (const char *r)
FILE *fd;
int file;
filename = concat_dir_and_file (home_dir, EDIT_MACRO_FILE);
if ((file = open (filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
file = open (filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (file == -1)
{
g_free (filename);
return 0;
@ -734,8 +737,11 @@ edit_delete_macro (WEdit * edit, int k)
(void) edit;
if (saved_macros_loaded)
if ((j = macro_exists (k)) < 0)
{
j = macro_exists (k);
if (j < 0)
return 0;
}
tmp = concat_dir_and_file (home_dir, EDIT_TEMP_FILE);
g = fopen (tmp, "w");
g_free (tmp);
@ -849,7 +855,8 @@ edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k)
if (macro_exists (k) < 0)
return 0;
if ((f = edit_open_macro_file ("r")))
f = edit_open_macro_file ("r");
if (f != NULL)
{
struct macro dummy;
do
@ -2101,9 +2108,9 @@ edit_save_block (WEdit * edit, const char *filename, long start, long finish)
{
int len, file;
if ((file =
mc_open (filename, O_CREAT | O_WRONLY | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY)) == -1)
file = mc_open (filename, O_CREAT | O_WRONLY | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY);
if (file == -1)
return 0;
if (column_highlighting)

Просмотреть файл

@ -152,7 +152,8 @@ lock_get_info (const char *lockfname)
int cnt;
static char buf[BUF_SIZE];
if ((cnt = readlink (lockfname, buf, BUF_SIZE - 1)) == -1 || !*buf)
cnt = readlink (lockfname, buf, BUF_SIZE - 1);
if (cnt == -1 || *buf == '\0')
return NULL;
buf[cnt] = '\0';
return buf;

Просмотреть файл

@ -143,11 +143,7 @@ destroy_defines (GTree ** defines)
inline static int
xx_tolower (WEdit * edit, int c)
{
if (edit->is_case_insensitive)
{
return tolower (c);
}
return c;
return edit->is_case_insensitive ? tolower (c) : c;
}
static void
@ -156,19 +152,20 @@ subst_defines (GTree * defines, char **argv, char **argv_end)
char **t, **p;
int argc;
while (*argv && argv < argv_end)
while (*argv != NULL && argv < argv_end)
{
if ((t = g_tree_lookup (defines, *argv)))
t = g_tree_lookup (defines, *argv);
if (t != NULL)
{
int count = 0;
/* Count argv array members */
argc = 0;
for (p = &argv[1]; *p; p++)
for (p = &argv[1]; *p != NULL; p++)
argc++;
/* Count members of definition array */
for (p = t; *p; p++)
for (p = t; *p != NULL; p++)
count++;
p = &argv[count + argc];
@ -181,7 +178,8 @@ subst_defines (GTree * defines, char **argv, char **argv_end)
*p-- = argv[argc-- + 1];
/* Copy definition members to argv */
for (p = argv; *t; *p++ = *t++);
for (p = argv; *t != NULL; *p++ = *t++)
;
}
argv++;
}
@ -194,15 +192,14 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
const unsigned char *p, *q;
int c, d, j;
if (!*text)
if (*text == '\0')
return -1;
c = xx_tolower (edit, edit_get_byte (edit, i - 1));
if (line_start)
if (c != '\n')
return -1;
if (whole_left)
if (strchr (whole_left, c))
return -1;
if (line_start != 0 && c != '\n')
return -1;
if (whole_left != NULL && strchr (whole_left, c) != NULL)
return -1;
for (p = (unsigned char *) text, q = p + str_term_width1 ((char *) p); p < q; p++, i++)
{
@ -214,10 +211,8 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
for (;;)
{
c = xx_tolower (edit, edit_get_byte (edit, i));
if (!*p)
if (whole_right)
if (!strchr (whole_right, c))
break;
if (*p == '\0' && whole_right != NULL && strchr (whole_right, c) == NULL)
break;
if (c == *p)
break;
if (c == '\n')
@ -235,7 +230,7 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
if (c == *p)
{
j = i;
if (*p == *text && !p[1]) /* handle eg '+' and @+@ keywords properly */
if (*p == *text && p[1] == '\0') /* handle eg '+' and @+@ keywords properly */
break;
}
if (j && strchr ((char *) p + 1, c)) /* c exists further down, so it will get matched later */
@ -247,24 +242,23 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
i--;
break;
}
if (!j)
if (j == 0)
return -1;
i = j;
break;
}
if (whole_right)
if (!strchr (whole_right, c))
if (whole_right != NULL && (strchr (whole_right, c) == NULL))
{
if (*p == '\0')
{
if (!*p)
{
i--;
break;
}
if (!j)
return -1;
i = j;
i--;
break;
}
if (j == 0)
return -1;
i = j;
break;
}
i++;
}
break;
@ -308,9 +302,8 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
return -1;
}
}
if (whole_right)
if (strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))))
return -1;
if (whole_right != NULL && strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))) != NULL)
return -1;
return i;
}
@ -318,9 +311,7 @@ static const char *
xx_strchr (WEdit * edit, const unsigned char *s, int char_byte)
{
while (*s >= '\005' && xx_tolower (edit, *s) != char_byte)
{
s++;
}
return (const char *) s;
}
@ -329,13 +320,16 @@ static struct syntax_rule
apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
{
struct context_rule *r;
int contextchanged = 0, c;
int found_right = 0, found_left = 0, keyword_foundleft = 0, keyword_foundright = 0;
int is_end;
int c;
gboolean contextchanged = FALSE;
gboolean found_left = FALSE, found_right = FALSE;
gboolean keyword_foundleft = FALSE, keyword_foundright = FALSE;
gboolean is_end;
long end = 0;
struct syntax_rule _rule = rule;
if (!(c = xx_tolower (edit, edit_get_byte (edit, i))))
c = xx_tolower (edit, edit_get_byte (edit, i));
if (c == 0)
return rule;
is_end = (rule.end == (unsigned char) i);
@ -347,7 +341,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
if (is_end)
{
_rule.keyword = 0;
keyword_foundleft = 1;
keyword_foundleft = TRUE;
}
}
@ -355,6 +349,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
if (_rule.context && !_rule.keyword)
{
long e;
r = edit->rules[_rule.context];
if (r->first_right == c && !(rule.border & RULE_ON_RIGHT_BORDER)
&& (e =
@ -362,25 +357,23 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
r->whole_word_chars_right, r->line_start_right)) > 0)
{
_rule.end = e;
found_right = 1;
found_right = TRUE;
_rule.border = RULE_ON_RIGHT_BORDER;
if (r->between_delimiters)
_rule.context = 0;
}
else if (is_end && rule.border & RULE_ON_RIGHT_BORDER)
{
/* always turn off a context at 4 */
found_left = 1;
found_left = TRUE;
_rule.border = 0;
if (!keyword_foundleft)
_rule.context = 0;
}
else if (is_end && rule.border & RULE_ON_LEFT_BORDER)
{
/* never turn off a context at 2 */
found_left = 1;
found_left = TRUE;
_rule.border = 0;
}
}
@ -390,9 +383,11 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
{
const char *p;
p = (r = edit->rules[_rule.context])->keyword_first_chars;
if (p)
while (*(p = xx_strchr (edit, (unsigned char *) p + 1, c)))
r = edit->rules[_rule.context];
p = r->keyword_first_chars;
if (p != NULL)
while (*(p = xx_strchr (edit, (unsigned char *) p + 1, c)) != '\0')
{
struct key_word *k;
int count;
@ -407,11 +402,12 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
end = e;
_rule.end = e;
_rule.keyword = count;
keyword_foundright = 1;
keyword_foundright = TRUE;
break;
}
}
}
/* check to turn on a context */
if (!_rule.context)
{
@ -421,7 +417,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
{
_rule.border = 0;
_rule.context = 0;
contextchanged = 1;
contextchanged = TRUE;
_rule.keyword = 0;
}
@ -431,20 +427,24 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
_rule.border = 0;
if (r->between_delimiters)
{
long e;
_rule.context = _rule._context;
contextchanged = 1;
contextchanged = TRUE;
_rule.keyword = 0;
if (r->first_right == c
&& (e =
compare_word_to_right (edit, i, r->right, r->whole_word_chars_left,
r->whole_word_chars_right,
r->line_start_right)) >= end)
if (r->first_right == c)
{
_rule.end = e;
found_right = 1;
_rule.border = RULE_ON_RIGHT_BORDER;
_rule.context = 0;
long e;
e = compare_word_to_right (edit, i, r->right, r->whole_word_chars_left,
r->whole_word_chars_right,
r->line_start_right);
if (e >= end)
{
_rule.end = e;
found_right = TRUE;
_rule.border = RULE_ON_RIGHT_BORDER;
_rule.context = 0;
}
}
}
}
@ -467,15 +467,14 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
if (e >= end && (!_rule.keyword || keyword_foundright))
{
_rule.end = e;
found_right = 1;
found_right = TRUE;
_rule.border = RULE_ON_LEFT_BORDER;
_rule._context = count;
if (!r->between_delimiters)
if (!_rule.keyword)
{
_rule.context = count;
contextchanged = 1;
}
if (!r->between_delimiters && !_rule.keyword)
{
_rule.context = count;
contextchanged = TRUE;
}
break;
}
}
@ -488,8 +487,10 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
{
const char *p;
p = (r = edit->rules[_rule.context])->keyword_first_chars;
while (*(p = xx_strchr (edit, (unsigned char *) p + 1, c)))
r = edit->rules[_rule.context];
p = r->keyword_first_chars;
while (*(p = xx_strchr (edit, (unsigned char *) p + 1, c)) != '\0')
{
struct key_word *k;
int count;
@ -507,6 +508,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
}
}
}
return _rule;
}
@ -714,12 +716,13 @@ get_args (char *l, char **args, int args_size)
while (argc < args_size)
{
char *p = l;
while (*p && whiteness (*p))
while (*p != '\0' && whiteness (*p))
p++;
if (!*p)
if (*p == '\0')
break;
for (l = p + 1; *l && !whiteness (*l); l++);
if (*l)
for (l = p + 1; *l != '\0' && !whiteness (*l); l++)
;
if (*l != '\0')
*l++ = '\0';
args[argc++] = convert (p);
}
@ -737,32 +740,30 @@ this_try_alloc_color_pair (const char *fg, const char *bg)
{
char f[80], b[80], *p;
if (bg)
if (!*bg)
bg = 0;
if (fg)
if (!*fg)
fg = 0;
if (fg)
if (bg != NULL && *bg == '\0')
bg = NULL;
if (fg != NULL && *fg == '\0')
fg = NULL;
if (fg != NULL)
{
g_strlcpy (f, fg, sizeof (f));
p = strchr (f, '/');
if (p)
if (p != NULL)
*p = '\0';
fg = f;
}
if (bg)
if (bg != NULL)
{
g_strlcpy (b, bg, sizeof (b));
p = strchr (b, '/');
if (p)
if (p != NULL)
*p = '\0';
bg = b;
}
return tty_try_alloc_color_pair (fg, bg);
}
static char *error_file_name = 0;
static char *error_file_name = NULL;
static FILE *
open_include_file (const char *filename)
@ -771,21 +772,21 @@ open_include_file (const char *filename)
MC_PTR_FREE (error_file_name);
error_file_name = g_strdup (filename);
if (*filename == PATH_SEP)
if (g_path_is_absolute (filename))
return fopen (filename, "r");
g_free (error_file_name);
error_file_name = g_strconcat (home_dir, PATH_SEP_STR EDIT_DIR PATH_SEP_STR,
filename, (char *) NULL);
f = fopen (error_file_name, "r");
if (f)
if (f != NULL)
return f;
g_free (error_file_name);
error_file_name = g_strconcat (mc_home, PATH_SEP_STR, "syntax", PATH_SEP_STR,
filename, (char *) NULL);
f = fopen (error_file_name, "r");
if (f)
if (f != NULL)
return f;
g_free (error_file_name);
@ -826,7 +827,7 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
alloc_words_per_context = MAX_WORDS_PER_CONTEXT,
max_alloc_words_per_context = MAX_WORDS_PER_CONTEXT;
args[0] = 0;
args[0] = NULL;
edit->is_case_insensitive = FALSE;
strcpy (whole_left, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_01234567890");
@ -1095,20 +1096,18 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
if (argc < 3)
break_a;
if ((argv = g_tree_lookup (edit->defines, key)))
{
argv = g_tree_lookup (edit->defines, key);
if (argv != NULL)
mc_defines_destroy (NULL, argv, NULL);
}
else
{
key = g_strdup (key);
}
argv = g_new (char *, argc - 1);
g_tree_insert (edit->defines, key, argv);
while (*a)
while (*a != NULL)
{
*argv++ = g_strdup (*a++);
};
}
*argv = NULL;
}
else
@ -1220,20 +1219,20 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
int result = 0;
int count = 0;
char *lib_file;
int found = 0;
gboolean found = FALSE;
char **tmpnames = NULL;
f = fopen (syntax_file, "r");
if (!f)
if (f == NULL)
{
lib_file = concat_dir_and_file (mc_home, "Syntax");
f = fopen (lib_file, "r");
g_free (lib_file);
if (!f)
if (f == NULL)
return -1;
}
args[0] = 0;
args[0] = NULL;
for (;;)
{
line++;
@ -1241,14 +1240,15 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
if (read_one_line (&l, f) == 0)
break;
(void) get_args (l, args, 1023); /* Final NULL */
if (!args[0])
if (args[0] == NULL)
continue;
/* Looking for `include ...` lines before first `file ...` ones */
if (!found && !strcmp (args[0], "include"))
if (!found && strcmp (args[0], "include") == 0)
{
if (g)
if (g != NULL)
continue;
if (!args[1] || !(g = open_include_file (args[1])))
{
result = line;
@ -1258,11 +1258,10 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
}
/* looking for `file ...' lines only */
if (strcmp (args[0], "file"))
{
if (strcmp (args[0], "file") != 0)
continue;
}
found = 1;
found = TRUE;
/* must have two args or report error */
if (!args[1] || !args[2])
@ -1272,7 +1271,6 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
}
if (pnames && *pnames)
{
/* 1: just collecting a list of names of rule sets */
/* Reallocate the list if required */
if (count % NENTRIES == 0)
@ -1288,16 +1286,15 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
}
else if (type)
{
/* 2: rule set was explicitly specified by the caller */
if (!strcmp (type, args[2]))
if (strcmp (type, args[2]) == 0)
goto found_type;
}
else if (editor_file && edit)
{
/* 3: auto-detect rule set from regular expressions */
int q;
q = mc_search (args[1], editor_file, MC_SEARCH_T_REGEX);
/* does filename match arg 1 ? */
if (!q && args[3])
@ -1331,15 +1328,12 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
break;
}
}
if (g)
{
fclose (g);
g = NULL;
}
else
{
if (g == NULL)
break;
}
fclose (g);
g = NULL;
}
}
}
@ -1409,17 +1403,14 @@ edit_load_syntax (WEdit * edit, char ***pnames, const char *type)
message (D_ERROR, _(" Load syntax file "),
_(" Cannot open file %s \n %s "), f, unix_error_string (errno));
}
else if (r)
else if (r != 0)
{
edit_free_syntax_rules (edit);
message (D_ERROR, _(" Load syntax file "),
_(" Error in file %s on line %d "), error_file_name ? error_file_name : f, r);
MC_PTR_FREE (error_file_name);
}
else
{
/* succeeded */
}
g_free (f);
}

123
src/ext.c
Просмотреть файл

@ -118,17 +118,19 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
unix_error_string (errno));
return;
}
cmd_file = fdopen (cmd_file_fd, "w");
fputs ("#! /bin/sh\n", cmd_file);
lc_prompt[0] = 0;
for (; *lc_data && *lc_data != '\n'; lc_data++) {
lc_prompt[0] = '\0';
for (; *lc_data != '\0' && *lc_data != '\n'; lc_data++) {
if (parameter_found) {
if (*lc_data == '}') {
char *parameter;
parameter_found = 0;
parameter = input_dialog (_(" Parameter "), lc_prompt, MC_HISTORY_EXT_PARAMETER, "");
if (!parameter) {
if (parameter == NULL) {
/* User canceled */
fclose (cmd_file);
unlink (file_name);
@ -147,7 +149,7 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
if (len < sizeof (lc_prompt) - 1) {
lc_prompt[len] = *lc_data;
lc_prompt[len + 1] = 0;
lc_prompt[len + 1] = '\0';
}
}
} else if (expand_prefix_found) {
@ -155,66 +157,73 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
if (*lc_data == '{')
parameter_found = 1;
else {
int i = check_format_view (lc_data);
int i;
char *v;
if (i) {
i = check_format_view (lc_data);
if (i != 0) {
lc_data += i - 1;
run_view = 1;
} else if ((i = check_format_cd (lc_data)) > 0) {
is_cd = 1;
quote_func = fake_name_quote;
do_local_copy = 0;
p = buffer;
lc_data += i - 1;
} else if ((i = check_format_var (lc_data, &v)) > 0 && v) {
fputs (v, cmd_file);
g_free (v);
lc_data += i;
} else {
char *text;
if (*lc_data == 'f') {
if (do_local_copy) {
localcopy = mc_getlocalcopy (filename);
if (localcopy == NULL) {
fclose (cmd_file);
unlink (file_name);
g_free (file_name);
return;
}
mc_stat (localcopy, &mystat);
localmtime = mystat.st_mtime;
text = (*quote_func) (localcopy, 0);
} else {
fn = vfs_canon_and_translate (filename);
text = (*quote_func) (fn, 0);
g_free (fn);
}
i = check_format_cd (lc_data);
if (i > 0) {
is_cd = 1;
quote_func = fake_name_quote;
do_local_copy = 0;
p = buffer;
lc_data += i - 1;
} else {
text = expand_format (NULL, *lc_data, !is_cd);
}
if (!is_cd)
fputs (text, cmd_file);
else {
strcpy (p, text);
p = strchr (p, 0);
i = check_format_var (lc_data, &v);
if (i > 0 && v != NULL) {
fputs (v, cmd_file);
g_free (v);
lc_data += i;
} else {
char *text;
if (*lc_data != 'f')
text = expand_format (NULL, *lc_data, !is_cd);
else {
if (do_local_copy) {
localcopy = mc_getlocalcopy (filename);
if (localcopy == NULL) {
fclose (cmd_file);
unlink (file_name);
g_free (file_name);
return;
}
mc_stat (localcopy, &mystat);
localmtime = mystat.st_mtime;
text = quote_func (localcopy, 0);
} else {
fn = vfs_canon_and_translate (filename);
text = quote_func (fn, 0);
g_free (fn);
}
}
if (!is_cd)
fputs (text, cmd_file);
else {
strcpy (p, text);
p = strchr (p, 0);
}
g_free (text);
written_nonspace = 1;
}
}
g_free (text);
written_nonspace = 1;
}
}
} else {
if (*lc_data == '%')
expand_prefix_found = 1;
else {
if (*lc_data != ' ' && *lc_data != '\t')
written_nonspace = 1;
if (is_cd)
*(p++) = *lc_data;
else
fputc (*lc_data, cmd_file);
}
} else if (*lc_data == '%')
expand_prefix_found = 1;
else {
if (*lc_data != ' ' && *lc_data != '\t')
written_nonspace = 1;
if (is_cd)
*(p++) = *lc_data;
else
fputc (*lc_data, cmd_file);
}
} /* for */
@ -223,9 +232,8 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
* Don't do it for the viewer - it may need to rerun the script,
* so we clean up after calling view().
*/
if (!run_view) {
if (!run_view)
fprintf (cmd_file, "\n/bin/rm -f %s\n", file_name);
}
fclose (cmd_file);
@ -285,7 +293,6 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
LINES - keybar_visible -
output_lines - 1,
LINES - keybar_visible - 1);
}
}
}

Просмотреть файл

@ -1153,7 +1153,8 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c
{
if (S_ISLNK (src_stats.st_mode) && ctx->stable_symlinks)
{
if ((return_status = make_symlink (ctx, s, d)) == FILE_CONT)
return_status = make_symlink (ctx, s, d);
if (return_status == FILE_CONT)
goto retry_src_remove;
else
return return_status;

Просмотреть файл

@ -76,7 +76,8 @@ my_mkdir_rec (char *s, mode_t mode)
q = vfs_canon (p);
g_free (p);
if (!(result = my_mkdir_rec (q, mode)))
result = my_mkdir_rec (q, mode);
if (result == 0)
result = mc_mkdir (s, mode);
g_free (q);

Просмотреть файл

@ -1327,11 +1327,14 @@ hot_next_token (void)
while ((c = getc (hotlist_file)) != EOF && c != '"')
{
if (c == '\\')
if ((c = getc (hotlist_file)) == EOF)
{
c = getc (hotlist_file);
if (c == EOF)
{
g_string_free (tkn_buf, TRUE);
return TKN_EOF;
}
}
g_string_append_c (tkn_buf, c == '\n' ? ' ' : c);
}
if (c == EOF)
@ -1340,7 +1343,8 @@ hot_next_token (void)
ret = TKN_STRING;
break;
case '\\':
if ((c = getc (hotlist_file)) == EOF)
c = getc (hotlist_file);
if (c == EOF)
{
g_string_free (tkn_buf, TRUE);
return TKN_EOF;
@ -1380,7 +1384,8 @@ while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
}
#define CHECK_TOKEN(_TKN_) \
if ((tkn = hot_next_token ()) != _TKN_) { \
tkn = hot_next_token (); \
if (tkn != _TKN_) { \
hotlist_state.readonly = 1; \
hotlist_state.file_error = 1; \
while (tkn != TKN_EOL && tkn != TKN_EOF) \
@ -1537,7 +1542,8 @@ load_hotlist (void)
*/
hotlist->directory = g_strdup ("Hotlist");
if ((hotlist_file = fopen (hotlist_file_name, "r")) == 0)
hotlist_file = fopen (hotlist_file_name, "r");
if (hotlist_file == NULL)
{
int result;
@ -1649,7 +1655,8 @@ save_hotlist (void)
{
mc_util_make_backup_if_possible (hotlist_file_name, ".bak");
if ((hotlist_file = fopen (hotlist_file_name, "w")) != 0)
hotlist_file = fopen (hotlist_file_name, "w");
if (hotlist_file != NULL)
{
hot_save_group (hotlist);
fclose (hotlist_file);

Просмотреть файл

@ -440,14 +440,24 @@ directory_history_add (struct WPanel *panel, const char *dir)
static const char *
get_parent_dir_name (const char *cwd, const char *lwd)
{
const char *p;
if (strlen (lwd) > strlen (cwd))
if ((p = strrchr (lwd, PATH_SEP)) && !strncmp (cwd, lwd, p - lwd) &&
((gsize) strlen (cwd) == (gsize) p - (gsize) lwd || (p == lwd && cwd[0] == PATH_SEP &&
cwd[1] == '\0')))
{
size_t llen, clen;
llen = strlen (lwd);
clen = strlen (cwd);
if (llen > clen)
{
const char *p;
p = strrchr (lwd, PATH_SEP);
if ((p != NULL)
&& (strncmp (cwd, lwd, (size_t) (p - lwd)) == 0)
&& (clen == (size_t) (p - lwd)
|| ((p == lwd) && (cwd[0] == PATH_SEP) && (cwd[1] == '\0'))))
return (p + 1);
}
}
return NULL;
}

Просмотреть файл

@ -668,7 +668,8 @@ read_filesystem_list (int need_fs_type, int all_fs)
if (!getcwd (dir, _POSIX_PATH_MAX))
return (NULL);
if ((fd = open (dir, O_RDONLY)) == -1)
fd = open (dir, O_RDONLY);
if (fd == -1)
return (NULL);
i = disk_get_entry (fd, &de);
@ -756,7 +757,7 @@ void
my_statfs (struct my_statfs *myfs_stats, const char *path)
{
#ifdef HAVE_INFOMOUNT_LIST
int i, len = 0;
size_t i, len = 0;
struct mount_entry *entry = NULL;
struct mount_entry *temp = mount_list;
struct fs_usage fs_use;
@ -765,7 +766,7 @@ my_statfs (struct my_statfs *myfs_stats, const char *path)
{
i = strlen (temp->me_mountdir);
if (i > len && (strncmp (path, temp->me_mountdir, i) == 0))
if (!entry || (path[i] == PATH_SEP || path[i] == 0))
if (!entry || (path[i] == PATH_SEP || path[i] == '\0'))
{
len = i;
entry = temp;
@ -800,7 +801,8 @@ my_statfs (struct my_statfs *myfs_stats, const char *path)
struct mount_entry *entry;
struct fs_usage fs_use;
if ((entry = read_filesystem_list (0, 0)) != NULL)
entry = read_filesystem_list (0, 0);
if (entry != NULL)
{
get_fs_usage (entry->me_mountdir, &fs_use);

Просмотреть файл

@ -498,7 +498,8 @@ init_subshell (void)
}
if (subshell_pid == 0)
{ /* We are in the child process */
{
/* We are in the child process */
init_subshell_child (pty_name);
}
@ -1254,20 +1255,20 @@ pty_open_master (char *pty_name)
for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1; ++ptr1)
{
pty_name[8] = *ptr1;
for (ptr2 = "0123456789abcdef"; *ptr2; ++ptr2)
for (ptr2 = "0123456789abcdef"; *ptr2 != '\0'; ++ptr2)
{
pty_name[9] = *ptr2;
/* Try to open master */
if ((pty_master = open (pty_name, O_RDWR)) == -1)
pty_master = open (pty_name, O_RDWR);
if (pty_master == -1)
{
if (errno == ENOENT) /* Different from EIO */
return -1; /* Out of pty devices */
else
continue; /* Try next pty device */
continue; /* Try next pty device */
}
pty_name[5] = 't'; /* Change "pty" to "tty" */
if (access (pty_name, 6))
if (access (pty_name, 6) != 0)
{
close (pty_master);
pty_name[5] = 'p';
@ -1293,7 +1294,8 @@ pty_open_slave (const char *pty_name)
/* chown (pty_name, getuid (), group_info->gr_gid); FIXME */
/* chmod (pty_name, S_IRUSR | S_IWUSR | S_IWGRP); FIXME */
}
if ((pty_slave = open (pty_name, O_RDWR)) == -1)
pty_slave = open (pty_name, O_RDWR);
if (pty_slave == -1)
fprintf (stderr, "open (pty_name, O_RDWR): %s\r\n", pty_name);
fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
return pty_slave;

Просмотреть файл

@ -403,7 +403,8 @@ tree_store_save (void)
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
mc_util_make_backup_if_possible (name, ".tmp");
if ((retval = tree_store_save_to (name)) != 0)
retval = tree_store_save_to (name);
if (retval != 0)
{
mc_util_restore_from_backup_if_possible (name, ".tmp");
g_free (name);

Просмотреть файл

@ -301,8 +301,8 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
*block = 0;
for (i = 0; i < panel->count; i++)
if (panel->dir.list[i].f.marked) {
strcat (block, tmp =
(*quote_func) (panel->dir.list[i].fname, 0));
tmp = (*quote_func) (panel->dir.list[i].fname, 0);
strcat (block, tmp);
g_free (tmp);
strcat (block, " ");
if (c_lc == 'u')
@ -784,7 +784,8 @@ user_menu_cmd (struct WEdit *edit_widget)
}
}
if ((data = load_file (menu)) == NULL){
data = load_file (menu);
if (data == NULL) {
message (D_ERROR, MSG_ERROR, _(" Cannot open file %s \n %s "),
menu, unix_error_string (errno));
g_free (menu);

Просмотреть файл

@ -373,7 +373,8 @@ mcview_load_command_output (mcview_t * view, const char *command)
mcview_close_datasource (view);
open_error_pipe ();
if ((fp = popen (command, "r")) == NULL)
fp = popen (command, "r");
if (fp == NULL)
{
/* Avoid two messages. Message from stderr has priority. */
mcview_display (view);

Просмотреть файл

@ -347,7 +347,8 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
else if (file != NULL && file[0] != '\0')
{
/* Open the file */
if ((fd = mc_open (file, O_RDONLY | O_NONBLOCK)) == -1)
fd = mc_open (file, O_RDONLY | O_NONBLOCK);
if (fd == -1)
{
g_snprintf (tmp, sizeof (tmp), _(" Cannot open \"%s\"\n %s "),
file, unix_error_string (errno));