1 /**********
2 Copyright 1990 Regents of the University of California.  All rights reserved.
3 Author: 1986 Wayne A. Christopher, U. C. Berkeley CAD Group
4 Modified 1999 Emmanuel Rouat
5 **********/
6 
7 /*
8  *   faustus@cad.berkeley.edu, ucbvax!faustus
9  * Permission is granted to modify and re-distribute this code in any manner
10  * as long as this notice is preserved.  All standard disclaimers apply.
11  *
12  * Toss the help window up on the screen, and deal with the graph...
13  */
14 
15 #include "ngspice/ngspice.h"
16 #include "ngspice/cpstd.h"
17 #include "ngspice/hlpdefs.h"
18 #include "ngspice/suffix.h"
19 
20 bool hlp_usex = FALSE;
21 
22 
23 void
hlp_provide(topic * top)24 hlp_provide(topic *top)
25 {
26     toplink *res;
27     topic *parent, *newtop;
28 
29     if (!top)
30         return;
31 
32 #ifndef X_DISPLAY_MISSING
33     if (getenv("DISPLAY") || hlp_displayname)
34         hlp_usex = TRUE;
35 #endif
36 
37     top->xposition = top->yposition = 0;
38     if (hlp_usex) {
39         if (!hlp_xdisplay(top)) {
40             fprintf(stderr, "Couldn't open X display.\n");
41             return;
42         }
43     } else {
44         if (!hlp_tdisplay(top)) {
45             fprintf(stderr, "Couldn't display text\n");
46             return;
47         }
48     }
49 
50 #ifndef X_DISPLAY_MISSING       /* X11 does this asynchronously */
51     if (hlp_usex)
52         return;
53 #endif
54 
55     for (;;) {
56         if (hlp_usex)
57             res = hlp_xhandle(&parent);
58         else
59             res = hlp_thandle(&parent);
60         if (!res && !parent) {
61             /* No more windows. */
62             hlp_killfamily(top);
63             if (hlp_usex)
64                 hlp_xclosedisplay(); /* need to change
65                                         display pointer back J.H. */
66             return;
67         }
68         if (res) {
69             /* Create a new window... */
70             if (hlp_usex)
71                 hlp_xwait(parent, TRUE);
72             if ((newtop = hlp_read(res->place)) == NULL) {
73                 fprintf(stderr, "Internal error: bad link\n");
74                 hlp_xwait(parent, FALSE);
75                 continue;
76             }
77             if (hlp_usex)
78                 hlp_xwait(parent, FALSE);
79             newtop->next = parent->children;
80             parent->children = newtop;
81             newtop->parent = parent;
82             newtop->xposition = parent->xposition + 50;
83             newtop->yposition = parent->yposition + 50;
84             if (hlp_usex) {
85                 if (!hlp_xdisplay(newtop)) {
86                     fprintf(stderr, "Couldn't open win\n");
87                     return;
88                 }
89             } else {
90                 if (!hlp_tdisplay(newtop)) {
91                     fprintf(stderr, "Couldn't display\n");
92                     return;
93                 }
94             }
95         } else {
96             /* Blow this one and its descendants away. */
97             hlp_killfamily(parent);
98             hlp_fixchildren(parent);
99             if (parent == top)
100                 return;
101         }
102     }
103 }
104 
105 
106 void
hlp_fixchildren(topic * parent)107 hlp_fixchildren(topic *parent)
108 {
109 
110     topic *pa;
111 
112     if (parent->parent) {
113         if (parent->parent->children == parent)
114             parent->parent->children = parent->next;
115         else {
116             for (pa = parent->parent->children; pa->next; pa = pa->next)
117                 if (pa->next == parent)
118                     break;
119             if (!pa->next)
120                 fprintf(stderr, "bah...\n");
121             pa->next = pa->next->next;
122         }
123     }
124 }
125 
126 
127 /* Note that this doesn't actually free the data structures, just gets
128  * rid of the window.
129  */
130 
131 void
hlp_killfamily(topic * top)132 hlp_killfamily(topic *top)
133 {
134     topic *ch;
135 
136     for (ch = top->children; ch; ch = ch->next)
137         hlp_killfamily(ch);
138 
139     if (hlp_usex)
140         hlp_xkillwin(top);
141     else
142         hlp_tkillwin(top);
143 
144     top->children = NULL;
145 }
146 
147