home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2581 < prev    next >
Encoding:
Text File  |  1992-11-20  |  57.3 KB  |  2,149 lines

  1. Path: sparky!uunet!stanford.edu!morrow.stanford.edu!sep!steve
  2. From: steve@sep.Stanford.EDU (Steve Cole)
  3. Newsgroups: alt.sources
  4. Subject: xtpanel 2.0 - interactive program builder - part 05/10
  5. Followup-To: alt.sources.d
  6. Date: 21 Nov 1992 00:32:14 GMT
  7. Organization: Stanford Exploration Project
  8. Lines: 2136
  9. Distribution: world
  10. Message-ID: <1ek02eINN194@morrow.stanford.edu>
  11. NNTP-Posting-Host: taal.stanford.edu
  12.  
  13.  
  14. Submitted-by: steve@sep.Stanford.EDU
  15. Archive-name: xtpanel/part05
  16.  
  17. #!/bin/sh
  18. # This is part 05 of a multipart archive
  19. # ============= xtpanel/main.c ==============
  20. if test ! -d 'xtpanel'; then
  21.     echo 'x - creating directory xtpanel'
  22.     mkdir 'xtpanel'
  23. fi
  24. if test -f 'xtpanel/main.c' -a X"$1" != X"-c"; then
  25.     echo 'x - skipping xtpanel/main.c (File already exists)'
  26. else
  27. echo 'x - extracting xtpanel/main.c (Text)'
  28. sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/main.c' &&
  29. /*
  30. X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
  31. X * University. Official permission to use this software is included in
  32. X * the documentation. It authorizes you to use this file for any
  33. X * non-commercial purpose, provided that this copyright notice is not
  34. X * removed and that any modifications made to this file are commented
  35. X * and dated in the style of the example below.
  36. X */
  37. X
  38. /*
  39. X *
  40. X *  source file:   ./xtpanel/main.c
  41. X *
  42. X * Steve Cole, Dave Nichols (SEP), August 28 1992
  43. X *      Inserted this sample edit history entry.
  44. X *      Please log any further modifications made to this file:
  45. X * Steve Cole, Dave Nichols (SEP), November 20 1992 -  version 2.00
  46. X * 1) added new objects: toggle, scrollbar, graph.
  47. X * 2) added new actions: ASSIGN, SET.
  48. X * 3) objects can have multiple actions.
  49. X * 4) backquoted strings in actions get executed at action time.
  50. X */
  51. X
  52. #include "patchlevel.h"
  53. X
  54. #include <stdio.h>
  55. #include <X11/Intrinsic.h>
  56. #include <X11/StringDefs.h>
  57. X
  58. #include <X11/Xaw/Box.h>
  59. #include <X11/Xaw/Cardinals.h>
  60. #include <X11/Xaw/Paned.h>
  61. #include <X11/Xmu/Converters.h>
  62. X
  63. #ifdef _POSIX_SOURCE
  64. #include <unistd.h>
  65. #else
  66. extern int isatty();
  67. #endif
  68. X
  69. #include "tree.h"
  70. #include "builders.h"
  71. X
  72. String fallback_resources[] = {
  73. X    "*input:                  True",
  74. X    "*Paned*resizable:   True",
  75. X    "*Dialog*command*label:   ok",
  76. X    "*command*label:   ok",
  77. X    "*Dialog*resizable:       True",
  78. X    "*Viewport*allowVert:     True",
  79. X    "*Box*allowResize:        True",
  80. X    "*Box*resizable:        True",
  81. X    /* give menus room for dots */
  82. X    "*SimpleMenu*HorizontalMargins:         30",
  83. X    "*Scrollbar*orientation:  horizontal",
  84. X    "*text*resizable:         True",
  85. X    "*Text*resizable:         True",
  86. X    "*text*scrollVertical:    whenNeeded",
  87. X    NULL,
  88. };
  89. X
  90. extern void return_key_callback(),dialog_update_callback();
  91. extern void text_update_callback(),graph_update_callback();
  92. X
  93. static XtActionsRec window_actions[] = {
  94. X    {"return_key",       return_key_callback},
  95. X    {"update_dialog",    dialog_update_callback},
  96. X    {"update_text",      text_update_callback},
  97. X    {"update_graph",     graph_update_callback},
  98. };
  99. X
  100. enum boxType{ NOBORDER, VBOX, HBOX, VPANE, HPANE };
  101. X
  102. int        quitflag=0;
  103. X
  104. Widget toplevel;
  105. char* progname;
  106. X
  107. extern void quit_xtpanel(),parse_args();
  108. static void process_tree();
  109. X    
  110. int main(argc,argv)
  111. X     
  112. X     int argc;
  113. X     char **argv;
  114. {
  115. X    XtAppContext app_con;
  116. X    entry *root;
  117. X
  118. X    toplevel = XtAppInitialize(&app_con, "XTpanel", NULL, ZERO,
  119. X                   &argc, argv, fallback_resources,
  120. X                   NULL, ZERO);
  121. X    
  122. X    XtAddCallback( toplevel, XtNdestroyCallback, quit_xtpanel, NULL);
  123. X    
  124. X    XtAppAddActions(app_con, window_actions, XtNumber(window_actions));
  125. X    
  126. X    /* make the root entry to the tree, it is called "root" */
  127. X    root= new_entry( "root", 4);
  128. X    
  129. X    /* now go and parse what is left of the command line */
  130. X    progname = strdupl( *argv );
  131. X    argv++; argc--;
  132. X    
  133. X    parse_args( argc, argv, root );
  134. X    
  135. X    /* parse stdin if it pointing at something */
  136. X    if( !isatty( fileno(stdin) )  ) parse_file( stdin, root );
  137. X    
  138. X    /* print tree for debugging */
  139. X    /* print_entry( stderr,root,0 );*/
  140. X    
  141. X    /*now go and do something with the tree we have created */
  142. X    process_tree( root,toplevel,NOBORDER );
  143. X    
  144. X    XtRealizeWidget(toplevel);
  145. X    
  146. X    /* do the action for all objects with action type string */
  147. X    /* so that strings are set to something when they are needed */
  148. X    all_actions();
  149. X    
  150. X    /* make panel just big enough to encompass all items */
  151. X    /* pass control to notifier */
  152. X    XtAppMainLoop(app_con);
  153. X
  154. X    return 0;
  155. }
  156. X
  157. X
  158. /* 
  159. X  This routine take the fully parsed object tree and makes the
  160. X  appropriate widgets from each object.
  161. X  
  162. X  The widgets are then added to the paned widget.
  163. X  */
  164. X
  165. /* this routine may be called recursively (if the user defined sub boxes ) */
  166. X
  167. static void process_tree(  root,parent,btype )
  168. X     entry *root;
  169. X     Widget parent;
  170. X     enum boxType btype;
  171. {
  172. X    entry* curr;
  173. X    Widget box;
  174. X    char *name;
  175. X    Arg args[10];
  176. X    int narg;
  177. X    
  178. X    switch (btype) {
  179. X      case NOBORDER:
  180. X      default:
  181. X    /* a vertical box with no border */
  182. X    /* used only for boxes made by xtpanel, which have no name */
  183. X    narg=0;
  184. X    box = XtCreateManagedWidget("noborder",boxWidgetClass,parent,
  185. X                    args,narg);
  186. X    break;
  187. X      case VBOX:
  188. X    /* begin a new vertical (tall and thin) box */
  189. X    name = get_value(root,"name","vbox");
  190. X    narg=0;
  191. X    common_tags(root,args,&narg,SET_ALL);
  192. X    XtSetArg(args[narg], XtNorientation, XtorientVertical ); narg++;
  193. X    box = XtCreateManagedWidget(name,boxWidgetClass,parent,args,narg);
  194. X    break;
  195. X      case HBOX:
  196. X    /* begin a new horizontal box */
  197. X    name = get_value(root,"name","hbox");
  198. X    narg=0;
  199. X    common_tags(root,args,&narg,SET_ALL);
  200. X    XtSetArg(args[narg], XtNorientation, XtorientHorizontal ); narg++;
  201. X    box = XtCreateManagedWidget(name,boxWidgetClass,parent,args,narg);
  202. X    break;
  203. X      case VPANE:
  204. X    /* begin a new vertically paned widget */
  205. X    name = get_value(root,"name","paned");
  206. X    narg=0;
  207. X    common_tags(root,args,&narg,SET_ALL);
  208. X    XtSetArg(args[narg], XtNorientation, XtorientVertical ); narg++;
  209. X    box = XtCreateManagedWidget(name,panedWidgetClass,parent,args,narg);
  210. X    break;
  211. X      case HPANE:
  212. X    /* begin a new horizontally paned widget */
  213. X    name = get_value(root,"name","paned");
  214. X    narg=0;
  215. X    common_tags(root,args,&narg,SET_ALL);
  216. X    XtSetArg(args[narg], XtNorientation, XtorientHorizontal ); narg++;
  217. X    box = XtCreateManagedWidget("paned",panedWidgetClass,parent,args,narg);
  218. X    break;
  219. X    }
  220. X    
  221. X    /* loop over first level of tree */
  222. X    for( curr=root->child; curr != (entry*)0; curr=curr->next ){
  223. X    
  224. X    /* here is the big switch on item type */
  225. X    
  226. X    if( !strcmp( curr->tag, "box" ) || !strcmp( curr->tag, "vbox")){
  227. X        /* recursively call process_tree, rooted at this entry */
  228. X        process_tree( curr, box, VBOX);
  229. X        
  230. X    }else if( !strcmp( curr->tag, "hbox" ) ){
  231. X        /* recursively call process_tree, rooted at this entry */
  232. X        process_tree( curr, box, HBOX);
  233. X        
  234. X    }else if( !strcmp( curr->tag, "pane" ) || !strcmp( curr->tag,"vpane")){
  235. X        process_tree( curr, box, VPANE);
  236. X        
  237. X    }else if( !strcmp( curr->tag, "hpane" ) ){
  238. X        process_tree( curr, box, HPANE);
  239. X        
  240. X    }else if( !strcmp( curr->tag, "message" ) ){
  241. X        build_message(curr,box);
  242. X        
  243. X    }else if( !strcmp( curr->tag, "button" ) ||
  244. X         !strcmp( curr->tag, "toggle" )){
  245. X        build_button(curr,box,curr->tag);
  246. X        
  247. X    }else if( !strcmp( curr->tag, "choice" ) ){
  248. X        build_choice(curr,box);
  249. X        
  250. X    }else if( !strcmp( curr->tag, "slider" ) ||
  251. X         !strcmp( curr->tag, "scrollbar" )){
  252. X        build_slider(curr,box,curr->tag);
  253. X
  254. X    }else if( !strcmp( curr->tag, "graph" ) ){
  255. X        build_graph(curr,box);
  256. X        
  257. X    }else if( !strcmp( curr->tag, "menubutton" ) ){
  258. X        build_menubutton(curr,box);
  259. X        
  260. X    }else if( !strcmp( curr->tag, "list" ) ){
  261. X        build_list(curr,box);
  262. X        
  263. X    }else if( !strcmp( curr->tag, "dialog" ) ){
  264. X        build_dialog(curr,box);
  265. X        
  266. X    }else if( !strcmp( curr->tag, "text" ) ){
  267. X        build_text(curr,box);
  268. X                
  269. X    }else if( !strcmp( curr->tag, "var" ) ){
  270. X        build_variable(curr,box);
  271. X        
  272. X        /* ignore tags specified for top level box */
  273. X    }else if( !strcmp( curr->tag, "name" ) ||
  274. X          !strcmp( curr->tag, "foreground" ) ||
  275. X          !strcmp( curr->tag, "background" ) ||
  276. X          !strcmp( curr->tag, "borderColor" ) ||
  277. X          !strcmp( curr->tag, "height" ) ||
  278. X          !strcmp( curr->tag, "width" ) ||
  279. X          !strcmp( curr->tag, "orientation" ) ||
  280. X          !strcmp( curr->tag, "bitmap" ) ||
  281. X          !strcmp( curr->tag, "editType" ) ||
  282. X          !strcmp( curr->tag, "font" )) {
  283. X
  284. X    }else{
  285. X        fprintf( stderr,"Unrecognised object type %s \n", curr->tag );
  286. X        exit(-1);
  287. X    }
  288. X    
  289. X    }
  290. X    
  291. }
  292. X
  293. /*
  294. X * Function name: quit_xtpanel
  295. X * Description: quits by destroying toplevel widget.
  296. X * Arguments: none
  297. X * Returns: none
  298. X */
  299. void quit_xtpanel()
  300. {
  301. X    extern Widget toplevel;
  302. X
  303. X    XtDestroyWidget((Widget)toplevel);
  304. X    exit(0);
  305. }
  306. X
  307. SHAR_EOF
  308. chmod 0664 xtpanel/main.c ||
  309. echo 'restore of xtpanel/main.c failed'
  310. Wc_c="`wc -c < 'xtpanel/main.c'`"
  311. test 7865 -eq "$Wc_c" ||
  312.     echo 'xtpanel/main.c: original size 7865, current size' "$Wc_c"
  313. fi
  314. # ============= xtpanel/parse.c ==============
  315. if test -f 'xtpanel/parse.c' -a X"$1" != X"-c"; then
  316.     echo 'x - skipping xtpanel/parse.c (File already exists)'
  317. else
  318. echo 'x - extracting xtpanel/parse.c (Text)'
  319. sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/parse.c' &&
  320. /*
  321. X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
  322. X * University. Official permission to use this software is included in
  323. X * the documentation. It authorizes you to use this file for any
  324. X * non-commercial purpose, provided that this copyright notice is not
  325. X * removed and that any modifications made to this file are commented
  326. X * and dated in the style of the example below.
  327. X */
  328. X
  329. /*
  330. X *
  331. X *  source file:   ./xtpanel/parse.c
  332. X *
  333. X * Steve Cole, Dave Nichols (SEP), August 28 1992
  334. X *      Inserted this sample edit history entry.
  335. X *      Please log any further modifications made to this file:
  336. X * Steve Cole, Dave Nichols (SEP), November 20 1992 -  version 2.00
  337. X * 1) added new objects: toggle, scrollbar, graph.
  338. X * 2) added new actions: ASSIGN, SET.
  339. X * 3) objects can have multiple actions.
  340. X * 4) backquoted strings in actions get executed at action time.
  341. X */
  342. X
  343. #include <sys/types.h>
  344. #include <sys/stat.h>
  345. X
  346. #include "tree.h"
  347. #include <stdio.h>
  348. #include <string.h>
  349. #include "string_buf.h"
  350. X
  351. #ifndef CPP_COM
  352. #define CPP_COM "/lib/cpp -P"
  353. #endif
  354. X
  355. #ifdef _POSIX_SOURCE
  356. X
  357. #include <limits.h>
  358. #ifdef MAX_PATH
  359. #define MAXPATHLEN PATH_MAX
  360. #else
  361. #define MAXPATHLEN _POSIX_PATH_MAX
  362. #endif
  363. X
  364. #include <unistd.h>
  365. X
  366. #else /* not posix */
  367. X
  368. #include <sys/param.h>
  369. X
  370. #ifndef MAXPATHLEN
  371. #define MAXPATHLEN 1024
  372. #endif
  373. extern   char* getenv();
  374. X
  375. #endif /* not posix */
  376. X
  377. extern char* progname;
  378. X
  379. static void cpp_arg_scan();
  380. static void parse_file_named();
  381. void parse_file();
  382. static void usage();
  383. static void parse_item();
  384. static void parse_slider();
  385. static void parse_message();
  386. static void parse_dialog();
  387. static void parse_text();
  388. static void parse_variable();
  389. static void parse_button();
  390. static void parse_menubutton();
  391. static void parse_choice();
  392. static void parse_list();
  393. static void parse_scrollbar();
  394. static void parse_graph();
  395. X
  396. X
  397. /* parse the command line */
  398. void parse_args(  argc, argv, root  )
  399. int argc;
  400. char** argv;
  401. entry *root;
  402. {
  403. X  entry *ent, *subent;
  404. X  int use_cpp;
  405. X  char *cpp_args;
  406. X
  407. /* no arguments and stdin is a terminal - do self-doc */
  408. if (argc == 0 && isatty(fileno(stdin))) {
  409. X      usage();
  410. X      exit(0);
  411. }
  412. X
  413. /* first argument -tty - take input from stdin if it is a tty */
  414. if (argc > 0) {
  415. X   if (!strcmp( *argv, "-tty" ) ){
  416. X      if( isatty( fileno(stdin))) {
  417. X        (void) parse_file(stdin,root);
  418. X      }
  419. X      argv++; argc--;
  420. X   }
  421. }
  422. X
  423. /* first argument -help - run the help script */
  424. if (argc > 0) {
  425. X   if (!strcmp( *argv, "-help" ) ){
  426. X        system("xtpanel -file help/help");
  427. X        argv++; argc--;
  428. X        if (argc == 0) exit(0);
  429. X   }
  430. }
  431. X
  432. /* scan over the argument list looking for the -cpp flag and any
  433. X * C-preprocessor arguments, -I... and -D....
  434. X */
  435. cpp_arg_scan( &argc, &argv, &use_cpp, &cpp_args );
  436. X
  437. X
  438. /* process the rest of the command line */
  439. while(argc>0){
  440. X
  441. X   ent = (entry*)0;
  442. X
  443. X   if( !strcmp( *argv, "-quit" ) ){
  444. X      ent = new_entry("button",6); 
  445. X      subent = new_entry( "name", 4 );
  446. X      subent->value = strdupl("QUIT");
  447. X      add_child( ent, subent );
  448. X      subent = new_entry( "action", 6 );
  449. X      subent->value = strdupl("QUIT");
  450. X      add_child( ent, subent );
  451. X      argv++; argc--;
  452. X
  453. X   }else if( !strcmp(  *argv, "-file" ) ){
  454. X      argv++; argc--;
  455. X      if( argc >0 ){
  456. X         char* filename; 
  457. X     filename = *argv; argv++; argc--;
  458. X         parse_file_named( filename, root, use_cpp, cpp_args );
  459. X      }else{
  460. X      fprintf(stderr,"expecting filename after \"-file\"\n");
  461. X          usage(); exit(-1);
  462. X      }
  463. X
  464. X   }else if( !strcmp(  *argv, "-button" ) ){
  465. X      ent = new_entry("button", 6 ); argv++; argc--;
  466. X      parse_button( &argc, &argv, ent );
  467. X
  468. X   }else if( !strcmp(  *argv, "-slider" ) ){
  469. X      ent = new_entry("slider", 6 ); argv++; argc--;
  470. X      parse_slider( &argc, &argv, ent );
  471. X
  472. X   }else if( !strcmp(  *argv, "-menubutton" ) ){
  473. X      ent = new_entry("menubutton", 10 ); argv++; argc--;
  474. X      parse_menubutton( &argc, &argv, ent );
  475. X
  476. X   }else if( !strcmp(  *argv, "-text" ) ){
  477. X      ent = new_entry("text", 4 ); argv++; argc--;
  478. X      parse_text( &argc, &argv, ent );
  479. X
  480. X   }else if( !strcmp(  *argv, "-dialog" ) ){
  481. X      ent = new_entry("dialog", 6 ); argv++; argc--;
  482. X      parse_dialog( &argc, &argv, ent );
  483. X
  484. X   }else if( !strcmp(  *argv, "-choice" ) ){
  485. X      ent = new_entry("choice", 6 ); argv++; argc--;
  486. X      parse_choice( &argc, &argv, ent );
  487. X
  488. X   }else if( !strcmp(  *argv, "-list" ) ){
  489. X      ent = new_entry("list", 4 ); argv++; argc--;
  490. X      parse_list( &argc, &argv, ent );
  491. X
  492. X   }else if( !strcmp(  *argv, "-message" ) ){
  493. X      ent = new_entry("message", 7 ); argv++; argc--;
  494. X      parse_message( &argc, &argv, ent );
  495. X
  496. X   }else if( !strcmp(  *argv, "-var" ) ){
  497. X      ent = new_entry("var", 3 ); argv++; argc--;
  498. X      parse_variable( &argc, &argv, ent );
  499. X
  500. X   }else if( !strcmp(  *argv, "-toggle" ) ){
  501. X      ent = new_entry("toggle", 6 ); argv++; argc--;
  502. X      parse_button( &argc, &argv, ent );
  503. X
  504. X   }else if( !strcmp(  *argv, "-scrollbar" ) ){
  505. X      ent = new_entry("scrollbar", 9 ); argv++; argc--;
  506. X      parse_scrollbar( &argc, &argv, ent );
  507. X
  508. X   }else if( !strcmp(  *argv, "-graph" ) ){
  509. X      ent = new_entry("graph", 5 ); argv++; argc--;
  510. X      parse_graph( &argc, &argv, ent );
  511. X
  512. X   }else{
  513. X      fprintf( stderr," unrecognised argument %s \n",*argv);
  514. X      usage();
  515. X      exit(-1);
  516. X   }
  517. X
  518. X   if( ent != (entry*)0 ) {    
  519. X      add_child( root, ent );
  520. X   }
  521. X
  522. }
  523. }
  524. X
  525. X
  526. /* scan over the argument list looking for the -cpp flag and any
  527. X * C-preprocessor arguments, -I... and -D....
  528. X * remove all relevant arguments from the argument list
  529. X */
  530. X
  531. static void cpp_arg_scan( pargc, pargv, use_cpp, cpp_args )
  532. int *pargc;
  533. char*** pargv;
  534. int *use_cpp;
  535. char** cpp_args;
  536. {
  537. X
  538. int *keep_args,i;
  539. int num_keep=0;
  540. char** locargv= *pargv;
  541. int argc= *pargc;
  542. X
  543. *cpp_args = malloc(1024);
  544. strcpy( *cpp_args, "");
  545. X
  546. X   keep_args = (int*)malloc( argc * sizeof(int) );
  547. X
  548. X   *use_cpp = 0;
  549. X
  550. X   for( i=0; i<argc; i++ ){
  551. X      if( !strcmp( *locargv, "-cpp" ) ){
  552. X    *use_cpp = 1;
  553. X      }else if( !strncmp( *locargv, "-I", 2 )){
  554. X    strcat( *cpp_args, *locargv );
  555. X    strcat( *cpp_args, " " );
  556. X      }else if( !strncmp( *locargv, "-D", 2 )){
  557. X    strcat( *cpp_args, *locargv );
  558. X    strcat( *cpp_args, " " );
  559. X      }else{
  560. X    keep_args[num_keep] = i;
  561. X        num_keep++;
  562. X      }
  563. X      locargv++; 
  564. X   }
  565. X
  566. X   /* now compress the argument list */
  567. X   for( i=0 ; i<num_keep; i++ ){
  568. X      (*pargv)[i] = (*pargv)[keep_args[i]];
  569. X   }
  570. X   *pargc = num_keep;
  571. X    
  572. }
  573. X
  574. static char *find_file();
  575. X
  576. static void parse_file_named( filename , root, use_cpp, cpp_args )
  577. char *filename;
  578. entry *root;
  579. int use_cpp;
  580. char *cpp_args;
  581. {
  582. char* name;
  583. FILE* file;
  584. char cpp_command[1024];
  585. X
  586. X   if( (name = find_file( filename )) == NULL ){
  587. X      fprintf(stderr,"unable to find file %s\n",filename); exit(-1);
  588. X   }else{
  589. X       if( use_cpp ){
  590. X      sprintf(cpp_command," %s <%s %s ",CPP_COM,name,cpp_args);
  591. X      file = popen( cpp_command, "r" );
  592. X       }else{
  593. X          file = fopen( name, "r" );
  594. X       }
  595. X
  596. X       if( file == (FILE*)0 ){
  597. X          fprintf(stderr,"unable to open file %s\n",name); exit(-1);
  598. X       }else{
  599. X          parse_file( file, root );
  600. X       }
  601. X
  602. X       if( use_cpp ){
  603. X          pclose( file );
  604. X       }else{
  605. X          fclose( file );
  606. X       }
  607. X   }
  608. }
  609. X
  610. /* parse a file */
  611. #define PARSE_LEN 5000
  612. char parse_buf[PARSE_LEN]; /* PARSE_LEN is the size of chunks to read */
  613. X
  614. void parse_file( file , root )
  615. FILE* file;
  616. entry* root;
  617. {
  618. X   int num;
  619. X   string_buf * buffer;
  620. X   char *charry;
  621. X
  622. X   buffer = buf_start();
  623. X
  624. X   while( (num = fread( parse_buf, 1, PARSE_LEN, file )) > 0 ){
  625. X     buf_cat( buffer, parse_buf, num );
  626. X   };
  627. X   if( num <0 ){
  628. X    fprintf(stderr," error reading input \n");
  629. X    exit(-1);
  630. X   }
  631. X
  632. X   /* trim off trailing whitespace */
  633. X   buf_trim( buffer, " \t\n" );
  634. X
  635. X   charry = buf_fetch( buffer );
  636. X
  637. X   if( strlen(charry) >0 ) xtpanel_scan( charry, root );
  638. X
  639. X   free(charry);
  640. X
  641. }
  642. X
  643. X
  644. /* make an entry for a given tag, the value will be the next argument */
  645. static entry* parse_next(  pargc, pargv , tag )
  646. int *pargc;
  647. char*** pargv;
  648. char* tag;
  649. {
  650. X  entry* newent;
  651. X
  652. X  if( *pargc == 0 || **pargv[0] == '-' ){
  653. X     /* no more arguments for this object */
  654. X     newent = (entry*)0;
  655. X  }else{
  656. X     /* else get the next argument an make an entry */
  657. X     newent = new_entry( tag, strlen(tag) );
  658. X     newent->value = strdupl( **pargv );
  659. X     (*pargc)--; (*pargv)++;
  660. X  }
  661. X  return newent;
  662. }
  663. X
  664. /* parse a button, it has a label, action, name, value */
  665. static void parse_button( pargc, pargv, ent )
  666. int *pargc;
  667. char*** pargv;
  668. entry *ent;
  669. {
  670. X
  671. entry *newent;
  672. X  if( (newent=parse_next( pargc, pargv, "label" )) == (entry*) 0 ) return;
  673. X  else add_child( ent, newent );
  674. X
  675. X  if( (newent=parse_next( pargc, pargv, "action" )) == (entry*) 0 ) return;
  676. X  else add_child( ent, newent );
  677. X
  678. X  if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  679. X  else add_child( ent, newent );
  680. X
  681. X  if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  682. X  else add_child( ent, newent );
  683. X
  684. }
  685. X
  686. /* parse a variable, it has a name and a value */
  687. static void parse_variable( pargc, pargv, ent )
  688. int *pargc;
  689. char*** pargv;
  690. entry *ent;
  691. {
  692. X
  693. entry *newent;
  694. X  if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  695. X  else add_child( ent, newent );
  696. X
  697. X  if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  698. X  else add_child( ent, newent );
  699. X
  700. }
  701. X
  702. /* parse a text item: value, action, name, width, height, editType */
  703. static void parse_text( pargc, pargv, ent )
  704. int *pargc;
  705. char*** pargv;
  706. entry *ent;
  707. {
  708. entry *newent;
  709. X
  710. X  if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  711. X  else add_child( ent, newent );
  712. X
  713. X  if( (newent=parse_next( pargc, pargv, "action" )) == (entry*) 0 ) return;
  714. X  else add_child( ent, newent );
  715. X
  716. X  if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  717. X  else add_child( ent, newent );
  718. X
  719. X  if( (newent=parse_next( pargc, pargv, "width" )) == (entry*) 0 ) return;
  720. X  else add_child( ent, newent );
  721. X
  722. X  if( (newent=parse_next( pargc, pargv, "height" )) == (entry*) 0 ) return;
  723. X  else add_child( ent, newent );
  724. X
  725. X  if( (newent=parse_next( pargc, pargv, "editType" )) == (entry*) 0 ) return;
  726. X  else add_child( ent, newent );
  727. }
  728. X
  729. /* parse a dialog item: label, action, name, value */
  730. static void parse_dialog( pargc, pargv, ent )
  731. int *pargc;
  732. char*** pargv;
  733. entry *ent;
  734. {
  735. entry *newent;
  736. X
  737. X  if( (newent=parse_next( pargc, pargv, "label" )) == (entry*) 0 ) return;
  738. X  else add_child( ent, newent );
  739. X
  740. X  if( (newent=parse_next( pargc, pargv, "action" )) == (entry*) 0 ) return;
  741. X  else add_child( ent, newent );
  742. X
  743. X  if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  744. X  else add_child( ent, newent );
  745. X
  746. X  if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  747. X  else add_child( ent, newent);
  748. X
  749. }
  750. X
  751. /* parse a mesage item: value, name */
  752. static void parse_message( pargc, pargv, ent )
  753. int *pargc;
  754. char*** pargv;
  755. entry *ent;
  756. {
  757. entry *newent;
  758. X
  759. X  if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  760. X  else add_child( ent, newent );
  761. X
  762. X  if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  763. X  else add_child( ent, newent );
  764. X
  765. }
  766. X
  767. /* parse a slider item, it just has lots of arguments*/
  768. static void parse_slider( pargc, pargv, ent )
  769. X     int *pargc;
  770. X     char*** pargv;
  771. X     entry *ent;
  772. {
  773. X    entry *newent;
  774. X    
  775. X    if( (newent=parse_next( pargc, pargv, "label" )) == (entry*) 0 ) return;
  776. X    else add_child( ent, newent );
  777. X    
  778. X    if( (newent=parse_next( pargc, pargv, "action" )) == (entry*) 0 ) return;
  779. X    else add_child( ent, newent );
  780. X    
  781. X    if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  782. X    else add_child( ent, newent );
  783. X    
  784. X    if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  785. X    else add_child( ent, newent );
  786. X    
  787. X    if( (newent=parse_next( pargc, pargv, "min" )) == (entry*) 0 ) return;
  788. X    else add_child( ent, newent );
  789. X    
  790. X    if( (newent=parse_next( pargc, pargv, "max" )) == (entry*) 0 ) return;
  791. X    else add_child( ent, newent );
  792. X    
  793. X    if( (newent=parse_next( pargc, pargv, "format" )) == (entry*) 0 ) return;
  794. X    else add_child( ent, newent );
  795. X    
  796. X    if( (newent=parse_next( pargc, pargv, "width" )) == (entry*) 0 ) return;
  797. X    else add_child( ent, newent );
  798. X    
  799. X    if( (newent=parse_next( pargc, pargv, "height" )) == (entry*) 0 ) return;
  800. X    else add_child( ent, newent );
  801. X    
  802. }
  803. X
  804. /* parse a scrollbar item, like slider but no label */
  805. static void parse_scrollbar( pargc, pargv, ent )
  806. X     int *pargc;
  807. X     char*** pargv;
  808. X     entry *ent;
  809. {
  810. X    entry *newent;
  811. X    
  812. X    if( (newent=parse_next( pargc, pargv, "action" )) == (entry*) 0 ) return;
  813. X    else add_child( ent, newent );
  814. X    
  815. X    if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  816. X    else add_child( ent, newent );
  817. X    
  818. X    if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  819. X    else add_child( ent, newent );
  820. X    
  821. X    if( (newent=parse_next( pargc, pargv, "min" )) == (entry*) 0 ) return;
  822. X    else add_child( ent, newent );
  823. X    
  824. X    if( (newent=parse_next( pargc, pargv, "max" )) == (entry*) 0 ) return;
  825. X    else add_child( ent, newent );
  826. X    
  827. X    if( (newent=parse_next( pargc, pargv, "format" )) == (entry*) 0 ) return;
  828. X    else add_child( ent, newent );
  829. X    
  830. X    if( (newent=parse_next( pargc, pargv, "width" )) == (entry*) 0 ) return;
  831. X    else add_child( ent, newent );
  832. X    
  833. X    if( (newent=parse_next( pargc, pargv, "height" )) == (entry*) 0 ) return;
  834. X    else add_child( ent, newent );
  835. X    
  836. }
  837. X
  838. /* parse a graph item, it is even worse than a slider */
  839. static void parse_graph( pargc, pargv, ent )
  840. X     int *pargc;
  841. X     char*** pargv;
  842. X     entry *ent;
  843. {
  844. X    entry *newent;
  845. X    
  846. X    if( (newent=parse_next( pargc, pargv, "nsamp" )) == (entry*) 0 ) return;
  847. X    else add_child( ent, newent );
  848. X    
  849. X    if( (newent=parse_next( pargc, pargv, "label" )) == (entry*) 0 ) return;
  850. X    else add_child( ent, newent );
  851. X    
  852. X    if( (newent=parse_next( pargc, pargv, "action" )) == (entry*) 0 ) return;
  853. X    else add_child( ent, newent );
  854. X    
  855. X    if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  856. X    else add_child( ent, newent );
  857. X    
  858. X    if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  859. X    else add_child( ent, newent );
  860. X    
  861. X    if( (newent=parse_next( pargc, pargv, "min" )) == (entry*) 0 ) return;
  862. X    else add_child( ent, newent );
  863. X    
  864. X    if( (newent=parse_next( pargc, pargv, "max" )) == (entry*) 0 ) return;
  865. X    else add_child( ent, newent );
  866. X    
  867. X    if( (newent=parse_next( pargc, pargv, "format" )) == (entry*) 0 ) return;
  868. X    else add_child( ent, newent );
  869. X    
  870. X    if( (newent=parse_next( pargc, pargv, "width" )) == (entry*) 0 ) return;
  871. X    else add_child( ent, newent );
  872. X    
  873. X    if( (newent=parse_next( pargc, pargv, "height" )) == (entry*) 0 ) return;
  874. X    else add_child( ent, newent );
  875. X    
  876. }
  877. X
  878. /* generic item, used in choice, list, and menubutton */
  879. static void parse_item( pargc, pargv, ent )
  880. X     int *pargc;
  881. X     char*** pargv;
  882. X     entry *ent;
  883. {
  884. X    entry *newent;
  885. X    
  886. X    if( (newent=parse_next( pargc, pargv, "label" )) == (entry*) 0 ) 
  887. X      { fprintf( stderr," expecting label for item \n"); exit(-1); }
  888. X    add_child( ent, newent );
  889. X    
  890. X    if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) 
  891. X      { fprintf( stderr," expecting value for item \n");exit(-1); }
  892. X    add_child( ent, newent );
  893. X    
  894. }
  895. X
  896. static void parse_menubutton( pargc, pargv, ent )
  897. X     int *pargc;
  898. X     char*** pargv;
  899. X     entry *ent;
  900. {
  901. X    entry *newent;
  902. X    
  903. X    if( (newent=parse_next( pargc, pargv, "label" )) == (entry*) 0 ) return;
  904. X    else add_child( ent, newent );
  905. X    
  906. X    if( (newent=parse_next( pargc, pargv, "action" )) == (entry*) 0 ) return;
  907. X    else add_child( ent, newent );
  908. X    
  909. X    if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  910. X    else add_child( ent, newent );
  911. X    
  912. X    if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  913. X    else add_child( ent, newent );
  914. X    
  915. X    if( *pargc >0 ){
  916. X    int numitem;
  917. X    numitem = atoi( **pargv ); (*pargc)--; (*pargv)++;
  918. X    while( numitem >0 ){
  919. X        entry* newitem;
  920. X        newitem = new_entry("item", 4);
  921. X        parse_item(  pargc, pargv, newitem );
  922. X        add_child( ent, newitem );
  923. X        numitem--;
  924. X    }
  925. X    }else{
  926. X    (*pargv)--;
  927. X    fprintf( stderr, " unexpected end of arguments after %s\n", 
  928. X        (**pargv) );
  929. X    fprintf( stderr, " expecting number of items in menu \n");
  930. X    usage();
  931. X    exit(-1);
  932. X    }
  933. }
  934. X
  935. X
  936. static void parse_choice( pargc, pargv, ent )
  937. X     int *pargc;
  938. X     char*** pargv;
  939. X     entry *ent;
  940. {
  941. X    entry *newent;
  942. X    
  943. X    if( (newent=parse_next( pargc, pargv, "label" )) == (entry*) 0 ) return;
  944. X    else add_child( ent, newent );
  945. X    
  946. X    if( (newent=parse_next( pargc, pargv, "action" )) == (entry*) 0 ) return;
  947. X    else add_child( ent, newent );
  948. X    
  949. X    if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  950. X    else add_child( ent, newent );
  951. X    
  952. X    if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  953. X    else add_child( ent, newent );
  954. X    
  955. X    if( *pargc >0 ){
  956. X    int numitem;
  957. X    numitem = atoi( **pargv ); (*pargc)--; (*pargv)++;
  958. X    while( numitem >0 ){
  959. X        entry* newitem;
  960. X        newitem = new_entry("item", 4);
  961. X        parse_item(  pargc, pargv, newitem );
  962. X        add_child( ent, newitem );
  963. X        numitem--;
  964. X    }
  965. X    }else{
  966. X    (*pargv)--;
  967. X    fprintf( stderr, " unexpected end of arguments after %s\n", 
  968. X        (**pargv) );
  969. X    fprintf( stderr, " expecting number of items in choice \n");
  970. X    usage();
  971. X    exit(-1);
  972. X    }
  973. }
  974. X
  975. X
  976. static void parse_list( pargc, pargv, ent )
  977. X     int *pargc;
  978. X     char*** pargv;
  979. X     entry *ent;
  980. {
  981. X    entry *newent;
  982. X    
  983. X    if( (newent=parse_next( pargc, pargv, "label" )) == (entry*) 0 ) return;
  984. X    else add_child( ent, newent );
  985. X    
  986. X    if( (newent=parse_next( pargc, pargv, "action" )) == (entry*) 0 ) return;
  987. X    else add_child( ent, newent );
  988. X    
  989. X    if( (newent=parse_next( pargc, pargv, "name" )) == (entry*) 0 ) return;
  990. X    else add_child( ent, newent );
  991. X    
  992. X    if( (newent=parse_next( pargc, pargv, "value" )) == (entry*) 0 ) return;
  993. X    else add_child( ent, newent );
  994. X    
  995. X    if( *pargc >0 ){
  996. X    int numitem;
  997. X    numitem = atoi( **pargv ); (*pargc)--; (*pargv)++;
  998. X    while( numitem >0 ){
  999. X        entry* newitem;
  1000. X        newitem = new_entry("item", 4);
  1001. X        parse_item(  pargc, pargv, newitem );
  1002. X        add_child( ent, newitem );
  1003. X        numitem--;
  1004. X    }
  1005. X    }else{
  1006. X    (*pargv)--;
  1007. X    fprintf( stderr, " unexpected end of arguments after %s\n", 
  1008. X        (**pargv) );
  1009. X    fprintf( stderr, " expecting number of items in list \n");
  1010. X    usage();
  1011. X    exit(-1);
  1012. X    }
  1013. }
  1014. X
  1015. X
  1016. static void usage()
  1017. {
  1018. X    fprintf( stderr,"USAGE\n-----\n%s [ < config_file ] \n",progname);
  1019. X    fprintf( stderr,"\t[ -file \t config_file2 ] \n");
  1020. X    fprintf( stderr,"\t[ -help ] \n");
  1021. X    fprintf( stderr,"\t[ -quit ] \n");
  1022. X    fprintf( stderr,"\t[ -message \t value name ] \n");
  1023. X    fprintf( stderr,"\t[ -text \t value action name width height");
  1024. X    fprintf( stderr," editType ]\n");
  1025. X    fprintf( stderr,"\t[ -button \t label action name value ] \n");
  1026. X    fprintf( stderr,"\t[ -toggle \t label action name value ] \n");
  1027. X    fprintf( stderr,"\t[ -dialog \t label action name value ]\n");
  1028. X    fprintf( stderr,"\t[ -slider \t label action name value min max");
  1029. X    fprintf( stderr," format width height ]\n");
  1030. X    fprintf( stderr,"\t[ -scrollbar \t action name value min max");
  1031. X    fprintf( stderr," format width height ]\n");
  1032. X    fprintf( stderr,"\t[ -choice \t label action name value numchoice");
  1033. X    fprintf( stderr," label value ... ]\n");
  1034. X    fprintf( stderr,"\t[ -list \t label action name value numchoice");
  1035. X    fprintf( stderr," label value ... ]\n");
  1036. X    fprintf( stderr,"\t[ -menubutton \t label action name value numchoice");
  1037. X    fprintf( stderr," label value ... ]\n");
  1038. X    fprintf( stderr,"\t[ -graph \t nsamp label action name value min max");
  1039. X    fprintf( stderr," format width height ]\n");
  1040. X    fprintf( stderr,"\t[ -var \t\t name value ]\n");
  1041. X    fprintf( stderr,"\n\n\n");
  1042. }
  1043. X
  1044. X
  1045. static char    *get_file_path();
  1046. static char *find_file( name )
  1047. X     char    *name;
  1048. {
  1049. X    static char     file_name[ MAXPATHLEN ];
  1050. X    struct stat     s;
  1051. X    int             path_index;
  1052. X    char            *path;
  1053. X    
  1054. X    /* name begins with / */
  1055. X    if( name[0] == '/' )
  1056. X      return name;
  1057. X    
  1058. X    /* search path */
  1059. X    path_index = 0;
  1060. X    while( ( path = get_file_path( path_index ) ) != NULL )
  1061. X      {
  1062. X      strcpy( file_name, path );
  1063. X      strcat( file_name, "/" );
  1064. X      strcat( file_name, name );
  1065. X      if( stat( file_name, &s ) != -1 ) return file_name;
  1066. X      path_index++;
  1067. X      }
  1068. X    
  1069. X    return name;
  1070. }
  1071. X
  1072. #ifndef SYS_XTPANELDIR
  1073. #define SYS_XTPANELDIR "/usr/local/lib/xtpanel"
  1074. #endif
  1075. X
  1076. static char* get_file_path( index )
  1077. X     int     index;
  1078. {
  1079. X    static char path[ MAXPATHLEN ];
  1080. X    char    *file_path = NULL;
  1081. X    char    *p;
  1082. X    char    *q;
  1083. X    
  1084. X    /*  build the path */
  1085. X    if( ( file_path = getenv( "XTPANEL_PATH" ) ) != NULL ){
  1086. X    strcpy( path, file_path );
  1087. X    strcat( path, ":"  );
  1088. X    }else{
  1089. X    strcpy( path, "./:" );
  1090. X    }
  1091. X    strcat( path, getenv("HOME") );
  1092. X    strcat( path, "/.xtpanel:"  );
  1093. X    strcat( path, SYS_XTPANELDIR );
  1094. X    
  1095. X    p = path;
  1096. X    
  1097. X    while( index-- >= 0 )
  1098. X      {
  1099. X      q = p;
  1100. X      p = strchr( p, ':' );
  1101. X      if( p == NULL )
  1102. X        break;
  1103. X      else
  1104. X        p++;
  1105. X      }
  1106. X    
  1107. X    if( index >= 0 )
  1108. X      return NULL;
  1109. X    
  1110. X    if( p != NULL ) p--;
  1111. X    if( p != NULL && *p == ':' ) *p = '\0';
  1112. X    
  1113. X    return q;
  1114. X    
  1115. }
  1116. X
  1117. X
  1118. /* parse an itemlist into separate items */
  1119. void parse_itemlist( root )
  1120. X     entry *root;
  1121. {
  1122. X    entry *curr;
  1123. X    entry *itement, *leaf;
  1124. X    char* itemlist;
  1125. X    char* separator;
  1126. X    char* item;
  1127. X    
  1128. X    
  1129. X    /* for all itemlist entries in "root" , convert them into items */
  1130. X    for (curr = get_next(root,"itemlist",(entry*) 0); curr != ((entry*) 0); 
  1131. X     curr = get_next(root,"itemlist",curr) ){
  1132. X    
  1133. X    itemlist = get_value(  curr, "list", ""  );
  1134. X    separator = get_value( curr, "separator", " " );
  1135. X    
  1136. X    for( item=strtok(itemlist,separator); 
  1137. X        item != (char*)0 ;
  1138. X        item =strtok( (char*)0, separator ) ){
  1139. X        
  1140. X        /* make a new item entry */
  1141. X        itement = new_entry( "item", 4 );
  1142. X        add_child( root, itement );
  1143. X        
  1144. X        /* make a new label entry */
  1145. X        leaf = new_entry( "label", 5 );
  1146. X        leaf->value = strdupl( item );
  1147. X        add_child( itement, leaf );
  1148. X        
  1149. X    }
  1150. X    }
  1151. X    
  1152. }
  1153. SHAR_EOF
  1154. chmod 0664 xtpanel/parse.c ||
  1155. echo 'restore of xtpanel/parse.c failed'
  1156. Wc_c="`wc -c < 'xtpanel/parse.c'`"
  1157. test 22092 -eq "$Wc_c" ||
  1158.     echo 'xtpanel/parse.c: original size 22092, current size' "$Wc_c"
  1159. fi
  1160. # ============= xtpanel/tree.c ==============
  1161. if test -f 'xtpanel/tree.c' -a X"$1" != X"-c"; then
  1162.     echo 'x - skipping xtpanel/tree.c (File already exists)'
  1163. else
  1164. echo 'x - extracting xtpanel/tree.c (Text)'
  1165. sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/tree.c' &&
  1166. /*
  1167. X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
  1168. X * University. Official permission to use this software is included in
  1169. X * the documentation. It authorizes you to use this file for any
  1170. X * non-commercial purpose, provided that this copyright notice is not
  1171. X * removed and that any modifications made to this file are commented
  1172. X * and dated in the style of the example below.
  1173. X */
  1174. X
  1175. /*
  1176. X *
  1177. X *  source file:   ./xtpanel/tree.c
  1178. X *
  1179. X * Steve Cole, Dave Nichols (SEP), August 28 1992
  1180. X *      Inserted this sample edit history entry.
  1181. X *      Please log any further modifications made to this file:
  1182. X * Steve Cole, Dave Nichols (SEP), November 20 1992 -  version 2.00
  1183. X * 1) added new objects: toggle, scrollbar, graph.
  1184. X * 2) added new actions: ASSIGN, SET.
  1185. X * 3) objects can have multiple actions.
  1186. X * 4) backquoted strings in actions get executed at action time.
  1187. X */
  1188. X
  1189. #include <stdio.h>
  1190. X
  1191. #include "tree.h"
  1192. X
  1193. /* 
  1194. X  
  1195. X  This is an entry stucture as defined in tree.h.
  1196. X  
  1197. X  Each item in a tree is an entry.
  1198. X  
  1199. X  struct _ent {
  1200. X  char* tag;
  1201. X  char* value;
  1202. X  struct _ent* child;
  1203. X  struct _ent* next;
  1204. X  } ;
  1205. X  
  1206. X  */
  1207. X
  1208. /* a tree contains either nodes or leaves.
  1209. X * each entry must have a tag ( its name )
  1210. X *
  1211. X * nodes have a child but no value.
  1212. X *
  1213. X * leaves have a value but no children.
  1214. X *
  1215. X * either may have a sibling (next)
  1216. X */
  1217. X
  1218. /* create a new empty entry, the tag is not null terminated */
  1219. entry* new_entry( tag, len )
  1220. X     char*tag;
  1221. X     int len;
  1222. {
  1223. X    entry* a;
  1224. X    a = (entry*) malloc( sizeof( entry ) );
  1225. X    
  1226. X    a->tag = malloc( len+1 );
  1227. X    strncpy( a->tag, tag, len );
  1228. X    a->tag[len] = '\0';
  1229. X    
  1230. X    a->value = (char*)0;
  1231. X    a->child= (entry*)0;
  1232. X    a->next= (entry*)0;
  1233. X    return a;
  1234. }
  1235. X
  1236. /* add a sibling to an entry, if this entry already has one it
  1237. X * will go and find the last sibling without a "next" field.  */
  1238. void add_sibling( orig, sib )
  1239. X     entry* orig, *sib;
  1240. {
  1241. X    entry *curr;
  1242. X    curr=orig;
  1243. X    
  1244. X    while( curr->next !=  (entry*)0 ){ curr = curr->next; }
  1245. X    
  1246. X    curr->next = sib;
  1247. }
  1248. X
  1249. /* add a child to an entry. It will be the sibling of any existing child */
  1250. void add_child( parent, child )
  1251. X     entry *parent,*child;
  1252. {
  1253. X    if( parent->child ==  (entry*)0 ){
  1254. X    parent->child = child;
  1255. X    }else{
  1256. X    add_sibling( parent->child, child );
  1257. X    }
  1258. }
  1259. X
  1260. X
  1261. /* retrieve an entry given the tag, if prev is non zero the entry will 
  1262. X   be the next matching entry after prev */
  1263. entry* get_next( root, tag, prev )
  1264. X     entry* root;
  1265. X     char* tag;
  1266. X     entry* prev;
  1267. {
  1268. X    entry *ent;
  1269. X    
  1270. X    /* start with the first child */
  1271. X    ent = root->child;
  1272. X    
  1273. X    /* first find the previous entry */
  1274. X    if( prev != (entry*)0 ){
  1275. X    while( ent != (entry*)0  && ent != prev ) ent = ent->next;
  1276. X    /* found prev, start at the next one */
  1277. X    if( ent != (entry*)0 ) ent = ent->next;
  1278. X    }
  1279. X    
  1280. X    while( ent != (entry*)0  ){
  1281. X    if( !strcmp( ent->tag, tag ) )  break;
  1282. X    ent = ent->next;
  1283. X    }
  1284. X    
  1285. X    return ent;
  1286. }
  1287. X
  1288. /* retrieve a copy of the value string given a tag.
  1289. X   if the tag is not found the default string will be copied */
  1290. char* get_value( root, tag, defstring )
  1291. X     entry* root;
  1292. X     char* tag;
  1293. X     char * defstring;
  1294. {
  1295. X    char *retval;
  1296. X    entry * ent;
  1297. X    
  1298. X    retval = (char*)0;
  1299. X    
  1300. X    ent = get_next( root, tag, 0 );
  1301. X    
  1302. X    if( ent != (entry*)0 &&  ent->value != (char*)0 ) {
  1303. X    retval = strdupl( ent->value );
  1304. X    }else{
  1305. X    retval = strdupl( defstring );
  1306. X    }
  1307. X    
  1308. X    return retval;
  1309. }
  1310. X
  1311. /* See if a given tag exists */
  1312. int is_specified( root, tag )
  1313. X     entry* root;
  1314. X     char* tag;
  1315. {
  1316. X    int retval;
  1317. X    entry * ent;
  1318. X    
  1319. X    retval = 0;
  1320. X    
  1321. X    ent = get_next( root, tag, 0 );
  1322. X    
  1323. X    if( ent != (entry*)0 &&  ent->value != (char*)0 ) {
  1324. X    retval = 1;
  1325. X    }else{
  1326. X    retval = 0;
  1327. X    }
  1328. X    
  1329. X    return retval;
  1330. }
  1331. X
  1332. /* print the tree rooted at this entry, useful for debugging */
  1333. void print_entry( file, ent, num_tab )
  1334. X     FILE* file;
  1335. X     entry *ent;
  1336. X     int num_tab;
  1337. {
  1338. X    char tabs[20];
  1339. X    int i;
  1340. X    entry *ch;
  1341. X    
  1342. X    for ( i=0; i<num_tab; i++ ) tabs[i] = '\t';
  1343. X    tabs[num_tab]='\0';
  1344. X    
  1345. X    fprintf(file,"%s tag=%s\n",tabs,ent->tag);
  1346. X    if( ent->value != 0 )  fprintf(file,"%s value=%s\n",tabs,ent->value);
  1347. X    
  1348. X    ch = ent->child;
  1349. X    while( ch != 0 ) {
  1350. X    print_entry( file, ch, num_tab+1 );
  1351. X        ch = ch->next;
  1352. X    }
  1353. X    
  1354. X    fprintf(file,"\n");
  1355. X    
  1356. }
  1357. SHAR_EOF
  1358. chmod 0664 xtpanel/tree.c ||
  1359. echo 'restore of xtpanel/tree.c failed'
  1360. Wc_c="`wc -c < 'xtpanel/tree.c'`"
  1361. test 4270 -eq "$Wc_c" ||
  1362.     echo 'xtpanel/tree.c: original size 4270, current size' "$Wc_c"
  1363. fi
  1364. # ============= xtpanel/tree.h ==============
  1365. if test -f 'xtpanel/tree.h' -a X"$1" != X"-c"; then
  1366.     echo 'x - skipping xtpanel/tree.h (File already exists)'
  1367. else
  1368. echo 'x - extracting xtpanel/tree.h (Text)'
  1369. sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/tree.h' &&
  1370. #ifndef TREE_H
  1371. #define TREE_H
  1372. X
  1373. #if defined __STDC__ || defined __stdc__ 
  1374. #include <stdlib.h>
  1375. #else
  1376. #if defined AIXV3 || defined sun || defined ultrix
  1377. #include <stdlib.h>
  1378. #else
  1379. extern char* malloc();
  1380. extern double atof();
  1381. #endif
  1382. #endif
  1383. X
  1384. #include <string.h>
  1385. X
  1386. #define ALPHNUM \
  1387. X   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
  1388. X
  1389. struct _ent {
  1390. X        char* tag;
  1391. X    char* value;
  1392. X    struct _ent* child;
  1393. X    struct _ent* next;
  1394. } ;
  1395. X
  1396. typedef struct _ent entry;
  1397. X
  1398. #ifndef _NO_PROTO
  1399. #include <stdio.h>
  1400. extern entry* new_entry( char*, int);
  1401. extern void add_child( entry*, entry* );
  1402. extern void add_sibling( entry*, entry* );
  1403. char* get_value( entry*, char*, char*);
  1404. char* get_name( entry*, char* );
  1405. entry* get_next(entry*, char*, entry* );
  1406. extern void print_entry( FILE*, entry*, int );
  1407. extern int is_specified( entry*,  char* );
  1408. X
  1409. #else
  1410. extern entry* new_entry();
  1411. extern void add_child();
  1412. extern void add_sibling();
  1413. char* get_value();
  1414. char* get_name();
  1415. entry* get_next();
  1416. extern void print_entry();
  1417. extern int is_specified();
  1418. #endif
  1419. X
  1420. static char* strdupl(a)
  1421. char*a; { char*b; b=malloc( strlen(a)+1); strcpy( b, a ); return b; }
  1422. X
  1423. #endif
  1424. SHAR_EOF
  1425. chmod 0664 xtpanel/tree.h ||
  1426. echo 'restore of xtpanel/tree.h failed'
  1427. Wc_c="`wc -c < 'xtpanel/tree.h'`"
  1428. test 1134 -eq "$Wc_c" ||
  1429.     echo 'xtpanel/tree.h: original size 1134, current size' "$Wc_c"
  1430. fi
  1431. # ============= xtpanel/XTpanel.ad.sed ==============
  1432. if test -f 'xtpanel/XTpanel.ad.sed' -a X"$1" != X"-c"; then
  1433.     echo 'x - skipping xtpanel/XTpanel.ad.sed (File already exists)'
  1434. else
  1435. echo 'x - extracting xtpanel/XTpanel.ad.sed (Text)'
  1436. sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/XTpanel.ad.sed' &&
  1437. *input:                        True
  1438. *Paned*resizable:               True
  1439. *Dialog*Command*label:           ok
  1440. *Command*label:               ok
  1441. *Dialog*resizable:               True
  1442. *Dialog*value.translations: #override <Key>Return: return_key()
  1443. *Viewport*allowVert:             True
  1444. *Box*allowResize:                True
  1445. *Box*resizable:                    True
  1446. *SimpleMenu*HorizontalMargins:             30
  1447. *sliderbox*Scrollbar*orientation:    horizontal
  1448. *sliderbox*Scrollbar*length:        100
  1449. *sliderbox*Scrollbar*thickness:        25
  1450. *text*resizable:                 True
  1451. *Text*resizable:                 True
  1452. *text*scrollVertical:            whenNeeded
  1453. *text*scrollHorizonal:           whenNeeded
  1454. X
  1455. ! A widget with name=noborder doesn't have a border
  1456. *noborder.borderWidth:         0
  1457. X
  1458. ! A box with name=squeezebox squeezes everything inside it
  1459. *squeezebox*vSpace:                    0
  1460. *squeezebox*hSpace:                    0
  1461. *squeezebox*Box*borderWidth:         0
  1462. *squeezebox*Box*vSpace:                0
  1463. *squeezebox*Box*hSpace:                0
  1464. *squeezebox*Command*borderWidth:      0
  1465. *squeezebox*Command*label:
  1466. *squeezebox*Command*width:        10
  1467. *squeezebox*Command*height:        10
  1468. *squeezebox.Scrollbar.orientation:      vertical
  1469. *squeezebox*Toggle*borderWidth:      0
  1470. *squeezebox*Toggle*label:
  1471. *squeezebox*Toggle*width:        10
  1472. *squeezebox*Toggle*height:        10
  1473. *squeezebox*togglebox*Label: 
  1474. *squeezebox*togglebox*orientation:      horizontal
  1475. *squeezebox*sliderbox.orientation:      horizontal
  1476. *squeezebox*sliderbox.Scrollbar.orientation:      horizontal
  1477. *squeezebox*Toggle.translations:#augment\n\
  1478. X      Meta<EnterNotify>:toggle() notify()
  1479. *squeezebox*Scrollbar*borderWidth:      0
  1480. *squeezebox*Scrollbar.translations:#override\n\
  1481. X      Meta<EnterNotify>: StartScroll(Continuous) MoveThumb() NotifyThumb()\n\
  1482. X      Meta<LeaveNotify>: NotifyScroll(Proportional) EndScroll()\n\
  1483. X      Meta<Motion>: MoveThumb() NotifyThumb()
  1484. X
  1485. ! A box with name=graphbox contains a graph object
  1486. *graphbox.orientation:            vertical
  1487. *graphbox.borderWidth:                 0
  1488. *graphbox*vSpace:                    0
  1489. *graphbox*hSpace:                    0
  1490. *graphbox*Box*vSpace:                    0
  1491. *graphbox*Box*hSpace:                    0
  1492. *graphbox*Scrollbar*borderWidth:      0
  1493. *graphbox*Scrollbar.translations:#override\n\
  1494. X      Meta<EnterNotify>: StartScroll(Continuous) MoveThumb() NotifyThumb()\n\
  1495. X      Meta<LeaveNotify>: NotifyScroll(Proportional) EndScroll()\n\
  1496. X      Meta<Motion>: MoveThumb() NotifyThumb()
  1497. X
  1498. *stevebitmap.bitmap:            SYS_XTPANELDIR/help/steve.xbm
  1499. *davebitmap.bitmap:            SYS_XTPANELDIR/help/dave.xbm
  1500. SHAR_EOF
  1501. chmod 0664 xtpanel/XTpanel.ad.sed ||
  1502. echo 'restore of xtpanel/XTpanel.ad.sed failed'
  1503. Wc_c="`wc -c < 'xtpanel/XTpanel.ad.sed'`"
  1504. test 2377 -eq "$Wc_c" ||
  1505.     echo 'xtpanel/XTpanel.ad.sed: original size 2377, current size' "$Wc_c"
  1506. fi
  1507. # ============= xtpanel/README ==============
  1508. if test -f 'xtpanel/README' -a X"$1" != X"-c"; then
  1509.     echo 'x - skipping xtpanel/README (File already exists)'
  1510. else
  1511. echo 'x - extracting xtpanel/README (Text)'
  1512. sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/README' &&
  1513. xtpanel - build an interactive program, from the command line
  1514. X      or using a simple scripting language
  1515. X
  1516. xtpanel provides a quick and easy way of producing a panel
  1517. containing interactive objects such as buttons, sliders, and text
  1518. fields, either from the command line or from an xtpanel script file.
  1519. Each panel object maintains a string representation of its value. When
  1520. the object is modified it updates its value and it can also perform an
  1521. action such as printing its value or calling a system command. Objects
  1522. can make use of the values of other objects in constructing their
  1523. actions, and they can set the values of other objects as the result of
  1524. an action. The result is an interactive X windows program, without the
  1525. need for conventional programming.
  1526. X
  1527. This program is not intended as a replacement for a full featured
  1528. interface programming toolkit like Tk or Dirt or as a replacement for a 
  1529. simple menu builder like xmenu, it falls somewhere in the gap between the two.
  1530. It is intended as an easy to use tool that can be used to add an
  1531. interactive wrapper to all those old programs and shells that you have 
  1532. lying around. 
  1533. X
  1534. X
  1535. Three utilities are provided with xtpanel. All three utilities are
  1536. written as xtpanel scripts. 
  1537. X
  1538. The first is a script generator. This is a collection af xtpanel scripts 
  1539. that can be used to build, examine and test xtpanel script files. 
  1540. It is invoked using the command "xtpanel-generator". The second utility is a
  1541. collection of example scripts and a master script that can be use to
  1542. view and run the examples. It is invoked using the command
  1543. "xtpanel-examples".  A particularly powerful demo is the "lister"
  1544. script example, which is a tool for maneuvering through a Unix
  1545. filesystem and viewing files at any level. The third is a set of
  1546. xtpanel scripts that present information about xtpanel, mostly taken
  1547. from this manual page, in an interactive, menu-driven form. This
  1548. is invoked by doing "xtpanel -help".
  1549. X
  1550. This program uses the X toolkit and the MIT Athena widget
  1551. set.
  1552. X
  1553. COPYRIGHT
  1554. Although xtpanel is not in the public domain, its copyright is not
  1555. very restrictive. Here is the official xtpanel copyright notice:
  1556. .PP
  1557. Copyright 1992 the Board of Trustees of the Leland Stanford Junior
  1558. University.  All Rights Reserved.  Permission is hereby given
  1559. to use, copy, modify, and distribute this software provided
  1560. that (1) copyright and proprietary notices are retained in
  1561. each copy, (2) any files which are modified are identified as such,
  1562. and (3) you do not copy or distribute the software for payment or
  1563. for commercial use without prior written consent from Stanford.
  1564. STANFORD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND
  1565. concerning this software or its use.
  1566. X
  1567. X
  1568. AUTHORS
  1569. Steve Cole (steve@sep.stanford.edu)
  1570. Dave Nichols (dave@sep.stanford.edu)
  1571. Stanford Exploration Project, Department of Geophysics
  1572. Stanford University, Stanford, CA 94305-2215
  1573. SHAR_EOF
  1574. chmod 0664 xtpanel/README ||
  1575. echo 'restore of xtpanel/README failed'
  1576. Wc_c="`wc -c < 'xtpanel/README'`"
  1577. test 2871 -eq "$Wc_c" ||
  1578.     echo 'xtpanel/README: original size 2871, current size' "$Wc_c"
  1579. fi
  1580. # ============= xtpanel/xtpanel_scan.l ==============
  1581. if test -f 'xtpanel/xtpanel_scan.l' -a X"$1" != X"-c"; then
  1582.     echo 'x - skipping xtpanel/xtpanel_scan.l (File already exists)'
  1583. else
  1584. echo 'x - extracting xtpanel/xtpanel_scan.l (Text)'
  1585. sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/xtpanel_scan.l' &&
  1586. %C
  1587. NONSEPAR [^ \t\n\{\}]
  1588. WHITE    [ \t\n]
  1589. ALPHA     [A-Za-z]
  1590. ALPHANUM [A-Za-z0-9_-]
  1591. TAG    {ALPHA}{ALPHANUM}*=
  1592. TAGBRACE {ALPHA}{ALPHANUM}*=\{
  1593. SQ    \'([^']*\'\')*[^']*[']
  1594. DQ    \"([^"]*\"\")*[^"]*["]
  1595. BQ    \`[^`]*[`]
  1596. LEFT    \{
  1597. RIGHT   \}
  1598. X
  1599. X
  1600. %{
  1601. X
  1602. /*
  1603. X * Copyright 1992 the Board of Trustees of the Leland Stanford Junior
  1604. X * University. Official permission to use this software is included in
  1605. X * the documentation. It authorizes you to use this file for any
  1606. X * non-commercial purpose, provided that this copyright notice is not
  1607. X * removed and that any modifications made to this file are commented
  1608. X * and dated in the style of the example below.
  1609. X */
  1610. X
  1611. /*
  1612. X *
  1613. X *  source file:   ./xtpanel/xtpanel-scan.l
  1614. X *
  1615. X * Steve Cole, Dave Nichols (SEP), August 31 1992
  1616. X *      Inserted this sample edit history entry.
  1617. X *      Please log any further modifications made to this file:
  1618. X * Steve Cole, Dave Nichols (SEP), November 20 1992 -  version 2.00
  1619. X * 1) added new objects: toggle, scrollbar, graph.
  1620. X * 2) added new actions: ASSIGN, SET.
  1621. X * 3) objects can have multiple actions.
  1622. X * 4) backquoted strings in actions get executed at action time.
  1623. X */
  1624. X
  1625. /* lexical scanning for xtpanel */
  1626. X
  1627. #include <ctype.h>
  1628. #include <stdio.h>
  1629. #include <string.h>
  1630. X
  1631. #if defined _POSIX_SOURCE
  1632. #include <unistd.h>
  1633. #endif
  1634. X
  1635. #include "tree.h"
  1636. #include "eval_command.h"
  1637. X
  1638. #ifndef MIN
  1639. #define MIN(A,B) (A<B?A:B)
  1640. #endif
  1641. X
  1642. #define MAX_NEST 20
  1643. static int stack_ptr = -1;
  1644. static char *input_buf;
  1645. static char *input_buf_start;
  1646. static char *input_buf_end;
  1647. X
  1648. static entry *entry_stack[MAX_NEST];
  1649. X
  1650. #undef input
  1651. #define input() ((int) *(input_buf++))
  1652. #undef unput
  1653. /* The redundant  =(c) insures side effects of expressions occur */
  1654. #define unput(c) (*(--(input_buf))=(c))
  1655. X
  1656. /* define the look ahead buffer size to something big
  1657. X * This is needed in case they have a very big text 
  1658. X * string in quotes.
  1659. X */
  1660. #undef YYLMAX
  1661. #define YYLMAX 50000
  1662. X
  1663. #define yywrap() xtpanel_wrap()
  1664. #define yylex()  xtpanel_lexscan()
  1665. #define yylook() xtpanel_yylook()
  1666. X
  1667. entry *tree_ent;
  1668. entry *treetop;
  1669. int len;
  1670. int left=0;
  1671. X
  1672. static void syntax_err();
  1673. static int massage();
  1674. X
  1675. /* workhorse to decode xtpanel files; */
  1676. X
  1677. entry* xtpanel_scan( buffer, root )
  1678. char* buffer;
  1679. entry* root;
  1680. {
  1681. X extern int yylex();
  1682. X
  1683. X /* note the input buffer should be null terminated */
  1684. X input_buf = buffer;
  1685. X input_buf_start = input_buf;
  1686. X input_buf_end = input_buf + strlen(input_buf) - 1;
  1687. X
  1688. X /* all the info we find will be stored under the root entry */
  1689. X push_entry( root );
  1690. X
  1691. X yylex();
  1692. X if( left > 0 ) {
  1693. X    fprintf(stderr," %d unmatched left braces present \n",left);
  1694. X    exit(-1);
  1695. X }
  1696. X if( left < 0 ) {
  1697. X    fprintf(stderr," %d unmatched right braces present \n",-left);
  1698. X    exit(-1);
  1699. X }
  1700. X
  1701. }
  1702. X
  1703. X
  1704. %}
  1705. %S FOUNDTAG 
  1706. %%
  1707. <FOUNDTAG>{SQ}        {
  1708. X             len = yyleng-2; tree_ent->value=malloc(len+1);
  1709. X             len = massage(yytext+1,tree_ent->value,len,yytext[0]);
  1710. X             tree_ent->value[len]='\0';  
  1711. X             add_child( treetop, tree_ent );
  1712. X             BEGIN 0; 
  1713. X             }
  1714. <FOUNDTAG>{BQ}        {
  1715. X             len = yyleng-2; yytext[yyleng-1] = '\0';
  1716. X             tree_ent->value = eval_command(yytext+1);
  1717. X             add_child( treetop, tree_ent );
  1718. X             BEGIN 0; 
  1719. X             }
  1720. <FOUNDTAG>{DQ}        {
  1721. X             len = yyleng-2; tree_ent->value=malloc(len+1);
  1722. X             len = massage(yytext+1,tree_ent->value,len,yytext[0]);
  1723. X             tree_ent->value[len]='\0'; 
  1724. X             add_child( treetop, tree_ent );
  1725. X             BEGIN 0; 
  1726. X             }
  1727. <FOUNDTAG>[^'"]{NONSEPAR}*    {
  1728. X             len=yyleng; tree_ent->value=malloc(len+1);
  1729. X              bcopy(yytext,tree_ent->value,len+1); 
  1730. X             tree_ent->value[len]='\0'; 
  1731. X             add_child( treetop, tree_ent );
  1732. X             BEGIN 0; 
  1733. X             }
  1734. ^{TAGBRACE}             { /* start of a new level of braces */
  1735. X             tree_ent = new_entry( yytext, 
  1736. X                    get_taglen(yytext,yyleng-1));
  1737. X                         push_entry( tree_ent );
  1738. X             left++;
  1739. X                 }
  1740. ([ \t]){TAGBRACE}      { /* start of a new level of braces */
  1741. X             tree_ent = new_entry( yytext+1, 
  1742. X                    get_taglen(yytext+1,yyleng-2));
  1743. X             push_entry(tree_ent);
  1744. X             left++;
  1745. X                 }
  1746. {TAG}/{NONSEPAR}    {
  1747. X             tree_ent = new_entry( yytext, yyleng-1 );
  1748. X                         BEGIN FOUNDTAG;
  1749. X             }
  1750. {TAG}{WHITE}        { /* an empty tag */
  1751. X              syntax_err("unexpected empty field ");
  1752. X             }
  1753. {RIGHT}            { /* end of a level of braces */
  1754. X             pop_entry();
  1755. X             left--; 
  1756. X             if( left<0 ) {
  1757. X                syntax_err("unmatched right brace");
  1758. X             }
  1759. X            }
  1760. {LEFT}            { /* found a left brace in the wrong context */
  1761. X              syntax_err("left brace found in an unexpected place");
  1762. X            }
  1763. ^\!.*   /* skip comment lines */;
  1764. .       |
  1765. \n      ;
  1766. %%
  1767. X
  1768. /* get the tag length from a string that may have spaces around the equal */
  1769. int get_taglen( str, len )
  1770. char *str; int len;
  1771. {
  1772. char *temp;
  1773. int ret;
  1774. temp = malloc( len+1); strncpy( temp, str, len ); temp[len]='\0';
  1775. ret= strcspn( temp, " =" ) ;
  1776. free(temp);
  1777. return ret;
  1778. }
  1779. X
  1780. /* print a syntax error, try and give them enough context to figure
  1781. X * out where it is */
  1782. static void  syntax_err( message )
  1783. char *message;
  1784. {
  1785. X    char temp[41];
  1786. X    int lchar,rchar,nchar,i,j,ptrpos;
  1787. X
  1788. X    /* print the error message */
  1789. X    fprintf(stderr,"Syntax Error: %s\n", message);
  1790. X
  1791. X    /* back up to the character causing the error */
  1792. X    input_buf--; 
  1793. X
  1794. X    /* print enough characters on either side to give he user some context*/
  1795. X    lchar = MIN( 20, input_buf - input_buf_start );
  1796. X    rchar = MIN( 20, input_buf_end - input_buf);
  1797. X    nchar = lchar+rchar+1;
  1798. X    strncpy( temp, (input_buf-lchar), nchar ); temp[nchar] = '\0';
  1799. X    fprintf(stderr,"%s\n",temp);
  1800. X
  1801. X    /* back up looking for a newline or the start of string */
  1802. X    ptrpos = lchar;
  1803. X    for( j=lchar-1; j>=0 ; j-- ){ 
  1804. X       if( temp[j] == '\n' ) { 
  1805. X         ptrpos=lchar-j-1;
  1806. X         break; 
  1807. X       }
  1808. X    }
  1809. X
  1810. X    /* now put a marker that points at the error */
  1811. X    for( i=0; i<ptrpos; i++ ) temp[i]=' ';
  1812. X    temp[ptrpos]='^'; temp[ptrpos+1]='\0';
  1813. X    strcat( temp, "--- error here (I think) ");
  1814. X    fprintf(stderr,"%s\n",temp);
  1815. X    exit(-1);
  1816. }
  1817. X
  1818. push_entry( ent )
  1819. entry* ent;
  1820. {
  1821. if( stack_ptr >=0 ) add_child( entry_stack[stack_ptr], ent );
  1822. stack_ptr++;
  1823. if( stack_ptr >MAX_NEST ){
  1824. X   fprintf(stderr," items nested too deeply, only %d levels supported\n",
  1825. X            MAX_NEST);
  1826. X   exit(-1);
  1827. }
  1828. entry_stack[stack_ptr] = ent;
  1829. treetop = entry_stack[stack_ptr];
  1830. }
  1831. X
  1832. X
  1833. pop_entry()
  1834. {
  1835. stack_ptr--;
  1836. if( stack_ptr >= 0 ) treetop = entry_stack[stack_ptr] ;
  1837. }
  1838. X
  1839. int
  1840. yywrap()
  1841. {
  1842. X    pop_entry();
  1843. X    if(stack_ptr < 0) return(1);
  1844. X    return(0);
  1845. }
  1846. X
  1847. X
  1848. /* play with quoted strings and newlines etc. */
  1849. static int
  1850. massage(string,out,len,quote)
  1851. register char *string, *out;
  1852. register int len, quote;
  1853. {
  1854. X  register int i,j;
  1855. X  for(i=0,j=0; i<len-1; j++) {
  1856. X    out[j]=string[i++];
  1857. X
  1858. X    if(out[j]==quote) /* compress doubled quotes */
  1859. X      if(string[i]==quote) i++;
  1860. X    
  1861. X    if(out[j]=='\\') {
  1862. X      if(string[i]== 'n') { 
  1863. X       /* turn backslash n "\n" into a newline */
  1864. X           i++; out[j] = '\n';
  1865. X      }else if( string[i] == '\n' ){ /* remove backslash newline */
  1866. X       i++; j--;
  1867. X      }
  1868. X    }
  1869. X    
  1870. X  }
  1871. X  if(i<len) out[j++] = string[i];
  1872. X  return(j);
  1873. }
  1874. SHAR_EOF
  1875. chmod 0664 xtpanel/xtpanel_scan.l ||
  1876. echo 'restore of xtpanel/xtpanel_scan.l failed'
  1877. Wc_c="`wc -c < 'xtpanel/xtpanel_scan.l'`"
  1878. test 6855 -eq "$Wc_c" ||
  1879.     echo 'xtpanel/xtpanel_scan.l: original size 6855, current size' "$Wc_c"
  1880. fi
  1881. # ============= xtpanel/patchlevel.h ==============
  1882. if test -f 'xtpanel/patchlevel.h' -a X"$1" != X"-c"; then
  1883.     echo 'x - skipping xtpanel/patchlevel.h (File already exists)'
  1884. else
  1885. echo 'x - extracting xtpanel/patchlevel.h (Text)'
  1886. sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/patchlevel.h' &&
  1887. static char version[] = "  xtpanel version 2.00 ";
  1888. SHAR_EOF
  1889. chmod 0664 xtpanel/patchlevel.h ||
  1890. echo 'restore of xtpanel/patchlevel.h failed'
  1891. Wc_c="`wc -c < 'xtpanel/patchlevel.h'`"
  1892. test 51 -eq "$Wc_c" ||
  1893.     echo 'xtpanel/patchlevel.h: original size 51, current size' "$Wc_c"
  1894. fi
  1895. # ============= xtpanel/NoImake.cpp ==============
  1896. if test -f 'xtpanel/NoImake.cpp' -a X"$1" != X"-c"; then
  1897.     echo 'x - skipping xtpanel/NoImake.cpp (File already exists)'
  1898. else
  1899. echo 'x - extracting xtpanel/NoImake.cpp (Text)'
  1900. sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/NoImake.cpp' &&
  1901. /* Variable definition for NoImake */
  1902. /* Martin Karrenbach   8-25-92     */
  1903. X
  1904. HOME            =/usr/local
  1905. X
  1906. BINDIR          =${HOME}/bin/X11
  1907. MANDIR          =${HOME}/man
  1908. USRLIBDIR       =${HOME}/lib
  1909. LIBDIR          =${USRLIBDIR}/X11
  1910. INCDIR          =${HOME}/include
  1911. X
  1912. #if defined(HP700)
  1913. LIBDIR          =/usr/lib/X11R4
  1914. #endif
  1915. X
  1916. RESOURCES       =${LIBDIR}/app-defaults
  1917. APPDEFAULTS     =Xtpanel
  1918. X
  1919. /* you normally should not have to modify below here, unless you add */
  1920. /* specific options for new machines                                 */
  1921. X
  1922. SUBDIRS = help generator examples
  1923. X
  1924. CPP             = /lib/cpp
  1925. X
  1926. CCOPTIONS       = -O
  1927. X
  1928. #if defined(SUN4)
  1929. CCOPTIONS       = -O -pipe
  1930. #endif
  1931. X
  1932. #if defined(HP700)
  1933. CCOPTIONS       = -O -Aa -D_HPUX_SOURCE
  1934. #endif
  1935. X
  1936. STD_DEFINES    = -D_NO_PROTO 
  1937. X
  1938. #if defined(RS6000)
  1939. STD_DEFINES    = -DSYSV -DAIXV3
  1940. #endif
  1941. X
  1942. EXTRA_DEFINES  = -DSYS_XTPANELDIR=\"$(SYS_XTPANELDIR)\"
  1943. X
  1944. STD_INCLUDES   = -I$(INCDIR) -I.
  1945. X
  1946. XXAWCLIENTLIBS  = -lXaw -lXmu -lXt -lXext -lX11
  1947. X
  1948. INCLUDES =  $(EXTRA_INCLUDES) $(STD_INCLUDES)
  1949. DEFINES  =  $(STD_DEFINES)    $(EXTRA_DEFINES) 
  1950. X
  1951. CFLAGS  = $(CDEBUGFLAGS) $(CCOPTIONS) $(DEFINES) $(INCLUDES) 
  1952. X
  1953. SYSLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  1954. X
  1955. LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS) $(LOCAL_LDFLAGS) -L$(LIBDIR) \
  1956. X            -L$(USRLIBDIR) $(LIBS)
  1957. X
  1958. RM      =  /bin/rm -f *.o core
  1959. X
  1960. RM_CMD      =  /bin/rm -f
  1961. X
  1962. INSTALL = install
  1963. X
  1964. MKDIRHIER = mkdirhier
  1965. X
  1966. /* all makefiles will have these rules  */
  1967. all::
  1968. X
  1969. clean::
  1970. X    $(RM_CMD) "#"*
  1971. SHAR_EOF
  1972. chmod 0664 xtpanel/NoImake.cpp ||
  1973. echo 'restore of xtpanel/NoImake.cpp failed'
  1974. Wc_c="`wc -c < 'xtpanel/NoImake.cpp'`"
  1975. test 1457 -eq "$Wc_c" ||
  1976.     echo 'xtpanel/NoImake.cpp: original size 1457, current size' "$Wc_c"
  1977. fi
  1978. # ============= xtpanel/NoImake.m4 ==============
  1979. if test -f 'xtpanel/NoImake.m4' -a X"$1" != X"-c"; then
  1980.     echo 'x - skipping xtpanel/NoImake.m4 (File already exists)'
  1981. else
  1982. echo 'x - extracting xtpanel/NoImake.m4 (Text)'
  1983. sed 's/^X//' << 'SHAR_EOF' > 'xtpanel/NoImake.m4' &&
  1984. undefine(`include')
  1985. X
  1986. define(MakeSubdirs,
  1987. all::
  1988. X    for dir in $1 ; do (echo Build in $$dir; cd $$dir ; make ) ; done
  1989. clean::
  1990. X    for dir in $1 ; do (echo Clean in $$dir; cd $$dir ; make  clean) ; done
  1991. install::
  1992. X    for dir in $1; do (echo Install in $$dir; cd $$dir; make install); done
  1993. )
  1994. X
  1995. define(DependSubdirs,
  1996. depend::
  1997. X    for dir in $1 ; do (cd $$dir ; make depend) ; done
  1998. )
  1999. X
  2000. define(NormalLibraryObjectRule,)
  2001. X
  2002. define(NormalLibraryTarget,
  2003. lib$1.a: $2
  2004. X    rm -f lib$1.a
  2005. X    ar r lib$1.a $2
  2006. X    ranlib lib$1.a
  2007. clean::
  2008. X    rm -f lib$1.a $2
  2009. )
  2010. X
  2011. define(LintLibraryTarget,)
  2012. X
  2013. define(CleanTarget,)
  2014. X
  2015. define(TagsTarget,
  2016. tags::
  2017. X    etags *.c *.h
  2018. )
  2019. X
  2020. define(NormalLintTarget,)
  2021. X
  2022. define(NormalProgramTarget,
  2023. $1:     $2
  2024. X    ${CC} ${CFLAGS} -o $1 $2 $4 $5
  2025. X    clean::
  2026. X        rm -f $1 $2
  2027. )
  2028. X
  2029. define(SingleProgramTarget,
  2030. $1:     $(OBJS)
  2031. X    ${CC} ${CFLAGS} -o $1 $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(SYSLIBS)
  2032. clean:: rm -f $1 $2
  2033. install::
  2034. X    MakeDir($(BINDIR))
  2035. X    install -c -s $1 $(BINDIR)
  2036. )
  2037. X
  2038. define(ComplexProgramTarget,
  2039. $1:     $(OBJS)
  2040. X    ${CC} ${CFLAGS} -o $1 $(OBJS)  $(LDOPTIONS) $(LOCAL_LIBRARIES) $(SYSLIBS)
  2041. clean::
  2042. X    rm -f $1 $2
  2043. install::
  2044. X    MakeDir($(BINDIR))
  2045. X    install -c -s $1 $(BINDIR)
  2046. )
  2047. X
  2048. define(InstallProgram,
  2049. install:: $1
  2050. X    MakeDir($2)
  2051. X    install -c -s $1 $2
  2052. )
  2053. X
  2054. define(InstallNonExec,
  2055. install:: $1
  2056. X    MakeDir($2)
  2057. X    install -c $1 $2
  2058. )
  2059. X
  2060. define(InstallScript,
  2061. install:: $1.script
  2062. X    MakeDir($2)
  2063. X    install -c -m 555 $1.script $2/$1
  2064. )
  2065. X
  2066. define(InstallManPage,
  2067. install:: $1.man
  2068. X    MakeDir($2)
  2069. X    install -c $1.man $2/$1.1
  2070. )
  2071. X
  2072. define(InstallAppDefaults,
  2073. install:: $1.ad
  2074. X    MakeDir($(RESOURCES))
  2075. X    install -c $1.ad $(RESOURCES)/$1
  2076. )
  2077. define(DependTarget,)
  2078. X
  2079. define(XawClientLibs,$(XAWCLIENTLIBS))
  2080. X
  2081. define(MakeDir,
  2082. X    @if [ -d $1  ]; then set +x; \
  2083. X    else (set -x; mkdir $1 ); fi)
  2084. X
  2085. define(InstallSubdirs,
  2086. install::
  2087. X    for dir in $1 ; \
  2088. X    do (cd $$dir ;     \
  2089. X    echo "installing" "in $(CURRENT_DIR)/$$dir...";  \
  2090. X    $(MAKE) $(MFLAGS) DESTDIR='$(DESTDIR)' install);  \
  2091. X    done
  2092. )
  2093. X
  2094. define(CleanSubdirs,
  2095. clean::
  2096. X    for i in $1 ; \
  2097. X    do \
  2098. X    (cd $$i ; echo "cleaning" "in $(CURRENT_DIR)/$$i..."; \
  2099. X    $(MAKE) $(MFLAGS) RM_CMD='$(RM_CMD)' clean); \
  2100. X    done
  2101. )
  2102. X
  2103. define(NamedTargetSubdirs,
  2104. $1::
  2105. X    for i in $2 ;\
  2106. X    do \
  2107. X    (cd $$i ; echo $3 "in $(CURRENT_DIR)/$$i..."; \
  2108. X    $(MAKE) $(MFLAGS) $4 $5); \
  2109. X    done
  2110. )
  2111. X
  2112. X
  2113. define(MakefileSubdirs,
  2114. Makefile::
  2115. X    echo "Makefile created with NoImake"
  2116. X    echo "Rerun NoImake at the top level"
  2117. )
  2118. X
  2119. define(InstallMultipleFlags,
  2120. install:: $1
  2121. X    MakeDir($(DESTDIR) $2)
  2122. X    for i in $1; do \
  2123. X      (set -x; $(INSTALL) -c $3 $$i $(DESTDIR) $2); \
  2124. X    done
  2125. )
  2126. X
  2127. define(MakeDirectories,
  2128. $1::
  2129. X    for i in $2; do if [ -d $(DESTDIR)$$i ]; then \
  2130. X    set +x; else  (set -x; $(MKDIRHIER) $(DESTDIR)$$i); fi \
  2131. X    done
  2132. )
  2133. SHAR_EOF
  2134. chmod 0664 xtpanel/NoImake.m4 ||
  2135. echo 'restore of xtpanel/NoImake.m4 failed'
  2136. Wc_c="`wc -c < 'xtpanel/NoImake.m4'`"
  2137. test 2598 -eq "$Wc_c" ||
  2138.     echo 'xtpanel/NoImake.m4: original size 2598, current size' "$Wc_c"
  2139. fi
  2140. true || echo 'restore of xtpanel/button.c failed'
  2141. echo End of part 5, continue with part 6
  2142. exit 0
  2143. -----------------------------------------------------------------
  2144. Steve Cole  (steve@sep.stanford.edu, apple!sep!steve)
  2145. Department of Geophysics, Stanford University, Stanford, CA 94305
  2146.