⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myfun.c

📁 一个实现基本功能的shell命令解释器
💻 C
字号:
#include "myfun.h"/***************************************************///Function file: myfun.c myfun.h//Return       : void//Var		   : void//Author	   : Moxudong//Verison      : V1.2//Last amend   : 2009-03-04  by Mxd/***************************************************/void p_info(void){	char *show, *buff;	show = (char *)malloc(MAX/4);	buff = (char *)malloc(MAX/4);	strcat(show, "[ysh@");	getcwd(buff, MAX/4);	strcat(show, buff);	strcat(show, "]# ");	printf("%s", show);}/***************************************************///Function file: myfun.c myfun.h//Return value : 0(success) or -1(falt)//Var		   : char *source, char *argv[]//source : the input string//argv[] : cuted string store in aegv[]//Author : Moxudong//Version: V1.0//Last amend : 2009-03-03 by Mxd/***************************************************/int cmd_cut(char *source, char *argv[]){	int  i = 0		,loop = 0		,space = 0		,len = 0		,sign = 1; // if you don't need the first space ,chose sign=0 ! 	if((source[0] == '\n') || (source[0] == '\0') 						   || (source[0] == ' '))	{		return -1;	}	else	{		len = strlen(source);		for(loop=0; loop<len; loop++)		{			if(*source == ' ')			{				if(space == 0)   // '0':It means the first time of space's show!				{					*source = '\0';					space = 1;					sign = 1;				}				*source++;			}			else			{				if(sign == 1)				{					argv[i++] = source;					argv[i] = NULL;				}				space = 0;				sign = 0;				*source++;			}		}		return i+1;	}}/****these func is in other C file*******void redirect(void){	printf("This is redirect!\n");}void my_pipe(void){	printf("This is my pipe!\n");}*****************************************/int is_founded(void){	FILE *fp;	if((fp = fopen("my_profile", "r")) == NULL)		return -1;	else		return 0;}int init_enveriment(char *path, char *path_rec[]){	FILE *fp;	if((fp = fopen("my_profile", "wb+")) == NULL)	{		printf("create profile error!\n");		return -1;	}	else	{		fwrite(path, sizeof(char)*strlen(path), 1, fp);		fclose(fp);	}	read_enveriment(path, path_rec);	return 0;}int read_enveriment(char *path, char *path_rec[]){	int cnt = 0, sign = 1;	while(*path++ != '/');	*path--;//changed now	while(*path != '\0')	{		if(*path == ':')		{			*path++ = '\0';			sign = 1;		}		else		{			if(sign == 1)			{				path_rec[cnt++] = path;				path_rec[cnt] = NULL;				sign = 0;			}			*path++;		}	}	return cnt+1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -