cmsmvs.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. /*
  2. Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
  3. See the accompanying file LICENSE, version 1999-Oct-05 or later
  4. (the contents of which are also included in zip.h) for terms of use.
  5. If, for some reason, both of these files are missing, the Info-ZIP license
  6. also may be found at: ftp://ftp.cdrom.com/pub/infozip/license.html
  7. */
  8. /*
  9. * routines common to VM/CMS and MVS
  10. */
  11. #include "zip.h"
  12. #include <stdio.h>
  13. #include <time.h>
  14. #include <errno.h>
  15. #ifndef MVS /* MVS has perfectly good definitions of the following */
  16. int stat(const char *path, struct stat *buf)
  17. {
  18. if ((buf->fp = fopen(path, "r")) != NULL) {
  19. fldata_t fdata;
  20. if (fldata( buf->fp, buf->fname, &fdata ) == 0) {
  21. buf->st_dev = fdata.__device;
  22. buf->st_mode = *(short *)(&fdata);
  23. }
  24. strcpy( buf->fname, path );
  25. fclose(buf->fp);
  26. }
  27. return (buf->fp != NULL ? 0 : 1);
  28. }
  29. #endif /* MVS */
  30. #ifndef UTIL /* the companion #endif is a bit of ways down ... */
  31. #define PAD 0
  32. #define PATH_END '/'
  33. /* Library functions not in (most) header files */
  34. #ifdef USE_ZIPMAIN
  35. int main OF((void));
  36. #endif
  37. int utime OF((char *, ztimbuf *));
  38. extern char *label;
  39. local ulg label_time = 0;
  40. local ulg label_mode = 0;
  41. local time_t label_utim = 0;
  42. #ifndef MVS /* MVS has perfectly good definitions of the following */
  43. int fstat(int fd, struct stat *buf)
  44. {
  45. fldata_t fdata;
  46. if ((fd != -1) && (fldata( (FILE *)fd, buf->fname, &fdata ) == 0)) {
  47. buf->st_dev = fdata.__device;
  48. buf->st_mode = *(short *)(&fdata);
  49. buf->fp = (FILE *)fd;
  50. return 0;
  51. }
  52. return -1;
  53. }
  54. #endif /* MVS */
  55. char *ex2in(x, isdir, pdosflag)
  56. char *x; /* external file name */
  57. int isdir; /* input: x is a directory */
  58. int *pdosflag; /* output: force MSDOS file attributes? */
  59. /* Convert the external file name to a zip file name, returning the malloc'ed
  60. string or NULL if not enough memory. */
  61. {
  62. char *n; /* internal file name (malloc'ed) */
  63. char *t; /* shortened name */
  64. int dosflag;
  65. char mem[10] = ""; /* member name */
  66. char ext[10] = ""; /* extension name */
  67. dosflag = dosify; /* default for non-DOS non-OS/2 */
  68. /* Find starting point in name before doing malloc */
  69. for (t = x; *t == '/'; t++)
  70. ;
  71. /* Make changes, if any, to the copied name (leave original intact) */
  72. if (!pathput)
  73. t = last(t, PATH_END);
  74. /* Malloc space for internal name and copy it */
  75. if ((n = malloc(strlen(t) + 1)) == NULL)
  76. return NULL;
  77. strcpy(n, t);
  78. #ifdef MVS
  79. /* strip quotes from name, non-OE format */
  80. if (*n == '\'' && (t = strrchr(n, '\'')) != n) {
  81. if (!*(t+1)) {
  82. /* yes, it is a quoted name */
  83. int l = strlen(n) - 2;
  84. memmove(n, n+1, l);
  85. *(n+l) = '\0';
  86. }
  87. }
  88. /* Change member names to fn.ext */
  89. if (t = strrchr(n, '(')) {
  90. *t = '\0';
  91. strcpy(mem,t+1); /* Save member name */
  92. if (t = strchr(mem, ')')) *t = '\0'; /* Set end of mbr */
  93. /* Save extension */
  94. if (t = strrchr(n, '.')) t++;
  95. else t = n;
  96. strcpy(ext,t);
  97. /* Build name as "member.ext" */
  98. strcpy(t,mem);
  99. strcat(t,".");
  100. strcat(t,ext);
  101. }
  102. /* Change all but the last '.' to '/' */
  103. if (t = strrchr(n, '.')) {
  104. while (--t > n)
  105. if (*t == '.')
  106. *t = '/';
  107. }
  108. #else
  109. /* On CMS, remove the filemode (all past 2nd '.') */
  110. if (t = strchr(n, '.'))
  111. if (t = strchr(t+1, '.'))
  112. *t = '\0';
  113. t = n;
  114. #endif
  115. strcpy(n, t);
  116. if (isdir == 42) return n; /* avoid warning on unused variable */
  117. if (dosify)
  118. msname(n); /* msname() needs string in native charset */
  119. strtoasc(n, n);
  120. /* Returned malloc'ed name */
  121. if (pdosflag)
  122. *pdosflag = dosflag;
  123. return n;
  124. }
  125. char *in2ex(n)
  126. char *n; /* internal file name */
  127. /* Convert the zip file name to an external file name, returning the malloc'ed
  128. string or NULL if not enough memory. */
  129. {
  130. char *x; /* external file name */
  131. if ((x = malloc(strlen(n) + 1 + PAD)) == NULL)
  132. return NULL;
  133. strtoebc(x, n);
  134. return x;
  135. }
  136. void stamp(f, d)
  137. char *f; /* name of file to change */
  138. ulg d; /* dos-style time to change it to */
  139. /* Set last updated and accessed time of file f to the DOS time d. */
  140. {
  141. ztimbuf u; /* argument for utime() */
  142. /* Convert DOS time to time_t format in u.actime and u.modtime */
  143. u.actime = u.modtime = dos2unixtime(d);
  144. utime(f, &u);
  145. }
  146. ulg filetime(f, a, n, t)
  147. char *f; /* name of file to get info on */
  148. ulg *a; /* return value: file attributes */
  149. long *n; /* return value: file size */
  150. iztimes *t; /* return value: access, modific. and creation times */
  151. {
  152. FILE *stream;
  153. time_t ltime;
  154. if (strcmp(f, "-") != 0) { /* if not compressing stdin */
  155. Trace((mesg, "opening file '%s' with '%s'\n", f, FOPR));
  156. if ((stream = fopen(f, FOPR)) == (FILE *)NULL) {
  157. return 0;
  158. } else {
  159. if (n != NULL) {
  160. /* With byteseek, this will work */
  161. fseek(stream, 0L, SEEK_END);
  162. *n = ftell(stream);
  163. Trace((mesg, "file size = %lu\n", *((ulg *)n)));
  164. }
  165. fclose(stream);
  166. }
  167. }
  168. else {
  169. /* Reading from stdin */
  170. if (n != NULL) {
  171. *n = -1L;
  172. }
  173. }
  174. /* Return current time for all the times -- for now */
  175. time(&ltime);
  176. if (t != NULL)
  177. t->atime = t->mtime = t->ctime = ltime;
  178. /* Set attributes (always a file) */
  179. if (a != NULL)
  180. *a = 0;
  181. return unix2dostime(&ltime);
  182. }
  183. int set_extra_field(z, z_utim)
  184. struct zlist far *z;
  185. iztimes *z_utim;
  186. /* create extra field and change z->att if desired */
  187. {
  188. fldata_t fdata;
  189. FILE *stream;
  190. char *eb_ptr;
  191. #ifdef USE_EF_UT_TIME
  192. extent ef_l_len = (EB_HEADSIZE+EB_UT_LEN(1));
  193. #else /* !USE_EF_UT_TIME */
  194. extent ef_l_len = 0;
  195. #endif /* ?USE_EF_UT_TIME */
  196. int set_cmsmvs_eb = 0;
  197. /*translate_eol = 0;*/
  198. if (aflag == ASCII) {
  199. z->att = ASCII;
  200. } else {
  201. if (bflag)
  202. z->att = BINARY;
  203. else
  204. z->att = __EBCDIC;
  205. ef_l_len += sizeof(fdata)+EB_HEADSIZE;
  206. set_cmsmvs_eb = 1;
  207. }
  208. if (ef_l_len > 0) {
  209. z->extra = (char *)malloc(ef_l_len);
  210. if (z->extra == NULL) {
  211. printf("\nFLDATA : Unable to allocate memory !\n");
  212. return ZE_MEM;
  213. }
  214. z->cext = z->ext = ef_l_len;
  215. eb_ptr = z->cextra = z->extra;
  216. if (set_cmsmvs_eb) {
  217. if (bflag)
  218. /*** stream = fopen(z->zname,"rb,type=record"); $RGH$ ***/
  219. stream = fopen(z->name,"rb");
  220. else
  221. stream = fopen(z->name,"r");
  222. if (stream == NULL) {
  223. printf("\nFLDATA : Could not open file : %s !\n",z->name);
  224. printf("Error %d: '%s'\n", errno, strerror(errno));
  225. return ZE_NONE;
  226. }
  227. fldata(stream,z->name,&fdata);
  228. /*put the system ID */
  229. #ifdef VM_CMS
  230. *(eb_ptr) = EF_VMCMS & 0xFF;
  231. *(eb_ptr+1) = EF_VMCMS >> 8;
  232. #else
  233. *(eb_ptr) = EF_MVS & 0xFF;
  234. *(eb_ptr+1) = EF_MVS >> 8;
  235. #endif
  236. *(eb_ptr+2) = sizeof(fdata) & 0xFF;
  237. *(eb_ptr+3) = sizeof(fdata) >> 8;
  238. memcpy(eb_ptr+EB_HEADSIZE,&fdata,sizeof(fdata));
  239. fclose(stream);
  240. #ifdef USE_EF_UT_TIME
  241. eb_ptr += (sizeof(fdata)+EB_HEADSIZE);
  242. #endif /* USE_EF_UT_TIME */
  243. }
  244. #ifdef USE_EF_UT_TIME
  245. eb_ptr[0] = 0x55; /* ascii[(unsigned)('U')] */
  246. eb_ptr[1] = 0x54; /* ascii[(unsigned)('T')] */
  247. eb_ptr[2] = EB_UT_LEN(1); /* length of data part of e.f. */
  248. eb_ptr[3] = 0;
  249. eb_ptr[4] = EB_UT_FL_MTIME;
  250. eb_ptr[5] = (char)(z_utim->mtime);
  251. eb_ptr[6] = (char)(z_utim->mtime >> 8);
  252. eb_ptr[7] = (char)(z_utim->mtime >> 16);
  253. eb_ptr[8] = (char)(z_utim->mtime >> 24);
  254. #endif /* USE_EF_UT_TIME */
  255. }
  256. return ZE_OK;
  257. }
  258. int deletedir(d)
  259. char *d; /* directory to delete */
  260. /* Delete the directory *d if it is empty, do nothing otherwise.
  261. Return the result of rmdir(), delete(), or system().
  262. For VMS, d must be in format [x.y]z.dir;1 (not [x.y.z]).
  263. */
  264. {
  265. return 0;
  266. }
  267. #ifdef USE_ZIPMAIN
  268. /* This function is called as main() to parse arguments */
  269. /* into argc and argv. This is required for stand-alone */
  270. /* execution. This calls the "real" main() when done. */
  271. int main(void)
  272. {
  273. int argc=0;
  274. char *argv[50];
  275. int iArgLen;
  276. char argstr[256];
  277. char **pEPLIST, *pCmdStart, *pArgStart, *pArgEnd;
  278. /* Get address of extended parameter list from S/370 Register 0 */
  279. pEPLIST = (char **)__xregs(0);
  280. /* Null-terminate the argument string */
  281. pCmdStart = *(pEPLIST+0);
  282. pArgStart = *(pEPLIST+1);
  283. pArgEnd = *(pEPLIST+2);
  284. iArgLen = pArgEnd - pCmdStart + 1;
  285. /* Make a copy of the command string */
  286. memcpy(argstr, pCmdStart, iArgLen);
  287. argstr[iArgLen] = '\0'; /* Null-terminate */
  288. /* Store first token (cmd) */
  289. argv[argc++] = strtok(argstr, " ");
  290. /* Store the rest (args) */
  291. while (argv[argc-1])
  292. argv[argc++] = strtok(NULL, " ");
  293. argc--; /* Back off last NULL entry */
  294. /* Call "real" main() function */
  295. return zipmain(argc, argv);
  296. }
  297. #endif /* USE_ZIPMAIN */
  298. #endif /* !UTIL */
  299. /******************************/
  300. /* Function version_local() */
  301. /******************************/
  302. void version_local()
  303. {
  304. char liblvlmsg [50+1];
  305. char *compiler = "?";
  306. char *platform = "?";
  307. char complevel[64];
  308. /* Map the runtime library level information */
  309. union {
  310. unsigned int iVRM;
  311. struct {
  312. unsigned int pd:4; /* Product designation */
  313. unsigned int vv:4; /* Version */
  314. unsigned int rr:8; /* Release */
  315. unsigned int mm:16; /* Modification level */
  316. } xVRM;
  317. } VRM;
  318. /* Break down the runtime library level */
  319. VRM.iVRM = __librel();
  320. sprintf(liblvlmsg, "Using runtime library level %s V%dR%dM%d",
  321. (VRM.xVRM.pd==1 ? "LE" : "CE"),
  322. VRM.xVRM.vv, VRM.xVRM.rr, VRM.xVRM.mm);
  323. /* Note: LE = Language Environment, CE = Common Env. (C/370). */
  324. /* This refers ONLY to the current runtimes, not the compiler. */
  325. #ifdef VM_CMS
  326. platform = "VM/CMS";
  327. #ifdef __IBMC__
  328. compiler = "IBM C";
  329. #else
  330. compiler = "C/370";
  331. #endif
  332. #endif
  333. #ifdef MVS
  334. platform = "MVS";
  335. #ifdef __IBMC__
  336. compiler = "IBM C/C++";
  337. #else
  338. compiler = "C/370";
  339. #endif
  340. #endif
  341. #ifdef __COMPILER_VER__
  342. VRM.iVRM = __COMPILER_VER__;
  343. sprintf(complevel," V%dR%dM%d",
  344. VRM.xVRM.vv, VRM.xVRM.rr, VRM.xVRM.mm);
  345. #else
  346. #ifdef __IBMC__
  347. sprintf(complevel," V%dR%d", __IBMC__ / 100, (__IBMC__ % 100)/10);
  348. #else
  349. complevel[0] = '\0';
  350. #endif
  351. #endif
  352. printf("Compiled with %s%s for %s%s%s.\n\n",
  353. /* Add compiler name and level */
  354. compiler, complevel,
  355. /* Add platform */
  356. platform,
  357. /* Add timestamp */
  358. #ifdef __DATE__
  359. " on " __DATE__
  360. #ifdef __TIME__
  361. " at " __TIME__
  362. #endif
  363. #endif
  364. ".\n",
  365. liblvlmsg
  366. );
  367. } /* end function version_local() */