1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| #include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
typedef struct command
{
char chemin[256];
char instruction[128];
char argument[128];
}command;
void
Execution(command cmde, int path)
{
pid_t fils;
printf("\nentrée fonction Execution :\n\n\n");
printf("cmde.instruction : %s\n\n", cmde.instruction);
printf("cmde.chemin : %s\n\n", cmde.chemin);
printf("cmde.argument : %s\n\n", cmde.argument);
fils=fork();
if (fils == 0)
{
if (path > 0)
{
printf("execl\n");
execl(cmde.chemin, cmde.instruction, cmde.argument, NULL);
}
else
{
printf("execlp\n\n\n");
execlp(cmde.instruction, cmde.instruction,cmde.argument, NULL);
}
}
}
void Interpretation(char* saisie)
{
int path=0, args=0,instruct=0;
command cmde;
cmde.argument[0]='\0';
char* temp=strtok(saisie, " ");
char* prog=temp;
char* PID;
if((PID=strchr(saisie,'&'))!=NULL)
{
puts(PID);
printf("\n\nPid : %d\n\n",getpid());
*PID='\0';
}
do
{
if((prog=strrchr(prog, '/')) != NULL)
{
prog++;
printf("instruction : %s\n",prog);
path=1;
instruct=1;
strcpy(cmde.chemin, temp);
strcpy(cmde.instruction, prog);
}
else
{
printf("temp 5 : %s\n",temp);
if(instruct==0)
{
printf("temp 4 : %s\n",temp);
strcpy(cmde.instruction, temp);
printf("temp = %s\n", temp);
printf("cmde.instruction : %s\n\n", cmde.instruction);
instruct=1;
}
else
{
if (args > 0)
{
printf("temp %d : %s\n",args+5,temp);
strcat(cmde.argument, " ");
}
strcat(cmde.argument, temp);
args++;
}
}
}
while((temp=strtok(0, " ")) != NULL);
printf("cmde.argument : %s\n\n", cmde.argument);
Execution(cmde, path);
}
void Prompt(char* saisie)
{
puts("1");
unsigned long i=strlen(saisie),j;
char *lapinou[6];
puts("2");
strcat(lapinou[0]," | ̄ ̄");
strcat(lapinou[1]," | ");
strcat(lapinou[2]," |__");
strcat(lapinou[3]," (\\__/) ||");
strcat(lapinou[4]," (ㅅ) || ");
strcat(lapinou[5]," / づ");
puts("3");
j=i+6;
lapinou[0]=(char*) malloc(sizeof (char)*j);
lapinou[1]=(char*) malloc(sizeof (char)*j);
lapinou[2]=(char*) malloc(sizeof (char)*j);
puts("4");
while(i>0)
{
strcat(lapinou[0]," ̄");
strcat(lapinou[2],"_");
i--;
}
puts("5");
strcat(lapinou[0], "|");
strcat(lapinou[2], "|");
strcat(lapinou[1], "|");
for(i=0;i<6;i++)
{
puts(lapinou[i]);
}
puts("7");
}
int
main()
{
char saisie[1500] = {'\0'};
char *pt;
puts("Saisir une commande :\n");
fgets(saisie, 300, stdin);
if ((pt=strchr(saisie, '\n')) != NULL)
{
*pt = '\0';
}
// strncpy(cmde.chemin, saisie, sizeof(cmde.chemin));
Prompt(saisie);
return 0;
} |
Partager