1
0

Source code upload

This commit is contained in:
calmsacibis995
2022-09-29 17:59:04 +03:00
parent 72fa9da3d7
commit 8fc8fa8089
33399 changed files with 11964078 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
#
# Makefile for bdftohtp(1).
#
#ident "$Revision: 1.5 $"
ROOT = /
include ${ROOT}/usr/include/make/commondefs
CFILES = bdftohtp.c xbmtohtpbm.c graytospans.c topcbm.c graytoxbm.c xbmtospans.c
TARGETS = xbmtohtpbm bdftohtp graytospans topcbm graytoxbm xbmtospans
LCINCS = -I$(INCLDIR)/gl
LLDLIBS = -limage -lXmu
default:$(TARGETS)
include ${COMMONRULES}
+319
View File
@@ -0,0 +1,319 @@
#include "stdio.h"
char *getnum(int *val, char *parmptr);
#define UNKNOWN 0
#define STARTFONT 1
#define COMMENT 2
#define FONT 3
#define SIZE 4
#define FONTBOUNDINGBOX 5
#define STARTPROPERTIES 6
#define _DEC_DEVICE_FONTNAMES 7
#define FONTNAME_REGISTRY 8
#define WEIGHT_NAME 9
#define SLANT 10
#define SETWIDTH_NAME 11
#define ADD_STYLE_NAME 12
#define PIXEL_SIZE 13
#define POINT_SIZE 14
#define RESOLUTION_X 15
#define RESOLUTION_Y 16
#define SPACING 17
#define AVERAGE_WIDTH 18
#define CHARSET_REGISTRY 19
#define CHARSET_ENCODING 20
#define CHARSET_COLLECTIONS 21
#define FULL_NAME 22
#define COPYRIGHT 23
#define FONT_ASCENT 24
#define FONT_DESCENT 25
#define CAP_HEIGHT 26
#define X_HEIGHT 27
#define ENDPROPERTIES 28
#define CHARS 29
#define STARTCHAR 30
#define ENCODING 31
#define SWIDTH 32
#define DWIDTH 33
#define BBX 34
#define BITMAP 35
#define ENDCHAR 36
#define ENDFONT 37
#define ENDOFFILE 99
char *linetypetab[]={
"UNKNOWN",
"STARTFONT",
"COMMENT",
"FONT",
"SIZE",
"FONTBOUNDINGBOX",
"STARTPROPERTIES",
"_DEC_DEVICE_FONTNAMES",
"FONTNAME_REGISTRY",
"WEIGHT_NAME",
"SLANT",
"SETWIDTH_NAME",
"ADD_STYLE_NAME",
"PIXEL_SIZE",
"POINT_SIZE",
"RESOLUTION_X",
"RESOLUTION_Y",
"SPACING",
"AVERAGE_WIDTH",
"CHARSET_REGISTRY",
"CHARSET_ENCODING",
"CHARSET_COLLECTIONS",
"FULL_NAME",
"COPYRIGHT",
"FONT_ASCENT",
"FONT_DESCENT",
"CAP_HEIGHT",
"X_HEIGHT",
"ENDPROPERTIES",
"CHARS",
"STARTCHAR",
"ENCODING",
"SWIDTH",
"DWIDTH",
"BBX",
"BITMAP",
"ENDCHAR",
"ENDFONT",
0
};
typedef struct charstruct_s {
int encoding;
int swidth1;
int swidth2;
int dwidth1;
int dwidth2;
int bbx1;
int bbx2;
int bbx3;
int bbx4;
int offset;
unsigned short *bitmap;
} charstruct_t;
#ifdef non_iso8660
#define printable(X) (((X) >= 32) && ((X) <= 127))
#else
#define printable(X) ( (((X) >= 32) && ((X) <= 127)) || \
(((X) >= (0x80|32) && ((X) <= (0x80|127)))) )
#endif
char line[1024];
int linestatus;
void
identifyline(int *linetype, char **firstparm)
{
int i, tokenlen;
if (linestatus == 1){
*linetype = ENDOFFILE;
*firstparm = 0;
return;
}
for (i = 0; ; i++){
if (linetypetab[i] == 0)
return;
tokenlen = strlen(linetypetab[i]);
if (strncmp(line, linetypetab[i], tokenlen) == 0)
break;
}
*linetype = i;
*firstparm = line+tokenlen;
}
main(int argc, char **argv)
{
int linetype, charstructlistp, i, j, nshorts;
int offset, maxht = 0, maxds = 0;
unsigned long v, len;
charstruct_t *charstruct, *charstructlist[2048];
char *p, *parmptr, *FontName;
if (argc == 2)
FontName = argv[1];
else
FontName = "Font";
charstructlistp = 0;
while (1) {
p = gets(line);
if (p == 0)
linestatus = 1;
else
linestatus = 0;
identifyline(&linetype, &parmptr);
switch(linetype) {
case ENDOFFILE:
goto output;
break;
case UNKNOWN:
fprintf(stderr, "Unknown token\n");
exit(1);
break;
case STARTFONT:
case COMMENT:
case FONT:
case SIZE:
case FONTBOUNDINGBOX:
case STARTPROPERTIES:
case _DEC_DEVICE_FONTNAMES:
case FONTNAME_REGISTRY:
case WEIGHT_NAME:
case SLANT:
case SETWIDTH_NAME:
case ADD_STYLE_NAME:
case PIXEL_SIZE:
case POINT_SIZE:
case RESOLUTION_X:
case RESOLUTION_Y:
case SPACING:
case AVERAGE_WIDTH:
case CHARSET_REGISTRY:
case CHARSET_ENCODING:
case CHARSET_COLLECTIONS:
case FULL_NAME:
case COPYRIGHT:
case FONT_ASCENT:
case FONT_DESCENT:
case CAP_HEIGHT:
case X_HEIGHT:
case ENDPROPERTIES:
case CHARS:
break;
case STARTCHAR:
/* Start a new character by mallocing a struct for
* it and putting the struct on the charstructlist
*/
charstruct = (charstruct_t *)
malloc(sizeof(charstruct_t));
charstructlist[charstructlistp] = charstruct;
charstructlistp++;
break;
case ENCODING:
parmptr = getnum(&i, parmptr);
charstruct->encoding = i;
break;
case SWIDTH:
parmptr = getnum(&i, parmptr);
charstruct->swidth1 = i;
parmptr = getnum(&i, parmptr);
charstruct->swidth2 = i;
break;
case DWIDTH:
parmptr = getnum(&i, parmptr);
charstruct->dwidth1 = i;
parmptr = getnum(&i, parmptr);
charstruct->dwidth2 = i;
break;
case BBX:
parmptr = getnum(&i, parmptr);
charstruct->bbx1 = i;
parmptr = getnum(&i, parmptr);
charstruct->bbx2 = i;
parmptr = getnum(&i, parmptr);
charstruct->bbx3 = i;
parmptr = getnum(&i, parmptr);
charstruct->bbx4 = i;
charstruct->offset = 0;
break;
case BITMAP:
nshorts = charstruct->bbx2*((charstruct->bbx1+15)/16);
charstruct->bitmap = (unsigned short*)
calloc(nshorts, sizeof(short));
for (i = nshorts-1; i >= 0; i--) {
gets(line);
len = strlen(line);
v = strtoul(line, NULL, 16);
switch (len) {
case 2:
charstruct->bitmap[i] = v << 8;
break;
case 4:
charstruct->bitmap[i] = v;
break;
case 6:
charstruct->bitmap[i] = (v<<8)&0xffff;
i--;
charstruct->bitmap[i] = v >> 8;
break;
case 8:
charstruct->bitmap[i] = v & 0xffff;
i--;
charstruct->bitmap[i] = v >> 16;
break;
}
}
break;
case ENDCHAR:
break;
case ENDFONT:
break;
default:
fprintf(stderr, "Unknown token\n");
exit(1);
break;
}
}
output:
printf("unsigned short %sData[] = {", FontName);
for (i = 0, offset = 0; i < charstructlistp; i++) {
charstruct = charstructlist[i];
if (!printable(charstruct->encoding))
continue;
charstruct->offset = offset;
nshorts = charstruct->bbx2*((charstruct->bbx1+15)/16);
offset += nshorts;
printf("\n\t\t\t\t\t\t\t\t/* char 0x%2.2x */\n",
charstruct->encoding);
printf("\t");
for (j = 0; j < nshorts; j++) {
printf("0x%4.4x, ", charstruct->bitmap[j]);
if (j % 7 == 6)
printf("\n\t");
}
}
printf("};\n\n");
printf("struct fontinfo %sInfo[] = {\n", FontName);
printf("#ifndef _STANDALONE\n{0,0,0,0,0,0},\n#endif\n");
for (i = 0; i < charstructlistp; i++){
charstruct = charstructlist[i];
if (!printable(charstruct->encoding))
continue;
if (charstruct->bbx2 > maxht)
maxht = charstruct->bbx2;
if (charstruct->bbx4 < maxds)
maxds = charstruct->bbx4;
printf("{%d, %d, %d, %d, %d, %d}, \t\t\t\t/* char 0x%2.2x */\n",
charstruct->offset,
charstruct->bbx1,
charstruct->bbx2,
charstruct->bbx3,
charstruct->bbx4,
charstruct->dwidth1,
charstruct->encoding);
}
printf("};\n\n");
printf("#define %s_ht\t%d\n",FontName,maxht);
printf("#define %s_ds\t%d\n",FontName,-maxds);
printf("#define %s_nc\t(sizeof(%sInfo)/sizeof(struct fontinfo))\n",
FontName,FontName);
printf("#define %s_nr\t(sizeof(%sData)/sizeof(short))\n",
FontName,FontName);
printf("#define %s_iso\t%d\n",FontName,(charstructlistp > 128));
}
char*
getnum(int *val, char *parmptr)
{
char *p;
*val = strtol(parmptr, &p, 10);
return p;
}
+142
View File
@@ -0,0 +1,142 @@
#!/bin/sh
#
# script to convert pcbm header file to an sgi .rgb file by creating a
# C program which includes the header pcbm file, which is compiled, and
# then spits out the .rgb file.
create_cfile () {
cat << EOF
/* temp file for frompcbm $1 */
#include <pcbm/pcbm.h>
#include <gl/image.h>
#define BLACK 0
#define RED 1
#define GREEN 2
#define YELLOW 3
#define BLUE 4
#define MAGENTA 5
#define CYAN 6
#define WHITE 7
#define BLACK2 8
#define RED2 9
#define GREEN2 10
#define YELLOW2 11
#define BLUE2 12
#define MAGENTA2 13
#define CYAN2 14
#define WHITE2 15
#define TP_IDX 16
#define VeryDarkGray 17
#define VeryLightGray 18
#define MediumGray 19
#define MACHCLR0 20
#define MACHCLR1 21
#define MACHCLR2 22
#define MACHCLR3 23
#define MACHCLR4 24
#include "$1.h"
int rgb[26] = {
0x000000, 0xff0000, 0x00ff00, 0xffff00,
0x0000ff, 0xff00ff, 0x00ffff, 0xffffff,
0x555555, 0xc67171, 0x71c671, 0x8e8e38,
0x7171c6, 0x8e388e, 0x388383, 0xaaaaaa,
0x606070, 0x2a2a2a, 0xd5d5d5, 0x808080,
#ifdef MACHCLR0_CLR
MACHCLR0_CLR,
#endif
#ifdef MACHCLR1_CLR
MACHCLR1_CLR,
#endif
#ifdef MACHCLR2_CLR
MACHCLR2_CLR,
#endif
#ifdef MACHCLR3_CLR
MACHCLR3_CLR,
#endif
#ifdef MACHCLR4_CLR
MACHCLR4_CLR,
#endif
0
};
short rdata[256][256];
short gdata[256][256];
short bdata[256][256];
main(int argc, char ** argv)
{
struct pcbm_node *p;
IMAGE *img;
int x,y;
for (y=0; y < 256; y++)
for (x = 0; x < 256; x++) {
rdata[y][x] = 210;
gdata[y][x] = 180;
bdata[y][x] = 140;
}
for (p=$2.bitlist; p->bits; p++) {
int r,g,b,c,spr,bx,by,i;
c = rgb[p->color];
r = (0xff0000 & c) >> 16;
g = (0x00ff00 & c) >> 8;
b = (0xff & c);
x = p->dx;
y = p->dy;
spr = (p->w-1)/16 + 1;
for (by=0; by < p->h; by++)
for (bx=0; bx < p->w; bx+=16)
for (i=0; i<16 && (bx+i) < p->w; i++)
if (p->bits[(by*spr)+(bx/16)] &
(1<<(15-i))) {
rdata[y+by][x+bx+i] = r;
gdata[y+by][x+bx+i] = g;
bdata[y+by][x+bx+i] = b;
}
}
img = iopen(argv[1],"w",RLE(1),3,$2.w,$2.h,3);
for (y=0; y < $2.h; y++) {
putrow(img,rdata[y],y,0);
putrow(img,gdata[y],y,1);
putrow(img,bdata[y],y,2);
}
iclose(img);
}
EOF
}
if [ -z "$1" ]
then
echo "usage: frompcbm filename [iconname]"
exit 1
fi
PCBMFILE=$1
BASENAME=`echo $1 | sed 's%\.h$%%'`
ICONNAME=${2:-$BASENAME}
RGBFILE=${BASENAME}.rgb
CONVBIN=frompcbm$$
CONVCFILE=${CONVBIN}.c
create_cfile $BASENAME $ICONNAME > $CONVCFILE
cc -I ${ROOT}/stand/arcs/include $CONVCFILE -limage -o $CONVBIN
if [ -x $CONVBIN ]
then
$CONVBIN $RGBFILE
fi
rm -f $CONVCFILE $CONVBIN
exit 0
+69
View File
@@ -0,0 +1,69 @@
#!/bin/sh
#
# script to convert scans header file to an sgi .rgb file by creating a
# C program which includes the header pcbm file, which is compiled, and
# then spits out the .rgb file.
create_cfile () {
cat << EOF
/* temp file for fromspans $1 */
#include <gl/image.h>
#include "$1.h"
short data[512][1280];
int
main(int argc, char ** argv)
{
char *p = clogo_data;
int px, y, i, ccol;
int w = clogo_w;
int h = clogo_h;
IMAGE *img;
for (y=0; y < clogo_h; y++) {
for (px=ccol=0; px < clogo_w; px += *p++) {
if (*p) {
for (i=px; i <= (px + *p - 1); i++)
data[y][i] = ccol ? 0 : 255;
}
ccol = !ccol;
}
}
img = iopen("spans.bw","w",RLE(1),3,clogo_w,clogo_h,1);
for (y=0; y < clogo_h; y++)
putrow(img,data[y],y,0);
iclose(img);
}
EOF
}
if [ -z "$1" ]
then
echo "usage: fromspans headername"
exit 1
fi
SPANFILE=$1
BASENAME=`echo $1 | sed 's%\.h$%%'`
RGBFILE=${BASENAME}.rgb
CONVBIN=tmp_fromspans$$
CONVCFILE=${CONVBIN}.c
create_cfile $BASENAME > $CONVCFILE
cc -g -I ${ROOT}/stand/arcs/include $CONVCFILE -limage -o $CONVBIN
if [ -x $CONVBIN ]
then
$CONVBIN $RGBFILE
fi
rm -f $CONVCFILE $CONVBIN
exit 0
+433
View File
@@ -0,0 +1,433 @@
#!/bin/sh
#
# gconf - generate config table for ARCS standalone libsk programs.
#
# usage: gconf [filename] [targetdir]
#
# Gconf generates a configuration table for built-in devices, filesystems,
# networks, and tuneable variables. The major use is to convey the
# inventory topology by listing device install routines, and their parent.
#
# Gconf will output filename.c (special case for file.cf -> file.c which
# should be the norm for co-existance with make). With no parameter it
# operates on file 'conf'.
#
# Note that all gconf directives (X[:!]) must be grouped together. Tables
# are now generated during parsing in order to allow cpp directives to work
# as expected.
#
# Gconf handles the following syntax (all commands start in column 0):
#
# *[...]
#
# This line is a comment.
#
# #[...]
#
# This line copied to the output file (to implement cpp directives).
#
# node: name [parent=nameofparent] [install=installname] \
# [gfxprobe=gfxprobename] [drvrinfo=drvriinfoname]
#
# This includes driver "name". Parent specifies the parent of
# this node. With no install routine will be called, but will
# cause the driver to be linked in. Gconf also takes the
# special parent of "root" to be a child of the system class.
# Install overides the default install routine of name_install().
# Gfxprobe is for graphics drivers who wish to interface with the
# textport. Drvrinfo is for drivers that let the system probe
# for their existance.
#
# node! name [rest of line is ignored]
#
# This excludes driver "name". It can be used as an alternative
# in some cases to commenting the line out with a '*'. However
# this has the additional effect of defining NO_name and including
# <sys/skpick.h>. This will allow drivers that export more than
# their install routine to be excluded.
#
# fs: name [install=installname]
#
# This includes filesystem "name". Install overides the default
# install routine name_install().
#
# fs! name [rest of line is ignored]
#
# This excludes filesystem "name" in the same manner as node!.
#
# if: nameprefix type description
#
# This includes if driver by using the probe, init, open and close
# routines with nameprefix appended to them. Type is usually IF_SGI
# (other values in stand/include/if.h). Description is the interface
# description string: SGI Integral IP1000 Enet Controller.
#
# if! [rest of line is ignored]
#
# Generate the necessary definitions such that linking can be done
# successfully even without an ethernet driver. This line will be
# ignored if there is a 'if:' somewhere else in the file.
#
# tune: [name value]
#
# This produces a #define name value, which should correspond
# to an entry in <tune.h>. The value given in the tune: statement
# will override the default value in <tune.h>. The special case
# of tune: with no arguements will cause <tune.h> to be included
# in the generated .c file to get all the default values.
#
# "$Revision: 1.17 $"
FILENAME=${1-conf}
TARGETDIR=${2-.}"/"
nawk -v TARGETDIR="$TARGETDIR" '
BEGIN {
# initialize flags and counters
tune = exclude = node = nodetouched = fstouched = iftouched = 0;
# Variables set when new context is done.
nodedone = 1; fsdone = 2; ifdone = 3
finished[nodedone] = finished[fsdone] = finished[ifdone] = 0
donei = 0
# Do not need any trailers yet.
finish=""
# Have at least one 'if:' entry
if_entry = 0
# Figure out filename for .c file. If the input filename ends in
# .cf, produce a .c file. Otherwise, just append .c to the end
# of the filename. Note .h file uses the same method.
cfile=TARGETDIR FILENAME
if (sub(".cf", ".c", cfile) != 1)
cfile = FILENAME ".c"
hfile=cfile
sub(".c$", ".h", hfile)
# Print header comment, and generate files
print "/* automatically generated config table */" > cfile
print "/* from " FILENAME " */" >>cfile
print "#include \"" hfile "\"" >>cfile
print "/* automatically generated config table header */" > hfile
print "/* from " FILENAME " */\n" >>hfile
}
/^\*.*$/ {
# skip comments (a comment must start in column 0).
continue
}
/^\#.*$/ {
# output lines starting with hash directly for cpp
print $0 >>cfile
continue
}
/^[ \t]*$/ {
# skip blank lines
continue
}
/^node:/ {
# matched a node: save nodename
nodes[node] = $2
# check if commands are grouped properly
if (finished[nodedone] == 1) {
print "error line " NR " -> node command " $2 " not grouped."
err = 1
continue
}
# look at rest of args to look for modifiers
gfx=drvr=parent=install=0
for (i=3; i <= NF; i++) {
if (match($i,"parent=") == 1)
parent = substr($i,RLENGTH+1,length($i)-RLENGTH)
else if (match($i,"install=") == 1)
install = substr($i,RLENGTH+1,length($i)-RLENGTH)
else if (match($i,"gfxprobe=") == 1)
gfx = substr($i,RLENGTH+1,length($i)-RLENGTH)
else if (match($i,"drvrinfo=") == 1)
drvr = substr($i,RLENGTH+1,length($i)-RLENGTH)
else {
print "error line " NR " -> " $i
err=1
continue
}
}
# If this is the first node, output the header.
if (nodetouched == 0) {
print finish >>cfile
finished[donei] = 1
print "#include <sys/types.h>" >>cfile
print "#include <standcfg.h>\n" >>cfile
print "struct standcfg standcfg[] = {" >>cfile
nodetouched=1
donei=nodedone
finish="\t0,0,0\n};\n"
}
if (install == 0)
routine = nodes[node] "_install"
else
routine = install
# output extern definition
print "extern int " routine "();" >>hfile
# output table entry
printf "\t%s,\t",routine >>cfile
if (parent == "root")
printf "(struct standcfg *)(__psunsigned_t)1" >>cfile
else if (parent == 0)
printf "(struct standcfg *)0" >>cfile
else {
for (i=0; i < node ; i++) {
if (nodes[i] == parent) {
printf "\t&standcfg[%d]",i >>cfile
break
}
}
if (i == node) {
print "parent " parent " not found."
err=1
continue
}
}
printf ",\t" >>cfile
if (gfx != 0) {
printf "%s", gfx >>cfile
print "extern void *" gfx "();" >>hfile
}
else
printf "\t0" >>cfile
printf ",\n#ifdef SLOTCONFIG\n\t" >>cfile
if (drvr != 0) {
printf "&%s", drvr >>cfile
print "extern struct drvrinfo_s " drvr ";" >>hfile
}
else
printf "0" >>cfile
printf ",\n#endif" >>cfile
print "\t\t\t/* " nodes[node] " */" >>cfile
node+=1
continue
}
/^node\!/ {
# check if commands are grouped properly
if (finished[nodedone] == 1) {
print "error line " NR " -> node command " $2 " not grouped."
err = 1
continue
}
# Node exclusion. Output #define, and note exclusion is used.
print "#define NO_" $2 >>cfile
# If this is the first node, output the header.
if (nodetouched == 0) {
print finish >>cfile
finished[donei] = 1
print "#include <standcfg.h>\n" >>cfile
print "struct standcfg standcfg[] = {" >>cfile
nodetouched=1
donei = nodedone
finish="\t0,0,0\n};\n"
} exclude=1
continue
}
/^fs:/ {
if (finished[fsdone] == 1) {
print "error line " NR " -> fs command " $2 " not grouped."
err = 1
continue
}
# Include a filesystem. Save Filesystem install
fs = $2 "_install"
# Look for modifiers (override install name)
for (i=3 ; i <= NF; i++) {
if (match($i,"install=") == 1)
fs = substr($i,RLENGTH+1,length($i)-RLENGTH)
else {
print "error line " NR " -> " $i
err=1
continue
}
}
# If this is the first fs, output the header.
if (fstouched == 0) {
print finish >>cfile
finished[donei] = 1
print "int (*_fs_table[])() = {" >>cfile
donei = fsdone;
fstouched=1
finish="\t0\n};\n"
}
# print the extern and then the filesystem entry
print "extern int " fs "();" >>hfile
print "\t" fs "," >>cfile
continue
}
/^fs\!/ {
# check if commands are grouped properly
if (finished[fsdone] == 1) {
print "error line " NR " -> fs command " $2 " not grouped."
err = 1
continue
}
# Exclude filesystem. Output #define, and not exclusion is used.
print "#define NO_" $2 >>cfile
# If this is the first fs, output the header.
if (fstouched == 0) {
print finish >>cfile
finished[donei] = 1
print "int (*_fs_table[])() = {" >>cfile
donei = fsdone
fstouched=1
finish="\t0\n};\n"
} exclude=1
continue
}
/^if:/ {
# check if commands are grouped properly
if (finished[ifdone] == 1) {
print "error line " NR " -> if command " $2 " not grouped."
err = 1
continue
}
# Network configuration. Parse it, and save it.
ifprefix = $2
iftype = $3
if (iftype == 0)
iftype = "IF_SGI"
ifdesc = $4
for (i = 5; i < NF ; i++)
ifdesc = ifdesc " " $i
if (ifdesc == 0)
ifdesc == ""
# output if header
if (iftouched == 0) {
print finish >>cfile
finished[donei] = 1
iftouched = 1;
donei = ifdone
}
if (if_entry == 0) {
print "#include <if.h>\n" >>cfile
print "struct if_func _if_func[] = {" >>cfile
finish = "};\n" \
"int _nifcs = " \
"(sizeof(_if_func)/sizeof(_if_func[0]));\n"
if_entry += 1;
}
# output extern definitions
print "extern void " ifprefix "init();\n"\
"extern int " ifprefix "probe();\n"\
"extern int " ifprefix "open();\n"\
"extern int " ifprefix "close();\n" >>hfile
# output current if
printf "\t{\n\t\t" >>cfile
print ifprefix "init, " ifprefix "probe, " ifprefix "open, " \
ifprefix "close," >>cfile
printf "\t\t%s,\t\"%s\"\n\t},\n", iftype, ifdesc >>cfile
continue
}
/^if\!/ {
# check if commands are grouped properly
if (finished[ifdone] == 1) {
print "error line " NR " -> if command " $2 " not grouped."
err = 1
continue
}
# output if header
if (iftouched == 0) {
print finish >>cfile
finished[donei] = 1
finish = "#include <if.h>\n" \
"struct if_func _if_func[1];\n" \
"int _nifcs = 0;\n"
iftouched = 1;
donei = ifdone
}
continue
}
/^tune:/ {
# tuning -- note that we are tuning.
tune = 1
# if no parameters just continue, since we already set the flag
if (NF == 1)
continue
# substitute tune: with #define.
sub("^tune:","#define",$0)
print $0 >>cfile
continue
}
{
# No match above -> error. Print message, set error
# flag to prevent .c generation at END, and let awk
# continue to look for more errors.
print "error line " NR " -> " $0
err=1
}
END {
# If there was a error exit with correct error code.
if (err == 1) {
system("rm -f " cfile " " hfile)
exit 1
}
# print last finish string
print finish >>cfile
# if exclusion is used, output #include
if (exclude != 0)
print "#include <sys/skpick.h>" >>cfile
# if tune is used, output #include
if (tune != 0)
print "#include <tune.h>" >>cfile
}
' $FILENAME
+74
View File
@@ -0,0 +1,74 @@
/*
* graytospans - convert a .bw image to spans
*/
#include "image.h"
#include "assert.h"
short buf[4096];
void
printone(short l)
{
static char digits[] = "0123456789abcdef";
static int rowcount = 0;
assert(l >= 0 && l <= 255);
fputs("0x", stdout);
putchar(digits[l >> 4]);
putchar(digits[l & 0xf]);
fputs(", ", stdout);
rowcount ++;
if (rowcount >= 8) {
fputs("\n\t", stdout);
rowcount = 0;
}
}
main(int argc, char **argv)
{
register IMAGE *image;
register int x, xsize;
register int y, ysize;
register int zsize;
if (argc < 2) {
fprintf(stderr, "usage: %s inimage.rgb\n", argv[0]);
exit(1);
}
if ((image = iopen(argv[1], "r")) == NULL ) {
fprintf(stderr, "readimg: can't open input file %s\n", argv[1]);
exit(1);
}
xsize = image->xsize;
ysize = image->ysize;
zsize = image->zsize;
if (zsize != 1) {
printf("Warning: Expecting a greyscale image in the 0-15 range\n");
}
printf("unsigned char clogo_data[] =\n{\n\t");
for (y = 0; y < ysize; y++) {
short ccolor = 1;
short currentlength = 0;
getrow(image, buf, y, 0);
for (x = 0; x < xsize; x++) {
short color = (buf[x] > 128) ? 1 : 0;
if (color != ccolor) {
printone(currentlength);
currentlength = 1;
ccolor = color;
} else if (currentlength == 255) {
printone(currentlength);
printone(0);
currentlength = 1;
} else
currentlength++;
}
if (currentlength)
printone(currentlength);
}
printf("};\n");
printf("int clogo_w = %d;\n", xsize);
printf("int clogo_h = %d;\n", ysize);
}
+105
View File
@@ -0,0 +1,105 @@
/*
* graytoxbm - convert a .bw image to xbitmap
*/
#include "image.h"
#include "assert.h"
short buf[4096];
void
printbits(short l, short c)
{
static char digits[] = "0123456789abcdef";
static int rowcount = 0;
static int leftover = 0;
static char leftbits = 0;
int i;
assert(l >= 0 && l <= 255);
if(leftover){
if(leftover + l < 8){
if(c){
for(i=leftover; i<leftover+l; i++){
leftbits |= 1 << i;
}
}
leftover += l;
return;
} else {
if(c){
for(i=leftover; i<8; i++){
leftbits |= 1 << i;
}
}
l = l - (8 - leftover);
leftover = 0;
fprintf(stdout, "0x%x, ", leftbits);
leftbits = 0;
rowcount++;
if(rowcount == 8){
fprintf(stdout, "\n\t");
rowcount= 0;
}
}
}
while(l >= 8){
fprintf(stdout, "%s, ", c ? "0xff" : "0x00");
rowcount ++;
if (rowcount >= 8) {
fputs("\n\t", stdout);
rowcount = 0;
}
l -= 8;
}
if(l){
leftover = l;
if(c){
for(i=0; i<l; i++){
leftbits |= 1 << i;
}
}
}
}
main(int argc, char **argv)
{
register IMAGE *image;
register int x, xsize;
register int y, ysize;
register int zsize;
if (argc < 2) {
fprintf(stderr, "usage: %s inimage.rgb\n", argv[0]);
exit(1);
}
if ((image = iopen(argv[1], "r")) == NULL ) {
fprintf(stderr, "readimg: can't open input file %s\n", argv[1]);
exit(1);
}
xsize = image->xsize;
ysize = image->ysize;
printf("#define clogo_width %d\n", xsize);
printf("#define clogo_height %d\n", ysize);
printf("static char clogo_bits[] =\n{\n\t");
for (y = ysize-1; y >= 0; y--) {
short ccolor = 1;
short currentlength = 0;
getrow(image, buf, y, 0);
for (x = 0; x < xsize; x++) {
short color = (buf[x] > 128) ? 1 : 0;
if (color != ccolor) {
printbits(currentlength, ccolor);
currentlength = 1;
ccolor = color;
} else if (currentlength == 255) {
printbits(currentlength, ccolor);
currentlength = 1;
} else
currentlength++;
}
if (currentlength)
printbits(currentlength, ccolor);
}
printf("};\n");
}
Binary file not shown.
Binary file not shown.
+246
View File
@@ -0,0 +1,246 @@
/*
* topcbm - convert a .rgb image prom color bitmap source
*/
#include <strings.h>
#include <image.h>
#include "assert.h"
short rbuf[1024];
short gbuf[1024];
short bbuf[1024];
unsigned short line[1024];
struct cdata {
int r,g,b;
int x1,y1,x2,y2;
int ref;
} cdata[128];
void checkcolor(int x, int y);
main(int argc, char **argv)
{
char imagename[256];
register IMAGE *image;
register int x, xsize;
register int y, ysize;
register int zsize;
long machclr[5];
int i;
char *p;
if (argc < 2) {
fprintf(stderr, "usage: %s inimage.rgb\n", argv[0]);
exit(1);
}
if ((image = iopen(argv[1], "r")) == NULL ) {
fprintf(stderr, "readimg: can't open input file %s\n", argv[1]);
exit(1);
}
strcpy(imagename,argv[1]);
p = strstr(imagename,".rgb");
if (p) *p = '\0';
xsize = image->xsize;
ysize = image->ysize;
zsize = image->zsize;
printf("/* prom color bitmap: %s */\n",imagename);
for (y = 0; y < ysize; y++) {
getrow(image, rbuf, y, 0);
getrow(image, gbuf, y, 1);
getrow(image, bbuf, y, 2);
for (x = 0; x < xsize; x++) {
checkcolor(x,y);
}
}
/* print bitmaps for each color */
for (i=0; cdata[i].ref; i++) {
int r = cdata[i].r;
int g = cdata[i].g;
int b = cdata[i].b;
int clr, j, tx, nsh, bit, idx;
char *cl;
switch (clr=(r<<16|g<<8|b)) {
case 0:
cl = "BLACK";
break;
case 0xff0000:
cl = "RED";
break;
case 0x00ff00:
cl = "GREEN";
break;
case 0xffff00:
cl = "YELLOW";
break;
case 0x0000ff:
cl = "BLUE";
break;
case 0xff00ff:
cl = "MAGENTA";
break;
case 0x00ffff:
cl = "CYAN";
break;
case 0xffffff:
cl = "WHITE";
break;
case 0x555555: /* DarkGray -- 85 */
cl = "BLACK2";
break;
case 0xc67171:
cl = "RED2";
break;
case 0x71c671: /* 113 198 113 */
cl = "GREEN2";
break;
case 0x8e8e38: /* 142 142 56 */
cl = "YELLOW2";
break;
case 0x7171c6: /* 113 113 198 */
cl = "BLUE2";
break;
case 0x883388: /* 136 51 136 uigrp */
case 0x8e388e: /* 142 56 142 */
cl = "MAGENTA2";
break;
case 0x388383: /* 56 131 131 */
cl = "CYAN2";
break;
case 0xaaaaaa:
cl = "WHITE2"; /* LightGray -- 170 */
break;
case 0xdddddd: /* 221 uigrp */
case 0xd5d5d5: /* 213 */
cl = "VeryLightGray";
break;
case 0x888888: /* 136 uigrp */
case 0x808080: /* 128 */
cl = "MediumGray";
break;
case 0x222222: /* 34 uigrp */
case 0x2a2a2a: /* 42 */
cl = "VeryDarkGray";
break;
case 0x606070: /* 96 96 112 */
cl = "TP_IDX";
break;
case 0x389279: /* Indigo2 */
case 0x013057: /* Indy */
case 0x082f4a: /* SR */
cl = "MACHCLR0";
machclr[0] = clr;
break;
case 0x097057: /* Indigo2 */
case 0x236fb4: /* Indy */
case 0x008b9b: /* SR */
cl = "MACHCLR1";
machclr[1] = clr;
break;
case 0x3fffbf: /* Indigo2 */
case 0x094575: /* Indy */
case 0x574763: /* SR */
cl = "MACHCLR2";
machclr[2] = clr;
break;
case 0x3f917f: /* Indigo2 */
cl = "MACHCLR3";
machclr[3] = clr;
break;
default:
cl = "XXX";
break;
}
printf("#define %s_%d_color %s /* %d %d %d */\n",
imagename,i,cl,r,g,b);
printf("unsigned short %s_%d_bits[] = {\n",imagename,i);
for (y=cdata[i].y1; y <= cdata[i].y2; y++) {
getrow(image,rbuf,y,0);
getrow(image,gbuf,y,1);
getrow(image,bbuf,y,2);
bzero(line,sizeof(line));
for (x=cdata[i].x1; x <= cdata[i].x2; x++) {
if ( (r == rbuf[x]) &&
(g == gbuf[x]) &&
(b == bbuf[x]) ) {
tx = x-cdata[i].x1;
idx = tx / 16;
bit = tx % 16;
line[idx] |= (1<<(15-bit));
}
}
bit = (cdata[i].x2-cdata[i].x1+1);
nsh = bit/16 + ((bit%16) != 0);
for (j=0; j < nsh; j++)
printf("0x%.4x, ",line[j]);
printf("\n");
}
printf("};\n");
}
/* dump node table */
printf("\nstruct pcbm_node %s_nodes[] = {\n",imagename);
for (i=0; cdata[i].ref; i++) {
printf("\t{%s_%d_color,%d,%d,%d,%d,%s_%d_bits},\n",
imagename,i,
cdata[i].x1,cdata[i].y1,
cdata[i].x2-cdata[i].x1+1,
cdata[i].y2-cdata[i].y1+1,
imagename,i);
}
printf("\t{0,0,0,0,0,0}\n};\n");
/* dump the main table */
printf("struct pcbm %s = {\n\t%d,\n\t%d,\n\t0,\n\t0,\n\t%s_nodes\n};\n",
imagename,
xsize,
ysize,
imagename);
/* dump mach dependent colors */
printf("\n");
for (i=0; i<5;i++) {
if (machclr[i])
printf("#define MACHCLR%d_CLR\t0x%x\n",i,machclr[i]);
}
}
void
checkcolor(int x, int y)
{
int i;
for (i=0; cdata[i].ref; i++) {
if ( (cdata[i].r == rbuf[x]) &&
(cdata[i].g == gbuf[x]) &&
(cdata[i].b == bbuf[x]) ) {
cdata[i].ref++;
/* update bounding box */
if (x < cdata[i].x1)
cdata[i].x1 = x;
else if (x > cdata[i].x2)
cdata[i].x2 = x;
if (y < cdata[i].y1)
cdata[i].y1 = y;
else if (y > cdata[i].y2)
cdata[i].y2 = y;
return;
}
}
cdata[i].ref = 1;
cdata[i].r = rbuf[x];
cdata[i].g = gbuf[x];
cdata[i].b = bbuf[x];
cdata[i].x1 = cdata[i].x2 = x;
cdata[i].y1 = cdata[i].y2 = y;
}
+101
View File
@@ -0,0 +1,101 @@
#include <stdio.h>
/*
* returns the hex digit with the bits reversed
*/
int
hextoi(char c)
{
switch (c) {
case '0': return 0x0;
case '1': return 0x8;
case '2': return 0x4;
case '3': return 0xc;
case '4': return 0x2;
case '5': return 0xa;
case '6': return 0x6;
case '7': return 0xe;
case '8': return 0x1;
case '9': return 0x9;
case 'a': return 0x5;
case 'b': return 0xd;
case 'c': return 0x3;
case 'd': return 0xb;
case 'e': return 0x7;
case 'f': return 0xf;
default:
fprintf(stderr, "xbmtohtpbm: bad hex number: %c\n", c);
return 0x0;
}
}
char
getbyte(FILE *in)
{
int c;
/* go to next zero (beginning of '0x') */
while ((c = fgetc(in)) != '0');
/* skip the x in '0x' */
fgetc(in);
c = hextoi(fgetc(in));
c |= hextoi(fgetc(in)) << 4;
return c;
}
main(int argc, char **argv)
{
FILE *in;
char line[80];
char name[32];
int width, height, shorts;
int sper, bper;
int x, y, i;
unsigned short *a;
if (argc == 2)
in = fopen(argv[1], "r");
else
in = stdin;
/* print #defines for width and height */
fputs(fgets(line, 80, in), stdout);
sscanf(line, "%*s%*s%d", &width);
fputs(fgets(line, 80, in), stdout);
sscanf(line, "%*s%*s%d", &height);
/* array definition */
fscanf(in, "%*s%*s%s%*s%*s", name);
printf("static unsigned short %s = {", name);
bper = (width + 7) / 8;
sper = (width + 15) / 16;
shorts = sper * height;
a = (unsigned short*)malloc(shorts*sizeof(short));
/* get data */
for (i = 0, y = 0; y < height; y++) {
for (x = bper; x > 0; x -= 2, i++) {
a[i] = getbyte(in) << 8;
if (x != 1)
a[i] |= getbyte(in);
}
}
/* print data */
printf("\n 0x%04x", a[(height-1)*sper]);
for (i = 1; i < sper; i++)
printf(", 0x%04x", a[(height-1)*sper+i]);
for (y = height-2; y >= 0; y--) {
for (x = 0; x < sper; x++, i++) {
printf(",");
printf((i % 8) ? " " : "\n ");
printf("0x%04x", a[y*sper+x]);
}
}
printf("};\n");
}
+156
View File
@@ -0,0 +1,156 @@
/*
* xbmtospans - xbitmap to spans converter
*/
#include <errno.h>
#include <stdio.h>
#include <ctype.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xmu/Drawing.h>
#include "image.h"
#include "assert.h"
char buf[4096];
static XImage image = {
0, 0, /* width, height */
0, XYBitmap, NULL, /* xoffset, format, data */
LSBFirst, 8, /* byte-order, bitmap-unit */
LSBFirst, 8, 1 /* bitmap-bit-order, bitmap-pad, depth */
};
void
getrowbits(buffer, yoff)
char *buffer;
int yoff;
{
char *bptr;
int ind = 0;
int i;
bptr = image.data + ((image.height - yoff - 1) * image.bytes_per_line);
bzero(buffer, image.width);
for(i=0; i<image.bytes_per_line; i++){
if((*bptr) & 0x1){
buffer[ind] = 0xff;
}
ind++;
if((*bptr) & 0x2){
buffer[ind] = 0xff;
}
ind++;
if((*bptr) & 0x4){
buffer[ind] = 0xff;
}
ind++;
if((*bptr) & 0x8){
buffer[ind] = 0xff;
}
ind++;
if((*bptr) & 0x10){
buffer[ind] = 0xff;
}
ind++;
if((*bptr) & 0x20){
buffer[ind] = 0xff;
}
ind++;
if((*bptr) & 0x40){
buffer[ind] = 0xff;
}
ind++;
if((*bptr) & 0x80){
buffer[ind] = 0xff;
}
ind++;
bptr++;
}
}
void
printone(short l)
{
static char digits[] = "0123456789abcdef";
static int rowcount = 0;
assert(l >= 0 && l <= 255);
fputs("0x", stdout);
putchar(digits[l >> 4]);
putchar(digits[l & 0xf]);
fputs(", ", stdout);
rowcount ++;
if (rowcount >= 8) {
fputs("\n\t", stdout);
rowcount = 0;
}
}
int ReadBitmapFile (filename)
char *filename;
{
unsigned int width, height;
int x_hot, y_hot;
unsigned char *data;
int status;
status = XmuReadBitmapDataFromFile (filename, &width, &height, &data,
&x_hot, &y_hot);
if (status != BitmapSuccess) return status;
image.width = width;
image.height = height;
image.data = (char *) data;
image.bytes_per_line = (image.width + 7) / 8;
return BitmapSuccess;
}
main(int argc, char **argv)
{
register int x;
register int y;
int status;
if(argc != 2){
fprintf(stderr, "Usage: xbmtospans <xbitmap file>\n");
exit(0);
}
status = ReadBitmapFile(argv[1]);
if (status != BitmapSuccess) {
fprintf (stderr, "%s: error reading input file \"%s\"\n",
argv[0], argv[1]);
exit (1);
}
printf("unsigned char clogo_data[] =\n{\n\t");
for (y = 0; y < image.height; y++) {
short ccolor = 1;
short currentlength = 0;
getrowbits(buf, y);
for (x = 0; x < image.width; x++) {
short color = buf[x] ? 1 : 0;
if (color != ccolor) {
printone(currentlength);
currentlength = 1;
ccolor = color;
} else if (currentlength == 255) {
printone(currentlength);
printone(0);
currentlength = 1;
} else
currentlength++;
}
if (currentlength)
printone(currentlength);
}
printf("};\n");
printf("int clogo_w = %d;\n", image.width);
printf("int clogo_h = %d;\n", image.height);
}