Replace some declaration; while loops with for loops

I should have been using this for getopt loops already but the call here
is slightly too long to fit on one line as a for loop.
weechat-hashes
C. McEnroe 2020-03-30 19:44:45 -04:00
parent a0dde10cb6
commit ff78362826
3 changed files with 6 additions and 12 deletions

9
chat.c
View File

@ -88,8 +88,7 @@ static void execRead(void) {
if (len < 0) err(EX_IOERR, "read"); if (len < 0) err(EX_IOERR, "read");
if (!len) return; if (!len) return;
buf[len] = '\0'; buf[len] = '\0';
char *ptr = buf; for (char *ptr = buf; ptr;) {
while (ptr) {
char *line = strsep(&ptr, "\n"); char *line = strsep(&ptr, "\n");
if (line[0]) command(execID, line); if (line[0]) command(execID, line);
} }
@ -101,8 +100,7 @@ static void utilRead(void) {
if (len < 0) err(EX_IOERR, "read"); if (len < 0) err(EX_IOERR, "read");
if (!len) return; if (!len) return;
buf[len] = '\0'; buf[len] = '\0';
char *ptr = buf; for (char *ptr = buf; ptr;) {
while (ptr) {
char *line = strsep(&ptr, "\n"); char *line = strsep(&ptr, "\n");
if (line[0]) uiFormat(Network, Warm, NULL, "%s", line); if (line[0]) uiFormat(Network, Warm, NULL, "%s", line);
} }
@ -287,8 +285,7 @@ int main(int argc, char *argv[]) {
if (signals[SIGCHLD]) { if (signals[SIGCHLD]) {
signals[SIGCHLD] = 0; signals[SIGCHLD] = 0;
int status; for (int status; 0 < waitpid(-1, &status, WNOHANG);) {
while (0 < waitpid(-1, &status, WNOHANG)) {
if (WIFEXITED(status) && WEXITSTATUS(status)) { if (WIFEXITED(status) && WEXITSTATUS(status)) {
uiFormat( uiFormat(
Network, Warm, NULL, Network, Warm, NULL,

View File

@ -383,8 +383,7 @@ static void handleNick(struct Message *msg) {
set(&self.nick, msg->params[0]); set(&self.nick, msg->params[0]);
uiRead(); // Update prompt. uiRead(); // Update prompt.
} }
uint id; for (uint id; (id = completeID(msg->nick));) {
while (None != (id = completeID(msg->nick))) {
if (!strcmp(idNames[id], msg->nick)) { if (!strcmp(idNames[id], msg->nick)) {
set(&idNames[id], msg->params[0]); set(&idNames[id], msg->params[0]);
} }
@ -404,8 +403,7 @@ static void handleNick(struct Message *msg) {
static void handleQuit(struct Message *msg) { static void handleQuit(struct Message *msg) {
require(msg, true, 0); require(msg, true, 0);
uint id; for (uint id; (id = completeID(msg->nick));) {
while (None != (id = completeID(msg->nick))) {
urlScan(id, msg->nick, msg->params[0]); urlScan(id, msg->nick, msg->params[0]);
uiFormat( uiFormat(
id, Cold, tagTime(msg), id, Cold, tagTime(msg),

3
ui.c
View File

@ -945,10 +945,9 @@ void uiRead(void) {
} }
} }
int ret;
wint_t ch; wint_t ch;
static bool paste, style; static bool paste, style;
while (ERR != (ret = wget_wch(input, &ch))) { for (int ret; ERR != (ret = wget_wch(input, &ch));) {
if (ret == KEY_CODE_YES && ch == KeyPasteOn) { if (ret == KEY_CODE_YES && ch == KeyPasteOn) {
paste = true; paste = true;
} else if (ret == KEY_CODE_YES && ch == KeyPasteOff) { } else if (ret == KEY_CODE_YES && ch == KeyPasteOff) {