summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/lib/input2int.c
blob: 5bd42016b4e3eff25b10b01f9a3bdcfe14267e70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* input2int.c: read two or three integers from text files.  These
   routines are only used in patgen.  Public domain. */

#include <w2c/config.h>
#include "lib.h"

#ifdef INTEGER_IS_INT
#define SCAN2INT "%d %d"
#define SCAN3INT "%d %d %d"
#else
#define SCAN2INT "%ld %ld"
#define SCAN3INT "%ld %ld %ld"
#endif

/* Read two integers from stdin.  */

void
zinput2ints (integer *a,  integer *b)
{
  int ch;

  while (scanf (SCAN2INT, a, b) != 2)
    {
      while ((ch = getchar ()) != EOF && ch != '\n');
      if (ch == EOF) return;
      fprintf (stderr, "Please enter two integers.\n");
    }

  while ((ch = getchar ()) != EOF && ch != '\n');
}


/* Read three integers from stdin.  */

void
zinput3ints (integer *a,  integer *b,  integer *c)
{
  int ch;

  while (scanf (SCAN3INT, a, b, c) != 3)
    {
      while ((ch = getchar ()) != EOF && ch != '\n');
      if (ch == EOF) return;
      fprintf (stderr, "Please enter three integers.\n");
    }

  while ((ch = getchar ()) != EOF && ch != '\n');
}