Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / gnu / lib / libdialog / gauge.c
1 /*
2  * gauge.c
3  *
4  * progress indicator for libdialog
5  *
6  *
7  * Copyright (c) 1995, Marc van Kempen
8  *
9  * All rights reserved.
10  *
11  * This software may be used, modified, copied, distributed, and
12  * sold, in both source and binary form provided that the above
13  * copyright and these terms are retained, verbatim, as the first
14  * lines of this file.  Under no circumstances is the author
15  * responsible for the proper functioning of this software, nor does
16  * the author assume any responsibility for damages incurred with
17  * its use.
18  *
19  * $FreeBSD: src/gnu/lib/libdialog/gauge.c,v 1.2.12.2 2002/06/18 07:55:55 dougb Exp $
20  * $DragonFly: src/gnu/lib/libdialog/gauge.c,v 1.2 2003/06/17 04:25:43 dillon Exp $
21  */
22
23 #include <stdlib.h>
24
25 #include "dialog.h"
26
27 void
28 dialog_gauge(char *title, char *prompt, int y, int x,
29              int height, int width, int perc)
30 /*
31  * Desc: display a progress bar, progress indicated by <perc>
32  */
33 {
34     WINDOW      *gw;
35     int         glen, i;
36     char        percs[5];
37
38     gw = newwin(height, width, y, x);
39     if (!gw) {
40         fprintf(stderr, "dialog_gauge: Error creating window (%d, %d, %d, %d)",
41                 height, width, y, x);
42         exit(-1);
43     }
44
45     draw_box(gw, 0, 0, height, width, dialog_attr, border_attr);
46     draw_shadow(stdscr, y, x, height, width);
47
48     wattrset(gw, title_attr);
49     if (title) {
50         wmove(gw, 0, (width - strlen(title))/2 - 1);
51         waddstr(gw, "[ ");
52         waddstr(gw, title);
53         waddstr(gw, " ]");
54     }
55     wattrset(gw, dialog_attr);
56     if (prompt) {
57         wmove(gw, 1, (width - strlen(prompt))/2 - 1);
58         waddstr(gw, prompt);
59     }
60
61     draw_box(gw, 2, 2, 3, width-4, dialog_attr, border_attr);
62     glen = (int) ((float) perc/100 * (width-6));
63
64     wattrset(gw, dialog_attr);
65     sprintf(percs, "%3d%%", perc);
66     wmove(gw, 5, width/2 - 2);
67     waddstr(gw, percs);
68
69     wattrset(gw, A_BOLD);
70     wmove(gw, 3, 3);
71     for (i=0; i<glen; i++) waddch(gw, ' ');
72
73     wrefresh(gw);
74     delwin(gw);
75
76     return;
77 } /* dialog_gauge() */
78