1 /******************************************************************************
2 *
3 * NSSDC/CDF CDFedit, auxiliary routines.
4 *
5 * Version 1.4b, 14-Dec-97, Hughes STX.
6 *
7 * Modification history:
8 *
9 * V1.0 19-Nov-93, J Love Original version.
10 * V1.0a 4-Feb-94, J Love DEC Alpha/OpenVMS port.
11 * V1.1 15-Dec-94, J Love CDF V2.5.
12 * V1.1a 23-Jan-95, J Love IRIX 6.x (64-bit).
13 * V1.1b 28-Feb-95, J Love Pass `char' as `int'.
14 * V1.2 21-Mar-95, J Love POSIX.
15 * V1.2a 18-Apr-95, J Love More POSIX.
16 * V1.3 6-Sep-95, J Love CDFexport-related changes. FSI key
17 * definitions.
18 * V1.4 26-Aug-96, J Love CDF V2.6.
19 * V1.4a 21-Feb-97, J Love Removed RICE.
20 * V1.4b 14-Dec-97, J Love Added ALPHAVMSi encoding.
21 * V3.3 10-Apr-09, M Liu Changed "MAC" to "PPC" for encoding.
22 *
23 ******************************************************************************/
24
25 #include "cdfedit.h"
26
27 /******************************************************************************
28 * InitializeScreen.
29 ******************************************************************************/
30
InitializeScreen()31 void InitializeScreen () {
32 create_pasteboard ();
33 set_cursor_mode (CURSORoff);
34 return;
35 }
36
37 /******************************************************************************
38 * CleanupScreen.
39 ******************************************************************************/
40
CleanupScreen()41 void CleanupScreen () {
42 delete_pasteboard (ERASE);
43 set_cursor_mode (CURSORon);
44 return;
45 }
46
47 /******************************************************************************
48 * ReportStatus.
49 ******************************************************************************/
50
ReportStatus(status,center)51 Logical ReportStatus (status, center)
52 CDFstatus status;
53 Logical center;
54 {
55 if ((StatusINFO(status) && report[INFOs]) ||
56 (StatusWARN(status) && report[WARNs]) ||
57 (StatusERROR(status) && report[ERRORs])) CDFstatusWindow (status,center);
58 return StatusOK(status);
59 }
60
61 /******************************************************************************
62 * CDFstatusWindow.
63 ******************************************************************************/
64
CDFstatusWindow(status,center)65 void CDFstatusWindow (status, center)
66 CDFstatus status;
67 Logical center;
68 {
69 static char text[CDF_STATUSTEXT_LEN+1];
70 CDFlib (SELECT_, CDF_STATUS_, status,
71 GET_, STATUS_TEXT_, text,
72 NULL_);
73 ProblemWindow (text, center);
74 return;
75 }
76
77 /******************************************************************************
78 * ProblemWindow.
79 ******************************************************************************/
80
ProblemWindow(message,center)81 void ProblemWindow (message, center)
82 char *message;
83 Logical center;
84 {
85 static int exitChars[] = { NUL };
86 static struct EditWindowStruct EW = {
87 " Enter any key to acknowledge... ", 0, 0, 0, 0, NULL, NULL, 1, 0,
88 NULL, FALSE, TRUE, exitChars, REFRESHkey_FSI, NUL, NUL, NUL, NUL, NUL,
89 NUL, NUL, NUL, NUL
90 };
91 if (center) {
92 EW.nColsTotal = MaxInt ((int)(strlen(EW.label) + 4),
93 (int)(strlen(message) + 2));
94 EW.ULrow = (SCREEN_HEIGHT - 3) / 2;
95 EW.ULcol = (SCREEN_WIDTH - EW.nColsTotal) / 2;
96 }
97 else {
98 EW.nColsTotal = SCREEN_WIDTH;
99 EW.ULrow = SCREEN_HEIGHT - 3;
100 EW.ULcol = 0;
101 }
102 EW.eText = message;
103 EditWindow (NEWew, &EW, LogicalTRUE);
104 EditWindow (BEEPew, &EW);
105 EditWindow (READew, &EW);
106 EditWindow (DELETEew, &EW);
107 return;
108 }
109
110 /******************************************************************************
111 * MessageWindow.
112 *
113 * void MessageWindow (char **lineS, Terminate with a NUL-string ("").
114 * char *label,
115 * Logical block);
116 *
117 ******************************************************************************/
118
119 #if defined(STDARG)
MessageWindow(char ** lineS,...)120 void MessageWindow (char **lineS, ...)
121 #else
122 void MessageWindow (va_alist)
123 va_dcl
124 #endif
125 {
126 #if !defined(STDARG)
127 char **lineS;
128 #endif
129 static int exitChars[] = { NUL };
130 static struct EditWindowStruct EW = {
131 NULL, 0, 0, 0, 0, NULL, NULL, 0, 0, NULL, FALSE, TRUE, exitChars,
132 REFRESHkey_FSI, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL
133 };
134 va_list ap;
135 #if defined(STDARG)
136 va_start (ap, lineS);
137 #else
138 VA_START (ap);
139 lineS = va_arg (ap, char **);
140 #endif
141 if (lineS == NULL) {
142 EditWindow (DELETEew, &EW);
143 cdf_FreeMemory (EW.eText, FatalError);
144 }
145 else {
146 int lineN; size_t textLength;
147 char *label = va_arg (ap, char *);
148 Logical block = va_arg (ap, Logical);
149 EW.nColsTotal = BOO(label == NULL,0,strlen(label)+4);
150 for (textLength = 0, lineN = 0; !NULstring(lineS[lineN]); lineN++) {
151 size_t length = strlen (lineS[lineN]);
152 EW.nColsTotal = MaxInt (EW.nColsTotal, (int) (length + 2));
153 textLength += length + 1;
154 }
155 EW.eText = (char *) cdf_AllocateMemory (textLength + 1, FatalError);
156 MakeNUL (EW.eText);
157 for (lineN = 0; !NULstring(lineS[lineN]); lineN++) {
158 strcatX (EW.eText, lineS[lineN], textLength);
159 strcatX (EW.eText, "\n", textLength);
160 }
161 EW.NeRows = lineN;
162 EW.label = label;
163 EW.ULrow = 5;
164 EW.ULcol = (SCREEN_WIDTH - EW.nColsTotal) / 2;
165 EditWindow (NEWew, &EW, LogicalTRUE);
166 if (block) EditWindow (READew, &EW);
167 }
168 va_end (ap);
169 return;
170 }
171
172 /******************************************************************************
173 * ConfirmWindow.
174 ******************************************************************************/
175
ConfirmWindow(rowN,width,question1,question2,yesInitial,helpId)176 Logical ConfirmWindow (rowN, width, question1, question2, yesInitial, helpId)
177 int rowN;
178 int width;
179 char *question1;
180 char *question2; /* If NULL, a one line question. */
181 Logical yesInitial; /* If TRUE, <YES> is initial current item. */
182 int helpId;
183 {
184 static char label[] = " Confirmation ";
185 static char *header[] = { NULL, NULL };
186 AOSs1 (trailer, "Select: ________ Exit: ________ Help: ________")
187 static char *items[] = {
188 "",
189 " <Yes> <No>",
190 ""
191 };
192 static int iLineNs[] = { 1, 1 };
193 static int iCols[] = { 18, 53 };
194 static int iLens[] = { 5, 4 };
195 static int exitChars[] = { ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL };
196 static struct ItemWindowStruct IWt = {
197 0, 0, 0, label, 0, header, 3, items, 2, iLineNs, iCols, iLens, 3,
198 1, trailer, exitChars, REFRESHkey_FSI, FALSE
199 };
200 Logical answer;
201 EncodeKeyDefinitions (1, trailer, ENTERkey_FSI, EXITkey_FSI,
202 HELPkey_FSI);
203 IWt.hLines[0] = question1;
204 IWt.NhLines = 1;
205 if (question2 != NULL) {
206 header[1] = question2;
207 IWt.NhLines = 2;
208 }
209 IWt.ULrow = rowN;
210 IWt.ULcol = (SCREEN_WIDTH - width) / 2;
211 IWt.nColsTotal = width;
212 ItemWindow (NEWiw, &IWt, BOO(yesInitial,0,1));
213 if (EnterIW(&IWt,helpId))
214 switch (IWt.itemN) {
215 case 0:
216 answer = TRUE;
217 break;
218 case 1:
219 answer = FALSE;
220 break;
221 }
222 else
223 answer = FALSE;
224 ItemWindow (DELETEiw, &IWt);
225 return answer;
226 }
227
228 /******************************************************************************
229 * ConfirmWindow2.
230 ******************************************************************************/
231
ConfirmWindow2(rowN,width,question1,question2,yesInitial,helpId)232 Logical ConfirmWindow2 (rowN, width, question1, question2, yesInitial, helpId)
233 int rowN;
234 int width;
235 char *question1;
236 char *question2; /* If NULL, a one line question. */
237 Logical yesInitial; /* If TRUE, <YES> is initial current item. */
238 int helpId;
239 {
240 static char label[] = " Confirmation ";
241 static char *header[] = { NULL, NULL };
242 AOSs1 (trailer, "Select: ________ Exit: ________ Help: ________")
243 static char *items1[] = {
244 "",
245 " <Yes> <No>",
246 ""
247 };
248 static char *items2[] = {
249 "",
250 " <Yes to V3> <Yes to V2> <No>",
251 ""
252 };
253 static int iLineNs1[] = { 1, 1 };
254 static int iLineNs2[] = { 1, 1, 1 };
255 static int iCols[2];
256 static int iLens[2];
257 static int iCols1[] = { 18, 53 };
258 static int iLens1[] = { 5, 4 };
259 static int iCols2[] = { 11, 30, 53 };
260 static int iLens2[] = { 11, 11, 4 };
261 static int exitChars[] = { ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL };
262 static struct ItemWindowStruct IWt;
263 static struct ItemWindowStruct IWt1 = {
264 0, 0, 0, label, 0, header, 3, items1, 2, iLineNs1, iCols1, iLens1, 3,
265 1, trailer, exitChars, REFRESHkey_FSI, FALSE
266 };
267 static struct ItemWindowStruct IWt2 = {
268 0, 0, 0, label, 0, header, 3, items2, 3, iLineNs2, iCols2, iLens2, 3,
269 1, trailer, exitChars, REFRESHkey_FSI, FALSE
270 };
271 Logical answer;
272 EncodeKeyDefinitions (1, trailer, ENTERkey_FSI, EXITkey_FSI,
273 HELPkey_FSI);
274 if (CDFgetFileBackwardEnvVar() == 1)
275 IWt = IWt1;
276 else
277 IWt = IWt2;
278
279 IWt.hLines[0] = question1;
280 IWt.NhLines = 1;
281 if (question2 != NULL) {
282 header[1] = question2;
283 IWt.NhLines = 2;
284 }
285 IWt.ULrow = rowN;
286 IWt.ULcol = (SCREEN_WIDTH - width) / 2;
287 IWt.nColsTotal = width;
288 ItemWindow (NEWiw, &IWt, 0);
289 if (EnterIW(&IWt,helpId)) {
290 if (CDFgetFileBackwardEnvVar() == 1) {
291 switch (IWt.itemN) {
292 case 0:
293 answer = TRUE;
294 break;
295 case 1:
296 answer = FALSE;
297 break;
298 }
299 } else {
300 switch (IWt.itemN) {
301 case 0:
302 answer = TRUE;
303 CDFsetFileBackward(BACKWARDFILEoff);
304 break;
305 case 1:
306 answer = TRUE;
307 CDFsetFileBackward(BACKWARDFILEon);
308 break;
309 case 2:
310 answer = FALSE;
311 break;
312 }
313 }
314 } else
315 answer = FALSE;
316 ItemWindow (DELETEiw, &IWt);
317 return answer;
318 }
319
320 /******************************************************************************
321 * EnterIW.
322 ******************************************************************************/
323
EnterIW(IW,helpId)324 Logical EnterIW (IW, helpId)
325 struct ItemWindowStruct *IW;
326 int helpId;
327 {
328 for (;;) {
329 ItemWindow (READiw, IW);
330 switch (IW->key) {
331 case EXITkey_FSI:
332 return FALSE;
333 case ENTERkey_FSI:
334 return TRUE;
335 case HELPkey_FSI:
336 OnlineHelpWindow (ilhFile, helpId);
337 break;
338 }
339 }
340 }
341
342 /******************************************************************************
343 * EnterPW.
344 ******************************************************************************/
345
EnterPW(PW,helpId)346 Logical EnterPW (PW, helpId)
347 struct PromptWindowStruct *PW;
348 int helpId;
349 {
350 for (;;) {
351 PromptWindow (READiw, PW);
352 switch (PW->key) {
353 case EXITkey_FSI:
354 return FALSE;
355 case ENTERkey_FSI:
356 return TRUE;
357 case HELPkey_FSI:
358 OnlineHelpWindow (ilhFile, helpId);
359 break;
360 }
361 }
362 }
363
364 /******************************************************************************
365 * IndexInList.
366 ******************************************************************************/
367
IndexInList(match,nItems,items)368 int IndexInList (match, nItems, items)
369 char *match;
370 int nItems;
371 char **items;
372 {
373 int i;
374 for (i = 0; i < nItems; i++) if (!strcmp(match,items[i])) return i;
375 return -1;
376 }
377
378 /******************************************************************************
379 * DataTypeItemN.
380 ******************************************************************************/
381
DataTypeItemN(dataType)382 int DataTypeItemN (dataType)
383 long dataType;
384 {
385 static char *symbols[] = { DTiwSYMBOLS };
386 static int colums[] = { DTiwCOLs };
387 static int lineNs[] = { DTiwLINEnS };
388 static int lengths[] = { DTiwLENs };
389 char token[11+1]; /* Assumes `CDF_EPOCH16' is longest data type token. */
390 int itemN; char *symbol;
391 for (itemN = 0; itemN < 15; itemN++) {
392 strcpyX (token, "CDF_", 11);
393 strcatX (token, DataTypeToken(dataType), 11);
394 symbol = &(symbols[lineNs[itemN]][colums[itemN]]);
395 if (!strncmp(token,symbol,lengths[itemN])) return itemN;
396 }
397 return 0;
398 }
399
400 /******************************************************************************
401 * ShowFullName.
402 ******************************************************************************/
403
ShowFullName(name,attr)404 void ShowFullName (name, attr)
405 char *name;
406 Logical attr; /* TRUE: attribute, FALSE: variable. */
407 {
408 AOSs6 (lineS, " ",BLANKs78," "," Enter any key to continue... "," ","")
409 size_t length = strlen (name);
410 char delim = PickDelimiter (name, length);
411 sprintf (lineS[1], " %c%s%c ", delim, name, delim);
412 MessageWindow (lineS, BOO(attr,"Full attribute name...",
413 "Full variable name..."), LogicalTRUE);
414 MessageWindow (NULL);
415 return;
416 }
417
418 /******************************************************************************
419 * SelectMajority.
420 ******************************************************************************/
421
SelectMajority()422 Logical SelectMajority () {
423 long majority; int itemN; CDFstatus status;
424 static char *header[] = { "Select new majority..." };
425 AOSs1 (trailer, "Select: ________ Exit: ________ Help: ________")
426 static char *items[] = { "ROW", "COLUMN" };
427 static int iLineNs[] = { 0, 1 };
428 static int iCols[] = { 0, 0 };
429 static int iLens[] = { 3, 6 };
430 static int exitChars[] = { ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL };
431 static struct ItemWindowStruct IWt = {
432 12, 0, 80, NULL, 1, header, 2, items, 2, iLineNs, iCols, iLens, 3, 1,
433 trailer, exitChars, REFRESHkey_FSI, FALSE
434 };
435 EncodeKeyDefinitions (1, trailer, ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI);
436 status = CDFlib (GET_, CDF_MAJORITY_, &majority,
437 NULL_);
438 if (!ReportStatus(status,FALSE)) return FALSE;
439 for (itemN = 0; itemN < 2; itemN++) {
440 if (!strcmp(MajorityToken(majority),IWt.iLines[itemN])) break;
441 }
442 ItemWindow (NEWiw, &IWt, itemN);
443 for (;;) {
444 if (EnterIW(&IWt,MAJORITYhelpID)) {
445 long majority = WhichMajority(items[IWt.itemN]);
446 status = CDFlib (PUT_, CDF_MAJORITY_, majority,
447 NULL_);
448 if (ReportStatus(status,FALSE)) {
449 ItemWindow (DELETEiw, &IWt);
450 return TRUE;
451 }
452 if (NoMoreAccess(NULL)) {
453 ItemWindow (DELETEiw, &IWt);
454 return FALSE;
455 }
456 }
457 else
458 break;
459 }
460 ItemWindow (DELETEiw, &IWt);
461 return TRUE;
462 }
463
464 /******************************************************************************
465 * SelectFormat.
466 ******************************************************************************/
467
SelectFormat()468 Logical SelectFormat () {
469 long format; int itemN; CDFstatus status;
470 static char *header[] = { "Select new format..." };
471 AOSs1 (trailer, "Select: ________ Exit: ________ Help: ________")
472 static char *items[] = { "SINGLE", "MULTI" };
473 static int iLineNs[] = { 0, 1 };
474 static int iCols[] = { 0, 0 };
475 static int iLens[] = { 6, 5 };
476 static int exitChars[] = { ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL };
477 static struct ItemWindowStruct IWt = {
478 12, 0, 80, NULL, 1, header, 2, items, 2, iLineNs, iCols, iLens, 3, 1,
479 trailer, exitChars, REFRESHkey_FSI, FALSE
480 };
481 EncodeKeyDefinitions (1, trailer, ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI);
482 status = CDFlib (GET_, CDF_FORMAT_, &format,
483 NULL_);
484 if (!ReportStatus(status,FALSE)) return FALSE;
485 for (itemN = 0; itemN < 2; itemN++) {
486 if (!strcmp(FormatToken(format),IWt.iLines[itemN])) break;
487 }
488 ItemWindow (NEWiw, &IWt, itemN);
489 for (;;) {
490 if (EnterIW(&IWt,FORMAThelpID)) {
491 format = WhichFormat(items[IWt.itemN]);
492 status = CDFlib (PUT_, CDF_FORMAT_, format,
493 NULL_);
494 if (ReportStatus(status,FALSE)) {
495 ItemWindow (DELETEiw, &IWt);
496 return TRUE;
497 }
498 if (NoMoreAccess(NULL)) {
499 ItemWindow (DELETEiw, &IWt);
500 return FALSE;
501 }
502 }
503 else
504 break;
505 }
506 ItemWindow (DELETEiw, &IWt);
507 return TRUE;
508 }
509
510 /******************************************************************************
511 * SelectEncoding.
512 ******************************************************************************/
513
SelectEncoding()514 Logical SelectEncoding () {
515 long encoding; int itemN; CDFstatus status;
516 static char *header[] = { "Select new encoding..." };
517 AOSs1 (trailer, "Select: ________ Exit: ________ Help: ________")
518 static char *items[] = {
519 "HOST SUN IBMPC SGi HP ALPHAVMSg ALPHAVMSi DECSTATION",
520 "NETWORK VAX IBMRS PPC NeXT ALPHAVMSd ALPHAOSF1"
521 };
522 static int iLineNs[] = { 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1 };
523 static int iCols[] = { 0,10,16,24,30,37,49,61,0,10,16,24,30,37,49 };
524 static int iLens[] = { 4,3,5,3,2,9,9,10,7,3,5,3,4,9,9 };
525 static int exitChars[] = { ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL };
526 static struct ItemWindowStruct IWt = {
527 12, 0, 80, NULL, 1, header, 2, items, 15, iLineNs, iCols, iLens, 3, 1,
528 trailer, exitChars, REFRESHkey_FSI, FALSE
529 };
530 char selectedEncoding[10+1], delim = ' ', *selected = NULL, *tmpStr;
531
532 EncodeKeyDefinitions (1, trailer, ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI);
533 status = CDFlib (GET_, CDF_ENCODING_, &encoding,
534 NULL_);
535 if (!ReportStatus(status,FALSE)) return FALSE;
536 for (itemN = 0; itemN < 15; itemN++) {
537 if (!strncmp(EncodingToken(encoding),
538 &(IWt.iLines[IWt.iLineNs[itemN]][IWt.iCols[itemN]]),
539 IWt.iLens[itemN])) break;
540 }
541 ItemWindow (NEWiw, &IWt, itemN);
542 for (;;) {
543 if (EnterIW(&IWt,ENCODINGhelpID)) {
544 tmpStr = &items[iLineNs[IWt.itemN]][iCols[IWt.itemN]];
545 selected = strchr(tmpStr, delim);
546 if (selected != NULL)
547 strcpyX (selectedEncoding, tmpStr, selected - tmpStr);
548 else
549 strcpyX (selectedEncoding, tmpStr, strlen(tmpStr));
550 encoding = WhichEncoding(selectedEncoding);
551 status = CDFlib (PUT_, CDF_ENCODING_, encoding,
552 NULL_);
553 if (ReportStatus(status,FALSE)) {
554 ItemWindow (DELETEiw, &IWt);
555 return TRUE;
556 }
557 if (NoMoreAccess(NULL)) {
558 ItemWindow (DELETEiw, &IWt);
559 return FALSE;
560 }
561 }
562 else
563 break;
564 }
565 ItemWindow (DELETEiw, &IWt);
566 return TRUE;
567 }
568
569 /******************************************************************************
570 * SelectSparseness.
571 ******************************************************************************/
572
SelectSparseness(zVar,changed)573 Logical SelectSparseness (zVar, changed)
574 Logical zVar;
575 Logical *changed; /* Assumed initialized to FALSE by caller. */
576 {
577 long sRecordsType; CDFstatus status; static Logical first = TRUE;
578 static char *header[] = { "Select sparseness..." };
579 AOSs1 (trailer, "Select: ________ Exit: ________ Help: ________")
580 static char *items[] = {
581 "sRecords.NO sRecords.PAD sRecords.PREV"
582 };
583 static int iLineNs[] = { 0,0,0 };
584 static int iCols[] = { 0,16,33 };
585 static int iLens[] = { 11,12,13 };
586 static int exitChars[] = { ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL };
587 static struct ItemWindowStruct IWt = {
588 14, 0, 80, NULL, 1, header, 1, items, 3, iLineNs, iCols, iLens, 1, 1,
589 trailer, exitChars, REFRESHkey_FSI, TRUE
590 };
591 static long sRecordsTypes[] = {
592 NO_SPARSERECORDS, PAD_SPARSERECORDS, PREV_SPARSERECORDS
593 };
594 if (first) {
595 EncodeKeyDefinitions (1, trailer, ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI);
596 first = FALSE;
597 }
598 ItemWindow (NEWiw, &IWt, 0);
599 for (;;) {
600 if (EnterIW(&IWt,SPARSENESShelpID)) {
601 sRecordsType = sRecordsTypes[IWt.itemN];
602 status = CDFlib (PUT_, BOO(zVar,zVAR_SPARSERECORDS_,
603 rVAR_SPARSERECORDS_), sRecordsType,
604 NULL_);
605 if (ReportStatus(status,FALSE)) {
606 ItemWindow (DELETEiw, &IWt);
607 ASSIGNnotNULL (changed, TRUE)
608 return TRUE;
609 }
610 if (NoMoreAccess(NULL)) {
611 ItemWindow (DELETEiw, &IWt);
612 return FALSE;
613 }
614 }
615 else {
616 ItemWindow (DELETEiw, &IWt);
617 return TRUE;
618 }
619 }
620 }
621
622 /******************************************************************************
623 * SelectCompression.
624 ******************************************************************************/
625
SelectCompression(forWhat,row,changed)626 Logical SelectCompression (forWhat, row, changed)
627 int forWhat;
628 int row;
629 Logical *changed; /* Assumed initialized to FALSE by caller. */
630 {
631 long cType, cParms[CDF_MAX_PARMS], compressionItem;
632 CDFstatus status; static Logical first = TRUE;
633 static char *header[] = { "Select compression..." };
634 AOSs1 (trailer, "Select: ________ Exit: ________ Help: ________")
635 static char *items[] = {
636 "None RLE.0 HUFF.0 AHUFF.0 GZIP..."
637 };
638 static int iLineNs[] = { 0,0,0,0,0 };
639 static int iCols[] = { 0,9,19,30,42 };
640 static int iLens[] = { 4,5,6,7,7 };
641 static int exitChars[] = { ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL };
642 static struct ItemWindowStruct IW = {
643 0, 0, 80, NULL, 1, header, 1, items, nCOMPRESSIONs, iLineNs, iCols,
644 iLens, 1, 1, trailer, exitChars, REFRESHkey_FSI, TRUE
645 };
646 if (first) {
647 EncodeKeyDefinitions (1, trailer, ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI);
648 first = FALSE;
649 }
650 switch (forWhat) {
651 case FORCDF: compressionItem = CDF_COMPRESSION_; break;
652 case FORzVAR: compressionItem = zVAR_COMPRESSION_; break;
653 case FORrVAR: compressionItem = rVAR_COMPRESSION_; break;
654 }
655 IW.ULrow = row;
656 ItemWindow (NEWiw, &IW, 0);
657 for (;;) {
658 if (EnterIW(&IW,BOO(forWhat == FORCDF,
659 CDFCOMPRESSIONhelpID,
660 VARCOMPRESSIONhelpID))) {
661 switch (IW.itemN) {
662 case NOcompressionIN:
663 cType = NO_COMPRESSION;
664 break;
665 case RLE0compressionIN:
666 cType = RLE_COMPRESSION;
667 cParms[0] = RLE_OF_ZEROs;
668 break;
669 case HUFF0compressionIN:
670 cType = HUFF_COMPRESSION;
671 cParms[0] = OPTIMAL_ENCODING_TREES;
672 break;
673 case AHUFF0compressionIN:
674 cType = AHUFF_COMPRESSION;
675 cParms[0] = OPTIMAL_ENCODING_TREES;
676 break;
677 case GZIPcompressionIN: {
678 static char *gzipHeader[] = {
679 "Syntax: GZIP.<1|2|3|4|5|6|7|8|9>"
680 };
681 AOSs1A (gzipTrailer,
682 "Enter: ________ Exit: ________ Help: ________")
683 static char token[MAX_GZIP_TOKEN_LEN+1];
684 static Logical gzipFirst = TRUE;
685 static int gzipExit[] = {
686 ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL
687 };
688 static struct PromptWindowStruct PW = {
689 "Enter GZIP compression parameters...", 0, 0, 80, 1, gzipHeader,
690 MAX_GZIP_TOKEN_LEN, token, 1, gzipTrailer, gzipExit,
691 REFRESHkey_FSI, SOLkey_FSI, EOLkey_FSI, INSERTorOVERkey_FSI
692 };
693 if (gzipFirst) {
694 EncodeKeyDefinitions (1, gzipTrailer,
695 ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI);
696 strcpyX (PW.value, "GZIP.", MAX_GZIP_TOKEN_LEN);
697 gzipFirst = FALSE;
698 }
699 PW.ULrow = row;
700 PromptWindow (NEWpw, &PW, (int) strlen(PW.value), LogicalTRUE);
701 for (;;) {
702 if (EnterPW(&PW,GZIPhelpID)) {
703 int level;
704 if (sscanf(PW.value,"GZIP.%d",&level) == 1) {
705 if (INCLUSIVE(1,level,9)) {
706 cType = GZIP_COMPRESSION;
707 cParms[0] = level;
708 PromptWindow (DELETEpw, &PW);
709 break;
710 }
711 else
712 ProblemWindow ("Illegal GZIP level.", FALSE);
713 }
714 else
715 ProblemWindow ("Illegal GZIP parameter.", FALSE);
716 }
717 else {
718 PromptWindow (DELETEpw, &PW);
719 ItemWindow (DELETEiw, &IW);
720 return TRUE;
721 }
722 }
723 break;
724 }
725 }
726 ItemWindow (UNDISPLAYiw, &IW);
727 if (forWhat == FORCDF) {
728 AOSs2 (compressingLines, "Changing compression...", "")
729 MessageWindow (compressingLines, NULL, LogicalFALSE);
730 zzzzz (1.0);
731 }
732 status = CDFlib (PUT_, compressionItem, cType, cParms,
733 NULL_);
734 if (forWhat == FORCDF) MessageWindow (NULL);
735 if (ReportStatus(status,FALSE)) {
736 ItemWindow (DELETEiw, &IW);
737 if (forWhat == FORCDF) compressed = (cType != NO_COMPRESSION);
738 ASSIGNnotNULL (changed, TRUE)
739 return TRUE;
740 }
741 if (NoMoreAccess(NULL)) {
742 ItemWindow (DELETEiw, &IW);
743 return FALSE;
744 }
745 ItemWindow (REDISPLAYiw, &IW);
746 }
747 else {
748 ItemWindow (DELETEiw, &IW);
749 return TRUE;
750 }
751 }
752 }
753
754 /******************************************************************************
755 * SelectDataSpec.
756 ******************************************************************************/
757
SelectDataSpec(dataType,numElems,label)758 Logical SelectDataSpec (dataType, numElems, label)
759 long *dataType; /* If NO_DATATYPE, start at item number 0. */
760 long *numElems; /* If NULL, don't prompt for number of elements. */
761 char *label; /* If NULL, no label. */
762 {
763 static char *header[] = { "Select data type..." };
764 static char *items[] = { DTiwSYMBOLS };
765 AOSs1 (trailer, "Select: ________ Exit: ________ Help: ________")
766 static int iLineNs[] = { DTiwLINEnS };
767 static int iCols[] = { DTiwCOLs };
768 static int iLens[] = { DTiwLENs };
769 static int exitChars[] = { ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL };
770 static struct ItemWindowStruct IWt = {
771 4, 1, 78, NULL, 1, header, 3, items, 15, iLineNs, iCols, iLens, 3, 1,
772 trailer, exitChars, REFRESHkey_FSI, FALSE
773 };
774 static Logical first = TRUE; int itemN;
775 char selectedDataType[11+1], delim = ' ', *selected = NULL, *tmpStr;
776 if (first) {
777 EncodeKeyDefinitions (1, trailer, ENTERkey_FSI, EXITkey_FSI,
778 HELPkey_FSI);
779 first = FALSE;
780 }
781 IWt.label = label;
782 itemN = BOO(*dataType == NO_DATATYPE,0,DataTypeItemN(*dataType));
783 ItemWindow (NEWiw, &IWt, itemN);
784 if (EnterIW(&IWt,VARDATATYPEhelpID)) {
785 tmpStr = &items[iLineNs[IWt.itemN]][iCols[IWt.itemN]];
786 selected = strchr(tmpStr, delim);
787 if (selected != NULL)
788 strcpyX (selectedDataType, tmpStr, selected - tmpStr);
789 else
790 strcpyX (selectedDataType, tmpStr, strlen(tmpStr));
791 *dataType = WhichDataType(selectedDataType);
792 ItemWindow (DELETEiw, &IWt);
793 if (numElems == NULL) return TRUE;
794 if (STRINGdataType(*dataType)) {
795 return SelectNumElems(*dataType,numElems,label);
796 }
797 *numElems = 1;
798 return TRUE;
799 }
800 ItemWindow (DELETEiw, &IWt);
801 return FALSE;
802 }
803
804 /******************************************************************************
805 * SelectNumElems.
806 ******************************************************************************/
807
SelectNumElems(dataType,numElems,label)808 Logical SelectNumElems (dataType, numElems, label)
809 long dataType;
810 long *numElems;
811 char *label;
812 {
813 static char *headerCHAR[] = {
814 "Enter number of elements (characters) for CDF_CHAR data type..."
815 };
816 static char *headerUCHAR[] = {
817 "Enter number of elements (characters) for CDF_UCHAR data type..."
818 };
819 AOSs1 (trailer, "Enter: ________ Exit: ________ Help: ________")
820 static char value[MAX_NUMELEMS_LEN+1];
821 static int exitChars[] = { ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL };
822 static struct PromptWindowStruct PWt = {
823 NULL, 4, 1, 78, 1, NULL, MAX_NUMELEMS_LEN, value, 1, trailer, exitChars,
824 REFRESHkey_FSI, SOLkey_FSI, EOLkey_FSI, INSERTorOVERkey_FSI
825 };
826 static Logical first = TRUE; long tNumElems;
827 if (first) {
828 EncodeKeyDefinitions (1, trailer, ENTERkey_FSI, EXITkey_FSI,
829 HELPkey_FSI);
830 first = FALSE;
831 }
832 strcpyX (PWt.value, "", MAX_NUMELEMS_LEN);
833 PWt.hLines = BOO(dataType == CDF_CHAR,headerCHAR,headerUCHAR);
834 PWt.label = label;
835 PromptWindow (NEWpw, &PWt, 0, LogicalTRUE);
836 for (;;) {
837 if (EnterPW(&PWt,VARNUMELEMShelpID)) {
838 if (sscanf(PWt.value,"%ld",&tNumElems) == 1) {
839 if (tNumElems > 0) {
840 PromptWindow (DELETEpw, &PWt);
841 *numElems = tNumElems;
842 return TRUE;
843 }
844 else
845 ProblemWindow ("Illegal number of elements.", FALSE);
846 }
847 else
848 ProblemWindow ("Error decoding number of elements.", FALSE);
849 }
850 else {
851 PromptWindow (DELETEpw, &PWt);
852 return FALSE;
853 }
854 }
855 }
856
857 /******************************************************************************
858 * SelectChecksum.
859 ******************************************************************************/
860
SelectChecksum()861 Logical SelectChecksum () {
862 long checksum; int itemN; CDFstatus status;
863 static char *header[] = { "Select new checksum method..." };
864 AOSs1 (trailer, "Select: ________ Exit: ________ Help: ________")
865 static char *items[] = { "None", "MD5" };
866 static int iLineNs[] = { 0, 1 };
867 static int iCols[] = { 0, 0 };
868 static int iLens[] = { 4, 3 };
869 static int exitChars[] = { ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI, NUL };
870 static struct ItemWindowStruct IWt = {
871 12, 0, 80, NULL, 1, header, 2, items, 2, iLineNs, iCols, iLens, 3, 1,
872 trailer, exitChars, REFRESHkey_FSI, FALSE
873 };
874 EncodeKeyDefinitions (1, trailer, ENTERkey_FSI, EXITkey_FSI, HELPkey_FSI);
875 status = CDFlib (GET_, CDF_CHECKSUM_, &checksum,
876 NULL_);
877 if (!ReportStatus(status,FALSE)) return FALSE;
878 for (itemN = 0; itemN < 2; itemN++) {
879 if (!strcmp(ChecksumToken(checksum),IWt.iLines[itemN])) break;
880 }
881 ItemWindow (NEWiw, &IWt, itemN);
882 for (;;) {
883 if (EnterIW(&IWt,CHECKSUMhelpID)) {
884 checksum = WhichChecksum(items[IWt.itemN]);
885 status = CDFlib (PUT_, CDF_CHECKSUM_, checksum,
886 NULL_);
887 if (ReportStatus(status,FALSE)) {
888 ItemWindow (DELETEiw, &IWt);
889 return TRUE;
890 }
891 if (NoMoreAccess(NULL)) {
892 ItemWindow (DELETEiw, &IWt);
893 return FALSE;
894 }
895 }
896 else
897 break;
898 }
899 ItemWindow (DELETEiw, &IWt);
900 return TRUE;
901 }
902
903