📄 mk_cpu.c
字号:
(void)fprintf (STDOUT," cnt is : %d", cnt);
}
if (cnt>0)
{
return (((int) c) & 0xff);
}
return ((int) XMK_EOF);
#elif defined(BORLAND_C) || defined(MICROSOFT_C)
if (! kbhit () ) return (XMK_EOF);
c = _getch ( );
if (XMK_IS_PRINTABLE_CHAR(c))
(void)fprintf (STDOUT, "%c", (char) c);
return (c);
#else
#ifdef XMK_ADD_PRINTF_CPU
XMK_TRACE_EXIT("xmk_GetChar");
#endif
return (XMK_FALSE);
#endif
}
#endif
#ifdef XMK_UNIX
/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
| Functionname : sig_catch |
+------------------------------------------------------------------------------+
| |
| Description : |
| A template to react on any UNIX process signal. This function represents |
| the signal handler, that is called by UNIX in the case if it was defined |
| correctly with the "signal()" C function. The initialization of all signals |
| and their handling is done within the xmk_TermInit () C function within this|
| module. |
| |
| Parameter : int signo - Signal's number |
| |
| Return : - |
| |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/
/*+FDEF E*/
#ifndef XNOPROTO
static void sig_catch(int signo)
#else
static void sig_catch(signo)
int signo;
#endif
/*-FDEF E*/
{
static int sema = 0;
int i = 6; /* Wati 6 seconds before exit */
XMK_SUPPRESS(SIGNO);
/*
** Only one signal is handled here
*/
if (sema) return;
sema = 1;
(void)fprintf(stderr, "**ERR:sdtmt:Using emergency exit due to system signal.\n");
while (i--)
{
(void)fprintf(stderr, ".");
(void)sleep (1);
}
xmk_exit(0);
}
#endif /* ... XMK_UNIX */
#ifdef XMK_USE_OS_ENVIRONMENT
/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
| Functionname : xmk_TermInit |
+------------------------------------------------------------------------------+
| |
| Description : |
| A template to initialize the user terminal. |
| |
| Parameter : - |
| |
| Return : - |
| |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/
/*+FDEF E*/
#ifndef XNOPROTO
int xmk_TermInit ( void )
#else
int xmk_TermInit ( )
#endif
/*-FDEF E*/
{
#ifdef XMK_ADD_PRINTF_CPU
XMK_FUNCTION("xmk_TermInit");
#endif
#ifdef XMK_UNIX
if (signal(SIGHUP, sig_catch) == SIG_ERR)
(void)fprintf(stderr, "Warning: Could not set signalhandler on UNIX signal SIGHUP (problem ignored).\n");
if (signal(SIGSEGV, sig_catch) == SIG_ERR)
(void)fprintf(stderr, "Warning: Could not set signalhandler on UNIX signal SIGSEGV (problem ignored).\n");
if (signal(SIGPIPE, sig_catch) == SIG_ERR)
(void)fprintf(stderr, "Warning: Could not set signalhandler on UNIX signal SIGPIPE (problem ignored).\n");
if (signal(SIGINT, sig_catch) == SIG_ERR)
(void)fprintf(stderr, "Warning: Could not set signalhandler on UNIX signal SIGINT (problem ignored).\n");
if (signal(SIGQUIT, sig_catch) == SIG_ERR)
(void)fprintf(stderr, "Warning: Could not set signalhandler on UNIX signal SIGQUIT (problem ignored).\n");
if (signal(SIGTERM, sig_catch) == SIG_ERR)
(void)fprintf(stderr, "Warning: Could not set signalhandler on UNIX signal SIGTERM (problem ignored).\n");
if (signal(SIGCLD, sig_catch) == SIG_ERR)
(void)fprintf(stderr, "Warning: Could not set signalhandler on UNIX signal SIGCLD (problem ignored).\n");
if (tcflush(STDIN_FILENO, TCIOFLUSH) == -1)
{
(void)fprintf(stderr, "Warning: Could not flush terminal (problem ignored).\n");
}
/*
** Read the current tty settings ...
*/
if (tcgetattr(STDIN_FILENO, &tty_buf) == -1)
{
(void)fprintf(stderr, "Warning: Could not get current terminal settings (problem ignored).\n");
}
/*
** Save the current tty settings
*/
(void)memcpy ((void*) &xmk_OldTTYSettings,
(void*) &tty_buf,
sizeof (xmk_OldTTYSettings));
/*
** Modify the current tty settings to canonical without echo ...
** (fgetc must return immediately when no key was pressed)
*/
tty_buf.c_lflag &= ~ICANON;
tty_buf.c_cc[VMIN] = 0;
tty_buf.c_cc[VTIME] = 0;
tty_buf.c_cc[VERASE] = 8;
#ifdef ECHOCTL_OFF
tty_buf.c_lflag &= ~ECHOCTL;
#endif
/*
** Write the new tty settings ...
*/
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tty_buf) == -1)
{
(void)fprintf(stderr, "Warning: Could not initialize terminal (problem ignored).\n");
}
#endif
#ifdef XMK_ADD_PRINTF_CPU
XMK_TRACE_EXIT("xmk_TermInit");
#endif
return (XMK_OKAY);
}
#endif
#ifdef XMK_USE_OS_ENVIRONMENT
/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
| Functionname : xmk_TermDeinit |
+------------------------------------------------------------------------------+
| |
| Description : |
| A template to initialize the user terminal. |
| |
| Parameter : - |
| |
| Return : - |
| |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/
/*+FDEF E*/
#ifndef XNOPROTO
int xmk_TermDeinit ( void )
#else
int xmk_TermDeinit ( )
#endif
/*-FDEF E*/
{
#ifdef XMK_ADD_PRINTF_CPU
XMK_FUNCTION("xmk_TermDeinit");
#endif
#ifdef XMK_UNIX
/*
** Restore the old terminal settings ...
*/
if (tcsetattr(STDIN_FILENO, TCSANOW, &xmk_OldTTYSettings) == -1)
{
(void)fprintf(stderr, "Warning: Could not reset terminal (problem ignored).\n");
}
#endif
#ifdef XMK_ADD_PRINTF_CPU
XMK_TRACE_EXIT("xmk_TermDeinit");
#endif
return (XMK_OKAY);
}
#endif
#ifdef XMK_ADD_STDIO
/*+FHDR E*/
/*
+------------------------------------------------------------------------------+
| Functionname : xmk_printf |
+------------------------------------------------------------------------------+
| |
| Description : |
| A template to print a string by using var args. |
| |
| This function is called from any place in the Cmicro Library, Cmicro Kernel |
| or generated C code, if the printf functionality is compiled with at least |
| one of the XMK_ADD_PRINTF* defines. |
| The function must return immediately, i.e.may not be blocking on the output |
| device. If the user does not care about this restriction, the correct |
| function of other program parts cannot be guaranteed. |
| The function can be used for ANSI C compilers only, because optional |
| argument lists are used like in the printf function of the standard C |
| library. |
| |
| Parameter : char* format Usual printf convention |
| ... var args |
| |
| Return : int without any meaning, because this is |
| is used to let declaration look like |
| declaration for printf. |
| |
+------------------------------------------------------------------------------+
*/
/*-FHDR E*/
/*+FDEF E*/
#ifndef XNOPROTO
int xmk_printf ( char* format, ... )
#else
#error "Sorry_No_Support_for_optional_Arguments_in_KR_Compilers"
#endif
/*-FDEF E*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -