Example #1
0
int obj_parse_vertex_index(int *vertex_index, int *texture_index, int *normal_index) {
    char *temp_str;
    char *token;
    int vertex_count = 0;


    while ((token = strtok(NULL, WHITESPACE)) != NULL) {
        if (texture_index != NULL)
            texture_index[vertex_count] = 0;
        if (normal_index != NULL)
            normal_index[vertex_count] = 0;

        vertex_index[vertex_count] = atoi(token);

        if (contains(token, "//"))  //normal only
        {
            temp_str = strchr(token, '/');
            temp_str++;
            normal_index[vertex_count] = atoi(++temp_str);
        }
        else if (contains(token, "/")) {
            temp_str = strchr(token, '/');
            texture_index[vertex_count] = atoi(++temp_str);

            if (contains(temp_str, "/")) {
                temp_str = strchr(temp_str, '/');
                normal_index[vertex_count] = atoi(++temp_str);
            }
        }

        vertex_count++;
    }

    return vertex_count;
}
Example #2
0
int
mailaddr_match(const struct mailaddr *maddr1, const struct mailaddr *maddr2)
{
	struct mailaddr m1 = *maddr1;
	struct mailaddr m2 = *maddr2;
	char	       *p;

	/* catchall */
	if (m2.user[0] == '\0' && m2.domain[0] == '\0')
		return 1;

	if (!hostname_match(m1.domain, m2.domain))
		return 0;

	if (m2.user[0]) {
		/* if address from table has a tag, we must respect it */
		if (strchr(m2.user, *env->sc_subaddressing_delim) == NULL) {
			/* otherwise, strip tag from session address if any */
			p = strchr(m1.user, *env->sc_subaddressing_delim);
			if (p)
				*p = '\0';
		}
		if (strcasecmp(m1.user, m2.user))
			return 0;
	}
	return 1;
}
Example #3
0
/*
 * Single-lined comments can now be logged safely, together with
 * process, thread and user ID, and the current time.
 */
void
GDKlog(const char *format, ...)
{
	va_list ap;
	char *p = 0, buf[1024];
	int mustopen = GDKgetHome();
	time_t tm = time(0);

	if (MT_pagesize() == 0)
		return;

	va_start(ap, format);
	vsprintf(buf, format, ap);
	va_end(ap);

	/* remove forbidden characters from message */
	for (p = buf; (p = strchr(p, '\n')) != NULL; *p = ' ')
		;
	for (p = buf; (p = strchr(p, '@')) != NULL; *p = ' ')
		;

	fseek(GDKlockFile, 0, SEEK_END);
#ifndef HAVE_GETUID
#define getuid() 0
#endif
	fprintf(GDKlockFile, "USR=%d PID=%d TIME=%.24s @ %s\n", (int) getuid(), (int) getpid(), ctime(&tm), buf);
	fflush(GDKlockFile);

	if (mustopen)
		GDKunlockHome();
}
Example #4
0
static int
processCompressOptions(char* opt)
{
    if (streq(opt, "none"))
        compression = COMPRESSION_NONE;
    else if (streq(opt, "packbits"))
        compression = COMPRESSION_PACKBITS;
    else if (strneq(opt, "jpeg", 4)) {
        char* cp = strchr(opt, ':');
        if (cp && isdigit(cp[1]))
            quality = atoi(cp+1);
        if (cp && strchr(cp, 'r'))
            jpegcolormode = JPEGCOLORMODE_RAW;
        compression = COMPRESSION_JPEG;
    } else if (strneq(opt, "lzw", 3)) {
        char* cp = strchr(opt, ':');
        if (cp)
            predictor = atoi(cp+1);
        compression = COMPRESSION_LZW;
    } else if (strneq(opt, "zip", 3)) {
        char* cp = strchr(opt, ':');
        if (cp)
            predictor = atoi(cp+1);
        compression = COMPRESSION_DEFLATE;
    } else
        return (0);
    return (1);
}
Example #5
0
static int *ParseNumberList(const char *InputString, int *ValuesFound)
{
    const char *str;
    int *OutputList;

    /* count the number of integers in the list */
    int values = 1;
    str = InputString;
    while ((str = strchr(str, ',')) != NULL)
    {
        str++;
        values++;
    }

    /* create a list and populate it with the frame counter values at which to take screenshots */
    if ((OutputList = (int *) malloc(sizeof(int) * (values + 1))) != NULL)
    {
        int idx = 0;
        str = InputString;
        while (str != NULL)
        {
            OutputList[idx++] = atoi(str);
            str = strchr(str, ',');
            if (str != NULL) str++;
        }
        OutputList[idx] = 0;
    }

    if (ValuesFound != NULL)
        *ValuesFound = values;
    return OutputList;
}
Example #6
0
static struct tm *
parse_date_elements(const char *day, const char *month, const char *year,
	const char *time, const char *zone)
{
    static struct tm tm;
    char *t;
    memset(&tm, 0, sizeof(tm));

    if (!day || !month || !year || !time)
	return NULL;
    tm.tm_mday = atoi(day);
    tm.tm_mon = make_month(month);
    if (tm.tm_mon < 0)
	return NULL;
    tm.tm_year = atoi(year);
    if (strlen(year) == 4)
	tm.tm_year -= 1900;
    else if (tm.tm_year < 70)
	tm.tm_year += 100;
    else if (tm.tm_year > 19000)
	tm.tm_year -= 19000;
    tm.tm_hour = make_num(time);
    t = strchr(time, ':');
    if (!t)
	return NULL;
    t++;
    tm.tm_min = atoi(t);
    t = strchr(t, ':');
    if (t)
	tm.tm_sec = atoi(t + 1);
    return tmSaneValues(&tm) ? &tm : NULL;
}
Example #7
0
PRIVATE char *tokenize(char *line)
{
  char *pos, *copy = NULL;
  int cut = -1;

  if(line){
    copy = (char *) space(strlen(line)+1);
    (void) sscanf(line, "%s", copy);
    pos = strchr(copy, '&');
    if (pos) {
      cut = (int) (pos-copy)+1;
      if (cut >= strlen(copy)) cut = -1;
      if (strchr(pos+1, '&')) nrerror("more than one cut-point in input");
      for (;*pos;pos++) *pos = *(pos+1); /* splice out the & */
    }
    if (cut > -1) {
      if (cut_point==-1) cut_point = cut;
      else if (cut_point != cut) {
        fprintf(stderr,"cut_point = %d cut = %d\n", cut_point, cut);
        nrerror("Sequence and Structure have different cut points.");
      }
    }
    free(line);
  }
  return copy;
}
Example #8
0
// extra font (experimental Windows Only)
// expra_path="path index unicodeLow-unicodeHigh"
int extra_font(SETTING* setting, FILE* log){
	if(!setting->extra_path){
		return TRUE;
	}
	const char* fontpath = setting->extra_path;
	fprintf(log,"[main/extra_font]extra path is %s\n",fontpath);
	char* next = strchr(fontpath,' ');
	if(next==NULL){
		fprintf(log,"[main/extra_font]error. separator' ' not found.\n");
		return FALSE;
	}
	char* path = (char*)malloc(next-fontpath+1);
	if(path==NULL){
		fprintf(log,"[main/extra_font]malloc failed.\n");
		return FALSE;
	}
	strncpy(path,fontpath,next-fontpath);
	path[next-fontpath] = '\0';
	int fontindex = MAX(0,atoi(next+1));
	next= strchr(next+1,' ');
	if(next==NULL){
		fprintf(log,"[main/extra_font]range unicode can not parsed:%s.\n",next);
		return FALSE;
	}
	setting->CAfont_path[EXTRA_FONT] = path;
	setting->CAfont_index[EXTRA_FONT] = fontindex;
	setting->extra_uc = next+1;
	return TRUE;
}
Example #9
0
//Checks to see if a symbol is found inside of a complex string ({ })
int nshComplex(char* var, char* symb) {
	int j,start,end,check,pos;
	check = 0;
	pos = 0;

	//Check to see if complex string is being used
	if (strchr(var,'{') != NULL && strchr(var,'}') != NULL)
	{
		//Find position of start and end of complex symbols
		for (j=0;j<strlen(var);j++)
		{

			if (var[j] == symb && pos == 0)
				pos = j;
			if (var[j] == '{')
				start = j;
			if (var[j] == '}')
				end = j;
		}
		if (start < pos && end > pos)
			check = 1;

	}

	return check;
}
Example #10
0
File: cmd.c Project: embedthis/mpr
/*
    Create a single string command to invoke - windows doesn't support exec(argv)
 */
static void prepWinCommand(MprCmd *cmd)
{
#if ME_WIN_LIKE
    /*
        WARNING: If starting a program compiled with Cygwin, there is a bug in Cygwin's parsing of the command
        string where embedded quotes are parsed incorrectly by the Cygwin CRT runtime. If an arg starts with a
        drive spec, embedded backquoted quotes will be stripped and the backquote will be passed in. Windows CRT
        handles this correctly.  For example:
            ./args "c:/path \"a b\"
            Cygwin will parse as  argv[1] == c:/path \a \b
            Windows will parse as argv[1] == c:/path "a b"
     */
    cchar   **ap, *start, *cp;
    char    *dp;
    ssize   len;
    int     argc, quote;

    /*
        Create the command line
     */
    argc = 0;
    for (len = 0, ap = cmd->argv; *ap; ap++) {
        /*
            Space and possible quotes and worst case backquoting
         */
        len += (slen(*ap) * 2) + 2 + 1;
        argc++;
    }
    cmd->command = mprAlloc(len + 1);
    cmd->command[len] = '\0';

    /*
        Add quotes around all args that have spaces and backquote double quotes.
        Example:    ["showColors", "red", "light blue", "Cannot \"render\""]
        Becomes:    "showColors" "red" "light blue" "Cannot \"render\""
     */
    dp = cmd->command;
    for (ap = &cmd->argv[0]; *ap; ) {
        start = cp = *ap;
        quote = '"';
        if (cp[0] != quote && (strchr(cp, ' ') != 0 || strchr(cp, quote) != 0)) {
            for (*dp++ = quote; *cp; ) {
                if (*cp == quote && !(cp > start && cp[-1] == '\\')) {
                    *dp++ = '\\';
                }
                *dp++ = *cp++;
            }
            *dp++ = quote;
        } else {
            strcpy(dp, cp);
            dp += strlen(cp);
        }
        if (*++ap) {
            *dp++ = ' ';
        }
    }
    *dp = '\0';
    mprLog("info mpr cmd", 6, "Windows command line: %s", cmd->command);
#endif /* ME_WIN_LIKE */
}
Example #11
0
int parse_config_line(char *line, char **option, char **value)
{
	char *p;
	int iscomment = 0;

	p = line;
	while ((p[0] == ' ') || (p[0] == '\t'))
		p++;
	if (p[0] == '\n')
		return 0;
	if (p[0] == '#')
		iscomment = 1;
	p = strchr(line, '=');
	if (!p)
		return 0;
	p[0] = '\0';
	*option = strstrip(line);
	if (*option[0] == '#')
		++(*option);
	*value  = strstrip(++p);
	p = strchr(p, '\n');
	if (p)
		p[0] = '\0';
	return iscomment ? 0 : 1;
}
Example #12
0
/*
 * Construct an Internet address representation.
 * If the nflag has been supplied, give
 * numeric value, otherwise try for symbolic name.
 */
const char *
inetname(struct sockaddr *sa)
{
	static char line[NI_MAXHOST], domain[MAXHOSTNAMELEN + 1];
	static int first = 1;
	char *cp;

	if (first && !nflag) {
		first = 0;
		if (gethostname(domain, sizeof(domain)) == 0 &&
		    (cp = strchr(domain, '.')))
			(void) strlcpy(domain, cp + 1, sizeof(domain));
		else
			domain[0] = 0;
	}
	cp = NULL;
	if (!nflag) {
		if (getnameinfo(sa, sa->sa_len, line, sizeof(line), NULL, 0,
		    NI_NAMEREQD) == 0) {
			if ((cp = strchr(line, '.')) &&
			    !strcmp(cp + 1, domain))
				*cp = 0;
			cp = line;
		}
	}
	if (cp)
		return cp;

	if (getnameinfo(sa, sa->sa_len, line, sizeof(line), NULL, 0,
	    NI_NUMERICHOST) != 0)
		strlcpy(line, "invalid", sizeof(line));
	return line;
}
Example #13
0
static void roadmap_option_set_geometry2 (const char *value) {

    char *p;
    char *geometry;
    char buffer[256];
    RoadMapConfigDescriptor descriptor;

    strncpy_safe (buffer, value, sizeof(buffer));

    geometry = strchr (buffer, '=');
    if (geometry == NULL) {
        roadmap_log (ROADMAP_FATAL,
                     "%s: invalid geometry option syntax", value);
    }
    *(geometry++) = 0;

    for (p = strchr(buffer, '-'); p != NULL; p =strchr(p, '-')) {
        *p = ' ';
    }

    descriptor.category = "Geometry";
    descriptor.name = strdup(buffer);
    descriptor.reference = NULL;
    roadmap_config_declare ("preferences", &descriptor, "300x200", NULL);
    roadmap_config_set (&descriptor, geometry);
}
Example #14
0
static int parse_conf(const char *conf,char *name,char *value)
{
	int res;
	char buf[1024];
	char *ptr;
	conf=skip_blanks(conf);
	if(*conf=='#'||*conf=='\0'||*conf=='=')
	{
		res=-1;
	}
	else
	{
		strcpy(buf,conf);
		if((ptr=strchr(buf,'='))==NULL)
			return -1;
		*ptr='\0';
		strcpy(name,trim_blanks(buf));

		ptr++;
		ptr=skip_blanks(ptr);
		if(*ptr=='\0'|| *ptr=='#')
			return -1;
		char *tmp=NULL;
		if((tmp=strchr(ptr,'#'))!=NULL)
			*tmp='\0';
		strcpy(value,trim_blanks(ptr));
		res=0;
	}
	return res;
}
Example #15
0
const char *
irc_message_get_address_from_host (const char *host)
{
    static char address[256];
    char host2[256], *pos_space, *pos;
    const char *ptr_host;

    address[0] = '\0';
    if (host)
    {
        ptr_host = host;
        pos_space = strchr (host, ' ');
        if (pos_space)
        {
            if (pos_space - host < (int)sizeof (host2))
            {
                strncpy (host2, host, pos_space - host);
                host2[pos_space - host] = '\0';
            }
            else
                snprintf (host2, sizeof (host2), "%s", host);
            ptr_host = host2;
        }

        if (ptr_host[0] == ':')
            ptr_host++;
        pos = strchr (ptr_host, '!');
        if (pos)
            snprintf (address, sizeof (address), "%s", pos + 1);
        else
            snprintf (address, sizeof (address), "%s", ptr_host);
    }

    return address;
}
Example #16
0
void reaffirm_owners()
{
  char *p, *q, s[121];
  struct userrec *u;

  /* Please stop breaking this function. */
  if (owner[0]) {
    q = owner;
    p = strchr(q, ',');
    while (p) {
      strncpyz(s, q, (p - q) + 1);
      rmspace(s);
      u = get_user_by_handle(userlist, s);
      if (u)
        u->flags = sanity_check(u->flags | USER_OWNER);
      q = p + 1;
      p = strchr(q, ',');
    }
    strcpy(s, q);
    rmspace(s);
    u = get_user_by_handle(userlist, s);
    if (u)
      u->flags = sanity_check(u->flags | USER_OWNER);
  }
}
Example #17
0
static void write_env_var(FILE *f, const char *v) {
        const char *p;

        p = strchr(v, '=');
        if (!p) {
                /* Fallback */
                fputs(v, f);
                fputc('\n', f);
                return;
        }

        p++;
        fwrite(v, 1, p-v, f);

        if (string_has_cc(p) || chars_intersect(p, WHITESPACE "\'\"\\`$")) {
                fputc('\"', f);

                for (; *p; p++) {
                        if (strchr("\'\"\\`$", *p))
                                fputc('\\', f);

                        fputc(*p, f);
                }

                fputc('\"', f);
        } else
                fputs(p, f);

        fputc('\n', f);
}
Example #18
0
int create_path(const char *path)
{
	char *start;
	mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;

	if (path[0] == '/')
		start = strchr(path + 1, '/');
	else
		start = strchr(path, '/');

	while (start) {
		char *buffer = strdup(path);
		buffer[start-path] = 0x00;

		if (mkdir(buffer, mode) == -1 && errno != EEXIST) {
			fprintf(stderr, "Problem creating directory %s", buffer);
			perror(" ");
			free(buffer);
			return -1;
		}
		free(buffer);
		start = strchr(start + 1, '/');
	}
	return 0;
}
Example #19
0
/*
 * Calculate the set of rights the user in 'auth_state' has in the ACL 'acl'.
 * 'acl' must be writable, but is restored to its original condition.
 */
EXPORTED int cyrus_acl_myrights(struct auth_state *auth_state, const char *origacl)
{
    char *acl = xstrdupsafe(origacl);
    char *thisid, *rights, *nextid;
    long acl_positive = 0, acl_negative = 0;
    long *acl_ptr;

    for (thisid = acl; *thisid; thisid = nextid) {
        acl_ptr = &acl_positive;
        rights = strchr(thisid, '\t');
        if (!rights) {
            break;
        }
        *rights++ = '\0';

        nextid = strchr(rights, '\t');
        if (!nextid) {
            rights[-1] = '\t';
            break;
        }
        *nextid++ = '\0';

        if (*thisid == '-') {
            acl_ptr = &acl_negative;
            thisid++;
        }
        if (auth_memberof(auth_state, thisid)) {
            *acl_ptr |= cyrus_acl_strtomask(rights);
        }
    }

    free(acl);

    return acl_positive & ~acl_negative;
}
Example #20
0
static int git_ssh_extract_url_parts(
	char **host,
	char **username,
	const char *url)
{
	char *colon, *at;
	const char *start;

	colon = strchr(url, ':');


	at = strchr(url, '@');
	if (at) {
		start = at + 1;
		*username = git__substrdup(url, at - url);
		GITERR_CHECK_ALLOC(*username);
	} else {
		start = url;
		*username = NULL;
	}

	if (colon == NULL || (colon < start)) {
		giterr_set(GITERR_NET, "malformed URL");
		return -1;
	}

	*host = git__substrdup(start, colon - start);
	GITERR_CHECK_ALLOC(*host);

	return 0;
}
Example #21
0
static char * cut_token(char * line)
{
  char * p;
  char * p_tab;
  char * p_space;

  p = line;

  p_space = strchr(line, ' ');
  p_tab = strchr(line, '\t');
  if (p_tab == NULL)
    p = p_space;
  else if (p_space == NULL)
    p = p_tab;
  else {
    if (p_tab < p_space)
      p = p_tab;
    else
      p = p_space;
  }
  if (p == NULL)
    return NULL;
  * p = 0;
  p ++;

  return p;
}
Example #22
0
static char *builtin_function_iftime(struct cw_channel *chan, int argc, char **argv, char *buf, size_t len)
{
    struct cw_timing timing;
    char *s, *q;

    if (argc < 4 || argc > 6 || !(s = strchr(argv[3], '?'))) {
        cw_log(LOG_ERROR, "Syntax: %s\n", if_time_func_syntax);
        return NULL;
    }
    /* Trim trailing space from the timespec */
    q = s;
    do {
        *(q--) = '\0';
    }
    while (q >= argv[3] && isspace(*q));
    pbx_extract_timing_fromargv(&timing, argc, argv);
    s++; // Move pointer after the '?' sign

    // Move pointer after ':' sign
    if ((q = strchr(s, ':'))) {
        *(q) = '\0';
        q++;
    }
    if (cw_check_timing(&timing)) {
        /* True: we want everything between '?' and ':' */
        cw_copy_string(buf, s, len);
    } else if (q && *(q) != '\0') {
        // False: we want everything after ':' (if anything) //
        cw_copy_string(buf, q, len);
    }
    return buf;
}
Example #23
0
/*
 *  Parse option string.
 */
static void __init root_nfs_parse(char *name, char *buf)
{
	char *options, *val, *cp;

	if ((options = strchr(name, ','))) {
		*options++ = 0;
		cp = strtok(options, ",");
		while (cp) {
			if ((val = strchr(cp, '='))) {
				struct nfs_int_opts *opts = root_int_opts;
				*val++ = '\0';
				while (opts->name && strcmp(opts->name, cp))
					opts++;
				if (opts->name)
					*(opts->val) = (int) simple_strtoul(val, NULL, 10);
			} else {
				struct nfs_bool_opts *opts = root_bool_opts;
				while (opts->name && strcmp(opts->name, cp))
					opts++;
				if (opts->name) {
					nfs_data.flags &= opts->and_mask;
					nfs_data.flags |= opts->or_mask;
				}
			}
			cp = strtok(NULL, ",");
		}
	}
	if (name[0] && strcmp(name, "default")) {
		strncpy(buf, name, NFS_MAXPATHLEN-1);
		buf[NFS_MAXPATHLEN-1] = 0;
	}
}
Example #24
0
/*
 * Like cli_strtok, but this puts the output into a given argument, rather
 * than allocating fresh memory
 * Returns NULL for error, or a pointer to output
 * njh@bandsman.co.uk
 */
char *cli_strtokbuf(const char *input, int fieldno, const char *delim, char *output)
{
    int counter = 0, i, j;

    /* step to arg # <fieldno> */
    for (i=0; input[i] && counter != fieldno; i++) {
	if (strchr(delim, input[i])) {
	    counter++;
	    while(input[i+1] && strchr(delim, input[i+1])) {
		i++;
	    }
	}
    }
    if (input[i] == '\0') {
	/* end of buffer before field reached */
	return NULL;
    }

    for (j=i; input[j]; j++) {
	if (strchr(delim, input[j])) {
	    break;
	}
    }
    if (i == j) {
	return NULL;
    }
    strncpy(output, input+i, j-i);
    output[j-i] = '\0';

    return output;
}
Example #25
0
//Find out how far the next line is indented
static int NextLineIndent(PCSTR input, int tabWidth)
{
    int indent = 0;
    PCSTR nextLine1 = strchr(input, '\n');
    PCSTR nextLine2 = strchr(input, '\r');
    if(nextLine2 != NULL && (nextLine1 == NULL || nextLine2 < nextLine1))
        nextLine1 = nextLine2;
    //This is the last line
    if(nextLine1 == NULL)
        return -1;
    if(*nextLine1 == '\r')
        nextLine1++;
    if(*nextLine1 == '\n')
        nextLine1++;
    while(*nextLine1 == ' ' || *nextLine1 == '\t')
    {
        indent += CharLen(*nextLine1, tabWidth);
        nextLine1++;
    }
    if(*nextLine1 == '\r' || *nextLine1 == '\n' || *nextLine1 == '\0')
    {
        //Blank lines don't have indents
        indent = -1;
    }
    
    return indent;
}
Example #26
0
/*-------------------------------------------------------------------------*
 * OCCURRENCE2                                                             *
 *                                                                         *
 *-------------------------------------------------------------------------*/
PlBool
occurrence2(char *str, PlLong c, PlLong *pos)
{
  char **info_pos;
  char *p;

  info_pos = Pl_Get_Choice_Buffer(char **); /* recover the buffer */

  if (Pl_Get_Choice_Counter() == 0) /* first invocation ? */
    {
      p = strchr(str, c);
      if (p == NULL)		/* C does not appear at all */
	{
	  Pl_No_More_Choice();	/* remove choice-point */
	  return PL_FALSE;	/* fail */
	}

      *info_pos = p;
    }
				/* info_pos = an occurrence */
  *pos = *info_pos - str;	/* set the output argument */

  p = strchr(*info_pos + 1, c);
  if (p == NULL)		/* no more occurrence */
    Pl_No_More_Choice();	/* remove choice-point */
  else
    *info_pos = p;		/* else update next solution */

  return PL_TRUE;		/* succeed */
}
/*
 * field breakup for ircd.conf file.
 */
static char *getfield(char *newline)
{
    static char *line = NULL;
    char  *end, *field;

    if (newline)
        line = newline;

    if (line == NULL)
    {
        fprintf(stderr, "returned null!\n");
        return NULL;
    }

    field = line;

    if ((end = strchr(line,':')) == NULL)
    {
        line = NULL;
        if ((end = strchr(field,'\n')) == NULL)
            end = field + strlen(field);
    }
    else
        line = end + 1;

    *end = '\0';

    return field;
}
Example #28
0
File: util.c Project: gtsong/CHAP2
/* extract a one-word name from a FastA header line */
char *fasta_name(char *line)
{
	char *buf, *s, *t;

	if (!line)
		return copy_string("");
	if (strlen(line) == 0)
		return copy_string("");
	if (line[0] != '>')
		fatal("missing FastA header line");
	buf = copy_string(line);

	// find first token after '>'
	s = buf+1;
	while (strchr(" \t", *s))
		++s;
	while (!strchr(" \t\n\0", *s))
		++s;
	*s = '\0';

	// trim trailing '|'
	while (s[-1] == '|')
		*--s = 0;

	// find last '|' delimited component
	while (!strchr(" \t>|", s[-1]))
		--s;

	t = copy_string(s);
	free(buf);
	return t;
}
Example #29
0
/* flags are of the form param; or param=value; */
void SkGraphics::SetFlags(const char* flags) {
    if (!flags) {
        return;
    }
    const char* nextSemi;
    do {
        size_t len = strlen(flags);
        const char* paramEnd = flags + len;
        const char* nextEqual = strchr(flags, '=');
        if (nextEqual && paramEnd > nextEqual) {
            paramEnd = nextEqual;
        }
        nextSemi = strchr(flags, ';');
        if (nextSemi && paramEnd > nextSemi) {
            paramEnd = nextSemi;
        }
        size_t paramLen = paramEnd - flags;
        for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
            if (paramLen != gFlags[i].fLen) {
                continue;
            }
            if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
                size_t val = 0;
                if (nextEqual) {
                    val = (size_t) atoi(nextEqual + 1);
                }
                (gFlags[i].fFunc)(val);
                break;
            }
        }
        flags = nextSemi + 1;
    } while (nextSemi);
}
Example #30
0
void
mime_tag_add (mime_var_t * obj, char *str)
{
  char *a = NULL;
  char *b = NULL;
  static char *tag[] = { "name=\"", "filename=\"", "Content-Type: " };

  a = strcasestr (str, tag[0]);
  if (a)
    {
      a += strlen (tag[0]);
      b = strchr (a, '"');
      if (!obj->name)
	obj->name = mime_substr (a, b - a);
    }

  a = strcasestr (str, tag[1]);
  if (a)
    {
      a += strlen (tag[1]);
      b = strchr (a, '"');
      if (!obj->filename)
	obj->filename = mime_substr (a, b - a);
    }

  a = strcasestr (str, tag[2]);
  if (a)
    {
      a += strlen (tag[2]);
      b = a + strlen (a);
      if (!obj->type)
	obj->type = mime_substr (a, b - a);
    }
}