Exemplo n.º 1
0
void shell(void)
{
	printf("\n%s\n",eval_version);

	/* shell constants */
	const char _shell_arrow[] =">>";
	const char _shell_exit[]="exit";

	/* shell variables */
	char *cmd = NULL;
	char *str = NULL;
	char *err = NULL;
	void runline(const char *cmd, char *err);

	/* shell system */
	if((cmd=(char *)(malloc(1)))==NULL) allocerr();
	if((err=(char *)(malloc(1)))==NULL) allocerr();
	while(strcmp(cmd,_shell_exit))
	{
		strcpy(err,""); /* empty err string */
		/* allocate (max_str_length) bytes to str for input */
		stralloc: if((cp=(char *)(realloc(str,sizeof(char)*
		(max_str_length))))!=NULL) { str = cp; } else {
		/* if the system is very very low on memory */
		if(max_str_length>=255) { max_str_length -= 1;
		goto stralloc; } else { allocerr(); } }
		printf("\n%s",_shell_arrow);
		gets(str);
		/* re-allocate cmd for reuse */
		if((cp=(char *)(realloc(cmd,sizeof(char)*(strlen(str)+1))))!=NULL)
		{ cmd = cp; } else { allocerr(); }
		strcpy(cmd,str);
		/* destroy str to free (max_str_length) bytes of memory space */
		free(str); str = NULL;
		/* truncuate the string cmd */
		strtrm(cmd,' ','s');
		if(*cmd==0) continue;
		/* if cmd is empty then continue */
		if(!strlen(cmd)) continue;
		/* allocate variable to store error information */
		if((cp=(char *)(realloc(err,sizeof(char)*(strlen(cmd)+256))))!=NULL)
		{ err = cp; } else { allocerr(); }
		/* cmd should not be exit */
		if(strcmp(cmd,_shell_exit))
		/* now run line string cmd */
		runline(cmd,err);
		/* check for any errors */
		if(strlen(err))
		printf("\nError: %s\n",err);
	}
	/* while exiting, free used memeory */
	free(cmd); cmd = NULL;
	free(err); err = NULL;
}
Exemplo n.º 2
0
void runline(const char *cmd, char *err)
{
	// this function takes an instruction for execution.
	// it removes all comments and passes the statement to exec

	void exec(const char *str, char *err);
	char impurity[2] = {'\0','\0'};
	impurity[0] = purity_check(cmd);
	if(*cmd==';') /* if statement is a comment. */
	return;
	if(!impurity[0])  /* if cmd is pure */
	{
		strcpy(err,"");
		char *statement = NULL;
		if((statement=(char *)(malloc(sizeof(char)*
		(strlen(cmd)+1))))==NULL) allocerr(); *statement='\0';
		char *spointer = statement;
		int l = 0;  /* to store length of spointer */
		l = strlen(cmd);
		int i = 0;  /* loop counter */
		char qt=0;
		for(i=0;i<l;i++,cmd++,spointer++)
		{
			if(*cmd==34||*cmd==39)  /* char["] and char['] */
			{
				if(qt==0)
				qt = 1;  /* special symbol starts */
				else
				qt = 0;  /* special symbol ends */
			}
			if(qt==0)
			if(*cmd=='#')  /* remove comments from the statement */
			break;
			*spointer = *cmd;  /* transfer cmd to str */
		}
		*spointer='\0';  /* set termination point for string */
		strtrm(statement,' ','s');
		/* now run the statement */
		exec(statement,err);
		if(!strlen(err))    /* if eval was succesfull. */
		{
			free(statement);
			statement = NULL;
			return;
		}
		else    /* if eval was un-succesfull. */
		{
			free(statement);
			statement = NULL;
			return;
		}
	}
	else  /* if cmd is impure */
	{
		strcpy(err,"Character [");
		strcat(err,impurity);
		strcat(err,"] is not allowed.");
		return;
	}
}
Exemplo n.º 3
0
void shell(void)
{
	/* shell constants */
	const char _shell_arrow[] =">>";
	const char _shell_exit[]="exit";

	/* shell variables */
	char *cmd = NULL;
	char *str = NULL;
	void runline(const char *cmd, char *err);
	char err[KB]="";

	/* shell system */
	if((cmd=(char *)(malloc(1)))==NULL) allocerr();
	while(strcmp(cmd,_shell_exit))
	{
		strcpy(err,""); /* empty err string */
		/* allocate 1MB to str for input */
		if((cp=(char *)(realloc(str,sizeof(char)*(MB))))!=NULL)
		{ str = cp; } else { allocerr(); }
		printf("\n%s",_shell_arrow);
		gets(str);
		/* re-allocate cmd for reuse */
		if((cp=(char *)(realloc(cmd,sizeof(char)*(strlen(str)+1))))!=NULL)
		{ cmd = cp; } else { allocerr(); }
		strcpy(cmd,str);
		/* destroy str to free memory space */
		free(str); str = NULL;
		/* truncuate the string cmd */
		if(strtrims(cmd,' '))
		continue;
		if(!strlen(cmd))
		continue;
		/* cmd should not be exit */
		if(strcmp(cmd,_shell_exit))
		/* now evaluate string cmd */
		runline(cmd,err);
		/* check for any errors */
		if(strlen(err))
		printf("\nError: %s\n",err);
	}
	/* while exiting, free used memeory */
	free(cmd); cmd=NULL;
}
Exemplo n.º 4
0
char * valstr(const char *str)
{
	signed int i=0;
	i = atoi(str);
	char *vals = NULL;
	if((vals=(char *)(malloc(sizeof(char)*
	(strlen(str)+1))))==NULL) allocerr(); *vals='\0';
	itoa(i,vals,10);
	return vals;
}
Exemplo n.º 5
0
char * iftopf(const char *str)
{
	//  INFIX TO POSTFIX EXPRESSION TRANSLATOR:
	// -----------------------------------------
	// This function converts a postfix expression
	// to an infix expression if the conversion was 
	// successful, the evaluated expression is returned 
	// as a string, wheras if converson fails then a 
	// string containing a '#' character followed by 
	// an error statement is returned.

	char *exp = NULL; /* string containing postfix expression */
	if((exp=(char *)(malloc(sizeof(char)*
	(strlen(str)+256))))==NULL) allocerr(); *exp='\0';

	strcpy(exp,str);
	strcat(exp,"  ...should be changed to postfix");
	return exp;
}
Exemplo n.º 6
0
BOOL read_chat_cfg(scfg_t* cfg, char* error)
{
	char	str[MAX_PATH+1],fname[13];
	short	i,j,n;
	long	offset=0;
	FILE	*instream;

	strcpy(fname,"chat.cnf");
	sprintf(str,"%s%s",cfg->ctrl_dir,fname);
	if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
		sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
		return(FALSE);
	}

	/*********/
	/* Gurus */
	/*********/

	get_int(cfg->total_gurus,instream);

	if(cfg->total_gurus) {
		if((cfg->guru=(guru_t **)malloc(sizeof(guru_t *)*cfg->total_gurus))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(guru_t *)*cfg->total_gurus);
	} else
		cfg->guru=NULL;

	for(i=0;i<cfg->total_gurus;i++) {
		if(feof(instream)) break;
		if((cfg->guru[i]=(guru_t *)malloc(sizeof(guru_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(guru_t));
		memset(cfg->guru[i],0,sizeof(guru_t));

		get_str(cfg->guru[i]->name,instream);
		get_str(cfg->guru[i]->code,instream);

		get_str(cfg->guru[i]->arstr,instream);
		cfg->guru[i]->ar=ARSTR(cfg->guru[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_chans=i;


	/********************/
	/* Chat Action Sets */
	/********************/

	get_int(cfg->total_actsets,instream);

	if(cfg->total_actsets) {
		if((cfg->actset=(actset_t **)malloc(sizeof(actset_t *)*cfg->total_actsets))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(actset_t *)*cfg->total_actsets);
	} else
		cfg->actset=NULL;

	for(i=0;i<cfg->total_actsets;i++) {
		if(feof(instream)) break;
		if((cfg->actset[i]=(actset_t *)malloc(sizeof(actset_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(actset_t));
		get_str(cfg->actset[i]->name,instream);
	}
	cfg->total_actsets=i;


	/****************/
	/* Chat Actions */
	/****************/

	get_int(cfg->total_chatacts,instream);

	if(cfg->total_chatacts) {
		if((cfg->chatact=(chatact_t **)malloc(sizeof(chatact_t *)*cfg->total_chatacts))
			==NULL)
			return allocerr(instream,error,offset,fname,sizeof(chatact_t *)*cfg->total_chatacts);
	} else
		cfg->chatact=NULL;

	for(i=0;i<cfg->total_chatacts;i++) {
		if(feof(instream)) break;
		if((cfg->chatact[i]=(chatact_t *)malloc(sizeof(chatact_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(chatact_t));
		memset(cfg->chatact[i],0,sizeof(chatact_t));

		get_int(cfg->chatact[i]->actset,instream);
		get_str(cfg->chatact[i]->cmd,instream);
		get_str(cfg->chatact[i]->out,instream);
		for(j=0;j<8;j++)
			get_int(n,instream);
	}

	cfg->total_chatacts=i;


	/***************************/
	/* Multinode Chat Channels */
	/***************************/

	get_int(cfg->total_chans,instream);

	if(cfg->total_chans) {
		if((cfg->chan=(chan_t **)malloc(sizeof(chan_t *)*cfg->total_chans))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(chan_t *)*cfg->total_chans);
	} else
		cfg->chan=NULL;

	for(i=0;i<cfg->total_chans;i++) {
		if(feof(instream)) break;
		if((cfg->chan[i]=(chan_t *)malloc(sizeof(chan_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(chan_t));
		memset(cfg->chan[i],0,sizeof(chan_t));

		get_int(cfg->chan[i]->actset,instream);
		get_str(cfg->chan[i]->name,instream);

		get_str(cfg->chan[i]->code,instream);

		get_str(cfg->chan[i]->arstr,instream);
		cfg->chan[i]->ar=ARSTR(cfg->chan[i]->arstr,cfg);

		get_int(cfg->chan[i]->cost,instream);
		get_int(cfg->chan[i]->guru,instream);
		get_int(cfg->chan[i]->misc,instream);
		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_chans=i;


	/**************/
	/* Chat Pages */
	/**************/

	get_int(cfg->total_pages,instream);

	if(cfg->total_pages) {
		if((cfg->page=(page_t **)malloc(sizeof(page_t *)*cfg->total_pages))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(page_t *)*cfg->total_pages);
	} else
		cfg->page=NULL;

	for(i=0;i<cfg->total_pages;i++) {
		if(feof(instream)) break;
		if((cfg->page[i]=(page_t *)malloc(sizeof(page_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(page_t));
		memset(cfg->page[i],0,sizeof(page_t));

		get_str(cfg->page[i]->cmd,instream);

		get_str(cfg->page[i]->arstr,instream);
		cfg->page[i]->ar=ARSTR(cfg->page[i]->arstr,cfg);

		get_int(cfg->page[i]->misc,instream);
		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_pages=i;


	fclose(instream);
	return(TRUE);
}
Exemplo n.º 7
0
BOOL read_xtrn_cfg(scfg_t* cfg, char* error)
{
	char	str[MAX_PATH+1],fname[13],c;
	short	i,j,n;
	long	offset=0;
	FILE	*instream;

	strcpy(fname,"xtrn.cnf");
	sprintf(str,"%s%s",cfg->ctrl_dir,fname);
	if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
		sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
		return(FALSE); 
	}

	/*************/
	/* Swap list */
	/*************/

	get_int(cfg->total_swaps,instream);

	if(cfg->total_swaps) {
		if((cfg->swap=(swap_t **)malloc(sizeof(swap_t *)*cfg->total_swaps))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(swap_t *)*cfg->total_swaps); 
	} else
		cfg->swap=NULL;

	for(i=0;i<cfg->total_swaps;i++) {
		if(feof(instream)) break;
		if((cfg->swap[i]=(swap_t *)malloc(sizeof(swap_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(swap_t));
		get_str(cfg->swap[i]->cmd,instream); 
	}
	cfg->total_swaps=i;

	/********************/
	/* External Editors */
	/********************/

	get_int(cfg->total_xedits,instream);

	if(cfg->total_xedits) {
		if((cfg->xedit=(xedit_t **)malloc(sizeof(xedit_t *)*cfg->total_xedits))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xedit_t *)*cfg->total_xedits); 
	} else
		cfg->xedit=NULL;

	for(i=0;i<cfg->total_xedits;i++) {
		if(feof(instream)) break;
		if((cfg->xedit[i]=(xedit_t *)malloc(sizeof(xedit_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xedit_t));
		memset(cfg->xedit[i],0,sizeof(xedit_t));

		get_str(cfg->xedit[i]->name,instream);
		get_str(cfg->xedit[i]->code,instream);
		get_str(cfg->xedit[i]->lcmd,instream);
		get_str(cfg->xedit[i]->rcmd,instream);

		get_int(cfg->xedit[i]->misc,instream);
		get_str(cfg->xedit[i]->arstr,instream);
		cfg->xedit[i]->ar=ARSTR(cfg->xedit[i]->arstr,cfg);

		get_int(cfg->xedit[i]->type,instream);
		get_int(c,instream);
		for(j=0;j<7;j++)
			get_int(n,instream);
	}
	cfg->total_xedits=i;


	/*****************************/
	/* External Program Sections */
	/*****************************/

	get_int(cfg->total_xtrnsecs,instream);

	if(cfg->total_xtrnsecs) {
		if((cfg->xtrnsec=(xtrnsec_t **)malloc(sizeof(xtrnsec_t *)*cfg->total_xtrnsecs))
			==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xtrnsec_t *)*cfg->total_xtrnsecs);
	} else
		cfg->xtrnsec=NULL;

	for(i=0;i<cfg->total_xtrnsecs;i++) {
		if(feof(instream)) break;
		if((cfg->xtrnsec[i]=(xtrnsec_t *)malloc(sizeof(xtrnsec_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xtrnsec_t));
		memset(cfg->xtrnsec[i],0,sizeof(xtrnsec_t));

		get_str(cfg->xtrnsec[i]->name,instream);
		get_str(cfg->xtrnsec[i]->code,instream);
		get_str(cfg->xtrnsec[i]->arstr,instream);
		cfg->xtrnsec[i]->ar=ARSTR(cfg->xtrnsec[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_xtrnsecs=i;


	/*********************/
	/* External Programs */
	/*********************/

	get_int(cfg->total_xtrns,instream);

	if(cfg->total_xtrns) {
		if((cfg->xtrn=(xtrn_t **)malloc(sizeof(xtrn_t *)*cfg->total_xtrns))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xtrn_t *)*cfg->total_xtrns);
	} else
		cfg->xtrn=NULL;

	for(i=0;i<cfg->total_xtrns;i++) {
		if(feof(instream)) break;
		if((cfg->xtrn[i]=(xtrn_t *)malloc(sizeof(xtrn_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(xtrn_t));
		memset(cfg->xtrn[i],0,sizeof(xtrn_t));

		get_int(cfg->xtrn[i]->sec,instream);
		get_str(cfg->xtrn[i]->name,instream);
		get_str(cfg->xtrn[i]->code,instream);
		get_str(cfg->xtrn[i]->arstr,instream);
		get_str(cfg->xtrn[i]->run_arstr,instream);
		cfg->xtrn[i]->ar=ARSTR(cfg->xtrn[i]->arstr,cfg);
		cfg->xtrn[i]->run_ar=ARSTR(cfg->xtrn[i]->run_arstr,cfg);

		get_int(cfg->xtrn[i]->type,instream);
		get_int(cfg->xtrn[i]->misc,instream);
		get_int(cfg->xtrn[i]->event,instream);
		get_int(cfg->xtrn[i]->cost,instream);
		get_str(cfg->xtrn[i]->cmd,instream);
		get_str(cfg->xtrn[i]->clean,instream);
		get_str(cfg->xtrn[i]->path,instream);
		get_int(cfg->xtrn[i]->textra,instream);
		get_int(cfg->xtrn[i]->maxtime,instream);
		for(j=0;j<7;j++)
			get_int(n,instream);
	}
	cfg->total_xtrns=i;


	/****************/
	/* Timed Events */
	/****************/

	get_int(cfg->total_events,instream);

	if(cfg->total_events) {
		if((cfg->event=(event_t **)malloc(sizeof(event_t *)*cfg->total_events))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(event_t *)*cfg->total_events);
	} else
		cfg->event=NULL;

	for(i=0;i<cfg->total_events;i++) {
		if(feof(instream)) break;
		if((cfg->event[i]=(event_t *)malloc(sizeof(event_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(event_t));
		memset(cfg->event[i],0,sizeof(event_t));

		get_str(cfg->event[i]->code,instream);
		get_str(cfg->event[i]->cmd,instream);
		get_int(cfg->event[i]->days,instream);
		get_int(cfg->event[i]->time,instream);
		get_int(cfg->event[i]->node,instream);
		get_int(cfg->event[i]->misc,instream);
		get_str(cfg->event[i]->dir,instream);
		get_int(cfg->event[i]->freq,instream);
		get_int(cfg->event[i]->mdays,instream);

		for(j=0;j<5;j++)
			get_int(n,instream);
	}
	cfg->total_events=i;

	/********************************/
	/* Native (32-bit) Program list */
	/********************************/

	get_int(cfg->total_natvpgms,instream);

	if(cfg->total_natvpgms) {
		if((cfg->natvpgm=(natvpgm_t **)malloc(sizeof(natvpgm_t *)*cfg->total_natvpgms))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(natvpgm_t *)*cfg->total_natvpgms);
	} else
		cfg->natvpgm=NULL;

	for(i=0;i<cfg->total_natvpgms;i++) {
		if(feof(instream)) break;
		if((cfg->natvpgm[i]=(natvpgm_t *)malloc(sizeof(natvpgm_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(natvpgm_t));
		get_str(cfg->natvpgm[i]->name,instream);
		cfg->natvpgm[i]->misc=0; 
	}
	cfg->total_natvpgms=i;
	for(i=0;i<cfg->total_natvpgms;i++) {
		if(feof(instream)) break;
		get_int(cfg->natvpgm[i]->misc,instream);
	}

	/*******************/
	/* Global Hot Keys */
	/*******************/

	get_int(cfg->total_hotkeys,instream);

	if(cfg->total_hotkeys) {
		if((cfg->hotkey=(hotkey_t **)malloc(sizeof(hotkey_t *)*cfg->total_hotkeys))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(hotkey_t *)*cfg->total_hotkeys);
	} else
		cfg->hotkey=NULL;

	for(i=0;i<cfg->total_hotkeys;i++) {
		if(feof(instream)) break;
		if((cfg->hotkey[i]=(hotkey_t *)malloc(sizeof(hotkey_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(hotkey_t));
		memset(cfg->hotkey[i],0,sizeof(hotkey_t));

		get_int(cfg->hotkey[i]->key,instream);
		get_str(cfg->hotkey[i]->cmd,instream);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_hotkeys=i;

	/************************************/
	/* External Program-related Toggles */
	/************************************/
	get_int(cfg->xtrn_misc,instream);

	fclose(instream);
	return(TRUE);
}
Exemplo n.º 8
0
BOOL read_file_cfg(scfg_t* cfg, char* error)
{
	char	str[MAX_PATH+1],fname[13],c,cmd[LEN_CMD+1];
	short	i,j,n;
	long	offset=0,t;
	FILE	*instream;

	strcpy(fname,"file.cnf");
	sprintf(str,"%s%s",cfg->ctrl_dir,fname);
	if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
		sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
		return(FALSE); 
	}

	get_int(cfg->min_dspace,instream);
	get_int(cfg->max_batup,instream);

	get_int(cfg->max_batdn,instream);

	get_int(cfg->max_userxfer,instream);

	get_int(t,instream);	/* unused - was cdt_byte_value */
	get_int(cfg->cdt_up_pct,instream);
	get_int(cfg->cdt_dn_pct,instream);
	get_int(t,instream);	/* unused - was temp_ext */
	get_str(cmd,instream);	/* unused - was temp_cmd */
	get_int(cfg->leech_pct,instream);
	get_int(cfg->leech_sec,instream);
	get_int(cfg->file_misc,instream);

	for(i=0;i<30;i++)
		get_int(n,instream);

	/**************************/
	/* Extractable File Types */
	/**************************/

	get_int(cfg->total_fextrs,instream);

	if(cfg->total_fextrs) {
		if((cfg->fextr=(fextr_t **)malloc(sizeof(fextr_t *)*cfg->total_fextrs))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fextr_t*)*cfg->total_fextrs); 
	} else
		cfg->fextr=NULL;

	for(i=0; i<cfg->total_fextrs; i++) {
		if(feof(instream))
			break;
		if((cfg->fextr[i]=(fextr_t *)malloc(sizeof(fextr_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fextr_t));
		memset(cfg->fextr[i],0,sizeof(fextr_t));
		get_str(cfg->fextr[i]->ext,instream);
		get_str(cfg->fextr[i]->cmd,instream);
		get_str(cfg->fextr[i]->arstr,instream);
		cfg->fextr[i]->ar=ARSTR(cfg->fextr[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_fextrs=i;

	/***************************/
	/* Compressable File Types */
	/***************************/

	get_int(cfg->total_fcomps,instream);

	if(cfg->total_fcomps) {
		if((cfg->fcomp=(fcomp_t **)malloc(sizeof(fcomp_t *)*cfg->total_fcomps))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fcomp_t*)*cfg->total_fcomps); 
	} else
		cfg->fcomp=NULL;

	for(i=0; i<cfg->total_fcomps; i++) {
		if(feof(instream))
			break;
		if((cfg->fcomp[i]=(fcomp_t *)malloc(sizeof(fcomp_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fcomp_t));
		memset(cfg->fcomp[i],0,sizeof(fcomp_t));
		get_str(cfg->fcomp[i]->ext,instream);
		get_str(cfg->fcomp[i]->cmd,instream);
		get_str(cfg->fcomp[i]->arstr,instream);
		cfg->fcomp[i]->ar=ARSTR(cfg->fcomp[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_fcomps=i;

	/***********************/
	/* Viewable File Types */
	/***********************/

	get_int(cfg->total_fviews,instream);

	if(cfg->total_fviews) {
		if((cfg->fview=(fview_t **)malloc(sizeof(fview_t *)*cfg->total_fviews))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fview_t*)*cfg->total_fviews); 
	} else
		cfg->fview=NULL;

	for(i=0; i<cfg->total_fviews; i++) {
		if(feof(instream)) break;
		if((cfg->fview[i]=(fview_t *)malloc(sizeof(fview_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(fview_t));
		memset(cfg->fview[i],0,sizeof(fview_t));
		get_str(cfg->fview[i]->ext,instream);
		get_str(cfg->fview[i]->cmd,instream);
		get_str(cfg->fview[i]->arstr,instream);
		cfg->fview[i]->ar=ARSTR(cfg->fview[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_fviews=i;

	/***********************/
	/* Testable File Types */
	/***********************/

	get_int(cfg->total_ftests,instream);

	if(cfg->total_ftests) {
		if((cfg->ftest=(ftest_t **)malloc(sizeof(ftest_t *)*cfg->total_ftests))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(ftest_t*)*cfg->total_ftests); 
	} else
		cfg->ftest=NULL;

	for(i=0; i<cfg->total_ftests; i++) {
		if(feof(instream)) break;
		if((cfg->ftest[i]=(ftest_t *)malloc(sizeof(ftest_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(ftest_t));
		memset(cfg->ftest[i],0,sizeof(ftest_t));
		get_str(cfg->ftest[i]->ext,instream);
		get_str(cfg->ftest[i]->cmd,instream);
		get_str(cfg->ftest[i]->workstr,instream);
		get_str(cfg->ftest[i]->arstr,instream);
		cfg->ftest[i]->ar=ARSTR(cfg->ftest[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_ftests=i;

	/*******************/
	/* Download events */
	/*******************/

	get_int(cfg->total_dlevents,instream);

	if(cfg->total_dlevents) {
		if((cfg->dlevent=(dlevent_t **)malloc(sizeof(dlevent_t *)*cfg->total_dlevents))
			==NULL)
			return allocerr(instream,error,offset,fname,sizeof(dlevent_t*)*cfg->total_dlevents); 
	} else
		cfg->dlevent=NULL;

	for(i=0; i<cfg->total_dlevents; i++) {
		if(feof(instream)) break;
		if((cfg->dlevent[i]=(dlevent_t *)malloc(sizeof(dlevent_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(dlevent_t));
		memset(cfg->dlevent[i],0,sizeof(dlevent_t));
		get_str(cfg->dlevent[i]->ext,instream);
		get_str(cfg->dlevent[i]->cmd,instream);
		get_str(cfg->dlevent[i]->workstr,instream);
		get_str(cfg->dlevent[i]->arstr,instream);
		cfg->dlevent[i]->ar=ARSTR(cfg->dlevent[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_dlevents=i;


	/***************************/
	/* File Transfer Protocols */
	/***************************/

	get_int(cfg->total_prots,instream);

	if(cfg->total_prots) {
		if((cfg->prot=(prot_t **)malloc(sizeof(prot_t *)*cfg->total_prots))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(prot_t*)*cfg->total_prots); 
	} else
		cfg->prot=NULL;

	for(i=0;i<cfg->total_prots;i++) {
		if(feof(instream)) break;
		if((cfg->prot[i]=(prot_t *)malloc(sizeof(prot_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(prot_t));
		memset(cfg->prot[i],0,sizeof(prot_t));

		get_int(cfg->prot[i]->mnemonic,instream);
		get_str(cfg->prot[i]->name,instream);
		get_str(cfg->prot[i]->ulcmd,instream);
		get_str(cfg->prot[i]->dlcmd,instream);
		get_str(cfg->prot[i]->batulcmd,instream);
		get_str(cfg->prot[i]->batdlcmd,instream);
		get_str(cfg->prot[i]->blindcmd,instream);
		get_str(cfg->prot[i]->bicmd,instream);
		get_int(cfg->prot[i]->misc,instream);
		get_str(cfg->prot[i]->arstr,instream);
		cfg->prot[i]->ar=ARSTR(cfg->prot[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_prots=i;

	/************************/
	/* Alternate File Paths */
	/************************/

	get_int(cfg->altpaths,instream);

	if(cfg->altpaths) {
		if((cfg->altpath=(char **)malloc(sizeof(char *)*cfg->altpaths))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(char *)*cfg->altpaths); 
	} else
		cfg->altpath=NULL;

	for(i=0;i<cfg->altpaths;i++) {
		if(feof(instream)) break;
		fread(str,LEN_DIR+1,1,instream);
		offset+=LEN_DIR+1;
		backslash(str);
		j=LEN_DIR+1;
		if((cfg->altpath[i]=(char *)malloc(j))==NULL)
			return allocerr(instream,error,offset,fname,j);
		memset(cfg->altpath[i],0,j);
		strcpy(cfg->altpath[i],str);
		for(j=0;j<8;j++)
			get_int(n,instream);
		}

	cfg->altpaths=i;

	/******************/
	/* File Libraries */
	/******************/

	get_int(cfg->total_libs,instream);

	if(cfg->total_libs) {
		if((cfg->lib=(lib_t **)malloc(sizeof(lib_t *)*cfg->total_libs))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(lib_t *)*cfg->total_libs);
	} else
		cfg->lib=NULL;

	for(i=0;i<cfg->total_libs;i++) {
		if(feof(instream)) break;
		if((cfg->lib[i]=(lib_t *)malloc(sizeof(lib_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(lib_t));
		memset(cfg->lib[i],0,sizeof(lib_t));
		cfg->lib[i]->offline_dir=INVALID_DIR;

		get_str(cfg->lib[i]->lname,instream);
		get_str(cfg->lib[i]->sname,instream);

		get_str(cfg->lib[i]->arstr,instream);
		cfg->lib[i]->ar=ARSTR(cfg->lib[i]->arstr,cfg);

		get_str(cfg->lib[i]->parent_path,instream);

		get_str(cfg->lib[i]->code_prefix,instream);

		get_int(c,instream);

		for(j=0;j<3;j++)
			get_int(n,instream);	/* 0x0000 */

		for(j=0;j<16;j++)
			get_int(n,instream);	/* 0xffff */
	}
	cfg->total_libs=i;

	/********************/
	/* File Directories */
	/********************/

	cfg->sysop_dir=cfg->user_dir=cfg->upload_dir=INVALID_DIR;
	get_int(cfg->total_dirs,instream);

	if(cfg->total_dirs) {
		if((cfg->dir=(dir_t **)malloc(sizeof(dir_t *)*(cfg->total_dirs+1)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(dir_t *)*(cfg->total_dirs+1));
	} else
		cfg->dir=NULL;

	for(i=0;i<cfg->total_dirs;i++) {
		if(feof(instream)) break;
		if((cfg->dir[i]=(dir_t *)malloc(sizeof(dir_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(dir_t));
		memset(cfg->dir[i],0,sizeof(dir_t));

		get_int(cfg->dir[i]->lib,instream);
		get_str(cfg->dir[i]->lname,instream);
		get_str(cfg->dir[i]->sname,instream);

		if(!stricmp(cfg->dir[i]->sname,"SYSOP"))			/* Sysop upload directory */
			cfg->sysop_dir=i;
		else if(!stricmp(cfg->dir[i]->sname,"USER"))		/* User to User xfer dir */
			cfg->user_dir=i;
		else if(!stricmp(cfg->dir[i]->sname,"UPLOADS"))  /* Upload directory */
			cfg->upload_dir=i;
		else if(!stricmp(cfg->dir[i]->sname,"OFFLINE"))	/* Offline files dir */
			cfg->lib[cfg->dir[i]->lib]->offline_dir=i;

		get_str(cfg->dir[i]->code_suffix,instream);

		get_str(cfg->dir[i]->data_dir,instream);

		get_str(cfg->dir[i]->arstr,instream);
		get_str(cfg->dir[i]->ul_arstr,instream);
		get_str(cfg->dir[i]->dl_arstr,instream);
		get_str(cfg->dir[i]->op_arstr,instream);

		cfg->dir[i]->ar=ARSTR(cfg->dir[i]->arstr,cfg);
		cfg->dir[i]->ul_ar=ARSTR(cfg->dir[i]->ul_arstr,cfg);
		cfg->dir[i]->dl_ar=ARSTR(cfg->dir[i]->dl_arstr,cfg);
		cfg->dir[i]->op_ar=ARSTR(cfg->dir[i]->op_arstr,cfg);

		get_str(cfg->dir[i]->path,instream);

		get_str(cfg->dir[i]->upload_sem,instream);

		get_int(cfg->dir[i]->maxfiles,instream);
		if(cfg->dir[i]->maxfiles>MAX_FILES)
			cfg->dir[i]->maxfiles=MAX_FILES;
		get_str(cfg->dir[i]->exts,instream);
		get_int(cfg->dir[i]->misc,instream);
		get_int(cfg->dir[i]->seqdev,instream);
		get_int(cfg->dir[i]->sort,instream);
		get_str(cfg->dir[i]->ex_arstr,instream);
		cfg->dir[i]->ex_ar=ARSTR(cfg->dir[i]->ex_arstr,cfg);

		get_int(cfg->dir[i]->maxage,instream);
		get_int(cfg->dir[i]->up_pct,instream);
		get_int(cfg->dir[i]->dn_pct,instream);
		get_int(c,instream);
		for(j=0;j<24;j++)
			get_int(n,instream); 
	}

	cfg->total_dirs=i;

	/**********************/
	/* Text File Sections */
	/**********************/

	get_int(cfg->total_txtsecs,instream);


	if(cfg->total_txtsecs) {
		if((cfg->txtsec=(txtsec_t **)malloc(sizeof(txtsec_t *)*cfg->total_txtsecs))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(txtsec_t *)*cfg->total_txtsecs); 
	} else
		cfg->txtsec=NULL;

	for(i=0;i<cfg->total_txtsecs;i++) {
		if(feof(instream)) break;
		if((cfg->txtsec[i]=(txtsec_t *)malloc(sizeof(txtsec_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(txtsec_t));
		memset(cfg->txtsec[i],0,sizeof(txtsec_t));

		get_str(cfg->txtsec[i]->name,instream);
		get_str(cfg->txtsec[i]->code,instream);
		get_str(cfg->txtsec[i]->arstr,instream);
		cfg->txtsec[i]->ar=ARSTR(cfg->txtsec[i]->arstr,cfg);

		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_txtsecs=i;

	fclose(instream);
	return(TRUE);
}
Exemplo n.º 9
0
void evali(const char *str, char *err, int *eval)
{
	//   Mathematical Expression Evaluation Function
	//  -----------------------------------------------
	//   This functions solves mathematical equations.
	//   When a complex equation is passed via *str,
	//   the equation is broken into parts, and the
	//   simplest part is passed on recursively onto
	//   the function itself. This recurvise process is 
	//   repeated until the whole equation has been solved.
	//   Results of the evaluation are stored in int eval.

	if(!bcheck(str))
	{
		/* this is the core of eval where the calculations are done.
		at this level, the equation does not have any brackets. */

		const char symbols[]="^*/%+-&";
		const char se[]="Invalid Syntax";

		char *tmp = NULL;
		if((tmp=(char *)(malloc(sizeof(char)*
		(strlen(str)+1))))==NULL) allocerr(); *tmp='\0';
		/* check wether str has reached the absolute stage */
		if(prechar(tmp,str,symbols)==0)
		{
			printf("\n[simple]");
			if(!ncheck(str))
			{
				printf("\nequation solved!");
				*eval = strint(str);
				free(tmp);
				tmp = NULL;
				return;
			}
			else if(!id_check(str))
			{
				printf("\nit's a variable!");
				free(tmp);
				tmp = NULL;
				return;
			}
			else
			{
				strcpy(err,se);
				stradd(err,": ");
				stradd(err,str);
				free(tmp);
				tmp = NULL;
				return;
			}
		}
		else  /* there are symbols in str */
		{
			free(tmp);
			tmp = NULL;
		}

		/* now the real maths */
		printf("\n[complex]");
		char *pre = NULL; /* string preceding of operator */
		char *pos = NULL; /* string succeding the operator */
		/* now allocate the variables */
		if((pre=(char *)(malloc(sizeof(char)*
		(strlen(str)+1))))==NULL) allocerr(); *pre='\0';
		if((pos=(char *)(malloc(sizeof(char)*
		(strlen(str)+1))))==NULL) allocerr(); *pos='\0';
		char symbol = 0;
		if(prechar(pre,str,"^"))
		{ if(postchar(pos,str,"^"))
		symbol = '^'; }
		else if(prechar(pre,str,"*"))
		{ if(postchar(pos,str,"*"))
		symbol = '*'; }
		else if(prechar(pre,str,"/"))
		{ if(postchar(pos,str,"/"))
		symbol = '/'; }
		else if(prechar(pre,str,"%"))
		{ if(postchar(pos,str,"%"))
		symbol = '%'; }
		else if(prechar(pre,str,"+"))
		{ if(postchar(pos,str,"+"))
		symbol = '+'; }
		else if(prechar(pre,str,"-"))
		{ if(postchar(pos,str,"-"))
		symbol = '-'; }
		else if(prechar(pre,str,"&"))
		{ if(postchar(pos,str,"&"))
		symbol = '&'; }
		char *ax = NULL; /* value preceding of operator */
		char *bx = NULL; /* value succeding the operator */
		char *cx = NULL; /* value of ax and bx processed */
		/* now allocate the variables */
		if((ax=(char *)(malloc(sizeof(char)*
		(strlen(pre)+1))))==NULL) allocerr(); *ax='\0';
		if((bx=(char *)(malloc(sizeof(char)*
		(strlen(pos)+1))))==NULL) allocerr(); *bx='\0';
		if((cx=(char *)(malloc(sizeof(char)*
		(strlen(str)+1))))==NULL) allocerr(); *cx='\0';
		/* find out the contents of bx */
		char *ebx = NULL; /* temp string to build bx */
		if((ebx=(char *)(malloc(sizeof(char)*
		(strlen(pos)+1))))==NULL) allocerr(); *ebx='\0';
		strcpy(bx,pos);
		strcpy(ebx,bx);
		for(;;)  /* infinite loop */
		{
			if(!prechar(bx,ebx,symbols))
			{
				strcpy(bx,ebx);
				free(ebx);
				ebx = NULL;
				/* de-allocate ebx */
				break;
			}
			else /* here ebx is build */
			strcpy(ebx,bx);
		}
		/* find out the contents of ax */
		char *eax = NULL; /* temp string to build ax */
		if((eax=(char *)(malloc(sizeof(char)*
		(strlen(pre)+1))))==NULL) allocerr(); *eax='\0';
		strcpy(ax,pre);
		strcpy(eax,ax);
		for(;;)  /* infinite loop */
		{
			if(!postchar(ax,eax,symbols))
			{
				strcpy(ax,eax);
				free(eax);
				eax = NULL;
				/* de-allocate eax */
				break;
			}
			else /* here eax is build */
			strcpy(eax,ax);
		}
		/* variables to store (pre-ax) and (pre-bx) */
		char *prex = NULL;	/* string of (pre-ax) */
		char *posx = NULL;	/* string of (pos-ax) */
		/* now allocate prex and posx */
		if((prex=(char *)(malloc(sizeof(char)*
		(strlen(pre)+1))))==NULL) allocerr(); *prex='\0';
		if((posx=(char *)(malloc(sizeof(char)*
		(strlen(pos)+1))))==NULL) allocerr(); *posx='\0';
		/* find prex and posx */
		strlft(prex,pre,(strlen(pre)-strlen(ax)));
		strrht(posx,pos,(strlen(pos)-strlen(bx)));
		/* de-allocate pre & pos */
		printf("\nsym: %c",symbol);
		printf("\npre: %s",pre);
		printf("\npos: %s",pos);
		free(pre); pre = NULL;
		free(pos); pos = NULL;
		/* process ax and bx to find cx */
// *****************
		/* de-allocate ax & bx */
		printf("\n*ax: %s",ax);
		printf("\n*bx: %s",bx);
		printf("\n*cx: %s",cx);
		printf("\nprx: %s",prex);
		printf("\npox: %s",posx);
		free(ax); ax = NULL;
		free(bx); bx = NULL;
		/* variable to store one-step solved equation */
		char *ex = NULL;
		if((ex=(char *)(malloc(sizeof(char)*
		(strlen(str)+1))))==NULL) allocerr(); *ex='\0';
		/* find ex using cx in prex and posx */
// *****************
		/* now de-allocate cx, prex & posx */
		free(cx); cx = NULL;
		free(prex); cx = NULL;
		free(posx); cx = NULL;
		/* recurse ex on eval for next-step solving */
// *****************
		/* de-allocate ex & return */
		free(ex);
		ex = NULL;
		return;
	}
	else
	{
		if(!bcount(str))
		{
			printf("\nEquation has brackets.");
			return;
		}
		else
		{
			strcpy(err,"Illegal Equation, inequal number of brackets.");
			return;
		}
	}
}
Exemplo n.º 10
0
BOOL read_main_cfg(scfg_t* cfg, char* error)
{
	char	str[MAX_PATH+1],fname[13],c;
	short	i,j;
	int16_t	n;
	long	offset=0;
	FILE	*instream;

	strcpy(fname,"main.cnf");
	sprintf(str,"%s%s",cfg->ctrl_dir,fname);
	if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
		sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
		return(FALSE); 
	}

	get_str(cfg->sys_name,instream);
	get_str(cfg->sys_id,instream);
	get_str(cfg->sys_location,instream);
	get_str(cfg->sys_phonefmt,instream);
	get_str(cfg->sys_op,instream);
	get_str(cfg->sys_guru,instream);
	get_str(cfg->sys_pass,instream);
	get_int(cfg->sys_nodes,instream);

#if 0	/* removed Jan-10-2003: cfg->node_num may be old or uninitialized */
	if(!cfg->sys_nodes || cfg->sys_nodes<cfg->node_num || cfg->sys_nodes>MAX_NODES) {
		if(!cfg->sys_nodes)
			sprintf(error,"Total nodes on system must be non-zero.");
		else if(cfg->sys_nodes>MAX_NODES)
			sprintf(error,"Total nodes exceeds %u.",MAX_NODES);
		else
			sprintf(error,"Total nodes (%u) < node number in NODE.CNF (%u)"
				,cfg->sys_nodes,cfg->node_num);
		fclose(instream);
		return(FALSE); 
	}
#endif

	for(i=0;i<cfg->sys_nodes;i++) {
		get_str(cfg->node_path[i],instream);
#if defined(__unix__)
		strlwr(cfg->node_path[i]);
#endif
	}

	get_str(cfg->data_dir,instream); 			  /* data directory */
	get_str(cfg->exec_dir,instream); 			  /* exec directory */

	get_str(cfg->sys_logon,instream);
	get_str(cfg->sys_logout,instream);
	get_str(cfg->sys_daily,instream);
	get_int(cfg->sys_timezone,instream);
	get_int(cfg->sys_misc,instream);
	get_int(cfg->sys_lastnode,instream);
	get_int(cfg->sys_autonode,instream);
	get_int(cfg->uq,instream);
	get_int(cfg->sys_pwdays,instream);
	get_int(cfg->sys_deldays,instream);
	get_int(cfg->sys_exp_warn,instream); 	/* Days left till expiration warning */
	get_int(cfg->sys_autodel,instream);
	get_int(cfg->sys_def_stat,instream); 	/* default status line */

	get_str(cfg->sys_chat_arstr,instream);
	cfg->sys_chat_ar=ARSTR(cfg->sys_chat_arstr,cfg);

	get_int(cfg->cdt_min_value,instream);
	get_int(cfg->max_minutes,instream);
	get_int(cfg->cdt_per_dollar,instream);
	get_str(cfg->new_pass,instream);
	get_str(cfg->new_magic,instream);
	get_str(cfg->new_sif,instream);
	get_str(cfg->new_sof,instream);
	if(!cfg->new_sof[0])		/* if output not specified, use input file */
		strcpy(cfg->new_sof,cfg->new_sif);

	/*********************/
	/* New User Settings */
	/*********************/

	get_int(cfg->new_level,instream);
	get_int(cfg->new_flags1,instream);
	get_int(cfg->new_flags2,instream);
	get_int(cfg->new_flags3,instream);
	get_int(cfg->new_flags4,instream);
	get_int(cfg->new_exempt,instream);
	get_int(cfg->new_rest,instream);
	get_int(cfg->new_cdt,instream);
	get_int(cfg->new_min,instream);
	get_str(cfg->new_xedit,instream);
	get_int(cfg->new_expire,instream);
	get_int(cfg->new_shell,instream);
	get_int(cfg->new_misc,instream);
	get_int(cfg->new_prot,instream);
	if(cfg->new_prot<' ')
		cfg->new_prot=' ';
	get_int(cfg->new_install,instream);
	for(i=0;i<7;i++)
		get_int(n,instream);

	/*************************/
	/* Expired User Settings */
	/*************************/

	get_int(cfg->expired_level,instream);
	get_int(cfg->expired_flags1,instream);
	get_int(cfg->expired_flags2,instream);
	get_int(cfg->expired_flags3,instream);
	get_int(cfg->expired_flags4,instream);
	get_int(cfg->expired_exempt,instream);
	get_int(cfg->expired_rest,instream);

	get_str(cfg->logon_mod,instream);
	get_str(cfg->logoff_mod,instream);
	get_str(cfg->newuser_mod,instream);
	get_str(cfg->login_mod,instream);
	if(!cfg->login_mod[0]) SAFECOPY(cfg->login_mod,"login");
	get_str(cfg->logout_mod,instream);
	get_str(cfg->sync_mod,instream);
	get_str(cfg->expire_mod,instream);
	get_int(cfg->ctrlkey_passthru,instream);
	get_str(cfg->mods_dir,instream);
	get_str(cfg->logs_dir,instream);
	if(!cfg->logs_dir[0]) SAFECOPY(cfg->logs_dir,cfg->data_dir);

	get_int(c,instream);
	for(i=0;i<158;i++)					/* unused - initialized to NULL */
		get_int(n,instream);
	for(i=0;i<254;i++)					/* unused - initialized to 0xff */
		get_int(n,instream);

	get_int(cfg->user_backup_level,instream);
	if(cfg->user_backup_level==0xffff)
		cfg->user_backup_level=5;
	get_int(cfg->mail_backup_level,instream);
	if(cfg->mail_backup_level==0xffff)
		cfg->mail_backup_level=5;

	/*******************/
	/* Validation Sets */
	/*******************/

	for(i=0;i<10 && !feof(instream);i++) {
		get_int(cfg->val_level[i],instream);
		get_int(cfg->val_expire[i],instream);
		get_int(cfg->val_flags1[i],instream);
		get_int(cfg->val_flags2[i],instream);
		get_int(cfg->val_flags3[i],instream);
		get_int(cfg->val_flags4[i],instream);
		get_int(cfg->val_cdt[i],instream);
		get_int(cfg->val_exempt[i],instream);
		get_int(cfg->val_rest[i],instream);
		for(j=0;j<8;j++)
			get_int(n,instream);
	}

	/***************************/
	/* Security Level Settings */
	/***************************/

	for(i=0;i<100 && !feof(instream);i++) {
		get_int(cfg->level_timeperday[i],instream);
#if 0	/* removed May 06, 2002 */
		if(cfg->level_timeperday[i]>500)
			cfg->level_timeperday[i]=500;
#endif
		get_int(cfg->level_timepercall[i],instream);
#if 0	/* removed May 06, 2002 */
		if(cfg->level_timepercall[i]>500)
			cfg->level_timepercall[i]=500;
#endif
		get_int(cfg->level_callsperday[i],instream);
		get_int(cfg->level_freecdtperday[i],instream);
		get_int(cfg->level_linespermsg[i],instream);
		get_int(cfg->level_postsperday[i],instream);
		get_int(cfg->level_emailperday[i],instream);
		get_int(cfg->level_misc[i],instream);
		get_int(cfg->level_expireto[i],instream);
		get_int(c,instream);
		for(j=0;j<5;j++)
			get_int(n,instream); 
	}
	if(i!=100) {
		sprintf(error,"Insufficient User Level Information: "
			"%d user levels read, 100 needed.",i);
		fclose(instream);
		return(FALSE); 
	}

	get_int(cfg->total_shells,instream);
	#ifdef SBBS
	if(!cfg->total_shells) {
		sprintf(error,"At least one command shell must be configured.");
		fclose(instream);
		return(FALSE); 
	}
	#endif

	if(cfg->total_shells) {
		if((cfg->shell=(shell_t **)malloc(sizeof(shell_t *)*cfg->total_shells))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(shell_t *)*cfg->total_shells);
	} else
		cfg->shell=NULL;

	for(i=0;i<cfg->total_shells;i++) {
		if(feof(instream)) break;
		if((cfg->shell[i]=(shell_t *)malloc(sizeof(shell_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(shell_t));
		memset(cfg->shell[i],0,sizeof(shell_t));

		get_str(cfg->shell[i]->name,instream);
		get_str(cfg->shell[i]->code,instream);
		get_str(cfg->shell[i]->arstr,instream);
		cfg->shell[i]->ar=ARSTR(cfg->shell[i]->arstr,cfg);
		get_int(cfg->shell[i]->misc,instream);
		for(j=0;j<8;j++)
			get_int(n,instream);
	}
	cfg->total_shells=i;

	if(cfg->new_shell>=cfg->total_shells)
		cfg->new_shell=0;

	fclose(instream);
	return(TRUE);
}
Exemplo n.º 11
0
char * iftopf(const char *str)
{
	//  INFIX TO POSTFIX EXPRESSION TRANSLATOR:
	// -----------------------------------------
	// This function converts a postfix expression
	// to an infix expression if the conversion was 
	// successful, the evaluated expression is returned 
	// as a string, wheras if converson fails then a 
	// string containing a '#' character followed by 
	// an error statement is returned.

	/* string containing postfix expression */
	char *exp = NULL;
	if((exp=(char *)(malloc(sizeof(char)*
	(strlen(str)+256))))==NULL) allocerr(); *exp='\0';

	/* count opearators */
	unsigned long int strlen = 0;
	long int op_count = 0;
	for(strlen=0;str[strlen]!='\0';strlen++)
	if((str[strlen]=='(')||
		(str[strlen]=='^')||
		(str[strlen]=='*')||
		(str[strlen]=='/')||
		(str[strlen]=='+')||
		(str[strlen]=='-')||
		(str[strlen]=='&')||
		(str[strlen]==')'))
	op_count++;

	if(!op_count)
	{
		/* there are no operations */
		strcpy(exp,str);
		return exp;
	}

	/* operator precedence structure */
	char_int op_list[8] =
	{
		'(',5,  // bracket open
		'^',4,  // power
		'*',3,  // multiply
		'/',3,  // divide
		'+',2,  // add
		'-',2,  // subtract
		'&',1,  // conctatenate
		')',0   // end bracket
	};

	/* stack to contain operators */
	char *stack = NULL;
	if((stack=(char *)(malloc(sizeof(char)*
	(op_count+1))))==NULL) allocerr(); *stack='\0';

	/* build the postfix expression */
	signed long int opp;
	unsigned long int i = 0;
	unsigned long int elen = 0;
	for(;*str!='\0';str++)
	{
		/* find out precedence */
		for(opp=-1,i=0;i<8;i++)
		if(*str==op_list[i].c)
		opp = op_list[i].i;

		/* push, pop or print */
		switch(opp)
		{
			case -1:
				exp[elen++] = *str;
				break;
			default:
				break;
		}
	}
	exp[elen] ='\0';

	return exp;
}
Exemplo n.º 12
0
void evali(const char *str, char *err, int *eval)
{
	//  Mathematical Expression Evaluation Function (INT)
	// ---------------------------------------------------
	//  This functions solves mathematical expressions
	//	based on integer numbers. When a complex expression
	//	is passed via *str, the expression is broken
	//	into parts, and the simplest part in accordance
	//	with the BODMAS theorum is passed on recursively 
	//	onto the function itself. This recurvise process is 
	//  repeated until the whole expression has been solved.
	//  Results of the evaluation are stored in int *eval.

	if((*str=='\0')||(strlen(str)==0))
	{
		strcpy(err,"Void Expression");
		return;
	}
	int i = 0;  /* common loop counter */
	char bcheck = 0;
	for(i=0;*str!='\0';str++,i++)
	{
		/* check if there are brackets in an equation. */
		if(*str=='('||*str==')')
		/* bcheck is 0 if there are no brackets & vice-versa. */
		{ bcheck = 1;
		break; }
	}
	for(;i>0;i--)
	str--;  /* reverse str pointer to original position */

	if(!bcheck)
	{
		/* this is the core of eval where the calculations are done.
		at this level, the equation does not have any brackets. */

		const char symbols[]="^*/%+-&";
		const char se[]="Invalid Syntax";
		const char ue[]="Unknown Symbol";

		char *tmp = NULL;
		if((tmp=(char *)(malloc(sizeof(char)*
		(strlen(str)+1))))==NULL) allocerr(); *tmp='\0';
		/* check wether str has reached the absolute stage */
		if(prechar(tmp,str,symbols)==0)
		{
			 /* char to store num_check results */
			char ncheck = 0;
			ncheck = num_check(str);
			if(!ncheck)
			{
				/* str is a number (real or integer) */
				*eval = atoi(str);
				free(tmp);
				tmp = NULL;
				return;
			}
			else if(!id_check(str))
			{
				free(tmp);
				tmp = NULL;
//				char *vals = NULL;
//				vals = valstr(str);
//				*eval = atoi(vals);
//				free(vals);
//				vals = NULL;
				*eval = 0;
				return;
			}
			else
			{
				/* not a variable, number nor function; hence an error */
				strcpy(err,se);
				strcat(err,": ");
				strcat(err,str);
				free(tmp);
				tmp = NULL;
				return;
			}
		}
		else  /* there are symbols in str */
		{
			free(tmp);
			tmp = NULL;
		}

		/* now the real maths */
		char *pre = NULL; /* string preceding the operator */
		char *pos = NULL; /* string succeding the operator */
		/* now allocate the variables */
		if((pre=(char *)(malloc(sizeof(char)*
		(strlen(str)+1))))==NULL) allocerr(); *pre='\0';
		if((pos=(char *)(malloc(sizeof(char)*
		(strlen(str)+1))))==NULL) allocerr(); *pos='\0';
		char symbol = 0;
		if(prechar(pre,str,"^"))
		{ if(postchar(pos,str,"^"))
		symbol = '^'; }
		else if(prechar(pre,str,"*"))
		{ if(postchar(pos,str,"*"))
		symbol = '*'; }
		else if(prechar(pre,str,"/"))
		{ if(postchar(pos,str,"/"))
		symbol = '/'; }
		else if(prechar(pre,str,"%"))
		{ if(postchar(pos,str,"%"))
		symbol = '%'; }
		else if(prechar(pre,str,"+"))
		{ if(postchar(pos,str,"+"))
		symbol = '+'; }
		else if(prechar(pre,str,"-"))
		{ if(postchar(pos,str,"-"))
		symbol = '-'; }
		else if(prechar(pre,str,"&"))
		{ if(postchar(pos,str,"&"))
		symbol = '&'; }
		else {
		strcpy(err,ue);
		strcat(err,": ");
		*++err=symbol;
		*++err='\0';
		return; }
		char *ax = NULL; /* value preceding of operator */
		char *bx = NULL; /* value succeding the operator */
		char *cx = NULL; /* value of ax and bx processed */
		/* now allocate ax and bx */
		if((ax=(char *)(malloc(sizeof(char)*
		(strlen(pre)+1))))==NULL) allocerr(); *ax='\0';
		if((bx=(char *)(malloc(sizeof(char)*
		(strlen(pos)+1))))==NULL) allocerr(); *bx='\0';
		/* find out the contents of bx */
		char *ebx = NULL; /* temp string to build bx */
		if((ebx=(char *)(malloc(sizeof(char)*
		(strlen(pos)+1))))==NULL) allocerr(); *ebx='\0';
		strcpy(bx,pos);
		strcpy(ebx,bx);
		for(;;)  /* infinite loop */
		{
			if(!prechar(bx,ebx,symbols))
			{
				strcpy(bx,ebx);
				free(ebx);
				ebx = NULL;
				/* de-allocate ebx */
				break;
			}
			else /* here ebx is build */
			strcpy(ebx,bx);
		}
		/* find out the contents of ax */
		char *eax = NULL; /* temp string to build ax */
		if((eax=(char *)(malloc(sizeof(char)*
		(strlen(pre)+1))))==NULL) allocerr(); *eax='\0';
		strcpy(ax,pre);
		strcpy(eax,ax);
		for(;;)  /* infinite loop */
		{
			if(!postchar(ax,eax,symbols))
			{
				strcpy(ax,eax);
				free(eax);
				eax = NULL;
				/* de-allocate eax */
				break;
			}
			else /* here eax is build */
			strcpy(eax,ax);
		}
		/* variables to store (pre-ax) and (pre-bx) */
		char *prex = NULL;	/* string of (pre-ax) */
		char *posx = NULL;	/* string of (pos-ax) */
		/* now allocate prex and posx */
		if((prex=(char *)(malloc(sizeof(char)*
		(strlen(pre)+1))))==NULL) allocerr(); *prex='\0';
		if((posx=(char *)(malloc(sizeof(char)*
		(strlen(pos)+1))))==NULL) allocerr(); *posx='\0';
		/* find prex and posx */
		strlft(prex,pre,(strlen(pre)-strlen(ax)));
		strrht(posx,pos,(strlen(pos)-strlen(bx)));
		/* de-allocate pre & pos */
		free(pre); pre = NULL;
		free(pos); pos = NULL;
		/* process ax and bx to find cx */
//		printf("\nax=%s",ax);
//		printf("\nbx=%s",bx);
		int evala=0;
		int evalb=0;
		int evalc=0;
		if(num_check(ax))
		{
//			tmp = valstr(ax);
//			if((cp=(char *)(realloc(ax,sizeof(char)*
//			(strlen(tmp)+1))))!=NULL) { ax = cp; }
//			else { allocerr(); }
//			strcpy(ax,tmp);
//			free(tmp);
//			tmp = NULL;
			strcpy(ax,"");
		}
		if(num_check(bx))
		{
//			tmp = valstr(bx);
//			if((cp=(char *)(realloc(bx,sizeof(char)*
//			(strlen(tmp)+1))))!=NULL) { bx = cp; }
//			else { allocerr(); }
//			strcpy(bx,tmp);
//			free(tmp);
//			tmp = NULL;
			strcpy(bx,"");
		}
		evala = atoi(ax);
		evalb = atoi(bx);
		switch(symbol)
		{
		case '^':	/* power */
			evalc = (int)(pow(evala,evalb));
			break;
		case '*':	/* multiplication */
			evalc = evala * evalb;
			break;
		case '/':	/* division */
			evalc = evala / evalb;
			break;
		case '%':	/* modulus */
			evalc = evala % evalb;
			break;
		case '+':	/* addition */
			evalc = evala + evalb;
			break;
		case '-':	/* subtraction */
			evalc = evala - evalb;
			break;
		case '&':	/* concatenation */
			if((cp=(char *)(realloc(cx,sizeof(char)*
			(strlen(ax)+strlen(bx)+1))))!=NULL)
			{ cx = cp; } else { allocerr(); }
			strcpy(cx,ax);
			strcat(cx,bx);
			evalc = atoi(cx);
			break;
		default:
			strcpy(err,ue);
			strcat(err,": ");
			*++err=symbol;
			*++err='\0';
			return;
		}
		/* find the length of evalc */
		int cxlen = 8;
		if(evalc<0)
		{ cxlen = 16; }
		else if(evalc==0)
		{ cxlen = 2; }
		else {
			cxlen = 0;
			int ctmp = evalc;
			while(ctmp>0) { ctmp/=10; cxlen++; }
		}
		/* allocate cx having the length of evalc */
		if((cx=(char *)(malloc(sizeof(char)*
		((cxlen)+1))))==NULL) allocerr(); *cx='\0';
		itoa(evalc,cx,10);
//		printf("\ncx=%s\n",cx);
		/* de-allocate ax & bx */
		free(ax); ax = NULL;
		free(bx); bx = NULL;
		/* variable to store one-step solved equation */
		char *ex = NULL;
		if((ex=(char *)(malloc(sizeof(char)*
		(strlen(prex)+strlen(cx)+strlen(posx)+1))))==NULL)
		allocerr(); *ex='\0';
		/* find ex using cx in prex and posx */
		strcpy(ex,prex);
		strcat(ex,cx);
		strcat(ex,posx);
		/* now de-allocate cx, prex & posx */
		free(cx); cx = NULL;
		free(prex); prex = NULL;
		free(posx); posx = NULL;
		/* recurse ex on eval for next-step solving */
		int integer=0;
		evali(ex,err,&integer);
		*eval = integer;
		/* de-allocate ex & return */
		free(ex);
		ex = NULL;
		return;
	}
	else
	{
		// check if an equation is correct in no. of brackets.
		unsigned int brackets[2]={0,0};
		for(i=0;*str!='\0';str++,i++)
		{
			/* find the no. of brackets */
			if(*str=='(')
			brackets[0]+=1;
			if(*str==')')
			brackets[1]+=1;
		}
		for(;i>0;i--)
		str--;  /* reverse str pointer to original position */

		if(brackets[0]==brackets[1])
		{
			char *pres = NULL;
			char *poss = NULL;
			char *mids = NULL;
			char *midx = NULL;
			char *newx = NULL;
			/* now allocate the above string */
			if((pres=(char *)(malloc(sizeof(char)*
			(strlen(str)+1))))==NULL) allocerr(); *pres='\0';
			if((poss=(char *)(malloc(sizeof(char)*
			(strlen(str)+1))))==NULL) allocerr(); *poss='\0';
			if((mids=(char *)(malloc(sizeof(char)*
			(strlen(str)+1))))==NULL) allocerr(); *mids='\0';
			if((midx=(char *)(malloc(sizeof(char)*
			(strlen(str)+1))))==NULL) allocerr(); *midx='\0';
			if((newx=(char *)(malloc(sizeof(char)*
			(strlen(str)+1))))==NULL) allocerr(); *newx='\0';
			/* now split the string */
			unsigned long int cs = 0;
			unsigned long int bcount = 0;
			/* make pres */
			for(cs=0;*str!='\0';cs++)
			{
				if(*str=='(')
				bcount++;
				if(bcount==brackets[0])
				break;
				*pres++ = *str++;
			}
			for(*pres = '\0';cs>0;cs--)
			pres--;
			/* make mids */
			for(cs=0,str++;((*str!=')')&&(*str!='\0'));cs++)
			*mids++ = *str++;
			for(*mids = '\0';cs>0;cs--)
			mids--;
			/* make poss */
			for(cs=0,str++;*str!='\0';cs++)
			*poss++ = *str++;
			for(*poss = '\0';cs>0;cs--)
			poss--;
			/* ok, now evaluate */
			int integer = 0;
			evali(mids,err,&integer);
			itoa(integer,midx,10);
			strcpy(newx,pres);
			strcat(newx,midx);
			strcat(newx,poss);
			evali(newx,err,&integer);
			*eval = integer;
			return;
		}
		else
		{
			strcpy(err,"Invalid Equation, inequal number of brackets.");
			return;
		}
	}
}
Exemplo n.º 13
0
void * evals(const char *str, const char data_type)
{
	//  EXPRESSION EVALUATION FUNCTION
	// --------------------------------
	// This function evaluates a mathematical
	// expresssion contained in str, and returns
	// the results after allocating it in memory.
	// The data type returned is determined by 
    // the value of argument char data_type:
	// if 'i' -> long             <- (int)
	// if 'n' -> short            <- (int-)
	// if 'c' -> char             <- (chr)
	// if 'd' -> double           <- (real)
	// if 'f' -> float            <- (real-)
	// if 'j' -> unsigned int     <- (int+)
	// if 'm' -> unsigned short   <- (int-+)
	// if 'a' -> unsigned char    <- (chr+)
	// if 's' -> string (char*)   <- (str)
	// if 'b' -> boolen           <- (bit)
	// if anything else, a null pointer is returned.
	evali_count += 1;

	/* convert expression to postfix form */
	char * iftopf(const char *str);
	char *exp = NULL; /* string to contain postfix expression */
	exp = iftopf(str);
	printf("infix: [%s]\npsfix: [%s]\n",str,exp);

	/* possible return data types */
	long *i = NULL;            // <- (int)
	short *n = NULL;           // <- (int-)
	char *c = NULL;            // <- (chr)
	double *d = NULL;          // <- (real)
	float *f = NULL;           // <- (real-)
	unsigned long *j = NULL;   // <- (int+)
	unsigned short *m = NULL;  // <- (int-+)
	unsigned char *a = NULL;   // <- (chr+)

	/* allocate memory to requested data type */
	switch(data_type)
	{
	case 'i':
		if((i=(long *)(malloc(sizeof(long
		))))==NULL) allocerr(); *i = 0;
		break;
	case 'n':
		if((n=(short *)(malloc(sizeof(short
		))))==NULL) allocerr(); *n = 0;
		break;
	case 'c':
		if((c=(char *)(malloc(sizeof(char
		))))==NULL) allocerr(); *c = 0;
		break;
	case 'd':
		if((d=(double *)(malloc(sizeof(double
		))))==NULL) allocerr(); *d = 0;
		break;
	case 'f':
		if((f=(float *)(malloc(sizeof(float
		))))==NULL) allocerr(); *f = 0;
		break;
	case 'j':
		if((j=(unsigned long *)
		(malloc(sizeof(unsigned long
		))))==NULL) allocerr(); *j = 0;
		break;
	case 'm':
		if((m=(unsigned short *)
		(malloc(sizeof(unsigned short
		))))==NULL) allocerr(); *m = 0;
		break;
	case 'a':
		if((a=(unsigned char *)
		(malloc(sizeof(unsigned char
		))))==NULL) allocerr(); *a = 0;
		break;
	}

	/* expression evaluation */
	*i=atoi(str);

	/* free mem. & return value */
	free(exp);
	exp = NULL;
	return i;
}
Exemplo n.º 14
0
BOOL read_msgs_cfg(scfg_t* cfg, char* error)
{
	char	str[MAX_PATH+1],fname[13],c;
	short	i,j;
	int16_t	n,k;
	long	offset=0;
	FILE	*instream;

	strcpy(fname,"msgs.cnf");
	sprintf(str,"%s%s",cfg->ctrl_dir,fname);
	if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
		sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
		return(FALSE);
	}

	/*************************/
	/* General Message Stuff */
	/*************************/

	get_int(cfg->max_qwkmsgs,instream);
	get_int(cfg->mail_maxcrcs,instream);
	get_int(cfg->mail_maxage,instream);
	get_str(cfg->preqwk_arstr,instream);
	cfg->preqwk_ar=ARSTR(cfg->preqwk_arstr,cfg);

	get_int(cfg->smb_retry_time,instream);	 /* odd byte */
	if(!cfg->smb_retry_time)
		cfg->smb_retry_time=30;
	get_int(cfg->max_qwkmsgage, instream);
	for(i=0;i<233;i++)	/* NULL */
		get_int(n,instream);
	get_int(cfg->msg_misc,instream);
	for(i=0;i<255;i++)	/* 0xff */
		get_int(n,instream);

	/******************/
	/* Message Groups */
	/******************/

	get_int(cfg->total_grps,instream);

	if(cfg->total_grps) {
		if((cfg->grp=(grp_t **)malloc(sizeof(grp_t *)*cfg->total_grps))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(grp_t *)*cfg->total_grps);
	} else
		cfg->grp=NULL;

	for(i=0;i<cfg->total_grps;i++) {

		if(feof(instream)) break;
		if((cfg->grp[i]=(grp_t *)malloc(sizeof(grp_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(grp_t));
		memset(cfg->grp[i],0,sizeof(grp_t));

		get_str(cfg->grp[i]->lname,instream);
		get_str(cfg->grp[i]->sname,instream);

		get_str(cfg->grp[i]->arstr,instream);
		cfg->grp[i]->ar=ARSTR(cfg->grp[i]->arstr,cfg);

		get_str(cfg->grp[i]->code_prefix,instream);

		get_int(c,instream);
		for(j=0;j<43;j++)
			get_int(n,instream);
		}
	cfg->total_grps=i;

	/**********************/
	/* Message Sub-boards */
	/**********************/

	get_int(cfg->total_subs,instream);

	if(cfg->total_subs) {
		if((cfg->sub=(sub_t **)malloc(sizeof(sub_t *)*cfg->total_subs))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(sub_t *)*cfg->total_subs);
	} else
		cfg->sub=NULL;

	for(i=0;i<cfg->total_subs;i++) {
		if(feof(instream)) break;
		if((cfg->sub[i]=(sub_t *)malloc(sizeof(sub_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(sub_t));
		memset(cfg->sub[i],0,sizeof(sub_t));

		get_int(cfg->sub[i]->grp,instream);
		get_str(cfg->sub[i]->lname,instream);
		get_str(cfg->sub[i]->sname,instream);
		get_str(cfg->sub[i]->qwkname,instream);
		get_str(cfg->sub[i]->code_suffix,instream);
		get_str(cfg->sub[i]->data_dir,instream);

#ifdef SBBS
		if(cfg->sub[i]->grp >= cfg->total_grps) {
			sprintf(error,"offset %ld in %s: invalid group number (%u) for sub-board: %s"
				,offset,fname
				,cfg->sub[i]->grp
				,cfg->sub[i]->code_suffix);
			fclose(instream);
			return(FALSE); 
		}
#endif

		get_str(cfg->sub[i]->arstr,instream);
		get_str(cfg->sub[i]->read_arstr,instream);
		get_str(cfg->sub[i]->post_arstr,instream);
		get_str(cfg->sub[i]->op_arstr,instream);

		cfg->sub[i]->ar=ARSTR(cfg->sub[i]->arstr,cfg);
		cfg->sub[i]->read_ar=ARSTR(cfg->sub[i]->read_arstr,cfg);
		cfg->sub[i]->post_ar=ARSTR(cfg->sub[i]->post_arstr,cfg);
		cfg->sub[i]->op_ar=ARSTR(cfg->sub[i]->op_arstr,cfg);

		get_int(cfg->sub[i]->misc,instream);

		get_str(cfg->sub[i]->tagline,instream);
		get_str(cfg->sub[i]->origline,instream);
		get_str(cfg->sub[i]->post_sem,instream);

#if 0
		fread(str,1,LEN_DIR+1,instream);				/* skip EchoMail path */
		offset+=LEN_DIR+1;
#else
		get_str(cfg->sub[i]->newsgroup,instream);
#endif

		get_int(cfg->sub[i]->faddr,instream);			/* FidoNet address */
		get_int(cfg->sub[i]->maxmsgs,instream);
		get_int(cfg->sub[i]->maxcrcs,instream);
		get_int(cfg->sub[i]->maxage,instream);
		get_int(cfg->sub[i]->ptridx,instream);
#ifdef SBBS
		for(j=0;j<i;j++)
			if(cfg->sub[i]->ptridx==cfg->sub[j]->ptridx) {
				sprintf(error,"offset %ld in %s: Duplicate pointer index for subs %s and %s"
					,offset,fname
					,cfg->sub[i]->code_suffix,cfg->sub[j]->code_suffix);
				fclose(instream);
				return(FALSE); 
			}
#endif

		get_str(cfg->sub[i]->mod_arstr,instream);
		cfg->sub[i]->mod_ar=ARSTR(cfg->sub[i]->mod_arstr,cfg);

		get_int(cfg->sub[i]->qwkconf,instream);
		get_int(c,instream);
		for(j=0;j<26;j++)
			get_int(n,instream);
		}
	cfg->total_subs=i;

	/***********/
	/* FidoNet */
	/***********/

	get_int(cfg->total_faddrs,instream);

	if(cfg->total_faddrs) {
		if((cfg->faddr=(faddr_t *)malloc(sizeof(faddr_t)*cfg->total_faddrs))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(faddr_t)*cfg->total_faddrs);
	} else
		cfg->faddr=NULL;

	for(i=0;i<cfg->total_faddrs;i++)
		get_int(cfg->faddr[i],instream);

	get_str(cfg->origline,instream);
	get_str(cfg->netmail_sem,instream);
	get_str(cfg->echomail_sem,instream);
	get_str(cfg->netmail_dir,instream);
	get_str(cfg->echomail_dir,instream);
	get_str(cfg->fidofile_dir,instream);
	get_int(cfg->netmail_misc,instream);
	get_int(cfg->netmail_cost,instream);
	get_int(cfg->dflt_faddr,instream);
	for(i=0;i<28;i++)
		get_int(n,instream);

	/**********/
	/* QWKnet */
	/**********/

	get_str(cfg->qnet_tagline,instream);

	get_int(cfg->total_qhubs,instream);

	if(cfg->total_qhubs) {
		if((cfg->qhub=(qhub_t **)malloc(sizeof(qhub_t *)*cfg->total_qhubs))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(qhub_t*)*cfg->total_qhubs);
	} else
		cfg->qhub=NULL;

	for(i=0;i<cfg->total_qhubs;i++) {
		if(feof(instream)) break;
		if((cfg->qhub[i]=(qhub_t *)malloc(sizeof(qhub_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(qhub_t));
		memset(cfg->qhub[i],0,sizeof(qhub_t));

		get_str(cfg->qhub[i]->id,instream);
		get_int(cfg->qhub[i]->time,instream);
		get_int(cfg->qhub[i]->freq,instream);
		get_int(cfg->qhub[i]->days,instream);
		get_int(cfg->qhub[i]->node,instream);
		get_str(cfg->qhub[i]->call,instream);
		get_str(cfg->qhub[i]->pack,instream);
		get_str(cfg->qhub[i]->unpack,instream);
		get_int(k,instream);

		if(k) {
			if((cfg->qhub[i]->sub=(ulong *)malloc(sizeof(ulong)*k))==NULL)
				return allocerr(instream,error,offset,fname,sizeof(ulong)*k);
			if((cfg->qhub[i]->conf=(ushort *)malloc(sizeof(ushort)*k))==NULL)
				return allocerr(instream,error,offset,fname,sizeof(ushort)*k);
			if((cfg->qhub[i]->mode=(char *)malloc(sizeof(char)*k))==NULL)
				return allocerr(instream,error,offset,fname,sizeof(uchar)*k);
		}

		for(j=0;j<k;j++) {
			uint16_t	subnum;
			if(feof(instream)) break;
			get_int(cfg->qhub[i]->conf[cfg->qhub[i]->subs],instream);
			get_int(subnum,instream);
			cfg->qhub[i]->sub[cfg->qhub[i]->subs]=subnum;
			get_int(cfg->qhub[i]->mode[cfg->qhub[i]->subs],instream);
			if(cfg->qhub[i]->sub[cfg->qhub[i]->subs]<cfg->total_subs)
				cfg->sub[cfg->qhub[i]->sub[cfg->qhub[i]->subs]]->misc|=SUB_QNET;
			else
				continue;
			if(cfg->qhub[i]->sub[cfg->qhub[i]->subs]!=INVALID_SUB)
				cfg->qhub[i]->subs++; }
		for(j=0;j<32;j++)
			get_int(n,instream);
	}

	cfg->total_qhubs=i;

	for(j=0;j<32;j++)
		get_int(n,instream);

	/************/
	/* PostLink */
	/************/

	fread(str,11,1,instream);		/* Unused - used to be Site Name */
	offset+=11;
	get_int(cfg->sys_psnum,instream);	/* Site Number */
	get_int(cfg->total_phubs,instream);

	if(cfg->total_phubs) {
		if((cfg->phub=(phub_t **)malloc(sizeof(phub_t *)*cfg->total_phubs))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(phub_t*)*cfg->total_phubs);
	} else
		cfg->phub=NULL;

	for(i=0;i<cfg->total_phubs;i++) {
		if(feof(instream)) break;
		if((cfg->phub[i]=(phub_t *)malloc(sizeof(phub_t)))==NULL)
			return allocerr(instream,error,offset,fname,sizeof(phub_t));
		memset(cfg->phub[i],0,sizeof(phub_t));

		get_str(cfg->phub[i]->name,instream);
		get_int(cfg->phub[i]->time,instream);
		get_int(cfg->phub[i]->freq,instream);
		get_int(cfg->phub[i]->days,instream);
		get_int(cfg->phub[i]->node,instream);
		get_str(cfg->phub[i]->call,instream);
		for(j=0;j<32;j++)
			get_int(n,instream);
	}

	cfg->total_phubs=i;

	get_str(cfg->sys_psname,instream);	/* Site Name */

	for(j=0;j<32;j++)
		get_int(n,instream);

	/************/
	/* Internet */
	/************/

	get_str(cfg->sys_inetaddr,instream); /* Internet address */
	get_str(cfg->inetmail_sem,instream);
	get_int(cfg->inetmail_misc,instream);
	get_int(cfg->inetmail_cost,instream);
	get_str(cfg->smtpmail_sem,instream);

	fclose(instream);
	return(TRUE);
}
Exemplo n.º 15
0
void exec(const char *str, char *err)
{
	// this function executes a given instruction.
	// all important functions are done from here.

	int eval(const char *str);
	void * evals(const char *str, const char data_type);
	strcpy(err,"");  /* empty error container string */
	char *exp = NULL; /* string containing evaluation expression */
	char *asgn = NULL;  /* string containing assignment variable name */
	char data_type = '\0'; /* data type of variable to evaluate */

	/* assignment analysis & error handling */
	if((asgn=(char *)(malloc(sizeof(char)*
	(strlen(str)+1))))==NULL) allocerr(); *asgn='\0';
	if(prechar(asgn,str,"=")=='=') /* check for = operator */
	{
		/* ok, it is a variable assignment */
		strtrm(asgn,' ','S');

		if((*asgn==0)||(strlen(asgn)==0))
		{
			/* error: assignment string is empty */
			strcpy(err,"Assignment variable is not specified.");
			free(asgn);
			return;
		}
		else  /* assignment string is NOT empty */
		{
			char isid[2] = {'\0','\0'};
			/* check identifier validity*/
			isid[0] = id_check(asgn);
			if(isid[0]!=0)  /* error: is not an identifier */
			{
				if(isid[0]==1)  /* error: var name starts with a number */
				{
					strcpy(err,"Variable name cannot start with a number.");
				}
				else if(isid[0]==32)  /* error: var name contains spaces */
				{
					strcpy(err,"Variable name cannot contain spaces.");
				}
				else  /* error: var name has illegal chars*/
				{
					strcpy(err,"Variable name cannot contain [");
					strcat(err,isid);
					strcat(err,"] character.");
				}
				free(asgn);
				return;
			}
			else  /* success: assignment string is valid */
			{
				/* allocate string exp */
				if((exp=(char *)(malloc(sizeof(char)*
				(strlen(str)+1))))==NULL) allocerr(); *exp='\0';
				/* now split the equation to get the exp. */
				postchar(exp,str,"=");
				strtrm(exp,' ','S');
				// find out the data type of the assignment
				// variable & store it in char data_type
			} 

		}
	}
	else	/* there is no assigment involved */
	{
		/* allocate string exp */
		if((exp=(char *)(malloc(sizeof(char)*
		(strlen(str)+1))))==NULL) allocerr(); *exp='\0';
		strcpy(exp,str);
		strtrm(exp,' ','S');
		/* de-allocate asgn */
		free(asgn);
		asgn = NULL;
	}

	/* variable assignment */
	if(asgn!=NULL)
	{
		/* possible variable data types */
		long *i = NULL;            // <- (int)
		short *n = NULL;           // <- (int-)
		char *c = NULL;            // <- (chr)
		double *d = NULL;          // <- (real)
		float *f = NULL;           // <- (real-)
		unsigned long *j = NULL;   // <- (int+)
		unsigned short *m = NULL;  // <- (int-+)
		unsigned char *a = NULL;   // <- (chr+)

		switch(data_type)
		{
		case 'i':
			break;
		default:
			strcpy(err,"Fatal Data Transfer Error on [");
			strcat(err,asgn);
			strcat(err,"] variable.");
		}

		/* de-allocate memory of data type */
		switch(data_type)
		{
		case 'i':
			free(i);
			i = NULL;
			break;
		case 'n':
			free(n);
			n = NULL;
			break;
		case 'c':
			free(c);
			c = NULL;
			break;
		case 'd':
			free(d);
			d = NULL;
			break;
		case 'f':
			free(f);
			f = NULL;
			break;
		case 'j':
			free(j);
			j = NULL;
			break;
		case 'm':
			free(m);
			m = NULL;
			break;
		case 'a':
			free(a);
			a = NULL;
			break;
		}
		/* de-allocate asgn */
		free(asgn);
		asgn = NULL;
	}
	else	/* no assigment */
	{
   		// if there is no assignment then integer is considered
		// to be the default assignment data type for evaluation.
		puts("");

		int _i=0;
		_i = eval(exp);
		printf("eval: %d\n",_i);

		data_type = 'i';
		long *i = NULL;
		i=(long *)(evals(exp,data_type));
		printf("evals: %ld\n",*i);
		free(i);
		i = NULL;

		void evali(const char *str, char *err, int *eval);
		evali(exp,err,&_i);
		printf("evali: %d\n",_i);
		printf("evali was invoked %d time(s).\n",evali_count);
		evali_count = 0;
	}
	free(exp);
	exp = NULL;
}
Exemplo n.º 16
0
BOOL read_node_cfg(scfg_t* cfg, char* error)
{
	char	c,str[MAX_PATH+1],fname[13];
	int 	i;
	int16_t	n;
	long	offset=0;
	FILE	*instream;

	strcpy(fname,"node.cnf");
	sprintf(str,"%s%s",cfg->node_dir,fname);
	if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
		sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
		return(FALSE); 
	}

	get_int(cfg->node_num,instream);
	if(!cfg->node_num) {
		sprintf(error,"offset %ld in %s, Node number must be non-zero"
			,offset,fname);
		fclose(instream);
		return(FALSE); 
	}
	get_str(cfg->node_name,instream);
	get_str(cfg->node_phone,instream);
	get_str(cfg->node_comspec,instream);
	#ifdef __OS2__
	if(!cfg->node_comspec[0])
		strcpy(cfg->node_comspec,"C:\\OS2\\MDOS\\COMMAND.COM");
	#endif
	get_int(cfg->node_misc,instream);
	get_int(cfg->node_ivt,instream);
	get_int(cfg->node_swap,instream);
	get_str(cfg->node_swapdir,instream);
	get_int(cfg->node_valuser,instream);
	get_int(cfg->node_minbps,instream);
	get_str(cfg->node_arstr,instream);
	cfg->node_ar=ARSTR(cfg->node_arstr, cfg);

	get_int(cfg->node_dollars_per_call,instream);
	get_str(cfg->node_editor,instream);
	get_str(cfg->node_viewer,instream);
	get_str(cfg->node_daily,instream);
	get_int(c,instream);
	if(c) cfg->node_scrnlen=c;
	get_int(cfg->node_scrnblank,instream);
	get_str(cfg->text_dir,instream); 				/* ctrl directory */
	get_str(cfg->text_dir,instream); 				/* text directory */
	get_str(cfg->temp_dir,instream); 				/* temp directory */
#if 0 /* removed Sep-9-2003, always use nodex/temp (rrs) */
	if(!cfg->temp_dir[0])
#endif
		strcpy(cfg->temp_dir,"temp");

	for(i=0;i<10;i++)  						/* WFC 0-9 DOS commands */
		get_str(cfg->wfc_cmd[i],instream); 
	for(i=0;i<12;i++)  						/* WFC F1-F12 shrinking DOS cmds */
		get_str(cfg->wfc_scmd[i],instream); 
	get_str(cfg->mdm_hang,instream);
	get_int(cfg->node_sem_check,instream);
	if(!cfg->node_sem_check) cfg->node_sem_check=60;
	get_int(cfg->node_stat_check,instream);
	if(!cfg->node_stat_check) cfg->node_stat_check=10;
	get_str(cfg->scfg_cmd,instream);
	if(!cfg->scfg_cmd[0])
		strcpy(cfg->scfg_cmd,"%!scfg %k");
	get_int(cfg->sec_warn,instream);
	if(!cfg->sec_warn)
		cfg->sec_warn=180;
	get_int(cfg->sec_hangup,instream);
	if(!cfg->sec_hangup)
		cfg->sec_hangup=300;
	for(i=0;i<188;i++) {				/* Unused - initialized to NULL */
		fread(&n,1,2,instream);
		offset+=2; }
	for(i=0;i<256;i++) {				/* Unused - initialized to 0xff */
		fread(&n,1,2,instream);
		offset+=2; }

	/***************/
	/* Modem Stuff */
	/***************/

	get_int(cfg->com_port,instream);
	get_int(cfg->com_irq,instream);
	get_int(cfg->com_base,instream);
	get_int(cfg->com_rate,instream);
	get_int(cfg->mdm_misc,instream);
	get_str(cfg->mdm_init,instream);
	get_str(cfg->mdm_spec,instream);
	get_str(cfg->mdm_term,instream);
	get_str(cfg->mdm_dial,instream);
	get_str(cfg->mdm_offh,instream);
	get_str(cfg->mdm_answ,instream);
	get_int(cfg->mdm_reinit,instream);
	get_int(cfg->mdm_ansdelay,instream);
	get_int(cfg->mdm_rings,instream);

	get_int(cfg->mdm_results,instream);

	if(cfg->mdm_results) {
		if((cfg->mdm_result=(mdm_result_t *)malloc(sizeof(mdm_result_t)*cfg->mdm_results))
			==NULL)
		return allocerr(instream,error,offset,fname,sizeof(mdm_result_t *)*cfg->mdm_results);
	} else
		cfg->mdm_result=NULL;

	for(i=0;i<cfg->mdm_results;i++) {
		if(feof(instream)) break;
		get_int(cfg->mdm_result[i].code,instream);
		get_int(cfg->mdm_result[i].rate,instream);
		get_int(cfg->mdm_result[i].cps,instream);
		get_str(cfg->mdm_result[i].str,instream); 
	}
	cfg->mdm_results=i;
	fclose(instream);
	return(TRUE);
}
Exemplo n.º 17
0
void strtrm(char *str, const char trim, const char mode)
{
	//  STRING TRIMMING FUNCTION:
	// ---------------------------
	// This function removes a certain character from a string,
	// then truncuates the string. <const char trim> is removed.
	// The <const char mode> defines the mode of operation:
	// if mode is 'r' or 'R' then right side of str is trimmed.
	// if mode is 'l' or 'L' then left side of str is trimmed.
	// if mode is 's' or 'S' then both sides of str is trimmed.
	// if mode is 'i' or 'I' then the entire string str is trimmed.
	// if mode is anything else, then str is not modified
	// Finally, if capital letter is used for mode, then the
	// string str is re-allocated to the new string size, 
	// in order to reduce memory usage. Warning: Use capital
	// char mode *only* for dynamically allocated strings.

	if(trim=='\0')
	return;  /* if trim is null then return */
	if((strlen(str)==0)||(*str=='\0'))
	return;  /* str is empty */

	if(mode=='i'||mode=='I') // inside
	{
		// an extensive trimming operation. this method omits all
		// the trim chars from str and squeezes str to close holes.

		char ch; /* temporary character storage variable */
		unsigned int i, j;  /* loop counters */
		for(;*str!='\0';str++)
		{
			if(*str==trim)
			{
				for(i=0;*str!='\0';i++,str++)
				{
					str++;
					ch = *str;
					str--;
					*str=ch;
				}
				for(j=0;j<=i;j++)
				str--;
			}
		}
		*str='\0';  /* set termination point for string */
		if(!strlen(str)) *str = '\0';
	}
	else if(mode=='r'||mode=='R') // right
	{
		// this method removes all char trim selectively from str
		// starting from right, it removes trim until a non-trim char.
		// if modified str is '\0', then return is 1, otherwise is 0

		const unsigned int len = strlen(str);
		unsigned int i = 0; /* loop counter */
		for(i=0;i<len;i++)
		str++; /* push str poiner to the right end */
		unsigned char wfound=0;
		for(i=0;i<len;i++)
		{
			str--;  /* move pointer backward by one block */
			if(*str!=trim)
			wfound=1;  /* reached end of trim chars */
			if(wfound)  /* now reached the end of actual string*/
			{
				str++;  /* move pointer forward by one block */
				*str='\0';    /* set termination point for string */
				goto end;
			}
		}
		if(i==len) /* check is str is full of trims */
		*str = '\0';
	}
	else if(mode=='l'||mode=='L') // left
	{
		// this method removes all char trim selectively from str
		// starting from left, it removes trim until a non-trim char.
		// if modified str is '\0', then return is 1, otherwise is 0

		const unsigned int len = strlen(str);
		unsigned int w = 0;  /* to store no.of trim chars */
		unsigned int l = 0;  /* to store real length */
		unsigned int i = 0;  /* loop counter */
		unsigned char wfound=0;  /* boolean to verify if w is found */
		for(;*str!='\0';str++)
		{
			if(*str!=trim)
			wfound=1;  /* now w is found */
			if(!wfound)
			if(*str==trim)
			w++;  /* find out the no. of trim chars. */
		}
		if(w==len) /* check is str is full of trims */
		{
			for(i=0;i<len;i++)
			str--;  /* move str pointer to the starting*/
			*str = '\0';
			goto end;
		}
		l=(len - w);  /* find out real length */
		for(i=0;i<len;i++)
		str--;  /* move str pointer to the starting*/
		char ch; /* temporary character storage variable */
		unsigned int u = 0;  /* loop counter */
		for(i=0;i<l;i++)
		{
			for(u=0;u<w;u++)
			str++;  /* moves pointer w block forward */
			ch = *str;  /* stores (w+u)th block of str into ch */
			for(u=0;u<w;u++)
			str--;  /* moves pointer w block backwards */
			*str = ch;  /* stores ch into (u)th block of str */
			str++; /* increments str pointer to the next block */
		}
		/* set termination point for string */
		*str='\0';
	}
	else if(mode=='s'||mode=='S') // sides
	{
		// the function is recursed to remove
		// char trim from left and right sides.
		strtrm(str,trim,'r');
		strtrm(str,trim,'l');
	}
end:
	if(mode=='I'||mode=='L'||mode=='R'||mode=='S')
	{
		// re-alocate str to new size.
		int newsize = strlen(str)+1;
		if((cp=(char *)(realloc(str,sizeof(char)*newsize)))!=NULL)
		{ str = cp; } else { allocerr(); }
	}
	return;
}