static void
_ifparser_source (const char *path, const char *en_dir, int quiet)
{
	char *abs_path;
	wordexp_t we;
	uint i;

	if (g_path_is_absolute (path))
		abs_path = g_strdup (path);
	else
		abs_path = g_build_filename (en_dir, path, NULL);

	if (!quiet)
		nm_log_info (LOGD_SETTINGS, "      interface-parser: source line includes interfaces file(s) %s\n", abs_path);

	/* ifupdown uses WRDE_NOCMD for wordexp. */
	if (wordexp (abs_path, &we, WRDE_NOCMD)) {
		if (!quiet)
			nm_log_warn (LOGD_SETTINGS, "word expansion for %s failed\n", abs_path);
	} else {
		for (i = 0; i < we.we_wordc; i++)
			_recursive_ifparser (we.we_wordv[i], quiet);
		wordfree (&we);
	}
	g_free (abs_path);
}
示例#2
0
char * word_expansion(char * line)
{
    //on traite les caractères spéciaux
    char * new_line = replace_char(line, "|");
    char * new_line_2 = replace_char(new_line, "<");
    char * new_line_3 = replace_char(new_line_2, ">");
    char * new_line_4 = replace_char(new_line_3, "&");
    wordexp_t result;
    wordexp(new_line_4, &result, 0);
    free(new_line_4);
    int cmd_offset = 0;
    //on calcule la longueur de la nouvelle commande
    for(int i=0; i<result.we_wordc; i++)
    {
        cmd_offset += strlen(result.we_wordv[i]);
        cmd_offset++; //derrière chaque commande, il y a un espace
    }
    //cmd_offset--;

    char * max_cmd = malloc(sizeof(char)*cmd_offset);
    //initialisation à '\0'
    for(int i=0; i<cmd_offset; i++)
        max_cmd[i] = '\0';
    int tmp_cmd_offset = 0;
    //on fait la recopie
    for(int i=0; tmp_cmd_offset<cmd_offset; i++)
    {
        strcat(max_cmd, result.we_wordv[i]);
        tmp_cmd_offset += (int)strlen(result.we_wordv[i]);
        max_cmd[tmp_cmd_offset++] = ' ';
    }
    max_cmd[cmd_offset] = '\0';
    wordfree(&result);
    return max_cmd;
}
示例#3
0
文件: pin_cmd.cpp 项目: flylucas/zsim
g_vector<g_string> PinCmd::getFullCmdArgs(uint32_t procIdx, const char** inputFile) {
    assert(procIdx < procInfo.size()); //must be one of the topmost processes
    g_vector<g_string> res = getPinCmdArgs(procIdx);

    g_string cmd = procInfo[procIdx].cmd;

    /* Loader injection: Turns out that Pin mingles with the simulated binary, which decides the loader used,
     * even when PIN_VM_LIBRARY_PATH is used. This kill the invariance on libzsim.so's loaded address, because
     * loaders in different children have different sizes. So, if specified, we prefix the program with the
     * given loader. This is optional because it won't work with statically linked binaries.
     *
     * BTW, thinking of running pin under a specific loaderto fix this instead? Nope, it gets into an infinite loop.
     */
    if (procInfo[procIdx].loader != "") {
        cmd = procInfo[procIdx].loader + " " + cmd;
        info("Injected loader on process%d, command line: %s", procIdx, cmd.c_str());
        warn("Loader injection makes Pin unaware of symbol routines, so things like routine patching"
             "will not work! You can homogeneize the loaders instead by editing the .interp ELF section");
    }

    //Parse command -- use glibc's wordexp to parse things like quotes, handle argument expansion, etc correctly
    wordexp_t p;
    wordexp(cmd.c_str(), &p, 0);
    for (uint32_t i = 0; i < p.we_wordc; i++) {
        res.push_back(g_string(p.we_wordv[i]));
    }
    wordfree(&p);

    //Input redirect
    *inputFile = (procInfo[procIdx].input == "")? nullptr : procInfo[procIdx].input.c_str();
    return res;
}
示例#4
0
string getDataDir()
{
#ifdef _WIN32
	wchar_t path[MAX_PATH];
	SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);

	wcscat(path, L"\\r");

	CreateDirectory(path, NULL);

	wstring tmp(path);

	return string(tmp.begin(), tmp.end());
#endif
#ifdef __APPLE__
	char path[1000];

	strcpy(path, "~/.r");

	wordexp_t exp_result;
	wordexp(path, &exp_result, 0);
	strcpy(path, exp_result.we_wordv[0]);
	wordfree(&exp_result); 

	mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);

	return path;
#endif
}
示例#5
0
std::string expandPath(const char* file)
{
	if (!file)
		return "";

	std::string f;
	size_t size = strlen(file);

	f.reserve(size);

	for (size_t x=0; x<size; x++)
	{
		if (file[x] == ' ')
			f.push_back('\\');

		f.push_back(file[x]);
	}

	wordexp_t exp_result;
	memset(&exp_result, 0, sizeof(wordexp_t));

	int res = wordexp(f.c_str(), &exp_result, 0);

	if (res != 0)
		return "";

	std::string r;

	if (exp_result.we_wordv[0])
		r = exp_result.we_wordv[0];

	wordfree(&exp_result);

	return r;
}
示例#6
0
const char *az_get_app_data_directory(void) {
  static char path_buffer[PATH_MAX];
  if (path_buffer[0] == '\0') {
    // First, do tilde-expansion so we get a path in the user's homedir.
    wordexp_t words;
    wordexp("~/.azimuth-game", &words, 0);
    if (words.we_wordc < 1) {
      wordfree(&words);
      return NULL;
    }
    strncpy(path_buffer, words.we_wordv[0], sizeof(path_buffer) - 1);
    wordfree(&words);
    struct stat stat_buffer;
    // Try to stat the desired path.
    if (stat(path_buffer, &stat_buffer) == 0) {
      // If the path exists but isn't a directory, we fail.
      if (!S_ISDIR(stat_buffer.st_mode)) {
        path_buffer[0] = '\0';
        return NULL;
      }
    }
    // If the directory doesn't exist, try to create it.  If we can't create
    // it, or if stat failed for some other reason, we fail.
    else if (errno != ENOENT || mkdir(path_buffer, 0700) != 0) {
      path_buffer[0] = '\0';
      return NULL;
    }
  }
  return path_buffer;
}
示例#7
0
文件: mu-util.c 项目: chrisklaiber/mu
static char*
do_wordexp (const char *path)
{
#ifdef HAVE_WORDEXP_H
	wordexp_t wexp;
	char *dir;

	if (!path) {
		/* g_debug ("%s: path is empty", __FUNCTION__); */
		return NULL;
	}

	if (wordexp (path, &wexp, 0) != 0) {
		/* g_debug ("%s: expansion failed for %s", __FUNCTION__, path); */
		return NULL;
	}

	/* we just pick the first one */
	dir = g_strdup (wexp.we_wordv[0]);

	/* strangely, below seems to lead to a crash on MacOS (BSD);
	   so we have to allow for a tiny leak here on that
	   platform... maybe instead of __APPLE__ it should be
	   __BSD__?*/
#ifndef __APPLE__
	wordfree (&wexp);
#endif /*__APPLE__*/
	return dir;

# else /*!HAVE_WORDEXP_H*/
/* E.g. OpenBSD does not have wordexp.h, so we ignore it */
	return path ? g_strdup (path) : NULL;
#endif /*HAVE_WORDEXP_H*/
}
示例#8
0
static void
mame_expand_string (gchar **p_string)
{
#if HAVE_WORDEXP_H
        wordexp_t words;

        g_return_if_fail (p_string != NULL);
        g_return_if_fail (*p_string != NULL);

        /* MAME configurations often use shell variables like $HOME
         * in its search and output paths, so we need to expand them. */
        if (wordexp (*p_string, &words, WRDE_NOCMD) == 0)
        {
                GString *buffer;
                gsize ii;

                buffer = g_string_sized_new (strlen (*p_string));
                for (ii = 0; ii < words.we_wordc; ii++)
                {
                        if (ii > 0)
                                g_string_append_c (buffer, ' ');
                        g_string_append (buffer, words.we_wordv[ii]);
                }

                g_free (*p_string);
                *p_string = g_string_free (buffer, FALSE);

                wordfree (&words);
        }
#endif
}
void NaiveAlgorithm::logPopulationStatistics()
{
    if (!currentLogFile.is_open()) {
        time_t now = time(NULL);
        std::stringstream s;
        wordexp_t directory;
        memset(&directory, 0, sizeof(wordexp_t));
        wordexp("~/temp/machines/", &directory, 0);
        s << directory.we_wordv[0];
        s << "log" << now << ".log";
        std::string filename = s.str();
        
        currentLogFile.open(filename.c_str());
    }
    
    // write generation #: <list of fitnesses>
    currentLogFile << generations << ": ";
    std::vector<SystemInfo *>::iterator popIter = population.begin();
    while (popIter != population.end()) {
        currentLogFile << (*popIter)->fitness << " ";
        popIter++;
    }
    currentLogFile << "\n";
    currentLogFile.flush();
}
示例#10
0
/* @brief Draw an image at the given offset.
 *
 * @param cr A cairo context for drawing to the screen.
 * @param file The image to be drawn.
 * @return The advance in the x direction.
 */
static uint32_t draw_image(cairo_t *cr, const char *file, offset_t offset) {
  wordexp_t expanded_file;
  if (wordexp(file, &expanded_file, 0)) {
    fprintf(stderr, "Error expanding file %s\n", file);
  } else {
    file = expanded_file.we_wordv[0];
  }

  if (access(file, F_OK) == -1) {
    fprintf(stderr, "Cannot open image file %s\n", file);
    return 0;
  }

  cairo_surface_t *img;
  img = cairo_image_surface_create_from_png(file);
  int w = cairo_image_surface_get_width(img);
  int h = cairo_image_surface_get_height(img);
  int neww = (int)(((float)(settings.height) * ((float)(w) / (float)(h))) + 0.49999999);
  img = scale_surface (img, w, h, neww, settings.height);
  h = settings.height;
  w = neww;
  /* Attempt to center the image if it is not the height of the line. */ 
  int image_offset = (h - settings.height) / 2;
  cairo_set_source_surface(cr, img, offset.x, offset.image_y - h + image_offset);
  cairo_mask_surface(cr, img, offset.x, offset.image_y - h + image_offset);

  return w;
}
示例#11
0
std::string DataDirLocater::SubstEnvVars(const std::string& in) const
{
	std::string out;
#ifdef _WIN32
	const size_t maxSize = 32 * 1024;
	char out_c[maxSize];
	ExpandEnvironmentStrings(in.c_str(), out_c, maxSize); // expands %HOME% etc.
	out = out_c;
#else
	std::string previous = in;
	for (int i = 0; i < 10; ++i) { // repeat substitution till we got a pure absolute path
		wordexp_t pwordexp;
		int r = wordexp(previous.c_str(), &pwordexp, WRDE_NOCMD); // expands $FOO, ${FOO}, ${FOO-DEF} ~/, etc.
		if (r == EXIT_SUCCESS) {
			if (pwordexp.we_wordc > 0) {
				out = pwordexp.we_wordv[0];;
				for (unsigned int w = 1; w < pwordexp.we_wordc; ++w) {
					out += " ";
					out += pwordexp.we_wordv[w];
				}
			}
			wordfree(&pwordexp);
		} else {
			out = in;
		}

		if (previous == out) {
			break;
		}
		previous.swap(out);
	}
#endif
	return out;
}
示例#12
0
static void
xdg_open_selection_cb (GtkClipboard *clipboard, const char *string, gpointer data)
{
    char *command;
    wordexp_t result;
    gboolean spawn;
    GError *spawn_error = NULL;

    command = g_strconcat ("xdg-open ", string, NULL);
    switch (wordexp (command, &result, WRDE_NOCMD)) {
        case 0:
            break;
        case WRDE_BADCHAR:
            fprintf (stderr, "'%s' contains an invalid character\n", string);
            goto finalize;
        case WRDE_CMDSUB:
            fprintf (stderr, "'%s' uses command substitution, which is not allowed\n", string);
            goto finalize;
        case WRDE_NOSPACE:
            fprintf (stderr, "Could not allocate enough memory when parsing '%s'\n", string);
            goto finalize;
        case WRDE_SYNTAX:
            fprintf (stderr, "Syntax error in '%s'\n", string);
            goto finalize;
    }
    spawn = g_spawn_async (NULL, result.we_wordv, NULL, G_SPAWN_SEARCH_PATH,
                           NULL, NULL, NULL, &spawn_error);
    if (!spawn) {
        fprintf (stderr, "%s\n", spawn_error->message);
        g_error_free (spawn_error);
    }
    finalize:
        wordfree (&result);
}
示例#13
0
文件: config.c 项目: solarce/sway
static char *get_config_path(void) {
	static const char *config_paths[] = {
		"$HOME/.sway/config",
		"$XDG_CONFIG_HOME/sway/config",
		"$HOME/.i3/config",
		"$XDG_CONFIG_HOME/i3/config",
                FALLBACK_CONFIG_DIR "/config",
		"/etc/i3/config",
	};

	if (!getenv("XDG_CONFIG_HOME")) {
		char *home = getenv("HOME");
		char *config_home = malloc(strlen("home") + strlen("/.config") + 1);
		strcpy(config_home, home);
		strcat(config_home, "/.config");
		setenv("XDG_CONFIG_HOME", config_home, 1);
		sway_log(L_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home);
	}

	wordexp_t p;
	char *path;

	int i;
	for (i = 0; i < (int)(sizeof(config_paths) / sizeof(char *)); ++i) {
		if (wordexp(config_paths[i], &p, 0) == 0) {
			path = p.we_wordv[0];
			if (file_exists(path)) {
				return path;
			}
		}
	}

	return NULL; // Not reached
}
示例#14
0
static int
glob_for_cachedir(char *path)
{
    int ret = 1;
    if (!str_endswith(path, "XXXXXX"))
	return ret;

    wordexp_t word_vector;
    char *p = solv_strdup(path);
    const int len = strlen(p);
    struct stat s;

    ret = 2;
    p[len-6] = '*';
    p[len-5] = '\0';
    if (wordexp(p, &word_vector, 0)) {
	solv_free(p);
	return ret;
    }
    for (int i = 0; i < word_vector.we_wordc; ++i) {
	char *entry = word_vector.we_wordv[i];
	if (stat(entry, &s))
	    continue;
	if (S_ISDIR(s.st_mode) &&
	    s.st_uid == getuid()) {
	    assert(strlen(path) == strlen(entry));
	    strcpy(path, entry);
	    ret = 0;
	    break;
	}
    }
    wordfree(&word_vector);
    solv_free(p);
    return ret;
}
std::string ConfigurationManager::retrieveAsPath(std::string namespaceName, std::string identifier, std::string defaultValue)
{
	std::string result = defaultValue;
	
	EntriesMap::const_iterator iter = entries->find(std::make_pair(namespaceName, identifier));
	if(iter != entries->end())
	{
		wordexp_t expansion;
		int expansionResult = 0;	

		expansionResult = wordexp(iter->second.c_str(), &expansion, WRDE_NOCMD);
		if(expansionResult == 0 && expansion.we_wordc > 0)
		{
			result.clear();

			for(int i=0;i<expansion.we_wordc;i++)
			{
				result += expansion.we_wordv[i];
			}
		}

		wordfree(&expansion);

		if(result[0] != '/') // relative path, need to prefix with workingDir
		{
			result = workingDir + result;
		}
	}

	return result;
}
示例#16
0
static int get_dclick_time (void)
{
    FILE *fp;
    char buf[256];
    int val;
    wordexp_t exp;
    struct stat st;

    // check to see if there is a gtkrc file in the home directory
    wordexp ("~/.gtkrc-2.0", &exp, 0);
    if (stat (exp.we_wordv[0], &st) != 0)
    {
        // there isn't - create one with default value
        sprintf (buf, "echo gtk-double-click-time=250 > %s", exp.we_wordv[0]);
        system (buf);
        return 250;
    }

    // there is a file - does it contain a value?
    fp = popen ("grep gtk-double-click-time ~/.gtkrc-2.0", "r");
    if (fp == NULL) return 0;  // should never happen...
    if (fgets (buf, sizeof (buf) - 1, fp) != NULL)
    {
        if (sscanf (buf, "gtk-double-click-time=%d", &val) == 1) return val;
    }

    // no matching parameter in file - prepend one
	sprintf (buf, "sed -i \"1i gtk-double-click-time=250\" %s", exp.we_wordv[0]);
    system (buf);
    return 250;
}
示例#17
0
文件: files.c 项目: arunh/c-lang
void files(void) {

    FILE *inputFile;

    //Expand filename from leading tilde
    wordexp_t exp_result;
	wordexp("~/.bash_profile", &exp_result, 0);
    char* filename = exp_result.we_wordv[0];
    
    
    int c; //getc returns an int to allow for EOF
    
    if ( (inputFile = fopen(filename, "r")) != NULL) {
        printf("Opened file: %s\n\n", filename);
        while( (c = getc(inputFile)) != EOF ) {
            putchar(c);
        }
        
        //Extraneous, for example
        if (feof(inputFile)) {
            printf("End of file confirmed!\n");
        }
        
        fclose(inputFile);
        printf("Closed file: %s\n", filename);
    }
    else {
        //stdin, stdout, stderr are always available
        fprintf(stderr, "Failed to open file: %s\n", strerror( errno ));
    }
    
}
示例#18
0
文件: config.c 项目: thejan2009/sway
char *swaynag_get_config_path(void) {
	static const char *config_paths[] = {
		"$HOME/.swaynag/config",
		"$XDG_CONFIG_HOME/swaynag/config",
		SYSCONFDIR "/swaynag/config",
	};

	char *config_home = getenv("XDG_CONFIG_HOME");
	if (!config_home || config_home[0] == '\0') {
		config_paths[1] = "$HOME/.config/swaynag/config";
	}

	wordexp_t p;
	for (size_t i = 0; i < sizeof(config_paths) / sizeof(char *); ++i) {
		if (wordexp(config_paths[i], &p, 0) == 0) {
			char *path = strdup(p.we_wordv[0]);
			wordfree(&p);
			if (file_exists(path)) {
				return path;
			}
			free(path);
		}
	}

	return NULL;
}
示例#19
0
static void expansion_demo(char const *str)
{
  printf("Before expansion: %s\n", str);

  wordexp_t exp;
  wordexp(str, &exp, 0);
  printf("After expansion: %s\n", exp.we_wordv[0]);
  wordfree(&exp);
}
示例#20
0
struct LineNode *GetLines(const char *FilePath)
{
    FILE *file = NULL;
    struct LineNode *head = NULL;
    struct LineNode *tail = NULL;
    char *currentLine = NULL;
    size_t lineLength = 0;
    wordexp_t expanded;

    memset(&expanded, 0, sizeof(wordexp_t));

    //Expand the path based on any shell characters given.
    wordexp(FilePath, &expanded, 0);
    check(expanded.we_wordv[0] != NULL, "Unable to expand file path for %s", FilePath);

    file = fopen(expanded.we_wordv[0], "r");
    check(file != NULL, "Unable to open file: %s.", FilePath);
    
    //Get the first line and set it to the head of the list.
    check(getline(&currentLine, &lineLength, file) != -1, "Unable to read line, or EOF.");

    head = GetNode(currentLine, 1);
    check(head != NULL, "Unable to get the first line of the file.");

    tail = head;

    //We have to set currentLine to NULL, otherwise 
    //we're reusing the same memory for each line...
    currentLine = NULL;

    //Get the rest of the lines...
    while(getline(&currentLine, &lineLength, file) != -1)
    {
        int LineNumber = tail->LineNumber + 1;
        struct LineNode *newNode = GetNode(currentLine, LineNumber);

        check(newNode != NULL, "Unable to get line %d.", LineNumber);

        tail->Next = newNode;
        tail = newNode;

        currentLine = NULL;
    }

    if(file)
        fclose(file);

    return head;
    
error:
    //We clean up whatever has been constructed of the linked list...
    DeleteLines(head);
    if(file)
        fclose(file);

    return NULL;
}
示例#21
0
文件: ftmenu.c 项目: taq/ftmenu
static void include_file(char *file){
	wordexp_t exp_result;
	wordexp(file,&exp_result,0);
	strcpy(file,exp_result.we_wordv[0]);
	g_print("Including %s file\n",file);
	proc_lines(file);
	g_print("Finished including %s file\n",file);
	return;
}
void Process(const char * i_lpszType, const char ** i_lpszCol_Names)
{
    XDATASET	cFile;
    XDATASET	cCombined;
    wordexp_t cResults;

    char lpszSearchFile[64];
    char lpszOutputFile[64];
    unsigned int uiColors[8][2] =
    {
        {2,4}, // u - v
        {2,3}, // u - b
        {3,4}, // b - v
        {7,5}, // uvm2 - uvw1
        {6,5}, // uvw2 - uvw1
        {7,4}, // uvm2 - v
        {6,4}, // uw2 - v
        {5,4} // uw1 - v
    };


    sprintf(lpszSearchFile,"*%s*photometry.csv",i_lpszType);
    sprintf(lpszOutputFile,"%s_photometry.csv",i_lpszType);

    if (wordexp(lpszSearchFile,&cResults,WRDE_NOCMD|WRDE_UNDEF) == 0)
    {
        if (cResults.we_wordc > 0)
        {
            printf("Count %i\n",cResults.we_wordc);
            unsigned int uiCount = cResults.we_wordc;
            for (unsigned int uiI = 0; uiI < cResults.we_wordc; uiI++)
                if (strcmp(cResults.we_wordv[uiI],lpszOutputFile) == 0)
                    uiCount--;
            if (uiCount > 0)
                cCombined.Allocate(17,uiCount);
            uiCount = 0;
            for (unsigned int uiI = 0; uiI < cResults.we_wordc; uiI++)
            {
                if (strcmp(cResults.we_wordv[uiI],lpszOutputFile) != 0)
                {

                    printf("Reading %s\n",cResults.we_wordv[uiI]);
                    cFile.ReadDataFile(cResults.we_wordv[uiI],false,false,',',1);

                    for(unsigned int uiJ = 0; uiJ < 9; uiJ++)
                        cCombined.SetElement(uiJ,uiCount,cFile.GetElement(uiJ,0));
                    for (unsigned int uiJ = 0; uiJ < 8; uiJ++)
                        cCombined.SetElement(9 + uiJ,uiCount,cFile.GetElement(uiColors[uiJ][0],0) - cFile.GetElement(uiColors[uiJ][1],0));
                    uiCount++;
                }
            }
            if (uiCount > 0)
                cCombined.SaveDataFileCSV(lpszOutputFile,i_lpszCol_Names);
            wordfree(&cResults);
        }
    }
}
示例#23
0
文件: ftmenu.c 项目: taq/ftmenu
static char* icon_file(char *menu_file, char *icon){
	wordexp_t exp_result;

	if(find_match(menu_file,"^(.*\\[begin\\]) (.*) (<)(.+)(>)",4,icon)==NULL)
		return NULL;
	wordexp(icon,&exp_result,0);
	strcpy(icon,exp_result.we_wordv[0]);
	return icon;
}
示例#24
0
文件: common.c 项目: demute/iPKCS11
char *expand_path(char *path)
{
    wordexp_t exp_result;
    wordexp(path, &exp_result, 0);
    char *expanded = strdup(exp_result.we_wordv[0]);
    wordfree(&exp_result);

    return expanded;
}
示例#25
0
/**
 * A simple ASON REPL shell.
 **/
int
main(void)
{
	ason_ns_t *ns = ason_ns_create(ASON_NS_RAM, "");
	char *line;
	ason_t *value;
	wordexp_t exp;

	if (wordexp("~/.asonq", &exp, 0))
		errx(1, "Could not perform shell expansion");

	if (! ns)
		errx(1, "Could not create namespace");

	using_history();
	read_history(exp.we_wordv[0]);

	for (;;) {
		line = readline("> ");

		if (! line) {
			printf("\n");
			break;
		}

		if (! *line) {
			free(line);
			continue;
		}

		add_history(line);
		write_history(exp.we_wordv[0]);

		if (command(line, ns)) {
			free(line);
			continue;
		}

		value = ason_ns_read(ns, line);

		free(line);

		if (! value) {
			printf("Syntax Error\n");
			continue;
		}

		line = ason_asprint_unicode(value);

		if (! line)
			errx(1, "Could not serialize value");

		printf("%s\n", line);
		free(line);
	}
}
示例#26
0
static void
command_line_test (const char *words)
{
  wordexp_t we;
  int i;
  int retval = wordexp (words, &we, 0);
  printf ("wordexp returned %d\n", retval);
  for (i = 0; i < we.we_wordc; i++)
    printf ("we_wordv[%d] = \"%s\"\n", i, we.we_wordv[i]);
}
示例#27
0
文件: glob.c 项目: bobrippling/ush
int ush_wordexp(char *s, wordexp_t *exp, int flags)
{
	int ret = wordexp(s, exp, flags);

	if(ret == 0){
		/* TODO: $(cmd), `cmd` */
	}

	return ret;
}
示例#28
0
int main(int argc, char *argv[])
{
pid_t nb_pid;
struct winsize ws;
wordexp_t env_wordexp;
char *env_progress_args;
char *env_progress_args_full;

env_progress_args = getenv("PROGRESS_ARGS");

if (env_progress_args) {
    int full_len;

    // prefix with (real) argv[0]
    // argv[0] + ' ' + env_progress_args + '\0'
    full_len = strlen(argv[0]) + 1 + strlen(env_progress_args) + 1;
    env_progress_args_full = malloc(full_len * sizeof(char));
    sprintf(env_progress_args_full, "%s %s", argv[0], env_progress_args);

    if (wordexp(env_progress_args_full, &env_wordexp, 0)) {
        fprintf(stderr,"Unable to parse PROGRESS_ARGS environment variable.\n");
        exit(EXIT_FAILURE);
    }
    parse_options(env_wordexp.we_wordc,env_wordexp.we_wordv);
}
parse_options(argc,argv);

// ws.ws_row, ws.ws_col
ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
if (flag_monitor || flag_monitor_continuous) {
    if ((mainwin = initscr()) == NULL ) {
        fprintf(stderr, "Error initialising ncurses.\n");
        exit(EXIT_FAILURE);
    }
    if (!flag_throughput) {
      flag_throughput = 1;
      throughput_wait_secs = 1;
    }
    set_hlist_size(throughput_wait_secs);
    signal(SIGINT, int_handler);
    do {
        monitor_processes(&nb_pid);
        refresh();
        if(flag_monitor_continuous && !nb_pid) {
          usleep(1000000 * throughput_wait_secs);
        }
    } while ((flag_monitor && nb_pid) || flag_monitor_continuous);
    endwin();
}
else {
    set_hlist_size(throughput_wait_secs);
    monitor_processes(&nb_pid);
}
return 0;
}
示例#29
0
文件: config.c 项目: alhazred/onarm
/*
 * Transforms the properties read from the repository for a method into a
 * method_info_t and returns a pointer to it. If expansion of the exec
 * property fails, due to an invalid string or memory allocation failure,
 * NULL is returned and exec_invalid is set appropriately to indicate whether
 * it was a memory allocation failure or an invalid exec string.
 */
static method_info_t *
create_method_info(const inetd_prop_t *mprops, boolean_t *exec_invalid)
{
	method_info_t	*ret;
	int		i;

	debug_msg("Entering create_method_info");

	if ((ret = calloc(1, sizeof (method_info_t))) == NULL)
		goto alloc_fail;

	/* Expand the exec string. */
	if ((i = wordexp(get_prop_value_string(mprops, PR_EXEC_NAME),
	    &ret->exec_args_we, WRDE_NOCMD|WRDE_UNDEF)) != 0) {
		if (i == WRDE_NOSPACE)
			goto alloc_fail;

		*exec_invalid = B_TRUE;
		free(ret);
		return (NULL);
	}

	if ((ret->exec_path = strdup(ret->exec_args_we.we_wordv[0])) == NULL)
		goto alloc_fail;

	if (mprops[MP_ARG0].ip_error == IVE_VALID) {	/* arg0 is set */
		/*
		 * Keep a copy of arg0 of the wordexp structure so that
		 * wordfree() gets passed what wordexp() originally returned,
		 * as documented as required in the man page.
		 */
		ret->wordexp_arg0_backup = ret->exec_args_we.we_wordv[0];
		if ((ret->exec_args_we.we_wordv[0] =
		    strdup(get_prop_value_string(mprops, PR_ARG0_NAME)))
		    == NULL)
			goto alloc_fail;
	}

	if (mprops[MP_TIMEOUT].ip_error == IVE_VALID) {
		ret->timeout = get_prop_value_count(mprops,
		    SCF_PROPERTY_TIMEOUT);
	} else {
		ret->timeout = DEFAULT_METHOD_TIMEOUT;
	}

	/* exec_invalid not set on success */

	return (ret);

alloc_fail:
	error_msg(strerror(errno));
	destroy_method_info(ret);
	*exec_invalid = B_FALSE;
	return (NULL);
}
示例#30
0
文件: ftmenu.c 项目: taq/ftmenu
static char* fluxbox_menu_file(char* init_file, char *menu_file){
	wordexp_t exp_result;

	if(find_match(init_file,"^(session\\.menuFile:)(.*)$",2,menu_file)==NULL){
		g_error("Could not find the menu file on config in %s",init_file);
		return NULL;
	}
	wordexp(menu_file,&exp_result,0);
	strcpy(menu_file,exp_result.we_wordv[0]);
	return menu_file;
}