Netware.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ntypes.h>
  5. #include <nwconio.h>
  6. #include <ctype.h>
  7. #include <unistd.h>
  8. #include <nit\nwdir.h>
  9. #include <dirent.h>
  10. #include <nwnamspc.h>
  11. #include <locale.h>
  12. #include <nwlocale.h>
  13. #include <time.h>
  14. extern void UseAccurateCaseForPaths(int);
  15. #include "zip.h"
  16. /*------------------------------------------------------------------
  17. ** Global Variables
  18. */
  19. #define skipspace( x ) while( isspace( *x ) ) ++x
  20. #define nextspace( x ) while( *x && !isspace( *x ) ) ++x
  21. #define CWS 0
  22. #define CWV 1
  23. #define CWP 2
  24. #define ALL 99
  25. /* Globals */
  26. extern char *GetWorkArea(void);
  27. extern char *next_arg(char *);
  28. extern int NLM_exiting;
  29. char fid[100];
  30. static breakkey = FALSE;
  31. #define MATCH shmatch
  32. extern char *label;
  33. local ulg label_time = 0;
  34. local ulg label_mode = 0;
  35. local time_t label_utim = 0;
  36. #define PAD 0
  37. #define PATH_END '/'
  38. local char *readd(d)
  39. DIR *d; /* directory stream to read from */
  40. /* Return a pointer to the next name in the directory stream d, or NULL if
  41. no more entries or an error occurs. */
  42. {
  43. struct dirent *e;
  44. e = readdir(d);
  45. return e == NULL ? (char *) NULL : e->d_name;
  46. }
  47. void findzip(char *s)
  48. {
  49. dowhereis(s);
  50. }
  51. void dowhereis(char *s)
  52. {
  53. char dir[_MAX_PATH];
  54. char fsv[_MAX_SERVER+_MAX_VOLUME+1];
  55. char fdir[_MAX_PATH];
  56. char fname[_MAX_FNAME],fext[_MAX_EXT], both[_MAX_FNAME+_MAX_EXT];
  57. char *p = next_arg(s); /* point at argument */
  58. if(!*p)
  59. {
  60. printf("No filename specified!");
  61. return;
  62. }
  63. //setlocale (LC_ALL, "NORWAY");
  64. NWLsetlocale (LC_ALL, "NORWAY");
  65. strcpy(dir,GetWorkArea());
  66. /* get the file name specification */
  67. _splitpath(p,fsv,fdir,fname,fext);
  68. //printf ("p %s, fsv %s, fdir %s, fname %s, fext %s\n", p,fsv,fdir,fname,fext);
  69. //getch();
  70. sprintf(both,"%s%s",strupr(fname),strupr(fext));
  71. breakkey = FALSE;
  72. /* startup the recursive file find operation */
  73. chdir(fsv);
  74. UseAccurateCaseForPaths(1);
  75. SetCurrentNameSpace (NW_NS_LONG);
  76. chdir(fdir);
  77. findit(both);
  78. }
  79. char *GetWorkArea(void)
  80. {
  81. static char cwd[_MAX_PATH];
  82. static char serverName[_MAX_SERVER];
  83. static char volumeName[_MAX_VOLUME + 1];
  84. static char dirName[_MAX_DIR];
  85. if(getcwd(cwd,_MAX_PATH) == NULL)
  86. return NULL;
  87. ParsePath(cwd,serverName,volumeName,dirName); /* shouldn't fail! */
  88. return cwd;
  89. }
  90. char *next_arg(char *s)
  91. {
  92. char *p;
  93. skipspace(s); /* ignore white */
  94. p = s;
  95. nextspace(s); /* find next blank */
  96. *s = NULL;
  97. return(p);
  98. }
  99. static void findit(char *what)
  100. {
  101. char dir[_MAX_PATH];
  102. char zipdir[_MAX_PATH];
  103. char szzipfile[_MAX_PATH];
  104. char *psz;
  105. DIR *dirStructPtr;
  106. DIR *dirStructPtrSave;
  107. int r;
  108. getcwd(dir,_MAX_PATH);
  109. psz = dir;
  110. while (*psz)
  111. {
  112. if (*psz == ':')
  113. {
  114. strcpy (zipdir, psz + 1);
  115. break;
  116. }
  117. psz++;
  118. }
  119. dirStructPtrSave = dirStructPtr = opendir(what);
  120. /*
  121. _A_NORMAL Normal file; read/write permitted
  122. _A_RDONLY Read-only file
  123. _A_HIDDEN Hidden file
  124. _A_SYSTEM System file
  125. _A_VOLID Volume ID entry
  126. _A_SUBDIR Subdirectory
  127. _A_ARCH Archive file
  128. */
  129. if (hidden_files)
  130. SetReaddirAttribute (dirStructPtr, _A_NORMAL | _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_ARCH);
  131. else
  132. SetReaddirAttribute (dirStructPtr, _A_NORMAL | _A_ARCH);
  133. //while(dirStructPtr && !breakkey)
  134. while(dirStructPtr && !NLM_exiting)
  135. {
  136. //printf ("\n NLM_exiting test Line 167.... \n");
  137. dirStructPtr = readdir(dirStructPtr);
  138. if((dirStructPtr == NULL) || (dirStructPtr == -1))
  139. break;
  140. /* Filen er funnet */
  141. if(dirStructPtr->d_attr & _A_SUBDIR)
  142. continue;
  143. strcpy (szzipfile, zipdir);
  144. strcat (szzipfile, "/");
  145. strcat (szzipfile, dirStructPtr->d_name);
  146. procnamehho (szzipfile);
  147. //ThreadSwitchWithDelay();
  148. //if(kbhit() && getch() == 3)
  149. // printf("^C\n",breakkey = TRUE);
  150. }
  151. if(dirStructPtrSave)
  152. closedir(dirStructPtrSave);
  153. if (!recurse)
  154. return;
  155. /* Now traverse the directories in this path */
  156. dirStructPtrSave = dirStructPtr = opendir("*.*");
  157. if(dirStructPtr == NULL)
  158. return;
  159. if (hidden_files)
  160. SetReaddirAttribute (dirStructPtr, _A_NORMAL | _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_ARCH | _A_SUBDIR);
  161. else
  162. SetReaddirAttribute (dirStructPtr, _A_NORMAL | _A_ARCH | _A_SUBDIR);
  163. //ThreadSwitchWithDelay();
  164. while(!NLM_exiting)
  165. {
  166. //printf ("\n NLM_exiting test Line 204.... \n"); getch ();
  167. dirStructPtr = readdir(dirStructPtr);
  168. if((dirStructPtr == NULL) || (dirStructPtr == -1))
  169. break;
  170. if(dirStructPtr->d_attr & _A_SUBDIR)
  171. {
  172. strcpy (szzipfile, zipdir);
  173. strcat (szzipfile, "/");
  174. strcat (szzipfile, dirStructPtr->d_name);
  175. procnamehho (szzipfile);
  176. chdir(dirStructPtr->d_name);
  177. findit(what);
  178. chdir("..");
  179. }
  180. //if(kbhit() && getch() == 3)
  181. // printf("^C\n",breakkey = TRUE);
  182. }
  183. if(dirStructPtrSave)
  184. closedir(dirStructPtrSave);
  185. }
  186. int wild(w)
  187. char *w; /* path/pattern to match */
  188. /* If not in exclude mode, expand the pattern based on the contents of the
  189. file system. Return an error code in the ZE_ class. */
  190. {
  191. DIR *d; /* stream for reading directory */
  192. char *e; /* name found in directory */
  193. int r; /* temporary variable */
  194. char *n; /* constructed name from directory */
  195. int f; /* true if there was a match */
  196. char *a; /* alloc'ed space for name */
  197. //char *p; /* path */
  198. char *q; /* name */
  199. char v[5]; /* space for device current directory */
  200. char dir[_MAX_PATH];
  201. char fsv[_MAX_SERVER+_MAX_VOLUME+1];
  202. char fdir[_MAX_PATH];
  203. char fname[_MAX_FNAME],fext[_MAX_EXT], both[_MAX_FNAME+_MAX_EXT];
  204. char *p; /* point at argument */
  205. p = w;
  206. /* Test HHO */
  207. findzip(p);
  208. return ZE_OK;
  209. strcpy(dir,GetWorkArea());
  210. /* get the file name specification */
  211. _splitpath(p,fsv,fdir,fname,fext);
  212. sprintf(both,"%s%s",strupr(fname),strupr(fext));
  213. /* startup the recursive file find operation */
  214. chdir(fsv);
  215. /* Search that level for matching names */
  216. if ((d = opendir(both)) == NULL)
  217. {
  218. free((zvoid *)a);
  219. return ZE_MISS;
  220. }
  221. f = 0;
  222. while ((e = readd(d)) != NULL) {
  223. if (strcmp(e, ".") && strcmp(e, "..") && MATCH(q, e))
  224. {
  225. f = 1;
  226. if (strcmp(p, ".") == 0) { /* path is . */
  227. r = procname(e); /* name is name */
  228. if (r) {
  229. f = 0;
  230. break;
  231. }
  232. } else
  233. {
  234. if ((n = malloc(strlen(p) + strlen(e) + 2)) == NULL)
  235. {
  236. free((zvoid *)a);
  237. closedir(d);
  238. return ZE_MEM;
  239. }
  240. n = strcpy(n, p);
  241. if (n[r = strlen(n) - 1] != '/' && n[r] != ':')
  242. strcat(n, "/");
  243. r = procname(strcat(n, e)); /* name is path/name */
  244. free((zvoid *)n);
  245. if (r) {
  246. f = 0;
  247. break;
  248. }
  249. }
  250. }
  251. }
  252. closedir(d);
  253. /* Done */
  254. free((zvoid *)a);
  255. return f ? ZE_OK : ZE_MISS;
  256. }
  257. int procnamehho (char *n)
  258. {
  259. int m; /* matched flag */
  260. char *p; /* path for recursion */
  261. struct stat s; /* result of stat() */
  262. struct zlist far *z; /* steps through zfiles list */
  263. char *a;
  264. if (n == NULL) /* volume_label request in freshen|delete mode ?? */
  265. return ZE_OK;
  266. if (strcmp(n, "-") == 0) /* if compressing stdin */
  267. return newname(n, 0);
  268. else if (stat(n, &s)
  269. #if defined(__TURBOC__) || defined(__WATCOMC__)
  270. /* For these 2 compilers, stat() succeeds on wild card names! */
  271. || isshexp(n)
  272. #endif
  273. )
  274. {
  275. /* Not a file or directory--search for shell expression in zip file */
  276. p = ex2in(n, 0, (int *)NULL); /* shouldn't affect matching chars */
  277. m = 1;
  278. for (z = zfiles; z != NULL; z = z->nxt) {
  279. if (MATCH(p, z->iname))
  280. {
  281. z->mark = pcount ? filter(z->zname) : 1;
  282. if (verbose)
  283. fprintf(mesg, "zip diagnostic: %scluding %s\n",
  284. z->mark ? "in" : "ex", z->name);
  285. m = 0;
  286. }
  287. }
  288. free((zvoid *)p);
  289. return m ? ZE_MISS : ZE_OK;
  290. }
  291. /* Live name--use if file, recurse if directory */
  292. for (p = n; *p; p++) /* use / consistently */
  293. if (*p == '\\')
  294. *p = '/';
  295. //printf ("\nHHO %s\n", n);
  296. if ((s.st_mode & S_IFDIR) == 0)
  297. {
  298. //printf ("\nHHO1 %s\n", n);
  299. /* add or remove name of file */
  300. //printf ("\nAdding name %s to list.\n", n);
  301. if ((m = newname(n, 0)) != ZE_OK)
  302. return m;
  303. } else {
  304. /* Add trailing / to the directory name */
  305. if ((p = malloc(strlen(n)+2)) == NULL)
  306. return ZE_MEM;
  307. if (strcmp(n, ".") == 0 || strcmp(n, "/.") == 0) {
  308. *p = '\0'; /* avoid "./" prefix and do not create zip entry */
  309. } else {
  310. strcpy(p, n);
  311. a = p + strlen(p);
  312. if (a[-1] != '/')
  313. strcpy(a, "/");
  314. //if (dirnames && (m = newname(p, 1)) != ZE_OK) {
  315. if ((m = newname(p, 1)) != ZE_OK) {
  316. free((zvoid *)p);
  317. return m;
  318. }
  319. free ((zvoid *)p);
  320. }
  321. return ZE_OK;
  322. }
  323. return ZE_OK;
  324. }
  325. int procname(n)
  326. char *n; /* name to process */
  327. /* Process a name or sh expression to operate on (or exclude). Return
  328. an error code in the ZE_ class. */
  329. {
  330. char *a; /* path and name for recursion */
  331. DIR *d; /* directory stream from opendir() */
  332. char *e; /* pointer to name from readd() */
  333. int m; /* matched flag */
  334. char *p; /* path for recursion */
  335. struct stat s; /* result of stat() */
  336. struct zlist far *z; /* steps through zfiles list */
  337. if (n == NULL) /* volume_label request in freshen|delete mode ?? */
  338. return ZE_OK;
  339. if (strcmp(n, "-") == 0) /* if compressing stdin */
  340. return newname(n, 0);
  341. else if (stat(n, &s)
  342. #if defined(__TURBOC__) || defined(__WATCOMC__)
  343. /* For these 2 compilers, stat() succeeds on wild card names! */
  344. || isshexp(n)
  345. #endif
  346. )
  347. {
  348. /* Not a file or directory--search for shell expression in zip file */
  349. p = ex2in(n, 0, (int *)NULL); /* shouldn't affect matching chars */
  350. m = 1;
  351. for (z = zfiles; z != NULL; z = z->nxt) {
  352. if (MATCH(p, z->iname))
  353. {
  354. z->mark = pcount ? filter(z->zname) : 1;
  355. if (verbose)
  356. fprintf(mesg, "zip diagnostic: %scluding %s\n",
  357. z->mark ? "in" : "ex", z->name);
  358. m = 0;
  359. }
  360. }
  361. free((zvoid *)p);
  362. return m ? ZE_MISS : ZE_OK;
  363. }
  364. /* Live name--use if file, recurse if directory */
  365. for (p = n; *p; p++) /* use / consistently */
  366. if (*p == '\\')
  367. *p = '/';
  368. if ((s.st_mode & S_IFDIR) == 0)
  369. {
  370. /* add or remove name of file */
  371. if ((m = newname(n, 0)) != ZE_OK)
  372. return m;
  373. } else {
  374. /* Add trailing / to the directory name */
  375. if ((p = malloc(strlen(n)+2)) == NULL)
  376. return ZE_MEM;
  377. if (strcmp(n, ".") == 0 || strcmp(n, "/.") == 0) {
  378. *p = '\0'; /* avoid "./" prefix and do not create zip entry */
  379. } else {
  380. strcpy(p, n);
  381. a = p + strlen(p);
  382. if (a[-1] != '/')
  383. strcpy(a, "/");
  384. if (dirnames && (m = newname(p, 1)) != ZE_OK) {
  385. free((zvoid *)p);
  386. return m;
  387. }
  388. }
  389. /* recurse into directory */
  390. if (recurse && (d = opendir(n)) != NULL)
  391. {
  392. while ((e = readd(d)) != NULL) {
  393. if (strcmp(e, ".") && strcmp(e, ".."))
  394. {
  395. if ((a = malloc(strlen(p) + strlen(e) + 1)) == NULL)
  396. {
  397. closedir(d);
  398. free((zvoid *)p);
  399. return ZE_MEM;
  400. }
  401. strcat(strcpy(a, p), e);
  402. if ((m = procname(a)) != ZE_OK) /* recurse on name */
  403. {
  404. if (m == ZE_MISS)
  405. zipwarn("name not matched: ", a);
  406. else
  407. ziperr(m, a);
  408. }
  409. free((zvoid *)a);
  410. }
  411. }
  412. closedir(d);
  413. }
  414. free((zvoid *)p);
  415. } /* (s.st_mode & S_IFDIR) == 0) */
  416. return ZE_OK;
  417. }
  418. char *szRelativParameter;
  419. char szRelativ[512];
  420. int iRelativOK = FALSE;
  421. int iRelativPakking = FALSE;
  422. int fixRelativpath ()
  423. {
  424. char *szp;
  425. szp = szRelativParameter;
  426. if (szRelativParameter[0] == '/' || szRelativParameter[0] == '\\')
  427. szp++;
  428. while (*szp) {
  429. if (*szp == '\\')
  430. *szp = '/';
  431. szp++;
  432. }
  433. szp = szRelativParameter;
  434. if (szRelativParameter[0] == '/')
  435. szp++;
  436. strcpy (szRelativ, szp);
  437. if (strlen(szp) == 0) {
  438. szRelativ[0] = '\0';
  439. return FALSE;
  440. }
  441. return TRUE;
  442. }
  443. char *ex2in(x, isdir, pdosflag)
  444. char *x; /* external file name */
  445. int isdir; /* input: x is a directory */
  446. int *pdosflag; /* output: force MSDOS file attributes? */
  447. /* Convert the external file name to a zip file name, returning the malloc'ed
  448. string or NULL if not enough memory. */
  449. {
  450. char *n; /* internal file name (malloc'ed) */
  451. char *t; /* shortened name */
  452. int dosflag;
  453. char *sztUpper;
  454. /* Find starting point in name before doing malloc */
  455. t = *x && *(x + 1) == ':' ? x + 2 : x;
  456. while (*t == '/' || *t == '\\')
  457. t++;
  458. /* Make changes, if any, to the copied name (leave original intact) */
  459. for (n = t; *n; n++)
  460. if (*n == '\\')
  461. *n = '/';
  462. if (iRelativPakking) {
  463. //printf ("\n LINE 516 *ex2ex Internt navn %s external name %s.\n", t, x); getch ();
  464. if (!iRelativOK) {
  465. if (!fixRelativpath()) {
  466. iRelativOK = FALSE;
  467. iRelativPakking = FALSE;
  468. }
  469. else {
  470. sztUpper = malloc (strlen(t) + 10);
  471. strcpy (sztUpper, t);
  472. NWLstrupr (sztUpper);
  473. NWLstrupr (szRelativ);
  474. if (strncmp (sztUpper, szRelativ, strlen(szRelativ)) == 0) {
  475. t = t + strlen(szRelativ);
  476. iRelativPakking = TRUE;
  477. iRelativOK = TRUE;
  478. }
  479. else {
  480. iRelativOK = FALSE;
  481. iRelativPakking = FALSE;
  482. }
  483. free (sztUpper);
  484. }
  485. }
  486. else
  487. {
  488. t = t + strlen(szRelativ);
  489. }
  490. }
  491. if (!pathput)
  492. t = last(t, PATH_END);
  493. /* Malloc space for internal name and copy it */
  494. if ((n = malloc(strlen(t) + 1)) == NULL)
  495. return NULL;
  496. strcpy(n, t);
  497. if (dosify)
  498. msname(n);
  499. /* Returned malloc'ed name */
  500. if (pdosflag)
  501. *pdosflag = dosflag;
  502. return n;
  503. }
  504. char *in2ex(n)
  505. char *n; /* internal file name */
  506. /* Convert the zip file name to an external file name, returning the malloc'ed
  507. string or NULL if not enough memory. */
  508. {
  509. char *x; /* external file name */
  510. if ((x = malloc(strlen(n) + 1 + PAD)) == NULL)
  511. return NULL;
  512. strcpy(x, n);
  513. //if ( !IsFileNameValid(x) )
  514. //ChangeNameForFAT(x);
  515. //printf ("\n *in2ex Internt navn %s external name %s.\n", n, x); getch ();
  516. return x;
  517. }
  518. void stamp(f, d)
  519. char *f; /* name of file to change */
  520. ulg d; /* dos-style time to change it to */
  521. /* Set last updated and accessed time of file f to the DOS time d. */
  522. {
  523. //SetFileTime(f, d);
  524. }
  525. ulg filetime(f, a, n, t)
  526. char *f; /* name of file to get info on */
  527. ulg *a; /* return value: file attributes */
  528. long *n; /* return value: file size */
  529. iztimes *t; /* return value: access, modific. and creation times */
  530. /* If file *f does not exist, return 0. Else, return the file's last
  531. modified date and time as an MSDOS date and time. The date and
  532. time is returned in a long with the date most significant to allow
  533. unsigned integer comparison of absolute times. Also, if a is not
  534. a NULL pointer, store the file attributes there, with the high two
  535. bytes being the Unix attributes, and the low byte being a mapping
  536. of that to DOS attributes. If n is not NULL, store the file size
  537. there. If t is not NULL, the file's access, modification and creation
  538. times are stored there as UNIX time_t values.
  539. If f is "-", use standard input as the file. If f is a device, return
  540. a file size of -1 */
  541. {
  542. struct stat s; /* results of stat() */
  543. /* convert FNMAX to malloc - 11/8/04 EG */
  544. char *name;
  545. int len = strlen(f);
  546. if (f == label) {
  547. if (a != NULL)
  548. *a = label_mode;
  549. if (n != NULL)
  550. *n = -2L; /* convention for a label name */
  551. if (t != NULL)
  552. t->atime = t->mtime = t->ctime = label_utim;
  553. return label_time;
  554. }
  555. if ((name = malloc(len + 1)) == NULL) {
  556. ZIPERR(ZE_MEM, "filetime");
  557. }
  558. strcpy(name, f);
  559. if (name[len - 1] == '/')
  560. name[len - 1] = '\0';
  561. /* not all systems allow stat'ing a file with / appended */
  562. if (strcmp(f, "-") == 0) {
  563. if (fstat(fileno(stdin), &s) != 0)
  564. error("fstat(stdin)");
  565. }
  566. else if (stat(name, &s) != 0) {
  567. /* Accept about any file kind including directories
  568. * (stored with trailing / with -r option)
  569. */
  570. free(name);
  571. return 0;
  572. }
  573. free(name);
  574. if (a != NULL) {
  575. *a = s.st_attr; // << 16) | !(s.st_mode & S_IWRITE);
  576. //*a = ((ulg)s.st_mode << 16) | !(s.st_mode & S_IWRITE);
  577. //if ((s.st_mode & S_IFMT) == S_IFDIR) {
  578. //*a |= MSDOS_DIR_ATTR;
  579. //}
  580. }
  581. if (n != NULL)
  582. *n = (s.st_mode & S_IFMT) == S_IFREG ? s.st_size : -1L;
  583. if (t != NULL) {
  584. t->atime = s.st_atime;
  585. t->mtime = s.st_mtime;
  586. t->ctime = t->mtime; /* best guess, (s.st_ctime: last status change!!) */
  587. }
  588. return unix2dostime(&s.st_mtime);
  589. }
  590. ulg filetimeHHO(f, a, n, t)
  591. char *f; /* name of file to get info on */
  592. ulg *a; /* return value: file attributes */
  593. long *n; /* return value: file size */
  594. iztimes *t; /* return value: access, modific. and creation times */
  595. /* If file *f does not exist, return 0. Else, return the file's last
  596. modified date and time as an MSDOS date and time. The date and
  597. time is returned in a long with the date most significant to allow
  598. unsigned integer comparison of absolute times. Also, if a is not
  599. a NULL pointer, store the file attributes there, with the high two
  600. bytes being the Unix attributes, and the low byte being a mapping
  601. of that to DOS attributes. If n is not NULL, store the file size
  602. there. If t is not NULL, the file's access, modification and creation
  603. times are stored there as UNIX time_t values.
  604. If f is "-", use standard input as the file. If f is a device, return
  605. a file size of -1 */
  606. {
  607. struct stat s; /* results of stat() */
  608. char *name;
  609. int len = strlen(f), isstdin = !strcmp(f, "-");
  610. if (f == label) {
  611. if (a != NULL)
  612. *a = label_mode;
  613. if (n != NULL)
  614. *n = -2L; /* convention for a label name */
  615. if (t != NULL)
  616. t->atime = t->mtime = t->ctime = label_utim;
  617. return label_time;
  618. }
  619. if ((name = malloc(len + 1)) == NULL) {
  620. ZIPERR(ZE_MEM, "filetimeHHO");
  621. }
  622. strcpy(name, f);
  623. if (name[len - 1] == '/')
  624. name[len - 1] = '\0';
  625. /* not all systems allow stat'ing a file with / appended */
  626. if (isstdin) {
  627. /* it is common for some PC based compilers to
  628. fail with fstat() on devices or pipes */
  629. if (fstat(fileno(stdin), &s) != 0) {
  630. s.st_mode = S_IFREG; s.st_size = -1L;
  631. }
  632. time(&s.st_ctime);
  633. s.st_atime = s.st_mtime = s.st_ctime;
  634. } else if (stat(name, &s) != 0) {
  635. /* Accept about any file kind including directories
  636. * (stored with trailing / with -r option)
  637. */
  638. free(name);
  639. return 0;
  640. }
  641. if (a != NULL) {
  642. //*a = ((ulg)s.st_mode << 16) | (isstdin ? 0L : (ulg)GetFileMode(name));
  643. //*a = (ulg)s.st_mode;
  644. *a = s.st_attr;
  645. }
  646. printf ("\nDette er en test LINE : 721 \n"); getch();
  647. if (n != NULL)
  648. *n = (s.st_mode & S_IFMT) == S_IFREG ? s.st_size : -1L;
  649. #ifdef __WATCOMC__
  650. /* of course, Watcom always has to make an exception */
  651. if (s.st_atime == 312764400)
  652. s.st_atime = s.st_mtime;
  653. if (s.st_ctime == 312764400)
  654. s.st_ctime = s.st_mtime;
  655. #endif
  656. if (t != NULL) {
  657. t->atime = s.st_atime;
  658. t->mtime = s.st_mtime;
  659. t->ctime = s.st_ctime;
  660. }
  661. printf ("\nDette er en test LINE : 735 \n"); getch();
  662. //return GetFileTime(name);
  663. free(name);
  664. return t->atime;
  665. }
  666. int deletedir(d)
  667. char *d; /* directory to delete */
  668. /* Delete the directory *d if it is empty, do nothing otherwise.
  669. Return the result of rmdir(), delete(), or system().
  670. */
  671. {
  672. return rmdir(d);
  673. }
  674. int set_extra_field(z, z_utim)
  675. struct zlist far *z;
  676. iztimes *z_utim;
  677. /* create extra field and change z->att if desired */
  678. {
  679. #ifdef USE_EF_UT_TIME
  680. if ((z->extra = (char *)malloc(EB_HEADSIZE+EB_UT_LEN(1))) == NULL)
  681. return ZE_MEM;
  682. z->extra[0] = 'U';
  683. z->extra[1] = 'T';
  684. z->extra[2] = EB_UT_LEN(1); /* length of data part of e.f. */
  685. z->extra[3] = 0;
  686. z->extra[4] = EB_UT_FL_MTIME;
  687. z->extra[5] = (char)(z_utim->mtime);
  688. z->extra[6] = (char)(z_utim->mtime >> 8);
  689. z->extra[7] = (char)(z_utim->mtime >> 16);
  690. z->extra[8] = (char)(z_utim->mtime >> 24);
  691. z->cext = z->ext = (EB_HEADSIZE+EB_UT_LEN(1));
  692. z->cextra = z->extra;
  693. return ZE_OK;
  694. #else /* !USE_EF_UT_TIME */
  695. return (int)(z-z);
  696. #endif /* ?USE_EF_UT_TIME */
  697. }
  698. /******************************/
  699. /* Function version_local() */
  700. /******************************/
  701. static ZCONST char CompiledWith[] = "Compiled with %s%s for %s%s%s%s.\n\n";
  702. /* At module level to keep Turbo C++ 1.0 happy !! */
  703. void version_local()
  704. {
  705. #if defined(__DJGPP__) || defined(__WATCOMC__) || \
  706. (defined(_MSC_VER) && (_MSC_VER != 800))
  707. char buf[80];
  708. #endif
  709. printf(CompiledWith,
  710. #ifdef __GNUC__
  711. # if defined(__DJGPP__)
  712. (sprintf(buf, "djgpp v%d / gcc ", __DJGPP__), buf),
  713. # elif defined(__GO32__)
  714. "djgpp v1.x / gcc ",
  715. # elif defined(__EMX__) /* ...so is __EMX__ (double sigh) */
  716. "emx+gcc ",
  717. # else
  718. "gcc ",
  719. # endif
  720. __VERSION__,
  721. #elif defined(__WATCOMC__)
  722. # if (__WATCOMC__ % 10 > 0)
  723. /* We do this silly test because __WATCOMC__ gives two digits for the */
  724. /* minor version, but Watcom packaging prefers to show only one digit. */
  725. (sprintf(buf, "Watcom C/C++ %d.%02d", __WATCOMC__ / 100,
  726. __WATCOMC__ % 100), buf), "",
  727. # else
  728. (sprintf(buf, "Watcom C/C++ %d.%d", __WATCOMC__ / 100,
  729. (__WATCOMC__ % 100) / 10), buf), "",
  730. # endif
  731. #elif defined(__TURBOC__)
  732. # ifdef __BORLANDC__
  733. "Borland C++",
  734. # if (__BORLANDC__ < 0x0200)
  735. " 1.0",
  736. # elif (__BORLANDC__ == 0x0200) /* James: __TURBOC__ = 0x0297 */
  737. " 2.0",
  738. # elif (__BORLANDC__ == 0x0400)
  739. " 3.0",
  740. # elif (__BORLANDC__ == 0x0410) /* __BCPLUSPLUS__ = 0x0310 */
  741. " 3.1",
  742. # elif (__BORLANDC__ == 0x0452) /* __BCPLUSPLUS__ = 0x0320 */
  743. " 4.0 or 4.02",
  744. # elif (__BORLANDC__ == 0x0460) /* __BCPLUSPLUS__ = 0x0340 */
  745. " 4.5",
  746. # elif (__BORLANDC__ == 0x0500) /* __TURBOC__ = 0x0500 */
  747. " 5.0",
  748. # else
  749. " later than 5.0",
  750. # endif
  751. # else
  752. "Turbo C",
  753. # if (__TURBOC__ > 0x0401)
  754. "++ later than 3.0"
  755. # elif (__TURBOC__ == 0x0401) /* Kevin: 3.0 -> 0x0401 */
  756. "++ 3.0",
  757. # elif (__TURBOC__ == 0x0295) /* [661] vfy'd by Kevin */
  758. "++ 1.0",
  759. # elif ((__TURBOC__ >= 0x018d) && (__TURBOC__ <= 0x0200)) /* James: 0x0200 */
  760. " 2.0",
  761. # elif (__TURBOC__ > 0x0100)
  762. " 1.5", /* James: 0x0105? */
  763. # else
  764. " 1.0", /* James: 0x0100 */
  765. # endif
  766. # endif
  767. #elif defined(MSC)
  768. "Microsoft C ",
  769. # ifdef _MSC_VER
  770. # if (_MSC_VER == 800)
  771. "(Visual C++ v1.1)",
  772. # elif (_MSC_VER == 850)
  773. "(Windows NT v3.5 SDK)",
  774. # elif (_MSC_VER == 900)
  775. "(Visual C++ v2.0/v2.1)",
  776. # elif (_MSC_VER > 900)
  777. (sprintf(buf2, "(Visual C++ v%d.%d)", _MSC_VER/100 - 6,
  778. _MSC_VER%100/10), buf2),
  779. # else
  780. (sprintf(buf, "%d.%02d", _MSC_VER/100, _MSC_VER%100), buf),
  781. # endif
  782. # else
  783. "5.1 or earlier",
  784. # endif
  785. #else
  786. "unknown compiler", "",
  787. #endif
  788. "MS-DOS",
  789. #if (defined(__GNUC__) || (defined(__WATCOMC__) && defined(__386__)))
  790. " (32-bit)",
  791. #elif defined(M_I86HM) || defined(__HUGE__)
  792. " (16-bit, huge)",
  793. #elif defined(M_I86LM) || defined(__LARGE__)
  794. " (16-bit, large)",
  795. #elif defined(M_I86MM) || defined(__MEDIUM__)
  796. " (16-bit, medium)",
  797. #elif defined(M_I86CM) || defined(__COMPACT__)
  798. " (16-bit, compact)",
  799. #elif defined(M_I86SM) || defined(__SMALL__)
  800. " (16-bit, small)",
  801. #elif defined(M_I86TM) || defined(__TINY__)
  802. " (16-bit, tiny)",
  803. #else
  804. " (16-bit)",
  805. #endif
  806. #ifdef __DATE__
  807. " on ", __DATE__
  808. #else
  809. "", ""
  810. #endif
  811. );
  812. } /* end function version_local() */
  813. #ifdef __WATCOMC__
  814. /* This papers over a bug in Watcom 10.6's standard library... sigh */
  815. /* Apparently it applies to both the DOS and Win32 stat()s. */
  816. int stat_bandaid(const char *path, struct stat *buf)
  817. {
  818. char newname[4];
  819. if (!stat(path, buf))
  820. return 0;
  821. else if (!strcmp(path, ".") || (path[0] && !strcmp(path + 1, ":."))) {
  822. strcpy(newname, path);
  823. newname[strlen(path) - 1] = '\\'; /* stat(".") fails for root! */
  824. return stat(newname, buf);
  825. } else
  826. return -1;
  827. }
  828. #endif