Article 126593 of comp.os.vms:
Path: nntpd.lkg.dec.com!pa.dec.com!decwrl!enews.sgi.com!lll-winken.llnl.gov!hookup!news.mathworks.com!mvb.saic.com!info-vax
From: "Richard B. Gilbert [VAX]" <76702.1567@compuserve.com>
Newsgroups: comp.os.vms
Subject: REQUEST: TOUCH command for OpenVMS
Message-ID: <950808013544_76702.1567_CHN38-1@CompuServe.COM>
Date: 07 Aug 95 21:35:44 EDT
Organization: Info-Vax<==>Comp.Os.Vms Gateway
X-Gateway-Source-Info: Mailing List
Lines: 155

	m_reymond@alpha3.dev.macsch.com (Mike Reymond) writes:

>Is there an OpenVMS equivalent for the UNIX touch command and where can I get 
>it?  Thanks ahead. 

	Try this.  It's slightly enhanced from Tony's original in that it is 
now ANSI compatible and will compile under VAX C or DECC on either an Alpha or
a VAX.  DECC will compile it using /STANDARD=ANSI89.

<<touch.c>>
/* This version of touch includes the patch posted 14 Apr 89 20:14:16 GMT
   by Tony Ivanov, GVG:
	"Also, I have received a 'bug report' for TOUCH.C (in MAKE directory)
	that if no arguments are supplied on the command line that a stack
	dump occurs.  Since I was able to duplicate the bug :-) (don't we all
	hear that!) the fix is as follows:

	Line 31 should be change from:
	for (argc--, pa=(*++argv);  (*pa == '-');  argc--, pa=(*++argv))
to:
	for (argc--, pa=(*++argv);  argc && (*pa == '-');  argc--, pa=(*++argv))
"
*/
# include	<descrip.h>
# include	<file.h>
# include	<rmsdef.h>
# include	<ssdef.h>
# include	<stdio.h>
# include	<stdlib.h>
# include	<unixio.h>
# include	<string.h>
# include	<starlet.h>
# include	<lib$routines.h>
# include	"types.h"

# define	FALSE	(0)
# define	TRUE	(!FALSE)

	static char	fname[256];		/* Buffer to hold actua file
						   name matched by wildcard. */
	static char	related[256];		/* Buffer to hold the related
						   file name. */
	static char	msg_buff[257];		/* Error message from lib$find_file(). */

	$DESCRIPTOR	(fname_desc, fname);
	$DESCRIPTOR	(related_desc, related);
	$DESCRIPTOR	(msg_desc, msg_buff);
	struct dsc$descriptor_s	files_desc =
		{0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};

int touch_file (char*);

int main (int argc, char *argv[])
{
	char	*pa;			/* Pointer to next file name to process. */
	char	*comma;			/* Pointer to comma in file spec. */
	int	context;		/* Context of file search. */
	char	*strchr();		/* A function. */
	int	status;			/* Status of call to lib$find_file(). */
	bool	verbose = FALSE;	/* TRUE for verbose mode. */
	ushort	msg_len;		/* Length of error message returned. */

		/* Check for -v flag. */
	for (argc--, pa=(*++argv);  (*pa == '-');  argc--, pa=(*++argv))
	{	while (*++pa)
		{	switch (*pa)
			{	case 'v':	verbose = TRUE;
						break;
				default:	printf ("touch: unknown flag %c.\n", *pa);
						exit (2);
			}
		}
	}

	for (;  argc;  argc--, argv++)
	{		/* Set up the related file descrtiptor. */
		related_desc.dsc$w_length = 0;
			/* Now process each of the files in the "comma separated list". */
		for (pa=(*argv), comma=strchr(pa,',');  pa;  )
		{		/* Set up local variables. */
			if (comma)
				*comma = '\0';
			files_desc.dsc$w_length = strlen(pa);
			files_desc.dsc$a_pointer = pa;
			context = 0;

				/* Process the next file. */
			while ((status = lib$find_file (&files_desc, &fname_desc, &context, 0, &related_desc, 0, 0)) != RMS$_NMF)
			{	*strchr(fname,' ') = '\0';
				if ((status == RMS$_NORMAL) || (status == RMS$_FNF))
				{	if (verbose)
						printf ("touch(%s)\n", fname);
					touch_file (fname);
				}
				else
				{	printf ("touch: can't touch '%s', ", fname);
					if (sys$getmsg (status, &msg_len, &msg_desc, 0, 0) == SS$_NORMAL)
					{	msg_buff[msg_len] = '\0';
						puts (msg_buff);
					}
					else
						printf ("status = 0x%s.\n", status);
				}
			}

				/* Set up for next file in "comma separated list" (if specified). */
			pa = (comma) ? comma+1 : 0;
			if (pa)
			{	for (;  *pa == ' ';  pa++);			/* Strip off leading blanks. */
				comma = strchr (pa, ',');			/* Find the next comma. */
				strcpy (related, fname);			/* Related file is last file found... */
				related_desc.dsc$w_length = strlen(related);	/* ...from lib$find_file(). */
			}
		}
	}
}


touch_file (file)
	char	*file;
{
	int	fd;

	if ((fd = open (file, O_RDWR | O_CREAT, 0)) < 0)
		fprintf (stderr, "touch: cannot access '%s'.\n", file);
	else
		close (fd);
}

<<types.h>>

# ifndef _GVG_TYPES_
# define _GVG_TYPES_

typedef unsigned char	bool;
typedef char		byte;
typedef unsigned char	ubyte;
typedef unsigned char	uchar;
typedef unsigned short	ushort;
typedef unsigned int	uint;
typedef unsigned long	ulong;

# endif

--
*************************************************************************
*                        Here, there be dragons!                        *
*                       DRAGON@CIS.CompuServe.Com                       *
*                                                                       *
*	I'm job hunting.  Any offers or leads will be appreciated.      *
* I'm looking for something in central NJ or eastern PA.  Thanks!       *
*                                                                       *
*                                                Richard B. Gilbert     *
*************************************************************************



