int getdata(int line, int col, const char *prompt, char *buf, int len, int echo) { move(line, col); SOLVE_ANSI_CACHE(); if(prompt && *prompt) outs(prompt); return vgets(buf, len, getdata2vgetflag(echo)); }
time4_t gettime(int line, time4_t dt, const char* head) { char yn[7]; struct tm ptime, endtime; time_t t; char prompt[STRLEN*2]; localtime4_r(&dt, &ptime); endtime = ptime; snprintf(yn, sizeof(yn), "%4d", ptime.tm_year + 1900); move(line, 0); SOLVE_ANSI_CACHE(); clrtoeol(); snprintf(prompt, sizeof(prompt), "%s 西元年:", head); do { getdata_buf(line, 0, prompt, yn, 5, NUMECHO); // signed: limited on (2037, ...) // unsigned: limited on (..., 1970) // let's restrict inside the boundary. } while ((endtime.tm_year = atoi(yn) - 1900) < 70 || endtime.tm_year > 135); strlcat(prompt, yn, sizeof(prompt)); strlcat(prompt, " 月:", sizeof(prompt)); snprintf(yn, sizeof(yn), "%d", ptime.tm_mon + 1); do { getdata_buf(line, 0, prompt, yn, 3, NUMECHO); } while ((endtime.tm_mon = atoi(yn) - 1) < 0 || endtime.tm_mon > 11); strlcat(prompt, yn, sizeof(prompt)); strlcat(prompt, " 日:", sizeof(prompt)); snprintf(yn, sizeof(yn), "%d", ptime.tm_mday); do { getdata_buf(line, 0, prompt, yn, 3, NUMECHO); } while ((endtime.tm_mday = atoi(yn)) < 1 || endtime.tm_mday > 31); snprintf(yn, sizeof(yn), "%d", ptime.tm_hour); strlcat(prompt, yn, sizeof(prompt)); strlcat(prompt, " 時(0-23):", sizeof(prompt)); do { getdata_buf(line, 0, prompt, yn, 3, NUMECHO); } while ((endtime.tm_hour = atoi(yn)) < 0 || endtime.tm_hour > 23); strlcat(prompt, yn, sizeof(prompt)); strlcat(prompt, " 分(0-59):", sizeof(prompt)); snprintf(yn, sizeof(yn), "%d", ptime.tm_min); do { getdata_buf(line, 0, prompt, yn, 3, NUMECHO); } while ((endtime.tm_min = atoi(yn)) < 0 || endtime.tm_min > 59); t = mktime(&endtime); /* saturation check */ if(t < 0) t = 1; if(t > INT_MAX) t = INT_MAX; return t; }
CCW_PROTO void ccw_footer(CCW_CTX *ctx) { move(b_lines, 0); SOLVE_ANSI_CACHE(); clrtoeol(); if (ctx->footer) { ctx->footer(ctx); return; } vs_footer(" CCW ", " (PgUp/PgDn)回顧訊息記錄\t(Ctrl-C)離開 "); }
CCW_PROTO void ccw_prompt(CCW_CTX *ctx) { move(b_lines-1, 0); SOLVE_ANSI_CACHE(); clrtoeol(); if (ctx->prompt) { ctx->prompt(ctx); return; } prints("%s: ", ctx->local_id); }
// default callback handlers CCW_PROTO void ccw_header(CCW_CTX *ctx) { move(0, 0); SOLVE_ANSI_CACHE(); clrtoeol(); if (ctx->header) { ctx->header(ctx); return; } outs("Common Chat Window"); }