home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2977 < prev    next >
Internet Message Format  |  1991-03-04  |  55KB

  1. From: guido@cwi.nl (Guido van Rossum)
  2. Newsgroups: alt.sources
  3. Subject: STDWIN 0.9.5, Part 16/19
  4. Message-ID: <3080@charon.cwi.nl>
  5. Date: 4 Mar 91 11:58:28 GMT
  6.  
  7. Archive-name: stdwin/part16
  8.  
  9. #! /bin/sh
  10. # This is a shell archive.  Remove anything before this line, then unpack
  11. # it by saving it into a file and typing "sh file".  To overwrite existing
  12. # files, type "sh file -c".  You can also feed this as standard input via
  13. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  14. # will see the following message at the end:
  15. #        "End of archive 16 (of 19)."
  16. # Contents:  Appls/bed/file.c Appls/bed/fmenu.c Appls/dpv/dpvdoc.h
  17. #   Appls/dpv/dpvmachine.c Appls/dpv/dpvmachine.h Appls/test/bike.c
  18. #   Appls/test/bits.c Appls/test/charset.c Appls/test/dklok.c
  19. #   H/lists.h H/patchlevel.h H/winreq.h Packs/vt/vtresize.c
  20. #   Packs/vt/vtvtrm.c Ports/mac/caret.c Ports/vtrm/DIST/pag.c
  21. #   Ports/x11/scroll.c
  22. # Wrapped by guido@voorn.cwi.nl on Mon Mar  4 12:37:34 1991
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'Appls/bed/file.c' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'Appls/bed/file.c'\"
  26. else
  27. echo shar: Extracting \"'Appls/bed/file.c'\" \(2953 characters\)
  28. sed "s/^X//" >'Appls/bed/file.c' <<'END_OF_FILE'
  29. X#include <stdio.h>
  30. X#include "bed.h"
  31. X
  32. Xextern char    *rindex () ;
  33. X
  34. Xextern int    sqrsize ;
  35. X
  36. Xextern int    map_width ;
  37. Xextern int    map_height ;
  38. X
  39. Xextern char    *raster ;
  40. Xextern int    raster_lenght ;
  41. Xextern int    stride ;
  42. X
  43. Xextern char    *fname ;
  44. Xextern char    *title ;
  45. X
  46. Xextern WINDOW    *win ;
  47. X
  48. Xextern bool    changed ;
  49. X
  50. Xchar
  51. X*strip (fname)
  52. X    char    *fname ;
  53. X{
  54. X    char    *p ;
  55. X
  56. X    if ((p = rindex (fname, '/')) == NULL &&    /* UNIX              */
  57. X        (p = rindex (fname, '\\')) == NULL &&    /* GEMDOS & MSDOS     */
  58. X        (p = rindex (fname, ':')) == NULL)
  59. X        return (fname) ;
  60. X    return (p + 1) ;
  61. X}
  62. X
  63. Xbool
  64. Xinput(fp)
  65. X    FILE *fp;
  66. X{
  67. X    int    value ;
  68. X    char    ibuf[81] ;
  69. X    char    *id ;
  70. X    char    *p ;
  71. X    char    *type ;
  72. X    int    i ;
  73. X
  74. X    for (;;) {
  75. X        if (fgets (ibuf, 81, fp) == NULL)
  76. X            /*
  77. X            ** EOF
  78. X            */
  79. X            break ;
  80. X
  81. X        if (strlen (ibuf) == 80) {
  82. X            /*
  83. X            ** Line too long, not a bitmap file
  84. X            */
  85. X            fclose (fp) ;
  86. X            return (FALSE) ;
  87. X        }
  88. X
  89. X        if (strncmp (ibuf, "#define ", 8) == 0) {
  90. X            id = ibuf + 8 ;
  91. X            if ((type = rindex (id, '_')) == NULL)
  92. X                type = id ;
  93. X            else
  94. X                type++ ;
  95. X
  96. X            if (!strncmp (type, "width", 5)) {
  97. X                map_width = atoi (type + 5) ;
  98. X            }
  99. X
  100. X            if (!strncmp (type, "height", 6)) {
  101. X                map_height = atoi (type + 6) ;
  102. X            }
  103. X
  104. X            continue ;
  105. X        }
  106. X
  107. X        if (strncmp (ibuf, "static unsigned char ", 21) == 0)
  108. X            id = ibuf + 21 ;
  109. X        else if (strncmp (ibuf, "static char ", 12) == 0)
  110. X            id = ibuf + 12 ;
  111. X        else
  112. X            continue ;
  113. X
  114. X        if ((type = rindex (id, '_')) == NULL)
  115. X            type = id ;
  116. X        else
  117. X            type++ ;
  118. X
  119. X        if (strncmp (type, "bits[]", 6) != 0)
  120. X            continue ;
  121. X
  122. X        newraster () ;
  123. X
  124. X        for (i = 0, p = raster ; i < raster_lenght ; ++i, ++p) {
  125. X            if (fscanf (fp, " 0x%2x%*[,}]%*[  \n]", &value) != 1) {
  126. X                free (raster) ;
  127. X                raster = NULL ;
  128. X                fclose (fp) ;
  129. X                return (FALSE) ;
  130. X            }
  131. X            *p = value ;
  132. X        }
  133. X    }
  134. X
  135. X    fclose (fp) ;
  136. X    return (TRUE) ;
  137. X}
  138. X
  139. Xbool
  140. Xreadbitmap ()
  141. X{
  142. X    FILE    *fp ;
  143. X    char    namebuf[256] ;
  144. X
  145. X    if (fname == NULL) {
  146. X        namebuf[0] = 0 ;
  147. X
  148. X        if (!waskfile ("Read file", namebuf, sizeof (namebuf), FALSE))
  149. X            return (FALSE) ;
  150. X
  151. X        fname = strdup (namebuf) ;
  152. X        title = strip (fname) ;
  153. X
  154. X        wsettitle (win, title) ;
  155. X    }
  156. X
  157. X    fp = fopen (fname, "r") ;
  158. X    if (fp == NULL) {
  159. X        perror(fname);
  160. X        return (FALSE) ;
  161. X    }
  162. X
  163. X    return (input(fp)) ;
  164. X}
  165. X
  166. Xvoid
  167. Xoutput(fp)
  168. X    FILE    *fp ;
  169. X{
  170. X    int    i ;
  171. X
  172. X    fprintf (fp, "#define %s_width\t%d\n", title, map_width) ;
  173. X    fprintf (fp, "#define %s_height\t%d\n", title, map_height) ;
  174. X    fprintf (fp, "static char %s_bits[] {\n   0x%02x", title,
  175. X                            raster[0] & 0xFF) ;
  176. X
  177. X    for (i = 1 ; i < raster_lenght ; ++i) {
  178. X        fprintf (fp, i % 12 ? ", " : ",\n   ") ;
  179. X        fprintf (fp, "0x%02x", raster[i] & 0xFF) ;
  180. X    }
  181. X    fprintf (fp, "};\n") ;
  182. X}
  183. X
  184. Xbool
  185. Xwritebitmap()
  186. X{
  187. X    FILE    *fp;
  188. X    char    namebuf[256];
  189. X    
  190. X    namebuf[0] = '\0' ;
  191. X    if (fname == NULL) {
  192. X        if (!waskfile ("Save as", namebuf, sizeof (namebuf), TRUE))
  193. X            return (FALSE) ;
  194. X        fname = strdup (namebuf) ;
  195. X        title = strip (namebuf) ;
  196. X        wsettitle (win, title) ;
  197. X    }
  198. X
  199. X    fp = fopen (fname, "w") ;
  200. X    if (fp == NULL) {
  201. X        wperror (fname) ;
  202. X        return (FALSE) ;
  203. X    }
  204. X
  205. X    output (fp) ; 
  206. X    fclose (fp) ;
  207. X    return (TRUE) ;
  208. X}
  209. X
  210. END_OF_FILE
  211. if test 2953 -ne `wc -c <'Appls/bed/file.c'`; then
  212.     echo shar: \"'Appls/bed/file.c'\" unpacked with wrong size!
  213. fi
  214. # end of 'Appls/bed/file.c'
  215. fi
  216. if test -f 'Appls/bed/fmenu.c' -a "${1}" != "-c" ; then 
  217.   echo shar: Will not clobber existing file \"'Appls/bed/fmenu.c'\"
  218. else
  219. echo shar: Extracting \"'Appls/bed/fmenu.c'\" \(2781 characters\)
  220. sed "s/^X//" >'Appls/bed/fmenu.c' <<'END_OF_FILE'
  221. X#include <stdio.h>
  222. X#include "bed.h"
  223. X#include "menu.h"
  224. X
  225. Xextern char    *strip () ;
  226. X
  227. Xextern int    sqrsize ;
  228. X
  229. Xextern int    map_width ;
  230. Xextern int    map_height ;
  231. X
  232. Xextern char    *fname ;
  233. Xextern char    *title ;
  234. X
  235. Xextern WINDOW    *win ;
  236. X
  237. Xextern char    *raster ;
  238. X
  239. Xextern bool    changed ;
  240. X
  241. Xvoid
  242. Xdo_open_file ()
  243. X{
  244. X    if (changed) {
  245. X        switch (waskync ("Save changes ?", 1)) {
  246. X        case 1:
  247. X            if (!writebitmap ())
  248. X                return ;
  249. X            break ;
  250. X        case -1 :
  251. X            return ;
  252. X        }
  253. X
  254. X        changed = FALSE ;
  255. X    }
  256. X    if (fname != NULL) {
  257. X        free (fname) ;
  258. X        fname = title = NULL ;
  259. X    }
  260. X
  261. X    if (!readbitmap ()) {
  262. X        if (fname != NULL) {
  263. X            free (fname) ;
  264. X            fname = title = NULL ;
  265. X            wsettitle (win, "Untitled") ;
  266. X        }
  267. X
  268. X        newraster () ;
  269. X    }
  270. X}
  271. X
  272. Xvoid
  273. Xdo_new_map ()
  274. X{
  275. X    char    str[20] ;
  276. X
  277. X    if (changed) {
  278. X        switch (waskync ("Save changes ?", 1)) {
  279. X        case 1 :
  280. X            if (!writebitmap ())
  281. X                return ;
  282. X            break ;
  283. X        case -1 :
  284. X            return ;
  285. X        }
  286. X
  287. X        changed = FALSE ;
  288. X    }
  289. X
  290. X    if (fname != NULL) {
  291. X        free (fname) ;
  292. X        fname = title = NULL ;
  293. X        wsettitle (win, "Untitled") ;
  294. X    }
  295. X
  296. X    *str = 0 ;
  297. X
  298. X    if (waskstr ("Enter width of new raster", str, 20)) {
  299. X        while ((map_width = atoi (str)) <= 0) {
  300. X            *str = 0 ;
  301. X            if (!waskstr ("Please enter a number greater 0",
  302. X                                str, 20)) {
  303. X                map_width = -1 ;
  304. X                break ;
  305. X            }
  306. X        }
  307. X
  308. X        if (waskstr ("Enter height of new raster", str, 20)) {
  309. X            while ((map_height = atoi (str)) <= 0) {
  310. X                *str = 0 ;
  311. X                if (!waskstr ("Please enter a number greater 0",
  312. X                                str, 20))
  313. X                    break ;
  314. X            }
  315. X        }
  316. X        else
  317. X            map_width = -1 ;
  318. X    }
  319. X
  320. X    if (map_width == -1) {
  321. X        map_width = DEF_COLS ;
  322. X        map_height = DEF_ROWS ;
  323. X    }
  324. X
  325. X    newraster () ;
  326. X}
  327. X
  328. Xbool
  329. Xdo_quit ()
  330. X{
  331. X    if (changed) {
  332. X        switch (waskync ("Save changes ?", 1)) {
  333. X        case 1 :
  334. X            if (!writebitmap ())
  335. X                return (FALSE) ;
  336. X            break ;
  337. X        case -1 :
  338. X            return (FALSE) ;
  339. X        }
  340. X
  341. X        changed = FALSE ;
  342. X    }
  343. X    wclose (win) ;
  344. X    free (raster) ;
  345. X    raster = NULL ;
  346. X    return (TRUE) ;
  347. X}
  348. X
  349. Xbool
  350. Xdo_file_menu (ep)
  351. X    EVENT    *ep ;
  352. X{
  353. X    switch (ep->u.m.item) {
  354. X    case OPEN_ITEM:
  355. X        do_open_file () ;
  356. X        setsqrsize () ;
  357. X        wchange (win, 0, 0, map_width * sqrsize,
  358. X                        map_height * sqrsize) ;
  359. X        wsetdocsize (win, map_width * sqrsize, map_height * sqrsize) ;
  360. X        break ;
  361. X    case NEW_ITEM:
  362. X        do_new_map () ;
  363. X        setsqrsize () ;
  364. X        wchange (win, 0, 0, map_width * sqrsize,
  365. X                        map_height * sqrsize) ;
  366. X        wsetdocsize (win, map_width * sqrsize, map_height * sqrsize) ;
  367. X        break ;
  368. X    case SAVE_ITEM:
  369. X        if (changed) {
  370. X            if (writebitmap ())
  371. X                changed = FALSE ;
  372. X        }
  373. X        break ;
  374. X    case SAVE_AS_ITEM: {
  375. X        char    namebuf[256] ;
  376. X
  377. X        strcpy (namebuf, fname) ;
  378. X        if (waskstr ("Save as ?", namebuf, 256, FALSE)) {
  379. X            char    *savedname = fname ;
  380. X
  381. X            fname = strdup (namebuf) ;
  382. X            title = strip (fname) ;
  383. X            (void) writebitmap () ;
  384. X            free (fname) ;
  385. X            fname = savedname ;
  386. X            title = strip (fname) ;
  387. X        }
  388. X        break ;
  389. X        }
  390. X    case QUIT_ITEM:
  391. X        return (do_quit ()) ;
  392. X    }
  393. X
  394. X    return (FALSE) ;
  395. X}
  396. END_OF_FILE
  397. if test 2781 -ne `wc -c <'Appls/bed/fmenu.c'`; then
  398.     echo shar: \"'Appls/bed/fmenu.c'\" unpacked with wrong size!
  399. fi
  400. # end of 'Appls/bed/fmenu.c'
  401. fi
  402. if test -f 'Appls/dpv/dpvdoc.h' -a "${1}" != "-c" ; then 
  403.   echo shar: Will not clobber existing file \"'Appls/dpv/dpvdoc.h'\"
  404. else
  405. echo shar: Extracting \"'Appls/dpv/dpvdoc.h'\" \(2487 characters\)
  406. sed "s/^X//" >'Appls/dpv/dpvdoc.h' <<'END_OF_FILE'
  407. X/* dpv -- ditroff previewer.  Description of input language. */
  408. X
  409. X/* This isn't really a source file but disguised as one it is
  410. X   more likely to be distributed with the rest of the source */
  411. X
  412. X/******************************************************************************
  413. X
  414. X    output language from ditroff:
  415. X    all numbers are character strings
  416. X    
  417. X    (These comments should suffice to write my own ditroff output
  418. X    filter, but I'm lazy...  Note that the parser expects its input to
  419. X    be error-free -- it contains unchecked fscanf calls all over.
  420. X    Also it is not clear whether relative motions may have negative
  421. X    numbers as parameters.  For filters descending from BWK's prototype
  422. X    this works for 'v' but not for 'h', as 'v' uses fscan but 'h'
  423. X    reads characters until it finds a non-digit...  GvR)
  424. X
  425. X{    push environment (font, size, position)
  426. X}    pop environment
  427. X#..\n    comment
  428. Xsn    size in points
  429. Xfn    font as number from 1 to n
  430. Xcx    ascii character x
  431. XCxyz    funny char \(xyz. terminated by white space
  432. XHn    go to absolute horizontal position n
  433. XVn    go to absolute vertical position n (down is positive)
  434. Xhn    go n units horizontally (relative)
  435. Xvn    ditto vertically
  436. Xnnc    move right nn, then print c (exactly 2 digits!)
  437. X        (this wart is an optimization that shrinks output file size
  438. X         about 35% and run-time about 15% while preserving ascii-ness)
  439. Xpn    new page begins (number n) -- set v to 0
  440. XP    spread ends -- output it. (Put in by vsort).
  441. Xnb a    end of line (information only -- no action needed)
  442. X    b = space before line, a = after
  443. Xw    paddable word space -- no action needed
  444. X
  445. XDt ..\n    draw operation 't':
  446. X    Dl x y        line from here by x,y (drawing char .)
  447. X            (affects position by x, y -- GvR)
  448. X    Dc d        circle of diameter d with left side here
  449. X    De x y        ellipse of axes x,y with left side here
  450. X    Da x y x1 y1    arc; see drawarc in dpvoutput.c for description
  451. X    D~ x y x y ...    B-spline curve by x,y then x,y ...
  452. X
  453. Xx ..\n    device control functions:
  454. X     x i    init
  455. X     x T s    name of device is s
  456. X     x r n h v    resolution is n/inch h = min horizontal motion, v = min vert
  457. X     x p    pause (can restart)
  458. X     x s    stop -- done for ever
  459. X     x t    generate trailer
  460. X     x f n s    font position n contains font s
  461. X             (there appears to be some disagreement whether this also
  462. X             selects s as the current font -- GvR)
  463. X     x H n    set character height to n
  464. X     x S n    set slant to N
  465. X
  466. X    Subcommands like "i" are often spelled out like "init".
  467. X
  468. X******************************************************************************/
  469. END_OF_FILE
  470. if test 2487 -ne `wc -c <'Appls/dpv/dpvdoc.h'`; then
  471.     echo shar: \"'Appls/dpv/dpvdoc.h'\" unpacked with wrong size!
  472. fi
  473. # end of 'Appls/dpv/dpvdoc.h'
  474. fi
  475. if test -f 'Appls/dpv/dpvmachine.c' -a "${1}" != "-c" ; then 
  476.   echo shar: Will not clobber existing file \"'Appls/dpv/dpvmachine.c'\"
  477. else
  478. echo shar: Extracting \"'Appls/dpv/dpvmachine.c'\" \(2989 characters\)
  479. sed "s/^X//" >'Appls/dpv/dpvmachine.c' <<'END_OF_FILE'
  480. X/* dpv -- ditroff previewer.  Ditroff virtual machine. */
  481. X
  482. X#include "dpv.h"
  483. X#include "dpvmachine.h"
  484. X#include "dpvoutput.h"
  485. X
  486. X/* Basic state */
  487. X
  488. Xint    size;        /* current point size */
  489. Xint    font;        /* current font */
  490. Xint    hpos;        /* horizontal position we are to be at next; left=0 */
  491. Xint    vpos;        /* current vertical position (down positive) */
  492. X
  493. X/* Environment */
  494. X
  495. X
  496. Xstruct    state    state[MAXSTATE];
  497. Xstruct    state    *statep = state;
  498. X
  499. X/* Mounted font table */
  500. X
  501. Xfontinfo fonts;
  502. Xint    nfonts = 0;    /* start with no fonts mounted */
  503. X
  504. X/* Page info */
  505. X
  506. Xint    ipage;        /* internal page number */
  507. X
  508. X/* Global info */
  509. X
  510. Xint    res = 432;    /* resolution for which input was prepared */
  511. X            /* default is old troff resolution */
  512. X
  513. X/* Load font info for font s on position n; optional file name s1 */
  514. X
  515. Xloadfont(n, s, s1)
  516. X    int n;
  517. X    char *s, *s1;
  518. X{
  519. X    if (n < 0 || n > NFONTS)
  520. X        error(FATAL, "can't load font %d", n);
  521. X    fonts.name[n]= strdup(s);
  522. X}
  523. X
  524. X/* Initialize device */
  525. X
  526. Xt_init()
  527. X{
  528. X    /* Start somewhere */
  529. X    hpos = vpos = 0;
  530. X    size= 10;
  531. X    font= 1;
  532. X    usefont();
  533. X}
  534. X
  535. X/* Begin a new block */
  536. X
  537. Xt_push()
  538. X{
  539. X    if (statep >= state+MAXSTATE)
  540. X        error(FATAL, "{ nested too deep");
  541. X    statep->ssize = size;
  542. X    statep->sfont = font;
  543. X    statep->shpos = hpos;
  544. X    statep->svpos = vpos;
  545. X    ++statep;
  546. X}
  547. X
  548. X/* Pop to previous state */
  549. X
  550. Xt_pop()
  551. X{
  552. X    if (--statep < state)
  553. X        error(FATAL, "extra }");
  554. X    size = statep->ssize;
  555. X    font = statep->sfont;
  556. X    hpos = statep->shpos;
  557. X    vpos = statep->svpos;
  558. X    usefont();
  559. X}
  560. X
  561. X/* Called at the start of a new page.
  562. X   Returns < 0 if it is time to stop. */
  563. X
  564. Xint
  565. Xt_page(n)
  566. X    int n;
  567. X{
  568. X    if (nextpage(n) < 0)
  569. X        return -1;
  570. X    vpos = hpos = 0;
  571. X    usefont();
  572. X    return 0;
  573. X}
  574. X
  575. X/* Do whatever for the end of a line */
  576. X
  577. Xt_newline()
  578. X{
  579. X    hpos = 0;    /* because we're now back at the left margin */
  580. X}
  581. X
  582. X/* Convert integer to internal size number */
  583. X
  584. Xt_size(n)
  585. X    int n;
  586. X{
  587. X    return n;
  588. X}
  589. X
  590. X/* Set character height to n */
  591. X
  592. X/*ARGSUSED*/
  593. Xt_charht(n)
  594. X    int n;
  595. X{
  596. X    static bool warned;
  597. X    if (!warned) {
  598. X        error(WARNING, "Setting character height not implemented");
  599. X        warned= TRUE;
  600. X    }
  601. X}
  602. X
  603. X/* Set slant to n */
  604. X
  605. X/*ARGSUSED*/
  606. Xt_slant(n)
  607. X    int n;
  608. X{
  609. X    static bool warned;
  610. X    if (!warned) {
  611. X        error(WARNING, "Setting slant not implemented");
  612. X        warned= TRUE;
  613. X    }
  614. X}
  615. X
  616. X/* Convert string to font number */
  617. X
  618. Xt_font(s)
  619. X    char *s;
  620. X{
  621. X    return atoi(s);
  622. X}
  623. X
  624. X/* Print string s as text */
  625. X
  626. Xt_text(s)
  627. X    char *s;
  628. X{
  629. X    int c;
  630. X    char str[100];
  631. X    
  632. X    /* XXX This function doesn't work any more since lastw is not set */
  633. X
  634. X    while (c = *s++) {
  635. X        if (c == '\\') {
  636. X            switch (c = *s++) {
  637. X            case '\\':
  638. X            case 'e':
  639. X                put1('\\');
  640. X                break;
  641. X            case '(':
  642. X                str[0] = *s++;
  643. X                str[1] = *s++;
  644. X                str[2] = EOS;
  645. X                put1s(str);
  646. X                break;
  647. X            }
  648. X        } else {
  649. X            put1(c);
  650. X        }
  651. X        /*hmot(lastw);*/
  652. X    }
  653. X}
  654. X
  655. X/* Reset; argument is 'p' for pause, 's' for start */
  656. X
  657. Xt_reset(c)
  658. X    int c;
  659. X{
  660. X    if (c == 's')
  661. X        lastpage();
  662. X}
  663. X
  664. X/* Absolute vertical motion to position n */
  665. X
  666. Xvgoto(n)
  667. X    int n;
  668. X{
  669. X    vpos = n;
  670. X    recheck();
  671. X}
  672. X
  673. X/* Set point size to n */
  674. X
  675. Xsetsize(n)
  676. Xint n;
  677. X{
  678. X    size = n;
  679. X    usefont();
  680. X}
  681. X
  682. X/* Set font to n */
  683. X
  684. Xsetfont(n)
  685. Xint n;
  686. X{
  687. X    font = n;
  688. X    usefont();
  689. X}
  690. END_OF_FILE
  691. if test 2989 -ne `wc -c <'Appls/dpv/dpvmachine.c'`; then
  692.     echo shar: \"'Appls/dpv/dpvmachine.c'\" unpacked with wrong size!
  693. fi
  694. # end of 'Appls/dpv/dpvmachine.c'
  695. fi
  696. if test -f 'Appls/dpv/dpvmachine.h' -a "${1}" != "-c" ; then 
  697.   echo shar: Will not clobber existing file \"'Appls/dpv/dpvmachine.h'\"
  698. else
  699. echo shar: Extracting \"'Appls/dpv/dpvmachine.h'\" \(2383 characters\)
  700. sed "s/^X//" >'Appls/dpv/dpvmachine.h' <<'END_OF_FILE'
  701. X/* dpv -- ditroff previewer.  Definitions for ditroff virtual machine. */
  702. X
  703. X/* The ditroff machine has the following state information:
  704. X
  705. X   Basic state:
  706. X   - hpos, vpos        print head position on current page
  707. X   - size        current point size
  708. X   - font        current font number (range 0..NFONTS-1)
  709. X   
  710. X   Environment:
  711. X   - a stack containing up to MAXSTATE copies of the basic state
  712. X   
  713. X   Mounted font table:
  714. X   - a mapping from font number to (ditroff) font names
  715. X     (i.e., which font is mounted on which logical position)
  716. X   
  717. X   Page info:
  718. X   - current page number
  719. X   
  720. X   Global info (not used much):
  721. X   - typesetter name
  722. X   - resolution assumed when preparing
  723. X   - page dimensions
  724. X   - etc.?
  725. X   
  726. X   To restart the machine at a given page, we need to save and restore
  727. X   the basic state, environment and mounted font table.
  728. X   It could be argued that at page boundaries the environment stack
  729. X   should be empty, and that the mounted font table should be initialized
  730. X   once and for ever.
  731. X   The latter isn't the case in practice; ".fp" requests can be and are
  732. X   used anywhere in ditroff source files.
  733. X   Because the environment pushes the (page-relative) position, it is
  734. X   unlikely that restoring an environment on a different page makes any
  735. X   sense, so we could assume this (and check that the input conforms).
  736. X*/
  737. X
  738. X/* Array dimensions */
  739. X
  740. X#define    NFONTS   65    /* total number of fonts usable */
  741. X#define    MAXSTATE 6    /* number of environments rememberable */
  742. X
  743. X/* Basic state */
  744. X
  745. Xextern int    hpos;    /* horizontal position we are to be at next; left=0 */
  746. Xextern int    vpos;    /* current vertical position (down positive) */
  747. Xextern int    size;    /* current point size */
  748. Xextern int    font;    /* current font */
  749. X
  750. X#define  hmot(n)    hpos += n
  751. X#define  hgoto(n)    hpos = n
  752. X#define  vmot(n)    vgoto(vpos + (n))
  753. Xextern vgoto();
  754. X
  755. X/* Environment */
  756. X
  757. Xstruct state {
  758. X    int    ssize;
  759. X    int    sfont;
  760. X    int    shpos;
  761. X    int    svpos;
  762. X};
  763. X
  764. Xextern struct    state    state[MAXSTATE];
  765. Xextern struct    state    *statep;
  766. X
  767. Xextern t_push();
  768. Xextern t_pop();
  769. X
  770. X/* Mounted font table */
  771. X
  772. Xtypedef struct _fontinfo {
  773. X    char *name[NFONTS];
  774. X} fontinfo;
  775. X
  776. Xextern fontinfo fonts;    /* current mounted font table */
  777. Xextern int    nfonts;    /* number of used entries (0..nfonts-1) */
  778. X
  779. X/* Page info */
  780. X
  781. Xextern int    ipage;    /* internal page number */
  782. X
  783. X/* Global typesetter info */
  784. X
  785. Xextern int    res;    /* resolution for which input was prepared */
  786. X            /* default is old troff resolution */
  787. END_OF_FILE
  788. if test 2383 -ne `wc -c <'Appls/dpv/dpvmachine.h'`; then
  789.     echo shar: \"'Appls/dpv/dpvmachine.h'\" unpacked with wrong size!
  790. fi
  791. # end of 'Appls/dpv/dpvmachine.h'
  792. fi
  793. if test -f 'Appls/test/bike.c' -a "${1}" != "-c" ; then 
  794.   echo shar: Will not clobber existing file \"'Appls/test/bike.c'\"
  795. else
  796. echo shar: Extracting \"'Appls/test/bike.c'\" \(2785 characters\)
  797. sed "s/^X//" >'Appls/test/bike.c' <<'END_OF_FILE'
  798. X#include "stdwin.h"
  799. X#include "tilist.h"
  800. X
  801. X#define NFRONT    3
  802. X#define NBACK    6
  803. X
  804. X#define VSTEP 50
  805. X#define HSCALE 470
  806. X
  807. X#define TIPWIDTH 40
  808. X
  809. Xint front[NFRONT] = {28, 38, 48};
  810. Xint back[NBACK] = {28, 24, 20, 17, 15, 13};
  811. X
  812. Xdouble verzet[NFRONT][NBACK];
  813. Xdouble lowest, highest;
  814. X
  815. XWINDOW *win;
  816. X
  817. XTILIST *til;
  818. X
  819. XTEXTITEM *fronttips[NFRONT];
  820. XTEXTITEM *backtips[NBACK];
  821. X
  822. Xcalculate()
  823. X{
  824. X    int f, b;
  825. X    double v;
  826. X    
  827. X    lowest = 1e10;
  828. X    highest = 0.0;
  829. X    for (f = 0; f < NFRONT; ++f) {
  830. X        for (b = 0; b < NBACK; ++b) {
  831. X            v = (double)front[f] / (double)back[b];
  832. X            verzet[f][b] = v;
  833. X            if (v < lowest)
  834. X                lowest = v;
  835. X            if (v > highest)
  836. X                highest = v;
  837. X        }
  838. X    }
  839. X}
  840. X
  841. Xsetuptil()
  842. X{
  843. X    int f, b;
  844. X    int h, v;
  845. X    
  846. X    til = tilcreate(win);
  847. X    
  848. X    h = 0;
  849. X    v = 2;
  850. X    for (b = 0; b < NBACK; ++b) {
  851. X        backtips[b] = tiladd(til, h, v, h+TIPWIDTH-2, 0, 1);
  852. X        h += TIPWIDTH;
  853. X    }
  854. X    
  855. X    h = 0;
  856. X    v = 0;
  857. X    for (f = 0; f < NFRONT; ++f) {
  858. X        v += VSTEP;
  859. X        fronttips[f] = tiladd(til, h, v, h+TIPWIDTH-2, 0, 1);
  860. X    }
  861. X    
  862. X    settilvalues();
  863. X}
  864. X
  865. Xsettilvalues()
  866. X{
  867. X    int f, b;
  868. X    char buf[100];
  869. X    
  870. X    for (f = 0; f < NFRONT; ++f) {
  871. X        sprintf(buf, "%d", front[f]);
  872. X        tilsettext(fronttips[f], buf);
  873. X    }
  874. X    for (b = 0; b < NBACK; ++b) {
  875. X        sprintf(buf, "%d", back[b]);
  876. X        tilsettext(backtips[b], buf);
  877. X    }
  878. X}
  879. X
  880. Xgettilvalues()
  881. X{
  882. X    int f, b;
  883. X    char *text;
  884. X    
  885. X    for (f = 0; f < NFRONT; ++f) {
  886. X        text = tilgettext(fronttips[f]);
  887. X        sscanf(text, "%d", &front[f]);
  888. X    }
  889. X    for (b = 0; b < NBACK; ++b) {
  890. X        text = tilgettext(backtips[b]);
  891. X        sscanf(text, "%d", &back[b]);
  892. X    }
  893. X    settilvalues();
  894. X    calculate();
  895. X    wchange(win, 0, 0, 30000, 30000);
  896. X}
  897. X
  898. Xvoid
  899. Xdrawproc(win, left, top, right, bottom)
  900. X    WINDOW *win;
  901. X    int left, top, right, bottom;
  902. X{
  903. X    int f, b;
  904. X    int h, v;
  905. X    int lasth;
  906. X    
  907. X    tildraw(til, left, top, right, bottom);
  908. X    
  909. X    v = VSTEP;
  910. X    for (f = 0; f < NFRONT; ++f) {
  911. X        for (b = 0; b < NBACK; ++b) {
  912. X            h = (verzet[f][b] - lowest) *
  913. X                 (HSCALE - 2*TIPWIDTH) / (highest - lowest);
  914. X            h += 2*TIPWIDTH;
  915. X            wcprintf(50, h, v-2-wlineheight(), "%d", back[b]);
  916. X            wdrawbox(h-2, v-2, h+2, v+2);
  917. X            wcprintf(50, h, v+2, "%.2f", verzet[f][b]);
  918. X            if (b > 0) {
  919. X                wpaint(lasth+2, v-1, h-2, v+1);
  920. X            }
  921. X            lasth = h;
  922. X        }
  923. X        v += VSTEP;
  924. X    }
  925. X}
  926. X
  927. Xmain(argc, argv)
  928. X    int argc;
  929. X    char **argv;
  930. X{
  931. X    winitargs(&argc, &argv);
  932. X    calculate();
  933. X    wsetdefwinsize(HSCALE + 4*wcharwidth('0'), (NFRONT+1) * VSTEP);
  934. X    win = wopen("Bike", drawproc);
  935. X    wsetdocsize(win, HSCALE + 4*wcharwidth('0'), (NFRONT+1) * VSTEP);
  936. X    setuptil();
  937. X    for (;;) {
  938. X        EVENT e;
  939. X        wgetevent(&e);
  940. X        if (tilevent(til, &e))
  941. X            continue;
  942. X        switch (e.type) {
  943. X        case WE_COMMAND:
  944. X            switch (e.u.command) {
  945. X            case WC_CLOSE:
  946. X                quit();
  947. X                /*NOTREACHED*/
  948. X            case WC_CANCEL:
  949. X                settilvalues();
  950. X                break;
  951. X            case WC_RETURN:
  952. X                gettilvalues();
  953. X                break;
  954. X            }
  955. X            break;
  956. X        case WE_CLOSE:
  957. X            quit();
  958. X            /*NOTREACHED*/
  959. X        }
  960. X    }
  961. X}
  962. X
  963. Xquit()
  964. X{
  965. X    wclose(win);
  966. X    wdone();
  967. X    exit(0);
  968. X    /*NOTREACHED*/
  969. X}
  970. END_OF_FILE
  971. if test 2785 -ne `wc -c <'Appls/test/bike.c'`; then
  972.     echo shar: \"'Appls/test/bike.c'\" unpacked with wrong size!
  973. fi
  974. # end of 'Appls/test/bike.c'
  975. fi
  976. if test -f 'Appls/test/bits.c' -a "${1}" != "-c" ; then 
  977.   echo shar: Will not clobber existing file \"'Appls/test/bits.c'\"
  978. else
  979. echo shar: Extracting \"'Appls/test/bits.c'\" \(2694 characters\)
  980. sed "s/^X//" >'Appls/test/bits.c' <<'END_OF_FILE'
  981. X/* Here's a very simple bitmap editor.
  982. X   A window shows a magnified 64x64 bitmap
  983. X   which you can edit by clicking the mouse.
  984. X   Clicking on a bit that's off turns it on,
  985. X   clicking on one that's on turns it off.
  986. X   Drag the mouse to set or clear more bits.
  987. X   Additional facilities like saving to a file
  988. X   are left as exercises for the reader. */
  989. X
  990. X#include "stdwin.h"
  991. X
  992. X/* Bitmap dimensions */
  993. X
  994. X#define WIDTH 64
  995. X#define HEIGHT 64
  996. X
  997. X/* The bitmap */
  998. X
  999. Xchar bit[WIDTH][HEIGHT];
  1000. X
  1001. X/* Magnification factors.
  1002. X   (Should really be calculated from screen dimensions). */
  1003. X
  1004. Xint xscale= 5;
  1005. Xint yscale= 5;
  1006. X
  1007. X/* The window */
  1008. X
  1009. XWINDOW *win;
  1010. X
  1011. X/* Main program */
  1012. X
  1013. Xmain(argc, argv)
  1014. X    int argc;
  1015. X    char **argv;
  1016. X{
  1017. X    winitargs(&argc, &argv);
  1018. X    setup();
  1019. X    mainloop();
  1020. X    wdone();
  1021. X    exit(0);
  1022. X}
  1023. X
  1024. X/* Create the window */
  1025. X
  1026. Xsetup()
  1027. X{
  1028. X    extern void drawproc(); /* Forward */
  1029. X    
  1030. X    wsetdefwinsize(WIDTH*xscale, HEIGHT*yscale);
  1031. X    win= wopen("Bitmap Editor Demo", drawproc);
  1032. X    wsetdocsize(win, WIDTH*xscale, HEIGHT*yscale);
  1033. X}
  1034. X
  1035. X/* Main event loop */
  1036. X
  1037. Xmainloop()
  1038. X{
  1039. X    int value= 0;
  1040. X    
  1041. X    for (;;) {
  1042. X        EVENT e;
  1043. X        
  1044. X        wgetevent(&e);
  1045. X        
  1046. X        switch (e.type) {
  1047. X        
  1048. X        case WE_MOUSE_DOWN:
  1049. X            value= !getbit(e.u.where.h/xscale, e.u.where.v/yscale);
  1050. X            /* Fall through to next cases */
  1051. X        case WE_MOUSE_MOVE:
  1052. X        case WE_MOUSE_UP:
  1053. X            setbit(e.u.where.h/xscale, e.u.where.v/yscale, value);
  1054. X            break;
  1055. X        
  1056. X        case WE_COMMAND:
  1057. X            switch (e.u.command) {
  1058. X            case WC_CLOSE:
  1059. X            case WC_CANCEL:
  1060. X                return;
  1061. X            }
  1062. X        
  1063. X        case WE_CLOSE:
  1064. X            return;
  1065. X        
  1066. X        }
  1067. X    }
  1068. X}
  1069. X
  1070. X/* Draw procedure */
  1071. X
  1072. Xvoid
  1073. Xdrawproc(win, left, top, right, bottom)
  1074. X    WINDOW *win;
  1075. X{
  1076. X#ifdef UNOPTIMIZED
  1077. X    int h, v;
  1078. X
  1079. X    for (v= top/yscale; v*yscale < bottom; ++v) {
  1080. X        for (h= left/xscale; h*xscale < right; ++h) {
  1081. X            if (getbit(h, v))
  1082. X                wpaint(h*xscale, v*yscale,
  1083. X                    (h+1)*xscale, (v+1)*yscale);
  1084. X        }
  1085. X    }
  1086. X#else
  1087. X    int h, v;
  1088. X    int start;
  1089. X
  1090. X    for (v= top/yscale; v*yscale < bottom; ++v) {
  1091. X        start = -1;
  1092. X        for (h= left/xscale; h*xscale < right; ++h) {
  1093. X            if (getbit(h, v)) {
  1094. X                if (start == -1)
  1095. X                    start = h;
  1096. X            } else {
  1097. X                if (start != -1) {
  1098. X                    wpaint(start*xscale, v*yscale,
  1099. X                        h*xscale, (v+1)*yscale);
  1100. X                    start = -1;
  1101. X                }
  1102. X            }
  1103. X        }
  1104. X        if (start != -1)
  1105. X            wpaint(start*xscale, v*yscale, h*xscale, (v+1)*yscale);
  1106. X    }
  1107. X#endif
  1108. X}
  1109. X
  1110. X/* Macro to test for bit coordinates in range */
  1111. X
  1112. X#define INRANGE(h, v) ((v) >= 0 && (v) < HEIGHT && (h) >= 0 && (h) < WIDTH)
  1113. X
  1114. X/* Return a bit's value; return 0 if outside range */
  1115. X
  1116. Xint
  1117. Xgetbit(h, v)
  1118. X{
  1119. X    if (INRANGE(h, v))
  1120. X        return bit[h][v];
  1121. X    else
  1122. X        return 0;
  1123. X}
  1124. X
  1125. X/* Change a bit's value (if in range) and arrange for it to be drawn. */
  1126. X
  1127. Xsetbit(h, v, value)
  1128. X{
  1129. X    if (INRANGE(h, v) && bit[h][v] != value) {
  1130. X        bit[h][v]= value;
  1131. X        wchange(win, h*xscale, v*yscale, (h+1)*xscale, (v+1)*yscale);
  1132. X    }
  1133. X}
  1134. END_OF_FILE
  1135. if test 2694 -ne `wc -c <'Appls/test/bits.c'`; then
  1136.     echo shar: \"'Appls/test/bits.c'\" unpacked with wrong size!
  1137. fi
  1138. # end of 'Appls/test/bits.c'
  1139. fi
  1140. if test -f 'Appls/test/charset.c' -a "${1}" != "-c" ; then 
  1141.   echo shar: Will not clobber existing file \"'Appls/test/charset.c'\"
  1142. else
  1143. echo shar: Extracting \"'Appls/test/charset.c'\" \(2954 characters\)
  1144. sed "s/^X//" >'Appls/test/charset.c' <<'END_OF_FILE'
  1145. X/* Display character set.
  1146. X   usage: charset [-font font] [minchar [maxchar]] */
  1147. X
  1148. X#include "tools.h"
  1149. X#include "stdwin.h"
  1150. X
  1151. Xint minchar= 0;            /* First char to draw */
  1152. Xint maxchar= 255;
  1153. X
  1154. Xmain(argc, argv)
  1155. X    int argc;
  1156. X    char **argv;
  1157. X{
  1158. X    int *which= &minchar;
  1159. X    int i;
  1160. X    
  1161. X    winitargs(&argc, &argv);
  1162. X    
  1163. X    for (i= 1; i < argc; ++i) {
  1164. X        if (isnumeric(argv[i])) {
  1165. X            *which= atoi(argv[i]);
  1166. X            which= &maxchar;
  1167. X        }
  1168. X        else
  1169. X            break;
  1170. X    }
  1171. X    if (i < argc) {
  1172. X        wdone();
  1173. X        fprintf(stderr, "usage: %s [minchar [maxchar]]\n", argv[0]);
  1174. X        exit(2);
  1175. X    }
  1176. X    
  1177. X    if (maxchar < minchar) {
  1178. X        wdone();
  1179. X        fprintf(stderr, "%s: maxchar < minchar\n", argv[0]);
  1180. X        exit(2);
  1181. X    }
  1182. X    
  1183. X    setup();
  1184. X    mainloop();
  1185. X    wdone();
  1186. X    exit(0);
  1187. X}
  1188. X
  1189. Xbool
  1190. Xisnumeric(str)
  1191. X    char *str;
  1192. X{
  1193. X    while (*str != EOS) {
  1194. X        if (!isdigit(*str))
  1195. X            return FALSE;
  1196. X        ++str;
  1197. X    }
  1198. X    return TRUE;
  1199. X}
  1200. X
  1201. XWINDOW *win;
  1202. Xint ncols, nrows;
  1203. Xint colwidth, rowheight;
  1204. X
  1205. Xvoid drawproc(win, l, t, r, b)
  1206. X    WINDOW *win;
  1207. X{
  1208. X    int lineheight= wlineheight();
  1209. X    int i= (t/rowheight) * ncols;
  1210. X    for (; i <= maxchar-minchar; ++i) {
  1211. X        int c= minchar+i;
  1212. X        int col= i%ncols;
  1213. X        int row= i/ncols;
  1214. X        int h= col*colwidth;
  1215. X        int v= row*rowheight;
  1216. X        int charwidth= wcharwidth(c);
  1217. X        if (v >= b)
  1218. X            break;
  1219. X        wdrawchar(h + (colwidth - charwidth) / 2,
  1220. X              v + (rowheight - lineheight) / 2,
  1221. X              c);
  1222. X    }
  1223. X}
  1224. X
  1225. Xsetup()
  1226. X{
  1227. X    int scrwidth, scrheight;
  1228. X    int maxwidth= 1;
  1229. X    int i;
  1230. X    
  1231. X    wgetscrsize(&scrwidth, &scrheight);
  1232. X    while (minchar <= maxchar && wcharwidth(minchar) == 0)
  1233. X        ++minchar;
  1234. X    while (maxchar >= minchar && wcharwidth(maxchar) == 0)
  1235. X        --maxchar;
  1236. X    if (minchar > maxchar) {
  1237. X        wdone();
  1238. X        fprintf(stderr, "no chars in given range\n");
  1239. X        exit(1);
  1240. X    }
  1241. X    for (i= minchar; i <= maxchar; i++) {
  1242. X        int w= wcharwidth(i);
  1243. X        if (w > maxwidth)
  1244. X            maxwidth= w;
  1245. X    }
  1246. X    colwidth= maxwidth * 2;
  1247. X    rowheight= wlineheight() * 3 / 2;
  1248. X    ncols= 16;
  1249. X    if ((ncols+2) * colwidth > scrwidth) {
  1250. X        ncols= scrwidth/colwidth - 2;
  1251. X        if (ncols < 1)
  1252. X            ncols= 1;
  1253. X    }
  1254. X    nrows= (maxchar - minchar + ncols) / ncols;
  1255. X    if (nrows < 1)
  1256. X        nrows= 1;
  1257. X    wsetdefwinsize(ncols*colwidth, nrows*rowheight);
  1258. X    wsetmaxwinsize(ncols*colwidth, nrows*rowheight);
  1259. X    win= wopen("Character Set", drawproc);
  1260. X    if (win == NULL) {
  1261. X        wdone();
  1262. X        fprintf(stderr, "can't open window\n");
  1263. X        exit(1);
  1264. X    }
  1265. X    (void) wmenucreate(1, "Press q to quit");
  1266. X}
  1267. X
  1268. Xmainloop()
  1269. X{
  1270. X    for (;;) {
  1271. X        EVENT e;
  1272. X        wgetevent(&e);
  1273. X        switch (e.type) {
  1274. X        case WE_CHAR:
  1275. X            switch (e.u.character) {
  1276. X            case 'q':
  1277. X            case 'Q':
  1278. X                return;
  1279. X            }
  1280. X            break;
  1281. X        case WE_COMMAND:
  1282. X            switch (e.u.command) {
  1283. X            case WC_CANCEL:
  1284. X            case WC_CLOSE:
  1285. X                wclose(win);
  1286. X                return;
  1287. X            }
  1288. X            break;
  1289. X        case WE_CLOSE:
  1290. X            wclose(win);
  1291. X            return;
  1292. X        case WE_MOUSE_DOWN:
  1293. X            charinfo(e.u.where.h, e.u.where.v);
  1294. X            break;
  1295. X        }
  1296. X    }
  1297. X}
  1298. X
  1299. Xcharinfo(h, v)
  1300. X    int h, v;
  1301. X{
  1302. X    int row= v/rowheight;
  1303. X    int col= h/colwidth;
  1304. X    int i= minchar + row*ncols + col;
  1305. X    if (i >= minchar && i <= maxchar) {
  1306. X        char buf[256];
  1307. X        sprintf(buf, "Char '%c' (%d. 0x%x), width %d",
  1308. X            i>=' ' && i<0x7f ? i : '?', i, i, wcharwidth(i));
  1309. X        wmessage(buf);
  1310. X    }
  1311. X    else
  1312. X        wfleep();
  1313. X}
  1314. END_OF_FILE
  1315. if test 2954 -ne `wc -c <'Appls/test/charset.c'`; then
  1316.     echo shar: \"'Appls/test/charset.c'\" unpacked with wrong size!
  1317. fi
  1318. # end of 'Appls/test/charset.c'
  1319. fi
  1320. if test -f 'Appls/test/dklok.c' -a "${1}" != "-c" ; then 
  1321.   echo shar: Will not clobber existing file \"'Appls/test/dklok.c'\"
  1322. else
  1323. echo shar: Extracting \"'Appls/test/dklok.c'\" \(2557 characters\)
  1324. sed "s/^X//" >'Appls/test/dklok.c' <<'END_OF_FILE'
  1325. X/* Digital clock */
  1326. X
  1327. X#ifdef ns32000
  1328. X#define void int
  1329. X#endif
  1330. X
  1331. X#include <ctype.h>
  1332. X#include <stdio.h>
  1333. X#include <time.h>
  1334. X
  1335. X#include "stdwin.h"
  1336. X
  1337. X#include "sevenseg.h"
  1338. X
  1339. Xextern long time();
  1340. X
  1341. Xint text_only;                /* Non-zero on text-only device */
  1342. X
  1343. XWINDOW *win;                /* Our window */
  1344. X
  1345. X#define NIMAGE    5            /* Number of chars in image */
  1346. Xchar image[NIMAGE+1];            /* Text to draw, plus trailing \0 */
  1347. X
  1348. Xint aleft, atop, aright, abottom;    /* Rect in which to draw */
  1349. X
  1350. Xgetinfo()
  1351. X{
  1352. X    wgetwinsize(win, &aright, &abottom);
  1353. X    wsetdocsize(win, aright, abottom);
  1354. X    newtime();
  1355. X}
  1356. X
  1357. Xnewtime()
  1358. X{
  1359. X    unsigned long now;
  1360. X    struct tm *tp;
  1361. X    
  1362. X    wchange(win, aleft, atop, aright, abottom);
  1363. X    time(&now);
  1364. X    tp= localtime(&now);
  1365. X    wsettimer(win, 10 * (60 - now%60));
  1366. X    sprintf(image, "%02d:%02d", tp->tm_hour, tp->tm_min);
  1367. X    
  1368. X}
  1369. X
  1370. Xvoid
  1371. Xdrawdigit(digit, left, top, right, bottom, dh, dv)
  1372. X    int digit;
  1373. X    int left, top, right, bottom;
  1374. X    int dh, dv; /* Segment thickness */
  1375. X{
  1376. X    int bits= sevenseg[digit];
  1377. X    int mid= (top + bottom) / 2;
  1378. X    void (*func)();
  1379. X    
  1380. X    if (text_only)
  1381. X        func= winvert;
  1382. X    else
  1383. X        func= wpaint;
  1384. X    
  1385. X    if (bits & (1<<6))
  1386. X        func(left, top, right, top+dv);
  1387. X    if (bits & (1<<5))
  1388. X        func(left, top, left+dh, mid);
  1389. X    if (bits & (1<<4))
  1390. X        func(right-dh, top, right, mid);
  1391. X    if (bits & (1<<3))
  1392. X        func(left, mid-dv/2, right, mid+dv-dv/2);
  1393. X    if (bits & (1<<2))
  1394. X        func(left, mid, left+dh, bottom);
  1395. X    if (bits & (1<<1))
  1396. X        func(right-dh, mid, right, bottom);
  1397. X    if (bits & (1<<0))
  1398. X        func(left, bottom-dv, right, bottom);
  1399. X}
  1400. X
  1401. Xvoid
  1402. Xdrawproc(win, left, top, right, bottom)
  1403. X    WINDOW *win;
  1404. X    int left, top, right, bottom;
  1405. X{
  1406. X    int width= aright - aleft;
  1407. X    int height= abottom - atop;
  1408. X    int dh= width / (NIMAGE*6 + 1);
  1409. X    int dv= height / 9;
  1410. X    int spacing;
  1411. X    int i;
  1412. X    
  1413. X    if (dh < 1)
  1414. X        dh= 1;
  1415. X    if (dv < 1)
  1416. X        dv= 1;
  1417. X    
  1418. X    spacing= dh*6;
  1419. X    
  1420. X    for (i= 0; i < NIMAGE && image[i] != '\0'; ++i) {
  1421. X        if (isdigit(image[i])) {
  1422. X            drawdigit(image[i] - '0',
  1423. X                aleft + dh + i*spacing, atop + dv,
  1424. X                aleft + dh + (i+1)*spacing - dh, abottom - dv,
  1425. X                dh, dv);
  1426. X        }
  1427. X    }
  1428. X}
  1429. X
  1430. Xmain(argc, argv)
  1431. X    int argc;
  1432. X    char **argv;
  1433. X{
  1434. X    winitargs(&argc, &argv);
  1435. X    setup();
  1436. X    mainloop();
  1437. X    wdone();
  1438. X    exit(0);
  1439. X}
  1440. X
  1441. Xsetup()
  1442. X{
  1443. X    if (wlineheight() == 1) {
  1444. X        text_only= 1;
  1445. X        wmessage("Text-only version");
  1446. X    }
  1447. X    win= wopen("DIGITAL CLOCK", drawproc);
  1448. X    getinfo();
  1449. X}
  1450. X
  1451. Xmainloop()
  1452. X{
  1453. X    for (;;) {
  1454. X        EVENT e;
  1455. X        wgetevent(&e);
  1456. X        switch (e.type) {
  1457. X        case WE_COMMAND:
  1458. X            switch (e.u.command) {
  1459. X            case WC_CLOSE:
  1460. X            case WC_CANCEL:
  1461. X                wclose(win);
  1462. X                return 0;
  1463. X            }
  1464. X            break;
  1465. X        case WE_CLOSE:
  1466. X            wclose(win);
  1467. X            return 0;
  1468. X        case WE_SIZE:
  1469. X            getinfo();
  1470. X            break;
  1471. X        case WE_TIMER:
  1472. X            newtime();
  1473. X            break;
  1474. X        }
  1475. X    }
  1476. X}
  1477. END_OF_FILE
  1478. if test 2557 -ne `wc -c <'Appls/test/dklok.c'`; then
  1479.     echo shar: \"'Appls/test/dklok.c'\" unpacked with wrong size!
  1480. fi
  1481. # end of 'Appls/test/dklok.c'
  1482. fi
  1483. if test -f 'H/lists.h' -a "${1}" != "-c" ; then 
  1484.   echo shar: Will not clobber existing file \"'H/lists.h'\"
  1485. else
  1486. echo shar: Extracting \"'H/lists.h'\" \(3065 characters\)
  1487. sed "s/^X//" >'H/lists.h' <<'END_OF_FILE'
  1488. X/* Package to manipulate dynamic arrays represented like
  1489. X   argc/argv (but not necessarily containing character pointers).
  1490. X   Operations provided are macros that expand to groups of statements;
  1491. X   their arguments should be side-effect-free.  The arguments argc and
  1492. X   argv should be single identifiers, since they are assigned to.
  1493. X   (L_DECLARE expands to a series of declarations.)
  1494. X   
  1495. X   This code was written because I found myself writing code very
  1496. X   similar to it times and times over, or, worse, using fixed-length
  1497. X   arrays out of laziness.  It's slow for large arrays (although this
  1498. X   could be improved easily by rounding up the sizes passed to
  1499. X   malloc/realloc), but this shouldn't be a problem for the applications
  1500. X   I am currently using it for.  It sure helped me write some array
  1501. X   processing code faster.
  1502. X   
  1503. X   Operations:
  1504. X   
  1505. X   L_DECLARE(argc, argv, type)        declare a list with element type 'type'
  1506. X   L_INIT(argc, argv)            initialize a list
  1507. X   L_DEALLOC(argc, argv)        deallocate a list
  1508. X   L_SETSIZE(argc, argv, type, size)    set list to size 'size'
  1509. X   L_EXTEND(argc, argv, type, count)    append 'count' unitinialized elements
  1510. X   L_APPEND(argc, argv, type, elem)    append a given element
  1511. X   L_REMOVE(argc, argv, type, index)    remove element number 'index'
  1512. X   L_INSERT(argc, argv, type, index, elem)    insert 'elem' at 'index'
  1513. X   L_SORT(argc, argv, type, compare)    sort the list ('compare' is a function)
  1514. X   
  1515. X   (There should also be operations to insert in the middle and to
  1516. X   remove elements.)
  1517. X   
  1518. X   NB: the 'type' argument could be discarded (except for L_DECLARE)
  1519. X   if we could live with warnings about assignments from malloc/realloc
  1520. X   to other pointer types.
  1521. X   
  1522. X*/
  1523. X
  1524. X/* This file only works when included by "stdwtools.h" !!! */
  1525. X
  1526. X/* You could define GOOD_REALLOC if your realloc() calls malloc() when
  1527. X   passed a NULL pointer */
  1528. X
  1529. X#ifdef GOOD_REALLOC
  1530. X#define _REALLOC(p, size) realloc(p, size)
  1531. X#else
  1532. X#define _REALLOC(p, size) ((p) ? realloc(p, size) : malloc(size))
  1533. X#endif
  1534. X
  1535. X#define L_DECLARE(argc, argv, type)    int argc = 0; type *argv = 0
  1536. X
  1537. X#define L_INIT(argc, argv)        argc = 0; argv = 0
  1538. X
  1539. X#define L_DEALLOC(argc, argv)        argc = 0; FREE(argv)
  1540. X
  1541. X#define L_SETSIZE(argc, argv, type, size) \
  1542. X    argv = (type *) _REALLOC((UNIVPTR) argv, \
  1543. X        (unsigned) (size) * sizeof(type)); \
  1544. X    argc = (argv == 0) ? 0 : size
  1545. X
  1546. X#define L_EXTEND(argc, argv, type, count) \
  1547. X    L_SETSIZE(argc, argv, type, argc+count)
  1548. X
  1549. X#define L_APPEND(argc, argv, type, elem) \
  1550. X    argv = (type *) _REALLOC((UNIVPTR) argv, \
  1551. X        (unsigned) (argc+1) * sizeof(type)); \
  1552. X    if (argv == 0) \
  1553. X        argc = 0; \
  1554. X    else \
  1555. X        argv[argc++] = elem
  1556. X
  1557. X#define L_REMOVE(argc, argv, type, index) \
  1558. X    { \
  1559. X        int k_; \
  1560. X        for (k_ = index+1; k_ < argc; ++k_) \
  1561. X            argv[k_-1] = argv[k_]; \
  1562. X        L_SETSIZE(argc, argv, type, argc-1); \
  1563. X    }
  1564. X
  1565. X#define L_INSERT(argc, argv, type, index, item) \
  1566. X    { \
  1567. X        int k_; \
  1568. X        L_SETSIZE(argc, argv, type, argc+1); \
  1569. X        for (k_ = argc-1; k_ > index; --k_) \
  1570. X            argv[k_] = argv[k_-1]; \
  1571. X        argv[index] = item; \
  1572. X    }
  1573. X
  1574. X#define L_SORT(argc, argv, type, compare) \
  1575. X    qsort((UNIVPTR)argv, argc, sizeof(type), compare)
  1576. END_OF_FILE
  1577. if test 3065 -ne `wc -c <'H/lists.h'`; then
  1578.     echo shar: \"'H/lists.h'\" unpacked with wrong size!
  1579. fi
  1580. # end of 'H/lists.h'
  1581. fi
  1582. if test -f 'H/patchlevel.h' -a "${1}" != "-c" ; then 
  1583.   echo shar: Will not clobber existing file \"'H/patchlevel.h'\"
  1584. else
  1585. echo shar: Extracting \"'H/patchlevel.h'\" \(21 characters\)
  1586. sed "s/^X//" >'H/patchlevel.h' <<'END_OF_FILE'
  1587. X#define PATCHLEVEL 5
  1588. END_OF_FILE
  1589. if test 21 -ne `wc -c <'H/patchlevel.h'`; then
  1590.     echo shar: \"'H/patchlevel.h'\" unpacked with wrong size!
  1591. fi
  1592. # end of 'H/patchlevel.h'
  1593. fi
  1594. if test -f 'H/winreq.h' -a "${1}" != "-c" ; then 
  1595.   echo shar: Will not clobber existing file \"'H/winreq.h'\"
  1596. else
  1597. echo shar: Extracting \"'H/winreq.h'\" \(3052 characters\)
  1598. sed "s/^X//" >'H/winreq.h' <<'END_OF_FILE'
  1599. X/* STDWIN Server -- Window (Manager) Requests. */
  1600. X
  1601. X/* Command codes in transaction header. */
  1602. X
  1603. X#define WIN_FIRST    1100
  1604. X
  1605. X#define WIN_HELLO    (WIN_FIRST+1)    /* Say hello to server */
  1606. X#define WIN_DROPDEAD    (WIN_FIRST+2)    /* Die, if idle */
  1607. X#define WIN_OPEN    (WIN_FIRST+3)    /* Open new window */
  1608. X#define WIN_CLOSE    (WIN_FIRST+4)    /* Close window */
  1609. X#define WIN_DRAW    (WIN_FIRST+5)    /* Drawing commands; see subcodes */
  1610. X#define WIN_GETEVENT    (WIN_FIRST+6)    /* Get event */
  1611. X#define WIN_FLEEP    (WIN_FIRST+7)    /* Flash or beep */
  1612. X#define WIN_ACTIVATE    (WIN_FIRST+8)    /* Make window active */
  1613. X#define WIN_SETDOCSIZE    (WIN_FIRST+9)    /* Set document size */
  1614. X#define WIN_SETTITLE    (WIN_FIRST+10)    /* Set window title */
  1615. X#define WIN_SHOW    (WIN_FIRST+11)    /* Show part of document */
  1616. X#define WIN_SETORIGIN    (WIN_FIRST+12)    /* Set window origin in document */
  1617. X#define WIN_CHANGE    (WIN_FIRST+13)    /* Change part of document */
  1618. X#define WIN_SCROLL    (WIN_FIRST+14)    /* Scroll part of document */
  1619. X#define WIN_MESSAGE    (WIN_FIRST+15)    /* Output message */
  1620. X#define WIN_ASKSTR    (WIN_FIRST+16)    /* Ask string */
  1621. X#define WIN_ASKYNC    (WIN_FIRST+17)    /* Ask yes/no/cancel question */
  1622. X#define WIN_SETCARET    (WIN_FIRST+18)    /* Set caret position */
  1623. X#define WIN_STATUS    (WIN_FIRST+19)    /* Get window status */
  1624. X#define WIN_GETFONTTAB    (WIN_FIRST+20)    /* Get font width table */
  1625. X#define WIN_SETTIMER    (WIN_FIRST+21)    /* Set window timer */
  1626. X#define WIN_SETCLIP    (WIN_FIRST+22)    /* Set clipboard string */
  1627. X#define WIN_GETCLIP    (WIN_FIRST+23)    /* Get clipboard string */
  1628. X#define WIN_POLLEVENT    (WIN_FIRST+24)    /* Poll for event */
  1629. X
  1630. X#define MENU_FIRST    (WIN_FIRST+50)
  1631. X
  1632. X#define MENU_CREATE    (MENU_FIRST+1)
  1633. X#define MENU_DELETE    (MENU_FIRST+2)
  1634. X#define MENU_ADDITEM    (MENU_FIRST+3)
  1635. X#define MENU_SETITEM    (MENU_FIRST+4)
  1636. X#define MENU_ATTACH    (MENU_FIRST+5)
  1637. X#define MENU_DETACH    (MENU_FIRST+6)
  1638. X#define MENU_ENABLE    (MENU_FIRST+7)
  1639. X#define MENU_CHECK    (MENU_FIRST+8)
  1640. X
  1641. X
  1642. X/* Subcodes in data buffer for WIN_DRAW. */
  1643. X
  1644. X#define DRW_LINE    1
  1645. X#define DRW_BOX        2
  1646. X#define DRW_CIRCLE    3
  1647. X#define DRW_ERASE    4
  1648. X#define DRW_PAINT    5
  1649. X#define DRW_SHADE    6
  1650. X#define DRW_INVERT    7
  1651. X#define DRW_TEXT    8
  1652. X#define DRW_FONT    9
  1653. X#define DRW_STYLE    10
  1654. X#define DRW_ELARC    11
  1655. X#define DRW_XORLINE    12
  1656. X
  1657. X/* Error codes for h_status. */
  1658. X
  1659. X#define WER_OK        0        /* ok */
  1660. X#define WER_FAIL    -101        /* don't know why it failed */
  1661. X#define WER_COMBAD    -102        /* bad command */
  1662. X#define WER_CAPBAD    -103        /* bad capability */
  1663. X#define WER_NOSPACE    -104        /* no space left */
  1664. X#define WER_ABORT    -105        /* call aborted */
  1665. X#define WER_NODATA    -106        /* No or insufficient data provided */
  1666. X
  1667. X/* Event packing parameters.
  1668. X   (This is a kludge!  Should be variable-length and have a length byte
  1669. X   in the data!) */
  1670. X
  1671. X#define EVSHORTS    7
  1672. X#define EVPACKSIZE    (EVSHORTS * sizeof(short))
  1673. X
  1674. X/* Server's buffer size. */
  1675. X
  1676. X#define SVRBUFSIZE    4096
  1677. X    /* I suppose this should really be negotiated between server and
  1678. X       client, e.g., WIN_HELLO should return the server's buffer
  1679. X       size. */
  1680. X
  1681. X/* Font width table length. */
  1682. X
  1683. X#define FONTTABLEN    256    /* Number of chars in a font */
  1684. X
  1685. X/* Pseudo-event sent when SIGAMOEBA received */
  1686. X
  1687. X#define WE_ALERT    22
  1688. END_OF_FILE
  1689. if test 3052 -ne `wc -c <'H/winreq.h'`; then
  1690.     echo shar: \"'H/winreq.h'\" unpacked with wrong size!
  1691. fi
  1692. # end of 'H/winreq.h'
  1693. fi
  1694. if test -f 'Packs/vt/vtresize.c' -a "${1}" != "-c" ; then 
  1695.   echo shar: Will not clobber existing file \"'Packs/vt/vtresize.c'\"
  1696. else
  1697. echo shar: Extracting \"'Packs/vt/vtresize.c'\" \(3023 characters\)
  1698. sed "s/^X//" >'Packs/vt/vtresize.c' <<'END_OF_FILE'
  1699. X/* Resize function */
  1700. X
  1701. X#include "vtimpl.h"
  1702. X
  1703. X/* Resize the screen.
  1704. X   When growing, blanks are added to the right and/or at the top (!);
  1705. X   when shrinking, characters are lost at those edges.
  1706. X   It is really a disaster if we run out of memory halfway
  1707. X   (much more so than in vtopen);
  1708. X   in this case the caller should immediately call vtclose,
  1709. X   and expect some memory leaks... */
  1710. X
  1711. Xbool
  1712. Xvtresize(vt, rows, cols, save)
  1713. X    VT *vt;
  1714. X    int rows, cols;
  1715. X    int save;
  1716. X{
  1717. X    int rowdiff;
  1718. X    int i;
  1719. X
  1720. X    rows += save;
  1721. X    rowdiff = rows - vt->rows;
  1722. X    if (cols != vt->cols) {
  1723. X        if (cols < vt->cols) {
  1724. X            /* Clear the corresponding screen area */
  1725. X            vtchange(vt, 0, cols, vt->rows, vt->cols);
  1726. X            vt->cols = cols;
  1727. X        }
  1728. X        i = vt->rows;
  1729. X        if (rows < i)
  1730. X            i = rows;
  1731. X        while (--i >= 0) {
  1732. X            if (!RESIZE(vt->data[i], char, cols))
  1733. X                return FALSE;
  1734. X            if (!RESIZE(vt->flags[i], unsigned char, cols))
  1735. X                return FALSE;
  1736. X            if (vt->llen[i] > cols)
  1737. X                vt->llen[i] = cols;
  1738. X        }
  1739. X        if (cols > vt->cols) {
  1740. X            /* Clear the corresponding screen area */
  1741. X            vtchange(vt, 0, vt->cols, rows, cols);
  1742. X            vt->cols = cols;
  1743. X        }
  1744. X    }
  1745. X
  1746. X    if (rowdiff != 0) {
  1747. X        if (rowdiff < 0) {
  1748. X            /* Get the last line into its new position */
  1749. X            vtscrollup(vt, 0, vt->rows, -rowdiff);
  1750. X            /* Free the excess lines */
  1751. X            for (i = rows; i < vt->rows; ++i) {
  1752. X                FREE(vt->data[i]);
  1753. X                FREE(vt->flags[i]);
  1754. X            }
  1755. X            /* Clear the corresponding screen area */
  1756. X            vtchange(vt, rows, 0, vt->rows, cols);
  1757. X            vt->rows = rows;
  1758. X        }
  1759. X
  1760. X        if (!RESIZE(vt->data, char *, rows))
  1761. X            return FALSE;
  1762. X        if (!RESIZE(vt->flags, unsigned char *, rows))
  1763. X            return FALSE;
  1764. X        if (!RESIZE(vt->llen, short, rows))
  1765. X            return FALSE;
  1766. X
  1767. X        if (rowdiff > 0) {
  1768. X            /* Add new lines */
  1769. X            for (i = vt->rows; i < rows; ++i) {
  1770. X                if ((vt->data[i] = NALLOC(char, cols)) == NULL)
  1771. X                    return FALSE;
  1772. X                if ((vt->flags[i] = NALLOC(unsigned char, cols)) == NULL)
  1773. X                    return FALSE;
  1774. X                vt->llen[i] = 0;
  1775. X            }
  1776. X            /* Clear the corresponding screen area */
  1777. X            vtchange(vt, vt->rows, 0, rows, cols);
  1778. X            vt->rows = rows;
  1779. X            /* Get the last line into its new position */
  1780. X            vtscrolldown(vt, 0, rows, rowdiff);
  1781. X        }
  1782. X    }
  1783. X
  1784. X    if (rowdiff != 0 || save != vt->topterm) {
  1785. X        vt->topterm = save;
  1786. X        vtsetscroll(vt, 0, 0); /* Reset scrolling region */
  1787. X    }
  1788. X
  1789. X    wsetdocsize(vt->win,
  1790. X        vt->cols * vt->cwidth, vt->rows * vt->cheight);
  1791. X
  1792. X    i = vt->cur_row + rowdiff;
  1793. X    CLIPMIN(i, save);
  1794. X    vtsetcursor(vt, i, vt->cur_col);
  1795. X
  1796. X    return TRUE;
  1797. X}
  1798. X
  1799. X/* Adapt the screen size to the new window dimensions.
  1800. X   The 'save' parameter is computed so as to keep the total amount
  1801. X   of rows the same (if possible).
  1802. X   Return value as for vtresize (i.e., FALSE is a disaster). */
  1803. X
  1804. Xbool
  1805. Xvtautosize(vt)
  1806. X    VT *vt;
  1807. X{
  1808. X    int width, height;
  1809. X    int newrows, newcols, newsave;
  1810. X    wgetwinsize(vt->win, &width, &height);
  1811. X    newrows = height / vt->cheight;
  1812. X    newcols = width / vt->cwidth;
  1813. X    newsave = vt->rows - newrows;
  1814. X    D( printf("vtautosize: size now %dx%d (char = %dx%d) => %dx%d\n",
  1815. X        width,height, vt->cwidth,vt->cheight, newrows,newcols) );
  1816. X    CLIPMIN(newsave, 0);
  1817. X    return vtresize(vt, newrows, newcols, newsave);
  1818. X}
  1819. END_OF_FILE
  1820. if test 3023 -ne `wc -c <'Packs/vt/vtresize.c'`; then
  1821.     echo shar: \"'Packs/vt/vtresize.c'\" unpacked with wrong size!
  1822. fi
  1823. # end of 'Packs/vt/vtresize.c'
  1824. fi
  1825. if test -f 'Packs/vt/vtvtrm.c' -a "${1}" != "-c" ; then 
  1826.   echo shar: Will not clobber existing file \"'Packs/vt/vtvtrm.c'\"
  1827. else
  1828. echo shar: Extracting \"'Packs/vt/vtvtrm.c'\" \(2629 characters\)
  1829. sed "s/^X//" >'Packs/vt/vtvtrm.c' <<'END_OF_FILE'
  1830. X/* VTRM implementation using VT as lower layer.
  1831. X   Unfortunately, this isn't too useful on the input part:
  1832. X   you'll really want to use wgetevent directly to get access
  1833. X   to mouse clicks, menu events etc.
  1834. X   Another problem is that there is no portable way to direct normal
  1835. X   output (e.g., from printf and putchar) to the VTRM window.
  1836. X   One other thing: you'll have to call wdone() when you really exit. */
  1837. X
  1838. X/* XXX This has never been tested... */
  1839. X
  1840. X#include "vtimpl.h"
  1841. X#include "vtrm.h"
  1842. X
  1843. Xstatic VT *vt;
  1844. Xstatic bool active;
  1845. X
  1846. Xint
  1847. Xtrmstart(rows_return, cols_return, flags_return)
  1848. X    int *rows_return, *cols_return, *flags_return;
  1849. X{
  1850. X    if (active)
  1851. X        return TE_TWICE; /* Already started */
  1852. X    if (vt == NULL) {
  1853. X        winit();
  1854. X        wsetdefwinsize(24*wcharwidth('0'), 80*wlineheight());
  1855. X        vt= vtopen("VTRM", 24, 80, 0);
  1856. X        if (vt == NULL)
  1857. X            return TE_NOMEM; /* Failure */
  1858. X    }
  1859. X    *rows_return= 24;
  1860. X    *cols_return= 80;
  1861. X    *flags_return=
  1862. X        HAS_STANDOUT | CAN_SCROLL | CAN_SENSE;
  1863. X    return TE_OK;
  1864. X}
  1865. X
  1866. Xtrmend()
  1867. X{
  1868. X    active= FALSE;
  1869. X}
  1870. X
  1871. Xtrmputdata(row, col, data)
  1872. X    int row, col;
  1873. X    char *data;
  1874. X{
  1875. X    char *start= data;
  1876. X    int mask= 0;
  1877. X    vtsetcursor(vt, row, col);
  1878. X    do {
  1879. X        if ((*data & 0x80) != mask) {
  1880. X            if (data > start) {
  1881. X                if (mask) {
  1882. X                    char *p;
  1883. X                    for (p= start; p < data; ++p)
  1884. X                        *p &= 0x7f;
  1885. X                    vt->gflags= VT_INVERSE;
  1886. X                }
  1887. X                vtputstring(vt, start, data-start);
  1888. X                if (mask) {
  1889. X                    char *p;
  1890. X                    for (p= start; p < data; ++p)
  1891. X                        *p |= 0x80;
  1892. X                    vt->gflags= 0;
  1893. X                }
  1894. X                start= data;
  1895. X            }
  1896. X            mask= *data & 0x80;
  1897. X        }
  1898. X    } while (*data++ != EOS);
  1899. X    /* XXX This is likely to omit the final data? */
  1900. X    vteolclear(vt, vt->cur_row, vt->cur_col);
  1901. X}
  1902. X
  1903. Xtrmscrollup(r1, r2, n)
  1904. X    int r1, r2;
  1905. X    int n;
  1906. X{
  1907. X    if (n > 0)
  1908. X        vtscrollup(vt, r1, r2+1, n);
  1909. X    else if (n < 0)
  1910. X        vtscrolldown(vt, r1, r2+1, -n);
  1911. X}
  1912. X
  1913. Xtrmsync(row, col)
  1914. X    int row, col;
  1915. X{
  1916. X    vtsetcursor(vt, row, col);
  1917. X}
  1918. X
  1919. Xstatic lasth, lastv;
  1920. X
  1921. Xint
  1922. Xtrminput()
  1923. X{
  1924. X    EVENT e;
  1925. X    for (;;) {
  1926. X        switch (e.type) {
  1927. X        case WE_COMMAND:
  1928. X            switch (e.type) {
  1929. X            case WC_CANCEL:
  1930. X                return '\003';
  1931. X            case WC_RETURN:
  1932. X                return '\r';
  1933. X            case WC_TAB:
  1934. X                return '\t';
  1935. X            case WC_BACKSPACE:
  1936. X                return '\b';
  1937. X            case WC_LEFT:
  1938. X                return '\034';
  1939. X            case WC_RIGHT:
  1940. X                return '\035';
  1941. X            case WC_UP:
  1942. X                return '\036';
  1943. X            case WC_DOWN:
  1944. X                return '\037';
  1945. X            }
  1946. X            break;
  1947. X        case WE_CHAR:
  1948. X            return e.u.character;
  1949. X            break;
  1950. X        case WE_MOUSE_DOWN:
  1951. X        case WE_MOUSE_MOVE:
  1952. X        case WE_MOUSE_UP:
  1953. X            lasth= e.u.where.h;
  1954. X            lastv= e.u.where.v;
  1955. X            if (e.type == WE_MOUSE_UP)
  1956. X                return '\007';
  1957. X            break;
  1958. X        }
  1959. X    }
  1960. X}
  1961. X
  1962. Xint
  1963. Xtrmsense(row_return, col_return)
  1964. X    int *row_return, *col_return;
  1965. X{
  1966. X    *row_return= lastv / vtcheight(vt);
  1967. X    *col_return= lasth / vtcwidth(vt);
  1968. X}
  1969. END_OF_FILE
  1970. if test 2629 -ne `wc -c <'Packs/vt/vtvtrm.c'`; then
  1971.     echo shar: \"'Packs/vt/vtvtrm.c'\" unpacked with wrong size!
  1972. fi
  1973. # end of 'Packs/vt/vtvtrm.c'
  1974. fi
  1975. if test -f 'Ports/mac/caret.c' -a "${1}" != "-c" ; then 
  1976.   echo shar: Will not clobber existing file \"'Ports/mac/caret.c'\"
  1977. else
  1978. echo shar: Extracting \"'Ports/mac/caret.c'\" \(2827 characters\)
  1979. sed "s/^X//" >'Ports/mac/caret.c' <<'END_OF_FILE'
  1980. X/* MAC STDWIN -- TEXT CARET HANDLING. */
  1981. X
  1982. X/* The 'caret' is a blinking vertical bar indicating the text insertion point.
  1983. X   Each window has its own caret position (hcaret, vcaret) telling where the
  1984. X   insertion point is; if either is negative no caret is shown.
  1985. X   Only the caret of the active window is actually visible.
  1986. X   The blinking is done by repeatedly calling (in the event loop when idling)
  1987. X   blinkcaret(), which flips the caret's state if it's been stable long enough.
  1988. X   The file-static variable lastflip records when the caret has last changed
  1989. X   state.
  1990. X   A struct member caret_on indicates per window whether the caret is
  1991. X   currently drawn or not.  (A file-static variable would really suffice.)
  1992. X
  1993. X   NB: all routines except w{set,no}caret assume win->w is the current GrafPort.    
  1994. X*/
  1995. X
  1996. X#include "macwin.h"
  1997. X
  1998. X#ifdef MPW
  1999. X#include <Events.h>
  2000. X#endif
  2001. X
  2002. X/* Function prototypes */
  2003. XSTATIC void invertcaret _ARGS((WINDOW *win));
  2004. XSTATIC void flipcaret _ARGS((WINDOW *win));
  2005. X
  2006. Xstatic long lastflip = 0;    /* Time when the caret last blinked */
  2007. X
  2008. X/* Invert the caret's pixels. */
  2009. X
  2010. Xstatic void
  2011. Xinvertcaret(win)
  2012. X    WINDOW *win;
  2013. X{
  2014. X    Rect r;
  2015. X    FontInfo finfo;
  2016. X    
  2017. X    if (win->hcaret < 0 || win->vcaret < 0)
  2018. X        return;
  2019. X    GetFontInfo(&finfo);
  2020. X    makerect(win, &r,
  2021. X        win->hcaret-1,
  2022. X        win->vcaret,
  2023. X        win->hcaret,
  2024. X        win->vcaret + finfo.leading + finfo.ascent + finfo.descent);
  2025. X    InvertRect(&r);
  2026. X}
  2027. X
  2028. X/* Flip the caret state, if the window has a caret.
  2029. X   Also set lastflip, so blinkcaret() below knows when to flip it again. */
  2030. X
  2031. Xstatic void
  2032. Xflipcaret(win)
  2033. X    WINDOW *win;
  2034. X{
  2035. X    if (win->hcaret < 0 || win->vcaret < 0)
  2036. X        return;
  2037. X    invertcaret(win);
  2038. X    win->caret_on = !win->caret_on;
  2039. X    lastflip= TickCount();
  2040. X}
  2041. X
  2042. X/* Make sure the caret is invisible.
  2043. X   This is necessary before operations like handling mouse clicks,
  2044. X   bringing up dialog boxes, or when the window goes inactive. */
  2045. X
  2046. Xvoid
  2047. Xrmcaret(win)
  2048. X    WINDOW *win;
  2049. X{
  2050. X    if (win->caret_on)
  2051. X        flipcaret(win);
  2052. X}
  2053. X
  2054. X/* Blink the caret, if there is one.
  2055. X   This should be called sufficiently often from the main event loop.
  2056. X   We only blink if enough ticks have passed since the last flip,
  2057. X   whether caused by us or by an explicit call to rmcaret(). */
  2058. X
  2059. Xvoid
  2060. Xblinkcaret(win)
  2061. X    WINDOW *win;
  2062. X{
  2063. X    if (win->hcaret < 0 || win->vcaret < 0)
  2064. X        return;
  2065. X    if (TickCount() >= lastflip + GetCaretTime())
  2066. X        flipcaret(win);
  2067. X}
  2068. X
  2069. X/* User-callable routine to specify the caret position.
  2070. X   The caret is not drawn now, but when the next blink is due. */
  2071. X
  2072. Xvoid
  2073. Xwsetcaret(win, h, v)
  2074. X    WINDOW *win;
  2075. X    int h, v;
  2076. X{
  2077. X    SetPort(win->w);
  2078. X    rmcaret(win);
  2079. X    win->hcaret = h;
  2080. X    win->vcaret = v;
  2081. X}
  2082. X
  2083. X/* User-callable routine to specify that the window has no caret.
  2084. X   This is indicated by setting (hcaret, vcaret) to (-1, -1). */
  2085. X
  2086. Xvoid
  2087. Xwnocaret(win)
  2088. X    WINDOW *win;
  2089. X{
  2090. X    SetPort(win->w);
  2091. X    rmcaret(win);    /* See remark in wsetcaret() */
  2092. X    win->hcaret = win->vcaret= -1;
  2093. X}
  2094. END_OF_FILE
  2095. if test 2827 -ne `wc -c <'Ports/mac/caret.c'`; then
  2096.     echo shar: \"'Ports/mac/caret.c'\" unpacked with wrong size!
  2097. fi
  2098. # end of 'Ports/mac/caret.c'
  2099. fi
  2100. if test -f 'Ports/vtrm/DIST/pag.c' -a "${1}" != "-c" ; then 
  2101.   echo shar: Will not clobber existing file \"'Ports/vtrm/DIST/pag.c'\"
  2102. else
  2103. echo shar: Extracting \"'Ports/vtrm/DIST/pag.c'\" \(2582 characters\)
  2104. sed "s/^X//" >'Ports/vtrm/DIST/pag.c' <<'END_OF_FILE'
  2105. X/* VTRM example -- a trivial pager.
  2106. X   There are zillions of things this pager doesn't do, or would
  2107. X   crash on, but it is a nice demonstration of the use of VTRM. */
  2108. X
  2109. X#include <stdio.h>
  2110. X
  2111. Xchar *index();
  2112. X
  2113. X#define CTRL(c) ((c)&0x1F)
  2114. X
  2115. X#include "trm.h"
  2116. X
  2117. Xint lines, columns, flags;
  2118. XFILE *fp;
  2119. X
  2120. X/* Main program -- scan arguments, open file, set-up VTRM, main loop. */
  2121. X
  2122. Xmain(argc, argv)
  2123. X    int argc;
  2124. X    char **argv;
  2125. X{
  2126. X    int n, c;
  2127. X    
  2128. X    if (argc != 2) {
  2129. X        fprintf(stderr, "usage: %s file\n", argv[0]);
  2130. X        exit(2);
  2131. X    }
  2132. X    
  2133. X    if ((fp= fopen(argv[1], "r")) == NULL) {
  2134. X        perror(argv[1]);
  2135. X        exit(1);
  2136. X    }
  2137. X    
  2138. X    if ((n= trmstart(&lines, &columns, &flags)) != 0) {
  2139. X        fprintf(stderr, "trmstart error %d\n", n);
  2140. X        exit(3);
  2141. X    }
  2142. X    
  2143. X    page();
  2144. X
  2145. X    for (;;) {
  2146. X        prompt();
  2147. X        c= trminput();
  2148. X        
  2149. X        switch (c) {
  2150. X
  2151. X        case ' ':            /* Display one more page */
  2152. X            page();
  2153. X            break;
  2154. X
  2155. X        case '\n':            /* Display one more line */
  2156. X        case '\r':
  2157. X            line();
  2158. X            break;
  2159. X
  2160. X        case 'q':            /* Quit */
  2161. X        case CTRL('C'):            /* or Interrupt */
  2162. X            trmputdata(lines-1, lines-1, 0, "");
  2163. X            trmsync(lines-1, 0);
  2164. X            trmend();
  2165. X            exit(2);
  2166. X        
  2167. X        case CTRL('Z'):            /* Suspend */
  2168. X            trmputdata(lines-1, lines-1, 0, "");
  2169. X            trmsync(lines-1, 0);
  2170. X            trmend();
  2171. X            trmsuspend();
  2172. X            if (trmstart(&lines, &columns, &flags))
  2173. X                exit(3);
  2174. X            page();
  2175. X            break;
  2176. X
  2177. X        default:            /* Error */
  2178. X            trmbell();
  2179. X            break;
  2180. X
  2181. X        }
  2182. X    }
  2183. X}
  2184. X
  2185. Xint left;    /* Lines left on current page */
  2186. X
  2187. X/* Output one page, using line() as a subroutine.
  2188. X   BUG: if the last line takes up more space than available, it is
  2189. X   displayed in its entirety, scrolling up more than a page in total. */
  2190. X
  2191. Xpage()
  2192. X{
  2193. X    left= lines-1;
  2194. X    do {
  2195. X        line();
  2196. X    } while (left > 0);
  2197. X}
  2198. X
  2199. X/* Output one line.  The line is displayed at the bottom,
  2200. X   assuming the botom line of the screen is free.
  2201. X   Update count of lines left on display.  Exit if EOF hit. */
  2202. X
  2203. Xline()
  2204. X{
  2205. X    char linebuf[BUFSIZ];
  2206. X    char *p;
  2207. X    int n;
  2208. X    
  2209. X    if (fgets(linebuf, sizeof linebuf, fp) == NULL) {
  2210. X        trmend();
  2211. X        exit(0);
  2212. X    }
  2213. X    if (p= index(linebuf, '\n'))
  2214. X        *p= '\0';
  2215. X    n= need(linebuf);
  2216. X    trmscrollup(0, lines-1, n);
  2217. X    trmputdata(lines-n-1, lines-2, 0, linebuf);
  2218. X    left -= n;
  2219. X}
  2220. X
  2221. X/* Compute the number of screen lines required.
  2222. X   Assumes only printing characters. */
  2223. X
  2224. Xneed(buf)
  2225. X    char *buf;
  2226. X{
  2227. X    int len= strlen(buf);
  2228. X    
  2229. X    if (len == 0)
  2230. X        return 1;
  2231. X    else
  2232. X        return (len+columns-1) / columns;
  2233. X}
  2234. X
  2235. X/* Issue a prompt on the bottom line.
  2236. X   Assumes this line is already free. */
  2237. X
  2238. Xprompt()
  2239. X{
  2240. X    static int beenhere= 0;
  2241. X    static char pr[]= "--More--";
  2242. X    
  2243. X    if (!beenhere++) {
  2244. X        char *p;
  2245. X        
  2246. X        for (p= pr; *p; ++p)
  2247. X            *p |= 0x80;
  2248. X    }
  2249. X    trmputdata(lines-1, lines-1, 0, pr);
  2250. X    trmsync(lines-1, strlen(pr));
  2251. X}
  2252. END_OF_FILE
  2253. if test 2582 -ne `wc -c <'Ports/vtrm/DIST/pag.c'`; then
  2254.     echo shar: \"'Ports/vtrm/DIST/pag.c'\" unpacked with wrong size!
  2255. fi
  2256. # end of 'Ports/vtrm/DIST/pag.c'
  2257. fi
  2258. if test -f 'Ports/x11/scroll.c' -a "${1}" != "-c" ; then 
  2259.   echo shar: Will not clobber existing file \"'Ports/x11/scroll.c'\"
  2260. else
  2261. echo shar: Extracting \"'Ports/x11/scroll.c'\" \(2894 characters\)
  2262. sed "s/^X//" >'Ports/x11/scroll.c' <<'END_OF_FILE'
  2263. X/* X11 STDWIN -- Scroll bars */
  2264. X
  2265. X#include "x11.h"
  2266. X
  2267. X#define IMARGIN 2 /* See window.c */
  2268. X
  2269. X/* Macro to compute the thumb position and size.
  2270. X   Don't call when docwidth (docheight) is zero. */
  2271. X
  2272. X/* dir is x or y; dim is width or height; bar is hbar or vbar */
  2273. X#define BARCOMPUTE(dir, dim, bar) { \
  2274. X        range= win->bar.dim; \
  2275. X        start= range * (-win->wa.dir) / win->doc.dim; \
  2276. X        size= range * win->wi.dim / win->doc.dim; \
  2277. X        _wdebug(4, "BARCOMPUTE: start=%d, size=%d", start, size); \
  2278. X    }
  2279. X
  2280. X/* Functions to draw the scroll bars.
  2281. X   Currently, the thumb is a rectangle separated by the scroll bar's
  2282. X   borders by a one-pixel wide space */
  2283. X
  2284. X_wdrawhbar(win)
  2285. X    WINDOW *win;
  2286. X{
  2287. X    _wdebug(3, "draw hbar");
  2288. X    XClearWindow(_wd, win->hbar.wid);
  2289. X    if (win->doc.width > win->wi.width) {
  2290. X        int start, size, range;
  2291. X        BARCOMPUTE(x, width, hbar);
  2292. X        XSetTile(_wd, win->gc, _w_gray());
  2293. X        XSetFillStyle(_wd, win->gc, FillTiled);
  2294. X        XFillRectangle(_wd, win->hbar.wid, win->gc,
  2295. X            start + 1, 1, size - 1, win->hbar.height - 2);
  2296. X        XSetFillStyle(_wd, win->gc, FillSolid);
  2297. X    }
  2298. X}
  2299. X
  2300. X_wdrawvbar(win)
  2301. X    WINDOW *win;
  2302. X{
  2303. X    _wdebug(3, "draw vbar");
  2304. X    XClearWindow(_wd, win->vbar.wid);
  2305. X    if (win->doc.height > win->wi.height) {
  2306. X        int start, size, range;
  2307. X        BARCOMPUTE(y, height, vbar);
  2308. X        XSetTile(_wd, win->gc, _w_gray());
  2309. X        XSetFillStyle(_wd, win->gc, FillTiled);
  2310. X        XFillRectangle(_wd, win->vbar.wid, win->gc,
  2311. X            1, start + 1, win->vbar.width - 2, size - 1);
  2312. X        XSetFillStyle(_wd, win->gc, FillSolid);
  2313. X    }
  2314. X}
  2315. X
  2316. X/* Functions to interpret scroll bar hits.
  2317. X   Matching the Toolkit scroll bars, we should implement:
  2318. X   - button 1: scroll forward, amount determined by position
  2319. X   - button 2: position scroll bar begin at pointer
  2320. X   - buttom 3: scroll back, amount determined by position
  2321. X*/
  2322. X
  2323. X/* dir is x or y; dim is width or height; bar is hbar or vbar;
  2324. X   drawcall is _wdraw{h,v}bar; imargin is IMARGIN or 0. */
  2325. X#define HITCODE(dir, dim, bar, drawcall, imargin) { \
  2326. X        WINDOW *win= bsp->win; \
  2327. X        int start, size, range, nstart; \
  2328. X        if (win->doc.dim <= win->wi.dim - imargin) \
  2329. X            return; \
  2330. X        BARCOMPUTE(dir, dim, bar); \
  2331. X        switch (bsp->button) { \
  2332. X        case 1: \
  2333. X            if (bsp->down) return; \
  2334. X            nstart= start + \
  2335. X                (bsp->dir * win->wi.dim + win->doc.dim/2) \
  2336. X                    / win->doc.dim; \
  2337. X            break; \
  2338. X        default: \
  2339. X            nstart= bsp->dir; \
  2340. X            break; \
  2341. X        case 3: \
  2342. X            if (bsp->down) return; \
  2343. X            nstart= start - \
  2344. X                (bsp->dir * win->wi.dim + win->doc.dim/2) \
  2345. X                    / win->doc.dim; \
  2346. X            break; \
  2347. X        } \
  2348. X        CLIPMAX(nstart, range-size); \
  2349. X        CLIPMIN(nstart, 0); \
  2350. X        if (nstart != start) { \
  2351. X            win->wa.dir= \
  2352. X                -(nstart * win->doc.dim / win->bar.dim); \
  2353. X            _wmove(&win->wa); \
  2354. X            drawcall(win); \
  2355. X        } \
  2356. X    }
  2357. X
  2358. X_whithbar(bsp, ep)
  2359. X    struct button_state *bsp;
  2360. X    EVENT *ep;
  2361. X{
  2362. X    _wdebug(3, "hit hbar");
  2363. X    HITCODE(x, width, hbar, _wdrawhbar, IMARGIN);
  2364. X}
  2365. X
  2366. X_whitvbar(bsp, ep)
  2367. X    struct button_state *bsp;
  2368. X    EVENT *ep;
  2369. X{
  2370. X    _wdebug(3, "hit vbar");
  2371. X    HITCODE(y, height, vbar, _wdrawvbar, 0);
  2372. X}
  2373. END_OF_FILE
  2374. if test 2894 -ne `wc -c <'Ports/x11/scroll.c'`; then
  2375.     echo shar: \"'Ports/x11/scroll.c'\" unpacked with wrong size!
  2376. fi
  2377. # end of 'Ports/x11/scroll.c'
  2378. fi
  2379. echo shar: End of archive 16 \(of 19\).
  2380. cp /dev/null ark16isdone
  2381. MISSING=""
  2382. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
  2383.     if test ! -f ark${I}isdone ; then
  2384.     MISSING="${MISSING} ${I}"
  2385.     fi
  2386. done
  2387. if test "${MISSING}" = "" ; then
  2388.     echo You have unpacked all 19 archives.
  2389.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2390. else
  2391.     echo You still need to unpack the following archives:
  2392.     echo "        " ${MISSING}
  2393. fi
  2394. ##  End of shell archive.
  2395. exit 0
  2396.