home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip532.zip / tops20 / tops20.c < prev   
C/C++ Source or Header  |  1997-09-28  |  7KB  |  309 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.  
  92.  
  93.     if (G.extra_field &&
  94.         (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,
  95.                           G.lrec.last_mod_file_date, &z_utime, NULL)
  96.          & EB_UT_FL_MTIME))
  97.     {
  98.         struct tm *t = localtime(&(z_utime.mtime));
  99.  
  100.         yr = t->tm_year + 1900;
  101.         mo = t->tm_mon;
  102.         dy = t->tm_mday;
  103.         hh = t->tm_hour;
  104.         mm = t->tm_min;
  105.         ss = t->tm_sec;
  106.     }
  107.     else
  108.     {
  109.         /* dissect the date */
  110.         yr = ((G.lrec.last_mod_file_date >> 9) & 0x7f) + 1980;
  111.         mo = ((G.lrec.last_mod_file_date >> 5) & 0x0f) - 1;
  112.         dy = (G.lrec.last_mod_file_date & 0x1f);
  113.  
  114.         /* dissect the time */
  115.         hh = (G.lrec.last_mod_file_time >> 11) & 0x1f;
  116.         mm = (G.lrec.last_mod_file_time >> 5) & 0x3f;
  117.         ss = (G.lrec.last_mod_file_time & 0x1f) * 2;
  118.     }
  119. #else /* !USE_EF_UT_TIME */
  120.  
  121.     /* dissect the date */
  122.     yr = ((G.lrec.last_mod_file_date >> 9) & 0x7f) + (1980 - YRBASE);
  123.     mo = (G.lrec.last_mod_file_date >> 5) & 0x0f;
  124.     dy = G.lrec.last_mod_file_date & 0x1f;
  125.  
  126.     /* dissect the time */
  127.     hh = (G.lrec.last_mod_file_time >> 11) & 0x1f;
  128.     mm = (G.lrec.last_mod_file_time >> 5) & 0x3f;
  129.     ss = (G.lrec.last_mod_file_time & 0x1f) * 2;
  130. #endif /* ?USE_EF_UT_TIME */
  131.  
  132.     sprintf(temp, "%02d/%02d/%02d %02d:%02d:%02d", mo, dy, yr, hh, mm, ss);
  133.  
  134.     ablock[1] = (int)(temp - 1);
  135.     ablock[2] = 0;
  136.     if (!jsys(IDTIM, ablock)) {
  137.         Info(slide, 1, ((char *)slide, "error:  IDTIM failure for %s\n",
  138.           G.filename));
  139.         fclose(G.outfile);
  140.         return;
  141.     }
  142.  
  143.     tad = ablock[2];
  144.     tblock[0] = tad;
  145.     tblock[1] = tad;
  146.     tblock[2] = -1;
  147.  
  148.     ablock[1] = fcntl(fileno(G.outfile), F_GETSYSFD, 0);
  149.                                                 /* _uffd[outfd]->uf_ch */
  150.     ablock[2] = (int) tblock;
  151.     ablock[3] = 3;
  152.     if (!jsys(SFTAD, ablock))
  153.         Info(slide, 1,((char *)slide, "error:  cannot set the time for %s\n",
  154.           G.filename));
  155.  
  156.     fclose(G.outfile);
  157.  
  158. } /* end function close_outfile() */
  159.  
  160.  
  161.  
  162.  
  163.  
  164. #ifndef SFX
  165.  
  166. /************************/
  167. /*  Function version()  */
  168. /************************/
  169.  
  170. void version(__G)
  171.     __GDEF
  172. {
  173. #if 0
  174.     char buf[40];
  175. #endif
  176.  
  177.     sprintf((char *)slide, LoadFarString(CompiledWith),
  178.  
  179. #ifdef __GNUC__
  180.       "gcc ", __VERSION__,
  181. #else
  182. #  if 0
  183.       "cc ", (sprintf(buf, " version %d", _RELEASE), buf),
  184. #  else
  185. #  ifdef __COMPILER_KCC__
  186.       "KCC", "",
  187. #  else
  188.       "unknown compiler", "",
  189. #  endif
  190. #  endif
  191. #endif
  192.  
  193.       "TOPS-20",
  194.  
  195. #if defined(foobar) || defined(FOOBAR)
  196.       " (Foo BAR)",   /* OS version or hardware */
  197. #else
  198.       "",
  199. #endif /* Foo BAR */
  200.  
  201. #ifdef __DATE__
  202.       " on ", __DATE__
  203. #else
  204.       "", ""
  205. #endif
  206.     );
  207.  
  208.     (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
  209.  
  210. } /* end function version() */
  211.  
  212. #endif /* !SFX */
  213.  
  214.  
  215.  
  216.  
  217.  
  218. /**********************/
  219. /*  Function upper()  */
  220. /**********************/
  221.  
  222. int upper(s)        /* returns s in uppercase */
  223.     char *s;        /* string to be uppercased */
  224. {
  225.     for (;  *s;  ++s)
  226.         *s = toupper(*s);
  227. }
  228.  
  229.  
  230.  
  231.  
  232.  
  233. /************************/
  234. /*  Function enquote()  */
  235. /************************/
  236.  
  237. int enquote(s)      /* calls dequote(s) to normalize string, then */
  238.     char *s;        /*  inserts ^Vs before otherwise illegal characters */
  239. {                   /*  in s, assuming that s is a TOPS-20 filename */
  240.     char d[100];
  241.     char *p, *q;
  242.     char c;
  243.  
  244.     if (s && *s) {
  245.         dequote(s);
  246.         p = s - 1;
  247.         q = d - 1;
  248.         while (c = *++p) {
  249.             if (!fnlegal(c))
  250.                 *++q = '\026';
  251.             *++q = c;
  252.         }
  253.         *++q = '\0';
  254.         strcpy(s, d);
  255.     }
  256.     return 0;
  257. }
  258.  
  259.  
  260.  
  261.  
  262.  
  263. /************************/
  264. /*  Function dequote()  */
  265. /************************/
  266.  
  267. int dequote(s)        /* returns s without ^Vs */
  268.     char *s;          /* string to be dequoted */
  269. {
  270.     char d[100];
  271.     char *p, *q;
  272.     int c;
  273.  
  274.     if (s && *s) {
  275.         p = s - 1;
  276.         q = d - 1;
  277.         while (c = *++p)
  278.             if (c != '\026')
  279.                 *++q = c;
  280.         *++q = '\0';
  281.         strcpy(s, d);
  282.     }
  283.     return 0;
  284. }
  285.  
  286.  
  287.  
  288.  
  289.  
  290. /************************/
  291. /*  Function fnlegal()  */
  292. /************************/
  293.  
  294. int fnlegal(c)         /* returns TRUE if c is a member of the */
  295.     char c;            /*  legal character set for filenames */
  296. {
  297.     char *q;
  298.     static char *legals = {"$%**-<>>AZ[[]]__az"};
  299.  
  300.     q = legals;
  301.     while (*q)
  302.         if (c < *q++)
  303.             break;
  304.         else if (c <= *q++)
  305.             return TRUE;
  306.  
  307.     return FALSE;
  308. }
  309.