Filewatcher File Search
FTP Search
  
Directory 
  
Content Search 
   
pkg://fntutl-1.40-4.src.rpm:3180/fntutl.tar.gz  info  downloads

asc2fnt.c000064400003250000024000000030140615254214500136170ustar00peterlinusers00000000000000/*
 *  Convert human-readable font image to EGA/VGA binary file.
 *
 *  $Header: asc2fnt.c,v 1.4 96/05/28 11:15:28 peterlin Exp $
 */

#include <string.h>
#include <stdio.h>
#include <errno.h>

#ifndef lint
static char rcsid[] = 
    "$Header: asc2fnt.c,v 1.4 96/05/28 11:15:28 peterlin Exp $";
#endif

#define ZERO '.'
#define ONE  '#'

/*  Evaluate a string representing an 8-bit binary number  */
bineval(char s[])
{
    int i;
    unsigned word = 0;

    for (i = 0; i < 8; i++, word = word << 1) {
        if (s[i] == ONE) word = word | 0x01;
    }
    return(word >> 1);
}


main(int argc, char *argv[])
{
    FILE *fp;
    char line[255], format[4];
    int n,i,c,height;

    if (argc == 1) {
	fprintf(stderr, "Usage: %s fontfile\n", argv[0]);
	exit(1);
    }
    if ((fp = fopen(argv[1], "r")) == NULL) {
        fprintf(stderr, "%s: cannot open %s\n", argv[0], argv[1]);
        perror(argv[0]);
        exit(1);
    }

    fscanf(fp,"%*s%*[ ]%s%*[ ]%*s%*[ ]%d%*[ ]%*s%*[ ]%s\n",
	line, &height, format);
    /*  Construct a PSF header if required */
    /*  All PSF files encountered so far as Mode 0 (byte offset 0x02 = 0)  */
    if (strcmp(format, "psf") == 0) {
	printf("%c%c%c%c", 0x36, 0x04, 0x00, height);
    }
    for (n = 0; n < 256; n++) {
	fscanf(fp,"%*s%*[ ]%d%*[^x]%*c%2x%*[^\n]", &c, &c);
	if (c != n) {
	    fprintf(stderr, "Char code mismatch, %d != %d\n", n, c);
	    exit(1);
	}
    	for (i = 0; i < height; i++) {
	    fscanf(fp,"%s\n", line);
	    c = bineval(line);
	    printf("%c", c);
	}
    }
    fclose(fp);
}
SF header if required */
    /*  All PSF files encountered so far as Mode 0 (byte offset 0x02 = 0)  */
    if (strcmp(format, "psf") == 0) {
	printf("%c%c%c%c", 0x36, 0x04, 0x00, height);
    }
    for (n = 0; n < 256; n++) {
	fscanf(fp,"%*s%*[ ]%d%*[^x]%*c%2x%*[^\n]", &c, &c);
	if (c != n) {
	    fprintf(stderr, "Char code mismatch, %d != %d\n", n, c);
	    exit(1);
	}
    	for (i = 0; i < height; i++) {
	    fscanf(fp,"%s\n", line);
	    c = bineval(line);
	    printf("%c", c);
	}
    }
    fcfnt2asc.c000064400003250000024000000041110615254332700136210ustar00peterlinusers00000000000000/*
 *  Convert binary fonts used by setfont(8) on Linux to human readable format.
 *
 *  $Header: fnt2asc.c,v 1.4 96/05/28 11:26:06 peterlin Exp $
 */

#ifndef lint
static char rcsid[] = 
    "$Header: fnt2asc.c,v 1.4 96/05/28 11:26:06 peterlin Exp $";
#endif

/*  needed for stat(2) on HP-UX  */
#ifdef __hpux
#ifndef _INCLUDE_POSIX_SOURCE
#define _INCLUDE_POSIX_SOURCE
#endif /* !_INCLUDE_POSIX_SOURCE */
#endif /* __hpux */

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>

#define ONE  '#'
#define ZERO '.'


/*  Get a single bit out of a word  */
unsigned getbit(unsigned word, unsigned bit)
{
    return ((word >> bit) & ~(~0 << 1));
}



main (int argc, char *argv[])
{
    FILE *fp;
    struct stat buf;
    int c, height, magic, mode, bit, mask;
    off_t fsize;
    long pos = 0;

    if (argc == 1) {
	printf("Usage: %s fontfile\n", argv[0]);
	exit(1);
    }
    if (stat(argv[1], &buf) != 0) {
	fprintf(stderr, "%s: cannot stat %s\n", argv[0], argv[1]);
	perror(argv[0]);
	exit(1);
    }

    if ((fp = fopen(argv[1], "r")) == NULL) {
	fprintf(stderr, "%s: cannot open %s\n", argv[0], argv[1]);
	perror(argv[0]);
	exit(1);
    }
    fsize = buf.st_size;
    height = fsize / 256;
    printf("File %s  height %d  ", argv[1], height);

    /*  Check for PSF files */
    if ((fsize % 256) != 0) {
	if ((magic = (getc(fp) + 256*getc(fp))) != 0x0436) {
	    fprintf(stderr, "%s: %s is not PSF file\n", argv[0], argv[1]);
	    fprintf(stderr, "Magic: %#.4x\n", magic);
	    exit(1);
	}
	mode = getc(fp);
	if (getc(fp) != height) {
	    fprintf(stderr, "%s: height mismatch in font %s\n",
		argv[0], argv[1]);
	    exit(1);
	}
	printf("format psf\n");
    } else {
	printf("format raw\n");
    }

    /*  Process the glyphs  */
    while ((c = getc(fp)) != EOF) {
	if ((pos % height) == 0) {
	    printf("Char %d (0x%.2x)\n", pos/height, pos/height);
	}
	for (bit = 7; bit >= 0; bit--) {
	    printf("%c", (getbit(c, bit) == 0) ? ZERO : ONE);
	}
#ifdef DEBUG
	printf("  %.2x\n", c);
#else /* ! DEBUG */
	printf("\n");
#endif /* DEBUG */
	pos = pos + 1;
    }

    fclose(fp);
}


match in font %s\n",
		argv[0], argv[1]);
	    exit(1);
	}
	printf("format psf\n");
    } else {
	printf("format raw\n");
    }

    /*  Process the glyphs  */
    while ((c = getc(fp)) != EOF) {
	if ((pos % height) == 0) {
	    printf("Char %d (0x%.2x)\n", pos/height, pos/height);
	}
	for (bit = 7; bit >= 0; bit--) {
	    printf("%c", (getbit(c, bit) == 0) ? ZERO : ONE);
	}
#ifdef DEBUG
	printf("  %.2x\n", c);
#else /* ! DEBUG */
	pri
Results 1 - 1
Help - FTP Sites List - Software Dir.
Searching half a billion files worldwide
© 1997-2009 MARUHN Internet Solutions