
/******************************************************************************

    MODULE
	Touch.c

    DESCRIPTION
	Touch checks the existance (via Lock) of files
	and then either calls SetFileDate if they exist
	or else creates new files

    NOTES
	Kickstart 2.0+ required
	compiles w/ Dice 2.07R - inline-pragmas required
	compiles w/ SAS/C v6.51

    BUGS
	none known

    TODO
	wildcard processing

    EXAMPLES

    SEE ALSO

    INDEX

    HISTORY
	12-02-95 b_noll created (accidently deleted the source)
	12-02-95 b_noll created

    AUTHOR
	Bernd Noll, Brunnenstrasse 55, D-67661 Kaiserslautern
	b_noll@informatik.uni-kl.de

******************************************************************************/

/**************************************
	    Includes
**************************************/

#ifndef   EXEC_LIBRARIES_H
# include <exec/libraries.h>
#endif /* EXEC_LIBRARIES_H */

#ifndef   CLIB_EXEC_PROTOS_H
# include <clib/exec_protos.h>
#endif /* CLIB_EXEC_PROTOS_H */

#ifndef   DOS_DOS_H
# include <dos/dos.h>
#endif /* DOS_DOS_H */

#ifndef   CLIB_DOS_PROTOS_H
# include <clib/dos_protos.h>
#endif /* CLIB_DOS_PROTOS_H */

#include <proto/dos.h>
#include <proto/exec.h>

/**************************************
	    Global Variables
**************************************/


/**************************************
	    Structures
**************************************/

struct _arg {

    STRPTR *file;

}; /* struct  */

/**************************************
	    Implementation
**************************************/

long _main (void)
{
    const char* version = "$VER: Touch 1.0 (12.02.95)";
    long retval = 20;
    struct Library* SysBase = *((struct Library**)4L);
    struct Library* DOSBase;

    if (DOSBase = OpenLibrary (DOSNAME, 37)) {
	struct _arg argv = { 0 };
	APTR   args;
	retval	 = 10;
	if (args = (void*)ReadArgs("FILE/A/M", (LONG*)&argv, NULL)) {
	    int    i;
	    BPTR   bptr;
	    STRPTR name;
	    struct DateStamp ds;

	    retval = 0;

	    for (i = 0; name = argv.file[i]; ++i) {

		DateStamp(&ds);

		if (bptr = Lock(name, SHARED_LOCK)) {
		    UnLock(bptr);

		    if (!SetFileDate(name, &ds)) {
			retval = 10;
			break;
		    } /* if */
		} else if (bptr = Open(name, MODE_NEWFILE)) {
		    Close(bptr);
		} else {
		    retval = 10;
		    break;
		} /* if */
	    } /* for */

	    FreeArgs (args);
	} /* if */
	CloseLibrary (DOSBase);
    } /* if */
    return (retval);
} /* _main */

/******************************************************************************
*****  END Touch.c
******************************************************************************/

