home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip512.zip / tops20 / tops20.c < prev   
C/C++ Source or Header  |  1994-08-12  |  6KB  |  267 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   tops20.c
  4.  
  5.   TOPS20-specific routines for use with Info-ZIP's UnZip 5.1 and later.
  6.  
  7.   Contains:  mapattr()
  8.              close_outfile()
  9.              version()
  10.              upper()
  11.              enquote()
  12.              dequote()
  13.              fnlegal()
  14.  
  15.   (not yet ported:  do_wild(), mapname(), checkdir(), ...)
  16.  
  17.   ---------------------------------------------------------------------------*/
  18.  
  19.  
  20. #include "unzip.h"
  21.  
  22.  
  23. /**********************/
  24. /* Function mapattr() */
  25. /**********************/
  26.  
  27. int mapattr()      /* just like Unix except no umask() */
  28. {
  29.     ulg  tmp = crec.external_file_attributes;
  30.  
  31.     switch (pInfo->hostnum) {
  32.         case UNIX_:
  33.         case VMS_:
  34.             pInfo->file_attr = (unsigned)(tmp >> 16);
  35.             break;
  36.         case AMIGA_:
  37.             tmp = (unsigned)(tmp>>1 & 7);   /* Amiga RWE bits */
  38.             pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
  39.             break;
  40.         case FS_FAT_:   /* MSDOS half of attributes should always be correct */
  41.         case FS_HPFS_:
  42.         case FS_NTFS_:
  43.         case MAC_:
  44.         case ATARI_:
  45.         case TOPS20_:
  46.         default:
  47.             tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
  48.             pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
  49.             break;
  50. #if 0
  51.         case ATARI_:
  52.         case TOPS20_:
  53.         default:
  54.             pInfo->file_attr = 0666;
  55.             break;
  56. #endif
  57.     } /* end switch (host-OS-created-by) */
  58.  
  59.     return 0;
  60.  
  61. } /* end function mapattr() */
  62.  
  63.  
  64.  
  65.  
  66.  
  67. /****************************/
  68. /* Function close_outfile() */
  69. /****************************/
  70.  
  71. void close_outfile()
  72. {
  73. #   define JSYS_CLASS           0070000000000
  74. #   define FLD(val,mask)        (((unsigned)(val)*((mask)&(-(mask))))&(mask))
  75. #   define _DEFJS(name,class)   (FLD(class,JSYS_CLASS) | (monsym(name)&0777777))
  76. #   define IDTIM                _DEFJS("IDTIM%", 1)
  77. #   define SFTAD                _DEFJS("SFTAD%", 0)
  78. #   define YRBASE               1900
  79.     int ablock[5], tblock[2];
  80.     int yr, mo, dy, hh, mm, ss;
  81.     char temp[100];
  82.     unsigned tad;
  83.  
  84.  
  85.     /* dissect the date */
  86.     yr = ((lrec.last_mod_file_date >> 9) & 0x7f) + (1980 - YRBASE);
  87.     mo = (lrec.last_mod_file_date >> 5) & 0x0f;
  88.     dy = lrec.last_mod_file_date & 0x1f;
  89.  
  90.     /* dissect the time */
  91.     hh = (lrec.last_mod_file_time >> 11) & 0x1f;
  92.     mm = (lrec.last_mod_file_time >> 5) & 0x3f;
  93.     ss = (lrec.last_mod_file_time & 0x1f) * 2;
  94.     
  95.     sprintf(temp, "%02d/%02d/%02d %02d:%02d:%02d", mo, dy, yr, hh, mm, ss);
  96.  
  97.     ablock[1] = (int)(temp - 1);
  98.     ablock[2] = 0;
  99.     if (!jsys(IDTIM, ablock)) {
  100.         fprintf(stderr, "error:  IDTIM failure for %s\n", filename);
  101.         fclose(outfile);
  102.         return;
  103.     }
  104.  
  105.     tad = ablock[2];
  106.     tblock[0] = tad;
  107.     tblock[1] = tad;
  108.     tblock[2] = -1;
  109.  
  110.     ablock[1] = fcntl(fileno(outfile), F_GETSYSFD, 0); /* _uffd[outfd]->uf_ch */
  111.     ablock[2] = (int) tblock;
  112.     ablock[3] = 3;
  113.     if (!jsys(SFTAD, ablock))
  114.         fprintf(stderr, "error:  can't set the time for %s\n", filename);
  115.  
  116.     fclose(outfile);
  117.  
  118. } /* end function close_outfile() */
  119.  
  120.  
  121.  
  122.  
  123.  
  124. #ifndef SFX
  125.  
  126. /************************/
  127. /*  Function version()  */
  128. /************************/
  129.  
  130. void version()
  131. {
  132.     extern char Far  CompiledWith[];
  133. #if 0
  134.     char buf[40];
  135. #endif
  136.  
  137.     printf(LoadFarString(CompiledWith),
  138.  
  139. #ifdef __GNUC__
  140.       "gcc ", __VERSION__,
  141. #else
  142. #  if 0
  143.       "cc ", (sprintf(buf, " version %d", _RELEASE), buf),
  144. #  else
  145. #  ifdef __COMPILER_KCC__
  146.       "KCC", "",
  147. #  else
  148.       "unknown compiler", "",
  149. #  endif
  150. #  endif
  151. #endif
  152.  
  153.       "TOPS-20",
  154.  
  155. #if defined(foobar) || defined(FOOBAR)
  156.       " (Foo BAR)",   /* OS version or hardware */
  157. #else
  158.       "",
  159. #endif /* Foo BAR */
  160.  
  161. #ifdef __DATE__
  162.       " on ", __DATE__
  163. #else
  164.       "", ""
  165. #endif
  166.       );
  167.  
  168. } /* end function version() */
  169.  
  170. #endif /* !SFX */
  171.  
  172.  
  173.  
  174.  
  175.  
  176. /**********************/
  177. /*  Function upper()  */
  178. /**********************/
  179.  
  180. int upper(s)        /* returns s in uppercase */
  181.     char *s;        /* string to be uppercased */
  182. {
  183.     for (;  *s;  ++s)
  184.         *s = toupper(*s);
  185. }
  186.  
  187.  
  188.  
  189.  
  190.  
  191. /************************/
  192. /*  Function enquote()  */
  193. /************************/
  194.  
  195. int enquote(s)      /* calls dequote(s) to normalize string, then */
  196.     char *s;        /*  inserts ^Vs before otherwise illegal characters */
  197. {                   /*  in s, assuming that s is a TOPS-20 filename */
  198.     char d[100];
  199.     char *p, *q;
  200.     char c;
  201.  
  202.     if (s && *s) {
  203.         dequote(s);
  204.         p = s - 1;
  205.         q = d - 1;
  206.         while (c = *++p) {
  207.             if (!fnlegal(c))
  208.                 *++q = '\026';
  209.             *++q = c;
  210.         }
  211.         *++q = '\0';
  212.         strcpy(s, d);
  213.     }
  214.     return 0;
  215. }
  216.  
  217.  
  218.  
  219.  
  220.  
  221. /************************/
  222. /*  Function dequote()  */
  223. /************************/
  224.  
  225. int dequote(s)        /* returns s without ^Vs */
  226.     char *s;          /* string to be dequoted */
  227. {
  228.     char d[100];
  229.     char *p, *q;
  230.     int c;
  231.  
  232.     if (s && *s) {
  233.         p = s - 1;
  234.         q = d - 1;
  235.         while (c = *++p)
  236.             if (c != '\026')
  237.                 *++q = c;
  238.         *++q = '\0';
  239.         strcpy(s, d);
  240.     }
  241.     return 0;
  242. }
  243.  
  244.  
  245.  
  246.  
  247.  
  248. /************************/
  249. /*  Function fnlegal()  */
  250. /************************/
  251.  
  252. int fnlegal(c)         /* returns TRUE if c is a member of the */
  253.     char c;            /*  legal character set for filenames */
  254. {
  255.     char *q;
  256.     static char *legals = {"$%**-<>>AZ[[]]__az"};
  257.  
  258.     q = legals;
  259.     while (*q)
  260.         if (c < *q++)
  261.             break;
  262.         else if (c <= *q++)
  263.             return TRUE;
  264.  
  265.     return FALSE;
  266. }
  267.