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