home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xdir / part01 next >
Encoding:
Text File  |  1989-06-03  |  54.7 KB  |  1,838 lines

  1. Path: uunet!island!argv
  2. From: argv@island.uu.net (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v04i014:  xdir -- Directory Browser, Part01/02
  5. Message-ID: <786@island.uu.net>
  6. Date: 3 Jun 89 21:25:46 GMT
  7. Organization: Island Graphics, Marin County, California
  8. Lines: 1827
  9. Approved: island!argv@sun.com
  10.  
  11. Submitted-by: Erik M. van der Poel <erik@sra.co.jp>
  12. Posting-number: Volume 4, Issue 14
  13. Archive-name: xdir/part01
  14.  
  15. [ I didn't have any problem compiling and running on my sun3/60.  It appears
  16.   to have all the necessary sys-v dependencies.  This is a nice looking tool.
  17.   The following is from Erik    --argv ]
  18.  
  19. This is a file name dialog/directory browser package that is handy when
  20. an application wants the user to provide a file name. The path can be
  21. typed at the keyboard or selected by browsing in directory listings with
  22. the mouse.
  23.  
  24. The following features are supported:
  25.  
  26.     * file name completion
  27.  
  28.     * fast directory reading
  29.  
  30.     * linking with Xaw (Athena) and/or Xw (Hewlett-Packard) widgets
  31.  
  32. The file xdir.c is just a wrapper that demonstrates the package, and the
  33. resulting executable can be run by typing xdir and then Return.
  34. --
  35. Erik M. van der Poel                  erik@sra.co.jp             (Japan)
  36. SRA, 1-1-1 Hirakawa-cho, Chiyoda-ku   erik%sra.co.jp@uunet.uu.net  (USA)
  37. Tokyo 102 Japan. TEL +81-3-234-2692   erik%sra.co.jp@mcvax.uucp (Europe)
  38.  
  39. -------------------------------------------------------------------------------
  40.  
  41.  
  42. #!/bin/sh
  43. # to extract, remove the header and type "sh filename"
  44. if `test ! -s ./README`
  45. then
  46. echo "writing ./README"
  47. cat > ./README << '\End\Of\File\'
  48.  
  49.  
  50.  
  51.                   XsraSelFile File Selection Dialog Package
  52.  
  53.  
  54.  
  55. This directory contains the XsraSelFile file selection dialog package. This
  56. package allows an application to obtain a filename from a user. The filename is
  57. selected by typing in a text widget or by browsing with the mouse in directory
  58. listings.
  59.  
  60. The following is a brief description of the available features.
  61.  
  62. * filename completion
  63.  
  64.     When the user types a filename in the Text widget, SelFile shows the
  65.     possible completions in the directory listings. The user can hit the space
  66.     bar to complete the filename.
  67.  
  68. * fast directory reading
  69.  
  70.     When a directory is opened, the entries are read and sorted. Then the stats
  71.     of only the first screenful of entries are taken, and these entries are
  72.     displayed. The stats of the other entries are taken upon demand (i.e. when
  73.     the user wishes to see them by scrolling, etc.) or in the background. The
  74.     Xt work procedure facility is used to do background work. The idea here is
  75.     to give the user some feedback as soon as possible.
  76.  
  77.     "It's just an illu--sion" :-)
  78.  
  79. * Xaw and/or Xw widgets
  80.  
  81.     SelFile can be linked with Xaw (Athena) and/or Xw (Hewlett-Packard)
  82.     widgets. However, it must be linked with the R3 or a later version of the
  83.     Xt Intrinsics. See the Imakefile for details.
  84.  
  85. * automatic display update after directory modification
  86.  
  87.     Every now and then SelFile looks at the directories being displayed to see
  88.     if they have been updated, and updates the display accordingly. Similarly,
  89.     file modes are checked (but not as often).
  90.  
  91. * tilde (~) for home directories
  92.  
  93.     When the user types a tilde at the beginning of the Text widget, SelFile
  94.     shows the home directories.
  95.  
  96. -------------------------------------------------------------------------------
  97.  
  98. This work is loosely based on (and the name comes from) an earlier X10 SelFile
  99. by Michiharu `NinjaTerm' Ariza.
  100.  
  101. Admittedly, this X11 SelFile also looks a bit like the directory browser on the
  102. NeXT machine.
  103.  
  104. -------------------------------------------------------------------------------
  105.  
  106. If you have any
  107.  
  108.     porting problems
  109.  
  110.     bug reports
  111.  
  112.     comments (particularly about ideas in the TODO file)
  113.  
  114.     or any other type of feedback
  115.  
  116. please send mail to
  117.  
  118.     erik@sra.co.jp
  119.                                            OR
  120.     erik%sra.co.jp@uunet.uu.net
  121.                                            OR
  122.     erik%sra.co.jp@mcvax.uucp
  123.                                            OR
  124.     try junet instead of co.jp
  125.                                            OR
  126.     Erik M. van der Poel
  127.     Software Research Associates, Inc.
  128.     1-1-1 Hirakawa-cho, Chiyoda-ku
  129.     Tokyo 102 Japan. TEL +81-3-234-2692
  130. \End\Of\File\
  131. else
  132.   echo "will not over write ./README"
  133. fi
  134. if `test ! -s ./SFinternal.h`
  135. then
  136. echo "writing ./SFinternal.h"
  137. cat > ./SFinternal.h << '\End\Of\File\'
  138. /* $Header: SFinternal.h,v 1.3 89/04/26 17:48:34 erik Exp $ */
  139.  
  140. /*
  141.  * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
  142.  *
  143.  * Permission to use, copy, modify, and distribute this software and its
  144.  * documentation for any purpose and without fee is hereby granted, provided
  145.  * that the above copyright notice appear in all copies and that both that
  146.  * copyright notice and this permission notice appear in supporting
  147.  * documentation, and that the name of Software Research Associates not be used
  148.  * in advertising or publicity pertaining to distribution of the software
  149.  * without specific, written prior permission.  Software Research Associates
  150.  * makes no representations about the suitability of this software for any
  151.  * purpose.  It is provided "as is" without express or implied warranty.
  152.  *
  153.  * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  154.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  155.  * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
  156.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  157.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  158.  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  159.  * PERFORMANCE OF THIS SOFTWARE.
  160.  *
  161.  * Author: Erik M. van der Poel
  162.  *         Software Research Associates, Inc., Tokyo, Japan
  163.  */
  164.  
  165. #include <X11/Intrinsic.h>
  166.  
  167. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  168. #include <Xw/Xw.h>
  169. #include <Xw/TextEdit.h>
  170. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  171. #include <X11/Text.h>
  172. #include <X11/AsciiText.h>
  173. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  174.  
  175. #define SEL_FILE_CANCEL        -1
  176. #define SEL_FILE_OK        0
  177. #define SEL_FILE_NULL        1
  178. #define SEL_FILE_TEXT        2
  179.  
  180. #define SF_DO_SCROLL        1
  181. #define SF_DO_NOT_SCROLL    0
  182.  
  183. typedef struct {
  184.     int    statDone;
  185.     char    *real;
  186.     char    *shown;
  187. } SFEntry;
  188.  
  189. typedef struct {
  190.     char    *dir;
  191.     char    *path;
  192.     SFEntry    *entries;
  193.     int    nEntries;
  194.     int    vOrigin;
  195.     int    nChars;
  196.     int    hOrigin;
  197.     int    changed;
  198.     int    beginSelection;
  199.     int    endSelection;
  200.     time_t    st_mtime;
  201. } SFDir;
  202.  
  203. extern int SFstatus;
  204.  
  205. extern char SFcurrentPath[], SFstartDir[], SFcurrentDir[];
  206.  
  207. extern Widget
  208.         selFile,
  209.         selFileCancel,
  210.         selFileField,
  211.         selFileForm,
  212.         selFileHScroll,
  213.         selFileHScrolls[],
  214.         selFileLists[],
  215.         selFileOK,
  216.         selFilePrompt,
  217.         selFileVScrolls[];
  218.  
  219. extern Display *SFdisplay;
  220.  
  221. extern int SFcharWidth, SFcharHeight, SFcharAscent;
  222.  
  223. extern SFDir *SFdirs;
  224.  
  225. extern int SFdirEnd, SFdirPtr;
  226.  
  227. extern Pixel SFfore, SFback;
  228.  
  229. extern XSegment SFsegs[], SFcompletionSegs[];
  230.  
  231. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  232. extern XwTextPosition SFtextPos;
  233. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  234. extern XtTextPosition SFtextPos;
  235. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  236.  
  237. extern void
  238.     SFenterList(),
  239.     SFleaveList(),
  240.     SFmotionList(),
  241.     SFbuttonPressList(),
  242.     SFbuttonReleaseList();
  243.  
  244. extern
  245.     SFvSliderMovedCallback(),
  246.     SFvFloatSliderMovedCallback(),
  247.     SFhSliderMovedCallback(),
  248.     SFpathSliderMovedCallback(),
  249.     SFvAreaSelectedCallback(),
  250.     SFhAreaSelectedCallback(),
  251.     SFpathAreaSelectedCallback();
  252.  
  253. extern int SFupperX, SFlowerY, SFupperY;
  254.  
  255. extern int SFtextX, SFtextYoffset;
  256.  
  257. extern int SFentryWidth, SFentryHeight;
  258.  
  259. extern int SFlineToTextH, SFlineToTextV;
  260.  
  261. extern int SFbesideText, SFaboveAndBelowText;
  262.  
  263. extern int SFcharsPerEntry;
  264.  
  265. extern int SFlistSize;
  266.  
  267. extern int SFcurrentInvert[];
  268.  
  269. extern int SFworkProcAdded;
  270.  
  271. extern Boolean SFworkProc();
  272.  
  273. extern XtAppContext SFapp;
  274.  
  275. extern int SFpathScrollWidth, SFvScrollHeight, SFhScrollWidth;
  276.  
  277. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  278. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  279. extern char SFtextBuffer[];
  280. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  281.  
  282. extern int SFbuttonPressed;
  283.  
  284. extern int SFcompareEntries();
  285.  
  286. extern SFdirModTimer();
  287.  
  288. extern XtIntervalId SFdirModTimerId;
  289.  
  290. extern int (*SFfunc)();
  291. \End\Of\File\
  292. else
  293.   echo "will not over write ./SFinternal.h"
  294. fi
  295. if `test ! -s ./SelFile.c`
  296. then
  297. echo "writing ./SelFile.c"
  298. cat > ./SelFile.c << '\End\Of\File\'
  299. #ifndef lint
  300. static char rcsid[] = "$Header: SelFile.c,v 1.7 89/05/30 14:49:17 erik Exp $";
  301. #endif
  302.  
  303. /*
  304.  * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
  305.  *
  306.  * Permission to use, copy, modify, and distribute this software and its
  307.  * documentation for any purpose and without fee is hereby granted, provided
  308.  * that the above copyright notice appear in all copies and that both that
  309.  * copyright notice and this permission notice appear in supporting
  310.  * documentation, and that the name of Software Research Associates not be used
  311.  * in advertising or publicity pertaining to distribution of the software
  312.  * without specific, written prior permission.  Software Research Associates
  313.  * makes no representations about the suitability of this software for any
  314.  * purpose.  It is provided "as is" without express or implied warranty.
  315.  *
  316.  * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  317.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  318.  * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
  319.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  320.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  321.  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  322.  * PERFORMANCE OF THIS SOFTWARE.
  323.  *
  324.  * Author: Erik M. van der Poel
  325.  *         Software Research Associates, Inc., Tokyo, Japan
  326.  */
  327.  
  328. /*
  329.  * Author's address:
  330.  *
  331.  *     erik@sra.co.jp
  332.  *                                            OR
  333.  *     erik%sra.co.jp@uunet.uu.net
  334.  *                                            OR
  335.  *     erik%sra.co.jp@mcvax.uucp
  336.  *                                            OR
  337.  *     try junet instead of co.jp
  338.  *                                            OR
  339.  *     Erik M. van der Poel
  340.  *     Software Research Associates, Inc.
  341.  *     1-1-1 Hirakawa-cho, Chiyoda-ku
  342.  *     Tokyo 102 Japan. TEL +81-3-234-2692
  343.  */
  344.  
  345. #include <stdio.h>
  346. #include <sys/param.h>
  347. #include <X11/cursorfont.h>
  348. #include <X11/Intrinsic.h>
  349. #include <X11/StringDefs.h>
  350. #include <X11/Composite.h>
  351. #include <X11/Shell.h>
  352.  
  353. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM)
  354. #include <Xw/Xw.h>
  355. #include <Xw/Form.h>
  356. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  357. #include <X11/Form.h>
  358. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  359.  
  360. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON)
  361. #include <Xw/Xw.h>
  362. #include <Xw/PButton.h>
  363. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  364. #include <X11/Command.h>
  365. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  366.  
  367. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  368. #include <Xw/Xw.h>
  369. #include <Xw/ScrollBar.h>
  370. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  371. #include <X11/Scroll.h>
  372. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  373.  
  374. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT)
  375. #include <Xw/Xw.h>
  376. #include <Xw/SText.h>
  377. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT) */
  378. #include <X11/Label.h>
  379. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT) */
  380.  
  381. #include "SFinternal.h"
  382.  
  383. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  384. #ifdef SEL_FILE_JAPANESE
  385. #include <X11/XWStr.h>
  386. #endif /* def SEL_FILE_JAPANESE */
  387. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  388.  
  389. #ifndef SYSV
  390. extern char *getwd();
  391. #endif /* ndef SYSV */
  392.  
  393. int SFstatus = SEL_FILE_NULL;
  394.  
  395. char
  396.     SFstartDir[MAXPATHLEN],
  397.     SFcurrentPath[MAXPATHLEN],
  398.     SFcurrentDir[MAXPATHLEN];
  399.  
  400. Widget
  401.     selFile,
  402.     selFileCancel,
  403.     selFileField,
  404.     selFileForm,
  405.     selFileHScroll,
  406.     selFileHScrolls[3],
  407.     selFileLists[3],
  408.     selFileOK,
  409.     selFilePrompt,
  410.     selFileVScrolls[3];
  411.  
  412. Display *SFdisplay;
  413.  
  414. Pixel SFfore, SFback;
  415.  
  416. XSegment SFsegs[2], SFcompletionSegs[2];
  417.  
  418. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  419. XwTextPosition SFtextPos;
  420. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  421. XtTextPosition SFtextPos;
  422. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  423.  
  424. int SFupperX, SFlowerY, SFupperY;
  425.  
  426. int SFtextX, SFtextYoffset;
  427.  
  428. int SFentryWidth, SFentryHeight;
  429.  
  430. int SFlineToTextH = 3;
  431.  
  432. int SFlineToTextV = 3;
  433.  
  434. int SFbesideText = 3;
  435.  
  436. int SFaboveAndBelowText = 2;
  437.  
  438. int SFcharsPerEntry = 15;
  439.  
  440. int SFlistSize = 10;
  441.  
  442. int SFworkProcAdded = 0;
  443.  
  444. XtAppContext SFapp;
  445.  
  446. int SFpathScrollWidth, SFvScrollHeight, SFhScrollWidth;
  447.  
  448. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  449. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  450. char SFtextBuffer[MAXPATHLEN];
  451. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  452.  
  453. XtIntervalId SFdirModTimerId;
  454.  
  455. int (*SFfunc)();
  456.  
  457. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  458. static char *oneLineTextEditTranslations = "\
  459.     <Key>Return:    execute()\n\
  460.     Ctrl<Key>M:    execute()\n\
  461. ";
  462. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  463. static char *oneLineTextEditTranslations = "\
  464.     <Key>Return:    redraw-display()\n\
  465.     Ctrl<Key>M:    redraw-display()\n\
  466. ";
  467. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  468.  
  469. /* ARGSUSED */
  470. static void
  471. SFexposeList(w, n, event)
  472.     Widget        w;
  473.     int        n;
  474.     XExposeEvent    *event;
  475. {
  476.     if ((event->type == NoExpose) || event->count) {
  477.         return;
  478.     }
  479.  
  480.     SFdrawList(n, SF_DO_NOT_SCROLL);
  481. }
  482.  
  483. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  484. static void
  485. returnCallback()
  486. {
  487.     SFstatus = SEL_FILE_OK;
  488. }
  489. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  490.  
  491. /* ARGSUSED */
  492. static void
  493. SFmodVerifyCallback(w, client_data, event)
  494.     Widget            w;
  495.     caddr_t            client_data;
  496.     XKeyPressedEvent    *event;
  497. {
  498.  
  499. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  500.     SFstatus = SEL_FILE_TEXT;
  501. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  502.     char    buf[2];
  503.  
  504.     if (
  505.         (XLookupString(event, buf, 2, NULL, NULL) == 1) &&
  506.         ((*buf) == '\r')
  507.     ) {
  508.         SFstatus = SEL_FILE_OK;
  509.     } else {
  510.         SFstatus = SEL_FILE_TEXT;
  511.     }
  512. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  513.  
  514. }
  515.  
  516. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  517. static XtCallbackRec SFmodVerify[] = {
  518.     { SFmodVerifyCallback, (caddr_t) NULL },
  519.     { NULL, (caddr_t) NULL },
  520. };
  521. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  522.  
  523. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON)
  524. static
  525. SFresetButton(w)
  526.     Widget w;
  527. {
  528.     static Arg    arg[] = {
  529.         { XtNset, False }
  530.     };
  531.  
  532.     XtSetValues(w, arg, 1);
  533. }
  534. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  535.  
  536. /* ARGSUSED */
  537. static void
  538. SFokCallback(w)
  539.     Widget    w;
  540. {
  541.     SFstatus = SEL_FILE_OK;
  542.  
  543. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON)
  544.     SFresetButton(w);
  545. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  546.  
  547. }
  548.  
  549. static XtCallbackRec SFokSelect[] = {
  550.     { SFokCallback, (caddr_t) NULL },
  551.     { NULL, (caddr_t) NULL },
  552. };
  553.  
  554. /* ARGSUSED */
  555. static void
  556. SFcancelCallback(w)
  557.     Widget    w;
  558. {
  559.     SFstatus = SEL_FILE_CANCEL;
  560.  
  561. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON)
  562.     SFresetButton(w);
  563. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  564.  
  565. }
  566.  
  567. static XtCallbackRec SFcancelSelect[] = {
  568.     { SFcancelCallback, (caddr_t) NULL },
  569.     { NULL, (caddr_t) NULL },
  570. };
  571.  
  572. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  573. typedef struct {
  574.     Dimension    height;
  575. } SFfieldData, *sfFieldPtr;
  576.  
  577. static XtResource SFfieldResources[] = {
  578.     {
  579.         XtNheight, XtCHeight, XtRDimension, sizeof(Dimension),
  580.         XtOffset(sfFieldPtr, height), XtRString, "1"
  581.     },
  582. };
  583. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  584.  
  585. static int
  586. SFcreateWidgets(prompt, ok, cancel)
  587.     u_char    *prompt;
  588.     u_char    *ok;
  589.     u_char    *cancel;
  590. {
  591.     int        i, n;
  592.     int        listWidth, listHeight;
  593.     int        listSpacing = 10;
  594.     int        scrollThickness = 15;
  595.     int        hScrollX, hScrollY;
  596.     int        vScrollX, vScrollY;
  597.     Cursor
  598.             xtermCursor,
  599.  
  600. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  601.             sbDownArrowCursor,
  602.             sbLeftArrowCursor,
  603.             sbUpArrowCursor,
  604. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  605.  
  606.             sbRightArrowCursor,
  607.             dotCursor;
  608.  
  609. #ifdef SEL_FILE_JAPANESE
  610.     CStr        csl[2];
  611.     u_char        cstr[256];
  612. #endif /* def SEL_FILE_JAPANESE */
  613.  
  614.     Arg        arglist[20];
  615.  
  616. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  617.     SFfieldData    *data;
  618. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  619.  
  620.     i = 0;
  621.     XtSetArg(arglist[i], XtNallowShellResize, True);        i++;
  622.     selFile = XtAppCreateShell("selFile", "SelFile",
  623.         applicationShellWidgetClass, SFdisplay, arglist, i);
  624.  
  625. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM)
  626.     selFileForm = XtCreateManagedWidget("selFileForm",
  627.         XwformWidgetClass, selFile, (ArgList) NULL, 0);
  628. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  629.     i = 0;
  630.     XtSetArg(arglist[i], XtNdefaultDistance, 30);            i++;
  631.     selFileForm = XtCreateManagedWidget("selFileForm",
  632.         formWidgetClass, selFile, arglist, i);
  633. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  634.  
  635.     i = 0;
  636.  
  637. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT)
  638.  
  639. #ifdef SEL_FILE_JAPANESE
  640.  
  641. #ifdef SEL_FILE_SJIS
  642.     (void) convSJIStoCS(prompt, cstr);
  643. #else /* def SEL_FILE_SJIS */
  644.     (void) convEUCtoCS(prompt, cstr);
  645. #endif /* def SEL_FILE_SJIS */
  646.  
  647.     csl[0] = cstr;
  648.     csl[1] = NULL;
  649.     XtSetArg(arglist[i], XtNstrings, csl);                i++;
  650. #else /* def SEL_FILE_JAPANESE */
  651.     XtSetArg(arglist[i], XtNstring, prompt);            i++;
  652. #endif /* def SEL_FILE_JAPANESE */
  653.  
  654. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT) */
  655.     XtSetArg(arglist[i], XtNlabel, prompt);                i++;
  656. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT) */
  657.  
  658. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM)
  659.     XtSetArg(arglist[i], XtNxOffset, 30);                i++;
  660.     XtSetArg(arglist[i], XtNyOffset, 30);                i++;
  661. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  662.  
  663.     XtSetArg(arglist[i], XtNborderWidth, 0);            i++;
  664.  
  665. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT)
  666.     selFilePrompt = XtCreateManagedWidget("selFilePrompt",
  667.         XwstatictextWidgetClass, selFileForm, arglist, i);
  668. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT) */
  669.     selFilePrompt = XtCreateManagedWidget("selFilePrompt",
  670.         labelWidgetClass, selFileForm, arglist, i);
  671. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT) */
  672.  
  673.     i = 0;
  674.     XtSetArg(arglist[i], XtNforeground, &SFfore);            i++;
  675.     XtSetArg(arglist[i], XtNbackground, &SFback);            i++;
  676.     XtGetValues(selFilePrompt, arglist, i);
  677.  
  678.     SFinitFont();
  679.  
  680.     SFentryWidth = SFbesideText + SFcharsPerEntry * SFcharWidth +
  681.             SFbesideText;
  682.     SFentryHeight = SFaboveAndBelowText + SFcharHeight +
  683.             SFaboveAndBelowText;
  684.  
  685.     listWidth = SFlineToTextH + SFentryWidth + SFlineToTextH + 1 +
  686.             scrollThickness;
  687.     listHeight = SFlineToTextV + SFentryHeight + SFlineToTextV + 1 +
  688.             SFlineToTextV + SFlistSize * SFentryHeight +
  689.             SFlineToTextV + 1 + scrollThickness;
  690.  
  691.     SFpathScrollWidth = 3 * listWidth + 2 * listSpacing + 4;
  692.  
  693.     hScrollX = -1;
  694.     hScrollY = SFlineToTextV + SFentryHeight + SFlineToTextV + 1 +
  695.             SFlineToTextV + SFlistSize * SFentryHeight +
  696.             SFlineToTextV;
  697.     SFhScrollWidth = SFlineToTextH + SFentryWidth + SFlineToTextH;
  698.  
  699.     vScrollX = SFlineToTextH + SFentryWidth + SFlineToTextH;
  700.     vScrollY = SFlineToTextV + SFentryHeight + SFlineToTextV;
  701.     SFvScrollHeight = SFlineToTextV + SFlistSize * SFentryHeight +
  702.             SFlineToTextV;
  703.  
  704.     SFupperX = SFlineToTextH + SFentryWidth + SFlineToTextH - 1;
  705.     SFlowerY = SFlineToTextV + SFentryHeight + SFlineToTextV + 1 +
  706.             SFlineToTextV;
  707.     SFupperY = SFlineToTextV + SFentryHeight + SFlineToTextV + 1 +
  708.             SFlineToTextV + SFlistSize * SFentryHeight - 1;
  709.  
  710.     SFtextX = SFlineToTextH + SFbesideText;
  711.     SFtextYoffset = SFlowerY + SFaboveAndBelowText + SFcharAscent;
  712.  
  713.     SFsegs[0].x1 = 0;
  714.     SFsegs[0].y1 = vScrollY;
  715.     SFsegs[0].x2 = vScrollX - 1;
  716.     SFsegs[0].y2 = vScrollY;
  717.     SFsegs[1].x1 = vScrollX;
  718.     SFsegs[1].y1 = 0;
  719.     SFsegs[1].x2 = vScrollX;
  720.     SFsegs[1].y2 = vScrollY - 1;
  721.  
  722.     SFcompletionSegs[0].x1 = SFcompletionSegs[0].x2 = SFlineToTextH;
  723.     SFcompletionSegs[1].x1 = SFcompletionSegs[1].x2 =
  724.         SFlineToTextH + SFentryWidth - 1;
  725.  
  726.     i = 0;
  727.     XtSetArg(arglist[i], XtNwidth, 3 * listWidth + 2 * listSpacing + 4);
  728.                                     i++;
  729.     XtSetArg(arglist[i], XtNborderColor, SFfore);            i++;
  730.  
  731. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM)
  732.     XtSetArg(arglist[i], XtNxRefWidget, selFilePrompt);        i++;
  733.     XtSetArg(arglist[i], XtNyRefWidget, selFilePrompt);        i++;
  734.     XtSetArg(arglist[i], XtNyAddHeight, True);            i++;
  735.     XtSetArg(arglist[i], XtNyOffset, 10);                i++;
  736. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  737.     XtSetArg(arglist[i], XtNfromVert, selFilePrompt);        i++;
  738.     XtSetArg(arglist[i], XtNvertDistance, 10);            i++;
  739.     XtSetArg(arglist[i], XtNresizable, True);            i++;
  740. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  741.  
  742. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  743.     XtSetArg(arglist[i], XtNmodifyVerification, SFmodVerify);    i++;
  744.     XtSetArg(arglist[i], XtNmotionVerification, SFmodVerify);    i++;
  745.     selFileField = XtCreateManagedWidget("selFileField",
  746.         XwtexteditWidgetClass, selFileForm, arglist, i);
  747. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  748.     XtSetArg(arglist[i], XtNstring, SFtextBuffer);            i++;
  749.     XtSetArg(arglist[i], XtNlength, MAXPATHLEN);            i++;
  750.     XtSetArg(arglist[i], XtNeditType, XttextEdit);            i++;
  751.     XtSetArg(arglist[i], XtNtextOptions,    0        |
  752.                         editable    |
  753.                         resizeHeight    |
  754.                         wordBreak    |
  755.                         0);            i++;
  756.     selFileField = XtCreateManagedWidget("selFileField",
  757.         asciiStringWidgetClass, selFileForm, arglist, i);
  758. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  759.  
  760.     XtOverrideTranslations(selFileField,
  761.         XtParseTranslationTable(oneLineTextEditTranslations));
  762.  
  763. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  764.  
  765.     data = XtNew(SFfieldData);
  766.  
  767.     XtGetApplicationResources(
  768.         selFileField,
  769.         (caddr_t) data,
  770.         SFfieldResources,
  771.         XtNumber(SFfieldResources),
  772.         (Arg *) NULL,
  773.         0
  774.     );
  775.  
  776.     if (data->height == 1) {
  777.  
  778. #ifdef SEL_FILE_JAPANESE
  779.         XFontStruct    *font, *kanjiFont;
  780.         XGCValues    values;
  781.         XWSGC        gcSet;
  782. #else /* def SEL_FILE_JAPANESE */
  783.         XFontStruct    *font;
  784. #endif /* def SEL_FILE_JAPANESE */
  785.  
  786.         int        ascent, descent;
  787.         Dimension    top, bottom;
  788.  
  789.         i = 0;
  790.         XtSetArg(arglist[i], XtNtopMargin, &top);        i++;
  791.         XtSetArg(arglist[i], XtNbottomMargin, &bottom);        i++;
  792.  
  793. #ifdef SEL_FILE_JAPANESE
  794.         XtSetArg(arglist[i], XtNfontG0, &font);            i++;
  795.         XtSetArg(arglist[i], XtNfontG1, &kanjiFont);        i++;
  796. #else /* def SEL_FILE_JAPANESE */
  797.         XtSetArg(arglist[i], XtNfont, &font);            i++;
  798. #endif /* def SEL_FILE_JAPANESE */
  799.  
  800.         XtGetValues(selFileField, arglist, i);
  801.  
  802. #ifdef SEL_FILE_JAPANESE
  803.         gcSet = XtWSGetGCSet(selFileField, 0, &values, font, kanjiFont,
  804.             NULL, NULL);
  805.         XWSFontHeight(gcSet, NULL, 0, &ascent, &descent);
  806. #else /* def SEL_FILE_JAPANESE */
  807.         ascent = font->ascent;
  808.         descent = font->descent;
  809. #endif /* def SEL_FILE_JAPANESE */
  810.  
  811.         i = 0;
  812.         XtSetArg(arglist[i], XtNheight,
  813.             top + bottom + ascent + descent);        i++;
  814.         XtSetValues(selFileField, arglist, i);
  815.     }
  816.  
  817. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  818.  
  819.     i = 0;
  820.  
  821. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  822.     XtSetArg(arglist[i], XtNslideOrientation, XwHORIZONTAL);    i++;
  823.     XtSetArg(arglist[i], XtNsliderMin, 0);                i++;
  824.     XtSetArg(arglist[i], XtNsliderExtent, 3);            i++;
  825.     XtSetArg(arglist[i], XtNrepeatRate, 1);                i++;
  826.     XtSetArg(arglist[i], XtNgranularity, 1);            i++;
  827. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  828.     XtSetArg(arglist[i], XtNorientation, XtorientHorizontal);    i++;
  829. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  830.  
  831.     XtSetArg(arglist[i], XtNwidth, SFpathScrollWidth);        i++;
  832.     XtSetArg(arglist[i], XtNheight, scrollThickness);        i++;
  833.     XtSetArg(arglist[i], XtNborderColor, SFfore);            i++;
  834.  
  835. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM)
  836.     XtSetArg(arglist[i], XtNxRefWidget, selFileField);        i++;
  837.     XtSetArg(arglist[i], XtNyRefWidget, selFileField);        i++;
  838.     XtSetArg(arglist[i], XtNyAddHeight, True);            i++;
  839.     XtSetArg(arglist[i], XtNyOffset, 30);                i++;
  840. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  841.     XtSetArg(arglist[i], XtNfromVert, selFileField);        i++;
  842.     XtSetArg(arglist[i], XtNvertDistance, 30);            i++;
  843. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  844.  
  845. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  846.     selFileHScroll = XtCreateManagedWidget("selFileHScroll",
  847.         XwscrollbarWidgetClass, selFileForm, arglist, i);
  848.  
  849.     XtAddCallback(selFileHScroll, XtNsliderMoved,
  850.         SFpathSliderMovedCallback, (caddr_t) NULL);
  851.     XtAddCallback(selFileHScroll, XtNareaSelected,
  852.         SFpathAreaSelectedCallback, (caddr_t) NULL);
  853. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  854.     selFileHScroll = XtCreateManagedWidget("selFileHScroll",
  855.         scrollbarWidgetClass, selFileForm, arglist, i);
  856.  
  857.     XtAddCallback(selFileHScroll, XtNjumpProc,
  858.         SFpathSliderMovedCallback, (caddr_t) NULL);
  859.     XtAddCallback(selFileHScroll, XtNscrollProc,
  860.         SFpathAreaSelectedCallback, (caddr_t) NULL);
  861. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  862.  
  863.     i = 0;
  864.     XtSetArg(arglist[i], XtNwidth, listWidth);            i++;
  865.     XtSetArg(arglist[i], XtNheight, listHeight);            i++;
  866.     XtSetArg(arglist[i], XtNborderColor, SFfore);            i++;
  867.  
  868. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM)
  869.     XtSetArg(arglist[i], XtNxRefWidget, selFileHScroll);        i++;
  870.     XtSetArg(arglist[i], XtNyRefWidget, selFileHScroll);        i++;
  871.     XtSetArg(arglist[i], XtNyAddHeight, True);            i++;
  872.     XtSetArg(arglist[i], XtNyOffset, 10);                i++;
  873. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  874.     XtSetArg(arglist[i], XtNfromVert, selFileHScroll);        i++;
  875.     XtSetArg(arglist[i], XtNvertDistance, 10);            i++;
  876. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  877.  
  878.     selFileLists[0] = XtCreateManagedWidget("selFileList1",
  879.         compositeWidgetClass, selFileForm, arglist, i);
  880.  
  881.     i = 0;
  882.     XtSetArg(arglist[i], XtNwidth, listWidth);            i++;
  883.     XtSetArg(arglist[i], XtNheight, listHeight);            i++;
  884.     XtSetArg(arglist[i], XtNborderColor, SFfore);            i++;
  885.  
  886. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM)
  887.     XtSetArg(arglist[i], XtNxRefWidget, selFileLists[0]);        i++;
  888.     XtSetArg(arglist[i], XtNyRefWidget, selFileLists[0]);        i++;
  889.     XtSetArg(arglist[i], XtNxAddWidth, True);            i++;
  890.     XtSetArg(arglist[i], XtNxOffset, listSpacing);            i++;
  891. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  892.     XtSetArg(arglist[i], XtNfromHoriz, selFileLists[0]);        i++;
  893.     XtSetArg(arglist[i], XtNfromVert, selFileHScroll);        i++;
  894.     XtSetArg(arglist[i], XtNhorizDistance, listSpacing);        i++;
  895.     XtSetArg(arglist[i], XtNvertDistance, 10);            i++;
  896. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  897.  
  898.     selFileLists[1] = XtCreateManagedWidget("selFileList2",
  899.         compositeWidgetClass, selFileForm, arglist, i);
  900.  
  901.     i = 0;
  902.     XtSetArg(arglist[i], XtNwidth, listWidth);            i++;
  903.     XtSetArg(arglist[i], XtNheight, listHeight);            i++;
  904.     XtSetArg(arglist[i], XtNborderColor, SFfore);            i++;
  905.  
  906. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM)
  907.     XtSetArg(arglist[i], XtNxRefWidget, selFileLists[1]);        i++;
  908.     XtSetArg(arglist[i], XtNyRefWidget, selFileLists[1]);        i++;
  909.     XtSetArg(arglist[i], XtNxAddWidth, True);            i++;
  910.     XtSetArg(arglist[i], XtNxOffset, listSpacing);            i++;
  911.     XtSetArg(arglist[i], XtNxAttachRight, True);            i++;
  912.     XtSetArg(arglist[i], XtNxAttachOffset, 30);            i++;
  913. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  914.     XtSetArg(arglist[i], XtNfromHoriz, selFileLists[1]);        i++;
  915.     XtSetArg(arglist[i], XtNfromVert, selFileHScroll);        i++;
  916.     XtSetArg(arglist[i], XtNhorizDistance, listSpacing);        i++;
  917.     XtSetArg(arglist[i], XtNvertDistance, 10);            i++;
  918. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  919.  
  920.     selFileLists[2] = XtCreateManagedWidget("selFileList3",
  921.         compositeWidgetClass, selFileForm, arglist, i);
  922.  
  923.     for (n = 0; n < 3; n++) {
  924.  
  925.         i = 0;
  926.  
  927. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  928.         XtSetArg(arglist[i], XtNsliderMin, 0);            i++;
  929.         XtSetArg(arglist[i], XtNrepeatRate, 1);            i++;
  930.         XtSetArg(arglist[i], XtNgranularity, 1);        i++;
  931. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  932.  
  933.         XtSetArg(arglist[i], XtNx, vScrollX);            i++;
  934.         XtSetArg(arglist[i], XtNy, vScrollY);            i++;
  935.         XtSetArg(arglist[i], XtNwidth, scrollThickness);    i++;
  936.         XtSetArg(arglist[i], XtNheight, SFvScrollHeight);    i++;
  937.         XtSetArg(arglist[i], XtNborderColor, SFfore);        i++;
  938.  
  939. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  940.         selFileVScrolls[n] = XtCreateManagedWidget("selFileVScroll",
  941.             XwscrollbarWidgetClass, selFileLists[n], arglist, i);
  942.  
  943.         XtAddCallback(selFileVScrolls[n], XtNsliderMoved,
  944.             SFvSliderMovedCallback, (caddr_t) n);
  945.         XtAddCallback(selFileVScrolls[n], XtNareaSelected,
  946.             SFvAreaSelectedCallback, (caddr_t) n);
  947. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  948.         selFileVScrolls[n] = XtCreateManagedWidget("selFileVScroll",
  949.             scrollbarWidgetClass, selFileLists[n], arglist, i);
  950.  
  951.         XtAddCallback(selFileVScrolls[n], XtNjumpProc,
  952.             SFvFloatSliderMovedCallback, (caddr_t) n);
  953.         XtAddCallback(selFileVScrolls[n], XtNscrollProc,
  954.             SFvAreaSelectedCallback, (caddr_t) n);
  955. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  956.  
  957.         i = 0;
  958.  
  959. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  960.         XtSetArg(arglist[i], XtNslideOrientation, XwHORIZONTAL);i++;
  961.         XtSetArg(arglist[i], XtNsliderMin, 0);            i++;
  962.         XtSetArg(arglist[i], XtNrepeatRate, 1);            i++;
  963.         XtSetArg(arglist[i], XtNgranularity, 1);        i++;
  964. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  965.         XtSetArg(arglist[i], XtNorientation, XtorientHorizontal);
  966.                                     i++;
  967. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  968.  
  969.         XtSetArg(arglist[i], XtNx, hScrollX);            i++;
  970.         XtSetArg(arglist[i], XtNy, hScrollY);            i++;
  971.         XtSetArg(arglist[i], XtNwidth, SFhScrollWidth);        i++;
  972.         XtSetArg(arglist[i], XtNheight, scrollThickness);    i++;
  973.         XtSetArg(arglist[i], XtNborderColor, SFfore);        i++;
  974.  
  975. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  976.         selFileHScrolls[n] = XtCreateManagedWidget("selFileHScroll",
  977.             XwscrollbarWidgetClass, selFileLists[n], arglist, i);
  978.  
  979.         XtAddCallback(selFileHScrolls[n], XtNsliderMoved,
  980.             SFhSliderMovedCallback, (caddr_t) n);
  981.         XtAddCallback(selFileHScrolls[n], XtNareaSelected,
  982.             SFhAreaSelectedCallback, (caddr_t) n);
  983. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  984.         selFileHScrolls[n] = XtCreateManagedWidget("selFileHScroll",
  985.             scrollbarWidgetClass, selFileLists[n], arglist, i);
  986.  
  987.         XtAddCallback(selFileHScrolls[n], XtNjumpProc,
  988.             SFhSliderMovedCallback, (caddr_t) n);
  989.         XtAddCallback(selFileHScrolls[n], XtNscrollProc,
  990.             SFhAreaSelectedCallback, (caddr_t) n);
  991. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  992.  
  993.     }
  994.  
  995.     i = 0;
  996.  
  997. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON)
  998.  
  999. #ifdef SEL_FILE_JAPANESE
  1000.  
  1001. #ifdef SEL_FILE_SJIS
  1002.     (void) convSJIStoCS(ok, cstr);
  1003. #else /* def SEL_FILE_SJIS */
  1004.     (void) convEUCtoCS(ok, cstr);
  1005. #endif /* def SEL_FILE_SJIS */
  1006.  
  1007.     XtSetArg(arglist[i], XtNlabel, cstr);                i++;
  1008. #else /* def SEL_FILE_JAPANESE */
  1009.     XtSetArg(arglist[i], XtNlabel, ok);                i++;
  1010. #endif /* def SEL_FILE_JAPANESE */
  1011.  
  1012.     XtSetArg(arglist[i], XtNhSpace, 4);                i++;
  1013.     XtSetArg(arglist[i], XtNvSpace, 4);                i++;
  1014.     XtSetArg(arglist[i], XtNselect, SFokSelect);            i++;
  1015. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1016.     XtSetArg(arglist[i], XtNlabel, ok);                i++;
  1017.     XtSetArg(arglist[i], XtNcallback, SFokSelect);            i++;
  1018.     XtSetArg(arglist[i], XtNborderColor, SFfore);            i++;
  1019. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1020.  
  1021. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM)
  1022.     XtSetArg(arglist[i], XtNxRefWidget, selFileLists[0]);        i++;
  1023.     XtSetArg(arglist[i], XtNyRefWidget, selFileLists[0]);        i++;
  1024.     XtSetArg(arglist[i], XtNyAddHeight, True);            i++;
  1025.     XtSetArg(arglist[i], XtNyOffset, 30);                i++;
  1026.     XtSetArg(arglist[i], XtNyAttachBottom, True);            i++;
  1027.     XtSetArg(arglist[i], XtNyAttachOffset, 30);            i++;
  1028. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  1029.     XtSetArg(arglist[i], XtNfromVert, selFileLists[0]);        i++;
  1030.     XtSetArg(arglist[i], XtNvertDistance, 30);            i++;
  1031. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  1032.  
  1033. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON)
  1034.     selFileOK = XtCreateManagedWidget("selFileOK", XwpushButtonWidgetClass,
  1035.         selFileForm, arglist, i);
  1036. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1037.     selFileOK = XtCreateManagedWidget("selFileOK", commandWidgetClass,
  1038.         selFileForm, arglist, i);
  1039. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1040.  
  1041.     i = 0;
  1042.  
  1043. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON)
  1044.  
  1045. #ifdef SEL_FILE_JAPANESE
  1046.  
  1047. #ifdef SEL_FILE_SJIS
  1048.     (void) convSJIStoCS(cancel, cstr);
  1049. #else /* def SEL_FILE_SJIS */
  1050.     (void) convEUCtoCS(cancel, cstr);
  1051. #endif /* def SEL_FILE_SJIS */
  1052.  
  1053.     XtSetArg(arglist[i], XtNlabel, cstr);                i++;
  1054. #else /* def SEL_FILE_JAPANESE */
  1055.     XtSetArg(arglist[i], XtNlabel, cancel);                i++;
  1056. #endif /* def SEL_FILE_JAPANESE */
  1057.  
  1058.     XtSetArg(arglist[i], XtNhSpace, 4);                i++;
  1059.     XtSetArg(arglist[i], XtNvSpace, 4);                i++;
  1060.     XtSetArg(arglist[i], XtNselect, SFcancelSelect);        i++;
  1061. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1062.     XtSetArg(arglist[i], XtNlabel, cancel);                i++;
  1063.     XtSetArg(arglist[i], XtNcallback, SFcancelSelect);        i++;
  1064.     XtSetArg(arglist[i], XtNborderColor, SFfore);            i++;
  1065. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1066.  
  1067. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM)
  1068.     XtSetArg(arglist[i], XtNxRefWidget, selFileOK);            i++;
  1069.     XtSetArg(arglist[i], XtNyRefWidget, selFileOK);            i++;
  1070.     XtSetArg(arglist[i], XtNxAddWidth, True);            i++;
  1071.     XtSetArg(arglist[i], XtNxOffset, 30);                i++;
  1072.     XtSetArg(arglist[i], XtNyAttachBottom, True);            i++;
  1073.     XtSetArg(arglist[i], XtNyAttachOffset, 30);            i++;
  1074. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  1075.     XtSetArg(arglist[i], XtNfromHoriz, selFileOK);            i++;
  1076.     XtSetArg(arglist[i], XtNfromVert, selFileLists[0]);        i++;
  1077.     XtSetArg(arglist[i], XtNhorizDistance, 30);            i++;
  1078.     XtSetArg(arglist[i], XtNvertDistance, 30);            i++;
  1079. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWFORM) */
  1080.  
  1081. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON)
  1082.     selFileCancel = XtCreateManagedWidget("selFileCancel",
  1083.         XwpushButtonWidgetClass, selFileForm, arglist, i);
  1084. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1085.     selFileCancel = XtCreateManagedWidget("selFileCancel",
  1086.         commandWidgetClass, selFileForm, arglist, i);
  1087. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1088.  
  1089.     XtRealizeWidget(selFile);
  1090.  
  1091.     SFcreateGC();
  1092.  
  1093.     xtermCursor = XCreateFontCursor(SFdisplay, XC_xterm);
  1094.  
  1095. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  1096.     sbDownArrowCursor = XCreateFontCursor(SFdisplay, XC_sb_down_arrow);
  1097.     sbLeftArrowCursor = XCreateFontCursor(SFdisplay, XC_sb_left_arrow);
  1098.     sbUpArrowCursor = XCreateFontCursor(SFdisplay, XC_sb_up_arrow);
  1099. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  1100.  
  1101.     sbRightArrowCursor = XCreateFontCursor(SFdisplay, XC_sb_right_arrow);
  1102.     dotCursor = XCreateFontCursor(SFdisplay, XC_dot);
  1103.  
  1104.     XDefineCursor(SFdisplay, XtWindow(selFileForm), xtermCursor);
  1105.     XDefineCursor(SFdisplay, XtWindow(selFileField), xtermCursor);
  1106.  
  1107. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  1108.     XDefineCursor(SFdisplay, XtWindow(selFileHScroll), sbDownArrowCursor);
  1109. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  1110.  
  1111.     for (n = 0; n < 3; n++) {
  1112.         XDefineCursor(SFdisplay, XtWindow(selFileLists[n]),
  1113.             sbRightArrowCursor);
  1114.  
  1115. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR)
  1116.         XDefineCursor(SFdisplay, XtWindow(selFileVScrolls[n]),
  1117.             sbLeftArrowCursor);
  1118.         XDefineCursor(SFdisplay, XtWindow(selFileHScrolls[n]),
  1119.             sbUpArrowCursor);
  1120. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSCROLLBAR) */
  1121.  
  1122.     }
  1123.     XDefineCursor(SFdisplay, XtWindow(selFileOK), dotCursor);
  1124.     XDefineCursor(SFdisplay, XtWindow(selFileCancel), dotCursor);
  1125.  
  1126.     for (n = 0; n < 3; n++) {
  1127.         XtAddEventHandler(selFileLists[n], ExposureMask, True,
  1128.             SFexposeList, (caddr_t) n);
  1129.         XtAddEventHandler(selFileLists[n], EnterWindowMask, False,
  1130.             SFenterList, (caddr_t) n);
  1131.         XtAddEventHandler(selFileLists[n], LeaveWindowMask, False,
  1132.             SFleaveList, (caddr_t) n);
  1133.         XtAddEventHandler(selFileLists[n], PointerMotionMask, False,
  1134.             SFmotionList, (caddr_t) n);
  1135.         XtAddEventHandler(selFileLists[n], ButtonPressMask, False,
  1136.             SFbuttonPressList, (caddr_t) n);
  1137.         XtAddEventHandler(selFileLists[n], ButtonReleaseMask, False,
  1138.             SFbuttonReleaseList, (caddr_t) n);
  1139.     }
  1140.  
  1141. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  1142.     XtAddCallback(selFileField, XtNexecute, returnCallback, (caddr_t) NULL);
  1143. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  1144.     XtAddEventHandler(selFileField, KeyPressMask, False,
  1145.         SFmodVerifyCallback, (caddr_t) NULL);
  1146. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  1147.  
  1148.     SFapp = XtWidgetToApplicationContext(selFile);
  1149. }
  1150.  
  1151. SFtextChanged()
  1152. {
  1153.  
  1154. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  1155.     static char    *SFtextBuffer = NULL;
  1156.  
  1157. #ifdef SEL_FILE_JAPANESE
  1158.     static int    alloc = 0;
  1159.     wchar_t        *wstr;
  1160.     int        len;
  1161. #endif /* def SEL_FILE_JAPANESE */
  1162.  
  1163. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  1164.  
  1165. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  1166.  
  1167. #ifdef SEL_FILE_JAPANESE
  1168.     wstr = XwTextCopyBuffer(selFileField);
  1169.     len = convWStoEUC(wstr, (unsigned char *) NULL);
  1170.     while (len + 1 > alloc) {
  1171.         alloc = 2 * (alloc + 1);
  1172.         SFtextBuffer = XtRealloc(SFtextBuffer, (unsigned) alloc);
  1173.     }
  1174.     (void) convWStoEUC(wstr, (unsigned char *) SFtextBuffer);
  1175.     XtFree((char *) wstr);
  1176. #else /* def SEL_FILE_JAPANESE */
  1177.     XtFree(SFtextBuffer);
  1178.     SFtextBuffer = (char *) XwTextCopyBuffer(selFileField);
  1179. #endif /* def SEL_FILE_JAPANESE */
  1180.  
  1181. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  1182.  
  1183.     if ((SFtextBuffer[0] == '/') || (SFtextBuffer[0] == '~')) {
  1184.         (void) strcpy(SFcurrentPath, SFtextBuffer);
  1185.  
  1186. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  1187.         SFtextPos = XwTextGetInsertPos(selFileField);
  1188. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  1189.         SFtextPos = XtTextGetInsertionPoint(selFileField);
  1190. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  1191.  
  1192.     } else {
  1193.         (void) strcat(strcpy(SFcurrentPath, SFstartDir), SFtextBuffer);
  1194.  
  1195. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT)
  1196.         SFtextPos = XwTextGetInsertPos(selFileField) +
  1197.             strlen(SFstartDir);
  1198. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  1199.         SFtextPos = XtTextGetInsertionPoint(selFileField) +
  1200.             strlen(SFstartDir);
  1201. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWTEXTEDIT) */
  1202.  
  1203.     }
  1204.  
  1205.     if (!SFworkProcAdded) {
  1206.         (void) XtAppAddWorkProc(SFapp, SFworkProc, NULL);
  1207.         SFworkProcAdded = 1;
  1208.     }
  1209.  
  1210.     SFupdatePath();
  1211. }
  1212.  
  1213. static char *
  1214. SFgetText()
  1215. {
  1216.     return strcpy(XtMalloc((unsigned) (strlen(SFcurrentPath) + 1)),
  1217.         SFcurrentPath);
  1218. }
  1219.  
  1220. static
  1221. SFprepareToReturn()
  1222. {
  1223.     SFstatus = SEL_FILE_NULL;
  1224.     XtRemoveGrab(selFile);
  1225.     XtUnmapWidget(selFile);
  1226.     XtRemoveTimeOut(SFdirModTimerId);
  1227.     if (SFchdir(SFstartDir)) {
  1228.         XtAppError(
  1229.             SFapp,
  1230.             "XsraSelFile: can't return to current directory"
  1231.         );
  1232.     }
  1233. }
  1234.  
  1235. int
  1236. XsraSelFile(display, prompt, ok, cancel, init_path, show_entry, path_return)
  1237.     Display        *display;
  1238.     unsigned char    *prompt;
  1239.     unsigned char    *ok;
  1240.     unsigned char    *cancel;
  1241.     char        *init_path;
  1242.     int        (*show_entry)();
  1243.     char        **path_return;
  1244. {
  1245.     static int    firstTime = 1;
  1246.  
  1247. #ifdef SEL_FILE_JAPANESE
  1248.     CStr        csl[2];
  1249.     u_char        cstr[256];
  1250. #endif /* def SEL_FILE_JAPANESE */
  1251.  
  1252.     int        i;
  1253.     Arg        arglist[20];
  1254.     XEvent        event;
  1255.  
  1256.     if ((!display) && firstTime) {
  1257.         Widget    w;
  1258.         int    argc;
  1259.         char    *argv[1];
  1260.  
  1261.         argc = 1;
  1262.         argv[0] = "xfoo";
  1263.         w = XtInitialize(argv[0], "XFoo", (XrmOptionDescRec *) NULL, 0,
  1264.             (Cardinal *) &argc, argv);
  1265.         display = XtDisplay(w);
  1266.     }
  1267.  
  1268.     if (!prompt) {
  1269.         prompt = (unsigned char *) "Pathname:";
  1270.     }
  1271.  
  1272.     if (!ok) {
  1273.         ok = (unsigned char *) "OK";
  1274.     }
  1275.  
  1276.     if (!cancel) {
  1277.         cancel = (unsigned char *) "Cancel";
  1278.     }
  1279.  
  1280.     if (firstTime) {
  1281.         firstTime = 0;
  1282.         SFdisplay = display;
  1283.         SFcreateWidgets(prompt, ok, cancel);
  1284.     } else {
  1285.         if (display && (SFdisplay != display)) {
  1286.             XtAppError(SFapp, "XsraSelFile: display different");
  1287.         }
  1288.  
  1289.         i = 0;
  1290.  
  1291. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT)
  1292.  
  1293. #ifdef SEL_FILE_JAPANESE
  1294.  
  1295. #ifdef SEL_FILE_SJIS
  1296.         (void) convSJIStoCS(prompt, cstr);
  1297. #else /* def SEL_FILE_SJIS */
  1298.         (void) convEUCtoCS(prompt, cstr);
  1299. #endif /* def SEL_FILE_SJIS */
  1300.  
  1301.         csl[0] = cstr;
  1302.         csl[1] = NULL;
  1303.         XtSetArg(arglist[i], XtNstrings, csl);            i++;
  1304. #else /* def SEL_FILE_JAPANESE */
  1305.         XtSetArg(arglist[i], XtNstring, prompt);        i++;
  1306. #endif /* def SEL_FILE_JAPANESE */
  1307.  
  1308. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT) */
  1309.         XtSetArg(arglist[i], XtNlabel, prompt);            i++;
  1310. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWSTATICTEXT) */
  1311.  
  1312.         XtSetValues(selFilePrompt, arglist, i);
  1313.  
  1314.         i = 0;
  1315.  
  1316. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON)
  1317.  
  1318. #ifdef SEL_FILE_JAPANESE
  1319.  
  1320. #ifdef SEL_FILE_SJIS
  1321.         (void) convSJIStoCS(ok, cstr);
  1322. #else /* def SEL_FILE_SJIS */
  1323.         (void) convEUCtoCS(ok, cstr);
  1324. #endif /* def SEL_FILE_SJIS */
  1325.  
  1326.         XtSetArg(arglist[i], XtNlabel, cstr);            i++;
  1327. #else /* def SEL_FILE_JAPANESE */
  1328.         XtSetArg(arglist[i], XtNlabel, ok);            i++;
  1329. #endif /* def SEL_FILE_JAPANESE */
  1330.  
  1331. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1332.         XtSetArg(arglist[i], XtNlabel, ok);            i++;
  1333. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1334.  
  1335.         XtSetValues(selFileOK, arglist, i);
  1336.  
  1337.         i = 0;
  1338.  
  1339. #if defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON)
  1340.  
  1341. #ifdef SEL_FILE_JAPANESE
  1342.  
  1343. #ifdef SEL_FILE_SJIS
  1344.         (void) convSJIStoCS(cancel, cstr);
  1345. #else /* def SEL_FILE_SJIS */
  1346.         (void) convEUCtoCS(cancel, cstr);
  1347. #endif /* def SEL_FILE_SJIS */
  1348.  
  1349.         XtSetArg(arglist[i], XtNlabel, cstr);            i++;
  1350. #else /* def SEL_FILE_JAPANESE */
  1351.         XtSetArg(arglist[i], XtNlabel, cancel);            i++;
  1352. #endif /* def SEL_FILE_JAPANESE */
  1353.  
  1354. #else /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1355.         XtSetArg(arglist[i], XtNlabel, cancel);            i++;
  1356. #endif /* defined(SEL_FILE_XW) || defined(SEL_FILE_XWPUSHBUTTON) */
  1357.  
  1358.         XtSetValues(selFileCancel, arglist, i);
  1359.  
  1360.         XtMapWidget(selFile);
  1361.     }
  1362.  
  1363. #ifdef SYSV
  1364.     if (!getwd(SFstartDir)) {
  1365.     /* if (!getcwd(SFstartDir, MAXPATHLEN)) { */
  1366. #else /* def SYSV */
  1367.     if (!getwd(SFstartDir)) {
  1368. #endif /* def SYSV */
  1369.  
  1370.         XtAppError(SFapp, "XsraSelFile: can't get current directory");
  1371.     }
  1372.     (void) strcat(SFstartDir, "/");
  1373.     (void) strcpy(SFcurrentDir, SFstartDir);
  1374.  
  1375.     if (init_path) {
  1376.         if (init_path[0] == '/') {
  1377.             (void) strcpy(SFcurrentPath, init_path);
  1378.             if (strncmp(
  1379.                 SFcurrentPath,
  1380.                 SFstartDir,
  1381.                 strlen(SFstartDir)
  1382.             )) {
  1383.                 SFsetText(SFcurrentPath);
  1384.             } else {
  1385.                 SFsetText(&(SFcurrentPath[strlen(SFstartDir)]));
  1386.             }
  1387.         } else {
  1388.             (void) strcat(strcpy(SFcurrentPath, SFstartDir),
  1389.                 init_path);
  1390.             SFsetText(&(SFcurrentPath[strlen(SFstartDir)]));
  1391.         }
  1392.     } else {
  1393.         (void) strcpy(SFcurrentPath, SFstartDir);
  1394.     }
  1395.  
  1396.     SFfunc = show_entry;
  1397.  
  1398.     SFtextChanged();
  1399.  
  1400.     XtAddGrab(selFile, True, True);
  1401.  
  1402.     SFdirModTimerId = XtAppAddTimeOut(SFapp, (unsigned long) 1000,
  1403.         SFdirModTimer, (caddr_t) NULL);
  1404.  
  1405.     while (1) {
  1406.         XtAppNextEvent(SFapp, &event);
  1407.         XtDispatchEvent(&event);
  1408.         switch (SFstatus) {
  1409.         case SEL_FILE_TEXT:
  1410.             SFstatus = SEL_FILE_NULL;
  1411.             SFtextChanged();
  1412.             break;
  1413.         case SEL_FILE_OK:
  1414.             SFprepareToReturn();
  1415.             if (path_return) {
  1416.                 *path_return = SFgetText();
  1417.             }
  1418.             return SEL_FILE_OK;
  1419.         case SEL_FILE_CANCEL:
  1420.             SFprepareToReturn();
  1421.             return SEL_FILE_CANCEL;
  1422.         case SEL_FILE_NULL:
  1423.             break;
  1424.         }
  1425.     }
  1426. }
  1427. \End\Of\File\
  1428. else
  1429.   echo "will not over write ./SelFile.c"
  1430. fi
  1431. if `test ! -s ./SelFile.man`
  1432. then
  1433. echo "writing ./SelFile.man"
  1434. cat > ./SelFile.man << '\End\Of\File\'
  1435. .\" $Header: SelFile.man,v 1.3 89/04/24 22:27:00 erik Exp $
  1436. .\"
  1437. .\" Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
  1438. .\"
  1439. .\" Permission to use, copy, modify, and distribute this software and its
  1440. .\" documentation for any purpose and without fee is hereby granted, provided
  1441. .\" that the above copyright notice appear in all copies and that both that
  1442. .\" copyright notice and this permission notice appear in supporting
  1443. .\" documentation, and that the name of Software Research Associates not be used
  1444. .\" in advertising or publicity pertaining to distribution of the software
  1445. .\" without specific, written prior permission.  Software Research Associates
  1446. .\" makes no representations about the suitability of this software for any
  1447. .\" purpose.  It is provided "as is" without express or implied warranty.
  1448. .\"
  1449. .\" SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  1450. .\" SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  1451. .\" IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
  1452. .\" INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  1453. .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  1454. .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1455. .\" PERFORMANCE OF THIS SOFTWARE.
  1456. .\"
  1457. .\" Author: Erik M. van der Poel
  1458. .\"         Software Research Associates, Inc., Tokyo, Japan
  1459. .\"
  1460. .TH XSRASELFILE 3X "April 24 1989" SRA
  1461. .SH NAME
  1462. \fIXsraSelFile\fR \- select a file
  1463. .sp
  1464. .SH SYNOPSIS
  1465. .nf
  1466. .ft B
  1467. #include <stdio.h>
  1468. #include <X11/Intrinsic.h>
  1469. .PP
  1470. .ft B
  1471. .ta +\w'unsigned char  'u
  1472. ret = XsraSelFile(display, prompt, ok, cancel, init_path, show_entry, path_return)
  1473. int    ret;
  1474. Display    *display;
  1475. unsigned char    *prompt;
  1476. unsigned char    *ok;
  1477. unsigned char    *cancel;
  1478. char    *init_path;
  1479. int    (*show_entry)();
  1480. char    **path_return;
  1481. .fi
  1482. .sp
  1483. .SH DESCRIPTION
  1484. .I XsraSelFile
  1485. allows an X11 user to select a file by typing the path or by browsing in
  1486. directory listings and selecting entries with the mouse.
  1487. .sp
  1488. The space bar can be pressed to complete filenames, and tilde is used for home
  1489. directories.
  1490. All of the usual key bindings can be used in the text widget, except for Return
  1491. and Control-M, which are equivalent to pressing the OK button.
  1492. The path can be scrolled using the large horizontal scroll bar, or by moving
  1493. the insertion cursor in the text widget.
  1494. The directory entries can be scrolled using the vertical scroll bars, or by
  1495. holding a mouse button down and moving out of the listing.
  1496. The scrolling speed varies with the distance from the listing.
  1497. .sp
  1498. The directory entries are terminated with special characters that indicate the
  1499. kind of entry, similar to the
  1500. .I \-F
  1501. option of
  1502. .IR ls (1).
  1503. .sp
  1504. The programmer's interface is simple, providing an easy way for the application
  1505. to obtain a filename from the user.
  1506. .sp
  1507. .I XsraSelFile
  1508. does not allow X events to be generated on any other widgets in the application
  1509. by adding a grab for the dialog widget while it is active.
  1510. .sp
  1511. .SH ARGUMENTS
  1512. The
  1513. .B display
  1514. argument specifies the display on which to create the new application shell
  1515. dialog widget.
  1516. If it is specified as NULL, the default display is opened by initializing the X
  1517. toolkit.
  1518. .sp
  1519. The
  1520. .B prompt
  1521. argument specifies the prompt to print near the top of the new widget.
  1522. This should be a string containing no newlines.
  1523. If the prompt is specified as NULL, the string "Pathname:" is used.
  1524. .sp
  1525. The
  1526. .B ok
  1527. argument specifies the string to print in the OK button.
  1528. If it is specified as NULL, "OK" is used.
  1529. .sp
  1530. The
  1531. .B cancel
  1532. argument specifies the string to print in the Cancel button.
  1533. If it is specified as NULL, "Cancel" is used.
  1534. .sp
  1535. The initial path may be set using
  1536. .BR init_path .
  1537. If it is specified as NULL, the initial path will be the current directory.
  1538. .sp
  1539. The
  1540. .B show_entry
  1541. argument is a pointer to a function that is called to decide whether or not to
  1542. display a particular directory entry.
  1543. If this argument is specified as NULL, all entries will be displayed.
  1544. Otherwise, the function is called with arguments as follows.
  1545. .sp
  1546. .nf
  1547. .ft I
  1548. .ta +\w'struct stat  'u
  1549. int show_entry(real_name, shown_name_return, entry_stat)
  1550. char    *real_name;
  1551. char    **shown_name_return;
  1552. struct stat    *entry_stat;
  1553. .ft R
  1554. .fi
  1555. .sp
  1556. The
  1557. .I real_name
  1558. argument is the name of the entry, and the
  1559. .I entry_stat
  1560. argument is a pointer to the stat buffer of the entry.
  1561. The contents of the real_name and entry_stat arguments should not be altered.
  1562. The
  1563. .I shown_name_return
  1564. argument is to be filled in by the function if a name other than the real name
  1565. is to be shown.
  1566. The function should return true if the entry is to be displayed.
  1567. An example of a show_entry function can be found in
  1568. .IR callback.c .
  1569. .sp
  1570. When the return key or the OK button is pressed,
  1571. .I XsraSelFile
  1572. returns, putting the full path of the selected file in
  1573. .B path_return
  1574. unless it is NULL.
  1575. .I XtMalloc
  1576. is used to make a copy of the path.
  1577. The application writer is responsible for freeing the space.
  1578. .sp
  1579. .SH RETURN VALUE
  1580. The
  1581. .B ret
  1582. return value is 0 if the user presses the return key or the OK button.
  1583. Otherwise, the user has pressed the Cancel button and a value of \-1 is
  1584. returned.
  1585. .sp
  1586. .SH COMPILATION
  1587. The XsraSelFile package can be linked with Athena (Xaw) and/or Hewlett-Packard
  1588. (Xw) widgets, by choosing the appropriate defines. See the Imakefile for
  1589. details.
  1590. .sp
  1591. .SH RESOURCES
  1592. The font to be used by
  1593. .I XsraSelFile
  1594. is specified by putting the following in a resource file:
  1595. .sp
  1596. .ft H
  1597.     selFile*font    :9x15
  1598. .ft R
  1599. .sp
  1600. (The default font is
  1601. .IR 9x15 .)
  1602. .sp
  1603. .SH ENVIRONMENT
  1604. DISPLAY \- the default host and display to use.
  1605. .sp
  1606. .SH "SEE ALSO"
  1607. X(1), xrdb(1), X Toolkit
  1608. .sp
  1609. .SH BUGS
  1610. .I XsraSelFile
  1611. must always be called with the same
  1612. .I display
  1613. argument.
  1614. .sp
  1615. When a directory is modified by a third party while the pointer is in that
  1616. directory's listing, the display will be updated and the pointer will be warped
  1617. away to prevent the user from selecting `the wrong file', which can be
  1618. considered dangerous if the application is about to delete whatever the user
  1619. selects.
  1620. .sp
  1621. .SH COPYRIGHT
  1622. Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
  1623. .sp
  1624. .SH AUTHOR
  1625. Erik M. van der Poel, Software Research Associates, Inc., Tokyo, Japan
  1626. \End\Of\File\
  1627. else
  1628.   echo "will not over write ./SelFile.man"
  1629. fi
  1630. if `test ! -s ./TODO`
  1631. then
  1632. echo "writing ./TODO"
  1633. cat > ./TODO << '\End\Of\File\'
  1634. * Variable number of lists (instead of 3), variable no. of entries, etc.
  1635.   Perhaps turn it into a widget?
  1636.  
  1637. * Use X selections instead of cut buffer.
  1638.   This would enable clients to obtain pathnames through selections, and the
  1639.   client would not have to link in the XsraSelFile code.
  1640.  
  1641. * Some clients may want to have more control over what happens in the
  1642.   XtAppNextEvent-XtDispatchEvent loop.
  1643.  
  1644. * Another idea is a text widget with file name completion that can be embedded
  1645.   in an application. The completions would only be popped up when the user
  1646.   wants to see them.
  1647.  
  1648. * Make another package for completion of not only filenames, but anything.
  1649.  
  1650. * launching by eg double click
  1651.  
  1652. * scrolling and selection through keyboard
  1653.  
  1654. * if file to be read, it must exist
  1655.  
  1656. * allow the user to specify the filename pattern e.g. *.c
  1657.  
  1658. * customized buttons eg vi
  1659.  
  1660. * directory stack option
  1661.  
  1662. * search (RE)
  1663.  
  1664. * file stat info
  1665. \End\Of\File\
  1666. else
  1667.   echo "will not over write ./TODO"
  1668. fi
  1669. if `test ! -s ./callback.c`
  1670. then
  1671. echo "writing ./callback.c"
  1672. cat > ./callback.c << '\End\Of\File\'
  1673. #ifndef lint
  1674. static char rcsid[] = "$Header: callback.c,v 1.2 89/05/29 15:06:48 erik Exp $";
  1675. #endif
  1676.  
  1677. /*
  1678.  * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
  1679.  *
  1680.  * Permission to use, copy, modify, and distribute this software and its
  1681.  * documentation for any purpose and without fee is hereby granted, provided
  1682.  * that the above copyright notice appear in all copies and that both that
  1683.  * copyright notice and this permission notice appear in supporting
  1684.  * documentation, and that the name of Software Research Associates not be used
  1685.  * in advertising or publicity pertaining to distribution of the software
  1686.  * without specific, written prior permission.  Software Research Associates
  1687.  * makes no representations about the suitability of this software for any
  1688.  * purpose.  It is provided "as is" without express or implied warranty.
  1689.  *
  1690.  * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  1691.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  1692.  * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
  1693.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  1694.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  1695.  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1696.  * PERFORMANCE OF THIS SOFTWARE.
  1697.  *
  1698.  * Author: Erik M. van der Poel
  1699.  *         Software Research Associates, Inc., Tokyo, Japan
  1700.  */
  1701.  
  1702. #include <stdio.h>
  1703. #include <X11/Intrinsic.h>
  1704. #include <sys/stat.h>
  1705.  
  1706. extern char *re_comp();
  1707.  
  1708. static int
  1709. match(exp, str)
  1710.     char    *exp, *str;
  1711. {
  1712.     char    *err;
  1713.  
  1714.     if (err = re_comp(exp)) {
  1715.         (void) fprintf(stderr, "re_comp(\"%s\"): %s\n", exp, err);
  1716.         exit(1);
  1717.     }
  1718.  
  1719.     return re_exec(str);
  1720. }
  1721.  
  1722. int
  1723. fileCheck(realFileName, shownFileName, fileStat)
  1724.     char        *realFileName;
  1725.     char        **shownFileName;
  1726.     struct stat    *fileStat;
  1727. {
  1728.     static char    shown[256];
  1729.  
  1730.     switch (match("^..*\.plt$", realFileName)) {
  1731.     case 0:
  1732.     case -1:
  1733.     default:
  1734.         break;
  1735.     case 1:
  1736.         if ((fileStat->st_mode & S_IFMT) == S_IFREG) {
  1737.             (void) strcpy(shown, realFileName);
  1738.             *(rindex(shown, '.')) = 0;
  1739.             *shownFileName = shown;
  1740.         }
  1741.         return 1;
  1742.     }
  1743.  
  1744.     switch (match("^..*\.xy$", realFileName)) {
  1745.     case 0:
  1746.     case -1:
  1747.     default:
  1748.         break;
  1749.     case 1:
  1750.         return 0;
  1751.     }
  1752.  
  1753.     switch (match("^..*\.z$", realFileName)) {
  1754.     case 0:
  1755.     case -1:
  1756.     default:
  1757.         break;
  1758.     case 1:
  1759.         return 0;
  1760.     }
  1761.  
  1762.     return 1;
  1763. }
  1764. \End\Of\File\
  1765. else
  1766.   echo "will not over write ./callback.c"
  1767. fi
  1768. if `test ! -s ./xdir.c`
  1769. then
  1770. echo "writing ./xdir.c"
  1771. cat > ./xdir.c << '\End\Of\File\'
  1772. #ifndef lint
  1773. static char rcsid[] = "$Header: xdir.c,v 1.3 89/05/29 15:07:10 erik Exp $";
  1774. #endif
  1775.  
  1776. /*
  1777.  * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan
  1778.  *
  1779.  * Permission to use, copy, modify, and distribute this software and its
  1780.  * documentation for any purpose and without fee is hereby granted, provided
  1781.  * that the above copyright notice appear in all copies and that both that
  1782.  * copyright notice and this permission notice appear in supporting
  1783.  * documentation, and that the name of Software Research Associates not be used
  1784.  * in advertising or publicity pertaining to distribution of the software
  1785.  * without specific, written prior permission.  Software Research Associates
  1786.  * makes no representations about the suitability of this software for any
  1787.  * purpose.  It is provided "as is" without express or implied warranty.
  1788.  *
  1789.  * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  1790.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  1791.  * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES BE LIABLE FOR ANY SPECIAL,
  1792.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  1793.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  1794.  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1795.  * PERFORMANCE OF THIS SOFTWARE.
  1796.  *
  1797.  * Author: Erik M. van der Poel
  1798.  *         Software Research Associates, Inc., Tokyo, Japan
  1799.  */
  1800.  
  1801. #include <stdio.h>
  1802. #include <X11/Intrinsic.h>
  1803.  
  1804. main(argc, argv)
  1805.     int    argc;
  1806.     char    *argv[];
  1807. {
  1808.     Widget    XDir;
  1809.     char    *path;
  1810.  
  1811.     XDir = XtInitialize(argv[0], "XDir", (XrmOptionDescRec *) NULL,
  1812.         (Cardinal) 0, (Cardinal *) &argc, argv);
  1813.  
  1814.     while (1) {
  1815.         if (XsraSelFile(
  1816.             XtDisplay(XDir),
  1817.             (unsigned char *) "Pathname to store in cut buffer:",
  1818.             (unsigned char *) "Cut",
  1819.             (unsigned char *) "Exit",
  1820.             (char *) NULL,
  1821.             (int (*)()) NULL,
  1822.             &path
  1823.         )) {
  1824.             break;
  1825.         }
  1826.         XStoreBytes(XtDisplay(XDir), path, strlen(path));
  1827.         XtFree(path);
  1828.     }
  1829.  
  1830.     return 0;
  1831. }
  1832. \End\Of\File\
  1833. else
  1834.   echo "will not over write ./xdir.c"
  1835. fi
  1836. echo "Finished archive 1 of 2"
  1837. exit
  1838.