1
/* A stupid little spinning wheel designed to make it look like useful work
5
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
7
This file is part of the GNU MP Library.
9
The GNU MP Library is free software; you can redistribute it and/or modify
10
it under the terms of the GNU Lesser General Public License as published by
11
the Free Software Foundation; either version 2.1 of the License, or (at your
12
option) any later version.
14
The GNU MP Library is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
License for more details.
19
You should have received a copy of the GNU Lesser General Public License
20
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
21
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30
#include <unistd.h> /* for isatty */
39
/* An application can update this to get a count printed with the spinner.
40
If left at 0, no count is printed. */
42
unsigned long spinner_count = 0;
45
static int spinner_wanted = -1; /* -1 uninitialized, 1 wanted, 0 not */
46
static int spinner_tick = 1; /* 1 ready to print, 0 not */
51
spinner_signal (int signum)
55
if (signal (SIGALRM, spinner_signal) == SIG_ERR) abort ();
60
/* Initialize the spinner.
62
This is done the first time spinner() is called, so an application
63
doesn't need to call this directly.
65
The spinner is only wanted if the output is a tty. */
67
#define SPINNER_WANTED_INIT() \
68
if (spinner_wanted < 0) spinner_init ()
73
spinner_wanted = isatty (fileno (stdout));
74
if (spinner_wanted == -1)
80
if (signal (SIGALRM, spinner_signal) == SIG_ERR) abort ();
88
static const char data[] = { '|', '/', '-', '\\' };
93
SPINNER_WANTED_INIT ();
98
pos = (pos + 1) % numberof (data);
101
if (spinner_count != 0)
103
sprintf (buf+1, " %lu\r", spinner_count);