コード例 #1
0
ファイル: CCharNPCStatus.cpp プロジェクト: bucketyied/Source
size_t CChar::NPC_OnHearName(LPCTSTR pszText) const
{
	ADDTOCALLSTACK("CChar::NPC_OnHearName");
	// Did I just hear my name in this text ?
	// should be able to deal with "hi Dennis" in the future.
	// RETURN:
	//  index to skip past the name.

	LPCTSTR pszName = GetName();

	size_t i = FindStrWord(pszText, pszName);
	if ( i )
		return i;

	// Named the chars type ? (must come first !)
	CCharBase *pCharDef = Char_GetDef();
	pszName = pCharDef->GetTradeName();
	for ( i = 0; pszText[i] != '\0'; i++ )
	{
		if ( pszName[i] == '\0' )
		{
			// found name
			while ( ISWHITESPACE(pszText[i]) )
				i++;
			return i;	// char name found
		}
		if ( toupper(pszName[i]) != toupper(pszText[i]) )	// not the name
			break;
	}

	return 0;
}
コード例 #2
0
ファイル: cvar.c プロジェクト: AidHamza/eviltoys
// we assume that prog is already set to the target progs
static void Cvar_UpdateAutoCvar(cvar_t *var)
{
	int i;
	int j;
	const char *s;
	vec3_t v;
	prvm_prog_t *prog;
	for (i = 0;i < PRVM_PROG_MAX;i++)
	{
		prog = &prvm_prog_list[i];
		if (prog->loaded && var->globaldefindex_progid[i] == prog->id)
		{
			// MUST BE SYNCED WITH prvm_edict.c PRVM_LoadProgs
			switch(prog->globaldefs[var->globaldefindex[i]].type & ~DEF_SAVEGLOBAL)
			{
			case ev_float:
				PRVM_GLOBALFIELDFLOAT(prog->globaldefs[var->globaldefindex[i]].ofs) = var->value;
				break;
			case ev_vector:
				s = var->string;
				VectorClear(v);
				for (j = 0;j < 3;j++)
				{
					while (*s && ISWHITESPACE(*s))
						s++;
					if (!*s)
						break;
					v[j] = atof(s);
					while (!ISWHITESPACE(*s))
						s++;
					if (!*s)
						break;
				}
				VectorCopy(v, PRVM_GLOBALFIELDVECTOR(prog->globaldefs[var->globaldefindex[i]].ofs));
				break;
			case ev_string:
				PRVM_ChangeEngineString(prog, var->globaldefindex_stringno[i], var->string);
				PRVM_GLOBALFIELDSTRING(prog->globaldefs[var->globaldefindex[i]].ofs) = var->globaldefindex_stringno[i];
				break;
			}
		}
	}
}
コード例 #3
0
ファイル: utils.c プロジェクト: petarov/strelko
int utils_isblank(const char *str) {
	const char *p = str;

	while(*p != '\0') {
		if (!ISWHITESPACE(*p))
			return FALSE;
		p++;
	}
	return TRUE;
}
コード例 #4
0
ファイル: cvar.c プロジェクト: MarioMario/smbnex-engine
// we assume that prog is already set to the target progs
static void Cvar_UpdateAutoCvar(cvar_t *var)
{
	int i;
	if(!prog)
		Host_Error("Cvar_UpdateAutoCvar: no prog set");
	i = PRVM_GetProgNr();
	if(var->globaldefindex_progid[i] == prog->id)
	{
		// MUST BE SYNCED WITH prvm_edict.c PRVM_LoadProgs
		int j;
		const char *s;
		vec3_t v;
		switch(prog->globaldefs[var->globaldefindex[i]].type & ~DEF_SAVEGLOBAL)
		{
			case ev_float:
				PRVM_GLOBALFIELDFLOAT(prog->globaldefs[var->globaldefindex[i]].ofs) = var->value;
				break;
			case ev_vector:
				s = var->string;
				VectorClear(v);
				for (j = 0;j < 3;j++)
				{
					while (*s && ISWHITESPACE(*s))
						s++;
					if (!*s)
						break;
					v[j] = atof(s);
					while (!ISWHITESPACE(*s))
						s++;
					if (!*s)
						break;
				}
				VectorCopy(v, PRVM_GLOBALFIELDVECTOR(prog->globaldefs[var->globaldefindex[i]].ofs));
				break;
			case ev_string:
				PRVM_ChangeEngineString(var->globaldefindex_stringno[i], var->string);
				PRVM_GLOBALFIELDSTRING(prog->globaldefs[var->globaldefindex[i]].ofs) = var->globaldefindex_stringno[i];
				break;
		}
	}
}
コード例 #5
0
ファイル: String.cpp プロジェクト: tklab-tud/uscxml
std::list<std::string> tokenize(const std::string &line, const char sep, bool trimWhiteSpace) {
	std::list<std::string> tokens;

	// appr. 3x faster than stringstream
	size_t start = 0;
	for (size_t i = 0; i < line.size(); i++) {
		if (line[i] == sep || (trimWhiteSpace && ISWHITESPACE(line[i]))) {
			if (i > 0 && start < i) {
				tokens.push_back(line.substr(start, i - start));
			}
			while (line[i] == sep || (trimWhiteSpace && ISWHITESPACE(line[i]))) {
				i++;    // skip multiple occurences of seperator and whitespaces
			}
			start = i;
		}
		if (i + 1 == line.size()) {
			tokens.push_back(line.substr(start, i + 1 - start));
		}
	}

	return tokens;
}
コード例 #6
0
ファイル: CString.cpp プロジェクト: roberpot/Source
size_t Str_TrimEndWhitespace( TCHAR * pStr, size_t len )
{
	while ( len > 0 )
	{
		len --;
		if ( pStr[len] < 0 || ! ISWHITESPACE( pStr[len] ))
		{
			++len;
			break;
		}
	}
	pStr[len] = '\0';
	return( len );
}
コード例 #7
0
ファイル: CCharNPCStatus.cpp プロジェクト: swak/Source
size_t CChar::NPC_OnHearName( LPCTSTR pszText ) const
{
	ADDTOCALLSTACK("CChar::NPC_OnHearName");
	// Did I just hear my name in this text ?
	// should be able to deal with "hi Dennis" in the future.
	// RETURN:
	//  index to skip past the name.

	LPCTSTR pszName = GetName();

	size_t i = FindStrWord( pszText, pszName );
	if ( i )
		return( i );

	if ( m_pNPC )
	{
		// My title ?
		if ( m_pNPC->m_Brain == NPCBRAIN_GUARD )
		{
			if ( ! strnicmp( pszText, "GUARD ", 6 ))
				return 6;
		}
		else if ( NPC_IsVendor())
		{
			if ( ! strnicmp( pszText, "VENDOR ", 7 ))
				return 7;
		}
	}

	CCharBase * pCharDef = Char_GetDef();

	// Named the chars type ? (must come first !)
	pszName = pCharDef->GetTradeName();
	for ( i = 0; pszText[i] != '\0'; i++ )
	{
		if ( pszName[i] == '\0' )
		{
			// found name.
			while ( ISWHITESPACE( pszText[i] ))
				i++;
			return( i );	// Char name found
		}
		if ( toupper( pszName[i] ) != toupper( pszText[i] ))	// not the name.
			break;
	}

	return( 0 );
}
コード例 #8
0
ファイル: stringhelper.cpp プロジェクト: 9drops/stunserver
    void Trim(std::string& str)
    {
        const char* psz = str.c_str();

        if (psz == NULL)
        {
            return;
        }

        int length = str.length();
        int start = -1;
        int end = -1;
        char ch;

        for (int index = 0; index < length; index++)
        {
            ch = psz[index];

            if (ISWHITESPACE(ch))
            {
                continue;
            }
            else if (start == -1)
            {
                start = index;
                end = index;
            }
            else
            {
                end = index;
            }
        }

        if (start != -1)
        {
            str = str.substr(start, end-start+1);
        }
    }
コード例 #9
0
ファイル: graysvr.cpp プロジェクト: bucketyied/Source
size_t FindStrWord( LPCTSTR pTextSearch, LPCTSTR pszKeyWord )
{
	// Find any of the pszKeyWord in the pTextSearch string.
	// Make sure we look for starts of words.

	size_t j = 0;
	for ( size_t i = 0; ; i++ )
	{
		if ( pszKeyWord[j] == '\0' || pszKeyWord[j] == ',')
		{
			if ( pTextSearch[i]== '\0' || ISWHITESPACE(pTextSearch[i]))
				return( i );
			j = 0;
		}
		if ( pTextSearch[i] == '\0' )
		{
			pszKeyWord = strchr(pszKeyWord, ',');
			if (pszKeyWord)
			{
				++pszKeyWord;
				i = 0;
				j = 0;
			}
			else
			return( 0 );
		}
		if ( j == 0 && i > 0 )
		{
			if ( IsAlpha( pTextSearch[i-1] ))	// not start of word ?
				continue;
		}
		if ( toupper( pTextSearch[i] ) == toupper( pszKeyWord[j] ))
			j++;
		else
			j = 0;
	}
}
コード例 #10
0
ファイル: quicklooknfo.c プロジェクト: Critter/QuickNFO
CFDataRef createHTMLData(CFDataRef nfo) {
    // Load HTML constants (UCS2)
    CFDataRef preNfo = createUCS2FromConst(PRE_NFO_HTML, sizeof(PRE_NFO_HTML));
    CFDataRef postNfo = createUCS2FromConst(POST_NFO_HTML, sizeof(POST_NFO_HTML));
    CFDataRef preBlock = createUCS2FromConst(PRE_BLOCK_HTML, sizeof(PRE_BLOCK_HTML));
    CFDataRef postBlock = createUCS2FromConst(POST_BLOCK_HTML, sizeof(POST_BLOCK_HTML));
    
    
    CFMutableDataRef result = CFDataCreateMutable(NULL, 0);
    
    appendCFData(result, preNfo);
    CFRelease(preNfo);
    
    const UInt8* inPtr = CFDataGetBytePtr(nfo);
	size_t inCharsLeft = CFDataGetLength(nfo) / sizeof(UInt16);
    
    const UInt8* bsPtr = inPtr;
    bool inRun = false;
    
    while (inCharsLeft-- > 0) {
        UInt16 chr = *((const UInt16*)inPtr);
        
        // Look ahead for new state
        bool newState = inRun;
        
        if(!inRun) {
            if(ISBLOCKORBOX(chr)) {
                newState = true;
            }
        } else {
            if(!ISBLOCKORBOX(chr) && !ISWHITESPACE(chr)) {
                newState = false;
            }
        }
        
        // Process change of state, append data
        if(inRun != newState) {
            if(inPtr != bsPtr) {
                if(inRun) {
                    appendCFData(result, preBlock);
                    CFDataAppendBytes(result, (const UInt8*)bsPtr, (inPtr - bsPtr));
                    appendCFData(result, postBlock);
                } else {
                    CFDataAppendBytes(result, (const UInt8*)bsPtr, (inPtr - bsPtr));
                }
                
                bsPtr = inPtr;
            }
            
            inRun = newState;
        }
        
        inPtr += sizeof(UInt16);
    }
    
    // Append trailing data
    if(inPtr > bsPtr) {
        if(inRun) {
            appendCFData(result, preBlock);
            CFDataAppendBytes(result, (const UInt8*)bsPtr, (inPtr - bsPtr));
            appendCFData(result, postBlock);
        } else {
            CFDataAppendBytes(result, (const UInt8*)bsPtr, (inPtr - bsPtr));
        }
    }
    
    CFRelease(preBlock);
    CFRelease(postBlock);
    
    appendCFData(result, postNfo);
    CFRelease(postNfo);
    
    return result;
}
コード例 #11
0
ファイル: nds_yn.c プロジェクト: tung/nethackds
char *_nds_parse_choices(const char *ques)
{
  static char choices[BUFSZ];

  char choices_by_class[MAXOCLASSES][BUFSZ / MAXOCLASSES];
  char special_choices[BUFSZ / MAXOCLASSES];

  int i;

  char *ptr = index(ques, '[');
  char last_choice = -1;
  int have_hyphen = 0;
  
  if (ptr == NULL) {
    return NULL;
  } else {
    ptr++;
  }

  for (i = 0; i < MAXOCLASSES; i++) {
    choices_by_class[i][0] = '\0';
  }

  special_choices[0] = '\0';

  for (i = 0; ptr[i] && (ptr[i] != ']'); i++) {

    struct obj *otmp;

    if (strncmp(ptr + i, " or ", 4) == 0) {
      i += 3;
    } else if (ISWHITESPACE(ptr[i])) {
      continue;
    } else if ((ptr[i] == '-') && ! ISWHITESPACE(ptr[i + 1])) {
      have_hyphen = 1;
    } else if (ptr[i] == '$') {
        _nds_insert_choice(choices_by_class[class_slot_for_class(COIN_CLASS)], ptr[i]);
    } else if (have_hyphen) {
      int j;

      for (j = last_choice + 1; j <= ptr[i]; j++) {
        int idx;

        otmp = obj_for_let(j);
        idx = class_slot_for_class(otmp->oclass);

        _nds_insert_choice(choices_by_class[idx], j);
      }

      have_hyphen = 0;
    } else {
      if ((otmp = obj_for_let(ptr[i])) != NULL) {
        int idx = class_slot_for_class(otmp->oclass);

        _nds_insert_choice(choices_by_class[idx], ptr[i]);
      } else {
        char tmp[2];

        tmp[0] = ptr[i];
        tmp[1] = '\0';

        strcat(special_choices, tmp);
      }

      last_choice = ptr[i];
    }
  }

  choices[0] = '\0';

  for (i = 0; i < MAXOCLASSES; i++) {
    strcat(choices, choices_by_class[i]);
  }

  if (*special_choices) {
    strcat(choices, " ");
    strcat(choices, special_choices);
  }

  return choices;
}
コード例 #12
0
ファイル: sys_win.c プロジェクト: paulvortex/DpOmnicide
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	MEMORYSTATUS lpBuffer;

	/* previous instances do not exist in Win32 */
	if (hPrevInstance)
		return 0;

	global_hInstance = hInstance;

	lpBuffer.dwLength = sizeof(MEMORYSTATUS);
	GlobalMemoryStatus (&lpBuffer);

	program_name[sizeof(program_name)-1] = 0;
	GetModuleFileNameA(NULL, program_name, sizeof(program_name) - 1);

	com_argc = 1;
	com_argv = argv;
	argv[0] = program_name;

	// FIXME: this tokenizer is rather redundent, call a more general one
	while (*lpCmdLine && (com_argc < MAX_NUM_ARGVS))
	{
		while (*lpCmdLine && ISWHITESPACE(*lpCmdLine))
			lpCmdLine++;

		if (!*lpCmdLine)
			break;

		if (*lpCmdLine == '\"')
		{
			// quoted string
			lpCmdLine++;
			argv[com_argc] = lpCmdLine;
			com_argc++;
			while (*lpCmdLine && (*lpCmdLine != '\"'))
				lpCmdLine++;
		}
		else
		{
			// unquoted word
			argv[com_argc] = lpCmdLine;
			com_argc++;
			while (*lpCmdLine && !ISWHITESPACE(*lpCmdLine))
				lpCmdLine++;
		}

		if (*lpCmdLine)
		{
			*lpCmdLine = 0;
			lpCmdLine++;
		}
	}

	Sys_ProvideSelfFD();

	Host_Main();

	/* return success of application */
	return true;
}