示例#1
0
文件: various.c 项目: edwardt/pcp
void
setup_globals(pmOptions *opts)
{
	pmID		pmids[HOST_NMETRICS];
	pmDesc		descs[HOST_NMETRICS];
	pmResult	*result;

	setup_context(opts);
	setup_metrics(hostmetrics, &pmids[0], &descs[0], HOST_NMETRICS);
	fetch_metrics("host", HOST_NMETRICS, pmids, &result);

	if (HOST_NMETRICS != result->numpmid)
	{
		fprintf(stderr,
			"%s: pmFetch failed to fetch initial metric value(s)\n",
			pmProgname);
		cleanstop(1);
	}

	hertz = extract_integer(result, descs, HOST_HERTZ);
	pagesize = extract_integer(result, descs, HOST_PAGESIZE);
	extract_string(result, descs, HOST_RELEASE, sysname.release, sizeof(sysname.release));
	extract_string(result, descs, HOST_VERSION, sysname.version, sizeof(sysname.version));
	extract_string(result, descs, HOST_MACHINE, sysname.machine, sizeof(sysname.machine));
	extract_string(result, descs, HOST_NODENAME, sysname.nodename, sizeof(sysname.nodename));
	nodenamelen = strlen(sysname.nodename);

	pmFreeResult(result);
}
示例#2
0
void process_cups(struct Ferret *ferret, struct NetFrame *frame, const unsigned char *px, unsigned length)
{
	unsigned offset = 0;
	unsigned type=0;
	unsigned state = 0;
	const unsigned char *uri;
	unsigned uri_length;
	const unsigned char *location;
	unsigned location_length;
	const unsigned char *information;
	unsigned information_length;
	const unsigned char *model;
	unsigned model_length;

	extract_num(px, length, &offset, &type);
	extract_num(px, length, &offset, &state);

	extract_string(px, length, &offset, &uri, &uri_length);
	extract_string(px, length, &offset, &location, &location_length);
	extract_string(px, length, &offset, &information, &information_length);
	extract_string(px, length, &offset, &model, &model_length);

	JOTDOWN(ferret,
			JOT_SZ("proto", "CUPS"),
			JOT_SRC("ip.src", frame),
			JOT_NUM("type",type),
			0);
	JOTDOWN(ferret,
			JOT_SZ("proto", "CUPS"),
			JOT_SRC("ip.src", frame),
			JOT_NUM("state",state),
			0);
	JOTDOWN(ferret,
			JOT_SZ("proto", "CUPS"),
			JOT_SRC("ip.src", frame),
			JOT_PRINT("uri",		 	uri, uri_length),
			0);
	JOTDOWN(ferret,
			JOT_SZ("proto", "CUPS"),
			JOT_SRC("ip.src", frame),
			JOT_PRINT("location",		 	location, location_length),
			0);
	JOTDOWN(ferret,
			JOT_SZ("proto", "CUPS"),
			JOT_SRC("ip.src", frame),
			JOT_PRINT("info",		 	information, information_length),
			0);
	JOTDOWN(ferret,
			JOT_SZ("proto", "CUPS"),
			JOT_SRC("ip.src", frame),
			JOT_PRINT("model",	 	model, model_length),
			0);
}
示例#3
0
char* unquote(char *d, const char *s)
{
	int l = strlen(s);
	if (l >= 2 && (s[0] == '\"' || s[0] == '\'') && s[l-1] == s[0])
		s++, l-=2;
	return extract_string(d, s, l);
}
示例#4
0
char* unquote(char *src)
{
    int l = strlen(src);
    if (l >= 2 && (src[0] == '\"' || src[0] == '\'') && src[l-1] == src[0])
        return extract_string(src, src+1, l-2);
    return src;
}
示例#5
0
int main()
{
	parse_data();
	while(T <= 10){
		printf("Test %d:\n", T++);
		N = extract_int();
		extract_string(bracets + 1);
		M = extract_int();

		build(1, 1, N);
		while(M--){
			operation = extract_int();
			if(!operation){
				printf("%s\n", !NODES[1].opening_excessive && !NODES[1].closing_excessive ? "YES" : "NO");
				continue;
			}

			// flip it
			// and let the update propagate through segmented tree.
			bracets[operation] = bracets[operation] == ')' ? '(' : ')';
			update(1, 1, N, operation);
		}
	}

	return 0;
}
示例#6
0
void
reparse_vars::visit (t_vardecl_body &n)
{
  if (t_filename_ptr parent = n.parent ()->is<t_filename> ())
    {
      // if previous sibling is "{", this is a multi-rule
      if (n.has_prev_sibling ())
        if (token_ptr tok = n.prev_sibling ()->is<token> ())
          {
            if (tok->tok == TK_FN_LBRACE)
              {
                string_lexer lex (extract_string (n));
                lex.push_state (yy::FILENAME);
                lex.push_state (yy::MULTIFILE);
                lex.init_token (R_FILENAME);
                if (node_ptr result = parser (lex, errors) ())
                  parent->replace (n, result->as<t_filename> ().list);
              }
          }

      // if the expansion is the filename's only child, it may be a list
      // of filenames, otherwise it's part of another filename
      if (n.has_sibling ())
        {
          string_lexer lex (extract_string (n));
          lex.push_state (yy::FILENAME);
          lex.init_token (R_FILENAME);
          if (node_ptr result = parser (lex, errors) ())
            parent->replace (n, result->as<t_filename> ().list);
        }
      else if (n.parent () && (parent = n.parent ()->is<t_filename> ()))
        {
          string_lexer lex (extract_string (n));
          lex.push_state (yy::FILENAME);
          lex.init_token (TK_WHITESPACE);
          lex.init_token (R_SOURCES);
          if (node_ptr result = parser (lex, errors) ())
            parent->parent ()->replace (*parent, result->as<t_sources_members> ().list);
        }
    }
  else if (t_rule_line_ptr parent = n.parent ()->is<t_rule_line> ())
    {
      // lift all content into the parent
      parent->replace (n, n.list);
    }
}
示例#7
0
char *file_directory(char *buffer, const char *path)
{
    const char *f;
    f = file_basename(path);
    if (f >= path+2 && f[-2] != ':')
        --f;
    return extract_string(buffer, path, f-path);
}
示例#8
0
int strlistncmp(char *str, llist *list, size_t n) 
{
	llist *itr = list;
	char *asd = extract_string(list, n);
	int r;
	while (!(r = strncmp(asd, str, n)) && list != NULL) {
		free(asd);
		list = list->next;
		asd = extract_string(list, n);
	}
	free(asd);
	if (list != NULL) {
		return r;
	} else {
		return 2;
	}
}
示例#9
0
const char *nls2b(const char *p)
{
	const char *e;
	if (*p != '$' || NULL == (e = strchr(p+1, *p)))
		return p;

	++e;
	char buffer[256];
	return nls2a(extract_string(buffer, p, e-p), e);
}
示例#10
0
char *get_directory(char *buffer, const char *path)
{
	if (is_alpha(path[0]) && ':' == path[1] && IS_SLASH(path[2]))
	{
		const char *f = get_file(path);
		if (f > &path[3]) --f;
		return extract_string(buffer, path, f-path);
	}
	buffer[0] = 0;
	return buffer;
}
示例#11
0
int main(void) {
    code_t *code = load_code("./code.scm");
    printf("%s", code->code);

    string_t *str = alloc_string();
    extract_string(code, 0, str);
    printf("%s", str->contents);
    dealloc_string(str);

    free_code(code);
    return 0;
}
示例#12
0
static struct passwd *parse_pwline(char *line, struct passwd *pw)
{
	if (!strchr(line, ':')) {
		struct passwd *p = getpwnam(line);
		endpwent();
		if (!p) {
			fprintf(stderr, "pwqcheck: User not found.\n");
			return NULL;
		}
		if (p->pw_passwd)
			memset(p->pw_passwd, 0, strlen(p->pw_passwd));
		memcpy(pw, p, sizeof(*pw));
	} else {
		memset(pw, 0, sizeof(*pw));
		pw->pw_name = extract_string(&line);
		pw->pw_passwd = extract_string(&line);
		extract_string(&line); /* uid */
		extract_string(&line); /* gid */
		pw->pw_gecos = extract_string(&line);
		pw->pw_dir = extract_string(&line);
		pw->pw_shell = line ? line : "";
		if (!*pw->pw_name || !*pw->pw_dir) {
			fprintf(stderr, "pwqcheck: Invalid passwd entry.\n");
			return NULL;
		}
	}
	return pw;
}
示例#13
0
const char *get_special_command(const char **p_path, char *buffer, int size)
{
    const char *in, *a, *b;
    a = strstr(in = *p_path, ">>");
    if (NULL == a)
        return NULL;
    b = a + 2;
    skip_spc(&b);
    while (a > in && IS_SPC(a[-1]))
        --a;
    *p_path = extract_string(buffer, in, imin((int)(a-in), size-1));
    return b;
}
int tokenize_message(const char * srcString, int nBuffers, char **lpszBuffers, char *buffer_ptr, module* defmodule)
{
    int tokencount = 0;
    while (tokencount < nBuffers)
    {
        const char *a, *e;
        char  c;
        while (0 != (c = *srcString) && (unsigned char) c <= 32 ) ++srcString;
        if (0 == c) break;

        if ('\"' == c)
        {
            a = ++srcString, e = (srcString += strlen(a));
            if (e > a && e[-1] == '\"') --e;
        }
        else
        {
            a = srcString;
            while (0 != (c = *srcString) && (unsigned char) c > ' ')
            {
                ++srcString;
                //if ('$' == c) { e = strchr(srcString, c); if (e) srcString = e+1; }
            }
            e = srcString;
            while (e > a && (unsigned char) e[-1] <= 32) --e;
            if (c) ++srcString;
        }

        int len = e - a;
        extract_string(buffer_ptr, a, len);

        // Removed "buffer_ptr[0] != '@'" from the 'if'
        // dont preprocess (quoted) broams
        if (strchr(buffer_ptr, '$'))
            len = strlen(message_preprocess(buffer_ptr,defmodule));

        *lpszBuffers++ = buffer_ptr;
        buffer_ptr += len + 1;
        ++tokencount;
    }
    return tokencount;
}
示例#15
0
int get_string_within (char *dest, int size, const char **p_src, const char *delims)
{
    const char *a, *b, *p;
    char c, n, d, e;
    n = 0; /* balance-counter for nested pairs of delims */
    a = NULL;
    d = delims[0], e = delims[1];
    for (p = *p_src; 0 != (c = *p++); ) {
        if (c == d && 0 == n++) {
            a = p;
        } else if (c == e && 0 == --n) {
            b = (*p_src = p) - 1;
            while (a < b && IS_SPC(*a))
                ++a;
            while (b > a && IS_SPC(b[-1]))
                --b;
            extract_string(dest, a, imin((int)(b-a), size-1));
            return 1;
        }
    }
    *dest = 0;
    return 0;
}
示例#16
0
int main(int argc, char *argv[])
{
FILE *fp1,*fp2,*fp3;
int found,check,number_of_patches=0;
char file_name[2][50];
char temp[200];
if ( argc != 4)
{
    printf("Wrong number of arguments, \n\nUSAGE: Executable Master_file Minor_file \n\n");
    return 0;
}
printf("Master File == %s , Minor File == %s",argv[1],argv[2]);

printf("\n\nChecking Both The files for changes \n");
if((fp1=fopen(argv[1],"r")) == NULL)
{
    printf("NOT Able to open Master \n ");
    return 0;
}
//fp2=fopen("Test1","r");
fp3=fopen("result","rw");
//char file1[100],file2[100],file3[100];
char *file1,*file2;
file1= (char *) malloc (200);
file2= (char *) malloc (200);
size_t len1=0,len2=0;

while((getline(&file1,&len1,fp1) != -1 ))
{
found=0;
check =1;
//printf("Strin is %s\n",file1);
strcpy(temp,file1);
extract_string(file1);
//printf("\nArg[2]== %s\n",argv[2]);
if((fp2=fopen(argv[2],"r")) == NULL)
{
    printf("Not able to open second file");
    return 0;
}
while((getline(&file2,&len2,fp2) != -1 ))
{
//printf("Second  File content is %s== %s\n",file2,file1);
    if(!(strstr(file1,"Merge branch")))
    {
        check=0;
        if(strstr(file2,file1))
        found=1;
//printf("Hello");
//printf("Found in second file == %s",file2);
//fclose(fp2);

    }   
}
fclose(fp2);
if(found==0 && check == 0)
{
   // printf("Commit  == %s",temp);
   // printf("Commit id %s\n",commit_id);
    char temp1[LENGTH] = {0};
    char output[LENGTH] = {0};
 //   chdir("/home/ubuntu/Desktop/i915_git/linux");
    chdir(argv[3]);

    snprintf(temp1,LENGTH,"git show %s | grep \"^+\\|^-\" | wc -l",commit_id);
    FILE *fp;
    if((fp=popen(temp1,"r")) == NULL)
       {
           printf("Commit length not found");
       }
    fgets(output,450,fp); 
    pclose(fp);
    
    chdir("/home/ubuntu/Desktop/Backport/tools/29_05_14");
    remove_special_char(temp);
    format_string(output);
    format_string(temp);
    snprintf(temp1,LENGTH,"echo \" Commit  == %s and Commit lenght is %s \" >>  Result",temp,output);
    printf(".");
 //   printf("\n\nValue command is %s",temp1);
    system(temp1);
    number_of_patches++;
  // printf("Commit id %s\n",commit_id);

}
}
fclose(fp1);

free(file1);
free(file2);
printf("\nNumber of PATCHES == %d\n",number_of_patches);
printf("\nCheck Results File for Details\n");
return 0;
}
示例#17
0
文件: pamsrv_cmd.c 项目: nalind/sssd
static int pam_parse_in_data_v2(struct sss_domain_info *domains,
                                const char *default_domain,
                                struct pam_data *pd,
                                uint8_t *body, size_t blen)
{
    size_t c;
    uint32_t type;
    uint32_t size;
    char *pam_user;
    int ret;
    uint32_t start;
    uint32_t terminator;

    if (blen < 4*sizeof(uint32_t)+2) {
        DEBUG(SSSDBG_CRIT_FAILURE, "Received data is invalid.\n");
        return EINVAL;
    }

    SAFEALIGN_COPY_UINT32(&start, body, NULL);
    SAFEALIGN_COPY_UINT32(&terminator, body + blen - sizeof(uint32_t), NULL);

    if (start != SSS_START_OF_PAM_REQUEST
        || terminator != SSS_END_OF_PAM_REQUEST) {
        DEBUG(SSSDBG_CRIT_FAILURE, "Received data is invalid.\n");
        return EINVAL;
    }

    c = sizeof(uint32_t);
    do {
        SAFEALIGN_COPY_UINT32_CHECK(&type, &body[c], blen, &c);

        if (type == SSS_END_OF_PAM_REQUEST) {
            if (c != blen) return EINVAL;
        } else {
            SAFEALIGN_COPY_UINT32_CHECK(&size, &body[c], blen, &c);
            /* the uint32_t end maker SSS_END_OF_PAM_REQUEST does not count to
             * the remaining buffer */
            if (size > (blen - c - sizeof(uint32_t))) {
                DEBUG(SSSDBG_CRIT_FAILURE, "Invalid data size.\n");
                return EINVAL;
            }

            switch(type) {
                case SSS_PAM_ITEM_USER:
                    ret = extract_string(&pam_user, size, body, blen, &c);
                    if (ret != EOK) return ret;

                    ret = sss_parse_name_for_domains(pd, domains,
                                                     default_domain, pam_user,
                                                     &pd->domain, &pd->user);
                    if (ret != EOK) return ret;
                    break;
                case SSS_PAM_ITEM_SERVICE:
                    ret = extract_string(&pd->service, size, body, blen, &c);
                    if (ret != EOK) return ret;
                    break;
                case SSS_PAM_ITEM_TTY:
                    ret = extract_string(&pd->tty, size, body, blen, &c);
                    if (ret != EOK) return ret;
                    break;
                case SSS_PAM_ITEM_RUSER:
                    ret = extract_string(&pd->ruser, size, body, blen, &c);
                    if (ret != EOK) return ret;
                    break;
                case SSS_PAM_ITEM_RHOST:
                    ret = extract_string(&pd->rhost, size, body, blen, &c);
                    if (ret != EOK) return ret;
                    break;
                case SSS_PAM_ITEM_CLI_PID:
                    ret = extract_uint32_t(&pd->cli_pid, size,
                                           body, blen, &c);
                    if (ret != EOK) return ret;
                    break;
                case SSS_PAM_ITEM_AUTHTOK:
                    ret = extract_authtok_v2(pd->authtok,
                                             size, body, blen, &c);
                    if (ret != EOK) return ret;
                    break;
                case SSS_PAM_ITEM_NEWAUTHTOK:
                    ret = extract_authtok_v2(pd->newauthtok,
                                             size, body, blen, &c);
                    if (ret != EOK) return ret;
                    break;
                default:
                    DEBUG(SSSDBG_CRIT_FAILURE,
                          "Ignoring unknown data type [%d].\n", type);
                    c += size;
            }
        }

    } while(c < blen);

    if (pd->user == NULL || *pd->user == '\0') return EINVAL;

    DEBUG_PAM_DATA(SSSDBG_CONF_SETTINGS, pd);

    return EOK;

}
示例#18
0
string controller::get_string(string var_name, string default_value){
  return extract_string(file_data, var_name, default_value);
}
示例#19
0
int decode_sc_data(struct loco_config_t *loco_config, struct loco_data_t *loco_data) {
    unsigned int i, j, k, func, id, temp, png_size;
    unsigned char index, length;
    char *loco_name;
    char *proto_name;
    char *png_name;

    index = 0;
    /* preamble */
    if (memcmp(loco_config->bin, pre_mfx, 3) == 0)
	printf("type: mfx\n");
    else if (memcmp(loco_config->bin, pre_mm, 3) == 0)
	printf("type: mm\n");
    else if (memcmp(loco_config->bin, pre_other, 3) == 0)
	printf("type: other\n");
    else
	return EXIT_FAILURE;

    i = 3;

    while (i < loco_config->eeprom_size) {
	index = loco_config->bin[i++];
	length = loco_config->bin[i++];

	switch (index) {

	case 0:
	    printf("index [0x%02x @ 0x%04x] sub-index [%u]: ", index, i, length);
	    temp = loco_config->bin[i++];
	    length = (loco_config->bin[i++] << 8) + temp;
	    printf(" total length [%u]\n", length);
	    id = loco_config->bin[i++];
	    while ((id != 0) && (id != 255)) {
		length = loco_config->bin[i++];
		/* printf("i 0x%02x [i] 0x%02x length %u\n" , i, loco_config->bin[i], length); */
		switch (id) {
		case 0x1e:
		    loco_name = extract_string(&i, loco_config->bin, length);
		    if (loco_name == NULL)
			return EXIT_FAILURE;
		    loco_data->name = loco_name;
		    printf("loco name: >%s<\n", loco_name);
		    break;
		case 0x1f:
		    proto_name = extract_string(&i, loco_config->bin, length);
		    if (proto_name == NULL)
			return EXIT_FAILURE;
		    printf("proto name: >%s<\n", proto_name);
		    loco_data->type = proto_name;
		    break;
		case 0x20:
		    png_name = extract_string(&i, loco_config->bin, length);
		    if (png_name == NULL)
			return EXIT_FAILURE;
		    printf("png name: >%s<\n", png_name);
		    loco_data->icon = png_name;
		    break;
		case 0x05:
		    png_size = length + (loco_config->bin[i++] << 8);
		    printf("png start: 0x%04x  end: 0x%04x  size: 0x%04x  %u bytes\n",
			   i, i + png_size, png_size, png_size);
		    return EXIT_SUCCESS;
		default:
		    printf("decoding problem: 0x%02x\n", id);
		    break;
		}
		id = loco_config->bin[i++];
		if (id == 0)
		    id = loco_config->bin[i++];
	    }
	    break;
	/* Loco functions */
	case 9:
	    printf("index [0x%02x @ 0x%04x] length [%3d]: ", index, i, length);
	    func = 0;
	    printf("\n");
	    for (j = 0; j < length / 10; j++) {
		printf(" function %2u: ", func++);
		for (k = 0; k < 10; k++) {
		    printf(" 0x%02x", loco_config->bin[i++]);
		}
		printf("\n");
		i -= 10;
		for (k = 0; k < 10; k++) {
		    uint8_t ti = loco_config->bin[i++];
		    switch(k) {
		    case 0:
			printf(" %10s 0x%02x", loco_function_string[ti & 0x07], ti);
			break;
		    case 99: /* TODO */
			printf("\n");
			print_bitmap(&loco_config->bin[i]);
			break;
		    default:
			break;
		    }
		}
		printf("\n");
	    }
	    break;
	default:
	    printf("index [0x%02x @ 0x%04x] length [%3d]: ", index, i, length);
	    if (length <= 4)
		memcpy(&temp, loco_config->bin, length);
	    else
		temp = 0;
	    switch (index) {
	    case 1:
		loco_data->long_uid = temp;
		printf("           mfx UID ");
		break;
	    case 2:
		loco_data->uid = temp;
		printf("               UID ");
		break;
	    case 3:
		loco_data->acc_delay = temp;
		printf("acceleration delay ");
		break;
	    case 4:
		loco_data->slow_down_delay = temp;
		printf("   slow down delay ");
		break;
	    case 5:
		loco_data->vmin = temp;
		printf("              Vmin ");
		break;
	    case 6:
		loco_data->vmax = temp;
		printf("              Vmax ");
		break;
	    case 7:
		loco_data->tacho = temp;
		printf("             tacho ");
		break;
	    case 8:
		loco_data->volume = temp;
		printf("            volume ");
		break;
	    default:
		printf("           unknown ");
		break;
	    }

	    for (j = 0; j < length; j++) {
		printf(" 0x%02x", loco_config->bin[i++]);
	    }
	    break;
	}
	printf("\n");
	if (index == 0)
	    break;
    }

    return 0;
}
示例#20
0
/* NOTE: this is used for upgrading old XML-based entries file. Be wary of
         removing items.

   ### many attributes are no longer used within the old-style log files.
   ### These attrs need to be recognized for old entries, however. For these
   ### cases, the code will parse the attribute, but not set *MODIFY_FLAGS
   ### for that particular field. MODIFY_FLAGS is *only* used by the
   ### log-based entry modification system, and will go way once we
   ### completely move away from loggy.

   Set *NEW_ENTRY to a new entry, taking attributes from ATTS, whose
   keys and values are both char *.  Allocate the entry and copy
   attributes into POOL as needed. */
static svn_error_t *
atts_to_entry(svn_wc_entry_t **new_entry,
              apr_hash_t *atts,
              apr_pool_t *pool)
{
    svn_wc_entry_t *entry = alloc_entry(pool);
    const char *name;

    /* Find the name and set up the entry under that name. */
    name = svn_hash_gets(atts, ENTRIES_ATTR_NAME);
    entry->name = name ? apr_pstrdup(pool, name) : SVN_WC_ENTRY_THIS_DIR;

    /* Attempt to set revision (resolve_to_defaults may do it later, too)

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *revision_str
            = svn_hash_gets(atts, ENTRIES_ATTR_REVISION);

        if (revision_str)
            entry->revision = SVN_STR_TO_REV(revision_str);
        else
            entry->revision = SVN_INVALID_REVNUM;
    }

    /* Attempt to set up url path (again, see resolve_to_defaults).

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->url = extract_string(atts, ENTRIES_ATTR_URL, pool);
    if (entry->url)
        entry->url = svn_uri_canonicalize(entry->url, pool);

    /* Set up repository root.  Make sure it is a prefix of url.

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->repos = extract_string(atts, ENTRIES_ATTR_REPOS, pool);
    if (entry->repos)
        entry->repos = svn_uri_canonicalize(entry->repos, pool);

    if (entry->url && entry->repos
            && !svn_uri__is_ancestor(entry->repos, entry->url))
        return svn_error_createf(SVN_ERR_WC_CORRUPT, NULL,
                                 _("Entry for '%s' has invalid repository "
                                   "root"),
                                 name ? name : SVN_WC_ENTRY_THIS_DIR);

    /* Set up kind. */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *kindstr
            = svn_hash_gets(atts, ENTRIES_ATTR_KIND);

        entry->kind = svn_node_none;
        if (kindstr)
        {
            if (strcmp(kindstr, ENTRIES_VALUE_FILE) == 0)
                entry->kind = svn_node_file;
            else if (strcmp(kindstr, ENTRIES_VALUE_DIR) == 0)
                entry->kind = svn_node_dir;
            else
                return svn_error_createf
                       (SVN_ERR_NODE_UNKNOWN_KIND, NULL,
                        _("Entry '%s' has invalid node kind"),
                        (name ? name : SVN_WC_ENTRY_THIS_DIR));
        }
    }

    /* Look for a schedule attribute on this entry. */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *schedulestr
            = svn_hash_gets(atts, ENTRIES_ATTR_SCHEDULE);

        entry->schedule = svn_wc_schedule_normal;
        if (schedulestr)
        {
            if (strcmp(schedulestr, ENTRIES_VALUE_ADD) == 0)
                entry->schedule = svn_wc_schedule_add;
            else if (strcmp(schedulestr, ENTRIES_VALUE_DELETE) == 0)
                entry->schedule = svn_wc_schedule_delete;
            else if (strcmp(schedulestr, ENTRIES_VALUE_REPLACE) == 0)
                entry->schedule = svn_wc_schedule_replace;
            else if (strcmp(schedulestr, "") == 0)
                entry->schedule = svn_wc_schedule_normal;
            else
                return svn_error_createf(
                           SVN_ERR_ENTRY_ATTRIBUTE_INVALID, NULL,
                           _("Entry '%s' has invalid 'schedule' value"),
                           (name ? name : SVN_WC_ENTRY_THIS_DIR));
        }
    }

    /* Is this entry in a state of mental torment (conflict)? */
    entry->prejfile = extract_string_normalize(atts,
                      ENTRIES_ATTR_PREJFILE,
                      pool);
    entry->conflict_old = extract_string_normalize(atts,
                          ENTRIES_ATTR_CONFLICT_OLD,
                          pool);
    entry->conflict_new = extract_string_normalize(atts,
                          ENTRIES_ATTR_CONFLICT_NEW,
                          pool);
    entry->conflict_wrk = extract_string_normalize(atts,
                          ENTRIES_ATTR_CONFLICT_WRK,
                          pool);

    /* Is this entry copied? */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    SVN_ERR(do_bool_attr(&entry->copied, atts, ENTRIES_ATTR_COPIED, name));

    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->copyfrom_url = extract_string(atts, ENTRIES_ATTR_COPYFROM_URL, pool);

    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *revstr;

        revstr = svn_hash_gets(atts, ENTRIES_ATTR_COPYFROM_REV);
        if (revstr)
            entry->copyfrom_rev = SVN_STR_TO_REV(revstr);
    }

    /* Is this entry deleted?

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    SVN_ERR(do_bool_attr(&entry->deleted, atts, ENTRIES_ATTR_DELETED, name));

    /* Is this entry absent?

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    SVN_ERR(do_bool_attr(&entry->absent, atts, ENTRIES_ATTR_ABSENT, name));

    /* Is this entry incomplete?

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    SVN_ERR(do_bool_attr(&entry->incomplete, atts, ENTRIES_ATTR_INCOMPLETE,
                         name));

    /* Attempt to set up timestamps. */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *text_timestr;

        text_timestr = svn_hash_gets(atts, ENTRIES_ATTR_TEXT_TIME);
        if (text_timestr)
            SVN_ERR(svn_time_from_cstring(&entry->text_time, text_timestr, pool));

        /* Note: we do not persist prop_time, so there is no need to attempt
           to parse a new prop_time value from the log. Certainly, on any
           recent working copy, there will not be a log record to alter
           the prop_time value. */
    }

    /* Checksum. */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->checksum = extract_string(atts, ENTRIES_ATTR_CHECKSUM, pool);

    /* UUID.

       ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->uuid = extract_string(atts, ENTRIES_ATTR_UUID, pool);

    /* Setup last-committed values. */
    {
        const char *cmt_datestr, *cmt_revstr;

        cmt_datestr = svn_hash_gets(atts, ENTRIES_ATTR_CMT_DATE);
        if (cmt_datestr)
        {
            SVN_ERR(svn_time_from_cstring(&entry->cmt_date, cmt_datestr, pool));
        }
        else
            entry->cmt_date = 0;

        cmt_revstr = svn_hash_gets(atts, ENTRIES_ATTR_CMT_REV);
        if (cmt_revstr)
        {
            entry->cmt_rev = SVN_STR_TO_REV(cmt_revstr);
        }
        else
            entry->cmt_rev = SVN_INVALID_REVNUM;

        entry->cmt_author = extract_string(atts, ENTRIES_ATTR_CMT_AUTHOR, pool);
    }

    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    entry->lock_token = extract_string(atts, ENTRIES_ATTR_LOCK_TOKEN, pool);
    entry->lock_owner = extract_string(atts, ENTRIES_ATTR_LOCK_OWNER, pool);
    entry->lock_comment = extract_string(atts, ENTRIES_ATTR_LOCK_COMMENT, pool);
    {
        const char *cdate_str =
            svn_hash_gets(atts, ENTRIES_ATTR_LOCK_CREATION_DATE);
        if (cdate_str)
        {
            SVN_ERR(svn_time_from_cstring(&entry->lock_creation_date,
                                          cdate_str, pool));
        }
    }
    /* ----- end of lock handling.  */

    /* Note: if there are attributes for the (deprecated) has_props,
       has_prop_mods, cachable_props, or present_props, then we're just
       going to ignore them. */

    /* Translated size */
    /* ### not used by loggy; no need to set MODIFY_FLAGS  */
    {
        const char *val = svn_hash_gets(atts, ENTRIES_ATTR_WORKING_SIZE);
        if (val)
        {
            /* Cast to off_t; it's safe: we put in an off_t to start with... */
            entry->working_size = (apr_off_t)apr_strtoi64(val, NULL, 0);
        }
    }

    *new_entry = entry;
    return SVN_NO_ERROR;
}
示例#21
0
char* NextToken(char* buf, const char** string, const char *delims)
{
    const char *a; int n;
    n = nexttoken(&a, string, delims);
    return extract_string(buf, a, imin(n, MAX_PATH - 1));
}
示例#22
0
char *strcpy_max(char *dest, const char *src, int maxlen)
{
	return extract_string(dest, src, imin(strlen(src), maxlen-1));
}
char *message_preprocess(char *buffer, module* defmodule)
{
    char *start = buffer, *end = NULL;
    while (NULL != (start = strchr(start, '$')) && NULL != (end = strchr(start+1, '$')))
    {
        int varlen = ++end - start - 2;
        const char *replacement = NULL;
        if (varlen)
        {
            char expression[400];
            extract_string(expression, start+1, varlen);
            if (0 == memcmp(expression, "Mouse.", 6))
            {
                POINT pt;
                GetCursorPos(&pt);
                switch (expression[6]) {
                case 'X':
                    sprintf(expression, "%d", (int)pt.x-10),  replacement = expression;
                    break;
                case 'Y':
                    sprintf(expression, "%d", (int)pt.y-10),  replacement = expression;
                    break;
                }
            }
            // Check if it's indirect access
            else if (expression[0] == '*')
            {
                //Indirection.
                if (char* cnameend = strchr(expression, '.')) // Refers to a property of a control.
                {
                    char cname[64], propname[64];
                    int cnamelen = cnameend-expression-1;
                    extract_string(cname, expression+1, cnamelen);
                    extract_string(propname, cnameend+1, varlen-cnamelen-1);
                    if (control *c = control_get(variables_get(cname, NULL, defmodule),defmodule) )
                    {
                        get_property_by_name(expression, c, propname);
                        replacement = expression;
                    } else replacement = NULL; // No '.' in other variable names - we failed locating the control.
                }
                else
                {
                    const char *key = variables_get(expression+1, NULL, defmodule);
                    replacement = key ? variables_get(key,NULL, defmodule) : NULL;
                }
            }
            else
            {
                //No indirection.
                if (char* cnameend = strchr(expression, '.')) // Refers to a property of a control.
                {
                    char cname[64], propname[64];
                    int cnamelen = cnameend-expression;
                    extract_string(cname, expression, cnamelen);
                    extract_string(propname, cnameend+1, varlen-cnamelen-1);
                    // Try and look up the control with the given name
                    if (!strcmp(cname,"DroppedFile")) // "fake" properties of the DroppedFile
                    {
                        strcpy(expression, variables_get("DroppedFile", NULL, defmodule));
                        if (!strcmp(propname, "Path"))
                        {
                            char* s = strrchr(expression, '\\');
                            replacement = s ? *s = 0, expression : NULL;
                        }
                        else if (!strcmp(propname, "Name"))
                        {
                            char* s = strrchr(expression, '\\');
                            char* t = strrchr(expression, '.');
                            s = s ? s+1 : expression; // step s past final slash, or set to start
                            if (t && (t-s > 0)) *t = 0;
                            replacement = s;
                        }
                        else if (!strcmp(propname, "Extension"))
                        {
                            char* s = strrchr(expression, '.');
                            replacement = s ? s+1 : NULL;
                        }
                        else if (!strcmp(propname, "Filename"))
                        {
                            char* s = strrchr(expression, '\\');
                            replacement = s ? s+1 : NULL;
                        }
                        else replacement = NULL;
                    }
                    else if (control *c = control_get(cname, defmodule) )
                    {
                        get_property_by_name(expression, c, propname);
                        replacement = expression;
                    } else replacement = NULL; // No '.' in other variable names - we failed locating the control.

                } else
                    replacement = variables_get(expression, NULL, defmodule);
            }

        }
        else
            replacement = "$"; // default: $$ becomes $

        if (replacement)
        {
            int newlen = strlen(replacement);
            memmove(start + newlen, end, strlen(end) + 1);
            memmove(start, replacement, newlen);
            end = start + newlen;
        }
        start = end;
    }
    return buffer;
}
int
mpc_inp_str (mpc_ptr rop, FILE *stream, size_t *read, int base,
mpc_rnd_t rnd_mode)
{
   size_t white, nread = 0;
   int inex = -1;
   int c;
   char *str;

   if (stream == NULL)
      stream = stdin;

   white = skip_whitespace (stream);
   c = getc (stream);
   if (c != EOF) {
     if (c == '(') {
       char *real_str;
       char *imag_str;
       size_t n;
       int ret;

       nread++; /* the opening parenthesis */
       white = skip_whitespace (stream);
       real_str = extract_string (stream);
       nread += strlen(real_str);

       c = getc (stream);
       if (!isspace ((unsigned int) c)) {
         if (c != EOF)
           ungetc (c, stream);
         mpc_free_str (real_str);
         goto error;
       }
       else
         ungetc (c, stream);

       white += skip_whitespace (stream);
       imag_str = extract_string (stream);
       nread += strlen (imag_str);

       str = mpc_alloc_str (nread + 2);
       ret = sprintf (str, "(%s %s", real_str, imag_str);
       MPC_ASSERT (ret >= 0);
       n = (size_t) ret;
       MPC_ASSERT (n == nread + 1);
       mpc_free_str (real_str);
       mpc_free_str (imag_str);

       white += skip_whitespace (stream);
       c = getc (stream);
       if (c == ')') {
         str = mpc_realloc_str (str, nread +2, nread + 3);
         str [nread+1] = (char) c;
         str [nread+2] = '\0';
         nread++;
       }
       else if (c != EOF)
         ungetc (c, stream);
     }
     else {
       if (c != EOF)
         ungetc (c, stream);
       str = extract_string (stream);
       nread += strlen (str);
     }

     inex = mpc_set_str (rop, str, base, rnd_mode);

     mpc_free_str (str);
   }

error:
   if (inex == -1) {
      mpfr_set_nan (MPC_RE(rop));
      mpfr_set_nan (MPC_IM(rop));
   }
   if (read != NULL)
     *read = white + nread;
   return inex;
}