コード例 #1
0
int
MyPutS(const char *str)
{
    PUTS(str);
    PUTCH('\n');
    TEXTMESSAGE;
    return 0;
}
コード例 #2
0
ファイル: token.c プロジェクト: enukane/netbsd-src
static int
eatcmnt(void)
{
	int ch;

	if (Cflag) { PUTCH('/'); PUTCH('*'); }
	for (;;) {
		ch = inch();
		if (ch == '\n') {
			ifiles->lineno++;
			PUTCH('\n');
		}
		if (ch == -1)
			return -1;
		if (ch == '*') {
			ch = inch();
			if (ch == '/') {
				if (Cflag) {
					PUTCH('*');
					PUTCH('/');
				} else
					PUTCH(' ');
				break;
			}
			unch(ch);
			ch = '*';
		}
		if (Cflag) PUTCH(ch);
	}
	return 0;
}
コード例 #3
0
int
MyFPutC(int ch, FILE *file)
{
    if (isterm(file)) {
	PUTCH(ch);
	TEXTMESSAGE;
	return ch;
    }
    return fputc(ch,file);
}
コード例 #4
0
size_t
MyFWrite(const void *ptr, size_t size, size_t n, FILE *file)
{
    if (isterm(file)) {
	size_t i;
	for (i = 0; i < n; i++)
	    PUTCH(((BYTE *)ptr)[i]);
	TEXTMESSAGE;
	return n;
    }
    return fwrite(ptr, size, n, file);
}
コード例 #5
0
ファイル: token.c プロジェクト: Sciumo/pcc
static void
eatcmnt(void)
{
	int ch;

	if (Cflag) { PUTCH('/'); PUTCH('*'); }
	for (;;) {
		ch = inch();
		if (ch == '\n') {
			ifiles->lineno++;
			putch('\n');
			continue;
		}
		if (ch == -1)
			break;
		if (ch == '*') {
			ch = inch();
			if (ch == '/') {
				if (Cflag) {
					PUTCH('*');
					PUTCH('/');
				} else
					PUTCH(' ');
				break;
			}
			unch(ch);
			ch = '*';
		}
		if (Cflag) PUTCH(ch);
	}
}
コード例 #6
0
ファイル: tty_io.c プロジェクト: wanlizhi/lantern
/**
 * for console, channel = 0. 指定的是使用哪个tty_table来输出,0指定的是控制台
 
 nr=0 number of bytes ,指定buf有多少个字节。
*/
int tty_write(unsigned channel, char * buf, int nr)
{
	static int cr_flag=0;
	struct tty_struct * tty;
	char c, *b=buf;

	if (channel>2 || nr<0) return -1;
	tty = channel + tty_table; /*使用控制台输出*/
	
	/**/
	while (nr>0) {
		sleep_if_full(&tty->write_q);
		/*if (current->signal)
			break;
		*/
		while (nr>0 && !FULL(tty->write_q)) {
			c=get_fs_byte(b);
			if (O_POST(tty)) {
				if (c=='\r' && O_CRNL(tty))
					c='\n';
				else if (c=='\n' && O_NLRET(tty))
					c='\r';
				if (c=='\n' && !cr_flag && O_NLCR(tty)) {
					cr_flag = 1;
					PUTCH(13,tty->write_q);
					continue;
				}
				if (O_LCUC(tty))
					c=toupper(c);
			}
			b++; nr--;
			cr_flag = 0;
			PUTCH(c,tty->write_q);
		}
		tty->write(tty);
		if (nr>0)
			/*schedule()*/;
	}
	return (b-buf);
}
コード例 #7
0
void copy_to_cooked(struct tty_struct * tty)
{
	signed char c;

	while (!EMPTY(tty->read_q) && !FULL(tty->secondary)) {
		GETCH(tty->read_q,c);
		if (c==13)
			if (I_CRNL(tty))
				c=10;
			else if (I_NOCR(tty))
				continue;
			else ;
		else if (c==10 && I_NLCR(tty))
			c=13;
		if (I_UCLC(tty))
			c=tolower(c);
		if (L_CANON(tty)) {
			if (c==ERASE_CHAR(tty)) {
				if (EMPTY(tty->secondary) ||
				   (c=LAST(tty->secondary))==10 ||
				   c==EOF_CHAR(tty))
					continue;
				if (L_ECHO(tty)) {
					if (c<32)
						PUTCH(127,tty->write_q);
					PUTCH(127,tty->write_q);
					tty->write(tty);
				}
				DEC(tty->secondary.head);
				continue;
			}
			if (c==STOP_CHAR(tty)) {
				tty->stopped=1;
				continue;
			}
			if (c==START_CHAR(tty)) {
				tty->stopped=0;
				continue;
			}
		}
		if (!L_ISIG(tty)) {
			if (c==INTR_CHAR(tty)) {
				tty_intr(tty,SIGINT);
				continue;
			}
		}
		if (c==10 || c==EOF_CHAR(tty))
			tty->secondary.data++;
		if (L_ECHO(tty)) {
			if (c==10) {
				PUTCH(10,tty->write_q);
				PUTCH(13,tty->write_q);
			} else if (c<32) {
				if (L_ECHOCTL(tty)) {
					PUTCH('^',tty->write_q);
					PUTCH(c+64,tty->write_q);
				}
			} else
				PUTCH(c,tty->write_q);
			tty->write(tty);
		}
		PUTCH(c,tty->secondary);
	}
	wake_up(&tty->secondary.proc_list);
}
コード例 #8
0
ファイル: token.c プロジェクト: Sciumo/pcc
/*
 * Scan quickly the input file searching for:
 *	- '#' directives
 *	- keywords (if not flslvl)
 *	- comments
 *
 *	Handle strings, numbers and trigraphs with care.
 *	Only data from pp files are scanned here, never any rescans.
 *	TODO: Only print out strings before calling other functions.
 */
static void
fastscan(void)
{
	struct symtab *nl;
	int ch, i;
	usch *cp;

	goto run;
	for (;;) {
		ch = inch();
xloop:		if (ch == -1)
			return;
#ifdef PCC_DEBUG
		if (dflag>1)
			printf("fastscan ch %d (%c)\n", ch, ch > 31 ? ch : '@');
#endif
		if ((spechr[ch] & C_SPEC) == 0) {
			PUTCH(ch);
			continue;
		}
		switch (ch) {
		case EBLOCK:
		case WARN:
		case CONC:
			error("bad char passed");
			break;

		case '/': /* Comments */
			if ((ch = inch()) == '/') {
cppcmt:				if (Cflag) { PUTCH(ch); } else { PUTCH(' '); }
				do {
					if (Cflag) PUTCH(ch);
					ch = inch();
				} while (ch != -1 && ch != '\n');
				goto xloop;
			} else if (ch == '*') {
				eatcmnt();
			} else {
				PUTCH('/');
				goto xloop;
			}
			break;

		case '\n': /* newlines, for pp directives */
			i = ifiles->escln + 1;
			ifiles->lineno += i;
			ifiles->escln = 0;
			while (i-- > 0)
				putch('\n');
run:			for(;;) {
				ch = inch();
				if (ch == '/') {
					ch = inch();
					if (ch == '/')
						goto cppcmt;
					if (ch == '*') {
						eatcmnt();
						continue;
					}
					unch(ch);
					ch = '/';
				}
				if (ch != ' ' && ch != '\t')
					break;
				PUTCH(ch);
			}
			if (ch == '#') {
				ppdir();
				continue;
			} else if (ch == '%') {
				ch = inch();
				if (ch == ':') {
					ppdir();
					continue;
				}
				unch(ch);
				ch = '%';
			}
			goto xloop;

		case '\"': /* strings */
str:			PUTCH(ch);
			while ((ch = inch()) != '\"') {
				if (ch == '\\') {
					PUTCH('\\');
					ch = inch();
				}
				if (ch == '\n') {
					warning("unterminated string literal");
					goto xloop;
				}
				if (ch == -1)
					return;
				PUTCH(ch);
			}
			PUTCH(ch);
			break;

		case '.':  /* for pp-number */
			PUTCH(ch);
			ch = inch();
			if (ch < '0' || ch > '9')
				goto xloop;

			/* FALLTHROUGH */
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			do {
nxp:				PUTCH(ch);
				ch = inch();
				if (ch == -1)
					return;
				if (spechr[ch] & C_EP) {
					PUTCH(ch);
					ch = inch();
					if (ch == '-' || ch == '+')
						goto nxp;
					if (ch == -1)
						return;
				}
			} while ((spechr[ch] & C_ID) || (ch == '.'));
			goto xloop;

		case '\'': /* character constant */
con:			PUTCH(ch);
			if (tflag)
				break; /* character constants ignored */
			while ((ch = inch()) != '\'') {
				if (ch == '\\') {
					PUTCH('\\');
					ch = inch();
				}
				if (ch == '\n') {
					warning("unterminated character constant");
					goto xloop;
				}
				if (ch == -1)
					return;
				PUTCH(ch);
			}
			PUTCH(ch);
			break;

		case 'L':
			ch = inch();
			if (ch == '\"') {
				PUTCH('L');
				goto str;
			}
			if (ch == '\'') {
				PUTCH('L');
				goto con;
			}
			unch(ch);
			ch = 'L';

			/* FALLTHROUGH */
		default:
#ifdef PCC_DEBUG
			if ((spechr[ch] & C_ID) == 0)
				error("fastscan");
#endif
			i = 0;
			do {
				yytext[i++] = (usch)ch;
				ch = inch();
			} while (ch != -1 && (spechr[ch] & C_ID));

			if (flslvl)
				goto xloop;

			yytext[i] = 0;
			unch(ch);

			cp = stringbuf;
			if ((nl = lookup(yytext, FIND)) && kfind(nl)) {
				putstr(stringbuf);
			} else
				putstr(yytext);
			stringbuf = cp;

			break;
		}
	}
}
コード例 #9
0
ファイル: token.c プロジェクト: pauley/pcc
/*
 * Scan quickly the input file searching for:
 *	- '#' directives
 *	- keywords (if not flslvl)
 *	- comments
 *
 *	Handle strings, numbers and trigraphs with care.
 *	Only data from pp files are scanned here, never any rescans.
 *	TODO: Only print out strings before calling other functions.
 */
static void
fastscan(void)
{
	struct symtab *nl;
	int ch, i;

	goto run;
	for (;;) {
		ch = NXTCH();
xloop:		if (ch == -1)
			return;
		if ((spechr[ch] & C_SPEC) == 0) {
			PUTCH(ch);
			continue;
		}
		switch (ch) {
		case '/': /* Comments */
			if ((ch = inch()) == '/') {
				if (Cflag) { PUTCH(ch); } else { PUTCH(' '); }
				do {
					if (Cflag) PUTCH(ch);
					ch = inch();
				} while (ch != -1 && ch != '\n');
				goto xloop;
			} else if (ch == '*') {
				if (Cflag) { PUTCH('/'); PUTCH('*'); }
				for (;;) {
					ch = inch();
					if (ch == '\n') {
						ifiles->lineno++;
						PUTCH('\n');
					}
					if (ch == -1)
						return;
					if (ch == '*') {
						ch = inch();
						if (ch == '/') {
							if (Cflag) {
								PUTCH('*');
								PUTCH('/');
							} else
								PUTCH(' ');
							break;
						}
						unch(ch);
						ch = '*';
					}
					if (Cflag) PUTCH(ch);
				}
			} else {
				PUTCH('/');
				goto xloop;
			}
			break;

		case '?':  /* trigraphs */
			if ((ch = chktg()))
				goto xloop;
			PUTCH('?');
			break;

		case '\\':
			if ((ch = NXTCH()) == '\n') {
				ifiles->lineno++;
				continue;
			} else {
				PUTCH('\\');
			}
			goto xloop;

		case '\n': /* newlines, for pp directives */
			ifiles->lineno++;
			do {
				PUTCH(ch);
run:				ch = NXTCH();
			} while (ch == ' ' || ch == '\t');
			if (ch == '#') {
				ppdir();
				continue;
			} else if (ch == '%') {
				ch = NXTCH();
				if (ch == ':') {
					ppdir();
					continue;
				} else {
					unch(ch);
					ch = '%';
				}
			}
			goto xloop;

		case '\"': /* strings */
str:			PUTCH(ch);
			while ((ch = inch()) != '\"') {
				PUTCH(ch);
				if (ch == '\\') {
					ch = inch();
					PUTCH(ch);
				}
				if (ch < 0)
					return;
			}
			PUTCH(ch);
			break;

		case '.':  /* for pp-number */
			PUTCH(ch);
			ch = NXTCH();
			if (ch < '0' || ch > '9')
				goto xloop;
			/* FALLTHROUGH */
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			do {
				PUTCH(ch);
				ch = NXTCH();
				if (spechr[ch] & C_EP) {
					PUTCH(ch);
					ch = NXTCH();
					if (ch == '-' || ch == '+')
						continue;
				}
			} while ((spechr[ch] & C_ID) || (ch == '.'));
			goto xloop;

		case '\'': /* character literal */
con:			PUTCH(ch);
			if (tflag)
				continue; /* character constants ignored */
			while ((ch = NXTCH()) != '\'') {
				PUTCH(ch);
				if (ch == '\\') {
					ch = NXTCH();
					PUTCH(ch);
				} else if (ch < 0)
					return;
				else if (ch == '\n')
					goto xloop;
			}
			PUTCH(ch);
			break;

		case 'L':
			ch = NXTCH();
			if (ch == '\"') {
				PUTCH('L');
				goto str;
			}
			if (ch == '\'') {
				PUTCH('L');
				goto con;
			}
			unch(ch);
			ch = 'L';
			/* FALLTHROUGH */
		default:
			if ((spechr[ch] & C_ID) == 0)
				error("fastscan");
			if (flslvl) {
				while (spechr[ch] & C_ID)
					ch = NXTCH();
				goto xloop;
			}
			i = 0;
			do {
				yytext[i++] = (usch)ch;
				ch = NXTCH();
				if (ch == '\\') {
					ch = NXTCH();
					if (ch != '\n') {
						unch('\n');
						ch = '\\';
					} else {
						ifiles->lineno++;
						ch = NXTCH();
					}
				}
				if (ch < 0)
					return;
			} while (spechr[ch] & C_ID);
			yytext[i] = 0;
			unch(ch);
			if ((nl = lookup((usch *)yytext, FIND)) != 0) {
				usch *op = stringbuf;
				putstr(gotident(nl));
				stringbuf = op;
			} else
				putstr((usch *)yytext);
			break;
		}
	}
}
コード例 #10
0
ファイル: token.c プロジェクト: enukane/netbsd-src
/*
 * Scan quickly the input file searching for:
 *	- '#' directives
 *	- keywords (if not flslvl)
 *	- comments
 *
 *	Handle strings, numbers and trigraphs with care.
 *	Only data from pp files are scanned here, never any rescans.
 *	TODO: Only print out strings before calling other functions.
 */
static void
fastscan(void)
{
	struct symtab *nl;
	int ch, i = 0;
	int nnl = 0;
	usch *cp;

	goto run;
	for (;;) {
		ch = NXTCH();
xloop:		if (ch == -1)
			return;
#ifdef PCC_DEBUG
		if (dflag>1)
			printf("fastscan ch %d (%c)\n", ch, ch > 31 ? ch : '@');
#endif
		if ((spechr[ch] & C_SPEC) == 0) {
			PUTCH(ch);
			continue;
		}
		switch (ch) {
		case EBLOCK:
		case WARN:
		case CONC:
			error("bad char passed");
			break;

		case '/': /* Comments */
			if ((ch = inch()) == '/') {
cppcmt:				if (Cflag) { PUTCH(ch); } else { PUTCH(' '); }
				do {
					if (Cflag) PUTCH(ch);
					ch = inch();
				} while (ch != -1 && ch != '\n');
				goto xloop;
			} else if (ch == '*') {
				if (eatcmnt())
					return;
			} else {
				PUTCH('/');
				goto xloop;
			}
			break;

		case '?':  /* trigraphs */
			if ((ch = chktg()))
				goto xloop;
			PUTCH('?');
			break;

		case '\\':
			if ((ch = NXTCH()) == '\n') {
				ifiles->lineno++;
				continue;
			} else {
				PUTCH('\\');
			}
			goto xloop;

		case '\n': /* newlines, for pp directives */
			while (nnl > 0) { PUTCH('\n'); nnl--; }
run2:			ifiles->lineno++;
			do {
				PUTCH(ch);
run:				ch = NXTCH();
				if (ch == '/') {
					ch = NXTCH();
					if (ch == '/')
						goto cppcmt;
					if (ch == '*') {
						if (eatcmnt())
							return;
						goto run;
					} 
					unch(ch);
					ch = '/';
				}
			} while (ch == ' ' || ch == '\t');
			if (ch == '\\') {
				ch = NXTCH();
				if (ch == '\n')
					goto run2;
				unch(ch);
				ch = '\\';
			}
			if (ch == '#') {
				ppdir();
				continue;
			} else if (ch == '%') {
				ch = NXTCH();
				if (ch == ':') {
					ppdir();
					continue;
				} else {
					unch(ch);
					ch = '%';
				}
			} else if (ch == '?') {
				if ((ch = chktg()) == '#') {
					ppdir();
					continue;
				} else if (ch == 0) 
					ch = '?';
			}
			goto xloop;

		case '\"': /* strings */
str:			PUTCH(ch);
			while ((ch = NXTCH()) != '\"') {
				if (ch == '\n')
					goto xloop;
				if (ch == '\\') {
					if ((ch = NXTCH()) != '\n') {
						PUTCH('\\');
						PUTCH(ch);
					} else
						nnl++;
					continue;
                                }
				if (ch < 0)
					return;
				PUTCH(ch);
			}
			PUTCH(ch);
			break;

		case '.':  /* for pp-number */
			PUTCH(ch);
			ch = NXTCH();
			if (ch < '0' || ch > '9')
				goto xloop;
			/* FALLTHROUGH */
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			do {
				PUTCH(ch);
nxt:				ch = NXTCH();
				if (ch == '\\') {
					ch = NXTCH();
					if (ch == '\n') {
						goto nxt;
					} else {
						unch(ch);
						ch = '\\';
					}
				}
				if (spechr[ch] & C_EP) {
					PUTCH(ch);
					ch = NXTCH();
					if (ch == '-' || ch == '+')
						continue;
				}
			} while ((spechr[ch] & C_ID) || (ch == '.'));
			goto xloop;

		case '\'': /* character literal */
con:			PUTCH(ch);
			if (tflag)
				continue; /* character constants ignored */
			while ((ch = NXTCH()) != '\'') {
				if (ch == '\n')
					goto xloop;
				if (ch == '\\') {
					if ((ch = NXTCH()) != '\n') {
						PUTCH('\\');
						PUTCH(ch);
					} else
						nnl++;
					continue;
				}
				if (ch < 0)
					return;
				PUTCH(ch);
			}
			PUTCH(ch);
			break;

		case 'L':
			ch = NXTCH();
			if (ch == '\"') {
				PUTCH('L');
				goto str;
			}
			if (ch == '\'') {
				PUTCH('L');
				goto con;
			}
			unch(ch);
			ch = 'L';
			/* FALLTHROUGH */
		default:
			if ((spechr[ch] & C_ID) == 0)
				error("fastscan");
			if (flslvl) {
				while (spechr[ch] & C_ID)
					ch = NXTCH();
				goto xloop;
			}
			i = 0;
			do {
				yytext[i++] = (usch)ch;
				ch = NXTCH();
				if (ch == '\\') {
					ch = NXTCH();
					if (ch != '\n') {
						unch(ch);
						ch = '\\';
					} else {
						putch('\n');
						ifiles->lineno++;
						ch = NXTCH();
					}
				}
				if (ch < 0)
					return;
			} while (spechr[ch] & C_ID);

			yytext[i] = 0;
			unch(ch);

			cp = stringbuf;
			if ((nl = lookup((usch *)yytext, FIND)) && kfind(nl)) {
				putstr(stringbuf);
			} else
				putstr((usch *)yytext);
			stringbuf = cp;

			break;
		}
	}
}
コード例 #11
0
ファイル: log.cpp プロジェクト: kiznit/rainbow-os
void Log(const char* format, va_list args)
{
    char buffer[500];                   // Buffer to hold the formatted string
    size_t size = sizeof(buffer) - 1;   // Minus 1 to account for terminating '\0'
    char* p = buffer;                   // Write pointer
    char convert[64];                   // Temporary buffer
    int base;                           // Base for converting numbers
    int precision;                      // How many digits to use to print a number
    uint64_t value;                     // Numeric value for conversions
    char c;                             // Character being processed

#define PUTCH(ch) do {      \
    if ( size-- <= 0 )      \
        goto Done;          \
    *p++ = (ch);            \
    } while (0)

    while (size > 0)
    {
        while ((c = *format++) != '%')
        {
            if (size-- <= 0 || c == '\0')
            {
                goto Done;
            }
            *p++ = c;
        }

        base = 10;
        precision = -1;

        switch (c = *format++)
        {
            case 'd':
            {
                value = va_arg(args, int);
                if ((int64_t) value < 0)
                {
                    PUTCH('-');
                    value = -value;
                }
                goto PrintNumber;
            }

            case 's':
            {
                const char* s = va_arg(args, const char*);
                while (*s) PUTCH(*s++);
                break;
            }

            case 'x':
            {
                value = va_arg(args, unsigned);
                base = 16;
                precision = sizeof(unsigned)*2;
                goto PrintNumber;
            }

            case 'X':
            {
                value = va_arg(args, uint64_t);
                base = 16;
                precision = sizeof(uint64_t)*2;
                goto PrintNumber;
            }

            case 'p':
            {
                value = va_arg(args, uintptr_t);
                base = 16;
                precision = sizeof(uintptr_t)*2;

            PrintNumber:

                int numDigits = 0;

                do
                {
                    convert[numDigits++] = digits[value % base];
                    value = value / base;
                } while (value > 0);

                for (int i = precision - numDigits; i > 0; --i)
                {
                    PUTCH('0');
                }

                while (numDigits > 0)
                {
                    PUTCH(convert[--numDigits]);
                }
                break;
            }

            default:
            {
                PUTCH('%');
                PUTCH(c);
                break;
            }
        }
    }

Done:
    *p = '\0';

    if (g_console)
    {
        g_console->Print(buffer);
    }
}
コード例 #12
0
/***********************************************************************
 * g e t P W F r o m C o n s o l e
 *
 * Does platform-dependent stuff to retrieve a char* from the console.
 * Retrieves up to the first newline character, but does not return
 * the newline. Maximum length is 200 chars.
 * Stars (*) are echoed to the screen.  Backspacing works.
 * WARNING: This function is NOT thread-safe!!! This should be OK because
 * the Java method that calls it is synchronized.
 *
 * RETURNS
 *      The password in a buffer owned by the caller, or NULL if the
 *      user did not enter a password (just hit <enter>).
 */
static char* getPWFromConsole()
{
    char c;
    char *ret;
    int i;
    char buf[200];  /* no buffer overflow: we bail after 200 chars */
    int length=200;
#ifdef XP_UNIX 
    int fd = fileno(stdin);
    struct termios save_tio;
    struct termios tio;
#endif


    /*
     * In Win32, the default is for _getch to not echo and to not be buffered.
     * In UNIX, we have to set this explicitly.
     */
#ifdef XP_UNIX
    if ( isatty(fd) ) {
        tcgetattr(fd, &save_tio);
        tio = save_tio;
        tio.c_lflag &= ~(ECHO|ICANON);   /* no echo, non-canonical mode */
        tio.c_cc[VMIN] = 1;     /* 1 char at a time */
        tio.c_cc[VTIME] = 0;    /* wait forever */
        tcsetattr(fd, TCSAFLUSH, &tio);
    } else {
        /* no reading from a file allowed. Windows enforces this automatically*/
        return NULL;
    }
#endif

    /*
     * Retrieve up to length characters, or the first newline character.
     */
    for(i=0; i < length-1; i++) {
        PR_ASSERT(i >= 0);
        c = GETCH();
        if( c == '\b' ) {
            /*
             * backspace.  Back up the buffer and the cursor.
             */
            if( i==0 ) {
                /* backspace is first char, do nothing */
                i--;
            } else {
                /* backspace is not first char, backup one */
                i -= 2;
                PUTCH('\b'); PUTCH(' '); PUTCH('\b');
            }
        } else if( c == '\r' || c == '\n' ) {
            /* newline, we're done */
            break;
        } else {
            /* normal password char.  Echo an asterisk. */
            buf[i] = c;
            PUTCH('*');
        }
    }
    buf[i] = '\0';
    PUTCH('\n');

    /*
     * Restore the saved terminal settings.
     */
#ifdef XP_UNIX
    tcsetattr(fd, TCSAFLUSH, &save_tio);
#endif

    /* If password is empty, return NULL to signal the user giving up */
    if(buf[0] == '\0') {
        ret = NULL;
    } else {
        ret = PL_strdup(buf);
    }

    /* Clear the input buffer */
    memset(buf, 0, length);

    return ret;
}
コード例 #13
0
int
MyPutCh(int ch)
{
    return PUTCH(ch);
}
コード例 #14
0
ファイル: tty_ioctl.c プロジェクト: jameszhan/foundation
int tty_ioctl(int dev, int cmd, int arg)
{
	struct tty_struct * tty;
	struct tty_struct * other_tty;
	int pgrp;

	if (MAJOR(dev) == 5) {
		dev = current->tty;
		if (dev<0)
			return -EINVAL;
	} else
		dev=MINOR(dev);
	tty = tty_table + (dev ? ((dev < 64)? dev-1:dev) : fg_console);

	if (IS_A_PTY(dev))
		other_tty = tty_table + PTY_OTHER(dev);
	else
		other_tty = NULL;
		
	if (!(tty->write_q && tty->read_q && tty->secondary && tty->write))
		return -EINVAL;
	switch (cmd) {
		case TCGETS:
			return get_termios(tty,(struct termios *) arg);
		case TCSETSF:
			flush(tty->read_q);
			flush(tty->secondary);
			if (other_tty)
				flush(other_tty->write_q);
		/* fallthrough */
		case TCSETSW:
			wait_until_sent(tty);
		/* fallthrough */
		case TCSETS:
			return set_termios(tty,(struct termios *) arg, dev);
		case TCGETA:
			return get_termio(tty,(struct termio *) arg);
		case TCSETAF:
			flush(tty->read_q);
			flush(tty->secondary);
			if (other_tty)
				flush(other_tty->write_q);
		/* fallthrough */
		case TCSETAW:
			wait_until_sent(tty); /* fallthrough */
		case TCSETA:
			return set_termio(tty,(struct termio *) arg, dev);
		case TCSBRK:
			if (!arg) {
				wait_until_sent(tty);
				send_break(tty);
			}
			return 0;
		case TCXONC:
			switch (arg) {
			case TCOOFF:
				tty->stopped = 1;
				tty->write(tty);
				return 0;
			case TCOON:
				tty->stopped = 0;
				tty->write(tty);
				return 0;
			case TCIOFF:
				if (STOP_CHAR(tty))
					PUTCH(STOP_CHAR(tty),tty->write_q);
				return 0;
			case TCION:
				if (START_CHAR(tty))
					PUTCH(START_CHAR(tty),tty->write_q);
				return 0;
			}
			return -EINVAL; /* not implemented */
		case TCFLSH:
			if (arg==0) {
				flush(tty->read_q);
				flush(tty->secondary);
				if (other_tty)
					flush(other_tty->write_q);
			} else if (arg==1)
				flush(tty->write_q);
			else if (arg==2) {
				flush(tty->read_q);
				flush(tty->secondary);
				flush(tty->write_q);
				if (other_tty)
					flush(other_tty->write_q);
			} else
				return -EINVAL;
			return 0;
		case TIOCEXCL:
			return -EINVAL; /* not implemented */
		case TIOCNXCL:
			return -EINVAL; /* not implemented */
		case TIOCSCTTY:
			return -EINVAL; /* set controlling term NI */
		case TIOCGPGRP:
			verify_area((void *) arg,4);
			put_fs_long(tty->pgrp,(unsigned long *) arg);
			return 0;
		case TIOCSPGRP:
			if ((current->tty < 0) ||
			    (current->tty != dev) ||
			    (tty->session != current->session))
				return -ENOTTY;
			pgrp=get_fs_long((unsigned long *) arg);
			if (pgrp < 0)
				return -EINVAL;
			if (session_of_pgrp(pgrp) != current->session)
				return -EPERM;
			tty->pgrp = pgrp;			
			return 0;
		case TIOCOUTQ:
			verify_area((void *) arg,4);
			put_fs_long(CHARS(tty->write_q),(unsigned long *) arg);
			return 0;
		case TIOCINQ:
			verify_area((void *) arg,4);
			put_fs_long(CHARS(tty->secondary),
				(unsigned long *) arg);
			return 0;
		case TIOCSTI:
			return -EINVAL; /* not implemented */
		case TIOCGWINSZ:
			return get_window_size(tty,(struct winsize *) arg);
		case TIOCSWINSZ:
			if (other_tty)
				set_window_size(other_tty,(struct winsize *) arg);
			return set_window_size(tty,(struct winsize *) arg);
		case TIOCMGET:
			return -EINVAL; /* not implemented */
		case TIOCMBIS:
			return -EINVAL; /* not implemented */
		case TIOCMBIC:
			return -EINVAL; /* not implemented */
		case TIOCMSET:
			return -EINVAL; /* not implemented */
		case TIOCGSOFTCAR:
			return -EINVAL; /* not implemented */
		case TIOCSSOFTCAR:
			return -EINVAL; /* not implemented */
		case TIOCLINUX:
			switch (get_fs_byte((char *)arg))
			{
				case 0: 
					return do_screendump(arg);
				case 1: 
					return do_get_ps_info(arg);
				default: 
					return -EINVAL;
			}
		default:
			return -EINVAL;
	}
}