1
0
mirror of https://github.com/systemd/systemd synced 2026-04-22 23:15:20 +02:00

Compare commits

..

6 Commits

Author SHA1 Message Date
Yu Watanabe
27a5281f4b
Merge pull request #22711 from yuwata/c11
move to C11 (gnu11) and use u8 specifier for special characters
2022-03-12 14:27:48 +09:00
Yu Watanabe
6f4bffb586 lgtm: disable cpp/missing-return
As it does not handle assert_not_reahed() gracefully.
2022-03-11 17:19:32 +09:00
Yu Watanabe
5535484e17 qrcode-util: use u8 literal specifier 2022-03-11 15:59:58 +09:00
Yu Watanabe
e5ba040fb8 hostnamectl: use u8 literal specifier 2022-03-11 15:53:18 +09:00
Yu Watanabe
7fbbec71b1 glyph-util: use u8 literal specifier for special characters 2022-03-11 15:35:47 +09:00
Yu Watanabe
2b2dbcbbeb meson: move to c_std=gnu11
Recently, the kernel communitiy started to discuss to move C11 (gnu11) [1],
and it seems to come near future.
Let's also move to c_std=gnu11. Unlike the kernel, we already uses
gnu99, hence hopefully we can move to C11 without changing anything.

[1] https://lore.kernel.org/lkml/CAHk-=wiyCH7xeHcmiFJ-YgXUy2Jaj7pnkdKpcovt8fYbVFW3TA@mail.gmail.com/
2022-03-11 15:13:29 +09:00
5 changed files with 54 additions and 49 deletions

View File

@ -4,6 +4,8 @@
# Explicitly enable certain checks which are hidden by default # Explicitly enable certain checks which are hidden by default
queries: queries:
- exclude: cpp/missing-return
# LGTM does not handle assert_not_reached() gracefully...
- include: cpp/bad-strncpy-size - include: cpp/bad-strncpy-size
- include: cpp/declaration-hides-variable - include: cpp/declaration-hides-variable
- include: cpp/inconsistent-null-check - include: cpp/inconsistent-null-check

View File

@ -4,7 +4,7 @@ project('systemd', 'c',
version : '250', version : '250',
license : 'LGPLv2+', license : 'LGPLv2+',
default_options: [ default_options: [
'c_std=gnu99', 'c_std=gnu11',
'prefix=/usr', 'prefix=/usr',
'sysconfdir=/etc', 'sysconfdir=/etc',
'localstatedir=/var', 'localstatedir=/var',

View File

@ -74,56 +74,56 @@ const char *special_glyph(SpecialGlyph code) {
/* UTF-8 */ /* UTF-8 */
[true] = { [true] = {
/* The following are multiple glyphs in both ASCII and in UNICODE */ /* The following are multiple glyphs in both ASCII and in UNICODE */
[SPECIAL_GLYPH_TREE_VERTICAL] = "\342\224\202 ", /* │ */ [SPECIAL_GLYPH_TREE_VERTICAL] = u8" ",
[SPECIAL_GLYPH_TREE_BRANCH] = "\342\224\234\342\224\200", /* ├─ */ [SPECIAL_GLYPH_TREE_BRANCH] = u8"├─",
[SPECIAL_GLYPH_TREE_RIGHT] = "\342\224\224\342\224\200", /* └─ */ [SPECIAL_GLYPH_TREE_RIGHT] = u8"└─",
[SPECIAL_GLYPH_TREE_SPACE] = " ", /* */ [SPECIAL_GLYPH_TREE_SPACE] = u8" ",
[SPECIAL_GLYPH_TREE_TOP] = "\u250C\342\224\200", /* ┌─ */ [SPECIAL_GLYPH_TREE_TOP] = u8"┌─",
/* Single glyphs in both cases */ /* Single glyphs in both cases */
[SPECIAL_GLYPH_TRIANGULAR_BULLET] = "\342\200\243", /* ‣ */ [SPECIAL_GLYPH_TRIANGULAR_BULLET] = u8"",
[SPECIAL_GLYPH_BLACK_CIRCLE] = "\342\227\217", /* ● */ [SPECIAL_GLYPH_BLACK_CIRCLE] = u8"",
[SPECIAL_GLYPH_WHITE_CIRCLE] = "\u25CB", /* ○ */ [SPECIAL_GLYPH_WHITE_CIRCLE] = u8"",
[SPECIAL_GLYPH_MULTIPLICATION_SIGN] = "\u00D7", /* × */ [SPECIAL_GLYPH_MULTIPLICATION_SIGN] = u8"×",
[SPECIAL_GLYPH_CIRCLE_ARROW] = "\u21BB", /* ↻ */ [SPECIAL_GLYPH_CIRCLE_ARROW] = u8"",
[SPECIAL_GLYPH_BULLET] = "\342\200\242", /* • */ [SPECIAL_GLYPH_BULLET] = u8"",
[SPECIAL_GLYPH_MU] = "\316\274", /* μ (actually called: GREEK SMALL LETTER MU) */ [SPECIAL_GLYPH_MU] = u8"μ", /* actually called: GREEK SMALL LETTER MU */
[SPECIAL_GLYPH_CHECK_MARK] = "\342\234\223", /* ✓ */ [SPECIAL_GLYPH_CHECK_MARK] = u8"",
[SPECIAL_GLYPH_CROSS_MARK] = "\342\234\227", /* ✗ (actually called: BALLOT X) */ [SPECIAL_GLYPH_CROSS_MARK] = u8"", /* actually called: BALLOT X */
[SPECIAL_GLYPH_LIGHT_SHADE] = "\342\226\221", /* ░ */ [SPECIAL_GLYPH_LIGHT_SHADE] = u8"",
[SPECIAL_GLYPH_DARK_SHADE] = "\342\226\223", /* ▒ */ [SPECIAL_GLYPH_DARK_SHADE] = u8"",
[SPECIAL_GLYPH_SIGMA] = "\316\243", /* Σ */ [SPECIAL_GLYPH_SIGMA] = u8"Σ",
[SPECIAL_GLYPH_ARROW_UP] = "\u2191", /* ↑ (actually called: UPWARDS ARROW) */ [SPECIAL_GLYPH_ARROW_UP] = u8"", /* actually called: UPWARDS ARROW */
[SPECIAL_GLYPH_ARROW_DOWN] = "\u2193", /* ↓ (actually called: DOWNWARDS ARROW) */ [SPECIAL_GLYPH_ARROW_DOWN] = u8"", /* actually called: DOWNWARDS ARROW */
/* Single glyph in Unicode, two in ASCII */ /* Single glyph in Unicode, two in ASCII */
[SPECIAL_GLYPH_ARROW_RIGHT] = "\342\206\222", /* → (actually called: RIGHTWARDS ARROW) */ [SPECIAL_GLYPH_ARROW_RIGHT] = u8"", /* actually called: RIGHTWARDS ARROW */
/* Single glyph in Unicode, three in ASCII */ /* Single glyph in Unicode, three in ASCII */
[SPECIAL_GLYPH_ELLIPSIS] = "\342\200\246", /* … (actually called: HORIZONTAL ELLIPSIS) */ [SPECIAL_GLYPH_ELLIPSIS] = u8"", /* actually called: HORIZONTAL ELLIPSIS */
/* Three glyphs in Unicode, five in ASCII */ /* Three glyphs in Unicode, five in ASCII */
[SPECIAL_GLYPH_EXTERNAL_LINK] = "[\360\237\241\225]", /* 🡕 (actually called: NORTH EAST SANS-SERIF ARROW, enclosed in []) */ [SPECIAL_GLYPH_EXTERNAL_LINK] = u8"[🡕]", /* actually called: NORTH EAST SANS-SERIF ARROW, enclosed in [] */
/* These smileys are a single glyph in Unicode, and three in ASCII */ /* These smileys are a single glyph in Unicode, and three in ASCII */
[SPECIAL_GLYPH_ECSTATIC_SMILEY] = "\360\237\230\207", /* 😇 (actually called: SMILING FACE WITH HALO) */ [SPECIAL_GLYPH_ECSTATIC_SMILEY] = u8"😇", /* actually called: SMILING FACE WITH HALO */
[SPECIAL_GLYPH_HAPPY_SMILEY] = "\360\237\230\200", /* 😀 (actually called: GRINNING FACE) */ [SPECIAL_GLYPH_HAPPY_SMILEY] = u8"😀", /* actually called: GRINNING FACE */
[SPECIAL_GLYPH_SLIGHTLY_HAPPY_SMILEY] = "\360\237\231\202", /* 🙂 (actually called: SLIGHTLY SMILING FACE) */ [SPECIAL_GLYPH_SLIGHTLY_HAPPY_SMILEY] = u8"🙂", /* actually called: SLIGHTLY SMILING FACE */
[SPECIAL_GLYPH_NEUTRAL_SMILEY] = "\360\237\230\220", /* 😐 (actually called: NEUTRAL FACE) */ [SPECIAL_GLYPH_NEUTRAL_SMILEY] = u8"😐", /* actually called: NEUTRAL FACE */
[SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY] = "\360\237\231\201", /* 🙁 (actually called: SLIGHTLY FROWNING FACE) */ [SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY] = u8"🙁", /* actually called: SLIGHTLY FROWNING FACE */
[SPECIAL_GLYPH_UNHAPPY_SMILEY] = "\360\237\230\250", /* 😨 (actually called: FEARFUL FACE) */ [SPECIAL_GLYPH_UNHAPPY_SMILEY] = u8"😨", /* actually called: FEARFUL FACE */
[SPECIAL_GLYPH_DEPRESSED_SMILEY] = "\360\237\244\242", /* 🤢 (actually called: NAUSEATED FACE) */ [SPECIAL_GLYPH_DEPRESSED_SMILEY] = u8"🤢", /* actually called: NAUSEATED FACE */
/* This emoji is a single character cell glyph in Unicode, and three in ASCII */ /* This emoji is a single character cell glyph in Unicode, and three in ASCII */
[SPECIAL_GLYPH_LOCK_AND_KEY] = "\360\237\224\220", /* 🔐 (actually called: CLOSED LOCK WITH KEY) */ [SPECIAL_GLYPH_LOCK_AND_KEY] = u8"🔐", /* actually called: CLOSED LOCK WITH KEY */
/* This emoji is a single character cell glyph in Unicode, and two in ASCII */ /* This emoji is a single character cell glyph in Unicode, and two in ASCII */
[SPECIAL_GLYPH_TOUCH] = "\360\237\221\206", /* 👆 (actually called: BACKHAND INDEX POINTING UP) */ [SPECIAL_GLYPH_TOUCH] = u8"👆", /* actually called: BACKHAND INDEX POINTING UP */
/* These three emojis are single character cell glyphs in Unicode and also in ASCII. */ /* These three emojis are single character cell glyphs in Unicode and also in ASCII. */
[SPECIAL_GLYPH_RECYCLING] = "\u267B\uFE0F ", /* ♻️ (actually called: UNIVERSAL RECYCLNG SYMBOL) */ [SPECIAL_GLYPH_RECYCLING] = u8"♻️", /* actually called: UNIVERSAL RECYCLNG SYMBOL */
[SPECIAL_GLYPH_DOWNLOAD] = "\u2935\uFE0F ", /* ⤵️ (actually called: RIGHT ARROW CURVING DOWN) */ [SPECIAL_GLYPH_DOWNLOAD] = u8"⤵️", /* actually called: RIGHT ARROW CURVING DOWN */
[SPECIAL_GLYPH_SPARKLES] = "\u2728", /* ✨ */ [SPECIAL_GLYPH_SPARKLES] = u8"",
}, },
}; };

View File

@ -55,21 +55,21 @@ typedef struct StatusInfo {
static const char* chassis_string_to_glyph(const char *chassis) { static const char* chassis_string_to_glyph(const char *chassis) {
if (streq_ptr(chassis, "laptop")) if (streq_ptr(chassis, "laptop"))
return "\U0001F4BB"; /* Personal Computer */ return u8"💻"; /* Personal Computer */
if (streq_ptr(chassis, "desktop")) if (streq_ptr(chassis, "desktop"))
return "\U0001F5A5"; /* Desktop Computer */ return u8"🖥️"; /* Desktop Computer */
if (streq_ptr(chassis, "server")) if (streq_ptr(chassis, "server"))
return "\U0001F5B3"; /* Old Personal Computer */ return u8"🖳"; /* Old Personal Computer */
if (streq_ptr(chassis, "tablet")) if (streq_ptr(chassis, "tablet"))
return "\u5177"; /* Ideograph tool, implement; draw up, write, looks vaguely tabletty */ return u8""; /* Ideograph tool, implement; draw up, write, looks vaguely tabletty */
if (streq_ptr(chassis, "watch")) if (streq_ptr(chassis, "watch"))
return "\u231A"; /* Watch */ return u8""; /* Watch */
if (streq_ptr(chassis, "handset")) if (streq_ptr(chassis, "handset"))
return "\U0001F57B"; /* Left Hand Telephone Receiver */ return u8"🕻"; /* Left Hand Telephone Receiver */
if (streq_ptr(chassis, "vm")) if (streq_ptr(chassis, "vm"))
return "\U0001F5B4"; /* Hard disk */ return u8"🖴"; /* Hard disk */
if (streq_ptr(chassis, "container")) if (streq_ptr(chassis, "container"))
return "\u2610"; /* Ballot Box */ return u8""; /* Ballot Box */
return NULL; return NULL;
} }

View File

@ -11,6 +11,9 @@
#include "terminal-util.h" #include "terminal-util.h"
#define ANSI_WHITE_ON_BLACK "\033[40;37;1m" #define ANSI_WHITE_ON_BLACK "\033[40;37;1m"
#define UNICODE_FULL_BLOCK u8"█"
#define UNICODE_LOWER_HALF_BLOCK u8"▄"
#define UNICODE_UPPER_HALF_BLOCK u8"▀"
static void *qrcode_dl = NULL; static void *qrcode_dl = NULL;
@ -30,7 +33,7 @@ static void print_border(FILE *output, unsigned width) {
fputs(ANSI_WHITE_ON_BLACK, output); fputs(ANSI_WHITE_ON_BLACK, output);
for (unsigned x = 0; x < 4 + width + 4; x++) for (unsigned x = 0; x < 4 + width + 4; x++)
fputs("\342\226\210", output); fputs(UNICODE_FULL_BLOCK, output);
fputs(ANSI_NORMAL "\n", output); fputs(ANSI_NORMAL "\n", output);
} }
@ -50,7 +53,7 @@ static void write_qrcode(FILE *output, QRcode *qr) {
fputs(ANSI_WHITE_ON_BLACK, output); fputs(ANSI_WHITE_ON_BLACK, output);
for (unsigned x = 0; x < 4; x++) for (unsigned x = 0; x < 4; x++)
fputs("\342\226\210", output); fputs(UNICODE_FULL_BLOCK, output);
for (unsigned x = 0; x < (unsigned) qr->width; x++) { for (unsigned x = 0; x < (unsigned) qr->width; x++) {
bool a, b; bool a, b;
@ -61,15 +64,15 @@ static void write_qrcode(FILE *output, QRcode *qr) {
if (a && b) if (a && b)
fputc(' ', output); fputc(' ', output);
else if (a) else if (a)
fputs("\342\226\204", output); fputs(UNICODE_LOWER_HALF_BLOCK, output);
else if (b) else if (b)
fputs("\342\226\200", output); fputs(UNICODE_UPPER_HALF_BLOCK, output);
else else
fputs("\342\226\210", output); fputs(UNICODE_FULL_BLOCK, output);
} }
for (unsigned x = 0; x < 4; x++) for (unsigned x = 0; x < 4; x++)
fputs("\342\226\210", output); fputs(UNICODE_FULL_BLOCK, output);
fputs(ANSI_NORMAL "\n", output); fputs(ANSI_NORMAL "\n", output);
} }