⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 psh1.c

📁 unix linux 编程实践源代码
💻 C
字号:
/*	prompting shell version 1 *		Prompts for the command and its arguments. *		Builds the argument vector for the call to execvp. *		Uses execvp(), and never returns. */#include	<stdio.h>#include	<signal.h>#include	<string.h>#define	MAXARGS		20				/* cmdline args	*/#define	ARGLEN		100				/* token length	*/int main(){	char	*arglist[MAXARGS+1];		/* an array of ptrs	*/	int	numargs;			/* index into array	*/	char	argbuf[ARGLEN];			/* read stuff here	*/	char	*makestring();			/* malloc etc		*/	numargs = 0;	while ( numargs < MAXARGS )	{							printf("Arg[%d]? ", numargs);		if ( fgets(argbuf, ARGLEN, stdin) && *argbuf != '\n' )			arglist[numargs++] = makestring(argbuf);		else		{			if ( numargs > 0 ){		/* any args?	*/				arglist[numargs]=NULL;	/* close list	*/				execute( arglist );	/* do it	*/				numargs = 0;		/* and reset	*/			}		}	}	return 0;}int execute( char *arglist[] )/* *	use execvp to do it */{	execvp(arglist[0], arglist);		/* do it */	perror("execvp failed");	exit(1);}char * makestring( char *buf )/* * trim off newline and create storage for the string */{	char	*cp, *malloc();	buf[strlen(buf)-1] = '\0';		/* trim newline	*/	cp = malloc( strlen(buf)+1 );		/* get memory	*/	if ( cp == NULL ){			/* or die	*/		fprintf(stderr,"no memory\n");		exit(1);	}	strcpy(cp, buf);		/* copy chars	*/	return cp;			/* return ptr	*/}

⌨️ 快捷键说明

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