コード例 #1
0
ファイル: init_tables.c プロジェクト: mjames-upc/garp
void
init_tables ( struct datatype_list *table, int *iret )
{
	char			name[256];
	char			directory[256];
	int			num;
	int			maxnum = MAXTYP;

/*
 *	Get name and location of master table.
 */
	expand_var ( "mastertbl", name );
	expand_var ( "tabledir", directory );

/*
 *	Read master table into structure.
 */
	readstn2 ( name, directory, &maxnum, &num, table, iret );
}
コード例 #2
0
ファイル: variables.c プロジェクト: BackupTheBerlios/texlive
string getval(string name)
{
  string *lookup = NULL;
  string res = NULL;

  /*
    Either the name is already in the symbol table ...
    */
  if ((lookup = hash_lookup(symtab, name)) != NULL) {
    /* FIXME: we return the first value ... */
    res = lookup[0];
    free(lookup);
  }
#if 0
  else if ((lookup = hash_lookup(symtab, vname)) != NULL) {
    /* FIXME: we return the first value ... */
    res = lookup[0];
    free(lookup);
  }
  else {
    string dollar_name = concat("$", vname);
    res = kpse_cnf_get(vname);
    free(dollar_name);
  }
#endif
  if (!res) {
#if 0
    /*
      ... Either it is known from kpathsea, in which case we put it 
      in the symbol table.
      */
    string dollar_name = concat("$", vname);
    res = expand_var(dollar_name);

    if (test_file('n', res)) {
      setval(vname, res);
    }
    else {
      /* res = "", so return NULL */
      res = NULL;
    }
    free (dollar_name);
#endif
    res = getenv(name);
  }

  if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
    fprintf(stderr, "GetVal %s => %s\n", name, res);
  }

  /* In any case ... */
  return res;
}
コード例 #3
0
ファイル: shutdownd.c プロジェクト: fcbsd/shutdownd
void
expand_warn_cmd(char *warn_cmd_tmpl, char *warn_cmd, int warn_cmd_len,
    int shutdown_mins, struct apm_power_info *apm_info)
{
	char mins[20];
	char tmpl[warn_cmd_len];

	snprintf(mins, sizeof(mins), "%d minute%s", apm_info->minutes_left,
		(apm_info->minutes_left == 1 ? "" : "s"));
	expand_var(warn_cmd_tmpl, warn_cmd, warn_cmd_len, "$battery_minutes",
	    mins);

	/* swap current buffer as template */
	strncpy(tmpl, warn_cmd, warn_cmd_len);
	bzero(warn_cmd, warn_cmd_len);

	snprintf(mins, sizeof(mins), "%d minute%s",
	    apm_info->minutes_left - shutdown_mins,
	    (apm_info->minutes_left - shutdown_mins == 1 ? "" : "s"));
	expand_var(tmpl, warn_cmd, warn_cmd_len, "$shutdown_minutes", mins);
}
コード例 #4
0
ファイル: wfdb-config.c プロジェクト: DanielEColi/wfdb
main(int argc, char **argv)
{
    char *filename, *prog_name(char *s);
    int i;
    void help(void);

    pname = prog_name(argv[0]);
    if (argc == 1) {
	help();
	exit(1);
    }

    for (i = 1; i < argc; i++) {
	if (strcmp(argv[i], "--version") == 0)
	    printf("%s\n", wfdbversion());
	else if (strcmp(argv[i], "--libs") == 0)
	    expand_var(wfdbldflags());
	else if (strcmp(argv[i], "--cflags") == 0)
	    expand_var(wfdbcflags());
	else
	    help();
    }
    exit(0);
}
コード例 #5
0
HRESULT script_preprocessor::process_import(const t_script_info & info, t_script_list & scripts)
{
    HRESULT hr = S_OK;

    if (!m_is_ok) return hr;

    for (t_size i = 0; i < m_directive_value_list.get_count(); ++i)
    {
        t_directive_value & val = m_directive_value_list[i];

        if (wcscmp(val.directive.get_ptr(), L"import") == 0)
        {
            // Try parse
            expand_var(val.value);

            pfc::array_t<wchar_t> code;
            bool success = helpers::read_file_wide(CP_ACP, val.value.get_ptr(), code);
            pfc::string_formatter msg;

            if (!success)
            {
                msg << "Error: ";
            }

            msg << WSPM_NAME " (" << info.build_info_string() << "): "
                << "Parsing file \"" << pfc::stringcvt::string_utf8_from_wide(val.value.get_ptr())
                << "\"";

            if (!success)
            {
                msg << ": Failed to load";
            }

            console::formatter() << msg;

            if (success)
            {
                t_script_code script;
                script.path = val.value;
                script.code = code;

                scripts.add_item(script);
            }
        }
    }

    return hr;
}
コード例 #6
0
bool script_preprocessor::process_script_info(t_script_info & info)
{
    bool ret = false;

    info.clear();
    if (!m_is_ok) return ret;

    for (t_size i = 0; i < m_directive_value_list.get_count(); ++i)
    {
        t_directive_value & v = m_directive_value_list[i];
        expand_var(v.value);
        pfc::string_simple value = pfc::stringcvt::string_utf8_from_wide(v.value.get_ptr());

        if (wcscmp(v.directive.get_ptr(), L"name") == 0)
        {
            ret = true;
            info.name = value;
        }
        else if (wcscmp(v.directive.get_ptr(), L"version") == 0)
        {
            ret = true;
            info.version = value;
        }
        else if (wcscmp(v.directive.get_ptr(), L"author") == 0)
        {
            ret = true;
            info.author = value;
        }
        else if (wcscmp(v.directive.get_ptr(), L"feature") == 0)
        {
            parse_directive_feature(value, info);
        }
        else if (wcscmp(v.directive.get_ptr(), L"tooltip") == 0)
        {
            if (strcmp(value.get_ptr(), "custom-paint") == 0)
            {
                info.tooltip_mask |= t_script_info::kTooltipCustomPaint;
            }
            else if (strcmp(value.get_ptr(), "custom-paint-no-background") == 0)
            {
                info.tooltip_mask |= t_script_info::kTooltipCustomPaintNoBackground;
            }
        }
    }

    return ret;
}
コード例 #7
0
ファイル: expand.cpp プロジェクト: frogshead/fish-shell
static int expand_variables_internal(parser_t &parser, wchar_t * const in, std::vector<completion_t> &out, long last_idx)
{
    int is_ok= 1;
    int empty=0;

    wcstring var_tmp;
    std::vector<long> var_idx_list;

    //  CHECK( out, 0 );

    for (long i=last_idx; (i>=0) && is_ok && !empty; i--)
    {
        const wchar_t c = in[i];
        if ((c == VARIABLE_EXPAND) || (c == VARIABLE_EXPAND_SINGLE))
        {
            long start_pos = i+1;
            long stop_pos;
            long var_len;
            int is_single = (c==VARIABLE_EXPAND_SINGLE);

            stop_pos = start_pos;

            while (1)
            {
                if (!(in[stop_pos ]))
                    break;
                if (!(iswalnum(in[stop_pos]) ||
                        (wcschr(L"_", in[stop_pos])!= 0)))
                    break;

                stop_pos++;
            }

            /*      printf( "Stop for '%c'\n", in[stop_pos]);*/

            var_len = stop_pos - start_pos;

            if (var_len == 0)
            {
                expand_variable_error(parser, in, stop_pos-1, -1);

                is_ok = 0;
                break;
            }

            var_tmp.append(in + start_pos, var_len);
            env_var_t var_val = expand_var(var_tmp.c_str());

            if (! var_val.missing())
            {
                int all_vars=1;
                wcstring_list_t var_item_list;

                if (is_ok)
                {
                    tokenize_variable_array(var_val.c_str(), var_item_list);

                    if (in[stop_pos] == L'[')
                    {
                        wchar_t *slice_end;
                        all_vars=0;

                        if (parse_slice(in + stop_pos, &slice_end, var_idx_list, var_item_list.size()))
                        {
                            parser.error(SYNTAX_ERROR,
                                         -1,
                                         L"Invalid index value");
                            is_ok = 0;
                            break;
                        }
                        stop_pos = (slice_end-in);
                    }

                    if (!all_vars)
                    {
                        wcstring_list_t string_values(var_idx_list.size());

                        for (size_t j=0; j<var_idx_list.size(); j++)
                        {
                            long tmp = var_idx_list.at(j);
                            /*
                                           Check that we are within array
                                           bounds. If not, truncate the list to
                                           exit.
                                           */
                            if (tmp < 1 || (size_t)tmp > var_item_list.size())
                            {
                                parser.error(SYNTAX_ERROR,
                                             -1,
                                             ARRAY_BOUNDS_ERR);
                                is_ok=0;
                                var_idx_list.resize(j);
                                break;
                            }
                            else
                            {
                                /* Replace each index in var_idx_list inplace with the string value at the specified index */
                                //al_set( var_idx_list, j, wcsdup((const wchar_t *)al_get( &var_item_list, tmp-1 ) ) );
                                string_values.at(j) = var_item_list.at(tmp-1);
                            }
                        }

                        // string_values is the new var_item_list
                        var_item_list.swap(string_values);
                    }
                }

                if (is_ok)
                {

                    if (is_single)
                    {
                        in[i]=0;
                        wcstring res = in;
                        res.push_back(INTERNAL_SEPARATOR);

                        for (size_t j=0; j<var_item_list.size(); j++)
                        {
                            const wcstring &next = var_item_list.at(j);
                            if (is_ok)
                            {
                                if (j != 0)
                                    res.append(L" ");
                                res.append(next);
                            }
                        }
                        res.append(in + stop_pos);
                        is_ok &= expand_variables2(parser, res, out, i);
                    }
                    else
                    {
                        for (size_t j=0; j<var_item_list.size(); j++)
                        {
                            const wcstring &next = var_item_list.at(j);
                            if (is_ok && (i == 0) && (!in[stop_pos]))
                            {
                                append_completion(out, next);
                            }
                            else
                            {

                                if (is_ok)
                                {
                                    wcstring new_in;

                                    if (start_pos > 0)
                                        new_in.append(in, start_pos - 1);

                                    // at this point new_in.size() is start_pos - 1
                                    if (start_pos>1 && new_in[start_pos-2]!=VARIABLE_EXPAND)
                                    {
                                        new_in.push_back(INTERNAL_SEPARATOR);
                                    }
                                    new_in.append(next);
                                    new_in.append(in + stop_pos);
                                    is_ok &= expand_variables2(parser, new_in, out, i);
                                }
                            }

                        }
                    }
                }

                return is_ok;
            }
            else
            {
                /*
                         Expand a non-existing variable
                         */
                if (c == VARIABLE_EXPAND)
                {
                    /*
                               Regular expansion, i.e. expand this argument to nothing
                               */
                    empty = 1;
                }
                else
                {
                    /*
                               Expansion to single argument.
                               */
                    wcstring res;
                    in[i] = 0;
                    res.append(in);
                    res.append(in + stop_pos);

                    is_ok &= expand_variables2(parser, res, out, i);
                    return is_ok;
                }
            }


        }
    }

    if (!empty)
    {
        append_completion(out, in);
    }

    return is_ok;
}
コード例 #8
0
ファイル: trigger.c プロジェクト: ajinkya93/OpenBSD
static char *
parse_cmd(int type, char *cmd, const char *repo,
    struct file_info_list *file_info)
{
	int expanded = 0;
	char argbuf[2] = { '\0', '\0' };
	char *allowed_args, *default_args, *args, *file, *p, *q = NULL;
	size_t pos;
	BUF *buf;

	switch (type) {
	case CVS_TRIGGER_COMMITINFO:
		allowed_args = "prsS{}";
		default_args = " %p/%r %S";
		file = CVS_PATH_COMMITINFO;
		break;
	case CVS_TRIGGER_LOGINFO:
		allowed_args = "prsSvVt{}";
		default_args = NULL;
		file = CVS_PATH_LOGINFO;
		break;
	case CVS_TRIGGER_VERIFYMSG:
		allowed_args = "l";
		default_args = " %l";
		file = CVS_PATH_VERIFYMSG;
		break;
	case CVS_TRIGGER_TAGINFO:
		allowed_args = "btoprsSvV{}";
		default_args = " %t %o %p/%r %{sv}";
		file = CVS_PATH_TAGINFO;
		break;
	default:
		return (NULL);
	}

	/* before doing any stuff, check if the command starts with % */
	for (p = cmd;
	     *p != '%' && !isspace((unsigned char)*p) && *p != '\0'; p++)
		;
	if (*p == '%')
		return (NULL);

	buf = buf_alloc(1024);

	p = cmd;
again:
	for (; *p != '\0'; p++) {
		if ((pos = strcspn(p, "$%")) != 0) {
			buf_append(buf, p, pos);
			p += pos;
		}

		q = NULL;
		if (*p == '\0')
			break;
		if (*p++ == '$') {
			if (*p == '{') {
				pos = strcspn(++p, "}");
				if (p[pos] == '\0')
					goto bad;
			} else {
				for (pos = 0; isalpha(p[pos]); pos++)
					;
				if (pos == 0) {
					cvs_log(LP_ERR,
					    "unrecognized variable syntax");
					goto bad;
				}
			}
			q = xmalloc(pos + 1);
			memcpy(q, p, pos);
			q[pos] = '\0';
			if (expand_var(buf, q))
				goto bad;
			p += pos - (*(p - 1) == '{' ? 0 : 1);
		} else {
			switch (*p) {
			case '\0':
				goto bad;
			case '{':
				if (strchr(allowed_args, '{') == NULL)
					goto bad;
				pos = strcspn(++p, "}");
				if (p[pos] == '\0')
					goto bad;
				q = xmalloc(pos + 1);
				memcpy(q, p, pos);
				q[pos] = '\0';
				args = q;
				p += pos;
				break;
			default:
				argbuf[0] = *p;
				args = argbuf;
				break;
			}
	
			if (expand_args(buf, file_info, repo, allowed_args,
			    args))
				goto bad;
			expanded = 1;
		}

		free(q);
	}

	if (!expanded && default_args != NULL) {
		p = default_args;
		expanded = 1;
		goto again;
	}

	buf_putc(buf, '\0');
	return (buf_release(buf));

bad:
	free(q);
	cvs_log(LP_NOTICE, "%s contains malformed command '%s'", file, cmd);
	buf_free(buf);
	return (NULL);
}
コード例 #9
0
ファイル: ssi_filter.c プロジェクト: liexusong/NXWEB
static int parse_directive(ssi_buffer* ssib, char* str, int len) {
  assert(!str[len]); // zero-terminated
  char* p=str;
  char* pe=str+len;
  char* attr_name[SSI_MAX_ATTRS];
  char* attr_value[SSI_MAX_ATTRS];
  int num_attr=0;
  while ((unsigned char)*p<=SPACE && p<pe) p++;
  if (p>=pe) return -1;
  char* cmd=p;
  while ((unsigned char)*p>SPACE) p++;
  *p++='\0';
  while (num_attr<SSI_MAX_ATTRS) {
    attr_name[num_attr]=p;
    p=strchr(p, '=');
    if (!p) break;
    *p++='\0';
    attr_name[num_attr]=nxweb_trunc_space(attr_name[num_attr]);
    while ((unsigned char)*p<=SPACE && p<pe) p++;
    if (p>=pe) return -1;
    char q=*p++;
    if (q!='\"' && q!='\'') return -1;
    attr_value[num_attr]=p;
    p=strchr(p, q);
    if (!p) return -1;
    *p++='\0';
    num_attr++;
  }

  if (!strcmp(cmd, "include")) {
    int i;
    for (i=0; i<num_attr; i++) {
      if (!strcmp(attr_name[i], "virtual")) {
        const char* expanded=expand_vars(ssib, attr_value[i]);
        if (!expanded) {
          nxweb_log_warning("ssi variables expansion failure: %s @ %s", attr_value[i], ssib->req->uri);
          return -1;
        }
        // nxweb_log_error("ssi variables expanded: %s -> %s", attr_value[i], expanded);
        nxweb_composite_stream_append_subrequest(ssib->cs, ssib->cs->req->host, expanded);
        return 0;
      }
    }
  }
  else if (!strcmp(cmd, "set")) {
    int i;
    const char* var_name=0;
    const char* var_value=0;
    nx_simple_map_entry* param;
    for (i=0; i<num_attr; i++) {
      if (!strcmp(attr_name[i], "var")) {
        var_name=attr_value[i];
      }
      else if (!strcmp(attr_name[i], "value")) {
        var_value=expand_vars(ssib, attr_value[i]);
        if (!var_value) {
          nxweb_log_warning("ssi set variable expansion failure: %s @ %s", attr_value[i], ssib->req->uri);
          return -1;
        }
        // nxweb_log_error("ssi variables expanded: %s -> %s", attr_value[i], var_value);
      }
    }
    if (var_name && var_value) {
      param=nx_simple_map_find(ssib->var_map, var_name);
      if (!param) {
        param=nxb_calloc_obj(ssib->nxb, sizeof(nx_simple_map_entry));
        ssib->var_map=nx_simple_map_add(ssib->var_map, param);
        param->name=var_name;
      }
      param->value=var_value;
      return 0;
    }
  }
  else if (!strcmp(cmd, "echo")) {
    int i;
    for (i=0; i<num_attr; i++) {
      if (!strcmp(attr_name[i], "var")) {
        const char* var_name=attr_value[i];
        char expanded[SSI_MAX_EXPR_LEN];
        char* end=expand_var(ssib, var_name, strlen(var_name), expanded, SSI_MAX_EXPR_LEN);
        if (!end) {
          // nxweb_log_warning("ssi echo variable expansion failure: %s @ %s", var_name, ssib->req->uri);
          return -1;
        }
        int len=end-expanded;
        char* buf=nxb_copy_obj(ssib->nxb, expanded, len);
        nxweb_composite_stream_append_bytes(ssib->cs, buf, len);
        return 0;
      }
    }
  }
  return -1;
}