Initial revision

This commit is contained in:
François Pinard
1994-11-16 02:56:44 +00:00
parent 5db79aed3b
commit 8667993049
3 changed files with 158 additions and 175 deletions

View File

@@ -1,4 +1,4 @@
# Makefile for GNU tar on MS-DOS.
# Makefile for GNU tar on MS-DOS using Turbo C 2.0.
# Copyright (C) 1991 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
@@ -15,18 +15,22 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
CC = bcc
CC = tcc
RM = rm -f
MODEL = m
DEFS = -DNONAMES -DNO_REMOTE -DSTDC_HEADERS=1 -m$(MODEL) -Dmain=_main
DEFS = -DNONAMES -DNO_REMOTE -DNO_MTIO -DSTDC_HEADERS -m$(MODEL) -Dmain=_main
LIBS =
DEF_AR_FILE = tar.out
DEFBLOCKING = 20
CFLAGS = $(DEFS)
CFLAGS = -I. $(DEFS) \
-DDEF_AR_FILE="$(DEF_AR_FILE)" \
-DDEFBLOCKING=$(DEFBLOCKING)
LDFLAGS = -m$(MODEL)
OBJ1 = tar.obj create.obj extract.obj buffer.obj getoldopt.obj update.obj gnu.obj mangle.obj
OBJ2 = version.obj list.obj names.obj diffarch.obj port.obj fnmatch.obj getopt.obj
OBJ2 = version.obj list.obj names.obj diffarch.obj port.obj wildmat.obj getopt.obj
OBJ3 = getopt1.obj regex.obj getdate.obj alloca.obj tcexparg.obj msd_dir.obj
OBJS = $(OBJ1) $(OBJ2) $(OBJ3)
@@ -39,11 +43,6 @@ tar: testpad.h getdate.c $(OBJS)
.c.obj:
$(CC) -c $(CFLAGS) $<
# For some reason, Borland C++ 3.1 chokes on this file when given
# the full set of -D options.
getoldopt.obj: getoldopt.c
$(CC) -c -m$(MODEL) -DSTDC_HEADERS getoldopt.c
testpad.h: testpad.exe
testpad
@@ -53,8 +52,6 @@ testpad.exe: testpad.c
clean:
$(RM) errs *.obj tar testpad testpad.h
mostlyclean: clean
distclean: clean
realclean: clean

View File

@@ -11,19 +11,17 @@
#include "msd_dir.h"
#ifndef __TURBOC__
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#include <string.h>
#include <dos.h>
#ifndef NULL
# define NULL 0
#endif /* NULL */
#endif /* NULL */
#ifndef MAXPATHLEN
# define MAXPATHLEN 255
#endif /* MAXPATHLEN */
#endif /* MAXPATHLEN */
/* attribute stuff */
#define A_RONLY 0x01
@@ -43,187 +41,178 @@
#define ATTRIBUTES (A_RONLY | A_SYSTEM | A_DIR)
/* what find first/next calls look use */
typedef struct
{
char d_buf[21];
char d_attribute;
unsigned short d_time;
unsigned short d_date;
long d_size;
char d_name[13];
}
typedef struct {
char d_buf[21];
char d_attribute;
unsigned short d_time;
unsigned short d_date;
long d_size;
char d_name[13];
} Dta_buf;
Dta_buf;
static char *getdirent();
static void mysetdta();
static void free_dircontents();
static char *getdirent ();
static void mysetdta ();
static void free_dircontents ();
static Dta_buf dtabuf;
static Dta_buf *dtapnt = &dtabuf;
static union REGS reg, nreg;
static Dta_buf dtabuf;
static Dta_buf *dtapnt = &dtabuf;
static union REGS reg, nreg;
#if defined(M_I86LM)
static struct SREGS sreg;
static struct SREGS sreg;
#endif
DIR *
opendir (name)
char *name;
DIR *
opendir(name)
char *name;
{
struct stat statb;
DIR *dirp;
char c;
char *s;
struct _dircontents *dp;
char nbuf[MAXPATHLEN + 1];
struct stat statb;
DIR *dirp;
char c;
char *s;
struct _dircontents *dp;
char nbuf[MAXPATHLEN + 1];
if (stat(name, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFDIR)
return (DIR *) NULL;
if (Newisnull(dirp, DIR))
return (DIR *) NULL;
if (*name && (c = name[strlen(name) - 1]) != '\\' && c != '/')
(void) strcat(strcpy(nbuf, name), "\\*.*");
else
(void) strcat(strcpy(nbuf, name), "*.*");
dirp->dd_loc = 0;
mysetdta();
dirp->dd_contents = dirp->dd_cp = (struct _dircontents *) NULL;
if ((s = getdirent(nbuf)) == (char *) NULL)
return dirp;
do {
if (Newisnull(dp, struct _dircontents) || (dp->_d_entry =
malloc((unsigned) (strlen(s) + 1))) == (char *) NULL)
{
if (dp)
free((char *) dp);
free_dircontents(dirp->dd_contents);
return (DIR *) NULL;
}
if (dirp->dd_contents)
dirp->dd_cp = dirp->dd_cp->_d_next = dp;
else
dirp->dd_contents = dirp->dd_cp = dp;
(void) strcpy(dp->_d_entry, s);
dp->_d_next = (struct _dircontents *) NULL;
} while ((s = getdirent((char *) NULL)) != (char *) NULL);
dirp->dd_cp = dirp->dd_contents;
if (stat (name, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFDIR)
return (DIR *) NULL;
if (Newisnull (dirp, DIR))
return (DIR *) NULL;
if (*name && (c = name[strlen (name) - 1]) != '\\' && c != '/')
(void) strcat (strcpy (nbuf, name), "\\*.*");
else
(void) strcat (strcpy (nbuf, name), "*.*");
dirp->dd_loc = 0;
mysetdta ();
dirp->dd_contents = dirp->dd_cp = (struct _dircontents *) NULL;
if ((s = getdirent (nbuf)) == (char *) NULL)
return dirp;
do
{
if (Newisnull (dp, struct _dircontents) || (dp->_d_entry =
malloc ((unsigned) (strlen (s) + 1))) == (char *) NULL)
{
if (dp)
free ((char *) dp);
free_dircontents (dirp->dd_contents);
return (DIR *) NULL;
}
if (dirp->dd_contents)
dirp->dd_cp = dirp->dd_cp->_d_next = dp;
else
dirp->dd_contents = dirp->dd_cp = dp;
(void) strcpy (dp->_d_entry, s);
dp->_d_next = (struct _dircontents *) NULL;
}
while ((s = getdirent ((char *) NULL)) != (char *) NULL);
dirp->dd_cp = dirp->dd_contents;
return dirp;
return dirp;
}
void
closedir (dirp)
DIR *dirp;
closedir(dirp)
DIR *dirp;
{
free_dircontents (dirp->dd_contents);
free ((char *) dirp);
free_dircontents(dirp->dd_contents);
free((char *) dirp);
}
struct dirent *
readdir (dirp)
DIR *dirp;
struct dirent *
readdir(dirp)
DIR *dirp;
{
static struct dirent dp;
static struct dirent dp;
if (dirp->dd_cp == (struct _dircontents *) NULL)
return (struct dirent *) NULL;
dp.d_namlen = dp.d_reclen =
strlen(strcpy(dp.d_name, dirp->dd_cp->_d_entry));
strlwr(dp.d_name); /* JF */
dp.d_ino = 0;
dirp->dd_cp = dirp->dd_cp->_d_next;
dirp->dd_loc++;
if (dirp->dd_cp == (struct _dircontents *) NULL)
return (struct dirent *) NULL;
dp.d_namlen = dp.d_reclen =
strlen (strcpy (dp.d_name, dirp->dd_cp->_d_entry));
strlwr (dp.d_name); /* JF */
dp.d_ino = 0;
dirp->dd_cp = dirp->dd_cp->_d_next;
dirp->dd_loc++;
return &dp;
return &dp;
}
void
seekdir (dirp, off)
DIR *dirp;
long off;
seekdir(dirp, off)
DIR *dirp;
long off;
{
long i = off;
struct _dircontents *dp;
long i = off;
struct _dircontents *dp;
if (off < 0)
return;
for (dp = dirp->dd_contents; --i >= 0 && dp; dp = dp->_d_next)
;
dirp->dd_loc = off - (i + 1);
dirp->dd_cp = dp;
if (off < 0)
return;
for (dp = dirp->dd_contents ; --i >= 0 && dp ; dp = dp->_d_next)
;
dirp->dd_loc = off - (i + 1);
dirp->dd_cp = dp;
}
long
telldir (dirp)
DIR *dirp;
telldir(dirp)
DIR *dirp;
{
return dirp->dd_loc;
return dirp->dd_loc;
}
static void
free_dircontents (dp)
struct _dircontents *dp;
static void
free_dircontents(dp)
struct _dircontents *dp;
{
struct _dircontents *odp;
struct _dircontents *odp;
while (dp)
{
if (dp->_d_entry)
free (dp->_d_entry);
dp = (odp = dp)->_d_next;
free ((char *) odp);
}
while (dp) {
if (dp->_d_entry)
free(dp->_d_entry);
dp = (odp = dp)->_d_next;
free((char *) odp);
}
}
static char *
getdirent (dir)
char *dir;
static char *
getdirent(dir)
char *dir;
{
if (dir != (char *) NULL)
{ /* get first entry */
reg.h.ah = DOSI_FINDF;
reg.h.cl = ATTRIBUTES;
if (dir != (char *) NULL) { /* get first entry */
reg.h.ah = DOSI_FINDF;
reg.h.cl = ATTRIBUTES;
#if defined(M_I86LM)
reg.x.dx = FP_OFF (dir);
sreg.ds = FP_SEG (dir);
reg.x.dx = FP_OFF(dir);
sreg.ds = FP_SEG(dir);
#else
reg.x.dx = (unsigned) dir;
reg.x.dx = (unsigned) dir;
#endif
}
else
{ /* get next entry */
reg.h.ah = DOSI_FINDN;
} else { /* get next entry */
reg.h.ah = DOSI_FINDN;
#if defined(M_I86LM)
reg.x.dx = FP_OFF (dtapnt);
sreg.ds = FP_SEG (dtapnt);
reg.x.dx = FP_OFF(dtapnt);
sreg.ds = FP_SEG(dtapnt);
#else
reg.x.dx = (unsigned) dtapnt;
reg.x.dx = (unsigned) dtapnt;
#endif
}
}
#if defined(M_I86LM)
intdosx (&reg, &nreg, &sreg);
intdosx(&reg, &nreg, &sreg);
#else
intdos (&reg, &nreg);
intdos(&reg, &nreg);
#endif
if (nreg.x.cflag)
return (char *) NULL;
if (nreg.x.cflag)
return (char *) NULL;
return dtabuf.d_name;
return dtabuf.d_name;
}
static void
mysetdta ()
static void
mysetdta()
{
reg.h.ah = DOSI_SDTA;
reg.h.ah = DOSI_SDTA;
#if defined(M_I86LM)
reg.x.dx = FP_OFF (dtapnt);
sreg.ds = FP_SEG (dtapnt);
intdosx (&reg, &nreg, &sreg);
reg.x.dx = FP_OFF(dtapnt);
sreg.ds = FP_SEG(dtapnt);
intdosx(&reg, &nreg, &sreg);
#else
reg.x.dx = (int) dtapnt;
intdos (&reg, &nreg);
reg.x.dx = (int) dtapnt;
intdos(&reg, &nreg);
#endif
}

View File

@@ -15,30 +15,27 @@ typedef int ino_t;
typedef int dev_t;
#endif
struct dirent
{
ino_t d_ino; /* a bit of a farce */
int d_reclen; /* more farce */
int d_namlen; /* length of d_name */
char d_name[MAXNAMLEN + 1]; /* garentee null termination */
};
struct direct {
ino_t d_ino; /* a bit of a farce */
int d_reclen; /* more farce */
int d_namlen; /* length of d_name */
char d_name[MAXNAMLEN + 1]; /* garentee null termination */
};
struct _dircontents
{
char *_d_entry;
struct _dircontents *_d_next;
};
struct _dircontents {
char *_d_entry;
struct _dircontents *_d_next;
};
typedef struct _dirdesc
{
int dd_id; /* uniquely identify each open directory */
long dd_loc; /* where we are in directory entry is this */
struct _dircontents *dd_contents; /* pointer to contents of dir */
struct _dircontents *dd_cp; /* pointer to current position */
} DIR;
typedef struct _dirdesc {
int dd_id; /* uniquely identify each open directory */
long dd_loc; /* where we are in directory entry is this */
struct _dircontents *dd_contents; /* pointer to contents of dir */
struct _dircontents *dd_cp; /* pointer to current position */
} DIR;
extern DIR *opendir ();
extern struct dirent *readdir ();
extern void seekdir ();
extern long telldir ();
extern void closedir ();
extern DIR *opendir();
extern struct direct *readdir();
extern void seekdir();
extern long telldir();
extern void closedir();