コード例 #1
0
bool CCLexicalAnalyzer::Create(const char *pStr)
{
	//strcpy(m_szOriginal, pStr);
	char seps[] = " ,\t'";	// ','는 임시로 빼 놓는다. ''로 스트링을 구분하기 위해
	char szToken[256];
	if(StrTok(szToken, pStr, seps)==false) return true;
	while(1){
		if(szToken[0]==' '){
		}
		else if(szToken[0]==','){
		}
		else if(szToken[0]=='\t'){
		}
		else if(szToken[0]=='\''){
			if(StrTok(szToken, NULL, "'")==false) return true;
			char *pAddToken = new char[strlen(szToken)+1];
			strcpy(pAddToken, szToken);
			m_Tokens.Add(pAddToken);
			if(StrTok(szToken, NULL, "'")==false) return true;
		}
		else{
			char *pAddToken = new char[strlen(szToken)+1];
			strcpy(pAddToken, szToken);
			m_Tokens.Add(pAddToken);
		}

		if(StrTok(szToken, NULL, seps)==false) return true;
	}
	/*
	char *pToken = strtok(pStr, seps);
	char szTemp[256];
	while(pToken!=NULL){
		if(pToken[0]=='\''){
			strcpy(szTemp, pToken);
			pToken = strtok(NULL, "'");
			strcpy(szTemp+strlen(szTemp), pToken);
			szTemp[strlen(szTemp)+1] = 0;
			szTemp[strlen(szTemp)] = '\'';
			pToken = szTemp;
		}
		char *pAddToken = new char[strlen(pToken)+1];
		strcpy(pAddToken, pToken);
		m_Tokens.Add(pAddToken);

		pToken = strtok(NULL, seps);
	}
	*/

	return true;
}
コード例 #2
0
ファイル: aseread.cpp プロジェクト: paud/d2x-xl
static int ASE_ReadMeshFaceList (CFILE *cfP, tASEModel *pm)
{
	tASESubModel	*psm = &pm->pSubModels->sm;
	tASEFace			*pf;
	int				i;

if (CharTok (" \t") != '{')
	return ASE_Error ("syntax error");
while ((pszToken = ASE_ReadLine (cfP))) {
	if (*pszToken == '}')
		return 1;
	if (!strcmp (pszToken, "*MESH_FACE")) {
		if (!psm->pFaces)
			return ASE_Error ("no faces found");
		i = IntTok (" \t");
		if ((i < 0) || (i >= psm->nFaces))
			return ASE_Error ("invalid face number");
		pf = psm->pFaces + i;
		for (i = 0; i < 3; i++) {
			strtok (NULL, " :\t");
			pf->nVerts [i] = IntTok (" :\t");
			}
		do {
			pszToken = StrTok (" :\t");
			if (!*pszToken)
				return ASE_Error ("unexpected end of file");
			} while (strcmp (pszToken, "*MESH_MTLID"));
		pf->nBitmap = IntTok (" ");
		}
	}
return ASE_Error ("unexpected end of file");
}
コード例 #3
0
ファイル: aseread.cpp プロジェクト: paud/d2x-xl
static int ASE_ReadTexture (CFILE *cfP, tASEModel *pm, int nBitmap, int nType, int bCustom)
{
	grsBitmap	*bmP = pm->textures.pBitmaps + nBitmap;
	char			fn [FILENAME_LEN], *ps;
	int			l;

if (CharTok (" \t") != '{')
	return ASE_Error ("syntax error");
bmP->bmFlat = 0;
while ((pszToken = ASE_ReadLine (cfP))) {
	if (*pszToken == '}')
		return 1;
	if (!strcmp (pszToken, "*BITMAP")) {
		if (bmP->bmTexBuf)	//duplicate
			return ASE_Error ("duplicate item");
		*fn = '\001';
		CFSplitPath (StrTok ("\""), NULL, fn + 1, NULL);
		if (!ReadModelTGA (strlwr (fn), bmP, nType, bCustom))
			return ASE_Error ("texture not found");
		l = (int) strlen (fn) + 1;
		if (!(pm->textures.pszNames [nBitmap] = (char *) D2_ALLOC (l)))
			return ASE_Error ("out of memory");
		memcpy (pm->textures.pszNames [nBitmap], fn, l);
		if ((ps = strstr (fn, "color")))
			pm->textures.nTeam [nBitmap] = atoi (ps + 5) + 1;
		else
			pm->textures.nTeam [nBitmap] = 0;
		bmP->bmTeam = pm->textures.nTeam [nBitmap];
		}
	}
return ASE_Error ("unexpected end of file");
}
コード例 #4
0
ファイル: webserver.c プロジェクト: MaTriXy/libupnp
/*!
 * \brief Returns a range of integers from a string.
 *
 * \return Always returns 1.
 */
static int GetNextRange(
	/*! string containing the token / range. */
	char **SrcRangeStr,
	/*! gets the first byte of the token. */
	off_t *FirstByte,
	/*! gets the last byte of the token. */
	off_t *LastByte)
{
	char *Ptr;
	char *Tok;
	int i;
	int64_t F = -1;
	int64_t L = -1;
	int Is_Suffix_byte_Range = 1;

	if (*SrcRangeStr == NULL)
		return -1;
	Tok = StrTok(SrcRangeStr, ",");
	if ((Ptr = strstr(Tok, "-")) == NULL)
		return -1;
	*Ptr = ' ';
	sscanf(Tok, "%" SCNd64 "%" SCNd64, &F, &L);
	if (F == -1 || L == -1) {
		*Ptr = '-';
		for (i = 0; i < (int)strlen(Tok); i++) {
			if (Tok[i] == '-') {
				break;
			} else if (isdigit(Tok[i])) {
				Is_Suffix_byte_Range = 0;
				break;
			}
		}
		if (Is_Suffix_byte_Range) {
			*FirstByte = (off_t) L;
			*LastByte = (off_t) F;
			return 1;
		}
	}
	*FirstByte = (off_t) F;
	*LastByte = (off_t) L;

	return 1;
}
コード例 #5
0
ファイル: UDPSocket.cpp プロジェクト: pfedick/pplib
/*!\brief Verbindung aufbauen
 *
 */
void UDPSocket::connect(const String &host_and_port)
{
	if (host_and_port.isEmpty())
		throw IllegalArgumentException("UDPSocket::connect(const String &host_and_port)");
	Array hostname = StrTok(host_and_port, ":");
	if (hostname.size() != 2)
		throw IllegalArgumentException("UDPSocket::connect(const String &host_and_port)");
	String portname = hostname.get(1);
	int port = portname.toInt();
	if (port <= 0 && portname.size() > 0) {
		// Vielleicht wurde ein Service-Namen angegeben?
		struct servent *s = getservbyname((const char*) portname, "tcp");
		if (s) {
			unsigned short int p = s->s_port;
			port = (int) ntohs(p);
		} else {
			throw IllegalPortException("UDPSocket::connect(const String &host_and_port=%s)", (const char*) host_and_port);
		}
	}
	if (port <= 0)
		throw IllegalPortException("UDPSocket::connect(const String &host_and_port=%s)", (const char*) host_and_port);
	return connect(hostname.get(0), port);
}
コード例 #6
0
ファイル: WikiParser.cpp プロジェクト: pfedick/pplib
void WikiParser::parseDoxygen(String &Line)
{
	String Tmp;
	Array matches;
	Line.pregReplace("/\\\\p\\s([a-z_A-Z_0-9]+)/","<b style=\"color: #005000;\">$1</b>");
	Line.pregReplace("/\\\\b\\s([^\\s]+)/","<b>$1</b>");
	Line.pregReplace("/^\\\\brief\\s(.*)$/","$1<br>");
	if (Line.pregMatch("/^\\\\desc(.*)$/i", matches)) {
		doxygenChapter(Line,"Beschreibung:",matches);
	}
	if (Line.pregMatch("/^\\\\return(.*)$/i",matches)) {
		doxygenChapter(Line,"Rückgabe:",matches);
	}
	if (Line.pregMatch("/^\\\\example(.*)$/i",matches)) {
		doxygenChapter(Line,"Beispiel:",matches);
	}
	if (Line.pregMatch("/^\\\\history(.*)$/i",matches)) {
		doxygenChapter(Line,"Historie:",matches);
	}

	if (Line.pregMatch("/^\\\\sourcecode(.*)$/i",matches)) {
		doxygenChapter(Line,"Quellcode:",matches);
	}

	if (Line.pregMatch("/^\\\\note(.*)$/i",matches)) {
		doxygenChapter(Line,"Hinweis:",matches);
	}
	if (Line.pregMatch("/^\\\\attention(.*)$/i",matches)) {
		doxygenChapter(Line,"Achtung:",matches);
	}

	if (Line.pregMatch("/^\\\\par$/i")) {
		Line="";
		for (int i=indentlevel;i>0;i--) Line+="</div>";
		indentlevel=0;
		Line+="<div style=\"margin-left: 30px;\">";
		indentlevel++;
	}
	if (Line.pregMatch("/^\\\\syntax\\s+(.*)$/i",matches)) {
		Line="";
		for (int i=indentlevel;i>0;i--) Line+="</div>";
		indentlevel=0;
		Line+="<b>Syntax:</b><div style=\"margin-left: 30px;\">";
		String s=matches[1];
		if (s.pregMatch("/^(.+)\\s+(.+)\\s*\\((.*)\\)$/",matches)) {
			Line.appendf("<span style=\"color: #400000;\">%s</span> <b>%s</b>(",
					matches.getPtr(1), matches.getPtr(2));
			Array Tok;
			StrTok(Tok,matches[3],",");
			// TODO
			String tt;
			int c=0;
			for (size_t j=0;j<Tok.size();j++) {
				tt=Tok[j];
				if (tt.pregMatch("/^(.*)\\s+(.*)$/",matches)) {
					if (c) Line+=", ";
					Line.appendf("<span style=\"color: #400000;\">%s</span> <b style=\"color: #005000;\">%s</b>",
							(const char*)matches[1], (const char*)matches[2]);
					c++;
				}

			}
		}
		Line+=")</div>";
	}

	if (Line.pregMatch("/^\\\\param\\s*\\[(.+)\\]\\s{0}(.+?)\\s+(.*)$/i",matches)) {
		Line="";
		if (!doxyparamsStarted) {
			for (int i=indentlevel;i>0;i--) Line+="</div>";
			indentlevel=0;
			doxyparamsStarted=true;
			Line+="<b>Parameter:</b><div style=\"margin-left: 30px;\">\n";
			indentlevel++;
		}

		Line+="<ul><li>[";
		Line+=matches[1];
		Line+="] <b style=\"color: #005000;\">";
		Line+=matches[2];
		Line+="</b> ";
		Line+=matches[3];
		Line+="</li></ul>";
		nobr=true;
	}
	if (Line.pregMatch("/^\\\\param\\s+(.+?)\\s+(.*)$/i",matches)) {
		Line="";
		if (!doxyparamsStarted) {
			for (int i=indentlevel;i>0;i--) Line+="</div>";
			indentlevel=0;
			doxyparamsStarted=true;
			Line+="<b>Parameter:</b><div style=\"margin-left: 30px;\">\n";
			indentlevel++;
		}
		Line+="<ul><li><b style=\"color: #005000;\">";
		Line+=matches[1];
		Line+="</b> ";
		Line+=matches[2];
		Line+="</li></ul>";
	}

}
コード例 #7
0
ファイル: action.c プロジェクト: andys/xevact
Bool LoadActions(char *file) {
	FILE	*fp;
	int	type, i;
	char	line[MAX_LINE_LEN],*token;
	Action	action,*new_action=NULL;
	
	DEBUG(D_LOAD) printf("LoadActions: %s\n",file);
	fp=fopen(file, "r");
	if (NULL==fp) {
		printf("Cannot open file: %s.\n",file);
		return FALSE;
		}
	while (fgets(line,MAX_LINE_LEN,fp)) {
		if (line[0]=='#') continue;
		if (strlen(line)<=1) continue;

		DEBUG(D_LOAD) printf("DEBUG: Read line: %s\n",line);
		{register int slen;
			slen=strlen(line);
			line[slen-1]=0; /* take out \n from fgets */
			line[slen]=0;   /* add extra \0 for last param check */
			}

		Zero(&action, sizeof(action));

		/* Event Type */
		token=StrTok(line, WHITE_SPACE);
		if (NULL==token) continue;
		type=StrToType(token);
		
		/* Flags */
		NextToken;
		action.flags=StrToFlags(token);

		/* delay */
		NextToken;
		action.delay.tv_sec=atoi(token);
		NextToken;
		action.delay.tv_usec=atoi(token);
		while (action.delay.tv_usec>1000000) {
			action.delay.tv_usec-=1000000;
			action.delay.tv_sec++;
			}
		DEBUG(D_LOAD) printf("DEBUG: delay is sec %d usec %d\n",action.delay.tv_sec,action.delay.tv_usec);
		
		/* Condition & test functions */
		NextToken;
		action.tests=atoi(token);
		new_action=NULL;
		for (i=0; i<action.tests; i++) {
			NextToken;
			if (!strcmp("DEFAULT",token)) {
				new_action=&set[type].default_action;
				}
			else {
				if (token[0]=='-' && token[1]==0) action.match[i]=NULL;
				else {
					if (token[0]=='!') {
						action.not[i]=TRUE;
						token++;
						}
					else action.not[i]=FALSE;
					action.match[i]=StrToCall(token,CALL_TEST);
					}	
				}
			
			NextToken;
			action.cond[i]=StrToCondition(token);
			}
		DEBUG(D_LOAD) printf("Read %d tests\n",i);
		
		/* Call */
		NextToken;
		action.call=StrToCall(token,CALL_ACTION);

		/* call's parameters (in string action.string) */
		token=&token[strlen(token)+1];
		if (strlen(token)>0) {
			action.string=(char *)malloc(strlen(token)+1);
			strcpy(action.string, token);
			DEBUG(D_LOAD) printf("Call Function Parameter: %s\n", token);
			}
		else action.string=NULL;
		
		
		/* add to list */
		set[type].is_set=TRUE;
		if (NULL==new_action) {
			new_action=(Action *)malloc(sizeof(Action));
			bcopy(&action, new_action, sizeof(Action));
			ListAddAfter(&set[type].tlist, ListLastElem(&set[type].tlist), new_action);
			}
		else	bcopy(&action, new_action, sizeof(Action));
		}
	return TRUE;
	}
コード例 #8
0
ファイル: codon.c プロジェクト: fast-project/mpifast
/********************************************************************
*
*	print_label_to_buffer_all_ex(buf, label, pos, strand, extra_space)
*
*	print a label (with label_name=label, position=pos, 
*	orientation = strand, extra_space = extra_space for partial start)
*	into the current buffer
*	return the offset of the buffer pointer to the current buffer
*	Has an option to strip/not-strip semicolons for hardline old blast
*	users.
*
*********************************************************************/
NLM_EXTERN Int4 print_label_to_buffer_all_ex(CharPtr buf, CharPtr label, 
		Int4 pos, Uint1 strand, Boolean extra_space, Boolean is_html, 
		Int4 label_space, Int4 num_space, Boolean show_strand, 
		Boolean strip_semicolon)
{
	Int4 len;
	Char symbol;
	Char temp[100];
	Int4 i = 0;
	CharPtr str;
	Int4 max_b_space;

	/*
	*	print the label to the buffer
	*/
	max_b_space = label_space + 1;
	len = 0;
	if(label)
	{
		if (strip_semicolon)
		{
			str= StrTok(label, ":");
			if(str == NULL)
				str = label;
			else
			{
				str = StrTok(NULL, ":");
				if(str == NULL)
					str = label;
			}
		}
		else
		{
			str = label;
		}
		len = MIN(max_b_space-1, (Int4)StringLen(str));
		StringNCpy(buf, str, len);
		i = len;
		if(is_html)
		{
			sprintf(buf+i, "</a>");
			i += 4;
		}
		buf[i++] = ' ';
		++len;
	}
	
	/*add the leftover empty space */
	for(; len<max_b_space; ++len)
		buf[i++] = ' ';

	if(show_strand)
	{
		symbol = ' ';
		if(strand == Seq_strand_plus)
			symbol = '>';
		if(strand == Seq_strand_minus)
			symbol = '<';
		buf[i++] = ' ';
		buf[i++] = symbol;
		buf[i++] = ' ';
	}

	len = 0;
	if(pos != -1)
	{
		sprintf(buf+i, "%ld", (long) pos);
		sprintf(temp, "%ld", (long) pos);
		len = StringLen(temp);
		i += len;
	}

	if(extra_space)	/*for partial codon*/
		++len;
	max_b_space = num_space + 1;
	for(; len <max_b_space; ++len)
		buf[i++] = ' ';
	return i;
}
コード例 #9
0
ファイル: control.c プロジェクト: ZirconiumX/Firenzina
void InitSearch(typePos *Position, char *str)
    {
    char *p;
    sint64 wtime = Infinity, btime = Infinity, winc = 0, binc = 0, Time, OppTime, mtg = 0;
    int sm = 0;
    Depth = 255;
    AbsoluteTime = DesiredTime = Infinity;
    Stop = false;
    DoInfinite = false;
    DoPonder = false;
    NewPonderhit = false;
    DoSearchMoves = false;
    LastMessage = 0;
    p = strtok(str, " ");
    for (StrTok(p); p != NULL; StrTok(p))
        {
        if (!strcmp(p, "depth"))
            {
            StrTok(p);
            Depth = MAX(1, atoi(p));
            }
        else if (!strcmp(p, "movetime"))
            {
            StrTok(p);
            AbsoluteTime = MAX(1, atoll(p)) * 1000;
            }
        else if (!strcmp(p, "wtime"))
            {
            StrTok(p);
            wtime = atoll(p) * 1000;
            }
        else if (!strcmp(p, "winc"))
            {
            StrTok(p);
            winc = atoll(p) * 1000;
            }
        else if (!strcmp(p, "btime"))
            {
            StrTok(p);
            btime = atoll(p) * 1000;
            }
        else if (!strcmp(p, "binc"))
            {
            StrTok(p);
            binc = atoll(p) * 1000;
            }
        else if (!strcmp(p, "movestogo"))
            {
            StrTok(p);
            mtg = atoi(p);
            }
        else if (!strcmp(p, "infinite"))
            DoInfinite = true;
        else if (!strcmp(p, "ponder"))
            DoPonder = true;
        else if (!strcmp(p, "searchmoves"))
            DoSearchMoves = true;
        else if (DoSearchMoves)
            SearchMoves[sm++] = NumericMove(Position, p);
        else
            ErrorEnd("go string: %s", p);
        }
    BattleTime = Infinity;
    NormalTime = Infinity;
    EasyTime = Infinity;

    Time = Position->wtm ? wtime : btime;
    OppTime = Position->wtm ? btime : wtime;
    if (Time < 0)
        Time = 0;
    if (Time == Infinity)
        goto End;
    Increment = Position->wtm ? winc : binc;
        TimeManager(Time, OppTime, Increment, mtg);
    End:
    if (Time == Infinity)
        Analysing = true;
    else
        Analysing = false;
    if (DoSearchMoves)
        SearchMoves[sm] = MoveNone;
    }
コード例 #10
0
ファイル: aseread.cpp プロジェクト: paud/d2x-xl
static int ASE_ReadSubModel (CFILE *cfP, tASEModel *pm)
{
	tASESubModelList	*pml;
	tASESubModel		*psm;

if (CharTok (" \t") != '{')
	return ASE_Error ("syntax error");
if (!(pml = (tASESubModelList *) D2_ALLOC (sizeof (tASESubModelList))))
	return ASE_Error ("out of memory");
memset (pml, 0, sizeof (*pml));
pml->pNextModel = pm->pSubModels;
pm->pSubModels = pml;
psm = &pm->pSubModels->sm;
psm->nId = pm->nSubModels++;
psm->nBomb = -1;
psm->nMissile = -1;
psm->nGun = -1;
psm->nGunPoint = -1;
psm->nBullets = -1;
psm->bRender = 1;
psm->nType = 0;
psm->bBarrel = 0;
while ((pszToken = ASE_ReadLine (cfP))) {
	if (*pszToken == '}')
		return 1;
	if (!strcmp (pszToken, "*NODE_NAME")) {
		strcpy (psm->szName, StrTok (" \t\""));
		if (strstr (psm->szName, "$GUNPNT"))
			psm->nGunPoint = atoi (psm->szName + 8);
		if (strstr (psm->szName, "$BULLETS"))
			psm->nBullets = 1;
		else if (strstr (psm->szName, "GLOW") != NULL) 
			psm->bGlow = 1;
		else if (strstr (psm->szName, "$DUMMY") != NULL)
			psm->bRender = 0;
		else if (strstr (psm->szName, "$THRUSTER") != NULL)
			psm->bThruster = 1;
		else if (strstr (psm->szName, "$WINGTIP") != NULL) {
			psm->bWeapon = 1;
			psm->nGun = 0;
			psm->nBomb =
			psm->nMissile = -1;
			psm->nType = atoi (psm->szName + 8) + 1;
			}
		else if (strstr (psm->szName, "$GUN") != NULL) {
			psm->bWeapon = 1;
			psm->nGun = atoi (psm->szName + 4) + 1;
			psm->nWeaponPos = atoi (psm->szName + 6) + 1;
			psm->nBomb =
			psm->nMissile = -1;
			}
		else if (strstr (psm->szName, "$BARREL") != NULL) {
			psm->bWeapon = 1;
			psm->nGun = atoi (psm->szName + 7) + 1;
			psm->nWeaponPos = atoi (psm->szName + 9) + 1;
			psm->nBomb =
			psm->nMissile = -1;
			psm->bBarrel = 1;
			}
		else if (strstr (psm->szName, "$MISSILE") != NULL) {
			psm->bWeapon = 1;
			psm->nMissile = atoi (psm->szName + 8) + 1;
			psm->nWeaponPos = atoi (psm->szName + 10) + 1;
			psm->nGun =
			psm->nBomb = -1;
			}
		else if (strstr (psm->szName, "$BOMB") != NULL) {
			psm->bWeapon = 1;
			psm->nBomb = atoi (psm->szName + 6) + 1;
			psm->nGun =
			psm->nMissile = -1;
			}
		}
	else if (!strcmp (pszToken, "*NODE_PARENT")) {
		strcpy (psm->szParent, StrTok (" \t\""));
		}
	if (!strcmp (pszToken, "*NODE_TM")) {
		if (!ASE_ReadNode (cfP, pm))
			return ASE_Error (NULL);
		}
	else if (!strcmp (pszToken, "*MESH")) {
		if (!ASE_ReadMesh (cfP, pm))
			return ASE_Error (NULL);
		}
	else if (!strcmp (pszToken, "*MATERIAL_REF")) {
		psm->nBitmap = IntTok (" \t");
		}
	}
return ASE_Error ("unexpected end of file");
}