我需要一些帮助才能开始使用shell在命令行上解析元素。我必须使用空格,单引号和双引号分隔不同的元素并将它们转换为标记。关于我可以使用哪些功能或方法的任何建议?
到目前为止,这是我的代码:
#include <stdio.h> //printf
#include <unistd.h> //isatty
#include <string.h> //strlen
int main(int argc, char **argv[]){
int MaxLength = 1024; //size of buffer
char buffer[MaxLength]; //bufer
bzero(buffer,sizeof(buffer)); //zeros out the buffer
char *command; // character pointer of strings
int inloop =1;
/* part 1 isatty */
if (isatty(0))
{
while(inloop ==1) // check if the standard input is from terminal
{
printf("$");
command = fgets(buffer,sizeof(buffer),stdin); //fgets(string of char pointer,size of,input from where
//check for empty space
//check for ''
//check for ""
//check for |
if(strcmp(command,"exit\n")==0)
inloop =0;
}
}
else
printf("the standard input is NOT from a terminal\n");
return 0;
}