Back to index

tetex-bin  3.0
Functions
newer.c File Reference
#include "c-auto.h"
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>

Go to the source code of this file.

Functions

int main P2C (int, argc, char **, argv)

Function Documentation

int main P2C ( int  ,
argc  ,
char **  ,
argv   
)

Definition at line 43 of file newer.c.

{
        struct stat x, y;

        if (argc > 1 && strcmp (argv[1], "--help") == 0) {
          fputs ("Usage: newer [OPTION]... FILE1 FILE2\n\
  Exit successfully if FILE1 exists and is at least as recent as FILE2.\n\
\n\
--help      display this help and exit\n\
--version   output version information and exit\n\n", stdout);
          fputs ("Email bug reports to tex-k@mail.tug.org.\n", stdout);
          exit(0);
        } else if (argc > 1 && strcmp (argv[1], "--version") == 0) {
          printf ("newer%s 0.63\n\
Copyright (C) 1996 AT&T Bell Laboratories.\n\
There is NO warranty.  You may redistribute this software\n\
under the terms of the GNU General Public License\n\
and the newer copyright.\n\
For more information about these matters, see the files\n\
named COPYING and the newer source.\n\
Primary author of newer: John Hobby.\n",
WEB2CVERSION);
          exit (0);
        }

        /* insist on exactly two args */
        if (argc != 3) {
          fputs ("newer: Need exactly two arguments.\n", stderr);
          fputs ("Try `newer --help' for more information.\n", stderr);
          exit(1);
        }
        
        /* does the first file exist? */
        if (stat (argv[1], &x) < 0)
                exit(1);
        
        /* does the second file exist? */
        if (stat (argv[2], &y) < 0)
                exit(0);
        
        /* fail if the first file is older than the second */
        if (x.st_mtime < y.st_mtime)
                exit(1);
        
        /* otherwise, succeed */
        exit(0);
}

Here is the call graph for this function: