我想使用 c 语言编程创建一个 shell 文件。我已经有教授给出的这个计划,但是当我尝试执行时我有这个错误并且我有这个问题
myshell.c 文件(这个文件是我必须修改和执行的文件)
/* RCS information: $Id: myshell.c,v 1.2 2006/04/05 22:46:33 elm Exp $ */
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
extern char **getcmdstring(char *cmd);
int main(void) {
int i;
char **args;
char cmd[4096];
while(1) {
printf("$ ");
fgets(cmd,4096,stdin);
args = getcmdstring(cmd);
for(i = 0; args[i] != NULL; i++) {
printf("Argument %d: %s\n", i, args[i]);
}
}
}
和 shell.l 文件
/* RCS information: $Id: shell.l,v 1.1 2006/04/05 22:46:33 elm Exp $ */
#include <stdio.h>
#include <strings.h>
#include <string.h>
int _numargs = 200;
char *_args[200];
int _argcount = 0;
char *strdup(const char *);
%}
WORD [a-zA-Z0-9\/\.-]+
SPECIAL [()><|&;]
%%
_argcount = 0; _args[0] = NULL;
{WORD}|{SPECIAL} {
if(_argcount < _numargs-1) {
_args[_argcount++] = (char *)strdup(yytext);
_args[_argcount] = NULL;
}
}
\n return (int)_args;
[ \t]+
.
%%
char **getcmdstring(char *cmd) {
char **ret;
yy_scan_string(cmd);
ret = (char **)yylex();
yy_delete_buffer(YY_CURRENT_BUFFER);
return ret;
}