예제 #1
0
bool PdmsFileSession::moveForward()
{
	int car;
	unsigned n;
	bool tokenFilled;
	n=0;

	if(PdmsLexer::moveForward()) return true;

	m_eol = false;
	tokenFilled = false;
	while(!tokenFilled)
	{
		car = getc(m_file);
		switch(car)
		{
		case '\n':
			if(n>0)
			{
				tokenFilled = true;
				m_eol = true;
			}
			m_currentLine++;
			break;
		case ' ':
		case '\t':
			if(n>0)
				tokenFilled = true;
			break;
		case EOF:
			tokenFilled = true;
			m_eof = true;
			break;
		default:
			if(n >= c_max_buff_size)
			{
				printWarning("Buffer overflow");
				return false;
			}
			tokenBuffer[n] = car;
			n++;
			break;
		}
	}
	tokenBuffer[n] = '\0';
	if(tokenBuffer[0] != '/')
		upperStr(tokenBuffer);
	return (n>0);
}
예제 #2
0
/*==============================================================================
 * FUNCTION:        RTLInstDict::appendToDict
 * OVERVIEW:        Appends one RTL to the dictionary
 * PARAMETERS:      n: name of the instruction to add to
 *                  p: list of formal parameters (as strings) for the RTL to add
 *                  r: reference to the RTL to add
 * RETURNS:         0 for success
 *============================================================================*/
int RTLInstDict::appendToDict(std::string &n, std::list<std::string> &p, RTL &r)
{
    char *opcode = new char[n.size() + 1];
    strcpy(opcode, n.c_str());
    upperStr(opcode, opcode);
    std::remove(opcode, opcode + strlen(opcode) + 1, '.');
    std::string s(opcode);
    //delete [] opcode;

    if (idict.find(s) == idict.end()) {
        idict[s] = TableEntry(p, r);
    } else {
        return idict[s].appendRTL(p, r);
    }
    return 0;
}
예제 #3
0
/*==============================================================================
 * FUNCTION:		 RTLInstDict::getNumOperands
 * OVERVIEW:		 Returns the signature of the given instruction.
 * PARAMETERS:		 name -
 * RETURNS:			 the signature (name + number of operands)
 *============================================================================*/
std::pair<std::string,unsigned> RTLInstDict::getSignature(const char* name) {
	// Take the argument, convert it to upper case and remove any _'s and .'s
	char *opcode = new char[strlen(name) + 1];
	upperStr(name, opcode);
//	std::remove(opcode,opcode+strlen(opcode)+1,'_');
	std::remove(opcode,opcode+strlen(opcode)+1,'.');

	// Look up the dictionary
	std::map<std::string,TableEntry>::iterator it = idict.find(opcode);
	if (it == idict.end()) {
		std::cerr << "Error: no entry for `" << name << "' in RTL dictionary\n";
		it = idict.find("NOP");		// At least, don't cause segfault
	} 

	std::pair<std::string, unsigned> ret;
	ret = std::pair<std::string,unsigned>(opcode,(it->second).params.size());
	//delete [] opcode;
	return ret;
}
예제 #4
0
void PdmsFileSession::skipComment()
{
	int car, commentBlockLevel;
	bool commentSymb;
	char *ptr1, *ptr2;
	int n;

	switch(currentToken)
	{
	case PDMS_COMMENT_LINE:
		//skip line only if the end of line has not been read in current buffer
		if(!m_eol)
		{
			n = 0;
			do{
				car = getc(m_file);
				if(car=='\t') car=' ';
				tokenBuffer[n] = car;
				if(((n+1)<c_max_buff_size) && ((car!=' ') || (n>0 && tokenBuffer[n-1]!=' '))) n++;
			} while(car!=EOF && (char)car!='\n');
			if(car == '\n')
				m_currentLine++;
			tokenBuffer[n-1] = '\0';
		}
		m_eol = false;
		break;
	case PDMS_COMMENT_BLOCK:
		//comment block opening symbol has been met. Search for comment block ending symbol
		//don't forget that some other comments could be embeded in this comment
		commentSymb = false;
		commentBlockLevel = 1;
		n = 0;
		do{
			car = getc(m_file);
			if(car=='\n') m_currentLine++;
			if(car=='\n' || car=='\t') car = ' ';
			if(car=='$') commentSymb = true;
			else if(car=='(' && commentSymb) commentBlockLevel++;
			else if(car==')' && commentSymb) commentBlockLevel--;
			else
			{
				commentSymb = false;
				tokenBuffer[n] = car;
				if(((n+1)<c_max_buff_size) && ((car!=' ') || (n>0 && tokenBuffer[n-1]!=' '))) n++;
			}
		} while(car!=EOF && commentBlockLevel>0);
		tokenBuffer[n-1] = '\0';
		m_eol = false;
		break;
	default:
		break;
	}

	upperStr(tokenBuffer);
	if(strncmp(tokenBuffer, "ENTERING IN GROUP:", 18)==0)
	{
		currentToken = PDMS_ENTER_METAGROUP;
		//The meta group name starts after the "entering in group:" statement, after the last slash
		//But we still store the whole path
		ptr2 = &(tokenBuffer[18]);
		while((*ptr2)==' ') {ptr2++;}
		//Copy the meta group name at the begining of tokenbuffer
		tokenBuffer[0] = '/';
		ptr1 = &(tokenBuffer[1]);
		while((*ptr2) && (*ptr2)!=' ')
		{
			*ptr1 = *ptr2;
			ptr1++;
			ptr2++;
		}
		*ptr1 = '\0';
		metaGroupMask = 0;
	}
	else if(strncmp(tokenBuffer, "LEAVING GROUP", 13)==0)
	{
		currentToken = PDMS_LEAVE_METAGROUP;
		metaGroupMask = 0;
	}
}
예제 #5
0
 String StringUtils::toUpper(const String& str)
 {
     String upperStr(str);
     toUpper(upperStr);
     return upperStr;
 }
예제 #6
0
struct tagInfo getOggHeader(char *file){
//if (DEBUG==1) putlog("reading ogg header");
	char header[4096];
	int i, c;
	int h1pos, h3pos, maxBr, nomBr, minBr, pos, count, tagLen;
	char *sub;
	char *name;
	char *val;
	char HEADLOC1[]="_vorbis", HEADLOC3[]="_vorbis", HEADLOC5[]="_vorbis";
	FILE *f;
	struct tagInfo info;

	info.artist=NULL;
	f = fopen(file,"rb");
	if (f==NULL){
       hexchat_print(ph,"file not found while trying to read ogg header");
       //if (DEBUG==1) putlog("file not found while trying to read ogg header");
       return info;
    }

	for (i=0;i<4095;i++) {c=fgetc(f);header[i]=(char)c;}
	fclose(f);
	HEADLOC1[0]=1;
	HEADLOC3[0]=3;
	HEADLOC5[0]=5;
	h1pos=inStr(header,4096,HEADLOC1);
	h3pos=inStr(header,4096,HEADLOC3);
	//int h5pos=inStr(header,4096,HEADLOC5); //not needed
	
	//printf("loc1: %i\n",h1pos);printf("loc3: %i\n",h3pos);printf("loc5: %i\n",h5pos);
	maxBr=getOggInt(header,h1pos+7+9,4);
	nomBr=getOggInt(header,h1pos+7+13,4);
	minBr=getOggInt(header,h1pos+7+17,4);
	info.freq=getOggInt(header,h1pos+7+5,4);
	info.mode=header[h1pos+7+4];
	info.bitrate=nomBr;
	if (((maxBr==nomBr)&&(nomBr=minBr))||((minBr==0)&&(maxBr==0))||((minBr=-1)&&(maxBr=-1)) )info.cbr=1;else info.cbr=0;
	printf("bitrates: %i|%i|%i\n",maxBr,nomBr,minBr);
	printf("freq: %u\n",info.freq);
	pos=h3pos+7;
	pos+=getOggInt(header,pos,4)+4;
	count=getOggInt(header,pos,4);
	//printf("tags: %i\n",count);
	pos+=4;

	info.artist=NULL;info.title=NULL;info.album=NULL;info.comment=NULL;info.genre=NULL;
	for (i=0;i<count;i++){
		tagLen=getOggInt(header,pos,4);
		//printf("taglength: %i\n",tagLen);
		sub=substring(header,pos+4,tagLen);
		name=upperStr(substring(sub,0,inStr(sub,tagLen,"=")));
		val=substring(sub,inStr(sub,tagLen,"=")+1,tagLen-inStr(sub,tagLen,"=")-1);
		//printf("Tag: %s\n",sub);
		//printf("Name: %s\n",name);
		//printf("value: %s\n",val);
		if (strcmp(name,"ARTIST")==0) info.artist=val;
		if (strcmp(name,"TITLE")==0) info.title=val;
		if (strcmp(name,"ALBUM")==0) info.album=val;
		if (strcmp(name,"GENRE")==0) info.genre=val;
		if (strcmp(name,"COMMENT")==0) info.comment=val;
		pos+=4+tagLen;
		free(name);
	}
	if (info.artist==NULL) info.artist="";
	if (info.album==NULL) info.album ="";
	if (info.title==NULL) info.title="";
	if (info.genre==NULL) info.genre="";
	if (info.comment==NULL) info.comment="";
	
	printf("Artist: %s\nTitle: %s\nAlbum: %s\n",info.artist,info.title, info.album);
	printf("Genre: %s\nComment: %s\nMode: %i\nCBR: %i\n",info.genre,info.comment,info.mode,info.cbr);
	//if (DEBUG==1) putlog("ogg header readed");
	return info;
}