home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1172 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  5.5 KB

  1. From: w8sdz@WSMR-SIMTEL20.ARMY.MIL (Keith Petersen)
  2. Newsgroups: alt.sources
  3. Subject: [ibm-pc-binaries] xxu.c - 20-to-Unix filename converter
  4. Message-ID: <11698@stag.math.lsa.umich.edu>
  5. Date: 12 Apr 90 23:00:31 GMT
  6.  
  7. Archive-name: xxu/12-Apr-90
  8. Original-posting-by: w8sdz@WSMR-SIMTEL20.ARMY.MIL (Keith Petersen)
  9. Original-subject: xxu.c - 20-to-Unix filename converter
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [This is an experimental alt.sources re-posting from the newsgroup(s)
  13. comp.binaries.ibm.pc.d. Comments on this service to emv@math.lsa.umich.edu 
  14. (Edward Vielmetti).]
  15.  
  16.  
  17. #!/bin/sh
  18. # shar:    Shell Archiver  (v1.24)
  19. #    Packed Tue Nov 15 12:22:31 EDT 1988 by davidsen
  20. #    from directory /usr2/davidsen/tmp
  21. #
  22. #    Run the following text with /bin/sh to create:
  23. #      xxu.c
  24. #
  25. sed 's/^X//' << 'SHAR_EOF' > xxu.c &&
  26. X/*  X X U  --  20-to-Unix filename converter  */
  27. X
  28. X/*
  29. X Change DEC-20 or VAX/VMS style filenames into normal Unix names.
  30. X Handy for use after ftp MGETs, when you find your directory full of
  31. X files with names like LIB:<KERMIT>CKUFIO.C.2 or FRED::[ETHEL]A.B;37
  32. X when all you really wanted was ckufio.c and a.b.
  33. X
  34. X Usage: xxu file(s)
  35. X
  36. X Action: Renames argument files as follows:
  37. X   strips Unix path name from front (up to rightmost '/') if present
  38. X   strips DEC device:, node:: names from front (up to rightmost ':') if present
  39. X   strips DEC-20 <directory> or VMS [directory] name if present
  40. X   strips DEC-20 version number from end (everything after 2nd dot) if present
  41. X   strips VMS generation number from end (everything after ';') if present
  42. X   lowercases any uppercase letters
  43. X   honors DEC-20 CTRL-V quote for special characters
  44. X   discards unquoted unprintable characters
  45. X   if result is null, file is renamed to xxfile-n, where n is a number.
  46. X   if result would write over an existing file, file also renamed to xxfile-n.
  47. X
  48. X Recommended procedure: make a new directory, cd to it, then FTP files
  49. X from DEC-20 or VMS system, then do "xxu *".
  50. X
  51. X Author:  F. da Cruz, CUCCA, July 85
  52. X*/
  53. X
  54. X#include <stdio.h>
  55. X#if    SYSV | M_XENIX
  56. X#include <sys/types.h>
  57. X#endif
  58. X#include <ctype.h>
  59. X#include <sys/file.h>            /* For access() */
  60. X/* <<<<<<<< define NO_RENAME on cc line if missing >>>>>>>> */
  61. X
  62. Xchar name[500];                /* File name buffer */
  63. Xchar *pp, *cp, *xp;            /* Character pointers */
  64. Xchar delim;                /* Directory Delimiter */
  65. Xint dc = 0, n = 0;            /* Counters */
  66. Xint quote = 0, indir = 0; done = 0;    /* Flags */
  67. X
  68. Xmain(argc,argv) int argc; char **argv; {
  69. X
  70. X    if (argc < 2) {            /* Give message if no args */
  71. X    fprintf(stderr,"Usage: xxu file(s)\n");
  72. X    exit(1);
  73. X    }
  74. X    n = 0;                /* Unfixable filename counter */
  75. X    while (--argc > 0) {        /* For all files on command line... */
  76. X    argv++;
  77. X    xp = *argv;            /* Copy pointer for simplicity */
  78. X    printf("%s ",*argv);        /* Echo name of this file */
  79. X
  80. X    pp = name;            /* Point to translation buffer */
  81. X    *name = '\0';            /* Initialize buffer */
  82. X    dc = 0;                /* Filename dot counter */
  83. X    done = 0;            /* Flag for early completion */
  84. X
  85. X    for (cp = xp; (*cp != '\0') && !done; cp++) { /* Loop thru chars... */
  86. X
  87. X        if (quote) {        /* If this char quoted, */
  88. X        *pp++ = *cp;        /*  include it literally. */
  89. X        quote = 0;
  90. X        }
  91. X        else if (indir) {        /* If in directory name, */
  92. X        if (*cp == delim) indir = 0; /* look for end delimiter. */
  93. X        }
  94. X        else switch (*cp) {
  95. X        case '<':        /* Discard DEC-20 directory name */
  96. X            indir = 1;
  97. X            delim = '>';
  98. X            break;
  99. X        case '[':        /* Discard VMS directory name */
  100. X            indir = 1;
  101. X            delim = ']';
  102. X            break;
  103. X        case '/':        /* Discard Unix path name */
  104. X        case ':':               /*  or DEC dev: or node:: name */
  105. X            pp = name; 
  106. X            break;
  107. X        case '.':        /* DEC -20 generation number */
  108. X                if (++dc == 1)    /* Keep first dot */
  109. X                *pp++ = *cp;
  110. X            else        /* Discard everything starting */
  111. X                done = 1;    /* with second dot. */
  112. X            break;
  113. X        case ';':        /* VMS generation or DEC-20 attrib */
  114. X            done = 1;        /* Discard everything starting with */
  115. X            break;        /* semicolon */
  116. X            case '\026':        /* Control-V quote for special chars */
  117. X            quote = 1;        /* Set flag for next time. */
  118. X            break;
  119. X        default:
  120. X            if (isupper(*cp))      /* Uppercase letter to lowercase */
  121. X                    *pp++ = tolower(*cp);
  122. X            else if (*cp == ' ')/* change blanks to underscore */
  123. X                *pp++ = '_';
  124. X            else if (isprint(*cp)) /* Other printable, just keep */
  125. X                *pp++ = *cp;
  126. X        }
  127. X    }
  128. X    *pp = '\0';            /* Done with name, terminate it */
  129. X    if (strcmp(name,xp) == 0) {    /* If no renaming necessary, */
  130. X        printf("(ok)\n");        /*  just give message. */
  131. X        continue;
  132. X        }
  133. X    while (*name == '\0' || access(name,0) == 0) { /* Find unique name */
  134. X        sprintf(name,"xxfile-%d",n++);
  135. X    }
  136. X    printf("=> %s ",name);        /* Tell what new name will be */
  137. X    if (rename(xp,name) == 0)    /* Try to rename it */
  138. X        printf("(ok)\n");        /* Say what happened */
  139. X    else
  140. X        perror("failed");
  141. X    }
  142. X    exit(0);                /* Done. */
  143. X}
  144. X
  145. X/*****************************************************************
  146. X |  rename - for systems lacking the rename system call
  147. X |----------------------------------------------------------------
  148. X |  Arguments:
  149. X |   1) string - current filename
  150. X |   2) string - new filename
  151. X ****************************************************************/
  152. X
  153. X#if    NO_RENAME
  154. Xrename(oldname, newname)
  155. X    char *oldname, *newname;
  156. X{
  157. X    char cmdline[133];
  158. X    
  159. X    sprintf(cmdline, "mv \"%s\" %s", oldname, newname);
  160. X    return system(cmdline);
  161. X}
  162. X#endif
  163. SHAR_EOF
  164. chmod 0644 xxu.c || echo "restore of xxu.c fails"
  165. exit 0
  166.