home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip531.zip / tops20 / tops20.c < prev   
C/C++ Source or Header  |  1997-01-24  |  7KB  |  305 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. #define UNZIP_INTERNAL
  21. #include "unzip.h"
  22.  
  23.  
  24. /**********************/
  25. /* Function mapattr() */
  26. /**********************/
  27.  
  28. int mapattr(__G)        /* just like Unix except no umask() */
  29.     __GDEF
  30. {
  31.     ulg  tmp = G.crec.external_file_attributes;
  32.  
  33.     switch (G.pInfo->hostnum) {
  34.         case UNIX_:
  35.         case VMS_:
  36.             G.pInfo->file_attr = (unsigned)(tmp >> 16);
  37.             break;
  38.         case AMIGA_:
  39.             tmp = (unsigned)(tmp>>1 & 7);   /* Amiga RWE bits */
  40.             G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
  41.             break;
  42.         case FS_FAT_:   /* MSDOS half of attributes should always be correct */
  43.         case FS_HPFS_:
  44.         case FS_NTFS_:
  45.         case MAC_:
  46.         case ATARI_:
  47.         case TOPS20_:
  48.         default:
  49.             tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
  50.             G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
  51.             break;
  52. #if 0
  53.         case ATARI_:
  54.         case TOPS20_:
  55.         default:
  56.             G.pInfo->file_attr = 0666;
  57.             break;
  58. #endif
  59.     } /* end switch (host-OS-created-by) */
  60.  
  61.     return 0;
  62.  
  63. } /* end function mapattr() */
  64.  
  65.  
  66.  
  67.  
  68.  
  69. /****************************/
  70. /* Function close_outfile() */
  71. /****************************/
  72.  
  73. void close_outfile(__G)
  74.     __GDEF
  75. {
  76. #   define JSYS_CLASS           0070000000000
  77. #   define FLD(val,mask)        (((unsigned)(val)*((mask)&(-(mask))))&(mask))
  78. #   define _DEFJS(name,class)   (FLD(class,JSYS_CLASS) | (monsym(name)&0777777))
  79. #   define IDTIM                _DEFJS("IDTIM%", 1)
  80. #   define SFTAD                _DEFJS("SFTAD%", 0)
  81. #   define YRBASE               1900
  82.     int ablock[5], tblock[2];
  83.     int yr, mo, dy, hh, mm, ss;
  84.     char temp[100];
  85.     unsigned tad;
  86. #ifdef USE_EF_UT_TIME
  87.     iztimes z_utime;
  88.  
  89.  
  90.     if (G.extra_field &&
  91.         (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,
  92.                           &z_utime, NULL) & EB_UT_FL_MTIME))
  93.     {
  94.         struct tm *t = localtime(&(z_utime.mtime));
  95.  
  96.         yr = t->tm_year + 1900;
  97.         mo = t->tm_mon;
  98.         dy = t->tm_mday;
  99.         hh = t->tm_hour;
  100.         mm = t->tm_min;
  101.         ss = t->tm_sec;
  102.     }
  103.     else
  104.     {
  105.         /* dissect the date */
  106.         yr = ((G.lrec.last_mod_file_date >> 9) & 0x7f) + 1980;
  107.         mo = ((G.lrec.last_mod_file_date >> 5) & 0x0f) - 1;
  108.         dy = (G.lrec.last_mod_file_date & 0x1f);
  109.  
  110.         /* dissect the time */
  111.         hh = (G.lrec.last_mod_file_time >> 11) & 0x1f;
  112.         mm = (G.lrec.last_mod_file_time >> 5) & 0x3f;
  113.         ss = (G.lrec.last_mod_file_time & 0x1f) * 2;
  114.     }
  115. #else /* !USE_EF_UT_TIME */
  116.  
  117.     /* dissect the date */
  118.     yr = ((G.lrec.last_mod_file_date >> 9) & 0x7f) + (1980 - YRBASE);
  119.     mo = (G.lrec.last_mod_file_date >> 5) & 0x0f;
  120.     dy = G.lrec.last_mod_file_date & 0x1f;
  121.  
  122.     /* dissect the time */
  123.     hh = (G.lrec.last_mod_file_time >> 11) & 0x1f;
  124.     mm = (G.lrec.last_mod_file_time >> 5) & 0x3f;
  125.     ss = (G.lrec.last_mod_file_time & 0x1f) * 2;
  126. #endif /* ?USE_EF_UT_TIME */
  127.  
  128.     sprintf(temp, "%02d/%02d/%02d %02d:%02d:%02d", mo, dy, yr, hh, mm, ss);
  129.  
  130.     ablock[1] = (int)(temp - 1);
  131.     ablock[2] = 0;
  132.     if (!jsys(IDTIM, ablock)) {
  133.         Info(slide, 1, ((char *)slide, "error:  IDTIM failure for %s\n",
  134.           G.filename));
  135.         fclose(G.outfile);
  136.         return;
  137.     }
  138.  
  139.     tad = ablock[2];
  140.     tblock[0] = tad;
  141.     tblock[1] = tad;
  142.     tblock[2] = -1;
  143.  
  144.     ablock[1] = fcntl(fileno(G.outfile), F_GETSYSFD, 0);
  145.                                                 /* _uffd[outfd]->uf_ch */
  146.     ablock[2] = (int) tblock;
  147.     ablock[3] = 3;
  148.     if (!jsys(SFTAD, ablock))
  149.         Info(slide, 1,((char *)slide, "error:  can't set the time for %s\n",
  150.           G.filename));
  151.  
  152.     fclose(G.outfile);
  153.  
  154. } /* end function close_outfile() */
  155.  
  156.  
  157.  
  158.  
  159.  
  160. #ifndef SFX
  161.  
  162. /************************/
  163. /*  Function version()  */
  164. /************************/
  165.  
  166. void version(__G)
  167.     __GDEF
  168. {
  169. #if 0
  170.     char buf[40];
  171. #endif
  172.  
  173.     sprintf((char *)slide, LoadFarString(CompiledWith),
  174.  
  175. #ifdef __GNUC__
  176.       "gcc ", __VERSION__,
  177. #else
  178. #  if 0
  179.       "cc ", (sprintf(buf, " version %d", _RELEASE), buf),
  180. #  else
  181. #  ifdef __COMPILER_KCC__
  182.       "KCC", "",
  183. #  else
  184.       "unknown compiler", "",
  185. #  endif
  186. #  endif
  187. #endif
  188.  
  189.       "TOPS-20",
  190.  
  191. #if defined(foobar) || defined(FOOBAR)
  192.       " (Foo BAR)",   /* OS version or hardware */
  193. #else
  194.       "",
  195. #endif /* Foo BAR */
  196.  
  197. #ifdef __DATE__
  198.       " on ", __DATE__
  199. #else
  200.       "", ""
  201. #endif
  202.     );
  203.  
  204.     (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
  205.  
  206. } /* end function version() */
  207.  
  208. #endif /* !SFX */
  209.  
  210.  
  211.  
  212.  
  213.  
  214. /**********************/
  215. /*  Function upper()  */
  216. /**********************/
  217.  
  218. int upper(s)        /* returns s in uppercase */
  219.     char *s;        /* string to be uppercased */
  220. {
  221.     for (;  *s;  ++s)
  222.         *s = toupper(*s);
  223. }
  224.  
  225.  
  226.  
  227.  
  228.  
  229. /************************/
  230. /*  Function enquote()  */
  231. /************************/
  232.  
  233. int enquote(s)      /* calls dequote(s) to normalize string, then */
  234.     char *s;        /*  inserts ^Vs before otherwise illegal characters */
  235. {                   /*  in s, assuming that s is a TOPS-20 filename */
  236.     char d[100];
  237.     char *p, *q;
  238.     char c;
  239.  
  240.     if (s && *s) {
  241.         dequote(s);
  242.         p = s - 1;
  243.         q = d - 1;
  244.         while (c = *++p) {
  245.             if (!fnlegal(c))
  246.                 *++q = '\026';
  247.             *++q = c;
  248.         }
  249.         *++q = '\0';
  250.         strcpy(s, d);
  251.     }
  252.     return 0;
  253. }
  254.  
  255.  
  256.  
  257.  
  258.  
  259. /************************/
  260. /*  Function dequote()  */
  261. /************************/
  262.  
  263. int dequote(s)        /* returns s without ^Vs */
  264.     char *s;          /* string to be dequoted */
  265. {
  266.     char d[100];
  267.     char *p, *q;
  268.     int c;
  269.  
  270.     if (s && *s) {
  271.         p = s - 1;
  272.         q = d - 1;
  273.         while (c = *++p)
  274.             if (c != '\026')
  275.                 *++q = c;
  276.         *++q = '\0';
  277.         strcpy(s, d);
  278.     }
  279.     return 0;
  280. }
  281.  
  282.  
  283.  
  284.  
  285.  
  286. /************************/
  287. /*  Function fnlegal()  */
  288. /************************/
  289.  
  290. int fnlegal(c)         /* returns TRUE if c is a member of the */
  291.     char c;            /*  legal character set for filenames */
  292. {
  293.     char *q;
  294.     static char *legals = {"$%**-<>>AZ[[]]__az"};
  295.  
  296.     q = legals;
  297.     while (*q)
  298.         if (c < *q++)
  299.             break;
  300.         else if (c <= *q++)
  301.             return TRUE;
  302.  
  303.     return FALSE;
  304. }
  305.