1: /*
   2:  * A program to create a manifest (shiping list) that is a shell script
   3:  * to return a Unix file name to it's original state after it has been
   4:  * clobbered by MSDOS's file name restrictions.
   5:  *
   6:  *	This code also used in arc, mtools, and pcomm
   7:  */
   8: 
   9: #ifdef BSD
  10: #define strrchr rindex
  11: #endif /* BSD */
  12: 
  13: #include <stdio.h>
  14: #include <ctype.h>
  15: 
  16: main(argc, argv)
  17: int argc;
  18: char *argv[];
  19: {
  20:     int i;
  21:     char *name, *new_name, *dos_name(), *strrchr();
  22:     void exit();
  23: 
  24:     if (argc == 1) {
  25:         fprintf(stderr, "Usage: mkmanifest <list-of-files>\n");
  26:         exit(1);
  27:     }
  28: 
  29:     for (i=1; i<argc; i++) {
  30:                     /* zap the leading path */
  31:         if (name = strrchr(argv[i], '/'))
  32:             name++;
  33:         else
  34:             name = argv[i];
  35:                     /* create new name */
  36:         new_name = dos_name(name);
  37: 
  38:         if (strcmp(new_name, name))
  39:             printf("mv %s %s\n", new_name, name);
  40:     }
  41:     exit(0);
  42: }
  43: 
  44: char *
  45: dos_name(name)
  46: char *name;
  47: {
  48:     static char *dev[9] = {"con", "aux", "com1", "com2", "lpt1", "prn",
  49:     "lpt2", "lpt3", "nul"};
  50:     char *s, *temp, *ext, *strcpy(), *strpbrk(), *strcat();
  51:     char buf[15];
  52:     int i, dot;
  53:     static char ans[13];
  54: 
  55:     strcpy(buf, name);
  56:     temp = buf;
  57:                     /* separate the name from extention */
  58:     ext = "";
  59:     dot = 0;
  60:     for (i=strlen(buf)-1; i>=0; i--) {
  61:         if (buf[i] == '.' && !dot) {
  62:             dot = 1;
  63:             buf[i] = '\0';
  64:             ext = &buf[i+1];
  65:         }
  66:         if (isupper(buf[i]))
  67:             buf[i] = tolower(buf[i]);
  68:     }
  69:                     /* if no name */
  70:     if (*temp == '\0')
  71:         temp = "x";
  72:                     /* if name is a device */
  73:     for (i=0; i<9; i++) {
  74:         if (!strcmp(temp, dev[i]))
  75:             *temp = 'x';
  76:     }
  77:                     /* name too long? */
  78:     if (strlen(temp) > 8)
  79:         *(temp+8) = '\0';
  80:                     /* extention too long? */
  81:     if (strlen(ext) > 3)
  82:         *(ext+3) = '\0';
  83:                     /* illegal characters? */
  84:     while (s = strpbrk(temp, "^+=/[]:',?*\\<>|\". "))
  85:         *s = 'x';
  86: 
  87:     while (s = strpbrk(ext, "^+=/[]:',?*\\<>|\". "))
  88:         *s = 'x';
  89: 
  90:     strcpy(ans, temp);
  91:     if (*ext) {
  92:         strcat(ans, ".");
  93:         strcat(ans, ext);
  94:     }
  95:     return(ans);
  96: }
  97: 
  98: #ifdef BSD
  99: /*
 100:  * Return ptr to first occurrence of any character from `brkset'
 101:  * in the character string `string'; NULL if none exists.
 102:  */
 103: 
 104: char *
 105: strpbrk(string, brkset)
 106: register char *string, *brkset;
 107: {
 108:     register char *p;
 109: 
 110:     if (!string || !brkset)
 111:         return(0);
 112:     do {
 113:         for (p = brkset; *p != '\0' && *p != *string; ++p)
 114:             ;
 115:         if (*p != '\0')
 116:             return(string);
 117:     }
 118:     while (*string++);
 119:     return(0);
 120: }
 121: #endif /* BSD */

Defined functions

dos_name defined in line 44; used 2 times
main defined in line 16; never used
strpbrk defined in line 104; used 3 times

Defined macros

strrchr defined in line 10; used 2 times
Last modified: 1992-06-24
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1928
Valid CSS Valid XHTML 1.0 Strict