#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#else
extern int fprintf ();
extern int tolower ();
#endif
extern char *strdup ();
extern int system ();
#include "gripes.h"
char *
mkprogname (s)
register char *s;
{
char *t;
t = strrchr (s, '/');
if (t == (char *)NULL)
t = s;
else
t++;
return strdup (t);
}
void
downcase (s)
unsigned char *s;
{
register unsigned char c;
while ((c = *s) != '\0')
{
if (isalpha (c))
*s = tolower (c);
s++;
}
}
int
is_newer (fa, fb)
register char *fa;
register char *fb;
{
struct stat fa_sb;
struct stat fb_sb;
register int fa_stat;
register int fb_stat;
register int status = 0;
fa_stat = stat (fa, &fa_sb);
if (fa_stat != 0)
status = 1;
fb_stat = stat (fb, &fb_sb);
if (fb_stat != 0)
status |= 2;
if (status != 0)
return -status;
return (fa_sb.st_mtime > fb_sb.st_mtime);
}
int
is_directory (path)
char *path;
{
struct stat sb;
register int status;
status = stat (path, &sb);
if (status != 0)
return -1;
return ((sb.st_mode & S_IFDIR) == S_IFDIR);
}
int
do_system_command (command)
char *command;
{
int status = 0;
extern int debug;
if (debug)
fprintf (stderr, "\ntrying command: %s\n", command);
else
status = system (command);
if (status == -1) {
fprintf(stderr,
"wait() for exit status of shell failed in function system()\n");
return 0;
} else if (status == 127 || status == (127 << 8)) {
fprintf(stderr, "execution of the shell failed in function system()\n");
return 0;
}
if (WIFSIGNALED(status))
return -1;
else if (WEXITSTATUS(status)) {
gripe_system_command (status);
return 0;
}
else
return 1;
}