home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume17 / mgr / part20 < prev    next >
Text File  |  1989-01-19  |  52KB  |  1,993 lines

  1. Subject:  v17i021:  MGR, Bellcore window manager, Part21/61
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4.  
  5. Submitted-by: Stephen A. Uhler <sau@bellcore.com>
  6. Posting-number: Volume 17, Issue 21
  7. Archive-name: mgr/part21
  8.  
  9.  
  10.  
  11.  
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 20 (of 61)."
  19. # Contents:  demo/misc/Makefile demo/misc/clock2.c src/blit/bitmap.c
  20. #   src/blit/line.C src/blit/sym.c src/destroy.c src/font_subs.c
  21. #   src/oblit/bitmap.c src/print.c src/win_make.c
  22. # Wrapped by rsalz@papaya.bbn.com on Thu Nov 17 21:05:23 1988
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'demo/misc/Makefile' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'demo/misc/Makefile'\"
  26. else
  27. echo shar: Extracting \"'demo/misc/Makefile'\" \(4414 characters\)
  28. sed "s/^X//" >'demo/misc/Makefile' <<'END_OF_FILE'
  29. X#                        Copyright (c) 1987 Bellcore
  30. X#                            All Rights Reserved
  31. X#       Permission is granted to copy or use this program, EXCEPT that it
  32. X#       may not be sold for profit, the copyright notice must be reproduced
  33. X#       on copies, and credit should be given to Bellcore where it is due.
  34. X#       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  35. X
  36. X#    $Header: Makefile,v 4.5 88/08/22 10:30:44 sau Exp $
  37. X#    $Source: /tmp/mgrsrc/demo/misc/RCS/Makefile,v $
  38. X
  39. X# makefile for demos 
  40. X
  41. XLIB= ../../lib/libmgr.a
  42. XBIT= ../../lib/blitlib.a
  43. XINCL= -I../../lib
  44. XCPIO=demo.cpio
  45. XTAR = demo.tar
  46. XCFLAGS=-O $(INCL)
  47. XLDFLAGS=$(LIB)
  48. XSTART=.
  49. XCPIO=misc.cpio
  50. XINSROOT=/usr/mgr
  51. XINSDIR=$(INSROOT)/bin
  52. X
  53. XCFILES= art_data.c bounce.c clock.c clock2.c close.c \
  54. X    dmgr.c ether.c getpty.c grav.c grid.c hilbert.c hpmgr.c maze.c \
  55. X    mgrmail.c mgrmode.c mgrmsgs.c oclose.c omgrmail.c overlayd.c \
  56. X    set_console.c set_emacs.c set_termcap.c show.c startup.c \
  57. X    stat.c stringart.c  lock.c
  58. X
  59. XOFILES= art_data.o bounce.o clock.o clock2.o close.o \
  60. X    dmgr.o ether.o getpty.o grav.o grid.o hilbert.o hpmgr.o maze.o \
  61. X    mgrmail.o mgrmode.o mgrmsgs.o oclose.o omgrmail.o overlayd.o \
  62. X    set_console.o set_emacs.o set_termcap.o show.o startup.o \
  63. X    stat.o stringart.o lock.o
  64. X
  65. XSMALL=    bounce clock clock2 close dmgr ether grav grid hilbert \
  66. X    hpmgr maze mgrmail mgrmode mgrmsgs oclose omgrmail \
  67. X    set_emacs set_termcap show startup stat stringart 
  68. X
  69. XALL = $(SMALL) overlayd set_console lock
  70. X
  71. XOTHER = Makefile
  72. X
  73. Xall:        $(ALL)
  74. X
  75. Xsmall:        $(SMALL)
  76. X
  77. Xfast:
  78. X        cc -c $(CFLAGS) $(CFILES)
  79. X        make all
  80. X
  81. Xbanner:        banner.o $(LIB)
  82. X        cc $(CFLAGS) -o banner banner.o $(LDFLAGS)
  83. X
  84. Xclock:        clock.o $(LIB)
  85. X        cc $(CFLAGS) -o clock clock.o $(LDFLAGS)
  86. X
  87. Xclock2:        clock2.o $(LIB)
  88. X        cc $(CFLAGS) -o clock2 clock2.o $(LDFLAGS)
  89. X
  90. Xbounce:        bounce.o $(LIB)
  91. X        cc $(CFLAGS) -o bounce bounce.o $(LDFLAGS)
  92. X
  93. Xdmgr:        dmgr.o $(LIB)
  94. X        cc $(CFLAGS) -o dmgr dmgr.o $(LDFLAGS)
  95. X
  96. Xgrav:        grav.o $(LIB)
  97. X        cc $(CFLAGS) -o grav grav.o $(LDFLAGS)
  98. X
  99. Xhpmgr:        hpmgr.o getpty.o $(LIB)
  100. X        cc $(CFLAGS) -o hpmgr hpmgr.o getpty.o $(LDFLAGS)
  101. X
  102. Xmgrmsgs:    mgrmsgs.o $(LIB)
  103. X        cc $(CFLAGS) -o mgrmsgs mgrmsgs.o $(LDFLAGS)
  104. X
  105. Xomgrmail:    omgrmail.o $(LIB)
  106. X        cc $(CFLAGS) -o omgrmail omgrmail.o $(LDFLAGS)
  107. X
  108. Xmgrmail:    mgrmail.o $(LIB)
  109. X        cc $(CFLAGS) -o mgrmail mgrmail.o $(LDFLAGS)
  110. X
  111. Xchart:        chart.o $(LIB)
  112. X        cc $(CFLAGS) -o chart chart.o $(LDFLAGS)
  113. X
  114. Xclose:        close.o $(LIB)
  115. X        cc $(CFLAGS) -o close close.o $(LDFLAGS)
  116. X
  117. Xoclose:        oclose.o $(LIB)
  118. X        cc $(CFLAGS) -o oclose oclose.o $(LDFLAGS)
  119. X
  120. Xclose3:        close3.o $(LIB)
  121. X        cc $(CFLAGS) -o close3 close3.o $(LDFLAGS)
  122. X
  123. Xstringart:    stringart.o art_data.o $(LIB)
  124. X        cc $(CFLAGS) -o stringart stringart.o art_data.o $(LDFLAGS)
  125. X
  126. Xstat:        stat.o $(LIB)
  127. X        cc $(CFLAGS) -o stat stat.o $(LDFLAGS)
  128. X
  129. Xether:        ether.o $(LIB)
  130. X        cc $(CFLAGS) -o ether ether.o $(LDFLAGS)
  131. X
  132. Xset_console:    set_console.o $(LIB)
  133. X        cc $(CFLAGS) -o set_console set_console.o $(LDFLAGS)
  134. X
  135. Xset_emacs:    set_emacs.o $(LIB)
  136. X        cc $(CFLAGS) -o set_emacs set_emacs.o $(LDFLAGS)
  137. X
  138. Xset_termcap:    set_termcap.o $(LIB)
  139. X        cc $(CFLAGS) -o set_termcap set_termcap.o $(LDFLAGS)
  140. X
  141. Xmgrmode:    mgrmode.o $(LIB)
  142. X        cc $(CFLAGS) -o mgrmode mgrmode.o $(LDFLAGS)
  143. X
  144. Xshow:        show.o $(LIB)
  145. X        cc $(CFLAGS) -o show show.o $(LDFLAGS)
  146. X
  147. Xstartup:    startup.o $(LIB)
  148. X        cc $(CFLAGS) -o startup startup.o $(LDFLAGS)
  149. X
  150. Xhilbert:    hilbert.o $(LIB)
  151. X        cc $(CFLAGS) -o hilbert hilbert.o $(LDFLAGS)
  152. X
  153. Xoverlayd:    overlayd.o $(LIB)
  154. X        cc $(CFLAGS) -o overlayd overlayd.o $(LDFLAGS)
  155. X
  156. Xgrid:        grid.o $(LIB)
  157. X        cc $(CFLAGS) -o grid grid.o $(LDFLAGS)
  158. X
  159. Xview:        view.o $(LIB)
  160. X        cc $(CFLAGS) -o view view.o $(LDFLAGS)
  161. X
  162. Xfile:        file.o $(LIB)
  163. X        cc $(CFLAGS) -o file file.o $(LDFLAGS)
  164. X
  165. Xprint:        print.o $(LIB)
  166. X        cc $(CFLAGS) -o print print.o $(LDFLAGS)
  167. X
  168. Xwprint:        wprint.o $(LIB)
  169. X        cc $(CFLAGS) -o wprint wprint.o $(LDFLAGS)
  170. X
  171. Xlock:        lock.o $(LIB)
  172. X        cc $(CFLAGS) -o lock lock.o $(BIT) $(OTHERLIB)
  173. X
  174. Xmaze:        maze.o $(LIB)
  175. X        cc $(CFLAGS) -o maze maze.o $(LDFLAGS)
  176. X
  177. X$(OFILES):    ../../lib/term.h $(LIB)
  178. X
  179. Xinstall:    all $(INSDIR)
  180. X        cd $(INSDIR);  rm -f $(ALL)
  181. X        cp $(ALL) $(INSDIR)
  182. X
  183. Xsmallinstall:    small $(INSDIR)
  184. X        cd $(INSDIR);  rm -f $(SMALL)
  185. X        cp $(SMALL) $(INSDIR)
  186. X        -/etc/chown root $(INSDIR)/maze  &&  chmod u+s $(INSDIR)/maze
  187. X
  188. X$(INSDIR):
  189. X    mkdir $@
  190. X
  191. Xtar:           
  192. X        tar cf $(TAR) `ls $(CFILES) $(SH) $(OTHER)`
  193. X
  194. Xclean:        
  195. X        rm -f *.o
  196. X
  197. Xclobber:        
  198. X        rm -f $(ALL)
  199. X
  200. Xlist:
  201. X    @for i in ${CFILES} ${HFILES} ${OTHER}; do \
  202. X        echo "${START}/$$i"; \
  203. X    done    
  204. X
  205. Xcpio:
  206. X    make -s list | cpio -ocv > ${CPIO}
  207. END_OF_FILE
  208. # end of 'demo/misc/Makefile'
  209. fi
  210. if test -f 'demo/misc/clock2.c' -a "${1}" != "-c" ; then 
  211.   echo shar: Will not clobber existing file \"'demo/misc/clock2.c'\"
  212. else
  213. echo shar: Extracting \"'demo/misc/clock2.c'\" \(5054 characters\)
  214. sed "s/^X//" >'demo/misc/clock2.c' <<'END_OF_FILE'
  215. X/*                        Copyright (c) 1987 Bellcore
  216. X *                            All Rights Reserved
  217. X *       Permission is granted to copy or use this program, EXCEPT that it
  218. X *       may not be sold for profit, the copyright notice must be reproduced
  219. X *       on copies, and credit should be given to Bellcore where it is due.
  220. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  221. X */
  222. X/*    $Header: clock2.c,v 4.2 88/06/22 14:37:27 bianchi Exp $
  223. X    $Source: /tmp/mgrsrc/demo/misc/RCS/clock2.c,v $
  224. X*/
  225. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/misc/RCS/clock2.c,v $$Revision: 4.2 $";
  226. X
  227. X/* get today's date  (analog clock version) */
  228. X
  229. X#include <errno.h>
  230. X#include <time.h>
  231. X#include <stdio.h>
  232. X#include "term.h"
  233. X#include "restart.h"
  234. X
  235. X#define OFFSET        (500<<10)        /* shift points to 1st quad */
  236. X
  237. X/* sin, cos tables: 0-360 deg. in 6 deg. increments (scaled to +/- 1024) */
  238. X
  239. Xint sin[] = {
  240. X     0, 107, 212, 316, 416, 512,
  241. X     601, 685, 760, 828, 886, 935,
  242. X     973, 1001, 1018, 1023, 1018, 1001,
  243. X     973, 935, 886, 828, 760, 685,
  244. X     601, 511, 416, 316, 212, 107,
  245. X     0, -107, -212, -316, -416, -512,
  246. X     -601, -685, -760, -828, -886, -935,
  247. X     -973, -1001, -1018, -1023, -1018, -1001,
  248. X     -973, -935, -886, -828, -760, -685,
  249. X     -601, -511, -416, -316, -212, -107,
  250. X     0 };
  251. X
  252. X
  253. Xint cos[] = {
  254. X     1023, 1018, 1001, 973, 935, 886,
  255. X     828, 760, 685, 601, 511, 416,
  256. X     316, 212, 107, 0, -107, -212,
  257. X     -316, -416, -512, -601, -685, -760,
  258. X     -828, -886, -935, -973, -1001, -1018,
  259. X     -1023, -1018, -1001, -973, -935, -886,
  260. X     -828, -760, -685, -601, -511, -416,
  261. X     -316, -212, -107, 0, 107, 212,
  262. X     316, 416, 512, 601, 685, 760,
  263. X     828, 886, 935, 973, 1001, 1018,
  264. X     1023 };
  265. X
  266. Xtypedef struct coord {
  267. X    int x,y;
  268. X    } coord;
  269. X
  270. X/* coordinates of the hands at 12:00 */
  271. X
  272. Xcoord second[] = { 1,-30,  0,485 };
  273. Xcoord minute[] = { 10,-10,  0,400,  -10,-10,  10,-10 };
  274. Xcoord hour[] = { 35,-10,  0,270,  -35,-10,  35,-10 };
  275. X
  276. Xcoord big_tic[] = { -11,485,  0,450,  11,485 };
  277. Xcoord tic[] = { 0,485,  0,460 };
  278. X
  279. Xint h, old_h, m, old_m, s, old_s;
  280. X
  281. Xmain(argc,argv)
  282. Xint argc;
  283. Xchar **argv;
  284. X   {
  285. X   register int i;
  286. X   int cal=0;
  287. X   int dotime(), clean();
  288. X   char line[80];
  289. X
  290. X   ckmgrterm( *argv );
  291. X
  292. X   if (argc>1 && strcmp(argv[1],"-c")==0)
  293. X      cal++;
  294. X
  295. X   /* setup mgr environment */
  296. X
  297. X   m_setup(0);
  298. X   m_push(P_FLAGS|P_EVENT);
  299. X   m_ttyset();
  300. X
  301. X   m_setevent(REDRAW,"R\r");
  302. X   m_setevent(RESHAPE,"R\r");
  303. X   if (cal)
  304. X      m_setevent(ACTIVATE,"A\r");
  305. X
  306. X   signal(SIGALRM,dotime);
  307. X   signal(SIGTERM,clean);
  308. X   signal(SIGINT,clean);
  309. X   signal(SIGHUP,clean);
  310. X
  311. X   while(1) {
  312. X      m_func(B_SET);
  313. X      m_clear();
  314. X      m_ellipse(500,500,490,490);
  315. X      for(i=0;i<60;i+=5)         /* the tic marks */
  316. X         if (i%15==0)
  317. X            draw(big_tic,2,i);
  318. X         else
  319. X            draw(tic,1,i);
  320. X   
  321. X      m_movecursor(500,500);
  322. X      get_time(&h, &m, &s);
  323. X
  324. X      draw(hour,3,h);
  325. X      draw(minute,3,m);
  326. X
  327. X      m_func(B_INVERT);
  328. X      draw(second,1,s);
  329. X      m_flush();
  330. X      dotime();
  331. X
  332. X      /* wait for an event */
  333. X
  334. X      while(1) {
  335. X     extern int   errno;
  336. X
  337. X         errno = 0;
  338. X     *line = '\0';
  339. X         if (m_gets(line) == NULL  &&  errno  &&  errno != EINTR)
  340. X            clean(0);
  341. X         alarm(0);
  342. X         if (*line=='R')
  343. X            break;
  344. X         else if (cal && *line == 'A') {
  345. X            long time(), tmp = time(0);
  346. X            char *ctime();
  347. X
  348. X            m_push(P_ALL);
  349. X            m_font(11);
  350. X            m_size(27,3);
  351. X            m_clear();
  352. X            m_printstr("\n "); 
  353. X            m_printstr(ctime(&tmp));
  354. X            m_flush();
  355. X            sleep(3);
  356. X            m_pop();
  357. X            m_clearmode(M_ACTIVATE);
  358. X            m_flush();
  359. X            }
  360. X         dotime();
  361. X         }
  362. X      }
  363. X   }
  364. X
  365. X/* update the time */
  366. X
  367. Xint
  368. Xdotime()
  369. X   {
  370. X   old_h=h, old_m=m, old_s=s;
  371. X   get_time(&h, &m, &s);
  372. X
  373. X   draw(second,1,old_s);
  374. X   if (old_m != m) {
  375. X      m_func(B_CLEAR);
  376. X      draw(minute,3,old_m);
  377. X      draw(hour,3,old_h);
  378. X      m_func(B_SET);
  379. X      draw(hour,3,h);
  380. X      draw(minute,3,m);
  381. X      m_func(B_INVERT);
  382. X      }
  383. X
  384. X   draw(second,1,s);
  385. X   m_flush();
  386. X   signal(SIGALRM,dotime);
  387. X   alarm(1);
  388. X   }
  389. X
  390. X/* rotate and draw hands */
  391. X   
  392. X#define X(i)    (what[i].x)
  393. X#define Y(i)    (what[i].y)
  394. X
  395. Xdraw(what, n, theta)
  396. Xcoord what[];            /* array of points */
  397. Xint n;                /* number of points */
  398. Xint theta;            /* angle (in 160th of a circle) */
  399. X   {
  400. X   register int i;
  401. X
  402. X   for(i=0;i<n;i++) {
  403. X      m_line((X(i)*cos[theta]+Y(i)*sin[theta] + OFFSET)>>10,
  404. X           (X(i)*sin[theta]-Y(i)*cos[theta] + OFFSET)>>10,
  405. X           (X(i+1)*cos[theta]+Y(i+1)*sin[theta] + OFFSET)>>10,
  406. X           (X(i+1)*sin[theta]-Y(i+1)*cos[theta] + OFFSET)>>10);
  407. X           }
  408. X   }
  409. X
  410. X/* convert time to angles */
  411. X
  412. Xget_time(h,m,s)
  413. Xint *h, *m, *s;        /* hours, minutes, seconds */
  414. X   {
  415. X   struct tm *tme, *localtime();
  416. X   long tmp,time();
  417. X    
  418. X   tmp = time(0);
  419. X   tme = localtime(&tmp);
  420. X
  421. X   *m = tme->tm_min;
  422. X   *s = tme->tm_sec;
  423. X   if (tme->tm_hour > 11)
  424. X      tme->tm_hour -= 12;
  425. X   *h = tme->tm_hour*5 + (2+tme->tm_min)/12;
  426. X   }
  427. X
  428. X/* clean up and exit */
  429. X
  430. Xclean(n)
  431. Xint    n;
  432. X   {
  433. X   m_popall(0);
  434. X   m_clear();
  435. X   m_flush();
  436. X   m_ttyreset();
  437. X   exit(1);
  438. X   }
  439. END_OF_FILE
  440. # end of 'demo/misc/clock2.c'
  441. fi
  442. if test -f 'src/blit/bitmap.c' -a "${1}" != "-c" ; then 
  443.   echo shar: Will not clobber existing file \"'src/blit/bitmap.c'\"
  444. else
  445. echo shar: Extracting \"'src/blit/bitmap.c'\" \(4616 characters\)
  446. sed "s/^X//" >'src/blit/bitmap.c' <<'END_OF_FILE'
  447. X/*                        Copyright (c) 1987 Bellcore
  448. X *                            All Rights Reserved
  449. X *       Permission is granted to copy or use this program, EXCEPT that it
  450. X *       may not be sold for profit, the copyright notice must be reproduced
  451. X *       on copies, and credit should be given to Bellcore where it is due.
  452. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  453. X */
  454. X/*    $Header: bitmap.c,v 4.2 88/07/07 09:04:29 sau Exp $
  455. X    $Source: /tmp/mgrsrc/src/blit/RCS/bitmap.c,v $
  456. X*/
  457. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/blit/RCS/bitmap.c,v $$Revision: 4.2 $";
  458. X
  459. X/*  SUN-2  and SUN-3 bitblit code */
  460. X
  461. X#ifdef sun
  462. X#  include <sys/ioctl.h>
  463. X#  include <sun/fbio.h>
  464. X#  include <sys/file.h>
  465. X#  include <sys/mman.h>
  466. X#endif
  467. X#include <stdio.h>
  468. X#include "bitmap.h"
  469. X
  470. Xint bit_debug = 1;
  471. Xstatic int _s_start;
  472. Xstatic _s_len;
  473. X
  474. X/* open the screen; it looks like memory */
  475. X
  476. XBITMAP *
  477. Xbit_open(name)
  478. Xchar *name;            /* name of frame buffer */
  479. X{
  480. X   BITMAP *result = BIT_NULL;
  481. X#ifdef sun
  482. X   int fd;
  483. X   char *malloc();
  484. X   register DATA addr;
  485. X   struct fbtype buff;
  486. X   int pagesize;
  487. X
  488. X   Bprintf(1) ("bit_open:(%s)\n", name);
  489. X
  490. X   /* open the SUN screen */
  491. X
  492. X   if ((fd = open(name, O_RDWR)) < 0)
  493. X      return (BIT_NULL);
  494. X
  495. X   /* get the frame buffer size */
  496. X
  497. X   if (ioctl(fd, FBIOGTYPE, &buff) < 0)
  498. X      return (BIT_NULL);
  499. X
  500. X   /* malloc space for frame buffer */
  501. X
  502. X   pagesize = getpagesize();
  503. X   if ((_s_start = (int) malloc(buff.fb_size + pagesize)) == 0)
  504. X      return (BIT_NULL);
  505. X
  506. X   /* align space on a page boundary */
  507. X
  508. X   buff.fb_size = (buff.fb_size+pagesize-1) &~ (pagesize-1);
  509. X   addr = (DATA ) ((_s_start + pagesize - 1) & ~(pagesize - 1));
  510. X
  511. X   /* map the frame buffer into malloc'd space */
  512. X
  513. X#ifdef _MAP_NEW        /* New semantics for mmap in Sun release 4.0 */
  514. X   addr = (DATA) mmap(addr, _s_len=buff.fb_size,
  515. X                         PROT_WRITE, _MAP_NEW|MAP_SHARED, fd, 0);
  516. X   if ((int)addr == -1)
  517. X      return (BIT_NULL);
  518. X#else
  519. X   if (mmap(addr, _s_len = buff.fb_size, PROT_WRITE, MAP_SHARED, fd, 0) < 0)
  520. X      return (BIT_NULL);
  521. X#endif
  522. X
  523. X   if ((result = (BITMAP *) malloc(sizeof(BITMAP))) == (BITMAP *) 0)
  524. X      return (BIT_NULL);
  525. X
  526. X   result->primary = result;
  527. X   result->data = addr;
  528. X   result->x0 = 0,
  529. X      result->y0 = 0,
  530. X      result->wide = buff.fb_width;
  531. X   result->high = buff.fb_height;
  532. X   result->type = _SCREEN;
  533. X   Bprintf(2) ("  O.K.(0x%lx)\n (%d x %x)",
  534. X           (long) result->data, result->wide, result->high);
  535. X#endif
  536. X   return (result);
  537. X}
  538. X
  539. X/* destroy a bitmap, free up space */
  540. X
  541. Xint
  542. Xbit_destroy(bitmap)
  543. XBITMAP *bitmap;
  544. X{
  545. X   Bprintf(1) ("bit_destroy:\n");
  546. X   if (bitmap == (BITMAP *) 0)
  547. X      return (-1);
  548. X   if (IS_MEMORY(bitmap) && IS_PRIMARY(bitmap))
  549. X      free(bitmap->data);
  550. X   else if (IS_SCREEN(bitmap) && IS_PRIMARY(bitmap)) {
  551. X      munmap(BIT_DATA(bitmap), _s_len);
  552. X      free(_s_start);
  553. X   }
  554. X   free(bitmap);
  555. X   return (0);
  556. X}
  557. X
  558. X/* create a bitmap as a sub-rectangle of another bitmap */
  559. X
  560. XBITMAP *
  561. Xbit_create(map, x, y, wide, high)
  562. XBITMAP *map;
  563. Xint x, y, wide, high;
  564. X{
  565. X   char *malloc();
  566. X   register BITMAP *result;
  567. X
  568. X   Bprintf(1) ("bit_create:\n");
  569. X   if (x + wide > map->wide)
  570. X      wide = map->wide - x;
  571. X   if (y + high > map->high)
  572. X      high = map->high - y;
  573. X   if (wide < 1 || high < 1)
  574. X      return (BIT_NULL);
  575. X
  576. X   if ((result = (BITMAP *) malloc(sizeof(BITMAP))) == (BITMAP *) 0)
  577. X      return (BIT_NULL);
  578. X
  579. X   result->data = map->data;
  580. X   result->x0 = map->x0 + x;
  581. X   result->y0 = map->y0 + y;
  582. X   result->wide = wide;
  583. X   result->high = high;
  584. X   result->primary = map->primary;
  585. X   result->type = map->type;
  586. X   Bprintf(2) ("  Created %d,%d %d,%d\n", result->x0, result->y0,
  587. X           result->wide, result->high);
  588. X   return (result);
  589. X}
  590. X
  591. X/* allocate space for, and create a memory bitmap */
  592. X
  593. XBITMAP *
  594. Xbit_alloc(wide, high, data, bits)
  595. Xunsigned short wide, high;
  596. XDATA data;
  597. Xint bits;    /* in preparation for color */
  598. X{
  599. X   char *malloc();
  600. X   register BITMAP *result;
  601. X   register int size;
  602. X
  603. X   Bprintf(1) ("bit_alloc:\n");
  604. X   if ((result = (BITMAP *) malloc(sizeof(BITMAP))) == (BITMAP *) 0)
  605. X      return (result);
  606. X
  607. X   result->x0 = 0;
  608. X   result->y0 = 0;
  609. X   result->high = high;
  610. X   result->wide = wide;
  611. X
  612. X   size = BIT_SIZE(result);
  613. X
  614. X   if (data != (DATA ) 0)
  615. X      result->data = data;
  616. X#ifdef ALIGN32
  617. X   else if ((result->data = (DATA ) memalign(4,size)) == (DATA ) 0) {
  618. X#else
  619. X   else if ((result->data = (DATA ) malloc(size)) == (DATA ) 0) {
  620. X#endif
  621. X      free(result);
  622. X      return ((BITMAP *) 0);
  623. X   }
  624. X
  625. X   result->primary = result;
  626. X   result->type = _MEMORY;
  627. X   Bprintf(2) ("  Created %d,%d %d,%d\n", result->x0, result->y0,
  628. X           result->wide, result->high);
  629. X   return (result);
  630. X}
  631. END_OF_FILE
  632. # end of 'src/blit/bitmap.c'
  633. fi
  634. if test -f 'src/blit/line.C' -a "${1}" != "-c" ; then 
  635.   echo shar: Will not clobber existing file \"'src/blit/line.C'\"
  636. else
  637. echo shar: Extracting \"'src/blit/line.C'\" \(4306 characters\)
  638. sed "s/^X//" >'src/blit/line.C' <<'END_OF_FILE'
  639. X/*                        Copyright (c) 1988 Bellcore
  640. X *                            All Rights Reserved
  641. X *       Permission is granted to copy or use this program, EXCEPT that it
  642. X *       may not be sold for profit, the copyright notice must be reproduced
  643. X *       on copies, and credit should be given to Bellcore where it is due.
  644. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  645. X */
  646. X/*    $Header: line.C,v 4.2 88/06/30 11:40:57 sau Exp $
  647. X    $Source: /tmp/mgrsrc/src/blit/RCS/line.C,v $
  648. X*/
  649. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/blit/RCS/line.C,v $$Revision: 4.2 $";
  650. X
  651. X#include "asm.h"
  652. X#include "bitmap.h"
  653. X
  654. X/*  Draw a line  - Bresenham method using bit-field instructions.
  655. X *  The bitfield instructions don't buy much (<10%), but they're there.
  656. X */
  657. X
  658. Xbit_line(dest, x0, y0, x1, y1, func)
  659. Xregister BITMAP *dest;                /* destination bitmap */    
  660. Xint x0, y0, x1, y1;            /* line coordinates */
  661. Xint func;                    /* set, clear, or invert */
  662. X   {
  663. X   register int err, rincr, rdecr, d_incr, count;
  664. X   register int offset;            /* bit offset from x0,y0 */
  665. X   register long *base;            /* address of x0,y0 */
  666. X   int dx, dy;                /* # of pixels in x and y */
  667. X   int temp;
  668. X
  669. X#ifndef NOCLIP
  670. X   /* clip here */
  671. X
  672. X#define TOP    001
  673. X#define BOTTOM    002
  674. X#define LEFT    004
  675. X#define RIGHT    010
  676. X#define CROSS(x,y) \
  677. X      (x<0 ? LEFT : x>= (dest->wide) ? RIGHT : 0) + \
  678. X      (y < 0 ? TOP : y >=  (dest -> high) ? BOTTOM : 0)
  679. X
  680. X      {
  681. X
  682. X      /* The classic line clipping algorithm */
  683. X
  684. X      int cross0 = CROSS(x0, y0);
  685. X      int cross1 = CROSS(x1, y1);
  686. X
  687. X      while (cross0 || cross1) {
  688. X          int cross, x, y;
  689. X          if (cross0 & cross1)
  690. X             return;
  691. X          if (cross0 != 0)
  692. X             cross = cross0;
  693. X          else
  694. X             cross = cross1;
  695. X          if (cross & (LEFT | RIGHT)) {
  696. X             int edge = (cross & LEFT) ? 0 : dest->wide - 1;
  697. X             y = y0 + (y1 - y0) * (edge - x0) / (x1 - x0);
  698. X             x = edge;
  699. X             }
  700. X          else if (cross & (TOP | BOTTOM)) {
  701. X             int edge = (cross & TOP) ? 0 : dest->high - 1;
  702. X             x = x0 + (x1 - x0) * (edge - y0) / (y1 - y0);
  703. X             y = edge;
  704. X             }
  705. X          if (cross == cross0) {
  706. X             x0 = x;
  707. X             y0 = y;
  708. X             cross0 = CROSS(x, y);
  709. X             }
  710. X          else {
  711. X             x1 = x;
  712. X             y1 = y;
  713. X             cross1 = CROSS(x, y);
  714. X             }
  715. X         }
  716. X      }
  717. X
  718. X   /* end of clipping */
  719. X#endif
  720. X
  721. X   x0 += dest->x0;
  722. X   y0 += dest->y0;
  723. X   x1 += dest->x0;
  724. X   y1 += dest->y0;
  725. X
  726. X   /* always draw left to right */
  727. X
  728. X   if (x1 < x0) {
  729. X      temp = x1, x1 = x0, x0 = temp;
  730. X      temp = y1, y1 = y0, y0 = temp;
  731. X      }
  732. X   dx = x1 - x0;
  733. X   dy = y1 - y0;
  734. X
  735. X   if (dy > 0)
  736. X      d_incr = BIT_LINE(dest);
  737. X   else
  738. X      d_incr = -BIT_LINE(dest), dy = -dy;
  739. X
  740. X   base = y0 * (BIT_LINE(dest) >> 5) + (dest->data);    /* start of line */
  741. X   offset = x0;            /* bit offset from line */
  742. X
  743. X#define STEP(dx,dy,xmove,ymove,op) {        \
  744. X    rincr = (dx - dy)<<1;            \
  745. X    rdecr = -(dy<<1);                \
  746. X    err = dx + rdecr;                \
  747. X    for (count = dx; count >= 0; count--) {    \
  748. X        op($base,$offset,IMM(1)); \
  749. X        offset  += (xmove);                        \
  750. X        if (err < 0) {                \
  751. X            offset += (ymove);                \
  752. X            err += rincr;                \
  753. X            }                    \
  754. X        else {                    \
  755. X            err += rdecr;                \
  756. X            }                    \
  757. X        }                     \
  758. X    }
  759. X
  760. X   /* @+ */
  761. X
  762. X   if (dx > dy)            /* gentle slope */
  763. X      switch (OPCODE(func)) {
  764. X     case OPCODE(SRC):
  765. X     case OPCODE(SRC | DST):
  766. X     case OPCODE(SRC | ~DST):
  767. X     case OPCODE(~0):
  768. X        STEP(dx, dy, 1, d_incr, BF_SET);
  769. X        break;
  770. X     case OPCODE(~SRC):
  771. X     case OPCODE(~(SRC|DST)):
  772. X     case OPCODE(DST & ~SRC):
  773. X     case OPCODE(0):
  774. X        STEP(dx, dy, 1, d_incr, BF_CLR);
  775. X        break;
  776. X     case OPCODE(SRC ^ DST):
  777. X     case OPCODE(~DST):
  778. X     case OPCODE(SRC & ~DST):
  779. X     case OPCODE(~(SRC&DST)):
  780. X        STEP(dx, dy, 1, d_incr, BF_INV);
  781. X        break;
  782. X         }
  783. X   else                /* steep slope */
  784. X      switch (OPCODE(func)) {
  785. X     case OPCODE(SRC):
  786. X     case OPCODE(SRC | DST):
  787. X     case OPCODE(SRC | ~DST):
  788. X     case OPCODE(~0):
  789. X        STEP(dy, dx, d_incr, 1, BF_SET);
  790. X        break;
  791. X     case OPCODE(~SRC):
  792. X     case OPCODE(~(SRC|DST)):
  793. X     case OPCODE(DST & ~SRC):
  794. X     case OPCODE(0):
  795. X        STEP(dy, dx, d_incr, 1, BF_CLR);
  796. X        break;
  797. X     case OPCODE(SRC ^ DST):
  798. X     case OPCODE(~DST):
  799. X     case OPCODE(SRC & ~DST):
  800. X     case OPCODE(~(SRC&DST)):
  801. X        STEP(dy, dx, d_incr, 1, BF_INV);
  802. X        break;
  803. X    }
  804. X   }
  805. END_OF_FILE
  806. # end of 'src/blit/line.C'
  807. fi
  808. if test -f 'src/blit/sym.c' -a "${1}" != "-c" ; then 
  809.   echo shar: Will not clobber existing file \"'src/blit/sym.c'\"
  810. else
  811. echo shar: Extracting \"'src/blit/sym.c'\" \(5117 characters\)
  812. sed "s/^X//" >'src/blit/sym.c' <<'END_OF_FILE'
  813. X/*                        Copyright (c) 1988 Bellcore
  814. X *                            All Rights Reserved
  815. X *       Permission is granted to copy or use this program, EXCEPT that it
  816. X *       may not be sold for profit, the copyright notice must be reproduced
  817. X *       on copies, and credit should be given to Bellcore where it is due.
  818. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  819. X */
  820. X/*    $Header: sym.c,v 4.1 88/06/21 13:19:15 bianchi Exp $
  821. X    $Source: /tmp/mgrsrc/src/blit/RCS/sym.c,v $
  822. X*/
  823. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/blit/RCS/sym.c,v $$Revision: 4.1 $";
  824. X
  825. X/* do symbolic substitution for asm decls SUN version */
  826. X
  827. X/*    sample stab entries
  828. X    .stabs    "x:r(0,1)",0x40,0,4,7
  829. X    .stabs    "i:r(0,1)",0x40,0,4,6
  830. X    .stabs    "d:r(0,13)",0x40,0,1,12
  831. X    .stabs    "s:r(0,13)=*(0,2)",0x40,0,1,13
  832. X   sample sun instruction
  833. X       bfins.l %d1, (%$dbase)[%$dst:%$field]
  834. X*/
  835. X
  836. X#include "stdio.h"
  837. X#include "hash.h"
  838. X
  839. X#define GET_OPT(i)   \
  840. X   strlen(argv[i])>2 ? argv[i]+2 : argv[++i]
  841. X
  842. X#define FMT    "    .stabs    \"%[^:]:r%*[^\"]\",0x%d,%*d,%*d,%s"
  843. X#define TSIZE        501            /* # of entries in hash table */
  844. X#define KEY    "#$ %s %s"        /* key work entry */
  845. X#define dprintf    if(debug)fprintf
  846. X
  847. Xchar line[512];            /* input line buffer */
  848. Xchar name[32];                /* parameter name */
  849. Xchar reg[10];                /* register value */
  850. X
  851. Xstruct table_entry *table[TSIZE];
  852. X
  853. Xmain(argc,argv)
  854. Xint argc;
  855. Xchar **argv;
  856. X   {
  857. X   int class;        /* storage class */
  858. X   int n;
  859. X   char *start, *end;    /* for finding sub's. */
  860. X   char *index(), *get_end();
  861. X   int value;        /* register value to substitute */
  862. X   int count = 0;    /* # of subs */
  863. X   int line_cnt=0;        /* input line # */
  864. X   char type;        /* register type 'a' or 'd' */
  865. X   int debug = 0;
  866. X   register int i;
  867. X
  868. X   for(i=1;i<argc;i++) {
  869. X      if (*argv[i] == '-')
  870. X         switch (argv[i][1]) {
  871. X            case 'd':            /* turn on debugging */
  872. X               debug++;
  873. X               break;
  874. X            case 'K':            /* add keyword */
  875. X                  { 
  876. X                  char *key = (GET_OPT(i));
  877. X                  char *reg = argv[++i];
  878. X                  add_entry(table,TSIZE,key);
  879. X                  put_entry(table,TSIZE,key,reg);
  880. X                  dprintf(stderr,"adding %s => %s from command line\n",key,reg);
  881. X                  }
  882. X               break;
  883. X            default:
  884. X               fprintf(stderr,"%s: bad flag %c ignored\n",argv[0],argv[i][1]);
  885. X            }
  886. X         }
  887. X
  888. X   dprintf(stderr,"Asm symbolic processor\n");
  889. X   while(gets(line) != NULL) {
  890. X      line_cnt++;
  891. X        n = sscanf(line,FMT,name,&class,reg);
  892. X        if (n==3 && class == 40) {                    /* declaration */
  893. X         if (is_entry(table,TSIZE,reg))  {        /* delete old name */
  894. X            dlt_entry(table,TSIZE,get_entry(table,TSIZE,reg));
  895. X            }
  896. X         add_entry(table,TSIZE,reg);
  897. X         add_entry(table,TSIZE,name);
  898. X         put_entry(table,TSIZE,name,reg);
  899. X         put_entry(table,TSIZE,reg,name);
  900. X         puts(line);
  901. X         dprintf(stderr,"adding %s => %s from stab entry\n",name,reg);
  902. X         }
  903. X      else if (sscanf(line,KEY,name,reg) == 2) {    /* keyword substitution */
  904. X         add_entry(table,TSIZE,name);
  905. X         put_entry(table,TSIZE,name,reg);
  906. X         dprintf(stderr,"adding %s => %s from file\n",name,reg);
  907. X         }
  908. X      else if (start = index(line,'$')) {                /* parameter substitution */
  909. X         fwrite(line,1,start-line,stdout);
  910. X         do {
  911. X            end = get_end(start+1);
  912. X            strncpy(name,start+1,end-start-1);
  913. X            name[end-start-1] = '\0';
  914. X            if (is_entry(table,TSIZE,name)) { /* do substitution */
  915. X               value = atoi(get_entry(table,TSIZE,name));
  916. X               if (value > 7) {
  917. X                  type = 'a';
  918. X                  value -=8;
  919. X                  }
  920. X               else
  921. X                  type = 'd';
  922. X               printf("%c%d",type,value);
  923. X               dprintf(stderr,"line %d: substituting <%c%d> for <%s>\n",
  924. X                       line_cnt,type,value,name);
  925. X               count++;
  926. X               }
  927. X            else if (is_reg(name))    {                            /* can't find sub */
  928. X               printf("%s",name);
  929. X               } 
  930. X            else {            
  931. X               printf("$%s",name);
  932. X               fprintf(stderr,"%s: Line %d no register found for %s\n",
  933. X                       *argv,line_cnt,name);
  934. X               }
  935. X            if (start = index(end,'$')) 
  936. X               fwrite(end,1,start-end,stdout);
  937. X            else
  938. X               printf("%s\n",end);
  939. X            }
  940. X         while(start);
  941. X         }
  942. X      else                                                            /* pass through */
  943. X         puts(line);
  944. X      }
  945. X   dprintf(stderr,"%d substitutions made on %d lines\n",count,line_cnt);
  946. X   exit(0);
  947. X   }
  948. X
  949. X/* find end of word */
  950. X
  951. Xchar *
  952. Xget_end(str)
  953. Xchar *str;
  954. X   {
  955. X   register char c;
  956. X   register int i=0;
  957. X
  958. X   while (i++,(c = *str++)) {
  959. X      if (c>='a' && c<='z') continue;
  960. X      if (c>='A' && c <= 'Z') continue;
  961. X      if (i>1 && c>='0' && c <= '9') continue;
  962. X      if (c != '_') break;
  963. X      }
  964. X   return(str-1);
  965. X   }
  966. X
  967. X/* see if variable is [ad][0-7] */
  968. X
  969. Xint
  970. Xis_reg(name)
  971. Xchar *name;
  972. X   {
  973. X   return( (name[0]=='d' || name[1] == 'a') &&
  974. X           (name[1] >= '0' && name[1] <= '7'));
  975. X   }
  976. END_OF_FILE
  977. # end of 'src/blit/sym.c'
  978. fi
  979. if test -f 'src/destroy.c' -a "${1}" != "-c" ; then 
  980.   echo shar: Will not clobber existing file \"'src/destroy.c'\"
  981. else
  982. echo shar: Extracting \"'src/destroy.c'\" \(5076 characters\)
  983. sed "s/^X//" >'src/destroy.c' <<'END_OF_FILE'
  984. X/*                        Copyright (c) 1987 Bellcore
  985. X *                            All Rights Reserved
  986. X *       Permission is granted to copy or use this program, EXCEPT that it
  987. X *       may not be sold for profit, the copyright notice must be reproduced
  988. X *       on copies, and credit should be given to Bellcore where it is due.
  989. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  990. X */
  991. X/*    $Header: destroy.c,v 4.1 88/06/21 13:21:40 bianchi Exp $
  992. X    $Source: /tmp/mgrsrc/src/RCS/destroy.c,v $
  993. X*/
  994. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/RCS/destroy.c,v $$Revision: 4.1 $";
  995. X
  996. X/* destroy a window (needs fixing) */
  997. X
  998. X#include "bitmap.h"
  999. X#include <stdio.h>     /* temporary */
  1000. X#include <sys/wait.h>
  1001. X#include <sys/signal.h>
  1002. X#include "defs.h"
  1003. X#include "font.h"
  1004. X#include "event.h"
  1005. X
  1006. X#define ALL    1
  1007. X
  1008. X/* mark active window for destruction */
  1009. X
  1010. Xint destroy_window()
  1011. X   {
  1012. X   ACTIVE(flags) |= W_DIED;
  1013. X   }
  1014. X
  1015. X/* destroy a window */
  1016. X
  1017. Xint destroy(win)
  1018. Xregister WINDOW *win;
  1019. X   {
  1020. X   int i;
  1021. X   union wait status;
  1022. X
  1023. X   if (win == (WINDOW *) 0)
  1024. X      return(-1);
  1025. X
  1026. X   MOUSE_OFF(mousex,mousey);
  1027. X   cursor_off();
  1028. X
  1029. X   if (win != active) {
  1030. X      ACTIVE_OFF();
  1031. X      expose(win);
  1032. X      }
  1033. X
  1034. X   active = W(next);
  1035. X
  1036. X   /* deallocate window slot */
  1037. X
  1038. X   if (active)
  1039. X      ACTIVE(prev) = W(prev);
  1040. X
  1041. X   /* remove window from screen */
  1042. X
  1043. X   erase_win(W(border));
  1044. X
  1045. X   if (W(main)==win) {        /* kill process associated with the window */
  1046. X#ifdef DEBUG
  1047. X      dprintf(d)(stderr,"%s: destroy main %s\r\n",W(tty),W(alt)?"ALT":"");
  1048. X#endif
  1049. X      killpg(W(pid),SIGHUP);
  1050. X
  1051. X      if (geteuid() < 1) {
  1052. X         chmod(W(tty),0666);
  1053. X         chown(W(tty),0,0);
  1054. X         }
  1055. X
  1056. X      close(W(to_fd));
  1057. X      mask &= ~(1<<W(to_fd));
  1058. X      poll &= ~(1<<W(to_fd));
  1059. X#ifdef WHO
  1060. X      rm_utmp(W(tty));
  1061. X#endif
  1062. X
  1063. X      /* tell alternate windows main died */
  1064. X
  1065. X      set_dead(win);
  1066. X
  1067. X      /* wait for shell to die */
  1068. X
  1069. X#ifdef DEBUG
  1070. X      dprintf(d)(stderr,"waiting for ..."); fflush(stderr);
  1071. X#endif
  1072. X      if (W(pid) > 1) {
  1073. X         i = wait3(&status,WNOHANG,0L);
  1074. X         if (i == 0) {                     /* start it so it can die */
  1075. X            kill(W(pid),SIGCONT);
  1076. X            wait(&status);
  1077. X            }
  1078. X         }
  1079. X#ifdef DEBUG
  1080. X      dprintf(d)(stderr," %d\r\n",i);
  1081. X#endif
  1082. X      next_window--; 
  1083. X      }
  1084. X
  1085. X   else if (W(main) && !(W(main)->flags&W_DIED)) {    /* main still alive */
  1086. X#ifdef DEBUG
  1087. X      dprintf(d)(stderr,"%s: destroy alt %d\r\n",W(tty),W(num));
  1088. X#endif
  1089. X      do_event(EVENT_DESTROY,win,E_MAIN);
  1090. X      if (W(from_fd)) {        /* re-attach output to main window */
  1091. X         W(main)->from_fd = W(main)->to_fd;
  1092. X         W(main)->max = W(max) - W(current); /* ??? */
  1093. X#ifdef DEBUG
  1094. X      dprintf(d)(stderr,"%s: copy %d chars at %d\r\n",
  1095. X               W(main)->max, W(current));
  1096. X#endif
  1097. X         bcopy(W(buff)+W(current)+1,W(main)->buff,W(main)->max);
  1098. X         W(main)->current = 0;
  1099. X#ifdef DEBUG
  1100. X         dprintf(d)(stderr,"%s: reattaching main %d chars\r\n",W(tty),W(max));
  1101. X#endif
  1102. X         }
  1103. X      detach(win);
  1104. X      }
  1105. X   else if (W(main)) {        /* tell main alts know they are dead */
  1106. X      W(main)->alt = (WINDOW *) 0;
  1107. X#ifdef DEBUG
  1108. X      dprintf(d)(stderr,"%s: destroy alt, (tell main)\r\n",W(tty));
  1109. X#endif
  1110. X      }
  1111. X   else {
  1112. X#ifdef DEBUG
  1113. X      dprintf(d)(stderr,"%s: destroy alt, (dead main)\r\n",W(tty));
  1114. X#endif
  1115. X      }
  1116. X
  1117. X   /* fix up display if any windows left */
  1118. X
  1119. X   if (active) {
  1120. X      repair(win);
  1121. X      un_covered();
  1122. X      clip_bad(win);    /* invalidate clip lists */
  1123. X      ACTIVE_ON();
  1124. X      cursor_on();
  1125. X      }
  1126. X
  1127. X   /* free space associated with dead window */
  1128. X
  1129. X   unlink_win(win,ALL);
  1130. X
  1131. X#ifdef DEBUG
  1132. X   dprintf(d)(stderr,"Active: %s-%d\r\n",
  1133. X          active?ACTIVE(tty):"NONE", active?ACTIVE(num):0);
  1134. X#endif
  1135. X
  1136. X   MOUSE_ON(mousex,mousey);
  1137. X
  1138. X   return(0);
  1139. X   }
  1140. X
  1141. X/* free all space associated with a window */
  1142. X
  1143. Xunlink_win(win,how)
  1144. Xregister WINDOW *win;        /* window to unlink */
  1145. Xint how;            /* if how, unlink window stack as well */
  1146. X   {
  1147. X   register int i;
  1148. X
  1149. X#ifdef DEBUG
  1150. X   dprintf(u)(stderr,"Unlinking %s %s\n",W(tty),how?"ALL":"");
  1151. X#endif
  1152. X
  1153. X   if (how && W(stack))
  1154. X      unlink_win(W(stack),how);
  1155. X   if (W(window))
  1156. X       bit_destroy(W(window));
  1157. X   for(i=0; i< MAXBITMAPS;i++) 
  1158. X      if (W(bitmaps)[i])
  1159. X          bit_destroy(W(bitmaps)[i]);
  1160. X   if (W(border))
  1161. X       bit_destroy(W(border));
  1162. X   if (W(save))
  1163. X       bit_destroy(W(save));
  1164. X   if (W(snarf))
  1165. X      free(W(snarf));
  1166. X   if (W(bitmap))
  1167. X      free(W(bitmap));
  1168. X   zap_cliplist(win);
  1169. X
  1170. X   for(i=0; i< MAXEVENTS;i++) 
  1171. X       if (W(events)[i])
  1172. X          free(W(events)[i]);
  1173. X
  1174. X   for(i=0; i< MAXMENU;i++) 
  1175. X      if (W(menus)[i])
  1176. X         menu_destroy(W(menus)[i]);
  1177. X
  1178. X   free(win);
  1179. X   }
  1180. X
  1181. X/* unlink an alternate window from list */
  1182. X
  1183. Xint
  1184. Xdetach(win2)
  1185. XWINDOW *win2;
  1186. X   {
  1187. X   register WINDOW *win = win2;
  1188. X
  1189. X   if (!(W(main)))
  1190. X      return;
  1191. X   for(win=win2->main;W(alt)!=win2;win=W(alt))
  1192. X      ;
  1193. X   W(alt)= win2->alt;
  1194. X   }
  1195. X
  1196. X/* notify alternate windows of impending death */
  1197. X
  1198. Xset_dead(win)
  1199. Xregister WINDOW *win;
  1200. X   {
  1201. X   for(win = W(alt); win != (WINDOW *) 0; win = W(alt)) {
  1202. X#ifdef DEBUG
  1203. X      dprintf(d)(stderr,"%s: telling %d\r\n",W(tty),W(num));
  1204. X#endif
  1205. X      W(main) = (WINDOW *) 0;
  1206. X      }
  1207. X   }
  1208. END_OF_FILE
  1209. # end of 'src/destroy.c'
  1210. fi
  1211. if test -f 'src/font_subs.c' -a "${1}" != "-c" ; then 
  1212.   echo shar: Will not clobber existing file \"'src/font_subs.c'\"
  1213. else
  1214. echo shar: Extracting \"'src/font_subs.c'\" \(4187 characters\)
  1215. sed "s/^X//" >'src/font_subs.c' <<'END_OF_FILE'
  1216. X/*                        Copyright (c) 1987 Bellcore
  1217. X *                            All Rights Reserved
  1218. X *       Permission is granted to copy or use this program, EXCEPT that it
  1219. X *       may not be sold for profit, the copyright notice must be reproduced
  1220. X *       on copies, and credit should be given to Bellcore where it is due.
  1221. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  1222. X */
  1223. X/*    $Header: font_subs.c,v 4.2 88/06/24 10:18:04 sau Exp $
  1224. X    $Source: /tmp/mgrsrc/src/RCS/font_subs.c,v $
  1225. X*/
  1226. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/RCS/font_subs.c,v $$Revision: 4.2 $";
  1227. X
  1228. X/* font routines */
  1229. X
  1230. X#include "bitmap.h"
  1231. X#include "font.h"
  1232. X#include "default_font.h"
  1233. X#include "window.h"
  1234. X#include <stdio.h>
  1235. X#ifdef DEBUG
  1236. X#   include "defs.h"
  1237. X#endif
  1238. X
  1239. X#define HEAD(x)        font->head.x
  1240. X
  1241. X/**************************************************************************
  1242. X *
  1243. X *    set up a font file
  1244. X */
  1245. X
  1246. Xstruct font *
  1247. Xopen_font(file)
  1248. Xchar *file;            /* name of font file */
  1249. X   {
  1250. X   FILE *fp;
  1251. X   int size;
  1252. X   char *malloc();
  1253. X   struct font *font, *open_sfont();
  1254. X
  1255. X   if (file == (char *) 0 || *file == '\0') {
  1256. X      return(open_sfont(default_font_head,&default_font));
  1257. X      }
  1258. X
  1259. X#ifdef DEBUG
  1260. X      dprintf(f)(stderr,"Opening font file [%s]\n",file);
  1261. X#endif
  1262. X
  1263. X   if ((fp=fopen(file,"r"))  == NULL)
  1264. X      return((struct font *)0);
  1265. X
  1266. X   if ((font=(struct font *) malloc(sizeof(struct font))) == (struct font *)0) {
  1267. X      fclose(fp);
  1268. X      return((struct font *)0);
  1269. X      }
  1270. X
  1271. X   if (fread(&(font->head),HEADER_SIZE,1,fp) != 1) {
  1272. X      free((char *) font);
  1273. X      fclose(fp);
  1274. X      return((struct font *)0);
  1275. X      }
  1276. X
  1277. X   if (HEAD(type) != FONT_A) {
  1278. X      free((char *) font);
  1279. X      fclose(fp);
  1280. X      return((struct font *)0);
  1281. X      }
  1282. X                               
  1283. X   font->data = bit_alloc(HEAD(wide) *HEAD(count),HEAD(high),NULL_DATA,1);
  1284. X   font->table = (struct entry **) 0;
  1285. X
  1286. X   /* read in font data */
  1287. X
  1288. X   size = BIT_SIZE(font->data);
  1289. X   fread(BIT_DATA(font->data), size, 1, fp);
  1290. X
  1291. X   /* create individual characters */
  1292. X
  1293. X   glyph_create( font );
  1294. X
  1295. X   fclose(fp);
  1296. X   return(font);
  1297. X   }
  1298. X
  1299. X
  1300. X/**************************************************************************
  1301. X *
  1302. X *    deallocate a font
  1303. X */
  1304. X
  1305. Xint
  1306. Xfree_font(dead_font)
  1307. Xstruct font *dead_font;        /* font to be deallocated */
  1308. X   {
  1309. X   register int i;
  1310. X
  1311. X   if (!dead_font)
  1312. X      return(-1);
  1313. X
  1314. X   for(i=0;i<MAXGLYPHS;i++)
  1315. X      if (dead_font->glyph[i])
  1316. X         bit_destroy(dead_font->glyph[i]);
  1317. X   if (dead_font->head.type != FONT_S)
  1318. X      bit_destroy(dead_font->data);
  1319. X   zap_fhash(dead_font);        /* free up hash table space */
  1320. X   i=font_purge(dead_font);    /* eliminate references to dead font */
  1321. X
  1322. X#ifdef DEBUG
  1323. X      dprintf(f)(stderr,"freeing font %d (%d references)\n",
  1324. X      dead_font->ident,i);
  1325. X#endif
  1326. X
  1327. X   free((char *) dead_font);
  1328. X   }
  1329. X
  1330. X/**************************************************************************
  1331. X *
  1332. X *    set up a static font file
  1333. X */
  1334. X
  1335. Xstruct font *
  1336. Xopen_sfont(head,data)
  1337. Xstruct font_header head;    /* font header */
  1338. XBITMAP *data;        /* array of bits */
  1339. X   {
  1340. X   char *malloc();
  1341. X   struct font *font;
  1342. X
  1343. X   if ((font=(struct font *) malloc(sizeof(struct font))) == (struct font *)0)
  1344. X      return((struct font *)0);
  1345. X
  1346. X   font->head = head;
  1347. X   font->data = data;
  1348. X   font->head.type = FONT_S;
  1349. X   font->table = (struct entry **) 0;
  1350. X
  1351. X   /* create individual characters */
  1352. X
  1353. X   glyph_create( font );
  1354. X
  1355. X   return(font);
  1356. X   }
  1357. X
  1358. X
  1359. Xstatic
  1360. Xglyph_create( font )
  1361. Xstruct font *font;
  1362. X   {
  1363. X   register int i, x;
  1364. X   int        first = HEAD(start);
  1365. X   int        last = HEAD(start) + HEAD(count);
  1366. X   int        wide = HEAD(wide);
  1367. X   int        high = HEAD(high);
  1368. X   int        nochar;
  1369. X   
  1370. X   /* Pick the character to be printed for characters not in the set.
  1371. X      Normally, it is the character specified by C_NOCHAR, but it that isn't
  1372. X      in the range of the set, we pick the first character (which is usually
  1373. X      a space).
  1374. X   */
  1375. X   nochar = C_NOCHAR - HEAD(start);
  1376. X   if( nochar >= last )
  1377. X    nochar = 0;
  1378. X   nochar *= wide;
  1379. X
  1380. X   x = 0;
  1381. X   for(i=0; i<MAXGLYPHS; i++)
  1382. X      if (i < first || i >= last)
  1383. X         font->glyph[i] = bit_create(font->data, nochar, 0, wide, high);
  1384. X      else {
  1385. X         font->glyph[i] = bit_create(font->data, x, 0, wide, high);
  1386. X         x += wide;
  1387. X         }
  1388. X   }
  1389. END_OF_FILE
  1390. # end of 'src/font_subs.c'
  1391. fi
  1392. if test -f 'src/oblit/bitmap.c' -a "${1}" != "-c" ; then 
  1393.   echo shar: Will not clobber existing file \"'src/oblit/bitmap.c'\"
  1394. else
  1395. echo shar: Extracting \"'src/oblit/bitmap.c'\" \(4634 characters\)
  1396. sed "s/^X//" >'src/oblit/bitmap.c' <<'END_OF_FILE'
  1397. X/*                        Copyright (c) 1987 Bellcore
  1398. X *                            All Rights Reserved
  1399. X *       Permission is granted to copy or use this program, EXCEPT that it
  1400. X *       may not be sold for profit, the copyright notice must be reproduced
  1401. X *       on copies, and credit should be given to Bellcore where it is due.
  1402. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  1403. X */
  1404. X/*    $Header: bitmap.c,v 4.2 88/07/07 09:08:51 sau Exp $
  1405. X    $Source: /tmp/mgrsrc/src/oblit/RCS/bitmap.c,v $
  1406. X*/
  1407. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/oblit/RCS/bitmap.c,v $$Revision: 4.2 $";
  1408. X
  1409. X/*  SUN-2  and SUN-3 bitblit code */
  1410. X
  1411. X#ifdef sun
  1412. X#  include <sys/ioctl.h>
  1413. X#  include <sun/fbio.h>
  1414. X#  include <sys/file.h>
  1415. X#  include <sys/mman.h>
  1416. X#endif
  1417. X#include <stdio.h>
  1418. X#include "bitmap.h"
  1419. X
  1420. Xint bit_debug = 1;
  1421. Xstatic int _s_start;
  1422. Xstatic _s_len;
  1423. X
  1424. X/* open the screen; it looks like memory */
  1425. X
  1426. XBITMAP *
  1427. Xbit_open(name)
  1428. Xchar *name;            /* name of frame buffer */
  1429. X{
  1430. X   BITMAP *result = BIT_NULL;
  1431. X#ifdef sun
  1432. X   int fd;
  1433. X   char *malloc();
  1434. X   register DATA addr;
  1435. X   struct fbtype buff;
  1436. X   int pagesize;
  1437. X
  1438. X   Bprintf(1) ("bit_open:(%s)\n", name);
  1439. X
  1440. X   /* open the SUN screen */
  1441. X
  1442. X   if ((fd = open(name, O_RDWR)) < 0)
  1443. X      return (BIT_NULL);
  1444. X
  1445. X   /* get the frame buffer size */
  1446. X
  1447. X   if (ioctl(fd, FBIOGTYPE, &buff) < 0)
  1448. X      return (BIT_NULL);
  1449. X
  1450. X   /* malloc space for frame buffer */
  1451. X
  1452. X   pagesize = getpagesize();
  1453. X   if ((_s_start = (int) malloc(buff.fb_size + pagesize)) == 0)
  1454. X      return (BIT_NULL);
  1455. X
  1456. X   /* align space on a page boundary */
  1457. X
  1458. X   buff.fb_size = (buff.fb_size+pagesize-1) &~ (pagesize-1);
  1459. X   addr = (DATA ) ((_s_start + pagesize - 1) & ~(pagesize - 1));
  1460. X
  1461. X   /* map the frame buffer into malloc'd space */
  1462. X
  1463. X#ifdef _MAP_NEW      /* New semantics for mmap in Sun release 4.0 */
  1464. X   addr = (DATA) mmap(addr, _s_len=buff.fb_size,
  1465. X                   PROT_WRITE, _MAP_NEW|MAP_SHARED, fd, 0);
  1466. X   if ((int)addr == -1)
  1467. X      return (BIT_NULL);
  1468. X#else
  1469. X   if (mmap(addr, _s_len = buff.fb_size, PROT_WRITE, MAP_SHARED, fd, 0) < 0)
  1470. X      return (BIT_NULL);
  1471. X#endif
  1472. X
  1473. X   if ((result = (BITMAP *) malloc(sizeof(BITMAP))) == (BITMAP *) 0)
  1474. X      return (BIT_NULL);
  1475. X
  1476. X   result->primary = result;
  1477. X   result->data = addr;
  1478. X   result->x0 = 0,
  1479. X      result->y0 = 0,
  1480. X      result->wide = buff.fb_width;
  1481. X   result->high = buff.fb_height;
  1482. X   result->type = _SCREEN;
  1483. X   Bprintf(2) ("  O.K.(0x%lx)\n (%d x %x)",
  1484. X           (long) result->data, result->wide, result->high);
  1485. X#endif
  1486. X   return (result);
  1487. X}
  1488. X
  1489. X/* destroy a bitmap, free up space */
  1490. X
  1491. Xint
  1492. Xbit_destroy(bitmap)
  1493. XBITMAP *bitmap;
  1494. X{
  1495. X   Bprintf(1) ("bit_destroy:\n");
  1496. X   if (bitmap == (BITMAP *) 0)
  1497. X      return (-1);
  1498. X   if (IS_MEMORY(bitmap) && IS_PRIMARY(bitmap))
  1499. X      free(bitmap->data);
  1500. X   else if (IS_SCREEN(bitmap) && IS_PRIMARY(bitmap)) {
  1501. X      munmap(BIT_DATA(bitmap), _s_len);
  1502. X      free(_s_start);
  1503. X   }
  1504. X   free(bitmap);
  1505. X   return (0);
  1506. X}
  1507. X
  1508. X/* create a bitmap as a sub-rectangle of another bitmap */
  1509. X
  1510. XBITMAP *
  1511. Xbit_create(map, x, y, wide, high)
  1512. XBITMAP *map;
  1513. Xint x, y, wide, high;
  1514. X{
  1515. X   char *malloc();
  1516. X   register BITMAP *result;
  1517. X
  1518. X   Bprintf(1) ("bit_create:\n");
  1519. X   if (x + wide > map->wide)
  1520. X      wide = map->wide - x;
  1521. X   if (y + high > map->high)
  1522. X      high = map->high - y;
  1523. X   if (wide < 1 || high < 1)
  1524. X      return (BIT_NULL);
  1525. X
  1526. X   if ((result = (BITMAP *) malloc(sizeof(BITMAP))) == (BITMAP *) 0)
  1527. X      return (BIT_NULL);
  1528. X
  1529. X   result->data = map->data;
  1530. X   result->x0 = map->x0 + x;
  1531. X   result->y0 = map->y0 + y;
  1532. X   result->wide = wide;
  1533. X   result->high = high;
  1534. X   result->primary = map->primary;
  1535. X   result->type = map->type;
  1536. X   Bprintf(2) ("  Created %d,%d %d,%d\n", result->x0, result->y0,
  1537. X           result->wide, result->high);
  1538. X   return (result);
  1539. X}
  1540. X
  1541. X/* allocate space for, and create a memory bitmap */
  1542. X
  1543. XBITMAP *
  1544. Xbit_alloc(wide, high, data, bits)
  1545. Xunsigned short wide, high;
  1546. XDATA data;
  1547. Xint bits;    /* in preparation for color */
  1548. X{
  1549. X   char *malloc();
  1550. X   register BITMAP *result;
  1551. X   register int size;
  1552. X
  1553. X   Bprintf(1) ("bit_alloc:\n");
  1554. X   if ((result = (BITMAP *) malloc(sizeof(BITMAP))) == (BITMAP *) 0)
  1555. X      return (result);
  1556. X
  1557. X   result->x0 = 0;
  1558. X   result->y0 = 0;
  1559. X   result->high = high;
  1560. X   result->wide = wide;
  1561. X
  1562. X   size = BIT_SIZE(result);
  1563. X
  1564. X   if (data != (DATA ) 0)
  1565. X      result->data = data;
  1566. X#ifdef ALIGN32
  1567. X   else if ((result->data = (DATA ) memalign(4,size)) == (DATA ) 0) {
  1568. X#else
  1569. X   else if ((result->data = (DATA ) malloc(size)) == (DATA ) 0) {
  1570. X#endif
  1571. X      free(result);
  1572. X      return ((BITMAP *) 0);
  1573. X   }
  1574. X
  1575. X   result->primary = result;
  1576. X   result->type = _MEMORY;
  1577. X   Bprintf(2) ("  Created %d,%d %d,%d\n", result->x0, result->y0,
  1578. X           result->wide, result->high);
  1579. X   return (result);
  1580. X}
  1581. END_OF_FILE
  1582. # end of 'src/oblit/bitmap.c'
  1583. fi
  1584. if test -f 'src/print.c' -a "${1}" != "-c" ; then 
  1585.   echo shar: Will not clobber existing file \"'src/print.c'\"
  1586. else
  1587. echo shar: Extracting \"'src/print.c'\" \(4315 characters\)
  1588. sed "s/^X//" >'src/print.c' <<'END_OF_FILE'
  1589. X/*                        Copyright (c) 1987 Bellcore
  1590. X *                            All Rights Reserved
  1591. X *       Permission is granted to copy or use this program, EXCEPT that it
  1592. X *       may not be sold for profit, the copyright notice must be reproduced
  1593. X *       on copies, and credit should be given to Bellcore where it is due.
  1594. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  1595. X */
  1596. X/*    $Header: print.c,v 4.1 88/06/21 13:34:25 bianchi Exp $
  1597. X    $Source: /tmp/mgrsrc/src/RCS/print.c,v $
  1598. X*/
  1599. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/RCS/print.c,v $$Revision: 4.1 $";
  1600. X
  1601. X/* debugging routines for printing status info */
  1602. X
  1603. X#include <stdio.h>
  1604. X
  1605. Xstatic char *flags[] = { 
  1606. X   "active",
  1607. X   "escape",
  1608. X   "snarfable",
  1609. X   "reverse",
  1610. X   "standout",
  1611. X   "died",
  1612. X   "expose",
  1613. X   "background",
  1614. X   "nokill",
  1615. X   "vi",
  1616. X   "downloading",
  1617. X   "noinput",
  1618. X   "nowrap",
  1619. X   "overstrike",
  1620. X   "abs-coords",
  1621. X   "minus",
  1622. X   "snarf-lines",
  1623. X   "snarf-tabs",
  1624. X   "snarf-hard",
  1625. X   (char *) 0
  1626. X   };
  1627. X
  1628. Xstatic char *events[] = {
  1629. X   "1_up",
  1630. X   "no-event",
  1631. X   "2_up",
  1632. X   "3_up",
  1633. X   "no-event",
  1634. X   "3_down",
  1635. X   "2_down",
  1636. X   "no-event",
  1637. X   "1_down",
  1638. X   "shape",
  1639. X   "redraw",
  1640. X   "activated",
  1641. X   "deactivated",
  1642. X   "covered",
  1643. X   "uncovered",
  1644. X   "moved",
  1645. X   "destroyed",
  1646. X   "accept",
  1647. X   "notify",
  1648. X   "tell-me",
  1649. X   "snarfed",
  1650. X   "paste",
  1651. X   "stack",
  1652. X   "stack_flag",
  1653. X   (char *) 0
  1654. X   };
  1655. X
  1656. Xstatic char *stack[] = {
  1657. X   "menu",
  1658. X   "event",
  1659. X   "font",
  1660. X   "cursor",
  1661. X   "bitmap",
  1662. X   "position",
  1663. X   "window",
  1664. X   "flags",
  1665. X   "mouse",
  1666. X   "text",
  1667. X   "CLEAR",
  1668. X   (char *) 0
  1669. X   };
  1670. X
  1671. Xstatic char *menu_states[] = {
  1672. X    "choice",
  1673. X    "bottom",
  1674. X    "top",
  1675. X    "top & bottom",
  1676. X    "left",
  1677. X    "left & bottom",
  1678. X    "left & top",
  1679. X    "left & top & bottom",
  1680. X    "right",
  1681. X    "right & bottom",
  1682. X    "right & top",
  1683. X    "right & top & bottom",
  1684. X    "right & left",
  1685. X    "right & left & bottom",
  1686. X    "right & left & top",
  1687. X    "right & left & top & bottom",
  1688. X   };
  1689. X
  1690. Xstatic char buff[512];
  1691. X
  1692. X/* get flag names */
  1693. X
  1694. Xchar *print_flags(n)
  1695. Xint n;
  1696. X   {
  1697. X   char *binary();
  1698. X   register int i,j;
  1699. X
  1700. X   sprintf(buff,"(%s)",binary(n));
  1701. X   for(j=1,i=0;flags[i];i++,j<<=1)
  1702. X      if (j&n) {
  1703. X         if (*buff) strcat(buff,",");
  1704. X         strcat(buff,flags[i]);
  1705. X         }
  1706. X   return(buff);
  1707. X   }
  1708. X
  1709. X/* get menu states */
  1710. X
  1711. Xchar
  1712. X*print_menu(n)
  1713. Xint n;        /* menu state */
  1714. X   {
  1715. X   return(menu_states[n%16]);
  1716. X   }
  1717. X
  1718. X/* get stack codes */
  1719. X
  1720. Xchar *print_stack(n)
  1721. Xint n;
  1722. X   {
  1723. X   register int i,j;
  1724. X   char *binary();
  1725. X
  1726. X   sprintf(buff,"(%s)",binary(n));
  1727. X   for(j=1,i=0;stack[i];i++,j<<=1)
  1728. X      if (j&n) {
  1729. X         if (*buff) strcat(buff,",");
  1730. X         strcat(buff,stack[i]);
  1731. X         }
  1732. X   return(buff);
  1733. X   }
  1734. X
  1735. X/* get event names */
  1736. X
  1737. Xchar *print_events(n)
  1738. Xint n;
  1739. X   {
  1740. X   register int i,j;
  1741. X   char *binary();
  1742. X
  1743. X   sprintf(buff,"(%s)",binary(n));
  1744. X   for(j=1,i=0;events[i];i++,j<<=1)
  1745. X      if (j&n) {
  1746. X         if (*buff) strcat(buff,",");
  1747. X         strcat(buff,events[i]);
  1748. X         }
  1749. X   return(buff);
  1750. X   }
  1751. X
  1752. X
  1753. X/* get ps info */
  1754. X
  1755. Xstatic char *list[100];
  1756. Xstatic int p_count = 0;
  1757. X
  1758. Xint
  1759. Xget_ps()
  1760. X   {
  1761. X   FILE *popen(), *ps = popen("ps a","r");
  1762. X   char line[81];
  1763. X   char *index(), *save_line();
  1764. X
  1765. X   fgets(line,sizeof(line),ps);
  1766. X   while(fgets(line,sizeof(line),ps) != NULL) {
  1767. X      list[p_count++] = save_line(line+6);
  1768. X      }
  1769. X   pclose(ps);
  1770. X   return(p_count);
  1771. X   }
  1772. X
  1773. Xint
  1774. Xfree_ps()
  1775. X   {
  1776. X   register int i;
  1777. X
  1778. X   for(i=0;i<p_count;i++) {
  1779. X      if (list[i])
  1780. X         free(list[i]);
  1781. X      }
  1782. X   p_count = 0;
  1783. X   }
  1784. X
  1785. Xchar *
  1786. Xprint_ps(tty)
  1787. Xchar *tty;
  1788. X   {
  1789. X   register int i;
  1790. X   register char *check = tty + (strlen(tty) - 2);
  1791. X   register char *p1,*p2;
  1792. X   char *index(), *strcpy();
  1793. X
  1794. X   *buff = '\0';
  1795. X   for(i=0;i<p_count;i++)
  1796. X      if (list[i] && strncmp(check,list[i],2)==0 &&
  1797. X                     (int)(p1 = index(list[i],':')+4)>4) {
  1798. X         if (p2 = index(p1,'\n'))
  1799. X            *p2 = '\0';
  1800. X         strcpy(buff,p1);
  1801. X         if (*p1 != '-')
  1802. X            break;
  1803. X         }
  1804. X   return(buff ? buff : strcpy(buff,"?? unknown ??"));
  1805. X   } 
  1806. X
  1807. X/*****************************************************************************
  1808. X *    print x in binary
  1809. X */
  1810. X
  1811. Xchar *
  1812. Xbinary(x)
  1813. Xint x;
  1814. X   {
  1815. X   register int i;
  1816. X   static char out[33];
  1817. X   int n=32;
  1818. X
  1819. X   out[n+1] = '\0';
  1820. X   for(i=0;i<n+1;i++)
  1821. X      if (x&(1<<i))
  1822. X         out[n-i] = '1';
  1823. X      else
  1824. X         out[n-i] = '0';
  1825. X   for(i=0;out[i]=='0' && i<33;i++);
  1826. X   return(i>0?out+i-1:out);
  1827. X   }
  1828. END_OF_FILE
  1829. # end of 'src/print.c'
  1830. fi
  1831. if test -f 'src/win_make.c' -a "${1}" != "-c" ; then 
  1832.   echo shar: Will not clobber existing file \"'src/win_make.c'\"
  1833. else
  1834. echo shar: Extracting \"'src/win_make.c'\" \(4132 characters\)
  1835. sed "s/^X//" >'src/win_make.c' <<'END_OF_FILE'
  1836. X/*                        Copyright (c) 1987 Bellcore
  1837. X *                            All Rights Reserved
  1838. X *       Permission is granted to copy or use this program, EXCEPT that it
  1839. X *       may not be sold for profit, the copyright notice must be reproduced
  1840. X *       on copies, and credit should be given to Bellcore where it is due.
  1841. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  1842. X */
  1843. X/*    $Header: win_make.c,v 4.1 88/06/21 13:34:54 bianchi Exp $
  1844. X    $Source: /tmp/mgrsrc/src/RCS/win_make.c,v $
  1845. X*/
  1846. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/RCS/win_make.c,v $$Revision: 4.1 $";
  1847. X
  1848. X/* make an alternate window */
  1849. X
  1850. X#include "bitmap.h"
  1851. X#include "font.h"
  1852. X#include "defs.h"
  1853. X#include "window.h"
  1854. X#include "event.h"
  1855. X#include <stdio.h>
  1856. X
  1857. X/* manipulte an alternate (client) window - called by put_window() */
  1858. X
  1859. Xint
  1860. Xwin_make(win,indx)
  1861. XWINDOW *win;            /* window issuing make-call */
  1862. Xint indx;            /* current index into char string (yuk!) */
  1863. X   {
  1864. X   register int *p = W(esc);    /* array of ESC digits */
  1865. X   int buff[10];
  1866. X   WINDOW *win2=win, *insert_win();
  1867. X
  1868. X   switch (W(esc_cnt)) {
  1869. X      case 1:            /*  destroy the window */
  1870. X#ifdef DEBUG
  1871. X         dprintf(N)(stderr,"%s: destroying %d\n",W(tty),p[0]);
  1872. X#endif
  1873. X         if (p[0]<=0 || W(main)->alt == (WINDOW *) 0 ||
  1874. X                  W(main)->alt->num<p[0]) {
  1875. X            break;
  1876. X            }
  1877. X         for (win = W(main)->alt;win!=(WINDOW *) 0; win=W(alt))  {
  1878. X            if (W(num)==p[0])
  1879. X               break;
  1880. X            }
  1881. X         if (win != (WINDOW *) 0) 
  1882. X            W(flags) |= W_DIED;
  1883. X         break;
  1884. X
  1885. X      case 0:        /* goto a new window */
  1886. X         if (W(num)==p[0] || W(main)->alt == (WINDOW *) 0 ||
  1887. X                  W(main)->alt->num<p[0]) {
  1888. X            break;
  1889. X            }
  1890. X         for (win = W(main);win!=(WINDOW *) 0; win=W(alt))  {
  1891. X            if (W(num)==p[0])
  1892. X               break;
  1893. X            }
  1894. X
  1895. X         /* move contents of shell buffer to new window */
  1896. X
  1897. X         if (win != (WINDOW *) 0) {
  1898. X            W(from_fd) = W(to_fd);
  1899. X            win2->from_fd = 0;
  1900. X            W(max) = win2->max - win2->current - indx - 1;
  1901. X            bcopy(win2->buff + win2->current + indx + 1,W(buff),W(max));
  1902. X            W(current) = 0;
  1903. X#ifdef DEBUG
  1904. X            dprintf(N)(stderr,"%s: xfer %d\r\n",W(tty),W(max));
  1905. X#endif
  1906. X            }
  1907. X         break;
  1908. X
  1909. X      case 3:        /* make a new window */
  1910. X         p[4] = -1;
  1911. X         /* no break */
  1912. X      case 4:        /* new window + font (not implemented) */
  1913. X#ifdef DEBUG
  1914. X         dprintf(N)(stderr,"%s: making alternate window\n",W(tty));
  1915. X#endif
  1916. X         if (check_window(p[0],p[1],p[2],p[3],p[4]) == 0 ||
  1917. X                 next_window >= MAXWIN) {
  1918. X            write(ACTIVE(to_fd),"\n",1);
  1919. X            break;
  1920. X            }
  1921. X         if (win!=active)
  1922. X            cursor_off();
  1923. X         ACTIVE_OFF();
  1924. X         if ((active = insert_win((WINDOW *) 0)) == (WINDOW *) 0 ||
  1925. X                     !setup_window(active,font,p[0],p[1],p[2],p[3])) {
  1926. X            fprintf(stderr,"Out of memory for window creation -- bye!\n");
  1927. X            quit();
  1928. X            }
  1929. X
  1930. X         /* next_window++;  (this needs more thought) */
  1931. X
  1932. X         /* make the window */
  1933. X
  1934. X         set_covered(active);
  1935. X         border(active,BLK_BDR,WH_BDR);
  1936. X         CLEAR(ACTIVE(window),BIT_CLR);
  1937. X         ACTIVE_ON();
  1938. X         cursor_on();
  1939. X
  1940. X#ifdef DEBUG
  1941. X         dprintf(N)(stderr,"%s: window created\n",W(tty));
  1942. X#endif
  1943. X         /* fix pointer chain */
  1944. X
  1945. X         ACTIVE(to_fd) =  W(to_fd);
  1946. X         ACTIVE(main) = W(main);
  1947. X         ACTIVE(pid) =  W(pid);
  1948. X         ACTIVE(setid) =  W(setid);
  1949. X         strcpy(ACTIVE(tty),ACTIVE(main)->tty);
  1950. X         ACTIVE(from_fd) = 0;
  1951. X         ACTIVE(alt) =  W(main)->alt;
  1952. X         ACTIVE(main)->alt = active;
  1953. X         if (ACTIVE(alt))
  1954. X            ACTIVE(num) = ACTIVE(alt)->num + 1;
  1955. X         else
  1956. X            ACTIVE(num) = 1;
  1957. X         
  1958. X#ifdef DEBUG
  1959. X         dprintf(N)(stderr,"%s: created num %d\r\n",ACTIVE(tty),ACTIVE(num));
  1960. X#endif
  1961. X         sprintf(buff,"%d\n",ACTIVE(num));
  1962. X         write(ACTIVE(to_fd),buff,strlen(buff));
  1963. X         clip_bad(active);    /* invalidate clip lists */
  1964. X         break;
  1965. X      case 5:        /* nothing */
  1966. X         break;
  1967. X     }
  1968. X   }
  1969. END_OF_FILE
  1970. # end of 'src/win_make.c'
  1971. fi
  1972. echo shar: End of archive 20 \(of 61\).
  1973. cp /dev/null ark20isdone
  1974. MISSING=""
  1975. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
  1976.     21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 \
  1977.     38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 \
  1978.     55 56 57 58 59 60 61 ; do
  1979.     if test ! -f ark${I}isdone ; then
  1980.     MISSING="${MISSING} ${I}"
  1981.     fi
  1982. done
  1983. if test "${MISSING}" = "" ; then
  1984.     echo You have unpacked all 61 archives.
  1985.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1986. else
  1987.     echo You still need to unpack the following archives:
  1988.     echo "        " ${MISSING}
  1989. fi
  1990. ##  End of shell archive.
  1991. exit 0
  1992.