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

  1. Newsgroups: comp.sources.x
  2. Path: uunet!wupost!zaphod.mps.ohio-state.edu!mips!msi!dcmartin
  3. From: crowley@chaco.cs.unm.edu (Charlie Crowley)
  4. Subject: v17i009: point text editor (TCL and TK), Part08/16
  5. Message-ID: <1992Mar18.141518.26956@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:15:18 GMT
  11. Approved: dcmartin@msi.com
  12.  
  13. Submitted-by: crowley@chaco.cs.unm.edu (Charlie Crowley)
  14. Posting-number: Volume 17, Issue 9
  15. Archive-name: tcl-editor/part08
  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 7 (of 15)."
  24. # Contents:  fileio.c funcdecl.h windows.c
  25. # Wrapped by crowley@chaco.cs.unm.edu on Tue Mar 10 15:05:42 1992
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'fileio.c' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'fileio.c'\"
  29. else
  30. echo shar: Extracting \"'fileio.c'\" \(18995 characters\)
  31. sed "s/^X//" >'fileio.c' <<'END_OF_FILE'
  32. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/fileio.c,v 1.9 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 <sys/types.h>
  38. X#include <sys/stat.h>
  39. X#include <sys/file.h>
  40. X#ifdef uts
  41. X#include <fcntl.h>
  42. X#endif /* uts */
  43. X#include "pt.h"
  44. X
  45. X/* the open files */
  46. struct openFile *files;
  47. X
  48. extern struct diskBuffer *buffers;
  49. extern struct diskBuffer *bufHash[];
  50. extern nextBuffer;
  51. X
  52. void
  53. initFileio()
  54. X{
  55. X    extern char msgBuffer[];
  56. X    extern Piece freePList;
  57. X    extern struct piece pieceTable[];
  58. X    extern char *bufferSpace;
  59. X    extern int nBuffers;
  60. X    extern unsigned int piecesLeft;
  61. X    extern unsigned int bytesLeft;
  62. X    extern int maxFiles;
  63. X    extern int debug;
  64. X    
  65. X    register int i;
  66. X    unsigned int size;
  67. X    unsigned char *bs;
  68. X
  69. X    for(i = 0; i < maxFiles; i++) {
  70. X        files[i].origHandle = -1;
  71. X    }
  72. X
  73. X    /* set up the buffer hash scheme */
  74. X    for(i = 0; i < NBUFHASH; i++)
  75. X        bufHash[i] = NULL;
  76. X    nextBuffer = -1;
  77. X
  78. X    /* allocate the space (out of this address space) for the buffers */
  79. retryAllocation:
  80. X    size = BUFFERSIZE * nBuffers;
  81. X    bs = (unsigned char *)PtMalloc(size, "IO buffer");
  82. X    if( bs == NULL ) {
  83. X        /* if there is not enough space, try fewer buffers */
  84. X        if( nBuffers >= 25 ) {
  85. X            nBuffers -= 20;
  86. X            goto retryAllocation;
  87. X        }
  88. X        size -= 16*i;
  89. X        printf(
  90. X            "NOT ENOUGH MEMORY! (%u bytes short) Use fewer buffers\n",
  91. X            size);
  92. X        exit(1);
  93. X    }
  94. X
  95. X    /* set up each buffer header to the address of the */
  96. X    /* allocated buffer. Buffer i is at buffers[i].bufferAddress  */
  97. X    for(i = 0; i < nBuffers; i++) {
  98. X        buffers[i].handle = -1;
  99. X        buffers[i].bufferAddress = bs;
  100. X        bs += BUFFERSIZE;
  101. X    }
  102. X    
  103. X    /* set up the free piece list */
  104. X    freePList = NULL;
  105. X    piecesLeft = 0;
  106. X}
  107. X
  108. static void
  109. InitCommandHistory( ff )
  110. X    struct openFile *ff;
  111. X{
  112. X    /* initialize the command history */
  113. X    ff->cmdHistory = (struct changeItem *)
  114. X            PtMalloc( sizeof(struct changeItem), "change item" );
  115. X    ff->cmdHistory->type = CNULL;
  116. X
  117. X    /* be SURE that this change is not used */
  118. X    ff->cmdHistory->flags = CHANGE_WAS_UNDONE
  119. X                | FILE_WAS_CLOSED
  120. X                | BLOCK_UNDO_BEGIN;
  121. X
  122. X    /* make this the only item in the command history list */
  123. X    ff->cmdHistory->prev = NULL;
  124. X    ff->cmdHistory->next = NULL;
  125. X}
  126. X
  127. int
  128. getFileId(origName)
  129. X    char *origName;
  130. X{
  131. X    extern char msgBuffer[];
  132. X    extern char scratchFileName[];
  133. X    extern int addHandle;
  134. X    extern int readOnly;
  135. X    extern int maxFiles;
  136. X    extern int trace_file;
  137. X
  138. X    int fileNumber, origHandle;
  139. X    int freeFileId;
  140. X    Offset size;
  141. X    Piece pp;
  142. X    struct openFile *ff;
  143. X    char *fullFilename;
  144. X
  145. X    if( origName == NULL ) {
  146. X        scratchFileName[0] = '\0';
  147. X        fullFilename = &scratchFileName[0];
  148. X    } else
  149. X        fullFilename = makeFullPathname(origName);
  150. X
  151. X    /* find a free file structure */
  152. X    freeFileId = -1;
  153. X    for(fileNumber = 0; fileNumber < maxFiles; fileNumber++) {
  154. X        if( files[fileNumber].origHandle == -1 ) {
  155. X            if( freeFileId == -1 )
  156. X                freeFileId = fileNumber;
  157. X        } else if(
  158. X            strcmp(files[fileNumber].origName, fullFilename)
  159. X                                == 0 ) {
  160. X            ++(files[fileNumber].useCount);
  161. X            return fileNumber;
  162. X        }
  163. X    }
  164. X    if( freeFileId == -1 ) {
  165. X        msg("openFile: out of file structures", 3);
  166. X        return -1;
  167. X    } else
  168. X        fileNumber = freeFileId;
  169. X
  170. X    /* open the original file */
  171. X    ff = &files[fileNumber];
  172. X    strncpy(ff->origName, fullFilename, FILENAMESIZE);
  173. X    
  174. X    if( fullFilename[0] == '\0' ) {
  175. X        origHandle = addHandle;
  176. X    } else {
  177. X        origHandle = open(fullFilename, O_RDONLY, 0);
  178. X
  179. X        if( origHandle < 0 ) {
  180. X            sprintf(msgBuffer, "Cannot open %s",
  181. X                fullFilename);
  182. X            msg(msgBuffer, 3);
  183. X            return -1;
  184. X        }
  185. X    }
  186. X    ff->origHandle = origHandle;
  187. X    if( trace_file > 0 ) {
  188. X        sprintf( msgBuffer, "# file id of %2d is file `%s'\n",
  189. X            fileNumber, fullFilename );
  190. X        write( trace_file, msgBuffer, strlen(msgBuffer) );
  191. X    }
  192. X
  193. X    /* initialize the other fields */
  194. X    if( origHandle != addHandle ) {
  195. X        size = lseek(origHandle, 0L, 2);
  196. X        lseek(origHandle, 0L, 0);
  197. X    } else
  198. X        size = 0;
  199. X    ff->fileSize = size;
  200. X    ff->origFileSize = size;
  201. X    ff->isView = 0;
  202. X    ff->useCount = 1;
  203. X    ff->flags = 0;
  204. X    if( readOnly )
  205. X        ff->flags |= READ_ONLY;
  206. X    else if( origHandle == addHandle ) {
  207. X        ff->flags &= ~READ_ONLY;
  208. X    } else {
  209. X        /* check for read and write permissions (6 => RW) */
  210. X        /* edit in readOnly mode if the UNIX file permissions */
  211. X        /* do not allow writing the file */
  212. X        if( access(ff->origName, R_OK | W_OK) == 0)
  213. X            ff->flags &= ~READ_ONLY;
  214. X        else
  215. X            ff->flags |= READ_ONLY;
  216. X    }
  217. X
  218. X    /* initialize the piece table */
  219. X    pp = getFreePiece();
  220. X    pp->file = origHandle;
  221. X    pp->position = 0;
  222. X    pp->length = size;
  223. X    ff->pieceList = pp;
  224. X
  225. X    InitCommandHistory( ff );
  226. X
  227. X    /* initialize the optimization fields */
  228. X    ff->loLogPiece = 0;
  229. X    ff->hiLogPiece = size - 1;
  230. X    ff->logPiece = pp;
  231. X    ff->hiLogBuffer = -1;
  232. X    ff->loLogBuffer = -1;
  233. X    ff->logBuf = NULL;
  234. X
  235. X    /*return the fileId */
  236. X    return fileNumber;
  237. X}
  238. X
  239. static void
  240. MakeBackups(ff, tempFile )
  241. X    struct openFile *ff;
  242. X    char *tempFile;
  243. X{
  244. X    extern int backupDepth;
  245. X    extern char *backupNameFormat;
  246. X    extern int backupByCopy;
  247. X    extern char msgBuffer[];
  248. X    extern char textBuffer[];
  249. X
  250. X    int i, version;
  251. X    char *end, *f, *p, *q;
  252. X    char ch;
  253. X
  254. if( !(ff->flags&BAK_MADE) && backupDepth > 0 ) {
  255. X    p = textBuffer;        /* create backup file name here */
  256. X    f = backupNameFormat;    /* printf-like name format */
  257. X    while( 1 ) {
  258. X        ch = *f++;
  259. X        if( ch == '\0' )
  260. X            break;
  261. X        if( ch != '%' ) {
  262. X            *p++ = ch;
  263. X            continue;
  264. X        }
  265. X        ch = *f++;
  266. X        switch( ch ) {
  267. X
  268. X        case 'n':    /* original file name */
  269. X            q = ff->origName;
  270. X            while( 1 ) {
  271. X                ch = *q++;
  272. X                if( ch == '\0' )
  273. X                    break;
  274. X                *p++ = ch;
  275. X            }
  276. X            break;
  277. X
  278. X        case 'b':    /* base name of original file */
  279. X            q = ff->origName;
  280. X            end = q + strlen(q) - 1;
  281. X            while( end > q && *end != '.' )
  282. X                --end;
  283. X            if( end == q )
  284. X                end = q + strlen(q);
  285. X            while( q < end )
  286. X                *p++ = *q++;
  287. X            break;
  288. X
  289. X        case 'v':    /* version number -- must be 1 to 9 */
  290. X            version = p - textBuffer;
  291. X            *p++ = '0';    /* placeholder */
  292. X            break;
  293. X        default:
  294. X            *p++ = ch;
  295. X            break;
  296. X        }
  297. X    }
  298. X    *p = '\0';
  299. X    /* if file p does not exist, this will return an error code but */
  300. X    /* is is cheaper just to do it than to ask if it exists first */
  301. X    /* delete the last backup */
  302. X    (void)unlink( textBuffer );
  303. X    strcpy( msgBuffer, textBuffer );
  304. X    /* move all the other existing backups down one slot */
  305. X    for(i = backupDepth - 1; i > 0; --i ) {
  306. X        textBuffer[version] = i + '0';
  307. X        msgBuffer[version] = i + 1 + '0';
  308. X        (void)rename( textBuffer, msgBuffer );
  309. X    }
  310. X#ifdef LATERLATER
  311. X    if( backupByCopy ) {
  312. X        sprintf( msgBuffer, "cp %s %s", ff->origName, textBuffer );
  313. X        (void)system(msgBuffer);
  314. X        /* OR
  315. X        Tcl_VarExec( mainBrowser->interp, "copy ", ff->origName,
  316. X                            textBuffer, NULL );
  317. X        */
  318. X    } else
  319. X#endif
  320. X        (void)rename(ff->origName, textBuffer);
  321. X    ff->flags |= BAK_MADE;
  322. X} else {
  323. X    if( unlink(ff->origName) ) {
  324. X        strcpy( textBuffer, ff->origName );
  325. X        p = tildefyFilename( textBuffer );
  326. X        sprintf(msgBuffer,
  327. X            "Delete of old version of %s failed; new version in %s",
  328. X            p, tempFile );
  329. X        msg(msgBuffer, 3);
  330. X    }
  331. X}
  332. if( rename(tempFile, ff->origName) ) {
  333. X    strcpy( textBuffer, ff->origName );
  334. X    p = tildefyFilename( textBuffer );
  335. X    sprintf(msgBuffer,
  336. X        "Rename of %s [new version] to %s [old version] failed",
  337. X        tempFile,p, textBuffer, tempFile );
  338. X    msg(msgBuffer, 3);
  339. X}
  340. X}
  341. X
  342. static void
  343. XFreeCommandHistory( ff )
  344. X    struct openFile *ff;
  345. X{
  346. X    struct changeItem * change, * change_to_free;
  347. X
  348. X    /* first find the end of the list */
  349. X    change = ff->cmdHistory;
  350. X    if( change == NULL )
  351. X        /* this should not happen */
  352. X        return;
  353. X    while( change->next != NULL )
  354. X        change = change->next;
  355. X
  356. X    /* now walk down the chain and free each one */
  357. X    while( change != NULL ) {
  358. X        change_to_free = change;
  359. X        change = change->prev;
  360. X        PtFree( (char *)change_to_free );
  361. X    }
  362. X    /* just to be neat */
  363. X    ff->cmdHistory = NULL;
  364. X}
  365. X
  366. void
  367. saveFile(w)
  368. X    struct window *w;
  369. X{
  370. X    extern char msgBuffer[];
  371. X    extern char textBuffer[];
  372. X    extern struct openFile *files;
  373. X    extern int addHandle;
  374. X    extern int hypertextOn;
  375. X
  376. X    struct openFile *ff;
  377. X    char *p, *tempFile;
  378. X    int i;
  379. X    int fid;
  380. X    Offset size;
  381. X    Piece pp;
  382. X    struct stat statbuf;
  383. X
  384. X#ifdef HYPERTEXT
  385. X    if( hypertextOn && w->document != NULL )
  386. X        fid = w->realFileId;
  387. X    else
  388. X#endif
  389. X        fid = w->fileId;
  390. X    ff = &files[fid];
  391. X    
  392. X    /* Do not save if the file is read only */
  393. X    if( ff->flags & READ_ONLY ) {
  394. X        strcpy( textBuffer, ff->origName );
  395. X        p = tildefyFilename( textBuffer );
  396. X        sprintf( msgBuffer, "File %s is read only", p );
  397. X        msg(msgBuffer, 3);
  398. X        return;
  399. X    }
  400. X
  401. X    /* get a temporary name and write the new version of the file to it */
  402. X    tempFile = makeTempFor(ff->origName);
  403. X    strcpy( textBuffer, ff->origName );
  404. X    p = tildefyFilename( textBuffer );
  405. X    sprintf(msgBuffer, "Writing file %s [%ld bytes]...", p, ff->fileSize);
  406. X    msg(msgBuffer, 1);
  407. X
  408. X    if( !doWrite( fid, tempFile ) )
  409. X        return;
  410. X
  411. X    /* change the permissions on the new file to match the old one */
  412. X    i = stat( ff->origName, &statbuf );
  413. X    if( i != 0 ) {
  414. X        printf("Stat of %s failed\n", ff->origName);
  415. X    } else {
  416. X        chown( tempFile, statbuf.st_uid, statbuf.st_gid );
  417. X        chmod( tempFile, statbuf.st_mode );
  418. X    }
  419. X
  420. X    /* write out the message telling the user the file was written */
  421. X    strcpy( textBuffer, ff->origName );
  422. X    p = tildefyFilename( textBuffer );
  423. X    sprintf(msgBuffer, "%s written...%ld bytes", p, ff->fileSize);
  424. X    msg(msgBuffer, 1);
  425. X
  426. X    /* invalidate any buffers allocated to this open file */
  427. X    fidInvalid(ff->origHandle, fid);
  428. X    ff->hiLogBuffer = -1;
  429. X    ff->loLogBuffer = -1;
  430. X
  431. X    /* reset the change flag */
  432. X    ff->flags &= ~IS_CHANGED;
  433. X    NewOpenList();
  434. X
  435. X    /* close the original file for this open file */
  436. X    if( ff->origHandle != addHandle ) {
  437. X        i = close(ff->origHandle);
  438. X        if( i != 0 ) {
  439. X            strcpy( textBuffer, ff->origName );
  440. X            tildefyFilename( textBuffer );
  441. X            p = (char *)sprintf(msgBuffer,
  442. X                    "saveFile: close of %s failed, ret=%d", p, i);
  443. X            msg(msgBuffer, 1);
  444. X        }
  445. X    }
  446. X
  447. X    /* for now free the command history */
  448. X    /* LATERLATER: fix things up so we can keep the command history */
  449. X    /* even over a save.  It is just a matter of changing the */
  450. X    /* file you consider the original file */
  451. X    FreeCommandHistory( ff );
  452. X    InitCommandHistory( ff );
  453. X
  454. X    MakeBackups( ff, tempFile );
  455. X
  456. X    /* open it up again */
  457. X    if( ff->origHandle != addHandle )
  458. X        ff->origHandle = open(ff->origName, O_RDONLY, 0644);
  459. X
  460. X    /* re-initialize the other fields */
  461. X    size = lseek(ff->origHandle, 0L, 2);
  462. X    ff->fileSize = size;
  463. X    ff->origFileSize = size;
  464. X    lseek(ff->origHandle, 0L, 0);
  465. X    
  466. X    /* free all the pieces */
  467. X    freePieces(ff->pieceList);
  468. X
  469. X    /* re-initialize the piece table */
  470. X    pp = getFreePiece();
  471. X    ff->pieceList = pp;
  472. X    pp->file = ff->origHandle;
  473. X    pp->position = 0;
  474. X    pp->length = size;
  475. X
  476. X    /* re-initialize the optimization fields */
  477. X    ff->loLogPiece = 0;
  478. X    ff->hiLogPiece = size - 1;
  479. X    ff->logPiece = pp;
  480. X    ff->hiLogBuffer = -1L;
  481. X    ff->loLogBuffer = -1L;
  482. X    ff->logBuf = NULL;
  483. X
  484. X    /* redraw the banner to remove the file modified `*' */
  485. X    banner( w, 0 );    /* 0 ==> don't redo the slider */
  486. X}
  487. X
  488. void
  489. writeFile(w)
  490. X    struct window *w;
  491. X{
  492. X    extern struct openFile *files;
  493. X    extern char msgBuffer[];
  494. X    extern char textBuffer[];
  495. X    extern char * returnString;
  496. X
  497. X    sprintf( msgBuffer,
  498. X"MakeModalEntry {Save As} {Filename to write to} {Okay} {Cancel write}");
  499. X    (void)ExecTclCommand( msgBuffer );
  500. X    command( FWAITFORRETURNSTRING, "", "", "", "", "", "" );
  501. X    if( strcmp(returnString,"XXXcancelXXX")==0 ) {
  502. X    cancel:
  503. X        msg("Write file cancelled", 1);
  504. X        return;
  505. X    }
  506. X
  507. X    /* check if the file already exists */
  508. X    if( access(returnString, F_OK) == 0 ) {
  509. X        sprintf( msgBuffer,
  510. X            "MakeModalYesNo {%s} {%s %s %s} {%s} {%s}",
  511. X            "Write over file?",
  512. X            "File", returnString, "already exists.",
  513. X            "Write over it",
  514. X            "Cancel write" );
  515. X        (void)ExecTclCommand( textBuffer );
  516. X        command( FWAITFORRETURNSTRING, "", "", "", "", "", "" );
  517. X        if( returnString[0] != 'y' )
  518. X            goto cancel;
  519. X    }
  520. X
  521. X    sprintf(textBuffer, "Writing file %s [%ld bytes]...",
  522. X        msgBuffer, files[w->fileId].fileSize);
  523. X    msg(textBuffer, 1);
  524. X
  525. X    if( !doWrite(w->fileId, returnString) )
  526. X        return;
  527. X
  528. X    sprintf(textBuffer, "%s written...%ld bytes",
  529. X        returnString, files[w->fileId].fileSize);
  530. X    msg(textBuffer, 1);
  531. X}
  532. X
  533. int
  534. doWrite(fileId, tempFile)
  535. X    int fileId;
  536. X    char *tempFile;
  537. X{
  538. X    extern char msgBuffer[];
  539. X    extern int getSpanSize;
  540. X
  541. X    Offset cp, fSize;
  542. X    int fid, iBuffer, lineSize;
  543. X    unsigned char *firstByte;
  544. X    unsigned char *lastByte;
  545. X    unsigned char *sBuffer;
  546. X    unsigned int sizeOfBuffer;
  547. X
  548. fSize = fileSize(fileId);
  549. X
  550. X/* open the output file */
  551. fid = open(tempFile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
  552. if( fid < 0 ) {
  553. X    perror("Create temp file");
  554. X    sprintf( msgBuffer, "Could not create %s, ret=%d", tempFile, fid );
  555. X    msg(msgBuffer, 1);
  556. X    return 0;
  557. X}
  558. X
  559. X/* allocate the IO buffer */
  560. sizeOfBuffer = 8192;
  561. while( 1 ) {
  562. X    sBuffer = (unsigned char *)PtMalloc(sizeOfBuffer, "output buffer");
  563. X    if( sBuffer == NULL ) {
  564. X        extern char textBuffer[];
  565. X        /* try again with a buffer half as large */
  566. X        sizeOfBuffer >>= 1;
  567. X        if( sizeOfBuffer <= MSGBUFFERSIZE ) {
  568. X            sBuffer = (unsigned char *)textBuffer;
  569. X            break;
  570. X        }
  571. X        continue;
  572. X    } else
  573. X        break;
  574. X}
  575. X
  576. cp = 0;
  577. iBuffer = 0;
  578. while( 1 ) {
  579. X    /* special case for files of length 0 */
  580. X    if( fSize == 0 )
  581. X        fSize = 1;
  582. X    sprintf(msgBuffer, "File is %d%% written out",
  583. X        (int)( (100*cp) / fSize) );
  584. X    msg(msgBuffer, 0);
  585. X    if( getSpan(fileId, cp, &firstByte, &lastByte, 0) )
  586. X        break;
  587. X    lineSize = (int)(lastByte - firstByte + 1);
  588. getSpanSize += lineSize;
  589. X    cp = cp + lineSize;
  590. X
  591. X    if( (iBuffer+lineSize) > sizeOfBuffer ) {/* will it fit? */
  592. X        /* no, so write out the buffer to empty it */
  593. X        int writeRet = write(fid, sBuffer, iBuffer);
  594. X        if( writeRet < iBuffer ) {
  595. error:
  596. X            perror("write to temp file");
  597. X            PtFree((char *)sBuffer);
  598. X            /* avoid recursive calls if msg tries to write disk */
  599. printf("doWrite: trying to write %d bytes but only wrote %d bytes\n",
  600. X                iBuffer, writeRet);
  601. X            close(fid);
  602. X            unlink(tempFile);
  603. X            return 0;
  604. X        } else
  605. X            iBuffer = 0;
  606. X    }
  607. X    /* move lineSize bytes from firstByte to sBuffer+iBuffer */
  608. X    bcopy( firstByte, sBuffer + iBuffer, lineSize );
  609. X    iBuffer += lineSize;
  610. X}
  611. if( write(fid, sBuffer, iBuffer) < iBuffer )
  612. X    goto error;
  613. close(fid);
  614. X
  615. X/* all is ok */
  616. PtFree((char *)sBuffer);
  617. return 1;
  618. X}
  619. X
  620. char *
  621. makeTempFor(name)
  622. X    char *name;
  623. X{
  624. X    static char tname[64];
  625. X    register int len;
  626. X    int pathEnd;
  627. X    char ch;
  628. X
  629. X    len = 0;
  630. X    pathEnd = -1;
  631. X    while( 1 ) {
  632. X        if( (ch = name[len]) == '\0' )
  633. X            break;
  634. X        tname[len] = ch;
  635. X        switch( ch ) {
  636. X        case '/':
  637. X            pathEnd = len;
  638. X        }
  639. X        ++len;
  640. X    }
  641. X    tname[pathEnd+1] = '\0';
  642. X    strcat(tname, "tempfile.pt");
  643. X    return &tname[0];
  644. X}
  645. X
  646. char *
  647. noWhiteSpace(fileName)
  648. X    register char *fileName;
  649. X{
  650. X    register int n;
  651. X
  652. X    if( fileName != NULL || fileName[0] == '\0' ) {
  653. X        /* eliminate white space around fileName */
  654. X
  655. X        /* first white space in the beginning */
  656. X        while( isspace(*fileName) )
  657. X            ++fileName;
  658. X
  659. X        /* now white space at the end */
  660. X        n = strlen(fileName) - 1;
  661. X        while( isspace(fileName[n]) )
  662. X            --n;
  663. X        fileName[n+1] = '\0';
  664. X    }
  665. X    return fileName;
  666. X}
  667. X
  668. int
  669. makeName(s)
  670. X    register char *s;
  671. X{
  672. X    register int l;
  673. X    int nTries;
  674. X    char ch;
  675. X
  676. X    /* try to create a new name by changing the last letter */
  677. X    l = strlen(s) - 1;
  678. X    nTries = 0;
  679. X    ch = s[l];    /* save first character */
  680. X    if( isupper(ch) )
  681. X        ch = tolower(ch);
  682. X    while( access(s, 0) == 0 ) {
  683. X        /* the file name exists so try another */
  684. X        ++nTries;
  685. X        if( s[l] == 'z' )
  686. X            s[l] = 'a';
  687. X        else
  688. X            ++s[l];
  689. X        if( s[l] == ch )
  690. X            return -1;    /* could not find an unused name */
  691. X    }
  692. X    return nTries;
  693. X}
  694. X
  695. int
  696. getBaseName(s)
  697. X    char *s;
  698. X{
  699. X    int n;
  700. X
  701. X    n = strlen(s) - 1;
  702. X    while( 1 ) {
  703. X        if( s[n] == '/' )
  704. X            break;
  705. X        if( --n < 0 )
  706. X            break;
  707. X    }
  708. X    return n+1;
  709. X}
  710. X
  711. Offset
  712. fileSize(fileNumber)
  713. X    int fileNumber;
  714. X{
  715. X    return files[fileNumber].fileSize;
  716. X}
  717. X
  718. int
  719. closeFile(fileId, ask)
  720. X    int fileId, ask;
  721. X{
  722. X    extern char msgBuffer[];
  723. X    extern char textBuffer[];
  724. X    extern struct changeItem scrapBuffer;
  725. X    extern int addHandle;
  726. X    extern int trace_file;
  727. X    extern char * returnString;
  728. X
  729. X    int i, writing;
  730. X    char *p, *tempFile;
  731. X    register struct openFile *ff;
  732. X
  733. X    if( fileId == -1 )
  734. X        return 0;
  735. X
  736. X    if( trace_file > 0 ) {
  737. X        sprintf( msgBuffer, "# close file id %2d\n", fileId );
  738. X        write( trace_file, msgBuffer, strlen(msgBuffer) );
  739. X    }
  740. X
  741. X    ff = &files[fileId];
  742. X
  743. X    /* check for 'files' that are really views */
  744. X    if( ff->isView )
  745. X        goto ViewOnly;
  746. X
  747. X    /* is this the last close? */
  748. X    if( --(ff->useCount) > 0 )
  749. X        return 0;
  750. X
  751. X    /* see if we need to write the file */
  752. X    writing = 1;
  753. X    /* has the file changed? */
  754. X    if( ff->pieceList->nextPiece == NULL
  755. X     && ff->pieceList->file == ff->origHandle ) {
  756. X        if( ff->fileSize == ff->origFileSize ) 
  757. X            writing = 0;
  758. X    }
  759. X    if( ask == 2 )    /* quit and discard mode */
  760. X        writing = 0;
  761. X    /* do not write the messages file into itself */
  762. X    if( ff->origHandle == addHandle )
  763. X        writing = 0;
  764. X    /* see if we already saved these changes */
  765. X    if( !(ff->flags & IS_CHANGED) )
  766. X        writing = 0;
  767. X    if( writing && (ff->flags & READ_ONLY) ) {
  768. X        strcpy( textBuffer, ff->origName );
  769. X        p = tildefyFilename( textBuffer );
  770. X        sprintf( msgBuffer,
  771. X            "MakeModalYesNo {%s} {%s %s %s} {%s} {%s}",
  772. X            "Read only file",
  773. X            "File", p, "is read only but changed.",
  774. X            "Close file without writing",
  775. X            "Cancel close" );
  776. X        (void)ExecTclCommand( textBuffer );
  777. X        command( FWAITFORRETURNSTRING, "", "", "", "", "", "" );
  778. X        if( returnString[0] != 'y' )
  779. X            return -1;
  780. X        writing = 0;
  781. X    }
  782. X    if( writing ) {
  783. X        /* verify the write if ask is true */
  784. X        if( ask ) {
  785. X            strcpy( textBuffer, ff->origName );
  786. X            p = tildefyFilename( textBuffer );
  787. X        sprintf( msgBuffer,
  788. X            "MakeModalYesNo {%s} {%s %s %s} {%s} {%s}",
  789. X            "Save file?",
  790. X            "Save file", p, "?",
  791. X            "Yes, save the changes",
  792. X            "No, discard changes" );
  793. X        (void)ExecTclCommand( textBuffer );
  794. X        command( FWAITFORRETURNSTRING, "", "", "", "", "", "" );
  795. X            writing = (returnString[0] -= 'y');
  796. X        }
  797. X        if( writing ) {
  798. X            tempFile = makeTempFor(ff->origName);
  799. X            strcpy( textBuffer, ff->origName );
  800. X            p = tildefyFilename( textBuffer );
  801. X            sprintf(msgBuffer, "Writing file %s [%ld bytes]...",
  802. X                p, ff->fileSize);
  803. X            msg(msgBuffer, 1);
  804. X            if( doWrite(fileId, tempFile) == 0 )
  805. X                return -1;
  806. X            strcpy( textBuffer, ff->origName );
  807. X            p = tildefyFilename( textBuffer );
  808. X            sprintf(msgBuffer, "%s written...%ld bytes",
  809. X                p, ff->fileSize);
  810. X            msg(msgBuffer, 1);
  811. X        }
  812. X    }
  813. X
  814. X    /* do the close */
  815. X    if( ff->origHandle == -1 ) {
  816. X        strcpy( textBuffer, ff->origName );
  817. X        p = tildefyFilename( textBuffer );
  818. X        sprintf(msgBuffer, "closeFile: file %s is not open", p);
  819. X        msg(msgBuffer, 1);
  820. X        return 0;
  821. X    }
  822. X    
  823. X    /* see if the scrap points into this file */
  824. X    if( ff->origHandle == scrapBuffer.fileId && scrapBuffer.type == 0 )
  825. X        /* this call only copies the scrap text to the add file */
  826. X        /* it does not really do any insert (just using the code) */
  827. X        insScrap( 0, 0 );
  828. X
  829. X    /* invalidate any buffers allocated to this open file */
  830. X    if( ff->origHandle != addHandle )
  831. X        fidInvalid(ff->origHandle, fileId);
  832. X        
  833. X    /* free the command history items */
  834. X    FreeCommandHistory( ff );
  835. X    
  836. X    /* close the original file for this open file */
  837. X    if( ff->origHandle != addHandle ) {
  838. X        i = close(ff->origHandle);
  839. X        if( i != 0 ) {
  840. X            strcpy( textBuffer, ff->origName );
  841. X            p = tildefyFilename( textBuffer );
  842. X            sprintf(msgBuffer,
  843. X                "closeFile: close of %s failed, ret=%d", p, i);
  844. X            msg(msgBuffer, 1);
  845. X        }
  846. X    }
  847. X
  848. X    /* rename the saved file */
  849. X    if( writing == 1) {
  850. X        MakeBackups( ff, tempFile );
  851. X    }
  852. X
  853. ViewOnly:
  854. X    /* free all the pieces */
  855. X    freePieces(ff->pieceList);
  856. X
  857. X    /* indicate the file structure is free */
  858. X    ff->origHandle = -1;
  859. X
  860. X    return 0;    /* all ok */
  861. X}
  862. END_OF_FILE
  863. if test 18995 -ne `wc -c <'fileio.c'`; then
  864.     echo shar: \"'fileio.c'\" unpacked with wrong size!
  865. fi
  866. # end of 'fileio.c'
  867. fi
  868. if test -f 'funcdecl.h' -a "${1}" != "-c" ; then 
  869.   echo shar: Will not clobber existing file \"'funcdecl.h'\"
  870. else
  871. echo shar: Extracting \"'funcdecl.h'\" \(17878 characters\)
  872. sed "s/^X//" >'funcdecl.h' <<'END_OF_FILE'
  873. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/funcdecl.h,v 1.13 1992/03/04 17:07:18 crowley Exp crowley $ */
  874. X
  875. X#ifdef HYPERTEXT
  876. X/* in anaDialogs.c */
  877. PickListItem * GenerateIDList(
  878. X#ifdef ANSI_PROTOTYPES
  879. X    ID id_in, MagicNumber magic
  880. X#endif
  881. X);
  882. void FreeIDList(
  883. X#ifdef ANSI_PROTOTYPES
  884. X    PickListItem * itemList
  885. X#endif
  886. X);
  887. AttributeID PickAttribute(
  888. X#ifdef ANSI_PROTOTYPES
  889. Document, char *
  890. X#endif
  891. X);
  892. LinkID PickLink(
  893. X#ifdef ANSI_PROTOTYPES
  894. Document, char *
  895. X#endif
  896. X);
  897. BlockID PickBlock(
  898. X#ifdef ANSI_PROTOTYPES
  899. Document, char *
  900. X#endif
  901. X);
  902. XFileID PickFile(
  903. X#ifdef ANSI_PROTOTYPES
  904. Document, char *
  905. X#endif
  906. X);
  907. TextID PickText(
  908. X#ifdef ANSI_PROTOTYPES
  909. Document, char *
  910. X#endif
  911. X);
  912. MapID PickMap(
  913. X#ifdef ANSI_PROTOTYPES
  914. Document, char *
  915. X#endif
  916. X);
  917. ViewID PickView(
  918. X#ifdef ANSI_PROTOTYPES
  919. Document, char *
  920. X#endif
  921. X);
  922. X
  923. X/* in anaObjects.c */
  924. DBM * OpenObjects(
  925. X#ifdef ANSI_PROTOTYPES
  926. String
  927. X#endif
  928. X);
  929. void CloseObjects(
  930. X#ifdef ANSI_PROTOTYPES
  931. DBM *
  932. X#endif
  933. X);
  934. void DumpDB(
  935. X#ifdef ANSI_PROTOTYPES
  936. DBM *
  937. X#endif
  938. X);
  939. AnaObject GetObject(
  940. X#ifdef ANSI_PROTOTYPES
  941. DBM *, MagicNumber, ID, AllocationMode
  942. X#endif
  943. X);
  944. void PutObject(
  945. X#ifdef ANSI_PROTOTYPES
  946. DBM *, MagicNumber, AnaObject, ReleaseMode
  947. X#endif
  948. X);
  949. Block GetBlock(
  950. X#ifdef ANSI_PROTOTYPES
  951. DBM *, BlockID, AllocationMode
  952. X#endif
  953. X);
  954. void PutBlock(
  955. X#ifdef ANSI_PROTOTYPES
  956. DBM *, Block, ReleaseMode
  957. X#endif
  958. X);
  959. Attribute GetAttribute(
  960. X#ifdef ANSI_PROTOTYPES
  961. DBM *, AttributeID, AllocationMode
  962. X#endif
  963. X);
  964. void PutAttribute(
  965. X#ifdef ANSI_PROTOTYPES
  966. DBM *, Attribute, ReleaseMode
  967. X#endif
  968. X);
  969. Map GetMap(
  970. X#ifdef ANSI_PROTOTYPES
  971. DBM *, MapID, AllocationMode
  972. X#endif
  973. X);
  974. void PutMap(
  975. X#ifdef ANSI_PROTOTYPES
  976. DBM *, Map, ReleaseMode
  977. X#endif
  978. X);
  979. XFile GetFile(
  980. X#ifdef ANSI_PROTOTYPES
  981. DBM *, FileID, AllocationMode
  982. X#endif
  983. X);
  984. void PutFile(
  985. X#ifdef ANSI_PROTOTYPES
  986. DBM *, File, ReleaseMode
  987. X#endif
  988. X);
  989. Text GetText(
  990. X#ifdef ANSI_PROTOTYPES
  991. DBM *, TextID, AllocationMode
  992. X#endif
  993. X);
  994. void PutText(
  995. X#ifdef ANSI_PROTOTYPES
  996. DBM *, Text, ReleaseMode
  997. X#endif
  998. X);
  999. Link GetLink(
  1000. X#ifdef ANSI_PROTOTYPES
  1001. DBM *, LinkID, AllocationMode
  1002. X#endif
  1003. X);
  1004. void PutLink(
  1005. X#ifdef ANSI_PROTOTYPES
  1006. DBM *, Link, ReleaseMode
  1007. X#endif
  1008. X);
  1009. View GetView(
  1010. X#ifdef ANSI_PROTOTYPES
  1011. DBM *, ViewID, AllocationMode
  1012. X#endif
  1013. X);
  1014. void PutView(
  1015. X#ifdef ANSI_PROTOTYPES
  1016. DBM *, View, ReleaseMode
  1017. X#endif
  1018. X);
  1019. Document GetDocument(
  1020. X#ifdef ANSI_PROTOTYPES
  1021. DBM *, DocumentID, AllocationMode
  1022. X#endif
  1023. X);
  1024. void PutDocument(
  1025. X#ifdef ANSI_PROTOTYPES
  1026. DBM *, Document, ReleaseMode
  1027. X#endif
  1028. X);
  1029. Block CreateBlock(
  1030. X#ifdef ANSI_PROTOTYPES
  1031. DBM *, Document, char *, AttributeID, Offset, FileID
  1032. X#endif
  1033. X);
  1034. Attribute CreateAttribute(
  1035. X#ifdef ANSI_PROTOTYPES
  1036. DBM *, Document, char *
  1037. X#endif
  1038. X);
  1039. AttributeID LookupAttributeByName(
  1040. X#ifdef ANSI_PROTOTYPES
  1041. DBM *, Document, char *
  1042. X#endif
  1043. X);
  1044. Map CreateMap(
  1045. X#ifdef ANSI_PROTOTYPES
  1046. DBM *, Document, char *
  1047. X#endif
  1048. X);
  1049. MapID LookupMapByName(
  1050. X#ifdef ANSI_PROTOTYPES
  1051. DBM *, Document, char *
  1052. X#endif
  1053. X);
  1054. Link CreateLink(
  1055. X#ifdef ANSI_PROTOTYPES
  1056. DBM *, Document, char *, AttributeID, BlockID, BlockID
  1057. X#endif
  1058. X);
  1059. XFile CreateFile(
  1060. X#ifdef ANSI_PROTOTYPES
  1061. DBM *, Document document, char * name
  1062. X#endif
  1063. X);
  1064. XFileID LookupFileByName(
  1065. X#ifdef ANSI_PROTOTYPES
  1066. DBM * db, Document, char *
  1067. X#endif
  1068. X);
  1069. Text CreateText(
  1070. X#ifdef ANSI_PROTOTYPES
  1071. DBM *, Document, char *
  1072. X#endif
  1073. X);
  1074. View CreateView(
  1075. X#ifdef ANSI_PROTOTYPES
  1076. DBM *, Document, char *, BlockID, MapID, MapID, MapID
  1077. X#endif
  1078. X);
  1079. Document CreateDocument(
  1080. X#ifdef ANSI_PROTOTYPES
  1081. DBM *, char *
  1082. X#endif
  1083. X);
  1084. X
  1085. X/* in anaSources.c */
  1086. int GetRealSelection(
  1087. X#ifdef ANSI_PROTOTYPES
  1088. struct openFile *, int
  1089. X#endif
  1090. X);
  1091. void InitHypertext(
  1092. X#ifdef ANSI_PROTOTYPES
  1093. void
  1094. X#endif
  1095. X);
  1096. void CloseHypertext(
  1097. X#ifdef ANSI_PROTOTYPES
  1098. void
  1099. X#endif
  1100. X);
  1101. void DumpPieces(
  1102. X#ifdef ANSI_PROTOTYPES
  1103. struct window *w
  1104. X#endif
  1105. X);
  1106. void DumpRealPieces(
  1107. X#ifdef ANSI_PROTOTYPES
  1108. struct window *w
  1109. X#endif
  1110. X);
  1111. void DumpTables(
  1112. X#ifdef ANSI_PROTOTYPES
  1113. void
  1114. X#endif
  1115. X);
  1116. void PrintPieceChain(
  1117. X#ifdef ANSI_PROTOTYPES
  1118. char *, Piece
  1119. X#endif
  1120. X);
  1121. void SeparateBlockMarkers(
  1122. X#ifdef ANSI_PROTOTYPES
  1123. struct window *w
  1124. X#endif
  1125. X);
  1126. Offset ReadBlockMarker(
  1127. X#ifdef ANSI_PROTOTYPES
  1128. int fid, Offset pos, BlockID * blockID,    unsigned int * flags
  1129. X#endif
  1130. X);
  1131. Offset FindBlock(
  1132. X#ifdef ANSI_PROTOTYPES
  1133. BlockID blockID, int fid
  1134. X#endif
  1135. X);
  1136. Offset SkipToEndOfBlock(
  1137. X#ifdef ANSI_PROTOTYPES
  1138. int fid, Offset pos, BlockID endBlockID
  1139. X#endif
  1140. X);
  1141. void CreateViewPieceTable(
  1142. X#ifdef ANSI_PROTOTYPES
  1143. struct window *w, struct openFile *ff
  1144. X#endif
  1145. X);
  1146. Offset ProcessOneBlock(
  1147. X#ifdef ANSI_PROTOTYPES
  1148. BlockID blockID, struct window *, Offset offset, Piece *, Piece *
  1149. X#endif
  1150. X);
  1151. void CreateSpanPieces(
  1152. X#ifdef ANSI_PROTOTYPES
  1153. BlockID blockID, int fid, Offset begin, Offset end, Piece *, Piece *
  1154. X#endif
  1155. X);
  1156. Offset CreatePieceTableForBlock(
  1157. X#ifdef ANSI_PROTOTYPES
  1158. struct window *, Offset offset, Piece *, Piece *
  1159. X#endif
  1160. X);
  1161. void FreeOldViewPieces(
  1162. X#ifdef ANSI_PROTOTYPES
  1163. X    struct openFile *ff;
  1164. X#endif
  1165. X);
  1166. int CreateViewFile(
  1167. X#ifdef ANSI_PROTOTYPES
  1168. struct window *w
  1169. X#endif
  1170. X);
  1171. void AddFileToDocument(
  1172. X#ifdef ANSI_PROTOTYPES
  1173. struct window *w
  1174. X#endif
  1175. X);
  1176. int InsertBlock(
  1177. X#ifdef ANSI_PROTOTYPES
  1178. unsigned int n
  1179. X#endif
  1180. X);
  1181. X#endif
  1182. X
  1183. X/* in browser.c */
  1184. void ReduceUseCount(
  1185. X#ifdef ANSI_PROTOTYPES
  1186. XFileListData *
  1187. X#endif
  1188. X);
  1189. void ptBrowserLetter(
  1190. X#ifdef ANSI_PROTOTYPES
  1191. int, XKeyEvent *, String *, Cardinal *
  1192. X#endif
  1193. X);
  1194. void ChangeBrowserFontTo(
  1195. X#ifdef ANSI_PROTOTYPES
  1196. BrowserData *, char *
  1197. X#endif
  1198. X);
  1199. void RaiseListWindow(
  1200. X#ifdef ANSI_PROTOTYPES
  1201. int n, char * geometry
  1202. X#endif
  1203. X);
  1204. int listComp(
  1205. X#ifdef ANSI_PROTOTYPES
  1206. char *, char *
  1207. X#endif
  1208. X);
  1209. void NewFilelist(
  1210. X#ifdef ANSI_PROTOTYPES
  1211. BrowserData *
  1212. X#endif
  1213. X);
  1214. void CreateNewBrowser(
  1215. X#ifdef ANSI_PROTOTYPES
  1216. int, char * geometry
  1217. X#endif
  1218. X);
  1219. void NewOpenList(
  1220. X#ifdef ANSI_PROTOTYPES
  1221. void
  1222. X#endif
  1223. X);
  1224. void CreateBigBrowser(
  1225. X#ifdef ANSI_PROTOTYPES
  1226. BrowserData *, char * geometry
  1227. X#endif
  1228. X);
  1229. void CreateFilelist(
  1230. X#ifdef ANSI_PROTOTYPES
  1231. void
  1232. X#endif
  1233. X);
  1234. X
  1235. X/* in buffers.c */
  1236. void unlink1(
  1237. X#ifdef ANSI_PROTOTYPES
  1238. struct diskBuffer *
  1239. X#endif
  1240. X);
  1241. struct diskBuffer * getBuffer(
  1242. X#ifdef ANSI_PROTOTYPES
  1243. int, int
  1244. X#endif
  1245. X);
  1246. void fidInvalid(
  1247. X#ifdef ANSI_PROTOTYPES
  1248. int, int
  1249. X#endif
  1250. X);
  1251. int getFileByte(
  1252. X#ifdef ANSI_PROTOTYPES
  1253. int, Offset
  1254. X#endif
  1255. X);
  1256. void ClearByteCache(
  1257. X#ifdef ANSI_PROTOTYPES
  1258. void
  1259. X#endif
  1260. X);
  1261. int getCachedFileByte(
  1262. X#ifdef ANSI_PROTOTYPES
  1263. int, Offset
  1264. X#endif
  1265. X);
  1266. int getSpan(
  1267. X#ifdef ANSI_PROTOTYPES
  1268. int, Offset, unsigned char **, unsigned char **, int
  1269. X#endif
  1270. X);
  1271. void writeChar(
  1272. X#ifdef ANSI_PROTOTYPES
  1273. int, Offset
  1274. X#endif
  1275. X);
  1276. X
  1277. X/* in cmdTable.c */
  1278. int FindCommandInTable(
  1279. X#ifdef ANSI_PROTOTYPES
  1280. char *
  1281. X#endif
  1282. X);
  1283. int GetCommandNumber(
  1284. X#ifdef ANSI_PROTOTYPES
  1285. char *
  1286. X#endif
  1287. X);
  1288. char * CommandNumberToName(
  1289. X#ifdef ANSI_PROTOTYPES
  1290. int
  1291. X#endif
  1292. X);
  1293. void AddPointCommands(
  1294. X#ifdef ANSI_PROTOTYPES
  1295. Tcl_Interp *
  1296. X#endif
  1297. X);
  1298. X
  1299. X/* in command.c */
  1300. void ptSearchLetter(
  1301. X#ifdef ANSI_PROTOTYPES
  1302. int, XKeyEvent *, String *, Cardinal *
  1303. X#endif
  1304. X);
  1305. void InitCommands(
  1306. X#ifdef ANSI_PROTOTYPES
  1307. void
  1308. X#endif
  1309. X);
  1310. char * command(
  1311. X#ifdef ANSI_PROTOTYPES
  1312. PointCommand, char *, char *, char *, char *, char *, char *
  1313. X#endif
  1314. X);
  1315. X
  1316. X/* in copymove.c */
  1317. void updateFile(
  1318. X#ifdef ANSI_PROTOTYPES
  1319. int, Offset, Offset, int
  1320. X#endif
  1321. X);
  1322. void updateTops(
  1323. X#ifdef ANSI_PROTOTYPES
  1324. int, Offset, Offset, int
  1325. X#endif
  1326. X);
  1327. void exchWithScrap(
  1328. X#ifdef ANSI_PROTOTYPES
  1329. void
  1330. X#endif
  1331. X);
  1332. void copyToScrap(
  1333. X#ifdef ANSI_PROTOTYPES
  1334. struct window *, Offset, Offset
  1335. X#endif
  1336. X);
  1337. void insScrap(
  1338. X#ifdef ANSI_PROTOTYPES
  1339. int, int
  1340. X#endif
  1341. X);
  1342. void copyMove(
  1343. X#ifdef ANSI_PROTOTYPES
  1344. struct window *, Offset, Offset, struct window *, Offset, int
  1345. X#endif
  1346. X);
  1347. void copyPieces(
  1348. X#ifdef ANSI_PROTOTYPES
  1349. Piece, struct window *, Offset, Offset, int, int
  1350. X#endif
  1351. X);
  1352. X
  1353. X/* in cursor.c */
  1354. int cursor(
  1355. X#ifdef ANSI_PROTOTYPES
  1356. char *, char *, int
  1357. X#endif
  1358. X);
  1359. void doScreenUpdate(
  1360. X#ifdef ANSI_PROTOTYPES
  1361. int, int, int
  1362. X#endif
  1363. X);
  1364. X
  1365. X/* dialogs.c */
  1366. int DialogBox(
  1367. X#ifdef ANSI_PROTOTYPES
  1368. char *, char *, char *, char *, char *, char *, int *, int
  1369. X#endif
  1370. X);
  1371. X
  1372. X/* in display.c */
  1373. void drawWindowFast(
  1374. X#ifdef ANSI_PROTOTYPES
  1375. struct window *, int, int, int, int
  1376. X#endif
  1377. X);
  1378. void drawWindow(
  1379. X#ifdef ANSI_PROTOTYPES
  1380. struct window *
  1381. X#endif
  1382. X);
  1383. void banner(
  1384. X#ifdef ANSI_PROTOTYPES
  1385. struct window *, int
  1386. X#endif
  1387. X);
  1388. void SetSlider(
  1389. X#ifdef ANSI_PROTOTYPES
  1390. struct window *, long
  1391. X#endif
  1392. X);
  1393. void fillWindow(
  1394. X#ifdef ANSI_PROTOTYPES
  1395. struct window *, int, int, int, int
  1396. X#endif
  1397. X);
  1398. void DrawString(
  1399. X#ifdef ANSI_PROTOTYPES
  1400. void
  1401. X#endif
  1402. X);
  1403. void CheckForSelection(
  1404. X#ifdef ANSI_PROTOTYPES
  1405. void
  1406. X#endif
  1407. X);
  1408. Offset fillLine(
  1409. X#ifdef ANSI_PROTOTYPES
  1410. struct window *, Offset, int, int, int, int, int
  1411. X#endif
  1412. X);
  1413. X
  1414. X/* in execcmd.c */
  1415. void execCmd(
  1416. X#ifdef ANSI_PROTOTYPES
  1417. int
  1418. X#endif
  1419. X);
  1420. X
  1421. X/* in fileio.c */
  1422. void initFileio(
  1423. X#ifdef ANSI_PROTOTYPES
  1424. void
  1425. X#endif
  1426. X);
  1427. int getFileId(
  1428. X#ifdef ANSI_PROTOTYPES
  1429. char *
  1430. X#endif
  1431. X);
  1432. void saveFile(
  1433. X#ifdef ANSI_PROTOTYPES
  1434. struct window *
  1435. X#endif
  1436. X);
  1437. void writeFile(
  1438. X#ifdef ANSI_PROTOTYPES
  1439. struct window *
  1440. X#endif
  1441. X);
  1442. int doWrite(
  1443. X#ifdef ANSI_PROTOTYPES
  1444. int, char *
  1445. X#endif
  1446. X);
  1447. char * makeTempFor(
  1448. X#ifdef ANSI_PROTOTYPES
  1449. char *
  1450. X#endif
  1451. X);
  1452. Offset fileSize(
  1453. X#ifdef ANSI_PROTOTYPES
  1454. int
  1455. X#endif
  1456. X);
  1457. int closeFile(
  1458. X#ifdef ANSI_PROTOTYPES
  1459. int, int
  1460. X#endif
  1461. X);
  1462. X
  1463. X/* findfiles.c */
  1464. char * OldFindMatchingFiles(
  1465. X#ifdef ANSI_PROTOTYPES
  1466. char *, char *
  1467. X#endif
  1468. X);
  1469. char * FindMatchingFiles(
  1470. X#ifdef ANSI_PROTOTYPES
  1471. char *, char *
  1472. X#endif
  1473. X);
  1474. char * makeFullPathname(
  1475. X#ifdef ANSI_PROTOTYPES
  1476. char *
  1477. X#endif
  1478. X);
  1479. int striccmp(
  1480. X#ifdef ANSI_PROTOTYPES
  1481. char *, char *
  1482. X#endif
  1483. X);
  1484. struct window * findFilenameWindow(
  1485. X#ifdef ANSI_PROTOTYPES
  1486. char *
  1487. X#endif
  1488. X);
  1489. X
  1490. X/* in findpos.c */
  1491. Offset xyToOffset(
  1492. X#ifdef ANSI_PROTOTYPES
  1493. struct window *, int, int
  1494. X#endif
  1495. X);
  1496. void OffsetToXY(
  1497. X#ifdef ANSI_PROTOTYPES
  1498. struct window *, Offset, int *, int *
  1499. X#endif
  1500. X);
  1501. int OffsetToCol(
  1502. X#ifdef ANSI_PROTOTYPES
  1503. struct window *, Offset, Offset
  1504. X#endif
  1505. X);
  1506. X
  1507. X/* goto.c */
  1508. void matchChar(
  1509. X#ifdef ANSI_PROTOTYPES
  1510. void
  1511. X#endif
  1512. X);
  1513. void doGoSel(
  1514. X#ifdef ANSI_PROTOTYPES
  1515. struct window *
  1516. X#endif
  1517. X);
  1518. void doGoto(
  1519. X#ifdef ANSI_PROTOTYPES
  1520. struct window *, int, int
  1521. X#endif
  1522. X);
  1523. X
  1524. X/* in help.c */
  1525. int help(
  1526. X#ifdef ANSI_PROTOTYPES
  1527. int
  1528. X#endif
  1529. X);
  1530. X
  1531. X/* in inschar.c */
  1532. void HandleKey(
  1533. X#ifdef ANSI_PROTOTYPES
  1534. int keysym, int state
  1535. X#endif
  1536. X);
  1537. void insChar(
  1538. X#ifdef ANSI_PROTOTYPES
  1539. int c2, int update
  1540. X#endif
  1541. X);
  1542. int doAutoIndent(
  1543. X#ifdef ANSI_PROTOTYPES
  1544. void
  1545. X#endif
  1546. X);
  1547. X
  1548. X/* in insdel.c */
  1549. void insertChar(
  1550. X#ifdef ANSI_PROTOTYPES
  1551. int
  1552. X#endif
  1553. X);
  1554. int delChar(
  1555. X#ifdef ANSI_PROTOTYPES
  1556. void
  1557. X#endif
  1558. X);
  1559. void DeleteViewChars(
  1560. X#ifdef ANSI_PROTOTYPES
  1561. void
  1562. X#endif
  1563. X);
  1564. int deleteChars(
  1565. X#ifdef ANSI_PROTOTYPES
  1566. int, int, int
  1567. X#endif
  1568. X);
  1569. X
  1570. X/* keyword.c */
  1571. void findKeyword(
  1572. X#ifdef ANSI_PROTOTYPES
  1573. char * keyword
  1574. X#endif
  1575. X);
  1576. X
  1577. X/* library.c */
  1578. struct window * FindWindowByTkName(
  1579. X#ifdef ANSI_PROTOTYPES
  1580. char * name
  1581. X#endif
  1582. X);
  1583. BrowserData * FindBrowserByTkName(
  1584. X#ifdef ANSI_PROTOTYPES
  1585. char * name
  1586. X#endif
  1587. X);
  1588. int ConvertGeometrySpec(
  1589. X#ifdef ANSI_PROTOTYPES
  1590. char * geometry, int * x, int * y, int * width, int * height
  1591. X#endif
  1592. X);
  1593. int indentToShowSelection(
  1594. X#ifdef ANSI_PROTOTYPES
  1595. int
  1596. X#endif
  1597. X);
  1598. char * ExecTclCommand(
  1599. X#ifdef ANSI_PROTOTYPES
  1600. char * command
  1601. X#endif
  1602. X);
  1603. int LineNumberOfSelection(
  1604. X#ifdef ANSI_PROTOTYPES
  1605. void
  1606. X#endif
  1607. X);
  1608. void FixName(
  1609. X#ifdef ANSI_PROTOTYPES
  1610. char *s
  1611. X#endif
  1612. X);
  1613. char *tildefyFilename(
  1614. X#ifdef ANSI_PROTOTYPES
  1615. char *
  1616. X#endif
  1617. X);
  1618. char * findFile(
  1619. X#ifdef ANSI_PROTOTYPES
  1620. char *
  1621. X#endif
  1622. X);
  1623. char * PtMalloc(
  1624. X#ifdef ANSI_PROTOTYPES
  1625. int, char *
  1626. X#endif
  1627. X);
  1628. void PtFree(
  1629. X#ifdef ANSI_PROTOTYPES
  1630. char *
  1631. X#endif
  1632. X);
  1633. int MarkTime(
  1634. X#ifdef ANSI_PROTOTYPES
  1635. void
  1636. X#endif
  1637. X);
  1638. void GetPointerPosition(
  1639. X#ifdef ANSI_PROTOTYPES
  1640. int *, int *
  1641. X#endif
  1642. X);
  1643. int SupplySelectionToX(
  1644. X#ifdef ANSI_PROTOTYPES
  1645. ClientData clientData, int offset, char * buffer, int maxBytes
  1646. X#endif
  1647. X);
  1648. void AssertSelectionOwnership(
  1649. X#ifdef ANSI_PROTOTYPES
  1650. void
  1651. X#endif
  1652. X);
  1653. int getSelection(
  1654. X#ifdef ANSI_PROTOTYPES
  1655. char *, int, int
  1656. X#endif
  1657. X);
  1658. int makeName(
  1659. X#ifdef ANSI_PROTOTYPES
  1660. char *
  1661. X#endif
  1662. X);
  1663. int getBaseName(
  1664. X#ifdef ANSI_PROTOTYPES
  1665. char *
  1666. X#endif
  1667. X);
  1668. void justifyLines(
  1669. X#ifdef ANSI_PROTOTYPES
  1670. void
  1671. X#endif
  1672. X);
  1673. char * noWhiteSpace(
  1674. X#ifdef ANSI_PROTOTYPES
  1675. char *
  1676. X#endif
  1677. X);
  1678. X
  1679. X/* in lines.c */
  1680. Offset readLine(
  1681. X#ifdef ANSI_PROTOTYPES
  1682. int, Offset, char *, int
  1683. X#endif
  1684. X);
  1685. Offset nextLine(
  1686. X#ifdef ANSI_PROTOTYPES
  1687. int, Offset, int *
  1688. X#endif
  1689. X);
  1690. Offset prevLine(
  1691. X#ifdef ANSI_PROTOTYPES
  1692. int, Offset, int *
  1693. X#endif
  1694. X);
  1695. X
  1696. X/* in main.c */
  1697. int main(
  1698. X#ifdef ANSI_PROTOTYPES
  1699. unsigned int, char **
  1700. X#endif
  1701. X);
  1702. X
  1703. X/* in makeMenus.c */
  1704. void MakeMouseMenuCursors(
  1705. X#ifdef ANSI_PROTOTYPES
  1706. void
  1707. X#endif
  1708. X);
  1709. X
  1710. X/* in makeWindow.c */
  1711. void EnterAWindow(
  1712. X#ifdef ANSI_PROTOTYPES
  1713. int, struct window *, XEvent *
  1714. X#endif
  1715. X);
  1716. void VScroll(
  1717. X#ifdef ANSI_PROTOTYPES
  1718. struct window * w, int how, int y, int button
  1719. X#endif
  1720. X);
  1721. int DoOneVScroll(
  1722. X#ifdef ANSI_PROTOTYPES
  1723. void
  1724. X#endif
  1725. X);
  1726. void HScroll(
  1727. X#ifdef ANSI_PROTOTYPES
  1728. struct window * w, int which, int x, int button
  1729. X#endif
  1730. X);
  1731. void MakeWindow(
  1732. X#ifdef ANSI_PROTOTYPES
  1733. struct window *, char * geometry
  1734. X#endif
  1735. X);
  1736. X
  1737. X/* in mouse.c */
  1738. void InitMouse(
  1739. X#ifdef ANSI_PROTOTYPES
  1740. void
  1741. X#endif
  1742. X);
  1743. void Mouse(
  1744. X#ifdef ANSI_PROTOTYPES
  1745. struct window * w, char * cmd, int x, int y
  1746. X#endif
  1747. X);
  1748. X
  1749. X/* in options.c */
  1750. void InitOptions(
  1751. X#ifdef ANSI_PROTOTYPES
  1752. void
  1753. X#endif
  1754. X);
  1755. char * GetPointOption(
  1756. X#ifdef ANSI_PROTOTYPES
  1757. char *
  1758. X#endif
  1759. X);
  1760. void SetPointOption(
  1761. X#ifdef ANSI_PROTOTYPES
  1762. char *, char *
  1763. X#endif
  1764. X);
  1765. X
  1766. X
  1767. X/* in piece.c */
  1768. Piece dupPieces(
  1769. X#ifdef ANSI_PROTOTYPES
  1770. Piece
  1771. X#endif
  1772. X);
  1773. Piece getFreePiece(
  1774. X#ifdef ANSI_PROTOTYPES
  1775. void
  1776. X#endif
  1777. X);
  1778. void freePieces(
  1779. X#ifdef ANSI_PROTOTYPES
  1780. Piece
  1781. X#endif
  1782. X);
  1783. Piece findPiece(
  1784. X#ifdef ANSI_PROTOTYPES
  1785. Offset, struct openFile *, Offset *
  1786. X#endif
  1787. X);
  1788. X
  1789. X/* in ptInit.c */
  1790. void ptInit(
  1791. X#ifdef ANSI_PROTOTYPES
  1792. void
  1793. X#endif
  1794. X);
  1795. void msg(
  1796. X#ifdef ANSI_PROTOTYPES
  1797. char *, int
  1798. X#endif
  1799. X);
  1800. X
  1801. X/* in regex.c */
  1802. char * re_comp(
  1803. X#ifdef ANSI_PROTOTYPES
  1804. char *pat
  1805. X#endif
  1806. X);
  1807. int re_exec(
  1808. X#ifdef ANSI_PROTOTYPES
  1809. int fid, int cp, int end_cp, int *lines_passed, int reversed
  1810. X#endif
  1811. X);
  1812. int re_match(
  1813. X#ifdef ANSI_PROTOTYPES
  1814. char *lp
  1815. X#endif
  1816. X);
  1817. void RegexReplaceAll(
  1818. X#ifdef ANSI_PROTOTYPES
  1819. struct window * w, char * searchFor, char * replaceWith, int inSelection
  1820. X#endif
  1821. X);
  1822. int RegexReplaceOne(
  1823. X#ifdef ANSI_PROTOTYPES
  1824. struct window * w, char * searchFor, char * replaceWith
  1825. X#endif
  1826. X);
  1827. X
  1828. X/* in repaint.c */
  1829. void SetTextColor(
  1830. X#ifdef ANSI_PROTOTYPES
  1831. struct window *w, int normal, int foreground, char * colorName
  1832. X#endif
  1833. X);
  1834. void CycleColors(
  1835. X#ifdef ANSI_PROTOTYPES
  1836. char **, char *
  1837. X#endif
  1838. X);
  1839. void InitRedisplay(
  1840. X#ifdef ANSI_PROTOTYPES
  1841. struct window *
  1842. X#endif
  1843. X);
  1844. void WorkspaceResized(
  1845. X#ifdef ANSI_PROTOTYPES
  1846. struct window *
  1847. X#endif
  1848. X);
  1849. void repaint(
  1850. X#ifdef ANSI_PROTOTYPES
  1851. struct window *, int, int, int, int
  1852. X#endif
  1853. X);
  1854. X
  1855. X/* replace.c */
  1856. void replaceText(
  1857. X#ifdef ANSI_PROTOTYPES
  1858. struct window *, char * fromString, int inSelection
  1859. X#endif
  1860. X);
  1861. void replaceTextAux(
  1862. X#ifdef ANSI_PROTOTYPES
  1863. struct window *, unsigned char *, unsigned char *, int, int
  1864. X#endif
  1865. X);
  1866. X
  1867. X/* in search.c */
  1868. int searchFor(
  1869. X#ifdef ANSI_PROTOTYPES
  1870. struct window * w, int searchMode, char * s, int update
  1871. X#endif
  1872. X);
  1873. X
  1874. X/* in select.c */
  1875. void ExtendSelection(
  1876. X#ifdef ANSI_PROTOTYPES
  1877. Offset, int, int, Offset
  1878. X#endif
  1879. X);
  1880. void drawSelection(
  1881. X#ifdef ANSI_PROTOTYPES
  1882. int
  1883. X#endif
  1884. X);
  1885. void DrawSection(
  1886. X#ifdef ANSI_PROTOTYPES
  1887. struct window *, Offset, int, int, int, int
  1888. X#endif
  1889. X);
  1890. void modeExtend(
  1891. X#ifdef ANSI_PROTOTYPES
  1892. struct window *, Offset, int, int, Offset
  1893. X#endif
  1894. X);
  1895. Offset adjustSelMode(
  1896. X#ifdef ANSI_PROTOTYPES
  1897. Offset
  1898. X#endif
  1899. X);
  1900. int XSelConvert(
  1901. X#ifdef ANSI_PROTOTYPES
  1902. int, Atom *, Atom *, Atom *, char * *, unsigned long *, int *
  1903. X#endif
  1904. X);
  1905. void XSelLose(
  1906. X#ifdef ANSI_PROTOTYPES
  1907. int, Atom *
  1908. X#endif
  1909. X);
  1910. X
  1911. X/* spans.c */
  1912. Offset searchSpans(
  1913. X#ifdef ANSI_PROTOTYPES
  1914. int, Offset, Offset, char *, int, int *
  1915. X#endif
  1916. X);
  1917. Offset searchReverseSpans(
  1918. X#ifdef ANSI_PROTOTYPES
  1919. int, Offset, Offset, char *, int, int *
  1920. X#endif
  1921. X);
  1922. unsigned char * match1up(
  1923. X#ifdef ANSI_PROTOTYPES
  1924. unsigned char *, int, int, int
  1925. X#endif
  1926. X);
  1927. unsigned char * match1dn(
  1928. X#ifdef ANSI_PROTOTYPES
  1929. unsigned char *, int, int, int
  1930. X#endif
  1931. X);
  1932. unsigned char * match2dn(
  1933. X#ifdef ANSI_PROTOTYPES
  1934. unsigned char *, int, int
  1935. X#endif
  1936. X);
  1937. int countnl(
  1938. X#ifdef ANSI_PROTOTYPES
  1939. unsigned char *, int
  1940. X#endif
  1941. X);
  1942. X
  1943. X/* stats.c */
  1944. void PrintStats(
  1945. X#ifdef ANSI_PROTOTYPES
  1946. int fileId
  1947. X#endif
  1948. X);
  1949. X
  1950. X/* tags.c */
  1951. void findCTag(
  1952. X#ifdef ANSI_PROTOTYPES
  1953. char * ctag
  1954. X#endif
  1955. X);
  1956. X
  1957. X/* tcl.c */
  1958. int doPtCommand(
  1959. X#ifdef ANSI_PROTOTYPES
  1960. ClientData clientData, Tcl_Interp * interp, int argc, char *argv[]
  1961. X#endif
  1962. X);
  1963. void AddPointCommands(
  1964. X#ifdef ANSI_PROTOTYPES
  1965. Tcl_Interp *
  1966. X#endif
  1967. X);
  1968. void ptTcl(
  1969. X#ifdef ANSI_PROTOTYPES
  1970. int, XButtonEvent *, String *, Cardinal *
  1971. X#endif
  1972. X);
  1973. X
  1974. X/* undoredo.c */
  1975. void initChanges(
  1976. X#ifdef ANSI_PROTOTYPES
  1977. void
  1978. X#endif
  1979. X);
  1980. struct changeItem * GetCurrentChange(
  1981. X#ifdef ANSI_PROTOTYPES
  1982. struct openFile * ff
  1983. X#endif
  1984. X);
  1985. struct changeItem * GetNewChange(
  1986. X#ifdef ANSI_PROTOTYPES
  1987. struct openFile * ff
  1988. X#endif
  1989. X);
  1990. void RecordChange(
  1991. X#ifdef ANSI_PROTOTYPES
  1992. struct openFile * ff, struct changeItem * new_change
  1993. X#endif
  1994. X);
  1995. void redo(
  1996. X#ifdef ANSI_PROTOTYPES
  1997. struct openFile * ff, int count
  1998. X#endif
  1999. X);
  2000. void again(
  2001. X#ifdef ANSI_PROTOTYPES
  2002. struct openFile * ff, int mostRecent
  2003. X#endif
  2004. X);
  2005. void UpdateUndoList(
  2006. X#ifdef ANSI_PROTOTYPES
  2007. struct openFile * ff
  2008. X#endif
  2009. X);
  2010. void ShowUndos(
  2011. X#ifdef ANSI_PROTOTYPES
  2012. struct openFile * ff
  2013. X#endif
  2014. X);
  2015. void undo(
  2016. X#ifdef ANSI_PROTOTYPES
  2017. struct openFile * ff, int count
  2018. X#endif
  2019. X);
  2020. void showChange(
  2021. X#ifdef ANSI_PROTOTYPES
  2022. void
  2023. X#endif
  2024. X);
  2025. X
  2026. X/* in userInput.c */
  2027. void FixName(
  2028. X#ifdef ANSI_PROTOTYPES
  2029. char *
  2030. X#endif
  2031. X);
  2032. void CommandHandler(
  2033. X#ifdef ANSI_PROTOTYPES
  2034. int, char *, char *
  2035. X#endif
  2036. X);
  2037. void GetKeystrokes(
  2038. X#ifdef ANSI_PROTOTYPES
  2039. int, XKeyEvent *
  2040. X#endif
  2041. X);
  2042. X
  2043. X/* in windows.c */
  2044. void initWindows(
  2045. X#ifdef ANSI_PROTOTYPES
  2046. void
  2047. X#endif
  2048. X);
  2049. void MakeWindowActive(
  2050. X#ifdef ANSI_PROTOTYPES
  2051. struct window *
  2052. X#endif
  2053. X);
  2054. struct window * createWindow(
  2055. X#ifdef ANSI_PROTOTYPES
  2056. struct window * w, char * filename, char * geometry
  2057. X#endif
  2058. X);
  2059. int closeWindow(
  2060. X#ifdef ANSI_PROTOTYPES
  2061. struct window *, int
  2062. X#endif
  2063. X);
  2064. void topWindow(
  2065. X#ifdef ANSI_PROTOTYPES
  2066. struct window *
  2067. X#endif
  2068. X);
  2069. void ZoomWindow(
  2070. X#ifdef ANSI_PROTOTYPES
  2071. struct window *, int
  2072. X#endif
  2073. X);
  2074. struct window * GetNewFile(
  2075. X#ifdef ANSI_PROTOTYPES
  2076. struct window * w, char * filename, char * geometry
  2077. X#endif
  2078. X);
  2079. void doNewWindow(
  2080. X#ifdef ANSI_PROTOTYPES
  2081. struct window *
  2082. X#endif
  2083. X);
  2084. void bottomFile(
  2085. X#ifdef ANSI_PROTOTYPES
  2086. struct window *
  2087. X#endif
  2088. X);
  2089. X
  2090. END_OF_FILE
  2091. if test 17878 -ne `wc -c <'funcdecl.h'`; then
  2092.     echo shar: \"'funcdecl.h'\" unpacked with wrong size!
  2093. fi
  2094. # end of 'funcdecl.h'
  2095. fi
  2096. if test -f 'windows.c' -a "${1}" != "-c" ; then 
  2097.   echo shar: Will not clobber existing file \"'windows.c'\"
  2098. else
  2099. echo shar: Extracting \"'windows.c'\" \(18315 characters\)
  2100. sed "s/^X//" >'windows.c' <<'END_OF_FILE'
  2101. X/* $Header: /nfs/unmvax/faculty/crowley/x/pt/RCS/windows.c,v 1.9 1992/03/04 17:07:18 crowley Exp crowley $ */
  2102. X
  2103. X#include <ctype.h>
  2104. X#include <string.h>
  2105. X#include "pt.h"
  2106. X#include <stdio.h>
  2107. X#include <sys/file.h>
  2108. X#ifdef uts
  2109. X#include <fcntl.h>
  2110. X#endif
  2111. X
  2112. X/* the list of active windows, top to bottom */
  2113. struct window *windowList = NULL;
  2114. X
  2115. X/* the active window */
  2116. struct window *activeWindow = NULL;
  2117. X
  2118. extern struct openFile *files;
  2119. X
  2120. void
  2121. initWindows()
  2122. X{
  2123. X    extern char charTable[];
  2124. X
  2125. X    charTable['\n'] = 1;
  2126. X    charTable[BLOCK_EOF] = 2;
  2127. X    charTable['\t'] = 3;
  2128. X}
  2129. X
  2130. void
  2131. MakeWindowActive( w )
  2132. X    struct window *w;
  2133. X{
  2134. X    extern struct window *activeWindow;
  2135. X
  2136. X    if( w != activeWindow ) {
  2137. X        /* remember the old active window */
  2138. X        struct window *oldw = activeWindow;
  2139. X
  2140. X        activeWindow = w;
  2141. X        banner( oldw, 0 );
  2142. X        banner( w, 0 );
  2143. X    }
  2144. X}
  2145. X
  2146. struct window *
  2147. createWindow( w, fileName, geometry )
  2148. X    struct window * w;
  2149. X    char * fileName;
  2150. X    char * geometry;
  2151. X{
  2152. X    extern struct window *selWindow;
  2153. X    extern Offset selBegin, selEnd;
  2154. X    extern char msgBuffer[];
  2155. X    extern int maxFiles;
  2156. X    extern int debug;
  2157. X    extern int autoZoom;
  2158. X    extern char * textFont;
  2159. X    extern int hypertextOn;
  2160. X    extern Display *MainDisplay;
  2161. X#ifdef HYPERTEXT
  2162. X    extern DBM *currentDB;
  2163. X    extern Document currentDocument;
  2164. X#endif
  2165. X    extern unsigned char beginMarkerChar;
  2166. X    extern Tcl_Interp * interp;
  2167. X    extern BrowserData * mainBrowser;
  2168. X    extern Window MainWindow;
  2169. X
  2170. X    int createToo = (w == NULL);
  2171. X    char * name;
  2172. X
  2173. X    if( createToo ) {    /* we need to create the window as well as */
  2174. X                /* load the new file into it */
  2175. X        w = (struct window *) PtMalloc( sizeof(struct window),
  2176. X                        "Window structure" );
  2177. X    }
  2178. X
  2179. X    w->fileId = getFileId(fileName);
  2180. X    w->realFileId = w->fileId;
  2181. X    if( w->fileId == -1 ) {
  2182. X        /* file not found, do not open the window */
  2183. X        printf( "File %s not found\n", fileName );
  2184. X        return NULL;
  2185. X    }
  2186. X#ifdef HYPERTEXT
  2187. X    if( hypertextOn && getFileByte(w->fileId,0) == (int)beginMarkerChar ) {
  2188. X        /* This is a hypertext file */
  2189. X        extern MapID naturalMap;
  2190. X        FileID fileID;
  2191. X        unsigned int flags;
  2192. X        BlockID blockID;
  2193. X
  2194. X        w->db = currentDB;
  2195. X        w->document = currentDocument;
  2196. X        fileID = LookupFileByName( w->db, w->document,
  2197. X                        files[w->fileId].origName );
  2198. X        if( fileID == NullObject ) {
  2199. X            printf(
  2200. X"ERROR: could not find file %s. Displaying as an ordinary file\n",
  2201. X                files[w->fileId].origName );
  2202. X            goto ordinary_file;
  2203. X        }
  2204. X        w->file = GetFile( w->db, fileID, ALLOCATE );
  2205. X
  2206. X        /* get the inital view */
  2207. X        w->view = NULL;    /* not using views yet */
  2208. X
  2209. X        /* get the maps from the initial view */
  2210. X        w->blockMap = GetMap( w->db, naturalMap, ALLOCATE);
  2211. X        if( w->blockMap == NULL ) {
  2212. X            printf( "Cannot find natural map in database %s\n",
  2213. X                                fileName );
  2214. X            return NULL;
  2215. X        }
  2216. X        /* Maybe later we can fetch these */
  2217. X        w->fromLinkMap = NULL;
  2218. X        w->toLinkMap = NULL;
  2219. X
  2220. X        /* get the initial block of the initial view */
  2221. X        (void)ReadBlockMarker( w->fileId, 1, &blockID, &flags );
  2222. X        w->block = GetBlock( w->db, blockID, ALLOCATE);
  2223. X        if( w->block == NULL ) {
  2224. X            printf( "Cannot find initial block in database %s\n",
  2225. X                                fileName );
  2226. X            return NULL;
  2227. X        }
  2228. X
  2229. X        /* Split up the file so that all block markers are in */
  2230. X        /* separate pieces.  Other code depends on this to be true. */
  2231. X        SeparateBlockMarkers( w );
  2232. X
  2233. X        /* fileId already copied to realFileId (above) */
  2234. X        w->fileId = CreateViewFile( w );
  2235. X    } else {
  2236. X    ordinary_file:
  2237. X        /* This is an ordinary file */
  2238. X        w->db = NULL;
  2239. X        w->document = NULL;
  2240. X        w->view = NULL;
  2241. X        w->block = NULL;
  2242. X        w->blockMap = NULL;
  2243. X        w->fromLinkMap = NULL;
  2244. X        w->toLinkMap = NULL;
  2245. X        w->file = NULL;
  2246. X    }
  2247. X#endif
  2248. X
  2249. X    w->posTopline = 0;
  2250. X
  2251. X    if( createToo ) {
  2252. X        /* insert w into the doubly linked windowList */
  2253. X        if( windowList == NULL ) {
  2254. X            w->prevWindow = NULL;
  2255. X            w->nextWindow = NULL;
  2256. X            windowList = w;
  2257. X        } else {
  2258. X            windowList->prevWindow = w;
  2259. X            w->prevWindow = NULL;
  2260. X            w->nextWindow = windowList;
  2261. X            windowList = w;
  2262. X        }
  2263. X    }
  2264. X
  2265. X    w->nameOffset = getBaseName(files[w->fileId].origName);
  2266. X
  2267. X    /* set the default window parameters */
  2268. X    w->posBotline = 0;
  2269. X    w->numTopline = 1;
  2270. X    w->numBotline = -1;
  2271. X    w->indent = 0;
  2272. X    
  2273. X    /* set up the last row cache */
  2274. X    w->posCurLast = 0;
  2275. X    w->lastPosTop = 0;
  2276. X    w->rowCurLast = 0;
  2277. X
  2278. X    /* set up the margins */
  2279. X    w->topMargin = 2;
  2280. X    w->leftMargin = 4;
  2281. X
  2282. X    /* set up the font name */
  2283. X    w->font.name = PtMalloc(strlen(textFont)+1, "font name");
  2284. X    strcpy(w->font.name, textFont);
  2285. X    /* height = 0 will ensure that the old font will not be reused */
  2286. X    (w->font).height = 0;
  2287. X    
  2288. X    /* create the three GCs needed by each window */
  2289. X    (w->font).gc_normal = XCreateGC(MainDisplay, MainWindow,
  2290. X                    0, NULL);
  2291. X    (w->font).gc_selected = XCreateGC(MainDisplay, MainWindow,
  2292. X                    0, NULL);
  2293. X    (w->font).gc_underline = XCreateGC(MainDisplay, MainWindow,
  2294. X                    0, NULL);
  2295. X
  2296. X    /* other setups */
  2297. X    w->x_window_id = NULL;
  2298. X    w->oldWidth = 0;
  2299. X    w->closeInform = NULL;
  2300. X    w->lineNumbers = 0;
  2301. X    
  2302. X    /* if there is a file in the window and there is not current */
  2303. X    /* selection, then move the selection to the new window */
  2304. X    if( w->fileId != -1 && selWindow == NULL ) {
  2305. X        /* put the selection at the first char in this window */
  2306. X        selWindow = w;
  2307. X        selBegin = 0;
  2308. X        selEnd = 0;
  2309. X    }
  2310. X
  2311. X    if( createToo ) {
  2312. X        w->screen_image = NULL;
  2313. X        /* this will cause a call to WorkspaceResized on the */
  2314. X        /* first expose event */
  2315. X        w->nRows = 0;
  2316. X        /*  create a text window */
  2317. X        (void)ExecTclCommand( "update" );
  2318. X        sprintf( msgBuffer, "TextWindow %s", geometry );
  2319. X        name = ExecTclCommand( msgBuffer );
  2320. X        w->tk_pathname = Tk_GetUid( name );
  2321. X        w->tk_toplevel = Tk_NameToWindow( interp, w->tk_pathname,
  2322. X                        mainBrowser->tk_toplevel );
  2323. X        sprintf( msgBuffer, "%s.VScrollAndText.Text", w->tk_pathname );
  2324. X        w->tk_text = Tk_NameToWindow( interp, msgBuffer,
  2325. X                        w->tk_toplevel);
  2326. X        w->x_window_id = Tk_WindowId( w->tk_text );
  2327. X
  2328. X        (void)ExecTclCommand( "update" );
  2329. X
  2330. X        /* zoom of necessary */
  2331. X        if( autoZoom )
  2332. X            ZoomWindow( w, 0 );
  2333. X    }
  2334. X
  2335. X    /* make the new window the active window */
  2336. X    MakeWindowActive( w );
  2337. X
  2338. X    /* update the list of open windows */
  2339. X    NewOpenList();
  2340. X
  2341. X    return w;
  2342. X}
  2343. X
  2344. int
  2345. closeWindow(w, ask)
  2346. X    register struct window *w;
  2347. X    int ask;
  2348. X{
  2349. X    extern struct window *selWindow;
  2350. X    extern struct window *activeWindow;
  2351. X    extern Offset selBegin, selEnd;
  2352. X    extern char msgBuffer[];
  2353. X    extern int debug;
  2354. X
  2355. X    struct window * w_prev, * w_next;
  2356. X
  2357. X    /* first destroy the widget tree (the shell is the top) */
  2358. X    
  2359. X#ifdef HYPERTEXT
  2360. X    /* free the objects and close the database */
  2361. X    if( w->db != NULL ) {
  2362. X        PutFile( w->db, w->file, RELEASE );
  2363. X        PutBlock( w->db, w->block, RELEASE );
  2364. X        PutMap( w->db, w->blockMap, RELEASE );
  2365. X        PutView( w->db, w->view, RELEASE );
  2366. X        PutDocument( w->db, w->document, RELEASE );
  2367. X    }
  2368. X#endif
  2369. X
  2370. X    if( closeFile(w->fileId, ask) == -1 )
  2371. X        return -1;
  2372. X
  2373. X    /* unlink this window from the window list */
  2374. X    w_prev = w->prevWindow;
  2375. X    w_next = w->nextWindow;
  2376. X    if( w_prev == NULL )
  2377. X        windowList = w_next;
  2378. X    else
  2379. X        w_prev->nextWindow = w_next;
  2380. X    if( w_next != NULL )
  2381. X        w_next->prevWindow = w_prev;
  2382. X    if( windowList == NULL )
  2383. X        activeWindow = NULL;
  2384. X
  2385. X    /* is the selection in this window? */
  2386. X    if( w == selWindow ) {
  2387. X        /* move the selection to the top window */
  2388. X        selWindow = windowList;
  2389. X        if( selWindow != NULL ) {
  2390. X            selBegin = 0;
  2391. X            selEnd = selBegin;
  2392. X        }
  2393. X    }
  2394. X
  2395. X    /* is this the active window? */
  2396. X    if( w == activeWindow ) {
  2397. X        MakeWindowActive( selWindow );
  2398. X    }
  2399. X
  2400. X    (void)ExecTclCommand( "update" );
  2401. X    Tk_DestroyWindow( w->tk_toplevel );
  2402. X    (void)ExecTclCommand( "update" );
  2403. X
  2404. X    /* free any allocated strings */
  2405. X    if( w->closeInform != NULL ) {
  2406. X        sprintf( msgBuffer, "catch {send %s %s}", w->closeInform,
  2407. X                            w->tk_pathname );
  2408. X        (void)ExecTclCommand( msgBuffer );
  2409. X        PtFree( w->closeInform );
  2410. X    }
  2411. X
  2412. X    PtFree( w->font.name );
  2413. X
  2414. X    PtFree( w->screen_image );
  2415. X
  2416. X    PtFree( (char *)w );
  2417. X
  2418. X    /* update the list of open windows */
  2419. X    NewOpenList();
  2420. X
  2421. X    return 0;
  2422. X}
  2423. X
  2424. static int timerIsOn = 0;
  2425. static Tk_TimerToken timer_token = NULL;
  2426. int intervalRows = 0;
  2427. int scrollDown = 0;
  2428. struct window * scroll_window;
  2429. X
  2430. static void
  2431. DoOneHScroll()
  2432. X{
  2433. X    extern int undoMotion;
  2434. X    extern Display *MainDisplay;
  2435. X
  2436. X    struct fontDataStruct *font = &( scroll_window->font);
  2437. X    int col1, col2, incr1, incr2, cols, wide;
  2438. X
  2439. X#ifdef LATERLATER
  2440. X    if( undoMotion ) {
  2441. X        /* record in the change history */
  2442. X        thisChange = GetNewChange( ff );
  2443. X        thisChange->type = CMOTION;
  2444. X        thisChange->lineNumber = scroll_window->numTopline;
  2445. X        thisChange->length = scroll_window->numTopline + intervalRows;
  2446. X        thisChange->w = scroll_window;
  2447. X        thisChange->flags = 0;
  2448. X        RecordChange( ff, thisChange );
  2449. X    }
  2450. X#endif
  2451. X    cols = intervalRows;
  2452. X    wide = font->width;
  2453. X    if( scrollDown ) {
  2454. X        scroll_window->indent += cols;
  2455. X        incr1 = cols * wide;
  2456. X        incr2 = 0;
  2457. X        col1 = (scroll_window->nCols) - cols;
  2458. X        col2 = scroll_window->nCols - 1;
  2459. X    } else {
  2460. X        /* do not allow scrolling off the beginning */
  2461. X        if( cols > scroll_window->indent )
  2462. X            cols = scroll_window->indent;
  2463. X        scroll_window->indent -= cols;
  2464. X        incr1 = 0;
  2465. X        incr2 = cols * wide;
  2466. X        col1 = 0;
  2467. X        col2 = cols - 1;
  2468. X    }
  2469. X    XCopyArea( MainDisplay, scroll_window->x_window_id,
  2470. X        scroll_window->x_window_id, font->gc_normal,
  2471. X        scroll_window->leftMargin + incr1, 0,
  2472. X        (scroll_window->nCols - cols) * wide,
  2473. X        Tk_Height(scroll_window->tk_toplevel),
  2474. X        scroll_window->leftMargin + incr2, 0 );
  2475. X    drawWindowFast(scroll_window, 0, scroll_window->nRows-1, col1, col2 );
  2476. X}
  2477. X
  2478. X/*ARGSUSED*/
  2479. static void
  2480. repeatHScroll( clientData )
  2481. X    ClientData clientData;
  2482. X{
  2483. X    DoOneHScroll();
  2484. X    timer_token = Tk_CreateTimerHandler( 100, repeatHScroll, 0 );
  2485. X}
  2486. X
  2487. void
  2488. HScroll( w, how, x, button )
  2489. X    struct window *w;
  2490. X    int how;
  2491. X    int x;
  2492. X    int button;
  2493. X{
  2494. X    int top_unit;
  2495. X
  2496. X    /* how = 0 ==> tk scrolling */
  2497. X    /* how = 1 ==> button press */
  2498. X    /* how = 2 ==> button release */
  2499. X    /* how = 3 ==> button motion */
  2500. X
  2501. X    scroll_window = w;
  2502. X    switch( how ) {
  2503. X    case 0:        /* Tk scrolling */
  2504. X        top_unit = x;
  2505. X        intervalRows = top_unit - (w->indent);
  2506. X        break;
  2507. X    case 1:        /* button press */
  2508. X        intervalRows = (x - w->leftMargin) / (w->font).width;
  2509. X        switch( button ) {
  2510. X        case 1:
  2511. X            scrollDown = 0;
  2512. X            break;
  2513. X        case 2:
  2514. X            goto thumbing;
  2515. X        case 3:
  2516. X            scrollDown = 1;
  2517. X            break;
  2518. X        }
  2519. X        if( !timerIsOn ) {
  2520. X            DoOneHScroll();
  2521. X            timer_token = Tk_CreateTimerHandler( 500,
  2522. X                            repeatHScroll, 0 );
  2523. X            timerIsOn = 1;
  2524. X        }
  2525. X        break;
  2526. X    case 2:        /* (left or right) button release */
  2527. X        if( timerIsOn ) {
  2528. X            timerIsOn = 0;
  2529. X            Tk_DeleteTimerHandler( timer_token );
  2530. X        }
  2531. X        return;
  2532. X    case 3:        /* (middle) button motion */
  2533. X    thumbing:
  2534. X        intervalRows = w->indent
  2535. X                - (x - w->leftMargin) / (w->font).width;
  2536. X        DoOneHScroll();
  2537. X        break;
  2538. X    }
  2539. X
  2540. X    /* always scroll at least one column */
  2541. X    if( intervalRows < 1 )
  2542. X        intervalRows = 1;
  2543. X}
  2544. X
  2545. int
  2546. DoOneVScroll()
  2547. X{
  2548. X    extern int undoMotion;
  2549. X    extern Display *MainDisplay;
  2550. X
  2551. X    struct fontDataStruct *font = &(scroll_window->font);
  2552. X    int fid = scroll_window->fileId;
  2553. X    struct changeItem *thisChange;
  2554. X    int rowsScrolled, high, incr1, incr2, row1, row2;
  2555. X    struct openFile * ff = &files[fid];
  2556. X    int copy_height;
  2557. X
  2558. X    if( undoMotion ) {
  2559. X        /* record in the change history */
  2560. X        thisChange = GetNewChange( ff );
  2561. X        thisChange->type = CMOTION;
  2562. X        thisChange->lineNumber = scroll_window->numTopline;
  2563. X        thisChange->length = scroll_window->numTopline + intervalRows;
  2564. X        thisChange->w = scroll_window;
  2565. X        thisChange->flags = 0;
  2566. X        RecordChange( ff, thisChange );
  2567. X    }
  2568. X
  2569. X    rowsScrolled = intervalRows;
  2570. X    high = font->height;
  2571. X    copy_height = (scroll_window->nRows - intervalRows) * high;
  2572. X    if( scrollDown ) {
  2573. X        scroll_window->posTopline = nextLine( fid,
  2574. X                scroll_window->posTopline, &rowsScrolled );
  2575. X        scroll_window->numTopline += rowsScrolled;
  2576. X        scroll_window->numBotline += rowsScrolled;
  2577. X        incr1 = rowsScrolled * high;
  2578. X        incr2 = 0;
  2579. X        row1 = scroll_window->nRows - rowsScrolled;
  2580. X        if( rowsScrolled < intervalRows )
  2581. X            row1 = rowsScrolled + 1;
  2582. X        row2 = scroll_window->nRows-1;
  2583. X    } else {
  2584. X        /* do not allow scrolling off the beginning */
  2585. X        if( scroll_window->posTopline <= 0 )
  2586. X            return 0;
  2587. X        scroll_window->posTopline = prevLine( fid,
  2588. X                scroll_window->posTopline, &rowsScrolled);
  2589. X        scroll_window->numTopline -= rowsScrolled;
  2590. X        scroll_window->numBotline -= rowsScrolled;
  2591. X        row1 = intervalRows - rowsScrolled;
  2592. X        if( row1 > 0 )
  2593. X            copy_height += row1 * high;
  2594. X        incr1 = 0;
  2595. X        incr2 = rowsScrolled * high;
  2596. X        row1 = 0;
  2597. X        row2 = rowsScrolled - 1;
  2598. X    }
  2599. X    /* only copy if we can use part of the present window */
  2600. X    if( intervalRows < scroll_window->nRows ) {
  2601. X        XCopyArea( MainDisplay, scroll_window->x_window_id,
  2602. X            scroll_window->x_window_id, font->gc_normal,
  2603. X            0, scroll_window->topMargin + incr1,
  2604. X            Tk_Width(scroll_window->tk_toplevel), copy_height,
  2605. X            0, scroll_window->topMargin + incr2 );
  2606. X        if( scrollDown && scroll_window->posBotline
  2607. X                    == fileSize(scroll_window->fileId) ) {
  2608. X            XClearArea( MainDisplay, scroll_window->x_window_id,
  2609. X                0, copy_height,
  2610. X                Tk_Width(scroll_window->tk_text),
  2611. X                Tk_Height(scroll_window->tk_text)-copy_height,
  2612. X                False
  2613. X            );
  2614. X            return rowsScrolled;
  2615. X        }
  2616. X    } else {
  2617. X        /* we went through the above calculations in order to get */
  2618. X        /* posTopline, numTopline and numBotline updated */
  2619. X        /* now fix up row1 and row2 */
  2620. X        row1 = 0;
  2621. X        row2 = scroll_window->nRows - 1;
  2622. X    }
  2623. X    drawWindowFast(scroll_window, row1, row2, 0, scroll_window->nCols-1 );
  2624. X    return rowsScrolled;
  2625. X}
  2626. X
  2627. X/*ARGSUSED*/
  2628. static void
  2629. repeatVScroll( clientData )
  2630. X    ClientData clientData;
  2631. X{
  2632. X    (void)DoOneVScroll();
  2633. X    timer_token = Tk_CreateTimerHandler( 100, repeatVScroll, 0 );
  2634. X}
  2635. X
  2636. void
  2637. VScroll( w, how, y, button )
  2638. X    struct window *w;
  2639. X    int how;
  2640. X    int y;
  2641. X    int button;
  2642. X{
  2643. X    /* how = 0 ==> tk scrolling */
  2644. X    /* how = 1 ==> button press */
  2645. X    /* how = 2 ==> button release */
  2646. X    /* how = 3 ==> button motion */
  2647. X    extern int button1ScrollsDown;
  2648. X
  2649. X    int row1, row;
  2650. X    int fid = w->fileId;
  2651. X    Offset cp, offset;
  2652. X    int top_unit;
  2653. X    int delta, inwindow;
  2654. X    int scrollbar_height;
  2655. X
  2656. X    scroll_window = w;
  2657. X    switch( how ) {
  2658. X    case 0:        /* Tk scrolling */
  2659. X        top_unit = y;
  2660. X        inwindow = w->posBotline - w->posTopline;
  2661. X        if( inwindow < 1 )
  2662. X            inwindow = 1;
  2663. X        delta = top_unit - w->posTopline;
  2664. X        if( delta < 0 ) {
  2665. X            delta = -delta;
  2666. X            scrollDown = 0;
  2667. X        } else
  2668. X            scrollDown = 1;
  2669. X        intervalRows = (w->nRows * delta) / inwindow;
  2670. X        if( intervalRows < 1 )
  2671. X            intervalRows = 1;
  2672. X        (void)DoOneVScroll();
  2673. X        break;
  2674. X    case 1:        /* button press */
  2675. X        intervalRows = (y - w->topMargin) / (w->font).height;
  2676. X        /* always scroll at least one line */
  2677. X        if( intervalRows < 1 )
  2678. X            intervalRows = 1;
  2679. X        switch( button ) {
  2680. X        case 1:
  2681. X            scrollDown = button1ScrollsDown;
  2682. X            break;
  2683. X        case 2:
  2684. X            goto thumbing;
  2685. X        case 3:
  2686. X            scrollDown = 1 - button1ScrollsDown;
  2687. X            break;
  2688. X        }
  2689. X        if( !timerIsOn ) {
  2690. X            (void)DoOneVScroll();
  2691. X            timer_token = Tk_CreateTimerHandler( 300,
  2692. X                            repeatVScroll, 0 );
  2693. X            timerIsOn = 1;
  2694. X        }
  2695. X        break;
  2696. X    case 2:        /* (left or right) button release */
  2697. X        if( timerIsOn ) {
  2698. X            timerIsOn = 0;
  2699. X            Tk_DeleteTimerHandler( timer_token );
  2700. X        }
  2701. X        return;
  2702. X    case 3:        /* (middle) button motion */
  2703. X    thumbing:
  2704. X        /* we get negative y values when the (grabbed) mouse goes */
  2705. X        /* above the scroll bar area.  Consider them zero. */
  2706. X        /* Also adjust for the case where the mouse pointer */
  2707. X        /* moves below the scrollbar area. */
  2708. X        scrollbar_height = Tk_Height(w->tk_text);
  2709. X        if( y < 0 )
  2710. X            y = 0;
  2711. X        else if( y > scrollbar_height )
  2712. X            y = scrollbar_height;
  2713. X        cp = fileSize( fid );
  2714. X        offset = (int)( ((double)y * cp) / scrollbar_height );
  2715. X        if( offset > cp )
  2716. X            offset = cp;
  2717. X        cp = w->posTopline;
  2718. X        row = w->numTopline;
  2719. X        while( cp < offset ) {
  2720. X            row1 = 1;
  2721. X            cp = nextLine( fid, cp, &row1 );
  2722. X            row += row1;
  2723. X        }
  2724. X        while( cp > offset ) {
  2725. X            row1 = 1;
  2726. X            cp = prevLine( fid, cp, &row1 );
  2727. X            row -= row1;
  2728. X        }
  2729. X        intervalRows = row - w->numTopline;
  2730. X        if( intervalRows == 0 )
  2731. X            return;
  2732. X        if( intervalRows < 0 ) {
  2733. X            intervalRows = -intervalRows;
  2734. X            scrollDown = 0;
  2735. X        } else
  2736. X            scrollDown = 1;
  2737. X        (void)DoOneVScroll();
  2738. X        break;
  2739. X    }
  2740. X}
  2741. X
  2742. X
  2743. void
  2744. topWindow(w)
  2745. X    register struct window *w;
  2746. X{
  2747. X    MakeWindowActive( w );
  2748. X}
  2749. X
  2750. void
  2751. ZoomWindow( w, how )
  2752. X    struct window *w;
  2753. X    int how;
  2754. X{
  2755. X    extern int display_height;
  2756. X    extern int display_width;
  2757. X    extern Display *MainDisplay;
  2758. X    extern int debug;
  2759. X
  2760. X    if( w->oldWidth == 0 ) {    /* not zoomed */
  2761. X        /* first save the present geometry */
  2762. X        w->oldX = Tk_X( w->tk_toplevel );
  2763. X        w->oldY = Tk_Y( w->tk_toplevel );
  2764. X        w->oldWidth = Tk_Width( w->tk_toplevel );
  2765. X        w->oldHeight = Tk_Height( w->tk_toplevel );
  2766. X
  2767. X        /* now set up to zoomed geometry */
  2768. X        Tk_MoveResizeWindow( w->tk_toplevel,
  2769. X            (how ? 4 : w->oldX),
  2770. X            3,
  2771. X            (how ? display_width-8 : w->oldWidth),
  2772. X            display_height-37
  2773. X        );
  2774. X    } else {    /* unzoom */
  2775. X        /* restore the old geometry */
  2776. X        Tk_MoveResizeWindow( w->tk_toplevel,
  2777. X            w->oldX, w->oldY-25, w->oldWidth, w->oldHeight );
  2778. X        /* set up so that it indicates not zoomed */
  2779. X        w->oldWidth = 0;
  2780. X    }
  2781. X}
  2782. X
  2783. struct window *
  2784. GetNewFile(w, fileName, geometry)
  2785. X    struct window * w;
  2786. X    char * fileName;
  2787. X    char * geometry;
  2788. X{
  2789. X    extern char msgBuffer[];
  2790. X    extern char textBuffer[];
  2791. X    extern char * returnString;
  2792. X
  2793. X    int n;
  2794. X
  2795. X    if( fileName == NULL ) {
  2796. cancelWindow:
  2797. X        msg("New file cancelled", 1);
  2798. X        return NULL;
  2799. X    }
  2800. X    fileName = noWhiteSpace(fileName);
  2801. X    strcpy(textBuffer, fileName);
  2802. X    if( access(textBuffer, 0) == -1 ) {
  2803. X        sprintf( msgBuffer,
  2804. X            "MakeModalYesNo \"%s\" \"%s %s %s\" \"%s\" \"%s\"",
  2805. X            "Create file?",
  2806. X            "File", fileName, "does not exist.",
  2807. X            "Create it",
  2808. X            "Cancel new file" );
  2809. X        (void)ExecTclCommand( msgBuffer );
  2810. X        command( FWAITFORRETURNSTRING, "","","","","","");
  2811. X        if( returnString[0] != 'y' ) {
  2812. X            goto cancelWindow;
  2813. X        }
  2814. X        n = open(textBuffer, O_CREAT, 0644);
  2815. X        if( n < 0 ) {
  2816. X            sprintf(msgBuffer, "Cannot create %s: ", textBuffer);
  2817. X            msg(msgBuffer, 1);
  2818. X            goto cancelWindow;
  2819. X        } else
  2820. X            close(n);
  2821. X    }
  2822. X    return createWindow( w, textBuffer, geometry );
  2823. X}
  2824. X
  2825. X
  2826. struct window *
  2827. XFindWindowByTkName( name )
  2828. X    char * name;
  2829. X{
  2830. X    extern struct window * windowList;
  2831. X
  2832. X    struct window * w = windowList;
  2833. X    Tk_Uid uid_of_name = Tk_GetUid( name );
  2834. X
  2835. X    while( w != NULL ) {
  2836. X        if( w->tk_pathname == uid_of_name  )
  2837. X            break;
  2838. X        w = w->nextWindow;
  2839. X    }
  2840. X    return w;
  2841. X}
  2842. X
  2843. void
  2844. bottomFile( w )
  2845. X    struct window *w;
  2846. X{
  2847. X    extern int debug;
  2848. X
  2849. X    Offset cp;
  2850. X    int j;
  2851. X    int i;
  2852. X    int fid = w->fileId;
  2853. X
  2854. X    if( w == NULL )
  2855. X        return;
  2856. X    /* remember where we came from */
  2857. X    w->rowLastline = w->numTopline;
  2858. X    cp = w->posBotline;
  2859. X
  2860. X    /* find the last line of the file */
  2861. X    i = 0;
  2862. X    while( 1 ) {
  2863. X        j = 1;
  2864. X        cp = nextLine( fid, cp, &j );
  2865. X        /* if j==0, we could not go down a line */
  2866. X        /* so we are at the end */
  2867. X        if( j == 0 )
  2868. X            break;
  2869. X        ++i;
  2870. X    }
  2871. X    ++i;    /* one more line so EOF mark shows */
  2872. X
  2873. X    /* now move the window down and redraw it */
  2874. X    j = i;    /* since i is a register variable, we must use j here */
  2875. X    w->posTopline = nextLine( fid, w->posTopline, &j );
  2876. X    w->posBotline = cp;
  2877. X    w->numTopline += j;
  2878. X    w->numBotline += j;
  2879. X    w->indent = 0;
  2880. X    drawWindow(w);
  2881. X}
  2882. X
  2883. END_OF_FILE
  2884. if test 18315 -ne `wc -c <'windows.c'`; then
  2885.     echo shar: \"'windows.c'\" unpacked with wrong size!
  2886. fi
  2887. # end of 'windows.c'
  2888. fi
  2889. echo shar: End of archive 7 \(of 15\).
  2890. cp /dev/null ark7isdone
  2891. MISSING=""
  2892. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ; do
  2893.     if test ! -f ark${I}isdone ; then
  2894.     MISSING="${MISSING} ${I}"
  2895.     fi
  2896. done
  2897. if test "${MISSING}" = "" ; then
  2898.     echo You have unpacked all 15 archives.
  2899.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2900. else
  2901.     echo You still need to unpack the following archives:
  2902.     echo "        " ${MISSING}
  2903. fi
  2904. ##  End of shell archive.
  2905. exit 0
  2906. -- 
  2907. --
  2908. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  2909. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  2910. Sunnyvale, California 94086            at&t: 408/522-9236
  2911.