Exemple #1
0
int main()
{
	int argc;
	char **argv = NULL, s[MAX];
	LinkedList * myList = linkedList();
  
  	printf("command?: ");
  	fgets(s, MAX, stdin);
  	strip(s);

  	while(strcmp(s, "exit") != 0)
  	{
		if(strcmp(s, "history") == 0)
      {
			argc = makeargs(s, &argv);
			addLast(myList, buildNode_Type(buildType_Args(argc, argv)));
         printList(myList, printType);
      }
		else
		{
			argc = makeargs(s, &argv);
			addLast(myList, buildNode_Type(buildType_Args(argc, argv)));

		}// end else

		printf("command?: ");
	  	fgets(s, MAX, stdin);
      strip(s);	 

  	}// end while

	clearList(myList, cleanType);
   	free(myList);
   	myList = NULL;

   	printf("Program Ended\n");

  	return 0;

}// end main
Exemple #2
0
void addToHistory(char * s)
{
	History * h = (History *)calloc(1, sizeof(History));

	int l = strlen(s);
	(*h).line = (char*)calloc(l + 1, sizeof(char));
	strncpy((*h).line, s, l);

	Node * nn = buildNode_Type(h);

	trimList();

	addLast(HISTORY, nn);
}
Exemple #3
0
void command(char* s, LinkedList* historyList)
{
	int preCount = 0, postCount = 0, pipeCount = 0, argc;
	char **prePipe = NULL, **postPipe = NULL, **argv = NULL;

	while(strcmp(s, "exit") != 0)
	{
		char s2[50];
		strcpy(s2, s);
		strip(s2);
		argc = makeargs(s2, &argv);
		addLast(historyList, buildNode_Type(buildType_Args(argc, argv)));
		memset(&s2[0], 0, sizeof(s2));

		pipeCount = containsPipe(s);
		if(pipeCount > 0)
		{
			prePipe = parsePrePipe(s, &preCount);
			postPipe = parsePostPipe(s, &postCount);
			pipeIt(prePipe, postPipe, historyList);
			clean(preCount, prePipe);
			clean(postCount, postPipe);
		}// end if pipeCount

		else
		{
			if(strcmp(argv[0],"cd") != 0) {
				if (argc != -1)
					forkIt(argv, historyList);
			}
			else
				myDir(argv);
		}
		//	clean(argc, argv);
		//	argv = NULL;

		//printList(historyList,printType);

		memset(&s[0], 0, sizeof(s));
		printf("\ncommand?: ");
		fgets(s, MAX, stdin);
		strip(s);

	}// end while




}