home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume17 / mgr / part31 < prev    next >
Encoding:
Internet Message Format  |  1989-01-19  |  51.6 KB

  1. Subject:  v17i032:  MGR, Bellcore window manager, Part31/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 32
  7. Archive-name: mgr/part31
  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 31 (of 61)."
  19. # Contents:  demo/icon/iconmsgs.c demo/misc/getpty.c demo/misc/stat.c
  20. #   doc/usrman/doc.5 src/startup.c
  21. # Wrapped by rsalz@papaya.bbn.com on Thu Nov 17 21:05:38 1988
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'demo/icon/iconmsgs.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'demo/icon/iconmsgs.c'\"
  25. else
  26. echo shar: Extracting \"'demo/icon/iconmsgs.c'\" \(9313 characters\)
  27. sed "s/^X//" >'demo/icon/iconmsgs.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: iconmsgs.c,v 4.1 88/06/21 13:59:58 bianchi Exp $
  36. X    $Source: /tmp/mgrsrc/demo/icon/RCS/iconmsgs.c,v $
  37. X*/
  38. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/icon/RCS/iconmsgs.c,v $$Revision: 4.1 $";
  39. X
  40. X/* check for new messages */
  41. X/* icon version */
  42. X
  43. X#include <stdio.h>
  44. X#include <signal.h>
  45. X#include <sgtty.h>
  46. X#include "term.h"
  47. X#include "msgs_icons.h"
  48. X
  49. X#define Isflag(arg,flag)    (!strncmp(arg,flag,strlen(flag)))
  50. X#define Max(x,y)        ((x)>(y)?(x):(y))
  51. X#define MENU_COUNT    (sizeof(menu)/sizeof(struct menu_entry))
  52. X#define SCMP(x,y)    (strcmp(x+(strlen(x)-strlen(y)),y)==0)
  53. X
  54. Xstatic char    MSG_reading[] = "\freading msgs ...\r";
  55. Xstatic char    MSG_done[] = "\rdone? [?,-,!]";
  56. Xstatic char    MSG_help[] = "\r\
  57. XAvailable commands:\r\n\
  58. X ?*          this message\r\n\
  59. X -           return to most recently seen message\r\n\
  60. X -<number>   skip back <number> messages\r\n\
  61. X !<cmd>      escape to the shell and issue <cmd>\r\n\
  62. X <anything>  exit\r\n";
  63. X
  64. X#define W_WIDE        80        /* character width of msgs window */
  65. X#define W_HIGH        24        /* character height of msgs window */
  66. X
  67. X#define MSGSCMD    "msgs -p"
  68. X#define BOUNDS    "/usr/msgs/bounds"
  69. X#define RC    ".msgsrc"
  70. X#define POLL     30                /* polling interval */
  71. X#define XPOS    220                /* start of msgs window */
  72. X#define YPOS    170                /* start of msgs window */
  73. X#define MAX    50                /* max number of messages */
  74. X
  75. X#define MSGS()    (1 + get_bounds(bounds) - get_rc(rc))
  76. X#define dprintf    if(debug) fprintf
  77. X
  78. Xstatic FILE    *bounds, *rc;        /* pntrs to bounds and rc files */
  79. Xstatic int    msg_cnt, old_msg_cnt=0;    /* # of messages */
  80. Xstatic char    line[MAXLINE];        /* input buffer */
  81. Xstatic int    poll=POLL;        /* poll interval */
  82. X
  83. Xstatic struct menu_entry menu[] = {
  84. X   "yes",    "y\r",
  85. X   "skip",   "n\r",
  86. X   "again",  "-\r",
  87. X   "save",   "s\r",
  88. X   "quit",   "q\r",
  89. X   };
  90. X
  91. Xstatic int    x, y, w, h;    /* window location, width and height */
  92. Xstatic int    border;        /* size of border */
  93. Xstatic int    debug = 0;    /* debug printout flag */
  94. Xstatic int    local=0;    /* use local machine for icons */
  95. Xstatic int    cwide, chigh;    /* width and height of font characters. */
  96. Xstatic char    *termcap;
  97. X
  98. Xmain(argc,argv)
  99. Xint argc;
  100. Xchar **argv;
  101. X   {
  102. X   register int i;
  103. X   int xpos = XPOS;
  104. X   int ypos = YPOS;
  105. X   int font = -1;
  106. X   int shape = 1;
  107. X
  108. X   char *getenv();
  109. X   char *home = getenv("HOME");
  110. X   int clean(), update();
  111. X
  112. X   /* make sure we have a valid environment to run in */
  113. X
  114. X   ckmgrterm( *argv );
  115. X
  116. X   if (home==NULL || *home=='\0') {
  117. X      fprintf(stderr,"%s: Can't find your home directory\n",argv[0]);
  118. X      exit(1);
  119. X      }
  120. X
  121. X   if ((bounds = fopen(BOUNDS,"r")) == NULL) {
  122. X      fprintf(stderr,"%s: Can't find a bounds file\n",argv[0]);
  123. X      exit(2);
  124. X      }
  125. X
  126. X   sprintf(line,"%s/%s",home,RC);
  127. X   
  128. X   if ((rc = fopen(line,"r")) == NULL) {
  129. X      fprintf(stderr,"%s: Can't find %s\n",argv[0],line);
  130. X      exit(3);
  131. X      }
  132. X
  133. X   /* process arguments */
  134. X
  135. X   for(i=1;i<argc;i++) {
  136. X      if (Isflag(argv[i],"-s"))
  137. X         shape = 0;
  138. X      else if (Isflag(argv[i],"-x"))
  139. X         xpos = atoi(argv[i]+2);
  140. X      else if (Isflag(argv[i],"-y"))
  141. X         ypos = atoi(argv[i]+2);
  142. X      else if (Isflag(argv[i],"-f"))
  143. X         font = atoi(argv[i]+2);
  144. X      else if (Isflag(argv[i],"-p"))
  145. X         poll  = Max(atoi(argv[i]+2),10);
  146. X      else if (Isflag(argv[i],"-d"))
  147. X         debug=1;
  148. X      else if (Isflag(argv[i],"-l"))
  149. X         local=1;
  150. X      else
  151. X         usage(argv[0],argv[i]);
  152. X      }
  153. X
  154. X   /* setup mgr stuff */
  155. X
  156. X   m_setup(M_FLUSH);
  157. X   m_push(P_BITMAP|P_MENU|P_EVENT|P_FONT|P_FLAGS|P_POSITION);
  158. X   if (font < 0)
  159. X    font = 0;
  160. X   m_font(font);
  161. X   get_font( &cwide, &chigh );
  162. X
  163. X   signal(SIGHUP,clean);
  164. X   signal(SIGTERM,clean);
  165. X   signal(SIGINT,clean);
  166. X   signal(SIGALRM,update);
  167. X
  168. X   m_ttyset();
  169. X   m_setmode(M_NOWRAP);
  170. X   m_setmode(M_ABS);
  171. X   m_func(B_COPY);
  172. X
  173. X   download_icon(&msg_board,1);
  174. X   download_icon(&msg_note,2);
  175. X   download_icon(&msg_read,3);
  176. X   download_icon(&msg_none,4);
  177. X
  178. X   get_size(&x,&y,&w,&h);
  179. X   get_param(0,0,0,&border);
  180. X   m_movecursor(x+30,0);
  181. X
  182. X   old_msg_cnt = MSGS();
  183. X   if (shape && !debug) {
  184. X      m_shapewindow(x,y,2*border+msg_board.w,2*border+msg_board.h);
  185. X      }
  186. X   else if (debug)
  187. X      fprintf(stderr,"would shape (%d,%d) + %d\r\n",
  188. X               msg_board.w, msg_board.h, 2*border);
  189. X   m_setevent(REDRAW,"R\r");
  190. X   m_setevent(ACTIVATED,"A\r");
  191. X   update(0);
  192. X   m_clearmode(M_ACTIVATE);
  193. X
  194. X   termcap = getenv("TERMCAP");
  195. X   if( termcap )
  196. X      *termcap = '\0';
  197. X
  198. X   while(1) {
  199. X      if( m_gets(line) == NULL ) {
  200. X     clearerr(m_termin);
  201. X     continue;
  202. X      }
  203. X      alarm(0);
  204. X
  205. X      /* read msgs */
  206. X
  207. X      old_msg_cnt = msg_cnt;
  208. X      msg_cnt = MSGS();
  209. X      if (msg_cnt > 0 && *line == 'A') {
  210. X         do_msgs(MSGSCMD,font,xpos,ypos);
  211. X         }
  212. X
  213. X      /* wait for window to deactivate */
  214. X
  215. X      else if (*line == 'A') {
  216. X         set_icon(msg_none,0,0);
  217. X         sleep(2);
  218. X         }
  219. X      m_clearmode(M_ACTIVATE);
  220. X      update(0);
  221. X      }
  222. X   }
  223. X    
  224. Xint
  225. Xget_rc(file)
  226. XFILE *file;
  227. X   {
  228. X   char line[100], *fgets();
  229. X   fseek(file,0,0);
  230. X   if (fgets(line,sizeof(line),file) != NULL) 
  231. X      return(atoi(line));
  232. X   else
  233. X      return(0);
  234. X   }
  235. X
  236. Xint
  237. Xget_bounds(file)
  238. XFILE *file;
  239. X   {
  240. X   char buff[100], *line, *fgets();
  241. X   fseek(file,0,0);
  242. X   if ((line=fgets(buff,sizeof(buff),file)) != NULL) {
  243. X      while(*line != ' ') line++;
  244. X      while(*line == ' ') line++;
  245. X      return(atoi(line));
  246. X      }
  247. X   else return(0);
  248. X   }
  249. X
  250. Xclean(n)
  251. Xint n;
  252. X   {
  253. X   m_ttyreset();
  254. X   m_selectwin(0);
  255. X   m_popall();
  256. X   exit(n);
  257. X   }
  258. X
  259. Xupdate(flag)
  260. Xint flag;
  261. X   {
  262. X   alarm(0);
  263. X   msg_cnt = MSGS();
  264. X   if (msg_cnt != old_msg_cnt || flag==0) {
  265. X      if (msg_cnt > old_msg_cnt)         /* new messages */
  266. X         m_printstr("\007");
  267. X      draw(msg_cnt,old_msg_cnt,flag==0);
  268. X      }
  269. X   old_msg_cnt = msg_cnt;
  270. X   alarm(poll);
  271. X   }
  272. X
  273. Xusage(name,error)
  274. Xchar *name, *error;
  275. X{
  276. X    fprintf(stderr,"Invalid argument: %s\n",error);
  277. X    fprintf(stderr,"usage: %s -[s|x<pos>|y<pos>|f<font>|p<poll>\n",name);
  278. X    exit(1);
  279. X}
  280. X
  281. X/* down load an icon */
  282. X
  283. Xdownload_icon(icon,where)
  284. Xregister struct icon *icon;    /* name of icon to download */
  285. Xint where;            /* bitmap to download icon to */
  286. X   {
  287. X   static int local_mode = -1;
  288. X   int size;
  289. X   int w_in=0, h_in=0;
  290. X
  291. X   /* first try the local machine */
  292. X
  293. X   if (!local) {
  294. X      dprintf(stderr, "looking for %s\n", icon->name);
  295. X      m_bitfile(where, icon->name , &w_in, &h_in);
  296. X      }
  297. X
  298. X   if (h_in==0 || w_in==0) {    /* can't find icon */
  299. X      dprintf(stderr,"Couldn't find %s, downloading\n",icon->name);
  300. X      if (local_mode == -1)
  301. X         ioctl(fileno(m_termout),TIOCLGET,&local_mode);
  302. X      local_mode |= LLITOUT;
  303. X      ioctl(fileno(m_termout),TIOCLSET,&local_mode);
  304. X
  305. X      size = icon->h * (((icon->w+15)&~15)>>3);
  306. X      m_bitldto(icon->w,icon->h,0,0,where,size);
  307. X      m_flush();
  308. X      write(fileno(m_termout),icon->data,size);
  309. X      local_mode &= ~LLITOUT;
  310. X      ioctl(fileno(m_termout),TIOCLSET,&local_mode);
  311. X      }
  312. X   else {
  313. X      dprintf(stderr,"Found %s (%d x %d) expected %d x %d\n",
  314. X               icon->name,w_in,h_in,icon->w,icon->h);
  315. X      icon->w = w_in;
  316. X      icon->h = h_in;
  317. X      }
  318. X   icon->type = where;
  319. X   } 
  320. X
  321. X#define Rand(min,max)    ((min) + random()%((max)-(min)))
  322. X#define MAXNOTES    100        /* enough to make the message board
  323. X                    look filled, but not take too long
  324. X                    to draw when there are hundreds of
  325. X                    messages. */
  326. X
  327. Xdraw(new,old,redraw)
  328. Xint new,old;                /* number of messages */
  329. Xint redraw;
  330. X   {
  331. X   register int i;
  332. X   long random();
  333. X
  334. X   dprintf(stderr,"draw %d -> %d (redraw=%d)\n",old,new,redraw);
  335. X
  336. X   if (redraw || new<old)
  337. X      set_icon(msg_board,0,0);
  338. X
  339. X   if (new>old)
  340. X      new -= old;
  341. X
  342. X   for(i=0;  i<new && i<MAXNOTES;  i++) {
  343. X      set_icon( msg_note, Rand(0, msg_board.w-msg_note.w),
  344. X        Rand(12, msg_board.w-msg_note.h) );
  345. X      }
  346. X   }
  347. X   
  348. Xset_icon(name,x0,y0)
  349. Xstruct icon name;        /* name of icon */
  350. Xint x0,y0;            /* where it goes */
  351. X   {
  352. X   m_bitcopyto(x0,y0,name.w,name.h,0,0,0,name.type);
  353. X   m_flush();
  354. X   }
  355. X   
  356. X/* run msgs in a subwindow */
  357. X
  358. Xdo_msgs(command,font,xpos,ypos)
  359. Xchar *command;
  360. Xint font,xpos,ypos;
  361. X    {
  362. X    int n;
  363. X
  364. X    alarm(0);
  365. X    m_push(P_EVENT | P_FONT);
  366. X    n = m_makewindow(xpos, ypos, W_WIDE*cwide + 2*border,
  367. X        W_HIGH*chigh + 2*border );
  368. X    if (n==0) {    /* can't make window */
  369. X        m_printstr("\007\fCan't open msgs window, sorry");
  370. X        m_pop();
  371. X        return(0);
  372. X        }
  373. X      set_icon(msg_read, 0, 0);
  374. X    m_selectwin(n);
  375. X    m_font(font);
  376. X    menu_load(1,MENU_COUNT,menu);
  377. X    m_selectmenu(1);
  378. X    m_printstr(MSG_reading);
  379. X    m_ttyreset();
  380. X    system(command);
  381. X    m_printstr(MSG_done);
  382. X        while( m_gets(line) != NULL ) {
  383. X        switch( *line ) {
  384. X        case '?':
  385. X            m_printstr(MSG_help);
  386. X            break;
  387. X        case '!':    /* shell escape */
  388. X            system( &line[1] );
  389. X            break;
  390. X        case '-': {    /* go back; -N goes back N messages */
  391. X                char    buf[ 2*MAXLINE ];
  392. X                if( line[1] == '\n' )
  393. X                    strcpy( line, "-1" );
  394. X                sprintf( buf, "%s %s", command, line );
  395. X                system( buf );
  396. X            }
  397. X            break;
  398. X        default:
  399. X            goto nomore;
  400. X        }
  401. X        m_printstr(MSG_done);
  402. X    }
  403. X    clearerr(m_termin);
  404. X    nomore:
  405. X    m_ttyset();
  406. X    m_selectwin(0);
  407. X    m_destroywin(n);
  408. X    m_pop();
  409. X    m_clearmode(M_ACTIVATE);
  410. X    }
  411. END_OF_FILE
  412. # end of 'demo/icon/iconmsgs.c'
  413. fi
  414. if test -f 'demo/misc/getpty.c' -a "${1}" != "-c" ; then 
  415.   echo shar: Will not clobber existing file \"'demo/misc/getpty.c'\"
  416. else
  417. echo shar: Extracting \"'demo/misc/getpty.c'\" \(9479 characters\)
  418. sed "s/^X//" >'demo/misc/getpty.c' <<'END_OF_FILE'
  419. X/*                        Copyright (c) 1987 Bellcore
  420. X *                            All Rights Reserved
  421. X *       Permission is granted to copy or use this program, EXCEPT that it
  422. X *       may not be sold for profit, the copyright notice must be reproduced
  423. X *       on copies, and credit should be given to Bellcore where it is due.
  424. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  425. X */
  426. X#ifndef lint
  427. Xstatic char rcsid[] = "$Header: getpty.c,v 4.2 88/06/22 14:37:33 bianchi Exp $";
  428. X#endif
  429. X#include <sys/types.h>
  430. X#include <sys/wait.h>
  431. X
  432. X#include <sys/file.h>
  433. X#include <sys/signal.h>
  434. X#include <sgtty.h>
  435. X#include <stdio.h>
  436. X
  437. X#include <errno.h>
  438. X#include <pwd.h>
  439. X
  440. X/*
  441. X**    size of input and output buffers
  442. X*/
  443. X#define BFRSIZE        1024
  444. X
  445. Xextern    int errno;
  446. Xextern  int done();
  447. Xint    lostpeer();
  448. Xint shellid;
  449. Xint    rem;
  450. Xint verboseflag = 0;
  451. Xint    defflags, tabflag;
  452. Xchar    deferase, defkill;
  453. Xstruct    tchars deftc;
  454. Xstruct    ltchars defltc;
  455. Xstruct    tchars notc =    { -1, -1, -1, -1, -1, -1 };
  456. Xstruct    ltchars noltc =    { -1, -1, -1, -1, -1, -1 };
  457. X
  458. X/*
  459. X** flags to signal that massage routines have more data ready to go
  460. X**    these flags are necessary so that massage routines can buffer
  461. X**    data if necessary
  462. X*/
  463. Xint more_out = 0;
  464. Xint more_in = 0;
  465. Xgetpty(cmd)
  466. X    char **cmd;
  467. X{
  468. X    int exit();
  469. X    struct sgttyb sb;
  470. X    char pibuf[BFRSIZE], fibuf[BFRSIZE], *pbp, *fbp;
  471. X    int pcc = 0, fcc = 0;
  472. X    int cc;
  473. X
  474. X    signal(SIGPIPE, lostpeer);
  475. X        shellid = get_command(cmd,&rem);
  476. X        if (rem < 0)
  477. X                return(-1);
  478. X
  479. X    ioctl(0, TIOCGETP, (char *)&sb);
  480. X    defflags = sb.sg_flags;
  481. X    tabflag = defflags & TBDELAY;
  482. X    defflags &= ECHO | CRMOD;
  483. X    deferase = sb.sg_erase;
  484. X    defkill = sb.sg_kill;
  485. X    ioctl(0, TIOCGETC, (char *)&deftc);
  486. X    notc.t_startc = deftc.t_startc;
  487. X    notc.t_stopc = deftc.t_stopc;
  488. X    ioctl(0, TIOCGLTC, (char *)&defltc);
  489. X    signal(SIGINT, exit);
  490. X    signal(SIGHUP, exit);
  491. X    signal(SIGQUIT, exit);
  492. X    mode(1);
  493. X    signal(SIGINT, SIG_IGN);
  494. X    signal(SIGCHLD, done);
  495. X    for (;;)
  496. X    {
  497. X        int ibits = 0, obits = 0;
  498. X
  499. X        if (fcc)
  500. X            obits |= (1<<rem);
  501. X        else
  502. X            ibits |= (1<<0);
  503. X        if (pcc >= 0)
  504. X            if (pcc)
  505. X                obits |= (1<<1);
  506. X            else
  507. X                ibits |= (1<<rem);
  508. X        if (fcc < 0 && pcc < 0)
  509. X            break;
  510. X        select(16, &ibits, &obits, 0, 0, 0);
  511. X        if (ibits == 0 && obits == 0) {
  512. X            sleep(5);
  513. X            continue;
  514. X        }
  515. X        if ((fcc == 0) && more_in)
  516. X        {
  517. X            fbp = fibuf;
  518. X            fcc = inmassage(fibuf,-2);
  519. X        }
  520. X        else
  521. X        {
  522. X            if (ibits & (1<<0)) {
  523. X                fcc = read(0, fibuf, sizeof (fibuf));
  524. X                if (fcc < 0 && errno == EWOULDBLOCK)
  525. X                    fcc = 0;
  526. X                else {
  527. X                    if (fcc <= 0)
  528. X                        break;
  529. X                    fbp = fibuf;
  530. X                    fcc = inmassage(fibuf,fcc);
  531. X                }
  532. X            }
  533. X        }
  534. X        if ((pcc == 0) && more_out)
  535. X        {
  536. X            pbp = pibuf;
  537. X            pcc = outmassage(pibuf,-2);
  538. X        }
  539. X        else
  540. X        {
  541. X            if (ibits & (1<<rem)) {
  542. X                pcc = read(rem, pibuf, sizeof (pibuf));
  543. X                pbp = pibuf;
  544. X                if (pcc < 0 && errno == EWOULDBLOCK)
  545. X                    pcc = 0;
  546. X                else if (pcc <= 0)
  547. X                    pcc = -1;
  548. X                pcc = outmassage(pibuf,pcc);
  549. X            }
  550. X        }
  551. X        if ((obits & (1<<1)) && pcc > 0) {
  552. X            cc = write(1, pbp, pcc);
  553. X            if (cc > 0) {
  554. X                pcc -= cc;
  555. X                pbp += cc;
  556. X            }
  557. X        }
  558. X        if ((obits & (1<<rem)) && fcc > 0) {
  559. X            cc = write(rem, fbp, fcc);
  560. X            if (cc > 0) {
  561. X                fcc -= cc;
  562. X                fbp += cc;
  563. X            }
  564. X        }
  565. X    }
  566. X    fprintf(stderr,"Closed connection.\r\n");
  567. X    done();
  568. X    /* this point should never be reached !!! */
  569. X    return(-2);
  570. X}
  571. X
  572. Xdone()
  573. X{
  574. X
  575. X    mode(0);
  576. X    if (shellid > 0 && kill(shellid, SIGKILL) >= 0)
  577. X        wait((int *)0);
  578. X    cleanup();
  579. X}
  580. X
  581. X
  582. X/*
  583. X * writer: write to remote: 0 -> line.
  584. X */
  585. Xwriter()
  586. X{
  587. X    int c;
  588. X    while (read(0,&c,1) != 0)
  589. X    {
  590. X        if (write(rem, &c, 1) == 0) {
  591. X            fprintf(stderr,"line gone\r\n");
  592. X            return(0);
  593. X        }
  594. X    }
  595. X}
  596. X
  597. X/*
  598. X * reader: read from remote: line -> 1
  599. X */
  600. Xreader()
  601. X{
  602. X    char rb[BUFSIZ];
  603. X    register int cnt;
  604. X
  605. X    for (;;) {
  606. X        cnt = read(rem, rb, sizeof (rb));
  607. X        if (cnt == 0)
  608. X            break;
  609. X        if (cnt < 0) {
  610. X            if (errno == EINTR)
  611. X                continue;
  612. X            break;
  613. X        }
  614. X        write(1, rb, cnt);
  615. X    }
  616. X}
  617. X
  618. Xmode(f)
  619. X{
  620. X    struct tchars *tc;
  621. X    struct ltchars *ltc;
  622. X    struct sgttyb sb;
  623. X
  624. X    ioctl(0, TIOCGETP, (char *)&sb);
  625. X    switch (f) {
  626. X
  627. X    case 0:
  628. X        sb.sg_flags &= ~(CBREAK|RAW|TBDELAY);
  629. X        sb.sg_flags |= defflags|tabflag;
  630. X        tc = &deftc;
  631. X        ltc = &defltc;
  632. X        sb.sg_kill = defkill;
  633. X        sb.sg_erase = deferase;
  634. X        break;
  635. X
  636. X    case 1:
  637. X        sb.sg_flags |=  RAW;
  638. X/*
  639. X        sb.sg_flags |= (eight ? RAW : CBREAK);
  640. X*/
  641. X        sb.sg_flags &= ~defflags;
  642. X        /* preserve tab delays, but turn off XTABS */
  643. X        if ((sb.sg_flags & TBDELAY) == XTABS)
  644. X            sb.sg_flags &= ~TBDELAY;
  645. X        tc = ¬c;
  646. X        ltc = &noltc;
  647. X        sb.sg_kill = sb.sg_erase = -1;
  648. X        break;
  649. X
  650. X    default:
  651. X        return;
  652. X    }
  653. X    ioctl(0, TIOCSLTC, (char *)ltc);
  654. X    ioctl(0, TIOCSETC, (char *)tc);
  655. X    ioctl(0, TIOCSETN, (char *)&sb);
  656. X}
  657. X
  658. X
  659. Xlostpeer()
  660. X{
  661. X    signal(SIGPIPE, SIG_IGN);
  662. X    fprintf(stderr,"\007Connection closed.\r\n");
  663. X    done();
  664. X}
  665. X
  666. X
  667. X#define SHELL        "/bin/sh"
  668. X
  669. X#ifdef SYSV
  670. X#define index        strchr
  671. X#endif
  672. X
  673. Xstatic char *line = "/dev/ptypX";
  674. Xstatic int  pty_index=5;    /* better hit rate than 0 */
  675. Xextern char **environ;
  676. X
  677. X/* place to save tty modes */
  678. X
  679. Xint t_ldisc;
  680. Xstruct sgttyb t_sgttyb;
  681. Xstruct tchars t_tchars;
  682. Xstruct ltchars t_ltchars;
  683. Xint t_lflags;
  684. X/*    get a pty line */
  685. X
  686. Xint
  687. Xgetapty()
  688. X   {
  689. X   register int i;
  690. X   int fd;
  691. X   char list[20];
  692. X
  693. X   strcpy(list,"0123456789abcdef");
  694. X   line[5] = 'p';
  695. X/*
  696. X   for(line[8]='p';line[8]!='r';line[8]='q')
  697. X*/
  698. X   for(line[8]='p';line[8]!='r';line[8]++)
  699. X      for (i=1;i<=16;i++) {
  700. X         line[9]=list[(pty_index+i)%16];
  701. X     if (verboseflag)
  702. X     {
  703. X        printf("trying %s\n",line);
  704. X     }
  705. X         if ((fd = open(line,2)) >= 0) {
  706. X            /* pty_index = (pty_index+i)%16; */
  707. X        if (verboseflag)
  708. X        {
  709. X        printf("   GOT %s\n",line);
  710. X        }
  711. X            line[5] = 't';
  712. X            return(fd);
  713. X            }
  714. X         }
  715. X   return(-1);
  716. X   }
  717. X      
  718. Xint getatty()
  719. X   {
  720. X   int fd;
  721. X   line[5]='t';
  722. X   fd=open(line,2);
  723. X   if (fd<0) {
  724. X      sleep(3);
  725. X      return (open(line,2));
  726. X      }
  727. X   return(fd);
  728. X   }
  729. X
  730. Xchar *
  731. Xlast_tty()
  732. X   {
  733. X   return(line);
  734. X   }
  735. X
  736. X/******************************************************************************/
  737. X/* start a command */
  738. X
  739. Xget_command(argv,file)
  740. Xchar **argv;
  741. Xint *file;
  742. X   {
  743. X   register int i;                /* counter */
  744. X   int fd;                    /* file desc */
  745. X   int tty;                    /* fd of /dev/tty */
  746. X   int pid;                    /* pid of shell */
  747. X   int group;                    /* process group id */
  748. X   int tty_slots;                /* # of tty slots */
  749. X   char *name, *get_path();
  750. X   char *getenv();
  751. X   char *shell = getenv("SHELL");
  752. X   char *arg[2];
  753. X#define MAXNAME 256
  754. X   char who[MAXNAME];
  755. X
  756. X   if (argv == (char **) 0 ) {
  757. X      argv = arg;
  758. X      *argv = shell?shell:SHELL;
  759. X      *(argv+1) = (char *) 0;
  760. X      }
  761. X   name = get_path(argv[0]);
  762. X
  763. X   if (name == (char *) 0 || *name == '\0')
  764. X      return(-2);
  765. X
  766. X#ifdef DEBUG
  767. X   dprintf(stderr,"EXECING: ");
  768. X   for(i=0;argv[i]!='\0';i++)
  769. X      dprintf(stderr,"%s ",argv[i]);
  770. X   dprintf("\n");
  771. X#endif
  772. X
  773. X   if ((*file=getapty()) < 0)
  774. X      return(-1);
  775. X   ioctl(*file,TIOCREMOTE,0);    /* I dunno */
  776. X
  777. X   ioctl(0,TIOCGETD,&t_ldisc);
  778. X   ioctl(0,TIOCGETP,&t_sgttyb);
  779. X   ioctl(0,TIOCGETC,&t_tchars);
  780. X   ioctl(0,TIOCGLTC,&t_ltchars);
  781. X   ioctl(0,TIOCLGET,&t_lflags);
  782. X
  783. X   if ((pid=fork()) != 0) {
  784. X      return(pid);
  785. X      }
  786. X
  787. X   /* void association with controlling terminal */
  788. X
  789. X#ifdef TIOCNOTTY
  790. X   tty = open("/dev/tty",0);
  791. X   ioctl(tty,TIOCNOTTY,0);
  792. X   close(tty);
  793. X#endif
  794. X
  795. X   if ((fd=getatty())<0) {
  796. X    char permsg[256];
  797. X      sprintf(permsg,"Slave side of p-tty %s won't open",line);
  798. X      perror(permsg);
  799. X      sleep(5);
  800. X      exit(1);
  801. X      }
  802. X
  803. X
  804. X   group=getpid();
  805. X
  806. X#ifndef SYSV
  807. X   tty_slots = getdtablesize();
  808. X#else
  809. X   tty_slots = 20;
  810. X#endif
  811. X
  812. X   for(i=0;i<tty_slots;i++) if (i != fd) close(i);
  813. X
  814. X   /* set the uid stuff up */
  815. X
  816. X   if (geteuid() < 2) {
  817. X      int uid = getuid();
  818. X      fchmod(fd,0622);
  819. X      fchown(fd,uid,-1);
  820. X      setreuid(uid,uid);
  821. X
  822. X      uid = getgid();
  823. X      fchown(fd,-1,uid);
  824. X      setregid(uid,uid);
  825. X      }
  826. X
  827. X   dup(fd), dup(fd), dup(fd);
  828. X   close(fd);
  829. X
  830. X   setpgrp(group,group);
  831. X   ioctl(0,TIOCSPGRP,&group);
  832. X
  833. X   t_ldisc=NTTYDISC;
  834. X   t_sgttyb.sg_flags = ECHO|CRMOD|EVENP|ODDP;
  835. X
  836. X   ioctl(0,TIOCSETD,&t_ldisc);
  837. X   ioctl(0,TIOCSETP,&t_sgttyb);
  838. X   ioctl(0,TIOCSETC,&t_tchars);
  839. X   ioctl(0,TIOCSLTC,&t_ltchars);
  840. X   ioctl(0,TIOCLSET,&t_lflags);
  841. X
  842. X   /* add a utmp entry */
  843. X
  844. X/*
  845. X#ifdef WHO
  846. X   add_utmp(0,sprintf(who,"%s%c",HOST,line[9]));
  847. X#endif
  848. X*/
  849. X
  850. X   /* start the command */
  851. X
  852. X#ifdef DEBUG
  853. X   dprintf(stderr,"execing %s (%s ...)\r\n",name,*argv);
  854. X   fflush(stderr);
  855. X#endif
  856. X
  857. X/*
  858. X   do_env("TERM=",TERMNAME);
  859. X   do_env("TERMCAP=","");
  860. X*/
  861. X
  862. X   execve(name,argv,environ);
  863. X   _exit(1);
  864. X   }
  865. X
  866. X/* get a complete path name from command */
  867. X
  868. Xstatic char path[512];
  869. Xstatic char start[512];
  870. X
  871. Xchar *
  872. Xget_path(name)
  873. Xchar *name;
  874. X   {
  875. X   char *getenv(), *index();
  876. X   register char c, *next, *list;
  877. X
  878. X#ifdef DEBUG
  879. X   dprintf(stderr,"looking for command: %s\n",name);
  880. X#endif
  881. X
  882. X   if (index("/.",*name))
  883. X      if (access(name,X_OK)==0)
  884. X         return(name);
  885. X      else
  886. X         return((char *)0);
  887. X
  888. X   strcpy(start,getenv("PATH"));
  889. X   for(list=start;next=index(list,':');list=next+1) {
  890. X      *next = '\0';
  891. X      sprintf(path,"%s/%s",list,name);
  892. X#ifdef DEBUG
  893. X      dprintf(stderr," X? %s\n",path);
  894. X#endif
  895. X      if (access(path,X_OK) == 0)
  896. X         return(path);
  897. X      }
  898. X
  899. X   sprintf(path,"%s/%s",list,name);
  900. X#ifdef DEBUG
  901. X   dprintf(stderr,"X? %s\n",path);
  902. X#endif
  903. X   if (list && access(path,X_OK) == 0) {
  904. X      return(path);
  905. X      }
  906. X   else {
  907. X      return((char *) 0);
  908. X      }
  909. X   }
  910. X
  911. X/* change an environment variable */
  912. X
  913. Xdo_env(name,value)
  914. Xchar *name, *value;
  915. X   {
  916. X   register int i;
  917. X   int n = strlen(name);
  918. X   
  919. X   for(i=0;environ[i] != (char *) 0;i++)
  920. X      if (strncmp(environ[i],name,n) == 0) {
  921. X         strcpy(environ[i]+n,value);
  922. X         break;
  923. X         }
  924. X   }
  925. X
  926. END_OF_FILE
  927. # end of 'demo/misc/getpty.c'
  928. fi
  929. if test -f 'demo/misc/stat.c' -a "${1}" != "-c" ; then 
  930.   echo shar: Will not clobber existing file \"'demo/misc/stat.c'\"
  931. else
  932. echo shar: Extracting \"'demo/misc/stat.c'\" \(9572 characters\)
  933. sed "s/^X//" >'demo/misc/stat.c' <<'END_OF_FILE'
  934. X/*                        Copyright (c) 1987 Bellcore
  935. X *                            All Rights Reserved
  936. X *       Permission is granted to copy or use this program, EXCEPT that it
  937. X *       may not be sold for profit, the copyright notice must be reproduced
  938. X *       on copies, and credit should be given to Bellcore where it is due.
  939. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  940. X */
  941. X/*    $Header: stat.c,v 4.2 88/06/22 14:38:11 bianchi Exp $
  942. X    $Source: /tmp/mgrsrc/demo/misc/RCS/stat.c,v $
  943. X*/
  944. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/misc/RCS/stat.c,v $$Revision: 4.2 $";
  945. X
  946. X/* strip_chart vmstat output version II */
  947. X
  948. X/*
  949. X#define NEWESC    'E' 
  950. X*/
  951. X
  952. X#include "term.h"
  953. X#include <signal.h>
  954. X#include <sgtty.h>
  955. X
  956. X#define MAXTRY    5        /* max number of tries for window parameters */
  957. X
  958. XFILE *popen(), *file;
  959. X
  960. Xstruct data {
  961. X   char *s_title;    /* short label */
  962. X   char *l_title;    /* long label */
  963. X   int index;        /* which item in vmstat */
  964. X   int max;        /* maximum value */
  965. X   };
  966. X
  967. Xstruct data data[] = {
  968. X   "r",        "jobs in run q",    0,    5,
  969. X   "b",        "jobs blocked",        1,    5,
  970. X   "w",        "jobs waiting",        2,    5,
  971. X   "fre",    "free memory",        4,    2000,
  972. X   "fr",    "freed pages",        9,    10,
  973. X   "d1",    "disk 1 accesses",    12,    5,
  974. X   "d2",    "disk 2 accesses",    13,    5,
  975. X   "d3",    "disk 3 accesses",    14,    5,
  976. X   "d4",    "disk 4 accesses",    15,    5,
  977. X   "in",    "interrupts",        16,    60,
  978. X   "sy",    "system calls",        17,    60,
  979. X   "cs",    "context switches",    18,    30,
  980. X   "us",    "% user time",        19,    100,
  981. X   "kn",    "% system time",    20,    100,
  982. X   "id",    "% idle time",        21,    100,
  983. X   "",        "",            -1,    -1
  984. X   };
  985. X
  986. X#define INTERVAL    60    /* bar interval (in secs) */
  987. X#define SCROLL        4    /* # of scrolls per window */
  988. X#define MAX        10    /* max number of plots */
  989. X#define FREQ        3    /* update frequency (secs)*/
  990. X#define DELTA        4    /* pixels/update */
  991. X
  992. X#define Min(x,y)    ((x)>(y)?(y):(x))
  993. X#define Max(x,y)    ((x)>(y)?(x):(y))
  994. X#define dprintf        if (debug) fprintf
  995. X
  996. Xmain(argc,argv)
  997. Xint argc;
  998. Xchar **argv;
  999. X   {
  1000. X   register int i;
  1001. X   register int x;    /* current plot position */
  1002. X   int bar=0;        /* hash mark counter */
  1003. X   int back=0;        /* enable background writes */
  1004. X   int solid=1;        /* make solid lines */
  1005. X   int freq = FREQ;    /* update frequency (secs) */
  1006. X   int size;        /* size of label region */
  1007. X   int interval;    /* hash mark interval (secs) */
  1008. X
  1009. X   char host[16];    /* hostname */
  1010. X   char title[255];    /* chart title */
  1011. X   char line[255];    /* vmstat input buffer */
  1012. X   char *fields[25];    /* pntrs to vmstat fields */
  1013. X   char labels[MAX][100];    /* place for labels */
  1014. X   char *sprintf();
  1015. X
  1016. X   int current[MAX];    /* current data value */
  1017. X   int old[MAX];    /* previous data value */
  1018. X   int field[MAX];    /* index into 'data' */
  1019. X   int first =1;    /* first time through */ 
  1020. X   int clean();
  1021. X
  1022. X   int f_high, f_wide;        /* font size */
  1023. X   int high,wide;        /* window size */
  1024. X   int x1;            /* left margin */
  1025. X   int x2;            /* title */
  1026. X   int y1;            /* title line */
  1027. X   int y2;            /* first bar */
  1028. X   int scroll;            /* scroll amount */
  1029. X   int count;            /* number of plots */
  1030. X   int delta=DELTA;        /* pixels/line */
  1031. X   int item;
  1032. X   int max = 0;
  1033. X   int dummy;
  1034. X   int debug=0;
  1035. X
  1036. X   ckmgrterm( *argv );
  1037. X
  1038. X   /* process arguments */
  1039. X
  1040. X   if (argc<2) {
  1041. X      fprintf(stderr,"usage: %s -[i<incr>sbf<freq>] [-max] arg ...\n",argv[0]);
  1042. X      fprintf(stderr,"args:\n");
  1043. X      for(i=0;data[i].max >=0;i++)
  1044. X         fprintf(stderr,"  %s    (%s)\n",data[i].s_title,data[i].l_title);
  1045. X      exit(1);
  1046. X      }
  1047. X
  1048. X   for(count=0,i=1;i<argc;i++) {
  1049. X      if (strcmp(argv[i],"-d")==0) {
  1050. X         debug++;
  1051. X         continue;
  1052. X         }
  1053. X      if (strcmp(argv[i],"-b")==0) {
  1054. X         back++;
  1055. X         continue;
  1056. X         }
  1057. X      if (strcmp(argv[i],"-s")==0) {
  1058. X         solid=0;
  1059. X         continue;
  1060. X         }
  1061. X      if (strncmp(argv[i],"-f",2)==0) {
  1062. X         freq = atoi(argv[i]+2);
  1063. X         if (freq < 1) freq = 1;
  1064. X         if (freq > 120) freq = 120;
  1065. X         continue;
  1066. X         }
  1067. X      if (strncmp(argv[i],"-i",2)==0) {
  1068. X         delta = atoi(argv[i]+2);
  1069. X         if (delta < 1) delta = 1;
  1070. X         if (freq > 10) delta = 10;
  1071. X         continue;
  1072. X         }
  1073. X      if (*argv[i] == '-') {
  1074. X         max = atoi(argv[i]+1);
  1075. X         continue;
  1076. X         }
  1077. X      if ((item = get_item(argv[i],data)) < 0) {
  1078. X         fprintf(stderr,"%s:    %s is an invalid item\n",argv[0],argv[i]);
  1079. X         continue;
  1080. X         }
  1081. X      if (max > 0) {
  1082. X         data[item].max = max;
  1083. X         max = 0;
  1084. X         }
  1085. X      field[count] = item;
  1086. X      sprintf(labels[count],"%s",data[item].l_title);
  1087. X      if (++count == MAX)
  1088. X         break;
  1089. X      }
  1090. X
  1091. X   if (count < 1) {
  1092. X      fprintf(stderr,"%s:    not enough fields\n,argv[0]");
  1093. X      exit(5); 
  1094. X      }
  1095. X
  1096. X   if ((file = popen(sprintf(line,"vmstat %d",freq),"r")) == NULL)
  1097. X      exit(1);
  1098. X
  1099. X   m_setup(0);
  1100. X   m_ttyset();
  1101. X   m_push(P_EVENT|P_FLAGS);
  1102. X   m_setmode(M_ABS);
  1103. X   if (!back)
  1104. X      m_setmode(M_BACKGROUND);
  1105. X   else
  1106. X      m_clearmode(M_BACKGROUND);
  1107. X
  1108. X   signal(SIGINT,clean);
  1109. X   signal(SIGTERM,clean);
  1110. X
  1111. X   system("stty -ctlecho");
  1112. X   m_setevent(RESHAPE,"R\fRedrawing...\n");
  1113. X   m_setevent(REDRAW,"R\fRedrawing...\n");
  1114. X   first = 1;
  1115. X
  1116. X   while (1) {
  1117. X
  1118. X      for(size=0,i=0;i<count;i++)
  1119. X         size = Max(size,strlen(labels[i]));
  1120. X
  1121. X      /* clear the screen, flush pending input */
  1122. X
  1123. X      read_it(fileno(m_termin),line);
  1124. X
  1125. X      /* get font size */
  1126. X
  1127. X      for(i=0;i<MAXTRY && get_font(&f_wide,&f_high) < 0;i++);
  1128. X
  1129. X      /* get window size */
  1130. X
  1131. X      for(i=0;i<MAXTRY && get_size(0,0,&wide,&high) <= 0;i++);
  1132. X   
  1133. X      if (wide==0 || high==0 || f_wide==0 || f_high==0) {
  1134. X         fprintf(stderr,"Can't get window info\n");
  1135. X         clean();
  1136. X         }
  1137. X
  1138. X      /* get the title */
  1139. X
  1140. X      gethostname(host,sizeof(host));
  1141. X
  1142. X      sprintf(title,"Statistics for %s (%d second intervals)",host,freq);
  1143. X
  1144. X      if (strlen(title)*f_wide > wide)
  1145. X         sprintf(title,"%s (%d sec.)",host,freq);
  1146. X
  1147. X      /* make sure window is big enough */
  1148. X
  1149. X      if (f_high * (count+1) > high) {
  1150. X         fprintf(stderr,"\fWindow isn't tall enough\n");
  1151. X         m_gets(line);
  1152. X         continue;
  1153. X         }
  1154. X
  1155. X      if (strlen(title)*f_wide > wide || 3*size*f_wide > wide*2) {
  1156. X         fprintf(stderr,"\fWindow isn't\nwide enough\n");
  1157. X         m_gets(line);
  1158. X         continue;
  1159. X         }
  1160. X
  1161. X      /* calculate key positions */
  1162. X
  1163. X      x1 = (size*f_wide+1);
  1164. X      x2 = (wide-strlen(title)*f_wide)/2;
  1165. X      y1 = f_high +1;
  1166. X      y2 = (high - y1) /count;
  1167. X      high--;
  1168. X
  1169. X      m_func(B_SET);
  1170. X      m_clear();
  1171. X      x = x1;
  1172. X      scroll = Max((wide-x1)/SCROLL,10);
  1173. X      scroll += scroll%DELTA;
  1174. X
  1175. X      if (freq >15)
  1176. X         interval = INTERVAL * 10 /freq;
  1177. X      else 
  1178. X         interval = INTERVAL / freq;
  1179. X
  1180. X      /* draw form */
  1181. X
  1182. X      m_moveprint(x2,y1,title);
  1183. X
  1184. X      for(i=0;i<count;i++) {
  1185. X         char tmp[10];
  1186. X         if (f_high * (3*count+1) <= high) {
  1187. X            sprintf(tmp,"%d",data[field[i]].max);
  1188. X            m_moveprint(x1-f_wide*strlen(tmp),high-(i+1)*y2+f_wide*2+1,tmp);
  1189. X            m_moveprint(x1-f_wide,high-i*y2,"0");
  1190. X            m_moveprint(1,high-i*y2-f_high,labels[i]);
  1191. X            }
  1192. X         else
  1193. X            m_moveprint(1,high-i*y2-1,labels[i]);
  1194. X         m_line(x1,high-i*y2,wide,high-i*y2);
  1195. X         }
  1196. X   
  1197. X      m_line(0,y1,wide,y1);
  1198. X      m_line(x1,y1,x1,high);
  1199. X      m_movecursor(x1,0);
  1200. X      m_flush();
  1201. X
  1202. X      /* read the data */
  1203. X
  1204. X      while (fgets(line,sizeof(line),file) != NULL) {
  1205. X         i = parse(line,fields);
  1206. X         if (strcmp(*fields,"procs")==0) {
  1207. X            fgets(line,sizeof(line),file);
  1208. X            fgets(line,sizeof(line),file);
  1209. X            continue;
  1210. X            }
  1211. X          if (i < 22) continue;
  1212. X
  1213. X         /* calculate new line position */
  1214. X
  1215. X         for(i=0;i<count;i++) {
  1216. X            current[i] = atoi(fields[data[field[i]].index]) *
  1217. X                         (y2-3)/data[field[i]].max;
  1218. X            current[i] = Min(current[i],y2-3) + y2*i + 1;
  1219. X
  1220. X            if (!first) {
  1221. X               m_line(x,high-old[i],x+delta,high-current[i]);
  1222. X               if (solid)
  1223. X                  m_line(x+delta,high-y2*i,x+delta,high-current[i]);
  1224. X               }
  1225. X
  1226. X            dprintf(stderr,"%s %d->%d, ",data[field[i]].s_title,
  1227. X                            high-old[i],high-current[i]);
  1228. X            old[i] = current[i];
  1229. X            }
  1230. X         dprintf(stderr," [%d]\n",high);
  1231. X   
  1232. X         if (++bar  == interval) {
  1233. X            m_line(x,y1,x,high);
  1234. X            bar = 0;
  1235. X            dprintf(stderr,"---------\n");
  1236. X            }
  1237. X
  1238. X         if (first)
  1239. X            first = 0;
  1240. X         else
  1241. X            x += delta;
  1242. X
  1243. X         if (x > wide-delta) {
  1244. X
  1245. X            /* scroll the display */
  1246. X
  1247. X            x -= scroll;
  1248. X            m_func(B_COPY);
  1249. X            m_bitcopy(x1+1,y1+1,wide-x1-1,high-y1-1,x1+scroll+1,y1+1);
  1250. X            m_func(B_CLEAR);
  1251. X            m_bitwrite(wide-scroll,y1+1,scroll,high);
  1252. X            m_func(B_SET);
  1253. X         
  1254. X            dprintf(stderr,"scroll to %d,%d from %d,%d\n",
  1255. X                    x1+1,y1+1,x1+scroll+1,y1+1);
  1256. X            for(i=0;i<count;i++) 
  1257. X               m_line(wide-scroll,high-i*y2,wide,high-i*y2);
  1258. X            }
  1259. X         m_flush();
  1260. X         if (read_it(fileno(m_termin),line) && *line == 'R')
  1261. X            break;
  1262. X         }
  1263. X      }
  1264. X   }
  1265. X
  1266. Xint
  1267. Xget_item(s,data)    /* look up an parameter */
  1268. Xchar *s;
  1269. Xstruct data data[];
  1270. X   {
  1271. X   register int i;
  1272. X
  1273. X   for(i=0;data[i].index>=0;i++)
  1274. X      if (strcmp(s,data[i].s_title)==0)
  1275. X        return(i);
  1276. X   return(-1);
  1277. X   }
  1278. X
  1279. Xclean()            /* clean up on SIGINT */
  1280. X   {
  1281. X   m_pop(0);
  1282. X   pclose(file);
  1283. X   m_clear();
  1284. X   m_flush();
  1285. X   m_ttyreset();
  1286. X   exit(1);
  1287. X   }
  1288. X
  1289. Xint read_it(fd,line)    /* non blocking read */
  1290. Xint fd;
  1291. Xchar *line;
  1292. X   {
  1293. X   long rd;
  1294. X
  1295. X   ioctl(fd,FIONREAD,&rd);
  1296. X   line[rd] = '\0';
  1297. X   if (rd > 0)  {
  1298. X      return(read(fd,line,rd));
  1299. X      }
  1300. X   else
  1301. X      return(0);
  1302. X   }
  1303. END_OF_FILE
  1304. # end of 'demo/misc/stat.c'
  1305. fi
  1306. if test -f 'doc/usrman/doc.5' -a "${1}" != "-c" ; then 
  1307.   echo shar: Will not clobber existing file \"'doc/usrman/doc.5'\"
  1308. else
  1309. echo shar: Extracting \"'doc/usrman/doc.5'\" \(9903 characters\)
  1310. sed "s/^X//" >'doc/usrman/doc.5' <<'END_OF_FILE'
  1311. X'\"                        Copyright (c) 1988 Bellcore
  1312. X'\"                            All Rights Reserved
  1313. X'\"       Permission is granted to copy or use this program, EXCEPT that it
  1314. X'\"       may not be sold for profit, the copyright notice must be reproduced
  1315. X'\"       on copies, and credit should be given to Bellcore where it is due.
  1316. X'\"       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  1317. X'\"
  1318. X'\"    $Header: doc.5,v 4.1 88/06/29 17:05:04 bianchi Exp $
  1319. X'\"    $Source: /tmp/mgrsrc/doc/usrman/RCS/doc.5,v $
  1320. X.Sh page Functions
  1321. XThe functions listed below have packaged common sequences of
  1322. X.I macro
  1323. Xcalls together to provide a slightly higher level of interface than the
  1324. Xmacros alone.  They are still low level, and have no pretense of
  1325. Xcompleteness. Except where noted, all of the functions return a value
  1326. Xgreater than zero on success, and a value less than zero upon failure.
  1327. XThe functions fail only if they read an unexpected value from \*M.
  1328. XClient programs may use the function
  1329. X.Fr m_lastline
  1330. Xin an attempt to determine what input caused the failure.
  1331. XThose functions which expect data from \*M automatically flush any
  1332. Xpending output before reading, and unless the 
  1333. X.I M_MODEOK
  1334. Xflag is set,
  1335. Xattempt to turn off character echoing
  1336. Xto prevent data returned by \*M from echoing back on the window.
  1337. X.LP
  1338. X.RS
  1339. X.Fd int
  1340. X.Fr get_all list 
  1341. X.Fs get_all\(dg 7 "Get all window status"
  1342. X.br
  1343. Xstruct window_data \*Alist;
  1344. X.Ft
  1345. XThe current position size and status of all windows on the display
  1346. Xis returned in
  1347. X.Fi list .
  1348. XThe number of in
  1349. Xwindows on the display is returned.
  1350. X.Fi List
  1351. Xshould be large enough to hold a status entry for each window.
  1352. XThe
  1353. X.I window_data
  1354. Xstructure 
  1355. Xis defined in
  1356. X.I term.h .
  1357. X.Fd int
  1358. X.Fr get_client list 
  1359. X.Fs get_client\(dg 7 "Get alternate window status"
  1360. X.br
  1361. Xstruct window_data \*Alist;
  1362. X.Ft
  1363. XThe current position size and status of the client programs
  1364. X.I main
  1365. Xand
  1366. X.I alternate
  1367. Xwindows
  1368. Xis returned in
  1369. X.Fi list .
  1370. XThe number of
  1371. Xwindows owned by the client program is returned.
  1372. X.Fi List
  1373. Xshould be large enough to hold a status entry for each window.
  1374. XThe
  1375. X.I window_data
  1376. Xstructure 
  1377. Xis defined in
  1378. X.I term.h .
  1379. X.Fd int
  1380. X.Fr get_colrow columns rows 
  1381. X.Fs get_colrow\(dg 7 "Get window size, in columns and rows"
  1382. X.br
  1383. Xint \*Acolumns, \*Arows;
  1384. X.Ft
  1385. XThe number of
  1386. X.I columns
  1387. Xand
  1388. X.I rows
  1389. Xin the current 
  1390. X.I "text region"
  1391. Xis returned in
  1392. X.Fi columns
  1393. Xand
  1394. X.Fi rows
  1395. Xrespectively.
  1396. XFor any
  1397. X.SM
  1398. X.I NULL
  1399. X.LG
  1400. Xargument,
  1401. Xno value is returned.
  1402. X.Fd int
  1403. X.Fr get_cursor column row 
  1404. X.Fs get_cursor\(dg 7 "Get cursor position"
  1405. X.br
  1406. Xint \*Acolumn, \*Arow;
  1407. X.Ft
  1408. XThe current
  1409. X.I character
  1410. Xcursor position is placed in
  1411. X.Fi column
  1412. Xand
  1413. X.Fi row .
  1414. XFor any
  1415. X.SM
  1416. X.I NULL
  1417. X.LG
  1418. Xargument,
  1419. Xno value is returned.
  1420. X.Fd int
  1421. X.Fr get_eachclientwin windatap
  1422. X.Fs get_eachclientwin\(dg 7 "Get window parameters for each window"
  1423. X.br
  1424. Xstruct window_data \*Awindatap;
  1425. X.Ft
  1426. XGet the window parameters for each window in the current window set,
  1427. Xone window at a time.
  1428. XThis function returns 1 if window_data structure has been filled,
  1429. X0 otherwise.
  1430. XIt is important to call get_eachcleintwin() in a tight loop that
  1431. Xdoesn't exit until it returns 0,
  1432. Xso that all the data is picked up.
  1433. XThis function is preferred to
  1434. X.Fr get_client
  1435. X because you don't need to know the maximum number of windows you are likely
  1436. Xto see.
  1437. X.Fd int
  1438. X.Fr get_eachwin windatap
  1439. X.Fs get_eachwin\(dg 7 "Get window parameters for each window"
  1440. X.br
  1441. Xstruct window_data \*Awindatap;
  1442. X.Ft
  1443. XGet the window parameters for all the windows,
  1444. Xone window at a time.
  1445. XThis function returns 1 if window_data structure has been filled,
  1446. X0 otherwise.
  1447. XIt is important to call get_eachwin() in a tight loop that
  1448. Xdoesn't exit until it returns 0,
  1449. Xso that all the data is picked up.
  1450. XThis function is preferred to
  1451. X.Fr get_all
  1452. X because you don't need to know the maximum number of windows you are likely
  1453. Xto see.
  1454. X.Fd int
  1455. X.Fr get_font wide high 
  1456. X.Fs get_font\(dg 7 "Get character font size"
  1457. X.br
  1458. Xint  \*Awide, \*Ahigh;
  1459. X.Ft
  1460. XThe character size of the current font, in pixels
  1461. Xis placed in
  1462. X.Fi wide
  1463. Xand
  1464. X.Fi high .
  1465. XFor any
  1466. X.SM
  1467. X.I NULL
  1468. X.LG
  1469. Xargument,
  1470. Xno value is returned.
  1471. XThe function returns the current font number, as would be
  1472. Xused in a call to
  1473. X.Fr m_font
  1474. X\&.
  1475. X.Fd int
  1476. X.Fr get_mouse x y 
  1477. X.Fs get_mouse\(dg 7 "Get mouse position"
  1478. X.br
  1479. Xint \*Ax, \*Ay;
  1480. X.Ft
  1481. XThe current mouse
  1482. Xposition, in
  1483. X.I window
  1484. Xcoordinates, is placed in
  1485. X.Fi x
  1486. Xand
  1487. X.Fi y .
  1488. XFor any
  1489. X.SM
  1490. X.I NULL
  1491. X.LG
  1492. Xargument,
  1493. Xno value is returned.
  1494. XThe function returns the current mouse button state, which is
  1495. Xin the range of -2 to +2 upon success, a value less than -2
  1496. Xupon failure.
  1497. XSee 
  1498. X.Fr m_getinfo G_MOUSE
  1499. X for a discussion of the return values.
  1500. X.Fd int
  1501. X.Fr get_param host xmax ymax border 
  1502. X.Fs get_param\(dg 7 "Get \*M system parameters"
  1503. X.br
  1504. Xchar \*Ahost;
  1505. Xint \*Axmax, \*Aymax, \*Aborder;
  1506. X.Ft
  1507. XThe
  1508. X.I \*M-host ,
  1509. Xdisplay size (in pixels)
  1510. Xand window border size (in pixels) is placed in the arguments
  1511. X.Fi host , xmax , ymax ,
  1512. Xand
  1513. X.Fi border .
  1514. XFor any
  1515. X.SM
  1516. X.I NULL
  1517. X.LG
  1518. Xargument,
  1519. Xno value is returned.
  1520. X.Fd int
  1521. X.Fr get_size X Y Dwidth Dheight 
  1522. X.Fs get_size\(dg 7 "Get the window size and position on the display"
  1523. X.br
  1524. Xint \*AX, \*AY, \*ADwidth, \*ADheight;
  1525. X.Ft
  1526. XThe position of the window on the display, in
  1527. X.I display
  1528. Xcoordinates is placed into
  1529. X.Fi X , Y , Dwidth 
  1530. Xand
  1531. X.Fi Dheight .
  1532. XFor any
  1533. X.SM
  1534. X.I NULL
  1535. X.LG
  1536. Xargument,
  1537. Xno value is returned.
  1538. X.Fd char \*A
  1539. X.Fr get_termcap  
  1540. X.Fs get_termcap\(dg 7 "Get a \s-2TERMCAP\s+2 entry"
  1541. X.br
  1542. X.Ft
  1543. XA string containing a
  1544. X.I \s-2TERMCAP\s+2
  1545. Xentry, suitable for placing into the
  1546. X.I \s-2TERMCAP\s+2
  1547. Xenvironment variable is returned.
  1548. XThe function
  1549. X.Fr get_termcap
  1550. X returns 
  1551. X.SM
  1552. X.I NULL
  1553. X.LG
  1554. Xupon failure.
  1555. X.Fd int
  1556. X.Fs is_active\(dg 7 "See if the window is the active window"
  1557. X.Fr is_active  
  1558. X.Ft
  1559. X.br
  1560. XThe function
  1561. X.Fr is_active
  1562. X returns
  1563. X.SM
  1564. X.I TRUE
  1565. X.LG
  1566. Xif the window is the
  1567. X.I active
  1568. Xwindow .
  1569. X.Fd void
  1570. X.Fr menu_load n count text 
  1571. X.Fs menu_load\(dg 8 "Down load a pop-up menu"
  1572. X.br
  1573. Xint n;
  1574. Xint count;
  1575. Xstruct menu_entry \*Atext;
  1576. X.Ft
  1577. XA menu is downloaded to \*M at position
  1578. X.Fi n .
  1579. XThe integer 
  1580. X.Fi count
  1581. Xis the number of menu items to be down-loaded, and
  1582. X.Fi text
  1583. Xis an array of menu item/value pairs.
  1584. XThe structure
  1585. X.I menu_entry
  1586. Xis defined in
  1587. X.I term.h .
  1588. X.Fd int
  1589. X.Fr m_bitfile to name widep highp
  1590. X.Fs m_bitfile\(dg 5 "Read a bitmap file into a scratchpad bitmap"
  1591. X.br
  1592. Xint to;
  1593. Xchar *name;
  1594. Xint *widep, *highp;
  1595. X.Ft
  1596. XGiven a bitmap id,
  1597. X.Fi to
  1598. Xand an icon 
  1599. X.Fi name ,
  1600. Xhave \*M load that icon into that scratchpad bitmap,
  1601. Xreturning the icon width
  1602. Xand height, in pixels, via the given integer pointers.
  1603. XReturn a positive number if successful.
  1604. XIf the icon is not loaded, set the width and height values to 0 and
  1605. Xreturn 0.
  1606. XThis function is identical to
  1607. X.Fr m_bitfromfile
  1608. Xplus the needed interception of the line returned from \*M.
  1609. X.Fd void
  1610. X.Fr m_bitload x y wide high data 
  1611. X.Fs m_bitload\(dg 5 "Download an image into the window"
  1612. X.br
  1613. Xint x,y;
  1614. Xint wide,high;
  1615. Xregister char \*Adata;
  1616. X.Ft
  1617. XThe bitmap image pointed at by
  1618. X.Fi data
  1619. Xis down-loaded to the window
  1620. Xat position
  1621. X.Fr ""  x  y
  1622. X in 
  1623. X.I window
  1624. Xcoordinates.
  1625. XIt is up to the client program to insure an 8 bit channel exists
  1626. Xbetween the client and \*M.
  1627. XThe integers
  1628. X.Fi wide
  1629. Xand
  1630. X.Fi high
  1631. Xspecify the size of the bitmap in pixels.
  1632. X.Fd char \*A
  1633. X.Fr m_lastline  
  1634. X.Fs m_lastline\(dg 1 "Retrieve the last line send from \*M for a library function"
  1635. X.br
  1636. X.Ft
  1637. XThe last input from \*M to a library function is returned.
  1638. XThe data is kept in a static buffer which is overwritten
  1639. Xat each request.
  1640. X.Fd int
  1641. X.Fr m_makewindow X Y Dwidth Dheight
  1642. X.Fs m_makewindow\(dg 11 "Make an alternate window"
  1643. X.br
  1644. Xint  X, Y, Dwidth, Dheight;
  1645. X.Ft
  1646. XAn alternate window is created as the
  1647. X.I active
  1648. Xwindow,
  1649. Xat display coordinates
  1650. X.Fr "" X Y
  1651. X and of size
  1652. X.Fi Dwidth
  1653. Xby
  1654. X.Fi Dheight
  1655. Xpixels.
  1656. XIf the window is too big to fit on the display, its
  1657. Xwidth and height are truncated.
  1658. XThe alternate window's
  1659. X.I window-id
  1660. Xis returned if the window was created successfully.
  1661. XThe macro
  1662. X.Fr m_selectwin
  1663. X is used to write on the newly created window.
  1664. X.Fd int
  1665. X.Fr m_setup mode 
  1666. X.Fs m_setup\(dg 1 "Initialize the library package"
  1667. X.br
  1668. Xint mode;
  1669. X.Ft
  1670. XThis function initializes the library.
  1671. XIt must be called before any other function or macro.
  1672. XThe argument
  1673. X.Fi mode
  1674. Xis one or more of the flags
  1675. X.SM
  1676. X.I M_FLUSH ,
  1677. X.I M_DEBUG ,
  1678. X.LG
  1679. Xor
  1680. X.SM
  1681. X.I M_MODEOK
  1682. X.LG
  1683. X.I or -ed
  1684. Xtogether.
  1685. XIf 
  1686. X.SM
  1687. X.I M_FLUSH
  1688. X.LG
  1689. Xis present, all macros and function flush output to \*M after each
  1690. Xmacro call.  This is slightly less efficient than letting the client
  1691. Xprogram flush the data
  1692. X(see
  1693. X.Fr m_flush
  1694. X )
  1695. Xbut prevent inadvertent buffering problems.
  1696. XThe 
  1697. X.I M_DEBUG
  1698. Xflag forces the macro package to read and write from
  1699. X.I stdin
  1700. Xand
  1701. X.I stdout
  1702. Xrespectively.
  1703. XNormally
  1704. X.I /dev/tty
  1705. Xis opened for reading and writing to permit standard input or output
  1706. Xredirection while still maintaining a connection to \*M.
  1707. XIf
  1708. X.I /dev/tty
  1709. Xcan not be opened, as would be the case for clients invoked through
  1710. X.I rsh ,
  1711. Xthe
  1712. X.I M_DEBUG
  1713. Xflag is turned on,
  1714. Xand
  1715. X.I stdin
  1716. Xand
  1717. X.I stdout
  1718. Xare used instead.
  1719. XThe
  1720. X.I M_MODEOK
  1721. Xflag instructs those functions which expect data from \*M
  1722. Xto assume the terminal modes are set appropriately.
  1723. XOtherwise, the functions attempt to turn off character echoing and
  1724. Xturn on line mode before fetching data from \*M.
  1725. XThe functions
  1726. X.Fr m_ttyset
  1727. X and
  1728. X.Fr m_ttyreset
  1729. X can be used to set and reset the terminal modes.
  1730. XThe function
  1731. X.Fr m_setup
  1732. X returns its argument, with the 
  1733. X.I M_DEBUG
  1734. Xflag
  1735. X.I or -ed
  1736. Xin if 
  1737. X.I /dev/tty
  1738. Xcan not be opened.
  1739. X.Fd void
  1740. X.Fr m_ttyreset  
  1741. X.Fs m_ttyreset\(dg 1 "Reset the tty modes"
  1742. X.br
  1743. X.Ft
  1744. XThe terminal modes are restored to their state just
  1745. Xprior to the last call to 
  1746. X.Fr m_ttyset 
  1747. X\&.
  1748. XCalls to 
  1749. X.Fr m_ttyset
  1750. X and
  1751. X.Fr m_ttyreset
  1752. X may be stacked up to ten levels.
  1753. X.Fd int
  1754. X.Fr m_ttyset  
  1755. X.Fs m_ttyset\(dg 1 "Set the tty modes for proper \*M interaction"
  1756. X.br
  1757. X.Ft
  1758. XThe terminal is set in a state suitable for data exchange with \*M.
  1759. XCharacter echoing is turned off, and line processing mode
  1760. Xis enabled.
  1761. XThe function returns zero (0) if it successfully retrieves the terminal
  1762. Xmodes, -1 otherwise.
  1763. X.RE
  1764. END_OF_FILE
  1765. # end of 'doc/usrman/doc.5'
  1766. fi
  1767. if test -f 'src/startup.c' -a "${1}" != "-c" ; then 
  1768.   echo shar: Will not clobber existing file \"'src/startup.c'\"
  1769. else
  1770. echo shar: Extracting \"'src/startup.c'\" \(9609 characters\)
  1771. sed "s/^X//" >'src/startup.c' <<'END_OF_FILE'
  1772. X/*                        Copyright (c) 1987 Bellcore
  1773. X *                            All Rights Reserved
  1774. X *       Permission is granted to copy or use this program, EXCEPT that it
  1775. X *       may not be sold for profit, the copyright notice must be reproduced
  1776. X *       on copies, and credit should be given to Bellcore where it is due.
  1777. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  1778. X */
  1779. X/*    $Header: startup.c,v 4.3 88/06/28 17:41:01 bianchi Exp $
  1780. X    $Source: /tmp/mgrsrc/src/RCS/startup.c,v $
  1781. X*/
  1782. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/RCS/startup.c,v $$Revision: 4.3 $";
  1783. X
  1784. X/* read and process startup file */ /* this needs to be redone */
  1785. X
  1786. X#include <stdio.h>
  1787. X#include "bitmap.h"
  1788. X#include "defs.h"
  1789. X#include "font.h"
  1790. X
  1791. X#define MAXLINE        128
  1792. X#define MAXFIELDS    100
  1793. X
  1794. Xstruct font *Get_font();
  1795. X
  1796. Xstatic int newx = -1, newy = -1, newdx, newdy, newfont, newflags;
  1797. Xstatic char newinit[MAXLINE];
  1798. Xstatic char *newshell[MAXFIELDS];
  1799. Xstatic char newstart[MAXLINE];
  1800. Xstatic char *initcmd, *suspendcmd, *resumecmd, *quitcmd;
  1801. X
  1802. Xstartup(name)        /* do startup file */
  1803. Xchar *name;        /* name of startup file */
  1804. X   {
  1805. X   FILE *file = fopen(name,"r");        /* file to read commands from */
  1806. X   int x=0 ,y=0 ,dx=0 ,dy=0 ,fnt=0 ;        /* window coords, font # */
  1807. X   char *trans(), *save_line(), *strcat();
  1808. X   char line[MAXLINE];                /* space to store stuff */
  1809. X   char start[MAXLINE];                /*  "  */
  1810. X   char init[MAXLINE];                /*  "  */
  1811. X   char *shell[MAXFIELDS];            /*  "  */
  1812. X   char *fields[MAXFIELDS];            /*  "  */
  1813. X   int curr_font = 0;                /* font # for this window */
  1814. X   int flags = 0;                /* window flags */
  1815. X   register int i;
  1816. X   int count,  gotwindow = 0, gotnewwindow = 0;            
  1817. X   int setactive = 0, activesetid = 0;
  1818. X   int windowsetid = 0;
  1819. X
  1820. X   bzero(start,MAXLINE);
  1821. X   bzero(line,MAXLINE);
  1822. X   bzero(init,MAXLINE);
  1823. X   bzero(shell,MAXFIELDS);
  1824. X   bzero(fields,MAXFIELDS);
  1825. X
  1826. X   if (file == NULL) 
  1827. X      return(-1);
  1828. X
  1829. X
  1830. X   /* process each line in startup file */
  1831. X
  1832. X   while (fgets(line,sizeof(line),file) != NULL) {
  1833. X#ifdef DEBUG
  1834. X      dprintf(S)(stderr,"*** got: %s \r\n",line);
  1835. X#endif
  1836. X      count = parse(line,fields);
  1837. X
  1838. X      if (*fields == (char *) 0)
  1839. X         continue;
  1840. X
  1841. X      else if (strcmp(*fields,"window")==0 || strcmp(*fields,"done")==0) {
  1842. X
  1843. X         if (gotnewwindow==1) {
  1844. X        gotnewwindow = 0;
  1845. X        newx = x;
  1846. X        newy = y;
  1847. X        newdx = dx;
  1848. X        newdy = dy;
  1849. X        newfont = curr_font;
  1850. X        strcpy(newstart, start);
  1851. X        strcpy(newinit, init);
  1852. X        for( i = 0; shell[i]; i++ ) {
  1853. X           if( newshell[i] )
  1854. X          free( newshell[i] );
  1855. X           newshell[i] = shell[i];
  1856. X           shell[i] = (char*)0;
  1857. X           }
  1858. X            gotwindow = 0;
  1859. X        newshell[i] = (char*)0;
  1860. X            gotwindow = 0;
  1861. X            bzero(start,MAXLINE);
  1862. X            bzero(init,MAXLINE);
  1863. X            curr_font = 0;
  1864. X            flags = 0;
  1865. X        windowsetid = 0;
  1866. X        }
  1867. X      /* got a window */
  1868. X
  1869. X         if (gotwindow==1) {
  1870. X            if (check_window(x,y,dx,dy,curr_font) == 0) {
  1871. X               gotwindow = 0;
  1872. X               bzero(start,MAXLINE);
  1873. X               bzero(init,MAXLINE);
  1874. X               curr_font = 0;
  1875. X               flags = 0;
  1876. X           windowsetid = 0;
  1877. X               continue;
  1878. X               }
  1879. X
  1880. X        if( !active ) {
  1881. X           MOUSE_OFF(mousex,mousey);
  1882. X               erase_win(screen,0,0);
  1883. X           MOUSE_ON(mousex,mousey);
  1884. X        }
  1885. X            dowindow( x, y, dx, dy, curr_font, shell, flags, init, start );
  1886. X
  1887. X        if( windowsetid ) {
  1888. X           ACTIVE(setid) = windowsetid;
  1889. X           windowsetid = 0;
  1890. X        }
  1891. X
  1892. X        if( setactive  &&  activesetid == 0 )
  1893. X           activesetid = ACTIVE(setid);
  1894. X   
  1895. X            if( setactive )
  1896. X           topwin( activesetid, -1 );
  1897. X        if( *shell )
  1898. X           free( *shell );
  1899. X            *shell = '\0';
  1900. X            flags = 0;
  1901. X            bzero(start,MAXLINE);
  1902. X            bzero(init,MAXLINE);
  1903. X            curr_font = 0;
  1904. X            }
  1905. X
  1906. X         if (strcmp(*fields,"window")==0 && count >=5) {
  1907. X
  1908. X            gotwindow = 1;
  1909. X            x = atoi(fields[1]);
  1910. X            y = atoi(fields[2]);
  1911. X            dx = atoi(fields[3]);
  1912. X            dy = atoi(fields[4]);
  1913. X            if (count > 5 && (fnt=atoi(fields[5]))<=MAXFONT) {
  1914. X           char lastchar();
  1915. X           struct font *fp = Get_font( fnt );
  1916. X
  1917. X           if( lastchar( fields[3] ) == 'c' )
  1918. X          dx = dx*fp->head.wide + 2*SUM_BDR;
  1919. X           if( lastchar( fields[4] ) == 'c' )
  1920. X          dy = dy*fp->head.high + 2*SUM_BDR;
  1921. X               curr_font = fnt;
  1922. X           }
  1923. X            }
  1924. X         else
  1925. X            gotwindow = 0;
  1926. X         }
  1927. X
  1928. X      else if (strcmp(*fields,"initcmd")==0 && count >2) {
  1929. X        save_fields( &initcmd, fields );
  1930. X        do_cmd( 'i' );
  1931. X     }
  1932. X      else if (strcmp(*fields,"suspendcmd")==0 && count >2) {
  1933. X        save_fields( &suspendcmd, fields );
  1934. X     }
  1935. X      else if (strcmp(*fields,"resumecmd")==0 && count >2) {
  1936. X        save_fields( &resumecmd, fields );
  1937. X     }
  1938. X      else if (strcmp(*fields,"quitcmd")==0 && count >2) {
  1939. X        save_fields( &quitcmd, fields );
  1940. X     }
  1941. X      else if (strcmp(*fields,"font")==0 && count >2) {
  1942. X         fnt = atoi(fields[1]);
  1943. X#ifdef DEBUG
  1944. X         dprintf(S)(stderr,"got font %s (%d)\r\n",fields[2],fnt);
  1945. X#endif
  1946. X         if (fnt > 0  &&  fnt <= MAXFONT) {
  1947. X            if (fontlist[fnt-1])
  1948. X               free(fontlist[fnt-1]);
  1949. X            fontlist[fnt-1] = save_line(fields[2]);
  1950. X            }
  1951. X         }
  1952. X
  1953. X      else if (strcmp(*fields,"map")==0 && count >8) {
  1954. X         for(i=0;i<8;i++)
  1955. X            map_mouse(i,atoi(fields[i+1]));
  1956. X#ifdef DEBUG
  1957. X         dprintf(S)(stderr,"got mouse map \r\n");
  1958. X#endif
  1959. X         }
  1960. X
  1961. X      else if (strcmp(*fields,"slide")==0 && count > 2) {
  1962. X         set_slide(atoi(fields[1]),atoi(fields[2]));
  1963. X#ifdef DEBUG
  1964. X         dprintf(S)(stderr,"set menu slide %d,%d\r\n",
  1965. X                    atoi(fields[1]),atoi(fields[2]));
  1966. X#endif
  1967. X         }
  1968. X
  1969. X      else if (strcmp(*fields,"page")==0 && count > 2) {
  1970. X         set_page(atoi(fields[1]),atoi(fields[2]));
  1971. X#ifdef DEBUG
  1972. X         dprintf(S)(stderr,"set menu page %d,%d\r\n",
  1973. X                    atoi(fields[1]),atoi(fields[2]));
  1974. X#endif
  1975. X         }
  1976. X
  1977. X      else if (strcmp(*fields,"active")==0 && gotwindow==1) {
  1978. X     setactive = 1;
  1979. X     activesetid = 0;
  1980. X      }
  1981. X      else if (strcmp(*fields,"windowsetid")==0 && count>1 && gotwindow==1) {
  1982. X     windowsetid = atoi( fields[1] );
  1983. X      }
  1984. X      else if (strcmp(*fields,"newwindow")==0 && gotwindow==1) {
  1985. X     gotnewwindow = 1;
  1986. X      }
  1987. X      else if (strcmp(*fields,"shell")==0 && count>1 && gotwindow==1) {
  1988. X         for(i=0;i<count-1;i++) {
  1989. X            if (shell[i])
  1990. X               free(shell[i]);
  1991. X            shell[i] = save_line(fields[i+1]);
  1992. X            }
  1993. X         if (shell[count-1]) {
  1994. X            free (shell[count-1]);
  1995. X            shell[count-1] = (char *) 0;
  1996. X            }
  1997. X         }
  1998. X      else if (strcmp(*fields,"init")==0) {
  1999. X         for(i=1;fields[i]!=(char *)0;i++) {
  2000. X        if( i > 1 )
  2001. X           strcat(init," ");
  2002. X            strcat(init,fields[i]);
  2003. X        }
  2004. X         trans(init);
  2005. X         }
  2006. X
  2007. X      else if (strcmp(*fields,"start")==0) {
  2008. X         for(i=1;fields[i]!=(char *)0;i++) {
  2009. X        if( i > 1 )
  2010. X           strcat(start," ");
  2011. X            strcat(start,fields[i]);
  2012. X        }
  2013. X         trans(start);
  2014. X         }
  2015. X
  2016. X      else if (strcmp(*fields,"flags")==0 && count > 1 && gotwindow==1) {
  2017. X         for(i=1;i<count;i++) {
  2018. X            if (strcmp(fields[i],"expose")==0)
  2019. X               flags |= W_EXPOSE;
  2020. X            else if (strcmp(fields[i],"background")==0)
  2021. X               flags |= W_BACKGROUND;
  2022. X            else if (strcmp(fields[i],"nokill")==0)
  2023. X               flags |= W_NOKILL;
  2024. X#ifdef DEBUG
  2025. X            dprintf(S)(stderr,"Flags: %d (%s)\r\n",flags,fields[i]);
  2026. X#endif
  2027. X            }
  2028. X         }
  2029. X
  2030. X      else {
  2031. X#ifdef DEBUG
  2032. X         dprintf(S)(stderr,"invalid line: %s\r\n",line);
  2033. X#endif
  2034. X         }
  2035. X      }
  2036. X   fclose(file);
  2037. X   return(0);
  2038. X   }
  2039. X
  2040. X
  2041. X/*    Given a character pointer and a pointer to an array of strings,
  2042. X    catenate the strings into fresh memory and put the address of the copy
  2043. X    into the character pointer.
  2044. X    free() any space originally pointed to by the character pointer.
  2045. X*/
  2046. Xsave_fields( cpp, fields )
  2047. Xchar    **cpp;
  2048. Xchar    *fields[];
  2049. X{
  2050. X    register int    i;
  2051. X    char        savestr[MAXLINE];
  2052. X
  2053. X    if( *cpp )
  2054. X        free( *cpp );
  2055. X    *savestr = '\0';
  2056. X    for( i=1;  fields[i]!=(char *)0;  i++ ) {
  2057. X        if( i > 1 )
  2058. X            strcat(savestr, " ");
  2059. X        strcat(savestr, fields[i]);
  2060. X    }
  2061. X    trans(savestr);
  2062. X    *cpp = save_line( savestr );
  2063. X}
  2064. X
  2065. X
  2066. Xdo_cmd( flag )
  2067. Xchar    flag;
  2068. X{
  2069. X    switch( flag ) {
  2070. X    case 'i':
  2071. X        system( initcmd );
  2072. X        break;
  2073. X    case 's':
  2074. X        system( suspendcmd );
  2075. X        break;
  2076. X    case 'r':
  2077. X        system( resumecmd );
  2078. X        break;
  2079. X    case 'q':
  2080. X        system( quitcmd );
  2081. X        break;
  2082. X    }
  2083. X}
  2084. X
  2085. X
  2086. Xinitwindow()
  2087. X{
  2088. X    dowindow( newx, newy, newdx, newdy, newfont, newshell, newflags,
  2089. X    newinit, newstart );
  2090. X}
  2091. X
  2092. X
  2093. Xstatic
  2094. Xchar
  2095. Xlastchar( cp )
  2096. Xchar *cp;
  2097. X{
  2098. X   int length = strlen(cp);
  2099. X   if( !length )
  2100. X      return '\0';
  2101. X   return  cp[ length-1 ];
  2102. X}
  2103. X
  2104. X
  2105. Xstatic
  2106. Xdowindow( x, y, dx, dy, font, shell, flags, init, start )
  2107. Xint    x, y, dx, dy, font;
  2108. Xchar    *shell[];
  2109. Xint    flags;
  2110. Xchar    *init, *start;
  2111. X{
  2112. X    struct font *fp = Get_font( font );
  2113. X    int i;
  2114. X
  2115. X#ifdef DEBUG
  2116. X    dprintf(S)(stderr,"starting shell %s\r\n",shell ? *shell : "???");
  2117. X#endif
  2118. X    if( x < 0 )
  2119. X       x = 32 + 16*next_windowset_id();
  2120. X    if( y < 0 )
  2121. X       y = 32 + 16*next_windowset_id();
  2122. X    if( dx <= 0 )
  2123. X      dx = 80*fp->head.wide + 2*SUM_BDR;
  2124. X    if( dy <= 0 )
  2125. X      dy = 24*fp->head.high + 2*SUM_BDR;
  2126. X    MOUSE_OFF(mousex,mousey);
  2127. X    create_window(x, y, dx, dy, font, *shell?shell:0);
  2128. X    MOUSE_ON(mousex,mousey);
  2129. X
  2130. X    if (flags)
  2131. X       ACTIVE(flags) |= flags;
  2132. X    if (*init)
  2133. X       put_window(active,init,strlen(init));
  2134. X    if (*start)
  2135. X       i = Write(ACTIVE(to_fd),start,strlen(start));
  2136. X#ifdef DEBUG
  2137. X    dprintf(S)(stderr,"%s: start string %d/%d %s\r\n",ACTIVE(tty),
  2138. X           i,strlen(start),start);
  2139. X#endif
  2140. X}
  2141. END_OF_FILE
  2142. # end of 'src/startup.c'
  2143. fi
  2144. echo shar: End of archive 31 \(of 61\).
  2145. cp /dev/null ark31isdone
  2146. MISSING=""
  2147. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
  2148.     21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 \
  2149.     38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 \
  2150.     55 56 57 58 59 60 61 ; do
  2151.     if test ! -f ark${I}isdone ; then
  2152.     MISSING="${MISSING} ${I}"
  2153.     fi
  2154. done
  2155. if test "${MISSING}" = "" ; then
  2156.     echo You have unpacked all 61 archives.
  2157.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2158. else
  2159.     echo You still need to unpack the following archives:
  2160.     echo "        " ${MISSING}
  2161. fi
  2162. ##  End of shell archive.
  2163. exit 0
  2164.