542 |
|
|
543 |
void emit_human_friendly_llu(unsigned long long arg) |
void emit_human_friendly_llu(unsigned long long arg) |
544 |
{ |
{ |
545 |
printf("%llu", arg); |
size_t i, len; |
546 |
|
char buffer[100]; |
547 |
|
|
548 |
|
sprintf(buffer, "%llu", arg); |
549 |
|
len = strlen(buffer); |
550 |
|
|
551 |
|
for (i = 0; i < len; i++) |
552 |
|
{ |
553 |
|
printf("%c", buffer[i]); |
554 |
|
if (((len-i-1) != 0) && (((len - i - 1) % 3) == 0)) |
555 |
|
printf(","); |
556 |
|
} |
557 |
} |
} |
558 |
|
|
559 |
void emit_file_pos_3tuple(unsigned long long line, unsigned long long col, unsigned long long offset) |
void emit_file_pos_3tuple(unsigned long long line, unsigned long long col, unsigned long long offset) |
591 |
char_no = 0; |
char_no = 0; |
592 |
line_no = 1; |
line_no = 1; |
593 |
col_no = 1; |
col_no = 1; |
594 |
in_c = in_i & 0xFF; |
in_c = in_i & 0xff; |
595 |
in_uc = in_i & 0xFF; |
in_uc = in_i & 0xff; |
596 |
|
|
597 |
do |
do |
598 |
{ |
{ |
603 |
printf(" Illegal character: 0x%02x.\n", ((unsigned)in_uc)); |
printf(" Illegal character: 0x%02x.\n", ((unsigned)in_uc)); |
604 |
} |
} |
605 |
|
|
606 |
|
//printf("Character: %02x State: %u\n", in_c, (unsigned)state); |
607 |
|
|
608 |
//Run through the state machine, which would look for bad EOL sequences. |
//Run through the state machine, which would look for bad EOL sequences. |
609 |
switch (state) |
switch (state) |
610 |
{ |
{ |
611 |
case PST_LINE: |
case PST_LINE: |
612 |
|
//Processing non-EOL characters. |
613 |
if (is_lf(in_c)) |
if (is_lf(in_c)) |
614 |
{ |
{ |
615 |
|
if ((char_no != 0) && (prev_c == ' ')) |
616 |
|
{ |
617 |
|
emit_file_pos_3tuple(line_no, col_no, char_no); |
618 |
|
printf(" Line contains trailing whitespace.\n"); |
619 |
|
} |
620 |
|
|
621 |
//Line feeds not allowed without preceding carriage return. |
//Line feeds not allowed without preceding carriage return. |
622 |
emit_file_pos_3tuple(line_no, col_no, char_no); |
emit_file_pos_3tuple(line_no, col_no, char_no); |
623 |
printf(" Out of sequence line feed character (0x0a)\n"); |
printf(" Out of sequence line feed character (0x0a).\n"); |
624 |
line_no++; |
line_no++; |
625 |
col_no = 1; |
col_no = 1; |
626 |
state = PST_LF_FOUND; |
state = PST_LF_FOUND; |
627 |
} |
} |
628 |
else if (is_cr(in_c)) |
else if (is_cr(in_c)) |
629 |
{ |
{ |
630 |
|
if ((char_no != 0) && (prev_c == ' ')) |
631 |
|
{ |
632 |
|
emit_file_pos_3tuple(line_no, col_no, char_no); |
633 |
|
printf(" Line contains trailing whitespace.\n"); |
634 |
|
} |
635 |
|
|
636 |
//Legal |
//Legal |
637 |
state = PST_CR_FOUND; |
state = PST_CR_FOUND; |
638 |
} |
} |
654 |
{ |
{ |
655 |
//Back-to-back carriage returns not allowed. |
//Back-to-back carriage returns not allowed. |
656 |
emit_file_pos_3tuple(line_no, col_no, char_no); |
emit_file_pos_3tuple(line_no, col_no, char_no); |
657 |
printf(" Out of sequence carriage return character (0x0D)\n"); |
printf(" Out of sequence carriage return character (0x0D).\n"); |
658 |
col_no++; |
col_no++; |
659 |
} |
} |
660 |
else |
else |
678 |
{ |
{ |
679 |
//Legal. Blank lines are fine. |
//Legal. Blank lines are fine. |
680 |
col_no++; |
col_no++; |
681 |
state = PST_LF_FOUND; |
state = PST_CR_FOUND; |
682 |
} |
} |
683 |
else |
else |
684 |
{ |
{ |
692 |
break; |
break; |
693 |
} |
} |
694 |
|
|
|
|
|
695 |
in_i = fgetc(f); |
in_i = fgetc(f); |
696 |
char_no++; |
prev_c = in_c; |
|
if (in_i == EOF) |
|
|
exit_flag = 1; |
|
697 |
in_c = in_i & 0xff; |
in_c = in_i & 0xff; |
698 |
in_uc = in_i & 0xff; |
in_uc = in_i & 0xff; |
699 |
|
char_no++; |
700 |
|
if (in_i == EOF) |
701 |
|
{ |
702 |
|
if (state != PST_LF_FOUND) |
703 |
|
{ |
704 |
|
emit_file_pos_3tuple(line_no, col_no, char_no-1); |
705 |
|
printf(" Final line of file does not have CR/LF sequence.\n"); |
706 |
|
} |
707 |
|
if ((state == PST_LINE) && (prev_c == ' ')) |
708 |
|
{ |
709 |
|
emit_file_pos_3tuple(line_no, col_no, char_no - 1); |
710 |
|
printf(" Final line contains trailing whitespace.\n"); |
711 |
|
} |
712 |
|
|
713 |
|
exit_flag = 1; |
714 |
|
} |
715 |
} while (!exit_flag); |
} while (!exit_flag); |
|
|
|
716 |
} |
} |
717 |
|
|
718 |
void process_file_by_name(const char *s) |
void process_file_by_name(const char *s) |