home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume17 / tcleditr / part13 < prev    next >
Encoding:
Text File  |  1992-03-17  |  42.6 KB  |  1,759 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: v17i014: point text editor (TCL and TK), Part13/16
  5. Message-ID: <1992Mar18.141835.27639@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:18:35 GMT
  11. Approved: dcmartin@msi.com
  12.  
  13. Submitted-by: crowley@chaco.cs.unm.edu (Charlie Crowley)
  14. Posting-number: Volume 17, Issue 14
  15. Archive-name: tcl-editor/part13
  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 12 (of 15)."
  24. # Contents:  command.c
  25. # Wrapped by crowley@chaco.cs.unm.edu on Tue Mar 10 15:05:49 1992
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'command.c' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'command.c'\"
  29. else
  30. echo shar: Extracting \"'command.c'\" \(40012 characters\)
  31. sed "s/^X//" >'command.c' <<'END_OF_FILE'
  32. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/command.c,v 1.12 1992/03/04 17:07:18 crowley Exp crowley $ */
  33. X
  34. X#include <ctype.h>
  35. X#include <string.h>
  36. X#include <stdio.h>
  37. X#include "pt.h"
  38. X#include <X11/keysym.h>
  39. X#include <X11/StringDefs.h>
  40. X
  41. X/* remember whether to erase the description message */
  42. int lastOnTopline = 0;
  43. X
  44. X/* remember the last command the user selected (for help) */
  45. int lastCommand = FDONOTHING;
  46. X
  47. X/* some status (or mode) flags and move/copy pending data */
  48. int movePending = 0;
  49. int copyPending = 0;
  50. struct window *pendWindow = NULL;
  51. Offset pendPosition;
  52. X
  53. X/* keyboard macro */
  54. char macroText[102];
  55. int macroIndex = 0;
  56. int macroSize = 0;
  57. int macroState = 0;
  58. X
  59. X/* for multiple exposes, keep the maximum bounds */
  60. static int minx = 999999, miny = 999999, maxx = 0, maxy = 0;
  61. X
  62. char *
  63. command( fn, arg1, arg2, arg3, arg4, arg5, arg6 )
  64. X    PointCommand fn;
  65. X    char *arg1;
  66. X    char *arg2;
  67. X    char *arg3;
  68. X    char *arg4;
  69. X    char *arg5;
  70. X    char *arg6;
  71. X{
  72. X    extern char msgBuffer[];
  73. X    extern char textBuffer[];
  74. X    extern char homeDirectory[];
  75. X    extern int debug;
  76. X    extern struct window *selWindow;
  77. X    extern Offset selBegin, selEnd;
  78. X    extern int overType;
  79. X    extern int lastOnTopline;
  80. X    extern int lastCommand;
  81. X    extern int macroIndex;
  82. X    extern int macroSize;
  83. X    extern int macroState;
  84. X    extern int selMode;
  85. X    extern int lastFn;
  86. X    extern int errno;
  87. X    extern struct openFile *files;
  88. X    extern struct optionItem options[];
  89. X    extern struct window *windowList;
  90. X    extern int copyPending, movePending;
  91. X    extern struct window *pendWindow;
  92. X    extern Offset pendPosition;
  93. X    extern int topOnFind;
  94. X    extern long timeOfLastSave;
  95. X    extern Offset mm_cp;
  96. X    extern Cursor mainCursor;
  97. X    extern Cursor currentCursor;
  98. X    extern Cursor dupCursor;
  99. X    extern Display *MainDisplay;
  100. X    extern BrowserData *mainBrowser;
  101. X    extern BrowserData *activeBrowser;
  102. X    extern BrowserData *browserList;
  103. X    extern struct window * activeWindow;
  104. X#ifdef HYPERTEXT
  105. X    extern DBM *currentDB;
  106. X    extern Document currentDocument;
  107. X    extern int hypertextOn;
  108. X#endif
  109. X    extern int tkScrolling;
  110. X    extern Tcl_Interp * interp;
  111. X    extern char * textGeometry;
  112. X    extern char * browserGeometry;
  113. X    extern char * textFont;
  114. X    extern char * browserFont;
  115. X    extern char * returnString;
  116. X    extern Tk_Window TkMainWindow;
  117. X    extern int scrollDown;
  118. X    extern int intervalRows;
  119. X    extern int linesOverFind;
  120. X    extern struct window * scroll_window;
  121. X
  122. X    int n, ret, row1, col1, col2;
  123. X    Offset cp;
  124. X    char ch;
  125. X    char *fileName, *str;
  126. X    struct window *w2;
  127. X    struct window *saveSelWindow;
  128. X    char * ret_string = NULL;
  129. X    int int1, int2, int3, int4, int5, int6;
  130. X    struct window * w = activeWindow;
  131. X    BrowserData * browser;
  132. X    struct changeItem * last_change;
  133. X    struct openFile * ff;
  134. X    Offset saveSelBegin, saveSelEnd;
  135. X
  136. X/* since we are about to issue a command, we do not need to erase */
  137. X/* the command description on the top line (so don't) */
  138. lastOnTopline = 0;
  139. X
  140. switch( fn ) {
  141. X
  142. X/*********************** EVENT HANDLER COMMANDS ***************************/
  143. case FBARRIER: {
  144. X    int x, y;
  145. X    struct fontDataStruct *font = &(w->font);
  146. X    (void)Tcl_GetInt( interp, arg1, &int1 );
  147. X    OffsetToXY( w, int1, &row1, &col1 );
  148. X    if( row1 < 0 ) {
  149. X        printf("offset %d is not in the window\n", row1);
  150. X        break;
  151. X    }
  152. X    x = w->leftMargin + col1 * font->width;
  153. X    y = w->topMargin + (row1+1) * font->height - 2;
  154. X    XDrawLine( MainDisplay, w->x_window_id, font->gc_normal,
  155. X        x, y, x-3, y+3 );
  156. X    XDrawLine( MainDisplay, w->x_window_id, font->gc_normal,
  157. X        x, y-1, x-3, y+2 );
  158. X    XDrawLine( MainDisplay, w->x_window_id, font->gc_normal,
  159. X        x, y, x+3, y+3 );
  160. X    XDrawLine( MainDisplay, w->x_window_id, font->gc_normal,
  161. X        x, y-1, x+3, y+2 );
  162. X    break;
  163. X}
  164. X#ifdef XXXXXX
  165. X    if( strcmp(arg1,"grab")==0 ) {
  166. X        Tk_Window tkwin;
  167. X        char name [100];
  168. X        
  169. X        sprintf( name, "%s.VScrollAndText", w->tk_pathname );
  170. X        tkwin = Tk_NameToWindow( interp, name, w->tk_toplevel );
  171. X        XGrabPointer(
  172. X            MainDisplay,
  173. X            Tk_WindowId(w->tk_toplevel),
  174. X            True,
  175. X            ButtonPressMask|ButtonReleaseMask|PointerMotionMask,
  176. X            GrabModeAsync,
  177. X            GrabModeAsync,
  178. X            (debug==0 ? Tk_WindowId(w->tk_toplevel)
  179. X                  : Tk_WindowId(tkwin) ),
  180. X            None,
  181. X            CurrentTime
  182. X        );
  183. X    } else {
  184. X        XUngrabPointer( MainDisplay, CurrentTime );
  185. X    }
  186. X    break;
  187. X#endif
  188. X
  189. case FCONFIGURE:
  190. X    w = FindWindowByTkName( arg1 );
  191. X    if( w == NULL ) {
  192. X        browser = FindBrowserByTkName( arg1 );
  193. X        if( browser == NULL ) {
  194. X            printf("FCONFIGURE: window %s was not found\n", arg1);
  195. X            break;
  196. X        }
  197. X        NewFilelist( browser );
  198. X        break;
  199. X    }
  200. X    WorkspaceResized( w );
  201. X    break;
  202. X
  203. case FENTERTEXT:
  204. X    w2 = FindWindowByTkName( arg1 );
  205. X    if( w2 == NULL ) {
  206. X#ifdef DEBUG_UPDATE
  207. X        printf("FENTERTEXT: window %s not found\n", arg1);
  208. X#endif
  209. X        break;
  210. X    }
  211. X    activeWindow = w2;
  212. X    XDefineCursor( MainDisplay, activeWindow->x_window_id, currentCursor );
  213. X    break;
  214. X
  215. case FENTERBROWSER:
  216. X    activeBrowser = FindBrowserByTkName( arg1 );
  217. X    chdir( activeBrowser->cwd );
  218. X    break;
  219. X
  220. case FEXPOSE:
  221. X    w = FindWindowByTkName( arg1 );
  222. X    if( w == NULL ) {
  223. X#ifdef DEBUG_UPDATE
  224. X        printf("FEXPOSE: window %s not found\n", arg1);
  225. X#endif
  226. X        break;
  227. X    }
  228. X    (void)Tcl_GetInt( interp, arg2, &int2 );
  229. X    if( int2 < minx )
  230. X        minx = int2;
  231. X    (void)Tcl_GetInt( interp, arg3, &int3 );
  232. X    if( int3 < miny )
  233. X        miny = int3;
  234. X    (void)Tcl_GetInt( interp, arg4, &int4 );
  235. X    int4 += int2;    /* get right x-coord */
  236. X    if( int4 > maxx )
  237. X        maxx = int4;
  238. X    (void)Tcl_GetInt( interp, arg5, &int5 );
  239. X    int5 += int3;    /* get bottom y-coord */
  240. X    if( int5 > maxy )
  241. X        maxy = int5;
  242. X    (void)Tcl_GetInt( interp, arg6, &int6 );
  243. X    if( int6 > 0 )    /* more expose events yet to come */
  244. X        break;
  245. X    repaint( w, minx, miny, maxx, maxy );
  246. X    maxx = maxy = 0;
  247. X    minx = miny = 999999;    /* bigger than any screen ? */
  248. X    break;
  249. X
  250. case FHSCROLL:
  251. X    if( w == NULL )
  252. X        break;
  253. X    if( striccmp(arg1,"press")==0 )
  254. X        n = 1;
  255. X    else if( striccmp(arg1,"release")==0 )
  256. X        n = 2;
  257. X    else if( striccmp(arg1,"motion")==0 )
  258. X        n = 3;
  259. X    else
  260. X        n = 0;
  261. X    if( n == tkScrolling )
  262. X        break;
  263. X    (void)Tcl_GetInt( interp, arg2, &int2 );
  264. X    if( n == 1 ) {
  265. X        (void)Tcl_GetInt( interp, arg3, &int3 );
  266. X    }
  267. X    HScroll( w, n, int2, int3 );
  268. X    break;
  269. X
  270. case FKEY:
  271. X    if( w == NULL ) {
  272. X        printf("FKEY: window is NULL\n");
  273. X        break;
  274. X    }
  275. X    (void)Tcl_GetInt( interp, arg1, &int1 );
  276. X    (void)Tcl_GetInt( interp, arg2, &int2 );
  277. X    HandleKey( int1, int2 );
  278. X    break;
  279. X
  280. case FMOUSE:
  281. X    w = FindWindowByTkName( arg1 );
  282. X    if( w == NULL ) {
  283. X        printf("FMOUSE: window %s not found\n", arg1);
  284. X        break;
  285. X    }
  286. X    (void)Tcl_GetInt( interp, arg3, &int3 );
  287. X    (void)Tcl_GetInt( interp, arg4, &int4 );
  288. X    Mouse( w, arg2, int3, int4 );
  289. X    break;
  290. X
  291. case FVSCROLL:
  292. X    if( w == NULL ) {
  293. X        printf("FVSCROLL: window is NULL\n");
  294. X        break;
  295. X    }
  296. X    if( striccmp(arg1,"press")==0 )
  297. X        n = 1;
  298. X    else if( striccmp(arg1,"release")==0 )
  299. X        n = 2;
  300. X    else if( striccmp(arg1,"motion")==0 )
  301. X        n = 3;
  302. X    else
  303. X        n = 0;
  304. X    if( tkScrolling ) {
  305. X        if( n != 0 )
  306. X            break;
  307. X        else
  308. X            int3 = 0;
  309. X    } else {
  310. X        if( n == 0 )
  311. X            break;
  312. X        else
  313. X            (void)Tcl_GetInt( interp, arg3, &int3 );
  314. X    }
  315. X    (void)Tcl_GetInt( interp, arg2, &int2 );
  316. X    VScroll( w, n, int2, int3 );
  317. X    break;
  318. X
  319. X/*********************** MACRO COMMANDS ***************************/
  320. case FWAITFORRETURNSTRING:
  321. X    PtFree( returnString );
  322. X    returnString = PtMalloc( 50 , "string" );
  323. X    returnString[0] = '\0';
  324. X    while( returnString[0] == '\0' ) {
  325. X        Tk_DoOneEvent( 0 );
  326. X    }
  327. X    break;
  328. X
  329. case FPOINTSELECTION:
  330. if( striccmp(arg1,"set")==0 ) {
  331. X    if( arg2[0] != '\0' ) {
  332. X        (void)Tcl_GetInt( interp, arg2, &selBegin );
  333. X        if( selBegin < 0 )
  334. X            selBegin = 0;
  335. X    }
  336. X    if( arg3[0] != '\0' ) {
  337. X        cp = fileSize(selWindow->fileId);
  338. X        if( selEnd >= cp ) {
  339. X            selEnd = cp - 1;
  340. X        }
  341. X    }
  342. X    (void)Tcl_GetInt( interp, arg3, &selEnd );
  343. X    if( arg4[0] != '\0' ) {
  344. X        w = FindWindowByTkName( arg4 );
  345. X        if( w == NULL ) {
  346. X            printf("FPOINTSELECTION: window %s not found\n",
  347. X                arg4);
  348. X            break;
  349. X        }
  350. X        selWindow = w;
  351. X    }
  352. X    if( arg5[0] != '\0' ) {
  353. X        if( strcmp(arg5,"char")==0 )
  354. X            selMode = SELCHAR;
  355. X        else if( strcmp(arg5,"word")==0 )
  356. X            selMode = SELWORD;
  357. X        else
  358. X            selMode = SELLINE;
  359. X    }
  360. X} else if( arg1[0] == '\0' || striccmp(arg1,"get")==0 ){
  361. X    switch( selMode ) {
  362. X        case SELCHAR: str = "char"; break;
  363. X        case SELWORD: str = "word"; break;
  364. X        case SELLINE: str = "line"; break;
  365. X    }
  366. X    sprintf( textBuffer, "%d %d %s %s %d", selBegin, selEnd,
  367. X        selWindow==NULL ?
  368. X            "NoSelection" : selWindow->tk_pathname,
  369. X        str, LineNumberOfSelection() );
  370. X    ret_string = textBuffer;
  371. X    Tcl_SetResult( interp, ret_string, TCL_STATIC );
  372. X} else {     /* must be a 'Sel return' */
  373. X    n = 256;
  374. try_again:
  375. X    ret_string = (char *)PtMalloc( n, "selection" );
  376. X    ret = getSelection( ret_string, 0, n );
  377. X    if( !ret ) {    /* did we get the whole selection? */
  378. X        /* if not, double the buffer and try again */
  379. X        n *= 2;
  380. X        PtFree( ret_string );
  381. X        goto try_again;
  382. X    }
  383. X    /* do we need to escape things? */
  384. X    if( striccmp(arg1,"escaped")==0 ) {
  385. X        /* first count the number of braces */
  386. X        row1 = 0;
  387. X        str = ret_string;
  388. X        while( (ch = *str++) != '\0' ) {
  389. X            if( ch == '{' || ch == '}' )
  390. X                ++row1;
  391. X        }
  392. X        if( row1 > 0 ) {
  393. X            /* allocate space for the escaped version */
  394. X            char * new_space = (char *)PtMalloc(
  395. X                row1 + (str - ret_string) + 1,
  396. X                "selection" );
  397. X            /* copy and escape */
  398. X            char * from = ret_string;
  399. X            char * to = new_space;
  400. X            while( 1 ) {
  401. X                ch = *from++;
  402. X                if( ch == '{' || ch == '}' )
  403. X                    *to++ = '\\';
  404. X                *to++ = ch;
  405. X                if( ch == '\0' )
  406. X                    break;
  407. X            }
  408. X            PtFree( ret_string );
  409. X            ret_string = new_space;
  410. X        }
  411. X    }
  412. X    Tcl_SetResult( interp, ret_string, (Tcl_FreeProc *)PtFree );
  413. X}
  414. break;
  415. X
  416. case FGETFILECHARS:
  417. X    (void)Tcl_GetInt( interp, arg1, &int1 );
  418. X    (void)Tcl_GetInt( interp, arg2, &int2 );
  419. X    if( int1 < 0 )
  420. X        int1 = 0;
  421. X    if( int2 >= int1 + MSGBUFFERSIZE )
  422. X        int2 = MSGBUFFERSIZE - 1;
  423. X    if( arg3[0] != '\0' )
  424. X        w = FindWindowByTkName( arg3 );
  425. X    if( w == NULL ) {
  426. X        printf("FGETFILECHARS: window %s not found\n", arg3);
  427. X        break;
  428. X    }
  429. X    n = w->fileId;
  430. X    str = textBuffer;
  431. X    while( int1 <= int2 )
  432. X        *str++ = getFileByte( n, int1++ );
  433. X    ret_string = textBuffer;
  434. X    Tcl_SetResult( interp, ret_string, TCL_STATIC );
  435. X    break;
  436. X
  437. case FSCROLLWINDOW:
  438. X    if( arg3[0] != '\0' )
  439. X        w = FindWindowByTkName( arg3 );
  440. X    if( w == NULL ) {
  441. X        printf("FSCROLLWINDOW: window %s not found\n", arg3);
  442. X        break;
  443. X    }
  444. X    /* default is to scroll down one page */
  445. X    /* 'page' or a numerical count ? */
  446. X    if(arg2[0] == '\0' || striccmp(arg2,"page")==0 )
  447. X        intervalRows = w->nRows - 2;
  448. X    else
  449. X        intervalRows = atoi( arg2 );
  450. X    /* 'up' or 'down' ? */
  451. X    if( arg1[0] != '\0' && striccmp(arg1,"up")==0 )
  452. X        scrollDown = 0;
  453. X    else
  454. X        scrollDown = 1;
  455. X    scroll_window = w;
  456. X    (void)DoOneVScroll();
  457. X    break;
  458. X
  459. case FGETROWCOL:
  460. X    if( arg2[0] != '\0' )
  461. X        w = FindWindowByTkName( arg2 );
  462. X    if( w == NULL ) {
  463. X        printf("FGETROWCOL: window %s not found\n", arg2);
  464. X        break;
  465. X    }
  466. X    if( arg1[0] == '\0' )
  467. X        cp = selBegin;
  468. X    else
  469. X        cp = atoi( arg1 );
  470. X    OffsetToXY( w, cp, &col1, &col2 );
  471. X    sprintf( textBuffer, "%d %d", col1, col2 );
  472. X    ret_string = textBuffer;
  473. X    Tcl_SetResult( interp, ret_string, TCL_STATIC );
  474. X    break;
  475. X
  476. case FWINDOWNAME:
  477. X    if( strcmp(arg1,"set") == 0 ) {
  478. X        w = FindWindowByTkName( arg3 );
  479. X        if( w == NULL ) {
  480. X            printf("FWINDOWNAME: window %s not found\n", arg3);
  481. X            break;
  482. X        }
  483. X        if( strcmp(arg2,"active") == 0 )
  484. X            activeWindow = w;
  485. X        else
  486. X            selWindow = w;
  487. X    } else {
  488. X        if( strcmp(arg2,"active") == 0 )
  489. X            ret_string = activeWindow->tk_pathname;
  490. X        else
  491. X            ret_string = selWindow->tk_pathname;
  492. X        Tcl_SetResult( interp, ret_string, TCL_STATIC );
  493. X    }
  494. X    break;
  495. X
  496. case FGETWINDOWINFO:
  497. X    if( arg1[0] != '\0' )
  498. X        w = FindWindowByTkName( arg1 );
  499. X    if( w == NULL ) {
  500. X        printf("FGETWINDOWINFO: window %s not found\n", arg1);
  501. X        break;
  502. X    }
  503. X    sprintf( msgBuffer, "%d %d %d %d %d %d %d %d %d %d",
  504. X        w->posTopline, w->posBotline,
  505. X        w->numTopline, w->numBotline,
  506. X        w->indent, w->nRows, w->nCols,
  507. X        w->x_window_id, w->tk_toplevel, w->tk_text );
  508. X    ret_string = msgBuffer;
  509. X    Tcl_SetResult( interp, ret_string, TCL_STATIC );
  510. X    break;
  511. X
  512. case FGETFILEINFO: {
  513. X    struct openFile * ff;
  514. X    if( arg1[0] != '\0' )
  515. X        w = FindWindowByTkName( arg1 );
  516. X    if( w == NULL ) {
  517. X        printf("FGETFILEINFO: window %s not found\n", arg1);
  518. X        break;
  519. X    }
  520. X    ff = &files[w->fileId];
  521. X    sprintf( msgBuffer, "%s %d %d %d",
  522. X        ff->origName, ff->fileSize, ff->origFileSize, ff->flags );
  523. X    ret_string = msgBuffer;
  524. X    Tcl_SetResult( interp, ret_string, TCL_STATIC );
  525. X    break;
  526. X}
  527. X
  528. case FINSERTSTRING:
  529. X    if( selWindow == NULL )
  530. X        break;
  531. X    n = strlen( arg1 );
  532. X    if( arg2[0] != '\0' && strcmp(arg2,"noupdate")==0 )
  533. X        ret = 0;
  534. X    else
  535. X        ret = 1;
  536. X    if( n < 10 && ret ) {
  537. X        while( *arg1 != '\0' )
  538. X            insChar( *arg1++, ret );
  539. X    } else {
  540. X        while( *arg1 != '\0' )
  541. X            insertChar( *arg1++ );
  542. X        if( ret )
  543. X            drawWindow( selWindow );
  544. X    }
  545. X    break;
  546. X
  547. X/**************************** SEARCH COMMANDS **************************/
  548. case FSEARCHFORS:
  549. X    if( arg3[0] != '\0' )
  550. X        w = FindWindowByTkName( arg3 );
  551. X    if( w == NULL ) {
  552. X        printf("FSEARCHFORS: window %s not found\n", arg3);
  553. X        break;
  554. X    }
  555. X    if( arg2[0] == '\0' || striccmp(arg2,"forward")==0 )
  556. X        n = 0;
  557. X    else
  558. X        n = 1;
  559. X    if( arg4[0] == '\0' || strcmp(arg4,"update")==0 )
  560. X        col1 = UPDATEWINDOWS;
  561. X    else
  562. X        col1 = NOUPDATE;
  563. X    n = searchFor( w, n, arg1, col1, linesOverFind );
  564. X    sprintf( textBuffer, "%d", n );
  565. X    ret_string = textBuffer;
  566. X    Tcl_SetResult( interp, ret_string, TCL_STATIC );
  567. X    break;
  568. X
  569. case FREGEXSEARCH:
  570. X    if( arg3[0] != '\0' )
  571. X        w = FindWindowByTkName( arg3 );
  572. X    if( w == NULL ) {
  573. X        printf("FSEARCHFORS: window %s not found\n", arg3);
  574. X        break;
  575. X    }
  576. X    if( arg2[0] == '\0' || striccmp(arg2,"forward")==0 )
  577. X        n = 0;
  578. X    else
  579. X        n = 1;
  580. X    if( arg4[0] == '\0' || strcmp(arg4,"update")==0 )
  581. X        col1 = UPDATEWINDOWS;
  582. X    else
  583. X        col1 = NOUPDATE;
  584. X    n = RegexSearch( w, n, arg1, col1, linesOverFind );
  585. X    sprintf( textBuffer, "%d", n );
  586. X    ret_string = textBuffer;
  587. X    Tcl_SetResult( interp, ret_string, TCL_STATIC );
  588. X    break;
  589. X
  590. case FCTAG:
  591. X    findCTag( arg1 );
  592. X    break;
  593. X
  594. case FREPEATSEARCH:
  595. X    if( arg2[0] != '\0' )
  596. X        w = FindWindowByTkName( arg2 );
  597. X    if( w == NULL ) {
  598. X        printf("FREPEATSEARCH: window %s not found\n", arg2);
  599. X        break;
  600. X    }
  601. X    (void)searchFor( w, (striccmp(arg1,"backward")==0), NULL, 1,
  602. X                            linesOverFind );
  603. X    break;
  604. X
  605. case FREPLACE:
  606. X    if( arg4[0] != '\0' )
  607. X        w = FindWindowByTkName( arg4 );
  608. X    if( w == NULL ) {
  609. X        printf("FREPLACE: window %s not found\n", arg4);
  610. X        break;
  611. X    }
  612. X    if( arg3[0] == '\0' || striccmp(arg3,"inselection")!=0 )
  613. X        n = 0;
  614. X    else 
  615. X        n = 1;
  616. X    replaceText( w, arg1, arg2, n );
  617. X    break;
  618. X
  619. case FREGEXREPLACEONE:
  620. X    if( arg4[0] != '\0' )
  621. X        w = FindWindowByTkName( arg4 );
  622. X    if( w == NULL ) {
  623. X        printf("FREPLACE: window %s not found\n", arg4);
  624. X        break;
  625. X    }
  626. X    if(  striccmp(arg3,"one")!=0 ) {
  627. X        n = RegexReplaceOne( w, arg1, arg2 );
  628. X        sprintf( textBuffer, "%d", n );
  629. X        ret_string = textBuffer;
  630. X        Tcl_SetResult( interp, ret_string, TCL_STATIC );
  631. X        break;
  632. X    }
  633. X    break;
  634. X
  635. case FREGEXREPLACEALL:
  636. X    if( arg3[0] == '\0' || striccmp(arg3,"inselection")!=0 )
  637. X        n = 0;
  638. X    else 
  639. X        n = 1;
  640. X    RegexReplaceAll( w, arg1, arg2, n );
  641. X    break;
  642. X
  643. case FMATCHCHAR:    /* find the matching character */
  644. X    matchChar();
  645. X    break;
  646. X
  647. X#define SEARCH_LETTER_BUFFER_SIZE    80
  648. X
  649. case FSEARCHLETTER:
  650. X{
  651. X    static char searchString[SEARCH_LETTER_BUFFER_SIZE];
  652. X    static int searchStringIndex = 0;
  653. X    static int searchMode = 0;
  654. X    char ch;
  655. X
  656. X    if( arg3[0] != '\0' )
  657. X        w = FindWindowByTkName( arg3 );
  658. X    if( w == NULL ) {
  659. X        printf("FSEARCHLETTER: window %s not found\n", arg3);
  660. X        break;
  661. X    }
  662. X    (void)Tcl_GetInt( interp, arg1, &int1 );
  663. X    if( int1 <= 127 ) {
  664. X        ch = (char)int1;
  665. X        (void)Tcl_GetInt( interp, arg2, &int2 );
  666. X        if( int2 & ControlMask )
  667. X            ch &= 0x1f;
  668. X    } else {
  669. X        int1 &= 0xff;
  670. X        /* ignore shift keys */
  671. X        if( 0xe1 <= int1 && int1 <= 0xee )
  672. X            return ret_string;
  673. X        ch = '\0';
  674. X    }
  675. X    if( ch == '\0' ) {
  676. X        searchStringIndex = 0;
  677. X        searchMode = 0;
  678. X        break;
  679. X    } else if( ch == '\b' || ch == '\177' ) {
  680. X        if( searchStringIndex > 0 )
  681. X            --searchStringIndex;
  682. X        else
  683. X            searchMode = 1;
  684. X        break;
  685. X    }
  686. X    /* start over on overflows */
  687. X    if( searchStringIndex >= SEARCH_LETTER_BUFFER_SIZE )
  688. X        searchStringIndex = 0;
  689. X    searchString[searchStringIndex++] = ch;
  690. X    if( w != NULL ) {
  691. X        /* terminate and copy string into the search buffer */
  692. X        searchString[searchStringIndex] = '\0';
  693. X        if( searchStringIndex > 1 )
  694. X            /* we want to find this string again if it matches */
  695. X            /* with the additional letter added */
  696. X            --selBegin;
  697. X        (void)searchFor( w, searchMode, searchString, 1,
  698. X                            linesOverFind );
  699. X    }
  700. X    break;
  701. X}
  702. X
  703. X/************************** TEXT CHANGING COMMANDS *************************/
  704. case FINSASCII:
  705. X    Tcl_GetInt( interp, arg1, &n );
  706. X    insChar( (unsigned char)n, 1 );
  707. X    break;
  708. X
  709. case FINSERT:
  710. X    if( arg1[0] == '\0' || strcmp(arg1,"update")==0 )
  711. X        n = UPDATEWINDOWS;
  712. X    else
  713. X        n = NOUPDATE;
  714. X    if( selWindow == NULL )
  715. X        break;
  716. X    insScrap( 1, n );
  717. X    break;
  718. X
  719. case FCHANGECASE: {
  720. X    int wasChanged;
  721. X    Offset sEnd = selEnd;    /* since selEnd will change in the loop */
  722. X    int row, col, fid, n;
  723. X    int how;
  724. X    Offset beginCp;
  725. X
  726. X    if( selWindow == NULL )
  727. X        break;
  728. X    if( arg1[0] == '\0' || striccmp(arg1,"toggle")==0 )
  729. X        how = 2;
  730. X    else if( striccmp(arg1,"tolower")==0 )
  731. X        how = 1;
  732. X    else
  733. X        how =0;
  734. X    fid = selWindow->fileId;
  735. X    while( selBegin <= sEnd ) {
  736. X        ch = (char)getFileByte( fid, selBegin );
  737. X        if( !isalpha(ch) ) {
  738. X            /* pass over the character if it is not alpha */
  739. X            goto redrawSelection;
  740. X        }
  741. X        wasChanged = 0;
  742. X        if( isupper(ch) && how != 0 ) {
  743. X            ch = tolower(ch);
  744. X            wasChanged = 1;
  745. X        } else if( islower(ch) && how != 1 ) {
  746. X            ch = toupper(ch);
  747. X            wasChanged = 1;
  748. X        }
  749. X        if( wasChanged ) {
  750. X            saveSelBegin = selEnd = selBegin;
  751. X            (void)deleteChars(selWindow->fileId, NOUPDATE, 0);
  752. X            selEnd = selBegin = saveSelBegin;
  753. X            insChar( ch, 1 );
  754. X        } else {
  755. X    redrawSelection:
  756. X            n = -1;
  757. X            beginCp = prevLine( selWindow->fileId, selBegin, &n );
  758. X            OffsetToXY( selWindow, ++selBegin, &row, &col );
  759. X            selEnd = selBegin;
  760. X            DrawSection( selWindow, beginCp, row, col-1, row, col );
  761. X        }
  762. X    }
  763. X    selEnd = selBegin;
  764. X    break;
  765. X}
  766. X
  767. case FJUSTIFY:
  768. X    if( w == NULL )
  769. X        break;
  770. X    justifyLines();
  771. X    break;
  772. X
  773. case FDELETE:
  774. X    if( arg1[0] == '\0' || strcmp(arg1,"update")==0 )
  775. X        n = UPDATEWINDOWS;
  776. X    else
  777. X        n = NOUPDATE;
  778. X    if( selWindow == NULL )
  779. X        break;
  780. X    (void)deleteChars(selWindow->fileId, n, 1);
  781. X    break;
  782. X
  783. case FEXCHSCRAP:
  784. X    if( selWindow == NULL )
  785. X        break;
  786. X    exchWithScrap();
  787. X    break;
  788. X
  789. case FCOPYSCRAP:
  790. X    if( selWindow == NULL )
  791. X        break;
  792. X    copyToScrap(selWindow, selBegin, selEnd);
  793. X    msg("The selection has been copied to the scrap buffer", 1);
  794. X    break;
  795. X
  796. case FCOPYTO:    /* copy selection to this point */
  797. X    n = COPY;
  798. X    goto moveAndCopy;
  799. X
  800. case FMOVETO:    /* move selection to this point */
  801. X    n = MOVE;
  802. moveAndCopy:
  803. X    if( w == NULL )
  804. X        break;
  805. X    /* adjust to the selection mode */
  806. X    cp = mm_cp;    /* hidden parameter from userInput */
  807. X    /* adjustSelMode always uses selWindow so we have to fool it */
  808. X    /* be setting selWindow before the call and resetting it after */
  809. X    saveSelWindow = selWindow;
  810. X    selWindow = w;
  811. X    cp = adjustSelMode( cp );
  812. X    selWindow = saveSelWindow;
  813. X    drawSelection( 1 );
  814. X    copyMove(selWindow, selBegin, selEnd, w, cp, n);
  815. X    break;
  816. X
  817. case FCOPYFROM:
  818. X    if( selWindow == NULL )
  819. X        break;
  820. X    if( copyPending ) {
  821. X        drawSelection( 1 );
  822. X        copyMove(selWindow, selBegin, selEnd, pendWindow, pendPosition,
  823. X                                    COPY);
  824. X        currentCursor = mainCursor;
  825. X        XDefineCursor(MainDisplay, selWindow->x_window_id,
  826. X                                currentCursor);
  827. X        copyPending = 0;
  828. X    } else {
  829. X        XDefineCursor( MainDisplay, selWindow->x_window_id, dupCursor);
  830. X        currentCursor = dupCursor;
  831. X        copyPending = 1;
  832. X        pendWindow = selWindow;
  833. X        pendPosition = selBegin;
  834. X    }
  835. X    break;
  836. X
  837. case FMOVEFROM:
  838. X    if( selWindow == NULL )
  839. X        break;
  840. X    if( movePending ) {
  841. X        copyMove(selWindow, selBegin, selEnd, pendWindow, pendPosition,
  842. X                                    MOVE);
  843. X        movePending = 0;
  844. X        msg( NULL, 0 );
  845. X    } else {
  846. X        msg("Extract mode", 4);
  847. X        movePending = 1;
  848. X        pendWindow = selWindow;
  849. X        pendPosition = selBegin;
  850. X    }
  851. X    break;
  852. X
  853. case FREDO:
  854. X    if( arg2[0] != '\0' )
  855. X        w = FindWindowByTkName( arg2 );
  856. X    if( w == NULL ) {
  857. X        printf("FREDO: window %s not found\n", arg1);
  858. X        break;
  859. X    }
  860. X    if( arg1[0] != '\0' )
  861. X        (void)Tcl_GetInt( interp, arg1, &int1 );
  862. X    else
  863. X        int1 = 1;
  864. X    redo( &files[w->fileId], int1 );
  865. X    break;
  866. X
  867. case FAGAIN:
  868. X    n = 1;
  869. X    if( arg1[0] != '\0' ) {
  870. X        if( striccmp(arg1,"thisfile")==0 )
  871. X            n = 0;
  872. X        else
  873. X            w = FindWindowByTkName( arg1 );
  874. X    }
  875. X    if( w == NULL ) {
  876. X        printf("FAGAIN: window %s not found\n", arg1);
  877. X        break;
  878. X    }
  879. X    again( &files[w->fileId], n );
  880. X    break;
  881. X
  882. case FUNDO:
  883. X    if( arg2[0] != '\0' )
  884. X        w = FindWindowByTkName( arg2 );
  885. X    if( w == NULL ) {
  886. X        printf("FUNDO: window %s not found\n", arg1);
  887. X        break;
  888. X    }
  889. X    ff = &files[w->fileId];
  890. X    if( arg1[0] != '\0' ) {
  891. X        last_change = GetCurrentChange( ff );
  892. X        if( strcmp(arg1,"end")==0 ) {
  893. X            last_change->flags |= BLOCK_UNDO_END;
  894. X            break;
  895. X        } else if( strcmp(arg1,"begin")==0 ) {
  896. X            last_change->flags |= BLOCK_UNDO_BEGIN;
  897. X            break;
  898. X        } else if( strcmp(arg1,"update")==0 ) {
  899. X            UpdateUndoList( ff );
  900. X            break;
  901. X        } else
  902. X            (void)Tcl_GetInt( interp, arg1, &int1 );
  903. X    } else
  904. X        int1 = 1;
  905. X    undo( ff, int1 );
  906. X    break;
  907. X
  908. X/************************** FILE POSITIONING COMMANDS ***********************/
  909. case FBOTFILE:
  910. X    if( arg1[0] != '\0' )
  911. X        w = FindWindowByTkName( arg1 );
  912. X    if( w == NULL ) {
  913. X        printf("FBOTFILE: window %s not found\n", arg1);
  914. X        break;
  915. X    }
  916. X    bottomFile(w);
  917. X    break;
  918. X
  919. case FGOTOSELECTION:
  920. X    if( w == NULL )
  921. X        break;
  922. X    doGoSel(w);
  923. X    break;
  924. X
  925. case FGOBACKTO:
  926. X    if( arg1[0] != '\0' )
  927. X        w = FindWindowByTkName( arg1 );
  928. X    if( w == NULL ) {
  929. X        printf("FGOBACKTO: window %s not found\n", arg1);
  930. X        break;
  931. X    }
  932. X    doGoto( w, w->rowLastline, 0 );
  933. X    break;
  934. X
  935. case FGOTOLINE:
  936. X    if( arg3[0] != '\0' )
  937. X        w = FindWindowByTkName( arg3 );
  938. X    if( w == NULL ) {
  939. X        printf("FGOTOLINE: window %s not found\n", arg3);
  940. X        break;
  941. X    }
  942. X    if( arg1[0] == '\0' )
  943. X        int1 = 1;
  944. X    else
  945. X        (void)Tcl_GetInt( interp, arg1, &int1 );
  946. X    if( arg2[0] == '\0' || striccmp(arg2,"lof")==0 )
  947. X        int2 = 1;
  948. X    else
  949. X        int2 = 0;
  950. X    doGoto( w, int1, int2 );
  951. X    break;
  952. X
  953. case FGOTODIGIT:
  954. X{
  955. X    static int lineNumber = 0;
  956. X    if( arg2[0] != '\0' )
  957. X        w = FindWindowByTkName( arg2 );
  958. X    if( w == NULL ) {
  959. X        printf("FGOTODIGIT: window %s not found\n", arg2);
  960. X        break;
  961. X    }
  962. X    if( arg1[0] != '\0' && isdigit( arg1[0] ) )
  963. X        lineNumber = 10*lineNumber + arg1[0] - '0';
  964. X    else {
  965. X        doGoto( w, lineNumber, 1 );
  966. X        lineNumber = 0;
  967. X    }
  968. X    break;
  969. X}
  970. X
  971. case FMOVESEL:
  972. X    int3 = 0;
  973. X    saveSelBegin = -1;
  974. X    if( arg3[0] == '\0' || strcmp(arg3,"update")==0 )
  975. X        int3 = 1;
  976. X    else if (strcmp(arg3,"nosel")==0 ) {
  977. X        saveSelBegin = selBegin;
  978. X        saveSelEnd = selEnd;
  979. X    }
  980. X    (void)cursor( arg1, arg2, int3 );
  981. X    if( saveSelBegin >= 0 ) {
  982. X        selBegin = saveSelBegin;
  983. X        selEnd = saveSelEnd;
  984. X    }
  985. X    sprintf( msgBuffer, "%d", selBegin );
  986. X    Tcl_SetResult( interp, msgBuffer, TCL_STATIC );
  987. X    break;
  988. X
  989. X/************************ WINDOW MANAGEMENT COMMANDS ***********************/
  990. case FSETTEXTCOLOR:
  991. X    if( arg4[0] != '\0' )
  992. X        w = FindWindowByTkName( arg4 );
  993. X    if( w == NULL ) {
  994. X        printf("FSETTEXTCOLOR: window %s not found\n", arg4);
  995. X        break;
  996. X    }
  997. X    if( arg2[0] == '\0' || striccmp(arg2,"normal")==0 )
  998. X        int2 = 1;
  999. X    else
  1000. X        int2 = 0;
  1001. X    if( arg3[0] == '\0' || striccmp(arg3,"foreground")==0 )
  1002. X        int3 = 1;
  1003. X    else
  1004. X        int3 = 0;
  1005. X    SetTextColor( w, int2, int3, arg1 );
  1006. X    drawWindow( w );
  1007. X    break;
  1008. X
  1009. case FBROWSER:
  1010. X    if( arg2[0] != '\0' && striccmp(arg2,"small")==0 )
  1011. X        n = 0;
  1012. X    else
  1013. X        n = 1;
  1014. X    CreateNewBrowser( n, arg1 );
  1015. X    ret_string = activeBrowser->tk_pathname;
  1016. X    Tcl_SetResult( interp, ret_string, TCL_STATIC );
  1017. X    break;
  1018. X
  1019. case FWINDOWFONT:
  1020. X    if( arg2[0] != '\0' )
  1021. X        w = FindWindowByTkName( arg2 );
  1022. X    if( w == NULL ) {
  1023. X        printf("FWINDOWFONT: window %s not found\n", arg2);
  1024. X        break;
  1025. X    }
  1026. X    if( arg1[0] == '\0' )
  1027. X        arg1 = textFont;
  1028. X    /* copy it into the window's font name */
  1029. X    PtFree( w->font.name );
  1030. X    w->font.name = PtMalloc(strlen(arg1)+1, "font name");
  1031. X    strcpy(w->font.name, arg1);
  1032. X    /* indicate that the font is not yet loaded */
  1033. X    w->font.height = 0;
  1034. X    /* redraw the window with the new font */
  1035. X    WorkspaceResized( w );
  1036. X    XClearWindow( MainDisplay, w->x_window_id );
  1037. X    drawWindow( w );
  1038. X    break;
  1039. X
  1040. case FBROWSERFONT:
  1041. X    if( arg1[0] == '\0' )
  1042. X        arg1 = browserFont;
  1043. X    ChangeBrowserFontTo( activeBrowser, arg1 );
  1044. X    /* redraw the file list */
  1045. X    NewFilelist( activeBrowser );
  1046. X    break;
  1047. X
  1048. case FLOWER:
  1049. X    if( arg1[0] != '\0' )
  1050. X        w = FindWindowByTkName( arg1 );
  1051. X    if( w == NULL ) {
  1052. X        printf("FLOWER: window %s not found\n", arg1);
  1053. X        break;
  1054. X    }
  1055. X    XLowerWindow( MainDisplay, Tk_WindowId(w->tk_toplevel) );
  1056. X    break;
  1057. X
  1058. case FRAISE:
  1059. X    if( arg1[0] != '\0' )
  1060. X        w = FindWindowByTkName( arg1 );
  1061. X    if( w == NULL ) {
  1062. X        printf("FRAISE: window %s not found\n", arg1);
  1063. X        break;
  1064. X    }
  1065. X    XRaiseWindow( MainDisplay, Tk_WindowId(w->tk_toplevel) );
  1066. X    break;
  1067. X
  1068. case FCD:
  1069. X    if( arg1[0] == '\0' )
  1070. X        arg1 = "~";
  1071. X    n = chdir( Tcl_TildeSubst(interp,arg1) );
  1072. X    (void)ExecTclCommand( "if [file exists .ptdirrc] {source .ptdirrc}" );
  1073. X    if( n == -1 ) {
  1074. X        extern int errno;
  1075. X        extern int sys_nerr;
  1076. X        extern char *sys_errlist[];
  1077. X        if( errno < sys_nerr )
  1078. X            fileName = sys_errlist[errno];
  1079. X        else
  1080. X            fileName = "";
  1081. X        sprintf( msgBuffer, "Change directory failed: %s", fileName );
  1082. X        msg( msgBuffer , 1 );
  1083. X    }
  1084. X    NewFilelist( activeBrowser );
  1085. X    break;
  1086. X
  1087. case FOPENWINDOW:
  1088. X    if( arg1[0] == '\0' )
  1089. X        arg1 = "NoFileName";
  1090. X    FixName( arg1 );
  1091. X    if( arg2[0] == '\0' )
  1092. X        arg2 = textGeometry;
  1093. X    w = GetNewFile( NULL, arg1, arg2 );
  1094. X    if( w != NULL )
  1095. X        ret_string = w->tk_pathname;
  1096. X    else
  1097. X        ret_string = "";
  1098. X    Tcl_SetResult( interp, ret_string, TCL_STATIC );
  1099. X    break;
  1100. X
  1101. case FCLOSEWINDOW:
  1102. X    if( arg2[0] != '\0' )
  1103. X        w = FindWindowByTkName( arg2 );
  1104. X    if( w == NULL ) {
  1105. X#ifdef DEBUG_UPDATE
  1106. X        printf("FCLOSEWINDOW: window %s not found\n", arg2);
  1107. X#endif
  1108. X        break;
  1109. X    }
  1110. X    if( arg1[0] == '\0' || striccmp(arg1,"ask")==0 )
  1111. X        n = 1;
  1112. X    else if( striccmp(arg1,"nosave")==0 )
  1113. X        n = 2;
  1114. X    else
  1115. X        n = 0;
  1116. X    if( w == NULL )
  1117. X        break;
  1118. X    (void)closeWindow(w, n);
  1119. X    break;
  1120. X
  1121. case FRAISELISTWINDOW:
  1122. X    if( arg2 == NULL || arg2[0] == '\0' )
  1123. X        arg2 = textGeometry;
  1124. X    (void)Tcl_GetInt( interp, arg1, &int1 );
  1125. X    RaiseListWindow( int1, arg2 );
  1126. X    break;
  1127. X
  1128. case FCLOSEBROWSER: {    /* close the active browser */
  1129. X    BrowserData *browser = browserList;
  1130. X    BrowserData *prev_browser, *next_browser;
  1131. X    
  1132. X    /* find activeBrowser on the browser list */
  1133. X    while( browser != activeBrowser && browser != NULL )
  1134. X        browser = browser->nextBrowser;
  1135. X    if( browser == NULL ) {
  1136. X        printf("ERROR: activeBrowser not on browserList\n");
  1137. X        return ret_string;
  1138. X    }
  1139. X    /* do not allow the toplevel window to be deleted */
  1140. X    if( browser == mainBrowser ) {
  1141. X        msg( "Cannot close the main browser window", 1 );
  1142. X        break;
  1143. X    }
  1144. X
  1145. X    /* reduce the use count for this FileListData */
  1146. X    ReduceUseCount( browser->fileListData );
  1147. X
  1148. X    /* unlink browser from the list of browsers */
  1149. X    prev_browser = browser->prevBrowser;
  1150. X    next_browser = browser->nextBrowser;
  1151. X    if( prev_browser == NULL ) {
  1152. X        /* activeBrowser is first in the browserList */
  1153. X        if( next_browser == NULL ) {
  1154. X            /* deleting last browser -- do not allow this */
  1155. X            msg("Cannot delete the last browser", 1);
  1156. X            return ret_string;
  1157. X        } else {
  1158. X            /* terminate chain and fix up activeBrowser */
  1159. X            next_browser->prevBrowser = NULL;
  1160. X            activeBrowser = next_browser;
  1161. X            browserList = next_browser;
  1162. X        }
  1163. X    } else {
  1164. X        prev_browser->nextBrowser = next_browser;
  1165. X        if( next_browser != NULL )
  1166. X            next_browser->prevBrowser = prev_browser;
  1167. X        activeBrowser = prev_browser;
  1168. X        /* browserList points to a previous browser so its okay */
  1169. X    }
  1170. X    Tk_DestroyWindow( browser->tk_toplevel );
  1171. X    PtFree( (char *)browser );
  1172. X    break;
  1173. X}
  1174. X
  1175. X
  1176. case FWRITEFILE:
  1177. X    if( arg1[0] != '\0' )
  1178. X        w = FindWindowByTkName( arg1 );
  1179. X    if( w == NULL ) {
  1180. X        printf("FWRITEFILE: window %s not found\n", arg1);
  1181. X        break;
  1182. X    }
  1183. X    writeFile( w );
  1184. X    break;
  1185. X
  1186. case FSAVEFILE:
  1187. X    if( arg1[0] != '\0' )
  1188. X        w = FindWindowByTkName( arg1 );
  1189. X    if( w == NULL ) {
  1190. X        printf("FSAVEFILE: window %s not found\n", arg1);
  1191. X        break;
  1192. X    }
  1193. X    saveFile(w);
  1194. X    break;
  1195. X
  1196. case FSAVEALL:
  1197. X    w2 = windowList;
  1198. X    while( w2 != NULL ) {
  1199. X        if( files[w2->fileId].flags & IS_CHANGED )
  1200. X            saveFile(w2);
  1201. X        w2 = w2->nextWindow;
  1202. X    }
  1203. X    timeOfLastSave = time(NULL);
  1204. X    break;
  1205. X
  1206. case FZOOM:
  1207. X    if( arg1[0] != '\0' )
  1208. X        w = FindWindowByTkName( arg1 );
  1209. X    if( w == NULL ) {
  1210. X        printf("FZOOM: window %s not found\n", arg1);
  1211. X        break;
  1212. X    }
  1213. X    if( arg2[0] == '\0' || strcmp(arg2,"vertical")== 0 )
  1214. X        n = 0;
  1215. X    else
  1216. X        n = 1;
  1217. X    ZoomWindow( w, n );
  1218. X    break;
  1219. X
  1220. X/****************************** OTHER COMMANDS *****************************/
  1221. case FREADONLY:
  1222. X    if( arg1[0] != '\0' )
  1223. X        w = FindWindowByTkName( arg1 );
  1224. X    if( w == NULL ) {
  1225. X        printf("FREADONLY: window %s not found\n", arg1);
  1226. X        break;
  1227. X    }
  1228. X    if( files[w->fileId].flags & READ_ONLY ) {
  1229. X        /* file is readOnly now.  Only allow writing if the */
  1230. X        /* file being edited has DOS write permission */
  1231. X        /* check for read and write permissions (6 => RW) */
  1232. X        if( access(files[w->fileId].origName, 6) == 0 )
  1233. X            files[w->fileId].flags &= ~READ_ONLY;
  1234. X    } else
  1235. X        /* allow any file to be readOnly */
  1236. X        files[w->fileId].flags |= READ_ONLY;
  1237. X    break;
  1238. X
  1239. case FLINENUMBERS:
  1240. X    if( arg1[0] != '\0' )
  1241. X        w = FindWindowByTkName( arg1 );
  1242. X    if( w == NULL ) {
  1243. X        printf("FLINENUMBERS: window %s not found\n", arg1);
  1244. X        break;
  1245. X    }
  1246. X    switch( arg2[0] ) {
  1247. X    case '1':
  1248. X        w->lineNumbers = 1;
  1249. X        break;
  1250. X    case '0':
  1251. X        w->lineNumbers = 0;
  1252. X        break;
  1253. X    default:
  1254. X        w->lineNumbers = !(w->lineNumbers);
  1255. X        break;
  1256. X    }
  1257. X    drawWindow( w );
  1258. X    break;
  1259. X
  1260. case FCANCEL:
  1261. X    if( copyPending ) {
  1262. X        currentCursor = mainCursor;
  1263. X        XDefineCursor(MainDisplay, selWindow->x_window_id,
  1264. X                                currentCursor);
  1265. X        copyPending = 0;
  1266. X    }
  1267. X    if( movePending ) {
  1268. X        movePending = 0;
  1269. X        msg(NULL, 0);
  1270. X    }
  1271. X    break;
  1272. X
  1273. case FOPTION:
  1274. X    if( striccmp(arg1,"set")==0 ) {
  1275. X        SetPointOption( arg2, arg3 );
  1276. X    } else {
  1277. X        ret_string = GetPointOption( arg2 );
  1278. X        Tcl_SetResult( interp, ret_string, TCL_STATIC );
  1279. X    }
  1280. X    break;
  1281. X
  1282. case FINFORMONCLOSE:
  1283. X    w = FindWindowByTkName( arg1 );
  1284. X    if( w == NULL ) {
  1285. X        printf("FINFORMONCLOSE: window %s not found\n", arg1);
  1286. X        break;
  1287. X    }
  1288. X    n = strlen( arg2 ) + strlen( arg3 ) + 2;
  1289. X    w->closeInform = (char *)PtMalloc( n, "string" );
  1290. X    sprintf( w->closeInform, "%s %s", arg2, arg3 );
  1291. X    break;
  1292. X
  1293. X
  1294. case FQUITPOINT:
  1295. X    /* first see if any files have changed */
  1296. X    w2 = windowList;
  1297. X    while(  w2 != NULL ) {
  1298. X        /* see if the file has been edited */
  1299. X        if( files[w2->fileId].flags & IS_CHANGED )
  1300. X            goto areChanges;
  1301. X        w2 = w2->nextWindow;
  1302. X    }
  1303. X    /* no changes, so quit */
  1304. X    goto exitPoint;
  1305. X
  1306. areChanges:
  1307. X        if( arg1[0] == '\0' || striccmp(arg1,"ask")==0 )
  1308. X                n = 1;
  1309. X    if( striccmp(arg1,"save")==0 )
  1310. X        n = 0;
  1311. X    else
  1312. X        n = 2;
  1313. X    while( windowList != NULL ) {
  1314. X        ret = closeWindow( windowList, n );
  1315. X        if( ret == -1 ) {
  1316. X            msg("Window close failed, quit cancelled", 1);
  1317. X            break;
  1318. X        }
  1319. X    }
  1320. X    /* closeWindow removes a window from windowList and sets */
  1321. X    /* windowList to NULL when it is empty -- therefor */
  1322. X    /* this look really will terminate */
  1323. X
  1324. exitPoint:
  1325. X#ifdef HYPERTEXT
  1326. X       if( hypertextOn )
  1327. X        CloseHypertext();
  1328. X#endif
  1329. X    /* TCL/TK CLEANUP */
  1330. X    Tk_DestroyWindow( TkMainWindow );
  1331. X    Tcl_DeleteInterp( interp );
  1332. X    exit( 0 );
  1333. X    break;
  1334. X
  1335. case FREDRAW:
  1336. X    if( arg1[0] != '\0' )
  1337. X        w = FindWindowByTkName( arg1 );
  1338. X    if( w == NULL ) {
  1339. X        printf("FREDRAW: window %s not found\n", arg1);
  1340. X        break;
  1341. X    }
  1342. X    drawWindow( w );
  1343. X    break;
  1344. X
  1345. case FDONOTHING:
  1346. X    break;
  1347. X
  1348. case FSHOWUNDOS:
  1349. X    if( w == NULL )
  1350. X        break;
  1351. X    ShowUndos( &files[w->fileId] );
  1352. X    break;
  1353. X
  1354. case FPRINTSTATS:
  1355. X    PrintStats( 1 );
  1356. X    break;
  1357. X
  1358. X#ifdef HYPERTEXT
  1359. case FADDFILETODOCUMENT:
  1360. X    AddFileToDocument( w );
  1361. X    sprintf(msgBuffer, "Added file %s into an Anasazi document %s",
  1362. X        &(files[w->fileId].origName[w->nameOffset]),
  1363. X        w->document->name);
  1364. X    msg( msgBuffer, 1 );
  1365. X/***** debug output *****/
  1366. printf( "%s\n", msgBuffer );
  1367. printf("file is %s (%d)\nblock is %s (%d)\nmap is %s (%d)\nview is %s (%d)\n",
  1368. w->file->name, w->file->this_one, w->block->name, w->block->this_one,
  1369. w->blockMap->name, w->blockMap->this_one, w->view->name, w->view->this_one);
  1370. X/***** debug output *****/
  1371. X    drawWindow( w );
  1372. X    break;
  1373. X
  1374. case FCREATEDOCUMENT:
  1375. X    break;
  1376. X
  1377. case FCREATEBLOCK:
  1378. X{
  1379. X    Block block;
  1380. X    AttributeID attrID = PickAttribute( w->document,
  1381. X            "Pick attribute for the new block" );
  1382. X
  1383. X    if( attrID != NullObject ) {
  1384. X        extern struct openFile *files;
  1385. X        int fid;
  1386. X        struct openFile *ff;
  1387. X        Attribute attribute;
  1388. X
  1389. X        block = CreateBlock( w->db, w->document, "block",
  1390. X                        attrID, 0, NullObject );
  1391. X/***** debug output *****/
  1392. attribute = GetAttribute( currentDB, attrID, NO_ALLOCATE);
  1393. printf("Created block %s (block ID=%d) with attribute %s (attribute ID=%d)\n",
  1394. block->name, block->this_one, attribute->name, attribute->this_one);
  1395. X/***** debug output *****/
  1396. X
  1397. X        drawSelection( 1 );    /* erase the selection */
  1398. X
  1399. X        fid = w->fileId;
  1400. X        ff = &files[fid];
  1401. X
  1402. X        /* convert selBegin and selEnd to the underlying (real) file */
  1403. X        ret = GetRealSelection( ff, 0/*get both selBegin and selEnd*/);
  1404. X
  1405. X        /* free the piece list of the old view */
  1406. X        FreeOldViewPieces( ff );
  1407. X
  1408. X        /* insert the new block into the real file */
  1409. X        w->fileId = w->realFileId;
  1410. X        (void)InsertBlock( block->this_one );
  1411. X
  1412. X        /* create a new piece table for the view */
  1413. X        w->fileId = CreateViewFile( w );
  1414. X
  1415. X        /* free the block structure since we are done with it */
  1416. X        PtFree( (char *)block );
  1417. X        drawWindow( w );
  1418. X    }
  1419. X    break;
  1420. X}
  1421. X
  1422. case FCREATEATTRIBUTE:
  1423. X{
  1424. X    Attribute attribute;
  1425. X
  1426. X    sprintf( msgBuffer, "MakeModalEntry {%s} {%s} {%s} {%s}",
  1427. X        "Create Attribute", "Name of attribute to create",
  1428. X        "Create attribute", "Cancel" );
  1429. X    (void)ExecTclCommand( msgBuffer );
  1430. X    command( FWAITFORRETURNSTRING, "", "", "", "", "", "" );
  1431. X    if( strcmp(returnString,"XXXcancelXXX") != 0 ) {
  1432. X        attribute = CreateAttribute( currentDB, currentDocument,
  1433. X                        returnString );
  1434. X/***** debug output *****/
  1435. printf("Created attribute %s with ID=%d\n",attribute->name,attribute->this_one);
  1436. X/***** debug output *****/
  1437. X        PtFree( (char *)attribute );
  1438. X    }
  1439. X    break;
  1440. X}
  1441. X
  1442. case FCREATEMAP:
  1443. X{
  1444. X    Map map;
  1445. X    char *s, *box_name;
  1446. X    PickListItem * itemList, *item;
  1447. X
  1448. X    sprintf( msgBuffer, "MakeModalEntry {%s} {%s} {%s} {%s}",
  1449. X        "Create Map", "Name of map to create",
  1450. X        "Create map", "Cancel" );
  1451. X    (void)ExecTclCommand( msgBuffer );
  1452. X    command( FWAITFORRETURNSTRING, "", "", "", "", "", "" );
  1453. X    if( strcmp(returnString,"XXXcancelXXX") != 0 ) {
  1454. X        map = CreateMap( currentDB, currentDocument, returnString );
  1455. X/***** debug output *****/
  1456. printf("Created map %s with ID=%d\n",map->name,map->this_one);
  1457. X/***** debug output *****/
  1458. X        /* get the list of items */
  1459. X        itemList = GenerateIDList( currentDocument->firstAttribute,
  1460. X            AttributeMagic );
  1461. X        sprintf( msgBuffer, "MakeMapBox" );
  1462. X        s = ExecTclCommand( msgBuffer );
  1463. X        /* make a copy of the name */
  1464. X        box_name = (char *)PtMalloc( strlen(s)+1, "name" );
  1465. X        strcpy( box_name, s );
  1466. X        /* fill the list box */
  1467. X        item = itemList;
  1468. X        while( itemList != NULL ) {
  1469. X            sprintf( msgBuffer, "%s.alist.items insert end {%s}",
  1470. X                        box_name, item->name );
  1471. X            (void)ExecTclCommand( msgBuffer );
  1472. X            item = item->next;
  1473. X        }
  1474. X        PtFree( (char *)box_name );
  1475. X
  1476. X        command( FWAITFORRETURNSTRING, "", "", "", "", "", "" );
  1477. X        if( strcmp(returnString,"XXXcancelXXX") != 0 ) {
  1478. X            int i, n, b[MAP_SIZE];
  1479. X            Attribute attribute;
  1480. X            for( i = 0; i < MAP_SIZE; ++i )
  1481. X                b[i] = 0;
  1482. X            n = sscanf( returnString, "%d %d %d %d %d",
  1483. X                &b[0], &b[1], &b[2], &b[3], &b[4]);
  1484. X/***** debug output *****/
  1485. printf("This map will show block types:\n");
  1486. for( i = 0; i < n; ++i ) {
  1487. X    attribute = GetAttribute( currentDB, (ID)b[i], NO_ALLOCATE );
  1488. X    if( attribute == NULL )
  1489. X        printf("Attribute ID %d is invalid\n", b[i]);
  1490. X    else {
  1491. X        printf("\t%s (%d)\n", attribute->name, b[i]);
  1492. X        map->domain[i] = b[i];
  1493. X    }
  1494. X}
  1495. printf("\n");
  1496. X/***** debug output *****/
  1497. X            PutMap( currentDB, map, 0 );
  1498. X        }
  1499. X        PtFree( (char *)map );
  1500. X        FreeIDList( itemList );
  1501. X    }
  1502. X    break;
  1503. X}
  1504. X
  1505. case FCREATELINK:
  1506. X    DumpTables();
  1507. X    break;
  1508. X
  1509. case FCREATEVIEW:
  1510. X    break;
  1511. X
  1512. case FCHANGEMAP:
  1513. X{
  1514. X    Map map;
  1515. X    int i;
  1516. X    MapID mapID = PickMap( w->document, "Pick map to change to" );
  1517. X
  1518. X    if( mapID != NullObject ) {
  1519. X        /* get the map */
  1520. X        map = GetMap( currentDB, mapID, ALLOCATE );
  1521. X        if( map == NULL ) {
  1522. X            printf("Map ID %d not found\n", mapID );
  1523. X            break;
  1524. X        }
  1525. X
  1526. X        /* free the old map (if any) and install the new one */
  1527. X        PtFree( (char *)(w->blockMap) );
  1528. X        w->blockMap = map;
  1529. X
  1530. X        printf("Current map will show block types:\n");
  1531. X        for( i = 0; i < MAP_SIZE && map->domain[i]!=NullObject; ++i ) {
  1532. X            Attribute attribute;
  1533. X            attribute = GetAttribute( currentDB,
  1534. X                        map->domain[i], NO_ALLOCATE );
  1535. X            if( attribute == NULL )
  1536. X                printf("Attribute ID %d is invalid\n",
  1537. X                        map->domain[i]);
  1538. X            else
  1539. X                printf("\t%s (%d)\n", attribute->name,
  1540. X                        attribute->this_one);
  1541. X        }
  1542. X
  1543. X        /* free the piece list of the old view */
  1544. X        FreeOldViewPieces( &(files[w->fileId]) );
  1545. X
  1546. X        /* create a piece table for the new view */
  1547. X        w->fileId = CreateViewFile( w );
  1548. X
  1549. X        drawWindow( w );
  1550. X    }
  1551. X    break;
  1552. X}
  1553. X
  1554. case FSHOWATTRIBUTES:
  1555. X{
  1556. X    AttributeID attributeID;
  1557. X    Attribute attribute;
  1558. X
  1559. X/***** debug output *****/
  1560. attributeID = currentDocument->firstAttribute;
  1561. printf("\n*** List of all defined attributes ***\n");
  1562. while( attributeID != NullObject ) {
  1563. X    attribute = GetAttribute( currentDB, attributeID, NO_ALLOCATE );
  1564. X    printf("%s (%d)\n", attribute->name, attribute->this_one );
  1565. X    attributeID = attribute->next;
  1566. X}
  1567. X/***** debug output *****/
  1568. X    attributeID = PickAttribute( currentDocument, "Show attributes" );
  1569. X    break;
  1570. X}
  1571. X
  1572. case FSHOWBLOCKS:
  1573. X{
  1574. X    BlockID blockID;
  1575. X    Block block;
  1576. X    int i;
  1577. X
  1578. X/***** debug output *****/
  1579. blockID = currentDocument->firstBlock;
  1580. printf("\n*** List of all defined blocks ***\n");
  1581. while( blockID != NullObject ) {
  1582. X    block = GetBlock( currentDB, blockID, NO_ALLOCATE );
  1583. X    printf("%s (%d) fileID=%d @ %d, attributes:",
  1584. X        block->name, block->this_one, block->file, block->hint );
  1585. X    for( i = 0; i < MAX_ATTRIBUTES; ++i ) {
  1586. X        if( block->attribute[i] == NullObject )
  1587. X            break;
  1588. X        printf(" %d", block->attribute[i]);
  1589. X    }
  1590. X    printf("\n");
  1591. X    blockID = block->next;
  1592. X}
  1593. X/***** debug output *****/
  1594. X    blockID = PickBlock( currentDocument, "Show blocks" );
  1595. X    break;
  1596. X}
  1597. X
  1598. case FSHOWDOCUMENTS:
  1599. X    printf("\n*** The current document ***\n");
  1600. X    printf("%s (%d), next free=%d, initial view=%d\n",
  1601. X        currentDocument->name, currentDocument->this_one,
  1602. X        currentDocument->nextFreeID, currentDocument->initialView );
  1603. X    break;
  1604. X
  1605. case FSHOWFILES:
  1606. X{
  1607. X    FileID fileID;
  1608. X    File file;
  1609. X
  1610. X/***** debug output *****/
  1611. fileID = currentDocument->firstFile;
  1612. printf("\n*** List of all defined files ***\n");
  1613. while( fileID != NullObject ) {
  1614. X    file = GetFile( currentDB, fileID, NO_ALLOCATE );
  1615. X    printf("%s (%d)\n", file->name, file->this_one );
  1616. X    fileID = file->next;
  1617. X}
  1618. X/***** debug output *****/
  1619. X/***** debug output *****/
  1620. X    fileID = PickFile( currentDocument, "Show files" );
  1621. X    break;
  1622. X}
  1623. X
  1624. case FSHOWLINKS:
  1625. X{    LinkID linkID;
  1626. X    Link link;
  1627. X    int i;
  1628. X
  1629. X/***** debug output *****/
  1630. linkID = currentDocument->firstLink;
  1631. printf("\n*** List of all defined links ***\n");
  1632. while( linkID != NullObject ) {
  1633. X    link = GetLink( currentDB, linkID, NO_ALLOCATE );
  1634. X    printf("%s (%d) fromID=%d toID=%d, attributes:",
  1635. X        link->name, link->this_one, link->from, link->to );
  1636. X    for( i = 0; i < MAX_ATTRIBUTES; ++i ) {
  1637. X        if( link->attribute[i] == NullObject )
  1638. X            break;
  1639. X        printf(" %d", link->attribute[i]);
  1640. X    }
  1641. X    printf("\n");
  1642. X    linkID = link->next;
  1643. X}
  1644. X/***** debug output *****/
  1645. X    linkID = PickLink( currentDocument, "Show links" );
  1646. X    break;
  1647. X}
  1648. X
  1649. case FSHOWMAPS:
  1650. X{
  1651. X    MapID mapID;
  1652. X    Map map;
  1653. X
  1654. X/***** debug output *****/
  1655. mapID = currentDocument->firstMap;
  1656. printf("\n*** List of all defined maps ***\n");
  1657. while( mapID != NullObject ) {
  1658. X    int i;
  1659. X    map = GetMap( currentDB, mapID, ALLOCATE );
  1660. X    printf("%s (%d)\n", map->name, map->this_one );
  1661. X    for( i = 0; i < MAP_SIZE && map->domain[i]!=NullObject; ++i ) {
  1662. X        Attribute attribute;
  1663. X        attribute = GetAttribute( currentDB, map->domain[i],
  1664. X                                NO_ALLOCATE );
  1665. X        if( attribute == NULL )
  1666. X            printf("Attribute ID %d is invalid\n",
  1667. X                    map->domain[i]);
  1668. X        else
  1669. X            printf("\t%s (%d)\n", attribute->name,
  1670. X                    attribute->this_one);
  1671. X    }
  1672. X    mapID = map->next;
  1673. X    PtFree( (char *)map );
  1674. X}
  1675. X/***** debug output *****/
  1676. X    mapID = PickMap( currentDocument, "Show maps" );
  1677. X    break;
  1678. X}
  1679. X
  1680. case FSHOWTEXTS:
  1681. X{
  1682. X    TextID textID;
  1683. X    Text text;
  1684. X
  1685. X/***** debug output *****/
  1686. textID = currentDocument->firstText;
  1687. printf("\n*** List of all defined texts ***\n");
  1688. while( textID != NullObject ) {
  1689. X    text = GetText( currentDB, textID, NO_ALLOCATE );
  1690. X    printf("%s (%d)\n", text->s, text->this_one );
  1691. X    textID = text->next;
  1692. X}
  1693. X/***** debug output *****/
  1694. X    textID = PickText( currentDocument, "Show texts" );
  1695. X    break;
  1696. X}
  1697. X
  1698. case FSHOWVIEWS:
  1699. X{    ViewID viewID;
  1700. X    View view;
  1701. X
  1702. X/***** debug output *****/
  1703. viewID = currentDocument->firstView;
  1704. printf("\n*** List of all defined views ***\n");
  1705. while( viewID != NullObject ) {
  1706. X    view = GetView( currentDB, viewID, NO_ALLOCATE );
  1707. X    printf("%s (%d), block=%d, fromLinkMap=%d, toLinkMap=%d, blockMap=%d\n",
  1708. X        view->name, view->this_one, view->blockID,
  1709. X        view->fromLinkMap, view->toLinkMap,
  1710. X        view->blockMap );
  1711. X    viewID = view->next;
  1712. X}
  1713. X/***** debug output *****/
  1714. X    viewID = PickView( currentDocument, "Show views" );
  1715. X    break;
  1716. X}
  1717. X#endif
  1718. X
  1719. default:
  1720. X    sprintf(msgBuffer, "No action is defined for command %d", fn);
  1721. X    msg(msgBuffer, 1);
  1722. X    break;
  1723. X}
  1724. lastFn = fn;
  1725. if( fn != FDONOTHING && fn > 0 ) 
  1726. X    lastCommand = fn;
  1727. X
  1728. return ret_string;
  1729. X}
  1730. X
  1731. END_OF_FILE
  1732. if test 40012 -ne `wc -c <'command.c'`; then
  1733.     echo shar: \"'command.c'\" unpacked with wrong size!
  1734. fi
  1735. # end of 'command.c'
  1736. fi
  1737. echo shar: End of archive 12 \(of 15\).
  1738. cp /dev/null ark12isdone
  1739. MISSING=""
  1740. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
  1741.     if test ! -f ark${I}isdone ; then
  1742.     MISSING="${MISSING} ${I}"
  1743.     fi
  1744. done
  1745. if test "${MISSING}" = "" ; then
  1746.     echo You have unpacked all 15 archives.
  1747.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1748. else
  1749.     echo You still need to unpack the following archives:
  1750.     echo "        " ${MISSING}
  1751. fi
  1752. ##  End of shell archive.
  1753. exit 0
  1754. -- 
  1755. --
  1756. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  1757. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  1758. Sunnyvale, California 94086            at&t: 408/522-9236
  1759.