clicker.c 477 B

123456789101112131415161718192021222324252627282930
  1. /*-
  2. * G_clicker()
  3. *
  4. * Print a clock hand (one of '|', '/', '-', '\') to stderr.
  5. * Used in place of G_percent for unknown number of iterations
  6. *
  7. */
  8. #include <stdio.h>
  9. static int G_clicker_prev = 0;
  10. int G_clicker(void)
  11. {
  12. int x;
  13. static char clicks[] = "|/-\\";
  14. if (G_clicker_prev == -1 || G_clicker_prev == 3)
  15. x = 0;
  16. else
  17. x = G_clicker_prev + 1;
  18. fprintf(stderr, "%1c\b", clicks[x]);
  19. fflush(stderr);
  20. G_clicker_prev = x;
  21. return 0;
  22. }