Changeset 5850 for trunk/Ohana/src/opihi/lib.data/open_graph.c
- Timestamp:
- Dec 27, 2005, 3:21:40 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/lib.data/open_graph.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.data/open_graph.c
r4689 r5850 2 2 # define DEBUG 0 3 3 4 /** this list must match the one in kapa/include/structures.h, and equiv */ 5 # define NGRAPHCOLORS 23 6 static char GRAPHCOLORS[NGRAPHCOLORS][2][15] = { 7 {"black", "0.00 0.00 0.00"}, 8 {"white", "1.00 1.00 1.00"}, 9 {"red", "1.00 0.00 0.00"}, 10 {"pink", "1.00 0.75 0.80"}, 11 {"orange", "1.00 0.65 0.00"}, 12 {"yellow", "1.00 1.00 0.00"}, 13 {"wheat", "0.96 0.87 0.70"}, 14 {"gold", "1.00 0.84 0.00"}, 15 {"green", "0.00 1.00 0.00"}, 16 {"darkgreen","0.00 0.40 0.00"}, 17 {"blue", "0.00 0.00 1.00"}, 18 {"skyblue", "0.53 0.81 0.92"}, 19 {"indigo", "0.56 0.16 0.87"}, 20 {"violet", "1.00 0.00 0.00"}, 21 {"grey10", "0.10 0.10 0.10"}, 22 {"grey20", "0.20 0.20 0.20"}, 23 {"grey30", "0.30 0.30 0.30"}, 24 {"grey40", "0.40 0.40 0.40"}, 25 {"grey50", "0.50 0.50 0.50"}, 26 {"grey60", "0.60 0.60 0.60"}, 27 {"grey70", "0.70 0.70 0.70"}, 28 {"grey80", "0.80 0.80 0.80"}, 29 {"grey90", "0.90 0.90 0.90"}}; 30 31 /* we have space for several kapa windows */ 4 /* we have space for several kapa windows */ 32 5 # define NXGRAPH 5 33 6 … … 50 23 51 24 for (i = 0; i < NXGRAPH; i++) { 52 if (Xgraph[i] > 0) { 53 SendGraphCommand (Xgraph[i], 4, "QUIT"); 54 } 25 KiiClose (Xgraph[i]); 55 26 } 56 27 } … … 81 52 graphdata[i].flipeast = TRUE; 82 53 graphdata[i].flipnorth = FALSE; 54 strcpy (graphdata[i].axis, "2222"); 55 strcpy (graphdata[i].ticks, "2222"); 56 strcpy (graphdata[i].labels, "2222"); 83 57 } 84 58 } … … 94 68 int open_graph (int N) { 95 69 96 int InitSocket, status, addreslen, Ntry, fd; 97 char temp[128], socket_name[64], *kapa_exec; 98 struct sockaddr_un Address; 70 int fd; 71 char *kapa_exec; 99 72 100 73 kapa_exec = get_variable ("KAPA"); … … 104 77 } 105 78 106 sprintf (socket_name, "/tmp/Kapa.XXXXXX"); 107 if ((fd = mkstemp (socket_name)) == -1) { 79 fd = KiiOpen (kapa_exec, NULL); 80 81 if (fd < 0) { 108 82 fprintf (stderr, "error starting kapa\n"); 109 83 return (FALSE); 110 } 111 close (fd); 112 unlink (socket_name); 84 } 113 85 114 strcpy (Address.sun_path, socket_name); 115 Address.sun_family = AF_UNIX; 116 InitSocket = socket (AF_UNIX, SOCK_STREAM, 0); 117 status = bind (InitSocket, (struct sockaddr *) &Address, sizeof (Address)); 118 status = listen (InitSocket, 1); 119 120 sprintf (temp, "%s %s &", kapa_exec, socket_name); 121 free (kapa_exec); 122 123 # if DEBUG 124 fprintf (stderr, "start kapa, press return: %s\n", temp); 125 fscanf (stdin, "%d", &i); 126 # else 127 system (temp); 128 # endif 129 130 addreslen = sizeof (Address); 131 fcntl (InitSocket, F_SETFL, O_NONBLOCK); 132 133 # define NTRY 200 134 Ntry = 0; 135 while (Ntry < NTRY) { 136 Xgraph[N] = accept (InitSocket, (struct sockaddr *)&Address, &addreslen); 137 if (Xgraph[N] == -1) { 138 if (errno == EAGAIN) { 139 usleep (10000); 140 Ntry ++; 141 } else { 142 Ntry = NTRY; 143 } 144 } else { 145 Ntry = NTRY; 146 } 147 } 148 if (Xgraph[N] < 0) { 149 fprintf (stderr, "error starting kapa\n"); 150 return (FALSE); 151 } else { 152 fcntl (Xgraph[N], F_SETFL, !O_NONBLOCK); 153 return (TRUE); 154 } 155 86 Xgraph[N] = fd; 87 return (TRUE); 156 88 } 157 89 … … 226 158 graphdata[Active] = data; 227 159 } 228 229 int GetColor (char *name) {230 231 int i;232 233 for (i = 0; i < NGRAPHCOLORS; i++) {234 if (!strcmp (name, GRAPHCOLORS[i][0])) {235 return (i);236 }237 }238 fprintf (stderr, "color may be one of:\n");239 for (i = 0; i < NGRAPHCOLORS; i++) {240 fprintf (stderr, " %s\n", GRAPHCOLORS[i][0]);241 }242 return (-1);243 }244 245 int SendLabel (char *string, int Xgraph, int mode) {246 247 SendGraphCommand (Xgraph, 4, "LABL");248 SendGraphCommand (Xgraph, 16, "%6d %6d", strlen (string), mode);249 write (Xgraph, string, strlen (string));250 return (TRUE);251 }252 253 /* send a message of arbitrary size, sending the size first */254 int SendGraphMessage (int device, char *format, ...) {255 256 int Nbyte, status;257 char tmp;258 va_list argp;259 260 va_start (argp, format);261 Nbyte = vsnprintf (&tmp, 0, format, argp);262 va_end (argp);263 264 if (!Nbyte) return (FALSE);265 266 va_start (argp, format);267 SendGraphCommand (device, 16, "NBYTES: %6d", Nbyte);268 status = SendGraphCommandV (device, Nbyte, format, argp);269 va_end (argp);270 return (status);271 }272 273 int SendGraphCommand (int device, int length, char *format, ...) {274 275 int status;276 va_list argp;277 278 va_start (argp, format);279 status = SendGraphCommandV (device, length, format, argp);280 va_end (argp);281 return (status);282 }283 284 int SendGraphCommandV (int device, int length, char *format, va_list argp) {285 286 char *string;287 288 /* I allocated and zero 1 extra byte */289 ALLOCATE (string, char, length + 1);290 memset (string, 0, length + 1);291 vsnprintf (string, length + 1, format, argp);292 293 /* fprintf (stderr, "msg: %s\n", string); */294 write (device, string, length);295 free (string);296 return (TRUE);297 }
Note:
See TracChangeset
for help on using the changeset viewer.
