userin.c

来自「LINUX下VI编写的SHELL工具LINUX下VI编写的SHELL工具」· C语言 代码 · 共 64 行

C
64
字号
//userin2.c

#include "smallsh.h"

char inpbuf[MAXBUF],tokbuf[2*MAXBUF],*ptr = inpbuf,*tok = tokbuf;

int userin(char *p)
{
	int c,count;
 	ptr = inpbuf;
  	tok = tokbuf;
         
   	printf("%s",p);
    count = 0;
    while(1)
    {
    	if((c = getchar()) == EOF)
     		return(EOF);
                  
       	if(count < MAXBUF)
        	inpbuf[count++] = c;
        else 
        {
        	printf("smallsh: input line too long \n");
         	count = 0;
          	printf("%s",p);
           	continue;
        }
                  
        if(c == '\n')
        {
        	inpbuf[count] = '\0';
         	return count;
        }
	}
}

/*
//gettok.c

int gettok(char **outptr)
{
	int type;
 	*outptr = tok;
  	while(*ptr == ' ' || *ptr == '\t')
   		ptr++;
  	*tok++ = *ptr;
         
 	switch(*ptr++)
  	{
   		case '\n':
     		type = EOL; break;
         case '&':
         	type= SEMICOLON; break;
         default:
         	type = ARG;
          	while(inarg(*ptr))
           		*tok++ = *ptr++;
     }
     *tok++ = '\0';
     return type;
}
*/

⌨️ 快捷键说明

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