Commit 75ecef53 authored by Michael Rouse's avatar Michael Rouse

Getting root folder of executable.

parent 0c80cd80
......@@ -126,4 +126,39 @@ date_t args_parse_date(char *dateStr)
#endif
return date;
}
char* args_get_directory_of_executable(char *name)
{
char path[1000];
path[0] = '\0';
char read_since_last_separator[100];
read_since_last_separator[0] = '\0';
int i;
int pos;
int len = strlen(name);
for (i = 0; i < len; i++)
{
if (name[i] == '/' || name[i] == '\\')
{
if (strlen(path) > 0)
{
pos = strlen(path);
path[pos] = '\\';
path[pos + 1] = '\0';
}
strcat(path, read_since_last_separator);
read_since_last_separator[0] = '\0';
}
else {
pos = strlen(read_since_last_separator);
read_since_last_separator[pos] = name[i];
read_since_last_separator[pos + 1] = '\0';
}
}
char *result = malloc(sizeof(path));
strcpy(result, path);
return result;
}
\ No newline at end of file
......@@ -33,4 +33,7 @@ args_t args_parse(int argc, char **argv);
/* Parse into a date */
date_t args_parse_date(char *date);
char* args_get_directory_of_executable(char *name);
#endif
\ No newline at end of file
......@@ -18,7 +18,8 @@ int main(int argc, char *argv[])
{
log_dull("==== Time Slime ====\n")
status = TimeSlime_Initialize("build");
char *base_folder = args_get_directory_of_executable(argv[0]);
status = TimeSlime_Initialize(base_folder);
if (status != TIMESLIME_OK)
{
printf("An error occured: %d\n", status);
......@@ -51,6 +52,9 @@ int main(int argc, char *argv[])
TimeSlime_Close();
free(base_folder);
base_folder = NULL;
return 0;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment