1 /*--------------------------------------------------------------------------------------------------
2   DataDraw is a CASE tool for generating data structures in C from simple descriptions.
3 --------------------------------------------------------------------------------------------------*/
4 #include <stdlib.h>
5 #include <string.h>
6 #include "htdatabase.h"
7 
8 htGraph htTheGraph;
9 
10 /*--------------------------------------------------------------------------------------------------
11   Create a new node.
12 --------------------------------------------------------------------------------------------------*/
htNodeCreate(char * name,int32 x,int32 y)13 htNode htNodeCreate(
14     char *name,
15     int32 x,
16     int32 y)
17 {
18     htNode node = htGraphFindNode(htTheGraph, x, y);
19     uint32 length = strlen(name) + 1;
20 
21     if(length > NAME_LENGTH) {
22 	utExit("Name %s is too long", name);
23     }
24     if(node != htNodeNull) {
25         utExit("Node %s is physically on top of node %s", name, htNodeGetName(node));
26     }
27     node = htNodeAlloc();
28     htNodeSetName(node, name, length);
29     htNodeSetX(node, x);
30     htNodeSetY(node, y);
31     htGraphInsertNode(htTheGraph, node);
32     return node;
33 }
34 
35 /*--------------------------------------------------------------------------------------------------
36   Read in the nodes from the text file.
37 --------------------------------------------------------------------------------------------------*/
readNodes(char * filename)38 static void readNodes(
39     char *filename)
40 {
41     char buffer[1024];
42     FILE *file = fopen(filename, "r");
43     htNode node;
44     int x, y;
45 
46     if(file == NULL) {
47         printf("Unable to open file %s\n", filename);
48         exit(1);
49     }
50     while(fscanf(file, "%s %d %d", buffer, &x, &y) == 3) {
51         node = htNodeCreate(buffer, x, y);
52     }
53     fclose(file);
54 }
55 
56 /*--------------------------------------------------------------------------------------------------
57   This is the actual main routine.
58 --------------------------------------------------------------------------------------------------*/
main(int argc,char ** argv)59 int main(
60     int argc,
61     char **argv)
62 {
63     utStart();
64     utInitLogFile("hash.log");
65     htDatabaseStart();
66     htTheGraph = htGraphAlloc();
67     readNodes(argv[1]);
68     htDatabaseStop();
69     utStop(false);
70     return 0;
71 }
72