The biggest change is the return type of substitute(). Before, 0 meant
success, now false means failure.
No functional change.
#include <ctype.h>
#include <curses.h>
#include <err.h>
#include <ctype.h>
#include <curses.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
readquote(void)
{
FILE *f = popen(_PATH_FORTUNE, "r");
readquote(void)
{
FILE *f = popen(_PATH_FORTUNE, "r");
err(1, "%s", _PATH_FORTUNE);
}
char buf[128], buf2[8 * sizeof(buf)];
err(1, "%s", _PATH_FORTUNE);
}
char buf[128], buf2[8 * sizeof(buf)];
- while (fgets(buf, sizeof(buf), f)) {
+ while (fgets(buf, sizeof buf, f) != NULL) {
char *s = strrchr(buf, '\n');
char *s = strrchr(buf, '\n');
- for (i = j = 0; buf[i]; i++) {
+ for (i = j = 0; buf[i] != '\0'; i++) {
if (buf[i] == '\t') {
buf2[j++] = ' ';
if (buf[i] == '\t') {
buf2[j++] = ' ';
buf2[j++] = ' ';
} else if (buf[i] == '\b') {
if (j > 0)
buf2[j++] = ' ';
} else if (buf[i] == '\b') {
if (j > 0)
stringarray_add(&lines, buf2);
stringarray_add(&sollines, buf2);
stringarray_add(&lines, buf2);
stringarray_add(&sollines, buf2);
}
for (int y = 0; y < lines.num; y++) {
}
for (int y = 0; y < lines.num; y++) {
- for (unsigned x = 0; lines.v[y][x]; x++) {
+ for (unsigned x = 0; lines.v[y][x] != '\0'; x++) {
if (islower((unsigned char)lines.v[y][x])) {
int q = lines.v[y][x] - 'a';
lines.v[y][x] = 'a' + key[q];
if (islower((unsigned char)lines.v[y][x])) {
int q = lines.v[y][x] - 'a';
lines.v[y][x] = 'a' + key[q];
substitute(int ch)
{
assert(cury >= 0 && cury < lines.num);
if (curx >= strlen(lines.v[cury])) {
beep();
substitute(int ch)
{
assert(cury >= 0 && cury < lines.num);
if (curx >= strlen(lines.v[cury])) {
beep();
}
int och = lines.v[cury][curx];
if (!isalpha((unsigned char)och)) {
beep();
}
int och = lines.v[cury][curx];
if (!isalpha((unsigned char)och)) {
beep();
}
int loch = tolower((unsigned char)och);
}
int loch = tolower((unsigned char)och);
int uch = toupper((unsigned char)ch);
for (int y = 0; y < lines.num; y++) {
int uch = toupper((unsigned char)ch);
for (int y = 0; y < lines.num; y++) {
- for (unsigned x = 0; lines.v[y][x]; x++) {
+ for (unsigned x = 0; lines.v[y][x] != '\0'; x++) {
if (lines.v[y][x] == loch) {
lines.v[y][x] = lch;
} else if (lines.v[y][x] == uoch) {
if (lines.v[y][x] == loch) {
lines.v[y][x] = lch;
} else if (lines.v[y][x] == uoch) {
}
////////////////////////////////////////////////////////////
}
////////////////////////////////////////////////////////////
move(i, 0);
int ln = i + scrolldown;
if (ln < lines.num) {
move(i, 0);
int ln = i + scrolldown;
if (ln < lines.num) {
- for (unsigned j = 0; lines.v[i][j]; j++) {
+ for (unsigned j = 0; lines.v[i][j] != '\0'; j++) {
int ch = lines.v[i][j];
if (ch != sollines.v[i][j] &&
isalpha((unsigned char)ch)) {
int ch = lines.v[i][j];
if (ch != sollines.v[i][j] &&
isalpha((unsigned char)ch)) {
break;
default:
if (isalpha(ch)) {
break;
default:
if (isalpha(ch)) {
if (curx < strlen(lines.v[cury])) {
curx++;
}
if (curx < strlen(lines.v[cury])) {
curx++;
}