www.pudn.com > xvoice-0.8.1.rar > xvoice.cc
/** * xvoice.cc * * Description: main program code for XVoice * * Copyright (c) 1999, David Z. Creemer. * See the LICENSE file. All rights not granted therein are reserved. * * @author David Z. Creemer * @version 1.0 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include "config.h" #include#include #include #include #include #include #include #include #include "Error.h" #include "x.h" #include "xvoice.h" #include "Target.h" #ifdef WINLIST #include "TargetList.h" #endif #include "MainWin.h" #include "ParseEventStream.h" #if defined( HAVE_SMAPI ) #include "Voice.h" #endif Display *gDisplay; MainWindow *gMainWin; char grammarDir [ 512 ]; char xvoicexml[1024]; void usage() { fprintf( stderr, "%s %s usage:\n-m turn mic on\n-h show this help\n", PACKAGE, VERSION ); } gint turnOnMic( gpointer ) { gMainWin->micOn(); // run only once return 0; } #define LOOPTRAP "XVOICELOOPING" void bootstrap_environment(char *appname) { char *bindir = getenv("SPCH_BIN"); char *loop = getenv(LOOPTRAP); if (bindir == 0) { int ret; printf("Environment not set. Looking for vvsetenv...."); if (loop != 0) { printf("\nxvoice is looping. vvsetenv is probably not installed correctly.\n"); exit(-1); } /* * try running vvsetenv. if it works, * then restart after sourcing vvsetenv. */ if (system("vvsetenv") == 0) { char cmdline[1000]; printf("found vvsetenv.\n"); printf("Restarting with new environment.\n"); snprintf(cmdline,1000,". vvsetenv; exec %s",appname); setenv(LOOPTRAP, "YES", 1); /* "Why bash2 ?" I hear you cry. Well, because bash 1.14.7 * has a bug which is invoked by vvsetenv. Amazing, but true. * If you don't have bash2, zsh will do. */ execlp("bash2", "bash2","-c", cmdline, NULL); printf("exec failed\n Bailing out.\n"); exit(-1); } else { printf("\nDidn't find vvsetenv. Bailing out.\n"); exit(-1); } } else { printf("Environment set.\n"); } } static int xvoice_init(void *p) { fstring filename; bool save = *((bool *)p); struct stat s; char *home=getenv("HOME"); #if defined( HAVE_SMAPI ) if ( !initVoice(save) ) { exit( 1 ); } #endif filename.appendf("%s/.%s", home, PACKAGE); if (stat(filename.c_str(), &s) != 0) { if (mkdir(filename.c_str(), 0755) < 0) { LogMessage(E_FATAL, "Could not create data directory %s!\n", filename.c_str()); return 0; } } filename.resize(0); filename.appendf("%s/.%s/grammars", home, PACKAGE); if (stat(filename.c_str(), &s) != 0) { if (mkdir(filename.c_str(), 0755) < 0) { LogMessage(E_FATAL, "Could not create data directory %s!\n", filename.c_str()); return 0; } } loadGrammars(); return 0; } int main( int argc, char* argv[] ) { bootstrap_environment(argv[0]); gDisplay = XOpenDisplay(NULL); bool save = false;; if ( gDisplay == NULL ) { fprintf( stderr, "can't open display" ); exit( 1 ); } #define GNOME_WINDOW #ifdef GNOME_WINDOW extern MainWindow *getGnomeMainWindow(int argc, char **argv); gMainWin = getGnomeMainWindow(argc, argv); #endif /* to be added */ #ifdef WM_WINDOW gMainWin = new wmMainWindow(argc, argv); #endif #ifdef CONSOLE_WINDOW gMainWin = new consoleMainWindow(argc, argv); #endif if ( argc > 1 ) { for ( int i=1; i