[unix-pc.sources] mkmanifest source

egray@fthood.UUCP (06/16/88)

This is a simple little program that creates a shell script that is
designed to restore Unix file names after they have been bludgened to
fit the MSDOS file name restrictions.  It comes in handy when using my
Mtools, Pcomm, or the Unix version of arc that was posted.

All the programs mentioned above take considerable amount of pride in
converting a perfectly good Unix file name to fix the MSDOS rules.
Typically this would include:

	Not case sensitive
	File name <= 8 characters
	Extention <= 3 characters
	No MSDOS device names
	None of the following characters: ^+=/[]:',?*\<>|\. 

For example, this is my mtools directory:

	Conversion	Unixpc.shar	mrd.c
	Makefile	convdate.c	mread.c
	Mdel.1		fixname.c	mren.c
	Mdir.1		getfat.c	msdos.h
	Mmd.1		init.c		mtype.c
	Mrd.1		isdir.c		mwrite.c
	Mread.1		match.c		putfat.c
	Mren.1		mdel.c		search.c
	Mtype.1		mdir.c		subdir.c
	Mwrite.1	mkentry.c	unixname.c
	Readme		mmd.c

To put these files on a MSDOS disk would mean all the uppercase file
names and the Unixpc.shar file (because the extention is 4 characters)
would be modified by Mtools.  Using this example, you'd type:

	mkmanifest *

to produce the following on the stdout:

	mv conversion Conversion
	mv makefile Makefile
	mv mdel.1 Mdel.1
	mv mdir.1 Mdir.1
	mv mmd.1 Mmd.1
	mv mrd. Mrd.1
	mv mread.1 Mread.1
	mv mren.1 Mren.1
	mv mtype.1 Mtype.1
	mv mwrite.1 Mwrite.1
	mv readme Readme
	mv unixpc.sha Unixpc.shar

The output of mkmanifest could be collected in a file and the file
could be put on the diskette to be used later to restore the names.

Typically I use:

	mkmanifest * > manifest

and then include the file manifest with the files on the diskette.

Have fun...

Emmet P. Gray				US Army, HQ III Corps & Fort Hood
...!uunet!uiucuxc!fthood!egray		Attn: AFZF-DE-ENV
					Directorate of Engineering & Housing
					Environmental Management Office
					Fort Hood, TX 76544-5057

-----------------------------------------------------------------------------
/*
 * A program to create a manifest (shiping list) that is a shell script
 * to return a Unix file name to it's original state after it has been
 * clobbered by MSDOS's file name restrictions.
 */

#include <stdio.h>
#include <ctype.h>

main(argc, argv)
int argc;
char *argv[];
{
	int i;
	char *name, *new_name, *fixname(), *strrchr();
	void exit();

	if (argc == 1) {
		fprintf(stderr, "Usage: mkmanifest <list-of-files>\n");
		exit(1);
	}

	for (i=1; i<argc; i++) {
					/* zap the leading path */
		if (name = strrchr(argv[i], '/'))
			name++;
		else
			name = argv[i];
					/* create new name */
		new_name = fixname(name);

		if (strcmp(new_name, name))
			printf("mv %s %s\n", new_name, name);
	}
	exit(0);
}

char *
fixname(name)
char *name;
{
	static char *dev[8] = {"con", "aux", "com1", "lpt1", "prn", "lpt2",
	"lpt3", "nul"};
	char *s, *temp, *ext, *malloc(), *strcpy(), *strpbrk(), *strcat();
	char temp_buf[15];
	int i, dot;
	static char ans[13];

	strcpy(temp_buf, name);
	temp = &temp_buf[0];
					/* separate the name from extention */
	ext = NULL;
	dot = 0;
	for (s = temp; *s; ++s) {
		if (*s == '.' && !dot) {
			dot = 1;
			*s = NULL;
			ext = s + 1;
		}
		if (isupper(*s))
			*s = tolower(*s);
	}
					/* if no name */
	if (*temp == NULL)
		temp = "x";
					/* if name is a device */
	for (i=0; i<8; i++) {
		if (!strcmp(temp, dev[i])) 
			*temp = 'x';
	}
					/* name too long? */
	if (strlen(temp) > 8)
		*(temp+8) = NULL;
					/* extention too long? */
	if (strlen(ext) > 3)
		*(ext+3) = NULL;
					/* illegal characters? */
	while (s = strpbrk(temp, "^+=/[]:',?*\\<>|\". "))
		*s = 'x';

	while (s = strpbrk(ext, "^+=/[]:',?*\\<>|\". "))
		*s = 'x';

	strcpy(ans, temp);
	if (*ext) {
		strcat(ans, ".");
		strcat(ans, ext);
	}
	return(ans);
}