예제 #1
0
static SoupURI *
suburi_new (SoupURI   *base,
            const char *first,
            ...)
{
  va_list args;
  GPtrArray *arg_array;
  const char *arg;
  char *subpath;
  SoupURI *ret;

  arg_array = g_ptr_array_new ();
  g_ptr_array_add (arg_array, (char*)soup_uri_get_path (base));
  g_ptr_array_add (arg_array, (char*)first);

  va_start (args, first);
  
  while ((arg = va_arg (args, const char *)) != NULL)
    g_ptr_array_add (arg_array, (char*)arg);
  g_ptr_array_add (arg_array, NULL);

  subpath = g_build_filenamev ((char**)arg_array->pdata);
  g_ptr_array_unref (arg_array);
  
  ret = soup_uri_copy (base);
  soup_uri_set_path (ret, subpath);
  g_free (subpath);
  
  va_end (args);
  
  return ret;
}
예제 #2
0
GFile *
ot_gfile_from_build_path (const char *first, ...)
{
  va_list args;
  const char *arg;
  ot_lfree char *path = NULL;
  ot_lptrarray GPtrArray *components = NULL;  

  va_start (args, first);

  components = g_ptr_array_new ();
  
  arg = first;
  while (arg != NULL)
    {
      g_ptr_array_add (components, (char*)arg);
      arg = va_arg (args, const char *);
    }

  va_end (args);

  g_ptr_array_add (components, NULL);

  path = g_build_filenamev ((char**)components->pdata);

  return g_file_new_for_path (path);
}
예제 #3
0
파일: helper.c 프로젝트: alepez/rofi
char *rofi_expand_path ( const char *input )
{
    char **str = g_strsplit ( input, G_DIR_SEPARATOR_S, -1 );
    for ( unsigned int i = 0; str && str[i]; i++ ) {
        // Replace ~ with current user homedir.
        if ( str[i][0] == '~' && str[i][1] == '\0' ) {
            g_free ( str[i] );
            str[i] = g_strdup ( g_get_home_dir () );
        }
        // If other user, ask getpwnam.
        else if ( str[i][0] == '~' ) {
            struct passwd *p = getpwnam ( &( str[i][1] ) );
            if ( p != NULL ) {
                g_free ( str[i] );
                str[i] = g_strdup ( p->pw_dir );
            }
        }
        else if ( i == 0 ) {
            char * s = str[i];
            if ( input[0] == G_DIR_SEPARATOR ) {
                str[i] = g_strdup_printf ( "%s%s", G_DIR_SEPARATOR_S, s );
                g_free ( s );
            }
        }
    }
    char *retv = g_build_filenamev ( str );
    g_strfreev ( str );
    return retv;
}
예제 #4
0
GFile *
ot_gfile_get_child_build_path (GFile      *parent,
                               const char *first, ...)
{
  va_list args;
  const char *arg;
  g_autofree char *path = NULL;
  g_autoptr(GPtrArray) components = NULL;  

  va_start (args, first);

  components = g_ptr_array_new ();
  
  arg = first;
  while (arg != NULL)
    {
      g_ptr_array_add (components, (char*)arg);
      arg = va_arg (args, const char *);
    }

  va_end (args);

  g_ptr_array_add (components, NULL);

  path = g_build_filenamev ((char**)components->pdata);

  return g_file_resolve_relative_path (parent, path);
}
예제 #5
0
/* Normalize a pathname. This collapses redundant separators and up-level references so that A//B, A/./B
 * and A/foo/../B all become A/B. It does not normalize the case. On Windows, it converts forward
 * slashes to backward slashes. It should be understood that this may change the meaning of the
 * path if it contains symbolic links!
 */
gchar *
normpath(const gchar * filename)
{
	gchar **v;
	gchar **p;
	gchar **out;
	gchar **pout;
	gchar *ret;

	if (!filename || strlen(filename) == 0)
		return g_strdup(".");
	v = g_strsplit_set(filename, "/\\", -1);
	if (!g_strv_length(v))
		return g_strdup(".");

	out = g_malloc0(sizeof(gchar *) * (g_strv_length(v) + 2));
	pout = out;

	if (filename[0] == '.' && strcmp(v[0], ".") == 0)
	{
		*pout = strdup(".");
		pout++;
	}
	else if (filename[0] == '/')
	{
		*pout = strdup("/");
		pout++;
	}

	for (p = v; *p; p++)
	{
		if (strcmp(*p, ".") == 0 || strcmp(*p, "") == 0)
		{
			continue;
		}
		else if (strcmp(*p, "..") == 0)
		{
			if (pout != out)
			{
				pout--;
				if (strcmp(*pout, "..") != 0)
				{
					g_free(*pout);
					*pout = NULL;
					continue;
				}
				pout++;
			}
		}
		*pout++ = g_strdup(*p);
	}

	ret = g_build_filenamev(out);

	g_strfreev(out);
	g_strfreev(v);
	return ret;
}
예제 #6
0
/* Always return an absolute filename and treat all absolute path elements as
 * absolute, not just the first one, e.g.
 *     ("/foo", "/bar", NULL) returns "/bar"
 * (g_build_filename would return "/foo/bar")
 * Returned path may still include '..' path elements.
 */
static char *
build_absolute_filename(const char *first_element,
                        ...)
{
    const char *element;
    va_list ap;
    char *cwd;
    char *path;
    GPtrArray *array;

    cwd = g_get_current_dir();

    array = g_ptr_array_new();

    g_ptr_array_add(array, cwd);

    va_start(ap, first_element);

    element = first_element;
    while (element != NULL) {
        if (g_path_is_absolute(element))
            g_ptr_array_set_size(array, 0);

        g_ptr_array_add(array, (char*)element);

        element = va_arg(ap, const char *);
    }
    va_end(ap);

    g_ptr_array_add(array, NULL);

    path = g_build_filenamev((char **)array->pdata);

    g_ptr_array_free(array, TRUE);

    g_free(cwd);

    return path;
}
예제 #7
0
파일: pkg-path.c 프로젝트: jjardon/perfkit
gchar*
pkg_path_for_data (const gchar *first_path, ...)
{
	GPtrArray *strv;
	va_list args;
	gchar *arg;

	g_return_val_if_fail(first_path != NULL, NULL);

	ENTRY;
	strv = g_ptr_array_new();
	g_ptr_array_add(strv, (gpointer)pkg_path_get_data_dir());
	g_ptr_array_add(strv, (gpointer)first_path);
	va_start(args, first_path);
	while ((arg = va_arg(args, gchar*))) {
		g_ptr_array_add(strv, (gpointer)arg);
	}
	va_end(args);
	g_ptr_array_add(strv, NULL);
	arg = g_build_filenamev((gchar **)strv->pdata);
	g_ptr_array_unref(strv);
	RETURN(arg);
}
예제 #8
0
char*
darxen_file_support_find_path(const char *first, ...)
{
	va_list args;
	char* arg;
	int argc = 1;

	va_start(args, first);

	GSList* argList = g_slist_append(NULL, (char*)first);
	GSList* pArgList = argList;

	while ((arg = va_arg(args, char*)))
	{
		argList = g_slist_append(argList, arg);
		argc++;
	}
	va_end(args);

	char** argv = (char**)calloc(argc + 1, sizeof(char*));
	argv[argc] = NULL;

	int i = 0;
	while (pArgList)
	{
		argv[i] = (char*)pArgList->data;
		i++;
		pArgList = pArgList->next;
	}
	g_slist_free(argList);

	gchar* path = g_build_filenamev(argv);
	char* res = darxen_file_support_get_overridable_file_path(path);
	g_free(path);

	return res;
}
예제 #9
0
파일: rtf-field.c 프로젝트: ptomato/osxcart
static void field_instruction_end(ParserContext *ctx)
{
	FieldInstructionState *state = get_state(ctx);
	gchar *field_type, *buffer;
	GSList *switches = NULL, *formatswitches = NULL, *iter;
	const FieldInfo *field_info = fields;
	GScanner *tokenizer = g_scanner_new(&field_parser);
	
	g_scanner_input_text(tokenizer, state->scanbuffer->str, strlen(state->scanbuffer->str));
	
	/* Get field type */
	if(!(field_type = get_string_token(tokenizer)))
		return;

	/* Determine if field type is supported and get switches and arguments */
	while(field_info->name != NULL)
	{
	    if(g_ascii_strcasecmp(field_type, field_info->name) == 0)
	    {
	        state->type = field_info->type;
	        switches = get_switches(tokenizer, switches, field_info->switches, field_info->argswitches, field_info->wideswitches, field_info->wideargswitches);
	        if(field_info->has_argument)
	        {
	            if(!(buffer = get_string_token(tokenizer)))
	                return;
	            state->argument = g_strdup(buffer);
	            switches = get_switches(tokenizer, switches, field_info->switches, field_info->argswitches, field_info->wideswitches, field_info->wideargswitches);
	        }
	        break;
	    }
	    field_info++;
	}
	if(field_info->name == NULL) /* Field name wasn't found in list */
	{
		g_warning(_("'%s' field not supported"), field_type);
		g_scanner_destroy(tokenizer);
		return;
	}

	formatswitches = get_switches(tokenizer, formatswitches, "", "@#*", "", "");
	for(iter = formatswitches; iter; iter = g_slist_next(iter))
	{
		SwitchInfo *info = (SwitchInfo *)iter->data;
		/* Parse a date format consisting of \@ and a string */
		if(strcmp(info->switchname, "@") == 0)
			state->date_format = g_strdup(info->switcharg);
		/* Parse a numeric format consisting of \# and a string */
		else if(strcmp(info->switchname, "#") == 0)
			state->numeric_format = g_strdup(info->switcharg);
		/* Parse a general format consisting of \* and a keyword */
		else if(strcmp(info->switchname, "*") == 0)
		{
			if(strcmp(info->switcharg, "ALPHABETIC") == 0)
				state->general_number_format = NUMBER_ALPHABETIC;
			else if(strcmp(info->switcharg, "alphabetic") == 0)
				state->general_number_format = NUMBER_alphabetic;
			else if(strcmp(info->switcharg, "Arabic") == 0)
				state->general_number_format = NUMBER_ARABIC;
			else if(strcmp(info->switcharg, "ArabicDash") == 0)
				state->general_number_format = NUMBER_ARABIC_DASH;
			else if(strcmp(info->switcharg, "CIRCLENUM") == 0)
				state->general_number_format = NUMBER_CIRCLENUM;
			else if(strcmp(info->switcharg, "GB1") == 0)
				state->general_number_format = NUMBER_DECIMAL_ENCLOSED_PERIOD;
			else if(strcmp(info->switcharg, "GB2") == 0)
				state->general_number_format = NUMBER_DECIMAL_ENCLOSED_PARENTHESES;
			else if(strcmp(info->switcharg, "Hex") == 0)
				state->general_number_format = NUMBER_HEX;
			else if(strcmp(info->switcharg, "MERGEFORMATINET") == 0)
				; /* ignore */
			else if(strcmp(info->switcharg, "Ordinal") == 0)
				state->general_number_format = NUMBER_ORDINAL;
			else if(strcmp(info->switcharg, "Roman") == 0)
				state->general_number_format = NUMBER_ROMAN;
			else if(strcmp(info->switcharg, "roman") == 0)
				state->general_number_format = NUMBER_roman;
			else
				g_warning(_("Format '%s' not supported"), info->switcharg);
				/* Just continue */
		}
	}

    Destination *fielddest = g_queue_peek_nth(ctx->destination_stack, 1);
    FieldState *fieldstate = g_queue_peek_tail(fielddest->state_stack);

	switch(state->type)
	{
		case FIELD_TYPE_HYPERLINK:
		    /* Actually inserting hyperlinks into the text buffer is a whole 
		    security can of worms I don't want to open! Just use field result */
		    fieldstate->ignore_field_result = FALSE;
			break;

		case FIELD_TYPE_INCLUDEPICTURE:
		{
			GError *error = NULL;
			gchar **pathcomponents = g_strsplit(state->argument, "\\", 0);
			gchar *realfilename = g_build_filenamev(pathcomponents);
			
			g_strfreev(pathcomponents);
			GdkPixbuf *picture = gdk_pixbuf_new_from_file(realfilename, &error);
			if(!picture)
				g_warning(_("Error loading picture from file '%s': %s"), realfilename, error->message);
			else
			{
				/* Insert picture into text buffer */
				GtkTextIter iter;
				gtk_text_buffer_get_iter_at_mark(ctx->textbuffer, &iter, ctx->endmark);
				gtk_text_buffer_insert_pixbuf(ctx->textbuffer, &iter, picture);
				g_object_unref(picture);
			}
			g_free(realfilename);
		}
		    /* Don't use calculated field result */
		    fieldstate->ignore_field_result = TRUE;
			break;

		case FIELD_TYPE_PAGE:
		{
			gchar *output = format_integer(1, state->general_number_format);
			GtkTextIter iter;
			gtk_text_buffer_get_iter_at_mark(ctx->textbuffer, &iter, ctx->endmark);
			gtk_text_buffer_insert(ctx->textbuffer, &iter, output, -1);
			g_free(output);
		}
		    /* Don't use calculated field result */
		    fieldstate->ignore_field_result = TRUE;
			break;
			
		default:
			g_assert_not_reached();
	}
	
	g_free(state->argument);
	g_free(state->date_format);
	g_free(state->numeric_format);
	g_slist_foreach(switches, (GFunc)free_switch_info, NULL);
	g_slist_foreach(formatswitches, (GFunc)free_switch_info, NULL);
	g_scanner_destroy(tokenizer);
}
예제 #10
0
gchar *
cut_utils_build_path_array (const gchar **paths)
{
    return g_build_filenamev((gchar **)paths);
}
예제 #11
0
			/* re-check the new current part again in the next iteration */
			--p;
			continue;
		}
		++p;
	}
	if (*path == '/') {
		guint num_parts;

		num_parts = g_strv_length (parts) + 1;      /* incl. terminator */
		parts = g_renew (gchar *, parts, num_parts + 1);
		g_memmove (parts + 1, parts, num_parts * sizeof (gchar *));
		parts[0] = g_strdup ("/");
	}

	clean_path = g_build_filenamev (parts);
	g_strfreev (parts);
	return clean_path;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
gchar *gst_filename_to_uri(const gchar *filename, GError **error)
{
	gchar *abs_location = NULL;
	gchar *uri, *abs_clean;

	g_return_val_if_fail (filename != NULL, NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);

	if (g_path_is_absolute (filename)) {
		if (!file_path_contains_relatives (filename)) {