home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfsm / part01 next >
Encoding:
Text File  |  1993-04-28  |  55.0 KB  |  1,944 lines

  1. Newsgroups: comp.sources.x
  2. From: rgasch@nl.oracle.com (Robert Gasch)
  3. Subject: v19i088:  xfsm - X Files System Monitor, Part01/01
  4. Message-ID: <1993Apr24.174454.407@sparky.imd.sterling.com>
  5. X-Md4-Signature: 5515415a45a67e4297ebf46b7d7efaca
  6. Date: Sat, 24 Apr 1993 17:44:54 GMT
  7. Approved: chris@sparky.imd.sterling.com
  8.  
  9. Submitted-by: rgasch@nl.oracle.com (Robert Gasch)
  10. Posting-number: Volume 19, Issue 88
  11. Archive-name: xfsm/part01
  12. Environment: X11, UNIX
  13.  
  14.  
  15. xfsm displays a list of bar graphs for the file systems of the host you are
  16. on. Clicking on a file system gives you detailed information - clicking on
  17. it again closes the detail window. Type "xfsm -?" for help.
  18.  
  19. The following systems are supported:
  20.     SVR4
  21.         SunOS
  22.         AIX
  23.         LINUX
  24.         TOS
  25.  
  26.  
  27. This is a shell archive. Remove everything below the header and the 
  28. extract the files by typing "sh <filename>".
  29. ----------------------- cut here ---------------------
  30. echo x - Imakefile
  31. sed '/^X/s///' > Imakefile << '/'
  32. X/* ************************************************************************* *
  33. X   xfsm - (C) Copyright 1993 Robert Gasch (rgasch@nl.oracle.com)
  34. X
  35. X   Permission to use, copy, modify and distribute this software for any 
  36. X   purpose and without fee is hereby granted, provided that this copyright
  37. X   notice appear in all copies as well as supporting documentation. All
  38. X   work developed as a consequence of the use of this program should duly
  39. X   acknowledge such use.
  40. X
  41. X   No representations are made about the suitability of this software for
  42. X   any purpose. This software is provided "as is" without express or implied 
  43. X   warranty.
  44. X
  45. X   All commercial uses of xfsm must be done by agreement with the autor.
  46. X * ************************************************************************* */
  47. X
  48. X
  49. X
  50. X# basic definitions for the Imake. Call xmkmf to generate the makefile.
  51. X
  52. XLOCAL_LIBRARIES = $(XLIB)
  53. X
  54. X
  55. X# flags for the compiler and linker
  56. X# uncomment the DEFINES definition appropriate fro your machine
  57. X# DEFINES        = -g -DSUNOS -DDEBUG 
  58. XDEFINES        = -O -DSUNOS 
  59. X# DEFINES        = -O -DLINUX
  60. X# DEFINES        = -O -DSVR4 
  61. X# DEFINES        = -O -DAIX 
  62. X# DEFINES        = -O -DTOS 
  63. X
  64. X
  65. XOBJS = main.o util.o
  66. XSRCS = main.c util.c
  67. X
  68. X
  69. XINCLUDES = -I$(TOP) -I$(TOP)/X11
  70. X
  71. X
  72. XComplexProgramTarget(xfsm)
  73. X
  74. /
  75. echo x - Makefile.std
  76. sed '/^X/s///' > Makefile.std << '/'
  77. X# path to X header files
  78. XXINCLUDE        = /usr/X11R5/include
  79. X
  80. X# path to X library files
  81. XXLIBS           = /usr/X11R5/lib
  82. X
  83. X# the C compiler, used as linker ;o)
  84. XCC        = cc 
  85. X
  86. X# flags for the compiler and linker
  87. X# uncomment the CFLAGS definition appropriate fro your machine 
  88. X# CFLAGS        = -g -DSUNOS -DDEBUG -I$(XINCLUDE)
  89. XCFLAGS        = -O -DSUNOS -I$(XINCLUDE)
  90. X# CFLAGS        = -O -LINUX -I$(XINCLUDE)
  91. X# CFLAGS        = -O -DSVR4 -I$(XINCLUDE)
  92. X# CFLAGS        = -O -DAIX -I$(XINCLUDE)
  93. X# CFLAGS        = -O -DTOS -I$(XINCLUDE)
  94. XLDFLAGS         = -L$(XLIBS)
  95. XLDLIBS          = -lX11 -lm 
  96. XOBJS        = main.o util.o
  97. X
  98. X
  99. X### Dependencies/Actions
  100. X
  101. Xxfsm:    $(OBJS)
  102. X    @echo -n "Linking xfsm ... "
  103. X    @$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o xfsm
  104. X    @echo "Done."
  105. X
  106. Xclean:
  107. X    rm -rf *.o 
  108. X
  109. X
  110. X### dependencies for each object
  111. Xmain.o: main.c main.h
  112. Xutil.o: util.c main.h
  113. X
  114. /
  115. echo x - README
  116. sed '/^X/s///' > README << '/'
  117. X            This is the README file for 
  118. X
  119. X
  120. X                        X   X  FFFFF  SSSSS  M     M                            
  121. X                         X X   F      S      M M M M                          
  122. X                          X    FFFFF  SSSSS  M  M  M                           
  123. X                         X X   F          S  M     M                           
  124. X                        X   X  F      SSSSS  M     M                            
  125. X
  126. X                        X      File   System Monitor   (c) 1993 Robert Gasch
  127. X
  128. X
  129. X1) Author & Copyright
  130. X
  131. X    xfsm was written by Robert Gasch (rgasch@nl.oracle.com) and is 
  132. X    copyright by the author.
  133. X
  134. X2) Distribution Policy
  135. X
  136. X     Permission to use, copy, modify and distribute this software for
  137. X    any purpose and without fee is hereby granted, provided that this
  138. X    copyright notice appear in all copies as well as supporting 
  139. X    documentation. All work developed as a consequence of the use of 
  140. X    this program should duly acknowledge such use.
  141. X
  142. X    All commercial uses of xfsm must be done by agreement with the
  143. X    author.
  144. X
  145. X3) Guarantees
  146. X
  147. X    xfsm should work all right *but*
  148. X
  149. X    No representations are made about the suitability of this software 
  150. X    for any purpose. This software is provided "as is" without express 
  151. X    or implied warranty.
  152. X
  153. X4) What is xfsm?
  154. X
  155. X    xfsm stands for X File System Monitor and runs under MIT's X11
  156. X    window system on several flavors of UNIX. It is a tool designed 
  157. X    to make monitoring your file systems' status easy by displaying 
  158. X    a simple bar graph for each file system greater than size 0. It
  159. X    updates the file systems' statistics at regular intervals and 
  160. X    has a scalable sleep time to allow fine tuning to save CPU
  161. X    power.
  162. X
  163. X5) What if you change the program?
  164. X
  165. X    If you extend xfsm's functionality, add support for new UNIX
  166. X    flavors, or simply solve bugs, *please*mail* me the changes(!)
  167. X    as I'd like to act as the central source for xfsm. This will 
  168. X    also enable me to include your changes in a future release. 
  169. X    Unless it is generic please enclose it in a meaningful
  170. X    #ifdef. If your change affects *many* lines, please provide
  171. X    some method of me finding it back (preferrably a #ifdef, 
  172. X    alternativeley some comment I can grep for). If I decide
  173. X    to incorporate your fix in a future release (seems likely)
  174. X    you'll be given credit.
  175. X
  176. X6) Systems currently supported
  177. X
  178. X    SVR4
  179. X    SunOS
  180. X    AIX
  181. X    LINUX
  182. X    TOS
  183. X
  184. X7) How do I get started?
  185. X
  186. X    This section assumes that you have all the necessary files! (The 
  187. X    file "Manifest" contains a list of distributed files.)
  188. X
  189. X    a) Customize the Imakefile to suit your system setup. 
  190. X    If it turns out that your system is not one of the currently
  191. X    supported ones, you'll have to add the appropriate definitions.
  192. X
  193. X    b) Make the Makefile by typing 
  194. X        xmkmf
  195. X    If your system does not support generating makefiles from 
  196. X    Imakefiles use "Makefile.std" as a template to build your
  197. X    own.
  198. X
  199. X    c) Once you have a valid Makefile build xfsm by tying
  200. X        make
  201. X
  202. X    Once you have created the executable, you're ready to go. The
  203. X    executable will be created in the directory in which the source
  204. X    for xfsm resides.
  205. X
  206. X8) Brief users guide
  207. X
  208. X    You can get a list of supported options by typing
  209. X        xfsm -?
  210. X
  211. X    Once you have started xfsm you will get a window containing 
  212. X    at least 1 bar graph (xfsm removes all file systems of size 0) 
  213. X    and 2 menus. The Menus are:
  214. X
  215. X        Update Now - updates all files systems' statistics now
  216. X        Quit       - exits xfsm
  217. X
  218. X    If you click on the graph of a file system with the left or middle
  219. X    mouse button you get a window displaying the detailed statistics
  220. X    for the file system. Clicking on the file system again, closes 
  221. X    the detail window while clicking on another file system while the
  222. X    detail window is open, displays this file system's statistics in 
  223. X    the detail window.
  224. X
  225. X    The right mouse button is used to toggle the display mode. The
  226. X    default startup mode graphs all file system equally big. By 
  227. X    clicking with the right mouse button, the graphs are drawn in 
  228. X    proportion to the file system's size. Clicking with the right
  229. X    mouse button again reverts back to the original mode. 
  230. X
  231. X    The following keys can be used to control xfsm:
  232. X        q - close the detail window
  233. X        u - update now
  234. X        t - toggle display mode
  235. X
  236. X    The Detail Window can display the following statistics. Depending
  237. X    on the system you are on, you may not get all these statistics:
  238. X        Total Size        The file system size in MB
  239. X        Space Free        Free space in MB
  240. X        Sapce Available        Space Available to non-root in MB
  241. X        Block Size        The size of a block in Bytes
  242. X        Blocks            The number of blocks
  243. X        Blocks Free        The number of free blocks
  244. X        Blocks Available    Blocks available to non-root
  245. X        File Inodes        The number of Inodes
  246. X        Free Inodes        The number of free Inodes
  247. X        Inodes Availible    Inodes available to non-root user
  248. X
  249. X    You can not resize the detail window. You can resize the main
  250. X    window but xfsm will now let you make the main window smaller 
  251. X    beyond a certain point. This is to ensure that the output 
  252. X    remains neat and legible.
  253. X
  254. X8) Command line parameters
  255. X
  256. X    xfsm accepts the following command line options:
  257. X
  258. X     -r              displays space available to root rather than user
  259. X                                not available on TOS
  260. X    -b              draw bars black
  261. X    -m              minimize window size
  262. X    -p              don't display percent
  263. X    -a              toggle display mode to absolute bar size
  264. X    -f              displays percent free rather than percent in use
  265. X    -s <arg>        scale sleep interval by <arg>
  266. X    -i <arg>        interval at which display is updated (default = 300s)
  267. X    -d <arg1 ... argn> do not include these file systems
  268. X    -?              get help
  269. X
  270. X9) Troubleshooting
  271. X
  272. X    If you find a problem which is not listed below there are 2 things
  273. X    you can do:
  274. X        1) Fix it yourself. If this case please send me a short 
  275. X        note explaining the problem and the fix. Note that the
  276. X        code for xfsm is actually pretty simple and for the 
  277. X        most part well commented so it should not be hard to
  278. X        figure out what's going on. If you can, please do it 
  279. X        this way as I am busy enough as is is.
  280. X        2) Send me a description of the problem. I'll try to
  281. X        attend to it as fast as I can, but work comes first so
  282. X        this may take a while.
  283. X
  284. X    Problem: Some windows are not updated correctly.
  285. X    Solution: This sounds like a known bug. Type "xfsm -?" to see
  286. X        the known bugs. Don't send me mail about these. They'll
  287. X        be fixed with the next release.
  288. X
  289. X    Problem: Compile fails with "GET_FS" undefined.
  290. X    Solution: You didn't provide the compiler with any -D options 
  291. X        for a particular machine type. Change your Imakefile 
  292. X        accordingly and go back to section 7 (How do I get 
  293. X        started?).
  294. X
  295. X    Problem: Compile fails with some member of the stats structure 
  296. X        undefined.
  297. X    Solution: You have selected inappropriate -D options for your 
  298. X        machine.  Change the option (if available) or add the 
  299. X        appropriate code. If you really don't know how to do 
  300. X        the latter mail me. Depending on my schedule I may 
  301. X        decide to help you out.
  302. X
  303. X    Problem: xfsm's reponse time is unacceptably slow.
  304. X    Solutions: Check if you're not scaling the sleep time using the
  305. X        -s command line option.
  306. X
  307. X    Problem: xfsm starts OK but I don't get the window.
  308. X    Solution: Check if your DISPLAY variable is set correctly.
  309. X
  310. X10) I've found a bug. What now?
  311. X
  312. X    Read section 9 (Troubeshooting) to see if it falls under one of
  313. X    the problems listed there. If not, reread the first part of
  314. X    section 9 (9.1 and 9.2). Then decide on the best way to approch
  315. X    your problem.
  316. X
  317. X11) I've come up with a feature which I think would be useful.
  318. X
  319. X    Here again you can do 2 things:
  320. X        1) Implement it yourself. If you do this then
  321. X        reread section 5 (What if you change the program?)
  322. X        to get an idea what I would like you to do with the
  323. X        result.
  324. X        2) Mail me. I'll consider it and if I agree with you
  325. X        will implement it whenever I find time.
  326. X
  327. X12) I'm extatic about this wonderful program. How can I make the author happy?
  328. X
  329. X    If you really feel this way, how about a short mail message
  330. X    telling me that you are happy about using xfsm.
  331. X
  332. X13) I hate this worthless program. It ruins my day.
  333. X
  334. X    Don't use it. Don't mail me!
  335. X
  336. X14) Credits
  337. X
  338. X    msleep was taken from Tom Boutell's "Broken Throne".
  339. X
  340. X    Many thanks to Joost Helberg for identifying numerous bugs,
  341. X    suggesting the relative display mode and providing the LINUX
  342. X    #defines.
  343. /
  344. echo x - main.c
  345. sed '/^X/s///' > main.c << '/'
  346. X/* ************************************************************************* *
  347. X   xfsm - (C) Copyright 1993 Robert Gasch (rgasch@nl.oracle.com)
  348. X
  349. X   Permission to use, copy, modify and distribute this software for any 
  350. X   purpose and without fee is hereby granted, provided that this copyright
  351. X   notice appear in all copies as well as supporting documentation. All
  352. X   work developed as a consequence of the use of this program should duly
  353. X   acknowledge such use.
  354. X
  355. X   No representations are made about the suitability of this software for
  356. X   any purpose. This software is provided "as is" without express or implied 
  357. X   warranty.
  358. X
  359. X   All commercial uses of xfsm must be done by agreement with the autor.
  360. X * ************************************************************************* */
  361. X
  362. X
  363. X
  364. X/* *************************************************************************
  365. X   This program displays a list of bar graphs for the file systems of the 
  366. X   machine you are on. The following switches are supported:
  367. X    -r        displays space available to root rather than user
  368. X                not available on TOS
  369. X    -b        draw bars black
  370. X    -m        minimize window size
  371. X    -p        don't display percent
  372. X    -a        toggle display mode to absolute bar size
  373. X    -f        displays percent free rather than percent in use
  374. X    -s <arg>    scale sleep interval by <arg>
  375. X    -i <arg>    interval at which display is updated (default = 300s)
  376. X    -d <arg1 ... argn> do not include these file systems
  377. X    -?        get this description
  378. X
  379. X
  380. X   Version History:
  381. X    24-3-93: 1.00 
  382. X    29-3-93: 1.01 
  383. X            Added support for gray filling of graphs
  384. X    10-4-93: 1.10 
  385. X            Added resize support, detail window title,
  386. X            fixed interval handling in msleep delay loop,
  387. X            added -m, -p and -s option
  388. X    12-4-93: 1.11
  389. X            Fixed resize bug which resulted in graph
  390. X            heights being too small
  391. X    14-4-93: 1.20
  392. X            Fixed percent display placement, added -t flag 
  393. X            and toggle handling
  394. X    16-4-93: 1.21
  395. X            Added MB line for detail window
  396. X    18-4-93: 1.22
  397. X            Fixed overflow problem for MB line (detail window)
  398. X            for very large file systems, adapted sleep 
  399. X            handling to allow larger scaling of sleep time
  400. X    19-4-93: 1.23
  401. X            Added LINUX ifdefs
  402. X   ************************************************************************* */
  403. X
  404. X
  405. X#include "main.h"
  406. X
  407. XDisplay            *mydisplay;
  408. XWinType            main_win,
  409. X            menu[MENU_ITEMS],
  410. X            fs_win[MAXFS],
  411. X            detail_win;
  412. XXGCValues        gray_gc_val;
  413. XXEvent            myevent;
  414. Xunsigned long        fg, bg;
  415. XKeySym          mykey;
  416. XXWindowAttributes      attribs;
  417. XXSizeHints        myhint;
  418. Xint             done,
  419. X            show_use=TRUE,
  420. X            upd_interval=300,
  421. X            NFS=0,
  422. X            detail_open=NOGOOD,
  423. X            minimize=FALSE,
  424. X            percent=TRUE,
  425. X            absolute=FALSE;
  426. X            gray=TRUE;
  427. Xlong            usec=SLEEPT,
  428. X            sec=0,
  429. X            b_blocks=0;
  430. Xfloat            fs_perc[MAXFS];
  431. Xstring          fs_name[MAXFS],
  432. X            hname;
  433. X
  434. X#ifdef TOS
  435. X            root=TRUE;
  436. X#else
  437. X            root=FALSE;
  438. X#endif
  439. X
  440. X#if defined (SUNOS) || defined (TOS) || defined (AIX) || defined (LINUX)
  441. Xstruct statfs         stats[MAXFS];
  442. X# else
  443. X# ifdef SVR4
  444. Xstruct statvfs        stats[MAXFS];
  445. X# endif
  446. X#endif
  447. X
  448. X
  449. X
  450. Xmain (argc, argv)
  451. Xint argc;
  452. Xchar **argv;
  453. X{
  454. X    int            i=0, t, myscreen, scrdepth;
  455. X    unsigned long int     gray_mask;
  456. X    FILE             *fp;
  457. X
  458. X    /* *** see if we catch a help flag *** */
  459. X    for (i=1; i<argc; i++)
  460. X        if (HELPARG)
  461. X            do_help(argv[0]); 
  462. X
  463. X    /* *** Open Pipe to appropriate command *** */
  464. X    if ((fp=popen (GET_HOSTNAME, "r")) == NULL)
  465. X        {
  466. X        fprintf (stderr, "Error opening pipe: %s ... Exiting\n",
  467. X            GET_HOSTNAME);
  468. X        exit (1);
  469. X        }
  470. X    if (fgets(hname,MAXCPL,fp)!=NULL)
  471. X        {
  472. X        /* *** convert trailing \n to \0 *** */
  473. X        char *c;
  474. X        if ((c=strchr (hname, '\n'))!=NULL)
  475. X            *c='\0';
  476. X        printf ("Hostname = %s\n", hname);
  477. X        }
  478. X    else
  479. X        fprintf (stderr, "Can't read hostname ...\n");
  480. X    pclose (fp);
  481. X
  482. X    /* *** open pipe to get file system names *** */
  483. X    if ((fp=popen (GET_FS, "r")) == NULL)
  484. X        {
  485. X        fprintf (stderr, "Error opening pipe: %s ... Exiting\n",
  486. X            GET_FS);
  487. X        exit (1);
  488. X        }
  489. X#ifdef AIX
  490. X    fgets(fs_name[0],MAXCPL,fp);    /* skip header line */
  491. X#endif
  492. X
  493. X    /* *** read all file systems *** */
  494. X    while (NFS<MAXFS && (fgets(fs_name[NFS++],MAXCPL,fp)!=NULL))
  495. X        {
  496. X        /* *** convert trailing \n to \0 *** */
  497. X        char *c;
  498. X        if ((c=strchr (fs_name[NFS-1], '\n'))!=NULL)
  499. X            *c='\0';
  500. X        printf ("%s\n", fs_name[NFS-1]);
  501. X        }
  502. X    if (NFS==MAXFS)
  503. X           {
  504. X           printf ("Maximum number of file systems (%d) exceeded...",
  505. X            MAXFS);
  506. X           printf ("Ignoring Rest\n");
  507. X           }
  508. X    else
  509. X        NFS--;    /* *** fix blank line at end *** */
  510. X    pclose (fp);
  511. X    if (NFS < 1)
  512. X        {
  513. X        fprintf (stderr, "Mount returned no valid file syetems ... \
  514. Xexiting\n");
  515. X        exit (1);
  516. X        }
  517. X    printf ("%d file systems found ...\n", NFS);
  518. X
  519. X    /* *** process arguments *** */
  520. X    process_args (argc, argv);
  521. X
  522. X    /* *** get the file system statistics *** */
  523. X    get_fs_stat();
  524. X
  525. X    /* *** connect to X Server and assign screen *** */
  526. X    if ((mydisplay = XOpenDisplay("")) == NULL)
  527. X        {
  528. X        fprintf (stderr, "Error Opening Display ... Exiting\n");
  529. X        exit (1);
  530. X        }
  531. X    myscreen = DefaultScreen (mydisplay);
  532. X    scrdepth = DefaultDepth (mydisplay, myscreen);
  533. X    init_all_windows();
  534. X
  535. X    /* *** assign foreground and backgound colors *** */
  536. X    bg = WhitePixel (mydisplay, myscreen);
  537. X    fg = BlackPixel (mydisplay, myscreen);
  538. X
  539. X    /* *** create Main Program Windows *** */
  540. X    create_window (DefaultRootWindow(mydisplay), &main_win, argc, argv);
  541. X    myhint.min_width=MIN_WIN_X;
  542. X    myhint.min_height=((MIN_INTERVAL*NFS)+BEGIN_NFS);
  543. X    myhint.flags=PMinSize;
  544. X    XSetStandardProperties (mydisplay, main_win.win, 0, 0, None, argv, 
  545. X        argc, &myhint);
  546. X    
  547. X    /* *** create all the buttons using child windows *** */
  548. X     for (i=0; i < MENU_ITEMS ; ++i) 
  549. X        create_window (main_win.win, &menu[i], argc, argv); 
  550. X    for (i=0; i < NFS; i++)
  551. X        {
  552. X        create_window (main_win.win, &fs_win[i], argc, argv); 
  553. X        if (gray)
  554. X            {
  555. X            gray_gc_val.tile=XCreatePixmapFromBitmapData (mydisplay,
  556. X                fs_win[i].win, gray1_bits, gray1_width, 
  557. X                gray1_height, fg, bg, scrdepth);
  558. X            if (!gray_gc_val.tile)
  559. X                {
  560. X                fprintf (stderr, "Couldn't create gray tile \
  561. X... escaping to black fill\n");
  562. X                gray=FALSE;
  563. X                }
  564. X            else
  565. X                {
  566. X                gray_gc_val.fill_style=FillTiled;
  567. X                gray_mask= GCFillStyle | GCTile;
  568. X                XChangeGC (mydisplay, fs_win[i].gc, gray_mask, 
  569. X                    &gray_gc_val);
  570. X                }
  571. X            }
  572. X        }
  573. X
  574. X    /* *** Map window definitions onto screen *** */
  575. X    XMapRaised (mydisplay, main_win.win);
  576. X    XMapSubwindows (mydisplay, main_win.win);
  577. X
  578. X#if DEBUG
  579. X    fprintf (stdout, "Setup is Done!\n");
  580. X#endif
  581. X
  582. X/* ************************************************************ */
  583. X/* ************** setup is done - main event loop ************* */
  584. X/* ************************************************************ */
  585. X
  586. X    do_event_loop (argc, argv);
  587. X
  588. X    /* *** we are done - destroy all the windows *** */
  589. X    if (detail_open != NOGOOD)
  590. X        {
  591. X        XFreeGC (mydisplay, detail_win.gc);
  592. X        XDestroyWindow (mydisplay, detail_win.win);
  593. X        }
  594. X    destroy_menu (menu, MENU_ITEMS);
  595. X    destroy_menu (fs_win, NFS);
  596. X    XFreeGC (mydisplay, main_win.gc);
  597. X    XDestroyWindow (mydisplay, main_win.win);
  598. X    XCloseDisplay (mydisplay);
  599. X    exit (0);
  600. X}
  601. X
  602. X
  603. X
  604. Xvoid do_event_loop (argc, argv)
  605. Xint argc;
  606. Xchar **argv;
  607. X{
  608. X    XEvent     tevent;
  609. X    int    count, cont, this_item, i, t, ppnfs; 
  610. X    long    target=time(NULL)+upd_interval;
  611. X    char    text[10];
  612. X
  613. X    done=FALSE;
  614. X    while (!done)
  615. X        {
  616. X        /* *** here we wait while there are no events *** */
  617. X        /* *** and count out down our interval. We    *** */
  618. X        /* *** wait .25 seconds each turn to save CPU *** */
  619. X        while (XPending (mydisplay) == 0)
  620. X        {
  621. X        msleep ();
  622. X        if ((time(NULL)) >= target)
  623. X            {
  624. X#ifdef DEBUG
  625. X            printf ("Update interval finished ... updating\n");
  626. X#endif
  627. X            redraw_main_win ();
  628. X            if (detail_open != NOGOOD)
  629. X                write_detail (detail_open);
  630. X            target=target+upd_interval;
  631. X            }
  632. X        }
  633. X          /* read the next event */
  634. X          XNextEvent (mydisplay, &myevent);
  635. X          switch (myevent.type)
  636. X              {
  637. X            /* *** expose event -> redraw the window *** */
  638. X            case Expose:
  639. X            /* ********************************************* *
  640. X             *  since a window can generate multiple expose  *
  641. X             *  events we can collapse these into one redraw *
  642. X             * ********************************************* */
  643. X            count=0;
  644. X            do
  645. X                {
  646. X                XPeekEvent (mydisplay, &tevent);
  647. X                if (tevent.xexpose.window == 
  648. X                    myevent.xexpose.window)
  649. X                    {
  650. X                    XNextEvent (mydisplay, &myevent);
  651. X                    count++;
  652. X                    }
  653. X                }
  654. X            while(tevent.xexpose.window==myevent.xexpose.window);
  655. X    
  656. X#if DEBUG
  657. X            if (!count)
  658. X                fprintf(stdout, 
  659. X                    "got expose event in window: %d\n",
  660. X                            myevent.xexpose.window);
  661. X            else
  662. X                
  663. X                fprintf(stdout, 
  664. X                    "Compressed %d expose events into 1 \
  665. Xin window: %d\n", count, myevent.xexpose.window);
  666. X#endif
  667. X
  668. X            /* ******************************************* *
  669. X             * ** now deal with the actual expose event ** *
  670. X             * ******************************************* */
  671. X              if (myevent.xexpose.window == main_win.win)
  672. X                   {
  673. X                for (i=0; i<NFS; i++)
  674. X                    {
  675. X                    XDrawImageString (mydisplay, 
  676. X                       main_win.win, main_win.gc, OFF_X+2,
  677. X                       fs_win[i].y-2, fs_name[i], 
  678. X                       strlen(fs_name[i]));
  679. X                    if (percent)
  680. X                        write_percent (i);
  681. X                    }
  682. X                break;
  683. X                }
  684. X            else
  685. X            if (myevent.xexpose.window == detail_win.win)
  686. X                write_detail (detail_open);
  687. X            cont=TRUE;
  688. X            cont = expose_win (menu, MENU_ITEMS);
  689. X            if (!cont) break;
  690. X            for (i=0; i<NFS; i++)
  691. X                if (myevent.xexpose.window == fs_win[i].win)
  692. X                    {
  693. X                    redraw_fs_win (i);
  694. X                    i=NFS;
  695. X                    }
  696. X            break;
  697. X
  698. X            /* *** change work window if main window changes *** */
  699. X            case ConfigureNotify:
  700. X#if DEBUG
  701. X            fprintf(stdout, 
  702. X                "got configure notify event in window: %d\n",
  703. X                        myevent.xconfigure.window);
  704. X#endif
  705. X            if (myevent.xconfigure.window != main_win.win)
  706. X                break;
  707. X            if (myevent.xconfigure.width==main_win.width &&
  708. X                myevent.xconfigure.height==main_win.height)
  709. X                break;
  710. X
  711. X            /* *** figure out how many points per nfs we have *** */
  712. X
  713. X            ppnfs=((myevent.xconfigure.height-BEGIN_NFS)/NFS);
  714. X#if DEBUG
  715. X            fprintf (stdout, "got resize event - new interval = \
  716. X%d\nwidth = %d height = %d\n", ppnfs, myevent.xconfigure.width,
  717. Xmyevent.xconfigure.height);
  718. X#endif
  719. X            XClearWindow (mydisplay, main_win.win);
  720. X            main_win.width=myevent.xconfigure.width;
  721. X            main_win.height=myevent.xconfigure.height;
  722. X            XResizeWindow (mydisplay, main_win.win, main_win.width,
  723. X                main_win.height);
  724. X            for (i=0; i<MENU_ITEMS; i++)
  725. X                {
  726. X                menu[i].x=((myevent.xconfigure.width-
  727. X                    SM_MENU_WIDTH)/2); 
  728. X                XMoveWindow (mydisplay, menu[i].win,
  729. X                    menu[i].x, menu[i].y);
  730. X                }
  731. X            for (i=0; i<NFS; i++)
  732. X                {
  733. X                fs_win[i].y=(BEGIN_NFS+(ppnfs*i));
  734. X                fs_win[i].width=
  735. X                    myevent.xconfigure.width-OFF_X*2;
  736. X                if (!absolute)
  737. X                    {
  738. X                    fs_win[i].width=(int)(fs_win[i].width*
  739. X                        (((float)stats[i].f_blocks)/
  740. X                        ((float)b_blocks)));
  741. X                    if (!fs_win[i].width)
  742. X                        fs_win[i].width=1;
  743. X                                }
  744. X                fs_win[i].height=ppnfs-LETTER_SPACE-
  745. X                    FREE_LETTER_SP;
  746. X                XClearWindow (mydisplay, fs_win[i].win);
  747. X                XMoveResizeWindow (mydisplay, fs_win[i].win,
  748. X                    OFF_X, fs_win[i].y, fs_win[i].width,
  749. X                    fs_win[i].height);
  750. X                XFillRectangle (mydisplay, fs_win[i].win, 
  751. X                    fs_win[i].gc, 0, 0, (int)
  752. X                    (float)(fs_perc[i]*fs_win[i].width), 
  753. X                    fs_win[i].height); 
  754. X                XDrawImageString (mydisplay, main_win.win, 
  755. X                    main_win.gc, OFF_X+2, fs_win[i].y-2, 
  756. X                    fs_name[i], strlen(fs_name[i]));
  757. X                redraw_fs_win(i);
  758. X                } 
  759. X
  760. X              break;
  761. X
  762. X            /* *** process keyboard mapping changes *** */
  763. X            case MappingNotify:
  764. X#if DEBUG
  765. X            fprintf(stdout, 
  766. X                "got mapping notify event in window: %d\n",
  767. X                           myevent.xexpose.window);
  768. X#endif
  769. X              XRefreshKeyboardMapping ((XMappingEvent *) &myevent );
  770. X              break;
  771. X
  772. X            /* *** drag in work window *** */
  773. X            case MotionNotify:
  774. X#if DEBUG
  775. X            fprintf(stdout, 
  776. X                "got motion notify event in window: %d\n",
  777. X                   myevent.xbutton.window);
  778. X#endif
  779. X              break;
  780. X
  781. X
  782. X           /* *** mouse enters a window *** */
  783. X           case EnterNotify:
  784. X            this_item = highlight_menu (menu, MENU_ITEMS, 
  785. X                TRUE);
  786. X            break;
  787. X
  788. X           /* *** Mouse Leaves a window *** */
  789. X           case LeaveNotify:
  790. X            this_item = highlight_menu (menu, MENU_ITEMS, 
  791. X                FALSE);
  792. X            break;
  793. X
  794. X           /* *** process mouse-button presses *** */
  795. X           case ButtonPress:
  796. X#if DEBUG
  797. X            fprintf(stdout, "button press (%d) in window: %d\n",
  798. X                myevent.xbutton.button, myevent.xbutton.window);
  799. X#endif
  800. X            if (myevent.xbutton.button==1 ||
  801. X                myevent.xbutton.button==2)
  802. X               {
  803. X               this_item=
  804. X                   which_button_pressed (menu, MENU_ITEMS);
  805. X                 if (this_item == UPDATE)
  806. X                {
  807. X                redraw_main_win ();
  808. X                if (detail_open != NOGOOD)
  809. X                    write_detail (detail_open);
  810. X                target=time(NULL)+upd_interval;
  811. X                break;
  812. X                }
  813. X               else
  814. X               if (this_item == QUIT)
  815. X                {
  816. X                done=TRUE;
  817. X                break;
  818. X                }
  819. X
  820. X               /* *** see if btnpress was in a graph window *** */
  821. X               this_item=
  822. X                which_button_pressed (fs_win, NFS);
  823. X               if (this_item == NOGOOD)
  824. X                break;
  825. X
  826. X               /* *** open a detail window *** */
  827. X               if (detail_open == NOGOOD)
  828. X                {
  829. X                create_window (DefaultRootWindow(mydisplay),
  830. X                    &detail_win, argc, argv);
  831. X                myhint.min_width=DETAIL_X;
  832. X                myhint.min_height=DETAIL_Y;
  833. X                myhint.max_width=DETAIL_X;
  834. X                myhint.max_height=DETAIL_Y;
  835. X                myhint.flags=PMinSize|PMaxSize;
  836. X                XSetStandardProperties (mydisplay, 
  837. X                    detail_win.win, 0, 0, None, argv, 
  838. X                    argc, &myhint);
  839. X                write_detail (this_item);
  840. X                XMapRaised (mydisplay, detail_win.win);
  841. X                detail_open = this_item;
  842. X                }
  843. X               /* *** det_win for this graph open - close it *** */
  844. X               else
  845. X               if (detail_open == this_item)
  846. X                {
  847. X                XFreeGC (mydisplay, detail_win.gc);
  848. X                XDestroyWindow (mydisplay, detail_win.win);
  849. X                detail_open=NOGOOD;
  850. X                }
  851. X               else
  852. X                {
  853. X                XClearWindow (mydisplay, detail_win.win);
  854. X                detail_open=this_item;
  855. X                write_detail (this_item);
  856. X                }
  857. X               }
  858. X               else
  859. X                toggle_mode();
  860. X
  861. X               break;
  862. X
  863. X        /* *** process mouse-button release *** */
  864. X        case ButtonRelease:
  865. X#if DEBUG
  866. X            fprintf(stdout, "button release in window: %d\n",
  867. X                myevent.xbutton.window);
  868. X#endif
  869. X              break;
  870. X
  871. X
  872. X        /* *** process Resize *** */
  873. X        case ResizeRequest:
  874. X#if DEBUG
  875. X            fprintf (stdout, "got resize event \n");
  876. X#endif
  877. X            break;
  878. X
  879. X        /* *** process keyboard input *** */
  880. X        case KeyPress:
  881. X#if DEBUG
  882. X            fprintf (stdout, "got keypress event in window: %d\n",
  883. X                        myevent.xkey.window);
  884. X#endif
  885. X              i=XLookupString ((XKeyEvent *)&myevent, text, 
  886. X                10, &mykey, 0 );
  887. X            if (text[0]==UPDATE_KEY)
  888. X                {
  889. X                redraw_main_win ();
  890. X                if (detail_open != NOGOOD)
  891. X                    write_detail (detail_open);
  892. X                target=time(NULL)+upd_interval;
  893. X                }
  894. X            else
  895. X            if (text[0]==QUIT_KEY)
  896. X               if (detail_open != NOGOOD)
  897. X                if (myevent.xkey.window == detail_win.win)
  898. X                   {
  899. X                   XFreeGC (mydisplay, detail_win.gc);
  900. X                   XDestroyWindow (mydisplay, detail_win.win);
  901. X                   detail_open=NOGOOD;
  902. X                   }
  903. X            if (text[0]==TOGGLE_KEY)
  904. X                toggle_mode ();
  905. X
  906. X            break;
  907. X         } /* switch (myevent.type) */
  908. X    } /* while (done == 0) */
  909. X}
  910. /
  911. echo x - main.h
  912. sed '/^X/s///' > main.h << '/'
  913. X/* ************************************************************************* *
  914. X   xfsm - (C) Copyright 1993 Robert Gasch (rgasch@nl.oracle.com)
  915. X
  916. X   Permission to use, copy, modify and distribute this software for any 
  917. X   purpose and without fee is hereby granted, provided that this copyright
  918. X   notice appear in all copies as well as supporting documentation. All
  919. X   work developed as a consequence of the use of this program should duly
  920. X   acknowledge such use.
  921. X
  922. X   No representations are made about the suitability of this software for
  923. X   any purpose. This software is provided "as is" without express or implied 
  924. X   warranty.
  925. X
  926. X   All commercial uses of xfsm must be done by agreement with the autor.
  927. X * ************************************************************************* */
  928. X
  929. X
  930. X
  931. X/* ****** include files ****** */
  932. X#include <X11/Xlib.h>
  933. X#include <X11/Xutil.h>
  934. X#include <X11/bitmaps/gray1>
  935. X#include <string.h>
  936. X#include <stdlib.h>
  937. X#include <stdio.h>
  938. X#include <sys/types.h>
  939. X#include <sys/time.h>
  940. X#if defined (SUNOS) || defined (TOS) || defined (LINUX)
  941. X#include <sys/vfs.h>
  942. X# else
  943. X# ifdef SVR4
  944. X# include <sys/statvfs.h>
  945. X#  else
  946. X#  ifdef AIX
  947. X#  include <sys/statfs.h>
  948. X#  include <sys/select.h>        /* required for msleep */
  949. X#  endif
  950. X# endif
  951. X#endif
  952. X
  953. X
  954. X/* ******************************************************************** */
  955. X/* ******************** general program constants ********************* */
  956. X/* ******************************************************************** */
  957. X#define TRUE        1
  958. X#define FALSE        0
  959. X#define NOGOOD        -1
  960. X#define MAXCPL          80
  961. X#define MAXFS           50
  962. X#define SLEEPT        50000L
  963. X#define QUIT_KEY    'q'
  964. X#define UPDATE_KEY    'u'
  965. X#define TOGGLE_KEY    't'
  966. X#define GET_HOSTNAME    "hostname"
  967. X#define MAX_SLEEP_SCALE    50
  968. X#define MILLION        1000000
  969. X#define MB        1048576
  970. X
  971. X#ifdef SVR4
  972. X#define GET_FS        "/etc/mount | cut -f1 -d\" \""
  973. X# else
  974. X# if defined (SUNOS) || defined (TOS) || defined (LINUX)
  975. X# define GET_FS        "/etc/mount | cut -f3 -d\" \""
  976. X# else
  977. X#  ifdef AIX
  978. X#  define GET_FS    "/etc/mount |cut -f10 -d\" \""
  979. X#  endif
  980. X# endif
  981. X#endif
  982. X
  983. X
  984. X#if defined (SVR4) || defined (AIX)
  985. X#define DETAIL_NUM    10
  986. X#else
  987. X# if defined (SUNOS) || defined (LINUX)
  988. X# define DETAIL_NUM    9
  989. X# else
  990. X#  ifdef TOS
  991. X#  define DETAIL_NUM    7
  992. X#  endif
  993. X# endif
  994. X#endif
  995. X
  996. X
  997. X
  998. X#define HELPARG        strcmp (argv[i], "-?") == NULL || \
  999. X            strcmp (argv[i], "help") == NULL || \
  1000. X            strcmp (argv[i], "-help") == NULL
  1001. X
  1002. X#define CHECKNA        if (strcmp (s, "-1") == NULL) strcpy (s, "N.A.")
  1003. X
  1004. X#define PRINT_KNOWN_BUGS     printf ("\n\
  1005. XKnown Bugs: \n\
  1006. X    1) When a detailed information window is opened it does not \n\
  1007. X       receive the expose event until the mouse reenters the main window.\n\
  1008. X    2) Update field does not receive initial expose event until mouse\n\
  1009. X       enters window.\n");
  1010. X
  1011. X#define PRINT_COPYRIGHT        printf ("\
  1012. Xxfsm v1.23 - (C) Copyright 1993 Robert Gasch (rgasch@nl.oracle.com)\n");
  1013. X
  1014. X
  1015. X
  1016. X/* ****** define window constants - these are positions and sizes ****** */
  1017. X#define WIN_X     150
  1018. X#define WIN_Y     150
  1019. X#define MIN_WIN_X    100
  1020. X#define MENU_HEIGHT     15
  1021. X#define MIN_MENU_HEIGHT    4
  1022. X#define LETTER_HEIGHT    12
  1023. X#define LETTER_SPACE    15
  1024. X#define FREE_LETTER_SP    (LETTER_SPACE-LETTER_HEIGHT)
  1025. X#define NFS_TEXT_Y    (fs_win[i].y-(LETTER_SPACE-(LETTER_HEIGHT+1)))
  1026. X#define SM_MENU_WIDTH    80
  1027. X#define MENU_WIDTH     110
  1028. X#define MENU_ITEMS    2
  1029. X#define MENU_SPACE    (MENU_HEIGHT*(MENU_ITEMS+2))
  1030. X#define BEGIN_NFS    MENU_SPACE
  1031. X#define MENU_Y        10
  1032. X#define OFF_X        10
  1033. X#define OFF_Y        10
  1034. X#define INTERVAL    ((MENU_HEIGHT+FREE_LETTER_SP)*2) 
  1035. X#define    MIN_INTERVAL    (MIN_MENU_HEIGHT+FREE_LETTER_SP+MENU_HEIGHT)
  1036. X#define DETAIL_X    195
  1037. X#define DETAIL_Y    ((MENU_HEIGHT*(DETAIL_NUM+3))+(OFF_X*2))
  1038. X#define DPC         6     /* Dots per character */
  1039. X/* ****** define constants used to identify menus and windows(buttons) ****** */
  1040. X#define UPDATE        0
  1041. X#define    QUIT        1
  1042. X
  1043. X
  1044. X
  1045. X/* ******************************************************************** */
  1046. X/* ********************* program data structures ********************** */
  1047. X/* ******************************************************************** */
  1048. X
  1049. X/* ****** XWindow struct - this simplifies function calls ****** */
  1050. Xtypedef struct {
  1051. X    Window         win;        /* window ID */
  1052. X    GC        gc;        /* window graphics content */
  1053. X    char        text[40];    /* title (for menus) */
  1054. X    int        x, y,         /* position */
  1055. X            width, height,     /* size */
  1056. X            line_thick;    /* line thickness of window border */
  1057. X    unsigned long    fg, bg;        /* foreground and background */
  1058. X    long        event_mask,     /* which events will be registered */ 
  1059. X            flags;        /* window flags */
  1060. X        } WinType, *WinTypePtr;
  1061. X
  1062. X/* *** string to hold file system name *** */
  1063. Xtypedef char string[MAXCPL];
  1064. X
  1065. X
  1066. X/* ******************************************************************** */
  1067. X/* ********************** function declarations *********************** */
  1068. X/* ******************************************************************** */
  1069. Xvoid    do_event_loop();
  1070. Xvoid    toggle_mode();
  1071. Xvoid    redraw_main_win();
  1072. Xvoid     write_detail();
  1073. Xvoid     write_percent();
  1074. Xvoid     redraw_fs_win();
  1075. Xvoid    get_fs_stat();
  1076. Xvoid     create_window ();
  1077. Xint    highlight_menu();
  1078. Xint    expose_win();
  1079. Xvoid    destroy_menu();
  1080. Xint    which_button_press();
  1081. Xvoid    msleep();
  1082. Xvoid     init_all_windows();
  1083. /
  1084. echo x - util.c
  1085. sed '/^X/s///' > util.c << '/'
  1086. X/* ************************************************************************* *
  1087. X   xfsm - (C) Copyright 1993 Robert Gasch (rgasch@nl.oracle.com)
  1088. X
  1089. X   Permission to use, copy, modify and distribute this software for any 
  1090. X   purpose and without fee is hereby granted, provided that this copyright
  1091. X   notice appear in all copies as well as supporting documentation. All
  1092. X   work developed as a consequence of the use of this program should duly
  1093. X   acknowledge such use.
  1094. X
  1095. X   No representations are made about the suitability of this software for
  1096. X   any purpose. This software is provided "as is" without express or implied 
  1097. X   warranty.
  1098. X
  1099. X   All commercial uses of xfsm must be done by agreement with the autor.
  1100. X * ************************************************************************* */
  1101. X
  1102. X
  1103. X
  1104. X#include "main.h"
  1105. X
  1106. Xextern Display        *mydisplay;
  1107. Xextern XEvent        myevent;
  1108. Xextern WinType        main_win,
  1109. X            menu[],
  1110. X            fs_win[],
  1111. X            detail_win;
  1112. Xextern unsigned long     fg, bg;
  1113. Xextern XSizeHints     myhint;
  1114. Xextern int        NFS,
  1115. X            Height, 
  1116. X            root,
  1117. X            show_use,
  1118. X            gray,
  1119. X            minimize,
  1120. X            percent,
  1121. X            absolute,
  1122. X            upd_interval;
  1123. Xextern long        sec,
  1124. X            usec,
  1125. X            b_blocks;
  1126. Xextern float         fs_perc[];
  1127. Xextern string        fs_name[],
  1128. X            hname;
  1129. X
  1130. X#if defined (SUNOS) || defined (TOS) || defined (AIX) || defined (LINUX)
  1131. Xextern struct statfs     stats[];
  1132. X# else
  1133. X# ifdef SVR4
  1134. Xextern struct statvfs     stats[];
  1135. X# endif
  1136. X#endif
  1137. X
  1138. X
  1139. X
  1140. Xchar *Menu_Text[MENU_ITEMS]={
  1141. X        " Update Now ",
  1142. X        "    Quit    "};
  1143. X
  1144. X
  1145. X
  1146. X/* *********************************************************************** */
  1147. X/* ********* toggle the display mode and update the windows ************** */
  1148. X/* *********************************************************************** */
  1149. Xvoid toggle_mode ()
  1150. X{
  1151. X    int i;
  1152. X
  1153. X    if (absolute)
  1154. X        absolute=FALSE;
  1155. X    else
  1156. X        absolute=TRUE;
  1157. X    for (i=0; i<NFS; i++)
  1158. X        {
  1159. X        fs_win[i].width=main_win.width-OFF_X*2;
  1160. X        if (!absolute)
  1161. X            {
  1162. X            fs_win[i].width=(int)(fs_win[i].width*
  1163. X                (((float)stats[i].f_blocks)/((float)b_blocks)));
  1164. X            if (!fs_win[i].width)
  1165. X                fs_win[i].width=1;
  1166. X            }
  1167. X        XResizeWindow (mydisplay,fs_win[i].win, fs_win[i].width,
  1168. X            fs_win[i].height);
  1169. X        redraw_fs_win (i);
  1170. X        }
  1171. X}
  1172. X
  1173. X
  1174. X
  1175. X/* *********************************************************************** */
  1176. X/* *********************** redraw the main window ************************ */
  1177. X/* *********************************************************************** */
  1178. Xvoid redraw_main_win ()
  1179. X{
  1180. X    int i;
  1181. X
  1182. X    get_fs_stat ();
  1183. X    XClearWindow (mydisplay, main_win.win);
  1184. X    for (i=0; i<NFS; i++)
  1185. X        {
  1186. X        XDrawImageString (mydisplay, main_win.win, main_win.gc, 
  1187. X            OFF_X+2, fs_win[i].y-2, fs_name[i], strlen(fs_name[i]));
  1188. X        redraw_fs_win (i);
  1189. X        if (percent)
  1190. X            write_percent (i);
  1191. X        }
  1192. X} 
  1193. X
  1194. X
  1195. X/* *********************************************************************** */
  1196. X/* ******************** write out the detailed info ********************** */
  1197. X/* *********************************************************************** */
  1198. Xvoid write_detail (i)
  1199. Xint i;
  1200. X{
  1201. X    int c=3, rhs=105;
  1202. X#if defined (SUNOS) || defined (TOS) || defined (AIX) || defined (LINUX)
  1203. X    long bsize=stats[i].f_bsize;
  1204. X#else
  1205. X    long bsize=stats[i].f_frsize;
  1206. X#endif
  1207. X    char s[30];
  1208. X
  1209. X    XClearWindow (mydisplay, detail_win.win);
  1210. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1211. X        (((DETAIL_X-OFF_X*2)/2)-(DPC/2*strlen (fs_name[i]))), 
  1212. X        OFF_Y+MENU_HEIGHT, fs_name[i], strlen (fs_name[i]));
  1213. X
  1214. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1215. X        OFF_X, OFF_Y+MENU_HEIGHT*c, "Total Size", 
  1216. X        strlen ("Total Size"));
  1217. X    if (stats[i].f_blocks == -1 || bsize == -1)
  1218. X        sprintf (s, "Undefined");
  1219. X    else
  1220. X        sprintf (s, "%.2f MB", 
  1221. X        /* *** use this computational order to avoid overflows *** */
  1222. X           (((double)(bsize)/(float)(MB)))*(double)(stats[i].f_blocks));
  1223. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1224. X        OFF_X+rhs, OFF_Y+MENU_HEIGHT*c++, s, strlen (s));
  1225. X
  1226. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1227. X        OFF_X, OFF_Y+MENU_HEIGHT*c, "Space Free", 
  1228. X        strlen ("Space Free"));
  1229. X    if (stats[i].f_bfree == -1 || bsize == -1)
  1230. X        sprintf (s, "Undefined");
  1231. X    else
  1232. X        sprintf (s, "%.2f MB",
  1233. X        /* *** use this computational order to avoid overflows *** */
  1234. X        (((double)(bsize)/(float)(MB)))*(double)(stats[i].f_bfree));
  1235. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1236. X        OFF_X+rhs, OFF_Y+MENU_HEIGHT*c++, s, strlen (s));
  1237. X
  1238. X#ifndef TOS
  1239. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1240. X        OFF_X, OFF_Y+MENU_HEIGHT*c, "Space Available", 
  1241. X        strlen ("Space Available"));
  1242. X    if (stats[i].f_bfree == -1 || bsize == -1)
  1243. X        sprintf (s, "Undefined");
  1244. X    else
  1245. X        sprintf (s, "%.2f MB",
  1246. X        /* *** use this computational order to avoid overflows *** */
  1247. X        (((double)(bsize)/(float)(MB)))*(double)(stats[i].f_bavail));
  1248. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1249. X        OFF_X+rhs, OFF_Y+MENU_HEIGHT*c++, s, strlen (s));
  1250. X#endif 
  1251. X
  1252. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1253. X        OFF_X, OFF_Y+MENU_HEIGHT*c, "Block Size", 
  1254. X        strlen ("Block Size"));
  1255. X    sprintf (s, "%ld", bsize);
  1256. X    CHECKNA;
  1257. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1258. X        OFF_X+rhs, OFF_Y+MENU_HEIGHT*c++, s, strlen (s));
  1259. X
  1260. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1261. X        OFF_X, OFF_Y+MENU_HEIGHT*c, "Blocks", strlen ("Blocks"));
  1262. X    sprintf (s, "%ld", stats[i].f_blocks);
  1263. X    CHECKNA;
  1264. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1265. X        OFF_X+rhs, OFF_Y+MENU_HEIGHT*c++, s, strlen (s));
  1266. X
  1267. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1268. X        OFF_X, OFF_Y+MENU_HEIGHT*c, "Blocks Free",
  1269. X        strlen ("Blocks Free"));
  1270. X    sprintf (s, "%ld", stats[i].f_bfree);
  1271. X    CHECKNA;
  1272. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1273. X        OFF_X+rhs, OFF_Y+MENU_HEIGHT*c++, s, strlen (s));
  1274. X
  1275. X#ifndef TOS
  1276. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1277. X        OFF_X, OFF_Y+MENU_HEIGHT*c, "Blocks Available",
  1278. X        strlen ("Blocks Available"));
  1279. X    sprintf (s, "%ld", stats[i].f_bavail);
  1280. X    CHECKNA;
  1281. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1282. X        OFF_X+rhs, OFF_Y+MENU_HEIGHT*c++, s, strlen (s));
  1283. X#endif
  1284. X
  1285. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1286. X        OFF_X, OFF_Y+MENU_HEIGHT*c, "File Inodes",
  1287. X        strlen ("File Inodes"));
  1288. X    sprintf (s, "%ld", stats[i].f_files);
  1289. X    CHECKNA;
  1290. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1291. X        OFF_X+rhs, OFF_Y+MENU_HEIGHT*c++, s, strlen (s));
  1292. X
  1293. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1294. X        OFF_X, OFF_Y+MENU_HEIGHT*c, "Free Inodes",
  1295. X        strlen ("Free Inodes"));
  1296. X    sprintf (s, "%ld", stats[i].f_ffree);
  1297. X    CHECKNA;
  1298. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1299. X        OFF_X+rhs, OFF_Y+MENU_HEIGHT*c++, s, strlen (s));
  1300. X
  1301. X#ifdef SVR4
  1302. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1303. X        OFF_X, OFF_Y+MENU_HEIGHT*c, "Inodes Available",
  1304. X        strlen ("Inodes Available"));
  1305. X    sprintf (s, "%ld", stats[i].f_favail);
  1306. X    CHECKNA;
  1307. X    XDrawImageString (mydisplay, detail_win.win, detail_win.gc, 
  1308. X        OFF_X+rhs, OFF_Y+MENU_HEIGHT*c++, s, strlen (s));
  1309. X#endif
  1310. X}
  1311. X
  1312. X
  1313. X
  1314. X/* *********************************************************************** */
  1315. X/* ************************* write the percentage ************************ */
  1316. X/* *********************************************************************** */
  1317. Xvoid write_percent(i)
  1318. Xint i;
  1319. X{
  1320. X    char     s[30];
  1321. X    int    c=0;
  1322. X
  1323. X    sprintf (s, "%d%%", (int)(fs_perc[i]*100));
  1324. X    XDrawImageString (mydisplay, main_win.win, main_win.gc, 
  1325. X        (main_win.width-OFF_Y-(strlen(s)*DPC)), NFS_TEXT_Y, 
  1326. X        s, strlen (s));
  1327. X}
  1328. X
  1329. X
  1330. X
  1331. X/* *********************************************************************** */
  1332. X/* *************************** redraw the bars *************************** */
  1333. X/* *********************************************************************** */
  1334. Xvoid redraw_fs_win(i)
  1335. Xint i;
  1336. X{
  1337. X    /* *** now draw bar *** */
  1338. X    XClearWindow (mydisplay, fs_win[i].win);
  1339. X    XFillRectangle (mydisplay, fs_win[i].win, fs_win[i].gc, 
  1340. X        0, 0, (int)(fs_perc[i]*fs_win[i].width), 
  1341. X        fs_win[i].height);
  1342. X}
  1343. X
  1344. X
  1345. X
  1346. X/* *********************************************************************** */
  1347. X/* ********************** get the file system stats ********************** */
  1348. X/* *********************************************************************** */
  1349. Xvoid get_fs_stat()
  1350. X{
  1351. X    int i, t, x;
  1352. X#if defined (SVR4) || defined (LINUX)
  1353. X    string s;
  1354. X#endif
  1355. X
  1356. X     /* *** read file system status *** */
  1357. X        for (i=0; i<NFS; i++)
  1358. X       {
  1359. X#if defined (SUNOS) || defined (LINUX) || defined (AIX)
  1360. X           t=statfs (fs_name[i], &stats[i]);
  1361. X# else
  1362. X# ifdef SVR4
  1363. X           t=statvfs (fs_name[i], &stats[i]);
  1364. X#  else
  1365. X#  ifdef TOS
  1366. X           t=statvfs (fs_name[i], &stats[i]), sizeof (struct statfs), 0);
  1367. X#  endif
  1368. X# endif
  1369. X#endif
  1370. X
  1371. X    /* *** see if the return code is an error *** */
  1372. X       if (t == -1)
  1373. X#if defined (SVR4) || defined (LINUX)
  1374. X        {
  1375. X        sprintf (s, "Can't get status on [%s]\n", fs_name[i]);
  1376. X                perror (s);
  1377. X        }
  1378. X#else
  1379. X                perror ("Can't get status on [%s]\n", fs_name[i]);
  1380. X#endif 
  1381. X       else
  1382. X        {
  1383. X#ifdef DEBUG
  1384. X                printf ("Got status on %s\n", fs_name[i]);
  1385. X#endif
  1386. X        /* *** find largest file system size *** */
  1387. X        if (stats[i].f_blocks > b_blocks)
  1388. X            b_blocks=stats[i].f_blocks;
  1389. X
  1390. X        /* *** throw out file systems of size 0 *** */
  1391. X        if (stats[i].f_blocks == 0)
  1392. X            {
  1393. X            printf ("File system %s is of size 0 - removing it!\n",
  1394. X                fs_name[i]);
  1395. X            for (x=i; x<NFS; x++)
  1396. X                {
  1397. X                strcpy (fs_name[x], fs_name[x+1]) ;
  1398. X                stats[x]=stats[x+1];
  1399. X                }
  1400. X            i--;
  1401. X            NFS--;
  1402. X            }
  1403. X        else
  1404. X            {
  1405. X            /* *** figure out percentage of free blocks *** */
  1406. X            if (root)
  1407. X               {
  1408. X                  if (show_use)
  1409. X                {
  1410. X                   fs_perc[i]=((float)
  1411. X                   (stats[i].f_blocks-stats[i].f_bfree))/
  1412. X                   ((float)stats[i].f_blocks);
  1413. X#ifdef DEBUG
  1414. X                   printf ("Free: %ld \t Total: %ld == %2f%%\n", 
  1415. X                   stats[i].f_bfree, stats[i].f_blocks, 
  1416. X                   fs_perc[i]);
  1417. X#endif
  1418. X                }
  1419. X                  else
  1420. X                {
  1421. X                   fs_perc[i]=((float)stats[i].f_bfree)/
  1422. X                    ((float)stats[i].f_blocks);
  1423. X#ifdef DEBUG
  1424. X                   printf ("Free: %ld \t Total: %ld == %.2f%%\n", 
  1425. X                    stats[i].f_bfree, stats[i].f_blocks, 
  1426. X                    fs_perc[i]);
  1427. X#endif
  1428. X                }
  1429. X               }
  1430. X            else
  1431. X               {
  1432. X                  if (show_use)
  1433. X                {
  1434. X                fs_perc[i]=((float)
  1435. X                    stats[i].f_blocks-stats[i].f_bavail)/
  1436. X                    ((float)stats[i].f_blocks);
  1437. X#ifdef DEBUG
  1438. X                   printf ("Free: %ld \t Total: %ld == %.2f%%\n", 
  1439. X                    stats[i].f_bfree, stats[i].f_blocks, 
  1440. X                    fs_perc[i]);
  1441. X#endif
  1442. X                } 
  1443. X                 else
  1444. X                {
  1445. X                   fs_perc[i]=((float)stats[i].f_bavail)/
  1446. X                       ((float)stats[i].f_blocks);
  1447. X#ifdef DEBUG
  1448. X                   printf ("Free: %ld \t Total: %ld == %.2f%%\n", 
  1449. X                    stats[i].f_bfree, stats[i].f_bavail, 
  1450. X                    fs_perc[i]);
  1451. X#endif
  1452. X                }
  1453. X               }
  1454. X            }
  1455. X        }
  1456. X    }
  1457. X    /* *** No file systems left *** */
  1458. X    if (NFS < 1)
  1459. X        {
  1460. X        fprintf(stderr,"No File systems left ... Exiting\n");
  1461. X        exit (0);
  1462. X        }
  1463. X}
  1464. X
  1465. X
  1466. X/* *********************************************************************** */
  1467. X/* *********************** create a single window ************************ */
  1468. X/* *********************************************************************** */
  1469. Xvoid create_window (parent_win, this_win, argc, argv)
  1470. XWindow    parent_win; 
  1471. XWinTypePtr this_win;
  1472. Xint     argc;
  1473. Xchar     **argv;
  1474. X{
  1475. X    /* ***  default program-specified window attributes *** */
  1476. X    myhint.x = this_win->x; 
  1477. X    myhint.y = this_win->y; 
  1478. X    myhint.width = this_win->width;  
  1479. X    myhint.height = this_win->height;
  1480. X    myhint.flags = this_win->flags;
  1481. X
  1482. X    /* *** Create Actual Window *** */
  1483. X    this_win->win = XCreateSimpleWindow (mydisplay, parent_win, 
  1484. X        myhint.x, myhint.y, myhint.width, myhint.height,
  1485. X        this_win->line_thick, fg, bg);
  1486. X
  1487. X    if (!this_win->win)
  1488. X        {
  1489. X        fprintf (stderr,"Error creating Simple Window %s ... Exiting\n",
  1490. X            this_win->text);
  1491. X        exit (1);
  1492. X        }
  1493. X#if DEBUG
  1494. X    fprintf (stdout, "Created Simple Window %s (%d)\n", 
  1495. X        this_win->text, this_win->win);
  1496. X#endif
  1497. X
  1498. X    /* *** cheap way to set the main properties *** */
  1499. X    XSetStandardProperties(mydisplay, this_win->win, this_win->text,
  1500. X        this_win->text, None, argv, argc, &myhint);
  1501. X
  1502. X    /* *** set Graphics Content creation and initialize *** */
  1503. X    this_win->gc = XCreateGC (mydisplay, this_win->win, 0, 0);
  1504. X
  1505. X    if (! this_win->gc)
  1506. X        {
  1507. X         fprintf (stderr, "Error creating GC for  %s ... Exiting\n",
  1508. X                        this_win->text);
  1509. X                exit (1);
  1510. X        }
  1511. X#if DEBUG
  1512. X    fprintf (stdout, "Created GC %d\n", this_win->gc);
  1513. X#endif
  1514. X
  1515. X    XSetBackground (mydisplay, this_win->gc, bg);
  1516. X    XSetForeground (mydisplay, this_win->gc, fg);
  1517. X
  1518. X    /* *** specify which input we want this window to process *** */
  1519. X    XSelectInput (mydisplay, this_win->win, this_win->event_mask);
  1520. X}
  1521. X
  1522. X
  1523. X
  1524. X
  1525. X/* *********************************************************************** */
  1526. X/* highlight menu item (window) in response to a mouse entering or leaving */
  1527. X/* *********************************************************************** */
  1528. Xint highlight_menu (menu, menu_num,highlight)
  1529. XWinType menu[];
  1530. Xint    menu_num;
  1531. Xint    highlight;
  1532. X{
  1533. X    int i, state=NOGOOD;
  1534. X
  1535. X    /* *** figure out which menu *** */
  1536. X    for (i=0; i<menu_num; i++) 
  1537. X        if (myevent.xcrossing.window==menu[i].win) 
  1538. X            {
  1539. X            state=i;
  1540. X            i=menu_num;
  1541. X            }
  1542. X    /* *** check if menu is valid and change fg & bg *** */
  1543. X      if (state>=0 && state<menu_num)
  1544. X        {
  1545. X        if (highlight)
  1546. X            {
  1547. X#if DEBUG
  1548. X            fprintf (stdout, "Enter state in button %s\n", 
  1549. X                menu[state].text);
  1550. X#endif
  1551. X            XSetBackground (mydisplay, menu[state].gc, fg);
  1552. X            XSetForeground (mydisplay, menu[state].gc, bg);
  1553. X            }
  1554. X        else
  1555. X            {
  1556. X#if DEBUG
  1557. X            fprintf (stdout, "Exit state in button %s\n", 
  1558. X                menu[state].text);
  1559. X#endif
  1560. X            XSetBackground (mydisplay, menu[state].gc, bg);
  1561. X            XSetForeground (mydisplay, menu[state].gc, fg);
  1562. X            }
  1563. X         for (i=0; i<menu_num; ++i)
  1564. X                XDrawImageString (mydisplay, menu[i].win, menu[i].gc, 1,
  1565. X               LETTER_HEIGHT, menu[i].text, strlen(menu[i].text)); 
  1566. X        return (state);
  1567. X        }
  1568. X    else
  1569. X        return (NOGOOD);
  1570. X}
  1571. X
  1572. X
  1573. X
  1574. X
  1575. X/* *********************************************************************** */
  1576. X/* ************** redraw the string in an exposed window ***************** */
  1577. X/* *********************************************************************** */
  1578. Xint expose_win (menu, menu_num)
  1579. XWinType    menu[];
  1580. Xint    menu_num;
  1581. X{
  1582. X    int i;
  1583. X
  1584. X    for (i=0; i<menu_num; i++)
  1585. X        {
  1586. X        if (myevent.xexpose.window == menu[i].win)
  1587. X            {
  1588. X            XDrawImageString (mydisplay, menu[i].win,     
  1589. X               menu[i].gc, 1, LETTER_HEIGHT, menu[i].text,
  1590. X               strlen(menu[i].text));
  1591. X            return (FALSE);
  1592. X            }
  1593. X        }
  1594. X    return (TRUE);
  1595. X}
  1596. X
  1597. X
  1598. X
  1599. X
  1600. X/* *********************************************************************** */
  1601. X/* *********************** destroy an entire menu  *********************** */
  1602. X/* *********************************************************************** */
  1603. Xvoid destroy_menu (menu, menu_num)
  1604. XWinType    menu[];
  1605. Xint    menu_num;
  1606. X{
  1607. X    int i;
  1608. X
  1609. X    for (i=0; i<menu_num; i++)
  1610. X        {
  1611. X        XDestroyWindow (mydisplay, menu[i].win);
  1612. X#if DEBUG
  1613. X        fprintf (stdout, "Destroyed menu: %s\n", menu[i].text);
  1614. X#endif
  1615. X        XFreeGC (mydisplay, menu[i].gc);
  1616. X#if DEBUG
  1617. X        fprintf (stdout, "Destroyed GC: %d\n", menu[i].gc);
  1618. X#endif
  1619. X        }
  1620. X}
  1621. X
  1622. X
  1623. X
  1624. X
  1625. X/* *********************************************************************** */
  1626. X/* *************** return the number of the button pressed *************** */
  1627. X/* *********************************************************************** */
  1628. Xint which_button_pressed (menu, menu_num)
  1629. XWinType    menu[];
  1630. Xint    menu_num;
  1631. X{
  1632. X    int i;
  1633. X
  1634. X    for (i=0; i<menu_num; i++)
  1635. X        if (myevent.xbutton.window == menu[i].win)
  1636. X            return (i);
  1637. X    return (NOGOOD);
  1638. X}
  1639. X
  1640. X
  1641. X
  1642. X/* ***************************************************************** */
  1643. X/* ****************** Process the progrma arguments **************** */
  1644. X/* ***************************************************************** */
  1645. Xvoid process_args (argc, argv)
  1646. Xint argc;
  1647. Xchar **argv;
  1648. X{
  1649. X    int i, x, t, removed=FALSE;
  1650. X
  1651. X    for (i=1; i<argc; i++)
  1652. X       if (strcmp (argv[i], "-r") == NULL)
  1653. X        {
  1654. X        root=TRUE;
  1655. X#ifndef TOS
  1656. X        printf ("-r falg caught - will give statistics for root\n");
  1657. X#else
  1658. X        fprintf (stderr, "-r flag not available on TOS\n");
  1659. X#endif
  1660. X        }
  1661. X       else
  1662. X       if (strcmp (argv[i], "-b") == NULL)
  1663. X        {
  1664. X        gray=FALSE;
  1665. X        printf ("-b flag caught - will draw bars black\n");
  1666. X        }
  1667. X       else
  1668. X       if (strcmp (argv[i], "-m") == NULL)
  1669. X        {
  1670. X        minimize=TRUE;
  1671. X        printf ("-m flag caught - will minimize window size\n");
  1672. X        }
  1673. X       else
  1674. X       if (strcmp (argv[i], "-p") == NULL)
  1675. X        {
  1676. X        percent=FALSE;
  1677. X        printf ("-p flag caught - will toggle percent display off\n");
  1678. X        }
  1679. X       else
  1680. X       if (strcmp (argv[i], "-a") == NULL)
  1681. X        {
  1682. X        absolute=TRUE;
  1683. X        printf ("-a flag caught - will display sizes relative to \
  1684. Xabsolute FS size\n");
  1685. X        }
  1686. X       else
  1687. X       if (strcmp (argv[i], "-k") == NULL)
  1688. X        {
  1689. X        percent=FALSE;
  1690. X        printf ("-k flag caught - will keep file ssytem opf file 0\n");
  1691. X        }
  1692. X       else
  1693. X       if (strcmp (argv[i], "-s") == NULL)
  1694. X        {
  1695. X        i++;
  1696. X        if (atoi(argv[i]) < 1 || atoi(argv[i]) > MAX_SLEEP_SCALE)
  1697. X            {
  1698. X            fprintf(stderr,
  1699. X                "Supplied scaling factor out of range (1-%d)\n",
  1700. X                MAX_SLEEP_SCALE);
  1701. X            }
  1702. X        else
  1703. X            {
  1704. X            usec*=(long)atoi(argv[i]);
  1705. X            if (usec >= MILLION)
  1706. X                {
  1707. X                sec = usec/MILLION;
  1708. X                usec = (usec-(sec*MILLION));
  1709. X                }
  1710. X            else
  1711. X                {
  1712. X                sec = 0;
  1713. X                usec = usec;
  1714. X                }
  1715. X            printf ("-s flag caught - will multiply sleep \
  1716. Xtime by %d\n", atoi(argv[i]));
  1717. X            printf ("\tWarning: response may be unacceptably \
  1718. Xslow!\n");
  1719. X            }
  1720. X        }
  1721. X       else
  1722. X       if (strcmp (argv[i], "-f") == NULL)
  1723. X        {
  1724. X        show_use=FALSE;
  1725. X        printf("-f flag caught - will show space free rather than \
  1726. Xspace used\n");
  1727. X        }
  1728. X       else
  1729. X       if (strcmp (argv[i], "-i") == NULL)
  1730. X        {
  1731. X        upd_interval=atoi(argv[++i]);
  1732. X        if (upd_interval < 1)
  1733. X           {
  1734. X           fprintf (stderr,
  1735. X            "Supplied interval (%d) too small (minimum=1)\n",
  1736. X            upd_interval);
  1737. X           exit (1);
  1738. X           }
  1739. X        printf ("-i flag caught - update interval changed to %d sec\n",
  1740. X           upd_interval);
  1741. X        }
  1742. X       else
  1743. X       if (strcmp (argv[i], "-d") == NULL)
  1744. X        /* *** does it begin with an "/" *** */
  1745. X        while (i<(argc-1) && argv[i+1][0]=='/')
  1746. X           {
  1747. X           /* *** check all file systems for arg *** */
  1748. X           for (x=0; x<NFS; x++)
  1749. X            /* *** we found a match *** */
  1750. X            if (strcmp (argv[i+1], fs_name[x]) == NULL)
  1751. X                {
  1752. X                /* *** shift files systenms 1 down *** */
  1753. X                for (t=x; t<NFS; t++)
  1754. X                    strcpy (fs_name[t], fs_name[t+1]);
  1755. X                x=--NFS;
  1756. X                removed=TRUE;
  1757. X                printf ("-d flag caught - %s will be ignored\n",
  1758. X                    argv[i+1]);
  1759. X                }
  1760. X           /* *** did we remove a file system with this arg *** */
  1761. X           if (x==NFS)
  1762. X            fprintf (stderr,"%s is not a file system ... ignored\n",
  1763. X                argv[i]);
  1764. X           i++;
  1765. X           }
  1766. X       else
  1767. X        printf ("Argument %s not recognized as an option ... ignored\n",
  1768. X            argv[i]);
  1769. X
  1770. X    if (NFS < 1)
  1771. X        {
  1772. X        fprintf(stderr,"No File systems left ... Exiting\n");
  1773. X        exit (0);
  1774. X        }
  1775. X#ifdef DEBUG
  1776. X    if (removed)
  1777. X        {
  1778. X        printf ("The following file systems remain:\n");
  1779. X        for (x=0; x<NFS; x++)
  1780. X            printf ("%s\n", fs_name[x]);
  1781. X        }
  1782. X#endif
  1783. X}
  1784. X
  1785. X
  1786. Xvoid do_help (prog)
  1787. Xchar *prog;
  1788. X{
  1789. X    PRINT_COPYRIGHT
  1790. X    printf ("\n\
  1791. X%s displays a list of bar graphs for the file systems of the host you are on.\n\
  1792. XClicking on a file system gives you detailed information - clicking on it \n\
  1793. Xagain closes the detail window. Use %c or the right mouse button to toggle \n\
  1794. Xbetween absolute and relative display modes.\n\
  1795. XThe following switches are supported:\n", prog, TOGGLE_KEY);
  1796. X#ifndef TOS
  1797. Xprintf ("    -r              graphs space available to root rather \
  1798. Xthan user\n");
  1799. X#endif
  1800. Xprintf ("    -b         draw graphs black\n\
  1801. X    -m        minimize window size\n\
  1802. X    -p        don't display percent\n\
  1803. X    -a        toggle display mode to absolute bar size\n\
  1804. X    -f              displays percent free rather then percent in use\n\
  1805. X    -s <arg>     scale sleep time by argument\n\
  1806. X        -i <arg>        interval at which display is updated (default = 300s)\n\
  1807. X        -d <arg1 ... argn> do not include these file systems\n\
  1808. X        -?              get this description\n");
  1809. X    PRINT_KNOWN_BUGS
  1810. X    exit (0);
  1811. X}
  1812. X
  1813. X
  1814. X
  1815. X/* **************************************************************** */
  1816. X/*  msleep will wait for n microseconds for a dummy I/O descriptor  */
  1817. X/*  **** take from Tom Boutell's Broken Throne with permission **** */
  1818. X/* **************************************************************** */
  1819. Xvoid msleep ()
  1820. X{
  1821. X    struct timeval  sleept;
  1822. X        
  1823. X    sleept.tv_sec = sec;
  1824. X    sleept.tv_usec = usec; 
  1825. X    select(FD_SETSIZE, NULL, NULL, NULL, &sleept);
  1826. X}
  1827. X
  1828. X
  1829. X
  1830. X
  1831. X/* ***************************************************************** */
  1832. X/* ********** this basically inits the window definitions ********** */
  1833. X/* ***************************************************************** */
  1834. Xvoid init_all_windows ()
  1835. X{
  1836. X        int i;
  1837. X    char s[30];
  1838. X    unsigned long     small_event_mask, big_event_mask, fs_mask, these_flags;
  1839. X
  1840. X        these_flags = PPosition | PSize;
  1841. X    small_event_mask= PPosition | PSize | StructureNotifyMask | 
  1842. X        ExposureMask| KeyPressMask | EnterWindowMask | LeaveWindowMask;
  1843. X        big_event_mask=ButtonPressMask | ExposureMask | EnterWindowMask 
  1844. X        | LeaveWindowMask;
  1845. X    fs_mask=ButtonPressMask | ExposureMask;
  1846. X    sprintf (s, "%s", hname);
  1847. X#ifndef TOS
  1848. X    if (root)
  1849. X        sprintf (s, "%s root", s);
  1850. X    else
  1851. X        sprintf (s, "%s user", s);
  1852. X#endif
  1853. X
  1854. X    if (show_use)
  1855. X        sprintf (s, "%s used", s);
  1856. X    else
  1857. X        sprintf (s, "%s free", s);
  1858. X        
  1859. X    strcpy (main_win.text, s);
  1860. X        main_win.x=WIN_X;
  1861. X        main_win.y=WIN_Y;
  1862. X    if (minimize)
  1863. X        {
  1864. X            main_win.width=MIN_WIN_X;
  1865. X            main_win.height=((MIN_INTERVAL*NFS)+BEGIN_NFS);
  1866. X        }
  1867. X    else
  1868. X        {
  1869. X            main_win.width=WIN_X;
  1870. X            main_win.height=((INTERVAL*NFS)+BEGIN_NFS);
  1871. X        }
  1872. X        main_win.line_thick=4;
  1873. X        main_win.flags=these_flags;
  1874. X        main_win.event_mask=small_event_mask;
  1875. X        for (i=0; i<MENU_ITEMS; i++)
  1876. X                {
  1877. X                strcpy (menu[i].text, Menu_Text[i]);
  1878. X        menu[i].x=((main_win.width-SM_MENU_WIDTH)/2);
  1879. X                menu[i].y=MENU_Y+MENU_HEIGHT*i;
  1880. X                menu[i].width=SM_MENU_WIDTH;
  1881. X                menu[i].height=MENU_HEIGHT;
  1882. X                menu[i].line_thick=0;
  1883. X                menu[i].event_mask=big_event_mask;
  1884. X                menu[i].flags=these_flags;
  1885. X                }
  1886. X        for (i=0; i<NFS; i++)
  1887. X                {
  1888. X        fs_win[i].x=OFF_X;
  1889. X        if (minimize)
  1890. X            {
  1891. X                    fs_win[i].y=((MIN_INTERVAL*i)+BEGIN_NFS);
  1892. X                    fs_win[i].height=MIN_MENU_HEIGHT;
  1893. X            }
  1894. X        else
  1895. X            {
  1896. X                    fs_win[i].y=((INTERVAL*i)+BEGIN_NFS);
  1897. X                    fs_win[i].height=MENU_HEIGHT;
  1898. X            }
  1899. X            fs_win[i].width=main_win.width-OFF_X-OFF_X; 
  1900. X        if (!absolute) 
  1901. X            {
  1902. X            fs_win[i].width=(int)(fs_win[i].width*
  1903. X                (((float)stats[i].f_blocks)/((float)b_blocks)));
  1904. X            if (!fs_win[i].width)
  1905. X                fs_win[i].width=1;
  1906. X            }
  1907. X                fs_win[i].line_thick=1;
  1908. X                fs_win[i].event_mask=fs_mask;
  1909. X                fs_win[i].flags=these_flags;
  1910. X                }
  1911. X    sprintf (s, "%s detail", hname);
  1912. X    strcpy (detail_win.text, s);
  1913. X    detail_win.x=OFF_X;
  1914. X    detail_win.y=OFF_Y;
  1915. X    detail_win.width=DETAIL_X;
  1916. X    detail_win.height=DETAIL_Y;
  1917. X    detail_win.line_thick=4;
  1918. X    detail_win.event_mask=small_event_mask;
  1919. X    detail_win.flags=these_flags;
  1920. X}
  1921. /
  1922. echo x - Manifest
  1923. sed '/^X/s///' > Manifest << '/'
  1924. XThis distribution contains the following files:
  1925. X
  1926. X Name            Amount            Description
  1927. X------------------------------------------------------------
  1928. XImakefile        1            Imakefile
  1929. XMakefile.std        1            sample Makefile
  1930. XManifest        1            This shipping list
  1931. XCopyright        1            Copyright Notice
  1932. XREADME            1            Docs
  1933. Xmain.h            1            definitions
  1934. Xmain.c            1            main and X event loop
  1935. Xutil.c            1            support routines
  1936. /
  1937.  
  1938. exit 0 # Just in case...
  1939. -- 
  1940.   // chris@IMD.Sterling.COM            | Send comp.sources.x submissions to:
  1941. \X/  Amiga - The only way to fly!      |
  1942.  "It's intuitively obvious to the most |    sources-x@imd.sterling.com
  1943.   casual observer..."                  |
  1944.