# HG changeset patch # User Matti Hamalainen # Date 1290287610 -7200 # Node ID c40329e954457eb6407c264a40525d4e371c6ca3 # Parent 4554f9abc6864074c7dd3dcfbd23f7df01185513 Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts. diff -r 4554f9abc686 -r c40329e95445 nnchat.c --- a/nnchat.c Sat Nov 20 23:12:04 2010 +0200 +++ b/nnchat.c Sat Nov 20 23:13:30 2010 +0200 @@ -879,19 +879,21 @@ return FALSE; } -char *promptRequester(const char *info) +char *promptRequester(const char *info, BOOL allowEmpty) { - char tmpBuf[512]; - ssize_t bufLen; + char tmpBuf[512], *ptr; + ssize_t pos; fputs(info, stdout); fgets(tmpBuf, sizeof(tmpBuf), stdin); - for (bufLen = strlen(tmpBuf) - 1; bufLen > 0 && (tmpBuf[bufLen] == '\n' || tmpBuf[bufLen] == '\r' || th_isspace(tmpBuf[bufLen])); bufLen--) - tmpBuf[bufLen] = 0; + for (pos = strlen(tmpBuf) - 1; pos > 0 && (tmpBuf[pos] == '\n' || tmpBuf[pos] == '\r' || th_isspace(tmpBuf[pos])); pos--) + tmpBuf[pos] = 0; - if (bufLen > 0) - return th_strdup(tmpBuf); + ptr = trimLeft(tmpBuf); + + if (allowEmpty || strlen(ptr) > 0) + return th_strdup(ptr); else return NULL; } @@ -984,8 +986,8 @@ /* Check if we have username and password */ if (optUserName == NULL || optPassword == NULL) { printf("\nYou can avoid this prompt by issuing '/save' after logging in.\n\n"); - optUserName = promptRequester("NN username: "); - optPassword = promptRequester("NN password: "); + optUserName = promptRequester("NN username: ", FALSE); + optPassword = promptRequester("NN password: ", TRUE); if (optUserName == NULL || optPassword == NULL) { THERR("User/pass not specified, get some --help\n"); return -1;