Line numbers.
This commit is contained in:
parent
07bce58799
commit
756ef9e485
|
@ -9,10 +9,12 @@
|
||||||
#include <ctype.h> /* isdigit */
|
#include <ctype.h> /* isdigit */
|
||||||
#include <limits.h> /* LONG_ INT_ _MIN _MAX */
|
#include <limits.h> /* LONG_ INT_ _MIN _MAX */
|
||||||
#include <assert.h> /* assert */
|
#include <assert.h> /* assert */
|
||||||
#include "min_array.h"
|
#include "../src/min_array.h"
|
||||||
|
|
||||||
|
struct num { size_t line; int num; };
|
||||||
|
|
||||||
MIN_ARRAY(char, char)
|
MIN_ARRAY(char, char)
|
||||||
MIN_ARRAY(num, int)
|
MIN_ARRAY(num, struct num)
|
||||||
|
|
||||||
/** Concatenates the contents after the file pointer of `fp` to `string`. Zeros
|
/** Concatenates the contents after the file pointer of `fp` to `string`. Zeros
|
||||||
are preserved, as well as appending a null-terminator. @return Success,
|
are preserved, as well as appending a null-terminator. @return Success,
|
||||||
|
@ -37,7 +39,7 @@ int main(void) {
|
||||||
int success = EXIT_FAILURE;
|
int success = EXIT_FAILURE;
|
||||||
struct char_array str = MIN_ARRAY_IDLE;
|
struct char_array str = MIN_ARRAY_IDLE;
|
||||||
struct num_array nums = MIN_ARRAY_IDLE;
|
struct num_array nums = MIN_ARRAY_IDLE;
|
||||||
int *num;
|
struct num *num;
|
||||||
long big_num;
|
long big_num;
|
||||||
char *a, *anum = 0;
|
char *a, *anum = 0;
|
||||||
size_t i, line = 1 /* Unix: delimited by '\n'. */;
|
size_t i, line = 1 /* Unix: delimited by '\n'. */;
|
||||||
|
@ -56,14 +58,16 @@ int main(void) {
|
||||||
goto catch; /* Long conversion failed, (not all platforms.) */
|
goto catch; /* Long conversion failed, (not all platforms.) */
|
||||||
if(big_num < INT_MIN || big_num > INT_MAX)
|
if(big_num < INT_MIN || big_num > INT_MAX)
|
||||||
{ errno = ERANGE; goto catch; }
|
{ errno = ERANGE; goto catch; }
|
||||||
*num = (int)big_num;
|
num->line = line;
|
||||||
|
num->num = (int)big_num;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Extracted:\n");
|
fprintf(stderr, "Extracted:\n");
|
||||||
for(i = 0; i < nums.size; i++) printf("%d\n", nums.data[i]);
|
for(i = 0; i < nums.size; i++) printf("Line %lu: %d\n",
|
||||||
|
(unsigned long)nums.data[i].line, nums.data[i].num);
|
||||||
success = EXIT_SUCCESS;
|
success = EXIT_SUCCESS;
|
||||||
goto finally;
|
goto finally;
|
||||||
catch:
|
catch:
|
||||||
fprintf(stderr, "Line %lu ", line), perror("stdin");
|
fprintf(stderr, "Line %lu ", (unsigned long)line), perror("stdin");
|
||||||
finally:
|
finally:
|
||||||
char_array_(&str);
|
char_array_(&str);
|
||||||
num_array_(&nums);
|
num_array_(&nums);
|
Loading…
Reference in New Issue