Exemple #1
0
void runs(const char *str)
{
	if(*str==';'||*str==' '||*str=='\t')
	return;
	/*
	 *  here str is trimmed of all spaces
	 *  and tabs and stored in string and.
	 */
	char *and = clones(str);
	trims(and,' ');
	trims(and,'\t');
	register int loop = 0;
	for(;and[loop]!='\0';loop++)
	{
		if(and[loop]==34||and[loop]==39)
		bits.qt += 1;
		else if(and[loop]==';'&&!bits.qt)
		and[loop] = '\0';
	}
	/* now execute "and" */
	PROTOTYPE (void exec, (char *));
	reallocstr(and);
	exec(and);
	free(and);
}
Exemple #2
0
int32 * newint32(const char *id)
{
    /*  This function creates a new integer
     *  whose name is defined by the string *id,
     *  and returns an integer pointer to it.
    **/
    /*  --- WARNING --- [ CHECK *id VALIDITY BEFORE PASSING ]
     * newint() does not check the validity of variable names,
     * _even_ null variable names, are accepted. The caller
     * should check the validity of the string being passed.
     */
    /* check if a variable with the same name exists */
    if((getint32(id))!=NULL) return NULL;
    struct int32_table_struct * table_ptr;
    /* increment table size by 1 for 1 new variable */
    int32_table_size += 1;
    /* reallocate table structure with new size */
    if((table_ptr = (struct int32_table_struct *)
                    realloc (int32_table, sizeof(struct int32_table_struct)*
                             int32_table_size))==NULL) msg(system_no_mem,3);
    else /* set the variable */
        int32_table = table_ptr;
    /* set the variable name */
    int32_table[int32_table_size-1].ids = clones(id);
    /* initiaze the variable to 0 */
    int32_table[int32_table_size-1].var = 0;
    /* return a pointer to the variable */
    return &int32_table[int32_table_size-1].var;
}
void runs(const char *str)
{
	if(*str=='#'||*str==' '||*str=='\t')
	return;
	linenum += 1;
	/*
	 *  here str is trimmed of all spaces
	 *  and tabs and stored in string and.
	 */
	char *and = clones(str);
	trims(and,' ');
	trims(and,'\t');
	/* eliminate the comments */
	register int32 loop = 0;
	for(;and[loop]!='\0';loop++) {
		if(and[loop]==34||and[loop]==39)
			bits.qt += 1;
		else if(and[loop]=='#'&&!bits.qt)
			and[loop] = '\0';
	}
	reallocstr(and);
	/* now execute "and" */
	lisp_error[0] = '\0';
	exec(and);
	/* now runs() returns */
	if(strlen(lisp_error))
	msg(lisp_error,2);
	free(and);
}
Exemple #4
0
void runs(const char *str)
{
	if(*str==';'||*str==' '||*str=='\t')
	return;
	linenum += 1;
	/*
	 *  here str is trimmed of all spaces
	 *  and tabs and stored in string and.
	 */
	char *and = clones(str);
	trims(and,' ');
	trims(and,'\t');
	/* eliminate the comments */
	register long int loop = 0;
	for(;and[loop]!='\0';loop++) {
		if(and[loop]==34||and[loop]==39)
			bits.qt += 1;
		else if(and[loop]==';'&&!bits.qt)
			and[loop] = '\0';
	}
	/* now execute "and" */
	void exec(const char *);
	reallocstr(and);
	exec(and);
	free(and);
}
Exemple #5
0
TFx *TMacroFx::clone(bool recursive) const
{
	int n = m_fxs.size();
	vector<TFxP> clones(n);
	std::map<TFx *, int> table;
	std::map<TFx *, int>::iterator it;
	int i, rootIndex = -1;
	// nodi
	for (i = 0; i < n; ++i) {
		TFx *fx = m_fxs[i].getPointer();
		assert(fx);
		clones[i] = fx->clone(false);
		assert(table.count(fx) == 0);
		table[fx] = i;
		if (fx == m_root.getPointer())
			rootIndex = i;
		TFx *linkedFx = fx->getLinkedFx();
		if (linkedFx && table.find(linkedFx) != table.end())
			clones[i]->linkParams(clones[table[linkedFx]].getPointer());
	}
	assert(rootIndex >= 0);
	// connessioni
	for (i = 0; i < n; i++) {
		TFx *fx = m_fxs[i].getPointer();
		for (int j = 0; j < fx->getInputPortCount(); j++) {
			TFxPort *port = fx->getInputPort(j);
			TFx *inputFx = port->getFx();
			if (!inputFx)
				continue;
			it = table.find(inputFx);
			if (it == table.end()) {
				// il j-esimo input di fx e' esterno alla macro
				if (recursive)
					clones[i]->connect(fx->getInputPortName(j), inputFx->clone(true));
			} else {
				// il j-esimo input di fx e' interno alla macro
				clones[i]->connect(fx->getInputPortName(j), clones[it->second].getPointer());
			}
		}
	}

	//TFx *rootClone =
	//  const_cast<TMacroFx*>(this)->
	//  clone(m_root.getPointer(), recursive, visited, clones);

	TMacroFx *clone = TMacroFx::create(clones);
	clone->setName(getName());
	clone->setFxId(getFxId());

	//Copy the index of the passive cache manager.
	clone->getAttributes()->passiveCacheDataIdx() = getAttributes()->passiveCacheDataIdx();

	assert(clone->getRoot() == clones[rootIndex].getPointer());

	return clone;
}
Exemple #6
0
int32 * newint(const char *id)
{
	struct int_table_struct * table_ptr;
	int_table_size += 1;
	if((table_ptr = (struct int_table_struct *) 
	realloc (int_table, sizeof(struct int_table_struct)*
	int_table_size))==NULL) msg(no_mem,3);
	else /* set the variable */
	int_table = table_ptr;
	int_table[int_table_size-1].ids = clones(id);
	int_table[int_table_size-1].var = 0;
	return &int_table[int_table_size-1].var;
}
num32 new_idHash(const char *id)
{
	if((get_idHash(id)))
		return 0;
	/* increment the hash table size 
	   by 1 for 1 new variable */
	idHashTable_size += 1;	

	/* reallocate the hash table with the new size */
	{ struct struct_idHashTable * table_ptr = NULL;
	if((table_ptr = (struct struct_idHashTable *)realloc(idHashTable,
	sizeof(struct struct_idHashTable)*idHashTable_size)) == NULL)
	msg(system_no_mem,3); else idHashTable = table_ptr; }

	/* set the variable name & key */
	idHashTable[idHashTable_size-1].str = clones(id);
	idHashTable[idHashTable_size-1].key = idHashTable_size;

	/* return a pointer to the variable */
	return idHashTable[idHashTable_size-1].key;
}
Exemple #8
0
void tables_write()
{
   // first connect to data base
   // "recreate" option delete all your tables !!!!
   TSQLFile* f = new TSQLFile(dbname, "recreate", username, userpass);
   if (f->IsZombie()) { delete f; return; }

   // you can change configuration only until first object
   // is written to TSQLFile
   f->SetUseSuffixes(kFALSE);
   f->SetArrayLimit(1000);
   f->SetUseIndexes(1);
//   f->SetTablesType("ISAM");
//   f->SetUseTransactions(kFALSE);

   // lets first write histogram
   TH1I* h1 = new TH1I("histo1","histo title", 1000, -4., 4.);
   h1->FillRandom("gaus",10000);
   h1->Write("histo");
   h1->SetDirectory(0);

   // here we create list of objects and store them as single key
   // without kSingleKey all TBox objects will appear as separate keys
   TList* arr = new TList;
   for(Int_t n=0;n<10;n++) {
      TBox* b = new TBox(n*10,n*100,n*20,n*200);
      arr->Add(b, Form("option_%d_option",n));
   }
   arr->Write("list",TObject::kSingleKey);

   // clones array is also stored as single key
   TClonesArray clones("TBox",10);
   for(int n=0;n<10;n++)
       new (clones[n]) TBox(n*10,n*100,n*20,n*200);
   clones.Write("clones",TObject::kSingleKey);

   // close connection to database
   delete f;
}
Exemple #9
0
num32 setaddress(const char *str)
{
    /* adds a new string to the symbol
     * table and returns it's index.
     */
    if(!symbol_table_offset)
        initialize_symbol_table();
    struct struct_symbol_table
        * linkage = symbol_table_offset, * pointer = NULL;

    while (linkage ->link)
        linkage = linkage ->link;
    num32 index = linkage ->index;
    linkage ->link = (struct struct_symbol_table *)
                     malloc(sizeof(struct struct_symbol_table));
    if(linkage ->link==NULL) msg(system_no_mem,3);

    linkage = linkage ->link;
    linkage ->link = NULL;
    linkage ->index = index + 1;
    linkage ->string = clones(str);
    return linkage ->index;
}
Exemple #10
0
void c2html(const char *filename, char *err, struct colors *c)
{
	/* <- core function -> here the C source 
	   code is tranlated to an HTML web page. */

	struct /* common bits */
	{
		unsigned char color : 1;  /* color the code */
		unsigned char qt1 : 1;  /* double quotes */
		unsigned char qt2 : 1;  /* single quotes */
		unsigned char cm1 : 1;  /* multi-line comments */
		unsigned char cm2 : 1;  /* single-line comments */
		unsigned char num : 1;  /* numerical constants */
		unsigned char pre : 1;  /* preprocessors */
		unsigned char cont : 1;  /* preprocessors */
	}
	bits = { 1, 0, 0, 0, 0, 0, 0, 0 };

	if(!strlen(filename))
	{
		puts("\nPlease enter a filename.");
		return;
	}

	if(*filename==':')
	{
		bits.color = 0;
		filename++;
	}
	else if(*filename=='?')
	{
		userdef_colors(c);
		filename++;
	}

	FILE *cfile,*hfile;
	cfile = hfile = NULL;

	char htmlfile[STR_MAX];
	strcpy(htmlfile,filename);
	strcat(htmlfile,".html");

	if((cfile = fopen(filename,"r"))==NULL)
	{
		sprintf(err,"Could not open file: %s",filename);
		return;
	}

	unsigned short int line_length = 0;
	char input_str[STR_MAX];
	printf("\nHow many letters per line? ");
	fgets(input_str,STR_MAX,stdin);
	string(input_str);
	line_length = atoi(input_str);
	if(line_length <= 1) line_length = 80;

	printf("\nAnalyzing file: %s ...\n\n",filename);

	register char move = 0;
	unsigned int strmax, strnow, lines, pages;
	unsigned long int charcount = 0;
	unsigned long int letters = 0;
	strmax = strnow = lines = pages = 0;

	for(;move!=EOF;strnow++, charcount++)
	{
		move = fgetc(cfile);
		if(move=='\n')
		{
			strmax = strnow>strmax ? strnow:strmax;
			strnow = 0;
			lines++;
		}
		if(move<128 && move!='\n' && move!= '\r')
			letters++;
	}

	pages = lines/50;
	pages += lines%50 < 10 ? 0 : 1;

	printf("No. of pages = %d\n",pages);
	printf("No. of lines = %d\n",lines);
	printf("No. of chars = %ld\n",charcount);
	printf("No. of letters = %ld\n",letters);
	
	if(charcount<=1)
	{
		strcpy(err,"Too few characters.");
		fclose(cfile);
		return;
	}

	if((hfile = fopen(htmlfile,"w"))==NULL)
	{
		sprintf(err,"Could not create file: %s",htmlfile);
		fclose(cfile);
		return;
	}

	printf("\nTranslating file: %s ...    ",filename);

	fprintf(hfile,"<HTML><HEAD><TITLE>%s</TITLE></HEAD>\n",filename);
	fprintf(hfile,"<BODY TEXT=%s BGCOLOR=white><CENTER><H1>%s</H1></CENTER><HR><CODE>\n",c->text,filename);

	char *wstr = NULL, *wwstr = NULL;
	if((wstr = (char *) malloc
	(sizeof(char)*(strmax+1)))==NULL)
	{
		strcpy(err,"Out of memory.");
		fclose(hfile);
		fclose(cfile);
		return;
	}
	else *wstr = '\0';

	unsigned int digits = 0;
	unsigned int _lines = lines;
	for(;_lines;digits++) _lines /= 10;

	char *nstr = NULL;
	if((nstr = (char *) malloc
	(sizeof(char)*(digits+1)))==NULL)
	{
		strcpy(err,"Out of memory.");
		free(wstr);
		fclose(hfile);
		fclose(cfile);
		return;
	}
	else *nstr = '\0';
	fclose(cfile);

	unsigned int lnum = 0; 
	unsigned register int cnum = 0;
	cfile = fopen(filename,"r");

	/* C keywords */
	char keys[33][9] =
	{ 
		"auto","break","case","char",
		"const","continue","default",
		"double","do","else","enum",
		"extern","float","for","goto",
		"if","int","long","register",
		"return","short","signed",
		"sizeof","static","struct",
		"switch","typedef","union",
		"unsigned","void","volatile",
		"while", "inline"
	};

	for(bits.cont=0;fgets(wstr,strmax,cfile)!=NULL;lnum++)
	{
		unsigned int remaining = 0;
		unsigned int split_offset = 0;
		remainder:

		/* show translation progress */
		char prog[4] = "00%";
		double progn = (lnum*100)/lines;
		if(progn<100)
		numstr(prog,(int)progn,progn<10?1:2);
		strcat(prog,"%");

		if(strlen(prog)==2)
		printf("\b\b%s",prog);
		if(strlen(prog)==3)
		printf("\b\b\b%s",prog);
		
		/* insert line numbers */
		short int numlength = 0;
		if(remaining)
			goto so_go_on;
		numstr(nstr,lnum,digits);
		numlength = strlen(nstr);
		fprintf(hfile,"<B>%s</B> &nbsp;",nstr);
		so_go_on:

		/* check if the line has been commented off */
		if(bits.cm1&&lnum)
		fprintf(hfile,"<FONT COLOR=%s>",c->comment);

		/* reset the booleans in bits */
		if(bits.cont && bits.pre)
			fprintf(hfile,"<B>");
		else
			bits.pre = 0;
		if(bits.cont && bits.qt1)
			fprintf(hfile,"<FONT COLOR=%s>",c->string);
		else
			bits.qt1 = 0;
		bits.qt2 = 0;
		bits.cm2 = 0;
		bits.num = 0;

		unsigned int line_len = 0;
		line_len = line_length - numlength;

		if(remaining)
		{
			numstr(nstr,lnum,digits);
			numlength = strlen(nstr);
			strnull(nstr);
			strbluff(nstr,"&nbsp;" ,numlength);
			fprintf(hfile,"%s &nbsp;",nstr);
			char *t = allocs(line_len+1);
			strmid(t,wwstr,split_offset,line_len);
			strcpy(wstr,t);
			split_offset += strlen(wstr);
			remaining -= strlen(wstr);
		}

		if(strlen(wstr)>line_len && remaining <= 0)
		{
			split_offset = 0;
			char *t = allocs(line_len+1);
			strmid(t,wstr,split_offset,line_len);
			wwstr = clones(wstr);
			strcpy(wstr,t);
			split_offset += strlen(wstr);
			remaining = strlen(wwstr)-line_len;
		}

		for(cnum=0;cnum<strlen(wstr);cnum++)
		{
			/* color up the keywords */
			int keyw;
			for(keyw=0;keyw<33;keyw++)
			if(!strncmp(&wstr[cnum],keys[keyw],
				strlen(keys[keyw]))&&!(
			   wstr[cnum-1]>='A'&&
			   wstr[cnum-1]<='Z')&&!(
			   wstr[cnum-1]>='a'&&
			   wstr[cnum-1]<='z')&&!(
			   wstr[cnum-1]>='0'&&
			   wstr[cnum-1]<='9')&&
			   wstr[cnum-1]!='_'
               &&(!bits.cm1)
               &&(!bits.cm2)
               &&(!bits.qt1)
               &&(!bits.qt2)
               &&bits.color)
			{
				if(!(wstr[cnum+strlen(keys[keyw])]>='A'&&
			         wstr[cnum+strlen(keys[keyw])]<='Z')&&!(
			         wstr[cnum+strlen(keys[keyw])]>='a'&&
			         wstr[cnum+strlen(keys[keyw])]<='z')&&!(
					 wstr[cnum+strlen(keys[keyw])]>='0'&&
			         wstr[cnum+strlen(keys[keyw])]<='9')&&
			         wstr[cnum+strlen(keys[keyw])]!='_') {
				fprintf(hfile,"<FONT COLOR=%s>%s</FONT>",c->keyword,keys[keyw]);
				cnum += strlen(keys[keyw]);
				}
			}

			/* color up the comments */
			if(!strncmp(&wstr[cnum],"/*",2)
			   &&!bits.qt1
			   &&!bits.qt2
			   &&!bits.cm2
			   &&bits.color)
			{
				fprintf(hfile,"<FONT COLOR=%s>/",c->comment);
				bits.cm1 = 1;
			}
			else if(!strncmp(&wstr[cnum],"*/",2)
				    &&!bits.qt1
					&&!bits.qt2
				    &&!bits.cm2
					&&(bits.cm1)
					&&bits.color)
			{
				fprintf(hfile,"*/</FONT>");
				cnum++;
				bits.cm1 = 0;
			}
			else if((!strncmp(&wstr[cnum],"//",2))
				     &&!bits.qt1
					 &&!bits.qt2
				     &&!bits.cm2
					 &&!bits.cm1
					 &&bits.color)
			{
				fprintf(hfile,"<FONT COLOR=%s>/",c->comment);
				bits.cm2 = 1;
			}
			/* color up the strings */
			else if(wstr[cnum]==34
				    &&(!bits.cm2)
					&&(!bits.cm1)
					&&(!bits.pre)
					&&bits.color)
			{
				if(wstr[cnum-1]!='\\') {
				if(!bits.qt1)
				{
					fprintf(hfile,"<FONT COLOR=%s>%c",c->string,34);
					bits.qt1 = 1;
				}
				else
				{
					fprintf(hfile,"%c</FONT>",34);
					bits.qt1 = 0;
				} }
			}
			/* color up the chars */
			else if(wstr[cnum]==39
					&&(!bits.qt1)
				    &&(!bits.cm2)
					&&(!bits.cm1)
					&&(!bits.pre)
					&&bits.color)
			{
				if(wstr[cnum-1]!='\\') {
				if(!bits.qt2)
				{
					fprintf(hfile,"<FONT COLOR=%s>%c",c->chr,39);
					bits.qt2 = 1;
				}
				else
				{
					fprintf(hfile,"%c</FONT>",39);
					bits.qt2 = 0;
				} }
			}
			/* color up the numbers */
			else if(wstr[cnum]>='0'&&
				    wstr[cnum]<='9'&&!(
					wstr[cnum-1]>'A'&&
					wstr[cnum-1]<'Z')&&!(
					wstr[cnum-1]>'a'&&
					wstr[cnum-1]<'z')&&
					wstr[cnum-1]!='_'
				    &&(!bits.cm2)
					&&(!bits.cm1)
					&&(!bits.qt1)
					&&(!bits.qt2)
					&&(!bits.num)
					&&(!bits.pre)
					&&bits.color)
			{
				fprintf(hfile,"<FONT COLOR=%s>%c",c->numbers,wstr[cnum]);
				bits.num = 1;
			}
			else if(bits.num /* to end number colouring */
				    &&((wstr[cnum]<'0')
				    ||(wstr[cnum]>'9')))
			{
			    fprintf(hfile,"</FONT>%c",wstr[cnum]);
				bits.num = 0;
			}
			/* color up the preprocessors */
			else if(wstr[cnum]=='#'
				    &&(!bits.cm2)
					&&(!bits.cm1)
					&&(!bits.qt1)
					&&(!bits.qt2)
					&&(!bits.pre)
					&&(bits.color))
			{
				fprintf(hfile,"<B>#");
				bits.pre = 1;
			}

			/* replace the C symbols
			 with their HTML equivalent */
			else if(wstr[cnum-1]==' '&&wstr[cnum]==' ')
			fprintf(hfile,"&nbsp;");
			else if(wstr[cnum]=='\t')
			fprintf(hfile,"&nbsp; ");
			else if(wstr[cnum]=='<')
			fprintf(hfile,"&lt;");
			else if(wstr[cnum]=='>')
			fprintf(hfile,"&gt;");
			else if(wstr[cnum]=='\n') {
				fprintf(hfile,"</FONT>");
				if(wstr[cnum-1]=='\\')
					bits.cont = 1;
				else
					bits.cont = 0;
			break;
			} else
			fprintf(hfile,"%c",wstr[cnum]);
		}

		if(bits.pre)
		fprintf(hfile,"</B>");
		/* end font tag */
		if(bits.cm1||
		   bits.cm2||
		   bits.qt1||
		   bits.qt2||
		   bits.num)
		fprintf(hfile,"</FONT>");
		/* end the line */
		fprintf(hfile,"<BR>\n");

		if(remaining)
			goto remainder;
	}

	fputs("</CODE><HR NOSHADE><FONT FACE=Arial>\n",hfile);
	fprintf(hfile,"No. of pages = %d<BR>\n",pages);
	fprintf(hfile,"No. of lines = %d<BR>\n",lines);
	fprintf(hfile,"No. of chars = %ld<BR>\n",charcount);
	fprintf(hfile,"No. of letters = %ld\n",letters);
	fputs("</FONT></BODY></HTML>",hfile);
	puts("\b\b\b100%\n\nTranslation Complete.");
	printf("HTML File: %s stored.\n",htmlfile);
	free(wstr);
	fclose(hfile);
	fclose(cfile);
}