DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T b

⟦a0dceec09⟧ TextFile

    Length: 5714 (0x1652)
    Types: TextFile
    Names: »b_openclose.BSD4_n.c«, »b_openclose.SYS_V.c«

Derivation

└─⟦060c9c824⟧ Bits:30007080 DKUUG TeX 2/12/89
    └─⟦this⟧ »./tex82/Unsupported/MFpxl/mflib/b_openclose.BSD4_n.c« 
    └─⟦this⟧ »./tex82/Unsupported/MFpxl/mflib/b_openclose.SYS_V.c« 
└─⟦52210d11f⟧ Bits:30007239 EUUGD2: TeX 3 1992-12
    └─⟦beba6c409⟧ »unix3.0/Unsupported.tar.Z« 
        └─⟦25c524ae4⟧ 
            └─⟦this⟧ »Unsupported/MFpxl/mflib/b_openclose.BSD4_n.c« 
            └─⟦this⟧ »Unsupported/MFpxl/mflib/b_openclose.SYS_V.c« 

TextFile

#ifndef lint
static char RCSid[] = "$Header: b_openclose.c,v 1.0.1.1 86/02/06 16:45:56 richards Released $";
#endif

/*
 *	Byte I/O utility routines: a compiler independent set of routines for
 *			reading and writing byte files for the MF utilities
 *
 *		function bopenin(
 *				var	f: bytefile;
 *				var	bname: packed array [] of UNIX_file_name_char;
 *					pathsel: integer;
 *			    ): boolean;
 *			{ open the file whose name is in array bname	}
 *			{ optionally searching using path "pathsel"	}
 *			{ for input only; return true if open OK	}
 *
 *		function bopenout(
 *				var	f: bytefile;
 *				var	bname: packed array [] of UNIX_file_name_char
 *			    ): boolean;
 *			{ open the file whose name is in array bname	}
 *			{ for input only; return true if open OK	}
 *
 *		procedure bclose(var f: bytefile);
 *			{ close open byte file F, flush output if needed }
 *
 *		function beof(var f: bytefile): boolean;
 *			{ true if EOF condition exists on b file	}
 *
 *		function bfilelen(var f: bytefile): integer;
 *			{ returns size in bytes of open b file		}
 *
 *		function bfileloc(var f: bytefile): integer;
 *			{ returns current file offset in bytes		}
 *
 *		procedure bsetptr(var f: bytefile, var ptr: integer);
 *			{ saves address of variable "ptr" in bytefile	}
 *			{ struct so it can be updated when accesses to	}
 *			{ bytefile are made. (used to emulate cur_loc	}
 *			{ used with original MF routines)		}
 *
 *		procedure bseek(var f: bytefile; n: integer);
 *			{ sets internal idea of "current byte position"	}
 *			{ to n; next read will read starting at byte n	}
 *
 *		procedure bgetname(
 *				var	f: bytefile;
 *				var	name: packed array [] of UNIX_file_name_char;
 *			    );
 *			{ obtains a copy of the name of file "f"	}
 *			{ in "name"					}
 *
 *
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "h00vars.h"
#include "mftypes.h"

/*
 * function bopenin(
 *			var	bf: bytefile;
 *			var	bname: array ...;
 *				pathsel: integer   ): boolean;
 *
 *		returns true if open succeeds, else false
 *		stores stdio file ptr in bf for use by
 *		remainder of routines. Pathsel selects a path name
 *		to use during input open, or 0 if no searching wanted
 */

bool bopenin(bf, bname, pathsel)
    register	bytefile *bf;
    register	UNIX_file_name_char *bname;
    integer	pathsel;
{
    char	*pathp;

    extern char	*path_select();

    if (pathsel && (*bname != '/'))
	pathp = path_select(pathsel);
    else
	pathp = NULL;

    do {
	path_buildname(bname, bf->b_file_name, &pathp);
	if (bf->b_fp = fopen(bf->b_file_name, "r")) {
		bf->b_locptr = NULL;
		return(TRUE);
	}
    } while (pathp != NULL);

    bf->b_fp = NULL;
    bf->b_locptr = NULL;
    return(FALSE);
}

/*
 * function bopenout(var bf: bytefile, var bname: array ...): boolean;
 *
 *		returns true if open succeeds, else false
 *		stores stdio file ptr in bf for use by
 *		remainder of routines.
 */

bool bopenout(bf, bname)
    bytefile	*bf;
    register	UNIX_file_name_char *bname;
{
    register	char *namep;
    register	FILE *fp;

    namep = bf->b_file_name;	/* skip over filename till first blank	*/
    while ((*namep = *bname) != ' ')
	bname++, namep++;
    *namep = '\0';

    if ((fp = fopen(bf->b_file_name, "w")) == NULL) {
	bf->b_fp = NULL;
	bf->b_locptr = 0;
	return(FALSE);
    }
    bf->b_fp = fp;
    bf->b_locptr = 0;
    return(TRUE);
}

/*
 * procedure bclose(var f: bytefile);
 *
 *	flush output and close "f"
 */

void bclose(bf)
    bytefile	*bf;
{
    if (bf->b_fp)
	(void) fclose(bf->b_fp);
    bf->b_fp = NULL;
    bf->b_locptr = NULL;
}

/*
 * function beof(var f: bytefile): boolean;
 *
 *	return true if EOF on byte file (also true if not open)
 */

bool beof(bf)
    bytefile	*bf;
{
    register	FILE *fp = bf->b_fp;
    register	int c;

    if ((fp == NULL) || (c = getc(fp)) == EOF)
	return (TRUE);
    (void) ungetc(c, fp);
    return (FALSE);
}


/*
 * function bfilelen(var bf: bytefile): integer;
 *
 *	return length of open byte file in bytes
 */

integer bfilelen(bf)
    bytefile	*bf;
{
    register	FILE *fp = bf->b_fp;
    struct	stat bstat;

    if (fp == NULL || fstat(fileno(fp), &bstat))
	return(0);

    return(bstat.st_size);
}

/*
 * function bfileloc(var bf: bytefile): integer;
 *
 *	return current location of open byte file in bytes
 */

integer bfileloc(bf)
    bytefile	*bf;
{
    register	FILE *fp = bf->b_fp;

    if (fp == NULL)
	return(0);

    return(ftell(fp));
}

/*
 * procedure bsetptr(var bf: bytefile; var ptr: integer);
 *
 *	save address of "ptr" in bytefile struct so whever we
 *	read/write/seek on "bf", we can update the value in "ptr"
 *	to follow.  Emulates "cur_loc" update mechanism used
 *	in MF.  Note that these routines don't do anything to
 *	the b_locptr field in "bf" unless we explicitly set
 *	it up with this routine.
 */

void bsetptr(bf, ptr)
    bytefile	*bf;
    integer	*ptr;
{
    bf->b_locptr = ptr;
}

/*
 * procedure bseek(var bf: bytefile;n: integer);
 *
 *	moves "current-position" to n for reading
 */

void bseek(bf, n)
    bytefile	*bf;
    integer	n;
{
    register	FILE *fp = bf->b_fp;

    if (fp && (fseek(fp, (long)n, 0) == -1))
	perror("bseek");
    if (bf->b_locptr)
	*bf->b_locptr = n;
}

/*
 * procedure bgetname(var bf: bytefile; var name: packed array ...)
 *
 *	provides a means to retrieve the name used to open a byte
 *	file.  copies it back from the bytefile structure into
 *	whatever perverted data type Pascal stores characters in
 */

void bgetname(bf, name)
    bytefile	*bf;
    register	UNIX_file_name_char *name;
{
    register	char *cp;

    cp = bf->b_file_name;
    while (*name = *cp++)
	name++;
    *name++ = ' ';	/* pascal likes space-terminated */
}