I am trying to understand a program here I have not been able to understand the static int split(char *cmd_exec, int input, int first, int last)
function what is the purpose of int input,int first,int last here , this function returns return command(input, first, last, new_cmd_exec1);
what does input,first,last and new_cmd_exec1 signify here? Why do we need to spilt the commands passed on to a shell ? The relevant code is following
我试图理解一个程序在这里我无法理解静态int split(char * cmd_exec,int input,int first,int last)函数int输入的目的是什么,int first,int last here,this function返回return命令(input,first,last,new_cmd_exec1); input,first,last和new_cmd_exec1在这里表示什么?为什么我们需要将传递给shell的命令溢出?相关代码如下
static int split(char *cmd_exec, int input, int first, int last)
{
char *new_cmd_exec1;
new_cmd_exec1=strdup(cmd_exec);
//else
{
int m=1;
args[0]=strtok(cmd_exec," ");
while((args[m]=strtok(NULL," "))!=NULL)
m++;
args[m]=NULL;
if (args[0] != NULL)
{
if (strcmp(args[0], "exit") == 0)
exit(0);
if (strcmp(args[0], "echo") != 0)
{
cmd_exec = skipcomma(new_cmd_exec1);
int m=1;
args[0]=strtok(cmd_exec," ");
while((args[m]=strtok(NULL," "))!=NULL)
m++;
args[m]=NULL;
}
if(strcmp("cd",args[0])==0)
{
change_directory();
return 1;
}
else if(strcmp("pwd",args[0])==0)
{
parent_directory();
return 1;
}
}
}
return command(input, first, last, new_cmd_exec1);
}
1 个解决方案
#1
0
The meaning of the variables isn't clear from the code you posted. However, if you can find any documentation for, or the definition of, the function command()
, you may be able to learn their intended purpose.
从您发布的代码中不清楚变量的含义。但是,如果您可以找到函数command()的任何文档或定义,您可以了解它们的预期用途。
Having said that, it's pretty clear from the code that these parameters are just copies of the parameters that were initially passed to split()
and passed on to command()
, so it is likely that the integers are general purpose parameters whose meaning will depend on the eventual type of command executed.
话虽如此,从代码中可以清楚地看出,这些参数只是最初传递给split()并传递给command()的参数的副本,因此整数很可能是通用参数,其含义取决于关于最终执行的命令类型。
#1
0
The meaning of the variables isn't clear from the code you posted. However, if you can find any documentation for, or the definition of, the function command()
, you may be able to learn their intended purpose.
从您发布的代码中不清楚变量的含义。但是,如果您可以找到函数command()的任何文档或定义,您可以了解它们的预期用途。
Having said that, it's pretty clear from the code that these parameters are just copies of the parameters that were initially passed to split()
and passed on to command()
, so it is likely that the integers are general purpose parameters whose meaning will depend on the eventual type of command executed.
话虽如此,从代码中可以清楚地看出,这些参数只是最初传递给split()并传递给command()的参数的副本,因此整数很可能是通用参数,其含义取决于关于最终执行的命令类型。