Jspice3
graphdb.c File Reference
#include "spice.h"
#include "ftegraph.h"
#include "ftedebug.h"
Include dependency graph for graphdb.c:

Go to the source code of this file.

Data Structures

struct  listgraph
 
struct  gbucket
 
struct  gcstack
 

Macros

#define NULL   ((char*)0)
 
#define NEWLISTGRAPH   (LISTGRAPH *) calloc(1, sizeof(LISTGRAPH))
 
#define NUMGBUCKETS   16
 
#define SETGRAPH(pgraph, id)
 
#define NEWGCSTACK   (GCSTACK *) calloc(1, sizeof(GCSTACK))
 

Typedefs

typedef struct listgraph LISTGRAPH
 
typedef struct gbucket GBUCKET
 
typedef struct gcstack GCSTACK
 

Functions

GRAPHNewGraph ()
 
GRAPHFindGraph (int id)
 
GRAPHCopyGraph (GRAPH *graph)
 
int DestroyGraph (int id)
 
void FreeGraphs ()
 
void SetGraphContext (int graphid)
 
void PushGraphContext (GRAPH *graph)
 
void PopGraphContext ()
 

Variables

GRAPHcurrentgraph
 
int numgraphcxsw
 
static GBUCKET GBucket [NUMGBUCKETS]
 
static RunningId = 1
 
GCSTACKgcstacktop
 

Macro Definition Documentation

#define NEWGCSTACK   (GCSTACK *) calloc(1, sizeof(GCSTACK))

Definition at line 240 of file graphdb.c.

#define NEWLISTGRAPH   (LISTGRAPH *) calloc(1, sizeof(LISTGRAPH))

Definition at line 38 of file graphdb.c.

#define NULL   ((char*)0)

Definition at line 17 of file graphdb.c.

#define NUMGBUCKETS   16

Definition at line 40 of file graphdb.c.

#define SETGRAPH (   pgraph,
  id 
)
Value:
(pgraph)->graphid = (id); \
(pgraph)->degree = 1; \
(pgraph)->linestyle = -1
static char * linestyle[]
Definition: plot5.c:17
static int graphid
Definition: check.c:23

Definition at line 53 of file graphdb.c.

Typedef Documentation

typedef struct gbucket GBUCKET
typedef struct gcstack GCSTACK
typedef struct listgraph LISTGRAPH

Function Documentation

GRAPH* CopyGraph ( GRAPH graph)

Definition at line 113 of file graphdb.c.

116 {
117  GRAPH *ret;
118  struct _keyed *k;
119 
120  ret = NewGraph();
121  bcopy(graph, ret, sizeof(struct graph));
122 
123  ret->graphid = RunningId - 1; /* restore id */
124 
125  /* copy keyed */
126  for (ret->keyed = NULL, k = graph->keyed; k; k = k->next) {
127  SaveText(ret, k->text, k->x, k->y);
128  }
129  ret->plotdata = (GRDATA)NULL;
130  if (graph->copydata)
131  ret->plotdata = (*graph->copydata)((GRDATA)graph->plotdata);
132 
133  ret->commandline = copy(graph->commandline);
134  ret->plotname = copy(graph->plotname);
135 
136  return (ret);
137 }
char * GRDATA
Definition: ftegraph.h:26
struct _keyed * next
Definition: ftegraph.h:129
GRDATA(* copydata)()
Definition: ftegraph.h:72
char * copy()
void SaveText()
int graphid
Definition: ftegraph.h:30
GRDATA plotdata
Definition: ftegraph.h:33
Definition: ftegraph.h:29
struct graph::_keyed * keyed
char * plotname
Definition: ftegraph.h:35
char * commandline
Definition: ftegraph.h:133
void bcopy(char *from, char *to, int num)
Definition: string.c:339
GRAPH * NewGraph()
Definition: graphdb.c:59
#define NULL
Definition: graphdb.c:17
static RunningId
Definition: graphdb.c:50
int DestroyGraph ( int  id)

Definition at line 141 of file graphdb.c.

144 {
145 
146  LISTGRAPH *list, *lastlist;
147  struct _keyed *k, *nextk;
148  extern struct dbcomm *dbiplot;
149  struct dbcomm *db;
150 
151  list = GBucket[id % NUMGBUCKETS].list;
152  lastlist = NULL;
153 
154  while (list) {
155  if (list->graph.graphid == id) { /* found it */
156 
157  /* Fix the iplot/trace dbiplot list */
158  for (db = dbiplot;
159  db && db->db_graphid != id; db = db->db_next) ;
160 
161  if (db && db->db_type == DB_IPLOT) {
162  db->db_type = DB_DEADIPLOT;
163  /* Delete this later */
164  return (0);
165  }
166 
167  /* adjust bucket pointers */
168  if (lastlist) {
169  lastlist->next = list->next;
170  }
171  else {
172  GBucket[id % NUMGBUCKETS].list = list->next;
173  }
174 
175  /* run through and de-allocate dynamically allocated keyed list */
176  k = list->graph.keyed;
177  while (k) {
178  nextk = k->next;
179  txfree(k->text);
180  txfree((char*)k);
181  k = nextk;
182  }
183 
184  if (list->graph.destroy)
185  (*list->graph.destroy)((GRDATA)list->graph.plotdata);
186  list->graph.plotdata = (GRDATA)NULL;
187 
188  tfree(list->graph.commandline);
189  tfree(list->graph.plotname);
190 
191  /* If device dependent space allocated, free it. */
192  if (list->graph.devdep)
193  txfree(list->graph.devdep);
194  txfree((char*)list);
195 
196  return (1);
197  }
198  lastlist = list;
199  list = list->next;
200  }
201 
202  internalerror("tried to destroy non-existent graph");
203  return (0);
204 }
struct dbcomm * dbiplot
Definition: main.c:186
static GBUCKET GBucket[NUMGBUCKETS]
Definition: graphdb.c:47
char * GRDATA
Definition: ftegraph.h:26
GRAPH graph
Definition: graphdb.c:35
int db_graphid
Definition: ftedebug.h:26
internalerror(char *message)
Definition: error.c:91
#define NUMGBUCKETS
Definition: graphdb.c:40
struct _keyed * next
Definition: ftegraph.h:129
struct listgraph * next
Definition: graphdb.c:36
char db_type
Definition: ftedebug.h:22
#define tfree(x)
Definition: cdmacs.h:22
void txfree()
int graphid
Definition: ftegraph.h:30
GRDATA plotdata
Definition: ftegraph.h:33
struct dbcomm * db_next
Definition: ftedebug.h:28
struct graph::_keyed * keyed
char * plotname
Definition: ftegraph.h:35
void(* destroy)()
Definition: ftegraph.h:71
char * devdep
Definition: ftegraph.h:144
#define DB_DEADIPLOT
Definition: ftedebug.h:18
Definition: dir.c:53
char * commandline
Definition: ftegraph.h:133
#define NULL
Definition: graphdb.c:17
#define DB_IPLOT
Definition: ftedebug.h:16
LISTGRAPH * list
Definition: graphdb.c:43
GRAPH* FindGraph ( int  id)

Definition at line 93 of file graphdb.c.

97 {
98  LISTGRAPH *list;
99 
100  for (list = GBucket[id % NUMGBUCKETS].list;
101  list && list->graph.graphid != id;
102  list = list->next)
103  ;
104 
105  if (list)
106  return (&list->graph);
107  else
108  return (NULL);
109 }
static GBUCKET GBucket[NUMGBUCKETS]
Definition: graphdb.c:47
GRAPH graph
Definition: graphdb.c:35
#define NUMGBUCKETS
Definition: graphdb.c:40
struct listgraph * next
Definition: graphdb.c:36
int graphid
Definition: ftegraph.h:30
Definition: dir.c:53
#define NULL
Definition: graphdb.c:17
void FreeGraphs ( )

Definition at line 208 of file graphdb.c.

211 {
212  GBUCKET *gbucket;
213  LISTGRAPH *list, *deadl;
214 
215  for (gbucket = GBucket; gbucket < &GBucket[NUMGBUCKETS]; gbucket++) {
216  list = gbucket->list;
217  while (list) {
218  deadl = list;
219  list = list->next;
220  txfree((char*)deadl);
221  }
222  }
223 }
static GBUCKET GBucket[NUMGBUCKETS]
Definition: graphdb.c:47
#define NUMGBUCKETS
Definition: graphdb.c:40
struct listgraph * next
Definition: graphdb.c:36
void txfree()
Definition: dir.c:53
LISTGRAPH * list
Definition: graphdb.c:43
GRAPH* NewGraph ( )

Definition at line 59 of file graphdb.c.

62 {
63 
64  GRAPH *pgraph;
65  LISTGRAPH *list;
66  int BucketId = RunningId % NUMGBUCKETS;
67 
68  if (!(list = NEWLISTGRAPH)) {
69  internalerror("can't allocate a listgraph");
70  return ((GRAPH *) NULL);
71  }
72 
73  pgraph = &list->graph;
74  SETGRAPH(pgraph, RunningId);
75 
76  if (!GBucket[BucketId].list) {
77  GBucket[BucketId].list = list;
78  }
79  else {
80  /* insert at front of current list */
81  list->next = GBucket[BucketId].list;
82  GBucket[BucketId].list = list;
83  }
84 
85  RunningId++ ;
86 
87  return (pgraph);
88 
89 }
static GBUCKET GBucket[NUMGBUCKETS]
Definition: graphdb.c:47
GRAPH graph
Definition: graphdb.c:35
#define SETGRAPH(pgraph, id)
Definition: graphdb.c:53
internalerror(char *message)
Definition: error.c:91
#define NUMGBUCKETS
Definition: graphdb.c:40
struct listgraph * next
Definition: graphdb.c:36
#define NEWLISTGRAPH
Definition: graphdb.c:38
Definition: ftegraph.h:29
Definition: dir.c:53
#define NULL
Definition: graphdb.c:17
LISTGRAPH * list
Definition: graphdb.c:43
static RunningId
Definition: graphdb.c:50
void PopGraphContext ( )

Definition at line 270 of file graphdb.c.

272 {
273  GCSTACK *dead;
274 
276  dead = gcstacktop;
278  txfree((char*)dead);
279  numgraphcxsw++;
280 }
GRAPH * currentgraph
Definition: graphdb.c:21
int numgraphcxsw
Definition: graphdb.c:24
struct gcstack * next
Definition: graphdb.c:237
GCSTACK * gcstacktop
Definition: graphdb.c:239
void txfree()
GRAPH * pgraph
Definition: graphdb.c:236
void PushGraphContext ( GRAPH graph)

Definition at line 250 of file graphdb.c.

253 {
255 
256  if (!gcstacktop) {
257  gcstacktop = gcstack;
258  }
259  else {
260  gcstack->next = gcstacktop;
261  gcstacktop = gcstack;
262  }
264  currentgraph = graph;
265  numgraphcxsw++;
266 }
GRAPH * currentgraph
Definition: graphdb.c:21
int numgraphcxsw
Definition: graphdb.c:24
#define NEWGCSTACK
Definition: graphdb.c:240
struct gcstack * next
Definition: graphdb.c:237
GCSTACK * gcstacktop
Definition: graphdb.c:239
GRAPH * pgraph
Definition: graphdb.c:236
void SetGraphContext ( int  graphid)

Definition at line 227 of file graphdb.c.

230 {
232 }
GRAPH * currentgraph
Definition: graphdb.c:21
GRAPH * FindGraph(int id)
Definition: graphdb.c:93
static int graphid
Definition: check.c:23

Variable Documentation

GRAPH* currentgraph

Definition at line 21 of file graphdb.c.

GBUCKET GBucket[NUMGBUCKETS]
static

Definition at line 47 of file graphdb.c.

GCSTACK* gcstacktop

Definition at line 239 of file graphdb.c.

int numgraphcxsw

Definition at line 24 of file graphdb.c.

RunningId = 1
static

Definition at line 50 of file graphdb.c.