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

  1. Subject:  v17i031:  MGR, Bellcore window manager, Part30/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 31
  7. Archive-name: mgr/part30
  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 30 (of 61)."
  19. # Contents:  demo/icon/browse.c demo/icon/iconmail.c lib/window.h
  20. #   src/do_button.c src/do_menu.c
  21. # Wrapped by rsalz@papaya.bbn.com on Thu Nov 17 21:05:37 1988
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. if test -f 'demo/icon/browse.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'demo/icon/browse.c'\"
  25. else
  26. echo shar: Extracting \"'demo/icon/browse.c'\" \(9077 characters\)
  27. sed "s/^X//" >'demo/icon/browse.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: browse.c,v 4.2 88/07/19 14:12:58 sau Exp $
  36. X    $Source: /tmp/mgrsrc/demo/icon/RCS/browse.c,v $
  37. X*/
  38. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/icon/RCS/browse.c,v $$Revision: 4.2 $";
  39. X
  40. X/* display bitmap files on window */
  41. X
  42. X#include "term.h"
  43. X#include <signal.h>
  44. X
  45. X#define GAP        3        /* space between icons */
  46. X#define MAXICONS    500        /* max number of icons */
  47. X#define SAVE        2        /* temp bitmap # */
  48. X
  49. X#define dprintf        if(debug)fprintf
  50. X
  51. Xstruct icon_pos {
  52. X   int x,y;                /* position on window */
  53. X   int w,h;                /* size of icon */
  54. X   char *name;                /* name of icon */
  55. X   };
  56. X
  57. Xstruct icon_pos icons[MAXICONS];
  58. Xchar line[MAXLINE];        /* input buffer */
  59. Xchar cwd[MAXLINE];
  60. Xint win_x, win_y;        /* window position */
  61. Xint win_high, win_wide;        /* window size */
  62. Xint f_wide, f_high;        /* font size */
  63. Xint debug;
  64. Xchar **first;            /* pntr to first icon */
  65. Xint invert = 0;
  66. X
  67. Xstruct menu_entry menu1[] = {
  68. X   "reread","r\r","next","n\r", "prev","p\r", "quit","q\r",
  69. X   };
  70. X
  71. Xstruct menu_entry menu2[] = {
  72. X   "reread","r\r","next","n\r",    "quit","q\r"
  73. X   };
  74. X
  75. Xstruct menu_entry menu3[] = {
  76. X   "reread","r\r","prev","p\r",    "quit","q\r"
  77. X   };
  78. X
  79. Xstruct menu_entry menu4[] = {
  80. X   "reread","r\r","quit","q\r"
  81. X   };
  82. X
  83. Xmain(argc,argv)
  84. Xchar **argv;
  85. X   {
  86. X   int page = 1;            /* current page number */
  87. X   int count;                /* number of icons on page */
  88. X   int x,y;                /* mouse position */
  89. X   int n = -1;                /* current icon */
  90. X   int clean();
  91. X   char *getenv();
  92. X   FILE *popen(), *fd = popen("/bin/pwd","r");
  93. X
  94. X   ckmgrterm( *argv );
  95. X
  96. X   debug = (int) getenv("DEBUG");
  97. X
  98. X   if (fd) {
  99. X      fgets(cwd,sizeof(cwd),fd);
  100. X      *(cwd + strlen(cwd) - 1) = '\0';    /* blah */
  101. X      dprintf(stderr,"Got cwd: [%s]\n",cwd);
  102. X      pclose(fd);
  103. X      }
  104. X   else {
  105. X      fprintf(stderr,"%s: can't get current directory\n",*argv);
  106. X      exit(2);
  107. X      }
  108. X
  109. X   if (argc <2 || argc > MAXICONS) {
  110. X      fprintf(stderr,"usage: %s icons... (up to %d)\n",*argv,MAXICONS);
  111. X      exit(1);
  112. X      }
  113. X
  114. X   if (strcmp(argv[1],"-r")==0) {
  115. X      invert++;
  116. X      argv++;
  117. X      argc--;
  118. X      }
  119. X
  120. X   first = ++argv;
  121. X   argc--;
  122. X
  123. X   m_setup(M_FLUSH);
  124. X   m_push(P_BITMAP|P_MENU|P_EVENT|P_FLAGS);
  125. X   m_ttyset();
  126. X
  127. X   menu_load(1,4,menu1);
  128. X   menu_load(2,3,menu2);
  129. X   menu_load(3,3,menu3);
  130. X   menu_load(4,2,menu4);
  131. X
  132. X   signal(SIGINT,clean);
  133. X   signal(SIGTERM,clean);
  134. X
  135. X   m_setmode(M_ABS);
  136. X   m_setmode(M_NOWRAP);
  137. X   get_size(&win_x,&win_y,&win_wide, &win_high);
  138. X   get_font(&f_wide, &f_high);
  139. X
  140. X   m_setevent(BUTTON_1,"^%p\r");
  141. X   m_setevent(BUTTON_1U,"$\r");
  142. X   m_setevent(MOVE,"M\r");
  143. X   m_setevent(RESHAPED,"R\r");
  144. X   m_setevent(REDRAW,"r\r");
  145. X
  146. X   count = fill_page(first,icons);
  147. X
  148. X   if (count == 0) {
  149. X      fprintf(stderr,"%s: no files in icon format\n",*--argv);
  150. X      clean(3);
  151. X      }
  152. X
  153. X   set_menu(first-argv,argc-count-(first-argv)-1);
  154. X
  155. X   dprintf(stderr,"Got %d,%d %dx%d [%dx%d]\n",
  156. X           win_x, win_y, win_wide, win_high, f_wide, f_high);
  157. X
  158. X   while(m_gets(line) != NULL) {
  159. X      dprintf(stderr,"Got [%s]\n",line);
  160. X      switch(*line) {
  161. X     case 'q':
  162. X        clean(0);
  163. X        break;
  164. X         case ':':        /* got a message - send current icon back */
  165. X            sscanf(line+1,"%d",&x);
  166. X            if (n >= 0) {
  167. X               m_sendto(x,icons[n].name);
  168. X               dprintf(stderr,"sent [%s] to %d\n",
  169. X                       icons[n].name,x);
  170. X               }
  171. X            break;
  172. X         case '^':        /* button down */
  173. X            sscanf(line+1,"%d %d",&x,&y);
  174. X            n = find_icon(icons,x,y);
  175. X            if (n >= 0) {
  176. X               border(icons[n],B_SET);
  177. X               sprintf(line,"%s/%s",cwd,icons[n].name);
  178. X               m_setevent(NOTIFY,line);
  179. X               sprintf(line,"%s (%d x %d)", icons[n].name,
  180. X            icons[n].w, icons[n].h);
  181. X               pop_text(line, icons[n].x+icons[n].w/2,
  182. X                                      icons[n].y+icons[n].h + GAP);
  183. X               border(icons[n],B_CLEAR);
  184. X               }
  185. X            break;
  186. X         case 'n':        /* next icons */
  187. X               if ((first-argv) + count >= argc)
  188. X                  break;
  189. X               first += 2*count/3 + 1;
  190. X               count = fill_page(first,icons);
  191. X               set_menu(first-argv,argc-count-(first-argv)-1);
  192. X               break;
  193. X         case 'p':        /* previous icons */
  194. X               if (first == argv)
  195. X                   break;
  196. X               first -= 2*count/3 + 1 ;
  197. X               if (first < argv)
  198. X                  first = argv;
  199. X               count = fill_page(first,icons);
  200. X               set_menu(first-argv,argc-count-(first-argv)-1);
  201. X               break;
  202. X         case 'M':        /* window moved */
  203. X               get_size(&win_x,&win_y,&win_wide, &win_high);
  204. X               break;
  205. X         case 'r':        /* window  redrawn  */
  206. X               count = fill_page(first,icons);
  207. X               set_menu(first-argv,argc-count-(first-argv)-1);
  208. X            break;
  209. X         case 'R':        /* window shaped*/
  210. X               dprintf(stderr,"Got %d,%d %dx%d [%dx%d]\n",
  211. X                       win_x, win_y, win_wide, win_high, f_wide, f_high);
  212. X               x = win_wide;
  213. X               y = win_high;
  214. X               get_size(&win_x,&win_y,&win_wide, &win_high);
  215. X               if (y != win_high || x>win_wide) {
  216. X                  count = fill_page(first,icons);
  217. X                  set_menu(first-argv,argc-count-(first-argv)-1);
  218. X                  }
  219. X            break;
  220. X         default:        /* button up (let go of button too fast) */
  221. X            break;
  222. X         }
  223. X      }
  224. X   clean(0);
  225. X   }
  226. X
  227. Xint
  228. Xfill_page(names,icon)
  229. Xchar **names;
  230. Xstruct icon_pos *icon;
  231. X   {
  232. X   register int count = 0;
  233. X   int x=GAP, y=GAP;            /* current icon position */
  234. X   int w,h;                /* current icon size */
  235. X   int maxh = 0;            /* max y extent of icons */
  236. X
  237. X   if (invert)
  238. X      m_func(B_COPYINVERTED);
  239. X   else
  240. X      m_func(B_COPY);
  241. X   m_clear();
  242. X   for(;*names;names++) {
  243. X      if (**names == '/')
  244. X         m_bitfile(1,*names, &w, &h);
  245. X      else {
  246. X         m_bitfile(1,sprintf(line,"%s/%s",cwd,*names), &w, &h);
  247. X         }
  248. X      dprintf(stderr,"getting %s -> %s",*names,line);
  249. X      if (w==0 || h == 0)
  250. X         continue;
  251. X
  252. X      if (w + x + 2*GAP > win_wide) {
  253. X         x = GAP;
  254. X         y += maxh + GAP;
  255. X         maxh = 0;
  256. X         }
  257. X
  258. X      if (y + h + GAP > win_high) {
  259. X         dprintf(stderr,"%s won't fit\n",*names);
  260. X         break;
  261. X         }
  262. X
  263. X      m_movecursor(x,y);
  264. X      m_bitcopyto(x,y,w,h,0,0,0,1);
  265. X      count++;
  266. X      icon->x = x;
  267. X      icon->y = y;
  268. X      icon->w = w;
  269. X      icon->h = h;
  270. X      icon->name = *names;
  271. X
  272. X      icon++;
  273. X      x += w + GAP;
  274. X      maxh = h>maxh ? h : maxh;
  275. X      }
  276. X   icon->x = -1;
  277. X   m_movecursor(0,win_high-f_high-GAP);
  278. X   return(count);
  279. X   }
  280. X
  281. Xclean(code)
  282. Xint code;
  283. X   {
  284. X    m_bitdestroy(1);
  285. X   m_pop();
  286. X   m_ttyreset();
  287. X   exit(code);
  288. X   }
  289. X
  290. X/* border an icon */
  291. X
  292. Xborder(icon,how)
  293. Xstruct icon_pos icon;
  294. Xint how;
  295. X   {
  296. X   int x=icon.x, y=icon.y, w=icon.w, h=icon.h;
  297. X   dprintf(stderr,"border: %d,%d %dx%d\n",x,y,w,h);
  298. X
  299. X   m_func(how);
  300. X   m_bitwrite(x-GAP,y-GAP,w+2*GAP,GAP);
  301. X   m_bitwrite(x-GAP,y+h,w+2*GAP,GAP);
  302. X   m_bitwrite(x-GAP,y,GAP,h);
  303. X   m_bitwrite(x+w,y,GAP,h);
  304. X   }
  305. X   
  306. X/* find an icon */
  307. X
  308. Xint
  309. Xfind_icon(icon,x,y)
  310. Xregister struct icon_pos *icon;
  311. Xregister int x,y;
  312. X   {
  313. X   register int i = 0;
  314. X
  315. X   dprintf(stderr,"Looking for: %d %d [%d]\n",x,y);
  316. X
  317. X   for(;icon->x != -1;i++,icon++)  {
  318. X      if (y>icon->y && x>icon->x &&
  319. X                       y < icon->y + icon->h &&
  320. X                       x < icon->x + icon->w) {
  321. X         dprintf(stderr,"found %d\n",i);
  322. X         return(i);
  323. X         }
  324. X      }
  325. X   return(-1);
  326. X   }
  327. X   
  328. Xpop_text(s,x,y)
  329. Xchar *s;        /* text to display */
  330. Xint x,y;        /* center of window */
  331. X   {
  332. X   int wide = (strlen(s)<5?5:strlen(s)) * f_wide + 10;
  333. X   int high = f_high + 4*GAP;
  334. X   int x0 = x - wide/2;
  335. X   int y0 = y + f_high;
  336. X
  337. X   if (x0<0)
  338. X      x0 = GAP;
  339. X   if (x0+wide > win_wide)
  340. X      x0 = win_wide-wide-GAP;
  341. X   if (y0+high > win_high - f_wide)
  342. X      y0 = GAP;
  343. X
  344. X   if (x0 < 0 || y0 + high > win_high - f_wide-GAP < 0) {
  345. X      m_gets(line);
  346. X      return(1);
  347. X      }
  348. X
  349. X   /* save current window text */
  350. X
  351. X   m_func(B_SRC);
  352. X   m_bitcopyto(0,0,wide,high,x0,y0,SAVE,0);
  353. X
  354. X   /* draw border */
  355. X
  356. X   m_func(B_SET);
  357. X   m_bitwrite(x0,y0,wide,high);
  358. X   m_func(B_CLEAR);
  359. X   m_bitwrite(x0+GAP,y0+GAP,wide-2*GAP,high-2*GAP);
  360. X   m_moveprint(x0+2*GAP,y0+(high-f_high)/2+GAP+f_high,s);
  361. X   m_movecursor(win_wide,y);
  362. X
  363. X   m_gets(line);
  364. X
  365. X   /* restore data */
  366. X
  367. X   m_func(B_SRC);
  368. X   m_bitcopyto(x0,y0,wide,high,0,0,0,SAVE);
  369. X   m_bitdestroy(SAVE);
  370. X   }
  371. X
  372. Xint
  373. Xset_menu(front,back)
  374. Xint front;
  375. Xint back;
  376. X   {
  377. X   register int i;
  378. X   if (front>0 && back>0)
  379. X      i = 1;
  380. X   else if (front > 0)
  381. X      i = 3;
  382. X   else if (back > 0)
  383. X      i = 2;
  384. X   else
  385. X      i = 4;
  386. X
  387. X   m_selectmenu(i);
  388. X   dprintf(stderr,"set menu %d (%d,%d)\n",i,front,back);
  389. X   return(i);
  390. X   }
  391. END_OF_FILE
  392. # end of 'demo/icon/browse.c'
  393. fi
  394. if test -f 'demo/icon/iconmail.c' -a "${1}" != "-c" ; then 
  395.   echo shar: Will not clobber existing file \"'demo/icon/iconmail.c'\"
  396. else
  397. echo shar: Extracting \"'demo/icon/iconmail.c'\" \(8565 characters\)
  398. sed "s/^X//" >'demo/icon/iconmail.c' <<'END_OF_FILE'
  399. X/*                        Copyright (c) 1987 Bellcore
  400. X *                            All Rights Reserved
  401. X *       Permission is granted to copy or use this program, EXCEPT that it
  402. X *       may not be sold for profit, the copyright notice must be reproduced
  403. X *       on copies, and credit should be given to Bellcore where it is due.
  404. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  405. X */
  406. X/*    $Header: iconmail.c,v 4.2 88/06/30 16:21:42 bianchi Exp $
  407. X    $Source: /tmp/mgrsrc/demo/icon/RCS/iconmail.c,v $
  408. X*/
  409. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/icon/RCS/iconmail.c,v $$Revision: 4.2 $";
  410. X
  411. X/* check for new mail  (icon version) */
  412. X
  413. X#include <sys/types.h>
  414. X#include <sys/stat.h>
  415. X#include <sys/time.h>        /* for fsleep */
  416. X#include <signal.h>
  417. X#include <sgtty.h>
  418. X#include <stdio.h>
  419. X
  420. X#include <term.h>
  421. X#include "mail_icons.h"
  422. X
  423. X#define MSG_READING    "\freading mail ...\r"
  424. X#define MSG_CHECKING    "\rChecking for new mail..."
  425. X
  426. X#define MAILF        "/usr/spool/mail"    /* spool file */
  427. X#define MAIL        "mail"            /* name of mail command */
  428. X#define POLL        60            /* polling interval */
  429. X#define XPOS        240            /* x start of mail window */
  430. X#define YPOS        190            /* y start of mail window */
  431. X#define W_WIDE        80            /* width of mail window */
  432. X#define W_HIGH        24            /* height of mail window */
  433. X#define MAX_ICON    64            /* max icon size */
  434. X
  435. X#define PROCESSED    2            /* new mail already processed */
  436. X
  437. X#define S(x)            statb.x
  438. X#define Isflag(arg,flag)    (!strncmp(arg,flag,strlen(flag)))
  439. X#define Max(x,y)        ((x)>(y)?(x):(y))
  440. X#define dprintf            if(debug) fprintf
  441. X
  442. X#define fsleep() \
  443. X   { \
  444. X   struct timeval time; \
  445. X   time.tv_sec = 0; \
  446. X   time.tv_usec = 330000; \
  447. X   select(0,0,0,0,&time); \
  448. X   }
  449. X
  450. X#define MENU_COUNT        (sizeof(menu)/sizeof(struct menu_entry))
  451. X
  452. Xstruct menu_entry menu[] = {
  453. X    "print","t\r",
  454. X    "delete","dt\r",
  455. X    "next","n\r",
  456. X    "quit","q\r",
  457. X    "help","?\r",
  458. X    "headers","h *\r",
  459. X    "abort","x\r",
  460. X};
  461. X
  462. Xstatic struct    stat statb;    /* spool file status */
  463. Xstatic char    mail[255];    /* spool file path name */
  464. Xstatic long    omtime=0l;    /* previous file mod. time */
  465. Xstatic int    state = 0;    /* mail & window state */
  466. Xstatic int    poll = POLL;    /* poll interval */
  467. Xstatic int    debug=0;    /* for mgrmail -d >& /dev/tty?? */
  468. Xstatic int    x,y;        /* window position */
  469. Xstatic int    w,h;        /* window size */
  470. Xstatic int    border;        /* size of mgr border */
  471. Xstatic int    local=0;    /* use local icon only */
  472. Xstatic int    local_mode = -1;/* local mode bits for tty */
  473. Xstatic int    cwide, chigh;    /* width and height of font characters */
  474. Xstatic char    *termcap;
  475. X
  476. Xmain(argc,argv)
  477. X    char **argv;
  478. X{
  479. X    register int i;
  480. X    int xpos = XPOS;        /* screen position of mail subwindow */
  481. X    int ypos = YPOS;
  482. X    int font = -1;            /* font to use for mail subwindow */
  483. X    int shape = 1;            /* initially reshape window */
  484. X    char *command = MAIL;        /* name of readmail command */
  485. X
  486. X    char *getenv();
  487. X    char *user = getenv("USER");
  488. X    char line[MAXLINE];        /* event input buffer */
  489. X
  490. X    int clean(), update();
  491. X
  492. X    /* make sure environment is ok */
  493. X
  494. X    ckmgrterm( *argv );
  495. X
  496. X    if (user==NULL || *user=='\0') {
  497. X        fprintf(stderr, "%s: No USER environment variable value.\n",
  498. X            argv[0]);
  499. X        exit(2);
  500. X    }
  501. X
  502. X    /* process arguments */
  503. X
  504. X    for(i=1;i<argc;i++) {
  505. X        if (Isflag(argv[i],"-s"))
  506. X            shape = 0;
  507. X        else if (Isflag(argv[i],"-d"))
  508. X            debug = 1;
  509. X        else if (Isflag(argv[i],"-l"))
  510. X            local = 1;
  511. X        else if (Isflag(argv[i],"-x"))
  512. X            xpos = atoi(argv[i]+2);
  513. X        else if (Isflag(argv[i],"-y"))
  514. X            ypos = atoi(argv[i]+2);
  515. X        else if (Isflag(argv[i],"-f"))
  516. X            font = atoi(argv[i]+2);
  517. X        else if (Isflag(argv[i],"-p"))
  518. X            poll  = Max(atoi(argv[i]+2),10);
  519. X        else if (Isflag(argv[i],"-M"))
  520. X            command  = argv[i]+2;
  521. X        else
  522. X            usage(argv[0],argv[i]);
  523. X    }
  524. X    sprintf(mail,"%s/%s",MAILF,user);
  525. X
  526. X    /* set up window environment */
  527. X
  528. X    m_setup(M_FLUSH);
  529. X    m_push(P_MENU|P_BITMAP|P_FONT|P_EVENT|P_FLAGS|P_POSITION);
  530. X    if (font < 0)
  531. X        font = 0;
  532. X    m_font(font);
  533. X    get_font( &cwide, &chigh );
  534. X
  535. X    signal(SIGHUP,clean);
  536. X    signal(SIGTERM,clean);
  537. X    signal(SIGINT,clean);
  538. X    signal(SIGALRM,update);
  539. X
  540. X    dprintf(stderr,"pushing environment\n"); fflush(stderr);
  541. X    m_ttyset();
  542. X    m_setmode(M_NOWRAP);
  543. X    m_setmode(M_ABS);
  544. X    m_func(B_COPY);
  545. X
  546. X    download_icon(&mbox_closed,1);
  547. X    download_icon(&mbox_full,2);
  548. X    download_icon(&mbox_zip,5);
  549. X    download_icon(&mbox_open,6);
  550. X
  551. X    get_size(&x,&y,&w,&h);
  552. X        get_param(0,0,0,&border);
  553. X    m_movecursor(x+30,0);
  554. X
  555. X    m_setmode(M_ACTIVATE);
  556. X    if (shape) {
  557. X        m_shapewindow(x,y,2*border+MAX_ICON, 2*border+MAX_ICON);
  558. X                get_size(&x,&y,&w,&h);
  559. X        }
  560. X
  561. X    m_setevent(ACTIVATE,"A\r");
  562. X    m_setevent(REDRAW,"R\r");
  563. X
  564. X    m_clearmode(M_ACTIVATE);
  565. X        set_icon(mbox_closed);
  566. X
  567. X    dprintf(stderr,"Starting state 0x%x\n",state); fflush(stderr);
  568. X
  569. X    update();
  570. X
  571. X    termcap = getenv("TERMCAP");
  572. X    if( termcap )
  573. X        *termcap = '\0';
  574. X
  575. X    /* wait for an event */
  576. X
  577. X    while(1) {
  578. X        if( m_gets(line) == NULL ) {
  579. X            clearerr( m_termin );
  580. X            continue;
  581. X        }
  582. X        dprintf(stderr,"state 0x%x line : %c\n",state,*line);
  583. X        fflush(stderr);
  584. X        switch(*line) {
  585. X        case 'A':    /* window is activated */
  586. X            if (!stat(mail,&statb) && S(st_size))
  587. X                do_mail(command,font,xpos,ypos);
  588. X            else {
  589. X                set_icon(mbox_open);
  590. X                sleep(2);
  591. X                m_clearmode(M_ACTIVATE);
  592. X            }
  593. X            state &= ~PROCESSED;
  594. X            update();
  595. X            break;
  596. X        case 'R':    /* screen is redrawn */
  597. X            state &= ~PROCESSED;
  598. X            get_size(&x,&y,&w,&h);
  599. X            m_movecursor(x+30,0);
  600. X            update();
  601. X            break;
  602. X        }
  603. X    }
  604. X}
  605. X
  606. X/* run readmail in a subwindow */
  607. X
  608. Xdo_mail(command,font,xpos,ypos)
  609. Xchar *command;
  610. Xint font,xpos,ypos;
  611. X    {
  612. X    int code;
  613. X    int n;
  614. X
  615. X    alarm(0);
  616. X    m_push(P_EVENT | P_FONT);
  617. X    dprintf(stderr,"doing mail\n"); fflush(stderr);
  618. X    n = m_makewindow(xpos, ypos, W_WIDE*cwide + 2*border,
  619. X        W_HIGH*chigh + 2*border);
  620. X    if (n==0) {    /* can't make window */
  621. X        m_printstr("\007\fCan't open mail window, sorry");
  622. X        m_pop();
  623. X        return(0);
  624. X        }
  625. X    /*
  626. X    if( *termcap  &&  newtermcap[0] == '\0' ) {
  627. X        strcpy( newtermcap, get_termcap() );
  628. X        termcap = newtermcap;
  629. X    }
  630. X    */
  631. X      set_icon(mbox_zip);
  632. X    m_selectwin(n);
  633. X    m_font(font);
  634. X    menu_load(1,MENU_COUNT,menu);
  635. X    m_selectmenu(1);
  636. X    m_printstr(MSG_READING);
  637. X    m_ttyreset();
  638. X    code = system(command);
  639. X    m_printstr(MSG_CHECKING);
  640. X    sleep(1);    /* for "New mail arrived" message */
  641. X    dprintf(stderr,"Readmail completed code %d\n",code); fflush(stderr);
  642. X    m_ttyset();
  643. X    m_selectwin(0);
  644. X    m_destroywin(n);
  645. X    m_pop();
  646. X    m_clearmode(M_ACTIVATE);
  647. X    dprintf(stderr,"window deactivated\n"); fflush(stderr);
  648. X    }
  649. X
  650. X/* check the spool file for new mail and update message */
  651. X
  652. Xint
  653. Xupdate()
  654. X{
  655. X    alarm(0);
  656. X    dprintf(stderr,"checking mail state 0x%x\n",state); fflush(stderr);
  657. X    if (!stat(mail,&statb) && S(st_mtime)>S(st_atime) && S(st_size)) {
  658. X        state &= ~PROCESSED;
  659. X        if (S(st_mtime) != omtime) {
  660. X        dprintf(stderr,"    First time New mail\n"); fflush(stderr);
  661. X                        m_printstr("\007");
  662. X              set_icon(mbox_full);
  663. X            omtime = S(st_mtime);
  664. X        }
  665. X    }
  666. X    else if (!(state&PROCESSED)) {
  667. X        dprintf(stderr,"    Clearing new mail\n"); fflush(stderr);
  668. X          set_icon(mbox_closed);
  669. X        state |= PROCESSED;
  670. X    }
  671. X    alarm(poll);
  672. X}
  673. X
  674. X/*    Clean up and exit */
  675. X
  676. Xclean(n)
  677. Xint    n;
  678. X{
  679. X    m_ttyreset();
  680. X    m_selectwin(0);
  681. X    m_popall();
  682. X    exit(n);
  683. X}
  684. X
  685. Xusage(name,error)
  686. Xchar *name, *error;
  687. X{
  688. X    fprintf(stderr,"Invalid flag: %s\n",error);
  689. X    fprintf(stderr,
  690. X        "usage: %s -[s|x<pos>|y<pos>|f<font>|p<poll>|M<mail_program>]\n"
  691. X        ,name);
  692. X    exit(1);
  693. X}
  694. X
  695. X/* down load an icon */
  696. X
  697. Xdownload_icon(icon,where)
  698. Xregister struct icon *icon;    /* name of icon to download */
  699. Xint where;            /* bitmap to download icon to */
  700. X   {
  701. X
  702. X   int size;
  703. X   int w_in=0, h_in=0;
  704. X
  705. X   if (!local) {
  706. X       /* first try the local machine */
  707. X      dprintf(stderr,"looking for %s\n",icon->name);
  708. X      m_bitfile(where, icon->name, &w_in, &h_in );
  709. X      }
  710. X
  711. X   if (h_in==0 || w_in==0) {    /* can't find icon */
  712. X      dprintf(stderr,"Couldn't find %s, downloading\n",icon->name);
  713. X      if (local_mode == -1)
  714. X         ioctl(fileno(m_termout),TIOCLGET,&local_mode);
  715. X      local_mode |= LLITOUT;
  716. X      ioctl(fileno(m_termout),TIOCLSET,&local_mode);
  717. X
  718. X      size = icon->h * (((icon->w+15)&~15)>>3);
  719. X      m_bitldto(icon->w,icon->h,0,0,where,size);
  720. X      m_flush();
  721. X      write(fileno(m_termout),icon->data,size);
  722. X      local_mode &= ~LLITOUT;
  723. X      ioctl(fileno(m_termout),TIOCLSET,&local_mode);
  724. X      }
  725. X   else {
  726. X      dprintf(stderr,"Found %s (%d x %d) expected %d x %d\n",
  727. X               icon->name,w_in,h_in,icon->w,icon->h);
  728. X      icon->w = w_in;
  729. X      icon->h = h_in;
  730. X      }
  731. X   icon->type = where;
  732. X   } 
  733. X
  734. Xset_icon(name)
  735. Xstruct icon name;        /* name of icon */
  736. X   {
  737. X   int x0 = (w-name.w)/2;
  738. X   int y0 = (h-name.h)/2;
  739. X
  740. X   m_clear();
  741. X   m_bitcopyto(x0,y0,name.w,name.h,0,0,0,name.type);
  742. X   dprintf(stderr,"copy %s to %d,%d (%d x %d)from %d\n",
  743. X           name.name,x0,y0,name.w,name.h,name.type);
  744. X   m_flush();
  745. X   }
  746. END_OF_FILE
  747. # end of 'demo/icon/iconmail.c'
  748. fi
  749. if test -f 'lib/window.h' -a "${1}" != "-c" ; then 
  750.   echo shar: Will not clobber existing file \"'lib/window.h'\"
  751. else
  752. echo shar: Extracting \"'lib/window.h'\" \(8727 characters\)
  753. sed "s/^X//" >'lib/window.h' <<'END_OF_FILE'
  754. X/*                        Copyright (c) 1988 Bellcore
  755. X *                            All Rights Reserved
  756. X *       Permission is granted to copy or use this program, EXCEPT that it
  757. X *       may not be sold for profit, the copyright notice must be reproduced
  758. X *       on copies, and credit should be given to Bellcore where it is due.
  759. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  760. X */
  761. X/*    $Header: window.h,v 4.2 88/08/12 07:41:26 sau Exp $
  762. X    $Source: /tmp/mgrsrc/lib/RCS/window.h,v $
  763. X*/
  764. Xstatic char    h_window_[] = "$Source: /tmp/mgrsrc/lib/RCS/window.h,v $$Revision: 4.2 $";
  765. X
  766. X/* defines for terminal emulator */
  767. X
  768. X/* text flags - for commands with text string arguments */
  769. X
  770. X#define T_INVALID    0    /* invalid command */
  771. X#define T_FONT        1    /* down load a new font */
  772. X#define T_MENU        2    /* down load a menu */
  773. X#define T_EVENT        3    /* down load an event string */
  774. X#define T_YANK        4    /* fill the yank bufffer */
  775. X#define T_BITMAP    5    /* down load a bit map */
  776. X#define T_COMMAND    6    /* start a new window & command in it */
  777. X#define T_GIMME        7    /* send me stuff */
  778. X#define T_SMAP        8    /* save a bitmap on a file */
  779. X#define T_GMAP        9    /* read a bitmap from a file */
  780. X#define T_SEND        10    /* send a message to another application */
  781. X#define T_GRUNCH    11    /* fast-draw, short vector mode */
  782. X#define T_STRING    12    /* write a text sting into an offscreen bitmap */
  783. X
  784. X/* option codes for GETMODE / SETMODE  */
  785. X
  786. X#define M_STANDOUT    0    /* window is in standout mode  */
  787. X#define M_WOB        1    /* window is white on black  */
  788. X#define M_AUTOEXPOSE    2    /* expose window upon shell output  */
  789. X#define M_BACKGROUND    3    /* permit obscured window to update  */
  790. X#define M_NOINPUT    4    /* don't accept keyboard input  */
  791. X#define M_NOWRAP    5    /* don't auto wrap  */
  792. X#define M_OVERSTRIKE    6    /* overstrike mode  */
  793. X#define M_ABS        7    /* use absolute coordinates  */
  794. X#define M_ACTIVATE    8    /* activate / hide window; not a mode */
  795. X#define M_STACK        12    /* permit event stacking */
  796. X#define M_DUPKEY    13    /* set keyboard escape key */
  797. X#define M_NOBUCKEY    14    /* prevent mgr processing buckey keys,
  798. X                   pass them through to the application */
  799. X
  800. X/* cut/paste options */
  801. X
  802. X#define M_SNARFLINES    9    /* only snarf entire lines */
  803. X#define M_SNARFTABS    10    /* change spaces to tabs in snarf */
  804. X#define M_SNARFHARD    11    /* snarf even if errors */
  805. X
  806. X/* option codes for GETINFO */
  807. X
  808. X#define G_MOUSE         0    /* mouse coordinates  */
  809. X#define G_TERMCAP     1    /* send back termcap entry  */
  810. X#define G_WINSIZE     2    /* cols, lines  */
  811. X#define G_FONT         3    /* font wide, high, #  */
  812. X#define G_COORDS     4    /* window coords  */
  813. X#define G_STATUS     5    /* window status  */
  814. X#define G_ALL         6    /* complete window status  */
  815. X#define G_SYSTEM     7    /* system status  */
  816. X#define G_ALLFONT     8    /* font information  */
  817. X#define G_TEXT        9    /* text region size */
  818. X#define G_ALLMINE      10    /* window status for client windows */
  819. X#define G_CURSOR    11    /* character/ graphics cursor position */
  820. X#define G_MOUSE2    12    /* cooked mouse coordinates  */
  821. X#define G_NOTIFY    13    /* gimme info re notify windows */
  822. X#define G_ID        14    /* my client window number */
  823. X#define G_FLAGS        15    /* current window flags */
  824. X#define G_MAX        15    /* maximum GETINFO value */
  825. X
  826. X/* option codes for stacking window environment */
  827. X
  828. X#define P_MENU        0x001    /* push menus */
  829. X#define P_EVENT        0x002    /* push events */
  830. X#define P_FONT        0x004    /* push current font */
  831. X#define P_CURSOR    0x008    /* push current cursor position  */
  832. X#define P_BITMAP    0x010    /* push saved bitmaps */
  833. X#define P_POSITION    0x020    /* push window location */
  834. X#define P_WINDOW    0x040    /* push window contents */
  835. X#define P_FLAGS        0x080    /* push window flags */
  836. X#define P_MOUSE        0x100    /* push mouse position */
  837. X#define P_TEXT        0x200    /* push text region */
  838. X
  839. X
  840. X#define P_ALL        0x3ff    /* push everything */
  841. X#define P_MAX        0x400    /* end of codes marker */
  842. X#define P_DEFAULT    (P_MENU | P_EVENT | P_FONT | P_FLAGS | P_TEXT)
  843. X#define P_CLEAR        0x400    /* clear new environment */
  844. X
  845. X/* menu_flags */
  846. X
  847. X#define MF_SNIP        8    /* don't send action for parent of s/o menu */
  848. X#define MF_PAGE        4    /* auto-page for menus */
  849. X#define MF_AUTO        2    /* auto-right exit for menus */
  850. X#define MF_CLEAR    1    /* clear menu flags */
  851. X
  852. X/* Escape codes */
  853. X
  854. X#define ESC        '\033'    /* escape character */
  855. X
  856. X#define E_MINUS        '-'    /* set the munus flag */
  857. X#define E_SEP1        ','    /* primary field seperator */
  858. X#define E_SEP2        ';'    /* secondary field seperator */
  859. X#define E_MOUSE        '?'    /* testing  -- move the mouse  */
  860. X#define E_ADDLINE    'a'    /* add a new line  */
  861. X#define E_ADDCHAR    'A'    /* add a character  */
  862. X#define E_BITBLT    'b'    /* do a bit blit  */
  863. X#define E_BITCRT    'B'    /* create a bit blit  */
  864. X#define E_CLEAREOL    'c'    /* clear  */
  865. X#define E_CLEAREOS    'C'    /* clear  */
  866. X#define E_DELETELINE    'd'    /* delete a line */
  867. X#define E_BITLOAD    'D'    /* download a bitmap  */
  868. X#define E_EVENT        'e'    /* download events  */
  869. X#define E_DELETECHAR    'E'    /* delete a char */
  870. X#define E_DOWN        'f'    /* down 1 line */
  871. X#define E_FONT        'F'    /* pick a new font  */
  872. X#define E_GO        'g'    /* Go; move graphics pointer  */
  873. X#define E_MOVE        'G'    /* move to x,y pixels  */
  874. X#define E_SETCURSOR    'h'    /* select cursor style */
  875. X#define E_BLEEP        'H'    /* blink a section of the screen */
  876. X#define E_GETINFO    'I'    /* get info from mgr */
  877. X#define E_STANDOUT    'i'    /* start standout mode */
  878. X#define E_FCOLOR    'j'    /* set forground color */
  879. X#define E_BCOLOR    'J'    /* set background color */
  880. X#define E_LINE        'l'    /* Plot a line  */
  881. X#define E_LINK        'L'    /* menu links */
  882. X#define E_MENU        'm'    /* download menus */
  883. X#define E_CUP        'M'    /* move to col, row (zero origin)  */
  884. X#define E_STANDEND    'n'    /* end standout mode */
  885. X#define E_CIRCLE    'o'    /* Plot a circle or an ellipse or an arc */
  886. X#define E_PUSH        'P'    /* push window environment */
  887. X#define E_POP        'p'    /* pop window environment */
  888. X#define E_RUBBER    'R'    /* rubber band a line/rect (obsolete) */
  889. X#define E_RIGHT        'r'    /* right 1 column  */
  890. X#define E_CLEARMODE    's'    /* clear window mode */
  891. X#define E_SETMODE    'S'    /* set a window mode */
  892. X#define E_TEXTREGION    't'    /* set the text region */
  893. X#define E_UPLINE    'u'    /* up 1 line  */
  894. X#define E_BITGET    'U'    /* upload a bitmap  */
  895. X#define E_SHAPE        'W'    /* reshape window, make it active  */
  896. X#define E_SIZE        'w'    /* reshape window: cols,rows  */
  897. X#define E_GIMME        'x'    /* send me data */
  898. X#define E_PUTSNARF    'y'    /* put the snarf buffer  */
  899. X#define E_SNARF        'Y'    /* snarf text into the snarf buffer  */
  900. X#define E_VI        'V'    /* set vi mode */
  901. X#define E_NOVI        'v'    /* turn off vi mode */
  902. X#define E_HALFWIN    'z'    /* make a 1/2 window */
  903. X#define E_MAKEWIN    'Z'    /* make/goto a new window */
  904. X#define E_NULL        '$'    /* do nothing, force exit */
  905. X#define E_SMAP        '>'    /* save a bitmap */
  906. X#define E_GMAP        '<'    /* get a bitmap */
  907. X#define E_SEND        '|'    /* send a message to another application */
  908. X#define E_CURSOR    '%'    /* set mouse cursor */
  909. X#define E_GRUNCH    ':'    /* graphics crunch mode (experimental) */
  910. X#define E_STRING    '.'    /* write characters in offscreen bitmap */
  911. X#ifdef XMENU
  912. X#define E_XMENU        'X'    /* extended menu operations */
  913. X#endif
  914. X
  915. X
  916. X/* misc */
  917. X
  918. X#define C_NOCHAR    '?'    /* for character not in font */
  919. X#define C_EXPOSED    'e'    /* window is not obscured */
  920. X#define C_ACTIVE    'a'    /* window has input focus */
  921. X#define C_NOTACTIVE    'n'    /* window is obscured */
  922. X#define C_OBSCURED    'o'    /* window is obscured */
  923. X#define C_NAME        "px|mgr|mgr teminal emulator"
  924. X
  925. X#define C_NULL        '\000'    /* null */
  926. X#define C_BS        '\b'    /* back space */
  927. X#define C_FF        '\f'    /* form feed */
  928. X#define C_BELL        '\007'    /* bell */
  929. X#define C_TAB        '\t'    /* tab */
  930. X#define C_RETURN    '\r'    /* return */
  931. X#define C_NL        '\n'    /* line feed */
  932. X
  933. X/* cursor styles */
  934. X#define CS_BLOCK        0        /* standard block cursor */
  935. X#define CS_LEFT        1        /* left vertical bar */
  936. X#define CS_RIGHT        2        /* right vertical bar */
  937. X#define CS_BOX            3        /* outline */
  938. X#define CS_UNDER        4        /* underline */
  939. X
  940. X/* some raster op functions  (for bit_copy) */
  941. X
  942. X#ifndef BIT_NOT
  943. X#define BIT_NOT(x)    (~(x))        /* from bitmap.h */
  944. X#endif
  945. X#define B_SRC        (0xc)
  946. X#define B_DST        (0xa)
  947. X#define B_OR        (B_SRC|B_DST)
  948. X#define B_COPY        (B_SRC)
  949. X#define B_COPYINVERTED    ((BIT_NOT(B_SRC))&0xf)
  950. X#define B_XOR        (B_SRC^B_DST)
  951. X#define B_AND        (B_SRC&B_DST)
  952. X
  953. X/* raster op functions  (for bit_write and bit_line) */
  954. X
  955. X#define B_SET        (0xf)
  956. X#define B_CLEAR        (0x0)
  957. X#define B_INVERT    ((BIT_NOT(B_DST))&0xf)
  958. X
  959. X/* where to find icon directory */
  960. X
  961. X#ifndef ICONDIR
  962. X#  define ICONDIR        "/usr/mgr/icon"    /* readable by all icons */
  963. X#endif
  964. X
  965. X/* other macros */
  966. X
  967. X#define Scalex(x) \
  968. X    (W(flags)&W_ABSCOORDS ?  (x) :  (x) * (int)BIT_WIDE(W(window))/GMAX)
  969. X#define Scaley(y) \
  970. X    (W(flags)&W_ABSCOORDS ?  (y) :  (y) * (int)BIT_HIGH(W(window))/GMAX)
  971. X#define Scalexy(y) \
  972. X    (W(flags)&W_ABSCOORDS ?  (y) : \
  973. X     (y) * (int)(BIT_HIGH(W(window))+BIT_WIDE(W(window)))/(2*GMAX))
  974. X
  975. X#define FSIZE(c)    ((int) (W(font)->head.c))
  976. X#define WIDE            BIT_WIDE(window)
  977. X#define HIGH            BIT_HIGH(window)
  978. X#define T_WIDE            BIT_WIDE(text)
  979. X#define T_HIGH            BIT_HIGH(text)
  980. END_OF_FILE
  981. # end of 'lib/window.h'
  982. fi
  983. if test -f 'src/do_button.c' -a "${1}" != "-c" ; then 
  984.   echo shar: Will not clobber existing file \"'src/do_button.c'\"
  985. else
  986. echo shar: Extracting \"'src/do_button.c'\" \(8518 characters\)
  987. sed "s/^X//" >'src/do_button.c' <<'END_OF_FILE'
  988. X/*                        Copyright (c) 1987 Bellcore
  989. X *                            All Rights Reserved
  990. X *       Permission is granted to copy or use this program, EXCEPT that it
  991. X *       may not be sold for profit, the copyright notice must be reproduced
  992. X *       on copies, and credit should be given to Bellcore where it is due.
  993. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  994. X */
  995. X/*    $Header: do_button.c,v 4.2 88/06/28 15:25:58 bianchi Exp $
  996. X    $Source: /tmp/mgrsrc/src/RCS/do_button.c,v $
  997. X*/
  998. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/RCS/do_button.c,v $$Revision: 4.2 $";
  999. X
  1000. X/* Figure out what to do with a button push */
  1001. X
  1002. X#include "bitmap.h"
  1003. X#include <stdio.h>     /* temporary */
  1004. X#include <sys/signal.h>
  1005. X#include "menu.h"
  1006. X#include "defs.h"
  1007. X#include "font.h"
  1008. X#include "event.h"
  1009. X
  1010. Xdo_button(button)
  1011. Xint button;
  1012. X   {
  1013. X   register WINDOW *win;        /* window of interest */
  1014. X   int choice;                /* current menu choice */
  1015. X   int choice_ok;            /* valid choice flag */
  1016. X   struct menu_state *state;        /* place to keep menu state */
  1017. X   register int which_menu;        /* which menu indicator */
  1018. X
  1019. X#ifdef DEBUG
  1020. X   dprintf(b)(stderr,"do button %d (button state id %d)\n",button,button_state);
  1021. X#endif
  1022. X
  1023. X   /*    Insist on a transition before taking any action.
  1024. X   */
  1025. X   if( button == button_state )
  1026. X      return;
  1027. X
  1028. X   /*    Other button codes, such as chords, are not recognized and have no
  1029. X    effect.
  1030. X   */
  1031. X   switch( button ) {
  1032. X   case 0:
  1033. X   case BUTTON_SYS:
  1034. X   case BUTTON_2:
  1035. X   case BUTTON_1:
  1036. X    break;
  1037. X   default:
  1038. X    return;
  1039. X   }
  1040. X
  1041. X   /*    If button was down and now no button is down,
  1042. X        send the event stating the formerly down button is now up.
  1043. X    If some button is down, the same or some other,
  1044. X        do nothing.
  1045. X    Note that this creates a fundmental property of MGR:  namely that
  1046. X    once a button is pressed, no other button pressings have any effect
  1047. X    until all buttons are released.
  1048. X   */
  1049. X   if( button_state ) {
  1050. X      if ( button == 0 ) {
  1051. X     int    b_event = -button_state;
  1052. X
  1053. X     /* button_state must be cleared before sending a Button_Up event to
  1054. X        prevent any event action from thinking the button is still down.
  1055. X     */
  1056. X         button_state = 0;
  1057. X         do_event( b_event, active, E_MAIN );
  1058. X         }
  1059. X      return;
  1060. X      }
  1061. X
  1062. X   /* button_state is the global record of the current button state.
  1063. X   */
  1064. X   button_state = button;
  1065. X
  1066. X   /* Check for events associated with this button being pushed.
  1067. X   */
  1068. X   do_event(button,active,E_MAIN);
  1069. X   switch (button) {
  1070. X      case BUTTON_1:    /* temporary vi hack */
  1071. X#ifdef VI
  1072. X           if (active && ACTIVE(flags)&W_VI) {
  1073. X
  1074. X              int x = mousex-(ACTIVE(x0)+ACTIVE(text).x);
  1075. X              int y = mousey-(ACTIVE(y0)+ACTIVE(text).y);
  1076. X              int dx = ACTIVE(text).wide ? 
  1077. X                       ACTIVE(text).wide : BIT_WIDE(ACTIVE(window));
  1078. X              int dy = ACTIVE(text).wide ? 
  1079. X                       ACTIVE(text).high : BIT_HIGH(ACTIVE(window));
  1080. X
  1081. X              if (x<0 || x > dx)
  1082. X                 break;
  1083. X              if (y>=0 && y<=dy) {
  1084. X                 char buff[10];
  1085. X                 sprintf(buff,"%dH%d|",
  1086. X                      y/ACTIVE(font)->head.high+1,
  1087. X                      x/ACTIVE(font)->head.wide+1);
  1088. X                 write(ACTIVE(to_fd),buff,strlen(buff));
  1089. X                 } 
  1090. X              else if (y<0)
  1091. X                 write(ACTIVE(to_fd),"\025",1);    /* ASCII Control-U */
  1092. X              else
  1093. X                 write(ACTIVE(to_fd),"\004",1);    /* ASCII Control-D */
  1094. X              }
  1095. X#endif
  1096. X           if (active) {
  1097. X              go_menu(1);
  1098. X       }
  1099. X           break;
  1100. X      case BUTTON_2:                /* for applic. menu */
  1101. X           if (active) {
  1102. X              go_menu(0);
  1103. X       }
  1104. X           break;
  1105. X      case BUTTON_SYS:                /* for system operation */
  1106. X           /* see if mouse is in a window */
  1107. X           if (mousex < STRIPE)
  1108. X              win = (WINDOW *) 0;
  1109. X           else
  1110. X              for(win=active;win != (WINDOW *) 0;win=W(next))
  1111. X                 if(mousein(mousex,mousey,win,1))
  1112. X                    break;
  1113. X
  1114. X           /* do a menu for no window, or active window */
  1115. X           if (win == active || win == (WINDOW *) 0) {
  1116. X              if (active && win == active) {
  1117. X                 state = menu_define(font,active_menu,0,0,
  1118. X                         PUTCOLOR(W(style)),
  1119. X                         PUTCOLOR(W(background)));
  1120. X                 which_menu = 1;
  1121. X                 }
  1122. X              else if (next_window >= MAXWIN) {
  1123. X                 state = menu_define(font,full_menu,0,0,MENU_FG,MENU_BG);
  1124. X                 which_menu = 2;
  1125. X                 }
  1126. X              else {
  1127. X                 state = menu_define(font,main_menu,0,0,MENU_FG,MENU_BG);
  1128. X                 which_menu = 3;
  1129. X                 }
  1130. X              if (active) {
  1131. X                 cursor_off();
  1132. X                 if (which_menu != 1)
  1133. X                    ACTIVE_OFF();
  1134. X                 }
  1135. X              state = menu_setup(state,screen,mousex,mousey,0);
  1136. X              menu_get(state,mouse,0,0);
  1137. X              choice = menu_choice(state);
  1138. X              choice_ok = menu_ischoice(state);
  1139. X              menu_destroy(state);
  1140. X              if (choice_ok) {
  1141. X                 switch(which_menu) {
  1142. X                    case 1:
  1143. X             ACTIVE_OFF();
  1144. X                         (*active_functions[choice])();
  1145. X                         break;
  1146. X                    case 2:
  1147. X                         (*full_functions[choice])();
  1148. X                         break;
  1149. X                    case 3:
  1150. X                         (*main_functions[choice])();
  1151. X                         break;
  1152. X                    }
  1153. X         }
  1154. X              if (active) {
  1155. X                 ACTIVE(flags) &= ~W_NOINPUT;
  1156. X                 ACTIVE_ON();
  1157. X                 cursor_on();
  1158. X                 }
  1159. X          do_button(0);
  1160. X              }
  1161. X           else {
  1162. X           /* bring obscured window to the top */
  1163. X#ifdef DEBUG
  1164. X              dprintf(b)(stderr,"activating: %s\r\n",W(tty));
  1165. X#endif
  1166. X              if (active) {
  1167. X                  ACTIVE_OFF();
  1168. X                  cursor_off();
  1169. X                  }
  1170. X              expose(win);
  1171. X              if (active) {
  1172. X                 ACTIVE(flags) &= ~W_NOINPUT;
  1173. X                 ACTIVE_ON();
  1174. X                 cursor_on();
  1175. X                 }
  1176. X              }
  1177. X           break;
  1178. X           }
  1179. X   return;
  1180. X   }
  1181. X
  1182. X/* hide the active window */
  1183. X
  1184. Xint hide_win()
  1185. X   {
  1186. X   hide(active);
  1187. X   }
  1188. X
  1189. X/* quit with confirm */
  1190. X
  1191. Xint quit()
  1192. X   {
  1193. X   struct menu_state *state;        /* place to keep menu state */
  1194. X   int confirm;
  1195. X   
  1196. X   /* confirm the quit */
  1197. X
  1198. X   state = menu_define(font,quit_menu,0,0,MENU_BG,MENU_FG);
  1199. X   state = menu_setup(state,screen,mousex,mousey,0);
  1200. X
  1201. X   /* The extra call to menu_get() makes the use of the mouse buttons
  1202. X      consistent on the menus; namely the action is selected by the button
  1203. X      going up.
  1204. X   */
  1205. X   menu_get(state,mouse,BUTTON_SYS,0);
  1206. X   menu_get(state,mouse,0,0);
  1207. X
  1208. X   confirm = menu_ischoice(state) ? menu_choice(state) : 0;
  1209. X   menu_destroy(state);
  1210. X   if (confirm == M_QUIT) {
  1211. X      _quit();
  1212. X      exit(0);
  1213. X      }
  1214. X   else if (confirm == M_SUSPEND)
  1215. X      suspend();
  1216. X   }
  1217. X
  1218. X/* really quit */
  1219. X
  1220. Xint
  1221. X_quit()
  1222. X   {
  1223. X   register WINDOW *win;
  1224. X   static int really_quit=0;
  1225. X
  1226. X   if (really_quit++) {            /* we're in bad shape */
  1227. X      perror("PANIC!!  Error during _quit()!");
  1228. X      setreuid(getuid(),getuid());
  1229. X      abort();
  1230. X      }
  1231. X
  1232. X   MOUSE_OFF(mousex,mousey);
  1233. X
  1234. X   sleep(1);        /* let the key (if any) un-press before resetting
  1235. X            the kbd */
  1236. X   set_kbd(0);        /* fix up keyboard modes */
  1237. X   kbd_reset();        /* reset the keyboard */
  1238. X   reset_tty(0);    /* fix up console tty modes */
  1239. X
  1240. X   /* fix pttys */
  1241. X   if (geteuid() < 2)
  1242. X      for(win=active;win != (WINDOW *) 0;win=W(next)) {
  1243. X         chmod(W(tty),0666);
  1244. X         chown(W(tty),0,0);
  1245. X         }
  1246. X
  1247. X   /* fix utmp file */
  1248. X
  1249. X#ifdef WHO
  1250. X   close(getdtablesize()-1); /* make sure there are enough fd's left */
  1251. X   for(win=active;win != (WINDOW *) 0;win=W(next))
  1252. X      if (W(tty))
  1253. X          rm_utmp(W(tty));
  1254. X   restore_utmp(0,"");
  1255. X#endif
  1256. X
  1257. X   CLEAR(screen,BIT_CLR);
  1258. X   do_cmd( 'q' );    /* do the quiting command */
  1259. X   }
  1260. X
  1261. X/* redraw the screen, restore contents of saved windows */
  1262. X
  1263. Xint redraw()
  1264. X   {
  1265. X   register WINDOW *win;
  1266. X
  1267. X#ifdef DEBUG
  1268. X   dprintf(b)(stderr,"\r\n\tREDRAW\r\n");
  1269. X#endif
  1270. X   for(win=active;win != (WINDOW *) 0;win=W(next)) {
  1271. X      if (W(flags)&W_ACTIVE) {
  1272. X         save_win(win);
  1273. X         do_event(EVENT_REDRAW,win,E_MAIN);
  1274. X         }
  1275. X      }
  1276. X
  1277. X   erase_win(screen,0,0);
  1278. X   if (active) {
  1279. X      for(win=ACTIVE(prev);win != active;win=W(prev)) {
  1280. X         restore_win(win);
  1281. X         border(win,BLK_BDR,WH_BDR);
  1282. X         }
  1283. X      restore_win(active);
  1284. X      border(active,BLK_BDR,WH_BDR);
  1285. X      }
  1286. X   }
  1287. END_OF_FILE
  1288. # end of 'src/do_button.c'
  1289. fi
  1290. if test -f 'src/do_menu.c' -a "${1}" != "-c" ; then 
  1291.   echo shar: Will not clobber existing file \"'src/do_menu.c'\"
  1292. else
  1293. echo shar: Extracting \"'src/do_menu.c'\" \(8358 characters\)
  1294. sed "s/^X//" >'src/do_menu.c' <<'END_OF_FILE'
  1295. X/*                        Copyright (c) 1987 Bellcore
  1296. X *                            All Rights Reserved
  1297. X *       Permission is granted to copy or use this program, EXCEPT that it
  1298. X *       may not be sold for profit, the copyright notice must be reproduced
  1299. X *       on copies, and credit should be given to Bellcore where it is due.
  1300. X *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  1301. X */
  1302. X/*    $Header: do_menu.c,v 4.1 88/06/21 13:21:47 bianchi Exp $
  1303. X    $Source: /tmp/mgrsrc/src/RCS/do_menu.c,v $
  1304. X*/
  1305. Xstatic char    RCSid_[] = "$Source: /tmp/mgrsrc/src/RCS/do_menu.c,v $$Revision: 4.1 $";
  1306. X/* high level menu manipulation routines */
  1307. X
  1308. X#include "bitmap.h"
  1309. X#include <stdio.h>     /* temporary */
  1310. X#include "menu.h"
  1311. X#include "defs.h"
  1312. X#include "font.h"
  1313. X
  1314. X/* do a tree of menus */
  1315. X
  1316. Xstatic int x_page = 5;        /* offset for paging menu */
  1317. Xstatic int y_page = -5;
  1318. Xstatic int x_slide = 40;    /* offset for scrolling menu */
  1319. Xstatic int y_slide = 10;
  1320. X
  1321. Xstruct menu_result *
  1322. Xdo_menus(screen,mouse,x,y,font,menu_list,menu,exit_code)
  1323. XBITMAP *screen;            /* bitmap screen */
  1324. Xint mouse;            /* fd to get mouse coordinates */
  1325. Xint x,y;            /* where the menu goes on the screen */
  1326. Xstruct font *font;        /* font to use for menus */
  1327. Xstruct menu_state *menu_list[];    /* list of available menus */
  1328. Xint menu;            /* current menu number */
  1329. Xint exit_code;            /* valid exit codes */
  1330. X   {
  1331. X   struct menu_state  *state;    /* 'cookie' for menu system */
  1332. X   struct menu_result *result;    /* messages for nodes of menu tree chosen */
  1333. X   int done=0;            /* true if ok to backup a level */
  1334. X   int first = 1;        /* true upon entry */
  1335. X   int next;            /* next menu # */
  1336. X   struct menu_result *add_result();
  1337. X   char *print_menu();
  1338. X
  1339. X   /* set up menu, get menu 'cookie' */
  1340. X
  1341. X   state = menu_list[menu];    /* fetch the menu state */
  1342. X   result = (struct menu_result *) 0;
  1343. X   state = menu_setup(state,screen,x,y,menu_choice(state));
  1344. X
  1345. X   if (state == (struct menu_state *) 0) {
  1346. X       perror("Error setting up menu");
  1347. X       return(NULL);
  1348. X       }
  1349. X
  1350. X   /* see if another page */
  1351. X
  1352. X   if (state->next >= 0)
  1353. X      exit_code |= EXIT_BOTTOM;
  1354. X   else
  1355. X      exit_code &= ~EXIT_BOTTOM;
  1356. X
  1357. X#ifdef DEBUG
  1358. X   dprintf(m)(stderr,"  Setting up menu %d at %d,%d: valid states %s\n",
  1359. X                      menu,x,y,print_menu(exit_code));
  1360. X#endif
  1361. X
  1362. X   /* get selection on current menu */
  1363. X
  1364. X   while (!done)
  1365. X     {
  1366. X
  1367. X     /* get menu state from user */
  1368. X#ifdef DEBUG
  1369. X   dprintf(m)(stderr,"  from user ..."); fflush(stderr);
  1370. X#endif
  1371. X
  1372. X     /* do auto right menus */
  1373. X
  1374. X     if (state->flags&MENU_PAGE && exit_code&EXIT_BOTTOM && first &&
  1375. X                     state->current >= state->count ) {
  1376. X        first=0;
  1377. X        state->exit = EXIT_BOTTOM;
  1378. X        }
  1379. X     else if (state->flags&MENU_AUTO && exit_code&EXIT_RIGHT && first) {
  1380. X        first=0;
  1381. X        state->exit = EXIT_RIGHT;
  1382. X        }
  1383. X     else
  1384. X        menu_get(state,mouse,0,exit_code);
  1385. X
  1386. X     /* execute appropriate state action */
  1387. X
  1388. X#ifdef DEBUG
  1389. X   dprintf(m)(stderr,"got menu %d (at %d,%d) selection %d (%s)\n",
  1390. X              menu,x,y,menu_choice(state),print_menu(menu_exit(state)));
  1391. X#endif
  1392. X
  1393. X     switch (menu_exit(state)) {
  1394. X        case EXIT_LEFT:        /* slid off to the left */
  1395. X        case EXIT_TOP:        /* slid of the top */
  1396. X             result = NULL;
  1397. X             done++;
  1398. X             break;
  1399. X        case EXIT_CHOICE:    /* add current choice onto list */
  1400. X             result = add_result(state,result);
  1401. X             done++;
  1402. X             break;
  1403. X        case EXIT_RIGHT:    /* slid off top the right */
  1404. X             if ((next = menu_next(state)) >=0 &&    /* link exists */
  1405. X                     menu_list[next] &&            /* menu exists */
  1406. X                     menu_list[next]->save == (BITMAP *) 0 &&    /* not used */
  1407. X                     (result=do_menus(screen,mouse,        /* choice */
  1408. X                                      x+x_slide,y-y_slide,font,menu_list,
  1409. X                                      next,exit_code|EXIT_LEFT))) {
  1410. X                done++;
  1411. X                }
  1412. X             break;
  1413. X        case EXIT_BOTTOM:
  1414. X             if ((next = menu_next(state)) >=0 &&    /* menu exists */
  1415. X                 menu_list[next]->save == (BITMAP *) 0 &&    /* not used */
  1416. X                     (result=do_menus(screen,mouse,        /* choice */
  1417. X                                      x+x_page,y+y_page,font,menu_list,
  1418. X                                      next,exit_code|EXIT_TOP))) {
  1419. X                done++;
  1420. X                }
  1421. X             break;
  1422. X        default:
  1423. X         if( !debug )
  1424. X        break;
  1425. X             fprintf(stderr,"invalid menu state: 0%o\n",menu_exit(state));
  1426. X             result = NULL;
  1427. X             done++;
  1428. X             break;
  1429. X        }
  1430. X     }
  1431. X  
  1432. X#ifdef DEBUG
  1433. X   dprintf(m)(stderr,"  Tearing down %d at %d,%d choice: %d, returning: %s\n",
  1434. X              menu,x,y,menu_choice(state),print_menu(menu_exit(state)));
  1435. X#endif
  1436. X
  1437. X   /* add our action onto action list */
  1438. X
  1439. X   if (menu_exit(state) == EXIT_RIGHT && result && !(state->flags&MENU_SNIP)) {
  1440. X      result = add_result(state,result);
  1441. X      }
  1442. X
  1443. X   /* erase menu from the screen */
  1444. X
  1445. X   menu_remove(state);
  1446. X   return(result);
  1447. X   }
  1448. X
  1449. X/* add a value to list of menu values */
  1450. X
  1451. Xstruct menu_result *
  1452. Xadd_result(state,list)
  1453. Xstruct menu_state *state;        /* menu to add choice to */
  1454. Xstruct menu_result *list;        /* current list of results */
  1455. X   {
  1456. X   register struct menu_result *current;    /* current result */
  1457. X   char *malloc();
  1458. X
  1459. X   /* set up list */
  1460. X
  1461. X   if (list == (struct menu_result *) 0) {
  1462. X      list = (struct menu_result *) malloc(sizeof(struct menu_result));
  1463. X      list->next = NULL;
  1464. X      list->value = NULL;
  1465. X      }
  1466. X   else if (list->value == NULL)
  1467. X      return(list);
  1468. X
  1469. X   /* add entry to existing list */
  1470. X
  1471. X   if (menu_value(state) && *menu_value(state) && 
  1472. X                      (current = (struct menu_result *) 
  1473. X                       malloc(sizeof(struct menu_result)))) {
  1474. X      current->value = menu_value(state);
  1475. X      current->next = list;
  1476. X      }
  1477. X   else
  1478. X      current = list;
  1479. X   return(current);
  1480. X   }
  1481. X
  1482. X/* do a tree of menus */
  1483. X
  1484. Xgo_menu(n)
  1485. Xint n;                    /* which menu button (0 or 1) */
  1486. X   {
  1487. X   struct menu_result *result = NULL;        /* result of menu selection */
  1488. X   register struct menu_result *current;    /* current action */
  1489. X   int pushed;
  1490. X   int exit = EXIT_RIGHT;            /* enable sliding and paging */
  1491. X   register int menu = ACTIVE(menu[n]);
  1492. X
  1493. X#ifdef DEBUG
  1494. X   dprintf(m)(stderr,"Starting menu %d, button %d\n",menu,n);
  1495. X#endif
  1496. X
  1497. X   /* go get a menu selection, return list of actions */
  1498. X
  1499. X   if (menu>=0 /* && mousein(mousex,mousey,active,0) */) {
  1500. X      result = do_menus(screen,mouse,mousex,mousey,
  1501. X               font,ACTIVE(menus),menu,exit);
  1502. X
  1503. X      /* send list of actions, and free action space */
  1504. X
  1505. X      for(current=result;current;) {
  1506. X         if (current->value)
  1507. X            Write(ACTIVE(to_fd),current->value,strlen(current->value));
  1508. X         result = current;
  1509. X         current = current->next;
  1510. X         free(result);
  1511. X         }
  1512. X        
  1513. X      /* button is no longer pushed down; record that fact */
  1514. X      do_button( 0 );
  1515. X      }
  1516. X   return;
  1517. X   }
  1518. X
  1519. X/* define a menu from menu download string */
  1520. X
  1521. Xstruct menu_state *
  1522. Xdo_menu(line,font,fg,bg)
  1523. Xchar *line;
  1524. Xstruct font *font;
  1525. Xint fg,bg;        /* fg and bg color */
  1526. X   {
  1527. X   register int count;
  1528. X   char *fields[MAXITEMS];
  1529. X
  1530. X   count = get_fields(line+1,*line,fields,MAXITEMS)/2;
  1531. X
  1532. X#ifdef DEBUG
  1533. X   dprintf(m)(stderr,"Setting up a menu, %d items\n",count);
  1534. X#endif
  1535. X   if (count < 1)
  1536. X      return((struct menu_state *) 0);
  1537. X
  1538. X   return(menu_define(font,fields,fields+count,count,fg,bg));
  1539. X   }
  1540. X
  1541. X
  1542. X/*******************************************************************************
  1543. X *
  1544. X * break a line into its component fields 
  1545. X */
  1546. X
  1547. Xstatic int
  1548. Xget_fields(line,delim,fields,max)
  1549. Xchar *line;                /* line to break into fields */
  1550. Xchar **fields;                /* resultant fields */
  1551. Xchar delim;                /* field delimeter */
  1552. Xint max;                /* max # fields */
  1553. X   {
  1554. X   register char c, *start;
  1555. X   register int count;
  1556. X   for(count=0,start=line; count<max && (c = *line); line++)
  1557. X      if (c == delim) {
  1558. X         fields[count++]=start;
  1559. X         *line = '\0';
  1560. X         start=line+1;
  1561. X         }
  1562. X   if (start<line)
  1563. X       fields[count++] = start;
  1564. X   fields[count]=(char *) 0;
  1565. X   return(count);
  1566. X   }
  1567. X
  1568. X/* set slideing defaults */
  1569. X
  1570. Xint
  1571. Xset_slide(x,y)
  1572. Xint x,y;
  1573. X   {
  1574. X   if (x || y) {
  1575. X      x_slide = x;
  1576. X      y_slide = y;
  1577. X      }
  1578. X   return(0);
  1579. X   }
  1580. X
  1581. X/* set paging defaults */
  1582. X
  1583. Xint
  1584. Xset_page(x,y)
  1585. Xint x,y;
  1586. X   {
  1587. X   if (x || y) {
  1588. X      x_page = x;
  1589. X      y_page = y;
  1590. X      }
  1591. X   return(0);
  1592. X   }
  1593. END_OF_FILE
  1594. # end of 'src/do_menu.c'
  1595. fi
  1596. echo shar: End of archive 30 \(of 61\).
  1597. cp /dev/null ark30isdone
  1598. MISSING=""
  1599. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
  1600.     21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 \
  1601.     38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 \
  1602.     55 56 57 58 59 60 61 ; do
  1603.     if test ! -f ark${I}isdone ; then
  1604.     MISSING="${MISSING} ${I}"
  1605.     fi
  1606. done
  1607. if test "${MISSING}" = "" ; then
  1608.     echo You have unpacked all 61 archives.
  1609.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1610. else
  1611.     echo You still need to unpack the following archives:
  1612.     echo "        " ${MISSING}
  1613. fi
  1614. ##  End of shell archive.
  1615. exit 0
  1616.