File: pathsupport.cpp

package info (click to toggle)
photoprint 0.3.3-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,708 kB
  • ctags: 3,996
  • sloc: cpp: 17,543; sh: 8,311; ansic: 4,299; makefile: 324
file content (44 lines) | stat: -rw-r--r-- 783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string.h>
#include <glib.h>

#include "searchpath.h"
#include "pathsupport.h"

using namespace std;

const char *get_homedir()
{
//	return(getenv("HOME"));
	return(g_get_home_dir());
}


char *substitute_homedir(const char *path)
{
	char *result=NULL;
	if(path)
	{
		if(path[0]=='~')
			++path;

		else if(strncasecmp(path,"$HOME",5)==0)
			path+=5;

		else	// No substitution to be done...
			return(strdup(path));

		if(path[0]=='/' || path[0]=='\\')
			++path;

		// If we get this far, then we need to substitute - and path now points
		// to the beginning of the path proper...
		const char *hd=g_get_home_dir();

		result=(char *)malloc(strlen(path)+strlen(hd)+2);	

		sprintf(result,"%s%c%s",hd,SEARCHPATH_SEPARATOR,path);
	}
	return(result);
}