Linux sell模拟实例 C语言.docVIP

  • 11
  • 0
  • 约2.14万字
  • 约 25页
  • 2016-10-18 发布于贵州
  • 举报
Linux sell模拟实例 C语言

直接键入“make”即可运行,无需修改。 可键入”DEBUG=yes”查命令,然后键入”DEBUG=no”取消。 期中包括简单命令,管道命令模拟。 以下是MAKEFILE: # # # Sample Makefile for Assignment 2 # CFLAGS = -g -Wall -Werror -O2 CC = gcc PROGRAM = mybash CFILES = parser.c mybash.c HFILE = parser.h ################################################## # # You shouldnt need to change anything else # ################################################## # compute the OFILES OFILES = ${CFILES:.c=.o} # all of the .o files that the program needs OBJECTS = ${OFILES} # How to make the whole program ${PROGRAM} : ${OBJECTS} ${CC} ${CFLAGS} ${OBJECTS} -o ${PROGRAM} # # File dependencies # ${OFILES}: ${HFILE} parser.h clean: /bin/rm -f *.o ${PROGRAM} 头文件: /* the states */ #define COMMAND 1 #define ARG 2 #define INFILE 3 #define OUTFILE 4 #define UNDEF 5 struct Command { char *command; char *args[11]; int numargs; }; struct CommandData { struct Command TheCommands[20]; /* the commands to be executed. TheCommands[0] is the first command to be executed. Its output is piped to TheCommands[1], etc. */ int numcommands; /* the number of commands in the above array */ char *infile; /* the file for input redirection, NULL if none */ char *outfile; /* the file for output redirection, NULL if none */ int background; /* 0 if process is to run in foreground, 1 if in background */ }; extern int ParseCommandLine(char *, struct CommandData *); 头文件中函数: #include stdio.h #include strings.h /* for strdup */ #include parser.h static int IsAlphaNum(char c) /* is this a valid char for a pathname or filename? */ { if (c = A c = Z) return 1; if (c = a c = z) return 1; if (c = 0 c = 9) return 1; if (c == . || c == _ || c == / || c == -) return 1; return 0; } /************** COPYWORD ************** This function copies a word (token) to the appropriate field of the struct CommandData data, and resets state. It returns 1 if successful, 0 if it detects an error. This

文档评论(0)

1亿VIP精品文档

相关文档