📄 userio.c
字号:
#ifdef AMIGA char temp2[GPRINTF_MESSAGE_LEN];#endif /* AMIGA*/#endif /* DOTS_FOR_ARGS */ sprintf(temp1, format, args);#endif /* USE_VSPRINTF *//* * Now we've got formatted output in temp1. Write it out. */#ifdef NYQUIST switch ((long) where) { case TRANS: stdputstr(temp1); break; case ERROR: errputstr(temp1); break; case FATAL: errputstr("FATAL: "); errputstr(temp1); break; case GDEBUG: errputstr("DEBUG: "); errputstr(temp1); break; default: errputstr("UNKNOWN: "); errputstr(temp1); break; } gflush();#else /* not NYQUIST */#ifdef AMIGA switch((long) where) { case TRANS: strcpy(temp2, temp1); break; case ERROR: strcpy(temp2, temp1); break; case FATAL: strcpy(temp2, "FATAL: "); strcat(temp2, temp1); break; case GDEBUG: strcpy(temp2,"DEBUG: "); strcat(temp2, temp1); break; default: strcpy(temp2, "UNKNOWN: "); strcat(temp2, temp1); break; } ConOutReq->io_Command = CMD_WRITE; ConOutReq->io_Data = (APTR)temp2; ConOutReq->io_Length = -1; /* NULL terminated string */ DoIO((struct IORequest *) ConOutReq); #else /* not NYQUIST or AMIGA */ switch(where) { case TRANS: printf("%s", temp1); break; case ERROR: fprintf(stderr, "%s", temp1); break; case GDEBUG: fprintf(stderr, "DEBUG %s", temp1); break; case FATAL: fprintf(stderr, "FATAL %s", temp1); break; default: fprintf(stderr, "UNKNOWN %s", temp1); break; }#endif /* AMIGA */#endif /* NYQUIST */}#endif /* ifndef gprintf *//*************************************************************************** gputchar* General putchar**************************************************************************/#ifndef gputchar#ifdef AMIGApublic int gputchar(c)int c;{ ConPutChar((char)c); return(c);}#elsepublic int gputchar(c)int c;{ putchar((char)c); return(c);}#endif#endif /* ifndef gputchar *//*************************************************************************** ggetchar* General getchar**************************************************************************/public int ggetchar(){#ifdef BUFFERED_SYNCHRONOUS_INPUT return getchar();#else key = wait_ascii(); if (key != ABORT_CHAR && key != '\b') gputchar((char)key); return(key);#endif}/*************************************************************************** ggets* General gets**************************************************************************/#ifndef ggetspublic char *ggets(str) char *str;{ char *s = str; int c; do { c = ggetchar(); if (c == '\b' /* backspace */) { if (s != str) { gputchar('\b'); gputchar((int)' '); gputchar('\b'); s--; } else {#ifdef AMIGA gputchar((int)0x9b); gputchar((int)0x43);#else /* gputchar((int)' '); */#endif gputchar((int)0x07); } } else *s++ = (char) c; } while (c != (int) '\n' && !abort_flag); *(s-1) = EOS; if (abort_flag) *str = EOS; return str;}#endif /* ifndef ggets *//***************************************************************************** get_ascii* Returns:* boolean: TRUE if a character was found* int * c: pointer to int into which to store the character, if any* Effect:* polls (doesn't wait) for an ascii character and says if it got one* the character is returned in *c.****************************************************************************/public boolean get_ascii(c) char *c;{ check_aborted(); /* input buffer check */ if (type_ahead_count == 0) return FALSE;#ifdef AMIGA /* if the buffer is full, then there is no outstanding read, restart it: */ if (type_ahead_count == type_ahead_max) ConRead();#endif type_ahead_count--; *c = type_ahead[type_ahead_head++]; if (type_ahead_head == type_ahead_max) type_ahead_head = 0; return TRUE;}#ifdef MACINTOSH /** Macintosh direct ascii input**/public boolean ascii_input(c)char *c;{ EventRecord theEvent; (void) GetNextEvent((keyDownMask | autoKeyMask), &theEvent); if ((theEvent.what == keyDown) || (theEvent.what == autoKey)) { *c = theEvent.message & charCodeMask; if (*c == '\r') *c = '\n'; return(true); } else { return(false); }}#endif#ifdef WINDOWS#include "conio.h"#define kbhit _kbhit#define getch _getch#endif#ifdef DOSpublic boolean ascii_input(c)char *c;{ if (abort_flag == ABORT_LEVEL) { *c=ABORT_CHAR; return((boolean)TRUE); } if (kbhit()) { /* If the keyboard was hit */ *c = getch(); /* Don't echo it */// printf("now break"); if (*c == '\r') *c = '\n'; return((boolean)TRUE); } return((boolean)FALSE); /* Keeps Lattice compiler happy */}#endif#ifdef UNIXpublic boolean ascii_input(c)char *c;{#ifdef UNIX_MACH /* * we can't read from stdin directly, because the ascii * input thread is already doing so, so instead we'll * wait for that thread to read a character and then take * it */ boolean ret = FALSE; A_LOCK(); if (a_in_flag) { (*c) = a_in; a_in_flag = 0; ret = TRUE; } A_UNLOCK(); if (ret) {#ifdef RTMach itc_condition_signal(&a_cond);#else /* RTMach */ condition_signal(&a_cond);#endif /* RTMach */ } if ((*c) == '\r') (*c) = '\n'; return(ret);#else /* UNIX_MACH */#ifndef BUFFERED_SYNCHRONOUS_INPUT int input = IOgetchar(); if (input != IOnochar) { *c = input; if (*c == '\r') *c = '\n'; return TRUE; }#endif /* BUFFERED_SYNCHRONOUS_INPUT */ return FALSE;#endif /* UNIX_MACH */}#endif#ifndef AMIGA /*DOS and MAC and UNIX */public void unget_ascii(char c){ if (type_ahead_head == 0) type_ahead_head = type_ahead_max; type_ahead_head--; type_ahead[type_ahead_head] = c; type_ahead_count++;}public boolean check_ascii(){ char c; if(get_ascii(&c)) { unget_ascii(c); return TRUE; } else return FALSE;}#endif/***************************************************************************** wait_ascii* Returns:* int: character for key pressed* Effect:* waits for the user to type a key on the terminal keyboard* (versus the synthesizer keyboard) and returns the key typed****************************************************************************/#ifdef MACINTOSHpublic int wait_ascii(){ char key ; /* key typed */ if (abort_flag == ABORT_LEVEL) return ABORT_CHAR; if (abort_flag == BREAK_LEVEL) return BREAK_CHAR; gflush(); while (!get_ascii(&key)) ; return(key); }#endif#ifdef DOSpublic int wait_ascii(){ char key ; /* key typed */ if (abort_flag == ABORT_LEVEL) return ABORT_CHAR; if (abort_flag == BREAK_LEVEL) return BREAK_CHAR; while(!get_ascii(&key)); /* GWL - check for abort on previos line */ return (int)key; }#endif#ifndef MACINTOSH#ifndef DOSpublic int wait_ascii(){#ifdef UNIX /* was defined (UNIX) || defined(ITC) */#ifndef UNIX_MACH fd_set readfds;#endif /* !UNIX_MACH */#endif char c; if (abort_flag == ABORT_LEVEL) return ABORT_CHAR; if (abort_flag == BREAK_LEVEL) return BREAK_CHAR; while (!get_ascii(&c)) {#ifdef AMIGA WaitPort(ConInPort);#endif#ifdef UNIX fflush(stdout);#ifdef UNIX_MACH /* * we can't select, since another thread is reading * from stdin, and we don't want to have an input war * so instead, the ascii input thread will signal * a_in_cond when it gets input, so we just wait * for that to happen */ A_LOCK();#ifdef RTMach itc_condition_wait(&a_in_cond, &a_mutex);#else /* RTMach */ condition_wait(&a_in_cond, &a_mutex);#endif /* RTMach */ A_UNLOCK();#else /* UNIX_MACH */ FD_ZERO(&readfds); FD_SET(IOinputfd, &readfds); gflush(); select(NOFILE+1, &readfds, 0, 0, NULL);#endif /* !UNIX_MACH */#endif /* ifdef UNIX */ } return (int) c;}#endif#endif#ifdef AMIGA/****************************************************************** AMIGA 2000. Console IO Functions JCD 25-Apr-88*******************************************************************/UBYTE KeybSig(){ return ConInPort->mp_SigBit;}private void ConPutChar(c)char c;{ ConOutReq->io_Command = CMD_WRITE; ConOutReq->io_Data = (APTR)&c; ConOutReq->io_Length = 1; DoIO((struct IORequest *) ConOutReq);}private void ConPutStr(str)char *str;{ ConOutReq->io_Command = CMD_WRITE; ConOutReq->io_Data = (APTR)str; ConOutReq->io_Length = -1; DoIO((struct IORequest *) ConOutReq);}private void ConRead(){ ConInReq->io_Command = CMD_READ; ConInReq->io_Data = (APTR)KeyBuff; ConInReq->io_Length = 1; SendIO((struct IORequest *) ConInReq);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -