// Search the zscore of a phoneme
const Zratio& 
ZPhoneme::zscore(const PhonemePlus& pp) const
{
  const_iterator position= find( pp.get_phone() );

  if (position==end())
	  	fatal_message(-1,"Unknown Phoneme!?!\n");

  return (*position).second.zratio ;
}
// Check if a flag belongs to the properties
bool 
ZPhoneme::is_a(const Phoneme& ph,const char a_flag) const
{
  const_iterator position= find(ph);
  if (position==end())
	 fatal_message(-1,"Unknown Phoneme\n");
  
  Flags fl=(*position).second.flags;
  return  fl.find(a_flag) != (unsigned) -1;
}
void Txt2Speech::utter(const char *target, const char* lang, BOOL display, LPCTSTR outFile)
{
  strstream outpho;
  LPhonemePlus lpp;
  
  try
    {
      if (!strcmp(lang,cur_lang)==0)
	{		
	  if (phonet)
	    phonet->~Speak(); // forget previous data
	       
	  // Initialize from the data in the .ini file
	  char ini_file[255];
	  sprintf(ini_file,"%s.ini",lang);
	       
	  CLoading message;
	  message.Create(MAKEINTRESOURCE(IDD_LOADING),AfxGetMainWnd());
	  message.ShowWindow(SW_SHOW);
	  message.RedrawWindow(NULL,NULL,RDW_UPDATENOW);
	  phonet= load_Speak(ini_file);
	  cur_lang=strdup(lang);
	  message.ShowWindow(SW_HIDE);
	  message.DestroyWindow();
	}
	   
      phonet->transcribe(lpp,target,130,40,1);
	   int error_code= MBR_SetDatabase(phonet->get_dba());
	    
	   if (error_code != MBRERR_NOERROR)
	     {
	       char local[255];
	       MBR_LastError(local,sizeof(local));
	       fatal_message(-1,"MBROLA Init failed:%s",local);
	     }
	   
	   // End with a Flush command


	   outpho << "; Target " << target << endl << "_ 100\n" 
		  << lpp << endl << "_ 100\n _ 0" << endl << char(0);
	   if(outFile) //save wave file after playing
		   MBR_Play(CString(outpho.str()),MBROUT_WAVE,outFile,NULL);
	   int ret=MBR_Play(CString(outpho.str()),MBR_WAIT,NULL,NULL);
	   
	   // If you want to display the phonetic transcription
	   if (display)
	     MessageBox(AfxGetMainWnd()->GetSafeHwnd(), CString(outpho.str()), CString("Phonetized"), MB_OK );
	 }
  catch (int somthg_wrong)
    {
      // We'll handle this another day
    }
}
// Check if at least one flag belongs to the properties
bool 
ZPhoneme::is_a(const Phoneme& ph,const string& flags) const
{
  const_iterator position= find(ph);
  if (position==end())
	 fatal_message(-1,"Unknown Phoneme\n");
  Flags fl=(*position).second.flags;
	for(size_type i=0; i<flags.length(); i++)
	  {
		 if ( fl.find(flags[i]) != (unsigned) -1)
			return true;
	  }
	return false;
}
bool _compare_strcmp(const char *file, int line, const char *func, const T1_comparable& __expected, const T2_comparable& __actual)
{
  if (__expected == NULL)
  {
    fatal_message("Expected value was NULL, programmer error");
  }

  if (__actual == NULL)
  {
    libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " but got NULL";
    return false;
  }

  if (strncmp(__expected, __actual, strlen(__expected)))
  {
    libtest::stream::make_cerr(file, line, func) << "Expected " << __expected << " passed \"" << __actual << "\"";
    return false;
  }

  return true;
}
Example #6
0
int main(int argc, char **argv) {
    char crontab[11 + LOGIN_NAME_MAX] = "crontabs/";/* partial pathname */
    struct passwd *pwent;			/* passwd struct */
    int ch;					/* option character */
    FILE *tab, *tmp = NULL;			/* output/input files */
    int action = CREATE;

#ifdef __WATCOMC__
    nid_t nid = 0, qnx_strtonid();	/* server node */
    pid_t server;
    int local = 0;

    argv0 = basename(argv[0]);
    pwent = getpwuid(getuid());
    umask(066);

    while ((ch = getopt(argc, argv, "d:en:lLru:")) != EOF) {
	switch (ch) {
	  case 'L':
	    nid = getnid();
	    local = !local;
	    break;
	  case 'n':
	    nid = qnx_strtonid(optarg);
	    local = !local;
	    break;
#else
    void * server = NULL;
    int fd;					/* shm_open file handle */
    int euid, egid;

    argv0 = basename(argv[0]);
    pwent = getpwuid(getuid());
    umask(066);

    while ((ch = getopt(argc, argv, "d:elru:")) != EOF) {
	switch (ch) {
#endif
	  case 'd':
	    crondir = optarg;
	    break;
	  case 'e':
	    action = EDIT;
	    break;
	  case 'l':
	    if (action == REMOVE)
		fatal_message("conflict: -r/-l");
	    action = LIST;
	    break;
	  case 'r':
	    if (action == LIST) {
		fatal_message("conflict: -r/-l");
	    }
	    action = REMOVE;
	    break;
	  case 'u':
	    /* get name and uid/gid for user */
	    if ((pwent = getpwnam(optarg)) == 0) {
		long id = strtol(optarg, (char **) &pwent, 10);

		if (*(char *) pwent != 0) {
		    fatal_message("%s %s", "invalid user", optarg);
		}
		if ((pwent = getpwuid(id)) == 0) {
		    fatal_message("%s %s", "unknown user", optarg);
		}
	    }
	    break;
	  default:
	    exit(EXIT_FAILURE);
	}
    }

    /* make sure we're allowed to do anything with this crontab */
    if (getuid() != pwent->pw_uid && getuid() != 0) {
	fatal_message("access denied to crontab for %s", pwent->pw_name);
    }

    /* Locate the server */
#ifdef __WATCOMC__ 
    switch (nid) {
      case 0:
	if ((server = qnx_name_locate(0, cronsrv + 1, 0, 0)) != -1) {
	    nid = getnid();
	    local++;
	    break;
	}
	/* fallthru */
      default:
	server = qnx_name_locate(nid, cronsrv + local, 0, 0);
    }

    if (server == -1)
	fprintf(stderr, "warning: cron has not been started\n");

    if (local) {
	crondir = malloc(strlen(optarg = crondir) + 8);
	sprintf(crondir, "%s.%ld", optarg, nid);
    }

#else
    /* check if cron server is running. */
    if ((fd = shm_open(SHM_CRON, O_RDONLY, S_IRWXU )) == -1) {
	fprintf(stderr, "warning: cron has not been started\n");
    }
    else if(MAP_FAILED == (server = mmap(0, sizeof(pid_t), PROT_READ, MAP_SHARED, fd, 0))) {
	fatal_message("mmapp: %s", strerror(errno));
    }

    if(server && kill(*(pid_t *)server, 0) == -1) {
	fatal_message("cron stopped abnormally");
    }
    close(fd);
#endif

    strcat(crontab, pwent->pw_name);

    if (optind == argc) {
	if (action == CREATE || action == EDIT) {
	    char work[] = "/tmp/cronXXXX";

	    mktemp(work);

	    if (action == CREATE) {
		/* read replacement crontab from stdin */
		tmp = fopen(work, "w+");
		while ((ch = getchar()) != EOF)
		    fputc(ch, tmp);
	    } else {
		char *editor = getenv("EDITOR");
		int status;

		if (editor == NULL)
		    editor = "vi";

		if (chdir(crondir) == -1)
		    fatal_message("%s: %s", crondir, strerror(errno));

		if ((tab = fopen(crontab, "r")) == 0 && errno != ENOENT) {
		    fatal_message("%s/%s: %s", crondir, pwent->pw_name, strerror(errno));
		}

		egid = getegid();
		euid = geteuid();
		setegid(getgid());
		seteuid(getuid());

		tmp = fopen(work, "w+");
		if (tab) {
		    while ((ch = fgetc(tab)) != EOF)
			fputc(ch, tmp);
		    fflush(tmp);
		    fclose(tab);
		}
		if ((status = spawnlp(P_WAIT, editor, editor, work, 0))) {
		    remove(work);
		    fatal_message(status == -1 ? "unable to start %s" : "%s exited %d", editor, status);
		}
		setegid(egid);
		seteuid(euid);
	    }
	    remove(work);
	    rewind(tmp);
	}
    } else if (optind == argc - 1 && action == CREATE) {
	/* copy file onto crontab */
	if (access(argv[optind], R_OK) != 0 || (tmp = fopen(argv[optind], "r")) == 0) {
	    fatal_message("%s: %s", argv[optind], strerror(errno));
	}
    } else {
	fatal_message("too many arguments");
    }

    if(chdir(crondir) != 0)
	fatal_message("crontab %s: %s", strerror(errno), crondir);

    if (not_authorized(pwent->pw_name) && pwent->pw_uid != 0) {
	fprintf(stderr, "warning: no permission for cron: %s\n", pwent->pw_name);
    }

    if (action == LIST) {
	if ((tab = fopen(crontab, "r")) == 0) {
	    if(errno == ENOENT) 
		fatal_message("no crontab for %s", pwent->pw_name);
	    fatal_message("%s: %s", pwent->pw_name, strerror(errno));
	} else {
	    while ((ch = fgetc(tab)) != EOF)
		putchar(ch);
	    fclose(tab);
	}
    } else {
	/* drop and store euid/egid, use uid/gid */ 
	egid = getegid();
	euid = geteuid();
	setegid(getgid());
	seteuid(getuid());

	chmod(crontab, S_IRWXU);	/* -rw---- */
	if (action == REMOVE) {
	    if (remove(crontab) == -1 && errno != ENOENT) {
		fatal_message("%s: %s", strerror(errno), crontab);
	    }
	} else if (action == CREATE || action == EDIT) {
	    if ((tab = fopen(crontab, "w")) == NULL) {
		fatal_message("%s: %s", strerror(errno), crontab);
	    }

	    while ((ch = fgetc(tmp)) != EOF)
		fputc(ch, tab);

	    fflush(tab); /* Changing write permissions later! */

	    fchown(fileno(tab), pwent->pw_uid, pwent->pw_gid);
	    fchmod(fileno(tab), S_IRUSR);	/* -r----- */
	    fclose(tab);
	    fclose(tmp);

	}
	/* restore euid/egid for kill */
	setegid(egid);
	seteuid(euid);

	/* Notify server */
#ifdef __WATCOMC__
	if (server != -1 && Send(server, pwent->pw_name, 0, strlen(pwent->pw_name) + 1, 0) < 0) {
#else
	if(server && kill(*(pid_t *)server, SIGUSR1) == -1) {
#endif
		fatal_message("inform cron about update: %s", strerror(errno));
	}
    }
    return EXIT_SUCCESS;
}