home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume19 / logwtchr / part01 < prev    next >
Encoding:
Text File  |  1993-04-27  |  21.8 KB  |  845 lines

  1. Newsgroups: comp.sources.x
  2. From: mengel@dcdmwm.fnal.gov (Marc W. Mengel)
  3. Subject: v19i072:  logwatcher -  a graphical monitor for dynamic {log,mail,...} files, Part01/01
  4. Message-ID: <1993Apr4.003255.1877@sparky.imd.sterling.com>
  5. X-Md4-Signature: 2cfb1a157f1b4cdfaad6cf345a298f72
  6. Date: Sun, 4 Apr 1993 00:32:55 GMT
  7. Approved: chris@sparky.imd.sterling.com
  8.  
  9. Submitted-by: mengel@dcdmwm.fnal.gov (Marc W. Mengel)
  10. Posting-number: Volume 19, Issue 72
  11. Archive-name: logwatcher/part01
  12. Environment: X11
  13.  
  14.  
  15. #!/bin/sh
  16. # This is a shell archive.  Execute this script with /bin/sh
  17. # to extract the files.
  18.  
  19. echo Extracting README
  20. sed -e 's/^X//' > README <<EOF
  21. XThis is a multiple-mailbox-widget application that lets you associate
  22. Xshell commands with clicking on various mailbox widgets, as well
  23. Xas letting you set the bitmap displayed, and placing a name under
  24. Xeach bitmap.  A simple example is the included  "xbiff.cf" config
  25. Xfile which puts up 2 mailboxes watching two mailfiles.
  26. X
  27. X Originally designed to watch console logs from the Purdue/OSU
  28. X conserver package, but has thousands of other uses.
  29. X
  30. XAuthor: Marc Mengel, Fermi National Accellerator Laboratory, 
  31. X    <mengel@fnal.fnal.gov>
  32. X
  33. XRestrictions: None really; use it as needed, but keep the copyrights in...
  34. EOF
  35. echo Extracting Imakefile
  36. sed -e 's/^X//' > Imakefile <<EOF
  37. X       INCLUDES = -I\$(TOP)
  38. XLOCAL_LIBRARIES = \$(XAWLIB) \$(XMULIB) \$(XTOOLLIB) \$(EXTENSIONLIB) \$(XLIB)
  39. X  SYS_LIBRARIES = -lm
  40. X           SRCS = gram.c main.c scan.c util.c
  41. X           OBJS = gram.o main.o scan.o util.o
  42. X
  43. XComplexProgramTarget(xbiff)
  44. X
  45. Xgram.c: gram.y
  46. X    yacc -vd gram.y; mv y.tab.c gram.c
  47. X
  48. Xscan.c: scan.l
  49. X    lex scan.l; mv lex.yy.c scan.c
  50. EOF
  51. echo Extracting Makefile
  52. sed -e 's/^X//' > Makefile <<EOF
  53. XMETA=Makefile gram.y scan.l
  54. XSRC= Machinelog.c util.c main.c
  55. XHDR= Machinelog.h MachinelogP.h
  56. XSRCg=gram.c scan.c
  57. XHDRg=y.tab.h
  58. XOBJ= gram.o util.o main.o scan.o 
  59. X
  60. XLIB= -L/usr/lpp/X11/Xamples/lib -lXaw -lXmu -lXt -lXext -lX11
  61. XINCLUDE= 
  62. XCFLAGS= -g \$(INCLUDE)
  63. X
  64. Xall: logwatcher
  65. X
  66. Xclean:
  67. X    rm  -f \$(OBJ) \$(SRCg) \$(HDRg) y.output
  68. X
  69. Xlint: lint.errs
  70. X
  71. X#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  72. X
  73. Xlint.errs: \$(SRC) \$(SRCg)
  74. X    lint -hxn \$(SRC) \$(SRCg) > lint.errs
  75. X
  76. Xlogwatcher: \$(OBJ)
  77. X    \$(CC) -o logwatcher \$(OBJ) \$(LIB)
  78. X
  79. Xgram.c y.tab.h : gram.y
  80. X    yacc -vd gram.y
  81. X    mv y.tab.c gram.c
  82. X
  83. Xscan.c: scan.l y.tab.h
  84. X    lex scan.l
  85. X    mv lex.yy.c scan.c
  86. EOF
  87. echo Extracting gram.y
  88. sed -e 's/^X//' > gram.y <<EOF
  89. X%{
  90. X /* (c) 1993 Marc Mengel and Fermilab, who retain a nonexclusive liscence */
  91. X#include <stdio.h>
  92. X#include <X11/Xatom.h>
  93. X#include <X11/Xlib.h>
  94. X#include <X11/Intrinsic.h>
  95. X#include <X11/StringDefs.h>
  96. X#include <X11/Xaw/Form.h>
  97. X#include <X11/Xaw/Mailbox.h>
  98. X
  99. XWidget cur, temp;
  100. Xchar **ppc;
  101. X%}
  102. X
  103. X%token STRING ITEM INT HEXINT ROW COLUMN COMMAND BITMAP
  104. X
  105. X%union {
  106. X    int i;        /* integer values */
  107. X    Widget w;    /* Xaw toolkit widgets */
  108. X    char *pc;    /* character strings */
  109. X};
  110. X
  111. X%type <pc> STRING                /* from scanner */
  112. X%type <w> group_def vitem_list hitem_list    /* internal use */
  113. X%type <i> INT HEXINT                /* from scanner */
  114. X
  115. X%%
  116. Xfile     : def_list group_def ';'
  117. X    ;
  118. X
  119. Xdef_list: item_def ';'
  120. X    | def_list item_def ';'
  121. X    ;
  122. X
  123. Xitem_def: ITEM STRING BITMAP STRING
  124. X        { 
  125. X
  126. X            store(\$2, \$4, 0,0,0);
  127. X        }
  128. X    | ITEM STRING COMMAND STRING BITMAP STRING
  129. X        { 
  130. X            ppc = malloc(3*sizeof(char *));
  131. X            ppc[0] = ppc[1] = ppc[2] = \$4;
  132. X            store(\$2, \$6, 0,0,ppc);
  133. X        }
  134. X    | ITEM STRING COMMAND '(' STRING ',' STRING ',' STRING ')' BITMAP STRING
  135. X        { 
  136. X            ppc = malloc(3*sizeof(char *));
  137. X            ppc[0] = \$5;
  138. X            ppc[1] = \$7;
  139. X            ppc[2] = \$9;
  140. X            store(\$2, \$12, 0,0,ppc);
  141. X        }
  142. X    ;
  143. X
  144. Xgroup_def
  145. X    : ROW     { push(cur); cur=newform(0,0);}     '{' hitem_list '}'
  146. X        { \$\$ = cur; done(cur);  cur = pop(); }
  147. X    | COLUMN { push(cur); cur=newform(0,0);}    '{' vitem_list '}'
  148. X        { \$\$ = cur; done(cur);  cur = pop(); }
  149. X    | STRING STRING ';'
  150. X        { \$\$ = makeitem( \$1, \$2, 0, 0, 0 ); }
  151. X    | STRING STRING COMMAND STRING ';'
  152. X        { 
  153. X            ppc = malloc(3*sizeof(char *));
  154. X            ppc[0] = ppc[1] = ppc[2] = \$4;
  155. X            \$\$ = makeitem( \$1, \$2, ppc, 0, 0 ); 
  156. X        }
  157. X    | STRING STRING COMMAND '(' STRING ',' STRING ',' STRING ')' ';'
  158. X        { 
  159. X            ppc = malloc(3*sizeof(char *));
  160. X            ppc[0] = \$5;
  161. X            ppc[1] = \$7;
  162. X            ppc[2] = \$9;
  163. X            \$\$ = makeitem( \$1, \$2, ppc, 0, 0 ); 
  164. X        }
  165. X    ;
  166. X
  167. X/*
  168. X** note that hitem_list and vitem_list are identical *except* that they
  169. X** pass XtNfromVert and XtNfromHoriz to make the icons stack vertically
  170. X** or horizantally in the form.
  171. X*/
  172. X
  173. Xvitem_list
  174. X    : ROW     { push(cur); cur=newform(0,0);}     '{' hitem_list '}' ';'
  175. X        { \$\$ = cur; done(cur);  cur = pop(); }
  176. X    | COLUMN { push(cur); cur=newform(0,0);}    '{' vitem_list '}' ';'
  177. X        { \$\$ = cur; done(cur);  cur = pop(); }
  178. X    | STRING STRING ';'
  179. X        { \$\$ = makeitem( \$1, \$2, 0, 0, 0 ); }
  180. X    | STRING STRING COMMAND STRING ';'
  181. X        { \$\$ = makeitem( \$1, \$2, \$4, 0, 0 ); }
  182. X     | vitem_list ROW { push(cur); cur=newform(\$1,XtNfromVert);} '{' hitem_list '}' ';'
  183. X        { \$\$ = cur; done(cur); cur = pop(); }
  184. X     | vitem_list COLUMN {push(cur);cur=newform(\$1,XtNfromVert);} '{' vitem_list '}' ';'
  185. X        { \$\$ = cur; done(cur); cur = pop(); }
  186. X    | vitem_list STRING STRING ';'
  187. X        { \$\$ = makeitem( \$2, \$3, 0, \$1, XtNfromVert ); }
  188. X    | vitem_list STRING STRING COMMAND STRING ';'
  189. X        { 
  190. X            ppc = malloc(3*sizeof(char *));
  191. X            ppc[0] = \$5;
  192. X            ppc[1] = \$5;
  193. X            ppc[2] = \$5;
  194. X            \$\$ = makeitem( \$2, \$3, ppc, \$1, XtNfromVert ); 
  195. X        } 
  196. X    | vitem_list STRING STRING COMMAND '(' STRING ',' STRING ',' STRING ')' ';'
  197. X        { 
  198. X            ppc = malloc(3*sizeof(char *));
  199. X            ppc[0] = \$6;
  200. X            ppc[1] = \$8;
  201. X            ppc[2] = \$10;
  202. X            \$\$ = makeitem( \$2, \$3, ppc, \$1, XtNfromVert ); 
  203. X        } 
  204. X    ;
  205. X
  206. Xhitem_list
  207. X    : ROW     { push(cur); cur=newform(0,0);}     '{' hitem_list '}' ';'
  208. X        { \$\$ = cur; done(cur); cur = pop(); }
  209. X    | COLUMN { push(cur); cur=newform(0,0);}    '{' vitem_list '}' ';'
  210. X        { \$\$ = cur; done(cur); cur = pop(); }
  211. X    | STRING STRING ';'
  212. X        { \$\$ = makeitem( \$1, \$2, 0, 0, 0 ); }
  213. X    | STRING STRING COMMAND STRING ';'
  214. X        { \$\$ = makeitem( \$1, \$2, \$4, 0, 0 ); }
  215. X     | hitem_list ROW { push(cur); cur=newform(\$1,XtNfromHoriz);} '{' hitem_list '}' ';'
  216. X        { \$\$ = cur; done(cur); cur = pop(); }
  217. X     | hitem_list COLUMN {push(cur);cur=newform(\$1,XtNfromHoriz);} '{' vitem_list '}' ';'
  218. X        { \$\$ = cur; done(cur); cur = pop(); }
  219. X    | hitem_list STRING STRING ';'
  220. X        { \$\$ = makeitem( \$2, \$3, 0, \$1, XtNfromHoriz ); }
  221. X    | hitem_list STRING STRING COMMAND STRING ';'
  222. X        { 
  223. X            ppc = malloc(3*sizeof(char *));
  224. X            ppc[0] = \$5;
  225. X            ppc[1] = \$5;
  226. X            ppc[2] = \$5;
  227. X            \$\$ = makeitem( \$2, \$3, ppc, \$1, XtNfromHoriz ); 
  228. X        } 
  229. X    | hitem_list STRING STRING COMMAND '(' STRING ',' STRING ',' STRING ')' ';'
  230. X        { 
  231. X            ppc = malloc(3*sizeof(char *));
  232. X            ppc[0] = \$6;
  233. X            ppc[1] = \$8;
  234. X            ppc[2] = \$10;
  235. X            \$\$ = makeitem( \$2, \$3, ppc, \$1, XtNfromHoriz ); 
  236. X        } 
  237. X    ;
  238. X%%
  239. X
  240. Xyyerror(s) { extern int lines; fprintf(stderr,"line %d:", lines ); perror(s);}
  241. X
  242. Xyywrap() { return 1;}
  243. EOF
  244. echo Extracting logwatcher.0
  245. sed -e 's/^X//' > logwatcher.0 <<EOF
  246. XLOGWATCHER(1)                  Console Tools                     LOGWATCHER(1)
  247. X
  248. X
  249. X
  250. XNAME
  251. X   logwatcher -- a graphical monitor for dynamic {log,mail,...} files
  252. X
  253. XSYNOPSIS
  254. X   logwatcher [xoptions] configfile
  255. X   logwatcher [xoptions] < configfile
  256. X
  257. XDESCRIPTION
  258. X   logwatcher reads a configuration listing icon bitmaps, position
  259. X   information and log file names, and presents an icon for each
  260. X   file, which is highlighted when the file grows.  When the icon
  261. X   for a given log file is pressed, the command associated with
  262. X   that icon is executed; you can also configure separate commands
  263. X   for button1, button2, and button3.
  264. X
  265. X   Command strings may have a "%s" in them, which is replaced with
  266. X   the log file name before execution (via sprintf(3)).  Backslash
  267. X   escapes (like "\\n") are replaced in quoted strings.
  268. X
  269. X   Commands can be specified on a per icon-type, and/or a per file
  270. X   basis, the per file command overrides the per icon-type item.
  271. X   A list of 3 commands in parenthesis can be given to allow different
  272. X   commands for different mouse buttons.
  273. X
  274. X   The strings in bitmap definitions are names of X bitmap files a'la
  275. X   bitmap(1).
  276. X
  277. X   rows and columns of icons may be nested to group various sets of
  278. X   items together.
  279. X
  280. XEXAMPLES
  281. X   /* three way xbiff */
  282. X   icon mailbox command "xterm -e Mail -f %s" 
  283. X    bitmap /usr/include/X11/bitmaps/flagdown;
  284. X
  285. X   row {
  286. X    mailbox "/usr/mail/fred";
  287. X    mailbox "/usr/mail/joe";
  288. X    mailbox "/usr/mail/harry";
  289. X   };
  290. X
  291. X
  292. XLOGWATCHER(1)                  Console Tools                     LOGWATCHER(1)
  293. X
  294. X   
  295. XGRAMMAR
  296. X   file : def_list group_def ';'
  297. X       ;
  298. X
  299. X   def_list: item_def ';'
  300. X       | def_list item_def ';'
  301. X       ;
  302. X
  303. X   item_def: ITEM STRING BITMAP STRING
  304. X       |ITEM STRING COMMAND STRING BITMAP STRING
  305. X       |ITEM STRING COMMAND '(' STRING ',' STRING ',' STRING ')' BITMAP STRING
  306. X       ;
  307. X
  308. X   group_def
  309. X       : ROW          '{' item_list '}'
  310. X       | COLUMN     '{' item_list '}'
  311. X       ;
  312. X
  313. X   item_list
  314. X     : ROW     '{' item_list '}' ';'
  315. X     | COLUMN     '{' item_list '}' ';'
  316. X     | STRING STRING ';'
  317. X     | STRING STRING COMMAND STRING ';'
  318. X     | STRING STRING COMMAND '(' STRING ',' STRING ',' STRING ')' ';'
  319. X     | item_list ROW  '{' item_list '}' ';'
  320. X     | item_list COLUMN  '{' item_list '}' ';'
  321. X     | item_list STRING STRING ';'
  322. X     | item_list STRING STRING COMMAND STRING ';'
  323. X     | item_list STRING STRING COMMAND '(' STRING ',' STRING ',' STRING ')' ';'
  324. X     ;
  325. X
  326. XRESOURCES
  327. X   logwatcher*Font
  328. X
  329. XAUTHOR
  330. X   Marc Mengel, Fermi National Accelerator Laboratory
  331. X
  332. XSEE ALSO
  333. X   xbiff(1), printf(3), system(3), bitmap(1)
  334. X
  335. XBUGS
  336. X   There should be some way to unhighlight all of the icons, with or
  337. X   without executing their commands.
  338. X
  339. X   Rows and columns can only be nested 1024 deep.
  340. X
  341. X   "\\023" style octal escapes don't work.
  342. EOF
  343. echo Extracting logwatcher.cf
  344. sed -e 's/^X//' > logwatcher.cf <<EOF
  345. X
  346. X
  347. Xicon rs6000 command "./cons  %s" bitmap "rs6000.bm" ;
  348. X
  349. Xicon sigma bitmap "sigma.bm" ;
  350. Xicon blank bitmap "blank.bm" ;
  351. X
  352. Xrow {
  353. X    row {
  354. X        column {
  355. X            rs6000 /usr/farm/log/fnck00;
  356. X            rs6000 /usr/farm/log/fnck01;
  357. X            rs6000 /usr/farm/log/fnck02;
  358. X            rs6000 /usr/farm/log/fnck03;
  359. X            sigma  _;
  360. X            rs6000 /usr/farm/log/fnck04;
  361. X            rs6000 /usr/farm/log/fnck05;
  362. X            rs6000 /usr/farm/log/fnck06;
  363. X            rs6000 /usr/farm/log/fnck07;
  364. X        };
  365. X        column {
  366. X            rs6000 /usr/farm/log/fnck08;
  367. X            rs6000 /usr/farm/log/fnck09;
  368. X            rs6000 /usr/farm/log/fnck10;
  369. X            rs6000 /usr/farm/log/fnck11;
  370. X            blank  _;
  371. X            rs6000 /usr/farm/log/fnck12;
  372. X            rs6000 /usr/farm/log/fnck13;
  373. X            rs6000 /usr/farm/log/fnck14;
  374. X            rs6000 /usr/farm/log/fnck15;
  375. X        };
  376. X        column {
  377. X            rs6000 /usr/farm/log/fnck16;
  378. X            rs6000 /usr/farm/log/fnck17;
  379. X            rs6000 /usr/farm/log/fnck18;
  380. X            rs6000 /usr/farm/log/fnck19;
  381. X            sigma  _;
  382. X            rs6000 /usr/farm/log/fnck20;
  383. X            rs6000 /usr/farm/log/fnck21;
  384. X            rs6000 /usr/farm/log/fnck22;
  385. X            rs6000 /usr/farm/log/fnck23;
  386. X        };
  387. X        column {
  388. X            rs6000 /usr/farm/log/fnck24;
  389. X            rs6000 /usr/farm/log/fnck25;
  390. X            rs6000 /usr/farm/log/fnck26;
  391. X            rs6000 /usr/farm/log/fnck27;
  392. X            rs6000 /usr/farm/log/fnck28;
  393. X            rs6000 /usr/farm/log/fnck29;
  394. X            rs6000 /usr/farm/log/fnck30;
  395. X            rs6000 /usr/farm/log/fnck31;
  396. X            rs6000 /usr/farm/log/fnck32;
  397. X        };
  398. X    };
  399. X    row {
  400. X        column {
  401. X            rs6000 /usr/farm/log/fnck33;
  402. X            rs6000 /usr/farm/log/fnck34;
  403. X            rs6000 /usr/farm/log/fnck35;
  404. X            rs6000 /usr/farm/log/fnck36;
  405. X            sigma    _;
  406. X            rs6000 /usr/farm/log/fnck37;
  407. X            rs6000 /usr/farm/log/fnck38;
  408. X            rs6000 /usr/farm/log/fnck39;
  409. X            rs6000 /usr/farm/log/fnck40;
  410. X        };
  411. X        column {
  412. X            rs6000 /usr/farm/log/fnck41;
  413. X            rs6000 /usr/farm/log/fnck42;
  414. X            rs6000 /usr/farm/log/fnck43;
  415. X            rs6000 /usr/farm/log/fnck44;
  416. X            blank _;
  417. X            rs6000 /usr/farm/log/fnck45;
  418. X            rs6000 /usr/farm/log/fnck46;
  419. X            rs6000 /usr/farm/log/fnck47;
  420. X            rs6000 /usr/farm/log/fnck48;
  421. X        };
  422. X        column {
  423. X            rs6000 /usr/farm/log/fnck49;
  424. X            rs6000 /usr/farm/log/fnck50;
  425. X            rs6000 /usr/farm/log/fnck51;
  426. X            rs6000 /usr/farm/log/fnck52;
  427. X            sigma    _;
  428. X            rs6000 /usr/farm/log/fnck53;
  429. X            rs6000 /usr/farm/log/fnck54;
  430. X            rs6000 /usr/farm/log/fnck55;
  431. X            rs6000 /usr/farm/log/fnck56;
  432. X        };
  433. X        column {
  434. X            rs6000 /usr/farm/log/fnck57;
  435. X            rs6000 /usr/farm/log/fnck58;
  436. X            rs6000 /usr/farm/log/fnck59;
  437. X            rs6000 /usr/farm/log/fnck60;
  438. X            rs6000 /usr/farm/log/fnck61;
  439. X            rs6000 /usr/farm/log/fnck62;
  440. X            rs6000 /usr/farm/log/fnck63;
  441. X            rs6000 /usr/farm/log/fnck64;
  442. X        };
  443. X    };
  444. X};
  445. EOF
  446. echo Extracting main.c
  447. sed -e 's/^X//' > main.c <<EOF
  448. X /* (c) 1993 Marc Mengel and Fermilab, who retain a nonexclusive liscence */
  449. X/*
  450. X** pretty straightforward, initialize the toolkit, call the parser
  451. X** to read in the configuration and build the widgets, and then
  452. X** call the x toolkit event loop.
  453. X*/
  454. X#include <stdio.h>
  455. X#include <X11/Xatom.h>
  456. X#include <X11/Xlib.h>
  457. X#include <X11/Intrinsic.h>
  458. X#include <X11/StringDefs.h>
  459. X#include <X11/Xaw/Mailbox.h>
  460. X#include <X11/Xaw/Form.h>
  461. X#include "patchlevel.h"
  462. Xextern void exit();
  463. Xextern Widget cur;
  464. X
  465. Xchar *ProgramName;
  466. X
  467. Xstatic void Usage ()
  468. X{
  469. X    static char *help_message[] = {
  470. X"where options include:",
  471. X"    -display host:dpy              X server to contact",
  472. X"    -geometry geom                 size of machinelog",
  473. X"    -bg color                      background color",
  474. X"    -fg color                      foreground color",
  475. X"    -n name                        title",
  476. XNULL};
  477. X    char **cpp;
  478. X
  479. X    fprintf (stderr, "%s", version_id);
  480. X    fprintf (stderr, "usage:  %s [options ...] [configfile]\\n", ProgramName);
  481. X    for (cpp = help_message; *cpp; cpp++) {
  482. X    fprintf (stderr, "%s\\n", *cpp);
  483. X    }
  484. X    fprintf (stderr, "\\n");
  485. X    exit (1);
  486. X}
  487. X
  488. XXtTranslations mytranslations;
  489. X
  490. Xextern void Btn1Cmd();
  491. Xextern void Btn2Cmd();
  492. Xextern void Btn3Cmd();
  493. X
  494. Xstatic XtActionsRec actions[] = {
  495. X    {"XlogBtn1Cmd", Btn1Cmd},
  496. X    {"XlogBtn2Cmd", Btn2Cmd},
  497. X    {"XlogBtn3Cmd", Btn3Cmd},
  498. X};
  499. X
  500. XWidget toplevel;
  501. X
  502. Xvoid 
  503. Xmain (argc, argv)
  504. X    int argc;
  505. X    char **argv;
  506. X{
  507. X    Widget  w;
  508. X    int i;
  509. X    extern int yydebug;
  510. X    Arg args[5];
  511. X    char *pcname;
  512. X     
  513. X
  514. X    ProgramName = argv[0];
  515. X
  516. X    toplevel = XtInitialize ("main", "XLog", 0, 0,
  517. X                 &argc, argv);
  518. X    XtAppAddActions( XtWidgetToApplicationContext(toplevel),
  519. X            actions, XtNumber(actions));
  520. X    mytranslations = XtParseTranslationTable(
  521. X    "<MapNotify>:unset()\\n\\
  522. X     <Btn1Down>,<Btn1Up>:XlogBtn1Cmd()unset()\\n\\
  523. X     <Btn2Down>,<Btn2Up>:XlogBtn2Cmd()unset()\\n\\
  524. X     <Btn3Down>,<Btn3Up>:XlogBtn3Cmd()unset()\\n"
  525. X    );
  526. X    if (argc == 2) {
  527. X    freopen(argv[1],"r",stdin);
  528. X    } else if (argc != 1) {
  529. X    Usage ();
  530. X    }
  531. X
  532. X    cur = toplevel;
  533. X
  534. X    yydebug = 1;
  535. X    yyparse();
  536. X    XtRealizeWidget (toplevel);
  537. X
  538. X    XtMainLoop ();
  539. X}
  540. EOF
  541. echo Extracting patchlevel.h
  542. sed -e 's/^X//' > patchlevel.h <<EOF
  543. Xstatic char ident[] =
  544. X"@(#)logwatcher 2.3 mengel@dcdmwm ";
  545. X#define version_id      (ident+4)
  546. EOF
  547. echo Extracting scan.l
  548. sed -e 's/^X//' > scan.l <<EOF
  549. X%{
  550. X /* (c) 1993 Marc Mengel and Fermilab, who retain a nonexclusive liscence */
  551. X#define Widget int
  552. X#include "y.tab.h"
  553. X
  554. Xextern char *strcpy();
  555. Xchar *strsav(s) char *s; { return strcpy(malloc(strlen(s)+1),s); }
  556. X
  557. Xint lines = 1;
  558. X%}
  559. X
  560. X%%
  561. X
  562. Xicon            {                       return ITEM; }
  563. Xrow            {                       return ROW; }
  564. Xcolumn            {                        return COLUMN;}
  565. Xcommand            {                        return COMMAND;}
  566. Xbitmap            {                       return BITMAP; }
  567. X[-a-zA-Z/_][-a-zA-Z0-9/_]* { yylval.pc = strsav(yytext);    return STRING; }
  568. X\\"([^\\\\"]|\\\\.)*\\"    { yylval.pc = strsav(unquote(yytext));    return STRING;}
  569. X[0-9]+            { yylval.i =  (int)strtol(yytext,0,10); return INT; }
  570. X0x[0-9a-f][0-9a-f]    { yylval.i =  (int)strtol(yytext,0,16); return INT; }
  571. X[(){},;]        { return yytext[0];}
  572. X"/*"([^*]*"*")*"/"    { ; }
  573. X"#".*            { ; }
  574. X\\n            { lines++; }
  575. X.            { ; }
  576. EOF
  577. echo Extracting util.c
  578. sed -e 's/^X//' > util.c <<EOF
  579. X /* (c) 1993 Marc Mengel and Fermilab, who retain a nonexclusive liscence */
  580. X#include <X11/Xatom.h>
  581. X#include <X11/Xlib.h>
  582. X#include <X11/Intrinsic.h>
  583. X#include <X11/StringDefs.h>
  584. X#include <X11/Xaw/Form.h>
  585. X#include <X11/Xaw/Label.h>
  586. X#include <X11/Xaw/Mailbox.h>
  587. X
  588. X/*
  589. X** first a wimpy hash table symbol table to keep icon types
  590. X*/
  591. Xtypedef struct item { 
  592. X    char     *item,         /* name of icon type */
  593. X        **ppcCmds; 
  594. X    int    bitmap;     /* bitmap data for icon */
  595. X    int     width, height;  /* bitmap dimensions */
  596. X    struct item *next;     /* next item in this hash bucket */
  597. X} ITEM;
  598. X
  599. XITEM *hash[256];        /* hash table of item lists */
  600. X
  601. X/*
  602. X** wimpy hash function, xor sum...
  603. X*/
  604. Xint hashit(pc)
  605. X    unsigned char *pc;
  606. X{
  607. X    int sum = 0;
  608. X
  609. X    while (pc && *pc) {
  610. X        sum ^= *(pc++);
  611. X    }
  612. X    return sum;
  613. X}
  614. X
  615. X/*
  616. X** routine to add an item to the symbol table 
  617. X*/
  618. Xstore( item, bitmap, width, height, ppcCmds )
  619. X    char *item, **ppcCmds;
  620. X    int bitmap;
  621. X    int width, height;
  622. X{
  623. X    ITEM *p;
  624. X    int n, res;
  625. X    int d;
  626. X    extern Widget toplevel;
  627. X
  628. X    n = hashit(item);
  629. X    p = malloc(sizeof(ITEM));
  630. X    p->item = item;
  631. X    res = XReadBitmapFile(XtDisplay(toplevel),
  632. X                DefaultRootWindow(XtDisplay(toplevel)),
  633. X                bitmap,&p->width,&p->height,&p->bitmap,&d,&d);
  634. X    if (res != BitmapSuccess )
  635. X        yyerror(bitmap);
  636. X    p->ppcCmds = ppcCmds;
  637. X    p->next = hash[n];
  638. X    hash[n] = p;
  639. X}
  640. X
  641. X/*
  642. X** make an item instance, with an overriding command name (optional).
  643. X** prev and direction are the arguments for stacking inside of a
  644. X** form widget (i.e. XtNvert and the widget above it... )
  645. X*/
  646. XWidget
  647. Xmakeitem( item, name, ppcCmds, prev, direction )
  648. X    char *item, *name, **ppcCmds;
  649. X    char *direction;
  650. X{
  651. X    int n;
  652. X    ITEM *p;
  653. X    Widget w, icn;
  654. X    extern Widget cur;
  655. X    extern XtTranslations mytranslations;
  656. X    char *pcname;
  657. X    Arg args[20];
  658. X    int i, x,y,width,height;
  659. X
  660. X    for (p = hash[hashit(item)]; 0 != p && 0 != strcmp(p->item, item); p = p->next)
  661. X        ;
  662. X    if ( 0 == p ) {
  663. X        yyerror("nonexistant item");
  664. X    } else {
  665. X        i = 0;
  666. X        if ( 0 != prev ) {
  667. X            XtSetArg(args[i], direction, prev); i++;
  668. X        }
  669. X        XtSetArg(args[i], XtNborderWidth, 0); i++;
  670. X        XtSetArg(args[i], XtNhorizDistance, 0); i++;
  671. X        XtSetArg(args[i], XtNvertDistance, 0); i++;
  672. X        w=XtCreateManagedWidget("form",formWidgetClass,cur,args,i);
  673. X        i = 0;
  674. X        XtSetArg(args[i], XtNfullPixmap, p->bitmap ); i++;
  675. X        XtSetArg(args[i], XtNemptyPixmap, p->bitmap ); i++;
  676. X        XtSetArg(args[i], XtNwidth, p->width ); i++;
  677. X        XtSetArg(args[i], XtNheight, p->height ); i++;
  678. X        XtSetArg(args[i], XtNfile, name); i++;
  679. X        if ( ppcCmds == NULL ) {
  680. X            ppcCmds = p->ppcCmds;
  681. X        }
  682. X        XtSetArg(args[i], XtNdestroyCallback, ppcCmds); i++;
  683. X        XtSetArg(args[i], XtNborderWidth, 0); i++;
  684. X        XtSetArg(args[i], XtNhorizDistance, 0); i++;
  685. X        XtSetArg(args[i], XtNvertDistance, 0); i++;
  686. X        icn = XtCreateManagedWidget("icon",mailboxWidgetClass,w,args,i);
  687. X        XtOverrideTranslations(icn,mytranslations);
  688. X        if ( 0 != name ) {
  689. X            i = 0;
  690. X            XtSetArg(args[i], XtNlabel, lastpart(name) );i++;
  691. X            XtSetArg(args[i], XtNborderWidth, 0); i++;
  692. X            XtSetArg(args[i], XtNfromVert, icn); i++;
  693. X            XtSetArg(args[i], XtNborderWidth, 0); i++;
  694. X            XtSetArg(args[i], XtNhorizDistance, 0); i++;
  695. X            XtSetArg(args[i], XtNvertDistance, 0); i++;
  696. X            (void)XtCreateManagedWidget("label",labelWidgetClass,w,
  697. X                                args,i);
  698. X        }
  699. X    }
  700. X    return w;
  701. X}
  702. X
  703. X/*
  704. X** makes a new form to hold a column or row of other widgets; called
  705. X** by the parser when we start a row { ... } or column { ... } construction.
  706. X** 
  707. X** prev and direction are for stacking us in our parent's widget.
  708. X*/
  709. Xnewform(prev, direction)
  710. X    char *direction;
  711. X    Widget prev;
  712. X{
  713. X    Widget w;
  714. X    extern Widget cur;
  715. X    Arg args[20];
  716. X    int i,x,y,width,height;
  717. X    
  718. X    
  719. X    i = 0;
  720. X    if ( 0 != prev ) {
  721. X        XtSetArg(args[i], direction, prev); i++;
  722. X    }
  723. X        XtSetArg(args[i], XtNborderWidth, 1); i++;
  724. X        XtSetArg(args[i], XtNhorizDistance, 0); i++;
  725. X        XtSetArg(args[i], XtNvertDistance, 0); i++;
  726. X    w=XtCreateManagedWidget("form",formWidgetClass,cur,args,i);
  727. X    return w;
  728. X}
  729. X
  730. X/*
  731. X** stub routine for debugging, etc. called at the end of a column{...}
  732. X** or row{...} construction in the parser
  733. X*/
  734. Xdone(w)
  735. X    Widget w;
  736. X{
  737. X}
  738. X
  739. X/*
  740. X** now a simple widget stack for keeping track of row and column widgets
  741. X** so we can build a form within a form and then put more stuff next
  742. X** to it.  Called from the parser 'cause its more understandable than
  743. X** sticking stuff in \$1
  744. X*/
  745. XWidget stack[1024];
  746. Xint tos = 0;
  747. Xpush(w)
  748. X    Widget w;
  749. X{
  750. X    stack[tos++] = w;
  751. X}
  752. X
  753. XWidget pop()
  754. X{
  755. X    return stack[--tos];
  756. X}
  757. X
  758. X/*
  759. X** routine to convert C-style strings from the scanner, so backslashes
  760. X** etc happen like the C scanner does them.   The conversion is almos
  761. X** certainly incomplete.
  762. X*/
  763. Xunquote(s)
  764. X    char *s;
  765. X{
  766. X    int i, shift = 1;
  767. X
  768. X    for( i = 0; s[i+shift] != '"'; i++ ){
  769. X        if (s[i+shift] == '\\\\') {
  770. X            shift++;
  771. X            switch (s[i+shift]) {
  772. X            case 'n':  s[i+shift] = '\\n'; break;
  773. X            case 't':  s[i+shift] = '\\t'; break;
  774. X            case 'b':  s[i+shift] = '\\b'; break;
  775. X            case 'r':  s[i+shift] = '\\r'; break;
  776. X            case '"':  s[i+shift] = '\\"'; break;
  777. X            }
  778. X        }
  779. X        s[i] = s[i+shift];
  780. X    }
  781. X    s[i] = 0;
  782. X    return s;
  783. X}
  784. X/*
  785. X** find last component in a filename string so we get shorter labels
  786. X*/
  787. X
  788. Xlastpart(s)
  789. X    char *s;
  790. X{
  791. X    char *s2;
  792. X
  793. X    if( s2 = rindex(s,'/')) {
  794. X        return s2+1;
  795. X    } else {
  796. X        return s;
  797. X    }
  798. X}
  799. X
  800. XBtn1Cmd(w) { DoCommand(w,0);}
  801. XBtn2Cmd(w) { DoCommand(w,1);}
  802. XBtn3Cmd(w) { DoCommand(w,2);}
  803. X
  804. XDoCommand(w, n)
  805. X    Widget w;
  806. X    int n;
  807. X{
  808. X    char **ppcCmds, *pcFile;
  809. X    Arg args[20];
  810. X    char buf[256];
  811. X    int i;
  812. X
  813. X    i = 0;
  814. X    XtSetArg(args[i], XtNdestroyCallback, &ppcCmds); i++;
  815. X    XtSetArg(args[i], XtNfile, &pcFile); i++;
  816. X    XtGetValues(w, args, i);
  817. X    if (0 == strcmp(ppcCmds[n] ,"exit"))
  818. X        exit(0);
  819. X    sprintf(buf, ppcCmds[n], pcFile );
  820. X    system(buf);
  821. X}
  822. EOF
  823. echo Extracting xbiff.cf
  824. sed -e 's/^X//' > xbiff.cf <<EOF
  825. Xicon mailbox command "xterm -e Mail -f %s" 
  826. X        bitmap /usr/include/X11/bitmaps/flagdown;
  827. Xicon quit    command exit
  828. X        bitmap /usr/include/X11/bitmaps/target;
  829. X   row {
  830. X    quit    "quit";
  831. X    mailbox "/usr/mail/mengel";
  832. X    mailbox "/usr/mail/root";
  833. X   };
  834. EOF
  835.  
  836. exit 0 # Just in case...
  837. -- 
  838.   // chris@IMD.Sterling.COM            | Send comp.sources.x submissions to:
  839. \X/  Amiga - The only way to fly!      |
  840.  "It's intuitively obvious to the most |    sources-x@imd.sterling.com
  841.   casual observer..."                  |
  842.