Example #1
0
File: stuff.c Project: ptt/pttbbs
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;
}
Example #2
0
static void
a_newtitle(const menu_t * pm)
{
    char            buf[PATHLEN];
    fileheader_t    item, *fhdr;

    fhdr = &pm->header[pm->now - pm->page];
    memcpy(&item, fhdr, FHSZ);
    strlcpy(buf, item.title + 3, sizeof(buf));
    if (getdata_buf(b_lines - 1, 0, "   新標題: ", buf, 60, DOECHO)) {
	strlcpy(item.title + 3, buf, sizeof(item.title) - 3);
	setadir(buf, pm->path);
        if (substitute_fileheader(buf, fhdr, &item, pm->now + 1) != 0)
            vmsg("無法變更名稱,可能目錄有其它板主正在修改。請退出本層目錄後再重試。");
    }
}
Example #3
0
static void
a_editsign(const menu_t * pm)
{
    char            buf[PATHLEN];
    fileheader_t    item;

    memcpy(&item, &pm->header[pm->now - pm->page], FHSZ);
    snprintf(buf, sizeof(buf), "%c%c", item.title[0], item.title[1]);
    if (getdata_buf(b_lines - 1, 1, "符號", buf, 3, DOECHO)) {
	item.title[0] = buf[0] ? buf[0] : ' ';
	item.title[1] = buf[1] ? buf[1] : ' ';
	item.title[2] = ' ';
	setadir(buf, pm->path);
        if (substitute_fileheader(buf, &item, &item, pm->now + 1) != 0) {
            vmsg("無法變更,可能目錄有其它板主正在修改。請退出本層目錄後再重試。");
        }
    }
}
Example #4
0
File: stuff.c Project: ptt/pttbbs
// TODO
// move this function to vtuikit.c
int
search_num(int ch, int max)
{
    int  clen = 1, y = b_lines - msg_occupied;
    char genbuf[10];

    genbuf[0] = ch; genbuf[1] = 0;
    clen = getdata_buf(y, 0,
	    " 跳至第幾項: ", genbuf, sizeof(genbuf)-1, NUMECHO);

    move(y, 0); clrtoeol();
    genbuf[clen] = '\0';
    if (genbuf[0] == '\0')
	return -1;
    clen = atoi(genbuf);
    if (clen == 0)
	return 0;
    if (clen > max)
	return max;
    return clen - 1;
}