home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume17 / bricons / part02 < prev    next >
Encoding:
Text File  |  1992-04-13  |  44.3 KB  |  1,703 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!mips!msi!dcmartin
  3. From: bri@ukc.ac.uk
  4. Subject: v17i062: bricons - command panel, Part02/02
  5. Message-ID: <1992Apr14.144611.9250@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Nntp-Posting-Host: fascet
  9. Organization: Molecular Simulations, Inc.
  10. References: <csx-17i061-bricons@uunet.UU.NET>
  11. Date: Tue, 14 Apr 1992 14:46:11 GMT
  12. Approved: dcmartin@msi.com
  13. Lines: 1688
  14.  
  15. Submitted-by: bri@ukc.ac.uk
  16. Posting-number: Volume 17, Issue 62
  17. Archive-name: bricons/part02
  18.  
  19. # this is part.02 (part 2 of a multipart archive)
  20. # do not concatenate these parts, unpack them in order with /bin/sh
  21. # file bricons.l continued
  22. #
  23. if test ! -r _shar_seq_.tmp; then
  24.     echo 'Please unpack part 1 first!'
  25.     exit 1
  26. fi
  27. (read Scheck
  28.  if test "$Scheck" != 2; then
  29.     echo Please unpack part "$Scheck" next!
  30.     exit 1
  31.  else
  32.     exit 0
  33.  fi
  34. ) < _shar_seq_.tmp || exit 1
  35. if test ! -f _shar_wnt_.tmp; then
  36.     echo 'x - still skipping bricons.l'
  37. else
  38. echo 'x - continuing file bricons.l'
  39. sed 's/^X//' << 'SHAR_EOF' >> 'bricons.l' &&
  40. .LP
  41. Please do not specify the BitmapFilePath in the Xbricons resource file as
  42. it will be ignored by the program.
  43. .LP
  44. This program will read a .briconsrc file from the current directory.  If the
  45. file to be read is in another directory then place the following line in the 
  46. &\.X11defaults or Xbricons resource file:
  47. .sp
  48. .ce
  49. *icon_file:     /usr/mydir/.briconsrc
  50. .SH FILES
  51. .LP
  52. The Xbricons file specifies the required resources.  To make sure the program
  53. uses the resources file set the following line in your .login:
  54. .ce
  55. setenv  XUSERFILESEARCHPATH ~/app_defaults/%N
  56. .LP
  57. and place all all resources in the app_defaults directory.
  58. .SH WIDGETS
  59. .LP
  60. The bricons program is a toolkit-based application which consists of a 
  61. combination of widgets.  In order to specify resources, it is useful to know
  62. the hierarchy of the widgets which compose bricons.  In the list below, 
  63. indentation indicates hierarchical structure.  The widget class name is given 
  64. first, followed by the widget instance name.
  65. .sp
  66. .nf
  67. X    Xbricons    toplevel    
  68. X        Form    box
  69. X            Command    action[18]
  70. X            OverrideShell    popup_shell
  71. X                Form    popup_layout
  72. X                Command    sub_action[10]
  73. .fi
  74. .SH EXAMPLE
  75. .LP
  76. Below is an example of a simple \&.briconsrc file:
  77. .sp
  78. .nf
  79. # <-- a line starting with a '#' is a comment line
  80. #
  81. #       Bri's icon file
  82. #
  83. X
  84. # first line must have keyword %icon or %text
  85. # to indicate if button is an icon
  86. X
  87. %icon calculator
  88. xcalc
  89. %text Games\\n sub\\n menu
  90. %sub_menu
  91. X    %text xeyes
  92. X    xeyes
  93. X    %text othello
  94. X    othello 
  95. %end_sub_menu
  96. .if
  97. .sp
  98. .SH BUGS
  99. After selecting the source button the buttons may not be re-displayed 
  100. correctly.  Selecting the source button a second time may help.
  101. .SH AUTHOR
  102. Bruce R Ingram, University of Kent at Canterbury.
  103. SHAR_EOF
  104. echo 'File bricons.l is complete' &&
  105. chmod 0644 bricons.l ||
  106. echo 'restore of bricons.l failed'
  107. Wc_c="`wc -c < 'bricons.l'`"
  108. test 6362 -eq "$Wc_c" ||
  109.     echo 'bricons.l: original size 6362, current size' "$Wc_c"
  110. rm -f _shar_wnt_.tmp
  111. fi
  112. # ============= bricons.txt ==============
  113. if test -f 'bricons.txt' -a X"$1" != X"-c"; then
  114.     echo 'x - skipping bricons.txt (File already exists)'
  115.     rm -f _shar_wnt_.tmp
  116. else
  117. > _shar_wnt_.tmp
  118. echo 'x - extracting bricons.txt (Text)'
  119. sed 's/^X//' << 'SHAR_EOF' > 'bricons.txt' &&
  120. X
  121. X
  122. X
  123. BRICONS(l)        MISC. REFERENCE MANUAL PAGES         BRICONS(l)
  124. X
  125. X
  126. X
  127. NAME
  128. X     bricons - quick start  up  utility  for  applications  using
  129. X     text, icons and pop-up menus an X display
  130. X
  131. SYNOPSIS
  132. X     bricons  [options]
  133. X     [-file] [-col] [-help] [-sensitive]
  134. X
  135. DESCRIPTION
  136. X     Bricons program allows the user to quickly start up applica-
  137. X     tions  by  selecting the appropriate button from the display
  138. X     and pressing the left mouse button.  A maximum of up to six-
  139. X     teen main menu buttons can be displayed. Each main menu but-
  140. X     ton can launch an application or pop-up a sub menu  contain-
  141. X     ing more buttons. The buttons can be represented as a bitmap
  142. X     or as text.
  143. X
  144. X     Information on how the program is  to  present  each  button
  145. X     (either  as a bitmap or text) and the application that is to
  146. X     be executed if that  button  is  selected  is  contained  in
  147. X     script  file  called .briconsrc.  This file should be stored
  148. X     in the user's home directory.
  149. X
  150. X     The .briconsrc file contains a number of key words which are
  151. X     used  to indicate if the button label is some text or a bit-
  152. X     map and if the button is to pop-up a sub menu  or  launch  a
  153. X     program.  These key words are explained below:
  154. X
  155. X     The .briconsrc file should start with the keyword  %icon  or
  156. X     %text  The key word %icon indicates that the button label is
  157. X     a bitmap.  This should be followed by the file name contain-
  158. X     ing the bitmap.  For example:
  159. X
  160. X                           %icon clock.icon
  161. X
  162. X     The key word %text indicates that the button label  is  some
  163. X     text.   The  text can be split over three lines by using the
  164. X     new line character \n.  For example:
  165. X
  166. X                      %text Line1\nLine2\nLine3
  167. X
  168. X     would be presented as:
  169. X                                Line1
  170. X                                Line2
  171. X                                Line3
  172. X
  173. X     Once a  button  has  been  selected  it  is  prevented  from
  174. X     accidentally  being  re-selected by "graying out" the button
  175. X     (default action).  Sometimes however it maybe  desirable  to
  176. X     allow the button to be selected more than once.  This can be
  177. X     done be using the keyword %icon+ or %text+
  178. X
  179. X
  180. X
  181. X
  182. Sun Release 4.1   Last change: 28th March 1992                  1
  183. X
  184. X
  185. X
  186. X
  187. X
  188. X
  189. BRICONS(l)        MISC. REFERENCE MANUAL PAGES         BRICONS(l)
  190. X
  191. X
  192. X
  193. X     The next line in the .briconsrc file should  either  contain
  194. X     the key word %sub_menu or the application to be started.  If
  195. X     the name of an application  is given then a check is made to
  196. X     see if such an program can be executed.  If the program does
  197. X     not exist or is not in the users path then an error  message
  198. X     is printed and the button associated with the application is
  199. X     ignored.
  200. X
  201. X     If the key word %sub_menu is used then a pop-up sub menu  is
  202. X     created.   Any further buttons defined in the briconsrc file
  203. X     will appear in the sub menu for that button  until  the  key
  204. X     word  %end_sub_menu  is found.  A maximum of ten buttons are
  205. X     allowed in a single pop-up sub menu.
  206. X
  207. X     Any line in the .briconsrc file starting with a #  character
  208. X     is treated as a comment and will be ignored.
  209. X
  210. X     This program has four default buttons labelled source, edit,
  211. X     help  and  quit.   The  edit  button allows the user to edit
  212. X     there icon file (default being an empty source button causes
  213. X     the  program  to  distory  all  the  current  buttons  being
  214. X     displayed and re-read the icon file and display the new but-
  215. X     tons.
  216. X
  217. OPTIONS
  218. X     bricons accepts all of  the  standard  X   Toolkit   command
  219. X     line options along with the additional options listed below:
  220. X
  221. X     -file
  222. X          Tells the program to read  this  file  instead  of  the
  223. X          default file.
  224. X
  225. X     -col Indicates the number of  buttons  in  a  column  before
  226. X          starting  a  new row.  The default number of columns is
  227. X          15.
  228. X
  229. X     -help
  230. X          Tells the program the path for the help file.
  231. X
  232. X     -sensitive
  233. X          Toggle used for default "graying out" of selected  but-
  234. X          tons.   If  set  to  TRUE  then buttons will "gray out"
  235. X          unless specifically requested not to.
  236. X
  237. XX DEFAULTS
  238. X     The bricons program reads the .Xdefaults file  and  Xbricons
  239. X     resource  file  during  startup  and  uses  the  appropriate
  240. X     resource  specification  to  customise  the  appearance   or
  241. X     characteristics  of  its  display.  This program understands
  242. X     all of the core resource names and classes as well as:
  243. X
  244. X     no_of_cols
  245. X
  246. X
  247. X
  248. Sun Release 4.1   Last change: 28th March 1992                  2
  249. X
  250. X
  251. X
  252. X
  253. X
  254. X
  255. BRICONS(l)        MISC. REFERENCE MANUAL PAGES         BRICONS(l)
  256. X
  257. X
  258. X
  259. X          Specifies the number of buttons in a column.
  260. X
  261. X     icon_file
  262. X          Specifies path name for icon file to be read.
  263. X
  264. X     help_file
  265. X          Specifies path name for help file.
  266. X
  267. SETTING BITMAP DIRECTORIES
  268. X     This program will search the default  bitmap  directory  for
  269. X     any bitmaps that are to be used to represent buttons. If the
  270. X     user wishes the program to search other directories for bit-
  271. X     map  files  then  this  should  be  specified  in  the users
  272. X     .X11defaults file.  *BitmapFilePath: should  be  added  fol-
  273. X     lowed  by  colon separated path names where the bitmap files
  274. X     can be found.  For example:
  275. X
  276. X     *BitmapFilePath:    /usr/local/include/X11/bitmaps:/usr/mydir/bitmaps
  277. X
  278. X     Please do not specify the  BitmapFilePath  in  the  Xbricons
  279. X     resource file as it will be ignored by the program.
  280. X
  281. X     This program will read a .briconsrc file  from  the  current
  282. X     directory.   If  the file to be read is in another directory
  283. X     then place the following line in the &.X11defaults or  Xbri-
  284. X     cons resource file:
  285. X
  286. X                *icon_file:     /usr/mydir/.briconsrc
  287. X
  288. FILES
  289. X     The Xbricons file specifies the required resources.  To make
  290. X     sure  the  program uses the resources file set the following
  291. X     line in your .login:
  292. X            setenv  XUSERFILESEARCHPATH ~/app_defaults/%N
  293. X
  294. X     and place all all resources in the app_defaults directory.
  295. X
  296. WIDGETS
  297. X     The bricons program is  a  toolkit-based  application  which
  298. X     consists  of  a combination of widgets.  In order to specify
  299. X     resources, it is useful to know the hierarchy of the widgets
  300. X     which compose bricons.  In the list below, indentation indi-
  301. X     cates hierarchical structure.   The  widget  class  name  is
  302. X     given first, followed by the widget instance name.
  303. X
  304. X          Xbricons  toplevel
  305. X               Form box
  306. X                    Command   action[18]
  307. X                    OverrideShell  popup_shell
  308. X                         Form popup_layout
  309. X                         Command   sub_action[10]
  310. X
  311. X
  312. X
  313. X
  314. Sun Release 4.1   Last change: 28th March 1992                  3
  315. X
  316. X
  317. X
  318. X
  319. X
  320. X
  321. BRICONS(l)        MISC. REFERENCE MANUAL PAGES         BRICONS(l)
  322. X
  323. X
  324. X
  325. EXAMPLE
  326. X     Below is an example of a simple .briconsrc file:
  327. X
  328. X     # <-- a line starting with a '#' is a comment line
  329. X     #
  330. X     #       Bri's icon file
  331. X     #
  332. X
  333. X     # first line must have keyword %icon or %text
  334. X     # to indicate if button is an icon
  335. X
  336. X     %icon calculator
  337. X     xcalc
  338. X     %text Games\n sub\n menu
  339. X     %sub_menu
  340. X          %text xeyes
  341. X          xeyes
  342. X          %text othello
  343. X          othello
  344. X     %end_sub_menu
  345. X
  346. X
  347. X
  348. BUGS
  349. X     After selecting the source button the  buttons  may  not  be
  350. X     re-displayed  correctly.   Selecting  the  source  button  a
  351. X     second time may help.
  352. X
  353. AUTHOR
  354. X     Bruce R Ingram, University of Kent at Canterbury.
  355. X
  356. X
  357. X
  358. X
  359. X
  360. X
  361. X
  362. X
  363. X
  364. X
  365. X
  366. X
  367. X
  368. X
  369. X
  370. X
  371. X
  372. X
  373. X
  374. X
  375. X
  376. X
  377. X
  378. X
  379. X
  380. Sun Release 4.1   Last change: 28th March 1992                  4
  381. X
  382. X
  383. X
  384. SHAR_EOF
  385. chmod 0644 bricons.txt ||
  386. echo 'restore of bricons.txt failed'
  387. Wc_c="`wc -c < 'bricons.txt'`"
  388. test 7617 -eq "$Wc_c" ||
  389.     echo 'bricons.txt: original size 7617, current size' "$Wc_c"
  390. rm -f _shar_wnt_.tmp
  391. fi
  392. # ============= buttons.c ==============
  393. if test -f 'buttons.c' -a X"$1" != X"-c"; then
  394.     echo 'x - skipping buttons.c (File already exists)'
  395.     rm -f _shar_wnt_.tmp
  396. else
  397. > _shar_wnt_.tmp
  398. echo 'x - extracting buttons.c (Text)'
  399. sed 's/^X//' << 'SHAR_EOF' > 'buttons.c' &&
  400. static char* sccs_buttons_c = "%W%%G%";
  401. X
  402. /* 
  403. X * Copyright 1992 Bruce. R. Ingram.
  404. X * University of Kent at Canterbury, UK
  405. X *
  406. X * Permission  to   use, copy, modify  and  distribute  this  software  and its
  407. X * documentation   for any purpose is hereby granted without fee, provided that
  408. X * the   above  copyright  notice  appear  in  all  copies  and  that both that
  409. X * copyright  notice   and  this   permission   notice  appear  in   supporting
  410. X * documentation,  and  that  the name  of the author and The University  of
  411. X * Kent  at  Canterbury  not be  used in advertising or publicity pertaining to
  412. X * distribution  of  the  software  without specific, written prior permission.
  413. X * The   author  and   The   University   of   Kent at   Canterbury   make  no
  414. X * representations  about  the  suitability  of this  software for any purpose.
  415. X * It is provided "as is" without express or implied warranty.
  416. X *
  417. X * THE   AUTHOR  AND  THE  UNIVERSITY  OF KENT  AT   CANTERBURY  DISCLAIMS ALL
  418. X * WARRANTIES  WITH  REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED  WARRANTIES
  419. X * OF   MERCHANTABILITY  AND  FITNESS,  IN NO  EVENT  SHALL THE AUTHOR  OR THE
  420. X * UNIVERSITY  OF KENT  AT  CANTERBURY  BE LIABLE FOR ANY SPECIAL, INDIRECT  OR
  421. X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS  OF USE,
  422. X * DATA  OR  PROFITS,  WHETHER  IN  AN ACTION OF CONTRACT, NEGLIGENCE  OR OTHER
  423. X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  424. X * OF THIS SOFTWARE.
  425. X *
  426. X * Author:
  427. X *
  428. X * Mr  B. R. Ingram email bri@ukc.ac.uk
  429. */
  430. X
  431. #include "gen.h"
  432. #include "widgets.h"
  433. X
  434. X
  435. extern  int     GetCommand PROTO((char *, char *));
  436. extern  int     GetKeyword PROTO((FILE *));
  437. static  void    CreateSubMenu PROTO((FILE *,int,char *,char *,Info *));
  438. extern  void    Quit PROTO((Widget,XtPointer,XtPointer)),
  439. X        SingleAction PROTO((Widget,XtPointer,XtPointer)),
  440. X        MultiAction PROTO((Widget,XtPointer,XtPointer)),
  441. X                ReadALine PROTO((FILE*,char **)),
  442. X                Source PROTO((Widget,XtPointer,XtPointer));
  443. extern  void    set_popup PROTO((Widget,XEvent *,String *,Cardinal *));
  444. extern  void    GetButtonTitle PROTO((FILE *,char *));
  445. extern  void    CheckForComments PROTO((FILE *));
  446. extern    void    delay PROTO((Widget,XEvent *,String *,Cardinal *));
  447. X
  448. static  void    SetButton PROTO((int,char *,int));
  449. static  void    SetSubMenuButton PROTO((int,char *,int));
  450. static    void    CreatePopupShell PROTO((int));
  451. static    void    CreateSubMenuButton PROTO((int,char *,int));
  452. static    void    DefaultButtons PROTO((Info *,int));
  453. X
  454. #include "trans.h"
  455. X
  456. X
  457. /*
  458. X    The function CreateButtons reads the contents of file data->icon_file
  459. X    the file should contain a list consisting of a button title which
  460. X    can be a string or a bitmap.  This is followed by a command that
  461. X    is to be executed.  For each title and command read correctly from 
  462. X    file a butoon is created. 
  463. */
  464. extern int
  465. CreateButtons(data)
  466. Info    *data;
  467. {
  468. X    int     i = 0;
  469. X    int    is_icon;
  470. X    char    ch, w_buffer[80];
  471. X    char    icon[MAXLINE], path[MAXPATHLEN], ptrans[250];
  472. X    char    *command;
  473. X    FILE    *fp;
  474. X
  475. X    fp = fopen(data->icon_file,"r");
  476. X    if(fp == NULL)
  477. X    {
  478. X        fp = fopen(data->icon_file,"w");
  479. X        (void) fprintf(fp,"# Default .briconsrc file\n");
  480. X        (void) fprintf(fp,"# A line starting with a '#' is a comment line\n");
  481. X        (void) fprintf(fp,"# first line must have keyword %%icon or %%text\n");
  482. X        (void) fprintf(fp,"# to indicate if button is an icon or text\n");
  483. X        (void) fprintf(fp,"# for more information select the help button\n");
  484. X        (void) fprintf(fp,"\n%%text test1\n");
  485. X        (void) fprintf(fp,"xterm\n");
  486. X        fclose(fp);
  487. X        DefaultButtons(data,i);
  488. X        return(i);
  489. X    }
  490. X    GetPath(path);
  491. X    ch = getc(fp);
  492. X    while((ch != EOF) && (i < MAXBUTTONS))
  493. X    {
  494. X        ungetc(ch,fp);
  495. X        is_icon = GetKeyword(fp);
  496. X        if(is_icon == EOF)
  497. X            break;
  498. X        /* get button title & check if it is an icon or text */
  499. X        GetButtonTitle(fp,icon);
  500. X        ReadALine(fp,&command);
  501. X        if((strcmp(command,"%sub_menu\n")) == 0)
  502. X        {
  503. X            /* 
  504. X                create translations for the button that 
  505. X                pops up the sub menu
  506. X            */
  507. X            (void) sprintf(ptrans,pb_Trans,i,popup_menu_name);
  508. X
  509. X            /* create main menu button that will popup sub menu */
  510. X            (void) sprintf(w_buffer,"action%d",i);
  511. X            action[i] = XtVaCreateWidget(
  512. X                    w_buffer,
  513. X                    commandWidgetClass,
  514. X                    box,
  515. X                    NULL);
  516. X
  517. X            XtVaSetValues(action[i],
  518. X                    XtNtranslations,
  519. X                    XtParseTranslationTable(ptrans),
  520. X                    NULL);
  521. X
  522. X            SetButton(is_icon,icon,i);
  523. X            CreateSubMenu(fp,i,icon,path,data); 
  524. X            i++;
  525. X        }
  526. X        else if((is_icon != UNKNOWN) && (GetCommand(path,command)))
  527. X        {
  528. X            (void) sprintf(w_buffer,"action%d",i);
  529. X            action[i] = XtVaCreateWidget(
  530. X                    w_buffer,          /* widget name */    
  531. X                    commandWidgetClass,  /* widget class */
  532. X                    box,                /* parent widget */
  533. X                    NULL);       /* terminate varargs list */
  534. X
  535. X            SetButton(is_icon,icon,i);
  536. X
  537. X            /* add callback for this button */
  538. X
  539. X            if(data->sensitive)
  540. X            {
  541. X                if((is_icon == TEXT) || (is_icon == ICON))
  542. X                    XtAddCallback(action[i],XtNcallback,
  543. X                        SingleAction,command);
  544. X                else
  545. X                    XtAddCallback(action[i],XtNcallback,
  546. X                        MultiAction,command);
  547. X            }
  548. X            else
  549. X            {
  550. X                if((is_icon == TEXT) || (is_icon == ICON))
  551. X                    XtAddCallback(action[i],XtNcallback,
  552. X                        MultiAction,command);
  553. X                else
  554. X                    XtAddCallback(action[i],XtNcallback,
  555. X                        SingleAction,command);
  556. X            }
  557. X            i++;
  558. X        }
  559. X        icon[0] = '\0';
  560. X        ch = getc(fp);
  561. X    }
  562. X    fclose(fp);
  563. X    DefaultButtons(data,i);
  564. X    return(i);
  565. }
  566. X
  567. static    void
  568. SetButton(is_icon,icon,button_num)
  569. int    is_icon;
  570. char    *icon;
  571. int    button_num;
  572. {
  573. X
  574. X    /* if button title is a string then */
  575. X    if((is_icon == TEXT) || (is_icon == TEXTPLUS))
  576. X    {
  577. X        XtVaSetValues(
  578. X            action[button_num],
  579. X            XtNwidth,
  580. X            W_WIDTH,
  581. X            XtNheight,
  582. X            W_HEIGHT,
  583. X            XtNlabel,
  584. X            icon,    /* button title */
  585. X            NULL);
  586. X    }
  587. X    /* if button title is a bitmap then */
  588. X    if((is_icon == ICON) || (is_icon == ICONPLUS))    
  589. X    {
  590. X        XtVaSetValues(
  591. X            action[button_num],
  592. X            XtNwidth,
  593. X            W_WIDTH,
  594. X            XtNheight,
  595. X            W_HEIGHT,
  596. X            XtVaTypedArg,
  597. X            XtNbitmap,
  598. X            XtRString,
  599. X            icon,    /* button title (bitmap) */
  600. X            strlen(icon) +1,
  601. X            NULL);
  602. X    }
  603. }
  604. X
  605. static    void
  606. SetSubMenuButton(is_icon,icon,button_num)
  607. int    is_icon;
  608. char    *icon;
  609. int    button_num;
  610. {
  611. X
  612. X    /* if button title is a string then */
  613. X    if((is_icon == TEXT) || (is_icon == TEXTPLUS))
  614. X    {
  615. X        XtVaSetValues(
  616. X            sub_action[button_num],
  617. X            XtNwidth,
  618. X            W_WIDTH,
  619. X            XtNheight,
  620. X            W_HEIGHT,
  621. X            XtNlabel,
  622. X            icon,    /* button title */
  623. X            NULL);
  624. X    }
  625. X    /* if button title is a bitmap then */
  626. X    if((is_icon == ICON) || (is_icon == ICONPLUS))    
  627. X    {
  628. X        XtVaSetValues(
  629. X            sub_action[button_num],
  630. X            XtNwidth,
  631. X            W_WIDTH,
  632. X            XtNheight,
  633. X            W_HEIGHT,
  634. X            XtVaTypedArg,
  635. X            XtNbitmap,
  636. X            XtRString,
  637. X            icon,    /* button title (bitmap) */
  638. X            strlen(icon) +1,
  639. X            NULL);
  640. X    }
  641. X    if(button_num > 0)
  642. X        XtVaSetValues(sub_action[button_num], XtNfromVert,
  643. X                sub_action[button_num - 1],NULL);
  644. }
  645. X
  646. /*
  647. X    The function PositionButtons places each button next to the 
  648. X    previous button one until the number of buttons equals the 
  649. X    number of columns.  Then a new row is started.
  650. */
  651. extern void
  652. PositionButtons(i,columns)
  653. int    i;
  654. int    columns;
  655. {
  656. X    int    button_no;
  657. X    int    position = 0;
  658. X
  659. X    button_no = 1;
  660. X    while((button_no < columns) && (button_no <= i))
  661. X    {
  662. X        XtVaSetValues(action[button_no],
  663. X            XtNfromHoriz,action[button_no - 1],NULL);
  664. X        button_no++;
  665. X    }
  666. X    position = columns;
  667. X    while(button_no <= i)
  668. X    {
  669. X        if(position == columns)
  670. X        {
  671. X            XtVaSetValues(action[button_no],
  672. X                XtNfromVert,action[button_no - columns],NULL);
  673. X            position = 0;
  674. X        }
  675. X        else
  676. X        {
  677. X            XtVaSetValues(action[button_no],
  678. X                XtNfromVert,action[button_no - columns],NULL);
  679. X            XtVaSetValues(action[button_no],
  680. X                XtNfromHoriz,action[button_no -1],NULL);
  681. X        }
  682. X        position++;
  683. X        button_no++;
  684. X    }
  685. }
  686. X
  687. /*
  688. X    Once all the buttons have been created then make sure they are 
  689. X    managed.
  690. */
  691. extern void
  692. ManageButtons()
  693. {
  694. X    WidgetList      w_list;
  695. X    Cardinal        num_childern, i;
  696. X
  697. X    XtVaGetValues(box,
  698. X        XtNchildren,
  699. X        &w_list,
  700. X        XtNnumChildren,
  701. X        &num_childern,
  702. X        NULL);
  703. X
  704. X    for(i = 0; i < num_childern; i++)
  705. X        XtManageChild(w_list[i]);
  706. }
  707. X
  708. static    void
  709. CreateSubMenu(fp,shell_no,label,path, data)
  710. FILE    *fp;
  711. int    shell_no;
  712. char    *label;
  713. char    *path;
  714. Info    *data;
  715. {
  716. X    int    button_num = 0;
  717. X    int    key_word = 0;
  718. X    int     make_shell = FALSE;
  719. X    char    icon[MAXLINE];
  720. X    char    *command;
  721. X
  722. X    while(button_num < MAXBUTTONS)
  723. X    {
  724. X        key_word = GetKeyword(fp);
  725. X        if(key_word == EOF)
  726. X            break;
  727. X        if(key_word == SUB_MENU)
  728. X            (void) fprintf(stderr,"ERROR: only one sub menu allowed per button\n");
  729. X        else if(key_word == END_SUB_MENU)
  730. X            break;
  731. X        else if(key_word == END)
  732. X            break;
  733. X        else if(key_word == UNKNOWN)
  734. X        {
  735. X            (void) fprintf(stderr,"ERROR: syntax error when reading icon file please check\n");
  736. X        }
  737. X        GetButtonTitle(fp,icon);
  738. X        ReadALine(fp,&command);
  739. X        if(GetCommand(path,command))
  740. X        {
  741. X            if(make_shell == FALSE)
  742. X            {
  743. X                CreatePopupShell(shell_no);
  744. X                make_shell = TRUE;
  745. X            }
  746. X            CreateSubMenuButton(key_word,icon,button_num);
  747. X
  748. X            if(data->sensitive)
  749. X            {
  750. X                if((key_word == TEXT) || (key_word == ICON))
  751. X                    XtAddCallback(sub_action[button_num],
  752. X                    XtNcallback,SingleAction,command);
  753. X                else
  754. X                    XtAddCallback(sub_action[button_num],
  755. X                    XtNcallback,MultiAction,command);
  756. X            }
  757. X            else
  758. X            {
  759. X                if((key_word == TEXT) || (key_word == ICON))
  760. X                    XtAddCallback(sub_action[button_num],
  761. X                    XtNcallback,MultiAction,command);
  762. X                else
  763. X                    XtAddCallback(sub_action[button_num],
  764. X                    XtNcallback,SingleAction,command);
  765. X            }
  766. X
  767. X            XtVaSetValues(sub_action[button_num],
  768. X                    XtNtranslations,
  769. X                    XtParseTranslationTable(cb_Trans),
  770. X                    NULL);
  771. X            button_num++;
  772. X        }
  773. X    }
  774. }
  775. X
  776. static    void
  777. CreatePopupShell(shell_no)
  778. int    shell_no;
  779. {
  780. X
  781. X    popup_shell = XtCreatePopupShell(
  782. X            "popup_menu",
  783. X            overrideShellWidgetClass,
  784. X            action[shell_no],
  785. X            NULL,
  786. X            0);
  787. X
  788. X    XtVaSetValues(popup_shell,
  789. X            XtNtranslations,
  790. X            XtParseTranslationTable(pm_Trans),
  791. X            NULL);
  792. X
  793. X    popup_layout = XtCreateManagedWidget(
  794. X            "popup_layout",
  795. X            formWidgetClass,
  796. X            popup_shell,
  797. X            NULL,
  798. X            0);
  799. }
  800. X
  801. static    void
  802. CreateSubMenuButton(key_word,button_name,button_num)
  803. int    key_word;
  804. char    *button_name;
  805. int    button_num;
  806. {
  807. X    char    w_buffer[80];
  808. X
  809. X    (void) sprintf(w_buffer,"sub_action%d",button_num);
  810. X    sub_action[button_num] = XtVaCreateManagedWidget(
  811. X            w_buffer,
  812. X            commandWidgetClass,
  813. X            popup_layout,
  814. X            NULL);
  815. X
  816. X    SetSubMenuButton(key_word,button_name,button_num); 
  817. }
  818. X
  819. extern    void
  820. set_popup(w,event,params,num_params)
  821. Widget    w;
  822. XXEvent    *event;    /* unused */
  823. String    *params;
  824. Cardinal    *num_params;
  825. {
  826. X    /*
  827. X        position the menu, whose name was passed as the first and
  828. X        only parameter at position (20,5) relative to the widget w.
  829. X    */
  830. X    Widget    a_shell;
  831. X    Position    x,y;
  832. X
  833. X    if(*num_params != 1)
  834. X        XtError("Wrong parameter count passed to set_popup()");
  835. X    
  836. X    /* get the internal Widget id of the named shell */
  837. X    a_shell = XtNameToWidget(toplevel,params[0]);
  838. X    if(a_shell == NULL)
  839. X        XtError("FATAL ERROR: Wrong shell name passed to set_popup()\n\
  840. X            please check icon file is correct");
  841. X    XtTranslateCoords(w,(Position) 5,(Position) 5, &x,&y);
  842. X    XtVaSetValues(a_shell,XtNx,x,XtNy,y,NULL);
  843. }
  844. X
  845. extern    void
  846. delay(w,event,params,num_params)
  847. Widget  w;
  848. XXEvent  *event; /* unused */
  849. String  *params;
  850. Cardinal        *num_params;
  851. {
  852. X    (void) sleep(1);
  853. }
  854. X
  855. static    void
  856. DefaultButtons(data,last_button)
  857. Info    *data;
  858. int    last_button;
  859. {
  860. X    int    string_length;
  861. X    char    w_buffer[80];
  862. X    char    ptrans[250];
  863. X    char    *edit_file, *h_file;
  864. X
  865. X    /* create default sub menu which will contain source, edit & quit */
  866. X    /* buttons.  Default menu button is called Manage  */
  867. X
  868. X    /* create main menu button */
  869. X    (void) sprintf(ptrans,pb_Trans,last_button,popup_menu_name);
  870. X
  871. X    (void) sprintf(w_buffer,"action%d",last_button);
  872. X    action[last_button] = XtVaCreateWidget(
  873. X            w_buffer,
  874. X            commandWidgetClass,
  875. X            box,
  876. X            NULL);
  877. X
  878. X    XtVaSetValues(action[last_button],XtNtranslations,
  879. X            XtParseTranslationTable(ptrans),NULL);
  880. X
  881. X    SetButton(TEXT,"Edit\nIcons",last_button);
  882. X
  883. X    /* create popup shell */
  884. X    CreatePopupShell(last_button);
  885. X
  886. X    CreateSubMenuButton(TEXT,"Source",0);
  887. X
  888. X    XtAddCallback(sub_action[0],XtNcallback,Source,data);
  889. X
  890. X    XtVaSetValues(sub_action[0],XtNtranslations,
  891. X                XtParseTranslationTable(cb_Trans),NULL);
  892. X
  893. X    CreateSubMenuButton(TEXT,"Edit",1);
  894. X
  895. X    string_length = strlen(EDITOR);
  896. X    string_length += strlen(data->icon_file);
  897. X    if((edit_file = malloc(string_length +1)) == NULL)
  898. X    {
  899. X        (void) fprintf(stderr,"ERROR: out of memory for string edit_file.  In function CreateButtons.\n");
  900. X        exit(1);
  901. X    }
  902. X    strcpy(edit_file,EDITOR);
  903. X    strcat(edit_file,data->icon_file);
  904. X
  905. X    XtAddCallback(sub_action[1],XtNcallback,SingleAction,edit_file);
  906. X
  907. X    XtVaSetValues(sub_action[1],XtNtranslations,
  908. X                XtParseTranslationTable(cb_Trans),NULL);
  909. X
  910. X    CreateSubMenuButton(TEXT,"Help",2);
  911. X
  912. X    string_length = 0;
  913. X    string_length = strlen(FORMATTER);
  914. X    string_length = strlen(HELP_VIEWER);
  915. X    string_length += strlen(data->help_file);
  916. X    if((h_file = malloc(string_length +1)) == NULL)
  917. X    {
  918. X        (void) fprintf(stderr,"ERROR: out of memory for string edit_file.  In function CreateButtons.\n");
  919. X        exit(1);
  920. X    }
  921. X    strcpy(h_file,FORMATTER);
  922. X    strcat(h_file,data->help_file);
  923. X    strcat(h_file,HELP_VIEWER);
  924. X    XtAddCallback(sub_action[2],XtNcallback,SingleAction,h_file);
  925. X
  926. X    XtVaSetValues(sub_action[2],XtNtranslations,
  927. X                XtParseTranslationTable(cb_Trans),NULL);
  928. X
  929. X    CreateSubMenuButton(TEXT,"Quit",3);
  930. X
  931. X    XtAddCallback(sub_action[3],XtNcallback,Quit,NULL);
  932. X
  933. X    XtVaSetValues(sub_action[3],XtNtranslations,
  934. X                XtParseTranslationTable(cb_Trans),NULL);
  935. }
  936. X
  937. SHAR_EOF
  938. chmod 0644 buttons.c ||
  939. echo 'restore of buttons.c failed'
  940. Wc_c="`wc -c < 'buttons.c'`"
  941. test 13200 -eq "$Wc_c" ||
  942.     echo 'buttons.c: original size 13200, current size' "$Wc_c"
  943. rm -f _shar_wnt_.tmp
  944. fi
  945. # ============= gen.c ==============
  946. if test -f 'gen.c' -a X"$1" != X"-c"; then
  947.     echo 'x - skipping gen.c (File already exists)'
  948.     rm -f _shar_wnt_.tmp
  949. else
  950. > _shar_wnt_.tmp
  951. echo 'x - extracting gen.c (Text)'
  952. sed 's/^X//' << 'SHAR_EOF' > 'gen.c' &&
  953. static char* sccs_gen_c = "%W%%G%";
  954. X
  955. /* 
  956. X * Copyright 1992 Bruce. R. Ingram.
  957. X * University of Kent at Canterbury, UK
  958. X *
  959. X * Permission  to   use, copy, modify  and  distribute  this  software  and its
  960. X * documentation   for any purpose is hereby granted without fee, provided that
  961. X * the   above  copyright  notice  appear  in  all  copies  and  that both that
  962. X * copyright  notice   and  this   permission   notice  appear  in   supporting
  963. X * documentation,  and  that  the name  of the author and The University  of
  964. X * Kent  at  Canterbury  not be  used in advertising or publicity pertaining to
  965. X * distribution  of  the  software  without specific, written prior permission.
  966. X * The   author  and   The   University   of   Kent at   Canterbury   make  no
  967. X * representations  about  the  suitability  of this  software for any purpose.
  968. X * It is provided "as is" without express or implied warranty.
  969. X *
  970. X * THE   AUTHOR  AND  THE  UNIVERSITY  OF KENT  AT   CANTERBURY  DISCLAIMS ALL
  971. X * WARRANTIES  WITH  REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED  WARRANTIES
  972. X * OF   MERCHANTABILITY  AND  FITNESS,  IN NO  EVENT  SHALL THE AUTHOR  OR THE
  973. X * UNIVERSITY  OF KENT  AT  CANTERBURY  BE LIABLE FOR ANY SPECIAL, INDIRECT  OR
  974. X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS  OF USE,
  975. X * DATA  OR  PROFITS,  WHETHER  IN  AN ACTION OF CONTRACT, NEGLIGENCE  OR OTHER
  976. X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  977. X * OF THIS SOFTWARE.
  978. X *
  979. X * Author:
  980. X *
  981. X * Mr  B. R. Ingram email bri@ukc.ac.uk
  982. */
  983. X
  984. #include "gen.h"
  985. X
  986. static    int    IsExecutable PROTO((char *,char *)), 
  987. X        Executable PROTO((char *));
  988. extern    void    CheckForComments PROTO((FILE *));
  989. X
  990. /*
  991. X    IsExecutable function searches along the users path trying to
  992. X    locate the file program.  If found a check is made to see if it
  993. X    is executable.  If it is TRUE is returned, otherwise FALSE is
  994. X    returned.
  995. */
  996. static int
  997. IsExecutable(path,program)
  998. char    *path;
  999. char    *program;
  1000. {
  1001. X    int i, j;
  1002. X    char    pathname[MAXPATHLEN];
  1003. X
  1004. X    i = 0;
  1005. X    if(*program == '/')
  1006. X    {
  1007. X        if(Executable(program))
  1008. X            return(TRUE);
  1009. X        else
  1010. X            return(FALSE);
  1011. X    }
  1012. X    while (path[i] != '\0')
  1013. X    {
  1014. X        if (path[i] == ' ')
  1015. X            ++i;
  1016. X        for (j = 0; path[i] != ' ' && path[i] != '\0'; ++i, ++j)
  1017. X            pathname[j] = path[i];
  1018. X        pathname[j++] = '/';
  1019. X        strcpy(&pathname[j], program);
  1020. X        if(Executable(pathname)) 
  1021. X            return(TRUE);
  1022. X    }
  1023. X    return(FALSE);
  1024. }
  1025. X
  1026. X
  1027. /*
  1028. X    GetCommand reads a line of text from the file pointed at by file
  1029. X    pointer fp.  It then checks if the first word is a valid command.
  1030. */
  1031. extern int
  1032. GetCommand(path,command)
  1033. char    *path;
  1034. char    *command;
  1035. {
  1036. X    int    i = 0;
  1037. X    int    is_binary = FALSE;
  1038. X    char    prog_name[MAXPATHLEN];
  1039. X    char    *c_ptr;
  1040. X
  1041. X    prog_name[0] = '\0';
  1042. X    if(*command != NULL)
  1043. X    {
  1044. X        c_ptr = command;
  1045. X        /* get first word from line of text */
  1046. X        while((*c_ptr != ' ') && (*c_ptr != '\0') && (*c_ptr != '\n'))
  1047. X            prog_name[i++] = *c_ptr++;
  1048. X        prog_name[i] = '\0';
  1049. X        if(IsExecutable(path,prog_name))
  1050. X            is_binary = TRUE;
  1051. X        else
  1052. X        {
  1053. X            (void) fprintf(stderr,"ERROR: %s ",prog_name);
  1054. X            (void) fprintf(stderr,"is not executable or file not found\n");
  1055. X        }
  1056. X    }
  1057. X    return(is_binary);
  1058. }
  1059. X
  1060. X
  1061. X
  1062. /*
  1063. X    The function GetPath fills in the given char array with the value of 
  1064. X    the environmental variable PATH, with spaces instead of colons, and a 
  1065. X    '.' in the appropriate place.
  1066. */
  1067. extern void
  1068. GetPath(p)
  1069. char *p;
  1070. {
  1071. X        char *path;
  1072. X
  1073. X        path = getenv("PATH");
  1074. X        if (*path == ':')
  1075. X                *p++ = '.';
  1076. X        while (*path != '\0') {
  1077. X                if (*path == ':')
  1078. X                        *p++ = ' ';
  1079. X                else
  1080. X                        *p++ = *path;
  1081. X                ++path;
  1082. X        }
  1083. X        if (*--path == ':')
  1084. X                *p++ = '.';
  1085. X        *p = '\0';
  1086. }
  1087. X
  1088. X
  1089. /*
  1090. X    The Executable  function returns True if file exists and is a directly 
  1091. X    executable Regular file. Otherwise False is returned.
  1092. X */
  1093. static int
  1094. Executable(file)
  1095. char *file;
  1096. {
  1097. X        struct stat st_buf;
  1098. X
  1099. X        if ( stat(file, &st_buf) != 0 )
  1100. X           return (FALSE); 
  1101. X        else 
  1102. X           return (S_IFREG & st_buf.st_mode) && (access(file,1)==0) && 
  1103. X        ( !(S_IFDIR & st_buf.st_mode) ) ; 
  1104. }
  1105. X
  1106. extern    void
  1107. ReadALine(fp,command)
  1108. FILE    *fp;
  1109. char    **command;
  1110. {
  1111. X    char    c_line[MAXLINE];
  1112. X
  1113. X    c_line[0] = '\0';
  1114. X    CheckForComments(fp);
  1115. X    fgets(c_line,MAXLINE,fp); 
  1116. X    if(*c_line != NULL)
  1117. X    {
  1118. X        *command = strcpy(malloc(strlen(c_line) + 1), c_line);
  1119. X        if(*command == NULL)
  1120. X        {
  1121. X            (void) fprintf(stderr,"ERROR: out of memory \n");
  1122. X            exit(1);
  1123. X        }
  1124. X    }
  1125. }
  1126. X
  1127. X
  1128. extern int
  1129. GetKeyword(fp)
  1130. FILE    *fp;
  1131. {
  1132. X    int    symbol = FALSE;
  1133. X    int    valid = 0;
  1134. X    char    label[20];
  1135. X
  1136. X    CheckForComments(fp);
  1137. X    valid = fscanf(fp,"%s",label);
  1138. X    if(valid == EOF)
  1139. X        symbol = EOF;
  1140. X    else if((strcmp(label,"%icon")) == 0)
  1141. X        symbol = ICON;
  1142. X    else if((strcmp(label,"%icon+")) == 0)
  1143. X        symbol = ICONPLUS;
  1144. X    else if((strcmp(label,"%text")) == 0)
  1145. X        symbol = TEXT;
  1146. X    else if((strcmp(label,"%text+")) == 0)
  1147. X        symbol = TEXTPLUS;
  1148. X    else if((strcmp(label,"%sub_menu")) == 0)
  1149. X        symbol = SUB_MENU;
  1150. X    else if((strcmp(label,"%end_sub_menu")) == 0)
  1151. X        symbol = END_SUB_MENU;
  1152. X    else if((strcmp(label,"\0")) == 0)
  1153. X        symbol = END;
  1154. X    else
  1155. X        symbol = UNKNOWN;
  1156. X    return(symbol);
  1157. }
  1158. X
  1159. X
  1160. /*
  1161. X    Read the button title from file pointed at by file pointer fp. 
  1162. */
  1163. extern    void
  1164. GetButtonTitle(fp,title)
  1165. FILE    *fp;
  1166. char    *title;
  1167. {
  1168. X    int    i = 0;
  1169. X    char    ch;    
  1170. X
  1171. X    title[0] = '\0';
  1172. X    ch = getc(fp);
  1173. X    if (isspace(ch))
  1174. X    {
  1175. X        while (((ch = getc(fp)) != EOF) && (isspace(ch)))
  1176. X                    ;
  1177. X    }
  1178. X    ungetc(ch,fp);
  1179. X    while(((ch = getc(fp)) != EOF) && (i < MAXLINE) && (ch != '\n'))
  1180. X    {
  1181. X        if(ch == '\\')
  1182. X        {
  1183. X            ch = getc(fp);
  1184. X            if(ch == EOF)
  1185. X                break;
  1186. X            if(ch == 'n')
  1187. X            {
  1188. X                title[i] = '\n';
  1189. X                i++;
  1190. X                ch = getc(fp);
  1191. X            }
  1192. X            else
  1193. X            {
  1194. X                title[i] = '\\';
  1195. X                i++;
  1196. X                title[i] = ch;
  1197. X            }
  1198. X        }
  1199. X        title[i] = ch;
  1200. X        i++;
  1201. X    }
  1202. X    title[i] = '\0';
  1203. }
  1204. X
  1205. X
  1206. /*
  1207. X    Any line of text beginning with a "#" character is a comment line.
  1208. X    This function looks for comment lines and ignores them.
  1209. */
  1210. extern void
  1211. CheckForComments(fp)
  1212. FILE    *fp;
  1213. {
  1214. X    int    is_comment = TRUE;
  1215. X    char    ch;
  1216. X
  1217. X    ch = getc(fp);
  1218. X    while(is_comment)
  1219. X    {
  1220. X        if(ch == '#')
  1221. X        {
  1222. X            while((ch != EOF) && (ch != '\n'))
  1223. X                ch = getc(fp);
  1224. X        }
  1225. X        else if(isspace(ch))
  1226. X        {
  1227. X             while((ch != EOF) && (isspace(ch)))
  1228. X                ch = getc(fp);
  1229. X        }
  1230. X        else
  1231. X        {
  1232. X            is_comment = FALSE;
  1233. X            ungetc(ch,fp);
  1234. X        }
  1235. X    }
  1236. }
  1237. X
  1238. SHAR_EOF
  1239. chmod 0644 gen.c ||
  1240. echo 'restore of gen.c failed'
  1241. Wc_c="`wc -c < 'gen.c'`"
  1242. test 6188 -eq "$Wc_c" ||
  1243.     echo 'gen.c: original size 6188, current size' "$Wc_c"
  1244. rm -f _shar_wnt_.tmp
  1245. fi
  1246. # ============= gen.h ==============
  1247. if test -f 'gen.h' -a X"$1" != X"-c"; then
  1248.     echo 'x - skipping gen.h (File already exists)'
  1249.     rm -f _shar_wnt_.tmp
  1250. else
  1251. > _shar_wnt_.tmp
  1252. echo 'x - extracting gen.h (Text)'
  1253. sed 's/^X//' << 'SHAR_EOF' > 'gen.h' &&
  1254. static char* sccs_gen_h = "%W%%G%";
  1255. X
  1256. #include <stdio.h>
  1257. #include <sys/param.h>
  1258. #include <sys/stat.h>
  1259. #include <X11/Xos.h>
  1260. #include <X11/Intrinsic.h>
  1261. #include <X11/StringDefs.h>
  1262. #include <X11/Xaw/Form.h>
  1263. #include <X11/Xaw/Command.h>
  1264. #include <X11/Shell.h>
  1265. #include <X11/Xaw/Cardinals.h>
  1266. #include <malloc.h>
  1267. #include <ctype.h>
  1268. X
  1269. /*
  1270. X    Macro for using prototypes if ANSI C is available.
  1271. */
  1272. #ifdef __STDC__
  1273. #define PROTO(x) x
  1274. #else
  1275. #define PROTO(x) ()
  1276. #endif
  1277. X
  1278. #define    MAXLINE        500    
  1279. #define    MAXBUTTONS    16        /* max number of "buttons" */
  1280. #define NO_OF_COLS      18        /* default number of columns */
  1281. #define    W_WIDTH        55        /* width of "button" widgets */
  1282. #define    W_HEIGHT    55        /* height of "button" widgets */
  1283. #define    EDITOR        "xterm -e vi "    /* editor used to edit icon file. */
  1284. #define    FORMATTER    "xterm -e vi " /* text formatter for help file */
  1285. #define    HELP_VIEWER    " "        /* viewer for help file */
  1286. #define    MAXPROCS    20
  1287. X
  1288. #define    ICON        1    
  1289. #define    TEXT        2
  1290. #define    SUB_MENU    3
  1291. #define    END_SUB_MENU    4
  1292. #define    UNKNOWN        5
  1293. #define    END        6
  1294. #define    TEXTPLUS    7
  1295. #define    ICONPLUS    8
  1296. X
  1297. #ifndef MAXPATHLEN
  1298. #define MAXPATHLEN    1024
  1299. #endif
  1300. X
  1301. #define    RESOURCE_NAME    ".bitmapFilePath: "
  1302. #define    RESOURCE_VALUE    "/bitmaps"
  1303. /*
  1304. X    structure for holding info on number of buttons created, number of
  1305. X    columns & file to be read.
  1306. */
  1307. typedef struct    info{
  1308. X        int    no_of_buttons;
  1309. X        int    no_of_columns;
  1310. X        Boolean    sensitive;
  1311. X        char    *icon_file;
  1312. X        char    *help_file;
  1313. }Info;
  1314. X
  1315. typedef struct    c_id{
  1316. X        int    child_id;
  1317. X        Widget    w_id;
  1318. }ChildInfo;
  1319. X
  1320. ChildInfo    ci_ptr[MAXPROCS];
  1321. X
  1322. /* forward declarations */
  1323. int    fprintf(), ungetc(), fclose(), fscanf();
  1324. char    *strcpy(), *getenv(), *malloc(); 
  1325. X
  1326. typedef int     bool_t;
  1327. X
  1328. SHAR_EOF
  1329. chmod 0644 gen.h ||
  1330. echo 'restore of gen.h failed'
  1331. Wc_c="`wc -c < 'gen.h'`"
  1332. test 1642 -eq "$Wc_c" ||
  1333.     echo 'gen.h: original size 1642, current size' "$Wc_c"
  1334. rm -f _shar_wnt_.tmp
  1335. fi
  1336. # ============= main.c ==============
  1337. if test -f 'main.c' -a X"$1" != X"-c"; then
  1338.     echo 'x - skipping main.c (File already exists)'
  1339.     rm -f _shar_wnt_.tmp
  1340. else
  1341. > _shar_wnt_.tmp
  1342. echo 'x - extracting main.c (Text)'
  1343. sed 's/^X//' << 'SHAR_EOF' > 'main.c' &&
  1344. static char* sccs_main_c = "%W%%G%"; 
  1345. X
  1346. /* 
  1347. X * Copyright 1992 Bruce. R. Ingram.
  1348. X * University of Kent at Canterbury, UK
  1349. X *
  1350. X * Permission  to   use, copy, modify  and  distribute  this  software  and its
  1351. X * documentation   for any purpose is hereby granted without fee, provided that
  1352. X * the   above  copyright  notice  appear  in  all  copies  and  that both that
  1353. X * copyright  notice   and  this   permission   notice  appear  in   supporting
  1354. X * documentation,  and  that  the name  of the author and The University  of
  1355. X * Kent  at  Canterbury  not be  used in advertising or publicity pertaining to
  1356. X * distribution  of  the  software  without specific, written prior permission.
  1357. X * The   author  and   The   University   of   Kent at   Canterbury   make  no
  1358. X * representations  about  the  suitability  of this  software for any purpose.
  1359. X * It is provided "as is" without express or implied warranty.
  1360. X *
  1361. X * THE   AUTHOR  AND  THE  UNIVERSITY  OF KENT  AT   CANTERBURY  DISCLAIMS ALL
  1362. X * WARRANTIES  WITH  REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED  WARRANTIES
  1363. X * OF   MERCHANTABILITY  AND  FITNESS,  IN NO  EVENT  SHALL THE AUTHOR  OR THE
  1364. X * UNIVERSITY  OF KENT  AT  CANTERBURY  BE LIABLE FOR ANY SPECIAL, INDIRECT  OR
  1365. X * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS  OF USE,
  1366. X * DATA  OR  PROFITS,  WHETHER  IN  AN ACTION OF CONTRACT, NEGLIGENCE  OR OTHER
  1367. X * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  1368. X * OF THIS SOFTWARE.
  1369. X *
  1370. X * Author:
  1371. X *
  1372. X * Mr  B. R. Ingram email bri@ukc.ac.uk
  1373. */
  1374. X
  1375. #include "gen.h"
  1376. #include "widgets.h"
  1377. X
  1378. X
  1379. /*  Forward  references  */
  1380. X
  1381. extern    int    CreateButtons PROTO((Info *));
  1382. extern    void    GetPath PROTO((char *));
  1383. extern    void    PositionButtons PROTO((int,int)), ManageButtons();
  1384. extern  void    set_popup PROTO((Widget,XEvent *,String *,Cardinal *));
  1385. extern    void    delay PROTO((Widget,XEvent *,String *,Cardinal *));
  1386. extern    void    Quit PROTO((Widget,XtPointer,XtPointer));
  1387. static    void    AddResource PROTO((char **));
  1388. X
  1389. #include "trans.h"
  1390. X
  1391. /*
  1392. X    We set various default resources for the various widgets.
  1393. */
  1394. String fallback_resources[] = {
  1395. "*background:    #ffd28e",
  1396. "*foreground:    black",
  1397. "*borderColor:    black",
  1398. "*box.background:    gray",
  1399. NULL,
  1400. };
  1401. X
  1402. X
  1403. /*
  1404. X    We store our application's resources in a structure of 
  1405. X    the following type.
  1406. */
  1407. typedef struct
  1408. {
  1409. X    int     no_of_cols;
  1410. X    char    *icon_file;
  1411. X    char    *help_file;
  1412. X    Boolean    sensitive;
  1413. } AppData, *AppDataPtr;
  1414. X
  1415. X
  1416. /* The description of our application's resources. */
  1417. static XtResource resources[] = {
  1418. X    { "no_of_cols", "No_of_cols",XtRInt,sizeof (int),
  1419. X      XtOffset(AppDataPtr,no_of_cols),XtRString,"18" },
  1420. X    { "icon_file", "Icon_file", XtRString, sizeof(char *),
  1421. X      XtOffset(AppDataPtr,icon_file),XtRString,"./.briconsrc" },
  1422. X    { "help_file", "Help_file", XtRString, sizeof(char *),
  1423. X      XtOffset(AppDataPtr,help_file),XtRString,
  1424. X      "bricons.txt" },
  1425. X    { "sensitive", "Sensitive", XtRBoolean, sizeof(Boolean),
  1426. X      XtOffset(AppDataPtr,sensitive),XtRString,"False" },
  1427. };
  1428. X
  1429. /* Reading command line options. */
  1430. XXrmOptionDescRec options[] = {
  1431. X    { "-col", "*no_of_cols", XrmoptionSepArg, NULL },
  1432. X    { "-file", "*icon_file", XrmoptionSepArg, NULL },
  1433. X    { "-help", "*help_file", XrmoptionSepArg, NULL },
  1434. X    { "-sensitive", "sensitive", XrmoptionSepArg, NULL }
  1435. };
  1436. X
  1437. X
  1438. XXtAppContext    app_context;
  1439. X
  1440. int 
  1441. main(argc,argv)
  1442. unsigned int argc;
  1443. char **argv;
  1444. {
  1445. X    int        string_len = 0;
  1446. X    Info        *data;    
  1447. X    AppData        Rdata;
  1448. X
  1449. X    /* create a shell widget for this application */
  1450. X    toplevel = XtVaAppInitialize(
  1451. X                &app_context,           /* Application context */
  1452. X                "Xbricons",             /* Application class name */
  1453. X                options,         /* Command line option list */
  1454. X        XtNumber(options),  
  1455. X                &argc, argv,            /* Command line args */
  1456. X        /* fallback_resources       use fallback_resources or */
  1457. X        NULL,             /* app_defaults file */
  1458. X                NULL);            /* terminate varargs list */    
  1459. X
  1460. X    /* Retrieve the application resources */
  1461. X    XtVaGetApplicationResources(toplevel,&Rdata,resources,
  1462. X            XtNumber(resources),NULL);
  1463. X
  1464. X    AddResource(argv[0]);
  1465. X
  1466. X    /* add the menu actions to the global action list */
  1467. X    XtAppAddActions(app_context,(XtActionList) menu_actions,
  1468. X                XtNumber(menu_actions));
  1469. X
  1470. X    /* create a form widget which is used to hold all the buttons */
  1471. X    box = XtVaCreateManagedWidget("box",    /* widget name */
  1472. X        formWidgetClass,        /* widget class */
  1473. X        toplevel,            /* parent widget */
  1474. X        NULL);                /* terminate varargs list */
  1475. X
  1476. /*
  1477. X    allocate some memory for data structure holding number of buttons,
  1478. X    the name of the icon file etc.
  1479. */
  1480. X    data = (struct info *) malloc(sizeof(struct info));
  1481. X    if(data == NULL)
  1482. X    {
  1483. X        (void) fprintf(stderr,"%s: out of memory when creating Info data structure. In function main\n",argv[0]);
  1484. X        exit(1);
  1485. X    }    
  1486. X
  1487. X    string_len = 0;
  1488. X    string_len = strlen(Rdata.icon_file);
  1489. X    if((data->icon_file = malloc(string_len +1)) == NULL)
  1490. X    {
  1491. X        (void) fprintf(stderr,"%s: out of memory reading icon file name.  In function main\n",argv[0]);
  1492. X        exit(1);
  1493. X    }
  1494. X    strcpy(data->icon_file,Rdata.icon_file);
  1495. X
  1496. X    string_len = 0;
  1497. X    string_len = strlen(Rdata.help_file);
  1498. X    if((data->help_file = malloc(string_len +1)) == NULL)
  1499. X    {
  1500. X        (void) fprintf(stderr,"%s: out of memory reading icon file name.  In function main\n",argv[0]);
  1501. X        exit(1);
  1502. X    }
  1503. X    strcpy(data->help_file,Rdata.help_file);
  1504. X
  1505. X    data->no_of_columns = Rdata.no_of_cols;
  1506. X
  1507. X    data->sensitive = Rdata.sensitive;
  1508. X
  1509. X    /* read contents of icon file & create buttons */
  1510. X    data->no_of_buttons = CreateButtons(data);
  1511. X
  1512. X    /* position buttons according to number of columns */
  1513. X    PositionButtons(data->no_of_buttons,data->no_of_columns);
  1514. X
  1515. X    ManageButtons();
  1516. X
  1517. X    /* create windows for widgets and map them. */
  1518. X    XtRealizeWidget(toplevel);
  1519. X
  1520. X    /* loop for events */
  1521. X    XtAppMainLoop(app_context);
  1522. X    exit(0);
  1523. }
  1524. X
  1525. X
  1526. X
  1527. static    void
  1528. AddResource(prog_name)
  1529. char *prog_name;
  1530. {
  1531. X    int        string_len, len;
  1532. X    char        *bitmap_dir;    
  1533. X    char        tmp_string[300];
  1534. X    char        *res_name_ptr;
  1535. X    char        current_dir[MAXPATHLEN];
  1536. X    char        *dummy;
  1537. X    XrmDatabase    resource_db;
  1538. X    XrmDatabase    *dbPtr;
  1539. X    XrmValue    value;
  1540. X    XrmValue    *vPtr;
  1541. X    Bool        found;
  1542. X
  1543. X    resource_db = XtDatabase(XtDisplay(toplevel));
  1544. X
  1545. X    string_len = strlen(RESOURCE_NAME);
  1546. X    string_len += strlen(RESOURCE_VALUE);
  1547. X    res_name_ptr = malloc(MAXPATHLEN + string_len + 1);
  1548. X    if(res_name_ptr == NULL)
  1549. X    {
  1550. X        (void) fprintf(stderr,"\nOut of memory error\n");
  1551. X        exit(1);
  1552. X    }
  1553. X    (void)getcwd(current_dir,MAXPATHLEN);
  1554. X
  1555. X    strcpy(res_name_ptr,RESOURCE_NAME);
  1556. X    strcat(res_name_ptr,current_dir);
  1557. X    strcat(res_name_ptr,RESOURCE_VALUE);
  1558. X
  1559. X    (void) sprintf(tmp_string,"%s.bitmapFilePath",prog_name);
  1560. X    found = XrmGetResource(resource_db, tmp_string, 
  1561. X            "Xbricons.BitmapFilePath", &dummy, &value);
  1562. X    dbPtr = &resource_db;
  1563. X    vPtr = &value;
  1564. X    if(!found)
  1565. X    {
  1566. X        (void) fprintf(stderr,"\n.bitmapFilePath not defined in resource file");
  1567. X        (void) fprintf(stderr,"\nAdding default: %s\n",res_name_ptr);
  1568. X        XrmPutLineResource(dbPtr, res_name_ptr); 
  1569. X    }
  1570. X    else
  1571. X    {
  1572. X        len  = strlen(vPtr->addr);
  1573. X        len += strlen(current_dir);
  1574. X        len += strlen(RESOURCE_NAME);
  1575. X        len += strlen(RESOURCE_VALUE);
  1576. X        bitmap_dir = malloc(len + 2);
  1577. X        if(bitmap_dir == NULL)
  1578. X        {
  1579. X            (void) fprintf(stderr,"\nOut of memory error\n");
  1580. X            exit(1);
  1581. X        }
  1582. X        strcpy(bitmap_dir, RESOURCE_NAME);
  1583. X        strcat(bitmap_dir,vPtr->addr);
  1584. X        strcat(bitmap_dir,":");
  1585. X        strcat(bitmap_dir,current_dir);
  1586. X        strcat(bitmap_dir,RESOURCE_VALUE);
  1587. X        XrmPutLineResource(dbPtr, bitmap_dir); 
  1588. X    }
  1589. }
  1590. SHAR_EOF
  1591. chmod 0644 main.c ||
  1592. echo 'restore of main.c failed'
  1593. Wc_c="`wc -c < 'main.c'`"
  1594. test 7300 -eq "$Wc_c" ||
  1595.     echo 'main.c: original size 7300, current size' "$Wc_c"
  1596. rm -f _shar_wnt_.tmp
  1597. fi
  1598. # ============= patchlevel.h ==============
  1599. if test -f 'patchlevel.h' -a X"$1" != X"-c"; then
  1600.     echo 'x - skipping patchlevel.h (File already exists)'
  1601.     rm -f _shar_wnt_.tmp
  1602. else
  1603. > _shar_wnt_.tmp
  1604. echo 'x - extracting patchlevel.h (Text)'
  1605. sed 's/^X//' << 'SHAR_EOF' > 'patchlevel.h' &&
  1606. #define PATCH_LEVEL 0
  1607. SHAR_EOF
  1608. chmod 0644 patchlevel.h ||
  1609. echo 'restore of patchlevel.h failed'
  1610. Wc_c="`wc -c < 'patchlevel.h'`"
  1611. test 22 -eq "$Wc_c" ||
  1612.     echo 'patchlevel.h: original size 22, current size' "$Wc_c"
  1613. rm -f _shar_wnt_.tmp
  1614. fi
  1615. # ============= trans.h ==============
  1616. if test -f 'trans.h' -a X"$1" != X"-c"; then
  1617.     echo 'x - skipping trans.h (File already exists)'
  1618.     rm -f _shar_wnt_.tmp
  1619. else
  1620. > _shar_wnt_.tmp
  1621. echo 'x - extracting trans.h (Text)'
  1622. sed 's/^X//' << 'SHAR_EOF' > 'trans.h' &&
  1623. static char* sccs_trans_h = "%W%%G%";
  1624. X
  1625. /*
  1626. X    translations for the main menu buttons to popup the sub menu.  
  1627. X    SetPopup positions the shell.  MenuPopup realizes the shell.
  1628. */
  1629. X
  1630. static    String pb_Trans =
  1631. X    "<EnterWindow>:    highlight() \n\
  1632. X    <LeaveWindow>:    unhighlight() \n\
  1633. X    <Btn1Down>:    set_popup(box.action%d.popup_menu) MenuPopup(popup_menu) unhighlight()";
  1634. X
  1635. /*
  1636. X    translations for the command buttons of the popup menus the
  1637. X    command callback is invoked when the button is released with
  1638. X    the pointer in the command widget.
  1639. */
  1640. X
  1641. static    String cb_Trans =
  1642. X    "<EnterWindow>:    set() \n\
  1643. X    <LeaveWindow>:    unset() \n\
  1644. X    <Btn1Up>:    notify() delay() reset()";
  1645. X
  1646. /*
  1647. X    translations for the shell of the popup menu.  When the button
  1648. X    is released the shell catches it and pops itself down.
  1649. */
  1650. X
  1651. static    String pm_Trans =
  1652. X    "<Btn1Up>:    MenuPopdown()";
  1653. X
  1654. /* add new actions to this program */
  1655. X
  1656. static    XtActionsRec    menu_actions[] = {
  1657. X    { "set_popup", set_popup },
  1658. X    { "delay", delay }
  1659. };
  1660. X
  1661. /*  the name of the shell, used by SetPopup and MenuPopup actions */
  1662. static  String popup_menu_name = "popup_menu";
  1663. X
  1664. SHAR_EOF
  1665. chmod 0644 trans.h ||
  1666. echo 'restore of trans.h failed'
  1667. Wc_c="`wc -c < 'trans.h'`"
  1668. test 1066 -eq "$Wc_c" ||
  1669.     echo 'trans.h: original size 1066, current size' "$Wc_c"
  1670. rm -f _shar_wnt_.tmp
  1671. fi
  1672. # ============= widgets.h ==============
  1673. if test -f 'widgets.h' -a X"$1" != X"-c"; then
  1674.     echo 'x - skipping widgets.h (File already exists)'
  1675.     rm -f _shar_wnt_.tmp
  1676. else
  1677. > _shar_wnt_.tmp
  1678. echo 'x - extracting widgets.h (Text)'
  1679. sed 's/^X//' << 'SHAR_EOF' > 'widgets.h' &&
  1680. X
  1681. Widget  toplevel,       /* must exist on which to place other widgets */
  1682. X        box,
  1683. X            action[MAXBUTTONS + 1],
  1684. X            popup_shell,
  1685. X                popup_layout,
  1686. X                sub_action[10];
  1687. SHAR_EOF
  1688. chmod 0644 widgets.h ||
  1689. echo 'restore of widgets.h failed'
  1690. Wc_c="`wc -c < 'widgets.h'`"
  1691. test 162 -eq "$Wc_c" ||
  1692.     echo 'widgets.h: original size 162, current size' "$Wc_c"
  1693. rm -f _shar_wnt_.tmp
  1694. fi
  1695. rm -f _shar_seq_.tmp
  1696. echo You have unpacked the last part
  1697. exit 0
  1698. -- 
  1699. --
  1700. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  1701. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  1702. Sunnyvale, California 94086            at&t: 408/522-9236
  1703.