コード例 #1
0
ファイル: attributes.c プロジェクト: sh19910711/leap.js
attribute attribute_findfirst(relation rel,
			      FILE **attribute_file) {
/* attribute_findfirst
 * Return the first attribute in a relation
 */
	attribute att;

	if (leapver!=LEAP_UPGRADE) {
		raise_error( ERROR_OBSOLETED_CODE, NONFATAL,"");
	}
	/* Create a ptr to an attribute structure */
	att=(attribute_struct *) malloc(sizeof(attribute_struct));
	
	/* Check that the ptr was allocated. */
	check_assign(att,"attributes.attribute_findfirst");

	(void) open_attribute_file(attribute_file,rel,"r");

	if (attribute_file==NULL) {
		return(NULL);
	} else {
		(void) attribute_populate(att,attribute_file);

		return(att);			
	}
}	
コード例 #2
0
ファイル: attributes.c プロジェクト: sh19910711/leap.js
attribute attribute_find ( relation rel, char *name) {
/* attribute_find
 * Locates the given attribute, and returns an attribute structure
 */
	attribute catt,ratt;
	tuple ctuple;
	word anum;

	/* Get the first attribute */
	/* catt=attribute_findfirst(rel,&attribute_file); */
	catt=relation_attribute_readfirst(rel,&ctuple,&anum);

	/* Whilst the attribute is valid, and the attribute does
	 * not match the search criteria 
	 */
	while ( (catt!=NULL) && (name!=NULL) && (strcmp(attribute_name(catt),name)!=0) ) {

		/* Locate the next field */
		catt=relation_attribute_readnext(rel,&ctuple,catt,&anum);
	}

	/* Check to see if we actually found anything */
	if ( (catt!=NULL) && (name!=NULL) && (strcmp(attribute_name(catt),name)==0) ) {
	
		/* We're about to destroy the tuple, which will destroy the attribute
		 * we just found. Make a copy quick!
		 */
		/* Create a ptr to an attribute structure */
		ratt=(attribute_struct *) malloc(sizeof(attribute_struct));
	
		/* Check that the ptr was allocated. */
		check_assign(ratt,"attributes.attribute_find(cpy)");

		strcpy(attribute_name(ratt),attribute_name(catt));
		attribute_type(ratt)=attribute_type(catt);
		attribute_size(ratt)=attribute_size(catt);
		attribute_no(ratt)=attribute_no(catt);
		
		close_tuple(&ctuple,TUPLE_DISPOSE);

		/* Return the ptr */
		return(ratt);
	} else {
	
		/* Close the tuple */
		close_tuple(&ctuple,TUPLE_DISPOSE);

		/* Return nothing */	
		return(NULL);
	}
}
コード例 #3
0
ファイル: attributes.c プロジェクト: sh19910711/leap.js
attribute attribute_build(relation rel,
			char *attribute_name,
			char data_type,
			int  attrib_size ) {
/* attribute_build
 * Builds an attribute from parameters 
 */
	attribute att;
 
	/* Create a ptr to an attribute structure */
	att=(attribute_struct *) malloc(sizeof(attribute_struct));
	
	/* Check that the ptr was allocated. */
	check_assign(att,"attributes.attribute_findfirst");

	strcpy(att->name,attribute_name);
	att->attrib_size=attrib_size;
			
	if (data_type==DT_STRING) {
		/* Type is string */
		att->data_type=DT_STRING;
		
		if ((att->attrib_size)==0) {
			att->attrib_size=DEFAULT_ATTRIBUTE_SIZE;
		}

	} else if (data_type==DT_NUMBER) {
		/* Type is a number */
		att->data_type=DT_NUMBER;
		
		if ((att->attrib_size)==0) {
			att->attrib_size=DEFAULT_NUMERIC_ATTRIBUTE_SIZE;
		}
	
	} else if (data_type==DT_BOOLEAN) {
		/* Type is a number */
		att->data_type=DT_BOOLEAN;

		if ((att->attrib_size)==0) {
			att->attrib_size=DEFAULT_BOOLEAN_ATTRIBUTE_SIZE;
		}
	} else {
		att->data_type=DT_UNDEFINED;
	}

	return(att);	
			
}
コード例 #4
0
ファイル: convert.c プロジェクト: sh19910711/leap.js
relation relation_read( char *path, char *name) {
/* relation_read
 * Read a specified relation into memory, and return
 * a ptr to it
 */
	relation rel;
	char relname[RELATION_NAME_SIZE+FILENAME_EXT_SIZE+1];
	FILE *tmp; /* Used to test if a file exists */
	char tstring[FILE_PATH_SIZE]; /* Used for test */
	char newrelname[FILE_PATH_SIZE];
	char oldrelname[FILE_PATH_SIZE];
	FILE *nrf;

	/* Create the relation and check its ok */	
	rel=(relation_struct *) malloc(sizeof(relation_struct));
	check_assign(rel,"relation.relation_read");

	/* Copy the relation filename into the "name" */
	strcpy(relname,name);		

	if (strtok(relname,".")==NULL) {
		leap_fprintf(stderr,"Not a relation? Something strange has happened");

		/* Return NULL. This is never reached (unless things really are going weird) */
		return(NULL);
	} else {
		strcpy(rel->name,relname);

		if (  (strcmp(rel->name,LEAP_DD_RSHIP)==0) 
	  		||(strcmp(rel->name,LEAP_DD_DATABASE)==0)
            ||(strcmp(rel->name,LEAP_DD_RELATIONS)==0)
           )
			rel->system=TRUE;
		else 
			rel->system=FALSE;

		/* Populate with some information */	
		strcpy(rel->filepath,path);
		strcpy(rel->filename,name);

		/* Populate the field information */
		strcpy(rel->fieldname,relname);
		/* And add the field extension */
		strcat(rel->fieldname,LEAP_FIELD_EXT);

		/* Reset the structural information */	
		rel->next=NULL;
		rel->previous=NULL;

		rel->rcache=NULL;

		/* Build the temporary file name */	
		strcpy(tstring,path);
		strcat(tstring,relname);
		strcat(tstring,LEAP_TEMPORARY_EXT);
		
		/* Try to open the temporary file */
		tmp=fopen(tstring,"r");

		/* If tmp is NULL, no file. (False)
		 * If tmp is NOT null, file (True)
 		 */
		if (tmp==NULL) {
			rel->temporary=FALSE;
		} else {
			rel->temporary=TRUE;
			/* Close the file */
			fclose(tmp);
		}

		rel->noattributes=0;
		/* TODO: This is stored in the new structure. When the
		 * new structure is enabled, read from this 
		 */

		strcpy(newrelname,path);
		strcat(newrelname,relname);
		strcat(newrelname,LEAP_NEW_RELATION_EXT);

		nrf=fopen(newrelname,"r");

		if (nrf==NULL) {
			if (status_trace) {
				leap_fprintf(stderr,"No new relation format file for relation %s exists, creating...",name);
				fflush(stdout);
			}


			build_new_relation( rel, newrelname );

			sprintf(oldrelname,"%s%s%s",path,relname,LEAP_FIELD_EXT);	
			sprintf(newrelname,"%soldfmt/%s%s",path,relname,LEAP_FIELD_EXT);	
			if (rename(oldrelname,newrelname)!=0) {
				leap_fprintf(stderr,"(Unable to relocate old format field def. file.)\n");
			}

			sprintf(oldrelname,"%s%s%s",path,relname,LEAP_RELATION_EXT);	
			sprintf(newrelname,"%soldfmt/%s%s",path,relname,LEAP_RELATION_EXT);	
			if (rename(oldrelname,newrelname)!=0) {
				leap_fprintf(stderr,"(Unable to relocate old format relation)\n");
			}


			if (status_trace) {
				leap_fprintf(stdout,"Done!\n");
			}
		} else {
			fclose(nrf);
		}
	
		/* We've loaded the relation, so return the result */
		return(rel);
	}
}
コード例 #5
0
ファイル: attributes.c プロジェクト: sh19910711/leap.js
attribute attribute_findnext( attribute att,
				FILE **attribute_file,
				boolean newnode,
				boolean node_dispose) {
/* attribute_findnext
 * Locates the next attribute, and optionally creates
 * a new node for this. In addition, if the last node is
 * located, it is optional whether the node is disposed.
 * (This is all in order to populate a tuple structure
 */
	attribute natt;
	int oldno;

	if (leapver!=LEAP_UPGRADE) {
		raise_error( ERROR_OBSOLETED_CODE, NONFATAL,"");
	}
	/* Check that the end of file hasn't been reached */
	if (feof(*attribute_file)==0) {

		/* A new node is required */
		if (newnode==TRUE) {
			/* Create a ptr to an attribute structure */
			natt=(attribute_struct *) malloc(sizeof(attribute_struct));
			check_assign(natt,"attribute.findnext");	
		
			/* Populate the attribute from the file */	
			attribute_populate(natt,attribute_file);

			natt->no=att->no+1;
			/* Return our new node */	
			return(natt);
		} else {
			oldno=att->no;
			/* Populate the attribute */
			attribute_populate(att,attribute_file);
			/* Again, the likelyhood of an error should be handled */

			att->no=oldno+1;
			return(att);
		}
	} else {
		/* End of file encountered */

#ifdef FULL_DEBUG
	printf("Closing Attribute file");
#endif
		/* Close the attribute file */
		close_attribute_file(attribute_file); 

		if (node_dispose) {
			/* We want to deallocate the memory */
			attribute_dispose(&att);
		}
		/* TODO - Investigate this - This means that the
		 * attributes can become dereferenced if we don't
		 * want to dispose of the node...
		 * Maybe we want to RETURN NULL, but not dispose
		 * of the option...., but this is a parameter...
		 */
		att=NULL; 
		return(NULL);
	}	

}
コード例 #6
0
ファイル: variable.c プロジェクト: amritkrs/Linux-Shell-in-C
/*---IT USES LIST FOR KEEPING TOKENS---*/
int add_var(char exp[],int ret)		
{
	int i=0;
	float eval_ans;		//to store answer of evaluation expression
	char eval[20];
	char var_name[MAXNAME];		//VARIABLE NAME SHOULD NOT EXCEED MAXNAME.
	List infix_list;		//INFIX TOKENS
	List postfix_list;		//POSTFIX TOKENS
	
	// HEADER ASSUMED FOR LIST MANIPULATION
	infix_list = malloc(sizeof(struct node));	
	postfix_list = malloc(sizeof(struct node));

	if(infix_list == NULL || postfix_list == NULL)	//ERROR CHECK FOR MALLOC
	{
		printf("\nmemory not enough\n");
		exit(1000);
	}

	infix_list->Next = NULL;
	postfix_list->Next = NULL;

	if(check_assign(exp)==1)	//if '=' is there
	{
		/*store variable name*/
		i=0;
		int sp_val=0;	//to account for end of var_name and only spaces left
		char *tmp;	//to account for the knowledge of var_name end except for leftover spaces
		while(*exp==' ' || *exp=='\t')
			exp++;
		while(*exp!='=')
		{
			/*to remove all the spaces once the variable name ends i do this*/
			{
				tmp = exp;
				while(*tmp!='=')
				{
					if(*tmp!=' ')
						break;
					tmp++;
				}
				if(*tmp == '=')
				{
					sp_val=1;
					while(*exp!='=')
						exp++;
				}
			}

			if(sp_val != 1)
			{
			if(i==29)	/*the var_nmae is exceeding limit,TRUNCATE*/
			{
			 	while(*exp!='=')
					exp++;
				break;
			}
			
			else
			{

			var_name[i] = *exp;
			exp++;
			i++;
			}//else
			
			}//if(sp_val)
		}//while

		exp++;
		var_name[i]='\0';
	
		
		if(check_evaluate(exp)==1)
		{
			/*carry out evaluation*/
			Createlist(exp,infix_list);

			infix_to_postfix(infix_list,postfix_list);

			eval_ans = evaluate(postfix_list);
			
			add_lexicon(var_name,0,eval_ans,NULL);
		
		}//check_evaluate

		else
		{
			/*string value,just add it.*/
			add_lexicon(var_name,0,1,exp);
		}

	}//check_assign

	else
	{
		/*no variable to assign*/
		if(check_evaluate(exp)==1)
		{
			Createlist(exp,infix_list);
			infix_to_postfix(infix_list,postfix_list);
			eval_ans = evaluate(postfix_list);	
		
			/*ret = 0,implies that return ans on terminal,
			else it implies return the answer to program*/

			if(ret == 0)
			{
				printf("%f\n",eval_ans);
			}
			else
			{
				return eval_ans;
			}
		}
	}//else
	return ret;
}
コード例 #7
0
ファイル: variable.c プロジェクト: amritkrs/Linux-Shell-in-C
/*TO CHECK IF THIS FILE FUNCTION IS NEEDED*/
int check_var_eval(char a[])
{
	if(check_assign(a) ==1 || check_evaluate(a) == 1)
		return 1;
	return 0;
}