home *** CD-ROM | disk | FTP | other *** search
- From: w8sdz@WSMR-SIMTEL20.ARMY.MIL (Keith Petersen)
- Newsgroups: alt.sources
- Subject: [ibm-pc-binaries] xxu.c - 20-to-Unix filename converter
- Message-ID: <11698@stag.math.lsa.umich.edu>
- Date: 12 Apr 90 23:00:31 GMT
-
- Archive-name: xxu/12-Apr-90
- Original-posting-by: w8sdz@WSMR-SIMTEL20.ARMY.MIL (Keith Petersen)
- Original-subject: xxu.c - 20-to-Unix filename converter
- Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
-
- [This is an experimental alt.sources re-posting from the newsgroup(s)
- comp.binaries.ibm.pc.d. Comments on this service to emv@math.lsa.umich.edu
- (Edward Vielmetti).]
-
-
- #!/bin/sh
- # shar: Shell Archiver (v1.24)
- # Packed Tue Nov 15 12:22:31 EDT 1988 by davidsen
- # from directory /usr2/davidsen/tmp
- #
- # Run the following text with /bin/sh to create:
- # xxu.c
- #
- sed 's/^X//' << 'SHAR_EOF' > xxu.c &&
- X/* X X U -- 20-to-Unix filename converter */
- X
- X/*
- X Change DEC-20 or VAX/VMS style filenames into normal Unix names.
- X Handy for use after ftp MGETs, when you find your directory full of
- X files with names like LIB:<KERMIT>CKUFIO.C.2 or FRED::[ETHEL]A.B;37
- X when all you really wanted was ckufio.c and a.b.
- X
- X Usage: xxu file(s)
- X
- X Action: Renames argument files as follows:
- X strips Unix path name from front (up to rightmost '/') if present
- X strips DEC device:, node:: names from front (up to rightmost ':') if present
- X strips DEC-20 <directory> or VMS [directory] name if present
- X strips DEC-20 version number from end (everything after 2nd dot) if present
- X strips VMS generation number from end (everything after ';') if present
- X lowercases any uppercase letters
- X honors DEC-20 CTRL-V quote for special characters
- X discards unquoted unprintable characters
- X if result is null, file is renamed to xxfile-n, where n is a number.
- X if result would write over an existing file, file also renamed to xxfile-n.
- X
- X Recommended procedure: make a new directory, cd to it, then FTP files
- X from DEC-20 or VMS system, then do "xxu *".
- X
- X Author: F. da Cruz, CUCCA, July 85
- X*/
- X
- X#include <stdio.h>
- X#if SYSV | M_XENIX
- X#include <sys/types.h>
- X#endif
- X#include <ctype.h>
- X#include <sys/file.h> /* For access() */
- X/* <<<<<<<< define NO_RENAME on cc line if missing >>>>>>>> */
- X
- Xchar name[500]; /* File name buffer */
- Xchar *pp, *cp, *xp; /* Character pointers */
- Xchar delim; /* Directory Delimiter */
- Xint dc = 0, n = 0; /* Counters */
- Xint quote = 0, indir = 0; done = 0; /* Flags */
- X
- Xmain(argc,argv) int argc; char **argv; {
- X
- X if (argc < 2) { /* Give message if no args */
- X fprintf(stderr,"Usage: xxu file(s)\n");
- X exit(1);
- X }
- X n = 0; /* Unfixable filename counter */
- X while (--argc > 0) { /* For all files on command line... */
- X argv++;
- X xp = *argv; /* Copy pointer for simplicity */
- X printf("%s ",*argv); /* Echo name of this file */
- X
- X pp = name; /* Point to translation buffer */
- X *name = '\0'; /* Initialize buffer */
- X dc = 0; /* Filename dot counter */
- X done = 0; /* Flag for early completion */
- X
- X for (cp = xp; (*cp != '\0') && !done; cp++) { /* Loop thru chars... */
- X
- X if (quote) { /* If this char quoted, */
- X *pp++ = *cp; /* include it literally. */
- X quote = 0;
- X }
- X else if (indir) { /* If in directory name, */
- X if (*cp == delim) indir = 0; /* look for end delimiter. */
- X }
- X else switch (*cp) {
- X case '<': /* Discard DEC-20 directory name */
- X indir = 1;
- X delim = '>';
- X break;
- X case '[': /* Discard VMS directory name */
- X indir = 1;
- X delim = ']';
- X break;
- X case '/': /* Discard Unix path name */
- X case ':': /* or DEC dev: or node:: name */
- X pp = name;
- X break;
- X case '.': /* DEC -20 generation number */
- X if (++dc == 1) /* Keep first dot */
- X *pp++ = *cp;
- X else /* Discard everything starting */
- X done = 1; /* with second dot. */
- X break;
- X case ';': /* VMS generation or DEC-20 attrib */
- X done = 1; /* Discard everything starting with */
- X break; /* semicolon */
- X case '\026': /* Control-V quote for special chars */
- X quote = 1; /* Set flag for next time. */
- X break;
- X default:
- X if (isupper(*cp)) /* Uppercase letter to lowercase */
- X *pp++ = tolower(*cp);
- X else if (*cp == ' ')/* change blanks to underscore */
- X *pp++ = '_';
- X else if (isprint(*cp)) /* Other printable, just keep */
- X *pp++ = *cp;
- X }
- X }
- X *pp = '\0'; /* Done with name, terminate it */
- X if (strcmp(name,xp) == 0) { /* If no renaming necessary, */
- X printf("(ok)\n"); /* just give message. */
- X continue;
- X }
- X while (*name == '\0' || access(name,0) == 0) { /* Find unique name */
- X sprintf(name,"xxfile-%d",n++);
- X }
- X printf("=> %s ",name); /* Tell what new name will be */
- X if (rename(xp,name) == 0) /* Try to rename it */
- X printf("(ok)\n"); /* Say what happened */
- X else
- X perror("failed");
- X }
- X exit(0); /* Done. */
- X}
- X
- X/*****************************************************************
- X | rename - for systems lacking the rename system call
- X |----------------------------------------------------------------
- X | Arguments:
- X | 1) string - current filename
- X | 2) string - new filename
- X ****************************************************************/
- X
- X#if NO_RENAME
- Xrename(oldname, newname)
- X char *oldname, *newname;
- X{
- X char cmdline[133];
- X
- X sprintf(cmdline, "mv \"%s\" %s", oldname, newname);
- X return system(cmdline);
- X}
- X#endif
- SHAR_EOF
- chmod 0644 xxu.c || echo "restore of xxu.c fails"
- exit 0
-