home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip511.zip / tops20 / tops20.c < prev   
C/C++ Source or Header  |  1994-06-21  |  6KB  |  266 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. #if 0
  133.     char buf[40];
  134. #endif
  135.  
  136.     printf(LoadFarString(CompiledWith),
  137.  
  138. #ifdef __GNUC__
  139.       "gcc ", __VERSION__,
  140. #else
  141. #  if 0
  142.       "cc ", (sprintf(buf, " version %d", _RELEASE), buf),
  143. #  else
  144. #  ifdef __COMPILER_KCC__
  145.       "KCC", "",
  146. #  else
  147.       "unknown compiler", "",
  148. #  endif
  149. #  endif
  150. #endif
  151.  
  152.       "TOPS-20",
  153.  
  154. #if defined(foobar) || defined(FOOBAR)
  155.       " (Foo BAR)",   /* OS version or hardware */
  156. #else
  157.       "",
  158. #endif /* Foo BAR */
  159.  
  160. #ifdef __DATE__
  161.       " on ", __DATE__
  162. #else
  163.       "", ""
  164. #endif
  165.       );
  166.  
  167. } /* end function version() */
  168.  
  169. #endif /* !SFX */
  170.  
  171.  
  172.  
  173.  
  174.  
  175. /**********************/
  176. /*  Function upper()  */
  177. /**********************/
  178.  
  179. int upper(s)        /* returns s in uppercase */
  180.     char *s;        /* string to be uppercased */
  181. {
  182.     for (;  *s;  ++s)
  183.         *s = toupper(*s);
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190. /************************/
  191. /*  Function enquote()  */
  192. /************************/
  193.  
  194. int enquote(s)      /* calls dequote(s) to normalize string, then */
  195.     char *s;        /*  inserts ^Vs before otherwise illegal characters */
  196. {                   /*  in s, assuming that s is a TOPS-20 filename */
  197.     char d[100];
  198.     char *p, *q;
  199.     char c;
  200.  
  201.     if (s && *s) {
  202.         dequote(s);
  203.         p = s - 1;
  204.         q = d - 1;
  205.         while (c = *++p) {
  206.             if (!fnlegal(c))
  207.                 *++q = '\026';
  208.             *++q = c;
  209.         }
  210.         *++q = '\0';
  211.         strcpy(s, d);
  212.     }
  213.     return 0;
  214. }
  215.  
  216.  
  217.  
  218.  
  219.  
  220. /************************/
  221. /*  Function dequote()  */
  222. /************************/
  223.  
  224. int dequote(s)        /* returns s without ^Vs */
  225.     char *s;          /* string to be dequoted */
  226. {
  227.     char d[100];
  228.     char *p, *q;
  229.     int c;
  230.  
  231.     if (s && *s) {
  232.         p = s - 1;
  233.         q = d - 1;
  234.         while (c = *++p)
  235.             if (c != '\026')
  236.                 *++q = c;
  237.         *++q = '\0';
  238.         strcpy(s, d);
  239.     }
  240.     return 0;
  241. }
  242.  
  243.  
  244.  
  245.  
  246.  
  247. /************************/
  248. /*  Function fnlegal()  */
  249. /************************/
  250.  
  251. int fnlegal(c)         /* returns TRUE if c is a member of the */
  252.     char c;            /*  legal character set for filenames */
  253. {
  254.     char *q;
  255.     static char *legals = {"$%**-<>>AZ[[]]__az"};
  256.  
  257.     q = legals;
  258.     while (*q)
  259.         if (c < *q++)
  260.             break;
  261.         else if (c <= *q++)
  262.             return TRUE;
  263.  
  264.     return FALSE;
  265. }
  266.