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

  1. Subject:  v17i026:  MGR, Bellcore window manager, Part25/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 26
  7. Archive-name: mgr/part25
  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 25 (of 61)."
  19. # Contents:  demo/misc/ether.c demo/misc/lock.c demo/msg/client.c
  20. #   font-16/U81 src/copyright.c src/get_info.c
  21. # Wrapped by rsalz@papaya.bbn.com on Thu Nov 17 21:05:30 1988
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'demo/misc/ether.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'demo/misc/ether.c'\"
  25. else
  26. echo shar: Extracting \"'demo/misc/ether.c'\" \(7443 characters\)
  27. sed "s/^X//" >'demo/misc/ether.c' <<'END_OF_FILE'
  28. X/*                        Copyright (c) 1987 Bellcore
  29. X *                            All Rights Reserved
  30. X *       Permission is granted to copy or use this program, EXCEPT that it
  31. X *       may not be sold for profit, the copyright notice must be reproduced
  32. X *       on copies, and credit should be given to Bellcore where it is due.
  33. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  34. X */
  35. X/*    $Header: ether.c,v 4.2 88/06/22 14:37:31 bianchi Exp $
  36. X    $Source: /tmp/mgrsrc/demo/misc/RCS/ether.c,v $
  37. X*/
  38. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/misc/RCS/ether.c,v $$Revision: 4.2 $";
  39. X
  40. X/* strip_chart vmstat output version II */
  41. X
  42. X#include "term.h"
  43. X#include <signal.h>
  44. X#include <sgtty.h>
  45. X
  46. XFILE *popen(), *file;
  47. X
  48. X#define INTERVAL    60    /* bar interval (in secs) */
  49. X#define SCROLL        4    /* # of scrolls per window */
  50. X#define MAX        3    /* max number of plots */
  51. X#define FREQ        3    /* update frequency (secs)*/
  52. X#define DELTA        4    /* pixels/update */
  53. X
  54. X#define Min(x,y)    ((x)>(y)?(y):(x))
  55. X#define Max(x,y)    ((x)>(y)?(x):(y))
  56. X#define dprintf        if (debug) fprintf
  57. X
  58. Xchar *labels[] = {        /* graph labels */
  59. X   "Input" , "Output", "Coll."
  60. X   };
  61. X
  62. Xint indx[] = {            /* field indeces into netstat(1) */
  63. X   0, 2, 4
  64. X   };
  65. X
  66. Xint limit[] = {            /* default maximums */
  67. X   15, 15, 3
  68. X   };
  69. X
  70. Xmain(argc,argv)
  71. Xint argc;
  72. Xchar **argv;
  73. X   {
  74. X   register int i;
  75. X   register int x;    /* current plot position */
  76. X   int bar=0;        /* hash mark counter */
  77. X   int back=0;        /* enable background writes */
  78. X   int solid=1;        /* make solid lines */
  79. X   int freq = FREQ;    /* update frequency (secs) */
  80. X   int size;        /* size of label region */
  81. X   int interval;    /* hash mark interval (secs) */
  82. X
  83. X   char host[16];    /* hostname */
  84. X   char title[255];    /* chart title */
  85. X   char line[255];    /* vmstat input buffer */
  86. X   char *fields[20];    /* place for raw input fields */
  87. X   char *sprintf();
  88. X
  89. X   int current[MAX];    /* current data value */
  90. X   int old[MAX];    /* previous data value */
  91. X   int first =1;    /* first time through */ 
  92. X   int clean();
  93. X
  94. X   int f_high, f_wide;        /* font size */
  95. X   int high,wide;        /* window size */
  96. X   int x1;            /* left margin */
  97. X   int x2;            /* title */
  98. X   int y1;            /* title line */
  99. X   int y2;            /* first bar */
  100. X   int scroll;            /* scroll amount */
  101. X   int delta=DELTA;        /* pixels/line */
  102. X   int item;
  103. X   int dummy;
  104. X   int debug=0;
  105. X
  106. X   ckmgrterm( *argv );
  107. X
  108. X   for(i=1;i<argc;i++) {
  109. X      if (strcmp(argv[i],"-d")==0) {
  110. X         debug++;
  111. X         }
  112. X      else if (strncmp(argv[i],"-f",2)==0) {
  113. X         freq = atoi(argv[i]+2);
  114. X         if (freq < 1) freq = 1;
  115. X         if (freq > 120) freq = 120;
  116. X         }
  117. X      else if (strncmp(argv[i],"-m",2)==0) {
  118. X         int max;
  119. X         max = atoi(argv[i]+2);
  120. X         if (max < 1) max = 1;
  121. X         if (max > 999) max = 999;
  122. X         limit[0] = limit[1] = max;
  123. X         limit[2] = (max>=5) ? max/5 : 1;
  124. X         
  125. X         }
  126. X      else
  127. X         fprintf(stderr,"%s: unknown flag %s. Ignored\n",*argv,argv[i]);
  128. X      }
  129. X
  130. X   if ((file = popen(sprintf(line,"netstat %d",freq),"r")) == NULL)
  131. X      exit(1);
  132. X
  133. X   m_setup(M_FLUSH);
  134. X   m_ttyset();
  135. X   m_push(P_EVENT|P_FLAGS);
  136. X   m_setmode(M_ABS);
  137. X
  138. X   signal(SIGINT,clean);
  139. X   signal(SIGTERM,clean);
  140. X
  141. X   system("stty -ctlecho");
  142. X   m_setevent(RESHAPE,"R\fRedrawing...\n");
  143. X   m_setevent(REDRAW,"R\fRedrawing...\n");
  144. X   first = 1;
  145. X
  146. X   while (1) {
  147. X
  148. X      for(size=0,i=0;i<MAX;i++)
  149. X         size = Max(size,strlen(labels[i]));
  150. X
  151. X      /* clear the screen, flush pending input */
  152. X
  153. X      read_it(fileno(m_termin),line);
  154. X
  155. X      /* get font size */
  156. X
  157. X      get_font(&f_wide,&f_high);
  158. X
  159. X      /* get window size */
  160. X
  161. X      get_size(&dummy,&dummy,&wide,&high);
  162. X   
  163. X      if (wide==0 || high==0 || f_wide==0 || f_high==0) {
  164. X         fprintf(stderr,"Can't get window info\n");
  165. X         clean();
  166. X         }
  167. X
  168. X      /* get the title */
  169. X
  170. X      gethostname(host,sizeof(host));
  171. X
  172. X      sprintf(title,"Network statistics for %s in packets/%d seconds",
  173. X              host,freq);
  174. X
  175. X      if (strlen(title)*f_wide > wide)
  176. X         sprintf(title,"%s (pkts/%ds.)",host,freq);
  177. X
  178. X      /* make sure window is big enough */
  179. X
  180. X      if (f_high * (2*MAX+1) > high) {
  181. X         fprintf(stderr,"\fWindow isn't tall enough\n");
  182. X         m_gets(line);
  183. X         continue;
  184. X         }
  185. X      if (f_high * (3*MAX +1) > high)
  186. X         size += 3;
  187. X
  188. X      if (strlen(title)*f_wide > wide || 3*size*f_wide > wide*2) {
  189. X         fprintf(stderr,"\fWindow isn't\nwide enough\n");
  190. X         m_gets(line);
  191. X         continue;
  192. X         }
  193. X
  194. X      /* calculate key positions */
  195. X
  196. X      x1 = (size*f_wide+1);
  197. X      x2 = (wide-strlen(title)*f_wide)/2;
  198. X      y1 = f_high +1;
  199. X      y2 = (high - y1) /MAX;
  200. X      high--;
  201. X
  202. X      m_func(B_SET);
  203. X      m_clear();
  204. X      x = x1;
  205. X      scroll = Max((wide-x1)/SCROLL,10);
  206. X      scroll += scroll%delta;
  207. X
  208. X      if (freq >15)
  209. X         interval = INTERVAL * 10 /freq;
  210. X      else 
  211. X         interval = INTERVAL / freq;
  212. X
  213. X      /* draw form */
  214. X
  215. X      m_moveprint(x2,y1,title);
  216. X
  217. X      for(i=0;i<MAX;i++) {
  218. X         m_moveprint(x1-f_wide,high-i*y2,"0");
  219. X         m_moveprint(x1-f_wide*3,high-(i+1)*y2+f_wide*2+1,
  220. X                     sprintf(line,"%3d",limit[i]));
  221. X         m_moveprint(1,high-i*y2-(y2-f_high)/2,labels[i]);
  222. X         m_line(x1,high-i*y2,wide,high-i*y2);
  223. X         }
  224. X   
  225. X      m_line(0,y1,wide,y1);
  226. X      m_line(x1,y1,x1,high);
  227. X      m_movecursor(x1,0);
  228. X      m_flush();
  229. X
  230. X      /* read the data */
  231. X
  232. X      while (fgets(line,sizeof(line),file) != NULL) {
  233. X         i = parse(line,fields);
  234. X         if (strcmp(*fields,"input")==0) {
  235. X            fgets(line,sizeof(line),file);
  236. X            fgets(line,sizeof(line),file);
  237. X            continue;
  238. X            }
  239. X
  240. X         /* calculate new line position */
  241. X
  242. X         for(i=0;i<MAX;i++) {
  243. X            current[i] = atoi(fields[indx[i]]) *
  244. X                         (y2-3)/limit[i];
  245. X            current[i] = Min(current[i],y2-3) + y2*i + 1;
  246. X
  247. X            if (!first) {
  248. X               m_line(x,high-old[i],x+delta,high-current[i]);
  249. X               if (solid)
  250. X                  m_line(x+delta,high-y2*i,x+delta,high-current[i]);
  251. X               }
  252. X
  253. X            dprintf(stderr,"%s %d->%d, ",labels[i],
  254. X                            high-old[i],high-current[i]);
  255. X            old[i] = current[i];
  256. X            }
  257. X         dprintf(stderr," [%d]\n",high);
  258. X   
  259. X         if (++bar  == interval) {
  260. X            m_line(x,y1,x,high);
  261. X            bar = 0;
  262. X            dprintf(stderr,"---------\n");
  263. X            }
  264. X
  265. X         if (first)
  266. X            first = 0;
  267. X         else
  268. X            x += delta;
  269. X
  270. X         if (x > wide-delta) {
  271. X
  272. X            /* scroll the display */
  273. X
  274. X            x -= scroll;
  275. X            m_func(B_COPY);
  276. X            m_bitcopy(x1+1,y1+1,wide-x1-1,high-y1-1,x1+scroll+1,y1+1);
  277. X            m_func(B_CLEAR);
  278. X            m_bitwrite(wide-scroll,y1+1,scroll,high);
  279. X            m_func(B_SET);
  280. X         
  281. X            dprintf(stderr,"scroll to %d,%d from %d,%d\n",
  282. X                    x1+1,y1+1,x1+scroll+1,y1+1);
  283. X            for(i=0;i<MAX;i++) 
  284. X               m_line(wide-scroll,high-i*y2,wide,high-i*y2);
  285. X            }
  286. X         m_flush();
  287. X         if (read_it(fileno(m_termin),line) && *line == 'R')
  288. X            break;
  289. X         }
  290. X      }
  291. X   }
  292. X
  293. Xclean()            /* clean up on SIGINT */
  294. X   {
  295. X   m_pop(0);
  296. X   pclose(file);
  297. X   m_clear();
  298. X   m_flush();
  299. X   m_ttyreset();
  300. X   exit(1);
  301. X   }
  302. X
  303. Xint read_it(fd,line)    /* non blocking read */
  304. Xint fd;
  305. Xchar *line;
  306. X   {
  307. X   long rd;
  308. X
  309. X   ioctl(fd,FIONREAD,&rd);
  310. X   line[rd] = '\0';
  311. X   if (rd > 0)  {
  312. X      return(read(fd,line,rd));
  313. X      }
  314. X   else
  315. X      return(0);
  316. X   }
  317. END_OF_FILE
  318. # end of 'demo/misc/ether.c'
  319. fi
  320. if test -f 'demo/misc/lock.c' -a "${1}" != "-c" ; then 
  321.   echo shar: Will not clobber existing file \"'demo/misc/lock.c'\"
  322. else
  323. echo shar: Extracting \"'demo/misc/lock.c'\" \(6857 characters\)
  324. sed "s/^X//" >'demo/misc/lock.c' <<'END_OF_FILE'
  325. X/*                        Copyright (c) 1987 Bellcore
  326. X *                            All Rights Reserved
  327. X *       Permission is granted to copy or use this program, EXCEPT that it
  328. X *       may not be sold for profit, the copyright notice must be reproduced
  329. X *       on copies, and credit should be given to Bellcore where it is due.
  330. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  331. X */
  332. X/* ************************************************************ *\
  333. X/* star-trek lock screen (sau/sdh) */
  334. X
  335. X#include <sgtty.h>
  336. X#include <stdio.h>
  337. X#include <pwd.h>
  338. X#include <sys/time.h>
  339. X#include <signal.h>
  340. X#include "bitmap.h"
  341. X
  342. X#define WIDE    BIT_WIDE(display)
  343. X#define HIGH    BIT_HIGH(display)
  344. X#define NICE    10
  345. X
  346. Xstruct passwd *pwd, *getpwuid();
  347. Xstruct timeval poll = {0,50000};
  348. Xstruct sgttyb sg,save;
  349. Xchar buff[100];
  350. Xstatic int dir = 1;
  351. X
  352. Xmain()
  353. X   {
  354. X   int read;
  355. X    int pid;
  356. X    int flip();
  357. X   BITMAP *display = bit_open("/dev/bwtwo0");
  358. X   BITMAP *stash = bit_alloc(WIDE,HIGH,NULL,1);
  359. X
  360. X   if (!(display&&stash)) {
  361. X      printf("Can't initialize the display, sorry\n");
  362. X        exit(1);
  363. X      }
  364. X
  365. X   pwd = getpwuid(getuid());
  366. X
  367. X   signal(SIGINT,SIG_IGN);
  368. X   signal(SIGHUP,SIG_IGN);
  369. X   signal(SIGTERM,SIG_IGN);
  370. X   signal(SIGQUIT,SIG_IGN);
  371. X   signal(SIGTSTP,SIG_IGN);
  372. X
  373. X   gtty(0,&sg);
  374. X   save = sg;
  375. X   sg.sg_flags &= ~(ECHO|RAW);
  376. X   sg.sg_flags |= CBREAK;
  377. X   stty(0,&sg);
  378. X   
  379. X   bit_blit(stash,0,0,WIDE,HIGH,BIT_SRC,display,0,0);
  380. X   bit_blit(display,0,0,WIDE,HIGH,BIT_SET,NULL,0,0);
  381. X   if (NICE > 0)
  382. X      nice(NICE);
  383. X    if ((pid=fork()) == 0) {/* child */
  384. X        signal(SIGALRM,flip);
  385. X        fly(display);
  386. X        }
  387. X   else {
  388. X        while(1) {
  389. X            read = 1;
  390. X            if (select(32,&read,0,0,&poll) && read) {
  391. X                gets(buff);
  392. X                kill(pid,SIGALRM);    /* change directions */
  393. X                if (strcmp(pwd->pw_passwd,crypt(buff,pwd->pw_passwd)) == 0) {
  394. X                    stty(0,&save);
  395. X                    kill(pid,SIGKILL);
  396. X                    while(wait(0)!=pid);
  397. X                    bit_blit(display,0,0,WIDE,HIGH,BIT_SRC,stash,0,0);
  398. X                    exit(0);
  399. X                    }
  400. X                }
  401. X            }
  402. X        }
  403. X    }
  404. X
  405. X/* star trek effect */
  406. X/*
  407. X * porter.c  Steve Hawley 4/3/87
  408. X * rehacked 5/18/1988 for extra speed.
  409. X * re-re hacked 6/20/88 for MGR (SAU)
  410. X * A demo to get stars inspired by Star Trek without
  411. X * using quickdraw, and by addressing the screen directly.
  412. X * this version is roughly 8 times faster than its quickdraw
  413. X * equivalent.
  414. X * In considering the bit drawing routines, remember that
  415. X * on the macintosh, a bit turned on is black, not white.
  416. X */
  417. X
  418. X#define BG_COLOR    4        /* usually blue */
  419. X#define SSIZE    2    /* star size */
  420. X#define MAXZ 500 /* maximum z depth */
  421. X#define NSTARS 256 /* maximum number of stars */
  422. X#define SPEED    6        /* star speed */
  423. X#define SCALE    (short)7    /* for rotator */
  424. X#define COUNT    (short)3    /* for rotator */
  425. X#define ON 1  /* plotting states */
  426. X#define OFF 0
  427. X#define Random() rand()
  428. X
  429. Xshort maxv, maxh; /* display size */
  430. Xshort hmaxv, hmaxh;    /* 1/2 display size */
  431. X
  432. Xstruct st {
  433. X   short x, y, z;
  434. X    short color;
  435. X    short dir;
  436. X   } stars[NSTARS]; /* our galaxy */
  437. X
  438. Xfly (where)
  439. XBITMAP *where;
  440. X{
  441. X        register short i;
  442. X        register struct st *stp;
  443. X
  444. X        init_all(where);     /* set up global variables */
  445. X        for (i=0, stp = stars; i< NSTARS; i++, stp++) {
  446. X                /* initialize galaxy */
  447. X                do {
  448. X                        stp->x = Random();
  449. X                        stp->y = Random();
  450. X                        stp->z = (Random() % MAXZ) + 1;
  451. X                        stp->dir = dir ? COUNT : -COUNT;
  452. X                        stp->color = Random() % 23;
  453. X                                if (stp->color == BG_COLOR)
  454. X                            stp->color++;
  455. X            
  456. X                } while(project(where,stp->x, stp->y, stp->z, stp->color, ON)); /* on screen? */
  457. X        }
  458. X        while (1) { /* loop 'til button */
  459. X                i = NSTARS;
  460. X                stp = stars;
  461. X                do {
  462. X                        project(where,stp->x, stp->y, stp->z, stp->color, OFF); /* turn star off*/
  463. X                        if ((stp->z -= SPEED) <= 0) { /* star went past us */
  464. X                                stp->x = Random();
  465. X                                stp->y = Random();
  466. X                                stp->z = MAXZ;
  467. X                                stp->dir = dir ? COUNT : -COUNT;
  468. X                        }
  469. X                                else {        /* rotate universe */
  470. X                                    cordic(&stp->x,&stp->y,SCALE,stp->dir);
  471. X                                }
  472. X                        if (project(where,stp->x, stp->y, stp->z, stp->color, ON)) {
  473. X                                /* if projection is off screen, get a new position */
  474. X                                stp->x = Random();
  475. X                                stp->y = Random();
  476. X                                stp->z = MAXZ;
  477. X                                stp->dir = dir ? COUNT : -COUNT;
  478. X                        }
  479. X                ++stp;
  480. X                } while(--i);
  481. X        }
  482. X}
  483. X
  484. Xproject(where,x, y, z, col, state)
  485. Xregister BITMAP *where;
  486. Xregister short x, y, z;
  487. Xregister int col;
  488. Xregister short state;
  489. X{
  490. X        
  491. X        /* one-point perspective projection */
  492. X        /* the offsets (maxh/2) and maxv/2) ensure that the
  493. X         * projection is screen centered
  494. X         */
  495. X        x = (x/z) + hmaxh;
  496. X        y = (y/z) + hmaxv;
  497. X        return(xplot(where,x, y, z, col, state));
  498. X
  499. X}
  500. X
  501. Xinit_all(where)
  502. Xregister BITMAP *where;
  503. X{
  504. X   maxv = BIT_HIGH(where);
  505. X   hmaxv = maxv>>1;
  506. X   maxh = BIT_WIDE(where);
  507. X   hmaxh = maxh>>1;
  508. X}       
  509. X
  510. Xxplot(where,x, y, z, col, state)
  511. Xregister BITMAP *where;
  512. Xregister int x, y;
  513. Xregister int z;    /* actually z position */
  514. Xregister int col;
  515. Xint state;
  516. X{
  517. X        register int size = SSIZE;
  518. X        /* are we on the screen? If not, let the caller know*/
  519. X        if (x < 0 || x >= maxh || y < 0 || y >= maxv )
  520. X            return(1);
  521. X
  522. X      if (z > (3*MAXZ/4))
  523. X         size--;
  524. X      else if ( z< (MAXZ/4))
  525. X         size++;
  526. X      bit_blit(where,x,y,size,size, state ?
  527. X        BIT_SRC^BIT_DST | GETCOLOR(col)^GETCOLOR(BG_COLOR) :
  528. X        BIT_SRC | GETCOLOR(BG_COLOR),
  529. X                 0l,0,0);
  530. X        return(0);
  531. X}
  532. X
  533. X/* CORDIC rotator. Takes as args a point (x,y) and spins it */
  534. X/* count steps counter-clockwise.                   1       */
  535. X/*                                Rotates atan( --------- ) */
  536. X/*                                                  scale   */
  537. X/*                                                 2        */
  538. X/* Therefore a scale of 5 is 1.79 degrees/step and          */
  539. X/* a scale of 4 is 3.57 degrees/step                        */
  540. X
  541. Xcordic(x, y, scale, count)
  542. Xshort *x, *y;
  543. Xregister short scale, count;
  544. X
  545. X{
  546. X   register short tempx, tempy;
  547. X
  548. X   tempx = *x;
  549. X   tempy = *y;
  550. X
  551. X   if (count > 0) /* positive count (counter-clockwise) */
  552. X      for (; count; count--){
  553. X         tempx -= (tempy >> scale);
  554. X         tempy += (tempx >> scale); 
  555. X      }
  556. X   else          /* negative count (clockwise) */
  557. X      for (; count; count++){
  558. X         tempx += (tempy >> scale);
  559. X         tempy -= (tempx >> scale);
  560. X      }
  561. X
  562. X   *x = tempx;
  563. X   *y = tempy;
  564. X}
  565. X
  566. Xint flip()
  567. X   {
  568. X   dir = 1-dir;
  569. X    }
  570. END_OF_FILE
  571. # end of 'demo/misc/lock.c'
  572. fi
  573. if test -f 'demo/msg/client.c' -a "${1}" != "-c" ; then 
  574.   echo shar: Will not clobber existing file \"'demo/msg/client.c'\"
  575. else
  576. echo shar: Extracting \"'demo/msg/client.c'\" \(6568 characters\)
  577. sed "s/^X//" >'demo/msg/client.c' <<'END_OF_FILE'
  578. X/*    $Header: client.c,v 4.1 88/06/21 14:02:36 bianchi Exp $
  579. X    $Source: /tmp/mgrsrc/demo/msg/RCS/client.c,v $
  580. X*/
  581. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/msg/RCS/client.c,v $$Revision: 4.1 $";
  582. X
  583. X/*                        Copyright (c) 1987 Bellcore
  584. X *                            All Rights Reserved
  585. X *       Permission is granted to copy or use this program, EXCEPT that it
  586. X *       may not be sold for profit, the copyright notice must be reproduced
  587. X *       on copies, and credit should be given to Bellcore where it is due.
  588. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  589. X */
  590. X/* sample client for testing server (template only) */
  591. X
  592. X#include <stdio.h>
  593. X#include <signal.h>
  594. X#include "term.h"
  595. X#include "do.h"
  596. X
  597. X#define MAX    20    /* max # of servers */
  598. X
  599. Xstruct server {
  600. X   int id;
  601. X   char *name;
  602. X   };
  603. X
  604. Xstruct server servers[MAX];
  605. Xint cnt=0;            /* server count */
  606. Xmain(argc,argv)
  607. Xint argc;
  608. Xchar **argv;
  609. X   {
  610. X   register int i;
  611. X   char *ttyname();
  612. X   char *str_save();
  613. X   int clean();
  614. X   char message[100];
  615. X   char line[100];
  616. X   char args[100];
  617. X   char name[20];
  618. X   int id;
  619. X
  620. X   ckmgrterm( *argv );
  621. X
  622. X   m_setup(M_FLUSH);
  623. X   chmod(ttyname(2),0600);        /* this is not gauranteed */
  624. X   m_push(P_EVENT|P_FLAGS);        /* save old events and flags */
  625. X   signal(SIGTERM,clean);        /* cleanup upon termination */
  626. X   signal(SIGINT,clean);
  627. X   m_setevent(NOTIFY,"client");        /* my name is "client" */
  628. X   m_setevent(ACCEPT,"&%f:%m\r");    /* get messages: &<from>:<message\r */
  629. X   m_setevent(BUTTON_1,"D %n");
  630. X   m_setevent(BUTTON_2,"X %n is id %w");
  631. X   sprintf(message,"%c",C_WHO);
  632. X   m_broadcast(message);        /* ask all servers for their id's */
  633. X   m_flush();
  634. X
  635. X   /* loop, reading lines from keyboard */
  636. X
  637. X   while(m_gets(line) != NULL) {
  638. X      printf("got: %s",line);
  639. X      if (*line == '&') {
  640. X         sscanf(line+1,"%d:%s %[^\n]", &id,message,args);
  641. X         switch (*message) {
  642. X            case S_HI:            /* received server announcement */
  643. X               printf("Server %d (%s) started [%s]\n",id,message,args);
  644. X               install(args,id);
  645. X               break;
  646. X
  647. X            case S_BYE:            /* a server died */
  648. X               printf("Server %d died\n",id);
  649. X               for(i=0;i<cnt;i++)
  650. X                  if (servers[i].id == id) {
  651. X                     printf("server %s (%d) removed from %d\n",
  652. X                            servers[i].name,servers[i].id,i);
  653. X                     servers[i].id = 0;
  654. X                     free(servers[i].name);
  655. X                     break;
  656. X                     }
  657. X                  if (i+1 == cnt && cnt>0)
  658. X                     cnt--;
  659. X               break;
  660. X
  661. X            case S_REPLY:            /* a server reply message */
  662. X               printf("Server %d replied %s\n",id,message);
  663. X               switch (message[1]) {
  664. X                  case R_WHO:            /* who are you */
  665. X                     install(args,id);
  666. X                     break;
  667. X                  case R_RCVD:            /* received command */
  668. X                     printf("Command received\n");
  669. X                     break;
  670. X                  case R_DO:            /* working on command */
  671. X                     printf("Command is executing\n");
  672. X                     break;
  673. X                  case R_DONE:            /* command completed */
  674. X                     printf("Command completed\n");
  675. X                     break;
  676. X                  case R_BAD:            /* command rejected */
  677. X                     printf("Command rejected\n");
  678. X                     break;
  679. X                  case R_UNKWN:            /* unknown command */
  680. X                     printf("Command unknown\n");
  681. X                     break;
  682. X                  default:
  683. X                     printf("Unknown server reply\n");
  684. X                  }
  685. X               break;
  686. X
  687. X            case C_WHO:            /* some other client sent this */
  688. X               printf("got a client WHO message\n");
  689. X               break;
  690. X
  691. X            default:
  692. X               printf("non-server message from %d (%s)\n",id,message);
  693. X               break;
  694. X            }
  695. X         }
  696. X
  697. X      /* not a message, must be a button hit or kbd */
  698. X
  699. X      else {
  700. X         switch (*line) {
  701. X            case 'L':            /* list servers */
  702. X               for(i=0;i<cnt;i++) {
  703. X                  if (servers[i].id > 0)
  704. X                     printf("%d) server %d is [%s]\n",
  705. X                             i,servers[i].id, servers[i].name);
  706. X                  }
  707. X               break;
  708. X
  709. X            case 'S':            /* put file in snarf buffer */
  710. X               m_snarf(line+2);
  711. X               printf("Putting->snarf buffer: %s\n",line+2);
  712. X               break;
  713. X
  714. X            case 'D':            /* send command to server */
  715. X               sscanf(line,"%*s %s %[^\n]", name,args);
  716. X               for(i=0;i<cnt;i++) 
  717. X                  if (servers[i].id > 0 && strcmp(servers[i].name,name)==0) {
  718. X                     printf("sending [%s] to %s (%d)\n",
  719. X                             args,name,servers[i].id);
  720. X                     sprintf(message,"%c %s",C_DO,args);
  721. X                     m_sendto(servers[i].id,message);
  722. X                     break;
  723. X                     }
  724. X               if (i==cnt)
  725. X                  printf("Can't find server [%s]\n",name);
  726. X               break;
  727. X
  728. X            case '?':            /* list commands */
  729. X               printf("L        list servers\n");
  730. X               printf("D <server> <command>        do a command\n");
  731. X               printf("?        ask for help\n");
  732. X               break;
  733. X
  734. X            default:
  735. X               printf("Not a message: %s\n",line);
  736. X            }
  737. X         }
  738. X      m_flush();
  739. X      }
  740. X   }
  741. X   
  742. X/*    Clean up and exit */
  743. X
  744. Xclean(n)
  745. Xint n;
  746. X   {
  747. X   m_popall();
  748. X   exit(n);
  749. X   }
  750. X
  751. X/* save a copy of string s */
  752. X
  753. Xchar *
  754. Xstr_save(s)
  755. Xchar *s;
  756. X   {
  757. X   char *malloc(), *strcpy();
  758. X   return(strcpy(malloc(strlen(s)+1),s)); 
  759. X   }
  760. X
  761. X/* install a server */
  762. X
  763. Xint
  764. Xinstall(name,id)
  765. Xchar *name;
  766. Xint id;
  767. X   {
  768. X   register int i,spot = -1;
  769. X
  770. X   for(i=0;i<cnt;i++)
  771. X      if (servers[i].id == id) {
  772. X         printf("server id %d already installed at %d\n",id,i);
  773. X         if (strcmp(name,servers[i].name) != 0) {
  774. X            free(servers[i].name);
  775. X            servers[i].name = str_save(name);
  776. X            }
  777. X         return(i);
  778. X         }
  779. X      else if (spot == -1 && servers[i].id == 0)
  780. X         spot = i;
  781. X
  782. X
  783. X      if (spot != -1) {
  784. X         servers[spot].id = id;
  785. X         servers[spot].name = str_save(name);
  786. X         printf("server %s (%d) installed at %d\n",
  787. X                name,id,spot);
  788. X         }
  789. X      else if (cnt < MAX) {
  790. X         servers[cnt].id = id;
  791. X         servers[cnt].name = str_save(name);
  792. X         printf("server %s (%d) installed at %d\n",
  793. X                name,id,cnt);
  794. X         cnt++;
  795. X         }
  796. X   return(i);
  797. X   }
  798. END_OF_FILE
  799. # end of 'demo/msg/client.c'
  800. fi
  801. if test -f 'font-16/U81' -a "${1}" != "-c" ; then 
  802.   echo shar: Will not clobber existing file \"'font-16/U81'\"
  803. else
  804. echo shar: Extracting \"'font-16/U81'\" \(7749 characters\)
  805. sed "s/^X//" >'font-16/U81' <<'END_OF_FILE'
  806. Xbegin 644 81.fnt
  807. XM%@X9!8  __@,    .                 #        !X         # #__P
  808. XM                          P!C &##,  8#P#@ !PX              .
  809. XM#\ X ?P'\ ,#_\'\/_X/@'\            #\   " _X!_#_P__O_X?PP!A^
  810. XM  &P!L # &X!A_#_P'\/_ ?P?_L ; &P!L 9 "__@'YP ?@ $    $      
  811. XM                                                        #@,!
  812. XMP    ![_^ P   #\                 > #      /X         , /_^  
  813. XM                        # &, 8,,P.!@[@?  .!P              P?
  814. XMX'@'_Q_\!P/_Q_\__C_A_\            ?X   <#_\?_/_S_^__G_S &'X 
  815. XM ; .P . [@&?_/_Q_\__'_Q_^P!L ; &P!D +_^ ?C !^  X    P       
  816. XM            '      #                                   8 P!@
  817. XM    /__X#    ?X         >      #\ ,      PP         8!@ 8   
  818. XM         (             , 8P!@Q_A\,#'!\  P#              '#AT
  819. XMV 8#& P& P & P .,&& P           #AP  !P, Q@,P#, #  8#, 8&  !
  820. XML!S  \'O 9@,P#& S ,8# ,# &8#, 9@,8!@ X!@.  8 'P   &         
  821. XM&   #P  8  < !P8  ,                  P               # # #  
  822. XM  !S__@,   #C@        #\   @_ /P P      !@    !P& Q@& !@    
  823. XM        @             P!C ,&/_,8P8,#P & &              8<#V8
  824. XM# &P!@P#  P!@ Q@,P!@           <#@  /@P!L ; &P , # &P!@8  &P
  825. XM., #X^\!L ; &P!L ; & P, 9@,P!F Q@& # & 8 !@ [@   X  !@     8
  826. XM   ?  !@ !P '!@  P                 #                , , ,   
  827. XM '/_^ P   <&         (X# &/_!M@#       &     ?P8#& 8 &      
  828. XM      '  !F         # &, P9\^QF!@P'  8 8             #A@/!@,
  829. XM ; &# , # & #& S &           !@&   V# &P!L ;  P , ; &!@  ;!P
  830. XMP -W;8&P!L ; &P!L 8# P!F S &,&# P 8 8!P & ''   #P  &     !@ 
  831. XM #   &     <&  #                  ,                8 P!@    
  832. XM8/_X#   !@8         A@. YP<.W , '@    8    #CA@,,#  8       
  833. XM     <  >>         , 8P?_VS;&8'& 8 !@!@ ,           ,& X&  !
  834. XM@ 88 P ,   88#, 8             8  #8, ;  P!L #  P , 8&  !L.# 
  835. XM S9M@; &P!L ; &P  ,# &,&, 8P8,# #@!@#  8 X.   /@  8     &   
  836. XM,   8      8  ,                  P               !@# &    !@
  837. XM__@,  #,#          # <'& 0S, P!_@   !@    <'& PP, !@        
  838. XM   #X '@>         P!C!__;,'S .X#  & & !X ,        !P8'@8  & 
  839. XM#!@#  P  !@P8P!@            !@_ 8PP!L # &P , #  P!@8  &QP, #
  840. XM'&S!L ; &P!L ;   P, 8P8P!AC 88 , & . !@' <   ^ _A@     8   P
  841. XM  !@     !@  P&      &         #                & , 8    &#_
  842. XM^ P!X8P, P   #X/PP, XX< ',[__,S    &!__^!@,8##_P &!X        
  843. XM 8=P!X >   @ 0  # &,!@Q\P., > (  X <### P        &!@^!@  P ,
  844. XM,,, #   ,#WA@.#@    &  &   ./_!C# &P , ;  P , # &!@  ;. P ,(
  845. XM;,&P!L ; &P!L  # P!C!C &&,!A@!@ 8 8 & X P  !P'_&/ /X#Q@_ # #
  846. XMQF/ #   &#@# ;G&?@/P8\ \9C@#^!_Q@&8!F 9 "8!G_X 8 P!@    X/_X
  847. XM# /QF!@'@   \#__ 8!W \ 8QO_]C&    8?__^& Q@,'^  8?X"$ P  P #
  848. XM#C@>  >'_[ #   ,   &##S !@'P   #@!P.,<#         X&'8&  & !@P
  849. XMPP ,   P#X'CX? #@ !X  >  !Q@.&,, S  P!L #  P , 8&  !MP#  PAL
  850. XM8; &P#, ; ,8  ,# &&,, 8-@#, . !@!P 8        P&;_#_P_V/_!_P_V
  851. XM;_ ,  P8< ,!^^;_#_QO\/]F_@?\'_& 9@&8!F 9@&?_@# # #    # __@,
  852. XM!AL8, S   ' ,SP!@#X \!#" P$,(X<#YC@  <8#& P88!_C P88&  !@ 8<
  853. XM''@  >?_L ,   P   8,'\ & _    . ' \SP,        # 8Y@8  P!\&##
  854. XM_PQP & ' ']A\ ?  >   >  ., <P8__, # &_^/_C  __@8  &^ , # &QA
  855. XML ;_\P!O_Q_X P, 88PP!@^ /P P & # !@       # 9X,,!C!XP,'_#!Y\
  856. XM, P #!C@ P&,9X.,#'@PP>?'# 8# 8!G Y@&<#F 8 , < , .    ,#_^0PD
  857. XM#QAP#,/_\8 C& & ' #\ , # PPWSX?^<   Y@,8#!A@'^>'C PP  #'_[P>
  858. XM>  !X  8!@  #   #!@/X P'.    X < _\ P        <!G&!@ & 'P8,/_
  859. XMS?P 8!_ '&'P!\ '@?_@> !PQXS!C_\P , ;_X_^, #_^!@  ;P P , ;#&P
  860. XM!O_# &_\!_P# P!AC# &#X > &  8 . &         !G 9@&8#F 8# 8#G 8
  861. XM#  ,&< # 8QG 9@&<!F YP,,!@,!@&,#& 8X<8!@!@!P P X <! P/_YC&P.
  862. XM&#P88__S  ,8 \ < _X P ,#__QXS [@  !V Q@,#,  9,R8!F   &?_G!P>
  863. XM  >  !@&   ,   ,& SP# X<   #@!P!_@#        !@&X8&  P !C P #/
  864. XMCP# >/  8. 'P!X!_^ > .#/[,&, S  P!L #  P/L 8&  !O@#  P!L,; &
  865. XMP , ; 8 # ,# ,(8-@ P X !@ 8 8         >8!F !@&8!@,!@&8!@,
  866. XM  P;@ ,!C&8!F 9@&8!F  P  P& 8X<8!ASA@& , # # # #X$# __G,[ 8X
  867. XM#AA@ #, !A@'P!P'!P#  P/__##8!L   #8#& P,P !L>/______\!@.. > 
  868. XM'@?_C P   P   P8#/@8#AS   . ' #\/_\  ?_@  . ?!@8 &  #,#  &X#
  869. XM ,!@, !@  . >     >!P,QM_\P!L # &P , # ^P!@8  &W , # &P9L ; 
  870. XM P!L!@ & P, 8-@PAAC # #  & !P!@        ?Y@&8 & 9_^ P& 9@& P 
  871. XM#!^  P&,9@&8!F 9@&8 #_@# 8!AAA@&#\& 8!@ & , 8 ?PP,#_^,S,!C@'
  872. XM,#  ,_@&& [ '@P# , # PP\,-@&P   -@,8# S  &PP_______P, =P >!X
  873. XM!_^,#   #   /_X,V!G.#L   8 8 ?X__P !_^   P!X&!@ P  ,__@ ; &!
  874. XM@, 8 &    !X    !X& S&W_S &P , ;  P , ; &!@  ;. P , ;!FP!L #
  875. XM &P#  8# P!@V#'&&, , 8  8 # &        /YF 9@ 8!G_X# 8!F 8#  ,
  876. XM'\ # 8QF 9@&8!F 9@ '_ ,!@&'.& 8'@8!@,  8 P!@!GF!P/_X[<P&. <P
  877. XM,  S  88'& 6# , P ,!#"PPV ;    V Q@,!X  ;'C8!F   &?_@^  >>  
  878. XM  88       __FS8,^X.P  !@!@#_P#        ' ' 8& &   ;_^ !L 8& 
  879. XMP!@ 8    !X!_^ > 8#/^8#, ;  P!L #  P!L 8&  !L<#  P!L#; &P , 
  880. XM; , !@,# &!P,^8P8 P#@ !@ . 8       !P&8!F !@&8  ,!@&8!@,  P<
  881. XMX ,!C&8!F 9@&8!F   & P& 8,P8Q@_!@&!@ !@# & ,/X& __AMC XX!V 8
  882. XM #, !@PX8!8, P#   &,;'C8!N   '8#& P'@ !DS(P,,   Q_^!P  9@   
  883. XM!A@      !@P?/@V/@>   & & \SP,      X 8 \!@8 P P!@## &P!@P# 
  884. XM&P!@X   !X'_X'@  ,?Q@,P!L ; &P , # &P!@8# &PX, # &P-L ;  P-L
  885. XM S & P, 8' W=C!@# ,  &  8!@       & 9@&8 & 9@  P& 9@& P #!AP
  886. XM P&,9@&8!F 9@&8   8# 8!@_!GF'.& 8,  & , 8 @? 8#_^#\$#S@'8!@ 
  887. XM 8 ,#' P%@X' ,   ,S'SY@,<   Y@,<' >  &>'AA@8  &!@ '     !_^#
  888. XM,       &# _\&8W!X   8 8#C' P X   'P#@#P.!@& # & ,, ; &# , ;
  889. XM &'P X !X  !X   X . [ &P!L ;  P , ; &!@, ;!PP , ; >P!L # ^P#
  890. XM, 8# P!@<#X^8# ,!@  8 !P&        8#G 9@&8#F 8# 8#F 8#  ,&#@#
  891. XM 8QF 9@&<!F Y@ ,!@,!@.!X&S8X<8#A@  P P P" X!@/_X/P8;/@[ #  !
  892. XMP P,8# >!XX P/_\?X.'##@X  '& PXX P  8P,"$ P  P,  (     '_X,P
  893. XM   ,   P8!_@9C>/P   P# ,,,# 'P   ? , +AP& P & P P8#& P8 8#& 
  894. XMP? 'P !X  >  <!P'P!L Q@,P#, #  8#, 8& 8#,#C  P!L!Y@,P &!S ,8
  895. XM# ,!@, @/!Y@, P.  !@ # 8       !@>>## 8P>,!@, P>8!@,  P8' ,!
  896. XMC&8!F 9X,,'F  P& P##X'@>'G XP^,  # # #    & __@> _'__, ,  #P
  897. XM# ; & P'_@# __P>   /\!___X8#!_ # __A_@      !@  @'_Y_^   >  
  898. XM  P  #!@#,##X_S   #@< !X , ?   !\!P '^'_C_^?_ #!_\?_!@!_\?_!
  899. XM\ ?  !@ !@ !P#_[ &__'_S_\__L !_\P!A^!_\P'/_[ &P#G_S  ?_L 9_\
  900. XM P'_P" X#L 8# __@'X .?@       #_9O\/_#_8_\ P#_9@& P #!@. P&,
  901. XM9@&,#&_P_V8 !_P!\/]@,!P.8!C_9_^ & , 8    8#_^ P!X'/X@ 0  #X,
  902. XM!L <  'X ,        /@!__^!@,!P ,#__!X            ?_G_X   P   
  903. XM#   ,& ,P,' ^    '#@ #  P \   #@&  /P?^/_X?P ,!_ ?P& !_ ?P#@
  904. XM \        ' #^, ;_@'\/_#_^P !_# &'X!_# ,__L ; .'\,  ?WP!A_ #
  905. XM '\ (# &P!@,#_^ ?@ 9^        'YF/ /X#Q@_@# #QF 8#  ,& 8# 8QF
  906. XM 8_\8\ \9@ #^ #P/& P& 9 "#QG_X . P'    !@/_X    ,           
  907. XM                                                            
  908. XM                        !P                                 !
  909. XMP                                                   ,       
  910. XM                                           &      P         
  911. XM!_!@  !@                 &     #     #, __@    P            
  912. XM                                                            
  913. XM                       &                                  & 
  914. XM                                                            
  915. XM                                          8     #           
  916. XM &   &                  8     ,     ,P#_^    #              
  917. XM                                                            
  918. XM                      P                                  P  
  919. XM                                                            
  920. XM                    /__                ,#      ,            
  921. XM8   8                ,#      P     S /_X    ,               
  922. XM                                                            
  923. XM                    "                                  "    
  924. XM                                                            
  925. XM                   __\                _\     /@           !@
  926. XM  !@                _\     #     !\ __@    P                
  927. XM                                                            
  928. XM                                                            
  929. XM                                                            
  930. XM                                    !_      \            &  
  931. X: &                !_      ,     #@  
  932. Xend
  933. END_OF_FILE
  934. # end of 'font-16/U81'
  935. fi
  936. if test -f 'src/copyright.c' -a "${1}" != "-c" ; then 
  937.   echo shar: Will not clobber existing file \"'src/copyright.c'\"
  938. else
  939. echo shar: Extracting \"'src/copyright.c'\" \(7128 characters\)
  940. sed "s/^X//" >'src/copyright.c' <<'END_OF_FILE'
  941. X/*                        Copyright (c) 1988 Bellcore
  942. X *                            All Rights Reserved
  943. X *       Permission is granted to copy or use this program, EXCEPT that it
  944. X *       may not be sold for profit, the copyright notice must be reproduced
  945. X *       on copies, and credit should be given to Bellcore where it is due.
  946. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  947. X */
  948. X/*    $Header: copyright.c,v 4.3 88/07/11 13:46:06 sau Exp $
  949. X    $Source: /tmp/mgrsrc/src/RCS/copyright.c,v $
  950. X*/
  951. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/RCS/copyright.c,v $$Revision: 4.3 $";
  952. X
  953. X/* flash a copyright notice at Mgr startup */
  954. X
  955. X#include <sys/time.h> 
  956. X#include <sys/signal.h>
  957. X#include "bitmap.h"
  958. X#include "copyright.h"
  959. X
  960. X#define SSIZE    3        /* star size */
  961. X
  962. X#define BG_COLOR        4    /* background color */
  963. X#define LOGO_COLOR    2    
  964. X#define CR_COLOR        5    /* copyright color */
  965. X
  966. Xstatic BITMAP *logo[] =
  967. X    { &lb_0, &lb_1, &lb_2, &lb_3, &lb_4, &lb_5, &lb_6, &lb_7};
  968. X
  969. Xstatic struct timeval delay = {
  970. X   (long) 0, (long) 120000
  971. X   };
  972. X
  973. X/* for "star trek" clip areas */
  974. X
  975. Xstruct rect {
  976. X    short x1,y1;
  977. X    short x2,y2;
  978. X    }c1,c2;
  979. X
  980. Xcopyright(where)
  981. XBITMAP *where;    /* where to blast the copyright */
  982. X    {
  983. X    BITMAP *notice = &cr;
  984. X    int x = (BIT_WIDE(where)-BIT_WIDE(notice))/2;
  985. X    int y = BIT_HIGH(where)/2;
  986. X    int high = BIT_HIGH(logo[0]);
  987. X    int wide = BIT_WIDE(logo[0]);
  988. X    int mask = 1;        /* select mask (1 == kbd) */
  989. X    int pid;                /* pid of "startrek" program */
  990. X    register int i;
  991. X    char c;
  992. X
  993. X    c1.x1 = x - SSIZE;
  994. X    c1.y1 = y - SSIZE;
  995. X    c1.x2 = BIT_WIDE(notice) + x;
  996. X    c1.y2 = BIT_HIGH(notice) + y;
  997. X
  998. X    bit_blit(where,0,0,BIT_WIDE(where),
  999. X            BIT_HIGH(where),BIT_SRC|GETCOLOR(BG_COLOR),0l,0,0);
  1000. X    bit_blit(where,x,y,BIT_WIDE(notice),BIT_HIGH(notice),
  1001. X            BIT_SRC^BIT_DST|GETCOLOR(BG_COLOR)^GETCOLOR(CR_COLOR),
  1002. X            notice,0,0);
  1003. X
  1004. X    x = (BIT_WIDE(where)-wide)/2;
  1005. X    y = y - high - BIT_HIGH(notice);
  1006. X
  1007. X    c2.x1 = x - SSIZE;
  1008. X    c2.y1 = y - SSIZE;
  1009. X    c2.x2 = wide + x;
  1010. X    c2.y2 = high + y;
  1011. X
  1012. X    /* kick off stars */
  1013. X
  1014. X    if ((pid=fork()) == 0) /* child */
  1015. X        fly(where,c1,c2);
  1016. X   else {
  1017. X        for(i=0;select(32,&mask,0,0,&delay) <= 0;i++,mask=1)
  1018. X            bit_blit(where,x,y,wide,high,
  1019. X            BIT_SRC|GETCOLOR(BG_COLOR),
  1020. X            logo[i%8],0,0);
  1021. X        read(0,&c,1);
  1022. X        kill(pid,SIGTERM);
  1023. X        while(wait(0)!=pid);
  1024. X        }
  1025. X    }
  1026. X
  1027. X/* star trek effect */
  1028. X
  1029. X
  1030. X/*
  1031. X * porter.c  Steve Hawley 4/3/87
  1032. X * rehacked 5/18/1988 for extra speed.
  1033. X * re-re hacked 6/20/88 for MGR (SAU)
  1034. X * A demo to get stars inspired by Star Trek without
  1035. X * using quickdraw, and by addressing the screen directly.
  1036. X * this version is roughly 8 times faster than its quickdraw
  1037. X * equivalent.
  1038. X * In considering the bit drawing routines, remember that
  1039. X * on the macintosh, a bit turned on is black, not white.
  1040. X */
  1041. X
  1042. X#define MAXZ 500 /* maximum z depth */
  1043. X#define NSTARS 256 /* maximum number of stars */
  1044. X#define SPEED    8        /* star speed */
  1045. X#define SCALE    (short)6    /* for rotator */
  1046. X#define COUNT    (short)3    /* for rotator */
  1047. X#define ON 1  /* plotting states */
  1048. X#define OFF 0
  1049. X#define Random() rand()
  1050. X
  1051. Xshort maxv, maxh; /* display size */
  1052. Xshort hmaxv, hmaxh;    /* 1/2 display size */
  1053. X
  1054. Xstruct st {
  1055. X        short x, y, z;
  1056. X    short color;
  1057. X        } stars[NSTARS]; /* our galaxy */
  1058. X
  1059. Xfly (where,clip1,clip2)
  1060. XBITMAP *where;
  1061. Xstruct rect clip1, clip2;        /* "holes" in galaxy */
  1062. X{
  1063. X        register short i;
  1064. X        register struct st *stp;
  1065. X
  1066. X        init_all(where);     /* set up global variables */
  1067. X        for (i=0, stp = stars; i< NSTARS; i++, stp++) {
  1068. X                /* initialize galaxy */
  1069. X                do {
  1070. X                        stp->x = Random();
  1071. X                        stp->y = Random();
  1072. X                        stp->z = (Random() % MAXZ) + 1;
  1073. X                        stp->color = Random() % 23;
  1074. X                                if (stp->color == BG_COLOR)
  1075. X                            stp->color++;
  1076. X            
  1077. X                } while(project(where,stp->x, stp->y, stp->z, stp->color, ON,clip1,clip2)); /* on screen? */
  1078. X        }
  1079. X        while (1) { /* loop 'til button */
  1080. X                i = NSTARS;
  1081. X                stp = stars;
  1082. X                do {
  1083. X                        project(where,stp->x, stp->y, stp->z, stp->color, OFF,clip1,clip2); /* turn star off*/
  1084. X                        if ((stp->z -= SPEED) <= 0) { /* star went past us */
  1085. X                                stp->x = Random();
  1086. X                                stp->y = Random();
  1087. X                                stp->z = MAXZ;
  1088. X                        }
  1089. X                                else {        /* rotate universe */
  1090. X                                    cordic(&stp->x,&stp->y,SCALE,COUNT);
  1091. X                                }
  1092. X                        if (project(where,stp->x, stp->y, stp->z, stp->color, ON,clip1,clip2)) {
  1093. X                                /* if projection is off screen, get a new position */
  1094. X                                stp->x = Random();
  1095. X                                stp->y = Random();
  1096. X                                stp->z = MAXZ;
  1097. X                        }
  1098. X                ++stp;
  1099. X                } while(--i);
  1100. X        }
  1101. X}
  1102. X
  1103. Xproject(where,x, y, z, col, state,clip1,clip2)
  1104. Xregister BITMAP *where;
  1105. Xregister short x, y, z;
  1106. Xregister int col;
  1107. Xregister short state;
  1108. Xstruct rect clip1, clip2;
  1109. X{
  1110. X        
  1111. X        /* one-point perspective projection */
  1112. X        /* the offsets (maxh/2) and maxv/2) ensure that the
  1113. X         * projection is screen centered
  1114. X         */
  1115. X        x = (x/z) + hmaxh;
  1116. X        y = (y/z) + hmaxv;
  1117. X        return(xplot(where,x, y, col, state,clip1,clip2));
  1118. X
  1119. X}
  1120. X
  1121. Xinit_all(where)
  1122. Xregister BITMAP *where;
  1123. X{
  1124. X   maxv = BIT_HIGH(where);
  1125. X   hmaxv = maxv>>1;
  1126. X   maxh = BIT_WIDE(where);
  1127. X   hmaxh = maxh>>1;
  1128. X}       
  1129. X
  1130. Xxplot(where,x, y, col, state,clip1,clip2)
  1131. Xregister BITMAP *where;
  1132. Xregister int x, y;
  1133. Xregister int col;
  1134. Xint state;
  1135. Xstruct rect clip1, clip2;
  1136. X{
  1137. X        register short *line, b;
  1138. X        
  1139. X        /* are we on the screen? If not, let the caller know*/
  1140. X        if (x < 0 || x >= maxh || y < 0 || y >= maxv )
  1141. X            return(1);
  1142. X        if (!(x < clip1.x1 || x >= clip1.x2 || y < clip1.y1 || y >= clip1.y2 ))
  1143. X            return(0);
  1144. X        if (!(x < clip2.x1 || x >= clip2.x2 || y < clip2.y1 || y >= clip2.y2 ))
  1145. X            return(0);
  1146. X
  1147. X        bit_blit(where,x,y,SSIZE,SSIZE, state ?
  1148. X        BIT_SRC^BIT_DST | GETCOLOR(col)^GETCOLOR(BG_COLOR) :
  1149. X        BIT_SRC | GETCOLOR(BG_COLOR),
  1150. X                 0l,0,0);
  1151. X        return(0);
  1152. X}
  1153. X
  1154. X/* CORDIC rotator. Takes as args a point (x,y) and spins it */
  1155. X/* count steps counter-clockwise.                   1       */
  1156. X/*                                Rotates atan( --------- ) */
  1157. X/*                                                  scale   */
  1158. X/*                                                 2        */
  1159. X/* Therefore a scale of 5 is 1.79 degrees/step and          */
  1160. X/* a scale of 4 is 3.57 degrees/step                        */
  1161. X
  1162. Xcordic(x, y, scale, count)
  1163. Xshort *x, *y;
  1164. Xregister short scale, count;
  1165. X
  1166. X{
  1167. X   register short tempx, tempy;
  1168. X
  1169. X   tempx = *x;
  1170. X   tempy = *y;
  1171. X
  1172. X   if (count > 0) /* positive count (counter-clockwise) */
  1173. X      for (; count; count--){
  1174. X         tempx -= (tempy >> scale);
  1175. X         tempy += (tempx >> scale); 
  1176. X      }
  1177. X   else          /* negative count (clockwise) */
  1178. X      for (; count; count++){
  1179. X         tempx += (tempy >> scale);
  1180. X         tempy += (tempx >> scale);
  1181. X      }
  1182. X
  1183. X   *x = tempx;
  1184. X   *y = tempy;
  1185. X}
  1186. END_OF_FILE
  1187. # end of 'src/copyright.c'
  1188. fi
  1189. if test -f 'src/get_info.c' -a "${1}" != "-c" ; then 
  1190.   echo shar: Will not clobber existing file \"'src/get_info.c'\"
  1191. else
  1192. echo shar: Extracting \"'src/get_info.c'\" \(7612 characters\)
  1193. sed "s/^X//" >'src/get_info.c' <<'END_OF_FILE'
  1194. X/*                        Copyright (c) 1987 Bellcore
  1195. X *                            All Rights Reserved
  1196. X *       Permission is granted to copy or use this program, EXCEPT that it
  1197. X *       may not be sold for profit, the copyright notice must be reproduced
  1198. X *       on copies, and credit should be given to Bellcore where it is due.
  1199. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  1200. X */
  1201. X/*    $Header: get_info.c,v 4.3 88/08/22 11:42:35 sau Exp $
  1202. X    $Source: /tmp/mgrsrc/src/RCS/get_info.c,v $
  1203. X*/
  1204. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/RCS/get_info.c,v $$Revision: 4.3 $";
  1205. X
  1206. X/* return info to shell */
  1207. X
  1208. X#include "bitmap.h"
  1209. X#include "font.h"
  1210. X#include "defs.h"
  1211. X#include "menu.h"
  1212. X#include "event.h"
  1213. X#include <stdio.h>
  1214. X#include "window.h"
  1215. X
  1216. X/*    BUTTON_SYS is never reported as a possible button setting. */
  1217. X#define    RPT_BUTTON()    (button_state == BUTTON_SYS ? 0 : button_state )
  1218. X
  1219. Xget_info(win,window,text)
  1220. Xregister WINDOW *win;            /* window info is about */
  1221. XBITMAP *window;                /* window's bitmap data */
  1222. XBITMAP *text;                /* window's text region */
  1223. X   {
  1224. X   int cnt = W(esc_cnt);        /* # of leading ESC #'s */
  1225. X   int count;                /* whatever */
  1226. X   char font_buff[MAX_PATH];        /* space to store a path name */
  1227. X   char coords[1024];            /* space for return value */
  1228. X   register WINDOW *win2;        /* generic window pntr */
  1229. X   struct font *Get_font();
  1230. X
  1231. X   if (cnt == 1) {        /* info about spot */
  1232. X      for(win2=active;win2!=(WINDOW *) 0;win2=win2->next)
  1233. X         if (mousein(W(esc)[0],W(esc)[1],win2,1))
  1234. X            break;
  1235. X      if (win2 != (WINDOW *) 0)
  1236. X         sprintf(coords,"%s %s %d %d\n",
  1237. X                  win->tty+strlen(win->tty)-2,
  1238. X                  win2->tty+strlen(win2->tty)-2,win2->num,win2->pid);
  1239. X      else
  1240. X         sprintf(coords,"\n");
  1241. X      Write(W(to_fd),coords,strlen(coords));
  1242. X      return;
  1243. X      }
  1244. X      
  1245. X#ifdef DEBUG
  1246. X   dprintf(i)(stderr,"%s: getting info %d\r\n",W(tty),*W(esc));
  1247. X#endif
  1248. X   switch (W(esc)[0]) {
  1249. X      case G_TERMCAP:    /* send termcap entry back to shell */
  1250. X           {
  1251. X           int lines = T_HIGH/FSIZE(high);
  1252. X           int cols  = T_WIDE/FSIZE(wide);
  1253. X           sprintf(coords,"%s:am:li#%d:co#%d:bs:cl=^L:ce=\\E%c:cd=\\E%c:cm=\\E%%r%%d%c%%d%c:al=\\E%c:dl=\\E%c:ic=\\E%c:dc=\\E%c:im=:ta=^I:up=\\E%c:do=\\E%c:nd=\\E%c:ku=\\E[A:kd=\\E[B:kr=\\E[C:kl=\\E[D:so=\\E%c:se=\\E%c:vs=\\E%c:ve=\\E%c:\n",
  1254. X                   C_NAME,lines,cols,E_CLEAREOL,E_CLEAREOS,
  1255. X                   E_SEP1,E_CUP,E_ADDLINE,E_DELETELINE,E_ADDCHAR,E_DELETECHAR, 
  1256. X                   E_UPLINE,E_DOWN,E_RIGHT,E_STANDOUT,E_STANDEND,
  1257. X                   E_VI,E_NOVI);
  1258. X           }
  1259. X           break;
  1260. X      case G_WINSIZE:                    /* cols, lines */
  1261. X           sprintf(coords,"%d %d\n", T_WIDE/FSIZE(wide),
  1262. X              T_HIGH/FSIZE(high));
  1263. X           break;
  1264. X      case G_FONT:                    /* font wide, high, # */
  1265. X           {
  1266. X           register int id = W(font)->ident;
  1267. X           sprintf(coords,"%d %d %d %s\n", FSIZE(wide),
  1268. X              FSIZE(high),id,id>0?fontlist[id-1]:
  1269. X              "default.fnt");
  1270. X           }
  1271. X           break;
  1272. X      case G_CURSOR:                    /* x,y gx,gy cursor_type */
  1273. X           sprintf(coords,"%d %d %d %d %d\n",
  1274. X              W(x)/FSIZE(wide),
  1275. X              W(y)/FSIZE(high)-1,
  1276. X              W(gx), W(gy),
  1277. X              W(curs_type));
  1278. X           break;
  1279. X      case G_TEXT:            /* text region size: x,y,wide,high */
  1280. X           sprintf(coords,"%d %d %d %d\n",
  1281. X              W(text.x),W(text.y),W(text.wide),W(text.high));
  1282. X           break;
  1283. X      case G_MOUSE:                    /* mouse coordinates */
  1284. X           sprintf(coords,"%d %d %d\n", mousex, mousey, RPT_BUTTON());
  1285. X           break;
  1286. X      case G_MOUSE2:                /* massaged coordinates */
  1287. X           if (W(flags)&W_ABSCOORDS)
  1288. X              sprintf(coords, "%d %d %d\n", mousex-W(x0), mousey-W(y0), 
  1289. X                    RPT_BUTTON());
  1290. X           else
  1291. X              sprintf(coords,"%d %d %d\n",
  1292. X                    (mousex-W(x0))*GMAX/BIT_WIDE(W(window)),
  1293. X                    (mousey-W(y0))*GMAX/BIT_HIGH(W(window)),
  1294. X                    RPT_BUTTON());
  1295. X           break;
  1296. X      case G_COORDS:                    /* window coords */
  1297. X           sprintf(coords,"%d %d %d %d\n",W(x0),W(y0),
  1298. X              WIDE,HIGH);
  1299. X           break;
  1300. X      case G_STATUS:                    /* window status */
  1301. X           sprintf(coords,"%c\n",W(flags)&W_ACTIVE
  1302. X                   ? C_EXPOSED: C_OBSCURED);
  1303. X           if (win == active)
  1304. X              *coords = C_ACTIVE;
  1305. X           break;
  1306. X      case G_ALLMINE:            /* window status for client windows */
  1307. X      case G_ALL:                /* complete window status */
  1308. X           {
  1309. X           register char status;
  1310. X           *coords = '\0';
  1311. X           for(win2=active;win2!=(WINDOW *) 0;win2=win2->next) {
  1312. X              if (*W(esc)==G_ALLMINE && win2->main != W(main))
  1313. X                 continue;
  1314. X              status = win2->flags&W_ACTIVE ? C_EXPOSED:C_OBSCURED;
  1315. X              if (win2 == win)
  1316. X                 status += ('A'-'a');
  1317. X              sprintf(coords+strlen(coords),"%d %d %d %d %s %d %c %d\n",
  1318. X                      win2->x0,
  1319. X                      win2->y0,
  1320. X                      win2->BIT_WIDE(border),
  1321. X                      win2->BIT_HIGH(border),
  1322. X                      win2->tty+strlen(win2->tty)-2,
  1323. X                      win2->num,
  1324. X                      status,
  1325. X              win2->setid);
  1326. X               Write(W(to_fd),coords,strlen(coords));
  1327. X               *coords = '\0';
  1328. X               }
  1329. X           sprintf(coords+strlen(coords),"\n");
  1330. X           }
  1331. X           break;
  1332. X      case G_NOTIFY:            /* list windows with notify set  */
  1333. X           {
  1334. X           register char *str;
  1335. X           *coords = '\0';
  1336. X           for(win2=active;win2!=(WINDOW *) 0;win2=win2->next) {
  1337. X#ifdef DEBUG
  1338. X              dprintf(i)(stderr,"  checking %s\r\n",win2->tty);
  1339. X#endif
  1340. X              if (IS_EVENT(win2,EVENT_NOTIFY) &&
  1341. X                    (str = win2->events[GET_EVENT(EVENT_NOTIFY)])) {
  1342. X                 sprintf(coords+strlen(coords),"%d.%d %d %s\n",
  1343. X                          win2->pid,win2->num,strlen(str),str);
  1344. X                 Write(W(to_fd),coords,strlen(coords));
  1345. X                 *coords = '\0';
  1346. X#ifdef DEBUG
  1347. X                 dprintf(i)(stderr,"    got %s\r\n",str);
  1348. X#endif
  1349. X                 } 
  1350. X              }
  1351. X           sprintf(coords+strlen(coords),"\n");
  1352. X           }
  1353. X           break;
  1354. X      case G_SYSTEM:                    /* system status */
  1355. X           gethostname(coords,sizeof(coords));
  1356. X           sprintf(coords+strlen(coords)," %d %d %d %d %d\n",
  1357. X                      BIT_WIDE(screen),
  1358. X                      BIT_HIGH(screen),
  1359. X                      SUM_BDR,
  1360. X                      DEPTH,
  1361. X                      BITS+1);
  1362. X           break;
  1363. X      case G_ID:                    /* client window id */
  1364. X           for(count=0,win2=W(main);win2;win2=win2->alt)
  1365. X              count++;
  1366. X           sprintf(coords,"%d %d\n",W(num),count);
  1367. X           break;
  1368. X      case G_FLAGS:                    /* window flags */
  1369. X           sprintf(coords,"%0x\n",W(flags));
  1370. X           break;
  1371. X#ifdef OBSOLETE
  1372. X      case G_ALLFONT:                    /* font information */
  1373. X           {
  1374. X           register struct font *temp;
  1375. X           register int i;
  1376. X           sprintf(coords,"%d %d",font->head.wide,
  1377. X                                 font->head.high);
  1378. X           for(i=0;i<MAXFONT;i++)  {
  1379. X              temp=Get_font(i);
  1380. X              sprintf(coords+strlen(coords), "  %d %d",
  1381. X                            temp->head.wide,
  1382. X                            temp->head.high);
  1383. X              }
  1384. X           strcat(coords,"\n");
  1385. X           }
  1386. X           break;
  1387. X#endif
  1388. X      }
  1389. X   if (strlen(coords))
  1390. X      Write(W(to_fd),coords,strlen(coords));
  1391. X#ifdef DEBUG
  1392. X   dprintf(i)(stderr,"  sending (%d) [%s]\r\n",
  1393. X                 strlen(coords),coords);
  1394. X#endif
  1395. X   }
  1396. END_OF_FILE
  1397. # end of 'src/get_info.c'
  1398. fi
  1399. echo shar: End of archive 25 \(of 61\).
  1400. cp /dev/null ark25isdone
  1401. MISSING=""
  1402. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
  1403.     21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 \
  1404.     38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 \
  1405.     55 56 57 58 59 60 61 ; do
  1406.     if test ! -f ark${I}isdone ; then
  1407.     MISSING="${MISSING} ${I}"
  1408.     fi
  1409. done
  1410. if test "${MISSING}" = "" ; then
  1411.     echo You have unpacked all 61 archives.
  1412.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1413. else
  1414.     echo You still need to unpack the following archives:
  1415.     echo "        " ${MISSING}
  1416. fi
  1417. ##  End of shell archive.
  1418. exit 0
  1419.