최종 파일은 일단 첨부 하고 나중에 정리 하자.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define CMD_MAX_LINE 255
typedef struct minishell_option_t {
int b_echo;
} minishell_option_s;
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
/*
fgets() reads in at most one less than size characters from stream and
stores them into the buffer pointed to by s. Reading stops after an
EOF or a newline. If a newline is read, it is stored into the buffer.
A terminating null byte ('\0') is stored after the last character in
the buffer.
fgets() returns s on success, and NULL on error or when end of file occurs
while no characters have been read.
*/
char * minishell_prompt = "minishell>";
char * minishell_exit = "exit";
minishell_option_s minishell_option = {TRUE};
char cmd_line[CMD_MAX_LINE];
int main(int argc, char * argv[])
{
fputs(minishell_prompt, stdout);
while(fgets(cmd_line,CMD_MAX_LINE,stdin)){
//cmd_line[CMD_MAX_LINE-1] = '\0';
//__fpurge(stdin); //리눅스 솔라리스 등에서만 가능!! 대신 다음줄을 사용
while( getchar() != '\n' );
if(!strncmp(cmd_line,minishell_exit,4)) exit(0);
if(minishell_option.b_echo)fputs(cmd_line,stdout);
fputs(minishell_prompt, stdout);
}
return 0;
}
minishell.zip
0.01MB
'그룹명2 > LINUX' 카테고리의 다른 글
리눅스 라이브러리 만들기 (0) | 2016.06.28 |
---|---|
systemd (0) | 2016.04.27 |
GDB 사용법 정리 (0) | 2016.04.20 |
참고: Joinc와 함께하는 리눅스 시스템 프로그래밍 (0) | 2016.04.20 |
리눅스 동적 라이브러리 만들기 (0) | 2016.04.20 |