/* hdb.c 1.8 (Berkeley) 84/10/20
* Copyright -C- 1982 Barry S. Roitblat
* This file contains database routines for the hard copy programs of the
* gremlin picture editor.
/* imports from main.c */
extern int linenum
; /* current line number in input file */
extern char gremlinfile
[]; /* name of file currently reading */
extern int SUNFILE
; /* TRUE if SUN gremlin file */
/* imports from point.c */
extern POINT
*PTMakePoint();
* This routine returns a pointer to an initialized database element
* which would be the only element in an empty list.
* This routine creates a new element with the specified attributes and
* links it into database.
DBCreateElt(type
, pointlist
, brush
, size
, text
, db
)
temp
= (ELT
*) malloc(sizeof(ELT
));
temp
->ptlist
= pointlist
;
* This routine reads the specified file into a database and
* returns a pointer to that database.
register int done
; /* flag for input exhausted */
register float nx
; /* x holder so x is not set before orienting */
int type
; /* element type */
ELT
*elist
; /* pointer to the file's elements */
POINT
*plist
; /* pointer for reading in points */
char string
[MAXSTRING
], *txt
;
float x
, y
; /* x and y are read in point coords */
(void) fscanf(file
,"%s\n",string
);
if (strcmp(string
, "gremlinfile")) {
if (strcmp(string
, "sungremlinfile")) {
error("%s is not a gremlin file", gremlinfile
);
(void) fscanf(file
, "%d%f%f\n", &size
, &x
, &y
);
/* ignore orientation and file positioning point */
if (fscanf(file
,"%s\n", string
) == EOF
) {
error("%s, error in file format", gremlinfile
);
type
= DBGetType(string
); /* interpret element type */
if (type
< 0) { /* no more data */
(void) fscanf(file
, "%f%f\n", &x
, &y
); /* always one point */
plist
= PTInit(); /* NULL point list */
/* Files created on the SUN have point lists terminated
* by a line containing only an asterik ('*'). Files
* created on the AED have point lists terminated by the
* coordinate pair (-1.00 -1.00).
if (TEXT(type
)) { /* read only first point for TEXT elements */
(void) PTMakePoint(nx
, y
, &plist
);
fgets(string
, MAXSTRING
, file
);
if (string
[0] == '*') { /* SUN gremlin file */
(void) sscanf(string
, "%f%f", &x
, &y
);
if ((x
== -1.00 && y
== -1.00) && (!SUNFILE
))
else { /* not TEXT element */
(void) PTMakePoint(nx
, y
, &plist
);
fgets(string
, MAXSTRING
, file
);
if (string
[0] == '*') { /* SUN gremlin file */
(void) sscanf(string
, "%f%f", &x
, &y
);
if ((x
== -1.00 && y
== -1.00) && (!SUNFILE
))
(void) fscanf(file
, "%d%d\n", &brush
, &size
);
(void) fscanf(file
, "%d", &len
); /* text length */
(void) getc(file
); /* eat blank */
txt
= malloc((unsigned) len
+ 1);
for (i
=0; i
<len
; ++i
) { /* read text */
(void) DBCreateElt(type
, plist
, brush
, size
, txt
, &elist
);
} /* end while not done */;
* Interpret element type in string s.
* Old file format consisted of integer element types.
* New file format has literal names for element types.
if (isdigit(s
[0]) || (s
[0] == '-')) /* old element format or EOF */
error("unknown element type");
error("unknown element type");
error("unknown element type");
error("unknown element type");