Browse Source

Share the init_path implementation between libespeak-ng and speak-ng.

master
Reece H. Dunn 9 years ago
parent
commit
44dbfc1b31
3 changed files with 18 additions and 72 deletions
  1. 3
    0
      src/include/espeak-ng/espeak_ng.h
  2. 11
    12
      src/libespeak-ng/speak_lib.c
  3. 4
    60
      src/speak-ng.c

+ 3
- 0
src/include/espeak-ng/espeak_ng.h View File



#define espeakINITIALIZE_PATH_ONLY 0x4000 #define espeakINITIALIZE_PATH_ONLY 0x4000


ESPEAK_NG_API void
espeak_ng_InitializePath(const char *path);

ESPEAK_NG_API espeak_ng_STATUS ESPEAK_NG_API espeak_ng_STATUS
espeak_ng_CompileDictionary(const char *dsource, espeak_ng_CompileDictionary(const char *dsource,
const char *dict_name, const char *dict_name,

+ 11
- 12
src/libespeak-ng/speak_lib.c View File

free(ptr); free(ptr);
} }


static void init_path(const char *path)
#pragma GCC visibility push(default)
ESPEAK_NG_API void espeak_ng_InitializePath(const char *path)
{ {
if (path != NULL) {
sprintf(path_home, "%s/espeak-data", path);
return;
}

#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
HKEY RegKey; HKEY RegKey;
unsigned long size; unsigned long size;
char *env; char *env;
unsigned char buf[sizeof(path_home)-13]; unsigned char buf[sizeof(path_home)-13];


if (path != NULL) {
sprintf(path_home, "%s/espeak-data", path);
return;
}

if ((env = getenv("ESPEAK_DATA_PATH")) != NULL) { if ((env = getenv("ESPEAK_DATA_PATH")) != NULL) {
sprintf(path_home, "%s/espeak-data", env); sprintf(path_home, "%s/espeak-data", env);
if (GetFileLength(path_home) == -2) if (GetFileLength(path_home) == -2)
RegQueryValueExA(RegKey, "path", 0, &var_type, buf, &size); RegQueryValueExA(RegKey, "path", 0, &var_type, buf, &size);


sprintf(path_home, "%s\\espeak-data", buf); sprintf(path_home, "%s\\espeak-data", buf);
#elif defined(PLATFORM_DOS)
strcpy(path_home, PATH_ESPEAK_DATA);
#else #else
char *env; char *env;


if (path != NULL) {
snprintf(path_home, sizeof(path_home), "%s/espeak-data", path);
return;
}

// check for environment variable // check for environment variable
if ((env = getenv("ESPEAK_DATA_PATH")) != NULL) { if ((env = getenv("ESPEAK_DATA_PATH")) != NULL) {
snprintf(path_home, sizeof(path_home), "%s/espeak-data", env); snprintf(path_home, sizeof(path_home), "%s/espeak-data", env);
strcpy(path_home, PATH_ESPEAK_DATA); strcpy(path_home, PATH_ESPEAK_DATA);
#endif #endif
} }
#pragma GCC visibility pop


static int initialise(int control) static int initialise(int control)
{ {
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
} }


init_path(path);
espeak_ng_InitializePath(path);
if (options & espeakINITIALIZE_PATH_ONLY) if (options & espeakINITIALIZE_PATH_ONLY)
return 0; return 0;



+ 4
- 60
src/speak-ng.c View File

return finished; return finished;
} }


static void init_path(char *argv0, char *path_specified)
{
(void)argv0; // unused (except with PLATFORM_WINDOWS)

if (path_specified) {
sprintf(path_home, "%s/espeak-data", path_specified);
return;
}

#ifdef PLATFORM_WINDOWS
HKEY RegKey;
unsigned long size;
unsigned long var_type;
char *p;
char *env;
unsigned char buf[sizeof(path_home)-12];

if (((env = getenv("ESPEAK_DATA_PATH")) != NULL) && ((strlen(env)+12) < sizeof(path_home))) {
sprintf(path_home, "%s\\espeak-data", env);
if (GetFileLength(path_home) == -2)
return; // an espeak-data directory exists in the directory specified by environment variable
}

strcpy(path_home, argv0);
if ((p = strrchr(path_home, '\\')) != NULL) {
strcpy(&p[1], "espeak-data");
if (GetFileLength(path_home) == -2)
return; // an espeak-data directory exists in the same directory as the espeak program
}

// otherwise, look in the Windows Registry
buf[0] = 0;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Speech\\Voices\\Tokens\\eSpeak", 0, KEY_READ, &RegKey);
size = sizeof(buf);
var_type = REG_SZ;
RegQueryValueEx(RegKey, "path", 0, &var_type, buf, &size);

sprintf(path_home, "%s\\espeak-data", buf);
#else
#ifdef PLATFORM_DOS
strcpy(path_home, PATH_ESPEAK_DATA);
#else
char *env;
if ((env = getenv("ESPEAK_DATA_PATH")) != NULL) {
snprintf(path_home, sizeof(path_home), "%s/espeak-data", env);
if (GetFileLength(path_home) == -2)
return; // an espeak-data directory exists
}

snprintf(path_home, sizeof(path_home), "%s/espeak-data", getenv("HOME"));
if (access(path_home, R_OK) != 0)
strcpy(path_home, PATH_ESPEAK_DATA);
#endif
#endif
}

static int initialise(void) static int initialise(void)
{ {
int param; int param;
option_multibyte = value; option_multibyte = value;
break; break;
case 'h': case 'h':
init_path(argv[0], data_path);
espeak_ng_InitializePath(data_path);
printf("\nspeak text-to-speech: %s Data at: %s\n%s", version_string, path_home, help_text); printf("\nspeak text-to-speech: %s Data at: %s\n%s", version_string, path_home, help_text);
exit(0); exit(0);
case 'k': case 'k':
} }
break; break;
case 0x104: // --voices case 0x104: // --voices
init_path(argv[0], data_path);
espeak_ng_InitializePath(data_path);
DisplayVoices(stdout, optarg2); DisplayVoices(stdout, optarg2);
exit(0); exit(0);
case 0x106: // -- split case 0x106: // -- split
} }
break; break;
case 0x10b: // --version case 0x10b: // --version
init_path(argv[0], data_path);
espeak_ng_InitializePath(data_path);
printf("speak text-to-speech: %s Data at: %s\n", version_string, path_home); printf("speak text-to-speech: %s Data at: %s\n", version_string, path_home);
exit(0); exit(0);
case 0x10c: // --sep case 0x10c: // --sep
} }
} }


init_path(argv[0], data_path);
espeak_ng_InitializePath(data_path);
initialise(); initialise();


if (voicename[0] == 0) if (voicename[0] == 0)

Loading…
Cancel
Save