| 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 |
#include <fontforge-config.h> |
| 29 |
|
| 30 |
#include "gfile.h" |
| 31 |
#include "ustring.h" |
| 32 |
|
| 33 |
#include <gio/gio.h> |
| 34 |
#include <stdbool.h> |
| 35 |
#include <stdlib.h> |
| 36 |
#include <string.h> |
| 37 |
|
| 38 |
static char* SupportedLocale(const char *locale, const char *fullspec, const char *filename) { |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
int i; |
| 44 |
|
| 45 |
static const char *supported[] = { "de","ja", NULL }; |
| 46 |
|
| 47 |
for ( i=0; supported[i]!=NULL; ++i ) { |
| 48 |
if ( strcmp(locale,supported[i])==0 ) { |
| 49 |
const char *pt = strrchr(filename, '/'); |
| 50 |
return smprintf("%s/old/%s/%s", fullspec, supported[i], pt ? pt : filename); |
| 51 |
} |
| 52 |
} |
| 53 |
return NULL; |
| 54 |
} |
| 55 |
|
| 56 |
static char* CheckSupportedLocale(const char *fullspec, const char *filename) { |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
const char *loc = getenv("LC_ALL"); |
| 62 |
char buffer[40], *pt; |
| 63 |
|
| 64 |
if ( loc==NULL ) loc = getenv("LC_CTYPE"); |
| 65 |
if ( loc==NULL ) loc = getenv("LANG"); |
| 66 |
if ( loc==NULL ) loc = getenv("LC_MESSAGES"); |
| 67 |
if ( loc==NULL ) |
| 68 |
return NULL; |
| 69 |
|
| 70 |
|
| 71 |
strncpy(buffer,loc,sizeof(buffer)); |
| 72 |
buffer[sizeof(buffer)-1] = '\0'; |
| 73 |
pt = SupportedLocale(buffer, fullspec, filename); |
| 74 |
if (pt) { |
| 75 |
return pt; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
if ( (pt=strchr(buffer,'.'))!=NULL ) { |
| 80 |
*pt = '\0'; |
| 81 |
pt = SupportedLocale(buffer, fullspec, filename); |
| 82 |
if (pt) { |
| 83 |
return pt; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
if ( (pt=strchr(buffer,'_'))!=NULL ) { |
| 89 |
*pt = '\0'; |
| 90 |
return SupportedLocale(buffer, fullspec, filename); |
| 91 |
} |
| 92 |
|
| 93 |
return NULL; |
| 94 |
} |
| 95 |
|
| 96 |
void help(const char *file, const char *section) { |
| 97 |
if (!file) { |
| 98 |
return; |
| 99 |
} else if (strstr(file, "://")) { |
| 100 |
g_app_info_launch_default_for_uri(file, NULL, NULL); |
| 101 |
return; |
| 102 |
} else if (!section) { |
| 103 |
section = ""; |
| 104 |
} |
| 105 |
|
| 106 |
bool launched = false; |
| 107 |
const char *helpdir = getHelpDir(); |
| 108 |
if (helpdir) { |
| 109 |
char *path = CheckSupportedLocale(helpdir, file); |
| 110 |
if (!path) { |
| 111 |
path = smprintf("%s/%s", helpdir, file); |
| 112 |
if (!path) { |
| 113 |
return; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
GFile *gfile = g_file_new_for_path(path); |
| 118 |
free(path); |
| 119 |
|
| 120 |
if (g_file_query_exists(gfile, NULL)) { |
| 121 |
gchar* uri = g_file_get_uri(gfile); |
| 122 |
path = smprintf("%s%s", uri, section); |
| 123 |
launched = g_app_info_launch_default_for_uri(path, NULL, NULL); |
| 124 |
g_free(uri); |
| 125 |
free(path); |
| 126 |
} |
| 127 |
g_object_unref(gfile); |
| 128 |
} |
| 129 |
|
| 130 |
if (!launched) { |
| 131 |
char *path = smprintf("https://fontforge.org/docs/%s%s", file, section); |
| 132 |
g_app_info_launch_default_for_uri(path, NULL, NULL); |
| 133 |
free(path); |
| 134 |
} |
| 135 |
} |