takeput.c

来自「unix环境高级编程 配套源代码 学习学习啊」· C语言 代码 · 共 56 行

C
56
字号
#include	"call.h"/* Process the argv-style arguments for take or put commands. */inttake_put_args(int argc, char **argv){	if (argc == 1) {		src = dst = argv[0];		return(0);	} else if (argc == 2) {		src = argv[0];		dst = argv[1];		return(0);	}	return(-1);}static char	cmdargs[MAXLINE];			/* can't be automatic; src/dst point into here *//* Read a line from the user.  Call our buf_args() function to * break it into an argv-style array, and call userfunc() to * process the arguments. */intprompt_read(char *prompt, int (*userfunc)(int, char **)){	int		n;	char	c, *ptr;	tty_reset(STDIN_FILENO);	/* allow user's editing chars */	n = strlen(prompt);	if (write(STDOUT_FILENO, prompt, n) != n)		err_sys("write error");	ptr = cmdargs;	for ( ; ; ) {		if ( (n = read(STDIN_FILENO, &c, 1)) < 0)			err_sys("read error");		else if (n == 0)			break;		if (c == '\n')			break;		if (ptr < &cmdargs[MAXLINE-2])			*ptr++ = c;	}	*ptr = 0;		/* null terminate */	tty_raw(STDIN_FILENO);		/* reset tty mode to raw */	return( buf_args(cmdargs, userfunc) );				/* return whatever userfunc() returns */}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?