home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume17 / tcleditr / part03 < prev    next >
Encoding:
Text File  |  1992-03-17  |  57.6 KB  |  2,110 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!think.com!mips!msi!dcmartin
  3. From: crowley@chaco.cs.unm.edu (Charlie Crowley)
  4. Subject: v17i004: point text editor (TCL and TK), Part03/16
  5. Message-ID: <1992Mar18.141336.26587@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Organization: Molecular Simulations, Inc.
  9. References: <csx-17i002-tcl-editor@uunet.UU.NET>
  10. Date: Wed, 18 Mar 1992 14:13:36 GMT
  11. Approved: dcmartin@msi.com
  12.  
  13. Submitted-by: crowley@chaco.cs.unm.edu (Charlie Crowley)
  14. Posting-number: Volume 17, Issue 4
  15. Archive-name: tcl-editor/part03
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 2 (of 15)."
  24. # Contents:  Changes.log anaDialogs.c findpos.c goto.c inschar.c
  25. #   library.c repaint.c replace.c stats.c tclLib/init.tcl
  26. #   tclLib/subs.tcl tclLib/windows.tcl
  27. # Wrapped by crowley@chaco.cs.unm.edu on Tue Mar 10 15:05:34 1992
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'Changes.log' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'Changes.log'\"
  31. else
  32. echo shar: Extracting \"'Changes.log'\" \(4484 characters\)
  33. sed "s/^X//" >'Changes.log' <<'END_OF_FILE'
  34. X    Changes to Point
  35. X
  36. X7 feb 92 -- Version 1.1 of Point which is compatible with the Tk1.4 toolkit
  37. X         and Tcl 6.2
  38. X
  39. X13 feb 92 -- compile bug in tkColbox.c fixed.  Wrong number of arguments.
  40. X
  41. X18 feb 92 -- add regular expression seach and regular expression replace.
  42. X          The form of the regular expression is the same as in grep/ed
  43. X          (not full regular expressions as in egrep).  The replace is the
  44. X          same as in the 's' command in ed, ex, sed and vi. Added commands:
  45. X          * RegexSearch -- search for a regular expression
  46. X          * RepeatRegexSearch -- search for the last RE entered
  47. X          * RegexReplaceOne -- replace the last string found in an RE search
  48. X          * RegexReplaceAll -- do a complete RE replace operation
  49. X
  50. X18 feb 92 -- rearranged the order in most of the menus.
  51. X
  52. X20 feb 92 -- Version 1.2 of Point with regular expressions.
  53. X
  54. X21 feb 92 -- corrected some problems with cursor motion from keys, that is,
  55. X    the MoveSel cluster of operations.  They seem to work now in that
  56. X    they don't mess up the display.  Also cursor right and cursor left
  57. X    now move the next or previous line as expected.
  58. X
  59. X23 feb 92 -- fixed a problem where Point would fail on partial geometries,
  60. X    that is, ones with the +N+N at the end (only the dimensions)
  61. X
  62. X28 feb 92 -- changed tkerror so that it doesn't print anything.  I was getting
  63. X    too many spurious errors caused by Tk menu problems
  64. X
  65. X3 mar 92 -- Sel get now returns the line number of the first character of
  66. X    the selection as an argument: firstChar lastChar windowName
  67. X    selectionMode lineNumberOfFirstChar
  68. X
  69. X3 mar 92 -- selecting in line mode (triple clicking) now displays the line
  70. X    numer of the first character of the selection in the browwser
  71. X    message area
  72. X
  73. X3 mar 92 -- changed FILE menu, 'Close' --> 'Close window' and added a
  74. X    'Quit Point =>'    menu
  75. X
  76. X4 mar 92 -- fixed bugs: when the browser was showing file sizes the names
  77. X    were not gotten correctly and you could not open and files or CD.
  78. X    Also directories were not sorted first when file sizes were
  79. X    showing.
  80. X
  81. X4 mar 92 -- added option 'insertReplaces'.  The default is False.  When it
  82. X    is set to True, then a selection of more than one character will
  83. X    be deleted when characters are typed.  This makes the insert like
  84. X    the Macintosh for selection larger than one character.  This
  85. X    facility is a compromise.  It does not replace for selections
  86. X    of only one character because Point does not allow zero width
  87. X    selections.
  88. X
  89. X4 mar 92 -- added an option 'titleFormat' that allows you to format the
  90. X    contents of the title line.  It is like a printf format with
  91. X    the following conversions:
  92. X    %n -- the file name (affected by pathNames option)
  93. X    %N -- the full path name of the file
  94. X    %s -- the short file name
  95. X    %c/modMsg/ -- "modMsg" if the file has changed and "" otherwise.
  96. X        The matching '/'s can be any character.
  97. X    %r/readOnlyMsg/ -- "readOnlyMsg" if file is read only
  98. X        and "" otherwise.  The matching '/'s can be any character.
  99. X    %o/overtypeMsg/ -- "overtypeMsg" if Point is in overType mode
  100. X        and "" otherwise.  The matching '/'s can be any character.
  101. X    %l -- the line number of the top line in the window
  102. X    %L -- the line number of the bottom line in the window
  103. X    %p -- the character number of the first character in the window
  104. X    %P -- the character number of the last character in the window
  105. X    %S -- the size of the file in characters
  106. X    %v -- the column number of the leftmost column in the window
  107. X    %V -- the column number of the rightmost column in the window
  108. X
  109. X4 mar 92 -- added an option "iconFormat" which is specified like "titleFormat"
  110. X    but affects the icon name of text windows.
  111. X
  112. X5 mar 92 -- changed pt to open windows at location1, location2 or location3.
  113. X    location1 is the default.  pt takes arguments of the form -1, -2
  114. X    and -3 that affect all subsequent windows until changed.  E.g.:
  115. X        pt -2 file1 -1 *.c -3 file2
  116. X
  117. X5 mar 92 -- removed 'lineNumbers' option.  Instead line numbering is done
  118. X    on a window by window basis.  There is a new command 'SetLineNumbers'.
  119. X    The first argument is the window to be affected ("" means the
  120. X    current window.  The second argument can be "0" to turn off line
  121. X    numbering and "1" to turn it on.  Anything else    toggles the it.
  122. X
  123. X5 mar 92 -- fixed but in pt where it used the cwd of point rather than
  124. X    of pt.  Also changed the default to not wait for the windows
  125. X    to close.  Thus the -nw and -nowait options are eliminated and
  126. X    replaced by option -w and -wait.
  127. X
  128. X5 mar 92 -- Version 1.3 of Point with the above changes and fixes.
  129. X
  130. X
  131. END_OF_FILE
  132. if test 4484 -ne `wc -c <'Changes.log'`; then
  133.     echo shar: \"'Changes.log'\" unpacked with wrong size!
  134. fi
  135. # end of 'Changes.log'
  136. fi
  137. if test -f 'anaDialogs.c' -a "${1}" != "-c" ; then 
  138.   echo shar: Will not clobber existing file \"'anaDialogs.c'\"
  139. else
  140. echo shar: Extracting \"'anaDialogs.c'\" \(3942 characters\)
  141. sed "s/^X//" >'anaDialogs.c' <<'END_OF_FILE'
  142. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/anaDialogs.c,v 1.4 1992/03/04 17:07:18 crowley Exp crowley $ */
  143. X
  144. X#ifdef HYPERTEXT
  145. X#include <string.h>
  146. X#include "pt.h"
  147. X
  148. DBM *currentDB;
  149. Document currentDocument;
  150. AttributeID mainFileBlock;
  151. MapID naturalMap;
  152. X
  153. PickListItem *
  154. GenerateIDList( id_in, magic )
  155. X    ID id_in;
  156. X    MagicNumber magic;
  157. X{
  158. X    extern DBM *currentDB;
  159. X
  160. X    PickListItem * itemListFront;
  161. X    PickListItem * itemListBack = NULL;
  162. X    ID id = id_in;
  163. X    AnaObject ana_object;
  164. X    int len;
  165. X    
  166. X    while( id != NullObject ) {
  167. X        /* allocate a new struct to hold the next item */
  168. X        PickListItem * new_item =
  169. X            (PickListItem *)PtMalloc(sizeof(PickListItem),"list");
  170. X        ana_object = GetObject( currentDB, magic, id, NO_ALLOCATE );
  171. X        /* copy the name and id into the struct */
  172. X        len = strlen(ana_object->name) + 1;
  173. X        new_item->name = (char *)PtMalloc( len, "name" );
  174. X        strcpy( new_item->name, ana_object->name );
  175. X        new_item->id = id;
  176. X        new_item->next = NULL;
  177. X        /* link it on the back of the list */
  178. X        if( itemListBack == NULL ) {
  179. X            itemListFront = new_item;
  180. X            itemListBack = new_item;
  181. X        } else {
  182. X            itemListBack->next = new_item;
  183. X            itemListBack = new_item;
  184. X        }
  185. X        /* and move to the next item */
  186. X        id = ana_object->next;
  187. X    }
  188. X    return itemListFront;
  189. X}
  190. X
  191. void
  192. XFreeIDList( itemList )
  193. X    PickListItem * itemList;
  194. X{
  195. X    while( itemList != NULL ) {
  196. X        PickListItem * toGo = itemList;
  197. X        itemList = itemList->next;
  198. X        PtFree( toGo->name );
  199. X        PtFree( (char *)toGo );
  200. X    }
  201. X}
  202. X
  203. static ID ID_chosen;
  204. X
  205. ID
  206. AnaPickBox( id_in, magic, label_string )
  207. X    ID id_in;
  208. X    MagicNumber magic;
  209. X    String label_string;
  210. X{
  211. X    extern DBM *currentDB;
  212. X    extern char msgBuffer[];
  213. X    extern char * returnString;
  214. X
  215. X    char *box_name, *s;
  216. X    PickListItem * itemList, *item;
  217. X
  218. X    /* get the list of items */
  219. X    itemList = GenerateIDList( id_in, magic );
  220. X        /* Create the list box */
  221. X    (void)ExecTclCommand( "update" );
  222. X    sprintf( msgBuffer, "MakePickBox {%s}", label_string );
  223. X    s = ExecTclCommand( msgBuffer );
  224. X    /* make a copy of the name */
  225. X    box_name = (char *)PtMalloc( strlen(s)+1, "name" );
  226. X    strcpy( box_name, s );
  227. X    /* fill the list box */
  228. X    item = itemList;
  229. X    while( item != NULL ) {
  230. X        sprintf( msgBuffer, "%s.slist.items insert end {%s}",
  231. X                        box_name, itemList->name );
  232. X        (void)ExecTclCommand( msgBuffer );
  233. X        item = item->next;
  234. X    }
  235. X
  236. X    /*  run a local event loop until the box is acted on */
  237. X    command( FWAITFORRETURNSTRING, "", "", "", "", "", "" );
  238. X    if( strcmp(returnString,"XXXcancelXXX") != 0 ) {
  239. X        int index = atoi(returnString);
  240. X        while( index-- > 0 )
  241. X            item = item->next;
  242. X        ID_chosen = item->id;
  243. printf( "Picked item %d, id %d, name <%s>\n", index, item->id, item->name );
  244. X    } else
  245. X        ID_chosen = -1;
  246. X
  247. X    FreeIDList( itemList );
  248. X    
  249. X    return ID_chosen;
  250. X}
  251. X
  252. AttributeID
  253. PickAttribute( document, label_string )
  254. X    Document document;
  255. X    String label_string;
  256. X{
  257. X    return (AttributeID) AnaPickBox( (ID)(document->firstAttribute),
  258. X                    AttributeMagic, label_string );
  259. X}
  260. X
  261. LinkID
  262. PickLink( document, label_string )
  263. X    Document document;
  264. X    String label_string;
  265. X{
  266. X    return (LinkID) AnaPickBox( (ID)(document->firstLink),
  267. X                    LinkMagic, label_string );
  268. X}
  269. X
  270. BlockID
  271. PickBlock( document, label_string )
  272. X    Document document;
  273. X    String label_string;
  274. X{
  275. X    return (BlockID) AnaPickBox( (ID)(document->firstBlock),
  276. X                    BlockMagic, label_string );
  277. X}
  278. X
  279. XFileID
  280. PickFile( document, label_string )
  281. X    Document document;
  282. X    String label_string;
  283. X{
  284. X    return (FileID) AnaPickBox( (ID)(document->firstFile),
  285. X                    FileMagic, label_string );
  286. X}
  287. X
  288. TextID
  289. PickText( document, label_string )
  290. X    Document document;
  291. X    String label_string;
  292. X{
  293. X    return (TextID) AnaPickBox( (ID)(document->firstText),
  294. X                    TextMagic, label_string );
  295. X}
  296. X
  297. MapID
  298. PickMap( document, label_string )
  299. X    Document document;
  300. X    String label_string;
  301. X{
  302. X    return (MapID) AnaPickBox( (ID)(document->firstMap),
  303. X                    MapMagic, label_string );
  304. X}
  305. X
  306. ViewID
  307. PickView( document, label_string )
  308. X    Document document;
  309. X    String label_string;
  310. X{
  311. X    return (ViewID) AnaPickBox( (ID)(document->firstView),
  312. X                    ViewMagic, label_string );
  313. X}
  314. X#endif
  315. X
  316. END_OF_FILE
  317. if test 3942 -ne `wc -c <'anaDialogs.c'`; then
  318.     echo shar: \"'anaDialogs.c'\" unpacked with wrong size!
  319. fi
  320. # end of 'anaDialogs.c'
  321. fi
  322. if test -f 'findpos.c' -a "${1}" != "-c" ; then 
  323.   echo shar: Will not clobber existing file \"'findpos.c'\"
  324. else
  325. echo shar: Extracting \"'findpos.c'\" \(4059 characters\)
  326. sed "s/^X//" >'findpos.c' <<'END_OF_FILE'
  327. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/findpos.c,v 1.2 1992/03/04 17:07:18 crowley Exp crowley $ */
  328. X
  329. X#include "pt.h"
  330. X
  331. Offset
  332. xyToOffset( w, row, col )
  333. X    struct window *w;
  334. X    int row, col;
  335. X{
  336. X    extern char msgBuffer[];
  337. X    extern struct window *windowList;
  338. X    extern int tabWidth;
  339. X    extern int debug;
  340. X
  341. X    Offset cp;
  342. X    int n, tabStop, rowsDown, iLine;
  343. X    int uch;
  344. X    int fid = w->fileId;
  345. X
  346. X    rowsDown = row;    /* rows down */
  347. X
  348. X#ifdef XXXXXXX
  349. X/* fix this later, maybe keep a flag to tell if the window has moved */
  350. X    /* has window moved since we last found a line? */
  351. X    doRowCache = 1;
  352. X    if( w->lastPosTop == w->posTopline ) {
  353. X        /* if so find the new line relative to it */
  354. X        cp = w->posCurLast;
  355. X        rowsDown -= w->rowCurLast;
  356. X        if( rowsDown < 0 ) {
  357. X            rowsDown = -rowsDown;
  358. X            cp = prevLine( fid, cp, &rowsDown );
  359. X        } else if( rowsDown > 0 )
  360. X            goto countDown;
  361. X    } else {
  362. X#endif
  363. X
  364. X        /* just count down from the top line */
  365. X        cp = w->posTopline;
  366. X#ifdef XXXXXXX
  367. X    countDown:
  368. X#endif
  369. X        n = rowsDown;
  370. X        cp = nextLine( fid, cp, &rowsDown );
  371. X
  372. X#ifdef FIX_THIS_LATER
  373. X        /* fix so that EOF works */
  374. X        if( (n -= rowsDown) > 0 ) {
  375. X            *inRow -= n;
  376. X            doRowCache = 0;
  377. X        }
  378. X        /* see if EOF on a line alone */
  379. X        if( (cp-1) > 0 &&
  380. X          (char)getFileByte( fid, cp-1 ) != '\n') {
  381. X            /* another fix so EOF works */
  382. X            --*inRow;
  383. X            doRowCache = 0;
  384. X        }
  385. X    }
  386. X    /* if we are near end of file, "row" and the */
  387. X    /* "cp" will not really be right.  The +3 is */
  388. X    /* superstitious but I want to be sure we don't get */
  389. X    /* get off on the counts.  There is little need */
  390. X    /* to optimize at the end of the file, we can forgo */
  391. X    /* that to be safe */
  392. X    if( (cp + 3 < fileSize(w->fileId)) && doRowCache ) {
  393. X        /* compute the number of rows down */
  394. X        w->rowCurLast = row;
  395. X        w->posCurLast = cp;
  396. X        w->lastPosTop = w->posTopline;
  397. X    } else
  398. X        w->lastPosTop = NULL;
  399. X#endif
  400. X
  401. X    n = col + w->indent;
  402. X    iLine = 0;
  403. X    if( w->lineNumbers )
  404. X        iLine = 5;
  405. X    while( iLine <= n ) {
  406. X        uch = getFileByte( fid, cp++ );
  407. X        switch( uch ) {
  408. X        case '\n':    /* end of line */
  409. X        case BLOCK_EOF:    /* end of file */
  410. X            /* NOTE: cp could get two past EOF since we post- */
  411. X            /* increment above and do not fix it below */
  412. X            goto endLoop;
  413. X        case '\t':
  414. X            tabStop = iLine + tabWidth - (iLine % tabWidth);
  415. X            if( tabStop > n )
  416. X                goto endLoop;
  417. X            else
  418. X                iLine = tabStop;
  419. X            break;
  420. X        default:
  421. X            iLine++;
  422. X            break;
  423. X        }
  424. X    }
  425. endLoop:
  426. X    return cp-1;
  427. X}
  428. X
  429. void
  430. OffsetToXY( w, offset, outRow, outCol )
  431. X    struct window *w;
  432. X    Offset offset;
  433. X    int *outRow, *outCol;
  434. X{
  435. X    extern int tabWidth;
  436. X    extern int getSpanSize;
  437. X
  438. X    Offset cp;
  439. X    int tabStop, row, lastRow, iLine;
  440. X    int fid = w->fileId;
  441. X        unsigned char *firstByte = (unsigned char *)1;
  442. X        unsigned char *lastByte = (unsigned char *)0;
  443. X
  444. X    /* see if offset is above the window */
  445. X    if( offset < w->posTopline )
  446. X        goto NotFound;
  447. X
  448. X    /* find out which row it is on */
  449. X    cp = w->posTopline;
  450. X    row = 0;
  451. X    iLine = 0;
  452. X    lastRow = w->nRows;
  453. X    while( row < lastRow ) {
  454. X        if( cp == offset ) {
  455. X            if( outRow != NULL )
  456. X                *outRow = row;
  457. X            if( outCol != NULL )
  458. X                *outCol = iLine - w->indent;
  459. X            return;
  460. X        }
  461. X                if( firstByte > lastByte ) {
  462. X                        if( getSpan( fid, cp, &firstByte, &lastByte, 0 ) )
  463. X                                break;
  464. X                }
  465. X                ++cp;
  466. X        switch( *firstByte++ ) {
  467. X        case '\n':
  468. X            iLine = 0;
  469. X            ++row;
  470. X            break;
  471. X        case '\t':
  472. X            tabStop = iLine + tabWidth - (iLine % tabWidth);
  473. X            iLine = tabStop;
  474. X            break;
  475. X        default:
  476. X            iLine++;
  477. X            break;
  478. X        }
  479. X++getSpanSize;
  480. X    }
  481. NotFound:
  482. X    if( outRow != NULL )
  483. X        *outRow = -1;
  484. X    if( outCol != NULL )
  485. X        *outCol = -1;
  486. X    return;
  487. X}
  488. X
  489. int
  490. OffsetToCol( w, offset, beginRowOffset )
  491. X    struct window *w;
  492. X    Offset offset, beginRowOffset;
  493. X{
  494. X    extern int tabWidth;
  495. X
  496. X    Offset cp;
  497. X    int tabStop, iLine;
  498. X    int uch;
  499. X    int fid = w->fileId;
  500. X
  501. X    iLine = 0;
  502. X    cp = beginRowOffset;
  503. X    while( cp < offset ) {
  504. X        uch = getFileByte( fid, cp++ );
  505. X        switch( uch ) {
  506. X        case BLOCK_EOF:    /* not found */
  507. X        case '\n':
  508. X            break;
  509. X        case '\t':
  510. X            tabStop = iLine + tabWidth - (iLine % tabWidth);
  511. X            iLine = tabStop;
  512. X            break;
  513. X        default:
  514. X            iLine++;
  515. X            break;
  516. X        }
  517. X    }
  518. X    return iLine;
  519. X}
  520. END_OF_FILE
  521. if test 4059 -ne `wc -c <'findpos.c'`; then
  522.     echo shar: \"'findpos.c'\" unpacked with wrong size!
  523. fi
  524. # end of 'findpos.c'
  525. fi
  526. if test -f 'goto.c' -a "${1}" != "-c" ; then 
  527.   echo shar: Will not clobber existing file \"'goto.c'\"
  528. else
  529. echo shar: Extracting \"'goto.c'\" \(4133 characters\)
  530. sed "s/^X//" >'goto.c' <<'END_OF_FILE'
  531. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/goto.c,v 1.5 1992/03/04 17:07:18 crowley Exp crowley $ */
  532. X
  533. X#include "pt.h"
  534. X
  535. void
  536. matchChar()
  537. X{
  538. X    extern struct window *selWindow;
  539. X    extern Offset selBegin, selEnd;
  540. X
  541. X    int uch;
  542. X    Offset cp;
  543. X    char ch1, ch2;
  544. X    int n, matchDirection;
  545. X    int fid = selWindow->fileId;
  546. X
  547. X    cp = selBegin;
  548. X    uch = getFileByte( fid, cp );
  549. X    switch( uch ) {
  550. X    case '(': ch1 = '('; ch2 = ')'; matchDirection =  1; break;
  551. X    case ')': ch1 = ')'; ch2 = '('; matchDirection = -1; break;
  552. X    case '[': ch1 = '['; ch2 = ']'; matchDirection =  1; break;
  553. X    case ']': ch1 = ']'; ch2 = '['; matchDirection = -1; break;
  554. X    case '{': ch1 = '{'; ch2 = '}'; matchDirection =  1; break;
  555. X    case '}': ch1 = '}'; ch2 = '{'; matchDirection = -1; break;
  556. X    default:  ch1 = ' '; ch2 = ' '; matchDirection = -1; break;
  557. X    }
  558. X    if( ch1 == ' ' ) {
  559. X        msg(
  560. X"Matching s defined for (, ), [, ], {, and } only", 1);
  561. X        return;
  562. X    }
  563. X    n = 1;    /* n==0 ==> we found the matching character */
  564. X    while( 1 ) {
  565. X        uch = getFileByte( fid, cp );
  566. X        cp += matchDirection;
  567. X        if( (char)uch == ch1 )
  568. X            ++n;
  569. X        else if( (char)uch == ch2 )
  570. X            --n;
  571. X        if( n == 0 || uch == BLOCK_EOF )
  572. X            break;
  573. X    }
  574. X    if( n == 0 ) {
  575. X        selBegin = cp;
  576. X        selEnd = selBegin;
  577. X        /* put the selection on the third line */
  578. X        if( selBegin >= selWindow->posBotline
  579. X         || selBegin < selWindow->posTopline ) {
  580. X            /* remember where we came from */
  581. X            selWindow->rowLastline = selWindow->numTopline;
  582. X            n = 4;
  583. X            cp = prevLine( fid, cp, &n );
  584. X            selWindow->posTopline = cp;
  585. X            /* recalculate the line number by letting */
  586. X            /* prevLine count as far back as it can */
  587. X            n = 3000000;
  588. X            cp = prevLine( fid, cp, &n );
  589. X            selWindow->numTopline = n + 1;
  590. X        }
  591. X        drawWindow(selWindow);
  592. X    } else
  593. X        msg("No matching character was found.", 1);
  594. X}
  595. X
  596. void
  597. doGoSel(w)
  598. X    struct window *w;
  599. X{
  600. X    extern struct window *selWindow;
  601. X    extern Offset selBegin, selEnd;
  602. X    extern int linesOverFind;
  603. X    extern int debug;
  604. X
  605. X    int n;
  606. X    int i;
  607. X    Offset cp, toCp;
  608. X    int fid = w->fileId;
  609. X
  610. X    /* remember where we came from */
  611. X    w->rowLastline = w->numTopline;
  612. X
  613. X    /* n is the number of lines to move */
  614. X    cp = selWindow->posTopline;
  615. X    i = linesOverFind;
  616. X
  617. X    /* find the number of lines in the window */
  618. X    i = selWindow->nRows;
  619. X    if( linesOverFind > i )
  620. X        /* if linesOverFind would place it outside the */
  621. X        /* window then put it in the middle of the window */
  622. X        i >>= 1;
  623. X    else
  624. X        /* otherwise put it linesOverFind lines down */
  625. X        i = linesOverFind;
  626. X    toCp = prevLine( fid, selBegin, &i );
  627. X    n = selWindow->numTopline;
  628. X    if( cp <= toCp ) {
  629. X        while( cp < toCp ) {
  630. X            i = 1;
  631. X            cp = nextLine( fid, cp, &i );
  632. X            ++n;
  633. X        }
  634. X    } else {    /* cp > toCp */
  635. X        while( cp > toCp ) {
  636. X            i = 1;
  637. X            cp = prevLine( fid, cp, &i );
  638. X            --n;
  639. X        }
  640. X    }
  641. X    selWindow->posTopline = toCp;
  642. X    selWindow->numTopline = n;
  643. X    (void)indentToShowSelection(-1);
  644. X    topWindow(selWindow);
  645. X    drawWindow(selWindow);
  646. X}
  647. X
  648. void
  649. doGoto(w, line_number_to_goto, adjustAndSelect)
  650. X    register struct window *w;
  651. X    int line_number_to_goto;
  652. X    int adjustAndSelect;
  653. X{
  654. X    extern char msgBuffer[];
  655. X    extern int linesOverFind;
  656. X    extern Offset selBegin, selEnd;
  657. X
  658. X    int n;
  659. X    int fid = w->fileId;
  660. X    int lof;
  661. X
  662. X    /* remember where we came from */
  663. X    w->rowLastline = w->numTopline;
  664. X
  665. X    /* n is the number of lines to move */
  666. X    n = line_number_to_goto - w->numTopline;
  667. X    if( n > 0 && n < w->nRows ) {
  668. X        /* the line is already showing on the screen */
  669. X        goto SelectOnly;
  670. X    }
  671. X    if( adjustAndSelect ) {
  672. X        lof = linesOverFind;
  673. X        if( lof >= w->nRows )
  674. X            lof = w->nRows / 2;
  675. X        n -= lof;
  676. X    }
  677. X    if( n > 0 ) {
  678. X        w->posTopline = nextLine( fid, w->posTopline, &n );
  679. X        w->numTopline += n;
  680. X        w->posBotline = nextLine( fid, w->posBotline, &n );
  681. X        w->numBotline += n;
  682. X    } else {    /* n < 0 */
  683. X        n = -n;
  684. X        /* prevLine will stop at line 1 no matter how big n is */
  685. X        /* (and return the number of lines actually moved) */
  686. X        w->posTopline = prevLine( fid, w->posTopline, &n );
  687. X        w->numTopline -= n;
  688. X        w->posBotline = prevLine( fid, w->posBotline, &n );
  689. X        w->numBotline -= n;
  690. X    }
  691. SelectOnly:
  692. X    if( adjustAndSelect ) {
  693. X        n = line_number_to_goto - w->numTopline;
  694. X        selBegin = nextLine( fid, w->posTopline, &n );
  695. X        n = 1;
  696. X        selEnd =  nextLine( fid, selBegin, &n ) - 1;
  697. X    }
  698. X    
  699. X    w->indent = 0;
  700. X    drawWindow(w);
  701. X}
  702. END_OF_FILE
  703. if test 4133 -ne `wc -c <'goto.c'`; then
  704.     echo shar: \"'goto.c'\" unpacked with wrong size!
  705. fi
  706. # end of 'goto.c'
  707. fi
  708. if test -f 'inschar.c' -a "${1}" != "-c" ; then 
  709.   echo shar: Will not clobber existing file \"'inschar.c'\"
  710. else
  711. echo shar: Extracting \"'inschar.c'\" \(5530 characters\)
  712. sed "s/^X//" >'inschar.c' <<'END_OF_FILE'
  713. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/inschar.c,v 1.5 1992/03/04 17:07:18 crowley Exp crowley $ */
  714. X
  715. X#include <ctype.h>
  716. X#include "pt.h"
  717. X
  718. void
  719. HandleKey( keysym, state )
  720. X    int keysym;
  721. X    int state;
  722. X{
  723. X    char ch;
  724. X
  725. X    if( keysym <= 127 ) {
  726. X        ch = (char)keysym;
  727. X        if( state & ControlMask )
  728. X            ch &= 0x1f;
  729. X    } else {
  730. X        keysym &= 0xff;
  731. X        /* ignore shift keys */
  732. X        if( 0xe1 <= keysym && keysym <= 0xee )
  733. X            return;
  734. X        ch = (char)keysym;
  735. X    }
  736. X    if( ch == '\r' )
  737. X        /* convert CRs to NLs */
  738. X        ch = '\n';
  739. X    else if( ch == '\377' )
  740. X        /* convert DELs to BSs */
  741. X        ch = '\b';
  742. X    if( (ch == '\b') && (state & (ShiftMask|ControlMask|Mod1Mask)) )
  743. X        ch = '\177';    /* word erase */
  744. X    insChar( ch, 1 );
  745. X}
  746. X
  747. void
  748. insChar( c2, update )
  749. X    int c2;
  750. X    int update;
  751. X{
  752. X    extern char msgBuffer[];
  753. X    extern char textBuffer[];
  754. X    extern struct window *selWindow;
  755. X    extern Offset selBegin, selEnd;
  756. X    extern int selMode;
  757. X    extern struct window *windowList;
  758. X    extern int overType;
  759. X    extern int autoIndent;
  760. X    extern int rightMargin;
  761. X    extern int unixMode;
  762. X    extern int insertReplaces;
  763. X    extern int debug;
  764. X
  765. X    Offset cp;
  766. X    Offset saveSelBegin, saveSelEnd;
  767. X    int insrow1;
  768. X    int n, row, col;
  769. X    char ch;
  770. X    int fid = selWindow->fileId;
  771. X    unsigned char c = (unsigned char)c2;
  772. X    
  773. X    /* erase the old selection */
  774. X    drawSelection( 1 );
  775. X
  776. X    /* selection mode is character after an insert */
  777. X    selMode = SELCHAR;
  778. X
  779. X    if( c == '\177') {    /* erase word */
  780. X        cp = selBegin;
  781. X        /* first scan back over white space */
  782. X        while( 1 ) {
  783. X            ch = (char)getFileByte( fid, --cp );
  784. X            switch( ch ) {
  785. X            case ' ':
  786. X            case '\t':
  787. X            case '\r':
  788. X            case '\n':
  789. X                break;
  790. X            default:
  791. X                goto endWhite;    /* break out of while loop */
  792. X            }
  793. X        }
  794. X    endWhite:
  795. X        /* now scan over alphanumerics */
  796. X        if( isalnum(ch) ) {
  797. X            while( isalnum(ch) ) {
  798. X                if( cp < 0 )
  799. X                    break;
  800. X                ch = (char)getFileByte( fid, --cp );
  801. X            }
  802. X        } else {
  803. X            while( !isalnum(ch) && !isspace(ch) && !iscntrl(ch) ) {
  804. X                if( cp < 0 )
  805. X                    break;
  806. X                ch = (char)getFileByte( fid, --cp );
  807. X            }
  808. X        }
  809. X        /* set up the selection to delete the chars passed over */
  810. X        selEnd = selBegin - 1;
  811. X        selBegin = cp + 1;
  812. X        if( selBegin <= selEnd ) {
  813. X            if( deleteChars(selWindow->fileId, NOUPDATE, 0) )
  814. X                c = '\n'; /* if so, force a drawWindow */
  815. X        } else
  816. X            selEnd = selBegin;
  817. X    } else if( c == '\b') {
  818. X        if( selBegin > 0 ) {
  819. X            if( (char)getFileByte(fid,selBegin) == '\n'
  820. X                            || !delChar() ) {
  821. X                selEnd = --selBegin;
  822. X                /* deleted a newline? */
  823. X                if( deleteChars(selWindow->fileId,NOUPDATE,0) )
  824. X                    /* if so, force a drawWindow */
  825. X                    c = '\n';
  826. X            }
  827. X        }
  828. X    } else {
  829. X        if( insertReplaces && selBegin < selEnd )
  830. X            deleteChars( fid, update, 1 );
  831. X        insertChar((unsigned char)c);
  832. X        if( rightMargin < 999 && c != '\n' ) {
  833. X            OffsetToXY( selWindow, selBegin, &row, &col );
  834. X            if( col > (rightMargin-selWindow->indent+1)) {
  835. X                saveSelBegin = selBegin;
  836. X                saveSelEnd = selEnd;
  837. X                while( 1 ) {
  838. X                    ch = (char)getFileByte(fid, --selBegin);
  839. X                    if( ch == ' ' || ch == '\t'
  840. X                     || ch=='\n' || selBegin <= 0 )
  841. X                        break;
  842. X                }
  843. X                if( ch == ' ' ) {
  844. X                    selEnd = selBegin;
  845. X                    deleteChars( fid, 0, 0 );
  846. X                    n = 0;
  847. X                } else {
  848. X                    selBegin = saveSelBegin - 1;
  849. X                    n = 1;
  850. X                }
  851. X                /* no need to set selEnd since */
  852. X                /* insertChar does not use it */
  853. X                insertChar('\n');
  854. X                if( autoIndent )
  855. X                    n += doAutoIndent();
  856. X                updateFile(selWindow->fileId,selBegin-1,1,0);
  857. X                selBegin = saveSelBegin + n;
  858. X                selEnd = saveSelEnd + n;
  859. X            }
  860. X        }
  861. X        if( c == '\n' && autoIndent ) {
  862. X            (void)doAutoIndent();
  863. X        }
  864. X        if( overType ) {
  865. X            selEnd = selBegin;
  866. X            ch = (char)getFileByte( fid, selBegin );
  867. X            if( ch != '\n' )
  868. X                (void)deleteChars(selWindow->fileId,NOUPDATE,0);
  869. X        }
  870. X    }
  871. X    if( !update )
  872. X        return;
  873. X    if( c == '\n' ) {
  874. X#ifdef XXXXXXX
  875. X/* I'm not sure now why this was put in, so I'll take it out */
  876. X        /* back up one character (to the one before the '\n') */
  877. X        --selBegin;
  878. X#endif
  879. X        OffsetToXY( selWindow, selBegin, &insrow1, NULL );
  880. X        /* auto-scroll at the bottom of a page */
  881. X        if( insrow1+1 >= selWindow->nRows ) {
  882. X            n = (selWindow->nRows)/3;
  883. X            selWindow->posTopline = nextLine( fid,
  884. X                selWindow->posTopline, &n);
  885. X            selWindow->numTopline += n;
  886. X        }
  887. X#ifdef XXXXXX
  888. X        /* this is to fix the problem of the very first line of */
  889. X        /* a new file not updating correctly */
  890. X        if( selWindow->posBotline <= 0 )
  891. X            selWindow->posBotline = selBegin;
  892. X#endif
  893. X        n = indentToShowSelection(-1);
  894. X        /* find the '\n' that was inserted */
  895. X        cp = selBegin;
  896. X        while( (char)getFileByte( fid, --cp ) != '\n' )
  897. X            /*EMPTY*/
  898. X            ;
  899. X        updateFile( selWindow->fileId, cp, selBegin-cp, 0 );
  900. X        if( n ) {
  901. X            drawWindow(selWindow);
  902. X            return;
  903. X        }
  904. X    } else {
  905. X        int n, y, row, col;
  906. X        Offset cp;
  907. X
  908. X        if( selBegin < selWindow->posTopline )
  909. X            doGoSel(selWindow);
  910. X
  911. X        /* if we have to indent, then redraw the screen */
  912. X        if( indentToShowSelection(-1) ) {
  913. X            drawWindow(selWindow);
  914. X            return;
  915. X        }
  916. X        OffsetToXY( selWindow, selBegin, &row, &col );
  917. X        y = selWindow->topMargin + (selWindow->font).ascent
  918. X                + row*((selWindow->font).height);
  919. X        n = -1;
  920. X        cp = prevLine( selWindow->fileId, selBegin, &n );
  921. X        fillLine(selWindow, cp, row, col, selWindow->nCols, y, 1 );
  922. X    }
  923. X}
  924. X
  925. X
  926. int
  927. doAutoIndent()
  928. X{
  929. X    extern char msgBuffer[];
  930. X    extern Offset selBegin;
  931. X    extern struct window *selWindow;
  932. X
  933. X    unsigned char uch;
  934. X    Offset cp;
  935. X    int n, charsInserted;
  936. X    int fid = selWindow->fileId;
  937. X
  938. X    n = -1;
  939. X    cp = prevLine( fid, selBegin - 1, &n );
  940. X    charsInserted = 0;
  941. X    while( 1 ) {
  942. X        uch = getFileByte( fid, cp++ );
  943. X        switch( uch ) {
  944. X            case ' ':
  945. X            case '\t':
  946. X                insertChar( uch );
  947. X                ++charsInserted;
  948. X                break;
  949. X            default:
  950. X                return charsInserted;
  951. X        }
  952. X    }
  953. X}
  954. END_OF_FILE
  955. if test 5530 -ne `wc -c <'inschar.c'`; then
  956.     echo shar: \"'inschar.c'\" unpacked with wrong size!
  957. fi
  958. # end of 'inschar.c'
  959. fi
  960. if test -f 'library.c' -a "${1}" != "-c" ; then 
  961.   echo shar: Will not clobber existing file \"'library.c'\"
  962. else
  963. echo shar: Extracting \"'library.c'\" \(3751 characters\)
  964. sed "s/^X//" >'library.c' <<'END_OF_FILE'
  965. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/library.c,v 1.10 1992/03/04 17:07:18 crowley Exp crowley $ */
  966. X
  967. X#include "pt.h"
  968. X#include "ctype.h"
  969. X#include "string.h"
  970. X#include "stdlib.h"
  971. X
  972. char scratchName[FILENAMESIZE];
  973. X
  974. int
  975. LineNumberOfSelection()
  976. X{
  977. X    extern struct window *selWindow;
  978. X    extern Offset selBegin, selEnd;
  979. X
  980. X    int cp = 0;
  981. X    int n;
  982. X    int line_number = 1;
  983. X    int fid = selWindow->fileId;
  984. X    
  985. X    while( cp < selBegin ) {
  986. X        n = 1;
  987. X        cp = nextLine( fid, cp, &n );
  988. X        ++line_number;
  989. X    }
  990. X    if( cp > selBegin )
  991. X        --line_number;
  992. X    return line_number;
  993. X}
  994. X
  995. void
  996. XFixName( s )
  997. X    char *s;
  998. X{
  999. X    int l = strlen(s) - 1;
  1000. X    char ch = s[l];
  1001. X    if( ch=='@' || ch=='*' || ch=='=' )
  1002. X        s[l] = '\0';
  1003. X}
  1004. X
  1005. char *
  1006. tildefyFilename( buffer )
  1007. X    char * buffer;
  1008. X{
  1009. X    extern char homeDirectory[];
  1010. X
  1011. X    int home_dir_len = strlen(homeDirectory);
  1012. X    char *p;
  1013. X
  1014. X    if( strncmp(buffer, homeDirectory, home_dir_len)==0 ) {
  1015. X        p = &(buffer[home_dir_len-1]);
  1016. X        *p = '~';
  1017. X    } else
  1018. X        p = buffer;
  1019. X    return p;
  1020. X}
  1021. X
  1022. char *
  1023. findFile(name)
  1024. X    char *name;
  1025. X{
  1026. X    extern char scratchName[];
  1027. X    extern char *getenv();
  1028. X    
  1029. X    char *env;
  1030. X    int i;
  1031. X
  1032. X    /* first look in the current directory */
  1033. X    if( access(name, 0) == 0 )
  1034. X        return name;
  1035. X    /* now look in the path or PATH directories */
  1036. X    env = getenv("path");
  1037. X    if( env == NULL ) {
  1038. X        env = getenv("PATH");
  1039. X        if( env == NULL )
  1040. X            return NULL;
  1041. X    }
  1042. X    while( *env != '\0' ) {
  1043. X        /* find the next directory name */
  1044. X        i = 0;
  1045. X        while( *env != ';' && *env != '\0' )
  1046. X            scratchName[i++] = *env++;
  1047. X        if( scratchName[i-1] != '/' )
  1048. X            scratchName[i++] = '/';
  1049. X        scratchName[i] = '\0';
  1050. X        strcat(scratchName, name);
  1051. X        if( access(scratchName, 0) == 0 )
  1052. X            return &scratchName[0];
  1053. X        if( *env != '\0' )
  1054. X            ++env;
  1055. X    }
  1056. X    return NULL;
  1057. X}
  1058. X
  1059. X/*ARGSUSED*/
  1060. char *
  1061. PtMalloc( size, purpose )
  1062. X    int size;
  1063. X    char *purpose;
  1064. X{
  1065. X    extern int debug;
  1066. X
  1067. X    char *mem = (char *)malloc( size );
  1068. X
  1069. X    return mem;
  1070. X}
  1071. X
  1072. void
  1073. PtFree( s )
  1074. X    char *s;
  1075. X{
  1076. X    extern int debug;
  1077. X
  1078. X    if( s != NULL )
  1079. X        free( s );
  1080. X}
  1081. X
  1082. void
  1083. justifyLines()
  1084. X{
  1085. X    /* external declarations */
  1086. X    extern struct window *selWindow;
  1087. X    extern Offset selBegin, selEnd;
  1088. X    extern int selMode;
  1089. X    extern int rightMargin;
  1090. X    extern int tabWidth;
  1091. X    extern int debug;
  1092. X
  1093. X    Offset cp, selFirst = selBegin, selLast = selEnd;
  1094. X    int fileId, n, col;
  1095. X    char ch, lastCh;
  1096. X    int fid = selWindow->fileId;
  1097. X
  1098. X    selMode = SELCHAR;
  1099. X    fileId = selWindow->fileId;
  1100. X    n = -1;
  1101. X    selBegin = prevLine( fileId, selBegin, &n );
  1102. X    n = 1;
  1103. X    selEnd = nextLine( fileId, selEnd, &n );
  1104. X    col = 0;
  1105. X    lastCh = 0;
  1106. X    while( 1 ) {
  1107. X        ch = getFileByte( fid, selBegin );
  1108. X        if( ch == '\n' ) {
  1109. X            /* replace the LF with a space */
  1110. X            selEnd = selBegin;
  1111. X            (void)deleteChars( fileId, 0, 0 );
  1112. X            insertChar(' ');
  1113. X            ch = ' ';
  1114. X        }
  1115. X        if( col >= rightMargin ) {
  1116. X            cp = selBegin;
  1117. X            while( ch != ' ' && ch != '\n' && ch != '\t' )
  1118. X                ch = (char)getFileByte(fileId, --cp);
  1119. X            if( ch == ' ' || ch == '\t' ) {
  1120. X                selEnd = selBegin = cp;
  1121. X                (void)deleteChars(fileId, 0, 0);
  1122. X                insertChar('\n');
  1123. X            }
  1124. X            /* else NL is already in place */
  1125. X            col = 0;
  1126. X            lastCh = '\n';
  1127. X        } else {
  1128. X            if( ch == '\t' ) {
  1129. X                if( (n = (col % tabWidth)) == 0 )
  1130. X                    n = tabWidth;
  1131. X                col += n;
  1132. X            } else
  1133. X                ++col;
  1134. X            ++selBegin;
  1135. X            lastCh = ch;
  1136. X        }
  1137. X        if( selBegin >= selLast )
  1138. X            break;
  1139. X    }
  1140. X    /* see how many spaces and tabs are at the end */
  1141. X    /* selEnd remembers the end of the string of spaces and tabs */
  1142. X    selEnd = --selBegin;
  1143. X    /* loop through the spaces and tabs */
  1144. X    while( 1 ) {
  1145. X        ch = getFileByte( fid, selBegin++ );
  1146. X        if( ch != ' ' && ch != '\t' )
  1147. X            break;
  1148. X        --selBegin;
  1149. X    }
  1150. X    /* (selBegin went one too) */
  1151. X    /* if we found some spaces, then delete them */
  1152. X    if( ++selBegin <= selEnd ) {
  1153. X        selLast -= (selEnd - selBegin + 1);
  1154. X        (void)deleteChars(fileId, 0, 0);
  1155. X    }
  1156. X    if( lastCh != '\n' ) {
  1157. X        insertChar('\n');
  1158. X        selLast += 2;
  1159. X    }
  1160. X    selBegin = selFirst;
  1161. X    selEnd = selLast - 1;
  1162. X    drawWindow( selWindow );
  1163. X}
  1164. X
  1165. END_OF_FILE
  1166. if test 3751 -ne `wc -c <'library.c'`; then
  1167.     echo shar: \"'library.c'\" unpacked with wrong size!
  1168. fi
  1169. # end of 'library.c'
  1170. fi
  1171. if test -f 'repaint.c' -a "${1}" != "-c" ; then 
  1172.   echo shar: Will not clobber existing file \"'repaint.c'\"
  1173. else
  1174. echo shar: Extracting \"'repaint.c'\" \(4471 characters\)
  1175. sed "s/^X//" >'repaint.c' <<'END_OF_FILE'
  1176. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/repaint.c,v 1.9 1992/03/04 17:07:18 crowley Exp crowley $ */
  1177. X
  1178. X#include <ctype.h>
  1179. X#include <string.h>
  1180. X#include <stdio.h>
  1181. X#include "pt.h"
  1182. X#include <X11/StringDefs.h>
  1183. X
  1184. void
  1185. SetTextColor( w, normal, foreground, colorName )
  1186. X    struct window *w;
  1187. X    int normal, foreground;
  1188. X    char * colorName;
  1189. X{
  1190. X    extern Display *MainDisplay;
  1191. X    extern Tcl_Interp * interp;
  1192. X    extern char msgBuffer[];
  1193. X
  1194. X    struct fontDataStruct *fontData = &(w->font);
  1195. X    Tk_Uid s = Tk_GetUid( colorName );
  1196. X    XColor * color = Tk_GetColor( interp, w->tk_toplevel, NULL, s );
  1197. X
  1198. X    if( color == NULL )
  1199. X        return;
  1200. X    if( normal && foreground ) {
  1201. X        XSetForeground( MainDisplay, fontData->gc_normal,
  1202. X                            color->pixel );
  1203. X    } else if( normal && !foreground ) {
  1204. X        XSetBackground( MainDisplay, fontData->gc_normal,
  1205. X                            color->pixel);
  1206. X        Tk_SetWindowBackground( w->tk_text, color->pixel );
  1207. X    } else if( !normal && foreground ) {
  1208. X        XSetForeground( MainDisplay, fontData->gc_selected,
  1209. X                            color->pixel);
  1210. X    } else {
  1211. X        XSetBackground( MainDisplay, fontData->gc_selected,
  1212. X                            color->pixel);
  1213. X    }
  1214. X}
  1215. X
  1216. void InitRedisplay( w )
  1217. X    struct window *w;
  1218. X{
  1219. X    extern Display *MainDisplay;
  1220. X    extern int debug;
  1221. X    extern char * textBackground;
  1222. X    extern char * textForeground;
  1223. X    extern char * selectedTextBackground;
  1224. X    extern char * selectedTextForeground;
  1225. X    extern Tcl_Interp * interp;
  1226. X    extern char msgBuffer[];
  1227. X
  1228. X    XFontStruct *fontInfo;
  1229. X    struct fontDataStruct *fontData = &(w->font);
  1230. X
  1231. X    if( w->x_window_id == NULL ) {
  1232. X        sprintf( msgBuffer, "%s.VScrollAndText.Text", w->tk_pathname );
  1233. X        w->tk_text = Tk_NameToWindow(interp, msgBuffer, w->tk_toplevel);
  1234. X        w->x_window_id = Tk_WindowId( w->tk_text );
  1235. X    }
  1236. X
  1237. X    if( fontData->height == 0 && w->x_window_id != NULL ) {
  1238. X    retry_font:
  1239. X        fontInfo = Tk_GetFontStruct( interp, w->tk_toplevel,
  1240. X                            fontData->name );
  1241. X        if( fontInfo == NULL ) {
  1242. X            printf("Cannot load font %s, using fixed\n",
  1243. X                fontData->name );
  1244. X            fontData->name = "fixed";
  1245. X            goto retry_font;
  1246. X        }
  1247. X        fontData->font = fontInfo->fid;
  1248. X        fontData->height = fontInfo->ascent + fontInfo->descent;
  1249. X        fontData->width = fontInfo->max_bounds.width;
  1250. X        fontData->ascent = fontInfo->ascent;
  1251. X
  1252. X        /* set up the gc for normal text */
  1253. X        XSetFont(MainDisplay, fontData->gc_normal, fontData->font);
  1254. X
  1255. X        /* set up the gc for selected text */
  1256. X        XSetFont(MainDisplay, fontData->gc_selected, fontData->font);
  1257. X        SetTextColor( w, 1, 1, textForeground );
  1258. X        SetTextColor( w, 1, 0, textBackground );
  1259. X        SetTextColor( w, 0, 1, selectedTextForeground );
  1260. X        SetTextColor( w, 0, 0, selectedTextBackground );
  1261. X        Tk_FreeFontStruct( fontInfo );
  1262. X    }
  1263. X}
  1264. X
  1265. void
  1266. WorkspaceResized( w )
  1267. X    struct window * w;
  1268. X{
  1269. X    extern Display *MainDisplay;
  1270. X    extern int debug;
  1271. X    extern int showPartialLines;
  1272. X    extern Tcl_Interp * interp;
  1273. X
  1274. X    int font_height, font_width;
  1275. X    int high, wide;
  1276. X
  1277. X    InitRedisplay( w );
  1278. X    wide = Tk_Width( w->tk_text );
  1279. X    high = Tk_Height( w->tk_text );
  1280. X
  1281. X    /* These calculations do not allow partially hidden rows and columns */
  1282. X    if( (font_height = (w->font).height) == 0 )
  1283. X        font_height = 15;
  1284. X    w->nRows = (high - w->topMargin) / font_height;
  1285. X    if( (font_width = (w->font).width) == 0 )
  1286. X        font_width = 8;
  1287. X    w->nCols = (wide - w->leftMargin) / font_width;
  1288. X    if( showPartialLines ) {
  1289. X        w->nRows = (high - w->topMargin + font_height - 1)
  1290. X                        / font_height;
  1291. X        w->nCols = (wide - w->leftMargin + font_width - 1)
  1292. X                        / font_width;
  1293. X    }
  1294. X#ifdef FIX_DISPLAY_LATER
  1295. X    /* reallocate the screen image and set to nuls */
  1296. X    PtFree( w->screen_image );
  1297. X    high = w->nRows * w->nCols;
  1298. X    w->screen_image = (char *)PtMalloc( high, "screen image" );
  1299. X    memset( w->screen_image, '\0', high );
  1300. X#endif
  1301. X}
  1302. X
  1303. void
  1304. repaint( w, left, top, right, bottom )
  1305. X    struct window * w;
  1306. X    int left;
  1307. X    int top;
  1308. X    int right;
  1309. X    int bottom;
  1310. X{
  1311. X    int firstRow, lastRow;
  1312. X    int firstCol, lastCol;
  1313. X
  1314. X    InitRedisplay( w );
  1315. X    if( w->nRows == 0 )
  1316. X        WorkspaceResized( w );
  1317. X
  1318. X    /* this is necessary when the whole window is exposed */
  1319. X    if( top < w->topMargin )
  1320. X        top = w->topMargin;
  1321. X    if( bottom < w->topMargin )
  1322. X        bottom = w->topMargin;
  1323. X    if( left < w->leftMargin )
  1324. X        left = w->leftMargin;
  1325. X    if( right < w->topMargin )
  1326. X        right = w->leftMargin;
  1327. X    firstRow =    (top - w->topMargin) / (w->font).height;
  1328. X    lastRow  = (bottom - w->topMargin) / (w->font).height;
  1329. X    /* never write a partial line at the bottom of the screen */
  1330. X    if( lastRow >= w->nRows )
  1331. X        lastRow = w->nRows - 1;
  1332. X    firstCol =  (left - w->leftMargin) / (w->font).width;
  1333. X    lastCol  = (right - w->leftMargin) / (w->font).width;
  1334. X    drawWindowFast( w, firstRow, lastRow, firstCol, lastCol );
  1335. X}
  1336. X
  1337. END_OF_FILE
  1338. if test 4471 -ne `wc -c <'repaint.c'`; then
  1339.     echo shar: \"'repaint.c'\" unpacked with wrong size!
  1340. fi
  1341. # end of 'repaint.c'
  1342. fi
  1343. if test -f 'replace.c' -a "${1}" != "-c" ; then 
  1344.   echo shar: Will not clobber existing file \"'replace.c'\"
  1345. else
  1346. echo shar: Extracting \"'replace.c'\" \(3845 characters\)
  1347. sed "s/^X//" >'replace.c' <<'END_OF_FILE'
  1348. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/replace.c,v 1.5 1992/03/04 17:07:18 crowley Exp crowley $ */
  1349. X
  1350. X#include <ctype.h>
  1351. X#include <stdio.h>
  1352. X#include "pt.h"
  1353. X
  1354. void
  1355. replaceText( w, fromString, toString, inSelection )
  1356. X    struct window *w;
  1357. X    char * fromString;
  1358. X    char * toString;
  1359. X    int inSelection;
  1360. X{
  1361. X    extern struct window *selWindow;
  1362. X    extern Offset selBegin, selEnd;
  1363. X    extern int selMode;
  1364. X    extern char msgBuffer[];
  1365. X    extern Offset addPosition;
  1366. X    extern int addHandle;
  1367. X    extern int debug;
  1368. X    extern struct openFile *files;
  1369. X
  1370. X    struct window *saveSelWindow;
  1371. X    Offset saveSelBegin, saveSelEnd, repEnd;
  1372. X    int n, fileId, fromLength;
  1373. X    int nLines, nReplaces;
  1374. X    int diffLengths;
  1375. X    Offset toLength, fSize;
  1376. X    Offset cp;
  1377. X    Piece tempPP, newPP;
  1378. X    struct changeItem *thisChange;
  1379. X    struct openFile *ff;
  1380. X
  1381. X    fileId = w->fileId;
  1382. X    ff = &files[fileId];
  1383. X    fSize = fileSize(fileId);
  1384. X    nReplaces = 0;
  1385. X    
  1386. X    /* check if this is a readOnly file */
  1387. X    if( ff->flags & READ_ONLY ) {
  1388. X        sprintf(msgBuffer, "File %s is read only", ff->origName);
  1389. X        msg(msgBuffer, 1);
  1390. X        return;
  1391. X    }
  1392. X
  1393. X    /* Create a piece for the replacement string and record it in */
  1394. X    /* the piece buffer.  This makes it easy to insert the replace */
  1395. X    /* string by copying this piece */
  1396. X    toLength = strlen(toString);
  1397. X    tempPP = getFreePiece();
  1398. X
  1399. X    tempPP->file = addHandle;
  1400. X    tempPP->position = addPosition;
  1401. X    for(n = 0; n < (int)toLength; n++ )
  1402. X        writeChar(toString[n], addPosition++);
  1403. X    tempPP->length = toLength;
  1404. X
  1405. X    if( inSelection )
  1406. X        repEnd = selEnd;
  1407. X    else
  1408. X        repEnd = fileSize(w->fileId);
  1409. X
  1410. X    if( w == selWindow )
  1411. X        cp = selBegin + 1;
  1412. X    else
  1413. X        cp = 0;
  1414. X    
  1415. X    /* How will the replace change character counts? */
  1416. X    /* we need to adjust repEnd after each replace */
  1417. X    fromLength = strlen(fromString);
  1418. X    diffLengths = strlen(toString) - fromLength;
  1419. X
  1420. X    /* set things up so the line counts will be right */
  1421. X    if( (char)getFileByte(fileId, cp) == '\n' )
  1422. X        nLines = 1;
  1423. X    else
  1424. X        nLines = 0;
  1425. X
  1426. X    /* save the location of the current selection */
  1427. X    saveSelWindow = selWindow;
  1428. X    saveSelBegin = selBegin;
  1429. X    saveSelEnd = selEnd;
  1430. X
  1431. X/* while loop to repeat the replace */
  1432. while( 1 ) {
  1433. X
  1434. X    sprintf(msgBuffer, "Replace is %d%% completed",
  1435. X        (int)( (100*cp) / (fSize + nReplaces*(toLength-fromLength)) )
  1436. X        );
  1437. X    msg(msgBuffer, 1);
  1438. X
  1439. X    /* find the string */
  1440. X    cp = searchSpans(fileId, cp, repEnd, fromString, fromLength, &n);
  1441. X    nLines += n;
  1442. X    if( cp == -1 )
  1443. X        break;
  1444. X    if( selWindow != w ) {
  1445. X        drawSelection( 1 );
  1446. X        selWindow = w;
  1447. X    }
  1448. X    selBegin = cp;
  1449. X    selEnd = selBegin + fromLength - 1;
  1450. X    selMode = SELCHAR;
  1451. X
  1452. X    /* remember where we came from */
  1453. X    selWindow->rowLastline = selWindow->numTopline;
  1454. X    
  1455. X    (void)deleteChars(selWindow->fileId, NOUPDATE, 0);
  1456. X        
  1457. X    /* record in the change history */
  1458. X    thisChange = GetNewChange( ff );
  1459. X    thisChange->type = CINSERT;
  1460. X    thisChange->position = selBegin;
  1461. X    thisChange->length = toLength;
  1462. X    thisChange->flags = 0;
  1463. X    thisChange->lineNumber = selWindow->numTopline;
  1464. X    thisChange->fileId = selWindow->fileId;
  1465. X    thisChange->w = selWindow;
  1466. X    newPP = getFreePiece();
  1467. X    newPP->file = addHandle;
  1468. X    newPP->position = tempPP->position;
  1469. X    newPP->length = toLength;
  1470. X    thisChange->firstPiece = newPP;
  1471. X    RecordChange( ff, thisChange );
  1472. X    
  1473. X    copyPieces( tempPP, selWindow, selBegin, toLength, 0, 0 );
  1474. X    cp = selBegin;
  1475. X    /* as we change the length of the text in the file with */
  1476. X    /* a replacement, we have to adjust repEnd so that we  */
  1477. X    /* will not quit early */
  1478. X    repEnd += diffLengths;
  1479. X
  1480. X    /* we want the final */
  1481. X    /* selection to be the same as the original */
  1482. X    /* selection even though we are replaceing */
  1483. X    /* inside it.  This makes the adjustment */
  1484. X    saveSelEnd += diffLengths;
  1485. X
  1486. X    ++nReplaces;
  1487. X}
  1488. X
  1489. X    /* free the temp piece */
  1490. X    freePieces(tempPP);
  1491. X
  1492. X    /* restore the previous selection */
  1493. X    selWindow = saveSelWindow;
  1494. X    selBegin = saveSelBegin;
  1495. X    selEnd = saveSelEnd;
  1496. X    drawWindow(selWindow);
  1497. X
  1498. X    sprintf(msgBuffer, "Made %d replacement%s", nReplaces,
  1499. X        nReplaces==1?"":"s");
  1500. X    msg(msgBuffer, 1);
  1501. X}
  1502. END_OF_FILE
  1503. if test 3845 -ne `wc -c <'replace.c'`; then
  1504.     echo shar: \"'replace.c'\" unpacked with wrong size!
  1505. fi
  1506. # end of 'replace.c'
  1507. fi
  1508. if test -f 'stats.c' -a "${1}" != "-c" ; then 
  1509.   echo shar: Will not clobber existing file \"'stats.c'\"
  1510. else
  1511. echo shar: Extracting \"'stats.c'\" \(3635 characters\)
  1512. sed "s/^X//" >'stats.c' <<'END_OF_FILE'
  1513. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/stats.c,v 1.2 1992/03/04 17:07:18 crowley Exp crowley $ */
  1514. X#include <stdio.h>
  1515. X/* stuff for edit tracing */
  1516. int trace_file = 0;    /* 0 ==> no tracing */
  1517. X
  1518. X/* some performance measuring counters */
  1519. int piecesRequested;
  1520. int piecesAllocated;
  1521. int getSpanSize;
  1522. int piecesFreed;
  1523. int piecesSearchedFor;
  1524. int piecesScanned;
  1525. int scanned0pieces;
  1526. int scanned1pieces;
  1527. int scanned2pieces;
  1528. int scanned3PlusPieces;
  1529. int hashChainBuffersScanned;
  1530. int buffersRequested;
  1531. int buffersNotFound;
  1532. int buffersInUse;
  1533. int buffersWritten;
  1534. int fileBytesRequested;
  1535. int getSpansRequested;
  1536. int spansOutOfRange;
  1537. int spansInBufferCache;
  1538. int spansInPieceCache;
  1539. int cacheBufferSizes;
  1540. int charsWritten;
  1541. X
  1542. void
  1543. PrintStats( fileId )
  1544. X    int fileId;
  1545. X{
  1546. X    extern char msgBuffer[];
  1547. X    
  1548. X    sprintf(msgBuffer,"***** Point caching statistics *****\n");
  1549. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1550. X    sprintf(msgBuffer,"%8d characters accessed\n", getSpansRequested);
  1551. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1552. X    sprintf(msgBuffer,"     %8d (%5.1f%%) through getFileByte\n", fileBytesRequested,
  1553. X                100.0 * (float)fileBytesRequested
  1554. X                    / getSpansRequested);
  1555. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1556. X    sprintf(msgBuffer,"     %8d (%5.1f%%) through getSpan\n",
  1557. X                getSpansRequested - fileBytesRequested,
  1558. X                100.0 * (getSpansRequested-fileBytesRequested)
  1559. X                    / getSpansRequested);
  1560. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1561. X    sprintf(msgBuffer,"%8d calls to getSpan\n", getSpansRequested);
  1562. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1563. X    sprintf(msgBuffer,"     %8.1f%% of getSpans found in buffer cache\n",
  1564. X                100.0 * (float)spansInBufferCache
  1565. X                    / getSpansRequested );
  1566. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1567. X    sprintf(msgBuffer,"     %8.1f%% of getSpans found in piece cache\n",
  1568. X                100.0 * (float)spansInPieceCache
  1569. X                    / getSpansRequested );
  1570. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1571. X    sprintf(msgBuffer,"     %8.1f bytes provided per span\n",
  1572. X                (float)cacheBufferSizes / getSpansRequested );
  1573. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1574. X    sprintf(msgBuffer,"     %8.1f bytes USED per span\n",
  1575. X                (float)getSpanSize / getSpansRequested );
  1576. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1577. X    sprintf(msgBuffer,"%8d piece table searches\n", piecesSearchedFor);
  1578. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1579. X    sprintf(msgBuffer,"     %8.1f scans per piece search\n",
  1580. X                (float)piecesScanned / piecesSearchedFor );
  1581. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1582. X    sprintf(msgBuffer,"     %8d times 0 pieces scanned\n", scanned0pieces);
  1583. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1584. X    sprintf(msgBuffer,"     %8d times 1 pieces scanned\n", scanned1pieces);
  1585. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1586. X    sprintf(msgBuffer,"     %8d times 2 pieces scanned\n", scanned2pieces);
  1587. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1588. X    sprintf(msgBuffer,"     %8d times 3 or more pieces scanned\n", scanned3PlusPieces);
  1589. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1590. X    sprintf(msgBuffer,"%8d buffers requested\n", buffersRequested);
  1591. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1592. X    sprintf(msgBuffer,"     %8.1f%% of buffers found in the cache\n", 
  1593. X                100.0 * (float)(buffersRequested
  1594. X                    - buffersNotFound) / buffersRequested );
  1595. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1596. X    sprintf(msgBuffer,"     %8.1f buffers searched in an average hash chain lookup\n",
  1597. X                (float)hashChainBuffersScanned
  1598. X                            / buffersRequested );
  1599. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1600. X    sprintf(msgBuffer,"     %8d buffers had to be written out to disk\n",
  1601. X                buffersWritten);
  1602. X    write( fileId, msgBuffer, strlen(msgBuffer) );
  1603. X}
  1604. END_OF_FILE
  1605. if test 3635 -ne `wc -c <'stats.c'`; then
  1606.     echo shar: \"'stats.c'\" unpacked with wrong size!
  1607. fi
  1608. # end of 'stats.c'
  1609. fi
  1610. if test -f 'tclLib/init.tcl' -a "${1}" != "-c" ; then 
  1611.   echo shar: Will not clobber existing file \"'tclLib/init.tcl'\"
  1612. else
  1613. echo shar: Extracting \"'tclLib/init.tcl'\" \(3992 characters\)
  1614. sed "s/^X//" >'tclLib/init.tcl' <<'END_OF_FILE'
  1615. X# init.tcl --
  1616. X#
  1617. X# Default system startup file for Tcl-based applications.  Defines
  1618. X# "unknown" procedure and auto-load facilities.
  1619. X#
  1620. X# $Header: /nfs/unmvax/faculty/crowley/x/pt/tclLib/init.tcl,v 1.1 1992/02/19 19:55:01 crowley Exp crowley $ SPRITE (Berkeley)
  1621. X#
  1622. X# Copyright 1991 Regents of the University of California
  1623. X# Permission to use, copy, modify, and distribute this
  1624. X# software and its documentation for any purpose and without
  1625. X# fee is hereby granted, provided that this copyright
  1626. X# notice appears in all copies.  The University of California
  1627. X# makes no representations about the suitability of this
  1628. X# software for any purpose.  It is provided "as is" without
  1629. X# express or implied warranty.
  1630. X#
  1631. X
  1632. X# unknown:
  1633. X# Invoked when a Tcl command is invoked that doesn't exist in the
  1634. X# interpreter:
  1635. X#
  1636. X#    1. See if the autoload facility can locate the command in a
  1637. X#       Tcl script file.  If so, load it and execute it.
  1638. X#    2. See if the command exists as an executable UNIX program.
  1639. X#       If so, "exec" the command.
  1640. X#    3. See if the command is a valid abbreviation for another command.
  1641. X#       if so, invoke the command.  However, only permit abbreviations
  1642. X#       at top-level.
  1643. X
  1644. proc unknown args {
  1645. X    global auto_noexec auto_noload env unknown_active
  1646. X
  1647. X    if [info exists unknown_active] {
  1648. X    unset unknown_active
  1649. X    error "unexpected recursion in \"unknown\" command"
  1650. X    }
  1651. X    set unknown_active 1
  1652. X    set name [lindex $args 0]
  1653. X    if ![info exists auto_noload] {
  1654. X    if [auto_load $name] {
  1655. X        unset unknown_active
  1656. X        return [uplevel $args]
  1657. X    }
  1658. X    }
  1659. X    if ![info exists auto_noexec] {
  1660. X    if [auto_execok $name] {
  1661. X        unset unknown_active
  1662. X        return [uplevel exec $args]
  1663. X    }
  1664. X    }
  1665. X    if {([info level] == 1) && ([info script] == "")} {
  1666. X    set cmds [info commands $name*]
  1667. X    if {[llength $cmds] == 1} {
  1668. X        unset unknown_active
  1669. X        return [uplevel [lreplace $args 0 0 $cmds]]
  1670. X    }
  1671. X    if {[llength $cmds] != 0} {
  1672. X        unset unknown_active
  1673. X        error "ambiguous command name \"$name\": $cmds"
  1674. X    }
  1675. X    }
  1676. X    unset unknown_active
  1677. X    error "invalid command name \"$name\""
  1678. X}
  1679. X
  1680. X# auto_load:
  1681. X# Checks a collection of library directories to see if a procedure
  1682. X# is defined in one of them.  If so, it sources the appropriate
  1683. X# library file to create the procedure.  Returns 1 if it successfully
  1684. X# loaded the procedure, 0 otherwise.
  1685. X
  1686. proc auto_load cmd {
  1687. X    global auto_index auto_path env
  1688. X
  1689. X    if [info exists auto_index($cmd)] {
  1690. X    source $auto_index($cmd)
  1691. X    return 1
  1692. X    }
  1693. X    if [catch {set path $auto_path}] {
  1694. X    if [catch {set path $env(TCLLIBPATH)}] {
  1695. X        if [catch {set path [info library]}] {
  1696. X        return 0
  1697. X        }
  1698. X    }
  1699. X    }
  1700. X    foreach dir $path {
  1701. X    set f ""
  1702. X    catch {
  1703. X        set f [open $dir/tclIndex]
  1704. X        if {[gets $f] != "# Tcl autoload index file: each line identifies a Tcl"} {
  1705. X        puts stdout "Bad id line in file $dir/tclIndex"
  1706. X        error done
  1707. X        }
  1708. X        while {[gets $f line] >= 0} {
  1709. X        if {([string index $line 0] == "#") || ([llength $line] != 2)} {
  1710. X            continue
  1711. X        }
  1712. X        set name [lindex $line 0]
  1713. X        if {![info exists auto_index($name)]} {
  1714. X            set auto_index($name) $dir/[lindex $line 1]
  1715. X        }
  1716. X        }
  1717. X    }
  1718. X    if {$f != ""} {
  1719. X        close $f
  1720. X    }
  1721. X    }
  1722. X    if [info exists auto_index($cmd)] {
  1723. X    source $auto_index($cmd)
  1724. X    return 1
  1725. X    }
  1726. X    return 0
  1727. X}
  1728. X
  1729. X# auto_execok:
  1730. X# Returns 1 if there's an executable in the current path for the
  1731. X# given name, 0 otherwise.  Builds an associative array auto_execs
  1732. X# that caches information about previous checks, for speed.
  1733. X
  1734. proc auto_execok name {
  1735. X    global auto_execs env
  1736. X
  1737. X    if [info exists auto_execs($name)] {
  1738. X    return $auto_execs($name)
  1739. X    }
  1740. X    set auto_execs($name) 0
  1741. X    foreach dir [split $env(PATH) :] {
  1742. X    if {[file executable $dir/$name] && ![file isdirectory $dir/$name]} {
  1743. X        set auto_execs($name) 1
  1744. X        return 1
  1745. X    }
  1746. X    }
  1747. X    return 0
  1748. X}
  1749. X
  1750. X# auto_reset:
  1751. X# Destroy all cached information for auto-loading and auto-execution,
  1752. X# so that the information gets recomputed the next time it's needed.
  1753. X
  1754. proc auto_reset {} {
  1755. X    global auto_execs auto_index
  1756. X    unset auto_execs auto_index
  1757. X}
  1758. END_OF_FILE
  1759. if test 3992 -ne `wc -c <'tclLib/init.tcl'`; then
  1760.     echo shar: \"'tclLib/init.tcl'\" unpacked with wrong size!
  1761. fi
  1762. # end of 'tclLib/init.tcl'
  1763. fi
  1764. if test -f 'tclLib/subs.tcl' -a "${1}" != "-c" ; then 
  1765.   echo shar: Will not clobber existing file \"'tclLib/subs.tcl'\"
  1766. else
  1767. echo shar: Extracting \"'tclLib/subs.tcl'\" \(3547 characters\)
  1768. sed "s/^X//" >'tclLib/subs.tcl' <<'END_OF_FILE'
  1769. X
  1770. X# The purpose of the following is to prevent too many interpretations
  1771. X# of strings that are gotten from the selection (and other places)
  1772. X
  1773. proc InsertSelectedString {} {
  1774. X    InsertString [selection get]
  1775. X}
  1776. X
  1777. proc SearchForSel {regex direction} {
  1778. X    set sel [selection get]
  1779. X    if {$regex == 1} then {
  1780. X        RegexSearch $sel $direction
  1781. X    } else {
  1782. X        Search $sel $direction
  1783. X    }
  1784. X}
  1785. X
  1786. X# Miscellaneous subroutines
  1787. X
  1788. proc FixGeometry {g} {
  1789. X    global screen_width screen_height
  1790. X    # set default values for width and height
  1791. X    set w 500
  1792. X    set h 450
  1793. X    set ret [regexp {([0-9]+)x([0-9]+)([+-])([0-9]+)([+-])([0-9]+)} $g \
  1794. X        junk w h sx x sy y]
  1795. X    if [info exists y] {
  1796. X        if ![string compare $sx "-"] {
  1797. X            set x [expr $screen_width-$w-$x]
  1798. X        }
  1799. X        if ![string compare $sy "-"] {
  1800. X            set y [expr $screen_height-$h-$y]
  1801. X        }
  1802. X        return [format "%dx%d+%d+%d" $w $h $x $y]
  1803. X    } else {
  1804. X        return [format "%dx%d" $w $h]
  1805. X    }
  1806. X}
  1807. X
  1808. proc execButton { w cmd } {
  1809. X    global insideButton
  1810. X    if $insideButton then {$w flash;catch "eval $cmd"}
  1811. X}
  1812. X
  1813. proc pr {s} {puts stdout $s}
  1814. X
  1815. proc OpenFileOrCD {button} {
  1816. X    global location1 location2 location3
  1817. X    global browser1 browser2 browser3
  1818. X    set name [selection get]
  1819. X    # check for a file size at the end of the name
  1820. X    set pat "\{(.*) \(\[0-9\]+k\)\}$"
  1821. X    if [regexp "$pat" "$name" junk fname] {
  1822. X        # and remove the file size if it is found
  1823. X        set name $fname
  1824. X    }
  1825. X    if [file isdirectory $name] then {
  1826. X        if {$button==1} {
  1827. X            CD $name
  1828. X        }
  1829. X        if {$button==2} {
  1830. X            Browser $browser2 small
  1831. X            CD $name
  1832. X        }
  1833. X        if {$button==3} {
  1834. X            Browser $browser3 small
  1835. X            CD $name
  1836. X        }
  1837. X    } else {
  1838. X        OpenWindow $name "[set location$button]"
  1839. X    }
  1840. X}
  1841. X
  1842. proc RemoteOpen {name {loc 1}} {
  1843. X    global location1 location2 location3
  1844. X    OpenWindow $name "[set location$loc]"
  1845. X}
  1846. X    
  1847. proc bind.entry args {
  1848. X    foreach w $args {
  1849. X    bind $w <Any-KeyPress> {%W insert cursor "%A"}
  1850. X    bind $w <Any-space> {%W insert cursor " "}
  1851. X    bind $w <Any-2> {puts stdout "character [%W index @%x]"}
  1852. X    bind $w <Any-Delete> {bs %W}
  1853. X    bind $w <Any-BackSpace> {bs %W}
  1854. X    bind $w <Any-Control-h> {bs %W}
  1855. X    bind $w <Any-1> {%W cursor @%x; %W select from @%x}
  1856. X#    bind $w <Any-1> {%W cursor @%x; focus %W; %W select from @%x}
  1857. X    bind $w <Any-B1-Motion> {%W select to @%x}
  1858. X    bind $w <Shift-1> {%W select adjust @%x}
  1859. X    bind $w <Shift-B1-Motion> {%W select to @%x}
  1860. X    bind $w <Any-3> {%W scan mark %x}
  1861. X    bind $w <Any-B3-Motion> {%W scan dragto %x}
  1862. X    bind $w <Any-Control-d> {%W delete sel.first sel.last}
  1863. X    bind $w <Any-Control-v> {%W insert cursor [selection get]}
  1864. X    bind $w <Any-Control-u> {%W delete 0 end}
  1865. X    # from here to the end are addtions from Mark Harrison 
  1866. X    # <harrison@csl.dl.nec.com> on mail list tcl@allspice.Berkeley.EDU
  1867. X        # quote, backslash, and left bracket need
  1868. X        # to be handled specially.
  1869. X        bind $w <Any-quotedbl> {%W insert cursor "\""}
  1870. X        bind $w <Any-backslash> {%W insert cursor "\\"}
  1871. X        bind $w <Any-bracketleft> {%W insert cursor "\["}
  1872. X        # left, right arrows move cursor
  1873. X        bind $w <Any-Left>  {%W cursor [expr [%W index cursor]-1] }
  1874. X        bind $w <Any-Right> {%W cursor [expr [%W index cursor]+1] }
  1875. X    }
  1876. X}
  1877. X
  1878. proc bind.menu args {
  1879. X    foreach w $args {
  1880. X    bind $w <Any-Enter> "$w activate @%y"
  1881. X    bind $w <Any-Leave> "$w activate none"
  1882. X    bind $w <Any-Motion> "$w activate @%y"
  1883. X    bind $w <Any-ButtonRelease-1> "$w invoke active"
  1884. X    }
  1885. X}
  1886. X
  1887. proc bs win {
  1888. X    set x [expr {[$win index cursor] - 1}]
  1889. X    if {$x != -1} {$win delete $x}
  1890. X}
  1891. X
  1892. proc tkerror {msg} {
  1893. X        if ![string match "*.ThinBrowserMenu.*" $msg] {
  1894. X# This gives spurious messages so omit it for now
  1895. X#                puts stderr "Tk background error: $msg"
  1896. X        }
  1897. X}
  1898. X
  1899. END_OF_FILE
  1900. if test 3547 -ne `wc -c <'tclLib/subs.tcl'`; then
  1901.     echo shar: \"'tclLib/subs.tcl'\" unpacked with wrong size!
  1902. fi
  1903. # end of 'tclLib/subs.tcl'
  1904. fi
  1905. if test -f 'tclLib/windows.tcl' -a "${1}" != "-c" ; then 
  1906.   echo shar: Will not clobber existing file \"'tclLib/windows.tcl'\"
  1907. else
  1908. echo shar: Extracting \"'tclLib/windows.tcl'\" \(5527 characters\)
  1909. sed "s/^X//" >'tclLib/windows.tcl' <<'END_OF_FILE'
  1910. X#
  1911. X#
  1912. X# Create a browser window
  1913. X#
  1914. X#
  1915. proc BrowserWindow {geometry} {
  1916. X
  1917. X    global wcounter raised bd location1 location2 location3
  1918. X    global screen_width screen_height
  1919. X
  1920. X    set wcounter [expr $wcounter+1]
  1921. X    set name [format ".bw%05d" $wcounter]
  1922. X
  1923. X    set thinBrowser [Option get thinBrowser]
  1924. X    if $thinBrowser then {
  1925. X        set geom 10x3
  1926. X        set cols 1
  1927. X    } else {
  1928. X        set geom 20x1
  1929. X        set cols 4
  1930. X    }
  1931. X    toplevel $name -class PtBrowser -relief $raised -bd $bd
  1932. X    wm geometry $name [FixGeometry $geometry]
  1933. X    wm positionfrom $name user
  1934. X    wm minsize $name 0 0
  1935. X    bind $name <Any-Enter>    "EnterBrowser $name"
  1936. X    bind $name <Configure>    "Configure $name"
  1937. X
  1938. X    # create the list of open windows
  1939. X    # first a frame to contain the scrollbar and the list
  1940. X    frame $name.openList
  1941. X
  1942. X    # then a scrollbar
  1943. X    scrollbar $name.openList.scroll -relief $raised -bd $bd \
  1944. X        -command "$name.openList.list view"
  1945. X
  1946. X    # then a list
  1947. X    colbox $name.openList.list -relief $raised -bd $bd \
  1948. X        -geometry $geom -scroll "$name.openList.scroll set"
  1949. X    bind $name.openList.list <Any-Button-1> \
  1950. X        "RaiseListWindow \[%W nearest %x %y\] $location1
  1951. X            RaiseWindow"
  1952. X    bind $name.openList.list <Any-Button-2> \
  1953. X        "RaiseListWindow \[%W nearest %x %y\] $location2
  1954. X            RaiseWindow"
  1955. X    bind $name.openList.list <Any-Button-3> \
  1956. X        "RaiseListWindow \[%W nearest %x %y\] $location3
  1957. X            RaiseWindow"
  1958. X    $name.openList.list insert 0 "No open files"
  1959. X
  1960. X    # then pack then in
  1961. X    pack append $name.openList \
  1962. X        $name.openList.scroll {left fill} \
  1963. X        $name.openList.list {right fill expand}
  1964. X
  1965. X    # create the menu bar
  1966. X    global BrowserMenuSpec ThinBrowserMenuSpec
  1967. X    if $thinBrowser then {
  1968. X        MakeMenubar $name.menu $ThinBrowserMenuSpec
  1969. X    } else {
  1970. X        MakeMenubar $name.menu $BrowserMenuSpec
  1971. X    }
  1972. X    BrowserMenuBindings $name.menu
  1973. X
  1974. X    # create the list of files in the current directory
  1975. X    # first a frame to contain the scrollbar and the list
  1976. X    frame $name.fileList
  1977. X
  1978. X    # then a scrollbar
  1979. X    scrollbar $name.fileList.scroll -relief $raised -bd $bd \
  1980. X        -command "$name.fileList.list view"
  1981. X
  1982. X    # then a list
  1983. X    colbox $name.fileList.list -relief $raised  -bd $bd -geometry 20x10 \
  1984. X        -columns $cols -scroll "$name.fileList.scroll set"
  1985. X    bind $name.fileList.list <Any-Double-Button-1> "OpenFileOrCD 1"
  1986. X    bind $name.fileList.list <Any-Double-Button-2> "OpenFileOrCD 2"
  1987. X    bind $name.fileList.list <Any-Double-Button-3> "OpenFileOrCD 3"
  1988. X    bind $name.fileList.list <Any-Button> "set item \[%W nearest %x %y\]
  1989. X                            %W select from \$item"
  1990. X    bind $name.fileList.list <Any-B1-Motion> "set item \[%W nearest %x %y\]
  1991. X                            %W select from \$item"
  1992. X    # then pack then in
  1993. X    pack append $name.fileList \
  1994. X        $name.fileList.scroll {left fill} \
  1995. X        $name.fileList.list {right fill expand}
  1996. X
  1997. X    # create a message line
  1998. X    entry $name.msg -relief $raised -bd $bd
  1999. X    bind.entry $name.msg
  2000. X
  2001. X    # pack everything in the frame
  2002. X    pack append $name \
  2003. X        $name.openList {top fill} \
  2004. X        $name.menu {top fill} \
  2005. X        $name.fileList {top fill expand} \
  2006. X        $name.msg {bottom fill}
  2007. X    set screen_width [winfo screenwidth $name]
  2008. X    set screen_height [winfo screenheight $name]
  2009. X    return $name
  2010. X}
  2011. X
  2012. X#
  2013. X#
  2014. X# Create a text window
  2015. X#
  2016. X#
  2017. proc TextWindow {geometry} {
  2018. X
  2019. X    global wcounter raised bd
  2020. X
  2021. X    set wcounter [expr $wcounter+1]
  2022. X    set name [format ".tw%05d" $wcounter]
  2023. X
  2024. X    toplevel $name -class PtText -relief $raised -bd $bd
  2025. X    wm geometry $name [FixGeometry $geometry]
  2026. X    wm positionfrom $name user
  2027. X    wm minsize $name 0 0
  2028. X    bind $name <Any-Enter> "EnterText $name"
  2029. X
  2030. X    # the menu bar at the top (the window manager provides the title)
  2031. X    global TextMenuSpec
  2032. X    MakeMenubar $name.menu $TextMenuSpec
  2033. X    TextMenuBindings $name.menu
  2034. X
  2035. X    # a frame to hold the vertical scroll bar and the text window
  2036. X    frame $name.VScrollAndText -relief $raised -bd $bd
  2037. X    scrollbar $name.VScrollAndText.VScroll -relief $raised -bd $bd \
  2038. X        -width 12 -command "VScroll tk"
  2039. X    bind $name.VScrollAndText.VScroll <Any-ButtonPress> {VScroll press %y %b}
  2040. X    bind $name.VScrollAndText.VScroll <Any-B1-Motion> {VScroll press %y 1}
  2041. X    bind $name.VScrollAndText.VScroll <Any-B2-Motion> {VScroll motion %y 2}
  2042. X    bind $name.VScrollAndText.VScroll <Any-B3-Motion> {VScroll press %y 3}
  2043. X    bind $name.VScrollAndText.VScroll <Any-ButtonRelease-1> \
  2044. X                        {VScroll release %y 1}
  2045. X    bind $name.VScrollAndText.VScroll <Any-ButtonRelease-3> \
  2046. X                        {VScroll release %y 3}
  2047. X    frame $name.VScrollAndText.Text
  2048. X    TextBindings $name.VScrollAndText.Text $name
  2049. X    pack append $name.VScrollAndText \
  2050. X        $name.VScrollAndText.VScroll {left fill} \
  2051. X        $name.VScrollAndText.Text {right expand fill}
  2052. X
  2053. X    # a frame to hold the filler (splitter) and the horizontal scroll bar
  2054. X    frame $name.SplitterAndHScroll
  2055. X    frame $name.SplitterAndHScroll.Splitter -geometry "12x12"
  2056. X    scrollbar $name.SplitterAndHScroll.HScroll -orient horizontal \
  2057. X        -relief $raised -bd $bd -width 10 -command "HScroll tk"
  2058. X    bind $name.SplitterAndHScroll.HScroll <Any-ButtonPress> \
  2059. X                            {HScroll press %x %b}
  2060. X    bind $name.SplitterAndHScroll.HScroll <Any-B1-Motion> \
  2061. X                            {HScroll press %x 1}
  2062. X    bind $name.SplitterAndHScroll.HScroll <Any-B2-Motion> \
  2063. X                            {HScroll motion %x 2}
  2064. X    bind $name.SplitterAndHScroll.HScroll <Any-B3-Motion> \
  2065. X                            {HScroll press %x 3}
  2066. X    bind $name.SplitterAndHScroll.HScroll <Any-ButtonRelease-1> \
  2067. X                            {HScroll release %x 1}
  2068. X    bind $name.SplitterAndHScroll.HScroll <Any-ButtonRelease-3> \
  2069. X                            {HScroll release %x 3}
  2070. X    pack append $name.SplitterAndHScroll \
  2071. X        $name.SplitterAndHScroll.Splitter {left fill} \
  2072. X        $name.SplitterAndHScroll.HScroll {right expand fill}
  2073. X
  2074. X    # now pack them all up in a column
  2075. X    pack append $name \
  2076. X        $name.menu {top fill} \
  2077. X        $name.VScrollAndText {top expand fill} \
  2078. X        $name.SplitterAndHScroll {bottom fill}
  2079. X    return $name
  2080. X}
  2081. X
  2082. END_OF_FILE
  2083. if test 5527 -ne `wc -c <'tclLib/windows.tcl'`; then
  2084.     echo shar: \"'tclLib/windows.tcl'\" unpacked with wrong size!
  2085. fi
  2086. # end of 'tclLib/windows.tcl'
  2087. fi
  2088. echo shar: End of archive 2 \(of 15\).
  2089. cp /dev/null ark2isdone
  2090. MISSING=""
  2091. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
  2092.     if test ! -f ark${I}isdone ; then
  2093.     MISSING="${MISSING} ${I}"
  2094.     fi
  2095. done
  2096. if test "${MISSING}" = "" ; then
  2097.     echo You have unpacked all 15 archives.
  2098.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2099. else
  2100.     echo You still need to unpack the following archives:
  2101.     echo "        " ${MISSING}
  2102. fi
  2103. ##  End of shell archive.
  2104. exit 0
  2105. -- 
  2106. --
  2107. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  2108. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  2109. Sunnyvale, California 94086            at&t: 408/522-9236
  2110.