- 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
您可能关注的文档
最近下载
- 传统基材润湿流平(氟碳硅烷嵌段).pdf VIP
- 南京财经大学2024-2025学年第1学期《高等数学(上)》期末考试试卷(B卷)附参考答案.pdf
- C4D课程考试试题及参考答案.doc VIP
- 2025年陕西公务员申论考试真题及答案B卷.docx VIP
- [渝粤教育] 西北工业大学 航天器控制原理 mooc 资料.docx VIP
- 航天器控制原理(西北工业大学)中国大学MOOC 慕课 章节测验 期末考试答案.pdf VIP
- 精品解析:2025年陕西省中考数学试题(原卷版).docx VIP
- 四维度主力跟踪.pdf
- 2022年陕西省中考数学真题(原卷版).docx VIP
- 大众网关控制器和bcm车身控制模块针脚定义非常有用.pdf VIP
原创力文档

文档评论(0)