Improve formatting

This commit is contained in:
GenjiFujimoto 2023-05-28 21:04:04 +02:00
parent d1f2b6e25f
commit 014d2ab62c
2 changed files with 10 additions and 25 deletions

View file

@ -3,30 +3,17 @@
int main()
{
int second = 0;
static char *buf = NULL;
static size_t size = 0;
ssize_t len = 0;
for (long n=1; (len = getline(&buf, &size, stdin)) > 0; n++)
long n = 1;
while(getline(&buf, &size, stdin) > 0)
{
if (n < 5)
if (n++ < 5) /* overflow possible */
continue;
if (len && buf[len - 1] == '\n')
buf[len - 1] = '\0';
if (strncmp(buf,"-->", 3) == 0)
{
if (second)
{
second = 0;
}
else
{
putchar('\n');
second = 1;
}
}
else if (buf[0] != 0) /* Don't print newline at EOF */
puts(buf);
else if (buf[0] != 10)
fputs(buf, stdout);
}
return 0;
}

10
popup.c
View file

@ -62,7 +62,7 @@ int get_max_len(char *string, XftFont *font, int max_text_width)
eol--;
}
for (int i = 0; i < eol; i++)
for (int i = 0; i < MIN(eol+1, strlen(string)); i++)
if (string[i] == '\n')
{
string[i] = ' ';
@ -73,11 +73,9 @@ int get_max_len(char *string, XftFont *font, int max_text_width)
while (eol && (string[eol] & 0xC0) == 0x80)
--eol;
if (info.width <= max_text_width)
return eol;
/* prefer splitting at spaces */
/* uncomment to always split at spaces */
/* if (info.width <= max_text_width) */
/* return eol; */
/* int temp = eol; */
/* while (string[eol] != ' ' && eol) */
/* --eol; */