Esempio n. 1
0
	int isdomain(char *str)
	{
		char d_ru[] = "ru";
		char d_com[] = "com";
		char d_org[] = "org";
		char *EL[MAXSIZE];
		int i;
		if (6 > slen(str))
			return 0;
		int Z = stok(str, '.', EL);
		if (!((scmp(EL[Z - 1], d_ru) == 0) || (scmp(EL[Z - 1], d_com) == 0) || (scmp(EL[Z - 1], d_org) == 0)))
		{
			suntok(str, '.', EL, Z);
			return 0;
		}
		suntok(str, '.', EL, Z);
		if (3 != Z)
			return 0;
		for (i = 0; str[i] != '\0'; i++)
		{
			if (!((str[i] >= 'A')&&(str[i] <= 'Z') || ( (str[i] >= 'a')&&(str[i] <= 'z')) || str[i] == '.' ))
				return 0;
		}
		return 1;
	}
Esempio n. 2
0
int ejsAddConstant(Ejs *ejs, EjsModule *mp, cchar *str)
{
    EjsConstants    *cp;
    ssize           len, oldLen;
    int             index;

    cp = mp->constants;
    if (cp->locked) {
        mprLog("ejs vm", 0, "Constant pool for module is locked. Cannot add constant \"%s\".",  str);
        return MPR_ERR_CANT_WRITE;
    }
    lock(mp);
    len = slen(str) + 1;
    if (ejsGrowConstants(ejs, mp, len) < 0) {
        unlock(mp);
        return MPR_ERR_MEMORY;
    }
    memcpy(&cp->pool[cp->poolLength], str, len);
    oldLen = cp->poolLength;
    cp->poolLength += len;

    mprAddKey(cp->table, str, ITOP(cp->indexCount));
    cp->index[cp->indexCount] = ITOP(oldLen << 1 | 1);
    index = cp->indexCount++;
    unlock(mp);
    return index;
}
Esempio n. 3
0
void String::InsertString(UINT dwPos, CTSTR str)
{
    assert(str);
    if(!str) return;

    assert(dwPos <= curLength);

    if(dwPos == curLength)
    {
        AppendString(str);
        return;
    }

    UINT strLength = slen(str);

    if(strLength)
    {
        lpString = (TSTR)ReAllocate(lpString, (curLength+strLength+1)*sizeof(TCHAR));

        TSTR lpPos = lpString+dwPos;
        mcpyrev(lpPos+strLength, lpPos, ((curLength+1)-dwPos)*sizeof(TCHAR));
        mcpy(lpPos, str, strLength*sizeof(TCHAR));

        curLength += strLength;
    }
}
Esempio n. 4
0
static int setContentLength(HttpConn *conn, MprList *files)
{
    MprPath     info;
    MprOff      len;
    char        *path, *pair;
    int         next;

    len = 0;
    if (app->upload) {
        httpEnableUpload(conn);
        return 0;
    }
    for (next = 0; (path = mprGetNextItem(files, &next)) != 0; ) {
        if (strcmp(path, "-") != 0) {
            if (mprGetPathInfo(path, &info) < 0) {
                mprError("Cannot access file %s", path);
                return MPR_ERR_CANT_ACCESS;
            }
            len += info.size;
        }
    }
    if (app->formData) {
        for (next = 0; (pair = mprGetNextItem(app->formData, &next)) != 0; ) {
            len += slen(pair);
        }
        len += mprGetListLength(app->formData) - 1;
    }
    if (app->bodyData) {
        len += mprGetBufLength(app->bodyData);
    }
    if (len > 0) {
        httpSetContentLength(conn, len);
    }
    return 0;
}
Esempio n. 5
0
int scmp(char m[], char n[])
//	Функция сравнения строк
{
	int i, j = 0;
	if(slen(m) == slen(n))
	{
		for(i = 0; i < slen(m); i++)
			if(m[i] == n[i])
				j++;
		if(i == j)
			return 0;
	}
	else
		return 1;
	return -1;
}
Esempio n. 6
0
static char *joinLine(cchar *str, ssize *lenp)
{
    cchar   *cp;
    char    *buf, *bp;
    ssize   len;
    int     count, bquote;

    for (count = 0, cp = str; *cp; cp++) {
        if (*cp == '\n') {
            count++;
        }
    }
    len = slen(str);
    if ((buf = mprAlloc(len + (count * 3) + 1)) == 0) {
        return 0;
    }
    bquote = 0;
    for (cp = str, bp = buf; *cp; cp++) {
        if (*cp == '\n') {
            *bp++ = '\\';
            *bp++ = 'n';
            *bp++ = '\\';
        } else if (*cp == '\\' && cp[1] != '\\') {
            bquote++;
        }
        *bp++ = *cp;
    }
    *bp = '\0';
    *lenp = len - bquote;
    return buf;
}
Esempio n. 7
0
/*
    This routine copies at most "count" characters from a string. It ensures the result is always null terminated and
    the buffer does not overflow. Returns MPR_ERR_WONT_FIT if the buffer is too small.
 */
PUBLIC ssize sncopy(char *dest, ssize destMax, cchar *src, ssize count)
{
    ssize      len;

    assert(dest);
    assert(src);
    assert(src != dest);
    assert(0 <= count && count < MAXINT);
    assert(0 < destMax && destMax < MAXINT);

    //  OPT use strnlen(src, count);
    len = slen(src);
    len = min(len, count);
    if (destMax <= len) {
        assert(!MPR_ERR_WONT_FIT);
        return MPR_ERR_WONT_FIT;
    }
    if (len > 0) {
        memcpy(dest, src, len);
        dest[len] = '\0';
    } else {
        *dest = '\0';
        len = 0;
    }
    return len;
}
Esempio n. 8
0
/*
    Trim characters from the given set. Returns a newly allocated string.
 */
PUBLIC char *strim(cchar *str, cchar *set, int where)
{
    char    *s;
    ssize   len, i;

    if (str == 0 || set == 0) {
        return 0;
    }
    if (where == 0) {
        where = MPR_TRIM_START | MPR_TRIM_END;
    }
    if (where & MPR_TRIM_START) {
        i = strspn(str, set);
    } else {
        i = 0;
    }
    s = sclone(&str[i]);
    if (where & MPR_TRIM_END) {
        len = slen(s);
        while (len > 0 && strspn(&s[len - 1], set) > 0) {
            s[len - 1] = '\0';
            len--;
        }
    }
    return s;
}
Esempio n. 9
0
/*  
    Prompt for input with the level of current nest (block nest depth)
 */
static char *readline(cchar *msg) 
{ 
    HistEvent   ev; 
    cchar       *str; 
    char        *result;
    ssize       len;
    int         count; 
 
    if (eh == NULL) { 
        eh = initEditLine();
    }
    prompt = msg;
    el_set(eh, EL_PROMPT, issuePrompt);
    el_set(eh, EL_SIGNAL, 1);
    str = el_gets(eh, &count); 
    if (str && count > 0) { 
        result = strdup(str); 
        len = slen(result);
        if (result[len - 1] == '\n') {
            result[len - 1] = '\0'; 
        }
        count = history(cmdHistory, &ev, H_ENTER, result); 
        return result; 
    }  
    return NULL; 
} 
Esempio n. 10
0
/*
    Determine the registry hive by the first portion of the path. Return
    a pointer to the rest of key path after the hive portion.
 */
static cchar *getHive(cchar *keyPath, HKEY *hive)
{
    char    key[ME_MAX_PATH], *cp;
    ssize   len;

    assert(keyPath && *keyPath);

    *hive = 0;

    scopy(key, sizeof(key), keyPath);
    key[sizeof(key) - 1] = '\0';

    if ((cp = schr(key, '\\')) != 0) {
        *cp++ = '\0';
    }
    if (cp == 0 || *cp == '\0') {
        return 0;
    }
    if (!scaselesscmp(key, "HKEY_LOCAL_MACHINE") || !scaselesscmp(key, "HKLM")) {
        *hive = HKEY_LOCAL_MACHINE;
    } else if (!scaselesscmp(key, "HKEY_CURRENT_USER") || !scaselesscmp(key, "HKCU")) {
        *hive = HKEY_CURRENT_USER;
    } else if (!scaselesscmp(key, "HKEY_USERS")) {
        *hive = HKEY_USERS;
    } else if (!scaselesscmp(key, "HKEY_CLASSES_ROOT")) {
        *hive = HKEY_CLASSES_ROOT;
    } else {
        return 0;
    }
    if (*hive == 0) {
        return 0;
    }
    len = slen(key) + 1;
    return keyPath + len;
}
Esempio n. 11
0
static char *findNewline(cchar *str, cchar *newline, ssize len, ssize *nlen)
{
    char    *start, *best;
    ssize   newlines;
    int     i;

    assert(str);
    assert(newline);
    assert(nlen);
    assert(len > 0);

    if (str == NULL || newline == NULL) {
        return NULL;
    }
    newlines = slen(newline);
    assert(newlines == 1 || newlines == 2);

    start = best = NULL;
    *nlen = 0;
    for (i = 0; i < newlines; i++) {
        if ((start = memchr(str, newline[i], len)) != 0) {
            if (best == NULL || start < best) {
                best = start;
                *nlen = 1;
                if (newlines == 2 && best[1] == newline[!i]) {
                    (*nlen)++;
                }
            }
        }
    }
    return best;
}
BOOL XFile::WriteAsUTF8(CTSTR lpBuffer, DWORD dwElements)
{
    DWORD retVal = 0;

    if(!lpBuffer)
        return false;

    if (!hFile) return false;

    if (!lpBuffer[0])
        return true;

    if(!dwElements)
        dwElements = slen(lpBuffer);

#ifdef UNICODE
    DWORD dwBytes = (DWORD)wchar_to_utf8_len(lpBuffer, dwElements, 0);
	LPSTR lpDest = (LPSTR)Allocate_Bak(dwBytes + 1);

    if (wchar_to_utf8(lpBuffer, dwElements, lpDest, dwBytes, 0))
        retVal = (Write(lpDest, dwBytes) == dwBytes);
    else
        Log(TEXT("XFile::WriteAsUTF8: wchar_to_utf8 failed: %d"), GetLastError());

    Free(lpDest);
#else
    DWORD retVal = (Write(lpBuffer, dwElements) == dwBytes);
#endif

    return retVal;
}
Esempio n. 13
0
/*
    Update menu string if text is non-null
    Update enable / disable if "enable" is non-zero. Positive will enable. Negative will disable.
    Update checked status if "check" is non-zero. Positive will enable, negative will disable.
 */
static void updateMenu(int id, char *text, int enable, int check)
{
    MENUITEMINFO    menuInfo;
    int             rc;

    if (text) {
        memset(&menuInfo, 0, sizeof(menuInfo));
        menuInfo.fMask = MIIM_STRING;
        menuInfo.cbSize = sizeof(menuInfo);
        menuInfo.fType = MFT_STRING;
        menuInfo.dwTypeData = NULL;
        menuInfo.fMask = MIIM_STRING;
        menuInfo.dwTypeData = text;
        menuInfo.cch = (uint) slen(text) + 1;
        rc = SetMenuItemInfo(app->subMenu, id, FALSE, &menuInfo);
    }
    if (enable > 0) {
        rc = EnableMenuItem(app->subMenu, id, MF_BYCOMMAND | MF_ENABLED);
    } else if (enable < 0) {
        rc = EnableMenuItem(app->subMenu, id, MF_BYCOMMAND | MF_GRAYED);
    }
    if (check > 0) {
        rc = CheckMenuItem(app->subMenu, id, MF_BYCOMMAND | MF_CHECKED);
    } else if (check < 0) {
        rc = CheckMenuItem(app->subMenu, id, MF_BYCOMMAND | MF_UNCHECKED);
    }
    rc = DrawMenuBar(app->appHwnd);
}
Esempio n. 14
0
String XConfig::ProcessString(TSTR &lpTemp)
{
    TSTR lpStart = lpTemp;

    BOOL bFoundEnd = FALSE;
    BOOL bPreviousWasEscaped = FALSE;
    while(*++lpTemp)
    {
        if (*lpTemp == '\\' && lpTemp[-1] == '\\')
        {
            bPreviousWasEscaped = TRUE;
            continue;
        }
        if(*lpTemp == '"' && (bPreviousWasEscaped || lpTemp[-1] != '\\'))
        {
            bFoundEnd = TRUE;
            break;
        }
        bPreviousWasEscaped = FALSE;
    }

    if(!bFoundEnd)
        return String();

    ++lpTemp;

    TCHAR backupChar = *lpTemp;
    *lpTemp = 0;
    String string = lpStart;
    *lpTemp = backupChar;

    if (string.Length() == 2)
        return String();

    String stringOut = string.Mid(1, string.Length()-1);
    if (stringOut.IsEmpty())
        return String();

    TSTR lpStringOut = stringOut;
    while(*lpStringOut != 0 && (lpStringOut = schr(lpStringOut, '\\')) != 0)
    {
        switch(lpStringOut[1])
        {
            case 0:     *lpStringOut = 0; break;
            case '"':   *lpStringOut = '"';  scpy(lpStringOut+1, lpStringOut+2); break;
            case 't':   *lpStringOut = '\t'; scpy(lpStringOut+1, lpStringOut+2); break;
            case 'r':   *lpStringOut = '\r'; scpy(lpStringOut+1, lpStringOut+2); break;
            case 'n':   *lpStringOut = '\n'; scpy(lpStringOut+1, lpStringOut+2); break;
            case '/':   *lpStringOut = '/';  scpy(lpStringOut+1, lpStringOut+2); break;
            case '\\':  scpy(lpStringOut+1, lpStringOut+2); break;
        }

        lpStringOut++;
    }

    stringOut.SetLength(slen(stringOut));

    return stringOut;
}
Esempio n. 15
0
int main(void)
{
  char str[] = "hello";
  rprint(str);
  printf("\n");
  printf("str's length is %d\n", slen(str));
  return 0;
}
Esempio n. 16
0
static cchar *checkFormat(EdiValidation *vp, EdiRec *rec, cchar *fieldName, cchar *value)
{
    int     matched[HTTP_MAX_ROUTE_MATCHES * 2];

    if (pcre_exec(vp->mdata, NULL, value, (int) slen(value), 0, 0, matched, sizeof(matched) / sizeof(int)) > 0) {
        return 0;
    }
    return "is in the wrong format";
}
Esempio n. 17
0
static void estTrace(void *fp, int level, char *str)
{
    level += 3;
    if (level <= websGetLogLevel()) {
        str = sclone(str);
        str[slen(str) - 1] = '\0';
        trace(level, "%s", str);
    }
}
Esempio n. 18
0
char *scat(char *s1, char *s2){
  int x=0;
  int y=slen(s2);
  while(s2[x]){
    s1[y+x]=s2[x];
    x++;
  }
  return s1;
}
Esempio n. 19
0
Public char *catList( char*dest,char*list[] ){
	if( dest==NULL||list==NULL) return dest;
	unsigned r=0;
	while( list[r]!=NULL ){
		cpyStringat( dest,list[r],slen(dest) );
		r++;
	}
	return dest;
}
Esempio n. 20
0
void length_check(char *string)
{
	int MAX_PATH = 260, length;
	length = slen(string);
	if (length > MAX_PATH)
		printf("ERROR: String is too long!\n");
	else
		printf("Length = %d\n", length);
}
Esempio n. 21
0
	int isservice(char *str)
	{
		char *EL[MAXSIZE];
		int i;
		if ((str[0] == '*') || (str[0] == '.') || (str[slen(str)-1] == '.'))
			return 0;
		if (3 > slen(str))
			return 0;
		int Z = stok(str, '.', EL);
		suntok(str, '.', EL, Z);
		if (2 != Z)
			return 0;
		for (i = 0; str[i] != '\0'; i++)
		{
			if (!((str[i] >= 'A')&&(str[i] <= 'Z') || ( (str[i] >= 'a')&&(str[i] <= 'z')) || (str[i] == '.') || (str[i] == '*') ))
				return 0;
		}
		return 1;
	}
Esempio n. 22
0
bool sstarts(cchar *str, cchar *prefix)
{
    if (str == 0 || prefix == 0) {
        return 0;
    }
    if (strncmp(str, prefix, slen(prefix)) == 0) {
        return 1;
    }
    return 0;
}
Esempio n. 23
0
PUBLIC ssize espRenderSafe(HttpConn *conn, cchar *fmt, ...)
{
    va_list     args;
    cchar       *s;

    va_start(args, fmt);
    s = mprEscapeHtml(sfmtv(fmt, args));
    va_end(args);
    return espRenderBlock(conn, s, slen(s));
}
Esempio n. 24
0
//unchecked
char *sstr(char *s, char *key){
  int x=0;
  while(&s[x]!=key&&s[x]!=0){
    x++;
  }
  if(sncmp(&s[x],key,slen(key))){
    return &s[x];
  }else{
    return 0;
  }
}
Esempio n. 25
0
static bool matchToken(cchar **str, cchar *token)
{
    ssize   len;

    len = slen(token);
    if (sncmp(*str, token, len) == 0) {
        *str += len;
        return 1;
    }
    return 0;
}
Esempio n. 26
0
void		draw_game_over(t_core *c)
{
	char const	*g = "GAME OVER ! PRESS SPACE OR ESCAPE";
	int const	l = slen(g);
	int const	w = l * (c->rdf->cw * c->rdf->s) + (l - 2) * c->rdf->p;
	int const	h = c->rdf->ch * c->rdf->s;

	(void)c;
	draw_text(c->rdf, g,
			WINDOW_WIDTH / 2 - w / 2, WINDOW_HEIGHT / 2 - h / 2);
}
Esempio n. 27
0
char *concatenate(const char *s, int n)
{
	const int l = slen(s);
	char* r = (char*)malloc(l * n + 1);
	for (int i = 0; i < l * n; i++)
	{
		*(r + i) = *(s + i % l);
	}
	*(r + l * n) = 0;
	return r;
}
Esempio n. 28
0
File: XT.cpp Progetto: robessog/OBS
void __cdecl LogRaw(const TCHAR *text, UINT len)
{
    if(!text) return;

    if (!len)
        len = slen(text);

    OpenLogFile();
    LogFile.WriteAsUTF8(text, len);
    LogFile.WriteAsUTF8(TEXT("\r\n"));
    CloseLogFile();
}
Esempio n. 29
0
File: cd.c Progetto: rdavid42/ft_p
int						cd(char *root, int *cs, char *cmd, int *id)
{
	char				**arg;
	char const			*cur = get_cwd();

	(void)id;
	arg = ssplit(cmd, ' ');
	if (scmp(root, cur, slen(root)) != 0)
		return (afree(arg), sc(cs, -2), error(CWD_DENIED), 0);
	go_dir(cs, root, cur, arg[1]);
	return (afree(arg), 1);
}
Esempio n. 30
0
SpatialException::SpatialException( const SpatialException& oldX ) throw()
{
  try {
    if(oldX.str_) {
      str_ = new char[slen(oldX.str_) + 1];
      strcpy(str_,oldX.str_);
    }
  }
  catch (...) {
    delete[] str_;
  }
}