# HG changeset patch # User Matti Hamalainen # Date 1289963592 -7200 # Node ID edd5ce3e5399d14e848d9a1913514ea91bd79ba1 # Parent 829457be9eea07553f32acba877d52faad231803 Add simplistic username/password requester if none given on commandline or config file. diff -r 829457be9eea -r edd5ce3e5399 nnchat.c --- a/nnchat.c Wed Nov 17 04:09:41 2010 +0200 +++ b/nnchat.c Wed Nov 17 05:13:12 2010 +0200 @@ -869,6 +869,22 @@ return FALSE; } +char *promptRequester(const char *info) +{ + char tmpBuf[512]; + ssize_t bufLen; + + 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; + + if (bufLen > 0) + return th_strdup(tmpBuf); + else + return NULL; +} int main(int argc, char *argv[]) { @@ -939,7 +955,7 @@ if ((cfgfile = fopen(setConfigFile, "r")) != NULL) th_cfg_read(cfgfile, setConfigFile, cfg); } - + setBrowser = getenv("BROWSER"); if (setBrowser == NULL) setBrowser = "firefox"; @@ -950,8 +966,13 @@ /* Check if we have username and password */ if (optUserName == NULL || optPassword == NULL) { - THERR("User/pass not specified, get some --help\n"); - return -1; + printf("\nYou can avoid this prompt by issuing '/save' after logging in.\n\n"); + optUserName = promptRequester("NN username: "); + optPassword = promptRequester("NN password: "); + if (optUserName == NULL || optPassword == NULL) { + THERR("User/pass not specified, get some --help\n"); + return -1; + } } if (!argsOK)