2022-10-04 05:47:23 +02:00
|
|
|
/*
|
|
|
|
* nonascii.c
|
|
|
|
*
|
|
|
|
* new Mon 03 Oct 2022 05:42:42 PM CEST
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2022-12-16 20:41:32 +01:00
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
int check_a_file_by_fp(FILE *fp, char *filename)
|
2022-10-04 05:47:23 +02:00
|
|
|
{
|
|
|
|
int input, linenum, count;
|
|
|
|
int flagline;
|
|
|
|
|
2022-10-04 19:31:50 +02:00
|
|
|
linenum = 1; /* humans start line count at 1 */
|
2022-10-04 05:47:23 +02:00
|
|
|
count = 0;
|
|
|
|
|
|
|
|
while (EOF != (input=getc(stdin))) {
|
|
|
|
if ('\n' == input) {
|
|
|
|
linenum++;
|
|
|
|
flagline = 0;
|
|
|
|
}
|
|
|
|
if ((input < 0) || (input>127)) {
|
|
|
|
if (!flagline) {
|
2022-12-16 20:41:32 +01:00
|
|
|
fprintf(stderr, "%s: non ascii 0x%x line %d\n",
|
|
|
|
filename,
|
2022-10-04 05:47:23 +02:00
|
|
|
input, linenum);
|
|
|
|
flagline = 1;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2022-12-16 20:41:32 +01:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
int check_a_file_by_name(char *name)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
if (NULL == name) {
|
|
|
|
fp = stdin;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (NULL==(fp=fopen(name, "r"))) {
|
|
|
|
perror(name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foo = check_a_file_by_fp(fp, NULL==name ? "<stdin>" : name);
|
|
|
|
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int foo, idx;
|
|
|
|
|
|
|
|
if (1 == argc) {
|
|
|
|
foo = check_a_file_by_name(NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (idx=1; idx<argc; idx++) {
|
|
|
|
printf("%4d %s\n", idx, argv[idx]);
|
|
|
|
}
|
2022-10-04 05:47:23 +02:00
|
|
|
}
|
2022-12-16 20:41:32 +01:00
|
|
|
|
2022-10-04 05:47:23 +02:00
|
|
|
return 0;
|
2022-12-16 20:41:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|