Xmipp  v3.23.11-Nereus
lib_std.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * L I B _ S T D *
3 **********************************************************************
4 * Library is part of the Situs package (c) Willy Wriggers, 1998-2003 *
5 * URL: situs.biomachina.org *
6 **********************************************************************
7 * *
8 * Auxiliary routines to read from stdin. *
9 * *
10 **********************************************************************
11 * See legal statement for terms of distribution *
12 *********************************************************************/
13 
14 #include "situs.h"
15 #include "lib_std.h"
16 #include "lib_err.h"
17 
18 /* returns first integer from input stream and checks for EOF or errors */
20 {
21  int i, ch;
22  const char *program = "lib_std";
23 
24  if (scanf("%d", &i) == EOF) {
25  error_EOF(14010, program);
26  }
27  for (; ;) {
28  ch = getchar();
29  if (ch == EOF) {
30  error_EOF(14020, program);
31  }
32  if (ch == '\n') break;
33  }
34  return i;
35 }
36 
37 /* returns first double from input stream and checks for EOF or errors */
38 double readln_double()
39 {
40  double ddx;
41  int ch;
42  const char *program = "lib_std";
43 
44  if (scanf("%le", &ddx) == EOF) {
45  error_EOF(14030, program);
46  }
47  for (; ;) {
48  ch = getchar();
49  if (ch == EOF) {
50  error_EOF(14040, program);
51  }
52  if (ch == '\n') break;
53  }
54  return ((double)ddx);
55 }
56 
57 /* removes erroneously pasted spaces from file name string */
58 void removespaces(char *file_name, unsigned fl)
59 {
60  int i;
61 
62  file_name[fl - 1] = '\0';
63 
64  /* remove leading space */
65  for (;;) {
66  if (file_name[0] == ' ') {
67  for (i = 1; i < (int)fl; ++i) file_name[i - 1] = file_name[i];
68  --fl;
69  } else break;
70  }
71 
72  /* remove trailing white space */
73  for (i = 0; i < (int)fl; ++i) if (file_name[i] == '\n' || file_name[i] == ' ') {
74  file_name[i] = '\0';
75  break;
76  }
77 }
78 
79 /* returns first char from input stream and checks for EOF or errors */
81 {
82  char cx;
83  int ch;
84  const char *program = "lib_std";
85 
86  if (scanf("%c", &cx) == EOF) {
87  error_EOF(14050, program);
88  }
89  for (; ;) {
90  ch = getchar();
91  if (ch == EOF) {
92  error_EOF(14060, program);
93  }
94  if (ch == '\n') break;
95  }
96  return ((char)cx);
97 }
98 
99 
void error_EOF(int error_number, const char *program)
Definition: lib_err.cpp:101
#define i
double readln_double()
Definition: lib_std.cpp:38
int readln_int()
Definition: lib_std.cpp:19
void removespaces(char *file_name, unsigned fl)
Definition: lib_std.cpp:58
char readln_char()
Definition: lib_std.cpp:80