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