home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
text
/
pastex-1.3-1of8.lha
/
PasTeX
/
src
/
flib
/
flib.c
next >
Wrap
C/C++ Source or Header
|
1992-11-03
|
47KB
|
1,874 lines
/*
* Fontlibrary program.
*
* used for our TeX-system to save disk space and for
* speed up the loading of fonts for "ShowDVI" and "DVIprint".
*
* This program is freely redistributable. You may modify and use this
* program to your heart's content, so long as you send modifications
* to Georg Hessmann. It can be included in any distribution, commercial
* or otherwise, so long as the banner string defined in the constant
* HEADER is not modified (except for the version number and the machine
* type) and this banner is printed on program invocation, or can be
* printed on program invocation with the -? option.
*
* For further information read the README file.
*
* 31.01.90 (hes) (C) Copyright 1990/91 Georg Hessmann.
*
* 12.02.90 (hes) v1.01 new flib-format, rename command
* 14.02.90 (rbs) ported to Atari ST
* 25.04.90 (jrb) fixed up for Atari ST gcc
* 05.06.90 (hes) v1.02 little bug fixes, add flib links (hes)
* 08.01.91 (hes) v1.03 add relative flib links
* 03.11.92 (hes) v1.10 add wildcard support (only with Dice/Amiga)
* add two new flags 's' and 'e'
* 's' -- strip path, don't store the path of a font
* 'e' -- strip extension, don't store the extension
*/
/* Is the compiler a ANSI-C compiler */
#ifdef AMIGA
# ifdef LATTICE
# define ANSI
# endif
# ifdef AZTEC_C
# define ANSI
# endif /* AZTEC_C */
# ifdef _DCC
# define ANSI
# endif /* _DCC */
#else
# ifdef ATARI
# ifdef __GNUC__
# define ANSI
# endif /* __GNUC__ */
# endif /* ATARI */
#endif /* AMIGA */
/* standard includes */
#include <stdio.h>
#ifdef ANSI
# include <stdlib.h>
# include <string.h>
# ifdef AMIGA
# ifndef _DCC
# include <dos.h>
# endif /* !_DCC */
# endif /* AMIGA */
# ifdef ATARI
# ifndef __GNUC__
# include <tos.h>
# include <ext.h>
# else
# include <unixlib.h>
# include <fcntl.h>
# define S_IWRITE W_OK
# define S_IREAD R_OK
# endif /* __GNUC__ */
# endif /* ATARI */
#endif /* ANSI */
/* open mode for files */
#ifdef ATARI
# define OPEN_FOR_READING "rb"
# define OPEN_FOR_WRITING "wb"
# define OPEN_FOR_APPEND "rb+"
# ifndef __GNUC__
extern int access(char *, int);
# endif /* __GNUC__ */
#else
# define OPEN_FOR_READING "r"
# define OPEN_FOR_WRITING "w"
# define OPEN_FOR_APPEND "r+"
#endif
/* prototyping on/off */
#ifdef ANSI
# define Args(x) x
#else
# define Args(x) ()
#endif /* ANSI */
#ifdef AZTEC_C
void *malloc Args((unsigned));
void free Args((char *));
char *strchr();
char *strrchr();
#endif /* AZTEC_C */
#ifdef AMIGA
# ifdef LATTICE
# define perror(x) poserr(x)
# endif /* LATTICE */
# ifdef AZTEC_C
# define remove(x) unlink(x)
/* warning: AztecC seems to have problems with the returncode from fseek */
# endif /* AZTEC_C */
#else AMIGA
# ifndef ANSI
# define remove(x) unlink(x)
# endif /* ANSI */
#endif /* AMIGA */
#ifdef ATARI
# include <errno.h>
#else
extern int errno;
#endif
/* Aufbau einer Fontlibrary :
* +---------------------------------------+
* | magic number 4 Bytes |
* | number of direntries 4 Bytes |
* | [flib_dirent]* |
* | [modules]* |
* +---------------------------------------+
*/
/* important constants */
#define OLD_LIBMAGIC 0xA797F033L /* magic number */
#define LIBMAGIC (((long)'F'<<24) | ((long)'L'<<16) | ((long)'I'<<8) | (long)'B')
#define LNKMAGIC (((long)'F'<<24) | ((long)'L'<<16) | ((long)'N'<<8) | (long)'K')
#define FILENAMELEN 14
#define NEWFILENAMELEN 22
#define TMPFLIB "tmpflib.tmp"
#define BUFSIZE 20480
#define DOSNAMESIZE 100
#define MAXLINKLEVELS 20
#ifdef AMIGA
# define MACHINE "AMIGA"
#else
# ifdef ATARI
# define MACHINE "ATARI"
# else
# define MACHINE "UNIX"
# include <sys/file.h>
# define S_IWRITE W_OK
# define S_IREAD R_OK
# endif /* ATARI */
#endif /* AMIGA */
#define VERSION "1.10"
#ifdef ATARI
# define HEADER "FontLib Manager - Version %s for %s \275 1990/91/92 Georg Hessmann/Robert Stabl\n"
#else
# define HEADER "FontLib Manager - Version %s for %s (c) 1990/91/92 Georg Hessmann\n"
#endif
#ifdef AMIGA
static char version[] = "\0$VER: flib 1.10 (11/03/92)";
#endif
#define OLD_VERSION 0
#define NEW_VERSION 1
static char buffer[BUFSIZE]; /* used to copy modules */
#ifndef FALSE
# define FALSE 0
#endif /* FALSE */
#ifndef TRUE
# define TRUE (!FALSE)
#endif /* TRUE */
#define offset(ptr,member) ((long)(&((ptr)->member))-(long)(ptr))
/************ structure definitions ***************/
/* fontlib directory structures */
struct flib_dirent { char mname[FILENAMELEN]; /* old version */
long size; /* size of pk-module in bytes */
long where; /* position in flib-file */
};
struct new_flib_dirent { char mname[NEWFILENAMELEN]; /* new version */
unsigned short checksum;
long size; /* size of pk-module in bytes */
long where; /* position in flib-file */
char * real_path; /* only for flib internal use!! */
/* real_path won't saved to the flib */
};
union direntry { struct flib_dirent old;
struct new_flib_dirent new;
};
/* internal representation of the flib-directory */
struct dirlist { struct new_flib_dirent dirent;
struct dirlist *next;
};
struct dir { long total;
long alloc;
int version; /* old or new flib */
int is_link;
struct dirlist *dirlist;
char real_name[DOSNAMESIZE];
};
/********* P R O T O T Y P E S ********/
/* main function */
void main Args((int argc, char *argv[]));
/********* local functions **********/
/* print the help */
static void usage Args((char *pname));
/* parse the first argument */
static int decode_args Args((int argc, char **argv,
int *table,
int *extract,
int *create,
int *delete,
int *compress,
int *verbose,
int *rename,
int *test,
int *link,
int *term_input));
/* calculates the length of a module name */
static int module_len(char * name);
/* delete flib with the name "name" and rename the tmpflib to "name" */
/* nr is the number of modules in the flib => nr == 0 --> no flib */
static int insert_name_into_dir Args((char *name,
struct dirlist **dirl,
int version));
/* is module from "test" in "inp1" or "inp2" ? */
static struct dirlist *exist_entry Args((struct dirlist *inp1,
struct dirlist *inp2,
struct dirlist *test));
/* create a dirlist structure entry whith the module-name "name" */
static int read_new_modules Args((int term_input,
int argc,
char **argv,
struct dir *directory,
struct dirlist **start_dirl,
int verbose));
/* read a list of modules from argv or from stdin */
static FILE *open_flib Args((char *name,
char *mode,
struct dir *directory,
short levels));
/* open a flib and test the magic-number */
static int read_dir Args((FILE *f,
struct dir *directory));
/* read the directory from the flib (file-pointer must be on the first dir) */
/* only this directory entries a correct where "where != 0" the others are unused */
static void print_dir Args((struct dir *directory,
char *lib_name,
int verbose));
/* print the contents of the directory */
static int ex_module Args((struct dir *directory,
char *mname,
FILE *flib, int verbose));
/* search a module in the flib and copy it to a new file */
static int create_new_flib Args((struct dir *directory,
char *name,
int verbose));
/* create a complete (new) flib, copy only files into the flib */
static int copy_module Args((char *name,
char *real_path,
FILE *flib,
long *size,
long *where,
unsigned short *check));
/* create a new flib and prepare the directory part */
static FILE *c