home *** CD-ROM | disk | FTP | other *** search
- /*
- fntime.c
-
- % time_funcs
-
- Time editting functions.
- The field variable should be a struct tm *.
-
- C-scape 3.1
- Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 3/12/87 jdc created
- 4/06/88 jmd added call to sed_DoSpecial
- 5/12/88 jmd added calls to sed_GetScratchPad()
- 9/17/88 jmd added std_ funcs, errmsg
- 10/09/88 jmd added SED_ABORT support
- 10/14/88 jdc added var_size element to field_funcs_struct
- 12/22/88 jmd added SED_FIRST support
-
- 6/07/89 jmd added test for mouse code (later removed)
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
-
-
- #include "cscape.h"
- #include "ostdlib.h" /* for atoi() */
-
- #include "scancode.h"
-
- #include <time.h>
- #include "cstime.h"
-
- /* error message (global variable can be changed by programmer) */
- char *fntime_errmsg = "Invalid time";
-
- OGLOBAL field_funcs_struct time_funcs = {
- std_fenter,
- time_fexit,
- time_fkey,
- time_senter,
- time_sexit,
- sizeof(struct tm)
- };
-
- void time_fkey(sed)
- sed_type sed;
- {
- int scancode, key;
-
- scancode = kb_Read();
-
- if (sed_DoSpecial(sed, scancode))
- return;
- if (special_key(sed, scancode))
- return;
- if (inter_field(sed, scancode))
- return;
- if (inter_page(sed, scancode))
- return;
-
- switch(scancode) {
- case ESC:
- sed_SetBaton(sed, 0);
- sed_ToggleExit(sed);
- break;
- case RIGHT:
- sed_IncChar(sed);
- break;
- case LEFT:
- sed_DecChar(sed);
- break;
- case HOME:
- sed_GoHome(sed);
- break;
- case END:
- sed_GoEnd(sed);
- break;
- case INS:
- break;
- case BACKSPACE:
- sed_Overwrite(sed,'0');
- sed_DecChar(sed);
- break;
- case DEL:
- sed_Overwrite(sed,'0');
- break;
- default:
- key = ascii(scancode);
- if (isdigit(key)) {
- if (sed_GetBaton(sed) == SED_FIRST) {
- /* clear record on first keystroke */
- sed_SetCurrRecord(sed, "000000");
- sed_UpdateCurrField(sed);
- }
- sed_Overwrite(sed, key);
- sed_IncChar(sed);
- }
- break;
- }
-
- /* reset baton */
- sed_SetBaton(sed, -1);
- }
-
- boolean time_fexit(sed)
- sed_type sed;
- {
- if (sed_GetBaton(sed) != SED_ABORT) {
- time_sexit(sed, sed_GetFieldNo(sed));
-
- if (!tm_IsTimeValid((struct tm *) sed_GetCurrVar(sed))) {
- tone();
- sed_BorderPrompt(sed, fntime_errmsg);
- /* wait for a keystroke */
- while (!kb_Check())
- ;
- sed_BorderPrompt(sed, sed_GetCurrFieldData(sed, 0));
- return(FALSE);
- }
- }
-
- return(std_fexit(sed));
- }
-
- void time_senter(sed, fieldno)
- sed_type sed;
- int fieldno;
- /*
- Convert native type to string for record.
- */
- {
- struct tm *t;
-
- t = (struct tm *) sed_GetVar(sed,fieldno);
-
- sprintf(sed_GetScratchPad(sed), "%02d%02d%02d", (t->tm_hour),t->tm_min,(t->tm_sec));
-
- sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
-
- std_senter(sed, fieldno);
- }
-
- void time_sexit(sed, fieldno)
- sed_type sed;
- int fieldno;
- /*
- Converts record back to native type.
- */
- {
- char *buf;
- struct tm *t;
-
- if (sed_GetBaton(sed) != SED_ABORT) {
- t = (struct tm *) sed_GetVar(sed,fieldno);
-
- buf = sed_GetScratchPad(sed);
-
- strcpy(buf,sed_GetRecord(sed, fieldno));
-
- t->tm_sec = atoi(buf+4);
- *(buf+4) = '\0';
- t->tm_min = atoi(buf+2);
- *(buf+2) = '\0';
- t->tm_hour = atoi(buf);
- }
- }
-
-
-
-