journal: move qrcode printing code to src/shared/
That way we can make use of it in homctl, too.
This commit is contained in:
parent
b3a97fd3ae
commit
da3920c3a4
|
@ -2196,7 +2196,8 @@ if conf.get('ENABLE_HOMED') == 1
|
||||||
libcrypt,
|
libcrypt,
|
||||||
libopenssl,
|
libopenssl,
|
||||||
libp11kit,
|
libp11kit,
|
||||||
libfido2],
|
libfido2,
|
||||||
|
libdl],
|
||||||
install_rpath : rootlibexecdir,
|
install_rpath : rootlibexecdir,
|
||||||
install : true,
|
install : true,
|
||||||
install_dir : rootbindir)
|
install_dir : rootbindir)
|
||||||
|
|
|
@ -13,24 +13,9 @@
|
||||||
#include "journal-qrcode.h"
|
#include "journal-qrcode.h"
|
||||||
#include "locale-util.h"
|
#include "locale-util.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
|
#include "qrcode-util.h"
|
||||||
#include "terminal-util.h"
|
#include "terminal-util.h"
|
||||||
|
|
||||||
#define ANSI_WHITE_ON_BLACK "\033[40;37;1m"
|
|
||||||
|
|
||||||
static void print_border(FILE *output, unsigned width) {
|
|
||||||
unsigned x, y;
|
|
||||||
|
|
||||||
/* Four rows of border */
|
|
||||||
for (y = 0; y < 4; y += 2) {
|
|
||||||
fputs(ANSI_WHITE_ON_BLACK, output);
|
|
||||||
|
|
||||||
for (x = 0; x < 4 + width + 4; x++)
|
|
||||||
fputs("\342\226\210", output);
|
|
||||||
|
|
||||||
fputs(ANSI_NORMAL "\n", output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int print_qr_code(
|
int print_qr_code(
|
||||||
FILE *output,
|
FILE *output,
|
||||||
const char *prefix_text,
|
const char *prefix_text,
|
||||||
|
@ -47,7 +32,6 @@ int print_qr_code(
|
||||||
_cleanup_free_ char *url = NULL;
|
_cleanup_free_ char *url = NULL;
|
||||||
_cleanup_fclose_ FILE *f = NULL;
|
_cleanup_fclose_ FILE *f = NULL;
|
||||||
size_t url_size = 0;
|
size_t url_size = 0;
|
||||||
unsigned x, y;
|
|
||||||
QRcode* qr;
|
QRcode* qr;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -106,40 +90,7 @@ int print_qr_code(
|
||||||
if (prefix_text)
|
if (prefix_text)
|
||||||
fputs(prefix_text, output);
|
fputs(prefix_text, output);
|
||||||
|
|
||||||
print_border(output, qr->width);
|
write_qrcode(output, qr);
|
||||||
|
|
||||||
for (y = 0; y < (unsigned) qr->width; y += 2) {
|
|
||||||
const uint8_t *row1, *row2;
|
|
||||||
|
|
||||||
row1 = qr->data + qr->width * y;
|
|
||||||
row2 = row1 + qr->width;
|
|
||||||
|
|
||||||
fputs(ANSI_WHITE_ON_BLACK, output);
|
|
||||||
for (x = 0; x < 4; x++)
|
|
||||||
fputs("\342\226\210", output);
|
|
||||||
|
|
||||||
for (x = 0; x < (unsigned) qr->width; x ++) {
|
|
||||||
bool a, b;
|
|
||||||
|
|
||||||
a = row1[x] & 1;
|
|
||||||
b = (y+1) < (unsigned) qr->width ? (row2[x] & 1) : false;
|
|
||||||
|
|
||||||
if (a && b)
|
|
||||||
fputc(' ', output);
|
|
||||||
else if (a)
|
|
||||||
fputs("\342\226\204", output);
|
|
||||||
else if (b)
|
|
||||||
fputs("\342\226\200", output);
|
|
||||||
else
|
|
||||||
fputs("\342\226\210", output);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (x = 0; x < 4; x++)
|
|
||||||
fputs("\342\226\210", output);
|
|
||||||
fputs(ANSI_NORMAL "\n", output);
|
|
||||||
}
|
|
||||||
|
|
||||||
print_border(output, qr->width);
|
|
||||||
|
|
||||||
sym_QRcode_free(qr);
|
sym_QRcode_free(qr);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -304,6 +304,13 @@ if conf.get('HAVE_PAM') == 1
|
||||||
'''.split())
|
'''.split())
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if conf.get('HAVE_QRENCODE') == 1
|
||||||
|
shared_sources += files('''
|
||||||
|
qrcode-util.c
|
||||||
|
qrcode-util.h
|
||||||
|
'''.split())
|
||||||
|
endif
|
||||||
|
|
||||||
generate_ip_protocol_list = find_program('generate-ip-protocol-list.sh')
|
generate_ip_protocol_list = find_program('generate-ip-protocol-list.sh')
|
||||||
ip_protocol_list_txt = custom_target(
|
ip_protocol_list_txt = custom_target(
|
||||||
'ip-protocol-list.txt',
|
'ip-protocol-list.txt',
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
#include "qrcode-util.h"
|
||||||
|
#include "terminal-util.h"
|
||||||
|
|
||||||
|
#define ANSI_WHITE_ON_BLACK "\033[40;37;1m"
|
||||||
|
|
||||||
|
static void print_border(FILE *output, unsigned width) {
|
||||||
|
unsigned x, y;
|
||||||
|
|
||||||
|
/* Four rows of border */
|
||||||
|
for (y = 0; y < 4; y += 2) {
|
||||||
|
fputs(ANSI_WHITE_ON_BLACK, output);
|
||||||
|
|
||||||
|
for (x = 0; x < 4 + width + 4; x++)
|
||||||
|
fputs("\342\226\210", output);
|
||||||
|
|
||||||
|
fputs(ANSI_NORMAL "\n", output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_qrcode(FILE *output, QRcode *qr) {
|
||||||
|
unsigned x, y;
|
||||||
|
|
||||||
|
assert(qr);
|
||||||
|
|
||||||
|
if (!output)
|
||||||
|
output = stdout;
|
||||||
|
|
||||||
|
print_border(output, qr->width);
|
||||||
|
|
||||||
|
for (y = 0; y < (unsigned) qr->width; y += 2) {
|
||||||
|
const uint8_t *row1, *row2;
|
||||||
|
|
||||||
|
row1 = qr->data + qr->width * y;
|
||||||
|
row2 = row1 + qr->width;
|
||||||
|
|
||||||
|
fputs(ANSI_WHITE_ON_BLACK, output);
|
||||||
|
for (x = 0; x < 4; x++)
|
||||||
|
fputs("\342\226\210", output);
|
||||||
|
|
||||||
|
for (x = 0; x < (unsigned) qr->width; x ++) {
|
||||||
|
bool a, b;
|
||||||
|
|
||||||
|
a = row1[x] & 1;
|
||||||
|
b = (y+1) < (unsigned) qr->width ? (row2[x] & 1) : false;
|
||||||
|
|
||||||
|
if (a && b)
|
||||||
|
fputc(' ', output);
|
||||||
|
else if (a)
|
||||||
|
fputs("\342\226\204", output);
|
||||||
|
else if (b)
|
||||||
|
fputs("\342\226\200", output);
|
||||||
|
else
|
||||||
|
fputs("\342\226\210", output);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (x = 0; x < 4; x++)
|
||||||
|
fputs("\342\226\210", output);
|
||||||
|
fputs(ANSI_NORMAL "\n", output);
|
||||||
|
}
|
||||||
|
|
||||||
|
print_border(output, qr->width);
|
||||||
|
fflush(output);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if HAVE_QRENCODE
|
||||||
|
#include <qrencode.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void write_qrcode(FILE *output, QRcode *qr);
|
||||||
|
#endif
|
Loading…
Reference in New Issue