|
47 | 47 | #include <stdlib.h>
|
48 | 48 |
|
49 | 49 | /**
|
50 |
| - * TODO |
51 |
| - * |
52 |
| - * https://gustedt.wordpress.com/2010/06/03/default-arguments-for-c99/ |
| 50 | + * Temporarily used to make arguments to get_* (but not Get*) optional. |
| 51 | + * Inspired by https://gustedt.wordpress.com/2010/06/03/default-arguments-for-c99/. |
53 | 52 | */
|
54 | 53 | #define _ARGS(_0, _1, _2, ...) _2
|
55 | 54 | #define ARGS(...) _ARGS(, ##__VA_ARGS__, 1, 0)
|
56 |
| -#define ARG_0(NAME) "Retry: " |
| 55 | +#define ARG_0(NAME) NULL |
57 | 56 | #define ARG_1(NAME, a) a
|
58 | 57 | #define __ZERO_OR_ONE_ARG(NAME, N, ...) ARG_ ## N (NAME, ##__VA_ARGS__)
|
59 | 58 | #define _ZERO_OR_ONE_ARG(NAME, N, ...) __ZERO_OR_ONE_ARG(NAME, N, ##__VA_ARGS__)
|
@@ -85,58 +84,58 @@ void eprintf(const char *file, int line, const char *format, ...) __attribute__(
|
85 | 84 | #define eprintf(format, ...) eprintf(__FILE__, __LINE__, format, ##__VA_ARGS__)
|
86 | 85 |
|
87 | 86 | /**
|
88 |
| - * Reads a line of text from standard input and returns the equivalent |
89 |
| - * char; if text does not represent a char, user is prompted to retry. |
90 |
| - * Leading and trailing whitespace is ignored. If line can't be read, |
91 |
| - * returns CHAR_MAX. |
| 87 | + * Prompts user for a line of text from standard input and returns the |
| 88 | + * equivalent char; if text does not represent a char, user is prompted |
| 89 | + * to retry. Leading and trailing whitespace is ignored. If line can't |
| 90 | + * be read, returns CHAR_MAX. |
92 | 91 | */
|
93 | 92 | char get_char(string prompt);
|
94 | 93 | char GetChar(void) __attribute__((deprecated));
|
95 | 94 | #define get_char(...) ZERO_OR_ONE_ARG(get_char, ##__VA_ARGS__)
|
96 | 95 |
|
97 | 96 | /**
|
98 |
| - * Reads a line of text from standard input and returns the equivalent |
99 |
| - * double as precisely as possible; if text does not represent a |
100 |
| - * double or if value would cause underflow or overflow, user is |
| 97 | + * Prompts user for a line of text from standard input and returns the |
| 98 | + * equivalent double as precisely as possible; if text does not represent |
| 99 | + * a double or if value would cause underflow or overflow, user is |
101 | 100 | * prompted to retry. If line can't be read, returns DBL_MAX.
|
102 | 101 | */
|
103 | 102 | double get_double(string prompt);
|
104 | 103 | double GetDouble(void) __attribute__((deprecated));
|
105 | 104 | #define get_double(...) ZERO_OR_ONE_ARG(get_double, ##__VA_ARGS__)
|
106 | 105 |
|
107 | 106 | /**
|
108 |
| - * Reads a line of text from standard input and returns the equivalent |
109 |
| - * float as precisely as possible; if text does not represent a float |
110 |
| - * or if value would cause underflow or overflow, user is prompted to |
111 |
| - * retry. If line can't be read, returns FLT_MAX. |
| 107 | + * Prompts user for a line of text from standard input and returns the |
| 108 | + * equivalent float as precisely as possible; if text does not represent |
| 109 | + * a float or if value would cause underflow or overflow, user is prompted |
| 110 | + * to retry. If line can't be read, returns FLT_MAX. |
112 | 111 | */
|
113 | 112 | float get_float(string prompt);
|
114 | 113 | float GetFloat(void) __attribute__((deprecated));
|
115 | 114 | #define get_float(...) ZERO_OR_ONE_ARG(get_float, ##__VA_ARGS__)
|
116 | 115 |
|
117 | 116 | /**
|
118 |
| - * Reads a line of text from standard input and returns it as an |
119 |
| - * int in [-2^31, 2^31 - 1), if possible; if text does not represent |
120 |
| - * such an int or if value would cause underflow or overflow, user is |
121 |
| - * prompted to retry. If line can't be read, returns INT_MAX. |
| 117 | + * Prompts user for a line of text from standard input and returns the |
| 118 | + * equivalent int; if text does not represent an int in [-2^31, 2^31 - 1) |
| 119 | + * or would cause underflow or overflow, user is prompted to retry. If line |
| 120 | + * can't be read, returns INT_MAX. |
122 | 121 | */
|
123 | 122 | int get_int(string prompt);
|
124 | 123 | int GetInt(void) __attribute__((deprecated));
|
125 | 124 | #define get_int(...) ZERO_OR_ONE_ARG(get_int, ##__VA_ARGS__)
|
126 | 125 |
|
127 | 126 | /**
|
128 |
| - * Reads a line of text from standard input and returns an equivalent |
129 |
| - * long long in [-2^63, 2^63 - 1), if possible; if text does not |
130 |
| - * represent such a long long or if value would cause underflow or overflow, |
131 |
| - * user is prompted to retry. If line can't be read, returns LLONG_MAX. |
| 127 | + * Prompts user for a line of text from standard input and returns the |
| 128 | + * equivalent long long; if text does not represent a long long in |
| 129 | + * [-2^63, 2^63 - 1) or would cause underflow or overflow, user is |
| 130 | + * prompted to retry. If line can't be read, returns LLONG_MAX. |
132 | 131 | */
|
133 | 132 | long long get_long_long(string prompt);
|
134 | 133 | long long GetLongLong(void) __attribute__((deprecated));
|
135 | 134 | #define get_long_long(...) ZERO_OR_ONE_ARG(get_long_long, ##__VA_ARGS__)
|
136 | 135 |
|
137 | 136 | /**
|
138 |
| - * Reads a line of text from standard input and returns it as |
139 |
| - * a string (char *), sans trailing line ending. Supports |
| 137 | + * Prompts user for a line of text from standard input and returns |
| 138 | + * it as a string (char *), sans trailing line ending. Supports |
140 | 139 | * CR (\r), LF (\n), and CRLF (\r\n) as line endings. If user
|
141 | 140 | * inputs only "\n", returns "", not NULL. Returns NULL upon
|
142 | 141 | * error or no input whatsoever (i.e., just EOF). Stores string
|
|
0 commit comments