2016-12-18 22:43:53 +02:00
|
|
|
/* Copyright (C) 2016 Arti Zirk <arti.zirk@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of I237 Door Access program.
|
|
|
|
*
|
|
|
|
* I237 Door Access is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* I237 Door Access is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with I237 Door Access. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-09-26 17:33:02 +03:00
|
|
|
#include <stdio.h>
|
2016-10-23 22:49:49 +03:00
|
|
|
#include <avr/pgmspace.h>
|
2016-09-26 17:33:02 +03:00
|
|
|
#include "print_helper.h"
|
|
|
|
|
2016-10-11 00:43:31 +03:00
|
|
|
int print_ascii_tbl (FILE *stream)
|
|
|
|
{
|
2016-09-26 17:33:02 +03:00
|
|
|
for (char c = ' '; c <= '~'; c++) {
|
2016-10-11 00:43:31 +03:00
|
|
|
if (!fprintf(stream, "%c ", c)) {
|
2016-09-26 17:33:02 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 00:43:31 +03:00
|
|
|
|
2016-09-26 17:33:02 +03:00
|
|
|
return fprintf(stream, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-11 00:43:31 +03:00
|
|
|
int print_for_human (FILE *stream, const unsigned char *array, const int len)
|
|
|
|
{
|
2016-09-26 17:33:02 +03:00
|
|
|
for (int i = 0; i < len; i++) {
|
2016-10-23 22:49:49 +03:00
|
|
|
unsigned char c = array[i];
|
|
|
|
if (c >= ' ' && c <= '~') {
|
|
|
|
if (!fprintf(stream, "%c", c)) {
|
2016-09-26 17:33:02 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
2016-10-23 22:49:49 +03:00
|
|
|
if (!fprintf(stream, "\"0x%02x\"", c)) {
|
2016-09-26 17:33:02 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 00:43:31 +03:00
|
|
|
|
2016-10-23 22:49:49 +03:00
|
|
|
return fprintf(stream, "\n");
|
2016-09-26 17:33:02 +03:00
|
|
|
}
|