Category : C Source Code
Archive   : MIKES40C.ZIP
Filename : MAKARRAY.C

 
Output of file : MAKARRAY.C contained in archive : MIKES40C.ZIP
/**********************************************************************
makarray.c compile: msc makarray.c; for Microsoft C 4.0
link makarray;

Makarray will convert any file into C array format. It was written
to allow 4000 byte screen dumps, like the .bin files generated by
ANSIPAINT, to be linked into a C program and displayed by the
putscrn(screen array, video page) function. The output for
makarray() is sent to stdout and can be redirected to any .c or .h
file. The resulting char * is called hexdata, but can be changed
to any name.

Usage: makarray filename >screen.h

10/24/86 by Mike Elkins Mike's C Board -- 619-722-8724

************************************************************************/
#include
#include
#include
#define BUFSIZE 512

extern int errno;
char buffer[BUFSIZE]; /* input buffer */

main(argc,argv) /* Generate arrar */
int argc;
char *argv[];
{
char c;
unsigned int i,numin,tot,file,cfrom;

if (argc < 2) {
abort("Usage:makarray filespec ",0,0);
}

if ((file=open(argv[1],O_BINARY)) == -1) {
abort("cannot open",argv[1],errno);
}

tot = 0;

/* read and dump BUFSIZE at a time */

printf("char hexdata[] = { \n");
do {
numin=read(file,buffer,BUFSIZE);
tot += numin;
if (numin == -1) {
abort("cannot read",argv[1],errno);
}
cfrom=0;
while (cfrom < numin) {


/* print 16 bytes in hex */

for (i=0; i < 16; i++) {
putchar('0');
putchar('x');
ohb(buffer[cfrom++]);
putchar(',');
}

/* print the bytes in ascii as a comment */
/**** REMOVE COMMENTS TO ENABLE ASCII *****/

/* printf(" /* "); */
/* for (i=0; i < 16; i++) { */
/* c = buffer[cfrom] & 0x7f;*/
/* if ( isprint(c) ) */
/* putchar(c); */
/* else */
/* putchar('.'); */
/* cfrom++; */
/* } */
/* printf(" * /"); */ /* remove space in comment */

putchar('\n');
}
}
while (numin == BUFSIZE);

printf("0x00 }; /* %u bytes */", tot); /* terminate w/NULL */
}

ohb(byt) /* print a byte in hex */
char byt;
{
onib(byt>>4);
onib(byt);
}

onib(nib) /* print a nibble as a hex character */
char nib;
{

nib&=15;
putchar((nib >= 10) ? nib-10+'A': nib+'0');
}

/** abort.c - print error messages & number then call _exit(FAIL)
9.15.83
**/

abort( msg1 ,msg2 ,errno) /* print error msg1, msg2, and nbr */
char *msg1,*msg2; /* Does not close files. */
short errno;
{
fprintf(stderr,"ERR: ");
if (msg1)
fprintf(stderr,msg1);
if (msg2)
fprintf(stderr," ");
fprintf(stderr,msg2);
if (errno) {
fprintf(stderr," %-d",errno);
}
exit(1);
}


  3 Responses to “Category : C Source Code
Archive   : MIKES40C.ZIP
Filename : MAKARRAY.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/