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

  1. From: guido@cwi.nl (Guido van Rossum)
  2. Newsgroups: alt.sources
  3. Subject: STDWIN 0.9.5, Part 12/19
  4. Message-ID: <3076@charon.cwi.nl>
  5. Date: 4 Mar 91 11:58:12 GMT
  6.  
  7. Archive-name: stdwin/part12
  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 12 (of 19)."
  16. # Contents:  Appls/bed/opmenu.c Appls/miniedit/miniedit.c
  17. #   Appls/repeat/repeat.c Appls/test/faced.c Doc/man/textedit.man
  18. #   Doc/man/vt.man Ports/alfa/bind.c
  19. # Wrapped by guido@voorn.cwi.nl on Mon Mar  4 12:37:30 1991
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'Appls/bed/opmenu.c' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'Appls/bed/opmenu.c'\"
  23. else
  24. echo shar: Extracting \"'Appls/bed/opmenu.c'\" \(7521 characters\)
  25. sed "s/^X//" >'Appls/bed/opmenu.c' <<'END_OF_FILE'
  26. X#include "bed.h"
  27. X#include "menu.h"
  28. X
  29. Xextern int    sqrsize ;
  30. X
  31. Xextern int    map_width ;
  32. Xextern int    map_height ;
  33. X
  34. Xextern char    *raster ;
  35. Xextern int    raster_lenght ;
  36. Xextern int    stride ;
  37. X
  38. Xstatic int    bits[] = { 0xFF, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F } ;
  39. Xextern int    lastbyte ;
  40. X
  41. Xextern WINDOW    *win ;
  42. X
  43. Xextern bool    changed ;
  44. X
  45. Xextern bool    selrect ;
  46. Xextern int    sr_left ;
  47. Xextern int    sr_top ;
  48. Xextern int    sr_right ;
  49. Xextern int    sr_bottom ;
  50. X
  51. X/* Data manipulation routines */
  52. X
  53. Xvoid
  54. Xclear_bits()
  55. X{
  56. X    register int    row ;
  57. X
  58. X    if (!selrect) {
  59. X        sr_left = sr_top = 0 ;
  60. X        sr_right = map_width ;
  61. X        sr_bottom = map_height ;
  62. X    }
  63. X
  64. X    for (row = sr_top ; row < sr_bottom ; ++row) {
  65. X        register int    col = sr_left ;
  66. X        register char    *byte = raster + (row * stride) + (col / 8) ;
  67. X        register int    pbit = col % 8 ;
  68. X
  69. X        while (col++ < sr_right) {
  70. X            *byte &= ~(1 << pbit) ;
  71. X
  72. X            if (++pbit >= 8) {
  73. X                pbit = 0 ;
  74. X                ++byte ;
  75. X            }
  76. X        }
  77. X    }
  78. X
  79. X    wchange (win, sr_left * sqrsize, sr_top * sqrsize,
  80. X        sr_right * sqrsize, sr_bottom * sqrsize) ;
  81. X
  82. X    changed = TRUE ;
  83. X}
  84. X
  85. Xvoid
  86. Xset_bits()
  87. X{
  88. X    register int    row ;
  89. X
  90. X    if (!selrect) {
  91. X        sr_left = sr_top = 0 ;
  92. X        sr_right = map_width ;
  93. X        sr_bottom = map_height ;
  94. X    }
  95. X
  96. X    for (row = sr_top ; row < sr_bottom ; ++row) {
  97. X        register int    col = sr_left ;
  98. X        register char    *byte = raster + (row * stride) + (col / 8) ;
  99. X        register int    pbit = col % 8 ;
  100. X
  101. X        while (col++ < sr_right) {
  102. X            *byte |= (1 << pbit) ;
  103. X
  104. X            if (++pbit >= 8) {
  105. X                pbit = 0 ;
  106. X                ++byte ;
  107. X            }
  108. X        }
  109. X    }
  110. X
  111. X    wchange (win, sr_left * sqrsize, sr_top * sqrsize,
  112. X        sr_right * sqrsize, sr_bottom * sqrsize) ;
  113. X
  114. X    changed = TRUE ;
  115. X}
  116. X
  117. Xvoid
  118. Xinvert_bits()
  119. X{
  120. X    register int    row ;
  121. X
  122. X    if (!selrect) {
  123. X        sr_left = sr_top = 0 ;
  124. X        sr_right = map_width ;
  125. X        sr_bottom = map_height ;
  126. X    }
  127. X
  128. X    for (row = sr_top ; row < sr_bottom ; ++row) {
  129. X        register int    col = sr_left ;
  130. X        register char    *byte = raster + (row * stride) + (col / 8) ;
  131. X        register int    pbit = col % 8 ;
  132. X
  133. X        while (col++ < sr_right) {
  134. X            *byte ^= (1 << pbit) ;
  135. X
  136. X            if (++pbit >= 8) {
  137. X                pbit = 0 ;
  138. X                ++byte ;
  139. X            }
  140. X        }
  141. X    }
  142. X
  143. X    wchange (win, sr_left * sqrsize, sr_top * sqrsize,
  144. X        sr_right * sqrsize, sr_bottom * sqrsize) ;
  145. X
  146. X    changed = TRUE ;
  147. X}
  148. X
  149. Xint
  150. Xtranspose_major()
  151. X{
  152. X    int    i ;
  153. X    int    j ;
  154. X    int    tmp ;
  155. X
  156. X    if (selrect) {
  157. X        if (sr_right - sr_left != sr_bottom - sr_top) {
  158. X            wfleep () ;
  159. X            wmessage ("You can only transpose a square") ;
  160. X            return ;
  161. X        }
  162. X
  163. X        for (i = 0 ; i < sr_bottom - sr_top ; ++i) {
  164. X            for (j = 0 ; j < i ; ++j) {
  165. X                int    row = i + sr_top ;
  166. X                int    col = j + sr_left ;
  167. X    
  168. X                tmp = getbit (col, row) ;
  169. X                setbit (col, row, getbit (i + sr_left,
  170. X                                j + sr_top)) ;
  171. X                setbit (i + sr_left, j + sr_top, tmp) ;
  172. X            }
  173. X        }
  174. X
  175. X        wchange (win, sr_left * sqrsize, sr_top * sqrsize,
  176. X            sr_right * sqrsize, sr_bottom * sqrsize) ;
  177. X
  178. X        changed = TRUE ;
  179. X    }
  180. X    else
  181. X        wfleep () ;
  182. X}
  183. X
  184. Xvoid
  185. Xtranspose_minor ()
  186. X{
  187. X    int    size ;
  188. X    int    i ;
  189. X    int    j ;
  190. X    int    tmp ;
  191. X
  192. X    if (selrect) {
  193. X        if (sr_bottom - sr_top != sr_right - sr_left) {
  194. X            wfleep () ;
  195. X            wmessage ("You can only transpose a square") ;
  196. X            return ;
  197. X        }
  198. X
  199. X        size = sr_bottom - sr_top ;
  200. X
  201. X        for (i = 0 ; i < size ; ++i) {
  202. X            for (j = 0 ; j < size - 1 - i ; ++j) {
  203. X                tmp = getbit (j + sr_left, i + sr_top) ;
  204. X                setbit (j + sr_left, i + sr_top,
  205. X                    getbit (size - 1 - i + sr_left,
  206. X                        size - 1 - j + sr_top)) ;
  207. X                setbit (size - 1 - i + sr_left,
  208. X                    size - 1 - j + sr_top, tmp) ;
  209. X            }
  210. X        }
  211. X
  212. X        wchange (win, sr_left * sqrsize, sr_top * sqrsize,
  213. X            sr_right * sqrsize, sr_bottom * sqrsize) ;
  214. X
  215. X        changed = TRUE ;
  216. X    }
  217. X    else
  218. X        wfleep () ;
  219. X
  220. X}
  221. X
  222. Xint
  223. Xrotate_left()
  224. X{
  225. X    int    i ;
  226. X    int    j ;
  227. X    int    size ;
  228. X    int    tmp ;
  229. X
  230. X    if (selrect) {
  231. X        if (sr_bottom - sr_top != sr_right - sr_left) {
  232. X            wfleep () ;
  233. X            wmessage ("You can only rotate a square") ;
  234. X            return ;    
  235. X        }
  236. X
  237. X        size = sr_bottom - sr_top ;
  238. X
  239. X        for (i = 0 ; i < size / 2 ; ++i) {
  240. X            for (j = 0 ; j < (size + 1) / 2 ; ++j) {
  241. X                tmp = getbit (j + sr_left, i + sr_top) ;
  242. X                setbit (j + sr_left, i + sr_top,
  243. X                    getbit (size - 1 - i + sr_left,
  244. X                        j + sr_top)) ;
  245. X                setbit (size - 1 - i + sr_left, j + sr_top,
  246. X                    getbit (size - 1 - j + sr_left,
  247. X                        size - 1 - i + sr_top)) ;
  248. X                setbit (size - 1 - j + sr_left,
  249. X                    size - 1 - i + sr_top,
  250. X                    getbit (i + sr_left,
  251. X                        size - 1 - j + sr_top)) ;
  252. X                setbit (i + sr_left, size - 1 - j + sr_top,
  253. X                    tmp) ;
  254. X            }
  255. X        }
  256. X
  257. X        wchange (win, sr_left * sqrsize, sr_top * sqrsize,
  258. X            sr_right * sqrsize, sr_bottom * sqrsize) ;
  259. X
  260. X        changed = TRUE ;
  261. X    }
  262. X    else
  263. X        wfleep () ;
  264. X}
  265. X
  266. Xvoid
  267. Xrotate_right()
  268. X{
  269. X    int    i ;
  270. X    int    j ;
  271. X    int    size ;
  272. X    int    tmp ;
  273. X
  274. X    if (selrect) {
  275. X        if (sr_bottom - sr_top != sr_right - sr_left) {
  276. X            wfleep () ;
  277. X            wmessage ("You can only rotate a square") ;
  278. X            return ;
  279. X        }
  280. X
  281. X        size = sr_bottom - sr_top ;
  282. X
  283. X        for (i = 0 ; i < size / 2 ; ++i) {
  284. X            for (j = 0 ; j < (size + 1) / 2 ; ++j) {
  285. X                tmp = getbit (j + sr_left, i + sr_top) ; 
  286. X                setbit (j + sr_left, i + sr_top,
  287. X                    getbit (i + sr_left,
  288. X                        size - 1 - j + sr_top)) ;
  289. X                setbit (i + sr_left, size - 1 - j + sr_top,
  290. X                    getbit (size - 1 - j + sr_left,
  291. X                        size - 1 - i + sr_top)) ;
  292. X                setbit (size - 1 - j + sr_left,
  293. X                    size - 1 - i + sr_top,
  294. X                    getbit (size - 1 - i + sr_left,
  295. X                        j + sr_top)) ;
  296. X                setbit (size - 1 - i + sr_left, j + sr_top,
  297. X                    tmp) ;
  298. X            }
  299. X        }
  300. X
  301. X        wchange (win, sr_left * sqrsize, sr_top * sqrsize,
  302. X            sr_right * sqrsize, sr_bottom * sqrsize) ;
  303. X
  304. X        changed = TRUE ;
  305. X    }
  306. X}
  307. X
  308. Xvoid
  309. Xflip_horizontal()
  310. X{
  311. X    int    i ;
  312. X    int    j ;
  313. X    int    sr_width ;
  314. X    int    sr_height ;
  315. X    int    tmp ;
  316. X
  317. X    if (selrect) {
  318. X        sr_width = sr_right - sr_left ;
  319. X        sr_height = sr_bottom - sr_top ;
  320. X
  321. X        for (i = 0 ; i < sr_height ; ++ i) {
  322. X            for (j = 0 ; j < sr_width / 2 ; ++j) {
  323. X                tmp = getbit (j + sr_left, i + sr_top) ;
  324. X                setbit (j + sr_left, i + sr_top,
  325. X                    getbit (sr_width - 1 - j + sr_left,
  326. X                        i + sr_top)) ;
  327. X                setbit (sr_width - 1 - j + sr_left, i + sr_top,
  328. X                    tmp) ;
  329. X            }
  330. X        }
  331. X
  332. X        wchange (win, sr_left * sqrsize, sr_top * sqrsize,
  333. X            sr_right * sqrsize, sr_bottom * sqrsize) ;
  334. X
  335. X        changed = TRUE ;
  336. X    }
  337. X    else
  338. X        wfleep () ;
  339. X}
  340. X
  341. Xvoid
  342. Xflip_vertical()
  343. X{
  344. X    int    i ;
  345. X    int    j ;
  346. X    int    sr_width ;
  347. X    int    sr_height ;
  348. X    int    tmp ;
  349. X
  350. X    if (selrect) {
  351. X        sr_width = sr_right - sr_left ;
  352. X        sr_height = sr_bottom - sr_top ;
  353. X
  354. X        for (i = 0 ; i < sr_height / 2 ; ++i) {
  355. X            for (j = 0 ; j < sr_width ; ++j) {
  356. X                tmp = getbit (j + sr_left, i + sr_top) ;
  357. X                setbit (j + sr_left, i + sr_top,
  358. X                    getbit (j + sr_left,
  359. X                        sr_height - 1 - i + sr_top)) ;
  360. X                setbit (j + sr_left, sr_height - 1 - i + sr_top,
  361. X                    tmp) ;
  362. X            }
  363. X        }
  364. X
  365. X        wchange (win, sr_left * sqrsize, sr_top * sqrsize,
  366. X            sr_right * sqrsize, sr_bottom * sqrsize) ;
  367. X
  368. X        changed = TRUE ;
  369. X    }
  370. X    else
  371. X        wfleep () ;
  372. X}
  373. X
  374. Xvoid
  375. Xzoom_in ()
  376. X{
  377. X    sqrsize *= 2 ;
  378. X    wsetdocsize (win, map_width * sqrsize, map_height * sqrsize) ;
  379. X    wchange (win, 0, 0, map_width * sqrsize, map_height * sqrsize) ;
  380. X}
  381. X
  382. Xvoid
  383. Xzoom_out ()
  384. X{
  385. X    int oss = sqrsize ;
  386. X    if (sqrsize == 1) wfleep () ;
  387. X    else {
  388. X        if ((sqrsize /= 2) < 1) sqrsize = 1 ;
  389. X        wsetdocsize (win, map_width * sqrsize, map_height * sqrsize) ;
  390. X        wchange (win, 0, 0, map_width * oss, map_height * oss) ;
  391. X    }
  392. X}
  393. X
  394. X
  395. Xvoid
  396. Xdo_op_menu (ep)
  397. X    EVENT    *ep ;
  398. X{
  399. X    switch (ep->u.m.item) {
  400. X    case CLEAR_ITEM :
  401. X        clear_bits () ;
  402. X        break ;
  403. X    case SET_ITEM :
  404. X        set_bits () ;
  405. X        break ;
  406. X    case INVERT_ITEM :
  407. X        invert_bits () ;
  408. X        break ;
  409. X    case TRANS_MAJ_ITEM :
  410. X        transpose_major () ;
  411. X        break ;
  412. X    case TRANS_MIN_ITEM :
  413. X        transpose_minor () ;
  414. X        break ;
  415. X    case ROT_LEFT_ITEM :
  416. X        rotate_left () ;
  417. X        break ;
  418. X    case ROT_RIGHT_ITEM :
  419. X        rotate_right () ;
  420. X        break ;
  421. X    case FLIP_HOR_ITEM :
  422. X        flip_horizontal () ;
  423. X        break ;
  424. X    case FLIP_VERT_ITEM :
  425. X        flip_vertical () ;
  426. X        break ;
  427. X    case ZOOM_IN :
  428. X        zoom_in () ;
  429. X        break ;
  430. X    case ZOOM_OUT :
  431. X        zoom_out () ;
  432. X        break ;
  433. X    }
  434. X}
  435. END_OF_FILE
  436. if test 7521 -ne `wc -c <'Appls/bed/opmenu.c'`; then
  437.     echo shar: \"'Appls/bed/opmenu.c'\" unpacked with wrong size!
  438. fi
  439. # end of 'Appls/bed/opmenu.c'
  440. fi
  441. if test -f 'Appls/miniedit/miniedit.c' -a "${1}" != "-c" ; then 
  442.   echo shar: Will not clobber existing file \"'Appls/miniedit/miniedit.c'\"
  443. else
  444. echo shar: Extracting \"'Appls/miniedit/miniedit.c'\" \(6739 characters\)
  445. sed "s/^X//" >'Appls/miniedit/miniedit.c' <<'END_OF_FILE'
  446. X/* Mini-editor using editwin module */
  447. X
  448. X#include "stdwin.h"
  449. X#include "tools.h"
  450. X#include "editwin.h"
  451. X
  452. Xmain(argc, argv)
  453. X    int argc;
  454. X    char **argv;
  455. X{
  456. X    winitargs(&argc, &argv);
  457. X    menusetup();
  458. X    openfiles(argc, argv);
  459. X    mainloop();
  460. X    wdone();
  461. X    exit(0);
  462. X}
  463. X
  464. XMENU *filemenu, *editmenu, *findmenu;
  465. X
  466. X#define FILE_MENU    1
  467. X#define EDIT_MENU    2
  468. X#define FIND_MENU    3
  469. X
  470. X/* File items */
  471. X#define NEW_ITEM    0
  472. X#define OPEN_ITEM    1
  473. X#define CLOSE_ITEM    3
  474. X#define SAVE_ITEM    4
  475. X#define SAVE_AS_ITEM    5
  476. X#define SAVE_COPY_ITEM    6
  477. X#define REVERT_ITEM    7
  478. X#define QUIT_ITEM    9
  479. X
  480. X/* Edit items */
  481. X#define UNDO_ITEM    0
  482. X#define CUT_ITEM    2
  483. X#define COPY_ITEM    3
  484. X#define PASTE_ITEM    4
  485. X#define CLEAR_ITEM    5
  486. X#define SEL_ALL_ITEM    6
  487. X#define EXEC_ITEM    8
  488. X
  489. X/* Find items */
  490. X#define FIND_ITEM    0
  491. X#define FIND_SAME_ITEM    1
  492. X#define REPL_ITEM    3
  493. X#define REPL_SAME_ITEM    4
  494. X#define REPL_ALL_ITEM    5
  495. X
  496. Xmenusetup()
  497. X{
  498. X    MENU *mp;
  499. X    
  500. X    filemenu= mp= wmenucreate(FILE_MENU, "File");
  501. X    
  502. X    wmenuadditem(mp, "New", 'N');
  503. X    wmenuadditem(mp, "Open...", 'o');
  504. X    wmenuadditem(mp, "", -1);
  505. X    wmenuadditem(mp, "Close", 'K');
  506. X    wmenuadditem(mp, "Save", 'S');
  507. X    wmenuadditem(mp, "Save as...", -1);
  508. X    wmenuadditem(mp, "Save a Copy...", -1);
  509. X    wmenuadditem(mp, "Revert to Saved", -1);
  510. X    wmenuadditem(mp, "", -1);
  511. X    wmenuadditem(mp, "Quit", 'Q');
  512. X    
  513. X    editmenu= mp= wmenucreate(EDIT_MENU, "Edit");
  514. X    
  515. X    wmenuadditem(mp, "Undo", 'Z');
  516. X    wmenuadditem(mp, "", -1);
  517. X    wmenuadditem(mp, "Cut", 'X');
  518. X    wmenuadditem(mp, "Copy", 'C');
  519. X    wmenuadditem(mp, "Paste", 'V');
  520. X    wmenuadditem(mp, "Clear", 'B');
  521. X    wmenuadditem(mp, "Select All", 'A');
  522. X    wmenuadditem(mp, "", -1);
  523. X    wmenuadditem(mp, "Execute", '\r');
  524. X    
  525. X    findmenu= mp= wmenucreate(FIND_MENU, "Find");
  526. X    
  527. X    wmenuadditem(mp, "Find...", 'F');
  528. X    wmenuadditem(mp, "Find Same", 'G');
  529. X    wmenuadditem(mp, "", -1);
  530. X    wmenuadditem(mp, "Replace...", 'R');
  531. X    wmenuadditem(mp, "Replace Same", 'T');
  532. X    wmenuadditem(mp, "Replace All", -1);
  533. X}
  534. X
  535. Xfixmenus(ew)
  536. X    EDITWIN *ew;
  537. X{
  538. X    bool focus;
  539. X    
  540. X    if (ew == NULL)
  541. X        return;
  542. X    
  543. X    wmenuenable(filemenu, SAVE_ITEM, !ew->saved);
  544. X    wmenuenable(filemenu, REVERT_ITEM, !ew->saved);
  545. X    
  546. X    wmenuenable(editmenu, UNDO_ITEM, FALSE);
  547. X    wmenuenable(editmenu, EXEC_ITEM, FALSE);
  548. X    
  549. X    focus= tegetfoc1(ew->tp) < tegetfoc2(ew->tp);
  550. X    wmenuenable(editmenu, CUT_ITEM, focus);
  551. X    wmenuenable(editmenu, COPY_ITEM, focus);
  552. X    wmenuenable(editmenu, CLEAR_ITEM, focus);
  553. X}
  554. X
  555. Xopenfiles(argc, argv)
  556. X    int argc;
  557. X    char **argv;
  558. X{
  559. X    int i;
  560. X    
  561. X    for (i= 1; i < argc; ++i) {
  562. X        (void) ewcreate(argv[i]);
  563. X    }
  564. X    if (ewcount() == 0) {
  565. X        if (ewopen() == NULL && ewnew() == NULL) {
  566. X            wdone();
  567. X            fprintf(stderr, "Can't open any windows\n");
  568. X            exit(1);
  569. X        }
  570. X    }
  571. X}
  572. X
  573. Xmainloop()
  574. X{
  575. X    for (;;) {
  576. X        EVENT e;
  577. X        EDITWIN *ew;
  578. X        
  579. X        wgetevent(&e);
  580. X        ew= ewfind(e.window);
  581. X        switch (e.type) {
  582. X        case WE_MENU:
  583. X            switch (e.u.m.id) {
  584. X            
  585. X            case FILE_MENU:
  586. X                switch (e.u.m.item) {
  587. X                case NEW_ITEM:
  588. X                    (void) ewnew();
  589. X                    break;
  590. X                case OPEN_ITEM:
  591. X                    (void) ewopen();
  592. X                    break;
  593. X                case CLOSE_ITEM:
  594. X                    if (ew != NULL) {
  595. X                        ewclose(ew);
  596. X                        if (ewcount() == 0)
  597. X                            return;
  598. X                    }
  599. X                    break;
  600. X                case SAVE_ITEM:
  601. X                    if (ew != NULL)
  602. X                        ewsave(ew);
  603. X                    break;
  604. X                case SAVE_AS_ITEM:
  605. X                    if (ew != NULL)
  606. X                        ewsaveas(ew);
  607. X                    break;
  608. X                case SAVE_COPY_ITEM:
  609. X                    if (ew != NULL)
  610. X                        ewsavecopy(ew);
  611. X                    break;
  612. X                case REVERT_ITEM:
  613. X                    if (ew != NULL)
  614. X                        ewrevert(ew);
  615. X                    break;
  616. X                case QUIT_ITEM:
  617. X                    if (ewcloseall())
  618. X                        return;
  619. X                    break;
  620. X                }
  621. X                break;
  622. X            
  623. X            case EDIT_MENU:
  624. X                if (ew == NULL) {
  625. X                    wfleep();
  626. X                    break;
  627. X                }
  628. X                switch (e.u.m.item) {
  629. X                case UNDO_ITEM:
  630. X                    ewundo(ew);
  631. X                    break;
  632. X                case CUT_ITEM:
  633. X                    ewcopy(ew);
  634. X                    ewreplace(ew, "");
  635. X                    break;
  636. X                case COPY_ITEM:
  637. X                    ewcopy(ew);
  638. X                    break;
  639. X                case PASTE_ITEM:
  640. X                    ewpaste(ew);
  641. X                    break;
  642. X                case CLEAR_ITEM:
  643. X                    ewreplace(ew, "");
  644. X                    break;
  645. X                case SEL_ALL_ITEM:
  646. X                    tesetfocus(ew->tp, 0,
  647. X                        tegetlen(ew->tp));
  648. X                    break;
  649. X                case EXEC_ITEM:
  650. X                    wfleep();
  651. X                    break;
  652. X                }
  653. X                break;
  654. X            
  655. X            case FIND_MENU:
  656. X                switch (e.u.m.item) {
  657. X                case FIND_ITEM:
  658. X                    find(ew, TRUE);
  659. X                    break;
  660. X                case FIND_SAME_ITEM:
  661. X                    find(ew, FALSE);
  662. X                    break;
  663. X                case REPL_ITEM:
  664. X                    replace(ew, TRUE);
  665. X                    break;
  666. X                case REPL_SAME_ITEM:
  667. X                    replace(ew, FALSE);
  668. X                    break;
  669. X                case REPL_ALL_ITEM:
  670. X                    replall(ew);
  671. X                    break;
  672. X                }
  673. X                break;
  674. X            
  675. X            }
  676. X            break;
  677. X        
  678. X        default:
  679. X            if (ew != NULL) {
  680. X                bool closed;
  681. X                ewevent(ew, &e, &closed);
  682. X                if (closed && ewcount() == 0)
  683. X                    return;
  684. X            }
  685. X            break;
  686. X        
  687. X        }
  688. X        
  689. X        fixmenus(ew);
  690. X    }
  691. X}
  692. X
  693. X#include "regexp.h"
  694. X
  695. Xchar whatbuf[256];    /* Last regular expression typed */
  696. Xregexp *prog;        /* Compiled regular expression */
  697. Xchar replbuf[256];    /* Last replacement string */
  698. X
  699. Xbool
  700. Xfind(ew, dodialog)
  701. X    EDITWIN *ew;
  702. X    bool dodialog;
  703. X{
  704. X    return finddialog(ew, dodialog, "Find regular expression:") &&
  705. X        findit(ew, FALSE);
  706. X}
  707. X
  708. Xbool
  709. Xreplace(ew, dodialog)
  710. X    EDITWIN *ew;
  711. X    bool dodialog;
  712. X{
  713. X    if (!finddialog(ew, dodialog, "Replace regular expression:")
  714. X        || !findit(ew, TRUE))
  715. X        return FALSE;
  716. X    wupdate(ew->win); /* Show what we've found */
  717. X    return repldialog(ew, dodialog) && replit(ew);
  718. X}
  719. X
  720. Xreplall(ew)
  721. X    EDITWIN *ew;
  722. X{
  723. X    if (!replace(ew, TRUE))
  724. X        return FALSE;
  725. X    while (findit(ew, TRUE)) {
  726. X        wupdate(ew->win);
  727. X        replit(ew);
  728. X        wupdate(ew->win);
  729. X        /* What if it takes forever? */
  730. X    }
  731. X    return TRUE;
  732. X}
  733. X
  734. Xbool
  735. Xfinddialog(ew, dodialog, prompt)
  736. X    EDITWIN *ew;
  737. X    bool dodialog;
  738. X    char *prompt;
  739. X{
  740. X    if (ew == NULL)
  741. X        return FALSE;
  742. X    if (dodialog || prog == NULL) {
  743. X        if (!waskstr(prompt, whatbuf, sizeof whatbuf))
  744. X            return FALSE;
  745. X        if (prog != NULL)
  746. X            free((char*)prog);
  747. X        prog= regcomp(whatbuf);
  748. X        if (prog == NULL)
  749. X            return FALSE;
  750. X    }
  751. X    return TRUE;
  752. X}
  753. X
  754. Xbool
  755. Xrepldialog(ew, dodialog)
  756. X    EDITWIN *ew;
  757. X    bool dodialog;
  758. X{
  759. X    if (!dodialog)
  760. X        return TRUE;
  761. X    return waskstr("Replacement string:", replbuf, sizeof replbuf);
  762. X}
  763. X
  764. Xbool
  765. Xfindit(ew, begin)
  766. X    EDITWIN *ew;
  767. X    bool begin; /* TRUE if must start at foc1 */
  768. X{
  769. X    int foc1= tegetfoc1(ew->tp);
  770. X    int foc2= tegetfoc2(ew->tp);
  771. X    int len= tegetlen(ew->tp);
  772. X    char *text= tegettext(ew->tp);
  773. X    
  774. X    if (!reglexec(prog, text, begin ? foc1 : foc2)) {
  775. X        wfleep();
  776. X        return FALSE;
  777. X    }
  778. X    if (!begin && prog->startp[0] == text+foc2 && foc1 == foc2 &&
  779. X        prog->startp[0] == prog->endp[0]) {
  780. X        /* Found empty string at empty focus;
  781. X           try again at next position (if in range) */
  782. X        if (++foc2 > len)
  783. X            return FALSE;
  784. X        if (!reglexec(prog, text, foc2)) {
  785. X            wfleep();
  786. X            return FALSE;
  787. X        }
  788. X    }
  789. X    tesetfocus(ew->tp, (int)(prog->startp[0] - text),
  790. X        (int)(prog->endp[0] - text));
  791. X    return TRUE;
  792. X}
  793. X
  794. Xbool
  795. Xreplit(ew)
  796. X    EDITWIN *ew;
  797. X{
  798. X    char substbuf[1024];
  799. X    /* Should be bigger -- what if the entire file matches? */
  800. X    
  801. X    regsub(prog, replbuf, substbuf);
  802. X    ewreplace(ew, substbuf);
  803. X    return TRUE;
  804. X}
  805. X
  806. Xvoid
  807. Xregerror(str)
  808. X    char *str;
  809. X{
  810. X    char buf[256];
  811. X    
  812. X    sprintf(buf, "Regular expression error: %s", str);
  813. X    wmessage(buf);
  814. X}
  815. END_OF_FILE
  816. if test 6739 -ne `wc -c <'Appls/miniedit/miniedit.c'`; then
  817.     echo shar: \"'Appls/miniedit/miniedit.c'\" unpacked with wrong size!
  818. fi
  819. # end of 'Appls/miniedit/miniedit.c'
  820. fi
  821. if test -f 'Appls/repeat/repeat.c' -a "${1}" != "-c" ; then 
  822.   echo shar: Will not clobber existing file \"'Appls/repeat/repeat.c'\"
  823. else
  824. echo shar: Extracting \"'Appls/repeat/repeat.c'\" \(6739 characters\)
  825. sed "s/^X//" >'Appls/repeat/repeat.c' <<'END_OF_FILE'
  826. X/* Repeat a command forever, displaying the output in a window.
  827. X   This is useful to have a continuously update from status programs
  828. X   like 'ps' or 'lpq'.
  829. X   
  830. X   Usage: repeat [-d delay] command [arg] ...
  831. X   
  832. X   To do:
  833. X    - adapt textedit width to window width?
  834. X    - allocate image buffer dynamically
  835. X    - more sensible error handling (allow to cancel)
  836. X    - add a menu option to change the delay
  837. X    - display the delay somehow
  838. X    - use d.ddd seconds notation instead of deciseconds
  839. X    - avoid flickering screen in X11 version
  840. X      (possibly by using tereplace on the smallest changed section,
  841. X      except need a way to turn the caret off???)
  842. X*/
  843. X
  844. X#include <stdio.h>
  845. X#include <string.h>
  846. X#include <stdwin.h>
  847. X
  848. Xextern char *malloc();
  849. X
  850. XWINDOW *win;
  851. XTEXTEDIT *tp;
  852. X
  853. X#define MAXSIZE 10000
  854. X
  855. X#define DELAY 5 /* retry after success in 0.5 seconds */
  856. X#define ERRDELAY 50 /* retry after popen error in 5 seconds */
  857. X
  858. Xint delay = DELAY; /* normal delay */
  859. Xint errdelay = ERRDELAY; /* delay after popen error */
  860. Xint tflag = 0; /* Display time above output when set */
  861. X
  862. Xchar *progname = "REPEAT";
  863. X
  864. Xvoid usage() {
  865. X    wdone();
  866. X    fprintf(stderr,
  867. X        "usage: %s [-d ddd.d] [-e ddd.d] [-t] cmd [arg] ...\n",
  868. X        progname);
  869. X    fprintf(stderr, "-d ddd.d: delay N seconds after command\n");
  870. X    fprintf(stderr, "-e ddd.d: delay N seconds after error\n");
  871. X    fprintf(stderr, "-t      : display current time above output\n");
  872. X    exit(2);
  873. X}
  874. X
  875. Xextern int optind;
  876. Xextern char *optarg;
  877. X
  878. Xvoid mainloop();
  879. Xvoid rerun();
  880. Xvoid drawproc();
  881. Xchar *mktitle();
  882. Xlong getfract();
  883. X
  884. Xint main(argc, argv)
  885. X    int argc;
  886. X    char **argv;
  887. X{
  888. X    int c;
  889. X    winitargs(&argc, &argv); /* Must be first for X11 */
  890. X    if (argc > 0 && argv[0] != NULL && argv[0][0] != '\0')
  891. X        progname = argv[0];
  892. X    while ((c = getopt(argc, argv, "d:e:t")) != EOF) {
  893. X        switch (c) {
  894. X        case 'd':
  895. X            delay = getfract(&optarg, 10);
  896. X            if (*optarg != '\0') {
  897. X                fprintf(stderr, "-d argument format error\n");
  898. X                usage();
  899. X            }
  900. X            if (delay <= 0)
  901. X                delay = DELAY;
  902. X            break;
  903. X        case 'e':
  904. X            errdelay = getfract(&optarg, 10);
  905. X            if (*optarg != '\0') {
  906. X                fprintf(stderr, "-e argument format error\n");
  907. X                usage();
  908. X            }
  909. X            if (errdelay <= 0)
  910. X                errdelay = ERRDELAY;
  911. X            break;
  912. X        case 't':
  913. X            tflag = 1;
  914. X            break;
  915. X        default:
  916. X            usage();
  917. X            /*NOTREACHED*/
  918. X        }
  919. X    }
  920. X    if (optind >= argc) {
  921. X        usage();
  922. X        /* NOTREACHED*/
  923. X    }
  924. X    win = wopen(mktitle(argc-optind, argv+optind), drawproc);
  925. X    if (win == NULL) {
  926. X        wdone();
  927. X        fprintf(stderr, "can't open window\n");
  928. X        return 1;
  929. X    }
  930. X    tp = tecreate(win, 0, 0, 10000, 10000);
  931. X    if (tp == NULL) {
  932. X        wclose(win);
  933. X        wdone();
  934. X        fprintf(stderr, "can't create textedit block\n");
  935. X        return 1;
  936. X    }
  937. X    mainloop(argc-optind, argv+optind);
  938. X    wdone();
  939. X    return 0;
  940. X}
  941. X
  942. Xvoid mainloop(argc, argv)
  943. X    int argc;
  944. X    char **argv;
  945. X{
  946. X    rerun(argc, argv);
  947. X    
  948. X    for (;;) {
  949. X        EVENT e;
  950. X        wgetevent(&e);
  951. X        switch (e.type) {
  952. X        case WE_TIMER:
  953. X            rerun(argc, argv);
  954. X            break;
  955. X        case WE_COMMAND:
  956. X            switch (e.u.command) {
  957. X            case WC_CLOSE:
  958. X            case WC_CANCEL:
  959. X                return;
  960. X            case WC_RETURN:
  961. X                rerun(argc, argv);
  962. X                break;
  963. X            }
  964. X            break;
  965. X        case WE_CLOSE:
  966. X            return;
  967. X        }
  968. X    }
  969. X}
  970. X
  971. Xvoid rerun(argc, argv)
  972. X    int argc;
  973. X    char **argv;
  974. X{
  975. X    int fd;
  976. X    char *image, *p;
  977. X    int left, n;
  978. X    
  979. X    if ((image = malloc(MAXSIZE)) == NULL) {
  980. X        wmessage("can't malloc output buffer");
  981. X        wsettimer(win, errdelay);
  982. X        return;
  983. X    }
  984. X    if ((fd = readfrom(argc, argv)) < 0) {
  985. X        wmessage("can't start command");
  986. X        wsettimer(win, errdelay);
  987. X        return;
  988. X    }
  989. X    left = MAXSIZE;
  990. X    p = image;
  991. X    if (tflag) {
  992. X        extern char *ctime();
  993. X        extern long time();
  994. X        long t;
  995. X        time(&t);
  996. X        strcpy(p, ctime(&t));
  997. X        p = strchr(p, '\0');
  998. X    }
  999. X    while (left > 0 && (n = read(fd, p, left)) > 0) {
  1000. X        p += n;
  1001. X        left -= n;
  1002. X    }
  1003. X    close(fd);
  1004. X    (void) wait((int *)0); /* Get rid of child -- naively */
  1005. X    tesetbuf(tp, image, (int)(p - image));
  1006. X    wsetdocsize(win, 0, tegetbottom(tp));
  1007. X    wnocaret(win); /* Hack */
  1008. X    wsettimer(win, delay);
  1009. X}
  1010. X
  1011. Xvoid drawproc(win, left, top, right, bottom)
  1012. X    WINDOW *win;
  1013. X{
  1014. X    tedrawnew(tp, left, top, right, bottom);
  1015. X}
  1016. X
  1017. Xchar *mktitle(argc, argv)
  1018. X    int argc;
  1019. X    char **argv;
  1020. X{
  1021. X    static char buf[1000];
  1022. X    int i;
  1023. X    char *p;
  1024. X    
  1025. X    p = buf;
  1026. X    for (i = 0; i < argc; ++i) {
  1027. X        if (i > 0) *p++ = ' ';
  1028. X        strcpy(p, argv[i]);
  1029. X        p = strchr(p, '\0');
  1030. X    }
  1031. X    return buf;
  1032. X}
  1033. X
  1034. X/* Function to get a number of the form ddd.ddd from a string, without
  1035. X   using floating point variables.  Input is the address of a string
  1036. X   pointer, which is incremented by the function to point after the
  1037. X   last character that was part of the number.
  1038. X   The function return value is X * scale, where X is the exact value
  1039. X   read from the string, e.g., for input "3.14" and scale 1000, 3140 is
  1040. X   returned.
  1041. X   There is no provision for a leading sign or to leading spaces.
  1042. X   Overflow goes undetected.
  1043. X*/
  1044. X
  1045. Xlong getfract(pstr, scale)
  1046. X    char **pstr;
  1047. X    long scale;
  1048. X{
  1049. X    char *str = *pstr;
  1050. X    long x = 0;
  1051. X    int in_fraction = 0;
  1052. X    char c;
  1053. X    
  1054. X    for (; (c = *str) != '\0'; str++) {
  1055. X        if (c >= '0' && c <= '9') {
  1056. X            if (in_fraction) {
  1057. X                if (scale < 10)
  1058. X                    break;
  1059. X                scale /= 10;
  1060. X            }
  1061. X            x = x*10 + (c - '0');
  1062. X        }
  1063. X        else if (c == '.' && !in_fraction)
  1064. X            in_fraction = 1;
  1065. X        else
  1066. X            break;
  1067. X    }
  1068. X    *pstr = str;
  1069. X    return x*scale;
  1070. X}
  1071. X
  1072. X/*
  1073. X                  Copyright 1989 by Douglas A. Young
  1074. X
  1075. X                           All Rights Reserved
  1076. X
  1077. X   Permission to use, copy, modify, and distribute this software 
  1078. X   for any purpose and without fee is hereby granted,
  1079. X   provided that the above copyright notice appear in all copies and that
  1080. X   both that copyright notice and this permission notice appear in
  1081. X   supporting documentation. The author disclaims all warranties with 
  1082. X   regard to this software, including all implied warranties of 
  1083. X   merchantability and fitness.
  1084. X
  1085. X   Comments and additions may be sent the author at:
  1086. X
  1087. X    dayoung@hplabs.hp.com
  1088. X
  1089. X   Modified to resemble popen(..., "r").  Returns the file descriptor
  1090. X   from which to read, or negative if an error occurred.  (The pid is lost.)
  1091. X   Name changed from talkto() to readfrom(). --Guido van Rossum, CWI
  1092. X*/
  1093. X
  1094. Xint
  1095. Xreadfrom(argc, argv)
  1096. X    int argc;
  1097. X    char **argv;
  1098. X{
  1099. X    int to_parent[2]; /* pipe descriptors from child->parent */
  1100. X    int pid;
  1101. X
  1102. X    if (pipe(to_parent) < 0) {
  1103. X        perror("pipe");
  1104. X        return -1;
  1105. X    }
  1106. X    pid = fork();
  1107. X    if (pid == 0) {                      /* in the child */
  1108. X        close(0);                    /* redirect stdin */
  1109. X        open("/dev/null", 0);
  1110. X        close(1);                    /* redirect stdout */
  1111. X        dup(to_parent[1]);
  1112. X        close(2);                    /* redirect stderr */
  1113. X        dup(to_parent[1]);
  1114. X
  1115. X        close(to_parent[0]);
  1116. X        close(to_parent[1]);
  1117. X
  1118. X        execvp(argv[0], argv);       /* exec the new cmd */
  1119. X        perror(argv[0]);             /* error in child! */
  1120. X        _exit(127);
  1121. X    }
  1122. X    else if (pid > 0) {                  /* in the parent */
  1123. X        close(to_parent[1]);
  1124. X        return to_parent[0];
  1125. X    }
  1126. X    else {                               /* error! */
  1127. X        perror("vfork");
  1128. X        return -1;
  1129. X    }
  1130. X}
  1131. END_OF_FILE
  1132. if test 6739 -ne `wc -c <'Appls/repeat/repeat.c'`; then
  1133.     echo shar: \"'Appls/repeat/repeat.c'\" unpacked with wrong size!
  1134. fi
  1135. # end of 'Appls/repeat/repeat.c'
  1136. fi
  1137. if test -f 'Appls/test/faced.c' -a "${1}" != "-c" ; then 
  1138.   echo shar: Will not clobber existing file \"'Appls/test/faced.c'\"
  1139. else
  1140. echo shar: Extracting \"'Appls/test/faced.c'\" \(7101 characters\)
  1141. sed "s/^X//" >'Appls/test/faced.c' <<'END_OF_FILE'
  1142. X/* Simple bitmap editor.
  1143. X   Uses ".face" file format (48x48).
  1144. X   
  1145. X   TO DO:
  1146. X       - fix row/col confusion
  1147. X    - connect dots given by mouse move?
  1148. X    - optimize drawing of consequtive black squares
  1149. X    - add open... command
  1150. X    - add flexible input format
  1151. X    - support X bitmap format
  1152. X    */
  1153. X
  1154. X#include <stdio.h>
  1155. X#include "stdwin.h"
  1156. X
  1157. X#define ROWS 48
  1158. X#define COLS 48
  1159. X#define SIZE (ROWS < COLS ? ROWS : COLS)
  1160. X
  1161. X#define BITS 16 /* Bits per word */
  1162. X
  1163. Xchar bit[ROWS][COLS];
  1164. X
  1165. Xint xscale= 5;
  1166. Xint yscale= 5;
  1167. X
  1168. XWINDOW *win;
  1169. X
  1170. Xint changed= 0;
  1171. X
  1172. X
  1173. Xmain(argc, argv)
  1174. X    int argc;
  1175. X    char **argv;
  1176. X{
  1177. X    FILE *fp;
  1178. X    
  1179. X    winitargs(&argc, &argv);
  1180. X    
  1181. X    if (argc > 1) {
  1182. X        fp= fopen(argv[1], "r");
  1183. X        if (fp == NULL) {
  1184. X            wdone();
  1185. X            perror(argv[1]);
  1186. X            exit(1);
  1187. X        }
  1188. X        input(fp);
  1189. X        fclose(fp);
  1190. X    }
  1191. X    
  1192. X    setup();
  1193. X    
  1194. X
  1195. X    for (;;) {
  1196. X        editing();
  1197. X        
  1198. X        if (changed) {
  1199. X            switch (waskync("Save changes?", 1)) {
  1200. X            case 1:
  1201. X                if (!save(argc > 1 ? argv[1] : NULL))
  1202. X                    continue;
  1203. X                break;
  1204. X            case -1:
  1205. X                continue;
  1206. X            }
  1207. X        }
  1208. X        break; /* Out of loop */
  1209. X    }
  1210. X    
  1211. X    wdone();
  1212. X    exit(0);
  1213. X}
  1214. X
  1215. Xsave(name)
  1216. X    char *name;
  1217. X{
  1218. X    FILE *fp;
  1219. X    char namebuf[256];
  1220. X    
  1221. X    namebuf[0]= '\0';
  1222. X    if (name == NULL) {
  1223. X        if (!waskfile("Save as", namebuf, sizeof namebuf, 1))
  1224. X            return 0;
  1225. X        name= namebuf;
  1226. X    }
  1227. X    fp= fopen(name, "w");
  1228. X    if (fp == NULL) {
  1229. X        wperror(name);
  1230. X        return 0;
  1231. X    }
  1232. X    output(fp);
  1233. X    fclose(fp);
  1234. X    return 1;
  1235. X}
  1236. X
  1237. X#define MAIN_MENU    1
  1238. X
  1239. X#define QUIT_ITEM    0
  1240. X
  1241. X#define OP_MENU        2
  1242. X
  1243. X#define CLEAR_ITEM    0
  1244. X#define SET_ITEM    1
  1245. X#define INVERT_ITEM    2
  1246. X#define TRANS_MAJ_ITEM    3
  1247. X#define TRANS_MIN_ITEM    4
  1248. X#define ROT_LEFT_ITEM    5
  1249. X#define ROT_RIGHT_ITEM    6
  1250. X#define FLIP_HOR_ITEM    7
  1251. X#define FLIP_VERT_ITEM    8
  1252. X
  1253. X#define NOPS        9
  1254. X
  1255. Xextern int (*oplist[])(); /* Forward */
  1256. Xdrawproc(); /* Forward */
  1257. X
  1258. Xint text_only;
  1259. X
  1260. Xsetup()
  1261. X{
  1262. X    MENU *mp;
  1263. X    int width, height;
  1264. X    
  1265. X    if (wlineheight() == 1)
  1266. X        text_only= xscale= yscale= 1;
  1267. X    
  1268. X    wsetdefwinsize(COLS*xscale, ROWS*yscale);
  1269. X    
  1270. X    mp= wmenucreate(MAIN_MENU, "Faced");
  1271. X    wmenuadditem(mp, "Quit", 'Q');
  1272. X    mp= wmenucreate(OP_MENU, "Operations");
  1273. X    wmenuadditem(mp, "Clear all", -1);
  1274. X    wmenuadditem(mp, "Set all", -1);
  1275. X    wmenuadditem(mp, "Invert", -1);
  1276. X    wmenuadditem(mp, "Transpose major", -1);
  1277. X    wmenuadditem(mp, "Transpose minor", -1);
  1278. X    wmenuadditem(mp, "Rotate left", -1);
  1279. X    wmenuadditem(mp, "Rotate right", -1);
  1280. X    wmenuadditem(mp, "Flip horizontal", -1);
  1281. X    wmenuadditem(mp, "Flip vertical", -1);
  1282. X    
  1283. X    win= wopen("faced", drawproc);
  1284. X    if (win == NULL) {
  1285. X        wmessage("Can't open window");
  1286. X        return;
  1287. X    }
  1288. X    wsetdocsize(win, COLS*xscale, ROWS*yscale);
  1289. X}
  1290. X
  1291. Xediting()
  1292. X{
  1293. X    int value= 0;
  1294. X    
  1295. X    for (;;) {
  1296. X        EVENT e;
  1297. X        
  1298. X        wgetevent(&e);
  1299. X        switch (e.type) {
  1300. X        case WE_MOUSE_DOWN:
  1301. X            value= !getbit(e.u.where.h/xscale, e.u.where.v/yscale);
  1302. X        case WE_MOUSE_MOVE:
  1303. X        case WE_MOUSE_UP:
  1304. X            setbit(e.u.where.h/xscale, e.u.where.v/yscale, value);
  1305. X            break;
  1306. X        case WE_COMMAND:
  1307. X            switch (e.u.command) {
  1308. X            case WC_CLOSE:
  1309. X                return;
  1310. X            case WC_CANCEL:
  1311. X                changed= 0;
  1312. X                return;
  1313. X            }
  1314. X        case WE_CLOSE:
  1315. X            return;
  1316. X        case WE_MENU:
  1317. X            switch (e.u.m.id) {
  1318. X            case MAIN_MENU:
  1319. X                switch (e.u.m.item) {
  1320. X                case QUIT_ITEM:
  1321. X                    return;
  1322. X                }
  1323. X                break;
  1324. X            case OP_MENU:
  1325. X                if (e.u.m.item >= 0 && e.u.m.item < NOPS) {
  1326. X                    (*oplist[e.u.m.item])();
  1327. X                    wchange(win, 0, 0,
  1328. X                        COLS*xscale, ROWS*yscale);
  1329. X                    changed= 1;
  1330. X                }
  1331. X                break;
  1332. X            }
  1333. X        }
  1334. X    }
  1335. X}
  1336. X
  1337. Xint
  1338. Xgetbit(col, row)
  1339. X{
  1340. X    if (row >= 0 && row < ROWS && col >= 0 && col < COLS)
  1341. X        return bit[row][col];
  1342. X    else
  1343. X        return 0;
  1344. X}
  1345. X
  1346. Xsetbit(col, row, value)
  1347. X{
  1348. X    if (row >= 0 && row < ROWS && col >= 0 && col < COLS &&
  1349. X            bit[row][col] != value) {
  1350. X        changed= 1;
  1351. X        bit[row][col]= value;
  1352. X        wchange(win, col*xscale, row*yscale,
  1353. X            (col+1)*xscale, (row+1)*yscale);
  1354. X    }
  1355. X}
  1356. X
  1357. Xdrawproc(win, left, top, right, bottom)
  1358. X    WINDOW *win;
  1359. X{
  1360. X    int row, col;
  1361. X    
  1362. X    if (left < 0)
  1363. X        left= 0;
  1364. X    if (right > COLS*xscale)
  1365. X        right= COLS*xscale;
  1366. X    if (top < 0)
  1367. X        top= 0;
  1368. X    if (bottom > ROWS*yscale)
  1369. X        bottom= ROWS*yscale;
  1370. X    
  1371. X    for (row= top/yscale; row*yscale < bottom; ++row) {
  1372. X        for (col= left/xscale; col*xscale < right; ++col) {
  1373. X            if (bit[row][col]) {
  1374. X                if (text_only)
  1375. X                    wdrawchar(col, row, 'x');
  1376. X                else
  1377. X                    wpaint(col*xscale, row*yscale,
  1378. X                        (col+1)*xscale, (row+1)*yscale);
  1379. X            }
  1380. X        }
  1381. X    }
  1382. X}
  1383. X
  1384. X
  1385. X/* File I/O routines */
  1386. X
  1387. Xinput(fp)
  1388. X    FILE *fp;
  1389. X{
  1390. X    int row;
  1391. X    
  1392. X    for (row= 0; row < ROWS; ++row) {
  1393. X        read_row(fp, row);
  1394. X    }
  1395. X}
  1396. X
  1397. Xread_row(fp, row)
  1398. X    FILE *fp;
  1399. X    int row;
  1400. X{
  1401. X    int left= 0;
  1402. X    long ibuf;
  1403. X    int col;
  1404. X    
  1405. X    for (col= 0; col < COLS; ++col) {
  1406. X        if (left <= 0) {
  1407. X            if (fscanf(fp, " 0x%4lx,", &ibuf) != 1) {
  1408. X                wdone();
  1409. X                fprintf(stderr,
  1410. X                    "Bad input format, row %d\n", row);
  1411. X                exit(1);
  1412. X            }
  1413. X            left= BITS;
  1414. X        }
  1415. X        --left;
  1416. X        bit[row][col]= (ibuf >> left) & 1;
  1417. X    }
  1418. X}
  1419. X
  1420. Xoutput(fp)
  1421. X    FILE *fp;
  1422. X{
  1423. X    int row;
  1424. X    
  1425. X    for (row= 0; row < ROWS; ++row)
  1426. X        write_row(fp, row);
  1427. X}
  1428. X
  1429. Xwrite_row(fp, row)
  1430. X    FILE *fp;
  1431. X    int row;
  1432. X{
  1433. X    int col;
  1434. X    int left= BITS;
  1435. X    long ibuf= 0;
  1436. X    
  1437. X    for (col= 0; col < COLS; ++col) {
  1438. X        if (left <= 0) {
  1439. X            fprintf(fp, "0x%04lX,", ibuf);
  1440. X            ibuf= 0;
  1441. X            left= BITS;
  1442. X        }
  1443. X        --left;
  1444. X        if (bit[row][col]) {
  1445. X            ibuf |= 1<<left;
  1446. X        }
  1447. X    }
  1448. X    if (left < BITS)
  1449. X        fprintf(fp, "0x%04lX,", ibuf);
  1450. X    fprintf(fp, "\n");
  1451. X}
  1452. X
  1453. X
  1454. X/* Data manipulation routines */
  1455. X
  1456. Xclear_bits()
  1457. X{
  1458. X    int row, col;
  1459. X    
  1460. X    for (row= 0; row < ROWS; ++row)
  1461. X        for (col= 0; col < COLS; ++col)
  1462. X            bit[row][col]= 0;
  1463. X}
  1464. X
  1465. Xset_bits()
  1466. X{
  1467. X    int row, col;
  1468. X    
  1469. X    for (row= 0; row < ROWS; ++row)
  1470. X        for (col= 0; col < COLS; ++col)
  1471. X            bit[row][col]= 1;
  1472. X}
  1473. X
  1474. Xinvert_bits()
  1475. X{
  1476. X    int row, col;
  1477. X    
  1478. X    for (row= 0; row < ROWS; ++row)
  1479. X        for (col= 0; col < COLS; ++col)
  1480. X            bit[row][col]= !bit[row][col];
  1481. X}
  1482. X
  1483. Xtranspose_major()
  1484. X{
  1485. X    int row, col;
  1486. X    char tmp;
  1487. X    
  1488. X    for (row= 0; row < SIZE; ++row) {
  1489. X        for (col= 0; col < row; ++col) {
  1490. X            tmp= bit[row][col];
  1491. X            bit[row][col]= bit[col][row];
  1492. X            bit[col][row]= tmp;
  1493. X        }
  1494. X    }
  1495. X}
  1496. X
  1497. Xtranspose_minor()
  1498. X{
  1499. X    int row, col;
  1500. X    char tmp;
  1501. X    
  1502. X    for (row= 0; row < SIZE; ++row) {
  1503. X        for (col= 0; col < SIZE-1-row; ++col) {
  1504. X            tmp= bit[row][col];
  1505. X            bit[row][col]= bit[SIZE-1-col][SIZE-1-row];
  1506. X            bit[SIZE-1-col][SIZE-1-row]= tmp;
  1507. X        }
  1508. X    }
  1509. X}
  1510. X
  1511. Xrotate_left()
  1512. X{
  1513. X    int row, col;
  1514. X    char tmp;
  1515. X    
  1516. X    for (row= 0; row < SIZE/2; ++row) {
  1517. X        for (col= 0; col < SIZE/2; ++col) {
  1518. X            tmp= bit[row][col];
  1519. X            bit[row][col]= bit[col][SIZE-1-row];
  1520. X            bit[col][SIZE-1-row]= bit[SIZE-1-row][SIZE-1-col];
  1521. X            bit[SIZE-1-row][SIZE-1-col]= bit[SIZE-1-col][row];
  1522. X            bit[SIZE-1-col][row]= tmp;
  1523. X        }
  1524. X    }
  1525. X}
  1526. X
  1527. Xrotate_right()
  1528. X{
  1529. X    int row, col;
  1530. X    char tmp;
  1531. X    
  1532. X    for (row= 0; row < SIZE/2; ++row) {
  1533. X        for (col= 0; col < SIZE/2; ++col) {
  1534. X            tmp= bit[row][col];
  1535. X            bit[row][col]= bit[SIZE-1-col][row];
  1536. X            bit[SIZE-1-col][row]= bit[SIZE-1-row][SIZE-1-col];
  1537. X            bit[SIZE-1-row][SIZE-1-col]= bit[col][SIZE-1-row];
  1538. X            bit[col][SIZE-1-row]= tmp;
  1539. X        }
  1540. X    }
  1541. X}
  1542. X
  1543. Xflip_horizontal()
  1544. X{
  1545. X    int row, col;
  1546. X    char tmp;
  1547. X    
  1548. X    for (row= 0; row < ROWS; ++row) {
  1549. X        for (col= 0; col < COLS/2; ++col) {
  1550. X            tmp= bit[row][col];
  1551. X            bit[row][col]= bit[row][COLS-1-col];
  1552. X            bit[row][COLS-1-col]= tmp;
  1553. X        }
  1554. X    }
  1555. X}
  1556. X
  1557. Xflip_vertical()
  1558. X{
  1559. X    int row, col;
  1560. X    char tmp;
  1561. X    
  1562. X    for (row= 0; row < ROWS/2; ++row) {
  1563. X        for (col= 0; col < COLS; ++col) {
  1564. X            tmp= bit[row][col];
  1565. X            bit[row][col]= bit[ROWS-1-row][col];
  1566. X            bit[ROWS-1-row][col]= tmp;
  1567. X        }
  1568. X    }
  1569. X}
  1570. X
  1571. Xint (*oplist[])() = {
  1572. X    clear_bits,
  1573. X    set_bits,
  1574. X    invert_bits,
  1575. X    transpose_major,
  1576. X    transpose_minor,
  1577. X    rotate_left,
  1578. X    rotate_right,
  1579. X    flip_horizontal,
  1580. X    flip_vertical,
  1581. X};
  1582. END_OF_FILE
  1583. if test 7101 -ne `wc -c <'Appls/test/faced.c'`; then
  1584.     echo shar: \"'Appls/test/faced.c'\" unpacked with wrong size!
  1585. fi
  1586. # end of 'Appls/test/faced.c'
  1587. fi
  1588. if test -f 'Doc/man/textedit.man' -a "${1}" != "-c" ; then 
  1589.   echo shar: Will not clobber existing file \"'Doc/man/textedit.man'\"
  1590. else
  1591. echo shar: Extracting \"'Doc/man/textedit.man'\" \(6406 characters\)
  1592. sed "s/^X//" >'Doc/man/textedit.man' <<'END_OF_FILE'
  1593. X.TH TEXTEDIT 3
  1594. X.SH NAME
  1595. XTextedit \- text-editing package for STDWIN
  1596. X.SH SYNOPSIS
  1597. X.nf
  1598. X.ft C
  1599. X#include "stdwin.h"
  1600. X
  1601. XTEXTEDIT *tealloc(WINDOW *win, int left, int top, int width);
  1602. XTEXTEDIT *tecreate(WINDOW *win, int left, int top, int right, int bottom);
  1603. Xvoid tefree(TEXTEDIT *tp);
  1604. Xvoid tedestroy(TEXTEDIT *tp);
  1605. X
  1606. Xvoid tedraw(TEXTEDIT *tp);
  1607. Xvoid tedrawnew(TEXTEDIT *tp, int left, int top, int right, int bottom);
  1608. Xvoid temove(TEXTEDIT *tp, int left, int top, int width);
  1609. Xvoid temovenew(TEXTEDIT *tp, int left, int top, int right, int bottom);
  1610. X
  1611. Xvoid tesetfocus(TEXTEDIT *tp, int foc1, int foc2);
  1612. Xvoid tereplace(TEXTEDIT *tp, char *str);
  1613. Xvoid tesetbuf(TEXTEDIT *tp, char *buf, int buflen);
  1614. X
  1615. Xvoid tearrow(TEXTEDIT *tp, int code);
  1616. Xvoid tebackspace(TEXTEDIT *tp);
  1617. Xbool teclicknew(TEXTEDIT *tp, int h, int v, bool extend);
  1618. Xbool tedoubleclick(TEXTEDIT *tp, int h, int v);
  1619. Xbool teevent(TEXTEDIT *tp, EVENT *ep);
  1620. X
  1621. X#define teclick(tp, h, v) teclicknew(tp, h, v, FALSE)
  1622. X#define teclickextend(tp, h, v) teclicknew(tp, h, v, TRUE)
  1623. X
  1624. Xchar *tegettext(TEXTEDIT *tp);
  1625. Xint tegetlen(TEXTEDIT *tp);
  1626. Xint tegetnlines(TEXTEDIT *tp);
  1627. Xint tegetfoc1(TEXTEDIT *tp);
  1628. Xint tegetfoc2(TEXTEDIT *tp);
  1629. Xint tegetleft(TEXTEDIT *tp);
  1630. Xint tegettop(TEXTEDIT *tp);
  1631. Xint tegetright(TEXTEDIT *tp);
  1632. Xint tegetbottom(TEXTEDIT *tp);
  1633. X
  1634. Xint wdrawpar(int h, int v, char *text, int width);
  1635. Xint wparheight(char *text, int width);
  1636. X.ft 1
  1637. X.fi
  1638. X.SH DESCRIPTION
  1639. X.I Textedit
  1640. Xis the standard text-editing package for STDWIN.
  1641. XIt allows you to designate any part of a window as a ``text-editing''
  1642. Xarea, in which the user can see or edit arbitrary text.
  1643. XUntil I find the time and the mental rest to write a decent manual,
  1644. Xyou'll have to do with the example and hints on this man page.
  1645. X.PP
  1646. XA textedit area need not occupy an entire window, and there can be
  1647. Xmore than one textedit area in a given window.
  1648. XConsequently, textedit areas are not resized automatically when their
  1649. Xwindow is resized, and the document size is not set automatically when
  1650. Xthe textedit area's size changes.
  1651. XIf you want to use a single textedit area in a window, and want them to
  1652. Xbe coupled more tightly, use the
  1653. X.I editwin
  1654. Xpackage instead.
  1655. X.PP
  1656. XThe functions
  1657. X.I wdrawpar
  1658. Xand
  1659. X.I wparheight
  1660. Xdraw a paragraph of text exactly like the
  1661. X.I textedit
  1662. Xroutines would draw it, without the need to allocate a textedit data
  1663. Xstructure for it.
  1664. X.I Wdrawpar
  1665. Xreturns the ``v'' coordinate of the bottom of the paragraph drawn, and
  1666. X.I wparheight
  1667. Xreturns its height.
  1668. X.PP
  1669. XAvailable routines are:
  1670. X.IP tealloc
  1671. X.IP tecreate
  1672. X.IP tefree
  1673. X.IP tedestroy
  1674. X.IP tedraw
  1675. X.IP tedrawnew
  1676. X.IP temove
  1677. X.IP temovenew
  1678. X.IP tesetfocus
  1679. X.IP tereplace
  1680. X.IP tesetbuf
  1681. X.IP tearrow
  1682. X.IP tebackspace
  1683. X.IP teclicknew
  1684. X.IP tedoubleclick
  1685. X.IP teevent
  1686. X.IP teclick
  1687. X.IP teclickextend
  1688. X.IP tegettext
  1689. X.IP tegetlen
  1690. X.IP tegetnlines
  1691. X.IP tegetfoc1
  1692. X.IP tegetfoc2
  1693. X.IP tegetleft
  1694. X.IP tegettop
  1695. X.IP tegetright
  1696. X.IP tegetbottom
  1697. X.IP wdrawpar
  1698. X.IP wparheight
  1699. X.SH EXAMPLE
  1700. X.nf
  1701. X.ft C
  1702. X#include "stdwin.h"
  1703. X
  1704. XWINDOW *win;
  1705. XTEXTEDIT *tp;
  1706. X
  1707. Xvoid drawproc(win, left, top, right, bottom) WINDOW *win; {
  1708. X    tedrawnew(tp,left, top, right, bottom);
  1709. X}
  1710. X
  1711. Xmain() {
  1712. X    winit();
  1713. X    win= wopen("Hello world", &drawproc);
  1714. X    tp= tecreate(win, 20, 20, 200, 200);
  1715. X    tereplace(tp, "Guido is gek");
  1716. X    for (;;) {
  1717. X        EVENT e;
  1718. X        wgetevent(&e);
  1719. X        if (teevent(tp, &e)) continue; /* Event has been handled */
  1720. X        if (e.type == WE_COMMAND && e.u.command == WC_CLOSE) break;
  1721. X    }
  1722. X    wdone();
  1723. X    exit(0);
  1724. X}
  1725. X.ft 1
  1726. X.fi
  1727. X.SH HINTS
  1728. X.I Tedestroy
  1729. Xcalls
  1730. X.I wchange
  1731. Xfor the area occupied by the textedit area, and then calls
  1732. X.IR tefree ;
  1733. X.I tefree
  1734. Xgets rid of the data structures allocated for it.
  1735. X.PP
  1736. X.I Tesetbuf
  1737. X``gives the buffer away.''
  1738. XThat is, you should have allocated the buffer using
  1739. X.IR malloc (3),
  1740. Xbut you shouldn't call
  1741. X.I free
  1742. Xto get rid of it \- a pointer to the buffer is incorporated in the
  1743. Xtextedit data structures, and it will be freed later by
  1744. X.I tefree.
  1745. XDon't pass a buffer that wasn't allocated through
  1746. X.IR malloc (3)!
  1747. X.PP
  1748. X.I Tegettext
  1749. Xreturns a pointer to the internal buffer used to represent the text.
  1750. XSubsequent calls to textedit routines that modify the buffer may
  1751. Xinvalidate this pointer.
  1752. XYou shouldn't modify the text found there.
  1753. XTo get the text selected in the focus, copy the substring found between
  1754. Xpositions
  1755. X.I tegetfoc1
  1756. Xand
  1757. X.I tegetfoc2,
  1758. Xfor example:
  1759. X.nf
  1760. X.ft C
  1761. X/* Copy focus text into buffer, whose size is len */
  1762. Xgetfocus(tp, buf, len) TEXTEDIT *tp; char *buf; {
  1763. X    int f1= tegetfoc1(tp), f2= tegetfoc2(tp);
  1764. X    char *text= tegettext(tp);
  1765. X    if (f2-f1 < len) len= f2-f1+1;
  1766. X    strncpy(buf, len-1, text+f1);
  1767. X    buf[len-1]= '\0';
  1768. X}
  1769. X.ft 1
  1770. X.fi
  1771. X.SH DIAGNOSTICS
  1772. X.I Tealloc
  1773. Xand
  1774. X.I tecreate
  1775. Xreturn NULL when they could not get all the necessary memory.
  1776. XThe other routines may fail but there is no way to find out.
  1777. X.SH SEE ALSO
  1778. XSTDWIN documentation
  1779. X.br
  1780. Xeditwin(3)
  1781. X.SH AUTHOR
  1782. XGuido van Rossum
  1783. X.SH BUGS
  1784. XTextedit areas always grow and shrunk automaticatically at the bottom.
  1785. XTherefore,
  1786. X.I tecreate
  1787. Xignores the bottom coordinate.
  1788. X.br
  1789. XWhen a textedit area shrinks more than a line at a time, garbage may
  1790. Xremain on the screen between the old and the new bottom position.
  1791. X.br
  1792. XThe text attributes (font, size and style) in effect when any of the
  1793. Xtextedit routines are called must be those that were in effect when the
  1794. Xtextedit area was created.  (The routines should save and restore the
  1795. Xtext attributes, but currently they don't.)
  1796. X.br
  1797. XThe constants TRUE and FALSE used in the #include file are not defined
  1798. Xthere, even though the typedef bool is.
  1799. X.br
  1800. XBeware that the last argument to
  1801. X.I tealloc
  1802. Xand
  1803. X.I temove
  1804. Xis the width of the textedit area on the screen, not its right
  1805. Xcoordinate!
  1806. X.br
  1807. XIt is a pain that there are ``new'' and ``old'' versions of routines
  1808. Xlike tealloc, tedraw, temove and teclick.
  1809. XThe old routines should not be used any more, and the new ones should be
  1810. Xrenamed to the old names.
  1811. X.br
  1812. X.I Wdrawpar
  1813. Xand
  1814. X.I wparheight
  1815. Xare easy to use but not particularly efficient; they allocate a textedit
  1816. Xdata structure, call internal textedit routines to do the work, and then
  1817. Xdeallocate the data structure again.
  1818. X.br
  1819. XMissing functionality:
  1820. Xa way to affect the line breaking algorithm;
  1821. Xa way to display text centered or with justified margins;
  1822. Xa way to disable changes while still passing events (for selection, etc.);
  1823. Xmore keyboard editing functions (begin/end of line/file, etc.);
  1824. Xa way to suppress the automatic growing of the textedit area;
  1825. Xa way to specify a margin around the textedit area where mouse clicks
  1826. Xare still accepted by
  1827. X.I teevent.
  1828. END_OF_FILE
  1829. if test 6406 -ne `wc -c <'Doc/man/textedit.man'`; then
  1830.     echo shar: \"'Doc/man/textedit.man'\" unpacked with wrong size!
  1831. fi
  1832. # end of 'Doc/man/textedit.man'
  1833. fi
  1834. if test -f 'Doc/man/vt.man' -a "${1}" != "-c" ; then 
  1835.   echo shar: Will not clobber existing file \"'Doc/man/vt.man'\"
  1836. else
  1837. echo shar: Extracting \"'Doc/man/vt.man'\" \(7408 characters\)
  1838. sed "s/^X//" >'Doc/man/vt.man' <<'END_OF_FILE'
  1839. X.TH VT 3
  1840. X.SH NAME
  1841. XVT \- virtual terminal package for STDWIN
  1842. X.SH SYNOPSIS
  1843. X.nf
  1844. X.ft C
  1845. X#include "stdwin.h"
  1846. X#include "vt.h"
  1847. X
  1848. XVT *vtopen(char *title, int rows, int cols, int saverows);
  1849. Xvoid vtclose(VT *vt);
  1850. Xvoid vtansiputs(VT *vt, char *text, int len);
  1851. Xvoid vtsetcursor(VT *vt, int row, int col);
  1852. Xvoid vtreset(VT *vt);
  1853. Xbool vtresize(VT *vt, int rows, int cols, int saverows);
  1854. Xbool vtautosize(VT *vt);
  1855. XVT *vtfind(WINDOW *win);
  1856. Xvoid vtsend(VT *vt, char *text, int buf);
  1857. X.ft 1
  1858. X
  1859. X/* The following functions are actually macros */
  1860. X.ft C
  1861. XWINDOW *vtwindow(VT *vt);
  1862. Xint vtcwidth(VT *vt);
  1863. Xint vtcheight(VT *vt);
  1864. Xvoid vtsetnlcr(VT *vt, bool nlcr);
  1865. Xvoid vtsetlazy(VT *vt, bool lazy);
  1866. X.ft 1
  1867. X.fi
  1868. X.SH DESCRIPTION
  1869. X.I VT
  1870. Xis a package which emulates one or more virtual terminals in STDWIN
  1871. Xwindows.
  1872. XA VT structure contains a WINDOW pointer and data structures to save the
  1873. Xscreen contents, cursor position, etc.
  1874. XSuch a virtual terminal may be used to implement a terminal emulation
  1875. Xprogram on a micro-computer (which was the original goal of this
  1876. Xprogramming exercise), or as a tool to simplify interfacing a program
  1877. Xusing printf-style output to STDWIN.
  1878. XThe virtual terminal's cursor position is indicated by STDWIN's standard
  1879. Xtext caret, appearing to the left of the character at the cursor
  1880. Xposition.
  1881. XThis actually feels very natural in most cases.
  1882. X.PP
  1883. XThe functions you might want to know about are:
  1884. X.IP vtopen
  1885. XCreates the window and returns a pointer to a VT struct.
  1886. X.I Rows
  1887. Xand
  1888. X.I cols
  1889. Xspecify the size of the virtual terminal;
  1890. X.I saverows
  1891. Xspecifies the number of rows saved after they have scrolled off the top
  1892. Xof the terminal.
  1893. XIf something went wrong, a nil pointer is returned.
  1894. X.IP vtclose
  1895. XCloses the window and deallocates the data contained in the VT struct.
  1896. X.IP vtansiputs
  1897. XSends an output string to the virtual terminal.
  1898. X.I Len
  1899. Xspecifies the length of the string; if it is negative, the string is
  1900. Xterminated by a null character.
  1901. XControl character and escape sequence processing is done in the style of
  1902. XANSI terminals, with some limitations and extensions.
  1903. XWarning: unless
  1904. X.I "vtsetnlcr(vt, 1)"
  1905. Xhas been called, both a CR and LF character must be sent to properly
  1906. Xstart a new line.
  1907. X.IP vtsetcursor
  1908. XMoves the terminal's cursor to the indicated position.
  1909. XThe top left corner of the virtual terminal is position (0, 0).
  1910. X.IP vtreset
  1911. XCompletely resets the virtual terminal to its initial state.
  1912. XThe cursor is moved to position (0, 0).
  1913. XThe
  1914. X.I lazy
  1915. Xand
  1916. X.I nlcr
  1917. Xflags are not changed.
  1918. X.IP vtresize
  1919. XChanges the dimensions of the virtual terminal to explicitly given
  1920. Xnumbers.
  1921. XIn case of memory shortage, this function may fail irrecoverably,
  1922. Xleaving the VT struct in an unusable state (except to
  1923. X.IR vtclose ).
  1924. X.IP vtautosize
  1925. XChanges the dimensions of the virtual terminal to conform to the new
  1926. Xwindow size.
  1927. XIf possible, the sum of rows and saverows is kept constant.
  1928. XThe same limitations as for
  1929. X.I vtresize
  1930. Xapply.
  1931. X.IP vtfind
  1932. XGiven a window pointer, returns a pointer to the VT struct containing
  1933. Xthat window.
  1934. XReturns a nil pointer if no such VT struct exists.
  1935. X.IP vtsend
  1936. XThis function is defined in the library, but you might want to write
  1937. Xyour own version.
  1938. XIt is called by the library for cases where the virtual terminal must
  1939. Xsend a reply back to the computer system.
  1940. X(This happens in response to certain ANSI escape sequences, in
  1941. Xparticular ESC-[-6-n or ESC-[-c.)
  1942. XYou may want to ignore this output, or actually send it down a serial
  1943. Xline if you are implementing a terminal emulator program for a
  1944. Xmicro-computer.
  1945. XThe library's default version calls
  1946. X.I vtansiputs
  1947. Xwith the same parameters as passed to
  1948. X.I vtsend.
  1949. X.IP vtwindow
  1950. XReturns a pointer to the window contained in the VT struct.
  1951. X.IP vtcwidth
  1952. XReturns the width of characters drawn in the VT's window.
  1953. X.IP vtcheight
  1954. XReturns the height of characters drawn in the VT's window.
  1955. X.IP vtsetnlcr
  1956. XTurns the
  1957. X.I nlcr
  1958. Xoption on or off.
  1959. XWhen on, every LF character received is translated into a CR plus LF.
  1960. XThis is useful if you want to perform C style output to a VT window,
  1961. Xwhere lines are terminated by a single LF.
  1962. XInitially this option is off.
  1963. X.IP vtsetlazy
  1964. XTurns the
  1965. X.I lazy
  1966. Xoption on or off.
  1967. XWhen on, actual output to the terminal is delayed until the window's
  1968. Xdraw procedure is called; when off, all output is drawn immediately.
  1969. XInitially this option is off.
  1970. X.SH ANSI ESCAPE SEQUENCES
  1971. XThe termcap entries for xterm, vt100, vt100em and versaterm would all
  1972. Xwork with the emulated terminal (if you could somehow translate the
  1973. Xoutput intended for a Unix terminal into calls to
  1974. X.IR vtansiputs ).
  1975. XUnrecognized escape sequences and control characters are ignored.
  1976. X.PP
  1977. X*** List all implemented escape sequences here. ***
  1978. X.SH EXAMPLE
  1979. X.nf
  1980. X.ft C
  1981. X#include "stdwin.h"
  1982. X#include "vt.h"
  1983. X
  1984. Xmain() {
  1985. X    VT *vt;
  1986. X    winit();
  1987. X    wsetdefwinsize(80*wcharwidth('0'), 24*wlineheight());
  1988. X    vt= vtopen("VT", 24, 80, 100); /* Should check outcome */
  1989. X    vtautosize(vt);
  1990. X    vtsetnlcr(vt, 1); /* Map LF to CR LF */
  1991. X    vtansiputs(vt, "Hello, world\en", -1);
  1992. X    eventloop();
  1993. X    wdone();
  1994. X    exit(0);
  1995. X}
  1996. X
  1997. Xeventloop(vt) VT *vt; {
  1998. X    for (;;) {
  1999. X        EVENT e;
  2000. X        wgetevent(&e);
  2001. X        switch (e.type) {
  2002. X        case WE_SIZE:
  2003. X            vtautosize(vt); /* Should check outcome */
  2004. X            break;
  2005. X        case WE_CHAR:
  2006. X            { char buf[2];
  2007. X              buf[0]= e.u.character;
  2008. X              vtansiputs(vt, buf, 1);
  2009. X              break; }
  2010. X        case WE_MOUSE_DOWN:
  2011. X            vtsetcursor(vt,
  2012. X                        e.u.where.v / vtcheight(vt),
  2013. X                        e.u.where.h / vtcwidth(vt));
  2014. X            break;
  2015. X        case WE_COMMAND:
  2016. X            switch (e.u.command) {
  2017. X            case WC_CLOSE:                              return;
  2018. X            case WC_RETURN: vtansiputs(vt, "\en", 1);    break;
  2019. X            case WC_BACKSPACE: vtansiputs(vt, "\eb", 1); break;
  2020. X            case WC_TAB: vtansiputs(vt, "\et", 1);       break;
  2021. X            }
  2022. X            break;
  2023. X        }
  2024. X    }
  2025. X}
  2026. X.ft 1
  2027. X.fi
  2028. X.SH DIAGNOSTICS
  2029. X.I Vtopen
  2030. Xreturns a nil pointer if it can't allocate all the required memory or if
  2031. Xthe call to
  2032. X.I wopen
  2033. Xit makes fails.
  2034. X.br
  2035. X.I Vtresize
  2036. Xand
  2037. X.I vtautosize
  2038. Xreturn false (zero) if they can't allocate the extra memory required;
  2039. Xin this case the VT struct has been damaged beyond repair.
  2040. X.SH SEE ALSO
  2041. XSTDWIN documentation
  2042. X.SH AUTHOR
  2043. XGuido van Rossum
  2044. X.SH BUGS
  2045. XIn some versions of STDWIN, the scroll bars won't appear and some other
  2046. Xfunctionality won't be available unless the program calls
  2047. X.I wgetevent.
  2048. X.br
  2049. XUnless the application calls
  2050. X.I vtautosize
  2051. Xat all the right moments, it is quite possible that the window size
  2052. Xdoesn't match the size of the virtual terminal.
  2053. XWhen the window is too small, STDWIN's automatic scrolling will cause
  2054. Xthe text to jump around; when it is too large, portions of the
  2055. Xscrolled-away text will remain visible but unreachable by the cursor.
  2056. X.br
  2057. XThe ANSI terminal implementation is incomplete.
  2058. XIt certainly isn't a full-fledged VT100.
  2059. X.br
  2060. XThe behaviour of the cursor at the right margin is slightly
  2061. Xunconventional.
  2062. X.br
  2063. XBold output only works on the Macintosh, and requires that a font called
  2064. X``Bold'' (9 points) be available in the system file.  This font can be
  2065. Xfound in the resources for (some versions of) VersaTerm(TM).
  2066. X.br
  2067. XThe package makes the assumption that all characters have the same
  2068. Xwidth.
  2069. X.br
  2070. XThe order of parameters indicating rows and columns is internally
  2071. Xconsistent, but reversed with respect to order used for h and v
  2072. Xcoordinates in the rest of STDWIN.
  2073. X.br
  2074. XThe origin of cursor coordinates passed to
  2075. X.I vtsetcursor
  2076. Xis (0, 0), even though the origin used by ANSI escape sequences is
  2077. X(1, 1).
  2078. X.br
  2079. XThe header file defines functions that aren't really part of the public
  2080. Xinterface.
  2081. END_OF_FILE
  2082. if test 7408 -ne `wc -c <'Doc/man/vt.man'`; then
  2083.     echo shar: \"'Doc/man/vt.man'\" unpacked with wrong size!
  2084. fi
  2085. # end of 'Doc/man/vt.man'
  2086. fi
  2087. if test -f 'Ports/alfa/bind.c' -a "${1}" != "-c" ; then 
  2088.   echo shar: Will not clobber existing file \"'Ports/alfa/bind.c'\"
  2089. else
  2090. echo shar: Extracting \"'Ports/alfa/bind.c'\" \(7177 characters\)
  2091. sed "s/^X//" >'Ports/alfa/bind.c' <<'END_OF_FILE'
  2092. X/* TERMCAP STDWIN -- KEY BINDING. */
  2093. X
  2094. X/* Separated from the default tables; the application may override
  2095. X   the tables but not the executable code. */
  2096. X
  2097. X#ifdef SYSV
  2098. X#define TERMIO
  2099. X#endif
  2100. X
  2101. X#ifdef unix
  2102. X#ifndef TERMIO
  2103. X#define DO_SGTTY
  2104. X#endif
  2105. X#define DO_TERMCAP
  2106. X#endif
  2107. X
  2108. X#include "alfa.h"
  2109. X
  2110. X#ifdef DO_SGTTY
  2111. X#include <sgtty.h>
  2112. X#endif
  2113. X#ifdef TERMIO
  2114. X#include <termio.h>
  2115. X#endif
  2116. X
  2117. X#ifdef DO_TERMCAP
  2118. X/* Termcap functions: */
  2119. Xchar *tgetstr();
  2120. Xint tgetnum();
  2121. Xbool tgetflag();
  2122. X#endif /* DO_TERMCAP */
  2123. X
  2124. Xstatic void charbinding(), tcbinding(), setbinding();
  2125. X
  2126. X/* Get key definitions from tty settings. */
  2127. X
  2128. Xvoid
  2129. Xgetttykeydefs(fd)
  2130. X    int fd;
  2131. X{
  2132. X#ifdef unix
  2133. X#ifdef DO_SGTTY
  2134. X    struct sgttyb gttybuf;
  2135. X    struct tchars tcharbuf;
  2136. X#endif
  2137. X#ifdef TERMIO
  2138. X    struct termio tio;
  2139. X#endif
  2140. X
  2141. X    copydefaults();
  2142. X    
  2143. X#ifdef DO_SGTTY
  2144. X    gtty(fd, >tybuf);
  2145. X    charbinding(SHORTCUT, 0, FIRST_CMD+WC_BACKSPACE,(int)gttybuf.sg_erase);
  2146. X    
  2147. X    ioctl(fd, TIOCGETC, (char *) &tcharbuf);
  2148. X    charbinding(SHORTCUT, 0, FIRST_CMD+WC_CANCEL, (int)tcharbuf.t_intrc);
  2149. X#endif
  2150. X#ifdef TERMIO
  2151. X    ioctl(fd, TCGETA, &tio);
  2152. X    charbinding(SHORTCUT, 0, FIRST_CMD+WC_BACKSPACE, (int)tio.c_cc[2]);
  2153. X    charbinding(SHORTCUT, 0, FIRST_CMD+WC_CANCEL, (int)tio.c_cc[0]);
  2154. X#endif
  2155. X
  2156. X#ifdef TIOCGLTC
  2157. X    {
  2158. X        struct ltchars ltcharbuf;
  2159. X        
  2160. X        ioctl(fd, TIOCGLTC, (char *) <charbuf);
  2161. X        charbinding(SHORTCUT, 0, SUSPEND_PROC, ltcharbuf.t_suspc);
  2162. X        charbinding(SHORTCUT, 0, REDRAW_SCREEN, ltcharbuf.t_rprntc);
  2163. X        charbinding(SHORTCUT, 0, LITERAL_NEXT, ltcharbuf.t_lnextc);
  2164. X    }
  2165. X#endif /* TIOCGLTC */
  2166. X#endif /* unix */
  2167. X}
  2168. X
  2169. X#ifdef unix
  2170. Xstatic void
  2171. Xcharbinding(type, id, item, key)
  2172. X    int type;
  2173. X    int id, item;
  2174. X    int key;
  2175. X{
  2176. X    if (key != 0 && (key&0xff) != 0xff) {
  2177. X        char keys[2];
  2178. X        keys[0]= key;
  2179. X        keys[1]= EOS;
  2180. X        setbinding(&_wprimap[*keys & 0xff], type, id, item, keys);
  2181. X    }
  2182. X}
  2183. X#endif /* unix */
  2184. X
  2185. X/* Get key definitions from termcap. */
  2186. X
  2187. Xvoid
  2188. Xgettckeydefs()
  2189. X{
  2190. X#ifdef DO_TERMCAP
  2191. X    copydefaults();
  2192. X    tcbinding(SHORTCUT, 0, FIRST_CMD+WC_BACKSPACE,    "kb");
  2193. X    tcbinding(SHORTCUT, 0, FIRST_CMD+WC_LEFT,    "kl");
  2194. X    tcbinding(SHORTCUT, 0, FIRST_CMD+WC_RIGHT,    "kr");
  2195. X    tcbinding(SHORTCUT, 0, FIRST_CMD+WC_UP,        "ku");
  2196. X    tcbinding(SHORTCUT, 0, FIRST_CMD+WC_DOWN,    "kd");
  2197. X    /*
  2198. X    tcbinding(SHORTCUT, 0, FIRST_CMD+WC_CLEAR,    "kC");
  2199. X    tcbinding(SHORTCUT, 0, FIRST_CMD+WC_HOME,    "kh");
  2200. X    tcbinding(SHORTCUT, 0, FIRST_CMD+WC_HOME_DOWN,    "kH");
  2201. X    */
  2202. X#endif /* DO_TERMCAP */
  2203. X}
  2204. X
  2205. X#ifdef DO_TERMCAP
  2206. Xstatic void
  2207. Xtcbinding(type, id, item, capname)
  2208. X    int type;
  2209. X    int id, item;
  2210. X    char capname[2];    /* Termcap capability name, e.g. "k1" */
  2211. X{
  2212. X    char buf[100];
  2213. X    char *p= buf;
  2214. X    char *keys;
  2215. X    
  2216. X    keys= tgetstr(capname, &p);
  2217. X    if (keys != NULL)
  2218. X        setbinding(&_wprimap[*keys & 0xff], type, id, item, keys);
  2219. X}
  2220. X#endif /* DO_TERMCAP */
  2221. X
  2222. X/* Bind a menu item to a meta-key.
  2223. X   As there are no meta-keys on standard Unix,
  2224. X   this is translated to ESC-key. */
  2225. X
  2226. Xvoid
  2227. Xwsetmetakey(id, item, key)
  2228. X    int id, item;
  2229. X    int key;
  2230. X{
  2231. X    char buf[3];
  2232. X    
  2233. X    buf[0]= '\033'; /* ESC */
  2234. X    buf[1]= key;
  2235. X    buf[2]= EOS;
  2236. X    wsetshortcut(id, item, buf);
  2237. X}
  2238. X
  2239. X/* Bind a menu item to a key sequence.
  2240. X   Note that this call is not part of the universal STDWIN interface,
  2241. X   only of the Unix interface for ASCII terminals. */
  2242. X
  2243. Xvoid
  2244. Xwsetshortcut(id, item, keys)
  2245. X    int id, item;
  2246. X    char *keys;
  2247. X{
  2248. X    if (keys == NULL || *keys == EOS)
  2249. X        return; /* Can't bind empty string */
  2250. X    copydefaults();
  2251. X    setbinding(&_wprimap[*keys & 0xff], SHORTCUT, id, item, keys);
  2252. X}
  2253. X
  2254. Xstatic struct keymap *extendmap();
  2255. X
  2256. Xstatic int
  2257. Xmapsize(map)
  2258. X    struct keymap *map;
  2259. X{
  2260. X    int size;
  2261. X    
  2262. X    if (map == NULL)
  2263. X        return 0;
  2264. X    for (size= 0; map[size].type != SENTINEL; ++size)
  2265. X        ;
  2266. X    return size+1;
  2267. X}
  2268. X
  2269. Xstatic void
  2270. Xsetbinding(map, type, id, item, keys)
  2271. X    struct keymap *map;
  2272. X    int type;
  2273. X    int id, item;
  2274. X    char *keys;
  2275. X{
  2276. X    if (keys[1] == EOS) {
  2277. X        map->key= *keys;
  2278. X        map->type= type;
  2279. X        map->id= id;
  2280. X        map->item= item;
  2281. X    }
  2282. X    else {
  2283. X        struct keymap *nmap;
  2284. X        if (map->type != SECONDARY) {
  2285. X            map->type= SECONDARY;
  2286. X            map->id= createmap();
  2287. X        }
  2288. X        for (nmap= _wsecmap[map->id];
  2289. X            nmap->type != SENTINEL; ++nmap) {
  2290. X            if (nmap->key == keys[1])
  2291. X                break;
  2292. X        }
  2293. X        if (nmap->type == SENTINEL)
  2294. X            nmap= extendmap((int) map->id, (int) keys[1]);
  2295. X        if (nmap != NULL)
  2296. X            setbinding(nmap, type, id, item, keys+1);
  2297. X    }
  2298. X}
  2299. X
  2300. Xstatic struct keymap *
  2301. Xextendmap(imap, c)
  2302. X    int imap;
  2303. X    int c;
  2304. X{
  2305. X    L_DECLARE(size, map, struct keymap);
  2306. X    
  2307. X    if (imap == 0 || imap >= SECMAPSIZE || (map= _wsecmap[imap]) == NULL)
  2308. X        return NULL;
  2309. X    size= mapsize(map);
  2310. X    L_EXTEND(size, map, struct keymap, 1);
  2311. X    _wsecmap[imap]= map;
  2312. X    if (map == NULL)
  2313. X        return NULL;
  2314. X    map += size - 2;
  2315. X    map->type= ORDINARY;
  2316. X    map->key= c;
  2317. X    map[1].type= SENTINEL;
  2318. X    return map;
  2319. X}
  2320. X
  2321. Xstatic int
  2322. Xcreatemap()
  2323. X{
  2324. X    L_DECLARE(size, map, struct keymap);
  2325. X    int i;
  2326. X    
  2327. X    L_EXTEND(size, map, struct keymap, 1);
  2328. X    if (map == NULL)
  2329. X        return 0;
  2330. X    map->type= SENTINEL;
  2331. X    for (i= 0; i < SECMAPSIZE && _wsecmap[i] != NULL; ++i)
  2332. X        ;
  2333. X    if (i >= SECMAPSIZE) { /* Overflow of _wsecmap array */
  2334. X        L_DEALLOC(size, map);
  2335. X        return 0;
  2336. X    }
  2337. X    else {
  2338. X        _wsecmap[i]= map;
  2339. X        return i;
  2340. X    }
  2341. X}
  2342. X
  2343. X/* Copy existing secondary key maps to dynamic memory.
  2344. X   Note: don't copy map 0, which is a dummy to force a dead-end street. */
  2345. X
  2346. Xstatic
  2347. Xcopydefaults()
  2348. X{
  2349. X    static bool been_here= FALSE;
  2350. X    int i;
  2351. X    struct keymap *map;
  2352. X    
  2353. X    if (been_here)
  2354. X        return;
  2355. X    been_here= TRUE;
  2356. X    
  2357. X    for (i= 1; i < SECMAPSIZE; ++i) {
  2358. X        map= _wsecmap[i];
  2359. X        if (map != NULL) {
  2360. X            int size= mapsize(map);
  2361. X            struct keymap *nmap;
  2362. X            int k;
  2363. X            nmap= (struct keymap *) malloc(
  2364. X                (unsigned) (size * sizeof(struct keymap)));
  2365. X            if (nmap != NULL) {
  2366. X                for (k= 0; k < size; ++k)
  2367. X                    nmap[k]= map[k];
  2368. X            }
  2369. X            _wsecmap[i]= nmap;
  2370. X        }
  2371. X    }
  2372. X}
  2373. X
  2374. X/* Routines to get a nice description of a menu item's shortcuts.
  2375. X   TO DO: protect against buffer overflow; cache output so it
  2376. X   isn't called so often (i.e., twice for each drawitem call!). */
  2377. X
  2378. Xstatic char *
  2379. Xcharrepr(c)
  2380. X    int c;
  2381. X{
  2382. X    static char repr[10];
  2383. X
  2384. X    switch (c) {
  2385. X
  2386. X    case 033:
  2387. X        return "ESC";
  2388. X    
  2389. X    case '\r':
  2390. X        return "CR";
  2391. X    
  2392. X    case '\b':
  2393. X        return "BS";
  2394. X    
  2395. X    case '\t':
  2396. X        return "TAB";
  2397. X    
  2398. X    case 0177:
  2399. X        return "DEL";
  2400. X
  2401. X    default:
  2402. X        if (c < ' ') {
  2403. X            repr[0]= '^';
  2404. X            repr[1]= c|'@';
  2405. X            repr[2]= '\0';
  2406. X        }
  2407. X        else if (c < 0177) {
  2408. X            repr[0]= c;
  2409. X            repr[1]= '\0';
  2410. X        }
  2411. X        else {
  2412. X            repr[0]= '\\';
  2413. X            repr[1]= '0' + (c>>6);
  2414. X            repr[2]= '0' + ((c>>3) & 07);
  2415. X            repr[3]= '0' + (c & 07);
  2416. X            repr[4]= '\0';
  2417. X        }
  2418. X        return repr;
  2419. X
  2420. X    }
  2421. X}
  2422. X
  2423. Xstatic char *
  2424. Xaddrepr(cp, c)
  2425. X    char *cp;
  2426. X    int c;
  2427. X{
  2428. X    char *rp= charrepr(c);
  2429. X    
  2430. X    while (*rp != '\0')
  2431. X        *cp++ = *rp++;
  2432. X    return cp;
  2433. X}
  2434. X
  2435. Xstatic char *
  2436. Xfollowmap(cp, map, id, item, stack, level)
  2437. X    char *cp;
  2438. X    struct keymap *map;
  2439. X    int id, item;
  2440. X    unsigned char *stack;
  2441. X    int level;
  2442. X{
  2443. X    if (map->type == SHORTCUT) {
  2444. X        if (map->id == id && map->item == item) {
  2445. X            int i;
  2446. X            for (i= 0; i < level; ++i) {
  2447. X                cp= addrepr(cp, (int) stack[i]);
  2448. X                *cp++ = '-';
  2449. X            }
  2450. X            cp= addrepr(cp, (int) map->key);
  2451. X            *cp++ = ',';
  2452. X            *cp++ = ' ';
  2453. X        }
  2454. X    }
  2455. X    else if (map->type == SECONDARY) {
  2456. X        stack[level]= map->key;
  2457. X        map= _wsecmap[map->id];
  2458. X        for (; map->type != SENTINEL; ++map)
  2459. X            cp= followmap(cp, map, id, item, stack, level+1);
  2460. X    }
  2461. X    return cp;
  2462. X}
  2463. X
  2464. Xvoid
  2465. Xgetbindings(buf, id, item)
  2466. X    char *buf;
  2467. X    int id;
  2468. X    int item;
  2469. X{
  2470. X    char *cp= buf;
  2471. X    unsigned char stack[50];
  2472. X    struct keymap *map;
  2473. X    
  2474. X    for (map= _wprimap; map < &_wprimap[256]; ++map)
  2475. X        cp= followmap(cp, map, id, item, stack, 0);
  2476. X    if (cp > buf)
  2477. X        cp -= 2;
  2478. X    *cp= EOS;
  2479. X}
  2480. END_OF_FILE
  2481. if test 7177 -ne `wc -c <'Ports/alfa/bind.c'`; then
  2482.     echo shar: \"'Ports/alfa/bind.c'\" unpacked with wrong size!
  2483. fi
  2484. # end of 'Ports/alfa/bind.c'
  2485. fi
  2486. echo shar: End of archive 12 \(of 19\).
  2487. cp /dev/null ark12isdone
  2488. MISSING=""
  2489. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
  2490.     if test ! -f ark${I}isdone ; then
  2491.     MISSING="${MISSING} ${I}"
  2492.     fi
  2493. done
  2494. if test "${MISSING}" = "" ; then
  2495.     echo You have unpacked all 19 archives.
  2496.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2497. else
  2498.     echo You still need to unpack the following archives:
  2499.     echo "        " ${MISSING}
  2500. fi
  2501. ##  End of shell archive.
  2502. exit 0
  2503.