1 /* hdb.c 1.1 (Berkeley) 83/07/09
2 *
3 * Copyright -C- 1982 Barry S. Roitblat
4 *
5 * This file contains database routines for the hard copy programs of the
6 * gremlin picture editor.
7 */
8
9 #include "gprint.h"
10
11
12 /* imports from c */
13
14 extern char *malloc();
15 extern char *strcpy();
16 extern char *sprintf();
17
18 /* imports from point.c */
19
20 extern POINT *PTInit();
21 extern POINT *PTMakePoint();
22
DBInit()23 ELT *DBInit()
24 /*
25 * This routine returns a pointer to an initialized database element
26 * which would be the only element in an empty list.
27 */
28
29 {
30 return(NULL);
31 } /* end DBInit */
32
DBCreateElt(type,pointlist,brush,size,text,db)33 ELT *DBCreateElt(type, pointlist, brush, size, text, db)
34 int type, brush, size;
35 POINT *pointlist;
36 char *text;
37 ELT *(*db) ;
38 /*
39 * This routine creates a new element with the specified attributes and
40 * links it into database.
41 */
42
43 {
44 register ELT *temp;
45
46 temp = (ELT *) malloc(sizeof(ELT));
47 temp->nextelt = *db;
48 temp->type = type;
49 temp->ptlist = pointlist;
50 temp->brushf = brush;
51 temp->size = size;
52 temp->textpt = text;
53 *db = temp;
54 return(temp);
55 } /* end CreateElt */
56
DBRead(file,orient,pos)57 ELT *DBRead(file, orient, pos)
58 register FILE *file;
59 int *orient;
60 POINT *pos;
61 /*
62 * This routine reads the specified file into a database and
63 * returns a pointer to that database. Orient and pos are also set
64 * from the file.
65 */
66
67 {
68 register int i;
69 register int done;
70 ELT *elist;
71 POINT *plist;
72 char string[100], *txt;
73 float x, y;
74 int len, type, brush, size;
75
76 elist = DBInit();
77 (void) fscanf(file,"%s",string);
78 if (strcmp(string, "gremlinfile")) {
79 fprintf(stderr, "not gremlin file\n");
80 return(elist);
81 }
82 (void) fscanf(file, "%d%f%f", orient, &x, &y);
83 pos->x = x;
84 pos->y = y;
85
86 done = FALSE;
87 while (!done) {
88 if (fscanf(file,"%d", &type) == EOF) {
89 fprintf(stderr, "error in file format\n");
90 return(elist);
91 }
92 if (type < 0) { /* no more data */
93 done = TRUE;
94 (void) fclose(file);
95 } else {
96 (void) fscanf(file, "%f%f", &x, &y);
97 plist = PTInit();
98 while ((x != -1) && (y != -1)) { /* pointlist terminated by -1,-1 */
99 (void) PTMakePoint(x, y, &plist);
100 (void) fscanf(file, "%f%f", &x, &y);
101 }
102 (void) fscanf(file, "%d%d", &brush, &size);
103 (void) fscanf(file, "%d", &len);
104 txt = malloc((unsigned) len + 1);
105 (void) getc(file); /* throw away space character */
106 for (i=0; i<len; ++i) {
107 txt[i] = getc(file);
108 }
109 txt[len] = '\0';
110 (void) DBCreateElt(type, plist, brush, size, txt, &elist);
111 } /* end else */
112 } /* end while not done */;
113 return(elist);
114 } /* end DBRead */
115
116