Hej, szukam pomocy z zrobieniem jakieś powłoki w C/C++ z własnego pomysłu poleceniami praca zaliczeniowa.
Może ktoś znajdzie w sieci lub ma cos takiego?
Ale czego oczekujesz? Pomocy z implementacją (wklej kod)? Żeby ktoś za Ciebie to napisał (wklej budżet)? Pomysłów (zły dział)?
Większość tych "blondynek" żebrzących o program na zaliczenie, to faceci, nie dajcie się zwieść.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#define TRUE 1
#define DEFAULT_PATH "/usr/bin/"
#define VERSION "MojaPowloka"
#define PATH_LENGHT 9
#define ARG_MAX 2097152
#define PRM_MAX 10
int status = 0;
void LoadCommand(char iCMD[])
{
printf("%s$ ", VERSION);
fgets(iCMD, sizeof(iCMD), stdin);
}
void MemoryAllocation(char iPARAMETERS[], char iCMD[])
{
int i = 0;
int j = 1;
for(i = 0; iCMD[i]!='\0'; i++) {
if(iCMD[i]==' ') j++;
}
for(i = 0; i<j; i++) {
iPARAMETERS[i] = (char) malloc((ARG_MAX+1)*(sizeof(char)));
}
}
int GetParameters(char iCMD[], char* iPARAMETERS[], char iPROGRAM[])
{
int i = 0;
for(i = 0; iCMD[i]!=' ' && iCMD[i]!='\0'; i++) {
iPROGRAM[PATH_LENGHT+i] = iCMD[i];
}
iPROGRAM[strlen(iPROGRAM)-1] = '\0';
i = 0;
int LastPosition = 0;
MemoryAllocation(iPARAMETERS, iCMD);
for(i = 0; i<PRM_MAX; i++) {
char tmpPARAM[ARG_MAX+1];
int j = 0;
for(j = 0; iCMD[LastPosition]!=' ' && iCMD[LastPosition]!='\0'; j++) {
tmpPARAM[j] = iCMD[LastPosition];
LastPosition++;
}
tmpPARAM[j]='\0';
strncpy(iPARAMETERS[i], tmpPARAM, strlen(tmpPARAM)+1);
if(iCMD[LastPosition]=='\0') {
i++;
break;
}
LastPosition++;
}
return i;
}
void Clean(char *iPARAMETERS[], int iNUMBER)
{
int i = 0;
for(i = 0; i<iNUMBER; i++) {
free(iPARAMETERS[i]);
}
}
int main(void)
{
while(TRUE) {
char Program[ARG_MAX+1] = DEFAULT_PATH;
char* Parameters[PRM_MAX];
char Command[ARG_MAX+1];
LoadCommand(Command);
int NumberOfParameters = GetParameters(Command, Parameters, Program);
if(fork()!=0) {
waitpid(-1, &status, 0);
}
else {
execve(Program, Parameters, 0);
}
Clean(Parameters, NumberOfParameters);
}
return 0;
}