그룹명2/LINUX
미니쉘(minishell) STEP01
lseek
2016. 4. 26. 11:23
최종 파일은 일단 첨부 하고 나중에 정리 하자.
#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