Parser

/*********************************************************************************/
/*                                                                               */
/* Program Name: parser3                                                         */
/* Usage:                                                                        */
/* Purpose: breaks up a string  of text into separate strings, puts pointers into*/
/* an array to be passed to argv                                                 */
/* Author: John Lynch                                                            */
/* Date: 5 2, 2000                                                               */
/* comments: this shell can only take in single commands without parameters      */
/*                                                                               */
/*********************************************************************************/
#include <minix/config.h>
#include <ansi.h>
#include <sys/types.h>
#include <minix/const.h>
#include <minix/type.h>
#include <limits.h>
#include <errno.h>
#include <minix/syslib.h>
#include <stdio.h>
#include <string.h>
#define Extern extern
#include <signal.h>
#include <errno.h>
#include <setjmp.h>

int tempindex = 0;
int j = 0;
int i = 0;
int h = 0;
int arg_index = 0;
int strn_count=0;
char input[25];
char *pointer_list[20];
main(){
	gets(input);
	
	/* walk through array*/
	strn_count = strlen(input);
	for(i=0; i <= strn_count; i++){
		if((input[i]==' ') || (input[i]=='\0')){

			pointer_list[j] = (char*)malloc(i - tempindex + 1);
			printf("\n address in array j at location %d is %p",j , pointer_list[j]);
			h = 0;
			/*for loops through section of string*/	
				
			for(;tempindex < i; tempindex++){
				/*printf("\n %c", input[tempindex]);*/
				pointer_list[j][h] = input[tempindex];
				/*printf("\n %c", pointer_list[j][h]);*/
				h++;
			}/*for*/
			
			/* add a null to end of string */
			/*printf("\nvalue of h is %d", h);*/
			pointer_list[j][h] = '\0';
			/* increase tempindex to point after the space*/
			tempindex++;
			
			/* this prints out the string the array points to*/
			/*for testing purposes*/
			printf("\nvalue inside if %s", pointer_list[j]);

			/*increase main pointer array to next position */
			j++;
		}/*if*/
	}/*for*/
	
	/*this loop is for testing only*/
	for(i=0; i 

Back to top